babylon.glTFFileLoader.js 334 KB

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