babylon.glTFFileLoader.js 414 KB

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