babylon.glTFFileLoader.js 378 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-glTFFileLoader.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** C:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  324. /*!*****************************************!*\
  325. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  326. \*****************************************/
  327. /*! exports provided: GLTFBinaryExtension */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  332. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  333. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  334. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  335. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  336. var BinaryExtensionBufferName = "binary_glTF";
  337. /** @hidden */
  338. var GLTFBinaryExtension = /** @class */ (function (_super) {
  339. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  340. function GLTFBinaryExtension() {
  341. return _super.call(this, "KHR_binary_glTF") || this;
  342. }
  343. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  344. var extensionsUsed = data.json.extensionsUsed;
  345. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  346. return false;
  347. }
  348. this._bin = data.bin;
  349. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  350. return true;
  351. };
  352. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  353. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  354. return false;
  355. }
  356. if (id !== BinaryExtensionBufferName) {
  357. return false;
  358. }
  359. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  360. return true;
  361. };
  362. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  363. var texture = gltfRuntime.textures[id];
  364. var source = gltfRuntime.images[texture.source];
  365. if (!source.extensions || !(this.name in source.extensions)) {
  366. return false;
  367. }
  368. var sourceExt = source.extensions[this.name];
  369. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  370. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  371. onSuccess(buffer);
  372. return true;
  373. };
  374. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  375. var shader = gltfRuntime.shaders[id];
  376. if (!shader.extensions || !(this.name in shader.extensions)) {
  377. return false;
  378. }
  379. var binaryExtensionShader = shader.extensions[this.name];
  380. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  381. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  382. setTimeout(function () {
  383. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  384. onSuccess(shaderString);
  385. });
  386. return true;
  387. };
  388. return GLTFBinaryExtension;
  389. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  390. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  391. /***/ }),
  392. /***/ "./glTF/1.0/glTFLoader.ts":
  393. /*!********************************!*\
  394. !*** ./glTF/1.0/glTFLoader.ts ***!
  395. \********************************/
  396. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  397. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  398. "use strict";
  399. __webpack_require__.r(__webpack_exports__);
  400. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  401. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  402. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  403. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  404. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  405. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  406. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  407. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  408. /**
  409. * Tokenizer. Used for shaders compatibility
  410. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  411. */
  412. var ETokenType;
  413. (function (ETokenType) {
  414. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  415. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  416. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  417. })(ETokenType || (ETokenType = {}));
  418. var Tokenizer = /** @class */ (function () {
  419. function Tokenizer(toParse) {
  420. this._pos = 0;
  421. this.currentToken = ETokenType.UNKNOWN;
  422. this.currentIdentifier = "";
  423. this.currentString = "";
  424. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  425. this._toParse = toParse;
  426. this._maxPos = toParse.length;
  427. }
  428. Tokenizer.prototype.getNextToken = function () {
  429. if (this.isEnd()) {
  430. return ETokenType.END_OF_INPUT;
  431. }
  432. this.currentString = this.read();
  433. this.currentToken = ETokenType.UNKNOWN;
  434. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  435. this.currentToken = ETokenType.IDENTIFIER;
  436. this.currentIdentifier = this.currentString;
  437. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  438. this.currentIdentifier += this.currentString;
  439. this.forward();
  440. }
  441. }
  442. return this.currentToken;
  443. };
  444. Tokenizer.prototype.peek = function () {
  445. return this._toParse[this._pos];
  446. };
  447. Tokenizer.prototype.read = function () {
  448. return this._toParse[this._pos++];
  449. };
  450. Tokenizer.prototype.forward = function () {
  451. this._pos++;
  452. };
  453. Tokenizer.prototype.isEnd = function () {
  454. return this._pos >= this._maxPos;
  455. };
  456. return Tokenizer;
  457. }());
  458. /**
  459. * Values
  460. */
  461. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  462. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  463. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  464. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  465. /**
  466. * Parse
  467. */
  468. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  469. for (var buf in parsedBuffers) {
  470. var parsedBuffer = parsedBuffers[buf];
  471. gltfRuntime.buffers[buf] = parsedBuffer;
  472. gltfRuntime.buffersCount++;
  473. }
  474. };
  475. var parseShaders = function (parsedShaders, gltfRuntime) {
  476. for (var sha in parsedShaders) {
  477. var parsedShader = parsedShaders[sha];
  478. gltfRuntime.shaders[sha] = parsedShader;
  479. gltfRuntime.shaderscount++;
  480. }
  481. };
  482. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  483. for (var object in parsedObjects) {
  484. var parsedObject = parsedObjects[object];
  485. gltfRuntime[runtimeProperty][object] = parsedObject;
  486. }
  487. };
  488. /**
  489. * Utils
  490. */
  491. var normalizeUVs = function (buffer) {
  492. if (!buffer) {
  493. return;
  494. }
  495. for (var i = 0; i < buffer.length / 2; i++) {
  496. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  497. }
  498. };
  499. var getAttribute = function (attributeParameter) {
  500. if (attributeParameter.semantic === "NORMAL") {
  501. return "normal";
  502. }
  503. else if (attributeParameter.semantic === "POSITION") {
  504. return "position";
  505. }
  506. else if (attributeParameter.semantic === "JOINT") {
  507. return "matricesIndices";
  508. }
  509. else if (attributeParameter.semantic === "WEIGHT") {
  510. return "matricesWeights";
  511. }
  512. else if (attributeParameter.semantic === "COLOR") {
  513. return "color";
  514. }
  515. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  516. var channel = Number(attributeParameter.semantic.split("_")[1]);
  517. return "uv" + (channel === 0 ? "" : channel + 1);
  518. }
  519. return null;
  520. };
  521. /**
  522. * Loads and creates animations
  523. */
  524. var loadAnimations = function (gltfRuntime) {
  525. for (var anim in gltfRuntime.animations) {
  526. var animation = gltfRuntime.animations[anim];
  527. if (!animation.channels || !animation.samplers) {
  528. continue;
  529. }
  530. var lastAnimation = null;
  531. for (var i = 0; i < animation.channels.length; i++) {
  532. // Get parameters and load buffers
  533. var channel = animation.channels[i];
  534. var sampler = animation.samplers[channel.sampler];
  535. if (!sampler) {
  536. continue;
  537. }
  538. var inputData = null;
  539. var outputData = null;
  540. if (animation.parameters) {
  541. inputData = animation.parameters[sampler.input];
  542. outputData = animation.parameters[sampler.output];
  543. }
  544. else {
  545. inputData = sampler.input;
  546. outputData = sampler.output;
  547. }
  548. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  549. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  550. var targetID = channel.target.id;
  551. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  552. if (targetNode === null) {
  553. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  554. }
  555. if (targetNode === null) {
  556. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  557. continue;
  558. }
  559. var isBone = targetNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  560. // Get target path (position, rotation or scaling)
  561. var targetPath = channel.target.path;
  562. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  563. if (targetPathIndex !== -1) {
  564. targetPath = babylonAnimationPaths[targetPathIndex];
  565. }
  566. // Determine animation type
  567. var animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  568. if (!isBone) {
  569. if (targetPath === "rotationQuaternion") {
  570. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  571. targetNode.rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  572. }
  573. else {
  574. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  575. }
  576. }
  577. // Create animation and key frames
  578. var babylonAnimation = null;
  579. var keys = [];
  580. var arrayOffset = 0;
  581. var modifyKey = false;
  582. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  583. babylonAnimation = lastAnimation;
  584. modifyKey = true;
  585. }
  586. if (!modifyKey) {
  587. babylonAnimation = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"](anim, isBone ? "_matrix" : targetPath, 1, animationType, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONLOOPMODE_CYCLE);
  588. }
  589. // For each frame
  590. for (var j = 0; j < bufferInput.length; j++) {
  591. var value = null;
  592. if (targetPath === "rotationQuaternion") { // VEC4
  593. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  594. arrayOffset += 4;
  595. }
  596. else { // Position and scaling are VEC3
  597. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  598. arrayOffset += 3;
  599. }
  600. if (isBone) {
  601. var bone = targetNode;
  602. var translation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  603. var rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  604. var scaling = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  605. // Warning on decompose
  606. var mat = bone.getBaseMatrix();
  607. if (modifyKey && lastAnimation) {
  608. mat = lastAnimation.getKeys()[j].value;
  609. }
  610. mat.decompose(scaling, rotationQuaternion, translation);
  611. if (targetPath === "position") {
  612. translation = value;
  613. }
  614. else if (targetPath === "rotationQuaternion") {
  615. rotationQuaternion = value;
  616. }
  617. else {
  618. scaling = value;
  619. }
  620. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  621. }
  622. if (!modifyKey) {
  623. keys.push({
  624. frame: bufferInput[j],
  625. value: value
  626. });
  627. }
  628. else if (lastAnimation) {
  629. lastAnimation.getKeys()[j].value = value;
  630. }
  631. }
  632. // Finish
  633. if (!modifyKey && babylonAnimation) {
  634. babylonAnimation.setKeys(keys);
  635. targetNode.animations.push(babylonAnimation);
  636. }
  637. lastAnimation = babylonAnimation;
  638. gltfRuntime.scene.stopAnimation(targetNode);
  639. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  640. }
  641. }
  642. };
  643. /**
  644. * Returns the bones transformation matrix
  645. */
  646. var configureBoneTransformation = function (node) {
  647. var mat = null;
  648. if (node.translation || node.rotation || node.scale) {
  649. var scale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  650. var rotation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  651. var position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  652. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  653. }
  654. else {
  655. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  656. }
  657. return mat;
  658. };
  659. /**
  660. * Returns the parent bone
  661. */
  662. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  663. // Try to find
  664. for (var i = 0; i < newSkeleton.bones.length; i++) {
  665. if (newSkeleton.bones[i].name === jointName) {
  666. return newSkeleton.bones[i];
  667. }
  668. }
  669. // Not found, search in gltf nodes
  670. var nodes = gltfRuntime.nodes;
  671. for (var nde in nodes) {
  672. var node = nodes[nde];
  673. if (!node.jointName) {
  674. continue;
  675. }
  676. var children = node.children;
  677. for (var i = 0; i < children.length; i++) {
  678. var child = gltfRuntime.nodes[children[i]];
  679. if (!child.jointName) {
  680. continue;
  681. }
  682. if (child.jointName === jointName) {
  683. var mat = configureBoneTransformation(node);
  684. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  685. bone.id = nde;
  686. return bone;
  687. }
  688. }
  689. }
  690. return null;
  691. };
  692. /**
  693. * Returns the appropriate root node
  694. */
  695. var getNodeToRoot = function (nodesToRoot, id) {
  696. for (var i = 0; i < nodesToRoot.length; i++) {
  697. var nodeToRoot = nodesToRoot[i];
  698. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  699. var child = nodeToRoot.node.children[j];
  700. if (child === id) {
  701. return nodeToRoot.bone;
  702. }
  703. }
  704. }
  705. return null;
  706. };
  707. /**
  708. * Returns the node with the joint name
  709. */
  710. var getJointNode = function (gltfRuntime, jointName) {
  711. var nodes = gltfRuntime.nodes;
  712. var node = nodes[jointName];
  713. if (node) {
  714. return {
  715. node: node,
  716. id: jointName
  717. };
  718. }
  719. for (var nde in nodes) {
  720. node = nodes[nde];
  721. if (node.jointName === jointName) {
  722. return {
  723. node: node,
  724. id: nde
  725. };
  726. }
  727. }
  728. return null;
  729. };
  730. /**
  731. * Checks if a nodes is in joints
  732. */
  733. var nodeIsInJoints = function (skins, id) {
  734. for (var i = 0; i < skins.jointNames.length; i++) {
  735. if (skins.jointNames[i] === id) {
  736. return true;
  737. }
  738. }
  739. return false;
  740. };
  741. /**
  742. * Fills the nodes to root for bones and builds hierarchy
  743. */
  744. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  745. // Creates nodes for root
  746. for (var nde in gltfRuntime.nodes) {
  747. var node = gltfRuntime.nodes[nde];
  748. var id = nde;
  749. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  750. continue;
  751. }
  752. // Create node to root bone
  753. var mat = configureBoneTransformation(node);
  754. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  755. bone.id = id;
  756. nodesToRoot.push({ bone: bone, node: node, id: id });
  757. }
  758. // Parenting
  759. for (var i = 0; i < nodesToRoot.length; i++) {
  760. var nodeToRoot = nodesToRoot[i];
  761. var children = nodeToRoot.node.children;
  762. for (var j = 0; j < children.length; j++) {
  763. var child = null;
  764. for (var k = 0; k < nodesToRoot.length; k++) {
  765. if (nodesToRoot[k].id === children[j]) {
  766. child = nodesToRoot[k];
  767. break;
  768. }
  769. }
  770. if (child) {
  771. child.bone._parent = nodeToRoot.bone;
  772. nodeToRoot.bone.children.push(child.bone);
  773. }
  774. }
  775. }
  776. };
  777. /**
  778. * Imports a skeleton
  779. */
  780. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  781. if (!newSkeleton) {
  782. newSkeleton = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  783. }
  784. if (!skins.babylonSkeleton) {
  785. return newSkeleton;
  786. }
  787. // Find the root bones
  788. var nodesToRoot = [];
  789. var nodesToRootToAdd = [];
  790. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  791. newSkeleton.bones = [];
  792. // Joints
  793. for (var i = 0; i < skins.jointNames.length; i++) {
  794. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  795. if (!jointNode) {
  796. continue;
  797. }
  798. var node = jointNode.node;
  799. if (!node) {
  800. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  801. continue;
  802. }
  803. var id = jointNode.id;
  804. // Optimize, if the bone already exists...
  805. var existingBone = gltfRuntime.scene.getBoneByID(id);
  806. if (existingBone) {
  807. newSkeleton.bones.push(existingBone);
  808. continue;
  809. }
  810. // Search for parent bone
  811. var foundBone = false;
  812. var parentBone = null;
  813. for (var j = 0; j < i; j++) {
  814. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  815. if (!jointNode_1) {
  816. continue;
  817. }
  818. var joint = jointNode_1.node;
  819. if (!joint) {
  820. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  821. continue;
  822. }
  823. var children = joint.children;
  824. if (!children) {
  825. continue;
  826. }
  827. foundBone = false;
  828. for (var k = 0; k < children.length; k++) {
  829. if (children[k] === id) {
  830. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  831. foundBone = true;
  832. break;
  833. }
  834. }
  835. if (foundBone) {
  836. break;
  837. }
  838. }
  839. // Create bone
  840. var mat = configureBoneTransformation(node);
  841. if (!parentBone && nodesToRoot.length > 0) {
  842. parentBone = getNodeToRoot(nodesToRoot, id);
  843. if (parentBone) {
  844. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  845. nodesToRootToAdd.push(parentBone);
  846. }
  847. }
  848. }
  849. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  850. bone.id = id;
  851. }
  852. // Polish
  853. var bones = newSkeleton.bones;
  854. newSkeleton.bones = [];
  855. for (var i = 0; i < skins.jointNames.length; i++) {
  856. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  857. if (!jointNode) {
  858. continue;
  859. }
  860. for (var j = 0; j < bones.length; j++) {
  861. if (bones[j].id === jointNode.id) {
  862. newSkeleton.bones.push(bones[j]);
  863. break;
  864. }
  865. }
  866. }
  867. newSkeleton.prepare();
  868. // Finish
  869. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  870. newSkeleton.bones.push(nodesToRootToAdd[i]);
  871. }
  872. return newSkeleton;
  873. };
  874. /**
  875. * Imports a mesh and its geometries
  876. */
  877. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  878. if (!newMesh) {
  879. newMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  880. newMesh.id = id;
  881. }
  882. if (!node.babylonNode) {
  883. return newMesh;
  884. }
  885. var subMaterials = [];
  886. var vertexData = null;
  887. var verticesStarts = new Array();
  888. var verticesCounts = new Array();
  889. var indexStarts = new Array();
  890. var indexCounts = new Array();
  891. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  892. var meshID = meshes[meshIndex];
  893. var mesh = gltfRuntime.meshes[meshID];
  894. if (!mesh) {
  895. continue;
  896. }
  897. // Positions, normals and UVs
  898. for (var i = 0; i < mesh.primitives.length; i++) {
  899. // Temporary vertex data
  900. var tempVertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  901. var primitive = mesh.primitives[i];
  902. if (primitive.mode !== 4) {
  903. // continue;
  904. }
  905. var attributes = primitive.attributes;
  906. var accessor = null;
  907. var buffer = null;
  908. // Set positions, normal and uvs
  909. for (var semantic in attributes) {
  910. // Link accessor and buffer view
  911. accessor = gltfRuntime.accessors[attributes[semantic]];
  912. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  913. if (semantic === "NORMAL") {
  914. tempVertexData.normals = new Float32Array(buffer.length);
  915. tempVertexData.normals.set(buffer);
  916. }
  917. else if (semantic === "POSITION") {
  918. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  919. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  920. for (var j = 0; j < buffer.length; j += 4) {
  921. tempVertexData.positions[j] = buffer[j];
  922. tempVertexData.positions[j + 1] = buffer[j + 1];
  923. tempVertexData.positions[j + 2] = buffer[j + 2];
  924. }
  925. }
  926. else {
  927. tempVertexData.positions = new Float32Array(buffer.length);
  928. tempVertexData.positions.set(buffer);
  929. }
  930. verticesCounts.push(tempVertexData.positions.length);
  931. }
  932. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  933. var channel = Number(semantic.split("_")[1]);
  934. var uvKind = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  935. var uvs = new Float32Array(buffer.length);
  936. uvs.set(buffer);
  937. normalizeUVs(uvs);
  938. tempVertexData.set(uvs, uvKind);
  939. }
  940. else if (semantic === "JOINT") {
  941. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  942. tempVertexData.matricesIndices.set(buffer);
  943. }
  944. else if (semantic === "WEIGHT") {
  945. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  946. tempVertexData.matricesWeights.set(buffer);
  947. }
  948. else if (semantic === "COLOR") {
  949. tempVertexData.colors = new Float32Array(buffer.length);
  950. tempVertexData.colors.set(buffer);
  951. }
  952. }
  953. // Indices
  954. accessor = gltfRuntime.accessors[primitive.indices];
  955. if (accessor) {
  956. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  957. tempVertexData.indices = new Int32Array(buffer.length);
  958. tempVertexData.indices.set(buffer);
  959. indexCounts.push(tempVertexData.indices.length);
  960. }
  961. else {
  962. // Set indices on the fly
  963. var indices = [];
  964. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  965. indices.push(j);
  966. }
  967. tempVertexData.indices = new Int32Array(indices);
  968. indexCounts.push(tempVertexData.indices.length);
  969. }
  970. if (!vertexData) {
  971. vertexData = tempVertexData;
  972. }
  973. else {
  974. vertexData.merge(tempVertexData);
  975. }
  976. // Sub material
  977. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  978. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  979. // Update vertices start and index start
  980. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  981. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  982. }
  983. }
  984. var material;
  985. if (subMaterials.length > 1) {
  986. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  987. material.subMaterials = subMaterials;
  988. }
  989. else {
  990. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  991. }
  992. if (subMaterials.length === 1) {
  993. material = subMaterials[0];
  994. }
  995. if (!newMesh.material) {
  996. newMesh.material = material;
  997. }
  998. // Apply geometry
  999. new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  1000. newMesh.computeWorldMatrix(true);
  1001. // Apply submeshes
  1002. newMesh.subMeshes = [];
  1003. var index = 0;
  1004. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  1005. var meshID = meshes[meshIndex];
  1006. var mesh = gltfRuntime.meshes[meshID];
  1007. if (!mesh) {
  1008. continue;
  1009. }
  1010. for (var i = 0; i < mesh.primitives.length; i++) {
  1011. if (mesh.primitives[i].mode !== 4) {
  1012. //continue;
  1013. }
  1014. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  1015. index++;
  1016. }
  1017. }
  1018. // Finish
  1019. return newMesh;
  1020. };
  1021. /**
  1022. * Configure node transformation from position, rotation and scaling
  1023. */
  1024. var configureNode = function (newNode, position, rotation, scaling) {
  1025. if (newNode.position) {
  1026. newNode.position = position;
  1027. }
  1028. if (newNode.rotationQuaternion || newNode.rotation) {
  1029. newNode.rotationQuaternion = rotation;
  1030. }
  1031. if (newNode.scaling) {
  1032. newNode.scaling = scaling;
  1033. }
  1034. };
  1035. /**
  1036. * Configures node from transformation matrix
  1037. */
  1038. var configureNodeFromMatrix = function (newNode, node, parent) {
  1039. if (node.matrix) {
  1040. var position = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  1041. var rotation = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1042. var scaling = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  1043. var mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1044. mat.decompose(scaling, rotation, position);
  1045. configureNode(newNode, position, rotation, scaling);
  1046. }
  1047. else if (node.translation && node.rotation && node.scale) {
  1048. configureNode(newNode, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale));
  1049. }
  1050. newNode.computeWorldMatrix(true);
  1051. };
  1052. /**
  1053. * Imports a node
  1054. */
  1055. var importNode = function (gltfRuntime, node, id, parent) {
  1056. var lastNode = null;
  1057. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  1058. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  1059. return null;
  1060. }
  1061. }
  1062. // Meshes
  1063. if (node.skin) {
  1064. if (node.meshes) {
  1065. var skin = gltfRuntime.skins[node.skin];
  1066. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  1067. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  1068. if (newMesh.skeleton === null) {
  1069. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  1070. if (!skin.babylonSkeleton) {
  1071. skin.babylonSkeleton = newMesh.skeleton;
  1072. }
  1073. }
  1074. lastNode = newMesh;
  1075. }
  1076. }
  1077. else if (node.meshes) {
  1078. /**
  1079. * Improve meshes property
  1080. */
  1081. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  1082. lastNode = newMesh;
  1083. }
  1084. // Lights
  1085. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1086. var light = gltfRuntime.lights[node.light];
  1087. if (light) {
  1088. if (light.type === "ambient") {
  1089. var ambienLight = light[light.type];
  1090. var hemiLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  1091. hemiLight.name = node.name || "";
  1092. if (ambienLight.color) {
  1093. hemiLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  1094. }
  1095. lastNode = hemiLight;
  1096. }
  1097. else if (light.type === "directional") {
  1098. var directionalLight = light[light.type];
  1099. var dirLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  1100. dirLight.name = node.name || "";
  1101. if (directionalLight.color) {
  1102. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  1103. }
  1104. lastNode = dirLight;
  1105. }
  1106. else if (light.type === "point") {
  1107. var pointLight = light[light.type];
  1108. var ptLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  1109. ptLight.name = node.name || "";
  1110. if (pointLight.color) {
  1111. ptLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  1112. }
  1113. lastNode = ptLight;
  1114. }
  1115. else if (light.type === "spot") {
  1116. var spotLight = light[light.type];
  1117. var spLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["SpotLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), 0, 0, gltfRuntime.scene);
  1118. spLight.name = node.name || "";
  1119. if (spotLight.color) {
  1120. spLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  1121. }
  1122. if (spotLight.fallOfAngle) {
  1123. spLight.angle = spotLight.fallOfAngle;
  1124. }
  1125. if (spotLight.fallOffExponent) {
  1126. spLight.exponent = spotLight.fallOffExponent;
  1127. }
  1128. lastNode = spLight;
  1129. }
  1130. }
  1131. }
  1132. // Cameras
  1133. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  1134. var camera = gltfRuntime.cameras[node.camera];
  1135. if (camera) {
  1136. if (camera.type === "orthographic") {
  1137. var orthoCamera = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  1138. orthoCamera.name = node.name || "";
  1139. orthoCamera.mode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  1140. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  1141. lastNode = orthoCamera;
  1142. }
  1143. else if (camera.type === "perspective") {
  1144. var perspectiveCamera = camera[camera.type];
  1145. var persCamera = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  1146. persCamera.name = node.name || "";
  1147. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  1148. if (!perspectiveCamera.aspectRatio) {
  1149. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  1150. }
  1151. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  1152. persCamera.maxZ = perspectiveCamera.zfar;
  1153. persCamera.minZ = perspectiveCamera.znear;
  1154. }
  1155. lastNode = persCamera;
  1156. }
  1157. }
  1158. }
  1159. // Empty node
  1160. if (!node.jointName) {
  1161. if (node.babylonNode) {
  1162. return node.babylonNode;
  1163. }
  1164. else if (lastNode === null) {
  1165. var dummy = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  1166. node.babylonNode = dummy;
  1167. lastNode = dummy;
  1168. }
  1169. }
  1170. if (lastNode !== null) {
  1171. if (node.matrix && lastNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  1172. configureNodeFromMatrix(lastNode, node, parent);
  1173. }
  1174. else {
  1175. var translation = node.translation || [0, 0, 0];
  1176. var rotation = node.rotation || [0, 0, 0, 1];
  1177. var scale = node.scale || [1, 1, 1];
  1178. configureNode(lastNode, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(translation), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(rotation), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(scale));
  1179. }
  1180. lastNode.updateCache(true);
  1181. node.babylonNode = lastNode;
  1182. }
  1183. return lastNode;
  1184. };
  1185. /**
  1186. * Traverses nodes and creates them
  1187. */
  1188. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  1189. if (meshIncluded === void 0) { meshIncluded = false; }
  1190. var node = gltfRuntime.nodes[id];
  1191. var newNode = null;
  1192. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  1193. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  1194. meshIncluded = true;
  1195. }
  1196. else {
  1197. meshIncluded = false;
  1198. }
  1199. }
  1200. else {
  1201. meshIncluded = true;
  1202. }
  1203. if (!node.jointName && meshIncluded) {
  1204. newNode = importNode(gltfRuntime, node, id, parent);
  1205. if (newNode !== null) {
  1206. newNode.id = id;
  1207. newNode.parent = parent;
  1208. }
  1209. }
  1210. if (node.children) {
  1211. for (var i = 0; i < node.children.length; i++) {
  1212. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  1213. }
  1214. }
  1215. };
  1216. /**
  1217. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  1218. */
  1219. var postLoad = function (gltfRuntime) {
  1220. // Nodes
  1221. var currentScene = gltfRuntime.currentScene;
  1222. if (currentScene) {
  1223. for (var i = 0; i < currentScene.nodes.length; i++) {
  1224. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1225. }
  1226. }
  1227. else {
  1228. for (var thing in gltfRuntime.scenes) {
  1229. currentScene = gltfRuntime.scenes[thing];
  1230. for (var i = 0; i < currentScene.nodes.length; i++) {
  1231. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1232. }
  1233. }
  1234. }
  1235. // Set animations
  1236. loadAnimations(gltfRuntime);
  1237. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  1238. var skeleton = gltfRuntime.scene.skeletons[i];
  1239. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  1240. }
  1241. };
  1242. /**
  1243. * onBind shaderrs callback to set uniforms and matrices
  1244. */
  1245. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  1246. var materialValues = material.values || technique.parameters;
  1247. for (var unif in unTreatedUniforms) {
  1248. var uniform = unTreatedUniforms[unif];
  1249. var type = uniform.type;
  1250. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2 || type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3 || type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4) {
  1251. if (uniform.semantic && !uniform.source && !uniform.node) {
  1252. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  1253. }
  1254. else if (uniform.semantic && (uniform.source || uniform.node)) {
  1255. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  1256. if (source === null) {
  1257. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  1258. }
  1259. if (source === null) {
  1260. continue;
  1261. }
  1262. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  1263. }
  1264. }
  1265. else {
  1266. var value = materialValues[technique.uniforms[unif]];
  1267. if (!value) {
  1268. continue;
  1269. }
  1270. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  1271. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  1272. if (texture === null || texture === undefined) {
  1273. continue;
  1274. }
  1275. shaderMaterial.getEffect().setTexture(unif, texture);
  1276. }
  1277. else {
  1278. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  1279. }
  1280. }
  1281. }
  1282. onSuccess(shaderMaterial);
  1283. };
  1284. /**
  1285. * Prepare uniforms to send the only one time
  1286. * Loads the appropriate textures
  1287. */
  1288. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  1289. var materialValues = material.values || technique.parameters;
  1290. var techniqueUniforms = technique.uniforms;
  1291. /**
  1292. * Prepare values here (not matrices)
  1293. */
  1294. for (var unif in unTreatedUniforms) {
  1295. var uniform = unTreatedUniforms[unif];
  1296. var type = uniform.type;
  1297. var value = materialValues[techniqueUniforms[unif]];
  1298. if (value === undefined) {
  1299. // In case the value is the same for all materials
  1300. value = uniform.value;
  1301. }
  1302. if (!value) {
  1303. continue;
  1304. }
  1305. var onLoadTexture = function (uniformName) {
  1306. return function (texture) {
  1307. if (uniform.value && uniformName) {
  1308. // Static uniform
  1309. shaderMaterial.setTexture(uniformName, texture);
  1310. delete unTreatedUniforms[uniformName];
  1311. }
  1312. };
  1313. };
  1314. // Texture (sampler2D)
  1315. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  1316. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  1317. }
  1318. // Others
  1319. else {
  1320. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  1321. // Static uniform
  1322. delete unTreatedUniforms[unif];
  1323. }
  1324. }
  1325. }
  1326. };
  1327. /**
  1328. * Shader compilation failed
  1329. */
  1330. var onShaderCompileError = function (program, shaderMaterial, onError) {
  1331. return function (effect, error) {
  1332. shaderMaterial.dispose(true);
  1333. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  1334. };
  1335. };
  1336. /**
  1337. * Shader compilation success
  1338. */
  1339. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  1340. return function (_) {
  1341. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  1342. shaderMaterial.onBind = function (mesh) {
  1343. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  1344. };
  1345. };
  1346. };
  1347. /**
  1348. * Returns the appropriate uniform if already handled by babylon
  1349. */
  1350. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  1351. for (var unif in technique.uniforms) {
  1352. var uniform = technique.uniforms[unif];
  1353. var uniformParameter = technique.parameters[uniform];
  1354. if (tokenizer.currentIdentifier === unif) {
  1355. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  1356. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1357. if (transformIndex !== -1) {
  1358. delete unTreatedUniforms[unif];
  1359. return babylonTransforms[transformIndex];
  1360. }
  1361. }
  1362. }
  1363. }
  1364. return tokenizer.currentIdentifier;
  1365. };
  1366. /**
  1367. * All shaders loaded. Create materials one by one
  1368. */
  1369. var importMaterials = function (gltfRuntime) {
  1370. // Create materials
  1371. for (var mat in gltfRuntime.materials) {
  1372. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  1373. }
  1374. };
  1375. /**
  1376. * Implementation of the base glTF spec
  1377. * @hidden
  1378. */
  1379. var GLTFLoaderBase = /** @class */ (function () {
  1380. function GLTFLoaderBase() {
  1381. }
  1382. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  1383. var gltfRuntime = {
  1384. extensions: {},
  1385. accessors: {},
  1386. buffers: {},
  1387. bufferViews: {},
  1388. meshes: {},
  1389. lights: {},
  1390. cameras: {},
  1391. nodes: {},
  1392. images: {},
  1393. textures: {},
  1394. shaders: {},
  1395. programs: {},
  1396. samplers: {},
  1397. techniques: {},
  1398. materials: {},
  1399. animations: {},
  1400. skins: {},
  1401. extensionsUsed: [],
  1402. scenes: {},
  1403. buffersCount: 0,
  1404. shaderscount: 0,
  1405. scene: scene,
  1406. rootUrl: rootUrl,
  1407. loadedBufferCount: 0,
  1408. loadedBufferViews: {},
  1409. loadedShaderCount: 0,
  1410. importOnlyMeshes: false,
  1411. dummyNodes: []
  1412. };
  1413. // Parse
  1414. if (parsedData.extensions) {
  1415. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  1416. }
  1417. if (parsedData.extensionsUsed) {
  1418. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  1419. }
  1420. if (parsedData.buffers) {
  1421. parseBuffers(parsedData.buffers, gltfRuntime);
  1422. }
  1423. if (parsedData.bufferViews) {
  1424. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  1425. }
  1426. if (parsedData.accessors) {
  1427. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  1428. }
  1429. if (parsedData.meshes) {
  1430. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  1431. }
  1432. if (parsedData.lights) {
  1433. parseObject(parsedData.lights, "lights", gltfRuntime);
  1434. }
  1435. if (parsedData.cameras) {
  1436. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  1437. }
  1438. if (parsedData.nodes) {
  1439. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  1440. }
  1441. if (parsedData.images) {
  1442. parseObject(parsedData.images, "images", gltfRuntime);
  1443. }
  1444. if (parsedData.textures) {
  1445. parseObject(parsedData.textures, "textures", gltfRuntime);
  1446. }
  1447. if (parsedData.shaders) {
  1448. parseShaders(parsedData.shaders, gltfRuntime);
  1449. }
  1450. if (parsedData.programs) {
  1451. parseObject(parsedData.programs, "programs", gltfRuntime);
  1452. }
  1453. if (parsedData.samplers) {
  1454. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  1455. }
  1456. if (parsedData.techniques) {
  1457. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  1458. }
  1459. if (parsedData.materials) {
  1460. parseObject(parsedData.materials, "materials", gltfRuntime);
  1461. }
  1462. if (parsedData.animations) {
  1463. parseObject(parsedData.animations, "animations", gltfRuntime);
  1464. }
  1465. if (parsedData.skins) {
  1466. parseObject(parsedData.skins, "skins", gltfRuntime);
  1467. }
  1468. if (parsedData.scenes) {
  1469. gltfRuntime.scenes = parsedData.scenes;
  1470. }
  1471. if (parsedData.scene && parsedData.scenes) {
  1472. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  1473. }
  1474. return gltfRuntime;
  1475. };
  1476. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1477. var buffer = gltfRuntime.buffers[id];
  1478. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  1479. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  1480. }
  1481. else {
  1482. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, undefined, true, function (request) {
  1483. if (request) {
  1484. onError(request.status + " " + request.statusText);
  1485. }
  1486. });
  1487. }
  1488. };
  1489. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1490. var texture = gltfRuntime.textures[id];
  1491. if (!texture || !texture.source) {
  1492. onError("");
  1493. return;
  1494. }
  1495. if (texture.babylonTexture) {
  1496. onSuccess(null);
  1497. return;
  1498. }
  1499. var source = gltfRuntime.images[texture.source];
  1500. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  1501. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  1502. }
  1503. else {
  1504. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, undefined, undefined, true, function (request) {
  1505. if (request) {
  1506. onError(request.status + " " + request.statusText);
  1507. }
  1508. });
  1509. }
  1510. };
  1511. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  1512. var texture = gltfRuntime.textures[id];
  1513. if (texture.babylonTexture) {
  1514. onSuccess(texture.babylonTexture);
  1515. return;
  1516. }
  1517. var sampler = gltfRuntime.samplers[texture.sampler];
  1518. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  1519. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  1520. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  1521. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  1522. var samplingMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  1523. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  1524. var blobURL = URL.createObjectURL(blob);
  1525. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  1526. var newTexture = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  1527. if (sampler.wrapS !== undefined) {
  1528. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  1529. }
  1530. if (sampler.wrapT !== undefined) {
  1531. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  1532. }
  1533. newTexture.name = id;
  1534. texture.babylonTexture = newTexture;
  1535. onSuccess(newTexture);
  1536. };
  1537. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1538. var shader = gltfRuntime.shaders[id];
  1539. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  1540. var shaderString = atob(shader.uri.split(",")[1]);
  1541. if (onSuccess) {
  1542. onSuccess(shaderString);
  1543. }
  1544. }
  1545. else {
  1546. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  1547. if (request && onError) {
  1548. onError(request.status + " " + request.statusText);
  1549. }
  1550. });
  1551. }
  1552. };
  1553. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  1554. var material = gltfRuntime.materials[id];
  1555. if (!material.technique) {
  1556. if (onError) {
  1557. onError("No technique found.");
  1558. }
  1559. return;
  1560. }
  1561. var technique = gltfRuntime.techniques[material.technique];
  1562. if (!technique) {
  1563. var defaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  1564. defaultMaterial.diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  1565. defaultMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  1566. onSuccess(defaultMaterial);
  1567. return;
  1568. }
  1569. var program = gltfRuntime.programs[technique.program];
  1570. var states = technique.states;
  1571. var vertexShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  1572. var pixelShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  1573. var newVertexShader = "";
  1574. var newPixelShader = "";
  1575. var vertexTokenizer = new Tokenizer(vertexShader);
  1576. var pixelTokenizer = new Tokenizer(pixelShader);
  1577. var unTreatedUniforms = {};
  1578. var uniforms = [];
  1579. var attributes = [];
  1580. var samplers = [];
  1581. // Fill uniform, sampler2D and attributes
  1582. for (var unif in technique.uniforms) {
  1583. var uniform = technique.uniforms[unif];
  1584. var uniformParameter = technique.parameters[uniform];
  1585. unTreatedUniforms[unif] = uniformParameter;
  1586. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  1587. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  1588. if (transformIndex !== -1) {
  1589. uniforms.push(babylonTransforms[transformIndex]);
  1590. delete unTreatedUniforms[unif];
  1591. }
  1592. else {
  1593. uniforms.push(unif);
  1594. }
  1595. }
  1596. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  1597. samplers.push(unif);
  1598. }
  1599. else {
  1600. uniforms.push(unif);
  1601. }
  1602. }
  1603. for (var attr in technique.attributes) {
  1604. var attribute = technique.attributes[attr];
  1605. var attributeParameter = technique.parameters[attribute];
  1606. if (attributeParameter.semantic) {
  1607. var name_1 = getAttribute(attributeParameter);
  1608. if (name_1) {
  1609. attributes.push(name_1);
  1610. }
  1611. }
  1612. }
  1613. // Configure vertex shader
  1614. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  1615. var tokenType = vertexTokenizer.currentToken;
  1616. if (tokenType !== ETokenType.IDENTIFIER) {
  1617. newVertexShader += vertexTokenizer.currentString;
  1618. continue;
  1619. }
  1620. var foundAttribute = false;
  1621. for (var attr in technique.attributes) {
  1622. var attribute = technique.attributes[attr];
  1623. var attributeParameter = technique.parameters[attribute];
  1624. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  1625. newVertexShader += getAttribute(attributeParameter);
  1626. foundAttribute = true;
  1627. break;
  1628. }
  1629. }
  1630. if (foundAttribute) {
  1631. continue;
  1632. }
  1633. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  1634. }
  1635. // Configure pixel shader
  1636. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  1637. var tokenType = pixelTokenizer.currentToken;
  1638. if (tokenType !== ETokenType.IDENTIFIER) {
  1639. newPixelShader += pixelTokenizer.currentString;
  1640. continue;
  1641. }
  1642. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  1643. }
  1644. // Create shader material
  1645. var shaderPath = {
  1646. vertex: program.vertexShader + id,
  1647. fragment: program.fragmentShader + id
  1648. };
  1649. var options = {
  1650. attributes: attributes,
  1651. uniforms: uniforms,
  1652. samplers: samplers,
  1653. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  1654. };
  1655. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  1656. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  1657. var shaderMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  1658. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  1659. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  1660. shaderMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  1661. if (states && states.functions) {
  1662. var functions = states.functions;
  1663. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  1664. shaderMaterial.backFaceCulling = false;
  1665. }
  1666. var blendFunc = functions.blendFuncSeparate;
  1667. if (blendFunc) {
  1668. if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].SRC_ALPHA && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE_MINUS_SRC_ALPHA && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1669. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  1670. }
  1671. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1672. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  1673. }
  1674. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].SRC_ALPHA && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1675. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  1676. }
  1677. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE_MINUS_SRC_COLOR && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1678. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  1679. }
  1680. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].DST_COLOR && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ZERO && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1681. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  1682. }
  1683. else if (blendFunc[0] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].SRC_ALPHA && blendFunc[1] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE_MINUS_SRC_COLOR && blendFunc[2] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE && blendFunc[3] === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EBlendingFunction"].ONE) {
  1684. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  1685. }
  1686. }
  1687. }
  1688. };
  1689. return GLTFLoaderBase;
  1690. }());
  1691. /**
  1692. * glTF V1 Loader
  1693. * @hidden
  1694. */
  1695. var GLTFLoader = /** @class */ (function () {
  1696. function GLTFLoader() {
  1697. this.state = null;
  1698. }
  1699. GLTFLoader.RegisterExtension = function (extension) {
  1700. if (GLTFLoader.Extensions[extension.name]) {
  1701. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  1702. return;
  1703. }
  1704. GLTFLoader.Extensions[extension.name] = extension;
  1705. };
  1706. GLTFLoader.prototype.dispose = function () {
  1707. // do nothing
  1708. };
  1709. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  1710. var _this = this;
  1711. scene.useRightHandedSystem = true;
  1712. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1713. gltfRuntime.importOnlyMeshes = true;
  1714. if (meshesNames === "") {
  1715. gltfRuntime.importMeshesNames = [];
  1716. }
  1717. else if (typeof meshesNames === "string") {
  1718. gltfRuntime.importMeshesNames = [meshesNames];
  1719. }
  1720. else if (meshesNames && !(meshesNames instanceof Array)) {
  1721. gltfRuntime.importMeshesNames = [meshesNames];
  1722. }
  1723. else {
  1724. gltfRuntime.importMeshesNames = [];
  1725. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  1726. }
  1727. // Create nodes
  1728. _this._createNodes(gltfRuntime);
  1729. var meshes = new Array();
  1730. var skeletons = new Array();
  1731. // Fill arrays of meshes and skeletons
  1732. for (var nde in gltfRuntime.nodes) {
  1733. var node = gltfRuntime.nodes[nde];
  1734. if (node.babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  1735. meshes.push(node.babylonNode);
  1736. }
  1737. }
  1738. for (var skl in gltfRuntime.skins) {
  1739. var skin = gltfRuntime.skins[skl];
  1740. if (skin.babylonSkeleton instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  1741. skeletons.push(skin.babylonSkeleton);
  1742. }
  1743. }
  1744. // Load buffers, shaders, materials, etc.
  1745. _this._loadBuffersAsync(gltfRuntime, function () {
  1746. _this._loadShadersAsync(gltfRuntime, function () {
  1747. importMaterials(gltfRuntime);
  1748. postLoad(gltfRuntime);
  1749. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  1750. onSuccess(meshes, skeletons);
  1751. }
  1752. });
  1753. }, onProgress);
  1754. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  1755. onSuccess(meshes, skeletons);
  1756. }
  1757. }, onError);
  1758. return true;
  1759. };
  1760. /**
  1761. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  1762. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  1763. * @param scene the scene the meshes should be added to
  1764. * @param data gltf data containing information of the meshes in a loaded file
  1765. * @param rootUrl root url to load from
  1766. * @param onProgress event that fires when loading progress has occured
  1767. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  1768. */
  1769. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  1770. var _this = this;
  1771. return new Promise(function (resolve, reject) {
  1772. _this._importMeshAsync(meshesNames, scene, data, rootUrl, function (meshes, skeletons) {
  1773. resolve({
  1774. meshes: meshes,
  1775. particleSystems: [],
  1776. skeletons: skeletons,
  1777. animationGroups: []
  1778. });
  1779. }, onProgress, function (message) {
  1780. reject(new Error(message));
  1781. });
  1782. });
  1783. };
  1784. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  1785. var _this = this;
  1786. scene.useRightHandedSystem = true;
  1787. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  1788. // Load runtime extensios
  1789. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  1790. // Create nodes
  1791. _this._createNodes(gltfRuntime);
  1792. // Load buffers, shaders, materials, etc.
  1793. _this._loadBuffersAsync(gltfRuntime, function () {
  1794. _this._loadShadersAsync(gltfRuntime, function () {
  1795. importMaterials(gltfRuntime);
  1796. postLoad(gltfRuntime);
  1797. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  1798. onSuccess();
  1799. }
  1800. });
  1801. });
  1802. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  1803. onSuccess();
  1804. }
  1805. }, onError);
  1806. }, onError);
  1807. };
  1808. /**
  1809. * Imports all objects from a loaded gltf file and adds them to the scene
  1810. * @param scene the scene the objects should be added to
  1811. * @param data gltf data containing information of the meshes in a loaded file
  1812. * @param rootUrl root url to load from
  1813. * @param onProgress event that fires when loading progress has occured
  1814. * @returns a promise which completes when objects have been loaded to the scene
  1815. */
  1816. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  1817. var _this = this;
  1818. return new Promise(function (resolve, reject) {
  1819. _this._loadAsync(scene, data, rootUrl, function () {
  1820. resolve();
  1821. }, onProgress, function (message) {
  1822. reject(new Error(message));
  1823. });
  1824. });
  1825. };
  1826. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  1827. var hasShaders = false;
  1828. var processShader = function (sha, shader) {
  1829. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  1830. if (shaderString instanceof ArrayBuffer) {
  1831. return;
  1832. }
  1833. gltfRuntime.loadedShaderCount++;
  1834. if (shaderString) {
  1835. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  1836. }
  1837. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  1838. onload();
  1839. }
  1840. }, function () {
  1841. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  1842. });
  1843. };
  1844. for (var sha in gltfRuntime.shaders) {
  1845. hasShaders = true;
  1846. var shader = gltfRuntime.shaders[sha];
  1847. if (shader) {
  1848. processShader.bind(this, sha, shader)();
  1849. }
  1850. else {
  1851. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  1852. }
  1853. }
  1854. if (!hasShaders) {
  1855. onload();
  1856. }
  1857. };
  1858. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  1859. var hasBuffers = false;
  1860. var processBuffer = function (buf, buffer) {
  1861. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  1862. gltfRuntime.loadedBufferCount++;
  1863. if (bufferView) {
  1864. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  1865. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  1866. }
  1867. gltfRuntime.loadedBufferViews[buf] = bufferView;
  1868. }
  1869. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  1870. onLoad();
  1871. }
  1872. }, function () {
  1873. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  1874. });
  1875. };
  1876. for (var buf in gltfRuntime.buffers) {
  1877. hasBuffers = true;
  1878. var buffer = gltfRuntime.buffers[buf];
  1879. if (buffer) {
  1880. processBuffer.bind(this, buf, buffer)();
  1881. }
  1882. else {
  1883. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  1884. }
  1885. }
  1886. if (!hasBuffers) {
  1887. onLoad();
  1888. }
  1889. };
  1890. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  1891. var currentScene = gltfRuntime.currentScene;
  1892. if (currentScene) {
  1893. // Only one scene even if multiple scenes are defined
  1894. for (var i = 0; i < currentScene.nodes.length; i++) {
  1895. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1896. }
  1897. }
  1898. else {
  1899. // Load all scenes
  1900. for (var thing in gltfRuntime.scenes) {
  1901. currentScene = gltfRuntime.scenes[thing];
  1902. for (var i = 0; i < currentScene.nodes.length; i++) {
  1903. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  1904. }
  1905. }
  1906. }
  1907. };
  1908. GLTFLoader.Extensions = {};
  1909. return GLTFLoader;
  1910. }());
  1911. /** @hidden */
  1912. var GLTFLoaderExtension = /** @class */ (function () {
  1913. function GLTFLoaderExtension(name) {
  1914. this._name = name;
  1915. }
  1916. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  1917. get: function () {
  1918. return this._name;
  1919. },
  1920. enumerable: true,
  1921. configurable: true
  1922. });
  1923. /**
  1924. * Defines an override for loading the runtime
  1925. * Return true to stop further extensions from loading the runtime
  1926. */
  1927. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1928. return false;
  1929. };
  1930. /**
  1931. * Defines an onverride for creating gltf runtime
  1932. * Return true to stop further extensions from creating the runtime
  1933. */
  1934. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  1935. return false;
  1936. };
  1937. /**
  1938. * Defines an override for loading buffers
  1939. * Return true to stop further extensions from loading this buffer
  1940. */
  1941. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1942. return false;
  1943. };
  1944. /**
  1945. * Defines an override for loading texture buffers
  1946. * Return true to stop further extensions from loading this texture data
  1947. */
  1948. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1949. return false;
  1950. };
  1951. /**
  1952. * Defines an override for creating textures
  1953. * Return true to stop further extensions from loading this texture
  1954. */
  1955. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  1956. return false;
  1957. };
  1958. /**
  1959. * Defines an override for loading shader strings
  1960. * Return true to stop further extensions from loading this shader data
  1961. */
  1962. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1963. return false;
  1964. };
  1965. /**
  1966. * Defines an override for loading materials
  1967. * Return true to stop further extensions from loading this material
  1968. */
  1969. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  1970. return false;
  1971. };
  1972. // ---------
  1973. // Utilities
  1974. // ---------
  1975. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1976. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  1977. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  1978. }, function () {
  1979. setTimeout(function () {
  1980. if (!onSuccess) {
  1981. return;
  1982. }
  1983. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  1984. });
  1985. });
  1986. };
  1987. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  1988. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  1989. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  1990. }, function () {
  1991. setTimeout(function () {
  1992. onSuccess();
  1993. });
  1994. });
  1995. };
  1996. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  1997. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  1998. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  1999. }, function () {
  2000. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  2001. });
  2002. };
  2003. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  2004. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  2005. if (buffer) {
  2006. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2007. }
  2008. }, onError);
  2009. };
  2010. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2011. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2012. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2013. }, function () {
  2014. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  2015. });
  2016. };
  2017. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2018. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2019. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2020. }, function () {
  2021. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  2022. });
  2023. };
  2024. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2025. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2026. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2027. }, function () {
  2028. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  2029. });
  2030. };
  2031. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2032. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  2033. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2034. }, function () {
  2035. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  2036. });
  2037. };
  2038. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  2039. for (var extensionName in GLTFLoader.Extensions) {
  2040. var loaderExtension = GLTFLoader.Extensions[extensionName];
  2041. if (func(loaderExtension)) {
  2042. return;
  2043. }
  2044. }
  2045. defaultFunc();
  2046. };
  2047. return GLTFLoaderExtension;
  2048. }());
  2049. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  2050. /***/ }),
  2051. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  2052. /*!******************************************!*\
  2053. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  2054. \******************************************/
  2055. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  2056. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2057. "use strict";
  2058. __webpack_require__.r(__webpack_exports__);
  2059. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  2060. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  2061. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  2062. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  2063. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  2064. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  2065. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  2066. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  2067. /**
  2068. * Enums
  2069. * @hidden
  2070. */
  2071. var EComponentType;
  2072. (function (EComponentType) {
  2073. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  2074. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  2075. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  2076. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  2077. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  2078. })(EComponentType || (EComponentType = {}));
  2079. /** @hidden */
  2080. var EShaderType;
  2081. (function (EShaderType) {
  2082. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  2083. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  2084. })(EShaderType || (EShaderType = {}));
  2085. /** @hidden */
  2086. var EParameterType;
  2087. (function (EParameterType) {
  2088. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  2089. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  2090. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  2091. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  2092. EParameterType[EParameterType["INT"] = 5124] = "INT";
  2093. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  2094. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  2095. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  2096. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  2097. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  2098. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  2099. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  2100. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  2101. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  2102. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  2103. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  2104. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  2105. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  2106. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  2107. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  2108. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  2109. })(EParameterType || (EParameterType = {}));
  2110. /** @hidden */
  2111. var ETextureWrapMode;
  2112. (function (ETextureWrapMode) {
  2113. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  2114. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  2115. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  2116. })(ETextureWrapMode || (ETextureWrapMode = {}));
  2117. /** @hidden */
  2118. var ETextureFilterType;
  2119. (function (ETextureFilterType) {
  2120. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  2121. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  2122. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  2123. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  2124. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  2125. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  2126. })(ETextureFilterType || (ETextureFilterType = {}));
  2127. /** @hidden */
  2128. var ETextureFormat;
  2129. (function (ETextureFormat) {
  2130. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  2131. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  2132. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  2133. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  2134. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  2135. })(ETextureFormat || (ETextureFormat = {}));
  2136. /** @hidden */
  2137. var ECullingType;
  2138. (function (ECullingType) {
  2139. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  2140. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  2141. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  2142. })(ECullingType || (ECullingType = {}));
  2143. /** @hidden */
  2144. var EBlendingFunction;
  2145. (function (EBlendingFunction) {
  2146. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  2147. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  2148. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  2149. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  2150. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  2151. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  2152. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  2153. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  2154. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  2155. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  2156. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  2157. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  2158. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  2159. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  2160. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  2161. })(EBlendingFunction || (EBlendingFunction = {}));
  2162. /***/ }),
  2163. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  2164. /*!*************************************!*\
  2165. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  2166. \*************************************/
  2167. /*! exports provided: GLTFUtils */
  2168. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2169. "use strict";
  2170. __webpack_require__.r(__webpack_exports__);
  2171. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  2172. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  2173. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  2174. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  2175. /**
  2176. * Utils functions for GLTF
  2177. * @hidden
  2178. */
  2179. var GLTFUtils = /** @class */ (function () {
  2180. function GLTFUtils() {
  2181. }
  2182. /**
  2183. * Sets the given "parameter" matrix
  2184. * @param scene: the Scene object
  2185. * @param source: the source node where to pick the matrix
  2186. * @param parameter: the GLTF technique parameter
  2187. * @param uniformName: the name of the shader's uniform
  2188. * @param shaderMaterial: the shader material
  2189. */
  2190. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  2191. var mat = null;
  2192. if (parameter.semantic === "MODEL") {
  2193. mat = source.getWorldMatrix();
  2194. }
  2195. else if (parameter.semantic === "PROJECTION") {
  2196. mat = scene.getProjectionMatrix();
  2197. }
  2198. else if (parameter.semantic === "VIEW") {
  2199. mat = scene.getViewMatrix();
  2200. }
  2201. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  2202. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  2203. }
  2204. else if (parameter.semantic === "MODELVIEW") {
  2205. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  2206. }
  2207. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  2208. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  2209. }
  2210. else if (parameter.semantic === "MODELINVERSE") {
  2211. mat = source.getWorldMatrix().invert();
  2212. }
  2213. else if (parameter.semantic === "VIEWINVERSE") {
  2214. mat = scene.getViewMatrix().invert();
  2215. }
  2216. else if (parameter.semantic === "PROJECTIONINVERSE") {
  2217. mat = scene.getProjectionMatrix().invert();
  2218. }
  2219. else if (parameter.semantic === "MODELVIEWINVERSE") {
  2220. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  2221. }
  2222. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  2223. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  2224. }
  2225. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  2226. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  2227. }
  2228. else {
  2229. debugger;
  2230. }
  2231. if (mat) {
  2232. switch (parameter.type) {
  2233. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  2234. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  2235. break;
  2236. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  2237. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  2238. break;
  2239. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  2240. shaderMaterial.setMatrix(uniformName, mat);
  2241. break;
  2242. default: break;
  2243. }
  2244. }
  2245. };
  2246. /**
  2247. * Sets the given "parameter" matrix
  2248. * @param shaderMaterial: the shader material
  2249. * @param uniform: the name of the shader's uniform
  2250. * @param value: the value of the uniform
  2251. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  2252. */
  2253. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  2254. switch (type) {
  2255. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  2256. shaderMaterial.setFloat(uniform, value);
  2257. return true;
  2258. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  2259. shaderMaterial.setVector2(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  2260. return true;
  2261. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  2262. shaderMaterial.setVector3(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  2263. return true;
  2264. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  2265. shaderMaterial.setVector4(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  2266. return true;
  2267. default: return false;
  2268. }
  2269. };
  2270. /**
  2271. * Returns the wrap mode of the texture
  2272. * @param mode: the mode value
  2273. */
  2274. GLTFUtils.GetWrapMode = function (mode) {
  2275. switch (mode) {
  2276. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  2277. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  2278. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  2279. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  2280. }
  2281. };
  2282. /**
  2283. * Returns the byte stride giving an accessor
  2284. * @param accessor: the GLTF accessor objet
  2285. */
  2286. GLTFUtils.GetByteStrideFromType = function (accessor) {
  2287. // Needs this function since "byteStride" isn't requiered in glTF format
  2288. var type = accessor.type;
  2289. switch (type) {
  2290. case "VEC2": return 2;
  2291. case "VEC3": return 3;
  2292. case "VEC4": return 4;
  2293. case "MAT2": return 4;
  2294. case "MAT3": return 9;
  2295. case "MAT4": return 16;
  2296. default: return 1;
  2297. }
  2298. };
  2299. /**
  2300. * Returns the texture filter mode giving a mode value
  2301. * @param mode: the filter mode value
  2302. */
  2303. GLTFUtils.GetTextureFilterMode = function (mode) {
  2304. switch (mode) {
  2305. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  2306. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  2307. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  2308. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  2309. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  2310. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2311. }
  2312. };
  2313. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  2314. var byteOffset = bufferView.byteOffset + byteOffset;
  2315. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  2316. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  2317. throw new Error("Buffer access is out of range");
  2318. }
  2319. var buffer = loadedBufferView.buffer;
  2320. byteOffset += loadedBufferView.byteOffset;
  2321. switch (componentType) {
  2322. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  2323. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  2324. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  2325. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  2326. default: return new Float32Array(buffer, byteOffset, byteLength);
  2327. }
  2328. };
  2329. /**
  2330. * Returns a buffer from its accessor
  2331. * @param gltfRuntime: the GLTF runtime
  2332. * @param accessor: the GLTF accessor
  2333. */
  2334. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  2335. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  2336. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  2337. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  2338. };
  2339. /**
  2340. * Decodes a buffer view into a string
  2341. * @param view: the buffer view
  2342. */
  2343. GLTFUtils.DecodeBufferToText = function (view) {
  2344. var result = "";
  2345. var length = view.byteLength;
  2346. for (var i = 0; i < length; ++i) {
  2347. result += String.fromCharCode(view[i]);
  2348. }
  2349. return result;
  2350. };
  2351. /**
  2352. * Returns the default material of gltf. Related to
  2353. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  2354. * @param scene: the Babylon.js scene
  2355. */
  2356. GLTFUtils.GetDefaultMaterial = function (scene) {
  2357. if (!GLTFUtils._DefaultMaterial) {
  2358. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  2359. "precision highp float;",
  2360. "",
  2361. "uniform mat4 worldView;",
  2362. "uniform mat4 projection;",
  2363. "",
  2364. "attribute vec3 position;",
  2365. "",
  2366. "void main(void)",
  2367. "{",
  2368. " gl_Position = projection * worldView * vec4(position, 1.0);",
  2369. "}"
  2370. ].join("\n");
  2371. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  2372. "precision highp float;",
  2373. "",
  2374. "uniform vec4 u_emission;",
  2375. "",
  2376. "void main(void)",
  2377. "{",
  2378. " gl_FragColor = u_emission;",
  2379. "}"
  2380. ].join("\n");
  2381. var shaderPath = {
  2382. vertex: "GLTFDefaultMaterial",
  2383. fragment: "GLTFDefaultMaterial"
  2384. };
  2385. var options = {
  2386. attributes: ["position"],
  2387. uniforms: ["worldView", "projection", "u_emission"],
  2388. samplers: new Array(),
  2389. needAlphaBlending: false
  2390. };
  2391. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  2392. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  2393. }
  2394. return GLTFUtils._DefaultMaterial;
  2395. };
  2396. // The GLTF default material
  2397. GLTFUtils._DefaultMaterial = null;
  2398. return GLTFUtils;
  2399. }());
  2400. /***/ }),
  2401. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  2402. /*!**************************************************!*\
  2403. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  2404. \**************************************************/
  2405. /*! exports provided: GLTFMaterialsCommonExtension */
  2406. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2407. "use strict";
  2408. __webpack_require__.r(__webpack_exports__);
  2409. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  2410. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  2411. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  2412. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  2413. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__);
  2414. /** @hidden */
  2415. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  2416. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  2417. function GLTFMaterialsCommonExtension() {
  2418. return _super.call(this, "KHR_materials_common") || this;
  2419. }
  2420. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  2421. if (!gltfRuntime.extensions) {
  2422. return false;
  2423. }
  2424. var extension = gltfRuntime.extensions[this.name];
  2425. if (!extension) {
  2426. return false;
  2427. }
  2428. // Create lights
  2429. var lights = extension.lights;
  2430. if (lights) {
  2431. for (var thing in lights) {
  2432. var light = lights[thing];
  2433. switch (light.type) {
  2434. case "ambient":
  2435. var ambientLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["HemisphericLight"](light.name, new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 1, 0), gltfRuntime.scene);
  2436. var ambient = light.ambient;
  2437. if (ambient) {
  2438. ambientLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  2439. }
  2440. break;
  2441. case "point":
  2442. var pointLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["PointLight"](light.name, new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Vector3"](10, 10, 10), gltfRuntime.scene);
  2443. var point = light.point;
  2444. if (point) {
  2445. pointLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  2446. }
  2447. break;
  2448. case "directional":
  2449. var dirLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["DirectionalLight"](light.name, new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), gltfRuntime.scene);
  2450. var directional = light.directional;
  2451. if (directional) {
  2452. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  2453. }
  2454. break;
  2455. case "spot":
  2456. var spot = light.spot;
  2457. if (spot) {
  2458. var spotLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["SpotLight"](light.name, new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 10, 0), new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
  2459. spotLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  2460. }
  2461. break;
  2462. default:
  2463. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  2464. break;
  2465. }
  2466. }
  2467. }
  2468. return false;
  2469. };
  2470. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2471. var material = gltfRuntime.materials[id];
  2472. if (!material || !material.extensions) {
  2473. return false;
  2474. }
  2475. var extension = material.extensions[this.name];
  2476. if (!extension) {
  2477. return false;
  2478. }
  2479. var standardMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  2480. standardMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  2481. if (extension.technique === "CONSTANT") {
  2482. standardMaterial.disableLighting = true;
  2483. }
  2484. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  2485. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  2486. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  2487. // Ambient
  2488. if (typeof extension.values.ambient === "string") {
  2489. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  2490. }
  2491. else {
  2492. standardMaterial.ambientColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  2493. }
  2494. // Diffuse
  2495. if (typeof extension.values.diffuse === "string") {
  2496. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  2497. }
  2498. else {
  2499. standardMaterial.diffuseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  2500. }
  2501. // Emission
  2502. if (typeof extension.values.emission === "string") {
  2503. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  2504. }
  2505. else {
  2506. standardMaterial.emissiveColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  2507. }
  2508. // Specular
  2509. if (typeof extension.values.specular === "string") {
  2510. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  2511. }
  2512. else {
  2513. standardMaterial.specularColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  2514. }
  2515. return true;
  2516. };
  2517. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  2518. // Create buffer from texture url
  2519. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  2520. // Create texture from buffer
  2521. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  2522. }, onError);
  2523. };
  2524. return GLTFMaterialsCommonExtension;
  2525. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  2526. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  2527. /***/ }),
  2528. /***/ "./glTF/1.0/index.ts":
  2529. /*!***************************!*\
  2530. !*** ./glTF/1.0/index.ts ***!
  2531. \***************************/
  2532. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  2533. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2534. "use strict";
  2535. __webpack_require__.r(__webpack_exports__);
  2536. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  2537. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  2538. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  2539. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  2540. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  2541. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  2542. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  2543. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  2544. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  2545. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  2546. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  2547. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  2548. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  2549. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  2550. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  2551. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  2552. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  2553. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  2554. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  2555. /***/ }),
  2556. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  2557. /*!*******************************************************!*\
  2558. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  2559. \*******************************************************/
  2560. /*! exports provided: EXT_lights_image_based */
  2561. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2562. "use strict";
  2563. __webpack_require__.r(__webpack_exports__);
  2564. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  2565. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  2566. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  2567. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2568. var NAME = "EXT_lights_image_based";
  2569. /**
  2570. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  2571. */
  2572. var EXT_lights_image_based = /** @class */ (function () {
  2573. /** @hidden */
  2574. function EXT_lights_image_based(loader) {
  2575. /**
  2576. * The name of this extension.
  2577. */
  2578. this.name = NAME;
  2579. this._loader = loader;
  2580. this.enabled = this._loader.isExtensionUsed(NAME);
  2581. }
  2582. /** @hidden */
  2583. EXT_lights_image_based.prototype.dispose = function () {
  2584. delete this._loader;
  2585. delete this._lights;
  2586. };
  2587. /** @hidden */
  2588. EXT_lights_image_based.prototype.onLoading = function () {
  2589. var extensions = this._loader.gltf.extensions;
  2590. if (extensions && extensions[this.name]) {
  2591. var extension = extensions[this.name];
  2592. this._lights = extension.lights;
  2593. }
  2594. };
  2595. /** @hidden */
  2596. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  2597. var _this = this;
  2598. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  2599. var promises = new Array();
  2600. promises.push(_this._loader.loadSceneAsync(context, scene));
  2601. _this._loader.logOpen("" + extensionContext);
  2602. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  2603. promises.push(_this._loadLightAsync("#/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  2604. _this._loader.babylonScene.environmentTexture = texture;
  2605. }));
  2606. _this._loader.logClose();
  2607. return Promise.all(promises).then(function () { });
  2608. });
  2609. };
  2610. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  2611. var _this = this;
  2612. if (!light._loaded) {
  2613. var promises = new Array();
  2614. this._loader.logOpen("" + context);
  2615. var imageData_1 = new Array(light.specularImages.length);
  2616. var _loop_1 = function (mipmap) {
  2617. var faces = light.specularImages[mipmap];
  2618. imageData_1[mipmap] = new Array(faces.length);
  2619. var _loop_2 = function (face) {
  2620. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  2621. this_1._loader.logOpen("" + specularImageContext);
  2622. var index = faces[face];
  2623. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  2624. promises.push(this_1._loader.loadImageAsync("#/images/" + index, image).then(function (data) {
  2625. imageData_1[mipmap][face] = data;
  2626. }));
  2627. this_1._loader.logClose();
  2628. };
  2629. for (var face = 0; face < faces.length; face++) {
  2630. _loop_2(face);
  2631. }
  2632. };
  2633. var this_1 = this;
  2634. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  2635. _loop_1(mipmap);
  2636. }
  2637. this._loader.logClose();
  2638. light._loaded = Promise.all(promises).then(function () {
  2639. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  2640. light._babylonTexture = babylonTexture;
  2641. if (light.intensity != undefined) {
  2642. babylonTexture.level = light.intensity;
  2643. }
  2644. if (light.rotation) {
  2645. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  2646. // Invert the rotation so that positive rotation is counter-clockwise.
  2647. if (!_this._loader.babylonScene.useRightHandedSystem) {
  2648. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  2649. }
  2650. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  2651. }
  2652. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  2653. sphericalHarmonics.scaleInPlace(light.intensity);
  2654. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  2655. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  2656. // Compute the lod generation scale to fit exactly to the number of levels available.
  2657. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  2658. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  2659. });
  2660. }
  2661. return light._loaded.then(function () {
  2662. return light._babylonTexture;
  2663. });
  2664. };
  2665. return EXT_lights_image_based;
  2666. }());
  2667. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  2668. /***/ }),
  2669. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  2670. /*!*************************************************!*\
  2671. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  2672. \*************************************************/
  2673. /*! exports provided: ExtrasAsMetadata */
  2674. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2675. "use strict";
  2676. __webpack_require__.r(__webpack_exports__);
  2677. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  2678. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2679. var NAME = "ExtrasAsMetadata";
  2680. /**
  2681. * Store glTF extras (if present) in BJS objects' metadata
  2682. */
  2683. var ExtrasAsMetadata = /** @class */ (function () {
  2684. /** @hidden */
  2685. function ExtrasAsMetadata(loader) {
  2686. /**
  2687. * The name of this extension.
  2688. */
  2689. this.name = NAME;
  2690. /**
  2691. * Defines whether this extension is enabled.
  2692. */
  2693. this.enabled = true;
  2694. this._loader = loader;
  2695. }
  2696. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  2697. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  2698. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  2699. var gltf = (metadata.gltf = metadata.gltf || {});
  2700. gltf.extras = gltfProp.extras;
  2701. }
  2702. };
  2703. /** @hidden */
  2704. ExtrasAsMetadata.prototype.dispose = function () {
  2705. delete this._loader;
  2706. };
  2707. /** @hidden */
  2708. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  2709. var _this = this;
  2710. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  2711. _this._assignExtras(babylonTransformNode, node);
  2712. assign(babylonTransformNode);
  2713. });
  2714. };
  2715. /** @hidden */
  2716. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  2717. var _this = this;
  2718. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  2719. _this._assignExtras(babylonCamera, camera);
  2720. assign(babylonCamera);
  2721. });
  2722. };
  2723. /** @hidden */
  2724. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  2725. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  2726. this._assignExtras(babylonMaterial, material);
  2727. return babylonMaterial;
  2728. };
  2729. return ExtrasAsMetadata;
  2730. }());
  2731. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  2732. /***/ }),
  2733. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  2734. /*!***********************************************************!*\
  2735. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  2736. \***********************************************************/
  2737. /*! exports provided: KHR_draco_mesh_compression */
  2738. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2739. "use strict";
  2740. __webpack_require__.r(__webpack_exports__);
  2741. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  2742. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  2743. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  2744. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2745. var NAME = "KHR_draco_mesh_compression";
  2746. /**
  2747. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  2748. */
  2749. var KHR_draco_mesh_compression = /** @class */ (function () {
  2750. /** @hidden */
  2751. function KHR_draco_mesh_compression(loader) {
  2752. /**
  2753. * The name of this extension.
  2754. */
  2755. this.name = NAME;
  2756. this._loader = loader;
  2757. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  2758. }
  2759. /** @hidden */
  2760. KHR_draco_mesh_compression.prototype.dispose = function () {
  2761. delete this.dracoCompression;
  2762. delete this._loader;
  2763. };
  2764. /** @hidden */
  2765. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  2766. var _this = this;
  2767. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  2768. if (primitive.mode != undefined) {
  2769. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  2770. primitive.mode !== 4 /* TRIANGLES */) {
  2771. throw new Error(context + ": Unsupported mode " + primitive.mode);
  2772. }
  2773. // TODO: handle triangle strips
  2774. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  2775. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  2776. }
  2777. }
  2778. var attributes = {};
  2779. var loadAttribute = function (name, kind) {
  2780. var uniqueId = extension.attributes[name];
  2781. if (uniqueId == undefined) {
  2782. return;
  2783. }
  2784. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  2785. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  2786. babylonMesh._delayInfo.push(kind);
  2787. }
  2788. attributes[kind] = uniqueId;
  2789. };
  2790. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  2791. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  2792. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  2793. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  2794. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  2795. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  2796. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  2797. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  2798. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  2799. if (!bufferView._dracoBabylonGeometry) {
  2800. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2801. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  2802. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  2803. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  2804. babylonVertexData.applyToGeometry(babylonGeometry);
  2805. return babylonGeometry;
  2806. }).catch(function (error) {
  2807. throw new Error(context + ": " + error.message);
  2808. });
  2809. });
  2810. }
  2811. return bufferView._dracoBabylonGeometry;
  2812. });
  2813. };
  2814. return KHR_draco_mesh_compression;
  2815. }());
  2816. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  2817. /***/ }),
  2818. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  2819. /*!****************************************************!*\
  2820. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  2821. \****************************************************/
  2822. /*! exports provided: KHR_lights */
  2823. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2824. "use strict";
  2825. __webpack_require__.r(__webpack_exports__);
  2826. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  2827. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  2828. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  2829. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2830. var NAME = "KHR_lights_punctual";
  2831. var LightType;
  2832. (function (LightType) {
  2833. LightType["DIRECTIONAL"] = "directional";
  2834. LightType["POINT"] = "point";
  2835. LightType["SPOT"] = "spot";
  2836. })(LightType || (LightType = {}));
  2837. /**
  2838. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  2839. */
  2840. var KHR_lights = /** @class */ (function () {
  2841. /** @hidden */
  2842. function KHR_lights(loader) {
  2843. /**
  2844. * The name of this extension.
  2845. */
  2846. this.name = NAME;
  2847. this._loader = loader;
  2848. this.enabled = this._loader.isExtensionUsed(NAME);
  2849. }
  2850. /** @hidden */
  2851. KHR_lights.prototype.dispose = function () {
  2852. delete this._loader;
  2853. delete this._lights;
  2854. };
  2855. /** @hidden */
  2856. KHR_lights.prototype.onLoading = function () {
  2857. var extensions = this._loader.gltf.extensions;
  2858. if (extensions && extensions[this.name]) {
  2859. var extension = extensions[this.name];
  2860. this._lights = extension.lights;
  2861. }
  2862. };
  2863. /** @hidden */
  2864. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  2865. var _this = this;
  2866. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  2867. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  2868. var babylonLight;
  2869. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  2870. var name = light.name || babylonMesh.name;
  2871. switch (light.type) {
  2872. case LightType.DIRECTIONAL: {
  2873. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  2874. break;
  2875. }
  2876. case LightType.POINT: {
  2877. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  2878. break;
  2879. }
  2880. case LightType.SPOT: {
  2881. var babylonSpotLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  2882. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  2883. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  2884. babylonLight = babylonSpotLight;
  2885. break;
  2886. }
  2887. default: {
  2888. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  2889. }
  2890. }
  2891. babylonLight.falloffType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  2892. babylonLight.diffuse = light.color ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  2893. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  2894. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  2895. babylonLight.parent = babylonMesh;
  2896. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  2897. assign(babylonMesh);
  2898. });
  2899. });
  2900. };
  2901. return KHR_lights;
  2902. }());
  2903. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  2904. /***/ }),
  2905. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  2906. /*!********************************************************!*\
  2907. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  2908. \********************************************************/
  2909. /*! exports provided: KHR_materials_clearcoat */
  2910. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2911. "use strict";
  2912. __webpack_require__.r(__webpack_exports__);
  2913. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  2914. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  2915. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2916. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2917. var NAME = "KHR_materials_clearcoat";
  2918. /**
  2919. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  2920. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  2921. * !!! Experimental Extension Subject to Changes !!!
  2922. */
  2923. var KHR_materials_clearcoat = /** @class */ (function () {
  2924. /** @hidden */
  2925. function KHR_materials_clearcoat(loader) {
  2926. /**
  2927. * The name of this extension.
  2928. */
  2929. this.name = NAME;
  2930. /**
  2931. * Defines a number that determines the order the extensions are applied.
  2932. */
  2933. this.order = 220;
  2934. this._loader = loader;
  2935. this.enabled = this._loader.isExtensionUsed(NAME);
  2936. }
  2937. /** @hidden */
  2938. KHR_materials_clearcoat.prototype.dispose = function () {
  2939. delete this._loader;
  2940. };
  2941. /** @hidden */
  2942. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2943. var _this = this;
  2944. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  2945. var promises = new Array();
  2946. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  2947. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  2948. return Promise.all(promises).then(function () { });
  2949. });
  2950. };
  2951. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  2952. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2953. throw new Error(context + ": Material type not supported");
  2954. }
  2955. var promises = new Array();
  2956. babylonMaterial.clearCoat.isEnabled = true;
  2957. if (properties.clearcoatFactor != undefined) {
  2958. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  2959. }
  2960. else {
  2961. babylonMaterial.clearCoat.intensity = 0;
  2962. }
  2963. if (properties.clearcoatTexture) {
  2964. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  2965. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  2966. babylonMaterial.clearCoat.texture = texture;
  2967. }));
  2968. }
  2969. if (properties.clearcoatRoughnessFactor != undefined) {
  2970. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  2971. }
  2972. else {
  2973. babylonMaterial.clearCoat.roughness = 0;
  2974. }
  2975. if (properties.clearcoatRoughnessTexture) {
  2976. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  2977. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  2978. babylonMaterial.clearCoat.texture = texture;
  2979. }));
  2980. }
  2981. if (properties.clearcoatNormalTexture) {
  2982. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  2983. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  2984. babylonMaterial.clearCoat.bumpTexture = texture;
  2985. }));
  2986. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  2987. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  2988. if (properties.clearcoatNormalTexture.scale != undefined) {
  2989. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  2990. }
  2991. }
  2992. return Promise.all(promises).then(function () { });
  2993. };
  2994. return KHR_materials_clearcoat;
  2995. }());
  2996. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  2997. /***/ }),
  2998. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  2999. /*!********************************************************************!*\
  3000. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  3001. \********************************************************************/
  3002. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  3003. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3004. "use strict";
  3005. __webpack_require__.r(__webpack_exports__);
  3006. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  3007. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3008. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  3009. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3010. var NAME = "KHR_materials_pbrSpecularGlossiness";
  3011. /**
  3012. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  3013. */
  3014. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  3015. /** @hidden */
  3016. function KHR_materials_pbrSpecularGlossiness(loader) {
  3017. /**
  3018. * The name of this extension.
  3019. */
  3020. this.name = NAME;
  3021. /**
  3022. * Defines a number that determines the order the extensions are applied.
  3023. */
  3024. this.order = 200;
  3025. this._loader = loader;
  3026. this.enabled = this._loader.isExtensionUsed(NAME);
  3027. }
  3028. /** @hidden */
  3029. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  3030. delete this._loader;
  3031. };
  3032. /** @hidden */
  3033. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3034. var _this = this;
  3035. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  3036. var promises = new Array();
  3037. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  3038. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  3039. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  3040. return Promise.all(promises).then(function () { });
  3041. });
  3042. };
  3043. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  3044. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3045. throw new Error(context + ": Material type not supported");
  3046. }
  3047. var promises = new Array();
  3048. babylonMaterial.metallic = null;
  3049. babylonMaterial.roughness = null;
  3050. if (properties.diffuseFactor) {
  3051. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  3052. babylonMaterial.alpha = properties.diffuseFactor[3];
  3053. }
  3054. else {
  3055. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  3056. }
  3057. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  3058. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  3059. if (properties.diffuseTexture) {
  3060. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  3061. texture.name = babylonMaterial.name + " (Diffuse)";
  3062. babylonMaterial.albedoTexture = texture;
  3063. }));
  3064. }
  3065. if (properties.specularGlossinessTexture) {
  3066. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  3067. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  3068. babylonMaterial.reflectivityTexture = texture;
  3069. }));
  3070. babylonMaterial.reflectivityTexture.hasAlpha = true;
  3071. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  3072. }
  3073. return Promise.all(promises).then(function () { });
  3074. };
  3075. return KHR_materials_pbrSpecularGlossiness;
  3076. }());
  3077. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  3078. /***/ }),
  3079. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  3080. /*!****************************************************!*\
  3081. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  3082. \****************************************************/
  3083. /*! exports provided: KHR_materials_sheen */
  3084. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3085. "use strict";
  3086. __webpack_require__.r(__webpack_exports__);
  3087. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  3088. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  3089. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  3090. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3091. var NAME = "KHR_materials_sheen";
  3092. /**
  3093. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  3094. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  3095. * !!! Experimental Extension Subject to Changes !!!
  3096. */
  3097. var KHR_materials_sheen = /** @class */ (function () {
  3098. /** @hidden */
  3099. function KHR_materials_sheen(loader) {
  3100. /**
  3101. * The name of this extension.
  3102. */
  3103. this.name = NAME;
  3104. /**
  3105. * Defines a number that determines the order the extensions are applied.
  3106. */
  3107. this.order = 240;
  3108. this._loader = loader;
  3109. this.enabled = this._loader.isExtensionUsed(NAME);
  3110. }
  3111. /** @hidden */
  3112. KHR_materials_sheen.prototype.dispose = function () {
  3113. delete this._loader;
  3114. };
  3115. /** @hidden */
  3116. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3117. var _this = this;
  3118. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  3119. var promises = new Array();
  3120. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  3121. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  3122. return Promise.all(promises).then(function () { });
  3123. });
  3124. };
  3125. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  3126. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3127. throw new Error(context + ": Material type not supported");
  3128. }
  3129. var promises = new Array();
  3130. babylonMaterial.sheen.isEnabled = true;
  3131. if (properties.intensityFactor != undefined) {
  3132. babylonMaterial.sheen.intensity = properties.intensityFactor;
  3133. }
  3134. else {
  3135. babylonMaterial.sheen.intensity = 0;
  3136. }
  3137. if (properties.colorFactor != undefined) {
  3138. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  3139. }
  3140. if (properties.colorIntensityTexture) {
  3141. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  3142. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  3143. babylonMaterial.sheen.texture = texture;
  3144. }));
  3145. }
  3146. return Promise.all(promises).then(function () { });
  3147. };
  3148. return KHR_materials_sheen;
  3149. }());
  3150. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  3151. /***/ }),
  3152. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  3153. /*!*******************************************************!*\
  3154. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  3155. \*******************************************************/
  3156. /*! exports provided: KHR_materials_specular */
  3157. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3158. "use strict";
  3159. __webpack_require__.r(__webpack_exports__);
  3160. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  3161. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  3162. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  3163. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3164. var NAME = "KHR_materials_specular";
  3165. /**
  3166. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  3167. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  3168. * !!! Experimental Extension Subject to Changes !!!
  3169. */
  3170. var KHR_materials_specular = /** @class */ (function () {
  3171. /** @hidden */
  3172. function KHR_materials_specular(loader) {
  3173. /**
  3174. * The name of this extension.
  3175. */
  3176. this.name = NAME;
  3177. /**
  3178. * Defines a number that determines the order the extensions are applied.
  3179. */
  3180. this.order = 230;
  3181. this._loader = loader;
  3182. this.enabled = this._loader.isExtensionUsed(NAME);
  3183. }
  3184. /** @hidden */
  3185. KHR_materials_specular.prototype.dispose = function () {
  3186. delete this._loader;
  3187. };
  3188. /** @hidden */
  3189. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3190. var _this = this;
  3191. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  3192. var promises = new Array();
  3193. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  3194. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  3195. return Promise.all(promises).then(function () { });
  3196. });
  3197. };
  3198. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  3199. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3200. throw new Error(context + ": Material type not supported");
  3201. }
  3202. if (properties.specularFactor !== undefined) {
  3203. babylonMaterial.metallicF0Factor = properties.specularFactor;
  3204. }
  3205. if (properties.specularTexture) {
  3206. // This does not allow a separate sampler for it at the moment but is currently under discussion.
  3207. babylonMaterial.useMetallicF0FactorFromMetallicTexture = true;
  3208. }
  3209. return Promise.resolve();
  3210. };
  3211. return KHR_materials_specular;
  3212. }());
  3213. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  3214. /***/ }),
  3215. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  3216. /*!****************************************************!*\
  3217. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  3218. \****************************************************/
  3219. /*! exports provided: KHR_materials_unlit */
  3220. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3221. "use strict";
  3222. __webpack_require__.r(__webpack_exports__);
  3223. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  3224. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3225. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  3226. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3227. var NAME = "KHR_materials_unlit";
  3228. /**
  3229. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  3230. */
  3231. var KHR_materials_unlit = /** @class */ (function () {
  3232. /** @hidden */
  3233. function KHR_materials_unlit(loader) {
  3234. /**
  3235. * The name of this extension.
  3236. */
  3237. this.name = NAME;
  3238. /**
  3239. * Defines a number that determines the order the extensions are applied.
  3240. */
  3241. this.order = 210;
  3242. this._loader = loader;
  3243. this.enabled = this._loader.isExtensionUsed(NAME);
  3244. }
  3245. /** @hidden */
  3246. KHR_materials_unlit.prototype.dispose = function () {
  3247. delete this._loader;
  3248. };
  3249. /** @hidden */
  3250. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3251. var _this = this;
  3252. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  3253. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  3254. });
  3255. };
  3256. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  3257. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3258. throw new Error(context + ": Material type not supported");
  3259. }
  3260. var promises = new Array();
  3261. babylonMaterial.unlit = true;
  3262. var properties = material.pbrMetallicRoughness;
  3263. if (properties) {
  3264. if (properties.baseColorFactor) {
  3265. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  3266. babylonMaterial.alpha = properties.baseColorFactor[3];
  3267. }
  3268. else {
  3269. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  3270. }
  3271. if (properties.baseColorTexture) {
  3272. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  3273. texture.name = babylonMaterial.name + " (Base Color)";
  3274. babylonMaterial.albedoTexture = texture;
  3275. }));
  3276. }
  3277. }
  3278. if (material.doubleSided) {
  3279. babylonMaterial.backFaceCulling = false;
  3280. babylonMaterial.twoSidedLighting = true;
  3281. }
  3282. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  3283. return Promise.all(promises).then(function () { });
  3284. };
  3285. return KHR_materials_unlit;
  3286. }());
  3287. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  3288. /***/ }),
  3289. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  3290. /*!******************************************************!*\
  3291. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  3292. \******************************************************/
  3293. /*! exports provided: KHR_mesh_quantization */
  3294. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3295. "use strict";
  3296. __webpack_require__.r(__webpack_exports__);
  3297. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  3298. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3299. var NAME = "KHR_mesh_quantization";
  3300. /**
  3301. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  3302. */
  3303. var KHR_mesh_quantization = /** @class */ (function () {
  3304. /** @hidden */
  3305. function KHR_mesh_quantization(loader) {
  3306. /**
  3307. * The name of this extension.
  3308. */
  3309. this.name = NAME;
  3310. this.enabled = loader.isExtensionUsed(NAME);
  3311. }
  3312. /** @hidden */
  3313. KHR_mesh_quantization.prototype.dispose = function () {
  3314. };
  3315. return KHR_mesh_quantization;
  3316. }());
  3317. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  3318. /***/ }),
  3319. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  3320. /*!******************************************************!*\
  3321. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  3322. \******************************************************/
  3323. /*! exports provided: KHR_texture_transform */
  3324. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3325. "use strict";
  3326. __webpack_require__.r(__webpack_exports__);
  3327. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  3328. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  3329. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  3330. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3331. var NAME = "KHR_texture_transform";
  3332. /**
  3333. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  3334. */
  3335. var KHR_texture_transform = /** @class */ (function () {
  3336. /** @hidden */
  3337. function KHR_texture_transform(loader) {
  3338. /**
  3339. * The name of this extension.
  3340. */
  3341. this.name = NAME;
  3342. this._loader = loader;
  3343. this.enabled = this._loader.isExtensionUsed(NAME);
  3344. }
  3345. /** @hidden */
  3346. KHR_texture_transform.prototype.dispose = function () {
  3347. delete this._loader;
  3348. };
  3349. /** @hidden */
  3350. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  3351. var _this = this;
  3352. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  3353. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  3354. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  3355. throw new Error(extensionContext + ": Texture type not supported");
  3356. }
  3357. if (extension.offset) {
  3358. babylonTexture.uOffset = extension.offset[0];
  3359. babylonTexture.vOffset = extension.offset[1];
  3360. }
  3361. // Always rotate around the origin.
  3362. babylonTexture.uRotationCenter = 0;
  3363. babylonTexture.vRotationCenter = 0;
  3364. if (extension.rotation) {
  3365. babylonTexture.wAng = -extension.rotation;
  3366. }
  3367. if (extension.scale) {
  3368. babylonTexture.uScale = extension.scale[0];
  3369. babylonTexture.vScale = extension.scale[1];
  3370. }
  3371. if (extension.texCoord != undefined) {
  3372. babylonTexture.coordinatesIndex = extension.texCoord;
  3373. }
  3374. assign(babylonTexture);
  3375. });
  3376. });
  3377. };
  3378. return KHR_texture_transform;
  3379. }());
  3380. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  3381. /***/ }),
  3382. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  3383. /*!***************************************************!*\
  3384. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  3385. \***************************************************/
  3386. /*! exports provided: MSFT_audio_emitter */
  3387. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3388. "use strict";
  3389. __webpack_require__.r(__webpack_exports__);
  3390. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  3391. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3392. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  3393. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3394. var NAME = "MSFT_audio_emitter";
  3395. /**
  3396. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  3397. */
  3398. var MSFT_audio_emitter = /** @class */ (function () {
  3399. /** @hidden */
  3400. function MSFT_audio_emitter(loader) {
  3401. /**
  3402. * The name of this extension.
  3403. */
  3404. this.name = NAME;
  3405. this._loader = loader;
  3406. this.enabled = this._loader.isExtensionUsed(NAME);
  3407. }
  3408. /** @hidden */
  3409. MSFT_audio_emitter.prototype.dispose = function () {
  3410. delete this._loader;
  3411. delete this._clips;
  3412. delete this._emitters;
  3413. };
  3414. /** @hidden */
  3415. MSFT_audio_emitter.prototype.onLoading = function () {
  3416. var extensions = this._loader.gltf.extensions;
  3417. if (extensions && extensions[this.name]) {
  3418. var extension = extensions[this.name];
  3419. this._clips = extension.clips;
  3420. this._emitters = extension.emitters;
  3421. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  3422. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  3423. }
  3424. };
  3425. /** @hidden */
  3426. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  3427. var _this = this;
  3428. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3429. var promises = new Array();
  3430. promises.push(_this._loader.loadSceneAsync(context, scene));
  3431. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  3432. var emitterIndex = _a[_i];
  3433. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  3434. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  3435. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  3436. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  3437. }
  3438. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  3439. }
  3440. return Promise.all(promises).then(function () { });
  3441. });
  3442. };
  3443. /** @hidden */
  3444. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  3445. var _this = this;
  3446. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  3447. var promises = new Array();
  3448. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  3449. var _loop_1 = function (emitterIndex) {
  3450. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  3451. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  3452. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  3453. var sound = _a[_i];
  3454. sound.attachToMesh(babylonMesh);
  3455. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  3456. sound.setLocalDirectionToMesh(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  3457. sound.setDirectionalCone(2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  3458. }
  3459. }
  3460. }));
  3461. };
  3462. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  3463. var emitterIndex = _a[_i];
  3464. _loop_1(emitterIndex);
  3465. }
  3466. assign(babylonMesh);
  3467. }).then(function (babylonMesh) {
  3468. return Promise.all(promises).then(function () {
  3469. return babylonMesh;
  3470. });
  3471. });
  3472. });
  3473. };
  3474. /** @hidden */
  3475. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  3476. var _this = this;
  3477. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  3478. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  3479. var promises = new Array();
  3480. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  3481. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  3482. var event_1 = _a[_i];
  3483. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  3484. }
  3485. return Promise.all(promises).then(function () {
  3486. return babylonAnimationGroup;
  3487. });
  3488. });
  3489. });
  3490. };
  3491. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  3492. if (clip._objectURL) {
  3493. return clip._objectURL;
  3494. }
  3495. var promise;
  3496. if (clip.uri) {
  3497. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  3498. }
  3499. else {
  3500. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  3501. promise = this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView);
  3502. }
  3503. clip._objectURL = promise.then(function (data) {
  3504. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  3505. });
  3506. return clip._objectURL;
  3507. };
  3508. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  3509. var _this = this;
  3510. emitter._babylonSounds = emitter._babylonSounds || [];
  3511. if (!emitter._babylonData) {
  3512. var clipPromises = new Array();
  3513. var name_1 = emitter.name || "emitter" + emitter.index;
  3514. var options_1 = {
  3515. loop: false,
  3516. autoplay: false,
  3517. volume: emitter.volume == undefined ? 1 : emitter.volume,
  3518. };
  3519. var _loop_2 = function (i) {
  3520. var clipContext = "#/extensions/" + this_1.name + "/clips";
  3521. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  3522. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  3523. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  3524. sound.refDistance = emitter.refDistance || 1;
  3525. sound.maxDistance = emitter.maxDistance || 256;
  3526. sound.rolloffFactor = emitter.rolloffFactor || 1;
  3527. sound.distanceModel = emitter.distanceModel || 'exponential';
  3528. sound._positionInEmitterSpace = true;
  3529. }));
  3530. };
  3531. var this_1 = this;
  3532. for (var i = 0; i < emitter.clips.length; i++) {
  3533. _loop_2(i);
  3534. }
  3535. var promise = Promise.all(clipPromises).then(function () {
  3536. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  3537. var weightedSound = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  3538. if (emitter.innerAngle) {
  3539. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  3540. }
  3541. if (emitter.outerAngle) {
  3542. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  3543. }
  3544. if (emitter.volume) {
  3545. weightedSound.volume = emitter.volume;
  3546. }
  3547. emitter._babylonData.sound = weightedSound;
  3548. });
  3549. emitter._babylonData = {
  3550. loaded: promise
  3551. };
  3552. }
  3553. return emitter._babylonData.loaded;
  3554. };
  3555. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  3556. switch (action) {
  3557. case "play" /* play */: {
  3558. return function (currentFrame) {
  3559. var frameOffset = (startOffset || 0) + (currentFrame - time);
  3560. sound.play(frameOffset);
  3561. };
  3562. }
  3563. case "stop" /* stop */: {
  3564. return function (currentFrame) {
  3565. sound.stop();
  3566. };
  3567. }
  3568. case "pause" /* pause */: {
  3569. return function (currentFrame) {
  3570. sound.pause();
  3571. };
  3572. }
  3573. default: {
  3574. throw new Error(context + ": Unsupported action " + action);
  3575. }
  3576. }
  3577. };
  3578. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  3579. var _this = this;
  3580. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  3581. return Promise.resolve();
  3582. }
  3583. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  3584. var emitterIndex = event.emitter;
  3585. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("#/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  3586. return this._loadEmitterAsync(context, emitter).then(function () {
  3587. var sound = emitter._babylonData.sound;
  3588. if (sound) {
  3589. var babylonAnimationEvent = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  3590. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  3591. // Make sure all started audio stops when this animation is terminated.
  3592. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  3593. sound.stop();
  3594. });
  3595. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  3596. sound.pause();
  3597. });
  3598. }
  3599. });
  3600. };
  3601. return MSFT_audio_emitter;
  3602. }());
  3603. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  3604. /***/ }),
  3605. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  3606. /*!*****************************************!*\
  3607. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  3608. \*****************************************/
  3609. /*! exports provided: MSFT_lod */
  3610. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3611. "use strict";
  3612. __webpack_require__.r(__webpack_exports__);
  3613. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  3614. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  3615. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  3616. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3617. var NAME = "MSFT_lod";
  3618. /**
  3619. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  3620. */
  3621. var MSFT_lod = /** @class */ (function () {
  3622. /** @hidden */
  3623. function MSFT_lod(loader) {
  3624. /**
  3625. * The name of this extension.
  3626. */
  3627. this.name = NAME;
  3628. /**
  3629. * Defines a number that determines the order the extensions are applied.
  3630. */
  3631. this.order = 100;
  3632. /**
  3633. * Maximum number of LODs to load, starting from the lowest LOD.
  3634. */
  3635. this.maxLODsToLoad = 10;
  3636. /**
  3637. * Observable raised when all node LODs of one level are loaded.
  3638. * The event data is the index of the loaded LOD starting from zero.
  3639. * Dispose the loader to cancel the loading of the next level of LODs.
  3640. */
  3641. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3642. /**
  3643. * Observable raised when all material LODs of one level are loaded.
  3644. * The event data is the index of the loaded LOD starting from zero.
  3645. * Dispose the loader to cancel the loading of the next level of LODs.
  3646. */
  3647. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3648. this._nodeIndexLOD = null;
  3649. this._nodeSignalLODs = new Array();
  3650. this._nodePromiseLODs = new Array();
  3651. this._materialIndexLOD = null;
  3652. this._materialSignalLODs = new Array();
  3653. this._materialPromiseLODs = new Array();
  3654. this._indexLOD = null;
  3655. this._bufferLODs = new Array();
  3656. this._loader = loader;
  3657. this.enabled = this._loader.isExtensionUsed(NAME);
  3658. }
  3659. /** @hidden */
  3660. MSFT_lod.prototype.dispose = function () {
  3661. this._disposeUnusedMaterials();
  3662. delete this._loader;
  3663. this._nodeIndexLOD = null;
  3664. this._nodeSignalLODs.length = 0;
  3665. this._nodePromiseLODs.length = 0;
  3666. this._materialIndexLOD = null;
  3667. this._materialSignalLODs.length = 0;
  3668. this._materialPromiseLODs.length = 0;
  3669. this._indexLOD = null;
  3670. this._bufferLODs.length = 0;
  3671. this.onMaterialLODsLoadedObservable.clear();
  3672. this.onNodeLODsLoadedObservable.clear();
  3673. };
  3674. /** @hidden */
  3675. MSFT_lod.prototype.onReady = function () {
  3676. var _this = this;
  3677. var _loop_1 = function (indexLOD) {
  3678. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  3679. if (indexLOD !== 0) {
  3680. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  3681. }
  3682. _this._loader.log("Loaded node LOD " + indexLOD);
  3683. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  3684. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  3685. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  3686. if (_this._nodeSignalLODs[indexLOD]) {
  3687. _this._nodeSignalLODs[indexLOD].resolve();
  3688. }
  3689. }
  3690. });
  3691. this_1._loader._completePromises.push(promise);
  3692. };
  3693. var this_1 = this;
  3694. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  3695. _loop_1(indexLOD);
  3696. }
  3697. var _loop_2 = function (indexLOD) {
  3698. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  3699. if (indexLOD !== 0) {
  3700. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  3701. }
  3702. _this._loader.log("Loaded material LOD " + indexLOD);
  3703. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  3704. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  3705. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  3706. if (_this._materialSignalLODs[indexLOD]) {
  3707. _this._materialSignalLODs[indexLOD].resolve();
  3708. }
  3709. }
  3710. });
  3711. this_2._loader._completePromises.push(promise);
  3712. };
  3713. var this_2 = this;
  3714. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  3715. _loop_2(indexLOD);
  3716. }
  3717. for (var indexLOD = 1; indexLOD < this._bufferLODs.length; indexLOD++) {
  3718. this._loadBufferLOD(indexLOD);
  3719. }
  3720. };
  3721. /** @hidden */
  3722. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  3723. var _this = this;
  3724. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  3725. var firstPromise;
  3726. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  3727. _this._loader.logOpen("" + extensionContext);
  3728. var _loop_3 = function (indexLOD) {
  3729. var nodeLOD = nodeLODs[indexLOD];
  3730. _this._indexLOD = indexLOD;
  3731. if (indexLOD !== 0) {
  3732. _this._nodeIndexLOD = indexLOD;
  3733. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  3734. }
  3735. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  3736. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  3737. if (indexLOD !== 0) {
  3738. // TODO: should not rely on _babylonTransformNode
  3739. var previousNodeLOD = nodeLODs[indexLOD - 1];
  3740. if (previousNodeLOD._babylonTransformNode) {
  3741. previousNodeLOD._babylonTransformNode.dispose();
  3742. delete previousNodeLOD._babylonTransformNode;
  3743. _this._disposeUnusedMaterials();
  3744. }
  3745. }
  3746. babylonMesh.setEnabled(true);
  3747. return babylonMesh;
  3748. });
  3749. if (indexLOD === 0) {
  3750. firstPromise = promise;
  3751. if (_this._bufferLODs.length !== 0) {
  3752. _this._loadBufferLOD(0);
  3753. }
  3754. }
  3755. else {
  3756. _this._nodeIndexLOD = null;
  3757. }
  3758. _this._indexLOD = null;
  3759. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  3760. _this._nodePromiseLODs[indexLOD].push(promise);
  3761. };
  3762. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  3763. _loop_3(indexLOD);
  3764. }
  3765. _this._loader.logClose();
  3766. return firstPromise;
  3767. });
  3768. };
  3769. /** @hidden */
  3770. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3771. var _this = this;
  3772. // Don't load material LODs if already loading a node LOD.
  3773. if (this._indexLOD) {
  3774. return null;
  3775. }
  3776. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  3777. var firstPromise;
  3778. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  3779. _this._loader.logOpen("" + extensionContext);
  3780. var _loop_4 = function (indexLOD) {
  3781. var materialLOD = materialLODs[indexLOD];
  3782. _this._indexLOD = indexLOD;
  3783. if (indexLOD !== 0) {
  3784. _this._materialIndexLOD = indexLOD;
  3785. }
  3786. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  3787. if (indexLOD === 0) {
  3788. assign(babylonMaterial);
  3789. }
  3790. }).then(function (babylonMaterial) {
  3791. if (indexLOD !== 0) {
  3792. assign(babylonMaterial);
  3793. // TODO: should not rely on _data
  3794. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  3795. if (previousDataLOD[babylonDrawMode]) {
  3796. previousDataLOD[babylonDrawMode].babylonMaterial.dispose();
  3797. delete previousDataLOD[babylonDrawMode];
  3798. }
  3799. }
  3800. return babylonMaterial;
  3801. });
  3802. if (indexLOD === 0) {
  3803. firstPromise = promise;
  3804. if (_this._bufferLODs.length !== 0) {
  3805. _this._loadBufferLOD(0);
  3806. }
  3807. }
  3808. else {
  3809. _this._materialIndexLOD = null;
  3810. }
  3811. _this._indexLOD = null;
  3812. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  3813. _this._materialPromiseLODs[indexLOD].push(promise);
  3814. };
  3815. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  3816. _loop_4(indexLOD);
  3817. }
  3818. _this._loader.logClose();
  3819. return firstPromise;
  3820. });
  3821. };
  3822. /** @hidden */
  3823. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  3824. var _this = this;
  3825. // Defer the loading of uris if loading a material or node LOD.
  3826. if (this._materialIndexLOD !== null) {
  3827. this._loader.log("deferred");
  3828. var previousIndexLOD = this._materialIndexLOD - 1;
  3829. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  3830. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  3831. return _this._loader.loadUriAsync(context, property, uri);
  3832. });
  3833. }
  3834. else if (this._nodeIndexLOD !== null) {
  3835. this._loader.log("deferred");
  3836. var previousIndexLOD = this._nodeIndexLOD - 1;
  3837. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  3838. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  3839. return _this._loader.loadUriAsync(context, property, uri);
  3840. });
  3841. }
  3842. return null;
  3843. };
  3844. /** @hidden */
  3845. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  3846. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  3847. if (!this._loader.bin) {
  3848. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  3849. }
  3850. // Non-LOD buffers will be bucketed into the first LOD.
  3851. var indexLOD = this._indexLOD || 0;
  3852. var start = byteOffset;
  3853. var end = start + byteLength - 1;
  3854. var bufferLOD_1 = this._bufferLODs[indexLOD];
  3855. if (bufferLOD_1) {
  3856. bufferLOD_1.start = Math.min(bufferLOD_1.start, start);
  3857. bufferLOD_1.end = Math.max(bufferLOD_1.end, end);
  3858. }
  3859. else {
  3860. bufferLOD_1 = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  3861. this._bufferLODs[indexLOD] = bufferLOD_1;
  3862. }
  3863. return bufferLOD_1.loaded.promise.then(function (data) {
  3864. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD_1.start, byteLength);
  3865. });
  3866. }
  3867. return null;
  3868. };
  3869. MSFT_lod.prototype._loadBufferLOD = function (indexLOD) {
  3870. var bufferLOD = this._bufferLODs[indexLOD];
  3871. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  3872. bufferLOD.loaded.resolve(data);
  3873. }, function (error) {
  3874. bufferLOD.loaded.reject(error);
  3875. });
  3876. };
  3877. /**
  3878. * Gets an array of LOD properties from lowest to highest.
  3879. */
  3880. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  3881. if (this.maxLODsToLoad <= 0) {
  3882. throw new Error("maxLODsToLoad must be greater than zero");
  3883. }
  3884. var properties = new Array();
  3885. for (var i = ids.length - 1; i >= 0; i--) {
  3886. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  3887. if (properties.length === this.maxLODsToLoad) {
  3888. return properties;
  3889. }
  3890. }
  3891. properties.push(property);
  3892. return properties;
  3893. };
  3894. MSFT_lod.prototype._disposeUnusedMaterials = function () {
  3895. // TODO: should not rely on _data
  3896. var materials = this._loader.gltf.materials;
  3897. if (materials) {
  3898. for (var _i = 0, materials_1 = materials; _i < materials_1.length; _i++) {
  3899. var material = materials_1[_i];
  3900. if (material._data) {
  3901. var _loop_5 = function (drawMode) {
  3902. var data = material._data[drawMode];
  3903. if (data.babylonMeshes.every(function (babylonMesh) { return babylonMesh.material !== data.babylonMaterial; })) {
  3904. // TODO: check if texture is in use instead of force disposing textures
  3905. data.babylonMaterial.dispose(false, true);
  3906. delete material._data[drawMode];
  3907. }
  3908. };
  3909. for (var drawMode in material._data) {
  3910. _loop_5(drawMode);
  3911. }
  3912. }
  3913. }
  3914. }
  3915. };
  3916. return MSFT_lod;
  3917. }());
  3918. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  3919. /***/ }),
  3920. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  3921. /*!***************************************************!*\
  3922. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  3923. \***************************************************/
  3924. /*! exports provided: MSFT_minecraftMesh */
  3925. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3926. "use strict";
  3927. __webpack_require__.r(__webpack_exports__);
  3928. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  3929. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  3930. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  3931. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3932. var NAME = "MSFT_minecraftMesh";
  3933. /** @hidden */
  3934. var MSFT_minecraftMesh = /** @class */ (function () {
  3935. function MSFT_minecraftMesh(loader) {
  3936. this.name = NAME;
  3937. this._loader = loader;
  3938. this.enabled = this._loader.isExtensionUsed(NAME);
  3939. }
  3940. MSFT_minecraftMesh.prototype.dispose = function () {
  3941. delete this._loader;
  3942. };
  3943. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3944. var _this = this;
  3945. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  3946. if (extra) {
  3947. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3948. throw new Error(extraContext + ": Material type not supported");
  3949. }
  3950. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  3951. if (babylonMaterial.needAlphaBlending()) {
  3952. babylonMaterial.forceDepthWrite = true;
  3953. babylonMaterial.separateCullingPass = true;
  3954. }
  3955. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  3956. babylonMaterial.twoSidedLighting = true;
  3957. return promise;
  3958. }
  3959. return null;
  3960. });
  3961. };
  3962. return MSFT_minecraftMesh;
  3963. }());
  3964. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  3965. /***/ }),
  3966. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  3967. /*!*************************************************!*\
  3968. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  3969. \*************************************************/
  3970. /*! exports provided: MSFT_sRGBFactors */
  3971. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3972. "use strict";
  3973. __webpack_require__.r(__webpack_exports__);
  3974. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  3975. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  3976. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  3977. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3978. var NAME = "MSFT_sRGBFactors";
  3979. /** @hidden */
  3980. var MSFT_sRGBFactors = /** @class */ (function () {
  3981. function MSFT_sRGBFactors(loader) {
  3982. this.name = NAME;
  3983. this._loader = loader;
  3984. this.enabled = this._loader.isExtensionUsed(NAME);
  3985. }
  3986. MSFT_sRGBFactors.prototype.dispose = function () {
  3987. delete this._loader;
  3988. };
  3989. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3990. var _this = this;
  3991. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  3992. if (extra) {
  3993. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3994. throw new Error(extraContext + ": Material type not supported");
  3995. }
  3996. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  3997. if (!babylonMaterial.albedoTexture) {
  3998. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  3999. }
  4000. if (!babylonMaterial.reflectivityTexture) {
  4001. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  4002. }
  4003. return promise;
  4004. }
  4005. return null;
  4006. });
  4007. };
  4008. return MSFT_sRGBFactors;
  4009. }());
  4010. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  4011. /***/ }),
  4012. /***/ "./glTF/2.0/Extensions/index.ts":
  4013. /*!**************************************!*\
  4014. !*** ./glTF/2.0/Extensions/index.ts ***!
  4015. \**************************************/
  4016. /*! exports provided: EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_mesh_quantization, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  4017. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4018. "use strict";
  4019. __webpack_require__.r(__webpack_exports__);
  4020. /* harmony import */ var _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EXT_lights_image_based */ "./glTF/2.0/Extensions/EXT_lights_image_based.ts");
  4021. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__["EXT_lights_image_based"]; });
  4022. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  4023. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  4024. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  4025. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  4026. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  4027. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  4028. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  4029. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  4030. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  4031. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_clearcoat"]; });
  4032. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  4033. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_sheen"]; });
  4034. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  4035. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_specular"]; });
  4036. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  4037. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__["KHR_mesh_quantization"]; });
  4038. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  4039. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__["KHR_texture_transform"]; });
  4040. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  4041. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__["MSFT_audio_emitter"]; });
  4042. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  4043. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__["MSFT_lod"]; });
  4044. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  4045. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__["MSFT_minecraftMesh"]; });
  4046. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  4047. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__["MSFT_sRGBFactors"]; });
  4048. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  4049. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__["ExtrasAsMetadata"]; });
  4050. /***/ }),
  4051. /***/ "./glTF/2.0/glTFLoader.ts":
  4052. /*!********************************!*\
  4053. !*** ./glTF/2.0/glTFLoader.ts ***!
  4054. \********************************/
  4055. /*! exports provided: ArrayItem, GLTFLoader */
  4056. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4057. "use strict";
  4058. __webpack_require__.r(__webpack_exports__);
  4059. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  4060. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  4061. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  4062. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  4063. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  4064. /**
  4065. * Helper class for working with arrays when loading the glTF asset
  4066. */
  4067. var ArrayItem = /** @class */ (function () {
  4068. function ArrayItem() {
  4069. }
  4070. /**
  4071. * Gets an item from the given array.
  4072. * @param context The context when loading the asset
  4073. * @param array The array to get the item from
  4074. * @param index The index to the array
  4075. * @returns The array item
  4076. */
  4077. ArrayItem.Get = function (context, array, index) {
  4078. if (!array || index == undefined || !array[index]) {
  4079. throw new Error(context + ": Failed to find index (" + index + ")");
  4080. }
  4081. return array[index];
  4082. };
  4083. /**
  4084. * Assign an `index` field to each item of the given array.
  4085. * @param array The array of items
  4086. */
  4087. ArrayItem.Assign = function (array) {
  4088. if (array) {
  4089. for (var index = 0; index < array.length; index++) {
  4090. array[index].index = index;
  4091. }
  4092. }
  4093. };
  4094. return ArrayItem;
  4095. }());
  4096. /**
  4097. * The glTF 2.0 loader
  4098. */
  4099. var GLTFLoader = /** @class */ (function () {
  4100. /** @hidden */
  4101. function GLTFLoader(parent) {
  4102. /** @hidden */
  4103. this._completePromises = new Array();
  4104. this._disposed = false;
  4105. this._state = null;
  4106. this._extensions = new Array();
  4107. this._defaultBabylonMaterialData = {};
  4108. this._requests = new Array();
  4109. this._parent = parent;
  4110. }
  4111. /**
  4112. * Registers a loader extension.
  4113. * @param name The name of the loader extension.
  4114. * @param factory The factory function that creates the loader extension.
  4115. */
  4116. GLTFLoader.RegisterExtension = function (name, factory) {
  4117. if (GLTFLoader.UnregisterExtension(name)) {
  4118. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  4119. }
  4120. GLTFLoader._RegisteredExtensions[name] = {
  4121. factory: factory
  4122. };
  4123. };
  4124. /**
  4125. * Unregisters a loader extension.
  4126. * @param name The name of the loader extension.
  4127. * @returns A boolean indicating whether the extension has been unregistered
  4128. */
  4129. GLTFLoader.UnregisterExtension = function (name) {
  4130. if (!GLTFLoader._RegisteredExtensions[name]) {
  4131. return false;
  4132. }
  4133. delete GLTFLoader._RegisteredExtensions[name];
  4134. return true;
  4135. };
  4136. Object.defineProperty(GLTFLoader.prototype, "state", {
  4137. /**
  4138. * Gets the loader state.
  4139. */
  4140. get: function () {
  4141. return this._state;
  4142. },
  4143. enumerable: true,
  4144. configurable: true
  4145. });
  4146. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  4147. /**
  4148. * The object that represents the glTF JSON.
  4149. */
  4150. get: function () {
  4151. return this._gltf;
  4152. },
  4153. enumerable: true,
  4154. configurable: true
  4155. });
  4156. Object.defineProperty(GLTFLoader.prototype, "bin", {
  4157. /**
  4158. * The BIN chunk of a binary glTF.
  4159. */
  4160. get: function () {
  4161. return this._bin;
  4162. },
  4163. enumerable: true,
  4164. configurable: true
  4165. });
  4166. Object.defineProperty(GLTFLoader.prototype, "parent", {
  4167. /**
  4168. * The parent file loader.
  4169. */
  4170. get: function () {
  4171. return this._parent;
  4172. },
  4173. enumerable: true,
  4174. configurable: true
  4175. });
  4176. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  4177. /**
  4178. * The Babylon scene when loading the asset.
  4179. */
  4180. get: function () {
  4181. return this._babylonScene;
  4182. },
  4183. enumerable: true,
  4184. configurable: true
  4185. });
  4186. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  4187. /**
  4188. * The root Babylon mesh when loading the asset.
  4189. */
  4190. get: function () {
  4191. return this._rootBabylonMesh;
  4192. },
  4193. enumerable: true,
  4194. configurable: true
  4195. });
  4196. /** @hidden */
  4197. GLTFLoader.prototype.dispose = function () {
  4198. if (this._disposed) {
  4199. return;
  4200. }
  4201. this._disposed = true;
  4202. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4203. var request = _a[_i];
  4204. request.abort();
  4205. }
  4206. this._requests.length = 0;
  4207. this._completePromises.length = 0;
  4208. for (var name_1 in this._extensions) {
  4209. var extension = this._extensions[name_1];
  4210. extension.dispose && extension.dispose();
  4211. delete this._extensions[name_1];
  4212. }
  4213. delete this._gltf;
  4214. delete this._babylonScene;
  4215. delete this._rootBabylonMesh;
  4216. delete this._progressCallback;
  4217. this._parent._clear();
  4218. };
  4219. /** @hidden */
  4220. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  4221. var _this = this;
  4222. return Promise.resolve().then(function () {
  4223. _this._babylonScene = scene;
  4224. _this._rootUrl = rootUrl;
  4225. _this._fileName = fileName || "scene";
  4226. _this._progressCallback = onProgress;
  4227. _this._loadData(data);
  4228. var nodes = null;
  4229. if (meshesNames) {
  4230. var nodeMap_1 = {};
  4231. if (_this._gltf.nodes) {
  4232. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  4233. var node = _a[_i];
  4234. if (node.name) {
  4235. nodeMap_1[node.name] = node.index;
  4236. }
  4237. }
  4238. }
  4239. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  4240. nodes = names.map(function (name) {
  4241. var node = nodeMap_1[name];
  4242. if (node === undefined) {
  4243. throw new Error("Failed to find node '" + name + "'");
  4244. }
  4245. return node;
  4246. });
  4247. }
  4248. return _this._loadAsync(nodes, function () {
  4249. return {
  4250. meshes: _this._getMeshes(),
  4251. particleSystems: [],
  4252. skeletons: _this._getSkeletons(),
  4253. animationGroups: _this._getAnimationGroups()
  4254. };
  4255. });
  4256. });
  4257. };
  4258. /** @hidden */
  4259. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4260. var _this = this;
  4261. return Promise.resolve().then(function () {
  4262. _this._babylonScene = scene;
  4263. _this._rootUrl = rootUrl;
  4264. _this._fileName = fileName || "scene";
  4265. _this._progressCallback = onProgress;
  4266. _this._loadData(data);
  4267. return _this._loadAsync(null, function () { return undefined; });
  4268. });
  4269. };
  4270. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  4271. var _this = this;
  4272. return Promise.resolve().then(function () {
  4273. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  4274. _this._loadExtensions();
  4275. _this._checkExtensions();
  4276. var loadingToReadyCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY];
  4277. var loadingToCompleteCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE];
  4278. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  4279. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  4280. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  4281. _this._extensionsOnLoading();
  4282. var promises = new Array();
  4283. // Block the marking of materials dirty until the scene is loaded.
  4284. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  4285. _this._babylonScene.blockMaterialDirtyMechanism = true;
  4286. if (nodes) {
  4287. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  4288. }
  4289. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  4290. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  4291. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  4292. }
  4293. // Restore the blocking of material dirty.
  4294. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  4295. if (_this._parent.compileMaterials) {
  4296. promises.push(_this._compileMaterialsAsync());
  4297. }
  4298. if (_this._parent.compileShadowGenerators) {
  4299. promises.push(_this._compileShadowGeneratorsAsync());
  4300. }
  4301. var resultPromise = Promise.all(promises).then(function () {
  4302. if (_this._rootBabylonMesh) {
  4303. _this._rootBabylonMesh.setEnabled(true);
  4304. }
  4305. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  4306. _this._extensionsOnReady();
  4307. _this._startAnimations();
  4308. return resultFunc();
  4309. });
  4310. resultPromise.then(function () {
  4311. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  4312. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  4313. if (!_this._disposed) {
  4314. Promise.all(_this._completePromises).then(function () {
  4315. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  4316. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  4317. _this._parent.onCompleteObservable.notifyObservers(undefined);
  4318. _this._parent.onCompleteObservable.clear();
  4319. _this.dispose();
  4320. }, function (error) {
  4321. _this._parent.onErrorObservable.notifyObservers(error);
  4322. _this._parent.onErrorObservable.clear();
  4323. _this.dispose();
  4324. });
  4325. }
  4326. });
  4327. });
  4328. return resultPromise;
  4329. }, function (error) {
  4330. if (!_this._disposed) {
  4331. _this._parent.onErrorObservable.notifyObservers(error);
  4332. _this._parent.onErrorObservable.clear();
  4333. _this.dispose();
  4334. }
  4335. throw error;
  4336. });
  4337. };
  4338. GLTFLoader.prototype._loadData = function (data) {
  4339. this._gltf = data.json;
  4340. this._setupData();
  4341. if (data.bin) {
  4342. var buffers = this._gltf.buffers;
  4343. if (buffers && buffers[0] && !buffers[0].uri) {
  4344. var binaryBuffer = buffers[0];
  4345. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  4346. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  4347. }
  4348. this._bin = data.bin;
  4349. }
  4350. else {
  4351. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  4352. }
  4353. }
  4354. };
  4355. GLTFLoader.prototype._setupData = function () {
  4356. ArrayItem.Assign(this._gltf.accessors);
  4357. ArrayItem.Assign(this._gltf.animations);
  4358. ArrayItem.Assign(this._gltf.buffers);
  4359. ArrayItem.Assign(this._gltf.bufferViews);
  4360. ArrayItem.Assign(this._gltf.cameras);
  4361. ArrayItem.Assign(this._gltf.images);
  4362. ArrayItem.Assign(this._gltf.materials);
  4363. ArrayItem.Assign(this._gltf.meshes);
  4364. ArrayItem.Assign(this._gltf.nodes);
  4365. ArrayItem.Assign(this._gltf.samplers);
  4366. ArrayItem.Assign(this._gltf.scenes);
  4367. ArrayItem.Assign(this._gltf.skins);
  4368. ArrayItem.Assign(this._gltf.textures);
  4369. if (this._gltf.nodes) {
  4370. var nodeParents = {};
  4371. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  4372. var node = _a[_i];
  4373. if (node.children) {
  4374. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  4375. var index = _c[_b];
  4376. nodeParents[index] = node.index;
  4377. }
  4378. }
  4379. }
  4380. var rootNode = this._createRootNode();
  4381. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  4382. var node = _e[_d];
  4383. var parentIndex = nodeParents[node.index];
  4384. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  4385. }
  4386. }
  4387. };
  4388. GLTFLoader.prototype._loadExtensions = function () {
  4389. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  4390. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  4391. if (extension.name !== name_2) {
  4392. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("The name of the glTF loader extension instance does not match the registered name: " + extension.name + " !== " + name_2);
  4393. }
  4394. this._extensions.push(extension);
  4395. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  4396. }
  4397. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  4398. this._parent.onExtensionLoadedObservable.clear();
  4399. };
  4400. GLTFLoader.prototype._checkExtensions = function () {
  4401. if (this._gltf.extensionsRequired) {
  4402. var _loop_1 = function (name_3) {
  4403. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  4404. if (!available) {
  4405. throw new Error("Require extension " + name_3 + " is not available");
  4406. }
  4407. };
  4408. var this_1 = this;
  4409. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  4410. var name_3 = _a[_i];
  4411. _loop_1(name_3);
  4412. }
  4413. }
  4414. };
  4415. GLTFLoader.prototype._setState = function (state) {
  4416. this._state = state;
  4417. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  4418. };
  4419. GLTFLoader.prototype._createRootNode = function () {
  4420. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  4421. this._rootBabylonMesh.setEnabled(false);
  4422. var rootNode = {
  4423. _babylonTransformNode: this._rootBabylonMesh,
  4424. index: -1
  4425. };
  4426. switch (this._parent.coordinateSystemMode) {
  4427. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  4428. if (!this._babylonScene.useRightHandedSystem) {
  4429. rootNode.rotation = [0, 1, 0, 0];
  4430. rootNode.scale = [1, 1, -1];
  4431. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  4432. }
  4433. break;
  4434. }
  4435. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  4436. this._babylonScene.useRightHandedSystem = true;
  4437. break;
  4438. }
  4439. default: {
  4440. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  4441. }
  4442. }
  4443. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  4444. return rootNode;
  4445. };
  4446. /**
  4447. * Loads a glTF scene.
  4448. * @param context The context when loading the asset
  4449. * @param scene The glTF scene property
  4450. * @returns A promise that resolves when the load is complete
  4451. */
  4452. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  4453. var _this = this;
  4454. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  4455. if (extensionPromise) {
  4456. return extensionPromise;
  4457. }
  4458. var promises = new Array();
  4459. this.logOpen(context + " " + (scene.name || ""));
  4460. if (scene.nodes) {
  4461. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  4462. var index = _a[_i];
  4463. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  4464. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  4465. babylonMesh.parent = _this._rootBabylonMesh;
  4466. }));
  4467. }
  4468. }
  4469. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  4470. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  4471. if (this._gltf.nodes) {
  4472. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  4473. var node = _c[_b];
  4474. if (node._babylonTransformNode && node._babylonBones) {
  4475. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  4476. var babylonBone = _e[_d];
  4477. babylonBone.linkTransformNode(node._babylonTransformNode);
  4478. }
  4479. }
  4480. }
  4481. }
  4482. promises.push(this._loadAnimationsAsync());
  4483. this.logClose();
  4484. return Promise.all(promises).then(function () { });
  4485. };
  4486. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  4487. if (node._primitiveBabylonMeshes) {
  4488. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  4489. var babylonMesh = _a[_i];
  4490. callback(babylonMesh);
  4491. }
  4492. }
  4493. };
  4494. GLTFLoader.prototype._getMeshes = function () {
  4495. var meshes = new Array();
  4496. // Root mesh is always first.
  4497. meshes.push(this._rootBabylonMesh);
  4498. var nodes = this._gltf.nodes;
  4499. if (nodes) {
  4500. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  4501. var node = nodes_1[_i];
  4502. this._forEachPrimitive(node, function (babylonMesh) {
  4503. meshes.push(babylonMesh);
  4504. });
  4505. }
  4506. }
  4507. return meshes;
  4508. };
  4509. GLTFLoader.prototype._getSkeletons = function () {
  4510. var skeletons = new Array();
  4511. var skins = this._gltf.skins;
  4512. if (skins) {
  4513. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  4514. var skin = skins_1[_i];
  4515. if (skin._data) {
  4516. skeletons.push(skin._data.babylonSkeleton);
  4517. }
  4518. }
  4519. }
  4520. return skeletons;
  4521. };
  4522. GLTFLoader.prototype._getAnimationGroups = function () {
  4523. var animationGroups = new Array();
  4524. var animations = this._gltf.animations;
  4525. if (animations) {
  4526. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  4527. var animation = animations_1[_i];
  4528. if (animation._babylonAnimationGroup) {
  4529. animationGroups.push(animation._babylonAnimationGroup);
  4530. }
  4531. }
  4532. }
  4533. return animationGroups;
  4534. };
  4535. GLTFLoader.prototype._startAnimations = function () {
  4536. switch (this._parent.animationStartMode) {
  4537. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  4538. // do nothing
  4539. break;
  4540. }
  4541. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  4542. var babylonAnimationGroups = this._getAnimationGroups();
  4543. if (babylonAnimationGroups.length !== 0) {
  4544. babylonAnimationGroups[0].start(true);
  4545. }
  4546. break;
  4547. }
  4548. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  4549. var babylonAnimationGroups = this._getAnimationGroups();
  4550. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  4551. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  4552. babylonAnimationGroup.start(true);
  4553. }
  4554. break;
  4555. }
  4556. default: {
  4557. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  4558. return;
  4559. }
  4560. }
  4561. };
  4562. /**
  4563. * Loads a glTF node.
  4564. * @param context The context when loading the asset
  4565. * @param node The glTF node property
  4566. * @param assign A function called synchronously after parsing the glTF properties
  4567. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  4568. */
  4569. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  4570. var _this = this;
  4571. if (assign === void 0) { assign = function () { }; }
  4572. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  4573. if (extensionPromise) {
  4574. return extensionPromise;
  4575. }
  4576. if (node._babylonTransformNode) {
  4577. throw new Error(context + ": Invalid recursive node hierarchy");
  4578. }
  4579. var promises = new Array();
  4580. this.logOpen(context + " " + (node.name || ""));
  4581. var loadNode = function (babylonTransformNode) {
  4582. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  4583. GLTFLoader._LoadTransform(node, babylonTransformNode);
  4584. if (node.camera != undefined) {
  4585. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  4586. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  4587. babylonCamera.parent = babylonTransformNode;
  4588. }));
  4589. }
  4590. if (node.children) {
  4591. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  4592. var index = _a[_i];
  4593. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  4594. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  4595. childBabylonMesh.parent = babylonTransformNode;
  4596. }));
  4597. }
  4598. }
  4599. assign(babylonTransformNode);
  4600. };
  4601. if (node.mesh == undefined) {
  4602. var nodeName = node.name || "node" + node.index;
  4603. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  4604. loadNode(node._babylonTransformNode);
  4605. }
  4606. else {
  4607. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  4608. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  4609. }
  4610. this.logClose();
  4611. return Promise.all(promises).then(function () {
  4612. _this._forEachPrimitive(node, function (babylonMesh) {
  4613. babylonMesh.refreshBoundingInfo(true);
  4614. });
  4615. return node._babylonTransformNode;
  4616. });
  4617. };
  4618. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  4619. var primitives = mesh.primitives;
  4620. if (!primitives || !primitives.length) {
  4621. throw new Error(context + ": Primitives are missing");
  4622. }
  4623. if (primitives[0].index == undefined) {
  4624. ArrayItem.Assign(primitives);
  4625. }
  4626. var promises = new Array();
  4627. this.logOpen(context + " " + (mesh.name || ""));
  4628. var name = node.name || "node" + node.index;
  4629. if (primitives.length === 1) {
  4630. var primitive = mesh.primitives[0];
  4631. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  4632. node._babylonTransformNode = babylonMesh;
  4633. node._primitiveBabylonMeshes = [babylonMesh];
  4634. }));
  4635. }
  4636. else {
  4637. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  4638. node._primitiveBabylonMeshes = [];
  4639. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  4640. var primitive = primitives_1[_i];
  4641. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  4642. babylonMesh.parent = node._babylonTransformNode;
  4643. node._primitiveBabylonMeshes.push(babylonMesh);
  4644. }));
  4645. }
  4646. }
  4647. if (node.skin != undefined) {
  4648. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  4649. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  4650. }
  4651. assign(node._babylonTransformNode);
  4652. this.logClose();
  4653. return Promise.all(promises).then(function () {
  4654. return node._babylonTransformNode;
  4655. });
  4656. };
  4657. /**
  4658. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  4659. * @param context The context when loading the asset
  4660. * @param name The mesh name when loading the asset
  4661. * @param node The glTF node when loading the asset
  4662. * @param mesh The glTF mesh when loading the asset
  4663. * @param primitive The glTF mesh primitive property
  4664. * @param assign A function called synchronously after parsing the glTF properties
  4665. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  4666. */
  4667. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  4668. var _this = this;
  4669. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  4670. if (extensionPromise) {
  4671. return extensionPromise;
  4672. }
  4673. this.logOpen("" + context);
  4674. var shouldInstance = this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  4675. var babylonAbstractMesh;
  4676. var promise;
  4677. if (shouldInstance && primitive._instanceData) {
  4678. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  4679. promise = primitive._instanceData.promise;
  4680. }
  4681. else {
  4682. var promises = new Array();
  4683. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  4684. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  4685. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  4686. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  4687. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  4688. babylonGeometry.applyToMesh(babylonMesh_1);
  4689. });
  4690. }));
  4691. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  4692. if (primitive.material == undefined) {
  4693. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  4694. if (!babylonMaterial) {
  4695. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  4696. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  4697. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  4698. }
  4699. babylonMesh_1.material = babylonMaterial;
  4700. }
  4701. else {
  4702. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  4703. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  4704. babylonMesh_1.material = babylonMaterial;
  4705. }));
  4706. }
  4707. promise = Promise.all(promises);
  4708. if (shouldInstance) {
  4709. primitive._instanceData = {
  4710. babylonSourceMesh: babylonMesh_1,
  4711. promise: promise
  4712. };
  4713. }
  4714. babylonAbstractMesh = babylonMesh_1;
  4715. }
  4716. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  4717. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  4718. assign(babylonAbstractMesh);
  4719. this.logClose();
  4720. return promise.then(function () {
  4721. return babylonAbstractMesh;
  4722. });
  4723. };
  4724. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4725. var _this = this;
  4726. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  4727. if (extensionPromise) {
  4728. return extensionPromise;
  4729. }
  4730. var attributes = primitive.attributes;
  4731. if (!attributes) {
  4732. throw new Error(context + ": Attributes are missing");
  4733. }
  4734. var promises = new Array();
  4735. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  4736. if (primitive.indices == undefined) {
  4737. babylonMesh.isUnIndexed = true;
  4738. }
  4739. else {
  4740. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  4741. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  4742. babylonGeometry.setIndices(data);
  4743. }));
  4744. }
  4745. var loadAttribute = function (attribute, kind, callback) {
  4746. if (attributes[attribute] == undefined) {
  4747. return;
  4748. }
  4749. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4750. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4751. babylonMesh._delayInfo.push(kind);
  4752. }
  4753. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  4754. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  4755. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  4756. }));
  4757. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  4758. babylonMesh.numBoneInfluencers = 8;
  4759. }
  4760. if (callback) {
  4761. callback(accessor);
  4762. }
  4763. };
  4764. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4765. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4766. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4767. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4768. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4769. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4770. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4771. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  4772. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  4773. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  4774. if (accessor.type === "VEC4" /* VEC4 */) {
  4775. babylonMesh.hasVertexAlpha = true;
  4776. }
  4777. });
  4778. return Promise.all(promises).then(function () {
  4779. return babylonGeometry;
  4780. });
  4781. };
  4782. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  4783. if (!primitive.targets) {
  4784. return;
  4785. }
  4786. if (node._numMorphTargets == undefined) {
  4787. node._numMorphTargets = primitive.targets.length;
  4788. }
  4789. else if (primitive.targets.length !== node._numMorphTargets) {
  4790. throw new Error(context + ": Primitives do not have the same number of targets");
  4791. }
  4792. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  4793. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  4794. for (var index = 0; index < primitive.targets.length; index++) {
  4795. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  4796. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  4797. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  4798. // TODO: tell the target whether it has positions, normals, tangents
  4799. }
  4800. };
  4801. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  4802. if (!primitive.targets) {
  4803. return Promise.resolve();
  4804. }
  4805. var promises = new Array();
  4806. var morphTargetManager = babylonMesh.morphTargetManager;
  4807. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  4808. var babylonMorphTarget = morphTargetManager.getTarget(index);
  4809. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  4810. }
  4811. return Promise.all(promises).then(function () { });
  4812. };
  4813. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  4814. var _this = this;
  4815. var promises = new Array();
  4816. var loadAttribute = function (attribute, kind, setData) {
  4817. if (attributes[attribute] == undefined) {
  4818. return;
  4819. }
  4820. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  4821. if (!babylonVertexBuffer) {
  4822. return;
  4823. }
  4824. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  4825. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  4826. setData(babylonVertexBuffer, data);
  4827. }));
  4828. };
  4829. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  4830. var positions = new Float32Array(data.length);
  4831. babylonVertexBuffer.forEach(data.length, function (value, index) {
  4832. positions[index] = data[index] + value;
  4833. });
  4834. babylonMorphTarget.setPositions(positions);
  4835. });
  4836. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  4837. var normals = new Float32Array(data.length);
  4838. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  4839. normals[index] = data[index] + value;
  4840. });
  4841. babylonMorphTarget.setNormals(normals);
  4842. });
  4843. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  4844. var tangents = new Float32Array(data.length / 3 * 4);
  4845. var dataIndex = 0;
  4846. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  4847. // Tangent data for morph targets is stored as xyz delta.
  4848. // The vertexData.tangent is stored as xyzw.
  4849. // So we need to skip every fourth vertexData.tangent.
  4850. if (((index + 1) % 4) !== 0) {
  4851. tangents[dataIndex] = data[dataIndex] + value;
  4852. dataIndex++;
  4853. }
  4854. });
  4855. babylonMorphTarget.setTangents(tangents);
  4856. });
  4857. return Promise.all(promises).then(function () { });
  4858. };
  4859. GLTFLoader._LoadTransform = function (node, babylonNode) {
  4860. // Ignore the TRS of skinned nodes.
  4861. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  4862. if (node.skin != undefined) {
  4863. return;
  4864. }
  4865. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  4866. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  4867. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  4868. if (node.matrix) {
  4869. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  4870. matrix.decompose(scaling, rotation, position);
  4871. }
  4872. else {
  4873. if (node.translation) {
  4874. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  4875. }
  4876. if (node.rotation) {
  4877. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  4878. }
  4879. if (node.scale) {
  4880. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  4881. }
  4882. }
  4883. babylonNode.position = position;
  4884. babylonNode.rotationQuaternion = rotation;
  4885. babylonNode.scaling = scaling;
  4886. };
  4887. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  4888. var _this = this;
  4889. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  4890. if (extensionPromise) {
  4891. return extensionPromise;
  4892. }
  4893. var assignSkeleton = function (skeleton) {
  4894. _this._forEachPrimitive(node, function (babylonMesh) {
  4895. babylonMesh.skeleton = skeleton;
  4896. });
  4897. };
  4898. if (skin._data) {
  4899. assignSkeleton(skin._data.babylonSkeleton);
  4900. return skin._data.promise;
  4901. }
  4902. var skeletonId = "skeleton" + skin.index;
  4903. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  4904. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  4905. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  4906. this._loadBones(context, skin, babylonSkeleton);
  4907. assignSkeleton(babylonSkeleton);
  4908. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  4909. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  4910. });
  4911. skin._data = {
  4912. babylonSkeleton: babylonSkeleton,
  4913. promise: promise
  4914. };
  4915. return promise;
  4916. };
  4917. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  4918. var babylonBones = {};
  4919. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  4920. var index = _a[_i];
  4921. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  4922. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  4923. }
  4924. };
  4925. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  4926. var babylonBone = babylonBones[node.index];
  4927. if (babylonBone) {
  4928. return babylonBone;
  4929. }
  4930. var babylonParentBone = null;
  4931. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  4932. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  4933. }
  4934. var boneIndex = skin.joints.indexOf(node.index);
  4935. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  4936. babylonBones[node.index] = babylonBone;
  4937. node._babylonBones = node._babylonBones || [];
  4938. node._babylonBones.push(babylonBone);
  4939. return babylonBone;
  4940. };
  4941. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  4942. if (skin.inverseBindMatrices == undefined) {
  4943. return Promise.resolve(null);
  4944. }
  4945. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  4946. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  4947. };
  4948. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  4949. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  4950. var babylonBone = _a[_i];
  4951. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  4952. var boneIndex = babylonBone._index;
  4953. if (inverseBindMatricesData && boneIndex !== -1) {
  4954. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  4955. baseMatrix.invertToRef(baseMatrix);
  4956. }
  4957. var babylonParentBone = babylonBone.getParent();
  4958. if (babylonParentBone) {
  4959. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  4960. }
  4961. babylonBone.updateMatrix(baseMatrix, false, false);
  4962. babylonBone._updateDifferenceMatrix(undefined, false);
  4963. }
  4964. };
  4965. GLTFLoader.prototype._getNodeMatrix = function (node) {
  4966. return node.matrix ?
  4967. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  4968. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Compose(node.scale ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One(), node.rotation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity(), node.translation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero());
  4969. };
  4970. /**
  4971. * Loads a glTF camera.
  4972. * @param context The context when loading the asset
  4973. * @param camera The glTF camera property
  4974. * @param assign A function called synchronously after parsing the glTF properties
  4975. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  4976. */
  4977. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  4978. if (assign === void 0) { assign = function () { }; }
  4979. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  4980. if (extensionPromise) {
  4981. return extensionPromise;
  4982. }
  4983. var promises = new Array();
  4984. this.logOpen(context + " " + (camera.name || ""));
  4985. var babylonCamera = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["FreeCamera"](camera.name || "camera" + camera.index, babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), this._babylonScene, false);
  4986. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  4987. switch (camera.type) {
  4988. case "perspective" /* PERSPECTIVE */: {
  4989. var perspective = camera.perspective;
  4990. if (!perspective) {
  4991. throw new Error(context + ": Camera perspective properties are missing");
  4992. }
  4993. babylonCamera.fov = perspective.yfov;
  4994. babylonCamera.minZ = perspective.znear;
  4995. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  4996. break;
  4997. }
  4998. case "orthographic" /* ORTHOGRAPHIC */: {
  4999. if (!camera.orthographic) {
  5000. throw new Error(context + ": Camera orthographic properties are missing");
  5001. }
  5002. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  5003. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  5004. babylonCamera.orthoRight = camera.orthographic.xmag;
  5005. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  5006. babylonCamera.orthoTop = camera.orthographic.ymag;
  5007. babylonCamera.minZ = camera.orthographic.znear;
  5008. babylonCamera.maxZ = camera.orthographic.zfar;
  5009. break;
  5010. }
  5011. default: {
  5012. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  5013. }
  5014. }
  5015. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  5016. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  5017. assign(babylonCamera);
  5018. return Promise.all(promises).then(function () {
  5019. return babylonCamera;
  5020. });
  5021. };
  5022. GLTFLoader.prototype._loadAnimationsAsync = function () {
  5023. var animations = this._gltf.animations;
  5024. if (!animations) {
  5025. return Promise.resolve();
  5026. }
  5027. var promises = new Array();
  5028. for (var index = 0; index < animations.length; index++) {
  5029. var animation = animations[index];
  5030. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  5031. }
  5032. return Promise.all(promises).then(function () { });
  5033. };
  5034. /**
  5035. * Loads a glTF animation.
  5036. * @param context The context when loading the asset
  5037. * @param animation The glTF animation property
  5038. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  5039. */
  5040. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  5041. var promise = this._extensionsLoadAnimationAsync(context, animation);
  5042. if (promise) {
  5043. return promise;
  5044. }
  5045. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  5046. animation._babylonAnimationGroup = babylonAnimationGroup;
  5047. var promises = new Array();
  5048. ArrayItem.Assign(animation.channels);
  5049. ArrayItem.Assign(animation.samplers);
  5050. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  5051. var channel = _a[_i];
  5052. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  5053. }
  5054. return Promise.all(promises).then(function () {
  5055. babylonAnimationGroup.normalize(0);
  5056. return babylonAnimationGroup;
  5057. });
  5058. };
  5059. /**
  5060. * @hidden Loads a glTF animation channel.
  5061. * @param context The context when loading the asset
  5062. * @param animationContext The context of the animation when loading the asset
  5063. * @param animation The glTF animation property
  5064. * @param channel The glTF animation channel property
  5065. * @param babylonAnimationGroup The babylon animation group property
  5066. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  5067. * @returns A void promise when the channel load is complete
  5068. */
  5069. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  5070. var _this = this;
  5071. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  5072. if (channel.target.node == undefined) {
  5073. return Promise.resolve();
  5074. }
  5075. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  5076. // Ignore animations that have no animation targets.
  5077. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  5078. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  5079. return Promise.resolve();
  5080. }
  5081. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  5082. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  5083. var targetPath;
  5084. var animationType;
  5085. switch (channel.target.path) {
  5086. case "translation" /* TRANSLATION */: {
  5087. targetPath = "position";
  5088. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  5089. break;
  5090. }
  5091. case "rotation" /* ROTATION */: {
  5092. targetPath = "rotationQuaternion";
  5093. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  5094. break;
  5095. }
  5096. case "scale" /* SCALE */: {
  5097. targetPath = "scaling";
  5098. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  5099. break;
  5100. }
  5101. case "weights" /* WEIGHTS */: {
  5102. targetPath = "influence";
  5103. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  5104. break;
  5105. }
  5106. default: {
  5107. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  5108. }
  5109. }
  5110. var outputBufferOffset = 0;
  5111. var getNextOutputValue;
  5112. switch (targetPath) {
  5113. case "position": {
  5114. getNextOutputValue = function () {
  5115. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  5116. outputBufferOffset += 3;
  5117. return value;
  5118. };
  5119. break;
  5120. }
  5121. case "rotationQuaternion": {
  5122. getNextOutputValue = function () {
  5123. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  5124. outputBufferOffset += 4;
  5125. return value;
  5126. };
  5127. break;
  5128. }
  5129. case "scaling": {
  5130. getNextOutputValue = function () {
  5131. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  5132. outputBufferOffset += 3;
  5133. return value;
  5134. };
  5135. break;
  5136. }
  5137. case "influence": {
  5138. getNextOutputValue = function () {
  5139. var value = new Array(targetNode._numMorphTargets);
  5140. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  5141. value[i] = data.output[outputBufferOffset++];
  5142. }
  5143. return value;
  5144. };
  5145. break;
  5146. }
  5147. }
  5148. var getNextKey;
  5149. switch (data.interpolation) {
  5150. case "STEP" /* STEP */: {
  5151. getNextKey = function (frameIndex) { return ({
  5152. frame: data.input[frameIndex],
  5153. value: getNextOutputValue(),
  5154. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  5155. }); };
  5156. break;
  5157. }
  5158. case "LINEAR" /* LINEAR */: {
  5159. getNextKey = function (frameIndex) { return ({
  5160. frame: data.input[frameIndex],
  5161. value: getNextOutputValue()
  5162. }); };
  5163. break;
  5164. }
  5165. case "CUBICSPLINE" /* CUBICSPLINE */: {
  5166. getNextKey = function (frameIndex) { return ({
  5167. frame: data.input[frameIndex],
  5168. inTangent: getNextOutputValue(),
  5169. value: getNextOutputValue(),
  5170. outTangent: getNextOutputValue()
  5171. }); };
  5172. break;
  5173. }
  5174. }
  5175. var keys = new Array(data.input.length);
  5176. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  5177. keys[frameIndex] = getNextKey(frameIndex);
  5178. }
  5179. if (targetPath === "influence") {
  5180. var _loop_2 = function (targetIndex) {
  5181. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  5182. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  5183. babylonAnimation.setKeys(keys.map(function (key) { return ({
  5184. frame: key.frame,
  5185. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  5186. value: key.value[targetIndex],
  5187. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  5188. }); }));
  5189. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  5190. var babylonMesh = babylonAbstractMesh;
  5191. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  5192. var babylonAnimationClone = babylonAnimation.clone();
  5193. morphTarget.animations.push(babylonAnimationClone);
  5194. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  5195. });
  5196. };
  5197. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  5198. _loop_2(targetIndex);
  5199. }
  5200. }
  5201. else {
  5202. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  5203. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  5204. babylonAnimation.setKeys(keys);
  5205. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  5206. animationTargetOverride.animations.push(babylonAnimation);
  5207. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  5208. }
  5209. else {
  5210. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  5211. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  5212. }
  5213. }
  5214. });
  5215. };
  5216. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  5217. if (sampler._data) {
  5218. return sampler._data;
  5219. }
  5220. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  5221. switch (interpolation) {
  5222. case "STEP" /* STEP */:
  5223. case "LINEAR" /* LINEAR */:
  5224. case "CUBICSPLINE" /* CUBICSPLINE */: {
  5225. break;
  5226. }
  5227. default: {
  5228. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  5229. }
  5230. }
  5231. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  5232. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  5233. sampler._data = Promise.all([
  5234. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  5235. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  5236. ]).then(function (_a) {
  5237. var inputData = _a[0], outputData = _a[1];
  5238. return {
  5239. input: inputData,
  5240. interpolation: interpolation,
  5241. output: outputData,
  5242. };
  5243. });
  5244. return sampler._data;
  5245. };
  5246. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5247. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  5248. if (extensionPromise) {
  5249. return extensionPromise;
  5250. }
  5251. if (!buffer._data) {
  5252. if (buffer.uri) {
  5253. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  5254. }
  5255. else {
  5256. if (!this._bin) {
  5257. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5258. }
  5259. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  5260. }
  5261. }
  5262. return buffer._data.then(function (data) {
  5263. try {
  5264. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  5265. }
  5266. catch (e) {
  5267. throw new Error(context + ": " + e.message);
  5268. }
  5269. });
  5270. };
  5271. /**
  5272. * Loads a glTF buffer view.
  5273. * @param context The context when loading the asset
  5274. * @param bufferView The glTF buffer view property
  5275. * @returns A promise that resolves with the loaded data when the load is complete
  5276. */
  5277. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  5278. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  5279. if (extensionPromise) {
  5280. return extensionPromise;
  5281. }
  5282. if (bufferView._data) {
  5283. return bufferView._data;
  5284. }
  5285. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  5286. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  5287. return bufferView._data;
  5288. };
  5289. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  5290. var _this = this;
  5291. if (accessor._data) {
  5292. return accessor._data;
  5293. }
  5294. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  5295. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  5296. var length = numComponents * accessor.count;
  5297. if (accessor.bufferView == undefined) {
  5298. accessor._data = Promise.resolve(new constructor(length));
  5299. }
  5300. else {
  5301. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  5302. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  5303. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  5304. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  5305. }
  5306. else {
  5307. var typedArray_1 = new constructor(length);
  5308. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, typedArray_1.length, accessor.normalized || false, function (value, index) {
  5309. typedArray_1[index] = value;
  5310. });
  5311. return typedArray_1;
  5312. }
  5313. });
  5314. }
  5315. if (accessor.sparse) {
  5316. var sparse_1 = accessor.sparse;
  5317. accessor._data = accessor._data.then(function (data) {
  5318. var typedArray = data;
  5319. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  5320. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  5321. return Promise.all([
  5322. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  5323. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  5324. ]).then(function (_a) {
  5325. var indicesData = _a[0], valuesData = _a[1];
  5326. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  5327. var sparseLength = numComponents * sparse_1.count;
  5328. var values;
  5329. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  5330. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  5331. }
  5332. else {
  5333. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  5334. values = new constructor(sparseLength);
  5335. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  5336. values[index] = value;
  5337. });
  5338. }
  5339. var valuesIndex = 0;
  5340. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  5341. var dataIndex = indices[indicesIndex] * numComponents;
  5342. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  5343. typedArray[dataIndex++] = values[valuesIndex++];
  5344. }
  5345. }
  5346. return typedArray;
  5347. });
  5348. });
  5349. }
  5350. return accessor._data;
  5351. };
  5352. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  5353. return this._loadAccessorAsync(context, accessor, Float32Array);
  5354. };
  5355. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  5356. if (accessor.type !== "SCALAR" /* SCALAR */) {
  5357. throw new Error(context + "/type: Invalid value " + accessor.type);
  5358. }
  5359. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  5360. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  5361. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  5362. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  5363. }
  5364. if (accessor._data) {
  5365. return accessor._data;
  5366. }
  5367. if (accessor.sparse) {
  5368. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  5369. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  5370. }
  5371. else {
  5372. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  5373. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  5374. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  5375. });
  5376. }
  5377. return accessor._data;
  5378. };
  5379. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  5380. var _this = this;
  5381. if (bufferView._babylonBuffer) {
  5382. return bufferView._babylonBuffer;
  5383. }
  5384. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  5385. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  5386. });
  5387. return bufferView._babylonBuffer;
  5388. };
  5389. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  5390. var _this = this;
  5391. if (accessor._babylonVertexBuffer) {
  5392. return accessor._babylonVertexBuffer;
  5393. }
  5394. if (accessor.sparse) {
  5395. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  5396. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  5397. });
  5398. }
  5399. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  5400. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  5401. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  5402. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  5403. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  5404. });
  5405. }
  5406. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  5407. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  5408. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  5409. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  5410. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  5411. });
  5412. }
  5413. else {
  5414. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  5415. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  5416. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  5417. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
  5418. });
  5419. }
  5420. return accessor._babylonVertexBuffer;
  5421. };
  5422. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  5423. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5424. throw new Error(context + ": Material type not supported");
  5425. }
  5426. var promises = new Array();
  5427. if (properties) {
  5428. if (properties.baseColorFactor) {
  5429. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  5430. babylonMaterial.alpha = properties.baseColorFactor[3];
  5431. }
  5432. else {
  5433. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  5434. }
  5435. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  5436. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  5437. if (properties.baseColorTexture) {
  5438. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  5439. texture.name = babylonMaterial.name + " (Base Color)";
  5440. babylonMaterial.albedoTexture = texture;
  5441. }));
  5442. }
  5443. if (properties.metallicRoughnessTexture) {
  5444. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  5445. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  5446. babylonMaterial.metallicTexture = texture;
  5447. }));
  5448. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  5449. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  5450. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  5451. }
  5452. }
  5453. return Promise.all(promises).then(function () { });
  5454. };
  5455. /** @hidden */
  5456. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5457. if (assign === void 0) { assign = function () { }; }
  5458. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  5459. if (extensionPromise) {
  5460. return extensionPromise;
  5461. }
  5462. material._data = material._data || {};
  5463. var babylonData = material._data[babylonDrawMode];
  5464. if (!babylonData) {
  5465. this.logOpen(context + " " + (material.name || ""));
  5466. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  5467. babylonData = {
  5468. babylonMaterial: babylonMaterial,
  5469. babylonMeshes: [],
  5470. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  5471. };
  5472. material._data[babylonDrawMode] = babylonData;
  5473. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  5474. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  5475. this.logClose();
  5476. }
  5477. babylonData.babylonMeshes.push(babylonMesh);
  5478. babylonMesh.onDisposeObservable.addOnce(function () {
  5479. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  5480. if (index !== -1) {
  5481. babylonData.babylonMeshes.splice(index, 1);
  5482. }
  5483. });
  5484. assign(babylonData.babylonMaterial);
  5485. return babylonData.promise.then(function () {
  5486. return babylonData.babylonMaterial;
  5487. });
  5488. };
  5489. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  5490. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  5491. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  5492. babylonMaterial.fillMode = babylonDrawMode;
  5493. babylonMaterial.enableSpecularAntiAliasing = true;
  5494. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  5495. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  5496. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  5497. babylonMaterial.metallic = 1;
  5498. babylonMaterial.roughness = 1;
  5499. return babylonMaterial;
  5500. };
  5501. /**
  5502. * Creates a Babylon material from a glTF material.
  5503. * @param context The context when loading the asset
  5504. * @param material The glTF material property
  5505. * @param babylonDrawMode The draw mode for the Babylon material
  5506. * @returns The Babylon material
  5507. */
  5508. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  5509. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  5510. if (extensionPromise) {
  5511. return extensionPromise;
  5512. }
  5513. var name = material.name || "material" + material.index;
  5514. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  5515. return babylonMaterial;
  5516. };
  5517. /**
  5518. * Loads properties from a glTF material into a Babylon material.
  5519. * @param context The context when loading the asset
  5520. * @param material The glTF material property
  5521. * @param babylonMaterial The Babylon material
  5522. * @returns A promise that resolves when the load is complete
  5523. */
  5524. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5525. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  5526. if (extensionPromise) {
  5527. return extensionPromise;
  5528. }
  5529. var promises = new Array();
  5530. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  5531. if (material.pbrMetallicRoughness) {
  5532. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  5533. }
  5534. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  5535. return Promise.all(promises).then(function () { });
  5536. };
  5537. /**
  5538. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  5539. * @param context The context when loading the asset
  5540. * @param material The glTF material property
  5541. * @param babylonMaterial The Babylon material
  5542. * @returns A promise that resolves when the load is complete
  5543. */
  5544. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  5545. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5546. throw new Error(context + ": Material type not supported");
  5547. }
  5548. var promises = new Array();
  5549. babylonMaterial.emissiveColor = material.emissiveFactor ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(material.emissiveFactor) : new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"](0, 0, 0);
  5550. if (material.doubleSided) {
  5551. babylonMaterial.backFaceCulling = false;
  5552. babylonMaterial.twoSidedLighting = true;
  5553. }
  5554. if (material.normalTexture) {
  5555. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  5556. texture.name = babylonMaterial.name + " (Normal)";
  5557. babylonMaterial.bumpTexture = texture;
  5558. }));
  5559. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  5560. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  5561. if (material.normalTexture.scale != undefined) {
  5562. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  5563. }
  5564. babylonMaterial.forceIrradianceInFragment = true;
  5565. }
  5566. if (material.occlusionTexture) {
  5567. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  5568. texture.name = babylonMaterial.name + " (Occlusion)";
  5569. babylonMaterial.ambientTexture = texture;
  5570. }));
  5571. babylonMaterial.useAmbientInGrayScale = true;
  5572. if (material.occlusionTexture.strength != undefined) {
  5573. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  5574. }
  5575. }
  5576. if (material.emissiveTexture) {
  5577. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  5578. texture.name = babylonMaterial.name + " (Emissive)";
  5579. babylonMaterial.emissiveTexture = texture;
  5580. }));
  5581. }
  5582. return Promise.all(promises).then(function () { });
  5583. };
  5584. /**
  5585. * Loads the alpha properties from a glTF material into a Babylon material.
  5586. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  5587. * @param context The context when loading the asset
  5588. * @param material The glTF material property
  5589. * @param babylonMaterial The Babylon material
  5590. */
  5591. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  5592. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5593. throw new Error(context + ": Material type not supported");
  5594. }
  5595. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  5596. switch (alphaMode) {
  5597. case "OPAQUE" /* OPAQUE */: {
  5598. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  5599. break;
  5600. }
  5601. case "MASK" /* MASK */: {
  5602. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  5603. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  5604. if (babylonMaterial.albedoTexture) {
  5605. babylonMaterial.albedoTexture.hasAlpha = true;
  5606. }
  5607. break;
  5608. }
  5609. case "BLEND" /* BLEND */: {
  5610. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  5611. if (babylonMaterial.albedoTexture) {
  5612. babylonMaterial.albedoTexture.hasAlpha = true;
  5613. babylonMaterial.useAlphaFromAlbedoTexture = true;
  5614. }
  5615. break;
  5616. }
  5617. default: {
  5618. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  5619. }
  5620. }
  5621. };
  5622. /**
  5623. * Loads a glTF texture info.
  5624. * @param context The context when loading the asset
  5625. * @param textureInfo The glTF texture info property
  5626. * @param assign A function called synchronously after parsing the glTF properties
  5627. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  5628. */
  5629. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  5630. var _this = this;
  5631. if (assign === void 0) { assign = function () { }; }
  5632. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  5633. if (extensionPromise) {
  5634. return extensionPromise;
  5635. }
  5636. this.logOpen("" + context);
  5637. if (textureInfo.texCoord >= 2) {
  5638. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  5639. }
  5640. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  5641. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  5642. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  5643. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  5644. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  5645. assign(babylonTexture);
  5646. });
  5647. this.logClose();
  5648. return promise;
  5649. };
  5650. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  5651. var _this = this;
  5652. if (assign === void 0) { assign = function () { }; }
  5653. var promises = new Array();
  5654. this.logOpen(context + " " + (texture.name || ""));
  5655. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  5656. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  5657. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  5658. var url = null;
  5659. if (image.uri) {
  5660. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  5661. url = image.uri;
  5662. }
  5663. else if (this._babylonScene.getEngine().textureFormatInUse) {
  5664. // If an image uri and a texture format is set like (eg. KTX) load from url instead of blob to support texture format and fallback
  5665. url = this._rootUrl + image.uri;
  5666. }
  5667. }
  5668. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5669. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  5670. if (!_this._disposed) {
  5671. deferred.resolve();
  5672. }
  5673. }, function (message, exception) {
  5674. if (!_this._disposed) {
  5675. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  5676. }
  5677. }, undefined, undefined, undefined, image.mimeType);
  5678. promises.push(deferred.promise);
  5679. if (!url) {
  5680. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  5681. var name = image.uri || _this._fileName + "#image" + image.index;
  5682. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  5683. babylonTexture.updateURL(dataUrl, data);
  5684. }));
  5685. }
  5686. babylonTexture.wrapU = samplerData.wrapU;
  5687. babylonTexture.wrapV = samplerData.wrapV;
  5688. assign(babylonTexture);
  5689. this.logClose();
  5690. return Promise.all(promises).then(function () {
  5691. return babylonTexture;
  5692. });
  5693. };
  5694. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  5695. if (!sampler._data) {
  5696. sampler._data = {
  5697. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  5698. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  5699. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  5700. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  5701. };
  5702. }
  5703. return sampler._data;
  5704. };
  5705. /**
  5706. * Loads a glTF image.
  5707. * @param context The context when loading the asset
  5708. * @param image The glTF image property
  5709. * @returns A promise that resolves with the loaded data when the load is complete
  5710. */
  5711. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  5712. if (!image._data) {
  5713. this.logOpen(context + " " + (image.name || ""));
  5714. if (image.uri) {
  5715. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  5716. }
  5717. else {
  5718. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  5719. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  5720. }
  5721. this.logClose();
  5722. }
  5723. return image._data;
  5724. };
  5725. /**
  5726. * Loads a glTF uri.
  5727. * @param context The context when loading the asset
  5728. * @param property The glTF property associated with the uri
  5729. * @param uri The base64 or relative uri
  5730. * @returns A promise that resolves with the loaded data when the load is complete
  5731. */
  5732. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  5733. var _this = this;
  5734. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  5735. if (extensionPromise) {
  5736. return extensionPromise;
  5737. }
  5738. if (!GLTFLoader._ValidateUri(uri)) {
  5739. throw new Error(context + ": '" + uri + "' is invalid");
  5740. }
  5741. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  5742. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  5743. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  5744. return Promise.resolve(data);
  5745. }
  5746. this.log("Loading " + uri);
  5747. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  5748. return new Promise(function (resolve, reject) {
  5749. if (!_this._disposed) {
  5750. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  5751. if (!_this._disposed) {
  5752. var data = new Uint8Array(fileData);
  5753. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  5754. resolve(data);
  5755. }
  5756. }, function (event) {
  5757. if (!_this._disposed) {
  5758. if (request_1) {
  5759. request_1._lengthComputable = event.lengthComputable;
  5760. request_1._loaded = event.loaded;
  5761. request_1._total = event.total;
  5762. }
  5763. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  5764. try {
  5765. _this._onProgress();
  5766. }
  5767. catch (e) {
  5768. reject(e);
  5769. }
  5770. }
  5771. }
  5772. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  5773. if (!_this._disposed) {
  5774. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  5775. }
  5776. });
  5777. _this._requests.push(request_1);
  5778. }
  5779. });
  5780. });
  5781. };
  5782. GLTFLoader.prototype._onProgress = function () {
  5783. if (!this._progressCallback) {
  5784. return;
  5785. }
  5786. var lengthComputable = true;
  5787. var loaded = 0;
  5788. var total = 0;
  5789. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  5790. var request = _a[_i];
  5791. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  5792. return;
  5793. }
  5794. lengthComputable = lengthComputable && request._lengthComputable;
  5795. loaded += request._loaded;
  5796. total += request._total;
  5797. }
  5798. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  5799. };
  5800. /**
  5801. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  5802. * @param babylonObject the Babylon object with metadata
  5803. * @param pointer the JSON pointer
  5804. */
  5805. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  5806. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  5807. var gltf = (metadata.gltf = metadata.gltf || {});
  5808. var pointers = (gltf.pointers = gltf.pointers || []);
  5809. pointers.push(pointer);
  5810. };
  5811. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  5812. // Set defaults if undefined
  5813. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  5814. switch (mode) {
  5815. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  5816. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  5817. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  5818. default:
  5819. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  5820. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  5821. }
  5822. };
  5823. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  5824. // Set defaults if undefined
  5825. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  5826. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  5827. if (magFilter === 9729 /* LINEAR */) {
  5828. switch (minFilter) {
  5829. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  5830. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  5831. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  5832. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  5833. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  5834. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  5835. default:
  5836. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  5837. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  5838. }
  5839. }
  5840. else {
  5841. if (magFilter !== 9728 /* NEAREST */) {
  5842. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  5843. }
  5844. switch (minFilter) {
  5845. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  5846. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  5847. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  5848. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  5849. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  5850. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  5851. default:
  5852. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  5853. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  5854. }
  5855. }
  5856. };
  5857. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  5858. switch (componentType) {
  5859. case 5120 /* BYTE */: return Int8Array;
  5860. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  5861. case 5122 /* SHORT */: return Int16Array;
  5862. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  5863. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  5864. case 5126 /* FLOAT */: return Float32Array;
  5865. default: throw new Error(context + ": Invalid component type " + componentType);
  5866. }
  5867. };
  5868. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  5869. var buffer = bufferView.buffer;
  5870. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  5871. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  5872. try {
  5873. return new constructor(buffer, byteOffset, length);
  5874. }
  5875. catch (e) {
  5876. throw new Error(context + ": " + e);
  5877. }
  5878. };
  5879. GLTFLoader._GetNumComponents = function (context, type) {
  5880. switch (type) {
  5881. case "SCALAR": return 1;
  5882. case "VEC2": return 2;
  5883. case "VEC3": return 3;
  5884. case "VEC4": return 4;
  5885. case "MAT2": return 4;
  5886. case "MAT3": return 9;
  5887. case "MAT4": return 16;
  5888. }
  5889. throw new Error(context + ": Invalid type (" + type + ")");
  5890. };
  5891. GLTFLoader._ValidateUri = function (uri) {
  5892. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  5893. };
  5894. GLTFLoader._GetDrawMode = function (context, mode) {
  5895. if (mode == undefined) {
  5896. mode = 4 /* TRIANGLES */;
  5897. }
  5898. switch (mode) {
  5899. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  5900. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  5901. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  5902. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  5903. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  5904. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  5905. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  5906. }
  5907. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  5908. };
  5909. GLTFLoader.prototype._compileMaterialsAsync = function () {
  5910. var _this = this;
  5911. this._parent._startPerformanceCounter("Compile materials");
  5912. var promises = new Array();
  5913. if (this._gltf.materials) {
  5914. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  5915. var material = _a[_i];
  5916. if (material._data) {
  5917. for (var babylonDrawMode in material._data) {
  5918. var babylonData = material._data[babylonDrawMode];
  5919. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  5920. var babylonMesh = _c[_b];
  5921. // Ensure nonUniformScaling is set if necessary.
  5922. babylonMesh.computeWorldMatrix(true);
  5923. var babylonMaterial = babylonData.babylonMaterial;
  5924. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  5925. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  5926. if (this._parent.useClipPlane) {
  5927. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  5928. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  5929. }
  5930. }
  5931. }
  5932. }
  5933. }
  5934. }
  5935. return Promise.all(promises).then(function () {
  5936. _this._parent._endPerformanceCounter("Compile materials");
  5937. });
  5938. };
  5939. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  5940. var _this = this;
  5941. this._parent._startPerformanceCounter("Compile shadow generators");
  5942. var promises = new Array();
  5943. var lights = this._babylonScene.lights;
  5944. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  5945. var light = lights_1[_i];
  5946. var generator = light.getShadowGenerator();
  5947. if (generator) {
  5948. promises.push(generator.forceCompilationAsync());
  5949. }
  5950. }
  5951. return Promise.all(promises).then(function () {
  5952. _this._parent._endPerformanceCounter("Compile shadow generators");
  5953. });
  5954. };
  5955. GLTFLoader.prototype._forEachExtensions = function (action) {
  5956. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  5957. var extension = _a[_i];
  5958. if (extension.enabled) {
  5959. action(extension);
  5960. }
  5961. }
  5962. };
  5963. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  5964. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  5965. var extension = _a[_i];
  5966. if (extension.enabled) {
  5967. var id = extension.name + "." + functionName;
  5968. var loaderProperty = property;
  5969. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  5970. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  5971. if (!activeLoaderExtensionFunctions[id]) {
  5972. activeLoaderExtensionFunctions[id] = true;
  5973. try {
  5974. var result = actionAsync(extension);
  5975. if (result) {
  5976. return result;
  5977. }
  5978. }
  5979. finally {
  5980. delete activeLoaderExtensionFunctions[id];
  5981. }
  5982. }
  5983. }
  5984. }
  5985. return null;
  5986. };
  5987. GLTFLoader.prototype._extensionsOnLoading = function () {
  5988. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  5989. };
  5990. GLTFLoader.prototype._extensionsOnReady = function () {
  5991. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  5992. };
  5993. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  5994. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  5995. };
  5996. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  5997. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  5998. };
  5999. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  6000. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  6001. };
  6002. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  6003. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  6004. };
  6005. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  6006. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  6007. };
  6008. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6009. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  6010. };
  6011. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  6012. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  6013. };
  6014. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6015. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  6016. };
  6017. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  6018. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  6019. };
  6020. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  6021. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  6022. };
  6023. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  6024. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  6025. };
  6026. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  6027. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  6028. };
  6029. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  6030. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  6031. };
  6032. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6033. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  6034. };
  6035. /**
  6036. * Helper method called by a loader extension to load an glTF extension.
  6037. * @param context The context when loading the asset
  6038. * @param property The glTF property to load the extension from
  6039. * @param extensionName The name of the extension to load
  6040. * @param actionAsync The action to run
  6041. * @returns The promise returned by actionAsync or null if the extension does not exist
  6042. */
  6043. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  6044. if (!property.extensions) {
  6045. return null;
  6046. }
  6047. var extensions = property.extensions;
  6048. var extension = extensions[extensionName];
  6049. if (!extension) {
  6050. return null;
  6051. }
  6052. return actionAsync(context + "/extensions/" + extensionName, extension);
  6053. };
  6054. /**
  6055. * Helper method called by a loader extension to load a glTF extra.
  6056. * @param context The context when loading the asset
  6057. * @param property The glTF property to load the extra from
  6058. * @param extensionName The name of the extension to load
  6059. * @param actionAsync The action to run
  6060. * @returns The promise returned by actionAsync or null if the extra does not exist
  6061. */
  6062. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  6063. if (!property.extras) {
  6064. return null;
  6065. }
  6066. var extras = property.extras;
  6067. var extra = extras[extensionName];
  6068. if (!extra) {
  6069. return null;
  6070. }
  6071. return actionAsync(context + "/extras/" + extensionName, extra);
  6072. };
  6073. /**
  6074. * Checks for presence of an extension.
  6075. * @param name The name of the extension to check
  6076. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  6077. */
  6078. GLTFLoader.prototype.isExtensionUsed = function (name) {
  6079. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  6080. };
  6081. /**
  6082. * Increments the indentation level and logs a message.
  6083. * @param message The message to log
  6084. */
  6085. GLTFLoader.prototype.logOpen = function (message) {
  6086. this._parent._logOpen(message);
  6087. };
  6088. /**
  6089. * Decrements the indentation level.
  6090. */
  6091. GLTFLoader.prototype.logClose = function () {
  6092. this._parent._logClose();
  6093. };
  6094. /**
  6095. * Logs a message
  6096. * @param message The message to log
  6097. */
  6098. GLTFLoader.prototype.log = function (message) {
  6099. this._parent._log(message);
  6100. };
  6101. /**
  6102. * Starts a performance counter.
  6103. * @param counterName The name of the performance counter
  6104. */
  6105. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  6106. this._parent._startPerformanceCounter(counterName);
  6107. };
  6108. /**
  6109. * Ends a performance counter.
  6110. * @param counterName The name of the performance counter
  6111. */
  6112. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  6113. this._parent._endPerformanceCounter(counterName);
  6114. };
  6115. GLTFLoader._DefaultSampler = { index: -1 };
  6116. GLTFLoader._RegisteredExtensions = {};
  6117. return GLTFLoader;
  6118. }());
  6119. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  6120. /***/ }),
  6121. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  6122. /*!******************************************!*\
  6123. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  6124. \******************************************/
  6125. /*! no static exports found */
  6126. /***/ (function(module, exports) {
  6127. /***/ }),
  6128. /***/ "./glTF/2.0/index.ts":
  6129. /*!***************************!*\
  6130. !*** ./glTF/2.0/index.ts ***!
  6131. \***************************/
  6132. /*! exports provided: ArrayItem, GLTFLoader, EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_mesh_quantization, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  6133. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6134. "use strict";
  6135. __webpack_require__.r(__webpack_exports__);
  6136. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  6137. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  6138. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  6139. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  6140. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  6141. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  6142. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  6143. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  6144. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  6145. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  6146. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  6147. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  6148. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  6149. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  6150. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  6151. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  6152. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  6153. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  6154. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  6155. /***/ }),
  6156. /***/ "./glTF/glTFFileLoader.ts":
  6157. /*!********************************!*\
  6158. !*** ./glTF/glTFFileLoader.ts ***!
  6159. \********************************/
  6160. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  6161. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6162. "use strict";
  6163. __webpack_require__.r(__webpack_exports__);
  6164. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  6165. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  6166. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  6167. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  6168. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  6169. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  6170. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  6171. /**
  6172. * Mode that determines the coordinate system to use.
  6173. */
  6174. var GLTFLoaderCoordinateSystemMode;
  6175. (function (GLTFLoaderCoordinateSystemMode) {
  6176. /**
  6177. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  6178. */
  6179. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  6180. /**
  6181. * Sets the useRightHandedSystem flag on the scene.
  6182. */
  6183. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  6184. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  6185. /**
  6186. * Mode that determines what animations will start.
  6187. */
  6188. var GLTFLoaderAnimationStartMode;
  6189. (function (GLTFLoaderAnimationStartMode) {
  6190. /**
  6191. * No animation will start.
  6192. */
  6193. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  6194. /**
  6195. * The first animation will start.
  6196. */
  6197. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  6198. /**
  6199. * All animations will start.
  6200. */
  6201. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  6202. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  6203. /**
  6204. * Loader state.
  6205. */
  6206. var GLTFLoaderState;
  6207. (function (GLTFLoaderState) {
  6208. /**
  6209. * The asset is loading.
  6210. */
  6211. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  6212. /**
  6213. * The asset is ready for rendering.
  6214. */
  6215. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  6216. /**
  6217. * The asset is completely loaded.
  6218. */
  6219. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  6220. })(GLTFLoaderState || (GLTFLoaderState = {}));
  6221. /**
  6222. * File loader for loading glTF files into a scene.
  6223. */
  6224. var GLTFFileLoader = /** @class */ (function () {
  6225. function GLTFFileLoader() {
  6226. // --------------
  6227. // Common options
  6228. // --------------
  6229. /**
  6230. * Raised when the asset has been parsed
  6231. */
  6232. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6233. // ----------
  6234. // V2 options
  6235. // ----------
  6236. /**
  6237. * The coordinate system mode. Defaults to AUTO.
  6238. */
  6239. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  6240. /**
  6241. * The animation start mode. Defaults to FIRST.
  6242. */
  6243. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  6244. /**
  6245. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  6246. */
  6247. this.compileMaterials = false;
  6248. /**
  6249. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  6250. */
  6251. this.useClipPlane = false;
  6252. /**
  6253. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  6254. */
  6255. this.compileShadowGenerators = false;
  6256. /**
  6257. * Defines if the Alpha blended materials are only applied as coverage.
  6258. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  6259. * If true, no extra effects are applied to transparent pixels.
  6260. */
  6261. this.transparencyAsCoverage = false;
  6262. /**
  6263. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  6264. * Enabling will disable offline support and glTF validator.
  6265. * Defaults to false.
  6266. */
  6267. this.useRangeRequests = false;
  6268. /**
  6269. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  6270. */
  6271. this.createInstances = true;
  6272. /**
  6273. * Function called before loading a url referenced by the asset.
  6274. */
  6275. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  6276. /**
  6277. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  6278. */
  6279. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6280. /**
  6281. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  6282. */
  6283. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6284. /**
  6285. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  6286. */
  6287. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6288. /**
  6289. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  6290. */
  6291. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6292. /**
  6293. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  6294. * For assets with LODs, raised when all of the LODs are complete.
  6295. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  6296. */
  6297. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6298. /**
  6299. * Observable raised when an error occurs.
  6300. */
  6301. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6302. /**
  6303. * Observable raised after the loader is disposed.
  6304. */
  6305. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6306. /**
  6307. * Observable raised after a loader extension is created.
  6308. * Set additional options for a loader extension in this event.
  6309. */
  6310. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6311. /**
  6312. * Defines if the loader should validate the asset.
  6313. */
  6314. this.validate = false;
  6315. /**
  6316. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  6317. */
  6318. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6319. this._loader = null;
  6320. /**
  6321. * Name of the loader ("gltf")
  6322. */
  6323. this.name = "gltf";
  6324. /** @hidden */
  6325. this.extensions = {
  6326. ".gltf": { isBinary: false },
  6327. ".glb": { isBinary: true }
  6328. };
  6329. this._logIndentLevel = 0;
  6330. this._loggingEnabled = false;
  6331. /** @hidden */
  6332. this._log = this._logDisabled;
  6333. this._capturePerformanceCounters = false;
  6334. /** @hidden */
  6335. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  6336. /** @hidden */
  6337. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  6338. }
  6339. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  6340. /**
  6341. * Raised when the asset has been parsed
  6342. */
  6343. set: function (callback) {
  6344. if (this._onParsedObserver) {
  6345. this.onParsedObservable.remove(this._onParsedObserver);
  6346. }
  6347. this._onParsedObserver = this.onParsedObservable.add(callback);
  6348. },
  6349. enumerable: true,
  6350. configurable: true
  6351. });
  6352. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  6353. /**
  6354. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  6355. */
  6356. set: function (callback) {
  6357. if (this._onMeshLoadedObserver) {
  6358. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  6359. }
  6360. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  6361. },
  6362. enumerable: true,
  6363. configurable: true
  6364. });
  6365. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  6366. /**
  6367. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  6368. */
  6369. set: function (callback) {
  6370. if (this._onTextureLoadedObserver) {
  6371. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  6372. }
  6373. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  6374. },
  6375. enumerable: true,
  6376. configurable: true
  6377. });
  6378. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  6379. /**
  6380. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  6381. */
  6382. set: function (callback) {
  6383. if (this._onMaterialLoadedObserver) {
  6384. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  6385. }
  6386. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  6387. },
  6388. enumerable: true,
  6389. configurable: true
  6390. });
  6391. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  6392. /**
  6393. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  6394. */
  6395. set: function (callback) {
  6396. if (this._onCameraLoadedObserver) {
  6397. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  6398. }
  6399. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  6400. },
  6401. enumerable: true,
  6402. configurable: true
  6403. });
  6404. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  6405. /**
  6406. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  6407. * For assets with LODs, raised when all of the LODs are complete.
  6408. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  6409. */
  6410. set: function (callback) {
  6411. if (this._onCompleteObserver) {
  6412. this.onCompleteObservable.remove(this._onCompleteObserver);
  6413. }
  6414. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  6415. },
  6416. enumerable: true,
  6417. configurable: true
  6418. });
  6419. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  6420. /**
  6421. * Callback raised when an error occurs.
  6422. */
  6423. set: function (callback) {
  6424. if (this._onErrorObserver) {
  6425. this.onErrorObservable.remove(this._onErrorObserver);
  6426. }
  6427. this._onErrorObserver = this.onErrorObservable.add(callback);
  6428. },
  6429. enumerable: true,
  6430. configurable: true
  6431. });
  6432. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  6433. /**
  6434. * Callback raised after the loader is disposed.
  6435. */
  6436. set: function (callback) {
  6437. if (this._onDisposeObserver) {
  6438. this.onDisposeObservable.remove(this._onDisposeObserver);
  6439. }
  6440. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  6441. },
  6442. enumerable: true,
  6443. configurable: true
  6444. });
  6445. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  6446. /**
  6447. * Callback raised after a loader extension is created.
  6448. */
  6449. set: function (callback) {
  6450. if (this._onExtensionLoadedObserver) {
  6451. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  6452. }
  6453. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  6454. },
  6455. enumerable: true,
  6456. configurable: true
  6457. });
  6458. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  6459. /**
  6460. * Defines if the loader logging is enabled.
  6461. */
  6462. get: function () {
  6463. return this._loggingEnabled;
  6464. },
  6465. set: function (value) {
  6466. if (this._loggingEnabled === value) {
  6467. return;
  6468. }
  6469. this._loggingEnabled = value;
  6470. if (this._loggingEnabled) {
  6471. this._log = this._logEnabled;
  6472. }
  6473. else {
  6474. this._log = this._logDisabled;
  6475. }
  6476. },
  6477. enumerable: true,
  6478. configurable: true
  6479. });
  6480. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  6481. /**
  6482. * Defines if the loader should capture performance counters.
  6483. */
  6484. get: function () {
  6485. return this._capturePerformanceCounters;
  6486. },
  6487. set: function (value) {
  6488. if (this._capturePerformanceCounters === value) {
  6489. return;
  6490. }
  6491. this._capturePerformanceCounters = value;
  6492. if (this._capturePerformanceCounters) {
  6493. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  6494. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  6495. }
  6496. else {
  6497. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  6498. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  6499. }
  6500. },
  6501. enumerable: true,
  6502. configurable: true
  6503. });
  6504. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  6505. /**
  6506. * Callback raised after a loader extension is created.
  6507. */
  6508. set: function (callback) {
  6509. if (this._onValidatedObserver) {
  6510. this.onValidatedObservable.remove(this._onValidatedObserver);
  6511. }
  6512. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  6513. },
  6514. enumerable: true,
  6515. configurable: true
  6516. });
  6517. /**
  6518. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  6519. */
  6520. GLTFFileLoader.prototype.dispose = function () {
  6521. if (this._loader) {
  6522. this._loader.dispose();
  6523. this._loader = null;
  6524. }
  6525. this._clear();
  6526. this.onDisposeObservable.notifyObservers(undefined);
  6527. this.onDisposeObservable.clear();
  6528. };
  6529. /** @hidden */
  6530. GLTFFileLoader.prototype._clear = function () {
  6531. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  6532. this.onMeshLoadedObservable.clear();
  6533. this.onTextureLoadedObservable.clear();
  6534. this.onMaterialLoadedObservable.clear();
  6535. this.onCameraLoadedObservable.clear();
  6536. this.onCompleteObservable.clear();
  6537. this.onExtensionLoadedObservable.clear();
  6538. };
  6539. /** @hidden */
  6540. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  6541. var _this = this;
  6542. if (useArrayBuffer) {
  6543. if (this.useRangeRequests) {
  6544. if (this.validate) {
  6545. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  6546. }
  6547. var fileRequests_1 = new Array();
  6548. var aggregatedFileRequest_1 = {
  6549. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  6550. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  6551. };
  6552. var dataBuffer_1 = {
  6553. readAsync: function (byteOffset, byteLength) {
  6554. return new Promise(function (resolve, reject) {
  6555. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  6556. dataBuffer_1.byteLength = Number(webRequest.getResponseHeader("Content-Range").split("/")[1]);
  6557. resolve(new Uint8Array(data));
  6558. }, onProgress, true, true, function (error) {
  6559. reject(error);
  6560. }, function (webRequest) {
  6561. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  6562. }));
  6563. });
  6564. },
  6565. byteLength: 0
  6566. };
  6567. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  6568. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  6569. onSuccess(loaderData);
  6570. }, onError);
  6571. return aggregatedFileRequest_1;
  6572. }
  6573. return scene._requestFile(url, function (data, request) {
  6574. var arrayBuffer = data;
  6575. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  6576. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  6577. byteLength: arrayBuffer.byteLength
  6578. })).then(function (loaderData) {
  6579. onSuccess(loaderData, request);
  6580. }, onError);
  6581. }, onProgress, true, true, onError);
  6582. }
  6583. return scene._requestFile(url, function (data, response) {
  6584. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  6585. onSuccess({ json: _this._parseJson(data) }, response);
  6586. }, onProgress, true, false, onError);
  6587. };
  6588. /** @hidden */
  6589. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  6590. var _this = this;
  6591. return scene._readFile(file, function (data) {
  6592. _this._validate(scene, data, "file:", file.name);
  6593. if (useArrayBuffer) {
  6594. var arrayBuffer_1 = data;
  6595. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  6596. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  6597. byteLength: arrayBuffer_1.byteLength
  6598. })).then(onSuccess, onError);
  6599. }
  6600. else {
  6601. onSuccess({ json: _this._parseJson(data) });
  6602. }
  6603. }, onProgress, useArrayBuffer, onError);
  6604. };
  6605. /** @hidden */
  6606. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  6607. var _this = this;
  6608. return Promise.resolve().then(function () {
  6609. _this.onParsedObservable.notifyObservers(data);
  6610. _this.onParsedObservable.clear();
  6611. _this._log("Loading " + (fileName || ""));
  6612. _this._loader = _this._getLoader(data);
  6613. return _this._loader.importMeshAsync(meshesNames, scene, data, rootUrl, onProgress, fileName);
  6614. });
  6615. };
  6616. /** @hidden */
  6617. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  6618. var _this = this;
  6619. return Promise.resolve().then(function () {
  6620. _this.onParsedObservable.notifyObservers(data);
  6621. _this.onParsedObservable.clear();
  6622. _this._log("Loading " + (fileName || ""));
  6623. _this._loader = _this._getLoader(data);
  6624. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  6625. });
  6626. };
  6627. /** @hidden */
  6628. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  6629. var _this = this;
  6630. return Promise.resolve().then(function () {
  6631. _this.onParsedObservable.notifyObservers(data);
  6632. _this.onParsedObservable.clear();
  6633. _this._log("Loading " + (fileName || ""));
  6634. _this._loader = _this._getLoader(data);
  6635. // Get materials/textures when loading to add to container
  6636. var materials = [];
  6637. _this.onMaterialLoadedObservable.add(function (material) {
  6638. materials.push(material);
  6639. });
  6640. var textures = [];
  6641. _this.onTextureLoadedObservable.add(function (texture) {
  6642. textures.push(texture);
  6643. });
  6644. return _this._loader.importMeshAsync(null, scene, data, rootUrl, onProgress, fileName).then(function (result) {
  6645. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  6646. Array.prototype.push.apply(container.meshes, result.meshes);
  6647. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  6648. Array.prototype.push.apply(container.skeletons, result.skeletons);
  6649. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  6650. Array.prototype.push.apply(container.materials, materials);
  6651. Array.prototype.push.apply(container.textures, textures);
  6652. container.removeAllFromScene();
  6653. return container;
  6654. });
  6655. });
  6656. };
  6657. /** @hidden */
  6658. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  6659. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  6660. };
  6661. /** @hidden */
  6662. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  6663. this._validate(scene, data);
  6664. return { json: this._parseJson(data) };
  6665. };
  6666. /** @hidden */
  6667. GLTFFileLoader.prototype.createPlugin = function () {
  6668. return new GLTFFileLoader();
  6669. };
  6670. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  6671. /**
  6672. * The loader state or null if the loader is not active.
  6673. */
  6674. get: function () {
  6675. return this._loader ? this._loader.state : null;
  6676. },
  6677. enumerable: true,
  6678. configurable: true
  6679. });
  6680. /**
  6681. * Returns a promise that resolves when the asset is completely loaded.
  6682. * @returns a promise that resolves when the asset is completely loaded.
  6683. */
  6684. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  6685. var _this = this;
  6686. return new Promise(function (resolve, reject) {
  6687. _this.onCompleteObservable.addOnce(function () {
  6688. resolve();
  6689. });
  6690. _this.onErrorObservable.addOnce(function (reason) {
  6691. reject(reason);
  6692. });
  6693. });
  6694. };
  6695. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  6696. var _this = this;
  6697. if (rootUrl === void 0) { rootUrl = ""; }
  6698. if (fileName === void 0) { fileName = ""; }
  6699. if (!this.validate) {
  6700. return;
  6701. }
  6702. this._startPerformanceCounter("Validate JSON");
  6703. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  6704. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  6705. }).then(function (result) {
  6706. _this._endPerformanceCounter("Validate JSON");
  6707. _this.onValidatedObservable.notifyObservers(result);
  6708. _this.onValidatedObservable.clear();
  6709. }, function (reason) {
  6710. _this._endPerformanceCounter("Validate JSON");
  6711. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  6712. _this.onValidatedObservable.clear();
  6713. });
  6714. };
  6715. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  6716. var asset = loaderData.json.asset || {};
  6717. this._log("Asset version: " + asset.version);
  6718. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  6719. asset.generator && this._log("Asset generator: " + asset.generator);
  6720. var version = GLTFFileLoader._parseVersion(asset.version);
  6721. if (!version) {
  6722. throw new Error("Invalid version: " + asset.version);
  6723. }
  6724. if (asset.minVersion !== undefined) {
  6725. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  6726. if (!minVersion) {
  6727. throw new Error("Invalid minimum version: " + asset.minVersion);
  6728. }
  6729. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  6730. throw new Error("Incompatible minimum version: " + asset.minVersion);
  6731. }
  6732. }
  6733. var createLoaders = {
  6734. 1: GLTFFileLoader._CreateGLTF1Loader,
  6735. 2: GLTFFileLoader._CreateGLTF2Loader
  6736. };
  6737. var createLoader = createLoaders[version.major];
  6738. if (!createLoader) {
  6739. throw new Error("Unsupported version: " + asset.version);
  6740. }
  6741. return createLoader(this);
  6742. };
  6743. GLTFFileLoader.prototype._parseJson = function (json) {
  6744. this._startPerformanceCounter("Parse JSON");
  6745. this._log("JSON length: " + json.length);
  6746. var parsed = JSON.parse(json);
  6747. this._endPerformanceCounter("Parse JSON");
  6748. return parsed;
  6749. };
  6750. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  6751. var _this = this;
  6752. this._startPerformanceCounter("Unpack Binary");
  6753. // Read magic + version + length + json length + json format
  6754. return dataReader.loadAsync(20).then(function () {
  6755. var Binary = {
  6756. Magic: 0x46546C67
  6757. };
  6758. var magic = dataReader.readUint32();
  6759. if (magic !== Binary.Magic) {
  6760. throw new Error("Unexpected magic: " + magic);
  6761. }
  6762. var version = dataReader.readUint32();
  6763. if (_this.loggingEnabled) {
  6764. _this._log("Binary version: " + version);
  6765. }
  6766. var length = dataReader.readUint32();
  6767. if (length !== dataReader.buffer.byteLength) {
  6768. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  6769. }
  6770. var unpacked;
  6771. switch (version) {
  6772. case 1: {
  6773. unpacked = _this._unpackBinaryV1Async(dataReader);
  6774. break;
  6775. }
  6776. case 2: {
  6777. unpacked = _this._unpackBinaryV2Async(dataReader);
  6778. break;
  6779. }
  6780. default: {
  6781. throw new Error("Unsupported version: " + version);
  6782. }
  6783. }
  6784. _this._endPerformanceCounter("Unpack Binary");
  6785. return unpacked;
  6786. });
  6787. };
  6788. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader) {
  6789. var ContentFormat = {
  6790. JSON: 0
  6791. };
  6792. var contentLength = dataReader.readUint32();
  6793. var contentFormat = dataReader.readUint32();
  6794. if (contentFormat !== ContentFormat.JSON) {
  6795. throw new Error("Unexpected content format: " + contentFormat);
  6796. }
  6797. var bodyLength = dataReader.buffer.byteLength - dataReader.byteOffset;
  6798. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  6799. if (bodyLength !== 0) {
  6800. var startByteOffset_1 = dataReader.byteOffset;
  6801. data.bin = {
  6802. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  6803. byteLength: bodyLength
  6804. };
  6805. }
  6806. return Promise.resolve(data);
  6807. };
  6808. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader) {
  6809. var _this = this;
  6810. var ChunkFormat = {
  6811. JSON: 0x4E4F534A,
  6812. BIN: 0x004E4942
  6813. };
  6814. // Read the JSON chunk header.
  6815. var chunkLength = dataReader.readUint32();
  6816. var chunkFormat = dataReader.readUint32();
  6817. if (chunkFormat !== ChunkFormat.JSON) {
  6818. throw new Error("First chunk format is not JSON");
  6819. }
  6820. // Bail if there are no other chunks.
  6821. if (dataReader.byteOffset + chunkLength === dataReader.buffer.byteLength) {
  6822. return dataReader.loadAsync(chunkLength).then(function () {
  6823. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  6824. });
  6825. }
  6826. // Read the JSON chunk and the length and type of the next chunk.
  6827. return dataReader.loadAsync(chunkLength + 8).then(function () {
  6828. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  6829. var readAsync = function () {
  6830. var chunkLength = dataReader.readUint32();
  6831. var chunkFormat = dataReader.readUint32();
  6832. switch (chunkFormat) {
  6833. case ChunkFormat.JSON: {
  6834. throw new Error("Unexpected JSON chunk");
  6835. }
  6836. case ChunkFormat.BIN: {
  6837. var startByteOffset_2 = dataReader.byteOffset;
  6838. data.bin = {
  6839. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  6840. byteLength: chunkLength
  6841. };
  6842. dataReader.skipBytes(chunkLength);
  6843. break;
  6844. }
  6845. default: {
  6846. // ignore unrecognized chunkFormat
  6847. dataReader.skipBytes(chunkLength);
  6848. break;
  6849. }
  6850. }
  6851. if (dataReader.byteOffset !== dataReader.buffer.byteLength) {
  6852. return dataReader.loadAsync(8).then(readAsync);
  6853. }
  6854. return Promise.resolve(data);
  6855. };
  6856. return readAsync();
  6857. });
  6858. };
  6859. GLTFFileLoader._parseVersion = function (version) {
  6860. if (version === "1.0" || version === "1.0.1") {
  6861. return {
  6862. major: 1,
  6863. minor: 0
  6864. };
  6865. }
  6866. var match = (version + "").match(/^(\d+)\.(\d+)/);
  6867. if (!match) {
  6868. return null;
  6869. }
  6870. return {
  6871. major: parseInt(match[1]),
  6872. minor: parseInt(match[2])
  6873. };
  6874. };
  6875. GLTFFileLoader._compareVersion = function (a, b) {
  6876. if (a.major > b.major) {
  6877. return 1;
  6878. }
  6879. if (a.major < b.major) {
  6880. return -1;
  6881. }
  6882. if (a.minor > b.minor) {
  6883. return 1;
  6884. }
  6885. if (a.minor < b.minor) {
  6886. return -1;
  6887. }
  6888. return 0;
  6889. };
  6890. /** @hidden */
  6891. GLTFFileLoader.prototype._logOpen = function (message) {
  6892. this._log(message);
  6893. this._logIndentLevel++;
  6894. };
  6895. /** @hidden */
  6896. GLTFFileLoader.prototype._logClose = function () {
  6897. --this._logIndentLevel;
  6898. };
  6899. GLTFFileLoader.prototype._logEnabled = function (message) {
  6900. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  6901. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  6902. };
  6903. GLTFFileLoader.prototype._logDisabled = function (message) {
  6904. };
  6905. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  6906. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  6907. };
  6908. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  6909. };
  6910. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  6911. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  6912. };
  6913. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  6914. };
  6915. // ----------
  6916. // V1 options
  6917. // ----------
  6918. /**
  6919. * 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.
  6920. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  6921. * Defaults to true.
  6922. * @hidden
  6923. */
  6924. GLTFFileLoader.IncrementalLoading = true;
  6925. /**
  6926. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  6927. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  6928. * @hidden
  6929. */
  6930. GLTFFileLoader.HomogeneousCoordinates = false;
  6931. GLTFFileLoader._logSpaces = " ";
  6932. return GLTFFileLoader;
  6933. }());
  6934. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  6935. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  6936. }
  6937. /***/ }),
  6938. /***/ "./glTF/glTFValidation.ts":
  6939. /*!********************************!*\
  6940. !*** ./glTF/glTFValidation.ts ***!
  6941. \********************************/
  6942. /*! exports provided: GLTFValidation */
  6943. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6944. "use strict";
  6945. __webpack_require__.r(__webpack_exports__);
  6946. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  6947. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  6948. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  6949. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  6950. var options = {
  6951. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  6952. };
  6953. if (fileName) {
  6954. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  6955. }
  6956. return (data instanceof ArrayBuffer)
  6957. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  6958. : GLTFValidator.validateString(data, options);
  6959. }
  6960. /**
  6961. * The worker function that gets converted to a blob url to pass into a worker.
  6962. */
  6963. function workerFunc() {
  6964. var pendingExternalResources = [];
  6965. onmessage = function (message) {
  6966. var data = message.data;
  6967. switch (data.id) {
  6968. case "init": {
  6969. importScripts(data.url);
  6970. break;
  6971. }
  6972. case "validate": {
  6973. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  6974. var index = pendingExternalResources.length;
  6975. pendingExternalResources.push({ resolve: resolve, reject: reject });
  6976. postMessage({ id: "getExternalResource", index: index, uri: uri });
  6977. }); }).then(function (value) {
  6978. postMessage({ id: "validate.resolve", value: value });
  6979. }, function (reason) {
  6980. postMessage({ id: "validate.reject", reason: reason });
  6981. });
  6982. break;
  6983. }
  6984. case "getExternalResource.resolve": {
  6985. pendingExternalResources[data.index].resolve(data.value);
  6986. break;
  6987. }
  6988. case "getExternalResource.reject": {
  6989. pendingExternalResources[data.index].reject(data.reason);
  6990. break;
  6991. }
  6992. }
  6993. };
  6994. }
  6995. /**
  6996. * glTF validation
  6997. */
  6998. var GLTFValidation = /** @class */ (function () {
  6999. function GLTFValidation() {
  7000. }
  7001. /**
  7002. * Validate a glTF asset using the glTF-Validator.
  7003. * @param data The JSON of a glTF or the array buffer of a binary glTF
  7004. * @param rootUrl The root url for the glTF
  7005. * @param fileName The file name for the glTF
  7006. * @param getExternalResource The callback to get external resources for the glTF validator
  7007. * @returns A promise that resolves with the glTF validation results once complete
  7008. */
  7009. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  7010. var _this = this;
  7011. if (typeof Worker === "function") {
  7012. return new Promise(function (resolve, reject) {
  7013. var workerContent = validateAsync + "(" + workerFunc + ")()";
  7014. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  7015. var worker = new Worker(workerBlobUrl);
  7016. var onError = function (error) {
  7017. worker.removeEventListener("error", onError);
  7018. worker.removeEventListener("message", onMessage);
  7019. reject(error);
  7020. };
  7021. var onMessage = function (message) {
  7022. var data = message.data;
  7023. switch (data.id) {
  7024. case "getExternalResource": {
  7025. getExternalResource(data.uri).then(function (value) {
  7026. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  7027. }, function (reason) {
  7028. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  7029. });
  7030. break;
  7031. }
  7032. case "validate.resolve": {
  7033. worker.removeEventListener("error", onError);
  7034. worker.removeEventListener("message", onMessage);
  7035. resolve(data.value);
  7036. break;
  7037. }
  7038. case "validate.reject": {
  7039. worker.removeEventListener("error", onError);
  7040. worker.removeEventListener("message", onMessage);
  7041. reject(data.reason);
  7042. }
  7043. }
  7044. };
  7045. worker.addEventListener("error", onError);
  7046. worker.addEventListener("message", onMessage);
  7047. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  7048. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  7049. });
  7050. }
  7051. else {
  7052. if (!this._LoadScriptPromise) {
  7053. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  7054. }
  7055. return this._LoadScriptPromise.then(function () {
  7056. return validateAsync(data, rootUrl, fileName, getExternalResource);
  7057. });
  7058. }
  7059. };
  7060. /**
  7061. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  7062. */
  7063. GLTFValidation.Configuration = {
  7064. url: "https://preview.babylonjs.com/gltf_validator.js"
  7065. };
  7066. return GLTFValidation;
  7067. }());
  7068. /***/ }),
  7069. /***/ "./legacy/legacy-glTF.ts":
  7070. /*!*******************************!*\
  7071. !*** ./legacy/legacy-glTF.ts ***!
  7072. \*******************************/
  7073. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  7074. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7075. "use strict";
  7076. __webpack_require__.r(__webpack_exports__);
  7077. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  7078. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  7079. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  7080. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  7081. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  7082. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  7083. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  7084. /**
  7085. * This is the entry point for the UMD module.
  7086. * The entry point for a future ESM package should be index.ts
  7087. */
  7088. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  7089. if (typeof globalObject !== "undefined") {
  7090. globalObject.BABYLON = globalObject.BABYLON || {};
  7091. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  7092. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  7093. }
  7094. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  7095. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  7096. }
  7097. }
  7098. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  7099. /***/ }),
  7100. /***/ "./legacy/legacy-glTF1.ts":
  7101. /*!********************************!*\
  7102. !*** ./legacy/legacy-glTF1.ts ***!
  7103. \********************************/
  7104. /*! exports provided: GLTF1 */
  7105. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7106. "use strict";
  7107. __webpack_require__.r(__webpack_exports__);
  7108. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/1.0 */ "./glTF/1.0/index.ts");
  7109. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  7110. /**
  7111. * This is the entry point for the UMD module.
  7112. * The entry point for a future ESM package should be index.ts
  7113. */
  7114. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  7115. if (typeof globalObject !== "undefined") {
  7116. globalObject.BABYLON = globalObject.BABYLON || {};
  7117. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  7118. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  7119. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  7120. }
  7121. }
  7122. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  7123. /***/ }),
  7124. /***/ "./legacy/legacy-glTF2.ts":
  7125. /*!********************************!*\
  7126. !*** ./legacy/legacy-glTF2.ts ***!
  7127. \********************************/
  7128. /*! exports provided: GLTF2 */
  7129. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7130. "use strict";
  7131. __webpack_require__.r(__webpack_exports__);
  7132. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  7133. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  7134. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  7135. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  7136. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  7137. /**
  7138. * This is the entry point for the UMD module.
  7139. * The entry point for a future ESM package should be index.ts
  7140. */
  7141. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  7142. if (typeof globalObject !== "undefined") {
  7143. globalObject.BABYLON = globalObject.BABYLON || {};
  7144. var BABYLON = globalObject.BABYLON;
  7145. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  7146. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  7147. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  7148. var keys = [];
  7149. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  7150. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  7151. keys.push(key);
  7152. }
  7153. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  7154. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  7155. keys.push(key);
  7156. }
  7157. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  7158. // Prevent Reassignment.
  7159. if (keys.indexOf(key) > -1) {
  7160. continue;
  7161. }
  7162. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  7163. }
  7164. }
  7165. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  7166. /***/ }),
  7167. /***/ "./legacy/legacy-glTFFileLoader.ts":
  7168. /*!*****************************************!*\
  7169. !*** ./legacy/legacy-glTFFileLoader.ts ***!
  7170. \*****************************************/
  7171. /*! exports provided: GLTF1, GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  7172. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7173. "use strict";
  7174. __webpack_require__.r(__webpack_exports__);
  7175. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  7176. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  7177. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  7178. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  7179. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  7180. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  7181. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  7182. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_1__["GLTF1"]; });
  7183. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  7184. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_2__["GLTF2"]; });
  7185. /***/ }),
  7186. /***/ "babylonjs/Misc/tools":
  7187. /*!****************************************************************************************************!*\
  7188. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  7189. \****************************************************************************************************/
  7190. /*! no static exports found */
  7191. /***/ (function(module, exports) {
  7192. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  7193. /***/ })
  7194. /******/ });
  7195. });
  7196. //# sourceMappingURL=babylon.glTFFileLoader.js.map