babylon.glTFFileLoader.js 436 KB

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