babylonjs.loaders.js 449 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** E:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./OBJ/index.ts":
  324. /*!**********************!*\
  325. !*** ./OBJ/index.ts ***!
  326. \**********************/
  327. /*! exports provided: MTLFileLoader, OBJFileLoader */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  333. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  334. /***/ }),
  335. /***/ "./OBJ/objFileLoader.ts":
  336. /*!******************************!*\
  337. !*** ./OBJ/objFileLoader.ts ***!
  338. \******************************/
  339. /*! exports provided: MTLFileLoader, OBJFileLoader */
  340. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  341. "use strict";
  342. __webpack_require__.r(__webpack_exports__);
  343. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  344. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  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, OBJFileLoader.INVERT_TEXTURE_Y);
  553. };
  554. return MTLFileLoader;
  555. }());
  556. /**
  557. * OBJ file type loader.
  558. * This is a babylon scene loader plugin.
  559. */
  560. var OBJFileLoader = /** @class */ (function () {
  561. /**
  562. * Creates loader for .OBJ files
  563. *
  564. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  565. */
  566. function OBJFileLoader(meshLoadOptions) {
  567. /**
  568. * Defines the name of the plugin.
  569. */
  570. this.name = "obj";
  571. /**
  572. * Defines the extension the plugin is able to load.
  573. */
  574. this.extensions = ".obj";
  575. /** @hidden */
  576. this.obj = /^o/;
  577. /** @hidden */
  578. this.group = /^g/;
  579. /** @hidden */
  580. this.mtllib = /^mtllib /;
  581. /** @hidden */
  582. this.usemtl = /^usemtl /;
  583. /** @hidden */
  584. this.smooth = /^s /;
  585. /** @hidden */
  586. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+){3,7}/;
  587. // vn float float float
  588. /** @hidden */
  589. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  590. // vt float float
  591. /** @hidden */
  592. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  593. // f vertex vertex vertex ...
  594. /** @hidden */
  595. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  596. // f vertex/uvs vertex/uvs vertex/uvs ...
  597. /** @hidden */
  598. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  599. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  600. /** @hidden */
  601. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  602. // f vertex//normal vertex//normal vertex//normal ...
  603. /** @hidden */
  604. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  605. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  606. /** @hidden */
  607. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  608. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  609. }
  610. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  611. get: function () {
  612. return {
  613. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  614. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  615. InvertY: OBJFileLoader.INVERT_Y,
  616. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  617. UVScaling: OBJFileLoader.UV_SCALING,
  618. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  619. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  620. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  621. };
  622. },
  623. enumerable: true,
  624. configurable: true
  625. });
  626. /**
  627. * Calls synchronously the MTL file attached to this obj.
  628. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  629. * Without this function materials are not displayed in the first frame (but displayed after).
  630. * In consequence it is impossible to get material information in your HTML file
  631. *
  632. * @param url The URL of the MTL file
  633. * @param rootUrl
  634. * @param onSuccess Callback function to be called when the MTL file is loaded
  635. * @private
  636. */
  637. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  638. //The complete path to the mtl file
  639. var pathOfFile = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  640. // Loads through the babylon tools to allow fileInput search.
  641. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  642. onFailure(pathOfFile, exception);
  643. });
  644. };
  645. /**
  646. * Instantiates a OBJ file loader plugin.
  647. * @returns the created plugin
  648. */
  649. OBJFileLoader.prototype.createPlugin = function () {
  650. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  651. };
  652. /**
  653. * If the data string can be loaded directly.
  654. *
  655. * @param data string containing the file data
  656. * @returns if the data can be loaded directly
  657. */
  658. OBJFileLoader.prototype.canDirectLoad = function (data) {
  659. return false;
  660. };
  661. /**
  662. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  663. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  664. * @param scene the scene the meshes should be added to
  665. * @param data the OBJ data to load
  666. * @param rootUrl root url to load from
  667. * @param onProgress event that fires when loading progress has occured
  668. * @param fileName Defines the name of the file to load
  669. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  670. */
  671. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  672. //get the meshes from OBJ file
  673. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  674. return {
  675. meshes: meshes,
  676. particleSystems: [],
  677. skeletons: [],
  678. animationGroups: []
  679. };
  680. });
  681. };
  682. /**
  683. * Imports all objects from the loaded OBJ data and adds them to the scene
  684. * @param scene the scene the objects should be added to
  685. * @param data the OBJ data to load
  686. * @param rootUrl root url to load from
  687. * @param onProgress event that fires when loading progress has occured
  688. * @param fileName Defines the name of the file to load
  689. * @returns a promise which completes when objects have been loaded to the scene
  690. */
  691. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  692. //Get the 3D model
  693. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  694. // return void
  695. });
  696. };
  697. /**
  698. * Load into an asset container.
  699. * @param scene The scene to load into
  700. * @param data The data to import
  701. * @param rootUrl The root url for scene and resources
  702. * @param onProgress The callback when the load progresses
  703. * @param fileName Defines the name of the file to load
  704. * @returns The loaded asset container
  705. */
  706. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  707. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  708. var container = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  709. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  710. result.meshes.forEach(function (mesh) {
  711. var material = mesh.material;
  712. if (material) {
  713. // Materials
  714. if (container.materials.indexOf(material) == -1) {
  715. container.materials.push(material);
  716. // Textures
  717. var textures = material.getActiveTextures();
  718. textures.forEach(function (t) {
  719. if (container.textures.indexOf(t) == -1) {
  720. container.textures.push(t);
  721. }
  722. });
  723. }
  724. }
  725. });
  726. container.removeAllFromScene();
  727. return container;
  728. });
  729. };
  730. /**
  731. * Read the OBJ file and create an Array of meshes.
  732. * Each mesh contains all information given by the OBJ and the MTL file.
  733. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  734. *
  735. * @param meshesNames
  736. * @param scene Scene The scene where are displayed the data
  737. * @param data String The content of the obj file
  738. * @param rootUrl String The path to the folder
  739. * @returns Array<AbstractMesh>
  740. * @private
  741. */
  742. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  743. var _this = this;
  744. var positions = []; //values for the positions of vertices
  745. var normals = []; //Values for the normals
  746. var uvs = []; //Values for the textures
  747. var colors = [];
  748. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  749. var handledMesh; //The current mesh of meshes array
  750. var indicesForBabylon = []; //The list of indices for VertexData
  751. var wrappedPositionForBabylon = []; //The list of position in vectors
  752. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  753. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  754. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  755. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  756. var curPositionInIndices = 0;
  757. var hasMeshes = false; //Meshes are defined in the file
  758. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  759. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  760. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  761. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  762. var triangles = []; //Indices from new triangles coming from polygons
  763. var materialNameFromObj = ""; //The name of the current material
  764. var fileToLoad = ""; //The name of the mtlFile to load
  765. var materialsFromMTLFile = new MTLFileLoader();
  766. var objMeshName = ""; //The name of the current obj mesh
  767. var increment = 1; //Id for meshes created by the multimaterial
  768. var isFirstMaterial = true;
  769. var grayColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  770. /**
  771. * Search for obj in the given array.
  772. * This function is called to check if a couple of data already exists in an array.
  773. *
  774. * If found, returns the index of the founded tuple index. Returns -1 if not found
  775. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  776. * @param obj Array<number>
  777. * @returns {boolean}
  778. */
  779. var isInArray = function (arr, obj) {
  780. if (!arr[obj[0]]) {
  781. arr[obj[0]] = { normals: [], idx: [] };
  782. }
  783. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  784. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  785. };
  786. var isInArrayUV = function (arr, obj) {
  787. if (!arr[obj[0]]) {
  788. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  789. }
  790. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  791. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  792. return arr[obj[0]].idx[idx];
  793. }
  794. return -1;
  795. };
  796. /**
  797. * This function set the data for each triangle.
  798. * Data are position, normals and uvs
  799. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  800. * If the tuple already exist, add only their indice
  801. *
  802. * @param indicePositionFromObj Integer The index in positions array
  803. * @param indiceUvsFromObj Integer The index in uvs array
  804. * @param indiceNormalFromObj Integer The index in normals array
  805. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  806. * @param textureVectorFromOBJ Vector3 The value of uvs
  807. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  808. */
  809. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  810. //Check if this tuple already exists in the list of tuples
  811. var _index;
  812. if (_this._meshLoadOptions.OptimizeWithUV) {
  813. _index = isInArrayUV(tuplePosNorm, [
  814. indicePositionFromObj,
  815. indiceNormalFromObj,
  816. indiceUvsFromObj
  817. ]);
  818. }
  819. else {
  820. _index = isInArray(tuplePosNorm, [
  821. indicePositionFromObj,
  822. indiceNormalFromObj
  823. ]);
  824. }
  825. //If it not exists
  826. if (_index === -1) {
  827. //Add an new indice.
  828. //The array of indices is only an array with his length equal to the number of triangles - 1.
  829. //We add vertices data in this order
  830. indicesForBabylon.push(wrappedPositionForBabylon.length);
  831. //Push the position of vertice for Babylon
  832. //Each element is a Vector3(x,y,z)
  833. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  834. //Push the uvs for Babylon
  835. //Each element is a Vector3(u,v)
  836. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  837. //Push the normals for Babylon
  838. //Each element is a Vector3(x,y,z)
  839. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  840. if (positionColorsFromOBJ !== undefined) {
  841. //Push the colors for Babylon
  842. //Each element is a BABYLON.Color4(r,g,b,a)
  843. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  844. }
  845. //Add the tuple in the comparison list
  846. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  847. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  848. if (_this._meshLoadOptions.OptimizeWithUV) {
  849. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  850. }
  851. }
  852. else {
  853. //The tuple already exists
  854. //Add the index of the already existing tuple
  855. //At this index we can get the value of position, normal, color and uvs of vertex
  856. indicesForBabylon.push(_index);
  857. }
  858. };
  859. /**
  860. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  861. */
  862. var unwrapData = function () {
  863. //Every array has the same length
  864. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  865. //Push the x, y, z values of each element in the unwrapped array
  866. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  867. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  868. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  869. }
  870. if (_this._meshLoadOptions.ImportVertexColors === true) {
  871. //Push the r, g, b, a values of each element in the unwrapped array
  872. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  873. }
  874. // Reset arrays for the next new meshes
  875. wrappedPositionForBabylon = [];
  876. wrappedNormalsForBabylon = [];
  877. wrappedUvsForBabylon = [];
  878. wrappedColorsForBabylon = [];
  879. tuplePosNorm = [];
  880. curPositionInIndices = 0;
  881. };
  882. /**
  883. * Create triangles from polygons
  884. * It is important to notice that a triangle is a polygon
  885. * We get 5 patterns of face defined in OBJ File :
  886. * facePattern1 = ["1","2","3","4","5","6"]
  887. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  888. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  889. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  890. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  891. * Each pattern is divided by the same method
  892. * @param face Array[String] The indices of elements
  893. * @param v Integer The variable to increment
  894. */
  895. var getTriangles = function (faces, v) {
  896. //Work for each element of the array
  897. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  898. //Add on the triangle variable the indexes to obtain triangles
  899. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  900. }
  901. //Result obtained after 2 iterations:
  902. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  903. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  904. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  905. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  906. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  907. };
  908. /**
  909. * Create triangles and push the data for each polygon for the pattern 1
  910. * In this pattern we get vertice positions
  911. * @param face
  912. * @param v
  913. */
  914. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  915. //Get the indices of triangles for each polygon
  916. getTriangles(face, v);
  917. //For each element in the triangles array.
  918. //This var could contains 1 to an infinity of triangles
  919. for (var k = 0; k < triangles.length; k++) {
  920. // Set position indice
  921. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  922. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  923. positions[indicePositionFromObj], //Get the vectors data
  924. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  925. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  926. }
  927. //Reset variable for the next line
  928. triangles = [];
  929. };
  930. /**
  931. * Create triangles and push the data for each polygon for the pattern 2
  932. * In this pattern we get vertice positions and uvsu
  933. * @param face
  934. * @param v
  935. */
  936. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  937. //Get the indices of triangles for each polygon
  938. getTriangles(face, v);
  939. for (var k = 0; k < triangles.length; k++) {
  940. //triangle[k] = "1/1"
  941. //Split the data for getting position and uv
  942. var point = triangles[k].split("/"); // ["1", "1"]
  943. //Set position indice
  944. var indicePositionFromObj = parseInt(point[0]) - 1;
  945. //Set uv indice
  946. var indiceUvsFromObj = parseInt(point[1]) - 1;
  947. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  948. positions[indicePositionFromObj], //Get the values for each element
  949. uvs[indiceUvsFromObj], babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  950. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  951. }
  952. //Reset variable for the next line
  953. triangles = [];
  954. };
  955. /**
  956. * Create triangles and push the data for each polygon for the pattern 3
  957. * In this pattern we get vertice positions, uvs and normals
  958. * @param face
  959. * @param v
  960. */
  961. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  962. //Get the indices of triangles for each polygon
  963. getTriangles(face, v);
  964. for (var k = 0; k < triangles.length; k++) {
  965. //triangle[k] = "1/1/1"
  966. //Split the data for getting position, uv, and normals
  967. var point = triangles[k].split("/"); // ["1", "1", "1"]
  968. // Set position indice
  969. var indicePositionFromObj = parseInt(point[0]) - 1;
  970. // Set uv indice
  971. var indiceUvsFromObj = parseInt(point[1]) - 1;
  972. // Set normal indice
  973. var indiceNormalFromObj = parseInt(point[2]) - 1;
  974. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  975. );
  976. }
  977. //Reset variable for the next line
  978. triangles = [];
  979. };
  980. /**
  981. * Create triangles and push the data for each polygon for the pattern 4
  982. * In this pattern we get vertice positions and normals
  983. * @param face
  984. * @param v
  985. */
  986. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  987. getTriangles(face, v);
  988. for (var k = 0; k < triangles.length; k++) {
  989. //triangle[k] = "1//1"
  990. //Split the data for getting position and normals
  991. var point = triangles[k].split("//"); // ["1", "1"]
  992. // We check indices, and normals
  993. var indicePositionFromObj = parseInt(point[0]) - 1;
  994. var indiceNormalFromObj = parseInt(point[1]) - 1;
  995. setData(indicePositionFromObj, 1, //Default value for uv
  996. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  997. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  998. }
  999. //Reset variable for the next line
  1000. triangles = [];
  1001. };
  1002. /**
  1003. * Create triangles and push the data for each polygon for the pattern 3
  1004. * In this pattern we get vertice positions, uvs and normals
  1005. * @param face
  1006. * @param v
  1007. */
  1008. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1009. //Get the indices of triangles for each polygon
  1010. getTriangles(face, v);
  1011. for (var k = 0; k < triangles.length; k++) {
  1012. //triangle[k] = "-1/-1/-1"
  1013. //Split the data for getting position, uv, and normals
  1014. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1015. // Set position indice
  1016. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1017. // Set uv indice
  1018. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1019. // Set normal indice
  1020. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1021. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1022. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1023. }
  1024. //Reset variable for the next line
  1025. triangles = [];
  1026. };
  1027. var addPreviousObjMesh = function () {
  1028. //Check if it is not the first mesh. Otherwise we don't have data.
  1029. if (meshesFromObj.length > 0) {
  1030. //Get the previous mesh for applying the data about the faces
  1031. //=> in obj file, faces definition append after the name of the mesh
  1032. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1033. //Set the data into Array for the mesh
  1034. unwrapData();
  1035. // Reverse tab. Otherwise face are displayed in the wrong sens
  1036. indicesForBabylon.reverse();
  1037. //Set the information for the mesh
  1038. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1039. handledMesh.indices = indicesForBabylon.slice();
  1040. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1041. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1042. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1043. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1044. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1045. }
  1046. //Reset the array for the next mesh
  1047. indicesForBabylon = [];
  1048. unwrappedPositionsForBabylon = [];
  1049. unwrappedColorsForBabylon = [];
  1050. unwrappedNormalsForBabylon = [];
  1051. unwrappedUVForBabylon = [];
  1052. }
  1053. };
  1054. //Main function
  1055. //Split the file into lines
  1056. var lines = data.split('\n');
  1057. //Look at each line
  1058. for (var i = 0; i < lines.length; i++) {
  1059. var line = lines[i].trim().replace(/\s\s/g, " ");
  1060. var result;
  1061. //Comment or newLine
  1062. if (line.length === 0 || line.charAt(0) === '#') {
  1063. continue;
  1064. //Get information about one position possible for the vertices
  1065. }
  1066. else if (this.vertexPattern.test(line)) {
  1067. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1068. // Value of result with line: "v 1.0 2.0 3.0"
  1069. // ["v", "1.0", "2.0", "3.0"]
  1070. // Create a Vector3 with the position x, y, z
  1071. positions.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1072. if (this._meshLoadOptions.ImportVertexColors === true) {
  1073. if (result.length >= 7) {
  1074. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1075. 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])));
  1076. }
  1077. else {
  1078. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1079. colors.push(grayColor);
  1080. }
  1081. }
  1082. }
  1083. else if ((result = this.normalPattern.exec(line)) !== null) {
  1084. //Create a Vector3 with the normals x, y, z
  1085. //Value of result
  1086. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1087. //Add the Vector in the list of normals
  1088. normals.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1089. }
  1090. else if ((result = this.uvPattern.exec(line)) !== null) {
  1091. //Create a Vector2 with the normals u, v
  1092. //Value of result
  1093. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1094. //Add the Vector in the list of uvs
  1095. 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));
  1096. //Identify patterns of faces
  1097. //Face could be defined in different type of pattern
  1098. }
  1099. else if ((result = this.facePattern3.exec(line)) !== null) {
  1100. //Value of result:
  1101. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1102. //Set the data for this face
  1103. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1104. 1);
  1105. }
  1106. else if ((result = this.facePattern4.exec(line)) !== null) {
  1107. //Value of result:
  1108. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1109. //Set the data for this face
  1110. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1111. 1);
  1112. }
  1113. else if ((result = this.facePattern5.exec(line)) !== null) {
  1114. //Value of result:
  1115. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1116. //Set the data for this face
  1117. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1118. 1);
  1119. }
  1120. else if ((result = this.facePattern2.exec(line)) !== null) {
  1121. //Value of result:
  1122. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1123. //Set the data for this face
  1124. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1125. 1);
  1126. }
  1127. else if ((result = this.facePattern1.exec(line)) !== null) {
  1128. //Value of result
  1129. //["f 1 2 3", "1 2 3"...]
  1130. //Set the data for this face
  1131. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1132. 1);
  1133. //Define a mesh or an object
  1134. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1135. }
  1136. else if (this.group.test(line) || this.obj.test(line)) {
  1137. //Create a new mesh corresponding to the name of the group.
  1138. //Definition of the mesh
  1139. var objMesh = {
  1140. name: line.substring(2).trim(),
  1141. indices: undefined,
  1142. positions: undefined,
  1143. normals: undefined,
  1144. uvs: undefined,
  1145. colors: undefined,
  1146. materialName: ""
  1147. };
  1148. addPreviousObjMesh();
  1149. //Push the last mesh created with only the name
  1150. meshesFromObj.push(objMesh);
  1151. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1152. hasMeshes = true;
  1153. isFirstMaterial = true;
  1154. increment = 1;
  1155. //Keyword for applying a material
  1156. }
  1157. else if (this.usemtl.test(line)) {
  1158. //Get the name of the material
  1159. materialNameFromObj = line.substring(7).trim();
  1160. //If this new material is in the same mesh
  1161. if (!isFirstMaterial) {
  1162. //Set the data for the previous mesh
  1163. addPreviousObjMesh();
  1164. //Create a new mesh
  1165. var objMesh =
  1166. //Set the name of the current obj mesh
  1167. {
  1168. name: objMeshName + "_mm" + increment.toString(),
  1169. indices: undefined,
  1170. positions: undefined,
  1171. normals: undefined,
  1172. uvs: undefined,
  1173. colors: undefined,
  1174. materialName: materialNameFromObj
  1175. };
  1176. increment++;
  1177. //If meshes are already defined
  1178. meshesFromObj.push(objMesh);
  1179. }
  1180. //Set the material name if the previous line define a mesh
  1181. if (hasMeshes && isFirstMaterial) {
  1182. //Set the material name to the previous mesh (1 material per mesh)
  1183. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1184. isFirstMaterial = false;
  1185. }
  1186. //Keyword for loading the mtl file
  1187. }
  1188. else if (this.mtllib.test(line)) {
  1189. //Get the name of mtl file
  1190. fileToLoad = line.substring(7).trim();
  1191. //Apply smoothing
  1192. }
  1193. else if (this.smooth.test(line)) {
  1194. // smooth shading => apply smoothing
  1195. //Today I don't know it work with babylon and with obj.
  1196. //With the obj file an integer is set
  1197. }
  1198. else {
  1199. //If there is another possibility
  1200. console.log("Unhandled expression at line : " + line);
  1201. }
  1202. }
  1203. //At the end of the file, add the last mesh into the meshesFromObj array
  1204. if (hasMeshes) {
  1205. //Set the data for the last mesh
  1206. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1207. //Reverse indices for displaying faces in the good sense
  1208. indicesForBabylon.reverse();
  1209. //Get the good array
  1210. unwrapData();
  1211. //Set array
  1212. handledMesh.indices = indicesForBabylon;
  1213. handledMesh.positions = unwrappedPositionsForBabylon;
  1214. handledMesh.normals = unwrappedNormalsForBabylon;
  1215. handledMesh.uvs = unwrappedUVForBabylon;
  1216. if (this._meshLoadOptions.ImportVertexColors === true) {
  1217. handledMesh.colors = unwrappedColorsForBabylon;
  1218. }
  1219. }
  1220. //If any o or g keyword found, create a mesh with a random id
  1221. if (!hasMeshes) {
  1222. // reverse tab of indices
  1223. indicesForBabylon.reverse();
  1224. //Get positions normals uvs
  1225. unwrapData();
  1226. //Set data for one mesh
  1227. meshesFromObj.push({
  1228. name: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1229. indices: indicesForBabylon,
  1230. positions: unwrappedPositionsForBabylon,
  1231. colors: unwrappedColorsForBabylon,
  1232. normals: unwrappedNormalsForBabylon,
  1233. uvs: unwrappedUVForBabylon,
  1234. materialName: materialNameFromObj
  1235. });
  1236. }
  1237. //Create a Mesh list
  1238. var babylonMeshesArray = []; //The mesh for babylon
  1239. var materialToUse = new Array();
  1240. //Set data for each mesh
  1241. for (var j = 0; j < meshesFromObj.length; j++) {
  1242. //check meshesNames (stlFileLoader)
  1243. if (meshesNames && meshesFromObj[j].name) {
  1244. if (meshesNames instanceof Array) {
  1245. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1246. continue;
  1247. }
  1248. }
  1249. else {
  1250. if (meshesFromObj[j].name !== meshesNames) {
  1251. continue;
  1252. }
  1253. }
  1254. }
  1255. //Get the current mesh
  1256. //Set the data with VertexBuffer for each mesh
  1257. handledMesh = meshesFromObj[j];
  1258. //Create a Mesh with the name of the obj mesh
  1259. var babylonMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1260. //Push the name of the material to an array
  1261. //This is indispensable for the importMesh function
  1262. materialToUse.push(meshesFromObj[j].materialName);
  1263. var vertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1264. //Set the data for the babylonMesh
  1265. vertexData.uvs = handledMesh.uvs;
  1266. vertexData.indices = handledMesh.indices;
  1267. vertexData.positions = handledMesh.positions;
  1268. if (this._meshLoadOptions.ComputeNormals === true) {
  1269. var normals_1 = new Array();
  1270. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1271. vertexData.normals = normals_1;
  1272. }
  1273. else {
  1274. vertexData.normals = handledMesh.normals;
  1275. }
  1276. if (this._meshLoadOptions.ImportVertexColors === true) {
  1277. vertexData.colors = handledMesh.colors;
  1278. }
  1279. //Set the data from the VertexBuffer to the current Mesh
  1280. vertexData.applyToMesh(babylonMesh);
  1281. if (this._meshLoadOptions.InvertY) {
  1282. babylonMesh.scaling.y *= -1;
  1283. }
  1284. //Push the mesh into an array
  1285. babylonMeshesArray.push(babylonMesh);
  1286. }
  1287. var mtlPromises = [];
  1288. //load the materials
  1289. //Check if we have a file to load
  1290. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1291. //Load the file synchronously
  1292. mtlPromises.push(new Promise(function (resolve, reject) {
  1293. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1294. try {
  1295. //Create materials thanks MTLLoader function
  1296. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl);
  1297. //Look at each material loaded in the mtl file
  1298. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1299. //Three variables to get all meshes with the same material
  1300. var startIndex = 0;
  1301. var _indices = [];
  1302. var _index;
  1303. //The material from MTL file is used in the meshes loaded
  1304. //Push the indice in an array
  1305. //Check if the material is not used for another mesh
  1306. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1307. _indices.push(_index);
  1308. startIndex = _index + 1;
  1309. }
  1310. //If the material is not used dispose it
  1311. if (_index === -1 && _indices.length === 0) {
  1312. //If the material is not needed, remove it
  1313. materialsFromMTLFile.materials[n].dispose();
  1314. }
  1315. else {
  1316. for (var o = 0; o < _indices.length; o++) {
  1317. //Apply the material to the Mesh for each mesh with the material
  1318. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1319. }
  1320. }
  1321. }
  1322. resolve();
  1323. }
  1324. catch (e) {
  1325. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1326. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1327. resolve();
  1328. }
  1329. else {
  1330. reject(e);
  1331. }
  1332. }
  1333. }, function (pathOfFile, exception) {
  1334. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1335. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1336. resolve();
  1337. }
  1338. else {
  1339. reject(exception);
  1340. }
  1341. });
  1342. }));
  1343. }
  1344. //Return an array with all Mesh
  1345. return Promise.all(mtlPromises).then(function () {
  1346. return babylonMeshesArray;
  1347. });
  1348. };
  1349. /**
  1350. * Defines if UVs are optimized by default during load.
  1351. */
  1352. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1353. /**
  1354. * Invert model on y-axis (does a model scaling inversion)
  1355. */
  1356. OBJFileLoader.INVERT_Y = false;
  1357. /**
  1358. * Invert Y-Axis of referenced textures on load
  1359. */
  1360. OBJFileLoader.INVERT_TEXTURE_Y = true;
  1361. /**
  1362. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1363. */
  1364. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1365. /**
  1366. * Compute the normals for the model, even if normals are present in the file.
  1367. */
  1368. OBJFileLoader.COMPUTE_NORMALS = false;
  1369. /**
  1370. * Defines custom scaling of UV coordinates of loaded meshes.
  1371. */
  1372. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1373. /**
  1374. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1375. */
  1376. OBJFileLoader.SKIP_MATERIALS = false;
  1377. /**
  1378. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1379. *
  1380. * Defaults to true for backwards compatibility.
  1381. */
  1382. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1383. return OBJFileLoader;
  1384. }());
  1385. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1386. //Add this loader into the register plugin
  1387. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1388. }
  1389. /***/ }),
  1390. /***/ "./STL/index.ts":
  1391. /*!**********************!*\
  1392. !*** ./STL/index.ts ***!
  1393. \**********************/
  1394. /*! exports provided: STLFileLoader */
  1395. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1396. "use strict";
  1397. __webpack_require__.r(__webpack_exports__);
  1398. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1399. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1400. /***/ }),
  1401. /***/ "./STL/stlFileLoader.ts":
  1402. /*!******************************!*\
  1403. !*** ./STL/stlFileLoader.ts ***!
  1404. \******************************/
  1405. /*! exports provided: STLFileLoader */
  1406. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1407. "use strict";
  1408. __webpack_require__.r(__webpack_exports__);
  1409. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1410. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  1411. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1412. /**
  1413. * STL file type loader.
  1414. * This is a babylon scene loader plugin.
  1415. */
  1416. var STLFileLoader = /** @class */ (function () {
  1417. function STLFileLoader() {
  1418. /** @hidden */
  1419. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  1420. /** @hidden */
  1421. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1422. /** @hidden */
  1423. 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;
  1424. /** @hidden */
  1425. 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;
  1426. /**
  1427. * Defines the name of the plugin.
  1428. */
  1429. this.name = "stl";
  1430. /**
  1431. * Defines the extensions the stl loader is able to load.
  1432. * force data to come in as an ArrayBuffer
  1433. * we'll convert to string if it looks like it's an ASCII .stl
  1434. */
  1435. this.extensions = {
  1436. ".stl": { isBinary: true },
  1437. };
  1438. }
  1439. /**
  1440. * Import meshes into a scene.
  1441. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1442. * @param scene The scene to import into
  1443. * @param data The data to import
  1444. * @param rootUrl The root url for scene and resources
  1445. * @param meshes The meshes array to import into
  1446. * @param particleSystems The particle systems array to import into
  1447. * @param skeletons The skeletons array to import into
  1448. * @param onError The callback when import fails
  1449. * @returns True if successful or false otherwise
  1450. */
  1451. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1452. var matches;
  1453. if (typeof data !== "string") {
  1454. if (this._isBinary(data)) {
  1455. // binary .stl
  1456. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1457. this._parseBinary(babylonMesh, data);
  1458. if (meshes) {
  1459. meshes.push(babylonMesh);
  1460. }
  1461. return true;
  1462. }
  1463. // ASCII .stl
  1464. // convert to string
  1465. var array_buffer = new Uint8Array(data);
  1466. var str = '';
  1467. for (var i = 0; i < data.byteLength; i++) {
  1468. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1469. }
  1470. data = str;
  1471. }
  1472. //if arrived here, data is a string, containing the STLA data.
  1473. while (matches = this.solidPattern.exec(data)) {
  1474. var meshName = matches[1];
  1475. var meshNameFromEnd = matches[3];
  1476. if (meshName != meshNameFromEnd) {
  1477. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1478. return false;
  1479. }
  1480. // check meshesNames
  1481. if (meshesNames && meshName) {
  1482. if (meshesNames instanceof Array) {
  1483. if (!meshesNames.indexOf(meshName)) {
  1484. continue;
  1485. }
  1486. }
  1487. else {
  1488. if (meshName !== meshesNames) {
  1489. continue;
  1490. }
  1491. }
  1492. }
  1493. // stl mesh name can be empty as well
  1494. meshName = meshName || "stlmesh";
  1495. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1496. this._parseASCII(babylonMesh, matches[2]);
  1497. if (meshes) {
  1498. meshes.push(babylonMesh);
  1499. }
  1500. }
  1501. return true;
  1502. };
  1503. /**
  1504. * Load into a scene.
  1505. * @param scene The scene to load into
  1506. * @param data The data to import
  1507. * @param rootUrl The root url for scene and resources
  1508. * @param onError The callback when import fails
  1509. * @returns true if successful or false otherwise
  1510. */
  1511. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1512. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1513. return result;
  1514. };
  1515. /**
  1516. * Load into an asset container.
  1517. * @param scene The scene to load into
  1518. * @param data The data to import
  1519. * @param rootUrl The root url for scene and resources
  1520. * @param onError The callback when import fails
  1521. * @returns The loaded asset container
  1522. */
  1523. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1524. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1525. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1526. container.removeAllFromScene();
  1527. return container;
  1528. };
  1529. STLFileLoader.prototype._isBinary = function (data) {
  1530. // check if file size is correct for binary stl
  1531. var faceSize, nFaces, reader;
  1532. reader = new DataView(data);
  1533. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1534. nFaces = reader.getUint32(80, true);
  1535. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1536. return true;
  1537. }
  1538. // check characters higher than ASCII to confirm binary
  1539. var fileLength = reader.byteLength;
  1540. for (var index = 0; index < fileLength; index++) {
  1541. if (reader.getUint8(index) > 127) {
  1542. return true;
  1543. }
  1544. }
  1545. return false;
  1546. };
  1547. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1548. var reader = new DataView(data);
  1549. var faces = reader.getUint32(80, true);
  1550. var dataOffset = 84;
  1551. var faceLength = 12 * 4 + 2;
  1552. var offset = 0;
  1553. var positions = new Float32Array(faces * 3 * 3);
  1554. var normals = new Float32Array(faces * 3 * 3);
  1555. var indices = new Uint32Array(faces * 3);
  1556. var indicesCount = 0;
  1557. for (var face = 0; face < faces; face++) {
  1558. var start = dataOffset + face * faceLength;
  1559. var normalX = reader.getFloat32(start, true);
  1560. var normalY = reader.getFloat32(start + 4, true);
  1561. var normalZ = reader.getFloat32(start + 8, true);
  1562. for (var i = 1; i <= 3; i++) {
  1563. var vertexstart = start + i * 12;
  1564. // ordering is intentional to match ascii import
  1565. positions[offset] = reader.getFloat32(vertexstart, true);
  1566. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1567. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1568. normals[offset] = normalX;
  1569. normals[offset + 2] = normalY;
  1570. normals[offset + 1] = normalZ;
  1571. offset += 3;
  1572. }
  1573. indices[indicesCount] = indicesCount++;
  1574. indices[indicesCount] = indicesCount++;
  1575. indices[indicesCount] = indicesCount++;
  1576. }
  1577. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1578. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1579. mesh.setIndices(indices);
  1580. mesh.computeWorldMatrix(true);
  1581. };
  1582. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1583. var positions = [];
  1584. var normals = [];
  1585. var indices = [];
  1586. var indicesCount = 0;
  1587. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1588. var matches;
  1589. while (matches = this.facetsPattern.exec(solidData)) {
  1590. var facet = matches[1];
  1591. //one normal per face
  1592. var normalMatches = this.normalPattern.exec(facet);
  1593. this.normalPattern.lastIndex = 0;
  1594. if (!normalMatches) {
  1595. continue;
  1596. }
  1597. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1598. var vertexMatch;
  1599. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1600. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1601. normals.push(normal[0], normal[1], normal[2]);
  1602. }
  1603. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1604. this.vertexPattern.lastIndex = 0;
  1605. }
  1606. this.facetsPattern.lastIndex = 0;
  1607. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1608. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1609. mesh.setIndices(indices);
  1610. mesh.computeWorldMatrix(true);
  1611. };
  1612. return STLFileLoader;
  1613. }());
  1614. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1615. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1616. }
  1617. /***/ }),
  1618. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1619. /*!*****************************************!*\
  1620. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1621. \*****************************************/
  1622. /*! exports provided: GLTFBinaryExtension */
  1623. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1624. "use strict";
  1625. __webpack_require__.r(__webpack_exports__);
  1626. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1627. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1628. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1629. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1630. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1631. var BinaryExtensionBufferName = "binary_glTF";
  1632. /** @hidden */
  1633. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1634. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1635. function GLTFBinaryExtension() {
  1636. return _super.call(this, "KHR_binary_glTF") || this;
  1637. }
  1638. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1639. var extensionsUsed = data.json.extensionsUsed;
  1640. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1641. return false;
  1642. }
  1643. this._bin = data.bin;
  1644. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1645. return true;
  1646. };
  1647. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1648. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1649. return false;
  1650. }
  1651. if (id !== BinaryExtensionBufferName) {
  1652. return false;
  1653. }
  1654. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1655. return true;
  1656. };
  1657. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1658. var texture = gltfRuntime.textures[id];
  1659. var source = gltfRuntime.images[texture.source];
  1660. if (!source.extensions || !(this.name in source.extensions)) {
  1661. return false;
  1662. }
  1663. var sourceExt = source.extensions[this.name];
  1664. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1665. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1666. onSuccess(buffer);
  1667. return true;
  1668. };
  1669. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1670. var shader = gltfRuntime.shaders[id];
  1671. if (!shader.extensions || !(this.name in shader.extensions)) {
  1672. return false;
  1673. }
  1674. var binaryExtensionShader = shader.extensions[this.name];
  1675. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1676. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1677. setTimeout(function () {
  1678. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1679. onSuccess(shaderString);
  1680. });
  1681. return true;
  1682. };
  1683. return GLTFBinaryExtension;
  1684. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1685. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1686. /***/ }),
  1687. /***/ "./glTF/1.0/glTFLoader.ts":
  1688. /*!********************************!*\
  1689. !*** ./glTF/1.0/glTFLoader.ts ***!
  1690. \********************************/
  1691. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1692. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1693. "use strict";
  1694. __webpack_require__.r(__webpack_exports__);
  1695. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1696. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1697. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1698. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1699. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  1700. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  1701. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1702. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1703. /**
  1704. * Tokenizer. Used for shaders compatibility
  1705. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1706. */
  1707. var ETokenType;
  1708. (function (ETokenType) {
  1709. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1710. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1711. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1712. })(ETokenType || (ETokenType = {}));
  1713. var Tokenizer = /** @class */ (function () {
  1714. function Tokenizer(toParse) {
  1715. this._pos = 0;
  1716. this.currentToken = ETokenType.UNKNOWN;
  1717. this.currentIdentifier = "";
  1718. this.currentString = "";
  1719. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1720. this._toParse = toParse;
  1721. this._maxPos = toParse.length;
  1722. }
  1723. Tokenizer.prototype.getNextToken = function () {
  1724. if (this.isEnd()) {
  1725. return ETokenType.END_OF_INPUT;
  1726. }
  1727. this.currentString = this.read();
  1728. this.currentToken = ETokenType.UNKNOWN;
  1729. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1730. this.currentToken = ETokenType.IDENTIFIER;
  1731. this.currentIdentifier = this.currentString;
  1732. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1733. this.currentIdentifier += this.currentString;
  1734. this.forward();
  1735. }
  1736. }
  1737. return this.currentToken;
  1738. };
  1739. Tokenizer.prototype.peek = function () {
  1740. return this._toParse[this._pos];
  1741. };
  1742. Tokenizer.prototype.read = function () {
  1743. return this._toParse[this._pos++];
  1744. };
  1745. Tokenizer.prototype.forward = function () {
  1746. this._pos++;
  1747. };
  1748. Tokenizer.prototype.isEnd = function () {
  1749. return this._pos >= this._maxPos;
  1750. };
  1751. return Tokenizer;
  1752. }());
  1753. /**
  1754. * Values
  1755. */
  1756. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1757. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1758. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1759. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1760. /**
  1761. * Parse
  1762. */
  1763. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1764. for (var buf in parsedBuffers) {
  1765. var parsedBuffer = parsedBuffers[buf];
  1766. gltfRuntime.buffers[buf] = parsedBuffer;
  1767. gltfRuntime.buffersCount++;
  1768. }
  1769. };
  1770. var parseShaders = function (parsedShaders, gltfRuntime) {
  1771. for (var sha in parsedShaders) {
  1772. var parsedShader = parsedShaders[sha];
  1773. gltfRuntime.shaders[sha] = parsedShader;
  1774. gltfRuntime.shaderscount++;
  1775. }
  1776. };
  1777. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1778. for (var object in parsedObjects) {
  1779. var parsedObject = parsedObjects[object];
  1780. gltfRuntime[runtimeProperty][object] = parsedObject;
  1781. }
  1782. };
  1783. /**
  1784. * Utils
  1785. */
  1786. var normalizeUVs = function (buffer) {
  1787. if (!buffer) {
  1788. return;
  1789. }
  1790. for (var i = 0; i < buffer.length / 2; i++) {
  1791. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1792. }
  1793. };
  1794. var getAttribute = function (attributeParameter) {
  1795. if (attributeParameter.semantic === "NORMAL") {
  1796. return "normal";
  1797. }
  1798. else if (attributeParameter.semantic === "POSITION") {
  1799. return "position";
  1800. }
  1801. else if (attributeParameter.semantic === "JOINT") {
  1802. return "matricesIndices";
  1803. }
  1804. else if (attributeParameter.semantic === "WEIGHT") {
  1805. return "matricesWeights";
  1806. }
  1807. else if (attributeParameter.semantic === "COLOR") {
  1808. return "color";
  1809. }
  1810. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1811. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1812. return "uv" + (channel === 0 ? "" : channel + 1);
  1813. }
  1814. return null;
  1815. };
  1816. /**
  1817. * Loads and creates animations
  1818. */
  1819. var loadAnimations = function (gltfRuntime) {
  1820. for (var anim in gltfRuntime.animations) {
  1821. var animation = gltfRuntime.animations[anim];
  1822. if (!animation.channels || !animation.samplers) {
  1823. continue;
  1824. }
  1825. var lastAnimation = null;
  1826. for (var i = 0; i < animation.channels.length; i++) {
  1827. // Get parameters and load buffers
  1828. var channel = animation.channels[i];
  1829. var sampler = animation.samplers[channel.sampler];
  1830. if (!sampler) {
  1831. continue;
  1832. }
  1833. var inputData = null;
  1834. var outputData = null;
  1835. if (animation.parameters) {
  1836. inputData = animation.parameters[sampler.input];
  1837. outputData = animation.parameters[sampler.output];
  1838. }
  1839. else {
  1840. inputData = sampler.input;
  1841. outputData = sampler.output;
  1842. }
  1843. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1844. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1845. var targetID = channel.target.id;
  1846. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1847. if (targetNode === null) {
  1848. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1849. }
  1850. if (targetNode === null) {
  1851. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1852. continue;
  1853. }
  1854. var isBone = targetNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1855. // Get target path (position, rotation or scaling)
  1856. var targetPath = channel.target.path;
  1857. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1858. if (targetPathIndex !== -1) {
  1859. targetPath = babylonAnimationPaths[targetPathIndex];
  1860. }
  1861. // Determine animation type
  1862. var animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1863. if (!isBone) {
  1864. if (targetPath === "rotationQuaternion") {
  1865. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1866. targetNode.rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1867. }
  1868. else {
  1869. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1870. }
  1871. }
  1872. // Create animation and key frames
  1873. var babylonAnimation = null;
  1874. var keys = [];
  1875. var arrayOffset = 0;
  1876. var modifyKey = false;
  1877. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1878. babylonAnimation = lastAnimation;
  1879. modifyKey = true;
  1880. }
  1881. if (!modifyKey) {
  1882. 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);
  1883. }
  1884. // For each frame
  1885. for (var j = 0; j < bufferInput.length; j++) {
  1886. var value = null;
  1887. if (targetPath === "rotationQuaternion") { // VEC4
  1888. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1889. arrayOffset += 4;
  1890. }
  1891. else { // Position and scaling are VEC3
  1892. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1893. arrayOffset += 3;
  1894. }
  1895. if (isBone) {
  1896. var bone = targetNode;
  1897. var translation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1898. var rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1899. var scaling = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1900. // Warning on decompose
  1901. var mat = bone.getBaseMatrix();
  1902. if (modifyKey && lastAnimation) {
  1903. mat = lastAnimation.getKeys()[j].value;
  1904. }
  1905. mat.decompose(scaling, rotationQuaternion, translation);
  1906. if (targetPath === "position") {
  1907. translation = value;
  1908. }
  1909. else if (targetPath === "rotationQuaternion") {
  1910. rotationQuaternion = value;
  1911. }
  1912. else {
  1913. scaling = value;
  1914. }
  1915. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1916. }
  1917. if (!modifyKey) {
  1918. keys.push({
  1919. frame: bufferInput[j],
  1920. value: value
  1921. });
  1922. }
  1923. else if (lastAnimation) {
  1924. lastAnimation.getKeys()[j].value = value;
  1925. }
  1926. }
  1927. // Finish
  1928. if (!modifyKey && babylonAnimation) {
  1929. babylonAnimation.setKeys(keys);
  1930. targetNode.animations.push(babylonAnimation);
  1931. }
  1932. lastAnimation = babylonAnimation;
  1933. gltfRuntime.scene.stopAnimation(targetNode);
  1934. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  1935. }
  1936. }
  1937. };
  1938. /**
  1939. * Returns the bones transformation matrix
  1940. */
  1941. var configureBoneTransformation = function (node) {
  1942. var mat = null;
  1943. if (node.translation || node.rotation || node.scale) {
  1944. var scale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  1945. var rotation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  1946. var position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  1947. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  1948. }
  1949. else {
  1950. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1951. }
  1952. return mat;
  1953. };
  1954. /**
  1955. * Returns the parent bone
  1956. */
  1957. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  1958. // Try to find
  1959. for (var i = 0; i < newSkeleton.bones.length; i++) {
  1960. if (newSkeleton.bones[i].name === jointName) {
  1961. return newSkeleton.bones[i];
  1962. }
  1963. }
  1964. // Not found, search in gltf nodes
  1965. var nodes = gltfRuntime.nodes;
  1966. for (var nde in nodes) {
  1967. var node = nodes[nde];
  1968. if (!node.jointName) {
  1969. continue;
  1970. }
  1971. var children = node.children;
  1972. for (var i = 0; i < children.length; i++) {
  1973. var child = gltfRuntime.nodes[children[i]];
  1974. if (!child.jointName) {
  1975. continue;
  1976. }
  1977. if (child.jointName === jointName) {
  1978. var mat = configureBoneTransformation(node);
  1979. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  1980. bone.id = nde;
  1981. return bone;
  1982. }
  1983. }
  1984. }
  1985. return null;
  1986. };
  1987. /**
  1988. * Returns the appropriate root node
  1989. */
  1990. var getNodeToRoot = function (nodesToRoot, id) {
  1991. for (var i = 0; i < nodesToRoot.length; i++) {
  1992. var nodeToRoot = nodesToRoot[i];
  1993. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  1994. var child = nodeToRoot.node.children[j];
  1995. if (child === id) {
  1996. return nodeToRoot.bone;
  1997. }
  1998. }
  1999. }
  2000. return null;
  2001. };
  2002. /**
  2003. * Returns the node with the joint name
  2004. */
  2005. var getJointNode = function (gltfRuntime, jointName) {
  2006. var nodes = gltfRuntime.nodes;
  2007. var node = nodes[jointName];
  2008. if (node) {
  2009. return {
  2010. node: node,
  2011. id: jointName
  2012. };
  2013. }
  2014. for (var nde in nodes) {
  2015. node = nodes[nde];
  2016. if (node.jointName === jointName) {
  2017. return {
  2018. node: node,
  2019. id: nde
  2020. };
  2021. }
  2022. }
  2023. return null;
  2024. };
  2025. /**
  2026. * Checks if a nodes is in joints
  2027. */
  2028. var nodeIsInJoints = function (skins, id) {
  2029. for (var i = 0; i < skins.jointNames.length; i++) {
  2030. if (skins.jointNames[i] === id) {
  2031. return true;
  2032. }
  2033. }
  2034. return false;
  2035. };
  2036. /**
  2037. * Fills the nodes to root for bones and builds hierarchy
  2038. */
  2039. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2040. // Creates nodes for root
  2041. for (var nde in gltfRuntime.nodes) {
  2042. var node = gltfRuntime.nodes[nde];
  2043. var id = nde;
  2044. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2045. continue;
  2046. }
  2047. // Create node to root bone
  2048. var mat = configureBoneTransformation(node);
  2049. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2050. bone.id = id;
  2051. nodesToRoot.push({ bone: bone, node: node, id: id });
  2052. }
  2053. // Parenting
  2054. for (var i = 0; i < nodesToRoot.length; i++) {
  2055. var nodeToRoot = nodesToRoot[i];
  2056. var children = nodeToRoot.node.children;
  2057. for (var j = 0; j < children.length; j++) {
  2058. var child = null;
  2059. for (var k = 0; k < nodesToRoot.length; k++) {
  2060. if (nodesToRoot[k].id === children[j]) {
  2061. child = nodesToRoot[k];
  2062. break;
  2063. }
  2064. }
  2065. if (child) {
  2066. child.bone._parent = nodeToRoot.bone;
  2067. nodeToRoot.bone.children.push(child.bone);
  2068. }
  2069. }
  2070. }
  2071. };
  2072. /**
  2073. * Imports a skeleton
  2074. */
  2075. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2076. if (!newSkeleton) {
  2077. newSkeleton = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2078. }
  2079. if (!skins.babylonSkeleton) {
  2080. return newSkeleton;
  2081. }
  2082. // Find the root bones
  2083. var nodesToRoot = [];
  2084. var nodesToRootToAdd = [];
  2085. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2086. newSkeleton.bones = [];
  2087. // Joints
  2088. for (var i = 0; i < skins.jointNames.length; i++) {
  2089. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2090. if (!jointNode) {
  2091. continue;
  2092. }
  2093. var node = jointNode.node;
  2094. if (!node) {
  2095. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2096. continue;
  2097. }
  2098. var id = jointNode.id;
  2099. // Optimize, if the bone already exists...
  2100. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2101. if (existingBone) {
  2102. newSkeleton.bones.push(existingBone);
  2103. continue;
  2104. }
  2105. // Search for parent bone
  2106. var foundBone = false;
  2107. var parentBone = null;
  2108. for (var j = 0; j < i; j++) {
  2109. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2110. if (!jointNode_1) {
  2111. continue;
  2112. }
  2113. var joint = jointNode_1.node;
  2114. if (!joint) {
  2115. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2116. continue;
  2117. }
  2118. var children = joint.children;
  2119. if (!children) {
  2120. continue;
  2121. }
  2122. foundBone = false;
  2123. for (var k = 0; k < children.length; k++) {
  2124. if (children[k] === id) {
  2125. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2126. foundBone = true;
  2127. break;
  2128. }
  2129. }
  2130. if (foundBone) {
  2131. break;
  2132. }
  2133. }
  2134. // Create bone
  2135. var mat = configureBoneTransformation(node);
  2136. if (!parentBone && nodesToRoot.length > 0) {
  2137. parentBone = getNodeToRoot(nodesToRoot, id);
  2138. if (parentBone) {
  2139. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2140. nodesToRootToAdd.push(parentBone);
  2141. }
  2142. }
  2143. }
  2144. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2145. bone.id = id;
  2146. }
  2147. // Polish
  2148. var bones = newSkeleton.bones;
  2149. newSkeleton.bones = [];
  2150. for (var i = 0; i < skins.jointNames.length; i++) {
  2151. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2152. if (!jointNode) {
  2153. continue;
  2154. }
  2155. for (var j = 0; j < bones.length; j++) {
  2156. if (bones[j].id === jointNode.id) {
  2157. newSkeleton.bones.push(bones[j]);
  2158. break;
  2159. }
  2160. }
  2161. }
  2162. newSkeleton.prepare();
  2163. // Finish
  2164. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2165. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2166. }
  2167. return newSkeleton;
  2168. };
  2169. /**
  2170. * Imports a mesh and its geometries
  2171. */
  2172. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2173. if (!newMesh) {
  2174. newMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2175. newMesh.id = id;
  2176. }
  2177. if (!node.babylonNode) {
  2178. return newMesh;
  2179. }
  2180. var subMaterials = [];
  2181. var vertexData = null;
  2182. var verticesStarts = new Array();
  2183. var verticesCounts = new Array();
  2184. var indexStarts = new Array();
  2185. var indexCounts = new Array();
  2186. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2187. var meshID = meshes[meshIndex];
  2188. var mesh = gltfRuntime.meshes[meshID];
  2189. if (!mesh) {
  2190. continue;
  2191. }
  2192. // Positions, normals and UVs
  2193. for (var i = 0; i < mesh.primitives.length; i++) {
  2194. // Temporary vertex data
  2195. var tempVertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2196. var primitive = mesh.primitives[i];
  2197. if (primitive.mode !== 4) {
  2198. // continue;
  2199. }
  2200. var attributes = primitive.attributes;
  2201. var accessor = null;
  2202. var buffer = null;
  2203. // Set positions, normal and uvs
  2204. for (var semantic in attributes) {
  2205. // Link accessor and buffer view
  2206. accessor = gltfRuntime.accessors[attributes[semantic]];
  2207. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2208. if (semantic === "NORMAL") {
  2209. tempVertexData.normals = new Float32Array(buffer.length);
  2210. tempVertexData.normals.set(buffer);
  2211. }
  2212. else if (semantic === "POSITION") {
  2213. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2214. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2215. for (var j = 0; j < buffer.length; j += 4) {
  2216. tempVertexData.positions[j] = buffer[j];
  2217. tempVertexData.positions[j + 1] = buffer[j + 1];
  2218. tempVertexData.positions[j + 2] = buffer[j + 2];
  2219. }
  2220. }
  2221. else {
  2222. tempVertexData.positions = new Float32Array(buffer.length);
  2223. tempVertexData.positions.set(buffer);
  2224. }
  2225. verticesCounts.push(tempVertexData.positions.length);
  2226. }
  2227. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2228. var channel = Number(semantic.split("_")[1]);
  2229. var uvKind = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2230. var uvs = new Float32Array(buffer.length);
  2231. uvs.set(buffer);
  2232. normalizeUVs(uvs);
  2233. tempVertexData.set(uvs, uvKind);
  2234. }
  2235. else if (semantic === "JOINT") {
  2236. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2237. tempVertexData.matricesIndices.set(buffer);
  2238. }
  2239. else if (semantic === "WEIGHT") {
  2240. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2241. tempVertexData.matricesWeights.set(buffer);
  2242. }
  2243. else if (semantic === "COLOR") {
  2244. tempVertexData.colors = new Float32Array(buffer.length);
  2245. tempVertexData.colors.set(buffer);
  2246. }
  2247. }
  2248. // Indices
  2249. accessor = gltfRuntime.accessors[primitive.indices];
  2250. if (accessor) {
  2251. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2252. tempVertexData.indices = new Int32Array(buffer.length);
  2253. tempVertexData.indices.set(buffer);
  2254. indexCounts.push(tempVertexData.indices.length);
  2255. }
  2256. else {
  2257. // Set indices on the fly
  2258. var indices = [];
  2259. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2260. indices.push(j);
  2261. }
  2262. tempVertexData.indices = new Int32Array(indices);
  2263. indexCounts.push(tempVertexData.indices.length);
  2264. }
  2265. if (!vertexData) {
  2266. vertexData = tempVertexData;
  2267. }
  2268. else {
  2269. vertexData.merge(tempVertexData);
  2270. }
  2271. // Sub material
  2272. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2273. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2274. // Update vertices start and index start
  2275. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2276. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2277. }
  2278. }
  2279. var material;
  2280. if (subMaterials.length > 1) {
  2281. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2282. material.subMaterials = subMaterials;
  2283. }
  2284. else {
  2285. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2286. }
  2287. if (subMaterials.length === 1) {
  2288. material = subMaterials[0];
  2289. }
  2290. if (!newMesh.material) {
  2291. newMesh.material = material;
  2292. }
  2293. // Apply geometry
  2294. new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2295. newMesh.computeWorldMatrix(true);
  2296. // Apply submeshes
  2297. newMesh.subMeshes = [];
  2298. var index = 0;
  2299. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2300. var meshID = meshes[meshIndex];
  2301. var mesh = gltfRuntime.meshes[meshID];
  2302. if (!mesh) {
  2303. continue;
  2304. }
  2305. for (var i = 0; i < mesh.primitives.length; i++) {
  2306. if (mesh.primitives[i].mode !== 4) {
  2307. //continue;
  2308. }
  2309. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2310. index++;
  2311. }
  2312. }
  2313. // Finish
  2314. return newMesh;
  2315. };
  2316. /**
  2317. * Configure node transformation from position, rotation and scaling
  2318. */
  2319. var configureNode = function (newNode, position, rotation, scaling) {
  2320. if (newNode.position) {
  2321. newNode.position = position;
  2322. }
  2323. if (newNode.rotationQuaternion || newNode.rotation) {
  2324. newNode.rotationQuaternion = rotation;
  2325. }
  2326. if (newNode.scaling) {
  2327. newNode.scaling = scaling;
  2328. }
  2329. };
  2330. /**
  2331. * Configures node from transformation matrix
  2332. */
  2333. var configureNodeFromMatrix = function (newNode, node, parent) {
  2334. if (node.matrix) {
  2335. var position = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2336. var rotation = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2337. var scaling = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2338. var mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2339. mat.decompose(scaling, rotation, position);
  2340. configureNode(newNode, position, rotation, scaling);
  2341. }
  2342. else if (node.translation && node.rotation && node.scale) {
  2343. 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));
  2344. }
  2345. newNode.computeWorldMatrix(true);
  2346. };
  2347. /**
  2348. * Imports a node
  2349. */
  2350. var importNode = function (gltfRuntime, node, id, parent) {
  2351. var lastNode = null;
  2352. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2353. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2354. return null;
  2355. }
  2356. }
  2357. // Meshes
  2358. if (node.skin) {
  2359. if (node.meshes) {
  2360. var skin = gltfRuntime.skins[node.skin];
  2361. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2362. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2363. if (newMesh.skeleton === null) {
  2364. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2365. if (!skin.babylonSkeleton) {
  2366. skin.babylonSkeleton = newMesh.skeleton;
  2367. }
  2368. }
  2369. lastNode = newMesh;
  2370. }
  2371. }
  2372. else if (node.meshes) {
  2373. /**
  2374. * Improve meshes property
  2375. */
  2376. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2377. lastNode = newMesh;
  2378. }
  2379. // Lights
  2380. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2381. var light = gltfRuntime.lights[node.light];
  2382. if (light) {
  2383. if (light.type === "ambient") {
  2384. var ambienLight = light[light.type];
  2385. var hemiLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2386. hemiLight.name = node.name || "";
  2387. if (ambienLight.color) {
  2388. hemiLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2389. }
  2390. lastNode = hemiLight;
  2391. }
  2392. else if (light.type === "directional") {
  2393. var directionalLight = light[light.type];
  2394. var dirLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2395. dirLight.name = node.name || "";
  2396. if (directionalLight.color) {
  2397. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2398. }
  2399. lastNode = dirLight;
  2400. }
  2401. else if (light.type === "point") {
  2402. var pointLight = light[light.type];
  2403. var ptLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2404. ptLight.name = node.name || "";
  2405. if (pointLight.color) {
  2406. ptLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2407. }
  2408. lastNode = ptLight;
  2409. }
  2410. else if (light.type === "spot") {
  2411. var spotLight = light[light.type];
  2412. 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);
  2413. spLight.name = node.name || "";
  2414. if (spotLight.color) {
  2415. spLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2416. }
  2417. if (spotLight.fallOfAngle) {
  2418. spLight.angle = spotLight.fallOfAngle;
  2419. }
  2420. if (spotLight.fallOffExponent) {
  2421. spLight.exponent = spotLight.fallOffExponent;
  2422. }
  2423. lastNode = spLight;
  2424. }
  2425. }
  2426. }
  2427. // Cameras
  2428. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2429. var camera = gltfRuntime.cameras[node.camera];
  2430. if (camera) {
  2431. if (camera.type === "orthographic") {
  2432. 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);
  2433. orthoCamera.name = node.name || "";
  2434. orthoCamera.mode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2435. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2436. lastNode = orthoCamera;
  2437. }
  2438. else if (camera.type === "perspective") {
  2439. var perspectiveCamera = camera[camera.type];
  2440. 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);
  2441. persCamera.name = node.name || "";
  2442. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2443. if (!perspectiveCamera.aspectRatio) {
  2444. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2445. }
  2446. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2447. persCamera.maxZ = perspectiveCamera.zfar;
  2448. persCamera.minZ = perspectiveCamera.znear;
  2449. }
  2450. lastNode = persCamera;
  2451. }
  2452. }
  2453. }
  2454. // Empty node
  2455. if (!node.jointName) {
  2456. if (node.babylonNode) {
  2457. return node.babylonNode;
  2458. }
  2459. else if (lastNode === null) {
  2460. var dummy = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2461. node.babylonNode = dummy;
  2462. lastNode = dummy;
  2463. }
  2464. }
  2465. if (lastNode !== null) {
  2466. if (node.matrix && lastNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2467. configureNodeFromMatrix(lastNode, node, parent);
  2468. }
  2469. else {
  2470. var translation = node.translation || [0, 0, 0];
  2471. var rotation = node.rotation || [0, 0, 0, 1];
  2472. var scale = node.scale || [1, 1, 1];
  2473. 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));
  2474. }
  2475. lastNode.updateCache(true);
  2476. node.babylonNode = lastNode;
  2477. }
  2478. return lastNode;
  2479. };
  2480. /**
  2481. * Traverses nodes and creates them
  2482. */
  2483. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2484. if (meshIncluded === void 0) { meshIncluded = false; }
  2485. var node = gltfRuntime.nodes[id];
  2486. var newNode = null;
  2487. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2488. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2489. meshIncluded = true;
  2490. }
  2491. else {
  2492. meshIncluded = false;
  2493. }
  2494. }
  2495. else {
  2496. meshIncluded = true;
  2497. }
  2498. if (!node.jointName && meshIncluded) {
  2499. newNode = importNode(gltfRuntime, node, id, parent);
  2500. if (newNode !== null) {
  2501. newNode.id = id;
  2502. newNode.parent = parent;
  2503. }
  2504. }
  2505. if (node.children) {
  2506. for (var i = 0; i < node.children.length; i++) {
  2507. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2508. }
  2509. }
  2510. };
  2511. /**
  2512. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2513. */
  2514. var postLoad = function (gltfRuntime) {
  2515. // Nodes
  2516. var currentScene = gltfRuntime.currentScene;
  2517. if (currentScene) {
  2518. for (var i = 0; i < currentScene.nodes.length; i++) {
  2519. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2520. }
  2521. }
  2522. else {
  2523. for (var thing in gltfRuntime.scenes) {
  2524. currentScene = gltfRuntime.scenes[thing];
  2525. for (var i = 0; i < currentScene.nodes.length; i++) {
  2526. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2527. }
  2528. }
  2529. }
  2530. // Set animations
  2531. loadAnimations(gltfRuntime);
  2532. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2533. var skeleton = gltfRuntime.scene.skeletons[i];
  2534. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2535. }
  2536. };
  2537. /**
  2538. * onBind shaderrs callback to set uniforms and matrices
  2539. */
  2540. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2541. var materialValues = material.values || technique.parameters;
  2542. for (var unif in unTreatedUniforms) {
  2543. var uniform = unTreatedUniforms[unif];
  2544. var type = uniform.type;
  2545. 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) {
  2546. if (uniform.semantic && !uniform.source && !uniform.node) {
  2547. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2548. }
  2549. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2550. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2551. if (source === null) {
  2552. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2553. }
  2554. if (source === null) {
  2555. continue;
  2556. }
  2557. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2558. }
  2559. }
  2560. else {
  2561. var value = materialValues[technique.uniforms[unif]];
  2562. if (!value) {
  2563. continue;
  2564. }
  2565. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2566. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2567. if (texture === null || texture === undefined) {
  2568. continue;
  2569. }
  2570. shaderMaterial.getEffect().setTexture(unif, texture);
  2571. }
  2572. else {
  2573. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2574. }
  2575. }
  2576. }
  2577. onSuccess(shaderMaterial);
  2578. };
  2579. /**
  2580. * Prepare uniforms to send the only one time
  2581. * Loads the appropriate textures
  2582. */
  2583. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2584. var materialValues = material.values || technique.parameters;
  2585. var techniqueUniforms = technique.uniforms;
  2586. /**
  2587. * Prepare values here (not matrices)
  2588. */
  2589. for (var unif in unTreatedUniforms) {
  2590. var uniform = unTreatedUniforms[unif];
  2591. var type = uniform.type;
  2592. var value = materialValues[techniqueUniforms[unif]];
  2593. if (value === undefined) {
  2594. // In case the value is the same for all materials
  2595. value = uniform.value;
  2596. }
  2597. if (!value) {
  2598. continue;
  2599. }
  2600. var onLoadTexture = function (uniformName) {
  2601. return function (texture) {
  2602. if (uniform.value && uniformName) {
  2603. // Static uniform
  2604. shaderMaterial.setTexture(uniformName, texture);
  2605. delete unTreatedUniforms[uniformName];
  2606. }
  2607. };
  2608. };
  2609. // Texture (sampler2D)
  2610. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2611. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2612. }
  2613. // Others
  2614. else {
  2615. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2616. // Static uniform
  2617. delete unTreatedUniforms[unif];
  2618. }
  2619. }
  2620. }
  2621. };
  2622. /**
  2623. * Shader compilation failed
  2624. */
  2625. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2626. return function (effect, error) {
  2627. shaderMaterial.dispose(true);
  2628. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2629. };
  2630. };
  2631. /**
  2632. * Shader compilation success
  2633. */
  2634. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2635. return function (_) {
  2636. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2637. shaderMaterial.onBind = function (mesh) {
  2638. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2639. };
  2640. };
  2641. };
  2642. /**
  2643. * Returns the appropriate uniform if already handled by babylon
  2644. */
  2645. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2646. for (var unif in technique.uniforms) {
  2647. var uniform = technique.uniforms[unif];
  2648. var uniformParameter = technique.parameters[uniform];
  2649. if (tokenizer.currentIdentifier === unif) {
  2650. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2651. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2652. if (transformIndex !== -1) {
  2653. delete unTreatedUniforms[unif];
  2654. return babylonTransforms[transformIndex];
  2655. }
  2656. }
  2657. }
  2658. }
  2659. return tokenizer.currentIdentifier;
  2660. };
  2661. /**
  2662. * All shaders loaded. Create materials one by one
  2663. */
  2664. var importMaterials = function (gltfRuntime) {
  2665. // Create materials
  2666. for (var mat in gltfRuntime.materials) {
  2667. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2668. }
  2669. };
  2670. /**
  2671. * Implementation of the base glTF spec
  2672. * @hidden
  2673. */
  2674. var GLTFLoaderBase = /** @class */ (function () {
  2675. function GLTFLoaderBase() {
  2676. }
  2677. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2678. var gltfRuntime = {
  2679. extensions: {},
  2680. accessors: {},
  2681. buffers: {},
  2682. bufferViews: {},
  2683. meshes: {},
  2684. lights: {},
  2685. cameras: {},
  2686. nodes: {},
  2687. images: {},
  2688. textures: {},
  2689. shaders: {},
  2690. programs: {},
  2691. samplers: {},
  2692. techniques: {},
  2693. materials: {},
  2694. animations: {},
  2695. skins: {},
  2696. extensionsUsed: [],
  2697. scenes: {},
  2698. buffersCount: 0,
  2699. shaderscount: 0,
  2700. scene: scene,
  2701. rootUrl: rootUrl,
  2702. loadedBufferCount: 0,
  2703. loadedBufferViews: {},
  2704. loadedShaderCount: 0,
  2705. importOnlyMeshes: false,
  2706. dummyNodes: []
  2707. };
  2708. // Parse
  2709. if (parsedData.extensions) {
  2710. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2711. }
  2712. if (parsedData.extensionsUsed) {
  2713. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2714. }
  2715. if (parsedData.buffers) {
  2716. parseBuffers(parsedData.buffers, gltfRuntime);
  2717. }
  2718. if (parsedData.bufferViews) {
  2719. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2720. }
  2721. if (parsedData.accessors) {
  2722. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2723. }
  2724. if (parsedData.meshes) {
  2725. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2726. }
  2727. if (parsedData.lights) {
  2728. parseObject(parsedData.lights, "lights", gltfRuntime);
  2729. }
  2730. if (parsedData.cameras) {
  2731. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2732. }
  2733. if (parsedData.nodes) {
  2734. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2735. }
  2736. if (parsedData.images) {
  2737. parseObject(parsedData.images, "images", gltfRuntime);
  2738. }
  2739. if (parsedData.textures) {
  2740. parseObject(parsedData.textures, "textures", gltfRuntime);
  2741. }
  2742. if (parsedData.shaders) {
  2743. parseShaders(parsedData.shaders, gltfRuntime);
  2744. }
  2745. if (parsedData.programs) {
  2746. parseObject(parsedData.programs, "programs", gltfRuntime);
  2747. }
  2748. if (parsedData.samplers) {
  2749. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2750. }
  2751. if (parsedData.techniques) {
  2752. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2753. }
  2754. if (parsedData.materials) {
  2755. parseObject(parsedData.materials, "materials", gltfRuntime);
  2756. }
  2757. if (parsedData.animations) {
  2758. parseObject(parsedData.animations, "animations", gltfRuntime);
  2759. }
  2760. if (parsedData.skins) {
  2761. parseObject(parsedData.skins, "skins", gltfRuntime);
  2762. }
  2763. if (parsedData.scenes) {
  2764. gltfRuntime.scenes = parsedData.scenes;
  2765. }
  2766. if (parsedData.scene && parsedData.scenes) {
  2767. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2768. }
  2769. return gltfRuntime;
  2770. };
  2771. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2772. var buffer = gltfRuntime.buffers[id];
  2773. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2774. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2775. }
  2776. else {
  2777. 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) {
  2778. if (request) {
  2779. onError(request.status + " " + request.statusText);
  2780. }
  2781. });
  2782. }
  2783. };
  2784. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2785. var texture = gltfRuntime.textures[id];
  2786. if (!texture || !texture.source) {
  2787. onError("");
  2788. return;
  2789. }
  2790. if (texture.babylonTexture) {
  2791. onSuccess(null);
  2792. return;
  2793. }
  2794. var source = gltfRuntime.images[texture.source];
  2795. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2796. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2797. }
  2798. else {
  2799. 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) {
  2800. if (request) {
  2801. onError(request.status + " " + request.statusText);
  2802. }
  2803. });
  2804. }
  2805. };
  2806. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2807. var texture = gltfRuntime.textures[id];
  2808. if (texture.babylonTexture) {
  2809. onSuccess(texture.babylonTexture);
  2810. return;
  2811. }
  2812. var sampler = gltfRuntime.samplers[texture.sampler];
  2813. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2814. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2815. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2816. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2817. var samplingMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2818. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2819. var blobURL = URL.createObjectURL(blob);
  2820. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2821. var newTexture = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2822. if (sampler.wrapS !== undefined) {
  2823. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2824. }
  2825. if (sampler.wrapT !== undefined) {
  2826. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2827. }
  2828. newTexture.name = id;
  2829. texture.babylonTexture = newTexture;
  2830. onSuccess(newTexture);
  2831. };
  2832. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2833. var shader = gltfRuntime.shaders[id];
  2834. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2835. var shaderString = atob(shader.uri.split(",")[1]);
  2836. if (onSuccess) {
  2837. onSuccess(shaderString);
  2838. }
  2839. }
  2840. else {
  2841. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2842. if (request && onError) {
  2843. onError(request.status + " " + request.statusText);
  2844. }
  2845. });
  2846. }
  2847. };
  2848. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2849. var material = gltfRuntime.materials[id];
  2850. if (!material.technique) {
  2851. if (onError) {
  2852. onError("No technique found.");
  2853. }
  2854. return;
  2855. }
  2856. var technique = gltfRuntime.techniques[material.technique];
  2857. if (!technique) {
  2858. var defaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2859. defaultMaterial.diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2860. defaultMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2861. onSuccess(defaultMaterial);
  2862. return;
  2863. }
  2864. var program = gltfRuntime.programs[technique.program];
  2865. var states = technique.states;
  2866. var vertexShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2867. var pixelShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2868. var newVertexShader = "";
  2869. var newPixelShader = "";
  2870. var vertexTokenizer = new Tokenizer(vertexShader);
  2871. var pixelTokenizer = new Tokenizer(pixelShader);
  2872. var unTreatedUniforms = {};
  2873. var uniforms = [];
  2874. var attributes = [];
  2875. var samplers = [];
  2876. // Fill uniform, sampler2D and attributes
  2877. for (var unif in technique.uniforms) {
  2878. var uniform = technique.uniforms[unif];
  2879. var uniformParameter = technique.parameters[uniform];
  2880. unTreatedUniforms[unif] = uniformParameter;
  2881. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2882. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2883. if (transformIndex !== -1) {
  2884. uniforms.push(babylonTransforms[transformIndex]);
  2885. delete unTreatedUniforms[unif];
  2886. }
  2887. else {
  2888. uniforms.push(unif);
  2889. }
  2890. }
  2891. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2892. samplers.push(unif);
  2893. }
  2894. else {
  2895. uniforms.push(unif);
  2896. }
  2897. }
  2898. for (var attr in technique.attributes) {
  2899. var attribute = technique.attributes[attr];
  2900. var attributeParameter = technique.parameters[attribute];
  2901. if (attributeParameter.semantic) {
  2902. var name_1 = getAttribute(attributeParameter);
  2903. if (name_1) {
  2904. attributes.push(name_1);
  2905. }
  2906. }
  2907. }
  2908. // Configure vertex shader
  2909. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2910. var tokenType = vertexTokenizer.currentToken;
  2911. if (tokenType !== ETokenType.IDENTIFIER) {
  2912. newVertexShader += vertexTokenizer.currentString;
  2913. continue;
  2914. }
  2915. var foundAttribute = false;
  2916. for (var attr in technique.attributes) {
  2917. var attribute = technique.attributes[attr];
  2918. var attributeParameter = technique.parameters[attribute];
  2919. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  2920. newVertexShader += getAttribute(attributeParameter);
  2921. foundAttribute = true;
  2922. break;
  2923. }
  2924. }
  2925. if (foundAttribute) {
  2926. continue;
  2927. }
  2928. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  2929. }
  2930. // Configure pixel shader
  2931. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  2932. var tokenType = pixelTokenizer.currentToken;
  2933. if (tokenType !== ETokenType.IDENTIFIER) {
  2934. newPixelShader += pixelTokenizer.currentString;
  2935. continue;
  2936. }
  2937. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  2938. }
  2939. // Create shader material
  2940. var shaderPath = {
  2941. vertex: program.vertexShader + id,
  2942. fragment: program.fragmentShader + id
  2943. };
  2944. var options = {
  2945. attributes: attributes,
  2946. uniforms: uniforms,
  2947. samplers: samplers,
  2948. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  2949. };
  2950. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  2951. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  2952. var shaderMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  2953. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  2954. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  2955. shaderMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2956. if (states && states.functions) {
  2957. var functions = states.functions;
  2958. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  2959. shaderMaterial.backFaceCulling = false;
  2960. }
  2961. var blendFunc = functions.blendFuncSeparate;
  2962. if (blendFunc) {
  2963. 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) {
  2964. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  2965. }
  2966. 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) {
  2967. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  2968. }
  2969. 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) {
  2970. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  2971. }
  2972. 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) {
  2973. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  2974. }
  2975. 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) {
  2976. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  2977. }
  2978. 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) {
  2979. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  2980. }
  2981. }
  2982. }
  2983. };
  2984. return GLTFLoaderBase;
  2985. }());
  2986. /**
  2987. * glTF V1 Loader
  2988. * @hidden
  2989. */
  2990. var GLTFLoader = /** @class */ (function () {
  2991. function GLTFLoader() {
  2992. this.state = null;
  2993. }
  2994. GLTFLoader.RegisterExtension = function (extension) {
  2995. if (GLTFLoader.Extensions[extension.name]) {
  2996. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  2997. return;
  2998. }
  2999. GLTFLoader.Extensions[extension.name] = extension;
  3000. };
  3001. GLTFLoader.prototype.dispose = function () {
  3002. // do nothing
  3003. };
  3004. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  3005. var _this = this;
  3006. scene.useRightHandedSystem = true;
  3007. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3008. gltfRuntime.importOnlyMeshes = true;
  3009. if (meshesNames === "") {
  3010. gltfRuntime.importMeshesNames = [];
  3011. }
  3012. else if (typeof meshesNames === "string") {
  3013. gltfRuntime.importMeshesNames = [meshesNames];
  3014. }
  3015. else if (meshesNames && !(meshesNames instanceof Array)) {
  3016. gltfRuntime.importMeshesNames = [meshesNames];
  3017. }
  3018. else {
  3019. gltfRuntime.importMeshesNames = [];
  3020. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3021. }
  3022. // Create nodes
  3023. _this._createNodes(gltfRuntime);
  3024. var meshes = new Array();
  3025. var skeletons = new Array();
  3026. // Fill arrays of meshes and skeletons
  3027. for (var nde in gltfRuntime.nodes) {
  3028. var node = gltfRuntime.nodes[nde];
  3029. if (node.babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3030. meshes.push(node.babylonNode);
  3031. }
  3032. }
  3033. for (var skl in gltfRuntime.skins) {
  3034. var skin = gltfRuntime.skins[skl];
  3035. if (skin.babylonSkeleton instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3036. skeletons.push(skin.babylonSkeleton);
  3037. }
  3038. }
  3039. // Load buffers, shaders, materials, etc.
  3040. _this._loadBuffersAsync(gltfRuntime, function () {
  3041. _this._loadShadersAsync(gltfRuntime, function () {
  3042. importMaterials(gltfRuntime);
  3043. postLoad(gltfRuntime);
  3044. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3045. onSuccess(meshes, skeletons);
  3046. }
  3047. });
  3048. }, onProgress);
  3049. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3050. onSuccess(meshes, skeletons);
  3051. }
  3052. }, onError);
  3053. return true;
  3054. };
  3055. /**
  3056. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3057. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3058. * @param scene the scene the meshes should be added to
  3059. * @param data gltf data containing information of the meshes in a loaded file
  3060. * @param rootUrl root url to load from
  3061. * @param onProgress event that fires when loading progress has occured
  3062. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3063. */
  3064. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  3065. var _this = this;
  3066. return new Promise(function (resolve, reject) {
  3067. _this._importMeshAsync(meshesNames, scene, data, rootUrl, function (meshes, skeletons) {
  3068. resolve({
  3069. meshes: meshes,
  3070. particleSystems: [],
  3071. skeletons: skeletons,
  3072. animationGroups: []
  3073. });
  3074. }, onProgress, function (message) {
  3075. reject(new Error(message));
  3076. });
  3077. });
  3078. };
  3079. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  3080. var _this = this;
  3081. scene.useRightHandedSystem = true;
  3082. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3083. // Load runtime extensios
  3084. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3085. // Create nodes
  3086. _this._createNodes(gltfRuntime);
  3087. // Load buffers, shaders, materials, etc.
  3088. _this._loadBuffersAsync(gltfRuntime, function () {
  3089. _this._loadShadersAsync(gltfRuntime, function () {
  3090. importMaterials(gltfRuntime);
  3091. postLoad(gltfRuntime);
  3092. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3093. onSuccess();
  3094. }
  3095. });
  3096. });
  3097. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3098. onSuccess();
  3099. }
  3100. }, onError);
  3101. }, onError);
  3102. };
  3103. /**
  3104. * Imports all objects from a loaded gltf file and adds them to the scene
  3105. * @param scene the scene the objects should be added to
  3106. * @param data gltf data containing information of the meshes in a loaded file
  3107. * @param rootUrl root url to load from
  3108. * @param onProgress event that fires when loading progress has occured
  3109. * @returns a promise which completes when objects have been loaded to the scene
  3110. */
  3111. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3112. var _this = this;
  3113. return new Promise(function (resolve, reject) {
  3114. _this._loadAsync(scene, data, rootUrl, function () {
  3115. resolve();
  3116. }, onProgress, function (message) {
  3117. reject(new Error(message));
  3118. });
  3119. });
  3120. };
  3121. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3122. var hasShaders = false;
  3123. var processShader = function (sha, shader) {
  3124. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3125. if (shaderString instanceof ArrayBuffer) {
  3126. return;
  3127. }
  3128. gltfRuntime.loadedShaderCount++;
  3129. if (shaderString) {
  3130. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3131. }
  3132. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3133. onload();
  3134. }
  3135. }, function () {
  3136. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3137. });
  3138. };
  3139. for (var sha in gltfRuntime.shaders) {
  3140. hasShaders = true;
  3141. var shader = gltfRuntime.shaders[sha];
  3142. if (shader) {
  3143. processShader.bind(this, sha, shader)();
  3144. }
  3145. else {
  3146. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3147. }
  3148. }
  3149. if (!hasShaders) {
  3150. onload();
  3151. }
  3152. };
  3153. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3154. var hasBuffers = false;
  3155. var processBuffer = function (buf, buffer) {
  3156. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3157. gltfRuntime.loadedBufferCount++;
  3158. if (bufferView) {
  3159. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3160. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3161. }
  3162. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3163. }
  3164. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3165. onLoad();
  3166. }
  3167. }, function () {
  3168. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3169. });
  3170. };
  3171. for (var buf in gltfRuntime.buffers) {
  3172. hasBuffers = true;
  3173. var buffer = gltfRuntime.buffers[buf];
  3174. if (buffer) {
  3175. processBuffer.bind(this, buf, buffer)();
  3176. }
  3177. else {
  3178. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3179. }
  3180. }
  3181. if (!hasBuffers) {
  3182. onLoad();
  3183. }
  3184. };
  3185. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3186. var currentScene = gltfRuntime.currentScene;
  3187. if (currentScene) {
  3188. // Only one scene even if multiple scenes are defined
  3189. for (var i = 0; i < currentScene.nodes.length; i++) {
  3190. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3191. }
  3192. }
  3193. else {
  3194. // Load all scenes
  3195. for (var thing in gltfRuntime.scenes) {
  3196. currentScene = gltfRuntime.scenes[thing];
  3197. for (var i = 0; i < currentScene.nodes.length; i++) {
  3198. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3199. }
  3200. }
  3201. }
  3202. };
  3203. GLTFLoader.Extensions = {};
  3204. return GLTFLoader;
  3205. }());
  3206. /** @hidden */
  3207. var GLTFLoaderExtension = /** @class */ (function () {
  3208. function GLTFLoaderExtension(name) {
  3209. this._name = name;
  3210. }
  3211. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3212. get: function () {
  3213. return this._name;
  3214. },
  3215. enumerable: true,
  3216. configurable: true
  3217. });
  3218. /**
  3219. * Defines an override for loading the runtime
  3220. * Return true to stop further extensions from loading the runtime
  3221. */
  3222. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3223. return false;
  3224. };
  3225. /**
  3226. * Defines an onverride for creating gltf runtime
  3227. * Return true to stop further extensions from creating the runtime
  3228. */
  3229. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3230. return false;
  3231. };
  3232. /**
  3233. * Defines an override for loading buffers
  3234. * Return true to stop further extensions from loading this buffer
  3235. */
  3236. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3237. return false;
  3238. };
  3239. /**
  3240. * Defines an override for loading texture buffers
  3241. * Return true to stop further extensions from loading this texture data
  3242. */
  3243. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3244. return false;
  3245. };
  3246. /**
  3247. * Defines an override for creating textures
  3248. * Return true to stop further extensions from loading this texture
  3249. */
  3250. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3251. return false;
  3252. };
  3253. /**
  3254. * Defines an override for loading shader strings
  3255. * Return true to stop further extensions from loading this shader data
  3256. */
  3257. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3258. return false;
  3259. };
  3260. /**
  3261. * Defines an override for loading materials
  3262. * Return true to stop further extensions from loading this material
  3263. */
  3264. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3265. return false;
  3266. };
  3267. // ---------
  3268. // Utilities
  3269. // ---------
  3270. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3271. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3272. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3273. }, function () {
  3274. setTimeout(function () {
  3275. if (!onSuccess) {
  3276. return;
  3277. }
  3278. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3279. });
  3280. });
  3281. };
  3282. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3283. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3284. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3285. }, function () {
  3286. setTimeout(function () {
  3287. onSuccess();
  3288. });
  3289. });
  3290. };
  3291. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3292. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3293. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3294. }, function () {
  3295. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3296. });
  3297. };
  3298. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3299. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3300. if (buffer) {
  3301. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3302. }
  3303. }, onError);
  3304. };
  3305. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3306. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3307. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3308. }, function () {
  3309. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3310. });
  3311. };
  3312. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3313. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3314. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3315. }, function () {
  3316. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3317. });
  3318. };
  3319. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3320. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3321. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3322. }, function () {
  3323. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3324. });
  3325. };
  3326. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3327. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3328. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3329. }, function () {
  3330. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3331. });
  3332. };
  3333. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3334. for (var extensionName in GLTFLoader.Extensions) {
  3335. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3336. if (func(loaderExtension)) {
  3337. return;
  3338. }
  3339. }
  3340. defaultFunc();
  3341. };
  3342. return GLTFLoaderExtension;
  3343. }());
  3344. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3345. /***/ }),
  3346. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3347. /*!******************************************!*\
  3348. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3349. \******************************************/
  3350. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3351. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3352. "use strict";
  3353. __webpack_require__.r(__webpack_exports__);
  3354. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3355. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3356. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3357. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3358. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3359. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3360. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3361. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3362. /**
  3363. * Enums
  3364. * @hidden
  3365. */
  3366. var EComponentType;
  3367. (function (EComponentType) {
  3368. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3369. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3370. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3371. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3372. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3373. })(EComponentType || (EComponentType = {}));
  3374. /** @hidden */
  3375. var EShaderType;
  3376. (function (EShaderType) {
  3377. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3378. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3379. })(EShaderType || (EShaderType = {}));
  3380. /** @hidden */
  3381. var EParameterType;
  3382. (function (EParameterType) {
  3383. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3384. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3385. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3386. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3387. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3388. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3389. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3390. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3391. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3392. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3393. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3394. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3395. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3396. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3397. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3398. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3399. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3400. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3401. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3402. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3403. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3404. })(EParameterType || (EParameterType = {}));
  3405. /** @hidden */
  3406. var ETextureWrapMode;
  3407. (function (ETextureWrapMode) {
  3408. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3409. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3410. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3411. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3412. /** @hidden */
  3413. var ETextureFilterType;
  3414. (function (ETextureFilterType) {
  3415. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3416. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3417. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3418. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3419. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3420. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3421. })(ETextureFilterType || (ETextureFilterType = {}));
  3422. /** @hidden */
  3423. var ETextureFormat;
  3424. (function (ETextureFormat) {
  3425. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3426. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3427. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3428. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3429. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3430. })(ETextureFormat || (ETextureFormat = {}));
  3431. /** @hidden */
  3432. var ECullingType;
  3433. (function (ECullingType) {
  3434. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3435. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3436. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3437. })(ECullingType || (ECullingType = {}));
  3438. /** @hidden */
  3439. var EBlendingFunction;
  3440. (function (EBlendingFunction) {
  3441. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3442. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3443. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3444. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3445. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3446. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3447. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3448. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3449. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3450. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3451. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3452. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3453. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3454. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3455. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3456. })(EBlendingFunction || (EBlendingFunction = {}));
  3457. /***/ }),
  3458. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3459. /*!*************************************!*\
  3460. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3461. \*************************************/
  3462. /*! exports provided: GLTFUtils */
  3463. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3464. "use strict";
  3465. __webpack_require__.r(__webpack_exports__);
  3466. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3467. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3468. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3469. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  3470. /**
  3471. * Utils functions for GLTF
  3472. * @hidden
  3473. */
  3474. var GLTFUtils = /** @class */ (function () {
  3475. function GLTFUtils() {
  3476. }
  3477. /**
  3478. * Sets the given "parameter" matrix
  3479. * @param scene: the Scene object
  3480. * @param source: the source node where to pick the matrix
  3481. * @param parameter: the GLTF technique parameter
  3482. * @param uniformName: the name of the shader's uniform
  3483. * @param shaderMaterial: the shader material
  3484. */
  3485. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3486. var mat = null;
  3487. if (parameter.semantic === "MODEL") {
  3488. mat = source.getWorldMatrix();
  3489. }
  3490. else if (parameter.semantic === "PROJECTION") {
  3491. mat = scene.getProjectionMatrix();
  3492. }
  3493. else if (parameter.semantic === "VIEW") {
  3494. mat = scene.getViewMatrix();
  3495. }
  3496. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3497. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3498. }
  3499. else if (parameter.semantic === "MODELVIEW") {
  3500. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3501. }
  3502. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3503. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3504. }
  3505. else if (parameter.semantic === "MODELINVERSE") {
  3506. mat = source.getWorldMatrix().invert();
  3507. }
  3508. else if (parameter.semantic === "VIEWINVERSE") {
  3509. mat = scene.getViewMatrix().invert();
  3510. }
  3511. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3512. mat = scene.getProjectionMatrix().invert();
  3513. }
  3514. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3515. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3516. }
  3517. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3518. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3519. }
  3520. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3521. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3522. }
  3523. else {
  3524. debugger;
  3525. }
  3526. if (mat) {
  3527. switch (parameter.type) {
  3528. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3529. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3530. break;
  3531. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3532. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3533. break;
  3534. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3535. shaderMaterial.setMatrix(uniformName, mat);
  3536. break;
  3537. default: break;
  3538. }
  3539. }
  3540. };
  3541. /**
  3542. * Sets the given "parameter" matrix
  3543. * @param shaderMaterial: the shader material
  3544. * @param uniform: the name of the shader's uniform
  3545. * @param value: the value of the uniform
  3546. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3547. */
  3548. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3549. switch (type) {
  3550. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3551. shaderMaterial.setFloat(uniform, value);
  3552. return true;
  3553. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3554. shaderMaterial.setVector2(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3555. return true;
  3556. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3557. shaderMaterial.setVector3(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3558. return true;
  3559. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3560. shaderMaterial.setVector4(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3561. return true;
  3562. default: return false;
  3563. }
  3564. };
  3565. /**
  3566. * Returns the wrap mode of the texture
  3567. * @param mode: the mode value
  3568. */
  3569. GLTFUtils.GetWrapMode = function (mode) {
  3570. switch (mode) {
  3571. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3572. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3573. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3574. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3575. }
  3576. };
  3577. /**
  3578. * Returns the byte stride giving an accessor
  3579. * @param accessor: the GLTF accessor objet
  3580. */
  3581. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3582. // Needs this function since "byteStride" isn't requiered in glTF format
  3583. var type = accessor.type;
  3584. switch (type) {
  3585. case "VEC2": return 2;
  3586. case "VEC3": return 3;
  3587. case "VEC4": return 4;
  3588. case "MAT2": return 4;
  3589. case "MAT3": return 9;
  3590. case "MAT4": return 16;
  3591. default: return 1;
  3592. }
  3593. };
  3594. /**
  3595. * Returns the texture filter mode giving a mode value
  3596. * @param mode: the filter mode value
  3597. */
  3598. GLTFUtils.GetTextureFilterMode = function (mode) {
  3599. switch (mode) {
  3600. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3601. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3602. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3603. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3604. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3605. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3606. }
  3607. };
  3608. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3609. var byteOffset = bufferView.byteOffset + byteOffset;
  3610. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3611. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3612. throw new Error("Buffer access is out of range");
  3613. }
  3614. var buffer = loadedBufferView.buffer;
  3615. byteOffset += loadedBufferView.byteOffset;
  3616. switch (componentType) {
  3617. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3618. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3619. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3620. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3621. default: return new Float32Array(buffer, byteOffset, byteLength);
  3622. }
  3623. };
  3624. /**
  3625. * Returns a buffer from its accessor
  3626. * @param gltfRuntime: the GLTF runtime
  3627. * @param accessor: the GLTF accessor
  3628. */
  3629. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3630. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3631. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3632. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3633. };
  3634. /**
  3635. * Decodes a buffer view into a string
  3636. * @param view: the buffer view
  3637. */
  3638. GLTFUtils.DecodeBufferToText = function (view) {
  3639. var result = "";
  3640. var length = view.byteLength;
  3641. for (var i = 0; i < length; ++i) {
  3642. result += String.fromCharCode(view[i]);
  3643. }
  3644. return result;
  3645. };
  3646. /**
  3647. * Returns the default material of gltf. Related to
  3648. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3649. * @param scene: the Babylon.js scene
  3650. */
  3651. GLTFUtils.GetDefaultMaterial = function (scene) {
  3652. if (!GLTFUtils._DefaultMaterial) {
  3653. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3654. "precision highp float;",
  3655. "",
  3656. "uniform mat4 worldView;",
  3657. "uniform mat4 projection;",
  3658. "",
  3659. "attribute vec3 position;",
  3660. "",
  3661. "void main(void)",
  3662. "{",
  3663. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3664. "}"
  3665. ].join("\n");
  3666. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3667. "precision highp float;",
  3668. "",
  3669. "uniform vec4 u_emission;",
  3670. "",
  3671. "void main(void)",
  3672. "{",
  3673. " gl_FragColor = u_emission;",
  3674. "}"
  3675. ].join("\n");
  3676. var shaderPath = {
  3677. vertex: "GLTFDefaultMaterial",
  3678. fragment: "GLTFDefaultMaterial"
  3679. };
  3680. var options = {
  3681. attributes: ["position"],
  3682. uniforms: ["worldView", "projection", "u_emission"],
  3683. samplers: new Array(),
  3684. needAlphaBlending: false
  3685. };
  3686. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3687. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3688. }
  3689. return GLTFUtils._DefaultMaterial;
  3690. };
  3691. // The GLTF default material
  3692. GLTFUtils._DefaultMaterial = null;
  3693. return GLTFUtils;
  3694. }());
  3695. /***/ }),
  3696. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3697. /*!**************************************************!*\
  3698. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3699. \**************************************************/
  3700. /*! exports provided: GLTFMaterialsCommonExtension */
  3701. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3702. "use strict";
  3703. __webpack_require__.r(__webpack_exports__);
  3704. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3705. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3706. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3707. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3708. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__);
  3709. /** @hidden */
  3710. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3711. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3712. function GLTFMaterialsCommonExtension() {
  3713. return _super.call(this, "KHR_materials_common") || this;
  3714. }
  3715. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3716. if (!gltfRuntime.extensions) {
  3717. return false;
  3718. }
  3719. var extension = gltfRuntime.extensions[this.name];
  3720. if (!extension) {
  3721. return false;
  3722. }
  3723. // Create lights
  3724. var lights = extension.lights;
  3725. if (lights) {
  3726. for (var thing in lights) {
  3727. var light = lights[thing];
  3728. switch (light.type) {
  3729. case "ambient":
  3730. 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);
  3731. var ambient = light.ambient;
  3732. if (ambient) {
  3733. ambientLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3734. }
  3735. break;
  3736. case "point":
  3737. 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);
  3738. var point = light.point;
  3739. if (point) {
  3740. pointLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3741. }
  3742. break;
  3743. case "directional":
  3744. 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);
  3745. var directional = light.directional;
  3746. if (directional) {
  3747. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3748. }
  3749. break;
  3750. case "spot":
  3751. var spot = light.spot;
  3752. if (spot) {
  3753. 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);
  3754. spotLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3755. }
  3756. break;
  3757. default:
  3758. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3759. break;
  3760. }
  3761. }
  3762. }
  3763. return false;
  3764. };
  3765. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3766. var material = gltfRuntime.materials[id];
  3767. if (!material || !material.extensions) {
  3768. return false;
  3769. }
  3770. var extension = material.extensions[this.name];
  3771. if (!extension) {
  3772. return false;
  3773. }
  3774. var standardMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3775. standardMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3776. if (extension.technique === "CONSTANT") {
  3777. standardMaterial.disableLighting = true;
  3778. }
  3779. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3780. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3781. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3782. // Ambient
  3783. if (typeof extension.values.ambient === "string") {
  3784. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3785. }
  3786. else {
  3787. standardMaterial.ambientColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3788. }
  3789. // Diffuse
  3790. if (typeof extension.values.diffuse === "string") {
  3791. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3792. }
  3793. else {
  3794. standardMaterial.diffuseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3795. }
  3796. // Emission
  3797. if (typeof extension.values.emission === "string") {
  3798. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3799. }
  3800. else {
  3801. standardMaterial.emissiveColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3802. }
  3803. // Specular
  3804. if (typeof extension.values.specular === "string") {
  3805. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3806. }
  3807. else {
  3808. standardMaterial.specularColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3809. }
  3810. return true;
  3811. };
  3812. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3813. // Create buffer from texture url
  3814. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3815. // Create texture from buffer
  3816. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3817. }, onError);
  3818. };
  3819. return GLTFMaterialsCommonExtension;
  3820. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3821. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3822. /***/ }),
  3823. /***/ "./glTF/1.0/index.ts":
  3824. /*!***************************!*\
  3825. !*** ./glTF/1.0/index.ts ***!
  3826. \***************************/
  3827. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3828. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3829. "use strict";
  3830. __webpack_require__.r(__webpack_exports__);
  3831. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3832. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3833. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3834. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3835. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3836. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3837. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3838. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3839. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3840. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3841. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3842. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3843. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3844. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3845. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3846. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3847. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3848. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3849. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3850. /***/ }),
  3851. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3852. /*!*******************************************************!*\
  3853. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3854. \*******************************************************/
  3855. /*! exports provided: EXT_lights_image_based */
  3856. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3857. "use strict";
  3858. __webpack_require__.r(__webpack_exports__);
  3859. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3860. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  3861. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3862. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3863. var NAME = "EXT_lights_image_based";
  3864. /**
  3865. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3866. */
  3867. var EXT_lights_image_based = /** @class */ (function () {
  3868. /** @hidden */
  3869. function EXT_lights_image_based(loader) {
  3870. /**
  3871. * The name of this extension.
  3872. */
  3873. this.name = NAME;
  3874. this._loader = loader;
  3875. this.enabled = this._loader.isExtensionUsed(NAME);
  3876. }
  3877. /** @hidden */
  3878. EXT_lights_image_based.prototype.dispose = function () {
  3879. delete this._loader;
  3880. delete this._lights;
  3881. };
  3882. /** @hidden */
  3883. EXT_lights_image_based.prototype.onLoading = function () {
  3884. var extensions = this._loader.gltf.extensions;
  3885. if (extensions && extensions[this.name]) {
  3886. var extension = extensions[this.name];
  3887. this._lights = extension.lights;
  3888. }
  3889. };
  3890. /** @hidden */
  3891. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3892. var _this = this;
  3893. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3894. var promises = new Array();
  3895. promises.push(_this._loader.loadSceneAsync(context, scene));
  3896. _this._loader.logOpen("" + extensionContext);
  3897. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3898. promises.push(_this._loadLightAsync("#/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3899. _this._loader.babylonScene.environmentTexture = texture;
  3900. }));
  3901. _this._loader.logClose();
  3902. return Promise.all(promises).then(function () { });
  3903. });
  3904. };
  3905. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3906. var _this = this;
  3907. if (!light._loaded) {
  3908. var promises = new Array();
  3909. this._loader.logOpen("" + context);
  3910. var imageData_1 = new Array(light.specularImages.length);
  3911. var _loop_1 = function (mipmap) {
  3912. var faces = light.specularImages[mipmap];
  3913. imageData_1[mipmap] = new Array(faces.length);
  3914. var _loop_2 = function (face) {
  3915. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  3916. this_1._loader.logOpen("" + specularImageContext);
  3917. var index = faces[face];
  3918. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  3919. promises.push(this_1._loader.loadImageAsync("#/images/" + index, image).then(function (data) {
  3920. imageData_1[mipmap][face] = data;
  3921. }));
  3922. this_1._loader.logClose();
  3923. };
  3924. for (var face = 0; face < faces.length; face++) {
  3925. _loop_2(face);
  3926. }
  3927. };
  3928. var this_1 = this;
  3929. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  3930. _loop_1(mipmap);
  3931. }
  3932. this._loader.logClose();
  3933. light._loaded = Promise.all(promises).then(function () {
  3934. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  3935. light._babylonTexture = babylonTexture;
  3936. if (light.intensity != undefined) {
  3937. babylonTexture.level = light.intensity;
  3938. }
  3939. if (light.rotation) {
  3940. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  3941. // Invert the rotation so that positive rotation is counter-clockwise.
  3942. if (!_this._loader.babylonScene.useRightHandedSystem) {
  3943. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  3944. }
  3945. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  3946. }
  3947. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  3948. sphericalHarmonics.scaleInPlace(light.intensity);
  3949. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  3950. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  3951. // Compute the lod generation scale to fit exactly to the number of levels available.
  3952. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  3953. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  3954. });
  3955. }
  3956. return light._loaded.then(function () {
  3957. return light._babylonTexture;
  3958. });
  3959. };
  3960. return EXT_lights_image_based;
  3961. }());
  3962. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  3963. /***/ }),
  3964. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  3965. /*!*************************************************!*\
  3966. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  3967. \*************************************************/
  3968. /*! exports provided: ExtrasAsMetadata */
  3969. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3970. "use strict";
  3971. __webpack_require__.r(__webpack_exports__);
  3972. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  3973. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3974. var NAME = "ExtrasAsMetadata";
  3975. /**
  3976. * Store glTF extras (if present) in BJS objects' metadata
  3977. */
  3978. var ExtrasAsMetadata = /** @class */ (function () {
  3979. /** @hidden */
  3980. function ExtrasAsMetadata(loader) {
  3981. /**
  3982. * The name of this extension.
  3983. */
  3984. this.name = NAME;
  3985. /**
  3986. * Defines whether this extension is enabled.
  3987. */
  3988. this.enabled = true;
  3989. this._loader = loader;
  3990. }
  3991. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  3992. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  3993. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  3994. var gltf = (metadata.gltf = metadata.gltf || {});
  3995. gltf.extras = gltfProp.extras;
  3996. }
  3997. };
  3998. /** @hidden */
  3999. ExtrasAsMetadata.prototype.dispose = function () {
  4000. delete this._loader;
  4001. };
  4002. /** @hidden */
  4003. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4004. var _this = this;
  4005. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4006. _this._assignExtras(babylonTransformNode, node);
  4007. assign(babylonTransformNode);
  4008. });
  4009. };
  4010. /** @hidden */
  4011. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4012. var _this = this;
  4013. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4014. _this._assignExtras(babylonCamera, camera);
  4015. assign(babylonCamera);
  4016. });
  4017. };
  4018. /** @hidden */
  4019. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4020. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4021. this._assignExtras(babylonMaterial, material);
  4022. return babylonMaterial;
  4023. };
  4024. return ExtrasAsMetadata;
  4025. }());
  4026. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4027. /***/ }),
  4028. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4029. /*!***********************************************************!*\
  4030. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4031. \***********************************************************/
  4032. /*! exports provided: KHR_draco_mesh_compression */
  4033. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4034. "use strict";
  4035. __webpack_require__.r(__webpack_exports__);
  4036. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4037. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  4038. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4039. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4040. var NAME = "KHR_draco_mesh_compression";
  4041. /**
  4042. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4043. */
  4044. var KHR_draco_mesh_compression = /** @class */ (function () {
  4045. /** @hidden */
  4046. function KHR_draco_mesh_compression(loader) {
  4047. /**
  4048. * The name of this extension.
  4049. */
  4050. this.name = NAME;
  4051. this._loader = loader;
  4052. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4053. }
  4054. /** @hidden */
  4055. KHR_draco_mesh_compression.prototype.dispose = function () {
  4056. delete this.dracoCompression;
  4057. delete this._loader;
  4058. };
  4059. /** @hidden */
  4060. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4061. var _this = this;
  4062. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4063. if (primitive.mode != undefined) {
  4064. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4065. primitive.mode !== 4 /* TRIANGLES */) {
  4066. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4067. }
  4068. // TODO: handle triangle strips
  4069. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4070. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4071. }
  4072. }
  4073. var attributes = {};
  4074. var loadAttribute = function (name, kind) {
  4075. var uniqueId = extension.attributes[name];
  4076. if (uniqueId == undefined) {
  4077. return;
  4078. }
  4079. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4080. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4081. babylonMesh._delayInfo.push(kind);
  4082. }
  4083. attributes[kind] = uniqueId;
  4084. };
  4085. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4086. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4087. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4088. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4089. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4090. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4091. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4092. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4093. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4094. if (!bufferView._dracoBabylonGeometry) {
  4095. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4096. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4097. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4098. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4099. babylonVertexData.applyToGeometry(babylonGeometry);
  4100. return babylonGeometry;
  4101. }).catch(function (error) {
  4102. throw new Error(context + ": " + error.message);
  4103. });
  4104. });
  4105. }
  4106. return bufferView._dracoBabylonGeometry;
  4107. });
  4108. };
  4109. return KHR_draco_mesh_compression;
  4110. }());
  4111. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4112. /***/ }),
  4113. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4114. /*!****************************************************!*\
  4115. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4116. \****************************************************/
  4117. /*! exports provided: KHR_lights */
  4118. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4119. "use strict";
  4120. __webpack_require__.r(__webpack_exports__);
  4121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4122. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4123. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4124. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4125. var NAME = "KHR_lights_punctual";
  4126. var LightType;
  4127. (function (LightType) {
  4128. LightType["DIRECTIONAL"] = "directional";
  4129. LightType["POINT"] = "point";
  4130. LightType["SPOT"] = "spot";
  4131. })(LightType || (LightType = {}));
  4132. /**
  4133. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  4134. */
  4135. var KHR_lights = /** @class */ (function () {
  4136. /** @hidden */
  4137. function KHR_lights(loader) {
  4138. /**
  4139. * The name of this extension.
  4140. */
  4141. this.name = NAME;
  4142. this._loader = loader;
  4143. this.enabled = this._loader.isExtensionUsed(NAME);
  4144. }
  4145. /** @hidden */
  4146. KHR_lights.prototype.dispose = function () {
  4147. delete this._loader;
  4148. delete this._lights;
  4149. };
  4150. /** @hidden */
  4151. KHR_lights.prototype.onLoading = function () {
  4152. var extensions = this._loader.gltf.extensions;
  4153. if (extensions && extensions[this.name]) {
  4154. var extension = extensions[this.name];
  4155. this._lights = extension.lights;
  4156. }
  4157. };
  4158. /** @hidden */
  4159. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4160. var _this = this;
  4161. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4162. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4163. var babylonLight;
  4164. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4165. var name = light.name || babylonMesh.name;
  4166. switch (light.type) {
  4167. case LightType.DIRECTIONAL: {
  4168. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  4169. break;
  4170. }
  4171. case LightType.POINT: {
  4172. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  4173. break;
  4174. }
  4175. case LightType.SPOT: {
  4176. 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);
  4177. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4178. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4179. babylonLight = babylonSpotLight;
  4180. break;
  4181. }
  4182. default: {
  4183. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4184. }
  4185. }
  4186. babylonLight.falloffType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4187. babylonLight.diffuse = light.color ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4188. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4189. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4190. babylonLight.parent = babylonMesh;
  4191. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4192. assign(babylonMesh);
  4193. });
  4194. });
  4195. };
  4196. return KHR_lights;
  4197. }());
  4198. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4199. /***/ }),
  4200. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4201. /*!********************************************************!*\
  4202. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4203. \********************************************************/
  4204. /*! exports provided: KHR_materials_clearcoat */
  4205. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4206. "use strict";
  4207. __webpack_require__.r(__webpack_exports__);
  4208. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4209. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4210. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4211. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4212. var NAME = "KHR_materials_clearcoat";
  4213. /**
  4214. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4215. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4216. * !!! Experimental Extension Subject to Changes !!!
  4217. */
  4218. var KHR_materials_clearcoat = /** @class */ (function () {
  4219. /** @hidden */
  4220. function KHR_materials_clearcoat(loader) {
  4221. /**
  4222. * The name of this extension.
  4223. */
  4224. this.name = NAME;
  4225. /**
  4226. * Defines a number that determines the order the extensions are applied.
  4227. */
  4228. this.order = 220;
  4229. this._loader = loader;
  4230. this.enabled = this._loader.isExtensionUsed(NAME);
  4231. }
  4232. /** @hidden */
  4233. KHR_materials_clearcoat.prototype.dispose = function () {
  4234. delete this._loader;
  4235. };
  4236. /** @hidden */
  4237. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4238. var _this = this;
  4239. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4240. var promises = new Array();
  4241. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4242. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4243. return Promise.all(promises).then(function () { });
  4244. });
  4245. };
  4246. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4247. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4248. throw new Error(context + ": Material type not supported");
  4249. }
  4250. var promises = new Array();
  4251. babylonMaterial.clearCoat.isEnabled = true;
  4252. if (properties.clearcoatFactor != undefined) {
  4253. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4254. }
  4255. else {
  4256. babylonMaterial.clearCoat.intensity = 0;
  4257. }
  4258. if (properties.clearcoatTexture) {
  4259. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4260. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4261. babylonMaterial.clearCoat.texture = texture;
  4262. }));
  4263. }
  4264. if (properties.clearcoatRoughnessFactor != undefined) {
  4265. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4266. }
  4267. else {
  4268. babylonMaterial.clearCoat.roughness = 0;
  4269. }
  4270. if (properties.clearcoatRoughnessTexture) {
  4271. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4272. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4273. babylonMaterial.clearCoat.texture = texture;
  4274. }));
  4275. }
  4276. if (properties.clearcoatNormalTexture) {
  4277. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4278. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4279. babylonMaterial.clearCoat.bumpTexture = texture;
  4280. }));
  4281. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4282. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4283. if (properties.clearcoatNormalTexture.scale != undefined) {
  4284. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4285. }
  4286. }
  4287. return Promise.all(promises).then(function () { });
  4288. };
  4289. return KHR_materials_clearcoat;
  4290. }());
  4291. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4292. /***/ }),
  4293. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4294. /*!********************************************************************!*\
  4295. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4296. \********************************************************************/
  4297. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4298. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4299. "use strict";
  4300. __webpack_require__.r(__webpack_exports__);
  4301. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4302. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4303. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4304. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4305. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4306. /**
  4307. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4308. */
  4309. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4310. /** @hidden */
  4311. function KHR_materials_pbrSpecularGlossiness(loader) {
  4312. /**
  4313. * The name of this extension.
  4314. */
  4315. this.name = NAME;
  4316. /**
  4317. * Defines a number that determines the order the extensions are applied.
  4318. */
  4319. this.order = 200;
  4320. this._loader = loader;
  4321. this.enabled = this._loader.isExtensionUsed(NAME);
  4322. }
  4323. /** @hidden */
  4324. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4325. delete this._loader;
  4326. };
  4327. /** @hidden */
  4328. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4329. var _this = this;
  4330. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4331. var promises = new Array();
  4332. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4333. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4334. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4335. return Promise.all(promises).then(function () { });
  4336. });
  4337. };
  4338. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4339. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4340. throw new Error(context + ": Material type not supported");
  4341. }
  4342. var promises = new Array();
  4343. babylonMaterial.metallic = null;
  4344. babylonMaterial.roughness = null;
  4345. if (properties.diffuseFactor) {
  4346. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4347. babylonMaterial.alpha = properties.diffuseFactor[3];
  4348. }
  4349. else {
  4350. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4351. }
  4352. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4353. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4354. if (properties.diffuseTexture) {
  4355. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4356. texture.name = babylonMaterial.name + " (Diffuse)";
  4357. babylonMaterial.albedoTexture = texture;
  4358. }));
  4359. }
  4360. if (properties.specularGlossinessTexture) {
  4361. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4362. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4363. babylonMaterial.reflectivityTexture = texture;
  4364. }));
  4365. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4366. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4367. }
  4368. return Promise.all(promises).then(function () { });
  4369. };
  4370. return KHR_materials_pbrSpecularGlossiness;
  4371. }());
  4372. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4373. /***/ }),
  4374. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4375. /*!****************************************************!*\
  4376. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4377. \****************************************************/
  4378. /*! exports provided: KHR_materials_sheen */
  4379. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4380. "use strict";
  4381. __webpack_require__.r(__webpack_exports__);
  4382. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4383. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4384. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4385. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4386. var NAME = "KHR_materials_sheen";
  4387. /**
  4388. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4389. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4390. * !!! Experimental Extension Subject to Changes !!!
  4391. */
  4392. var KHR_materials_sheen = /** @class */ (function () {
  4393. /** @hidden */
  4394. function KHR_materials_sheen(loader) {
  4395. /**
  4396. * The name of this extension.
  4397. */
  4398. this.name = NAME;
  4399. /**
  4400. * Defines a number that determines the order the extensions are applied.
  4401. */
  4402. this.order = 240;
  4403. this._loader = loader;
  4404. this.enabled = this._loader.isExtensionUsed(NAME);
  4405. }
  4406. /** @hidden */
  4407. KHR_materials_sheen.prototype.dispose = function () {
  4408. delete this._loader;
  4409. };
  4410. /** @hidden */
  4411. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4412. var _this = this;
  4413. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4414. var promises = new Array();
  4415. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4416. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4417. return Promise.all(promises).then(function () { });
  4418. });
  4419. };
  4420. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4421. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4422. throw new Error(context + ": Material type not supported");
  4423. }
  4424. var promises = new Array();
  4425. babylonMaterial.sheen.isEnabled = true;
  4426. if (properties.intensityFactor != undefined) {
  4427. babylonMaterial.sheen.intensity = properties.intensityFactor;
  4428. }
  4429. else {
  4430. babylonMaterial.sheen.intensity = 0;
  4431. }
  4432. if (properties.colorFactor != undefined) {
  4433. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  4434. }
  4435. if (properties.colorIntensityTexture) {
  4436. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  4437. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  4438. babylonMaterial.sheen.texture = texture;
  4439. }));
  4440. }
  4441. return Promise.all(promises).then(function () { });
  4442. };
  4443. return KHR_materials_sheen;
  4444. }());
  4445. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4446. /***/ }),
  4447. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4448. /*!*******************************************************!*\
  4449. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4450. \*******************************************************/
  4451. /*! exports provided: KHR_materials_specular */
  4452. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4453. "use strict";
  4454. __webpack_require__.r(__webpack_exports__);
  4455. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4456. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4457. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4458. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4459. var NAME = "KHR_materials_specular";
  4460. /**
  4461. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4462. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4463. * !!! Experimental Extension Subject to Changes !!!
  4464. */
  4465. var KHR_materials_specular = /** @class */ (function () {
  4466. /** @hidden */
  4467. function KHR_materials_specular(loader) {
  4468. /**
  4469. * The name of this extension.
  4470. */
  4471. this.name = NAME;
  4472. /**
  4473. * Defines a number that determines the order the extensions are applied.
  4474. */
  4475. this.order = 230;
  4476. this._loader = loader;
  4477. this.enabled = this._loader.isExtensionUsed(NAME);
  4478. }
  4479. /** @hidden */
  4480. KHR_materials_specular.prototype.dispose = function () {
  4481. delete this._loader;
  4482. };
  4483. /** @hidden */
  4484. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4485. var _this = this;
  4486. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4487. var promises = new Array();
  4488. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4489. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4490. return Promise.all(promises).then(function () { });
  4491. });
  4492. };
  4493. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4494. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4495. throw new Error(context + ": Material type not supported");
  4496. }
  4497. if (properties.specularFactor !== undefined) {
  4498. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4499. }
  4500. if (properties.specularTexture) {
  4501. // This does not allow a separate sampler for it at the moment but is currently under discussion.
  4502. babylonMaterial.useMetallicF0FactorFromMetallicTexture = true;
  4503. }
  4504. return Promise.resolve();
  4505. };
  4506. return KHR_materials_specular;
  4507. }());
  4508. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4509. /***/ }),
  4510. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  4511. /*!****************************************************!*\
  4512. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  4513. \****************************************************/
  4514. /*! exports provided: KHR_materials_unlit */
  4515. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4516. "use strict";
  4517. __webpack_require__.r(__webpack_exports__);
  4518. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  4519. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4520. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4521. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4522. var NAME = "KHR_materials_unlit";
  4523. /**
  4524. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4525. */
  4526. var KHR_materials_unlit = /** @class */ (function () {
  4527. /** @hidden */
  4528. function KHR_materials_unlit(loader) {
  4529. /**
  4530. * The name of this extension.
  4531. */
  4532. this.name = NAME;
  4533. /**
  4534. * Defines a number that determines the order the extensions are applied.
  4535. */
  4536. this.order = 210;
  4537. this._loader = loader;
  4538. this.enabled = this._loader.isExtensionUsed(NAME);
  4539. }
  4540. /** @hidden */
  4541. KHR_materials_unlit.prototype.dispose = function () {
  4542. delete this._loader;
  4543. };
  4544. /** @hidden */
  4545. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4546. var _this = this;
  4547. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  4548. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  4549. });
  4550. };
  4551. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  4552. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4553. throw new Error(context + ": Material type not supported");
  4554. }
  4555. var promises = new Array();
  4556. babylonMaterial.unlit = true;
  4557. var properties = material.pbrMetallicRoughness;
  4558. if (properties) {
  4559. if (properties.baseColorFactor) {
  4560. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  4561. babylonMaterial.alpha = properties.baseColorFactor[3];
  4562. }
  4563. else {
  4564. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4565. }
  4566. if (properties.baseColorTexture) {
  4567. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  4568. texture.name = babylonMaterial.name + " (Base Color)";
  4569. babylonMaterial.albedoTexture = texture;
  4570. }));
  4571. }
  4572. }
  4573. if (material.doubleSided) {
  4574. babylonMaterial.backFaceCulling = false;
  4575. babylonMaterial.twoSidedLighting = true;
  4576. }
  4577. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4578. return Promise.all(promises).then(function () { });
  4579. };
  4580. return KHR_materials_unlit;
  4581. }());
  4582. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  4583. /***/ }),
  4584. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  4585. /*!******************************************************!*\
  4586. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  4587. \******************************************************/
  4588. /*! exports provided: KHR_mesh_quantization */
  4589. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4590. "use strict";
  4591. __webpack_require__.r(__webpack_exports__);
  4592. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  4593. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4594. var NAME = "KHR_mesh_quantization";
  4595. /**
  4596. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  4597. */
  4598. var KHR_mesh_quantization = /** @class */ (function () {
  4599. /** @hidden */
  4600. function KHR_mesh_quantization(loader) {
  4601. /**
  4602. * The name of this extension.
  4603. */
  4604. this.name = NAME;
  4605. this.enabled = loader.isExtensionUsed(NAME);
  4606. }
  4607. /** @hidden */
  4608. KHR_mesh_quantization.prototype.dispose = function () {
  4609. };
  4610. return KHR_mesh_quantization;
  4611. }());
  4612. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  4613. /***/ }),
  4614. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  4615. /*!******************************************************!*\
  4616. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  4617. \******************************************************/
  4618. /*! exports provided: KHR_texture_transform */
  4619. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4620. "use strict";
  4621. __webpack_require__.r(__webpack_exports__);
  4622. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  4623. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  4624. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  4625. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4626. var NAME = "KHR_texture_transform";
  4627. /**
  4628. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4629. */
  4630. var KHR_texture_transform = /** @class */ (function () {
  4631. /** @hidden */
  4632. function KHR_texture_transform(loader) {
  4633. /**
  4634. * The name of this extension.
  4635. */
  4636. this.name = NAME;
  4637. this._loader = loader;
  4638. this.enabled = this._loader.isExtensionUsed(NAME);
  4639. }
  4640. /** @hidden */
  4641. KHR_texture_transform.prototype.dispose = function () {
  4642. delete this._loader;
  4643. };
  4644. /** @hidden */
  4645. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  4646. var _this = this;
  4647. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  4648. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  4649. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  4650. throw new Error(extensionContext + ": Texture type not supported");
  4651. }
  4652. if (extension.offset) {
  4653. babylonTexture.uOffset = extension.offset[0];
  4654. babylonTexture.vOffset = extension.offset[1];
  4655. }
  4656. // Always rotate around the origin.
  4657. babylonTexture.uRotationCenter = 0;
  4658. babylonTexture.vRotationCenter = 0;
  4659. if (extension.rotation) {
  4660. babylonTexture.wAng = -extension.rotation;
  4661. }
  4662. if (extension.scale) {
  4663. babylonTexture.uScale = extension.scale[0];
  4664. babylonTexture.vScale = extension.scale[1];
  4665. }
  4666. if (extension.texCoord != undefined) {
  4667. babylonTexture.coordinatesIndex = extension.texCoord;
  4668. }
  4669. assign(babylonTexture);
  4670. });
  4671. });
  4672. };
  4673. return KHR_texture_transform;
  4674. }());
  4675. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  4676. /***/ }),
  4677. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  4678. /*!***************************************************!*\
  4679. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  4680. \***************************************************/
  4681. /*! exports provided: MSFT_audio_emitter */
  4682. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4683. "use strict";
  4684. __webpack_require__.r(__webpack_exports__);
  4685. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  4686. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4687. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4688. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4689. var NAME = "MSFT_audio_emitter";
  4690. /**
  4691. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4692. */
  4693. var MSFT_audio_emitter = /** @class */ (function () {
  4694. /** @hidden */
  4695. function MSFT_audio_emitter(loader) {
  4696. /**
  4697. * The name of this extension.
  4698. */
  4699. this.name = NAME;
  4700. this._loader = loader;
  4701. this.enabled = this._loader.isExtensionUsed(NAME);
  4702. }
  4703. /** @hidden */
  4704. MSFT_audio_emitter.prototype.dispose = function () {
  4705. delete this._loader;
  4706. delete this._clips;
  4707. delete this._emitters;
  4708. };
  4709. /** @hidden */
  4710. MSFT_audio_emitter.prototype.onLoading = function () {
  4711. var extensions = this._loader.gltf.extensions;
  4712. if (extensions && extensions[this.name]) {
  4713. var extension = extensions[this.name];
  4714. this._clips = extension.clips;
  4715. this._emitters = extension.emitters;
  4716. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  4717. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  4718. }
  4719. };
  4720. /** @hidden */
  4721. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  4722. var _this = this;
  4723. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  4724. var promises = new Array();
  4725. promises.push(_this._loader.loadSceneAsync(context, scene));
  4726. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4727. var emitterIndex = _a[_i];
  4728. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4729. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  4730. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4731. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  4732. }
  4733. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  4734. }
  4735. return Promise.all(promises).then(function () { });
  4736. });
  4737. };
  4738. /** @hidden */
  4739. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  4740. var _this = this;
  4741. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4742. var promises = new Array();
  4743. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  4744. var _loop_1 = function (emitterIndex) {
  4745. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4746. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  4747. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  4748. var sound = _a[_i];
  4749. sound.attachToMesh(babylonMesh);
  4750. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4751. sound.setLocalDirectionToMesh(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  4752. 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);
  4753. }
  4754. }
  4755. }));
  4756. };
  4757. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4758. var emitterIndex = _a[_i];
  4759. _loop_1(emitterIndex);
  4760. }
  4761. assign(babylonMesh);
  4762. }).then(function (babylonMesh) {
  4763. return Promise.all(promises).then(function () {
  4764. return babylonMesh;
  4765. });
  4766. });
  4767. });
  4768. };
  4769. /** @hidden */
  4770. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  4771. var _this = this;
  4772. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  4773. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  4774. var promises = new Array();
  4775. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  4776. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  4777. var event_1 = _a[_i];
  4778. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  4779. }
  4780. return Promise.all(promises).then(function () {
  4781. return babylonAnimationGroup;
  4782. });
  4783. });
  4784. });
  4785. };
  4786. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  4787. if (clip._objectURL) {
  4788. return clip._objectURL;
  4789. }
  4790. var promise;
  4791. if (clip.uri) {
  4792. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  4793. }
  4794. else {
  4795. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  4796. promise = this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView);
  4797. }
  4798. clip._objectURL = promise.then(function (data) {
  4799. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  4800. });
  4801. return clip._objectURL;
  4802. };
  4803. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  4804. var _this = this;
  4805. emitter._babylonSounds = emitter._babylonSounds || [];
  4806. if (!emitter._babylonData) {
  4807. var clipPromises = new Array();
  4808. var name_1 = emitter.name || "emitter" + emitter.index;
  4809. var options_1 = {
  4810. loop: false,
  4811. autoplay: false,
  4812. volume: emitter.volume == undefined ? 1 : emitter.volume,
  4813. };
  4814. var _loop_2 = function (i) {
  4815. var clipContext = "#/extensions/" + this_1.name + "/clips";
  4816. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  4817. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  4818. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  4819. sound.refDistance = emitter.refDistance || 1;
  4820. sound.maxDistance = emitter.maxDistance || 256;
  4821. sound.rolloffFactor = emitter.rolloffFactor || 1;
  4822. sound.distanceModel = emitter.distanceModel || 'exponential';
  4823. sound._positionInEmitterSpace = true;
  4824. }));
  4825. };
  4826. var this_1 = this;
  4827. for (var i = 0; i < emitter.clips.length; i++) {
  4828. _loop_2(i);
  4829. }
  4830. var promise = Promise.all(clipPromises).then(function () {
  4831. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  4832. var weightedSound = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  4833. if (emitter.innerAngle) {
  4834. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  4835. }
  4836. if (emitter.outerAngle) {
  4837. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  4838. }
  4839. if (emitter.volume) {
  4840. weightedSound.volume = emitter.volume;
  4841. }
  4842. emitter._babylonData.sound = weightedSound;
  4843. });
  4844. emitter._babylonData = {
  4845. loaded: promise
  4846. };
  4847. }
  4848. return emitter._babylonData.loaded;
  4849. };
  4850. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  4851. switch (action) {
  4852. case "play" /* play */: {
  4853. return function (currentFrame) {
  4854. var frameOffset = (startOffset || 0) + (currentFrame - time);
  4855. sound.play(frameOffset);
  4856. };
  4857. }
  4858. case "stop" /* stop */: {
  4859. return function (currentFrame) {
  4860. sound.stop();
  4861. };
  4862. }
  4863. case "pause" /* pause */: {
  4864. return function (currentFrame) {
  4865. sound.pause();
  4866. };
  4867. }
  4868. default: {
  4869. throw new Error(context + ": Unsupported action " + action);
  4870. }
  4871. }
  4872. };
  4873. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  4874. var _this = this;
  4875. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  4876. return Promise.resolve();
  4877. }
  4878. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  4879. var emitterIndex = event.emitter;
  4880. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("#/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  4881. return this._loadEmitterAsync(context, emitter).then(function () {
  4882. var sound = emitter._babylonData.sound;
  4883. if (sound) {
  4884. var babylonAnimationEvent = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  4885. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  4886. // Make sure all started audio stops when this animation is terminated.
  4887. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  4888. sound.stop();
  4889. });
  4890. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  4891. sound.pause();
  4892. });
  4893. }
  4894. });
  4895. };
  4896. return MSFT_audio_emitter;
  4897. }());
  4898. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  4899. /***/ }),
  4900. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  4901. /*!*****************************************!*\
  4902. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  4903. \*****************************************/
  4904. /*! exports provided: MSFT_lod */
  4905. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4906. "use strict";
  4907. __webpack_require__.r(__webpack_exports__);
  4908. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  4909. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  4910. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  4911. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4912. var NAME = "MSFT_lod";
  4913. /**
  4914. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4915. */
  4916. var MSFT_lod = /** @class */ (function () {
  4917. /** @hidden */
  4918. function MSFT_lod(loader) {
  4919. /**
  4920. * The name of this extension.
  4921. */
  4922. this.name = NAME;
  4923. /**
  4924. * Defines a number that determines the order the extensions are applied.
  4925. */
  4926. this.order = 100;
  4927. /**
  4928. * Maximum number of LODs to load, starting from the lowest LOD.
  4929. */
  4930. this.maxLODsToLoad = 10;
  4931. /**
  4932. * Observable raised when all node LODs of one level are loaded.
  4933. * The event data is the index of the loaded LOD starting from zero.
  4934. * Dispose the loader to cancel the loading of the next level of LODs.
  4935. */
  4936. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4937. /**
  4938. * Observable raised when all material LODs of one level are loaded.
  4939. * The event data is the index of the loaded LOD starting from zero.
  4940. * Dispose the loader to cancel the loading of the next level of LODs.
  4941. */
  4942. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4943. this._nodeIndexLOD = null;
  4944. this._nodeSignalLODs = new Array();
  4945. this._nodePromiseLODs = new Array();
  4946. this._materialIndexLOD = null;
  4947. this._materialSignalLODs = new Array();
  4948. this._materialPromiseLODs = new Array();
  4949. this._indexLOD = null;
  4950. this._bufferLODs = new Array();
  4951. this._loader = loader;
  4952. this.enabled = this._loader.isExtensionUsed(NAME);
  4953. }
  4954. /** @hidden */
  4955. MSFT_lod.prototype.dispose = function () {
  4956. this._disposeUnusedMaterials();
  4957. delete this._loader;
  4958. this._nodeIndexLOD = null;
  4959. this._nodeSignalLODs.length = 0;
  4960. this._nodePromiseLODs.length = 0;
  4961. this._materialIndexLOD = null;
  4962. this._materialSignalLODs.length = 0;
  4963. this._materialPromiseLODs.length = 0;
  4964. this._indexLOD = null;
  4965. this._bufferLODs.length = 0;
  4966. this.onMaterialLODsLoadedObservable.clear();
  4967. this.onNodeLODsLoadedObservable.clear();
  4968. };
  4969. /** @hidden */
  4970. MSFT_lod.prototype.onReady = function () {
  4971. var _this = this;
  4972. var _loop_1 = function (indexLOD) {
  4973. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  4974. if (indexLOD !== 0) {
  4975. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  4976. }
  4977. _this._loader.log("Loaded node LOD " + indexLOD);
  4978. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  4979. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  4980. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  4981. if (_this._nodeSignalLODs[indexLOD]) {
  4982. _this._nodeSignalLODs[indexLOD].resolve();
  4983. }
  4984. }
  4985. });
  4986. this_1._loader._completePromises.push(promise);
  4987. };
  4988. var this_1 = this;
  4989. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  4990. _loop_1(indexLOD);
  4991. }
  4992. var _loop_2 = function (indexLOD) {
  4993. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  4994. if (indexLOD !== 0) {
  4995. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  4996. }
  4997. _this._loader.log("Loaded material LOD " + indexLOD);
  4998. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  4999. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  5000. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  5001. if (_this._materialSignalLODs[indexLOD]) {
  5002. _this._materialSignalLODs[indexLOD].resolve();
  5003. }
  5004. }
  5005. });
  5006. this_2._loader._completePromises.push(promise);
  5007. };
  5008. var this_2 = this;
  5009. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  5010. _loop_2(indexLOD);
  5011. }
  5012. for (var indexLOD = 1; indexLOD < this._bufferLODs.length; indexLOD++) {
  5013. this._loadBufferLOD(indexLOD);
  5014. }
  5015. };
  5016. /** @hidden */
  5017. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  5018. var _this = this;
  5019. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5020. var firstPromise;
  5021. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5022. _this._loader.logOpen("" + extensionContext);
  5023. var _loop_3 = function (indexLOD) {
  5024. var nodeLOD = nodeLODs[indexLOD];
  5025. _this._indexLOD = indexLOD;
  5026. if (indexLOD !== 0) {
  5027. _this._nodeIndexLOD = indexLOD;
  5028. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5029. }
  5030. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5031. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5032. if (indexLOD !== 0) {
  5033. // TODO: should not rely on _babylonTransformNode
  5034. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5035. if (previousNodeLOD._babylonTransformNode) {
  5036. previousNodeLOD._babylonTransformNode.dispose();
  5037. delete previousNodeLOD._babylonTransformNode;
  5038. _this._disposeUnusedMaterials();
  5039. }
  5040. }
  5041. babylonMesh.setEnabled(true);
  5042. return babylonMesh;
  5043. });
  5044. if (indexLOD === 0) {
  5045. firstPromise = promise;
  5046. if (_this._bufferLODs.length !== 0) {
  5047. _this._loadBufferLOD(0);
  5048. }
  5049. }
  5050. else {
  5051. _this._nodeIndexLOD = null;
  5052. }
  5053. _this._indexLOD = null;
  5054. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5055. _this._nodePromiseLODs[indexLOD].push(promise);
  5056. };
  5057. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5058. _loop_3(indexLOD);
  5059. }
  5060. _this._loader.logClose();
  5061. return firstPromise;
  5062. });
  5063. };
  5064. /** @hidden */
  5065. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5066. var _this = this;
  5067. // Don't load material LODs if already loading a node LOD.
  5068. if (this._indexLOD) {
  5069. return null;
  5070. }
  5071. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5072. var firstPromise;
  5073. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5074. _this._loader.logOpen("" + extensionContext);
  5075. var _loop_4 = function (indexLOD) {
  5076. var materialLOD = materialLODs[indexLOD];
  5077. _this._indexLOD = indexLOD;
  5078. if (indexLOD !== 0) {
  5079. _this._materialIndexLOD = indexLOD;
  5080. }
  5081. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5082. if (indexLOD === 0) {
  5083. assign(babylonMaterial);
  5084. }
  5085. }).then(function (babylonMaterial) {
  5086. if (indexLOD !== 0) {
  5087. assign(babylonMaterial);
  5088. // TODO: should not rely on _data
  5089. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5090. if (previousDataLOD[babylonDrawMode]) {
  5091. previousDataLOD[babylonDrawMode].babylonMaterial.dispose();
  5092. delete previousDataLOD[babylonDrawMode];
  5093. }
  5094. }
  5095. return babylonMaterial;
  5096. });
  5097. if (indexLOD === 0) {
  5098. firstPromise = promise;
  5099. if (_this._bufferLODs.length !== 0) {
  5100. _this._loadBufferLOD(0);
  5101. }
  5102. }
  5103. else {
  5104. _this._materialIndexLOD = null;
  5105. }
  5106. _this._indexLOD = null;
  5107. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5108. _this._materialPromiseLODs[indexLOD].push(promise);
  5109. };
  5110. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5111. _loop_4(indexLOD);
  5112. }
  5113. _this._loader.logClose();
  5114. return firstPromise;
  5115. });
  5116. };
  5117. /** @hidden */
  5118. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5119. var _this = this;
  5120. // Defer the loading of uris if loading a material or node LOD.
  5121. if (this._materialIndexLOD !== null) {
  5122. this._loader.log("deferred");
  5123. var previousIndexLOD = this._materialIndexLOD - 1;
  5124. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5125. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5126. return _this._loader.loadUriAsync(context, property, uri);
  5127. });
  5128. }
  5129. else if (this._nodeIndexLOD !== null) {
  5130. this._loader.log("deferred");
  5131. var previousIndexLOD = this._nodeIndexLOD - 1;
  5132. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5133. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5134. return _this._loader.loadUriAsync(context, property, uri);
  5135. });
  5136. }
  5137. return null;
  5138. };
  5139. /** @hidden */
  5140. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5141. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5142. if (!this._loader.bin) {
  5143. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5144. }
  5145. // Non-LOD buffers will be bucketed into the first LOD.
  5146. var indexLOD = this._indexLOD || 0;
  5147. var start = byteOffset;
  5148. var end = start + byteLength - 1;
  5149. var bufferLOD_1 = this._bufferLODs[indexLOD];
  5150. if (bufferLOD_1) {
  5151. bufferLOD_1.start = Math.min(bufferLOD_1.start, start);
  5152. bufferLOD_1.end = Math.max(bufferLOD_1.end, end);
  5153. }
  5154. else {
  5155. bufferLOD_1 = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5156. this._bufferLODs[indexLOD] = bufferLOD_1;
  5157. }
  5158. return bufferLOD_1.loaded.promise.then(function (data) {
  5159. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD_1.start, byteLength);
  5160. });
  5161. }
  5162. return null;
  5163. };
  5164. MSFT_lod.prototype._loadBufferLOD = function (indexLOD) {
  5165. var bufferLOD = this._bufferLODs[indexLOD];
  5166. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5167. bufferLOD.loaded.resolve(data);
  5168. }, function (error) {
  5169. bufferLOD.loaded.reject(error);
  5170. });
  5171. };
  5172. /**
  5173. * Gets an array of LOD properties from lowest to highest.
  5174. */
  5175. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5176. if (this.maxLODsToLoad <= 0) {
  5177. throw new Error("maxLODsToLoad must be greater than zero");
  5178. }
  5179. var properties = new Array();
  5180. for (var i = ids.length - 1; i >= 0; i--) {
  5181. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5182. if (properties.length === this.maxLODsToLoad) {
  5183. return properties;
  5184. }
  5185. }
  5186. properties.push(property);
  5187. return properties;
  5188. };
  5189. MSFT_lod.prototype._disposeUnusedMaterials = function () {
  5190. // TODO: should not rely on _data
  5191. var materials = this._loader.gltf.materials;
  5192. if (materials) {
  5193. for (var _i = 0, materials_1 = materials; _i < materials_1.length; _i++) {
  5194. var material = materials_1[_i];
  5195. if (material._data) {
  5196. var _loop_5 = function (drawMode) {
  5197. var data = material._data[drawMode];
  5198. if (data.babylonMeshes.every(function (babylonMesh) { return babylonMesh.material !== data.babylonMaterial; })) {
  5199. // TODO: check if texture is in use instead of force disposing textures
  5200. data.babylonMaterial.dispose(false, true);
  5201. delete material._data[drawMode];
  5202. }
  5203. };
  5204. for (var drawMode in material._data) {
  5205. _loop_5(drawMode);
  5206. }
  5207. }
  5208. }
  5209. }
  5210. };
  5211. return MSFT_lod;
  5212. }());
  5213. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5214. /***/ }),
  5215. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5216. /*!***************************************************!*\
  5217. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5218. \***************************************************/
  5219. /*! exports provided: MSFT_minecraftMesh */
  5220. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5221. "use strict";
  5222. __webpack_require__.r(__webpack_exports__);
  5223. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5224. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5225. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5226. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5227. var NAME = "MSFT_minecraftMesh";
  5228. /** @hidden */
  5229. var MSFT_minecraftMesh = /** @class */ (function () {
  5230. function MSFT_minecraftMesh(loader) {
  5231. this.name = NAME;
  5232. this._loader = loader;
  5233. this.enabled = this._loader.isExtensionUsed(NAME);
  5234. }
  5235. MSFT_minecraftMesh.prototype.dispose = function () {
  5236. delete this._loader;
  5237. };
  5238. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5239. var _this = this;
  5240. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5241. if (extra) {
  5242. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5243. throw new Error(extraContext + ": Material type not supported");
  5244. }
  5245. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5246. if (babylonMaterial.needAlphaBlending()) {
  5247. babylonMaterial.forceDepthWrite = true;
  5248. babylonMaterial.separateCullingPass = true;
  5249. }
  5250. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5251. babylonMaterial.twoSidedLighting = true;
  5252. return promise;
  5253. }
  5254. return null;
  5255. });
  5256. };
  5257. return MSFT_minecraftMesh;
  5258. }());
  5259. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5260. /***/ }),
  5261. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5262. /*!*************************************************!*\
  5263. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5264. \*************************************************/
  5265. /*! exports provided: MSFT_sRGBFactors */
  5266. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5267. "use strict";
  5268. __webpack_require__.r(__webpack_exports__);
  5269. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5270. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5271. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5272. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5273. var NAME = "MSFT_sRGBFactors";
  5274. /** @hidden */
  5275. var MSFT_sRGBFactors = /** @class */ (function () {
  5276. function MSFT_sRGBFactors(loader) {
  5277. this.name = NAME;
  5278. this._loader = loader;
  5279. this.enabled = this._loader.isExtensionUsed(NAME);
  5280. }
  5281. MSFT_sRGBFactors.prototype.dispose = function () {
  5282. delete this._loader;
  5283. };
  5284. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5285. var _this = this;
  5286. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5287. if (extra) {
  5288. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5289. throw new Error(extraContext + ": Material type not supported");
  5290. }
  5291. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5292. if (!babylonMaterial.albedoTexture) {
  5293. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5294. }
  5295. if (!babylonMaterial.reflectivityTexture) {
  5296. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5297. }
  5298. return promise;
  5299. }
  5300. return null;
  5301. });
  5302. };
  5303. return MSFT_sRGBFactors;
  5304. }());
  5305. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5306. /***/ }),
  5307. /***/ "./glTF/2.0/Extensions/index.ts":
  5308. /*!**************************************!*\
  5309. !*** ./glTF/2.0/Extensions/index.ts ***!
  5310. \**************************************/
  5311. /*! 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 */
  5312. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5313. "use strict";
  5314. __webpack_require__.r(__webpack_exports__);
  5315. /* 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");
  5316. /* 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"]; });
  5317. /* 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");
  5318. /* 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"]; });
  5319. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5320. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  5321. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5322. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  5323. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5324. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  5325. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5326. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_clearcoat"]; });
  5327. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5328. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_sheen"]; });
  5329. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5330. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_specular"]; });
  5331. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  5332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__["KHR_mesh_quantization"]; });
  5333. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__["KHR_texture_transform"]; });
  5335. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5336. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__["MSFT_audio_emitter"]; });
  5337. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5338. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__["MSFT_lod"]; });
  5339. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5340. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__["MSFT_minecraftMesh"]; });
  5341. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5342. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__["MSFT_sRGBFactors"]; });
  5343. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5344. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__["ExtrasAsMetadata"]; });
  5345. /***/ }),
  5346. /***/ "./glTF/2.0/glTFLoader.ts":
  5347. /*!********************************!*\
  5348. !*** ./glTF/2.0/glTFLoader.ts ***!
  5349. \********************************/
  5350. /*! exports provided: ArrayItem, GLTFLoader */
  5351. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5352. "use strict";
  5353. __webpack_require__.r(__webpack_exports__);
  5354. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5355. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5356. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  5357. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5358. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5359. /**
  5360. * Helper class for working with arrays when loading the glTF asset
  5361. */
  5362. var ArrayItem = /** @class */ (function () {
  5363. function ArrayItem() {
  5364. }
  5365. /**
  5366. * Gets an item from the given array.
  5367. * @param context The context when loading the asset
  5368. * @param array The array to get the item from
  5369. * @param index The index to the array
  5370. * @returns The array item
  5371. */
  5372. ArrayItem.Get = function (context, array, index) {
  5373. if (!array || index == undefined || !array[index]) {
  5374. throw new Error(context + ": Failed to find index (" + index + ")");
  5375. }
  5376. return array[index];
  5377. };
  5378. /**
  5379. * Assign an `index` field to each item of the given array.
  5380. * @param array The array of items
  5381. */
  5382. ArrayItem.Assign = function (array) {
  5383. if (array) {
  5384. for (var index = 0; index < array.length; index++) {
  5385. array[index].index = index;
  5386. }
  5387. }
  5388. };
  5389. return ArrayItem;
  5390. }());
  5391. /**
  5392. * The glTF 2.0 loader
  5393. */
  5394. var GLTFLoader = /** @class */ (function () {
  5395. /** @hidden */
  5396. function GLTFLoader(parent) {
  5397. /** @hidden */
  5398. this._completePromises = new Array();
  5399. this._disposed = false;
  5400. this._state = null;
  5401. this._extensions = new Array();
  5402. this._defaultBabylonMaterialData = {};
  5403. this._requests = new Array();
  5404. this._parent = parent;
  5405. }
  5406. /**
  5407. * Registers a loader extension.
  5408. * @param name The name of the loader extension.
  5409. * @param factory The factory function that creates the loader extension.
  5410. */
  5411. GLTFLoader.RegisterExtension = function (name, factory) {
  5412. if (GLTFLoader.UnregisterExtension(name)) {
  5413. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  5414. }
  5415. GLTFLoader._RegisteredExtensions[name] = {
  5416. factory: factory
  5417. };
  5418. };
  5419. /**
  5420. * Unregisters a loader extension.
  5421. * @param name The name of the loader extension.
  5422. * @returns A boolean indicating whether the extension has been unregistered
  5423. */
  5424. GLTFLoader.UnregisterExtension = function (name) {
  5425. if (!GLTFLoader._RegisteredExtensions[name]) {
  5426. return false;
  5427. }
  5428. delete GLTFLoader._RegisteredExtensions[name];
  5429. return true;
  5430. };
  5431. Object.defineProperty(GLTFLoader.prototype, "state", {
  5432. /**
  5433. * Gets the loader state.
  5434. */
  5435. get: function () {
  5436. return this._state;
  5437. },
  5438. enumerable: true,
  5439. configurable: true
  5440. });
  5441. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  5442. /**
  5443. * The object that represents the glTF JSON.
  5444. */
  5445. get: function () {
  5446. return this._gltf;
  5447. },
  5448. enumerable: true,
  5449. configurable: true
  5450. });
  5451. Object.defineProperty(GLTFLoader.prototype, "bin", {
  5452. /**
  5453. * The BIN chunk of a binary glTF.
  5454. */
  5455. get: function () {
  5456. return this._bin;
  5457. },
  5458. enumerable: true,
  5459. configurable: true
  5460. });
  5461. Object.defineProperty(GLTFLoader.prototype, "parent", {
  5462. /**
  5463. * The parent file loader.
  5464. */
  5465. get: function () {
  5466. return this._parent;
  5467. },
  5468. enumerable: true,
  5469. configurable: true
  5470. });
  5471. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  5472. /**
  5473. * The Babylon scene when loading the asset.
  5474. */
  5475. get: function () {
  5476. return this._babylonScene;
  5477. },
  5478. enumerable: true,
  5479. configurable: true
  5480. });
  5481. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  5482. /**
  5483. * The root Babylon mesh when loading the asset.
  5484. */
  5485. get: function () {
  5486. return this._rootBabylonMesh;
  5487. },
  5488. enumerable: true,
  5489. configurable: true
  5490. });
  5491. /** @hidden */
  5492. GLTFLoader.prototype.dispose = function () {
  5493. if (this._disposed) {
  5494. return;
  5495. }
  5496. this._disposed = true;
  5497. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  5498. var request = _a[_i];
  5499. request.abort();
  5500. }
  5501. this._requests.length = 0;
  5502. this._completePromises.length = 0;
  5503. for (var name_1 in this._extensions) {
  5504. var extension = this._extensions[name_1];
  5505. extension.dispose && extension.dispose();
  5506. delete this._extensions[name_1];
  5507. }
  5508. delete this._gltf;
  5509. delete this._babylonScene;
  5510. delete this._rootBabylonMesh;
  5511. delete this._progressCallback;
  5512. this._parent._clear();
  5513. };
  5514. /** @hidden */
  5515. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  5516. var _this = this;
  5517. return Promise.resolve().then(function () {
  5518. _this._babylonScene = scene;
  5519. _this._rootUrl = rootUrl;
  5520. _this._fileName = fileName || "scene";
  5521. _this._progressCallback = onProgress;
  5522. _this._loadData(data);
  5523. var nodes = null;
  5524. if (meshesNames) {
  5525. var nodeMap_1 = {};
  5526. if (_this._gltf.nodes) {
  5527. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  5528. var node = _a[_i];
  5529. if (node.name) {
  5530. nodeMap_1[node.name] = node.index;
  5531. }
  5532. }
  5533. }
  5534. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  5535. nodes = names.map(function (name) {
  5536. var node = nodeMap_1[name];
  5537. if (node === undefined) {
  5538. throw new Error("Failed to find node '" + name + "'");
  5539. }
  5540. return node;
  5541. });
  5542. }
  5543. return _this._loadAsync(nodes, function () {
  5544. return {
  5545. meshes: _this._getMeshes(),
  5546. particleSystems: [],
  5547. skeletons: _this._getSkeletons(),
  5548. animationGroups: _this._getAnimationGroups()
  5549. };
  5550. });
  5551. });
  5552. };
  5553. /** @hidden */
  5554. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  5555. var _this = this;
  5556. return Promise.resolve().then(function () {
  5557. _this._babylonScene = scene;
  5558. _this._rootUrl = rootUrl;
  5559. _this._fileName = fileName || "scene";
  5560. _this._progressCallback = onProgress;
  5561. _this._loadData(data);
  5562. return _this._loadAsync(null, function () { return undefined; });
  5563. });
  5564. };
  5565. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  5566. var _this = this;
  5567. return Promise.resolve().then(function () {
  5568. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  5569. _this._loadExtensions();
  5570. _this._checkExtensions();
  5571. 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];
  5572. 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];
  5573. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  5574. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  5575. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  5576. _this._extensionsOnLoading();
  5577. var promises = new Array();
  5578. // Block the marking of materials dirty until the scene is loaded.
  5579. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  5580. _this._babylonScene.blockMaterialDirtyMechanism = true;
  5581. if (nodes) {
  5582. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  5583. }
  5584. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  5585. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  5586. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  5587. }
  5588. // Restore the blocking of material dirty.
  5589. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  5590. if (_this._parent.compileMaterials) {
  5591. promises.push(_this._compileMaterialsAsync());
  5592. }
  5593. if (_this._parent.compileShadowGenerators) {
  5594. promises.push(_this._compileShadowGeneratorsAsync());
  5595. }
  5596. var resultPromise = Promise.all(promises).then(function () {
  5597. if (_this._rootBabylonMesh) {
  5598. _this._rootBabylonMesh.setEnabled(true);
  5599. }
  5600. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  5601. _this._extensionsOnReady();
  5602. _this._startAnimations();
  5603. return resultFunc();
  5604. });
  5605. resultPromise.then(function () {
  5606. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  5607. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  5608. if (!_this._disposed) {
  5609. Promise.all(_this._completePromises).then(function () {
  5610. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  5611. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  5612. _this._parent.onCompleteObservable.notifyObservers(undefined);
  5613. _this._parent.onCompleteObservable.clear();
  5614. _this.dispose();
  5615. }, function (error) {
  5616. _this._parent.onErrorObservable.notifyObservers(error);
  5617. _this._parent.onErrorObservable.clear();
  5618. _this.dispose();
  5619. });
  5620. }
  5621. });
  5622. });
  5623. return resultPromise;
  5624. }, function (error) {
  5625. if (!_this._disposed) {
  5626. _this._parent.onErrorObservable.notifyObservers(error);
  5627. _this._parent.onErrorObservable.clear();
  5628. _this.dispose();
  5629. }
  5630. throw error;
  5631. });
  5632. };
  5633. GLTFLoader.prototype._loadData = function (data) {
  5634. this._gltf = data.json;
  5635. this._setupData();
  5636. if (data.bin) {
  5637. var buffers = this._gltf.buffers;
  5638. if (buffers && buffers[0] && !buffers[0].uri) {
  5639. var binaryBuffer = buffers[0];
  5640. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  5641. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  5642. }
  5643. this._bin = data.bin;
  5644. }
  5645. else {
  5646. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  5647. }
  5648. }
  5649. };
  5650. GLTFLoader.prototype._setupData = function () {
  5651. ArrayItem.Assign(this._gltf.accessors);
  5652. ArrayItem.Assign(this._gltf.animations);
  5653. ArrayItem.Assign(this._gltf.buffers);
  5654. ArrayItem.Assign(this._gltf.bufferViews);
  5655. ArrayItem.Assign(this._gltf.cameras);
  5656. ArrayItem.Assign(this._gltf.images);
  5657. ArrayItem.Assign(this._gltf.materials);
  5658. ArrayItem.Assign(this._gltf.meshes);
  5659. ArrayItem.Assign(this._gltf.nodes);
  5660. ArrayItem.Assign(this._gltf.samplers);
  5661. ArrayItem.Assign(this._gltf.scenes);
  5662. ArrayItem.Assign(this._gltf.skins);
  5663. ArrayItem.Assign(this._gltf.textures);
  5664. if (this._gltf.nodes) {
  5665. var nodeParents = {};
  5666. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  5667. var node = _a[_i];
  5668. if (node.children) {
  5669. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  5670. var index = _c[_b];
  5671. nodeParents[index] = node.index;
  5672. }
  5673. }
  5674. }
  5675. var rootNode = this._createRootNode();
  5676. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  5677. var node = _e[_d];
  5678. var parentIndex = nodeParents[node.index];
  5679. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  5680. }
  5681. }
  5682. };
  5683. GLTFLoader.prototype._loadExtensions = function () {
  5684. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  5685. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  5686. if (extension.name !== name_2) {
  5687. 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);
  5688. }
  5689. this._extensions.push(extension);
  5690. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  5691. }
  5692. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  5693. this._parent.onExtensionLoadedObservable.clear();
  5694. };
  5695. GLTFLoader.prototype._checkExtensions = function () {
  5696. if (this._gltf.extensionsRequired) {
  5697. var _loop_1 = function (name_3) {
  5698. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  5699. if (!available) {
  5700. throw new Error("Require extension " + name_3 + " is not available");
  5701. }
  5702. };
  5703. var this_1 = this;
  5704. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  5705. var name_3 = _a[_i];
  5706. _loop_1(name_3);
  5707. }
  5708. }
  5709. };
  5710. GLTFLoader.prototype._setState = function (state) {
  5711. this._state = state;
  5712. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  5713. };
  5714. GLTFLoader.prototype._createRootNode = function () {
  5715. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  5716. this._rootBabylonMesh.setEnabled(false);
  5717. var rootNode = {
  5718. _babylonTransformNode: this._rootBabylonMesh,
  5719. index: -1
  5720. };
  5721. switch (this._parent.coordinateSystemMode) {
  5722. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  5723. if (!this._babylonScene.useRightHandedSystem) {
  5724. rootNode.rotation = [0, 1, 0, 0];
  5725. rootNode.scale = [1, 1, -1];
  5726. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  5727. }
  5728. break;
  5729. }
  5730. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  5731. this._babylonScene.useRightHandedSystem = true;
  5732. break;
  5733. }
  5734. default: {
  5735. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  5736. }
  5737. }
  5738. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  5739. return rootNode;
  5740. };
  5741. /**
  5742. * Loads a glTF scene.
  5743. * @param context The context when loading the asset
  5744. * @param scene The glTF scene property
  5745. * @returns A promise that resolves when the load is complete
  5746. */
  5747. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  5748. var _this = this;
  5749. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  5750. if (extensionPromise) {
  5751. return extensionPromise;
  5752. }
  5753. var promises = new Array();
  5754. this.logOpen(context + " " + (scene.name || ""));
  5755. if (scene.nodes) {
  5756. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  5757. var index = _a[_i];
  5758. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  5759. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  5760. babylonMesh.parent = _this._rootBabylonMesh;
  5761. }));
  5762. }
  5763. }
  5764. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  5765. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  5766. if (this._gltf.nodes) {
  5767. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  5768. var node = _c[_b];
  5769. if (node._babylonTransformNode && node._babylonBones) {
  5770. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  5771. var babylonBone = _e[_d];
  5772. babylonBone.linkTransformNode(node._babylonTransformNode);
  5773. }
  5774. }
  5775. }
  5776. }
  5777. promises.push(this._loadAnimationsAsync());
  5778. this.logClose();
  5779. return Promise.all(promises).then(function () { });
  5780. };
  5781. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  5782. if (node._primitiveBabylonMeshes) {
  5783. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  5784. var babylonMesh = _a[_i];
  5785. callback(babylonMesh);
  5786. }
  5787. }
  5788. };
  5789. GLTFLoader.prototype._getMeshes = function () {
  5790. var meshes = new Array();
  5791. // Root mesh is always first.
  5792. meshes.push(this._rootBabylonMesh);
  5793. var nodes = this._gltf.nodes;
  5794. if (nodes) {
  5795. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  5796. var node = nodes_1[_i];
  5797. this._forEachPrimitive(node, function (babylonMesh) {
  5798. meshes.push(babylonMesh);
  5799. });
  5800. }
  5801. }
  5802. return meshes;
  5803. };
  5804. GLTFLoader.prototype._getSkeletons = function () {
  5805. var skeletons = new Array();
  5806. var skins = this._gltf.skins;
  5807. if (skins) {
  5808. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  5809. var skin = skins_1[_i];
  5810. if (skin._data) {
  5811. skeletons.push(skin._data.babylonSkeleton);
  5812. }
  5813. }
  5814. }
  5815. return skeletons;
  5816. };
  5817. GLTFLoader.prototype._getAnimationGroups = function () {
  5818. var animationGroups = new Array();
  5819. var animations = this._gltf.animations;
  5820. if (animations) {
  5821. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  5822. var animation = animations_1[_i];
  5823. if (animation._babylonAnimationGroup) {
  5824. animationGroups.push(animation._babylonAnimationGroup);
  5825. }
  5826. }
  5827. }
  5828. return animationGroups;
  5829. };
  5830. GLTFLoader.prototype._startAnimations = function () {
  5831. switch (this._parent.animationStartMode) {
  5832. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  5833. // do nothing
  5834. break;
  5835. }
  5836. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  5837. var babylonAnimationGroups = this._getAnimationGroups();
  5838. if (babylonAnimationGroups.length !== 0) {
  5839. babylonAnimationGroups[0].start(true);
  5840. }
  5841. break;
  5842. }
  5843. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  5844. var babylonAnimationGroups = this._getAnimationGroups();
  5845. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  5846. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  5847. babylonAnimationGroup.start(true);
  5848. }
  5849. break;
  5850. }
  5851. default: {
  5852. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  5853. return;
  5854. }
  5855. }
  5856. };
  5857. /**
  5858. * Loads a glTF node.
  5859. * @param context The context when loading the asset
  5860. * @param node The glTF node property
  5861. * @param assign A function called synchronously after parsing the glTF properties
  5862. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  5863. */
  5864. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  5865. var _this = this;
  5866. if (assign === void 0) { assign = function () { }; }
  5867. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  5868. if (extensionPromise) {
  5869. return extensionPromise;
  5870. }
  5871. if (node._babylonTransformNode) {
  5872. throw new Error(context + ": Invalid recursive node hierarchy");
  5873. }
  5874. var promises = new Array();
  5875. this.logOpen(context + " " + (node.name || ""));
  5876. var loadNode = function (babylonTransformNode) {
  5877. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  5878. GLTFLoader._LoadTransform(node, babylonTransformNode);
  5879. if (node.camera != undefined) {
  5880. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  5881. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  5882. babylonCamera.parent = babylonTransformNode;
  5883. }));
  5884. }
  5885. if (node.children) {
  5886. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  5887. var index = _a[_i];
  5888. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  5889. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  5890. childBabylonMesh.parent = babylonTransformNode;
  5891. }));
  5892. }
  5893. }
  5894. assign(babylonTransformNode);
  5895. };
  5896. if (node.mesh == undefined) {
  5897. var nodeName = node.name || "node" + node.index;
  5898. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  5899. loadNode(node._babylonTransformNode);
  5900. }
  5901. else {
  5902. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  5903. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  5904. }
  5905. this.logClose();
  5906. return Promise.all(promises).then(function () {
  5907. _this._forEachPrimitive(node, function (babylonMesh) {
  5908. babylonMesh.refreshBoundingInfo(true);
  5909. });
  5910. return node._babylonTransformNode;
  5911. });
  5912. };
  5913. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  5914. var primitives = mesh.primitives;
  5915. if (!primitives || !primitives.length) {
  5916. throw new Error(context + ": Primitives are missing");
  5917. }
  5918. if (primitives[0].index == undefined) {
  5919. ArrayItem.Assign(primitives);
  5920. }
  5921. var promises = new Array();
  5922. this.logOpen(context + " " + (mesh.name || ""));
  5923. var name = node.name || "node" + node.index;
  5924. if (primitives.length === 1) {
  5925. var primitive = mesh.primitives[0];
  5926. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  5927. node._babylonTransformNode = babylonMesh;
  5928. node._primitiveBabylonMeshes = [babylonMesh];
  5929. }));
  5930. }
  5931. else {
  5932. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  5933. node._primitiveBabylonMeshes = [];
  5934. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  5935. var primitive = primitives_1[_i];
  5936. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  5937. babylonMesh.parent = node._babylonTransformNode;
  5938. node._primitiveBabylonMeshes.push(babylonMesh);
  5939. }));
  5940. }
  5941. }
  5942. if (node.skin != undefined) {
  5943. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  5944. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  5945. }
  5946. assign(node._babylonTransformNode);
  5947. this.logClose();
  5948. return Promise.all(promises).then(function () {
  5949. return node._babylonTransformNode;
  5950. });
  5951. };
  5952. /**
  5953. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  5954. * @param context The context when loading the asset
  5955. * @param name The mesh name when loading the asset
  5956. * @param node The glTF node when loading the asset
  5957. * @param mesh The glTF mesh when loading the asset
  5958. * @param primitive The glTF mesh primitive property
  5959. * @param assign A function called synchronously after parsing the glTF properties
  5960. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  5961. */
  5962. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  5963. var _this = this;
  5964. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  5965. if (extensionPromise) {
  5966. return extensionPromise;
  5967. }
  5968. this.logOpen("" + context);
  5969. var shouldInstance = this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  5970. var babylonAbstractMesh;
  5971. var promise;
  5972. if (shouldInstance && primitive._instanceData) {
  5973. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  5974. promise = primitive._instanceData.promise;
  5975. }
  5976. else {
  5977. var promises = new Array();
  5978. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  5979. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  5980. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  5981. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  5982. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  5983. babylonGeometry.applyToMesh(babylonMesh_1);
  5984. });
  5985. }));
  5986. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  5987. if (primitive.material == undefined) {
  5988. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  5989. if (!babylonMaterial) {
  5990. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  5991. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  5992. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  5993. }
  5994. babylonMesh_1.material = babylonMaterial;
  5995. }
  5996. else {
  5997. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  5998. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  5999. babylonMesh_1.material = babylonMaterial;
  6000. }));
  6001. }
  6002. promise = Promise.all(promises);
  6003. if (shouldInstance) {
  6004. primitive._instanceData = {
  6005. babylonSourceMesh: babylonMesh_1,
  6006. promise: promise
  6007. };
  6008. }
  6009. babylonAbstractMesh = babylonMesh_1;
  6010. }
  6011. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  6012. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  6013. assign(babylonAbstractMesh);
  6014. this.logClose();
  6015. return promise.then(function () {
  6016. return babylonAbstractMesh;
  6017. });
  6018. };
  6019. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  6020. var _this = this;
  6021. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  6022. if (extensionPromise) {
  6023. return extensionPromise;
  6024. }
  6025. var attributes = primitive.attributes;
  6026. if (!attributes) {
  6027. throw new Error(context + ": Attributes are missing");
  6028. }
  6029. var promises = new Array();
  6030. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  6031. if (primitive.indices == undefined) {
  6032. babylonMesh.isUnIndexed = true;
  6033. }
  6034. else {
  6035. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6036. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6037. babylonGeometry.setIndices(data);
  6038. }));
  6039. }
  6040. var loadAttribute = function (attribute, kind, callback) {
  6041. if (attributes[attribute] == undefined) {
  6042. return;
  6043. }
  6044. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6045. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6046. babylonMesh._delayInfo.push(kind);
  6047. }
  6048. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6049. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6050. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6051. }));
  6052. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6053. babylonMesh.numBoneInfluencers = 8;
  6054. }
  6055. if (callback) {
  6056. callback(accessor);
  6057. }
  6058. };
  6059. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6060. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6061. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6062. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6063. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6064. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6065. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6066. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  6067. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  6068. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6069. if (accessor.type === "VEC4" /* VEC4 */) {
  6070. babylonMesh.hasVertexAlpha = true;
  6071. }
  6072. });
  6073. return Promise.all(promises).then(function () {
  6074. return babylonGeometry;
  6075. });
  6076. };
  6077. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6078. if (!primitive.targets) {
  6079. return;
  6080. }
  6081. if (node._numMorphTargets == undefined) {
  6082. node._numMorphTargets = primitive.targets.length;
  6083. }
  6084. else if (primitive.targets.length !== node._numMorphTargets) {
  6085. throw new Error(context + ": Primitives do not have the same number of targets");
  6086. }
  6087. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6088. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6089. for (var index = 0; index < primitive.targets.length; index++) {
  6090. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6091. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6092. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6093. // TODO: tell the target whether it has positions, normals, tangents
  6094. }
  6095. };
  6096. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6097. if (!primitive.targets) {
  6098. return Promise.resolve();
  6099. }
  6100. var promises = new Array();
  6101. var morphTargetManager = babylonMesh.morphTargetManager;
  6102. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6103. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6104. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6105. }
  6106. return Promise.all(promises).then(function () { });
  6107. };
  6108. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6109. var _this = this;
  6110. var promises = new Array();
  6111. var loadAttribute = function (attribute, kind, setData) {
  6112. if (attributes[attribute] == undefined) {
  6113. return;
  6114. }
  6115. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6116. if (!babylonVertexBuffer) {
  6117. return;
  6118. }
  6119. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6120. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6121. setData(babylonVertexBuffer, data);
  6122. }));
  6123. };
  6124. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6125. var positions = new Float32Array(data.length);
  6126. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6127. positions[index] = data[index] + value;
  6128. });
  6129. babylonMorphTarget.setPositions(positions);
  6130. });
  6131. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6132. var normals = new Float32Array(data.length);
  6133. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6134. normals[index] = data[index] + value;
  6135. });
  6136. babylonMorphTarget.setNormals(normals);
  6137. });
  6138. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6139. var tangents = new Float32Array(data.length / 3 * 4);
  6140. var dataIndex = 0;
  6141. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6142. // Tangent data for morph targets is stored as xyz delta.
  6143. // The vertexData.tangent is stored as xyzw.
  6144. // So we need to skip every fourth vertexData.tangent.
  6145. if (((index + 1) % 4) !== 0) {
  6146. tangents[dataIndex] = data[dataIndex] + value;
  6147. dataIndex++;
  6148. }
  6149. });
  6150. babylonMorphTarget.setTangents(tangents);
  6151. });
  6152. return Promise.all(promises).then(function () { });
  6153. };
  6154. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6155. // Ignore the TRS of skinned nodes.
  6156. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6157. if (node.skin != undefined) {
  6158. return;
  6159. }
  6160. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6161. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6162. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6163. if (node.matrix) {
  6164. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6165. matrix.decompose(scaling, rotation, position);
  6166. }
  6167. else {
  6168. if (node.translation) {
  6169. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6170. }
  6171. if (node.rotation) {
  6172. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6173. }
  6174. if (node.scale) {
  6175. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6176. }
  6177. }
  6178. babylonNode.position = position;
  6179. babylonNode.rotationQuaternion = rotation;
  6180. babylonNode.scaling = scaling;
  6181. };
  6182. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6183. var _this = this;
  6184. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6185. if (extensionPromise) {
  6186. return extensionPromise;
  6187. }
  6188. var assignSkeleton = function (skeleton) {
  6189. _this._forEachPrimitive(node, function (babylonMesh) {
  6190. babylonMesh.skeleton = skeleton;
  6191. });
  6192. };
  6193. if (skin._data) {
  6194. assignSkeleton(skin._data.babylonSkeleton);
  6195. return skin._data.promise;
  6196. }
  6197. var skeletonId = "skeleton" + skin.index;
  6198. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6199. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6200. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6201. this._loadBones(context, skin, babylonSkeleton);
  6202. assignSkeleton(babylonSkeleton);
  6203. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6204. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6205. });
  6206. skin._data = {
  6207. babylonSkeleton: babylonSkeleton,
  6208. promise: promise
  6209. };
  6210. return promise;
  6211. };
  6212. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6213. var babylonBones = {};
  6214. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6215. var index = _a[_i];
  6216. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6217. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6218. }
  6219. };
  6220. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6221. var babylonBone = babylonBones[node.index];
  6222. if (babylonBone) {
  6223. return babylonBone;
  6224. }
  6225. var babylonParentBone = null;
  6226. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6227. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6228. }
  6229. var boneIndex = skin.joints.indexOf(node.index);
  6230. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6231. babylonBones[node.index] = babylonBone;
  6232. node._babylonBones = node._babylonBones || [];
  6233. node._babylonBones.push(babylonBone);
  6234. return babylonBone;
  6235. };
  6236. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6237. if (skin.inverseBindMatrices == undefined) {
  6238. return Promise.resolve(null);
  6239. }
  6240. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6241. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6242. };
  6243. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6244. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6245. var babylonBone = _a[_i];
  6246. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6247. var boneIndex = babylonBone._index;
  6248. if (inverseBindMatricesData && boneIndex !== -1) {
  6249. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6250. baseMatrix.invertToRef(baseMatrix);
  6251. }
  6252. var babylonParentBone = babylonBone.getParent();
  6253. if (babylonParentBone) {
  6254. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6255. }
  6256. babylonBone.updateMatrix(baseMatrix, false, false);
  6257. babylonBone._updateDifferenceMatrix(undefined, false);
  6258. }
  6259. };
  6260. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6261. return node.matrix ?
  6262. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6263. 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());
  6264. };
  6265. /**
  6266. * Loads a glTF camera.
  6267. * @param context The context when loading the asset
  6268. * @param camera The glTF camera property
  6269. * @param assign A function called synchronously after parsing the glTF properties
  6270. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6271. */
  6272. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6273. if (assign === void 0) { assign = function () { }; }
  6274. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6275. if (extensionPromise) {
  6276. return extensionPromise;
  6277. }
  6278. var promises = new Array();
  6279. this.logOpen(context + " " + (camera.name || ""));
  6280. 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);
  6281. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6282. switch (camera.type) {
  6283. case "perspective" /* PERSPECTIVE */: {
  6284. var perspective = camera.perspective;
  6285. if (!perspective) {
  6286. throw new Error(context + ": Camera perspective properties are missing");
  6287. }
  6288. babylonCamera.fov = perspective.yfov;
  6289. babylonCamera.minZ = perspective.znear;
  6290. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6291. break;
  6292. }
  6293. case "orthographic" /* ORTHOGRAPHIC */: {
  6294. if (!camera.orthographic) {
  6295. throw new Error(context + ": Camera orthographic properties are missing");
  6296. }
  6297. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6298. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6299. babylonCamera.orthoRight = camera.orthographic.xmag;
  6300. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6301. babylonCamera.orthoTop = camera.orthographic.ymag;
  6302. babylonCamera.minZ = camera.orthographic.znear;
  6303. babylonCamera.maxZ = camera.orthographic.zfar;
  6304. break;
  6305. }
  6306. default: {
  6307. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6308. }
  6309. }
  6310. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6311. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6312. assign(babylonCamera);
  6313. return Promise.all(promises).then(function () {
  6314. return babylonCamera;
  6315. });
  6316. };
  6317. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6318. var animations = this._gltf.animations;
  6319. if (!animations) {
  6320. return Promise.resolve();
  6321. }
  6322. var promises = new Array();
  6323. for (var index = 0; index < animations.length; index++) {
  6324. var animation = animations[index];
  6325. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6326. }
  6327. return Promise.all(promises).then(function () { });
  6328. };
  6329. /**
  6330. * Loads a glTF animation.
  6331. * @param context The context when loading the asset
  6332. * @param animation The glTF animation property
  6333. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6334. */
  6335. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6336. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6337. if (promise) {
  6338. return promise;
  6339. }
  6340. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6341. animation._babylonAnimationGroup = babylonAnimationGroup;
  6342. var promises = new Array();
  6343. ArrayItem.Assign(animation.channels);
  6344. ArrayItem.Assign(animation.samplers);
  6345. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6346. var channel = _a[_i];
  6347. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6348. }
  6349. return Promise.all(promises).then(function () {
  6350. babylonAnimationGroup.normalize(0);
  6351. return babylonAnimationGroup;
  6352. });
  6353. };
  6354. /**
  6355. * @hidden Loads a glTF animation channel.
  6356. * @param context The context when loading the asset
  6357. * @param animationContext The context of the animation when loading the asset
  6358. * @param animation The glTF animation property
  6359. * @param channel The glTF animation channel property
  6360. * @param babylonAnimationGroup The babylon animation group property
  6361. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6362. * @returns A void promise when the channel load is complete
  6363. */
  6364. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6365. var _this = this;
  6366. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6367. if (channel.target.node == undefined) {
  6368. return Promise.resolve();
  6369. }
  6370. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6371. // Ignore animations that have no animation targets.
  6372. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6373. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6374. return Promise.resolve();
  6375. }
  6376. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6377. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6378. var targetPath;
  6379. var animationType;
  6380. switch (channel.target.path) {
  6381. case "translation" /* TRANSLATION */: {
  6382. targetPath = "position";
  6383. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6384. break;
  6385. }
  6386. case "rotation" /* ROTATION */: {
  6387. targetPath = "rotationQuaternion";
  6388. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  6389. break;
  6390. }
  6391. case "scale" /* SCALE */: {
  6392. targetPath = "scaling";
  6393. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6394. break;
  6395. }
  6396. case "weights" /* WEIGHTS */: {
  6397. targetPath = "influence";
  6398. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  6399. break;
  6400. }
  6401. default: {
  6402. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  6403. }
  6404. }
  6405. var outputBufferOffset = 0;
  6406. var getNextOutputValue;
  6407. switch (targetPath) {
  6408. case "position": {
  6409. getNextOutputValue = function () {
  6410. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6411. outputBufferOffset += 3;
  6412. return value;
  6413. };
  6414. break;
  6415. }
  6416. case "rotationQuaternion": {
  6417. getNextOutputValue = function () {
  6418. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  6419. outputBufferOffset += 4;
  6420. return value;
  6421. };
  6422. break;
  6423. }
  6424. case "scaling": {
  6425. getNextOutputValue = function () {
  6426. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6427. outputBufferOffset += 3;
  6428. return value;
  6429. };
  6430. break;
  6431. }
  6432. case "influence": {
  6433. getNextOutputValue = function () {
  6434. var value = new Array(targetNode._numMorphTargets);
  6435. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  6436. value[i] = data.output[outputBufferOffset++];
  6437. }
  6438. return value;
  6439. };
  6440. break;
  6441. }
  6442. }
  6443. var getNextKey;
  6444. switch (data.interpolation) {
  6445. case "STEP" /* STEP */: {
  6446. getNextKey = function (frameIndex) { return ({
  6447. frame: data.input[frameIndex],
  6448. value: getNextOutputValue(),
  6449. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  6450. }); };
  6451. break;
  6452. }
  6453. case "LINEAR" /* LINEAR */: {
  6454. getNextKey = function (frameIndex) { return ({
  6455. frame: data.input[frameIndex],
  6456. value: getNextOutputValue()
  6457. }); };
  6458. break;
  6459. }
  6460. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6461. getNextKey = function (frameIndex) { return ({
  6462. frame: data.input[frameIndex],
  6463. inTangent: getNextOutputValue(),
  6464. value: getNextOutputValue(),
  6465. outTangent: getNextOutputValue()
  6466. }); };
  6467. break;
  6468. }
  6469. }
  6470. var keys = new Array(data.input.length);
  6471. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  6472. keys[frameIndex] = getNextKey(frameIndex);
  6473. }
  6474. if (targetPath === "influence") {
  6475. var _loop_2 = function (targetIndex) {
  6476. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6477. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6478. babylonAnimation.setKeys(keys.map(function (key) { return ({
  6479. frame: key.frame,
  6480. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  6481. value: key.value[targetIndex],
  6482. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  6483. }); }));
  6484. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  6485. var babylonMesh = babylonAbstractMesh;
  6486. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  6487. var babylonAnimationClone = babylonAnimation.clone();
  6488. morphTarget.animations.push(babylonAnimationClone);
  6489. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  6490. });
  6491. };
  6492. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  6493. _loop_2(targetIndex);
  6494. }
  6495. }
  6496. else {
  6497. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6498. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6499. babylonAnimation.setKeys(keys);
  6500. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  6501. animationTargetOverride.animations.push(babylonAnimation);
  6502. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  6503. }
  6504. else {
  6505. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  6506. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  6507. }
  6508. }
  6509. });
  6510. };
  6511. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  6512. if (sampler._data) {
  6513. return sampler._data;
  6514. }
  6515. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  6516. switch (interpolation) {
  6517. case "STEP" /* STEP */:
  6518. case "LINEAR" /* LINEAR */:
  6519. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6520. break;
  6521. }
  6522. default: {
  6523. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  6524. }
  6525. }
  6526. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  6527. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  6528. sampler._data = Promise.all([
  6529. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  6530. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  6531. ]).then(function (_a) {
  6532. var inputData = _a[0], outputData = _a[1];
  6533. return {
  6534. input: inputData,
  6535. interpolation: interpolation,
  6536. output: outputData,
  6537. };
  6538. });
  6539. return sampler._data;
  6540. };
  6541. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6542. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  6543. if (extensionPromise) {
  6544. return extensionPromise;
  6545. }
  6546. if (!buffer._data) {
  6547. if (buffer.uri) {
  6548. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  6549. }
  6550. else {
  6551. if (!this._bin) {
  6552. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6553. }
  6554. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  6555. }
  6556. }
  6557. return buffer._data.then(function (data) {
  6558. try {
  6559. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  6560. }
  6561. catch (e) {
  6562. throw new Error(context + ": " + e.message);
  6563. }
  6564. });
  6565. };
  6566. /**
  6567. * Loads a glTF buffer view.
  6568. * @param context The context when loading the asset
  6569. * @param bufferView The glTF buffer view property
  6570. * @returns A promise that resolves with the loaded data when the load is complete
  6571. */
  6572. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  6573. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  6574. if (extensionPromise) {
  6575. return extensionPromise;
  6576. }
  6577. if (bufferView._data) {
  6578. return bufferView._data;
  6579. }
  6580. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  6581. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  6582. return bufferView._data;
  6583. };
  6584. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  6585. var _this = this;
  6586. if (accessor._data) {
  6587. return accessor._data;
  6588. }
  6589. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  6590. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  6591. var length = numComponents * accessor.count;
  6592. if (accessor.bufferView == undefined) {
  6593. accessor._data = Promise.resolve(new constructor(length));
  6594. }
  6595. else {
  6596. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6597. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  6598. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6599. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  6600. }
  6601. else {
  6602. var typedArray_1 = new constructor(length);
  6603. 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) {
  6604. typedArray_1[index] = value;
  6605. });
  6606. return typedArray_1;
  6607. }
  6608. });
  6609. }
  6610. if (accessor.sparse) {
  6611. var sparse_1 = accessor.sparse;
  6612. accessor._data = accessor._data.then(function (data) {
  6613. var typedArray = data;
  6614. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  6615. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  6616. return Promise.all([
  6617. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  6618. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  6619. ]).then(function (_a) {
  6620. var indicesData = _a[0], valuesData = _a[1];
  6621. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  6622. var sparseLength = numComponents * sparse_1.count;
  6623. var values;
  6624. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6625. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6626. }
  6627. else {
  6628. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6629. values = new constructor(sparseLength);
  6630. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  6631. values[index] = value;
  6632. });
  6633. }
  6634. var valuesIndex = 0;
  6635. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  6636. var dataIndex = indices[indicesIndex] * numComponents;
  6637. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  6638. typedArray[dataIndex++] = values[valuesIndex++];
  6639. }
  6640. }
  6641. return typedArray;
  6642. });
  6643. });
  6644. }
  6645. return accessor._data;
  6646. };
  6647. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  6648. return this._loadAccessorAsync(context, accessor, Float32Array);
  6649. };
  6650. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  6651. if (accessor.type !== "SCALAR" /* SCALAR */) {
  6652. throw new Error(context + "/type: Invalid value " + accessor.type);
  6653. }
  6654. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  6655. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  6656. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  6657. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  6658. }
  6659. if (accessor._data) {
  6660. return accessor._data;
  6661. }
  6662. if (accessor.sparse) {
  6663. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  6664. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  6665. }
  6666. else {
  6667. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6668. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6669. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  6670. });
  6671. }
  6672. return accessor._data;
  6673. };
  6674. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  6675. var _this = this;
  6676. if (bufferView._babylonBuffer) {
  6677. return bufferView._babylonBuffer;
  6678. }
  6679. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6680. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  6681. });
  6682. return bufferView._babylonBuffer;
  6683. };
  6684. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  6685. var _this = this;
  6686. if (accessor._babylonVertexBuffer) {
  6687. return accessor._babylonVertexBuffer;
  6688. }
  6689. if (accessor.sparse) {
  6690. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6691. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6692. });
  6693. }
  6694. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  6695. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  6696. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  6697. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6698. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6699. });
  6700. }
  6701. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  6702. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  6703. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6704. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6705. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6706. });
  6707. }
  6708. else {
  6709. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6710. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  6711. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  6712. 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);
  6713. });
  6714. }
  6715. return accessor._babylonVertexBuffer;
  6716. };
  6717. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  6718. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6719. throw new Error(context + ": Material type not supported");
  6720. }
  6721. var promises = new Array();
  6722. if (properties) {
  6723. if (properties.baseColorFactor) {
  6724. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  6725. babylonMaterial.alpha = properties.baseColorFactor[3];
  6726. }
  6727. else {
  6728. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  6729. }
  6730. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  6731. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  6732. if (properties.baseColorTexture) {
  6733. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  6734. texture.name = babylonMaterial.name + " (Base Color)";
  6735. babylonMaterial.albedoTexture = texture;
  6736. }));
  6737. }
  6738. if (properties.metallicRoughnessTexture) {
  6739. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  6740. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  6741. babylonMaterial.metallicTexture = texture;
  6742. }));
  6743. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  6744. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  6745. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  6746. }
  6747. }
  6748. return Promise.all(promises).then(function () { });
  6749. };
  6750. /** @hidden */
  6751. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6752. if (assign === void 0) { assign = function () { }; }
  6753. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  6754. if (extensionPromise) {
  6755. return extensionPromise;
  6756. }
  6757. material._data = material._data || {};
  6758. var babylonData = material._data[babylonDrawMode];
  6759. if (!babylonData) {
  6760. this.logOpen(context + " " + (material.name || ""));
  6761. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  6762. babylonData = {
  6763. babylonMaterial: babylonMaterial,
  6764. babylonMeshes: [],
  6765. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  6766. };
  6767. material._data[babylonDrawMode] = babylonData;
  6768. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  6769. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6770. this.logClose();
  6771. }
  6772. babylonData.babylonMeshes.push(babylonMesh);
  6773. babylonMesh.onDisposeObservable.addOnce(function () {
  6774. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  6775. if (index !== -1) {
  6776. babylonData.babylonMeshes.splice(index, 1);
  6777. }
  6778. });
  6779. assign(babylonData.babylonMaterial);
  6780. return babylonData.promise.then(function () {
  6781. return babylonData.babylonMaterial;
  6782. });
  6783. };
  6784. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  6785. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  6786. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  6787. babylonMaterial.fillMode = babylonDrawMode;
  6788. babylonMaterial.enableSpecularAntiAliasing = true;
  6789. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  6790. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  6791. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6792. babylonMaterial.metallic = 1;
  6793. babylonMaterial.roughness = 1;
  6794. return babylonMaterial;
  6795. };
  6796. /**
  6797. * Creates a Babylon material from a glTF material.
  6798. * @param context The context when loading the asset
  6799. * @param material The glTF material property
  6800. * @param babylonDrawMode The draw mode for the Babylon material
  6801. * @returns The Babylon material
  6802. */
  6803. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  6804. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  6805. if (extensionPromise) {
  6806. return extensionPromise;
  6807. }
  6808. var name = material.name || "material" + material.index;
  6809. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  6810. return babylonMaterial;
  6811. };
  6812. /**
  6813. * Loads properties from a glTF material into a Babylon material.
  6814. * @param context The context when loading the asset
  6815. * @param material The glTF material property
  6816. * @param babylonMaterial The Babylon material
  6817. * @returns A promise that resolves when the load is complete
  6818. */
  6819. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6820. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  6821. if (extensionPromise) {
  6822. return extensionPromise;
  6823. }
  6824. var promises = new Array();
  6825. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  6826. if (material.pbrMetallicRoughness) {
  6827. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  6828. }
  6829. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  6830. return Promise.all(promises).then(function () { });
  6831. };
  6832. /**
  6833. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  6834. * @param context The context when loading the asset
  6835. * @param material The glTF material property
  6836. * @param babylonMaterial The Babylon material
  6837. * @returns A promise that resolves when the load is complete
  6838. */
  6839. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  6840. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6841. throw new Error(context + ": Material type not supported");
  6842. }
  6843. var promises = new Array();
  6844. 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);
  6845. if (material.doubleSided) {
  6846. babylonMaterial.backFaceCulling = false;
  6847. babylonMaterial.twoSidedLighting = true;
  6848. }
  6849. if (material.normalTexture) {
  6850. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  6851. texture.name = babylonMaterial.name + " (Normal)";
  6852. babylonMaterial.bumpTexture = texture;
  6853. }));
  6854. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  6855. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  6856. if (material.normalTexture.scale != undefined) {
  6857. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  6858. }
  6859. babylonMaterial.forceIrradianceInFragment = true;
  6860. }
  6861. if (material.occlusionTexture) {
  6862. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  6863. texture.name = babylonMaterial.name + " (Occlusion)";
  6864. babylonMaterial.ambientTexture = texture;
  6865. }));
  6866. babylonMaterial.useAmbientInGrayScale = true;
  6867. if (material.occlusionTexture.strength != undefined) {
  6868. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  6869. }
  6870. }
  6871. if (material.emissiveTexture) {
  6872. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  6873. texture.name = babylonMaterial.name + " (Emissive)";
  6874. babylonMaterial.emissiveTexture = texture;
  6875. }));
  6876. }
  6877. return Promise.all(promises).then(function () { });
  6878. };
  6879. /**
  6880. * Loads the alpha properties from a glTF material into a Babylon material.
  6881. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  6882. * @param context The context when loading the asset
  6883. * @param material The glTF material property
  6884. * @param babylonMaterial The Babylon material
  6885. */
  6886. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  6887. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6888. throw new Error(context + ": Material type not supported");
  6889. }
  6890. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  6891. switch (alphaMode) {
  6892. case "OPAQUE" /* OPAQUE */: {
  6893. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6894. break;
  6895. }
  6896. case "MASK" /* MASK */: {
  6897. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  6898. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  6899. if (babylonMaterial.albedoTexture) {
  6900. babylonMaterial.albedoTexture.hasAlpha = true;
  6901. }
  6902. break;
  6903. }
  6904. case "BLEND" /* BLEND */: {
  6905. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  6906. if (babylonMaterial.albedoTexture) {
  6907. babylonMaterial.albedoTexture.hasAlpha = true;
  6908. babylonMaterial.useAlphaFromAlbedoTexture = true;
  6909. }
  6910. break;
  6911. }
  6912. default: {
  6913. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  6914. }
  6915. }
  6916. };
  6917. /**
  6918. * Loads a glTF texture info.
  6919. * @param context The context when loading the asset
  6920. * @param textureInfo The glTF texture info property
  6921. * @param assign A function called synchronously after parsing the glTF properties
  6922. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  6923. */
  6924. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  6925. var _this = this;
  6926. if (assign === void 0) { assign = function () { }; }
  6927. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  6928. if (extensionPromise) {
  6929. return extensionPromise;
  6930. }
  6931. this.logOpen("" + context);
  6932. if (textureInfo.texCoord >= 2) {
  6933. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  6934. }
  6935. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  6936. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  6937. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  6938. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  6939. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  6940. assign(babylonTexture);
  6941. });
  6942. this.logClose();
  6943. return promise;
  6944. };
  6945. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  6946. var _this = this;
  6947. if (assign === void 0) { assign = function () { }; }
  6948. var promises = new Array();
  6949. this.logOpen(context + " " + (texture.name || ""));
  6950. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  6951. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  6952. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  6953. var url = null;
  6954. if (image.uri) {
  6955. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  6956. url = image.uri;
  6957. }
  6958. else if (this._babylonScene.getEngine().textureFormatInUse) {
  6959. // 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
  6960. url = this._rootUrl + image.uri;
  6961. }
  6962. }
  6963. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6964. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  6965. if (!_this._disposed) {
  6966. deferred.resolve();
  6967. }
  6968. }, function (message, exception) {
  6969. if (!_this._disposed) {
  6970. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  6971. }
  6972. }, undefined, undefined, undefined, image.mimeType);
  6973. promises.push(deferred.promise);
  6974. if (!url) {
  6975. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  6976. var name = image.uri || _this._fileName + "#image" + image.index;
  6977. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  6978. babylonTexture.updateURL(dataUrl, data);
  6979. }));
  6980. }
  6981. babylonTexture.wrapU = samplerData.wrapU;
  6982. babylonTexture.wrapV = samplerData.wrapV;
  6983. assign(babylonTexture);
  6984. this.logClose();
  6985. return Promise.all(promises).then(function () {
  6986. return babylonTexture;
  6987. });
  6988. };
  6989. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  6990. if (!sampler._data) {
  6991. sampler._data = {
  6992. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  6993. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  6994. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  6995. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  6996. };
  6997. }
  6998. return sampler._data;
  6999. };
  7000. /**
  7001. * Loads a glTF image.
  7002. * @param context The context when loading the asset
  7003. * @param image The glTF image property
  7004. * @returns A promise that resolves with the loaded data when the load is complete
  7005. */
  7006. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  7007. if (!image._data) {
  7008. this.logOpen(context + " " + (image.name || ""));
  7009. if (image.uri) {
  7010. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  7011. }
  7012. else {
  7013. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  7014. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  7015. }
  7016. this.logClose();
  7017. }
  7018. return image._data;
  7019. };
  7020. /**
  7021. * Loads a glTF uri.
  7022. * @param context The context when loading the asset
  7023. * @param property The glTF property associated with the uri
  7024. * @param uri The base64 or relative uri
  7025. * @returns A promise that resolves with the loaded data when the load is complete
  7026. */
  7027. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  7028. var _this = this;
  7029. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  7030. if (extensionPromise) {
  7031. return extensionPromise;
  7032. }
  7033. if (!GLTFLoader._ValidateUri(uri)) {
  7034. throw new Error(context + ": '" + uri + "' is invalid");
  7035. }
  7036. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7037. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7038. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7039. return Promise.resolve(data);
  7040. }
  7041. this.log("Loading " + uri);
  7042. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7043. return new Promise(function (resolve, reject) {
  7044. if (!_this._disposed) {
  7045. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  7046. if (!_this._disposed) {
  7047. var data = new Uint8Array(fileData);
  7048. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  7049. resolve(data);
  7050. }
  7051. }, function (event) {
  7052. if (!_this._disposed) {
  7053. if (request_1) {
  7054. request_1._lengthComputable = event.lengthComputable;
  7055. request_1._loaded = event.loaded;
  7056. request_1._total = event.total;
  7057. }
  7058. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  7059. try {
  7060. _this._onProgress();
  7061. }
  7062. catch (e) {
  7063. reject(e);
  7064. }
  7065. }
  7066. }
  7067. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  7068. if (!_this._disposed) {
  7069. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7070. }
  7071. });
  7072. _this._requests.push(request_1);
  7073. }
  7074. });
  7075. });
  7076. };
  7077. GLTFLoader.prototype._onProgress = function () {
  7078. if (!this._progressCallback) {
  7079. return;
  7080. }
  7081. var lengthComputable = true;
  7082. var loaded = 0;
  7083. var total = 0;
  7084. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  7085. var request = _a[_i];
  7086. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  7087. return;
  7088. }
  7089. lengthComputable = lengthComputable && request._lengthComputable;
  7090. loaded += request._loaded;
  7091. total += request._total;
  7092. }
  7093. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  7094. };
  7095. /**
  7096. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7097. * @param babylonObject the Babylon object with metadata
  7098. * @param pointer the JSON pointer
  7099. */
  7100. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7101. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7102. var gltf = (metadata.gltf = metadata.gltf || {});
  7103. var pointers = (gltf.pointers = gltf.pointers || []);
  7104. pointers.push(pointer);
  7105. };
  7106. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7107. // Set defaults if undefined
  7108. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7109. switch (mode) {
  7110. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7111. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7112. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7113. default:
  7114. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7115. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7116. }
  7117. };
  7118. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7119. // Set defaults if undefined
  7120. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7121. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7122. if (magFilter === 9729 /* LINEAR */) {
  7123. switch (minFilter) {
  7124. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7125. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7126. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7127. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7128. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7129. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7130. default:
  7131. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7132. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7133. }
  7134. }
  7135. else {
  7136. if (magFilter !== 9728 /* NEAREST */) {
  7137. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7138. }
  7139. switch (minFilter) {
  7140. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7141. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7142. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7143. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7144. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7145. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7146. default:
  7147. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7148. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7149. }
  7150. }
  7151. };
  7152. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7153. switch (componentType) {
  7154. case 5120 /* BYTE */: return Int8Array;
  7155. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7156. case 5122 /* SHORT */: return Int16Array;
  7157. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7158. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7159. case 5126 /* FLOAT */: return Float32Array;
  7160. default: throw new Error(context + ": Invalid component type " + componentType);
  7161. }
  7162. };
  7163. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7164. var buffer = bufferView.buffer;
  7165. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7166. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7167. try {
  7168. return new constructor(buffer, byteOffset, length);
  7169. }
  7170. catch (e) {
  7171. throw new Error(context + ": " + e);
  7172. }
  7173. };
  7174. GLTFLoader._GetNumComponents = function (context, type) {
  7175. switch (type) {
  7176. case "SCALAR": return 1;
  7177. case "VEC2": return 2;
  7178. case "VEC3": return 3;
  7179. case "VEC4": return 4;
  7180. case "MAT2": return 4;
  7181. case "MAT3": return 9;
  7182. case "MAT4": return 16;
  7183. }
  7184. throw new Error(context + ": Invalid type (" + type + ")");
  7185. };
  7186. GLTFLoader._ValidateUri = function (uri) {
  7187. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7188. };
  7189. GLTFLoader._GetDrawMode = function (context, mode) {
  7190. if (mode == undefined) {
  7191. mode = 4 /* TRIANGLES */;
  7192. }
  7193. switch (mode) {
  7194. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7195. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7196. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7197. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7198. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7199. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7200. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7201. }
  7202. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7203. };
  7204. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7205. var _this = this;
  7206. this._parent._startPerformanceCounter("Compile materials");
  7207. var promises = new Array();
  7208. if (this._gltf.materials) {
  7209. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7210. var material = _a[_i];
  7211. if (material._data) {
  7212. for (var babylonDrawMode in material._data) {
  7213. var babylonData = material._data[babylonDrawMode];
  7214. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7215. var babylonMesh = _c[_b];
  7216. // Ensure nonUniformScaling is set if necessary.
  7217. babylonMesh.computeWorldMatrix(true);
  7218. var babylonMaterial = babylonData.babylonMaterial;
  7219. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7220. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7221. if (this._parent.useClipPlane) {
  7222. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7223. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7224. }
  7225. }
  7226. }
  7227. }
  7228. }
  7229. }
  7230. return Promise.all(promises).then(function () {
  7231. _this._parent._endPerformanceCounter("Compile materials");
  7232. });
  7233. };
  7234. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7235. var _this = this;
  7236. this._parent._startPerformanceCounter("Compile shadow generators");
  7237. var promises = new Array();
  7238. var lights = this._babylonScene.lights;
  7239. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7240. var light = lights_1[_i];
  7241. var generator = light.getShadowGenerator();
  7242. if (generator) {
  7243. promises.push(generator.forceCompilationAsync());
  7244. }
  7245. }
  7246. return Promise.all(promises).then(function () {
  7247. _this._parent._endPerformanceCounter("Compile shadow generators");
  7248. });
  7249. };
  7250. GLTFLoader.prototype._forEachExtensions = function (action) {
  7251. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7252. var extension = _a[_i];
  7253. if (extension.enabled) {
  7254. action(extension);
  7255. }
  7256. }
  7257. };
  7258. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7259. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7260. var extension = _a[_i];
  7261. if (extension.enabled) {
  7262. var id = extension.name + "." + functionName;
  7263. var loaderProperty = property;
  7264. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7265. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7266. if (!activeLoaderExtensionFunctions[id]) {
  7267. activeLoaderExtensionFunctions[id] = true;
  7268. try {
  7269. var result = actionAsync(extension);
  7270. if (result) {
  7271. return result;
  7272. }
  7273. }
  7274. finally {
  7275. delete activeLoaderExtensionFunctions[id];
  7276. }
  7277. }
  7278. }
  7279. }
  7280. return null;
  7281. };
  7282. GLTFLoader.prototype._extensionsOnLoading = function () {
  7283. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7284. };
  7285. GLTFLoader.prototype._extensionsOnReady = function () {
  7286. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7287. };
  7288. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7289. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7290. };
  7291. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7292. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7293. };
  7294. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7295. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7296. };
  7297. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7298. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7299. };
  7300. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7301. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7302. };
  7303. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7304. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7305. };
  7306. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7307. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7308. };
  7309. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7310. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7311. };
  7312. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7313. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7314. };
  7315. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7316. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7317. };
  7318. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7319. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7320. };
  7321. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7322. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7323. };
  7324. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7325. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7326. };
  7327. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7328. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7329. };
  7330. /**
  7331. * Helper method called by a loader extension to load an glTF extension.
  7332. * @param context The context when loading the asset
  7333. * @param property The glTF property to load the extension from
  7334. * @param extensionName The name of the extension to load
  7335. * @param actionAsync The action to run
  7336. * @returns The promise returned by actionAsync or null if the extension does not exist
  7337. */
  7338. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7339. if (!property.extensions) {
  7340. return null;
  7341. }
  7342. var extensions = property.extensions;
  7343. var extension = extensions[extensionName];
  7344. if (!extension) {
  7345. return null;
  7346. }
  7347. return actionAsync(context + "/extensions/" + extensionName, extension);
  7348. };
  7349. /**
  7350. * Helper method called by a loader extension to load a glTF extra.
  7351. * @param context The context when loading the asset
  7352. * @param property The glTF property to load the extra from
  7353. * @param extensionName The name of the extension to load
  7354. * @param actionAsync The action to run
  7355. * @returns The promise returned by actionAsync or null if the extra does not exist
  7356. */
  7357. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7358. if (!property.extras) {
  7359. return null;
  7360. }
  7361. var extras = property.extras;
  7362. var extra = extras[extensionName];
  7363. if (!extra) {
  7364. return null;
  7365. }
  7366. return actionAsync(context + "/extras/" + extensionName, extra);
  7367. };
  7368. /**
  7369. * Checks for presence of an extension.
  7370. * @param name The name of the extension to check
  7371. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7372. */
  7373. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7374. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7375. };
  7376. /**
  7377. * Increments the indentation level and logs a message.
  7378. * @param message The message to log
  7379. */
  7380. GLTFLoader.prototype.logOpen = function (message) {
  7381. this._parent._logOpen(message);
  7382. };
  7383. /**
  7384. * Decrements the indentation level.
  7385. */
  7386. GLTFLoader.prototype.logClose = function () {
  7387. this._parent._logClose();
  7388. };
  7389. /**
  7390. * Logs a message
  7391. * @param message The message to log
  7392. */
  7393. GLTFLoader.prototype.log = function (message) {
  7394. this._parent._log(message);
  7395. };
  7396. /**
  7397. * Starts a performance counter.
  7398. * @param counterName The name of the performance counter
  7399. */
  7400. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7401. this._parent._startPerformanceCounter(counterName);
  7402. };
  7403. /**
  7404. * Ends a performance counter.
  7405. * @param counterName The name of the performance counter
  7406. */
  7407. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7408. this._parent._endPerformanceCounter(counterName);
  7409. };
  7410. GLTFLoader._DefaultSampler = { index: -1 };
  7411. GLTFLoader._RegisteredExtensions = {};
  7412. return GLTFLoader;
  7413. }());
  7414. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  7415. /***/ }),
  7416. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  7417. /*!******************************************!*\
  7418. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  7419. \******************************************/
  7420. /*! no static exports found */
  7421. /***/ (function(module, exports) {
  7422. /***/ }),
  7423. /***/ "./glTF/2.0/index.ts":
  7424. /*!***************************!*\
  7425. !*** ./glTF/2.0/index.ts ***!
  7426. \***************************/
  7427. /*! 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 */
  7428. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7429. "use strict";
  7430. __webpack_require__.r(__webpack_exports__);
  7431. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  7432. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  7433. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  7434. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  7435. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  7436. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  7437. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  7438. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  7439. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  7440. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  7441. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  7442. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  7443. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  7444. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  7445. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  7446. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  7447. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  7448. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  7449. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  7450. /***/ }),
  7451. /***/ "./glTF/glTFFileLoader.ts":
  7452. /*!********************************!*\
  7453. !*** ./glTF/glTFFileLoader.ts ***!
  7454. \********************************/
  7455. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  7456. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7457. "use strict";
  7458. __webpack_require__.r(__webpack_exports__);
  7459. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  7460. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  7461. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  7462. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  7463. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  7464. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  7465. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  7466. /**
  7467. * Mode that determines the coordinate system to use.
  7468. */
  7469. var GLTFLoaderCoordinateSystemMode;
  7470. (function (GLTFLoaderCoordinateSystemMode) {
  7471. /**
  7472. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  7473. */
  7474. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  7475. /**
  7476. * Sets the useRightHandedSystem flag on the scene.
  7477. */
  7478. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  7479. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  7480. /**
  7481. * Mode that determines what animations will start.
  7482. */
  7483. var GLTFLoaderAnimationStartMode;
  7484. (function (GLTFLoaderAnimationStartMode) {
  7485. /**
  7486. * No animation will start.
  7487. */
  7488. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  7489. /**
  7490. * The first animation will start.
  7491. */
  7492. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  7493. /**
  7494. * All animations will start.
  7495. */
  7496. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  7497. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  7498. /**
  7499. * Loader state.
  7500. */
  7501. var GLTFLoaderState;
  7502. (function (GLTFLoaderState) {
  7503. /**
  7504. * The asset is loading.
  7505. */
  7506. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  7507. /**
  7508. * The asset is ready for rendering.
  7509. */
  7510. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  7511. /**
  7512. * The asset is completely loaded.
  7513. */
  7514. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  7515. })(GLTFLoaderState || (GLTFLoaderState = {}));
  7516. /**
  7517. * File loader for loading glTF files into a scene.
  7518. */
  7519. var GLTFFileLoader = /** @class */ (function () {
  7520. function GLTFFileLoader() {
  7521. // --------------
  7522. // Common options
  7523. // --------------
  7524. /**
  7525. * Raised when the asset has been parsed
  7526. */
  7527. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7528. // ----------
  7529. // V2 options
  7530. // ----------
  7531. /**
  7532. * The coordinate system mode. Defaults to AUTO.
  7533. */
  7534. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  7535. /**
  7536. * The animation start mode. Defaults to FIRST.
  7537. */
  7538. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  7539. /**
  7540. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  7541. */
  7542. this.compileMaterials = false;
  7543. /**
  7544. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  7545. */
  7546. this.useClipPlane = false;
  7547. /**
  7548. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  7549. */
  7550. this.compileShadowGenerators = false;
  7551. /**
  7552. * Defines if the Alpha blended materials are only applied as coverage.
  7553. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  7554. * If true, no extra effects are applied to transparent pixels.
  7555. */
  7556. this.transparencyAsCoverage = false;
  7557. /**
  7558. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  7559. * Enabling will disable offline support and glTF validator.
  7560. * Defaults to false.
  7561. */
  7562. this.useRangeRequests = false;
  7563. /**
  7564. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  7565. */
  7566. this.createInstances = true;
  7567. /**
  7568. * Function called before loading a url referenced by the asset.
  7569. */
  7570. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7571. /**
  7572. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7573. */
  7574. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7575. /**
  7576. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  7577. */
  7578. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7579. /**
  7580. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  7581. */
  7582. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7583. /**
  7584. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  7585. */
  7586. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7587. /**
  7588. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  7589. * For assets with LODs, raised when all of the LODs are complete.
  7590. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7591. */
  7592. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7593. /**
  7594. * Observable raised when an error occurs.
  7595. */
  7596. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7597. /**
  7598. * Observable raised after the loader is disposed.
  7599. */
  7600. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7601. /**
  7602. * Observable raised after a loader extension is created.
  7603. * Set additional options for a loader extension in this event.
  7604. */
  7605. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7606. /**
  7607. * Defines if the loader should validate the asset.
  7608. */
  7609. this.validate = false;
  7610. /**
  7611. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  7612. */
  7613. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7614. this._loader = null;
  7615. /**
  7616. * Name of the loader ("gltf")
  7617. */
  7618. this.name = "gltf";
  7619. /** @hidden */
  7620. this.extensions = {
  7621. ".gltf": { isBinary: false },
  7622. ".glb": { isBinary: true }
  7623. };
  7624. this._logIndentLevel = 0;
  7625. this._loggingEnabled = false;
  7626. /** @hidden */
  7627. this._log = this._logDisabled;
  7628. this._capturePerformanceCounters = false;
  7629. /** @hidden */
  7630. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7631. /** @hidden */
  7632. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7633. }
  7634. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  7635. /**
  7636. * Raised when the asset has been parsed
  7637. */
  7638. set: function (callback) {
  7639. if (this._onParsedObserver) {
  7640. this.onParsedObservable.remove(this._onParsedObserver);
  7641. }
  7642. this._onParsedObserver = this.onParsedObservable.add(callback);
  7643. },
  7644. enumerable: true,
  7645. configurable: true
  7646. });
  7647. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  7648. /**
  7649. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7650. */
  7651. set: function (callback) {
  7652. if (this._onMeshLoadedObserver) {
  7653. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  7654. }
  7655. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  7656. },
  7657. enumerable: true,
  7658. configurable: true
  7659. });
  7660. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  7661. /**
  7662. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  7663. */
  7664. set: function (callback) {
  7665. if (this._onTextureLoadedObserver) {
  7666. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  7667. }
  7668. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  7669. },
  7670. enumerable: true,
  7671. configurable: true
  7672. });
  7673. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  7674. /**
  7675. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  7676. */
  7677. set: function (callback) {
  7678. if (this._onMaterialLoadedObserver) {
  7679. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  7680. }
  7681. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  7682. },
  7683. enumerable: true,
  7684. configurable: true
  7685. });
  7686. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  7687. /**
  7688. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  7689. */
  7690. set: function (callback) {
  7691. if (this._onCameraLoadedObserver) {
  7692. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  7693. }
  7694. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  7695. },
  7696. enumerable: true,
  7697. configurable: true
  7698. });
  7699. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  7700. /**
  7701. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  7702. * For assets with LODs, raised when all of the LODs are complete.
  7703. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7704. */
  7705. set: function (callback) {
  7706. if (this._onCompleteObserver) {
  7707. this.onCompleteObservable.remove(this._onCompleteObserver);
  7708. }
  7709. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  7710. },
  7711. enumerable: true,
  7712. configurable: true
  7713. });
  7714. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  7715. /**
  7716. * Callback raised when an error occurs.
  7717. */
  7718. set: function (callback) {
  7719. if (this._onErrorObserver) {
  7720. this.onErrorObservable.remove(this._onErrorObserver);
  7721. }
  7722. this._onErrorObserver = this.onErrorObservable.add(callback);
  7723. },
  7724. enumerable: true,
  7725. configurable: true
  7726. });
  7727. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  7728. /**
  7729. * Callback raised after the loader is disposed.
  7730. */
  7731. set: function (callback) {
  7732. if (this._onDisposeObserver) {
  7733. this.onDisposeObservable.remove(this._onDisposeObserver);
  7734. }
  7735. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  7736. },
  7737. enumerable: true,
  7738. configurable: true
  7739. });
  7740. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  7741. /**
  7742. * Callback raised after a loader extension is created.
  7743. */
  7744. set: function (callback) {
  7745. if (this._onExtensionLoadedObserver) {
  7746. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  7747. }
  7748. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  7749. },
  7750. enumerable: true,
  7751. configurable: true
  7752. });
  7753. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  7754. /**
  7755. * Defines if the loader logging is enabled.
  7756. */
  7757. get: function () {
  7758. return this._loggingEnabled;
  7759. },
  7760. set: function (value) {
  7761. if (this._loggingEnabled === value) {
  7762. return;
  7763. }
  7764. this._loggingEnabled = value;
  7765. if (this._loggingEnabled) {
  7766. this._log = this._logEnabled;
  7767. }
  7768. else {
  7769. this._log = this._logDisabled;
  7770. }
  7771. },
  7772. enumerable: true,
  7773. configurable: true
  7774. });
  7775. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  7776. /**
  7777. * Defines if the loader should capture performance counters.
  7778. */
  7779. get: function () {
  7780. return this._capturePerformanceCounters;
  7781. },
  7782. set: function (value) {
  7783. if (this._capturePerformanceCounters === value) {
  7784. return;
  7785. }
  7786. this._capturePerformanceCounters = value;
  7787. if (this._capturePerformanceCounters) {
  7788. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  7789. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  7790. }
  7791. else {
  7792. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7793. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7794. }
  7795. },
  7796. enumerable: true,
  7797. configurable: true
  7798. });
  7799. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  7800. /**
  7801. * Callback raised after a loader extension is created.
  7802. */
  7803. set: function (callback) {
  7804. if (this._onValidatedObserver) {
  7805. this.onValidatedObservable.remove(this._onValidatedObserver);
  7806. }
  7807. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  7808. },
  7809. enumerable: true,
  7810. configurable: true
  7811. });
  7812. /**
  7813. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  7814. */
  7815. GLTFFileLoader.prototype.dispose = function () {
  7816. if (this._loader) {
  7817. this._loader.dispose();
  7818. this._loader = null;
  7819. }
  7820. this._clear();
  7821. this.onDisposeObservable.notifyObservers(undefined);
  7822. this.onDisposeObservable.clear();
  7823. };
  7824. /** @hidden */
  7825. GLTFFileLoader.prototype._clear = function () {
  7826. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7827. this.onMeshLoadedObservable.clear();
  7828. this.onTextureLoadedObservable.clear();
  7829. this.onMaterialLoadedObservable.clear();
  7830. this.onCameraLoadedObservable.clear();
  7831. this.onCompleteObservable.clear();
  7832. this.onExtensionLoadedObservable.clear();
  7833. };
  7834. /** @hidden */
  7835. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  7836. var _this = this;
  7837. if (useArrayBuffer) {
  7838. if (this.useRangeRequests) {
  7839. if (this.validate) {
  7840. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  7841. }
  7842. var fileRequests_1 = new Array();
  7843. var aggregatedFileRequest_1 = {
  7844. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  7845. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  7846. };
  7847. var dataBuffer_1 = {
  7848. readAsync: function (byteOffset, byteLength) {
  7849. return new Promise(function (resolve, reject) {
  7850. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  7851. dataBuffer_1.byteLength = Number(webRequest.getResponseHeader("Content-Range").split("/")[1]);
  7852. resolve(new Uint8Array(data));
  7853. }, onProgress, true, true, function (error) {
  7854. reject(error);
  7855. }, function (webRequest) {
  7856. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  7857. }));
  7858. });
  7859. },
  7860. byteLength: 0
  7861. };
  7862. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  7863. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  7864. onSuccess(loaderData);
  7865. }, onError);
  7866. return aggregatedFileRequest_1;
  7867. }
  7868. return scene._requestFile(url, function (data, request) {
  7869. var arrayBuffer = data;
  7870. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7871. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  7872. byteLength: arrayBuffer.byteLength
  7873. })).then(function (loaderData) {
  7874. onSuccess(loaderData, request);
  7875. }, onError);
  7876. }, onProgress, true, true, onError);
  7877. }
  7878. return scene._requestFile(url, function (data, response) {
  7879. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  7880. onSuccess({ json: _this._parseJson(data) }, response);
  7881. }, onProgress, true, false, onError);
  7882. };
  7883. /** @hidden */
  7884. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  7885. var _this = this;
  7886. return scene._readFile(file, function (data) {
  7887. _this._validate(scene, data, "file:", file.name);
  7888. if (useArrayBuffer) {
  7889. var arrayBuffer_1 = data;
  7890. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7891. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  7892. byteLength: arrayBuffer_1.byteLength
  7893. })).then(onSuccess, onError);
  7894. }
  7895. else {
  7896. onSuccess({ json: _this._parseJson(data) });
  7897. }
  7898. }, onProgress, useArrayBuffer, onError);
  7899. };
  7900. /** @hidden */
  7901. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  7902. var _this = this;
  7903. return Promise.resolve().then(function () {
  7904. _this.onParsedObservable.notifyObservers(data);
  7905. _this.onParsedObservable.clear();
  7906. _this._log("Loading " + (fileName || ""));
  7907. _this._loader = _this._getLoader(data);
  7908. return _this._loader.importMeshAsync(meshesNames, scene, data, rootUrl, onProgress, fileName);
  7909. });
  7910. };
  7911. /** @hidden */
  7912. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7913. var _this = this;
  7914. return Promise.resolve().then(function () {
  7915. _this.onParsedObservable.notifyObservers(data);
  7916. _this.onParsedObservable.clear();
  7917. _this._log("Loading " + (fileName || ""));
  7918. _this._loader = _this._getLoader(data);
  7919. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  7920. });
  7921. };
  7922. /** @hidden */
  7923. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7924. var _this = this;
  7925. return Promise.resolve().then(function () {
  7926. _this.onParsedObservable.notifyObservers(data);
  7927. _this.onParsedObservable.clear();
  7928. _this._log("Loading " + (fileName || ""));
  7929. _this._loader = _this._getLoader(data);
  7930. // Get materials/textures when loading to add to container
  7931. var materials = [];
  7932. _this.onMaterialLoadedObservable.add(function (material) {
  7933. materials.push(material);
  7934. });
  7935. var textures = [];
  7936. _this.onTextureLoadedObservable.add(function (texture) {
  7937. textures.push(texture);
  7938. });
  7939. return _this._loader.importMeshAsync(null, scene, data, rootUrl, onProgress, fileName).then(function (result) {
  7940. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  7941. Array.prototype.push.apply(container.meshes, result.meshes);
  7942. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  7943. Array.prototype.push.apply(container.skeletons, result.skeletons);
  7944. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  7945. Array.prototype.push.apply(container.materials, materials);
  7946. Array.prototype.push.apply(container.textures, textures);
  7947. container.removeAllFromScene();
  7948. return container;
  7949. });
  7950. });
  7951. };
  7952. /** @hidden */
  7953. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  7954. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  7955. };
  7956. /** @hidden */
  7957. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  7958. this._validate(scene, data);
  7959. return { json: this._parseJson(data) };
  7960. };
  7961. /** @hidden */
  7962. GLTFFileLoader.prototype.createPlugin = function () {
  7963. return new GLTFFileLoader();
  7964. };
  7965. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  7966. /**
  7967. * The loader state or null if the loader is not active.
  7968. */
  7969. get: function () {
  7970. return this._loader ? this._loader.state : null;
  7971. },
  7972. enumerable: true,
  7973. configurable: true
  7974. });
  7975. /**
  7976. * Returns a promise that resolves when the asset is completely loaded.
  7977. * @returns a promise that resolves when the asset is completely loaded.
  7978. */
  7979. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  7980. var _this = this;
  7981. return new Promise(function (resolve, reject) {
  7982. _this.onCompleteObservable.addOnce(function () {
  7983. resolve();
  7984. });
  7985. _this.onErrorObservable.addOnce(function (reason) {
  7986. reject(reason);
  7987. });
  7988. });
  7989. };
  7990. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  7991. var _this = this;
  7992. if (rootUrl === void 0) { rootUrl = ""; }
  7993. if (fileName === void 0) { fileName = ""; }
  7994. if (!this.validate) {
  7995. return;
  7996. }
  7997. this._startPerformanceCounter("Validate JSON");
  7998. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  7999. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  8000. }).then(function (result) {
  8001. _this._endPerformanceCounter("Validate JSON");
  8002. _this.onValidatedObservable.notifyObservers(result);
  8003. _this.onValidatedObservable.clear();
  8004. }, function (reason) {
  8005. _this._endPerformanceCounter("Validate JSON");
  8006. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  8007. _this.onValidatedObservable.clear();
  8008. });
  8009. };
  8010. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  8011. var asset = loaderData.json.asset || {};
  8012. this._log("Asset version: " + asset.version);
  8013. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  8014. asset.generator && this._log("Asset generator: " + asset.generator);
  8015. var version = GLTFFileLoader._parseVersion(asset.version);
  8016. if (!version) {
  8017. throw new Error("Invalid version: " + asset.version);
  8018. }
  8019. if (asset.minVersion !== undefined) {
  8020. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  8021. if (!minVersion) {
  8022. throw new Error("Invalid minimum version: " + asset.minVersion);
  8023. }
  8024. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  8025. throw new Error("Incompatible minimum version: " + asset.minVersion);
  8026. }
  8027. }
  8028. var createLoaders = {
  8029. 1: GLTFFileLoader._CreateGLTF1Loader,
  8030. 2: GLTFFileLoader._CreateGLTF2Loader
  8031. };
  8032. var createLoader = createLoaders[version.major];
  8033. if (!createLoader) {
  8034. throw new Error("Unsupported version: " + asset.version);
  8035. }
  8036. return createLoader(this);
  8037. };
  8038. GLTFFileLoader.prototype._parseJson = function (json) {
  8039. this._startPerformanceCounter("Parse JSON");
  8040. this._log("JSON length: " + json.length);
  8041. var parsed = JSON.parse(json);
  8042. this._endPerformanceCounter("Parse JSON");
  8043. return parsed;
  8044. };
  8045. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8046. var _this = this;
  8047. this._startPerformanceCounter("Unpack Binary");
  8048. // Read magic + version + length + json length + json format
  8049. return dataReader.loadAsync(20).then(function () {
  8050. var Binary = {
  8051. Magic: 0x46546C67
  8052. };
  8053. var magic = dataReader.readUint32();
  8054. if (magic !== Binary.Magic) {
  8055. throw new Error("Unexpected magic: " + magic);
  8056. }
  8057. var version = dataReader.readUint32();
  8058. if (_this.loggingEnabled) {
  8059. _this._log("Binary version: " + version);
  8060. }
  8061. var length = dataReader.readUint32();
  8062. if (length !== dataReader.buffer.byteLength) {
  8063. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8064. }
  8065. var unpacked;
  8066. switch (version) {
  8067. case 1: {
  8068. unpacked = _this._unpackBinaryV1Async(dataReader);
  8069. break;
  8070. }
  8071. case 2: {
  8072. unpacked = _this._unpackBinaryV2Async(dataReader);
  8073. break;
  8074. }
  8075. default: {
  8076. throw new Error("Unsupported version: " + version);
  8077. }
  8078. }
  8079. _this._endPerformanceCounter("Unpack Binary");
  8080. return unpacked;
  8081. });
  8082. };
  8083. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader) {
  8084. var ContentFormat = {
  8085. JSON: 0
  8086. };
  8087. var contentLength = dataReader.readUint32();
  8088. var contentFormat = dataReader.readUint32();
  8089. if (contentFormat !== ContentFormat.JSON) {
  8090. throw new Error("Unexpected content format: " + contentFormat);
  8091. }
  8092. var bodyLength = dataReader.buffer.byteLength - dataReader.byteOffset;
  8093. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8094. if (bodyLength !== 0) {
  8095. var startByteOffset_1 = dataReader.byteOffset;
  8096. data.bin = {
  8097. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8098. byteLength: bodyLength
  8099. };
  8100. }
  8101. return Promise.resolve(data);
  8102. };
  8103. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader) {
  8104. var _this = this;
  8105. var ChunkFormat = {
  8106. JSON: 0x4E4F534A,
  8107. BIN: 0x004E4942
  8108. };
  8109. // Read the JSON chunk header.
  8110. var chunkLength = dataReader.readUint32();
  8111. var chunkFormat = dataReader.readUint32();
  8112. if (chunkFormat !== ChunkFormat.JSON) {
  8113. throw new Error("First chunk format is not JSON");
  8114. }
  8115. // Bail if there are no other chunks.
  8116. if (dataReader.byteOffset + chunkLength === dataReader.buffer.byteLength) {
  8117. return dataReader.loadAsync(chunkLength).then(function () {
  8118. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8119. });
  8120. }
  8121. // Read the JSON chunk and the length and type of the next chunk.
  8122. return dataReader.loadAsync(chunkLength + 8).then(function () {
  8123. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8124. var readAsync = function () {
  8125. var chunkLength = dataReader.readUint32();
  8126. var chunkFormat = dataReader.readUint32();
  8127. switch (chunkFormat) {
  8128. case ChunkFormat.JSON: {
  8129. throw new Error("Unexpected JSON chunk");
  8130. }
  8131. case ChunkFormat.BIN: {
  8132. var startByteOffset_2 = dataReader.byteOffset;
  8133. data.bin = {
  8134. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8135. byteLength: chunkLength
  8136. };
  8137. dataReader.skipBytes(chunkLength);
  8138. break;
  8139. }
  8140. default: {
  8141. // ignore unrecognized chunkFormat
  8142. dataReader.skipBytes(chunkLength);
  8143. break;
  8144. }
  8145. }
  8146. if (dataReader.byteOffset !== dataReader.buffer.byteLength) {
  8147. return dataReader.loadAsync(8).then(readAsync);
  8148. }
  8149. return Promise.resolve(data);
  8150. };
  8151. return readAsync();
  8152. });
  8153. };
  8154. GLTFFileLoader._parseVersion = function (version) {
  8155. if (version === "1.0" || version === "1.0.1") {
  8156. return {
  8157. major: 1,
  8158. minor: 0
  8159. };
  8160. }
  8161. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8162. if (!match) {
  8163. return null;
  8164. }
  8165. return {
  8166. major: parseInt(match[1]),
  8167. minor: parseInt(match[2])
  8168. };
  8169. };
  8170. GLTFFileLoader._compareVersion = function (a, b) {
  8171. if (a.major > b.major) {
  8172. return 1;
  8173. }
  8174. if (a.major < b.major) {
  8175. return -1;
  8176. }
  8177. if (a.minor > b.minor) {
  8178. return 1;
  8179. }
  8180. if (a.minor < b.minor) {
  8181. return -1;
  8182. }
  8183. return 0;
  8184. };
  8185. /** @hidden */
  8186. GLTFFileLoader.prototype._logOpen = function (message) {
  8187. this._log(message);
  8188. this._logIndentLevel++;
  8189. };
  8190. /** @hidden */
  8191. GLTFFileLoader.prototype._logClose = function () {
  8192. --this._logIndentLevel;
  8193. };
  8194. GLTFFileLoader.prototype._logEnabled = function (message) {
  8195. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8196. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8197. };
  8198. GLTFFileLoader.prototype._logDisabled = function (message) {
  8199. };
  8200. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8201. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8202. };
  8203. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8204. };
  8205. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8206. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8207. };
  8208. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8209. };
  8210. // ----------
  8211. // V1 options
  8212. // ----------
  8213. /**
  8214. * 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.
  8215. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8216. * Defaults to true.
  8217. * @hidden
  8218. */
  8219. GLTFFileLoader.IncrementalLoading = true;
  8220. /**
  8221. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8222. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8223. * @hidden
  8224. */
  8225. GLTFFileLoader.HomogeneousCoordinates = false;
  8226. GLTFFileLoader._logSpaces = " ";
  8227. return GLTFFileLoader;
  8228. }());
  8229. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8230. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8231. }
  8232. /***/ }),
  8233. /***/ "./glTF/glTFValidation.ts":
  8234. /*!********************************!*\
  8235. !*** ./glTF/glTFValidation.ts ***!
  8236. \********************************/
  8237. /*! exports provided: GLTFValidation */
  8238. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8239. "use strict";
  8240. __webpack_require__.r(__webpack_exports__);
  8241. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  8242. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  8243. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  8244. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  8245. var options = {
  8246. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  8247. };
  8248. if (fileName) {
  8249. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  8250. }
  8251. return (data instanceof ArrayBuffer)
  8252. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  8253. : GLTFValidator.validateString(data, options);
  8254. }
  8255. /**
  8256. * The worker function that gets converted to a blob url to pass into a worker.
  8257. */
  8258. function workerFunc() {
  8259. var pendingExternalResources = [];
  8260. onmessage = function (message) {
  8261. var data = message.data;
  8262. switch (data.id) {
  8263. case "init": {
  8264. importScripts(data.url);
  8265. break;
  8266. }
  8267. case "validate": {
  8268. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  8269. var index = pendingExternalResources.length;
  8270. pendingExternalResources.push({ resolve: resolve, reject: reject });
  8271. postMessage({ id: "getExternalResource", index: index, uri: uri });
  8272. }); }).then(function (value) {
  8273. postMessage({ id: "validate.resolve", value: value });
  8274. }, function (reason) {
  8275. postMessage({ id: "validate.reject", reason: reason });
  8276. });
  8277. break;
  8278. }
  8279. case "getExternalResource.resolve": {
  8280. pendingExternalResources[data.index].resolve(data.value);
  8281. break;
  8282. }
  8283. case "getExternalResource.reject": {
  8284. pendingExternalResources[data.index].reject(data.reason);
  8285. break;
  8286. }
  8287. }
  8288. };
  8289. }
  8290. /**
  8291. * glTF validation
  8292. */
  8293. var GLTFValidation = /** @class */ (function () {
  8294. function GLTFValidation() {
  8295. }
  8296. /**
  8297. * Validate a glTF asset using the glTF-Validator.
  8298. * @param data The JSON of a glTF or the array buffer of a binary glTF
  8299. * @param rootUrl The root url for the glTF
  8300. * @param fileName The file name for the glTF
  8301. * @param getExternalResource The callback to get external resources for the glTF validator
  8302. * @returns A promise that resolves with the glTF validation results once complete
  8303. */
  8304. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  8305. var _this = this;
  8306. if (typeof Worker === "function") {
  8307. return new Promise(function (resolve, reject) {
  8308. var workerContent = validateAsync + "(" + workerFunc + ")()";
  8309. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  8310. var worker = new Worker(workerBlobUrl);
  8311. var onError = function (error) {
  8312. worker.removeEventListener("error", onError);
  8313. worker.removeEventListener("message", onMessage);
  8314. reject(error);
  8315. };
  8316. var onMessage = function (message) {
  8317. var data = message.data;
  8318. switch (data.id) {
  8319. case "getExternalResource": {
  8320. getExternalResource(data.uri).then(function (value) {
  8321. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  8322. }, function (reason) {
  8323. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  8324. });
  8325. break;
  8326. }
  8327. case "validate.resolve": {
  8328. worker.removeEventListener("error", onError);
  8329. worker.removeEventListener("message", onMessage);
  8330. resolve(data.value);
  8331. break;
  8332. }
  8333. case "validate.reject": {
  8334. worker.removeEventListener("error", onError);
  8335. worker.removeEventListener("message", onMessage);
  8336. reject(data.reason);
  8337. }
  8338. }
  8339. };
  8340. worker.addEventListener("error", onError);
  8341. worker.addEventListener("message", onMessage);
  8342. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  8343. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  8344. });
  8345. }
  8346. else {
  8347. if (!this._LoadScriptPromise) {
  8348. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  8349. }
  8350. return this._LoadScriptPromise.then(function () {
  8351. return validateAsync(data, rootUrl, fileName, getExternalResource);
  8352. });
  8353. }
  8354. };
  8355. /**
  8356. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  8357. */
  8358. GLTFValidation.Configuration = {
  8359. url: "https://preview.babylonjs.com/gltf_validator.js"
  8360. };
  8361. return GLTFValidation;
  8362. }());
  8363. /***/ }),
  8364. /***/ "./glTF/index.ts":
  8365. /*!***********************!*\
  8366. !*** ./glTF/index.ts ***!
  8367. \***********************/
  8368. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  8369. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8370. "use strict";
  8371. __webpack_require__.r(__webpack_exports__);
  8372. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8373. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8374. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8375. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8376. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8377. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8378. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8379. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  8380. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  8381. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  8382. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  8383. /***/ }),
  8384. /***/ "./index.ts":
  8385. /*!******************!*\
  8386. !*** ./index.ts ***!
  8387. \******************/
  8388. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8389. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8390. "use strict";
  8391. __webpack_require__.r(__webpack_exports__);
  8392. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  8393. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8394. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8395. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8396. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8397. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  8398. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  8399. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  8400. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  8401. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  8402. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  8403. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  8404. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  8405. /***/ }),
  8406. /***/ "./legacy/legacy-glTF.ts":
  8407. /*!*******************************!*\
  8408. !*** ./legacy/legacy-glTF.ts ***!
  8409. \*******************************/
  8410. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  8411. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8412. "use strict";
  8413. __webpack_require__.r(__webpack_exports__);
  8414. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8415. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  8416. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8417. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8418. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8419. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8420. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8421. /**
  8422. * This is the entry point for the UMD module.
  8423. * The entry point for a future ESM package should be index.ts
  8424. */
  8425. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8426. if (typeof globalObject !== "undefined") {
  8427. globalObject.BABYLON = globalObject.BABYLON || {};
  8428. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  8429. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  8430. }
  8431. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  8432. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  8433. }
  8434. }
  8435. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8436. /***/ }),
  8437. /***/ "./legacy/legacy-glTF1.ts":
  8438. /*!********************************!*\
  8439. !*** ./legacy/legacy-glTF1.ts ***!
  8440. \********************************/
  8441. /*! exports provided: GLTF1 */
  8442. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8443. "use strict";
  8444. __webpack_require__.r(__webpack_exports__);
  8445. /* 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");
  8446. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  8447. /**
  8448. * This is the entry point for the UMD module.
  8449. * The entry point for a future ESM package should be index.ts
  8450. */
  8451. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8452. if (typeof globalObject !== "undefined") {
  8453. globalObject.BABYLON = globalObject.BABYLON || {};
  8454. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  8455. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  8456. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  8457. }
  8458. }
  8459. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8460. /***/ }),
  8461. /***/ "./legacy/legacy-glTF2.ts":
  8462. /*!********************************!*\
  8463. !*** ./legacy/legacy-glTF2.ts ***!
  8464. \********************************/
  8465. /*! exports provided: GLTF2 */
  8466. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8467. "use strict";
  8468. __webpack_require__.r(__webpack_exports__);
  8469. /* 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");
  8470. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8471. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  8472. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  8473. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  8474. /**
  8475. * This is the entry point for the UMD module.
  8476. * The entry point for a future ESM package should be index.ts
  8477. */
  8478. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8479. if (typeof globalObject !== "undefined") {
  8480. globalObject.BABYLON = globalObject.BABYLON || {};
  8481. var BABYLON = globalObject.BABYLON;
  8482. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  8483. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  8484. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  8485. var keys = [];
  8486. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  8487. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  8488. keys.push(key);
  8489. }
  8490. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  8491. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  8492. keys.push(key);
  8493. }
  8494. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  8495. // Prevent Reassignment.
  8496. if (keys.indexOf(key) > -1) {
  8497. continue;
  8498. }
  8499. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  8500. }
  8501. }
  8502. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8503. /***/ }),
  8504. /***/ "./legacy/legacy-objFileLoader.ts":
  8505. /*!****************************************!*\
  8506. !*** ./legacy/legacy-objFileLoader.ts ***!
  8507. \****************************************/
  8508. /*! exports provided: MTLFileLoader, OBJFileLoader */
  8509. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8510. "use strict";
  8511. __webpack_require__.r(__webpack_exports__);
  8512. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  8513. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  8514. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  8515. /**
  8516. * This is the entry point for the UMD module.
  8517. * The entry point for a future ESM package should be index.ts
  8518. */
  8519. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8520. if (typeof globalObject !== "undefined") {
  8521. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  8522. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  8523. }
  8524. }
  8525. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8526. /***/ }),
  8527. /***/ "./legacy/legacy-stlFileLoader.ts":
  8528. /*!****************************************!*\
  8529. !*** ./legacy/legacy-stlFileLoader.ts ***!
  8530. \****************************************/
  8531. /*! exports provided: STLFileLoader */
  8532. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8533. "use strict";
  8534. __webpack_require__.r(__webpack_exports__);
  8535. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  8536. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  8537. /**
  8538. * This is the entry point for the UMD module.
  8539. * The entry point for a future ESM package should be index.ts
  8540. */
  8541. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8542. if (typeof globalObject !== "undefined") {
  8543. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  8544. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  8545. }
  8546. }
  8547. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8548. /***/ }),
  8549. /***/ "./legacy/legacy.ts":
  8550. /*!**************************!*\
  8551. !*** ./legacy/legacy.ts ***!
  8552. \**************************/
  8553. /*! exports provided: GLTF1, GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8554. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8555. "use strict";
  8556. __webpack_require__.r(__webpack_exports__);
  8557. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  8558. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  8559. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  8560. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  8561. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  8562. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  8563. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8564. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  8565. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  8566. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  8567. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  8568. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  8569. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  8570. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  8571. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  8572. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  8573. /***/ }),
  8574. /***/ "babylonjs/Misc/tools":
  8575. /*!****************************************************************************************************!*\
  8576. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  8577. \****************************************************************************************************/
  8578. /*! no static exports found */
  8579. /***/ (function(module, exports) {
  8580. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  8581. /***/ })
  8582. /******/ });
  8583. });
  8584. //# sourceMappingURL=babylonjs.loaders.js.map