babylonjs.loaders.js 406 KB

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