babylonjs.loaders.js 450 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107
  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. !*** C:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./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.loadNodeAsync = function (context, node, assign) {
  5045. var _this = this;
  5046. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5047. var firstPromise;
  5048. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5049. _this._loader.logOpen("" + extensionContext);
  5050. var _loop_3 = function (indexLOD) {
  5051. var nodeLOD = nodeLODs[indexLOD];
  5052. _this._indexLOD = indexLOD;
  5053. if (indexLOD !== 0) {
  5054. _this._nodeIndexLOD = indexLOD;
  5055. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5056. }
  5057. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5058. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5059. if (indexLOD !== 0) {
  5060. // TODO: should not rely on _babylonTransformNode
  5061. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5062. if (previousNodeLOD._babylonTransformNode) {
  5063. previousNodeLOD._babylonTransformNode.dispose();
  5064. delete previousNodeLOD._babylonTransformNode;
  5065. _this._disposeUnusedMaterials();
  5066. }
  5067. }
  5068. babylonMesh.setEnabled(true);
  5069. return babylonMesh;
  5070. });
  5071. if (indexLOD === 0) {
  5072. firstPromise = promise;
  5073. if (_this._bufferLODs.length !== 0) {
  5074. _this._loadBufferLOD(0);
  5075. }
  5076. }
  5077. else {
  5078. _this._nodeIndexLOD = null;
  5079. }
  5080. _this._indexLOD = null;
  5081. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5082. _this._nodePromiseLODs[indexLOD].push(promise);
  5083. };
  5084. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5085. _loop_3(indexLOD);
  5086. }
  5087. _this._loader.logClose();
  5088. return firstPromise;
  5089. });
  5090. };
  5091. /** @hidden */
  5092. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5093. var _this = this;
  5094. // Don't load material LODs if already loading a node LOD.
  5095. if (this._indexLOD) {
  5096. return null;
  5097. }
  5098. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5099. var firstPromise;
  5100. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5101. _this._loader.logOpen("" + extensionContext);
  5102. var _loop_4 = function (indexLOD) {
  5103. var materialLOD = materialLODs[indexLOD];
  5104. _this._indexLOD = indexLOD;
  5105. if (indexLOD !== 0) {
  5106. _this._materialIndexLOD = indexLOD;
  5107. }
  5108. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5109. if (indexLOD === 0) {
  5110. assign(babylonMaterial);
  5111. }
  5112. }).then(function (babylonMaterial) {
  5113. if (indexLOD !== 0) {
  5114. assign(babylonMaterial);
  5115. // TODO: should not rely on _data
  5116. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5117. if (previousDataLOD[babylonDrawMode]) {
  5118. previousDataLOD[babylonDrawMode].babylonMaterial.dispose();
  5119. delete previousDataLOD[babylonDrawMode];
  5120. }
  5121. }
  5122. return babylonMaterial;
  5123. });
  5124. if (indexLOD === 0) {
  5125. firstPromise = promise;
  5126. if (_this._bufferLODs.length !== 0) {
  5127. _this._loadBufferLOD(0);
  5128. }
  5129. }
  5130. else {
  5131. _this._materialIndexLOD = null;
  5132. }
  5133. _this._indexLOD = null;
  5134. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5135. _this._materialPromiseLODs[indexLOD].push(promise);
  5136. };
  5137. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5138. _loop_4(indexLOD);
  5139. }
  5140. _this._loader.logClose();
  5141. return firstPromise;
  5142. });
  5143. };
  5144. /** @hidden */
  5145. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5146. var _this = this;
  5147. // Defer the loading of uris if loading a material or node LOD.
  5148. if (this._materialIndexLOD !== null) {
  5149. this._loader.log("deferred");
  5150. var previousIndexLOD = this._materialIndexLOD - 1;
  5151. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5152. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5153. return _this._loader.loadUriAsync(context, property, uri);
  5154. });
  5155. }
  5156. else if (this._nodeIndexLOD !== null) {
  5157. this._loader.log("deferred");
  5158. var previousIndexLOD = this._nodeIndexLOD - 1;
  5159. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5160. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5161. return _this._loader.loadUriAsync(context, property, uri);
  5162. });
  5163. }
  5164. return null;
  5165. };
  5166. /** @hidden */
  5167. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5168. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5169. if (!this._loader.bin) {
  5170. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5171. }
  5172. // Non-LOD buffers will be bucketed into the first LOD.
  5173. var indexLOD = this._indexLOD || 0;
  5174. var start = byteOffset;
  5175. var end = start + byteLength - 1;
  5176. var bufferLOD_1 = this._bufferLODs[indexLOD];
  5177. if (bufferLOD_1) {
  5178. bufferLOD_1.start = Math.min(bufferLOD_1.start, start);
  5179. bufferLOD_1.end = Math.max(bufferLOD_1.end, end);
  5180. }
  5181. else {
  5182. bufferLOD_1 = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5183. this._bufferLODs[indexLOD] = bufferLOD_1;
  5184. }
  5185. return bufferLOD_1.loaded.promise.then(function (data) {
  5186. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD_1.start, byteLength);
  5187. });
  5188. }
  5189. return null;
  5190. };
  5191. MSFT_lod.prototype._loadBufferLOD = function (indexLOD) {
  5192. var bufferLOD = this._bufferLODs[indexLOD];
  5193. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5194. bufferLOD.loaded.resolve(data);
  5195. }, function (error) {
  5196. bufferLOD.loaded.reject(error);
  5197. });
  5198. };
  5199. /**
  5200. * Gets an array of LOD properties from lowest to highest.
  5201. */
  5202. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5203. if (this.maxLODsToLoad <= 0) {
  5204. throw new Error("maxLODsToLoad must be greater than zero");
  5205. }
  5206. var properties = new Array();
  5207. for (var i = ids.length - 1; i >= 0; i--) {
  5208. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5209. if (properties.length === this.maxLODsToLoad) {
  5210. return properties;
  5211. }
  5212. }
  5213. properties.push(property);
  5214. return properties;
  5215. };
  5216. MSFT_lod.prototype._disposeUnusedMaterials = function () {
  5217. // TODO: should not rely on _data
  5218. var materials = this._loader.gltf.materials;
  5219. if (materials) {
  5220. for (var _i = 0, materials_1 = materials; _i < materials_1.length; _i++) {
  5221. var material = materials_1[_i];
  5222. if (material._data) {
  5223. var _loop_5 = function (drawMode) {
  5224. var data = material._data[drawMode];
  5225. if (data.babylonMeshes.every(function (babylonMesh) { return babylonMesh.material !== data.babylonMaterial; })) {
  5226. // TODO: check if texture is in use instead of force disposing textures
  5227. data.babylonMaterial.dispose(false, true);
  5228. delete material._data[drawMode];
  5229. }
  5230. };
  5231. for (var drawMode in material._data) {
  5232. _loop_5(drawMode);
  5233. }
  5234. }
  5235. }
  5236. }
  5237. };
  5238. return MSFT_lod;
  5239. }());
  5240. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5241. /***/ }),
  5242. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5243. /*!***************************************************!*\
  5244. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5245. \***************************************************/
  5246. /*! exports provided: MSFT_minecraftMesh */
  5247. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5248. "use strict";
  5249. __webpack_require__.r(__webpack_exports__);
  5250. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5251. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5252. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5253. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5254. var NAME = "MSFT_minecraftMesh";
  5255. /** @hidden */
  5256. var MSFT_minecraftMesh = /** @class */ (function () {
  5257. function MSFT_minecraftMesh(loader) {
  5258. this.name = NAME;
  5259. this._loader = loader;
  5260. this.enabled = this._loader.isExtensionUsed(NAME);
  5261. }
  5262. MSFT_minecraftMesh.prototype.dispose = function () {
  5263. delete this._loader;
  5264. };
  5265. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5266. var _this = this;
  5267. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5268. if (extra) {
  5269. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5270. throw new Error(extraContext + ": Material type not supported");
  5271. }
  5272. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5273. if (babylonMaterial.needAlphaBlending()) {
  5274. babylonMaterial.forceDepthWrite = true;
  5275. babylonMaterial.separateCullingPass = true;
  5276. }
  5277. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5278. babylonMaterial.twoSidedLighting = true;
  5279. return promise;
  5280. }
  5281. return null;
  5282. });
  5283. };
  5284. return MSFT_minecraftMesh;
  5285. }());
  5286. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5287. /***/ }),
  5288. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5289. /*!*************************************************!*\
  5290. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5291. \*************************************************/
  5292. /*! exports provided: MSFT_sRGBFactors */
  5293. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5294. "use strict";
  5295. __webpack_require__.r(__webpack_exports__);
  5296. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5297. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5298. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5299. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5300. var NAME = "MSFT_sRGBFactors";
  5301. /** @hidden */
  5302. var MSFT_sRGBFactors = /** @class */ (function () {
  5303. function MSFT_sRGBFactors(loader) {
  5304. this.name = NAME;
  5305. this._loader = loader;
  5306. this.enabled = this._loader.isExtensionUsed(NAME);
  5307. }
  5308. MSFT_sRGBFactors.prototype.dispose = function () {
  5309. delete this._loader;
  5310. };
  5311. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5312. var _this = this;
  5313. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5314. if (extra) {
  5315. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5316. throw new Error(extraContext + ": Material type not supported");
  5317. }
  5318. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5319. if (!babylonMaterial.albedoTexture) {
  5320. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5321. }
  5322. if (!babylonMaterial.reflectivityTexture) {
  5323. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5324. }
  5325. return promise;
  5326. }
  5327. return null;
  5328. });
  5329. };
  5330. return MSFT_sRGBFactors;
  5331. }());
  5332. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5333. /***/ }),
  5334. /***/ "./glTF/2.0/Extensions/index.ts":
  5335. /*!**************************************!*\
  5336. !*** ./glTF/2.0/Extensions/index.ts ***!
  5337. \**************************************/
  5338. /*! 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 */
  5339. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5340. "use strict";
  5341. __webpack_require__.r(__webpack_exports__);
  5342. /* 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");
  5343. /* 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"]; });
  5344. /* 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");
  5345. /* 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"]; });
  5346. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5347. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  5348. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5349. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  5350. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5351. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  5352. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5353. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_clearcoat"]; });
  5354. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5355. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_sheen"]; });
  5356. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5357. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_specular"]; });
  5358. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  5359. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__["KHR_mesh_quantization"]; });
  5360. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5361. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__["KHR_texture_transform"]; });
  5362. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5363. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__["MSFT_audio_emitter"]; });
  5364. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5365. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__["MSFT_lod"]; });
  5366. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5367. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__["MSFT_minecraftMesh"]; });
  5368. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5369. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__["MSFT_sRGBFactors"]; });
  5370. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5371. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__["ExtrasAsMetadata"]; });
  5372. /***/ }),
  5373. /***/ "./glTF/2.0/glTFLoader.ts":
  5374. /*!********************************!*\
  5375. !*** ./glTF/2.0/glTFLoader.ts ***!
  5376. \********************************/
  5377. /*! exports provided: ArrayItem, GLTFLoader */
  5378. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5379. "use strict";
  5380. __webpack_require__.r(__webpack_exports__);
  5381. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5382. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5383. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  5384. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5385. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5386. /**
  5387. * Helper class for working with arrays when loading the glTF asset
  5388. */
  5389. var ArrayItem = /** @class */ (function () {
  5390. function ArrayItem() {
  5391. }
  5392. /**
  5393. * Gets an item from the given array.
  5394. * @param context The context when loading the asset
  5395. * @param array The array to get the item from
  5396. * @param index The index to the array
  5397. * @returns The array item
  5398. */
  5399. ArrayItem.Get = function (context, array, index) {
  5400. if (!array || index == undefined || !array[index]) {
  5401. throw new Error(context + ": Failed to find index (" + index + ")");
  5402. }
  5403. return array[index];
  5404. };
  5405. /**
  5406. * Assign an `index` field to each item of the given array.
  5407. * @param array The array of items
  5408. */
  5409. ArrayItem.Assign = function (array) {
  5410. if (array) {
  5411. for (var index = 0; index < array.length; index++) {
  5412. array[index].index = index;
  5413. }
  5414. }
  5415. };
  5416. return ArrayItem;
  5417. }());
  5418. /**
  5419. * The glTF 2.0 loader
  5420. */
  5421. var GLTFLoader = /** @class */ (function () {
  5422. /** @hidden */
  5423. function GLTFLoader(parent) {
  5424. /** @hidden */
  5425. this._completePromises = new Array();
  5426. this._disposed = false;
  5427. this._state = null;
  5428. this._extensions = new Array();
  5429. this._defaultBabylonMaterialData = {};
  5430. this._requests = new Array();
  5431. this._parent = parent;
  5432. }
  5433. /**
  5434. * Registers a loader extension.
  5435. * @param name The name of the loader extension.
  5436. * @param factory The factory function that creates the loader extension.
  5437. */
  5438. GLTFLoader.RegisterExtension = function (name, factory) {
  5439. if (GLTFLoader.UnregisterExtension(name)) {
  5440. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  5441. }
  5442. GLTFLoader._RegisteredExtensions[name] = {
  5443. factory: factory
  5444. };
  5445. };
  5446. /**
  5447. * Unregisters a loader extension.
  5448. * @param name The name of the loader extension.
  5449. * @returns A boolean indicating whether the extension has been unregistered
  5450. */
  5451. GLTFLoader.UnregisterExtension = function (name) {
  5452. if (!GLTFLoader._RegisteredExtensions[name]) {
  5453. return false;
  5454. }
  5455. delete GLTFLoader._RegisteredExtensions[name];
  5456. return true;
  5457. };
  5458. Object.defineProperty(GLTFLoader.prototype, "state", {
  5459. /**
  5460. * Gets the loader state.
  5461. */
  5462. get: function () {
  5463. return this._state;
  5464. },
  5465. enumerable: true,
  5466. configurable: true
  5467. });
  5468. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  5469. /**
  5470. * The object that represents the glTF JSON.
  5471. */
  5472. get: function () {
  5473. return this._gltf;
  5474. },
  5475. enumerable: true,
  5476. configurable: true
  5477. });
  5478. Object.defineProperty(GLTFLoader.prototype, "bin", {
  5479. /**
  5480. * The BIN chunk of a binary glTF.
  5481. */
  5482. get: function () {
  5483. return this._bin;
  5484. },
  5485. enumerable: true,
  5486. configurable: true
  5487. });
  5488. Object.defineProperty(GLTFLoader.prototype, "parent", {
  5489. /**
  5490. * The parent file loader.
  5491. */
  5492. get: function () {
  5493. return this._parent;
  5494. },
  5495. enumerable: true,
  5496. configurable: true
  5497. });
  5498. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  5499. /**
  5500. * The Babylon scene when loading the asset.
  5501. */
  5502. get: function () {
  5503. return this._babylonScene;
  5504. },
  5505. enumerable: true,
  5506. configurable: true
  5507. });
  5508. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  5509. /**
  5510. * The root Babylon mesh when loading the asset.
  5511. */
  5512. get: function () {
  5513. return this._rootBabylonMesh;
  5514. },
  5515. enumerable: true,
  5516. configurable: true
  5517. });
  5518. /** @hidden */
  5519. GLTFLoader.prototype.dispose = function () {
  5520. if (this._disposed) {
  5521. return;
  5522. }
  5523. this._disposed = true;
  5524. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  5525. var request = _a[_i];
  5526. request.abort();
  5527. }
  5528. this._requests.length = 0;
  5529. this._completePromises.length = 0;
  5530. for (var name_1 in this._extensions) {
  5531. var extension = this._extensions[name_1];
  5532. extension.dispose && extension.dispose();
  5533. delete this._extensions[name_1];
  5534. }
  5535. delete this._gltf;
  5536. delete this._babylonScene;
  5537. delete this._rootBabylonMesh;
  5538. delete this._progressCallback;
  5539. this._parent._clear();
  5540. };
  5541. /** @hidden */
  5542. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  5543. var _this = this;
  5544. return Promise.resolve().then(function () {
  5545. _this._babylonScene = scene;
  5546. _this._rootUrl = rootUrl;
  5547. _this._fileName = fileName || "scene";
  5548. _this._progressCallback = onProgress;
  5549. _this._loadData(data);
  5550. var nodes = null;
  5551. if (meshesNames) {
  5552. var nodeMap_1 = {};
  5553. if (_this._gltf.nodes) {
  5554. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  5555. var node = _a[_i];
  5556. if (node.name) {
  5557. nodeMap_1[node.name] = node.index;
  5558. }
  5559. }
  5560. }
  5561. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  5562. nodes = names.map(function (name) {
  5563. var node = nodeMap_1[name];
  5564. if (node === undefined) {
  5565. throw new Error("Failed to find node '" + name + "'");
  5566. }
  5567. return node;
  5568. });
  5569. }
  5570. return _this._loadAsync(nodes, function () {
  5571. return {
  5572. meshes: _this._getMeshes(),
  5573. particleSystems: [],
  5574. skeletons: _this._getSkeletons(),
  5575. animationGroups: _this._getAnimationGroups()
  5576. };
  5577. });
  5578. });
  5579. };
  5580. /** @hidden */
  5581. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  5582. var _this = this;
  5583. return Promise.resolve().then(function () {
  5584. _this._babylonScene = scene;
  5585. _this._rootUrl = rootUrl;
  5586. _this._fileName = fileName || "scene";
  5587. _this._progressCallback = onProgress;
  5588. _this._loadData(data);
  5589. return _this._loadAsync(null, function () { return undefined; });
  5590. });
  5591. };
  5592. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  5593. var _this = this;
  5594. return Promise.resolve().then(function () {
  5595. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  5596. _this._loadExtensions();
  5597. _this._checkExtensions();
  5598. 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];
  5599. 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];
  5600. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  5601. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  5602. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  5603. _this._extensionsOnLoading();
  5604. var promises = new Array();
  5605. // Block the marking of materials dirty until the scene is loaded.
  5606. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  5607. _this._babylonScene.blockMaterialDirtyMechanism = true;
  5608. if (nodes) {
  5609. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  5610. }
  5611. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  5612. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  5613. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  5614. }
  5615. // Restore the blocking of material dirty.
  5616. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  5617. if (_this._parent.compileMaterials) {
  5618. promises.push(_this._compileMaterialsAsync());
  5619. }
  5620. if (_this._parent.compileShadowGenerators) {
  5621. promises.push(_this._compileShadowGeneratorsAsync());
  5622. }
  5623. var resultPromise = Promise.all(promises).then(function () {
  5624. if (_this._rootBabylonMesh) {
  5625. _this._rootBabylonMesh.setEnabled(true);
  5626. }
  5627. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  5628. _this._extensionsOnReady();
  5629. _this._startAnimations();
  5630. return resultFunc();
  5631. });
  5632. resultPromise.then(function () {
  5633. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  5634. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  5635. if (!_this._disposed) {
  5636. Promise.all(_this._completePromises).then(function () {
  5637. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  5638. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  5639. _this._parent.onCompleteObservable.notifyObservers(undefined);
  5640. _this._parent.onCompleteObservable.clear();
  5641. _this.dispose();
  5642. }, function (error) {
  5643. _this._parent.onErrorObservable.notifyObservers(error);
  5644. _this._parent.onErrorObservable.clear();
  5645. _this.dispose();
  5646. });
  5647. }
  5648. });
  5649. });
  5650. return resultPromise;
  5651. }, function (error) {
  5652. if (!_this._disposed) {
  5653. _this._parent.onErrorObservable.notifyObservers(error);
  5654. _this._parent.onErrorObservable.clear();
  5655. _this.dispose();
  5656. }
  5657. throw error;
  5658. });
  5659. };
  5660. GLTFLoader.prototype._loadData = function (data) {
  5661. this._gltf = data.json;
  5662. this._setupData();
  5663. if (data.bin) {
  5664. var buffers = this._gltf.buffers;
  5665. if (buffers && buffers[0] && !buffers[0].uri) {
  5666. var binaryBuffer = buffers[0];
  5667. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  5668. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  5669. }
  5670. this._bin = data.bin;
  5671. }
  5672. else {
  5673. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  5674. }
  5675. }
  5676. };
  5677. GLTFLoader.prototype._setupData = function () {
  5678. ArrayItem.Assign(this._gltf.accessors);
  5679. ArrayItem.Assign(this._gltf.animations);
  5680. ArrayItem.Assign(this._gltf.buffers);
  5681. ArrayItem.Assign(this._gltf.bufferViews);
  5682. ArrayItem.Assign(this._gltf.cameras);
  5683. ArrayItem.Assign(this._gltf.images);
  5684. ArrayItem.Assign(this._gltf.materials);
  5685. ArrayItem.Assign(this._gltf.meshes);
  5686. ArrayItem.Assign(this._gltf.nodes);
  5687. ArrayItem.Assign(this._gltf.samplers);
  5688. ArrayItem.Assign(this._gltf.scenes);
  5689. ArrayItem.Assign(this._gltf.skins);
  5690. ArrayItem.Assign(this._gltf.textures);
  5691. if (this._gltf.nodes) {
  5692. var nodeParents = {};
  5693. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  5694. var node = _a[_i];
  5695. if (node.children) {
  5696. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  5697. var index = _c[_b];
  5698. nodeParents[index] = node.index;
  5699. }
  5700. }
  5701. }
  5702. var rootNode = this._createRootNode();
  5703. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  5704. var node = _e[_d];
  5705. var parentIndex = nodeParents[node.index];
  5706. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  5707. }
  5708. }
  5709. };
  5710. GLTFLoader.prototype._loadExtensions = function () {
  5711. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  5712. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  5713. if (extension.name !== name_2) {
  5714. 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);
  5715. }
  5716. this._extensions.push(extension);
  5717. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  5718. }
  5719. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  5720. this._parent.onExtensionLoadedObservable.clear();
  5721. };
  5722. GLTFLoader.prototype._checkExtensions = function () {
  5723. if (this._gltf.extensionsRequired) {
  5724. var _loop_1 = function (name_3) {
  5725. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  5726. if (!available) {
  5727. throw new Error("Require extension " + name_3 + " is not available");
  5728. }
  5729. };
  5730. var this_1 = this;
  5731. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  5732. var name_3 = _a[_i];
  5733. _loop_1(name_3);
  5734. }
  5735. }
  5736. };
  5737. GLTFLoader.prototype._setState = function (state) {
  5738. this._state = state;
  5739. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  5740. };
  5741. GLTFLoader.prototype._createRootNode = function () {
  5742. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  5743. this._rootBabylonMesh.setEnabled(false);
  5744. var rootNode = {
  5745. _babylonTransformNode: this._rootBabylonMesh,
  5746. index: -1
  5747. };
  5748. switch (this._parent.coordinateSystemMode) {
  5749. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  5750. if (!this._babylonScene.useRightHandedSystem) {
  5751. rootNode.rotation = [0, 1, 0, 0];
  5752. rootNode.scale = [1, 1, -1];
  5753. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  5754. }
  5755. break;
  5756. }
  5757. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  5758. this._babylonScene.useRightHandedSystem = true;
  5759. break;
  5760. }
  5761. default: {
  5762. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  5763. }
  5764. }
  5765. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  5766. return rootNode;
  5767. };
  5768. /**
  5769. * Loads a glTF scene.
  5770. * @param context The context when loading the asset
  5771. * @param scene The glTF scene property
  5772. * @returns A promise that resolves when the load is complete
  5773. */
  5774. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  5775. var _this = this;
  5776. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  5777. if (extensionPromise) {
  5778. return extensionPromise;
  5779. }
  5780. var promises = new Array();
  5781. this.logOpen(context + " " + (scene.name || ""));
  5782. if (scene.nodes) {
  5783. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  5784. var index = _a[_i];
  5785. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  5786. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  5787. babylonMesh.parent = _this._rootBabylonMesh;
  5788. }));
  5789. }
  5790. }
  5791. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  5792. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  5793. if (this._gltf.nodes) {
  5794. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  5795. var node = _c[_b];
  5796. if (node._babylonTransformNode && node._babylonBones) {
  5797. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  5798. var babylonBone = _e[_d];
  5799. babylonBone.linkTransformNode(node._babylonTransformNode);
  5800. }
  5801. }
  5802. }
  5803. }
  5804. promises.push(this._loadAnimationsAsync());
  5805. this.logClose();
  5806. return Promise.all(promises).then(function () { });
  5807. };
  5808. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  5809. if (node._primitiveBabylonMeshes) {
  5810. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  5811. var babylonMesh = _a[_i];
  5812. callback(babylonMesh);
  5813. }
  5814. }
  5815. };
  5816. GLTFLoader.prototype._getMeshes = function () {
  5817. var meshes = new Array();
  5818. // Root mesh is always first.
  5819. meshes.push(this._rootBabylonMesh);
  5820. var nodes = this._gltf.nodes;
  5821. if (nodes) {
  5822. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  5823. var node = nodes_1[_i];
  5824. this._forEachPrimitive(node, function (babylonMesh) {
  5825. meshes.push(babylonMesh);
  5826. });
  5827. }
  5828. }
  5829. return meshes;
  5830. };
  5831. GLTFLoader.prototype._getSkeletons = function () {
  5832. var skeletons = new Array();
  5833. var skins = this._gltf.skins;
  5834. if (skins) {
  5835. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  5836. var skin = skins_1[_i];
  5837. if (skin._data) {
  5838. skeletons.push(skin._data.babylonSkeleton);
  5839. }
  5840. }
  5841. }
  5842. return skeletons;
  5843. };
  5844. GLTFLoader.prototype._getAnimationGroups = function () {
  5845. var animationGroups = new Array();
  5846. var animations = this._gltf.animations;
  5847. if (animations) {
  5848. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  5849. var animation = animations_1[_i];
  5850. if (animation._babylonAnimationGroup) {
  5851. animationGroups.push(animation._babylonAnimationGroup);
  5852. }
  5853. }
  5854. }
  5855. return animationGroups;
  5856. };
  5857. GLTFLoader.prototype._startAnimations = function () {
  5858. switch (this._parent.animationStartMode) {
  5859. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  5860. // do nothing
  5861. break;
  5862. }
  5863. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  5864. var babylonAnimationGroups = this._getAnimationGroups();
  5865. if (babylonAnimationGroups.length !== 0) {
  5866. babylonAnimationGroups[0].start(true);
  5867. }
  5868. break;
  5869. }
  5870. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  5871. var babylonAnimationGroups = this._getAnimationGroups();
  5872. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  5873. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  5874. babylonAnimationGroup.start(true);
  5875. }
  5876. break;
  5877. }
  5878. default: {
  5879. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  5880. return;
  5881. }
  5882. }
  5883. };
  5884. /**
  5885. * Loads a glTF node.
  5886. * @param context The context when loading the asset
  5887. * @param node The glTF node property
  5888. * @param assign A function called synchronously after parsing the glTF properties
  5889. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  5890. */
  5891. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  5892. var _this = this;
  5893. if (assign === void 0) { assign = function () { }; }
  5894. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  5895. if (extensionPromise) {
  5896. return extensionPromise;
  5897. }
  5898. if (node._babylonTransformNode) {
  5899. throw new Error(context + ": Invalid recursive node hierarchy");
  5900. }
  5901. var promises = new Array();
  5902. this.logOpen(context + " " + (node.name || ""));
  5903. var loadNode = function (babylonTransformNode) {
  5904. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  5905. GLTFLoader._LoadTransform(node, babylonTransformNode);
  5906. if (node.camera != undefined) {
  5907. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  5908. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  5909. babylonCamera.parent = babylonTransformNode;
  5910. }));
  5911. }
  5912. if (node.children) {
  5913. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  5914. var index = _a[_i];
  5915. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  5916. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  5917. childBabylonMesh.parent = babylonTransformNode;
  5918. }));
  5919. }
  5920. }
  5921. assign(babylonTransformNode);
  5922. };
  5923. if (node.mesh == undefined) {
  5924. var nodeName = node.name || "node" + node.index;
  5925. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  5926. loadNode(node._babylonTransformNode);
  5927. }
  5928. else {
  5929. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  5930. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  5931. }
  5932. this.logClose();
  5933. return Promise.all(promises).then(function () {
  5934. _this._forEachPrimitive(node, function (babylonMesh) {
  5935. babylonMesh.refreshBoundingInfo(true);
  5936. });
  5937. return node._babylonTransformNode;
  5938. });
  5939. };
  5940. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  5941. var primitives = mesh.primitives;
  5942. if (!primitives || !primitives.length) {
  5943. throw new Error(context + ": Primitives are missing");
  5944. }
  5945. if (primitives[0].index == undefined) {
  5946. ArrayItem.Assign(primitives);
  5947. }
  5948. var promises = new Array();
  5949. this.logOpen(context + " " + (mesh.name || ""));
  5950. var name = node.name || "node" + node.index;
  5951. if (primitives.length === 1) {
  5952. var primitive = mesh.primitives[0];
  5953. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  5954. node._babylonTransformNode = babylonMesh;
  5955. node._primitiveBabylonMeshes = [babylonMesh];
  5956. }));
  5957. }
  5958. else {
  5959. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  5960. node._primitiveBabylonMeshes = [];
  5961. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  5962. var primitive = primitives_1[_i];
  5963. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  5964. babylonMesh.parent = node._babylonTransformNode;
  5965. node._primitiveBabylonMeshes.push(babylonMesh);
  5966. }));
  5967. }
  5968. }
  5969. if (node.skin != undefined) {
  5970. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  5971. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  5972. }
  5973. assign(node._babylonTransformNode);
  5974. this.logClose();
  5975. return Promise.all(promises).then(function () {
  5976. return node._babylonTransformNode;
  5977. });
  5978. };
  5979. /**
  5980. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  5981. * @param context The context when loading the asset
  5982. * @param name The mesh name when loading the asset
  5983. * @param node The glTF node when loading the asset
  5984. * @param mesh The glTF mesh when loading the asset
  5985. * @param primitive The glTF mesh primitive property
  5986. * @param assign A function called synchronously after parsing the glTF properties
  5987. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  5988. */
  5989. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  5990. var _this = this;
  5991. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  5992. if (extensionPromise) {
  5993. return extensionPromise;
  5994. }
  5995. this.logOpen("" + context);
  5996. var shouldInstance = this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  5997. var babylonAbstractMesh;
  5998. var promise;
  5999. if (shouldInstance && primitive._instanceData) {
  6000. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  6001. promise = primitive._instanceData.promise;
  6002. }
  6003. else {
  6004. var promises = new Array();
  6005. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  6006. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  6007. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  6008. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  6009. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  6010. babylonGeometry.applyToMesh(babylonMesh_1);
  6011. });
  6012. }));
  6013. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  6014. if (primitive.material == undefined) {
  6015. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  6016. if (!babylonMaterial) {
  6017. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  6018. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6019. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  6020. }
  6021. babylonMesh_1.material = babylonMaterial;
  6022. }
  6023. else {
  6024. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  6025. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  6026. babylonMesh_1.material = babylonMaterial;
  6027. }));
  6028. }
  6029. promise = Promise.all(promises);
  6030. if (shouldInstance) {
  6031. primitive._instanceData = {
  6032. babylonSourceMesh: babylonMesh_1,
  6033. promise: promise
  6034. };
  6035. }
  6036. babylonAbstractMesh = babylonMesh_1;
  6037. }
  6038. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  6039. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  6040. assign(babylonAbstractMesh);
  6041. this.logClose();
  6042. return promise.then(function () {
  6043. return babylonAbstractMesh;
  6044. });
  6045. };
  6046. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  6047. var _this = this;
  6048. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  6049. if (extensionPromise) {
  6050. return extensionPromise;
  6051. }
  6052. var attributes = primitive.attributes;
  6053. if (!attributes) {
  6054. throw new Error(context + ": Attributes are missing");
  6055. }
  6056. var promises = new Array();
  6057. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  6058. if (primitive.indices == undefined) {
  6059. babylonMesh.isUnIndexed = true;
  6060. }
  6061. else {
  6062. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6063. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6064. babylonGeometry.setIndices(data);
  6065. }));
  6066. }
  6067. var loadAttribute = function (attribute, kind, callback) {
  6068. if (attributes[attribute] == undefined) {
  6069. return;
  6070. }
  6071. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6072. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6073. babylonMesh._delayInfo.push(kind);
  6074. }
  6075. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6076. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6077. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6078. }));
  6079. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6080. babylonMesh.numBoneInfluencers = 8;
  6081. }
  6082. if (callback) {
  6083. callback(accessor);
  6084. }
  6085. };
  6086. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6087. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6088. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6089. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6090. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6091. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6092. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6093. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  6094. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  6095. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6096. if (accessor.type === "VEC4" /* VEC4 */) {
  6097. babylonMesh.hasVertexAlpha = true;
  6098. }
  6099. });
  6100. return Promise.all(promises).then(function () {
  6101. return babylonGeometry;
  6102. });
  6103. };
  6104. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6105. if (!primitive.targets) {
  6106. return;
  6107. }
  6108. if (node._numMorphTargets == undefined) {
  6109. node._numMorphTargets = primitive.targets.length;
  6110. }
  6111. else if (primitive.targets.length !== node._numMorphTargets) {
  6112. throw new Error(context + ": Primitives do not have the same number of targets");
  6113. }
  6114. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6115. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6116. for (var index = 0; index < primitive.targets.length; index++) {
  6117. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6118. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6119. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6120. // TODO: tell the target whether it has positions, normals, tangents
  6121. }
  6122. };
  6123. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6124. if (!primitive.targets) {
  6125. return Promise.resolve();
  6126. }
  6127. var promises = new Array();
  6128. var morphTargetManager = babylonMesh.morphTargetManager;
  6129. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6130. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6131. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6132. }
  6133. return Promise.all(promises).then(function () { });
  6134. };
  6135. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6136. var _this = this;
  6137. var promises = new Array();
  6138. var loadAttribute = function (attribute, kind, setData) {
  6139. if (attributes[attribute] == undefined) {
  6140. return;
  6141. }
  6142. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6143. if (!babylonVertexBuffer) {
  6144. return;
  6145. }
  6146. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6147. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6148. setData(babylonVertexBuffer, data);
  6149. }));
  6150. };
  6151. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6152. var positions = new Float32Array(data.length);
  6153. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6154. positions[index] = data[index] + value;
  6155. });
  6156. babylonMorphTarget.setPositions(positions);
  6157. });
  6158. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6159. var normals = new Float32Array(data.length);
  6160. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6161. normals[index] = data[index] + value;
  6162. });
  6163. babylonMorphTarget.setNormals(normals);
  6164. });
  6165. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6166. var tangents = new Float32Array(data.length / 3 * 4);
  6167. var dataIndex = 0;
  6168. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6169. // Tangent data for morph targets is stored as xyz delta.
  6170. // The vertexData.tangent is stored as xyzw.
  6171. // So we need to skip every fourth vertexData.tangent.
  6172. if (((index + 1) % 4) !== 0) {
  6173. tangents[dataIndex] = data[dataIndex] + value;
  6174. dataIndex++;
  6175. }
  6176. });
  6177. babylonMorphTarget.setTangents(tangents);
  6178. });
  6179. return Promise.all(promises).then(function () { });
  6180. };
  6181. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6182. // Ignore the TRS of skinned nodes.
  6183. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6184. if (node.skin != undefined) {
  6185. return;
  6186. }
  6187. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6188. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6189. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6190. if (node.matrix) {
  6191. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6192. matrix.decompose(scaling, rotation, position);
  6193. }
  6194. else {
  6195. if (node.translation) {
  6196. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6197. }
  6198. if (node.rotation) {
  6199. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6200. }
  6201. if (node.scale) {
  6202. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6203. }
  6204. }
  6205. babylonNode.position = position;
  6206. babylonNode.rotationQuaternion = rotation;
  6207. babylonNode.scaling = scaling;
  6208. };
  6209. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6210. var _this = this;
  6211. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6212. if (extensionPromise) {
  6213. return extensionPromise;
  6214. }
  6215. var assignSkeleton = function (skeleton) {
  6216. _this._forEachPrimitive(node, function (babylonMesh) {
  6217. babylonMesh.skeleton = skeleton;
  6218. });
  6219. };
  6220. if (skin._data) {
  6221. assignSkeleton(skin._data.babylonSkeleton);
  6222. return skin._data.promise;
  6223. }
  6224. var skeletonId = "skeleton" + skin.index;
  6225. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6226. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6227. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6228. this._loadBones(context, skin, babylonSkeleton);
  6229. assignSkeleton(babylonSkeleton);
  6230. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6231. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6232. });
  6233. skin._data = {
  6234. babylonSkeleton: babylonSkeleton,
  6235. promise: promise
  6236. };
  6237. return promise;
  6238. };
  6239. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6240. var babylonBones = {};
  6241. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6242. var index = _a[_i];
  6243. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6244. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6245. }
  6246. };
  6247. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6248. var babylonBone = babylonBones[node.index];
  6249. if (babylonBone) {
  6250. return babylonBone;
  6251. }
  6252. var babylonParentBone = null;
  6253. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6254. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6255. }
  6256. var boneIndex = skin.joints.indexOf(node.index);
  6257. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6258. babylonBones[node.index] = babylonBone;
  6259. node._babylonBones = node._babylonBones || [];
  6260. node._babylonBones.push(babylonBone);
  6261. return babylonBone;
  6262. };
  6263. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6264. if (skin.inverseBindMatrices == undefined) {
  6265. return Promise.resolve(null);
  6266. }
  6267. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6268. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6269. };
  6270. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6271. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6272. var babylonBone = _a[_i];
  6273. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6274. var boneIndex = babylonBone._index;
  6275. if (inverseBindMatricesData && boneIndex !== -1) {
  6276. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6277. baseMatrix.invertToRef(baseMatrix);
  6278. }
  6279. var babylonParentBone = babylonBone.getParent();
  6280. if (babylonParentBone) {
  6281. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6282. }
  6283. babylonBone.updateMatrix(baseMatrix, false, false);
  6284. babylonBone._updateDifferenceMatrix(undefined, false);
  6285. }
  6286. };
  6287. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6288. return node.matrix ?
  6289. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6290. 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());
  6291. };
  6292. /**
  6293. * Loads a glTF camera.
  6294. * @param context The context when loading the asset
  6295. * @param camera The glTF camera property
  6296. * @param assign A function called synchronously after parsing the glTF properties
  6297. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6298. */
  6299. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6300. if (assign === void 0) { assign = function () { }; }
  6301. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6302. if (extensionPromise) {
  6303. return extensionPromise;
  6304. }
  6305. var promises = new Array();
  6306. this.logOpen(context + " " + (camera.name || ""));
  6307. 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);
  6308. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6309. switch (camera.type) {
  6310. case "perspective" /* PERSPECTIVE */: {
  6311. var perspective = camera.perspective;
  6312. if (!perspective) {
  6313. throw new Error(context + ": Camera perspective properties are missing");
  6314. }
  6315. babylonCamera.fov = perspective.yfov;
  6316. babylonCamera.minZ = perspective.znear;
  6317. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6318. break;
  6319. }
  6320. case "orthographic" /* ORTHOGRAPHIC */: {
  6321. if (!camera.orthographic) {
  6322. throw new Error(context + ": Camera orthographic properties are missing");
  6323. }
  6324. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6325. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6326. babylonCamera.orthoRight = camera.orthographic.xmag;
  6327. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6328. babylonCamera.orthoTop = camera.orthographic.ymag;
  6329. babylonCamera.minZ = camera.orthographic.znear;
  6330. babylonCamera.maxZ = camera.orthographic.zfar;
  6331. break;
  6332. }
  6333. default: {
  6334. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6335. }
  6336. }
  6337. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6338. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6339. assign(babylonCamera);
  6340. return Promise.all(promises).then(function () {
  6341. return babylonCamera;
  6342. });
  6343. };
  6344. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6345. var animations = this._gltf.animations;
  6346. if (!animations) {
  6347. return Promise.resolve();
  6348. }
  6349. var promises = new Array();
  6350. for (var index = 0; index < animations.length; index++) {
  6351. var animation = animations[index];
  6352. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6353. }
  6354. return Promise.all(promises).then(function () { });
  6355. };
  6356. /**
  6357. * Loads a glTF animation.
  6358. * @param context The context when loading the asset
  6359. * @param animation The glTF animation property
  6360. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6361. */
  6362. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6363. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6364. if (promise) {
  6365. return promise;
  6366. }
  6367. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6368. animation._babylonAnimationGroup = babylonAnimationGroup;
  6369. var promises = new Array();
  6370. ArrayItem.Assign(animation.channels);
  6371. ArrayItem.Assign(animation.samplers);
  6372. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6373. var channel = _a[_i];
  6374. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6375. }
  6376. return Promise.all(promises).then(function () {
  6377. babylonAnimationGroup.normalize(0);
  6378. return babylonAnimationGroup;
  6379. });
  6380. };
  6381. /**
  6382. * @hidden Loads a glTF animation channel.
  6383. * @param context The context when loading the asset
  6384. * @param animationContext The context of the animation when loading the asset
  6385. * @param animation The glTF animation property
  6386. * @param channel The glTF animation channel property
  6387. * @param babylonAnimationGroup The babylon animation group property
  6388. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6389. * @returns A void promise when the channel load is complete
  6390. */
  6391. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6392. var _this = this;
  6393. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6394. if (channel.target.node == undefined) {
  6395. return Promise.resolve();
  6396. }
  6397. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6398. // Ignore animations that have no animation targets.
  6399. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6400. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6401. return Promise.resolve();
  6402. }
  6403. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6404. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6405. var targetPath;
  6406. var animationType;
  6407. switch (channel.target.path) {
  6408. case "translation" /* TRANSLATION */: {
  6409. targetPath = "position";
  6410. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6411. break;
  6412. }
  6413. case "rotation" /* ROTATION */: {
  6414. targetPath = "rotationQuaternion";
  6415. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  6416. break;
  6417. }
  6418. case "scale" /* SCALE */: {
  6419. targetPath = "scaling";
  6420. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6421. break;
  6422. }
  6423. case "weights" /* WEIGHTS */: {
  6424. targetPath = "influence";
  6425. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  6426. break;
  6427. }
  6428. default: {
  6429. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  6430. }
  6431. }
  6432. var outputBufferOffset = 0;
  6433. var getNextOutputValue;
  6434. switch (targetPath) {
  6435. case "position": {
  6436. getNextOutputValue = function () {
  6437. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6438. outputBufferOffset += 3;
  6439. return value;
  6440. };
  6441. break;
  6442. }
  6443. case "rotationQuaternion": {
  6444. getNextOutputValue = function () {
  6445. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  6446. outputBufferOffset += 4;
  6447. return value;
  6448. };
  6449. break;
  6450. }
  6451. case "scaling": {
  6452. getNextOutputValue = function () {
  6453. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6454. outputBufferOffset += 3;
  6455. return value;
  6456. };
  6457. break;
  6458. }
  6459. case "influence": {
  6460. getNextOutputValue = function () {
  6461. var value = new Array(targetNode._numMorphTargets);
  6462. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  6463. value[i] = data.output[outputBufferOffset++];
  6464. }
  6465. return value;
  6466. };
  6467. break;
  6468. }
  6469. }
  6470. var getNextKey;
  6471. switch (data.interpolation) {
  6472. case "STEP" /* STEP */: {
  6473. getNextKey = function (frameIndex) { return ({
  6474. frame: data.input[frameIndex],
  6475. value: getNextOutputValue(),
  6476. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  6477. }); };
  6478. break;
  6479. }
  6480. case "LINEAR" /* LINEAR */: {
  6481. getNextKey = function (frameIndex) { return ({
  6482. frame: data.input[frameIndex],
  6483. value: getNextOutputValue()
  6484. }); };
  6485. break;
  6486. }
  6487. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6488. getNextKey = function (frameIndex) { return ({
  6489. frame: data.input[frameIndex],
  6490. inTangent: getNextOutputValue(),
  6491. value: getNextOutputValue(),
  6492. outTangent: getNextOutputValue()
  6493. }); };
  6494. break;
  6495. }
  6496. }
  6497. var keys = new Array(data.input.length);
  6498. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  6499. keys[frameIndex] = getNextKey(frameIndex);
  6500. }
  6501. if (targetPath === "influence") {
  6502. var _loop_2 = function (targetIndex) {
  6503. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6504. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6505. babylonAnimation.setKeys(keys.map(function (key) { return ({
  6506. frame: key.frame,
  6507. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  6508. value: key.value[targetIndex],
  6509. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  6510. }); }));
  6511. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  6512. var babylonMesh = babylonAbstractMesh;
  6513. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  6514. var babylonAnimationClone = babylonAnimation.clone();
  6515. morphTarget.animations.push(babylonAnimationClone);
  6516. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  6517. });
  6518. };
  6519. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  6520. _loop_2(targetIndex);
  6521. }
  6522. }
  6523. else {
  6524. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6525. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6526. babylonAnimation.setKeys(keys);
  6527. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  6528. animationTargetOverride.animations.push(babylonAnimation);
  6529. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  6530. }
  6531. else {
  6532. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  6533. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  6534. }
  6535. }
  6536. });
  6537. };
  6538. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  6539. if (sampler._data) {
  6540. return sampler._data;
  6541. }
  6542. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  6543. switch (interpolation) {
  6544. case "STEP" /* STEP */:
  6545. case "LINEAR" /* LINEAR */:
  6546. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6547. break;
  6548. }
  6549. default: {
  6550. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  6551. }
  6552. }
  6553. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  6554. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  6555. sampler._data = Promise.all([
  6556. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  6557. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  6558. ]).then(function (_a) {
  6559. var inputData = _a[0], outputData = _a[1];
  6560. return {
  6561. input: inputData,
  6562. interpolation: interpolation,
  6563. output: outputData,
  6564. };
  6565. });
  6566. return sampler._data;
  6567. };
  6568. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6569. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  6570. if (extensionPromise) {
  6571. return extensionPromise;
  6572. }
  6573. if (!buffer._data) {
  6574. if (buffer.uri) {
  6575. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  6576. }
  6577. else {
  6578. if (!this._bin) {
  6579. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6580. }
  6581. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  6582. }
  6583. }
  6584. return buffer._data.then(function (data) {
  6585. try {
  6586. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  6587. }
  6588. catch (e) {
  6589. throw new Error(context + ": " + e.message);
  6590. }
  6591. });
  6592. };
  6593. /**
  6594. * Loads a glTF buffer view.
  6595. * @param context The context when loading the asset
  6596. * @param bufferView The glTF buffer view property
  6597. * @returns A promise that resolves with the loaded data when the load is complete
  6598. */
  6599. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  6600. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  6601. if (extensionPromise) {
  6602. return extensionPromise;
  6603. }
  6604. if (bufferView._data) {
  6605. return bufferView._data;
  6606. }
  6607. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  6608. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  6609. return bufferView._data;
  6610. };
  6611. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  6612. var _this = this;
  6613. if (accessor._data) {
  6614. return accessor._data;
  6615. }
  6616. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  6617. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  6618. var length = numComponents * accessor.count;
  6619. if (accessor.bufferView == undefined) {
  6620. accessor._data = Promise.resolve(new constructor(length));
  6621. }
  6622. else {
  6623. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6624. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  6625. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6626. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  6627. }
  6628. else {
  6629. var typedArray_1 = new constructor(length);
  6630. 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) {
  6631. typedArray_1[index] = value;
  6632. });
  6633. return typedArray_1;
  6634. }
  6635. });
  6636. }
  6637. if (accessor.sparse) {
  6638. var sparse_1 = accessor.sparse;
  6639. accessor._data = accessor._data.then(function (data) {
  6640. var typedArray = data;
  6641. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  6642. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  6643. return Promise.all([
  6644. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  6645. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  6646. ]).then(function (_a) {
  6647. var indicesData = _a[0], valuesData = _a[1];
  6648. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  6649. var sparseLength = numComponents * sparse_1.count;
  6650. var values;
  6651. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6652. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6653. }
  6654. else {
  6655. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6656. values = new constructor(sparseLength);
  6657. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  6658. values[index] = value;
  6659. });
  6660. }
  6661. var valuesIndex = 0;
  6662. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  6663. var dataIndex = indices[indicesIndex] * numComponents;
  6664. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  6665. typedArray[dataIndex++] = values[valuesIndex++];
  6666. }
  6667. }
  6668. return typedArray;
  6669. });
  6670. });
  6671. }
  6672. return accessor._data;
  6673. };
  6674. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  6675. return this._loadAccessorAsync(context, accessor, Float32Array);
  6676. };
  6677. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  6678. if (accessor.type !== "SCALAR" /* SCALAR */) {
  6679. throw new Error(context + "/type: Invalid value " + accessor.type);
  6680. }
  6681. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  6682. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  6683. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  6684. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  6685. }
  6686. if (accessor._data) {
  6687. return accessor._data;
  6688. }
  6689. if (accessor.sparse) {
  6690. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  6691. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  6692. }
  6693. else {
  6694. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6695. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6696. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  6697. });
  6698. }
  6699. return accessor._data;
  6700. };
  6701. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  6702. var _this = this;
  6703. if (bufferView._babylonBuffer) {
  6704. return bufferView._babylonBuffer;
  6705. }
  6706. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6707. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  6708. });
  6709. return bufferView._babylonBuffer;
  6710. };
  6711. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  6712. var _this = this;
  6713. if (accessor._babylonVertexBuffer) {
  6714. return accessor._babylonVertexBuffer;
  6715. }
  6716. if (accessor.sparse) {
  6717. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6718. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6719. });
  6720. }
  6721. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  6722. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  6723. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  6724. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6725. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6726. });
  6727. }
  6728. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  6729. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  6730. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6731. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6732. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6733. });
  6734. }
  6735. else {
  6736. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6737. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  6738. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  6739. 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);
  6740. });
  6741. }
  6742. return accessor._babylonVertexBuffer;
  6743. };
  6744. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  6745. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6746. throw new Error(context + ": Material type not supported");
  6747. }
  6748. var promises = new Array();
  6749. if (properties) {
  6750. if (properties.baseColorFactor) {
  6751. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  6752. babylonMaterial.alpha = properties.baseColorFactor[3];
  6753. }
  6754. else {
  6755. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  6756. }
  6757. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  6758. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  6759. if (properties.baseColorTexture) {
  6760. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  6761. texture.name = babylonMaterial.name + " (Base Color)";
  6762. babylonMaterial.albedoTexture = texture;
  6763. }));
  6764. }
  6765. if (properties.metallicRoughnessTexture) {
  6766. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  6767. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  6768. babylonMaterial.metallicTexture = texture;
  6769. }));
  6770. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  6771. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  6772. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  6773. }
  6774. }
  6775. return Promise.all(promises).then(function () { });
  6776. };
  6777. /** @hidden */
  6778. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6779. if (assign === void 0) { assign = function () { }; }
  6780. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  6781. if (extensionPromise) {
  6782. return extensionPromise;
  6783. }
  6784. material._data = material._data || {};
  6785. var babylonData = material._data[babylonDrawMode];
  6786. if (!babylonData) {
  6787. this.logOpen(context + " " + (material.name || ""));
  6788. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  6789. babylonData = {
  6790. babylonMaterial: babylonMaterial,
  6791. babylonMeshes: [],
  6792. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  6793. };
  6794. material._data[babylonDrawMode] = babylonData;
  6795. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  6796. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6797. this.logClose();
  6798. }
  6799. babylonData.babylonMeshes.push(babylonMesh);
  6800. babylonMesh.onDisposeObservable.addOnce(function () {
  6801. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  6802. if (index !== -1) {
  6803. babylonData.babylonMeshes.splice(index, 1);
  6804. }
  6805. });
  6806. assign(babylonData.babylonMaterial);
  6807. return babylonData.promise.then(function () {
  6808. return babylonData.babylonMaterial;
  6809. });
  6810. };
  6811. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  6812. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  6813. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  6814. babylonMaterial.fillMode = babylonDrawMode;
  6815. babylonMaterial.enableSpecularAntiAliasing = true;
  6816. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  6817. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  6818. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6819. babylonMaterial.metallic = 1;
  6820. babylonMaterial.roughness = 1;
  6821. return babylonMaterial;
  6822. };
  6823. /**
  6824. * Creates a Babylon material from a glTF material.
  6825. * @param context The context when loading the asset
  6826. * @param material The glTF material property
  6827. * @param babylonDrawMode The draw mode for the Babylon material
  6828. * @returns The Babylon material
  6829. */
  6830. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  6831. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  6832. if (extensionPromise) {
  6833. return extensionPromise;
  6834. }
  6835. var name = material.name || "material" + material.index;
  6836. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  6837. return babylonMaterial;
  6838. };
  6839. /**
  6840. * Loads properties from a glTF material into a Babylon material.
  6841. * @param context The context when loading the asset
  6842. * @param material The glTF material property
  6843. * @param babylonMaterial The Babylon material
  6844. * @returns A promise that resolves when the load is complete
  6845. */
  6846. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6847. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  6848. if (extensionPromise) {
  6849. return extensionPromise;
  6850. }
  6851. var promises = new Array();
  6852. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  6853. if (material.pbrMetallicRoughness) {
  6854. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  6855. }
  6856. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  6857. return Promise.all(promises).then(function () { });
  6858. };
  6859. /**
  6860. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  6861. * @param context The context when loading the asset
  6862. * @param material The glTF material property
  6863. * @param babylonMaterial The Babylon material
  6864. * @returns A promise that resolves when the load is complete
  6865. */
  6866. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  6867. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6868. throw new Error(context + ": Material type not supported");
  6869. }
  6870. var promises = new Array();
  6871. 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);
  6872. if (material.doubleSided) {
  6873. babylonMaterial.backFaceCulling = false;
  6874. babylonMaterial.twoSidedLighting = true;
  6875. }
  6876. if (material.normalTexture) {
  6877. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  6878. texture.name = babylonMaterial.name + " (Normal)";
  6879. babylonMaterial.bumpTexture = texture;
  6880. }));
  6881. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  6882. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  6883. if (material.normalTexture.scale != undefined) {
  6884. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  6885. }
  6886. babylonMaterial.forceIrradianceInFragment = true;
  6887. }
  6888. if (material.occlusionTexture) {
  6889. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  6890. texture.name = babylonMaterial.name + " (Occlusion)";
  6891. babylonMaterial.ambientTexture = texture;
  6892. }));
  6893. babylonMaterial.useAmbientInGrayScale = true;
  6894. if (material.occlusionTexture.strength != undefined) {
  6895. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  6896. }
  6897. }
  6898. if (material.emissiveTexture) {
  6899. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  6900. texture.name = babylonMaterial.name + " (Emissive)";
  6901. babylonMaterial.emissiveTexture = texture;
  6902. }));
  6903. }
  6904. return Promise.all(promises).then(function () { });
  6905. };
  6906. /**
  6907. * Loads the alpha properties from a glTF material into a Babylon material.
  6908. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  6909. * @param context The context when loading the asset
  6910. * @param material The glTF material property
  6911. * @param babylonMaterial The Babylon material
  6912. */
  6913. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  6914. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6915. throw new Error(context + ": Material type not supported");
  6916. }
  6917. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  6918. switch (alphaMode) {
  6919. case "OPAQUE" /* OPAQUE */: {
  6920. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6921. break;
  6922. }
  6923. case "MASK" /* MASK */: {
  6924. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  6925. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  6926. if (babylonMaterial.albedoTexture) {
  6927. babylonMaterial.albedoTexture.hasAlpha = true;
  6928. }
  6929. break;
  6930. }
  6931. case "BLEND" /* BLEND */: {
  6932. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  6933. if (babylonMaterial.albedoTexture) {
  6934. babylonMaterial.albedoTexture.hasAlpha = true;
  6935. babylonMaterial.useAlphaFromAlbedoTexture = true;
  6936. }
  6937. break;
  6938. }
  6939. default: {
  6940. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  6941. }
  6942. }
  6943. };
  6944. /**
  6945. * Loads a glTF texture info.
  6946. * @param context The context when loading the asset
  6947. * @param textureInfo The glTF texture info property
  6948. * @param assign A function called synchronously after parsing the glTF properties
  6949. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  6950. */
  6951. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  6952. var _this = this;
  6953. if (assign === void 0) { assign = function () { }; }
  6954. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  6955. if (extensionPromise) {
  6956. return extensionPromise;
  6957. }
  6958. this.logOpen("" + context);
  6959. if (textureInfo.texCoord >= 2) {
  6960. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  6961. }
  6962. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  6963. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  6964. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  6965. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  6966. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  6967. assign(babylonTexture);
  6968. });
  6969. this.logClose();
  6970. return promise;
  6971. };
  6972. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  6973. var _this = this;
  6974. if (assign === void 0) { assign = function () { }; }
  6975. var promises = new Array();
  6976. this.logOpen(context + " " + (texture.name || ""));
  6977. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  6978. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  6979. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  6980. var url = null;
  6981. if (image.uri) {
  6982. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  6983. url = image.uri;
  6984. }
  6985. else if (this._babylonScene.getEngine().textureFormatInUse) {
  6986. // 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
  6987. url = this._rootUrl + image.uri;
  6988. }
  6989. }
  6990. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6991. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  6992. if (!_this._disposed) {
  6993. deferred.resolve();
  6994. }
  6995. }, function (message, exception) {
  6996. if (!_this._disposed) {
  6997. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  6998. }
  6999. }, undefined, undefined, undefined, image.mimeType);
  7000. promises.push(deferred.promise);
  7001. if (!url) {
  7002. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  7003. var name = image.uri || _this._fileName + "#image" + image.index;
  7004. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  7005. babylonTexture.updateURL(dataUrl, data);
  7006. }));
  7007. }
  7008. babylonTexture.wrapU = samplerData.wrapU;
  7009. babylonTexture.wrapV = samplerData.wrapV;
  7010. assign(babylonTexture);
  7011. this.logClose();
  7012. return Promise.all(promises).then(function () {
  7013. return babylonTexture;
  7014. });
  7015. };
  7016. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  7017. if (!sampler._data) {
  7018. sampler._data = {
  7019. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  7020. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  7021. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  7022. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  7023. };
  7024. }
  7025. return sampler._data;
  7026. };
  7027. /**
  7028. * Loads a glTF image.
  7029. * @param context The context when loading the asset
  7030. * @param image The glTF image property
  7031. * @returns A promise that resolves with the loaded data when the load is complete
  7032. */
  7033. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  7034. if (!image._data) {
  7035. this.logOpen(context + " " + (image.name || ""));
  7036. if (image.uri) {
  7037. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  7038. }
  7039. else {
  7040. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  7041. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  7042. }
  7043. this.logClose();
  7044. }
  7045. return image._data;
  7046. };
  7047. /**
  7048. * Loads a glTF uri.
  7049. * @param context The context when loading the asset
  7050. * @param property The glTF property associated with the uri
  7051. * @param uri The base64 or relative uri
  7052. * @returns A promise that resolves with the loaded data when the load is complete
  7053. */
  7054. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  7055. var _this = this;
  7056. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  7057. if (extensionPromise) {
  7058. return extensionPromise;
  7059. }
  7060. if (!GLTFLoader._ValidateUri(uri)) {
  7061. throw new Error(context + ": '" + uri + "' is invalid");
  7062. }
  7063. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7064. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7065. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7066. return Promise.resolve(data);
  7067. }
  7068. this.log("Loading " + uri);
  7069. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7070. return new Promise(function (resolve, reject) {
  7071. if (!_this._disposed) {
  7072. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  7073. if (!_this._disposed) {
  7074. var data = new Uint8Array(fileData);
  7075. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  7076. resolve(data);
  7077. }
  7078. }, function (event) {
  7079. if (!_this._disposed) {
  7080. if (request_1) {
  7081. request_1._lengthComputable = event.lengthComputable;
  7082. request_1._loaded = event.loaded;
  7083. request_1._total = event.total;
  7084. }
  7085. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  7086. try {
  7087. _this._onProgress();
  7088. }
  7089. catch (e) {
  7090. reject(e);
  7091. }
  7092. }
  7093. }
  7094. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  7095. if (!_this._disposed) {
  7096. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7097. }
  7098. });
  7099. _this._requests.push(request_1);
  7100. }
  7101. });
  7102. });
  7103. };
  7104. GLTFLoader.prototype._onProgress = function () {
  7105. if (!this._progressCallback) {
  7106. return;
  7107. }
  7108. var lengthComputable = true;
  7109. var loaded = 0;
  7110. var total = 0;
  7111. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  7112. var request = _a[_i];
  7113. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  7114. return;
  7115. }
  7116. lengthComputable = lengthComputable && request._lengthComputable;
  7117. loaded += request._loaded;
  7118. total += request._total;
  7119. }
  7120. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  7121. };
  7122. /**
  7123. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7124. * @param babylonObject the Babylon object with metadata
  7125. * @param pointer the JSON pointer
  7126. */
  7127. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7128. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7129. var gltf = (metadata.gltf = metadata.gltf || {});
  7130. var pointers = (gltf.pointers = gltf.pointers || []);
  7131. pointers.push(pointer);
  7132. };
  7133. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7134. // Set defaults if undefined
  7135. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7136. switch (mode) {
  7137. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7138. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7139. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7140. default:
  7141. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7142. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7143. }
  7144. };
  7145. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7146. // Set defaults if undefined
  7147. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7148. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7149. if (magFilter === 9729 /* LINEAR */) {
  7150. switch (minFilter) {
  7151. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7152. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7153. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7154. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7155. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7156. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7157. default:
  7158. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7159. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7160. }
  7161. }
  7162. else {
  7163. if (magFilter !== 9728 /* NEAREST */) {
  7164. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7165. }
  7166. switch (minFilter) {
  7167. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7168. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7169. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7170. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7171. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7172. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7173. default:
  7174. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7175. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7176. }
  7177. }
  7178. };
  7179. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7180. switch (componentType) {
  7181. case 5120 /* BYTE */: return Int8Array;
  7182. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7183. case 5122 /* SHORT */: return Int16Array;
  7184. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7185. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7186. case 5126 /* FLOAT */: return Float32Array;
  7187. default: throw new Error(context + ": Invalid component type " + componentType);
  7188. }
  7189. };
  7190. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7191. var buffer = bufferView.buffer;
  7192. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7193. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7194. try {
  7195. return new constructor(buffer, byteOffset, length);
  7196. }
  7197. catch (e) {
  7198. throw new Error(context + ": " + e);
  7199. }
  7200. };
  7201. GLTFLoader._GetNumComponents = function (context, type) {
  7202. switch (type) {
  7203. case "SCALAR": return 1;
  7204. case "VEC2": return 2;
  7205. case "VEC3": return 3;
  7206. case "VEC4": return 4;
  7207. case "MAT2": return 4;
  7208. case "MAT3": return 9;
  7209. case "MAT4": return 16;
  7210. }
  7211. throw new Error(context + ": Invalid type (" + type + ")");
  7212. };
  7213. GLTFLoader._ValidateUri = function (uri) {
  7214. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7215. };
  7216. GLTFLoader._GetDrawMode = function (context, mode) {
  7217. if (mode == undefined) {
  7218. mode = 4 /* TRIANGLES */;
  7219. }
  7220. switch (mode) {
  7221. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7222. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7223. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7224. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7225. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7226. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7227. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7228. }
  7229. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7230. };
  7231. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7232. var _this = this;
  7233. this._parent._startPerformanceCounter("Compile materials");
  7234. var promises = new Array();
  7235. if (this._gltf.materials) {
  7236. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7237. var material = _a[_i];
  7238. if (material._data) {
  7239. for (var babylonDrawMode in material._data) {
  7240. var babylonData = material._data[babylonDrawMode];
  7241. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7242. var babylonMesh = _c[_b];
  7243. // Ensure nonUniformScaling is set if necessary.
  7244. babylonMesh.computeWorldMatrix(true);
  7245. var babylonMaterial = babylonData.babylonMaterial;
  7246. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7247. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7248. if (this._parent.useClipPlane) {
  7249. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7250. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7251. }
  7252. }
  7253. }
  7254. }
  7255. }
  7256. }
  7257. return Promise.all(promises).then(function () {
  7258. _this._parent._endPerformanceCounter("Compile materials");
  7259. });
  7260. };
  7261. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7262. var _this = this;
  7263. this._parent._startPerformanceCounter("Compile shadow generators");
  7264. var promises = new Array();
  7265. var lights = this._babylonScene.lights;
  7266. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7267. var light = lights_1[_i];
  7268. var generator = light.getShadowGenerator();
  7269. if (generator) {
  7270. promises.push(generator.forceCompilationAsync());
  7271. }
  7272. }
  7273. return Promise.all(promises).then(function () {
  7274. _this._parent._endPerformanceCounter("Compile shadow generators");
  7275. });
  7276. };
  7277. GLTFLoader.prototype._forEachExtensions = function (action) {
  7278. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7279. var extension = _a[_i];
  7280. if (extension.enabled) {
  7281. action(extension);
  7282. }
  7283. }
  7284. };
  7285. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7286. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7287. var extension = _a[_i];
  7288. if (extension.enabled) {
  7289. var id = extension.name + "." + functionName;
  7290. var loaderProperty = property;
  7291. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7292. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7293. if (!activeLoaderExtensionFunctions[id]) {
  7294. activeLoaderExtensionFunctions[id] = true;
  7295. try {
  7296. var result = actionAsync(extension);
  7297. if (result) {
  7298. return result;
  7299. }
  7300. }
  7301. finally {
  7302. delete activeLoaderExtensionFunctions[id];
  7303. }
  7304. }
  7305. }
  7306. }
  7307. return null;
  7308. };
  7309. GLTFLoader.prototype._extensionsOnLoading = function () {
  7310. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7311. };
  7312. GLTFLoader.prototype._extensionsOnReady = function () {
  7313. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7314. };
  7315. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7316. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7317. };
  7318. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7319. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7320. };
  7321. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7322. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7323. };
  7324. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7325. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7326. };
  7327. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7328. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7329. };
  7330. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7331. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7332. };
  7333. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7334. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7335. };
  7336. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7337. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7338. };
  7339. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7340. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7341. };
  7342. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7343. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7344. };
  7345. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7346. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7347. };
  7348. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7349. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7350. };
  7351. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7352. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7353. };
  7354. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7355. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7356. };
  7357. /**
  7358. * Helper method called by a loader extension to load an glTF extension.
  7359. * @param context The context when loading the asset
  7360. * @param property The glTF property to load the extension from
  7361. * @param extensionName The name of the extension to load
  7362. * @param actionAsync The action to run
  7363. * @returns The promise returned by actionAsync or null if the extension does not exist
  7364. */
  7365. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7366. if (!property.extensions) {
  7367. return null;
  7368. }
  7369. var extensions = property.extensions;
  7370. var extension = extensions[extensionName];
  7371. if (!extension) {
  7372. return null;
  7373. }
  7374. return actionAsync(context + "/extensions/" + extensionName, extension);
  7375. };
  7376. /**
  7377. * Helper method called by a loader extension to load a glTF extra.
  7378. * @param context The context when loading the asset
  7379. * @param property The glTF property to load the extra from
  7380. * @param extensionName The name of the extension to load
  7381. * @param actionAsync The action to run
  7382. * @returns The promise returned by actionAsync or null if the extra does not exist
  7383. */
  7384. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7385. if (!property.extras) {
  7386. return null;
  7387. }
  7388. var extras = property.extras;
  7389. var extra = extras[extensionName];
  7390. if (!extra) {
  7391. return null;
  7392. }
  7393. return actionAsync(context + "/extras/" + extensionName, extra);
  7394. };
  7395. /**
  7396. * Checks for presence of an extension.
  7397. * @param name The name of the extension to check
  7398. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7399. */
  7400. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7401. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7402. };
  7403. /**
  7404. * Increments the indentation level and logs a message.
  7405. * @param message The message to log
  7406. */
  7407. GLTFLoader.prototype.logOpen = function (message) {
  7408. this._parent._logOpen(message);
  7409. };
  7410. /**
  7411. * Decrements the indentation level.
  7412. */
  7413. GLTFLoader.prototype.logClose = function () {
  7414. this._parent._logClose();
  7415. };
  7416. /**
  7417. * Logs a message
  7418. * @param message The message to log
  7419. */
  7420. GLTFLoader.prototype.log = function (message) {
  7421. this._parent._log(message);
  7422. };
  7423. /**
  7424. * Starts a performance counter.
  7425. * @param counterName The name of the performance counter
  7426. */
  7427. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7428. this._parent._startPerformanceCounter(counterName);
  7429. };
  7430. /**
  7431. * Ends a performance counter.
  7432. * @param counterName The name of the performance counter
  7433. */
  7434. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7435. this._parent._endPerformanceCounter(counterName);
  7436. };
  7437. GLTFLoader._DefaultSampler = { index: -1 };
  7438. GLTFLoader._RegisteredExtensions = {};
  7439. return GLTFLoader;
  7440. }());
  7441. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  7442. /***/ }),
  7443. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  7444. /*!******************************************!*\
  7445. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  7446. \******************************************/
  7447. /*! no static exports found */
  7448. /***/ (function(module, exports) {
  7449. /***/ }),
  7450. /***/ "./glTF/2.0/index.ts":
  7451. /*!***************************!*\
  7452. !*** ./glTF/2.0/index.ts ***!
  7453. \***************************/
  7454. /*! 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 */
  7455. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7456. "use strict";
  7457. __webpack_require__.r(__webpack_exports__);
  7458. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  7459. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  7460. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  7461. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  7462. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  7463. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  7464. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  7465. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  7466. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  7467. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  7468. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  7469. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  7470. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  7471. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  7472. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  7473. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  7474. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  7475. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  7476. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  7477. /***/ }),
  7478. /***/ "./glTF/glTFFileLoader.ts":
  7479. /*!********************************!*\
  7480. !*** ./glTF/glTFFileLoader.ts ***!
  7481. \********************************/
  7482. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  7483. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7484. "use strict";
  7485. __webpack_require__.r(__webpack_exports__);
  7486. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  7487. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  7488. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  7489. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  7490. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  7491. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  7492. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  7493. /**
  7494. * Mode that determines the coordinate system to use.
  7495. */
  7496. var GLTFLoaderCoordinateSystemMode;
  7497. (function (GLTFLoaderCoordinateSystemMode) {
  7498. /**
  7499. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  7500. */
  7501. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  7502. /**
  7503. * Sets the useRightHandedSystem flag on the scene.
  7504. */
  7505. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  7506. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  7507. /**
  7508. * Mode that determines what animations will start.
  7509. */
  7510. var GLTFLoaderAnimationStartMode;
  7511. (function (GLTFLoaderAnimationStartMode) {
  7512. /**
  7513. * No animation will start.
  7514. */
  7515. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  7516. /**
  7517. * The first animation will start.
  7518. */
  7519. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  7520. /**
  7521. * All animations will start.
  7522. */
  7523. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  7524. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  7525. /**
  7526. * Loader state.
  7527. */
  7528. var GLTFLoaderState;
  7529. (function (GLTFLoaderState) {
  7530. /**
  7531. * The asset is loading.
  7532. */
  7533. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  7534. /**
  7535. * The asset is ready for rendering.
  7536. */
  7537. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  7538. /**
  7539. * The asset is completely loaded.
  7540. */
  7541. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  7542. })(GLTFLoaderState || (GLTFLoaderState = {}));
  7543. /**
  7544. * File loader for loading glTF files into a scene.
  7545. */
  7546. var GLTFFileLoader = /** @class */ (function () {
  7547. function GLTFFileLoader() {
  7548. // --------------
  7549. // Common options
  7550. // --------------
  7551. /**
  7552. * Raised when the asset has been parsed
  7553. */
  7554. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7555. // ----------
  7556. // V2 options
  7557. // ----------
  7558. /**
  7559. * The coordinate system mode. Defaults to AUTO.
  7560. */
  7561. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  7562. /**
  7563. * The animation start mode. Defaults to FIRST.
  7564. */
  7565. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  7566. /**
  7567. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  7568. */
  7569. this.compileMaterials = false;
  7570. /**
  7571. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  7572. */
  7573. this.useClipPlane = false;
  7574. /**
  7575. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  7576. */
  7577. this.compileShadowGenerators = false;
  7578. /**
  7579. * Defines if the Alpha blended materials are only applied as coverage.
  7580. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  7581. * If true, no extra effects are applied to transparent pixels.
  7582. */
  7583. this.transparencyAsCoverage = false;
  7584. /**
  7585. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  7586. * Enabling will disable offline support and glTF validator.
  7587. * Defaults to false.
  7588. */
  7589. this.useRangeRequests = false;
  7590. /**
  7591. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  7592. */
  7593. this.createInstances = true;
  7594. /**
  7595. * Function called before loading a url referenced by the asset.
  7596. */
  7597. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7598. /**
  7599. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7600. */
  7601. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7602. /**
  7603. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  7604. */
  7605. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7606. /**
  7607. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  7608. */
  7609. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7610. /**
  7611. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  7612. */
  7613. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7614. /**
  7615. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  7616. * For assets with LODs, raised when all of the LODs are complete.
  7617. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7618. */
  7619. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7620. /**
  7621. * Observable raised when an error occurs.
  7622. */
  7623. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7624. /**
  7625. * Observable raised after the loader is disposed.
  7626. */
  7627. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7628. /**
  7629. * Observable raised after a loader extension is created.
  7630. * Set additional options for a loader extension in this event.
  7631. */
  7632. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7633. /**
  7634. * Defines if the loader should validate the asset.
  7635. */
  7636. this.validate = false;
  7637. /**
  7638. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  7639. */
  7640. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7641. this._loader = null;
  7642. /**
  7643. * Name of the loader ("gltf")
  7644. */
  7645. this.name = "gltf";
  7646. /** @hidden */
  7647. this.extensions = {
  7648. ".gltf": { isBinary: false },
  7649. ".glb": { isBinary: true }
  7650. };
  7651. this._logIndentLevel = 0;
  7652. this._loggingEnabled = false;
  7653. /** @hidden */
  7654. this._log = this._logDisabled;
  7655. this._capturePerformanceCounters = false;
  7656. /** @hidden */
  7657. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7658. /** @hidden */
  7659. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7660. }
  7661. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  7662. /**
  7663. * Raised when the asset has been parsed
  7664. */
  7665. set: function (callback) {
  7666. if (this._onParsedObserver) {
  7667. this.onParsedObservable.remove(this._onParsedObserver);
  7668. }
  7669. this._onParsedObserver = this.onParsedObservable.add(callback);
  7670. },
  7671. enumerable: true,
  7672. configurable: true
  7673. });
  7674. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  7675. /**
  7676. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7677. */
  7678. set: function (callback) {
  7679. if (this._onMeshLoadedObserver) {
  7680. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  7681. }
  7682. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  7683. },
  7684. enumerable: true,
  7685. configurable: true
  7686. });
  7687. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  7688. /**
  7689. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  7690. */
  7691. set: function (callback) {
  7692. if (this._onTextureLoadedObserver) {
  7693. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  7694. }
  7695. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  7696. },
  7697. enumerable: true,
  7698. configurable: true
  7699. });
  7700. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  7701. /**
  7702. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  7703. */
  7704. set: function (callback) {
  7705. if (this._onMaterialLoadedObserver) {
  7706. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  7707. }
  7708. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  7709. },
  7710. enumerable: true,
  7711. configurable: true
  7712. });
  7713. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  7714. /**
  7715. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  7716. */
  7717. set: function (callback) {
  7718. if (this._onCameraLoadedObserver) {
  7719. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  7720. }
  7721. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  7722. },
  7723. enumerable: true,
  7724. configurable: true
  7725. });
  7726. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  7727. /**
  7728. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  7729. * For assets with LODs, raised when all of the LODs are complete.
  7730. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7731. */
  7732. set: function (callback) {
  7733. if (this._onCompleteObserver) {
  7734. this.onCompleteObservable.remove(this._onCompleteObserver);
  7735. }
  7736. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  7737. },
  7738. enumerable: true,
  7739. configurable: true
  7740. });
  7741. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  7742. /**
  7743. * Callback raised when an error occurs.
  7744. */
  7745. set: function (callback) {
  7746. if (this._onErrorObserver) {
  7747. this.onErrorObservable.remove(this._onErrorObserver);
  7748. }
  7749. this._onErrorObserver = this.onErrorObservable.add(callback);
  7750. },
  7751. enumerable: true,
  7752. configurable: true
  7753. });
  7754. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  7755. /**
  7756. * Callback raised after the loader is disposed.
  7757. */
  7758. set: function (callback) {
  7759. if (this._onDisposeObserver) {
  7760. this.onDisposeObservable.remove(this._onDisposeObserver);
  7761. }
  7762. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  7763. },
  7764. enumerable: true,
  7765. configurable: true
  7766. });
  7767. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  7768. /**
  7769. * Callback raised after a loader extension is created.
  7770. */
  7771. set: function (callback) {
  7772. if (this._onExtensionLoadedObserver) {
  7773. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  7774. }
  7775. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  7776. },
  7777. enumerable: true,
  7778. configurable: true
  7779. });
  7780. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  7781. /**
  7782. * Defines if the loader logging is enabled.
  7783. */
  7784. get: function () {
  7785. return this._loggingEnabled;
  7786. },
  7787. set: function (value) {
  7788. if (this._loggingEnabled === value) {
  7789. return;
  7790. }
  7791. this._loggingEnabled = value;
  7792. if (this._loggingEnabled) {
  7793. this._log = this._logEnabled;
  7794. }
  7795. else {
  7796. this._log = this._logDisabled;
  7797. }
  7798. },
  7799. enumerable: true,
  7800. configurable: true
  7801. });
  7802. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  7803. /**
  7804. * Defines if the loader should capture performance counters.
  7805. */
  7806. get: function () {
  7807. return this._capturePerformanceCounters;
  7808. },
  7809. set: function (value) {
  7810. if (this._capturePerformanceCounters === value) {
  7811. return;
  7812. }
  7813. this._capturePerformanceCounters = value;
  7814. if (this._capturePerformanceCounters) {
  7815. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  7816. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  7817. }
  7818. else {
  7819. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7820. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7821. }
  7822. },
  7823. enumerable: true,
  7824. configurable: true
  7825. });
  7826. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  7827. /**
  7828. * Callback raised after a loader extension is created.
  7829. */
  7830. set: function (callback) {
  7831. if (this._onValidatedObserver) {
  7832. this.onValidatedObservable.remove(this._onValidatedObserver);
  7833. }
  7834. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  7835. },
  7836. enumerable: true,
  7837. configurable: true
  7838. });
  7839. /**
  7840. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  7841. */
  7842. GLTFFileLoader.prototype.dispose = function () {
  7843. if (this._loader) {
  7844. this._loader.dispose();
  7845. this._loader = null;
  7846. }
  7847. this._clear();
  7848. this.onDisposeObservable.notifyObservers(undefined);
  7849. this.onDisposeObservable.clear();
  7850. };
  7851. /** @hidden */
  7852. GLTFFileLoader.prototype._clear = function () {
  7853. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7854. this.onMeshLoadedObservable.clear();
  7855. this.onTextureLoadedObservable.clear();
  7856. this.onMaterialLoadedObservable.clear();
  7857. this.onCameraLoadedObservable.clear();
  7858. this.onCompleteObservable.clear();
  7859. this.onExtensionLoadedObservable.clear();
  7860. };
  7861. /** @hidden */
  7862. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  7863. var _this = this;
  7864. if (useArrayBuffer) {
  7865. if (this.useRangeRequests) {
  7866. if (this.validate) {
  7867. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  7868. }
  7869. var fileRequests_1 = new Array();
  7870. var aggregatedFileRequest_1 = {
  7871. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  7872. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  7873. };
  7874. var dataBuffer_1 = {
  7875. readAsync: function (byteOffset, byteLength) {
  7876. return new Promise(function (resolve, reject) {
  7877. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  7878. var contentRange = webRequest.getResponseHeader("Content-Range");
  7879. if (contentRange) {
  7880. dataBuffer_1.byteLength = Number(contentRange.split("/")[1]);
  7881. }
  7882. resolve(new Uint8Array(data));
  7883. }, onProgress, true, true, function (error) {
  7884. reject(error);
  7885. }, function (webRequest) {
  7886. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  7887. }));
  7888. });
  7889. },
  7890. byteLength: 0
  7891. };
  7892. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  7893. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  7894. onSuccess(loaderData);
  7895. }, onError);
  7896. return aggregatedFileRequest_1;
  7897. }
  7898. return scene._requestFile(url, function (data, request) {
  7899. var arrayBuffer = data;
  7900. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7901. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  7902. byteLength: arrayBuffer.byteLength
  7903. })).then(function (loaderData) {
  7904. onSuccess(loaderData, request);
  7905. }, onError);
  7906. }, onProgress, true, true, onError);
  7907. }
  7908. return scene._requestFile(url, function (data, response) {
  7909. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  7910. onSuccess({ json: _this._parseJson(data) }, response);
  7911. }, onProgress, true, false, onError);
  7912. };
  7913. /** @hidden */
  7914. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  7915. var _this = this;
  7916. return scene._readFile(file, function (data) {
  7917. _this._validate(scene, data, "file:", file.name);
  7918. if (useArrayBuffer) {
  7919. var arrayBuffer_1 = data;
  7920. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7921. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  7922. byteLength: arrayBuffer_1.byteLength
  7923. })).then(onSuccess, onError);
  7924. }
  7925. else {
  7926. onSuccess({ json: _this._parseJson(data) });
  7927. }
  7928. }, onProgress, useArrayBuffer, onError);
  7929. };
  7930. /** @hidden */
  7931. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  7932. var _this = this;
  7933. return Promise.resolve().then(function () {
  7934. _this.onParsedObservable.notifyObservers(data);
  7935. _this.onParsedObservable.clear();
  7936. _this._log("Loading " + (fileName || ""));
  7937. _this._loader = _this._getLoader(data);
  7938. return _this._loader.importMeshAsync(meshesNames, scene, data, rootUrl, onProgress, fileName);
  7939. });
  7940. };
  7941. /** @hidden */
  7942. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7943. var _this = this;
  7944. return Promise.resolve().then(function () {
  7945. _this.onParsedObservable.notifyObservers(data);
  7946. _this.onParsedObservable.clear();
  7947. _this._log("Loading " + (fileName || ""));
  7948. _this._loader = _this._getLoader(data);
  7949. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  7950. });
  7951. };
  7952. /** @hidden */
  7953. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7954. var _this = this;
  7955. return Promise.resolve().then(function () {
  7956. _this.onParsedObservable.notifyObservers(data);
  7957. _this.onParsedObservable.clear();
  7958. _this._log("Loading " + (fileName || ""));
  7959. _this._loader = _this._getLoader(data);
  7960. // Get materials/textures when loading to add to container
  7961. var materials = [];
  7962. _this.onMaterialLoadedObservable.add(function (material) {
  7963. materials.push(material);
  7964. });
  7965. var textures = [];
  7966. _this.onTextureLoadedObservable.add(function (texture) {
  7967. textures.push(texture);
  7968. });
  7969. return _this._loader.importMeshAsync(null, scene, data, rootUrl, onProgress, fileName).then(function (result) {
  7970. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  7971. Array.prototype.push.apply(container.meshes, result.meshes);
  7972. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  7973. Array.prototype.push.apply(container.skeletons, result.skeletons);
  7974. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  7975. Array.prototype.push.apply(container.materials, materials);
  7976. Array.prototype.push.apply(container.textures, textures);
  7977. container.removeAllFromScene();
  7978. return container;
  7979. });
  7980. });
  7981. };
  7982. /** @hidden */
  7983. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  7984. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  7985. };
  7986. /** @hidden */
  7987. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  7988. this._validate(scene, data);
  7989. return { json: this._parseJson(data) };
  7990. };
  7991. /** @hidden */
  7992. GLTFFileLoader.prototype.createPlugin = function () {
  7993. return new GLTFFileLoader();
  7994. };
  7995. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  7996. /**
  7997. * The loader state or null if the loader is not active.
  7998. */
  7999. get: function () {
  8000. return this._loader ? this._loader.state : null;
  8001. },
  8002. enumerable: true,
  8003. configurable: true
  8004. });
  8005. /**
  8006. * Returns a promise that resolves when the asset is completely loaded.
  8007. * @returns a promise that resolves when the asset is completely loaded.
  8008. */
  8009. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  8010. var _this = this;
  8011. return new Promise(function (resolve, reject) {
  8012. _this.onCompleteObservable.addOnce(function () {
  8013. resolve();
  8014. });
  8015. _this.onErrorObservable.addOnce(function (reason) {
  8016. reject(reason);
  8017. });
  8018. });
  8019. };
  8020. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  8021. var _this = this;
  8022. if (rootUrl === void 0) { rootUrl = ""; }
  8023. if (fileName === void 0) { fileName = ""; }
  8024. if (!this.validate) {
  8025. return;
  8026. }
  8027. this._startPerformanceCounter("Validate JSON");
  8028. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  8029. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  8030. }).then(function (result) {
  8031. _this._endPerformanceCounter("Validate JSON");
  8032. _this.onValidatedObservable.notifyObservers(result);
  8033. _this.onValidatedObservable.clear();
  8034. }, function (reason) {
  8035. _this._endPerformanceCounter("Validate JSON");
  8036. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  8037. _this.onValidatedObservable.clear();
  8038. });
  8039. };
  8040. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  8041. var asset = loaderData.json.asset || {};
  8042. this._log("Asset version: " + asset.version);
  8043. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  8044. asset.generator && this._log("Asset generator: " + asset.generator);
  8045. var version = GLTFFileLoader._parseVersion(asset.version);
  8046. if (!version) {
  8047. throw new Error("Invalid version: " + asset.version);
  8048. }
  8049. if (asset.minVersion !== undefined) {
  8050. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  8051. if (!minVersion) {
  8052. throw new Error("Invalid minimum version: " + asset.minVersion);
  8053. }
  8054. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  8055. throw new Error("Incompatible minimum version: " + asset.minVersion);
  8056. }
  8057. }
  8058. var createLoaders = {
  8059. 1: GLTFFileLoader._CreateGLTF1Loader,
  8060. 2: GLTFFileLoader._CreateGLTF2Loader
  8061. };
  8062. var createLoader = createLoaders[version.major];
  8063. if (!createLoader) {
  8064. throw new Error("Unsupported version: " + asset.version);
  8065. }
  8066. return createLoader(this);
  8067. };
  8068. GLTFFileLoader.prototype._parseJson = function (json) {
  8069. this._startPerformanceCounter("Parse JSON");
  8070. this._log("JSON length: " + json.length);
  8071. var parsed = JSON.parse(json);
  8072. this._endPerformanceCounter("Parse JSON");
  8073. return parsed;
  8074. };
  8075. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8076. var _this = this;
  8077. this._startPerformanceCounter("Unpack Binary");
  8078. // Read magic + version + length + json length + json format
  8079. return dataReader.loadAsync(20).then(function () {
  8080. var Binary = {
  8081. Magic: 0x46546C67
  8082. };
  8083. var magic = dataReader.readUint32();
  8084. if (magic !== Binary.Magic) {
  8085. throw new Error("Unexpected magic: " + magic);
  8086. }
  8087. var version = dataReader.readUint32();
  8088. if (_this.loggingEnabled) {
  8089. _this._log("Binary version: " + version);
  8090. }
  8091. var length = dataReader.readUint32();
  8092. if (dataReader.buffer.byteLength != 0 && length !== dataReader.buffer.byteLength) {
  8093. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8094. }
  8095. var unpacked;
  8096. switch (version) {
  8097. case 1: {
  8098. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  8099. break;
  8100. }
  8101. case 2: {
  8102. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  8103. break;
  8104. }
  8105. default: {
  8106. throw new Error("Unsupported version: " + version);
  8107. }
  8108. }
  8109. _this._endPerformanceCounter("Unpack Binary");
  8110. return unpacked;
  8111. });
  8112. };
  8113. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  8114. var ContentFormat = {
  8115. JSON: 0
  8116. };
  8117. var contentLength = dataReader.readUint32();
  8118. var contentFormat = dataReader.readUint32();
  8119. if (contentFormat !== ContentFormat.JSON) {
  8120. throw new Error("Unexpected content format: " + contentFormat);
  8121. }
  8122. var bodyLength = length - dataReader.byteOffset;
  8123. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8124. if (bodyLength !== 0) {
  8125. var startByteOffset_1 = dataReader.byteOffset;
  8126. data.bin = {
  8127. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8128. byteLength: bodyLength
  8129. };
  8130. }
  8131. return Promise.resolve(data);
  8132. };
  8133. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  8134. var _this = this;
  8135. var ChunkFormat = {
  8136. JSON: 0x4E4F534A,
  8137. BIN: 0x004E4942
  8138. };
  8139. var data = { json: {}, bin: null };
  8140. var readAsync = function () {
  8141. var chunkLength = dataReader.readUint32();
  8142. var chunkFormat = dataReader.readUint32();
  8143. var finalChunk = (dataReader.byteOffset + chunkLength + 8 > length);
  8144. // Read the chunk and (if available) the length and type of the next chunk.
  8145. return dataReader.loadAsync(finalChunk ? chunkLength : chunkLength + 8).then(function () {
  8146. switch (chunkFormat) {
  8147. case ChunkFormat.JSON: {
  8148. data.json = _this._parseJson(dataReader.readString(chunkLength));
  8149. break;
  8150. }
  8151. case ChunkFormat.BIN: {
  8152. var startByteOffset_2 = dataReader.byteOffset;
  8153. data.bin = {
  8154. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8155. byteLength: chunkLength
  8156. };
  8157. dataReader.skipBytes(chunkLength);
  8158. break;
  8159. }
  8160. default: {
  8161. // ignore unrecognized chunkFormat
  8162. dataReader.skipBytes(chunkLength);
  8163. break;
  8164. }
  8165. }
  8166. if (finalChunk) {
  8167. return data;
  8168. }
  8169. return readAsync();
  8170. });
  8171. };
  8172. return readAsync();
  8173. };
  8174. GLTFFileLoader._parseVersion = function (version) {
  8175. if (version === "1.0" || version === "1.0.1") {
  8176. return {
  8177. major: 1,
  8178. minor: 0
  8179. };
  8180. }
  8181. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8182. if (!match) {
  8183. return null;
  8184. }
  8185. return {
  8186. major: parseInt(match[1]),
  8187. minor: parseInt(match[2])
  8188. };
  8189. };
  8190. GLTFFileLoader._compareVersion = function (a, b) {
  8191. if (a.major > b.major) {
  8192. return 1;
  8193. }
  8194. if (a.major < b.major) {
  8195. return -1;
  8196. }
  8197. if (a.minor > b.minor) {
  8198. return 1;
  8199. }
  8200. if (a.minor < b.minor) {
  8201. return -1;
  8202. }
  8203. return 0;
  8204. };
  8205. /** @hidden */
  8206. GLTFFileLoader.prototype._logOpen = function (message) {
  8207. this._log(message);
  8208. this._logIndentLevel++;
  8209. };
  8210. /** @hidden */
  8211. GLTFFileLoader.prototype._logClose = function () {
  8212. --this._logIndentLevel;
  8213. };
  8214. GLTFFileLoader.prototype._logEnabled = function (message) {
  8215. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8216. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8217. };
  8218. GLTFFileLoader.prototype._logDisabled = function (message) {
  8219. };
  8220. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8221. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8222. };
  8223. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8224. };
  8225. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8226. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8227. };
  8228. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8229. };
  8230. // ----------
  8231. // V1 options
  8232. // ----------
  8233. /**
  8234. * 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.
  8235. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8236. * Defaults to true.
  8237. * @hidden
  8238. */
  8239. GLTFFileLoader.IncrementalLoading = true;
  8240. /**
  8241. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8242. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8243. * @hidden
  8244. */
  8245. GLTFFileLoader.HomogeneousCoordinates = false;
  8246. GLTFFileLoader._logSpaces = " ";
  8247. return GLTFFileLoader;
  8248. }());
  8249. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8250. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8251. }
  8252. /***/ }),
  8253. /***/ "./glTF/glTFValidation.ts":
  8254. /*!********************************!*\
  8255. !*** ./glTF/glTFValidation.ts ***!
  8256. \********************************/
  8257. /*! exports provided: GLTFValidation */
  8258. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8259. "use strict";
  8260. __webpack_require__.r(__webpack_exports__);
  8261. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  8262. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  8263. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  8264. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  8265. var options = {
  8266. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  8267. };
  8268. if (fileName) {
  8269. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  8270. }
  8271. return (data instanceof ArrayBuffer)
  8272. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  8273. : GLTFValidator.validateString(data, options);
  8274. }
  8275. /**
  8276. * The worker function that gets converted to a blob url to pass into a worker.
  8277. */
  8278. function workerFunc() {
  8279. var pendingExternalResources = [];
  8280. onmessage = function (message) {
  8281. var data = message.data;
  8282. switch (data.id) {
  8283. case "init": {
  8284. importScripts(data.url);
  8285. break;
  8286. }
  8287. case "validate": {
  8288. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  8289. var index = pendingExternalResources.length;
  8290. pendingExternalResources.push({ resolve: resolve, reject: reject });
  8291. postMessage({ id: "getExternalResource", index: index, uri: uri });
  8292. }); }).then(function (value) {
  8293. postMessage({ id: "validate.resolve", value: value });
  8294. }, function (reason) {
  8295. postMessage({ id: "validate.reject", reason: reason });
  8296. });
  8297. break;
  8298. }
  8299. case "getExternalResource.resolve": {
  8300. pendingExternalResources[data.index].resolve(data.value);
  8301. break;
  8302. }
  8303. case "getExternalResource.reject": {
  8304. pendingExternalResources[data.index].reject(data.reason);
  8305. break;
  8306. }
  8307. }
  8308. };
  8309. }
  8310. /**
  8311. * glTF validation
  8312. */
  8313. var GLTFValidation = /** @class */ (function () {
  8314. function GLTFValidation() {
  8315. }
  8316. /**
  8317. * Validate a glTF asset using the glTF-Validator.
  8318. * @param data The JSON of a glTF or the array buffer of a binary glTF
  8319. * @param rootUrl The root url for the glTF
  8320. * @param fileName The file name for the glTF
  8321. * @param getExternalResource The callback to get external resources for the glTF validator
  8322. * @returns A promise that resolves with the glTF validation results once complete
  8323. */
  8324. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  8325. var _this = this;
  8326. if (typeof Worker === "function") {
  8327. return new Promise(function (resolve, reject) {
  8328. var workerContent = validateAsync + "(" + workerFunc + ")()";
  8329. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  8330. var worker = new Worker(workerBlobUrl);
  8331. var onError = function (error) {
  8332. worker.removeEventListener("error", onError);
  8333. worker.removeEventListener("message", onMessage);
  8334. reject(error);
  8335. };
  8336. var onMessage = function (message) {
  8337. var data = message.data;
  8338. switch (data.id) {
  8339. case "getExternalResource": {
  8340. getExternalResource(data.uri).then(function (value) {
  8341. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  8342. }, function (reason) {
  8343. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  8344. });
  8345. break;
  8346. }
  8347. case "validate.resolve": {
  8348. worker.removeEventListener("error", onError);
  8349. worker.removeEventListener("message", onMessage);
  8350. resolve(data.value);
  8351. break;
  8352. }
  8353. case "validate.reject": {
  8354. worker.removeEventListener("error", onError);
  8355. worker.removeEventListener("message", onMessage);
  8356. reject(data.reason);
  8357. }
  8358. }
  8359. };
  8360. worker.addEventListener("error", onError);
  8361. worker.addEventListener("message", onMessage);
  8362. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  8363. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  8364. });
  8365. }
  8366. else {
  8367. if (!this._LoadScriptPromise) {
  8368. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  8369. }
  8370. return this._LoadScriptPromise.then(function () {
  8371. return validateAsync(data, rootUrl, fileName, getExternalResource);
  8372. });
  8373. }
  8374. };
  8375. /**
  8376. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  8377. */
  8378. GLTFValidation.Configuration = {
  8379. url: "https://preview.babylonjs.com/gltf_validator.js"
  8380. };
  8381. return GLTFValidation;
  8382. }());
  8383. /***/ }),
  8384. /***/ "./glTF/index.ts":
  8385. /*!***********************!*\
  8386. !*** ./glTF/index.ts ***!
  8387. \***********************/
  8388. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  8389. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8390. "use strict";
  8391. __webpack_require__.r(__webpack_exports__);
  8392. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8393. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8394. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8395. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8396. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8397. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8398. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8399. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  8400. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  8401. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  8402. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  8403. /***/ }),
  8404. /***/ "./index.ts":
  8405. /*!******************!*\
  8406. !*** ./index.ts ***!
  8407. \******************/
  8408. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8409. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8410. "use strict";
  8411. __webpack_require__.r(__webpack_exports__);
  8412. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  8413. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8414. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8415. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8416. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8417. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  8418. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  8419. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  8420. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  8421. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  8422. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  8423. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  8424. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  8425. /***/ }),
  8426. /***/ "./legacy/legacy-glTF.ts":
  8427. /*!*******************************!*\
  8428. !*** ./legacy/legacy-glTF.ts ***!
  8429. \*******************************/
  8430. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  8431. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8432. "use strict";
  8433. __webpack_require__.r(__webpack_exports__);
  8434. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8435. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  8436. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8437. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8438. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8439. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8440. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8441. /**
  8442. * This is the entry point for the UMD module.
  8443. * The entry point for a future ESM package should be index.ts
  8444. */
  8445. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8446. if (typeof globalObject !== "undefined") {
  8447. globalObject.BABYLON = globalObject.BABYLON || {};
  8448. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  8449. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  8450. }
  8451. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  8452. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  8453. }
  8454. }
  8455. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8456. /***/ }),
  8457. /***/ "./legacy/legacy-glTF1.ts":
  8458. /*!********************************!*\
  8459. !*** ./legacy/legacy-glTF1.ts ***!
  8460. \********************************/
  8461. /*! exports provided: GLTF1 */
  8462. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8463. "use strict";
  8464. __webpack_require__.r(__webpack_exports__);
  8465. /* 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");
  8466. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  8467. /**
  8468. * This is the entry point for the UMD module.
  8469. * The entry point for a future ESM package should be index.ts
  8470. */
  8471. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8472. if (typeof globalObject !== "undefined") {
  8473. globalObject.BABYLON = globalObject.BABYLON || {};
  8474. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  8475. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  8476. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  8477. }
  8478. }
  8479. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8480. /***/ }),
  8481. /***/ "./legacy/legacy-glTF2.ts":
  8482. /*!********************************!*\
  8483. !*** ./legacy/legacy-glTF2.ts ***!
  8484. \********************************/
  8485. /*! exports provided: GLTF2 */
  8486. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8487. "use strict";
  8488. __webpack_require__.r(__webpack_exports__);
  8489. /* 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");
  8490. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8491. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  8492. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  8493. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  8494. /**
  8495. * This is the entry point for the UMD module.
  8496. * The entry point for a future ESM package should be index.ts
  8497. */
  8498. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8499. if (typeof globalObject !== "undefined") {
  8500. globalObject.BABYLON = globalObject.BABYLON || {};
  8501. var BABYLON = globalObject.BABYLON;
  8502. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  8503. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  8504. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  8505. var keys = [];
  8506. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  8507. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  8508. keys.push(key);
  8509. }
  8510. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  8511. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  8512. keys.push(key);
  8513. }
  8514. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  8515. // Prevent Reassignment.
  8516. if (keys.indexOf(key) > -1) {
  8517. continue;
  8518. }
  8519. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  8520. }
  8521. }
  8522. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8523. /***/ }),
  8524. /***/ "./legacy/legacy-objFileLoader.ts":
  8525. /*!****************************************!*\
  8526. !*** ./legacy/legacy-objFileLoader.ts ***!
  8527. \****************************************/
  8528. /*! exports provided: MTLFileLoader, OBJFileLoader */
  8529. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8530. "use strict";
  8531. __webpack_require__.r(__webpack_exports__);
  8532. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  8533. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  8534. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  8535. /**
  8536. * This is the entry point for the UMD module.
  8537. * The entry point for a future ESM package should be index.ts
  8538. */
  8539. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8540. if (typeof globalObject !== "undefined") {
  8541. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  8542. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  8543. }
  8544. }
  8545. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8546. /***/ }),
  8547. /***/ "./legacy/legacy-stlFileLoader.ts":
  8548. /*!****************************************!*\
  8549. !*** ./legacy/legacy-stlFileLoader.ts ***!
  8550. \****************************************/
  8551. /*! exports provided: STLFileLoader */
  8552. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8553. "use strict";
  8554. __webpack_require__.r(__webpack_exports__);
  8555. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  8556. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  8557. /**
  8558. * This is the entry point for the UMD module.
  8559. * The entry point for a future ESM package should be index.ts
  8560. */
  8561. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8562. if (typeof globalObject !== "undefined") {
  8563. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  8564. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  8565. }
  8566. }
  8567. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8568. /***/ }),
  8569. /***/ "./legacy/legacy.ts":
  8570. /*!**************************!*\
  8571. !*** ./legacy/legacy.ts ***!
  8572. \**************************/
  8573. /*! exports provided: GLTF1, GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8574. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8575. "use strict";
  8576. __webpack_require__.r(__webpack_exports__);
  8577. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  8578. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  8579. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  8580. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  8581. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  8582. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  8583. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8584. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  8585. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  8586. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  8587. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  8588. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  8589. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  8590. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  8591. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  8592. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  8593. /***/ }),
  8594. /***/ "babylonjs/Misc/tools":
  8595. /*!****************************************************************************************************!*\
  8596. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  8597. \****************************************************************************************************/
  8598. /*! no static exports found */
  8599. /***/ (function(module, exports) {
  8600. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  8601. /***/ })
  8602. /******/ });
  8603. });
  8604. //# sourceMappingURL=babylonjs.loaders.js.map