babylonjs.loaders.js 486 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764
  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.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** E:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./OBJ/index.ts":
  324. /*!**********************!*\
  325. !*** ./OBJ/index.ts ***!
  326. \**********************/
  327. /*! exports provided: MTLFileLoader, OBJFileLoader */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  333. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  335. /***/ }),
  336. /***/ "./OBJ/mtlFileLoader.ts":
  337. /*!******************************!*\
  338. !*** ./OBJ/mtlFileLoader.ts ***!
  339. \******************************/
  340. /*! exports provided: MTLFileLoader */
  341. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  342. "use strict";
  343. __webpack_require__.r(__webpack_exports__);
  344. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  345. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  346. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  347. /**
  348. * Class reading and parsing the MTL file bundled with the obj file.
  349. */
  350. var MTLFileLoader = /** @class */ (function () {
  351. function MTLFileLoader() {
  352. /**
  353. * All material loaded from the mtl will be set here
  354. */
  355. this.materials = [];
  356. }
  357. /**
  358. * This function will read the mtl file and create each material described inside
  359. * This function could be improve by adding :
  360. * -some component missing (Ni, Tf...)
  361. * -including the specific options available
  362. *
  363. * @param scene defines the scene the material will be created in
  364. * @param data defines the mtl data to parse
  365. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  366. * @param forAssetContainer defines if the material should be registered in the scene
  367. */
  368. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl, forAssetContainer) {
  369. if (data instanceof ArrayBuffer) {
  370. return;
  371. }
  372. //Split the lines from the file
  373. var lines = data.split('\n');
  374. //Space char
  375. var delimiter_pattern = /\s+/;
  376. //Array with RGB colors
  377. var color;
  378. //New material
  379. var material = null;
  380. //Look at each line
  381. for (var i = 0; i < lines.length; i++) {
  382. var line = lines[i].trim();
  383. // Blank line or comment
  384. if (line.length === 0 || line.charAt(0) === '#') {
  385. continue;
  386. }
  387. //Get the first parameter (keyword)
  388. var pos = line.indexOf(' ');
  389. var key = (pos >= 0) ? line.substring(0, pos) : line;
  390. key = key.toLowerCase();
  391. //Get the data following the key
  392. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  393. //This mtl keyword will create the new material
  394. if (key === "newmtl") {
  395. //Check if it is the first material.
  396. // Materials specifications are described after this keyword.
  397. if (material) {
  398. //Add the previous material in the material array.
  399. this.materials.push(material);
  400. }
  401. //Create a new material.
  402. // value is the name of the material read in the mtl file
  403. scene._blockEntityCollection = forAssetContainer;
  404. material = new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"](value, scene);
  405. scene._blockEntityCollection = false;
  406. }
  407. else if (key === "kd" && material) {
  408. // Diffuse color (color under white light) using RGB values
  409. //value = "r g b"
  410. color = value.split(delimiter_pattern, 3).map(parseFloat);
  411. //color = [r,g,b]
  412. //Set tghe color into the material
  413. material.diffuseColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  414. }
  415. else if (key === "ka" && material) {
  416. // Ambient color (color under shadow) using RGB values
  417. //value = "r g b"
  418. color = value.split(delimiter_pattern, 3).map(parseFloat);
  419. //color = [r,g,b]
  420. //Set tghe color into the material
  421. material.ambientColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  422. }
  423. else if (key === "ks" && material) {
  424. // Specular color (color when light is reflected from shiny surface) using RGB values
  425. //value = "r g b"
  426. color = value.split(delimiter_pattern, 3).map(parseFloat);
  427. //color = [r,g,b]
  428. //Set the color into the material
  429. material.specularColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  430. }
  431. else if (key === "ke" && material) {
  432. // Emissive color using RGB values
  433. color = value.split(delimiter_pattern, 3).map(parseFloat);
  434. material.emissiveColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  435. }
  436. else if (key === "ns" && material) {
  437. //value = "Integer"
  438. material.specularPower = parseFloat(value);
  439. }
  440. else if (key === "d" && material) {
  441. //d is dissolve for current material. It mean alpha for BABYLON
  442. material.alpha = parseFloat(value);
  443. //Texture
  444. //This part can be improved by adding the possible options of texture
  445. }
  446. else if (key === "map_ka" && material) {
  447. // ambient texture map with a loaded image
  448. //We must first get the folder of the image
  449. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  450. }
  451. else if (key === "map_kd" && material) {
  452. // Diffuse texture map with a loaded image
  453. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  454. }
  455. else if (key === "map_ks" && material) {
  456. // Specular texture map with a loaded image
  457. //We must first get the folder of the image
  458. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  459. }
  460. else if (key === "map_ns") {
  461. //Specular
  462. //Specular highlight component
  463. //We must first get the folder of the image
  464. //
  465. //Not supported by BABYLON
  466. //
  467. // continue;
  468. }
  469. else if (key === "map_bump" && material) {
  470. //The bump texture
  471. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  472. }
  473. else if (key === "map_d" && material) {
  474. // The dissolve of the material
  475. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  476. //Options for illumination
  477. }
  478. else if (key === "illum") {
  479. //Illumination
  480. if (value === "0") {
  481. //That mean Kd == Kd
  482. }
  483. else if (value === "1") {
  484. //Color on and Ambient on
  485. }
  486. else if (value === "2") {
  487. //Highlight on
  488. }
  489. else if (value === "3") {
  490. //Reflection on and Ray trace on
  491. }
  492. else if (value === "4") {
  493. //Transparency: Glass on, Reflection: Ray trace on
  494. }
  495. else if (value === "5") {
  496. //Reflection: Fresnel on and Ray trace on
  497. }
  498. else if (value === "6") {
  499. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  500. }
  501. else if (value === "7") {
  502. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  503. }
  504. else if (value === "8") {
  505. //Reflection on and Ray trace off
  506. }
  507. else if (value === "9") {
  508. //Transparency: Glass on, Reflection: Ray trace off
  509. }
  510. else if (value === "10") {
  511. //Casts shadows onto invisible surfaces
  512. }
  513. }
  514. else {
  515. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  516. }
  517. }
  518. //At the end of the file, add the last material
  519. if (material) {
  520. this.materials.push(material);
  521. }
  522. };
  523. /**
  524. * Gets the texture for the material.
  525. *
  526. * If the material is imported from input file,
  527. * We sanitize the url to ensure it takes the textre from aside the material.
  528. *
  529. * @param rootUrl The root url to load from
  530. * @param value The value stored in the mtl
  531. * @return The Texture
  532. */
  533. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  534. if (!value) {
  535. return null;
  536. }
  537. var url = rootUrl;
  538. // Load from input file.
  539. if (rootUrl === "file:") {
  540. var lastDelimiter = value.lastIndexOf("\\");
  541. if (lastDelimiter === -1) {
  542. lastDelimiter = value.lastIndexOf("/");
  543. }
  544. if (lastDelimiter > -1) {
  545. url += value.substr(lastDelimiter + 1);
  546. }
  547. else {
  548. url += value;
  549. }
  550. }
  551. // Not from input file.
  552. else {
  553. url += value;
  554. }
  555. return new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
  556. };
  557. /**
  558. * Invert Y-Axis of referenced textures on load
  559. */
  560. MTLFileLoader.INVERT_TEXTURE_Y = true;
  561. return MTLFileLoader;
  562. }());
  563. /***/ }),
  564. /***/ "./OBJ/objFileLoader.ts":
  565. /*!******************************!*\
  566. !*** ./OBJ/objFileLoader.ts ***!
  567. \******************************/
  568. /*! exports provided: OBJFileLoader */
  569. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  570. "use strict";
  571. __webpack_require__.r(__webpack_exports__);
  572. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  573. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  574. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  575. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  576. /**
  577. * OBJ file type loader.
  578. * This is a babylon scene loader plugin.
  579. */
  580. var OBJFileLoader = /** @class */ (function () {
  581. /**
  582. * Creates loader for .OBJ files
  583. *
  584. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  585. */
  586. function OBJFileLoader(meshLoadOptions) {
  587. /**
  588. * Defines the name of the plugin.
  589. */
  590. this.name = "obj";
  591. /**
  592. * Defines the extension the plugin is able to load.
  593. */
  594. this.extensions = ".obj";
  595. /** @hidden */
  596. this.obj = /^o/;
  597. /** @hidden */
  598. this.group = /^g/;
  599. /** @hidden */
  600. this.mtllib = /^mtllib /;
  601. /** @hidden */
  602. this.usemtl = /^usemtl /;
  603. /** @hidden */
  604. this.smooth = /^s /;
  605. /** @hidden */
  606. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+){3,7}/;
  607. // vn float float float
  608. /** @hidden */
  609. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  610. // vt float float
  611. /** @hidden */
  612. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  613. // f vertex vertex vertex ...
  614. /** @hidden */
  615. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  616. // f vertex/uvs vertex/uvs vertex/uvs ...
  617. /** @hidden */
  618. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  619. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  620. /** @hidden */
  621. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  622. // f vertex//normal vertex//normal vertex//normal ...
  623. /** @hidden */
  624. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  625. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  626. /** @hidden */
  627. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  628. this._forAssetContainer = false;
  629. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  630. }
  631. Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
  632. /**
  633. * Invert Y-Axis of referenced textures on load
  634. */
  635. get: function () {
  636. return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y;
  637. },
  638. set: function (value) {
  639. _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y = value;
  640. },
  641. enumerable: true,
  642. configurable: true
  643. });
  644. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  645. get: function () {
  646. return {
  647. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  648. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  649. InvertY: OBJFileLoader.INVERT_Y,
  650. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  651. UVScaling: OBJFileLoader.UV_SCALING,
  652. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  653. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  654. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  655. };
  656. },
  657. enumerable: true,
  658. configurable: true
  659. });
  660. /**
  661. * Calls synchronously the MTL file attached to this obj.
  662. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  663. * Without this function materials are not displayed in the first frame (but displayed after).
  664. * In consequence it is impossible to get material information in your HTML file
  665. *
  666. * @param url The URL of the MTL file
  667. * @param rootUrl
  668. * @param onSuccess Callback function to be called when the MTL file is loaded
  669. * @private
  670. */
  671. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  672. //The complete path to the mtl file
  673. var pathOfFile = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  674. // Loads through the babylon tools to allow fileInput search.
  675. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  676. onFailure(pathOfFile, exception);
  677. });
  678. };
  679. /**
  680. * Instantiates a OBJ file loader plugin.
  681. * @returns the created plugin
  682. */
  683. OBJFileLoader.prototype.createPlugin = function () {
  684. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  685. };
  686. /**
  687. * If the data string can be loaded directly.
  688. *
  689. * @param data string containing the file data
  690. * @returns if the data can be loaded directly
  691. */
  692. OBJFileLoader.prototype.canDirectLoad = function (data) {
  693. return false;
  694. };
  695. /**
  696. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  697. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  698. * @param scene the scene the meshes should be added to
  699. * @param data the OBJ data to load
  700. * @param rootUrl root url to load from
  701. * @param onProgress event that fires when loading progress has occured
  702. * @param fileName Defines the name of the file to load
  703. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  704. */
  705. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  706. //get the meshes from OBJ file
  707. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  708. return {
  709. meshes: meshes,
  710. particleSystems: [],
  711. skeletons: [],
  712. animationGroups: []
  713. };
  714. });
  715. };
  716. /**
  717. * Imports all objects from the loaded OBJ data and adds them to the scene
  718. * @param scene the scene the objects should be added to
  719. * @param data the OBJ data to load
  720. * @param rootUrl root url to load from
  721. * @param onProgress event that fires when loading progress has occured
  722. * @param fileName Defines the name of the file to load
  723. * @returns a promise which completes when objects have been loaded to the scene
  724. */
  725. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  726. //Get the 3D model
  727. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  728. // return void
  729. });
  730. };
  731. /**
  732. * Load into an asset container.
  733. * @param scene The scene to load into
  734. * @param data The data to import
  735. * @param rootUrl The root url for scene and resources
  736. * @param onProgress The callback when the load progresses
  737. * @param fileName Defines the name of the file to load
  738. * @returns The loaded asset container
  739. */
  740. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  741. var _this = this;
  742. this._forAssetContainer = true;
  743. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  744. var container = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  745. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  746. result.meshes.forEach(function (mesh) {
  747. var material = mesh.material;
  748. if (material) {
  749. // Materials
  750. if (container.materials.indexOf(material) == -1) {
  751. container.materials.push(material);
  752. // Textures
  753. var textures = material.getActiveTextures();
  754. textures.forEach(function (t) {
  755. if (container.textures.indexOf(t) == -1) {
  756. container.textures.push(t);
  757. }
  758. });
  759. }
  760. }
  761. });
  762. _this._forAssetContainer = false;
  763. return container;
  764. }).catch(function (ex) {
  765. _this._forAssetContainer = false;
  766. throw ex;
  767. });
  768. };
  769. /**
  770. * Read the OBJ file and create an Array of meshes.
  771. * Each mesh contains all information given by the OBJ and the MTL file.
  772. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  773. *
  774. * @param meshesNames
  775. * @param scene Scene The scene where are displayed the data
  776. * @param data String The content of the obj file
  777. * @param rootUrl String The path to the folder
  778. * @returns Array<AbstractMesh>
  779. * @private
  780. */
  781. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  782. var _this = this;
  783. var positions = []; //values for the positions of vertices
  784. var normals = []; //Values for the normals
  785. var uvs = []; //Values for the textures
  786. var colors = [];
  787. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  788. var handledMesh; //The current mesh of meshes array
  789. var indicesForBabylon = []; //The list of indices for VertexData
  790. var wrappedPositionForBabylon = []; //The list of position in vectors
  791. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  792. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  793. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  794. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  795. var curPositionInIndices = 0;
  796. var hasMeshes = false; //Meshes are defined in the file
  797. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  798. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  799. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  800. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  801. var triangles = []; //Indices from new triangles coming from polygons
  802. var materialNameFromObj = ""; //The name of the current material
  803. var fileToLoad = ""; //The name of the mtlFile to load
  804. var materialsFromMTLFile = new _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]();
  805. var objMeshName = ""; //The name of the current obj mesh
  806. var increment = 1; //Id for meshes created by the multimaterial
  807. var isFirstMaterial = true;
  808. var grayColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  809. /**
  810. * Search for obj in the given array.
  811. * This function is called to check if a couple of data already exists in an array.
  812. *
  813. * If found, returns the index of the founded tuple index. Returns -1 if not found
  814. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  815. * @param obj Array<number>
  816. * @returns {boolean}
  817. */
  818. var isInArray = function (arr, obj) {
  819. if (!arr[obj[0]]) {
  820. arr[obj[0]] = { normals: [], idx: [] };
  821. }
  822. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  823. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  824. };
  825. var isInArrayUV = function (arr, obj) {
  826. if (!arr[obj[0]]) {
  827. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  828. }
  829. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  830. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  831. return arr[obj[0]].idx[idx];
  832. }
  833. return -1;
  834. };
  835. /**
  836. * This function set the data for each triangle.
  837. * Data are position, normals and uvs
  838. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  839. * If the tuple already exist, add only their indice
  840. *
  841. * @param indicePositionFromObj Integer The index in positions array
  842. * @param indiceUvsFromObj Integer The index in uvs array
  843. * @param indiceNormalFromObj Integer The index in normals array
  844. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  845. * @param textureVectorFromOBJ Vector3 The value of uvs
  846. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  847. */
  848. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  849. //Check if this tuple already exists in the list of tuples
  850. var _index;
  851. if (_this._meshLoadOptions.OptimizeWithUV) {
  852. _index = isInArrayUV(tuplePosNorm, [
  853. indicePositionFromObj,
  854. indiceNormalFromObj,
  855. indiceUvsFromObj
  856. ]);
  857. }
  858. else {
  859. _index = isInArray(tuplePosNorm, [
  860. indicePositionFromObj,
  861. indiceNormalFromObj
  862. ]);
  863. }
  864. //If it not exists
  865. if (_index === -1) {
  866. //Add an new indice.
  867. //The array of indices is only an array with his length equal to the number of triangles - 1.
  868. //We add vertices data in this order
  869. indicesForBabylon.push(wrappedPositionForBabylon.length);
  870. //Push the position of vertice for Babylon
  871. //Each element is a Vector3(x,y,z)
  872. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  873. //Push the uvs for Babylon
  874. //Each element is a Vector3(u,v)
  875. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  876. //Push the normals for Babylon
  877. //Each element is a Vector3(x,y,z)
  878. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  879. if (positionColorsFromOBJ !== undefined) {
  880. //Push the colors for Babylon
  881. //Each element is a BABYLON.Color4(r,g,b,a)
  882. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  883. }
  884. //Add the tuple in the comparison list
  885. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  886. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  887. if (_this._meshLoadOptions.OptimizeWithUV) {
  888. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  889. }
  890. }
  891. else {
  892. //The tuple already exists
  893. //Add the index of the already existing tuple
  894. //At this index we can get the value of position, normal, color and uvs of vertex
  895. indicesForBabylon.push(_index);
  896. }
  897. };
  898. /**
  899. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  900. */
  901. var unwrapData = function () {
  902. //Every array has the same length
  903. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  904. //Push the x, y, z values of each element in the unwrapped array
  905. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  906. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  907. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  908. }
  909. if (_this._meshLoadOptions.ImportVertexColors === true) {
  910. //Push the r, g, b, a values of each element in the unwrapped array
  911. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  912. }
  913. // Reset arrays for the next new meshes
  914. wrappedPositionForBabylon = [];
  915. wrappedNormalsForBabylon = [];
  916. wrappedUvsForBabylon = [];
  917. wrappedColorsForBabylon = [];
  918. tuplePosNorm = [];
  919. curPositionInIndices = 0;
  920. };
  921. /**
  922. * Create triangles from polygons
  923. * It is important to notice that a triangle is a polygon
  924. * We get 5 patterns of face defined in OBJ File :
  925. * facePattern1 = ["1","2","3","4","5","6"]
  926. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  927. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  928. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  929. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  930. * Each pattern is divided by the same method
  931. * @param face Array[String] The indices of elements
  932. * @param v Integer The variable to increment
  933. */
  934. var getTriangles = function (faces, v) {
  935. //Work for each element of the array
  936. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  937. //Add on the triangle variable the indexes to obtain triangles
  938. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  939. }
  940. //Result obtained after 2 iterations:
  941. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  942. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  943. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  944. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  945. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  946. };
  947. /**
  948. * Create triangles and push the data for each polygon for the pattern 1
  949. * In this pattern we get vertice positions
  950. * @param face
  951. * @param v
  952. */
  953. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  954. //Get the indices of triangles for each polygon
  955. getTriangles(face, v);
  956. //For each element in the triangles array.
  957. //This var could contains 1 to an infinity of triangles
  958. for (var k = 0; k < triangles.length; k++) {
  959. // Set position indice
  960. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  961. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  962. positions[indicePositionFromObj], //Get the vectors data
  963. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  964. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  965. }
  966. //Reset variable for the next line
  967. triangles = [];
  968. };
  969. /**
  970. * Create triangles and push the data for each polygon for the pattern 2
  971. * In this pattern we get vertice positions and uvsu
  972. * @param face
  973. * @param v
  974. */
  975. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  976. //Get the indices of triangles for each polygon
  977. getTriangles(face, v);
  978. for (var k = 0; k < triangles.length; k++) {
  979. //triangle[k] = "1/1"
  980. //Split the data for getting position and uv
  981. var point = triangles[k].split("/"); // ["1", "1"]
  982. //Set position indice
  983. var indicePositionFromObj = parseInt(point[0]) - 1;
  984. //Set uv indice
  985. var indiceUvsFromObj = parseInt(point[1]) - 1;
  986. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  987. positions[indicePositionFromObj], //Get the values for each element
  988. uvs[indiceUvsFromObj], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  989. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  990. }
  991. //Reset variable for the next line
  992. triangles = [];
  993. };
  994. /**
  995. * Create triangles and push the data for each polygon for the pattern 3
  996. * In this pattern we get vertice positions, uvs and normals
  997. * @param face
  998. * @param v
  999. */
  1000. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  1001. //Get the indices of triangles for each polygon
  1002. getTriangles(face, v);
  1003. for (var k = 0; k < triangles.length; k++) {
  1004. //triangle[k] = "1/1/1"
  1005. //Split the data for getting position, uv, and normals
  1006. var point = triangles[k].split("/"); // ["1", "1", "1"]
  1007. // Set position indice
  1008. var indicePositionFromObj = parseInt(point[0]) - 1;
  1009. // Set uv indice
  1010. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1011. // Set normal indice
  1012. var indiceNormalFromObj = parseInt(point[2]) - 1;
  1013. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  1014. );
  1015. }
  1016. //Reset variable for the next line
  1017. triangles = [];
  1018. };
  1019. /**
  1020. * Create triangles and push the data for each polygon for the pattern 4
  1021. * In this pattern we get vertice positions and normals
  1022. * @param face
  1023. * @param v
  1024. */
  1025. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  1026. getTriangles(face, v);
  1027. for (var k = 0; k < triangles.length; k++) {
  1028. //triangle[k] = "1//1"
  1029. //Split the data for getting position and normals
  1030. var point = triangles[k].split("//"); // ["1", "1"]
  1031. // We check indices, and normals
  1032. var indicePositionFromObj = parseInt(point[0]) - 1;
  1033. var indiceNormalFromObj = parseInt(point[1]) - 1;
  1034. setData(indicePositionFromObj, 1, //Default value for uv
  1035. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  1036. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1037. }
  1038. //Reset variable for the next line
  1039. triangles = [];
  1040. };
  1041. /**
  1042. * Create triangles and push the data for each polygon for the pattern 3
  1043. * In this pattern we get vertice positions, uvs and normals
  1044. * @param face
  1045. * @param v
  1046. */
  1047. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1048. //Get the indices of triangles for each polygon
  1049. getTriangles(face, v);
  1050. for (var k = 0; k < triangles.length; k++) {
  1051. //triangle[k] = "-1/-1/-1"
  1052. //Split the data for getting position, uv, and normals
  1053. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1054. // Set position indice
  1055. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1056. // Set uv indice
  1057. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1058. // Set normal indice
  1059. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1060. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1061. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1062. }
  1063. //Reset variable for the next line
  1064. triangles = [];
  1065. };
  1066. var addPreviousObjMesh = function () {
  1067. //Check if it is not the first mesh. Otherwise we don't have data.
  1068. if (meshesFromObj.length > 0) {
  1069. //Get the previous mesh for applying the data about the faces
  1070. //=> in obj file, faces definition append after the name of the mesh
  1071. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1072. //Set the data into Array for the mesh
  1073. unwrapData();
  1074. // Reverse tab. Otherwise face are displayed in the wrong sens
  1075. indicesForBabylon.reverse();
  1076. //Set the information for the mesh
  1077. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1078. handledMesh.indices = indicesForBabylon.slice();
  1079. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1080. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1081. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1082. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1083. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1084. }
  1085. //Reset the array for the next mesh
  1086. indicesForBabylon = [];
  1087. unwrappedPositionsForBabylon = [];
  1088. unwrappedColorsForBabylon = [];
  1089. unwrappedNormalsForBabylon = [];
  1090. unwrappedUVForBabylon = [];
  1091. }
  1092. };
  1093. //Main function
  1094. //Split the file into lines
  1095. var lines = data.split('\n');
  1096. //Look at each line
  1097. for (var i = 0; i < lines.length; i++) {
  1098. var line = lines[i].trim().replace(/\s\s/g, " ");
  1099. var result;
  1100. //Comment or newLine
  1101. if (line.length === 0 || line.charAt(0) === '#') {
  1102. continue;
  1103. //Get information about one position possible for the vertices
  1104. }
  1105. else if (this.vertexPattern.test(line)) {
  1106. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1107. // Value of result with line: "v 1.0 2.0 3.0"
  1108. // ["v", "1.0", "2.0", "3.0"]
  1109. // Create a Vector3 with the position x, y, z
  1110. positions.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1111. if (this._meshLoadOptions.ImportVertexColors === true) {
  1112. if (result.length >= 7) {
  1113. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1114. colors.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
  1115. }
  1116. else {
  1117. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1118. colors.push(grayColor);
  1119. }
  1120. }
  1121. }
  1122. else if ((result = this.normalPattern.exec(line)) !== null) {
  1123. //Create a Vector3 with the normals x, y, z
  1124. //Value of result
  1125. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1126. //Add the Vector in the list of normals
  1127. normals.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1128. }
  1129. else if ((result = this.uvPattern.exec(line)) !== null) {
  1130. //Create a Vector2 with the normals u, v
  1131. //Value of result
  1132. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1133. //Add the Vector in the list of uvs
  1134. uvs.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
  1135. //Identify patterns of faces
  1136. //Face could be defined in different type of pattern
  1137. }
  1138. else if ((result = this.facePattern3.exec(line)) !== null) {
  1139. //Value of result:
  1140. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1141. //Set the data for this face
  1142. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1143. 1);
  1144. }
  1145. else if ((result = this.facePattern4.exec(line)) !== null) {
  1146. //Value of result:
  1147. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1148. //Set the data for this face
  1149. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1150. 1);
  1151. }
  1152. else if ((result = this.facePattern5.exec(line)) !== null) {
  1153. //Value of result:
  1154. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1155. //Set the data for this face
  1156. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1157. 1);
  1158. }
  1159. else if ((result = this.facePattern2.exec(line)) !== null) {
  1160. //Value of result:
  1161. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1162. //Set the data for this face
  1163. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1164. 1);
  1165. }
  1166. else if ((result = this.facePattern1.exec(line)) !== null) {
  1167. //Value of result
  1168. //["f 1 2 3", "1 2 3"...]
  1169. //Set the data for this face
  1170. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1171. 1);
  1172. //Define a mesh or an object
  1173. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1174. }
  1175. else if (this.group.test(line) || this.obj.test(line)) {
  1176. //Create a new mesh corresponding to the name of the group.
  1177. //Definition of the mesh
  1178. var objMesh = {
  1179. name: line.substring(2).trim(),
  1180. indices: undefined,
  1181. positions: undefined,
  1182. normals: undefined,
  1183. uvs: undefined,
  1184. colors: undefined,
  1185. materialName: ""
  1186. };
  1187. addPreviousObjMesh();
  1188. //Push the last mesh created with only the name
  1189. meshesFromObj.push(objMesh);
  1190. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1191. hasMeshes = true;
  1192. isFirstMaterial = true;
  1193. increment = 1;
  1194. //Keyword for applying a material
  1195. }
  1196. else if (this.usemtl.test(line)) {
  1197. //Get the name of the material
  1198. materialNameFromObj = line.substring(7).trim();
  1199. //If this new material is in the same mesh
  1200. if (!isFirstMaterial || !hasMeshes) {
  1201. //Set the data for the previous mesh
  1202. addPreviousObjMesh();
  1203. //Create a new mesh
  1204. var objMesh =
  1205. //Set the name of the current obj mesh
  1206. {
  1207. name: (objMeshName || "mesh") + "_mm" + increment.toString(),
  1208. indices: undefined,
  1209. positions: undefined,
  1210. normals: undefined,
  1211. uvs: undefined,
  1212. colors: undefined,
  1213. materialName: materialNameFromObj
  1214. };
  1215. increment++;
  1216. //If meshes are already defined
  1217. meshesFromObj.push(objMesh);
  1218. hasMeshes = true;
  1219. }
  1220. //Set the material name if the previous line define a mesh
  1221. if (hasMeshes && isFirstMaterial) {
  1222. //Set the material name to the previous mesh (1 material per mesh)
  1223. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1224. isFirstMaterial = false;
  1225. }
  1226. //Keyword for loading the mtl file
  1227. }
  1228. else if (this.mtllib.test(line)) {
  1229. //Get the name of mtl file
  1230. fileToLoad = line.substring(7).trim();
  1231. //Apply smoothing
  1232. }
  1233. else if (this.smooth.test(line)) {
  1234. // smooth shading => apply smoothing
  1235. //Today I don't know it work with babylon and with obj.
  1236. //With the obj file an integer is set
  1237. }
  1238. else {
  1239. //If there is another possibility
  1240. console.log("Unhandled expression at line : " + line);
  1241. }
  1242. }
  1243. //At the end of the file, add the last mesh into the meshesFromObj array
  1244. if (hasMeshes) {
  1245. //Set the data for the last mesh
  1246. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1247. //Reverse indices for displaying faces in the good sense
  1248. indicesForBabylon.reverse();
  1249. //Get the good array
  1250. unwrapData();
  1251. //Set array
  1252. handledMesh.indices = indicesForBabylon;
  1253. handledMesh.positions = unwrappedPositionsForBabylon;
  1254. handledMesh.normals = unwrappedNormalsForBabylon;
  1255. handledMesh.uvs = unwrappedUVForBabylon;
  1256. if (this._meshLoadOptions.ImportVertexColors === true) {
  1257. handledMesh.colors = unwrappedColorsForBabylon;
  1258. }
  1259. }
  1260. //If any o or g keyword found, create a mesh with a random id
  1261. if (!hasMeshes) {
  1262. // reverse tab of indices
  1263. indicesForBabylon.reverse();
  1264. //Get positions normals uvs
  1265. unwrapData();
  1266. //Set data for one mesh
  1267. meshesFromObj.push({
  1268. name: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1269. indices: indicesForBabylon,
  1270. positions: unwrappedPositionsForBabylon,
  1271. colors: unwrappedColorsForBabylon,
  1272. normals: unwrappedNormalsForBabylon,
  1273. uvs: unwrappedUVForBabylon,
  1274. materialName: materialNameFromObj
  1275. });
  1276. }
  1277. //Create a Mesh list
  1278. var babylonMeshesArray = []; //The mesh for babylon
  1279. var materialToUse = new Array();
  1280. //Set data for each mesh
  1281. for (var j = 0; j < meshesFromObj.length; j++) {
  1282. //check meshesNames (stlFileLoader)
  1283. if (meshesNames && meshesFromObj[j].name) {
  1284. if (meshesNames instanceof Array) {
  1285. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1286. continue;
  1287. }
  1288. }
  1289. else {
  1290. if (meshesFromObj[j].name !== meshesNames) {
  1291. continue;
  1292. }
  1293. }
  1294. }
  1295. //Get the current mesh
  1296. //Set the data with VertexBuffer for each mesh
  1297. handledMesh = meshesFromObj[j];
  1298. //Create a Mesh with the name of the obj mesh
  1299. scene._blockEntityCollection = this._forAssetContainer;
  1300. var babylonMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1301. scene._blockEntityCollection = false;
  1302. //Push the name of the material to an array
  1303. //This is indispensable for the importMesh function
  1304. materialToUse.push(meshesFromObj[j].materialName);
  1305. var vertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1306. //Set the data for the babylonMesh
  1307. vertexData.uvs = handledMesh.uvs;
  1308. vertexData.indices = handledMesh.indices;
  1309. vertexData.positions = handledMesh.positions;
  1310. if (this._meshLoadOptions.ComputeNormals === true) {
  1311. var normals_1 = new Array();
  1312. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1313. vertexData.normals = normals_1;
  1314. }
  1315. else {
  1316. vertexData.normals = handledMesh.normals;
  1317. }
  1318. if (this._meshLoadOptions.ImportVertexColors === true) {
  1319. vertexData.colors = handledMesh.colors;
  1320. }
  1321. //Set the data from the VertexBuffer to the current Mesh
  1322. vertexData.applyToMesh(babylonMesh);
  1323. if (this._meshLoadOptions.InvertY) {
  1324. babylonMesh.scaling.y *= -1;
  1325. }
  1326. //Push the mesh into an array
  1327. babylonMeshesArray.push(babylonMesh);
  1328. }
  1329. var mtlPromises = [];
  1330. //load the materials
  1331. //Check if we have a file to load
  1332. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1333. //Load the file synchronously
  1334. mtlPromises.push(new Promise(function (resolve, reject) {
  1335. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1336. try {
  1337. //Create materials thanks MTLLoader function
  1338. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._forAssetContainer);
  1339. //Look at each material loaded in the mtl file
  1340. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1341. //Three variables to get all meshes with the same material
  1342. var startIndex = 0;
  1343. var _indices = [];
  1344. var _index;
  1345. //The material from MTL file is used in the meshes loaded
  1346. //Push the indice in an array
  1347. //Check if the material is not used for another mesh
  1348. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1349. _indices.push(_index);
  1350. startIndex = _index + 1;
  1351. }
  1352. //If the material is not used dispose it
  1353. if (_index === -1 && _indices.length === 0) {
  1354. //If the material is not needed, remove it
  1355. materialsFromMTLFile.materials[n].dispose();
  1356. }
  1357. else {
  1358. for (var o = 0; o < _indices.length; o++) {
  1359. //Apply the material to the Mesh for each mesh with the material
  1360. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1361. }
  1362. }
  1363. }
  1364. resolve();
  1365. }
  1366. catch (e) {
  1367. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1368. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1369. resolve();
  1370. }
  1371. else {
  1372. reject(e);
  1373. }
  1374. }
  1375. }, function (pathOfFile, exception) {
  1376. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1377. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1378. resolve();
  1379. }
  1380. else {
  1381. reject(exception);
  1382. }
  1383. });
  1384. }));
  1385. }
  1386. //Return an array with all Mesh
  1387. return Promise.all(mtlPromises).then(function () {
  1388. return babylonMeshesArray;
  1389. });
  1390. };
  1391. /**
  1392. * Defines if UVs are optimized by default during load.
  1393. */
  1394. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1395. /**
  1396. * Invert model on y-axis (does a model scaling inversion)
  1397. */
  1398. OBJFileLoader.INVERT_Y = false;
  1399. /**
  1400. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1401. */
  1402. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1403. /**
  1404. * Compute the normals for the model, even if normals are present in the file.
  1405. */
  1406. OBJFileLoader.COMPUTE_NORMALS = false;
  1407. /**
  1408. * Defines custom scaling of UV coordinates of loaded meshes.
  1409. */
  1410. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1411. /**
  1412. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1413. */
  1414. OBJFileLoader.SKIP_MATERIALS = false;
  1415. /**
  1416. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1417. *
  1418. * Defaults to true for backwards compatibility.
  1419. */
  1420. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1421. return OBJFileLoader;
  1422. }());
  1423. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1424. //Add this loader into the register plugin
  1425. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1426. }
  1427. /***/ }),
  1428. /***/ "./STL/index.ts":
  1429. /*!**********************!*\
  1430. !*** ./STL/index.ts ***!
  1431. \**********************/
  1432. /*! exports provided: STLFileLoader */
  1433. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1434. "use strict";
  1435. __webpack_require__.r(__webpack_exports__);
  1436. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1437. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1438. /***/ }),
  1439. /***/ "./STL/stlFileLoader.ts":
  1440. /*!******************************!*\
  1441. !*** ./STL/stlFileLoader.ts ***!
  1442. \******************************/
  1443. /*! exports provided: STLFileLoader */
  1444. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1445. "use strict";
  1446. __webpack_require__.r(__webpack_exports__);
  1447. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1448. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  1449. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1450. /**
  1451. * STL file type loader.
  1452. * This is a babylon scene loader plugin.
  1453. */
  1454. var STLFileLoader = /** @class */ (function () {
  1455. function STLFileLoader() {
  1456. /** @hidden */
  1457. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  1458. /** @hidden */
  1459. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1460. /** @hidden */
  1461. this.normalPattern = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1462. /** @hidden */
  1463. this.vertexPattern = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1464. /**
  1465. * Defines the name of the plugin.
  1466. */
  1467. this.name = "stl";
  1468. /**
  1469. * Defines the extensions the stl loader is able to load.
  1470. * force data to come in as an ArrayBuffer
  1471. * we'll convert to string if it looks like it's an ASCII .stl
  1472. */
  1473. this.extensions = {
  1474. ".stl": { isBinary: true },
  1475. };
  1476. }
  1477. /**
  1478. * Import meshes into a scene.
  1479. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1480. * @param scene The scene to import into
  1481. * @param data The data to import
  1482. * @param rootUrl The root url for scene and resources
  1483. * @param meshes The meshes array to import into
  1484. * @param particleSystems The particle systems array to import into
  1485. * @param skeletons The skeletons array to import into
  1486. * @param onError The callback when import fails
  1487. * @returns True if successful or false otherwise
  1488. */
  1489. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1490. var matches;
  1491. if (typeof data !== "string") {
  1492. if (this._isBinary(data)) {
  1493. // binary .stl
  1494. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1495. this._parseBinary(babylonMesh, data);
  1496. if (meshes) {
  1497. meshes.push(babylonMesh);
  1498. }
  1499. return true;
  1500. }
  1501. // ASCII .stl
  1502. // convert to string
  1503. var array_buffer = new Uint8Array(data);
  1504. var str = '';
  1505. for (var i = 0; i < data.byteLength; i++) {
  1506. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1507. }
  1508. data = str;
  1509. }
  1510. //if arrived here, data is a string, containing the STLA data.
  1511. while (matches = this.solidPattern.exec(data)) {
  1512. var meshName = matches[1];
  1513. var meshNameFromEnd = matches[3];
  1514. if (meshName != meshNameFromEnd) {
  1515. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1516. return false;
  1517. }
  1518. // check meshesNames
  1519. if (meshesNames && meshName) {
  1520. if (meshesNames instanceof Array) {
  1521. if (!meshesNames.indexOf(meshName)) {
  1522. continue;
  1523. }
  1524. }
  1525. else {
  1526. if (meshName !== meshesNames) {
  1527. continue;
  1528. }
  1529. }
  1530. }
  1531. // stl mesh name can be empty as well
  1532. meshName = meshName || "stlmesh";
  1533. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1534. this._parseASCII(babylonMesh, matches[2]);
  1535. if (meshes) {
  1536. meshes.push(babylonMesh);
  1537. }
  1538. }
  1539. return true;
  1540. };
  1541. /**
  1542. * Load into a scene.
  1543. * @param scene The scene to load into
  1544. * @param data The data to import
  1545. * @param rootUrl The root url for scene and resources
  1546. * @param onError The callback when import fails
  1547. * @returns true if successful or false otherwise
  1548. */
  1549. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1550. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1551. return result;
  1552. };
  1553. /**
  1554. * Load into an asset container.
  1555. * @param scene The scene to load into
  1556. * @param data The data to import
  1557. * @param rootUrl The root url for scene and resources
  1558. * @param onError The callback when import fails
  1559. * @returns The loaded asset container
  1560. */
  1561. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1562. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1563. scene._blockEntityCollection = true;
  1564. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1565. scene._blockEntityCollection = false;
  1566. return container;
  1567. };
  1568. STLFileLoader.prototype._isBinary = function (data) {
  1569. // check if file size is correct for binary stl
  1570. var faceSize, nFaces, reader;
  1571. reader = new DataView(data);
  1572. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1573. nFaces = reader.getUint32(80, true);
  1574. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1575. return true;
  1576. }
  1577. // check characters higher than ASCII to confirm binary
  1578. var fileLength = reader.byteLength;
  1579. for (var index = 0; index < fileLength; index++) {
  1580. if (reader.getUint8(index) > 127) {
  1581. return true;
  1582. }
  1583. }
  1584. return false;
  1585. };
  1586. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1587. var reader = new DataView(data);
  1588. var faces = reader.getUint32(80, true);
  1589. var dataOffset = 84;
  1590. var faceLength = 12 * 4 + 2;
  1591. var offset = 0;
  1592. var positions = new Float32Array(faces * 3 * 3);
  1593. var normals = new Float32Array(faces * 3 * 3);
  1594. var indices = new Uint32Array(faces * 3);
  1595. var indicesCount = 0;
  1596. for (var face = 0; face < faces; face++) {
  1597. var start = dataOffset + face * faceLength;
  1598. var normalX = reader.getFloat32(start, true);
  1599. var normalY = reader.getFloat32(start + 4, true);
  1600. var normalZ = reader.getFloat32(start + 8, true);
  1601. for (var i = 1; i <= 3; i++) {
  1602. var vertexstart = start + i * 12;
  1603. // ordering is intentional to match ascii import
  1604. positions[offset] = reader.getFloat32(vertexstart, true);
  1605. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1606. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1607. normals[offset] = normalX;
  1608. normals[offset + 2] = normalY;
  1609. normals[offset + 1] = normalZ;
  1610. offset += 3;
  1611. }
  1612. indices[indicesCount] = indicesCount++;
  1613. indices[indicesCount] = indicesCount++;
  1614. indices[indicesCount] = indicesCount++;
  1615. }
  1616. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1617. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1618. mesh.setIndices(indices);
  1619. mesh.computeWorldMatrix(true);
  1620. };
  1621. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1622. var positions = [];
  1623. var normals = [];
  1624. var indices = [];
  1625. var indicesCount = 0;
  1626. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1627. var matches;
  1628. while (matches = this.facetsPattern.exec(solidData)) {
  1629. var facet = matches[1];
  1630. //one normal per face
  1631. var normalMatches = this.normalPattern.exec(facet);
  1632. this.normalPattern.lastIndex = 0;
  1633. if (!normalMatches) {
  1634. continue;
  1635. }
  1636. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1637. var vertexMatch;
  1638. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1639. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1640. normals.push(normal[0], normal[1], normal[2]);
  1641. }
  1642. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1643. this.vertexPattern.lastIndex = 0;
  1644. }
  1645. this.facetsPattern.lastIndex = 0;
  1646. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1647. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1648. mesh.setIndices(indices);
  1649. mesh.computeWorldMatrix(true);
  1650. };
  1651. return STLFileLoader;
  1652. }());
  1653. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1654. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1655. }
  1656. /***/ }),
  1657. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1658. /*!*****************************************!*\
  1659. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1660. \*****************************************/
  1661. /*! exports provided: GLTFBinaryExtension */
  1662. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1663. "use strict";
  1664. __webpack_require__.r(__webpack_exports__);
  1665. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1666. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1667. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1668. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1669. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1670. var BinaryExtensionBufferName = "binary_glTF";
  1671. /** @hidden */
  1672. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1673. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1674. function GLTFBinaryExtension() {
  1675. return _super.call(this, "KHR_binary_glTF") || this;
  1676. }
  1677. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1678. var extensionsUsed = data.json.extensionsUsed;
  1679. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1680. return false;
  1681. }
  1682. this._bin = data.bin;
  1683. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1684. return true;
  1685. };
  1686. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1687. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1688. return false;
  1689. }
  1690. if (id !== BinaryExtensionBufferName) {
  1691. return false;
  1692. }
  1693. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1694. return true;
  1695. };
  1696. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1697. var texture = gltfRuntime.textures[id];
  1698. var source = gltfRuntime.images[texture.source];
  1699. if (!source.extensions || !(this.name in source.extensions)) {
  1700. return false;
  1701. }
  1702. var sourceExt = source.extensions[this.name];
  1703. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1704. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1705. onSuccess(buffer);
  1706. return true;
  1707. };
  1708. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1709. var shader = gltfRuntime.shaders[id];
  1710. if (!shader.extensions || !(this.name in shader.extensions)) {
  1711. return false;
  1712. }
  1713. var binaryExtensionShader = shader.extensions[this.name];
  1714. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1715. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1716. setTimeout(function () {
  1717. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1718. onSuccess(shaderString);
  1719. });
  1720. return true;
  1721. };
  1722. return GLTFBinaryExtension;
  1723. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1724. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1725. /***/ }),
  1726. /***/ "./glTF/1.0/glTFLoader.ts":
  1727. /*!********************************!*\
  1728. !*** ./glTF/1.0/glTFLoader.ts ***!
  1729. \********************************/
  1730. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1731. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1732. "use strict";
  1733. __webpack_require__.r(__webpack_exports__);
  1734. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1735. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1736. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1737. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1738. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  1739. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  1740. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1741. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1742. /**
  1743. * Tokenizer. Used for shaders compatibility
  1744. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1745. */
  1746. var ETokenType;
  1747. (function (ETokenType) {
  1748. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1749. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1750. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1751. })(ETokenType || (ETokenType = {}));
  1752. var Tokenizer = /** @class */ (function () {
  1753. function Tokenizer(toParse) {
  1754. this._pos = 0;
  1755. this.currentToken = ETokenType.UNKNOWN;
  1756. this.currentIdentifier = "";
  1757. this.currentString = "";
  1758. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1759. this._toParse = toParse;
  1760. this._maxPos = toParse.length;
  1761. }
  1762. Tokenizer.prototype.getNextToken = function () {
  1763. if (this.isEnd()) {
  1764. return ETokenType.END_OF_INPUT;
  1765. }
  1766. this.currentString = this.read();
  1767. this.currentToken = ETokenType.UNKNOWN;
  1768. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1769. this.currentToken = ETokenType.IDENTIFIER;
  1770. this.currentIdentifier = this.currentString;
  1771. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1772. this.currentIdentifier += this.currentString;
  1773. this.forward();
  1774. }
  1775. }
  1776. return this.currentToken;
  1777. };
  1778. Tokenizer.prototype.peek = function () {
  1779. return this._toParse[this._pos];
  1780. };
  1781. Tokenizer.prototype.read = function () {
  1782. return this._toParse[this._pos++];
  1783. };
  1784. Tokenizer.prototype.forward = function () {
  1785. this._pos++;
  1786. };
  1787. Tokenizer.prototype.isEnd = function () {
  1788. return this._pos >= this._maxPos;
  1789. };
  1790. return Tokenizer;
  1791. }());
  1792. /**
  1793. * Values
  1794. */
  1795. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1796. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1797. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1798. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1799. /**
  1800. * Parse
  1801. */
  1802. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1803. for (var buf in parsedBuffers) {
  1804. var parsedBuffer = parsedBuffers[buf];
  1805. gltfRuntime.buffers[buf] = parsedBuffer;
  1806. gltfRuntime.buffersCount++;
  1807. }
  1808. };
  1809. var parseShaders = function (parsedShaders, gltfRuntime) {
  1810. for (var sha in parsedShaders) {
  1811. var parsedShader = parsedShaders[sha];
  1812. gltfRuntime.shaders[sha] = parsedShader;
  1813. gltfRuntime.shaderscount++;
  1814. }
  1815. };
  1816. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1817. for (var object in parsedObjects) {
  1818. var parsedObject = parsedObjects[object];
  1819. gltfRuntime[runtimeProperty][object] = parsedObject;
  1820. }
  1821. };
  1822. /**
  1823. * Utils
  1824. */
  1825. var normalizeUVs = function (buffer) {
  1826. if (!buffer) {
  1827. return;
  1828. }
  1829. for (var i = 0; i < buffer.length / 2; i++) {
  1830. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1831. }
  1832. };
  1833. var getAttribute = function (attributeParameter) {
  1834. if (attributeParameter.semantic === "NORMAL") {
  1835. return "normal";
  1836. }
  1837. else if (attributeParameter.semantic === "POSITION") {
  1838. return "position";
  1839. }
  1840. else if (attributeParameter.semantic === "JOINT") {
  1841. return "matricesIndices";
  1842. }
  1843. else if (attributeParameter.semantic === "WEIGHT") {
  1844. return "matricesWeights";
  1845. }
  1846. else if (attributeParameter.semantic === "COLOR") {
  1847. return "color";
  1848. }
  1849. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1850. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1851. return "uv" + (channel === 0 ? "" : channel + 1);
  1852. }
  1853. return null;
  1854. };
  1855. /**
  1856. * Loads and creates animations
  1857. */
  1858. var loadAnimations = function (gltfRuntime) {
  1859. for (var anim in gltfRuntime.animations) {
  1860. var animation = gltfRuntime.animations[anim];
  1861. if (!animation.channels || !animation.samplers) {
  1862. continue;
  1863. }
  1864. var lastAnimation = null;
  1865. for (var i = 0; i < animation.channels.length; i++) {
  1866. // Get parameters and load buffers
  1867. var channel = animation.channels[i];
  1868. var sampler = animation.samplers[channel.sampler];
  1869. if (!sampler) {
  1870. continue;
  1871. }
  1872. var inputData = null;
  1873. var outputData = null;
  1874. if (animation.parameters) {
  1875. inputData = animation.parameters[sampler.input];
  1876. outputData = animation.parameters[sampler.output];
  1877. }
  1878. else {
  1879. inputData = sampler.input;
  1880. outputData = sampler.output;
  1881. }
  1882. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1883. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1884. var targetID = channel.target.id;
  1885. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1886. if (targetNode === null) {
  1887. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1888. }
  1889. if (targetNode === null) {
  1890. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1891. continue;
  1892. }
  1893. var isBone = targetNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1894. // Get target path (position, rotation or scaling)
  1895. var targetPath = channel.target.path;
  1896. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1897. if (targetPathIndex !== -1) {
  1898. targetPath = babylonAnimationPaths[targetPathIndex];
  1899. }
  1900. // Determine animation type
  1901. var animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1902. if (!isBone) {
  1903. if (targetPath === "rotationQuaternion") {
  1904. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1905. targetNode.rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1906. }
  1907. else {
  1908. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1909. }
  1910. }
  1911. // Create animation and key frames
  1912. var babylonAnimation = null;
  1913. var keys = [];
  1914. var arrayOffset = 0;
  1915. var modifyKey = false;
  1916. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1917. babylonAnimation = lastAnimation;
  1918. modifyKey = true;
  1919. }
  1920. if (!modifyKey) {
  1921. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1922. 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);
  1923. gltfRuntime.scene._blockEntityCollection = false;
  1924. }
  1925. // For each frame
  1926. for (var j = 0; j < bufferInput.length; j++) {
  1927. var value = null;
  1928. if (targetPath === "rotationQuaternion") { // VEC4
  1929. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1930. arrayOffset += 4;
  1931. }
  1932. else { // Position and scaling are VEC3
  1933. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1934. arrayOffset += 3;
  1935. }
  1936. if (isBone) {
  1937. var bone = targetNode;
  1938. var translation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1939. var rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1940. var scaling = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1941. // Warning on decompose
  1942. var mat = bone.getBaseMatrix();
  1943. if (modifyKey && lastAnimation) {
  1944. mat = lastAnimation.getKeys()[j].value;
  1945. }
  1946. mat.decompose(scaling, rotationQuaternion, translation);
  1947. if (targetPath === "position") {
  1948. translation = value;
  1949. }
  1950. else if (targetPath === "rotationQuaternion") {
  1951. rotationQuaternion = value;
  1952. }
  1953. else {
  1954. scaling = value;
  1955. }
  1956. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1957. }
  1958. if (!modifyKey) {
  1959. keys.push({
  1960. frame: bufferInput[j],
  1961. value: value
  1962. });
  1963. }
  1964. else if (lastAnimation) {
  1965. lastAnimation.getKeys()[j].value = value;
  1966. }
  1967. }
  1968. // Finish
  1969. if (!modifyKey && babylonAnimation) {
  1970. babylonAnimation.setKeys(keys);
  1971. targetNode.animations.push(babylonAnimation);
  1972. }
  1973. lastAnimation = babylonAnimation;
  1974. gltfRuntime.scene.stopAnimation(targetNode);
  1975. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  1976. }
  1977. }
  1978. };
  1979. /**
  1980. * Returns the bones transformation matrix
  1981. */
  1982. var configureBoneTransformation = function (node) {
  1983. var mat = null;
  1984. if (node.translation || node.rotation || node.scale) {
  1985. var scale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  1986. var rotation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  1987. var position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  1988. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  1989. }
  1990. else {
  1991. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1992. }
  1993. return mat;
  1994. };
  1995. /**
  1996. * Returns the parent bone
  1997. */
  1998. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  1999. // Try to find
  2000. for (var i = 0; i < newSkeleton.bones.length; i++) {
  2001. if (newSkeleton.bones[i].name === jointName) {
  2002. return newSkeleton.bones[i];
  2003. }
  2004. }
  2005. // Not found, search in gltf nodes
  2006. var nodes = gltfRuntime.nodes;
  2007. for (var nde in nodes) {
  2008. var node = nodes[nde];
  2009. if (!node.jointName) {
  2010. continue;
  2011. }
  2012. var children = node.children;
  2013. for (var i = 0; i < children.length; i++) {
  2014. var child = gltfRuntime.nodes[children[i]];
  2015. if (!child.jointName) {
  2016. continue;
  2017. }
  2018. if (child.jointName === jointName) {
  2019. var mat = configureBoneTransformation(node);
  2020. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  2021. bone.id = nde;
  2022. return bone;
  2023. }
  2024. }
  2025. }
  2026. return null;
  2027. };
  2028. /**
  2029. * Returns the appropriate root node
  2030. */
  2031. var getNodeToRoot = function (nodesToRoot, id) {
  2032. for (var i = 0; i < nodesToRoot.length; i++) {
  2033. var nodeToRoot = nodesToRoot[i];
  2034. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  2035. var child = nodeToRoot.node.children[j];
  2036. if (child === id) {
  2037. return nodeToRoot.bone;
  2038. }
  2039. }
  2040. }
  2041. return null;
  2042. };
  2043. /**
  2044. * Returns the node with the joint name
  2045. */
  2046. var getJointNode = function (gltfRuntime, jointName) {
  2047. var nodes = gltfRuntime.nodes;
  2048. var node = nodes[jointName];
  2049. if (node) {
  2050. return {
  2051. node: node,
  2052. id: jointName
  2053. };
  2054. }
  2055. for (var nde in nodes) {
  2056. node = nodes[nde];
  2057. if (node.jointName === jointName) {
  2058. return {
  2059. node: node,
  2060. id: nde
  2061. };
  2062. }
  2063. }
  2064. return null;
  2065. };
  2066. /**
  2067. * Checks if a nodes is in joints
  2068. */
  2069. var nodeIsInJoints = function (skins, id) {
  2070. for (var i = 0; i < skins.jointNames.length; i++) {
  2071. if (skins.jointNames[i] === id) {
  2072. return true;
  2073. }
  2074. }
  2075. return false;
  2076. };
  2077. /**
  2078. * Fills the nodes to root for bones and builds hierarchy
  2079. */
  2080. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2081. // Creates nodes for root
  2082. for (var nde in gltfRuntime.nodes) {
  2083. var node = gltfRuntime.nodes[nde];
  2084. var id = nde;
  2085. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2086. continue;
  2087. }
  2088. // Create node to root bone
  2089. var mat = configureBoneTransformation(node);
  2090. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2091. bone.id = id;
  2092. nodesToRoot.push({ bone: bone, node: node, id: id });
  2093. }
  2094. // Parenting
  2095. for (var i = 0; i < nodesToRoot.length; i++) {
  2096. var nodeToRoot = nodesToRoot[i];
  2097. var children = nodeToRoot.node.children;
  2098. for (var j = 0; j < children.length; j++) {
  2099. var child = null;
  2100. for (var k = 0; k < nodesToRoot.length; k++) {
  2101. if (nodesToRoot[k].id === children[j]) {
  2102. child = nodesToRoot[k];
  2103. break;
  2104. }
  2105. }
  2106. if (child) {
  2107. child.bone._parent = nodeToRoot.bone;
  2108. nodeToRoot.bone.children.push(child.bone);
  2109. }
  2110. }
  2111. }
  2112. };
  2113. /**
  2114. * Imports a skeleton
  2115. */
  2116. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2117. if (!newSkeleton) {
  2118. newSkeleton = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2119. }
  2120. if (!skins.babylonSkeleton) {
  2121. return newSkeleton;
  2122. }
  2123. // Find the root bones
  2124. var nodesToRoot = [];
  2125. var nodesToRootToAdd = [];
  2126. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2127. newSkeleton.bones = [];
  2128. // Joints
  2129. for (var i = 0; i < skins.jointNames.length; i++) {
  2130. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2131. if (!jointNode) {
  2132. continue;
  2133. }
  2134. var node = jointNode.node;
  2135. if (!node) {
  2136. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2137. continue;
  2138. }
  2139. var id = jointNode.id;
  2140. // Optimize, if the bone already exists...
  2141. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2142. if (existingBone) {
  2143. newSkeleton.bones.push(existingBone);
  2144. continue;
  2145. }
  2146. // Search for parent bone
  2147. var foundBone = false;
  2148. var parentBone = null;
  2149. for (var j = 0; j < i; j++) {
  2150. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2151. if (!jointNode_1) {
  2152. continue;
  2153. }
  2154. var joint = jointNode_1.node;
  2155. if (!joint) {
  2156. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2157. continue;
  2158. }
  2159. var children = joint.children;
  2160. if (!children) {
  2161. continue;
  2162. }
  2163. foundBone = false;
  2164. for (var k = 0; k < children.length; k++) {
  2165. if (children[k] === id) {
  2166. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2167. foundBone = true;
  2168. break;
  2169. }
  2170. }
  2171. if (foundBone) {
  2172. break;
  2173. }
  2174. }
  2175. // Create bone
  2176. var mat = configureBoneTransformation(node);
  2177. if (!parentBone && nodesToRoot.length > 0) {
  2178. parentBone = getNodeToRoot(nodesToRoot, id);
  2179. if (parentBone) {
  2180. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2181. nodesToRootToAdd.push(parentBone);
  2182. }
  2183. }
  2184. }
  2185. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2186. bone.id = id;
  2187. }
  2188. // Polish
  2189. var bones = newSkeleton.bones;
  2190. newSkeleton.bones = [];
  2191. for (var i = 0; i < skins.jointNames.length; i++) {
  2192. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2193. if (!jointNode) {
  2194. continue;
  2195. }
  2196. for (var j = 0; j < bones.length; j++) {
  2197. if (bones[j].id === jointNode.id) {
  2198. newSkeleton.bones.push(bones[j]);
  2199. break;
  2200. }
  2201. }
  2202. }
  2203. newSkeleton.prepare();
  2204. // Finish
  2205. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2206. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2207. }
  2208. return newSkeleton;
  2209. };
  2210. /**
  2211. * Imports a mesh and its geometries
  2212. */
  2213. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2214. if (!newMesh) {
  2215. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2216. newMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2217. gltfRuntime.scene._blockEntityCollection = false;
  2218. newMesh.id = id;
  2219. }
  2220. if (!node.babylonNode) {
  2221. return newMesh;
  2222. }
  2223. var subMaterials = [];
  2224. var vertexData = null;
  2225. var verticesStarts = new Array();
  2226. var verticesCounts = new Array();
  2227. var indexStarts = new Array();
  2228. var indexCounts = new Array();
  2229. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2230. var meshID = meshes[meshIndex];
  2231. var mesh = gltfRuntime.meshes[meshID];
  2232. if (!mesh) {
  2233. continue;
  2234. }
  2235. // Positions, normals and UVs
  2236. for (var i = 0; i < mesh.primitives.length; i++) {
  2237. // Temporary vertex data
  2238. var tempVertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2239. var primitive = mesh.primitives[i];
  2240. if (primitive.mode !== 4) {
  2241. // continue;
  2242. }
  2243. var attributes = primitive.attributes;
  2244. var accessor = null;
  2245. var buffer = null;
  2246. // Set positions, normal and uvs
  2247. for (var semantic in attributes) {
  2248. // Link accessor and buffer view
  2249. accessor = gltfRuntime.accessors[attributes[semantic]];
  2250. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2251. if (semantic === "NORMAL") {
  2252. tempVertexData.normals = new Float32Array(buffer.length);
  2253. tempVertexData.normals.set(buffer);
  2254. }
  2255. else if (semantic === "POSITION") {
  2256. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2257. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2258. for (var j = 0; j < buffer.length; j += 4) {
  2259. tempVertexData.positions[j] = buffer[j];
  2260. tempVertexData.positions[j + 1] = buffer[j + 1];
  2261. tempVertexData.positions[j + 2] = buffer[j + 2];
  2262. }
  2263. }
  2264. else {
  2265. tempVertexData.positions = new Float32Array(buffer.length);
  2266. tempVertexData.positions.set(buffer);
  2267. }
  2268. verticesCounts.push(tempVertexData.positions.length);
  2269. }
  2270. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2271. var channel = Number(semantic.split("_")[1]);
  2272. var uvKind = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2273. var uvs = new Float32Array(buffer.length);
  2274. uvs.set(buffer);
  2275. normalizeUVs(uvs);
  2276. tempVertexData.set(uvs, uvKind);
  2277. }
  2278. else if (semantic === "JOINT") {
  2279. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2280. tempVertexData.matricesIndices.set(buffer);
  2281. }
  2282. else if (semantic === "WEIGHT") {
  2283. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2284. tempVertexData.matricesWeights.set(buffer);
  2285. }
  2286. else if (semantic === "COLOR") {
  2287. tempVertexData.colors = new Float32Array(buffer.length);
  2288. tempVertexData.colors.set(buffer);
  2289. }
  2290. }
  2291. // Indices
  2292. accessor = gltfRuntime.accessors[primitive.indices];
  2293. if (accessor) {
  2294. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2295. tempVertexData.indices = new Int32Array(buffer.length);
  2296. tempVertexData.indices.set(buffer);
  2297. indexCounts.push(tempVertexData.indices.length);
  2298. }
  2299. else {
  2300. // Set indices on the fly
  2301. var indices = [];
  2302. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2303. indices.push(j);
  2304. }
  2305. tempVertexData.indices = new Int32Array(indices);
  2306. indexCounts.push(tempVertexData.indices.length);
  2307. }
  2308. if (!vertexData) {
  2309. vertexData = tempVertexData;
  2310. }
  2311. else {
  2312. vertexData.merge(tempVertexData);
  2313. }
  2314. // Sub material
  2315. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2316. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2317. // Update vertices start and index start
  2318. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2319. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2320. }
  2321. }
  2322. var material;
  2323. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2324. if (subMaterials.length > 1) {
  2325. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2326. material.subMaterials = subMaterials;
  2327. }
  2328. else {
  2329. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2330. }
  2331. if (subMaterials.length === 1) {
  2332. material = subMaterials[0];
  2333. }
  2334. if (!newMesh.material) {
  2335. newMesh.material = material;
  2336. }
  2337. // Apply geometry
  2338. new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2339. newMesh.computeWorldMatrix(true);
  2340. gltfRuntime.scene._blockEntityCollection = false;
  2341. // Apply submeshes
  2342. newMesh.subMeshes = [];
  2343. var index = 0;
  2344. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2345. var meshID = meshes[meshIndex];
  2346. var mesh = gltfRuntime.meshes[meshID];
  2347. if (!mesh) {
  2348. continue;
  2349. }
  2350. for (var i = 0; i < mesh.primitives.length; i++) {
  2351. if (mesh.primitives[i].mode !== 4) {
  2352. //continue;
  2353. }
  2354. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2355. index++;
  2356. }
  2357. }
  2358. // Finish
  2359. return newMesh;
  2360. };
  2361. /**
  2362. * Configure node transformation from position, rotation and scaling
  2363. */
  2364. var configureNode = function (newNode, position, rotation, scaling) {
  2365. if (newNode.position) {
  2366. newNode.position = position;
  2367. }
  2368. if (newNode.rotationQuaternion || newNode.rotation) {
  2369. newNode.rotationQuaternion = rotation;
  2370. }
  2371. if (newNode.scaling) {
  2372. newNode.scaling = scaling;
  2373. }
  2374. };
  2375. /**
  2376. * Configures node from transformation matrix
  2377. */
  2378. var configureNodeFromMatrix = function (newNode, node, parent) {
  2379. if (node.matrix) {
  2380. var position = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2381. var rotation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2382. var scaling = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2383. var mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2384. mat.decompose(scaling, rotation, position);
  2385. configureNode(newNode, position, rotation, scaling);
  2386. }
  2387. else if (node.translation && node.rotation && node.scale) {
  2388. 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));
  2389. }
  2390. newNode.computeWorldMatrix(true);
  2391. };
  2392. /**
  2393. * Imports a node
  2394. */
  2395. var importNode = function (gltfRuntime, node, id, parent) {
  2396. var lastNode = null;
  2397. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2398. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2399. return null;
  2400. }
  2401. }
  2402. // Meshes
  2403. if (node.skin) {
  2404. if (node.meshes) {
  2405. var skin = gltfRuntime.skins[node.skin];
  2406. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2407. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2408. if (newMesh.skeleton === null) {
  2409. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2410. if (!skin.babylonSkeleton) {
  2411. skin.babylonSkeleton = newMesh.skeleton;
  2412. }
  2413. }
  2414. lastNode = newMesh;
  2415. }
  2416. }
  2417. else if (node.meshes) {
  2418. /**
  2419. * Improve meshes property
  2420. */
  2421. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2422. lastNode = newMesh;
  2423. }
  2424. // Lights
  2425. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2426. var light = gltfRuntime.lights[node.light];
  2427. if (light) {
  2428. if (light.type === "ambient") {
  2429. var ambienLight = light[light.type];
  2430. 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);
  2431. hemiLight.name = node.name || "";
  2432. if (ambienLight.color) {
  2433. hemiLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2434. }
  2435. lastNode = hemiLight;
  2436. }
  2437. else if (light.type === "directional") {
  2438. var directionalLight = light[light.type];
  2439. 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);
  2440. dirLight.name = node.name || "";
  2441. if (directionalLight.color) {
  2442. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2443. }
  2444. lastNode = dirLight;
  2445. }
  2446. else if (light.type === "point") {
  2447. var pointLight = light[light.type];
  2448. 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);
  2449. ptLight.name = node.name || "";
  2450. if (pointLight.color) {
  2451. ptLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2452. }
  2453. lastNode = ptLight;
  2454. }
  2455. else if (light.type === "spot") {
  2456. var spotLight = light[light.type];
  2457. 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);
  2458. spLight.name = node.name || "";
  2459. if (spotLight.color) {
  2460. spLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2461. }
  2462. if (spotLight.fallOfAngle) {
  2463. spLight.angle = spotLight.fallOfAngle;
  2464. }
  2465. if (spotLight.fallOffExponent) {
  2466. spLight.exponent = spotLight.fallOffExponent;
  2467. }
  2468. lastNode = spLight;
  2469. }
  2470. }
  2471. }
  2472. // Cameras
  2473. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2474. var camera = gltfRuntime.cameras[node.camera];
  2475. if (camera) {
  2476. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2477. if (camera.type === "orthographic") {
  2478. 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);
  2479. orthoCamera.name = node.name || "";
  2480. orthoCamera.mode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2481. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2482. lastNode = orthoCamera;
  2483. }
  2484. else if (camera.type === "perspective") {
  2485. var perspectiveCamera = camera[camera.type];
  2486. 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);
  2487. persCamera.name = node.name || "";
  2488. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2489. if (!perspectiveCamera.aspectRatio) {
  2490. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2491. }
  2492. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2493. persCamera.maxZ = perspectiveCamera.zfar;
  2494. persCamera.minZ = perspectiveCamera.znear;
  2495. }
  2496. lastNode = persCamera;
  2497. }
  2498. gltfRuntime.scene._blockEntityCollection = false;
  2499. }
  2500. }
  2501. // Empty node
  2502. if (!node.jointName) {
  2503. if (node.babylonNode) {
  2504. return node.babylonNode;
  2505. }
  2506. else if (lastNode === null) {
  2507. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2508. var dummy = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2509. gltfRuntime.scene._blockEntityCollection = false;
  2510. node.babylonNode = dummy;
  2511. lastNode = dummy;
  2512. }
  2513. }
  2514. if (lastNode !== null) {
  2515. if (node.matrix && lastNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2516. configureNodeFromMatrix(lastNode, node, parent);
  2517. }
  2518. else {
  2519. var translation = node.translation || [0, 0, 0];
  2520. var rotation = node.rotation || [0, 0, 0, 1];
  2521. var scale = node.scale || [1, 1, 1];
  2522. 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));
  2523. }
  2524. lastNode.updateCache(true);
  2525. node.babylonNode = lastNode;
  2526. }
  2527. return lastNode;
  2528. };
  2529. /**
  2530. * Traverses nodes and creates them
  2531. */
  2532. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2533. if (meshIncluded === void 0) { meshIncluded = false; }
  2534. var node = gltfRuntime.nodes[id];
  2535. var newNode = null;
  2536. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2537. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2538. meshIncluded = true;
  2539. }
  2540. else {
  2541. meshIncluded = false;
  2542. }
  2543. }
  2544. else {
  2545. meshIncluded = true;
  2546. }
  2547. if (!node.jointName && meshIncluded) {
  2548. newNode = importNode(gltfRuntime, node, id, parent);
  2549. if (newNode !== null) {
  2550. newNode.id = id;
  2551. newNode.parent = parent;
  2552. }
  2553. }
  2554. if (node.children) {
  2555. for (var i = 0; i < node.children.length; i++) {
  2556. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2557. }
  2558. }
  2559. };
  2560. /**
  2561. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2562. */
  2563. var postLoad = function (gltfRuntime) {
  2564. // Nodes
  2565. var currentScene = gltfRuntime.currentScene;
  2566. if (currentScene) {
  2567. for (var i = 0; i < currentScene.nodes.length; i++) {
  2568. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2569. }
  2570. }
  2571. else {
  2572. for (var thing in gltfRuntime.scenes) {
  2573. currentScene = gltfRuntime.scenes[thing];
  2574. for (var i = 0; i < currentScene.nodes.length; i++) {
  2575. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2576. }
  2577. }
  2578. }
  2579. // Set animations
  2580. loadAnimations(gltfRuntime);
  2581. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2582. var skeleton = gltfRuntime.scene.skeletons[i];
  2583. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2584. }
  2585. };
  2586. /**
  2587. * onBind shaderrs callback to set uniforms and matrices
  2588. */
  2589. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2590. var materialValues = material.values || technique.parameters;
  2591. for (var unif in unTreatedUniforms) {
  2592. var uniform = unTreatedUniforms[unif];
  2593. var type = uniform.type;
  2594. 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) {
  2595. if (uniform.semantic && !uniform.source && !uniform.node) {
  2596. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2597. }
  2598. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2599. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2600. if (source === null) {
  2601. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2602. }
  2603. if (source === null) {
  2604. continue;
  2605. }
  2606. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2607. }
  2608. }
  2609. else {
  2610. var value = materialValues[technique.uniforms[unif]];
  2611. if (!value) {
  2612. continue;
  2613. }
  2614. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2615. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2616. if (texture === null || texture === undefined) {
  2617. continue;
  2618. }
  2619. shaderMaterial.getEffect().setTexture(unif, texture);
  2620. }
  2621. else {
  2622. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2623. }
  2624. }
  2625. }
  2626. onSuccess(shaderMaterial);
  2627. };
  2628. /**
  2629. * Prepare uniforms to send the only one time
  2630. * Loads the appropriate textures
  2631. */
  2632. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2633. var materialValues = material.values || technique.parameters;
  2634. var techniqueUniforms = technique.uniforms;
  2635. /**
  2636. * Prepare values here (not matrices)
  2637. */
  2638. for (var unif in unTreatedUniforms) {
  2639. var uniform = unTreatedUniforms[unif];
  2640. var type = uniform.type;
  2641. var value = materialValues[techniqueUniforms[unif]];
  2642. if (value === undefined) {
  2643. // In case the value is the same for all materials
  2644. value = uniform.value;
  2645. }
  2646. if (!value) {
  2647. continue;
  2648. }
  2649. var onLoadTexture = function (uniformName) {
  2650. return function (texture) {
  2651. if (uniform.value && uniformName) {
  2652. // Static uniform
  2653. shaderMaterial.setTexture(uniformName, texture);
  2654. delete unTreatedUniforms[uniformName];
  2655. }
  2656. };
  2657. };
  2658. // Texture (sampler2D)
  2659. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2660. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2661. }
  2662. // Others
  2663. else {
  2664. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2665. // Static uniform
  2666. delete unTreatedUniforms[unif];
  2667. }
  2668. }
  2669. }
  2670. };
  2671. /**
  2672. * Shader compilation failed
  2673. */
  2674. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2675. return function (effect, error) {
  2676. shaderMaterial.dispose(true);
  2677. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2678. };
  2679. };
  2680. /**
  2681. * Shader compilation success
  2682. */
  2683. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2684. return function (_) {
  2685. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2686. shaderMaterial.onBind = function (mesh) {
  2687. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2688. };
  2689. };
  2690. };
  2691. /**
  2692. * Returns the appropriate uniform if already handled by babylon
  2693. */
  2694. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2695. for (var unif in technique.uniforms) {
  2696. var uniform = technique.uniforms[unif];
  2697. var uniformParameter = technique.parameters[uniform];
  2698. if (tokenizer.currentIdentifier === unif) {
  2699. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2700. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2701. if (transformIndex !== -1) {
  2702. delete unTreatedUniforms[unif];
  2703. return babylonTransforms[transformIndex];
  2704. }
  2705. }
  2706. }
  2707. }
  2708. return tokenizer.currentIdentifier;
  2709. };
  2710. /**
  2711. * All shaders loaded. Create materials one by one
  2712. */
  2713. var importMaterials = function (gltfRuntime) {
  2714. // Create materials
  2715. for (var mat in gltfRuntime.materials) {
  2716. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2717. }
  2718. };
  2719. /**
  2720. * Implementation of the base glTF spec
  2721. * @hidden
  2722. */
  2723. var GLTFLoaderBase = /** @class */ (function () {
  2724. function GLTFLoaderBase() {
  2725. }
  2726. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2727. var gltfRuntime = {
  2728. extensions: {},
  2729. accessors: {},
  2730. buffers: {},
  2731. bufferViews: {},
  2732. meshes: {},
  2733. lights: {},
  2734. cameras: {},
  2735. nodes: {},
  2736. images: {},
  2737. textures: {},
  2738. shaders: {},
  2739. programs: {},
  2740. samplers: {},
  2741. techniques: {},
  2742. materials: {},
  2743. animations: {},
  2744. skins: {},
  2745. extensionsUsed: [],
  2746. scenes: {},
  2747. buffersCount: 0,
  2748. shaderscount: 0,
  2749. scene: scene,
  2750. rootUrl: rootUrl,
  2751. loadedBufferCount: 0,
  2752. loadedBufferViews: {},
  2753. loadedShaderCount: 0,
  2754. importOnlyMeshes: false,
  2755. dummyNodes: [],
  2756. forAssetContainer: false
  2757. };
  2758. // Parse
  2759. if (parsedData.extensions) {
  2760. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2761. }
  2762. if (parsedData.extensionsUsed) {
  2763. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2764. }
  2765. if (parsedData.buffers) {
  2766. parseBuffers(parsedData.buffers, gltfRuntime);
  2767. }
  2768. if (parsedData.bufferViews) {
  2769. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2770. }
  2771. if (parsedData.accessors) {
  2772. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2773. }
  2774. if (parsedData.meshes) {
  2775. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2776. }
  2777. if (parsedData.lights) {
  2778. parseObject(parsedData.lights, "lights", gltfRuntime);
  2779. }
  2780. if (parsedData.cameras) {
  2781. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2782. }
  2783. if (parsedData.nodes) {
  2784. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2785. }
  2786. if (parsedData.images) {
  2787. parseObject(parsedData.images, "images", gltfRuntime);
  2788. }
  2789. if (parsedData.textures) {
  2790. parseObject(parsedData.textures, "textures", gltfRuntime);
  2791. }
  2792. if (parsedData.shaders) {
  2793. parseShaders(parsedData.shaders, gltfRuntime);
  2794. }
  2795. if (parsedData.programs) {
  2796. parseObject(parsedData.programs, "programs", gltfRuntime);
  2797. }
  2798. if (parsedData.samplers) {
  2799. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2800. }
  2801. if (parsedData.techniques) {
  2802. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2803. }
  2804. if (parsedData.materials) {
  2805. parseObject(parsedData.materials, "materials", gltfRuntime);
  2806. }
  2807. if (parsedData.animations) {
  2808. parseObject(parsedData.animations, "animations", gltfRuntime);
  2809. }
  2810. if (parsedData.skins) {
  2811. parseObject(parsedData.skins, "skins", gltfRuntime);
  2812. }
  2813. if (parsedData.scenes) {
  2814. gltfRuntime.scenes = parsedData.scenes;
  2815. }
  2816. if (parsedData.scene && parsedData.scenes) {
  2817. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2818. }
  2819. return gltfRuntime;
  2820. };
  2821. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2822. var buffer = gltfRuntime.buffers[id];
  2823. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2824. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2825. }
  2826. else {
  2827. 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) {
  2828. if (request) {
  2829. onError(request.status + " " + request.statusText);
  2830. }
  2831. });
  2832. }
  2833. };
  2834. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2835. var texture = gltfRuntime.textures[id];
  2836. if (!texture || !texture.source) {
  2837. onError("");
  2838. return;
  2839. }
  2840. if (texture.babylonTexture) {
  2841. onSuccess(null);
  2842. return;
  2843. }
  2844. var source = gltfRuntime.images[texture.source];
  2845. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2846. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2847. }
  2848. else {
  2849. 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) {
  2850. if (request) {
  2851. onError(request.status + " " + request.statusText);
  2852. }
  2853. });
  2854. }
  2855. };
  2856. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2857. var texture = gltfRuntime.textures[id];
  2858. if (texture.babylonTexture) {
  2859. onSuccess(texture.babylonTexture);
  2860. return;
  2861. }
  2862. var sampler = gltfRuntime.samplers[texture.sampler];
  2863. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2864. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2865. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2866. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2867. var samplingMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2868. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2869. var blobURL = URL.createObjectURL(blob);
  2870. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2871. var newTexture = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2872. if (sampler.wrapS !== undefined) {
  2873. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2874. }
  2875. if (sampler.wrapT !== undefined) {
  2876. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2877. }
  2878. newTexture.name = id;
  2879. texture.babylonTexture = newTexture;
  2880. onSuccess(newTexture);
  2881. };
  2882. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2883. var shader = gltfRuntime.shaders[id];
  2884. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2885. var shaderString = atob(shader.uri.split(",")[1]);
  2886. if (onSuccess) {
  2887. onSuccess(shaderString);
  2888. }
  2889. }
  2890. else {
  2891. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2892. if (request && onError) {
  2893. onError(request.status + " " + request.statusText);
  2894. }
  2895. });
  2896. }
  2897. };
  2898. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2899. var material = gltfRuntime.materials[id];
  2900. if (!material.technique) {
  2901. if (onError) {
  2902. onError("No technique found.");
  2903. }
  2904. return;
  2905. }
  2906. var technique = gltfRuntime.techniques[material.technique];
  2907. if (!technique) {
  2908. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2909. var defaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2910. gltfRuntime.scene._blockEntityCollection = false;
  2911. defaultMaterial.diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2912. defaultMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2913. onSuccess(defaultMaterial);
  2914. return;
  2915. }
  2916. var program = gltfRuntime.programs[technique.program];
  2917. var states = technique.states;
  2918. var vertexShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2919. var pixelShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2920. var newVertexShader = "";
  2921. var newPixelShader = "";
  2922. var vertexTokenizer = new Tokenizer(vertexShader);
  2923. var pixelTokenizer = new Tokenizer(pixelShader);
  2924. var unTreatedUniforms = {};
  2925. var uniforms = [];
  2926. var attributes = [];
  2927. var samplers = [];
  2928. // Fill uniform, sampler2D and attributes
  2929. for (var unif in technique.uniforms) {
  2930. var uniform = technique.uniforms[unif];
  2931. var uniformParameter = technique.parameters[uniform];
  2932. unTreatedUniforms[unif] = uniformParameter;
  2933. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2934. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2935. if (transformIndex !== -1) {
  2936. uniforms.push(babylonTransforms[transformIndex]);
  2937. delete unTreatedUniforms[unif];
  2938. }
  2939. else {
  2940. uniforms.push(unif);
  2941. }
  2942. }
  2943. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2944. samplers.push(unif);
  2945. }
  2946. else {
  2947. uniforms.push(unif);
  2948. }
  2949. }
  2950. for (var attr in technique.attributes) {
  2951. var attribute = technique.attributes[attr];
  2952. var attributeParameter = technique.parameters[attribute];
  2953. if (attributeParameter.semantic) {
  2954. var name_1 = getAttribute(attributeParameter);
  2955. if (name_1) {
  2956. attributes.push(name_1);
  2957. }
  2958. }
  2959. }
  2960. // Configure vertex shader
  2961. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2962. var tokenType = vertexTokenizer.currentToken;
  2963. if (tokenType !== ETokenType.IDENTIFIER) {
  2964. newVertexShader += vertexTokenizer.currentString;
  2965. continue;
  2966. }
  2967. var foundAttribute = false;
  2968. for (var attr in technique.attributes) {
  2969. var attribute = technique.attributes[attr];
  2970. var attributeParameter = technique.parameters[attribute];
  2971. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  2972. newVertexShader += getAttribute(attributeParameter);
  2973. foundAttribute = true;
  2974. break;
  2975. }
  2976. }
  2977. if (foundAttribute) {
  2978. continue;
  2979. }
  2980. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  2981. }
  2982. // Configure pixel shader
  2983. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  2984. var tokenType = pixelTokenizer.currentToken;
  2985. if (tokenType !== ETokenType.IDENTIFIER) {
  2986. newPixelShader += pixelTokenizer.currentString;
  2987. continue;
  2988. }
  2989. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  2990. }
  2991. // Create shader material
  2992. var shaderPath = {
  2993. vertex: program.vertexShader + id,
  2994. fragment: program.fragmentShader + id
  2995. };
  2996. var options = {
  2997. attributes: attributes,
  2998. uniforms: uniforms,
  2999. samplers: samplers,
  3000. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  3001. };
  3002. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  3003. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  3004. var shaderMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  3005. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  3006. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  3007. shaderMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  3008. if (states && states.functions) {
  3009. var functions = states.functions;
  3010. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  3011. shaderMaterial.backFaceCulling = false;
  3012. }
  3013. var blendFunc = functions.blendFuncSeparate;
  3014. if (blendFunc) {
  3015. 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) {
  3016. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  3017. }
  3018. 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) {
  3019. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  3020. }
  3021. 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) {
  3022. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  3023. }
  3024. 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) {
  3025. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  3026. }
  3027. 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) {
  3028. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  3029. }
  3030. 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) {
  3031. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  3032. }
  3033. }
  3034. }
  3035. };
  3036. return GLTFLoaderBase;
  3037. }());
  3038. /**
  3039. * glTF V1 Loader
  3040. * @hidden
  3041. */
  3042. var GLTFLoader = /** @class */ (function () {
  3043. function GLTFLoader() {
  3044. this.state = null;
  3045. }
  3046. GLTFLoader.RegisterExtension = function (extension) {
  3047. if (GLTFLoader.Extensions[extension.name]) {
  3048. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  3049. return;
  3050. }
  3051. GLTFLoader.Extensions[extension.name] = extension;
  3052. };
  3053. GLTFLoader.prototype.dispose = function () {
  3054. // do nothing
  3055. };
  3056. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3057. var _this = this;
  3058. scene.useRightHandedSystem = true;
  3059. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3060. gltfRuntime.forAssetContainer = forAssetContainer;
  3061. gltfRuntime.importOnlyMeshes = true;
  3062. if (meshesNames === "") {
  3063. gltfRuntime.importMeshesNames = [];
  3064. }
  3065. else if (typeof meshesNames === "string") {
  3066. gltfRuntime.importMeshesNames = [meshesNames];
  3067. }
  3068. else if (meshesNames && !(meshesNames instanceof Array)) {
  3069. gltfRuntime.importMeshesNames = [meshesNames];
  3070. }
  3071. else {
  3072. gltfRuntime.importMeshesNames = [];
  3073. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3074. }
  3075. // Create nodes
  3076. _this._createNodes(gltfRuntime);
  3077. var meshes = new Array();
  3078. var skeletons = new Array();
  3079. // Fill arrays of meshes and skeletons
  3080. for (var nde in gltfRuntime.nodes) {
  3081. var node = gltfRuntime.nodes[nde];
  3082. if (node.babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3083. meshes.push(node.babylonNode);
  3084. }
  3085. }
  3086. for (var skl in gltfRuntime.skins) {
  3087. var skin = gltfRuntime.skins[skl];
  3088. if (skin.babylonSkeleton instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3089. skeletons.push(skin.babylonSkeleton);
  3090. }
  3091. }
  3092. // Load buffers, shaders, materials, etc.
  3093. _this._loadBuffersAsync(gltfRuntime, function () {
  3094. _this._loadShadersAsync(gltfRuntime, function () {
  3095. importMaterials(gltfRuntime);
  3096. postLoad(gltfRuntime);
  3097. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3098. onSuccess(meshes, skeletons);
  3099. }
  3100. });
  3101. }, onProgress);
  3102. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3103. onSuccess(meshes, skeletons);
  3104. }
  3105. }, onError);
  3106. return true;
  3107. };
  3108. /**
  3109. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3110. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3111. * @param scene the scene the meshes should be added to
  3112. * @param forAssetContainer defines if the entities must be stored in the scene
  3113. * @param data gltf data containing information of the meshes in a loaded file
  3114. * @param rootUrl root url to load from
  3115. * @param onProgress event that fires when loading progress has occured
  3116. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3117. */
  3118. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress) {
  3119. var _this = this;
  3120. return new Promise(function (resolve, reject) {
  3121. _this._importMeshAsync(meshesNames, scene, data, rootUrl, forAssetContainer, function (meshes, skeletons) {
  3122. resolve({
  3123. meshes: meshes,
  3124. particleSystems: [],
  3125. skeletons: skeletons,
  3126. animationGroups: [],
  3127. lights: [],
  3128. transformNodes: []
  3129. });
  3130. }, onProgress, function (message) {
  3131. reject(new Error(message));
  3132. });
  3133. });
  3134. };
  3135. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3136. var _this = this;
  3137. scene.useRightHandedSystem = true;
  3138. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3139. // Load runtime extensios
  3140. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3141. // Create nodes
  3142. _this._createNodes(gltfRuntime);
  3143. // Load buffers, shaders, materials, etc.
  3144. _this._loadBuffersAsync(gltfRuntime, function () {
  3145. _this._loadShadersAsync(gltfRuntime, function () {
  3146. importMaterials(gltfRuntime);
  3147. postLoad(gltfRuntime);
  3148. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3149. onSuccess();
  3150. }
  3151. });
  3152. });
  3153. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3154. onSuccess();
  3155. }
  3156. }, onError);
  3157. }, onError);
  3158. };
  3159. /**
  3160. * Imports all objects from a loaded gltf file and adds them to the scene
  3161. * @param scene the scene the objects should be added to
  3162. * @param data gltf data containing information of the meshes in a loaded file
  3163. * @param rootUrl root url to load from
  3164. * @param onProgress event that fires when loading progress has occured
  3165. * @returns a promise which completes when objects have been loaded to the scene
  3166. */
  3167. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3168. var _this = this;
  3169. return new Promise(function (resolve, reject) {
  3170. _this._loadAsync(scene, data, rootUrl, false, function () {
  3171. resolve();
  3172. }, onProgress, function (message) {
  3173. reject(new Error(message));
  3174. });
  3175. });
  3176. };
  3177. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3178. var hasShaders = false;
  3179. var processShader = function (sha, shader) {
  3180. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3181. if (shaderString instanceof ArrayBuffer) {
  3182. return;
  3183. }
  3184. gltfRuntime.loadedShaderCount++;
  3185. if (shaderString) {
  3186. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3187. }
  3188. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3189. onload();
  3190. }
  3191. }, function () {
  3192. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3193. });
  3194. };
  3195. for (var sha in gltfRuntime.shaders) {
  3196. hasShaders = true;
  3197. var shader = gltfRuntime.shaders[sha];
  3198. if (shader) {
  3199. processShader.bind(this, sha, shader)();
  3200. }
  3201. else {
  3202. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3203. }
  3204. }
  3205. if (!hasShaders) {
  3206. onload();
  3207. }
  3208. };
  3209. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3210. var hasBuffers = false;
  3211. var processBuffer = function (buf, buffer) {
  3212. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3213. gltfRuntime.loadedBufferCount++;
  3214. if (bufferView) {
  3215. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3216. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3217. }
  3218. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3219. }
  3220. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3221. onLoad();
  3222. }
  3223. }, function () {
  3224. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3225. });
  3226. };
  3227. for (var buf in gltfRuntime.buffers) {
  3228. hasBuffers = true;
  3229. var buffer = gltfRuntime.buffers[buf];
  3230. if (buffer) {
  3231. processBuffer.bind(this, buf, buffer)();
  3232. }
  3233. else {
  3234. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3235. }
  3236. }
  3237. if (!hasBuffers) {
  3238. onLoad();
  3239. }
  3240. };
  3241. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3242. var currentScene = gltfRuntime.currentScene;
  3243. if (currentScene) {
  3244. // Only one scene even if multiple scenes are defined
  3245. for (var i = 0; i < currentScene.nodes.length; i++) {
  3246. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3247. }
  3248. }
  3249. else {
  3250. // Load all scenes
  3251. for (var thing in gltfRuntime.scenes) {
  3252. currentScene = gltfRuntime.scenes[thing];
  3253. for (var i = 0; i < currentScene.nodes.length; i++) {
  3254. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3255. }
  3256. }
  3257. }
  3258. };
  3259. GLTFLoader.Extensions = {};
  3260. return GLTFLoader;
  3261. }());
  3262. /** @hidden */
  3263. var GLTFLoaderExtension = /** @class */ (function () {
  3264. function GLTFLoaderExtension(name) {
  3265. this._name = name;
  3266. }
  3267. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3268. get: function () {
  3269. return this._name;
  3270. },
  3271. enumerable: true,
  3272. configurable: true
  3273. });
  3274. /**
  3275. * Defines an override for loading the runtime
  3276. * Return true to stop further extensions from loading the runtime
  3277. */
  3278. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3279. return false;
  3280. };
  3281. /**
  3282. * Defines an onverride for creating gltf runtime
  3283. * Return true to stop further extensions from creating the runtime
  3284. */
  3285. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3286. return false;
  3287. };
  3288. /**
  3289. * Defines an override for loading buffers
  3290. * Return true to stop further extensions from loading this buffer
  3291. */
  3292. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3293. return false;
  3294. };
  3295. /**
  3296. * Defines an override for loading texture buffers
  3297. * Return true to stop further extensions from loading this texture data
  3298. */
  3299. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3300. return false;
  3301. };
  3302. /**
  3303. * Defines an override for creating textures
  3304. * Return true to stop further extensions from loading this texture
  3305. */
  3306. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3307. return false;
  3308. };
  3309. /**
  3310. * Defines an override for loading shader strings
  3311. * Return true to stop further extensions from loading this shader data
  3312. */
  3313. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3314. return false;
  3315. };
  3316. /**
  3317. * Defines an override for loading materials
  3318. * Return true to stop further extensions from loading this material
  3319. */
  3320. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3321. return false;
  3322. };
  3323. // ---------
  3324. // Utilities
  3325. // ---------
  3326. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3327. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3328. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3329. }, function () {
  3330. setTimeout(function () {
  3331. if (!onSuccess) {
  3332. return;
  3333. }
  3334. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3335. });
  3336. });
  3337. };
  3338. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3339. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3340. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3341. }, function () {
  3342. setTimeout(function () {
  3343. onSuccess();
  3344. });
  3345. });
  3346. };
  3347. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3348. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3349. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3350. }, function () {
  3351. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3352. });
  3353. };
  3354. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3355. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3356. if (buffer) {
  3357. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3358. }
  3359. }, onError);
  3360. };
  3361. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3362. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3363. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3364. }, function () {
  3365. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3366. });
  3367. };
  3368. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3369. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3370. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3371. }, function () {
  3372. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3373. });
  3374. };
  3375. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3376. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3377. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3378. }, function () {
  3379. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3380. });
  3381. };
  3382. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3383. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3384. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3385. }, function () {
  3386. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3387. });
  3388. };
  3389. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3390. for (var extensionName in GLTFLoader.Extensions) {
  3391. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3392. if (func(loaderExtension)) {
  3393. return;
  3394. }
  3395. }
  3396. defaultFunc();
  3397. };
  3398. return GLTFLoaderExtension;
  3399. }());
  3400. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3401. /***/ }),
  3402. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3403. /*!******************************************!*\
  3404. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3405. \******************************************/
  3406. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  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__, "EComponentType", function() { return EComponentType; });
  3411. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3412. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3413. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3414. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3415. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3416. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3417. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3418. /**
  3419. * Enums
  3420. * @hidden
  3421. */
  3422. var EComponentType;
  3423. (function (EComponentType) {
  3424. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3425. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3426. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3427. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3428. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3429. })(EComponentType || (EComponentType = {}));
  3430. /** @hidden */
  3431. var EShaderType;
  3432. (function (EShaderType) {
  3433. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3434. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3435. })(EShaderType || (EShaderType = {}));
  3436. /** @hidden */
  3437. var EParameterType;
  3438. (function (EParameterType) {
  3439. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3440. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3441. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3442. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3443. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3444. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3445. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3446. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3447. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3448. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3449. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3450. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3451. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3452. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3453. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3454. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3455. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3456. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3457. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3458. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3459. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3460. })(EParameterType || (EParameterType = {}));
  3461. /** @hidden */
  3462. var ETextureWrapMode;
  3463. (function (ETextureWrapMode) {
  3464. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3465. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3466. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3467. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3468. /** @hidden */
  3469. var ETextureFilterType;
  3470. (function (ETextureFilterType) {
  3471. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3472. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3473. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3474. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3475. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3476. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3477. })(ETextureFilterType || (ETextureFilterType = {}));
  3478. /** @hidden */
  3479. var ETextureFormat;
  3480. (function (ETextureFormat) {
  3481. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3482. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3483. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3484. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3485. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3486. })(ETextureFormat || (ETextureFormat = {}));
  3487. /** @hidden */
  3488. var ECullingType;
  3489. (function (ECullingType) {
  3490. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3491. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3492. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3493. })(ECullingType || (ECullingType = {}));
  3494. /** @hidden */
  3495. var EBlendingFunction;
  3496. (function (EBlendingFunction) {
  3497. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3498. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3499. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3500. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3501. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3502. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3503. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3504. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3505. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3506. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3507. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3508. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3509. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3510. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3511. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3512. })(EBlendingFunction || (EBlendingFunction = {}));
  3513. /***/ }),
  3514. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3515. /*!*************************************!*\
  3516. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3517. \*************************************/
  3518. /*! exports provided: GLTFUtils */
  3519. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3520. "use strict";
  3521. __webpack_require__.r(__webpack_exports__);
  3522. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3523. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3524. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3525. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  3526. /**
  3527. * Utils functions for GLTF
  3528. * @hidden
  3529. */
  3530. var GLTFUtils = /** @class */ (function () {
  3531. function GLTFUtils() {
  3532. }
  3533. /**
  3534. * Sets the given "parameter" matrix
  3535. * @param scene: the Scene object
  3536. * @param source: the source node where to pick the matrix
  3537. * @param parameter: the GLTF technique parameter
  3538. * @param uniformName: the name of the shader's uniform
  3539. * @param shaderMaterial: the shader material
  3540. */
  3541. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3542. var mat = null;
  3543. if (parameter.semantic === "MODEL") {
  3544. mat = source.getWorldMatrix();
  3545. }
  3546. else if (parameter.semantic === "PROJECTION") {
  3547. mat = scene.getProjectionMatrix();
  3548. }
  3549. else if (parameter.semantic === "VIEW") {
  3550. mat = scene.getViewMatrix();
  3551. }
  3552. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3553. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3554. }
  3555. else if (parameter.semantic === "MODELVIEW") {
  3556. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3557. }
  3558. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3559. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3560. }
  3561. else if (parameter.semantic === "MODELINVERSE") {
  3562. mat = source.getWorldMatrix().invert();
  3563. }
  3564. else if (parameter.semantic === "VIEWINVERSE") {
  3565. mat = scene.getViewMatrix().invert();
  3566. }
  3567. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3568. mat = scene.getProjectionMatrix().invert();
  3569. }
  3570. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3571. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3572. }
  3573. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3574. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3575. }
  3576. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3577. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3578. }
  3579. else {
  3580. debugger;
  3581. }
  3582. if (mat) {
  3583. switch (parameter.type) {
  3584. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3585. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3586. break;
  3587. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3588. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3589. break;
  3590. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3591. shaderMaterial.setMatrix(uniformName, mat);
  3592. break;
  3593. default: break;
  3594. }
  3595. }
  3596. };
  3597. /**
  3598. * Sets the given "parameter" matrix
  3599. * @param shaderMaterial: the shader material
  3600. * @param uniform: the name of the shader's uniform
  3601. * @param value: the value of the uniform
  3602. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3603. */
  3604. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3605. switch (type) {
  3606. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3607. shaderMaterial.setFloat(uniform, value);
  3608. return true;
  3609. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3610. shaderMaterial.setVector2(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3611. return true;
  3612. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3613. shaderMaterial.setVector3(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3614. return true;
  3615. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3616. shaderMaterial.setVector4(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3617. return true;
  3618. default: return false;
  3619. }
  3620. };
  3621. /**
  3622. * Returns the wrap mode of the texture
  3623. * @param mode: the mode value
  3624. */
  3625. GLTFUtils.GetWrapMode = function (mode) {
  3626. switch (mode) {
  3627. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3628. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3629. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3630. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3631. }
  3632. };
  3633. /**
  3634. * Returns the byte stride giving an accessor
  3635. * @param accessor: the GLTF accessor objet
  3636. */
  3637. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3638. // Needs this function since "byteStride" isn't requiered in glTF format
  3639. var type = accessor.type;
  3640. switch (type) {
  3641. case "VEC2": return 2;
  3642. case "VEC3": return 3;
  3643. case "VEC4": return 4;
  3644. case "MAT2": return 4;
  3645. case "MAT3": return 9;
  3646. case "MAT4": return 16;
  3647. default: return 1;
  3648. }
  3649. };
  3650. /**
  3651. * Returns the texture filter mode giving a mode value
  3652. * @param mode: the filter mode value
  3653. */
  3654. GLTFUtils.GetTextureFilterMode = function (mode) {
  3655. switch (mode) {
  3656. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3657. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3658. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3659. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3660. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3661. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3662. }
  3663. };
  3664. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3665. var byteOffset = bufferView.byteOffset + byteOffset;
  3666. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3667. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3668. throw new Error("Buffer access is out of range");
  3669. }
  3670. var buffer = loadedBufferView.buffer;
  3671. byteOffset += loadedBufferView.byteOffset;
  3672. switch (componentType) {
  3673. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3674. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3675. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3676. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3677. default: return new Float32Array(buffer, byteOffset, byteLength);
  3678. }
  3679. };
  3680. /**
  3681. * Returns a buffer from its accessor
  3682. * @param gltfRuntime: the GLTF runtime
  3683. * @param accessor: the GLTF accessor
  3684. */
  3685. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3686. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3687. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3688. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3689. };
  3690. /**
  3691. * Decodes a buffer view into a string
  3692. * @param view: the buffer view
  3693. */
  3694. GLTFUtils.DecodeBufferToText = function (view) {
  3695. var result = "";
  3696. var length = view.byteLength;
  3697. for (var i = 0; i < length; ++i) {
  3698. result += String.fromCharCode(view[i]);
  3699. }
  3700. return result;
  3701. };
  3702. /**
  3703. * Returns the default material of gltf. Related to
  3704. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3705. * @param scene: the Babylon.js scene
  3706. */
  3707. GLTFUtils.GetDefaultMaterial = function (scene) {
  3708. if (!GLTFUtils._DefaultMaterial) {
  3709. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3710. "precision highp float;",
  3711. "",
  3712. "uniform mat4 worldView;",
  3713. "uniform mat4 projection;",
  3714. "",
  3715. "attribute vec3 position;",
  3716. "",
  3717. "void main(void)",
  3718. "{",
  3719. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3720. "}"
  3721. ].join("\n");
  3722. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3723. "precision highp float;",
  3724. "",
  3725. "uniform vec4 u_emission;",
  3726. "",
  3727. "void main(void)",
  3728. "{",
  3729. " gl_FragColor = u_emission;",
  3730. "}"
  3731. ].join("\n");
  3732. var shaderPath = {
  3733. vertex: "GLTFDefaultMaterial",
  3734. fragment: "GLTFDefaultMaterial"
  3735. };
  3736. var options = {
  3737. attributes: ["position"],
  3738. uniforms: ["worldView", "projection", "u_emission"],
  3739. samplers: new Array(),
  3740. needAlphaBlending: false
  3741. };
  3742. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3743. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3744. }
  3745. return GLTFUtils._DefaultMaterial;
  3746. };
  3747. // The GLTF default material
  3748. GLTFUtils._DefaultMaterial = null;
  3749. return GLTFUtils;
  3750. }());
  3751. /***/ }),
  3752. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3753. /*!**************************************************!*\
  3754. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3755. \**************************************************/
  3756. /*! exports provided: GLTFMaterialsCommonExtension */
  3757. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3758. "use strict";
  3759. __webpack_require__.r(__webpack_exports__);
  3760. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3761. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3762. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3763. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3764. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__);
  3765. /** @hidden */
  3766. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3767. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3768. function GLTFMaterialsCommonExtension() {
  3769. return _super.call(this, "KHR_materials_common") || this;
  3770. }
  3771. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3772. if (!gltfRuntime.extensions) {
  3773. return false;
  3774. }
  3775. var extension = gltfRuntime.extensions[this.name];
  3776. if (!extension) {
  3777. return false;
  3778. }
  3779. // Create lights
  3780. var lights = extension.lights;
  3781. if (lights) {
  3782. for (var thing in lights) {
  3783. var light = lights[thing];
  3784. switch (light.type) {
  3785. case "ambient":
  3786. 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);
  3787. var ambient = light.ambient;
  3788. if (ambient) {
  3789. ambientLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3790. }
  3791. break;
  3792. case "point":
  3793. 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);
  3794. var point = light.point;
  3795. if (point) {
  3796. pointLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3797. }
  3798. break;
  3799. case "directional":
  3800. 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);
  3801. var directional = light.directional;
  3802. if (directional) {
  3803. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3804. }
  3805. break;
  3806. case "spot":
  3807. var spot = light.spot;
  3808. if (spot) {
  3809. 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);
  3810. spotLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3811. }
  3812. break;
  3813. default:
  3814. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3815. break;
  3816. }
  3817. }
  3818. }
  3819. return false;
  3820. };
  3821. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3822. var material = gltfRuntime.materials[id];
  3823. if (!material || !material.extensions) {
  3824. return false;
  3825. }
  3826. var extension = material.extensions[this.name];
  3827. if (!extension) {
  3828. return false;
  3829. }
  3830. var standardMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3831. standardMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3832. if (extension.technique === "CONSTANT") {
  3833. standardMaterial.disableLighting = true;
  3834. }
  3835. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3836. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3837. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3838. // Ambient
  3839. if (typeof extension.values.ambient === "string") {
  3840. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3841. }
  3842. else {
  3843. standardMaterial.ambientColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3844. }
  3845. // Diffuse
  3846. if (typeof extension.values.diffuse === "string") {
  3847. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3848. }
  3849. else {
  3850. standardMaterial.diffuseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3851. }
  3852. // Emission
  3853. if (typeof extension.values.emission === "string") {
  3854. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3855. }
  3856. else {
  3857. standardMaterial.emissiveColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3858. }
  3859. // Specular
  3860. if (typeof extension.values.specular === "string") {
  3861. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3862. }
  3863. else {
  3864. standardMaterial.specularColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3865. }
  3866. return true;
  3867. };
  3868. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3869. // Create buffer from texture url
  3870. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3871. // Create texture from buffer
  3872. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3873. }, onError);
  3874. };
  3875. return GLTFMaterialsCommonExtension;
  3876. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3877. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3878. /***/ }),
  3879. /***/ "./glTF/1.0/index.ts":
  3880. /*!***************************!*\
  3881. !*** ./glTF/1.0/index.ts ***!
  3882. \***************************/
  3883. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3884. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3885. "use strict";
  3886. __webpack_require__.r(__webpack_exports__);
  3887. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3888. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3889. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3890. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3891. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3892. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3893. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3894. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3895. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3896. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3897. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3898. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3899. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3900. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3901. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3902. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3903. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3904. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3905. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3906. /***/ }),
  3907. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3908. /*!*******************************************************!*\
  3909. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3910. \*******************************************************/
  3911. /*! exports provided: EXT_lights_image_based */
  3912. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3913. "use strict";
  3914. __webpack_require__.r(__webpack_exports__);
  3915. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3916. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  3917. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3918. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3919. var NAME = "EXT_lights_image_based";
  3920. /**
  3921. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3922. */
  3923. var EXT_lights_image_based = /** @class */ (function () {
  3924. /** @hidden */
  3925. function EXT_lights_image_based(loader) {
  3926. /**
  3927. * The name of this extension.
  3928. */
  3929. this.name = NAME;
  3930. this._loader = loader;
  3931. this.enabled = this._loader.isExtensionUsed(NAME);
  3932. }
  3933. /** @hidden */
  3934. EXT_lights_image_based.prototype.dispose = function () {
  3935. delete this._loader;
  3936. delete this._lights;
  3937. };
  3938. /** @hidden */
  3939. EXT_lights_image_based.prototype.onLoading = function () {
  3940. var extensions = this._loader.gltf.extensions;
  3941. if (extensions && extensions[this.name]) {
  3942. var extension = extensions[this.name];
  3943. this._lights = extension.lights;
  3944. }
  3945. };
  3946. /** @hidden */
  3947. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3948. var _this = this;
  3949. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3950. var promises = new Array();
  3951. promises.push(_this._loader.loadSceneAsync(context, scene));
  3952. _this._loader.logOpen("" + extensionContext);
  3953. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3954. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3955. _this._loader.babylonScene.environmentTexture = texture;
  3956. }));
  3957. _this._loader.logClose();
  3958. return Promise.all(promises).then(function () { });
  3959. });
  3960. };
  3961. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3962. var _this = this;
  3963. if (!light._loaded) {
  3964. var promises = new Array();
  3965. this._loader.logOpen("" + context);
  3966. var imageData_1 = new Array(light.specularImages.length);
  3967. var _loop_1 = function (mipmap) {
  3968. var faces = light.specularImages[mipmap];
  3969. imageData_1[mipmap] = new Array(faces.length);
  3970. var _loop_2 = function (face) {
  3971. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  3972. this_1._loader.logOpen("" + specularImageContext);
  3973. var index = faces[face];
  3974. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  3975. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  3976. imageData_1[mipmap][face] = data;
  3977. }));
  3978. this_1._loader.logClose();
  3979. };
  3980. for (var face = 0; face < faces.length; face++) {
  3981. _loop_2(face);
  3982. }
  3983. };
  3984. var this_1 = this;
  3985. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  3986. _loop_1(mipmap);
  3987. }
  3988. this._loader.logClose();
  3989. light._loaded = Promise.all(promises).then(function () {
  3990. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  3991. babylonTexture.name = light.name || "environment";
  3992. light._babylonTexture = babylonTexture;
  3993. if (light.intensity != undefined) {
  3994. babylonTexture.level = light.intensity;
  3995. }
  3996. if (light.rotation) {
  3997. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  3998. // Invert the rotation so that positive rotation is counter-clockwise.
  3999. if (!_this._loader.babylonScene.useRightHandedSystem) {
  4000. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  4001. }
  4002. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  4003. }
  4004. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  4005. sphericalHarmonics.scaleInPlace(light.intensity);
  4006. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  4007. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  4008. // Compute the lod generation scale to fit exactly to the number of levels available.
  4009. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  4010. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  4011. });
  4012. }
  4013. return light._loaded.then(function () {
  4014. return light._babylonTexture;
  4015. });
  4016. };
  4017. return EXT_lights_image_based;
  4018. }());
  4019. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  4020. /***/ }),
  4021. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  4022. /*!********************************************************!*\
  4023. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  4024. \********************************************************/
  4025. /*! exports provided: EXT_mesh_gpu_instancing */
  4026. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4027. "use strict";
  4028. __webpack_require__.r(__webpack_exports__);
  4029. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  4030. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4031. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4032. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4033. var NAME = "EXT_mesh_gpu_instancing";
  4034. /**
  4035. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  4036. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  4037. * !!! Experimental Extension Subject to Changes !!!
  4038. */
  4039. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  4040. /** @hidden */
  4041. function EXT_mesh_gpu_instancing(loader) {
  4042. /**
  4043. * The name of this extension.
  4044. */
  4045. this.name = NAME;
  4046. this._loader = loader;
  4047. this.enabled = this._loader.isExtensionUsed(NAME);
  4048. }
  4049. /** @hidden */
  4050. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  4051. delete this._loader;
  4052. };
  4053. /** @hidden */
  4054. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  4055. var _this = this;
  4056. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4057. _this._loader._disableInstancedMesh++;
  4058. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  4059. _this._loader._disableInstancedMesh--;
  4060. if (!node._primitiveBabylonMeshes) {
  4061. return promise;
  4062. }
  4063. var promises = new Array();
  4064. var instanceCount = 0;
  4065. var loadAttribute = function (attribute) {
  4066. if (extension.attributes[attribute] == undefined) {
  4067. promises.push(Promise.resolve(null));
  4068. return;
  4069. }
  4070. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  4071. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  4072. if (instanceCount === 0) {
  4073. instanceCount = accessor.count;
  4074. }
  4075. else if (instanceCount !== accessor.count) {
  4076. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  4077. }
  4078. };
  4079. loadAttribute("TRANSLATION");
  4080. loadAttribute("ROTATION");
  4081. loadAttribute("SCALE");
  4082. return promise.then(function (babylonTransformNode) {
  4083. return Promise.all(promises).then(function (_a) {
  4084. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  4085. var matrices = new Float32Array(instanceCount * 16);
  4086. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  4087. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  4088. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  4089. for (var i = 0; i < instanceCount; ++i) {
  4090. 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]);
  4091. 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]);
  4092. 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]);
  4093. 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]);
  4094. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  4095. }
  4096. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  4097. var babylonMesh = _b[_i];
  4098. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  4099. }
  4100. return babylonTransformNode;
  4101. });
  4102. });
  4103. });
  4104. };
  4105. return EXT_mesh_gpu_instancing;
  4106. }());
  4107. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  4108. /***/ }),
  4109. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  4110. /*!*************************************************!*\
  4111. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  4112. \*************************************************/
  4113. /*! exports provided: ExtrasAsMetadata */
  4114. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4115. "use strict";
  4116. __webpack_require__.r(__webpack_exports__);
  4117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  4118. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4119. var NAME = "ExtrasAsMetadata";
  4120. /**
  4121. * Store glTF extras (if present) in BJS objects' metadata
  4122. */
  4123. var ExtrasAsMetadata = /** @class */ (function () {
  4124. /** @hidden */
  4125. function ExtrasAsMetadata(loader) {
  4126. /**
  4127. * The name of this extension.
  4128. */
  4129. this.name = NAME;
  4130. /**
  4131. * Defines whether this extension is enabled.
  4132. */
  4133. this.enabled = true;
  4134. this._loader = loader;
  4135. }
  4136. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  4137. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  4138. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  4139. var gltf = (metadata.gltf = metadata.gltf || {});
  4140. gltf.extras = gltfProp.extras;
  4141. }
  4142. };
  4143. /** @hidden */
  4144. ExtrasAsMetadata.prototype.dispose = function () {
  4145. delete this._loader;
  4146. };
  4147. /** @hidden */
  4148. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4149. var _this = this;
  4150. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4151. _this._assignExtras(babylonTransformNode, node);
  4152. assign(babylonTransformNode);
  4153. });
  4154. };
  4155. /** @hidden */
  4156. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4157. var _this = this;
  4158. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4159. _this._assignExtras(babylonCamera, camera);
  4160. assign(babylonCamera);
  4161. });
  4162. };
  4163. /** @hidden */
  4164. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4165. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4166. this._assignExtras(babylonMaterial, material);
  4167. return babylonMaterial;
  4168. };
  4169. return ExtrasAsMetadata;
  4170. }());
  4171. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4172. /***/ }),
  4173. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4174. /*!***********************************************************!*\
  4175. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4176. \***********************************************************/
  4177. /*! exports provided: KHR_draco_mesh_compression */
  4178. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4179. "use strict";
  4180. __webpack_require__.r(__webpack_exports__);
  4181. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4182. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  4183. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4184. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4185. var NAME = "KHR_draco_mesh_compression";
  4186. /**
  4187. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4188. */
  4189. var KHR_draco_mesh_compression = /** @class */ (function () {
  4190. /** @hidden */
  4191. function KHR_draco_mesh_compression(loader) {
  4192. /**
  4193. * The name of this extension.
  4194. */
  4195. this.name = NAME;
  4196. this._loader = loader;
  4197. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4198. }
  4199. /** @hidden */
  4200. KHR_draco_mesh_compression.prototype.dispose = function () {
  4201. delete this.dracoCompression;
  4202. delete this._loader;
  4203. };
  4204. /** @hidden */
  4205. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4206. var _this = this;
  4207. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4208. if (primitive.mode != undefined) {
  4209. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4210. primitive.mode !== 4 /* TRIANGLES */) {
  4211. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4212. }
  4213. // TODO: handle triangle strips
  4214. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4215. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4216. }
  4217. }
  4218. var attributes = {};
  4219. var loadAttribute = function (name, kind) {
  4220. var uniqueId = extension.attributes[name];
  4221. if (uniqueId == undefined) {
  4222. return;
  4223. }
  4224. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4225. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4226. babylonMesh._delayInfo.push(kind);
  4227. }
  4228. attributes[kind] = uniqueId;
  4229. };
  4230. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4231. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4232. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4233. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4234. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4235. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4236. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4237. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4238. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4239. if (!bufferView._dracoBabylonGeometry) {
  4240. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4241. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4242. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4243. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4244. babylonVertexData.applyToGeometry(babylonGeometry);
  4245. return babylonGeometry;
  4246. }).catch(function (error) {
  4247. throw new Error(context + ": " + error.message);
  4248. });
  4249. });
  4250. }
  4251. return bufferView._dracoBabylonGeometry;
  4252. });
  4253. };
  4254. return KHR_draco_mesh_compression;
  4255. }());
  4256. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4257. /***/ }),
  4258. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4259. /*!****************************************************!*\
  4260. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4261. \****************************************************/
  4262. /*! exports provided: KHR_lights */
  4263. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4264. "use strict";
  4265. __webpack_require__.r(__webpack_exports__);
  4266. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4267. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4268. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4269. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4270. var NAME = "KHR_lights_punctual";
  4271. var LightType;
  4272. (function (LightType) {
  4273. LightType["DIRECTIONAL"] = "directional";
  4274. LightType["POINT"] = "point";
  4275. LightType["SPOT"] = "spot";
  4276. })(LightType || (LightType = {}));
  4277. /**
  4278. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  4279. */
  4280. var KHR_lights = /** @class */ (function () {
  4281. /** @hidden */
  4282. function KHR_lights(loader) {
  4283. /**
  4284. * The name of this extension.
  4285. */
  4286. this.name = NAME;
  4287. this._loader = loader;
  4288. this.enabled = this._loader.isExtensionUsed(NAME);
  4289. }
  4290. /** @hidden */
  4291. KHR_lights.prototype.dispose = function () {
  4292. delete this._loader;
  4293. delete this._lights;
  4294. };
  4295. /** @hidden */
  4296. KHR_lights.prototype.onLoading = function () {
  4297. var extensions = this._loader.gltf.extensions;
  4298. if (extensions && extensions[this.name]) {
  4299. var extension = extensions[this.name];
  4300. this._lights = extension.lights;
  4301. }
  4302. };
  4303. /** @hidden */
  4304. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4305. var _this = this;
  4306. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4307. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4308. var babylonLight;
  4309. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4310. var name = light.name || babylonMesh.name;
  4311. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  4312. switch (light.type) {
  4313. case LightType.DIRECTIONAL: {
  4314. 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);
  4315. break;
  4316. }
  4317. case LightType.POINT: {
  4318. 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);
  4319. break;
  4320. }
  4321. case LightType.SPOT: {
  4322. 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);
  4323. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4324. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4325. babylonLight = babylonSpotLight;
  4326. break;
  4327. }
  4328. default: {
  4329. _this._loader.babylonScene._blockEntityCollection = false;
  4330. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4331. }
  4332. }
  4333. _this._loader.babylonScene._blockEntityCollection = false;
  4334. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4335. 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();
  4336. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4337. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4338. babylonLight.parent = babylonMesh;
  4339. _this._loader._babylonLights.push(babylonLight);
  4340. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4341. assign(babylonMesh);
  4342. });
  4343. });
  4344. };
  4345. return KHR_lights;
  4346. }());
  4347. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4348. /***/ }),
  4349. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4350. /*!********************************************************!*\
  4351. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4352. \********************************************************/
  4353. /*! exports provided: KHR_materials_clearcoat */
  4354. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4355. "use strict";
  4356. __webpack_require__.r(__webpack_exports__);
  4357. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4358. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4359. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4360. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4361. var NAME = "KHR_materials_clearcoat";
  4362. /**
  4363. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4364. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4365. * !!! Experimental Extension Subject to Changes !!!
  4366. */
  4367. var KHR_materials_clearcoat = /** @class */ (function () {
  4368. /** @hidden */
  4369. function KHR_materials_clearcoat(loader) {
  4370. /**
  4371. * The name of this extension.
  4372. */
  4373. this.name = NAME;
  4374. /**
  4375. * Defines a number that determines the order the extensions are applied.
  4376. */
  4377. this.order = 190;
  4378. this._loader = loader;
  4379. this.enabled = this._loader.isExtensionUsed(NAME);
  4380. }
  4381. /** @hidden */
  4382. KHR_materials_clearcoat.prototype.dispose = function () {
  4383. delete this._loader;
  4384. };
  4385. /** @hidden */
  4386. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4387. var _this = this;
  4388. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4389. var promises = new Array();
  4390. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4391. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4392. return Promise.all(promises).then(function () { });
  4393. });
  4394. };
  4395. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4396. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4397. throw new Error(context + ": Material type not supported");
  4398. }
  4399. var promises = new Array();
  4400. babylonMaterial.clearCoat.isEnabled = true;
  4401. if (properties.clearcoatFactor != undefined) {
  4402. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4403. }
  4404. else {
  4405. babylonMaterial.clearCoat.intensity = 0;
  4406. }
  4407. if (properties.clearcoatTexture) {
  4408. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4409. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4410. babylonMaterial.clearCoat.texture = texture;
  4411. }));
  4412. }
  4413. if (properties.clearcoatRoughnessFactor != undefined) {
  4414. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4415. }
  4416. else {
  4417. babylonMaterial.clearCoat.roughness = 0;
  4418. }
  4419. if (properties.clearcoatRoughnessTexture) {
  4420. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4421. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4422. babylonMaterial.clearCoat.texture = texture;
  4423. }));
  4424. }
  4425. if (properties.clearcoatNormalTexture) {
  4426. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4427. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4428. babylonMaterial.clearCoat.bumpTexture = texture;
  4429. }));
  4430. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4431. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4432. if (properties.clearcoatNormalTexture.scale != undefined) {
  4433. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4434. }
  4435. }
  4436. return Promise.all(promises).then(function () { });
  4437. };
  4438. return KHR_materials_clearcoat;
  4439. }());
  4440. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4441. /***/ }),
  4442. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  4443. /*!**************************************************!*\
  4444. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  4445. \**************************************************/
  4446. /*! exports provided: KHR_materials_ior */
  4447. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4448. "use strict";
  4449. __webpack_require__.r(__webpack_exports__);
  4450. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  4451. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4452. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4453. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4454. var NAME = "KHR_materials_ior";
  4455. /**
  4456. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  4457. * !!! Experimental Extension Subject to Changes !!!
  4458. */
  4459. var KHR_materials_ior = /** @class */ (function () {
  4460. /** @hidden */
  4461. function KHR_materials_ior(loader) {
  4462. /**
  4463. * The name of this extension.
  4464. */
  4465. this.name = NAME;
  4466. /**
  4467. * Defines a number that determines the order the extensions are applied.
  4468. */
  4469. this.order = 180;
  4470. this._loader = loader;
  4471. this.enabled = this._loader.isExtensionUsed(NAME);
  4472. }
  4473. /** @hidden */
  4474. KHR_materials_ior.prototype.dispose = function () {
  4475. delete this._loader;
  4476. };
  4477. /** @hidden */
  4478. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4479. var _this = this;
  4480. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4481. var promises = new Array();
  4482. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4483. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  4484. return Promise.all(promises).then(function () { });
  4485. });
  4486. };
  4487. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  4488. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4489. throw new Error(context + ": Material type not supported");
  4490. }
  4491. if (properties.ior !== undefined) {
  4492. babylonMaterial.indexOfRefraction = properties.ior;
  4493. }
  4494. else {
  4495. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  4496. }
  4497. return Promise.resolve();
  4498. };
  4499. /**
  4500. * Default ior Value from the spec.
  4501. */
  4502. KHR_materials_ior._DEFAULT_IOR = 1.5;
  4503. return KHR_materials_ior;
  4504. }());
  4505. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  4506. /***/ }),
  4507. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4508. /*!********************************************************************!*\
  4509. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4510. \********************************************************************/
  4511. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4512. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4513. "use strict";
  4514. __webpack_require__.r(__webpack_exports__);
  4515. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4516. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4517. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4518. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4519. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4520. /**
  4521. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4522. */
  4523. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4524. /** @hidden */
  4525. function KHR_materials_pbrSpecularGlossiness(loader) {
  4526. /**
  4527. * The name of this extension.
  4528. */
  4529. this.name = NAME;
  4530. /**
  4531. * Defines a number that determines the order the extensions are applied.
  4532. */
  4533. this.order = 200;
  4534. this._loader = loader;
  4535. this.enabled = this._loader.isExtensionUsed(NAME);
  4536. }
  4537. /** @hidden */
  4538. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4539. delete this._loader;
  4540. };
  4541. /** @hidden */
  4542. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4543. var _this = this;
  4544. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4545. var promises = new Array();
  4546. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4547. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4548. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4549. return Promise.all(promises).then(function () { });
  4550. });
  4551. };
  4552. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4553. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4554. throw new Error(context + ": Material type not supported");
  4555. }
  4556. var promises = new Array();
  4557. babylonMaterial.metallic = null;
  4558. babylonMaterial.roughness = null;
  4559. if (properties.diffuseFactor) {
  4560. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4561. babylonMaterial.alpha = properties.diffuseFactor[3];
  4562. }
  4563. else {
  4564. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4565. }
  4566. 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();
  4567. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4568. if (properties.diffuseTexture) {
  4569. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4570. texture.name = babylonMaterial.name + " (Diffuse)";
  4571. babylonMaterial.albedoTexture = texture;
  4572. }));
  4573. }
  4574. if (properties.specularGlossinessTexture) {
  4575. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4576. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4577. babylonMaterial.reflectivityTexture = texture;
  4578. }));
  4579. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4580. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4581. }
  4582. return Promise.all(promises).then(function () { });
  4583. };
  4584. return KHR_materials_pbrSpecularGlossiness;
  4585. }());
  4586. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4587. /***/ }),
  4588. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4589. /*!****************************************************!*\
  4590. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4591. \****************************************************/
  4592. /*! exports provided: KHR_materials_sheen */
  4593. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4594. "use strict";
  4595. __webpack_require__.r(__webpack_exports__);
  4596. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4597. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4598. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4599. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4600. var NAME = "KHR_materials_sheen";
  4601. /**
  4602. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4603. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4604. * !!! Experimental Extension Subject to Changes !!!
  4605. */
  4606. var KHR_materials_sheen = /** @class */ (function () {
  4607. /** @hidden */
  4608. function KHR_materials_sheen(loader) {
  4609. /**
  4610. * The name of this extension.
  4611. */
  4612. this.name = NAME;
  4613. /**
  4614. * Defines a number that determines the order the extensions are applied.
  4615. */
  4616. this.order = 190;
  4617. this._loader = loader;
  4618. this.enabled = this._loader.isExtensionUsed(NAME);
  4619. }
  4620. /** @hidden */
  4621. KHR_materials_sheen.prototype.dispose = function () {
  4622. delete this._loader;
  4623. };
  4624. /** @hidden */
  4625. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4626. var _this = this;
  4627. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4628. var promises = new Array();
  4629. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4630. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4631. return Promise.all(promises).then(function () { });
  4632. });
  4633. };
  4634. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4635. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4636. throw new Error(context + ": Material type not supported");
  4637. }
  4638. var promises = new Array();
  4639. babylonMaterial.sheen.isEnabled = true;
  4640. if (properties.intensityFactor != undefined) {
  4641. babylonMaterial.sheen.intensity = properties.intensityFactor;
  4642. }
  4643. else {
  4644. babylonMaterial.sheen.intensity = 0;
  4645. }
  4646. if (properties.colorFactor != undefined) {
  4647. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  4648. }
  4649. if (properties.colorIntensityTexture) {
  4650. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  4651. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  4652. babylonMaterial.sheen.texture = texture;
  4653. }));
  4654. }
  4655. if (properties.roughnessFactor !== undefined) {
  4656. babylonMaterial.sheen.roughness = properties.roughnessFactor;
  4657. }
  4658. else {
  4659. babylonMaterial.sheen.roughness = 0;
  4660. }
  4661. babylonMaterial.sheen.albedoScaling = true;
  4662. return Promise.all(promises).then(function () { });
  4663. };
  4664. return KHR_materials_sheen;
  4665. }());
  4666. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4667. /***/ }),
  4668. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4669. /*!*******************************************************!*\
  4670. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4671. \*******************************************************/
  4672. /*! exports provided: KHR_materials_specular */
  4673. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4674. "use strict";
  4675. __webpack_require__.r(__webpack_exports__);
  4676. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4677. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4678. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4679. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4680. var NAME = "KHR_materials_specular";
  4681. /**
  4682. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  4683. * !!! Experimental Extension Subject to Changes !!!
  4684. */
  4685. var KHR_materials_specular = /** @class */ (function () {
  4686. /** @hidden */
  4687. function KHR_materials_specular(loader) {
  4688. /**
  4689. * The name of this extension.
  4690. */
  4691. this.name = NAME;
  4692. /**
  4693. * Defines a number that determines the order the extensions are applied.
  4694. */
  4695. this.order = 190;
  4696. this._loader = loader;
  4697. this.enabled = this._loader.isExtensionUsed(NAME);
  4698. }
  4699. /** @hidden */
  4700. KHR_materials_specular.prototype.dispose = function () {
  4701. delete this._loader;
  4702. };
  4703. /** @hidden */
  4704. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4705. var _this = this;
  4706. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4707. var promises = new Array();
  4708. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4709. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4710. return Promise.all(promises).then(function () { });
  4711. });
  4712. };
  4713. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4714. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4715. throw new Error(context + ": Material type not supported");
  4716. }
  4717. var promises = new Array();
  4718. if (properties.specularFactor !== undefined) {
  4719. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4720. }
  4721. if (properties.specularColorFactor !== undefined) {
  4722. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  4723. }
  4724. if (properties.specularTexture) {
  4725. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  4726. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  4727. babylonMaterial.metallicReflectanceTexture = texture;
  4728. }));
  4729. }
  4730. return Promise.all(promises).then(function () { });
  4731. };
  4732. return KHR_materials_specular;
  4733. }());
  4734. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4735. /***/ }),
  4736. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  4737. /*!***********************************************************!*\
  4738. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  4739. \***********************************************************/
  4740. /*! exports provided: KHR_materials_transmission */
  4741. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4742. "use strict";
  4743. __webpack_require__.r(__webpack_exports__);
  4744. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  4745. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4746. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4747. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4748. var NAME = "KHR_materials_transmission";
  4749. /**
  4750. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  4751. * !!! Experimental Extension Subject to Changes !!!
  4752. */
  4753. var KHR_materials_transmission = /** @class */ (function () {
  4754. /** @hidden */
  4755. function KHR_materials_transmission(loader) {
  4756. /**
  4757. * The name of this extension.
  4758. */
  4759. this.name = NAME;
  4760. /**
  4761. * Defines a number that determines the order the extensions are applied.
  4762. */
  4763. this.order = 175;
  4764. this._loader = loader;
  4765. this.enabled = this._loader.isExtensionUsed(NAME);
  4766. if (this.enabled) {
  4767. loader._parent.transparencyAsCoverage = true;
  4768. }
  4769. }
  4770. /** @hidden */
  4771. KHR_materials_transmission.prototype.dispose = function () {
  4772. delete this._loader;
  4773. };
  4774. /** @hidden */
  4775. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4776. var _this = this;
  4777. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4778. console.log(extensionContext);
  4779. var promises = new Array();
  4780. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4781. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4782. promises.push(_this._loadTransparentPropertiesAsync(context, material, babylonMaterial, extension));
  4783. return Promise.all(promises).then(function () { });
  4784. });
  4785. };
  4786. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  4787. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4788. throw new Error(context + ": Material type not supported");
  4789. }
  4790. var pbrMaterial = babylonMaterial;
  4791. // Enables "refraction" texture which represents transmitted light.
  4792. pbrMaterial.subSurface.isRefractionEnabled = true;
  4793. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  4794. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  4795. // Albedo colour will tint transmission.
  4796. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  4797. if (extension.transmissionFactor !== undefined) {
  4798. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  4799. }
  4800. else {
  4801. pbrMaterial.subSurface.refractionIntensity = 1.0;
  4802. }
  4803. if (extension.transmissionTexture) {
  4804. return this._loader.loadTextureInfoAsync(context, extension.transmissionTexture)
  4805. .then(function (texture) {
  4806. pbrMaterial.subSurface.thicknessTexture = texture;
  4807. pbrMaterial.subSurface.useMaskFromThicknessTexture = true;
  4808. });
  4809. }
  4810. else {
  4811. return Promise.resolve();
  4812. }
  4813. };
  4814. return KHR_materials_transmission;
  4815. }());
  4816. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  4817. /***/ }),
  4818. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  4819. /*!****************************************************!*\
  4820. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  4821. \****************************************************/
  4822. /*! exports provided: KHR_materials_unlit */
  4823. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4824. "use strict";
  4825. __webpack_require__.r(__webpack_exports__);
  4826. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  4827. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4828. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4829. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4830. var NAME = "KHR_materials_unlit";
  4831. /**
  4832. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4833. */
  4834. var KHR_materials_unlit = /** @class */ (function () {
  4835. /** @hidden */
  4836. function KHR_materials_unlit(loader) {
  4837. /**
  4838. * The name of this extension.
  4839. */
  4840. this.name = NAME;
  4841. /**
  4842. * Defines a number that determines the order the extensions are applied.
  4843. */
  4844. this.order = 210;
  4845. this._loader = loader;
  4846. this.enabled = this._loader.isExtensionUsed(NAME);
  4847. }
  4848. /** @hidden */
  4849. KHR_materials_unlit.prototype.dispose = function () {
  4850. delete this._loader;
  4851. };
  4852. /** @hidden */
  4853. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4854. var _this = this;
  4855. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  4856. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  4857. });
  4858. };
  4859. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  4860. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4861. throw new Error(context + ": Material type not supported");
  4862. }
  4863. var promises = new Array();
  4864. babylonMaterial.unlit = true;
  4865. var properties = material.pbrMetallicRoughness;
  4866. if (properties) {
  4867. if (properties.baseColorFactor) {
  4868. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  4869. babylonMaterial.alpha = properties.baseColorFactor[3];
  4870. }
  4871. else {
  4872. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4873. }
  4874. if (properties.baseColorTexture) {
  4875. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  4876. texture.name = babylonMaterial.name + " (Base Color)";
  4877. babylonMaterial.albedoTexture = texture;
  4878. }));
  4879. }
  4880. }
  4881. if (material.doubleSided) {
  4882. babylonMaterial.backFaceCulling = false;
  4883. babylonMaterial.twoSidedLighting = true;
  4884. }
  4885. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4886. return Promise.all(promises).then(function () { });
  4887. };
  4888. return KHR_materials_unlit;
  4889. }());
  4890. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  4891. /***/ }),
  4892. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  4893. /*!*******************************************************!*\
  4894. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  4895. \*******************************************************/
  4896. /*! exports provided: KHR_materials_variants */
  4897. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4898. "use strict";
  4899. __webpack_require__.r(__webpack_exports__);
  4900. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  4901. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4902. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/tools");
  4903. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  4904. var NAME = "KHR_materials_variants";
  4905. /**
  4906. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  4907. * !!! Experimental Extension Subject to Changes !!!
  4908. */
  4909. var KHR_materials_variants = /** @class */ (function () {
  4910. /** @hidden */
  4911. function KHR_materials_variants(loader) {
  4912. /**
  4913. * The name of this extension.
  4914. */
  4915. this.name = NAME;
  4916. this._loader = loader;
  4917. this.enabled = this._loader.isExtensionUsed(NAME);
  4918. }
  4919. /** @hidden */
  4920. KHR_materials_variants.prototype.dispose = function () {
  4921. delete this._loader;
  4922. };
  4923. /**
  4924. * Gets the list of available variant tag names for this asset.
  4925. */
  4926. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  4927. return Object.keys(this._GetVariantsMap(rootMesh));
  4928. };
  4929. /**
  4930. * Select a variant given a variant tag name or a list of variant tag names.
  4931. * @param rootMesh The glTF root mesh
  4932. * @param variantName The variant name(s) to select
  4933. */
  4934. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  4935. var variantsMap = this._GetVariantsMap(rootMesh);
  4936. var select = function (variantName) {
  4937. var entries = variantsMap[variantName];
  4938. if (entries) {
  4939. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  4940. var entry = entries_1[_i];
  4941. entry.mesh.material = entry.material;
  4942. }
  4943. }
  4944. };
  4945. if (variantName instanceof Array) {
  4946. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  4947. var name_1 = variantName_1[_i];
  4948. select(name_1);
  4949. }
  4950. }
  4951. else {
  4952. select(variantName);
  4953. }
  4954. };
  4955. KHR_materials_variants._GetVariantsMap = function (rootMesh) {
  4956. var _a, _b;
  4957. 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];
  4958. };
  4959. /** @hidden */
  4960. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  4961. var _this = this;
  4962. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4963. var promises = new Array();
  4964. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  4965. assign(babylonMesh);
  4966. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  4967. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  4968. // For each mapping, look at the tags and make a new entry for them
  4969. for (var _i = 0, _a = extension.mapping; _i < _a.length; _i++) {
  4970. var mapping = _a[_i];
  4971. var _loop_1 = function (tag) {
  4972. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  4973. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  4974. var root = _this._loader.rootBabylonMesh;
  4975. var metadata = (root.metadata = root.metadata || {});
  4976. var gltf = (metadata.gltf = metadata.gltf || {});
  4977. var map = (gltf[NAME] = gltf[NAME] || {});
  4978. map[tag] = map[tag] || [];
  4979. map[tag].push({
  4980. mesh: babylonMesh,
  4981. material: babylonMaterial
  4982. });
  4983. }));
  4984. };
  4985. for (var _b = 0, _c = mapping.tags; _b < _c.length; _b++) {
  4986. var tag = _c[_b];
  4987. _loop_1(tag);
  4988. }
  4989. }
  4990. }
  4991. }));
  4992. return Promise.all(promises).then(function (_a) {
  4993. var babylonMesh = _a[0];
  4994. return babylonMesh;
  4995. });
  4996. });
  4997. };
  4998. return KHR_materials_variants;
  4999. }());
  5000. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  5001. /***/ }),
  5002. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  5003. /*!******************************************************!*\
  5004. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  5005. \******************************************************/
  5006. /*! exports provided: KHR_mesh_quantization */
  5007. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5008. "use strict";
  5009. __webpack_require__.r(__webpack_exports__);
  5010. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  5011. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5012. var NAME = "KHR_mesh_quantization";
  5013. /**
  5014. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  5015. */
  5016. var KHR_mesh_quantization = /** @class */ (function () {
  5017. /** @hidden */
  5018. function KHR_mesh_quantization(loader) {
  5019. /**
  5020. * The name of this extension.
  5021. */
  5022. this.name = NAME;
  5023. this.enabled = loader.isExtensionUsed(NAME);
  5024. }
  5025. /** @hidden */
  5026. KHR_mesh_quantization.prototype.dispose = function () {
  5027. };
  5028. return KHR_mesh_quantization;
  5029. }());
  5030. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  5031. /***/ }),
  5032. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  5033. /*!***************************************************!*\
  5034. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  5035. \***************************************************/
  5036. /*! exports provided: KHR_texture_basisu */
  5037. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5038. "use strict";
  5039. __webpack_require__.r(__webpack_exports__);
  5040. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  5041. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5042. var NAME = "KHR_texture_basisu";
  5043. /**
  5044. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  5045. * !!! Experimental Extension Subject to Changes !!!
  5046. */
  5047. var KHR_texture_basisu = /** @class */ (function () {
  5048. /** @hidden */
  5049. function KHR_texture_basisu(loader) {
  5050. /** The name of this extension. */
  5051. this.name = NAME;
  5052. this._loader = loader;
  5053. this.enabled = loader.isExtensionUsed(NAME);
  5054. }
  5055. /** @hidden */
  5056. KHR_texture_basisu.prototype.dispose = function () {
  5057. delete this._loader;
  5058. };
  5059. /** @hidden */
  5060. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  5061. var _this = this;
  5062. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  5063. 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));
  5064. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  5065. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  5066. babylonTexture.gammaSpace = false;
  5067. assign(babylonTexture);
  5068. });
  5069. });
  5070. };
  5071. return KHR_texture_basisu;
  5072. }());
  5073. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  5074. /***/ }),
  5075. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  5076. /*!******************************************************!*\
  5077. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  5078. \******************************************************/
  5079. /*! exports provided: KHR_texture_transform */
  5080. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5081. "use strict";
  5082. __webpack_require__.r(__webpack_exports__);
  5083. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  5084. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  5085. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  5086. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5087. var NAME = "KHR_texture_transform";
  5088. /**
  5089. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  5090. */
  5091. var KHR_texture_transform = /** @class */ (function () {
  5092. /** @hidden */
  5093. function KHR_texture_transform(loader) {
  5094. /**
  5095. * The name of this extension.
  5096. */
  5097. this.name = NAME;
  5098. this._loader = loader;
  5099. this.enabled = this._loader.isExtensionUsed(NAME);
  5100. }
  5101. /** @hidden */
  5102. KHR_texture_transform.prototype.dispose = function () {
  5103. delete this._loader;
  5104. };
  5105. /** @hidden */
  5106. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  5107. var _this = this;
  5108. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  5109. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  5110. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  5111. throw new Error(extensionContext + ": Texture type not supported");
  5112. }
  5113. if (extension.offset) {
  5114. babylonTexture.uOffset = extension.offset[0];
  5115. babylonTexture.vOffset = extension.offset[1];
  5116. }
  5117. // Always rotate around the origin.
  5118. babylonTexture.uRotationCenter = 0;
  5119. babylonTexture.vRotationCenter = 0;
  5120. if (extension.rotation) {
  5121. babylonTexture.wAng = -extension.rotation;
  5122. }
  5123. if (extension.scale) {
  5124. babylonTexture.uScale = extension.scale[0];
  5125. babylonTexture.vScale = extension.scale[1];
  5126. }
  5127. if (extension.texCoord != undefined) {
  5128. babylonTexture.coordinatesIndex = extension.texCoord;
  5129. }
  5130. assign(babylonTexture);
  5131. });
  5132. });
  5133. };
  5134. return KHR_texture_transform;
  5135. }());
  5136. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  5137. /***/ }),
  5138. /***/ "./glTF/2.0/Extensions/KHR_xmp.ts":
  5139. /*!****************************************!*\
  5140. !*** ./glTF/2.0/Extensions/KHR_xmp.ts ***!
  5141. \****************************************/
  5142. /*! exports provided: KHR_xmp */
  5143. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5144. "use strict";
  5145. __webpack_require__.r(__webpack_exports__);
  5146. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return KHR_xmp; });
  5147. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5148. var NAME = "KHR_xmp";
  5149. /**
  5150. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  5151. * !!! Experimental Extension Subject to Changes !!!
  5152. */
  5153. var KHR_xmp = /** @class */ (function () {
  5154. /** @hidden */
  5155. function KHR_xmp(loader) {
  5156. /**
  5157. * The name of this extension.
  5158. */
  5159. this.name = NAME;
  5160. /**
  5161. * Defines a number that determines the order the extensions are applied.
  5162. */
  5163. this.order = 100;
  5164. this._loader = loader;
  5165. this.enabled = this._loader.isExtensionUsed(NAME);
  5166. }
  5167. /** @hidden */
  5168. KHR_xmp.prototype.dispose = function () {
  5169. delete this._loader;
  5170. };
  5171. /**
  5172. * Called after the loader state changes to LOADING.
  5173. */
  5174. KHR_xmp.prototype.onLoading = function () {
  5175. var _a, _b, _c;
  5176. var xmp_gltf = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_xmp;
  5177. 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;
  5178. if (xmp_gltf && xmp_node) {
  5179. var packet = +xmp_node.packet;
  5180. if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {
  5181. this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};
  5182. this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];
  5183. }
  5184. }
  5185. };
  5186. return KHR_xmp;
  5187. }());
  5188. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_xmp(loader); });
  5189. /***/ }),
  5190. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  5191. /*!***************************************************!*\
  5192. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  5193. \***************************************************/
  5194. /*! exports provided: MSFT_audio_emitter */
  5195. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5196. "use strict";
  5197. __webpack_require__.r(__webpack_exports__);
  5198. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  5199. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  5200. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  5201. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5202. var NAME = "MSFT_audio_emitter";
  5203. /**
  5204. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  5205. */
  5206. var MSFT_audio_emitter = /** @class */ (function () {
  5207. /** @hidden */
  5208. function MSFT_audio_emitter(loader) {
  5209. /**
  5210. * The name of this extension.
  5211. */
  5212. this.name = NAME;
  5213. this._loader = loader;
  5214. this.enabled = this._loader.isExtensionUsed(NAME);
  5215. }
  5216. /** @hidden */
  5217. MSFT_audio_emitter.prototype.dispose = function () {
  5218. delete this._loader;
  5219. delete this._clips;
  5220. delete this._emitters;
  5221. };
  5222. /** @hidden */
  5223. MSFT_audio_emitter.prototype.onLoading = function () {
  5224. var extensions = this._loader.gltf.extensions;
  5225. if (extensions && extensions[this.name]) {
  5226. var extension = extensions[this.name];
  5227. this._clips = extension.clips;
  5228. this._emitters = extension.emitters;
  5229. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  5230. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  5231. }
  5232. };
  5233. /** @hidden */
  5234. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  5235. var _this = this;
  5236. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  5237. var promises = new Array();
  5238. promises.push(_this._loader.loadSceneAsync(context, scene));
  5239. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5240. var emitterIndex = _a[_i];
  5241. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5242. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  5243. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5244. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  5245. }
  5246. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  5247. }
  5248. return Promise.all(promises).then(function () { });
  5249. });
  5250. };
  5251. /** @hidden */
  5252. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  5253. var _this = this;
  5254. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5255. var promises = new Array();
  5256. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  5257. var _loop_1 = function (emitterIndex) {
  5258. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5259. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  5260. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  5261. var sound = _a[_i];
  5262. sound.attachToMesh(babylonMesh);
  5263. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5264. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  5265. 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);
  5266. }
  5267. }
  5268. }));
  5269. };
  5270. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5271. var emitterIndex = _a[_i];
  5272. _loop_1(emitterIndex);
  5273. }
  5274. assign(babylonMesh);
  5275. }).then(function (babylonMesh) {
  5276. return Promise.all(promises).then(function () {
  5277. return babylonMesh;
  5278. });
  5279. });
  5280. });
  5281. };
  5282. /** @hidden */
  5283. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  5284. var _this = this;
  5285. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  5286. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  5287. var promises = new Array();
  5288. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  5289. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  5290. var event_1 = _a[_i];
  5291. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  5292. }
  5293. return Promise.all(promises).then(function () {
  5294. return babylonAnimationGroup;
  5295. });
  5296. });
  5297. });
  5298. };
  5299. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  5300. if (clip._objectURL) {
  5301. return clip._objectURL;
  5302. }
  5303. var promise;
  5304. if (clip.uri) {
  5305. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  5306. }
  5307. else {
  5308. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  5309. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  5310. }
  5311. clip._objectURL = promise.then(function (data) {
  5312. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  5313. });
  5314. return clip._objectURL;
  5315. };
  5316. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  5317. var _this = this;
  5318. emitter._babylonSounds = emitter._babylonSounds || [];
  5319. if (!emitter._babylonData) {
  5320. var clipPromises = new Array();
  5321. var name_1 = emitter.name || "emitter" + emitter.index;
  5322. var options_1 = {
  5323. loop: false,
  5324. autoplay: false,
  5325. volume: emitter.volume == undefined ? 1 : emitter.volume,
  5326. };
  5327. var _loop_2 = function (i) {
  5328. var clipContext = "/extensions/" + this_1.name + "/clips";
  5329. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  5330. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  5331. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  5332. sound.refDistance = emitter.refDistance || 1;
  5333. sound.maxDistance = emitter.maxDistance || 256;
  5334. sound.rolloffFactor = emitter.rolloffFactor || 1;
  5335. sound.distanceModel = emitter.distanceModel || 'exponential';
  5336. sound._positionInEmitterSpace = true;
  5337. }));
  5338. };
  5339. var this_1 = this;
  5340. for (var i = 0; i < emitter.clips.length; i++) {
  5341. _loop_2(i);
  5342. }
  5343. var promise = Promise.all(clipPromises).then(function () {
  5344. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  5345. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  5346. if (emitter.innerAngle) {
  5347. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  5348. }
  5349. if (emitter.outerAngle) {
  5350. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  5351. }
  5352. if (emitter.volume) {
  5353. weightedSound.volume = emitter.volume;
  5354. }
  5355. emitter._babylonData.sound = weightedSound;
  5356. });
  5357. emitter._babylonData = {
  5358. loaded: promise
  5359. };
  5360. }
  5361. return emitter._babylonData.loaded;
  5362. };
  5363. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  5364. switch (action) {
  5365. case "play" /* play */: {
  5366. return function (currentFrame) {
  5367. var frameOffset = (startOffset || 0) + (currentFrame - time);
  5368. sound.play(frameOffset);
  5369. };
  5370. }
  5371. case "stop" /* stop */: {
  5372. return function (currentFrame) {
  5373. sound.stop();
  5374. };
  5375. }
  5376. case "pause" /* pause */: {
  5377. return function (currentFrame) {
  5378. sound.pause();
  5379. };
  5380. }
  5381. default: {
  5382. throw new Error(context + ": Unsupported action " + action);
  5383. }
  5384. }
  5385. };
  5386. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  5387. var _this = this;
  5388. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  5389. return Promise.resolve();
  5390. }
  5391. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  5392. var emitterIndex = event.emitter;
  5393. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  5394. return this._loadEmitterAsync(context, emitter).then(function () {
  5395. var sound = emitter._babylonData.sound;
  5396. if (sound) {
  5397. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  5398. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  5399. // Make sure all started audio stops when this animation is terminated.
  5400. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  5401. sound.stop();
  5402. });
  5403. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  5404. sound.pause();
  5405. });
  5406. }
  5407. });
  5408. };
  5409. return MSFT_audio_emitter;
  5410. }());
  5411. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  5412. /***/ }),
  5413. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  5414. /*!*****************************************!*\
  5415. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  5416. \*****************************************/
  5417. /*! exports provided: MSFT_lod */
  5418. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5419. "use strict";
  5420. __webpack_require__.r(__webpack_exports__);
  5421. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  5422. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  5423. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  5424. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5425. var NAME = "MSFT_lod";
  5426. /**
  5427. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  5428. */
  5429. var MSFT_lod = /** @class */ (function () {
  5430. /** @hidden */
  5431. function MSFT_lod(loader) {
  5432. /**
  5433. * The name of this extension.
  5434. */
  5435. this.name = NAME;
  5436. /**
  5437. * Defines a number that determines the order the extensions are applied.
  5438. */
  5439. this.order = 100;
  5440. /**
  5441. * Maximum number of LODs to load, starting from the lowest LOD.
  5442. */
  5443. this.maxLODsToLoad = 10;
  5444. /**
  5445. * Observable raised when all node LODs of one level are loaded.
  5446. * The event data is the index of the loaded LOD starting from zero.
  5447. * Dispose the loader to cancel the loading of the next level of LODs.
  5448. */
  5449. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5450. /**
  5451. * Observable raised when all material LODs of one level are loaded.
  5452. * The event data is the index of the loaded LOD starting from zero.
  5453. * Dispose the loader to cancel the loading of the next level of LODs.
  5454. */
  5455. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5456. this._bufferLODs = new Array();
  5457. this._nodeIndexLOD = null;
  5458. this._nodeSignalLODs = new Array();
  5459. this._nodePromiseLODs = new Array();
  5460. this._nodeBufferLODs = new Array();
  5461. this._materialIndexLOD = null;
  5462. this._materialSignalLODs = new Array();
  5463. this._materialPromiseLODs = new Array();
  5464. this._materialBufferLODs = new Array();
  5465. this._loader = loader;
  5466. this.enabled = this._loader.isExtensionUsed(NAME);
  5467. }
  5468. /** @hidden */
  5469. MSFT_lod.prototype.dispose = function () {
  5470. delete this._loader;
  5471. this._nodeIndexLOD = null;
  5472. this._nodeSignalLODs.length = 0;
  5473. this._nodePromiseLODs.length = 0;
  5474. this._nodeBufferLODs.length = 0;
  5475. this._materialIndexLOD = null;
  5476. this._materialSignalLODs.length = 0;
  5477. this._materialPromiseLODs.length = 0;
  5478. this._materialBufferLODs.length = 0;
  5479. this.onMaterialLODsLoadedObservable.clear();
  5480. this.onNodeLODsLoadedObservable.clear();
  5481. };
  5482. /** @hidden */
  5483. MSFT_lod.prototype.onReady = function () {
  5484. var _this = this;
  5485. var _loop_1 = function (indexLOD) {
  5486. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  5487. if (indexLOD !== 0) {
  5488. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  5489. _this._loader.log("Loaded node LOD " + indexLOD);
  5490. }
  5491. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  5492. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  5493. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  5494. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  5495. if (_this._nodeSignalLODs[indexLOD]) {
  5496. _this._nodeSignalLODs[indexLOD].resolve();
  5497. }
  5498. }
  5499. });
  5500. this_1._loader._completePromises.push(promise);
  5501. };
  5502. var this_1 = this;
  5503. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  5504. _loop_1(indexLOD);
  5505. }
  5506. var _loop_2 = function (indexLOD) {
  5507. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  5508. if (indexLOD !== 0) {
  5509. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  5510. _this._loader.log("Loaded material LOD " + indexLOD);
  5511. }
  5512. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  5513. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  5514. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  5515. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  5516. if (_this._materialSignalLODs[indexLOD]) {
  5517. _this._materialSignalLODs[indexLOD].resolve();
  5518. }
  5519. }
  5520. });
  5521. this_2._loader._completePromises.push(promise);
  5522. };
  5523. var this_2 = this;
  5524. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  5525. _loop_2(indexLOD);
  5526. }
  5527. };
  5528. /** @hidden */
  5529. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  5530. var promise = this._loader.loadSceneAsync(context, scene);
  5531. this._loadBufferLOD(this._bufferLODs, 0);
  5532. return promise;
  5533. };
  5534. /** @hidden */
  5535. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  5536. var _this = this;
  5537. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5538. var firstPromise;
  5539. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5540. _this._loader.logOpen("" + extensionContext);
  5541. var _loop_3 = function (indexLOD) {
  5542. var nodeLOD = nodeLODs[indexLOD];
  5543. if (indexLOD !== 0) {
  5544. _this._nodeIndexLOD = indexLOD;
  5545. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5546. }
  5547. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5548. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5549. if (indexLOD !== 0) {
  5550. // TODO: should not rely on _babylonTransformNode
  5551. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5552. if (previousNodeLOD._babylonTransformNode) {
  5553. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  5554. delete previousNodeLOD._babylonTransformNode;
  5555. }
  5556. }
  5557. babylonMesh.setEnabled(true);
  5558. return babylonMesh;
  5559. });
  5560. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5561. if (indexLOD === 0) {
  5562. firstPromise = promise;
  5563. }
  5564. else {
  5565. _this._nodeIndexLOD = null;
  5566. _this._nodePromiseLODs[indexLOD].push(promise);
  5567. }
  5568. };
  5569. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5570. _loop_3(indexLOD);
  5571. }
  5572. _this._loader.logClose();
  5573. return firstPromise;
  5574. });
  5575. };
  5576. /** @hidden */
  5577. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5578. var _this = this;
  5579. // Don't load material LODs if already loading a node LOD.
  5580. if (this._nodeIndexLOD) {
  5581. return null;
  5582. }
  5583. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5584. var firstPromise;
  5585. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5586. _this._loader.logOpen("" + extensionContext);
  5587. var _loop_4 = function (indexLOD) {
  5588. var materialLOD = materialLODs[indexLOD];
  5589. if (indexLOD !== 0) {
  5590. _this._materialIndexLOD = indexLOD;
  5591. }
  5592. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5593. if (indexLOD === 0) {
  5594. assign(babylonMaterial);
  5595. }
  5596. }).then(function (babylonMaterial) {
  5597. if (indexLOD !== 0) {
  5598. assign(babylonMaterial);
  5599. // TODO: should not rely on _data
  5600. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5601. if (previousDataLOD[babylonDrawMode]) {
  5602. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  5603. delete previousDataLOD[babylonDrawMode];
  5604. }
  5605. }
  5606. return babylonMaterial;
  5607. });
  5608. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5609. if (indexLOD === 0) {
  5610. firstPromise = promise;
  5611. }
  5612. else {
  5613. _this._materialIndexLOD = null;
  5614. _this._materialPromiseLODs[indexLOD].push(promise);
  5615. }
  5616. };
  5617. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5618. _loop_4(indexLOD);
  5619. }
  5620. _this._loader.logClose();
  5621. return firstPromise;
  5622. });
  5623. };
  5624. /** @hidden */
  5625. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5626. var _this = this;
  5627. // Defer the loading of uris if loading a node or material LOD.
  5628. if (this._nodeIndexLOD !== null) {
  5629. this._loader.log("deferred");
  5630. var previousIndexLOD = this._nodeIndexLOD - 1;
  5631. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5632. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5633. return _this._loader.loadUriAsync(context, property, uri);
  5634. });
  5635. }
  5636. else if (this._materialIndexLOD !== null) {
  5637. this._loader.log("deferred");
  5638. var previousIndexLOD = this._materialIndexLOD - 1;
  5639. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5640. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5641. return _this._loader.loadUriAsync(context, property, uri);
  5642. });
  5643. }
  5644. return null;
  5645. };
  5646. /** @hidden */
  5647. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5648. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5649. if (!this._loader.bin) {
  5650. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5651. }
  5652. var loadAsync = function (bufferLODs, indexLOD) {
  5653. var start = byteOffset;
  5654. var end = start + byteLength - 1;
  5655. var bufferLOD = bufferLODs[indexLOD];
  5656. if (bufferLOD) {
  5657. bufferLOD.start = Math.min(bufferLOD.start, start);
  5658. bufferLOD.end = Math.max(bufferLOD.end, end);
  5659. }
  5660. else {
  5661. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5662. bufferLODs[indexLOD] = bufferLOD;
  5663. }
  5664. return bufferLOD.loaded.promise.then(function (data) {
  5665. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  5666. });
  5667. };
  5668. this._loader.log("deferred");
  5669. if (this._nodeIndexLOD !== null) {
  5670. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  5671. }
  5672. else if (this._materialIndexLOD !== null) {
  5673. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  5674. }
  5675. else {
  5676. return loadAsync(this._bufferLODs, 0);
  5677. }
  5678. }
  5679. return null;
  5680. };
  5681. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  5682. var bufferLOD = bufferLODs[indexLOD];
  5683. if (bufferLOD) {
  5684. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  5685. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5686. bufferLOD.loaded.resolve(data);
  5687. }, function (error) {
  5688. bufferLOD.loaded.reject(error);
  5689. });
  5690. }
  5691. };
  5692. /**
  5693. * Gets an array of LOD properties from lowest to highest.
  5694. */
  5695. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5696. if (this.maxLODsToLoad <= 0) {
  5697. throw new Error("maxLODsToLoad must be greater than zero");
  5698. }
  5699. var properties = new Array();
  5700. for (var i = ids.length - 1; i >= 0; i--) {
  5701. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5702. if (properties.length === this.maxLODsToLoad) {
  5703. return properties;
  5704. }
  5705. }
  5706. properties.push(property);
  5707. return properties;
  5708. };
  5709. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  5710. var _this = this;
  5711. var babylonMaterials = new Array();
  5712. var babylonMaterial = babylonTransformNode.material;
  5713. if (babylonMaterial) {
  5714. babylonMaterials.push(babylonMaterial);
  5715. }
  5716. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  5717. var babylonMesh = _a[_i];
  5718. if (babylonMesh.material) {
  5719. babylonMaterials.push(babylonMesh.material);
  5720. }
  5721. }
  5722. babylonTransformNode.dispose();
  5723. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  5724. this._disposeMaterials(babylonMaterialsToDispose);
  5725. };
  5726. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  5727. var babylonTextures = {};
  5728. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  5729. var babylonMaterial = babylonMaterials_1[_i];
  5730. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  5731. var babylonTexture = _b[_a];
  5732. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  5733. }
  5734. babylonMaterial.dispose();
  5735. }
  5736. for (var uniqueId in babylonTextures) {
  5737. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  5738. var babylonMaterial = _d[_c];
  5739. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  5740. delete babylonTextures[uniqueId];
  5741. }
  5742. }
  5743. }
  5744. for (var uniqueId in babylonTextures) {
  5745. babylonTextures[uniqueId].dispose();
  5746. }
  5747. };
  5748. return MSFT_lod;
  5749. }());
  5750. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5751. /***/ }),
  5752. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5753. /*!***************************************************!*\
  5754. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5755. \***************************************************/
  5756. /*! exports provided: MSFT_minecraftMesh */
  5757. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5758. "use strict";
  5759. __webpack_require__.r(__webpack_exports__);
  5760. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5761. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5762. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5763. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5764. var NAME = "MSFT_minecraftMesh";
  5765. /** @hidden */
  5766. var MSFT_minecraftMesh = /** @class */ (function () {
  5767. function MSFT_minecraftMesh(loader) {
  5768. this.name = NAME;
  5769. this._loader = loader;
  5770. this.enabled = this._loader.isExtensionUsed(NAME);
  5771. }
  5772. MSFT_minecraftMesh.prototype.dispose = function () {
  5773. delete this._loader;
  5774. };
  5775. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5776. var _this = this;
  5777. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5778. if (extra) {
  5779. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5780. throw new Error(extraContext + ": Material type not supported");
  5781. }
  5782. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5783. if (babylonMaterial.needAlphaBlending()) {
  5784. babylonMaterial.forceDepthWrite = true;
  5785. babylonMaterial.separateCullingPass = true;
  5786. }
  5787. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5788. babylonMaterial.twoSidedLighting = true;
  5789. return promise;
  5790. }
  5791. return null;
  5792. });
  5793. };
  5794. return MSFT_minecraftMesh;
  5795. }());
  5796. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5797. /***/ }),
  5798. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5799. /*!*************************************************!*\
  5800. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5801. \*************************************************/
  5802. /*! exports provided: MSFT_sRGBFactors */
  5803. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5804. "use strict";
  5805. __webpack_require__.r(__webpack_exports__);
  5806. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5807. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5808. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5809. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5810. var NAME = "MSFT_sRGBFactors";
  5811. /** @hidden */
  5812. var MSFT_sRGBFactors = /** @class */ (function () {
  5813. function MSFT_sRGBFactors(loader) {
  5814. this.name = NAME;
  5815. this._loader = loader;
  5816. this.enabled = this._loader.isExtensionUsed(NAME);
  5817. }
  5818. MSFT_sRGBFactors.prototype.dispose = function () {
  5819. delete this._loader;
  5820. };
  5821. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5822. var _this = this;
  5823. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5824. if (extra) {
  5825. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5826. throw new Error(extraContext + ": Material type not supported");
  5827. }
  5828. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5829. if (!babylonMaterial.albedoTexture) {
  5830. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5831. }
  5832. if (!babylonMaterial.reflectivityTexture) {
  5833. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5834. }
  5835. return promise;
  5836. }
  5837. return null;
  5838. });
  5839. };
  5840. return MSFT_sRGBFactors;
  5841. }());
  5842. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5843. /***/ }),
  5844. /***/ "./glTF/2.0/Extensions/index.ts":
  5845. /*!**************************************!*\
  5846. !*** ./glTF/2.0/Extensions/index.ts ***!
  5847. \**************************************/
  5848. /*! 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 */
  5849. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5850. "use strict";
  5851. __webpack_require__.r(__webpack_exports__);
  5852. /* 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");
  5853. /* 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"]; });
  5854. /* 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");
  5855. /* 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"]; });
  5856. /* 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");
  5857. /* 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"]; });
  5858. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5859. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  5860. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5861. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_pbrSpecularGlossiness"]; });
  5862. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5863. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_unlit"]; });
  5864. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5865. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_clearcoat"]; });
  5866. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5867. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  5868. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5869. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_specular"]; });
  5870. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  5871. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_ior"]; });
  5872. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  5873. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_variants"]; });
  5874. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  5875. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_transmission"]; });
  5876. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  5877. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__["KHR_mesh_quantization"]; });
  5878. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  5879. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__["KHR_texture_basisu"]; });
  5880. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5881. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__["KHR_texture_transform"]; });
  5882. /* harmony import */ var _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_xmp */ "./glTF/2.0/Extensions/KHR_xmp.ts");
  5883. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__["KHR_xmp"]; });
  5884. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5885. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__["MSFT_audio_emitter"]; });
  5886. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5887. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__["MSFT_lod"]; });
  5888. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5889. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__["MSFT_minecraftMesh"]; });
  5890. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5891. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__["MSFT_sRGBFactors"]; });
  5892. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5893. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__["ExtrasAsMetadata"]; });
  5894. /***/ }),
  5895. /***/ "./glTF/2.0/glTFLoader.ts":
  5896. /*!********************************!*\
  5897. !*** ./glTF/2.0/glTFLoader.ts ***!
  5898. \********************************/
  5899. /*! exports provided: ArrayItem, GLTFLoader */
  5900. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5901. "use strict";
  5902. __webpack_require__.r(__webpack_exports__);
  5903. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5904. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5905. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  5906. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5907. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5908. /**
  5909. * Helper class for working with arrays when loading the glTF asset
  5910. */
  5911. var ArrayItem = /** @class */ (function () {
  5912. function ArrayItem() {
  5913. }
  5914. /**
  5915. * Gets an item from the given array.
  5916. * @param context The context when loading the asset
  5917. * @param array The array to get the item from
  5918. * @param index The index to the array
  5919. * @returns The array item
  5920. */
  5921. ArrayItem.Get = function (context, array, index) {
  5922. if (!array || index == undefined || !array[index]) {
  5923. throw new Error(context + ": Failed to find index (" + index + ")");
  5924. }
  5925. return array[index];
  5926. };
  5927. /**
  5928. * Assign an `index` field to each item of the given array.
  5929. * @param array The array of items
  5930. */
  5931. ArrayItem.Assign = function (array) {
  5932. if (array) {
  5933. for (var index = 0; index < array.length; index++) {
  5934. array[index].index = index;
  5935. }
  5936. }
  5937. };
  5938. return ArrayItem;
  5939. }());
  5940. /**
  5941. * The glTF 2.0 loader
  5942. */
  5943. var GLTFLoader = /** @class */ (function () {
  5944. /** @hidden */
  5945. function GLTFLoader(parent) {
  5946. /** @hidden */
  5947. this._completePromises = new Array();
  5948. /** @hidden */
  5949. this._forAssetContainer = false;
  5950. /** Storage */
  5951. this._babylonLights = [];
  5952. /** @hidden */
  5953. this._disableInstancedMesh = 0;
  5954. this._disposed = false;
  5955. this._state = null;
  5956. this._extensions = new Array();
  5957. this._defaultBabylonMaterialData = {};
  5958. this._parent = parent;
  5959. }
  5960. /**
  5961. * Registers a loader extension.
  5962. * @param name The name of the loader extension.
  5963. * @param factory The factory function that creates the loader extension.
  5964. */
  5965. GLTFLoader.RegisterExtension = function (name, factory) {
  5966. if (GLTFLoader.UnregisterExtension(name)) {
  5967. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  5968. }
  5969. GLTFLoader._RegisteredExtensions[name] = {
  5970. factory: factory
  5971. };
  5972. };
  5973. /**
  5974. * Unregisters a loader extension.
  5975. * @param name The name of the loader extension.
  5976. * @returns A boolean indicating whether the extension has been unregistered
  5977. */
  5978. GLTFLoader.UnregisterExtension = function (name) {
  5979. if (!GLTFLoader._RegisteredExtensions[name]) {
  5980. return false;
  5981. }
  5982. delete GLTFLoader._RegisteredExtensions[name];
  5983. return true;
  5984. };
  5985. Object.defineProperty(GLTFLoader.prototype, "state", {
  5986. /**
  5987. * The loader state.
  5988. */
  5989. get: function () {
  5990. return this._state;
  5991. },
  5992. enumerable: true,
  5993. configurable: true
  5994. });
  5995. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  5996. /**
  5997. * The object that represents the glTF JSON.
  5998. */
  5999. get: function () {
  6000. return this._gltf;
  6001. },
  6002. enumerable: true,
  6003. configurable: true
  6004. });
  6005. Object.defineProperty(GLTFLoader.prototype, "bin", {
  6006. /**
  6007. * The BIN chunk of a binary glTF.
  6008. */
  6009. get: function () {
  6010. return this._bin;
  6011. },
  6012. enumerable: true,
  6013. configurable: true
  6014. });
  6015. Object.defineProperty(GLTFLoader.prototype, "parent", {
  6016. /**
  6017. * The parent file loader.
  6018. */
  6019. get: function () {
  6020. return this._parent;
  6021. },
  6022. enumerable: true,
  6023. configurable: true
  6024. });
  6025. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  6026. /**
  6027. * The Babylon scene when loading the asset.
  6028. */
  6029. get: function () {
  6030. return this._babylonScene;
  6031. },
  6032. enumerable: true,
  6033. configurable: true
  6034. });
  6035. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  6036. /**
  6037. * The root Babylon mesh when loading the asset.
  6038. */
  6039. get: function () {
  6040. return this._rootBabylonMesh;
  6041. },
  6042. enumerable: true,
  6043. configurable: true
  6044. });
  6045. /** @hidden */
  6046. GLTFLoader.prototype.dispose = function () {
  6047. if (this._disposed) {
  6048. return;
  6049. }
  6050. this._disposed = true;
  6051. this._completePromises.length = 0;
  6052. for (var name_1 in this._extensions) {
  6053. var extension = this._extensions[name_1];
  6054. extension.dispose && extension.dispose();
  6055. delete this._extensions[name_1];
  6056. }
  6057. delete this._gltf;
  6058. delete this._babylonScene;
  6059. delete this._rootBabylonMesh;
  6060. this._parent.dispose();
  6061. };
  6062. /** @hidden */
  6063. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  6064. var _this = this;
  6065. return Promise.resolve().then(function () {
  6066. _this._babylonScene = scene;
  6067. _this._rootUrl = rootUrl;
  6068. _this._fileName = fileName || "scene";
  6069. _this._forAssetContainer = forAssetContainer;
  6070. _this._loadData(data);
  6071. var nodes = null;
  6072. if (meshesNames) {
  6073. var nodeMap_1 = {};
  6074. if (_this._gltf.nodes) {
  6075. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  6076. var node = _a[_i];
  6077. if (node.name) {
  6078. nodeMap_1[node.name] = node.index;
  6079. }
  6080. }
  6081. }
  6082. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  6083. nodes = names.map(function (name) {
  6084. var node = nodeMap_1[name];
  6085. if (node === undefined) {
  6086. throw new Error("Failed to find node '" + name + "'");
  6087. }
  6088. return node;
  6089. });
  6090. }
  6091. return _this._loadAsync(nodes, function () {
  6092. return {
  6093. meshes: _this._getMeshes(),
  6094. particleSystems: [],
  6095. skeletons: _this._getSkeletons(),
  6096. animationGroups: _this._getAnimationGroups(),
  6097. lights: _this._babylonLights,
  6098. transformNodes: _this._getTransformNodes()
  6099. };
  6100. });
  6101. });
  6102. };
  6103. /** @hidden */
  6104. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  6105. var _this = this;
  6106. return Promise.resolve().then(function () {
  6107. _this._babylonScene = scene;
  6108. _this._rootUrl = rootUrl;
  6109. _this._fileName = fileName || "scene";
  6110. _this._loadData(data);
  6111. return _this._loadAsync(null, function () { return undefined; });
  6112. });
  6113. };
  6114. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  6115. var _this = this;
  6116. return Promise.resolve().then(function () {
  6117. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  6118. _this._loadExtensions();
  6119. _this._checkExtensions();
  6120. 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];
  6121. 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];
  6122. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  6123. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  6124. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  6125. _this._extensionsOnLoading();
  6126. var promises = new Array();
  6127. // Block the marking of materials dirty until the scene is loaded.
  6128. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  6129. _this._babylonScene.blockMaterialDirtyMechanism = true;
  6130. if (nodes) {
  6131. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  6132. }
  6133. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  6134. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  6135. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  6136. }
  6137. // Restore the blocking of material dirty.
  6138. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  6139. if (_this._parent.compileMaterials) {
  6140. promises.push(_this._compileMaterialsAsync());
  6141. }
  6142. if (_this._parent.compileShadowGenerators) {
  6143. promises.push(_this._compileShadowGeneratorsAsync());
  6144. }
  6145. var resultPromise = Promise.all(promises).then(function () {
  6146. if (_this._rootBabylonMesh) {
  6147. _this._rootBabylonMesh.setEnabled(true);
  6148. }
  6149. _this._extensionsOnReady();
  6150. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  6151. _this._startAnimations();
  6152. return resultFunc();
  6153. });
  6154. resultPromise.then(function () {
  6155. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  6156. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  6157. if (!_this._disposed) {
  6158. Promise.all(_this._completePromises).then(function () {
  6159. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  6160. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  6161. _this._parent.onCompleteObservable.notifyObservers(undefined);
  6162. _this._parent.onCompleteObservable.clear();
  6163. _this.dispose();
  6164. }, function (error) {
  6165. _this._parent.onErrorObservable.notifyObservers(error);
  6166. _this._parent.onErrorObservable.clear();
  6167. _this.dispose();
  6168. });
  6169. }
  6170. });
  6171. });
  6172. return resultPromise;
  6173. }, function (error) {
  6174. if (!_this._disposed) {
  6175. _this._parent.onErrorObservable.notifyObservers(error);
  6176. _this._parent.onErrorObservable.clear();
  6177. _this.dispose();
  6178. }
  6179. throw error;
  6180. });
  6181. };
  6182. GLTFLoader.prototype._loadData = function (data) {
  6183. this._gltf = data.json;
  6184. this._setupData();
  6185. if (data.bin) {
  6186. var buffers = this._gltf.buffers;
  6187. if (buffers && buffers[0] && !buffers[0].uri) {
  6188. var binaryBuffer = buffers[0];
  6189. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  6190. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  6191. }
  6192. this._bin = data.bin;
  6193. }
  6194. else {
  6195. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  6196. }
  6197. }
  6198. };
  6199. GLTFLoader.prototype._setupData = function () {
  6200. ArrayItem.Assign(this._gltf.accessors);
  6201. ArrayItem.Assign(this._gltf.animations);
  6202. ArrayItem.Assign(this._gltf.buffers);
  6203. ArrayItem.Assign(this._gltf.bufferViews);
  6204. ArrayItem.Assign(this._gltf.cameras);
  6205. ArrayItem.Assign(this._gltf.images);
  6206. ArrayItem.Assign(this._gltf.materials);
  6207. ArrayItem.Assign(this._gltf.meshes);
  6208. ArrayItem.Assign(this._gltf.nodes);
  6209. ArrayItem.Assign(this._gltf.samplers);
  6210. ArrayItem.Assign(this._gltf.scenes);
  6211. ArrayItem.Assign(this._gltf.skins);
  6212. ArrayItem.Assign(this._gltf.textures);
  6213. if (this._gltf.nodes) {
  6214. var nodeParents = {};
  6215. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  6216. var node = _a[_i];
  6217. if (node.children) {
  6218. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  6219. var index = _c[_b];
  6220. nodeParents[index] = node.index;
  6221. }
  6222. }
  6223. }
  6224. var rootNode = this._createRootNode();
  6225. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  6226. var node = _e[_d];
  6227. var parentIndex = nodeParents[node.index];
  6228. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  6229. }
  6230. }
  6231. };
  6232. GLTFLoader.prototype._loadExtensions = function () {
  6233. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  6234. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  6235. if (extension.name !== name_2) {
  6236. 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);
  6237. }
  6238. this._extensions.push(extension);
  6239. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  6240. }
  6241. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  6242. this._parent.onExtensionLoadedObservable.clear();
  6243. };
  6244. GLTFLoader.prototype._checkExtensions = function () {
  6245. if (this._gltf.extensionsRequired) {
  6246. var _loop_1 = function (name_3) {
  6247. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  6248. if (!available) {
  6249. throw new Error("Require extension " + name_3 + " is not available");
  6250. }
  6251. };
  6252. var this_1 = this;
  6253. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  6254. var name_3 = _a[_i];
  6255. _loop_1(name_3);
  6256. }
  6257. }
  6258. };
  6259. GLTFLoader.prototype._setState = function (state) {
  6260. this._state = state;
  6261. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  6262. };
  6263. GLTFLoader.prototype._createRootNode = function () {
  6264. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6265. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  6266. this._babylonScene._blockEntityCollection = false;
  6267. this._rootBabylonMesh.setEnabled(false);
  6268. var rootNode = {
  6269. _babylonTransformNode: this._rootBabylonMesh,
  6270. index: -1
  6271. };
  6272. switch (this._parent.coordinateSystemMode) {
  6273. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  6274. if (!this._babylonScene.useRightHandedSystem) {
  6275. rootNode.rotation = [0, 1, 0, 0];
  6276. rootNode.scale = [1, 1, -1];
  6277. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  6278. }
  6279. break;
  6280. }
  6281. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  6282. this._babylonScene.useRightHandedSystem = true;
  6283. break;
  6284. }
  6285. default: {
  6286. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  6287. }
  6288. }
  6289. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  6290. return rootNode;
  6291. };
  6292. /**
  6293. * Loads a glTF scene.
  6294. * @param context The context when loading the asset
  6295. * @param scene The glTF scene property
  6296. * @returns A promise that resolves when the load is complete
  6297. */
  6298. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  6299. var _this = this;
  6300. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  6301. if (extensionPromise) {
  6302. return extensionPromise;
  6303. }
  6304. var promises = new Array();
  6305. this.logOpen(context + " " + (scene.name || ""));
  6306. if (scene.nodes) {
  6307. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  6308. var index = _a[_i];
  6309. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  6310. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  6311. babylonMesh.parent = _this._rootBabylonMesh;
  6312. }));
  6313. }
  6314. }
  6315. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  6316. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  6317. if (this._gltf.nodes) {
  6318. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  6319. var node = _c[_b];
  6320. if (node._babylonTransformNode && node._babylonBones) {
  6321. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  6322. var babylonBone = _e[_d];
  6323. babylonBone.linkTransformNode(node._babylonTransformNode);
  6324. }
  6325. }
  6326. }
  6327. }
  6328. promises.push(this._loadAnimationsAsync());
  6329. this.logClose();
  6330. return Promise.all(promises).then(function () { });
  6331. };
  6332. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  6333. if (node._primitiveBabylonMeshes) {
  6334. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  6335. var babylonMesh = _a[_i];
  6336. callback(babylonMesh);
  6337. }
  6338. }
  6339. };
  6340. GLTFLoader.prototype._getMeshes = function () {
  6341. var meshes = new Array();
  6342. // Root mesh is always first.
  6343. meshes.push(this._rootBabylonMesh);
  6344. var nodes = this._gltf.nodes;
  6345. if (nodes) {
  6346. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  6347. var node = nodes_1[_i];
  6348. this._forEachPrimitive(node, function (babylonMesh) {
  6349. meshes.push(babylonMesh);
  6350. });
  6351. }
  6352. }
  6353. return meshes;
  6354. };
  6355. GLTFLoader.prototype._getTransformNodes = function () {
  6356. var transformNodes = new Array();
  6357. var nodes = this._gltf.nodes;
  6358. if (nodes) {
  6359. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  6360. var node = nodes_2[_i];
  6361. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  6362. transformNodes.push(node._babylonTransformNode);
  6363. }
  6364. }
  6365. }
  6366. return transformNodes;
  6367. };
  6368. GLTFLoader.prototype._getSkeletons = function () {
  6369. var skeletons = new Array();
  6370. var skins = this._gltf.skins;
  6371. if (skins) {
  6372. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  6373. var skin = skins_1[_i];
  6374. if (skin._data) {
  6375. skeletons.push(skin._data.babylonSkeleton);
  6376. }
  6377. }
  6378. }
  6379. return skeletons;
  6380. };
  6381. GLTFLoader.prototype._getAnimationGroups = function () {
  6382. var animationGroups = new Array();
  6383. var animations = this._gltf.animations;
  6384. if (animations) {
  6385. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  6386. var animation = animations_1[_i];
  6387. if (animation._babylonAnimationGroup) {
  6388. animationGroups.push(animation._babylonAnimationGroup);
  6389. }
  6390. }
  6391. }
  6392. return animationGroups;
  6393. };
  6394. GLTFLoader.prototype._startAnimations = function () {
  6395. switch (this._parent.animationStartMode) {
  6396. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  6397. // do nothing
  6398. break;
  6399. }
  6400. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  6401. var babylonAnimationGroups = this._getAnimationGroups();
  6402. if (babylonAnimationGroups.length !== 0) {
  6403. babylonAnimationGroups[0].start(true);
  6404. }
  6405. break;
  6406. }
  6407. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  6408. var babylonAnimationGroups = this._getAnimationGroups();
  6409. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  6410. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  6411. babylonAnimationGroup.start(true);
  6412. }
  6413. break;
  6414. }
  6415. default: {
  6416. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  6417. return;
  6418. }
  6419. }
  6420. };
  6421. /**
  6422. * Loads a glTF node.
  6423. * @param context The context when loading the asset
  6424. * @param node The glTF node property
  6425. * @param assign A function called synchronously after parsing the glTF properties
  6426. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  6427. */
  6428. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  6429. var _this = this;
  6430. if (assign === void 0) { assign = function () { }; }
  6431. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  6432. if (extensionPromise) {
  6433. return extensionPromise;
  6434. }
  6435. if (node._babylonTransformNode) {
  6436. throw new Error(context + ": Invalid recursive node hierarchy");
  6437. }
  6438. var promises = new Array();
  6439. this.logOpen(context + " " + (node.name || ""));
  6440. var loadNode = function (babylonTransformNode) {
  6441. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  6442. GLTFLoader._LoadTransform(node, babylonTransformNode);
  6443. if (node.camera != undefined) {
  6444. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  6445. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  6446. babylonCamera.parent = babylonTransformNode;
  6447. }));
  6448. }
  6449. if (node.children) {
  6450. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  6451. var index = _a[_i];
  6452. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  6453. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  6454. childBabylonMesh.parent = babylonTransformNode;
  6455. }));
  6456. }
  6457. }
  6458. assign(babylonTransformNode);
  6459. };
  6460. if (node.mesh == undefined) {
  6461. var nodeName = node.name || "node" + node.index;
  6462. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6463. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  6464. this._babylonScene._blockEntityCollection = false;
  6465. loadNode(node._babylonTransformNode);
  6466. }
  6467. else {
  6468. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  6469. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  6470. }
  6471. this.logClose();
  6472. return Promise.all(promises).then(function () {
  6473. _this._forEachPrimitive(node, function (babylonMesh) {
  6474. babylonMesh.refreshBoundingInfo(true);
  6475. });
  6476. return node._babylonTransformNode;
  6477. });
  6478. };
  6479. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  6480. var primitives = mesh.primitives;
  6481. if (!primitives || !primitives.length) {
  6482. throw new Error(context + ": Primitives are missing");
  6483. }
  6484. if (primitives[0].index == undefined) {
  6485. ArrayItem.Assign(primitives);
  6486. }
  6487. var promises = new Array();
  6488. this.logOpen(context + " " + (mesh.name || ""));
  6489. var name = node.name || "node" + node.index;
  6490. if (primitives.length === 1) {
  6491. var primitive = mesh.primitives[0];
  6492. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  6493. node._babylonTransformNode = babylonMesh;
  6494. node._primitiveBabylonMeshes = [babylonMesh];
  6495. }));
  6496. }
  6497. else {
  6498. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6499. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  6500. this._babylonScene._blockEntityCollection = false;
  6501. node._primitiveBabylonMeshes = [];
  6502. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  6503. var primitive = primitives_1[_i];
  6504. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  6505. babylonMesh.parent = node._babylonTransformNode;
  6506. node._primitiveBabylonMeshes.push(babylonMesh);
  6507. }));
  6508. }
  6509. }
  6510. if (node.skin != undefined) {
  6511. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  6512. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  6513. }
  6514. assign(node._babylonTransformNode);
  6515. this.logClose();
  6516. return Promise.all(promises).then(function () {
  6517. return node._babylonTransformNode;
  6518. });
  6519. };
  6520. /**
  6521. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  6522. * @param context The context when loading the asset
  6523. * @param name The mesh name when loading the asset
  6524. * @param node The glTF node when loading the asset
  6525. * @param mesh The glTF mesh when loading the asset
  6526. * @param primitive The glTF mesh primitive property
  6527. * @param assign A function called synchronously after parsing the glTF properties
  6528. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  6529. */
  6530. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  6531. var _this = this;
  6532. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  6533. if (extensionPromise) {
  6534. return extensionPromise;
  6535. }
  6536. this.logOpen("" + context);
  6537. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  6538. var babylonAbstractMesh;
  6539. var promise;
  6540. if (shouldInstance && primitive._instanceData) {
  6541. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  6542. promise = primitive._instanceData.promise;
  6543. }
  6544. else {
  6545. var promises = new Array();
  6546. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6547. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  6548. this._babylonScene._blockEntityCollection = false;
  6549. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  6550. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  6551. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  6552. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  6553. babylonGeometry.applyToMesh(babylonMesh_1);
  6554. });
  6555. }));
  6556. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  6557. if (primitive.material == undefined) {
  6558. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  6559. if (!babylonMaterial) {
  6560. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  6561. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6562. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  6563. }
  6564. babylonMesh_1.material = babylonMaterial;
  6565. }
  6566. else {
  6567. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  6568. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  6569. babylonMesh_1.material = babylonMaterial;
  6570. }));
  6571. }
  6572. promise = Promise.all(promises);
  6573. if (shouldInstance) {
  6574. primitive._instanceData = {
  6575. babylonSourceMesh: babylonMesh_1,
  6576. promise: promise
  6577. };
  6578. }
  6579. babylonAbstractMesh = babylonMesh_1;
  6580. }
  6581. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  6582. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  6583. assign(babylonAbstractMesh);
  6584. this.logClose();
  6585. return promise.then(function () {
  6586. return babylonAbstractMesh;
  6587. });
  6588. };
  6589. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  6590. var _this = this;
  6591. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  6592. if (extensionPromise) {
  6593. return extensionPromise;
  6594. }
  6595. var attributes = primitive.attributes;
  6596. if (!attributes) {
  6597. throw new Error(context + ": Attributes are missing");
  6598. }
  6599. var promises = new Array();
  6600. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  6601. if (primitive.indices == undefined) {
  6602. babylonMesh.isUnIndexed = true;
  6603. }
  6604. else {
  6605. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6606. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6607. babylonGeometry.setIndices(data);
  6608. }));
  6609. }
  6610. var loadAttribute = function (attribute, kind, callback) {
  6611. if (attributes[attribute] == undefined) {
  6612. return;
  6613. }
  6614. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6615. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6616. babylonMesh._delayInfo.push(kind);
  6617. }
  6618. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6619. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6620. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6621. }));
  6622. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6623. babylonMesh.numBoneInfluencers = 8;
  6624. }
  6625. if (callback) {
  6626. callback(accessor);
  6627. }
  6628. };
  6629. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6630. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6631. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6632. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6633. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6634. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6635. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6636. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  6637. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  6638. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6639. if (accessor.type === "VEC4" /* VEC4 */) {
  6640. babylonMesh.hasVertexAlpha = true;
  6641. }
  6642. });
  6643. return Promise.all(promises).then(function () {
  6644. return babylonGeometry;
  6645. });
  6646. };
  6647. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6648. if (!primitive.targets) {
  6649. return;
  6650. }
  6651. if (node._numMorphTargets == undefined) {
  6652. node._numMorphTargets = primitive.targets.length;
  6653. }
  6654. else if (primitive.targets.length !== node._numMorphTargets) {
  6655. throw new Error(context + ": Primitives do not have the same number of targets");
  6656. }
  6657. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6658. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6659. for (var index = 0; index < primitive.targets.length; index++) {
  6660. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6661. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6662. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6663. // TODO: tell the target whether it has positions, normals, tangents
  6664. }
  6665. };
  6666. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6667. if (!primitive.targets) {
  6668. return Promise.resolve();
  6669. }
  6670. var promises = new Array();
  6671. var morphTargetManager = babylonMesh.morphTargetManager;
  6672. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6673. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6674. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6675. }
  6676. return Promise.all(promises).then(function () { });
  6677. };
  6678. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6679. var _this = this;
  6680. var promises = new Array();
  6681. var loadAttribute = function (attribute, kind, setData) {
  6682. if (attributes[attribute] == undefined) {
  6683. return;
  6684. }
  6685. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6686. if (!babylonVertexBuffer) {
  6687. return;
  6688. }
  6689. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6690. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6691. setData(babylonVertexBuffer, data);
  6692. }));
  6693. };
  6694. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6695. var positions = new Float32Array(data.length);
  6696. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6697. positions[index] = data[index] + value;
  6698. });
  6699. babylonMorphTarget.setPositions(positions);
  6700. });
  6701. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6702. var normals = new Float32Array(data.length);
  6703. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6704. normals[index] = data[index] + value;
  6705. });
  6706. babylonMorphTarget.setNormals(normals);
  6707. });
  6708. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6709. var tangents = new Float32Array(data.length / 3 * 4);
  6710. var dataIndex = 0;
  6711. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6712. // Tangent data for morph targets is stored as xyz delta.
  6713. // The vertexData.tangent is stored as xyzw.
  6714. // So we need to skip every fourth vertexData.tangent.
  6715. if (((index + 1) % 4) !== 0) {
  6716. tangents[dataIndex] = data[dataIndex] + value;
  6717. dataIndex++;
  6718. }
  6719. });
  6720. babylonMorphTarget.setTangents(tangents);
  6721. });
  6722. return Promise.all(promises).then(function () { });
  6723. };
  6724. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6725. // Ignore the TRS of skinned nodes.
  6726. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6727. if (node.skin != undefined) {
  6728. return;
  6729. }
  6730. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6731. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6732. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6733. if (node.matrix) {
  6734. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6735. matrix.decompose(scaling, rotation, position);
  6736. }
  6737. else {
  6738. if (node.translation) {
  6739. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6740. }
  6741. if (node.rotation) {
  6742. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6743. }
  6744. if (node.scale) {
  6745. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6746. }
  6747. }
  6748. babylonNode.position = position;
  6749. babylonNode.rotationQuaternion = rotation;
  6750. babylonNode.scaling = scaling;
  6751. };
  6752. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6753. var _this = this;
  6754. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6755. if (extensionPromise) {
  6756. return extensionPromise;
  6757. }
  6758. var assignSkeleton = function (skeleton) {
  6759. _this._forEachPrimitive(node, function (babylonMesh) {
  6760. babylonMesh.skeleton = skeleton;
  6761. });
  6762. };
  6763. if (skin._data) {
  6764. assignSkeleton(skin._data.babylonSkeleton);
  6765. return skin._data.promise;
  6766. }
  6767. var skeletonId = "skeleton" + skin.index;
  6768. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6769. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6770. this._babylonScene._blockEntityCollection = false;
  6771. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6772. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6773. this._loadBones(context, skin, babylonSkeleton);
  6774. assignSkeleton(babylonSkeleton);
  6775. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6776. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6777. });
  6778. skin._data = {
  6779. babylonSkeleton: babylonSkeleton,
  6780. promise: promise
  6781. };
  6782. return promise;
  6783. };
  6784. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6785. var babylonBones = {};
  6786. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6787. var index = _a[_i];
  6788. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6789. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6790. }
  6791. };
  6792. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6793. var babylonBone = babylonBones[node.index];
  6794. if (babylonBone) {
  6795. return babylonBone;
  6796. }
  6797. var babylonParentBone = null;
  6798. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6799. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6800. }
  6801. var boneIndex = skin.joints.indexOf(node.index);
  6802. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6803. babylonBones[node.index] = babylonBone;
  6804. node._babylonBones = node._babylonBones || [];
  6805. node._babylonBones.push(babylonBone);
  6806. return babylonBone;
  6807. };
  6808. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6809. if (skin.inverseBindMatrices == undefined) {
  6810. return Promise.resolve(null);
  6811. }
  6812. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6813. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6814. };
  6815. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6816. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6817. var babylonBone = _a[_i];
  6818. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6819. var boneIndex = babylonBone._index;
  6820. if (inverseBindMatricesData && boneIndex !== -1) {
  6821. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6822. baseMatrix.invertToRef(baseMatrix);
  6823. }
  6824. var babylonParentBone = babylonBone.getParent();
  6825. if (babylonParentBone) {
  6826. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6827. }
  6828. babylonBone.updateMatrix(baseMatrix, false, false);
  6829. babylonBone._updateDifferenceMatrix(undefined, false);
  6830. }
  6831. };
  6832. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6833. return node.matrix ?
  6834. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6835. 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());
  6836. };
  6837. /**
  6838. * Loads a glTF camera.
  6839. * @param context The context when loading the asset
  6840. * @param camera The glTF camera property
  6841. * @param assign A function called synchronously after parsing the glTF properties
  6842. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6843. */
  6844. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6845. if (assign === void 0) { assign = function () { }; }
  6846. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6847. if (extensionPromise) {
  6848. return extensionPromise;
  6849. }
  6850. var promises = new Array();
  6851. this.logOpen(context + " " + (camera.name || ""));
  6852. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6853. 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);
  6854. this._babylonScene._blockEntityCollection = false;
  6855. babylonCamera.ignoreParentScaling = true;
  6856. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6857. switch (camera.type) {
  6858. case "perspective" /* PERSPECTIVE */: {
  6859. var perspective = camera.perspective;
  6860. if (!perspective) {
  6861. throw new Error(context + ": Camera perspective properties are missing");
  6862. }
  6863. babylonCamera.fov = perspective.yfov;
  6864. babylonCamera.minZ = perspective.znear;
  6865. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6866. break;
  6867. }
  6868. case "orthographic" /* ORTHOGRAPHIC */: {
  6869. if (!camera.orthographic) {
  6870. throw new Error(context + ": Camera orthographic properties are missing");
  6871. }
  6872. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6873. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6874. babylonCamera.orthoRight = camera.orthographic.xmag;
  6875. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6876. babylonCamera.orthoTop = camera.orthographic.ymag;
  6877. babylonCamera.minZ = camera.orthographic.znear;
  6878. babylonCamera.maxZ = camera.orthographic.zfar;
  6879. break;
  6880. }
  6881. default: {
  6882. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6883. }
  6884. }
  6885. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6886. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6887. assign(babylonCamera);
  6888. this.logClose();
  6889. return Promise.all(promises).then(function () {
  6890. return babylonCamera;
  6891. });
  6892. };
  6893. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6894. var animations = this._gltf.animations;
  6895. if (!animations) {
  6896. return Promise.resolve();
  6897. }
  6898. var promises = new Array();
  6899. for (var index = 0; index < animations.length; index++) {
  6900. var animation = animations[index];
  6901. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6902. }
  6903. return Promise.all(promises).then(function () { });
  6904. };
  6905. /**
  6906. * Loads a glTF animation.
  6907. * @param context The context when loading the asset
  6908. * @param animation The glTF animation property
  6909. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6910. */
  6911. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6912. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6913. if (promise) {
  6914. return promise;
  6915. }
  6916. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6917. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6918. this._babylonScene._blockEntityCollection = false;
  6919. animation._babylonAnimationGroup = babylonAnimationGroup;
  6920. var promises = new Array();
  6921. ArrayItem.Assign(animation.channels);
  6922. ArrayItem.Assign(animation.samplers);
  6923. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6924. var channel = _a[_i];
  6925. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6926. }
  6927. return Promise.all(promises).then(function () {
  6928. babylonAnimationGroup.normalize(0);
  6929. return babylonAnimationGroup;
  6930. });
  6931. };
  6932. /**
  6933. * @hidden Loads a glTF animation channel.
  6934. * @param context The context when loading the asset
  6935. * @param animationContext The context of the animation when loading the asset
  6936. * @param animation The glTF animation property
  6937. * @param channel The glTF animation channel property
  6938. * @param babylonAnimationGroup The babylon animation group property
  6939. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6940. * @returns A void promise when the channel load is complete
  6941. */
  6942. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6943. var _this = this;
  6944. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6945. if (channel.target.node == undefined) {
  6946. return Promise.resolve();
  6947. }
  6948. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6949. // Ignore animations that have no animation targets.
  6950. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6951. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6952. return Promise.resolve();
  6953. }
  6954. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6955. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6956. var targetPath;
  6957. var animationType;
  6958. switch (channel.target.path) {
  6959. case "translation" /* TRANSLATION */: {
  6960. targetPath = "position";
  6961. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6962. break;
  6963. }
  6964. case "rotation" /* ROTATION */: {
  6965. targetPath = "rotationQuaternion";
  6966. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  6967. break;
  6968. }
  6969. case "scale" /* SCALE */: {
  6970. targetPath = "scaling";
  6971. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6972. break;
  6973. }
  6974. case "weights" /* WEIGHTS */: {
  6975. targetPath = "influence";
  6976. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  6977. break;
  6978. }
  6979. default: {
  6980. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  6981. }
  6982. }
  6983. var outputBufferOffset = 0;
  6984. var getNextOutputValue;
  6985. switch (targetPath) {
  6986. case "position": {
  6987. getNextOutputValue = function () {
  6988. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6989. outputBufferOffset += 3;
  6990. return value;
  6991. };
  6992. break;
  6993. }
  6994. case "rotationQuaternion": {
  6995. getNextOutputValue = function () {
  6996. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  6997. outputBufferOffset += 4;
  6998. return value;
  6999. };
  7000. break;
  7001. }
  7002. case "scaling": {
  7003. getNextOutputValue = function () {
  7004. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7005. outputBufferOffset += 3;
  7006. return value;
  7007. };
  7008. break;
  7009. }
  7010. case "influence": {
  7011. getNextOutputValue = function () {
  7012. var value = new Array(targetNode._numMorphTargets);
  7013. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  7014. value[i] = data.output[outputBufferOffset++];
  7015. }
  7016. return value;
  7017. };
  7018. break;
  7019. }
  7020. }
  7021. var getNextKey;
  7022. switch (data.interpolation) {
  7023. case "STEP" /* STEP */: {
  7024. getNextKey = function (frameIndex) { return ({
  7025. frame: data.input[frameIndex],
  7026. value: getNextOutputValue(),
  7027. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  7028. }); };
  7029. break;
  7030. }
  7031. case "LINEAR" /* LINEAR */: {
  7032. getNextKey = function (frameIndex) { return ({
  7033. frame: data.input[frameIndex],
  7034. value: getNextOutputValue()
  7035. }); };
  7036. break;
  7037. }
  7038. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7039. getNextKey = function (frameIndex) { return ({
  7040. frame: data.input[frameIndex],
  7041. inTangent: getNextOutputValue(),
  7042. value: getNextOutputValue(),
  7043. outTangent: getNextOutputValue()
  7044. }); };
  7045. break;
  7046. }
  7047. }
  7048. var keys = new Array(data.input.length);
  7049. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  7050. keys[frameIndex] = getNextKey(frameIndex);
  7051. }
  7052. if (targetPath === "influence") {
  7053. var _loop_2 = function (targetIndex) {
  7054. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7055. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7056. babylonAnimation.setKeys(keys.map(function (key) { return ({
  7057. frame: key.frame,
  7058. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  7059. value: key.value[targetIndex],
  7060. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  7061. }); }));
  7062. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  7063. var babylonMesh = babylonAbstractMesh;
  7064. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  7065. var babylonAnimationClone = babylonAnimation.clone();
  7066. morphTarget.animations.push(babylonAnimationClone);
  7067. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  7068. });
  7069. };
  7070. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  7071. _loop_2(targetIndex);
  7072. }
  7073. }
  7074. else {
  7075. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7076. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7077. babylonAnimation.setKeys(keys);
  7078. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  7079. animationTargetOverride.animations.push(babylonAnimation);
  7080. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  7081. }
  7082. else {
  7083. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  7084. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  7085. }
  7086. }
  7087. });
  7088. };
  7089. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  7090. if (sampler._data) {
  7091. return sampler._data;
  7092. }
  7093. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  7094. switch (interpolation) {
  7095. case "STEP" /* STEP */:
  7096. case "LINEAR" /* LINEAR */:
  7097. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7098. break;
  7099. }
  7100. default: {
  7101. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  7102. }
  7103. }
  7104. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  7105. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  7106. sampler._data = Promise.all([
  7107. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  7108. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  7109. ]).then(function (_a) {
  7110. var inputData = _a[0], outputData = _a[1];
  7111. return {
  7112. input: inputData,
  7113. interpolation: interpolation,
  7114. output: outputData,
  7115. };
  7116. });
  7117. return sampler._data;
  7118. };
  7119. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7120. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  7121. if (extensionPromise) {
  7122. return extensionPromise;
  7123. }
  7124. if (!buffer._data) {
  7125. if (buffer.uri) {
  7126. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  7127. }
  7128. else {
  7129. if (!this._bin) {
  7130. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  7131. }
  7132. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  7133. }
  7134. }
  7135. return buffer._data.then(function (data) {
  7136. try {
  7137. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  7138. }
  7139. catch (e) {
  7140. throw new Error(context + ": " + e.message);
  7141. }
  7142. });
  7143. };
  7144. /**
  7145. * Loads a glTF buffer view.
  7146. * @param context The context when loading the asset
  7147. * @param bufferView The glTF buffer view property
  7148. * @returns A promise that resolves with the loaded data when the load is complete
  7149. */
  7150. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  7151. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  7152. if (extensionPromise) {
  7153. return extensionPromise;
  7154. }
  7155. if (bufferView._data) {
  7156. return bufferView._data;
  7157. }
  7158. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  7159. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  7160. return bufferView._data;
  7161. };
  7162. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  7163. var _this = this;
  7164. if (accessor._data) {
  7165. return accessor._data;
  7166. }
  7167. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  7168. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  7169. var length = numComponents * accessor.count;
  7170. if (accessor.bufferView == undefined) {
  7171. accessor._data = Promise.resolve(new constructor(length));
  7172. }
  7173. else {
  7174. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7175. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  7176. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  7177. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  7178. }
  7179. else {
  7180. var typedArray_1 = new constructor(length);
  7181. 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) {
  7182. typedArray_1[index] = value;
  7183. });
  7184. return typedArray_1;
  7185. }
  7186. });
  7187. }
  7188. if (accessor.sparse) {
  7189. var sparse_1 = accessor.sparse;
  7190. accessor._data = accessor._data.then(function (data) {
  7191. var typedArray = data;
  7192. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  7193. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  7194. return Promise.all([
  7195. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  7196. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  7197. ]).then(function (_a) {
  7198. var indicesData = _a[0], valuesData = _a[1];
  7199. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  7200. var sparseLength = numComponents * sparse_1.count;
  7201. var values;
  7202. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  7203. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7204. }
  7205. else {
  7206. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7207. values = new constructor(sparseLength);
  7208. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  7209. values[index] = value;
  7210. });
  7211. }
  7212. var valuesIndex = 0;
  7213. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  7214. var dataIndex = indices[indicesIndex] * numComponents;
  7215. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  7216. typedArray[dataIndex++] = values[valuesIndex++];
  7217. }
  7218. }
  7219. return typedArray;
  7220. });
  7221. });
  7222. }
  7223. return accessor._data;
  7224. };
  7225. /** @hidden */
  7226. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  7227. return this._loadAccessorAsync(context, accessor, Float32Array);
  7228. };
  7229. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  7230. if (accessor.type !== "SCALAR" /* SCALAR */) {
  7231. throw new Error(context + "/type: Invalid value " + accessor.type);
  7232. }
  7233. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  7234. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  7235. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  7236. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  7237. }
  7238. if (accessor._data) {
  7239. return accessor._data;
  7240. }
  7241. if (accessor.sparse) {
  7242. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  7243. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  7244. }
  7245. else {
  7246. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7247. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7248. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  7249. });
  7250. }
  7251. return accessor._data;
  7252. };
  7253. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  7254. var _this = this;
  7255. if (bufferView._babylonBuffer) {
  7256. return bufferView._babylonBuffer;
  7257. }
  7258. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7259. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  7260. });
  7261. return bufferView._babylonBuffer;
  7262. };
  7263. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  7264. var _this = this;
  7265. if (accessor._babylonVertexBuffer) {
  7266. return accessor._babylonVertexBuffer;
  7267. }
  7268. if (accessor.sparse) {
  7269. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7270. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7271. });
  7272. }
  7273. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  7274. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  7275. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  7276. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7277. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7278. });
  7279. }
  7280. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  7281. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  7282. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  7283. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7284. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7285. });
  7286. }
  7287. else {
  7288. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7289. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  7290. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  7291. 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);
  7292. });
  7293. }
  7294. return accessor._babylonVertexBuffer;
  7295. };
  7296. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  7297. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7298. throw new Error(context + ": Material type not supported");
  7299. }
  7300. var promises = new Array();
  7301. if (properties) {
  7302. if (properties.baseColorFactor) {
  7303. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  7304. babylonMaterial.alpha = properties.baseColorFactor[3];
  7305. }
  7306. else {
  7307. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  7308. }
  7309. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  7310. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  7311. if (properties.baseColorTexture) {
  7312. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  7313. texture.name = babylonMaterial.name + " (Base Color)";
  7314. babylonMaterial.albedoTexture = texture;
  7315. }));
  7316. }
  7317. if (properties.metallicRoughnessTexture) {
  7318. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  7319. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  7320. babylonMaterial.metallicTexture = texture;
  7321. }));
  7322. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  7323. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  7324. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  7325. }
  7326. }
  7327. return Promise.all(promises).then(function () { });
  7328. };
  7329. /** @hidden */
  7330. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7331. if (assign === void 0) { assign = function () { }; }
  7332. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  7333. if (extensionPromise) {
  7334. return extensionPromise;
  7335. }
  7336. material._data = material._data || {};
  7337. var babylonData = material._data[babylonDrawMode];
  7338. if (!babylonData) {
  7339. this.logOpen(context + " " + (material.name || ""));
  7340. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  7341. babylonData = {
  7342. babylonMaterial: babylonMaterial,
  7343. babylonMeshes: [],
  7344. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  7345. };
  7346. material._data[babylonDrawMode] = babylonData;
  7347. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  7348. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7349. this.logClose();
  7350. }
  7351. babylonData.babylonMeshes.push(babylonMesh);
  7352. babylonMesh.onDisposeObservable.addOnce(function () {
  7353. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  7354. if (index !== -1) {
  7355. babylonData.babylonMeshes.splice(index, 1);
  7356. }
  7357. });
  7358. assign(babylonData.babylonMaterial);
  7359. return babylonData.promise.then(function () {
  7360. return babylonData.babylonMaterial;
  7361. });
  7362. };
  7363. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  7364. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7365. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  7366. this._babylonScene._blockEntityCollection = false;
  7367. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  7368. babylonMaterial.fillMode = babylonDrawMode;
  7369. babylonMaterial.enableSpecularAntiAliasing = true;
  7370. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  7371. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  7372. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7373. babylonMaterial.metallic = 1;
  7374. babylonMaterial.roughness = 1;
  7375. return babylonMaterial;
  7376. };
  7377. /**
  7378. * Creates a Babylon material from a glTF material.
  7379. * @param context The context when loading the asset
  7380. * @param material The glTF material property
  7381. * @param babylonDrawMode The draw mode for the Babylon material
  7382. * @returns The Babylon material
  7383. */
  7384. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  7385. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  7386. if (extensionPromise) {
  7387. return extensionPromise;
  7388. }
  7389. var name = material.name || "material" + material.index;
  7390. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  7391. return babylonMaterial;
  7392. };
  7393. /**
  7394. * Loads properties from a glTF material into a Babylon material.
  7395. * @param context The context when loading the asset
  7396. * @param material The glTF material property
  7397. * @param babylonMaterial The Babylon material
  7398. * @returns A promise that resolves when the load is complete
  7399. */
  7400. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7401. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  7402. if (extensionPromise) {
  7403. return extensionPromise;
  7404. }
  7405. var promises = new Array();
  7406. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  7407. if (material.pbrMetallicRoughness) {
  7408. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  7409. }
  7410. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  7411. return Promise.all(promises).then(function () { });
  7412. };
  7413. /**
  7414. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  7415. * @param context The context when loading the asset
  7416. * @param material The glTF material property
  7417. * @param babylonMaterial The Babylon material
  7418. * @returns A promise that resolves when the load is complete
  7419. */
  7420. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  7421. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7422. throw new Error(context + ": Material type not supported");
  7423. }
  7424. var promises = new Array();
  7425. 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);
  7426. if (material.doubleSided) {
  7427. babylonMaterial.backFaceCulling = false;
  7428. babylonMaterial.twoSidedLighting = true;
  7429. }
  7430. if (material.normalTexture) {
  7431. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  7432. texture.name = babylonMaterial.name + " (Normal)";
  7433. babylonMaterial.bumpTexture = texture;
  7434. }));
  7435. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  7436. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  7437. if (material.normalTexture.scale != undefined) {
  7438. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  7439. }
  7440. babylonMaterial.forceIrradianceInFragment = true;
  7441. }
  7442. if (material.occlusionTexture) {
  7443. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  7444. texture.name = babylonMaterial.name + " (Occlusion)";
  7445. babylonMaterial.ambientTexture = texture;
  7446. }));
  7447. babylonMaterial.useAmbientInGrayScale = true;
  7448. if (material.occlusionTexture.strength != undefined) {
  7449. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  7450. }
  7451. }
  7452. if (material.emissiveTexture) {
  7453. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  7454. texture.name = babylonMaterial.name + " (Emissive)";
  7455. babylonMaterial.emissiveTexture = texture;
  7456. }));
  7457. }
  7458. return Promise.all(promises).then(function () { });
  7459. };
  7460. /**
  7461. * Loads the alpha properties from a glTF material into a Babylon material.
  7462. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  7463. * @param context The context when loading the asset
  7464. * @param material The glTF material property
  7465. * @param babylonMaterial The Babylon material
  7466. */
  7467. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  7468. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7469. throw new Error(context + ": Material type not supported");
  7470. }
  7471. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  7472. switch (alphaMode) {
  7473. case "OPAQUE" /* OPAQUE */: {
  7474. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7475. break;
  7476. }
  7477. case "MASK" /* MASK */: {
  7478. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  7479. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  7480. if (babylonMaterial.albedoTexture) {
  7481. babylonMaterial.albedoTexture.hasAlpha = true;
  7482. }
  7483. break;
  7484. }
  7485. case "BLEND" /* BLEND */: {
  7486. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  7487. if (babylonMaterial.albedoTexture) {
  7488. babylonMaterial.albedoTexture.hasAlpha = true;
  7489. babylonMaterial.useAlphaFromAlbedoTexture = true;
  7490. }
  7491. break;
  7492. }
  7493. default: {
  7494. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  7495. }
  7496. }
  7497. };
  7498. /**
  7499. * Loads a glTF texture info.
  7500. * @param context The context when loading the asset
  7501. * @param textureInfo The glTF texture info property
  7502. * @param assign A function called synchronously after parsing the glTF properties
  7503. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  7504. */
  7505. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  7506. var _this = this;
  7507. if (assign === void 0) { assign = function () { }; }
  7508. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  7509. if (extensionPromise) {
  7510. return extensionPromise;
  7511. }
  7512. this.logOpen("" + context);
  7513. if (textureInfo.texCoord >= 2) {
  7514. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  7515. }
  7516. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  7517. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  7518. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  7519. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  7520. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  7521. assign(babylonTexture);
  7522. });
  7523. this.logClose();
  7524. return promise;
  7525. };
  7526. /** @hidden */
  7527. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  7528. if (assign === void 0) { assign = function () { }; }
  7529. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  7530. if (extensionPromise) {
  7531. return extensionPromise;
  7532. }
  7533. this.logOpen(context + " " + (texture.name || ""));
  7534. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  7535. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  7536. var promise = this._createTextureAsync(context, sampler, image, assign);
  7537. this.logClose();
  7538. return promise;
  7539. };
  7540. /** @hidden */
  7541. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign) {
  7542. var _this = this;
  7543. if (assign === void 0) { assign = function () { }; }
  7544. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  7545. var promises = new Array();
  7546. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  7547. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7548. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  7549. if (!_this._disposed) {
  7550. deferred.resolve();
  7551. }
  7552. }, function (message, exception) {
  7553. if (!_this._disposed) {
  7554. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  7555. }
  7556. }, undefined, undefined, undefined, image.mimeType);
  7557. this._babylonScene._blockEntityCollection = false;
  7558. promises.push(deferred.promise);
  7559. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  7560. var name = image.uri || _this._fileName + "#image" + image.index;
  7561. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  7562. babylonTexture.updateURL(dataUrl, data);
  7563. }));
  7564. babylonTexture.wrapU = samplerData.wrapU;
  7565. babylonTexture.wrapV = samplerData.wrapV;
  7566. assign(babylonTexture);
  7567. return Promise.all(promises).then(function () {
  7568. return babylonTexture;
  7569. });
  7570. };
  7571. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  7572. if (!sampler._data) {
  7573. sampler._data = {
  7574. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  7575. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  7576. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  7577. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  7578. };
  7579. }
  7580. return sampler._data;
  7581. };
  7582. /**
  7583. * Loads a glTF image.
  7584. * @param context The context when loading the asset
  7585. * @param image The glTF image property
  7586. * @returns A promise that resolves with the loaded data when the load is complete
  7587. */
  7588. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  7589. if (!image._data) {
  7590. this.logOpen(context + " " + (image.name || ""));
  7591. if (image.uri) {
  7592. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  7593. }
  7594. else {
  7595. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  7596. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  7597. }
  7598. this.logClose();
  7599. }
  7600. return image._data;
  7601. };
  7602. /**
  7603. * Loads a glTF uri.
  7604. * @param context The context when loading the asset
  7605. * @param property The glTF property associated with the uri
  7606. * @param uri The base64 or relative uri
  7607. * @returns A promise that resolves with the loaded data when the load is complete
  7608. */
  7609. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  7610. var _this = this;
  7611. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  7612. if (extensionPromise) {
  7613. return extensionPromise;
  7614. }
  7615. if (!GLTFLoader._ValidateUri(uri)) {
  7616. throw new Error(context + ": '" + uri + "' is invalid");
  7617. }
  7618. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7619. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7620. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7621. return Promise.resolve(data);
  7622. }
  7623. this.log("Loading " + uri);
  7624. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7625. return new Promise(function (resolve, reject) {
  7626. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  7627. if (!_this._disposed) {
  7628. _this.log("Loaded " + uri + " (" + data.byteLength + " bytes)");
  7629. resolve(new Uint8Array(data));
  7630. }
  7631. }, true, function (request) {
  7632. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7633. });
  7634. });
  7635. });
  7636. };
  7637. /**
  7638. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7639. * @param babylonObject the Babylon object with metadata
  7640. * @param pointer the JSON pointer
  7641. */
  7642. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7643. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7644. var gltf = (metadata.gltf = metadata.gltf || {});
  7645. var pointers = (gltf.pointers = gltf.pointers || []);
  7646. pointers.push(pointer);
  7647. };
  7648. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7649. // Set defaults if undefined
  7650. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7651. switch (mode) {
  7652. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7653. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7654. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7655. default:
  7656. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7657. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7658. }
  7659. };
  7660. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7661. // Set defaults if undefined
  7662. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7663. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7664. if (magFilter === 9729 /* LINEAR */) {
  7665. switch (minFilter) {
  7666. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7667. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7668. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7669. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7670. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7671. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7672. default:
  7673. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7674. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7675. }
  7676. }
  7677. else {
  7678. if (magFilter !== 9728 /* NEAREST */) {
  7679. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7680. }
  7681. switch (minFilter) {
  7682. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7683. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7684. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7685. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7686. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7687. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7688. default:
  7689. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7690. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7691. }
  7692. }
  7693. };
  7694. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7695. switch (componentType) {
  7696. case 5120 /* BYTE */: return Int8Array;
  7697. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7698. case 5122 /* SHORT */: return Int16Array;
  7699. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7700. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7701. case 5126 /* FLOAT */: return Float32Array;
  7702. default: throw new Error(context + ": Invalid component type " + componentType);
  7703. }
  7704. };
  7705. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7706. var buffer = bufferView.buffer;
  7707. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7708. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7709. try {
  7710. return new constructor(buffer, byteOffset, length);
  7711. }
  7712. catch (e) {
  7713. throw new Error(context + ": " + e);
  7714. }
  7715. };
  7716. GLTFLoader._GetNumComponents = function (context, type) {
  7717. switch (type) {
  7718. case "SCALAR": return 1;
  7719. case "VEC2": return 2;
  7720. case "VEC3": return 3;
  7721. case "VEC4": return 4;
  7722. case "MAT2": return 4;
  7723. case "MAT3": return 9;
  7724. case "MAT4": return 16;
  7725. }
  7726. throw new Error(context + ": Invalid type (" + type + ")");
  7727. };
  7728. GLTFLoader._ValidateUri = function (uri) {
  7729. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7730. };
  7731. /** @hidden */
  7732. GLTFLoader._GetDrawMode = function (context, mode) {
  7733. if (mode == undefined) {
  7734. mode = 4 /* TRIANGLES */;
  7735. }
  7736. switch (mode) {
  7737. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7738. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7739. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7740. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7741. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7742. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7743. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7744. }
  7745. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7746. };
  7747. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7748. var _this = this;
  7749. this._parent._startPerformanceCounter("Compile materials");
  7750. var promises = new Array();
  7751. if (this._gltf.materials) {
  7752. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7753. var material = _a[_i];
  7754. if (material._data) {
  7755. for (var babylonDrawMode in material._data) {
  7756. var babylonData = material._data[babylonDrawMode];
  7757. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7758. var babylonMesh = _c[_b];
  7759. // Ensure nonUniformScaling is set if necessary.
  7760. babylonMesh.computeWorldMatrix(true);
  7761. var babylonMaterial = babylonData.babylonMaterial;
  7762. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7763. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7764. if (this._parent.useClipPlane) {
  7765. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7766. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7767. }
  7768. }
  7769. }
  7770. }
  7771. }
  7772. }
  7773. return Promise.all(promises).then(function () {
  7774. _this._parent._endPerformanceCounter("Compile materials");
  7775. });
  7776. };
  7777. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7778. var _this = this;
  7779. this._parent._startPerformanceCounter("Compile shadow generators");
  7780. var promises = new Array();
  7781. var lights = this._babylonScene.lights;
  7782. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7783. var light = lights_1[_i];
  7784. var generator = light.getShadowGenerator();
  7785. if (generator) {
  7786. promises.push(generator.forceCompilationAsync());
  7787. }
  7788. }
  7789. return Promise.all(promises).then(function () {
  7790. _this._parent._endPerformanceCounter("Compile shadow generators");
  7791. });
  7792. };
  7793. GLTFLoader.prototype._forEachExtensions = function (action) {
  7794. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7795. var extension = _a[_i];
  7796. if (extension.enabled) {
  7797. action(extension);
  7798. }
  7799. }
  7800. };
  7801. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7802. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7803. var extension = _a[_i];
  7804. if (extension.enabled) {
  7805. var id = extension.name + "." + functionName;
  7806. var loaderProperty = property;
  7807. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7808. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7809. if (!activeLoaderExtensionFunctions[id]) {
  7810. activeLoaderExtensionFunctions[id] = true;
  7811. try {
  7812. var result = actionAsync(extension);
  7813. if (result) {
  7814. return result;
  7815. }
  7816. }
  7817. finally {
  7818. delete activeLoaderExtensionFunctions[id];
  7819. }
  7820. }
  7821. }
  7822. }
  7823. return null;
  7824. };
  7825. GLTFLoader.prototype._extensionsOnLoading = function () {
  7826. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7827. };
  7828. GLTFLoader.prototype._extensionsOnReady = function () {
  7829. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7830. };
  7831. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7832. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7833. };
  7834. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7835. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7836. };
  7837. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7838. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7839. };
  7840. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7841. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7842. };
  7843. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7844. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7845. };
  7846. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7847. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7848. };
  7849. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7850. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7851. };
  7852. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7853. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7854. };
  7855. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7856. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7857. };
  7858. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  7859. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  7860. };
  7861. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7862. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7863. };
  7864. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7865. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7866. };
  7867. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7868. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7869. };
  7870. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7871. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7872. };
  7873. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7874. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7875. };
  7876. /**
  7877. * Helper method called by a loader extension to load an glTF extension.
  7878. * @param context The context when loading the asset
  7879. * @param property The glTF property to load the extension from
  7880. * @param extensionName The name of the extension to load
  7881. * @param actionAsync The action to run
  7882. * @returns The promise returned by actionAsync or null if the extension does not exist
  7883. */
  7884. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7885. if (!property.extensions) {
  7886. return null;
  7887. }
  7888. var extensions = property.extensions;
  7889. var extension = extensions[extensionName];
  7890. if (!extension) {
  7891. return null;
  7892. }
  7893. return actionAsync(context + "/extensions/" + extensionName, extension);
  7894. };
  7895. /**
  7896. * Helper method called by a loader extension to load a glTF extra.
  7897. * @param context The context when loading the asset
  7898. * @param property The glTF property to load the extra from
  7899. * @param extensionName The name of the extension to load
  7900. * @param actionAsync The action to run
  7901. * @returns The promise returned by actionAsync or null if the extra does not exist
  7902. */
  7903. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7904. if (!property.extras) {
  7905. return null;
  7906. }
  7907. var extras = property.extras;
  7908. var extra = extras[extensionName];
  7909. if (!extra) {
  7910. return null;
  7911. }
  7912. return actionAsync(context + "/extras/" + extensionName, extra);
  7913. };
  7914. /**
  7915. * Checks for presence of an extension.
  7916. * @param name The name of the extension to check
  7917. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7918. */
  7919. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7920. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7921. };
  7922. /**
  7923. * Increments the indentation level and logs a message.
  7924. * @param message The message to log
  7925. */
  7926. GLTFLoader.prototype.logOpen = function (message) {
  7927. this._parent._logOpen(message);
  7928. };
  7929. /**
  7930. * Decrements the indentation level.
  7931. */
  7932. GLTFLoader.prototype.logClose = function () {
  7933. this._parent._logClose();
  7934. };
  7935. /**
  7936. * Logs a message
  7937. * @param message The message to log
  7938. */
  7939. GLTFLoader.prototype.log = function (message) {
  7940. this._parent._log(message);
  7941. };
  7942. /**
  7943. * Starts a performance counter.
  7944. * @param counterName The name of the performance counter
  7945. */
  7946. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7947. this._parent._startPerformanceCounter(counterName);
  7948. };
  7949. /**
  7950. * Ends a performance counter.
  7951. * @param counterName The name of the performance counter
  7952. */
  7953. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7954. this._parent._endPerformanceCounter(counterName);
  7955. };
  7956. GLTFLoader._RegisteredExtensions = {};
  7957. /**
  7958. * The default glTF sampler.
  7959. */
  7960. GLTFLoader.DefaultSampler = { index: -1 };
  7961. return GLTFLoader;
  7962. }());
  7963. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  7964. /***/ }),
  7965. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  7966. /*!******************************************!*\
  7967. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  7968. \******************************************/
  7969. /*! no static exports found */
  7970. /***/ (function(module, exports) {
  7971. /***/ }),
  7972. /***/ "./glTF/2.0/index.ts":
  7973. /*!***************************!*\
  7974. !*** ./glTF/2.0/index.ts ***!
  7975. \***************************/
  7976. /*! 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 */
  7977. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7978. "use strict";
  7979. __webpack_require__.r(__webpack_exports__);
  7980. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  7981. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  7982. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  7983. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  7984. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  7985. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  7986. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  7987. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  7988. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  7989. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  7990. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  7991. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  7992. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  7993. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_ior"]; });
  7994. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_variants"]; });
  7995. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_transmission"]; });
  7996. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  7997. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_basisu"]; });
  7998. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  7999. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_xmp"]; });
  8000. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  8001. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  8002. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  8003. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  8004. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  8005. /***/ }),
  8006. /***/ "./glTF/glTFFileLoader.ts":
  8007. /*!********************************!*\
  8008. !*** ./glTF/glTFFileLoader.ts ***!
  8009. \********************************/
  8010. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  8011. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8012. "use strict";
  8013. __webpack_require__.r(__webpack_exports__);
  8014. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  8015. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  8016. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  8017. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  8018. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  8019. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  8020. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8021. /**
  8022. * Mode that determines the coordinate system to use.
  8023. */
  8024. var GLTFLoaderCoordinateSystemMode;
  8025. (function (GLTFLoaderCoordinateSystemMode) {
  8026. /**
  8027. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8028. */
  8029. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  8030. /**
  8031. * Sets the useRightHandedSystem flag on the scene.
  8032. */
  8033. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  8034. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  8035. /**
  8036. * Mode that determines what animations will start.
  8037. */
  8038. var GLTFLoaderAnimationStartMode;
  8039. (function (GLTFLoaderAnimationStartMode) {
  8040. /**
  8041. * No animation will start.
  8042. */
  8043. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  8044. /**
  8045. * The first animation will start.
  8046. */
  8047. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  8048. /**
  8049. * All animations will start.
  8050. */
  8051. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  8052. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  8053. /**
  8054. * Loader state.
  8055. */
  8056. var GLTFLoaderState;
  8057. (function (GLTFLoaderState) {
  8058. /**
  8059. * The asset is loading.
  8060. */
  8061. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  8062. /**
  8063. * The asset is ready for rendering.
  8064. */
  8065. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  8066. /**
  8067. * The asset is completely loaded.
  8068. */
  8069. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  8070. })(GLTFLoaderState || (GLTFLoaderState = {}));
  8071. /**
  8072. * File loader for loading glTF files into a scene.
  8073. */
  8074. var GLTFFileLoader = /** @class */ (function () {
  8075. function GLTFFileLoader() {
  8076. // --------------
  8077. // Common options
  8078. // --------------
  8079. /**
  8080. * Raised when the asset has been parsed
  8081. */
  8082. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8083. // ----------
  8084. // V2 options
  8085. // ----------
  8086. /**
  8087. * The coordinate system mode. Defaults to AUTO.
  8088. */
  8089. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  8090. /**
  8091. * The animation start mode. Defaults to FIRST.
  8092. */
  8093. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  8094. /**
  8095. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  8096. */
  8097. this.compileMaterials = false;
  8098. /**
  8099. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  8100. */
  8101. this.useClipPlane = false;
  8102. /**
  8103. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  8104. */
  8105. this.compileShadowGenerators = false;
  8106. /**
  8107. * Defines if the Alpha blended materials are only applied as coverage.
  8108. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  8109. * If true, no extra effects are applied to transparent pixels.
  8110. */
  8111. this.transparencyAsCoverage = false;
  8112. /**
  8113. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  8114. * Enabling will disable offline support and glTF validator.
  8115. * Defaults to false.
  8116. */
  8117. this.useRangeRequests = false;
  8118. /**
  8119. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  8120. */
  8121. this.createInstances = true;
  8122. /**
  8123. * Function called before loading a url referenced by the asset.
  8124. */
  8125. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8126. /**
  8127. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8128. */
  8129. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8130. /**
  8131. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  8132. */
  8133. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8134. /**
  8135. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  8136. */
  8137. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8138. /**
  8139. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  8140. */
  8141. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8142. /**
  8143. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  8144. * For assets with LODs, raised when all of the LODs are complete.
  8145. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8146. */
  8147. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8148. /**
  8149. * Observable raised when an error occurs.
  8150. */
  8151. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8152. /**
  8153. * Observable raised after the loader is disposed.
  8154. */
  8155. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8156. /**
  8157. * Observable raised after a loader extension is created.
  8158. * Set additional options for a loader extension in this event.
  8159. */
  8160. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8161. /**
  8162. * Defines if the loader should validate the asset.
  8163. */
  8164. this.validate = false;
  8165. /**
  8166. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  8167. */
  8168. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8169. this._loader = null;
  8170. this._requests = new Array();
  8171. /**
  8172. * Name of the loader ("gltf")
  8173. */
  8174. this.name = "gltf";
  8175. /** @hidden */
  8176. this.extensions = {
  8177. ".gltf": { isBinary: false },
  8178. ".glb": { isBinary: true }
  8179. };
  8180. this._logIndentLevel = 0;
  8181. this._loggingEnabled = false;
  8182. /** @hidden */
  8183. this._log = this._logDisabled;
  8184. this._capturePerformanceCounters = false;
  8185. /** @hidden */
  8186. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8187. /** @hidden */
  8188. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8189. }
  8190. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  8191. /**
  8192. * Raised when the asset has been parsed
  8193. */
  8194. set: function (callback) {
  8195. if (this._onParsedObserver) {
  8196. this.onParsedObservable.remove(this._onParsedObserver);
  8197. }
  8198. this._onParsedObserver = this.onParsedObservable.add(callback);
  8199. },
  8200. enumerable: true,
  8201. configurable: true
  8202. });
  8203. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  8204. /**
  8205. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8206. */
  8207. set: function (callback) {
  8208. if (this._onMeshLoadedObserver) {
  8209. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  8210. }
  8211. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  8212. },
  8213. enumerable: true,
  8214. configurable: true
  8215. });
  8216. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  8217. /**
  8218. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  8219. */
  8220. set: function (callback) {
  8221. if (this._onTextureLoadedObserver) {
  8222. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  8223. }
  8224. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  8225. },
  8226. enumerable: true,
  8227. configurable: true
  8228. });
  8229. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  8230. /**
  8231. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  8232. */
  8233. set: function (callback) {
  8234. if (this._onMaterialLoadedObserver) {
  8235. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  8236. }
  8237. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  8238. },
  8239. enumerable: true,
  8240. configurable: true
  8241. });
  8242. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  8243. /**
  8244. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  8245. */
  8246. set: function (callback) {
  8247. if (this._onCameraLoadedObserver) {
  8248. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  8249. }
  8250. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  8251. },
  8252. enumerable: true,
  8253. configurable: true
  8254. });
  8255. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  8256. /**
  8257. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  8258. * For assets with LODs, raised when all of the LODs are complete.
  8259. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8260. */
  8261. set: function (callback) {
  8262. if (this._onCompleteObserver) {
  8263. this.onCompleteObservable.remove(this._onCompleteObserver);
  8264. }
  8265. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  8266. },
  8267. enumerable: true,
  8268. configurable: true
  8269. });
  8270. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  8271. /**
  8272. * Callback raised when an error occurs.
  8273. */
  8274. set: function (callback) {
  8275. if (this._onErrorObserver) {
  8276. this.onErrorObservable.remove(this._onErrorObserver);
  8277. }
  8278. this._onErrorObserver = this.onErrorObservable.add(callback);
  8279. },
  8280. enumerable: true,
  8281. configurable: true
  8282. });
  8283. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  8284. /**
  8285. * Callback raised after the loader is disposed.
  8286. */
  8287. set: function (callback) {
  8288. if (this._onDisposeObserver) {
  8289. this.onDisposeObservable.remove(this._onDisposeObserver);
  8290. }
  8291. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  8292. },
  8293. enumerable: true,
  8294. configurable: true
  8295. });
  8296. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  8297. /**
  8298. * Callback raised after a loader extension is created.
  8299. */
  8300. set: function (callback) {
  8301. if (this._onExtensionLoadedObserver) {
  8302. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  8303. }
  8304. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  8305. },
  8306. enumerable: true,
  8307. configurable: true
  8308. });
  8309. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  8310. /**
  8311. * Defines if the loader logging is enabled.
  8312. */
  8313. get: function () {
  8314. return this._loggingEnabled;
  8315. },
  8316. set: function (value) {
  8317. if (this._loggingEnabled === value) {
  8318. return;
  8319. }
  8320. this._loggingEnabled = value;
  8321. if (this._loggingEnabled) {
  8322. this._log = this._logEnabled;
  8323. }
  8324. else {
  8325. this._log = this._logDisabled;
  8326. }
  8327. },
  8328. enumerable: true,
  8329. configurable: true
  8330. });
  8331. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  8332. /**
  8333. * Defines if the loader should capture performance counters.
  8334. */
  8335. get: function () {
  8336. return this._capturePerformanceCounters;
  8337. },
  8338. set: function (value) {
  8339. if (this._capturePerformanceCounters === value) {
  8340. return;
  8341. }
  8342. this._capturePerformanceCounters = value;
  8343. if (this._capturePerformanceCounters) {
  8344. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  8345. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  8346. }
  8347. else {
  8348. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8349. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8350. }
  8351. },
  8352. enumerable: true,
  8353. configurable: true
  8354. });
  8355. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  8356. /**
  8357. * Callback raised after a loader extension is created.
  8358. */
  8359. set: function (callback) {
  8360. if (this._onValidatedObserver) {
  8361. this.onValidatedObservable.remove(this._onValidatedObserver);
  8362. }
  8363. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  8364. },
  8365. enumerable: true,
  8366. configurable: true
  8367. });
  8368. /**
  8369. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  8370. */
  8371. GLTFFileLoader.prototype.dispose = function () {
  8372. if (this._loader) {
  8373. this._loader.dispose();
  8374. this._loader = null;
  8375. }
  8376. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  8377. var request = _a[_i];
  8378. request.abort();
  8379. }
  8380. this._requests.length = 0;
  8381. delete this._progressCallback;
  8382. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8383. this.onMeshLoadedObservable.clear();
  8384. this.onTextureLoadedObservable.clear();
  8385. this.onMaterialLoadedObservable.clear();
  8386. this.onCameraLoadedObservable.clear();
  8387. this.onCompleteObservable.clear();
  8388. this.onExtensionLoadedObservable.clear();
  8389. this.onDisposeObservable.notifyObservers(undefined);
  8390. this.onDisposeObservable.clear();
  8391. };
  8392. /** @hidden */
  8393. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  8394. var _this = this;
  8395. this._progressCallback = onProgress;
  8396. if (useArrayBuffer) {
  8397. if (this.useRangeRequests) {
  8398. if (this.validate) {
  8399. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  8400. }
  8401. var fileRequest_1 = {
  8402. abort: function () { },
  8403. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  8404. };
  8405. var dataBuffer = {
  8406. readAsync: function (byteOffset, byteLength) {
  8407. return new Promise(function (resolve, reject) {
  8408. _this._requestFile(url, scene, function (data) {
  8409. resolve(new Uint8Array(data));
  8410. }, true, function (error) {
  8411. reject(error);
  8412. }, function (webRequest) {
  8413. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  8414. });
  8415. });
  8416. },
  8417. byteLength: 0
  8418. };
  8419. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  8420. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  8421. onSuccess(loaderData);
  8422. }, onError);
  8423. return fileRequest_1;
  8424. }
  8425. return this._requestFile(url, scene, function (data, request) {
  8426. var arrayBuffer = data;
  8427. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8428. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  8429. byteLength: arrayBuffer.byteLength
  8430. })).then(function (loaderData) {
  8431. onSuccess(loaderData, request);
  8432. }, onError);
  8433. }, true, onError);
  8434. }
  8435. return this._requestFile(url, scene, function (data, request) {
  8436. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  8437. onSuccess({ json: _this._parseJson(data) }, request);
  8438. }, useArrayBuffer, onError);
  8439. };
  8440. /** @hidden */
  8441. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  8442. var _this = this;
  8443. return scene._readFile(file, function (data) {
  8444. _this._validate(scene, data, "file:", file.name);
  8445. if (useArrayBuffer) {
  8446. var arrayBuffer_1 = data;
  8447. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8448. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  8449. byteLength: arrayBuffer_1.byteLength
  8450. })).then(onSuccess, onError);
  8451. }
  8452. else {
  8453. onSuccess({ json: _this._parseJson(data) });
  8454. }
  8455. }, onProgress, useArrayBuffer, onError);
  8456. };
  8457. /** @hidden */
  8458. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  8459. var _this = this;
  8460. return Promise.resolve().then(function () {
  8461. _this.onParsedObservable.notifyObservers(data);
  8462. _this.onParsedObservable.clear();
  8463. _this._log("Loading " + (fileName || ""));
  8464. _this._loader = _this._getLoader(data);
  8465. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  8466. });
  8467. };
  8468. /** @hidden */
  8469. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  8470. var _this = this;
  8471. return Promise.resolve().then(function () {
  8472. _this.onParsedObservable.notifyObservers(data);
  8473. _this.onParsedObservable.clear();
  8474. _this._log("Loading " + (fileName || ""));
  8475. _this._loader = _this._getLoader(data);
  8476. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  8477. });
  8478. };
  8479. /** @hidden */
  8480. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  8481. var _this = this;
  8482. return Promise.resolve().then(function () {
  8483. _this.onParsedObservable.notifyObservers(data);
  8484. _this.onParsedObservable.clear();
  8485. _this._log("Loading " + (fileName || ""));
  8486. _this._loader = _this._getLoader(data);
  8487. // Get materials/textures when loading to add to container
  8488. var materials = [];
  8489. _this.onMaterialLoadedObservable.add(function (material) {
  8490. materials.push(material);
  8491. });
  8492. var textures = [];
  8493. _this.onTextureLoadedObservable.add(function (texture) {
  8494. textures.push(texture);
  8495. });
  8496. var cameras = [];
  8497. _this.onCameraLoadedObservable.add(function (camera) {
  8498. cameras.push(camera);
  8499. });
  8500. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  8501. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  8502. Array.prototype.push.apply(container.meshes, result.meshes);
  8503. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  8504. Array.prototype.push.apply(container.skeletons, result.skeletons);
  8505. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  8506. Array.prototype.push.apply(container.materials, materials);
  8507. Array.prototype.push.apply(container.textures, textures);
  8508. Array.prototype.push.apply(container.lights, result.lights);
  8509. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  8510. Array.prototype.push.apply(container.cameras, cameras);
  8511. return container;
  8512. });
  8513. });
  8514. };
  8515. /** @hidden */
  8516. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  8517. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  8518. };
  8519. /** @hidden */
  8520. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  8521. this._validate(scene, data);
  8522. return { json: this._parseJson(data) };
  8523. };
  8524. /** @hidden */
  8525. GLTFFileLoader.prototype.createPlugin = function () {
  8526. return new GLTFFileLoader();
  8527. };
  8528. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  8529. /**
  8530. * The loader state or null if the loader is not active.
  8531. */
  8532. get: function () {
  8533. return this._loader ? this._loader.state : null;
  8534. },
  8535. enumerable: true,
  8536. configurable: true
  8537. });
  8538. /**
  8539. * Returns a promise that resolves when the asset is completely loaded.
  8540. * @returns a promise that resolves when the asset is completely loaded.
  8541. */
  8542. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  8543. var _this = this;
  8544. return new Promise(function (resolve, reject) {
  8545. _this.onCompleteObservable.addOnce(function () {
  8546. resolve();
  8547. });
  8548. _this.onErrorObservable.addOnce(function (reason) {
  8549. reject(reason);
  8550. });
  8551. });
  8552. };
  8553. /** @hidden */
  8554. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  8555. var _this = this;
  8556. var request = scene._loadFile(url, onSuccess, function (event) {
  8557. _this._onProgress(event, request);
  8558. }, undefined, useArrayBuffer, onError);
  8559. request.onCompleteObservable.add(function (request) {
  8560. _this._requests.splice(_this._requests.indexOf(request), 1);
  8561. });
  8562. this._requests.push(request);
  8563. return request;
  8564. };
  8565. /** @hidden */
  8566. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  8567. var _this = this;
  8568. var request = scene._requestFile(url, onSuccess, function (event) {
  8569. _this._onProgress(event, request);
  8570. }, undefined, useArrayBuffer, onError, onOpened);
  8571. request.onCompleteObservable.add(function (request) {
  8572. _this._requests.splice(_this._requests.indexOf(request), 1);
  8573. });
  8574. this._requests.push(request);
  8575. return request;
  8576. };
  8577. GLTFFileLoader.prototype._onProgress = function (event, request) {
  8578. if (!this._progressCallback) {
  8579. return;
  8580. }
  8581. request._lengthComputable = event.lengthComputable;
  8582. request._loaded = event.loaded;
  8583. request._total = event.total;
  8584. var lengthComputable = true;
  8585. var loaded = 0;
  8586. var total = 0;
  8587. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  8588. var request_1 = _a[_i];
  8589. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  8590. return;
  8591. }
  8592. lengthComputable = lengthComputable && request_1._lengthComputable;
  8593. loaded += request_1._loaded;
  8594. total += request_1._total;
  8595. }
  8596. this._progressCallback({
  8597. lengthComputable: lengthComputable,
  8598. loaded: loaded,
  8599. total: lengthComputable ? total : 0
  8600. });
  8601. };
  8602. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  8603. var _this = this;
  8604. if (rootUrl === void 0) { rootUrl = ""; }
  8605. if (fileName === void 0) { fileName = ""; }
  8606. if (!this.validate) {
  8607. return;
  8608. }
  8609. this._startPerformanceCounter("Validate JSON");
  8610. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  8611. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  8612. }).then(function (result) {
  8613. _this._endPerformanceCounter("Validate JSON");
  8614. _this.onValidatedObservable.notifyObservers(result);
  8615. _this.onValidatedObservable.clear();
  8616. }, function (reason) {
  8617. _this._endPerformanceCounter("Validate JSON");
  8618. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  8619. _this.onValidatedObservable.clear();
  8620. });
  8621. };
  8622. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  8623. var asset = loaderData.json.asset || {};
  8624. this._log("Asset version: " + asset.version);
  8625. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  8626. asset.generator && this._log("Asset generator: " + asset.generator);
  8627. var version = GLTFFileLoader._parseVersion(asset.version);
  8628. if (!version) {
  8629. throw new Error("Invalid version: " + asset.version);
  8630. }
  8631. if (asset.minVersion !== undefined) {
  8632. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  8633. if (!minVersion) {
  8634. throw new Error("Invalid minimum version: " + asset.minVersion);
  8635. }
  8636. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  8637. throw new Error("Incompatible minimum version: " + asset.minVersion);
  8638. }
  8639. }
  8640. var createLoaders = {
  8641. 1: GLTFFileLoader._CreateGLTF1Loader,
  8642. 2: GLTFFileLoader._CreateGLTF2Loader
  8643. };
  8644. var createLoader = createLoaders[version.major];
  8645. if (!createLoader) {
  8646. throw new Error("Unsupported version: " + asset.version);
  8647. }
  8648. return createLoader(this);
  8649. };
  8650. GLTFFileLoader.prototype._parseJson = function (json) {
  8651. this._startPerformanceCounter("Parse JSON");
  8652. this._log("JSON length: " + json.length);
  8653. var parsed = JSON.parse(json);
  8654. this._endPerformanceCounter("Parse JSON");
  8655. return parsed;
  8656. };
  8657. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8658. var _this = this;
  8659. this._startPerformanceCounter("Unpack Binary");
  8660. // Read magic + version + length + json length + json format
  8661. return dataReader.loadAsync(20).then(function () {
  8662. var Binary = {
  8663. Magic: 0x46546C67
  8664. };
  8665. var magic = dataReader.readUint32();
  8666. if (magic !== Binary.Magic) {
  8667. throw new Error("Unexpected magic: " + magic);
  8668. }
  8669. var version = dataReader.readUint32();
  8670. if (_this.loggingEnabled) {
  8671. _this._log("Binary version: " + version);
  8672. }
  8673. var length = dataReader.readUint32();
  8674. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  8675. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8676. }
  8677. var unpacked;
  8678. switch (version) {
  8679. case 1: {
  8680. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  8681. break;
  8682. }
  8683. case 2: {
  8684. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  8685. break;
  8686. }
  8687. default: {
  8688. throw new Error("Unsupported version: " + version);
  8689. }
  8690. }
  8691. _this._endPerformanceCounter("Unpack Binary");
  8692. return unpacked;
  8693. });
  8694. };
  8695. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  8696. var ContentFormat = {
  8697. JSON: 0
  8698. };
  8699. var contentLength = dataReader.readUint32();
  8700. var contentFormat = dataReader.readUint32();
  8701. if (contentFormat !== ContentFormat.JSON) {
  8702. throw new Error("Unexpected content format: " + contentFormat);
  8703. }
  8704. var bodyLength = length - dataReader.byteOffset;
  8705. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8706. if (bodyLength !== 0) {
  8707. var startByteOffset_1 = dataReader.byteOffset;
  8708. data.bin = {
  8709. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8710. byteLength: bodyLength
  8711. };
  8712. }
  8713. return Promise.resolve(data);
  8714. };
  8715. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  8716. var _this = this;
  8717. var ChunkFormat = {
  8718. JSON: 0x4E4F534A,
  8719. BIN: 0x004E4942
  8720. };
  8721. // Read the JSON chunk header.
  8722. var chunkLength = dataReader.readUint32();
  8723. var chunkFormat = dataReader.readUint32();
  8724. if (chunkFormat !== ChunkFormat.JSON) {
  8725. throw new Error("First chunk format is not JSON");
  8726. }
  8727. // Bail if there are no other chunks.
  8728. if (dataReader.byteOffset + chunkLength === length) {
  8729. return dataReader.loadAsync(chunkLength).then(function () {
  8730. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8731. });
  8732. }
  8733. // Read the JSON chunk and the length and type of the next chunk.
  8734. return dataReader.loadAsync(chunkLength + 8).then(function () {
  8735. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8736. var readAsync = function () {
  8737. var chunkLength = dataReader.readUint32();
  8738. var chunkFormat = dataReader.readUint32();
  8739. switch (chunkFormat) {
  8740. case ChunkFormat.JSON: {
  8741. throw new Error("Unexpected JSON chunk");
  8742. }
  8743. case ChunkFormat.BIN: {
  8744. var startByteOffset_2 = dataReader.byteOffset;
  8745. data.bin = {
  8746. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8747. byteLength: chunkLength
  8748. };
  8749. dataReader.skipBytes(chunkLength);
  8750. break;
  8751. }
  8752. default: {
  8753. // ignore unrecognized chunkFormat
  8754. dataReader.skipBytes(chunkLength);
  8755. break;
  8756. }
  8757. }
  8758. if (dataReader.byteOffset !== length) {
  8759. return dataReader.loadAsync(8).then(readAsync);
  8760. }
  8761. return Promise.resolve(data);
  8762. };
  8763. return readAsync();
  8764. });
  8765. };
  8766. GLTFFileLoader._parseVersion = function (version) {
  8767. if (version === "1.0" || version === "1.0.1") {
  8768. return {
  8769. major: 1,
  8770. minor: 0
  8771. };
  8772. }
  8773. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8774. if (!match) {
  8775. return null;
  8776. }
  8777. return {
  8778. major: parseInt(match[1]),
  8779. minor: parseInt(match[2])
  8780. };
  8781. };
  8782. GLTFFileLoader._compareVersion = function (a, b) {
  8783. if (a.major > b.major) {
  8784. return 1;
  8785. }
  8786. if (a.major < b.major) {
  8787. return -1;
  8788. }
  8789. if (a.minor > b.minor) {
  8790. return 1;
  8791. }
  8792. if (a.minor < b.minor) {
  8793. return -1;
  8794. }
  8795. return 0;
  8796. };
  8797. /** @hidden */
  8798. GLTFFileLoader.prototype._logOpen = function (message) {
  8799. this._log(message);
  8800. this._logIndentLevel++;
  8801. };
  8802. /** @hidden */
  8803. GLTFFileLoader.prototype._logClose = function () {
  8804. --this._logIndentLevel;
  8805. };
  8806. GLTFFileLoader.prototype._logEnabled = function (message) {
  8807. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8808. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8809. };
  8810. GLTFFileLoader.prototype._logDisabled = function (message) {
  8811. };
  8812. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8813. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8814. };
  8815. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8816. };
  8817. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8818. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8819. };
  8820. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8821. };
  8822. // ----------
  8823. // V1 options
  8824. // ----------
  8825. /**
  8826. * 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.
  8827. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8828. * Defaults to true.
  8829. * @hidden
  8830. */
  8831. GLTFFileLoader.IncrementalLoading = true;
  8832. /**
  8833. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8834. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8835. * @hidden
  8836. */
  8837. GLTFFileLoader.HomogeneousCoordinates = false;
  8838. GLTFFileLoader._logSpaces = " ";
  8839. return GLTFFileLoader;
  8840. }());
  8841. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8842. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8843. }
  8844. /***/ }),
  8845. /***/ "./glTF/glTFValidation.ts":
  8846. /*!********************************!*\
  8847. !*** ./glTF/glTFValidation.ts ***!
  8848. \********************************/
  8849. /*! exports provided: GLTFValidation */
  8850. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8851. "use strict";
  8852. __webpack_require__.r(__webpack_exports__);
  8853. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  8854. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  8855. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  8856. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  8857. var options = {
  8858. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  8859. };
  8860. if (fileName) {
  8861. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  8862. }
  8863. return (data instanceof ArrayBuffer)
  8864. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  8865. : GLTFValidator.validateString(data, options);
  8866. }
  8867. /**
  8868. * The worker function that gets converted to a blob url to pass into a worker.
  8869. */
  8870. function workerFunc() {
  8871. var pendingExternalResources = [];
  8872. onmessage = function (message) {
  8873. var data = message.data;
  8874. switch (data.id) {
  8875. case "init": {
  8876. importScripts(data.url);
  8877. break;
  8878. }
  8879. case "validate": {
  8880. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  8881. var index = pendingExternalResources.length;
  8882. pendingExternalResources.push({ resolve: resolve, reject: reject });
  8883. postMessage({ id: "getExternalResource", index: index, uri: uri });
  8884. }); }).then(function (value) {
  8885. postMessage({ id: "validate.resolve", value: value });
  8886. }, function (reason) {
  8887. postMessage({ id: "validate.reject", reason: reason });
  8888. });
  8889. break;
  8890. }
  8891. case "getExternalResource.resolve": {
  8892. pendingExternalResources[data.index].resolve(data.value);
  8893. break;
  8894. }
  8895. case "getExternalResource.reject": {
  8896. pendingExternalResources[data.index].reject(data.reason);
  8897. break;
  8898. }
  8899. }
  8900. };
  8901. }
  8902. /**
  8903. * glTF validation
  8904. */
  8905. var GLTFValidation = /** @class */ (function () {
  8906. function GLTFValidation() {
  8907. }
  8908. /**
  8909. * Validate a glTF asset using the glTF-Validator.
  8910. * @param data The JSON of a glTF or the array buffer of a binary glTF
  8911. * @param rootUrl The root url for the glTF
  8912. * @param fileName The file name for the glTF
  8913. * @param getExternalResource The callback to get external resources for the glTF validator
  8914. * @returns A promise that resolves with the glTF validation results once complete
  8915. */
  8916. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  8917. var _this = this;
  8918. if (typeof Worker === "function") {
  8919. return new Promise(function (resolve, reject) {
  8920. var workerContent = validateAsync + "(" + workerFunc + ")()";
  8921. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  8922. var worker = new Worker(workerBlobUrl);
  8923. var onError = function (error) {
  8924. worker.removeEventListener("error", onError);
  8925. worker.removeEventListener("message", onMessage);
  8926. reject(error);
  8927. };
  8928. var onMessage = function (message) {
  8929. var data = message.data;
  8930. switch (data.id) {
  8931. case "getExternalResource": {
  8932. getExternalResource(data.uri).then(function (value) {
  8933. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  8934. }, function (reason) {
  8935. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  8936. });
  8937. break;
  8938. }
  8939. case "validate.resolve": {
  8940. worker.removeEventListener("error", onError);
  8941. worker.removeEventListener("message", onMessage);
  8942. resolve(data.value);
  8943. break;
  8944. }
  8945. case "validate.reject": {
  8946. worker.removeEventListener("error", onError);
  8947. worker.removeEventListener("message", onMessage);
  8948. reject(data.reason);
  8949. }
  8950. }
  8951. };
  8952. worker.addEventListener("error", onError);
  8953. worker.addEventListener("message", onMessage);
  8954. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  8955. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  8956. });
  8957. }
  8958. else {
  8959. if (!this._LoadScriptPromise) {
  8960. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  8961. }
  8962. return this._LoadScriptPromise.then(function () {
  8963. return validateAsync(data, rootUrl, fileName, getExternalResource);
  8964. });
  8965. }
  8966. };
  8967. /**
  8968. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  8969. */
  8970. GLTFValidation.Configuration = {
  8971. url: "https://preview.babylonjs.com/gltf_validator.js"
  8972. };
  8973. return GLTFValidation;
  8974. }());
  8975. /***/ }),
  8976. /***/ "./glTF/index.ts":
  8977. /*!***********************!*\
  8978. !*** ./glTF/index.ts ***!
  8979. \***********************/
  8980. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  8981. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8982. "use strict";
  8983. __webpack_require__.r(__webpack_exports__);
  8984. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8985. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8986. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8987. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8988. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8989. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8990. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8991. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  8992. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  8993. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  8994. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  8995. /***/ }),
  8996. /***/ "./index.ts":
  8997. /*!******************!*\
  8998. !*** ./index.ts ***!
  8999. \******************/
  9000. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9001. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9002. "use strict";
  9003. __webpack_require__.r(__webpack_exports__);
  9004. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  9005. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9006. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9007. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9008. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9009. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  9010. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  9011. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  9012. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  9013. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  9014. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  9015. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  9016. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  9017. /***/ }),
  9018. /***/ "./legacy/legacy-glTF.ts":
  9019. /*!*******************************!*\
  9020. !*** ./legacy/legacy-glTF.ts ***!
  9021. \*******************************/
  9022. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  9023. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9024. "use strict";
  9025. __webpack_require__.r(__webpack_exports__);
  9026. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9027. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  9028. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9029. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9030. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9031. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9032. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9033. /**
  9034. * This is the entry point for the UMD module.
  9035. * The entry point for a future ESM package should be index.ts
  9036. */
  9037. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9038. if (typeof globalObject !== "undefined") {
  9039. globalObject.BABYLON = globalObject.BABYLON || {};
  9040. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  9041. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  9042. }
  9043. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  9044. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  9045. }
  9046. }
  9047. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9048. /***/ }),
  9049. /***/ "./legacy/legacy-glTF1.ts":
  9050. /*!********************************!*\
  9051. !*** ./legacy/legacy-glTF1.ts ***!
  9052. \********************************/
  9053. /*! exports provided: GLTF1 */
  9054. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9055. "use strict";
  9056. __webpack_require__.r(__webpack_exports__);
  9057. /* 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");
  9058. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  9059. /**
  9060. * This is the entry point for the UMD module.
  9061. * The entry point for a future ESM package should be index.ts
  9062. */
  9063. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9064. if (typeof globalObject !== "undefined") {
  9065. globalObject.BABYLON = globalObject.BABYLON || {};
  9066. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  9067. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  9068. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  9069. }
  9070. }
  9071. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9072. /***/ }),
  9073. /***/ "./legacy/legacy-glTF2.ts":
  9074. /*!********************************!*\
  9075. !*** ./legacy/legacy-glTF2.ts ***!
  9076. \********************************/
  9077. /*! exports provided: GLTF2 */
  9078. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9079. "use strict";
  9080. __webpack_require__.r(__webpack_exports__);
  9081. /* 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");
  9082. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  9083. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  9084. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  9085. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  9086. /**
  9087. * This is the entry point for the UMD module.
  9088. * The entry point for a future ESM package should be index.ts
  9089. */
  9090. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9091. if (typeof globalObject !== "undefined") {
  9092. globalObject.BABYLON = globalObject.BABYLON || {};
  9093. var BABYLON = globalObject.BABYLON;
  9094. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  9095. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  9096. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  9097. var keys = [];
  9098. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  9099. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  9100. keys.push(key);
  9101. }
  9102. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  9103. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  9104. keys.push(key);
  9105. }
  9106. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  9107. // Prevent Reassignment.
  9108. if (keys.indexOf(key) > -1) {
  9109. continue;
  9110. }
  9111. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  9112. }
  9113. }
  9114. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9115. /***/ }),
  9116. /***/ "./legacy/legacy-objFileLoader.ts":
  9117. /*!****************************************!*\
  9118. !*** ./legacy/legacy-objFileLoader.ts ***!
  9119. \****************************************/
  9120. /*! exports provided: MTLFileLoader, OBJFileLoader */
  9121. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9122. "use strict";
  9123. __webpack_require__.r(__webpack_exports__);
  9124. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  9125. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  9126. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  9127. /**
  9128. * This is the entry point for the UMD module.
  9129. * The entry point for a future ESM package should be index.ts
  9130. */
  9131. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9132. if (typeof globalObject !== "undefined") {
  9133. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  9134. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  9135. }
  9136. }
  9137. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9138. /***/ }),
  9139. /***/ "./legacy/legacy-stlFileLoader.ts":
  9140. /*!****************************************!*\
  9141. !*** ./legacy/legacy-stlFileLoader.ts ***!
  9142. \****************************************/
  9143. /*! exports provided: STLFileLoader */
  9144. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9145. "use strict";
  9146. __webpack_require__.r(__webpack_exports__);
  9147. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  9148. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  9149. /**
  9150. * This is the entry point for the UMD module.
  9151. * The entry point for a future ESM package should be index.ts
  9152. */
  9153. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9154. if (typeof globalObject !== "undefined") {
  9155. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  9156. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  9157. }
  9158. }
  9159. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9160. /***/ }),
  9161. /***/ "./legacy/legacy.ts":
  9162. /*!**************************!*\
  9163. !*** ./legacy/legacy.ts ***!
  9164. \**************************/
  9165. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9166. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9167. "use strict";
  9168. __webpack_require__.r(__webpack_exports__);
  9169. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  9170. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  9171. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  9172. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  9173. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  9174. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  9175. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9176. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  9177. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  9178. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  9179. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  9180. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  9181. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  9182. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  9183. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  9184. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  9185. /***/ }),
  9186. /***/ "babylonjs/Misc/tools":
  9187. /*!****************************************************************************************************!*\
  9188. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  9189. \****************************************************************************************************/
  9190. /*! no static exports found */
  9191. /***/ (function(module, exports) {
  9192. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  9193. /***/ })
  9194. /******/ });
  9195. });
  9196. //# sourceMappingURL=babylonjs.loaders.js.map