babylon.glTFFileLoader.js 414 KB

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