babylonjs.loaders.js 425 KB

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