babylonjs.loaders.js 450 KB

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