babylonjs.loaders.js 450 KB

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