babylon.glTFFileLoader.js 346 KB

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