babylonjs.loaders.js 488 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** E:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./OBJ/index.ts":
  324. /*!**********************!*\
  325. !*** ./OBJ/index.ts ***!
  326. \**********************/
  327. /*! exports provided: MTLFileLoader, OBJFileLoader */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  333. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  335. /***/ }),
  336. /***/ "./OBJ/mtlFileLoader.ts":
  337. /*!******************************!*\
  338. !*** ./OBJ/mtlFileLoader.ts ***!
  339. \******************************/
  340. /*! exports provided: MTLFileLoader */
  341. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  342. "use strict";
  343. __webpack_require__.r(__webpack_exports__);
  344. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  345. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  346. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  347. /**
  348. * Class reading and parsing the MTL file bundled with the obj file.
  349. */
  350. var MTLFileLoader = /** @class */ (function () {
  351. function MTLFileLoader() {
  352. /**
  353. * All material loaded from the mtl will be set here
  354. */
  355. this.materials = [];
  356. }
  357. /**
  358. * This function will read the mtl file and create each material described inside
  359. * This function could be improve by adding :
  360. * -some component missing (Ni, Tf...)
  361. * -including the specific options available
  362. *
  363. * @param scene defines the scene the material will be created in
  364. * @param data defines the mtl data to parse
  365. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  366. * @param forAssetContainer defines if the material should be registered in the scene
  367. */
  368. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl, forAssetContainer) {
  369. if (data instanceof ArrayBuffer) {
  370. return;
  371. }
  372. //Split the lines from the file
  373. var lines = data.split('\n');
  374. //Space char
  375. var delimiter_pattern = /\s+/;
  376. //Array with RGB colors
  377. var color;
  378. //New material
  379. var material = null;
  380. //Look at each line
  381. for (var i = 0; i < lines.length; i++) {
  382. var line = lines[i].trim();
  383. // Blank line or comment
  384. if (line.length === 0 || line.charAt(0) === '#') {
  385. continue;
  386. }
  387. //Get the first parameter (keyword)
  388. var pos = line.indexOf(' ');
  389. var key = (pos >= 0) ? line.substring(0, pos) : line;
  390. key = key.toLowerCase();
  391. //Get the data following the key
  392. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  393. //This mtl keyword will create the new material
  394. if (key === "newmtl") {
  395. //Check if it is the first material.
  396. // Materials specifications are described after this keyword.
  397. if (material) {
  398. //Add the previous material in the material array.
  399. this.materials.push(material);
  400. }
  401. //Create a new material.
  402. // value is the name of the material read in the mtl file
  403. scene._blockEntityCollection = forAssetContainer;
  404. material = new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"](value, scene);
  405. scene._blockEntityCollection = false;
  406. }
  407. else if (key === "kd" && material) {
  408. // Diffuse color (color under white light) using RGB values
  409. //value = "r g b"
  410. color = value.split(delimiter_pattern, 3).map(parseFloat);
  411. //color = [r,g,b]
  412. //Set tghe color into the material
  413. material.diffuseColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  414. }
  415. else if (key === "ka" && material) {
  416. // Ambient color (color under shadow) using RGB values
  417. //value = "r g b"
  418. color = value.split(delimiter_pattern, 3).map(parseFloat);
  419. //color = [r,g,b]
  420. //Set tghe color into the material
  421. material.ambientColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  422. }
  423. else if (key === "ks" && material) {
  424. // Specular color (color when light is reflected from shiny surface) using RGB values
  425. //value = "r g b"
  426. color = value.split(delimiter_pattern, 3).map(parseFloat);
  427. //color = [r,g,b]
  428. //Set the color into the material
  429. material.specularColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  430. }
  431. else if (key === "ke" && material) {
  432. // Emissive color using RGB values
  433. color = value.split(delimiter_pattern, 3).map(parseFloat);
  434. material.emissiveColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  435. }
  436. else if (key === "ns" && material) {
  437. //value = "Integer"
  438. material.specularPower = parseFloat(value);
  439. }
  440. else if (key === "d" && material) {
  441. //d is dissolve for current material. It mean alpha for BABYLON
  442. material.alpha = parseFloat(value);
  443. //Texture
  444. //This part can be improved by adding the possible options of texture
  445. }
  446. else if (key === "map_ka" && material) {
  447. // ambient texture map with a loaded image
  448. //We must first get the folder of the image
  449. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  450. }
  451. else if (key === "map_kd" && material) {
  452. // Diffuse texture map with a loaded image
  453. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  454. }
  455. else if (key === "map_ks" && material) {
  456. // Specular texture map with a loaded image
  457. //We must first get the folder of the image
  458. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  459. }
  460. else if (key === "map_ns") {
  461. //Specular
  462. //Specular highlight component
  463. //We must first get the folder of the image
  464. //
  465. //Not supported by BABYLON
  466. //
  467. // continue;
  468. }
  469. else if (key === "map_bump" && material) {
  470. //The bump texture
  471. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  472. }
  473. else if (key === "map_d" && material) {
  474. // The dissolve of the material
  475. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  476. //Options for illumination
  477. }
  478. else if (key === "illum") {
  479. //Illumination
  480. if (value === "0") {
  481. //That mean Kd == Kd
  482. }
  483. else if (value === "1") {
  484. //Color on and Ambient on
  485. }
  486. else if (value === "2") {
  487. //Highlight on
  488. }
  489. else if (value === "3") {
  490. //Reflection on and Ray trace on
  491. }
  492. else if (value === "4") {
  493. //Transparency: Glass on, Reflection: Ray trace on
  494. }
  495. else if (value === "5") {
  496. //Reflection: Fresnel on and Ray trace on
  497. }
  498. else if (value === "6") {
  499. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  500. }
  501. else if (value === "7") {
  502. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  503. }
  504. else if (value === "8") {
  505. //Reflection on and Ray trace off
  506. }
  507. else if (value === "9") {
  508. //Transparency: Glass on, Reflection: Ray trace off
  509. }
  510. else if (value === "10") {
  511. //Casts shadows onto invisible surfaces
  512. }
  513. }
  514. else {
  515. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  516. }
  517. }
  518. //At the end of the file, add the last material
  519. if (material) {
  520. this.materials.push(material);
  521. }
  522. };
  523. /**
  524. * Gets the texture for the material.
  525. *
  526. * If the material is imported from input file,
  527. * We sanitize the url to ensure it takes the textre from aside the material.
  528. *
  529. * @param rootUrl The root url to load from
  530. * @param value The value stored in the mtl
  531. * @return The Texture
  532. */
  533. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  534. if (!value) {
  535. return null;
  536. }
  537. var url = rootUrl;
  538. // Load from input file.
  539. if (rootUrl === "file:") {
  540. var lastDelimiter = value.lastIndexOf("\\");
  541. if (lastDelimiter === -1) {
  542. lastDelimiter = value.lastIndexOf("/");
  543. }
  544. if (lastDelimiter > -1) {
  545. url += value.substr(lastDelimiter + 1);
  546. }
  547. else {
  548. url += value;
  549. }
  550. }
  551. // Not from input file.
  552. else {
  553. url += value;
  554. }
  555. return new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
  556. };
  557. /**
  558. * Invert Y-Axis of referenced textures on load
  559. */
  560. MTLFileLoader.INVERT_TEXTURE_Y = true;
  561. return MTLFileLoader;
  562. }());
  563. /***/ }),
  564. /***/ "./OBJ/objFileLoader.ts":
  565. /*!******************************!*\
  566. !*** ./OBJ/objFileLoader.ts ***!
  567. \******************************/
  568. /*! exports provided: OBJFileLoader */
  569. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  570. "use strict";
  571. __webpack_require__.r(__webpack_exports__);
  572. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  573. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  574. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  575. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  576. /**
  577. * OBJ file type loader.
  578. * This is a babylon scene loader plugin.
  579. */
  580. var OBJFileLoader = /** @class */ (function () {
  581. /**
  582. * Creates loader for .OBJ files
  583. *
  584. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  585. */
  586. function OBJFileLoader(meshLoadOptions) {
  587. /**
  588. * Defines the name of the plugin.
  589. */
  590. this.name = "obj";
  591. /**
  592. * Defines the extension the plugin is able to load.
  593. */
  594. this.extensions = ".obj";
  595. /** @hidden */
  596. this.obj = /^o/;
  597. /** @hidden */
  598. this.group = /^g/;
  599. /** @hidden */
  600. this.mtllib = /^mtllib /;
  601. /** @hidden */
  602. this.usemtl = /^usemtl /;
  603. /** @hidden */
  604. this.smooth = /^s /;
  605. /** @hidden */
  606. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+){3,7}/;
  607. // vn float float float
  608. /** @hidden */
  609. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  610. // vt float float
  611. /** @hidden */
  612. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  613. // f vertex vertex vertex ...
  614. /** @hidden */
  615. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  616. // f vertex/uvs vertex/uvs vertex/uvs ...
  617. /** @hidden */
  618. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  619. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  620. /** @hidden */
  621. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  622. // f vertex//normal vertex//normal vertex//normal ...
  623. /** @hidden */
  624. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  625. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  626. /** @hidden */
  627. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  628. this._forAssetContainer = false;
  629. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  630. }
  631. Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
  632. /**
  633. * Invert Y-Axis of referenced textures on load
  634. */
  635. get: function () {
  636. return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y;
  637. },
  638. set: function (value) {
  639. _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y = value;
  640. },
  641. enumerable: true,
  642. configurable: true
  643. });
  644. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  645. get: function () {
  646. return {
  647. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  648. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  649. InvertY: OBJFileLoader.INVERT_Y,
  650. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  651. UVScaling: OBJFileLoader.UV_SCALING,
  652. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  653. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  654. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  655. };
  656. },
  657. enumerable: true,
  658. configurable: true
  659. });
  660. /**
  661. * Calls synchronously the MTL file attached to this obj.
  662. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  663. * Without this function materials are not displayed in the first frame (but displayed after).
  664. * In consequence it is impossible to get material information in your HTML file
  665. *
  666. * @param url The URL of the MTL file
  667. * @param rootUrl
  668. * @param onSuccess Callback function to be called when the MTL file is loaded
  669. * @private
  670. */
  671. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  672. //The complete path to the mtl file
  673. var pathOfFile = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  674. // Loads through the babylon tools to allow fileInput search.
  675. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  676. onFailure(pathOfFile, exception);
  677. });
  678. };
  679. /**
  680. * Instantiates a OBJ file loader plugin.
  681. * @returns the created plugin
  682. */
  683. OBJFileLoader.prototype.createPlugin = function () {
  684. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  685. };
  686. /**
  687. * If the data string can be loaded directly.
  688. *
  689. * @param data string containing the file data
  690. * @returns if the data can be loaded directly
  691. */
  692. OBJFileLoader.prototype.canDirectLoad = function (data) {
  693. return false;
  694. };
  695. /**
  696. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  697. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  698. * @param scene the scene the meshes should be added to
  699. * @param data the OBJ data to load
  700. * @param rootUrl root url to load from
  701. * @param onProgress event that fires when loading progress has occured
  702. * @param fileName Defines the name of the file to load
  703. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  704. */
  705. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  706. //get the meshes from OBJ file
  707. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  708. return {
  709. meshes: meshes,
  710. particleSystems: [],
  711. skeletons: [],
  712. animationGroups: []
  713. };
  714. });
  715. };
  716. /**
  717. * Imports all objects from the loaded OBJ data and adds them to the scene
  718. * @param scene the scene the objects should be added to
  719. * @param data the OBJ data to load
  720. * @param rootUrl root url to load from
  721. * @param onProgress event that fires when loading progress has occured
  722. * @param fileName Defines the name of the file to load
  723. * @returns a promise which completes when objects have been loaded to the scene
  724. */
  725. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  726. //Get the 3D model
  727. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  728. // return void
  729. });
  730. };
  731. /**
  732. * Load into an asset container.
  733. * @param scene The scene to load into
  734. * @param data The data to import
  735. * @param rootUrl The root url for scene and resources
  736. * @param onProgress The callback when the load progresses
  737. * @param fileName Defines the name of the file to load
  738. * @returns The loaded asset container
  739. */
  740. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  741. var _this = this;
  742. this._forAssetContainer = true;
  743. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  744. var container = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  745. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  746. result.meshes.forEach(function (mesh) {
  747. var material = mesh.material;
  748. if (material) {
  749. // Materials
  750. if (container.materials.indexOf(material) == -1) {
  751. container.materials.push(material);
  752. // Textures
  753. var textures = material.getActiveTextures();
  754. textures.forEach(function (t) {
  755. if (container.textures.indexOf(t) == -1) {
  756. container.textures.push(t);
  757. }
  758. });
  759. }
  760. }
  761. });
  762. _this._forAssetContainer = false;
  763. return container;
  764. }).catch(function (ex) {
  765. _this._forAssetContainer = false;
  766. throw ex;
  767. });
  768. };
  769. /**
  770. * Read the OBJ file and create an Array of meshes.
  771. * Each mesh contains all information given by the OBJ and the MTL file.
  772. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  773. *
  774. * @param meshesNames
  775. * @param scene Scene The scene where are displayed the data
  776. * @param data String The content of the obj file
  777. * @param rootUrl String The path to the folder
  778. * @returns Array<AbstractMesh>
  779. * @private
  780. */
  781. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  782. var _this = this;
  783. var positions = []; //values for the positions of vertices
  784. var normals = []; //Values for the normals
  785. var uvs = []; //Values for the textures
  786. var colors = [];
  787. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  788. var handledMesh; //The current mesh of meshes array
  789. var indicesForBabylon = []; //The list of indices for VertexData
  790. var wrappedPositionForBabylon = []; //The list of position in vectors
  791. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  792. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  793. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  794. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  795. var curPositionInIndices = 0;
  796. var hasMeshes = false; //Meshes are defined in the file
  797. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  798. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  799. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  800. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  801. var triangles = []; //Indices from new triangles coming from polygons
  802. var materialNameFromObj = ""; //The name of the current material
  803. var fileToLoad = ""; //The name of the mtlFile to load
  804. var materialsFromMTLFile = new _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]();
  805. var objMeshName = ""; //The name of the current obj mesh
  806. var increment = 1; //Id for meshes created by the multimaterial
  807. var isFirstMaterial = true;
  808. var grayColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  809. /**
  810. * Search for obj in the given array.
  811. * This function is called to check if a couple of data already exists in an array.
  812. *
  813. * If found, returns the index of the founded tuple index. Returns -1 if not found
  814. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  815. * @param obj Array<number>
  816. * @returns {boolean}
  817. */
  818. var isInArray = function (arr, obj) {
  819. if (!arr[obj[0]]) {
  820. arr[obj[0]] = { normals: [], idx: [] };
  821. }
  822. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  823. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  824. };
  825. var isInArrayUV = function (arr, obj) {
  826. if (!arr[obj[0]]) {
  827. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  828. }
  829. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  830. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  831. return arr[obj[0]].idx[idx];
  832. }
  833. return -1;
  834. };
  835. /**
  836. * This function set the data for each triangle.
  837. * Data are position, normals and uvs
  838. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  839. * If the tuple already exist, add only their indice
  840. *
  841. * @param indicePositionFromObj Integer The index in positions array
  842. * @param indiceUvsFromObj Integer The index in uvs array
  843. * @param indiceNormalFromObj Integer The index in normals array
  844. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  845. * @param textureVectorFromOBJ Vector3 The value of uvs
  846. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  847. */
  848. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  849. //Check if this tuple already exists in the list of tuples
  850. var _index;
  851. if (_this._meshLoadOptions.OptimizeWithUV) {
  852. _index = isInArrayUV(tuplePosNorm, [
  853. indicePositionFromObj,
  854. indiceNormalFromObj,
  855. indiceUvsFromObj
  856. ]);
  857. }
  858. else {
  859. _index = isInArray(tuplePosNorm, [
  860. indicePositionFromObj,
  861. indiceNormalFromObj
  862. ]);
  863. }
  864. //If it not exists
  865. if (_index === -1) {
  866. //Add an new indice.
  867. //The array of indices is only an array with his length equal to the number of triangles - 1.
  868. //We add vertices data in this order
  869. indicesForBabylon.push(wrappedPositionForBabylon.length);
  870. //Push the position of vertice for Babylon
  871. //Each element is a Vector3(x,y,z)
  872. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  873. //Push the uvs for Babylon
  874. //Each element is a Vector3(u,v)
  875. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  876. //Push the normals for Babylon
  877. //Each element is a Vector3(x,y,z)
  878. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  879. if (positionColorsFromOBJ !== undefined) {
  880. //Push the colors for Babylon
  881. //Each element is a BABYLON.Color4(r,g,b,a)
  882. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  883. }
  884. //Add the tuple in the comparison list
  885. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  886. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  887. if (_this._meshLoadOptions.OptimizeWithUV) {
  888. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  889. }
  890. }
  891. else {
  892. //The tuple already exists
  893. //Add the index of the already existing tuple
  894. //At this index we can get the value of position, normal, color and uvs of vertex
  895. indicesForBabylon.push(_index);
  896. }
  897. };
  898. /**
  899. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  900. */
  901. var unwrapData = function () {
  902. //Every array has the same length
  903. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  904. //Push the x, y, z values of each element in the unwrapped array
  905. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  906. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  907. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  908. }
  909. if (_this._meshLoadOptions.ImportVertexColors === true) {
  910. //Push the r, g, b, a values of each element in the unwrapped array
  911. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  912. }
  913. // Reset arrays for the next new meshes
  914. wrappedPositionForBabylon = [];
  915. wrappedNormalsForBabylon = [];
  916. wrappedUvsForBabylon = [];
  917. wrappedColorsForBabylon = [];
  918. tuplePosNorm = [];
  919. curPositionInIndices = 0;
  920. };
  921. /**
  922. * Create triangles from polygons
  923. * It is important to notice that a triangle is a polygon
  924. * We get 5 patterns of face defined in OBJ File :
  925. * facePattern1 = ["1","2","3","4","5","6"]
  926. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  927. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  928. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  929. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  930. * Each pattern is divided by the same method
  931. * @param face Array[String] The indices of elements
  932. * @param v Integer The variable to increment
  933. */
  934. var getTriangles = function (faces, v) {
  935. //Work for each element of the array
  936. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  937. //Add on the triangle variable the indexes to obtain triangles
  938. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  939. }
  940. //Result obtained after 2 iterations:
  941. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  942. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  943. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  944. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  945. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  946. };
  947. /**
  948. * Create triangles and push the data for each polygon for the pattern 1
  949. * In this pattern we get vertice positions
  950. * @param face
  951. * @param v
  952. */
  953. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  954. //Get the indices of triangles for each polygon
  955. getTriangles(face, v);
  956. //For each element in the triangles array.
  957. //This var could contains 1 to an infinity of triangles
  958. for (var k = 0; k < triangles.length; k++) {
  959. // Set position indice
  960. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  961. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  962. positions[indicePositionFromObj], //Get the vectors data
  963. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  964. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  965. }
  966. //Reset variable for the next line
  967. triangles = [];
  968. };
  969. /**
  970. * Create triangles and push the data for each polygon for the pattern 2
  971. * In this pattern we get vertice positions and uvsu
  972. * @param face
  973. * @param v
  974. */
  975. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  976. //Get the indices of triangles for each polygon
  977. getTriangles(face, v);
  978. for (var k = 0; k < triangles.length; k++) {
  979. //triangle[k] = "1/1"
  980. //Split the data for getting position and uv
  981. var point = triangles[k].split("/"); // ["1", "1"]
  982. //Set position indice
  983. var indicePositionFromObj = parseInt(point[0]) - 1;
  984. //Set uv indice
  985. var indiceUvsFromObj = parseInt(point[1]) - 1;
  986. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  987. positions[indicePositionFromObj], //Get the values for each element
  988. uvs[indiceUvsFromObj], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  989. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  990. }
  991. //Reset variable for the next line
  992. triangles = [];
  993. };
  994. /**
  995. * Create triangles and push the data for each polygon for the pattern 3
  996. * In this pattern we get vertice positions, uvs and normals
  997. * @param face
  998. * @param v
  999. */
  1000. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  1001. //Get the indices of triangles for each polygon
  1002. getTriangles(face, v);
  1003. for (var k = 0; k < triangles.length; k++) {
  1004. //triangle[k] = "1/1/1"
  1005. //Split the data for getting position, uv, and normals
  1006. var point = triangles[k].split("/"); // ["1", "1", "1"]
  1007. // Set position indice
  1008. var indicePositionFromObj = parseInt(point[0]) - 1;
  1009. // Set uv indice
  1010. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1011. // Set normal indice
  1012. var indiceNormalFromObj = parseInt(point[2]) - 1;
  1013. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  1014. );
  1015. }
  1016. //Reset variable for the next line
  1017. triangles = [];
  1018. };
  1019. /**
  1020. * Create triangles and push the data for each polygon for the pattern 4
  1021. * In this pattern we get vertice positions and normals
  1022. * @param face
  1023. * @param v
  1024. */
  1025. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  1026. getTriangles(face, v);
  1027. for (var k = 0; k < triangles.length; k++) {
  1028. //triangle[k] = "1//1"
  1029. //Split the data for getting position and normals
  1030. var point = triangles[k].split("//"); // ["1", "1"]
  1031. // We check indices, and normals
  1032. var indicePositionFromObj = parseInt(point[0]) - 1;
  1033. var indiceNormalFromObj = parseInt(point[1]) - 1;
  1034. setData(indicePositionFromObj, 1, //Default value for uv
  1035. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  1036. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1037. }
  1038. //Reset variable for the next line
  1039. triangles = [];
  1040. };
  1041. /**
  1042. * Create triangles and push the data for each polygon for the pattern 3
  1043. * In this pattern we get vertice positions, uvs and normals
  1044. * @param face
  1045. * @param v
  1046. */
  1047. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1048. //Get the indices of triangles for each polygon
  1049. getTriangles(face, v);
  1050. for (var k = 0; k < triangles.length; k++) {
  1051. //triangle[k] = "-1/-1/-1"
  1052. //Split the data for getting position, uv, and normals
  1053. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1054. // Set position indice
  1055. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1056. // Set uv indice
  1057. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1058. // Set normal indice
  1059. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1060. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1061. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1062. }
  1063. //Reset variable for the next line
  1064. triangles = [];
  1065. };
  1066. var addPreviousObjMesh = function () {
  1067. //Check if it is not the first mesh. Otherwise we don't have data.
  1068. if (meshesFromObj.length > 0) {
  1069. //Get the previous mesh for applying the data about the faces
  1070. //=> in obj file, faces definition append after the name of the mesh
  1071. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1072. //Set the data into Array for the mesh
  1073. unwrapData();
  1074. // Reverse tab. Otherwise face are displayed in the wrong sens
  1075. indicesForBabylon.reverse();
  1076. //Set the information for the mesh
  1077. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1078. handledMesh.indices = indicesForBabylon.slice();
  1079. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1080. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1081. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1082. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1083. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1084. }
  1085. //Reset the array for the next mesh
  1086. indicesForBabylon = [];
  1087. unwrappedPositionsForBabylon = [];
  1088. unwrappedColorsForBabylon = [];
  1089. unwrappedNormalsForBabylon = [];
  1090. unwrappedUVForBabylon = [];
  1091. }
  1092. };
  1093. //Main function
  1094. //Split the file into lines
  1095. var lines = data.split('\n');
  1096. //Look at each line
  1097. for (var i = 0; i < lines.length; i++) {
  1098. var line = lines[i].trim().replace(/\s\s/g, " ");
  1099. var result;
  1100. //Comment or newLine
  1101. if (line.length === 0 || line.charAt(0) === '#') {
  1102. continue;
  1103. //Get information about one position possible for the vertices
  1104. }
  1105. else if (this.vertexPattern.test(line)) {
  1106. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1107. // Value of result with line: "v 1.0 2.0 3.0"
  1108. // ["v", "1.0", "2.0", "3.0"]
  1109. // Create a Vector3 with the position x, y, z
  1110. positions.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1111. if (this._meshLoadOptions.ImportVertexColors === true) {
  1112. if (result.length >= 7) {
  1113. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1114. colors.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
  1115. }
  1116. else {
  1117. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1118. colors.push(grayColor);
  1119. }
  1120. }
  1121. }
  1122. else if ((result = this.normalPattern.exec(line)) !== null) {
  1123. //Create a Vector3 with the normals x, y, z
  1124. //Value of result
  1125. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1126. //Add the Vector in the list of normals
  1127. normals.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1128. }
  1129. else if ((result = this.uvPattern.exec(line)) !== null) {
  1130. //Create a Vector2 with the normals u, v
  1131. //Value of result
  1132. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1133. //Add the Vector in the list of uvs
  1134. uvs.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
  1135. //Identify patterns of faces
  1136. //Face could be defined in different type of pattern
  1137. }
  1138. else if ((result = this.facePattern3.exec(line)) !== null) {
  1139. //Value of result:
  1140. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1141. //Set the data for this face
  1142. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1143. 1);
  1144. }
  1145. else if ((result = this.facePattern4.exec(line)) !== null) {
  1146. //Value of result:
  1147. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1148. //Set the data for this face
  1149. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1150. 1);
  1151. }
  1152. else if ((result = this.facePattern5.exec(line)) !== null) {
  1153. //Value of result:
  1154. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1155. //Set the data for this face
  1156. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1157. 1);
  1158. }
  1159. else if ((result = this.facePattern2.exec(line)) !== null) {
  1160. //Value of result:
  1161. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1162. //Set the data for this face
  1163. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1164. 1);
  1165. }
  1166. else if ((result = this.facePattern1.exec(line)) !== null) {
  1167. //Value of result
  1168. //["f 1 2 3", "1 2 3"...]
  1169. //Set the data for this face
  1170. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1171. 1);
  1172. //Define a mesh or an object
  1173. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1174. }
  1175. else if (this.group.test(line) || this.obj.test(line)) {
  1176. //Create a new mesh corresponding to the name of the group.
  1177. //Definition of the mesh
  1178. var objMesh = {
  1179. name: line.substring(2).trim(),
  1180. indices: undefined,
  1181. positions: undefined,
  1182. normals: undefined,
  1183. uvs: undefined,
  1184. colors: undefined,
  1185. materialName: ""
  1186. };
  1187. addPreviousObjMesh();
  1188. //Push the last mesh created with only the name
  1189. meshesFromObj.push(objMesh);
  1190. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1191. hasMeshes = true;
  1192. isFirstMaterial = true;
  1193. increment = 1;
  1194. //Keyword for applying a material
  1195. }
  1196. else if (this.usemtl.test(line)) {
  1197. //Get the name of the material
  1198. materialNameFromObj = line.substring(7).trim();
  1199. //If this new material is in the same mesh
  1200. if (!isFirstMaterial || !hasMeshes) {
  1201. //Set the data for the previous mesh
  1202. addPreviousObjMesh();
  1203. //Create a new mesh
  1204. var objMesh =
  1205. //Set the name of the current obj mesh
  1206. {
  1207. name: (objMeshName || "mesh") + "_mm" + increment.toString(),
  1208. indices: undefined,
  1209. positions: undefined,
  1210. normals: undefined,
  1211. uvs: undefined,
  1212. colors: undefined,
  1213. materialName: materialNameFromObj
  1214. };
  1215. increment++;
  1216. //If meshes are already defined
  1217. meshesFromObj.push(objMesh);
  1218. hasMeshes = true;
  1219. }
  1220. //Set the material name if the previous line define a mesh
  1221. if (hasMeshes && isFirstMaterial) {
  1222. //Set the material name to the previous mesh (1 material per mesh)
  1223. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1224. isFirstMaterial = false;
  1225. }
  1226. //Keyword for loading the mtl file
  1227. }
  1228. else if (this.mtllib.test(line)) {
  1229. //Get the name of mtl file
  1230. fileToLoad = line.substring(7).trim();
  1231. //Apply smoothing
  1232. }
  1233. else if (this.smooth.test(line)) {
  1234. // smooth shading => apply smoothing
  1235. //Today I don't know it work with babylon and with obj.
  1236. //With the obj file an integer is set
  1237. }
  1238. else {
  1239. //If there is another possibility
  1240. console.log("Unhandled expression at line : " + line);
  1241. }
  1242. }
  1243. //At the end of the file, add the last mesh into the meshesFromObj array
  1244. if (hasMeshes) {
  1245. //Set the data for the last mesh
  1246. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1247. //Reverse indices for displaying faces in the good sense
  1248. indicesForBabylon.reverse();
  1249. //Get the good array
  1250. unwrapData();
  1251. //Set array
  1252. handledMesh.indices = indicesForBabylon;
  1253. handledMesh.positions = unwrappedPositionsForBabylon;
  1254. handledMesh.normals = unwrappedNormalsForBabylon;
  1255. handledMesh.uvs = unwrappedUVForBabylon;
  1256. if (this._meshLoadOptions.ImportVertexColors === true) {
  1257. handledMesh.colors = unwrappedColorsForBabylon;
  1258. }
  1259. }
  1260. //If any o or g keyword found, create a mesh with a random id
  1261. if (!hasMeshes) {
  1262. // reverse tab of indices
  1263. indicesForBabylon.reverse();
  1264. //Get positions normals uvs
  1265. unwrapData();
  1266. //Set data for one mesh
  1267. meshesFromObj.push({
  1268. name: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1269. indices: indicesForBabylon,
  1270. positions: unwrappedPositionsForBabylon,
  1271. colors: unwrappedColorsForBabylon,
  1272. normals: unwrappedNormalsForBabylon,
  1273. uvs: unwrappedUVForBabylon,
  1274. materialName: materialNameFromObj
  1275. });
  1276. }
  1277. //Create a Mesh list
  1278. var babylonMeshesArray = []; //The mesh for babylon
  1279. var materialToUse = new Array();
  1280. //Set data for each mesh
  1281. for (var j = 0; j < meshesFromObj.length; j++) {
  1282. //check meshesNames (stlFileLoader)
  1283. if (meshesNames && meshesFromObj[j].name) {
  1284. if (meshesNames instanceof Array) {
  1285. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1286. continue;
  1287. }
  1288. }
  1289. else {
  1290. if (meshesFromObj[j].name !== meshesNames) {
  1291. continue;
  1292. }
  1293. }
  1294. }
  1295. //Get the current mesh
  1296. //Set the data with VertexBuffer for each mesh
  1297. handledMesh = meshesFromObj[j];
  1298. //Create a Mesh with the name of the obj mesh
  1299. scene._blockEntityCollection = this._forAssetContainer;
  1300. var babylonMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1301. scene._blockEntityCollection = false;
  1302. //Push the name of the material to an array
  1303. //This is indispensable for the importMesh function
  1304. materialToUse.push(meshesFromObj[j].materialName);
  1305. var vertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1306. //Set the data for the babylonMesh
  1307. vertexData.uvs = handledMesh.uvs;
  1308. vertexData.indices = handledMesh.indices;
  1309. vertexData.positions = handledMesh.positions;
  1310. if (this._meshLoadOptions.ComputeNormals === true) {
  1311. var normals_1 = new Array();
  1312. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1313. vertexData.normals = normals_1;
  1314. }
  1315. else {
  1316. vertexData.normals = handledMesh.normals;
  1317. }
  1318. if (this._meshLoadOptions.ImportVertexColors === true) {
  1319. vertexData.colors = handledMesh.colors;
  1320. }
  1321. //Set the data from the VertexBuffer to the current Mesh
  1322. vertexData.applyToMesh(babylonMesh);
  1323. if (this._meshLoadOptions.InvertY) {
  1324. babylonMesh.scaling.y *= -1;
  1325. }
  1326. //Push the mesh into an array
  1327. babylonMeshesArray.push(babylonMesh);
  1328. }
  1329. var mtlPromises = [];
  1330. //load the materials
  1331. //Check if we have a file to load
  1332. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1333. //Load the file synchronously
  1334. mtlPromises.push(new Promise(function (resolve, reject) {
  1335. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1336. try {
  1337. //Create materials thanks MTLLoader function
  1338. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._forAssetContainer);
  1339. //Look at each material loaded in the mtl file
  1340. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1341. //Three variables to get all meshes with the same material
  1342. var startIndex = 0;
  1343. var _indices = [];
  1344. var _index;
  1345. //The material from MTL file is used in the meshes loaded
  1346. //Push the indice in an array
  1347. //Check if the material is not used for another mesh
  1348. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1349. _indices.push(_index);
  1350. startIndex = _index + 1;
  1351. }
  1352. //If the material is not used dispose it
  1353. if (_index === -1 && _indices.length === 0) {
  1354. //If the material is not needed, remove it
  1355. materialsFromMTLFile.materials[n].dispose();
  1356. }
  1357. else {
  1358. for (var o = 0; o < _indices.length; o++) {
  1359. //Apply the material to the Mesh for each mesh with the material
  1360. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1361. }
  1362. }
  1363. }
  1364. resolve();
  1365. }
  1366. catch (e) {
  1367. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1368. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1369. resolve();
  1370. }
  1371. else {
  1372. reject(e);
  1373. }
  1374. }
  1375. }, function (pathOfFile, exception) {
  1376. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1377. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1378. resolve();
  1379. }
  1380. else {
  1381. reject(exception);
  1382. }
  1383. });
  1384. }));
  1385. }
  1386. //Return an array with all Mesh
  1387. return Promise.all(mtlPromises).then(function () {
  1388. return babylonMeshesArray;
  1389. });
  1390. };
  1391. /**
  1392. * Defines if UVs are optimized by default during load.
  1393. */
  1394. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1395. /**
  1396. * Invert model on y-axis (does a model scaling inversion)
  1397. */
  1398. OBJFileLoader.INVERT_Y = false;
  1399. /**
  1400. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1401. */
  1402. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1403. /**
  1404. * Compute the normals for the model, even if normals are present in the file.
  1405. */
  1406. OBJFileLoader.COMPUTE_NORMALS = false;
  1407. /**
  1408. * Defines custom scaling of UV coordinates of loaded meshes.
  1409. */
  1410. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1411. /**
  1412. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1413. */
  1414. OBJFileLoader.SKIP_MATERIALS = false;
  1415. /**
  1416. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1417. *
  1418. * Defaults to true for backwards compatibility.
  1419. */
  1420. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1421. return OBJFileLoader;
  1422. }());
  1423. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1424. //Add this loader into the register plugin
  1425. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1426. }
  1427. /***/ }),
  1428. /***/ "./STL/index.ts":
  1429. /*!**********************!*\
  1430. !*** ./STL/index.ts ***!
  1431. \**********************/
  1432. /*! exports provided: STLFileLoader */
  1433. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1434. "use strict";
  1435. __webpack_require__.r(__webpack_exports__);
  1436. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1437. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1438. /***/ }),
  1439. /***/ "./STL/stlFileLoader.ts":
  1440. /*!******************************!*\
  1441. !*** ./STL/stlFileLoader.ts ***!
  1442. \******************************/
  1443. /*! exports provided: STLFileLoader */
  1444. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1445. "use strict";
  1446. __webpack_require__.r(__webpack_exports__);
  1447. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1448. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  1449. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1450. /**
  1451. * STL file type loader.
  1452. * This is a babylon scene loader plugin.
  1453. */
  1454. var STLFileLoader = /** @class */ (function () {
  1455. function STLFileLoader() {
  1456. /** @hidden */
  1457. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  1458. /** @hidden */
  1459. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1460. /** @hidden */
  1461. this.normalPattern = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1462. /** @hidden */
  1463. this.vertexPattern = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1464. /**
  1465. * Defines the name of the plugin.
  1466. */
  1467. this.name = "stl";
  1468. /**
  1469. * Defines the extensions the stl loader is able to load.
  1470. * force data to come in as an ArrayBuffer
  1471. * we'll convert to string if it looks like it's an ASCII .stl
  1472. */
  1473. this.extensions = {
  1474. ".stl": { isBinary: true },
  1475. };
  1476. }
  1477. /**
  1478. * Import meshes into a scene.
  1479. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1480. * @param scene The scene to import into
  1481. * @param data The data to import
  1482. * @param rootUrl The root url for scene and resources
  1483. * @param meshes The meshes array to import into
  1484. * @param particleSystems The particle systems array to import into
  1485. * @param skeletons The skeletons array to import into
  1486. * @param onError The callback when import fails
  1487. * @returns True if successful or false otherwise
  1488. */
  1489. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1490. var matches;
  1491. if (typeof data !== "string") {
  1492. if (this._isBinary(data)) {
  1493. // binary .stl
  1494. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1495. this._parseBinary(babylonMesh, data);
  1496. if (meshes) {
  1497. meshes.push(babylonMesh);
  1498. }
  1499. return true;
  1500. }
  1501. // ASCII .stl
  1502. // convert to string
  1503. var array_buffer = new Uint8Array(data);
  1504. var str = '';
  1505. for (var i = 0; i < data.byteLength; i++) {
  1506. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1507. }
  1508. data = str;
  1509. }
  1510. //if arrived here, data is a string, containing the STLA data.
  1511. while (matches = this.solidPattern.exec(data)) {
  1512. var meshName = matches[1];
  1513. var meshNameFromEnd = matches[3];
  1514. if (meshName != meshNameFromEnd) {
  1515. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1516. return false;
  1517. }
  1518. // check meshesNames
  1519. if (meshesNames && meshName) {
  1520. if (meshesNames instanceof Array) {
  1521. if (!meshesNames.indexOf(meshName)) {
  1522. continue;
  1523. }
  1524. }
  1525. else {
  1526. if (meshName !== meshesNames) {
  1527. continue;
  1528. }
  1529. }
  1530. }
  1531. // stl mesh name can be empty as well
  1532. meshName = meshName || "stlmesh";
  1533. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1534. this._parseASCII(babylonMesh, matches[2]);
  1535. if (meshes) {
  1536. meshes.push(babylonMesh);
  1537. }
  1538. }
  1539. return true;
  1540. };
  1541. /**
  1542. * Load into a scene.
  1543. * @param scene The scene to load into
  1544. * @param data The data to import
  1545. * @param rootUrl The root url for scene and resources
  1546. * @param onError The callback when import fails
  1547. * @returns true if successful or false otherwise
  1548. */
  1549. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1550. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1551. return result;
  1552. };
  1553. /**
  1554. * Load into an asset container.
  1555. * @param scene The scene to load into
  1556. * @param data The data to import
  1557. * @param rootUrl The root url for scene and resources
  1558. * @param onError The callback when import fails
  1559. * @returns The loaded asset container
  1560. */
  1561. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1562. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1563. scene._blockEntityCollection = true;
  1564. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1565. scene._blockEntityCollection = false;
  1566. return container;
  1567. };
  1568. STLFileLoader.prototype._isBinary = function (data) {
  1569. // check if file size is correct for binary stl
  1570. var faceSize, nFaces, reader;
  1571. reader = new DataView(data);
  1572. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1573. nFaces = reader.getUint32(80, true);
  1574. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1575. return true;
  1576. }
  1577. // check characters higher than ASCII to confirm binary
  1578. var fileLength = reader.byteLength;
  1579. for (var index = 0; index < fileLength; index++) {
  1580. if (reader.getUint8(index) > 127) {
  1581. return true;
  1582. }
  1583. }
  1584. return false;
  1585. };
  1586. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1587. var reader = new DataView(data);
  1588. var faces = reader.getUint32(80, true);
  1589. var dataOffset = 84;
  1590. var faceLength = 12 * 4 + 2;
  1591. var offset = 0;
  1592. var positions = new Float32Array(faces * 3 * 3);
  1593. var normals = new Float32Array(faces * 3 * 3);
  1594. var indices = new Uint32Array(faces * 3);
  1595. var indicesCount = 0;
  1596. for (var face = 0; face < faces; face++) {
  1597. var start = dataOffset + face * faceLength;
  1598. var normalX = reader.getFloat32(start, true);
  1599. var normalY = reader.getFloat32(start + 4, true);
  1600. var normalZ = reader.getFloat32(start + 8, true);
  1601. for (var i = 1; i <= 3; i++) {
  1602. var vertexstart = start + i * 12;
  1603. // ordering is intentional to match ascii import
  1604. positions[offset] = reader.getFloat32(vertexstart, true);
  1605. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1606. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1607. normals[offset] = normalX;
  1608. normals[offset + 2] = normalY;
  1609. normals[offset + 1] = normalZ;
  1610. offset += 3;
  1611. }
  1612. indices[indicesCount] = indicesCount++;
  1613. indices[indicesCount] = indicesCount++;
  1614. indices[indicesCount] = indicesCount++;
  1615. }
  1616. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1617. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1618. mesh.setIndices(indices);
  1619. mesh.computeWorldMatrix(true);
  1620. };
  1621. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1622. var positions = [];
  1623. var normals = [];
  1624. var indices = [];
  1625. var indicesCount = 0;
  1626. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1627. var matches;
  1628. while (matches = this.facetsPattern.exec(solidData)) {
  1629. var facet = matches[1];
  1630. //one normal per face
  1631. var normalMatches = this.normalPattern.exec(facet);
  1632. this.normalPattern.lastIndex = 0;
  1633. if (!normalMatches) {
  1634. continue;
  1635. }
  1636. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1637. var vertexMatch;
  1638. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1639. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1640. normals.push(normal[0], normal[1], normal[2]);
  1641. }
  1642. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1643. this.vertexPattern.lastIndex = 0;
  1644. }
  1645. this.facetsPattern.lastIndex = 0;
  1646. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1647. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1648. mesh.setIndices(indices);
  1649. mesh.computeWorldMatrix(true);
  1650. };
  1651. return STLFileLoader;
  1652. }());
  1653. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1654. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1655. }
  1656. /***/ }),
  1657. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1658. /*!*****************************************!*\
  1659. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1660. \*****************************************/
  1661. /*! exports provided: GLTFBinaryExtension */
  1662. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1663. "use strict";
  1664. __webpack_require__.r(__webpack_exports__);
  1665. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1666. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1667. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1668. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1669. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1670. var BinaryExtensionBufferName = "binary_glTF";
  1671. /** @hidden */
  1672. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1673. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1674. function GLTFBinaryExtension() {
  1675. return _super.call(this, "KHR_binary_glTF") || this;
  1676. }
  1677. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1678. var extensionsUsed = data.json.extensionsUsed;
  1679. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1680. return false;
  1681. }
  1682. this._bin = data.bin;
  1683. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1684. return true;
  1685. };
  1686. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1687. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1688. return false;
  1689. }
  1690. if (id !== BinaryExtensionBufferName) {
  1691. return false;
  1692. }
  1693. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1694. return true;
  1695. };
  1696. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1697. var texture = gltfRuntime.textures[id];
  1698. var source = gltfRuntime.images[texture.source];
  1699. if (!source.extensions || !(this.name in source.extensions)) {
  1700. return false;
  1701. }
  1702. var sourceExt = source.extensions[this.name];
  1703. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1704. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1705. onSuccess(buffer);
  1706. return true;
  1707. };
  1708. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1709. var shader = gltfRuntime.shaders[id];
  1710. if (!shader.extensions || !(this.name in shader.extensions)) {
  1711. return false;
  1712. }
  1713. var binaryExtensionShader = shader.extensions[this.name];
  1714. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1715. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1716. setTimeout(function () {
  1717. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1718. onSuccess(shaderString);
  1719. });
  1720. return true;
  1721. };
  1722. return GLTFBinaryExtension;
  1723. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1724. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1725. /***/ }),
  1726. /***/ "./glTF/1.0/glTFLoader.ts":
  1727. /*!********************************!*\
  1728. !*** ./glTF/1.0/glTFLoader.ts ***!
  1729. \********************************/
  1730. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1731. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1732. "use strict";
  1733. __webpack_require__.r(__webpack_exports__);
  1734. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1735. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1736. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1737. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1738. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  1739. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  1740. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1741. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1742. /**
  1743. * Tokenizer. Used for shaders compatibility
  1744. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1745. */
  1746. var ETokenType;
  1747. (function (ETokenType) {
  1748. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1749. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1750. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1751. })(ETokenType || (ETokenType = {}));
  1752. var Tokenizer = /** @class */ (function () {
  1753. function Tokenizer(toParse) {
  1754. this._pos = 0;
  1755. this.currentToken = ETokenType.UNKNOWN;
  1756. this.currentIdentifier = "";
  1757. this.currentString = "";
  1758. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1759. this._toParse = toParse;
  1760. this._maxPos = toParse.length;
  1761. }
  1762. Tokenizer.prototype.getNextToken = function () {
  1763. if (this.isEnd()) {
  1764. return ETokenType.END_OF_INPUT;
  1765. }
  1766. this.currentString = this.read();
  1767. this.currentToken = ETokenType.UNKNOWN;
  1768. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1769. this.currentToken = ETokenType.IDENTIFIER;
  1770. this.currentIdentifier = this.currentString;
  1771. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1772. this.currentIdentifier += this.currentString;
  1773. this.forward();
  1774. }
  1775. }
  1776. return this.currentToken;
  1777. };
  1778. Tokenizer.prototype.peek = function () {
  1779. return this._toParse[this._pos];
  1780. };
  1781. Tokenizer.prototype.read = function () {
  1782. return this._toParse[this._pos++];
  1783. };
  1784. Tokenizer.prototype.forward = function () {
  1785. this._pos++;
  1786. };
  1787. Tokenizer.prototype.isEnd = function () {
  1788. return this._pos >= this._maxPos;
  1789. };
  1790. return Tokenizer;
  1791. }());
  1792. /**
  1793. * Values
  1794. */
  1795. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1796. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1797. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1798. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1799. /**
  1800. * Parse
  1801. */
  1802. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1803. for (var buf in parsedBuffers) {
  1804. var parsedBuffer = parsedBuffers[buf];
  1805. gltfRuntime.buffers[buf] = parsedBuffer;
  1806. gltfRuntime.buffersCount++;
  1807. }
  1808. };
  1809. var parseShaders = function (parsedShaders, gltfRuntime) {
  1810. for (var sha in parsedShaders) {
  1811. var parsedShader = parsedShaders[sha];
  1812. gltfRuntime.shaders[sha] = parsedShader;
  1813. gltfRuntime.shaderscount++;
  1814. }
  1815. };
  1816. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1817. for (var object in parsedObjects) {
  1818. var parsedObject = parsedObjects[object];
  1819. gltfRuntime[runtimeProperty][object] = parsedObject;
  1820. }
  1821. };
  1822. /**
  1823. * Utils
  1824. */
  1825. var normalizeUVs = function (buffer) {
  1826. if (!buffer) {
  1827. return;
  1828. }
  1829. for (var i = 0; i < buffer.length / 2; i++) {
  1830. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1831. }
  1832. };
  1833. var getAttribute = function (attributeParameter) {
  1834. if (attributeParameter.semantic === "NORMAL") {
  1835. return "normal";
  1836. }
  1837. else if (attributeParameter.semantic === "POSITION") {
  1838. return "position";
  1839. }
  1840. else if (attributeParameter.semantic === "JOINT") {
  1841. return "matricesIndices";
  1842. }
  1843. else if (attributeParameter.semantic === "WEIGHT") {
  1844. return "matricesWeights";
  1845. }
  1846. else if (attributeParameter.semantic === "COLOR") {
  1847. return "color";
  1848. }
  1849. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1850. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1851. return "uv" + (channel === 0 ? "" : channel + 1);
  1852. }
  1853. return null;
  1854. };
  1855. /**
  1856. * Loads and creates animations
  1857. */
  1858. var loadAnimations = function (gltfRuntime) {
  1859. for (var anim in gltfRuntime.animations) {
  1860. var animation = gltfRuntime.animations[anim];
  1861. if (!animation.channels || !animation.samplers) {
  1862. continue;
  1863. }
  1864. var lastAnimation = null;
  1865. for (var i = 0; i < animation.channels.length; i++) {
  1866. // Get parameters and load buffers
  1867. var channel = animation.channels[i];
  1868. var sampler = animation.samplers[channel.sampler];
  1869. if (!sampler) {
  1870. continue;
  1871. }
  1872. var inputData = null;
  1873. var outputData = null;
  1874. if (animation.parameters) {
  1875. inputData = animation.parameters[sampler.input];
  1876. outputData = animation.parameters[sampler.output];
  1877. }
  1878. else {
  1879. inputData = sampler.input;
  1880. outputData = sampler.output;
  1881. }
  1882. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1883. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1884. var targetID = channel.target.id;
  1885. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1886. if (targetNode === null) {
  1887. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1888. }
  1889. if (targetNode === null) {
  1890. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1891. continue;
  1892. }
  1893. var isBone = targetNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1894. // Get target path (position, rotation or scaling)
  1895. var targetPath = channel.target.path;
  1896. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1897. if (targetPathIndex !== -1) {
  1898. targetPath = babylonAnimationPaths[targetPathIndex];
  1899. }
  1900. // Determine animation type
  1901. var animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1902. if (!isBone) {
  1903. if (targetPath === "rotationQuaternion") {
  1904. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1905. targetNode.rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1906. }
  1907. else {
  1908. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1909. }
  1910. }
  1911. // Create animation and key frames
  1912. var babylonAnimation = null;
  1913. var keys = [];
  1914. var arrayOffset = 0;
  1915. var modifyKey = false;
  1916. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1917. babylonAnimation = lastAnimation;
  1918. modifyKey = true;
  1919. }
  1920. if (!modifyKey) {
  1921. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1922. babylonAnimation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"](anim, isBone ? "_matrix" : targetPath, 1, animationType, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONLOOPMODE_CYCLE);
  1923. gltfRuntime.scene._blockEntityCollection = false;
  1924. }
  1925. // For each frame
  1926. for (var j = 0; j < bufferInput.length; j++) {
  1927. var value = null;
  1928. if (targetPath === "rotationQuaternion") { // VEC4
  1929. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1930. arrayOffset += 4;
  1931. }
  1932. else { // Position and scaling are VEC3
  1933. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1934. arrayOffset += 3;
  1935. }
  1936. if (isBone) {
  1937. var bone = targetNode;
  1938. var translation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1939. var rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1940. var scaling = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1941. // Warning on decompose
  1942. var mat = bone.getBaseMatrix();
  1943. if (modifyKey && lastAnimation) {
  1944. mat = lastAnimation.getKeys()[j].value;
  1945. }
  1946. mat.decompose(scaling, rotationQuaternion, translation);
  1947. if (targetPath === "position") {
  1948. translation = value;
  1949. }
  1950. else if (targetPath === "rotationQuaternion") {
  1951. rotationQuaternion = value;
  1952. }
  1953. else {
  1954. scaling = value;
  1955. }
  1956. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1957. }
  1958. if (!modifyKey) {
  1959. keys.push({
  1960. frame: bufferInput[j],
  1961. value: value
  1962. });
  1963. }
  1964. else if (lastAnimation) {
  1965. lastAnimation.getKeys()[j].value = value;
  1966. }
  1967. }
  1968. // Finish
  1969. if (!modifyKey && babylonAnimation) {
  1970. babylonAnimation.setKeys(keys);
  1971. targetNode.animations.push(babylonAnimation);
  1972. }
  1973. lastAnimation = babylonAnimation;
  1974. gltfRuntime.scene.stopAnimation(targetNode);
  1975. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  1976. }
  1977. }
  1978. };
  1979. /**
  1980. * Returns the bones transformation matrix
  1981. */
  1982. var configureBoneTransformation = function (node) {
  1983. var mat = null;
  1984. if (node.translation || node.rotation || node.scale) {
  1985. var scale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  1986. var rotation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  1987. var position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  1988. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  1989. }
  1990. else {
  1991. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1992. }
  1993. return mat;
  1994. };
  1995. /**
  1996. * Returns the parent bone
  1997. */
  1998. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  1999. // Try to find
  2000. for (var i = 0; i < newSkeleton.bones.length; i++) {
  2001. if (newSkeleton.bones[i].name === jointName) {
  2002. return newSkeleton.bones[i];
  2003. }
  2004. }
  2005. // Not found, search in gltf nodes
  2006. var nodes = gltfRuntime.nodes;
  2007. for (var nde in nodes) {
  2008. var node = nodes[nde];
  2009. if (!node.jointName) {
  2010. continue;
  2011. }
  2012. var children = node.children;
  2013. for (var i = 0; i < children.length; i++) {
  2014. var child = gltfRuntime.nodes[children[i]];
  2015. if (!child.jointName) {
  2016. continue;
  2017. }
  2018. if (child.jointName === jointName) {
  2019. var mat = configureBoneTransformation(node);
  2020. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  2021. bone.id = nde;
  2022. return bone;
  2023. }
  2024. }
  2025. }
  2026. return null;
  2027. };
  2028. /**
  2029. * Returns the appropriate root node
  2030. */
  2031. var getNodeToRoot = function (nodesToRoot, id) {
  2032. for (var i = 0; i < nodesToRoot.length; i++) {
  2033. var nodeToRoot = nodesToRoot[i];
  2034. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  2035. var child = nodeToRoot.node.children[j];
  2036. if (child === id) {
  2037. return nodeToRoot.bone;
  2038. }
  2039. }
  2040. }
  2041. return null;
  2042. };
  2043. /**
  2044. * Returns the node with the joint name
  2045. */
  2046. var getJointNode = function (gltfRuntime, jointName) {
  2047. var nodes = gltfRuntime.nodes;
  2048. var node = nodes[jointName];
  2049. if (node) {
  2050. return {
  2051. node: node,
  2052. id: jointName
  2053. };
  2054. }
  2055. for (var nde in nodes) {
  2056. node = nodes[nde];
  2057. if (node.jointName === jointName) {
  2058. return {
  2059. node: node,
  2060. id: nde
  2061. };
  2062. }
  2063. }
  2064. return null;
  2065. };
  2066. /**
  2067. * Checks if a nodes is in joints
  2068. */
  2069. var nodeIsInJoints = function (skins, id) {
  2070. for (var i = 0; i < skins.jointNames.length; i++) {
  2071. if (skins.jointNames[i] === id) {
  2072. return true;
  2073. }
  2074. }
  2075. return false;
  2076. };
  2077. /**
  2078. * Fills the nodes to root for bones and builds hierarchy
  2079. */
  2080. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2081. // Creates nodes for root
  2082. for (var nde in gltfRuntime.nodes) {
  2083. var node = gltfRuntime.nodes[nde];
  2084. var id = nde;
  2085. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2086. continue;
  2087. }
  2088. // Create node to root bone
  2089. var mat = configureBoneTransformation(node);
  2090. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2091. bone.id = id;
  2092. nodesToRoot.push({ bone: bone, node: node, id: id });
  2093. }
  2094. // Parenting
  2095. for (var i = 0; i < nodesToRoot.length; i++) {
  2096. var nodeToRoot = nodesToRoot[i];
  2097. var children = nodeToRoot.node.children;
  2098. for (var j = 0; j < children.length; j++) {
  2099. var child = null;
  2100. for (var k = 0; k < nodesToRoot.length; k++) {
  2101. if (nodesToRoot[k].id === children[j]) {
  2102. child = nodesToRoot[k];
  2103. break;
  2104. }
  2105. }
  2106. if (child) {
  2107. child.bone._parent = nodeToRoot.bone;
  2108. nodeToRoot.bone.children.push(child.bone);
  2109. }
  2110. }
  2111. }
  2112. };
  2113. /**
  2114. * Imports a skeleton
  2115. */
  2116. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2117. if (!newSkeleton) {
  2118. newSkeleton = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2119. }
  2120. if (!skins.babylonSkeleton) {
  2121. return newSkeleton;
  2122. }
  2123. // Find the root bones
  2124. var nodesToRoot = [];
  2125. var nodesToRootToAdd = [];
  2126. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2127. newSkeleton.bones = [];
  2128. // Joints
  2129. for (var i = 0; i < skins.jointNames.length; i++) {
  2130. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2131. if (!jointNode) {
  2132. continue;
  2133. }
  2134. var node = jointNode.node;
  2135. if (!node) {
  2136. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2137. continue;
  2138. }
  2139. var id = jointNode.id;
  2140. // Optimize, if the bone already exists...
  2141. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2142. if (existingBone) {
  2143. newSkeleton.bones.push(existingBone);
  2144. continue;
  2145. }
  2146. // Search for parent bone
  2147. var foundBone = false;
  2148. var parentBone = null;
  2149. for (var j = 0; j < i; j++) {
  2150. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2151. if (!jointNode_1) {
  2152. continue;
  2153. }
  2154. var joint = jointNode_1.node;
  2155. if (!joint) {
  2156. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2157. continue;
  2158. }
  2159. var children = joint.children;
  2160. if (!children) {
  2161. continue;
  2162. }
  2163. foundBone = false;
  2164. for (var k = 0; k < children.length; k++) {
  2165. if (children[k] === id) {
  2166. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2167. foundBone = true;
  2168. break;
  2169. }
  2170. }
  2171. if (foundBone) {
  2172. break;
  2173. }
  2174. }
  2175. // Create bone
  2176. var mat = configureBoneTransformation(node);
  2177. if (!parentBone && nodesToRoot.length > 0) {
  2178. parentBone = getNodeToRoot(nodesToRoot, id);
  2179. if (parentBone) {
  2180. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2181. nodesToRootToAdd.push(parentBone);
  2182. }
  2183. }
  2184. }
  2185. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2186. bone.id = id;
  2187. }
  2188. // Polish
  2189. var bones = newSkeleton.bones;
  2190. newSkeleton.bones = [];
  2191. for (var i = 0; i < skins.jointNames.length; i++) {
  2192. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2193. if (!jointNode) {
  2194. continue;
  2195. }
  2196. for (var j = 0; j < bones.length; j++) {
  2197. if (bones[j].id === jointNode.id) {
  2198. newSkeleton.bones.push(bones[j]);
  2199. break;
  2200. }
  2201. }
  2202. }
  2203. newSkeleton.prepare();
  2204. // Finish
  2205. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2206. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2207. }
  2208. return newSkeleton;
  2209. };
  2210. /**
  2211. * Imports a mesh and its geometries
  2212. */
  2213. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2214. if (!newMesh) {
  2215. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2216. newMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2217. gltfRuntime.scene._blockEntityCollection = false;
  2218. newMesh.id = id;
  2219. }
  2220. if (!node.babylonNode) {
  2221. return newMesh;
  2222. }
  2223. var subMaterials = [];
  2224. var vertexData = null;
  2225. var verticesStarts = new Array();
  2226. var verticesCounts = new Array();
  2227. var indexStarts = new Array();
  2228. var indexCounts = new Array();
  2229. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2230. var meshID = meshes[meshIndex];
  2231. var mesh = gltfRuntime.meshes[meshID];
  2232. if (!mesh) {
  2233. continue;
  2234. }
  2235. // Positions, normals and UVs
  2236. for (var i = 0; i < mesh.primitives.length; i++) {
  2237. // Temporary vertex data
  2238. var tempVertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2239. var primitive = mesh.primitives[i];
  2240. if (primitive.mode !== 4) {
  2241. // continue;
  2242. }
  2243. var attributes = primitive.attributes;
  2244. var accessor = null;
  2245. var buffer = null;
  2246. // Set positions, normal and uvs
  2247. for (var semantic in attributes) {
  2248. // Link accessor and buffer view
  2249. accessor = gltfRuntime.accessors[attributes[semantic]];
  2250. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2251. if (semantic === "NORMAL") {
  2252. tempVertexData.normals = new Float32Array(buffer.length);
  2253. tempVertexData.normals.set(buffer);
  2254. }
  2255. else if (semantic === "POSITION") {
  2256. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2257. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2258. for (var j = 0; j < buffer.length; j += 4) {
  2259. tempVertexData.positions[j] = buffer[j];
  2260. tempVertexData.positions[j + 1] = buffer[j + 1];
  2261. tempVertexData.positions[j + 2] = buffer[j + 2];
  2262. }
  2263. }
  2264. else {
  2265. tempVertexData.positions = new Float32Array(buffer.length);
  2266. tempVertexData.positions.set(buffer);
  2267. }
  2268. verticesCounts.push(tempVertexData.positions.length);
  2269. }
  2270. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2271. var channel = Number(semantic.split("_")[1]);
  2272. var uvKind = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2273. var uvs = new Float32Array(buffer.length);
  2274. uvs.set(buffer);
  2275. normalizeUVs(uvs);
  2276. tempVertexData.set(uvs, uvKind);
  2277. }
  2278. else if (semantic === "JOINT") {
  2279. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2280. tempVertexData.matricesIndices.set(buffer);
  2281. }
  2282. else if (semantic === "WEIGHT") {
  2283. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2284. tempVertexData.matricesWeights.set(buffer);
  2285. }
  2286. else if (semantic === "COLOR") {
  2287. tempVertexData.colors = new Float32Array(buffer.length);
  2288. tempVertexData.colors.set(buffer);
  2289. }
  2290. }
  2291. // Indices
  2292. accessor = gltfRuntime.accessors[primitive.indices];
  2293. if (accessor) {
  2294. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2295. tempVertexData.indices = new Int32Array(buffer.length);
  2296. tempVertexData.indices.set(buffer);
  2297. indexCounts.push(tempVertexData.indices.length);
  2298. }
  2299. else {
  2300. // Set indices on the fly
  2301. var indices = [];
  2302. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2303. indices.push(j);
  2304. }
  2305. tempVertexData.indices = new Int32Array(indices);
  2306. indexCounts.push(tempVertexData.indices.length);
  2307. }
  2308. if (!vertexData) {
  2309. vertexData = tempVertexData;
  2310. }
  2311. else {
  2312. vertexData.merge(tempVertexData);
  2313. }
  2314. // Sub material
  2315. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2316. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2317. // Update vertices start and index start
  2318. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2319. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2320. }
  2321. }
  2322. var material;
  2323. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2324. if (subMaterials.length > 1) {
  2325. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2326. material.subMaterials = subMaterials;
  2327. }
  2328. else {
  2329. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2330. }
  2331. if (subMaterials.length === 1) {
  2332. material = subMaterials[0];
  2333. }
  2334. if (!newMesh.material) {
  2335. newMesh.material = material;
  2336. }
  2337. // Apply geometry
  2338. new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2339. newMesh.computeWorldMatrix(true);
  2340. gltfRuntime.scene._blockEntityCollection = false;
  2341. // Apply submeshes
  2342. newMesh.subMeshes = [];
  2343. var index = 0;
  2344. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2345. var meshID = meshes[meshIndex];
  2346. var mesh = gltfRuntime.meshes[meshID];
  2347. if (!mesh) {
  2348. continue;
  2349. }
  2350. for (var i = 0; i < mesh.primitives.length; i++) {
  2351. if (mesh.primitives[i].mode !== 4) {
  2352. //continue;
  2353. }
  2354. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2355. index++;
  2356. }
  2357. }
  2358. // Finish
  2359. return newMesh;
  2360. };
  2361. /**
  2362. * Configure node transformation from position, rotation and scaling
  2363. */
  2364. var configureNode = function (newNode, position, rotation, scaling) {
  2365. if (newNode.position) {
  2366. newNode.position = position;
  2367. }
  2368. if (newNode.rotationQuaternion || newNode.rotation) {
  2369. newNode.rotationQuaternion = rotation;
  2370. }
  2371. if (newNode.scaling) {
  2372. newNode.scaling = scaling;
  2373. }
  2374. };
  2375. /**
  2376. * Configures node from transformation matrix
  2377. */
  2378. var configureNodeFromMatrix = function (newNode, node, parent) {
  2379. if (node.matrix) {
  2380. var position = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2381. var rotation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2382. var scaling = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2383. var mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2384. mat.decompose(scaling, rotation, position);
  2385. configureNode(newNode, position, rotation, scaling);
  2386. }
  2387. else if (node.translation && node.rotation && node.scale) {
  2388. configureNode(newNode, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale));
  2389. }
  2390. newNode.computeWorldMatrix(true);
  2391. };
  2392. /**
  2393. * Imports a node
  2394. */
  2395. var importNode = function (gltfRuntime, node, id, parent) {
  2396. var lastNode = null;
  2397. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2398. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2399. return null;
  2400. }
  2401. }
  2402. // Meshes
  2403. if (node.skin) {
  2404. if (node.meshes) {
  2405. var skin = gltfRuntime.skins[node.skin];
  2406. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2407. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2408. if (newMesh.skeleton === null) {
  2409. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2410. if (!skin.babylonSkeleton) {
  2411. skin.babylonSkeleton = newMesh.skeleton;
  2412. }
  2413. }
  2414. lastNode = newMesh;
  2415. }
  2416. }
  2417. else if (node.meshes) {
  2418. /**
  2419. * Improve meshes property
  2420. */
  2421. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2422. lastNode = newMesh;
  2423. }
  2424. // Lights
  2425. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2426. var light = gltfRuntime.lights[node.light];
  2427. if (light) {
  2428. if (light.type === "ambient") {
  2429. var ambienLight = light[light.type];
  2430. var hemiLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2431. hemiLight.name = node.name || "";
  2432. if (ambienLight.color) {
  2433. hemiLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2434. }
  2435. lastNode = hemiLight;
  2436. }
  2437. else if (light.type === "directional") {
  2438. var directionalLight = light[light.type];
  2439. var dirLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2440. dirLight.name = node.name || "";
  2441. if (directionalLight.color) {
  2442. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2443. }
  2444. lastNode = dirLight;
  2445. }
  2446. else if (light.type === "point") {
  2447. var pointLight = light[light.type];
  2448. var ptLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2449. ptLight.name = node.name || "";
  2450. if (pointLight.color) {
  2451. ptLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2452. }
  2453. lastNode = ptLight;
  2454. }
  2455. else if (light.type === "spot") {
  2456. var spotLight = light[light.type];
  2457. var spLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SpotLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), 0, 0, gltfRuntime.scene);
  2458. spLight.name = node.name || "";
  2459. if (spotLight.color) {
  2460. spLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2461. }
  2462. if (spotLight.fallOfAngle) {
  2463. spLight.angle = spotLight.fallOfAngle;
  2464. }
  2465. if (spotLight.fallOffExponent) {
  2466. spLight.exponent = spotLight.fallOffExponent;
  2467. }
  2468. lastNode = spLight;
  2469. }
  2470. }
  2471. }
  2472. // Cameras
  2473. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2474. var camera = gltfRuntime.cameras[node.camera];
  2475. if (camera) {
  2476. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2477. if (camera.type === "orthographic") {
  2478. var orthoCamera = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  2479. orthoCamera.name = node.name || "";
  2480. orthoCamera.mode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2481. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2482. lastNode = orthoCamera;
  2483. }
  2484. else if (camera.type === "perspective") {
  2485. var perspectiveCamera = camera[camera.type];
  2486. var persCamera = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  2487. persCamera.name = node.name || "";
  2488. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2489. if (!perspectiveCamera.aspectRatio) {
  2490. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2491. }
  2492. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2493. persCamera.maxZ = perspectiveCamera.zfar;
  2494. persCamera.minZ = perspectiveCamera.znear;
  2495. }
  2496. lastNode = persCamera;
  2497. }
  2498. gltfRuntime.scene._blockEntityCollection = false;
  2499. }
  2500. }
  2501. // Empty node
  2502. if (!node.jointName) {
  2503. if (node.babylonNode) {
  2504. return node.babylonNode;
  2505. }
  2506. else if (lastNode === null) {
  2507. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2508. var dummy = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2509. gltfRuntime.scene._blockEntityCollection = false;
  2510. node.babylonNode = dummy;
  2511. lastNode = dummy;
  2512. }
  2513. }
  2514. if (lastNode !== null) {
  2515. if (node.matrix && lastNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2516. configureNodeFromMatrix(lastNode, node, parent);
  2517. }
  2518. else {
  2519. var translation = node.translation || [0, 0, 0];
  2520. var rotation = node.rotation || [0, 0, 0, 1];
  2521. var scale = node.scale || [1, 1, 1];
  2522. configureNode(lastNode, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(translation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(rotation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(scale));
  2523. }
  2524. lastNode.updateCache(true);
  2525. node.babylonNode = lastNode;
  2526. }
  2527. return lastNode;
  2528. };
  2529. /**
  2530. * Traverses nodes and creates them
  2531. */
  2532. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2533. if (meshIncluded === void 0) { meshIncluded = false; }
  2534. var node = gltfRuntime.nodes[id];
  2535. var newNode = null;
  2536. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2537. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2538. meshIncluded = true;
  2539. }
  2540. else {
  2541. meshIncluded = false;
  2542. }
  2543. }
  2544. else {
  2545. meshIncluded = true;
  2546. }
  2547. if (!node.jointName && meshIncluded) {
  2548. newNode = importNode(gltfRuntime, node, id, parent);
  2549. if (newNode !== null) {
  2550. newNode.id = id;
  2551. newNode.parent = parent;
  2552. }
  2553. }
  2554. if (node.children) {
  2555. for (var i = 0; i < node.children.length; i++) {
  2556. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2557. }
  2558. }
  2559. };
  2560. /**
  2561. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2562. */
  2563. var postLoad = function (gltfRuntime) {
  2564. // Nodes
  2565. var currentScene = gltfRuntime.currentScene;
  2566. if (currentScene) {
  2567. for (var i = 0; i < currentScene.nodes.length; i++) {
  2568. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2569. }
  2570. }
  2571. else {
  2572. for (var thing in gltfRuntime.scenes) {
  2573. currentScene = gltfRuntime.scenes[thing];
  2574. for (var i = 0; i < currentScene.nodes.length; i++) {
  2575. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2576. }
  2577. }
  2578. }
  2579. // Set animations
  2580. loadAnimations(gltfRuntime);
  2581. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2582. var skeleton = gltfRuntime.scene.skeletons[i];
  2583. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2584. }
  2585. };
  2586. /**
  2587. * onBind shaderrs callback to set uniforms and matrices
  2588. */
  2589. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2590. var materialValues = material.values || technique.parameters;
  2591. for (var unif in unTreatedUniforms) {
  2592. var uniform = unTreatedUniforms[unif];
  2593. var type = uniform.type;
  2594. 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) {
  2595. if (uniform.semantic && !uniform.source && !uniform.node) {
  2596. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2597. }
  2598. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2599. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2600. if (source === null) {
  2601. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2602. }
  2603. if (source === null) {
  2604. continue;
  2605. }
  2606. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2607. }
  2608. }
  2609. else {
  2610. var value = materialValues[technique.uniforms[unif]];
  2611. if (!value) {
  2612. continue;
  2613. }
  2614. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2615. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2616. if (texture === null || texture === undefined) {
  2617. continue;
  2618. }
  2619. shaderMaterial.getEffect().setTexture(unif, texture);
  2620. }
  2621. else {
  2622. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2623. }
  2624. }
  2625. }
  2626. onSuccess(shaderMaterial);
  2627. };
  2628. /**
  2629. * Prepare uniforms to send the only one time
  2630. * Loads the appropriate textures
  2631. */
  2632. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2633. var materialValues = material.values || technique.parameters;
  2634. var techniqueUniforms = technique.uniforms;
  2635. /**
  2636. * Prepare values here (not matrices)
  2637. */
  2638. for (var unif in unTreatedUniforms) {
  2639. var uniform = unTreatedUniforms[unif];
  2640. var type = uniform.type;
  2641. var value = materialValues[techniqueUniforms[unif]];
  2642. if (value === undefined) {
  2643. // In case the value is the same for all materials
  2644. value = uniform.value;
  2645. }
  2646. if (!value) {
  2647. continue;
  2648. }
  2649. var onLoadTexture = function (uniformName) {
  2650. return function (texture) {
  2651. if (uniform.value && uniformName) {
  2652. // Static uniform
  2653. shaderMaterial.setTexture(uniformName, texture);
  2654. delete unTreatedUniforms[uniformName];
  2655. }
  2656. };
  2657. };
  2658. // Texture (sampler2D)
  2659. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2660. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2661. }
  2662. // Others
  2663. else {
  2664. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2665. // Static uniform
  2666. delete unTreatedUniforms[unif];
  2667. }
  2668. }
  2669. }
  2670. };
  2671. /**
  2672. * Shader compilation failed
  2673. */
  2674. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2675. return function (effect, error) {
  2676. shaderMaterial.dispose(true);
  2677. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2678. };
  2679. };
  2680. /**
  2681. * Shader compilation success
  2682. */
  2683. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2684. return function (_) {
  2685. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2686. shaderMaterial.onBind = function (mesh) {
  2687. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2688. };
  2689. };
  2690. };
  2691. /**
  2692. * Returns the appropriate uniform if already handled by babylon
  2693. */
  2694. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2695. for (var unif in technique.uniforms) {
  2696. var uniform = technique.uniforms[unif];
  2697. var uniformParameter = technique.parameters[uniform];
  2698. if (tokenizer.currentIdentifier === unif) {
  2699. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2700. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2701. if (transformIndex !== -1) {
  2702. delete unTreatedUniforms[unif];
  2703. return babylonTransforms[transformIndex];
  2704. }
  2705. }
  2706. }
  2707. }
  2708. return tokenizer.currentIdentifier;
  2709. };
  2710. /**
  2711. * All shaders loaded. Create materials one by one
  2712. */
  2713. var importMaterials = function (gltfRuntime) {
  2714. // Create materials
  2715. for (var mat in gltfRuntime.materials) {
  2716. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2717. }
  2718. };
  2719. /**
  2720. * Implementation of the base glTF spec
  2721. * @hidden
  2722. */
  2723. var GLTFLoaderBase = /** @class */ (function () {
  2724. function GLTFLoaderBase() {
  2725. }
  2726. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2727. var gltfRuntime = {
  2728. extensions: {},
  2729. accessors: {},
  2730. buffers: {},
  2731. bufferViews: {},
  2732. meshes: {},
  2733. lights: {},
  2734. cameras: {},
  2735. nodes: {},
  2736. images: {},
  2737. textures: {},
  2738. shaders: {},
  2739. programs: {},
  2740. samplers: {},
  2741. techniques: {},
  2742. materials: {},
  2743. animations: {},
  2744. skins: {},
  2745. extensionsUsed: [],
  2746. scenes: {},
  2747. buffersCount: 0,
  2748. shaderscount: 0,
  2749. scene: scene,
  2750. rootUrl: rootUrl,
  2751. loadedBufferCount: 0,
  2752. loadedBufferViews: {},
  2753. loadedShaderCount: 0,
  2754. importOnlyMeshes: false,
  2755. dummyNodes: [],
  2756. forAssetContainer: false
  2757. };
  2758. // Parse
  2759. if (parsedData.extensions) {
  2760. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2761. }
  2762. if (parsedData.extensionsUsed) {
  2763. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2764. }
  2765. if (parsedData.buffers) {
  2766. parseBuffers(parsedData.buffers, gltfRuntime);
  2767. }
  2768. if (parsedData.bufferViews) {
  2769. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2770. }
  2771. if (parsedData.accessors) {
  2772. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2773. }
  2774. if (parsedData.meshes) {
  2775. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2776. }
  2777. if (parsedData.lights) {
  2778. parseObject(parsedData.lights, "lights", gltfRuntime);
  2779. }
  2780. if (parsedData.cameras) {
  2781. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2782. }
  2783. if (parsedData.nodes) {
  2784. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2785. }
  2786. if (parsedData.images) {
  2787. parseObject(parsedData.images, "images", gltfRuntime);
  2788. }
  2789. if (parsedData.textures) {
  2790. parseObject(parsedData.textures, "textures", gltfRuntime);
  2791. }
  2792. if (parsedData.shaders) {
  2793. parseShaders(parsedData.shaders, gltfRuntime);
  2794. }
  2795. if (parsedData.programs) {
  2796. parseObject(parsedData.programs, "programs", gltfRuntime);
  2797. }
  2798. if (parsedData.samplers) {
  2799. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2800. }
  2801. if (parsedData.techniques) {
  2802. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2803. }
  2804. if (parsedData.materials) {
  2805. parseObject(parsedData.materials, "materials", gltfRuntime);
  2806. }
  2807. if (parsedData.animations) {
  2808. parseObject(parsedData.animations, "animations", gltfRuntime);
  2809. }
  2810. if (parsedData.skins) {
  2811. parseObject(parsedData.skins, "skins", gltfRuntime);
  2812. }
  2813. if (parsedData.scenes) {
  2814. gltfRuntime.scenes = parsedData.scenes;
  2815. }
  2816. if (parsedData.scene && parsedData.scenes) {
  2817. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2818. }
  2819. return gltfRuntime;
  2820. };
  2821. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2822. var buffer = gltfRuntime.buffers[id];
  2823. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2824. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2825. }
  2826. else {
  2827. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, undefined, true, function (request) {
  2828. if (request) {
  2829. onError(request.status + " " + request.statusText);
  2830. }
  2831. });
  2832. }
  2833. };
  2834. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2835. var texture = gltfRuntime.textures[id];
  2836. if (!texture || !texture.source) {
  2837. onError("");
  2838. return;
  2839. }
  2840. if (texture.babylonTexture) {
  2841. onSuccess(null);
  2842. return;
  2843. }
  2844. var source = gltfRuntime.images[texture.source];
  2845. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2846. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2847. }
  2848. else {
  2849. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, undefined, undefined, true, function (request) {
  2850. if (request) {
  2851. onError(request.status + " " + request.statusText);
  2852. }
  2853. });
  2854. }
  2855. };
  2856. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2857. var texture = gltfRuntime.textures[id];
  2858. if (texture.babylonTexture) {
  2859. onSuccess(texture.babylonTexture);
  2860. return;
  2861. }
  2862. var sampler = gltfRuntime.samplers[texture.sampler];
  2863. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2864. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2865. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2866. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2867. var samplingMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2868. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2869. var blobURL = URL.createObjectURL(blob);
  2870. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2871. var newTexture = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2872. if (sampler.wrapS !== undefined) {
  2873. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2874. }
  2875. if (sampler.wrapT !== undefined) {
  2876. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2877. }
  2878. newTexture.name = id;
  2879. texture.babylonTexture = newTexture;
  2880. onSuccess(newTexture);
  2881. };
  2882. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2883. var shader = gltfRuntime.shaders[id];
  2884. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2885. var shaderString = atob(shader.uri.split(",")[1]);
  2886. if (onSuccess) {
  2887. onSuccess(shaderString);
  2888. }
  2889. }
  2890. else {
  2891. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2892. if (request && onError) {
  2893. onError(request.status + " " + request.statusText);
  2894. }
  2895. });
  2896. }
  2897. };
  2898. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2899. var material = gltfRuntime.materials[id];
  2900. if (!material.technique) {
  2901. if (onError) {
  2902. onError("No technique found.");
  2903. }
  2904. return;
  2905. }
  2906. var technique = gltfRuntime.techniques[material.technique];
  2907. if (!technique) {
  2908. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2909. var defaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2910. gltfRuntime.scene._blockEntityCollection = false;
  2911. defaultMaterial.diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2912. defaultMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2913. onSuccess(defaultMaterial);
  2914. return;
  2915. }
  2916. var program = gltfRuntime.programs[technique.program];
  2917. var states = technique.states;
  2918. var vertexShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2919. var pixelShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2920. var newVertexShader = "";
  2921. var newPixelShader = "";
  2922. var vertexTokenizer = new Tokenizer(vertexShader);
  2923. var pixelTokenizer = new Tokenizer(pixelShader);
  2924. var unTreatedUniforms = {};
  2925. var uniforms = [];
  2926. var attributes = [];
  2927. var samplers = [];
  2928. // Fill uniform, sampler2D and attributes
  2929. for (var unif in technique.uniforms) {
  2930. var uniform = technique.uniforms[unif];
  2931. var uniformParameter = technique.parameters[uniform];
  2932. unTreatedUniforms[unif] = uniformParameter;
  2933. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2934. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2935. if (transformIndex !== -1) {
  2936. uniforms.push(babylonTransforms[transformIndex]);
  2937. delete unTreatedUniforms[unif];
  2938. }
  2939. else {
  2940. uniforms.push(unif);
  2941. }
  2942. }
  2943. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2944. samplers.push(unif);
  2945. }
  2946. else {
  2947. uniforms.push(unif);
  2948. }
  2949. }
  2950. for (var attr in technique.attributes) {
  2951. var attribute = technique.attributes[attr];
  2952. var attributeParameter = technique.parameters[attribute];
  2953. if (attributeParameter.semantic) {
  2954. var name_1 = getAttribute(attributeParameter);
  2955. if (name_1) {
  2956. attributes.push(name_1);
  2957. }
  2958. }
  2959. }
  2960. // Configure vertex shader
  2961. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2962. var tokenType = vertexTokenizer.currentToken;
  2963. if (tokenType !== ETokenType.IDENTIFIER) {
  2964. newVertexShader += vertexTokenizer.currentString;
  2965. continue;
  2966. }
  2967. var foundAttribute = false;
  2968. for (var attr in technique.attributes) {
  2969. var attribute = technique.attributes[attr];
  2970. var attributeParameter = technique.parameters[attribute];
  2971. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  2972. newVertexShader += getAttribute(attributeParameter);
  2973. foundAttribute = true;
  2974. break;
  2975. }
  2976. }
  2977. if (foundAttribute) {
  2978. continue;
  2979. }
  2980. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  2981. }
  2982. // Configure pixel shader
  2983. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  2984. var tokenType = pixelTokenizer.currentToken;
  2985. if (tokenType !== ETokenType.IDENTIFIER) {
  2986. newPixelShader += pixelTokenizer.currentString;
  2987. continue;
  2988. }
  2989. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  2990. }
  2991. // Create shader material
  2992. var shaderPath = {
  2993. vertex: program.vertexShader + id,
  2994. fragment: program.fragmentShader + id
  2995. };
  2996. var options = {
  2997. attributes: attributes,
  2998. uniforms: uniforms,
  2999. samplers: samplers,
  3000. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  3001. };
  3002. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  3003. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  3004. var shaderMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  3005. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  3006. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  3007. shaderMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  3008. if (states && states.functions) {
  3009. var functions = states.functions;
  3010. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  3011. shaderMaterial.backFaceCulling = false;
  3012. }
  3013. var blendFunc = functions.blendFuncSeparate;
  3014. if (blendFunc) {
  3015. 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) {
  3016. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  3017. }
  3018. 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) {
  3019. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  3020. }
  3021. 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) {
  3022. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  3023. }
  3024. 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) {
  3025. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  3026. }
  3027. 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) {
  3028. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  3029. }
  3030. 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) {
  3031. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  3032. }
  3033. }
  3034. }
  3035. };
  3036. return GLTFLoaderBase;
  3037. }());
  3038. /**
  3039. * glTF V1 Loader
  3040. * @hidden
  3041. */
  3042. var GLTFLoader = /** @class */ (function () {
  3043. function GLTFLoader() {
  3044. this.state = null;
  3045. }
  3046. GLTFLoader.RegisterExtension = function (extension) {
  3047. if (GLTFLoader.Extensions[extension.name]) {
  3048. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  3049. return;
  3050. }
  3051. GLTFLoader.Extensions[extension.name] = extension;
  3052. };
  3053. GLTFLoader.prototype.dispose = function () {
  3054. // do nothing
  3055. };
  3056. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3057. var _this = this;
  3058. scene.useRightHandedSystem = true;
  3059. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3060. gltfRuntime.forAssetContainer = forAssetContainer;
  3061. gltfRuntime.importOnlyMeshes = true;
  3062. if (meshesNames === "") {
  3063. gltfRuntime.importMeshesNames = [];
  3064. }
  3065. else if (typeof meshesNames === "string") {
  3066. gltfRuntime.importMeshesNames = [meshesNames];
  3067. }
  3068. else if (meshesNames && !(meshesNames instanceof Array)) {
  3069. gltfRuntime.importMeshesNames = [meshesNames];
  3070. }
  3071. else {
  3072. gltfRuntime.importMeshesNames = [];
  3073. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3074. }
  3075. // Create nodes
  3076. _this._createNodes(gltfRuntime);
  3077. var meshes = new Array();
  3078. var skeletons = new Array();
  3079. // Fill arrays of meshes and skeletons
  3080. for (var nde in gltfRuntime.nodes) {
  3081. var node = gltfRuntime.nodes[nde];
  3082. if (node.babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3083. meshes.push(node.babylonNode);
  3084. }
  3085. }
  3086. for (var skl in gltfRuntime.skins) {
  3087. var skin = gltfRuntime.skins[skl];
  3088. if (skin.babylonSkeleton instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3089. skeletons.push(skin.babylonSkeleton);
  3090. }
  3091. }
  3092. // Load buffers, shaders, materials, etc.
  3093. _this._loadBuffersAsync(gltfRuntime, function () {
  3094. _this._loadShadersAsync(gltfRuntime, function () {
  3095. importMaterials(gltfRuntime);
  3096. postLoad(gltfRuntime);
  3097. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3098. onSuccess(meshes, skeletons);
  3099. }
  3100. });
  3101. }, onProgress);
  3102. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3103. onSuccess(meshes, skeletons);
  3104. }
  3105. }, onError);
  3106. return true;
  3107. };
  3108. /**
  3109. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3110. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3111. * @param scene the scene the meshes should be added to
  3112. * @param forAssetContainer defines if the entities must be stored in the scene
  3113. * @param data gltf data containing information of the meshes in a loaded file
  3114. * @param rootUrl root url to load from
  3115. * @param onProgress event that fires when loading progress has occured
  3116. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3117. */
  3118. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress) {
  3119. var _this = this;
  3120. return new Promise(function (resolve, reject) {
  3121. _this._importMeshAsync(meshesNames, scene, data, rootUrl, forAssetContainer, function (meshes, skeletons) {
  3122. resolve({
  3123. meshes: meshes,
  3124. particleSystems: [],
  3125. skeletons: skeletons,
  3126. animationGroups: [],
  3127. lights: [],
  3128. transformNodes: []
  3129. });
  3130. }, onProgress, function (message) {
  3131. reject(new Error(message));
  3132. });
  3133. });
  3134. };
  3135. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3136. var _this = this;
  3137. scene.useRightHandedSystem = true;
  3138. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3139. // Load runtime extensios
  3140. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3141. // Create nodes
  3142. _this._createNodes(gltfRuntime);
  3143. // Load buffers, shaders, materials, etc.
  3144. _this._loadBuffersAsync(gltfRuntime, function () {
  3145. _this._loadShadersAsync(gltfRuntime, function () {
  3146. importMaterials(gltfRuntime);
  3147. postLoad(gltfRuntime);
  3148. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3149. onSuccess();
  3150. }
  3151. });
  3152. });
  3153. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3154. onSuccess();
  3155. }
  3156. }, onError);
  3157. }, onError);
  3158. };
  3159. /**
  3160. * Imports all objects from a loaded gltf file and adds them to the scene
  3161. * @param scene the scene the objects should be added to
  3162. * @param data gltf data containing information of the meshes in a loaded file
  3163. * @param rootUrl root url to load from
  3164. * @param onProgress event that fires when loading progress has occured
  3165. * @returns a promise which completes when objects have been loaded to the scene
  3166. */
  3167. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3168. var _this = this;
  3169. return new Promise(function (resolve, reject) {
  3170. _this._loadAsync(scene, data, rootUrl, false, function () {
  3171. resolve();
  3172. }, onProgress, function (message) {
  3173. reject(new Error(message));
  3174. });
  3175. });
  3176. };
  3177. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3178. var hasShaders = false;
  3179. var processShader = function (sha, shader) {
  3180. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3181. if (shaderString instanceof ArrayBuffer) {
  3182. return;
  3183. }
  3184. gltfRuntime.loadedShaderCount++;
  3185. if (shaderString) {
  3186. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3187. }
  3188. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3189. onload();
  3190. }
  3191. }, function () {
  3192. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3193. });
  3194. };
  3195. for (var sha in gltfRuntime.shaders) {
  3196. hasShaders = true;
  3197. var shader = gltfRuntime.shaders[sha];
  3198. if (shader) {
  3199. processShader.bind(this, sha, shader)();
  3200. }
  3201. else {
  3202. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3203. }
  3204. }
  3205. if (!hasShaders) {
  3206. onload();
  3207. }
  3208. };
  3209. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3210. var hasBuffers = false;
  3211. var processBuffer = function (buf, buffer) {
  3212. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3213. gltfRuntime.loadedBufferCount++;
  3214. if (bufferView) {
  3215. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3216. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3217. }
  3218. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3219. }
  3220. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3221. onLoad();
  3222. }
  3223. }, function () {
  3224. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3225. });
  3226. };
  3227. for (var buf in gltfRuntime.buffers) {
  3228. hasBuffers = true;
  3229. var buffer = gltfRuntime.buffers[buf];
  3230. if (buffer) {
  3231. processBuffer.bind(this, buf, buffer)();
  3232. }
  3233. else {
  3234. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3235. }
  3236. }
  3237. if (!hasBuffers) {
  3238. onLoad();
  3239. }
  3240. };
  3241. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3242. var currentScene = gltfRuntime.currentScene;
  3243. if (currentScene) {
  3244. // Only one scene even if multiple scenes are defined
  3245. for (var i = 0; i < currentScene.nodes.length; i++) {
  3246. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3247. }
  3248. }
  3249. else {
  3250. // Load all scenes
  3251. for (var thing in gltfRuntime.scenes) {
  3252. currentScene = gltfRuntime.scenes[thing];
  3253. for (var i = 0; i < currentScene.nodes.length; i++) {
  3254. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3255. }
  3256. }
  3257. }
  3258. };
  3259. GLTFLoader.Extensions = {};
  3260. return GLTFLoader;
  3261. }());
  3262. /** @hidden */
  3263. var GLTFLoaderExtension = /** @class */ (function () {
  3264. function GLTFLoaderExtension(name) {
  3265. this._name = name;
  3266. }
  3267. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3268. get: function () {
  3269. return this._name;
  3270. },
  3271. enumerable: true,
  3272. configurable: true
  3273. });
  3274. /**
  3275. * Defines an override for loading the runtime
  3276. * Return true to stop further extensions from loading the runtime
  3277. */
  3278. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3279. return false;
  3280. };
  3281. /**
  3282. * Defines an onverride for creating gltf runtime
  3283. * Return true to stop further extensions from creating the runtime
  3284. */
  3285. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3286. return false;
  3287. };
  3288. /**
  3289. * Defines an override for loading buffers
  3290. * Return true to stop further extensions from loading this buffer
  3291. */
  3292. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3293. return false;
  3294. };
  3295. /**
  3296. * Defines an override for loading texture buffers
  3297. * Return true to stop further extensions from loading this texture data
  3298. */
  3299. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3300. return false;
  3301. };
  3302. /**
  3303. * Defines an override for creating textures
  3304. * Return true to stop further extensions from loading this texture
  3305. */
  3306. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3307. return false;
  3308. };
  3309. /**
  3310. * Defines an override for loading shader strings
  3311. * Return true to stop further extensions from loading this shader data
  3312. */
  3313. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3314. return false;
  3315. };
  3316. /**
  3317. * Defines an override for loading materials
  3318. * Return true to stop further extensions from loading this material
  3319. */
  3320. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3321. return false;
  3322. };
  3323. // ---------
  3324. // Utilities
  3325. // ---------
  3326. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3327. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3328. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3329. }, function () {
  3330. setTimeout(function () {
  3331. if (!onSuccess) {
  3332. return;
  3333. }
  3334. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3335. });
  3336. });
  3337. };
  3338. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3339. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3340. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3341. }, function () {
  3342. setTimeout(function () {
  3343. onSuccess();
  3344. });
  3345. });
  3346. };
  3347. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3348. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3349. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3350. }, function () {
  3351. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3352. });
  3353. };
  3354. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3355. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3356. if (buffer) {
  3357. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3358. }
  3359. }, onError);
  3360. };
  3361. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3362. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3363. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3364. }, function () {
  3365. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3366. });
  3367. };
  3368. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3369. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3370. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3371. }, function () {
  3372. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3373. });
  3374. };
  3375. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3376. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3377. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3378. }, function () {
  3379. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3380. });
  3381. };
  3382. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3383. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3384. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3385. }, function () {
  3386. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3387. });
  3388. };
  3389. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3390. for (var extensionName in GLTFLoader.Extensions) {
  3391. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3392. if (func(loaderExtension)) {
  3393. return;
  3394. }
  3395. }
  3396. defaultFunc();
  3397. };
  3398. return GLTFLoaderExtension;
  3399. }());
  3400. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3401. /***/ }),
  3402. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3403. /*!******************************************!*\
  3404. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3405. \******************************************/
  3406. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3407. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3408. "use strict";
  3409. __webpack_require__.r(__webpack_exports__);
  3410. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3411. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3412. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3413. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3414. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3415. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3416. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3417. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3418. /**
  3419. * Enums
  3420. * @hidden
  3421. */
  3422. var EComponentType;
  3423. (function (EComponentType) {
  3424. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3425. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3426. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3427. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3428. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3429. })(EComponentType || (EComponentType = {}));
  3430. /** @hidden */
  3431. var EShaderType;
  3432. (function (EShaderType) {
  3433. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3434. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3435. })(EShaderType || (EShaderType = {}));
  3436. /** @hidden */
  3437. var EParameterType;
  3438. (function (EParameterType) {
  3439. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3440. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3441. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3442. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3443. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3444. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3445. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3446. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3447. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3448. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3449. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3450. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3451. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3452. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3453. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3454. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3455. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3456. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3457. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3458. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3459. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3460. })(EParameterType || (EParameterType = {}));
  3461. /** @hidden */
  3462. var ETextureWrapMode;
  3463. (function (ETextureWrapMode) {
  3464. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3465. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3466. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3467. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3468. /** @hidden */
  3469. var ETextureFilterType;
  3470. (function (ETextureFilterType) {
  3471. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3472. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3473. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3474. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3475. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3476. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3477. })(ETextureFilterType || (ETextureFilterType = {}));
  3478. /** @hidden */
  3479. var ETextureFormat;
  3480. (function (ETextureFormat) {
  3481. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3482. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3483. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3484. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3485. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3486. })(ETextureFormat || (ETextureFormat = {}));
  3487. /** @hidden */
  3488. var ECullingType;
  3489. (function (ECullingType) {
  3490. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3491. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3492. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3493. })(ECullingType || (ECullingType = {}));
  3494. /** @hidden */
  3495. var EBlendingFunction;
  3496. (function (EBlendingFunction) {
  3497. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3498. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3499. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3500. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3501. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3502. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3503. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3504. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3505. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3506. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3507. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3508. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3509. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3510. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3511. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3512. })(EBlendingFunction || (EBlendingFunction = {}));
  3513. /***/ }),
  3514. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3515. /*!*************************************!*\
  3516. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3517. \*************************************/
  3518. /*! exports provided: GLTFUtils */
  3519. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3520. "use strict";
  3521. __webpack_require__.r(__webpack_exports__);
  3522. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3523. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3524. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3525. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  3526. /**
  3527. * Utils functions for GLTF
  3528. * @hidden
  3529. */
  3530. var GLTFUtils = /** @class */ (function () {
  3531. function GLTFUtils() {
  3532. }
  3533. /**
  3534. * Sets the given "parameter" matrix
  3535. * @param scene: the Scene object
  3536. * @param source: the source node where to pick the matrix
  3537. * @param parameter: the GLTF technique parameter
  3538. * @param uniformName: the name of the shader's uniform
  3539. * @param shaderMaterial: the shader material
  3540. */
  3541. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3542. var mat = null;
  3543. if (parameter.semantic === "MODEL") {
  3544. mat = source.getWorldMatrix();
  3545. }
  3546. else if (parameter.semantic === "PROJECTION") {
  3547. mat = scene.getProjectionMatrix();
  3548. }
  3549. else if (parameter.semantic === "VIEW") {
  3550. mat = scene.getViewMatrix();
  3551. }
  3552. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3553. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3554. }
  3555. else if (parameter.semantic === "MODELVIEW") {
  3556. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3557. }
  3558. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3559. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3560. }
  3561. else if (parameter.semantic === "MODELINVERSE") {
  3562. mat = source.getWorldMatrix().invert();
  3563. }
  3564. else if (parameter.semantic === "VIEWINVERSE") {
  3565. mat = scene.getViewMatrix().invert();
  3566. }
  3567. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3568. mat = scene.getProjectionMatrix().invert();
  3569. }
  3570. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3571. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3572. }
  3573. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3574. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3575. }
  3576. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3577. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3578. }
  3579. else {
  3580. debugger;
  3581. }
  3582. if (mat) {
  3583. switch (parameter.type) {
  3584. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3585. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3586. break;
  3587. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3588. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3589. break;
  3590. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3591. shaderMaterial.setMatrix(uniformName, mat);
  3592. break;
  3593. default: break;
  3594. }
  3595. }
  3596. };
  3597. /**
  3598. * Sets the given "parameter" matrix
  3599. * @param shaderMaterial: the shader material
  3600. * @param uniform: the name of the shader's uniform
  3601. * @param value: the value of the uniform
  3602. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3603. */
  3604. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3605. switch (type) {
  3606. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3607. shaderMaterial.setFloat(uniform, value);
  3608. return true;
  3609. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3610. shaderMaterial.setVector2(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3611. return true;
  3612. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3613. shaderMaterial.setVector3(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3614. return true;
  3615. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3616. shaderMaterial.setVector4(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3617. return true;
  3618. default: return false;
  3619. }
  3620. };
  3621. /**
  3622. * Returns the wrap mode of the texture
  3623. * @param mode: the mode value
  3624. */
  3625. GLTFUtils.GetWrapMode = function (mode) {
  3626. switch (mode) {
  3627. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3628. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3629. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3630. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3631. }
  3632. };
  3633. /**
  3634. * Returns the byte stride giving an accessor
  3635. * @param accessor: the GLTF accessor objet
  3636. */
  3637. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3638. // Needs this function since "byteStride" isn't requiered in glTF format
  3639. var type = accessor.type;
  3640. switch (type) {
  3641. case "VEC2": return 2;
  3642. case "VEC3": return 3;
  3643. case "VEC4": return 4;
  3644. case "MAT2": return 4;
  3645. case "MAT3": return 9;
  3646. case "MAT4": return 16;
  3647. default: return 1;
  3648. }
  3649. };
  3650. /**
  3651. * Returns the texture filter mode giving a mode value
  3652. * @param mode: the filter mode value
  3653. */
  3654. GLTFUtils.GetTextureFilterMode = function (mode) {
  3655. switch (mode) {
  3656. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3657. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3658. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3659. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3660. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3661. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3662. }
  3663. };
  3664. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3665. var byteOffset = bufferView.byteOffset + byteOffset;
  3666. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3667. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3668. throw new Error("Buffer access is out of range");
  3669. }
  3670. var buffer = loadedBufferView.buffer;
  3671. byteOffset += loadedBufferView.byteOffset;
  3672. switch (componentType) {
  3673. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3674. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3675. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3676. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3677. default: return new Float32Array(buffer, byteOffset, byteLength);
  3678. }
  3679. };
  3680. /**
  3681. * Returns a buffer from its accessor
  3682. * @param gltfRuntime: the GLTF runtime
  3683. * @param accessor: the GLTF accessor
  3684. */
  3685. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3686. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3687. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3688. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3689. };
  3690. /**
  3691. * Decodes a buffer view into a string
  3692. * @param view: the buffer view
  3693. */
  3694. GLTFUtils.DecodeBufferToText = function (view) {
  3695. var result = "";
  3696. var length = view.byteLength;
  3697. for (var i = 0; i < length; ++i) {
  3698. result += String.fromCharCode(view[i]);
  3699. }
  3700. return result;
  3701. };
  3702. /**
  3703. * Returns the default material of gltf. Related to
  3704. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3705. * @param scene: the Babylon.js scene
  3706. */
  3707. GLTFUtils.GetDefaultMaterial = function (scene) {
  3708. if (!GLTFUtils._DefaultMaterial) {
  3709. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3710. "precision highp float;",
  3711. "",
  3712. "uniform mat4 worldView;",
  3713. "uniform mat4 projection;",
  3714. "",
  3715. "attribute vec3 position;",
  3716. "",
  3717. "void main(void)",
  3718. "{",
  3719. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3720. "}"
  3721. ].join("\n");
  3722. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3723. "precision highp float;",
  3724. "",
  3725. "uniform vec4 u_emission;",
  3726. "",
  3727. "void main(void)",
  3728. "{",
  3729. " gl_FragColor = u_emission;",
  3730. "}"
  3731. ].join("\n");
  3732. var shaderPath = {
  3733. vertex: "GLTFDefaultMaterial",
  3734. fragment: "GLTFDefaultMaterial"
  3735. };
  3736. var options = {
  3737. attributes: ["position"],
  3738. uniforms: ["worldView", "projection", "u_emission"],
  3739. samplers: new Array(),
  3740. needAlphaBlending: false
  3741. };
  3742. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3743. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3744. }
  3745. return GLTFUtils._DefaultMaterial;
  3746. };
  3747. // The GLTF default material
  3748. GLTFUtils._DefaultMaterial = null;
  3749. return GLTFUtils;
  3750. }());
  3751. /***/ }),
  3752. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3753. /*!**************************************************!*\
  3754. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3755. \**************************************************/
  3756. /*! exports provided: GLTFMaterialsCommonExtension */
  3757. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3758. "use strict";
  3759. __webpack_require__.r(__webpack_exports__);
  3760. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3761. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3762. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3763. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3764. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__);
  3765. /** @hidden */
  3766. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3767. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3768. function GLTFMaterialsCommonExtension() {
  3769. return _super.call(this, "KHR_materials_common") || this;
  3770. }
  3771. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3772. if (!gltfRuntime.extensions) {
  3773. return false;
  3774. }
  3775. var extension = gltfRuntime.extensions[this.name];
  3776. if (!extension) {
  3777. return false;
  3778. }
  3779. // Create lights
  3780. var lights = extension.lights;
  3781. if (lights) {
  3782. for (var thing in lights) {
  3783. var light = lights[thing];
  3784. switch (light.type) {
  3785. case "ambient":
  3786. var ambientLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["HemisphericLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 1, 0), gltfRuntime.scene);
  3787. var ambient = light.ambient;
  3788. if (ambient) {
  3789. ambientLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3790. }
  3791. break;
  3792. case "point":
  3793. var pointLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["PointLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](10, 10, 10), gltfRuntime.scene);
  3794. var point = light.point;
  3795. if (point) {
  3796. pointLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3797. }
  3798. break;
  3799. case "directional":
  3800. var dirLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["DirectionalLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), gltfRuntime.scene);
  3801. var directional = light.directional;
  3802. if (directional) {
  3803. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3804. }
  3805. break;
  3806. case "spot":
  3807. var spot = light.spot;
  3808. if (spot) {
  3809. var spotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["SpotLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 10, 0), new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
  3810. spotLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3811. }
  3812. break;
  3813. default:
  3814. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3815. break;
  3816. }
  3817. }
  3818. }
  3819. return false;
  3820. };
  3821. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3822. var material = gltfRuntime.materials[id];
  3823. if (!material || !material.extensions) {
  3824. return false;
  3825. }
  3826. var extension = material.extensions[this.name];
  3827. if (!extension) {
  3828. return false;
  3829. }
  3830. var standardMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3831. standardMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3832. if (extension.technique === "CONSTANT") {
  3833. standardMaterial.disableLighting = true;
  3834. }
  3835. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3836. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3837. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3838. // Ambient
  3839. if (typeof extension.values.ambient === "string") {
  3840. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3841. }
  3842. else {
  3843. standardMaterial.ambientColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3844. }
  3845. // Diffuse
  3846. if (typeof extension.values.diffuse === "string") {
  3847. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3848. }
  3849. else {
  3850. standardMaterial.diffuseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3851. }
  3852. // Emission
  3853. if (typeof extension.values.emission === "string") {
  3854. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3855. }
  3856. else {
  3857. standardMaterial.emissiveColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3858. }
  3859. // Specular
  3860. if (typeof extension.values.specular === "string") {
  3861. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3862. }
  3863. else {
  3864. standardMaterial.specularColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3865. }
  3866. return true;
  3867. };
  3868. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3869. // Create buffer from texture url
  3870. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3871. // Create texture from buffer
  3872. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3873. }, onError);
  3874. };
  3875. return GLTFMaterialsCommonExtension;
  3876. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3877. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3878. /***/ }),
  3879. /***/ "./glTF/1.0/index.ts":
  3880. /*!***************************!*\
  3881. !*** ./glTF/1.0/index.ts ***!
  3882. \***************************/
  3883. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3884. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3885. "use strict";
  3886. __webpack_require__.r(__webpack_exports__);
  3887. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3888. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3889. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3890. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3891. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3892. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3893. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3894. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3895. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3896. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3897. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3898. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3899. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3900. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3901. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3902. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3903. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3904. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3905. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3906. /***/ }),
  3907. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3908. /*!*******************************************************!*\
  3909. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3910. \*******************************************************/
  3911. /*! exports provided: EXT_lights_image_based */
  3912. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3913. "use strict";
  3914. __webpack_require__.r(__webpack_exports__);
  3915. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3916. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  3917. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3918. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3919. var NAME = "EXT_lights_image_based";
  3920. /**
  3921. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3922. */
  3923. var EXT_lights_image_based = /** @class */ (function () {
  3924. /** @hidden */
  3925. function EXT_lights_image_based(loader) {
  3926. /**
  3927. * The name of this extension.
  3928. */
  3929. this.name = NAME;
  3930. this._loader = loader;
  3931. this.enabled = this._loader.isExtensionUsed(NAME);
  3932. }
  3933. /** @hidden */
  3934. EXT_lights_image_based.prototype.dispose = function () {
  3935. delete this._loader;
  3936. delete this._lights;
  3937. };
  3938. /** @hidden */
  3939. EXT_lights_image_based.prototype.onLoading = function () {
  3940. var extensions = this._loader.gltf.extensions;
  3941. if (extensions && extensions[this.name]) {
  3942. var extension = extensions[this.name];
  3943. this._lights = extension.lights;
  3944. }
  3945. };
  3946. /** @hidden */
  3947. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3948. var _this = this;
  3949. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3950. var promises = new Array();
  3951. promises.push(_this._loader.loadSceneAsync(context, scene));
  3952. _this._loader.logOpen("" + extensionContext);
  3953. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3954. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3955. _this._loader.babylonScene.environmentTexture = texture;
  3956. }));
  3957. _this._loader.logClose();
  3958. return Promise.all(promises).then(function () { });
  3959. });
  3960. };
  3961. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3962. var _this = this;
  3963. if (!light._loaded) {
  3964. var promises = new Array();
  3965. this._loader.logOpen("" + context);
  3966. var imageData_1 = new Array(light.specularImages.length);
  3967. var _loop_1 = function (mipmap) {
  3968. var faces = light.specularImages[mipmap];
  3969. imageData_1[mipmap] = new Array(faces.length);
  3970. var _loop_2 = function (face) {
  3971. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  3972. this_1._loader.logOpen("" + specularImageContext);
  3973. var index = faces[face];
  3974. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  3975. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  3976. imageData_1[mipmap][face] = data;
  3977. }));
  3978. this_1._loader.logClose();
  3979. };
  3980. for (var face = 0; face < faces.length; face++) {
  3981. _loop_2(face);
  3982. }
  3983. };
  3984. var this_1 = this;
  3985. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  3986. _loop_1(mipmap);
  3987. }
  3988. this._loader.logClose();
  3989. light._loaded = Promise.all(promises).then(function () {
  3990. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  3991. babylonTexture.name = light.name || "environment";
  3992. light._babylonTexture = babylonTexture;
  3993. if (light.intensity != undefined) {
  3994. babylonTexture.level = light.intensity;
  3995. }
  3996. if (light.rotation) {
  3997. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  3998. // Invert the rotation so that positive rotation is counter-clockwise.
  3999. if (!_this._loader.babylonScene.useRightHandedSystem) {
  4000. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  4001. }
  4002. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  4003. }
  4004. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  4005. sphericalHarmonics.scaleInPlace(light.intensity);
  4006. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  4007. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  4008. // Compute the lod generation scale to fit exactly to the number of levels available.
  4009. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  4010. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  4011. });
  4012. }
  4013. return light._loaded.then(function () {
  4014. return light._babylonTexture;
  4015. });
  4016. };
  4017. return EXT_lights_image_based;
  4018. }());
  4019. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  4020. /***/ }),
  4021. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  4022. /*!********************************************************!*\
  4023. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  4024. \********************************************************/
  4025. /*! exports provided: EXT_mesh_gpu_instancing */
  4026. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4027. "use strict";
  4028. __webpack_require__.r(__webpack_exports__);
  4029. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  4030. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4031. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4032. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4033. var NAME = "EXT_mesh_gpu_instancing";
  4034. /**
  4035. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  4036. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  4037. * !!! Experimental Extension Subject to Changes !!!
  4038. */
  4039. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  4040. /** @hidden */
  4041. function EXT_mesh_gpu_instancing(loader) {
  4042. /**
  4043. * The name of this extension.
  4044. */
  4045. this.name = NAME;
  4046. this._loader = loader;
  4047. this.enabled = this._loader.isExtensionUsed(NAME);
  4048. }
  4049. /** @hidden */
  4050. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  4051. delete this._loader;
  4052. };
  4053. /** @hidden */
  4054. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  4055. var _this = this;
  4056. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4057. _this._loader._disableInstancedMesh++;
  4058. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  4059. _this._loader._disableInstancedMesh--;
  4060. if (!node._primitiveBabylonMeshes) {
  4061. return promise;
  4062. }
  4063. var promises = new Array();
  4064. var instanceCount = 0;
  4065. var loadAttribute = function (attribute) {
  4066. if (extension.attributes[attribute] == undefined) {
  4067. promises.push(Promise.resolve(null));
  4068. return;
  4069. }
  4070. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  4071. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  4072. if (instanceCount === 0) {
  4073. instanceCount = accessor.count;
  4074. }
  4075. else if (instanceCount !== accessor.count) {
  4076. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  4077. }
  4078. };
  4079. loadAttribute("TRANSLATION");
  4080. loadAttribute("ROTATION");
  4081. loadAttribute("SCALE");
  4082. return promise.then(function (babylonTransformNode) {
  4083. return Promise.all(promises).then(function (_a) {
  4084. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  4085. var matrices = new Float32Array(instanceCount * 16);
  4086. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  4087. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  4088. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  4089. for (var i = 0; i < instanceCount; ++i) {
  4090. translationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(translationBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0]);
  4091. rotationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArrayToRef(rotationBuffer, i * 4, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0]);
  4092. scaleBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(scaleBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1]);
  4093. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0]);
  4094. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  4095. }
  4096. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  4097. var babylonMesh = _b[_i];
  4098. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  4099. }
  4100. return babylonTransformNode;
  4101. });
  4102. });
  4103. });
  4104. };
  4105. return EXT_mesh_gpu_instancing;
  4106. }());
  4107. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  4108. /***/ }),
  4109. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  4110. /*!*************************************************!*\
  4111. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  4112. \*************************************************/
  4113. /*! exports provided: ExtrasAsMetadata */
  4114. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4115. "use strict";
  4116. __webpack_require__.r(__webpack_exports__);
  4117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  4118. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4119. var NAME = "ExtrasAsMetadata";
  4120. /**
  4121. * Store glTF extras (if present) in BJS objects' metadata
  4122. */
  4123. var ExtrasAsMetadata = /** @class */ (function () {
  4124. /** @hidden */
  4125. function ExtrasAsMetadata(loader) {
  4126. /**
  4127. * The name of this extension.
  4128. */
  4129. this.name = NAME;
  4130. /**
  4131. * Defines whether this extension is enabled.
  4132. */
  4133. this.enabled = true;
  4134. this._loader = loader;
  4135. }
  4136. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  4137. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  4138. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  4139. var gltf = (metadata.gltf = metadata.gltf || {});
  4140. gltf.extras = gltfProp.extras;
  4141. }
  4142. };
  4143. /** @hidden */
  4144. ExtrasAsMetadata.prototype.dispose = function () {
  4145. delete this._loader;
  4146. };
  4147. /** @hidden */
  4148. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4149. var _this = this;
  4150. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4151. _this._assignExtras(babylonTransformNode, node);
  4152. assign(babylonTransformNode);
  4153. });
  4154. };
  4155. /** @hidden */
  4156. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4157. var _this = this;
  4158. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4159. _this._assignExtras(babylonCamera, camera);
  4160. assign(babylonCamera);
  4161. });
  4162. };
  4163. /** @hidden */
  4164. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4165. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4166. this._assignExtras(babylonMaterial, material);
  4167. return babylonMaterial;
  4168. };
  4169. return ExtrasAsMetadata;
  4170. }());
  4171. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4172. /***/ }),
  4173. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4174. /*!***********************************************************!*\
  4175. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4176. \***********************************************************/
  4177. /*! exports provided: KHR_draco_mesh_compression */
  4178. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4179. "use strict";
  4180. __webpack_require__.r(__webpack_exports__);
  4181. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4182. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  4183. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4184. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4185. var NAME = "KHR_draco_mesh_compression";
  4186. /**
  4187. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4188. */
  4189. var KHR_draco_mesh_compression = /** @class */ (function () {
  4190. /** @hidden */
  4191. function KHR_draco_mesh_compression(loader) {
  4192. /**
  4193. * The name of this extension.
  4194. */
  4195. this.name = NAME;
  4196. this._loader = loader;
  4197. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4198. }
  4199. /** @hidden */
  4200. KHR_draco_mesh_compression.prototype.dispose = function () {
  4201. delete this.dracoCompression;
  4202. delete this._loader;
  4203. };
  4204. /** @hidden */
  4205. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4206. var _this = this;
  4207. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4208. if (primitive.mode != undefined) {
  4209. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4210. primitive.mode !== 4 /* TRIANGLES */) {
  4211. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4212. }
  4213. // TODO: handle triangle strips
  4214. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4215. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4216. }
  4217. }
  4218. var attributes = {};
  4219. var loadAttribute = function (name, kind) {
  4220. var uniqueId = extension.attributes[name];
  4221. if (uniqueId == undefined) {
  4222. return;
  4223. }
  4224. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4225. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4226. babylonMesh._delayInfo.push(kind);
  4227. }
  4228. attributes[kind] = uniqueId;
  4229. };
  4230. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4231. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4232. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4233. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4234. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4235. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4236. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4237. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4238. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4239. if (!bufferView._dracoBabylonGeometry) {
  4240. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4241. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4242. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4243. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4244. babylonVertexData.applyToGeometry(babylonGeometry);
  4245. return babylonGeometry;
  4246. }).catch(function (error) {
  4247. throw new Error(context + ": " + error.message);
  4248. });
  4249. });
  4250. }
  4251. return bufferView._dracoBabylonGeometry;
  4252. });
  4253. };
  4254. return KHR_draco_mesh_compression;
  4255. }());
  4256. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4257. /***/ }),
  4258. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4259. /*!****************************************************!*\
  4260. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4261. \****************************************************/
  4262. /*! exports provided: KHR_lights */
  4263. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4264. "use strict";
  4265. __webpack_require__.r(__webpack_exports__);
  4266. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4267. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4268. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4269. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4270. var NAME = "KHR_lights_punctual";
  4271. var LightType;
  4272. (function (LightType) {
  4273. LightType["DIRECTIONAL"] = "directional";
  4274. LightType["POINT"] = "point";
  4275. LightType["SPOT"] = "spot";
  4276. })(LightType || (LightType = {}));
  4277. /**
  4278. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  4279. */
  4280. var KHR_lights = /** @class */ (function () {
  4281. /** @hidden */
  4282. function KHR_lights(loader) {
  4283. /**
  4284. * The name of this extension.
  4285. */
  4286. this.name = NAME;
  4287. this._loader = loader;
  4288. this.enabled = this._loader.isExtensionUsed(NAME);
  4289. }
  4290. /** @hidden */
  4291. KHR_lights.prototype.dispose = function () {
  4292. delete this._loader;
  4293. delete this._lights;
  4294. };
  4295. /** @hidden */
  4296. KHR_lights.prototype.onLoading = function () {
  4297. var extensions = this._loader.gltf.extensions;
  4298. if (extensions && extensions[this.name]) {
  4299. var extension = extensions[this.name];
  4300. this._lights = extension.lights;
  4301. }
  4302. };
  4303. /** @hidden */
  4304. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4305. var _this = this;
  4306. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4307. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4308. var babylonLight;
  4309. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4310. var name = light.name || babylonMesh.name;
  4311. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  4312. switch (light.type) {
  4313. case LightType.DIRECTIONAL: {
  4314. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  4315. break;
  4316. }
  4317. case LightType.POINT: {
  4318. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  4319. break;
  4320. }
  4321. case LightType.SPOT: {
  4322. var babylonSpotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  4323. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4324. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4325. babylonLight = babylonSpotLight;
  4326. break;
  4327. }
  4328. default: {
  4329. _this._loader.babylonScene._blockEntityCollection = false;
  4330. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4331. }
  4332. }
  4333. _this._loader.babylonScene._blockEntityCollection = false;
  4334. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4335. babylonLight.diffuse = light.color ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4336. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4337. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4338. babylonLight.parent = babylonMesh;
  4339. _this._loader._babylonLights.push(babylonLight);
  4340. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4341. assign(babylonMesh);
  4342. });
  4343. });
  4344. };
  4345. return KHR_lights;
  4346. }());
  4347. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4348. /***/ }),
  4349. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4350. /*!********************************************************!*\
  4351. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4352. \********************************************************/
  4353. /*! exports provided: KHR_materials_clearcoat */
  4354. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4355. "use strict";
  4356. __webpack_require__.r(__webpack_exports__);
  4357. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4358. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4359. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4360. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4361. var NAME = "KHR_materials_clearcoat";
  4362. /**
  4363. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4364. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4365. * !!! Experimental Extension Subject to Changes !!!
  4366. */
  4367. var KHR_materials_clearcoat = /** @class */ (function () {
  4368. /** @hidden */
  4369. function KHR_materials_clearcoat(loader) {
  4370. /**
  4371. * The name of this extension.
  4372. */
  4373. this.name = NAME;
  4374. /**
  4375. * Defines a number that determines the order the extensions are applied.
  4376. */
  4377. this.order = 190;
  4378. this._loader = loader;
  4379. this.enabled = this._loader.isExtensionUsed(NAME);
  4380. }
  4381. /** @hidden */
  4382. KHR_materials_clearcoat.prototype.dispose = function () {
  4383. delete this._loader;
  4384. };
  4385. /** @hidden */
  4386. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4387. var _this = this;
  4388. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4389. var promises = new Array();
  4390. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4391. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4392. return Promise.all(promises).then(function () { });
  4393. });
  4394. };
  4395. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4396. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4397. throw new Error(context + ": Material type not supported");
  4398. }
  4399. var promises = new Array();
  4400. babylonMaterial.clearCoat.isEnabled = true;
  4401. if (properties.clearcoatFactor != undefined) {
  4402. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4403. }
  4404. else {
  4405. babylonMaterial.clearCoat.intensity = 0;
  4406. }
  4407. if (properties.clearcoatTexture) {
  4408. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4409. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4410. babylonMaterial.clearCoat.texture = texture;
  4411. }));
  4412. }
  4413. if (properties.clearcoatRoughnessFactor != undefined) {
  4414. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4415. }
  4416. else {
  4417. babylonMaterial.clearCoat.roughness = 0;
  4418. }
  4419. if (properties.clearcoatRoughnessTexture) {
  4420. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4421. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4422. babylonMaterial.clearCoat.texture = texture;
  4423. }));
  4424. }
  4425. if (properties.clearcoatNormalTexture) {
  4426. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4427. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4428. babylonMaterial.clearCoat.bumpTexture = texture;
  4429. }));
  4430. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4431. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4432. if (properties.clearcoatNormalTexture.scale != undefined) {
  4433. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4434. }
  4435. }
  4436. return Promise.all(promises).then(function () { });
  4437. };
  4438. return KHR_materials_clearcoat;
  4439. }());
  4440. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4441. /***/ }),
  4442. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  4443. /*!**************************************************!*\
  4444. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  4445. \**************************************************/
  4446. /*! exports provided: KHR_materials_ior */
  4447. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4448. "use strict";
  4449. __webpack_require__.r(__webpack_exports__);
  4450. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  4451. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4452. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4453. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4454. var NAME = "KHR_materials_ior";
  4455. /**
  4456. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  4457. * !!! Experimental Extension Subject to Changes !!!
  4458. */
  4459. var KHR_materials_ior = /** @class */ (function () {
  4460. /** @hidden */
  4461. function KHR_materials_ior(loader) {
  4462. /**
  4463. * The name of this extension.
  4464. */
  4465. this.name = NAME;
  4466. /**
  4467. * Defines a number that determines the order the extensions are applied.
  4468. */
  4469. this.order = 180;
  4470. this._loader = loader;
  4471. this.enabled = this._loader.isExtensionUsed(NAME);
  4472. }
  4473. /** @hidden */
  4474. KHR_materials_ior.prototype.dispose = function () {
  4475. delete this._loader;
  4476. };
  4477. /** @hidden */
  4478. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4479. var _this = this;
  4480. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4481. var promises = new Array();
  4482. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4483. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  4484. return Promise.all(promises).then(function () { });
  4485. });
  4486. };
  4487. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  4488. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4489. throw new Error(context + ": Material type not supported");
  4490. }
  4491. if (properties.ior !== undefined) {
  4492. babylonMaterial.indexOfRefraction = properties.ior;
  4493. }
  4494. else {
  4495. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  4496. }
  4497. return Promise.resolve();
  4498. };
  4499. /**
  4500. * Default ior Value from the spec.
  4501. */
  4502. KHR_materials_ior._DEFAULT_IOR = 1.5;
  4503. return KHR_materials_ior;
  4504. }());
  4505. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  4506. /***/ }),
  4507. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4508. /*!********************************************************************!*\
  4509. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4510. \********************************************************************/
  4511. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4512. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4513. "use strict";
  4514. __webpack_require__.r(__webpack_exports__);
  4515. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4516. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4517. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4518. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4519. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4520. /**
  4521. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4522. */
  4523. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4524. /** @hidden */
  4525. function KHR_materials_pbrSpecularGlossiness(loader) {
  4526. /**
  4527. * The name of this extension.
  4528. */
  4529. this.name = NAME;
  4530. /**
  4531. * Defines a number that determines the order the extensions are applied.
  4532. */
  4533. this.order = 200;
  4534. this._loader = loader;
  4535. this.enabled = this._loader.isExtensionUsed(NAME);
  4536. }
  4537. /** @hidden */
  4538. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4539. delete this._loader;
  4540. };
  4541. /** @hidden */
  4542. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4543. var _this = this;
  4544. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4545. var promises = new Array();
  4546. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4547. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4548. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4549. return Promise.all(promises).then(function () { });
  4550. });
  4551. };
  4552. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4553. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4554. throw new Error(context + ": Material type not supported");
  4555. }
  4556. var promises = new Array();
  4557. babylonMaterial.metallic = null;
  4558. babylonMaterial.roughness = null;
  4559. if (properties.diffuseFactor) {
  4560. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4561. babylonMaterial.alpha = properties.diffuseFactor[3];
  4562. }
  4563. else {
  4564. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4565. }
  4566. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4567. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4568. if (properties.diffuseTexture) {
  4569. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4570. texture.name = babylonMaterial.name + " (Diffuse)";
  4571. babylonMaterial.albedoTexture = texture;
  4572. }));
  4573. }
  4574. if (properties.specularGlossinessTexture) {
  4575. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4576. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4577. babylonMaterial.reflectivityTexture = texture;
  4578. }));
  4579. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4580. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4581. }
  4582. return Promise.all(promises).then(function () { });
  4583. };
  4584. return KHR_materials_pbrSpecularGlossiness;
  4585. }());
  4586. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4587. /***/ }),
  4588. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4589. /*!****************************************************!*\
  4590. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4591. \****************************************************/
  4592. /*! exports provided: KHR_materials_sheen */
  4593. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4594. "use strict";
  4595. __webpack_require__.r(__webpack_exports__);
  4596. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4597. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4598. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4599. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4600. var NAME = "KHR_materials_sheen";
  4601. /**
  4602. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4603. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4604. * !!! Experimental Extension Subject to Changes !!!
  4605. */
  4606. var KHR_materials_sheen = /** @class */ (function () {
  4607. /** @hidden */
  4608. function KHR_materials_sheen(loader) {
  4609. /**
  4610. * The name of this extension.
  4611. */
  4612. this.name = NAME;
  4613. /**
  4614. * Defines a number that determines the order the extensions are applied.
  4615. */
  4616. this.order = 190;
  4617. this._loader = loader;
  4618. this.enabled = this._loader.isExtensionUsed(NAME);
  4619. }
  4620. /** @hidden */
  4621. KHR_materials_sheen.prototype.dispose = function () {
  4622. delete this._loader;
  4623. };
  4624. /** @hidden */
  4625. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4626. var _this = this;
  4627. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4628. var promises = new Array();
  4629. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4630. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4631. return Promise.all(promises).then(function () { });
  4632. });
  4633. };
  4634. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4635. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4636. throw new Error(context + ": Material type not supported");
  4637. }
  4638. var promises = new Array();
  4639. babylonMaterial.sheen.isEnabled = true;
  4640. if (properties.intensityFactor != undefined) {
  4641. babylonMaterial.sheen.intensity = properties.intensityFactor;
  4642. }
  4643. else {
  4644. babylonMaterial.sheen.intensity = 0;
  4645. }
  4646. if (properties.colorFactor != undefined) {
  4647. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  4648. }
  4649. if (properties.colorIntensityTexture) {
  4650. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  4651. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  4652. babylonMaterial.sheen.texture = texture;
  4653. }));
  4654. }
  4655. if (properties.roughnessFactor !== undefined) {
  4656. babylonMaterial.sheen.roughness = properties.roughnessFactor;
  4657. }
  4658. else {
  4659. babylonMaterial.sheen.roughness = 0;
  4660. }
  4661. babylonMaterial.sheen.albedoScaling = true;
  4662. return Promise.all(promises).then(function () { });
  4663. };
  4664. return KHR_materials_sheen;
  4665. }());
  4666. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4667. /***/ }),
  4668. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4669. /*!*******************************************************!*\
  4670. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4671. \*******************************************************/
  4672. /*! exports provided: KHR_materials_specular */
  4673. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4674. "use strict";
  4675. __webpack_require__.r(__webpack_exports__);
  4676. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4677. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4678. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4679. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4680. var NAME = "KHR_materials_specular";
  4681. /**
  4682. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  4683. * !!! Experimental Extension Subject to Changes !!!
  4684. */
  4685. var KHR_materials_specular = /** @class */ (function () {
  4686. /** @hidden */
  4687. function KHR_materials_specular(loader) {
  4688. /**
  4689. * The name of this extension.
  4690. */
  4691. this.name = NAME;
  4692. /**
  4693. * Defines a number that determines the order the extensions are applied.
  4694. */
  4695. this.order = 190;
  4696. this._loader = loader;
  4697. this.enabled = this._loader.isExtensionUsed(NAME);
  4698. }
  4699. /** @hidden */
  4700. KHR_materials_specular.prototype.dispose = function () {
  4701. delete this._loader;
  4702. };
  4703. /** @hidden */
  4704. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4705. var _this = this;
  4706. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4707. var promises = new Array();
  4708. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4709. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4710. return Promise.all(promises).then(function () { });
  4711. });
  4712. };
  4713. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4714. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4715. throw new Error(context + ": Material type not supported");
  4716. }
  4717. var promises = new Array();
  4718. if (properties.specularFactor !== undefined) {
  4719. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4720. }
  4721. if (properties.specularColorFactor !== undefined) {
  4722. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  4723. }
  4724. if (properties.specularTexture) {
  4725. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  4726. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  4727. babylonMaterial.metallicReflectanceTexture = texture;
  4728. }));
  4729. }
  4730. return Promise.all(promises).then(function () { });
  4731. };
  4732. return KHR_materials_specular;
  4733. }());
  4734. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4735. /***/ }),
  4736. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  4737. /*!***********************************************************!*\
  4738. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  4739. \***********************************************************/
  4740. /*! exports provided: KHR_materials_transmission */
  4741. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4742. "use strict";
  4743. __webpack_require__.r(__webpack_exports__);
  4744. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  4745. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4746. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4747. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4748. var NAME = "KHR_materials_transmission";
  4749. /**
  4750. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  4751. * !!! Experimental Extension Subject to Changes !!!
  4752. */
  4753. var KHR_materials_transmission = /** @class */ (function () {
  4754. /** @hidden */
  4755. function KHR_materials_transmission(loader) {
  4756. /**
  4757. * The name of this extension.
  4758. */
  4759. this.name = NAME;
  4760. /**
  4761. * Defines a number that determines the order the extensions are applied.
  4762. */
  4763. this.order = 175;
  4764. this._loader = loader;
  4765. this.enabled = this._loader.isExtensionUsed(NAME);
  4766. if (this.enabled) {
  4767. loader._parent.transparencyAsCoverage = true;
  4768. }
  4769. }
  4770. /** @hidden */
  4771. KHR_materials_transmission.prototype.dispose = function () {
  4772. delete this._loader;
  4773. };
  4774. /** @hidden */
  4775. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4776. var _this = this;
  4777. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4778. console.log(extensionContext);
  4779. var promises = new Array();
  4780. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4781. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4782. promises.push(_this._loadTransparentPropertiesAsync(context, material, babylonMaterial, extension));
  4783. return Promise.all(promises).then(function () { });
  4784. });
  4785. };
  4786. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  4787. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4788. throw new Error(context + ": Material type not supported");
  4789. }
  4790. var pbrMaterial = babylonMaterial;
  4791. // Enables "refraction" texture which represents transmitted light.
  4792. pbrMaterial.subSurface.isRefractionEnabled = true;
  4793. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  4794. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  4795. // Albedo colour will tint transmission.
  4796. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  4797. if (extension.transmissionFactor !== undefined) {
  4798. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  4799. }
  4800. else {
  4801. pbrMaterial.subSurface.refractionIntensity = 1.0;
  4802. }
  4803. if (extension.transmissionTexture) {
  4804. return this._loader.loadTextureInfoAsync(context, extension.transmissionTexture)
  4805. .then(function (texture) {
  4806. pbrMaterial.subSurface.thicknessTexture = texture;
  4807. pbrMaterial.subSurface.useMaskFromThicknessTexture = true;
  4808. });
  4809. }
  4810. else {
  4811. return Promise.resolve();
  4812. }
  4813. };
  4814. return KHR_materials_transmission;
  4815. }());
  4816. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  4817. /***/ }),
  4818. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  4819. /*!****************************************************!*\
  4820. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  4821. \****************************************************/
  4822. /*! exports provided: KHR_materials_unlit */
  4823. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4824. "use strict";
  4825. __webpack_require__.r(__webpack_exports__);
  4826. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  4827. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4828. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4829. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4830. var NAME = "KHR_materials_unlit";
  4831. /**
  4832. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4833. */
  4834. var KHR_materials_unlit = /** @class */ (function () {
  4835. /** @hidden */
  4836. function KHR_materials_unlit(loader) {
  4837. /**
  4838. * The name of this extension.
  4839. */
  4840. this.name = NAME;
  4841. /**
  4842. * Defines a number that determines the order the extensions are applied.
  4843. */
  4844. this.order = 210;
  4845. this._loader = loader;
  4846. this.enabled = this._loader.isExtensionUsed(NAME);
  4847. }
  4848. /** @hidden */
  4849. KHR_materials_unlit.prototype.dispose = function () {
  4850. delete this._loader;
  4851. };
  4852. /** @hidden */
  4853. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4854. var _this = this;
  4855. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  4856. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  4857. });
  4858. };
  4859. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  4860. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4861. throw new Error(context + ": Material type not supported");
  4862. }
  4863. var promises = new Array();
  4864. babylonMaterial.unlit = true;
  4865. var properties = material.pbrMetallicRoughness;
  4866. if (properties) {
  4867. if (properties.baseColorFactor) {
  4868. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  4869. babylonMaterial.alpha = properties.baseColorFactor[3];
  4870. }
  4871. else {
  4872. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4873. }
  4874. if (properties.baseColorTexture) {
  4875. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  4876. texture.name = babylonMaterial.name + " (Base Color)";
  4877. babylonMaterial.albedoTexture = texture;
  4878. }));
  4879. }
  4880. }
  4881. if (material.doubleSided) {
  4882. babylonMaterial.backFaceCulling = false;
  4883. babylonMaterial.twoSidedLighting = true;
  4884. }
  4885. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4886. return Promise.all(promises).then(function () { });
  4887. };
  4888. return KHR_materials_unlit;
  4889. }());
  4890. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  4891. /***/ }),
  4892. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  4893. /*!*******************************************************!*\
  4894. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  4895. \*******************************************************/
  4896. /*! exports provided: KHR_materials_variants */
  4897. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4898. "use strict";
  4899. __webpack_require__.r(__webpack_exports__);
  4900. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  4901. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4902. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/tools");
  4903. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  4904. var NAME = "KHR_materials_variants";
  4905. /**
  4906. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  4907. * !!! Experimental Extension Subject to Changes !!!
  4908. */
  4909. var KHR_materials_variants = /** @class */ (function () {
  4910. /** @hidden */
  4911. function KHR_materials_variants(loader) {
  4912. /**
  4913. * The name of this extension.
  4914. */
  4915. this.name = NAME;
  4916. this._loader = loader;
  4917. this.enabled = this._loader.isExtensionUsed(NAME);
  4918. }
  4919. /** @hidden */
  4920. KHR_materials_variants.prototype.dispose = function () {
  4921. delete this._loader;
  4922. };
  4923. /**
  4924. * Gets the list of available variant tag names for this asset.
  4925. * @param rootMesh The glTF root mesh
  4926. * @returns the list of all the variant names for this model
  4927. */
  4928. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  4929. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  4930. if (!extensionMetadata) {
  4931. return [];
  4932. }
  4933. return Object.keys(extensionMetadata.variants);
  4934. };
  4935. /**
  4936. * Select a variant given a variant tag name or a list of variant tag names.
  4937. * @param rootMesh The glTF root mesh
  4938. * @param variantName The variant name(s) to select.
  4939. */
  4940. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  4941. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  4942. if (!extensionMetadata) {
  4943. throw new Error("Cannot select variant on a glTF mesh that does not have the " + NAME + " extension");
  4944. }
  4945. var select = function (variantName) {
  4946. var entries = extensionMetadata.variants[variantName];
  4947. if (entries) {
  4948. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  4949. var entry = entries_1[_i];
  4950. entry.mesh.material = entry.material;
  4951. }
  4952. }
  4953. };
  4954. if (variantName instanceof Array) {
  4955. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  4956. var name_1 = variantName_1[_i];
  4957. select(name_1);
  4958. }
  4959. }
  4960. else {
  4961. select(variantName);
  4962. }
  4963. extensionMetadata.lastSelected = variantName;
  4964. };
  4965. /**
  4966. * Reset back to the original before selecting a variant.
  4967. * @param rootMesh The glTF root mesh
  4968. */
  4969. KHR_materials_variants.Reset = function (rootMesh) {
  4970. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  4971. if (!extensionMetadata) {
  4972. throw new Error("Cannot reset on a glTF mesh that does not have the " + NAME + " extension");
  4973. }
  4974. for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
  4975. var entry = _a[_i];
  4976. entry.mesh.material = entry.material;
  4977. }
  4978. extensionMetadata.lastSelected = null;
  4979. };
  4980. /**
  4981. * Gets the last selected variant tag name(s) or null if original.
  4982. * @param rootMesh The glTF root mesh
  4983. * @returns The selected variant tag name(s).
  4984. */
  4985. KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
  4986. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  4987. if (!extensionMetadata) {
  4988. throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the " + NAME + " extension");
  4989. }
  4990. return extensionMetadata.lastSelected;
  4991. };
  4992. KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
  4993. var _a, _b;
  4994. return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
  4995. };
  4996. /** @hidden */
  4997. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  4998. var _this = this;
  4999. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  5000. var promises = new Array();
  5001. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  5002. assign(babylonMesh);
  5003. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5004. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  5005. var root = _this._loader.rootBabylonMesh;
  5006. var metadata = (root.metadata = root.metadata || {});
  5007. var gltf = (metadata.gltf = metadata.gltf || {});
  5008. var extensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
  5009. // Store the original material.
  5010. extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });
  5011. // For each mapping, look at the tags and make a new entry for them.
  5012. var variants_1 = extensionMetadata.variants;
  5013. for (var _i = 0, _a = extension.mapping; _i < _a.length; _i++) {
  5014. var mapping = _a[_i];
  5015. var _loop_1 = function (tag) {
  5016. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  5017. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5018. variants_1[tag] = variants_1[tag] || [];
  5019. variants_1[tag].push({
  5020. mesh: babylonMesh,
  5021. material: babylonMaterial
  5022. });
  5023. }));
  5024. };
  5025. for (var _b = 0, _c = mapping.tags; _b < _c.length; _b++) {
  5026. var tag = _c[_b];
  5027. _loop_1(tag);
  5028. }
  5029. }
  5030. }
  5031. }));
  5032. return Promise.all(promises).then(function (_a) {
  5033. var babylonMesh = _a[0];
  5034. return babylonMesh;
  5035. });
  5036. });
  5037. };
  5038. return KHR_materials_variants;
  5039. }());
  5040. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  5041. /***/ }),
  5042. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  5043. /*!******************************************************!*\
  5044. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  5045. \******************************************************/
  5046. /*! exports provided: KHR_mesh_quantization */
  5047. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5048. "use strict";
  5049. __webpack_require__.r(__webpack_exports__);
  5050. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  5051. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5052. var NAME = "KHR_mesh_quantization";
  5053. /**
  5054. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  5055. */
  5056. var KHR_mesh_quantization = /** @class */ (function () {
  5057. /** @hidden */
  5058. function KHR_mesh_quantization(loader) {
  5059. /**
  5060. * The name of this extension.
  5061. */
  5062. this.name = NAME;
  5063. this.enabled = loader.isExtensionUsed(NAME);
  5064. }
  5065. /** @hidden */
  5066. KHR_mesh_quantization.prototype.dispose = function () {
  5067. };
  5068. return KHR_mesh_quantization;
  5069. }());
  5070. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  5071. /***/ }),
  5072. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  5073. /*!***************************************************!*\
  5074. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  5075. \***************************************************/
  5076. /*! exports provided: KHR_texture_basisu */
  5077. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5078. "use strict";
  5079. __webpack_require__.r(__webpack_exports__);
  5080. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  5081. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5082. var NAME = "KHR_texture_basisu";
  5083. /**
  5084. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  5085. * !!! Experimental Extension Subject to Changes !!!
  5086. */
  5087. var KHR_texture_basisu = /** @class */ (function () {
  5088. /** @hidden */
  5089. function KHR_texture_basisu(loader) {
  5090. /** The name of this extension. */
  5091. this.name = NAME;
  5092. this._loader = loader;
  5093. this.enabled = loader.isExtensionUsed(NAME);
  5094. }
  5095. /** @hidden */
  5096. KHR_texture_basisu.prototype.dispose = function () {
  5097. delete this._loader;
  5098. };
  5099. /** @hidden */
  5100. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  5101. var _this = this;
  5102. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  5103. var sampler = (texture.sampler == undefined ? _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].DefaultSampler : _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(context + "/sampler", _this._loader.gltf.samplers, texture.sampler));
  5104. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  5105. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  5106. babylonTexture.gammaSpace = false;
  5107. assign(babylonTexture);
  5108. });
  5109. });
  5110. };
  5111. return KHR_texture_basisu;
  5112. }());
  5113. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  5114. /***/ }),
  5115. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  5116. /*!******************************************************!*\
  5117. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  5118. \******************************************************/
  5119. /*! exports provided: KHR_texture_transform */
  5120. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5121. "use strict";
  5122. __webpack_require__.r(__webpack_exports__);
  5123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  5124. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  5125. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  5126. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5127. var NAME = "KHR_texture_transform";
  5128. /**
  5129. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  5130. */
  5131. var KHR_texture_transform = /** @class */ (function () {
  5132. /** @hidden */
  5133. function KHR_texture_transform(loader) {
  5134. /**
  5135. * The name of this extension.
  5136. */
  5137. this.name = NAME;
  5138. this._loader = loader;
  5139. this.enabled = this._loader.isExtensionUsed(NAME);
  5140. }
  5141. /** @hidden */
  5142. KHR_texture_transform.prototype.dispose = function () {
  5143. delete this._loader;
  5144. };
  5145. /** @hidden */
  5146. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  5147. var _this = this;
  5148. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  5149. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  5150. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  5151. throw new Error(extensionContext + ": Texture type not supported");
  5152. }
  5153. if (extension.offset) {
  5154. babylonTexture.uOffset = extension.offset[0];
  5155. babylonTexture.vOffset = extension.offset[1];
  5156. }
  5157. // Always rotate around the origin.
  5158. babylonTexture.uRotationCenter = 0;
  5159. babylonTexture.vRotationCenter = 0;
  5160. if (extension.rotation) {
  5161. babylonTexture.wAng = -extension.rotation;
  5162. }
  5163. if (extension.scale) {
  5164. babylonTexture.uScale = extension.scale[0];
  5165. babylonTexture.vScale = extension.scale[1];
  5166. }
  5167. if (extension.texCoord != undefined) {
  5168. babylonTexture.coordinatesIndex = extension.texCoord;
  5169. }
  5170. assign(babylonTexture);
  5171. });
  5172. });
  5173. };
  5174. return KHR_texture_transform;
  5175. }());
  5176. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  5177. /***/ }),
  5178. /***/ "./glTF/2.0/Extensions/KHR_xmp.ts":
  5179. /*!****************************************!*\
  5180. !*** ./glTF/2.0/Extensions/KHR_xmp.ts ***!
  5181. \****************************************/
  5182. /*! exports provided: KHR_xmp */
  5183. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5184. "use strict";
  5185. __webpack_require__.r(__webpack_exports__);
  5186. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return KHR_xmp; });
  5187. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5188. var NAME = "KHR_xmp";
  5189. /**
  5190. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  5191. * !!! Experimental Extension Subject to Changes !!!
  5192. */
  5193. var KHR_xmp = /** @class */ (function () {
  5194. /** @hidden */
  5195. function KHR_xmp(loader) {
  5196. /**
  5197. * The name of this extension.
  5198. */
  5199. this.name = NAME;
  5200. /**
  5201. * Defines a number that determines the order the extensions are applied.
  5202. */
  5203. this.order = 100;
  5204. this._loader = loader;
  5205. this.enabled = this._loader.isExtensionUsed(NAME);
  5206. }
  5207. /** @hidden */
  5208. KHR_xmp.prototype.dispose = function () {
  5209. delete this._loader;
  5210. };
  5211. /**
  5212. * Called after the loader state changes to LOADING.
  5213. */
  5214. KHR_xmp.prototype.onLoading = function () {
  5215. var _a, _b, _c;
  5216. var xmp_gltf = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_xmp;
  5217. var xmp_node = (_c = (_b = this._loader.gltf.asset) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.KHR_xmp;
  5218. if (xmp_gltf && xmp_node) {
  5219. var packet = +xmp_node.packet;
  5220. if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {
  5221. this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};
  5222. this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];
  5223. }
  5224. }
  5225. };
  5226. return KHR_xmp;
  5227. }());
  5228. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_xmp(loader); });
  5229. /***/ }),
  5230. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  5231. /*!***************************************************!*\
  5232. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  5233. \***************************************************/
  5234. /*! exports provided: MSFT_audio_emitter */
  5235. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5236. "use strict";
  5237. __webpack_require__.r(__webpack_exports__);
  5238. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  5239. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  5240. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  5241. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5242. var NAME = "MSFT_audio_emitter";
  5243. /**
  5244. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  5245. */
  5246. var MSFT_audio_emitter = /** @class */ (function () {
  5247. /** @hidden */
  5248. function MSFT_audio_emitter(loader) {
  5249. /**
  5250. * The name of this extension.
  5251. */
  5252. this.name = NAME;
  5253. this._loader = loader;
  5254. this.enabled = this._loader.isExtensionUsed(NAME);
  5255. }
  5256. /** @hidden */
  5257. MSFT_audio_emitter.prototype.dispose = function () {
  5258. delete this._loader;
  5259. delete this._clips;
  5260. delete this._emitters;
  5261. };
  5262. /** @hidden */
  5263. MSFT_audio_emitter.prototype.onLoading = function () {
  5264. var extensions = this._loader.gltf.extensions;
  5265. if (extensions && extensions[this.name]) {
  5266. var extension = extensions[this.name];
  5267. this._clips = extension.clips;
  5268. this._emitters = extension.emitters;
  5269. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  5270. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  5271. }
  5272. };
  5273. /** @hidden */
  5274. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  5275. var _this = this;
  5276. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  5277. var promises = new Array();
  5278. promises.push(_this._loader.loadSceneAsync(context, scene));
  5279. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5280. var emitterIndex = _a[_i];
  5281. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5282. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  5283. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5284. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  5285. }
  5286. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  5287. }
  5288. return Promise.all(promises).then(function () { });
  5289. });
  5290. };
  5291. /** @hidden */
  5292. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  5293. var _this = this;
  5294. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5295. var promises = new Array();
  5296. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  5297. var _loop_1 = function (emitterIndex) {
  5298. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5299. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  5300. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  5301. var sound = _a[_i];
  5302. sound.attachToMesh(babylonMesh);
  5303. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5304. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  5305. sound.setDirectionalCone(2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  5306. }
  5307. }
  5308. }));
  5309. };
  5310. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5311. var emitterIndex = _a[_i];
  5312. _loop_1(emitterIndex);
  5313. }
  5314. assign(babylonMesh);
  5315. }).then(function (babylonMesh) {
  5316. return Promise.all(promises).then(function () {
  5317. return babylonMesh;
  5318. });
  5319. });
  5320. });
  5321. };
  5322. /** @hidden */
  5323. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  5324. var _this = this;
  5325. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  5326. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  5327. var promises = new Array();
  5328. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  5329. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  5330. var event_1 = _a[_i];
  5331. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  5332. }
  5333. return Promise.all(promises).then(function () {
  5334. return babylonAnimationGroup;
  5335. });
  5336. });
  5337. });
  5338. };
  5339. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  5340. if (clip._objectURL) {
  5341. return clip._objectURL;
  5342. }
  5343. var promise;
  5344. if (clip.uri) {
  5345. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  5346. }
  5347. else {
  5348. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  5349. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  5350. }
  5351. clip._objectURL = promise.then(function (data) {
  5352. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  5353. });
  5354. return clip._objectURL;
  5355. };
  5356. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  5357. var _this = this;
  5358. emitter._babylonSounds = emitter._babylonSounds || [];
  5359. if (!emitter._babylonData) {
  5360. var clipPromises = new Array();
  5361. var name_1 = emitter.name || "emitter" + emitter.index;
  5362. var options_1 = {
  5363. loop: false,
  5364. autoplay: false,
  5365. volume: emitter.volume == undefined ? 1 : emitter.volume,
  5366. };
  5367. var _loop_2 = function (i) {
  5368. var clipContext = "/extensions/" + this_1.name + "/clips";
  5369. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  5370. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  5371. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  5372. sound.refDistance = emitter.refDistance || 1;
  5373. sound.maxDistance = emitter.maxDistance || 256;
  5374. sound.rolloffFactor = emitter.rolloffFactor || 1;
  5375. sound.distanceModel = emitter.distanceModel || 'exponential';
  5376. sound._positionInEmitterSpace = true;
  5377. }));
  5378. };
  5379. var this_1 = this;
  5380. for (var i = 0; i < emitter.clips.length; i++) {
  5381. _loop_2(i);
  5382. }
  5383. var promise = Promise.all(clipPromises).then(function () {
  5384. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  5385. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  5386. if (emitter.innerAngle) {
  5387. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  5388. }
  5389. if (emitter.outerAngle) {
  5390. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  5391. }
  5392. if (emitter.volume) {
  5393. weightedSound.volume = emitter.volume;
  5394. }
  5395. emitter._babylonData.sound = weightedSound;
  5396. });
  5397. emitter._babylonData = {
  5398. loaded: promise
  5399. };
  5400. }
  5401. return emitter._babylonData.loaded;
  5402. };
  5403. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  5404. switch (action) {
  5405. case "play" /* play */: {
  5406. return function (currentFrame) {
  5407. var frameOffset = (startOffset || 0) + (currentFrame - time);
  5408. sound.play(frameOffset);
  5409. };
  5410. }
  5411. case "stop" /* stop */: {
  5412. return function (currentFrame) {
  5413. sound.stop();
  5414. };
  5415. }
  5416. case "pause" /* pause */: {
  5417. return function (currentFrame) {
  5418. sound.pause();
  5419. };
  5420. }
  5421. default: {
  5422. throw new Error(context + ": Unsupported action " + action);
  5423. }
  5424. }
  5425. };
  5426. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  5427. var _this = this;
  5428. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  5429. return Promise.resolve();
  5430. }
  5431. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  5432. var emitterIndex = event.emitter;
  5433. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  5434. return this._loadEmitterAsync(context, emitter).then(function () {
  5435. var sound = emitter._babylonData.sound;
  5436. if (sound) {
  5437. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  5438. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  5439. // Make sure all started audio stops when this animation is terminated.
  5440. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  5441. sound.stop();
  5442. });
  5443. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  5444. sound.pause();
  5445. });
  5446. }
  5447. });
  5448. };
  5449. return MSFT_audio_emitter;
  5450. }());
  5451. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  5452. /***/ }),
  5453. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  5454. /*!*****************************************!*\
  5455. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  5456. \*****************************************/
  5457. /*! exports provided: MSFT_lod */
  5458. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5459. "use strict";
  5460. __webpack_require__.r(__webpack_exports__);
  5461. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  5462. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  5463. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  5464. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5465. var NAME = "MSFT_lod";
  5466. /**
  5467. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  5468. */
  5469. var MSFT_lod = /** @class */ (function () {
  5470. /** @hidden */
  5471. function MSFT_lod(loader) {
  5472. /**
  5473. * The name of this extension.
  5474. */
  5475. this.name = NAME;
  5476. /**
  5477. * Defines a number that determines the order the extensions are applied.
  5478. */
  5479. this.order = 100;
  5480. /**
  5481. * Maximum number of LODs to load, starting from the lowest LOD.
  5482. */
  5483. this.maxLODsToLoad = 10;
  5484. /**
  5485. * Observable raised when all node LODs of one level are loaded.
  5486. * The event data is the index of the loaded LOD starting from zero.
  5487. * Dispose the loader to cancel the loading of the next level of LODs.
  5488. */
  5489. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5490. /**
  5491. * Observable raised when all material LODs of one level are loaded.
  5492. * The event data is the index of the loaded LOD starting from zero.
  5493. * Dispose the loader to cancel the loading of the next level of LODs.
  5494. */
  5495. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5496. this._bufferLODs = new Array();
  5497. this._nodeIndexLOD = null;
  5498. this._nodeSignalLODs = new Array();
  5499. this._nodePromiseLODs = new Array();
  5500. this._nodeBufferLODs = new Array();
  5501. this._materialIndexLOD = null;
  5502. this._materialSignalLODs = new Array();
  5503. this._materialPromiseLODs = new Array();
  5504. this._materialBufferLODs = new Array();
  5505. this._loader = loader;
  5506. this.enabled = this._loader.isExtensionUsed(NAME);
  5507. }
  5508. /** @hidden */
  5509. MSFT_lod.prototype.dispose = function () {
  5510. delete this._loader;
  5511. this._nodeIndexLOD = null;
  5512. this._nodeSignalLODs.length = 0;
  5513. this._nodePromiseLODs.length = 0;
  5514. this._nodeBufferLODs.length = 0;
  5515. this._materialIndexLOD = null;
  5516. this._materialSignalLODs.length = 0;
  5517. this._materialPromiseLODs.length = 0;
  5518. this._materialBufferLODs.length = 0;
  5519. this.onMaterialLODsLoadedObservable.clear();
  5520. this.onNodeLODsLoadedObservable.clear();
  5521. };
  5522. /** @hidden */
  5523. MSFT_lod.prototype.onReady = function () {
  5524. var _this = this;
  5525. var _loop_1 = function (indexLOD) {
  5526. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  5527. if (indexLOD !== 0) {
  5528. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  5529. _this._loader.log("Loaded node LOD " + indexLOD);
  5530. }
  5531. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  5532. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  5533. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  5534. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  5535. if (_this._nodeSignalLODs[indexLOD]) {
  5536. _this._nodeSignalLODs[indexLOD].resolve();
  5537. }
  5538. }
  5539. });
  5540. this_1._loader._completePromises.push(promise);
  5541. };
  5542. var this_1 = this;
  5543. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  5544. _loop_1(indexLOD);
  5545. }
  5546. var _loop_2 = function (indexLOD) {
  5547. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  5548. if (indexLOD !== 0) {
  5549. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  5550. _this._loader.log("Loaded material LOD " + indexLOD);
  5551. }
  5552. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  5553. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  5554. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  5555. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  5556. if (_this._materialSignalLODs[indexLOD]) {
  5557. _this._materialSignalLODs[indexLOD].resolve();
  5558. }
  5559. }
  5560. });
  5561. this_2._loader._completePromises.push(promise);
  5562. };
  5563. var this_2 = this;
  5564. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  5565. _loop_2(indexLOD);
  5566. }
  5567. };
  5568. /** @hidden */
  5569. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  5570. var promise = this._loader.loadSceneAsync(context, scene);
  5571. this._loadBufferLOD(this._bufferLODs, 0);
  5572. return promise;
  5573. };
  5574. /** @hidden */
  5575. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  5576. var _this = this;
  5577. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5578. var firstPromise;
  5579. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5580. _this._loader.logOpen("" + extensionContext);
  5581. var _loop_3 = function (indexLOD) {
  5582. var nodeLOD = nodeLODs[indexLOD];
  5583. if (indexLOD !== 0) {
  5584. _this._nodeIndexLOD = indexLOD;
  5585. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5586. }
  5587. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5588. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5589. if (indexLOD !== 0) {
  5590. // TODO: should not rely on _babylonTransformNode
  5591. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5592. if (previousNodeLOD._babylonTransformNode) {
  5593. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  5594. delete previousNodeLOD._babylonTransformNode;
  5595. }
  5596. }
  5597. babylonMesh.setEnabled(true);
  5598. return babylonMesh;
  5599. });
  5600. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5601. if (indexLOD === 0) {
  5602. firstPromise = promise;
  5603. }
  5604. else {
  5605. _this._nodeIndexLOD = null;
  5606. _this._nodePromiseLODs[indexLOD].push(promise);
  5607. }
  5608. };
  5609. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5610. _loop_3(indexLOD);
  5611. }
  5612. _this._loader.logClose();
  5613. return firstPromise;
  5614. });
  5615. };
  5616. /** @hidden */
  5617. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5618. var _this = this;
  5619. // Don't load material LODs if already loading a node LOD.
  5620. if (this._nodeIndexLOD) {
  5621. return null;
  5622. }
  5623. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5624. var firstPromise;
  5625. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5626. _this._loader.logOpen("" + extensionContext);
  5627. var _loop_4 = function (indexLOD) {
  5628. var materialLOD = materialLODs[indexLOD];
  5629. if (indexLOD !== 0) {
  5630. _this._materialIndexLOD = indexLOD;
  5631. }
  5632. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5633. if (indexLOD === 0) {
  5634. assign(babylonMaterial);
  5635. }
  5636. }).then(function (babylonMaterial) {
  5637. if (indexLOD !== 0) {
  5638. assign(babylonMaterial);
  5639. // TODO: should not rely on _data
  5640. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5641. if (previousDataLOD[babylonDrawMode]) {
  5642. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  5643. delete previousDataLOD[babylonDrawMode];
  5644. }
  5645. }
  5646. return babylonMaterial;
  5647. });
  5648. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5649. if (indexLOD === 0) {
  5650. firstPromise = promise;
  5651. }
  5652. else {
  5653. _this._materialIndexLOD = null;
  5654. _this._materialPromiseLODs[indexLOD].push(promise);
  5655. }
  5656. };
  5657. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5658. _loop_4(indexLOD);
  5659. }
  5660. _this._loader.logClose();
  5661. return firstPromise;
  5662. });
  5663. };
  5664. /** @hidden */
  5665. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5666. var _this = this;
  5667. // Defer the loading of uris if loading a node or material LOD.
  5668. if (this._nodeIndexLOD !== null) {
  5669. this._loader.log("deferred");
  5670. var previousIndexLOD = this._nodeIndexLOD - 1;
  5671. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5672. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5673. return _this._loader.loadUriAsync(context, property, uri);
  5674. });
  5675. }
  5676. else if (this._materialIndexLOD !== null) {
  5677. this._loader.log("deferred");
  5678. var previousIndexLOD = this._materialIndexLOD - 1;
  5679. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5680. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5681. return _this._loader.loadUriAsync(context, property, uri);
  5682. });
  5683. }
  5684. return null;
  5685. };
  5686. /** @hidden */
  5687. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5688. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5689. if (!this._loader.bin) {
  5690. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5691. }
  5692. var loadAsync = function (bufferLODs, indexLOD) {
  5693. var start = byteOffset;
  5694. var end = start + byteLength - 1;
  5695. var bufferLOD = bufferLODs[indexLOD];
  5696. if (bufferLOD) {
  5697. bufferLOD.start = Math.min(bufferLOD.start, start);
  5698. bufferLOD.end = Math.max(bufferLOD.end, end);
  5699. }
  5700. else {
  5701. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5702. bufferLODs[indexLOD] = bufferLOD;
  5703. }
  5704. return bufferLOD.loaded.promise.then(function (data) {
  5705. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  5706. });
  5707. };
  5708. this._loader.log("deferred");
  5709. if (this._nodeIndexLOD !== null) {
  5710. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  5711. }
  5712. else if (this._materialIndexLOD !== null) {
  5713. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  5714. }
  5715. else {
  5716. return loadAsync(this._bufferLODs, 0);
  5717. }
  5718. }
  5719. return null;
  5720. };
  5721. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  5722. var bufferLOD = bufferLODs[indexLOD];
  5723. if (bufferLOD) {
  5724. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  5725. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5726. bufferLOD.loaded.resolve(data);
  5727. }, function (error) {
  5728. bufferLOD.loaded.reject(error);
  5729. });
  5730. }
  5731. };
  5732. /**
  5733. * Gets an array of LOD properties from lowest to highest.
  5734. */
  5735. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5736. if (this.maxLODsToLoad <= 0) {
  5737. throw new Error("maxLODsToLoad must be greater than zero");
  5738. }
  5739. var properties = new Array();
  5740. for (var i = ids.length - 1; i >= 0; i--) {
  5741. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5742. if (properties.length === this.maxLODsToLoad) {
  5743. return properties;
  5744. }
  5745. }
  5746. properties.push(property);
  5747. return properties;
  5748. };
  5749. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  5750. var _this = this;
  5751. var babylonMaterials = new Array();
  5752. var babylonMaterial = babylonTransformNode.material;
  5753. if (babylonMaterial) {
  5754. babylonMaterials.push(babylonMaterial);
  5755. }
  5756. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  5757. var babylonMesh = _a[_i];
  5758. if (babylonMesh.material) {
  5759. babylonMaterials.push(babylonMesh.material);
  5760. }
  5761. }
  5762. babylonTransformNode.dispose();
  5763. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  5764. this._disposeMaterials(babylonMaterialsToDispose);
  5765. };
  5766. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  5767. var babylonTextures = {};
  5768. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  5769. var babylonMaterial = babylonMaterials_1[_i];
  5770. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  5771. var babylonTexture = _b[_a];
  5772. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  5773. }
  5774. babylonMaterial.dispose();
  5775. }
  5776. for (var uniqueId in babylonTextures) {
  5777. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  5778. var babylonMaterial = _d[_c];
  5779. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  5780. delete babylonTextures[uniqueId];
  5781. }
  5782. }
  5783. }
  5784. for (var uniqueId in babylonTextures) {
  5785. babylonTextures[uniqueId].dispose();
  5786. }
  5787. };
  5788. return MSFT_lod;
  5789. }());
  5790. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5791. /***/ }),
  5792. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5793. /*!***************************************************!*\
  5794. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5795. \***************************************************/
  5796. /*! exports provided: MSFT_minecraftMesh */
  5797. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5798. "use strict";
  5799. __webpack_require__.r(__webpack_exports__);
  5800. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5801. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5802. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5803. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5804. var NAME = "MSFT_minecraftMesh";
  5805. /** @hidden */
  5806. var MSFT_minecraftMesh = /** @class */ (function () {
  5807. function MSFT_minecraftMesh(loader) {
  5808. this.name = NAME;
  5809. this._loader = loader;
  5810. this.enabled = this._loader.isExtensionUsed(NAME);
  5811. }
  5812. MSFT_minecraftMesh.prototype.dispose = function () {
  5813. delete this._loader;
  5814. };
  5815. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5816. var _this = this;
  5817. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5818. if (extra) {
  5819. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5820. throw new Error(extraContext + ": Material type not supported");
  5821. }
  5822. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5823. if (babylonMaterial.needAlphaBlending()) {
  5824. babylonMaterial.forceDepthWrite = true;
  5825. babylonMaterial.separateCullingPass = true;
  5826. }
  5827. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5828. babylonMaterial.twoSidedLighting = true;
  5829. return promise;
  5830. }
  5831. return null;
  5832. });
  5833. };
  5834. return MSFT_minecraftMesh;
  5835. }());
  5836. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5837. /***/ }),
  5838. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5839. /*!*************************************************!*\
  5840. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5841. \*************************************************/
  5842. /*! exports provided: MSFT_sRGBFactors */
  5843. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5844. "use strict";
  5845. __webpack_require__.r(__webpack_exports__);
  5846. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5847. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5848. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5849. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5850. var NAME = "MSFT_sRGBFactors";
  5851. /** @hidden */
  5852. var MSFT_sRGBFactors = /** @class */ (function () {
  5853. function MSFT_sRGBFactors(loader) {
  5854. this.name = NAME;
  5855. this._loader = loader;
  5856. this.enabled = this._loader.isExtensionUsed(NAME);
  5857. }
  5858. MSFT_sRGBFactors.prototype.dispose = function () {
  5859. delete this._loader;
  5860. };
  5861. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5862. var _this = this;
  5863. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5864. if (extra) {
  5865. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5866. throw new Error(extraContext + ": Material type not supported");
  5867. }
  5868. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5869. if (!babylonMaterial.albedoTexture) {
  5870. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5871. }
  5872. if (!babylonMaterial.reflectivityTexture) {
  5873. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5874. }
  5875. return promise;
  5876. }
  5877. return null;
  5878. });
  5879. };
  5880. return MSFT_sRGBFactors;
  5881. }());
  5882. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5883. /***/ }),
  5884. /***/ "./glTF/2.0/Extensions/index.ts":
  5885. /*!**************************************!*\
  5886. !*** ./glTF/2.0/Extensions/index.ts ***!
  5887. \**************************************/
  5888. /*! exports provided: EXT_lights_image_based, EXT_mesh_gpu_instancing, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  5889. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5890. "use strict";
  5891. __webpack_require__.r(__webpack_exports__);
  5892. /* 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");
  5893. /* 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"]; });
  5894. /* harmony import */ var _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EXT_mesh_gpu_instancing */ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts");
  5895. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  5896. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  5897. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__["KHR_draco_mesh_compression"]; });
  5898. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5899. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  5900. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5901. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_pbrSpecularGlossiness"]; });
  5902. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5903. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_unlit"]; });
  5904. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5905. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_clearcoat"]; });
  5906. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5907. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  5908. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5909. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_specular"]; });
  5910. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  5911. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_ior"]; });
  5912. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  5913. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_variants"]; });
  5914. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  5915. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_transmission"]; });
  5916. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  5917. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__["KHR_mesh_quantization"]; });
  5918. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  5919. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__["KHR_texture_basisu"]; });
  5920. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5921. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__["KHR_texture_transform"]; });
  5922. /* harmony import */ var _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_xmp */ "./glTF/2.0/Extensions/KHR_xmp.ts");
  5923. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__["KHR_xmp"]; });
  5924. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5925. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__["MSFT_audio_emitter"]; });
  5926. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5927. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__["MSFT_lod"]; });
  5928. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5929. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__["MSFT_minecraftMesh"]; });
  5930. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5931. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__["MSFT_sRGBFactors"]; });
  5932. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5933. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__["ExtrasAsMetadata"]; });
  5934. /***/ }),
  5935. /***/ "./glTF/2.0/glTFLoader.ts":
  5936. /*!********************************!*\
  5937. !*** ./glTF/2.0/glTFLoader.ts ***!
  5938. \********************************/
  5939. /*! exports provided: ArrayItem, GLTFLoader */
  5940. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5941. "use strict";
  5942. __webpack_require__.r(__webpack_exports__);
  5943. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5944. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5945. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  5946. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5947. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5948. /**
  5949. * Helper class for working with arrays when loading the glTF asset
  5950. */
  5951. var ArrayItem = /** @class */ (function () {
  5952. function ArrayItem() {
  5953. }
  5954. /**
  5955. * Gets an item from the given array.
  5956. * @param context The context when loading the asset
  5957. * @param array The array to get the item from
  5958. * @param index The index to the array
  5959. * @returns The array item
  5960. */
  5961. ArrayItem.Get = function (context, array, index) {
  5962. if (!array || index == undefined || !array[index]) {
  5963. throw new Error(context + ": Failed to find index (" + index + ")");
  5964. }
  5965. return array[index];
  5966. };
  5967. /**
  5968. * Assign an `index` field to each item of the given array.
  5969. * @param array The array of items
  5970. */
  5971. ArrayItem.Assign = function (array) {
  5972. if (array) {
  5973. for (var index = 0; index < array.length; index++) {
  5974. array[index].index = index;
  5975. }
  5976. }
  5977. };
  5978. return ArrayItem;
  5979. }());
  5980. /**
  5981. * The glTF 2.0 loader
  5982. */
  5983. var GLTFLoader = /** @class */ (function () {
  5984. /** @hidden */
  5985. function GLTFLoader(parent) {
  5986. /** @hidden */
  5987. this._completePromises = new Array();
  5988. /** @hidden */
  5989. this._forAssetContainer = false;
  5990. /** Storage */
  5991. this._babylonLights = [];
  5992. /** @hidden */
  5993. this._disableInstancedMesh = 0;
  5994. this._disposed = false;
  5995. this._state = null;
  5996. this._extensions = new Array();
  5997. this._defaultBabylonMaterialData = {};
  5998. this._parent = parent;
  5999. }
  6000. /**
  6001. * Registers a loader extension.
  6002. * @param name The name of the loader extension.
  6003. * @param factory The factory function that creates the loader extension.
  6004. */
  6005. GLTFLoader.RegisterExtension = function (name, factory) {
  6006. if (GLTFLoader.UnregisterExtension(name)) {
  6007. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  6008. }
  6009. GLTFLoader._RegisteredExtensions[name] = {
  6010. factory: factory
  6011. };
  6012. };
  6013. /**
  6014. * Unregisters a loader extension.
  6015. * @param name The name of the loader extension.
  6016. * @returns A boolean indicating whether the extension has been unregistered
  6017. */
  6018. GLTFLoader.UnregisterExtension = function (name) {
  6019. if (!GLTFLoader._RegisteredExtensions[name]) {
  6020. return false;
  6021. }
  6022. delete GLTFLoader._RegisteredExtensions[name];
  6023. return true;
  6024. };
  6025. Object.defineProperty(GLTFLoader.prototype, "state", {
  6026. /**
  6027. * The loader state.
  6028. */
  6029. get: function () {
  6030. return this._state;
  6031. },
  6032. enumerable: true,
  6033. configurable: true
  6034. });
  6035. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  6036. /**
  6037. * The object that represents the glTF JSON.
  6038. */
  6039. get: function () {
  6040. return this._gltf;
  6041. },
  6042. enumerable: true,
  6043. configurable: true
  6044. });
  6045. Object.defineProperty(GLTFLoader.prototype, "bin", {
  6046. /**
  6047. * The BIN chunk of a binary glTF.
  6048. */
  6049. get: function () {
  6050. return this._bin;
  6051. },
  6052. enumerable: true,
  6053. configurable: true
  6054. });
  6055. Object.defineProperty(GLTFLoader.prototype, "parent", {
  6056. /**
  6057. * The parent file loader.
  6058. */
  6059. get: function () {
  6060. return this._parent;
  6061. },
  6062. enumerable: true,
  6063. configurable: true
  6064. });
  6065. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  6066. /**
  6067. * The Babylon scene when loading the asset.
  6068. */
  6069. get: function () {
  6070. return this._babylonScene;
  6071. },
  6072. enumerable: true,
  6073. configurable: true
  6074. });
  6075. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  6076. /**
  6077. * The root Babylon mesh when loading the asset.
  6078. */
  6079. get: function () {
  6080. return this._rootBabylonMesh;
  6081. },
  6082. enumerable: true,
  6083. configurable: true
  6084. });
  6085. /** @hidden */
  6086. GLTFLoader.prototype.dispose = function () {
  6087. if (this._disposed) {
  6088. return;
  6089. }
  6090. this._disposed = true;
  6091. this._completePromises.length = 0;
  6092. for (var name_1 in this._extensions) {
  6093. var extension = this._extensions[name_1];
  6094. extension.dispose && extension.dispose();
  6095. delete this._extensions[name_1];
  6096. }
  6097. delete this._gltf;
  6098. delete this._babylonScene;
  6099. delete this._rootBabylonMesh;
  6100. this._parent.dispose();
  6101. };
  6102. /** @hidden */
  6103. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  6104. var _this = this;
  6105. return Promise.resolve().then(function () {
  6106. _this._babylonScene = scene;
  6107. _this._rootUrl = rootUrl;
  6108. _this._fileName = fileName || "scene";
  6109. _this._forAssetContainer = forAssetContainer;
  6110. _this._loadData(data);
  6111. var nodes = null;
  6112. if (meshesNames) {
  6113. var nodeMap_1 = {};
  6114. if (_this._gltf.nodes) {
  6115. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  6116. var node = _a[_i];
  6117. if (node.name) {
  6118. nodeMap_1[node.name] = node.index;
  6119. }
  6120. }
  6121. }
  6122. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  6123. nodes = names.map(function (name) {
  6124. var node = nodeMap_1[name];
  6125. if (node === undefined) {
  6126. throw new Error("Failed to find node '" + name + "'");
  6127. }
  6128. return node;
  6129. });
  6130. }
  6131. return _this._loadAsync(nodes, function () {
  6132. return {
  6133. meshes: _this._getMeshes(),
  6134. particleSystems: [],
  6135. skeletons: _this._getSkeletons(),
  6136. animationGroups: _this._getAnimationGroups(),
  6137. lights: _this._babylonLights,
  6138. transformNodes: _this._getTransformNodes()
  6139. };
  6140. });
  6141. });
  6142. };
  6143. /** @hidden */
  6144. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  6145. var _this = this;
  6146. return Promise.resolve().then(function () {
  6147. _this._babylonScene = scene;
  6148. _this._rootUrl = rootUrl;
  6149. _this._fileName = fileName || "scene";
  6150. _this._loadData(data);
  6151. return _this._loadAsync(null, function () { return undefined; });
  6152. });
  6153. };
  6154. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  6155. var _this = this;
  6156. return Promise.resolve().then(function () {
  6157. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  6158. _this._loadExtensions();
  6159. _this._checkExtensions();
  6160. 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];
  6161. 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];
  6162. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  6163. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  6164. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  6165. _this._extensionsOnLoading();
  6166. var promises = new Array();
  6167. // Block the marking of materials dirty until the scene is loaded.
  6168. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  6169. _this._babylonScene.blockMaterialDirtyMechanism = true;
  6170. if (nodes) {
  6171. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  6172. }
  6173. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  6174. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  6175. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  6176. }
  6177. // Restore the blocking of material dirty.
  6178. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  6179. if (_this._parent.compileMaterials) {
  6180. promises.push(_this._compileMaterialsAsync());
  6181. }
  6182. if (_this._parent.compileShadowGenerators) {
  6183. promises.push(_this._compileShadowGeneratorsAsync());
  6184. }
  6185. var resultPromise = Promise.all(promises).then(function () {
  6186. if (_this._rootBabylonMesh) {
  6187. _this._rootBabylonMesh.setEnabled(true);
  6188. }
  6189. _this._extensionsOnReady();
  6190. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  6191. _this._startAnimations();
  6192. return resultFunc();
  6193. });
  6194. resultPromise.then(function () {
  6195. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  6196. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  6197. if (!_this._disposed) {
  6198. Promise.all(_this._completePromises).then(function () {
  6199. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  6200. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  6201. _this._parent.onCompleteObservable.notifyObservers(undefined);
  6202. _this._parent.onCompleteObservable.clear();
  6203. _this.dispose();
  6204. }, function (error) {
  6205. _this._parent.onErrorObservable.notifyObservers(error);
  6206. _this._parent.onErrorObservable.clear();
  6207. _this.dispose();
  6208. });
  6209. }
  6210. });
  6211. });
  6212. return resultPromise;
  6213. }, function (error) {
  6214. if (!_this._disposed) {
  6215. _this._parent.onErrorObservable.notifyObservers(error);
  6216. _this._parent.onErrorObservable.clear();
  6217. _this.dispose();
  6218. }
  6219. throw error;
  6220. });
  6221. };
  6222. GLTFLoader.prototype._loadData = function (data) {
  6223. this._gltf = data.json;
  6224. this._setupData();
  6225. if (data.bin) {
  6226. var buffers = this._gltf.buffers;
  6227. if (buffers && buffers[0] && !buffers[0].uri) {
  6228. var binaryBuffer = buffers[0];
  6229. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  6230. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  6231. }
  6232. this._bin = data.bin;
  6233. }
  6234. else {
  6235. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  6236. }
  6237. }
  6238. };
  6239. GLTFLoader.prototype._setupData = function () {
  6240. ArrayItem.Assign(this._gltf.accessors);
  6241. ArrayItem.Assign(this._gltf.animations);
  6242. ArrayItem.Assign(this._gltf.buffers);
  6243. ArrayItem.Assign(this._gltf.bufferViews);
  6244. ArrayItem.Assign(this._gltf.cameras);
  6245. ArrayItem.Assign(this._gltf.images);
  6246. ArrayItem.Assign(this._gltf.materials);
  6247. ArrayItem.Assign(this._gltf.meshes);
  6248. ArrayItem.Assign(this._gltf.nodes);
  6249. ArrayItem.Assign(this._gltf.samplers);
  6250. ArrayItem.Assign(this._gltf.scenes);
  6251. ArrayItem.Assign(this._gltf.skins);
  6252. ArrayItem.Assign(this._gltf.textures);
  6253. if (this._gltf.nodes) {
  6254. var nodeParents = {};
  6255. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  6256. var node = _a[_i];
  6257. if (node.children) {
  6258. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  6259. var index = _c[_b];
  6260. nodeParents[index] = node.index;
  6261. }
  6262. }
  6263. }
  6264. var rootNode = this._createRootNode();
  6265. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  6266. var node = _e[_d];
  6267. var parentIndex = nodeParents[node.index];
  6268. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  6269. }
  6270. }
  6271. };
  6272. GLTFLoader.prototype._loadExtensions = function () {
  6273. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  6274. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  6275. if (extension.name !== name_2) {
  6276. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("The name of the glTF loader extension instance does not match the registered name: " + extension.name + " !== " + name_2);
  6277. }
  6278. this._extensions.push(extension);
  6279. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  6280. }
  6281. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  6282. this._parent.onExtensionLoadedObservable.clear();
  6283. };
  6284. GLTFLoader.prototype._checkExtensions = function () {
  6285. if (this._gltf.extensionsRequired) {
  6286. var _loop_1 = function (name_3) {
  6287. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  6288. if (!available) {
  6289. throw new Error("Require extension " + name_3 + " is not available");
  6290. }
  6291. };
  6292. var this_1 = this;
  6293. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  6294. var name_3 = _a[_i];
  6295. _loop_1(name_3);
  6296. }
  6297. }
  6298. };
  6299. GLTFLoader.prototype._setState = function (state) {
  6300. this._state = state;
  6301. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  6302. };
  6303. GLTFLoader.prototype._createRootNode = function () {
  6304. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6305. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  6306. this._babylonScene._blockEntityCollection = false;
  6307. this._rootBabylonMesh.setEnabled(false);
  6308. var rootNode = {
  6309. _babylonTransformNode: this._rootBabylonMesh,
  6310. index: -1
  6311. };
  6312. switch (this._parent.coordinateSystemMode) {
  6313. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  6314. if (!this._babylonScene.useRightHandedSystem) {
  6315. rootNode.rotation = [0, 1, 0, 0];
  6316. rootNode.scale = [1, 1, -1];
  6317. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  6318. }
  6319. break;
  6320. }
  6321. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  6322. this._babylonScene.useRightHandedSystem = true;
  6323. break;
  6324. }
  6325. default: {
  6326. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  6327. }
  6328. }
  6329. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  6330. return rootNode;
  6331. };
  6332. /**
  6333. * Loads a glTF scene.
  6334. * @param context The context when loading the asset
  6335. * @param scene The glTF scene property
  6336. * @returns A promise that resolves when the load is complete
  6337. */
  6338. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  6339. var _this = this;
  6340. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  6341. if (extensionPromise) {
  6342. return extensionPromise;
  6343. }
  6344. var promises = new Array();
  6345. this.logOpen(context + " " + (scene.name || ""));
  6346. if (scene.nodes) {
  6347. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  6348. var index = _a[_i];
  6349. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  6350. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  6351. babylonMesh.parent = _this._rootBabylonMesh;
  6352. }));
  6353. }
  6354. }
  6355. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  6356. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  6357. if (this._gltf.nodes) {
  6358. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  6359. var node = _c[_b];
  6360. if (node._babylonTransformNode && node._babylonBones) {
  6361. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  6362. var babylonBone = _e[_d];
  6363. babylonBone.linkTransformNode(node._babylonTransformNode);
  6364. }
  6365. }
  6366. }
  6367. }
  6368. promises.push(this._loadAnimationsAsync());
  6369. this.logClose();
  6370. return Promise.all(promises).then(function () { });
  6371. };
  6372. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  6373. if (node._primitiveBabylonMeshes) {
  6374. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  6375. var babylonMesh = _a[_i];
  6376. callback(babylonMesh);
  6377. }
  6378. }
  6379. };
  6380. GLTFLoader.prototype._getMeshes = function () {
  6381. var meshes = new Array();
  6382. // Root mesh is always first.
  6383. meshes.push(this._rootBabylonMesh);
  6384. var nodes = this._gltf.nodes;
  6385. if (nodes) {
  6386. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  6387. var node = nodes_1[_i];
  6388. this._forEachPrimitive(node, function (babylonMesh) {
  6389. meshes.push(babylonMesh);
  6390. });
  6391. }
  6392. }
  6393. return meshes;
  6394. };
  6395. GLTFLoader.prototype._getTransformNodes = function () {
  6396. var transformNodes = new Array();
  6397. var nodes = this._gltf.nodes;
  6398. if (nodes) {
  6399. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  6400. var node = nodes_2[_i];
  6401. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  6402. transformNodes.push(node._babylonTransformNode);
  6403. }
  6404. }
  6405. }
  6406. return transformNodes;
  6407. };
  6408. GLTFLoader.prototype._getSkeletons = function () {
  6409. var skeletons = new Array();
  6410. var skins = this._gltf.skins;
  6411. if (skins) {
  6412. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  6413. var skin = skins_1[_i];
  6414. if (skin._data) {
  6415. skeletons.push(skin._data.babylonSkeleton);
  6416. }
  6417. }
  6418. }
  6419. return skeletons;
  6420. };
  6421. GLTFLoader.prototype._getAnimationGroups = function () {
  6422. var animationGroups = new Array();
  6423. var animations = this._gltf.animations;
  6424. if (animations) {
  6425. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  6426. var animation = animations_1[_i];
  6427. if (animation._babylonAnimationGroup) {
  6428. animationGroups.push(animation._babylonAnimationGroup);
  6429. }
  6430. }
  6431. }
  6432. return animationGroups;
  6433. };
  6434. GLTFLoader.prototype._startAnimations = function () {
  6435. switch (this._parent.animationStartMode) {
  6436. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  6437. // do nothing
  6438. break;
  6439. }
  6440. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  6441. var babylonAnimationGroups = this._getAnimationGroups();
  6442. if (babylonAnimationGroups.length !== 0) {
  6443. babylonAnimationGroups[0].start(true);
  6444. }
  6445. break;
  6446. }
  6447. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  6448. var babylonAnimationGroups = this._getAnimationGroups();
  6449. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  6450. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  6451. babylonAnimationGroup.start(true);
  6452. }
  6453. break;
  6454. }
  6455. default: {
  6456. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  6457. return;
  6458. }
  6459. }
  6460. };
  6461. /**
  6462. * Loads a glTF node.
  6463. * @param context The context when loading the asset
  6464. * @param node The glTF node property
  6465. * @param assign A function called synchronously after parsing the glTF properties
  6466. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  6467. */
  6468. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  6469. var _this = this;
  6470. if (assign === void 0) { assign = function () { }; }
  6471. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  6472. if (extensionPromise) {
  6473. return extensionPromise;
  6474. }
  6475. if (node._babylonTransformNode) {
  6476. throw new Error(context + ": Invalid recursive node hierarchy");
  6477. }
  6478. var promises = new Array();
  6479. this.logOpen(context + " " + (node.name || ""));
  6480. var loadNode = function (babylonTransformNode) {
  6481. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  6482. GLTFLoader._LoadTransform(node, babylonTransformNode);
  6483. if (node.camera != undefined) {
  6484. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  6485. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  6486. babylonCamera.parent = babylonTransformNode;
  6487. }));
  6488. }
  6489. if (node.children) {
  6490. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  6491. var index = _a[_i];
  6492. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  6493. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  6494. childBabylonMesh.parent = babylonTransformNode;
  6495. }));
  6496. }
  6497. }
  6498. assign(babylonTransformNode);
  6499. };
  6500. if (node.mesh == undefined) {
  6501. var nodeName = node.name || "node" + node.index;
  6502. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6503. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  6504. this._babylonScene._blockEntityCollection = false;
  6505. loadNode(node._babylonTransformNode);
  6506. }
  6507. else {
  6508. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  6509. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  6510. }
  6511. this.logClose();
  6512. return Promise.all(promises).then(function () {
  6513. _this._forEachPrimitive(node, function (babylonMesh) {
  6514. babylonMesh.refreshBoundingInfo(true);
  6515. });
  6516. return node._babylonTransformNode;
  6517. });
  6518. };
  6519. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  6520. var primitives = mesh.primitives;
  6521. if (!primitives || !primitives.length) {
  6522. throw new Error(context + ": Primitives are missing");
  6523. }
  6524. if (primitives[0].index == undefined) {
  6525. ArrayItem.Assign(primitives);
  6526. }
  6527. var promises = new Array();
  6528. this.logOpen(context + " " + (mesh.name || ""));
  6529. var name = node.name || "node" + node.index;
  6530. if (primitives.length === 1) {
  6531. var primitive = mesh.primitives[0];
  6532. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  6533. node._babylonTransformNode = babylonMesh;
  6534. node._primitiveBabylonMeshes = [babylonMesh];
  6535. }));
  6536. }
  6537. else {
  6538. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6539. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  6540. this._babylonScene._blockEntityCollection = false;
  6541. node._primitiveBabylonMeshes = [];
  6542. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  6543. var primitive = primitives_1[_i];
  6544. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  6545. babylonMesh.parent = node._babylonTransformNode;
  6546. node._primitiveBabylonMeshes.push(babylonMesh);
  6547. }));
  6548. }
  6549. }
  6550. if (node.skin != undefined) {
  6551. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  6552. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  6553. }
  6554. assign(node._babylonTransformNode);
  6555. this.logClose();
  6556. return Promise.all(promises).then(function () {
  6557. return node._babylonTransformNode;
  6558. });
  6559. };
  6560. /**
  6561. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  6562. * @param context The context when loading the asset
  6563. * @param name The mesh name when loading the asset
  6564. * @param node The glTF node when loading the asset
  6565. * @param mesh The glTF mesh when loading the asset
  6566. * @param primitive The glTF mesh primitive property
  6567. * @param assign A function called synchronously after parsing the glTF properties
  6568. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  6569. */
  6570. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  6571. var _this = this;
  6572. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  6573. if (extensionPromise) {
  6574. return extensionPromise;
  6575. }
  6576. this.logOpen("" + context);
  6577. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  6578. var babylonAbstractMesh;
  6579. var promise;
  6580. if (shouldInstance && primitive._instanceData) {
  6581. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  6582. promise = primitive._instanceData.promise;
  6583. }
  6584. else {
  6585. var promises = new Array();
  6586. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6587. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  6588. this._babylonScene._blockEntityCollection = false;
  6589. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  6590. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  6591. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  6592. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  6593. babylonGeometry.applyToMesh(babylonMesh_1);
  6594. });
  6595. }));
  6596. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  6597. if (primitive.material == undefined) {
  6598. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  6599. if (!babylonMaterial) {
  6600. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  6601. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6602. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  6603. }
  6604. babylonMesh_1.material = babylonMaterial;
  6605. }
  6606. else {
  6607. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  6608. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  6609. babylonMesh_1.material = babylonMaterial;
  6610. }));
  6611. }
  6612. promise = Promise.all(promises);
  6613. if (shouldInstance) {
  6614. primitive._instanceData = {
  6615. babylonSourceMesh: babylonMesh_1,
  6616. promise: promise
  6617. };
  6618. }
  6619. babylonAbstractMesh = babylonMesh_1;
  6620. }
  6621. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  6622. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  6623. assign(babylonAbstractMesh);
  6624. this.logClose();
  6625. return promise.then(function () {
  6626. return babylonAbstractMesh;
  6627. });
  6628. };
  6629. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  6630. var _this = this;
  6631. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  6632. if (extensionPromise) {
  6633. return extensionPromise;
  6634. }
  6635. var attributes = primitive.attributes;
  6636. if (!attributes) {
  6637. throw new Error(context + ": Attributes are missing");
  6638. }
  6639. var promises = new Array();
  6640. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  6641. if (primitive.indices == undefined) {
  6642. babylonMesh.isUnIndexed = true;
  6643. }
  6644. else {
  6645. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6646. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6647. babylonGeometry.setIndices(data);
  6648. }));
  6649. }
  6650. var loadAttribute = function (attribute, kind, callback) {
  6651. if (attributes[attribute] == undefined) {
  6652. return;
  6653. }
  6654. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6655. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6656. babylonMesh._delayInfo.push(kind);
  6657. }
  6658. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6659. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6660. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6661. }));
  6662. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6663. babylonMesh.numBoneInfluencers = 8;
  6664. }
  6665. if (callback) {
  6666. callback(accessor);
  6667. }
  6668. };
  6669. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6670. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6671. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6672. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6673. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6674. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6675. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6676. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  6677. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  6678. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6679. if (accessor.type === "VEC4" /* VEC4 */) {
  6680. babylonMesh.hasVertexAlpha = true;
  6681. }
  6682. });
  6683. return Promise.all(promises).then(function () {
  6684. return babylonGeometry;
  6685. });
  6686. };
  6687. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6688. if (!primitive.targets) {
  6689. return;
  6690. }
  6691. if (node._numMorphTargets == undefined) {
  6692. node._numMorphTargets = primitive.targets.length;
  6693. }
  6694. else if (primitive.targets.length !== node._numMorphTargets) {
  6695. throw new Error(context + ": Primitives do not have the same number of targets");
  6696. }
  6697. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6698. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6699. for (var index = 0; index < primitive.targets.length; index++) {
  6700. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6701. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6702. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6703. // TODO: tell the target whether it has positions, normals, tangents
  6704. }
  6705. };
  6706. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6707. if (!primitive.targets) {
  6708. return Promise.resolve();
  6709. }
  6710. var promises = new Array();
  6711. var morphTargetManager = babylonMesh.morphTargetManager;
  6712. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6713. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6714. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6715. }
  6716. return Promise.all(promises).then(function () { });
  6717. };
  6718. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6719. var _this = this;
  6720. var promises = new Array();
  6721. var loadAttribute = function (attribute, kind, setData) {
  6722. if (attributes[attribute] == undefined) {
  6723. return;
  6724. }
  6725. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6726. if (!babylonVertexBuffer) {
  6727. return;
  6728. }
  6729. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6730. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6731. setData(babylonVertexBuffer, data);
  6732. }));
  6733. };
  6734. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6735. var positions = new Float32Array(data.length);
  6736. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6737. positions[index] = data[index] + value;
  6738. });
  6739. babylonMorphTarget.setPositions(positions);
  6740. });
  6741. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6742. var normals = new Float32Array(data.length);
  6743. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6744. normals[index] = data[index] + value;
  6745. });
  6746. babylonMorphTarget.setNormals(normals);
  6747. });
  6748. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6749. var tangents = new Float32Array(data.length / 3 * 4);
  6750. var dataIndex = 0;
  6751. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6752. // Tangent data for morph targets is stored as xyz delta.
  6753. // The vertexData.tangent is stored as xyzw.
  6754. // So we need to skip every fourth vertexData.tangent.
  6755. if (((index + 1) % 4) !== 0) {
  6756. tangents[dataIndex] = data[dataIndex] + value;
  6757. dataIndex++;
  6758. }
  6759. });
  6760. babylonMorphTarget.setTangents(tangents);
  6761. });
  6762. return Promise.all(promises).then(function () { });
  6763. };
  6764. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6765. // Ignore the TRS of skinned nodes.
  6766. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6767. if (node.skin != undefined) {
  6768. return;
  6769. }
  6770. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6771. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6772. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6773. if (node.matrix) {
  6774. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6775. matrix.decompose(scaling, rotation, position);
  6776. }
  6777. else {
  6778. if (node.translation) {
  6779. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6780. }
  6781. if (node.rotation) {
  6782. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6783. }
  6784. if (node.scale) {
  6785. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6786. }
  6787. }
  6788. babylonNode.position = position;
  6789. babylonNode.rotationQuaternion = rotation;
  6790. babylonNode.scaling = scaling;
  6791. };
  6792. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6793. var _this = this;
  6794. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6795. if (extensionPromise) {
  6796. return extensionPromise;
  6797. }
  6798. var assignSkeleton = function (skeleton) {
  6799. _this._forEachPrimitive(node, function (babylonMesh) {
  6800. babylonMesh.skeleton = skeleton;
  6801. });
  6802. };
  6803. if (skin._data) {
  6804. assignSkeleton(skin._data.babylonSkeleton);
  6805. return skin._data.promise;
  6806. }
  6807. var skeletonId = "skeleton" + skin.index;
  6808. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6809. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6810. this._babylonScene._blockEntityCollection = false;
  6811. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6812. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6813. this._loadBones(context, skin, babylonSkeleton);
  6814. assignSkeleton(babylonSkeleton);
  6815. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6816. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6817. });
  6818. skin._data = {
  6819. babylonSkeleton: babylonSkeleton,
  6820. promise: promise
  6821. };
  6822. return promise;
  6823. };
  6824. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6825. var babylonBones = {};
  6826. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6827. var index = _a[_i];
  6828. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6829. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6830. }
  6831. };
  6832. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6833. var babylonBone = babylonBones[node.index];
  6834. if (babylonBone) {
  6835. return babylonBone;
  6836. }
  6837. var babylonParentBone = null;
  6838. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6839. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6840. }
  6841. var boneIndex = skin.joints.indexOf(node.index);
  6842. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6843. babylonBones[node.index] = babylonBone;
  6844. node._babylonBones = node._babylonBones || [];
  6845. node._babylonBones.push(babylonBone);
  6846. return babylonBone;
  6847. };
  6848. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6849. if (skin.inverseBindMatrices == undefined) {
  6850. return Promise.resolve(null);
  6851. }
  6852. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6853. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6854. };
  6855. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6856. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6857. var babylonBone = _a[_i];
  6858. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6859. var boneIndex = babylonBone._index;
  6860. if (inverseBindMatricesData && boneIndex !== -1) {
  6861. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6862. baseMatrix.invertToRef(baseMatrix);
  6863. }
  6864. var babylonParentBone = babylonBone.getParent();
  6865. if (babylonParentBone) {
  6866. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6867. }
  6868. babylonBone.updateMatrix(baseMatrix, false, false);
  6869. babylonBone._updateDifferenceMatrix(undefined, false);
  6870. }
  6871. };
  6872. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6873. return node.matrix ?
  6874. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6875. 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());
  6876. };
  6877. /**
  6878. * Loads a glTF camera.
  6879. * @param context The context when loading the asset
  6880. * @param camera The glTF camera property
  6881. * @param assign A function called synchronously after parsing the glTF properties
  6882. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6883. */
  6884. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6885. if (assign === void 0) { assign = function () { }; }
  6886. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6887. if (extensionPromise) {
  6888. return extensionPromise;
  6889. }
  6890. var promises = new Array();
  6891. this.logOpen(context + " " + (camera.name || ""));
  6892. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6893. 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);
  6894. this._babylonScene._blockEntityCollection = false;
  6895. babylonCamera.ignoreParentScaling = true;
  6896. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6897. switch (camera.type) {
  6898. case "perspective" /* PERSPECTIVE */: {
  6899. var perspective = camera.perspective;
  6900. if (!perspective) {
  6901. throw new Error(context + ": Camera perspective properties are missing");
  6902. }
  6903. babylonCamera.fov = perspective.yfov;
  6904. babylonCamera.minZ = perspective.znear;
  6905. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6906. break;
  6907. }
  6908. case "orthographic" /* ORTHOGRAPHIC */: {
  6909. if (!camera.orthographic) {
  6910. throw new Error(context + ": Camera orthographic properties are missing");
  6911. }
  6912. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6913. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6914. babylonCamera.orthoRight = camera.orthographic.xmag;
  6915. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6916. babylonCamera.orthoTop = camera.orthographic.ymag;
  6917. babylonCamera.minZ = camera.orthographic.znear;
  6918. babylonCamera.maxZ = camera.orthographic.zfar;
  6919. break;
  6920. }
  6921. default: {
  6922. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6923. }
  6924. }
  6925. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6926. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6927. assign(babylonCamera);
  6928. this.logClose();
  6929. return Promise.all(promises).then(function () {
  6930. return babylonCamera;
  6931. });
  6932. };
  6933. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6934. var animations = this._gltf.animations;
  6935. if (!animations) {
  6936. return Promise.resolve();
  6937. }
  6938. var promises = new Array();
  6939. for (var index = 0; index < animations.length; index++) {
  6940. var animation = animations[index];
  6941. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6942. }
  6943. return Promise.all(promises).then(function () { });
  6944. };
  6945. /**
  6946. * Loads a glTF animation.
  6947. * @param context The context when loading the asset
  6948. * @param animation The glTF animation property
  6949. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6950. */
  6951. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6952. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6953. if (promise) {
  6954. return promise;
  6955. }
  6956. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6957. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6958. this._babylonScene._blockEntityCollection = false;
  6959. animation._babylonAnimationGroup = babylonAnimationGroup;
  6960. var promises = new Array();
  6961. ArrayItem.Assign(animation.channels);
  6962. ArrayItem.Assign(animation.samplers);
  6963. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6964. var channel = _a[_i];
  6965. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6966. }
  6967. return Promise.all(promises).then(function () {
  6968. babylonAnimationGroup.normalize(0);
  6969. return babylonAnimationGroup;
  6970. });
  6971. };
  6972. /**
  6973. * @hidden Loads a glTF animation channel.
  6974. * @param context The context when loading the asset
  6975. * @param animationContext The context of the animation when loading the asset
  6976. * @param animation The glTF animation property
  6977. * @param channel The glTF animation channel property
  6978. * @param babylonAnimationGroup The babylon animation group property
  6979. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6980. * @returns A void promise when the channel load is complete
  6981. */
  6982. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6983. var _this = this;
  6984. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6985. if (channel.target.node == undefined) {
  6986. return Promise.resolve();
  6987. }
  6988. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6989. // Ignore animations that have no animation targets.
  6990. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6991. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6992. return Promise.resolve();
  6993. }
  6994. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6995. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6996. var targetPath;
  6997. var animationType;
  6998. switch (channel.target.path) {
  6999. case "translation" /* TRANSLATION */: {
  7000. targetPath = "position";
  7001. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  7002. break;
  7003. }
  7004. case "rotation" /* ROTATION */: {
  7005. targetPath = "rotationQuaternion";
  7006. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  7007. break;
  7008. }
  7009. case "scale" /* SCALE */: {
  7010. targetPath = "scaling";
  7011. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  7012. break;
  7013. }
  7014. case "weights" /* WEIGHTS */: {
  7015. targetPath = "influence";
  7016. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  7017. break;
  7018. }
  7019. default: {
  7020. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  7021. }
  7022. }
  7023. var outputBufferOffset = 0;
  7024. var getNextOutputValue;
  7025. switch (targetPath) {
  7026. case "position": {
  7027. getNextOutputValue = function () {
  7028. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7029. outputBufferOffset += 3;
  7030. return value;
  7031. };
  7032. break;
  7033. }
  7034. case "rotationQuaternion": {
  7035. getNextOutputValue = function () {
  7036. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  7037. outputBufferOffset += 4;
  7038. return value;
  7039. };
  7040. break;
  7041. }
  7042. case "scaling": {
  7043. getNextOutputValue = function () {
  7044. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7045. outputBufferOffset += 3;
  7046. return value;
  7047. };
  7048. break;
  7049. }
  7050. case "influence": {
  7051. getNextOutputValue = function () {
  7052. var value = new Array(targetNode._numMorphTargets);
  7053. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  7054. value[i] = data.output[outputBufferOffset++];
  7055. }
  7056. return value;
  7057. };
  7058. break;
  7059. }
  7060. }
  7061. var getNextKey;
  7062. switch (data.interpolation) {
  7063. case "STEP" /* STEP */: {
  7064. getNextKey = function (frameIndex) { return ({
  7065. frame: data.input[frameIndex],
  7066. value: getNextOutputValue(),
  7067. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  7068. }); };
  7069. break;
  7070. }
  7071. case "LINEAR" /* LINEAR */: {
  7072. getNextKey = function (frameIndex) { return ({
  7073. frame: data.input[frameIndex],
  7074. value: getNextOutputValue()
  7075. }); };
  7076. break;
  7077. }
  7078. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7079. getNextKey = function (frameIndex) { return ({
  7080. frame: data.input[frameIndex],
  7081. inTangent: getNextOutputValue(),
  7082. value: getNextOutputValue(),
  7083. outTangent: getNextOutputValue()
  7084. }); };
  7085. break;
  7086. }
  7087. }
  7088. var keys = new Array(data.input.length);
  7089. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  7090. keys[frameIndex] = getNextKey(frameIndex);
  7091. }
  7092. if (targetPath === "influence") {
  7093. var _loop_2 = function (targetIndex) {
  7094. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7095. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7096. babylonAnimation.setKeys(keys.map(function (key) { return ({
  7097. frame: key.frame,
  7098. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  7099. value: key.value[targetIndex],
  7100. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  7101. }); }));
  7102. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  7103. var babylonMesh = babylonAbstractMesh;
  7104. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  7105. var babylonAnimationClone = babylonAnimation.clone();
  7106. morphTarget.animations.push(babylonAnimationClone);
  7107. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  7108. });
  7109. };
  7110. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  7111. _loop_2(targetIndex);
  7112. }
  7113. }
  7114. else {
  7115. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7116. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7117. babylonAnimation.setKeys(keys);
  7118. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  7119. animationTargetOverride.animations.push(babylonAnimation);
  7120. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  7121. }
  7122. else {
  7123. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  7124. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  7125. }
  7126. }
  7127. });
  7128. };
  7129. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  7130. if (sampler._data) {
  7131. return sampler._data;
  7132. }
  7133. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  7134. switch (interpolation) {
  7135. case "STEP" /* STEP */:
  7136. case "LINEAR" /* LINEAR */:
  7137. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7138. break;
  7139. }
  7140. default: {
  7141. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  7142. }
  7143. }
  7144. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  7145. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  7146. sampler._data = Promise.all([
  7147. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  7148. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  7149. ]).then(function (_a) {
  7150. var inputData = _a[0], outputData = _a[1];
  7151. return {
  7152. input: inputData,
  7153. interpolation: interpolation,
  7154. output: outputData,
  7155. };
  7156. });
  7157. return sampler._data;
  7158. };
  7159. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7160. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  7161. if (extensionPromise) {
  7162. return extensionPromise;
  7163. }
  7164. if (!buffer._data) {
  7165. if (buffer.uri) {
  7166. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  7167. }
  7168. else {
  7169. if (!this._bin) {
  7170. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  7171. }
  7172. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  7173. }
  7174. }
  7175. return buffer._data.then(function (data) {
  7176. try {
  7177. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  7178. }
  7179. catch (e) {
  7180. throw new Error(context + ": " + e.message);
  7181. }
  7182. });
  7183. };
  7184. /**
  7185. * Loads a glTF buffer view.
  7186. * @param context The context when loading the asset
  7187. * @param bufferView The glTF buffer view property
  7188. * @returns A promise that resolves with the loaded data when the load is complete
  7189. */
  7190. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  7191. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  7192. if (extensionPromise) {
  7193. return extensionPromise;
  7194. }
  7195. if (bufferView._data) {
  7196. return bufferView._data;
  7197. }
  7198. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  7199. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  7200. return bufferView._data;
  7201. };
  7202. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  7203. var _this = this;
  7204. if (accessor._data) {
  7205. return accessor._data;
  7206. }
  7207. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  7208. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  7209. var length = numComponents * accessor.count;
  7210. if (accessor.bufferView == undefined) {
  7211. accessor._data = Promise.resolve(new constructor(length));
  7212. }
  7213. else {
  7214. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7215. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  7216. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  7217. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  7218. }
  7219. else {
  7220. var typedArray_1 = new constructor(length);
  7221. 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) {
  7222. typedArray_1[index] = value;
  7223. });
  7224. return typedArray_1;
  7225. }
  7226. });
  7227. }
  7228. if (accessor.sparse) {
  7229. var sparse_1 = accessor.sparse;
  7230. accessor._data = accessor._data.then(function (data) {
  7231. var typedArray = data;
  7232. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  7233. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  7234. return Promise.all([
  7235. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  7236. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  7237. ]).then(function (_a) {
  7238. var indicesData = _a[0], valuesData = _a[1];
  7239. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  7240. var sparseLength = numComponents * sparse_1.count;
  7241. var values;
  7242. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  7243. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7244. }
  7245. else {
  7246. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7247. values = new constructor(sparseLength);
  7248. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  7249. values[index] = value;
  7250. });
  7251. }
  7252. var valuesIndex = 0;
  7253. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  7254. var dataIndex = indices[indicesIndex] * numComponents;
  7255. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  7256. typedArray[dataIndex++] = values[valuesIndex++];
  7257. }
  7258. }
  7259. return typedArray;
  7260. });
  7261. });
  7262. }
  7263. return accessor._data;
  7264. };
  7265. /** @hidden */
  7266. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  7267. return this._loadAccessorAsync(context, accessor, Float32Array);
  7268. };
  7269. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  7270. if (accessor.type !== "SCALAR" /* SCALAR */) {
  7271. throw new Error(context + "/type: Invalid value " + accessor.type);
  7272. }
  7273. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  7274. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  7275. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  7276. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  7277. }
  7278. if (accessor._data) {
  7279. return accessor._data;
  7280. }
  7281. if (accessor.sparse) {
  7282. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  7283. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  7284. }
  7285. else {
  7286. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7287. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7288. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  7289. });
  7290. }
  7291. return accessor._data;
  7292. };
  7293. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  7294. var _this = this;
  7295. if (bufferView._babylonBuffer) {
  7296. return bufferView._babylonBuffer;
  7297. }
  7298. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7299. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  7300. });
  7301. return bufferView._babylonBuffer;
  7302. };
  7303. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  7304. var _this = this;
  7305. if (accessor._babylonVertexBuffer) {
  7306. return accessor._babylonVertexBuffer;
  7307. }
  7308. if (accessor.sparse) {
  7309. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7310. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7311. });
  7312. }
  7313. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  7314. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  7315. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  7316. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7317. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7318. });
  7319. }
  7320. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  7321. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  7322. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  7323. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7324. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7325. });
  7326. }
  7327. else {
  7328. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7329. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  7330. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  7331. 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);
  7332. });
  7333. }
  7334. return accessor._babylonVertexBuffer;
  7335. };
  7336. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  7337. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7338. throw new Error(context + ": Material type not supported");
  7339. }
  7340. var promises = new Array();
  7341. if (properties) {
  7342. if (properties.baseColorFactor) {
  7343. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  7344. babylonMaterial.alpha = properties.baseColorFactor[3];
  7345. }
  7346. else {
  7347. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  7348. }
  7349. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  7350. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  7351. if (properties.baseColorTexture) {
  7352. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  7353. texture.name = babylonMaterial.name + " (Base Color)";
  7354. babylonMaterial.albedoTexture = texture;
  7355. }));
  7356. }
  7357. if (properties.metallicRoughnessTexture) {
  7358. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  7359. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  7360. babylonMaterial.metallicTexture = texture;
  7361. }));
  7362. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  7363. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  7364. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  7365. }
  7366. }
  7367. return Promise.all(promises).then(function () { });
  7368. };
  7369. /** @hidden */
  7370. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7371. if (assign === void 0) { assign = function () { }; }
  7372. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  7373. if (extensionPromise) {
  7374. return extensionPromise;
  7375. }
  7376. material._data = material._data || {};
  7377. var babylonData = material._data[babylonDrawMode];
  7378. if (!babylonData) {
  7379. this.logOpen(context + " " + (material.name || ""));
  7380. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  7381. babylonData = {
  7382. babylonMaterial: babylonMaterial,
  7383. babylonMeshes: [],
  7384. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  7385. };
  7386. material._data[babylonDrawMode] = babylonData;
  7387. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  7388. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7389. this.logClose();
  7390. }
  7391. babylonData.babylonMeshes.push(babylonMesh);
  7392. babylonMesh.onDisposeObservable.addOnce(function () {
  7393. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  7394. if (index !== -1) {
  7395. babylonData.babylonMeshes.splice(index, 1);
  7396. }
  7397. });
  7398. assign(babylonData.babylonMaterial);
  7399. return babylonData.promise.then(function () {
  7400. return babylonData.babylonMaterial;
  7401. });
  7402. };
  7403. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  7404. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7405. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  7406. this._babylonScene._blockEntityCollection = false;
  7407. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  7408. babylonMaterial.fillMode = babylonDrawMode;
  7409. babylonMaterial.enableSpecularAntiAliasing = true;
  7410. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  7411. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  7412. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7413. babylonMaterial.metallic = 1;
  7414. babylonMaterial.roughness = 1;
  7415. return babylonMaterial;
  7416. };
  7417. /**
  7418. * Creates a Babylon material from a glTF material.
  7419. * @param context The context when loading the asset
  7420. * @param material The glTF material property
  7421. * @param babylonDrawMode The draw mode for the Babylon material
  7422. * @returns The Babylon material
  7423. */
  7424. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  7425. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  7426. if (extensionPromise) {
  7427. return extensionPromise;
  7428. }
  7429. var name = material.name || "material" + material.index;
  7430. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  7431. return babylonMaterial;
  7432. };
  7433. /**
  7434. * Loads properties from a glTF material into a Babylon material.
  7435. * @param context The context when loading the asset
  7436. * @param material The glTF material property
  7437. * @param babylonMaterial The Babylon material
  7438. * @returns A promise that resolves when the load is complete
  7439. */
  7440. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7441. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  7442. if (extensionPromise) {
  7443. return extensionPromise;
  7444. }
  7445. var promises = new Array();
  7446. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  7447. if (material.pbrMetallicRoughness) {
  7448. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  7449. }
  7450. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  7451. return Promise.all(promises).then(function () { });
  7452. };
  7453. /**
  7454. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  7455. * @param context The context when loading the asset
  7456. * @param material The glTF material property
  7457. * @param babylonMaterial The Babylon material
  7458. * @returns A promise that resolves when the load is complete
  7459. */
  7460. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  7461. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7462. throw new Error(context + ": Material type not supported");
  7463. }
  7464. var promises = new Array();
  7465. 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);
  7466. if (material.doubleSided) {
  7467. babylonMaterial.backFaceCulling = false;
  7468. babylonMaterial.twoSidedLighting = true;
  7469. }
  7470. if (material.normalTexture) {
  7471. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  7472. texture.name = babylonMaterial.name + " (Normal)";
  7473. babylonMaterial.bumpTexture = texture;
  7474. }));
  7475. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  7476. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  7477. if (material.normalTexture.scale != undefined) {
  7478. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  7479. }
  7480. babylonMaterial.forceIrradianceInFragment = true;
  7481. }
  7482. if (material.occlusionTexture) {
  7483. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  7484. texture.name = babylonMaterial.name + " (Occlusion)";
  7485. babylonMaterial.ambientTexture = texture;
  7486. }));
  7487. babylonMaterial.useAmbientInGrayScale = true;
  7488. if (material.occlusionTexture.strength != undefined) {
  7489. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  7490. }
  7491. }
  7492. if (material.emissiveTexture) {
  7493. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  7494. texture.name = babylonMaterial.name + " (Emissive)";
  7495. babylonMaterial.emissiveTexture = texture;
  7496. }));
  7497. }
  7498. return Promise.all(promises).then(function () { });
  7499. };
  7500. /**
  7501. * Loads the alpha properties from a glTF material into a Babylon material.
  7502. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  7503. * @param context The context when loading the asset
  7504. * @param material The glTF material property
  7505. * @param babylonMaterial The Babylon material
  7506. */
  7507. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  7508. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7509. throw new Error(context + ": Material type not supported");
  7510. }
  7511. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  7512. switch (alphaMode) {
  7513. case "OPAQUE" /* OPAQUE */: {
  7514. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7515. break;
  7516. }
  7517. case "MASK" /* MASK */: {
  7518. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  7519. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  7520. if (babylonMaterial.albedoTexture) {
  7521. babylonMaterial.albedoTexture.hasAlpha = true;
  7522. }
  7523. break;
  7524. }
  7525. case "BLEND" /* BLEND */: {
  7526. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  7527. if (babylonMaterial.albedoTexture) {
  7528. babylonMaterial.albedoTexture.hasAlpha = true;
  7529. babylonMaterial.useAlphaFromAlbedoTexture = true;
  7530. }
  7531. break;
  7532. }
  7533. default: {
  7534. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  7535. }
  7536. }
  7537. };
  7538. /**
  7539. * Loads a glTF texture info.
  7540. * @param context The context when loading the asset
  7541. * @param textureInfo The glTF texture info property
  7542. * @param assign A function called synchronously after parsing the glTF properties
  7543. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  7544. */
  7545. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  7546. var _this = this;
  7547. if (assign === void 0) { assign = function () { }; }
  7548. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  7549. if (extensionPromise) {
  7550. return extensionPromise;
  7551. }
  7552. this.logOpen("" + context);
  7553. if (textureInfo.texCoord >= 2) {
  7554. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  7555. }
  7556. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  7557. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  7558. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  7559. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  7560. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  7561. assign(babylonTexture);
  7562. });
  7563. this.logClose();
  7564. return promise;
  7565. };
  7566. /** @hidden */
  7567. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  7568. if (assign === void 0) { assign = function () { }; }
  7569. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  7570. if (extensionPromise) {
  7571. return extensionPromise;
  7572. }
  7573. this.logOpen(context + " " + (texture.name || ""));
  7574. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  7575. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  7576. var promise = this._createTextureAsync(context, sampler, image, assign);
  7577. this.logClose();
  7578. return promise;
  7579. };
  7580. /** @hidden */
  7581. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign) {
  7582. var _this = this;
  7583. if (assign === void 0) { assign = function () { }; }
  7584. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  7585. var promises = new Array();
  7586. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  7587. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7588. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  7589. if (!_this._disposed) {
  7590. deferred.resolve();
  7591. }
  7592. }, function (message, exception) {
  7593. if (!_this._disposed) {
  7594. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  7595. }
  7596. }, undefined, undefined, undefined, image.mimeType);
  7597. this._babylonScene._blockEntityCollection = false;
  7598. promises.push(deferred.promise);
  7599. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  7600. var name = image.uri || _this._fileName + "#image" + image.index;
  7601. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  7602. babylonTexture.updateURL(dataUrl, data);
  7603. }));
  7604. babylonTexture.wrapU = samplerData.wrapU;
  7605. babylonTexture.wrapV = samplerData.wrapV;
  7606. assign(babylonTexture);
  7607. return Promise.all(promises).then(function () {
  7608. return babylonTexture;
  7609. });
  7610. };
  7611. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  7612. if (!sampler._data) {
  7613. sampler._data = {
  7614. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  7615. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  7616. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  7617. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  7618. };
  7619. }
  7620. return sampler._data;
  7621. };
  7622. /**
  7623. * Loads a glTF image.
  7624. * @param context The context when loading the asset
  7625. * @param image The glTF image property
  7626. * @returns A promise that resolves with the loaded data when the load is complete
  7627. */
  7628. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  7629. if (!image._data) {
  7630. this.logOpen(context + " " + (image.name || ""));
  7631. if (image.uri) {
  7632. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  7633. }
  7634. else {
  7635. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  7636. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  7637. }
  7638. this.logClose();
  7639. }
  7640. return image._data;
  7641. };
  7642. /**
  7643. * Loads a glTF uri.
  7644. * @param context The context when loading the asset
  7645. * @param property The glTF property associated with the uri
  7646. * @param uri The base64 or relative uri
  7647. * @returns A promise that resolves with the loaded data when the load is complete
  7648. */
  7649. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  7650. var _this = this;
  7651. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  7652. if (extensionPromise) {
  7653. return extensionPromise;
  7654. }
  7655. if (!GLTFLoader._ValidateUri(uri)) {
  7656. throw new Error(context + ": '" + uri + "' is invalid");
  7657. }
  7658. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7659. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7660. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7661. return Promise.resolve(data);
  7662. }
  7663. this.log("Loading " + uri);
  7664. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7665. return new Promise(function (resolve, reject) {
  7666. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  7667. if (!_this._disposed) {
  7668. _this.log("Loaded " + uri + " (" + data.byteLength + " bytes)");
  7669. resolve(new Uint8Array(data));
  7670. }
  7671. }, true, function (request) {
  7672. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7673. });
  7674. });
  7675. });
  7676. };
  7677. /**
  7678. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7679. * @param babylonObject the Babylon object with metadata
  7680. * @param pointer the JSON pointer
  7681. */
  7682. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7683. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7684. var gltf = (metadata.gltf = metadata.gltf || {});
  7685. var pointers = (gltf.pointers = gltf.pointers || []);
  7686. pointers.push(pointer);
  7687. };
  7688. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7689. // Set defaults if undefined
  7690. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7691. switch (mode) {
  7692. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7693. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7694. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7695. default:
  7696. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7697. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7698. }
  7699. };
  7700. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7701. // Set defaults if undefined
  7702. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7703. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7704. if (magFilter === 9729 /* LINEAR */) {
  7705. switch (minFilter) {
  7706. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7707. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7708. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7709. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7710. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7711. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7712. default:
  7713. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7714. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7715. }
  7716. }
  7717. else {
  7718. if (magFilter !== 9728 /* NEAREST */) {
  7719. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7720. }
  7721. switch (minFilter) {
  7722. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7723. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7724. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7725. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7726. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7727. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7728. default:
  7729. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7730. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7731. }
  7732. }
  7733. };
  7734. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7735. switch (componentType) {
  7736. case 5120 /* BYTE */: return Int8Array;
  7737. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7738. case 5122 /* SHORT */: return Int16Array;
  7739. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7740. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7741. case 5126 /* FLOAT */: return Float32Array;
  7742. default: throw new Error(context + ": Invalid component type " + componentType);
  7743. }
  7744. };
  7745. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7746. var buffer = bufferView.buffer;
  7747. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7748. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7749. try {
  7750. return new constructor(buffer, byteOffset, length);
  7751. }
  7752. catch (e) {
  7753. throw new Error(context + ": " + e);
  7754. }
  7755. };
  7756. GLTFLoader._GetNumComponents = function (context, type) {
  7757. switch (type) {
  7758. case "SCALAR": return 1;
  7759. case "VEC2": return 2;
  7760. case "VEC3": return 3;
  7761. case "VEC4": return 4;
  7762. case "MAT2": return 4;
  7763. case "MAT3": return 9;
  7764. case "MAT4": return 16;
  7765. }
  7766. throw new Error(context + ": Invalid type (" + type + ")");
  7767. };
  7768. GLTFLoader._ValidateUri = function (uri) {
  7769. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7770. };
  7771. /** @hidden */
  7772. GLTFLoader._GetDrawMode = function (context, mode) {
  7773. if (mode == undefined) {
  7774. mode = 4 /* TRIANGLES */;
  7775. }
  7776. switch (mode) {
  7777. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7778. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7779. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7780. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7781. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7782. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7783. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7784. }
  7785. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7786. };
  7787. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7788. var _this = this;
  7789. this._parent._startPerformanceCounter("Compile materials");
  7790. var promises = new Array();
  7791. if (this._gltf.materials) {
  7792. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7793. var material = _a[_i];
  7794. if (material._data) {
  7795. for (var babylonDrawMode in material._data) {
  7796. var babylonData = material._data[babylonDrawMode];
  7797. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7798. var babylonMesh = _c[_b];
  7799. // Ensure nonUniformScaling is set if necessary.
  7800. babylonMesh.computeWorldMatrix(true);
  7801. var babylonMaterial = babylonData.babylonMaterial;
  7802. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7803. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7804. if (this._parent.useClipPlane) {
  7805. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7806. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7807. }
  7808. }
  7809. }
  7810. }
  7811. }
  7812. }
  7813. return Promise.all(promises).then(function () {
  7814. _this._parent._endPerformanceCounter("Compile materials");
  7815. });
  7816. };
  7817. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7818. var _this = this;
  7819. this._parent._startPerformanceCounter("Compile shadow generators");
  7820. var promises = new Array();
  7821. var lights = this._babylonScene.lights;
  7822. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7823. var light = lights_1[_i];
  7824. var generator = light.getShadowGenerator();
  7825. if (generator) {
  7826. promises.push(generator.forceCompilationAsync());
  7827. }
  7828. }
  7829. return Promise.all(promises).then(function () {
  7830. _this._parent._endPerformanceCounter("Compile shadow generators");
  7831. });
  7832. };
  7833. GLTFLoader.prototype._forEachExtensions = function (action) {
  7834. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7835. var extension = _a[_i];
  7836. if (extension.enabled) {
  7837. action(extension);
  7838. }
  7839. }
  7840. };
  7841. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7842. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7843. var extension = _a[_i];
  7844. if (extension.enabled) {
  7845. var id = extension.name + "." + functionName;
  7846. var loaderProperty = property;
  7847. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7848. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7849. if (!activeLoaderExtensionFunctions[id]) {
  7850. activeLoaderExtensionFunctions[id] = true;
  7851. try {
  7852. var result = actionAsync(extension);
  7853. if (result) {
  7854. return result;
  7855. }
  7856. }
  7857. finally {
  7858. delete activeLoaderExtensionFunctions[id];
  7859. }
  7860. }
  7861. }
  7862. }
  7863. return null;
  7864. };
  7865. GLTFLoader.prototype._extensionsOnLoading = function () {
  7866. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7867. };
  7868. GLTFLoader.prototype._extensionsOnReady = function () {
  7869. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7870. };
  7871. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7872. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7873. };
  7874. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7875. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7876. };
  7877. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7878. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7879. };
  7880. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7881. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7882. };
  7883. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7884. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7885. };
  7886. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7887. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7888. };
  7889. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7890. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7891. };
  7892. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7893. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7894. };
  7895. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7896. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7897. };
  7898. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  7899. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  7900. };
  7901. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7902. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7903. };
  7904. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7905. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7906. };
  7907. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7908. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7909. };
  7910. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7911. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7912. };
  7913. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7914. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7915. };
  7916. /**
  7917. * Helper method called by a loader extension to load an glTF extension.
  7918. * @param context The context when loading the asset
  7919. * @param property The glTF property to load the extension from
  7920. * @param extensionName The name of the extension to load
  7921. * @param actionAsync The action to run
  7922. * @returns The promise returned by actionAsync or null if the extension does not exist
  7923. */
  7924. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7925. if (!property.extensions) {
  7926. return null;
  7927. }
  7928. var extensions = property.extensions;
  7929. var extension = extensions[extensionName];
  7930. if (!extension) {
  7931. return null;
  7932. }
  7933. return actionAsync(context + "/extensions/" + extensionName, extension);
  7934. };
  7935. /**
  7936. * Helper method called by a loader extension to load a glTF extra.
  7937. * @param context The context when loading the asset
  7938. * @param property The glTF property to load the extra from
  7939. * @param extensionName The name of the extension to load
  7940. * @param actionAsync The action to run
  7941. * @returns The promise returned by actionAsync or null if the extra does not exist
  7942. */
  7943. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7944. if (!property.extras) {
  7945. return null;
  7946. }
  7947. var extras = property.extras;
  7948. var extra = extras[extensionName];
  7949. if (!extra) {
  7950. return null;
  7951. }
  7952. return actionAsync(context + "/extras/" + extensionName, extra);
  7953. };
  7954. /**
  7955. * Checks for presence of an extension.
  7956. * @param name The name of the extension to check
  7957. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7958. */
  7959. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7960. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7961. };
  7962. /**
  7963. * Increments the indentation level and logs a message.
  7964. * @param message The message to log
  7965. */
  7966. GLTFLoader.prototype.logOpen = function (message) {
  7967. this._parent._logOpen(message);
  7968. };
  7969. /**
  7970. * Decrements the indentation level.
  7971. */
  7972. GLTFLoader.prototype.logClose = function () {
  7973. this._parent._logClose();
  7974. };
  7975. /**
  7976. * Logs a message
  7977. * @param message The message to log
  7978. */
  7979. GLTFLoader.prototype.log = function (message) {
  7980. this._parent._log(message);
  7981. };
  7982. /**
  7983. * Starts a performance counter.
  7984. * @param counterName The name of the performance counter
  7985. */
  7986. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7987. this._parent._startPerformanceCounter(counterName);
  7988. };
  7989. /**
  7990. * Ends a performance counter.
  7991. * @param counterName The name of the performance counter
  7992. */
  7993. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7994. this._parent._endPerformanceCounter(counterName);
  7995. };
  7996. GLTFLoader._RegisteredExtensions = {};
  7997. /**
  7998. * The default glTF sampler.
  7999. */
  8000. GLTFLoader.DefaultSampler = { index: -1 };
  8001. return GLTFLoader;
  8002. }());
  8003. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  8004. /***/ }),
  8005. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  8006. /*!******************************************!*\
  8007. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  8008. \******************************************/
  8009. /*! no static exports found */
  8010. /***/ (function(module, exports) {
  8011. /***/ }),
  8012. /***/ "./glTF/2.0/index.ts":
  8013. /*!***************************!*\
  8014. !*** ./glTF/2.0/index.ts ***!
  8015. \***************************/
  8016. /*! exports provided: ArrayItem, GLTFLoader, EXT_lights_image_based, EXT_mesh_gpu_instancing, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  8017. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8018. "use strict";
  8019. __webpack_require__.r(__webpack_exports__);
  8020. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  8021. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  8022. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  8023. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  8024. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  8025. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  8026. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  8027. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  8028. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  8029. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  8030. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  8031. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  8032. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  8033. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_ior"]; });
  8034. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_variants"]; });
  8035. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_transmission"]; });
  8036. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  8037. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_basisu"]; });
  8038. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  8039. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_xmp"]; });
  8040. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  8041. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  8042. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  8043. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  8044. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  8045. /***/ }),
  8046. /***/ "./glTF/glTFFileLoader.ts":
  8047. /*!********************************!*\
  8048. !*** ./glTF/glTFFileLoader.ts ***!
  8049. \********************************/
  8050. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  8051. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8052. "use strict";
  8053. __webpack_require__.r(__webpack_exports__);
  8054. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  8055. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  8056. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  8057. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  8058. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  8059. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  8060. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8061. /**
  8062. * Mode that determines the coordinate system to use.
  8063. */
  8064. var GLTFLoaderCoordinateSystemMode;
  8065. (function (GLTFLoaderCoordinateSystemMode) {
  8066. /**
  8067. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8068. */
  8069. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  8070. /**
  8071. * Sets the useRightHandedSystem flag on the scene.
  8072. */
  8073. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  8074. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  8075. /**
  8076. * Mode that determines what animations will start.
  8077. */
  8078. var GLTFLoaderAnimationStartMode;
  8079. (function (GLTFLoaderAnimationStartMode) {
  8080. /**
  8081. * No animation will start.
  8082. */
  8083. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  8084. /**
  8085. * The first animation will start.
  8086. */
  8087. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  8088. /**
  8089. * All animations will start.
  8090. */
  8091. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  8092. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  8093. /**
  8094. * Loader state.
  8095. */
  8096. var GLTFLoaderState;
  8097. (function (GLTFLoaderState) {
  8098. /**
  8099. * The asset is loading.
  8100. */
  8101. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  8102. /**
  8103. * The asset is ready for rendering.
  8104. */
  8105. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  8106. /**
  8107. * The asset is completely loaded.
  8108. */
  8109. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  8110. })(GLTFLoaderState || (GLTFLoaderState = {}));
  8111. /**
  8112. * File loader for loading glTF files into a scene.
  8113. */
  8114. var GLTFFileLoader = /** @class */ (function () {
  8115. function GLTFFileLoader() {
  8116. // --------------
  8117. // Common options
  8118. // --------------
  8119. /**
  8120. * Raised when the asset has been parsed
  8121. */
  8122. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8123. // ----------
  8124. // V2 options
  8125. // ----------
  8126. /**
  8127. * The coordinate system mode. Defaults to AUTO.
  8128. */
  8129. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  8130. /**
  8131. * The animation start mode. Defaults to FIRST.
  8132. */
  8133. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  8134. /**
  8135. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  8136. */
  8137. this.compileMaterials = false;
  8138. /**
  8139. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  8140. */
  8141. this.useClipPlane = false;
  8142. /**
  8143. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  8144. */
  8145. this.compileShadowGenerators = false;
  8146. /**
  8147. * Defines if the Alpha blended materials are only applied as coverage.
  8148. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  8149. * If true, no extra effects are applied to transparent pixels.
  8150. */
  8151. this.transparencyAsCoverage = false;
  8152. /**
  8153. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  8154. * Enabling will disable offline support and glTF validator.
  8155. * Defaults to false.
  8156. */
  8157. this.useRangeRequests = false;
  8158. /**
  8159. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  8160. */
  8161. this.createInstances = true;
  8162. /**
  8163. * Function called before loading a url referenced by the asset.
  8164. */
  8165. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8166. /**
  8167. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8168. */
  8169. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8170. /**
  8171. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  8172. */
  8173. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8174. /**
  8175. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  8176. */
  8177. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8178. /**
  8179. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  8180. */
  8181. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8182. /**
  8183. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  8184. * For assets with LODs, raised when all of the LODs are complete.
  8185. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8186. */
  8187. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8188. /**
  8189. * Observable raised when an error occurs.
  8190. */
  8191. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8192. /**
  8193. * Observable raised after the loader is disposed.
  8194. */
  8195. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8196. /**
  8197. * Observable raised after a loader extension is created.
  8198. * Set additional options for a loader extension in this event.
  8199. */
  8200. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8201. /**
  8202. * Defines if the loader should validate the asset.
  8203. */
  8204. this.validate = false;
  8205. /**
  8206. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  8207. */
  8208. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8209. this._loader = null;
  8210. this._requests = new Array();
  8211. /**
  8212. * Name of the loader ("gltf")
  8213. */
  8214. this.name = "gltf";
  8215. /** @hidden */
  8216. this.extensions = {
  8217. ".gltf": { isBinary: false },
  8218. ".glb": { isBinary: true }
  8219. };
  8220. this._logIndentLevel = 0;
  8221. this._loggingEnabled = false;
  8222. /** @hidden */
  8223. this._log = this._logDisabled;
  8224. this._capturePerformanceCounters = false;
  8225. /** @hidden */
  8226. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8227. /** @hidden */
  8228. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8229. }
  8230. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  8231. /**
  8232. * Raised when the asset has been parsed
  8233. */
  8234. set: function (callback) {
  8235. if (this._onParsedObserver) {
  8236. this.onParsedObservable.remove(this._onParsedObserver);
  8237. }
  8238. this._onParsedObserver = this.onParsedObservable.add(callback);
  8239. },
  8240. enumerable: true,
  8241. configurable: true
  8242. });
  8243. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  8244. /**
  8245. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8246. */
  8247. set: function (callback) {
  8248. if (this._onMeshLoadedObserver) {
  8249. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  8250. }
  8251. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  8252. },
  8253. enumerable: true,
  8254. configurable: true
  8255. });
  8256. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  8257. /**
  8258. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  8259. */
  8260. set: function (callback) {
  8261. if (this._onTextureLoadedObserver) {
  8262. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  8263. }
  8264. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  8265. },
  8266. enumerable: true,
  8267. configurable: true
  8268. });
  8269. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  8270. /**
  8271. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  8272. */
  8273. set: function (callback) {
  8274. if (this._onMaterialLoadedObserver) {
  8275. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  8276. }
  8277. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  8278. },
  8279. enumerable: true,
  8280. configurable: true
  8281. });
  8282. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  8283. /**
  8284. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  8285. */
  8286. set: function (callback) {
  8287. if (this._onCameraLoadedObserver) {
  8288. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  8289. }
  8290. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  8291. },
  8292. enumerable: true,
  8293. configurable: true
  8294. });
  8295. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  8296. /**
  8297. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  8298. * For assets with LODs, raised when all of the LODs are complete.
  8299. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8300. */
  8301. set: function (callback) {
  8302. if (this._onCompleteObserver) {
  8303. this.onCompleteObservable.remove(this._onCompleteObserver);
  8304. }
  8305. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  8306. },
  8307. enumerable: true,
  8308. configurable: true
  8309. });
  8310. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  8311. /**
  8312. * Callback raised when an error occurs.
  8313. */
  8314. set: function (callback) {
  8315. if (this._onErrorObserver) {
  8316. this.onErrorObservable.remove(this._onErrorObserver);
  8317. }
  8318. this._onErrorObserver = this.onErrorObservable.add(callback);
  8319. },
  8320. enumerable: true,
  8321. configurable: true
  8322. });
  8323. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  8324. /**
  8325. * Callback raised after the loader is disposed.
  8326. */
  8327. set: function (callback) {
  8328. if (this._onDisposeObserver) {
  8329. this.onDisposeObservable.remove(this._onDisposeObserver);
  8330. }
  8331. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  8332. },
  8333. enumerable: true,
  8334. configurable: true
  8335. });
  8336. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  8337. /**
  8338. * Callback raised after a loader extension is created.
  8339. */
  8340. set: function (callback) {
  8341. if (this._onExtensionLoadedObserver) {
  8342. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  8343. }
  8344. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  8345. },
  8346. enumerable: true,
  8347. configurable: true
  8348. });
  8349. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  8350. /**
  8351. * Defines if the loader logging is enabled.
  8352. */
  8353. get: function () {
  8354. return this._loggingEnabled;
  8355. },
  8356. set: function (value) {
  8357. if (this._loggingEnabled === value) {
  8358. return;
  8359. }
  8360. this._loggingEnabled = value;
  8361. if (this._loggingEnabled) {
  8362. this._log = this._logEnabled;
  8363. }
  8364. else {
  8365. this._log = this._logDisabled;
  8366. }
  8367. },
  8368. enumerable: true,
  8369. configurable: true
  8370. });
  8371. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  8372. /**
  8373. * Defines if the loader should capture performance counters.
  8374. */
  8375. get: function () {
  8376. return this._capturePerformanceCounters;
  8377. },
  8378. set: function (value) {
  8379. if (this._capturePerformanceCounters === value) {
  8380. return;
  8381. }
  8382. this._capturePerformanceCounters = value;
  8383. if (this._capturePerformanceCounters) {
  8384. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  8385. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  8386. }
  8387. else {
  8388. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8389. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8390. }
  8391. },
  8392. enumerable: true,
  8393. configurable: true
  8394. });
  8395. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  8396. /**
  8397. * Callback raised after a loader extension is created.
  8398. */
  8399. set: function (callback) {
  8400. if (this._onValidatedObserver) {
  8401. this.onValidatedObservable.remove(this._onValidatedObserver);
  8402. }
  8403. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  8404. },
  8405. enumerable: true,
  8406. configurable: true
  8407. });
  8408. /**
  8409. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  8410. */
  8411. GLTFFileLoader.prototype.dispose = function () {
  8412. if (this._loader) {
  8413. this._loader.dispose();
  8414. this._loader = null;
  8415. }
  8416. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  8417. var request = _a[_i];
  8418. request.abort();
  8419. }
  8420. this._requests.length = 0;
  8421. delete this._progressCallback;
  8422. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8423. this.onMeshLoadedObservable.clear();
  8424. this.onTextureLoadedObservable.clear();
  8425. this.onMaterialLoadedObservable.clear();
  8426. this.onCameraLoadedObservable.clear();
  8427. this.onCompleteObservable.clear();
  8428. this.onExtensionLoadedObservable.clear();
  8429. this.onDisposeObservable.notifyObservers(undefined);
  8430. this.onDisposeObservable.clear();
  8431. };
  8432. /** @hidden */
  8433. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  8434. var _this = this;
  8435. this._progressCallback = onProgress;
  8436. if (useArrayBuffer) {
  8437. if (this.useRangeRequests) {
  8438. if (this.validate) {
  8439. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  8440. }
  8441. var fileRequest_1 = {
  8442. abort: function () { },
  8443. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  8444. };
  8445. var dataBuffer = {
  8446. readAsync: function (byteOffset, byteLength) {
  8447. return new Promise(function (resolve, reject) {
  8448. _this._requestFile(url, scene, function (data) {
  8449. resolve(new Uint8Array(data));
  8450. }, true, function (error) {
  8451. reject(error);
  8452. }, function (webRequest) {
  8453. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  8454. });
  8455. });
  8456. },
  8457. byteLength: 0
  8458. };
  8459. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  8460. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  8461. onSuccess(loaderData);
  8462. }, onError);
  8463. return fileRequest_1;
  8464. }
  8465. return this._requestFile(url, scene, function (data, request) {
  8466. var arrayBuffer = data;
  8467. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8468. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  8469. byteLength: arrayBuffer.byteLength
  8470. })).then(function (loaderData) {
  8471. onSuccess(loaderData, request);
  8472. }, onError);
  8473. }, true, onError);
  8474. }
  8475. return this._requestFile(url, scene, function (data, request) {
  8476. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  8477. onSuccess({ json: _this._parseJson(data) }, request);
  8478. }, useArrayBuffer, onError);
  8479. };
  8480. /** @hidden */
  8481. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  8482. var _this = this;
  8483. return scene._readFile(file, function (data) {
  8484. _this._validate(scene, data, "file:", file.name);
  8485. if (useArrayBuffer) {
  8486. var arrayBuffer_1 = data;
  8487. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8488. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  8489. byteLength: arrayBuffer_1.byteLength
  8490. })).then(onSuccess, onError);
  8491. }
  8492. else {
  8493. onSuccess({ json: _this._parseJson(data) });
  8494. }
  8495. }, onProgress, useArrayBuffer, onError);
  8496. };
  8497. /** @hidden */
  8498. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  8499. var _this = this;
  8500. return Promise.resolve().then(function () {
  8501. _this.onParsedObservable.notifyObservers(data);
  8502. _this.onParsedObservable.clear();
  8503. _this._log("Loading " + (fileName || ""));
  8504. _this._loader = _this._getLoader(data);
  8505. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  8506. });
  8507. };
  8508. /** @hidden */
  8509. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  8510. var _this = this;
  8511. return Promise.resolve().then(function () {
  8512. _this.onParsedObservable.notifyObservers(data);
  8513. _this.onParsedObservable.clear();
  8514. _this._log("Loading " + (fileName || ""));
  8515. _this._loader = _this._getLoader(data);
  8516. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  8517. });
  8518. };
  8519. /** @hidden */
  8520. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  8521. var _this = this;
  8522. return Promise.resolve().then(function () {
  8523. _this.onParsedObservable.notifyObservers(data);
  8524. _this.onParsedObservable.clear();
  8525. _this._log("Loading " + (fileName || ""));
  8526. _this._loader = _this._getLoader(data);
  8527. // Get materials/textures when loading to add to container
  8528. var materials = [];
  8529. _this.onMaterialLoadedObservable.add(function (material) {
  8530. materials.push(material);
  8531. });
  8532. var textures = [];
  8533. _this.onTextureLoadedObservable.add(function (texture) {
  8534. textures.push(texture);
  8535. });
  8536. var cameras = [];
  8537. _this.onCameraLoadedObservable.add(function (camera) {
  8538. cameras.push(camera);
  8539. });
  8540. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  8541. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  8542. Array.prototype.push.apply(container.meshes, result.meshes);
  8543. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  8544. Array.prototype.push.apply(container.skeletons, result.skeletons);
  8545. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  8546. Array.prototype.push.apply(container.materials, materials);
  8547. Array.prototype.push.apply(container.textures, textures);
  8548. Array.prototype.push.apply(container.lights, result.lights);
  8549. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  8550. Array.prototype.push.apply(container.cameras, cameras);
  8551. return container;
  8552. });
  8553. });
  8554. };
  8555. /** @hidden */
  8556. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  8557. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  8558. };
  8559. /** @hidden */
  8560. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  8561. this._validate(scene, data);
  8562. return { json: this._parseJson(data) };
  8563. };
  8564. /** @hidden */
  8565. GLTFFileLoader.prototype.createPlugin = function () {
  8566. return new GLTFFileLoader();
  8567. };
  8568. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  8569. /**
  8570. * The loader state or null if the loader is not active.
  8571. */
  8572. get: function () {
  8573. return this._loader ? this._loader.state : null;
  8574. },
  8575. enumerable: true,
  8576. configurable: true
  8577. });
  8578. /**
  8579. * Returns a promise that resolves when the asset is completely loaded.
  8580. * @returns a promise that resolves when the asset is completely loaded.
  8581. */
  8582. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  8583. var _this = this;
  8584. return new Promise(function (resolve, reject) {
  8585. _this.onCompleteObservable.addOnce(function () {
  8586. resolve();
  8587. });
  8588. _this.onErrorObservable.addOnce(function (reason) {
  8589. reject(reason);
  8590. });
  8591. });
  8592. };
  8593. /** @hidden */
  8594. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  8595. var _this = this;
  8596. var request = scene._loadFile(url, onSuccess, function (event) {
  8597. _this._onProgress(event, request);
  8598. }, undefined, useArrayBuffer, onError);
  8599. request.onCompleteObservable.add(function (request) {
  8600. _this._requests.splice(_this._requests.indexOf(request), 1);
  8601. });
  8602. this._requests.push(request);
  8603. return request;
  8604. };
  8605. /** @hidden */
  8606. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  8607. var _this = this;
  8608. var request = scene._requestFile(url, onSuccess, function (event) {
  8609. _this._onProgress(event, request);
  8610. }, undefined, useArrayBuffer, onError, onOpened);
  8611. request.onCompleteObservable.add(function (request) {
  8612. _this._requests.splice(_this._requests.indexOf(request), 1);
  8613. });
  8614. this._requests.push(request);
  8615. return request;
  8616. };
  8617. GLTFFileLoader.prototype._onProgress = function (event, request) {
  8618. if (!this._progressCallback) {
  8619. return;
  8620. }
  8621. request._lengthComputable = event.lengthComputable;
  8622. request._loaded = event.loaded;
  8623. request._total = event.total;
  8624. var lengthComputable = true;
  8625. var loaded = 0;
  8626. var total = 0;
  8627. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  8628. var request_1 = _a[_i];
  8629. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  8630. return;
  8631. }
  8632. lengthComputable = lengthComputable && request_1._lengthComputable;
  8633. loaded += request_1._loaded;
  8634. total += request_1._total;
  8635. }
  8636. this._progressCallback({
  8637. lengthComputable: lengthComputable,
  8638. loaded: loaded,
  8639. total: lengthComputable ? total : 0
  8640. });
  8641. };
  8642. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  8643. var _this = this;
  8644. if (rootUrl === void 0) { rootUrl = ""; }
  8645. if (fileName === void 0) { fileName = ""; }
  8646. if (!this.validate) {
  8647. return;
  8648. }
  8649. this._startPerformanceCounter("Validate JSON");
  8650. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  8651. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  8652. }).then(function (result) {
  8653. _this._endPerformanceCounter("Validate JSON");
  8654. _this.onValidatedObservable.notifyObservers(result);
  8655. _this.onValidatedObservable.clear();
  8656. }, function (reason) {
  8657. _this._endPerformanceCounter("Validate JSON");
  8658. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  8659. _this.onValidatedObservable.clear();
  8660. });
  8661. };
  8662. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  8663. var asset = loaderData.json.asset || {};
  8664. this._log("Asset version: " + asset.version);
  8665. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  8666. asset.generator && this._log("Asset generator: " + asset.generator);
  8667. var version = GLTFFileLoader._parseVersion(asset.version);
  8668. if (!version) {
  8669. throw new Error("Invalid version: " + asset.version);
  8670. }
  8671. if (asset.minVersion !== undefined) {
  8672. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  8673. if (!minVersion) {
  8674. throw new Error("Invalid minimum version: " + asset.minVersion);
  8675. }
  8676. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  8677. throw new Error("Incompatible minimum version: " + asset.minVersion);
  8678. }
  8679. }
  8680. var createLoaders = {
  8681. 1: GLTFFileLoader._CreateGLTF1Loader,
  8682. 2: GLTFFileLoader._CreateGLTF2Loader
  8683. };
  8684. var createLoader = createLoaders[version.major];
  8685. if (!createLoader) {
  8686. throw new Error("Unsupported version: " + asset.version);
  8687. }
  8688. return createLoader(this);
  8689. };
  8690. GLTFFileLoader.prototype._parseJson = function (json) {
  8691. this._startPerformanceCounter("Parse JSON");
  8692. this._log("JSON length: " + json.length);
  8693. var parsed = JSON.parse(json);
  8694. this._endPerformanceCounter("Parse JSON");
  8695. return parsed;
  8696. };
  8697. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8698. var _this = this;
  8699. this._startPerformanceCounter("Unpack Binary");
  8700. // Read magic + version + length + json length + json format
  8701. return dataReader.loadAsync(20).then(function () {
  8702. var Binary = {
  8703. Magic: 0x46546C67
  8704. };
  8705. var magic = dataReader.readUint32();
  8706. if (magic !== Binary.Magic) {
  8707. throw new Error("Unexpected magic: " + magic);
  8708. }
  8709. var version = dataReader.readUint32();
  8710. if (_this.loggingEnabled) {
  8711. _this._log("Binary version: " + version);
  8712. }
  8713. var length = dataReader.readUint32();
  8714. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  8715. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8716. }
  8717. var unpacked;
  8718. switch (version) {
  8719. case 1: {
  8720. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  8721. break;
  8722. }
  8723. case 2: {
  8724. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  8725. break;
  8726. }
  8727. default: {
  8728. throw new Error("Unsupported version: " + version);
  8729. }
  8730. }
  8731. _this._endPerformanceCounter("Unpack Binary");
  8732. return unpacked;
  8733. });
  8734. };
  8735. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  8736. var ContentFormat = {
  8737. JSON: 0
  8738. };
  8739. var contentLength = dataReader.readUint32();
  8740. var contentFormat = dataReader.readUint32();
  8741. if (contentFormat !== ContentFormat.JSON) {
  8742. throw new Error("Unexpected content format: " + contentFormat);
  8743. }
  8744. var bodyLength = length - dataReader.byteOffset;
  8745. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8746. if (bodyLength !== 0) {
  8747. var startByteOffset_1 = dataReader.byteOffset;
  8748. data.bin = {
  8749. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8750. byteLength: bodyLength
  8751. };
  8752. }
  8753. return Promise.resolve(data);
  8754. };
  8755. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  8756. var _this = this;
  8757. var ChunkFormat = {
  8758. JSON: 0x4E4F534A,
  8759. BIN: 0x004E4942
  8760. };
  8761. // Read the JSON chunk header.
  8762. var chunkLength = dataReader.readUint32();
  8763. var chunkFormat = dataReader.readUint32();
  8764. if (chunkFormat !== ChunkFormat.JSON) {
  8765. throw new Error("First chunk format is not JSON");
  8766. }
  8767. // Bail if there are no other chunks.
  8768. if (dataReader.byteOffset + chunkLength === length) {
  8769. return dataReader.loadAsync(chunkLength).then(function () {
  8770. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8771. });
  8772. }
  8773. // Read the JSON chunk and the length and type of the next chunk.
  8774. return dataReader.loadAsync(chunkLength + 8).then(function () {
  8775. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8776. var readAsync = function () {
  8777. var chunkLength = dataReader.readUint32();
  8778. var chunkFormat = dataReader.readUint32();
  8779. switch (chunkFormat) {
  8780. case ChunkFormat.JSON: {
  8781. throw new Error("Unexpected JSON chunk");
  8782. }
  8783. case ChunkFormat.BIN: {
  8784. var startByteOffset_2 = dataReader.byteOffset;
  8785. data.bin = {
  8786. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8787. byteLength: chunkLength
  8788. };
  8789. dataReader.skipBytes(chunkLength);
  8790. break;
  8791. }
  8792. default: {
  8793. // ignore unrecognized chunkFormat
  8794. dataReader.skipBytes(chunkLength);
  8795. break;
  8796. }
  8797. }
  8798. if (dataReader.byteOffset !== length) {
  8799. return dataReader.loadAsync(8).then(readAsync);
  8800. }
  8801. return Promise.resolve(data);
  8802. };
  8803. return readAsync();
  8804. });
  8805. };
  8806. GLTFFileLoader._parseVersion = function (version) {
  8807. if (version === "1.0" || version === "1.0.1") {
  8808. return {
  8809. major: 1,
  8810. minor: 0
  8811. };
  8812. }
  8813. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8814. if (!match) {
  8815. return null;
  8816. }
  8817. return {
  8818. major: parseInt(match[1]),
  8819. minor: parseInt(match[2])
  8820. };
  8821. };
  8822. GLTFFileLoader._compareVersion = function (a, b) {
  8823. if (a.major > b.major) {
  8824. return 1;
  8825. }
  8826. if (a.major < b.major) {
  8827. return -1;
  8828. }
  8829. if (a.minor > b.minor) {
  8830. return 1;
  8831. }
  8832. if (a.minor < b.minor) {
  8833. return -1;
  8834. }
  8835. return 0;
  8836. };
  8837. /** @hidden */
  8838. GLTFFileLoader.prototype._logOpen = function (message) {
  8839. this._log(message);
  8840. this._logIndentLevel++;
  8841. };
  8842. /** @hidden */
  8843. GLTFFileLoader.prototype._logClose = function () {
  8844. --this._logIndentLevel;
  8845. };
  8846. GLTFFileLoader.prototype._logEnabled = function (message) {
  8847. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8848. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8849. };
  8850. GLTFFileLoader.prototype._logDisabled = function (message) {
  8851. };
  8852. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8853. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8854. };
  8855. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8856. };
  8857. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8858. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8859. };
  8860. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8861. };
  8862. // ----------
  8863. // V1 options
  8864. // ----------
  8865. /**
  8866. * 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.
  8867. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8868. * Defaults to true.
  8869. * @hidden
  8870. */
  8871. GLTFFileLoader.IncrementalLoading = true;
  8872. /**
  8873. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8874. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8875. * @hidden
  8876. */
  8877. GLTFFileLoader.HomogeneousCoordinates = false;
  8878. GLTFFileLoader._logSpaces = " ";
  8879. return GLTFFileLoader;
  8880. }());
  8881. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8882. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8883. }
  8884. /***/ }),
  8885. /***/ "./glTF/glTFValidation.ts":
  8886. /*!********************************!*\
  8887. !*** ./glTF/glTFValidation.ts ***!
  8888. \********************************/
  8889. /*! exports provided: GLTFValidation */
  8890. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8891. "use strict";
  8892. __webpack_require__.r(__webpack_exports__);
  8893. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  8894. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  8895. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  8896. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  8897. var options = {
  8898. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  8899. };
  8900. if (fileName) {
  8901. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  8902. }
  8903. return (data instanceof ArrayBuffer)
  8904. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  8905. : GLTFValidator.validateString(data, options);
  8906. }
  8907. /**
  8908. * The worker function that gets converted to a blob url to pass into a worker.
  8909. */
  8910. function workerFunc() {
  8911. var pendingExternalResources = [];
  8912. onmessage = function (message) {
  8913. var data = message.data;
  8914. switch (data.id) {
  8915. case "init": {
  8916. importScripts(data.url);
  8917. break;
  8918. }
  8919. case "validate": {
  8920. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  8921. var index = pendingExternalResources.length;
  8922. pendingExternalResources.push({ resolve: resolve, reject: reject });
  8923. postMessage({ id: "getExternalResource", index: index, uri: uri });
  8924. }); }).then(function (value) {
  8925. postMessage({ id: "validate.resolve", value: value });
  8926. }, function (reason) {
  8927. postMessage({ id: "validate.reject", reason: reason });
  8928. });
  8929. break;
  8930. }
  8931. case "getExternalResource.resolve": {
  8932. pendingExternalResources[data.index].resolve(data.value);
  8933. break;
  8934. }
  8935. case "getExternalResource.reject": {
  8936. pendingExternalResources[data.index].reject(data.reason);
  8937. break;
  8938. }
  8939. }
  8940. };
  8941. }
  8942. /**
  8943. * glTF validation
  8944. */
  8945. var GLTFValidation = /** @class */ (function () {
  8946. function GLTFValidation() {
  8947. }
  8948. /**
  8949. * Validate a glTF asset using the glTF-Validator.
  8950. * @param data The JSON of a glTF or the array buffer of a binary glTF
  8951. * @param rootUrl The root url for the glTF
  8952. * @param fileName The file name for the glTF
  8953. * @param getExternalResource The callback to get external resources for the glTF validator
  8954. * @returns A promise that resolves with the glTF validation results once complete
  8955. */
  8956. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  8957. var _this = this;
  8958. if (typeof Worker === "function") {
  8959. return new Promise(function (resolve, reject) {
  8960. var workerContent = validateAsync + "(" + workerFunc + ")()";
  8961. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  8962. var worker = new Worker(workerBlobUrl);
  8963. var onError = function (error) {
  8964. worker.removeEventListener("error", onError);
  8965. worker.removeEventListener("message", onMessage);
  8966. reject(error);
  8967. };
  8968. var onMessage = function (message) {
  8969. var data = message.data;
  8970. switch (data.id) {
  8971. case "getExternalResource": {
  8972. getExternalResource(data.uri).then(function (value) {
  8973. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  8974. }, function (reason) {
  8975. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  8976. });
  8977. break;
  8978. }
  8979. case "validate.resolve": {
  8980. worker.removeEventListener("error", onError);
  8981. worker.removeEventListener("message", onMessage);
  8982. resolve(data.value);
  8983. break;
  8984. }
  8985. case "validate.reject": {
  8986. worker.removeEventListener("error", onError);
  8987. worker.removeEventListener("message", onMessage);
  8988. reject(data.reason);
  8989. }
  8990. }
  8991. };
  8992. worker.addEventListener("error", onError);
  8993. worker.addEventListener("message", onMessage);
  8994. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  8995. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  8996. });
  8997. }
  8998. else {
  8999. if (!this._LoadScriptPromise) {
  9000. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  9001. }
  9002. return this._LoadScriptPromise.then(function () {
  9003. return validateAsync(data, rootUrl, fileName, getExternalResource);
  9004. });
  9005. }
  9006. };
  9007. /**
  9008. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  9009. */
  9010. GLTFValidation.Configuration = {
  9011. url: "https://preview.babylonjs.com/gltf_validator.js"
  9012. };
  9013. return GLTFValidation;
  9014. }());
  9015. /***/ }),
  9016. /***/ "./glTF/index.ts":
  9017. /*!***********************!*\
  9018. !*** ./glTF/index.ts ***!
  9019. \***********************/
  9020. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  9021. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9022. "use strict";
  9023. __webpack_require__.r(__webpack_exports__);
  9024. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9025. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9026. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9027. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9028. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9029. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  9030. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9031. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  9032. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  9033. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  9034. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  9035. /***/ }),
  9036. /***/ "./index.ts":
  9037. /*!******************!*\
  9038. !*** ./index.ts ***!
  9039. \******************/
  9040. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9041. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9042. "use strict";
  9043. __webpack_require__.r(__webpack_exports__);
  9044. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  9045. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9046. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9047. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9048. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9049. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  9050. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  9051. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  9052. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  9053. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  9054. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  9055. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  9056. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  9057. /***/ }),
  9058. /***/ "./legacy/legacy-glTF.ts":
  9059. /*!*******************************!*\
  9060. !*** ./legacy/legacy-glTF.ts ***!
  9061. \*******************************/
  9062. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  9063. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9064. "use strict";
  9065. __webpack_require__.r(__webpack_exports__);
  9066. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9067. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  9068. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9069. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9070. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9071. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9072. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9073. /**
  9074. * This is the entry point for the UMD module.
  9075. * The entry point for a future ESM package should be index.ts
  9076. */
  9077. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9078. if (typeof globalObject !== "undefined") {
  9079. globalObject.BABYLON = globalObject.BABYLON || {};
  9080. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  9081. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  9082. }
  9083. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  9084. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  9085. }
  9086. }
  9087. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9088. /***/ }),
  9089. /***/ "./legacy/legacy-glTF1.ts":
  9090. /*!********************************!*\
  9091. !*** ./legacy/legacy-glTF1.ts ***!
  9092. \********************************/
  9093. /*! exports provided: GLTF1 */
  9094. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9095. "use strict";
  9096. __webpack_require__.r(__webpack_exports__);
  9097. /* 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");
  9098. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  9099. /**
  9100. * This is the entry point for the UMD module.
  9101. * The entry point for a future ESM package should be index.ts
  9102. */
  9103. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9104. if (typeof globalObject !== "undefined") {
  9105. globalObject.BABYLON = globalObject.BABYLON || {};
  9106. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  9107. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  9108. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  9109. }
  9110. }
  9111. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9112. /***/ }),
  9113. /***/ "./legacy/legacy-glTF2.ts":
  9114. /*!********************************!*\
  9115. !*** ./legacy/legacy-glTF2.ts ***!
  9116. \********************************/
  9117. /*! exports provided: GLTF2 */
  9118. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9119. "use strict";
  9120. __webpack_require__.r(__webpack_exports__);
  9121. /* 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");
  9122. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  9123. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  9124. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  9125. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  9126. /**
  9127. * This is the entry point for the UMD module.
  9128. * The entry point for a future ESM package should be index.ts
  9129. */
  9130. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9131. if (typeof globalObject !== "undefined") {
  9132. globalObject.BABYLON = globalObject.BABYLON || {};
  9133. var BABYLON = globalObject.BABYLON;
  9134. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  9135. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  9136. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  9137. var keys = [];
  9138. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  9139. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  9140. keys.push(key);
  9141. }
  9142. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  9143. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  9144. keys.push(key);
  9145. }
  9146. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  9147. // Prevent Reassignment.
  9148. if (keys.indexOf(key) > -1) {
  9149. continue;
  9150. }
  9151. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  9152. }
  9153. }
  9154. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9155. /***/ }),
  9156. /***/ "./legacy/legacy-objFileLoader.ts":
  9157. /*!****************************************!*\
  9158. !*** ./legacy/legacy-objFileLoader.ts ***!
  9159. \****************************************/
  9160. /*! exports provided: MTLFileLoader, OBJFileLoader */
  9161. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9162. "use strict";
  9163. __webpack_require__.r(__webpack_exports__);
  9164. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  9165. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  9166. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  9167. /**
  9168. * This is the entry point for the UMD module.
  9169. * The entry point for a future ESM package should be index.ts
  9170. */
  9171. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9172. if (typeof globalObject !== "undefined") {
  9173. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  9174. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  9175. }
  9176. }
  9177. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9178. /***/ }),
  9179. /***/ "./legacy/legacy-stlFileLoader.ts":
  9180. /*!****************************************!*\
  9181. !*** ./legacy/legacy-stlFileLoader.ts ***!
  9182. \****************************************/
  9183. /*! exports provided: STLFileLoader */
  9184. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9185. "use strict";
  9186. __webpack_require__.r(__webpack_exports__);
  9187. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  9188. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  9189. /**
  9190. * This is the entry point for the UMD module.
  9191. * The entry point for a future ESM package should be index.ts
  9192. */
  9193. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9194. if (typeof globalObject !== "undefined") {
  9195. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  9196. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  9197. }
  9198. }
  9199. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9200. /***/ }),
  9201. /***/ "./legacy/legacy.ts":
  9202. /*!**************************!*\
  9203. !*** ./legacy/legacy.ts ***!
  9204. \**************************/
  9205. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9206. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9207. "use strict";
  9208. __webpack_require__.r(__webpack_exports__);
  9209. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  9210. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  9211. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  9212. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  9213. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  9214. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  9215. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9216. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  9217. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  9218. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  9219. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  9220. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  9221. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  9222. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  9223. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  9224. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  9225. /***/ }),
  9226. /***/ "babylonjs/Misc/tools":
  9227. /*!****************************************************************************************************!*\
  9228. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  9229. \****************************************************************************************************/
  9230. /*! no static exports found */
  9231. /***/ (function(module, exports) {
  9232. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  9233. /***/ })
  9234. /******/ });
  9235. });
  9236. //# sourceMappingURL=babylonjs.loaders.js.map