babylonjs.loaders.js 450 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** C:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./OBJ/index.ts":
  324. /*!**********************!*\
  325. !*** ./OBJ/index.ts ***!
  326. \**********************/
  327. /*! exports provided: MTLFileLoader, OBJFileLoader */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  333. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  335. /***/ }),
  336. /***/ "./OBJ/mtlFileLoader.ts":
  337. /*!******************************!*\
  338. !*** ./OBJ/mtlFileLoader.ts ***!
  339. \******************************/
  340. /*! exports provided: MTLFileLoader */
  341. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  342. "use strict";
  343. __webpack_require__.r(__webpack_exports__);
  344. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  345. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  346. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  347. /**
  348. * Class reading and parsing the MTL file bundled with the obj file.
  349. */
  350. var MTLFileLoader = /** @class */ (function () {
  351. function MTLFileLoader() {
  352. /**
  353. * All material loaded from the mtl will be set here
  354. */
  355. this.materials = [];
  356. }
  357. /**
  358. * This function will read the mtl file and create each material described inside
  359. * This function could be improve by adding :
  360. * -some component missing (Ni, Tf...)
  361. * -including the specific options available
  362. *
  363. * @param scene defines the scene the material will be created in
  364. * @param data defines the mtl data to parse
  365. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  366. */
  367. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl) {
  368. if (data instanceof ArrayBuffer) {
  369. return;
  370. }
  371. //Split the lines from the file
  372. var lines = data.split('\n');
  373. //Space char
  374. var delimiter_pattern = /\s+/;
  375. //Array with RGB colors
  376. var color;
  377. //New material
  378. var material = null;
  379. //Look at each line
  380. for (var i = 0; i < lines.length; i++) {
  381. var line = lines[i].trim();
  382. // Blank line or comment
  383. if (line.length === 0 || line.charAt(0) === '#') {
  384. continue;
  385. }
  386. //Get the first parameter (keyword)
  387. var pos = line.indexOf(' ');
  388. var key = (pos >= 0) ? line.substring(0, pos) : line;
  389. key = key.toLowerCase();
  390. //Get the data following the key
  391. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  392. //This mtl keyword will create the new material
  393. if (key === "newmtl") {
  394. //Check if it is the first material.
  395. // Materials specifications are described after this keyword.
  396. if (material) {
  397. //Add the previous material in the material array.
  398. this.materials.push(material);
  399. }
  400. //Create a new material.
  401. // value is the name of the material read in the mtl file
  402. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"](value, scene);
  403. }
  404. else if (key === "kd" && material) {
  405. // Diffuse color (color under white light) using RGB values
  406. //value = "r g b"
  407. color = value.split(delimiter_pattern, 3).map(parseFloat);
  408. //color = [r,g,b]
  409. //Set tghe color into the material
  410. material.diffuseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  411. }
  412. else if (key === "ka" && material) {
  413. // Ambient color (color under shadow) using RGB values
  414. //value = "r g b"
  415. color = value.split(delimiter_pattern, 3).map(parseFloat);
  416. //color = [r,g,b]
  417. //Set tghe color into the material
  418. material.ambientColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  419. }
  420. else if (key === "ks" && material) {
  421. // Specular color (color when light is reflected from shiny surface) using RGB values
  422. //value = "r g b"
  423. color = value.split(delimiter_pattern, 3).map(parseFloat);
  424. //color = [r,g,b]
  425. //Set the color into the material
  426. material.specularColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  427. }
  428. else if (key === "ke" && material) {
  429. // Emissive color using RGB values
  430. color = value.split(delimiter_pattern, 3).map(parseFloat);
  431. material.emissiveColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  432. }
  433. else if (key === "ns" && material) {
  434. //value = "Integer"
  435. material.specularPower = parseFloat(value);
  436. }
  437. else if (key === "d" && material) {
  438. //d is dissolve for current material. It mean alpha for BABYLON
  439. material.alpha = parseFloat(value);
  440. //Texture
  441. //This part can be improved by adding the possible options of texture
  442. }
  443. else if (key === "map_ka" && material) {
  444. // ambient texture map with a loaded image
  445. //We must first get the folder of the image
  446. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  447. }
  448. else if (key === "map_kd" && material) {
  449. // Diffuse texture map with a loaded image
  450. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  451. }
  452. else if (key === "map_ks" && material) {
  453. // Specular texture map with a loaded image
  454. //We must first get the folder of the image
  455. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  456. }
  457. else if (key === "map_ns") {
  458. //Specular
  459. //Specular highlight component
  460. //We must first get the folder of the image
  461. //
  462. //Not supported by BABYLON
  463. //
  464. // continue;
  465. }
  466. else if (key === "map_bump" && material) {
  467. //The bump texture
  468. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  469. }
  470. else if (key === "map_d" && material) {
  471. // The dissolve of the material
  472. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  473. //Options for illumination
  474. }
  475. else if (key === "illum") {
  476. //Illumination
  477. if (value === "0") {
  478. //That mean Kd == Kd
  479. }
  480. else if (value === "1") {
  481. //Color on and Ambient on
  482. }
  483. else if (value === "2") {
  484. //Highlight on
  485. }
  486. else if (value === "3") {
  487. //Reflection on and Ray trace on
  488. }
  489. else if (value === "4") {
  490. //Transparency: Glass on, Reflection: Ray trace on
  491. }
  492. else if (value === "5") {
  493. //Reflection: Fresnel on and Ray trace on
  494. }
  495. else if (value === "6") {
  496. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  497. }
  498. else if (value === "7") {
  499. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  500. }
  501. else if (value === "8") {
  502. //Reflection on and Ray trace off
  503. }
  504. else if (value === "9") {
  505. //Transparency: Glass on, Reflection: Ray trace off
  506. }
  507. else if (value === "10") {
  508. //Casts shadows onto invisible surfaces
  509. }
  510. }
  511. else {
  512. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  513. }
  514. }
  515. //At the end of the file, add the last material
  516. if (material) {
  517. this.materials.push(material);
  518. }
  519. };
  520. /**
  521. * Gets the texture for the material.
  522. *
  523. * If the material is imported from input file,
  524. * We sanitize the url to ensure it takes the textre from aside the material.
  525. *
  526. * @param rootUrl The root url to load from
  527. * @param value The value stored in the mtl
  528. * @return The Texture
  529. */
  530. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  531. if (!value) {
  532. return null;
  533. }
  534. var url = rootUrl;
  535. // Load from input file.
  536. if (rootUrl === "file:") {
  537. var lastDelimiter = value.lastIndexOf("\\");
  538. if (lastDelimiter === -1) {
  539. lastDelimiter = value.lastIndexOf("/");
  540. }
  541. if (lastDelimiter > -1) {
  542. url += value.substr(lastDelimiter + 1);
  543. }
  544. else {
  545. url += value;
  546. }
  547. }
  548. // Not from input file.
  549. else {
  550. url += value;
  551. }
  552. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
  553. };
  554. /**
  555. * Invert Y-Axis of referenced textures on load
  556. */
  557. MTLFileLoader.INVERT_TEXTURE_Y = true;
  558. return MTLFileLoader;
  559. }());
  560. /***/ }),
  561. /***/ "./OBJ/objFileLoader.ts":
  562. /*!******************************!*\
  563. !*** ./OBJ/objFileLoader.ts ***!
  564. \******************************/
  565. /*! exports provided: OBJFileLoader */
  566. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  567. "use strict";
  568. __webpack_require__.r(__webpack_exports__);
  569. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  570. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  571. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  572. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  573. /**
  574. * OBJ file type loader.
  575. * This is a babylon scene loader plugin.
  576. */
  577. var OBJFileLoader = /** @class */ (function () {
  578. /**
  579. * Creates loader for .OBJ files
  580. *
  581. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  582. */
  583. function OBJFileLoader(meshLoadOptions) {
  584. /**
  585. * Defines the name of the plugin.
  586. */
  587. this.name = "obj";
  588. /**
  589. * Defines the extension the plugin is able to load.
  590. */
  591. this.extensions = ".obj";
  592. /** @hidden */
  593. this.obj = /^o/;
  594. /** @hidden */
  595. this.group = /^g/;
  596. /** @hidden */
  597. this.mtllib = /^mtllib /;
  598. /** @hidden */
  599. this.usemtl = /^usemtl /;
  600. /** @hidden */
  601. this.smooth = /^s /;
  602. /** @hidden */
  603. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+){3,7}/;
  604. // vn float float float
  605. /** @hidden */
  606. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  607. // vt float float
  608. /** @hidden */
  609. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  610. // f vertex vertex vertex ...
  611. /** @hidden */
  612. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  613. // f vertex/uvs vertex/uvs vertex/uvs ...
  614. /** @hidden */
  615. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  616. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  617. /** @hidden */
  618. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  619. // f vertex//normal vertex//normal vertex//normal ...
  620. /** @hidden */
  621. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  622. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  623. /** @hidden */
  624. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  625. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  626. }
  627. Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
  628. /**
  629. * Invert Y-Axis of referenced textures on load
  630. */
  631. get: function () {
  632. return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y;
  633. },
  634. set: function (value) {
  635. _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y = value;
  636. },
  637. enumerable: true,
  638. configurable: true
  639. });
  640. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  641. get: function () {
  642. return {
  643. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  644. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  645. InvertY: OBJFileLoader.INVERT_Y,
  646. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  647. UVScaling: OBJFileLoader.UV_SCALING,
  648. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  649. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  650. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  651. };
  652. },
  653. enumerable: true,
  654. configurable: true
  655. });
  656. /**
  657. * Calls synchronously the MTL file attached to this obj.
  658. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  659. * Without this function materials are not displayed in the first frame (but displayed after).
  660. * In consequence it is impossible to get material information in your HTML file
  661. *
  662. * @param url The URL of the MTL file
  663. * @param rootUrl
  664. * @param onSuccess Callback function to be called when the MTL file is loaded
  665. * @private
  666. */
  667. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  668. //The complete path to the mtl file
  669. var pathOfFile = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  670. // Loads through the babylon tools to allow fileInput search.
  671. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  672. onFailure(pathOfFile, exception);
  673. });
  674. };
  675. /**
  676. * Instantiates a OBJ file loader plugin.
  677. * @returns the created plugin
  678. */
  679. OBJFileLoader.prototype.createPlugin = function () {
  680. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  681. };
  682. /**
  683. * If the data string can be loaded directly.
  684. *
  685. * @param data string containing the file data
  686. * @returns if the data can be loaded directly
  687. */
  688. OBJFileLoader.prototype.canDirectLoad = function (data) {
  689. return false;
  690. };
  691. /**
  692. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  693. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  694. * @param scene the scene the meshes should be added to
  695. * @param data the OBJ data to load
  696. * @param rootUrl root url to load from
  697. * @param onProgress event that fires when loading progress has occured
  698. * @param fileName Defines the name of the file to load
  699. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  700. */
  701. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  702. //get the meshes from OBJ file
  703. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  704. return {
  705. meshes: meshes,
  706. particleSystems: [],
  707. skeletons: [],
  708. animationGroups: []
  709. };
  710. });
  711. };
  712. /**
  713. * Imports all objects from the loaded OBJ data and adds them to the scene
  714. * @param scene the scene the objects should be added to
  715. * @param data the OBJ data to load
  716. * @param rootUrl root url to load from
  717. * @param onProgress event that fires when loading progress has occured
  718. * @param fileName Defines the name of the file to load
  719. * @returns a promise which completes when objects have been loaded to the scene
  720. */
  721. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  722. //Get the 3D model
  723. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  724. // return void
  725. });
  726. };
  727. /**
  728. * Load into an asset container.
  729. * @param scene The scene to load into
  730. * @param data The data to import
  731. * @param rootUrl The root url for scene and resources
  732. * @param onProgress The callback when the load progresses
  733. * @param fileName Defines the name of the file to load
  734. * @returns The loaded asset container
  735. */
  736. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  737. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  738. var container = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  739. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  740. result.meshes.forEach(function (mesh) {
  741. var material = mesh.material;
  742. if (material) {
  743. // Materials
  744. if (container.materials.indexOf(material) == -1) {
  745. container.materials.push(material);
  746. // Textures
  747. var textures = material.getActiveTextures();
  748. textures.forEach(function (t) {
  749. if (container.textures.indexOf(t) == -1) {
  750. container.textures.push(t);
  751. }
  752. });
  753. }
  754. }
  755. });
  756. container.removeAllFromScene();
  757. return container;
  758. });
  759. };
  760. /**
  761. * Read the OBJ file and create an Array of meshes.
  762. * Each mesh contains all information given by the OBJ and the MTL file.
  763. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  764. *
  765. * @param meshesNames
  766. * @param scene Scene The scene where are displayed the data
  767. * @param data String The content of the obj file
  768. * @param rootUrl String The path to the folder
  769. * @returns Array<AbstractMesh>
  770. * @private
  771. */
  772. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  773. var _this = this;
  774. var positions = []; //values for the positions of vertices
  775. var normals = []; //Values for the normals
  776. var uvs = []; //Values for the textures
  777. var colors = [];
  778. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  779. var handledMesh; //The current mesh of meshes array
  780. var indicesForBabylon = []; //The list of indices for VertexData
  781. var wrappedPositionForBabylon = []; //The list of position in vectors
  782. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  783. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  784. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  785. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  786. var curPositionInIndices = 0;
  787. var hasMeshes = false; //Meshes are defined in the file
  788. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  789. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  790. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  791. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  792. var triangles = []; //Indices from new triangles coming from polygons
  793. var materialNameFromObj = ""; //The name of the current material
  794. var fileToLoad = ""; //The name of the mtlFile to load
  795. var materialsFromMTLFile = new _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]();
  796. var objMeshName = ""; //The name of the current obj mesh
  797. var increment = 1; //Id for meshes created by the multimaterial
  798. var isFirstMaterial = true;
  799. var grayColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  800. /**
  801. * Search for obj in the given array.
  802. * This function is called to check if a couple of data already exists in an array.
  803. *
  804. * If found, returns the index of the founded tuple index. Returns -1 if not found
  805. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  806. * @param obj Array<number>
  807. * @returns {boolean}
  808. */
  809. var isInArray = function (arr, obj) {
  810. if (!arr[obj[0]]) {
  811. arr[obj[0]] = { normals: [], idx: [] };
  812. }
  813. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  814. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  815. };
  816. var isInArrayUV = function (arr, obj) {
  817. if (!arr[obj[0]]) {
  818. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  819. }
  820. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  821. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  822. return arr[obj[0]].idx[idx];
  823. }
  824. return -1;
  825. };
  826. /**
  827. * This function set the data for each triangle.
  828. * Data are position, normals and uvs
  829. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  830. * If the tuple already exist, add only their indice
  831. *
  832. * @param indicePositionFromObj Integer The index in positions array
  833. * @param indiceUvsFromObj Integer The index in uvs array
  834. * @param indiceNormalFromObj Integer The index in normals array
  835. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  836. * @param textureVectorFromOBJ Vector3 The value of uvs
  837. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  838. */
  839. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  840. //Check if this tuple already exists in the list of tuples
  841. var _index;
  842. if (_this._meshLoadOptions.OptimizeWithUV) {
  843. _index = isInArrayUV(tuplePosNorm, [
  844. indicePositionFromObj,
  845. indiceNormalFromObj,
  846. indiceUvsFromObj
  847. ]);
  848. }
  849. else {
  850. _index = isInArray(tuplePosNorm, [
  851. indicePositionFromObj,
  852. indiceNormalFromObj
  853. ]);
  854. }
  855. //If it not exists
  856. if (_index === -1) {
  857. //Add an new indice.
  858. //The array of indices is only an array with his length equal to the number of triangles - 1.
  859. //We add vertices data in this order
  860. indicesForBabylon.push(wrappedPositionForBabylon.length);
  861. //Push the position of vertice for Babylon
  862. //Each element is a Vector3(x,y,z)
  863. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  864. //Push the uvs for Babylon
  865. //Each element is a Vector3(u,v)
  866. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  867. //Push the normals for Babylon
  868. //Each element is a Vector3(x,y,z)
  869. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  870. if (positionColorsFromOBJ !== undefined) {
  871. //Push the colors for Babylon
  872. //Each element is a BABYLON.Color4(r,g,b,a)
  873. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  874. }
  875. //Add the tuple in the comparison list
  876. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  877. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  878. if (_this._meshLoadOptions.OptimizeWithUV) {
  879. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  880. }
  881. }
  882. else {
  883. //The tuple already exists
  884. //Add the index of the already existing tuple
  885. //At this index we can get the value of position, normal, color and uvs of vertex
  886. indicesForBabylon.push(_index);
  887. }
  888. };
  889. /**
  890. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  891. */
  892. var unwrapData = function () {
  893. //Every array has the same length
  894. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  895. //Push the x, y, z values of each element in the unwrapped array
  896. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  897. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  898. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  899. }
  900. if (_this._meshLoadOptions.ImportVertexColors === true) {
  901. //Push the r, g, b, a values of each element in the unwrapped array
  902. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  903. }
  904. // Reset arrays for the next new meshes
  905. wrappedPositionForBabylon = [];
  906. wrappedNormalsForBabylon = [];
  907. wrappedUvsForBabylon = [];
  908. wrappedColorsForBabylon = [];
  909. tuplePosNorm = [];
  910. curPositionInIndices = 0;
  911. };
  912. /**
  913. * Create triangles from polygons
  914. * It is important to notice that a triangle is a polygon
  915. * We get 5 patterns of face defined in OBJ File :
  916. * facePattern1 = ["1","2","3","4","5","6"]
  917. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  918. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  919. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  920. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  921. * Each pattern is divided by the same method
  922. * @param face Array[String] The indices of elements
  923. * @param v Integer The variable to increment
  924. */
  925. var getTriangles = function (faces, v) {
  926. //Work for each element of the array
  927. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  928. //Add on the triangle variable the indexes to obtain triangles
  929. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  930. }
  931. //Result obtained after 2 iterations:
  932. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  933. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  934. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  935. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  936. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  937. };
  938. /**
  939. * Create triangles and push the data for each polygon for the pattern 1
  940. * In this pattern we get vertice positions
  941. * @param face
  942. * @param v
  943. */
  944. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  945. //Get the indices of triangles for each polygon
  946. getTriangles(face, v);
  947. //For each element in the triangles array.
  948. //This var could contains 1 to an infinity of triangles
  949. for (var k = 0; k < triangles.length; k++) {
  950. // Set position indice
  951. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  952. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  953. positions[indicePositionFromObj], //Get the vectors data
  954. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  955. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  956. }
  957. //Reset variable for the next line
  958. triangles = [];
  959. };
  960. /**
  961. * Create triangles and push the data for each polygon for the pattern 2
  962. * In this pattern we get vertice positions and uvsu
  963. * @param face
  964. * @param v
  965. */
  966. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  967. //Get the indices of triangles for each polygon
  968. getTriangles(face, v);
  969. for (var k = 0; k < triangles.length; k++) {
  970. //triangle[k] = "1/1"
  971. //Split the data for getting position and uv
  972. var point = triangles[k].split("/"); // ["1", "1"]
  973. //Set position indice
  974. var indicePositionFromObj = parseInt(point[0]) - 1;
  975. //Set uv indice
  976. var indiceUvsFromObj = parseInt(point[1]) - 1;
  977. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  978. positions[indicePositionFromObj], //Get the values for each element
  979. uvs[indiceUvsFromObj], babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  980. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  981. }
  982. //Reset variable for the next line
  983. triangles = [];
  984. };
  985. /**
  986. * Create triangles and push the data for each polygon for the pattern 3
  987. * In this pattern we get vertice positions, uvs and normals
  988. * @param face
  989. * @param v
  990. */
  991. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  992. //Get the indices of triangles for each polygon
  993. getTriangles(face, v);
  994. for (var k = 0; k < triangles.length; k++) {
  995. //triangle[k] = "1/1/1"
  996. //Split the data for getting position, uv, and normals
  997. var point = triangles[k].split("/"); // ["1", "1", "1"]
  998. // Set position indice
  999. var indicePositionFromObj = parseInt(point[0]) - 1;
  1000. // Set uv indice
  1001. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1002. // Set normal indice
  1003. var indiceNormalFromObj = parseInt(point[2]) - 1;
  1004. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  1005. );
  1006. }
  1007. //Reset variable for the next line
  1008. triangles = [];
  1009. };
  1010. /**
  1011. * Create triangles and push the data for each polygon for the pattern 4
  1012. * In this pattern we get vertice positions and normals
  1013. * @param face
  1014. * @param v
  1015. */
  1016. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  1017. getTriangles(face, v);
  1018. for (var k = 0; k < triangles.length; k++) {
  1019. //triangle[k] = "1//1"
  1020. //Split the data for getting position and normals
  1021. var point = triangles[k].split("//"); // ["1", "1"]
  1022. // We check indices, and normals
  1023. var indicePositionFromObj = parseInt(point[0]) - 1;
  1024. var indiceNormalFromObj = parseInt(point[1]) - 1;
  1025. setData(indicePositionFromObj, 1, //Default value for uv
  1026. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  1027. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1028. }
  1029. //Reset variable for the next line
  1030. triangles = [];
  1031. };
  1032. /**
  1033. * Create triangles and push the data for each polygon for the pattern 3
  1034. * In this pattern we get vertice positions, uvs and normals
  1035. * @param face
  1036. * @param v
  1037. */
  1038. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1039. //Get the indices of triangles for each polygon
  1040. getTriangles(face, v);
  1041. for (var k = 0; k < triangles.length; k++) {
  1042. //triangle[k] = "-1/-1/-1"
  1043. //Split the data for getting position, uv, and normals
  1044. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1045. // Set position indice
  1046. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1047. // Set uv indice
  1048. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1049. // Set normal indice
  1050. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1051. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1052. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1053. }
  1054. //Reset variable for the next line
  1055. triangles = [];
  1056. };
  1057. var addPreviousObjMesh = function () {
  1058. //Check if it is not the first mesh. Otherwise we don't have data.
  1059. if (meshesFromObj.length > 0) {
  1060. //Get the previous mesh for applying the data about the faces
  1061. //=> in obj file, faces definition append after the name of the mesh
  1062. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1063. //Set the data into Array for the mesh
  1064. unwrapData();
  1065. // Reverse tab. Otherwise face are displayed in the wrong sens
  1066. indicesForBabylon.reverse();
  1067. //Set the information for the mesh
  1068. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1069. handledMesh.indices = indicesForBabylon.slice();
  1070. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1071. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1072. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1073. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1074. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1075. }
  1076. //Reset the array for the next mesh
  1077. indicesForBabylon = [];
  1078. unwrappedPositionsForBabylon = [];
  1079. unwrappedColorsForBabylon = [];
  1080. unwrappedNormalsForBabylon = [];
  1081. unwrappedUVForBabylon = [];
  1082. }
  1083. };
  1084. //Main function
  1085. //Split the file into lines
  1086. var lines = data.split('\n');
  1087. //Look at each line
  1088. for (var i = 0; i < lines.length; i++) {
  1089. var line = lines[i].trim().replace(/\s\s/g, " ");
  1090. var result;
  1091. //Comment or newLine
  1092. if (line.length === 0 || line.charAt(0) === '#') {
  1093. continue;
  1094. //Get information about one position possible for the vertices
  1095. }
  1096. else if (this.vertexPattern.test(line)) {
  1097. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1098. // Value of result with line: "v 1.0 2.0 3.0"
  1099. // ["v", "1.0", "2.0", "3.0"]
  1100. // Create a Vector3 with the position x, y, z
  1101. positions.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1102. if (this._meshLoadOptions.ImportVertexColors === true) {
  1103. if (result.length >= 7) {
  1104. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1105. colors.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color4"](parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
  1106. }
  1107. else {
  1108. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1109. colors.push(grayColor);
  1110. }
  1111. }
  1112. }
  1113. else if ((result = this.normalPattern.exec(line)) !== null) {
  1114. //Create a Vector3 with the normals x, y, z
  1115. //Value of result
  1116. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1117. //Add the Vector in the list of normals
  1118. normals.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1119. }
  1120. else if ((result = this.uvPattern.exec(line)) !== null) {
  1121. //Create a Vector2 with the normals u, v
  1122. //Value of result
  1123. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1124. //Add the Vector in the list of uvs
  1125. uvs.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
  1126. //Identify patterns of faces
  1127. //Face could be defined in different type of pattern
  1128. }
  1129. else if ((result = this.facePattern3.exec(line)) !== null) {
  1130. //Value of result:
  1131. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1132. //Set the data for this face
  1133. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1134. 1);
  1135. }
  1136. else if ((result = this.facePattern4.exec(line)) !== null) {
  1137. //Value of result:
  1138. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1139. //Set the data for this face
  1140. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1141. 1);
  1142. }
  1143. else if ((result = this.facePattern5.exec(line)) !== null) {
  1144. //Value of result:
  1145. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1146. //Set the data for this face
  1147. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1148. 1);
  1149. }
  1150. else if ((result = this.facePattern2.exec(line)) !== null) {
  1151. //Value of result:
  1152. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1153. //Set the data for this face
  1154. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1155. 1);
  1156. }
  1157. else if ((result = this.facePattern1.exec(line)) !== null) {
  1158. //Value of result
  1159. //["f 1 2 3", "1 2 3"...]
  1160. //Set the data for this face
  1161. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1162. 1);
  1163. //Define a mesh or an object
  1164. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1165. }
  1166. else if (this.group.test(line) || this.obj.test(line)) {
  1167. //Create a new mesh corresponding to the name of the group.
  1168. //Definition of the mesh
  1169. var objMesh = {
  1170. name: line.substring(2).trim(),
  1171. indices: undefined,
  1172. positions: undefined,
  1173. normals: undefined,
  1174. uvs: undefined,
  1175. colors: undefined,
  1176. materialName: ""
  1177. };
  1178. addPreviousObjMesh();
  1179. //Push the last mesh created with only the name
  1180. meshesFromObj.push(objMesh);
  1181. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1182. hasMeshes = true;
  1183. isFirstMaterial = true;
  1184. increment = 1;
  1185. //Keyword for applying a material
  1186. }
  1187. else if (this.usemtl.test(line)) {
  1188. //Get the name of the material
  1189. materialNameFromObj = line.substring(7).trim();
  1190. //If this new material is in the same mesh
  1191. if (!isFirstMaterial) {
  1192. //Set the data for the previous mesh
  1193. addPreviousObjMesh();
  1194. //Create a new mesh
  1195. var objMesh =
  1196. //Set the name of the current obj mesh
  1197. {
  1198. name: objMeshName + "_mm" + increment.toString(),
  1199. indices: undefined,
  1200. positions: undefined,
  1201. normals: undefined,
  1202. uvs: undefined,
  1203. colors: undefined,
  1204. materialName: materialNameFromObj
  1205. };
  1206. increment++;
  1207. //If meshes are already defined
  1208. meshesFromObj.push(objMesh);
  1209. }
  1210. //Set the material name if the previous line define a mesh
  1211. if (hasMeshes && isFirstMaterial) {
  1212. //Set the material name to the previous mesh (1 material per mesh)
  1213. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1214. isFirstMaterial = false;
  1215. }
  1216. //Keyword for loading the mtl file
  1217. }
  1218. else if (this.mtllib.test(line)) {
  1219. //Get the name of mtl file
  1220. fileToLoad = line.substring(7).trim();
  1221. //Apply smoothing
  1222. }
  1223. else if (this.smooth.test(line)) {
  1224. // smooth shading => apply smoothing
  1225. //Today I don't know it work with babylon and with obj.
  1226. //With the obj file an integer is set
  1227. }
  1228. else {
  1229. //If there is another possibility
  1230. console.log("Unhandled expression at line : " + line);
  1231. }
  1232. }
  1233. //At the end of the file, add the last mesh into the meshesFromObj array
  1234. if (hasMeshes) {
  1235. //Set the data for the last mesh
  1236. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1237. //Reverse indices for displaying faces in the good sense
  1238. indicesForBabylon.reverse();
  1239. //Get the good array
  1240. unwrapData();
  1241. //Set array
  1242. handledMesh.indices = indicesForBabylon;
  1243. handledMesh.positions = unwrappedPositionsForBabylon;
  1244. handledMesh.normals = unwrappedNormalsForBabylon;
  1245. handledMesh.uvs = unwrappedUVForBabylon;
  1246. if (this._meshLoadOptions.ImportVertexColors === true) {
  1247. handledMesh.colors = unwrappedColorsForBabylon;
  1248. }
  1249. }
  1250. //If any o or g keyword found, create a mesh with a random id
  1251. if (!hasMeshes) {
  1252. // reverse tab of indices
  1253. indicesForBabylon.reverse();
  1254. //Get positions normals uvs
  1255. unwrapData();
  1256. //Set data for one mesh
  1257. meshesFromObj.push({
  1258. name: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1259. indices: indicesForBabylon,
  1260. positions: unwrappedPositionsForBabylon,
  1261. colors: unwrappedColorsForBabylon,
  1262. normals: unwrappedNormalsForBabylon,
  1263. uvs: unwrappedUVForBabylon,
  1264. materialName: materialNameFromObj
  1265. });
  1266. }
  1267. //Create a Mesh list
  1268. var babylonMeshesArray = []; //The mesh for babylon
  1269. var materialToUse = new Array();
  1270. //Set data for each mesh
  1271. for (var j = 0; j < meshesFromObj.length; j++) {
  1272. //check meshesNames (stlFileLoader)
  1273. if (meshesNames && meshesFromObj[j].name) {
  1274. if (meshesNames instanceof Array) {
  1275. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1276. continue;
  1277. }
  1278. }
  1279. else {
  1280. if (meshesFromObj[j].name !== meshesNames) {
  1281. continue;
  1282. }
  1283. }
  1284. }
  1285. //Get the current mesh
  1286. //Set the data with VertexBuffer for each mesh
  1287. handledMesh = meshesFromObj[j];
  1288. //Create a Mesh with the name of the obj mesh
  1289. var babylonMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1290. //Push the name of the material to an array
  1291. //This is indispensable for the importMesh function
  1292. materialToUse.push(meshesFromObj[j].materialName);
  1293. var vertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1294. //Set the data for the babylonMesh
  1295. vertexData.uvs = handledMesh.uvs;
  1296. vertexData.indices = handledMesh.indices;
  1297. vertexData.positions = handledMesh.positions;
  1298. if (this._meshLoadOptions.ComputeNormals === true) {
  1299. var normals_1 = new Array();
  1300. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1301. vertexData.normals = normals_1;
  1302. }
  1303. else {
  1304. vertexData.normals = handledMesh.normals;
  1305. }
  1306. if (this._meshLoadOptions.ImportVertexColors === true) {
  1307. vertexData.colors = handledMesh.colors;
  1308. }
  1309. //Set the data from the VertexBuffer to the current Mesh
  1310. vertexData.applyToMesh(babylonMesh);
  1311. if (this._meshLoadOptions.InvertY) {
  1312. babylonMesh.scaling.y *= -1;
  1313. }
  1314. //Push the mesh into an array
  1315. babylonMeshesArray.push(babylonMesh);
  1316. }
  1317. var mtlPromises = [];
  1318. //load the materials
  1319. //Check if we have a file to load
  1320. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1321. //Load the file synchronously
  1322. mtlPromises.push(new Promise(function (resolve, reject) {
  1323. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1324. try {
  1325. //Create materials thanks MTLLoader function
  1326. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl);
  1327. //Look at each material loaded in the mtl file
  1328. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1329. //Three variables to get all meshes with the same material
  1330. var startIndex = 0;
  1331. var _indices = [];
  1332. var _index;
  1333. //The material from MTL file is used in the meshes loaded
  1334. //Push the indice in an array
  1335. //Check if the material is not used for another mesh
  1336. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1337. _indices.push(_index);
  1338. startIndex = _index + 1;
  1339. }
  1340. //If the material is not used dispose it
  1341. if (_index === -1 && _indices.length === 0) {
  1342. //If the material is not needed, remove it
  1343. materialsFromMTLFile.materials[n].dispose();
  1344. }
  1345. else {
  1346. for (var o = 0; o < _indices.length; o++) {
  1347. //Apply the material to the Mesh for each mesh with the material
  1348. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1349. }
  1350. }
  1351. }
  1352. resolve();
  1353. }
  1354. catch (e) {
  1355. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1356. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1357. resolve();
  1358. }
  1359. else {
  1360. reject(e);
  1361. }
  1362. }
  1363. }, function (pathOfFile, exception) {
  1364. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1365. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1366. resolve();
  1367. }
  1368. else {
  1369. reject(exception);
  1370. }
  1371. });
  1372. }));
  1373. }
  1374. //Return an array with all Mesh
  1375. return Promise.all(mtlPromises).then(function () {
  1376. return babylonMeshesArray;
  1377. });
  1378. };
  1379. /**
  1380. * Defines if UVs are optimized by default during load.
  1381. */
  1382. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1383. /**
  1384. * Invert model on y-axis (does a model scaling inversion)
  1385. */
  1386. OBJFileLoader.INVERT_Y = false;
  1387. /**
  1388. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1389. */
  1390. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1391. /**
  1392. * Compute the normals for the model, even if normals are present in the file.
  1393. */
  1394. OBJFileLoader.COMPUTE_NORMALS = false;
  1395. /**
  1396. * Defines custom scaling of UV coordinates of loaded meshes.
  1397. */
  1398. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1399. /**
  1400. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1401. */
  1402. OBJFileLoader.SKIP_MATERIALS = false;
  1403. /**
  1404. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1405. *
  1406. * Defaults to true for backwards compatibility.
  1407. */
  1408. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1409. return OBJFileLoader;
  1410. }());
  1411. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1412. //Add this loader into the register plugin
  1413. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1414. }
  1415. /***/ }),
  1416. /***/ "./STL/index.ts":
  1417. /*!**********************!*\
  1418. !*** ./STL/index.ts ***!
  1419. \**********************/
  1420. /*! exports provided: STLFileLoader */
  1421. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1422. "use strict";
  1423. __webpack_require__.r(__webpack_exports__);
  1424. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1425. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1426. /***/ }),
  1427. /***/ "./STL/stlFileLoader.ts":
  1428. /*!******************************!*\
  1429. !*** ./STL/stlFileLoader.ts ***!
  1430. \******************************/
  1431. /*! exports provided: STLFileLoader */
  1432. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1433. "use strict";
  1434. __webpack_require__.r(__webpack_exports__);
  1435. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1436. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  1437. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1438. /**
  1439. * STL file type loader.
  1440. * This is a babylon scene loader plugin.
  1441. */
  1442. var STLFileLoader = /** @class */ (function () {
  1443. function STLFileLoader() {
  1444. /** @hidden */
  1445. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  1446. /** @hidden */
  1447. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1448. /** @hidden */
  1449. 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;
  1450. /** @hidden */
  1451. 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;
  1452. /**
  1453. * Defines the name of the plugin.
  1454. */
  1455. this.name = "stl";
  1456. /**
  1457. * Defines the extensions the stl loader is able to load.
  1458. * force data to come in as an ArrayBuffer
  1459. * we'll convert to string if it looks like it's an ASCII .stl
  1460. */
  1461. this.extensions = {
  1462. ".stl": { isBinary: true },
  1463. };
  1464. }
  1465. /**
  1466. * Import meshes into a scene.
  1467. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1468. * @param scene The scene to import into
  1469. * @param data The data to import
  1470. * @param rootUrl The root url for scene and resources
  1471. * @param meshes The meshes array to import into
  1472. * @param particleSystems The particle systems array to import into
  1473. * @param skeletons The skeletons array to import into
  1474. * @param onError The callback when import fails
  1475. * @returns True if successful or false otherwise
  1476. */
  1477. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1478. var matches;
  1479. if (typeof data !== "string") {
  1480. if (this._isBinary(data)) {
  1481. // binary .stl
  1482. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1483. this._parseBinary(babylonMesh, data);
  1484. if (meshes) {
  1485. meshes.push(babylonMesh);
  1486. }
  1487. return true;
  1488. }
  1489. // ASCII .stl
  1490. // convert to string
  1491. var array_buffer = new Uint8Array(data);
  1492. var str = '';
  1493. for (var i = 0; i < data.byteLength; i++) {
  1494. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1495. }
  1496. data = str;
  1497. }
  1498. //if arrived here, data is a string, containing the STLA data.
  1499. while (matches = this.solidPattern.exec(data)) {
  1500. var meshName = matches[1];
  1501. var meshNameFromEnd = matches[3];
  1502. if (meshName != meshNameFromEnd) {
  1503. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1504. return false;
  1505. }
  1506. // check meshesNames
  1507. if (meshesNames && meshName) {
  1508. if (meshesNames instanceof Array) {
  1509. if (!meshesNames.indexOf(meshName)) {
  1510. continue;
  1511. }
  1512. }
  1513. else {
  1514. if (meshName !== meshesNames) {
  1515. continue;
  1516. }
  1517. }
  1518. }
  1519. // stl mesh name can be empty as well
  1520. meshName = meshName || "stlmesh";
  1521. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1522. this._parseASCII(babylonMesh, matches[2]);
  1523. if (meshes) {
  1524. meshes.push(babylonMesh);
  1525. }
  1526. }
  1527. return true;
  1528. };
  1529. /**
  1530. * Load into a scene.
  1531. * @param scene The scene to load into
  1532. * @param data The data to import
  1533. * @param rootUrl The root url for scene and resources
  1534. * @param onError The callback when import fails
  1535. * @returns true if successful or false otherwise
  1536. */
  1537. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1538. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1539. return result;
  1540. };
  1541. /**
  1542. * Load into an asset container.
  1543. * @param scene The scene to load into
  1544. * @param data The data to import
  1545. * @param rootUrl The root url for scene and resources
  1546. * @param onError The callback when import fails
  1547. * @returns The loaded asset container
  1548. */
  1549. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1550. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1551. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1552. container.removeAllFromScene();
  1553. return container;
  1554. };
  1555. STLFileLoader.prototype._isBinary = function (data) {
  1556. // check if file size is correct for binary stl
  1557. var faceSize, nFaces, reader;
  1558. reader = new DataView(data);
  1559. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1560. nFaces = reader.getUint32(80, true);
  1561. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1562. return true;
  1563. }
  1564. // check characters higher than ASCII to confirm binary
  1565. var fileLength = reader.byteLength;
  1566. for (var index = 0; index < fileLength; index++) {
  1567. if (reader.getUint8(index) > 127) {
  1568. return true;
  1569. }
  1570. }
  1571. return false;
  1572. };
  1573. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1574. var reader = new DataView(data);
  1575. var faces = reader.getUint32(80, true);
  1576. var dataOffset = 84;
  1577. var faceLength = 12 * 4 + 2;
  1578. var offset = 0;
  1579. var positions = new Float32Array(faces * 3 * 3);
  1580. var normals = new Float32Array(faces * 3 * 3);
  1581. var indices = new Uint32Array(faces * 3);
  1582. var indicesCount = 0;
  1583. for (var face = 0; face < faces; face++) {
  1584. var start = dataOffset + face * faceLength;
  1585. var normalX = reader.getFloat32(start, true);
  1586. var normalY = reader.getFloat32(start + 4, true);
  1587. var normalZ = reader.getFloat32(start + 8, true);
  1588. for (var i = 1; i <= 3; i++) {
  1589. var vertexstart = start + i * 12;
  1590. // ordering is intentional to match ascii import
  1591. positions[offset] = reader.getFloat32(vertexstart, true);
  1592. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1593. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1594. normals[offset] = normalX;
  1595. normals[offset + 2] = normalY;
  1596. normals[offset + 1] = normalZ;
  1597. offset += 3;
  1598. }
  1599. indices[indicesCount] = indicesCount++;
  1600. indices[indicesCount] = indicesCount++;
  1601. indices[indicesCount] = indicesCount++;
  1602. }
  1603. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1604. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1605. mesh.setIndices(indices);
  1606. mesh.computeWorldMatrix(true);
  1607. };
  1608. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1609. var positions = [];
  1610. var normals = [];
  1611. var indices = [];
  1612. var indicesCount = 0;
  1613. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1614. var matches;
  1615. while (matches = this.facetsPattern.exec(solidData)) {
  1616. var facet = matches[1];
  1617. //one normal per face
  1618. var normalMatches = this.normalPattern.exec(facet);
  1619. this.normalPattern.lastIndex = 0;
  1620. if (!normalMatches) {
  1621. continue;
  1622. }
  1623. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1624. var vertexMatch;
  1625. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1626. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1627. normals.push(normal[0], normal[1], normal[2]);
  1628. }
  1629. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1630. this.vertexPattern.lastIndex = 0;
  1631. }
  1632. this.facetsPattern.lastIndex = 0;
  1633. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1634. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1635. mesh.setIndices(indices);
  1636. mesh.computeWorldMatrix(true);
  1637. };
  1638. return STLFileLoader;
  1639. }());
  1640. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1641. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1642. }
  1643. /***/ }),
  1644. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1645. /*!*****************************************!*\
  1646. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1647. \*****************************************/
  1648. /*! exports provided: GLTFBinaryExtension */
  1649. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1650. "use strict";
  1651. __webpack_require__.r(__webpack_exports__);
  1652. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1653. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1654. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1655. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1656. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1657. var BinaryExtensionBufferName = "binary_glTF";
  1658. /** @hidden */
  1659. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1660. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1661. function GLTFBinaryExtension() {
  1662. return _super.call(this, "KHR_binary_glTF") || this;
  1663. }
  1664. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1665. var extensionsUsed = data.json.extensionsUsed;
  1666. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1667. return false;
  1668. }
  1669. this._bin = data.bin;
  1670. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1671. return true;
  1672. };
  1673. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1674. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1675. return false;
  1676. }
  1677. if (id !== BinaryExtensionBufferName) {
  1678. return false;
  1679. }
  1680. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1681. return true;
  1682. };
  1683. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1684. var texture = gltfRuntime.textures[id];
  1685. var source = gltfRuntime.images[texture.source];
  1686. if (!source.extensions || !(this.name in source.extensions)) {
  1687. return false;
  1688. }
  1689. var sourceExt = source.extensions[this.name];
  1690. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1691. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1692. onSuccess(buffer);
  1693. return true;
  1694. };
  1695. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1696. var shader = gltfRuntime.shaders[id];
  1697. if (!shader.extensions || !(this.name in shader.extensions)) {
  1698. return false;
  1699. }
  1700. var binaryExtensionShader = shader.extensions[this.name];
  1701. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1702. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1703. setTimeout(function () {
  1704. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1705. onSuccess(shaderString);
  1706. });
  1707. return true;
  1708. };
  1709. return GLTFBinaryExtension;
  1710. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1711. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1712. /***/ }),
  1713. /***/ "./glTF/1.0/glTFLoader.ts":
  1714. /*!********************************!*\
  1715. !*** ./glTF/1.0/glTFLoader.ts ***!
  1716. \********************************/
  1717. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1718. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1719. "use strict";
  1720. __webpack_require__.r(__webpack_exports__);
  1721. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1722. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1723. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1724. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1725. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  1726. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  1727. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1728. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1729. /**
  1730. * Tokenizer. Used for shaders compatibility
  1731. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1732. */
  1733. var ETokenType;
  1734. (function (ETokenType) {
  1735. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1736. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1737. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1738. })(ETokenType || (ETokenType = {}));
  1739. var Tokenizer = /** @class */ (function () {
  1740. function Tokenizer(toParse) {
  1741. this._pos = 0;
  1742. this.currentToken = ETokenType.UNKNOWN;
  1743. this.currentIdentifier = "";
  1744. this.currentString = "";
  1745. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1746. this._toParse = toParse;
  1747. this._maxPos = toParse.length;
  1748. }
  1749. Tokenizer.prototype.getNextToken = function () {
  1750. if (this.isEnd()) {
  1751. return ETokenType.END_OF_INPUT;
  1752. }
  1753. this.currentString = this.read();
  1754. this.currentToken = ETokenType.UNKNOWN;
  1755. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1756. this.currentToken = ETokenType.IDENTIFIER;
  1757. this.currentIdentifier = this.currentString;
  1758. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1759. this.currentIdentifier += this.currentString;
  1760. this.forward();
  1761. }
  1762. }
  1763. return this.currentToken;
  1764. };
  1765. Tokenizer.prototype.peek = function () {
  1766. return this._toParse[this._pos];
  1767. };
  1768. Tokenizer.prototype.read = function () {
  1769. return this._toParse[this._pos++];
  1770. };
  1771. Tokenizer.prototype.forward = function () {
  1772. this._pos++;
  1773. };
  1774. Tokenizer.prototype.isEnd = function () {
  1775. return this._pos >= this._maxPos;
  1776. };
  1777. return Tokenizer;
  1778. }());
  1779. /**
  1780. * Values
  1781. */
  1782. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1783. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1784. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1785. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1786. /**
  1787. * Parse
  1788. */
  1789. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1790. for (var buf in parsedBuffers) {
  1791. var parsedBuffer = parsedBuffers[buf];
  1792. gltfRuntime.buffers[buf] = parsedBuffer;
  1793. gltfRuntime.buffersCount++;
  1794. }
  1795. };
  1796. var parseShaders = function (parsedShaders, gltfRuntime) {
  1797. for (var sha in parsedShaders) {
  1798. var parsedShader = parsedShaders[sha];
  1799. gltfRuntime.shaders[sha] = parsedShader;
  1800. gltfRuntime.shaderscount++;
  1801. }
  1802. };
  1803. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1804. for (var object in parsedObjects) {
  1805. var parsedObject = parsedObjects[object];
  1806. gltfRuntime[runtimeProperty][object] = parsedObject;
  1807. }
  1808. };
  1809. /**
  1810. * Utils
  1811. */
  1812. var normalizeUVs = function (buffer) {
  1813. if (!buffer) {
  1814. return;
  1815. }
  1816. for (var i = 0; i < buffer.length / 2; i++) {
  1817. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1818. }
  1819. };
  1820. var getAttribute = function (attributeParameter) {
  1821. if (attributeParameter.semantic === "NORMAL") {
  1822. return "normal";
  1823. }
  1824. else if (attributeParameter.semantic === "POSITION") {
  1825. return "position";
  1826. }
  1827. else if (attributeParameter.semantic === "JOINT") {
  1828. return "matricesIndices";
  1829. }
  1830. else if (attributeParameter.semantic === "WEIGHT") {
  1831. return "matricesWeights";
  1832. }
  1833. else if (attributeParameter.semantic === "COLOR") {
  1834. return "color";
  1835. }
  1836. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1837. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1838. return "uv" + (channel === 0 ? "" : channel + 1);
  1839. }
  1840. return null;
  1841. };
  1842. /**
  1843. * Loads and creates animations
  1844. */
  1845. var loadAnimations = function (gltfRuntime) {
  1846. for (var anim in gltfRuntime.animations) {
  1847. var animation = gltfRuntime.animations[anim];
  1848. if (!animation.channels || !animation.samplers) {
  1849. continue;
  1850. }
  1851. var lastAnimation = null;
  1852. for (var i = 0; i < animation.channels.length; i++) {
  1853. // Get parameters and load buffers
  1854. var channel = animation.channels[i];
  1855. var sampler = animation.samplers[channel.sampler];
  1856. if (!sampler) {
  1857. continue;
  1858. }
  1859. var inputData = null;
  1860. var outputData = null;
  1861. if (animation.parameters) {
  1862. inputData = animation.parameters[sampler.input];
  1863. outputData = animation.parameters[sampler.output];
  1864. }
  1865. else {
  1866. inputData = sampler.input;
  1867. outputData = sampler.output;
  1868. }
  1869. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1870. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1871. var targetID = channel.target.id;
  1872. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1873. if (targetNode === null) {
  1874. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1875. }
  1876. if (targetNode === null) {
  1877. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1878. continue;
  1879. }
  1880. var isBone = targetNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1881. // Get target path (position, rotation or scaling)
  1882. var targetPath = channel.target.path;
  1883. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1884. if (targetPathIndex !== -1) {
  1885. targetPath = babylonAnimationPaths[targetPathIndex];
  1886. }
  1887. // Determine animation type
  1888. var animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1889. if (!isBone) {
  1890. if (targetPath === "rotationQuaternion") {
  1891. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1892. targetNode.rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1893. }
  1894. else {
  1895. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1896. }
  1897. }
  1898. // Create animation and key frames
  1899. var babylonAnimation = null;
  1900. var keys = [];
  1901. var arrayOffset = 0;
  1902. var modifyKey = false;
  1903. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1904. babylonAnimation = lastAnimation;
  1905. modifyKey = true;
  1906. }
  1907. if (!modifyKey) {
  1908. 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);
  1909. }
  1910. // For each frame
  1911. for (var j = 0; j < bufferInput.length; j++) {
  1912. var value = null;
  1913. if (targetPath === "rotationQuaternion") { // VEC4
  1914. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1915. arrayOffset += 4;
  1916. }
  1917. else { // Position and scaling are VEC3
  1918. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1919. arrayOffset += 3;
  1920. }
  1921. if (isBone) {
  1922. var bone = targetNode;
  1923. var translation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1924. var rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1925. var scaling = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1926. // Warning on decompose
  1927. var mat = bone.getBaseMatrix();
  1928. if (modifyKey && lastAnimation) {
  1929. mat = lastAnimation.getKeys()[j].value;
  1930. }
  1931. mat.decompose(scaling, rotationQuaternion, translation);
  1932. if (targetPath === "position") {
  1933. translation = value;
  1934. }
  1935. else if (targetPath === "rotationQuaternion") {
  1936. rotationQuaternion = value;
  1937. }
  1938. else {
  1939. scaling = value;
  1940. }
  1941. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1942. }
  1943. if (!modifyKey) {
  1944. keys.push({
  1945. frame: bufferInput[j],
  1946. value: value
  1947. });
  1948. }
  1949. else if (lastAnimation) {
  1950. lastAnimation.getKeys()[j].value = value;
  1951. }
  1952. }
  1953. // Finish
  1954. if (!modifyKey && babylonAnimation) {
  1955. babylonAnimation.setKeys(keys);
  1956. targetNode.animations.push(babylonAnimation);
  1957. }
  1958. lastAnimation = babylonAnimation;
  1959. gltfRuntime.scene.stopAnimation(targetNode);
  1960. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  1961. }
  1962. }
  1963. };
  1964. /**
  1965. * Returns the bones transformation matrix
  1966. */
  1967. var configureBoneTransformation = function (node) {
  1968. var mat = null;
  1969. if (node.translation || node.rotation || node.scale) {
  1970. var scale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  1971. var rotation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  1972. var position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  1973. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  1974. }
  1975. else {
  1976. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1977. }
  1978. return mat;
  1979. };
  1980. /**
  1981. * Returns the parent bone
  1982. */
  1983. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  1984. // Try to find
  1985. for (var i = 0; i < newSkeleton.bones.length; i++) {
  1986. if (newSkeleton.bones[i].name === jointName) {
  1987. return newSkeleton.bones[i];
  1988. }
  1989. }
  1990. // Not found, search in gltf nodes
  1991. var nodes = gltfRuntime.nodes;
  1992. for (var nde in nodes) {
  1993. var node = nodes[nde];
  1994. if (!node.jointName) {
  1995. continue;
  1996. }
  1997. var children = node.children;
  1998. for (var i = 0; i < children.length; i++) {
  1999. var child = gltfRuntime.nodes[children[i]];
  2000. if (!child.jointName) {
  2001. continue;
  2002. }
  2003. if (child.jointName === jointName) {
  2004. var mat = configureBoneTransformation(node);
  2005. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  2006. bone.id = nde;
  2007. return bone;
  2008. }
  2009. }
  2010. }
  2011. return null;
  2012. };
  2013. /**
  2014. * Returns the appropriate root node
  2015. */
  2016. var getNodeToRoot = function (nodesToRoot, id) {
  2017. for (var i = 0; i < nodesToRoot.length; i++) {
  2018. var nodeToRoot = nodesToRoot[i];
  2019. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  2020. var child = nodeToRoot.node.children[j];
  2021. if (child === id) {
  2022. return nodeToRoot.bone;
  2023. }
  2024. }
  2025. }
  2026. return null;
  2027. };
  2028. /**
  2029. * Returns the node with the joint name
  2030. */
  2031. var getJointNode = function (gltfRuntime, jointName) {
  2032. var nodes = gltfRuntime.nodes;
  2033. var node = nodes[jointName];
  2034. if (node) {
  2035. return {
  2036. node: node,
  2037. id: jointName
  2038. };
  2039. }
  2040. for (var nde in nodes) {
  2041. node = nodes[nde];
  2042. if (node.jointName === jointName) {
  2043. return {
  2044. node: node,
  2045. id: nde
  2046. };
  2047. }
  2048. }
  2049. return null;
  2050. };
  2051. /**
  2052. * Checks if a nodes is in joints
  2053. */
  2054. var nodeIsInJoints = function (skins, id) {
  2055. for (var i = 0; i < skins.jointNames.length; i++) {
  2056. if (skins.jointNames[i] === id) {
  2057. return true;
  2058. }
  2059. }
  2060. return false;
  2061. };
  2062. /**
  2063. * Fills the nodes to root for bones and builds hierarchy
  2064. */
  2065. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2066. // Creates nodes for root
  2067. for (var nde in gltfRuntime.nodes) {
  2068. var node = gltfRuntime.nodes[nde];
  2069. var id = nde;
  2070. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2071. continue;
  2072. }
  2073. // Create node to root bone
  2074. var mat = configureBoneTransformation(node);
  2075. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2076. bone.id = id;
  2077. nodesToRoot.push({ bone: bone, node: node, id: id });
  2078. }
  2079. // Parenting
  2080. for (var i = 0; i < nodesToRoot.length; i++) {
  2081. var nodeToRoot = nodesToRoot[i];
  2082. var children = nodeToRoot.node.children;
  2083. for (var j = 0; j < children.length; j++) {
  2084. var child = null;
  2085. for (var k = 0; k < nodesToRoot.length; k++) {
  2086. if (nodesToRoot[k].id === children[j]) {
  2087. child = nodesToRoot[k];
  2088. break;
  2089. }
  2090. }
  2091. if (child) {
  2092. child.bone._parent = nodeToRoot.bone;
  2093. nodeToRoot.bone.children.push(child.bone);
  2094. }
  2095. }
  2096. }
  2097. };
  2098. /**
  2099. * Imports a skeleton
  2100. */
  2101. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2102. if (!newSkeleton) {
  2103. newSkeleton = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2104. }
  2105. if (!skins.babylonSkeleton) {
  2106. return newSkeleton;
  2107. }
  2108. // Find the root bones
  2109. var nodesToRoot = [];
  2110. var nodesToRootToAdd = [];
  2111. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2112. newSkeleton.bones = [];
  2113. // Joints
  2114. for (var i = 0; i < skins.jointNames.length; i++) {
  2115. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2116. if (!jointNode) {
  2117. continue;
  2118. }
  2119. var node = jointNode.node;
  2120. if (!node) {
  2121. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2122. continue;
  2123. }
  2124. var id = jointNode.id;
  2125. // Optimize, if the bone already exists...
  2126. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2127. if (existingBone) {
  2128. newSkeleton.bones.push(existingBone);
  2129. continue;
  2130. }
  2131. // Search for parent bone
  2132. var foundBone = false;
  2133. var parentBone = null;
  2134. for (var j = 0; j < i; j++) {
  2135. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2136. if (!jointNode_1) {
  2137. continue;
  2138. }
  2139. var joint = jointNode_1.node;
  2140. if (!joint) {
  2141. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2142. continue;
  2143. }
  2144. var children = joint.children;
  2145. if (!children) {
  2146. continue;
  2147. }
  2148. foundBone = false;
  2149. for (var k = 0; k < children.length; k++) {
  2150. if (children[k] === id) {
  2151. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2152. foundBone = true;
  2153. break;
  2154. }
  2155. }
  2156. if (foundBone) {
  2157. break;
  2158. }
  2159. }
  2160. // Create bone
  2161. var mat = configureBoneTransformation(node);
  2162. if (!parentBone && nodesToRoot.length > 0) {
  2163. parentBone = getNodeToRoot(nodesToRoot, id);
  2164. if (parentBone) {
  2165. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2166. nodesToRootToAdd.push(parentBone);
  2167. }
  2168. }
  2169. }
  2170. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2171. bone.id = id;
  2172. }
  2173. // Polish
  2174. var bones = newSkeleton.bones;
  2175. newSkeleton.bones = [];
  2176. for (var i = 0; i < skins.jointNames.length; i++) {
  2177. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2178. if (!jointNode) {
  2179. continue;
  2180. }
  2181. for (var j = 0; j < bones.length; j++) {
  2182. if (bones[j].id === jointNode.id) {
  2183. newSkeleton.bones.push(bones[j]);
  2184. break;
  2185. }
  2186. }
  2187. }
  2188. newSkeleton.prepare();
  2189. // Finish
  2190. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2191. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2192. }
  2193. return newSkeleton;
  2194. };
  2195. /**
  2196. * Imports a mesh and its geometries
  2197. */
  2198. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2199. if (!newMesh) {
  2200. newMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2201. newMesh.id = id;
  2202. }
  2203. if (!node.babylonNode) {
  2204. return newMesh;
  2205. }
  2206. var subMaterials = [];
  2207. var vertexData = null;
  2208. var verticesStarts = new Array();
  2209. var verticesCounts = new Array();
  2210. var indexStarts = new Array();
  2211. var indexCounts = new Array();
  2212. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2213. var meshID = meshes[meshIndex];
  2214. var mesh = gltfRuntime.meshes[meshID];
  2215. if (!mesh) {
  2216. continue;
  2217. }
  2218. // Positions, normals and UVs
  2219. for (var i = 0; i < mesh.primitives.length; i++) {
  2220. // Temporary vertex data
  2221. var tempVertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2222. var primitive = mesh.primitives[i];
  2223. if (primitive.mode !== 4) {
  2224. // continue;
  2225. }
  2226. var attributes = primitive.attributes;
  2227. var accessor = null;
  2228. var buffer = null;
  2229. // Set positions, normal and uvs
  2230. for (var semantic in attributes) {
  2231. // Link accessor and buffer view
  2232. accessor = gltfRuntime.accessors[attributes[semantic]];
  2233. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2234. if (semantic === "NORMAL") {
  2235. tempVertexData.normals = new Float32Array(buffer.length);
  2236. tempVertexData.normals.set(buffer);
  2237. }
  2238. else if (semantic === "POSITION") {
  2239. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2240. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2241. for (var j = 0; j < buffer.length; j += 4) {
  2242. tempVertexData.positions[j] = buffer[j];
  2243. tempVertexData.positions[j + 1] = buffer[j + 1];
  2244. tempVertexData.positions[j + 2] = buffer[j + 2];
  2245. }
  2246. }
  2247. else {
  2248. tempVertexData.positions = new Float32Array(buffer.length);
  2249. tempVertexData.positions.set(buffer);
  2250. }
  2251. verticesCounts.push(tempVertexData.positions.length);
  2252. }
  2253. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2254. var channel = Number(semantic.split("_")[1]);
  2255. var uvKind = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2256. var uvs = new Float32Array(buffer.length);
  2257. uvs.set(buffer);
  2258. normalizeUVs(uvs);
  2259. tempVertexData.set(uvs, uvKind);
  2260. }
  2261. else if (semantic === "JOINT") {
  2262. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2263. tempVertexData.matricesIndices.set(buffer);
  2264. }
  2265. else if (semantic === "WEIGHT") {
  2266. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2267. tempVertexData.matricesWeights.set(buffer);
  2268. }
  2269. else if (semantic === "COLOR") {
  2270. tempVertexData.colors = new Float32Array(buffer.length);
  2271. tempVertexData.colors.set(buffer);
  2272. }
  2273. }
  2274. // Indices
  2275. accessor = gltfRuntime.accessors[primitive.indices];
  2276. if (accessor) {
  2277. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2278. tempVertexData.indices = new Int32Array(buffer.length);
  2279. tempVertexData.indices.set(buffer);
  2280. indexCounts.push(tempVertexData.indices.length);
  2281. }
  2282. else {
  2283. // Set indices on the fly
  2284. var indices = [];
  2285. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2286. indices.push(j);
  2287. }
  2288. tempVertexData.indices = new Int32Array(indices);
  2289. indexCounts.push(tempVertexData.indices.length);
  2290. }
  2291. if (!vertexData) {
  2292. vertexData = tempVertexData;
  2293. }
  2294. else {
  2295. vertexData.merge(tempVertexData);
  2296. }
  2297. // Sub material
  2298. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2299. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2300. // Update vertices start and index start
  2301. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2302. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2303. }
  2304. }
  2305. var material;
  2306. if (subMaterials.length > 1) {
  2307. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2308. material.subMaterials = subMaterials;
  2309. }
  2310. else {
  2311. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2312. }
  2313. if (subMaterials.length === 1) {
  2314. material = subMaterials[0];
  2315. }
  2316. if (!newMesh.material) {
  2317. newMesh.material = material;
  2318. }
  2319. // Apply geometry
  2320. new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2321. newMesh.computeWorldMatrix(true);
  2322. // Apply submeshes
  2323. newMesh.subMeshes = [];
  2324. var index = 0;
  2325. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2326. var meshID = meshes[meshIndex];
  2327. var mesh = gltfRuntime.meshes[meshID];
  2328. if (!mesh) {
  2329. continue;
  2330. }
  2331. for (var i = 0; i < mesh.primitives.length; i++) {
  2332. if (mesh.primitives[i].mode !== 4) {
  2333. //continue;
  2334. }
  2335. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2336. index++;
  2337. }
  2338. }
  2339. // Finish
  2340. return newMesh;
  2341. };
  2342. /**
  2343. * Configure node transformation from position, rotation and scaling
  2344. */
  2345. var configureNode = function (newNode, position, rotation, scaling) {
  2346. if (newNode.position) {
  2347. newNode.position = position;
  2348. }
  2349. if (newNode.rotationQuaternion || newNode.rotation) {
  2350. newNode.rotationQuaternion = rotation;
  2351. }
  2352. if (newNode.scaling) {
  2353. newNode.scaling = scaling;
  2354. }
  2355. };
  2356. /**
  2357. * Configures node from transformation matrix
  2358. */
  2359. var configureNodeFromMatrix = function (newNode, node, parent) {
  2360. if (node.matrix) {
  2361. var position = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2362. var rotation = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2363. var scaling = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2364. var mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2365. mat.decompose(scaling, rotation, position);
  2366. configureNode(newNode, position, rotation, scaling);
  2367. }
  2368. else if (node.translation && node.rotation && node.scale) {
  2369. 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));
  2370. }
  2371. newNode.computeWorldMatrix(true);
  2372. };
  2373. /**
  2374. * Imports a node
  2375. */
  2376. var importNode = function (gltfRuntime, node, id, parent) {
  2377. var lastNode = null;
  2378. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2379. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2380. return null;
  2381. }
  2382. }
  2383. // Meshes
  2384. if (node.skin) {
  2385. if (node.meshes) {
  2386. var skin = gltfRuntime.skins[node.skin];
  2387. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2388. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2389. if (newMesh.skeleton === null) {
  2390. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2391. if (!skin.babylonSkeleton) {
  2392. skin.babylonSkeleton = newMesh.skeleton;
  2393. }
  2394. }
  2395. lastNode = newMesh;
  2396. }
  2397. }
  2398. else if (node.meshes) {
  2399. /**
  2400. * Improve meshes property
  2401. */
  2402. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2403. lastNode = newMesh;
  2404. }
  2405. // Lights
  2406. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2407. var light = gltfRuntime.lights[node.light];
  2408. if (light) {
  2409. if (light.type === "ambient") {
  2410. var ambienLight = light[light.type];
  2411. var hemiLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2412. hemiLight.name = node.name || "";
  2413. if (ambienLight.color) {
  2414. hemiLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2415. }
  2416. lastNode = hemiLight;
  2417. }
  2418. else if (light.type === "directional") {
  2419. var directionalLight = light[light.type];
  2420. var dirLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2421. dirLight.name = node.name || "";
  2422. if (directionalLight.color) {
  2423. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2424. }
  2425. lastNode = dirLight;
  2426. }
  2427. else if (light.type === "point") {
  2428. var pointLight = light[light.type];
  2429. var ptLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2430. ptLight.name = node.name || "";
  2431. if (pointLight.color) {
  2432. ptLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2433. }
  2434. lastNode = ptLight;
  2435. }
  2436. else if (light.type === "spot") {
  2437. var spotLight = light[light.type];
  2438. 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);
  2439. spLight.name = node.name || "";
  2440. if (spotLight.color) {
  2441. spLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2442. }
  2443. if (spotLight.fallOfAngle) {
  2444. spLight.angle = spotLight.fallOfAngle;
  2445. }
  2446. if (spotLight.fallOffExponent) {
  2447. spLight.exponent = spotLight.fallOffExponent;
  2448. }
  2449. lastNode = spLight;
  2450. }
  2451. }
  2452. }
  2453. // Cameras
  2454. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2455. var camera = gltfRuntime.cameras[node.camera];
  2456. if (camera) {
  2457. if (camera.type === "orthographic") {
  2458. 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);
  2459. orthoCamera.name = node.name || "";
  2460. orthoCamera.mode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2461. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2462. lastNode = orthoCamera;
  2463. }
  2464. else if (camera.type === "perspective") {
  2465. var perspectiveCamera = camera[camera.type];
  2466. 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);
  2467. persCamera.name = node.name || "";
  2468. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2469. if (!perspectiveCamera.aspectRatio) {
  2470. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2471. }
  2472. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2473. persCamera.maxZ = perspectiveCamera.zfar;
  2474. persCamera.minZ = perspectiveCamera.znear;
  2475. }
  2476. lastNode = persCamera;
  2477. }
  2478. }
  2479. }
  2480. // Empty node
  2481. if (!node.jointName) {
  2482. if (node.babylonNode) {
  2483. return node.babylonNode;
  2484. }
  2485. else if (lastNode === null) {
  2486. var dummy = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2487. node.babylonNode = dummy;
  2488. lastNode = dummy;
  2489. }
  2490. }
  2491. if (lastNode !== null) {
  2492. if (node.matrix && lastNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2493. configureNodeFromMatrix(lastNode, node, parent);
  2494. }
  2495. else {
  2496. var translation = node.translation || [0, 0, 0];
  2497. var rotation = node.rotation || [0, 0, 0, 1];
  2498. var scale = node.scale || [1, 1, 1];
  2499. 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));
  2500. }
  2501. lastNode.updateCache(true);
  2502. node.babylonNode = lastNode;
  2503. }
  2504. return lastNode;
  2505. };
  2506. /**
  2507. * Traverses nodes and creates them
  2508. */
  2509. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2510. if (meshIncluded === void 0) { meshIncluded = false; }
  2511. var node = gltfRuntime.nodes[id];
  2512. var newNode = null;
  2513. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2514. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2515. meshIncluded = true;
  2516. }
  2517. else {
  2518. meshIncluded = false;
  2519. }
  2520. }
  2521. else {
  2522. meshIncluded = true;
  2523. }
  2524. if (!node.jointName && meshIncluded) {
  2525. newNode = importNode(gltfRuntime, node, id, parent);
  2526. if (newNode !== null) {
  2527. newNode.id = id;
  2528. newNode.parent = parent;
  2529. }
  2530. }
  2531. if (node.children) {
  2532. for (var i = 0; i < node.children.length; i++) {
  2533. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2534. }
  2535. }
  2536. };
  2537. /**
  2538. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2539. */
  2540. var postLoad = function (gltfRuntime) {
  2541. // Nodes
  2542. var currentScene = gltfRuntime.currentScene;
  2543. if (currentScene) {
  2544. for (var i = 0; i < currentScene.nodes.length; i++) {
  2545. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2546. }
  2547. }
  2548. else {
  2549. for (var thing in gltfRuntime.scenes) {
  2550. currentScene = gltfRuntime.scenes[thing];
  2551. for (var i = 0; i < currentScene.nodes.length; i++) {
  2552. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2553. }
  2554. }
  2555. }
  2556. // Set animations
  2557. loadAnimations(gltfRuntime);
  2558. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2559. var skeleton = gltfRuntime.scene.skeletons[i];
  2560. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2561. }
  2562. };
  2563. /**
  2564. * onBind shaderrs callback to set uniforms and matrices
  2565. */
  2566. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2567. var materialValues = material.values || technique.parameters;
  2568. for (var unif in unTreatedUniforms) {
  2569. var uniform = unTreatedUniforms[unif];
  2570. var type = uniform.type;
  2571. 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) {
  2572. if (uniform.semantic && !uniform.source && !uniform.node) {
  2573. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2574. }
  2575. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2576. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2577. if (source === null) {
  2578. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2579. }
  2580. if (source === null) {
  2581. continue;
  2582. }
  2583. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2584. }
  2585. }
  2586. else {
  2587. var value = materialValues[technique.uniforms[unif]];
  2588. if (!value) {
  2589. continue;
  2590. }
  2591. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2592. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2593. if (texture === null || texture === undefined) {
  2594. continue;
  2595. }
  2596. shaderMaterial.getEffect().setTexture(unif, texture);
  2597. }
  2598. else {
  2599. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2600. }
  2601. }
  2602. }
  2603. onSuccess(shaderMaterial);
  2604. };
  2605. /**
  2606. * Prepare uniforms to send the only one time
  2607. * Loads the appropriate textures
  2608. */
  2609. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2610. var materialValues = material.values || technique.parameters;
  2611. var techniqueUniforms = technique.uniforms;
  2612. /**
  2613. * Prepare values here (not matrices)
  2614. */
  2615. for (var unif in unTreatedUniforms) {
  2616. var uniform = unTreatedUniforms[unif];
  2617. var type = uniform.type;
  2618. var value = materialValues[techniqueUniforms[unif]];
  2619. if (value === undefined) {
  2620. // In case the value is the same for all materials
  2621. value = uniform.value;
  2622. }
  2623. if (!value) {
  2624. continue;
  2625. }
  2626. var onLoadTexture = function (uniformName) {
  2627. return function (texture) {
  2628. if (uniform.value && uniformName) {
  2629. // Static uniform
  2630. shaderMaterial.setTexture(uniformName, texture);
  2631. delete unTreatedUniforms[uniformName];
  2632. }
  2633. };
  2634. };
  2635. // Texture (sampler2D)
  2636. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2637. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2638. }
  2639. // Others
  2640. else {
  2641. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2642. // Static uniform
  2643. delete unTreatedUniforms[unif];
  2644. }
  2645. }
  2646. }
  2647. };
  2648. /**
  2649. * Shader compilation failed
  2650. */
  2651. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2652. return function (effect, error) {
  2653. shaderMaterial.dispose(true);
  2654. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2655. };
  2656. };
  2657. /**
  2658. * Shader compilation success
  2659. */
  2660. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2661. return function (_) {
  2662. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2663. shaderMaterial.onBind = function (mesh) {
  2664. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2665. };
  2666. };
  2667. };
  2668. /**
  2669. * Returns the appropriate uniform if already handled by babylon
  2670. */
  2671. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2672. for (var unif in technique.uniforms) {
  2673. var uniform = technique.uniforms[unif];
  2674. var uniformParameter = technique.parameters[uniform];
  2675. if (tokenizer.currentIdentifier === unif) {
  2676. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2677. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2678. if (transformIndex !== -1) {
  2679. delete unTreatedUniforms[unif];
  2680. return babylonTransforms[transformIndex];
  2681. }
  2682. }
  2683. }
  2684. }
  2685. return tokenizer.currentIdentifier;
  2686. };
  2687. /**
  2688. * All shaders loaded. Create materials one by one
  2689. */
  2690. var importMaterials = function (gltfRuntime) {
  2691. // Create materials
  2692. for (var mat in gltfRuntime.materials) {
  2693. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2694. }
  2695. };
  2696. /**
  2697. * Implementation of the base glTF spec
  2698. * @hidden
  2699. */
  2700. var GLTFLoaderBase = /** @class */ (function () {
  2701. function GLTFLoaderBase() {
  2702. }
  2703. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2704. var gltfRuntime = {
  2705. extensions: {},
  2706. accessors: {},
  2707. buffers: {},
  2708. bufferViews: {},
  2709. meshes: {},
  2710. lights: {},
  2711. cameras: {},
  2712. nodes: {},
  2713. images: {},
  2714. textures: {},
  2715. shaders: {},
  2716. programs: {},
  2717. samplers: {},
  2718. techniques: {},
  2719. materials: {},
  2720. animations: {},
  2721. skins: {},
  2722. extensionsUsed: [],
  2723. scenes: {},
  2724. buffersCount: 0,
  2725. shaderscount: 0,
  2726. scene: scene,
  2727. rootUrl: rootUrl,
  2728. loadedBufferCount: 0,
  2729. loadedBufferViews: {},
  2730. loadedShaderCount: 0,
  2731. importOnlyMeshes: false,
  2732. dummyNodes: []
  2733. };
  2734. // Parse
  2735. if (parsedData.extensions) {
  2736. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2737. }
  2738. if (parsedData.extensionsUsed) {
  2739. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2740. }
  2741. if (parsedData.buffers) {
  2742. parseBuffers(parsedData.buffers, gltfRuntime);
  2743. }
  2744. if (parsedData.bufferViews) {
  2745. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2746. }
  2747. if (parsedData.accessors) {
  2748. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2749. }
  2750. if (parsedData.meshes) {
  2751. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2752. }
  2753. if (parsedData.lights) {
  2754. parseObject(parsedData.lights, "lights", gltfRuntime);
  2755. }
  2756. if (parsedData.cameras) {
  2757. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2758. }
  2759. if (parsedData.nodes) {
  2760. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2761. }
  2762. if (parsedData.images) {
  2763. parseObject(parsedData.images, "images", gltfRuntime);
  2764. }
  2765. if (parsedData.textures) {
  2766. parseObject(parsedData.textures, "textures", gltfRuntime);
  2767. }
  2768. if (parsedData.shaders) {
  2769. parseShaders(parsedData.shaders, gltfRuntime);
  2770. }
  2771. if (parsedData.programs) {
  2772. parseObject(parsedData.programs, "programs", gltfRuntime);
  2773. }
  2774. if (parsedData.samplers) {
  2775. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2776. }
  2777. if (parsedData.techniques) {
  2778. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2779. }
  2780. if (parsedData.materials) {
  2781. parseObject(parsedData.materials, "materials", gltfRuntime);
  2782. }
  2783. if (parsedData.animations) {
  2784. parseObject(parsedData.animations, "animations", gltfRuntime);
  2785. }
  2786. if (parsedData.skins) {
  2787. parseObject(parsedData.skins, "skins", gltfRuntime);
  2788. }
  2789. if (parsedData.scenes) {
  2790. gltfRuntime.scenes = parsedData.scenes;
  2791. }
  2792. if (parsedData.scene && parsedData.scenes) {
  2793. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2794. }
  2795. return gltfRuntime;
  2796. };
  2797. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2798. var buffer = gltfRuntime.buffers[id];
  2799. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2800. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2801. }
  2802. else {
  2803. 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) {
  2804. if (request) {
  2805. onError(request.status + " " + request.statusText);
  2806. }
  2807. });
  2808. }
  2809. };
  2810. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2811. var texture = gltfRuntime.textures[id];
  2812. if (!texture || !texture.source) {
  2813. onError("");
  2814. return;
  2815. }
  2816. if (texture.babylonTexture) {
  2817. onSuccess(null);
  2818. return;
  2819. }
  2820. var source = gltfRuntime.images[texture.source];
  2821. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2822. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2823. }
  2824. else {
  2825. 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) {
  2826. if (request) {
  2827. onError(request.status + " " + request.statusText);
  2828. }
  2829. });
  2830. }
  2831. };
  2832. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2833. var texture = gltfRuntime.textures[id];
  2834. if (texture.babylonTexture) {
  2835. onSuccess(texture.babylonTexture);
  2836. return;
  2837. }
  2838. var sampler = gltfRuntime.samplers[texture.sampler];
  2839. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2840. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2841. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2842. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2843. var samplingMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2844. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2845. var blobURL = URL.createObjectURL(blob);
  2846. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2847. var newTexture = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2848. if (sampler.wrapS !== undefined) {
  2849. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2850. }
  2851. if (sampler.wrapT !== undefined) {
  2852. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2853. }
  2854. newTexture.name = id;
  2855. texture.babylonTexture = newTexture;
  2856. onSuccess(newTexture);
  2857. };
  2858. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2859. var shader = gltfRuntime.shaders[id];
  2860. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2861. var shaderString = atob(shader.uri.split(",")[1]);
  2862. if (onSuccess) {
  2863. onSuccess(shaderString);
  2864. }
  2865. }
  2866. else {
  2867. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2868. if (request && onError) {
  2869. onError(request.status + " " + request.statusText);
  2870. }
  2871. });
  2872. }
  2873. };
  2874. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2875. var material = gltfRuntime.materials[id];
  2876. if (!material.technique) {
  2877. if (onError) {
  2878. onError("No technique found.");
  2879. }
  2880. return;
  2881. }
  2882. var technique = gltfRuntime.techniques[material.technique];
  2883. if (!technique) {
  2884. var defaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2885. defaultMaterial.diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2886. defaultMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2887. onSuccess(defaultMaterial);
  2888. return;
  2889. }
  2890. var program = gltfRuntime.programs[technique.program];
  2891. var states = technique.states;
  2892. var vertexShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2893. var pixelShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2894. var newVertexShader = "";
  2895. var newPixelShader = "";
  2896. var vertexTokenizer = new Tokenizer(vertexShader);
  2897. var pixelTokenizer = new Tokenizer(pixelShader);
  2898. var unTreatedUniforms = {};
  2899. var uniforms = [];
  2900. var attributes = [];
  2901. var samplers = [];
  2902. // Fill uniform, sampler2D and attributes
  2903. for (var unif in technique.uniforms) {
  2904. var uniform = technique.uniforms[unif];
  2905. var uniformParameter = technique.parameters[uniform];
  2906. unTreatedUniforms[unif] = uniformParameter;
  2907. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2908. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2909. if (transformIndex !== -1) {
  2910. uniforms.push(babylonTransforms[transformIndex]);
  2911. delete unTreatedUniforms[unif];
  2912. }
  2913. else {
  2914. uniforms.push(unif);
  2915. }
  2916. }
  2917. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2918. samplers.push(unif);
  2919. }
  2920. else {
  2921. uniforms.push(unif);
  2922. }
  2923. }
  2924. for (var attr in technique.attributes) {
  2925. var attribute = technique.attributes[attr];
  2926. var attributeParameter = technique.parameters[attribute];
  2927. if (attributeParameter.semantic) {
  2928. var name_1 = getAttribute(attributeParameter);
  2929. if (name_1) {
  2930. attributes.push(name_1);
  2931. }
  2932. }
  2933. }
  2934. // Configure vertex shader
  2935. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2936. var tokenType = vertexTokenizer.currentToken;
  2937. if (tokenType !== ETokenType.IDENTIFIER) {
  2938. newVertexShader += vertexTokenizer.currentString;
  2939. continue;
  2940. }
  2941. var foundAttribute = false;
  2942. for (var attr in technique.attributes) {
  2943. var attribute = technique.attributes[attr];
  2944. var attributeParameter = technique.parameters[attribute];
  2945. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  2946. newVertexShader += getAttribute(attributeParameter);
  2947. foundAttribute = true;
  2948. break;
  2949. }
  2950. }
  2951. if (foundAttribute) {
  2952. continue;
  2953. }
  2954. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  2955. }
  2956. // Configure pixel shader
  2957. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  2958. var tokenType = pixelTokenizer.currentToken;
  2959. if (tokenType !== ETokenType.IDENTIFIER) {
  2960. newPixelShader += pixelTokenizer.currentString;
  2961. continue;
  2962. }
  2963. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  2964. }
  2965. // Create shader material
  2966. var shaderPath = {
  2967. vertex: program.vertexShader + id,
  2968. fragment: program.fragmentShader + id
  2969. };
  2970. var options = {
  2971. attributes: attributes,
  2972. uniforms: uniforms,
  2973. samplers: samplers,
  2974. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  2975. };
  2976. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  2977. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  2978. var shaderMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  2979. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  2980. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  2981. shaderMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2982. if (states && states.functions) {
  2983. var functions = states.functions;
  2984. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  2985. shaderMaterial.backFaceCulling = false;
  2986. }
  2987. var blendFunc = functions.blendFuncSeparate;
  2988. if (blendFunc) {
  2989. 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) {
  2990. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  2991. }
  2992. 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) {
  2993. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  2994. }
  2995. 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) {
  2996. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  2997. }
  2998. 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) {
  2999. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  3000. }
  3001. 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) {
  3002. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  3003. }
  3004. 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) {
  3005. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  3006. }
  3007. }
  3008. }
  3009. };
  3010. return GLTFLoaderBase;
  3011. }());
  3012. /**
  3013. * glTF V1 Loader
  3014. * @hidden
  3015. */
  3016. var GLTFLoader = /** @class */ (function () {
  3017. function GLTFLoader() {
  3018. this.state = null;
  3019. }
  3020. GLTFLoader.RegisterExtension = function (extension) {
  3021. if (GLTFLoader.Extensions[extension.name]) {
  3022. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  3023. return;
  3024. }
  3025. GLTFLoader.Extensions[extension.name] = extension;
  3026. };
  3027. GLTFLoader.prototype.dispose = function () {
  3028. // do nothing
  3029. };
  3030. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  3031. var _this = this;
  3032. scene.useRightHandedSystem = true;
  3033. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3034. gltfRuntime.importOnlyMeshes = true;
  3035. if (meshesNames === "") {
  3036. gltfRuntime.importMeshesNames = [];
  3037. }
  3038. else if (typeof meshesNames === "string") {
  3039. gltfRuntime.importMeshesNames = [meshesNames];
  3040. }
  3041. else if (meshesNames && !(meshesNames instanceof Array)) {
  3042. gltfRuntime.importMeshesNames = [meshesNames];
  3043. }
  3044. else {
  3045. gltfRuntime.importMeshesNames = [];
  3046. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3047. }
  3048. // Create nodes
  3049. _this._createNodes(gltfRuntime);
  3050. var meshes = new Array();
  3051. var skeletons = new Array();
  3052. // Fill arrays of meshes and skeletons
  3053. for (var nde in gltfRuntime.nodes) {
  3054. var node = gltfRuntime.nodes[nde];
  3055. if (node.babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3056. meshes.push(node.babylonNode);
  3057. }
  3058. }
  3059. for (var skl in gltfRuntime.skins) {
  3060. var skin = gltfRuntime.skins[skl];
  3061. if (skin.babylonSkeleton instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3062. skeletons.push(skin.babylonSkeleton);
  3063. }
  3064. }
  3065. // Load buffers, shaders, materials, etc.
  3066. _this._loadBuffersAsync(gltfRuntime, function () {
  3067. _this._loadShadersAsync(gltfRuntime, function () {
  3068. importMaterials(gltfRuntime);
  3069. postLoad(gltfRuntime);
  3070. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3071. onSuccess(meshes, skeletons);
  3072. }
  3073. });
  3074. }, onProgress);
  3075. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3076. onSuccess(meshes, skeletons);
  3077. }
  3078. }, onError);
  3079. return true;
  3080. };
  3081. /**
  3082. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3083. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3084. * @param scene the scene the meshes should be added to
  3085. * @param data gltf data containing information of the meshes in a loaded file
  3086. * @param rootUrl root url to load from
  3087. * @param onProgress event that fires when loading progress has occured
  3088. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3089. */
  3090. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  3091. var _this = this;
  3092. return new Promise(function (resolve, reject) {
  3093. _this._importMeshAsync(meshesNames, scene, data, rootUrl, function (meshes, skeletons) {
  3094. resolve({
  3095. meshes: meshes,
  3096. particleSystems: [],
  3097. skeletons: skeletons,
  3098. animationGroups: []
  3099. });
  3100. }, onProgress, function (message) {
  3101. reject(new Error(message));
  3102. });
  3103. });
  3104. };
  3105. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  3106. var _this = this;
  3107. scene.useRightHandedSystem = true;
  3108. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3109. // Load runtime extensios
  3110. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3111. // Create nodes
  3112. _this._createNodes(gltfRuntime);
  3113. // Load buffers, shaders, materials, etc.
  3114. _this._loadBuffersAsync(gltfRuntime, function () {
  3115. _this._loadShadersAsync(gltfRuntime, function () {
  3116. importMaterials(gltfRuntime);
  3117. postLoad(gltfRuntime);
  3118. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3119. onSuccess();
  3120. }
  3121. });
  3122. });
  3123. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3124. onSuccess();
  3125. }
  3126. }, onError);
  3127. }, onError);
  3128. };
  3129. /**
  3130. * Imports all objects from a loaded gltf file and adds them to the scene
  3131. * @param scene the scene the objects should be added to
  3132. * @param data gltf data containing information of the meshes in a loaded file
  3133. * @param rootUrl root url to load from
  3134. * @param onProgress event that fires when loading progress has occured
  3135. * @returns a promise which completes when objects have been loaded to the scene
  3136. */
  3137. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3138. var _this = this;
  3139. return new Promise(function (resolve, reject) {
  3140. _this._loadAsync(scene, data, rootUrl, function () {
  3141. resolve();
  3142. }, onProgress, function (message) {
  3143. reject(new Error(message));
  3144. });
  3145. });
  3146. };
  3147. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3148. var hasShaders = false;
  3149. var processShader = function (sha, shader) {
  3150. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3151. if (shaderString instanceof ArrayBuffer) {
  3152. return;
  3153. }
  3154. gltfRuntime.loadedShaderCount++;
  3155. if (shaderString) {
  3156. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3157. }
  3158. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3159. onload();
  3160. }
  3161. }, function () {
  3162. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3163. });
  3164. };
  3165. for (var sha in gltfRuntime.shaders) {
  3166. hasShaders = true;
  3167. var shader = gltfRuntime.shaders[sha];
  3168. if (shader) {
  3169. processShader.bind(this, sha, shader)();
  3170. }
  3171. else {
  3172. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3173. }
  3174. }
  3175. if (!hasShaders) {
  3176. onload();
  3177. }
  3178. };
  3179. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3180. var hasBuffers = false;
  3181. var processBuffer = function (buf, buffer) {
  3182. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3183. gltfRuntime.loadedBufferCount++;
  3184. if (bufferView) {
  3185. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3186. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3187. }
  3188. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3189. }
  3190. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3191. onLoad();
  3192. }
  3193. }, function () {
  3194. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3195. });
  3196. };
  3197. for (var buf in gltfRuntime.buffers) {
  3198. hasBuffers = true;
  3199. var buffer = gltfRuntime.buffers[buf];
  3200. if (buffer) {
  3201. processBuffer.bind(this, buf, buffer)();
  3202. }
  3203. else {
  3204. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3205. }
  3206. }
  3207. if (!hasBuffers) {
  3208. onLoad();
  3209. }
  3210. };
  3211. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3212. var currentScene = gltfRuntime.currentScene;
  3213. if (currentScene) {
  3214. // Only one scene even if multiple scenes are defined
  3215. for (var i = 0; i < currentScene.nodes.length; i++) {
  3216. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3217. }
  3218. }
  3219. else {
  3220. // Load all scenes
  3221. for (var thing in gltfRuntime.scenes) {
  3222. currentScene = gltfRuntime.scenes[thing];
  3223. for (var i = 0; i < currentScene.nodes.length; i++) {
  3224. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3225. }
  3226. }
  3227. }
  3228. };
  3229. GLTFLoader.Extensions = {};
  3230. return GLTFLoader;
  3231. }());
  3232. /** @hidden */
  3233. var GLTFLoaderExtension = /** @class */ (function () {
  3234. function GLTFLoaderExtension(name) {
  3235. this._name = name;
  3236. }
  3237. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3238. get: function () {
  3239. return this._name;
  3240. },
  3241. enumerable: true,
  3242. configurable: true
  3243. });
  3244. /**
  3245. * Defines an override for loading the runtime
  3246. * Return true to stop further extensions from loading the runtime
  3247. */
  3248. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3249. return false;
  3250. };
  3251. /**
  3252. * Defines an onverride for creating gltf runtime
  3253. * Return true to stop further extensions from creating the runtime
  3254. */
  3255. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3256. return false;
  3257. };
  3258. /**
  3259. * Defines an override for loading buffers
  3260. * Return true to stop further extensions from loading this buffer
  3261. */
  3262. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3263. return false;
  3264. };
  3265. /**
  3266. * Defines an override for loading texture buffers
  3267. * Return true to stop further extensions from loading this texture data
  3268. */
  3269. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3270. return false;
  3271. };
  3272. /**
  3273. * Defines an override for creating textures
  3274. * Return true to stop further extensions from loading this texture
  3275. */
  3276. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3277. return false;
  3278. };
  3279. /**
  3280. * Defines an override for loading shader strings
  3281. * Return true to stop further extensions from loading this shader data
  3282. */
  3283. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3284. return false;
  3285. };
  3286. /**
  3287. * Defines an override for loading materials
  3288. * Return true to stop further extensions from loading this material
  3289. */
  3290. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3291. return false;
  3292. };
  3293. // ---------
  3294. // Utilities
  3295. // ---------
  3296. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3297. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3298. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3299. }, function () {
  3300. setTimeout(function () {
  3301. if (!onSuccess) {
  3302. return;
  3303. }
  3304. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3305. });
  3306. });
  3307. };
  3308. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3309. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3310. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3311. }, function () {
  3312. setTimeout(function () {
  3313. onSuccess();
  3314. });
  3315. });
  3316. };
  3317. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3318. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3319. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3320. }, function () {
  3321. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3322. });
  3323. };
  3324. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3325. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3326. if (buffer) {
  3327. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3328. }
  3329. }, onError);
  3330. };
  3331. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3332. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3333. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3334. }, function () {
  3335. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3336. });
  3337. };
  3338. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3339. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3340. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3341. }, function () {
  3342. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3343. });
  3344. };
  3345. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3346. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3347. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3348. }, function () {
  3349. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3350. });
  3351. };
  3352. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3353. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3354. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3355. }, function () {
  3356. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3357. });
  3358. };
  3359. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3360. for (var extensionName in GLTFLoader.Extensions) {
  3361. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3362. if (func(loaderExtension)) {
  3363. return;
  3364. }
  3365. }
  3366. defaultFunc();
  3367. };
  3368. return GLTFLoaderExtension;
  3369. }());
  3370. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3371. /***/ }),
  3372. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3373. /*!******************************************!*\
  3374. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3375. \******************************************/
  3376. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3377. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3378. "use strict";
  3379. __webpack_require__.r(__webpack_exports__);
  3380. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3381. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3382. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3383. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3384. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3385. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3386. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3387. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3388. /**
  3389. * Enums
  3390. * @hidden
  3391. */
  3392. var EComponentType;
  3393. (function (EComponentType) {
  3394. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3395. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3396. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3397. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3398. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3399. })(EComponentType || (EComponentType = {}));
  3400. /** @hidden */
  3401. var EShaderType;
  3402. (function (EShaderType) {
  3403. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3404. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3405. })(EShaderType || (EShaderType = {}));
  3406. /** @hidden */
  3407. var EParameterType;
  3408. (function (EParameterType) {
  3409. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3410. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3411. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3412. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3413. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3414. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3415. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3416. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3417. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3418. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3419. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3420. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3421. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3422. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3423. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3424. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3425. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3426. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3427. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3428. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3429. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3430. })(EParameterType || (EParameterType = {}));
  3431. /** @hidden */
  3432. var ETextureWrapMode;
  3433. (function (ETextureWrapMode) {
  3434. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3435. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3436. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3437. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3438. /** @hidden */
  3439. var ETextureFilterType;
  3440. (function (ETextureFilterType) {
  3441. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3442. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3443. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3444. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3445. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3446. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3447. })(ETextureFilterType || (ETextureFilterType = {}));
  3448. /** @hidden */
  3449. var ETextureFormat;
  3450. (function (ETextureFormat) {
  3451. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3452. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3453. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3454. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3455. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3456. })(ETextureFormat || (ETextureFormat = {}));
  3457. /** @hidden */
  3458. var ECullingType;
  3459. (function (ECullingType) {
  3460. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3461. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3462. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3463. })(ECullingType || (ECullingType = {}));
  3464. /** @hidden */
  3465. var EBlendingFunction;
  3466. (function (EBlendingFunction) {
  3467. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3468. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3469. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3470. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3471. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3472. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3473. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3474. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3475. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3476. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3477. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3478. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3479. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3480. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3481. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3482. })(EBlendingFunction || (EBlendingFunction = {}));
  3483. /***/ }),
  3484. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3485. /*!*************************************!*\
  3486. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3487. \*************************************/
  3488. /*! exports provided: GLTFUtils */
  3489. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3490. "use strict";
  3491. __webpack_require__.r(__webpack_exports__);
  3492. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3493. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3494. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3495. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  3496. /**
  3497. * Utils functions for GLTF
  3498. * @hidden
  3499. */
  3500. var GLTFUtils = /** @class */ (function () {
  3501. function GLTFUtils() {
  3502. }
  3503. /**
  3504. * Sets the given "parameter" matrix
  3505. * @param scene: the Scene object
  3506. * @param source: the source node where to pick the matrix
  3507. * @param parameter: the GLTF technique parameter
  3508. * @param uniformName: the name of the shader's uniform
  3509. * @param shaderMaterial: the shader material
  3510. */
  3511. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3512. var mat = null;
  3513. if (parameter.semantic === "MODEL") {
  3514. mat = source.getWorldMatrix();
  3515. }
  3516. else if (parameter.semantic === "PROJECTION") {
  3517. mat = scene.getProjectionMatrix();
  3518. }
  3519. else if (parameter.semantic === "VIEW") {
  3520. mat = scene.getViewMatrix();
  3521. }
  3522. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3523. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3524. }
  3525. else if (parameter.semantic === "MODELVIEW") {
  3526. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3527. }
  3528. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3529. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3530. }
  3531. else if (parameter.semantic === "MODELINVERSE") {
  3532. mat = source.getWorldMatrix().invert();
  3533. }
  3534. else if (parameter.semantic === "VIEWINVERSE") {
  3535. mat = scene.getViewMatrix().invert();
  3536. }
  3537. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3538. mat = scene.getProjectionMatrix().invert();
  3539. }
  3540. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3541. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3542. }
  3543. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3544. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3545. }
  3546. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3547. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3548. }
  3549. else {
  3550. debugger;
  3551. }
  3552. if (mat) {
  3553. switch (parameter.type) {
  3554. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3555. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3556. break;
  3557. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3558. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3559. break;
  3560. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3561. shaderMaterial.setMatrix(uniformName, mat);
  3562. break;
  3563. default: break;
  3564. }
  3565. }
  3566. };
  3567. /**
  3568. * Sets the given "parameter" matrix
  3569. * @param shaderMaterial: the shader material
  3570. * @param uniform: the name of the shader's uniform
  3571. * @param value: the value of the uniform
  3572. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3573. */
  3574. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3575. switch (type) {
  3576. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3577. shaderMaterial.setFloat(uniform, value);
  3578. return true;
  3579. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3580. shaderMaterial.setVector2(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3581. return true;
  3582. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3583. shaderMaterial.setVector3(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3584. return true;
  3585. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3586. shaderMaterial.setVector4(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3587. return true;
  3588. default: return false;
  3589. }
  3590. };
  3591. /**
  3592. * Returns the wrap mode of the texture
  3593. * @param mode: the mode value
  3594. */
  3595. GLTFUtils.GetWrapMode = function (mode) {
  3596. switch (mode) {
  3597. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3598. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3599. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3600. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3601. }
  3602. };
  3603. /**
  3604. * Returns the byte stride giving an accessor
  3605. * @param accessor: the GLTF accessor objet
  3606. */
  3607. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3608. // Needs this function since "byteStride" isn't requiered in glTF format
  3609. var type = accessor.type;
  3610. switch (type) {
  3611. case "VEC2": return 2;
  3612. case "VEC3": return 3;
  3613. case "VEC4": return 4;
  3614. case "MAT2": return 4;
  3615. case "MAT3": return 9;
  3616. case "MAT4": return 16;
  3617. default: return 1;
  3618. }
  3619. };
  3620. /**
  3621. * Returns the texture filter mode giving a mode value
  3622. * @param mode: the filter mode value
  3623. */
  3624. GLTFUtils.GetTextureFilterMode = function (mode) {
  3625. switch (mode) {
  3626. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3627. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3628. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3629. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3630. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3631. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3632. }
  3633. };
  3634. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3635. var byteOffset = bufferView.byteOffset + byteOffset;
  3636. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3637. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3638. throw new Error("Buffer access is out of range");
  3639. }
  3640. var buffer = loadedBufferView.buffer;
  3641. byteOffset += loadedBufferView.byteOffset;
  3642. switch (componentType) {
  3643. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3644. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3645. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3646. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3647. default: return new Float32Array(buffer, byteOffset, byteLength);
  3648. }
  3649. };
  3650. /**
  3651. * Returns a buffer from its accessor
  3652. * @param gltfRuntime: the GLTF runtime
  3653. * @param accessor: the GLTF accessor
  3654. */
  3655. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3656. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3657. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3658. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3659. };
  3660. /**
  3661. * Decodes a buffer view into a string
  3662. * @param view: the buffer view
  3663. */
  3664. GLTFUtils.DecodeBufferToText = function (view) {
  3665. var result = "";
  3666. var length = view.byteLength;
  3667. for (var i = 0; i < length; ++i) {
  3668. result += String.fromCharCode(view[i]);
  3669. }
  3670. return result;
  3671. };
  3672. /**
  3673. * Returns the default material of gltf. Related to
  3674. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3675. * @param scene: the Babylon.js scene
  3676. */
  3677. GLTFUtils.GetDefaultMaterial = function (scene) {
  3678. if (!GLTFUtils._DefaultMaterial) {
  3679. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3680. "precision highp float;",
  3681. "",
  3682. "uniform mat4 worldView;",
  3683. "uniform mat4 projection;",
  3684. "",
  3685. "attribute vec3 position;",
  3686. "",
  3687. "void main(void)",
  3688. "{",
  3689. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3690. "}"
  3691. ].join("\n");
  3692. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3693. "precision highp float;",
  3694. "",
  3695. "uniform vec4 u_emission;",
  3696. "",
  3697. "void main(void)",
  3698. "{",
  3699. " gl_FragColor = u_emission;",
  3700. "}"
  3701. ].join("\n");
  3702. var shaderPath = {
  3703. vertex: "GLTFDefaultMaterial",
  3704. fragment: "GLTFDefaultMaterial"
  3705. };
  3706. var options = {
  3707. attributes: ["position"],
  3708. uniforms: ["worldView", "projection", "u_emission"],
  3709. samplers: new Array(),
  3710. needAlphaBlending: false
  3711. };
  3712. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3713. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3714. }
  3715. return GLTFUtils._DefaultMaterial;
  3716. };
  3717. // The GLTF default material
  3718. GLTFUtils._DefaultMaterial = null;
  3719. return GLTFUtils;
  3720. }());
  3721. /***/ }),
  3722. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3723. /*!**************************************************!*\
  3724. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3725. \**************************************************/
  3726. /*! exports provided: GLTFMaterialsCommonExtension */
  3727. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3728. "use strict";
  3729. __webpack_require__.r(__webpack_exports__);
  3730. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3731. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3732. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3733. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  3734. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__);
  3735. /** @hidden */
  3736. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3737. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3738. function GLTFMaterialsCommonExtension() {
  3739. return _super.call(this, "KHR_materials_common") || this;
  3740. }
  3741. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3742. if (!gltfRuntime.extensions) {
  3743. return false;
  3744. }
  3745. var extension = gltfRuntime.extensions[this.name];
  3746. if (!extension) {
  3747. return false;
  3748. }
  3749. // Create lights
  3750. var lights = extension.lights;
  3751. if (lights) {
  3752. for (var thing in lights) {
  3753. var light = lights[thing];
  3754. switch (light.type) {
  3755. case "ambient":
  3756. 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);
  3757. var ambient = light.ambient;
  3758. if (ambient) {
  3759. ambientLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3760. }
  3761. break;
  3762. case "point":
  3763. 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);
  3764. var point = light.point;
  3765. if (point) {
  3766. pointLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3767. }
  3768. break;
  3769. case "directional":
  3770. 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);
  3771. var directional = light.directional;
  3772. if (directional) {
  3773. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3774. }
  3775. break;
  3776. case "spot":
  3777. var spot = light.spot;
  3778. if (spot) {
  3779. 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);
  3780. spotLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3781. }
  3782. break;
  3783. default:
  3784. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3785. break;
  3786. }
  3787. }
  3788. }
  3789. return false;
  3790. };
  3791. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3792. var material = gltfRuntime.materials[id];
  3793. if (!material || !material.extensions) {
  3794. return false;
  3795. }
  3796. var extension = material.extensions[this.name];
  3797. if (!extension) {
  3798. return false;
  3799. }
  3800. var standardMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3801. standardMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3802. if (extension.technique === "CONSTANT") {
  3803. standardMaterial.disableLighting = true;
  3804. }
  3805. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3806. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3807. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3808. // Ambient
  3809. if (typeof extension.values.ambient === "string") {
  3810. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3811. }
  3812. else {
  3813. standardMaterial.ambientColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3814. }
  3815. // Diffuse
  3816. if (typeof extension.values.diffuse === "string") {
  3817. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3818. }
  3819. else {
  3820. standardMaterial.diffuseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3821. }
  3822. // Emission
  3823. if (typeof extension.values.emission === "string") {
  3824. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3825. }
  3826. else {
  3827. standardMaterial.emissiveColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3828. }
  3829. // Specular
  3830. if (typeof extension.values.specular === "string") {
  3831. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3832. }
  3833. else {
  3834. standardMaterial.specularColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3835. }
  3836. return true;
  3837. };
  3838. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3839. // Create buffer from texture url
  3840. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3841. // Create texture from buffer
  3842. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3843. }, onError);
  3844. };
  3845. return GLTFMaterialsCommonExtension;
  3846. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3847. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3848. /***/ }),
  3849. /***/ "./glTF/1.0/index.ts":
  3850. /*!***************************!*\
  3851. !*** ./glTF/1.0/index.ts ***!
  3852. \***************************/
  3853. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3854. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3855. "use strict";
  3856. __webpack_require__.r(__webpack_exports__);
  3857. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3858. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3859. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3860. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3861. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3862. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3863. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3864. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3865. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3866. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3867. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3868. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3869. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3870. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3871. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3872. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3873. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3874. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3875. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3876. /***/ }),
  3877. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3878. /*!*******************************************************!*\
  3879. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3880. \*******************************************************/
  3881. /*! exports provided: EXT_lights_image_based */
  3882. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3883. "use strict";
  3884. __webpack_require__.r(__webpack_exports__);
  3885. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3886. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  3887. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3888. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3889. var NAME = "EXT_lights_image_based";
  3890. /**
  3891. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3892. */
  3893. var EXT_lights_image_based = /** @class */ (function () {
  3894. /** @hidden */
  3895. function EXT_lights_image_based(loader) {
  3896. /**
  3897. * The name of this extension.
  3898. */
  3899. this.name = NAME;
  3900. this._loader = loader;
  3901. this.enabled = this._loader.isExtensionUsed(NAME);
  3902. }
  3903. /** @hidden */
  3904. EXT_lights_image_based.prototype.dispose = function () {
  3905. delete this._loader;
  3906. delete this._lights;
  3907. };
  3908. /** @hidden */
  3909. EXT_lights_image_based.prototype.onLoading = function () {
  3910. var extensions = this._loader.gltf.extensions;
  3911. if (extensions && extensions[this.name]) {
  3912. var extension = extensions[this.name];
  3913. this._lights = extension.lights;
  3914. }
  3915. };
  3916. /** @hidden */
  3917. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3918. var _this = this;
  3919. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3920. var promises = new Array();
  3921. promises.push(_this._loader.loadSceneAsync(context, scene));
  3922. _this._loader.logOpen("" + extensionContext);
  3923. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3924. promises.push(_this._loadLightAsync("#/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3925. _this._loader.babylonScene.environmentTexture = texture;
  3926. }));
  3927. _this._loader.logClose();
  3928. return Promise.all(promises).then(function () { });
  3929. });
  3930. };
  3931. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3932. var _this = this;
  3933. if (!light._loaded) {
  3934. var promises = new Array();
  3935. this._loader.logOpen("" + context);
  3936. var imageData_1 = new Array(light.specularImages.length);
  3937. var _loop_1 = function (mipmap) {
  3938. var faces = light.specularImages[mipmap];
  3939. imageData_1[mipmap] = new Array(faces.length);
  3940. var _loop_2 = function (face) {
  3941. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  3942. this_1._loader.logOpen("" + specularImageContext);
  3943. var index = faces[face];
  3944. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  3945. promises.push(this_1._loader.loadImageAsync("#/images/" + index, image).then(function (data) {
  3946. imageData_1[mipmap][face] = data;
  3947. }));
  3948. this_1._loader.logClose();
  3949. };
  3950. for (var face = 0; face < faces.length; face++) {
  3951. _loop_2(face);
  3952. }
  3953. };
  3954. var this_1 = this;
  3955. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  3956. _loop_1(mipmap);
  3957. }
  3958. this._loader.logClose();
  3959. light._loaded = Promise.all(promises).then(function () {
  3960. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  3961. light._babylonTexture = babylonTexture;
  3962. if (light.intensity != undefined) {
  3963. babylonTexture.level = light.intensity;
  3964. }
  3965. if (light.rotation) {
  3966. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  3967. // Invert the rotation so that positive rotation is counter-clockwise.
  3968. if (!_this._loader.babylonScene.useRightHandedSystem) {
  3969. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  3970. }
  3971. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  3972. }
  3973. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  3974. sphericalHarmonics.scaleInPlace(light.intensity);
  3975. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  3976. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  3977. // Compute the lod generation scale to fit exactly to the number of levels available.
  3978. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  3979. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  3980. });
  3981. }
  3982. return light._loaded.then(function () {
  3983. return light._babylonTexture;
  3984. });
  3985. };
  3986. return EXT_lights_image_based;
  3987. }());
  3988. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  3989. /***/ }),
  3990. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  3991. /*!*************************************************!*\
  3992. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  3993. \*************************************************/
  3994. /*! exports provided: ExtrasAsMetadata */
  3995. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3996. "use strict";
  3997. __webpack_require__.r(__webpack_exports__);
  3998. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  3999. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4000. var NAME = "ExtrasAsMetadata";
  4001. /**
  4002. * Store glTF extras (if present) in BJS objects' metadata
  4003. */
  4004. var ExtrasAsMetadata = /** @class */ (function () {
  4005. /** @hidden */
  4006. function ExtrasAsMetadata(loader) {
  4007. /**
  4008. * The name of this extension.
  4009. */
  4010. this.name = NAME;
  4011. /**
  4012. * Defines whether this extension is enabled.
  4013. */
  4014. this.enabled = true;
  4015. this._loader = loader;
  4016. }
  4017. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  4018. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  4019. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  4020. var gltf = (metadata.gltf = metadata.gltf || {});
  4021. gltf.extras = gltfProp.extras;
  4022. }
  4023. };
  4024. /** @hidden */
  4025. ExtrasAsMetadata.prototype.dispose = function () {
  4026. delete this._loader;
  4027. };
  4028. /** @hidden */
  4029. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4030. var _this = this;
  4031. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4032. _this._assignExtras(babylonTransformNode, node);
  4033. assign(babylonTransformNode);
  4034. });
  4035. };
  4036. /** @hidden */
  4037. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4038. var _this = this;
  4039. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4040. _this._assignExtras(babylonCamera, camera);
  4041. assign(babylonCamera);
  4042. });
  4043. };
  4044. /** @hidden */
  4045. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4046. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4047. this._assignExtras(babylonMaterial, material);
  4048. return babylonMaterial;
  4049. };
  4050. return ExtrasAsMetadata;
  4051. }());
  4052. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4053. /***/ }),
  4054. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4055. /*!***********************************************************!*\
  4056. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4057. \***********************************************************/
  4058. /*! exports provided: KHR_draco_mesh_compression */
  4059. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4060. "use strict";
  4061. __webpack_require__.r(__webpack_exports__);
  4062. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4063. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  4064. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4065. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4066. var NAME = "KHR_draco_mesh_compression";
  4067. /**
  4068. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4069. */
  4070. var KHR_draco_mesh_compression = /** @class */ (function () {
  4071. /** @hidden */
  4072. function KHR_draco_mesh_compression(loader) {
  4073. /**
  4074. * The name of this extension.
  4075. */
  4076. this.name = NAME;
  4077. this._loader = loader;
  4078. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4079. }
  4080. /** @hidden */
  4081. KHR_draco_mesh_compression.prototype.dispose = function () {
  4082. delete this.dracoCompression;
  4083. delete this._loader;
  4084. };
  4085. /** @hidden */
  4086. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4087. var _this = this;
  4088. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4089. if (primitive.mode != undefined) {
  4090. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4091. primitive.mode !== 4 /* TRIANGLES */) {
  4092. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4093. }
  4094. // TODO: handle triangle strips
  4095. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4096. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4097. }
  4098. }
  4099. var attributes = {};
  4100. var loadAttribute = function (name, kind) {
  4101. var uniqueId = extension.attributes[name];
  4102. if (uniqueId == undefined) {
  4103. return;
  4104. }
  4105. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4106. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4107. babylonMesh._delayInfo.push(kind);
  4108. }
  4109. attributes[kind] = uniqueId;
  4110. };
  4111. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4112. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4113. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4114. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4115. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4116. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4117. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4118. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4119. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4120. if (!bufferView._dracoBabylonGeometry) {
  4121. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4122. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4123. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4124. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4125. babylonVertexData.applyToGeometry(babylonGeometry);
  4126. return babylonGeometry;
  4127. }).catch(function (error) {
  4128. throw new Error(context + ": " + error.message);
  4129. });
  4130. });
  4131. }
  4132. return bufferView._dracoBabylonGeometry;
  4133. });
  4134. };
  4135. return KHR_draco_mesh_compression;
  4136. }());
  4137. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4138. /***/ }),
  4139. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4140. /*!****************************************************!*\
  4141. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4142. \****************************************************/
  4143. /*! exports provided: KHR_lights */
  4144. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4145. "use strict";
  4146. __webpack_require__.r(__webpack_exports__);
  4147. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4148. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4149. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4150. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4151. var NAME = "KHR_lights_punctual";
  4152. var LightType;
  4153. (function (LightType) {
  4154. LightType["DIRECTIONAL"] = "directional";
  4155. LightType["POINT"] = "point";
  4156. LightType["SPOT"] = "spot";
  4157. })(LightType || (LightType = {}));
  4158. /**
  4159. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  4160. */
  4161. var KHR_lights = /** @class */ (function () {
  4162. /** @hidden */
  4163. function KHR_lights(loader) {
  4164. /**
  4165. * The name of this extension.
  4166. */
  4167. this.name = NAME;
  4168. this._loader = loader;
  4169. this.enabled = this._loader.isExtensionUsed(NAME);
  4170. }
  4171. /** @hidden */
  4172. KHR_lights.prototype.dispose = function () {
  4173. delete this._loader;
  4174. delete this._lights;
  4175. };
  4176. /** @hidden */
  4177. KHR_lights.prototype.onLoading = function () {
  4178. var extensions = this._loader.gltf.extensions;
  4179. if (extensions && extensions[this.name]) {
  4180. var extension = extensions[this.name];
  4181. this._lights = extension.lights;
  4182. }
  4183. };
  4184. /** @hidden */
  4185. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4186. var _this = this;
  4187. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4188. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4189. var babylonLight;
  4190. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4191. var name = light.name || babylonMesh.name;
  4192. switch (light.type) {
  4193. case LightType.DIRECTIONAL: {
  4194. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  4195. break;
  4196. }
  4197. case LightType.POINT: {
  4198. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  4199. break;
  4200. }
  4201. case LightType.SPOT: {
  4202. 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);
  4203. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4204. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4205. babylonLight = babylonSpotLight;
  4206. break;
  4207. }
  4208. default: {
  4209. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4210. }
  4211. }
  4212. babylonLight.falloffType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4213. babylonLight.diffuse = light.color ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4214. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4215. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4216. babylonLight.parent = babylonMesh;
  4217. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4218. assign(babylonMesh);
  4219. });
  4220. });
  4221. };
  4222. return KHR_lights;
  4223. }());
  4224. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4225. /***/ }),
  4226. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4227. /*!********************************************************!*\
  4228. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4229. \********************************************************/
  4230. /*! exports provided: KHR_materials_clearcoat */
  4231. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4232. "use strict";
  4233. __webpack_require__.r(__webpack_exports__);
  4234. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4235. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4236. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4237. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4238. var NAME = "KHR_materials_clearcoat";
  4239. /**
  4240. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4241. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4242. * !!! Experimental Extension Subject to Changes !!!
  4243. */
  4244. var KHR_materials_clearcoat = /** @class */ (function () {
  4245. /** @hidden */
  4246. function KHR_materials_clearcoat(loader) {
  4247. /**
  4248. * The name of this extension.
  4249. */
  4250. this.name = NAME;
  4251. /**
  4252. * Defines a number that determines the order the extensions are applied.
  4253. */
  4254. this.order = 220;
  4255. this._loader = loader;
  4256. this.enabled = this._loader.isExtensionUsed(NAME);
  4257. }
  4258. /** @hidden */
  4259. KHR_materials_clearcoat.prototype.dispose = function () {
  4260. delete this._loader;
  4261. };
  4262. /** @hidden */
  4263. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4264. var _this = this;
  4265. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4266. var promises = new Array();
  4267. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4268. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4269. return Promise.all(promises).then(function () { });
  4270. });
  4271. };
  4272. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4273. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4274. throw new Error(context + ": Material type not supported");
  4275. }
  4276. var promises = new Array();
  4277. babylonMaterial.clearCoat.isEnabled = true;
  4278. if (properties.clearcoatFactor != undefined) {
  4279. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4280. }
  4281. else {
  4282. babylonMaterial.clearCoat.intensity = 0;
  4283. }
  4284. if (properties.clearcoatTexture) {
  4285. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4286. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4287. babylonMaterial.clearCoat.texture = texture;
  4288. }));
  4289. }
  4290. if (properties.clearcoatRoughnessFactor != undefined) {
  4291. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4292. }
  4293. else {
  4294. babylonMaterial.clearCoat.roughness = 0;
  4295. }
  4296. if (properties.clearcoatRoughnessTexture) {
  4297. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4298. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4299. babylonMaterial.clearCoat.texture = texture;
  4300. }));
  4301. }
  4302. if (properties.clearcoatNormalTexture) {
  4303. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4304. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4305. babylonMaterial.clearCoat.bumpTexture = texture;
  4306. }));
  4307. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4308. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4309. if (properties.clearcoatNormalTexture.scale != undefined) {
  4310. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4311. }
  4312. }
  4313. return Promise.all(promises).then(function () { });
  4314. };
  4315. return KHR_materials_clearcoat;
  4316. }());
  4317. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4318. /***/ }),
  4319. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4320. /*!********************************************************************!*\
  4321. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4322. \********************************************************************/
  4323. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4324. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4325. "use strict";
  4326. __webpack_require__.r(__webpack_exports__);
  4327. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4328. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4329. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4330. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4331. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4332. /**
  4333. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4334. */
  4335. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4336. /** @hidden */
  4337. function KHR_materials_pbrSpecularGlossiness(loader) {
  4338. /**
  4339. * The name of this extension.
  4340. */
  4341. this.name = NAME;
  4342. /**
  4343. * Defines a number that determines the order the extensions are applied.
  4344. */
  4345. this.order = 200;
  4346. this._loader = loader;
  4347. this.enabled = this._loader.isExtensionUsed(NAME);
  4348. }
  4349. /** @hidden */
  4350. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4351. delete this._loader;
  4352. };
  4353. /** @hidden */
  4354. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4355. var _this = this;
  4356. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4357. var promises = new Array();
  4358. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4359. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4360. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4361. return Promise.all(promises).then(function () { });
  4362. });
  4363. };
  4364. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4365. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4366. throw new Error(context + ": Material type not supported");
  4367. }
  4368. var promises = new Array();
  4369. babylonMaterial.metallic = null;
  4370. babylonMaterial.roughness = null;
  4371. if (properties.diffuseFactor) {
  4372. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4373. babylonMaterial.alpha = properties.diffuseFactor[3];
  4374. }
  4375. else {
  4376. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4377. }
  4378. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4379. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4380. if (properties.diffuseTexture) {
  4381. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4382. texture.name = babylonMaterial.name + " (Diffuse)";
  4383. babylonMaterial.albedoTexture = texture;
  4384. }));
  4385. }
  4386. if (properties.specularGlossinessTexture) {
  4387. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4388. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4389. babylonMaterial.reflectivityTexture = texture;
  4390. }));
  4391. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4392. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4393. }
  4394. return Promise.all(promises).then(function () { });
  4395. };
  4396. return KHR_materials_pbrSpecularGlossiness;
  4397. }());
  4398. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4399. /***/ }),
  4400. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4401. /*!****************************************************!*\
  4402. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4403. \****************************************************/
  4404. /*! exports provided: KHR_materials_sheen */
  4405. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4406. "use strict";
  4407. __webpack_require__.r(__webpack_exports__);
  4408. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4409. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4410. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4411. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4412. var NAME = "KHR_materials_sheen";
  4413. /**
  4414. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4415. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4416. * !!! Experimental Extension Subject to Changes !!!
  4417. */
  4418. var KHR_materials_sheen = /** @class */ (function () {
  4419. /** @hidden */
  4420. function KHR_materials_sheen(loader) {
  4421. /**
  4422. * The name of this extension.
  4423. */
  4424. this.name = NAME;
  4425. /**
  4426. * Defines a number that determines the order the extensions are applied.
  4427. */
  4428. this.order = 240;
  4429. this._loader = loader;
  4430. this.enabled = this._loader.isExtensionUsed(NAME);
  4431. }
  4432. /** @hidden */
  4433. KHR_materials_sheen.prototype.dispose = function () {
  4434. delete this._loader;
  4435. };
  4436. /** @hidden */
  4437. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4438. var _this = this;
  4439. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4440. var promises = new Array();
  4441. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4442. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4443. return Promise.all(promises).then(function () { });
  4444. });
  4445. };
  4446. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4447. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4448. throw new Error(context + ": Material type not supported");
  4449. }
  4450. var promises = new Array();
  4451. babylonMaterial.sheen.isEnabled = true;
  4452. if (properties.intensityFactor != undefined) {
  4453. babylonMaterial.sheen.intensity = properties.intensityFactor;
  4454. }
  4455. else {
  4456. babylonMaterial.sheen.intensity = 0;
  4457. }
  4458. if (properties.colorFactor != undefined) {
  4459. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  4460. }
  4461. if (properties.colorIntensityTexture) {
  4462. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  4463. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  4464. babylonMaterial.sheen.texture = texture;
  4465. }));
  4466. }
  4467. return Promise.all(promises).then(function () { });
  4468. };
  4469. return KHR_materials_sheen;
  4470. }());
  4471. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4472. /***/ }),
  4473. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4474. /*!*******************************************************!*\
  4475. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4476. \*******************************************************/
  4477. /*! exports provided: KHR_materials_specular */
  4478. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4479. "use strict";
  4480. __webpack_require__.r(__webpack_exports__);
  4481. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4482. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4483. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4484. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4485. var NAME = "KHR_materials_specular";
  4486. /**
  4487. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4488. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4489. * !!! Experimental Extension Subject to Changes !!!
  4490. */
  4491. var KHR_materials_specular = /** @class */ (function () {
  4492. /** @hidden */
  4493. function KHR_materials_specular(loader) {
  4494. /**
  4495. * The name of this extension.
  4496. */
  4497. this.name = NAME;
  4498. /**
  4499. * Defines a number that determines the order the extensions are applied.
  4500. */
  4501. this.order = 230;
  4502. this._loader = loader;
  4503. this.enabled = this._loader.isExtensionUsed(NAME);
  4504. }
  4505. /** @hidden */
  4506. KHR_materials_specular.prototype.dispose = function () {
  4507. delete this._loader;
  4508. };
  4509. /** @hidden */
  4510. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4511. var _this = this;
  4512. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4513. var promises = new Array();
  4514. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4515. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4516. return Promise.all(promises).then(function () { });
  4517. });
  4518. };
  4519. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4520. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4521. throw new Error(context + ": Material type not supported");
  4522. }
  4523. if (properties.specularFactor !== undefined) {
  4524. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4525. }
  4526. if (properties.specularTexture) {
  4527. // This does not allow a separate sampler for it at the moment but is currently under discussion.
  4528. babylonMaterial.useMetallicF0FactorFromMetallicTexture = true;
  4529. }
  4530. return Promise.resolve();
  4531. };
  4532. return KHR_materials_specular;
  4533. }());
  4534. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4535. /***/ }),
  4536. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  4537. /*!****************************************************!*\
  4538. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  4539. \****************************************************/
  4540. /*! exports provided: KHR_materials_unlit */
  4541. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4542. "use strict";
  4543. __webpack_require__.r(__webpack_exports__);
  4544. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  4545. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4546. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4547. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4548. var NAME = "KHR_materials_unlit";
  4549. /**
  4550. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4551. */
  4552. var KHR_materials_unlit = /** @class */ (function () {
  4553. /** @hidden */
  4554. function KHR_materials_unlit(loader) {
  4555. /**
  4556. * The name of this extension.
  4557. */
  4558. this.name = NAME;
  4559. /**
  4560. * Defines a number that determines the order the extensions are applied.
  4561. */
  4562. this.order = 210;
  4563. this._loader = loader;
  4564. this.enabled = this._loader.isExtensionUsed(NAME);
  4565. }
  4566. /** @hidden */
  4567. KHR_materials_unlit.prototype.dispose = function () {
  4568. delete this._loader;
  4569. };
  4570. /** @hidden */
  4571. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4572. var _this = this;
  4573. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  4574. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  4575. });
  4576. };
  4577. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  4578. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4579. throw new Error(context + ": Material type not supported");
  4580. }
  4581. var promises = new Array();
  4582. babylonMaterial.unlit = true;
  4583. var properties = material.pbrMetallicRoughness;
  4584. if (properties) {
  4585. if (properties.baseColorFactor) {
  4586. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  4587. babylonMaterial.alpha = properties.baseColorFactor[3];
  4588. }
  4589. else {
  4590. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4591. }
  4592. if (properties.baseColorTexture) {
  4593. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  4594. texture.name = babylonMaterial.name + " (Base Color)";
  4595. babylonMaterial.albedoTexture = texture;
  4596. }));
  4597. }
  4598. }
  4599. if (material.doubleSided) {
  4600. babylonMaterial.backFaceCulling = false;
  4601. babylonMaterial.twoSidedLighting = true;
  4602. }
  4603. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4604. return Promise.all(promises).then(function () { });
  4605. };
  4606. return KHR_materials_unlit;
  4607. }());
  4608. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  4609. /***/ }),
  4610. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  4611. /*!******************************************************!*\
  4612. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  4613. \******************************************************/
  4614. /*! exports provided: KHR_mesh_quantization */
  4615. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4616. "use strict";
  4617. __webpack_require__.r(__webpack_exports__);
  4618. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  4619. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4620. var NAME = "KHR_mesh_quantization";
  4621. /**
  4622. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  4623. */
  4624. var KHR_mesh_quantization = /** @class */ (function () {
  4625. /** @hidden */
  4626. function KHR_mesh_quantization(loader) {
  4627. /**
  4628. * The name of this extension.
  4629. */
  4630. this.name = NAME;
  4631. this.enabled = loader.isExtensionUsed(NAME);
  4632. }
  4633. /** @hidden */
  4634. KHR_mesh_quantization.prototype.dispose = function () {
  4635. };
  4636. return KHR_mesh_quantization;
  4637. }());
  4638. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  4639. /***/ }),
  4640. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  4641. /*!******************************************************!*\
  4642. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  4643. \******************************************************/
  4644. /*! exports provided: KHR_texture_transform */
  4645. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4646. "use strict";
  4647. __webpack_require__.r(__webpack_exports__);
  4648. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  4649. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  4650. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  4651. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4652. var NAME = "KHR_texture_transform";
  4653. /**
  4654. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4655. */
  4656. var KHR_texture_transform = /** @class */ (function () {
  4657. /** @hidden */
  4658. function KHR_texture_transform(loader) {
  4659. /**
  4660. * The name of this extension.
  4661. */
  4662. this.name = NAME;
  4663. this._loader = loader;
  4664. this.enabled = this._loader.isExtensionUsed(NAME);
  4665. }
  4666. /** @hidden */
  4667. KHR_texture_transform.prototype.dispose = function () {
  4668. delete this._loader;
  4669. };
  4670. /** @hidden */
  4671. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  4672. var _this = this;
  4673. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  4674. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  4675. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  4676. throw new Error(extensionContext + ": Texture type not supported");
  4677. }
  4678. if (extension.offset) {
  4679. babylonTexture.uOffset = extension.offset[0];
  4680. babylonTexture.vOffset = extension.offset[1];
  4681. }
  4682. // Always rotate around the origin.
  4683. babylonTexture.uRotationCenter = 0;
  4684. babylonTexture.vRotationCenter = 0;
  4685. if (extension.rotation) {
  4686. babylonTexture.wAng = -extension.rotation;
  4687. }
  4688. if (extension.scale) {
  4689. babylonTexture.uScale = extension.scale[0];
  4690. babylonTexture.vScale = extension.scale[1];
  4691. }
  4692. if (extension.texCoord != undefined) {
  4693. babylonTexture.coordinatesIndex = extension.texCoord;
  4694. }
  4695. assign(babylonTexture);
  4696. });
  4697. });
  4698. };
  4699. return KHR_texture_transform;
  4700. }());
  4701. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  4702. /***/ }),
  4703. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  4704. /*!***************************************************!*\
  4705. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  4706. \***************************************************/
  4707. /*! exports provided: MSFT_audio_emitter */
  4708. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4709. "use strict";
  4710. __webpack_require__.r(__webpack_exports__);
  4711. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  4712. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/tools");
  4713. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4714. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4715. var NAME = "MSFT_audio_emitter";
  4716. /**
  4717. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4718. */
  4719. var MSFT_audio_emitter = /** @class */ (function () {
  4720. /** @hidden */
  4721. function MSFT_audio_emitter(loader) {
  4722. /**
  4723. * The name of this extension.
  4724. */
  4725. this.name = NAME;
  4726. this._loader = loader;
  4727. this.enabled = this._loader.isExtensionUsed(NAME);
  4728. }
  4729. /** @hidden */
  4730. MSFT_audio_emitter.prototype.dispose = function () {
  4731. delete this._loader;
  4732. delete this._clips;
  4733. delete this._emitters;
  4734. };
  4735. /** @hidden */
  4736. MSFT_audio_emitter.prototype.onLoading = function () {
  4737. var extensions = this._loader.gltf.extensions;
  4738. if (extensions && extensions[this.name]) {
  4739. var extension = extensions[this.name];
  4740. this._clips = extension.clips;
  4741. this._emitters = extension.emitters;
  4742. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  4743. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  4744. }
  4745. };
  4746. /** @hidden */
  4747. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  4748. var _this = this;
  4749. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  4750. var promises = new Array();
  4751. promises.push(_this._loader.loadSceneAsync(context, scene));
  4752. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4753. var emitterIndex = _a[_i];
  4754. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4755. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  4756. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4757. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  4758. }
  4759. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  4760. }
  4761. return Promise.all(promises).then(function () { });
  4762. });
  4763. };
  4764. /** @hidden */
  4765. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  4766. var _this = this;
  4767. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4768. var promises = new Array();
  4769. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  4770. var _loop_1 = function (emitterIndex) {
  4771. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4772. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  4773. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  4774. var sound = _a[_i];
  4775. sound.attachToMesh(babylonMesh);
  4776. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4777. sound.setLocalDirectionToMesh(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  4778. 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);
  4779. }
  4780. }
  4781. }));
  4782. };
  4783. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4784. var emitterIndex = _a[_i];
  4785. _loop_1(emitterIndex);
  4786. }
  4787. assign(babylonMesh);
  4788. }).then(function (babylonMesh) {
  4789. return Promise.all(promises).then(function () {
  4790. return babylonMesh;
  4791. });
  4792. });
  4793. });
  4794. };
  4795. /** @hidden */
  4796. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  4797. var _this = this;
  4798. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  4799. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  4800. var promises = new Array();
  4801. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  4802. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  4803. var event_1 = _a[_i];
  4804. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  4805. }
  4806. return Promise.all(promises).then(function () {
  4807. return babylonAnimationGroup;
  4808. });
  4809. });
  4810. });
  4811. };
  4812. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  4813. if (clip._objectURL) {
  4814. return clip._objectURL;
  4815. }
  4816. var promise;
  4817. if (clip.uri) {
  4818. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  4819. }
  4820. else {
  4821. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  4822. promise = this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView);
  4823. }
  4824. clip._objectURL = promise.then(function (data) {
  4825. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  4826. });
  4827. return clip._objectURL;
  4828. };
  4829. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  4830. var _this = this;
  4831. emitter._babylonSounds = emitter._babylonSounds || [];
  4832. if (!emitter._babylonData) {
  4833. var clipPromises = new Array();
  4834. var name_1 = emitter.name || "emitter" + emitter.index;
  4835. var options_1 = {
  4836. loop: false,
  4837. autoplay: false,
  4838. volume: emitter.volume == undefined ? 1 : emitter.volume,
  4839. };
  4840. var _loop_2 = function (i) {
  4841. var clipContext = "#/extensions/" + this_1.name + "/clips";
  4842. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  4843. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  4844. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  4845. sound.refDistance = emitter.refDistance || 1;
  4846. sound.maxDistance = emitter.maxDistance || 256;
  4847. sound.rolloffFactor = emitter.rolloffFactor || 1;
  4848. sound.distanceModel = emitter.distanceModel || 'exponential';
  4849. sound._positionInEmitterSpace = true;
  4850. }));
  4851. };
  4852. var this_1 = this;
  4853. for (var i = 0; i < emitter.clips.length; i++) {
  4854. _loop_2(i);
  4855. }
  4856. var promise = Promise.all(clipPromises).then(function () {
  4857. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  4858. var weightedSound = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  4859. if (emitter.innerAngle) {
  4860. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  4861. }
  4862. if (emitter.outerAngle) {
  4863. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  4864. }
  4865. if (emitter.volume) {
  4866. weightedSound.volume = emitter.volume;
  4867. }
  4868. emitter._babylonData.sound = weightedSound;
  4869. });
  4870. emitter._babylonData = {
  4871. loaded: promise
  4872. };
  4873. }
  4874. return emitter._babylonData.loaded;
  4875. };
  4876. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  4877. switch (action) {
  4878. case "play" /* play */: {
  4879. return function (currentFrame) {
  4880. var frameOffset = (startOffset || 0) + (currentFrame - time);
  4881. sound.play(frameOffset);
  4882. };
  4883. }
  4884. case "stop" /* stop */: {
  4885. return function (currentFrame) {
  4886. sound.stop();
  4887. };
  4888. }
  4889. case "pause" /* pause */: {
  4890. return function (currentFrame) {
  4891. sound.pause();
  4892. };
  4893. }
  4894. default: {
  4895. throw new Error(context + ": Unsupported action " + action);
  4896. }
  4897. }
  4898. };
  4899. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  4900. var _this = this;
  4901. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  4902. return Promise.resolve();
  4903. }
  4904. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  4905. var emitterIndex = event.emitter;
  4906. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("#/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  4907. return this._loadEmitterAsync(context, emitter).then(function () {
  4908. var sound = emitter._babylonData.sound;
  4909. if (sound) {
  4910. var babylonAnimationEvent = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  4911. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  4912. // Make sure all started audio stops when this animation is terminated.
  4913. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  4914. sound.stop();
  4915. });
  4916. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  4917. sound.pause();
  4918. });
  4919. }
  4920. });
  4921. };
  4922. return MSFT_audio_emitter;
  4923. }());
  4924. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  4925. /***/ }),
  4926. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  4927. /*!*****************************************!*\
  4928. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  4929. \*****************************************/
  4930. /*! exports provided: MSFT_lod */
  4931. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4932. "use strict";
  4933. __webpack_require__.r(__webpack_exports__);
  4934. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  4935. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  4936. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  4937. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4938. var NAME = "MSFT_lod";
  4939. /**
  4940. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4941. */
  4942. var MSFT_lod = /** @class */ (function () {
  4943. /** @hidden */
  4944. function MSFT_lod(loader) {
  4945. /**
  4946. * The name of this extension.
  4947. */
  4948. this.name = NAME;
  4949. /**
  4950. * Defines a number that determines the order the extensions are applied.
  4951. */
  4952. this.order = 100;
  4953. /**
  4954. * Maximum number of LODs to load, starting from the lowest LOD.
  4955. */
  4956. this.maxLODsToLoad = 10;
  4957. /**
  4958. * Observable raised when all node LODs of one level are loaded.
  4959. * The event data is the index of the loaded LOD starting from zero.
  4960. * Dispose the loader to cancel the loading of the next level of LODs.
  4961. */
  4962. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4963. /**
  4964. * Observable raised when all material LODs of one level are loaded.
  4965. * The event data is the index of the loaded LOD starting from zero.
  4966. * Dispose the loader to cancel the loading of the next level of LODs.
  4967. */
  4968. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4969. this._nodeIndexLOD = null;
  4970. this._nodeSignalLODs = new Array();
  4971. this._nodePromiseLODs = new Array();
  4972. this._materialIndexLOD = null;
  4973. this._materialSignalLODs = new Array();
  4974. this._materialPromiseLODs = new Array();
  4975. this._indexLOD = null;
  4976. this._bufferLODs = new Array();
  4977. this._loader = loader;
  4978. this.enabled = this._loader.isExtensionUsed(NAME);
  4979. }
  4980. /** @hidden */
  4981. MSFT_lod.prototype.dispose = function () {
  4982. this._disposeUnusedMaterials();
  4983. delete this._loader;
  4984. this._nodeIndexLOD = null;
  4985. this._nodeSignalLODs.length = 0;
  4986. this._nodePromiseLODs.length = 0;
  4987. this._materialIndexLOD = null;
  4988. this._materialSignalLODs.length = 0;
  4989. this._materialPromiseLODs.length = 0;
  4990. this._indexLOD = null;
  4991. this._bufferLODs.length = 0;
  4992. this.onMaterialLODsLoadedObservable.clear();
  4993. this.onNodeLODsLoadedObservable.clear();
  4994. };
  4995. /** @hidden */
  4996. MSFT_lod.prototype.onReady = function () {
  4997. var _this = this;
  4998. var _loop_1 = function (indexLOD) {
  4999. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  5000. if (indexLOD !== 0) {
  5001. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  5002. }
  5003. _this._loader.log("Loaded node LOD " + indexLOD);
  5004. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  5005. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  5006. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  5007. if (_this._nodeSignalLODs[indexLOD]) {
  5008. _this._nodeSignalLODs[indexLOD].resolve();
  5009. }
  5010. }
  5011. });
  5012. this_1._loader._completePromises.push(promise);
  5013. };
  5014. var this_1 = this;
  5015. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  5016. _loop_1(indexLOD);
  5017. }
  5018. var _loop_2 = function (indexLOD) {
  5019. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  5020. if (indexLOD !== 0) {
  5021. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  5022. }
  5023. _this._loader.log("Loaded material LOD " + indexLOD);
  5024. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  5025. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  5026. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  5027. if (_this._materialSignalLODs[indexLOD]) {
  5028. _this._materialSignalLODs[indexLOD].resolve();
  5029. }
  5030. }
  5031. });
  5032. this_2._loader._completePromises.push(promise);
  5033. };
  5034. var this_2 = this;
  5035. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  5036. _loop_2(indexLOD);
  5037. }
  5038. for (var indexLOD = 1; indexLOD < this._bufferLODs.length; indexLOD++) {
  5039. this._loadBufferLOD(indexLOD);
  5040. }
  5041. };
  5042. /** @hidden */
  5043. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  5044. var _this = this;
  5045. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5046. var firstPromise;
  5047. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5048. _this._loader.logOpen("" + extensionContext);
  5049. var _loop_3 = function (indexLOD) {
  5050. var nodeLOD = nodeLODs[indexLOD];
  5051. _this._indexLOD = indexLOD;
  5052. if (indexLOD !== 0) {
  5053. _this._nodeIndexLOD = indexLOD;
  5054. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5055. }
  5056. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5057. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5058. if (indexLOD !== 0) {
  5059. // TODO: should not rely on _babylonTransformNode
  5060. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5061. if (previousNodeLOD._babylonTransformNode) {
  5062. previousNodeLOD._babylonTransformNode.dispose();
  5063. delete previousNodeLOD._babylonTransformNode;
  5064. _this._disposeUnusedMaterials();
  5065. }
  5066. }
  5067. babylonMesh.setEnabled(true);
  5068. return babylonMesh;
  5069. });
  5070. if (indexLOD === 0) {
  5071. firstPromise = promise;
  5072. if (_this._bufferLODs.length !== 0) {
  5073. _this._loadBufferLOD(0);
  5074. }
  5075. }
  5076. else {
  5077. _this._nodeIndexLOD = null;
  5078. }
  5079. _this._indexLOD = null;
  5080. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5081. _this._nodePromiseLODs[indexLOD].push(promise);
  5082. };
  5083. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5084. _loop_3(indexLOD);
  5085. }
  5086. _this._loader.logClose();
  5087. return firstPromise;
  5088. });
  5089. };
  5090. /** @hidden */
  5091. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5092. var _this = this;
  5093. // Don't load material LODs if already loading a node LOD.
  5094. if (this._indexLOD) {
  5095. return null;
  5096. }
  5097. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5098. var firstPromise;
  5099. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5100. _this._loader.logOpen("" + extensionContext);
  5101. var _loop_4 = function (indexLOD) {
  5102. var materialLOD = materialLODs[indexLOD];
  5103. _this._indexLOD = indexLOD;
  5104. if (indexLOD !== 0) {
  5105. _this._materialIndexLOD = indexLOD;
  5106. }
  5107. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5108. if (indexLOD === 0) {
  5109. assign(babylonMaterial);
  5110. }
  5111. }).then(function (babylonMaterial) {
  5112. if (indexLOD !== 0) {
  5113. assign(babylonMaterial);
  5114. // TODO: should not rely on _data
  5115. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5116. if (previousDataLOD[babylonDrawMode]) {
  5117. previousDataLOD[babylonDrawMode].babylonMaterial.dispose();
  5118. delete previousDataLOD[babylonDrawMode];
  5119. }
  5120. }
  5121. return babylonMaterial;
  5122. });
  5123. if (indexLOD === 0) {
  5124. firstPromise = promise;
  5125. if (_this._bufferLODs.length !== 0) {
  5126. _this._loadBufferLOD(0);
  5127. }
  5128. }
  5129. else {
  5130. _this._materialIndexLOD = null;
  5131. }
  5132. _this._indexLOD = null;
  5133. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5134. _this._materialPromiseLODs[indexLOD].push(promise);
  5135. };
  5136. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5137. _loop_4(indexLOD);
  5138. }
  5139. _this._loader.logClose();
  5140. return firstPromise;
  5141. });
  5142. };
  5143. /** @hidden */
  5144. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5145. var _this = this;
  5146. // Defer the loading of uris if loading a material or node LOD.
  5147. if (this._materialIndexLOD !== null) {
  5148. this._loader.log("deferred");
  5149. var previousIndexLOD = this._materialIndexLOD - 1;
  5150. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5151. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5152. return _this._loader.loadUriAsync(context, property, uri);
  5153. });
  5154. }
  5155. else if (this._nodeIndexLOD !== null) {
  5156. this._loader.log("deferred");
  5157. var previousIndexLOD = this._nodeIndexLOD - 1;
  5158. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5159. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5160. return _this._loader.loadUriAsync(context, property, uri);
  5161. });
  5162. }
  5163. return null;
  5164. };
  5165. /** @hidden */
  5166. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5167. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5168. if (!this._loader.bin) {
  5169. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5170. }
  5171. // Non-LOD buffers will be bucketed into the first LOD.
  5172. var indexLOD = this._indexLOD || 0;
  5173. var start = byteOffset;
  5174. var end = start + byteLength - 1;
  5175. var bufferLOD_1 = this._bufferLODs[indexLOD];
  5176. if (bufferLOD_1) {
  5177. bufferLOD_1.start = Math.min(bufferLOD_1.start, start);
  5178. bufferLOD_1.end = Math.max(bufferLOD_1.end, end);
  5179. }
  5180. else {
  5181. bufferLOD_1 = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5182. this._bufferLODs[indexLOD] = bufferLOD_1;
  5183. }
  5184. return bufferLOD_1.loaded.promise.then(function (data) {
  5185. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD_1.start, byteLength);
  5186. });
  5187. }
  5188. return null;
  5189. };
  5190. MSFT_lod.prototype._loadBufferLOD = function (indexLOD) {
  5191. var bufferLOD = this._bufferLODs[indexLOD];
  5192. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5193. bufferLOD.loaded.resolve(data);
  5194. }, function (error) {
  5195. bufferLOD.loaded.reject(error);
  5196. });
  5197. };
  5198. /**
  5199. * Gets an array of LOD properties from lowest to highest.
  5200. */
  5201. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5202. if (this.maxLODsToLoad <= 0) {
  5203. throw new Error("maxLODsToLoad must be greater than zero");
  5204. }
  5205. var properties = new Array();
  5206. for (var i = ids.length - 1; i >= 0; i--) {
  5207. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5208. if (properties.length === this.maxLODsToLoad) {
  5209. return properties;
  5210. }
  5211. }
  5212. properties.push(property);
  5213. return properties;
  5214. };
  5215. MSFT_lod.prototype._disposeUnusedMaterials = function () {
  5216. // TODO: should not rely on _data
  5217. var materials = this._loader.gltf.materials;
  5218. if (materials) {
  5219. for (var _i = 0, materials_1 = materials; _i < materials_1.length; _i++) {
  5220. var material = materials_1[_i];
  5221. if (material._data) {
  5222. var _loop_5 = function (drawMode) {
  5223. var data = material._data[drawMode];
  5224. if (data.babylonMeshes.every(function (babylonMesh) { return babylonMesh.material !== data.babylonMaterial; })) {
  5225. // TODO: check if texture is in use instead of force disposing textures
  5226. data.babylonMaterial.dispose(false, true);
  5227. delete material._data[drawMode];
  5228. }
  5229. };
  5230. for (var drawMode in material._data) {
  5231. _loop_5(drawMode);
  5232. }
  5233. }
  5234. }
  5235. }
  5236. };
  5237. return MSFT_lod;
  5238. }());
  5239. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5240. /***/ }),
  5241. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5242. /*!***************************************************!*\
  5243. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5244. \***************************************************/
  5245. /*! exports provided: MSFT_minecraftMesh */
  5246. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5247. "use strict";
  5248. __webpack_require__.r(__webpack_exports__);
  5249. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5250. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5251. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5252. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5253. var NAME = "MSFT_minecraftMesh";
  5254. /** @hidden */
  5255. var MSFT_minecraftMesh = /** @class */ (function () {
  5256. function MSFT_minecraftMesh(loader) {
  5257. this.name = NAME;
  5258. this._loader = loader;
  5259. this.enabled = this._loader.isExtensionUsed(NAME);
  5260. }
  5261. MSFT_minecraftMesh.prototype.dispose = function () {
  5262. delete this._loader;
  5263. };
  5264. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5265. var _this = this;
  5266. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5267. if (extra) {
  5268. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5269. throw new Error(extraContext + ": Material type not supported");
  5270. }
  5271. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5272. if (babylonMaterial.needAlphaBlending()) {
  5273. babylonMaterial.forceDepthWrite = true;
  5274. babylonMaterial.separateCullingPass = true;
  5275. }
  5276. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5277. babylonMaterial.twoSidedLighting = true;
  5278. return promise;
  5279. }
  5280. return null;
  5281. });
  5282. };
  5283. return MSFT_minecraftMesh;
  5284. }());
  5285. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5286. /***/ }),
  5287. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5288. /*!*************************************************!*\
  5289. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5290. \*************************************************/
  5291. /*! exports provided: MSFT_sRGBFactors */
  5292. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5293. "use strict";
  5294. __webpack_require__.r(__webpack_exports__);
  5295. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5296. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5297. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5298. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5299. var NAME = "MSFT_sRGBFactors";
  5300. /** @hidden */
  5301. var MSFT_sRGBFactors = /** @class */ (function () {
  5302. function MSFT_sRGBFactors(loader) {
  5303. this.name = NAME;
  5304. this._loader = loader;
  5305. this.enabled = this._loader.isExtensionUsed(NAME);
  5306. }
  5307. MSFT_sRGBFactors.prototype.dispose = function () {
  5308. delete this._loader;
  5309. };
  5310. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5311. var _this = this;
  5312. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5313. if (extra) {
  5314. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5315. throw new Error(extraContext + ": Material type not supported");
  5316. }
  5317. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5318. if (!babylonMaterial.albedoTexture) {
  5319. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5320. }
  5321. if (!babylonMaterial.reflectivityTexture) {
  5322. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5323. }
  5324. return promise;
  5325. }
  5326. return null;
  5327. });
  5328. };
  5329. return MSFT_sRGBFactors;
  5330. }());
  5331. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5332. /***/ }),
  5333. /***/ "./glTF/2.0/Extensions/index.ts":
  5334. /*!**************************************!*\
  5335. !*** ./glTF/2.0/Extensions/index.ts ***!
  5336. \**************************************/
  5337. /*! 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 */
  5338. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5339. "use strict";
  5340. __webpack_require__.r(__webpack_exports__);
  5341. /* 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");
  5342. /* 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"]; });
  5343. /* 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");
  5344. /* 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"]; });
  5345. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5346. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  5347. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5348. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  5349. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5350. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  5351. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5352. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_clearcoat"]; });
  5353. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5354. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_sheen"]; });
  5355. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5356. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_specular"]; });
  5357. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  5358. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_8__["KHR_mesh_quantization"]; });
  5359. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5360. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_9__["KHR_texture_transform"]; });
  5361. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5362. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_10__["MSFT_audio_emitter"]; });
  5363. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5364. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_11__["MSFT_lod"]; });
  5365. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5366. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_12__["MSFT_minecraftMesh"]; });
  5367. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5368. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_13__["MSFT_sRGBFactors"]; });
  5369. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5370. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_14__["ExtrasAsMetadata"]; });
  5371. /***/ }),
  5372. /***/ "./glTF/2.0/glTFLoader.ts":
  5373. /*!********************************!*\
  5374. !*** ./glTF/2.0/glTFLoader.ts ***!
  5375. \********************************/
  5376. /*! exports provided: ArrayItem, GLTFLoader */
  5377. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5378. "use strict";
  5379. __webpack_require__.r(__webpack_exports__);
  5380. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5381. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5382. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  5383. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5384. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5385. /**
  5386. * Helper class for working with arrays when loading the glTF asset
  5387. */
  5388. var ArrayItem = /** @class */ (function () {
  5389. function ArrayItem() {
  5390. }
  5391. /**
  5392. * Gets an item from the given array.
  5393. * @param context The context when loading the asset
  5394. * @param array The array to get the item from
  5395. * @param index The index to the array
  5396. * @returns The array item
  5397. */
  5398. ArrayItem.Get = function (context, array, index) {
  5399. if (!array || index == undefined || !array[index]) {
  5400. throw new Error(context + ": Failed to find index (" + index + ")");
  5401. }
  5402. return array[index];
  5403. };
  5404. /**
  5405. * Assign an `index` field to each item of the given array.
  5406. * @param array The array of items
  5407. */
  5408. ArrayItem.Assign = function (array) {
  5409. if (array) {
  5410. for (var index = 0; index < array.length; index++) {
  5411. array[index].index = index;
  5412. }
  5413. }
  5414. };
  5415. return ArrayItem;
  5416. }());
  5417. /**
  5418. * The glTF 2.0 loader
  5419. */
  5420. var GLTFLoader = /** @class */ (function () {
  5421. /** @hidden */
  5422. function GLTFLoader(parent) {
  5423. /** @hidden */
  5424. this._completePromises = new Array();
  5425. this._disposed = false;
  5426. this._state = null;
  5427. this._extensions = new Array();
  5428. this._defaultBabylonMaterialData = {};
  5429. this._requests = new Array();
  5430. this._parent = parent;
  5431. }
  5432. /**
  5433. * Registers a loader extension.
  5434. * @param name The name of the loader extension.
  5435. * @param factory The factory function that creates the loader extension.
  5436. */
  5437. GLTFLoader.RegisterExtension = function (name, factory) {
  5438. if (GLTFLoader.UnregisterExtension(name)) {
  5439. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  5440. }
  5441. GLTFLoader._RegisteredExtensions[name] = {
  5442. factory: factory
  5443. };
  5444. };
  5445. /**
  5446. * Unregisters a loader extension.
  5447. * @param name The name of the loader extension.
  5448. * @returns A boolean indicating whether the extension has been unregistered
  5449. */
  5450. GLTFLoader.UnregisterExtension = function (name) {
  5451. if (!GLTFLoader._RegisteredExtensions[name]) {
  5452. return false;
  5453. }
  5454. delete GLTFLoader._RegisteredExtensions[name];
  5455. return true;
  5456. };
  5457. Object.defineProperty(GLTFLoader.prototype, "state", {
  5458. /**
  5459. * Gets the loader state.
  5460. */
  5461. get: function () {
  5462. return this._state;
  5463. },
  5464. enumerable: true,
  5465. configurable: true
  5466. });
  5467. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  5468. /**
  5469. * The object that represents the glTF JSON.
  5470. */
  5471. get: function () {
  5472. return this._gltf;
  5473. },
  5474. enumerable: true,
  5475. configurable: true
  5476. });
  5477. Object.defineProperty(GLTFLoader.prototype, "bin", {
  5478. /**
  5479. * The BIN chunk of a binary glTF.
  5480. */
  5481. get: function () {
  5482. return this._bin;
  5483. },
  5484. enumerable: true,
  5485. configurable: true
  5486. });
  5487. Object.defineProperty(GLTFLoader.prototype, "parent", {
  5488. /**
  5489. * The parent file loader.
  5490. */
  5491. get: function () {
  5492. return this._parent;
  5493. },
  5494. enumerable: true,
  5495. configurable: true
  5496. });
  5497. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  5498. /**
  5499. * The Babylon scene when loading the asset.
  5500. */
  5501. get: function () {
  5502. return this._babylonScene;
  5503. },
  5504. enumerable: true,
  5505. configurable: true
  5506. });
  5507. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  5508. /**
  5509. * The root Babylon mesh when loading the asset.
  5510. */
  5511. get: function () {
  5512. return this._rootBabylonMesh;
  5513. },
  5514. enumerable: true,
  5515. configurable: true
  5516. });
  5517. /** @hidden */
  5518. GLTFLoader.prototype.dispose = function () {
  5519. if (this._disposed) {
  5520. return;
  5521. }
  5522. this._disposed = true;
  5523. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  5524. var request = _a[_i];
  5525. request.abort();
  5526. }
  5527. this._requests.length = 0;
  5528. this._completePromises.length = 0;
  5529. for (var name_1 in this._extensions) {
  5530. var extension = this._extensions[name_1];
  5531. extension.dispose && extension.dispose();
  5532. delete this._extensions[name_1];
  5533. }
  5534. delete this._gltf;
  5535. delete this._babylonScene;
  5536. delete this._rootBabylonMesh;
  5537. delete this._progressCallback;
  5538. this._parent._clear();
  5539. };
  5540. /** @hidden */
  5541. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  5542. var _this = this;
  5543. return Promise.resolve().then(function () {
  5544. _this._babylonScene = scene;
  5545. _this._rootUrl = rootUrl;
  5546. _this._fileName = fileName || "scene";
  5547. _this._progressCallback = onProgress;
  5548. _this._loadData(data);
  5549. var nodes = null;
  5550. if (meshesNames) {
  5551. var nodeMap_1 = {};
  5552. if (_this._gltf.nodes) {
  5553. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  5554. var node = _a[_i];
  5555. if (node.name) {
  5556. nodeMap_1[node.name] = node.index;
  5557. }
  5558. }
  5559. }
  5560. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  5561. nodes = names.map(function (name) {
  5562. var node = nodeMap_1[name];
  5563. if (node === undefined) {
  5564. throw new Error("Failed to find node '" + name + "'");
  5565. }
  5566. return node;
  5567. });
  5568. }
  5569. return _this._loadAsync(nodes, function () {
  5570. return {
  5571. meshes: _this._getMeshes(),
  5572. particleSystems: [],
  5573. skeletons: _this._getSkeletons(),
  5574. animationGroups: _this._getAnimationGroups()
  5575. };
  5576. });
  5577. });
  5578. };
  5579. /** @hidden */
  5580. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  5581. var _this = this;
  5582. return Promise.resolve().then(function () {
  5583. _this._babylonScene = scene;
  5584. _this._rootUrl = rootUrl;
  5585. _this._fileName = fileName || "scene";
  5586. _this._progressCallback = onProgress;
  5587. _this._loadData(data);
  5588. return _this._loadAsync(null, function () { return undefined; });
  5589. });
  5590. };
  5591. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  5592. var _this = this;
  5593. return Promise.resolve().then(function () {
  5594. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  5595. _this._loadExtensions();
  5596. _this._checkExtensions();
  5597. 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];
  5598. 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];
  5599. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  5600. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  5601. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  5602. _this._extensionsOnLoading();
  5603. var promises = new Array();
  5604. // Block the marking of materials dirty until the scene is loaded.
  5605. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  5606. _this._babylonScene.blockMaterialDirtyMechanism = true;
  5607. if (nodes) {
  5608. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  5609. }
  5610. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  5611. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  5612. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  5613. }
  5614. // Restore the blocking of material dirty.
  5615. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  5616. if (_this._parent.compileMaterials) {
  5617. promises.push(_this._compileMaterialsAsync());
  5618. }
  5619. if (_this._parent.compileShadowGenerators) {
  5620. promises.push(_this._compileShadowGeneratorsAsync());
  5621. }
  5622. var resultPromise = Promise.all(promises).then(function () {
  5623. if (_this._rootBabylonMesh) {
  5624. _this._rootBabylonMesh.setEnabled(true);
  5625. }
  5626. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  5627. _this._extensionsOnReady();
  5628. _this._startAnimations();
  5629. return resultFunc();
  5630. });
  5631. resultPromise.then(function () {
  5632. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  5633. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  5634. if (!_this._disposed) {
  5635. Promise.all(_this._completePromises).then(function () {
  5636. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  5637. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  5638. _this._parent.onCompleteObservable.notifyObservers(undefined);
  5639. _this._parent.onCompleteObservable.clear();
  5640. _this.dispose();
  5641. }, function (error) {
  5642. _this._parent.onErrorObservable.notifyObservers(error);
  5643. _this._parent.onErrorObservable.clear();
  5644. _this.dispose();
  5645. });
  5646. }
  5647. });
  5648. });
  5649. return resultPromise;
  5650. }, function (error) {
  5651. if (!_this._disposed) {
  5652. _this._parent.onErrorObservable.notifyObservers(error);
  5653. _this._parent.onErrorObservable.clear();
  5654. _this.dispose();
  5655. }
  5656. throw error;
  5657. });
  5658. };
  5659. GLTFLoader.prototype._loadData = function (data) {
  5660. this._gltf = data.json;
  5661. this._setupData();
  5662. if (data.bin) {
  5663. var buffers = this._gltf.buffers;
  5664. if (buffers && buffers[0] && !buffers[0].uri) {
  5665. var binaryBuffer = buffers[0];
  5666. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  5667. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  5668. }
  5669. this._bin = data.bin;
  5670. }
  5671. else {
  5672. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  5673. }
  5674. }
  5675. };
  5676. GLTFLoader.prototype._setupData = function () {
  5677. ArrayItem.Assign(this._gltf.accessors);
  5678. ArrayItem.Assign(this._gltf.animations);
  5679. ArrayItem.Assign(this._gltf.buffers);
  5680. ArrayItem.Assign(this._gltf.bufferViews);
  5681. ArrayItem.Assign(this._gltf.cameras);
  5682. ArrayItem.Assign(this._gltf.images);
  5683. ArrayItem.Assign(this._gltf.materials);
  5684. ArrayItem.Assign(this._gltf.meshes);
  5685. ArrayItem.Assign(this._gltf.nodes);
  5686. ArrayItem.Assign(this._gltf.samplers);
  5687. ArrayItem.Assign(this._gltf.scenes);
  5688. ArrayItem.Assign(this._gltf.skins);
  5689. ArrayItem.Assign(this._gltf.textures);
  5690. if (this._gltf.nodes) {
  5691. var nodeParents = {};
  5692. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  5693. var node = _a[_i];
  5694. if (node.children) {
  5695. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  5696. var index = _c[_b];
  5697. nodeParents[index] = node.index;
  5698. }
  5699. }
  5700. }
  5701. var rootNode = this._createRootNode();
  5702. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  5703. var node = _e[_d];
  5704. var parentIndex = nodeParents[node.index];
  5705. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  5706. }
  5707. }
  5708. };
  5709. GLTFLoader.prototype._loadExtensions = function () {
  5710. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  5711. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  5712. if (extension.name !== name_2) {
  5713. 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);
  5714. }
  5715. this._extensions.push(extension);
  5716. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  5717. }
  5718. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  5719. this._parent.onExtensionLoadedObservable.clear();
  5720. };
  5721. GLTFLoader.prototype._checkExtensions = function () {
  5722. if (this._gltf.extensionsRequired) {
  5723. var _loop_1 = function (name_3) {
  5724. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  5725. if (!available) {
  5726. throw new Error("Require extension " + name_3 + " is not available");
  5727. }
  5728. };
  5729. var this_1 = this;
  5730. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  5731. var name_3 = _a[_i];
  5732. _loop_1(name_3);
  5733. }
  5734. }
  5735. };
  5736. GLTFLoader.prototype._setState = function (state) {
  5737. this._state = state;
  5738. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  5739. };
  5740. GLTFLoader.prototype._createRootNode = function () {
  5741. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  5742. this._rootBabylonMesh.setEnabled(false);
  5743. var rootNode = {
  5744. _babylonTransformNode: this._rootBabylonMesh,
  5745. index: -1
  5746. };
  5747. switch (this._parent.coordinateSystemMode) {
  5748. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  5749. if (!this._babylonScene.useRightHandedSystem) {
  5750. rootNode.rotation = [0, 1, 0, 0];
  5751. rootNode.scale = [1, 1, -1];
  5752. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  5753. }
  5754. break;
  5755. }
  5756. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  5757. this._babylonScene.useRightHandedSystem = true;
  5758. break;
  5759. }
  5760. default: {
  5761. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  5762. }
  5763. }
  5764. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  5765. return rootNode;
  5766. };
  5767. /**
  5768. * Loads a glTF scene.
  5769. * @param context The context when loading the asset
  5770. * @param scene The glTF scene property
  5771. * @returns A promise that resolves when the load is complete
  5772. */
  5773. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  5774. var _this = this;
  5775. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  5776. if (extensionPromise) {
  5777. return extensionPromise;
  5778. }
  5779. var promises = new Array();
  5780. this.logOpen(context + " " + (scene.name || ""));
  5781. if (scene.nodes) {
  5782. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  5783. var index = _a[_i];
  5784. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  5785. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  5786. babylonMesh.parent = _this._rootBabylonMesh;
  5787. }));
  5788. }
  5789. }
  5790. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  5791. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  5792. if (this._gltf.nodes) {
  5793. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  5794. var node = _c[_b];
  5795. if (node._babylonTransformNode && node._babylonBones) {
  5796. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  5797. var babylonBone = _e[_d];
  5798. babylonBone.linkTransformNode(node._babylonTransformNode);
  5799. }
  5800. }
  5801. }
  5802. }
  5803. promises.push(this._loadAnimationsAsync());
  5804. this.logClose();
  5805. return Promise.all(promises).then(function () { });
  5806. };
  5807. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  5808. if (node._primitiveBabylonMeshes) {
  5809. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  5810. var babylonMesh = _a[_i];
  5811. callback(babylonMesh);
  5812. }
  5813. }
  5814. };
  5815. GLTFLoader.prototype._getMeshes = function () {
  5816. var meshes = new Array();
  5817. // Root mesh is always first.
  5818. meshes.push(this._rootBabylonMesh);
  5819. var nodes = this._gltf.nodes;
  5820. if (nodes) {
  5821. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  5822. var node = nodes_1[_i];
  5823. this._forEachPrimitive(node, function (babylonMesh) {
  5824. meshes.push(babylonMesh);
  5825. });
  5826. }
  5827. }
  5828. return meshes;
  5829. };
  5830. GLTFLoader.prototype._getSkeletons = function () {
  5831. var skeletons = new Array();
  5832. var skins = this._gltf.skins;
  5833. if (skins) {
  5834. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  5835. var skin = skins_1[_i];
  5836. if (skin._data) {
  5837. skeletons.push(skin._data.babylonSkeleton);
  5838. }
  5839. }
  5840. }
  5841. return skeletons;
  5842. };
  5843. GLTFLoader.prototype._getAnimationGroups = function () {
  5844. var animationGroups = new Array();
  5845. var animations = this._gltf.animations;
  5846. if (animations) {
  5847. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  5848. var animation = animations_1[_i];
  5849. if (animation._babylonAnimationGroup) {
  5850. animationGroups.push(animation._babylonAnimationGroup);
  5851. }
  5852. }
  5853. }
  5854. return animationGroups;
  5855. };
  5856. GLTFLoader.prototype._startAnimations = function () {
  5857. switch (this._parent.animationStartMode) {
  5858. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  5859. // do nothing
  5860. break;
  5861. }
  5862. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  5863. var babylonAnimationGroups = this._getAnimationGroups();
  5864. if (babylonAnimationGroups.length !== 0) {
  5865. babylonAnimationGroups[0].start(true);
  5866. }
  5867. break;
  5868. }
  5869. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  5870. var babylonAnimationGroups = this._getAnimationGroups();
  5871. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  5872. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  5873. babylonAnimationGroup.start(true);
  5874. }
  5875. break;
  5876. }
  5877. default: {
  5878. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  5879. return;
  5880. }
  5881. }
  5882. };
  5883. /**
  5884. * Loads a glTF node.
  5885. * @param context The context when loading the asset
  5886. * @param node The glTF node property
  5887. * @param assign A function called synchronously after parsing the glTF properties
  5888. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  5889. */
  5890. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  5891. var _this = this;
  5892. if (assign === void 0) { assign = function () { }; }
  5893. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  5894. if (extensionPromise) {
  5895. return extensionPromise;
  5896. }
  5897. if (node._babylonTransformNode) {
  5898. throw new Error(context + ": Invalid recursive node hierarchy");
  5899. }
  5900. var promises = new Array();
  5901. this.logOpen(context + " " + (node.name || ""));
  5902. var loadNode = function (babylonTransformNode) {
  5903. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  5904. GLTFLoader._LoadTransform(node, babylonTransformNode);
  5905. if (node.camera != undefined) {
  5906. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  5907. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  5908. babylonCamera.parent = babylonTransformNode;
  5909. }));
  5910. }
  5911. if (node.children) {
  5912. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  5913. var index = _a[_i];
  5914. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  5915. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  5916. childBabylonMesh.parent = babylonTransformNode;
  5917. }));
  5918. }
  5919. }
  5920. assign(babylonTransformNode);
  5921. };
  5922. if (node.mesh == undefined) {
  5923. var nodeName = node.name || "node" + node.index;
  5924. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  5925. loadNode(node._babylonTransformNode);
  5926. }
  5927. else {
  5928. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  5929. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  5930. }
  5931. this.logClose();
  5932. return Promise.all(promises).then(function () {
  5933. _this._forEachPrimitive(node, function (babylonMesh) {
  5934. babylonMesh.refreshBoundingInfo(true);
  5935. });
  5936. return node._babylonTransformNode;
  5937. });
  5938. };
  5939. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  5940. var primitives = mesh.primitives;
  5941. if (!primitives || !primitives.length) {
  5942. throw new Error(context + ": Primitives are missing");
  5943. }
  5944. if (primitives[0].index == undefined) {
  5945. ArrayItem.Assign(primitives);
  5946. }
  5947. var promises = new Array();
  5948. this.logOpen(context + " " + (mesh.name || ""));
  5949. var name = node.name || "node" + node.index;
  5950. if (primitives.length === 1) {
  5951. var primitive = mesh.primitives[0];
  5952. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  5953. node._babylonTransformNode = babylonMesh;
  5954. node._primitiveBabylonMeshes = [babylonMesh];
  5955. }));
  5956. }
  5957. else {
  5958. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  5959. node._primitiveBabylonMeshes = [];
  5960. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  5961. var primitive = primitives_1[_i];
  5962. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  5963. babylonMesh.parent = node._babylonTransformNode;
  5964. node._primitiveBabylonMeshes.push(babylonMesh);
  5965. }));
  5966. }
  5967. }
  5968. if (node.skin != undefined) {
  5969. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  5970. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  5971. }
  5972. assign(node._babylonTransformNode);
  5973. this.logClose();
  5974. return Promise.all(promises).then(function () {
  5975. return node._babylonTransformNode;
  5976. });
  5977. };
  5978. /**
  5979. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  5980. * @param context The context when loading the asset
  5981. * @param name The mesh name when loading the asset
  5982. * @param node The glTF node when loading the asset
  5983. * @param mesh The glTF mesh when loading the asset
  5984. * @param primitive The glTF mesh primitive property
  5985. * @param assign A function called synchronously after parsing the glTF properties
  5986. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  5987. */
  5988. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  5989. var _this = this;
  5990. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  5991. if (extensionPromise) {
  5992. return extensionPromise;
  5993. }
  5994. this.logOpen("" + context);
  5995. var shouldInstance = this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  5996. var babylonAbstractMesh;
  5997. var promise;
  5998. if (shouldInstance && primitive._instanceData) {
  5999. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  6000. promise = primitive._instanceData.promise;
  6001. }
  6002. else {
  6003. var promises = new Array();
  6004. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  6005. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  6006. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  6007. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  6008. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  6009. babylonGeometry.applyToMesh(babylonMesh_1);
  6010. });
  6011. }));
  6012. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  6013. if (primitive.material == undefined) {
  6014. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  6015. if (!babylonMaterial) {
  6016. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  6017. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6018. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  6019. }
  6020. babylonMesh_1.material = babylonMaterial;
  6021. }
  6022. else {
  6023. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  6024. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  6025. babylonMesh_1.material = babylonMaterial;
  6026. }));
  6027. }
  6028. promise = Promise.all(promises);
  6029. if (shouldInstance) {
  6030. primitive._instanceData = {
  6031. babylonSourceMesh: babylonMesh_1,
  6032. promise: promise
  6033. };
  6034. }
  6035. babylonAbstractMesh = babylonMesh_1;
  6036. }
  6037. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  6038. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  6039. assign(babylonAbstractMesh);
  6040. this.logClose();
  6041. return promise.then(function () {
  6042. return babylonAbstractMesh;
  6043. });
  6044. };
  6045. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  6046. var _this = this;
  6047. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  6048. if (extensionPromise) {
  6049. return extensionPromise;
  6050. }
  6051. var attributes = primitive.attributes;
  6052. if (!attributes) {
  6053. throw new Error(context + ": Attributes are missing");
  6054. }
  6055. var promises = new Array();
  6056. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  6057. if (primitive.indices == undefined) {
  6058. babylonMesh.isUnIndexed = true;
  6059. }
  6060. else {
  6061. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6062. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6063. babylonGeometry.setIndices(data);
  6064. }));
  6065. }
  6066. var loadAttribute = function (attribute, kind, callback) {
  6067. if (attributes[attribute] == undefined) {
  6068. return;
  6069. }
  6070. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6071. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6072. babylonMesh._delayInfo.push(kind);
  6073. }
  6074. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6075. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6076. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6077. }));
  6078. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6079. babylonMesh.numBoneInfluencers = 8;
  6080. }
  6081. if (callback) {
  6082. callback(accessor);
  6083. }
  6084. };
  6085. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6086. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6087. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6088. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6089. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6090. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6091. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6092. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  6093. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  6094. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6095. if (accessor.type === "VEC4" /* VEC4 */) {
  6096. babylonMesh.hasVertexAlpha = true;
  6097. }
  6098. });
  6099. return Promise.all(promises).then(function () {
  6100. return babylonGeometry;
  6101. });
  6102. };
  6103. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6104. if (!primitive.targets) {
  6105. return;
  6106. }
  6107. if (node._numMorphTargets == undefined) {
  6108. node._numMorphTargets = primitive.targets.length;
  6109. }
  6110. else if (primitive.targets.length !== node._numMorphTargets) {
  6111. throw new Error(context + ": Primitives do not have the same number of targets");
  6112. }
  6113. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6114. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6115. for (var index = 0; index < primitive.targets.length; index++) {
  6116. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6117. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6118. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6119. // TODO: tell the target whether it has positions, normals, tangents
  6120. }
  6121. };
  6122. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6123. if (!primitive.targets) {
  6124. return Promise.resolve();
  6125. }
  6126. var promises = new Array();
  6127. var morphTargetManager = babylonMesh.morphTargetManager;
  6128. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6129. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6130. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6131. }
  6132. return Promise.all(promises).then(function () { });
  6133. };
  6134. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6135. var _this = this;
  6136. var promises = new Array();
  6137. var loadAttribute = function (attribute, kind, setData) {
  6138. if (attributes[attribute] == undefined) {
  6139. return;
  6140. }
  6141. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6142. if (!babylonVertexBuffer) {
  6143. return;
  6144. }
  6145. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6146. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6147. setData(babylonVertexBuffer, data);
  6148. }));
  6149. };
  6150. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6151. var positions = new Float32Array(data.length);
  6152. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6153. positions[index] = data[index] + value;
  6154. });
  6155. babylonMorphTarget.setPositions(positions);
  6156. });
  6157. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6158. var normals = new Float32Array(data.length);
  6159. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6160. normals[index] = data[index] + value;
  6161. });
  6162. babylonMorphTarget.setNormals(normals);
  6163. });
  6164. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6165. var tangents = new Float32Array(data.length / 3 * 4);
  6166. var dataIndex = 0;
  6167. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6168. // Tangent data for morph targets is stored as xyz delta.
  6169. // The vertexData.tangent is stored as xyzw.
  6170. // So we need to skip every fourth vertexData.tangent.
  6171. if (((index + 1) % 4) !== 0) {
  6172. tangents[dataIndex] = data[dataIndex] + value;
  6173. dataIndex++;
  6174. }
  6175. });
  6176. babylonMorphTarget.setTangents(tangents);
  6177. });
  6178. return Promise.all(promises).then(function () { });
  6179. };
  6180. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6181. // Ignore the TRS of skinned nodes.
  6182. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6183. if (node.skin != undefined) {
  6184. return;
  6185. }
  6186. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6187. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6188. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6189. if (node.matrix) {
  6190. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6191. matrix.decompose(scaling, rotation, position);
  6192. }
  6193. else {
  6194. if (node.translation) {
  6195. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6196. }
  6197. if (node.rotation) {
  6198. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6199. }
  6200. if (node.scale) {
  6201. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6202. }
  6203. }
  6204. babylonNode.position = position;
  6205. babylonNode.rotationQuaternion = rotation;
  6206. babylonNode.scaling = scaling;
  6207. };
  6208. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6209. var _this = this;
  6210. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6211. if (extensionPromise) {
  6212. return extensionPromise;
  6213. }
  6214. var assignSkeleton = function (skeleton) {
  6215. _this._forEachPrimitive(node, function (babylonMesh) {
  6216. babylonMesh.skeleton = skeleton;
  6217. });
  6218. };
  6219. if (skin._data) {
  6220. assignSkeleton(skin._data.babylonSkeleton);
  6221. return skin._data.promise;
  6222. }
  6223. var skeletonId = "skeleton" + skin.index;
  6224. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6225. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6226. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6227. this._loadBones(context, skin, babylonSkeleton);
  6228. assignSkeleton(babylonSkeleton);
  6229. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6230. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6231. });
  6232. skin._data = {
  6233. babylonSkeleton: babylonSkeleton,
  6234. promise: promise
  6235. };
  6236. return promise;
  6237. };
  6238. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6239. var babylonBones = {};
  6240. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6241. var index = _a[_i];
  6242. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6243. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6244. }
  6245. };
  6246. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6247. var babylonBone = babylonBones[node.index];
  6248. if (babylonBone) {
  6249. return babylonBone;
  6250. }
  6251. var babylonParentBone = null;
  6252. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6253. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6254. }
  6255. var boneIndex = skin.joints.indexOf(node.index);
  6256. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6257. babylonBones[node.index] = babylonBone;
  6258. node._babylonBones = node._babylonBones || [];
  6259. node._babylonBones.push(babylonBone);
  6260. return babylonBone;
  6261. };
  6262. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6263. if (skin.inverseBindMatrices == undefined) {
  6264. return Promise.resolve(null);
  6265. }
  6266. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6267. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6268. };
  6269. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6270. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6271. var babylonBone = _a[_i];
  6272. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6273. var boneIndex = babylonBone._index;
  6274. if (inverseBindMatricesData && boneIndex !== -1) {
  6275. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6276. baseMatrix.invertToRef(baseMatrix);
  6277. }
  6278. var babylonParentBone = babylonBone.getParent();
  6279. if (babylonParentBone) {
  6280. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6281. }
  6282. babylonBone.updateMatrix(baseMatrix, false, false);
  6283. babylonBone._updateDifferenceMatrix(undefined, false);
  6284. }
  6285. };
  6286. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6287. return node.matrix ?
  6288. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6289. 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());
  6290. };
  6291. /**
  6292. * Loads a glTF camera.
  6293. * @param context The context when loading the asset
  6294. * @param camera The glTF camera property
  6295. * @param assign A function called synchronously after parsing the glTF properties
  6296. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6297. */
  6298. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6299. if (assign === void 0) { assign = function () { }; }
  6300. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6301. if (extensionPromise) {
  6302. return extensionPromise;
  6303. }
  6304. var promises = new Array();
  6305. this.logOpen(context + " " + (camera.name || ""));
  6306. 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);
  6307. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6308. switch (camera.type) {
  6309. case "perspective" /* PERSPECTIVE */: {
  6310. var perspective = camera.perspective;
  6311. if (!perspective) {
  6312. throw new Error(context + ": Camera perspective properties are missing");
  6313. }
  6314. babylonCamera.fov = perspective.yfov;
  6315. babylonCamera.minZ = perspective.znear;
  6316. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6317. break;
  6318. }
  6319. case "orthographic" /* ORTHOGRAPHIC */: {
  6320. if (!camera.orthographic) {
  6321. throw new Error(context + ": Camera orthographic properties are missing");
  6322. }
  6323. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6324. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6325. babylonCamera.orthoRight = camera.orthographic.xmag;
  6326. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6327. babylonCamera.orthoTop = camera.orthographic.ymag;
  6328. babylonCamera.minZ = camera.orthographic.znear;
  6329. babylonCamera.maxZ = camera.orthographic.zfar;
  6330. break;
  6331. }
  6332. default: {
  6333. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6334. }
  6335. }
  6336. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6337. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6338. assign(babylonCamera);
  6339. return Promise.all(promises).then(function () {
  6340. return babylonCamera;
  6341. });
  6342. };
  6343. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6344. var animations = this._gltf.animations;
  6345. if (!animations) {
  6346. return Promise.resolve();
  6347. }
  6348. var promises = new Array();
  6349. for (var index = 0; index < animations.length; index++) {
  6350. var animation = animations[index];
  6351. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6352. }
  6353. return Promise.all(promises).then(function () { });
  6354. };
  6355. /**
  6356. * Loads a glTF animation.
  6357. * @param context The context when loading the asset
  6358. * @param animation The glTF animation property
  6359. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6360. */
  6361. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6362. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6363. if (promise) {
  6364. return promise;
  6365. }
  6366. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6367. animation._babylonAnimationGroup = babylonAnimationGroup;
  6368. var promises = new Array();
  6369. ArrayItem.Assign(animation.channels);
  6370. ArrayItem.Assign(animation.samplers);
  6371. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6372. var channel = _a[_i];
  6373. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6374. }
  6375. return Promise.all(promises).then(function () {
  6376. babylonAnimationGroup.normalize(0);
  6377. return babylonAnimationGroup;
  6378. });
  6379. };
  6380. /**
  6381. * @hidden Loads a glTF animation channel.
  6382. * @param context The context when loading the asset
  6383. * @param animationContext The context of the animation when loading the asset
  6384. * @param animation The glTF animation property
  6385. * @param channel The glTF animation channel property
  6386. * @param babylonAnimationGroup The babylon animation group property
  6387. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6388. * @returns A void promise when the channel load is complete
  6389. */
  6390. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6391. var _this = this;
  6392. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6393. if (channel.target.node == undefined) {
  6394. return Promise.resolve();
  6395. }
  6396. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6397. // Ignore animations that have no animation targets.
  6398. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6399. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6400. return Promise.resolve();
  6401. }
  6402. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6403. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6404. var targetPath;
  6405. var animationType;
  6406. switch (channel.target.path) {
  6407. case "translation" /* TRANSLATION */: {
  6408. targetPath = "position";
  6409. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6410. break;
  6411. }
  6412. case "rotation" /* ROTATION */: {
  6413. targetPath = "rotationQuaternion";
  6414. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  6415. break;
  6416. }
  6417. case "scale" /* SCALE */: {
  6418. targetPath = "scaling";
  6419. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6420. break;
  6421. }
  6422. case "weights" /* WEIGHTS */: {
  6423. targetPath = "influence";
  6424. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  6425. break;
  6426. }
  6427. default: {
  6428. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  6429. }
  6430. }
  6431. var outputBufferOffset = 0;
  6432. var getNextOutputValue;
  6433. switch (targetPath) {
  6434. case "position": {
  6435. getNextOutputValue = function () {
  6436. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6437. outputBufferOffset += 3;
  6438. return value;
  6439. };
  6440. break;
  6441. }
  6442. case "rotationQuaternion": {
  6443. getNextOutputValue = function () {
  6444. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  6445. outputBufferOffset += 4;
  6446. return value;
  6447. };
  6448. break;
  6449. }
  6450. case "scaling": {
  6451. getNextOutputValue = function () {
  6452. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6453. outputBufferOffset += 3;
  6454. return value;
  6455. };
  6456. break;
  6457. }
  6458. case "influence": {
  6459. getNextOutputValue = function () {
  6460. var value = new Array(targetNode._numMorphTargets);
  6461. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  6462. value[i] = data.output[outputBufferOffset++];
  6463. }
  6464. return value;
  6465. };
  6466. break;
  6467. }
  6468. }
  6469. var getNextKey;
  6470. switch (data.interpolation) {
  6471. case "STEP" /* STEP */: {
  6472. getNextKey = function (frameIndex) { return ({
  6473. frame: data.input[frameIndex],
  6474. value: getNextOutputValue(),
  6475. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  6476. }); };
  6477. break;
  6478. }
  6479. case "LINEAR" /* LINEAR */: {
  6480. getNextKey = function (frameIndex) { return ({
  6481. frame: data.input[frameIndex],
  6482. value: getNextOutputValue()
  6483. }); };
  6484. break;
  6485. }
  6486. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6487. getNextKey = function (frameIndex) { return ({
  6488. frame: data.input[frameIndex],
  6489. inTangent: getNextOutputValue(),
  6490. value: getNextOutputValue(),
  6491. outTangent: getNextOutputValue()
  6492. }); };
  6493. break;
  6494. }
  6495. }
  6496. var keys = new Array(data.input.length);
  6497. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  6498. keys[frameIndex] = getNextKey(frameIndex);
  6499. }
  6500. if (targetPath === "influence") {
  6501. var _loop_2 = function (targetIndex) {
  6502. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6503. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6504. babylonAnimation.setKeys(keys.map(function (key) { return ({
  6505. frame: key.frame,
  6506. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  6507. value: key.value[targetIndex],
  6508. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  6509. }); }));
  6510. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  6511. var babylonMesh = babylonAbstractMesh;
  6512. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  6513. var babylonAnimationClone = babylonAnimation.clone();
  6514. morphTarget.animations.push(babylonAnimationClone);
  6515. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  6516. });
  6517. };
  6518. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  6519. _loop_2(targetIndex);
  6520. }
  6521. }
  6522. else {
  6523. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6524. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6525. babylonAnimation.setKeys(keys);
  6526. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  6527. animationTargetOverride.animations.push(babylonAnimation);
  6528. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  6529. }
  6530. else {
  6531. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  6532. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  6533. }
  6534. }
  6535. });
  6536. };
  6537. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  6538. if (sampler._data) {
  6539. return sampler._data;
  6540. }
  6541. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  6542. switch (interpolation) {
  6543. case "STEP" /* STEP */:
  6544. case "LINEAR" /* LINEAR */:
  6545. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6546. break;
  6547. }
  6548. default: {
  6549. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  6550. }
  6551. }
  6552. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  6553. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  6554. sampler._data = Promise.all([
  6555. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  6556. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  6557. ]).then(function (_a) {
  6558. var inputData = _a[0], outputData = _a[1];
  6559. return {
  6560. input: inputData,
  6561. interpolation: interpolation,
  6562. output: outputData,
  6563. };
  6564. });
  6565. return sampler._data;
  6566. };
  6567. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6568. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  6569. if (extensionPromise) {
  6570. return extensionPromise;
  6571. }
  6572. if (!buffer._data) {
  6573. if (buffer.uri) {
  6574. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  6575. }
  6576. else {
  6577. if (!this._bin) {
  6578. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6579. }
  6580. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  6581. }
  6582. }
  6583. return buffer._data.then(function (data) {
  6584. try {
  6585. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  6586. }
  6587. catch (e) {
  6588. throw new Error(context + ": " + e.message);
  6589. }
  6590. });
  6591. };
  6592. /**
  6593. * Loads a glTF buffer view.
  6594. * @param context The context when loading the asset
  6595. * @param bufferView The glTF buffer view property
  6596. * @returns A promise that resolves with the loaded data when the load is complete
  6597. */
  6598. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  6599. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  6600. if (extensionPromise) {
  6601. return extensionPromise;
  6602. }
  6603. if (bufferView._data) {
  6604. return bufferView._data;
  6605. }
  6606. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  6607. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  6608. return bufferView._data;
  6609. };
  6610. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  6611. var _this = this;
  6612. if (accessor._data) {
  6613. return accessor._data;
  6614. }
  6615. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  6616. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  6617. var length = numComponents * accessor.count;
  6618. if (accessor.bufferView == undefined) {
  6619. accessor._data = Promise.resolve(new constructor(length));
  6620. }
  6621. else {
  6622. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6623. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  6624. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6625. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  6626. }
  6627. else {
  6628. var typedArray_1 = new constructor(length);
  6629. 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) {
  6630. typedArray_1[index] = value;
  6631. });
  6632. return typedArray_1;
  6633. }
  6634. });
  6635. }
  6636. if (accessor.sparse) {
  6637. var sparse_1 = accessor.sparse;
  6638. accessor._data = accessor._data.then(function (data) {
  6639. var typedArray = data;
  6640. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  6641. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  6642. return Promise.all([
  6643. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  6644. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  6645. ]).then(function (_a) {
  6646. var indicesData = _a[0], valuesData = _a[1];
  6647. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  6648. var sparseLength = numComponents * sparse_1.count;
  6649. var values;
  6650. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6651. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6652. }
  6653. else {
  6654. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6655. values = new constructor(sparseLength);
  6656. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  6657. values[index] = value;
  6658. });
  6659. }
  6660. var valuesIndex = 0;
  6661. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  6662. var dataIndex = indices[indicesIndex] * numComponents;
  6663. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  6664. typedArray[dataIndex++] = values[valuesIndex++];
  6665. }
  6666. }
  6667. return typedArray;
  6668. });
  6669. });
  6670. }
  6671. return accessor._data;
  6672. };
  6673. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  6674. return this._loadAccessorAsync(context, accessor, Float32Array);
  6675. };
  6676. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  6677. if (accessor.type !== "SCALAR" /* SCALAR */) {
  6678. throw new Error(context + "/type: Invalid value " + accessor.type);
  6679. }
  6680. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  6681. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  6682. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  6683. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  6684. }
  6685. if (accessor._data) {
  6686. return accessor._data;
  6687. }
  6688. if (accessor.sparse) {
  6689. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  6690. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  6691. }
  6692. else {
  6693. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6694. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6695. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  6696. });
  6697. }
  6698. return accessor._data;
  6699. };
  6700. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  6701. var _this = this;
  6702. if (bufferView._babylonBuffer) {
  6703. return bufferView._babylonBuffer;
  6704. }
  6705. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6706. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  6707. });
  6708. return bufferView._babylonBuffer;
  6709. };
  6710. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  6711. var _this = this;
  6712. if (accessor._babylonVertexBuffer) {
  6713. return accessor._babylonVertexBuffer;
  6714. }
  6715. if (accessor.sparse) {
  6716. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6717. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6718. });
  6719. }
  6720. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  6721. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  6722. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  6723. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6724. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6725. });
  6726. }
  6727. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  6728. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  6729. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6730. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6731. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6732. });
  6733. }
  6734. else {
  6735. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6736. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  6737. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  6738. 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);
  6739. });
  6740. }
  6741. return accessor._babylonVertexBuffer;
  6742. };
  6743. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  6744. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6745. throw new Error(context + ": Material type not supported");
  6746. }
  6747. var promises = new Array();
  6748. if (properties) {
  6749. if (properties.baseColorFactor) {
  6750. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  6751. babylonMaterial.alpha = properties.baseColorFactor[3];
  6752. }
  6753. else {
  6754. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  6755. }
  6756. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  6757. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  6758. if (properties.baseColorTexture) {
  6759. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  6760. texture.name = babylonMaterial.name + " (Base Color)";
  6761. babylonMaterial.albedoTexture = texture;
  6762. }));
  6763. }
  6764. if (properties.metallicRoughnessTexture) {
  6765. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  6766. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  6767. babylonMaterial.metallicTexture = texture;
  6768. }));
  6769. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  6770. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  6771. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  6772. }
  6773. }
  6774. return Promise.all(promises).then(function () { });
  6775. };
  6776. /** @hidden */
  6777. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6778. if (assign === void 0) { assign = function () { }; }
  6779. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  6780. if (extensionPromise) {
  6781. return extensionPromise;
  6782. }
  6783. material._data = material._data || {};
  6784. var babylonData = material._data[babylonDrawMode];
  6785. if (!babylonData) {
  6786. this.logOpen(context + " " + (material.name || ""));
  6787. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  6788. babylonData = {
  6789. babylonMaterial: babylonMaterial,
  6790. babylonMeshes: [],
  6791. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  6792. };
  6793. material._data[babylonDrawMode] = babylonData;
  6794. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  6795. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6796. this.logClose();
  6797. }
  6798. babylonData.babylonMeshes.push(babylonMesh);
  6799. babylonMesh.onDisposeObservable.addOnce(function () {
  6800. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  6801. if (index !== -1) {
  6802. babylonData.babylonMeshes.splice(index, 1);
  6803. }
  6804. });
  6805. assign(babylonData.babylonMaterial);
  6806. return babylonData.promise.then(function () {
  6807. return babylonData.babylonMaterial;
  6808. });
  6809. };
  6810. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  6811. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  6812. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  6813. babylonMaterial.fillMode = babylonDrawMode;
  6814. babylonMaterial.enableSpecularAntiAliasing = true;
  6815. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  6816. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  6817. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6818. babylonMaterial.metallic = 1;
  6819. babylonMaterial.roughness = 1;
  6820. return babylonMaterial;
  6821. };
  6822. /**
  6823. * Creates a Babylon material from a glTF material.
  6824. * @param context The context when loading the asset
  6825. * @param material The glTF material property
  6826. * @param babylonDrawMode The draw mode for the Babylon material
  6827. * @returns The Babylon material
  6828. */
  6829. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  6830. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  6831. if (extensionPromise) {
  6832. return extensionPromise;
  6833. }
  6834. var name = material.name || "material" + material.index;
  6835. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  6836. return babylonMaterial;
  6837. };
  6838. /**
  6839. * Loads properties from a glTF material into a Babylon material.
  6840. * @param context The context when loading the asset
  6841. * @param material The glTF material property
  6842. * @param babylonMaterial The Babylon material
  6843. * @returns A promise that resolves when the load is complete
  6844. */
  6845. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6846. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  6847. if (extensionPromise) {
  6848. return extensionPromise;
  6849. }
  6850. var promises = new Array();
  6851. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  6852. if (material.pbrMetallicRoughness) {
  6853. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  6854. }
  6855. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  6856. return Promise.all(promises).then(function () { });
  6857. };
  6858. /**
  6859. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  6860. * @param context The context when loading the asset
  6861. * @param material The glTF material property
  6862. * @param babylonMaterial The Babylon material
  6863. * @returns A promise that resolves when the load is complete
  6864. */
  6865. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  6866. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6867. throw new Error(context + ": Material type not supported");
  6868. }
  6869. var promises = new Array();
  6870. 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);
  6871. if (material.doubleSided) {
  6872. babylonMaterial.backFaceCulling = false;
  6873. babylonMaterial.twoSidedLighting = true;
  6874. }
  6875. if (material.normalTexture) {
  6876. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  6877. texture.name = babylonMaterial.name + " (Normal)";
  6878. babylonMaterial.bumpTexture = texture;
  6879. }));
  6880. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  6881. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  6882. if (material.normalTexture.scale != undefined) {
  6883. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  6884. }
  6885. babylonMaterial.forceIrradianceInFragment = true;
  6886. }
  6887. if (material.occlusionTexture) {
  6888. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  6889. texture.name = babylonMaterial.name + " (Occlusion)";
  6890. babylonMaterial.ambientTexture = texture;
  6891. }));
  6892. babylonMaterial.useAmbientInGrayScale = true;
  6893. if (material.occlusionTexture.strength != undefined) {
  6894. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  6895. }
  6896. }
  6897. if (material.emissiveTexture) {
  6898. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  6899. texture.name = babylonMaterial.name + " (Emissive)";
  6900. babylonMaterial.emissiveTexture = texture;
  6901. }));
  6902. }
  6903. return Promise.all(promises).then(function () { });
  6904. };
  6905. /**
  6906. * Loads the alpha properties from a glTF material into a Babylon material.
  6907. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  6908. * @param context The context when loading the asset
  6909. * @param material The glTF material property
  6910. * @param babylonMaterial The Babylon material
  6911. */
  6912. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  6913. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6914. throw new Error(context + ": Material type not supported");
  6915. }
  6916. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  6917. switch (alphaMode) {
  6918. case "OPAQUE" /* OPAQUE */: {
  6919. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6920. break;
  6921. }
  6922. case "MASK" /* MASK */: {
  6923. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  6924. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  6925. if (babylonMaterial.albedoTexture) {
  6926. babylonMaterial.albedoTexture.hasAlpha = true;
  6927. }
  6928. break;
  6929. }
  6930. case "BLEND" /* BLEND */: {
  6931. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  6932. if (babylonMaterial.albedoTexture) {
  6933. babylonMaterial.albedoTexture.hasAlpha = true;
  6934. babylonMaterial.useAlphaFromAlbedoTexture = true;
  6935. }
  6936. break;
  6937. }
  6938. default: {
  6939. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  6940. }
  6941. }
  6942. };
  6943. /**
  6944. * Loads a glTF texture info.
  6945. * @param context The context when loading the asset
  6946. * @param textureInfo The glTF texture info property
  6947. * @param assign A function called synchronously after parsing the glTF properties
  6948. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  6949. */
  6950. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  6951. var _this = this;
  6952. if (assign === void 0) { assign = function () { }; }
  6953. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  6954. if (extensionPromise) {
  6955. return extensionPromise;
  6956. }
  6957. this.logOpen("" + context);
  6958. if (textureInfo.texCoord >= 2) {
  6959. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  6960. }
  6961. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  6962. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  6963. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  6964. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  6965. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  6966. assign(babylonTexture);
  6967. });
  6968. this.logClose();
  6969. return promise;
  6970. };
  6971. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  6972. var _this = this;
  6973. if (assign === void 0) { assign = function () { }; }
  6974. var promises = new Array();
  6975. this.logOpen(context + " " + (texture.name || ""));
  6976. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  6977. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  6978. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  6979. var url = null;
  6980. if (image.uri) {
  6981. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  6982. url = image.uri;
  6983. }
  6984. else if (this._babylonScene.getEngine().textureFormatInUse) {
  6985. // 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
  6986. url = this._rootUrl + image.uri;
  6987. }
  6988. }
  6989. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6990. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  6991. if (!_this._disposed) {
  6992. deferred.resolve();
  6993. }
  6994. }, function (message, exception) {
  6995. if (!_this._disposed) {
  6996. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  6997. }
  6998. }, undefined, undefined, undefined, image.mimeType);
  6999. promises.push(deferred.promise);
  7000. if (!url) {
  7001. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  7002. var name = image.uri || _this._fileName + "#image" + image.index;
  7003. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  7004. babylonTexture.updateURL(dataUrl, data);
  7005. }));
  7006. }
  7007. babylonTexture.wrapU = samplerData.wrapU;
  7008. babylonTexture.wrapV = samplerData.wrapV;
  7009. assign(babylonTexture);
  7010. this.logClose();
  7011. return Promise.all(promises).then(function () {
  7012. return babylonTexture;
  7013. });
  7014. };
  7015. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  7016. if (!sampler._data) {
  7017. sampler._data = {
  7018. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  7019. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  7020. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  7021. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  7022. };
  7023. }
  7024. return sampler._data;
  7025. };
  7026. /**
  7027. * Loads a glTF image.
  7028. * @param context The context when loading the asset
  7029. * @param image The glTF image property
  7030. * @returns A promise that resolves with the loaded data when the load is complete
  7031. */
  7032. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  7033. if (!image._data) {
  7034. this.logOpen(context + " " + (image.name || ""));
  7035. if (image.uri) {
  7036. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  7037. }
  7038. else {
  7039. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  7040. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  7041. }
  7042. this.logClose();
  7043. }
  7044. return image._data;
  7045. };
  7046. /**
  7047. * Loads a glTF uri.
  7048. * @param context The context when loading the asset
  7049. * @param property The glTF property associated with the uri
  7050. * @param uri The base64 or relative uri
  7051. * @returns A promise that resolves with the loaded data when the load is complete
  7052. */
  7053. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  7054. var _this = this;
  7055. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  7056. if (extensionPromise) {
  7057. return extensionPromise;
  7058. }
  7059. if (!GLTFLoader._ValidateUri(uri)) {
  7060. throw new Error(context + ": '" + uri + "' is invalid");
  7061. }
  7062. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7063. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7064. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7065. return Promise.resolve(data);
  7066. }
  7067. this.log("Loading " + uri);
  7068. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7069. return new Promise(function (resolve, reject) {
  7070. if (!_this._disposed) {
  7071. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  7072. if (!_this._disposed) {
  7073. var data = new Uint8Array(fileData);
  7074. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  7075. resolve(data);
  7076. }
  7077. }, function (event) {
  7078. if (!_this._disposed) {
  7079. if (request_1) {
  7080. request_1._lengthComputable = event.lengthComputable;
  7081. request_1._loaded = event.loaded;
  7082. request_1._total = event.total;
  7083. }
  7084. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  7085. try {
  7086. _this._onProgress();
  7087. }
  7088. catch (e) {
  7089. reject(e);
  7090. }
  7091. }
  7092. }
  7093. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  7094. if (!_this._disposed) {
  7095. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7096. }
  7097. });
  7098. _this._requests.push(request_1);
  7099. }
  7100. });
  7101. });
  7102. };
  7103. GLTFLoader.prototype._onProgress = function () {
  7104. if (!this._progressCallback) {
  7105. return;
  7106. }
  7107. var lengthComputable = true;
  7108. var loaded = 0;
  7109. var total = 0;
  7110. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  7111. var request = _a[_i];
  7112. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  7113. return;
  7114. }
  7115. lengthComputable = lengthComputable && request._lengthComputable;
  7116. loaded += request._loaded;
  7117. total += request._total;
  7118. }
  7119. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  7120. };
  7121. /**
  7122. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7123. * @param babylonObject the Babylon object with metadata
  7124. * @param pointer the JSON pointer
  7125. */
  7126. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7127. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7128. var gltf = (metadata.gltf = metadata.gltf || {});
  7129. var pointers = (gltf.pointers = gltf.pointers || []);
  7130. pointers.push(pointer);
  7131. };
  7132. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7133. // Set defaults if undefined
  7134. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7135. switch (mode) {
  7136. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7137. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7138. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7139. default:
  7140. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7141. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7142. }
  7143. };
  7144. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7145. // Set defaults if undefined
  7146. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7147. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7148. if (magFilter === 9729 /* LINEAR */) {
  7149. switch (minFilter) {
  7150. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7151. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7152. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7153. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7154. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7155. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7156. default:
  7157. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7158. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7159. }
  7160. }
  7161. else {
  7162. if (magFilter !== 9728 /* NEAREST */) {
  7163. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7164. }
  7165. switch (minFilter) {
  7166. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7167. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7168. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7169. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7170. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7171. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7172. default:
  7173. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7174. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7175. }
  7176. }
  7177. };
  7178. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7179. switch (componentType) {
  7180. case 5120 /* BYTE */: return Int8Array;
  7181. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7182. case 5122 /* SHORT */: return Int16Array;
  7183. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7184. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7185. case 5126 /* FLOAT */: return Float32Array;
  7186. default: throw new Error(context + ": Invalid component type " + componentType);
  7187. }
  7188. };
  7189. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7190. var buffer = bufferView.buffer;
  7191. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7192. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7193. try {
  7194. return new constructor(buffer, byteOffset, length);
  7195. }
  7196. catch (e) {
  7197. throw new Error(context + ": " + e);
  7198. }
  7199. };
  7200. GLTFLoader._GetNumComponents = function (context, type) {
  7201. switch (type) {
  7202. case "SCALAR": return 1;
  7203. case "VEC2": return 2;
  7204. case "VEC3": return 3;
  7205. case "VEC4": return 4;
  7206. case "MAT2": return 4;
  7207. case "MAT3": return 9;
  7208. case "MAT4": return 16;
  7209. }
  7210. throw new Error(context + ": Invalid type (" + type + ")");
  7211. };
  7212. GLTFLoader._ValidateUri = function (uri) {
  7213. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7214. };
  7215. GLTFLoader._GetDrawMode = function (context, mode) {
  7216. if (mode == undefined) {
  7217. mode = 4 /* TRIANGLES */;
  7218. }
  7219. switch (mode) {
  7220. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7221. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7222. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7223. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7224. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7225. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7226. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7227. }
  7228. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7229. };
  7230. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7231. var _this = this;
  7232. this._parent._startPerformanceCounter("Compile materials");
  7233. var promises = new Array();
  7234. if (this._gltf.materials) {
  7235. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7236. var material = _a[_i];
  7237. if (material._data) {
  7238. for (var babylonDrawMode in material._data) {
  7239. var babylonData = material._data[babylonDrawMode];
  7240. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7241. var babylonMesh = _c[_b];
  7242. // Ensure nonUniformScaling is set if necessary.
  7243. babylonMesh.computeWorldMatrix(true);
  7244. var babylonMaterial = babylonData.babylonMaterial;
  7245. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7246. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7247. if (this._parent.useClipPlane) {
  7248. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7249. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7250. }
  7251. }
  7252. }
  7253. }
  7254. }
  7255. }
  7256. return Promise.all(promises).then(function () {
  7257. _this._parent._endPerformanceCounter("Compile materials");
  7258. });
  7259. };
  7260. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7261. var _this = this;
  7262. this._parent._startPerformanceCounter("Compile shadow generators");
  7263. var promises = new Array();
  7264. var lights = this._babylonScene.lights;
  7265. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7266. var light = lights_1[_i];
  7267. var generator = light.getShadowGenerator();
  7268. if (generator) {
  7269. promises.push(generator.forceCompilationAsync());
  7270. }
  7271. }
  7272. return Promise.all(promises).then(function () {
  7273. _this._parent._endPerformanceCounter("Compile shadow generators");
  7274. });
  7275. };
  7276. GLTFLoader.prototype._forEachExtensions = function (action) {
  7277. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7278. var extension = _a[_i];
  7279. if (extension.enabled) {
  7280. action(extension);
  7281. }
  7282. }
  7283. };
  7284. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7285. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7286. var extension = _a[_i];
  7287. if (extension.enabled) {
  7288. var id = extension.name + "." + functionName;
  7289. var loaderProperty = property;
  7290. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7291. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7292. if (!activeLoaderExtensionFunctions[id]) {
  7293. activeLoaderExtensionFunctions[id] = true;
  7294. try {
  7295. var result = actionAsync(extension);
  7296. if (result) {
  7297. return result;
  7298. }
  7299. }
  7300. finally {
  7301. delete activeLoaderExtensionFunctions[id];
  7302. }
  7303. }
  7304. }
  7305. }
  7306. return null;
  7307. };
  7308. GLTFLoader.prototype._extensionsOnLoading = function () {
  7309. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7310. };
  7311. GLTFLoader.prototype._extensionsOnReady = function () {
  7312. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7313. };
  7314. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7315. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7316. };
  7317. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7318. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7319. };
  7320. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7321. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7322. };
  7323. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7324. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7325. };
  7326. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7327. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7328. };
  7329. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7330. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7331. };
  7332. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7333. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7334. };
  7335. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7336. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7337. };
  7338. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7339. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7340. };
  7341. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7342. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7343. };
  7344. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7345. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7346. };
  7347. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7348. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7349. };
  7350. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7351. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7352. };
  7353. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7354. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7355. };
  7356. /**
  7357. * Helper method called by a loader extension to load an glTF extension.
  7358. * @param context The context when loading the asset
  7359. * @param property The glTF property to load the extension from
  7360. * @param extensionName The name of the extension to load
  7361. * @param actionAsync The action to run
  7362. * @returns The promise returned by actionAsync or null if the extension does not exist
  7363. */
  7364. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7365. if (!property.extensions) {
  7366. return null;
  7367. }
  7368. var extensions = property.extensions;
  7369. var extension = extensions[extensionName];
  7370. if (!extension) {
  7371. return null;
  7372. }
  7373. return actionAsync(context + "/extensions/" + extensionName, extension);
  7374. };
  7375. /**
  7376. * Helper method called by a loader extension to load a glTF extra.
  7377. * @param context The context when loading the asset
  7378. * @param property The glTF property to load the extra from
  7379. * @param extensionName The name of the extension to load
  7380. * @param actionAsync The action to run
  7381. * @returns The promise returned by actionAsync or null if the extra does not exist
  7382. */
  7383. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7384. if (!property.extras) {
  7385. return null;
  7386. }
  7387. var extras = property.extras;
  7388. var extra = extras[extensionName];
  7389. if (!extra) {
  7390. return null;
  7391. }
  7392. return actionAsync(context + "/extras/" + extensionName, extra);
  7393. };
  7394. /**
  7395. * Checks for presence of an extension.
  7396. * @param name The name of the extension to check
  7397. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7398. */
  7399. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7400. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7401. };
  7402. /**
  7403. * Increments the indentation level and logs a message.
  7404. * @param message The message to log
  7405. */
  7406. GLTFLoader.prototype.logOpen = function (message) {
  7407. this._parent._logOpen(message);
  7408. };
  7409. /**
  7410. * Decrements the indentation level.
  7411. */
  7412. GLTFLoader.prototype.logClose = function () {
  7413. this._parent._logClose();
  7414. };
  7415. /**
  7416. * Logs a message
  7417. * @param message The message to log
  7418. */
  7419. GLTFLoader.prototype.log = function (message) {
  7420. this._parent._log(message);
  7421. };
  7422. /**
  7423. * Starts a performance counter.
  7424. * @param counterName The name of the performance counter
  7425. */
  7426. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7427. this._parent._startPerformanceCounter(counterName);
  7428. };
  7429. /**
  7430. * Ends a performance counter.
  7431. * @param counterName The name of the performance counter
  7432. */
  7433. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7434. this._parent._endPerformanceCounter(counterName);
  7435. };
  7436. GLTFLoader._DefaultSampler = { index: -1 };
  7437. GLTFLoader._RegisteredExtensions = {};
  7438. return GLTFLoader;
  7439. }());
  7440. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  7441. /***/ }),
  7442. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  7443. /*!******************************************!*\
  7444. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  7445. \******************************************/
  7446. /*! no static exports found */
  7447. /***/ (function(module, exports) {
  7448. /***/ }),
  7449. /***/ "./glTF/2.0/index.ts":
  7450. /*!***************************!*\
  7451. !*** ./glTF/2.0/index.ts ***!
  7452. \***************************/
  7453. /*! 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 */
  7454. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7455. "use strict";
  7456. __webpack_require__.r(__webpack_exports__);
  7457. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  7458. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  7459. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  7460. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  7461. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  7462. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  7463. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  7464. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  7465. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  7466. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  7467. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  7468. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  7469. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  7470. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  7471. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  7472. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  7473. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  7474. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  7475. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  7476. /***/ }),
  7477. /***/ "./glTF/glTFFileLoader.ts":
  7478. /*!********************************!*\
  7479. !*** ./glTF/glTFFileLoader.ts ***!
  7480. \********************************/
  7481. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  7482. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7483. "use strict";
  7484. __webpack_require__.r(__webpack_exports__);
  7485. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  7486. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  7487. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  7488. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  7489. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  7490. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  7491. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  7492. /**
  7493. * Mode that determines the coordinate system to use.
  7494. */
  7495. var GLTFLoaderCoordinateSystemMode;
  7496. (function (GLTFLoaderCoordinateSystemMode) {
  7497. /**
  7498. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  7499. */
  7500. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  7501. /**
  7502. * Sets the useRightHandedSystem flag on the scene.
  7503. */
  7504. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  7505. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  7506. /**
  7507. * Mode that determines what animations will start.
  7508. */
  7509. var GLTFLoaderAnimationStartMode;
  7510. (function (GLTFLoaderAnimationStartMode) {
  7511. /**
  7512. * No animation will start.
  7513. */
  7514. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  7515. /**
  7516. * The first animation will start.
  7517. */
  7518. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  7519. /**
  7520. * All animations will start.
  7521. */
  7522. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  7523. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  7524. /**
  7525. * Loader state.
  7526. */
  7527. var GLTFLoaderState;
  7528. (function (GLTFLoaderState) {
  7529. /**
  7530. * The asset is loading.
  7531. */
  7532. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  7533. /**
  7534. * The asset is ready for rendering.
  7535. */
  7536. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  7537. /**
  7538. * The asset is completely loaded.
  7539. */
  7540. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  7541. })(GLTFLoaderState || (GLTFLoaderState = {}));
  7542. /**
  7543. * File loader for loading glTF files into a scene.
  7544. */
  7545. var GLTFFileLoader = /** @class */ (function () {
  7546. function GLTFFileLoader() {
  7547. // --------------
  7548. // Common options
  7549. // --------------
  7550. /**
  7551. * Raised when the asset has been parsed
  7552. */
  7553. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7554. // ----------
  7555. // V2 options
  7556. // ----------
  7557. /**
  7558. * The coordinate system mode. Defaults to AUTO.
  7559. */
  7560. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  7561. /**
  7562. * The animation start mode. Defaults to FIRST.
  7563. */
  7564. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  7565. /**
  7566. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  7567. */
  7568. this.compileMaterials = false;
  7569. /**
  7570. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  7571. */
  7572. this.useClipPlane = false;
  7573. /**
  7574. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  7575. */
  7576. this.compileShadowGenerators = false;
  7577. /**
  7578. * Defines if the Alpha blended materials are only applied as coverage.
  7579. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  7580. * If true, no extra effects are applied to transparent pixels.
  7581. */
  7582. this.transparencyAsCoverage = false;
  7583. /**
  7584. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  7585. * Enabling will disable offline support and glTF validator.
  7586. * Defaults to false.
  7587. */
  7588. this.useRangeRequests = false;
  7589. /**
  7590. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  7591. */
  7592. this.createInstances = true;
  7593. /**
  7594. * Function called before loading a url referenced by the asset.
  7595. */
  7596. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7597. /**
  7598. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7599. */
  7600. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7601. /**
  7602. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  7603. */
  7604. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7605. /**
  7606. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  7607. */
  7608. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7609. /**
  7610. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  7611. */
  7612. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7613. /**
  7614. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  7615. * For assets with LODs, raised when all of the LODs are complete.
  7616. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7617. */
  7618. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7619. /**
  7620. * Observable raised when an error occurs.
  7621. */
  7622. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7623. /**
  7624. * Observable raised after the loader is disposed.
  7625. */
  7626. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7627. /**
  7628. * Observable raised after a loader extension is created.
  7629. * Set additional options for a loader extension in this event.
  7630. */
  7631. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7632. /**
  7633. * Defines if the loader should validate the asset.
  7634. */
  7635. this.validate = false;
  7636. /**
  7637. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  7638. */
  7639. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7640. this._loader = null;
  7641. /**
  7642. * Name of the loader ("gltf")
  7643. */
  7644. this.name = "gltf";
  7645. /** @hidden */
  7646. this.extensions = {
  7647. ".gltf": { isBinary: false },
  7648. ".glb": { isBinary: true }
  7649. };
  7650. this._logIndentLevel = 0;
  7651. this._loggingEnabled = false;
  7652. /** @hidden */
  7653. this._log = this._logDisabled;
  7654. this._capturePerformanceCounters = false;
  7655. /** @hidden */
  7656. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7657. /** @hidden */
  7658. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7659. }
  7660. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  7661. /**
  7662. * Raised when the asset has been parsed
  7663. */
  7664. set: function (callback) {
  7665. if (this._onParsedObserver) {
  7666. this.onParsedObservable.remove(this._onParsedObserver);
  7667. }
  7668. this._onParsedObserver = this.onParsedObservable.add(callback);
  7669. },
  7670. enumerable: true,
  7671. configurable: true
  7672. });
  7673. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  7674. /**
  7675. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7676. */
  7677. set: function (callback) {
  7678. if (this._onMeshLoadedObserver) {
  7679. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  7680. }
  7681. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  7682. },
  7683. enumerable: true,
  7684. configurable: true
  7685. });
  7686. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  7687. /**
  7688. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  7689. */
  7690. set: function (callback) {
  7691. if (this._onTextureLoadedObserver) {
  7692. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  7693. }
  7694. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  7695. },
  7696. enumerable: true,
  7697. configurable: true
  7698. });
  7699. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  7700. /**
  7701. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  7702. */
  7703. set: function (callback) {
  7704. if (this._onMaterialLoadedObserver) {
  7705. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  7706. }
  7707. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  7708. },
  7709. enumerable: true,
  7710. configurable: true
  7711. });
  7712. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  7713. /**
  7714. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  7715. */
  7716. set: function (callback) {
  7717. if (this._onCameraLoadedObserver) {
  7718. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  7719. }
  7720. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  7721. },
  7722. enumerable: true,
  7723. configurable: true
  7724. });
  7725. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  7726. /**
  7727. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  7728. * For assets with LODs, raised when all of the LODs are complete.
  7729. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7730. */
  7731. set: function (callback) {
  7732. if (this._onCompleteObserver) {
  7733. this.onCompleteObservable.remove(this._onCompleteObserver);
  7734. }
  7735. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  7736. },
  7737. enumerable: true,
  7738. configurable: true
  7739. });
  7740. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  7741. /**
  7742. * Callback raised when an error occurs.
  7743. */
  7744. set: function (callback) {
  7745. if (this._onErrorObserver) {
  7746. this.onErrorObservable.remove(this._onErrorObserver);
  7747. }
  7748. this._onErrorObserver = this.onErrorObservable.add(callback);
  7749. },
  7750. enumerable: true,
  7751. configurable: true
  7752. });
  7753. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  7754. /**
  7755. * Callback raised after the loader is disposed.
  7756. */
  7757. set: function (callback) {
  7758. if (this._onDisposeObserver) {
  7759. this.onDisposeObservable.remove(this._onDisposeObserver);
  7760. }
  7761. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  7762. },
  7763. enumerable: true,
  7764. configurable: true
  7765. });
  7766. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  7767. /**
  7768. * Callback raised after a loader extension is created.
  7769. */
  7770. set: function (callback) {
  7771. if (this._onExtensionLoadedObserver) {
  7772. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  7773. }
  7774. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  7775. },
  7776. enumerable: true,
  7777. configurable: true
  7778. });
  7779. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  7780. /**
  7781. * Defines if the loader logging is enabled.
  7782. */
  7783. get: function () {
  7784. return this._loggingEnabled;
  7785. },
  7786. set: function (value) {
  7787. if (this._loggingEnabled === value) {
  7788. return;
  7789. }
  7790. this._loggingEnabled = value;
  7791. if (this._loggingEnabled) {
  7792. this._log = this._logEnabled;
  7793. }
  7794. else {
  7795. this._log = this._logDisabled;
  7796. }
  7797. },
  7798. enumerable: true,
  7799. configurable: true
  7800. });
  7801. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  7802. /**
  7803. * Defines if the loader should capture performance counters.
  7804. */
  7805. get: function () {
  7806. return this._capturePerformanceCounters;
  7807. },
  7808. set: function (value) {
  7809. if (this._capturePerformanceCounters === value) {
  7810. return;
  7811. }
  7812. this._capturePerformanceCounters = value;
  7813. if (this._capturePerformanceCounters) {
  7814. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  7815. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  7816. }
  7817. else {
  7818. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7819. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7820. }
  7821. },
  7822. enumerable: true,
  7823. configurable: true
  7824. });
  7825. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  7826. /**
  7827. * Callback raised after a loader extension is created.
  7828. */
  7829. set: function (callback) {
  7830. if (this._onValidatedObserver) {
  7831. this.onValidatedObservable.remove(this._onValidatedObserver);
  7832. }
  7833. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  7834. },
  7835. enumerable: true,
  7836. configurable: true
  7837. });
  7838. /**
  7839. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  7840. */
  7841. GLTFFileLoader.prototype.dispose = function () {
  7842. if (this._loader) {
  7843. this._loader.dispose();
  7844. this._loader = null;
  7845. }
  7846. this._clear();
  7847. this.onDisposeObservable.notifyObservers(undefined);
  7848. this.onDisposeObservable.clear();
  7849. };
  7850. /** @hidden */
  7851. GLTFFileLoader.prototype._clear = function () {
  7852. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7853. this.onMeshLoadedObservable.clear();
  7854. this.onTextureLoadedObservable.clear();
  7855. this.onMaterialLoadedObservable.clear();
  7856. this.onCameraLoadedObservable.clear();
  7857. this.onCompleteObservable.clear();
  7858. this.onExtensionLoadedObservable.clear();
  7859. };
  7860. /** @hidden */
  7861. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  7862. var _this = this;
  7863. if (useArrayBuffer) {
  7864. if (this.useRangeRequests) {
  7865. if (this.validate) {
  7866. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  7867. }
  7868. var fileRequests_1 = new Array();
  7869. var aggregatedFileRequest_1 = {
  7870. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  7871. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  7872. };
  7873. var dataBuffer_1 = {
  7874. readAsync: function (byteOffset, byteLength) {
  7875. return new Promise(function (resolve, reject) {
  7876. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  7877. dataBuffer_1.byteLength = Number(webRequest.getResponseHeader("Content-Range").split("/")[1]);
  7878. resolve(new Uint8Array(data));
  7879. }, onProgress, true, true, function (error) {
  7880. reject(error);
  7881. }, function (webRequest) {
  7882. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  7883. }));
  7884. });
  7885. },
  7886. byteLength: 0
  7887. };
  7888. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  7889. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  7890. onSuccess(loaderData);
  7891. }, onError);
  7892. return aggregatedFileRequest_1;
  7893. }
  7894. return scene._requestFile(url, function (data, request) {
  7895. var arrayBuffer = data;
  7896. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7897. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  7898. byteLength: arrayBuffer.byteLength
  7899. })).then(function (loaderData) {
  7900. onSuccess(loaderData, request);
  7901. }, onError);
  7902. }, onProgress, true, true, onError);
  7903. }
  7904. return scene._requestFile(url, function (data, response) {
  7905. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  7906. onSuccess({ json: _this._parseJson(data) }, response);
  7907. }, onProgress, true, false, onError);
  7908. };
  7909. /** @hidden */
  7910. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  7911. var _this = this;
  7912. return scene._readFile(file, function (data) {
  7913. _this._validate(scene, data, "file:", file.name);
  7914. if (useArrayBuffer) {
  7915. var arrayBuffer_1 = data;
  7916. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7917. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  7918. byteLength: arrayBuffer_1.byteLength
  7919. })).then(onSuccess, onError);
  7920. }
  7921. else {
  7922. onSuccess({ json: _this._parseJson(data) });
  7923. }
  7924. }, onProgress, useArrayBuffer, onError);
  7925. };
  7926. /** @hidden */
  7927. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  7928. var _this = this;
  7929. return Promise.resolve().then(function () {
  7930. _this.onParsedObservable.notifyObservers(data);
  7931. _this.onParsedObservable.clear();
  7932. _this._log("Loading " + (fileName || ""));
  7933. _this._loader = _this._getLoader(data);
  7934. return _this._loader.importMeshAsync(meshesNames, scene, data, rootUrl, onProgress, fileName);
  7935. });
  7936. };
  7937. /** @hidden */
  7938. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7939. var _this = this;
  7940. return Promise.resolve().then(function () {
  7941. _this.onParsedObservable.notifyObservers(data);
  7942. _this.onParsedObservable.clear();
  7943. _this._log("Loading " + (fileName || ""));
  7944. _this._loader = _this._getLoader(data);
  7945. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  7946. });
  7947. };
  7948. /** @hidden */
  7949. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7950. var _this = this;
  7951. return Promise.resolve().then(function () {
  7952. _this.onParsedObservable.notifyObservers(data);
  7953. _this.onParsedObservable.clear();
  7954. _this._log("Loading " + (fileName || ""));
  7955. _this._loader = _this._getLoader(data);
  7956. // Get materials/textures when loading to add to container
  7957. var materials = [];
  7958. _this.onMaterialLoadedObservable.add(function (material) {
  7959. materials.push(material);
  7960. });
  7961. var textures = [];
  7962. _this.onTextureLoadedObservable.add(function (texture) {
  7963. textures.push(texture);
  7964. });
  7965. return _this._loader.importMeshAsync(null, scene, data, rootUrl, onProgress, fileName).then(function (result) {
  7966. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  7967. Array.prototype.push.apply(container.meshes, result.meshes);
  7968. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  7969. Array.prototype.push.apply(container.skeletons, result.skeletons);
  7970. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  7971. Array.prototype.push.apply(container.materials, materials);
  7972. Array.prototype.push.apply(container.textures, textures);
  7973. container.removeAllFromScene();
  7974. return container;
  7975. });
  7976. });
  7977. };
  7978. /** @hidden */
  7979. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  7980. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  7981. };
  7982. /** @hidden */
  7983. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  7984. this._validate(scene, data);
  7985. return { json: this._parseJson(data) };
  7986. };
  7987. /** @hidden */
  7988. GLTFFileLoader.prototype.createPlugin = function () {
  7989. return new GLTFFileLoader();
  7990. };
  7991. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  7992. /**
  7993. * The loader state or null if the loader is not active.
  7994. */
  7995. get: function () {
  7996. return this._loader ? this._loader.state : null;
  7997. },
  7998. enumerable: true,
  7999. configurable: true
  8000. });
  8001. /**
  8002. * Returns a promise that resolves when the asset is completely loaded.
  8003. * @returns a promise that resolves when the asset is completely loaded.
  8004. */
  8005. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  8006. var _this = this;
  8007. return new Promise(function (resolve, reject) {
  8008. _this.onCompleteObservable.addOnce(function () {
  8009. resolve();
  8010. });
  8011. _this.onErrorObservable.addOnce(function (reason) {
  8012. reject(reason);
  8013. });
  8014. });
  8015. };
  8016. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  8017. var _this = this;
  8018. if (rootUrl === void 0) { rootUrl = ""; }
  8019. if (fileName === void 0) { fileName = ""; }
  8020. if (!this.validate) {
  8021. return;
  8022. }
  8023. this._startPerformanceCounter("Validate JSON");
  8024. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  8025. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  8026. }).then(function (result) {
  8027. _this._endPerformanceCounter("Validate JSON");
  8028. _this.onValidatedObservable.notifyObservers(result);
  8029. _this.onValidatedObservable.clear();
  8030. }, function (reason) {
  8031. _this._endPerformanceCounter("Validate JSON");
  8032. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  8033. _this.onValidatedObservable.clear();
  8034. });
  8035. };
  8036. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  8037. var asset = loaderData.json.asset || {};
  8038. this._log("Asset version: " + asset.version);
  8039. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  8040. asset.generator && this._log("Asset generator: " + asset.generator);
  8041. var version = GLTFFileLoader._parseVersion(asset.version);
  8042. if (!version) {
  8043. throw new Error("Invalid version: " + asset.version);
  8044. }
  8045. if (asset.minVersion !== undefined) {
  8046. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  8047. if (!minVersion) {
  8048. throw new Error("Invalid minimum version: " + asset.minVersion);
  8049. }
  8050. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  8051. throw new Error("Incompatible minimum version: " + asset.minVersion);
  8052. }
  8053. }
  8054. var createLoaders = {
  8055. 1: GLTFFileLoader._CreateGLTF1Loader,
  8056. 2: GLTFFileLoader._CreateGLTF2Loader
  8057. };
  8058. var createLoader = createLoaders[version.major];
  8059. if (!createLoader) {
  8060. throw new Error("Unsupported version: " + asset.version);
  8061. }
  8062. return createLoader(this);
  8063. };
  8064. GLTFFileLoader.prototype._parseJson = function (json) {
  8065. this._startPerformanceCounter("Parse JSON");
  8066. this._log("JSON length: " + json.length);
  8067. var parsed = JSON.parse(json);
  8068. this._endPerformanceCounter("Parse JSON");
  8069. return parsed;
  8070. };
  8071. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8072. var _this = this;
  8073. this._startPerformanceCounter("Unpack Binary");
  8074. // Read magic + version + length + json length + json format
  8075. return dataReader.loadAsync(20).then(function () {
  8076. var Binary = {
  8077. Magic: 0x46546C67
  8078. };
  8079. var magic = dataReader.readUint32();
  8080. if (magic !== Binary.Magic) {
  8081. throw new Error("Unexpected magic: " + magic);
  8082. }
  8083. var version = dataReader.readUint32();
  8084. if (_this.loggingEnabled) {
  8085. _this._log("Binary version: " + version);
  8086. }
  8087. var length = dataReader.readUint32();
  8088. if (length !== dataReader.buffer.byteLength) {
  8089. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8090. }
  8091. var unpacked;
  8092. switch (version) {
  8093. case 1: {
  8094. unpacked = _this._unpackBinaryV1Async(dataReader);
  8095. break;
  8096. }
  8097. case 2: {
  8098. unpacked = _this._unpackBinaryV2Async(dataReader);
  8099. break;
  8100. }
  8101. default: {
  8102. throw new Error("Unsupported version: " + version);
  8103. }
  8104. }
  8105. _this._endPerformanceCounter("Unpack Binary");
  8106. return unpacked;
  8107. });
  8108. };
  8109. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader) {
  8110. var ContentFormat = {
  8111. JSON: 0
  8112. };
  8113. var contentLength = dataReader.readUint32();
  8114. var contentFormat = dataReader.readUint32();
  8115. if (contentFormat !== ContentFormat.JSON) {
  8116. throw new Error("Unexpected content format: " + contentFormat);
  8117. }
  8118. var bodyLength = dataReader.buffer.byteLength - dataReader.byteOffset;
  8119. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8120. if (bodyLength !== 0) {
  8121. var startByteOffset_1 = dataReader.byteOffset;
  8122. data.bin = {
  8123. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8124. byteLength: bodyLength
  8125. };
  8126. }
  8127. return Promise.resolve(data);
  8128. };
  8129. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader) {
  8130. var _this = this;
  8131. var ChunkFormat = {
  8132. JSON: 0x4E4F534A,
  8133. BIN: 0x004E4942
  8134. };
  8135. // Read the JSON chunk header.
  8136. var chunkLength = dataReader.readUint32();
  8137. var chunkFormat = dataReader.readUint32();
  8138. if (chunkFormat !== ChunkFormat.JSON) {
  8139. throw new Error("First chunk format is not JSON");
  8140. }
  8141. // Bail if there are no other chunks.
  8142. if (dataReader.byteOffset + chunkLength === dataReader.buffer.byteLength) {
  8143. return dataReader.loadAsync(chunkLength).then(function () {
  8144. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8145. });
  8146. }
  8147. // Read the JSON chunk and the length and type of the next chunk.
  8148. return dataReader.loadAsync(chunkLength + 8).then(function () {
  8149. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8150. var readAsync = function () {
  8151. var chunkLength = dataReader.readUint32();
  8152. var chunkFormat = dataReader.readUint32();
  8153. switch (chunkFormat) {
  8154. case ChunkFormat.JSON: {
  8155. throw new Error("Unexpected JSON chunk");
  8156. }
  8157. case ChunkFormat.BIN: {
  8158. var startByteOffset_2 = dataReader.byteOffset;
  8159. data.bin = {
  8160. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8161. byteLength: chunkLength
  8162. };
  8163. dataReader.skipBytes(chunkLength);
  8164. break;
  8165. }
  8166. default: {
  8167. // ignore unrecognized chunkFormat
  8168. dataReader.skipBytes(chunkLength);
  8169. break;
  8170. }
  8171. }
  8172. if (dataReader.byteOffset !== dataReader.buffer.byteLength) {
  8173. return dataReader.loadAsync(8).then(readAsync);
  8174. }
  8175. return Promise.resolve(data);
  8176. };
  8177. return readAsync();
  8178. });
  8179. };
  8180. GLTFFileLoader._parseVersion = function (version) {
  8181. if (version === "1.0" || version === "1.0.1") {
  8182. return {
  8183. major: 1,
  8184. minor: 0
  8185. };
  8186. }
  8187. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8188. if (!match) {
  8189. return null;
  8190. }
  8191. return {
  8192. major: parseInt(match[1]),
  8193. minor: parseInt(match[2])
  8194. };
  8195. };
  8196. GLTFFileLoader._compareVersion = function (a, b) {
  8197. if (a.major > b.major) {
  8198. return 1;
  8199. }
  8200. if (a.major < b.major) {
  8201. return -1;
  8202. }
  8203. if (a.minor > b.minor) {
  8204. return 1;
  8205. }
  8206. if (a.minor < b.minor) {
  8207. return -1;
  8208. }
  8209. return 0;
  8210. };
  8211. /** @hidden */
  8212. GLTFFileLoader.prototype._logOpen = function (message) {
  8213. this._log(message);
  8214. this._logIndentLevel++;
  8215. };
  8216. /** @hidden */
  8217. GLTFFileLoader.prototype._logClose = function () {
  8218. --this._logIndentLevel;
  8219. };
  8220. GLTFFileLoader.prototype._logEnabled = function (message) {
  8221. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8222. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8223. };
  8224. GLTFFileLoader.prototype._logDisabled = function (message) {
  8225. };
  8226. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8227. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8228. };
  8229. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8230. };
  8231. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8232. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8233. };
  8234. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8235. };
  8236. // ----------
  8237. // V1 options
  8238. // ----------
  8239. /**
  8240. * 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.
  8241. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8242. * Defaults to true.
  8243. * @hidden
  8244. */
  8245. GLTFFileLoader.IncrementalLoading = true;
  8246. /**
  8247. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8248. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8249. * @hidden
  8250. */
  8251. GLTFFileLoader.HomogeneousCoordinates = false;
  8252. GLTFFileLoader._logSpaces = " ";
  8253. return GLTFFileLoader;
  8254. }());
  8255. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8256. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8257. }
  8258. /***/ }),
  8259. /***/ "./glTF/glTFValidation.ts":
  8260. /*!********************************!*\
  8261. !*** ./glTF/glTFValidation.ts ***!
  8262. \********************************/
  8263. /*! exports provided: GLTFValidation */
  8264. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8265. "use strict";
  8266. __webpack_require__.r(__webpack_exports__);
  8267. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  8268. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  8269. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  8270. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  8271. var options = {
  8272. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  8273. };
  8274. if (fileName) {
  8275. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  8276. }
  8277. return (data instanceof ArrayBuffer)
  8278. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  8279. : GLTFValidator.validateString(data, options);
  8280. }
  8281. /**
  8282. * The worker function that gets converted to a blob url to pass into a worker.
  8283. */
  8284. function workerFunc() {
  8285. var pendingExternalResources = [];
  8286. onmessage = function (message) {
  8287. var data = message.data;
  8288. switch (data.id) {
  8289. case "init": {
  8290. importScripts(data.url);
  8291. break;
  8292. }
  8293. case "validate": {
  8294. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  8295. var index = pendingExternalResources.length;
  8296. pendingExternalResources.push({ resolve: resolve, reject: reject });
  8297. postMessage({ id: "getExternalResource", index: index, uri: uri });
  8298. }); }).then(function (value) {
  8299. postMessage({ id: "validate.resolve", value: value });
  8300. }, function (reason) {
  8301. postMessage({ id: "validate.reject", reason: reason });
  8302. });
  8303. break;
  8304. }
  8305. case "getExternalResource.resolve": {
  8306. pendingExternalResources[data.index].resolve(data.value);
  8307. break;
  8308. }
  8309. case "getExternalResource.reject": {
  8310. pendingExternalResources[data.index].reject(data.reason);
  8311. break;
  8312. }
  8313. }
  8314. };
  8315. }
  8316. /**
  8317. * glTF validation
  8318. */
  8319. var GLTFValidation = /** @class */ (function () {
  8320. function GLTFValidation() {
  8321. }
  8322. /**
  8323. * Validate a glTF asset using the glTF-Validator.
  8324. * @param data The JSON of a glTF or the array buffer of a binary glTF
  8325. * @param rootUrl The root url for the glTF
  8326. * @param fileName The file name for the glTF
  8327. * @param getExternalResource The callback to get external resources for the glTF validator
  8328. * @returns A promise that resolves with the glTF validation results once complete
  8329. */
  8330. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  8331. var _this = this;
  8332. if (typeof Worker === "function") {
  8333. return new Promise(function (resolve, reject) {
  8334. var workerContent = validateAsync + "(" + workerFunc + ")()";
  8335. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  8336. var worker = new Worker(workerBlobUrl);
  8337. var onError = function (error) {
  8338. worker.removeEventListener("error", onError);
  8339. worker.removeEventListener("message", onMessage);
  8340. reject(error);
  8341. };
  8342. var onMessage = function (message) {
  8343. var data = message.data;
  8344. switch (data.id) {
  8345. case "getExternalResource": {
  8346. getExternalResource(data.uri).then(function (value) {
  8347. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  8348. }, function (reason) {
  8349. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  8350. });
  8351. break;
  8352. }
  8353. case "validate.resolve": {
  8354. worker.removeEventListener("error", onError);
  8355. worker.removeEventListener("message", onMessage);
  8356. resolve(data.value);
  8357. break;
  8358. }
  8359. case "validate.reject": {
  8360. worker.removeEventListener("error", onError);
  8361. worker.removeEventListener("message", onMessage);
  8362. reject(data.reason);
  8363. }
  8364. }
  8365. };
  8366. worker.addEventListener("error", onError);
  8367. worker.addEventListener("message", onMessage);
  8368. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  8369. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  8370. });
  8371. }
  8372. else {
  8373. if (!this._LoadScriptPromise) {
  8374. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  8375. }
  8376. return this._LoadScriptPromise.then(function () {
  8377. return validateAsync(data, rootUrl, fileName, getExternalResource);
  8378. });
  8379. }
  8380. };
  8381. /**
  8382. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  8383. */
  8384. GLTFValidation.Configuration = {
  8385. url: "https://preview.babylonjs.com/gltf_validator.js"
  8386. };
  8387. return GLTFValidation;
  8388. }());
  8389. /***/ }),
  8390. /***/ "./glTF/index.ts":
  8391. /*!***********************!*\
  8392. !*** ./glTF/index.ts ***!
  8393. \***********************/
  8394. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  8395. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8396. "use strict";
  8397. __webpack_require__.r(__webpack_exports__);
  8398. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8399. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8400. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8401. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8402. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8403. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8404. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8405. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  8406. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  8407. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  8408. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  8409. /***/ }),
  8410. /***/ "./index.ts":
  8411. /*!******************!*\
  8412. !*** ./index.ts ***!
  8413. \******************/
  8414. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8415. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8416. "use strict";
  8417. __webpack_require__.r(__webpack_exports__);
  8418. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  8419. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8420. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8421. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8422. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8423. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  8424. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  8425. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  8426. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  8427. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  8428. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  8429. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  8430. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  8431. /***/ }),
  8432. /***/ "./legacy/legacy-glTF.ts":
  8433. /*!*******************************!*\
  8434. !*** ./legacy/legacy-glTF.ts ***!
  8435. \*******************************/
  8436. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  8437. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8438. "use strict";
  8439. __webpack_require__.r(__webpack_exports__);
  8440. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8441. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  8442. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8443. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8444. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8445. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8446. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  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. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  8455. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  8456. }
  8457. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  8458. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  8459. }
  8460. }
  8461. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8462. /***/ }),
  8463. /***/ "./legacy/legacy-glTF1.ts":
  8464. /*!********************************!*\
  8465. !*** ./legacy/legacy-glTF1.ts ***!
  8466. \********************************/
  8467. /*! exports provided: GLTF1 */
  8468. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8469. "use strict";
  8470. __webpack_require__.r(__webpack_exports__);
  8471. /* 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");
  8472. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  8473. /**
  8474. * This is the entry point for the UMD module.
  8475. * The entry point for a future ESM package should be index.ts
  8476. */
  8477. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8478. if (typeof globalObject !== "undefined") {
  8479. globalObject.BABYLON = globalObject.BABYLON || {};
  8480. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  8481. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  8482. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  8483. }
  8484. }
  8485. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8486. /***/ }),
  8487. /***/ "./legacy/legacy-glTF2.ts":
  8488. /*!********************************!*\
  8489. !*** ./legacy/legacy-glTF2.ts ***!
  8490. \********************************/
  8491. /*! exports provided: GLTF2 */
  8492. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8493. "use strict";
  8494. __webpack_require__.r(__webpack_exports__);
  8495. /* 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");
  8496. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8497. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  8498. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  8499. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  8500. /**
  8501. * This is the entry point for the UMD module.
  8502. * The entry point for a future ESM package should be index.ts
  8503. */
  8504. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8505. if (typeof globalObject !== "undefined") {
  8506. globalObject.BABYLON = globalObject.BABYLON || {};
  8507. var BABYLON = globalObject.BABYLON;
  8508. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  8509. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  8510. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  8511. var keys = [];
  8512. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  8513. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  8514. keys.push(key);
  8515. }
  8516. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  8517. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  8518. keys.push(key);
  8519. }
  8520. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  8521. // Prevent Reassignment.
  8522. if (keys.indexOf(key) > -1) {
  8523. continue;
  8524. }
  8525. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  8526. }
  8527. }
  8528. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8529. /***/ }),
  8530. /***/ "./legacy/legacy-objFileLoader.ts":
  8531. /*!****************************************!*\
  8532. !*** ./legacy/legacy-objFileLoader.ts ***!
  8533. \****************************************/
  8534. /*! exports provided: MTLFileLoader, OBJFileLoader */
  8535. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8536. "use strict";
  8537. __webpack_require__.r(__webpack_exports__);
  8538. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  8539. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  8540. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  8541. /**
  8542. * This is the entry point for the UMD module.
  8543. * The entry point for a future ESM package should be index.ts
  8544. */
  8545. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8546. if (typeof globalObject !== "undefined") {
  8547. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  8548. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  8549. }
  8550. }
  8551. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8552. /***/ }),
  8553. /***/ "./legacy/legacy-stlFileLoader.ts":
  8554. /*!****************************************!*\
  8555. !*** ./legacy/legacy-stlFileLoader.ts ***!
  8556. \****************************************/
  8557. /*! exports provided: STLFileLoader */
  8558. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8559. "use strict";
  8560. __webpack_require__.r(__webpack_exports__);
  8561. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  8562. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  8563. /**
  8564. * This is the entry point for the UMD module.
  8565. * The entry point for a future ESM package should be index.ts
  8566. */
  8567. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8568. if (typeof globalObject !== "undefined") {
  8569. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  8570. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  8571. }
  8572. }
  8573. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8574. /***/ }),
  8575. /***/ "./legacy/legacy.ts":
  8576. /*!**************************!*\
  8577. !*** ./legacy/legacy.ts ***!
  8578. \**************************/
  8579. /*! exports provided: GLTF1, GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8580. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8581. "use strict";
  8582. __webpack_require__.r(__webpack_exports__);
  8583. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  8584. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  8585. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  8586. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  8587. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  8588. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  8589. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8590. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  8591. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  8592. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  8593. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  8594. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  8595. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  8596. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  8597. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  8598. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  8599. /***/ }),
  8600. /***/ "babylonjs/Misc/tools":
  8601. /*!****************************************************************************************************!*\
  8602. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  8603. \****************************************************************************************************/
  8604. /*! no static exports found */
  8605. /***/ (function(module, exports) {
  8606. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  8607. /***/ })
  8608. /******/ });
  8609. });
  8610. //# sourceMappingURL=babylonjs.loaders.js.map