babylon.glTFFileLoader.js 339 KB

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