babylonjs.loaders.js 417 KB

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