babylon.glTFFileLoader.js 347 KB

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