babylonjs.loaders.js 450 KB

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