babylonjs.loaders.js 524 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501
  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, __createBinding, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault, __classPrivateFieldGet, __classPrivateFieldSet */
  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__, "__createBinding", function() { return __createBinding; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  126. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  127. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__classPrivateFieldGet", function() { return __classPrivateFieldGet; });
  128. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__classPrivateFieldSet", function() { return __classPrivateFieldSet; });
  129. /*! *****************************************************************************
  130. Copyright (c) Microsoft Corporation.
  131. Permission to use, copy, modify, and/or distribute this software for any
  132. purpose with or without fee is hereby granted.
  133. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  134. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  135. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  136. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  137. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  138. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  139. PERFORMANCE OF THIS SOFTWARE.
  140. ***************************************************************************** */
  141. /* global Reflect, Promise */
  142. var extendStatics = function(d, b) {
  143. extendStatics = Object.setPrototypeOf ||
  144. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  145. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  146. return extendStatics(d, b);
  147. };
  148. function __extends(d, b) {
  149. extendStatics(d, b);
  150. function __() { this.constructor = d; }
  151. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  152. }
  153. var __assign = function() {
  154. __assign = Object.assign || function __assign(t) {
  155. for (var s, i = 1, n = arguments.length; i < n; i++) {
  156. s = arguments[i];
  157. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  158. }
  159. return t;
  160. }
  161. return __assign.apply(this, arguments);
  162. }
  163. function __rest(s, e) {
  164. var t = {};
  165. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  166. t[p] = s[p];
  167. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  168. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  169. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  170. t[p[i]] = s[p[i]];
  171. }
  172. return t;
  173. }
  174. function __decorate(decorators, target, key, desc) {
  175. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  176. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  177. 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;
  178. return c > 3 && r && Object.defineProperty(target, key, r), r;
  179. }
  180. function __param(paramIndex, decorator) {
  181. return function (target, key) { decorator(target, key, paramIndex); }
  182. }
  183. function __metadata(metadataKey, metadataValue) {
  184. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  185. }
  186. function __awaiter(thisArg, _arguments, P, generator) {
  187. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  188. return new (P || (P = Promise))(function (resolve, reject) {
  189. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  190. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  191. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  192. step((generator = generator.apply(thisArg, _arguments || [])).next());
  193. });
  194. }
  195. function __generator(thisArg, body) {
  196. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  197. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  198. function verb(n) { return function (v) { return step([n, v]); }; }
  199. function step(op) {
  200. if (f) throw new TypeError("Generator is already executing.");
  201. while (_) try {
  202. 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;
  203. if (y = 0, t) op = [op[0] & 2, t.value];
  204. switch (op[0]) {
  205. case 0: case 1: t = op; break;
  206. case 4: _.label++; return { value: op[1], done: false };
  207. case 5: _.label++; y = op[1]; op = [0]; continue;
  208. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  209. default:
  210. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  211. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  212. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  213. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  214. if (t[2]) _.ops.pop();
  215. _.trys.pop(); continue;
  216. }
  217. op = body.call(thisArg, _);
  218. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  219. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  220. }
  221. }
  222. var __createBinding = Object.create ? (function(o, m, k, k2) {
  223. if (k2 === undefined) k2 = k;
  224. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  225. }) : (function(o, m, k, k2) {
  226. if (k2 === undefined) k2 = k;
  227. o[k2] = m[k];
  228. });
  229. function __exportStar(m, o) {
  230. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
  231. }
  232. function __values(o) {
  233. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  234. if (m) return m.call(o);
  235. if (o && typeof o.length === "number") return {
  236. next: function () {
  237. if (o && i >= o.length) o = void 0;
  238. return { value: o && o[i++], done: !o };
  239. }
  240. };
  241. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  242. }
  243. function __read(o, n) {
  244. var m = typeof Symbol === "function" && o[Symbol.iterator];
  245. if (!m) return o;
  246. var i = m.call(o), r, ar = [], e;
  247. try {
  248. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  249. }
  250. catch (error) { e = { error: error }; }
  251. finally {
  252. try {
  253. if (r && !r.done && (m = i["return"])) m.call(i);
  254. }
  255. finally { if (e) throw e.error; }
  256. }
  257. return ar;
  258. }
  259. function __spread() {
  260. for (var ar = [], i = 0; i < arguments.length; i++)
  261. ar = ar.concat(__read(arguments[i]));
  262. return ar;
  263. }
  264. function __spreadArrays() {
  265. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  266. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  267. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  268. r[k] = a[j];
  269. return r;
  270. };
  271. function __await(v) {
  272. return this instanceof __await ? (this.v = v, this) : new __await(v);
  273. }
  274. function __asyncGenerator(thisArg, _arguments, generator) {
  275. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  276. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  277. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  278. 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); }); }; }
  279. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  280. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  281. function fulfill(value) { resume("next", value); }
  282. function reject(value) { resume("throw", value); }
  283. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  284. }
  285. function __asyncDelegator(o) {
  286. var i, p;
  287. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  288. 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; }
  289. }
  290. function __asyncValues(o) {
  291. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  292. var m = o[Symbol.asyncIterator], i;
  293. 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);
  294. 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); }); }; }
  295. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  296. }
  297. function __makeTemplateObject(cooked, raw) {
  298. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  299. return cooked;
  300. };
  301. var __setModuleDefault = Object.create ? (function(o, v) {
  302. Object.defineProperty(o, "default", { enumerable: true, value: v });
  303. }) : function(o, v) {
  304. o["default"] = v;
  305. };
  306. function __importStar(mod) {
  307. if (mod && mod.__esModule) return mod;
  308. var result = {};
  309. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  310. __setModuleDefault(result, mod);
  311. return result;
  312. }
  313. function __importDefault(mod) {
  314. return (mod && mod.__esModule) ? mod : { default: mod };
  315. }
  316. function __classPrivateFieldGet(receiver, privateMap) {
  317. if (!privateMap.has(receiver)) {
  318. throw new TypeError("attempted to get private field on non-instance");
  319. }
  320. return privateMap.get(receiver);
  321. }
  322. function __classPrivateFieldSet(receiver, privateMap, value) {
  323. if (!privateMap.has(receiver)) {
  324. throw new TypeError("attempted to set private field on non-instance");
  325. }
  326. privateMap.set(receiver, value);
  327. return value;
  328. }
  329. /***/ }),
  330. /***/ "../../node_modules/webpack/buildin/global.js":
  331. /*!***********************************!*\
  332. !*** (webpack)/buildin/global.js ***!
  333. \***********************************/
  334. /*! no static exports found */
  335. /***/ (function(module, exports) {
  336. var g;
  337. // This works in non-strict mode
  338. g = (function() {
  339. return this;
  340. })();
  341. try {
  342. // This works if eval is allowed (see CSP)
  343. g = g || new Function("return this")();
  344. } catch (e) {
  345. // This works if the window reference is available
  346. if (typeof window === "object") g = window;
  347. }
  348. // g can still be undefined, but nothing to do about it...
  349. // We return undefined, instead of nothing here, so it's
  350. // easier to handle this case. if(!global) { ...}
  351. module.exports = g;
  352. /***/ }),
  353. /***/ "./OBJ/index.ts":
  354. /*!**********************!*\
  355. !*** ./OBJ/index.ts ***!
  356. \**********************/
  357. /*! exports provided: MTLFileLoader, OBJFileLoader */
  358. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  359. "use strict";
  360. __webpack_require__.r(__webpack_exports__);
  361. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  362. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  363. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  364. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  365. /***/ }),
  366. /***/ "./OBJ/mtlFileLoader.ts":
  367. /*!******************************!*\
  368. !*** ./OBJ/mtlFileLoader.ts ***!
  369. \******************************/
  370. /*! exports provided: MTLFileLoader */
  371. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  372. "use strict";
  373. __webpack_require__.r(__webpack_exports__);
  374. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  375. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  376. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  377. /**
  378. * Class reading and parsing the MTL file bundled with the obj file.
  379. */
  380. var MTLFileLoader = /** @class */ (function () {
  381. function MTLFileLoader() {
  382. /**
  383. * All material loaded from the mtl will be set here
  384. */
  385. this.materials = [];
  386. }
  387. /**
  388. * This function will read the mtl file and create each material described inside
  389. * This function could be improve by adding :
  390. * -some component missing (Ni, Tf...)
  391. * -including the specific options available
  392. *
  393. * @param scene defines the scene the material will be created in
  394. * @param data defines the mtl data to parse
  395. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  396. * @param forAssetContainer defines if the material should be registered in the scene
  397. */
  398. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl, forAssetContainer) {
  399. if (data instanceof ArrayBuffer) {
  400. return;
  401. }
  402. //Split the lines from the file
  403. var lines = data.split('\n');
  404. //Space char
  405. var delimiter_pattern = /\s+/;
  406. //Array with RGB colors
  407. var color;
  408. //New material
  409. var material = null;
  410. //Look at each line
  411. for (var i = 0; i < lines.length; i++) {
  412. var line = lines[i].trim();
  413. // Blank line or comment
  414. if (line.length === 0 || line.charAt(0) === '#') {
  415. continue;
  416. }
  417. //Get the first parameter (keyword)
  418. var pos = line.indexOf(' ');
  419. var key = (pos >= 0) ? line.substring(0, pos) : line;
  420. key = key.toLowerCase();
  421. //Get the data following the key
  422. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  423. //This mtl keyword will create the new material
  424. if (key === "newmtl") {
  425. //Check if it is the first material.
  426. // Materials specifications are described after this keyword.
  427. if (material) {
  428. //Add the previous material in the material array.
  429. this.materials.push(material);
  430. }
  431. //Create a new material.
  432. // value is the name of the material read in the mtl file
  433. scene._blockEntityCollection = forAssetContainer;
  434. material = new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"](value, scene);
  435. scene._blockEntityCollection = false;
  436. }
  437. else if (key === "kd" && material) {
  438. // Diffuse color (color under white light) using RGB values
  439. //value = "r g b"
  440. color = value.split(delimiter_pattern, 3).map(parseFloat);
  441. //color = [r,g,b]
  442. //Set tghe color into the material
  443. material.diffuseColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  444. }
  445. else if (key === "ka" && material) {
  446. // Ambient color (color under shadow) using RGB values
  447. //value = "r g b"
  448. color = value.split(delimiter_pattern, 3).map(parseFloat);
  449. //color = [r,g,b]
  450. //Set tghe color into the material
  451. material.ambientColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  452. }
  453. else if (key === "ks" && material) {
  454. // Specular color (color when light is reflected from shiny surface) using RGB values
  455. //value = "r g b"
  456. color = value.split(delimiter_pattern, 3).map(parseFloat);
  457. //color = [r,g,b]
  458. //Set the color into the material
  459. material.specularColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  460. }
  461. else if (key === "ke" && material) {
  462. // Emissive color using RGB values
  463. color = value.split(delimiter_pattern, 3).map(parseFloat);
  464. material.emissiveColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  465. }
  466. else if (key === "ns" && material) {
  467. //value = "Integer"
  468. material.specularPower = parseFloat(value);
  469. }
  470. else if (key === "d" && material) {
  471. //d is dissolve for current material. It mean alpha for BABYLON
  472. material.alpha = parseFloat(value);
  473. //Texture
  474. //This part can be improved by adding the possible options of texture
  475. }
  476. else if (key === "map_ka" && material) {
  477. // ambient texture map with a loaded image
  478. //We must first get the folder of the image
  479. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  480. }
  481. else if (key === "map_kd" && material) {
  482. // Diffuse texture map with a loaded image
  483. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  484. }
  485. else if (key === "map_ks" && material) {
  486. // Specular texture map with a loaded image
  487. //We must first get the folder of the image
  488. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  489. }
  490. else if (key === "map_ns") {
  491. //Specular
  492. //Specular highlight component
  493. //We must first get the folder of the image
  494. //
  495. //Not supported by BABYLON
  496. //
  497. // continue;
  498. }
  499. else if (key === "map_bump" && material) {
  500. //The bump texture
  501. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  502. }
  503. else if (key === "map_d" && material) {
  504. // The dissolve of the material
  505. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  506. //Options for illumination
  507. }
  508. else if (key === "illum") {
  509. //Illumination
  510. if (value === "0") {
  511. //That mean Kd == Kd
  512. }
  513. else if (value === "1") {
  514. //Color on and Ambient on
  515. }
  516. else if (value === "2") {
  517. //Highlight on
  518. }
  519. else if (value === "3") {
  520. //Reflection on and Ray trace on
  521. }
  522. else if (value === "4") {
  523. //Transparency: Glass on, Reflection: Ray trace on
  524. }
  525. else if (value === "5") {
  526. //Reflection: Fresnel on and Ray trace on
  527. }
  528. else if (value === "6") {
  529. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  530. }
  531. else if (value === "7") {
  532. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  533. }
  534. else if (value === "8") {
  535. //Reflection on and Ray trace off
  536. }
  537. else if (value === "9") {
  538. //Transparency: Glass on, Reflection: Ray trace off
  539. }
  540. else if (value === "10") {
  541. //Casts shadows onto invisible surfaces
  542. }
  543. }
  544. else {
  545. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  546. }
  547. }
  548. //At the end of the file, add the last material
  549. if (material) {
  550. this.materials.push(material);
  551. }
  552. };
  553. /**
  554. * Gets the texture for the material.
  555. *
  556. * If the material is imported from input file,
  557. * We sanitize the url to ensure it takes the textre from aside the material.
  558. *
  559. * @param rootUrl The root url to load from
  560. * @param value The value stored in the mtl
  561. * @return The Texture
  562. */
  563. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  564. if (!value) {
  565. return null;
  566. }
  567. var url = rootUrl;
  568. // Load from input file.
  569. if (rootUrl === "file:") {
  570. var lastDelimiter = value.lastIndexOf("\\");
  571. if (lastDelimiter === -1) {
  572. lastDelimiter = value.lastIndexOf("/");
  573. }
  574. if (lastDelimiter > -1) {
  575. url += value.substr(lastDelimiter + 1);
  576. }
  577. else {
  578. url += value;
  579. }
  580. }
  581. // Not from input file.
  582. else {
  583. url += value;
  584. }
  585. return new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
  586. };
  587. /**
  588. * Invert Y-Axis of referenced textures on load
  589. */
  590. MTLFileLoader.INVERT_TEXTURE_Y = true;
  591. return MTLFileLoader;
  592. }());
  593. /***/ }),
  594. /***/ "./OBJ/objFileLoader.ts":
  595. /*!******************************!*\
  596. !*** ./OBJ/objFileLoader.ts ***!
  597. \******************************/
  598. /*! exports provided: OBJFileLoader */
  599. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  600. "use strict";
  601. __webpack_require__.r(__webpack_exports__);
  602. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  603. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  604. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  605. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  606. /**
  607. * OBJ file type loader.
  608. * This is a babylon scene loader plugin.
  609. */
  610. var OBJFileLoader = /** @class */ (function () {
  611. /**
  612. * Creates loader for .OBJ files
  613. *
  614. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  615. */
  616. function OBJFileLoader(meshLoadOptions) {
  617. /**
  618. * Defines the name of the plugin.
  619. */
  620. this.name = "obj";
  621. /**
  622. * Defines the extension the plugin is able to load.
  623. */
  624. this.extensions = ".obj";
  625. /** @hidden */
  626. this.obj = /^o/;
  627. /** @hidden */
  628. this.group = /^g/;
  629. /** @hidden */
  630. this.mtllib = /^mtllib /;
  631. /** @hidden */
  632. this.usemtl = /^usemtl /;
  633. /** @hidden */
  634. this.smooth = /^s /;
  635. /** @hidden */
  636. this.vertexPattern = /v(\s+[\d|\.|\+|\-|e|E]+){3,7}/;
  637. // vn float float float
  638. /** @hidden */
  639. this.normalPattern = /vn(\s+[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  640. // vt float float
  641. /** @hidden */
  642. this.uvPattern = /vt(\s+[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  643. // f vertex vertex vertex ...
  644. /** @hidden */
  645. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  646. // f vertex/uvs vertex/uvs vertex/uvs ...
  647. /** @hidden */
  648. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  649. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  650. /** @hidden */
  651. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  652. // f vertex//normal vertex//normal vertex//normal ...
  653. /** @hidden */
  654. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  655. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  656. /** @hidden */
  657. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  658. this._forAssetContainer = false;
  659. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  660. }
  661. Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
  662. /**
  663. * Invert Y-Axis of referenced textures on load
  664. */
  665. get: function () {
  666. return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y;
  667. },
  668. set: function (value) {
  669. _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y = value;
  670. },
  671. enumerable: false,
  672. configurable: true
  673. });
  674. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  675. get: function () {
  676. return {
  677. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  678. OptimizeNormals: OBJFileLoader.OPTIMIZE_NORMALS,
  679. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  680. InvertY: OBJFileLoader.INVERT_Y,
  681. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  682. UVScaling: OBJFileLoader.UV_SCALING,
  683. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  684. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  685. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  686. };
  687. },
  688. enumerable: false,
  689. configurable: true
  690. });
  691. /**
  692. * Calls synchronously the MTL file attached to this obj.
  693. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  694. * Without this function materials are not displayed in the first frame (but displayed after).
  695. * In consequence it is impossible to get material information in your HTML file
  696. *
  697. * @param url The URL of the MTL file
  698. * @param rootUrl
  699. * @param onSuccess Callback function to be called when the MTL file is loaded
  700. * @private
  701. */
  702. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  703. //The complete path to the mtl file
  704. var pathOfFile = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  705. // Loads through the babylon tools to allow fileInput search.
  706. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  707. onFailure(pathOfFile, exception);
  708. });
  709. };
  710. /**
  711. * Instantiates a OBJ file loader plugin.
  712. * @returns the created plugin
  713. */
  714. OBJFileLoader.prototype.createPlugin = function () {
  715. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  716. };
  717. /**
  718. * If the data string can be loaded directly.
  719. *
  720. * @param data string containing the file data
  721. * @returns if the data can be loaded directly
  722. */
  723. OBJFileLoader.prototype.canDirectLoad = function (data) {
  724. return false;
  725. };
  726. /**
  727. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  728. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  729. * @param scene the scene the meshes should be added to
  730. * @param data the OBJ data to load
  731. * @param rootUrl root url to load from
  732. * @param onProgress event that fires when loading progress has occured
  733. * @param fileName Defines the name of the file to load
  734. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  735. */
  736. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  737. //get the meshes from OBJ file
  738. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  739. return {
  740. meshes: meshes,
  741. particleSystems: [],
  742. skeletons: [],
  743. animationGroups: [],
  744. transformNodes: [],
  745. geometries: [],
  746. lights: []
  747. };
  748. });
  749. };
  750. /**
  751. * Imports all objects from the loaded OBJ data and adds them to the scene
  752. * @param scene the scene the objects should be added to
  753. * @param data the OBJ data to load
  754. * @param rootUrl root url to load from
  755. * @param onProgress event that fires when loading progress has occured
  756. * @param fileName Defines the name of the file to load
  757. * @returns a promise which completes when objects have been loaded to the scene
  758. */
  759. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  760. //Get the 3D model
  761. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  762. // return void
  763. });
  764. };
  765. /**
  766. * Load into an asset container.
  767. * @param scene The scene to load into
  768. * @param data The data to import
  769. * @param rootUrl The root url for scene and resources
  770. * @param onProgress The callback when the load progresses
  771. * @param fileName Defines the name of the file to load
  772. * @returns The loaded asset container
  773. */
  774. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  775. var _this = this;
  776. this._forAssetContainer = true;
  777. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  778. var container = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  779. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  780. result.meshes.forEach(function (mesh) {
  781. var material = mesh.material;
  782. if (material) {
  783. // Materials
  784. if (container.materials.indexOf(material) == -1) {
  785. container.materials.push(material);
  786. // Textures
  787. var textures = material.getActiveTextures();
  788. textures.forEach(function (t) {
  789. if (container.textures.indexOf(t) == -1) {
  790. container.textures.push(t);
  791. }
  792. });
  793. }
  794. }
  795. });
  796. _this._forAssetContainer = false;
  797. return container;
  798. }).catch(function (ex) {
  799. _this._forAssetContainer = false;
  800. throw ex;
  801. });
  802. };
  803. OBJFileLoader.prototype._optimizeNormals = function (mesh) {
  804. var positions = mesh.getVerticesData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  805. var normals = mesh.getVerticesData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  806. var mapVertices = {};
  807. if (!positions || !normals) {
  808. return;
  809. }
  810. for (var i = 0; i < positions.length / 3; i++) {
  811. var x = positions[i * 3 + 0];
  812. var y = positions[i * 3 + 1];
  813. var z = positions[i * 3 + 2];
  814. var key = x + "_" + y + "_" + z;
  815. var lst = mapVertices[key];
  816. if (!lst) {
  817. lst = [];
  818. mapVertices[key] = lst;
  819. }
  820. lst.push(i);
  821. }
  822. var normal = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"]();
  823. for (var key in mapVertices) {
  824. var lst = mapVertices[key];
  825. if (lst.length < 2) {
  826. continue;
  827. }
  828. var v0Idx = lst[0];
  829. for (var i = 1; i < lst.length; ++i) {
  830. var vIdx = lst[i];
  831. normals[v0Idx * 3 + 0] += normals[vIdx * 3 + 0];
  832. normals[v0Idx * 3 + 1] += normals[vIdx * 3 + 1];
  833. normals[v0Idx * 3 + 2] += normals[vIdx * 3 + 2];
  834. }
  835. normal.copyFromFloats(normals[v0Idx * 3 + 0], normals[v0Idx * 3 + 1], normals[v0Idx * 3 + 2]);
  836. normal.normalize();
  837. for (var i = 0; i < lst.length; ++i) {
  838. var vIdx = lst[i];
  839. normals[vIdx * 3 + 0] = normal.x;
  840. normals[vIdx * 3 + 1] = normal.y;
  841. normals[vIdx * 3 + 2] = normal.z;
  842. }
  843. }
  844. mesh.setVerticesData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  845. };
  846. /**
  847. * Read the OBJ file and create an Array of meshes.
  848. * Each mesh contains all information given by the OBJ and the MTL file.
  849. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  850. *
  851. * @param meshesNames
  852. * @param scene Scene The scene where are displayed the data
  853. * @param data String The content of the obj file
  854. * @param rootUrl String The path to the folder
  855. * @returns Array<AbstractMesh>
  856. * @private
  857. */
  858. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  859. var _this = this;
  860. var positions = []; //values for the positions of vertices
  861. var normals = []; //Values for the normals
  862. var uvs = []; //Values for the textures
  863. var colors = [];
  864. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  865. var handledMesh; //The current mesh of meshes array
  866. var indicesForBabylon = []; //The list of indices for VertexData
  867. var wrappedPositionForBabylon = []; //The list of position in vectors
  868. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  869. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  870. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  871. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  872. var curPositionInIndices = 0;
  873. var hasMeshes = false; //Meshes are defined in the file
  874. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  875. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  876. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  877. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  878. var triangles = []; //Indices from new triangles coming from polygons
  879. var materialNameFromObj = ""; //The name of the current material
  880. var fileToLoad = ""; //The name of the mtlFile to load
  881. var materialsFromMTLFile = new _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]();
  882. var objMeshName = ""; //The name of the current obj mesh
  883. var increment = 1; //Id for meshes created by the multimaterial
  884. var isFirstMaterial = true;
  885. var grayColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  886. /**
  887. * Search for obj in the given array.
  888. * This function is called to check if a couple of data already exists in an array.
  889. *
  890. * If found, returns the index of the founded tuple index. Returns -1 if not found
  891. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  892. * @param obj Array<number>
  893. * @returns {boolean}
  894. */
  895. var isInArray = function (arr, obj) {
  896. if (!arr[obj[0]]) {
  897. arr[obj[0]] = { normals: [], idx: [] };
  898. }
  899. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  900. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  901. };
  902. var isInArrayUV = function (arr, obj) {
  903. if (!arr[obj[0]]) {
  904. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  905. }
  906. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  907. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  908. return arr[obj[0]].idx[idx];
  909. }
  910. return -1;
  911. };
  912. /**
  913. * This function set the data for each triangle.
  914. * Data are position, normals and uvs
  915. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  916. * If the tuple already exist, add only their indice
  917. *
  918. * @param indicePositionFromObj Integer The index in positions array
  919. * @param indiceUvsFromObj Integer The index in uvs array
  920. * @param indiceNormalFromObj Integer The index in normals array
  921. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  922. * @param textureVectorFromOBJ Vector3 The value of uvs
  923. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  924. */
  925. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  926. //Check if this tuple already exists in the list of tuples
  927. var _index;
  928. if (_this._meshLoadOptions.OptimizeWithUV) {
  929. _index = isInArrayUV(tuplePosNorm, [
  930. indicePositionFromObj,
  931. indiceNormalFromObj,
  932. indiceUvsFromObj
  933. ]);
  934. }
  935. else {
  936. _index = isInArray(tuplePosNorm, [
  937. indicePositionFromObj,
  938. indiceNormalFromObj
  939. ]);
  940. }
  941. //If it not exists
  942. if (_index === -1) {
  943. //Add an new indice.
  944. //The array of indices is only an array with his length equal to the number of triangles - 1.
  945. //We add vertices data in this order
  946. indicesForBabylon.push(wrappedPositionForBabylon.length);
  947. //Push the position of vertice for Babylon
  948. //Each element is a Vector3(x,y,z)
  949. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  950. //Push the uvs for Babylon
  951. //Each element is a Vector3(u,v)
  952. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  953. //Push the normals for Babylon
  954. //Each element is a Vector3(x,y,z)
  955. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  956. if (positionColorsFromOBJ !== undefined) {
  957. //Push the colors for Babylon
  958. //Each element is a BABYLON.Color4(r,g,b,a)
  959. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  960. }
  961. //Add the tuple in the comparison list
  962. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  963. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  964. if (_this._meshLoadOptions.OptimizeWithUV) {
  965. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  966. }
  967. }
  968. else {
  969. //The tuple already exists
  970. //Add the index of the already existing tuple
  971. //At this index we can get the value of position, normal, color and uvs of vertex
  972. indicesForBabylon.push(_index);
  973. }
  974. };
  975. /**
  976. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  977. */
  978. var unwrapData = function () {
  979. //Every array has the same length
  980. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  981. //Push the x, y, z values of each element in the unwrapped array
  982. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  983. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  984. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  985. if (_this._meshLoadOptions.ImportVertexColors === true) {
  986. //Push the r, g, b, a values of each element in the unwrapped array
  987. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  988. }
  989. }
  990. // Reset arrays for the next new meshes
  991. wrappedPositionForBabylon = [];
  992. wrappedNormalsForBabylon = [];
  993. wrappedUvsForBabylon = [];
  994. wrappedColorsForBabylon = [];
  995. tuplePosNorm = [];
  996. curPositionInIndices = 0;
  997. };
  998. /**
  999. * Create triangles from polygons
  1000. * It is important to notice that a triangle is a polygon
  1001. * We get 5 patterns of face defined in OBJ File :
  1002. * facePattern1 = ["1","2","3","4","5","6"]
  1003. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  1004. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  1005. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  1006. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  1007. * Each pattern is divided by the same method
  1008. * @param face Array[String] The indices of elements
  1009. * @param v Integer The variable to increment
  1010. */
  1011. var getTriangles = function (faces, v) {
  1012. //Work for each element of the array
  1013. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  1014. //Add on the triangle variable the indexes to obtain triangles
  1015. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  1016. }
  1017. //Result obtained after 2 iterations:
  1018. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  1019. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  1020. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  1021. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  1022. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  1023. };
  1024. /**
  1025. * Create triangles and push the data for each polygon for the pattern 1
  1026. * In this pattern we get vertice positions
  1027. * @param face
  1028. * @param v
  1029. */
  1030. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  1031. //Get the indices of triangles for each polygon
  1032. getTriangles(face, v);
  1033. //For each element in the triangles array.
  1034. //This var could contains 1 to an infinity of triangles
  1035. for (var k = 0; k < triangles.length; k++) {
  1036. // Set position indice
  1037. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  1038. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  1039. positions[indicePositionFromObj], //Get the vectors data
  1040. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  1041. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1042. }
  1043. //Reset variable for the next line
  1044. triangles = [];
  1045. };
  1046. /**
  1047. * Create triangles and push the data for each polygon for the pattern 2
  1048. * In this pattern we get vertice positions and uvsu
  1049. * @param face
  1050. * @param v
  1051. */
  1052. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  1053. //Get the indices of triangles for each polygon
  1054. getTriangles(face, v);
  1055. for (var k = 0; k < triangles.length; k++) {
  1056. //triangle[k] = "1/1"
  1057. //Split the data for getting position and uv
  1058. var point = triangles[k].split("/"); // ["1", "1"]
  1059. //Set position indice
  1060. var indicePositionFromObj = parseInt(point[0]) - 1;
  1061. //Set uv indice
  1062. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1063. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  1064. positions[indicePositionFromObj], //Get the values for each element
  1065. uvs[indiceUvsFromObj], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  1066. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1067. }
  1068. //Reset variable for the next line
  1069. triangles = [];
  1070. };
  1071. /**
  1072. * Create triangles and push the data for each polygon for the pattern 3
  1073. * In this pattern we get vertice positions, uvs and normals
  1074. * @param face
  1075. * @param v
  1076. */
  1077. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  1078. //Get the indices of triangles for each polygon
  1079. getTriangles(face, v);
  1080. for (var k = 0; k < triangles.length; k++) {
  1081. //triangle[k] = "1/1/1"
  1082. //Split the data for getting position, uv, and normals
  1083. var point = triangles[k].split("/"); // ["1", "1", "1"]
  1084. // Set position indice
  1085. var indicePositionFromObj = parseInt(point[0]) - 1;
  1086. // Set uv indice
  1087. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1088. // Set normal indice
  1089. var indiceNormalFromObj = parseInt(point[2]) - 1;
  1090. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  1091. );
  1092. }
  1093. //Reset variable for the next line
  1094. triangles = [];
  1095. };
  1096. /**
  1097. * Create triangles and push the data for each polygon for the pattern 4
  1098. * In this pattern we get vertice positions and normals
  1099. * @param face
  1100. * @param v
  1101. */
  1102. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  1103. getTriangles(face, v);
  1104. for (var k = 0; k < triangles.length; k++) {
  1105. //triangle[k] = "1//1"
  1106. //Split the data for getting position and normals
  1107. var point = triangles[k].split("//"); // ["1", "1"]
  1108. // We check indices, and normals
  1109. var indicePositionFromObj = parseInt(point[0]) - 1;
  1110. var indiceNormalFromObj = parseInt(point[1]) - 1;
  1111. setData(indicePositionFromObj, 1, //Default value for uv
  1112. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  1113. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1114. }
  1115. //Reset variable for the next line
  1116. triangles = [];
  1117. };
  1118. /**
  1119. * Create triangles and push the data for each polygon for the pattern 3
  1120. * In this pattern we get vertice positions, uvs and normals
  1121. * @param face
  1122. * @param v
  1123. */
  1124. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1125. //Get the indices of triangles for each polygon
  1126. getTriangles(face, v);
  1127. for (var k = 0; k < triangles.length; k++) {
  1128. //triangle[k] = "-1/-1/-1"
  1129. //Split the data for getting position, uv, and normals
  1130. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1131. // Set position indice
  1132. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1133. // Set uv indice
  1134. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1135. // Set normal indice
  1136. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1137. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1138. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1139. }
  1140. //Reset variable for the next line
  1141. triangles = [];
  1142. };
  1143. var addPreviousObjMesh = function () {
  1144. //Check if it is not the first mesh. Otherwise we don't have data.
  1145. if (meshesFromObj.length > 0) {
  1146. //Get the previous mesh for applying the data about the faces
  1147. //=> in obj file, faces definition append after the name of the mesh
  1148. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1149. //Set the data into Array for the mesh
  1150. unwrapData();
  1151. // Reverse tab. Otherwise face are displayed in the wrong sens
  1152. indicesForBabylon.reverse();
  1153. //Set the information for the mesh
  1154. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1155. handledMesh.indices = indicesForBabylon.slice();
  1156. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1157. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1158. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1159. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1160. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1161. }
  1162. //Reset the array for the next mesh
  1163. indicesForBabylon = [];
  1164. unwrappedPositionsForBabylon = [];
  1165. unwrappedColorsForBabylon = [];
  1166. unwrappedNormalsForBabylon = [];
  1167. unwrappedUVForBabylon = [];
  1168. }
  1169. };
  1170. //Main function
  1171. //Split the file into lines
  1172. var lines = data.split('\n');
  1173. //Look at each line
  1174. for (var i = 0; i < lines.length; i++) {
  1175. var line = lines[i].trim().replace(/\s\s/g, " ");
  1176. var result;
  1177. //Comment or newLine
  1178. if (line.length === 0 || line.charAt(0) === '#') {
  1179. continue;
  1180. //Get information about one position possible for the vertices
  1181. }
  1182. else if (this.vertexPattern.test(line)) {
  1183. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1184. // Value of result with line: "v 1.0 2.0 3.0"
  1185. // ["v", "1.0", "2.0", "3.0"]
  1186. // Create a Vector3 with the position x, y, z
  1187. positions.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1188. if (this._meshLoadOptions.ImportVertexColors === true) {
  1189. if (result.length >= 7) {
  1190. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1191. colors.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
  1192. }
  1193. else {
  1194. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1195. colors.push(grayColor);
  1196. }
  1197. }
  1198. }
  1199. else if ((result = this.normalPattern.exec(line)) !== null) {
  1200. //Create a Vector3 with the normals x, y, z
  1201. //Value of result
  1202. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1203. //Add the Vector in the list of normals
  1204. normals.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1205. }
  1206. else if ((result = this.uvPattern.exec(line)) !== null) {
  1207. //Create a Vector2 with the normals u, v
  1208. //Value of result
  1209. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1210. //Add the Vector in the list of uvs
  1211. uvs.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
  1212. //Identify patterns of faces
  1213. //Face could be defined in different type of pattern
  1214. }
  1215. else if ((result = this.facePattern3.exec(line)) !== null) {
  1216. //Value of result:
  1217. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1218. //Set the data for this face
  1219. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1220. 1);
  1221. }
  1222. else if ((result = this.facePattern4.exec(line)) !== null) {
  1223. //Value of result:
  1224. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1225. //Set the data for this face
  1226. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1227. 1);
  1228. }
  1229. else if ((result = this.facePattern5.exec(line)) !== null) {
  1230. //Value of result:
  1231. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1232. //Set the data for this face
  1233. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1234. 1);
  1235. }
  1236. else if ((result = this.facePattern2.exec(line)) !== null) {
  1237. //Value of result:
  1238. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1239. //Set the data for this face
  1240. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1241. 1);
  1242. }
  1243. else if ((result = this.facePattern1.exec(line)) !== null) {
  1244. //Value of result
  1245. //["f 1 2 3", "1 2 3"...]
  1246. //Set the data for this face
  1247. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1248. 1);
  1249. //Define a mesh or an object
  1250. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1251. }
  1252. else if (this.group.test(line) || this.obj.test(line)) {
  1253. //Create a new mesh corresponding to the name of the group.
  1254. //Definition of the mesh
  1255. var objMesh = {
  1256. name: line.substring(2).trim(),
  1257. indices: undefined,
  1258. positions: undefined,
  1259. normals: undefined,
  1260. uvs: undefined,
  1261. colors: undefined,
  1262. materialName: ""
  1263. };
  1264. addPreviousObjMesh();
  1265. //Push the last mesh created with only the name
  1266. meshesFromObj.push(objMesh);
  1267. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1268. hasMeshes = true;
  1269. isFirstMaterial = true;
  1270. increment = 1;
  1271. //Keyword for applying a material
  1272. }
  1273. else if (this.usemtl.test(line)) {
  1274. //Get the name of the material
  1275. materialNameFromObj = line.substring(7).trim();
  1276. //If this new material is in the same mesh
  1277. if (!isFirstMaterial || !hasMeshes) {
  1278. //Set the data for the previous mesh
  1279. addPreviousObjMesh();
  1280. //Create a new mesh
  1281. var objMesh =
  1282. //Set the name of the current obj mesh
  1283. {
  1284. name: (objMeshName || "mesh") + "_mm" + increment.toString(),
  1285. indices: undefined,
  1286. positions: undefined,
  1287. normals: undefined,
  1288. uvs: undefined,
  1289. colors: undefined,
  1290. materialName: materialNameFromObj
  1291. };
  1292. increment++;
  1293. //If meshes are already defined
  1294. meshesFromObj.push(objMesh);
  1295. hasMeshes = true;
  1296. }
  1297. //Set the material name if the previous line define a mesh
  1298. if (hasMeshes && isFirstMaterial) {
  1299. //Set the material name to the previous mesh (1 material per mesh)
  1300. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1301. isFirstMaterial = false;
  1302. }
  1303. //Keyword for loading the mtl file
  1304. }
  1305. else if (this.mtllib.test(line)) {
  1306. //Get the name of mtl file
  1307. fileToLoad = line.substring(7).trim();
  1308. //Apply smoothing
  1309. }
  1310. else if (this.smooth.test(line)) {
  1311. // smooth shading => apply smoothing
  1312. //Today I don't know it work with babylon and with obj.
  1313. //With the obj file an integer is set
  1314. }
  1315. else {
  1316. //If there is another possibility
  1317. console.log("Unhandled expression at line : " + line);
  1318. }
  1319. }
  1320. //At the end of the file, add the last mesh into the meshesFromObj array
  1321. if (hasMeshes) {
  1322. //Set the data for the last mesh
  1323. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1324. //Reverse indices for displaying faces in the good sense
  1325. indicesForBabylon.reverse();
  1326. //Get the good array
  1327. unwrapData();
  1328. //Set array
  1329. handledMesh.indices = indicesForBabylon;
  1330. handledMesh.positions = unwrappedPositionsForBabylon;
  1331. handledMesh.normals = unwrappedNormalsForBabylon;
  1332. handledMesh.uvs = unwrappedUVForBabylon;
  1333. if (this._meshLoadOptions.ImportVertexColors === true) {
  1334. handledMesh.colors = unwrappedColorsForBabylon;
  1335. }
  1336. }
  1337. //If any o or g keyword found, create a mesh with a random id
  1338. if (!hasMeshes) {
  1339. // reverse tab of indices
  1340. indicesForBabylon.reverse();
  1341. //Get positions normals uvs
  1342. unwrapData();
  1343. //Set data for one mesh
  1344. meshesFromObj.push({
  1345. name: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1346. indices: indicesForBabylon,
  1347. positions: unwrappedPositionsForBabylon,
  1348. colors: unwrappedColorsForBabylon,
  1349. normals: unwrappedNormalsForBabylon,
  1350. uvs: unwrappedUVForBabylon,
  1351. materialName: materialNameFromObj
  1352. });
  1353. }
  1354. //Create a Mesh list
  1355. var babylonMeshesArray = []; //The mesh for babylon
  1356. var materialToUse = new Array();
  1357. //Set data for each mesh
  1358. for (var j = 0; j < meshesFromObj.length; j++) {
  1359. //check meshesNames (stlFileLoader)
  1360. if (meshesNames && meshesFromObj[j].name) {
  1361. if (meshesNames instanceof Array) {
  1362. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1363. continue;
  1364. }
  1365. }
  1366. else {
  1367. if (meshesFromObj[j].name !== meshesNames) {
  1368. continue;
  1369. }
  1370. }
  1371. }
  1372. //Get the current mesh
  1373. //Set the data with VertexBuffer for each mesh
  1374. handledMesh = meshesFromObj[j];
  1375. //Create a Mesh with the name of the obj mesh
  1376. scene._blockEntityCollection = this._forAssetContainer;
  1377. var babylonMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1378. scene._blockEntityCollection = false;
  1379. //Push the name of the material to an array
  1380. //This is indispensable for the importMesh function
  1381. materialToUse.push(meshesFromObj[j].materialName);
  1382. var vertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1383. //Set the data for the babylonMesh
  1384. vertexData.uvs = handledMesh.uvs;
  1385. vertexData.indices = handledMesh.indices;
  1386. vertexData.positions = handledMesh.positions;
  1387. if (this._meshLoadOptions.ComputeNormals === true) {
  1388. var normals_1 = new Array();
  1389. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1390. vertexData.normals = normals_1;
  1391. }
  1392. else {
  1393. vertexData.normals = handledMesh.normals;
  1394. }
  1395. if (this._meshLoadOptions.ImportVertexColors === true) {
  1396. vertexData.colors = handledMesh.colors;
  1397. }
  1398. //Set the data from the VertexBuffer to the current Mesh
  1399. vertexData.applyToMesh(babylonMesh);
  1400. if (this._meshLoadOptions.InvertY) {
  1401. babylonMesh.scaling.y *= -1;
  1402. }
  1403. if (this._meshLoadOptions.OptimizeNormals === true) {
  1404. this._optimizeNormals(babylonMesh);
  1405. }
  1406. //Push the mesh into an array
  1407. babylonMeshesArray.push(babylonMesh);
  1408. }
  1409. var mtlPromises = [];
  1410. //load the materials
  1411. //Check if we have a file to load
  1412. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1413. //Load the file synchronously
  1414. mtlPromises.push(new Promise(function (resolve, reject) {
  1415. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1416. try {
  1417. //Create materials thanks MTLLoader function
  1418. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._forAssetContainer);
  1419. //Look at each material loaded in the mtl file
  1420. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1421. //Three variables to get all meshes with the same material
  1422. var startIndex = 0;
  1423. var _indices = [];
  1424. var _index;
  1425. //The material from MTL file is used in the meshes loaded
  1426. //Push the indice in an array
  1427. //Check if the material is not used for another mesh
  1428. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1429. _indices.push(_index);
  1430. startIndex = _index + 1;
  1431. }
  1432. //If the material is not used dispose it
  1433. if (_index === -1 && _indices.length === 0) {
  1434. //If the material is not needed, remove it
  1435. materialsFromMTLFile.materials[n].dispose();
  1436. }
  1437. else {
  1438. for (var o = 0; o < _indices.length; o++) {
  1439. //Apply the material to the Mesh for each mesh with the material
  1440. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1441. }
  1442. }
  1443. }
  1444. resolve();
  1445. }
  1446. catch (e) {
  1447. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1448. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1449. resolve();
  1450. }
  1451. else {
  1452. reject(e);
  1453. }
  1454. }
  1455. }, function (pathOfFile, exception) {
  1456. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1457. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1458. resolve();
  1459. }
  1460. else {
  1461. reject(exception);
  1462. }
  1463. });
  1464. }));
  1465. }
  1466. //Return an array with all Mesh
  1467. return Promise.all(mtlPromises).then(function () {
  1468. return babylonMeshesArray;
  1469. });
  1470. };
  1471. /**
  1472. * Defines if UVs are optimized by default during load.
  1473. */
  1474. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1475. /**
  1476. * Invert model on y-axis (does a model scaling inversion)
  1477. */
  1478. OBJFileLoader.INVERT_Y = false;
  1479. /**
  1480. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1481. */
  1482. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1483. /**
  1484. * Compute the normals for the model, even if normals are present in the file.
  1485. */
  1486. OBJFileLoader.COMPUTE_NORMALS = false;
  1487. /**
  1488. * Optimize the normals for the model. Lighting can be uneven if you use OptimizeWithUV = true because new vertices can be created for the same location if they pertain to different faces.
  1489. * Using OptimizehNormals = true will help smoothing the lighting by averaging the normals of those vertices.
  1490. */
  1491. OBJFileLoader.OPTIMIZE_NORMALS = false;
  1492. /**
  1493. * Defines custom scaling of UV coordinates of loaded meshes.
  1494. */
  1495. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1496. /**
  1497. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1498. */
  1499. OBJFileLoader.SKIP_MATERIALS = false;
  1500. /**
  1501. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1502. *
  1503. * Defaults to true for backwards compatibility.
  1504. */
  1505. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1506. return OBJFileLoader;
  1507. }());
  1508. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1509. //Add this loader into the register plugin
  1510. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1511. }
  1512. /***/ }),
  1513. /***/ "./STL/index.ts":
  1514. /*!**********************!*\
  1515. !*** ./STL/index.ts ***!
  1516. \**********************/
  1517. /*! exports provided: STLFileLoader */
  1518. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1519. "use strict";
  1520. __webpack_require__.r(__webpack_exports__);
  1521. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1522. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1523. /***/ }),
  1524. /***/ "./STL/stlFileLoader.ts":
  1525. /*!******************************!*\
  1526. !*** ./STL/stlFileLoader.ts ***!
  1527. \******************************/
  1528. /*! exports provided: STLFileLoader */
  1529. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1530. "use strict";
  1531. __webpack_require__.r(__webpack_exports__);
  1532. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1533. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  1534. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1535. /**
  1536. * STL file type loader.
  1537. * This is a babylon scene loader plugin.
  1538. */
  1539. var STLFileLoader = /** @class */ (function () {
  1540. function STLFileLoader() {
  1541. /** @hidden */
  1542. this.solidPattern = /solid (\S*)([\S\s]*?)endsolid[ ]*(\S*)/g;
  1543. /** @hidden */
  1544. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1545. /** @hidden */
  1546. 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;
  1547. /** @hidden */
  1548. 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;
  1549. /**
  1550. * Defines the name of the plugin.
  1551. */
  1552. this.name = "stl";
  1553. /**
  1554. * Defines the extensions the stl loader is able to load.
  1555. * force data to come in as an ArrayBuffer
  1556. * we'll convert to string if it looks like it's an ASCII .stl
  1557. */
  1558. this.extensions = {
  1559. ".stl": { isBinary: true },
  1560. };
  1561. }
  1562. /**
  1563. * Import meshes into a scene.
  1564. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1565. * @param scene The scene to import into
  1566. * @param data The data to import
  1567. * @param rootUrl The root url for scene and resources
  1568. * @param meshes The meshes array to import into
  1569. * @param particleSystems The particle systems array to import into
  1570. * @param skeletons The skeletons array to import into
  1571. * @param onError The callback when import fails
  1572. * @returns True if successful or false otherwise
  1573. */
  1574. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1575. var matches;
  1576. if (typeof data !== "string") {
  1577. if (this._isBinary(data)) {
  1578. // binary .stl
  1579. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1580. this._parseBinary(babylonMesh, data);
  1581. if (meshes) {
  1582. meshes.push(babylonMesh);
  1583. }
  1584. return true;
  1585. }
  1586. // ASCII .stl
  1587. // convert to string
  1588. var array_buffer = new Uint8Array(data);
  1589. var str = '';
  1590. for (var i = 0; i < data.byteLength; i++) {
  1591. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1592. }
  1593. data = str;
  1594. }
  1595. //if arrived here, data is a string, containing the STLA data.
  1596. while (matches = this.solidPattern.exec(data)) {
  1597. var meshName = matches[1];
  1598. var meshNameFromEnd = matches[3];
  1599. if (meshName != meshNameFromEnd) {
  1600. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1601. return false;
  1602. }
  1603. // check meshesNames
  1604. if (meshesNames && meshName) {
  1605. if (meshesNames instanceof Array) {
  1606. if (!meshesNames.indexOf(meshName)) {
  1607. continue;
  1608. }
  1609. }
  1610. else {
  1611. if (meshName !== meshesNames) {
  1612. continue;
  1613. }
  1614. }
  1615. }
  1616. // stl mesh name can be empty as well
  1617. meshName = meshName || "stlmesh";
  1618. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1619. this._parseASCII(babylonMesh, matches[2]);
  1620. if (meshes) {
  1621. meshes.push(babylonMesh);
  1622. }
  1623. }
  1624. return true;
  1625. };
  1626. /**
  1627. * Load into a scene.
  1628. * @param scene The scene to load into
  1629. * @param data The data to import
  1630. * @param rootUrl The root url for scene and resources
  1631. * @param onError The callback when import fails
  1632. * @returns true if successful or false otherwise
  1633. */
  1634. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1635. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1636. return result;
  1637. };
  1638. /**
  1639. * Load into an asset container.
  1640. * @param scene The scene to load into
  1641. * @param data The data to import
  1642. * @param rootUrl The root url for scene and resources
  1643. * @param onError The callback when import fails
  1644. * @returns The loaded asset container
  1645. */
  1646. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1647. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1648. scene._blockEntityCollection = true;
  1649. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1650. scene._blockEntityCollection = false;
  1651. return container;
  1652. };
  1653. STLFileLoader.prototype._isBinary = function (data) {
  1654. // check if file size is correct for binary stl
  1655. var faceSize, nFaces, reader;
  1656. reader = new DataView(data);
  1657. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1658. nFaces = reader.getUint32(80, true);
  1659. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1660. return true;
  1661. }
  1662. // check characters higher than ASCII to confirm binary
  1663. var fileLength = reader.byteLength;
  1664. for (var index = 0; index < fileLength; index++) {
  1665. if (reader.getUint8(index) > 127) {
  1666. return true;
  1667. }
  1668. }
  1669. return false;
  1670. };
  1671. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1672. var reader = new DataView(data);
  1673. var faces = reader.getUint32(80, true);
  1674. var dataOffset = 84;
  1675. var faceLength = 12 * 4 + 2;
  1676. var offset = 0;
  1677. var positions = new Float32Array(faces * 3 * 3);
  1678. var normals = new Float32Array(faces * 3 * 3);
  1679. var indices = new Uint32Array(faces * 3);
  1680. var indicesCount = 0;
  1681. for (var face = 0; face < faces; face++) {
  1682. var start = dataOffset + face * faceLength;
  1683. var normalX = reader.getFloat32(start, true);
  1684. var normalY = reader.getFloat32(start + 4, true);
  1685. var normalZ = reader.getFloat32(start + 8, true);
  1686. for (var i = 1; i <= 3; i++) {
  1687. var vertexstart = start + i * 12;
  1688. // ordering is intentional to match ascii import
  1689. positions[offset] = reader.getFloat32(vertexstart, true);
  1690. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1691. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1692. normals[offset] = normalX;
  1693. normals[offset + 2] = normalY;
  1694. normals[offset + 1] = normalZ;
  1695. offset += 3;
  1696. }
  1697. indices[indicesCount] = indicesCount++;
  1698. indices[indicesCount] = indicesCount++;
  1699. indices[indicesCount] = indicesCount++;
  1700. }
  1701. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1702. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1703. mesh.setIndices(indices);
  1704. mesh.computeWorldMatrix(true);
  1705. };
  1706. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1707. var positions = [];
  1708. var normals = [];
  1709. var indices = [];
  1710. var indicesCount = 0;
  1711. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1712. var matches;
  1713. while (matches = this.facetsPattern.exec(solidData)) {
  1714. var facet = matches[1];
  1715. //one normal per face
  1716. var normalMatches = this.normalPattern.exec(facet);
  1717. this.normalPattern.lastIndex = 0;
  1718. if (!normalMatches) {
  1719. continue;
  1720. }
  1721. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1722. var vertexMatch;
  1723. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1724. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1725. normals.push(normal[0], normal[1], normal[2]);
  1726. }
  1727. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1728. this.vertexPattern.lastIndex = 0;
  1729. }
  1730. this.facetsPattern.lastIndex = 0;
  1731. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1732. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1733. mesh.setIndices(indices);
  1734. mesh.computeWorldMatrix(true);
  1735. };
  1736. return STLFileLoader;
  1737. }());
  1738. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1739. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1740. }
  1741. /***/ }),
  1742. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1743. /*!*****************************************!*\
  1744. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1745. \*****************************************/
  1746. /*! exports provided: GLTFBinaryExtension */
  1747. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1748. "use strict";
  1749. __webpack_require__.r(__webpack_exports__);
  1750. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1751. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1752. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1753. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1754. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1755. var BinaryExtensionBufferName = "binary_glTF";
  1756. /** @hidden */
  1757. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1758. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1759. function GLTFBinaryExtension() {
  1760. return _super.call(this, "KHR_binary_glTF") || this;
  1761. }
  1762. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1763. var extensionsUsed = data.json.extensionsUsed;
  1764. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1765. return false;
  1766. }
  1767. this._bin = data.bin;
  1768. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1769. return true;
  1770. };
  1771. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1772. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1773. return false;
  1774. }
  1775. if (id !== BinaryExtensionBufferName) {
  1776. return false;
  1777. }
  1778. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1779. return true;
  1780. };
  1781. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1782. var texture = gltfRuntime.textures[id];
  1783. var source = gltfRuntime.images[texture.source];
  1784. if (!source.extensions || !(this.name in source.extensions)) {
  1785. return false;
  1786. }
  1787. var sourceExt = source.extensions[this.name];
  1788. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1789. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1790. onSuccess(buffer);
  1791. return true;
  1792. };
  1793. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1794. var shader = gltfRuntime.shaders[id];
  1795. if (!shader.extensions || !(this.name in shader.extensions)) {
  1796. return false;
  1797. }
  1798. var binaryExtensionShader = shader.extensions[this.name];
  1799. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1800. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1801. setTimeout(function () {
  1802. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1803. onSuccess(shaderString);
  1804. });
  1805. return true;
  1806. };
  1807. return GLTFBinaryExtension;
  1808. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1809. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1810. /***/ }),
  1811. /***/ "./glTF/1.0/glTFLoader.ts":
  1812. /*!********************************!*\
  1813. !*** ./glTF/1.0/glTFLoader.ts ***!
  1814. \********************************/
  1815. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1816. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1817. "use strict";
  1818. __webpack_require__.r(__webpack_exports__);
  1819. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1820. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1821. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1822. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1823. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  1824. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  1825. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1826. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1827. /**
  1828. * Tokenizer. Used for shaders compatibility
  1829. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1830. */
  1831. var ETokenType;
  1832. (function (ETokenType) {
  1833. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1834. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1835. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1836. })(ETokenType || (ETokenType = {}));
  1837. var Tokenizer = /** @class */ (function () {
  1838. function Tokenizer(toParse) {
  1839. this._pos = 0;
  1840. this.currentToken = ETokenType.UNKNOWN;
  1841. this.currentIdentifier = "";
  1842. this.currentString = "";
  1843. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1844. this._toParse = toParse;
  1845. this._maxPos = toParse.length;
  1846. }
  1847. Tokenizer.prototype.getNextToken = function () {
  1848. if (this.isEnd()) {
  1849. return ETokenType.END_OF_INPUT;
  1850. }
  1851. this.currentString = this.read();
  1852. this.currentToken = ETokenType.UNKNOWN;
  1853. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1854. this.currentToken = ETokenType.IDENTIFIER;
  1855. this.currentIdentifier = this.currentString;
  1856. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1857. this.currentIdentifier += this.currentString;
  1858. this.forward();
  1859. }
  1860. }
  1861. return this.currentToken;
  1862. };
  1863. Tokenizer.prototype.peek = function () {
  1864. return this._toParse[this._pos];
  1865. };
  1866. Tokenizer.prototype.read = function () {
  1867. return this._toParse[this._pos++];
  1868. };
  1869. Tokenizer.prototype.forward = function () {
  1870. this._pos++;
  1871. };
  1872. Tokenizer.prototype.isEnd = function () {
  1873. return this._pos >= this._maxPos;
  1874. };
  1875. return Tokenizer;
  1876. }());
  1877. /**
  1878. * Values
  1879. */
  1880. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1881. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1882. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1883. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1884. /**
  1885. * Parse
  1886. */
  1887. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1888. for (var buf in parsedBuffers) {
  1889. var parsedBuffer = parsedBuffers[buf];
  1890. gltfRuntime.buffers[buf] = parsedBuffer;
  1891. gltfRuntime.buffersCount++;
  1892. }
  1893. };
  1894. var parseShaders = function (parsedShaders, gltfRuntime) {
  1895. for (var sha in parsedShaders) {
  1896. var parsedShader = parsedShaders[sha];
  1897. gltfRuntime.shaders[sha] = parsedShader;
  1898. gltfRuntime.shaderscount++;
  1899. }
  1900. };
  1901. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1902. for (var object in parsedObjects) {
  1903. var parsedObject = parsedObjects[object];
  1904. gltfRuntime[runtimeProperty][object] = parsedObject;
  1905. }
  1906. };
  1907. /**
  1908. * Utils
  1909. */
  1910. var normalizeUVs = function (buffer) {
  1911. if (!buffer) {
  1912. return;
  1913. }
  1914. for (var i = 0; i < buffer.length / 2; i++) {
  1915. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1916. }
  1917. };
  1918. var getAttribute = function (attributeParameter) {
  1919. if (attributeParameter.semantic === "NORMAL") {
  1920. return "normal";
  1921. }
  1922. else if (attributeParameter.semantic === "POSITION") {
  1923. return "position";
  1924. }
  1925. else if (attributeParameter.semantic === "JOINT") {
  1926. return "matricesIndices";
  1927. }
  1928. else if (attributeParameter.semantic === "WEIGHT") {
  1929. return "matricesWeights";
  1930. }
  1931. else if (attributeParameter.semantic === "COLOR") {
  1932. return "color";
  1933. }
  1934. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1935. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1936. return "uv" + (channel === 0 ? "" : channel + 1);
  1937. }
  1938. return null;
  1939. };
  1940. /**
  1941. * Loads and creates animations
  1942. */
  1943. var loadAnimations = function (gltfRuntime) {
  1944. for (var anim in gltfRuntime.animations) {
  1945. var animation = gltfRuntime.animations[anim];
  1946. if (!animation.channels || !animation.samplers) {
  1947. continue;
  1948. }
  1949. var lastAnimation = null;
  1950. for (var i = 0; i < animation.channels.length; i++) {
  1951. // Get parameters and load buffers
  1952. var channel = animation.channels[i];
  1953. var sampler = animation.samplers[channel.sampler];
  1954. if (!sampler) {
  1955. continue;
  1956. }
  1957. var inputData = null;
  1958. var outputData = null;
  1959. if (animation.parameters) {
  1960. inputData = animation.parameters[sampler.input];
  1961. outputData = animation.parameters[sampler.output];
  1962. }
  1963. else {
  1964. inputData = sampler.input;
  1965. outputData = sampler.output;
  1966. }
  1967. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1968. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1969. var targetID = channel.target.id;
  1970. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1971. if (targetNode === null) {
  1972. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1973. }
  1974. if (targetNode === null) {
  1975. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1976. continue;
  1977. }
  1978. var isBone = targetNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1979. // Get target path (position, rotation or scaling)
  1980. var targetPath = channel.target.path;
  1981. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1982. if (targetPathIndex !== -1) {
  1983. targetPath = babylonAnimationPaths[targetPathIndex];
  1984. }
  1985. // Determine animation type
  1986. var animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1987. if (!isBone) {
  1988. if (targetPath === "rotationQuaternion") {
  1989. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1990. targetNode.rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1991. }
  1992. else {
  1993. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1994. }
  1995. }
  1996. // Create animation and key frames
  1997. var babylonAnimation = null;
  1998. var keys = [];
  1999. var arrayOffset = 0;
  2000. var modifyKey = false;
  2001. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  2002. babylonAnimation = lastAnimation;
  2003. modifyKey = true;
  2004. }
  2005. if (!modifyKey) {
  2006. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2007. babylonAnimation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"](anim, isBone ? "_matrix" : targetPath, 1, animationType, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONLOOPMODE_CYCLE);
  2008. gltfRuntime.scene._blockEntityCollection = false;
  2009. }
  2010. // For each frame
  2011. for (var j = 0; j < bufferInput.length; j++) {
  2012. var value = null;
  2013. if (targetPath === "rotationQuaternion") { // VEC4
  2014. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  2015. arrayOffset += 4;
  2016. }
  2017. else { // Position and scaling are VEC3
  2018. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  2019. arrayOffset += 3;
  2020. }
  2021. if (isBone) {
  2022. var bone = targetNode;
  2023. var translation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  2024. var rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2025. var scaling = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  2026. // Warning on decompose
  2027. var mat = bone.getBaseMatrix();
  2028. if (modifyKey && lastAnimation) {
  2029. mat = lastAnimation.getKeys()[j].value;
  2030. }
  2031. mat.decompose(scaling, rotationQuaternion, translation);
  2032. if (targetPath === "position") {
  2033. translation = value;
  2034. }
  2035. else if (targetPath === "rotationQuaternion") {
  2036. rotationQuaternion = value;
  2037. }
  2038. else {
  2039. scaling = value;
  2040. }
  2041. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  2042. }
  2043. if (!modifyKey) {
  2044. keys.push({
  2045. frame: bufferInput[j],
  2046. value: value
  2047. });
  2048. }
  2049. else if (lastAnimation) {
  2050. lastAnimation.getKeys()[j].value = value;
  2051. }
  2052. }
  2053. // Finish
  2054. if (!modifyKey && babylonAnimation) {
  2055. babylonAnimation.setKeys(keys);
  2056. targetNode.animations.push(babylonAnimation);
  2057. }
  2058. lastAnimation = babylonAnimation;
  2059. gltfRuntime.scene.stopAnimation(targetNode);
  2060. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  2061. }
  2062. }
  2063. };
  2064. /**
  2065. * Returns the bones transformation matrix
  2066. */
  2067. var configureBoneTransformation = function (node) {
  2068. var mat = null;
  2069. if (node.translation || node.rotation || node.scale) {
  2070. var scale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  2071. var rotation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  2072. var position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  2073. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  2074. }
  2075. else {
  2076. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2077. }
  2078. return mat;
  2079. };
  2080. /**
  2081. * Returns the parent bone
  2082. */
  2083. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  2084. // Try to find
  2085. for (var i = 0; i < newSkeleton.bones.length; i++) {
  2086. if (newSkeleton.bones[i].name === jointName) {
  2087. return newSkeleton.bones[i];
  2088. }
  2089. }
  2090. // Not found, search in gltf nodes
  2091. var nodes = gltfRuntime.nodes;
  2092. for (var nde in nodes) {
  2093. var node = nodes[nde];
  2094. if (!node.jointName) {
  2095. continue;
  2096. }
  2097. var children = node.children;
  2098. for (var i = 0; i < children.length; i++) {
  2099. var child = gltfRuntime.nodes[children[i]];
  2100. if (!child.jointName) {
  2101. continue;
  2102. }
  2103. if (child.jointName === jointName) {
  2104. var mat = configureBoneTransformation(node);
  2105. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  2106. bone.id = nde;
  2107. return bone;
  2108. }
  2109. }
  2110. }
  2111. return null;
  2112. };
  2113. /**
  2114. * Returns the appropriate root node
  2115. */
  2116. var getNodeToRoot = function (nodesToRoot, id) {
  2117. for (var i = 0; i < nodesToRoot.length; i++) {
  2118. var nodeToRoot = nodesToRoot[i];
  2119. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  2120. var child = nodeToRoot.node.children[j];
  2121. if (child === id) {
  2122. return nodeToRoot.bone;
  2123. }
  2124. }
  2125. }
  2126. return null;
  2127. };
  2128. /**
  2129. * Returns the node with the joint name
  2130. */
  2131. var getJointNode = function (gltfRuntime, jointName) {
  2132. var nodes = gltfRuntime.nodes;
  2133. var node = nodes[jointName];
  2134. if (node) {
  2135. return {
  2136. node: node,
  2137. id: jointName
  2138. };
  2139. }
  2140. for (var nde in nodes) {
  2141. node = nodes[nde];
  2142. if (node.jointName === jointName) {
  2143. return {
  2144. node: node,
  2145. id: nde
  2146. };
  2147. }
  2148. }
  2149. return null;
  2150. };
  2151. /**
  2152. * Checks if a nodes is in joints
  2153. */
  2154. var nodeIsInJoints = function (skins, id) {
  2155. for (var i = 0; i < skins.jointNames.length; i++) {
  2156. if (skins.jointNames[i] === id) {
  2157. return true;
  2158. }
  2159. }
  2160. return false;
  2161. };
  2162. /**
  2163. * Fills the nodes to root for bones and builds hierarchy
  2164. */
  2165. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2166. // Creates nodes for root
  2167. for (var nde in gltfRuntime.nodes) {
  2168. var node = gltfRuntime.nodes[nde];
  2169. var id = nde;
  2170. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2171. continue;
  2172. }
  2173. // Create node to root bone
  2174. var mat = configureBoneTransformation(node);
  2175. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2176. bone.id = id;
  2177. nodesToRoot.push({ bone: bone, node: node, id: id });
  2178. }
  2179. // Parenting
  2180. for (var i = 0; i < nodesToRoot.length; i++) {
  2181. var nodeToRoot = nodesToRoot[i];
  2182. var children = nodeToRoot.node.children;
  2183. for (var j = 0; j < children.length; j++) {
  2184. var child = null;
  2185. for (var k = 0; k < nodesToRoot.length; k++) {
  2186. if (nodesToRoot[k].id === children[j]) {
  2187. child = nodesToRoot[k];
  2188. break;
  2189. }
  2190. }
  2191. if (child) {
  2192. child.bone._parent = nodeToRoot.bone;
  2193. nodeToRoot.bone.children.push(child.bone);
  2194. }
  2195. }
  2196. }
  2197. };
  2198. /**
  2199. * Imports a skeleton
  2200. */
  2201. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2202. if (!newSkeleton) {
  2203. newSkeleton = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2204. }
  2205. if (!skins.babylonSkeleton) {
  2206. return newSkeleton;
  2207. }
  2208. // Find the root bones
  2209. var nodesToRoot = [];
  2210. var nodesToRootToAdd = [];
  2211. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2212. newSkeleton.bones = [];
  2213. // Joints
  2214. for (var i = 0; i < skins.jointNames.length; i++) {
  2215. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2216. if (!jointNode) {
  2217. continue;
  2218. }
  2219. var node = jointNode.node;
  2220. if (!node) {
  2221. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2222. continue;
  2223. }
  2224. var id = jointNode.id;
  2225. // Optimize, if the bone already exists...
  2226. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2227. if (existingBone) {
  2228. newSkeleton.bones.push(existingBone);
  2229. continue;
  2230. }
  2231. // Search for parent bone
  2232. var foundBone = false;
  2233. var parentBone = null;
  2234. for (var j = 0; j < i; j++) {
  2235. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2236. if (!jointNode_1) {
  2237. continue;
  2238. }
  2239. var joint = jointNode_1.node;
  2240. if (!joint) {
  2241. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2242. continue;
  2243. }
  2244. var children = joint.children;
  2245. if (!children) {
  2246. continue;
  2247. }
  2248. foundBone = false;
  2249. for (var k = 0; k < children.length; k++) {
  2250. if (children[k] === id) {
  2251. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2252. foundBone = true;
  2253. break;
  2254. }
  2255. }
  2256. if (foundBone) {
  2257. break;
  2258. }
  2259. }
  2260. // Create bone
  2261. var mat = configureBoneTransformation(node);
  2262. if (!parentBone && nodesToRoot.length > 0) {
  2263. parentBone = getNodeToRoot(nodesToRoot, id);
  2264. if (parentBone) {
  2265. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2266. nodesToRootToAdd.push(parentBone);
  2267. }
  2268. }
  2269. }
  2270. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2271. bone.id = id;
  2272. }
  2273. // Polish
  2274. var bones = newSkeleton.bones;
  2275. newSkeleton.bones = [];
  2276. for (var i = 0; i < skins.jointNames.length; i++) {
  2277. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2278. if (!jointNode) {
  2279. continue;
  2280. }
  2281. for (var j = 0; j < bones.length; j++) {
  2282. if (bones[j].id === jointNode.id) {
  2283. newSkeleton.bones.push(bones[j]);
  2284. break;
  2285. }
  2286. }
  2287. }
  2288. newSkeleton.prepare();
  2289. // Finish
  2290. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2291. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2292. }
  2293. return newSkeleton;
  2294. };
  2295. /**
  2296. * Imports a mesh and its geometries
  2297. */
  2298. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2299. if (!newMesh) {
  2300. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2301. newMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2302. gltfRuntime.scene._blockEntityCollection = false;
  2303. newMesh.id = id;
  2304. }
  2305. if (!node.babylonNode) {
  2306. return newMesh;
  2307. }
  2308. var subMaterials = [];
  2309. var vertexData = null;
  2310. var verticesStarts = new Array();
  2311. var verticesCounts = new Array();
  2312. var indexStarts = new Array();
  2313. var indexCounts = new Array();
  2314. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2315. var meshID = meshes[meshIndex];
  2316. var mesh = gltfRuntime.meshes[meshID];
  2317. if (!mesh) {
  2318. continue;
  2319. }
  2320. // Positions, normals and UVs
  2321. for (var i = 0; i < mesh.primitives.length; i++) {
  2322. // Temporary vertex data
  2323. var tempVertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2324. var primitive = mesh.primitives[i];
  2325. if (primitive.mode !== 4) {
  2326. // continue;
  2327. }
  2328. var attributes = primitive.attributes;
  2329. var accessor = null;
  2330. var buffer = null;
  2331. // Set positions, normal and uvs
  2332. for (var semantic in attributes) {
  2333. // Link accessor and buffer view
  2334. accessor = gltfRuntime.accessors[attributes[semantic]];
  2335. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2336. if (semantic === "NORMAL") {
  2337. tempVertexData.normals = new Float32Array(buffer.length);
  2338. tempVertexData.normals.set(buffer);
  2339. }
  2340. else if (semantic === "POSITION") {
  2341. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2342. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2343. for (var j = 0; j < buffer.length; j += 4) {
  2344. tempVertexData.positions[j] = buffer[j];
  2345. tempVertexData.positions[j + 1] = buffer[j + 1];
  2346. tempVertexData.positions[j + 2] = buffer[j + 2];
  2347. }
  2348. }
  2349. else {
  2350. tempVertexData.positions = new Float32Array(buffer.length);
  2351. tempVertexData.positions.set(buffer);
  2352. }
  2353. verticesCounts.push(tempVertexData.positions.length);
  2354. }
  2355. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2356. var channel = Number(semantic.split("_")[1]);
  2357. var uvKind = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2358. var uvs = new Float32Array(buffer.length);
  2359. uvs.set(buffer);
  2360. normalizeUVs(uvs);
  2361. tempVertexData.set(uvs, uvKind);
  2362. }
  2363. else if (semantic === "JOINT") {
  2364. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2365. tempVertexData.matricesIndices.set(buffer);
  2366. }
  2367. else if (semantic === "WEIGHT") {
  2368. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2369. tempVertexData.matricesWeights.set(buffer);
  2370. }
  2371. else if (semantic === "COLOR") {
  2372. tempVertexData.colors = new Float32Array(buffer.length);
  2373. tempVertexData.colors.set(buffer);
  2374. }
  2375. }
  2376. // Indices
  2377. accessor = gltfRuntime.accessors[primitive.indices];
  2378. if (accessor) {
  2379. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2380. tempVertexData.indices = new Int32Array(buffer.length);
  2381. tempVertexData.indices.set(buffer);
  2382. indexCounts.push(tempVertexData.indices.length);
  2383. }
  2384. else {
  2385. // Set indices on the fly
  2386. var indices = [];
  2387. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2388. indices.push(j);
  2389. }
  2390. tempVertexData.indices = new Int32Array(indices);
  2391. indexCounts.push(tempVertexData.indices.length);
  2392. }
  2393. if (!vertexData) {
  2394. vertexData = tempVertexData;
  2395. }
  2396. else {
  2397. vertexData.merge(tempVertexData);
  2398. }
  2399. // Sub material
  2400. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2401. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2402. // Update vertices start and index start
  2403. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2404. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2405. }
  2406. }
  2407. var material;
  2408. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2409. if (subMaterials.length > 1) {
  2410. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2411. material.subMaterials = subMaterials;
  2412. }
  2413. else {
  2414. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2415. }
  2416. if (subMaterials.length === 1) {
  2417. material = subMaterials[0];
  2418. }
  2419. if (!newMesh.material) {
  2420. newMesh.material = material;
  2421. }
  2422. // Apply geometry
  2423. new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2424. newMesh.computeWorldMatrix(true);
  2425. gltfRuntime.scene._blockEntityCollection = false;
  2426. // Apply submeshes
  2427. newMesh.subMeshes = [];
  2428. var index = 0;
  2429. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2430. var meshID = meshes[meshIndex];
  2431. var mesh = gltfRuntime.meshes[meshID];
  2432. if (!mesh) {
  2433. continue;
  2434. }
  2435. for (var i = 0; i < mesh.primitives.length; i++) {
  2436. if (mesh.primitives[i].mode !== 4) {
  2437. //continue;
  2438. }
  2439. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2440. index++;
  2441. }
  2442. }
  2443. // Finish
  2444. return newMesh;
  2445. };
  2446. /**
  2447. * Configure node transformation from position, rotation and scaling
  2448. */
  2449. var configureNode = function (newNode, position, rotation, scaling) {
  2450. if (newNode.position) {
  2451. newNode.position = position;
  2452. }
  2453. if (newNode.rotationQuaternion || newNode.rotation) {
  2454. newNode.rotationQuaternion = rotation;
  2455. }
  2456. if (newNode.scaling) {
  2457. newNode.scaling = scaling;
  2458. }
  2459. };
  2460. /**
  2461. * Configures node from transformation matrix
  2462. */
  2463. var configureNodeFromMatrix = function (newNode, node, parent) {
  2464. if (node.matrix) {
  2465. var position = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2466. var rotation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2467. var scaling = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2468. var mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2469. mat.decompose(scaling, rotation, position);
  2470. configureNode(newNode, position, rotation, scaling);
  2471. }
  2472. else if (node.translation && node.rotation && node.scale) {
  2473. configureNode(newNode, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale));
  2474. }
  2475. newNode.computeWorldMatrix(true);
  2476. };
  2477. /**
  2478. * Imports a node
  2479. */
  2480. var importNode = function (gltfRuntime, node, id, parent) {
  2481. var lastNode = null;
  2482. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2483. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2484. return null;
  2485. }
  2486. }
  2487. // Meshes
  2488. if (node.skin) {
  2489. if (node.meshes) {
  2490. var skin = gltfRuntime.skins[node.skin];
  2491. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2492. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2493. if (newMesh.skeleton === null) {
  2494. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2495. if (!skin.babylonSkeleton) {
  2496. skin.babylonSkeleton = newMesh.skeleton;
  2497. }
  2498. }
  2499. lastNode = newMesh;
  2500. }
  2501. }
  2502. else if (node.meshes) {
  2503. /**
  2504. * Improve meshes property
  2505. */
  2506. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2507. lastNode = newMesh;
  2508. }
  2509. // Lights
  2510. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2511. var light = gltfRuntime.lights[node.light];
  2512. if (light) {
  2513. if (light.type === "ambient") {
  2514. var ambienLight = light[light.type];
  2515. var hemiLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2516. hemiLight.name = node.name || "";
  2517. if (ambienLight.color) {
  2518. hemiLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2519. }
  2520. lastNode = hemiLight;
  2521. }
  2522. else if (light.type === "directional") {
  2523. var directionalLight = light[light.type];
  2524. var dirLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2525. dirLight.name = node.name || "";
  2526. if (directionalLight.color) {
  2527. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2528. }
  2529. lastNode = dirLight;
  2530. }
  2531. else if (light.type === "point") {
  2532. var pointLight = light[light.type];
  2533. var ptLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2534. ptLight.name = node.name || "";
  2535. if (pointLight.color) {
  2536. ptLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2537. }
  2538. lastNode = ptLight;
  2539. }
  2540. else if (light.type === "spot") {
  2541. var spotLight = light[light.type];
  2542. var spLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SpotLight"](node.light, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), 0, 0, gltfRuntime.scene);
  2543. spLight.name = node.name || "";
  2544. if (spotLight.color) {
  2545. spLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2546. }
  2547. if (spotLight.fallOfAngle) {
  2548. spLight.angle = spotLight.fallOfAngle;
  2549. }
  2550. if (spotLight.fallOffExponent) {
  2551. spLight.exponent = spotLight.fallOffExponent;
  2552. }
  2553. lastNode = spLight;
  2554. }
  2555. }
  2556. }
  2557. // Cameras
  2558. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2559. var camera = gltfRuntime.cameras[node.camera];
  2560. if (camera) {
  2561. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2562. if (camera.type === "orthographic") {
  2563. var orthoCamera = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  2564. orthoCamera.name = node.name || "";
  2565. orthoCamera.mode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2566. orthoCamera.attachControl();
  2567. lastNode = orthoCamera;
  2568. }
  2569. else if (camera.type === "perspective") {
  2570. var perspectiveCamera = camera[camera.type];
  2571. var persCamera = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["FreeCamera"](node.camera, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene, false);
  2572. persCamera.name = node.name || "";
  2573. persCamera.attachControl();
  2574. if (!perspectiveCamera.aspectRatio) {
  2575. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2576. }
  2577. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2578. persCamera.maxZ = perspectiveCamera.zfar;
  2579. persCamera.minZ = perspectiveCamera.znear;
  2580. }
  2581. lastNode = persCamera;
  2582. }
  2583. gltfRuntime.scene._blockEntityCollection = false;
  2584. }
  2585. }
  2586. // Empty node
  2587. if (!node.jointName) {
  2588. if (node.babylonNode) {
  2589. return node.babylonNode;
  2590. }
  2591. else if (lastNode === null) {
  2592. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2593. var dummy = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2594. gltfRuntime.scene._blockEntityCollection = false;
  2595. node.babylonNode = dummy;
  2596. lastNode = dummy;
  2597. }
  2598. }
  2599. if (lastNode !== null) {
  2600. if (node.matrix && lastNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2601. configureNodeFromMatrix(lastNode, node, parent);
  2602. }
  2603. else {
  2604. var translation = node.translation || [0, 0, 0];
  2605. var rotation = node.rotation || [0, 0, 0, 1];
  2606. var scale = node.scale || [1, 1, 1];
  2607. configureNode(lastNode, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(translation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(rotation), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(scale));
  2608. }
  2609. lastNode.updateCache(true);
  2610. node.babylonNode = lastNode;
  2611. }
  2612. return lastNode;
  2613. };
  2614. /**
  2615. * Traverses nodes and creates them
  2616. */
  2617. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2618. if (meshIncluded === void 0) { meshIncluded = false; }
  2619. var node = gltfRuntime.nodes[id];
  2620. var newNode = null;
  2621. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2622. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2623. meshIncluded = true;
  2624. }
  2625. else {
  2626. meshIncluded = false;
  2627. }
  2628. }
  2629. else {
  2630. meshIncluded = true;
  2631. }
  2632. if (!node.jointName && meshIncluded) {
  2633. newNode = importNode(gltfRuntime, node, id, parent);
  2634. if (newNode !== null) {
  2635. newNode.id = id;
  2636. newNode.parent = parent;
  2637. }
  2638. }
  2639. if (node.children) {
  2640. for (var i = 0; i < node.children.length; i++) {
  2641. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2642. }
  2643. }
  2644. };
  2645. /**
  2646. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2647. */
  2648. var postLoad = function (gltfRuntime) {
  2649. // Nodes
  2650. var currentScene = gltfRuntime.currentScene;
  2651. if (currentScene) {
  2652. for (var i = 0; i < currentScene.nodes.length; i++) {
  2653. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2654. }
  2655. }
  2656. else {
  2657. for (var thing in gltfRuntime.scenes) {
  2658. currentScene = gltfRuntime.scenes[thing];
  2659. for (var i = 0; i < currentScene.nodes.length; i++) {
  2660. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2661. }
  2662. }
  2663. }
  2664. // Set animations
  2665. loadAnimations(gltfRuntime);
  2666. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2667. var skeleton = gltfRuntime.scene.skeletons[i];
  2668. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2669. }
  2670. };
  2671. /**
  2672. * onBind shaderrs callback to set uniforms and matrices
  2673. */
  2674. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2675. var materialValues = material.values || technique.parameters;
  2676. for (var unif in unTreatedUniforms) {
  2677. var uniform = unTreatedUniforms[unif];
  2678. var type = uniform.type;
  2679. 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) {
  2680. if (uniform.semantic && !uniform.source && !uniform.node) {
  2681. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2682. }
  2683. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2684. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2685. if (source === null) {
  2686. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2687. }
  2688. if (source === null) {
  2689. continue;
  2690. }
  2691. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2692. }
  2693. }
  2694. else {
  2695. var value = materialValues[technique.uniforms[unif]];
  2696. if (!value) {
  2697. continue;
  2698. }
  2699. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2700. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2701. if (texture === null || texture === undefined) {
  2702. continue;
  2703. }
  2704. shaderMaterial.getEffect().setTexture(unif, texture);
  2705. }
  2706. else {
  2707. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2708. }
  2709. }
  2710. }
  2711. onSuccess(shaderMaterial);
  2712. };
  2713. /**
  2714. * Prepare uniforms to send the only one time
  2715. * Loads the appropriate textures
  2716. */
  2717. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2718. var materialValues = material.values || technique.parameters;
  2719. var techniqueUniforms = technique.uniforms;
  2720. /**
  2721. * Prepare values here (not matrices)
  2722. */
  2723. for (var unif in unTreatedUniforms) {
  2724. var uniform = unTreatedUniforms[unif];
  2725. var type = uniform.type;
  2726. var value = materialValues[techniqueUniforms[unif]];
  2727. if (value === undefined) {
  2728. // In case the value is the same for all materials
  2729. value = uniform.value;
  2730. }
  2731. if (!value) {
  2732. continue;
  2733. }
  2734. var onLoadTexture = function (uniformName) {
  2735. return function (texture) {
  2736. if (uniform.value && uniformName) {
  2737. // Static uniform
  2738. shaderMaterial.setTexture(uniformName, texture);
  2739. delete unTreatedUniforms[uniformName];
  2740. }
  2741. };
  2742. };
  2743. // Texture (sampler2D)
  2744. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2745. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2746. }
  2747. // Others
  2748. else {
  2749. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2750. // Static uniform
  2751. delete unTreatedUniforms[unif];
  2752. }
  2753. }
  2754. }
  2755. };
  2756. /**
  2757. * Shader compilation failed
  2758. */
  2759. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2760. return function (effect, error) {
  2761. shaderMaterial.dispose(true);
  2762. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2763. };
  2764. };
  2765. /**
  2766. * Shader compilation success
  2767. */
  2768. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2769. return function (_) {
  2770. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2771. shaderMaterial.onBind = function (mesh) {
  2772. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2773. };
  2774. };
  2775. };
  2776. /**
  2777. * Returns the appropriate uniform if already handled by babylon
  2778. */
  2779. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2780. for (var unif in technique.uniforms) {
  2781. var uniform = technique.uniforms[unif];
  2782. var uniformParameter = technique.parameters[uniform];
  2783. if (tokenizer.currentIdentifier === unif) {
  2784. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2785. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2786. if (transformIndex !== -1) {
  2787. delete unTreatedUniforms[unif];
  2788. return babylonTransforms[transformIndex];
  2789. }
  2790. }
  2791. }
  2792. }
  2793. return tokenizer.currentIdentifier;
  2794. };
  2795. /**
  2796. * All shaders loaded. Create materials one by one
  2797. */
  2798. var importMaterials = function (gltfRuntime) {
  2799. // Create materials
  2800. for (var mat in gltfRuntime.materials) {
  2801. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2802. }
  2803. };
  2804. /**
  2805. * Implementation of the base glTF spec
  2806. * @hidden
  2807. */
  2808. var GLTFLoaderBase = /** @class */ (function () {
  2809. function GLTFLoaderBase() {
  2810. }
  2811. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2812. var gltfRuntime = {
  2813. extensions: {},
  2814. accessors: {},
  2815. buffers: {},
  2816. bufferViews: {},
  2817. meshes: {},
  2818. lights: {},
  2819. cameras: {},
  2820. nodes: {},
  2821. images: {},
  2822. textures: {},
  2823. shaders: {},
  2824. programs: {},
  2825. samplers: {},
  2826. techniques: {},
  2827. materials: {},
  2828. animations: {},
  2829. skins: {},
  2830. extensionsUsed: [],
  2831. scenes: {},
  2832. buffersCount: 0,
  2833. shaderscount: 0,
  2834. scene: scene,
  2835. rootUrl: rootUrl,
  2836. loadedBufferCount: 0,
  2837. loadedBufferViews: {},
  2838. loadedShaderCount: 0,
  2839. importOnlyMeshes: false,
  2840. dummyNodes: [],
  2841. forAssetContainer: false
  2842. };
  2843. // Parse
  2844. if (parsedData.extensions) {
  2845. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2846. }
  2847. if (parsedData.extensionsUsed) {
  2848. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2849. }
  2850. if (parsedData.buffers) {
  2851. parseBuffers(parsedData.buffers, gltfRuntime);
  2852. }
  2853. if (parsedData.bufferViews) {
  2854. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2855. }
  2856. if (parsedData.accessors) {
  2857. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2858. }
  2859. if (parsedData.meshes) {
  2860. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2861. }
  2862. if (parsedData.lights) {
  2863. parseObject(parsedData.lights, "lights", gltfRuntime);
  2864. }
  2865. if (parsedData.cameras) {
  2866. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2867. }
  2868. if (parsedData.nodes) {
  2869. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2870. }
  2871. if (parsedData.images) {
  2872. parseObject(parsedData.images, "images", gltfRuntime);
  2873. }
  2874. if (parsedData.textures) {
  2875. parseObject(parsedData.textures, "textures", gltfRuntime);
  2876. }
  2877. if (parsedData.shaders) {
  2878. parseShaders(parsedData.shaders, gltfRuntime);
  2879. }
  2880. if (parsedData.programs) {
  2881. parseObject(parsedData.programs, "programs", gltfRuntime);
  2882. }
  2883. if (parsedData.samplers) {
  2884. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2885. }
  2886. if (parsedData.techniques) {
  2887. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2888. }
  2889. if (parsedData.materials) {
  2890. parseObject(parsedData.materials, "materials", gltfRuntime);
  2891. }
  2892. if (parsedData.animations) {
  2893. parseObject(parsedData.animations, "animations", gltfRuntime);
  2894. }
  2895. if (parsedData.skins) {
  2896. parseObject(parsedData.skins, "skins", gltfRuntime);
  2897. }
  2898. if (parsedData.scenes) {
  2899. gltfRuntime.scenes = parsedData.scenes;
  2900. }
  2901. if (parsedData.scene && parsedData.scenes) {
  2902. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2903. }
  2904. return gltfRuntime;
  2905. };
  2906. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2907. var buffer = gltfRuntime.buffers[id];
  2908. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2909. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2910. }
  2911. else {
  2912. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + buffer.uri, function (data) { return onSuccess(new Uint8Array(data)); }, onProgress, undefined, true, function (request) {
  2913. if (request) {
  2914. onError(request.status + " " + request.statusText);
  2915. }
  2916. });
  2917. }
  2918. };
  2919. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2920. var texture = gltfRuntime.textures[id];
  2921. if (!texture || !texture.source) {
  2922. onError("");
  2923. return;
  2924. }
  2925. if (texture.babylonTexture) {
  2926. onSuccess(null);
  2927. return;
  2928. }
  2929. var source = gltfRuntime.images[texture.source];
  2930. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2931. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2932. }
  2933. else {
  2934. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + source.uri, function (data) { return onSuccess(new Uint8Array(data)); }, undefined, undefined, true, function (request) {
  2935. if (request) {
  2936. onError(request.status + " " + request.statusText);
  2937. }
  2938. });
  2939. }
  2940. };
  2941. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2942. var texture = gltfRuntime.textures[id];
  2943. if (texture.babylonTexture) {
  2944. onSuccess(texture.babylonTexture);
  2945. return;
  2946. }
  2947. var sampler = gltfRuntime.samplers[texture.sampler];
  2948. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2949. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2950. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2951. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2952. var samplingMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2953. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2954. var blobURL = URL.createObjectURL(blob);
  2955. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2956. var newTexture = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2957. if (sampler.wrapS !== undefined) {
  2958. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2959. }
  2960. if (sampler.wrapT !== undefined) {
  2961. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2962. }
  2963. newTexture.name = id;
  2964. texture.babylonTexture = newTexture;
  2965. onSuccess(newTexture);
  2966. };
  2967. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2968. var shader = gltfRuntime.shaders[id];
  2969. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2970. var shaderString = atob(shader.uri.split(",")[1]);
  2971. if (onSuccess) {
  2972. onSuccess(shaderString);
  2973. }
  2974. }
  2975. else {
  2976. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2977. if (request && onError) {
  2978. onError(request.status + " " + request.statusText);
  2979. }
  2980. });
  2981. }
  2982. };
  2983. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2984. var material = gltfRuntime.materials[id];
  2985. if (!material.technique) {
  2986. if (onError) {
  2987. onError("No technique found.");
  2988. }
  2989. return;
  2990. }
  2991. var technique = gltfRuntime.techniques[material.technique];
  2992. if (!technique) {
  2993. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2994. var defaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2995. gltfRuntime.scene._blockEntityCollection = false;
  2996. defaultMaterial.diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2997. defaultMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2998. onSuccess(defaultMaterial);
  2999. return;
  3000. }
  3001. var program = gltfRuntime.programs[technique.program];
  3002. var states = technique.states;
  3003. var vertexShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  3004. var pixelShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  3005. var newVertexShader = "";
  3006. var newPixelShader = "";
  3007. var vertexTokenizer = new Tokenizer(vertexShader);
  3008. var pixelTokenizer = new Tokenizer(pixelShader);
  3009. var unTreatedUniforms = {};
  3010. var uniforms = [];
  3011. var attributes = [];
  3012. var samplers = [];
  3013. // Fill uniform, sampler2D and attributes
  3014. for (var unif in technique.uniforms) {
  3015. var uniform = technique.uniforms[unif];
  3016. var uniformParameter = technique.parameters[uniform];
  3017. unTreatedUniforms[unif] = uniformParameter;
  3018. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  3019. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  3020. if (transformIndex !== -1) {
  3021. uniforms.push(babylonTransforms[transformIndex]);
  3022. delete unTreatedUniforms[unif];
  3023. }
  3024. else {
  3025. uniforms.push(unif);
  3026. }
  3027. }
  3028. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  3029. samplers.push(unif);
  3030. }
  3031. else {
  3032. uniforms.push(unif);
  3033. }
  3034. }
  3035. for (var attr in technique.attributes) {
  3036. var attribute = technique.attributes[attr];
  3037. var attributeParameter = technique.parameters[attribute];
  3038. if (attributeParameter.semantic) {
  3039. var name_1 = getAttribute(attributeParameter);
  3040. if (name_1) {
  3041. attributes.push(name_1);
  3042. }
  3043. }
  3044. }
  3045. // Configure vertex shader
  3046. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  3047. var tokenType = vertexTokenizer.currentToken;
  3048. if (tokenType !== ETokenType.IDENTIFIER) {
  3049. newVertexShader += vertexTokenizer.currentString;
  3050. continue;
  3051. }
  3052. var foundAttribute = false;
  3053. for (var attr in technique.attributes) {
  3054. var attribute = technique.attributes[attr];
  3055. var attributeParameter = technique.parameters[attribute];
  3056. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  3057. newVertexShader += getAttribute(attributeParameter);
  3058. foundAttribute = true;
  3059. break;
  3060. }
  3061. }
  3062. if (foundAttribute) {
  3063. continue;
  3064. }
  3065. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  3066. }
  3067. // Configure pixel shader
  3068. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  3069. var tokenType = pixelTokenizer.currentToken;
  3070. if (tokenType !== ETokenType.IDENTIFIER) {
  3071. newPixelShader += pixelTokenizer.currentString;
  3072. continue;
  3073. }
  3074. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  3075. }
  3076. // Create shader material
  3077. var shaderPath = {
  3078. vertex: program.vertexShader + id,
  3079. fragment: program.fragmentShader + id
  3080. };
  3081. var options = {
  3082. attributes: attributes,
  3083. uniforms: uniforms,
  3084. samplers: samplers,
  3085. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  3086. };
  3087. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  3088. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  3089. var shaderMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  3090. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  3091. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  3092. shaderMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  3093. if (states && states.functions) {
  3094. var functions = states.functions;
  3095. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  3096. shaderMaterial.backFaceCulling = false;
  3097. }
  3098. var blendFunc = functions.blendFuncSeparate;
  3099. if (blendFunc) {
  3100. 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) {
  3101. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  3102. }
  3103. 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) {
  3104. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  3105. }
  3106. 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) {
  3107. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  3108. }
  3109. 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) {
  3110. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  3111. }
  3112. 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) {
  3113. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  3114. }
  3115. 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) {
  3116. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  3117. }
  3118. }
  3119. }
  3120. };
  3121. return GLTFLoaderBase;
  3122. }());
  3123. /**
  3124. * glTF V1 Loader
  3125. * @hidden
  3126. */
  3127. var GLTFLoader = /** @class */ (function () {
  3128. function GLTFLoader() {
  3129. this.state = null;
  3130. }
  3131. GLTFLoader.RegisterExtension = function (extension) {
  3132. if (GLTFLoader.Extensions[extension.name]) {
  3133. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  3134. return;
  3135. }
  3136. GLTFLoader.Extensions[extension.name] = extension;
  3137. };
  3138. GLTFLoader.prototype.dispose = function () {
  3139. // do nothing
  3140. };
  3141. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3142. var _this = this;
  3143. scene.useRightHandedSystem = true;
  3144. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3145. gltfRuntime.forAssetContainer = forAssetContainer;
  3146. gltfRuntime.importOnlyMeshes = true;
  3147. if (meshesNames === "") {
  3148. gltfRuntime.importMeshesNames = [];
  3149. }
  3150. else if (typeof meshesNames === "string") {
  3151. gltfRuntime.importMeshesNames = [meshesNames];
  3152. }
  3153. else if (meshesNames && !(meshesNames instanceof Array)) {
  3154. gltfRuntime.importMeshesNames = [meshesNames];
  3155. }
  3156. else {
  3157. gltfRuntime.importMeshesNames = [];
  3158. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3159. }
  3160. // Create nodes
  3161. _this._createNodes(gltfRuntime);
  3162. var meshes = new Array();
  3163. var skeletons = new Array();
  3164. // Fill arrays of meshes and skeletons
  3165. for (var nde in gltfRuntime.nodes) {
  3166. var node = gltfRuntime.nodes[nde];
  3167. if (node.babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3168. meshes.push(node.babylonNode);
  3169. }
  3170. }
  3171. for (var skl in gltfRuntime.skins) {
  3172. var skin = gltfRuntime.skins[skl];
  3173. if (skin.babylonSkeleton instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3174. skeletons.push(skin.babylonSkeleton);
  3175. }
  3176. }
  3177. // Load buffers, shaders, materials, etc.
  3178. _this._loadBuffersAsync(gltfRuntime, function () {
  3179. _this._loadShadersAsync(gltfRuntime, function () {
  3180. importMaterials(gltfRuntime);
  3181. postLoad(gltfRuntime);
  3182. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3183. onSuccess(meshes, skeletons);
  3184. }
  3185. });
  3186. }, onProgress);
  3187. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3188. onSuccess(meshes, skeletons);
  3189. }
  3190. }, onError);
  3191. return true;
  3192. };
  3193. /**
  3194. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3195. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3196. * @param scene the scene the meshes should be added to
  3197. * @param forAssetContainer defines if the entities must be stored in the scene
  3198. * @param data gltf data containing information of the meshes in a loaded file
  3199. * @param rootUrl root url to load from
  3200. * @param onProgress event that fires when loading progress has occured
  3201. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3202. */
  3203. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress) {
  3204. var _this = this;
  3205. return new Promise(function (resolve, reject) {
  3206. _this._importMeshAsync(meshesNames, scene, data, rootUrl, forAssetContainer, function (meshes, skeletons) {
  3207. resolve({
  3208. meshes: meshes,
  3209. particleSystems: [],
  3210. skeletons: skeletons,
  3211. animationGroups: [],
  3212. lights: [],
  3213. transformNodes: [],
  3214. geometries: []
  3215. });
  3216. }, onProgress, function (message) {
  3217. reject(new Error(message));
  3218. });
  3219. });
  3220. };
  3221. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3222. var _this = this;
  3223. scene.useRightHandedSystem = true;
  3224. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3225. // Load runtime extensios
  3226. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3227. // Create nodes
  3228. _this._createNodes(gltfRuntime);
  3229. // Load buffers, shaders, materials, etc.
  3230. _this._loadBuffersAsync(gltfRuntime, function () {
  3231. _this._loadShadersAsync(gltfRuntime, function () {
  3232. importMaterials(gltfRuntime);
  3233. postLoad(gltfRuntime);
  3234. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3235. onSuccess();
  3236. }
  3237. });
  3238. });
  3239. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3240. onSuccess();
  3241. }
  3242. }, onError);
  3243. }, onError);
  3244. };
  3245. /**
  3246. * Imports all objects from a loaded gltf file and adds them to the scene
  3247. * @param scene the scene the objects should be added to
  3248. * @param data gltf data containing information of the meshes in a loaded file
  3249. * @param rootUrl root url to load from
  3250. * @param onProgress event that fires when loading progress has occured
  3251. * @returns a promise which completes when objects have been loaded to the scene
  3252. */
  3253. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3254. var _this = this;
  3255. return new Promise(function (resolve, reject) {
  3256. _this._loadAsync(scene, data, rootUrl, false, function () {
  3257. resolve();
  3258. }, onProgress, function (message) {
  3259. reject(new Error(message));
  3260. });
  3261. });
  3262. };
  3263. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3264. var hasShaders = false;
  3265. var processShader = function (sha, shader) {
  3266. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3267. if (shaderString instanceof ArrayBuffer) {
  3268. return;
  3269. }
  3270. gltfRuntime.loadedShaderCount++;
  3271. if (shaderString) {
  3272. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3273. }
  3274. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3275. onload();
  3276. }
  3277. }, function () {
  3278. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3279. });
  3280. };
  3281. for (var sha in gltfRuntime.shaders) {
  3282. hasShaders = true;
  3283. var shader = gltfRuntime.shaders[sha];
  3284. if (shader) {
  3285. processShader.bind(this, sha, shader)();
  3286. }
  3287. else {
  3288. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3289. }
  3290. }
  3291. if (!hasShaders) {
  3292. onload();
  3293. }
  3294. };
  3295. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3296. var hasBuffers = false;
  3297. var processBuffer = function (buf, buffer) {
  3298. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3299. gltfRuntime.loadedBufferCount++;
  3300. if (bufferView) {
  3301. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3302. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3303. }
  3304. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3305. }
  3306. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3307. onLoad();
  3308. }
  3309. }, function () {
  3310. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3311. });
  3312. };
  3313. for (var buf in gltfRuntime.buffers) {
  3314. hasBuffers = true;
  3315. var buffer = gltfRuntime.buffers[buf];
  3316. if (buffer) {
  3317. processBuffer.bind(this, buf, buffer)();
  3318. }
  3319. else {
  3320. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3321. }
  3322. }
  3323. if (!hasBuffers) {
  3324. onLoad();
  3325. }
  3326. };
  3327. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3328. var currentScene = gltfRuntime.currentScene;
  3329. if (currentScene) {
  3330. // Only one scene even if multiple scenes are defined
  3331. for (var i = 0; i < currentScene.nodes.length; i++) {
  3332. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3333. }
  3334. }
  3335. else {
  3336. // Load all scenes
  3337. for (var thing in gltfRuntime.scenes) {
  3338. currentScene = gltfRuntime.scenes[thing];
  3339. for (var i = 0; i < currentScene.nodes.length; i++) {
  3340. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3341. }
  3342. }
  3343. }
  3344. };
  3345. GLTFLoader.Extensions = {};
  3346. return GLTFLoader;
  3347. }());
  3348. /** @hidden */
  3349. var GLTFLoaderExtension = /** @class */ (function () {
  3350. function GLTFLoaderExtension(name) {
  3351. this._name = name;
  3352. }
  3353. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3354. get: function () {
  3355. return this._name;
  3356. },
  3357. enumerable: false,
  3358. configurable: true
  3359. });
  3360. /**
  3361. * Defines an override for loading the runtime
  3362. * Return true to stop further extensions from loading the runtime
  3363. */
  3364. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3365. return false;
  3366. };
  3367. /**
  3368. * Defines an onverride for creating gltf runtime
  3369. * Return true to stop further extensions from creating the runtime
  3370. */
  3371. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3372. return false;
  3373. };
  3374. /**
  3375. * Defines an override for loading buffers
  3376. * Return true to stop further extensions from loading this buffer
  3377. */
  3378. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3379. return false;
  3380. };
  3381. /**
  3382. * Defines an override for loading texture buffers
  3383. * Return true to stop further extensions from loading this texture data
  3384. */
  3385. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3386. return false;
  3387. };
  3388. /**
  3389. * Defines an override for creating textures
  3390. * Return true to stop further extensions from loading this texture
  3391. */
  3392. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3393. return false;
  3394. };
  3395. /**
  3396. * Defines an override for loading shader strings
  3397. * Return true to stop further extensions from loading this shader data
  3398. */
  3399. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3400. return false;
  3401. };
  3402. /**
  3403. * Defines an override for loading materials
  3404. * Return true to stop further extensions from loading this material
  3405. */
  3406. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3407. return false;
  3408. };
  3409. // ---------
  3410. // Utilities
  3411. // ---------
  3412. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3413. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3414. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3415. }, function () {
  3416. setTimeout(function () {
  3417. if (!onSuccess) {
  3418. return;
  3419. }
  3420. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3421. });
  3422. });
  3423. };
  3424. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3425. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3426. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3427. }, function () {
  3428. setTimeout(function () {
  3429. onSuccess();
  3430. });
  3431. });
  3432. };
  3433. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3434. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3435. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3436. }, function () {
  3437. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3438. });
  3439. };
  3440. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3441. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3442. if (buffer) {
  3443. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3444. }
  3445. }, onError);
  3446. };
  3447. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3448. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3449. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3450. }, function () {
  3451. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3452. });
  3453. };
  3454. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3455. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3456. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3457. }, function () {
  3458. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3459. });
  3460. };
  3461. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3462. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3463. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3464. }, function () {
  3465. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3466. });
  3467. };
  3468. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3469. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3470. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3471. }, function () {
  3472. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3473. });
  3474. };
  3475. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3476. for (var extensionName in GLTFLoader.Extensions) {
  3477. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3478. if (func(loaderExtension)) {
  3479. return;
  3480. }
  3481. }
  3482. defaultFunc();
  3483. };
  3484. return GLTFLoaderExtension;
  3485. }());
  3486. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3487. /***/ }),
  3488. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3489. /*!******************************************!*\
  3490. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3491. \******************************************/
  3492. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3493. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3494. "use strict";
  3495. __webpack_require__.r(__webpack_exports__);
  3496. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3497. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3498. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3499. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3500. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3501. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3502. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3503. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3504. /**
  3505. * Enums
  3506. * @hidden
  3507. */
  3508. var EComponentType;
  3509. (function (EComponentType) {
  3510. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3511. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3512. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3513. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3514. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3515. })(EComponentType || (EComponentType = {}));
  3516. /** @hidden */
  3517. var EShaderType;
  3518. (function (EShaderType) {
  3519. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3520. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3521. })(EShaderType || (EShaderType = {}));
  3522. /** @hidden */
  3523. var EParameterType;
  3524. (function (EParameterType) {
  3525. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3526. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3527. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3528. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3529. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3530. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3531. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3532. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3533. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3534. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3535. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3536. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3537. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3538. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3539. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3540. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3541. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3542. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3543. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3544. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3545. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3546. })(EParameterType || (EParameterType = {}));
  3547. /** @hidden */
  3548. var ETextureWrapMode;
  3549. (function (ETextureWrapMode) {
  3550. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3551. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3552. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3553. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3554. /** @hidden */
  3555. var ETextureFilterType;
  3556. (function (ETextureFilterType) {
  3557. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3558. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3559. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3560. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3561. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3562. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3563. })(ETextureFilterType || (ETextureFilterType = {}));
  3564. /** @hidden */
  3565. var ETextureFormat;
  3566. (function (ETextureFormat) {
  3567. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3568. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3569. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3570. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3571. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3572. })(ETextureFormat || (ETextureFormat = {}));
  3573. /** @hidden */
  3574. var ECullingType;
  3575. (function (ECullingType) {
  3576. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3577. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3578. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3579. })(ECullingType || (ECullingType = {}));
  3580. /** @hidden */
  3581. var EBlendingFunction;
  3582. (function (EBlendingFunction) {
  3583. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3584. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3585. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3586. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3587. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3588. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3589. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3590. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3591. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3592. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3593. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3594. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3595. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3596. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3597. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3598. })(EBlendingFunction || (EBlendingFunction = {}));
  3599. /***/ }),
  3600. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3601. /*!*************************************!*\
  3602. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3603. \*************************************/
  3604. /*! exports provided: GLTFUtils */
  3605. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3606. "use strict";
  3607. __webpack_require__.r(__webpack_exports__);
  3608. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3609. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3610. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3611. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  3612. /**
  3613. * Utils functions for GLTF
  3614. * @hidden
  3615. */
  3616. var GLTFUtils = /** @class */ (function () {
  3617. function GLTFUtils() {
  3618. }
  3619. /**
  3620. * Sets the given "parameter" matrix
  3621. * @param scene: the Scene object
  3622. * @param source: the source node where to pick the matrix
  3623. * @param parameter: the GLTF technique parameter
  3624. * @param uniformName: the name of the shader's uniform
  3625. * @param shaderMaterial: the shader material
  3626. */
  3627. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3628. var mat = null;
  3629. if (parameter.semantic === "MODEL") {
  3630. mat = source.getWorldMatrix();
  3631. }
  3632. else if (parameter.semantic === "PROJECTION") {
  3633. mat = scene.getProjectionMatrix();
  3634. }
  3635. else if (parameter.semantic === "VIEW") {
  3636. mat = scene.getViewMatrix();
  3637. }
  3638. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3639. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3640. }
  3641. else if (parameter.semantic === "MODELVIEW") {
  3642. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3643. }
  3644. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3645. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3646. }
  3647. else if (parameter.semantic === "MODELINVERSE") {
  3648. mat = source.getWorldMatrix().invert();
  3649. }
  3650. else if (parameter.semantic === "VIEWINVERSE") {
  3651. mat = scene.getViewMatrix().invert();
  3652. }
  3653. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3654. mat = scene.getProjectionMatrix().invert();
  3655. }
  3656. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3657. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3658. }
  3659. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3660. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3661. }
  3662. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3663. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3664. }
  3665. else {
  3666. debugger;
  3667. }
  3668. if (mat) {
  3669. switch (parameter.type) {
  3670. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3671. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3672. break;
  3673. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3674. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3675. break;
  3676. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3677. shaderMaterial.setMatrix(uniformName, mat);
  3678. break;
  3679. default: break;
  3680. }
  3681. }
  3682. };
  3683. /**
  3684. * Sets the given "parameter" matrix
  3685. * @param shaderMaterial: the shader material
  3686. * @param uniform: the name of the shader's uniform
  3687. * @param value: the value of the uniform
  3688. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3689. */
  3690. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3691. switch (type) {
  3692. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3693. shaderMaterial.setFloat(uniform, value);
  3694. return true;
  3695. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3696. shaderMaterial.setVector2(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3697. return true;
  3698. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3699. shaderMaterial.setVector3(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3700. return true;
  3701. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3702. shaderMaterial.setVector4(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3703. return true;
  3704. default: return false;
  3705. }
  3706. };
  3707. /**
  3708. * Returns the wrap mode of the texture
  3709. * @param mode: the mode value
  3710. */
  3711. GLTFUtils.GetWrapMode = function (mode) {
  3712. switch (mode) {
  3713. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3714. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3715. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3716. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3717. }
  3718. };
  3719. /**
  3720. * Returns the byte stride giving an accessor
  3721. * @param accessor: the GLTF accessor objet
  3722. */
  3723. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3724. // Needs this function since "byteStride" isn't requiered in glTF format
  3725. var type = accessor.type;
  3726. switch (type) {
  3727. case "VEC2": return 2;
  3728. case "VEC3": return 3;
  3729. case "VEC4": return 4;
  3730. case "MAT2": return 4;
  3731. case "MAT3": return 9;
  3732. case "MAT4": return 16;
  3733. default: return 1;
  3734. }
  3735. };
  3736. /**
  3737. * Returns the texture filter mode giving a mode value
  3738. * @param mode: the filter mode value
  3739. */
  3740. GLTFUtils.GetTextureFilterMode = function (mode) {
  3741. switch (mode) {
  3742. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3743. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3744. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3745. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3746. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3747. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3748. }
  3749. };
  3750. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3751. var byteOffset = bufferView.byteOffset + byteOffset;
  3752. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3753. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3754. throw new Error("Buffer access is out of range");
  3755. }
  3756. var buffer = loadedBufferView.buffer;
  3757. byteOffset += loadedBufferView.byteOffset;
  3758. switch (componentType) {
  3759. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3760. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3761. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3762. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3763. default: return new Float32Array(buffer, byteOffset, byteLength);
  3764. }
  3765. };
  3766. /**
  3767. * Returns a buffer from its accessor
  3768. * @param gltfRuntime: the GLTF runtime
  3769. * @param accessor: the GLTF accessor
  3770. */
  3771. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3772. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3773. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3774. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3775. };
  3776. /**
  3777. * Decodes a buffer view into a string
  3778. * @param view: the buffer view
  3779. */
  3780. GLTFUtils.DecodeBufferToText = function (view) {
  3781. var result = "";
  3782. var length = view.byteLength;
  3783. for (var i = 0; i < length; ++i) {
  3784. result += String.fromCharCode(view[i]);
  3785. }
  3786. return result;
  3787. };
  3788. /**
  3789. * Returns the default material of gltf. Related to
  3790. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3791. * @param scene: the Babylon.js scene
  3792. */
  3793. GLTFUtils.GetDefaultMaterial = function (scene) {
  3794. if (!GLTFUtils._DefaultMaterial) {
  3795. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3796. "precision highp float;",
  3797. "",
  3798. "uniform mat4 worldView;",
  3799. "uniform mat4 projection;",
  3800. "",
  3801. "attribute vec3 position;",
  3802. "",
  3803. "void main(void)",
  3804. "{",
  3805. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3806. "}"
  3807. ].join("\n");
  3808. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3809. "precision highp float;",
  3810. "",
  3811. "uniform vec4 u_emission;",
  3812. "",
  3813. "void main(void)",
  3814. "{",
  3815. " gl_FragColor = u_emission;",
  3816. "}"
  3817. ].join("\n");
  3818. var shaderPath = {
  3819. vertex: "GLTFDefaultMaterial",
  3820. fragment: "GLTFDefaultMaterial"
  3821. };
  3822. var options = {
  3823. attributes: ["position"],
  3824. uniforms: ["worldView", "projection", "u_emission"],
  3825. samplers: new Array(),
  3826. needAlphaBlending: false
  3827. };
  3828. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3829. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3830. }
  3831. return GLTFUtils._DefaultMaterial;
  3832. };
  3833. // The GLTF default material
  3834. GLTFUtils._DefaultMaterial = null;
  3835. return GLTFUtils;
  3836. }());
  3837. /***/ }),
  3838. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3839. /*!**************************************************!*\
  3840. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3841. \**************************************************/
  3842. /*! exports provided: GLTFMaterialsCommonExtension */
  3843. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3844. "use strict";
  3845. __webpack_require__.r(__webpack_exports__);
  3846. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3847. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3848. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3849. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3850. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__);
  3851. /** @hidden */
  3852. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3853. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3854. function GLTFMaterialsCommonExtension() {
  3855. return _super.call(this, "KHR_materials_common") || this;
  3856. }
  3857. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3858. if (!gltfRuntime.extensions) {
  3859. return false;
  3860. }
  3861. var extension = gltfRuntime.extensions[this.name];
  3862. if (!extension) {
  3863. return false;
  3864. }
  3865. // Create lights
  3866. var lights = extension.lights;
  3867. if (lights) {
  3868. for (var thing in lights) {
  3869. var light = lights[thing];
  3870. switch (light.type) {
  3871. case "ambient":
  3872. var ambientLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["HemisphericLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 1, 0), gltfRuntime.scene);
  3873. var ambient = light.ambient;
  3874. if (ambient) {
  3875. ambientLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3876. }
  3877. break;
  3878. case "point":
  3879. var pointLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["PointLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](10, 10, 10), gltfRuntime.scene);
  3880. var point = light.point;
  3881. if (point) {
  3882. pointLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3883. }
  3884. break;
  3885. case "directional":
  3886. var dirLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["DirectionalLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), gltfRuntime.scene);
  3887. var directional = light.directional;
  3888. if (directional) {
  3889. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3890. }
  3891. break;
  3892. case "spot":
  3893. var spot = light.spot;
  3894. if (spot) {
  3895. var spotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["SpotLight"](light.name, new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, 10, 0), new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Vector3"](0, -1, 0), spot.fallOffAngle || Math.PI, spot.fallOffExponent || 0.0, gltfRuntime.scene);
  3896. spotLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3897. }
  3898. break;
  3899. default:
  3900. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3901. break;
  3902. }
  3903. }
  3904. }
  3905. return false;
  3906. };
  3907. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3908. var material = gltfRuntime.materials[id];
  3909. if (!material || !material.extensions) {
  3910. return false;
  3911. }
  3912. var extension = material.extensions[this.name];
  3913. if (!extension) {
  3914. return false;
  3915. }
  3916. var standardMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3917. standardMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3918. if (extension.technique === "CONSTANT") {
  3919. standardMaterial.disableLighting = true;
  3920. }
  3921. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3922. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3923. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3924. // Ambient
  3925. if (typeof extension.values.ambient === "string") {
  3926. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3927. }
  3928. else {
  3929. standardMaterial.ambientColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3930. }
  3931. // Diffuse
  3932. if (typeof extension.values.diffuse === "string") {
  3933. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3934. }
  3935. else {
  3936. standardMaterial.diffuseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3937. }
  3938. // Emission
  3939. if (typeof extension.values.emission === "string") {
  3940. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3941. }
  3942. else {
  3943. standardMaterial.emissiveColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3944. }
  3945. // Specular
  3946. if (typeof extension.values.specular === "string") {
  3947. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3948. }
  3949. else {
  3950. standardMaterial.specularColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3951. }
  3952. return true;
  3953. };
  3954. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3955. // Create buffer from texture url
  3956. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3957. // Create texture from buffer
  3958. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3959. }, onError);
  3960. };
  3961. return GLTFMaterialsCommonExtension;
  3962. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3963. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3964. /***/ }),
  3965. /***/ "./glTF/1.0/index.ts":
  3966. /*!***************************!*\
  3967. !*** ./glTF/1.0/index.ts ***!
  3968. \***************************/
  3969. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3970. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3971. "use strict";
  3972. __webpack_require__.r(__webpack_exports__);
  3973. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3974. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3975. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3976. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3977. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3978. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3979. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3980. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3981. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3982. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3983. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3984. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3985. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3986. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3987. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3988. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3989. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3990. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3991. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3992. /***/ }),
  3993. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3994. /*!*******************************************************!*\
  3995. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3996. \*******************************************************/
  3997. /*! exports provided: EXT_lights_image_based */
  3998. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3999. "use strict";
  4000. __webpack_require__.r(__webpack_exports__);
  4001. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  4002. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  4003. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  4004. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4005. var NAME = "EXT_lights_image_based";
  4006. /**
  4007. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  4008. */
  4009. var EXT_lights_image_based = /** @class */ (function () {
  4010. /** @hidden */
  4011. function EXT_lights_image_based(loader) {
  4012. /**
  4013. * The name of this extension.
  4014. */
  4015. this.name = NAME;
  4016. this._loader = loader;
  4017. this.enabled = this._loader.isExtensionUsed(NAME);
  4018. }
  4019. /** @hidden */
  4020. EXT_lights_image_based.prototype.dispose = function () {
  4021. this._loader = null;
  4022. delete this._lights;
  4023. };
  4024. /** @hidden */
  4025. EXT_lights_image_based.prototype.onLoading = function () {
  4026. var extensions = this._loader.gltf.extensions;
  4027. if (extensions && extensions[this.name]) {
  4028. var extension = extensions[this.name];
  4029. this._lights = extension.lights;
  4030. }
  4031. };
  4032. /** @hidden */
  4033. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  4034. var _this = this;
  4035. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  4036. var promises = new Array();
  4037. promises.push(_this._loader.loadSceneAsync(context, scene));
  4038. _this._loader.logOpen("" + extensionContext);
  4039. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  4040. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  4041. _this._loader.babylonScene.environmentTexture = texture;
  4042. }));
  4043. _this._loader.logClose();
  4044. return Promise.all(promises).then(function () { });
  4045. });
  4046. };
  4047. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  4048. var _this = this;
  4049. if (!light._loaded) {
  4050. var promises = new Array();
  4051. this._loader.logOpen("" + context);
  4052. var imageData_1 = new Array(light.specularImages.length);
  4053. var _loop_1 = function (mipmap) {
  4054. var faces = light.specularImages[mipmap];
  4055. imageData_1[mipmap] = new Array(faces.length);
  4056. var _loop_2 = function (face) {
  4057. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  4058. this_1._loader.logOpen("" + specularImageContext);
  4059. var index = faces[face];
  4060. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  4061. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  4062. imageData_1[mipmap][face] = data;
  4063. }));
  4064. this_1._loader.logClose();
  4065. };
  4066. for (var face = 0; face < faces.length; face++) {
  4067. _loop_2(face);
  4068. }
  4069. };
  4070. var this_1 = this;
  4071. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  4072. _loop_1(mipmap);
  4073. }
  4074. this._loader.logClose();
  4075. light._loaded = Promise.all(promises).then(function () {
  4076. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  4077. babylonTexture.name = light.name || "environment";
  4078. light._babylonTexture = babylonTexture;
  4079. if (light.intensity != undefined) {
  4080. babylonTexture.level = light.intensity;
  4081. }
  4082. if (light.rotation) {
  4083. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  4084. // Invert the rotation so that positive rotation is counter-clockwise.
  4085. if (!_this._loader.babylonScene.useRightHandedSystem) {
  4086. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  4087. }
  4088. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  4089. }
  4090. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  4091. sphericalHarmonics.scaleInPlace(light.intensity);
  4092. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  4093. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  4094. // Compute the lod generation scale to fit exactly to the number of levels available.
  4095. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  4096. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  4097. });
  4098. }
  4099. return light._loaded.then(function () {
  4100. return light._babylonTexture;
  4101. });
  4102. };
  4103. return EXT_lights_image_based;
  4104. }());
  4105. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  4106. /***/ }),
  4107. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  4108. /*!********************************************************!*\
  4109. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  4110. \********************************************************/
  4111. /*! exports provided: EXT_mesh_gpu_instancing */
  4112. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4113. "use strict";
  4114. __webpack_require__.r(__webpack_exports__);
  4115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  4116. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4117. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4118. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4119. var NAME = "EXT_mesh_gpu_instancing";
  4120. /**
  4121. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  4122. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  4123. * !!! Experimental Extension Subject to Changes !!!
  4124. */
  4125. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  4126. /** @hidden */
  4127. function EXT_mesh_gpu_instancing(loader) {
  4128. /**
  4129. * The name of this extension.
  4130. */
  4131. this.name = NAME;
  4132. this._loader = loader;
  4133. this.enabled = this._loader.isExtensionUsed(NAME);
  4134. }
  4135. /** @hidden */
  4136. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  4137. this._loader = null;
  4138. };
  4139. /** @hidden */
  4140. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  4141. var _this = this;
  4142. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4143. _this._loader._disableInstancedMesh++;
  4144. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  4145. _this._loader._disableInstancedMesh--;
  4146. if (!node._primitiveBabylonMeshes) {
  4147. return promise;
  4148. }
  4149. var promises = new Array();
  4150. var instanceCount = 0;
  4151. var loadAttribute = function (attribute) {
  4152. if (extension.attributes[attribute] == undefined) {
  4153. promises.push(Promise.resolve(null));
  4154. return;
  4155. }
  4156. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  4157. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  4158. if (instanceCount === 0) {
  4159. instanceCount = accessor.count;
  4160. }
  4161. else if (instanceCount !== accessor.count) {
  4162. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  4163. }
  4164. };
  4165. loadAttribute("TRANSLATION");
  4166. loadAttribute("ROTATION");
  4167. loadAttribute("SCALE");
  4168. return promise.then(function (babylonTransformNode) {
  4169. return Promise.all(promises).then(function (_a) {
  4170. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  4171. var matrices = new Float32Array(instanceCount * 16);
  4172. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  4173. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  4174. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  4175. for (var i = 0; i < instanceCount; ++i) {
  4176. translationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(translationBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0]);
  4177. rotationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArrayToRef(rotationBuffer, i * 4, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0]);
  4178. scaleBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(scaleBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1]);
  4179. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0]);
  4180. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  4181. }
  4182. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  4183. var babylonMesh = _b[_i];
  4184. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  4185. }
  4186. return babylonTransformNode;
  4187. });
  4188. });
  4189. });
  4190. };
  4191. return EXT_mesh_gpu_instancing;
  4192. }());
  4193. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  4194. /***/ }),
  4195. /***/ "./glTF/2.0/Extensions/EXT_meshopt_compression.ts":
  4196. /*!********************************************************!*\
  4197. !*** ./glTF/2.0/Extensions/EXT_meshopt_compression.ts ***!
  4198. \********************************************************/
  4199. /*! exports provided: EXT_meshopt_compression */
  4200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4201. "use strict";
  4202. __webpack_require__.r(__webpack_exports__);
  4203. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_meshopt_compression", function() { return EXT_meshopt_compression; });
  4204. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  4205. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  4206. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4207. var NAME = "EXT_meshopt_compression";
  4208. /**
  4209. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression)
  4210. *
  4211. * This extension uses a WebAssembly decoder module from https://github.com/zeux/meshoptimizer/tree/master/js
  4212. */
  4213. var EXT_meshopt_compression = /** @class */ (function () {
  4214. /** @hidden */
  4215. function EXT_meshopt_compression(loader) {
  4216. /**
  4217. * The name of this extension.
  4218. */
  4219. this.name = NAME;
  4220. this.enabled = loader.isExtensionUsed(NAME);
  4221. this._loader = loader;
  4222. if (this.enabled) {
  4223. this._decoderPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(EXT_meshopt_compression.DecoderPath).then(function () {
  4224. // Wait for WebAssembly compilation before resolving promise
  4225. return MeshoptDecoder.ready;
  4226. });
  4227. }
  4228. }
  4229. /** @hidden */
  4230. EXT_meshopt_compression.prototype.dispose = function () {
  4231. this._loader = null;
  4232. delete this._decoderPromise;
  4233. };
  4234. /** @hidden */
  4235. EXT_meshopt_compression.prototype.loadBufferViewAsync = function (context, bufferView) {
  4236. var _this = this;
  4237. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, bufferView, this.name, function (extensionContext, extension) {
  4238. var bufferViewMeshopt = bufferView;
  4239. if (bufferViewMeshopt._meshOptData) {
  4240. return bufferViewMeshopt._meshOptData;
  4241. }
  4242. var buffer = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/buffer", _this._loader.gltf.buffers, extension.buffer);
  4243. var bufferPromise = _this._loader.loadBufferAsync("/buffers/" + buffer.index, buffer, (extension.byteOffset || 0), extension.byteLength);
  4244. bufferViewMeshopt._meshOptData = Promise.all([bufferPromise, _this._decoderPromise]).then(function (res) {
  4245. var source = res[0];
  4246. var count = extension.count;
  4247. var stride = extension.byteStride;
  4248. var result = new Uint8Array(new ArrayBuffer(count * stride));
  4249. MeshoptDecoder.decodeGltfBuffer(result, count, stride, source, extension.mode, extension.filter);
  4250. return Promise.resolve(result);
  4251. });
  4252. return bufferViewMeshopt._meshOptData;
  4253. });
  4254. };
  4255. /**
  4256. * Path to decoder module; defaults to https://preview.babylonjs.com/meshopt_decoder.js
  4257. */
  4258. EXT_meshopt_compression.DecoderPath = "https://preview.babylonjs.com/meshopt_decoder.js";
  4259. return EXT_meshopt_compression;
  4260. }());
  4261. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_meshopt_compression(loader); });
  4262. /***/ }),
  4263. /***/ "./glTF/2.0/Extensions/EXT_texture_webp.ts":
  4264. /*!*************************************************!*\
  4265. !*** ./glTF/2.0/Extensions/EXT_texture_webp.ts ***!
  4266. \*************************************************/
  4267. /*! exports provided: EXT_texture_webp */
  4268. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4269. "use strict";
  4270. __webpack_require__.r(__webpack_exports__);
  4271. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_texture_webp", function() { return EXT_texture_webp; });
  4272. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4273. var NAME = "EXT_texture_webp";
  4274. /**
  4275. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_texture_webp/)
  4276. */
  4277. var EXT_texture_webp = /** @class */ (function () {
  4278. /** @hidden */
  4279. function EXT_texture_webp(loader) {
  4280. /** The name of this extension. */
  4281. this.name = NAME;
  4282. this._loader = loader;
  4283. this.enabled = loader.isExtensionUsed(NAME);
  4284. }
  4285. /** @hidden */
  4286. EXT_texture_webp.prototype.dispose = function () {
  4287. this._loader = null;
  4288. };
  4289. /** @hidden */
  4290. EXT_texture_webp.prototype._loadTextureAsync = function (context, texture, assign) {
  4291. var _this = this;
  4292. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  4293. var sampler = (texture.sampler == undefined ? _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].DefaultSampler : _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(context + "/sampler", _this._loader.gltf.samplers, texture.sampler));
  4294. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  4295. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  4296. assign(babylonTexture);
  4297. });
  4298. });
  4299. };
  4300. return EXT_texture_webp;
  4301. }());
  4302. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_texture_webp(loader); });
  4303. /***/ }),
  4304. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  4305. /*!*************************************************!*\
  4306. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  4307. \*************************************************/
  4308. /*! exports provided: ExtrasAsMetadata */
  4309. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4310. "use strict";
  4311. __webpack_require__.r(__webpack_exports__);
  4312. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  4313. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4314. var NAME = "ExtrasAsMetadata";
  4315. /**
  4316. * Store glTF extras (if present) in BJS objects' metadata
  4317. */
  4318. var ExtrasAsMetadata = /** @class */ (function () {
  4319. /** @hidden */
  4320. function ExtrasAsMetadata(loader) {
  4321. /**
  4322. * The name of this extension.
  4323. */
  4324. this.name = NAME;
  4325. /**
  4326. * Defines whether this extension is enabled.
  4327. */
  4328. this.enabled = true;
  4329. this._loader = loader;
  4330. }
  4331. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  4332. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  4333. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  4334. var gltf = (metadata.gltf = metadata.gltf || {});
  4335. gltf.extras = gltfProp.extras;
  4336. }
  4337. };
  4338. /** @hidden */
  4339. ExtrasAsMetadata.prototype.dispose = function () {
  4340. this._loader = null;
  4341. };
  4342. /** @hidden */
  4343. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4344. var _this = this;
  4345. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4346. _this._assignExtras(babylonTransformNode, node);
  4347. assign(babylonTransformNode);
  4348. });
  4349. };
  4350. /** @hidden */
  4351. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4352. var _this = this;
  4353. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4354. _this._assignExtras(babylonCamera, camera);
  4355. assign(babylonCamera);
  4356. });
  4357. };
  4358. /** @hidden */
  4359. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4360. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4361. this._assignExtras(babylonMaterial, material);
  4362. return babylonMaterial;
  4363. };
  4364. return ExtrasAsMetadata;
  4365. }());
  4366. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4367. /***/ }),
  4368. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4369. /*!***********************************************************!*\
  4370. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4371. \***********************************************************/
  4372. /*! exports provided: KHR_draco_mesh_compression */
  4373. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4374. "use strict";
  4375. __webpack_require__.r(__webpack_exports__);
  4376. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4377. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  4378. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4379. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4380. var NAME = "KHR_draco_mesh_compression";
  4381. /**
  4382. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4383. */
  4384. var KHR_draco_mesh_compression = /** @class */ (function () {
  4385. /** @hidden */
  4386. function KHR_draco_mesh_compression(loader) {
  4387. /**
  4388. * The name of this extension.
  4389. */
  4390. this.name = NAME;
  4391. this._loader = loader;
  4392. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4393. }
  4394. /** @hidden */
  4395. KHR_draco_mesh_compression.prototype.dispose = function () {
  4396. delete this.dracoCompression;
  4397. this._loader = null;
  4398. };
  4399. /** @hidden */
  4400. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4401. var _this = this;
  4402. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4403. if (primitive.mode != undefined) {
  4404. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4405. primitive.mode !== 4 /* TRIANGLES */) {
  4406. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4407. }
  4408. // TODO: handle triangle strips
  4409. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4410. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4411. }
  4412. }
  4413. var attributes = {};
  4414. var loadAttribute = function (name, kind) {
  4415. var uniqueId = extension.attributes[name];
  4416. if (uniqueId == undefined) {
  4417. return;
  4418. }
  4419. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4420. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4421. babylonMesh._delayInfo.push(kind);
  4422. }
  4423. attributes[kind] = uniqueId;
  4424. };
  4425. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4426. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4427. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4428. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4429. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4430. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4431. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4432. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4433. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4434. if (!bufferView._dracoBabylonGeometry) {
  4435. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4436. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4437. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4438. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4439. babylonVertexData.applyToGeometry(babylonGeometry);
  4440. return babylonGeometry;
  4441. }).catch(function (error) {
  4442. throw new Error(context + ": " + error.message);
  4443. });
  4444. });
  4445. }
  4446. return bufferView._dracoBabylonGeometry;
  4447. });
  4448. };
  4449. return KHR_draco_mesh_compression;
  4450. }());
  4451. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4452. /***/ }),
  4453. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4454. /*!****************************************************!*\
  4455. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4456. \****************************************************/
  4457. /*! exports provided: KHR_lights */
  4458. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4459. "use strict";
  4460. __webpack_require__.r(__webpack_exports__);
  4461. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4462. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4463. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4464. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4465. var NAME = "KHR_lights_punctual";
  4466. /**
  4467. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  4468. */
  4469. var KHR_lights = /** @class */ (function () {
  4470. /** @hidden */
  4471. function KHR_lights(loader) {
  4472. /**
  4473. * The name of this extension.
  4474. */
  4475. this.name = NAME;
  4476. this._loader = loader;
  4477. this.enabled = this._loader.isExtensionUsed(NAME);
  4478. }
  4479. /** @hidden */
  4480. KHR_lights.prototype.dispose = function () {
  4481. this._loader = null;
  4482. delete this._lights;
  4483. };
  4484. /** @hidden */
  4485. KHR_lights.prototype.onLoading = function () {
  4486. var extensions = this._loader.gltf.extensions;
  4487. if (extensions && extensions[this.name]) {
  4488. var extension = extensions[this.name];
  4489. this._lights = extension.lights;
  4490. }
  4491. };
  4492. /** @hidden */
  4493. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4494. var _this = this;
  4495. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4496. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4497. var babylonLight;
  4498. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4499. var name = light.name || babylonMesh.name;
  4500. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  4501. switch (light.type) {
  4502. case "directional" /* DIRECTIONAL */: {
  4503. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  4504. break;
  4505. }
  4506. case "point" /* POINT */: {
  4507. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  4508. break;
  4509. }
  4510. case "spot" /* SPOT */: {
  4511. var babylonSpotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  4512. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4513. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4514. babylonLight = babylonSpotLight;
  4515. break;
  4516. }
  4517. default: {
  4518. _this._loader.babylonScene._blockEntityCollection = false;
  4519. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4520. }
  4521. }
  4522. _this._loader.babylonScene._blockEntityCollection = false;
  4523. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4524. babylonLight.diffuse = light.color ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4525. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4526. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4527. babylonLight.parent = babylonMesh;
  4528. _this._loader._babylonLights.push(babylonLight);
  4529. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4530. assign(babylonMesh);
  4531. });
  4532. });
  4533. };
  4534. return KHR_lights;
  4535. }());
  4536. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4537. /***/ }),
  4538. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4539. /*!********************************************************!*\
  4540. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4541. \********************************************************/
  4542. /*! exports provided: KHR_materials_clearcoat */
  4543. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4544. "use strict";
  4545. __webpack_require__.r(__webpack_exports__);
  4546. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4547. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4548. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4549. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4550. var NAME = "KHR_materials_clearcoat";
  4551. /**
  4552. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md)
  4553. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4554. */
  4555. var KHR_materials_clearcoat = /** @class */ (function () {
  4556. /** @hidden */
  4557. function KHR_materials_clearcoat(loader) {
  4558. /**
  4559. * The name of this extension.
  4560. */
  4561. this.name = NAME;
  4562. /**
  4563. * Defines a number that determines the order the extensions are applied.
  4564. */
  4565. this.order = 190;
  4566. this._loader = loader;
  4567. this.enabled = this._loader.isExtensionUsed(NAME);
  4568. }
  4569. /** @hidden */
  4570. KHR_materials_clearcoat.prototype.dispose = function () {
  4571. this._loader = null;
  4572. };
  4573. /** @hidden */
  4574. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4575. var _this = this;
  4576. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4577. var promises = new Array();
  4578. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4579. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4580. return Promise.all(promises).then(function () { });
  4581. });
  4582. };
  4583. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4584. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4585. throw new Error(context + ": Material type not supported");
  4586. }
  4587. var promises = new Array();
  4588. babylonMaterial.clearCoat.isEnabled = true;
  4589. babylonMaterial.clearCoat.useRoughnessFromMainTexture = false;
  4590. babylonMaterial.clearCoat.remapF0OnInterfaceChange = false;
  4591. if (properties.clearcoatFactor != undefined) {
  4592. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4593. }
  4594. else {
  4595. babylonMaterial.clearCoat.intensity = 0;
  4596. }
  4597. if (properties.clearcoatTexture) {
  4598. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4599. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4600. babylonMaterial.clearCoat.texture = texture;
  4601. }));
  4602. }
  4603. if (properties.clearcoatRoughnessFactor != undefined) {
  4604. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4605. }
  4606. else {
  4607. babylonMaterial.clearCoat.roughness = 0;
  4608. }
  4609. if (properties.clearcoatRoughnessTexture) {
  4610. properties.clearcoatRoughnessTexture.nonColorData = true;
  4611. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4612. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4613. babylonMaterial.clearCoat.textureRoughness = texture;
  4614. }));
  4615. }
  4616. if (properties.clearcoatNormalTexture) {
  4617. properties.clearcoatNormalTexture.nonColorData = true;
  4618. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4619. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4620. babylonMaterial.clearCoat.bumpTexture = texture;
  4621. }));
  4622. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4623. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4624. if (properties.clearcoatNormalTexture.scale != undefined) {
  4625. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4626. }
  4627. }
  4628. return Promise.all(promises).then(function () { });
  4629. };
  4630. return KHR_materials_clearcoat;
  4631. }());
  4632. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4633. /***/ }),
  4634. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  4635. /*!**************************************************!*\
  4636. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  4637. \**************************************************/
  4638. /*! exports provided: KHR_materials_ior */
  4639. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4640. "use strict";
  4641. __webpack_require__.r(__webpack_exports__);
  4642. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  4643. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4644. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4645. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4646. var NAME = "KHR_materials_ior";
  4647. /**
  4648. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  4649. * !!! Experimental Extension Subject to Changes !!!
  4650. */
  4651. var KHR_materials_ior = /** @class */ (function () {
  4652. /** @hidden */
  4653. function KHR_materials_ior(loader) {
  4654. /**
  4655. * The name of this extension.
  4656. */
  4657. this.name = NAME;
  4658. /**
  4659. * Defines a number that determines the order the extensions are applied.
  4660. */
  4661. this.order = 180;
  4662. this._loader = loader;
  4663. this.enabled = this._loader.isExtensionUsed(NAME);
  4664. }
  4665. /** @hidden */
  4666. KHR_materials_ior.prototype.dispose = function () {
  4667. this._loader = null;
  4668. };
  4669. /** @hidden */
  4670. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4671. var _this = this;
  4672. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4673. var promises = new Array();
  4674. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4675. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  4676. return Promise.all(promises).then(function () { });
  4677. });
  4678. };
  4679. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  4680. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4681. throw new Error(context + ": Material type not supported");
  4682. }
  4683. if (properties.ior !== undefined) {
  4684. babylonMaterial.indexOfRefraction = properties.ior;
  4685. }
  4686. else {
  4687. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  4688. }
  4689. return Promise.resolve();
  4690. };
  4691. /**
  4692. * Default ior Value from the spec.
  4693. */
  4694. KHR_materials_ior._DEFAULT_IOR = 1.5;
  4695. return KHR_materials_ior;
  4696. }());
  4697. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  4698. /***/ }),
  4699. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4700. /*!********************************************************************!*\
  4701. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4702. \********************************************************************/
  4703. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4704. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4705. "use strict";
  4706. __webpack_require__.r(__webpack_exports__);
  4707. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4708. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4709. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4710. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4711. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4712. /**
  4713. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4714. */
  4715. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4716. /** @hidden */
  4717. function KHR_materials_pbrSpecularGlossiness(loader) {
  4718. /**
  4719. * The name of this extension.
  4720. */
  4721. this.name = NAME;
  4722. /**
  4723. * Defines a number that determines the order the extensions are applied.
  4724. */
  4725. this.order = 200;
  4726. this._loader = loader;
  4727. this.enabled = this._loader.isExtensionUsed(NAME);
  4728. }
  4729. /** @hidden */
  4730. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4731. this._loader = null;
  4732. };
  4733. /** @hidden */
  4734. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4735. var _this = this;
  4736. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4737. var promises = new Array();
  4738. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4739. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4740. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4741. return Promise.all(promises).then(function () { });
  4742. });
  4743. };
  4744. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4745. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4746. throw new Error(context + ": Material type not supported");
  4747. }
  4748. var promises = new Array();
  4749. babylonMaterial.metallic = null;
  4750. babylonMaterial.roughness = null;
  4751. if (properties.diffuseFactor) {
  4752. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4753. babylonMaterial.alpha = properties.diffuseFactor[3];
  4754. }
  4755. else {
  4756. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4757. }
  4758. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4759. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4760. if (properties.diffuseTexture) {
  4761. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4762. texture.name = babylonMaterial.name + " (Diffuse)";
  4763. babylonMaterial.albedoTexture = texture;
  4764. }));
  4765. }
  4766. if (properties.specularGlossinessTexture) {
  4767. properties.specularGlossinessTexture.nonColorData = true;
  4768. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4769. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4770. babylonMaterial.reflectivityTexture = texture;
  4771. }));
  4772. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4773. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4774. }
  4775. return Promise.all(promises).then(function () { });
  4776. };
  4777. return KHR_materials_pbrSpecularGlossiness;
  4778. }());
  4779. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4780. /***/ }),
  4781. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4782. /*!****************************************************!*\
  4783. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4784. \****************************************************/
  4785. /*! exports provided: KHR_materials_sheen */
  4786. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4787. "use strict";
  4788. __webpack_require__.r(__webpack_exports__);
  4789. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4790. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4791. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4792. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4793. var NAME = "KHR_materials_sheen";
  4794. /**
  4795. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_sheen/README.md)
  4796. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4797. * !!! Experimental Extension Subject to Changes !!!
  4798. */
  4799. var KHR_materials_sheen = /** @class */ (function () {
  4800. /** @hidden */
  4801. function KHR_materials_sheen(loader) {
  4802. /**
  4803. * The name of this extension.
  4804. */
  4805. this.name = NAME;
  4806. /**
  4807. * Defines a number that determines the order the extensions are applied.
  4808. */
  4809. this.order = 190;
  4810. this._loader = loader;
  4811. this.enabled = this._loader.isExtensionUsed(NAME);
  4812. }
  4813. /** @hidden */
  4814. KHR_materials_sheen.prototype.dispose = function () {
  4815. this._loader = null;
  4816. };
  4817. /** @hidden */
  4818. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4819. var _this = this;
  4820. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4821. var promises = new Array();
  4822. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4823. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4824. return Promise.all(promises).then(function () { });
  4825. });
  4826. };
  4827. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4828. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4829. throw new Error(context + ": Material type not supported");
  4830. }
  4831. var promises = new Array();
  4832. babylonMaterial.sheen.isEnabled = true;
  4833. babylonMaterial.sheen.intensity = 1;
  4834. if (properties.sheenColorFactor != undefined) {
  4835. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.sheenColorFactor);
  4836. }
  4837. else {
  4838. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  4839. }
  4840. if (properties.sheenColorTexture) {
  4841. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenColorTexture", properties.sheenColorTexture, function (texture) {
  4842. texture.name = babylonMaterial.name + " (Sheen Color)";
  4843. babylonMaterial.sheen.texture = texture;
  4844. }));
  4845. }
  4846. if (properties.sheenRoughnessFactor !== undefined) {
  4847. babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;
  4848. }
  4849. else {
  4850. babylonMaterial.sheen.roughness = 0;
  4851. }
  4852. if (properties.sheenRoughnessTexture) {
  4853. properties.sheenRoughnessTexture.nonColorData = true;
  4854. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenRoughnessTexture", properties.sheenRoughnessTexture, function (texture) {
  4855. texture.name = babylonMaterial.name + " (Sheen Roughness)";
  4856. babylonMaterial.sheen.textureRoughness = texture;
  4857. }));
  4858. }
  4859. babylonMaterial.sheen.albedoScaling = true;
  4860. babylonMaterial.sheen.useRoughnessFromMainTexture = false;
  4861. return Promise.all(promises).then(function () { });
  4862. };
  4863. return KHR_materials_sheen;
  4864. }());
  4865. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4866. /***/ }),
  4867. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4868. /*!*******************************************************!*\
  4869. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4870. \*******************************************************/
  4871. /*! exports provided: KHR_materials_specular */
  4872. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4873. "use strict";
  4874. __webpack_require__.r(__webpack_exports__);
  4875. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4876. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4877. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4878. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4879. var NAME = "KHR_materials_specular";
  4880. /**
  4881. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  4882. * !!! Experimental Extension Subject to Changes !!!
  4883. */
  4884. var KHR_materials_specular = /** @class */ (function () {
  4885. /** @hidden */
  4886. function KHR_materials_specular(loader) {
  4887. /**
  4888. * The name of this extension.
  4889. */
  4890. this.name = NAME;
  4891. /**
  4892. * Defines a number that determines the order the extensions are applied.
  4893. */
  4894. this.order = 190;
  4895. this._loader = loader;
  4896. this.enabled = this._loader.isExtensionUsed(NAME);
  4897. }
  4898. /** @hidden */
  4899. KHR_materials_specular.prototype.dispose = function () {
  4900. this._loader = null;
  4901. };
  4902. /** @hidden */
  4903. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4904. var _this = this;
  4905. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4906. var promises = new Array();
  4907. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4908. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4909. return Promise.all(promises).then(function () { });
  4910. });
  4911. };
  4912. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4913. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4914. throw new Error(context + ": Material type not supported");
  4915. }
  4916. var promises = new Array();
  4917. if (properties.specularFactor !== undefined) {
  4918. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4919. }
  4920. if (properties.specularColorFactor !== undefined) {
  4921. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  4922. }
  4923. if (properties.specularTexture) {
  4924. properties.specularTexture.nonColorData = true;
  4925. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  4926. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  4927. babylonMaterial.metallicReflectanceTexture = texture;
  4928. }));
  4929. }
  4930. return Promise.all(promises).then(function () { });
  4931. };
  4932. return KHR_materials_specular;
  4933. }());
  4934. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4935. /***/ }),
  4936. /***/ "./glTF/2.0/Extensions/KHR_materials_translucency.ts":
  4937. /*!***********************************************************!*\
  4938. !*** ./glTF/2.0/Extensions/KHR_materials_translucency.ts ***!
  4939. \***********************************************************/
  4940. /*! exports provided: KHR_materials_translucency */
  4941. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4942. "use strict";
  4943. __webpack_require__.r(__webpack_exports__);
  4944. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_translucency", function() { return KHR_materials_translucency; });
  4945. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4946. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4947. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4948. var NAME = "KHR_materials_translucency";
  4949. /**
  4950. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
  4951. * !!! Experimental Extension Subject to Changes !!!
  4952. */
  4953. var KHR_materials_translucency = /** @class */ (function () {
  4954. /** @hidden */
  4955. function KHR_materials_translucency(loader) {
  4956. /**
  4957. * The name of this extension.
  4958. */
  4959. this.name = NAME;
  4960. /**
  4961. * Defines a number that determines the order the extensions are applied.
  4962. */
  4963. this.order = 175;
  4964. this._loader = loader;
  4965. this.enabled = this._loader.isExtensionUsed(NAME);
  4966. if (this.enabled) {
  4967. loader.parent.transparencyAsCoverage = true;
  4968. }
  4969. }
  4970. /** @hidden */
  4971. KHR_materials_translucency.prototype.dispose = function () {
  4972. this._loader = null;
  4973. };
  4974. /** @hidden */
  4975. KHR_materials_translucency.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4976. var _this = this;
  4977. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4978. var promises = new Array();
  4979. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4980. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4981. promises.push(_this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
  4982. return Promise.all(promises).then(function () { });
  4983. });
  4984. };
  4985. KHR_materials_translucency.prototype._loadTranslucentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  4986. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4987. throw new Error(context + ": Material type not supported");
  4988. }
  4989. var pbrMaterial = babylonMaterial;
  4990. // Enables "translucency" texture which represents diffusely-transmitted light.
  4991. pbrMaterial.subSurface.isTranslucencyEnabled = true;
  4992. // Since this extension models thin-surface transmission only, we must make the
  4993. // internal IOR == 1.0 and set the thickness to 0.
  4994. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  4995. pbrMaterial.subSurface.minimumThickness = 0.0;
  4996. pbrMaterial.subSurface.maximumThickness = 0.0;
  4997. // Albedo colour will tint transmission.
  4998. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  4999. if (extension.translucencyFactor !== undefined) {
  5000. pbrMaterial.subSurface.translucencyIntensity = extension.translucencyFactor;
  5001. }
  5002. else {
  5003. pbrMaterial.subSurface.translucencyIntensity = 0.0;
  5004. pbrMaterial.subSurface.isTranslucencyEnabled = false;
  5005. return Promise.resolve();
  5006. }
  5007. if (extension.translucencyTexture) {
  5008. return this._loader.loadTextureInfoAsync(context + "/translucencyTexture", extension.translucencyTexture)
  5009. .then(function (texture) {
  5010. pbrMaterial.subSurface.thicknessTexture = texture;
  5011. pbrMaterial.subSurface.useMaskFromThicknessTextureGltf = true;
  5012. });
  5013. }
  5014. else {
  5015. return Promise.resolve();
  5016. }
  5017. };
  5018. return KHR_materials_translucency;
  5019. }());
  5020. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_translucency(loader); });
  5021. /***/ }),
  5022. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  5023. /*!***********************************************************!*\
  5024. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  5025. \***********************************************************/
  5026. /*! exports provided: KHR_materials_transmission */
  5027. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5028. "use strict";
  5029. __webpack_require__.r(__webpack_exports__);
  5030. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  5031. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  5032. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5033. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__);
  5034. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5035. /**
  5036. * A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.
  5037. */
  5038. var TransmissionHelper = /** @class */ (function () {
  5039. /**
  5040. * constructor
  5041. * @param options Defines the options we want to customize the helper
  5042. * @param scene The scene to add the material to
  5043. */
  5044. function TransmissionHelper(options, scene) {
  5045. var _this = this;
  5046. this._opaqueRenderTarget = null;
  5047. this._opaqueMeshesCache = [];
  5048. this._transparentMeshesCache = [];
  5049. this._options = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])(Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, TransmissionHelper._getDefaultOptions()), options);
  5050. this._scene = scene;
  5051. this._scene._transmissionHelper = this;
  5052. this.onErrorObservable = new babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Observable"]();
  5053. this._scene.onDisposeObservable.addOnce(function (scene) {
  5054. _this.dispose();
  5055. });
  5056. this._parseScene();
  5057. this._setupRenderTargets();
  5058. }
  5059. /**
  5060. * Creates the default options for the helper.
  5061. */
  5062. TransmissionHelper._getDefaultOptions = function () {
  5063. return {
  5064. renderSize: 1024
  5065. };
  5066. };
  5067. /**
  5068. * Updates the background according to the new options
  5069. * @param options
  5070. */
  5071. TransmissionHelper.prototype.updateOptions = function (options) {
  5072. var _this = this;
  5073. // First check if any options are actually being changed. If not, exit.
  5074. var newValues = Object.keys(options).filter(function (key) { return _this._options[key] !== options[key]; });
  5075. if (!newValues.length) {
  5076. return;
  5077. }
  5078. var newOptions = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])(Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, this._options), options);
  5079. var oldOptions = this._options;
  5080. this._options = newOptions;
  5081. // If size changes, recreate everything
  5082. if (newOptions.renderSize !== oldOptions.renderSize) {
  5083. this._setupRenderTargets();
  5084. }
  5085. };
  5086. TransmissionHelper.prototype.getOpaqueTarget = function () {
  5087. return this._opaqueRenderTarget;
  5088. };
  5089. TransmissionHelper.prototype.shouldRenderAsTransmission = function (material) {
  5090. if (!material) {
  5091. return false;
  5092. }
  5093. if (material instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"] && (material.subSurface.isRefractionEnabled)) {
  5094. return true;
  5095. }
  5096. return false;
  5097. };
  5098. TransmissionHelper.prototype._addMesh = function (mesh) {
  5099. if (mesh instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5100. mesh.onMaterialChangedObservable.add(this.onMeshMaterialChanged.bind(this));
  5101. if (this.shouldRenderAsTransmission(mesh.material)) {
  5102. this._transparentMeshesCache.push(mesh);
  5103. }
  5104. else {
  5105. this._opaqueMeshesCache.push(mesh);
  5106. }
  5107. }
  5108. };
  5109. TransmissionHelper.prototype._removeMesh = function (mesh) {
  5110. if (mesh instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5111. mesh.onMaterialChangedObservable.remove(this.onMeshMaterialChanged.bind(this));
  5112. var idx = this._transparentMeshesCache.indexOf(mesh);
  5113. if (idx !== -1) {
  5114. this._transparentMeshesCache.splice(idx, 1);
  5115. }
  5116. idx = this._opaqueMeshesCache.indexOf(mesh);
  5117. if (idx !== -1) {
  5118. this._opaqueMeshesCache.splice(idx, 1);
  5119. }
  5120. }
  5121. };
  5122. TransmissionHelper.prototype._parseScene = function () {
  5123. this._scene.meshes.forEach(this._addMesh.bind(this));
  5124. // Listen for when a mesh is added to the scene and add it to our cache lists.
  5125. this._scene.onNewMeshAddedObservable.add(this._addMesh.bind(this));
  5126. // Listen for when a mesh is removed from to the scene and remove it from our cache lists.
  5127. this._scene.onMeshRemovedObservable.add(this._removeMesh.bind(this));
  5128. };
  5129. // When one of the meshes in the scene has its material changed, make sure that it's in the correct cache list.
  5130. TransmissionHelper.prototype.onMeshMaterialChanged = function (mesh) {
  5131. if (mesh instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5132. var transparentIdx = this._transparentMeshesCache.indexOf(mesh);
  5133. var opaqueIdx = this._opaqueMeshesCache.indexOf(mesh);
  5134. // If the material is transparent, make sure that it's added to the transparent list and removed from the opaque list
  5135. var useTransmission = this.shouldRenderAsTransmission(mesh.material);
  5136. if (useTransmission) {
  5137. if (mesh.material instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  5138. mesh.material.subSurface.refractionTexture = this._opaqueRenderTarget;
  5139. }
  5140. if (opaqueIdx !== -1) {
  5141. this._opaqueMeshesCache.splice(opaqueIdx, 1);
  5142. this._transparentMeshesCache.push(mesh);
  5143. }
  5144. else if (transparentIdx === -1) {
  5145. this._transparentMeshesCache.push(mesh);
  5146. }
  5147. // If the material is opaque, make sure that it's added to the opaque list and removed from the transparent list
  5148. }
  5149. else {
  5150. if (transparentIdx !== -1) {
  5151. this._transparentMeshesCache.splice(transparentIdx, 1);
  5152. this._opaqueMeshesCache.push(mesh);
  5153. }
  5154. else if (opaqueIdx === -1) {
  5155. this._opaqueMeshesCache.push(mesh);
  5156. }
  5157. }
  5158. }
  5159. };
  5160. /**
  5161. * Setup the render targets according to the specified options.
  5162. */
  5163. TransmissionHelper.prototype._setupRenderTargets = function () {
  5164. var _this = this;
  5165. var opaqueRTIndex = -1;
  5166. // Remove any layers rendering to the opaque scene.
  5167. if (this._scene.layers && this._opaqueRenderTarget) {
  5168. for (var _i = 0, _a = this._scene.layers; _i < _a.length; _i++) {
  5169. var layer = _a[_i];
  5170. var idx = layer.renderTargetTextures.indexOf(this._opaqueRenderTarget);
  5171. if (idx >= 0) {
  5172. layer.renderTargetTextures.splice(idx, 1);
  5173. }
  5174. }
  5175. }
  5176. // Remove opaque render target
  5177. if (this._opaqueRenderTarget) {
  5178. opaqueRTIndex = this._scene.customRenderTargets.indexOf(this._opaqueRenderTarget);
  5179. this._opaqueRenderTarget.dispose();
  5180. }
  5181. this._opaqueRenderTarget = new babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["RenderTargetTexture"]("opaqueSceneTexture", this._options.renderSize, this._scene, true);
  5182. this._opaqueRenderTarget.renderList = this._opaqueMeshesCache;
  5183. // this._opaqueRenderTarget.clearColor = new Color4(0.0, 0.0, 0.0, 0.0);
  5184. this._opaqueRenderTarget.gammaSpace = true;
  5185. this._opaqueRenderTarget.lodGenerationScale = 1;
  5186. this._opaqueRenderTarget.lodGenerationOffset = -4;
  5187. this._opaqueRenderTarget.samples = 4;
  5188. if (opaqueRTIndex >= 0) {
  5189. this._scene.customRenderTargets.splice(opaqueRTIndex, 0, this._opaqueRenderTarget);
  5190. }
  5191. else {
  5192. opaqueRTIndex = this._scene.customRenderTargets.length;
  5193. this._scene.customRenderTargets.push(this._opaqueRenderTarget);
  5194. }
  5195. // If there are other layers, they should be included in the render of the opaque background.
  5196. if (this._scene.layers && this._opaqueRenderTarget) {
  5197. for (var _b = 0, _c = this._scene.layers; _b < _c.length; _b++) {
  5198. var layer = _c[_b];
  5199. layer.renderTargetTextures.push(this._opaqueRenderTarget);
  5200. }
  5201. }
  5202. this._transparentMeshesCache.forEach(function (mesh) {
  5203. if (_this.shouldRenderAsTransmission(mesh.material) && mesh.material instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  5204. mesh.material.refractionTexture = _this._opaqueRenderTarget;
  5205. }
  5206. });
  5207. };
  5208. /**
  5209. * Dispose all the elements created by the Helper.
  5210. */
  5211. TransmissionHelper.prototype.dispose = function () {
  5212. this._scene._transmissionHelper = undefined;
  5213. if (this._opaqueRenderTarget) {
  5214. this._opaqueRenderTarget.dispose();
  5215. this._opaqueRenderTarget = null;
  5216. }
  5217. this._transparentMeshesCache = [];
  5218. this._opaqueMeshesCache = [];
  5219. };
  5220. return TransmissionHelper;
  5221. }());
  5222. var NAME = "KHR_materials_transmission";
  5223. /**
  5224. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
  5225. */
  5226. var KHR_materials_transmission = /** @class */ (function () {
  5227. /** @hidden */
  5228. function KHR_materials_transmission(loader) {
  5229. /**
  5230. * The name of this extension.
  5231. */
  5232. this.name = NAME;
  5233. /**
  5234. * Defines a number that determines the order the extensions are applied.
  5235. */
  5236. this.order = 175;
  5237. this._loader = loader;
  5238. this.enabled = this._loader.isExtensionUsed(NAME);
  5239. if (this.enabled) {
  5240. loader.parent.transparencyAsCoverage = true;
  5241. }
  5242. }
  5243. /** @hidden */
  5244. KHR_materials_transmission.prototype.dispose = function () {
  5245. this._loader = null;
  5246. };
  5247. /** @hidden */
  5248. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5249. var _this = this;
  5250. return _glTFLoader__WEBPACK_IMPORTED_MODULE_2__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5251. var promises = new Array();
  5252. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  5253. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  5254. promises.push(_this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
  5255. return Promise.all(promises).then(function () { });
  5256. });
  5257. };
  5258. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  5259. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"])) {
  5260. throw new Error(context + ": Material type not supported");
  5261. }
  5262. var pbrMaterial = babylonMaterial;
  5263. // Enables "refraction" texture which represents transmitted light.
  5264. pbrMaterial.subSurface.isRefractionEnabled = true;
  5265. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  5266. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  5267. // Albedo colour will tint transmission.
  5268. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  5269. if (extension.transmissionFactor !== undefined) {
  5270. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  5271. var scene = pbrMaterial.getScene();
  5272. if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {
  5273. new TransmissionHelper({}, pbrMaterial.getScene());
  5274. }
  5275. }
  5276. else {
  5277. pbrMaterial.subSurface.refractionIntensity = 0.0;
  5278. pbrMaterial.subSurface.isRefractionEnabled = false;
  5279. return Promise.resolve();
  5280. }
  5281. if (extension.transmissionTexture) {
  5282. extension.transmissionTexture.nonColorData = true;
  5283. return this._loader.loadTextureInfoAsync(context + "/transmissionTexture", extension.transmissionTexture, undefined)
  5284. .then(function (texture) {
  5285. pbrMaterial.subSurface.thicknessTexture = texture;
  5286. pbrMaterial.subSurface.useMaskFromThicknessTextureGltf = true;
  5287. });
  5288. }
  5289. else {
  5290. return Promise.resolve();
  5291. }
  5292. };
  5293. return KHR_materials_transmission;
  5294. }());
  5295. _glTFLoader__WEBPACK_IMPORTED_MODULE_2__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  5296. /***/ }),
  5297. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  5298. /*!****************************************************!*\
  5299. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  5300. \****************************************************/
  5301. /*! exports provided: KHR_materials_unlit */
  5302. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5303. "use strict";
  5304. __webpack_require__.r(__webpack_exports__);
  5305. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  5306. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  5307. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  5308. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5309. var NAME = "KHR_materials_unlit";
  5310. /**
  5311. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  5312. */
  5313. var KHR_materials_unlit = /** @class */ (function () {
  5314. /** @hidden */
  5315. function KHR_materials_unlit(loader) {
  5316. /**
  5317. * The name of this extension.
  5318. */
  5319. this.name = NAME;
  5320. /**
  5321. * Defines a number that determines the order the extensions are applied.
  5322. */
  5323. this.order = 210;
  5324. this._loader = loader;
  5325. this.enabled = this._loader.isExtensionUsed(NAME);
  5326. }
  5327. /** @hidden */
  5328. KHR_materials_unlit.prototype.dispose = function () {
  5329. this._loader = null;
  5330. };
  5331. /** @hidden */
  5332. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5333. var _this = this;
  5334. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  5335. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  5336. });
  5337. };
  5338. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  5339. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5340. throw new Error(context + ": Material type not supported");
  5341. }
  5342. var promises = new Array();
  5343. babylonMaterial.unlit = true;
  5344. var properties = material.pbrMetallicRoughness;
  5345. if (properties) {
  5346. if (properties.baseColorFactor) {
  5347. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  5348. babylonMaterial.alpha = properties.baseColorFactor[3];
  5349. }
  5350. else {
  5351. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  5352. }
  5353. if (properties.baseColorTexture) {
  5354. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  5355. texture.name = babylonMaterial.name + " (Base Color)";
  5356. babylonMaterial.albedoTexture = texture;
  5357. }));
  5358. }
  5359. }
  5360. if (material.doubleSided) {
  5361. babylonMaterial.backFaceCulling = false;
  5362. babylonMaterial.twoSidedLighting = true;
  5363. }
  5364. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  5365. return Promise.all(promises).then(function () { });
  5366. };
  5367. return KHR_materials_unlit;
  5368. }());
  5369. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  5370. /***/ }),
  5371. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  5372. /*!*******************************************************!*\
  5373. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  5374. \*******************************************************/
  5375. /*! exports provided: KHR_materials_variants */
  5376. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5377. "use strict";
  5378. __webpack_require__.r(__webpack_exports__);
  5379. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  5380. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5381. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/tools");
  5382. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  5383. var NAME = "KHR_materials_variants";
  5384. /**
  5385. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)
  5386. */
  5387. var KHR_materials_variants = /** @class */ (function () {
  5388. /** @hidden */
  5389. function KHR_materials_variants(loader) {
  5390. /**
  5391. * The name of this extension.
  5392. */
  5393. this.name = NAME;
  5394. this._loader = loader;
  5395. this.enabled = this._loader.isExtensionUsed(NAME);
  5396. }
  5397. /** @hidden */
  5398. KHR_materials_variants.prototype.dispose = function () {
  5399. this._loader = null;
  5400. };
  5401. /**
  5402. * Gets the list of available variant names for this asset.
  5403. * @param rootMesh The glTF root mesh
  5404. * @returns the list of all the variant names for this model
  5405. */
  5406. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  5407. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5408. if (!extensionMetadata) {
  5409. return [];
  5410. }
  5411. return Object.keys(extensionMetadata.variants);
  5412. };
  5413. /**
  5414. * Gets the list of available variant names for this asset.
  5415. * @param rootMesh The glTF root mesh
  5416. * @returns the list of all the variant names for this model
  5417. */
  5418. KHR_materials_variants.prototype.getAvailableVariants = function (rootMesh) {
  5419. return KHR_materials_variants.GetAvailableVariants(rootMesh);
  5420. };
  5421. /**
  5422. * Select a variant given a variant name or a list of variant names.
  5423. * @param rootMesh The glTF root mesh
  5424. * @param variantName The variant name(s) to select.
  5425. */
  5426. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  5427. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5428. if (!extensionMetadata) {
  5429. throw new Error("Cannot select variant on a glTF mesh that does not have the " + NAME + " extension");
  5430. }
  5431. var select = function (variantName) {
  5432. var entries = extensionMetadata.variants[variantName];
  5433. if (entries) {
  5434. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  5435. var entry = entries_1[_i];
  5436. entry.mesh.material = entry.material;
  5437. }
  5438. }
  5439. };
  5440. if (variantName instanceof Array) {
  5441. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  5442. var name_1 = variantName_1[_i];
  5443. select(name_1);
  5444. }
  5445. }
  5446. else {
  5447. select(variantName);
  5448. }
  5449. extensionMetadata.lastSelected = variantName;
  5450. };
  5451. /**
  5452. * Select a variant given a variant name or a list of variant names.
  5453. * @param rootMesh The glTF root mesh
  5454. * @param variantName The variant name(s) to select.
  5455. */
  5456. KHR_materials_variants.prototype.selectVariant = function (rootMesh, variantName) {
  5457. return KHR_materials_variants.SelectVariant(rootMesh, variantName);
  5458. };
  5459. /**
  5460. * Reset back to the original before selecting a variant.
  5461. * @param rootMesh The glTF root mesh
  5462. */
  5463. KHR_materials_variants.Reset = function (rootMesh) {
  5464. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5465. if (!extensionMetadata) {
  5466. throw new Error("Cannot reset on a glTF mesh that does not have the " + NAME + " extension");
  5467. }
  5468. for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
  5469. var entry = _a[_i];
  5470. entry.mesh.material = entry.material;
  5471. }
  5472. extensionMetadata.lastSelected = null;
  5473. };
  5474. /**
  5475. * Reset back to the original before selecting a variant.
  5476. * @param rootMesh The glTF root mesh
  5477. */
  5478. KHR_materials_variants.prototype.reset = function (rootMesh) {
  5479. return KHR_materials_variants.Reset(rootMesh);
  5480. };
  5481. /**
  5482. * Gets the last selected variant name(s) or null if original.
  5483. * @param rootMesh The glTF root mesh
  5484. * @returns The selected variant name(s).
  5485. */
  5486. KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
  5487. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5488. if (!extensionMetadata) {
  5489. throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the " + NAME + " extension");
  5490. }
  5491. return extensionMetadata.lastSelected;
  5492. };
  5493. /**
  5494. * Gets the last selected variant name(s) or null if original.
  5495. * @param rootMesh The glTF root mesh
  5496. * @returns The selected variant name(s).
  5497. */
  5498. KHR_materials_variants.prototype.getLastSelectedVariant = function (rootMesh) {
  5499. return KHR_materials_variants.GetLastSelectedVariant(rootMesh);
  5500. };
  5501. KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
  5502. var _a, _b;
  5503. return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
  5504. };
  5505. /** @hidden */
  5506. KHR_materials_variants.prototype.onLoading = function () {
  5507. var extensions = this._loader.gltf.extensions;
  5508. if (extensions && extensions[this.name]) {
  5509. var extension = extensions[this.name];
  5510. this._variants = extension.variants;
  5511. }
  5512. };
  5513. /** @hidden */
  5514. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  5515. var _this = this;
  5516. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  5517. var promises = new Array();
  5518. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  5519. assign(babylonMesh);
  5520. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5521. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  5522. var root = _this._loader.rootBabylonMesh;
  5523. var metadata = (root.metadata = root.metadata || {});
  5524. var gltf = (metadata.gltf = metadata.gltf || {});
  5525. var extensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
  5526. // Store the original material.
  5527. extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });
  5528. // For each mapping, look at the variants and make a new entry for them.
  5529. var variants_1 = extensionMetadata.variants;
  5530. for (var _i = 0, _a = extension.mappings; _i < _a.length; _i++) {
  5531. var mapping = _a[_i];
  5532. var _loop_1 = function (variantIndex) {
  5533. var variant = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/mapping/" + variantIndex, _this._variants, variantIndex);
  5534. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  5535. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5536. variants_1[variant.name] = variants_1[variant.name] || [];
  5537. variants_1[variant.name].push({
  5538. mesh: babylonMesh,
  5539. material: babylonMaterial
  5540. });
  5541. }));
  5542. };
  5543. for (var _b = 0, _c = mapping.variants; _b < _c.length; _b++) {
  5544. var variantIndex = _c[_b];
  5545. _loop_1(variantIndex);
  5546. }
  5547. }
  5548. }
  5549. }));
  5550. return Promise.all(promises).then(function (_a) {
  5551. var babylonMesh = _a[0];
  5552. return babylonMesh;
  5553. });
  5554. });
  5555. };
  5556. return KHR_materials_variants;
  5557. }());
  5558. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  5559. /***/ }),
  5560. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  5561. /*!******************************************************!*\
  5562. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  5563. \******************************************************/
  5564. /*! exports provided: KHR_mesh_quantization */
  5565. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5566. "use strict";
  5567. __webpack_require__.r(__webpack_exports__);
  5568. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  5569. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5570. var NAME = "KHR_mesh_quantization";
  5571. /**
  5572. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  5573. */
  5574. var KHR_mesh_quantization = /** @class */ (function () {
  5575. /** @hidden */
  5576. function KHR_mesh_quantization(loader) {
  5577. /**
  5578. * The name of this extension.
  5579. */
  5580. this.name = NAME;
  5581. this.enabled = loader.isExtensionUsed(NAME);
  5582. }
  5583. /** @hidden */
  5584. KHR_mesh_quantization.prototype.dispose = function () {
  5585. };
  5586. return KHR_mesh_quantization;
  5587. }());
  5588. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  5589. /***/ }),
  5590. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  5591. /*!***************************************************!*\
  5592. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  5593. \***************************************************/
  5594. /*! exports provided: KHR_texture_basisu */
  5595. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5596. "use strict";
  5597. __webpack_require__.r(__webpack_exports__);
  5598. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  5599. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5600. var NAME = "KHR_texture_basisu";
  5601. /**
  5602. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  5603. * !!! Experimental Extension Subject to Changes !!!
  5604. */
  5605. var KHR_texture_basisu = /** @class */ (function () {
  5606. /** @hidden */
  5607. function KHR_texture_basisu(loader) {
  5608. /** The name of this extension. */
  5609. this.name = NAME;
  5610. this._loader = loader;
  5611. this.enabled = loader.isExtensionUsed(NAME);
  5612. }
  5613. /** @hidden */
  5614. KHR_texture_basisu.prototype.dispose = function () {
  5615. this._loader = null;
  5616. };
  5617. /** @hidden */
  5618. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  5619. var _this = this;
  5620. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  5621. var sampler = (texture.sampler == undefined ? _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].DefaultSampler : _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(context + "/sampler", _this._loader.gltf.samplers, texture.sampler));
  5622. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  5623. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  5624. assign(babylonTexture);
  5625. }, texture._textureInfo.nonColorData ? { useRGBAIfASTCBC7NotAvailableWhenUASTC: true } : undefined);
  5626. });
  5627. };
  5628. return KHR_texture_basisu;
  5629. }());
  5630. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  5631. /***/ }),
  5632. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  5633. /*!******************************************************!*\
  5634. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  5635. \******************************************************/
  5636. /*! exports provided: KHR_texture_transform */
  5637. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5638. "use strict";
  5639. __webpack_require__.r(__webpack_exports__);
  5640. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  5641. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  5642. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  5643. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5644. var NAME = "KHR_texture_transform";
  5645. /**
  5646. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  5647. */
  5648. var KHR_texture_transform = /** @class */ (function () {
  5649. /** @hidden */
  5650. function KHR_texture_transform(loader) {
  5651. /**
  5652. * The name of this extension.
  5653. */
  5654. this.name = NAME;
  5655. this._loader = loader;
  5656. this.enabled = this._loader.isExtensionUsed(NAME);
  5657. }
  5658. /** @hidden */
  5659. KHR_texture_transform.prototype.dispose = function () {
  5660. this._loader = null;
  5661. };
  5662. /** @hidden */
  5663. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  5664. var _this = this;
  5665. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  5666. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  5667. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  5668. throw new Error(extensionContext + ": Texture type not supported");
  5669. }
  5670. if (extension.offset) {
  5671. babylonTexture.uOffset = extension.offset[0];
  5672. babylonTexture.vOffset = extension.offset[1];
  5673. }
  5674. // Always rotate around the origin.
  5675. babylonTexture.uRotationCenter = 0;
  5676. babylonTexture.vRotationCenter = 0;
  5677. if (extension.rotation) {
  5678. babylonTexture.wAng = -extension.rotation;
  5679. }
  5680. if (extension.scale) {
  5681. babylonTexture.uScale = extension.scale[0];
  5682. babylonTexture.vScale = extension.scale[1];
  5683. }
  5684. if (extension.texCoord != undefined) {
  5685. babylonTexture.coordinatesIndex = extension.texCoord;
  5686. }
  5687. assign(babylonTexture);
  5688. });
  5689. });
  5690. };
  5691. return KHR_texture_transform;
  5692. }());
  5693. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  5694. /***/ }),
  5695. /***/ "./glTF/2.0/Extensions/KHR_xmp_json_ld.ts":
  5696. /*!************************************************!*\
  5697. !*** ./glTF/2.0/Extensions/KHR_xmp_json_ld.ts ***!
  5698. \************************************************/
  5699. /*! exports provided: KHR_xmp_json_ld */
  5700. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5701. "use strict";
  5702. __webpack_require__.r(__webpack_exports__);
  5703. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp_json_ld", function() { return KHR_xmp_json_ld; });
  5704. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5705. var NAME = "KHR_xmp_json_ld";
  5706. /**
  5707. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1893)
  5708. * !!! Experimental Extension Subject to Changes !!!
  5709. */
  5710. var KHR_xmp_json_ld = /** @class */ (function () {
  5711. /** @hidden */
  5712. function KHR_xmp_json_ld(loader) {
  5713. /**
  5714. * The name of this extension.
  5715. */
  5716. this.name = NAME;
  5717. /**
  5718. * Defines a number that determines the order the extensions are applied.
  5719. */
  5720. this.order = 100;
  5721. this._loader = loader;
  5722. this.enabled = this._loader.isExtensionUsed(NAME);
  5723. }
  5724. /** @hidden */
  5725. KHR_xmp_json_ld.prototype.dispose = function () {
  5726. this._loader = null;
  5727. };
  5728. /**
  5729. * Called after the loader state changes to LOADING.
  5730. */
  5731. KHR_xmp_json_ld.prototype.onLoading = function () {
  5732. var _a, _b, _c;
  5733. var xmp_gltf = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_xmp_json_ld;
  5734. var xmp_node = (_c = (_b = this._loader.gltf.asset) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.KHR_xmp_json_ld;
  5735. if (xmp_gltf && xmp_node) {
  5736. var packet = +xmp_node.packet;
  5737. if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {
  5738. this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};
  5739. this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];
  5740. }
  5741. }
  5742. };
  5743. return KHR_xmp_json_ld;
  5744. }());
  5745. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_xmp_json_ld(loader); });
  5746. /***/ }),
  5747. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  5748. /*!***************************************************!*\
  5749. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  5750. \***************************************************/
  5751. /*! exports provided: MSFT_audio_emitter */
  5752. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5753. "use strict";
  5754. __webpack_require__.r(__webpack_exports__);
  5755. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  5756. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  5757. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  5758. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5759. var NAME = "MSFT_audio_emitter";
  5760. /**
  5761. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  5762. */
  5763. var MSFT_audio_emitter = /** @class */ (function () {
  5764. /** @hidden */
  5765. function MSFT_audio_emitter(loader) {
  5766. /**
  5767. * The name of this extension.
  5768. */
  5769. this.name = NAME;
  5770. this._loader = loader;
  5771. this.enabled = this._loader.isExtensionUsed(NAME);
  5772. }
  5773. /** @hidden */
  5774. MSFT_audio_emitter.prototype.dispose = function () {
  5775. this._loader = null;
  5776. this._clips = null;
  5777. this._emitters = null;
  5778. };
  5779. /** @hidden */
  5780. MSFT_audio_emitter.prototype.onLoading = function () {
  5781. var extensions = this._loader.gltf.extensions;
  5782. if (extensions && extensions[this.name]) {
  5783. var extension = extensions[this.name];
  5784. this._clips = extension.clips;
  5785. this._emitters = extension.emitters;
  5786. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  5787. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  5788. }
  5789. };
  5790. /** @hidden */
  5791. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  5792. var _this = this;
  5793. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  5794. var promises = new Array();
  5795. promises.push(_this._loader.loadSceneAsync(context, scene));
  5796. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5797. var emitterIndex = _a[_i];
  5798. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5799. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  5800. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5801. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  5802. }
  5803. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  5804. }
  5805. return Promise.all(promises).then(function () { });
  5806. });
  5807. };
  5808. /** @hidden */
  5809. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  5810. var _this = this;
  5811. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5812. var promises = new Array();
  5813. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  5814. var _loop_1 = function (emitterIndex) {
  5815. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5816. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  5817. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  5818. var sound = _a[_i];
  5819. sound.attachToMesh(babylonMesh);
  5820. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5821. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  5822. sound.setDirectionalCone(2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  5823. }
  5824. }
  5825. }));
  5826. };
  5827. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5828. var emitterIndex = _a[_i];
  5829. _loop_1(emitterIndex);
  5830. }
  5831. assign(babylonMesh);
  5832. }).then(function (babylonMesh) {
  5833. return Promise.all(promises).then(function () {
  5834. return babylonMesh;
  5835. });
  5836. });
  5837. });
  5838. };
  5839. /** @hidden */
  5840. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  5841. var _this = this;
  5842. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  5843. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  5844. var promises = new Array();
  5845. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  5846. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  5847. var event_1 = _a[_i];
  5848. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  5849. }
  5850. return Promise.all(promises).then(function () {
  5851. return babylonAnimationGroup;
  5852. });
  5853. });
  5854. });
  5855. };
  5856. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  5857. if (clip._objectURL) {
  5858. return clip._objectURL;
  5859. }
  5860. var promise;
  5861. if (clip.uri) {
  5862. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  5863. }
  5864. else {
  5865. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  5866. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  5867. }
  5868. clip._objectURL = promise.then(function (data) {
  5869. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  5870. });
  5871. return clip._objectURL;
  5872. };
  5873. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  5874. var _this = this;
  5875. emitter._babylonSounds = emitter._babylonSounds || [];
  5876. if (!emitter._babylonData) {
  5877. var clipPromises = new Array();
  5878. var name_1 = emitter.name || "emitter" + emitter.index;
  5879. var options_1 = {
  5880. loop: false,
  5881. autoplay: false,
  5882. volume: emitter.volume == undefined ? 1 : emitter.volume,
  5883. };
  5884. var _loop_2 = function (i) {
  5885. var clipContext = "/extensions/" + this_1.name + "/clips";
  5886. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  5887. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  5888. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  5889. sound.refDistance = emitter.refDistance || 1;
  5890. sound.maxDistance = emitter.maxDistance || 256;
  5891. sound.rolloffFactor = emitter.rolloffFactor || 1;
  5892. sound.distanceModel = emitter.distanceModel || 'exponential';
  5893. sound._positionInEmitterSpace = true;
  5894. }));
  5895. };
  5896. var this_1 = this;
  5897. for (var i = 0; i < emitter.clips.length; i++) {
  5898. _loop_2(i);
  5899. }
  5900. var promise = Promise.all(clipPromises).then(function () {
  5901. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  5902. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  5903. if (emitter.innerAngle) {
  5904. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  5905. }
  5906. if (emitter.outerAngle) {
  5907. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  5908. }
  5909. if (emitter.volume) {
  5910. weightedSound.volume = emitter.volume;
  5911. }
  5912. emitter._babylonData.sound = weightedSound;
  5913. });
  5914. emitter._babylonData = {
  5915. loaded: promise
  5916. };
  5917. }
  5918. return emitter._babylonData.loaded;
  5919. };
  5920. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  5921. switch (action) {
  5922. case "play" /* play */: {
  5923. return function (currentFrame) {
  5924. var frameOffset = (startOffset || 0) + (currentFrame - time);
  5925. sound.play(frameOffset);
  5926. };
  5927. }
  5928. case "stop" /* stop */: {
  5929. return function (currentFrame) {
  5930. sound.stop();
  5931. };
  5932. }
  5933. case "pause" /* pause */: {
  5934. return function (currentFrame) {
  5935. sound.pause();
  5936. };
  5937. }
  5938. default: {
  5939. throw new Error(context + ": Unsupported action " + action);
  5940. }
  5941. }
  5942. };
  5943. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  5944. var _this = this;
  5945. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  5946. return Promise.resolve();
  5947. }
  5948. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  5949. var emitterIndex = event.emitter;
  5950. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  5951. return this._loadEmitterAsync(context, emitter).then(function () {
  5952. var sound = emitter._babylonData.sound;
  5953. if (sound) {
  5954. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  5955. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  5956. // Make sure all started audio stops when this animation is terminated.
  5957. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  5958. sound.stop();
  5959. });
  5960. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  5961. sound.pause();
  5962. });
  5963. }
  5964. });
  5965. };
  5966. return MSFT_audio_emitter;
  5967. }());
  5968. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  5969. /***/ }),
  5970. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  5971. /*!*****************************************!*\
  5972. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  5973. \*****************************************/
  5974. /*! exports provided: MSFT_lod */
  5975. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5976. "use strict";
  5977. __webpack_require__.r(__webpack_exports__);
  5978. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  5979. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  5980. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  5981. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5982. var NAME = "MSFT_lod";
  5983. /**
  5984. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  5985. */
  5986. var MSFT_lod = /** @class */ (function () {
  5987. /** @hidden */
  5988. function MSFT_lod(loader) {
  5989. /**
  5990. * The name of this extension.
  5991. */
  5992. this.name = NAME;
  5993. /**
  5994. * Defines a number that determines the order the extensions are applied.
  5995. */
  5996. this.order = 100;
  5997. /**
  5998. * Maximum number of LODs to load, starting from the lowest LOD.
  5999. */
  6000. this.maxLODsToLoad = 10;
  6001. /**
  6002. * Observable raised when all node LODs of one level are loaded.
  6003. * The event data is the index of the loaded LOD starting from zero.
  6004. * Dispose the loader to cancel the loading of the next level of LODs.
  6005. */
  6006. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6007. /**
  6008. * Observable raised when all material LODs of one level are loaded.
  6009. * The event data is the index of the loaded LOD starting from zero.
  6010. * Dispose the loader to cancel the loading of the next level of LODs.
  6011. */
  6012. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  6013. this._bufferLODs = new Array();
  6014. this._nodeIndexLOD = null;
  6015. this._nodeSignalLODs = new Array();
  6016. this._nodePromiseLODs = new Array();
  6017. this._nodeBufferLODs = new Array();
  6018. this._materialIndexLOD = null;
  6019. this._materialSignalLODs = new Array();
  6020. this._materialPromiseLODs = new Array();
  6021. this._materialBufferLODs = new Array();
  6022. this._loader = loader;
  6023. this.enabled = this._loader.isExtensionUsed(NAME);
  6024. }
  6025. /** @hidden */
  6026. MSFT_lod.prototype.dispose = function () {
  6027. this._loader = null;
  6028. this._nodeIndexLOD = null;
  6029. this._nodeSignalLODs.length = 0;
  6030. this._nodePromiseLODs.length = 0;
  6031. this._nodeBufferLODs.length = 0;
  6032. this._materialIndexLOD = null;
  6033. this._materialSignalLODs.length = 0;
  6034. this._materialPromiseLODs.length = 0;
  6035. this._materialBufferLODs.length = 0;
  6036. this.onMaterialLODsLoadedObservable.clear();
  6037. this.onNodeLODsLoadedObservable.clear();
  6038. };
  6039. /** @hidden */
  6040. MSFT_lod.prototype.onReady = function () {
  6041. var _this = this;
  6042. var _loop_1 = function (indexLOD) {
  6043. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  6044. if (indexLOD !== 0) {
  6045. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  6046. _this._loader.log("Loaded node LOD " + indexLOD);
  6047. }
  6048. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  6049. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  6050. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  6051. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  6052. if (_this._nodeSignalLODs[indexLOD]) {
  6053. _this._nodeSignalLODs[indexLOD].resolve();
  6054. }
  6055. }
  6056. });
  6057. this_1._loader._completePromises.push(promise);
  6058. };
  6059. var this_1 = this;
  6060. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  6061. _loop_1(indexLOD);
  6062. }
  6063. var _loop_2 = function (indexLOD) {
  6064. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  6065. if (indexLOD !== 0) {
  6066. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  6067. _this._loader.log("Loaded material LOD " + indexLOD);
  6068. }
  6069. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  6070. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  6071. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  6072. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  6073. if (_this._materialSignalLODs[indexLOD]) {
  6074. _this._materialSignalLODs[indexLOD].resolve();
  6075. }
  6076. }
  6077. });
  6078. this_2._loader._completePromises.push(promise);
  6079. };
  6080. var this_2 = this;
  6081. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  6082. _loop_2(indexLOD);
  6083. }
  6084. };
  6085. /** @hidden */
  6086. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  6087. var promise = this._loader.loadSceneAsync(context, scene);
  6088. this._loadBufferLOD(this._bufferLODs, 0);
  6089. return promise;
  6090. };
  6091. /** @hidden */
  6092. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  6093. var _this = this;
  6094. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  6095. var firstPromise;
  6096. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  6097. _this._loader.logOpen("" + extensionContext);
  6098. var _loop_3 = function (indexLOD) {
  6099. var nodeLOD = nodeLODs[indexLOD];
  6100. if (indexLOD !== 0) {
  6101. _this._nodeIndexLOD = indexLOD;
  6102. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6103. }
  6104. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  6105. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  6106. if (indexLOD !== 0) {
  6107. // TODO: should not rely on _babylonTransformNode
  6108. var previousNodeLOD = nodeLODs[indexLOD - 1];
  6109. if (previousNodeLOD._babylonTransformNode) {
  6110. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  6111. delete previousNodeLOD._babylonTransformNode;
  6112. }
  6113. }
  6114. babylonMesh.setEnabled(true);
  6115. return babylonMesh;
  6116. });
  6117. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  6118. if (indexLOD === 0) {
  6119. firstPromise = promise;
  6120. }
  6121. else {
  6122. _this._nodeIndexLOD = null;
  6123. _this._nodePromiseLODs[indexLOD].push(promise);
  6124. }
  6125. };
  6126. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  6127. _loop_3(indexLOD);
  6128. }
  6129. _this._loader.logClose();
  6130. return firstPromise;
  6131. });
  6132. };
  6133. /** @hidden */
  6134. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6135. var _this = this;
  6136. // Don't load material LODs if already loading a node LOD.
  6137. if (this._nodeIndexLOD) {
  6138. return null;
  6139. }
  6140. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  6141. var firstPromise;
  6142. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  6143. _this._loader.logOpen("" + extensionContext);
  6144. var _loop_4 = function (indexLOD) {
  6145. var materialLOD = materialLODs[indexLOD];
  6146. if (indexLOD !== 0) {
  6147. _this._materialIndexLOD = indexLOD;
  6148. }
  6149. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  6150. if (indexLOD === 0) {
  6151. assign(babylonMaterial);
  6152. }
  6153. }).then(function (babylonMaterial) {
  6154. if (indexLOD !== 0) {
  6155. assign(babylonMaterial);
  6156. // TODO: should not rely on _data
  6157. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  6158. if (previousDataLOD[babylonDrawMode]) {
  6159. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  6160. delete previousDataLOD[babylonDrawMode];
  6161. }
  6162. }
  6163. return babylonMaterial;
  6164. });
  6165. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  6166. if (indexLOD === 0) {
  6167. firstPromise = promise;
  6168. }
  6169. else {
  6170. _this._materialIndexLOD = null;
  6171. _this._materialPromiseLODs[indexLOD].push(promise);
  6172. }
  6173. };
  6174. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  6175. _loop_4(indexLOD);
  6176. }
  6177. _this._loader.logClose();
  6178. return firstPromise;
  6179. });
  6180. };
  6181. /** @hidden */
  6182. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  6183. var _this = this;
  6184. // Defer the loading of uris if loading a node or material LOD.
  6185. if (this._nodeIndexLOD !== null) {
  6186. this._loader.log("deferred");
  6187. var previousIndexLOD = this._nodeIndexLOD - 1;
  6188. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6189. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  6190. return _this._loader.loadUriAsync(context, property, uri);
  6191. });
  6192. }
  6193. else if (this._materialIndexLOD !== null) {
  6194. this._loader.log("deferred");
  6195. var previousIndexLOD = this._materialIndexLOD - 1;
  6196. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6197. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  6198. return _this._loader.loadUriAsync(context, property, uri);
  6199. });
  6200. }
  6201. return null;
  6202. };
  6203. /** @hidden */
  6204. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6205. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  6206. if (!this._loader.bin) {
  6207. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6208. }
  6209. var loadAsync = function (bufferLODs, indexLOD) {
  6210. var start = byteOffset;
  6211. var end = start + byteLength - 1;
  6212. var bufferLOD = bufferLODs[indexLOD];
  6213. if (bufferLOD) {
  6214. bufferLOD.start = Math.min(bufferLOD.start, start);
  6215. bufferLOD.end = Math.max(bufferLOD.end, end);
  6216. }
  6217. else {
  6218. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  6219. bufferLODs[indexLOD] = bufferLOD;
  6220. }
  6221. return bufferLOD.loaded.promise.then(function (data) {
  6222. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  6223. });
  6224. };
  6225. this._loader.log("deferred");
  6226. if (this._nodeIndexLOD !== null) {
  6227. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  6228. }
  6229. else if (this._materialIndexLOD !== null) {
  6230. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  6231. }
  6232. else {
  6233. return loadAsync(this._bufferLODs, 0);
  6234. }
  6235. }
  6236. return null;
  6237. };
  6238. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  6239. var bufferLOD = bufferLODs[indexLOD];
  6240. if (bufferLOD) {
  6241. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  6242. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  6243. bufferLOD.loaded.resolve(data);
  6244. }, function (error) {
  6245. bufferLOD.loaded.reject(error);
  6246. });
  6247. }
  6248. };
  6249. /**
  6250. * Gets an array of LOD properties from lowest to highest.
  6251. */
  6252. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  6253. if (this.maxLODsToLoad <= 0) {
  6254. throw new Error("maxLODsToLoad must be greater than zero");
  6255. }
  6256. var properties = new Array();
  6257. for (var i = ids.length - 1; i >= 0; i--) {
  6258. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  6259. if (properties.length === this.maxLODsToLoad) {
  6260. return properties;
  6261. }
  6262. }
  6263. properties.push(property);
  6264. return properties;
  6265. };
  6266. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  6267. var _this = this;
  6268. var babylonMaterials = new Array();
  6269. var babylonMaterial = babylonTransformNode.material;
  6270. if (babylonMaterial) {
  6271. babylonMaterials.push(babylonMaterial);
  6272. }
  6273. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  6274. var babylonMesh = _a[_i];
  6275. if (babylonMesh.material) {
  6276. babylonMaterials.push(babylonMesh.material);
  6277. }
  6278. }
  6279. babylonTransformNode.dispose();
  6280. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  6281. this._disposeMaterials(babylonMaterialsToDispose);
  6282. };
  6283. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  6284. var babylonTextures = {};
  6285. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  6286. var babylonMaterial = babylonMaterials_1[_i];
  6287. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  6288. var babylonTexture = _b[_a];
  6289. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  6290. }
  6291. babylonMaterial.dispose();
  6292. }
  6293. for (var uniqueId in babylonTextures) {
  6294. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  6295. var babylonMaterial = _d[_c];
  6296. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  6297. delete babylonTextures[uniqueId];
  6298. }
  6299. }
  6300. }
  6301. for (var uniqueId in babylonTextures) {
  6302. babylonTextures[uniqueId].dispose();
  6303. }
  6304. };
  6305. return MSFT_lod;
  6306. }());
  6307. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  6308. /***/ }),
  6309. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  6310. /*!***************************************************!*\
  6311. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  6312. \***************************************************/
  6313. /*! exports provided: MSFT_minecraftMesh */
  6314. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6315. "use strict";
  6316. __webpack_require__.r(__webpack_exports__);
  6317. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  6318. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  6319. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  6320. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  6321. var NAME = "MSFT_minecraftMesh";
  6322. /** @hidden */
  6323. var MSFT_minecraftMesh = /** @class */ (function () {
  6324. function MSFT_minecraftMesh(loader) {
  6325. this.name = NAME;
  6326. this._loader = loader;
  6327. this.enabled = this._loader.isExtensionUsed(NAME);
  6328. }
  6329. MSFT_minecraftMesh.prototype.dispose = function () {
  6330. this._loader = null;
  6331. };
  6332. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6333. var _this = this;
  6334. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  6335. if (extra) {
  6336. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6337. throw new Error(extraContext + ": Material type not supported");
  6338. }
  6339. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  6340. if (babylonMaterial.needAlphaBlending()) {
  6341. babylonMaterial.forceDepthWrite = true;
  6342. babylonMaterial.separateCullingPass = true;
  6343. }
  6344. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  6345. babylonMaterial.twoSidedLighting = true;
  6346. return promise;
  6347. }
  6348. return null;
  6349. });
  6350. };
  6351. return MSFT_minecraftMesh;
  6352. }());
  6353. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  6354. /***/ }),
  6355. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  6356. /*!*************************************************!*\
  6357. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  6358. \*************************************************/
  6359. /*! exports provided: MSFT_sRGBFactors */
  6360. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6361. "use strict";
  6362. __webpack_require__.r(__webpack_exports__);
  6363. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  6364. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  6365. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  6366. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  6367. var NAME = "MSFT_sRGBFactors";
  6368. /** @hidden */
  6369. var MSFT_sRGBFactors = /** @class */ (function () {
  6370. function MSFT_sRGBFactors(loader) {
  6371. this.name = NAME;
  6372. this._loader = loader;
  6373. this.enabled = this._loader.isExtensionUsed(NAME);
  6374. }
  6375. MSFT_sRGBFactors.prototype.dispose = function () {
  6376. this._loader = null;
  6377. };
  6378. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6379. var _this = this;
  6380. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  6381. if (extra) {
  6382. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6383. throw new Error(extraContext + ": Material type not supported");
  6384. }
  6385. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  6386. if (!babylonMaterial.albedoTexture) {
  6387. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  6388. }
  6389. if (!babylonMaterial.reflectivityTexture) {
  6390. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  6391. }
  6392. return promise;
  6393. }
  6394. return null;
  6395. });
  6396. };
  6397. return MSFT_sRGBFactors;
  6398. }());
  6399. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  6400. /***/ }),
  6401. /***/ "./glTF/2.0/Extensions/index.ts":
  6402. /*!**************************************!*\
  6403. !*** ./glTF/2.0/Extensions/index.ts ***!
  6404. \**************************************/
  6405. /*! exports provided: EXT_lights_image_based, EXT_mesh_gpu_instancing, EXT_meshopt_compression, EXT_texture_webp, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_materials_translucency, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp_json_ld, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  6406. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6407. "use strict";
  6408. __webpack_require__.r(__webpack_exports__);
  6409. /* 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");
  6410. /* 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"]; });
  6411. /* harmony import */ var _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EXT_mesh_gpu_instancing */ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts");
  6412. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  6413. /* harmony import */ var _EXT_meshopt_compression__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./EXT_meshopt_compression */ "./glTF/2.0/Extensions/EXT_meshopt_compression.ts");
  6414. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_meshopt_compression", function() { return _EXT_meshopt_compression__WEBPACK_IMPORTED_MODULE_2__["EXT_meshopt_compression"]; });
  6415. /* harmony import */ var _EXT_texture_webp__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EXT_texture_webp */ "./glTF/2.0/Extensions/EXT_texture_webp.ts");
  6416. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_texture_webp", function() { return _EXT_texture_webp__WEBPACK_IMPORTED_MODULE_3__["EXT_texture_webp"]; });
  6417. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  6418. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_4__["KHR_draco_mesh_compression"]; });
  6419. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  6420. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_5__["KHR_lights"]; });
  6421. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  6422. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_pbrSpecularGlossiness"]; });
  6423. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  6424. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_unlit"]; });
  6425. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  6426. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_clearcoat"]; });
  6427. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  6428. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_sheen"]; });
  6429. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  6430. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_specular"]; });
  6431. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  6432. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_ior"]; });
  6433. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  6434. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_12__["KHR_materials_variants"]; });
  6435. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  6436. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_13__["KHR_materials_transmission"]; });
  6437. /* harmony import */ var _KHR_materials_translucency__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_materials_translucency */ "./glTF/2.0/Extensions/KHR_materials_translucency.ts");
  6438. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_translucency", function() { return _KHR_materials_translucency__WEBPACK_IMPORTED_MODULE_14__["KHR_materials_translucency"]; });
  6439. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  6440. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_15__["KHR_mesh_quantization"]; });
  6441. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  6442. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_16__["KHR_texture_basisu"]; });
  6443. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  6444. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_17__["KHR_texture_transform"]; });
  6445. /* harmony import */ var _KHR_xmp_json_ld__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./KHR_xmp_json_ld */ "./glTF/2.0/Extensions/KHR_xmp_json_ld.ts");
  6446. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp_json_ld", function() { return _KHR_xmp_json_ld__WEBPACK_IMPORTED_MODULE_18__["KHR_xmp_json_ld"]; });
  6447. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  6448. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_19__["MSFT_audio_emitter"]; });
  6449. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  6450. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_20__["MSFT_lod"]; });
  6451. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  6452. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_21__["MSFT_minecraftMesh"]; });
  6453. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  6454. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_22__["MSFT_sRGBFactors"]; });
  6455. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  6456. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_23__["ExtrasAsMetadata"]; });
  6457. /***/ }),
  6458. /***/ "./glTF/2.0/glTFLoader.ts":
  6459. /*!********************************!*\
  6460. !*** ./glTF/2.0/glTFLoader.ts ***!
  6461. \********************************/
  6462. /*! exports provided: ArrayItem, GLTFLoader */
  6463. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6464. "use strict";
  6465. __webpack_require__.r(__webpack_exports__);
  6466. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  6467. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  6468. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  6469. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  6470. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  6471. /**
  6472. * Helper class for working with arrays when loading the glTF asset
  6473. */
  6474. var ArrayItem = /** @class */ (function () {
  6475. function ArrayItem() {
  6476. }
  6477. /**
  6478. * Gets an item from the given array.
  6479. * @param context The context when loading the asset
  6480. * @param array The array to get the item from
  6481. * @param index The index to the array
  6482. * @returns The array item
  6483. */
  6484. ArrayItem.Get = function (context, array, index) {
  6485. if (!array || index == undefined || !array[index]) {
  6486. throw new Error(context + ": Failed to find index (" + index + ")");
  6487. }
  6488. return array[index];
  6489. };
  6490. /**
  6491. * Assign an `index` field to each item of the given array.
  6492. * @param array The array of items
  6493. */
  6494. ArrayItem.Assign = function (array) {
  6495. if (array) {
  6496. for (var index = 0; index < array.length; index++) {
  6497. array[index].index = index;
  6498. }
  6499. }
  6500. };
  6501. return ArrayItem;
  6502. }());
  6503. /**
  6504. * The glTF 2.0 loader
  6505. */
  6506. var GLTFLoader = /** @class */ (function () {
  6507. /** @hidden */
  6508. function GLTFLoader(parent) {
  6509. /** @hidden */
  6510. this._completePromises = new Array();
  6511. /** @hidden */
  6512. this._forAssetContainer = false;
  6513. /** Storage */
  6514. this._babylonLights = [];
  6515. /** @hidden */
  6516. this._disableInstancedMesh = 0;
  6517. this._disposed = false;
  6518. this._state = null;
  6519. this._extensions = new Array();
  6520. this._defaultBabylonMaterialData = {};
  6521. this._parent = parent;
  6522. }
  6523. /**
  6524. * Registers a loader extension.
  6525. * @param name The name of the loader extension.
  6526. * @param factory The factory function that creates the loader extension.
  6527. */
  6528. GLTFLoader.RegisterExtension = function (name, factory) {
  6529. if (GLTFLoader.UnregisterExtension(name)) {
  6530. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  6531. }
  6532. GLTFLoader._RegisteredExtensions[name] = {
  6533. factory: factory
  6534. };
  6535. };
  6536. /**
  6537. * Unregisters a loader extension.
  6538. * @param name The name of the loader extension.
  6539. * @returns A boolean indicating whether the extension has been unregistered
  6540. */
  6541. GLTFLoader.UnregisterExtension = function (name) {
  6542. if (!GLTFLoader._RegisteredExtensions[name]) {
  6543. return false;
  6544. }
  6545. delete GLTFLoader._RegisteredExtensions[name];
  6546. return true;
  6547. };
  6548. Object.defineProperty(GLTFLoader.prototype, "state", {
  6549. /**
  6550. * The loader state.
  6551. */
  6552. get: function () {
  6553. return this._state;
  6554. },
  6555. enumerable: false,
  6556. configurable: true
  6557. });
  6558. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  6559. /**
  6560. * The object that represents the glTF JSON.
  6561. */
  6562. get: function () {
  6563. return this._gltf;
  6564. },
  6565. enumerable: false,
  6566. configurable: true
  6567. });
  6568. Object.defineProperty(GLTFLoader.prototype, "bin", {
  6569. /**
  6570. * The BIN chunk of a binary glTF.
  6571. */
  6572. get: function () {
  6573. return this._bin;
  6574. },
  6575. enumerable: false,
  6576. configurable: true
  6577. });
  6578. Object.defineProperty(GLTFLoader.prototype, "parent", {
  6579. /**
  6580. * The parent file loader.
  6581. */
  6582. get: function () {
  6583. return this._parent;
  6584. },
  6585. enumerable: false,
  6586. configurable: true
  6587. });
  6588. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  6589. /**
  6590. * The Babylon scene when loading the asset.
  6591. */
  6592. get: function () {
  6593. return this._babylonScene;
  6594. },
  6595. enumerable: false,
  6596. configurable: true
  6597. });
  6598. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  6599. /**
  6600. * The root Babylon mesh when loading the asset.
  6601. */
  6602. get: function () {
  6603. return this._rootBabylonMesh;
  6604. },
  6605. enumerable: false,
  6606. configurable: true
  6607. });
  6608. /** @hidden */
  6609. GLTFLoader.prototype.dispose = function () {
  6610. if (this._disposed) {
  6611. return;
  6612. }
  6613. this._disposed = true;
  6614. this._completePromises.length = 0;
  6615. for (var name_1 in this._extensions) {
  6616. var extension = this._extensions[name_1];
  6617. extension.dispose && extension.dispose();
  6618. delete this._extensions[name_1];
  6619. }
  6620. this._gltf = null;
  6621. this._babylonScene = null;
  6622. this._rootBabylonMesh = null;
  6623. this._parent.dispose();
  6624. };
  6625. /** @hidden */
  6626. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  6627. var _this = this;
  6628. if (fileName === void 0) { fileName = ""; }
  6629. return Promise.resolve().then(function () {
  6630. _this._babylonScene = scene;
  6631. _this._forAssetContainer = forAssetContainer;
  6632. _this._loadData(data);
  6633. var nodes = null;
  6634. if (meshesNames) {
  6635. var nodeMap_1 = {};
  6636. if (_this._gltf.nodes) {
  6637. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  6638. var node = _a[_i];
  6639. if (node.name) {
  6640. nodeMap_1[node.name] = node.index;
  6641. }
  6642. }
  6643. }
  6644. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  6645. nodes = names.map(function (name) {
  6646. var node = nodeMap_1[name];
  6647. if (node === undefined) {
  6648. throw new Error("Failed to find node '" + name + "'");
  6649. }
  6650. return node;
  6651. });
  6652. }
  6653. return _this._loadAsync(rootUrl, fileName, nodes, function () {
  6654. return {
  6655. meshes: _this._getMeshes(),
  6656. particleSystems: [],
  6657. skeletons: _this._getSkeletons(),
  6658. animationGroups: _this._getAnimationGroups(),
  6659. lights: _this._babylonLights,
  6660. transformNodes: _this._getTransformNodes(),
  6661. geometries: _this._getGeometries()
  6662. };
  6663. });
  6664. });
  6665. };
  6666. /** @hidden */
  6667. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  6668. var _this = this;
  6669. if (fileName === void 0) { fileName = ""; }
  6670. return Promise.resolve().then(function () {
  6671. _this._babylonScene = scene;
  6672. _this._loadData(data);
  6673. return _this._loadAsync(rootUrl, fileName, null, function () { return undefined; });
  6674. });
  6675. };
  6676. GLTFLoader.prototype._loadAsync = function (rootUrl, fileName, nodes, resultFunc) {
  6677. var _this = this;
  6678. return Promise.resolve().then(function () {
  6679. _this._rootUrl = rootUrl;
  6680. _this._uniqueRootUrl = (!babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(rootUrl, "file:") && fileName) ? rootUrl : "" + rootUrl + Date.now() + "/";
  6681. _this._fileName = fileName;
  6682. _this._loadExtensions();
  6683. _this._checkExtensions();
  6684. 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];
  6685. 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];
  6686. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  6687. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  6688. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  6689. _this._extensionsOnLoading();
  6690. var promises = new Array();
  6691. // Block the marking of materials dirty until the scene is loaded.
  6692. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  6693. _this._babylonScene.blockMaterialDirtyMechanism = true;
  6694. if (nodes) {
  6695. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  6696. }
  6697. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  6698. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  6699. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  6700. }
  6701. if (_this.parent.loadAllMaterials && _this._gltf.materials) {
  6702. for (var m = 0; m < _this._gltf.materials.length; ++m) {
  6703. var material = _this._gltf.materials[m];
  6704. var context_1 = "/materials/" + m;
  6705. var babylonDrawMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  6706. promises.push(_this._loadMaterialAsync(context_1, material, null, babylonDrawMode, function (material) { }));
  6707. }
  6708. }
  6709. // Restore the blocking of material dirty.
  6710. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  6711. if (_this._parent.compileMaterials) {
  6712. promises.push(_this._compileMaterialsAsync());
  6713. }
  6714. if (_this._parent.compileShadowGenerators) {
  6715. promises.push(_this._compileShadowGeneratorsAsync());
  6716. }
  6717. var resultPromise = Promise.all(promises).then(function () {
  6718. if (_this._rootBabylonMesh) {
  6719. _this._rootBabylonMesh.setEnabled(true);
  6720. }
  6721. _this._extensionsOnReady();
  6722. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  6723. _this._startAnimations();
  6724. return resultFunc();
  6725. });
  6726. return resultPromise.then(function (result) {
  6727. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  6728. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  6729. if (!_this._disposed) {
  6730. Promise.all(_this._completePromises).then(function () {
  6731. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  6732. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  6733. _this._parent.onCompleteObservable.notifyObservers(undefined);
  6734. _this._parent.onCompleteObservable.clear();
  6735. _this.dispose();
  6736. }, function (error) {
  6737. _this._parent.onErrorObservable.notifyObservers(error);
  6738. _this._parent.onErrorObservable.clear();
  6739. _this.dispose();
  6740. });
  6741. }
  6742. });
  6743. return result;
  6744. });
  6745. }).catch(function (error) {
  6746. if (!_this._disposed) {
  6747. _this._parent.onErrorObservable.notifyObservers(error);
  6748. _this._parent.onErrorObservable.clear();
  6749. _this.dispose();
  6750. }
  6751. throw error;
  6752. });
  6753. };
  6754. GLTFLoader.prototype._loadData = function (data) {
  6755. this._gltf = data.json;
  6756. this._setupData();
  6757. if (data.bin) {
  6758. var buffers = this._gltf.buffers;
  6759. if (buffers && buffers[0] && !buffers[0].uri) {
  6760. var binaryBuffer = buffers[0];
  6761. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  6762. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  6763. }
  6764. this._bin = data.bin;
  6765. }
  6766. else {
  6767. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  6768. }
  6769. }
  6770. };
  6771. GLTFLoader.prototype._setupData = function () {
  6772. ArrayItem.Assign(this._gltf.accessors);
  6773. ArrayItem.Assign(this._gltf.animations);
  6774. ArrayItem.Assign(this._gltf.buffers);
  6775. ArrayItem.Assign(this._gltf.bufferViews);
  6776. ArrayItem.Assign(this._gltf.cameras);
  6777. ArrayItem.Assign(this._gltf.images);
  6778. ArrayItem.Assign(this._gltf.materials);
  6779. ArrayItem.Assign(this._gltf.meshes);
  6780. ArrayItem.Assign(this._gltf.nodes);
  6781. ArrayItem.Assign(this._gltf.samplers);
  6782. ArrayItem.Assign(this._gltf.scenes);
  6783. ArrayItem.Assign(this._gltf.skins);
  6784. ArrayItem.Assign(this._gltf.textures);
  6785. if (this._gltf.nodes) {
  6786. var nodeParents = {};
  6787. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  6788. var node = _a[_i];
  6789. if (node.children) {
  6790. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  6791. var index = _c[_b];
  6792. nodeParents[index] = node.index;
  6793. }
  6794. }
  6795. }
  6796. var rootNode = this._createRootNode();
  6797. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  6798. var node = _e[_d];
  6799. var parentIndex = nodeParents[node.index];
  6800. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  6801. }
  6802. }
  6803. };
  6804. GLTFLoader.prototype._loadExtensions = function () {
  6805. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  6806. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  6807. if (extension.name !== name_2) {
  6808. 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);
  6809. }
  6810. this._extensions.push(extension);
  6811. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  6812. }
  6813. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  6814. this._parent.onExtensionLoadedObservable.clear();
  6815. };
  6816. GLTFLoader.prototype._checkExtensions = function () {
  6817. if (this._gltf.extensionsRequired) {
  6818. var _loop_1 = function (name_3) {
  6819. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  6820. if (!available) {
  6821. throw new Error("Require extension " + name_3 + " is not available");
  6822. }
  6823. };
  6824. var this_1 = this;
  6825. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  6826. var name_3 = _a[_i];
  6827. _loop_1(name_3);
  6828. }
  6829. }
  6830. };
  6831. GLTFLoader.prototype._setState = function (state) {
  6832. this._state = state;
  6833. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  6834. };
  6835. GLTFLoader.prototype._createRootNode = function () {
  6836. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6837. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  6838. this._babylonScene._blockEntityCollection = false;
  6839. this._rootBabylonMesh.setEnabled(false);
  6840. var rootNode = {
  6841. _babylonTransformNode: this._rootBabylonMesh,
  6842. index: -1
  6843. };
  6844. switch (this._parent.coordinateSystemMode) {
  6845. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  6846. if (!this._babylonScene.useRightHandedSystem) {
  6847. rootNode.rotation = [0, 1, 0, 0];
  6848. rootNode.scale = [1, 1, -1];
  6849. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  6850. }
  6851. break;
  6852. }
  6853. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  6854. this._babylonScene.useRightHandedSystem = true;
  6855. break;
  6856. }
  6857. default: {
  6858. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  6859. }
  6860. }
  6861. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  6862. return rootNode;
  6863. };
  6864. /**
  6865. * Loads a glTF scene.
  6866. * @param context The context when loading the asset
  6867. * @param scene The glTF scene property
  6868. * @returns A promise that resolves when the load is complete
  6869. */
  6870. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  6871. var _this = this;
  6872. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  6873. if (extensionPromise) {
  6874. return extensionPromise;
  6875. }
  6876. var promises = new Array();
  6877. this.logOpen(context + " " + (scene.name || ""));
  6878. if (scene.nodes) {
  6879. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  6880. var index = _a[_i];
  6881. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  6882. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  6883. babylonMesh.parent = _this._rootBabylonMesh;
  6884. }));
  6885. }
  6886. }
  6887. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  6888. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  6889. if (this._gltf.nodes) {
  6890. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  6891. var node = _c[_b];
  6892. if (node._babylonTransformNode && node._babylonBones) {
  6893. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  6894. var babylonBone = _e[_d];
  6895. babylonBone.linkTransformNode(node._babylonTransformNode);
  6896. }
  6897. }
  6898. }
  6899. }
  6900. promises.push(this._loadAnimationsAsync());
  6901. this.logClose();
  6902. return Promise.all(promises).then(function () { });
  6903. };
  6904. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  6905. if (node._primitiveBabylonMeshes) {
  6906. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  6907. var babylonMesh = _a[_i];
  6908. callback(babylonMesh);
  6909. }
  6910. }
  6911. };
  6912. GLTFLoader.prototype._getGeometries = function () {
  6913. var geometries = new Array();
  6914. var nodes = this._gltf.nodes;
  6915. if (nodes) {
  6916. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  6917. var node = nodes_1[_i];
  6918. this._forEachPrimitive(node, function (babylonMesh) {
  6919. var geometry = babylonMesh.geometry;
  6920. if (geometry && geometries.indexOf(geometry) === -1) {
  6921. geometries.push(geometry);
  6922. }
  6923. });
  6924. }
  6925. }
  6926. return geometries;
  6927. };
  6928. GLTFLoader.prototype._getMeshes = function () {
  6929. var meshes = new Array();
  6930. // Root mesh is always first.
  6931. meshes.push(this._rootBabylonMesh);
  6932. var nodes = this._gltf.nodes;
  6933. if (nodes) {
  6934. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  6935. var node = nodes_2[_i];
  6936. this._forEachPrimitive(node, function (babylonMesh) {
  6937. meshes.push(babylonMesh);
  6938. });
  6939. }
  6940. }
  6941. return meshes;
  6942. };
  6943. GLTFLoader.prototype._getTransformNodes = function () {
  6944. var transformNodes = new Array();
  6945. var nodes = this._gltf.nodes;
  6946. if (nodes) {
  6947. for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
  6948. var node = nodes_3[_i];
  6949. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  6950. transformNodes.push(node._babylonTransformNode);
  6951. }
  6952. }
  6953. }
  6954. return transformNodes;
  6955. };
  6956. GLTFLoader.prototype._getSkeletons = function () {
  6957. var skeletons = new Array();
  6958. var skins = this._gltf.skins;
  6959. if (skins) {
  6960. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  6961. var skin = skins_1[_i];
  6962. if (skin._data) {
  6963. skeletons.push(skin._data.babylonSkeleton);
  6964. }
  6965. }
  6966. }
  6967. return skeletons;
  6968. };
  6969. GLTFLoader.prototype._getAnimationGroups = function () {
  6970. var animationGroups = new Array();
  6971. var animations = this._gltf.animations;
  6972. if (animations) {
  6973. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  6974. var animation = animations_1[_i];
  6975. if (animation._babylonAnimationGroup) {
  6976. animationGroups.push(animation._babylonAnimationGroup);
  6977. }
  6978. }
  6979. }
  6980. return animationGroups;
  6981. };
  6982. GLTFLoader.prototype._startAnimations = function () {
  6983. switch (this._parent.animationStartMode) {
  6984. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  6985. // do nothing
  6986. break;
  6987. }
  6988. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  6989. var babylonAnimationGroups = this._getAnimationGroups();
  6990. if (babylonAnimationGroups.length !== 0) {
  6991. babylonAnimationGroups[0].start(true);
  6992. }
  6993. break;
  6994. }
  6995. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  6996. var babylonAnimationGroups = this._getAnimationGroups();
  6997. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  6998. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  6999. babylonAnimationGroup.start(true);
  7000. }
  7001. break;
  7002. }
  7003. default: {
  7004. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  7005. return;
  7006. }
  7007. }
  7008. };
  7009. /**
  7010. * Loads a glTF node.
  7011. * @param context The context when loading the asset
  7012. * @param node The glTF node property
  7013. * @param assign A function called synchronously after parsing the glTF properties
  7014. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  7015. */
  7016. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  7017. var _this = this;
  7018. if (assign === void 0) { assign = function () { }; }
  7019. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  7020. if (extensionPromise) {
  7021. return extensionPromise;
  7022. }
  7023. if (node._babylonTransformNode) {
  7024. throw new Error(context + ": Invalid recursive node hierarchy");
  7025. }
  7026. var promises = new Array();
  7027. this.logOpen(context + " " + (node.name || ""));
  7028. var loadNode = function (babylonTransformNode) {
  7029. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  7030. GLTFLoader._LoadTransform(node, babylonTransformNode);
  7031. if (node.camera != undefined) {
  7032. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  7033. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  7034. babylonCamera.parent = babylonTransformNode;
  7035. }));
  7036. }
  7037. if (node.children) {
  7038. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  7039. var index = _a[_i];
  7040. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  7041. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  7042. childBabylonMesh.parent = babylonTransformNode;
  7043. }));
  7044. }
  7045. }
  7046. assign(babylonTransformNode);
  7047. };
  7048. if (node.mesh == undefined) {
  7049. var nodeName = node.name || "node" + node.index;
  7050. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7051. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  7052. this._babylonScene._blockEntityCollection = false;
  7053. loadNode(node._babylonTransformNode);
  7054. }
  7055. else {
  7056. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  7057. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  7058. }
  7059. this.logClose();
  7060. return Promise.all(promises).then(function () {
  7061. _this._forEachPrimitive(node, function (babylonMesh) {
  7062. if (babylonMesh.geometry && babylonMesh.geometry.useBoundingInfoFromGeometry) {
  7063. // simply apply the world matrices to the bounding info - the extends are already ok
  7064. babylonMesh._updateBoundingInfo();
  7065. }
  7066. else {
  7067. babylonMesh.refreshBoundingInfo(true);
  7068. }
  7069. });
  7070. return node._babylonTransformNode;
  7071. });
  7072. };
  7073. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  7074. var primitives = mesh.primitives;
  7075. if (!primitives || !primitives.length) {
  7076. throw new Error(context + ": Primitives are missing");
  7077. }
  7078. if (primitives[0].index == undefined) {
  7079. ArrayItem.Assign(primitives);
  7080. }
  7081. var promises = new Array();
  7082. this.logOpen(context + " " + (mesh.name || ""));
  7083. var name = node.name || "node" + node.index;
  7084. if (primitives.length === 1) {
  7085. var primitive = mesh.primitives[0];
  7086. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  7087. node._babylonTransformNode = babylonMesh;
  7088. node._primitiveBabylonMeshes = [babylonMesh];
  7089. }));
  7090. }
  7091. else {
  7092. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7093. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  7094. this._babylonScene._blockEntityCollection = false;
  7095. node._primitiveBabylonMeshes = [];
  7096. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  7097. var primitive = primitives_1[_i];
  7098. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  7099. babylonMesh.parent = node._babylonTransformNode;
  7100. node._primitiveBabylonMeshes.push(babylonMesh);
  7101. }));
  7102. }
  7103. }
  7104. if (node.skin != undefined) {
  7105. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  7106. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  7107. }
  7108. assign(node._babylonTransformNode);
  7109. this.logClose();
  7110. return Promise.all(promises).then(function () {
  7111. return node._babylonTransformNode;
  7112. });
  7113. };
  7114. /**
  7115. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  7116. * @param context The context when loading the asset
  7117. * @param name The mesh name when loading the asset
  7118. * @param node The glTF node when loading the asset
  7119. * @param mesh The glTF mesh when loading the asset
  7120. * @param primitive The glTF mesh primitive property
  7121. * @param assign A function called synchronously after parsing the glTF properties
  7122. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  7123. */
  7124. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7125. var _this = this;
  7126. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  7127. if (extensionPromise) {
  7128. return extensionPromise;
  7129. }
  7130. this.logOpen("" + context);
  7131. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  7132. var babylonAbstractMesh;
  7133. var promise;
  7134. if (shouldInstance && primitive._instanceData) {
  7135. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  7136. promise = primitive._instanceData.promise;
  7137. }
  7138. else {
  7139. var promises = new Array();
  7140. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7141. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  7142. this._babylonScene._blockEntityCollection = false;
  7143. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  7144. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  7145. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  7146. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  7147. _this._babylonScene._blockEntityCollection = _this._forAssetContainer;
  7148. babylonGeometry.applyToMesh(babylonMesh_1);
  7149. _this._babylonScene._blockEntityCollection = false;
  7150. });
  7151. }));
  7152. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  7153. if (primitive.material == undefined) {
  7154. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  7155. if (!babylonMaterial) {
  7156. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  7157. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7158. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  7159. }
  7160. babylonMesh_1.material = babylonMaterial;
  7161. }
  7162. else {
  7163. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  7164. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  7165. babylonMesh_1.material = babylonMaterial;
  7166. }));
  7167. }
  7168. promise = Promise.all(promises);
  7169. if (shouldInstance) {
  7170. primitive._instanceData = {
  7171. babylonSourceMesh: babylonMesh_1,
  7172. promise: promise
  7173. };
  7174. }
  7175. babylonAbstractMesh = babylonMesh_1;
  7176. }
  7177. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  7178. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  7179. assign(babylonAbstractMesh);
  7180. this.logClose();
  7181. return promise.then(function () {
  7182. return babylonAbstractMesh;
  7183. });
  7184. };
  7185. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  7186. var _this = this;
  7187. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  7188. if (extensionPromise) {
  7189. return extensionPromise;
  7190. }
  7191. var attributes = primitive.attributes;
  7192. if (!attributes) {
  7193. throw new Error(context + ": Attributes are missing");
  7194. }
  7195. var promises = new Array();
  7196. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  7197. if (primitive.indices == undefined) {
  7198. babylonMesh.isUnIndexed = true;
  7199. }
  7200. else {
  7201. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  7202. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7203. babylonGeometry.setIndices(data);
  7204. }));
  7205. }
  7206. var loadAttribute = function (attribute, kind, callback) {
  7207. if (attributes[attribute] == undefined) {
  7208. return;
  7209. }
  7210. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  7211. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  7212. babylonMesh._delayInfo.push(kind);
  7213. }
  7214. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  7215. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  7216. if (babylonVertexBuffer.getKind() === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
  7217. var mmin = accessor.min, mmax = accessor.max;
  7218. if (mmin !== undefined && mmax !== undefined) {
  7219. var min = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], max = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1];
  7220. min.copyFromFloats.apply(min, mmin);
  7221. max.copyFromFloats.apply(max, mmax);
  7222. babylonGeometry._boundingInfo = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["BoundingInfo"](min, max);
  7223. babylonGeometry.useBoundingInfoFromGeometry = true;
  7224. }
  7225. }
  7226. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  7227. }));
  7228. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  7229. babylonMesh.numBoneInfluencers = 8;
  7230. }
  7231. if (callback) {
  7232. callback(accessor);
  7233. }
  7234. };
  7235. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  7236. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  7237. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  7238. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  7239. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  7240. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  7241. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  7242. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  7243. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  7244. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  7245. if (accessor.type === "VEC4" /* VEC4 */) {
  7246. babylonMesh.hasVertexAlpha = true;
  7247. }
  7248. });
  7249. return Promise.all(promises).then(function () {
  7250. return babylonGeometry;
  7251. });
  7252. };
  7253. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  7254. if (!primitive.targets) {
  7255. return;
  7256. }
  7257. if (node._numMorphTargets == undefined) {
  7258. node._numMorphTargets = primitive.targets.length;
  7259. }
  7260. else if (primitive.targets.length !== node._numMorphTargets) {
  7261. throw new Error(context + ": Primitives do not have the same number of targets");
  7262. }
  7263. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  7264. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  7265. for (var index = 0; index < primitive.targets.length; index++) {
  7266. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  7267. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  7268. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  7269. // TODO: tell the target whether it has positions, normals, tangents
  7270. }
  7271. };
  7272. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  7273. if (!primitive.targets) {
  7274. return Promise.resolve();
  7275. }
  7276. var promises = new Array();
  7277. var morphTargetManager = babylonMesh.morphTargetManager;
  7278. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  7279. var babylonMorphTarget = morphTargetManager.getTarget(index);
  7280. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  7281. }
  7282. return Promise.all(promises).then(function () { });
  7283. };
  7284. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  7285. var _this = this;
  7286. var promises = new Array();
  7287. var loadAttribute = function (attribute, kind, setData) {
  7288. if (attributes[attribute] == undefined) {
  7289. return;
  7290. }
  7291. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  7292. if (!babylonVertexBuffer) {
  7293. return;
  7294. }
  7295. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  7296. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7297. setData(babylonVertexBuffer, data);
  7298. }));
  7299. };
  7300. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  7301. var positions = new Float32Array(data.length);
  7302. babylonVertexBuffer.forEach(data.length, function (value, index) {
  7303. positions[index] = data[index] + value;
  7304. });
  7305. babylonMorphTarget.setPositions(positions);
  7306. });
  7307. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  7308. var normals = new Float32Array(data.length);
  7309. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  7310. normals[index] = data[index] + value;
  7311. });
  7312. babylonMorphTarget.setNormals(normals);
  7313. });
  7314. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  7315. var tangents = new Float32Array(data.length / 3 * 4);
  7316. var dataIndex = 0;
  7317. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  7318. // Tangent data for morph targets is stored as xyz delta.
  7319. // The vertexData.tangent is stored as xyzw.
  7320. // So we need to skip every fourth vertexData.tangent.
  7321. if (((index + 1) % 4) !== 0) {
  7322. tangents[dataIndex] = data[dataIndex] + value;
  7323. dataIndex++;
  7324. }
  7325. });
  7326. babylonMorphTarget.setTangents(tangents);
  7327. });
  7328. return Promise.all(promises).then(function () { });
  7329. };
  7330. GLTFLoader._LoadTransform = function (node, babylonNode) {
  7331. // Ignore the TRS of skinned nodes.
  7332. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  7333. if (node.skin != undefined) {
  7334. return;
  7335. }
  7336. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  7337. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  7338. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  7339. if (node.matrix) {
  7340. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  7341. matrix.decompose(scaling, rotation, position);
  7342. }
  7343. else {
  7344. if (node.translation) {
  7345. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  7346. }
  7347. if (node.rotation) {
  7348. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  7349. }
  7350. if (node.scale) {
  7351. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  7352. }
  7353. }
  7354. babylonNode.position = position;
  7355. babylonNode.rotationQuaternion = rotation;
  7356. babylonNode.scaling = scaling;
  7357. };
  7358. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  7359. var _this = this;
  7360. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  7361. if (extensionPromise) {
  7362. return extensionPromise;
  7363. }
  7364. var assignSkeleton = function (skeleton) {
  7365. _this._forEachPrimitive(node, function (babylonMesh) {
  7366. babylonMesh.skeleton = skeleton;
  7367. });
  7368. };
  7369. if (skin._data) {
  7370. assignSkeleton(skin._data.babylonSkeleton);
  7371. return skin._data.promise;
  7372. }
  7373. var skeletonId = "skeleton" + skin.index;
  7374. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7375. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  7376. this._babylonScene._blockEntityCollection = false;
  7377. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  7378. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  7379. this._loadBones(context, skin, babylonSkeleton);
  7380. assignSkeleton(babylonSkeleton);
  7381. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  7382. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  7383. });
  7384. skin._data = {
  7385. babylonSkeleton: babylonSkeleton,
  7386. promise: promise
  7387. };
  7388. return promise;
  7389. };
  7390. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  7391. var babylonBones = {};
  7392. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  7393. var index = _a[_i];
  7394. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  7395. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  7396. }
  7397. };
  7398. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  7399. var babylonBone = babylonBones[node.index];
  7400. if (babylonBone) {
  7401. return babylonBone;
  7402. }
  7403. var babylonParentBone = null;
  7404. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  7405. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  7406. }
  7407. var boneIndex = skin.joints.indexOf(node.index);
  7408. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  7409. babylonBones[node.index] = babylonBone;
  7410. node._babylonBones = node._babylonBones || [];
  7411. node._babylonBones.push(babylonBone);
  7412. return babylonBone;
  7413. };
  7414. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  7415. if (skin.inverseBindMatrices == undefined) {
  7416. return Promise.resolve(null);
  7417. }
  7418. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  7419. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  7420. };
  7421. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  7422. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  7423. var babylonBone = _a[_i];
  7424. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  7425. var boneIndex = babylonBone._index;
  7426. if (inverseBindMatricesData && boneIndex !== -1) {
  7427. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  7428. baseMatrix.invertToRef(baseMatrix);
  7429. }
  7430. var babylonParentBone = babylonBone.getParent();
  7431. if (babylonParentBone) {
  7432. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  7433. }
  7434. babylonBone.setBindPose(baseMatrix);
  7435. babylonBone.updateMatrix(baseMatrix, false, false);
  7436. babylonBone._updateDifferenceMatrix(undefined, false);
  7437. }
  7438. };
  7439. GLTFLoader.prototype._getNodeMatrix = function (node) {
  7440. return node.matrix ?
  7441. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  7442. 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());
  7443. };
  7444. /**
  7445. * Loads a glTF camera.
  7446. * @param context The context when loading the asset
  7447. * @param camera The glTF camera property
  7448. * @param assign A function called synchronously after parsing the glTF properties
  7449. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  7450. */
  7451. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  7452. if (assign === void 0) { assign = function () { }; }
  7453. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  7454. if (extensionPromise) {
  7455. return extensionPromise;
  7456. }
  7457. var promises = new Array();
  7458. this.logOpen(context + " " + (camera.name || ""));
  7459. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7460. 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);
  7461. this._babylonScene._blockEntityCollection = false;
  7462. babylonCamera.ignoreParentScaling = true;
  7463. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  7464. switch (camera.type) {
  7465. case "perspective" /* PERSPECTIVE */: {
  7466. var perspective = camera.perspective;
  7467. if (!perspective) {
  7468. throw new Error(context + ": Camera perspective properties are missing");
  7469. }
  7470. babylonCamera.fov = perspective.yfov;
  7471. babylonCamera.minZ = perspective.znear;
  7472. babylonCamera.maxZ = perspective.zfar || 0;
  7473. break;
  7474. }
  7475. case "orthographic" /* ORTHOGRAPHIC */: {
  7476. if (!camera.orthographic) {
  7477. throw new Error(context + ": Camera orthographic properties are missing");
  7478. }
  7479. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  7480. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  7481. babylonCamera.orthoRight = camera.orthographic.xmag;
  7482. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  7483. babylonCamera.orthoTop = camera.orthographic.ymag;
  7484. babylonCamera.minZ = camera.orthographic.znear;
  7485. babylonCamera.maxZ = camera.orthographic.zfar;
  7486. break;
  7487. }
  7488. default: {
  7489. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  7490. }
  7491. }
  7492. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  7493. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  7494. assign(babylonCamera);
  7495. this.logClose();
  7496. return Promise.all(promises).then(function () {
  7497. return babylonCamera;
  7498. });
  7499. };
  7500. GLTFLoader.prototype._loadAnimationsAsync = function () {
  7501. var animations = this._gltf.animations;
  7502. if (!animations) {
  7503. return Promise.resolve();
  7504. }
  7505. var promises = new Array();
  7506. for (var index = 0; index < animations.length; index++) {
  7507. var animation = animations[index];
  7508. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation).then(function (animationGroup) {
  7509. // Delete the animation group if it ended up not having any animations in it.
  7510. if (animationGroup.targetedAnimations.length === 0) {
  7511. animationGroup.dispose();
  7512. }
  7513. }));
  7514. }
  7515. return Promise.all(promises).then(function () { });
  7516. };
  7517. /**
  7518. * Loads a glTF animation.
  7519. * @param context The context when loading the asset
  7520. * @param animation The glTF animation property
  7521. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  7522. */
  7523. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  7524. var promise = this._extensionsLoadAnimationAsync(context, animation);
  7525. if (promise) {
  7526. return promise;
  7527. }
  7528. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7529. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  7530. this._babylonScene._blockEntityCollection = false;
  7531. animation._babylonAnimationGroup = babylonAnimationGroup;
  7532. var promises = new Array();
  7533. ArrayItem.Assign(animation.channels);
  7534. ArrayItem.Assign(animation.samplers);
  7535. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  7536. var channel = _a[_i];
  7537. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  7538. }
  7539. return Promise.all(promises).then(function () {
  7540. babylonAnimationGroup.normalize(0);
  7541. return babylonAnimationGroup;
  7542. });
  7543. };
  7544. /**
  7545. * @hidden Loads a glTF animation channel.
  7546. * @param context The context when loading the asset
  7547. * @param animationContext The context of the animation when loading the asset
  7548. * @param animation The glTF animation property
  7549. * @param channel The glTF animation channel property
  7550. * @param babylonAnimationGroup The babylon animation group property
  7551. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  7552. * @returns A void promise when the channel load is complete
  7553. */
  7554. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  7555. var _this = this;
  7556. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  7557. if (channel.target.node == undefined) {
  7558. return Promise.resolve();
  7559. }
  7560. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  7561. // Ignore animations that have no animation targets.
  7562. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  7563. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  7564. return Promise.resolve();
  7565. }
  7566. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  7567. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  7568. var targetPath;
  7569. var animationType;
  7570. switch (channel.target.path) {
  7571. case "translation" /* TRANSLATION */: {
  7572. targetPath = "position";
  7573. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  7574. break;
  7575. }
  7576. case "rotation" /* ROTATION */: {
  7577. targetPath = "rotationQuaternion";
  7578. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  7579. break;
  7580. }
  7581. case "scale" /* SCALE */: {
  7582. targetPath = "scaling";
  7583. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  7584. break;
  7585. }
  7586. case "weights" /* WEIGHTS */: {
  7587. targetPath = "influence";
  7588. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  7589. break;
  7590. }
  7591. default: {
  7592. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  7593. }
  7594. }
  7595. var outputBufferOffset = 0;
  7596. var getNextOutputValue;
  7597. switch (targetPath) {
  7598. case "position": {
  7599. getNextOutputValue = function () {
  7600. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7601. outputBufferOffset += 3;
  7602. return value;
  7603. };
  7604. break;
  7605. }
  7606. case "rotationQuaternion": {
  7607. getNextOutputValue = function () {
  7608. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  7609. outputBufferOffset += 4;
  7610. return value;
  7611. };
  7612. break;
  7613. }
  7614. case "scaling": {
  7615. getNextOutputValue = function () {
  7616. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7617. outputBufferOffset += 3;
  7618. return value;
  7619. };
  7620. break;
  7621. }
  7622. case "influence": {
  7623. getNextOutputValue = function () {
  7624. var value = new Array(targetNode._numMorphTargets);
  7625. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  7626. value[i] = data.output[outputBufferOffset++];
  7627. }
  7628. return value;
  7629. };
  7630. break;
  7631. }
  7632. }
  7633. var getNextKey;
  7634. switch (data.interpolation) {
  7635. case "STEP" /* STEP */: {
  7636. getNextKey = function (frameIndex) { return ({
  7637. frame: data.input[frameIndex],
  7638. value: getNextOutputValue(),
  7639. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  7640. }); };
  7641. break;
  7642. }
  7643. case "LINEAR" /* LINEAR */: {
  7644. getNextKey = function (frameIndex) { return ({
  7645. frame: data.input[frameIndex],
  7646. value: getNextOutputValue()
  7647. }); };
  7648. break;
  7649. }
  7650. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7651. getNextKey = function (frameIndex) { return ({
  7652. frame: data.input[frameIndex],
  7653. inTangent: getNextOutputValue(),
  7654. value: getNextOutputValue(),
  7655. outTangent: getNextOutputValue()
  7656. }); };
  7657. break;
  7658. }
  7659. }
  7660. var keys = new Array(data.input.length);
  7661. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  7662. keys[frameIndex] = getNextKey(frameIndex);
  7663. }
  7664. if (targetPath === "influence") {
  7665. var _loop_2 = function (targetIndex) {
  7666. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7667. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7668. babylonAnimation.setKeys(keys.map(function (key) { return ({
  7669. frame: key.frame,
  7670. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  7671. value: key.value[targetIndex],
  7672. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  7673. }); }));
  7674. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  7675. var babylonMesh = babylonAbstractMesh;
  7676. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  7677. var babylonAnimationClone = babylonAnimation.clone();
  7678. morphTarget.animations.push(babylonAnimationClone);
  7679. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  7680. });
  7681. };
  7682. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  7683. _loop_2(targetIndex);
  7684. }
  7685. }
  7686. else {
  7687. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7688. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7689. babylonAnimation.setKeys(keys);
  7690. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  7691. animationTargetOverride.animations.push(babylonAnimation);
  7692. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  7693. }
  7694. else {
  7695. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  7696. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  7697. }
  7698. }
  7699. });
  7700. };
  7701. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  7702. if (sampler._data) {
  7703. return sampler._data;
  7704. }
  7705. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  7706. switch (interpolation) {
  7707. case "STEP" /* STEP */:
  7708. case "LINEAR" /* LINEAR */:
  7709. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7710. break;
  7711. }
  7712. default: {
  7713. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  7714. }
  7715. }
  7716. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  7717. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  7718. sampler._data = Promise.all([
  7719. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  7720. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  7721. ]).then(function (_a) {
  7722. var inputData = _a[0], outputData = _a[1];
  7723. return {
  7724. input: inputData,
  7725. interpolation: interpolation,
  7726. output: outputData,
  7727. };
  7728. });
  7729. return sampler._data;
  7730. };
  7731. /**
  7732. * Loads a glTF buffer.
  7733. * @param context The context when loading the asset
  7734. * @param buffer The glTF buffer property
  7735. * @param byteOffset The byte offset to use
  7736. * @param byteLength The byte length to use
  7737. * @returns A promise that resolves with the loaded data when the load is complete
  7738. */
  7739. GLTFLoader.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7740. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  7741. if (extensionPromise) {
  7742. return extensionPromise;
  7743. }
  7744. if (!buffer._data) {
  7745. if (buffer.uri) {
  7746. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  7747. }
  7748. else {
  7749. if (!this._bin) {
  7750. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  7751. }
  7752. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  7753. }
  7754. }
  7755. return buffer._data.then(function (data) {
  7756. try {
  7757. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  7758. }
  7759. catch (e) {
  7760. throw new Error(context + ": " + e.message);
  7761. }
  7762. });
  7763. };
  7764. /**
  7765. * Loads a glTF buffer view.
  7766. * @param context The context when loading the asset
  7767. * @param bufferView The glTF buffer view property
  7768. * @returns A promise that resolves with the loaded data when the load is complete
  7769. */
  7770. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  7771. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  7772. if (extensionPromise) {
  7773. return extensionPromise;
  7774. }
  7775. if (bufferView._data) {
  7776. return bufferView._data;
  7777. }
  7778. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  7779. bufferView._data = this.loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  7780. return bufferView._data;
  7781. };
  7782. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  7783. var _this = this;
  7784. if (accessor._data) {
  7785. return accessor._data;
  7786. }
  7787. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  7788. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  7789. var length = numComponents * accessor.count;
  7790. if (accessor.bufferView == undefined) {
  7791. accessor._data = Promise.resolve(new constructor(length));
  7792. }
  7793. else {
  7794. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7795. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  7796. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized && (!bufferView_1.byteStride || bufferView_1.byteStride === byteStride)) {
  7797. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  7798. }
  7799. else {
  7800. var typedArray_1 = new constructor(length);
  7801. 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) {
  7802. typedArray_1[index] = value;
  7803. });
  7804. return typedArray_1;
  7805. }
  7806. });
  7807. }
  7808. if (accessor.sparse) {
  7809. var sparse_1 = accessor.sparse;
  7810. accessor._data = accessor._data.then(function (data) {
  7811. var typedArray = data;
  7812. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  7813. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  7814. return Promise.all([
  7815. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  7816. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  7817. ]).then(function (_a) {
  7818. var indicesData = _a[0], valuesData = _a[1];
  7819. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  7820. var sparseLength = numComponents * sparse_1.count;
  7821. var values;
  7822. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  7823. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7824. }
  7825. else {
  7826. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7827. values = new constructor(sparseLength);
  7828. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  7829. values[index] = value;
  7830. });
  7831. }
  7832. var valuesIndex = 0;
  7833. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  7834. var dataIndex = indices[indicesIndex] * numComponents;
  7835. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  7836. typedArray[dataIndex++] = values[valuesIndex++];
  7837. }
  7838. }
  7839. return typedArray;
  7840. });
  7841. });
  7842. }
  7843. return accessor._data;
  7844. };
  7845. /** @hidden */
  7846. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  7847. return this._loadAccessorAsync(context, accessor, Float32Array);
  7848. };
  7849. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  7850. if (accessor.type !== "SCALAR" /* SCALAR */) {
  7851. throw new Error(context + "/type: Invalid value " + accessor.type);
  7852. }
  7853. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  7854. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  7855. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  7856. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  7857. }
  7858. if (accessor._data) {
  7859. return accessor._data;
  7860. }
  7861. if (accessor.sparse) {
  7862. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  7863. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  7864. }
  7865. else {
  7866. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7867. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7868. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  7869. });
  7870. }
  7871. return accessor._data;
  7872. };
  7873. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  7874. var _this = this;
  7875. if (bufferView._babylonBuffer) {
  7876. return bufferView._babylonBuffer;
  7877. }
  7878. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7879. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  7880. });
  7881. return bufferView._babylonBuffer;
  7882. };
  7883. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  7884. var _this = this;
  7885. if (accessor._babylonVertexBuffer) {
  7886. return accessor._babylonVertexBuffer;
  7887. }
  7888. if (accessor.sparse) {
  7889. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7890. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7891. });
  7892. }
  7893. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  7894. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  7895. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  7896. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7897. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7898. });
  7899. }
  7900. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  7901. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  7902. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  7903. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7904. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7905. });
  7906. }
  7907. else {
  7908. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7909. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  7910. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  7911. 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, 1, true);
  7912. });
  7913. }
  7914. return accessor._babylonVertexBuffer;
  7915. };
  7916. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  7917. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7918. throw new Error(context + ": Material type not supported");
  7919. }
  7920. var promises = new Array();
  7921. if (properties) {
  7922. if (properties.baseColorFactor) {
  7923. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  7924. babylonMaterial.alpha = properties.baseColorFactor[3];
  7925. }
  7926. else {
  7927. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  7928. }
  7929. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  7930. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  7931. if (properties.baseColorTexture) {
  7932. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  7933. texture.name = babylonMaterial.name + " (Base Color)";
  7934. babylonMaterial.albedoTexture = texture;
  7935. }));
  7936. }
  7937. if (properties.metallicRoughnessTexture) {
  7938. properties.metallicRoughnessTexture.nonColorData = true;
  7939. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  7940. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  7941. babylonMaterial.metallicTexture = texture;
  7942. }));
  7943. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  7944. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  7945. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  7946. }
  7947. }
  7948. return Promise.all(promises).then(function () { });
  7949. };
  7950. /** @hidden */
  7951. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7952. if (assign === void 0) { assign = function () { }; }
  7953. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  7954. if (extensionPromise) {
  7955. return extensionPromise;
  7956. }
  7957. material._data = material._data || {};
  7958. var babylonData = material._data[babylonDrawMode];
  7959. if (!babylonData) {
  7960. this.logOpen(context + " " + (material.name || ""));
  7961. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  7962. babylonData = {
  7963. babylonMaterial: babylonMaterial,
  7964. babylonMeshes: [],
  7965. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  7966. };
  7967. material._data[babylonDrawMode] = babylonData;
  7968. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  7969. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7970. this.logClose();
  7971. }
  7972. if (babylonMesh) {
  7973. babylonData.babylonMeshes.push(babylonMesh);
  7974. babylonMesh.onDisposeObservable.addOnce(function () {
  7975. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  7976. if (index !== -1) {
  7977. babylonData.babylonMeshes.splice(index, 1);
  7978. }
  7979. });
  7980. }
  7981. assign(babylonData.babylonMaterial);
  7982. return babylonData.promise.then(function () {
  7983. return babylonData.babylonMaterial;
  7984. });
  7985. };
  7986. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  7987. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7988. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  7989. this._babylonScene._blockEntityCollection = false;
  7990. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  7991. babylonMaterial.fillMode = babylonDrawMode;
  7992. babylonMaterial.enableSpecularAntiAliasing = true;
  7993. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  7994. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  7995. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7996. babylonMaterial.metallic = 1;
  7997. babylonMaterial.roughness = 1;
  7998. return babylonMaterial;
  7999. };
  8000. /**
  8001. * Creates a Babylon material from a glTF material.
  8002. * @param context The context when loading the asset
  8003. * @param material The glTF material property
  8004. * @param babylonDrawMode The draw mode for the Babylon material
  8005. * @returns The Babylon material
  8006. */
  8007. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  8008. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  8009. if (extensionPromise) {
  8010. return extensionPromise;
  8011. }
  8012. var name = material.name || "material" + material.index;
  8013. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  8014. return babylonMaterial;
  8015. };
  8016. /**
  8017. * Loads properties from a glTF material into a Babylon material.
  8018. * @param context The context when loading the asset
  8019. * @param material The glTF material property
  8020. * @param babylonMaterial The Babylon material
  8021. * @returns A promise that resolves when the load is complete
  8022. */
  8023. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  8024. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  8025. if (extensionPromise) {
  8026. return extensionPromise;
  8027. }
  8028. var promises = new Array();
  8029. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  8030. if (material.pbrMetallicRoughness) {
  8031. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  8032. }
  8033. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  8034. return Promise.all(promises).then(function () { });
  8035. };
  8036. /**
  8037. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  8038. * @param context The context when loading the asset
  8039. * @param material The glTF material property
  8040. * @param babylonMaterial The Babylon material
  8041. * @returns A promise that resolves when the load is complete
  8042. */
  8043. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  8044. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  8045. throw new Error(context + ": Material type not supported");
  8046. }
  8047. var promises = new Array();
  8048. 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);
  8049. if (material.doubleSided) {
  8050. babylonMaterial.backFaceCulling = false;
  8051. babylonMaterial.twoSidedLighting = true;
  8052. }
  8053. if (material.normalTexture) {
  8054. material.normalTexture.nonColorData = true;
  8055. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  8056. texture.name = babylonMaterial.name + " (Normal)";
  8057. babylonMaterial.bumpTexture = texture;
  8058. }));
  8059. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  8060. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  8061. if (material.normalTexture.scale != undefined) {
  8062. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  8063. }
  8064. babylonMaterial.forceIrradianceInFragment = true;
  8065. }
  8066. if (material.occlusionTexture) {
  8067. material.occlusionTexture.nonColorData = true;
  8068. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  8069. texture.name = babylonMaterial.name + " (Occlusion)";
  8070. babylonMaterial.ambientTexture = texture;
  8071. }));
  8072. babylonMaterial.useAmbientInGrayScale = true;
  8073. if (material.occlusionTexture.strength != undefined) {
  8074. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  8075. }
  8076. }
  8077. if (material.emissiveTexture) {
  8078. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  8079. texture.name = babylonMaterial.name + " (Emissive)";
  8080. babylonMaterial.emissiveTexture = texture;
  8081. }));
  8082. }
  8083. return Promise.all(promises).then(function () { });
  8084. };
  8085. /**
  8086. * Loads the alpha properties from a glTF material into a Babylon material.
  8087. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  8088. * @param context The context when loading the asset
  8089. * @param material The glTF material property
  8090. * @param babylonMaterial The Babylon material
  8091. */
  8092. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  8093. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  8094. throw new Error(context + ": Material type not supported");
  8095. }
  8096. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  8097. switch (alphaMode) {
  8098. case "OPAQUE" /* OPAQUE */: {
  8099. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  8100. break;
  8101. }
  8102. case "MASK" /* MASK */: {
  8103. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  8104. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  8105. if (babylonMaterial.albedoTexture) {
  8106. babylonMaterial.albedoTexture.hasAlpha = true;
  8107. }
  8108. break;
  8109. }
  8110. case "BLEND" /* BLEND */: {
  8111. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  8112. if (babylonMaterial.albedoTexture) {
  8113. babylonMaterial.albedoTexture.hasAlpha = true;
  8114. babylonMaterial.useAlphaFromAlbedoTexture = true;
  8115. }
  8116. break;
  8117. }
  8118. default: {
  8119. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  8120. }
  8121. }
  8122. };
  8123. /**
  8124. * Loads a glTF texture info.
  8125. * @param context The context when loading the asset
  8126. * @param textureInfo The glTF texture info property
  8127. * @param assign A function called synchronously after parsing the glTF properties
  8128. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  8129. */
  8130. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  8131. var _this = this;
  8132. if (assign === void 0) { assign = function () { }; }
  8133. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  8134. if (extensionPromise) {
  8135. return extensionPromise;
  8136. }
  8137. this.logOpen("" + context);
  8138. if (textureInfo.texCoord >= 2) {
  8139. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  8140. }
  8141. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  8142. texture._textureInfo = textureInfo;
  8143. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  8144. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  8145. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  8146. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  8147. assign(babylonTexture);
  8148. });
  8149. this.logClose();
  8150. return promise;
  8151. };
  8152. /** @hidden */
  8153. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  8154. if (assign === void 0) { assign = function () { }; }
  8155. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  8156. if (extensionPromise) {
  8157. return extensionPromise;
  8158. }
  8159. this.logOpen(context + " " + (texture.name || ""));
  8160. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  8161. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  8162. var promise = this._createTextureAsync(context, sampler, image, assign);
  8163. this.logClose();
  8164. return promise;
  8165. };
  8166. /** @hidden */
  8167. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions) {
  8168. var _this = this;
  8169. if (assign === void 0) { assign = function () { }; }
  8170. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  8171. var promises = new Array();
  8172. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  8173. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  8174. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  8175. if (!_this._disposed) {
  8176. deferred.resolve();
  8177. }
  8178. }, function (message, exception) {
  8179. if (!_this._disposed) {
  8180. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  8181. }
  8182. }, undefined, undefined, undefined, image.mimeType, textureLoaderOptions);
  8183. this._babylonScene._blockEntityCollection = false;
  8184. promises.push(deferred.promise);
  8185. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  8186. var name = image.uri || _this._fileName + "#image" + image.index;
  8187. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  8188. babylonTexture.updateURL(dataUrl, data);
  8189. }));
  8190. babylonTexture.wrapU = samplerData.wrapU;
  8191. babylonTexture.wrapV = samplerData.wrapV;
  8192. assign(babylonTexture);
  8193. return Promise.all(promises).then(function () {
  8194. return babylonTexture;
  8195. });
  8196. };
  8197. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  8198. if (!sampler._data) {
  8199. sampler._data = {
  8200. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  8201. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  8202. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  8203. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  8204. };
  8205. }
  8206. return sampler._data;
  8207. };
  8208. /**
  8209. * Loads a glTF image.
  8210. * @param context The context when loading the asset
  8211. * @param image The glTF image property
  8212. * @returns A promise that resolves with the loaded data when the load is complete
  8213. */
  8214. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  8215. if (!image._data) {
  8216. this.logOpen(context + " " + (image.name || ""));
  8217. if (image.uri) {
  8218. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  8219. }
  8220. else {
  8221. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  8222. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  8223. }
  8224. this.logClose();
  8225. }
  8226. return image._data;
  8227. };
  8228. /**
  8229. * Loads a glTF uri.
  8230. * @param context The context when loading the asset
  8231. * @param property The glTF property associated with the uri
  8232. * @param uri The base64 or relative uri
  8233. * @returns A promise that resolves with the loaded data when the load is complete
  8234. */
  8235. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  8236. var _this = this;
  8237. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  8238. if (extensionPromise) {
  8239. return extensionPromise;
  8240. }
  8241. if (!GLTFLoader._ValidateUri(uri)) {
  8242. throw new Error(context + ": '" + uri + "' is invalid");
  8243. }
  8244. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  8245. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  8246. this.log(context + ": Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  8247. return Promise.resolve(data);
  8248. }
  8249. this.log(context + ": Loading " + uri);
  8250. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  8251. return new Promise(function (resolve, reject) {
  8252. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  8253. if (!_this._disposed) {
  8254. _this.log(context + ": Loaded " + uri + " (" + data.byteLength + " bytes)");
  8255. resolve(new Uint8Array(data));
  8256. }
  8257. }, true, function (request) {
  8258. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  8259. });
  8260. });
  8261. });
  8262. };
  8263. /**
  8264. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  8265. * @param babylonObject the Babylon object with metadata
  8266. * @param pointer the JSON pointer
  8267. */
  8268. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  8269. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  8270. var gltf = (metadata.gltf = metadata.gltf || {});
  8271. var pointers = (gltf.pointers = gltf.pointers || []);
  8272. pointers.push(pointer);
  8273. };
  8274. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  8275. // Set defaults if undefined
  8276. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  8277. switch (mode) {
  8278. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  8279. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  8280. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  8281. default:
  8282. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  8283. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  8284. }
  8285. };
  8286. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  8287. // Set defaults if undefined
  8288. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  8289. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  8290. if (magFilter === 9729 /* LINEAR */) {
  8291. switch (minFilter) {
  8292. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  8293. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  8294. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  8295. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  8296. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  8297. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  8298. default:
  8299. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  8300. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  8301. }
  8302. }
  8303. else {
  8304. if (magFilter !== 9728 /* NEAREST */) {
  8305. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  8306. }
  8307. switch (minFilter) {
  8308. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  8309. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  8310. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  8311. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  8312. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  8313. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  8314. default:
  8315. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  8316. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  8317. }
  8318. }
  8319. };
  8320. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  8321. switch (componentType) {
  8322. case 5120 /* BYTE */: return Int8Array;
  8323. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  8324. case 5122 /* SHORT */: return Int16Array;
  8325. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  8326. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  8327. case 5126 /* FLOAT */: return Float32Array;
  8328. default: throw new Error(context + ": Invalid component type " + componentType);
  8329. }
  8330. };
  8331. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  8332. var buffer = bufferView.buffer;
  8333. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  8334. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  8335. try {
  8336. return new constructor(buffer, byteOffset, length);
  8337. }
  8338. catch (e) {
  8339. throw new Error(context + ": " + e);
  8340. }
  8341. };
  8342. GLTFLoader._GetNumComponents = function (context, type) {
  8343. switch (type) {
  8344. case "SCALAR": return 1;
  8345. case "VEC2": return 2;
  8346. case "VEC3": return 3;
  8347. case "VEC4": return 4;
  8348. case "MAT2": return 4;
  8349. case "MAT3": return 9;
  8350. case "MAT4": return 16;
  8351. }
  8352. throw new Error(context + ": Invalid type (" + type + ")");
  8353. };
  8354. GLTFLoader._ValidateUri = function (uri) {
  8355. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  8356. };
  8357. /** @hidden */
  8358. GLTFLoader._GetDrawMode = function (context, mode) {
  8359. if (mode == undefined) {
  8360. mode = 4 /* TRIANGLES */;
  8361. }
  8362. switch (mode) {
  8363. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  8364. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  8365. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  8366. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  8367. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  8368. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  8369. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  8370. }
  8371. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  8372. };
  8373. GLTFLoader.prototype._compileMaterialsAsync = function () {
  8374. var _this = this;
  8375. this._parent._startPerformanceCounter("Compile materials");
  8376. var promises = new Array();
  8377. if (this._gltf.materials) {
  8378. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  8379. var material = _a[_i];
  8380. if (material._data) {
  8381. for (var babylonDrawMode in material._data) {
  8382. var babylonData = material._data[babylonDrawMode];
  8383. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  8384. var babylonMesh = _c[_b];
  8385. // Ensure nonUniformScaling is set if necessary.
  8386. babylonMesh.computeWorldMatrix(true);
  8387. var babylonMaterial = babylonData.babylonMaterial;
  8388. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  8389. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  8390. if (this._parent.useClipPlane) {
  8391. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  8392. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  8393. }
  8394. }
  8395. }
  8396. }
  8397. }
  8398. }
  8399. return Promise.all(promises).then(function () {
  8400. _this._parent._endPerformanceCounter("Compile materials");
  8401. });
  8402. };
  8403. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  8404. var _this = this;
  8405. this._parent._startPerformanceCounter("Compile shadow generators");
  8406. var promises = new Array();
  8407. var lights = this._babylonScene.lights;
  8408. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  8409. var light = lights_1[_i];
  8410. var generator = light.getShadowGenerator();
  8411. if (generator) {
  8412. promises.push(generator.forceCompilationAsync());
  8413. }
  8414. }
  8415. return Promise.all(promises).then(function () {
  8416. _this._parent._endPerformanceCounter("Compile shadow generators");
  8417. });
  8418. };
  8419. GLTFLoader.prototype._forEachExtensions = function (action) {
  8420. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  8421. var extension = _a[_i];
  8422. if (extension.enabled) {
  8423. action(extension);
  8424. }
  8425. }
  8426. };
  8427. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  8428. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  8429. var extension = _a[_i];
  8430. if (extension.enabled) {
  8431. var id = extension.name + "." + functionName;
  8432. var loaderProperty = property;
  8433. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  8434. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  8435. if (!activeLoaderExtensionFunctions[id]) {
  8436. activeLoaderExtensionFunctions[id] = true;
  8437. try {
  8438. var result = actionAsync(extension);
  8439. if (result) {
  8440. return result;
  8441. }
  8442. }
  8443. finally {
  8444. delete activeLoaderExtensionFunctions[id];
  8445. }
  8446. }
  8447. }
  8448. }
  8449. return null;
  8450. };
  8451. GLTFLoader.prototype._extensionsOnLoading = function () {
  8452. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  8453. };
  8454. GLTFLoader.prototype._extensionsOnReady = function () {
  8455. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  8456. };
  8457. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  8458. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  8459. };
  8460. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  8461. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  8462. };
  8463. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  8464. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  8465. };
  8466. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  8467. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  8468. };
  8469. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  8470. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  8471. };
  8472. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  8473. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  8474. };
  8475. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  8476. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  8477. };
  8478. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  8479. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  8480. };
  8481. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  8482. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  8483. };
  8484. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  8485. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  8486. };
  8487. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  8488. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  8489. };
  8490. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  8491. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  8492. };
  8493. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  8494. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  8495. };
  8496. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  8497. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  8498. };
  8499. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  8500. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  8501. };
  8502. /**
  8503. * Helper method called by a loader extension to load an glTF extension.
  8504. * @param context The context when loading the asset
  8505. * @param property The glTF property to load the extension from
  8506. * @param extensionName The name of the extension to load
  8507. * @param actionAsync The action to run
  8508. * @returns The promise returned by actionAsync or null if the extension does not exist
  8509. */
  8510. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  8511. if (!property.extensions) {
  8512. return null;
  8513. }
  8514. var extensions = property.extensions;
  8515. var extension = extensions[extensionName];
  8516. if (!extension) {
  8517. return null;
  8518. }
  8519. return actionAsync(context + "/extensions/" + extensionName, extension);
  8520. };
  8521. /**
  8522. * Helper method called by a loader extension to load a glTF extra.
  8523. * @param context The context when loading the asset
  8524. * @param property The glTF property to load the extra from
  8525. * @param extensionName The name of the extension to load
  8526. * @param actionAsync The action to run
  8527. * @returns The promise returned by actionAsync or null if the extra does not exist
  8528. */
  8529. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  8530. if (!property.extras) {
  8531. return null;
  8532. }
  8533. var extras = property.extras;
  8534. var extra = extras[extensionName];
  8535. if (!extra) {
  8536. return null;
  8537. }
  8538. return actionAsync(context + "/extras/" + extensionName, extra);
  8539. };
  8540. /**
  8541. * Checks for presence of an extension.
  8542. * @param name The name of the extension to check
  8543. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  8544. */
  8545. GLTFLoader.prototype.isExtensionUsed = function (name) {
  8546. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  8547. };
  8548. /**
  8549. * Increments the indentation level and logs a message.
  8550. * @param message The message to log
  8551. */
  8552. GLTFLoader.prototype.logOpen = function (message) {
  8553. this._parent._logOpen(message);
  8554. };
  8555. /**
  8556. * Decrements the indentation level.
  8557. */
  8558. GLTFLoader.prototype.logClose = function () {
  8559. this._parent._logClose();
  8560. };
  8561. /**
  8562. * Logs a message
  8563. * @param message The message to log
  8564. */
  8565. GLTFLoader.prototype.log = function (message) {
  8566. this._parent._log(message);
  8567. };
  8568. /**
  8569. * Starts a performance counter.
  8570. * @param counterName The name of the performance counter
  8571. */
  8572. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  8573. this._parent._startPerformanceCounter(counterName);
  8574. };
  8575. /**
  8576. * Ends a performance counter.
  8577. * @param counterName The name of the performance counter
  8578. */
  8579. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  8580. this._parent._endPerformanceCounter(counterName);
  8581. };
  8582. GLTFLoader._RegisteredExtensions = {};
  8583. /**
  8584. * The default glTF sampler.
  8585. */
  8586. GLTFLoader.DefaultSampler = { index: -1 };
  8587. return GLTFLoader;
  8588. }());
  8589. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  8590. /***/ }),
  8591. /***/ "./glTF/2.0/glTFLoaderExtension.ts":
  8592. /*!*****************************************!*\
  8593. !*** ./glTF/2.0/glTFLoaderExtension.ts ***!
  8594. \*****************************************/
  8595. /*! no exports provided */
  8596. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8597. "use strict";
  8598. __webpack_require__.r(__webpack_exports__);
  8599. /***/ }),
  8600. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  8601. /*!******************************************!*\
  8602. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  8603. \******************************************/
  8604. /*! no exports provided */
  8605. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8606. "use strict";
  8607. __webpack_require__.r(__webpack_exports__);
  8608. /***/ }),
  8609. /***/ "./glTF/2.0/index.ts":
  8610. /*!***************************!*\
  8611. !*** ./glTF/2.0/index.ts ***!
  8612. \***************************/
  8613. /*! exports provided: ArrayItem, GLTFLoader, EXT_lights_image_based, EXT_mesh_gpu_instancing, EXT_meshopt_compression, EXT_texture_webp, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_materials_translucency, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp_json_ld, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  8614. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8615. "use strict";
  8616. __webpack_require__.r(__webpack_exports__);
  8617. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  8618. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  8619. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  8620. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoaderExtension */ "./glTF/2.0/glTFLoaderExtension.ts");
  8621. /* empty/unused harmony star reexport *//* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8622. /* empty/unused harmony star reexport *//* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  8623. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_lights_image_based"]; });
  8624. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_mesh_gpu_instancing"]; });
  8625. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_meshopt_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_meshopt_compression"]; });
  8626. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_texture_webp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_texture_webp"]; });
  8627. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_draco_mesh_compression"]; });
  8628. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  8629. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  8630. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_unlit"]; });
  8631. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_clearcoat"]; });
  8632. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_sheen"]; });
  8633. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_specular"]; });
  8634. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_ior"]; });
  8635. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_variants"]; });
  8636. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_transmission"]; });
  8637. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_translucency", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_translucency"]; });
  8638. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_mesh_quantization"]; });
  8639. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_basisu"]; });
  8640. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_transform"]; });
  8641. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp_json_ld", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_xmp_json_ld"]; });
  8642. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_audio_emitter"]; });
  8643. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_lod"]; });
  8644. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_minecraftMesh"]; });
  8645. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_sRGBFactors"]; });
  8646. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["ExtrasAsMetadata"]; });
  8647. /***/ }),
  8648. /***/ "./glTF/glTFFileLoader.ts":
  8649. /*!********************************!*\
  8650. !*** ./glTF/glTFFileLoader.ts ***!
  8651. \********************************/
  8652. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  8653. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8654. "use strict";
  8655. __webpack_require__.r(__webpack_exports__);
  8656. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  8657. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  8658. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  8659. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  8660. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  8661. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  8662. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8663. /**
  8664. * Mode that determines the coordinate system to use.
  8665. */
  8666. var GLTFLoaderCoordinateSystemMode;
  8667. (function (GLTFLoaderCoordinateSystemMode) {
  8668. /**
  8669. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8670. */
  8671. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  8672. /**
  8673. * Sets the useRightHandedSystem flag on the scene.
  8674. */
  8675. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  8676. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  8677. /**
  8678. * Mode that determines what animations will start.
  8679. */
  8680. var GLTFLoaderAnimationStartMode;
  8681. (function (GLTFLoaderAnimationStartMode) {
  8682. /**
  8683. * No animation will start.
  8684. */
  8685. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  8686. /**
  8687. * The first animation will start.
  8688. */
  8689. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  8690. /**
  8691. * All animations will start.
  8692. */
  8693. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  8694. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  8695. /**
  8696. * Loader state.
  8697. */
  8698. var GLTFLoaderState;
  8699. (function (GLTFLoaderState) {
  8700. /**
  8701. * The asset is loading.
  8702. */
  8703. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  8704. /**
  8705. * The asset is ready for rendering.
  8706. */
  8707. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  8708. /**
  8709. * The asset is completely loaded.
  8710. */
  8711. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  8712. })(GLTFLoaderState || (GLTFLoaderState = {}));
  8713. /**
  8714. * File loader for loading glTF files into a scene.
  8715. */
  8716. var GLTFFileLoader = /** @class */ (function () {
  8717. function GLTFFileLoader() {
  8718. // --------------
  8719. // Common options
  8720. // --------------
  8721. /**
  8722. * Raised when the asset has been parsed
  8723. */
  8724. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8725. // ----------
  8726. // V2 options
  8727. // ----------
  8728. /**
  8729. * The coordinate system mode. Defaults to AUTO.
  8730. */
  8731. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  8732. /**
  8733. * The animation start mode. Defaults to FIRST.
  8734. */
  8735. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  8736. /**
  8737. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  8738. */
  8739. this.compileMaterials = false;
  8740. /**
  8741. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  8742. */
  8743. this.useClipPlane = false;
  8744. /**
  8745. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  8746. */
  8747. this.compileShadowGenerators = false;
  8748. /**
  8749. * Defines if the Alpha blended materials are only applied as coverage.
  8750. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  8751. * If true, no extra effects are applied to transparent pixels.
  8752. */
  8753. this.transparencyAsCoverage = false;
  8754. /**
  8755. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  8756. * Enabling will disable offline support and glTF validator.
  8757. * Defaults to false.
  8758. */
  8759. this.useRangeRequests = false;
  8760. /**
  8761. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  8762. */
  8763. this.createInstances = true;
  8764. /**
  8765. * Defines if the loader should always compute the bounding boxes of meshes and not use the min/max values from the position accessor. Defaults to false.
  8766. */
  8767. this.alwaysComputeBoundingBox = false;
  8768. /**
  8769. * If true, load all materials defined in the file, even if not used by any mesh. Defaults to false.
  8770. */
  8771. this.loadAllMaterials = false;
  8772. /**
  8773. * Function called before loading a url referenced by the asset.
  8774. */
  8775. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8776. /**
  8777. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8778. * Note that the observable is raised as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
  8779. */
  8780. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8781. /**
  8782. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  8783. */
  8784. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8785. /**
  8786. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  8787. */
  8788. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8789. /**
  8790. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  8791. */
  8792. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8793. /**
  8794. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  8795. * For assets with LODs, raised when all of the LODs are complete.
  8796. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8797. */
  8798. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8799. /**
  8800. * Observable raised when an error occurs.
  8801. */
  8802. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8803. /**
  8804. * Observable raised after the loader is disposed.
  8805. */
  8806. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8807. /**
  8808. * Observable raised after a loader extension is created.
  8809. * Set additional options for a loader extension in this event.
  8810. */
  8811. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8812. /**
  8813. * Defines if the loader should validate the asset.
  8814. */
  8815. this.validate = false;
  8816. /**
  8817. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  8818. */
  8819. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8820. this._loader = null;
  8821. this._requests = new Array();
  8822. /**
  8823. * Name of the loader ("gltf")
  8824. */
  8825. this.name = "gltf";
  8826. /** @hidden */
  8827. this.extensions = {
  8828. ".gltf": { isBinary: false },
  8829. ".glb": { isBinary: true }
  8830. };
  8831. this._logIndentLevel = 0;
  8832. this._loggingEnabled = false;
  8833. /** @hidden */
  8834. this._log = this._logDisabled;
  8835. this._capturePerformanceCounters = false;
  8836. /** @hidden */
  8837. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8838. /** @hidden */
  8839. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8840. }
  8841. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  8842. /**
  8843. * Raised when the asset has been parsed
  8844. */
  8845. set: function (callback) {
  8846. if (this._onParsedObserver) {
  8847. this.onParsedObservable.remove(this._onParsedObserver);
  8848. }
  8849. this._onParsedObserver = this.onParsedObservable.add(callback);
  8850. },
  8851. enumerable: false,
  8852. configurable: true
  8853. });
  8854. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  8855. /**
  8856. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8857. * Note that the callback is called as soon as the mesh object is created, meaning some data may not have been setup yet for this mesh (vertex data, morph targets, material, ...)
  8858. */
  8859. set: function (callback) {
  8860. if (this._onMeshLoadedObserver) {
  8861. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  8862. }
  8863. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  8864. },
  8865. enumerable: false,
  8866. configurable: true
  8867. });
  8868. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  8869. /**
  8870. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  8871. */
  8872. set: function (callback) {
  8873. if (this._onTextureLoadedObserver) {
  8874. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  8875. }
  8876. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  8877. },
  8878. enumerable: false,
  8879. configurable: true
  8880. });
  8881. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  8882. /**
  8883. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  8884. */
  8885. set: function (callback) {
  8886. if (this._onMaterialLoadedObserver) {
  8887. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  8888. }
  8889. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  8890. },
  8891. enumerable: false,
  8892. configurable: true
  8893. });
  8894. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  8895. /**
  8896. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  8897. */
  8898. set: function (callback) {
  8899. if (this._onCameraLoadedObserver) {
  8900. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  8901. }
  8902. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  8903. },
  8904. enumerable: false,
  8905. configurable: true
  8906. });
  8907. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  8908. /**
  8909. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  8910. * For assets with LODs, raised when all of the LODs are complete.
  8911. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8912. */
  8913. set: function (callback) {
  8914. if (this._onCompleteObserver) {
  8915. this.onCompleteObservable.remove(this._onCompleteObserver);
  8916. }
  8917. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  8918. },
  8919. enumerable: false,
  8920. configurable: true
  8921. });
  8922. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  8923. /**
  8924. * Callback raised when an error occurs.
  8925. */
  8926. set: function (callback) {
  8927. if (this._onErrorObserver) {
  8928. this.onErrorObservable.remove(this._onErrorObserver);
  8929. }
  8930. this._onErrorObserver = this.onErrorObservable.add(callback);
  8931. },
  8932. enumerable: false,
  8933. configurable: true
  8934. });
  8935. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  8936. /**
  8937. * Callback raised after the loader is disposed.
  8938. */
  8939. set: function (callback) {
  8940. if (this._onDisposeObserver) {
  8941. this.onDisposeObservable.remove(this._onDisposeObserver);
  8942. }
  8943. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  8944. },
  8945. enumerable: false,
  8946. configurable: true
  8947. });
  8948. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  8949. /**
  8950. * Callback raised after a loader extension is created.
  8951. */
  8952. set: function (callback) {
  8953. if (this._onExtensionLoadedObserver) {
  8954. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  8955. }
  8956. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  8957. },
  8958. enumerable: false,
  8959. configurable: true
  8960. });
  8961. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  8962. /**
  8963. * Defines if the loader logging is enabled.
  8964. */
  8965. get: function () {
  8966. return this._loggingEnabled;
  8967. },
  8968. set: function (value) {
  8969. if (this._loggingEnabled === value) {
  8970. return;
  8971. }
  8972. this._loggingEnabled = value;
  8973. if (this._loggingEnabled) {
  8974. this._log = this._logEnabled;
  8975. }
  8976. else {
  8977. this._log = this._logDisabled;
  8978. }
  8979. },
  8980. enumerable: false,
  8981. configurable: true
  8982. });
  8983. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  8984. /**
  8985. * Defines if the loader should capture performance counters.
  8986. */
  8987. get: function () {
  8988. return this._capturePerformanceCounters;
  8989. },
  8990. set: function (value) {
  8991. if (this._capturePerformanceCounters === value) {
  8992. return;
  8993. }
  8994. this._capturePerformanceCounters = value;
  8995. if (this._capturePerformanceCounters) {
  8996. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  8997. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  8998. }
  8999. else {
  9000. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  9001. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  9002. }
  9003. },
  9004. enumerable: false,
  9005. configurable: true
  9006. });
  9007. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  9008. /**
  9009. * Callback raised after a loader extension is created.
  9010. */
  9011. set: function (callback) {
  9012. if (this._onValidatedObserver) {
  9013. this.onValidatedObservable.remove(this._onValidatedObserver);
  9014. }
  9015. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  9016. },
  9017. enumerable: false,
  9018. configurable: true
  9019. });
  9020. /**
  9021. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  9022. */
  9023. GLTFFileLoader.prototype.dispose = function () {
  9024. if (this._loader) {
  9025. this._loader.dispose();
  9026. this._loader = null;
  9027. }
  9028. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  9029. var request = _a[_i];
  9030. request.abort();
  9031. }
  9032. this._requests.length = 0;
  9033. delete this._progressCallback;
  9034. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  9035. this.onMeshLoadedObservable.clear();
  9036. this.onTextureLoadedObservable.clear();
  9037. this.onMaterialLoadedObservable.clear();
  9038. this.onCameraLoadedObservable.clear();
  9039. this.onCompleteObservable.clear();
  9040. this.onExtensionLoadedObservable.clear();
  9041. this.onDisposeObservable.notifyObservers(undefined);
  9042. this.onDisposeObservable.clear();
  9043. };
  9044. /** @hidden */
  9045. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  9046. var _this = this;
  9047. this._progressCallback = onProgress;
  9048. if (useArrayBuffer) {
  9049. if (this.useRangeRequests) {
  9050. if (this.validate) {
  9051. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  9052. }
  9053. var fileRequest_1 = {
  9054. abort: function () { },
  9055. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  9056. };
  9057. var dataBuffer = {
  9058. readAsync: function (byteOffset, byteLength) {
  9059. return new Promise(function (resolve, reject) {
  9060. _this._requestFile(url, scene, function (data) {
  9061. resolve(new Uint8Array(data));
  9062. }, true, function (error) {
  9063. reject(error);
  9064. }, function (webRequest) {
  9065. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  9066. });
  9067. });
  9068. },
  9069. byteLength: 0
  9070. };
  9071. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  9072. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  9073. onSuccess(loaderData);
  9074. }, onError);
  9075. return fileRequest_1;
  9076. }
  9077. return this._requestFile(url, scene, function (data, request) {
  9078. var arrayBuffer = data;
  9079. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  9080. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  9081. byteLength: arrayBuffer.byteLength
  9082. })).then(function (loaderData) {
  9083. onSuccess(loaderData, request);
  9084. }, onError);
  9085. }, true, onError);
  9086. }
  9087. return this._requestFile(url, scene, function (data, request) {
  9088. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  9089. onSuccess({ json: _this._parseJson(data) }, request);
  9090. }, useArrayBuffer, onError);
  9091. };
  9092. /** @hidden */
  9093. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  9094. var _this = this;
  9095. return scene._readFile(file, function (data) {
  9096. _this._validate(scene, data, "file:", file.name);
  9097. if (useArrayBuffer) {
  9098. var arrayBuffer_1 = data;
  9099. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  9100. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  9101. byteLength: arrayBuffer_1.byteLength
  9102. })).then(onSuccess, onError);
  9103. }
  9104. else {
  9105. onSuccess({ json: _this._parseJson(data) });
  9106. }
  9107. }, onProgress, useArrayBuffer, onError);
  9108. };
  9109. /** @hidden */
  9110. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  9111. var _this = this;
  9112. return Promise.resolve().then(function () {
  9113. _this.onParsedObservable.notifyObservers(data);
  9114. _this.onParsedObservable.clear();
  9115. _this._log("Loading " + (fileName || ""));
  9116. _this._loader = _this._getLoader(data);
  9117. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  9118. });
  9119. };
  9120. /** @hidden */
  9121. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  9122. var _this = this;
  9123. return Promise.resolve().then(function () {
  9124. _this.onParsedObservable.notifyObservers(data);
  9125. _this.onParsedObservable.clear();
  9126. _this._log("Loading " + (fileName || ""));
  9127. _this._loader = _this._getLoader(data);
  9128. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  9129. });
  9130. };
  9131. /** @hidden */
  9132. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  9133. var _this = this;
  9134. return Promise.resolve().then(function () {
  9135. _this.onParsedObservable.notifyObservers(data);
  9136. _this.onParsedObservable.clear();
  9137. _this._log("Loading " + (fileName || ""));
  9138. _this._loader = _this._getLoader(data);
  9139. // Prepare the asset container.
  9140. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  9141. // Get materials/textures when loading to add to container
  9142. var materials = [];
  9143. _this.onMaterialLoadedObservable.add(function (material) {
  9144. materials.push(material);
  9145. material.onDisposeObservable.addOnce(function () {
  9146. var index = container.materials.indexOf(material);
  9147. if (index > -1) {
  9148. container.materials.splice(index, 1);
  9149. }
  9150. index = materials.indexOf(material);
  9151. if (index > -1) {
  9152. materials.splice(index, 1);
  9153. }
  9154. });
  9155. });
  9156. var textures = [];
  9157. _this.onTextureLoadedObservable.add(function (texture) {
  9158. textures.push(texture);
  9159. texture.onDisposeObservable.addOnce(function () {
  9160. var index = container.textures.indexOf(texture);
  9161. if (index > -1) {
  9162. container.textures.splice(index, 1);
  9163. }
  9164. index = textures.indexOf(texture);
  9165. if (index > -1) {
  9166. textures.splice(index, 1);
  9167. }
  9168. });
  9169. });
  9170. var cameras = [];
  9171. _this.onCameraLoadedObservable.add(function (camera) {
  9172. cameras.push(camera);
  9173. });
  9174. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  9175. Array.prototype.push.apply(container.geometries, result.geometries);
  9176. Array.prototype.push.apply(container.meshes, result.meshes);
  9177. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  9178. Array.prototype.push.apply(container.skeletons, result.skeletons);
  9179. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  9180. Array.prototype.push.apply(container.materials, materials);
  9181. Array.prototype.push.apply(container.textures, textures);
  9182. Array.prototype.push.apply(container.lights, result.lights);
  9183. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  9184. Array.prototype.push.apply(container.cameras, cameras);
  9185. return container;
  9186. });
  9187. });
  9188. };
  9189. /** @hidden */
  9190. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  9191. return (data.indexOf("asset") !== -1 && data.indexOf("version") !== -1)
  9192. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:base64," + GLTFFileLoader.magicBase64Encoded)
  9193. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded)
  9194. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded);
  9195. };
  9196. /** @hidden */
  9197. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  9198. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "base64," + GLTFFileLoader.magicBase64Encoded) ||
  9199. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded) ||
  9200. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded)) {
  9201. var arrayBuffer_2 = babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(data);
  9202. this._validate(scene, arrayBuffer_2);
  9203. return this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  9204. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_2, byteOffset, byteLength)); },
  9205. byteLength: arrayBuffer_2.byteLength
  9206. }));
  9207. }
  9208. this._validate(scene, data);
  9209. return Promise.resolve({ json: this._parseJson(data) });
  9210. };
  9211. /** @hidden */
  9212. GLTFFileLoader.prototype.createPlugin = function () {
  9213. return new GLTFFileLoader();
  9214. };
  9215. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  9216. /**
  9217. * The loader state or null if the loader is not active.
  9218. */
  9219. get: function () {
  9220. return this._loader ? this._loader.state : null;
  9221. },
  9222. enumerable: false,
  9223. configurable: true
  9224. });
  9225. /**
  9226. * Returns a promise that resolves when the asset is completely loaded.
  9227. * @returns a promise that resolves when the asset is completely loaded.
  9228. */
  9229. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  9230. var _this = this;
  9231. return new Promise(function (resolve, reject) {
  9232. _this.onCompleteObservable.addOnce(function () {
  9233. resolve();
  9234. });
  9235. _this.onErrorObservable.addOnce(function (reason) {
  9236. reject(reason);
  9237. });
  9238. });
  9239. };
  9240. /** @hidden */
  9241. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  9242. var _this = this;
  9243. var request = scene._loadFile(url, onSuccess, function (event) {
  9244. _this._onProgress(event, request);
  9245. }, undefined, useArrayBuffer, onError);
  9246. request.onCompleteObservable.add(function (request) {
  9247. _this._requests.splice(_this._requests.indexOf(request), 1);
  9248. });
  9249. this._requests.push(request);
  9250. return request;
  9251. };
  9252. /** @hidden */
  9253. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  9254. var _this = this;
  9255. var request = scene._requestFile(url, onSuccess, function (event) {
  9256. _this._onProgress(event, request);
  9257. }, undefined, useArrayBuffer, onError, onOpened);
  9258. request.onCompleteObservable.add(function (request) {
  9259. _this._requests.splice(_this._requests.indexOf(request), 1);
  9260. });
  9261. this._requests.push(request);
  9262. return request;
  9263. };
  9264. GLTFFileLoader.prototype._onProgress = function (event, request) {
  9265. if (!this._progressCallback) {
  9266. return;
  9267. }
  9268. request._lengthComputable = event.lengthComputable;
  9269. request._loaded = event.loaded;
  9270. request._total = event.total;
  9271. var lengthComputable = true;
  9272. var loaded = 0;
  9273. var total = 0;
  9274. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  9275. var request_1 = _a[_i];
  9276. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  9277. return;
  9278. }
  9279. lengthComputable = lengthComputable && request_1._lengthComputable;
  9280. loaded += request_1._loaded;
  9281. total += request_1._total;
  9282. }
  9283. this._progressCallback({
  9284. lengthComputable: lengthComputable,
  9285. loaded: loaded,
  9286. total: lengthComputable ? total : 0
  9287. });
  9288. };
  9289. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  9290. var _this = this;
  9291. if (rootUrl === void 0) { rootUrl = ""; }
  9292. if (fileName === void 0) { fileName = ""; }
  9293. if (!this.validate) {
  9294. return;
  9295. }
  9296. this._startPerformanceCounter("Validate JSON");
  9297. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  9298. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  9299. }).then(function (result) {
  9300. _this._endPerformanceCounter("Validate JSON");
  9301. _this.onValidatedObservable.notifyObservers(result);
  9302. _this.onValidatedObservable.clear();
  9303. }, function (reason) {
  9304. _this._endPerformanceCounter("Validate JSON");
  9305. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  9306. _this.onValidatedObservable.clear();
  9307. });
  9308. };
  9309. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  9310. var asset = loaderData.json.asset || {};
  9311. this._log("Asset version: " + asset.version);
  9312. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  9313. asset.generator && this._log("Asset generator: " + asset.generator);
  9314. var version = GLTFFileLoader._parseVersion(asset.version);
  9315. if (!version) {
  9316. throw new Error("Invalid version: " + asset.version);
  9317. }
  9318. if (asset.minVersion !== undefined) {
  9319. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  9320. if (!minVersion) {
  9321. throw new Error("Invalid minimum version: " + asset.minVersion);
  9322. }
  9323. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  9324. throw new Error("Incompatible minimum version: " + asset.minVersion);
  9325. }
  9326. }
  9327. var createLoaders = {
  9328. 1: GLTFFileLoader._CreateGLTF1Loader,
  9329. 2: GLTFFileLoader._CreateGLTF2Loader
  9330. };
  9331. var createLoader = createLoaders[version.major];
  9332. if (!createLoader) {
  9333. throw new Error("Unsupported version: " + asset.version);
  9334. }
  9335. return createLoader(this);
  9336. };
  9337. GLTFFileLoader.prototype._parseJson = function (json) {
  9338. this._startPerformanceCounter("Parse JSON");
  9339. this._log("JSON length: " + json.length);
  9340. var parsed = JSON.parse(json);
  9341. this._endPerformanceCounter("Parse JSON");
  9342. return parsed;
  9343. };
  9344. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  9345. var _this = this;
  9346. this._startPerformanceCounter("Unpack Binary");
  9347. // Read magic + version + length + json length + json format
  9348. return dataReader.loadAsync(20).then(function () {
  9349. var Binary = {
  9350. Magic: 0x46546C67
  9351. };
  9352. var magic = dataReader.readUint32();
  9353. if (magic !== Binary.Magic) {
  9354. throw new Error("Unexpected magic: " + magic);
  9355. }
  9356. var version = dataReader.readUint32();
  9357. if (_this.loggingEnabled) {
  9358. _this._log("Binary version: " + version);
  9359. }
  9360. var length = dataReader.readUint32();
  9361. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  9362. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  9363. }
  9364. var unpacked;
  9365. switch (version) {
  9366. case 1: {
  9367. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  9368. break;
  9369. }
  9370. case 2: {
  9371. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  9372. break;
  9373. }
  9374. default: {
  9375. throw new Error("Unsupported version: " + version);
  9376. }
  9377. }
  9378. _this._endPerformanceCounter("Unpack Binary");
  9379. return unpacked;
  9380. });
  9381. };
  9382. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  9383. var ContentFormat = {
  9384. JSON: 0
  9385. };
  9386. var contentLength = dataReader.readUint32();
  9387. var contentFormat = dataReader.readUint32();
  9388. if (contentFormat !== ContentFormat.JSON) {
  9389. throw new Error("Unexpected content format: " + contentFormat);
  9390. }
  9391. var bodyLength = length - dataReader.byteOffset;
  9392. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  9393. if (bodyLength !== 0) {
  9394. var startByteOffset_1 = dataReader.byteOffset;
  9395. data.bin = {
  9396. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  9397. byteLength: bodyLength
  9398. };
  9399. }
  9400. return Promise.resolve(data);
  9401. };
  9402. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  9403. var _this = this;
  9404. var ChunkFormat = {
  9405. JSON: 0x4E4F534A,
  9406. BIN: 0x004E4942
  9407. };
  9408. // Read the JSON chunk header.
  9409. var chunkLength = dataReader.readUint32();
  9410. var chunkFormat = dataReader.readUint32();
  9411. if (chunkFormat !== ChunkFormat.JSON) {
  9412. throw new Error("First chunk format is not JSON");
  9413. }
  9414. // Bail if there are no other chunks.
  9415. if (dataReader.byteOffset + chunkLength === length) {
  9416. return dataReader.loadAsync(chunkLength).then(function () {
  9417. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  9418. });
  9419. }
  9420. // Read the JSON chunk and the length and type of the next chunk.
  9421. return dataReader.loadAsync(chunkLength + 8).then(function () {
  9422. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  9423. var readAsync = function () {
  9424. var chunkLength = dataReader.readUint32();
  9425. var chunkFormat = dataReader.readUint32();
  9426. switch (chunkFormat) {
  9427. case ChunkFormat.JSON: {
  9428. throw new Error("Unexpected JSON chunk");
  9429. }
  9430. case ChunkFormat.BIN: {
  9431. var startByteOffset_2 = dataReader.byteOffset;
  9432. data.bin = {
  9433. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  9434. byteLength: chunkLength
  9435. };
  9436. dataReader.skipBytes(chunkLength);
  9437. break;
  9438. }
  9439. default: {
  9440. // ignore unrecognized chunkFormat
  9441. dataReader.skipBytes(chunkLength);
  9442. break;
  9443. }
  9444. }
  9445. if (dataReader.byteOffset !== length) {
  9446. return dataReader.loadAsync(8).then(readAsync);
  9447. }
  9448. return Promise.resolve(data);
  9449. };
  9450. return readAsync();
  9451. });
  9452. };
  9453. GLTFFileLoader._parseVersion = function (version) {
  9454. if (version === "1.0" || version === "1.0.1") {
  9455. return {
  9456. major: 1,
  9457. minor: 0
  9458. };
  9459. }
  9460. var match = (version + "").match(/^(\d+)\.(\d+)/);
  9461. if (!match) {
  9462. return null;
  9463. }
  9464. return {
  9465. major: parseInt(match[1]),
  9466. minor: parseInt(match[2])
  9467. };
  9468. };
  9469. GLTFFileLoader._compareVersion = function (a, b) {
  9470. if (a.major > b.major) {
  9471. return 1;
  9472. }
  9473. if (a.major < b.major) {
  9474. return -1;
  9475. }
  9476. if (a.minor > b.minor) {
  9477. return 1;
  9478. }
  9479. if (a.minor < b.minor) {
  9480. return -1;
  9481. }
  9482. return 0;
  9483. };
  9484. /** @hidden */
  9485. GLTFFileLoader.prototype._logOpen = function (message) {
  9486. this._log(message);
  9487. this._logIndentLevel++;
  9488. };
  9489. /** @hidden */
  9490. GLTFFileLoader.prototype._logClose = function () {
  9491. --this._logIndentLevel;
  9492. };
  9493. GLTFFileLoader.prototype._logEnabled = function (message) {
  9494. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  9495. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  9496. };
  9497. GLTFFileLoader.prototype._logDisabled = function (message) {
  9498. };
  9499. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  9500. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  9501. };
  9502. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  9503. };
  9504. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  9505. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  9506. };
  9507. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  9508. };
  9509. // ----------
  9510. // V1 options
  9511. // ----------
  9512. /**
  9513. * 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.
  9514. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  9515. * Defaults to true.
  9516. * @hidden
  9517. */
  9518. GLTFFileLoader.IncrementalLoading = true;
  9519. /**
  9520. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  9521. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  9522. * @hidden
  9523. */
  9524. GLTFFileLoader.HomogeneousCoordinates = false;
  9525. GLTFFileLoader.magicBase64Encoded = "Z2xURg"; // "glTF" base64 encoded (without the quotes!)
  9526. GLTFFileLoader._logSpaces = " ";
  9527. return GLTFFileLoader;
  9528. }());
  9529. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  9530. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  9531. }
  9532. /***/ }),
  9533. /***/ "./glTF/glTFValidation.ts":
  9534. /*!********************************!*\
  9535. !*** ./glTF/glTFValidation.ts ***!
  9536. \********************************/
  9537. /*! exports provided: GLTFValidation */
  9538. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9539. "use strict";
  9540. __webpack_require__.r(__webpack_exports__);
  9541. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  9542. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  9543. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  9544. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  9545. var options = {
  9546. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  9547. };
  9548. if (fileName) {
  9549. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  9550. }
  9551. return (data instanceof ArrayBuffer)
  9552. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  9553. : GLTFValidator.validateString(data, options);
  9554. }
  9555. /**
  9556. * The worker function that gets converted to a blob url to pass into a worker.
  9557. */
  9558. function workerFunc() {
  9559. var pendingExternalResources = [];
  9560. onmessage = function (message) {
  9561. var data = message.data;
  9562. switch (data.id) {
  9563. case "init": {
  9564. importScripts(data.url);
  9565. break;
  9566. }
  9567. case "validate": {
  9568. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  9569. var index = pendingExternalResources.length;
  9570. pendingExternalResources.push({ resolve: resolve, reject: reject });
  9571. postMessage({ id: "getExternalResource", index: index, uri: uri });
  9572. }); }).then(function (value) {
  9573. postMessage({ id: "validate.resolve", value: value });
  9574. }, function (reason) {
  9575. postMessage({ id: "validate.reject", reason: reason });
  9576. });
  9577. break;
  9578. }
  9579. case "getExternalResource.resolve": {
  9580. pendingExternalResources[data.index].resolve(data.value);
  9581. break;
  9582. }
  9583. case "getExternalResource.reject": {
  9584. pendingExternalResources[data.index].reject(data.reason);
  9585. break;
  9586. }
  9587. }
  9588. };
  9589. }
  9590. /**
  9591. * glTF validation
  9592. */
  9593. var GLTFValidation = /** @class */ (function () {
  9594. function GLTFValidation() {
  9595. }
  9596. /**
  9597. * Validate a glTF asset using the glTF-Validator.
  9598. * @param data The JSON of a glTF or the array buffer of a binary glTF
  9599. * @param rootUrl The root url for the glTF
  9600. * @param fileName The file name for the glTF
  9601. * @param getExternalResource The callback to get external resources for the glTF validator
  9602. * @returns A promise that resolves with the glTF validation results once complete
  9603. */
  9604. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  9605. var _this = this;
  9606. if (typeof Worker === "function") {
  9607. return new Promise(function (resolve, reject) {
  9608. var workerContent = validateAsync + "(" + workerFunc + ")()";
  9609. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  9610. var worker = new Worker(workerBlobUrl);
  9611. var onError = function (error) {
  9612. worker.removeEventListener("error", onError);
  9613. worker.removeEventListener("message", onMessage);
  9614. reject(error);
  9615. };
  9616. var onMessage = function (message) {
  9617. var data = message.data;
  9618. switch (data.id) {
  9619. case "getExternalResource": {
  9620. getExternalResource(data.uri).then(function (value) {
  9621. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  9622. }, function (reason) {
  9623. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  9624. });
  9625. break;
  9626. }
  9627. case "validate.resolve": {
  9628. worker.removeEventListener("error", onError);
  9629. worker.removeEventListener("message", onMessage);
  9630. resolve(data.value);
  9631. break;
  9632. }
  9633. case "validate.reject": {
  9634. worker.removeEventListener("error", onError);
  9635. worker.removeEventListener("message", onMessage);
  9636. reject(data.reason);
  9637. }
  9638. }
  9639. };
  9640. worker.addEventListener("error", onError);
  9641. worker.addEventListener("message", onMessage);
  9642. worker.postMessage({ id: "init", url: _this.Configuration.url });
  9643. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  9644. });
  9645. }
  9646. else {
  9647. if (!this._LoadScriptPromise) {
  9648. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  9649. }
  9650. return this._LoadScriptPromise.then(function () {
  9651. return validateAsync(data, rootUrl, fileName, getExternalResource);
  9652. });
  9653. }
  9654. };
  9655. /**
  9656. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  9657. */
  9658. GLTFValidation.Configuration = {
  9659. url: "https://preview.babylonjs.com/gltf_validator.js"
  9660. };
  9661. return GLTFValidation;
  9662. }());
  9663. /***/ }),
  9664. /***/ "./glTF/index.ts":
  9665. /*!***********************!*\
  9666. !*** ./glTF/index.ts ***!
  9667. \***********************/
  9668. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  9669. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9670. "use strict";
  9671. __webpack_require__.r(__webpack_exports__);
  9672. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9673. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9674. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9675. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9676. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9677. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  9678. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9679. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  9680. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  9681. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  9682. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  9683. /***/ }),
  9684. /***/ "./index.ts":
  9685. /*!******************!*\
  9686. !*** ./index.ts ***!
  9687. \******************/
  9688. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9689. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9690. "use strict";
  9691. __webpack_require__.r(__webpack_exports__);
  9692. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  9693. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9694. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9695. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9696. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9697. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  9698. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  9699. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  9700. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  9701. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  9702. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  9703. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  9704. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  9705. /***/ }),
  9706. /***/ "./legacy/legacy-glTF.ts":
  9707. /*!*******************************!*\
  9708. !*** ./legacy/legacy-glTF.ts ***!
  9709. \*******************************/
  9710. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  9711. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9712. "use strict";
  9713. __webpack_require__.r(__webpack_exports__);
  9714. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9715. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  9716. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9717. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9718. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9719. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9720. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9721. /**
  9722. * This is the entry point for the UMD module.
  9723. * The entry point for a future ESM package should be index.ts
  9724. */
  9725. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9726. if (typeof globalObject !== "undefined") {
  9727. globalObject.BABYLON = globalObject.BABYLON || {};
  9728. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  9729. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  9730. }
  9731. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  9732. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  9733. }
  9734. }
  9735. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9736. /***/ }),
  9737. /***/ "./legacy/legacy-glTF1.ts":
  9738. /*!********************************!*\
  9739. !*** ./legacy/legacy-glTF1.ts ***!
  9740. \********************************/
  9741. /*! exports provided: GLTF1 */
  9742. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9743. "use strict";
  9744. __webpack_require__.r(__webpack_exports__);
  9745. /* 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");
  9746. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  9747. /**
  9748. * This is the entry point for the UMD module.
  9749. * The entry point for a future ESM package should be index.ts
  9750. */
  9751. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9752. if (typeof globalObject !== "undefined") {
  9753. globalObject.BABYLON = globalObject.BABYLON || {};
  9754. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  9755. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  9756. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  9757. }
  9758. }
  9759. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9760. /***/ }),
  9761. /***/ "./legacy/legacy-glTF2.ts":
  9762. /*!********************************!*\
  9763. !*** ./legacy/legacy-glTF2.ts ***!
  9764. \********************************/
  9765. /*! exports provided: GLTF2 */
  9766. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9767. "use strict";
  9768. __webpack_require__.r(__webpack_exports__);
  9769. /* 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");
  9770. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  9771. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  9772. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  9773. /**
  9774. * This is the entry point for the UMD module.
  9775. * The entry point for a future ESM package should be index.ts
  9776. */
  9777. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9778. if (typeof globalObject !== "undefined") {
  9779. globalObject.BABYLON = globalObject.BABYLON || {};
  9780. var BABYLON = globalObject.BABYLON;
  9781. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  9782. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  9783. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  9784. var keys = [];
  9785. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  9786. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  9787. keys.push(key);
  9788. }
  9789. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  9790. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  9791. keys.push(key);
  9792. }
  9793. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  9794. // Prevent Reassignment.
  9795. if (keys.indexOf(key) > -1) {
  9796. continue;
  9797. }
  9798. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  9799. }
  9800. }
  9801. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9802. /***/ }),
  9803. /***/ "./legacy/legacy-objFileLoader.ts":
  9804. /*!****************************************!*\
  9805. !*** ./legacy/legacy-objFileLoader.ts ***!
  9806. \****************************************/
  9807. /*! exports provided: MTLFileLoader, OBJFileLoader */
  9808. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9809. "use strict";
  9810. __webpack_require__.r(__webpack_exports__);
  9811. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  9812. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  9813. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  9814. /**
  9815. * This is the entry point for the UMD module.
  9816. * The entry point for a future ESM package should be index.ts
  9817. */
  9818. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9819. if (typeof globalObject !== "undefined") {
  9820. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  9821. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  9822. }
  9823. }
  9824. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9825. /***/ }),
  9826. /***/ "./legacy/legacy-stlFileLoader.ts":
  9827. /*!****************************************!*\
  9828. !*** ./legacy/legacy-stlFileLoader.ts ***!
  9829. \****************************************/
  9830. /*! exports provided: STLFileLoader */
  9831. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9832. "use strict";
  9833. __webpack_require__.r(__webpack_exports__);
  9834. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  9835. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  9836. /**
  9837. * This is the entry point for the UMD module.
  9838. * The entry point for a future ESM package should be index.ts
  9839. */
  9840. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9841. if (typeof globalObject !== "undefined") {
  9842. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  9843. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  9844. }
  9845. }
  9846. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9847. /***/ }),
  9848. /***/ "./legacy/legacy.ts":
  9849. /*!**************************!*\
  9850. !*** ./legacy/legacy.ts ***!
  9851. \**************************/
  9852. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9853. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9854. "use strict";
  9855. __webpack_require__.r(__webpack_exports__);
  9856. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  9857. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  9858. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  9859. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  9860. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  9861. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  9862. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9863. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  9864. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  9865. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  9866. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  9867. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  9868. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  9869. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  9870. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  9871. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  9872. /***/ }),
  9873. /***/ "babylonjs/Misc/tools":
  9874. /*!****************************************************************************************************!*\
  9875. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  9876. \****************************************************************************************************/
  9877. /*! no static exports found */
  9878. /***/ (function(module, exports) {
  9879. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  9880. /***/ })
  9881. /******/ });
  9882. });
  9883. //# sourceMappingURL=babylonjs.loaders.js.map