babylonjs.loaders.js 519 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384
  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_observable__) {
  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/observable");
  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/observable");
  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. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  679. InvertY: OBJFileLoader.INVERT_Y,
  680. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  681. UVScaling: OBJFileLoader.UV_SCALING,
  682. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  683. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  684. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  685. };
  686. },
  687. enumerable: false,
  688. configurable: true
  689. });
  690. /**
  691. * Calls synchronously the MTL file attached to this obj.
  692. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  693. * Without this function materials are not displayed in the first frame (but displayed after).
  694. * In consequence it is impossible to get material information in your HTML file
  695. *
  696. * @param url The URL of the MTL file
  697. * @param rootUrl
  698. * @param onSuccess Callback function to be called when the MTL file is loaded
  699. * @private
  700. */
  701. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  702. //The complete path to the mtl file
  703. var pathOfFile = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  704. // Loads through the babylon tools to allow fileInput search.
  705. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  706. onFailure(pathOfFile, exception);
  707. });
  708. };
  709. /**
  710. * Instantiates a OBJ file loader plugin.
  711. * @returns the created plugin
  712. */
  713. OBJFileLoader.prototype.createPlugin = function () {
  714. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  715. };
  716. /**
  717. * If the data string can be loaded directly.
  718. *
  719. * @param data string containing the file data
  720. * @returns if the data can be loaded directly
  721. */
  722. OBJFileLoader.prototype.canDirectLoad = function (data) {
  723. return false;
  724. };
  725. /**
  726. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  727. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  728. * @param scene the scene the meshes should be added to
  729. * @param data the OBJ data to load
  730. * @param rootUrl root url to load from
  731. * @param onProgress event that fires when loading progress has occured
  732. * @param fileName Defines the name of the file to load
  733. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  734. */
  735. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  736. //get the meshes from OBJ file
  737. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  738. return {
  739. meshes: meshes,
  740. particleSystems: [],
  741. skeletons: [],
  742. animationGroups: [],
  743. transformNodes: [],
  744. geometries: [],
  745. lights: []
  746. };
  747. });
  748. };
  749. /**
  750. * Imports all objects from the loaded OBJ data and adds them to the scene
  751. * @param scene the scene the objects should be added to
  752. * @param data the OBJ data to load
  753. * @param rootUrl root url to load from
  754. * @param onProgress event that fires when loading progress has occured
  755. * @param fileName Defines the name of the file to load
  756. * @returns a promise which completes when objects have been loaded to the scene
  757. */
  758. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  759. //Get the 3D model
  760. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  761. // return void
  762. });
  763. };
  764. /**
  765. * Load into an asset container.
  766. * @param scene The scene to load into
  767. * @param data The data to import
  768. * @param rootUrl The root url for scene and resources
  769. * @param onProgress The callback when the load progresses
  770. * @param fileName Defines the name of the file to load
  771. * @returns The loaded asset container
  772. */
  773. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  774. var _this = this;
  775. this._forAssetContainer = true;
  776. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  777. var container = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  778. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  779. result.meshes.forEach(function (mesh) {
  780. var material = mesh.material;
  781. if (material) {
  782. // Materials
  783. if (container.materials.indexOf(material) == -1) {
  784. container.materials.push(material);
  785. // Textures
  786. var textures = material.getActiveTextures();
  787. textures.forEach(function (t) {
  788. if (container.textures.indexOf(t) == -1) {
  789. container.textures.push(t);
  790. }
  791. });
  792. }
  793. }
  794. });
  795. _this._forAssetContainer = false;
  796. return container;
  797. }).catch(function (ex) {
  798. _this._forAssetContainer = false;
  799. throw ex;
  800. });
  801. };
  802. /**
  803. * Read the OBJ file and create an Array of meshes.
  804. * Each mesh contains all information given by the OBJ and the MTL file.
  805. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  806. *
  807. * @param meshesNames
  808. * @param scene Scene The scene where are displayed the data
  809. * @param data String The content of the obj file
  810. * @param rootUrl String The path to the folder
  811. * @returns Array<AbstractMesh>
  812. * @private
  813. */
  814. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  815. var _this = this;
  816. var positions = []; //values for the positions of vertices
  817. var normals = []; //Values for the normals
  818. var uvs = []; //Values for the textures
  819. var colors = [];
  820. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  821. var handledMesh; //The current mesh of meshes array
  822. var indicesForBabylon = []; //The list of indices for VertexData
  823. var wrappedPositionForBabylon = []; //The list of position in vectors
  824. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  825. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  826. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  827. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  828. var curPositionInIndices = 0;
  829. var hasMeshes = false; //Meshes are defined in the file
  830. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  831. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  832. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  833. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  834. var triangles = []; //Indices from new triangles coming from polygons
  835. var materialNameFromObj = ""; //The name of the current material
  836. var fileToLoad = ""; //The name of the mtlFile to load
  837. var materialsFromMTLFile = new _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]();
  838. var objMeshName = ""; //The name of the current obj mesh
  839. var increment = 1; //Id for meshes created by the multimaterial
  840. var isFirstMaterial = true;
  841. var grayColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  842. /**
  843. * Search for obj in the given array.
  844. * This function is called to check if a couple of data already exists in an array.
  845. *
  846. * If found, returns the index of the founded tuple index. Returns -1 if not found
  847. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  848. * @param obj Array<number>
  849. * @returns {boolean}
  850. */
  851. var isInArray = function (arr, obj) {
  852. if (!arr[obj[0]]) {
  853. arr[obj[0]] = { normals: [], idx: [] };
  854. }
  855. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  856. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  857. };
  858. var isInArrayUV = function (arr, obj) {
  859. if (!arr[obj[0]]) {
  860. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  861. }
  862. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  863. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  864. return arr[obj[0]].idx[idx];
  865. }
  866. return -1;
  867. };
  868. /**
  869. * This function set the data for each triangle.
  870. * Data are position, normals and uvs
  871. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  872. * If the tuple already exist, add only their indice
  873. *
  874. * @param indicePositionFromObj Integer The index in positions array
  875. * @param indiceUvsFromObj Integer The index in uvs array
  876. * @param indiceNormalFromObj Integer The index in normals array
  877. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  878. * @param textureVectorFromOBJ Vector3 The value of uvs
  879. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  880. */
  881. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  882. //Check if this tuple already exists in the list of tuples
  883. var _index;
  884. if (_this._meshLoadOptions.OptimizeWithUV) {
  885. _index = isInArrayUV(tuplePosNorm, [
  886. indicePositionFromObj,
  887. indiceNormalFromObj,
  888. indiceUvsFromObj
  889. ]);
  890. }
  891. else {
  892. _index = isInArray(tuplePosNorm, [
  893. indicePositionFromObj,
  894. indiceNormalFromObj
  895. ]);
  896. }
  897. //If it not exists
  898. if (_index === -1) {
  899. //Add an new indice.
  900. //The array of indices is only an array with his length equal to the number of triangles - 1.
  901. //We add vertices data in this order
  902. indicesForBabylon.push(wrappedPositionForBabylon.length);
  903. //Push the position of vertice for Babylon
  904. //Each element is a Vector3(x,y,z)
  905. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  906. //Push the uvs for Babylon
  907. //Each element is a Vector3(u,v)
  908. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  909. //Push the normals for Babylon
  910. //Each element is a Vector3(x,y,z)
  911. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  912. if (positionColorsFromOBJ !== undefined) {
  913. //Push the colors for Babylon
  914. //Each element is a BABYLON.Color4(r,g,b,a)
  915. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  916. }
  917. //Add the tuple in the comparison list
  918. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  919. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  920. if (_this._meshLoadOptions.OptimizeWithUV) {
  921. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  922. }
  923. }
  924. else {
  925. //The tuple already exists
  926. //Add the index of the already existing tuple
  927. //At this index we can get the value of position, normal, color and uvs of vertex
  928. indicesForBabylon.push(_index);
  929. }
  930. };
  931. /**
  932. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  933. */
  934. var unwrapData = function () {
  935. //Every array has the same length
  936. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  937. //Push the x, y, z values of each element in the unwrapped array
  938. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  939. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  940. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  941. if (_this._meshLoadOptions.ImportVertexColors === true) {
  942. //Push the r, g, b, a values of each element in the unwrapped array
  943. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  944. }
  945. }
  946. // Reset arrays for the next new meshes
  947. wrappedPositionForBabylon = [];
  948. wrappedNormalsForBabylon = [];
  949. wrappedUvsForBabylon = [];
  950. wrappedColorsForBabylon = [];
  951. tuplePosNorm = [];
  952. curPositionInIndices = 0;
  953. };
  954. /**
  955. * Create triangles from polygons
  956. * It is important to notice that a triangle is a polygon
  957. * We get 5 patterns of face defined in OBJ File :
  958. * facePattern1 = ["1","2","3","4","5","6"]
  959. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  960. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  961. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  962. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  963. * Each pattern is divided by the same method
  964. * @param face Array[String] The indices of elements
  965. * @param v Integer The variable to increment
  966. */
  967. var getTriangles = function (faces, v) {
  968. //Work for each element of the array
  969. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  970. //Add on the triangle variable the indexes to obtain triangles
  971. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  972. }
  973. //Result obtained after 2 iterations:
  974. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  975. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  976. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  977. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  978. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  979. };
  980. /**
  981. * Create triangles and push the data for each polygon for the pattern 1
  982. * In this pattern we get vertice positions
  983. * @param face
  984. * @param v
  985. */
  986. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  987. //Get the indices of triangles for each polygon
  988. getTriangles(face, v);
  989. //For each element in the triangles array.
  990. //This var could contains 1 to an infinity of triangles
  991. for (var k = 0; k < triangles.length; k++) {
  992. // Set position indice
  993. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  994. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  995. positions[indicePositionFromObj], //Get the vectors data
  996. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  997. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  998. }
  999. //Reset variable for the next line
  1000. triangles = [];
  1001. };
  1002. /**
  1003. * Create triangles and push the data for each polygon for the pattern 2
  1004. * In this pattern we get vertice positions and uvsu
  1005. * @param face
  1006. * @param v
  1007. */
  1008. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  1009. //Get the indices of triangles for each polygon
  1010. getTriangles(face, v);
  1011. for (var k = 0; k < triangles.length; k++) {
  1012. //triangle[k] = "1/1"
  1013. //Split the data for getting position and uv
  1014. var point = triangles[k].split("/"); // ["1", "1"]
  1015. //Set position indice
  1016. var indicePositionFromObj = parseInt(point[0]) - 1;
  1017. //Set uv indice
  1018. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1019. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  1020. positions[indicePositionFromObj], //Get the values for each element
  1021. uvs[indiceUvsFromObj], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  1022. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1023. }
  1024. //Reset variable for the next line
  1025. triangles = [];
  1026. };
  1027. /**
  1028. * Create triangles and push the data for each polygon for the pattern 3
  1029. * In this pattern we get vertice positions, uvs and normals
  1030. * @param face
  1031. * @param v
  1032. */
  1033. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  1034. //Get the indices of triangles for each polygon
  1035. getTriangles(face, v);
  1036. for (var k = 0; k < triangles.length; k++) {
  1037. //triangle[k] = "1/1/1"
  1038. //Split the data for getting position, uv, and normals
  1039. var point = triangles[k].split("/"); // ["1", "1", "1"]
  1040. // Set position indice
  1041. var indicePositionFromObj = parseInt(point[0]) - 1;
  1042. // Set uv indice
  1043. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1044. // Set normal indice
  1045. var indiceNormalFromObj = parseInt(point[2]) - 1;
  1046. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  1047. );
  1048. }
  1049. //Reset variable for the next line
  1050. triangles = [];
  1051. };
  1052. /**
  1053. * Create triangles and push the data for each polygon for the pattern 4
  1054. * In this pattern we get vertice positions and normals
  1055. * @param face
  1056. * @param v
  1057. */
  1058. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  1059. getTriangles(face, v);
  1060. for (var k = 0; k < triangles.length; k++) {
  1061. //triangle[k] = "1//1"
  1062. //Split the data for getting position and normals
  1063. var point = triangles[k].split("//"); // ["1", "1"]
  1064. // We check indices, and normals
  1065. var indicePositionFromObj = parseInt(point[0]) - 1;
  1066. var indiceNormalFromObj = parseInt(point[1]) - 1;
  1067. setData(indicePositionFromObj, 1, //Default value for uv
  1068. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  1069. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1070. }
  1071. //Reset variable for the next line
  1072. triangles = [];
  1073. };
  1074. /**
  1075. * Create triangles and push the data for each polygon for the pattern 3
  1076. * In this pattern we get vertice positions, uvs and normals
  1077. * @param face
  1078. * @param v
  1079. */
  1080. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1081. //Get the indices of triangles for each polygon
  1082. getTriangles(face, v);
  1083. for (var k = 0; k < triangles.length; k++) {
  1084. //triangle[k] = "-1/-1/-1"
  1085. //Split the data for getting position, uv, and normals
  1086. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1087. // Set position indice
  1088. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1089. // Set uv indice
  1090. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1091. // Set normal indice
  1092. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1093. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1094. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1095. }
  1096. //Reset variable for the next line
  1097. triangles = [];
  1098. };
  1099. var addPreviousObjMesh = function () {
  1100. //Check if it is not the first mesh. Otherwise we don't have data.
  1101. if (meshesFromObj.length > 0) {
  1102. //Get the previous mesh for applying the data about the faces
  1103. //=> in obj file, faces definition append after the name of the mesh
  1104. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1105. //Set the data into Array for the mesh
  1106. unwrapData();
  1107. // Reverse tab. Otherwise face are displayed in the wrong sens
  1108. indicesForBabylon.reverse();
  1109. //Set the information for the mesh
  1110. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1111. handledMesh.indices = indicesForBabylon.slice();
  1112. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1113. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1114. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1115. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1116. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1117. }
  1118. //Reset the array for the next mesh
  1119. indicesForBabylon = [];
  1120. unwrappedPositionsForBabylon = [];
  1121. unwrappedColorsForBabylon = [];
  1122. unwrappedNormalsForBabylon = [];
  1123. unwrappedUVForBabylon = [];
  1124. }
  1125. };
  1126. //Main function
  1127. //Split the file into lines
  1128. var lines = data.split('\n');
  1129. //Look at each line
  1130. for (var i = 0; i < lines.length; i++) {
  1131. var line = lines[i].trim().replace(/\s\s/g, " ");
  1132. var result;
  1133. //Comment or newLine
  1134. if (line.length === 0 || line.charAt(0) === '#') {
  1135. continue;
  1136. //Get information about one position possible for the vertices
  1137. }
  1138. else if (this.vertexPattern.test(line)) {
  1139. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1140. // Value of result with line: "v 1.0 2.0 3.0"
  1141. // ["v", "1.0", "2.0", "3.0"]
  1142. // Create a Vector3 with the position x, y, z
  1143. positions.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1144. if (this._meshLoadOptions.ImportVertexColors === true) {
  1145. if (result.length >= 7) {
  1146. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1147. 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])));
  1148. }
  1149. else {
  1150. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1151. colors.push(grayColor);
  1152. }
  1153. }
  1154. }
  1155. else if ((result = this.normalPattern.exec(line)) !== null) {
  1156. //Create a Vector3 with the normals x, y, z
  1157. //Value of result
  1158. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1159. //Add the Vector in the list of normals
  1160. normals.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1161. }
  1162. else if ((result = this.uvPattern.exec(line)) !== null) {
  1163. //Create a Vector2 with the normals u, v
  1164. //Value of result
  1165. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1166. //Add the Vector in the list of uvs
  1167. 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));
  1168. //Identify patterns of faces
  1169. //Face could be defined in different type of pattern
  1170. }
  1171. else if ((result = this.facePattern3.exec(line)) !== null) {
  1172. //Value of result:
  1173. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1174. //Set the data for this face
  1175. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1176. 1);
  1177. }
  1178. else if ((result = this.facePattern4.exec(line)) !== null) {
  1179. //Value of result:
  1180. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1181. //Set the data for this face
  1182. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1183. 1);
  1184. }
  1185. else if ((result = this.facePattern5.exec(line)) !== null) {
  1186. //Value of result:
  1187. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1188. //Set the data for this face
  1189. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1190. 1);
  1191. }
  1192. else if ((result = this.facePattern2.exec(line)) !== null) {
  1193. //Value of result:
  1194. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1195. //Set the data for this face
  1196. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1197. 1);
  1198. }
  1199. else if ((result = this.facePattern1.exec(line)) !== null) {
  1200. //Value of result
  1201. //["f 1 2 3", "1 2 3"...]
  1202. //Set the data for this face
  1203. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1204. 1);
  1205. //Define a mesh or an object
  1206. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1207. }
  1208. else if (this.group.test(line) || this.obj.test(line)) {
  1209. //Create a new mesh corresponding to the name of the group.
  1210. //Definition of the mesh
  1211. var objMesh = {
  1212. name: line.substring(2).trim(),
  1213. indices: undefined,
  1214. positions: undefined,
  1215. normals: undefined,
  1216. uvs: undefined,
  1217. colors: undefined,
  1218. materialName: ""
  1219. };
  1220. addPreviousObjMesh();
  1221. //Push the last mesh created with only the name
  1222. meshesFromObj.push(objMesh);
  1223. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1224. hasMeshes = true;
  1225. isFirstMaterial = true;
  1226. increment = 1;
  1227. //Keyword for applying a material
  1228. }
  1229. else if (this.usemtl.test(line)) {
  1230. //Get the name of the material
  1231. materialNameFromObj = line.substring(7).trim();
  1232. //If this new material is in the same mesh
  1233. if (!isFirstMaterial || !hasMeshes) {
  1234. //Set the data for the previous mesh
  1235. addPreviousObjMesh();
  1236. //Create a new mesh
  1237. var objMesh =
  1238. //Set the name of the current obj mesh
  1239. {
  1240. name: (objMeshName || "mesh") + "_mm" + increment.toString(),
  1241. indices: undefined,
  1242. positions: undefined,
  1243. normals: undefined,
  1244. uvs: undefined,
  1245. colors: undefined,
  1246. materialName: materialNameFromObj
  1247. };
  1248. increment++;
  1249. //If meshes are already defined
  1250. meshesFromObj.push(objMesh);
  1251. hasMeshes = true;
  1252. }
  1253. //Set the material name if the previous line define a mesh
  1254. if (hasMeshes && isFirstMaterial) {
  1255. //Set the material name to the previous mesh (1 material per mesh)
  1256. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1257. isFirstMaterial = false;
  1258. }
  1259. //Keyword for loading the mtl file
  1260. }
  1261. else if (this.mtllib.test(line)) {
  1262. //Get the name of mtl file
  1263. fileToLoad = line.substring(7).trim();
  1264. //Apply smoothing
  1265. }
  1266. else if (this.smooth.test(line)) {
  1267. // smooth shading => apply smoothing
  1268. //Today I don't know it work with babylon and with obj.
  1269. //With the obj file an integer is set
  1270. }
  1271. else {
  1272. //If there is another possibility
  1273. console.log("Unhandled expression at line : " + line);
  1274. }
  1275. }
  1276. //At the end of the file, add the last mesh into the meshesFromObj array
  1277. if (hasMeshes) {
  1278. //Set the data for the last mesh
  1279. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1280. //Reverse indices for displaying faces in the good sense
  1281. indicesForBabylon.reverse();
  1282. //Get the good array
  1283. unwrapData();
  1284. //Set array
  1285. handledMesh.indices = indicesForBabylon;
  1286. handledMesh.positions = unwrappedPositionsForBabylon;
  1287. handledMesh.normals = unwrappedNormalsForBabylon;
  1288. handledMesh.uvs = unwrappedUVForBabylon;
  1289. if (this._meshLoadOptions.ImportVertexColors === true) {
  1290. handledMesh.colors = unwrappedColorsForBabylon;
  1291. }
  1292. }
  1293. //If any o or g keyword found, create a mesh with a random id
  1294. if (!hasMeshes) {
  1295. // reverse tab of indices
  1296. indicesForBabylon.reverse();
  1297. //Get positions normals uvs
  1298. unwrapData();
  1299. //Set data for one mesh
  1300. meshesFromObj.push({
  1301. name: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1302. indices: indicesForBabylon,
  1303. positions: unwrappedPositionsForBabylon,
  1304. colors: unwrappedColorsForBabylon,
  1305. normals: unwrappedNormalsForBabylon,
  1306. uvs: unwrappedUVForBabylon,
  1307. materialName: materialNameFromObj
  1308. });
  1309. }
  1310. //Create a Mesh list
  1311. var babylonMeshesArray = []; //The mesh for babylon
  1312. var materialToUse = new Array();
  1313. //Set data for each mesh
  1314. for (var j = 0; j < meshesFromObj.length; j++) {
  1315. //check meshesNames (stlFileLoader)
  1316. if (meshesNames && meshesFromObj[j].name) {
  1317. if (meshesNames instanceof Array) {
  1318. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1319. continue;
  1320. }
  1321. }
  1322. else {
  1323. if (meshesFromObj[j].name !== meshesNames) {
  1324. continue;
  1325. }
  1326. }
  1327. }
  1328. //Get the current mesh
  1329. //Set the data with VertexBuffer for each mesh
  1330. handledMesh = meshesFromObj[j];
  1331. //Create a Mesh with the name of the obj mesh
  1332. scene._blockEntityCollection = this._forAssetContainer;
  1333. var babylonMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1334. scene._blockEntityCollection = false;
  1335. //Push the name of the material to an array
  1336. //This is indispensable for the importMesh function
  1337. materialToUse.push(meshesFromObj[j].materialName);
  1338. var vertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1339. //Set the data for the babylonMesh
  1340. vertexData.uvs = handledMesh.uvs;
  1341. vertexData.indices = handledMesh.indices;
  1342. vertexData.positions = handledMesh.positions;
  1343. if (this._meshLoadOptions.ComputeNormals === true) {
  1344. var normals_1 = new Array();
  1345. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1346. vertexData.normals = normals_1;
  1347. }
  1348. else {
  1349. vertexData.normals = handledMesh.normals;
  1350. }
  1351. if (this._meshLoadOptions.ImportVertexColors === true) {
  1352. vertexData.colors = handledMesh.colors;
  1353. }
  1354. //Set the data from the VertexBuffer to the current Mesh
  1355. vertexData.applyToMesh(babylonMesh);
  1356. if (this._meshLoadOptions.InvertY) {
  1357. babylonMesh.scaling.y *= -1;
  1358. }
  1359. //Push the mesh into an array
  1360. babylonMeshesArray.push(babylonMesh);
  1361. }
  1362. var mtlPromises = [];
  1363. //load the materials
  1364. //Check if we have a file to load
  1365. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1366. //Load the file synchronously
  1367. mtlPromises.push(new Promise(function (resolve, reject) {
  1368. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1369. try {
  1370. //Create materials thanks MTLLoader function
  1371. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._forAssetContainer);
  1372. //Look at each material loaded in the mtl file
  1373. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1374. //Three variables to get all meshes with the same material
  1375. var startIndex = 0;
  1376. var _indices = [];
  1377. var _index;
  1378. //The material from MTL file is used in the meshes loaded
  1379. //Push the indice in an array
  1380. //Check if the material is not used for another mesh
  1381. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1382. _indices.push(_index);
  1383. startIndex = _index + 1;
  1384. }
  1385. //If the material is not used dispose it
  1386. if (_index === -1 && _indices.length === 0) {
  1387. //If the material is not needed, remove it
  1388. materialsFromMTLFile.materials[n].dispose();
  1389. }
  1390. else {
  1391. for (var o = 0; o < _indices.length; o++) {
  1392. //Apply the material to the Mesh for each mesh with the material
  1393. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1394. }
  1395. }
  1396. }
  1397. resolve();
  1398. }
  1399. catch (e) {
  1400. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1401. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1402. resolve();
  1403. }
  1404. else {
  1405. reject(e);
  1406. }
  1407. }
  1408. }, function (pathOfFile, exception) {
  1409. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1410. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1411. resolve();
  1412. }
  1413. else {
  1414. reject(exception);
  1415. }
  1416. });
  1417. }));
  1418. }
  1419. //Return an array with all Mesh
  1420. return Promise.all(mtlPromises).then(function () {
  1421. return babylonMeshesArray;
  1422. });
  1423. };
  1424. /**
  1425. * Defines if UVs are optimized by default during load.
  1426. */
  1427. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1428. /**
  1429. * Invert model on y-axis (does a model scaling inversion)
  1430. */
  1431. OBJFileLoader.INVERT_Y = false;
  1432. /**
  1433. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1434. */
  1435. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1436. /**
  1437. * Compute the normals for the model, even if normals are present in the file.
  1438. */
  1439. OBJFileLoader.COMPUTE_NORMALS = false;
  1440. /**
  1441. * Defines custom scaling of UV coordinates of loaded meshes.
  1442. */
  1443. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1444. /**
  1445. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1446. */
  1447. OBJFileLoader.SKIP_MATERIALS = false;
  1448. /**
  1449. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1450. *
  1451. * Defaults to true for backwards compatibility.
  1452. */
  1453. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1454. return OBJFileLoader;
  1455. }());
  1456. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1457. //Add this loader into the register plugin
  1458. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1459. }
  1460. /***/ }),
  1461. /***/ "./STL/index.ts":
  1462. /*!**********************!*\
  1463. !*** ./STL/index.ts ***!
  1464. \**********************/
  1465. /*! exports provided: STLFileLoader */
  1466. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1467. "use strict";
  1468. __webpack_require__.r(__webpack_exports__);
  1469. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1470. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1471. /***/ }),
  1472. /***/ "./STL/stlFileLoader.ts":
  1473. /*!******************************!*\
  1474. !*** ./STL/stlFileLoader.ts ***!
  1475. \******************************/
  1476. /*! exports provided: STLFileLoader */
  1477. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1478. "use strict";
  1479. __webpack_require__.r(__webpack_exports__);
  1480. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1481. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/observable");
  1482. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1483. /**
  1484. * STL file type loader.
  1485. * This is a babylon scene loader plugin.
  1486. */
  1487. var STLFileLoader = /** @class */ (function () {
  1488. function STLFileLoader() {
  1489. /** @hidden */
  1490. this.solidPattern = /solid (\S*)([\S\s]*?)endsolid[ ]*(\S*)/g;
  1491. /** @hidden */
  1492. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1493. /** @hidden */
  1494. 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;
  1495. /** @hidden */
  1496. 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;
  1497. /**
  1498. * Defines the name of the plugin.
  1499. */
  1500. this.name = "stl";
  1501. /**
  1502. * Defines the extensions the stl loader is able to load.
  1503. * force data to come in as an ArrayBuffer
  1504. * we'll convert to string if it looks like it's an ASCII .stl
  1505. */
  1506. this.extensions = {
  1507. ".stl": { isBinary: true },
  1508. };
  1509. }
  1510. /**
  1511. * Import meshes into a scene.
  1512. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1513. * @param scene The scene to import into
  1514. * @param data The data to import
  1515. * @param rootUrl The root url for scene and resources
  1516. * @param meshes The meshes array to import into
  1517. * @param particleSystems The particle systems array to import into
  1518. * @param skeletons The skeletons array to import into
  1519. * @param onError The callback when import fails
  1520. * @returns True if successful or false otherwise
  1521. */
  1522. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1523. var matches;
  1524. if (typeof data !== "string") {
  1525. if (this._isBinary(data)) {
  1526. // binary .stl
  1527. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1528. this._parseBinary(babylonMesh, data);
  1529. if (meshes) {
  1530. meshes.push(babylonMesh);
  1531. }
  1532. return true;
  1533. }
  1534. // ASCII .stl
  1535. // convert to string
  1536. var array_buffer = new Uint8Array(data);
  1537. var str = '';
  1538. for (var i = 0; i < data.byteLength; i++) {
  1539. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1540. }
  1541. data = str;
  1542. }
  1543. //if arrived here, data is a string, containing the STLA data.
  1544. while (matches = this.solidPattern.exec(data)) {
  1545. var meshName = matches[1];
  1546. var meshNameFromEnd = matches[3];
  1547. if (meshName != meshNameFromEnd) {
  1548. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1549. return false;
  1550. }
  1551. // check meshesNames
  1552. if (meshesNames && meshName) {
  1553. if (meshesNames instanceof Array) {
  1554. if (!meshesNames.indexOf(meshName)) {
  1555. continue;
  1556. }
  1557. }
  1558. else {
  1559. if (meshName !== meshesNames) {
  1560. continue;
  1561. }
  1562. }
  1563. }
  1564. // stl mesh name can be empty as well
  1565. meshName = meshName || "stlmesh";
  1566. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1567. this._parseASCII(babylonMesh, matches[2]);
  1568. if (meshes) {
  1569. meshes.push(babylonMesh);
  1570. }
  1571. }
  1572. return true;
  1573. };
  1574. /**
  1575. * Load into a scene.
  1576. * @param scene The scene to load into
  1577. * @param data The data to import
  1578. * @param rootUrl The root url for scene and resources
  1579. * @param onError The callback when import fails
  1580. * @returns true if successful or false otherwise
  1581. */
  1582. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1583. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1584. return result;
  1585. };
  1586. /**
  1587. * Load into an asset container.
  1588. * @param scene The scene to load into
  1589. * @param data The data to import
  1590. * @param rootUrl The root url for scene and resources
  1591. * @param onError The callback when import fails
  1592. * @returns The loaded asset container
  1593. */
  1594. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1595. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1596. scene._blockEntityCollection = true;
  1597. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1598. scene._blockEntityCollection = false;
  1599. return container;
  1600. };
  1601. STLFileLoader.prototype._isBinary = function (data) {
  1602. // check if file size is correct for binary stl
  1603. var faceSize, nFaces, reader;
  1604. reader = new DataView(data);
  1605. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1606. nFaces = reader.getUint32(80, true);
  1607. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1608. return true;
  1609. }
  1610. // check characters higher than ASCII to confirm binary
  1611. var fileLength = reader.byteLength;
  1612. for (var index = 0; index < fileLength; index++) {
  1613. if (reader.getUint8(index) > 127) {
  1614. return true;
  1615. }
  1616. }
  1617. return false;
  1618. };
  1619. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1620. var reader = new DataView(data);
  1621. var faces = reader.getUint32(80, true);
  1622. var dataOffset = 84;
  1623. var faceLength = 12 * 4 + 2;
  1624. var offset = 0;
  1625. var positions = new Float32Array(faces * 3 * 3);
  1626. var normals = new Float32Array(faces * 3 * 3);
  1627. var indices = new Uint32Array(faces * 3);
  1628. var indicesCount = 0;
  1629. for (var face = 0; face < faces; face++) {
  1630. var start = dataOffset + face * faceLength;
  1631. var normalX = reader.getFloat32(start, true);
  1632. var normalY = reader.getFloat32(start + 4, true);
  1633. var normalZ = reader.getFloat32(start + 8, true);
  1634. for (var i = 1; i <= 3; i++) {
  1635. var vertexstart = start + i * 12;
  1636. // ordering is intentional to match ascii import
  1637. positions[offset] = reader.getFloat32(vertexstart, true);
  1638. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1639. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1640. normals[offset] = normalX;
  1641. normals[offset + 2] = normalY;
  1642. normals[offset + 1] = normalZ;
  1643. offset += 3;
  1644. }
  1645. indices[indicesCount] = indicesCount++;
  1646. indices[indicesCount] = indicesCount++;
  1647. indices[indicesCount] = indicesCount++;
  1648. }
  1649. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1650. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1651. mesh.setIndices(indices);
  1652. mesh.computeWorldMatrix(true);
  1653. };
  1654. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1655. var positions = [];
  1656. var normals = [];
  1657. var indices = [];
  1658. var indicesCount = 0;
  1659. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1660. var matches;
  1661. while (matches = this.facetsPattern.exec(solidData)) {
  1662. var facet = matches[1];
  1663. //one normal per face
  1664. var normalMatches = this.normalPattern.exec(facet);
  1665. this.normalPattern.lastIndex = 0;
  1666. if (!normalMatches) {
  1667. continue;
  1668. }
  1669. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1670. var vertexMatch;
  1671. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1672. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1673. normals.push(normal[0], normal[1], normal[2]);
  1674. }
  1675. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1676. this.vertexPattern.lastIndex = 0;
  1677. }
  1678. this.facetsPattern.lastIndex = 0;
  1679. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1680. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1681. mesh.setIndices(indices);
  1682. mesh.computeWorldMatrix(true);
  1683. };
  1684. return STLFileLoader;
  1685. }());
  1686. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1687. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1688. }
  1689. /***/ }),
  1690. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1691. /*!*****************************************!*\
  1692. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1693. \*****************************************/
  1694. /*! exports provided: GLTFBinaryExtension */
  1695. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1696. "use strict";
  1697. __webpack_require__.r(__webpack_exports__);
  1698. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1699. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1700. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1701. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1702. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1703. var BinaryExtensionBufferName = "binary_glTF";
  1704. /** @hidden */
  1705. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1706. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1707. function GLTFBinaryExtension() {
  1708. return _super.call(this, "KHR_binary_glTF") || this;
  1709. }
  1710. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1711. var extensionsUsed = data.json.extensionsUsed;
  1712. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1713. return false;
  1714. }
  1715. this._bin = data.bin;
  1716. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1717. return true;
  1718. };
  1719. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1720. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1721. return false;
  1722. }
  1723. if (id !== BinaryExtensionBufferName) {
  1724. return false;
  1725. }
  1726. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1727. return true;
  1728. };
  1729. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1730. var texture = gltfRuntime.textures[id];
  1731. var source = gltfRuntime.images[texture.source];
  1732. if (!source.extensions || !(this.name in source.extensions)) {
  1733. return false;
  1734. }
  1735. var sourceExt = source.extensions[this.name];
  1736. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1737. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1738. onSuccess(buffer);
  1739. return true;
  1740. };
  1741. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1742. var shader = gltfRuntime.shaders[id];
  1743. if (!shader.extensions || !(this.name in shader.extensions)) {
  1744. return false;
  1745. }
  1746. var binaryExtensionShader = shader.extensions[this.name];
  1747. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1748. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1749. setTimeout(function () {
  1750. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1751. onSuccess(shaderString);
  1752. });
  1753. return true;
  1754. };
  1755. return GLTFBinaryExtension;
  1756. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1757. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1758. /***/ }),
  1759. /***/ "./glTF/1.0/glTFLoader.ts":
  1760. /*!********************************!*\
  1761. !*** ./glTF/1.0/glTFLoader.ts ***!
  1762. \********************************/
  1763. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1764. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1765. "use strict";
  1766. __webpack_require__.r(__webpack_exports__);
  1767. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1768. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1769. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1770. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1771. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  1772. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  1773. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1774. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1775. /**
  1776. * Tokenizer. Used for shaders compatibility
  1777. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1778. */
  1779. var ETokenType;
  1780. (function (ETokenType) {
  1781. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1782. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1783. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1784. })(ETokenType || (ETokenType = {}));
  1785. var Tokenizer = /** @class */ (function () {
  1786. function Tokenizer(toParse) {
  1787. this._pos = 0;
  1788. this.currentToken = ETokenType.UNKNOWN;
  1789. this.currentIdentifier = "";
  1790. this.currentString = "";
  1791. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1792. this._toParse = toParse;
  1793. this._maxPos = toParse.length;
  1794. }
  1795. Tokenizer.prototype.getNextToken = function () {
  1796. if (this.isEnd()) {
  1797. return ETokenType.END_OF_INPUT;
  1798. }
  1799. this.currentString = this.read();
  1800. this.currentToken = ETokenType.UNKNOWN;
  1801. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1802. this.currentToken = ETokenType.IDENTIFIER;
  1803. this.currentIdentifier = this.currentString;
  1804. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1805. this.currentIdentifier += this.currentString;
  1806. this.forward();
  1807. }
  1808. }
  1809. return this.currentToken;
  1810. };
  1811. Tokenizer.prototype.peek = function () {
  1812. return this._toParse[this._pos];
  1813. };
  1814. Tokenizer.prototype.read = function () {
  1815. return this._toParse[this._pos++];
  1816. };
  1817. Tokenizer.prototype.forward = function () {
  1818. this._pos++;
  1819. };
  1820. Tokenizer.prototype.isEnd = function () {
  1821. return this._pos >= this._maxPos;
  1822. };
  1823. return Tokenizer;
  1824. }());
  1825. /**
  1826. * Values
  1827. */
  1828. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1829. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1830. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1831. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1832. /**
  1833. * Parse
  1834. */
  1835. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1836. for (var buf in parsedBuffers) {
  1837. var parsedBuffer = parsedBuffers[buf];
  1838. gltfRuntime.buffers[buf] = parsedBuffer;
  1839. gltfRuntime.buffersCount++;
  1840. }
  1841. };
  1842. var parseShaders = function (parsedShaders, gltfRuntime) {
  1843. for (var sha in parsedShaders) {
  1844. var parsedShader = parsedShaders[sha];
  1845. gltfRuntime.shaders[sha] = parsedShader;
  1846. gltfRuntime.shaderscount++;
  1847. }
  1848. };
  1849. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1850. for (var object in parsedObjects) {
  1851. var parsedObject = parsedObjects[object];
  1852. gltfRuntime[runtimeProperty][object] = parsedObject;
  1853. }
  1854. };
  1855. /**
  1856. * Utils
  1857. */
  1858. var normalizeUVs = function (buffer) {
  1859. if (!buffer) {
  1860. return;
  1861. }
  1862. for (var i = 0; i < buffer.length / 2; i++) {
  1863. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1864. }
  1865. };
  1866. var getAttribute = function (attributeParameter) {
  1867. if (attributeParameter.semantic === "NORMAL") {
  1868. return "normal";
  1869. }
  1870. else if (attributeParameter.semantic === "POSITION") {
  1871. return "position";
  1872. }
  1873. else if (attributeParameter.semantic === "JOINT") {
  1874. return "matricesIndices";
  1875. }
  1876. else if (attributeParameter.semantic === "WEIGHT") {
  1877. return "matricesWeights";
  1878. }
  1879. else if (attributeParameter.semantic === "COLOR") {
  1880. return "color";
  1881. }
  1882. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1883. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1884. return "uv" + (channel === 0 ? "" : channel + 1);
  1885. }
  1886. return null;
  1887. };
  1888. /**
  1889. * Loads and creates animations
  1890. */
  1891. var loadAnimations = function (gltfRuntime) {
  1892. for (var anim in gltfRuntime.animations) {
  1893. var animation = gltfRuntime.animations[anim];
  1894. if (!animation.channels || !animation.samplers) {
  1895. continue;
  1896. }
  1897. var lastAnimation = null;
  1898. for (var i = 0; i < animation.channels.length; i++) {
  1899. // Get parameters and load buffers
  1900. var channel = animation.channels[i];
  1901. var sampler = animation.samplers[channel.sampler];
  1902. if (!sampler) {
  1903. continue;
  1904. }
  1905. var inputData = null;
  1906. var outputData = null;
  1907. if (animation.parameters) {
  1908. inputData = animation.parameters[sampler.input];
  1909. outputData = animation.parameters[sampler.output];
  1910. }
  1911. else {
  1912. inputData = sampler.input;
  1913. outputData = sampler.output;
  1914. }
  1915. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1916. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1917. var targetID = channel.target.id;
  1918. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1919. if (targetNode === null) {
  1920. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1921. }
  1922. if (targetNode === null) {
  1923. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1924. continue;
  1925. }
  1926. var isBone = targetNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1927. // Get target path (position, rotation or scaling)
  1928. var targetPath = channel.target.path;
  1929. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1930. if (targetPathIndex !== -1) {
  1931. targetPath = babylonAnimationPaths[targetPathIndex];
  1932. }
  1933. // Determine animation type
  1934. var animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1935. if (!isBone) {
  1936. if (targetPath === "rotationQuaternion") {
  1937. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1938. targetNode.rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1939. }
  1940. else {
  1941. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1942. }
  1943. }
  1944. // Create animation and key frames
  1945. var babylonAnimation = null;
  1946. var keys = [];
  1947. var arrayOffset = 0;
  1948. var modifyKey = false;
  1949. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1950. babylonAnimation = lastAnimation;
  1951. modifyKey = true;
  1952. }
  1953. if (!modifyKey) {
  1954. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1955. 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);
  1956. gltfRuntime.scene._blockEntityCollection = false;
  1957. }
  1958. // For each frame
  1959. for (var j = 0; j < bufferInput.length; j++) {
  1960. var value = null;
  1961. if (targetPath === "rotationQuaternion") { // VEC4
  1962. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1963. arrayOffset += 4;
  1964. }
  1965. else { // Position and scaling are VEC3
  1966. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1967. arrayOffset += 3;
  1968. }
  1969. if (isBone) {
  1970. var bone = targetNode;
  1971. var translation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1972. var rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1973. var scaling = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1974. // Warning on decompose
  1975. var mat = bone.getBaseMatrix();
  1976. if (modifyKey && lastAnimation) {
  1977. mat = lastAnimation.getKeys()[j].value;
  1978. }
  1979. mat.decompose(scaling, rotationQuaternion, translation);
  1980. if (targetPath === "position") {
  1981. translation = value;
  1982. }
  1983. else if (targetPath === "rotationQuaternion") {
  1984. rotationQuaternion = value;
  1985. }
  1986. else {
  1987. scaling = value;
  1988. }
  1989. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1990. }
  1991. if (!modifyKey) {
  1992. keys.push({
  1993. frame: bufferInput[j],
  1994. value: value
  1995. });
  1996. }
  1997. else if (lastAnimation) {
  1998. lastAnimation.getKeys()[j].value = value;
  1999. }
  2000. }
  2001. // Finish
  2002. if (!modifyKey && babylonAnimation) {
  2003. babylonAnimation.setKeys(keys);
  2004. targetNode.animations.push(babylonAnimation);
  2005. }
  2006. lastAnimation = babylonAnimation;
  2007. gltfRuntime.scene.stopAnimation(targetNode);
  2008. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  2009. }
  2010. }
  2011. };
  2012. /**
  2013. * Returns the bones transformation matrix
  2014. */
  2015. var configureBoneTransformation = function (node) {
  2016. var mat = null;
  2017. if (node.translation || node.rotation || node.scale) {
  2018. var scale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  2019. var rotation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  2020. var position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  2021. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  2022. }
  2023. else {
  2024. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2025. }
  2026. return mat;
  2027. };
  2028. /**
  2029. * Returns the parent bone
  2030. */
  2031. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  2032. // Try to find
  2033. for (var i = 0; i < newSkeleton.bones.length; i++) {
  2034. if (newSkeleton.bones[i].name === jointName) {
  2035. return newSkeleton.bones[i];
  2036. }
  2037. }
  2038. // Not found, search in gltf nodes
  2039. var nodes = gltfRuntime.nodes;
  2040. for (var nde in nodes) {
  2041. var node = nodes[nde];
  2042. if (!node.jointName) {
  2043. continue;
  2044. }
  2045. var children = node.children;
  2046. for (var i = 0; i < children.length; i++) {
  2047. var child = gltfRuntime.nodes[children[i]];
  2048. if (!child.jointName) {
  2049. continue;
  2050. }
  2051. if (child.jointName === jointName) {
  2052. var mat = configureBoneTransformation(node);
  2053. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  2054. bone.id = nde;
  2055. return bone;
  2056. }
  2057. }
  2058. }
  2059. return null;
  2060. };
  2061. /**
  2062. * Returns the appropriate root node
  2063. */
  2064. var getNodeToRoot = function (nodesToRoot, id) {
  2065. for (var i = 0; i < nodesToRoot.length; i++) {
  2066. var nodeToRoot = nodesToRoot[i];
  2067. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  2068. var child = nodeToRoot.node.children[j];
  2069. if (child === id) {
  2070. return nodeToRoot.bone;
  2071. }
  2072. }
  2073. }
  2074. return null;
  2075. };
  2076. /**
  2077. * Returns the node with the joint name
  2078. */
  2079. var getJointNode = function (gltfRuntime, jointName) {
  2080. var nodes = gltfRuntime.nodes;
  2081. var node = nodes[jointName];
  2082. if (node) {
  2083. return {
  2084. node: node,
  2085. id: jointName
  2086. };
  2087. }
  2088. for (var nde in nodes) {
  2089. node = nodes[nde];
  2090. if (node.jointName === jointName) {
  2091. return {
  2092. node: node,
  2093. id: nde
  2094. };
  2095. }
  2096. }
  2097. return null;
  2098. };
  2099. /**
  2100. * Checks if a nodes is in joints
  2101. */
  2102. var nodeIsInJoints = function (skins, id) {
  2103. for (var i = 0; i < skins.jointNames.length; i++) {
  2104. if (skins.jointNames[i] === id) {
  2105. return true;
  2106. }
  2107. }
  2108. return false;
  2109. };
  2110. /**
  2111. * Fills the nodes to root for bones and builds hierarchy
  2112. */
  2113. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2114. // Creates nodes for root
  2115. for (var nde in gltfRuntime.nodes) {
  2116. var node = gltfRuntime.nodes[nde];
  2117. var id = nde;
  2118. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2119. continue;
  2120. }
  2121. // Create node to root bone
  2122. var mat = configureBoneTransformation(node);
  2123. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2124. bone.id = id;
  2125. nodesToRoot.push({ bone: bone, node: node, id: id });
  2126. }
  2127. // Parenting
  2128. for (var i = 0; i < nodesToRoot.length; i++) {
  2129. var nodeToRoot = nodesToRoot[i];
  2130. var children = nodeToRoot.node.children;
  2131. for (var j = 0; j < children.length; j++) {
  2132. var child = null;
  2133. for (var k = 0; k < nodesToRoot.length; k++) {
  2134. if (nodesToRoot[k].id === children[j]) {
  2135. child = nodesToRoot[k];
  2136. break;
  2137. }
  2138. }
  2139. if (child) {
  2140. child.bone._parent = nodeToRoot.bone;
  2141. nodeToRoot.bone.children.push(child.bone);
  2142. }
  2143. }
  2144. }
  2145. };
  2146. /**
  2147. * Imports a skeleton
  2148. */
  2149. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2150. if (!newSkeleton) {
  2151. newSkeleton = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2152. }
  2153. if (!skins.babylonSkeleton) {
  2154. return newSkeleton;
  2155. }
  2156. // Find the root bones
  2157. var nodesToRoot = [];
  2158. var nodesToRootToAdd = [];
  2159. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2160. newSkeleton.bones = [];
  2161. // Joints
  2162. for (var i = 0; i < skins.jointNames.length; i++) {
  2163. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2164. if (!jointNode) {
  2165. continue;
  2166. }
  2167. var node = jointNode.node;
  2168. if (!node) {
  2169. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2170. continue;
  2171. }
  2172. var id = jointNode.id;
  2173. // Optimize, if the bone already exists...
  2174. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2175. if (existingBone) {
  2176. newSkeleton.bones.push(existingBone);
  2177. continue;
  2178. }
  2179. // Search for parent bone
  2180. var foundBone = false;
  2181. var parentBone = null;
  2182. for (var j = 0; j < i; j++) {
  2183. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2184. if (!jointNode_1) {
  2185. continue;
  2186. }
  2187. var joint = jointNode_1.node;
  2188. if (!joint) {
  2189. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2190. continue;
  2191. }
  2192. var children = joint.children;
  2193. if (!children) {
  2194. continue;
  2195. }
  2196. foundBone = false;
  2197. for (var k = 0; k < children.length; k++) {
  2198. if (children[k] === id) {
  2199. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2200. foundBone = true;
  2201. break;
  2202. }
  2203. }
  2204. if (foundBone) {
  2205. break;
  2206. }
  2207. }
  2208. // Create bone
  2209. var mat = configureBoneTransformation(node);
  2210. if (!parentBone && nodesToRoot.length > 0) {
  2211. parentBone = getNodeToRoot(nodesToRoot, id);
  2212. if (parentBone) {
  2213. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2214. nodesToRootToAdd.push(parentBone);
  2215. }
  2216. }
  2217. }
  2218. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2219. bone.id = id;
  2220. }
  2221. // Polish
  2222. var bones = newSkeleton.bones;
  2223. newSkeleton.bones = [];
  2224. for (var i = 0; i < skins.jointNames.length; i++) {
  2225. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2226. if (!jointNode) {
  2227. continue;
  2228. }
  2229. for (var j = 0; j < bones.length; j++) {
  2230. if (bones[j].id === jointNode.id) {
  2231. newSkeleton.bones.push(bones[j]);
  2232. break;
  2233. }
  2234. }
  2235. }
  2236. newSkeleton.prepare();
  2237. // Finish
  2238. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2239. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2240. }
  2241. return newSkeleton;
  2242. };
  2243. /**
  2244. * Imports a mesh and its geometries
  2245. */
  2246. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2247. if (!newMesh) {
  2248. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2249. newMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2250. gltfRuntime.scene._blockEntityCollection = false;
  2251. newMesh.id = id;
  2252. }
  2253. if (!node.babylonNode) {
  2254. return newMesh;
  2255. }
  2256. var subMaterials = [];
  2257. var vertexData = null;
  2258. var verticesStarts = new Array();
  2259. var verticesCounts = new Array();
  2260. var indexStarts = new Array();
  2261. var indexCounts = new Array();
  2262. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2263. var meshID = meshes[meshIndex];
  2264. var mesh = gltfRuntime.meshes[meshID];
  2265. if (!mesh) {
  2266. continue;
  2267. }
  2268. // Positions, normals and UVs
  2269. for (var i = 0; i < mesh.primitives.length; i++) {
  2270. // Temporary vertex data
  2271. var tempVertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2272. var primitive = mesh.primitives[i];
  2273. if (primitive.mode !== 4) {
  2274. // continue;
  2275. }
  2276. var attributes = primitive.attributes;
  2277. var accessor = null;
  2278. var buffer = null;
  2279. // Set positions, normal and uvs
  2280. for (var semantic in attributes) {
  2281. // Link accessor and buffer view
  2282. accessor = gltfRuntime.accessors[attributes[semantic]];
  2283. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2284. if (semantic === "NORMAL") {
  2285. tempVertexData.normals = new Float32Array(buffer.length);
  2286. tempVertexData.normals.set(buffer);
  2287. }
  2288. else if (semantic === "POSITION") {
  2289. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2290. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2291. for (var j = 0; j < buffer.length; j += 4) {
  2292. tempVertexData.positions[j] = buffer[j];
  2293. tempVertexData.positions[j + 1] = buffer[j + 1];
  2294. tempVertexData.positions[j + 2] = buffer[j + 2];
  2295. }
  2296. }
  2297. else {
  2298. tempVertexData.positions = new Float32Array(buffer.length);
  2299. tempVertexData.positions.set(buffer);
  2300. }
  2301. verticesCounts.push(tempVertexData.positions.length);
  2302. }
  2303. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2304. var channel = Number(semantic.split("_")[1]);
  2305. var uvKind = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2306. var uvs = new Float32Array(buffer.length);
  2307. uvs.set(buffer);
  2308. normalizeUVs(uvs);
  2309. tempVertexData.set(uvs, uvKind);
  2310. }
  2311. else if (semantic === "JOINT") {
  2312. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2313. tempVertexData.matricesIndices.set(buffer);
  2314. }
  2315. else if (semantic === "WEIGHT") {
  2316. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2317. tempVertexData.matricesWeights.set(buffer);
  2318. }
  2319. else if (semantic === "COLOR") {
  2320. tempVertexData.colors = new Float32Array(buffer.length);
  2321. tempVertexData.colors.set(buffer);
  2322. }
  2323. }
  2324. // Indices
  2325. accessor = gltfRuntime.accessors[primitive.indices];
  2326. if (accessor) {
  2327. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2328. tempVertexData.indices = new Int32Array(buffer.length);
  2329. tempVertexData.indices.set(buffer);
  2330. indexCounts.push(tempVertexData.indices.length);
  2331. }
  2332. else {
  2333. // Set indices on the fly
  2334. var indices = [];
  2335. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2336. indices.push(j);
  2337. }
  2338. tempVertexData.indices = new Int32Array(indices);
  2339. indexCounts.push(tempVertexData.indices.length);
  2340. }
  2341. if (!vertexData) {
  2342. vertexData = tempVertexData;
  2343. }
  2344. else {
  2345. vertexData.merge(tempVertexData);
  2346. }
  2347. // Sub material
  2348. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2349. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2350. // Update vertices start and index start
  2351. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2352. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2353. }
  2354. }
  2355. var material;
  2356. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2357. if (subMaterials.length > 1) {
  2358. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2359. material.subMaterials = subMaterials;
  2360. }
  2361. else {
  2362. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2363. }
  2364. if (subMaterials.length === 1) {
  2365. material = subMaterials[0];
  2366. }
  2367. if (!newMesh.material) {
  2368. newMesh.material = material;
  2369. }
  2370. // Apply geometry
  2371. new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2372. newMesh.computeWorldMatrix(true);
  2373. gltfRuntime.scene._blockEntityCollection = false;
  2374. // Apply submeshes
  2375. newMesh.subMeshes = [];
  2376. var index = 0;
  2377. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2378. var meshID = meshes[meshIndex];
  2379. var mesh = gltfRuntime.meshes[meshID];
  2380. if (!mesh) {
  2381. continue;
  2382. }
  2383. for (var i = 0; i < mesh.primitives.length; i++) {
  2384. if (mesh.primitives[i].mode !== 4) {
  2385. //continue;
  2386. }
  2387. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2388. index++;
  2389. }
  2390. }
  2391. // Finish
  2392. return newMesh;
  2393. };
  2394. /**
  2395. * Configure node transformation from position, rotation and scaling
  2396. */
  2397. var configureNode = function (newNode, position, rotation, scaling) {
  2398. if (newNode.position) {
  2399. newNode.position = position;
  2400. }
  2401. if (newNode.rotationQuaternion || newNode.rotation) {
  2402. newNode.rotationQuaternion = rotation;
  2403. }
  2404. if (newNode.scaling) {
  2405. newNode.scaling = scaling;
  2406. }
  2407. };
  2408. /**
  2409. * Configures node from transformation matrix
  2410. */
  2411. var configureNodeFromMatrix = function (newNode, node, parent) {
  2412. if (node.matrix) {
  2413. var position = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2414. var rotation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2415. var scaling = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2416. var mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2417. mat.decompose(scaling, rotation, position);
  2418. configureNode(newNode, position, rotation, scaling);
  2419. }
  2420. else if (node.translation && node.rotation && node.scale) {
  2421. 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));
  2422. }
  2423. newNode.computeWorldMatrix(true);
  2424. };
  2425. /**
  2426. * Imports a node
  2427. */
  2428. var importNode = function (gltfRuntime, node, id, parent) {
  2429. var lastNode = null;
  2430. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2431. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2432. return null;
  2433. }
  2434. }
  2435. // Meshes
  2436. if (node.skin) {
  2437. if (node.meshes) {
  2438. var skin = gltfRuntime.skins[node.skin];
  2439. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2440. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2441. if (newMesh.skeleton === null) {
  2442. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2443. if (!skin.babylonSkeleton) {
  2444. skin.babylonSkeleton = newMesh.skeleton;
  2445. }
  2446. }
  2447. lastNode = newMesh;
  2448. }
  2449. }
  2450. else if (node.meshes) {
  2451. /**
  2452. * Improve meshes property
  2453. */
  2454. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2455. lastNode = newMesh;
  2456. }
  2457. // Lights
  2458. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2459. var light = gltfRuntime.lights[node.light];
  2460. if (light) {
  2461. if (light.type === "ambient") {
  2462. var ambienLight = light[light.type];
  2463. 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);
  2464. hemiLight.name = node.name || "";
  2465. if (ambienLight.color) {
  2466. hemiLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2467. }
  2468. lastNode = hemiLight;
  2469. }
  2470. else if (light.type === "directional") {
  2471. var directionalLight = light[light.type];
  2472. 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);
  2473. dirLight.name = node.name || "";
  2474. if (directionalLight.color) {
  2475. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2476. }
  2477. lastNode = dirLight;
  2478. }
  2479. else if (light.type === "point") {
  2480. var pointLight = light[light.type];
  2481. 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);
  2482. ptLight.name = node.name || "";
  2483. if (pointLight.color) {
  2484. ptLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2485. }
  2486. lastNode = ptLight;
  2487. }
  2488. else if (light.type === "spot") {
  2489. var spotLight = light[light.type];
  2490. 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);
  2491. spLight.name = node.name || "";
  2492. if (spotLight.color) {
  2493. spLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2494. }
  2495. if (spotLight.fallOfAngle) {
  2496. spLight.angle = spotLight.fallOfAngle;
  2497. }
  2498. if (spotLight.fallOffExponent) {
  2499. spLight.exponent = spotLight.fallOffExponent;
  2500. }
  2501. lastNode = spLight;
  2502. }
  2503. }
  2504. }
  2505. // Cameras
  2506. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2507. var camera = gltfRuntime.cameras[node.camera];
  2508. if (camera) {
  2509. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2510. if (camera.type === "orthographic") {
  2511. 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);
  2512. orthoCamera.name = node.name || "";
  2513. orthoCamera.mode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2514. orthoCamera.attachControl();
  2515. lastNode = orthoCamera;
  2516. }
  2517. else if (camera.type === "perspective") {
  2518. var perspectiveCamera = camera[camera.type];
  2519. 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);
  2520. persCamera.name = node.name || "";
  2521. persCamera.attachControl();
  2522. if (!perspectiveCamera.aspectRatio) {
  2523. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2524. }
  2525. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2526. persCamera.maxZ = perspectiveCamera.zfar;
  2527. persCamera.minZ = perspectiveCamera.znear;
  2528. }
  2529. lastNode = persCamera;
  2530. }
  2531. gltfRuntime.scene._blockEntityCollection = false;
  2532. }
  2533. }
  2534. // Empty node
  2535. if (!node.jointName) {
  2536. if (node.babylonNode) {
  2537. return node.babylonNode;
  2538. }
  2539. else if (lastNode === null) {
  2540. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2541. var dummy = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2542. gltfRuntime.scene._blockEntityCollection = false;
  2543. node.babylonNode = dummy;
  2544. lastNode = dummy;
  2545. }
  2546. }
  2547. if (lastNode !== null) {
  2548. if (node.matrix && lastNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2549. configureNodeFromMatrix(lastNode, node, parent);
  2550. }
  2551. else {
  2552. var translation = node.translation || [0, 0, 0];
  2553. var rotation = node.rotation || [0, 0, 0, 1];
  2554. var scale = node.scale || [1, 1, 1];
  2555. 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));
  2556. }
  2557. lastNode.updateCache(true);
  2558. node.babylonNode = lastNode;
  2559. }
  2560. return lastNode;
  2561. };
  2562. /**
  2563. * Traverses nodes and creates them
  2564. */
  2565. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2566. if (meshIncluded === void 0) { meshIncluded = false; }
  2567. var node = gltfRuntime.nodes[id];
  2568. var newNode = null;
  2569. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2570. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2571. meshIncluded = true;
  2572. }
  2573. else {
  2574. meshIncluded = false;
  2575. }
  2576. }
  2577. else {
  2578. meshIncluded = true;
  2579. }
  2580. if (!node.jointName && meshIncluded) {
  2581. newNode = importNode(gltfRuntime, node, id, parent);
  2582. if (newNode !== null) {
  2583. newNode.id = id;
  2584. newNode.parent = parent;
  2585. }
  2586. }
  2587. if (node.children) {
  2588. for (var i = 0; i < node.children.length; i++) {
  2589. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2590. }
  2591. }
  2592. };
  2593. /**
  2594. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2595. */
  2596. var postLoad = function (gltfRuntime) {
  2597. // Nodes
  2598. var currentScene = gltfRuntime.currentScene;
  2599. if (currentScene) {
  2600. for (var i = 0; i < currentScene.nodes.length; i++) {
  2601. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2602. }
  2603. }
  2604. else {
  2605. for (var thing in gltfRuntime.scenes) {
  2606. currentScene = gltfRuntime.scenes[thing];
  2607. for (var i = 0; i < currentScene.nodes.length; i++) {
  2608. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2609. }
  2610. }
  2611. }
  2612. // Set animations
  2613. loadAnimations(gltfRuntime);
  2614. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2615. var skeleton = gltfRuntime.scene.skeletons[i];
  2616. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2617. }
  2618. };
  2619. /**
  2620. * onBind shaderrs callback to set uniforms and matrices
  2621. */
  2622. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2623. var materialValues = material.values || technique.parameters;
  2624. for (var unif in unTreatedUniforms) {
  2625. var uniform = unTreatedUniforms[unif];
  2626. var type = uniform.type;
  2627. 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) {
  2628. if (uniform.semantic && !uniform.source && !uniform.node) {
  2629. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2630. }
  2631. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2632. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2633. if (source === null) {
  2634. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2635. }
  2636. if (source === null) {
  2637. continue;
  2638. }
  2639. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2640. }
  2641. }
  2642. else {
  2643. var value = materialValues[technique.uniforms[unif]];
  2644. if (!value) {
  2645. continue;
  2646. }
  2647. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2648. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2649. if (texture === null || texture === undefined) {
  2650. continue;
  2651. }
  2652. shaderMaterial.getEffect().setTexture(unif, texture);
  2653. }
  2654. else {
  2655. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2656. }
  2657. }
  2658. }
  2659. onSuccess(shaderMaterial);
  2660. };
  2661. /**
  2662. * Prepare uniforms to send the only one time
  2663. * Loads the appropriate textures
  2664. */
  2665. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2666. var materialValues = material.values || technique.parameters;
  2667. var techniqueUniforms = technique.uniforms;
  2668. /**
  2669. * Prepare values here (not matrices)
  2670. */
  2671. for (var unif in unTreatedUniforms) {
  2672. var uniform = unTreatedUniforms[unif];
  2673. var type = uniform.type;
  2674. var value = materialValues[techniqueUniforms[unif]];
  2675. if (value === undefined) {
  2676. // In case the value is the same for all materials
  2677. value = uniform.value;
  2678. }
  2679. if (!value) {
  2680. continue;
  2681. }
  2682. var onLoadTexture = function (uniformName) {
  2683. return function (texture) {
  2684. if (uniform.value && uniformName) {
  2685. // Static uniform
  2686. shaderMaterial.setTexture(uniformName, texture);
  2687. delete unTreatedUniforms[uniformName];
  2688. }
  2689. };
  2690. };
  2691. // Texture (sampler2D)
  2692. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2693. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2694. }
  2695. // Others
  2696. else {
  2697. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2698. // Static uniform
  2699. delete unTreatedUniforms[unif];
  2700. }
  2701. }
  2702. }
  2703. };
  2704. /**
  2705. * Shader compilation failed
  2706. */
  2707. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2708. return function (effect, error) {
  2709. shaderMaterial.dispose(true);
  2710. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2711. };
  2712. };
  2713. /**
  2714. * Shader compilation success
  2715. */
  2716. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2717. return function (_) {
  2718. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2719. shaderMaterial.onBind = function (mesh) {
  2720. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2721. };
  2722. };
  2723. };
  2724. /**
  2725. * Returns the appropriate uniform if already handled by babylon
  2726. */
  2727. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2728. for (var unif in technique.uniforms) {
  2729. var uniform = technique.uniforms[unif];
  2730. var uniformParameter = technique.parameters[uniform];
  2731. if (tokenizer.currentIdentifier === unif) {
  2732. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2733. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2734. if (transformIndex !== -1) {
  2735. delete unTreatedUniforms[unif];
  2736. return babylonTransforms[transformIndex];
  2737. }
  2738. }
  2739. }
  2740. }
  2741. return tokenizer.currentIdentifier;
  2742. };
  2743. /**
  2744. * All shaders loaded. Create materials one by one
  2745. */
  2746. var importMaterials = function (gltfRuntime) {
  2747. // Create materials
  2748. for (var mat in gltfRuntime.materials) {
  2749. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2750. }
  2751. };
  2752. /**
  2753. * Implementation of the base glTF spec
  2754. * @hidden
  2755. */
  2756. var GLTFLoaderBase = /** @class */ (function () {
  2757. function GLTFLoaderBase() {
  2758. }
  2759. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2760. var gltfRuntime = {
  2761. extensions: {},
  2762. accessors: {},
  2763. buffers: {},
  2764. bufferViews: {},
  2765. meshes: {},
  2766. lights: {},
  2767. cameras: {},
  2768. nodes: {},
  2769. images: {},
  2770. textures: {},
  2771. shaders: {},
  2772. programs: {},
  2773. samplers: {},
  2774. techniques: {},
  2775. materials: {},
  2776. animations: {},
  2777. skins: {},
  2778. extensionsUsed: [],
  2779. scenes: {},
  2780. buffersCount: 0,
  2781. shaderscount: 0,
  2782. scene: scene,
  2783. rootUrl: rootUrl,
  2784. loadedBufferCount: 0,
  2785. loadedBufferViews: {},
  2786. loadedShaderCount: 0,
  2787. importOnlyMeshes: false,
  2788. dummyNodes: [],
  2789. forAssetContainer: false
  2790. };
  2791. // Parse
  2792. if (parsedData.extensions) {
  2793. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2794. }
  2795. if (parsedData.extensionsUsed) {
  2796. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2797. }
  2798. if (parsedData.buffers) {
  2799. parseBuffers(parsedData.buffers, gltfRuntime);
  2800. }
  2801. if (parsedData.bufferViews) {
  2802. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2803. }
  2804. if (parsedData.accessors) {
  2805. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2806. }
  2807. if (parsedData.meshes) {
  2808. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2809. }
  2810. if (parsedData.lights) {
  2811. parseObject(parsedData.lights, "lights", gltfRuntime);
  2812. }
  2813. if (parsedData.cameras) {
  2814. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2815. }
  2816. if (parsedData.nodes) {
  2817. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2818. }
  2819. if (parsedData.images) {
  2820. parseObject(parsedData.images, "images", gltfRuntime);
  2821. }
  2822. if (parsedData.textures) {
  2823. parseObject(parsedData.textures, "textures", gltfRuntime);
  2824. }
  2825. if (parsedData.shaders) {
  2826. parseShaders(parsedData.shaders, gltfRuntime);
  2827. }
  2828. if (parsedData.programs) {
  2829. parseObject(parsedData.programs, "programs", gltfRuntime);
  2830. }
  2831. if (parsedData.samplers) {
  2832. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2833. }
  2834. if (parsedData.techniques) {
  2835. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2836. }
  2837. if (parsedData.materials) {
  2838. parseObject(parsedData.materials, "materials", gltfRuntime);
  2839. }
  2840. if (parsedData.animations) {
  2841. parseObject(parsedData.animations, "animations", gltfRuntime);
  2842. }
  2843. if (parsedData.skins) {
  2844. parseObject(parsedData.skins, "skins", gltfRuntime);
  2845. }
  2846. if (parsedData.scenes) {
  2847. gltfRuntime.scenes = parsedData.scenes;
  2848. }
  2849. if (parsedData.scene && parsedData.scenes) {
  2850. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2851. }
  2852. return gltfRuntime;
  2853. };
  2854. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2855. var buffer = gltfRuntime.buffers[id];
  2856. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2857. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2858. }
  2859. else {
  2860. 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) {
  2861. if (request) {
  2862. onError(request.status + " " + request.statusText);
  2863. }
  2864. });
  2865. }
  2866. };
  2867. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2868. var texture = gltfRuntime.textures[id];
  2869. if (!texture || !texture.source) {
  2870. onError("");
  2871. return;
  2872. }
  2873. if (texture.babylonTexture) {
  2874. onSuccess(null);
  2875. return;
  2876. }
  2877. var source = gltfRuntime.images[texture.source];
  2878. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2879. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2880. }
  2881. else {
  2882. 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) {
  2883. if (request) {
  2884. onError(request.status + " " + request.statusText);
  2885. }
  2886. });
  2887. }
  2888. };
  2889. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2890. var texture = gltfRuntime.textures[id];
  2891. if (texture.babylonTexture) {
  2892. onSuccess(texture.babylonTexture);
  2893. return;
  2894. }
  2895. var sampler = gltfRuntime.samplers[texture.sampler];
  2896. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2897. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2898. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2899. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2900. var samplingMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2901. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2902. var blobURL = URL.createObjectURL(blob);
  2903. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2904. var newTexture = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2905. if (sampler.wrapS !== undefined) {
  2906. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2907. }
  2908. if (sampler.wrapT !== undefined) {
  2909. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2910. }
  2911. newTexture.name = id;
  2912. texture.babylonTexture = newTexture;
  2913. onSuccess(newTexture);
  2914. };
  2915. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2916. var shader = gltfRuntime.shaders[id];
  2917. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2918. var shaderString = atob(shader.uri.split(",")[1]);
  2919. if (onSuccess) {
  2920. onSuccess(shaderString);
  2921. }
  2922. }
  2923. else {
  2924. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2925. if (request && onError) {
  2926. onError(request.status + " " + request.statusText);
  2927. }
  2928. });
  2929. }
  2930. };
  2931. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2932. var material = gltfRuntime.materials[id];
  2933. if (!material.technique) {
  2934. if (onError) {
  2935. onError("No technique found.");
  2936. }
  2937. return;
  2938. }
  2939. var technique = gltfRuntime.techniques[material.technique];
  2940. if (!technique) {
  2941. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2942. var defaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2943. gltfRuntime.scene._blockEntityCollection = false;
  2944. defaultMaterial.diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2945. defaultMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2946. onSuccess(defaultMaterial);
  2947. return;
  2948. }
  2949. var program = gltfRuntime.programs[technique.program];
  2950. var states = technique.states;
  2951. var vertexShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2952. var pixelShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2953. var newVertexShader = "";
  2954. var newPixelShader = "";
  2955. var vertexTokenizer = new Tokenizer(vertexShader);
  2956. var pixelTokenizer = new Tokenizer(pixelShader);
  2957. var unTreatedUniforms = {};
  2958. var uniforms = [];
  2959. var attributes = [];
  2960. var samplers = [];
  2961. // Fill uniform, sampler2D and attributes
  2962. for (var unif in technique.uniforms) {
  2963. var uniform = technique.uniforms[unif];
  2964. var uniformParameter = technique.parameters[uniform];
  2965. unTreatedUniforms[unif] = uniformParameter;
  2966. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2967. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2968. if (transformIndex !== -1) {
  2969. uniforms.push(babylonTransforms[transformIndex]);
  2970. delete unTreatedUniforms[unif];
  2971. }
  2972. else {
  2973. uniforms.push(unif);
  2974. }
  2975. }
  2976. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2977. samplers.push(unif);
  2978. }
  2979. else {
  2980. uniforms.push(unif);
  2981. }
  2982. }
  2983. for (var attr in technique.attributes) {
  2984. var attribute = technique.attributes[attr];
  2985. var attributeParameter = technique.parameters[attribute];
  2986. if (attributeParameter.semantic) {
  2987. var name_1 = getAttribute(attributeParameter);
  2988. if (name_1) {
  2989. attributes.push(name_1);
  2990. }
  2991. }
  2992. }
  2993. // Configure vertex shader
  2994. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2995. var tokenType = vertexTokenizer.currentToken;
  2996. if (tokenType !== ETokenType.IDENTIFIER) {
  2997. newVertexShader += vertexTokenizer.currentString;
  2998. continue;
  2999. }
  3000. var foundAttribute = false;
  3001. for (var attr in technique.attributes) {
  3002. var attribute = technique.attributes[attr];
  3003. var attributeParameter = technique.parameters[attribute];
  3004. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  3005. newVertexShader += getAttribute(attributeParameter);
  3006. foundAttribute = true;
  3007. break;
  3008. }
  3009. }
  3010. if (foundAttribute) {
  3011. continue;
  3012. }
  3013. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  3014. }
  3015. // Configure pixel shader
  3016. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  3017. var tokenType = pixelTokenizer.currentToken;
  3018. if (tokenType !== ETokenType.IDENTIFIER) {
  3019. newPixelShader += pixelTokenizer.currentString;
  3020. continue;
  3021. }
  3022. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  3023. }
  3024. // Create shader material
  3025. var shaderPath = {
  3026. vertex: program.vertexShader + id,
  3027. fragment: program.fragmentShader + id
  3028. };
  3029. var options = {
  3030. attributes: attributes,
  3031. uniforms: uniforms,
  3032. samplers: samplers,
  3033. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  3034. };
  3035. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  3036. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  3037. var shaderMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  3038. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  3039. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  3040. shaderMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  3041. if (states && states.functions) {
  3042. var functions = states.functions;
  3043. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  3044. shaderMaterial.backFaceCulling = false;
  3045. }
  3046. var blendFunc = functions.blendFuncSeparate;
  3047. if (blendFunc) {
  3048. 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) {
  3049. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  3050. }
  3051. 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) {
  3052. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  3053. }
  3054. 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) {
  3055. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  3056. }
  3057. 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) {
  3058. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  3059. }
  3060. 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) {
  3061. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  3062. }
  3063. 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) {
  3064. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  3065. }
  3066. }
  3067. }
  3068. };
  3069. return GLTFLoaderBase;
  3070. }());
  3071. /**
  3072. * glTF V1 Loader
  3073. * @hidden
  3074. */
  3075. var GLTFLoader = /** @class */ (function () {
  3076. function GLTFLoader() {
  3077. this.state = null;
  3078. }
  3079. GLTFLoader.RegisterExtension = function (extension) {
  3080. if (GLTFLoader.Extensions[extension.name]) {
  3081. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  3082. return;
  3083. }
  3084. GLTFLoader.Extensions[extension.name] = extension;
  3085. };
  3086. GLTFLoader.prototype.dispose = function () {
  3087. // do nothing
  3088. };
  3089. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3090. var _this = this;
  3091. scene.useRightHandedSystem = true;
  3092. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3093. gltfRuntime.forAssetContainer = forAssetContainer;
  3094. gltfRuntime.importOnlyMeshes = true;
  3095. if (meshesNames === "") {
  3096. gltfRuntime.importMeshesNames = [];
  3097. }
  3098. else if (typeof meshesNames === "string") {
  3099. gltfRuntime.importMeshesNames = [meshesNames];
  3100. }
  3101. else if (meshesNames && !(meshesNames instanceof Array)) {
  3102. gltfRuntime.importMeshesNames = [meshesNames];
  3103. }
  3104. else {
  3105. gltfRuntime.importMeshesNames = [];
  3106. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3107. }
  3108. // Create nodes
  3109. _this._createNodes(gltfRuntime);
  3110. var meshes = new Array();
  3111. var skeletons = new Array();
  3112. // Fill arrays of meshes and skeletons
  3113. for (var nde in gltfRuntime.nodes) {
  3114. var node = gltfRuntime.nodes[nde];
  3115. if (node.babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3116. meshes.push(node.babylonNode);
  3117. }
  3118. }
  3119. for (var skl in gltfRuntime.skins) {
  3120. var skin = gltfRuntime.skins[skl];
  3121. if (skin.babylonSkeleton instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3122. skeletons.push(skin.babylonSkeleton);
  3123. }
  3124. }
  3125. // Load buffers, shaders, materials, etc.
  3126. _this._loadBuffersAsync(gltfRuntime, function () {
  3127. _this._loadShadersAsync(gltfRuntime, function () {
  3128. importMaterials(gltfRuntime);
  3129. postLoad(gltfRuntime);
  3130. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3131. onSuccess(meshes, skeletons);
  3132. }
  3133. });
  3134. }, onProgress);
  3135. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3136. onSuccess(meshes, skeletons);
  3137. }
  3138. }, onError);
  3139. return true;
  3140. };
  3141. /**
  3142. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3143. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3144. * @param scene the scene the meshes should be added to
  3145. * @param forAssetContainer defines if the entities must be stored in the scene
  3146. * @param data gltf data containing information of the meshes in a loaded file
  3147. * @param rootUrl root url to load from
  3148. * @param onProgress event that fires when loading progress has occured
  3149. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3150. */
  3151. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress) {
  3152. var _this = this;
  3153. return new Promise(function (resolve, reject) {
  3154. _this._importMeshAsync(meshesNames, scene, data, rootUrl, forAssetContainer, function (meshes, skeletons) {
  3155. resolve({
  3156. meshes: meshes,
  3157. particleSystems: [],
  3158. skeletons: skeletons,
  3159. animationGroups: [],
  3160. lights: [],
  3161. transformNodes: [],
  3162. geometries: []
  3163. });
  3164. }, onProgress, function (message) {
  3165. reject(new Error(message));
  3166. });
  3167. });
  3168. };
  3169. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3170. var _this = this;
  3171. scene.useRightHandedSystem = true;
  3172. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3173. // Load runtime extensios
  3174. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3175. // Create nodes
  3176. _this._createNodes(gltfRuntime);
  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) {
  3183. onSuccess();
  3184. }
  3185. });
  3186. });
  3187. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3188. onSuccess();
  3189. }
  3190. }, onError);
  3191. }, onError);
  3192. };
  3193. /**
  3194. * Imports all objects from a loaded gltf file and adds them to the scene
  3195. * @param scene the scene the objects should be added to
  3196. * @param data gltf data containing information of the meshes in a loaded file
  3197. * @param rootUrl root url to load from
  3198. * @param onProgress event that fires when loading progress has occured
  3199. * @returns a promise which completes when objects have been loaded to the scene
  3200. */
  3201. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3202. var _this = this;
  3203. return new Promise(function (resolve, reject) {
  3204. _this._loadAsync(scene, data, rootUrl, false, function () {
  3205. resolve();
  3206. }, onProgress, function (message) {
  3207. reject(new Error(message));
  3208. });
  3209. });
  3210. };
  3211. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3212. var hasShaders = false;
  3213. var processShader = function (sha, shader) {
  3214. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3215. if (shaderString instanceof ArrayBuffer) {
  3216. return;
  3217. }
  3218. gltfRuntime.loadedShaderCount++;
  3219. if (shaderString) {
  3220. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3221. }
  3222. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3223. onload();
  3224. }
  3225. }, function () {
  3226. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3227. });
  3228. };
  3229. for (var sha in gltfRuntime.shaders) {
  3230. hasShaders = true;
  3231. var shader = gltfRuntime.shaders[sha];
  3232. if (shader) {
  3233. processShader.bind(this, sha, shader)();
  3234. }
  3235. else {
  3236. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3237. }
  3238. }
  3239. if (!hasShaders) {
  3240. onload();
  3241. }
  3242. };
  3243. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3244. var hasBuffers = false;
  3245. var processBuffer = function (buf, buffer) {
  3246. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3247. gltfRuntime.loadedBufferCount++;
  3248. if (bufferView) {
  3249. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3250. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3251. }
  3252. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3253. }
  3254. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3255. onLoad();
  3256. }
  3257. }, function () {
  3258. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3259. });
  3260. };
  3261. for (var buf in gltfRuntime.buffers) {
  3262. hasBuffers = true;
  3263. var buffer = gltfRuntime.buffers[buf];
  3264. if (buffer) {
  3265. processBuffer.bind(this, buf, buffer)();
  3266. }
  3267. else {
  3268. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3269. }
  3270. }
  3271. if (!hasBuffers) {
  3272. onLoad();
  3273. }
  3274. };
  3275. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3276. var currentScene = gltfRuntime.currentScene;
  3277. if (currentScene) {
  3278. // Only one scene even if multiple scenes are defined
  3279. for (var i = 0; i < currentScene.nodes.length; i++) {
  3280. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3281. }
  3282. }
  3283. else {
  3284. // Load all scenes
  3285. for (var thing in gltfRuntime.scenes) {
  3286. currentScene = gltfRuntime.scenes[thing];
  3287. for (var i = 0; i < currentScene.nodes.length; i++) {
  3288. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3289. }
  3290. }
  3291. }
  3292. };
  3293. GLTFLoader.Extensions = {};
  3294. return GLTFLoader;
  3295. }());
  3296. /** @hidden */
  3297. var GLTFLoaderExtension = /** @class */ (function () {
  3298. function GLTFLoaderExtension(name) {
  3299. this._name = name;
  3300. }
  3301. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3302. get: function () {
  3303. return this._name;
  3304. },
  3305. enumerable: false,
  3306. configurable: true
  3307. });
  3308. /**
  3309. * Defines an override for loading the runtime
  3310. * Return true to stop further extensions from loading the runtime
  3311. */
  3312. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3313. return false;
  3314. };
  3315. /**
  3316. * Defines an onverride for creating gltf runtime
  3317. * Return true to stop further extensions from creating the runtime
  3318. */
  3319. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3320. return false;
  3321. };
  3322. /**
  3323. * Defines an override for loading buffers
  3324. * Return true to stop further extensions from loading this buffer
  3325. */
  3326. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3327. return false;
  3328. };
  3329. /**
  3330. * Defines an override for loading texture buffers
  3331. * Return true to stop further extensions from loading this texture data
  3332. */
  3333. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3334. return false;
  3335. };
  3336. /**
  3337. * Defines an override for creating textures
  3338. * Return true to stop further extensions from loading this texture
  3339. */
  3340. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3341. return false;
  3342. };
  3343. /**
  3344. * Defines an override for loading shader strings
  3345. * Return true to stop further extensions from loading this shader data
  3346. */
  3347. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3348. return false;
  3349. };
  3350. /**
  3351. * Defines an override for loading materials
  3352. * Return true to stop further extensions from loading this material
  3353. */
  3354. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3355. return false;
  3356. };
  3357. // ---------
  3358. // Utilities
  3359. // ---------
  3360. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3361. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3362. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3363. }, function () {
  3364. setTimeout(function () {
  3365. if (!onSuccess) {
  3366. return;
  3367. }
  3368. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3369. });
  3370. });
  3371. };
  3372. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3373. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3374. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3375. }, function () {
  3376. setTimeout(function () {
  3377. onSuccess();
  3378. });
  3379. });
  3380. };
  3381. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3382. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3383. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3384. }, function () {
  3385. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3386. });
  3387. };
  3388. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3389. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3390. if (buffer) {
  3391. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3392. }
  3393. }, onError);
  3394. };
  3395. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3396. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3397. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3398. }, function () {
  3399. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3400. });
  3401. };
  3402. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3403. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3404. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3405. }, function () {
  3406. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3407. });
  3408. };
  3409. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3410. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3411. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3412. }, function () {
  3413. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3414. });
  3415. };
  3416. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3417. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3418. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3419. }, function () {
  3420. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3421. });
  3422. };
  3423. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3424. for (var extensionName in GLTFLoader.Extensions) {
  3425. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3426. if (func(loaderExtension)) {
  3427. return;
  3428. }
  3429. }
  3430. defaultFunc();
  3431. };
  3432. return GLTFLoaderExtension;
  3433. }());
  3434. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3435. /***/ }),
  3436. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3437. /*!******************************************!*\
  3438. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3439. \******************************************/
  3440. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3441. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3442. "use strict";
  3443. __webpack_require__.r(__webpack_exports__);
  3444. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3445. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3446. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3447. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3448. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3449. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3450. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3451. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3452. /**
  3453. * Enums
  3454. * @hidden
  3455. */
  3456. var EComponentType;
  3457. (function (EComponentType) {
  3458. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3459. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3460. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3461. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3462. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3463. })(EComponentType || (EComponentType = {}));
  3464. /** @hidden */
  3465. var EShaderType;
  3466. (function (EShaderType) {
  3467. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3468. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3469. })(EShaderType || (EShaderType = {}));
  3470. /** @hidden */
  3471. var EParameterType;
  3472. (function (EParameterType) {
  3473. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3474. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3475. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3476. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3477. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3478. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3479. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3480. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3481. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3482. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3483. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3484. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3485. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3486. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3487. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3488. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3489. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3490. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3491. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3492. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3493. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3494. })(EParameterType || (EParameterType = {}));
  3495. /** @hidden */
  3496. var ETextureWrapMode;
  3497. (function (ETextureWrapMode) {
  3498. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3499. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3500. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3501. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3502. /** @hidden */
  3503. var ETextureFilterType;
  3504. (function (ETextureFilterType) {
  3505. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3506. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3507. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3508. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3509. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3510. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3511. })(ETextureFilterType || (ETextureFilterType = {}));
  3512. /** @hidden */
  3513. var ETextureFormat;
  3514. (function (ETextureFormat) {
  3515. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3516. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3517. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3518. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3519. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3520. })(ETextureFormat || (ETextureFormat = {}));
  3521. /** @hidden */
  3522. var ECullingType;
  3523. (function (ECullingType) {
  3524. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3525. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3526. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3527. })(ECullingType || (ECullingType = {}));
  3528. /** @hidden */
  3529. var EBlendingFunction;
  3530. (function (EBlendingFunction) {
  3531. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3532. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3533. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3534. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3535. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3536. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3537. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3538. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3539. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3540. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3541. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3542. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3543. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3544. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3545. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3546. })(EBlendingFunction || (EBlendingFunction = {}));
  3547. /***/ }),
  3548. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3549. /*!*************************************!*\
  3550. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3551. \*************************************/
  3552. /*! exports provided: GLTFUtils */
  3553. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3554. "use strict";
  3555. __webpack_require__.r(__webpack_exports__);
  3556. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3557. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3558. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  3559. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  3560. /**
  3561. * Utils functions for GLTF
  3562. * @hidden
  3563. */
  3564. var GLTFUtils = /** @class */ (function () {
  3565. function GLTFUtils() {
  3566. }
  3567. /**
  3568. * Sets the given "parameter" matrix
  3569. * @param scene: the Scene object
  3570. * @param source: the source node where to pick the matrix
  3571. * @param parameter: the GLTF technique parameter
  3572. * @param uniformName: the name of the shader's uniform
  3573. * @param shaderMaterial: the shader material
  3574. */
  3575. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3576. var mat = null;
  3577. if (parameter.semantic === "MODEL") {
  3578. mat = source.getWorldMatrix();
  3579. }
  3580. else if (parameter.semantic === "PROJECTION") {
  3581. mat = scene.getProjectionMatrix();
  3582. }
  3583. else if (parameter.semantic === "VIEW") {
  3584. mat = scene.getViewMatrix();
  3585. }
  3586. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3587. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3588. }
  3589. else if (parameter.semantic === "MODELVIEW") {
  3590. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3591. }
  3592. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3593. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3594. }
  3595. else if (parameter.semantic === "MODELINVERSE") {
  3596. mat = source.getWorldMatrix().invert();
  3597. }
  3598. else if (parameter.semantic === "VIEWINVERSE") {
  3599. mat = scene.getViewMatrix().invert();
  3600. }
  3601. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3602. mat = scene.getProjectionMatrix().invert();
  3603. }
  3604. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3605. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3606. }
  3607. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3608. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3609. }
  3610. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3611. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3612. }
  3613. else {
  3614. debugger;
  3615. }
  3616. if (mat) {
  3617. switch (parameter.type) {
  3618. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3619. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3620. break;
  3621. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3622. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3623. break;
  3624. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3625. shaderMaterial.setMatrix(uniformName, mat);
  3626. break;
  3627. default: break;
  3628. }
  3629. }
  3630. };
  3631. /**
  3632. * Sets the given "parameter" matrix
  3633. * @param shaderMaterial: the shader material
  3634. * @param uniform: the name of the shader's uniform
  3635. * @param value: the value of the uniform
  3636. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3637. */
  3638. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3639. switch (type) {
  3640. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3641. shaderMaterial.setFloat(uniform, value);
  3642. return true;
  3643. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3644. shaderMaterial.setVector2(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3645. return true;
  3646. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3647. shaderMaterial.setVector3(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3648. return true;
  3649. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3650. shaderMaterial.setVector4(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3651. return true;
  3652. default: return false;
  3653. }
  3654. };
  3655. /**
  3656. * Returns the wrap mode of the texture
  3657. * @param mode: the mode value
  3658. */
  3659. GLTFUtils.GetWrapMode = function (mode) {
  3660. switch (mode) {
  3661. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3662. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3663. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3664. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3665. }
  3666. };
  3667. /**
  3668. * Returns the byte stride giving an accessor
  3669. * @param accessor: the GLTF accessor objet
  3670. */
  3671. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3672. // Needs this function since "byteStride" isn't requiered in glTF format
  3673. var type = accessor.type;
  3674. switch (type) {
  3675. case "VEC2": return 2;
  3676. case "VEC3": return 3;
  3677. case "VEC4": return 4;
  3678. case "MAT2": return 4;
  3679. case "MAT3": return 9;
  3680. case "MAT4": return 16;
  3681. default: return 1;
  3682. }
  3683. };
  3684. /**
  3685. * Returns the texture filter mode giving a mode value
  3686. * @param mode: the filter mode value
  3687. */
  3688. GLTFUtils.GetTextureFilterMode = function (mode) {
  3689. switch (mode) {
  3690. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3691. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3692. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3693. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3694. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3695. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3696. }
  3697. };
  3698. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3699. var byteOffset = bufferView.byteOffset + byteOffset;
  3700. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3701. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3702. throw new Error("Buffer access is out of range");
  3703. }
  3704. var buffer = loadedBufferView.buffer;
  3705. byteOffset += loadedBufferView.byteOffset;
  3706. switch (componentType) {
  3707. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3708. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3709. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3710. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3711. default: return new Float32Array(buffer, byteOffset, byteLength);
  3712. }
  3713. };
  3714. /**
  3715. * Returns a buffer from its accessor
  3716. * @param gltfRuntime: the GLTF runtime
  3717. * @param accessor: the GLTF accessor
  3718. */
  3719. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3720. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3721. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3722. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3723. };
  3724. /**
  3725. * Decodes a buffer view into a string
  3726. * @param view: the buffer view
  3727. */
  3728. GLTFUtils.DecodeBufferToText = function (view) {
  3729. var result = "";
  3730. var length = view.byteLength;
  3731. for (var i = 0; i < length; ++i) {
  3732. result += String.fromCharCode(view[i]);
  3733. }
  3734. return result;
  3735. };
  3736. /**
  3737. * Returns the default material of gltf. Related to
  3738. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3739. * @param scene: the Babylon.js scene
  3740. */
  3741. GLTFUtils.GetDefaultMaterial = function (scene) {
  3742. if (!GLTFUtils._DefaultMaterial) {
  3743. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3744. "precision highp float;",
  3745. "",
  3746. "uniform mat4 worldView;",
  3747. "uniform mat4 projection;",
  3748. "",
  3749. "attribute vec3 position;",
  3750. "",
  3751. "void main(void)",
  3752. "{",
  3753. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3754. "}"
  3755. ].join("\n");
  3756. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3757. "precision highp float;",
  3758. "",
  3759. "uniform vec4 u_emission;",
  3760. "",
  3761. "void main(void)",
  3762. "{",
  3763. " gl_FragColor = u_emission;",
  3764. "}"
  3765. ].join("\n");
  3766. var shaderPath = {
  3767. vertex: "GLTFDefaultMaterial",
  3768. fragment: "GLTFDefaultMaterial"
  3769. };
  3770. var options = {
  3771. attributes: ["position"],
  3772. uniforms: ["worldView", "projection", "u_emission"],
  3773. samplers: new Array(),
  3774. needAlphaBlending: false
  3775. };
  3776. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3777. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3778. }
  3779. return GLTFUtils._DefaultMaterial;
  3780. };
  3781. // The GLTF default material
  3782. GLTFUtils._DefaultMaterial = null;
  3783. return GLTFUtils;
  3784. }());
  3785. /***/ }),
  3786. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3787. /*!**************************************************!*\
  3788. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3789. \**************************************************/
  3790. /*! exports provided: GLTFMaterialsCommonExtension */
  3791. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3792. "use strict";
  3793. __webpack_require__.r(__webpack_exports__);
  3794. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3795. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3796. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3797. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  3798. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__);
  3799. /** @hidden */
  3800. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3801. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3802. function GLTFMaterialsCommonExtension() {
  3803. return _super.call(this, "KHR_materials_common") || this;
  3804. }
  3805. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3806. if (!gltfRuntime.extensions) {
  3807. return false;
  3808. }
  3809. var extension = gltfRuntime.extensions[this.name];
  3810. if (!extension) {
  3811. return false;
  3812. }
  3813. // Create lights
  3814. var lights = extension.lights;
  3815. if (lights) {
  3816. for (var thing in lights) {
  3817. var light = lights[thing];
  3818. switch (light.type) {
  3819. case "ambient":
  3820. 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);
  3821. var ambient = light.ambient;
  3822. if (ambient) {
  3823. ambientLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3824. }
  3825. break;
  3826. case "point":
  3827. 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);
  3828. var point = light.point;
  3829. if (point) {
  3830. pointLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3831. }
  3832. break;
  3833. case "directional":
  3834. 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);
  3835. var directional = light.directional;
  3836. if (directional) {
  3837. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3838. }
  3839. break;
  3840. case "spot":
  3841. var spot = light.spot;
  3842. if (spot) {
  3843. 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);
  3844. spotLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3845. }
  3846. break;
  3847. default:
  3848. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3849. break;
  3850. }
  3851. }
  3852. }
  3853. return false;
  3854. };
  3855. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3856. var material = gltfRuntime.materials[id];
  3857. if (!material || !material.extensions) {
  3858. return false;
  3859. }
  3860. var extension = material.extensions[this.name];
  3861. if (!extension) {
  3862. return false;
  3863. }
  3864. var standardMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3865. standardMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3866. if (extension.technique === "CONSTANT") {
  3867. standardMaterial.disableLighting = true;
  3868. }
  3869. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3870. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3871. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3872. // Ambient
  3873. if (typeof extension.values.ambient === "string") {
  3874. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3875. }
  3876. else {
  3877. standardMaterial.ambientColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3878. }
  3879. // Diffuse
  3880. if (typeof extension.values.diffuse === "string") {
  3881. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3882. }
  3883. else {
  3884. standardMaterial.diffuseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3885. }
  3886. // Emission
  3887. if (typeof extension.values.emission === "string") {
  3888. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3889. }
  3890. else {
  3891. standardMaterial.emissiveColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3892. }
  3893. // Specular
  3894. if (typeof extension.values.specular === "string") {
  3895. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3896. }
  3897. else {
  3898. standardMaterial.specularColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3899. }
  3900. return true;
  3901. };
  3902. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3903. // Create buffer from texture url
  3904. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3905. // Create texture from buffer
  3906. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3907. }, onError);
  3908. };
  3909. return GLTFMaterialsCommonExtension;
  3910. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3911. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3912. /***/ }),
  3913. /***/ "./glTF/1.0/index.ts":
  3914. /*!***************************!*\
  3915. !*** ./glTF/1.0/index.ts ***!
  3916. \***************************/
  3917. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3918. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3919. "use strict";
  3920. __webpack_require__.r(__webpack_exports__);
  3921. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3922. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3923. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3924. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3925. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3926. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3927. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3928. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3929. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3930. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3931. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3932. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3933. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3934. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3935. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3936. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3937. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3938. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3939. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3940. /***/ }),
  3941. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3942. /*!*******************************************************!*\
  3943. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3944. \*******************************************************/
  3945. /*! exports provided: EXT_lights_image_based */
  3946. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3947. "use strict";
  3948. __webpack_require__.r(__webpack_exports__);
  3949. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3950. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/observable");
  3951. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3952. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3953. var NAME = "EXT_lights_image_based";
  3954. /**
  3955. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3956. */
  3957. var EXT_lights_image_based = /** @class */ (function () {
  3958. /** @hidden */
  3959. function EXT_lights_image_based(loader) {
  3960. /**
  3961. * The name of this extension.
  3962. */
  3963. this.name = NAME;
  3964. this._loader = loader;
  3965. this.enabled = this._loader.isExtensionUsed(NAME);
  3966. }
  3967. /** @hidden */
  3968. EXT_lights_image_based.prototype.dispose = function () {
  3969. this._loader = null;
  3970. delete this._lights;
  3971. };
  3972. /** @hidden */
  3973. EXT_lights_image_based.prototype.onLoading = function () {
  3974. var extensions = this._loader.gltf.extensions;
  3975. if (extensions && extensions[this.name]) {
  3976. var extension = extensions[this.name];
  3977. this._lights = extension.lights;
  3978. }
  3979. };
  3980. /** @hidden */
  3981. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3982. var _this = this;
  3983. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3984. var promises = new Array();
  3985. promises.push(_this._loader.loadSceneAsync(context, scene));
  3986. _this._loader.logOpen("" + extensionContext);
  3987. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3988. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3989. _this._loader.babylonScene.environmentTexture = texture;
  3990. }));
  3991. _this._loader.logClose();
  3992. return Promise.all(promises).then(function () { });
  3993. });
  3994. };
  3995. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3996. var _this = this;
  3997. if (!light._loaded) {
  3998. var promises = new Array();
  3999. this._loader.logOpen("" + context);
  4000. var imageData_1 = new Array(light.specularImages.length);
  4001. var _loop_1 = function (mipmap) {
  4002. var faces = light.specularImages[mipmap];
  4003. imageData_1[mipmap] = new Array(faces.length);
  4004. var _loop_2 = function (face) {
  4005. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  4006. this_1._loader.logOpen("" + specularImageContext);
  4007. var index = faces[face];
  4008. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  4009. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  4010. imageData_1[mipmap][face] = data;
  4011. }));
  4012. this_1._loader.logClose();
  4013. };
  4014. for (var face = 0; face < faces.length; face++) {
  4015. _loop_2(face);
  4016. }
  4017. };
  4018. var this_1 = this;
  4019. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  4020. _loop_1(mipmap);
  4021. }
  4022. this._loader.logClose();
  4023. light._loaded = Promise.all(promises).then(function () {
  4024. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  4025. babylonTexture.name = light.name || "environment";
  4026. light._babylonTexture = babylonTexture;
  4027. if (light.intensity != undefined) {
  4028. babylonTexture.level = light.intensity;
  4029. }
  4030. if (light.rotation) {
  4031. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  4032. // Invert the rotation so that positive rotation is counter-clockwise.
  4033. if (!_this._loader.babylonScene.useRightHandedSystem) {
  4034. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  4035. }
  4036. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  4037. }
  4038. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  4039. sphericalHarmonics.scaleInPlace(light.intensity);
  4040. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  4041. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  4042. // Compute the lod generation scale to fit exactly to the number of levels available.
  4043. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  4044. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  4045. });
  4046. }
  4047. return light._loaded.then(function () {
  4048. return light._babylonTexture;
  4049. });
  4050. };
  4051. return EXT_lights_image_based;
  4052. }());
  4053. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  4054. /***/ }),
  4055. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  4056. /*!********************************************************!*\
  4057. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  4058. \********************************************************/
  4059. /*! exports provided: EXT_mesh_gpu_instancing */
  4060. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4061. "use strict";
  4062. __webpack_require__.r(__webpack_exports__);
  4063. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  4064. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  4065. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4066. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4067. var NAME = "EXT_mesh_gpu_instancing";
  4068. /**
  4069. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  4070. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  4071. * !!! Experimental Extension Subject to Changes !!!
  4072. */
  4073. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  4074. /** @hidden */
  4075. function EXT_mesh_gpu_instancing(loader) {
  4076. /**
  4077. * The name of this extension.
  4078. */
  4079. this.name = NAME;
  4080. this._loader = loader;
  4081. this.enabled = this._loader.isExtensionUsed(NAME);
  4082. }
  4083. /** @hidden */
  4084. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  4085. this._loader = null;
  4086. };
  4087. /** @hidden */
  4088. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  4089. var _this = this;
  4090. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4091. _this._loader._disableInstancedMesh++;
  4092. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  4093. _this._loader._disableInstancedMesh--;
  4094. if (!node._primitiveBabylonMeshes) {
  4095. return promise;
  4096. }
  4097. var promises = new Array();
  4098. var instanceCount = 0;
  4099. var loadAttribute = function (attribute) {
  4100. if (extension.attributes[attribute] == undefined) {
  4101. promises.push(Promise.resolve(null));
  4102. return;
  4103. }
  4104. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  4105. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  4106. if (instanceCount === 0) {
  4107. instanceCount = accessor.count;
  4108. }
  4109. else if (instanceCount !== accessor.count) {
  4110. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  4111. }
  4112. };
  4113. loadAttribute("TRANSLATION");
  4114. loadAttribute("ROTATION");
  4115. loadAttribute("SCALE");
  4116. return promise.then(function (babylonTransformNode) {
  4117. return Promise.all(promises).then(function (_a) {
  4118. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  4119. var matrices = new Float32Array(instanceCount * 16);
  4120. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  4121. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  4122. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  4123. for (var i = 0; i < instanceCount; ++i) {
  4124. 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]);
  4125. 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]);
  4126. 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]);
  4127. 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]);
  4128. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  4129. }
  4130. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  4131. var babylonMesh = _b[_i];
  4132. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  4133. }
  4134. return babylonTransformNode;
  4135. });
  4136. });
  4137. });
  4138. };
  4139. return EXT_mesh_gpu_instancing;
  4140. }());
  4141. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  4142. /***/ }),
  4143. /***/ "./glTF/2.0/Extensions/EXT_meshopt_compression.ts":
  4144. /*!********************************************************!*\
  4145. !*** ./glTF/2.0/Extensions/EXT_meshopt_compression.ts ***!
  4146. \********************************************************/
  4147. /*! exports provided: EXT_meshopt_compression */
  4148. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4149. "use strict";
  4150. __webpack_require__.r(__webpack_exports__);
  4151. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_meshopt_compression", function() { return EXT_meshopt_compression; });
  4152. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/observable");
  4153. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  4154. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4155. var NAME = "EXT_meshopt_compression";
  4156. /**
  4157. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression)
  4158. *
  4159. * This extension uses a WebAssembly decoder module from https://github.com/zeux/meshoptimizer/tree/master/js
  4160. */
  4161. var EXT_meshopt_compression = /** @class */ (function () {
  4162. /** @hidden */
  4163. function EXT_meshopt_compression(loader) {
  4164. /**
  4165. * The name of this extension.
  4166. */
  4167. this.name = NAME;
  4168. this.enabled = loader.isExtensionUsed(NAME);
  4169. this._loader = loader;
  4170. if (this.enabled) {
  4171. this._decoderPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(EXT_meshopt_compression.DecoderPath).then(function () {
  4172. // Wait for WebAssembly compilation before resolving promise
  4173. return MeshoptDecoder.ready;
  4174. });
  4175. }
  4176. }
  4177. /** @hidden */
  4178. EXT_meshopt_compression.prototype.dispose = function () {
  4179. this._loader = null;
  4180. delete this._decoderPromise;
  4181. };
  4182. /** @hidden */
  4183. EXT_meshopt_compression.prototype.loadBufferViewAsync = function (context, bufferView) {
  4184. var _this = this;
  4185. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, bufferView, this.name, function (extensionContext, extension) {
  4186. var bufferViewMeshopt = bufferView;
  4187. if (bufferViewMeshopt._meshOptData) {
  4188. return bufferViewMeshopt._meshOptData;
  4189. }
  4190. var buffer = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/buffer", _this._loader.gltf.buffers, extension.buffer);
  4191. var bufferPromise = _this._loader.loadBufferAsync("/buffers/" + buffer.index, buffer, (extension.byteOffset || 0), extension.byteLength);
  4192. bufferViewMeshopt._meshOptData = Promise.all([bufferPromise, _this._decoderPromise]).then(function (res) {
  4193. var source = res[0];
  4194. var count = extension.count;
  4195. var stride = extension.byteStride;
  4196. var result = new Uint8Array(new ArrayBuffer(count * stride));
  4197. MeshoptDecoder.decodeGltfBuffer(result, count, stride, source, extension.mode, extension.filter);
  4198. return Promise.resolve(result);
  4199. });
  4200. return bufferViewMeshopt._meshOptData;
  4201. });
  4202. };
  4203. /**
  4204. * Path to decoder module; defaults to https://preview.babylonjs.com/meshopt_decoder.js
  4205. */
  4206. EXT_meshopt_compression.DecoderPath = "https://preview.babylonjs.com/meshopt_decoder.js";
  4207. return EXT_meshopt_compression;
  4208. }());
  4209. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_meshopt_compression(loader); });
  4210. /***/ }),
  4211. /***/ "./glTF/2.0/Extensions/EXT_texture_webp.ts":
  4212. /*!*************************************************!*\
  4213. !*** ./glTF/2.0/Extensions/EXT_texture_webp.ts ***!
  4214. \*************************************************/
  4215. /*! exports provided: EXT_texture_webp */
  4216. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4217. "use strict";
  4218. __webpack_require__.r(__webpack_exports__);
  4219. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_texture_webp", function() { return EXT_texture_webp; });
  4220. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4221. var NAME = "EXT_texture_webp";
  4222. /**
  4223. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_texture_webp/)
  4224. */
  4225. var EXT_texture_webp = /** @class */ (function () {
  4226. /** @hidden */
  4227. function EXT_texture_webp(loader) {
  4228. /** The name of this extension. */
  4229. this.name = NAME;
  4230. this._loader = loader;
  4231. this.enabled = loader.isExtensionUsed(NAME);
  4232. }
  4233. /** @hidden */
  4234. EXT_texture_webp.prototype.dispose = function () {
  4235. this._loader = null;
  4236. };
  4237. /** @hidden */
  4238. EXT_texture_webp.prototype._loadTextureAsync = function (context, texture, assign) {
  4239. var _this = this;
  4240. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  4241. 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));
  4242. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  4243. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  4244. assign(babylonTexture);
  4245. });
  4246. });
  4247. };
  4248. return EXT_texture_webp;
  4249. }());
  4250. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_texture_webp(loader); });
  4251. /***/ }),
  4252. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  4253. /*!*************************************************!*\
  4254. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  4255. \*************************************************/
  4256. /*! exports provided: ExtrasAsMetadata */
  4257. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4258. "use strict";
  4259. __webpack_require__.r(__webpack_exports__);
  4260. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  4261. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4262. var NAME = "ExtrasAsMetadata";
  4263. /**
  4264. * Store glTF extras (if present) in BJS objects' metadata
  4265. */
  4266. var ExtrasAsMetadata = /** @class */ (function () {
  4267. /** @hidden */
  4268. function ExtrasAsMetadata(loader) {
  4269. /**
  4270. * The name of this extension.
  4271. */
  4272. this.name = NAME;
  4273. /**
  4274. * Defines whether this extension is enabled.
  4275. */
  4276. this.enabled = true;
  4277. this._loader = loader;
  4278. }
  4279. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  4280. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  4281. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  4282. var gltf = (metadata.gltf = metadata.gltf || {});
  4283. gltf.extras = gltfProp.extras;
  4284. }
  4285. };
  4286. /** @hidden */
  4287. ExtrasAsMetadata.prototype.dispose = function () {
  4288. this._loader = null;
  4289. };
  4290. /** @hidden */
  4291. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4292. var _this = this;
  4293. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4294. _this._assignExtras(babylonTransformNode, node);
  4295. assign(babylonTransformNode);
  4296. });
  4297. };
  4298. /** @hidden */
  4299. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4300. var _this = this;
  4301. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4302. _this._assignExtras(babylonCamera, camera);
  4303. assign(babylonCamera);
  4304. });
  4305. };
  4306. /** @hidden */
  4307. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4308. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4309. this._assignExtras(babylonMaterial, material);
  4310. return babylonMaterial;
  4311. };
  4312. return ExtrasAsMetadata;
  4313. }());
  4314. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4315. /***/ }),
  4316. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4317. /*!***********************************************************!*\
  4318. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4319. \***********************************************************/
  4320. /*! exports provided: KHR_draco_mesh_compression */
  4321. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4322. "use strict";
  4323. __webpack_require__.r(__webpack_exports__);
  4324. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4325. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/observable");
  4326. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4327. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4328. var NAME = "KHR_draco_mesh_compression";
  4329. /**
  4330. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4331. */
  4332. var KHR_draco_mesh_compression = /** @class */ (function () {
  4333. /** @hidden */
  4334. function KHR_draco_mesh_compression(loader) {
  4335. /**
  4336. * The name of this extension.
  4337. */
  4338. this.name = NAME;
  4339. this._loader = loader;
  4340. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4341. }
  4342. /** @hidden */
  4343. KHR_draco_mesh_compression.prototype.dispose = function () {
  4344. delete this.dracoCompression;
  4345. this._loader = null;
  4346. };
  4347. /** @hidden */
  4348. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4349. var _this = this;
  4350. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4351. if (primitive.mode != undefined) {
  4352. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4353. primitive.mode !== 4 /* TRIANGLES */) {
  4354. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4355. }
  4356. // TODO: handle triangle strips
  4357. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4358. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4359. }
  4360. }
  4361. var attributes = {};
  4362. var loadAttribute = function (name, kind) {
  4363. var uniqueId = extension.attributes[name];
  4364. if (uniqueId == undefined) {
  4365. return;
  4366. }
  4367. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4368. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4369. babylonMesh._delayInfo.push(kind);
  4370. }
  4371. attributes[kind] = uniqueId;
  4372. };
  4373. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4374. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4375. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4376. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4377. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4378. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4379. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4380. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4381. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4382. if (!bufferView._dracoBabylonGeometry) {
  4383. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4384. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4385. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4386. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4387. babylonVertexData.applyToGeometry(babylonGeometry);
  4388. return babylonGeometry;
  4389. }).catch(function (error) {
  4390. throw new Error(context + ": " + error.message);
  4391. });
  4392. });
  4393. }
  4394. return bufferView._dracoBabylonGeometry;
  4395. });
  4396. };
  4397. return KHR_draco_mesh_compression;
  4398. }());
  4399. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4400. /***/ }),
  4401. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4402. /*!****************************************************!*\
  4403. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4404. \****************************************************/
  4405. /*! exports provided: KHR_lights */
  4406. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4407. "use strict";
  4408. __webpack_require__.r(__webpack_exports__);
  4409. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4410. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  4411. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4412. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4413. var NAME = "KHR_lights_punctual";
  4414. /**
  4415. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  4416. */
  4417. var KHR_lights = /** @class */ (function () {
  4418. /** @hidden */
  4419. function KHR_lights(loader) {
  4420. /**
  4421. * The name of this extension.
  4422. */
  4423. this.name = NAME;
  4424. this._loader = loader;
  4425. this.enabled = this._loader.isExtensionUsed(NAME);
  4426. }
  4427. /** @hidden */
  4428. KHR_lights.prototype.dispose = function () {
  4429. this._loader = null;
  4430. delete this._lights;
  4431. };
  4432. /** @hidden */
  4433. KHR_lights.prototype.onLoading = function () {
  4434. var extensions = this._loader.gltf.extensions;
  4435. if (extensions && extensions[this.name]) {
  4436. var extension = extensions[this.name];
  4437. this._lights = extension.lights;
  4438. }
  4439. };
  4440. /** @hidden */
  4441. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4442. var _this = this;
  4443. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4444. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4445. var babylonLight;
  4446. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4447. var name = light.name || babylonMesh.name;
  4448. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  4449. switch (light.type) {
  4450. case "directional" /* DIRECTIONAL */: {
  4451. 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);
  4452. break;
  4453. }
  4454. case "point" /* POINT */: {
  4455. 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);
  4456. break;
  4457. }
  4458. case "spot" /* SPOT */: {
  4459. 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);
  4460. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4461. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4462. babylonLight = babylonSpotLight;
  4463. break;
  4464. }
  4465. default: {
  4466. _this._loader.babylonScene._blockEntityCollection = false;
  4467. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4468. }
  4469. }
  4470. _this._loader.babylonScene._blockEntityCollection = false;
  4471. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4472. 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();
  4473. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4474. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4475. babylonLight.parent = babylonMesh;
  4476. _this._loader._babylonLights.push(babylonLight);
  4477. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4478. assign(babylonMesh);
  4479. });
  4480. });
  4481. };
  4482. return KHR_lights;
  4483. }());
  4484. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4485. /***/ }),
  4486. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4487. /*!********************************************************!*\
  4488. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4489. \********************************************************/
  4490. /*! exports provided: KHR_materials_clearcoat */
  4491. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4492. "use strict";
  4493. __webpack_require__.r(__webpack_exports__);
  4494. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4495. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4496. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4497. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4498. var NAME = "KHR_materials_clearcoat";
  4499. /**
  4500. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md)
  4501. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4502. */
  4503. var KHR_materials_clearcoat = /** @class */ (function () {
  4504. /** @hidden */
  4505. function KHR_materials_clearcoat(loader) {
  4506. /**
  4507. * The name of this extension.
  4508. */
  4509. this.name = NAME;
  4510. /**
  4511. * Defines a number that determines the order the extensions are applied.
  4512. */
  4513. this.order = 190;
  4514. this._loader = loader;
  4515. this.enabled = this._loader.isExtensionUsed(NAME);
  4516. }
  4517. /** @hidden */
  4518. KHR_materials_clearcoat.prototype.dispose = function () {
  4519. this._loader = null;
  4520. };
  4521. /** @hidden */
  4522. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4523. var _this = this;
  4524. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4525. var promises = new Array();
  4526. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4527. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4528. return Promise.all(promises).then(function () { });
  4529. });
  4530. };
  4531. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4532. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4533. throw new Error(context + ": Material type not supported");
  4534. }
  4535. var promises = new Array();
  4536. babylonMaterial.clearCoat.isEnabled = true;
  4537. babylonMaterial.clearCoat.useRoughnessFromMainTexture = false;
  4538. babylonMaterial.clearCoat.remapF0OnInterfaceChange = false;
  4539. if (properties.clearcoatFactor != undefined) {
  4540. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4541. }
  4542. else {
  4543. babylonMaterial.clearCoat.intensity = 0;
  4544. }
  4545. if (properties.clearcoatTexture) {
  4546. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4547. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4548. babylonMaterial.clearCoat.texture = texture;
  4549. }));
  4550. }
  4551. if (properties.clearcoatRoughnessFactor != undefined) {
  4552. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4553. }
  4554. else {
  4555. babylonMaterial.clearCoat.roughness = 0;
  4556. }
  4557. if (properties.clearcoatRoughnessTexture) {
  4558. properties.clearcoatRoughnessTexture.nonColorData = true;
  4559. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4560. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4561. babylonMaterial.clearCoat.textureRoughness = texture;
  4562. }));
  4563. }
  4564. if (properties.clearcoatNormalTexture) {
  4565. properties.clearcoatNormalTexture.nonColorData = true;
  4566. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4567. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4568. babylonMaterial.clearCoat.bumpTexture = texture;
  4569. }));
  4570. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4571. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4572. if (properties.clearcoatNormalTexture.scale != undefined) {
  4573. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4574. }
  4575. }
  4576. return Promise.all(promises).then(function () { });
  4577. };
  4578. return KHR_materials_clearcoat;
  4579. }());
  4580. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4581. /***/ }),
  4582. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  4583. /*!**************************************************!*\
  4584. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  4585. \**************************************************/
  4586. /*! exports provided: KHR_materials_ior */
  4587. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4588. "use strict";
  4589. __webpack_require__.r(__webpack_exports__);
  4590. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  4591. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4592. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4593. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4594. var NAME = "KHR_materials_ior";
  4595. /**
  4596. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  4597. * !!! Experimental Extension Subject to Changes !!!
  4598. */
  4599. var KHR_materials_ior = /** @class */ (function () {
  4600. /** @hidden */
  4601. function KHR_materials_ior(loader) {
  4602. /**
  4603. * The name of this extension.
  4604. */
  4605. this.name = NAME;
  4606. /**
  4607. * Defines a number that determines the order the extensions are applied.
  4608. */
  4609. this.order = 180;
  4610. this._loader = loader;
  4611. this.enabled = this._loader.isExtensionUsed(NAME);
  4612. }
  4613. /** @hidden */
  4614. KHR_materials_ior.prototype.dispose = function () {
  4615. this._loader = null;
  4616. };
  4617. /** @hidden */
  4618. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4619. var _this = this;
  4620. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4621. var promises = new Array();
  4622. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4623. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  4624. return Promise.all(promises).then(function () { });
  4625. });
  4626. };
  4627. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  4628. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4629. throw new Error(context + ": Material type not supported");
  4630. }
  4631. if (properties.ior !== undefined) {
  4632. babylonMaterial.indexOfRefraction = properties.ior;
  4633. }
  4634. else {
  4635. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  4636. }
  4637. return Promise.resolve();
  4638. };
  4639. /**
  4640. * Default ior Value from the spec.
  4641. */
  4642. KHR_materials_ior._DEFAULT_IOR = 1.5;
  4643. return KHR_materials_ior;
  4644. }());
  4645. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  4646. /***/ }),
  4647. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4648. /*!********************************************************************!*\
  4649. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4650. \********************************************************************/
  4651. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4652. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4653. "use strict";
  4654. __webpack_require__.r(__webpack_exports__);
  4655. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4656. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/observable");
  4657. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4658. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4659. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4660. /**
  4661. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4662. */
  4663. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4664. /** @hidden */
  4665. function KHR_materials_pbrSpecularGlossiness(loader) {
  4666. /**
  4667. * The name of this extension.
  4668. */
  4669. this.name = NAME;
  4670. /**
  4671. * Defines a number that determines the order the extensions are applied.
  4672. */
  4673. this.order = 200;
  4674. this._loader = loader;
  4675. this.enabled = this._loader.isExtensionUsed(NAME);
  4676. }
  4677. /** @hidden */
  4678. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4679. this._loader = null;
  4680. };
  4681. /** @hidden */
  4682. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4683. var _this = this;
  4684. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4685. var promises = new Array();
  4686. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4687. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4688. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4689. return Promise.all(promises).then(function () { });
  4690. });
  4691. };
  4692. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4693. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4694. throw new Error(context + ": Material type not supported");
  4695. }
  4696. var promises = new Array();
  4697. babylonMaterial.metallic = null;
  4698. babylonMaterial.roughness = null;
  4699. if (properties.diffuseFactor) {
  4700. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4701. babylonMaterial.alpha = properties.diffuseFactor[3];
  4702. }
  4703. else {
  4704. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4705. }
  4706. 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();
  4707. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4708. if (properties.diffuseTexture) {
  4709. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4710. texture.name = babylonMaterial.name + " (Diffuse)";
  4711. babylonMaterial.albedoTexture = texture;
  4712. }));
  4713. }
  4714. if (properties.specularGlossinessTexture) {
  4715. properties.specularGlossinessTexture.nonColorData = true;
  4716. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4717. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4718. babylonMaterial.reflectivityTexture = texture;
  4719. }));
  4720. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4721. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4722. }
  4723. return Promise.all(promises).then(function () { });
  4724. };
  4725. return KHR_materials_pbrSpecularGlossiness;
  4726. }());
  4727. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4728. /***/ }),
  4729. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4730. /*!****************************************************!*\
  4731. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4732. \****************************************************/
  4733. /*! exports provided: KHR_materials_sheen */
  4734. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4735. "use strict";
  4736. __webpack_require__.r(__webpack_exports__);
  4737. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4738. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4739. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4740. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4741. var NAME = "KHR_materials_sheen";
  4742. /**
  4743. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_sheen/README.md)
  4744. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4745. * !!! Experimental Extension Subject to Changes !!!
  4746. */
  4747. var KHR_materials_sheen = /** @class */ (function () {
  4748. /** @hidden */
  4749. function KHR_materials_sheen(loader) {
  4750. /**
  4751. * The name of this extension.
  4752. */
  4753. this.name = NAME;
  4754. /**
  4755. * Defines a number that determines the order the extensions are applied.
  4756. */
  4757. this.order = 190;
  4758. this._loader = loader;
  4759. this.enabled = this._loader.isExtensionUsed(NAME);
  4760. }
  4761. /** @hidden */
  4762. KHR_materials_sheen.prototype.dispose = function () {
  4763. this._loader = null;
  4764. };
  4765. /** @hidden */
  4766. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4767. var _this = this;
  4768. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4769. var promises = new Array();
  4770. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4771. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4772. return Promise.all(promises).then(function () { });
  4773. });
  4774. };
  4775. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4776. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4777. throw new Error(context + ": Material type not supported");
  4778. }
  4779. var promises = new Array();
  4780. babylonMaterial.sheen.isEnabled = true;
  4781. babylonMaterial.sheen.intensity = 1;
  4782. if (properties.sheenColorFactor != undefined) {
  4783. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.sheenColorFactor);
  4784. }
  4785. else {
  4786. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  4787. }
  4788. if (properties.sheenColorTexture) {
  4789. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenColorTexture", properties.sheenColorTexture, function (texture) {
  4790. texture.name = babylonMaterial.name + " (Sheen Color)";
  4791. babylonMaterial.sheen.texture = texture;
  4792. }));
  4793. }
  4794. if (properties.sheenRoughnessFactor !== undefined) {
  4795. babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;
  4796. }
  4797. else {
  4798. babylonMaterial.sheen.roughness = 0;
  4799. }
  4800. if (properties.sheenRoughnessTexture) {
  4801. properties.sheenRoughnessTexture.nonColorData = true;
  4802. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenRoughnessTexture", properties.sheenRoughnessTexture, function (texture) {
  4803. texture.name = babylonMaterial.name + " (Sheen Roughness)";
  4804. babylonMaterial.sheen.textureRoughness = texture;
  4805. }));
  4806. }
  4807. babylonMaterial.sheen.albedoScaling = true;
  4808. babylonMaterial.sheen.useRoughnessFromMainTexture = false;
  4809. return Promise.all(promises).then(function () { });
  4810. };
  4811. return KHR_materials_sheen;
  4812. }());
  4813. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4814. /***/ }),
  4815. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4816. /*!*******************************************************!*\
  4817. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4818. \*******************************************************/
  4819. /*! exports provided: KHR_materials_specular */
  4820. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4821. "use strict";
  4822. __webpack_require__.r(__webpack_exports__);
  4823. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4824. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4825. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4826. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4827. var NAME = "KHR_materials_specular";
  4828. /**
  4829. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  4830. * !!! Experimental Extension Subject to Changes !!!
  4831. */
  4832. var KHR_materials_specular = /** @class */ (function () {
  4833. /** @hidden */
  4834. function KHR_materials_specular(loader) {
  4835. /**
  4836. * The name of this extension.
  4837. */
  4838. this.name = NAME;
  4839. /**
  4840. * Defines a number that determines the order the extensions are applied.
  4841. */
  4842. this.order = 190;
  4843. this._loader = loader;
  4844. this.enabled = this._loader.isExtensionUsed(NAME);
  4845. }
  4846. /** @hidden */
  4847. KHR_materials_specular.prototype.dispose = function () {
  4848. this._loader = null;
  4849. };
  4850. /** @hidden */
  4851. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4852. var _this = this;
  4853. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4854. var promises = new Array();
  4855. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4856. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4857. return Promise.all(promises).then(function () { });
  4858. });
  4859. };
  4860. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4861. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4862. throw new Error(context + ": Material type not supported");
  4863. }
  4864. var promises = new Array();
  4865. if (properties.specularFactor !== undefined) {
  4866. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4867. }
  4868. if (properties.specularColorFactor !== undefined) {
  4869. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  4870. }
  4871. if (properties.specularTexture) {
  4872. properties.specularTexture.nonColorData = true;
  4873. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  4874. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  4875. babylonMaterial.metallicReflectanceTexture = texture;
  4876. }));
  4877. }
  4878. return Promise.all(promises).then(function () { });
  4879. };
  4880. return KHR_materials_specular;
  4881. }());
  4882. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4883. /***/ }),
  4884. /***/ "./glTF/2.0/Extensions/KHR_materials_translucency.ts":
  4885. /*!***********************************************************!*\
  4886. !*** ./glTF/2.0/Extensions/KHR_materials_translucency.ts ***!
  4887. \***********************************************************/
  4888. /*! exports provided: KHR_materials_translucency */
  4889. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4890. "use strict";
  4891. __webpack_require__.r(__webpack_exports__);
  4892. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_translucency", function() { return KHR_materials_translucency; });
  4893. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4894. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4895. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4896. var NAME = "KHR_materials_translucency";
  4897. /**
  4898. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
  4899. * !!! Experimental Extension Subject to Changes !!!
  4900. */
  4901. var KHR_materials_translucency = /** @class */ (function () {
  4902. /** @hidden */
  4903. function KHR_materials_translucency(loader) {
  4904. /**
  4905. * The name of this extension.
  4906. */
  4907. this.name = NAME;
  4908. /**
  4909. * Defines a number that determines the order the extensions are applied.
  4910. */
  4911. this.order = 175;
  4912. this._loader = loader;
  4913. this.enabled = this._loader.isExtensionUsed(NAME);
  4914. if (this.enabled) {
  4915. loader.parent.transparencyAsCoverage = true;
  4916. }
  4917. }
  4918. /** @hidden */
  4919. KHR_materials_translucency.prototype.dispose = function () {
  4920. this._loader = null;
  4921. };
  4922. /** @hidden */
  4923. KHR_materials_translucency.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4924. var _this = this;
  4925. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4926. var promises = new Array();
  4927. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4928. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4929. promises.push(_this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
  4930. return Promise.all(promises).then(function () { });
  4931. });
  4932. };
  4933. KHR_materials_translucency.prototype._loadTranslucentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  4934. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4935. throw new Error(context + ": Material type not supported");
  4936. }
  4937. var pbrMaterial = babylonMaterial;
  4938. // Enables "translucency" texture which represents diffusely-transmitted light.
  4939. pbrMaterial.subSurface.isTranslucencyEnabled = true;
  4940. // Since this extension models thin-surface transmission only, we must make the
  4941. // internal IOR == 1.0 and set the thickness to 0.
  4942. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  4943. pbrMaterial.subSurface.minimumThickness = 0.0;
  4944. pbrMaterial.subSurface.maximumThickness = 0.0;
  4945. // Albedo colour will tint transmission.
  4946. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  4947. if (extension.translucencyFactor !== undefined) {
  4948. pbrMaterial.subSurface.translucencyIntensity = extension.translucencyFactor;
  4949. }
  4950. else {
  4951. pbrMaterial.subSurface.translucencyIntensity = 0.0;
  4952. pbrMaterial.subSurface.isTranslucencyEnabled = false;
  4953. return Promise.resolve();
  4954. }
  4955. if (extension.translucencyTexture) {
  4956. return this._loader.loadTextureInfoAsync(context + "/translucencyTexture", extension.translucencyTexture)
  4957. .then(function (texture) {
  4958. pbrMaterial.subSurface.thicknessTexture = texture;
  4959. pbrMaterial.subSurface.useMaskFromThicknessTextureGltf = true;
  4960. });
  4961. }
  4962. else {
  4963. return Promise.resolve();
  4964. }
  4965. };
  4966. return KHR_materials_translucency;
  4967. }());
  4968. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_translucency(loader); });
  4969. /***/ }),
  4970. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  4971. /*!***********************************************************!*\
  4972. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  4973. \***********************************************************/
  4974. /*! exports provided: KHR_materials_transmission */
  4975. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4976. "use strict";
  4977. __webpack_require__.r(__webpack_exports__);
  4978. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  4979. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  4980. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4981. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__);
  4982. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4983. /**
  4984. * A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.
  4985. */
  4986. var TransmissionHelper = /** @class */ (function () {
  4987. /**
  4988. * constructor
  4989. * @param options Defines the options we want to customize the helper
  4990. * @param scene The scene to add the material to
  4991. */
  4992. function TransmissionHelper(options, scene) {
  4993. var _this = this;
  4994. this._opaqueRenderTarget = null;
  4995. this._opaqueMeshesCache = [];
  4996. this._transparentMeshesCache = [];
  4997. this._options = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])(Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, TransmissionHelper._getDefaultOptions()), options);
  4998. this._scene = scene;
  4999. this._scene._transmissionHelper = this;
  5000. this.onErrorObservable = new babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Observable"]();
  5001. this._scene.onDisposeObservable.addOnce(function (scene) {
  5002. _this.dispose();
  5003. });
  5004. this._parseScene();
  5005. this._setupRenderTargets();
  5006. }
  5007. /**
  5008. * Creates the default options for the helper.
  5009. */
  5010. TransmissionHelper._getDefaultOptions = function () {
  5011. return {
  5012. renderSize: 1024
  5013. };
  5014. };
  5015. /**
  5016. * Updates the background according to the new options
  5017. * @param options
  5018. */
  5019. TransmissionHelper.prototype.updateOptions = function (options) {
  5020. var _this = this;
  5021. // First check if any options are actually being changed. If not, exit.
  5022. var newValues = Object.keys(options).filter(function (key) { return _this._options[key] !== options[key]; });
  5023. if (!newValues.length) {
  5024. return;
  5025. }
  5026. var newOptions = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])(Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, this._options), options);
  5027. var oldOptions = this._options;
  5028. this._options = newOptions;
  5029. // If size changes, recreate everything
  5030. if (newOptions.renderSize !== oldOptions.renderSize) {
  5031. this._setupRenderTargets();
  5032. }
  5033. };
  5034. TransmissionHelper.prototype.getOpaqueTarget = function () {
  5035. return this._opaqueRenderTarget;
  5036. };
  5037. TransmissionHelper.prototype.shouldRenderAsTransmission = function (material) {
  5038. if (!material) {
  5039. return false;
  5040. }
  5041. if (material instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"] && (material.subSurface.isRefractionEnabled)) {
  5042. return true;
  5043. }
  5044. return false;
  5045. };
  5046. TransmissionHelper.prototype._addMesh = function (mesh) {
  5047. if (mesh instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5048. mesh.onMaterialChangedObservable.add(this.onMeshMaterialChanged.bind(this));
  5049. if (this.shouldRenderAsTransmission(mesh.material)) {
  5050. this._transparentMeshesCache.push(mesh);
  5051. }
  5052. else {
  5053. this._opaqueMeshesCache.push(mesh);
  5054. }
  5055. }
  5056. };
  5057. TransmissionHelper.prototype._removeMesh = function (mesh) {
  5058. if (mesh instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5059. mesh.onMaterialChangedObservable.remove(this.onMeshMaterialChanged.bind(this));
  5060. var idx = this._transparentMeshesCache.indexOf(mesh);
  5061. if (idx !== -1) {
  5062. this._transparentMeshesCache.splice(idx, 1);
  5063. }
  5064. idx = this._opaqueMeshesCache.indexOf(mesh);
  5065. if (idx !== -1) {
  5066. this._opaqueMeshesCache.splice(idx, 1);
  5067. }
  5068. }
  5069. };
  5070. TransmissionHelper.prototype._parseScene = function () {
  5071. this._scene.meshes.forEach(this._addMesh.bind(this));
  5072. // Listen for when a mesh is added to the scene and add it to our cache lists.
  5073. this._scene.onNewMeshAddedObservable.add(this._addMesh.bind(this));
  5074. // Listen for when a mesh is removed from to the scene and remove it from our cache lists.
  5075. this._scene.onMeshRemovedObservable.add(this._removeMesh.bind(this));
  5076. };
  5077. // When one of the meshes in the scene has its material changed, make sure that it's in the correct cache list.
  5078. TransmissionHelper.prototype.onMeshMaterialChanged = function (mesh) {
  5079. if (mesh instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5080. var transparentIdx = this._transparentMeshesCache.indexOf(mesh);
  5081. var opaqueIdx = this._opaqueMeshesCache.indexOf(mesh);
  5082. // If the material is transparent, make sure that it's added to the transparent list and removed from the opaque list
  5083. var useTransmission = this.shouldRenderAsTransmission(mesh.material);
  5084. if (useTransmission) {
  5085. if (mesh.material instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  5086. mesh.material.subSurface.refractionTexture = this._opaqueRenderTarget;
  5087. }
  5088. if (opaqueIdx !== -1) {
  5089. this._opaqueMeshesCache.splice(opaqueIdx, 1);
  5090. this._transparentMeshesCache.push(mesh);
  5091. }
  5092. else if (transparentIdx === -1) {
  5093. this._transparentMeshesCache.push(mesh);
  5094. }
  5095. // If the material is opaque, make sure that it's added to the opaque list and removed from the transparent list
  5096. }
  5097. else {
  5098. if (transparentIdx !== -1) {
  5099. this._transparentMeshesCache.splice(transparentIdx, 1);
  5100. this._opaqueMeshesCache.push(mesh);
  5101. }
  5102. else if (opaqueIdx === -1) {
  5103. this._opaqueMeshesCache.push(mesh);
  5104. }
  5105. }
  5106. }
  5107. };
  5108. /**
  5109. * Setup the render targets according to the specified options.
  5110. */
  5111. TransmissionHelper.prototype._setupRenderTargets = function () {
  5112. var _this = this;
  5113. var opaqueRTIndex = -1;
  5114. // Remove any layers rendering to the opaque scene.
  5115. if (this._scene.layers && this._opaqueRenderTarget) {
  5116. for (var _i = 0, _a = this._scene.layers; _i < _a.length; _i++) {
  5117. var layer = _a[_i];
  5118. var idx = layer.renderTargetTextures.indexOf(this._opaqueRenderTarget);
  5119. if (idx >= 0) {
  5120. layer.renderTargetTextures.splice(idx, 1);
  5121. }
  5122. }
  5123. }
  5124. // Remove opaque render target
  5125. if (this._opaqueRenderTarget) {
  5126. opaqueRTIndex = this._scene.customRenderTargets.indexOf(this._opaqueRenderTarget);
  5127. this._opaqueRenderTarget.dispose();
  5128. }
  5129. this._opaqueRenderTarget = new babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["RenderTargetTexture"]("opaqueSceneTexture", this._options.renderSize, this._scene, true);
  5130. this._opaqueRenderTarget.renderList = this._opaqueMeshesCache;
  5131. // this._opaqueRenderTarget.clearColor = new Color4(0.0, 0.0, 0.0, 0.0);
  5132. this._opaqueRenderTarget.gammaSpace = true;
  5133. this._opaqueRenderTarget.lodGenerationScale = 1;
  5134. this._opaqueRenderTarget.lodGenerationOffset = -4;
  5135. this._opaqueRenderTarget.samples = 4;
  5136. if (opaqueRTIndex >= 0) {
  5137. this._scene.customRenderTargets.splice(opaqueRTIndex, 0, this._opaqueRenderTarget);
  5138. }
  5139. else {
  5140. opaqueRTIndex = this._scene.customRenderTargets.length;
  5141. this._scene.customRenderTargets.push(this._opaqueRenderTarget);
  5142. }
  5143. // If there are other layers, they should be included in the render of the opaque background.
  5144. if (this._scene.layers && this._opaqueRenderTarget) {
  5145. for (var _b = 0, _c = this._scene.layers; _b < _c.length; _b++) {
  5146. var layer = _c[_b];
  5147. layer.renderTargetTextures.push(this._opaqueRenderTarget);
  5148. }
  5149. }
  5150. this._transparentMeshesCache.forEach(function (mesh) {
  5151. if (_this.shouldRenderAsTransmission(mesh.material) && mesh.material instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  5152. mesh.material.refractionTexture = _this._opaqueRenderTarget;
  5153. }
  5154. });
  5155. };
  5156. /**
  5157. * Dispose all the elements created by the Helper.
  5158. */
  5159. TransmissionHelper.prototype.dispose = function () {
  5160. this._scene._transmissionHelper = undefined;
  5161. if (this._opaqueRenderTarget) {
  5162. this._opaqueRenderTarget.dispose();
  5163. this._opaqueRenderTarget = null;
  5164. }
  5165. this._transparentMeshesCache = [];
  5166. this._opaqueMeshesCache = [];
  5167. };
  5168. return TransmissionHelper;
  5169. }());
  5170. var NAME = "KHR_materials_transmission";
  5171. /**
  5172. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
  5173. */
  5174. var KHR_materials_transmission = /** @class */ (function () {
  5175. /** @hidden */
  5176. function KHR_materials_transmission(loader) {
  5177. /**
  5178. * The name of this extension.
  5179. */
  5180. this.name = NAME;
  5181. /**
  5182. * Defines a number that determines the order the extensions are applied.
  5183. */
  5184. this.order = 175;
  5185. this._loader = loader;
  5186. this.enabled = this._loader.isExtensionUsed(NAME);
  5187. if (this.enabled) {
  5188. loader.parent.transparencyAsCoverage = true;
  5189. }
  5190. }
  5191. /** @hidden */
  5192. KHR_materials_transmission.prototype.dispose = function () {
  5193. this._loader = null;
  5194. };
  5195. /** @hidden */
  5196. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5197. var _this = this;
  5198. return _glTFLoader__WEBPACK_IMPORTED_MODULE_2__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5199. var promises = new Array();
  5200. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  5201. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  5202. promises.push(_this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
  5203. return Promise.all(promises).then(function () { });
  5204. });
  5205. };
  5206. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  5207. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"])) {
  5208. throw new Error(context + ": Material type not supported");
  5209. }
  5210. var pbrMaterial = babylonMaterial;
  5211. // Enables "refraction" texture which represents transmitted light.
  5212. pbrMaterial.subSurface.isRefractionEnabled = true;
  5213. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  5214. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  5215. // Albedo colour will tint transmission.
  5216. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  5217. if (extension.transmissionFactor !== undefined) {
  5218. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  5219. var scene = pbrMaterial.getScene();
  5220. if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {
  5221. new TransmissionHelper({}, pbrMaterial.getScene());
  5222. }
  5223. }
  5224. else {
  5225. pbrMaterial.subSurface.refractionIntensity = 0.0;
  5226. pbrMaterial.subSurface.isRefractionEnabled = false;
  5227. return Promise.resolve();
  5228. }
  5229. if (extension.transmissionTexture) {
  5230. extension.transmissionTexture.nonColorData = true;
  5231. return this._loader.loadTextureInfoAsync(context + "/transmissionTexture", extension.transmissionTexture, undefined)
  5232. .then(function (texture) {
  5233. pbrMaterial.subSurface.thicknessTexture = texture;
  5234. pbrMaterial.subSurface.useMaskFromThicknessTextureGltf = true;
  5235. });
  5236. }
  5237. else {
  5238. return Promise.resolve();
  5239. }
  5240. };
  5241. return KHR_materials_transmission;
  5242. }());
  5243. _glTFLoader__WEBPACK_IMPORTED_MODULE_2__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  5244. /***/ }),
  5245. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  5246. /*!****************************************************!*\
  5247. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  5248. \****************************************************/
  5249. /*! exports provided: KHR_materials_unlit */
  5250. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5251. "use strict";
  5252. __webpack_require__.r(__webpack_exports__);
  5253. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  5254. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/observable");
  5255. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  5256. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5257. var NAME = "KHR_materials_unlit";
  5258. /**
  5259. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  5260. */
  5261. var KHR_materials_unlit = /** @class */ (function () {
  5262. /** @hidden */
  5263. function KHR_materials_unlit(loader) {
  5264. /**
  5265. * The name of this extension.
  5266. */
  5267. this.name = NAME;
  5268. /**
  5269. * Defines a number that determines the order the extensions are applied.
  5270. */
  5271. this.order = 210;
  5272. this._loader = loader;
  5273. this.enabled = this._loader.isExtensionUsed(NAME);
  5274. }
  5275. /** @hidden */
  5276. KHR_materials_unlit.prototype.dispose = function () {
  5277. this._loader = null;
  5278. };
  5279. /** @hidden */
  5280. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5281. var _this = this;
  5282. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  5283. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  5284. });
  5285. };
  5286. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  5287. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5288. throw new Error(context + ": Material type not supported");
  5289. }
  5290. var promises = new Array();
  5291. babylonMaterial.unlit = true;
  5292. var properties = material.pbrMetallicRoughness;
  5293. if (properties) {
  5294. if (properties.baseColorFactor) {
  5295. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  5296. babylonMaterial.alpha = properties.baseColorFactor[3];
  5297. }
  5298. else {
  5299. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  5300. }
  5301. if (properties.baseColorTexture) {
  5302. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  5303. texture.name = babylonMaterial.name + " (Base Color)";
  5304. babylonMaterial.albedoTexture = texture;
  5305. }));
  5306. }
  5307. }
  5308. if (material.doubleSided) {
  5309. babylonMaterial.backFaceCulling = false;
  5310. babylonMaterial.twoSidedLighting = true;
  5311. }
  5312. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  5313. return Promise.all(promises).then(function () { });
  5314. };
  5315. return KHR_materials_unlit;
  5316. }());
  5317. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  5318. /***/ }),
  5319. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  5320. /*!*******************************************************!*\
  5321. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  5322. \*******************************************************/
  5323. /*! exports provided: KHR_materials_variants */
  5324. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5325. "use strict";
  5326. __webpack_require__.r(__webpack_exports__);
  5327. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  5328. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5329. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/observable");
  5330. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  5331. var NAME = "KHR_materials_variants";
  5332. /**
  5333. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)
  5334. */
  5335. var KHR_materials_variants = /** @class */ (function () {
  5336. /** @hidden */
  5337. function KHR_materials_variants(loader) {
  5338. /**
  5339. * The name of this extension.
  5340. */
  5341. this.name = NAME;
  5342. this._loader = loader;
  5343. this.enabled = this._loader.isExtensionUsed(NAME);
  5344. }
  5345. /** @hidden */
  5346. KHR_materials_variants.prototype.dispose = function () {
  5347. this._loader = null;
  5348. };
  5349. /**
  5350. * Gets the list of available variant names for this asset.
  5351. * @param rootMesh The glTF root mesh
  5352. * @returns the list of all the variant names for this model
  5353. */
  5354. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  5355. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5356. if (!extensionMetadata) {
  5357. return [];
  5358. }
  5359. return Object.keys(extensionMetadata.variants);
  5360. };
  5361. /**
  5362. * Gets the list of available variant names for this asset.
  5363. * @param rootMesh The glTF root mesh
  5364. * @returns the list of all the variant names for this model
  5365. */
  5366. KHR_materials_variants.prototype.getAvailableVariants = function (rootMesh) {
  5367. return KHR_materials_variants.GetAvailableVariants(rootMesh);
  5368. };
  5369. /**
  5370. * Select a variant given a variant name or a list of variant names.
  5371. * @param rootMesh The glTF root mesh
  5372. * @param variantName The variant name(s) to select.
  5373. */
  5374. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  5375. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5376. if (!extensionMetadata) {
  5377. throw new Error("Cannot select variant on a glTF mesh that does not have the " + NAME + " extension");
  5378. }
  5379. var select = function (variantName) {
  5380. var entries = extensionMetadata.variants[variantName];
  5381. if (entries) {
  5382. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  5383. var entry = entries_1[_i];
  5384. entry.mesh.material = entry.material;
  5385. }
  5386. }
  5387. };
  5388. if (variantName instanceof Array) {
  5389. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  5390. var name_1 = variantName_1[_i];
  5391. select(name_1);
  5392. }
  5393. }
  5394. else {
  5395. select(variantName);
  5396. }
  5397. extensionMetadata.lastSelected = variantName;
  5398. };
  5399. /**
  5400. * Select a variant given a variant name or a list of variant names.
  5401. * @param rootMesh The glTF root mesh
  5402. * @param variantName The variant name(s) to select.
  5403. */
  5404. KHR_materials_variants.prototype.selectVariant = function (rootMesh, variantName) {
  5405. return KHR_materials_variants.SelectVariant(rootMesh, variantName);
  5406. };
  5407. /**
  5408. * Reset back to the original before selecting a variant.
  5409. * @param rootMesh The glTF root mesh
  5410. */
  5411. KHR_materials_variants.Reset = function (rootMesh) {
  5412. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5413. if (!extensionMetadata) {
  5414. throw new Error("Cannot reset on a glTF mesh that does not have the " + NAME + " extension");
  5415. }
  5416. for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
  5417. var entry = _a[_i];
  5418. entry.mesh.material = entry.material;
  5419. }
  5420. extensionMetadata.lastSelected = null;
  5421. };
  5422. /**
  5423. * Reset back to the original before selecting a variant.
  5424. * @param rootMesh The glTF root mesh
  5425. */
  5426. KHR_materials_variants.prototype.reset = function (rootMesh) {
  5427. return KHR_materials_variants.Reset(rootMesh);
  5428. };
  5429. /**
  5430. * Gets the last selected variant name(s) or null if original.
  5431. * @param rootMesh The glTF root mesh
  5432. * @returns The selected variant name(s).
  5433. */
  5434. KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
  5435. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  5436. if (!extensionMetadata) {
  5437. throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the " + NAME + " extension");
  5438. }
  5439. return extensionMetadata.lastSelected;
  5440. };
  5441. /**
  5442. * Gets the last selected variant name(s) or null if original.
  5443. * @param rootMesh The glTF root mesh
  5444. * @returns The selected variant name(s).
  5445. */
  5446. KHR_materials_variants.prototype.getLastSelectedVariant = function (rootMesh) {
  5447. return KHR_materials_variants.GetLastSelectedVariant(rootMesh);
  5448. };
  5449. KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
  5450. var _a, _b;
  5451. 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;
  5452. };
  5453. /** @hidden */
  5454. KHR_materials_variants.prototype.onLoading = function () {
  5455. var extensions = this._loader.gltf.extensions;
  5456. if (extensions && extensions[this.name]) {
  5457. var extension = extensions[this.name];
  5458. this._variants = extension.variants;
  5459. }
  5460. };
  5461. /** @hidden */
  5462. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  5463. var _this = this;
  5464. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  5465. var promises = new Array();
  5466. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  5467. assign(babylonMesh);
  5468. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  5469. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  5470. var root = _this._loader.rootBabylonMesh;
  5471. var metadata = (root.metadata = root.metadata || {});
  5472. var gltf = (metadata.gltf = metadata.gltf || {});
  5473. var extensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
  5474. // Store the original material.
  5475. extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });
  5476. // For each mapping, look at the variants and make a new entry for them.
  5477. var variants_1 = extensionMetadata.variants;
  5478. for (var _i = 0, _a = extension.mappings; _i < _a.length; _i++) {
  5479. var mapping = _a[_i];
  5480. var _loop_1 = function (variantIndex) {
  5481. var variant = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/mapping/" + variantIndex, _this._variants, variantIndex);
  5482. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  5483. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5484. variants_1[variant.name] = variants_1[variant.name] || [];
  5485. variants_1[variant.name].push({
  5486. mesh: babylonMesh,
  5487. material: babylonMaterial
  5488. });
  5489. }));
  5490. };
  5491. for (var _b = 0, _c = mapping.variants; _b < _c.length; _b++) {
  5492. var variantIndex = _c[_b];
  5493. _loop_1(variantIndex);
  5494. }
  5495. }
  5496. }
  5497. }));
  5498. return Promise.all(promises).then(function (_a) {
  5499. var babylonMesh = _a[0];
  5500. return babylonMesh;
  5501. });
  5502. });
  5503. };
  5504. return KHR_materials_variants;
  5505. }());
  5506. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  5507. /***/ }),
  5508. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  5509. /*!******************************************************!*\
  5510. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  5511. \******************************************************/
  5512. /*! exports provided: KHR_mesh_quantization */
  5513. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5514. "use strict";
  5515. __webpack_require__.r(__webpack_exports__);
  5516. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  5517. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5518. var NAME = "KHR_mesh_quantization";
  5519. /**
  5520. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  5521. */
  5522. var KHR_mesh_quantization = /** @class */ (function () {
  5523. /** @hidden */
  5524. function KHR_mesh_quantization(loader) {
  5525. /**
  5526. * The name of this extension.
  5527. */
  5528. this.name = NAME;
  5529. this.enabled = loader.isExtensionUsed(NAME);
  5530. }
  5531. /** @hidden */
  5532. KHR_mesh_quantization.prototype.dispose = function () {
  5533. };
  5534. return KHR_mesh_quantization;
  5535. }());
  5536. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  5537. /***/ }),
  5538. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  5539. /*!***************************************************!*\
  5540. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  5541. \***************************************************/
  5542. /*! exports provided: KHR_texture_basisu */
  5543. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5544. "use strict";
  5545. __webpack_require__.r(__webpack_exports__);
  5546. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  5547. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5548. var NAME = "KHR_texture_basisu";
  5549. /**
  5550. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  5551. * !!! Experimental Extension Subject to Changes !!!
  5552. */
  5553. var KHR_texture_basisu = /** @class */ (function () {
  5554. /** @hidden */
  5555. function KHR_texture_basisu(loader) {
  5556. /** The name of this extension. */
  5557. this.name = NAME;
  5558. this._loader = loader;
  5559. this.enabled = loader.isExtensionUsed(NAME);
  5560. }
  5561. /** @hidden */
  5562. KHR_texture_basisu.prototype.dispose = function () {
  5563. this._loader = null;
  5564. };
  5565. /** @hidden */
  5566. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  5567. var _this = this;
  5568. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  5569. 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));
  5570. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  5571. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  5572. assign(babylonTexture);
  5573. }, texture._textureInfo.nonColorData ? { useRGBAIfASTCBC7NotAvailableWhenUASTC: true } : undefined);
  5574. });
  5575. };
  5576. return KHR_texture_basisu;
  5577. }());
  5578. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  5579. /***/ }),
  5580. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  5581. /*!******************************************************!*\
  5582. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  5583. \******************************************************/
  5584. /*! exports provided: KHR_texture_transform */
  5585. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5586. "use strict";
  5587. __webpack_require__.r(__webpack_exports__);
  5588. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  5589. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/observable");
  5590. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  5591. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5592. var NAME = "KHR_texture_transform";
  5593. /**
  5594. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  5595. */
  5596. var KHR_texture_transform = /** @class */ (function () {
  5597. /** @hidden */
  5598. function KHR_texture_transform(loader) {
  5599. /**
  5600. * The name of this extension.
  5601. */
  5602. this.name = NAME;
  5603. this._loader = loader;
  5604. this.enabled = this._loader.isExtensionUsed(NAME);
  5605. }
  5606. /** @hidden */
  5607. KHR_texture_transform.prototype.dispose = function () {
  5608. this._loader = null;
  5609. };
  5610. /** @hidden */
  5611. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  5612. var _this = this;
  5613. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  5614. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  5615. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  5616. throw new Error(extensionContext + ": Texture type not supported");
  5617. }
  5618. if (extension.offset) {
  5619. babylonTexture.uOffset = extension.offset[0];
  5620. babylonTexture.vOffset = extension.offset[1];
  5621. }
  5622. // Always rotate around the origin.
  5623. babylonTexture.uRotationCenter = 0;
  5624. babylonTexture.vRotationCenter = 0;
  5625. if (extension.rotation) {
  5626. babylonTexture.wAng = -extension.rotation;
  5627. }
  5628. if (extension.scale) {
  5629. babylonTexture.uScale = extension.scale[0];
  5630. babylonTexture.vScale = extension.scale[1];
  5631. }
  5632. if (extension.texCoord != undefined) {
  5633. babylonTexture.coordinatesIndex = extension.texCoord;
  5634. }
  5635. assign(babylonTexture);
  5636. });
  5637. });
  5638. };
  5639. return KHR_texture_transform;
  5640. }());
  5641. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  5642. /***/ }),
  5643. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  5644. /*!***************************************************!*\
  5645. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  5646. \***************************************************/
  5647. /*! exports provided: MSFT_audio_emitter */
  5648. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5649. "use strict";
  5650. __webpack_require__.r(__webpack_exports__);
  5651. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  5652. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/observable");
  5653. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  5654. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5655. var NAME = "MSFT_audio_emitter";
  5656. /**
  5657. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  5658. */
  5659. var MSFT_audio_emitter = /** @class */ (function () {
  5660. /** @hidden */
  5661. function MSFT_audio_emitter(loader) {
  5662. /**
  5663. * The name of this extension.
  5664. */
  5665. this.name = NAME;
  5666. this._loader = loader;
  5667. this.enabled = this._loader.isExtensionUsed(NAME);
  5668. }
  5669. /** @hidden */
  5670. MSFT_audio_emitter.prototype.dispose = function () {
  5671. this._loader = null;
  5672. this._clips = null;
  5673. this._emitters = null;
  5674. };
  5675. /** @hidden */
  5676. MSFT_audio_emitter.prototype.onLoading = function () {
  5677. var extensions = this._loader.gltf.extensions;
  5678. if (extensions && extensions[this.name]) {
  5679. var extension = extensions[this.name];
  5680. this._clips = extension.clips;
  5681. this._emitters = extension.emitters;
  5682. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  5683. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  5684. }
  5685. };
  5686. /** @hidden */
  5687. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  5688. var _this = this;
  5689. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  5690. var promises = new Array();
  5691. promises.push(_this._loader.loadSceneAsync(context, scene));
  5692. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5693. var emitterIndex = _a[_i];
  5694. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5695. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  5696. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5697. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  5698. }
  5699. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  5700. }
  5701. return Promise.all(promises).then(function () { });
  5702. });
  5703. };
  5704. /** @hidden */
  5705. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  5706. var _this = this;
  5707. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5708. var promises = new Array();
  5709. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  5710. var _loop_1 = function (emitterIndex) {
  5711. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  5712. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  5713. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  5714. var sound = _a[_i];
  5715. sound.attachToMesh(babylonMesh);
  5716. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  5717. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  5718. 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);
  5719. }
  5720. }
  5721. }));
  5722. };
  5723. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  5724. var emitterIndex = _a[_i];
  5725. _loop_1(emitterIndex);
  5726. }
  5727. assign(babylonMesh);
  5728. }).then(function (babylonMesh) {
  5729. return Promise.all(promises).then(function () {
  5730. return babylonMesh;
  5731. });
  5732. });
  5733. });
  5734. };
  5735. /** @hidden */
  5736. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  5737. var _this = this;
  5738. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  5739. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  5740. var promises = new Array();
  5741. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  5742. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  5743. var event_1 = _a[_i];
  5744. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  5745. }
  5746. return Promise.all(promises).then(function () {
  5747. return babylonAnimationGroup;
  5748. });
  5749. });
  5750. });
  5751. };
  5752. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  5753. if (clip._objectURL) {
  5754. return clip._objectURL;
  5755. }
  5756. var promise;
  5757. if (clip.uri) {
  5758. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  5759. }
  5760. else {
  5761. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  5762. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  5763. }
  5764. clip._objectURL = promise.then(function (data) {
  5765. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  5766. });
  5767. return clip._objectURL;
  5768. };
  5769. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  5770. var _this = this;
  5771. emitter._babylonSounds = emitter._babylonSounds || [];
  5772. if (!emitter._babylonData) {
  5773. var clipPromises = new Array();
  5774. var name_1 = emitter.name || "emitter" + emitter.index;
  5775. var options_1 = {
  5776. loop: false,
  5777. autoplay: false,
  5778. volume: emitter.volume == undefined ? 1 : emitter.volume,
  5779. };
  5780. var _loop_2 = function (i) {
  5781. var clipContext = "/extensions/" + this_1.name + "/clips";
  5782. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  5783. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  5784. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  5785. sound.refDistance = emitter.refDistance || 1;
  5786. sound.maxDistance = emitter.maxDistance || 256;
  5787. sound.rolloffFactor = emitter.rolloffFactor || 1;
  5788. sound.distanceModel = emitter.distanceModel || 'exponential';
  5789. sound._positionInEmitterSpace = true;
  5790. }));
  5791. };
  5792. var this_1 = this;
  5793. for (var i = 0; i < emitter.clips.length; i++) {
  5794. _loop_2(i);
  5795. }
  5796. var promise = Promise.all(clipPromises).then(function () {
  5797. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  5798. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  5799. if (emitter.innerAngle) {
  5800. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  5801. }
  5802. if (emitter.outerAngle) {
  5803. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  5804. }
  5805. if (emitter.volume) {
  5806. weightedSound.volume = emitter.volume;
  5807. }
  5808. emitter._babylonData.sound = weightedSound;
  5809. });
  5810. emitter._babylonData = {
  5811. loaded: promise
  5812. };
  5813. }
  5814. return emitter._babylonData.loaded;
  5815. };
  5816. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  5817. switch (action) {
  5818. case "play" /* play */: {
  5819. return function (currentFrame) {
  5820. var frameOffset = (startOffset || 0) + (currentFrame - time);
  5821. sound.play(frameOffset);
  5822. };
  5823. }
  5824. case "stop" /* stop */: {
  5825. return function (currentFrame) {
  5826. sound.stop();
  5827. };
  5828. }
  5829. case "pause" /* pause */: {
  5830. return function (currentFrame) {
  5831. sound.pause();
  5832. };
  5833. }
  5834. default: {
  5835. throw new Error(context + ": Unsupported action " + action);
  5836. }
  5837. }
  5838. };
  5839. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  5840. var _this = this;
  5841. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  5842. return Promise.resolve();
  5843. }
  5844. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  5845. var emitterIndex = event.emitter;
  5846. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  5847. return this._loadEmitterAsync(context, emitter).then(function () {
  5848. var sound = emitter._babylonData.sound;
  5849. if (sound) {
  5850. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  5851. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  5852. // Make sure all started audio stops when this animation is terminated.
  5853. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  5854. sound.stop();
  5855. });
  5856. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  5857. sound.pause();
  5858. });
  5859. }
  5860. });
  5861. };
  5862. return MSFT_audio_emitter;
  5863. }());
  5864. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  5865. /***/ }),
  5866. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  5867. /*!*****************************************!*\
  5868. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  5869. \*****************************************/
  5870. /*! exports provided: MSFT_lod */
  5871. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5872. "use strict";
  5873. __webpack_require__.r(__webpack_exports__);
  5874. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  5875. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  5876. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  5877. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5878. var NAME = "MSFT_lod";
  5879. /**
  5880. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  5881. */
  5882. var MSFT_lod = /** @class */ (function () {
  5883. /** @hidden */
  5884. function MSFT_lod(loader) {
  5885. /**
  5886. * The name of this extension.
  5887. */
  5888. this.name = NAME;
  5889. /**
  5890. * Defines a number that determines the order the extensions are applied.
  5891. */
  5892. this.order = 100;
  5893. /**
  5894. * Maximum number of LODs to load, starting from the lowest LOD.
  5895. */
  5896. this.maxLODsToLoad = 10;
  5897. /**
  5898. * Observable raised when all node LODs of one level are loaded.
  5899. * The event data is the index of the loaded LOD starting from zero.
  5900. * Dispose the loader to cancel the loading of the next level of LODs.
  5901. */
  5902. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5903. /**
  5904. * Observable raised when all material LODs of one level are loaded.
  5905. * The event data is the index of the loaded LOD starting from zero.
  5906. * Dispose the loader to cancel the loading of the next level of LODs.
  5907. */
  5908. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5909. this._bufferLODs = new Array();
  5910. this._nodeIndexLOD = null;
  5911. this._nodeSignalLODs = new Array();
  5912. this._nodePromiseLODs = new Array();
  5913. this._nodeBufferLODs = new Array();
  5914. this._materialIndexLOD = null;
  5915. this._materialSignalLODs = new Array();
  5916. this._materialPromiseLODs = new Array();
  5917. this._materialBufferLODs = new Array();
  5918. this._loader = loader;
  5919. this.enabled = this._loader.isExtensionUsed(NAME);
  5920. }
  5921. /** @hidden */
  5922. MSFT_lod.prototype.dispose = function () {
  5923. this._loader = null;
  5924. this._nodeIndexLOD = null;
  5925. this._nodeSignalLODs.length = 0;
  5926. this._nodePromiseLODs.length = 0;
  5927. this._nodeBufferLODs.length = 0;
  5928. this._materialIndexLOD = null;
  5929. this._materialSignalLODs.length = 0;
  5930. this._materialPromiseLODs.length = 0;
  5931. this._materialBufferLODs.length = 0;
  5932. this.onMaterialLODsLoadedObservable.clear();
  5933. this.onNodeLODsLoadedObservable.clear();
  5934. };
  5935. /** @hidden */
  5936. MSFT_lod.prototype.onReady = function () {
  5937. var _this = this;
  5938. var _loop_1 = function (indexLOD) {
  5939. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  5940. if (indexLOD !== 0) {
  5941. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  5942. _this._loader.log("Loaded node LOD " + indexLOD);
  5943. }
  5944. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  5945. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  5946. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  5947. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  5948. if (_this._nodeSignalLODs[indexLOD]) {
  5949. _this._nodeSignalLODs[indexLOD].resolve();
  5950. }
  5951. }
  5952. });
  5953. this_1._loader._completePromises.push(promise);
  5954. };
  5955. var this_1 = this;
  5956. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  5957. _loop_1(indexLOD);
  5958. }
  5959. var _loop_2 = function (indexLOD) {
  5960. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  5961. if (indexLOD !== 0) {
  5962. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  5963. _this._loader.log("Loaded material LOD " + indexLOD);
  5964. }
  5965. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  5966. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  5967. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  5968. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  5969. if (_this._materialSignalLODs[indexLOD]) {
  5970. _this._materialSignalLODs[indexLOD].resolve();
  5971. }
  5972. }
  5973. });
  5974. this_2._loader._completePromises.push(promise);
  5975. };
  5976. var this_2 = this;
  5977. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  5978. _loop_2(indexLOD);
  5979. }
  5980. };
  5981. /** @hidden */
  5982. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  5983. var promise = this._loader.loadSceneAsync(context, scene);
  5984. this._loadBufferLOD(this._bufferLODs, 0);
  5985. return promise;
  5986. };
  5987. /** @hidden */
  5988. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  5989. var _this = this;
  5990. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5991. var firstPromise;
  5992. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5993. _this._loader.logOpen("" + extensionContext);
  5994. var _loop_3 = function (indexLOD) {
  5995. var nodeLOD = nodeLODs[indexLOD];
  5996. if (indexLOD !== 0) {
  5997. _this._nodeIndexLOD = indexLOD;
  5998. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5999. }
  6000. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  6001. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  6002. if (indexLOD !== 0) {
  6003. // TODO: should not rely on _babylonTransformNode
  6004. var previousNodeLOD = nodeLODs[indexLOD - 1];
  6005. if (previousNodeLOD._babylonTransformNode) {
  6006. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  6007. delete previousNodeLOD._babylonTransformNode;
  6008. }
  6009. }
  6010. babylonMesh.setEnabled(true);
  6011. return babylonMesh;
  6012. });
  6013. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  6014. if (indexLOD === 0) {
  6015. firstPromise = promise;
  6016. }
  6017. else {
  6018. _this._nodeIndexLOD = null;
  6019. _this._nodePromiseLODs[indexLOD].push(promise);
  6020. }
  6021. };
  6022. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  6023. _loop_3(indexLOD);
  6024. }
  6025. _this._loader.logClose();
  6026. return firstPromise;
  6027. });
  6028. };
  6029. /** @hidden */
  6030. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6031. var _this = this;
  6032. // Don't load material LODs if already loading a node LOD.
  6033. if (this._nodeIndexLOD) {
  6034. return null;
  6035. }
  6036. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  6037. var firstPromise;
  6038. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  6039. _this._loader.logOpen("" + extensionContext);
  6040. var _loop_4 = function (indexLOD) {
  6041. var materialLOD = materialLODs[indexLOD];
  6042. if (indexLOD !== 0) {
  6043. _this._materialIndexLOD = indexLOD;
  6044. }
  6045. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  6046. if (indexLOD === 0) {
  6047. assign(babylonMaterial);
  6048. }
  6049. }).then(function (babylonMaterial) {
  6050. if (indexLOD !== 0) {
  6051. assign(babylonMaterial);
  6052. // TODO: should not rely on _data
  6053. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  6054. if (previousDataLOD[babylonDrawMode]) {
  6055. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  6056. delete previousDataLOD[babylonDrawMode];
  6057. }
  6058. }
  6059. return babylonMaterial;
  6060. });
  6061. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  6062. if (indexLOD === 0) {
  6063. firstPromise = promise;
  6064. }
  6065. else {
  6066. _this._materialIndexLOD = null;
  6067. _this._materialPromiseLODs[indexLOD].push(promise);
  6068. }
  6069. };
  6070. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  6071. _loop_4(indexLOD);
  6072. }
  6073. _this._loader.logClose();
  6074. return firstPromise;
  6075. });
  6076. };
  6077. /** @hidden */
  6078. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  6079. var _this = this;
  6080. // Defer the loading of uris if loading a node or material LOD.
  6081. if (this._nodeIndexLOD !== null) {
  6082. this._loader.log("deferred");
  6083. var previousIndexLOD = this._nodeIndexLOD - 1;
  6084. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6085. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  6086. return _this._loader.loadUriAsync(context, property, uri);
  6087. });
  6088. }
  6089. else if (this._materialIndexLOD !== null) {
  6090. this._loader.log("deferred");
  6091. var previousIndexLOD = this._materialIndexLOD - 1;
  6092. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6093. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  6094. return _this._loader.loadUriAsync(context, property, uri);
  6095. });
  6096. }
  6097. return null;
  6098. };
  6099. /** @hidden */
  6100. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6101. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  6102. if (!this._loader.bin) {
  6103. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6104. }
  6105. var loadAsync = function (bufferLODs, indexLOD) {
  6106. var start = byteOffset;
  6107. var end = start + byteLength - 1;
  6108. var bufferLOD = bufferLODs[indexLOD];
  6109. if (bufferLOD) {
  6110. bufferLOD.start = Math.min(bufferLOD.start, start);
  6111. bufferLOD.end = Math.max(bufferLOD.end, end);
  6112. }
  6113. else {
  6114. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  6115. bufferLODs[indexLOD] = bufferLOD;
  6116. }
  6117. return bufferLOD.loaded.promise.then(function (data) {
  6118. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  6119. });
  6120. };
  6121. this._loader.log("deferred");
  6122. if (this._nodeIndexLOD !== null) {
  6123. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  6124. }
  6125. else if (this._materialIndexLOD !== null) {
  6126. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  6127. }
  6128. else {
  6129. return loadAsync(this._bufferLODs, 0);
  6130. }
  6131. }
  6132. return null;
  6133. };
  6134. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  6135. var bufferLOD = bufferLODs[indexLOD];
  6136. if (bufferLOD) {
  6137. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  6138. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  6139. bufferLOD.loaded.resolve(data);
  6140. }, function (error) {
  6141. bufferLOD.loaded.reject(error);
  6142. });
  6143. }
  6144. };
  6145. /**
  6146. * Gets an array of LOD properties from lowest to highest.
  6147. */
  6148. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  6149. if (this.maxLODsToLoad <= 0) {
  6150. throw new Error("maxLODsToLoad must be greater than zero");
  6151. }
  6152. var properties = new Array();
  6153. for (var i = ids.length - 1; i >= 0; i--) {
  6154. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  6155. if (properties.length === this.maxLODsToLoad) {
  6156. return properties;
  6157. }
  6158. }
  6159. properties.push(property);
  6160. return properties;
  6161. };
  6162. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  6163. var _this = this;
  6164. var babylonMaterials = new Array();
  6165. var babylonMaterial = babylonTransformNode.material;
  6166. if (babylonMaterial) {
  6167. babylonMaterials.push(babylonMaterial);
  6168. }
  6169. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  6170. var babylonMesh = _a[_i];
  6171. if (babylonMesh.material) {
  6172. babylonMaterials.push(babylonMesh.material);
  6173. }
  6174. }
  6175. babylonTransformNode.dispose();
  6176. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  6177. this._disposeMaterials(babylonMaterialsToDispose);
  6178. };
  6179. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  6180. var babylonTextures = {};
  6181. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  6182. var babylonMaterial = babylonMaterials_1[_i];
  6183. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  6184. var babylonTexture = _b[_a];
  6185. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  6186. }
  6187. babylonMaterial.dispose();
  6188. }
  6189. for (var uniqueId in babylonTextures) {
  6190. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  6191. var babylonMaterial = _d[_c];
  6192. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  6193. delete babylonTextures[uniqueId];
  6194. }
  6195. }
  6196. }
  6197. for (var uniqueId in babylonTextures) {
  6198. babylonTextures[uniqueId].dispose();
  6199. }
  6200. };
  6201. return MSFT_lod;
  6202. }());
  6203. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  6204. /***/ }),
  6205. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  6206. /*!***************************************************!*\
  6207. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  6208. \***************************************************/
  6209. /*! exports provided: MSFT_minecraftMesh */
  6210. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6211. "use strict";
  6212. __webpack_require__.r(__webpack_exports__);
  6213. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  6214. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  6215. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  6216. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  6217. var NAME = "MSFT_minecraftMesh";
  6218. /** @hidden */
  6219. var MSFT_minecraftMesh = /** @class */ (function () {
  6220. function MSFT_minecraftMesh(loader) {
  6221. this.name = NAME;
  6222. this._loader = loader;
  6223. this.enabled = this._loader.isExtensionUsed(NAME);
  6224. }
  6225. MSFT_minecraftMesh.prototype.dispose = function () {
  6226. this._loader = null;
  6227. };
  6228. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6229. var _this = this;
  6230. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  6231. if (extra) {
  6232. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6233. throw new Error(extraContext + ": Material type not supported");
  6234. }
  6235. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  6236. if (babylonMaterial.needAlphaBlending()) {
  6237. babylonMaterial.forceDepthWrite = true;
  6238. babylonMaterial.separateCullingPass = true;
  6239. }
  6240. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  6241. babylonMaterial.twoSidedLighting = true;
  6242. return promise;
  6243. }
  6244. return null;
  6245. });
  6246. };
  6247. return MSFT_minecraftMesh;
  6248. }());
  6249. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  6250. /***/ }),
  6251. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  6252. /*!*************************************************!*\
  6253. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  6254. \*************************************************/
  6255. /*! exports provided: MSFT_sRGBFactors */
  6256. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6257. "use strict";
  6258. __webpack_require__.r(__webpack_exports__);
  6259. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  6260. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  6261. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  6262. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  6263. var NAME = "MSFT_sRGBFactors";
  6264. /** @hidden */
  6265. var MSFT_sRGBFactors = /** @class */ (function () {
  6266. function MSFT_sRGBFactors(loader) {
  6267. this.name = NAME;
  6268. this._loader = loader;
  6269. this.enabled = this._loader.isExtensionUsed(NAME);
  6270. }
  6271. MSFT_sRGBFactors.prototype.dispose = function () {
  6272. this._loader = null;
  6273. };
  6274. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6275. var _this = this;
  6276. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  6277. if (extra) {
  6278. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6279. throw new Error(extraContext + ": Material type not supported");
  6280. }
  6281. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  6282. if (!babylonMaterial.albedoTexture) {
  6283. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  6284. }
  6285. if (!babylonMaterial.reflectivityTexture) {
  6286. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  6287. }
  6288. return promise;
  6289. }
  6290. return null;
  6291. });
  6292. };
  6293. return MSFT_sRGBFactors;
  6294. }());
  6295. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  6296. /***/ }),
  6297. /***/ "./glTF/2.0/Extensions/index.ts":
  6298. /*!**************************************!*\
  6299. !*** ./glTF/2.0/Extensions/index.ts ***!
  6300. \**************************************/
  6301. /*! 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, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  6302. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6303. "use strict";
  6304. __webpack_require__.r(__webpack_exports__);
  6305. /* 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");
  6306. /* 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"]; });
  6307. /* 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");
  6308. /* 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"]; });
  6309. /* harmony import */ var _EXT_meshopt_compression__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./EXT_meshopt_compression */ "./glTF/2.0/Extensions/EXT_meshopt_compression.ts");
  6310. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_meshopt_compression", function() { return _EXT_meshopt_compression__WEBPACK_IMPORTED_MODULE_2__["EXT_meshopt_compression"]; });
  6311. /* harmony import */ var _EXT_texture_webp__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EXT_texture_webp */ "./glTF/2.0/Extensions/EXT_texture_webp.ts");
  6312. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_texture_webp", function() { return _EXT_texture_webp__WEBPACK_IMPORTED_MODULE_3__["EXT_texture_webp"]; });
  6313. /* 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");
  6314. /* 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"]; });
  6315. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  6316. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_5__["KHR_lights"]; });
  6317. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  6318. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_pbrSpecularGlossiness"]; });
  6319. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  6320. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_unlit"]; });
  6321. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  6322. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_clearcoat"]; });
  6323. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  6324. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_sheen"]; });
  6325. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  6326. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_specular"]; });
  6327. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  6328. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_ior"]; });
  6329. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  6330. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_12__["KHR_materials_variants"]; });
  6331. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  6332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_13__["KHR_materials_transmission"]; });
  6333. /* harmony import */ var _KHR_materials_translucency__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_materials_translucency */ "./glTF/2.0/Extensions/KHR_materials_translucency.ts");
  6334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_translucency", function() { return _KHR_materials_translucency__WEBPACK_IMPORTED_MODULE_14__["KHR_materials_translucency"]; });
  6335. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  6336. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_15__["KHR_mesh_quantization"]; });
  6337. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  6338. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_16__["KHR_texture_basisu"]; });
  6339. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  6340. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_17__["KHR_texture_transform"]; });
  6341. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  6342. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_18__["MSFT_audio_emitter"]; });
  6343. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  6344. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_19__["MSFT_lod"]; });
  6345. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  6346. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_20__["MSFT_minecraftMesh"]; });
  6347. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  6348. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_21__["MSFT_sRGBFactors"]; });
  6349. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  6350. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_22__["ExtrasAsMetadata"]; });
  6351. /***/ }),
  6352. /***/ "./glTF/2.0/glTFLoader.ts":
  6353. /*!********************************!*\
  6354. !*** ./glTF/2.0/glTFLoader.ts ***!
  6355. \********************************/
  6356. /*! exports provided: ArrayItem, GLTFLoader */
  6357. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  6358. "use strict";
  6359. __webpack_require__.r(__webpack_exports__);
  6360. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  6361. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  6362. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/observable");
  6363. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  6364. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  6365. /**
  6366. * Helper class for working with arrays when loading the glTF asset
  6367. */
  6368. var ArrayItem = /** @class */ (function () {
  6369. function ArrayItem() {
  6370. }
  6371. /**
  6372. * Gets an item from the given array.
  6373. * @param context The context when loading the asset
  6374. * @param array The array to get the item from
  6375. * @param index The index to the array
  6376. * @returns The array item
  6377. */
  6378. ArrayItem.Get = function (context, array, index) {
  6379. if (!array || index == undefined || !array[index]) {
  6380. throw new Error(context + ": Failed to find index (" + index + ")");
  6381. }
  6382. return array[index];
  6383. };
  6384. /**
  6385. * Assign an `index` field to each item of the given array.
  6386. * @param array The array of items
  6387. */
  6388. ArrayItem.Assign = function (array) {
  6389. if (array) {
  6390. for (var index = 0; index < array.length; index++) {
  6391. array[index].index = index;
  6392. }
  6393. }
  6394. };
  6395. return ArrayItem;
  6396. }());
  6397. /**
  6398. * The glTF 2.0 loader
  6399. */
  6400. var GLTFLoader = /** @class */ (function () {
  6401. /** @hidden */
  6402. function GLTFLoader(parent) {
  6403. /** @hidden */
  6404. this._completePromises = new Array();
  6405. /** @hidden */
  6406. this._forAssetContainer = false;
  6407. /** Storage */
  6408. this._babylonLights = [];
  6409. /** @hidden */
  6410. this._disableInstancedMesh = 0;
  6411. this._disposed = false;
  6412. this._state = null;
  6413. this._extensions = new Array();
  6414. this._defaultBabylonMaterialData = {};
  6415. this._parent = parent;
  6416. }
  6417. /**
  6418. * Registers a loader extension.
  6419. * @param name The name of the loader extension.
  6420. * @param factory The factory function that creates the loader extension.
  6421. */
  6422. GLTFLoader.RegisterExtension = function (name, factory) {
  6423. if (GLTFLoader.UnregisterExtension(name)) {
  6424. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  6425. }
  6426. GLTFLoader._RegisteredExtensions[name] = {
  6427. factory: factory
  6428. };
  6429. };
  6430. /**
  6431. * Unregisters a loader extension.
  6432. * @param name The name of the loader extension.
  6433. * @returns A boolean indicating whether the extension has been unregistered
  6434. */
  6435. GLTFLoader.UnregisterExtension = function (name) {
  6436. if (!GLTFLoader._RegisteredExtensions[name]) {
  6437. return false;
  6438. }
  6439. delete GLTFLoader._RegisteredExtensions[name];
  6440. return true;
  6441. };
  6442. Object.defineProperty(GLTFLoader.prototype, "state", {
  6443. /**
  6444. * The loader state.
  6445. */
  6446. get: function () {
  6447. return this._state;
  6448. },
  6449. enumerable: false,
  6450. configurable: true
  6451. });
  6452. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  6453. /**
  6454. * The object that represents the glTF JSON.
  6455. */
  6456. get: function () {
  6457. return this._gltf;
  6458. },
  6459. enumerable: false,
  6460. configurable: true
  6461. });
  6462. Object.defineProperty(GLTFLoader.prototype, "bin", {
  6463. /**
  6464. * The BIN chunk of a binary glTF.
  6465. */
  6466. get: function () {
  6467. return this._bin;
  6468. },
  6469. enumerable: false,
  6470. configurable: true
  6471. });
  6472. Object.defineProperty(GLTFLoader.prototype, "parent", {
  6473. /**
  6474. * The parent file loader.
  6475. */
  6476. get: function () {
  6477. return this._parent;
  6478. },
  6479. enumerable: false,
  6480. configurable: true
  6481. });
  6482. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  6483. /**
  6484. * The Babylon scene when loading the asset.
  6485. */
  6486. get: function () {
  6487. return this._babylonScene;
  6488. },
  6489. enumerable: false,
  6490. configurable: true
  6491. });
  6492. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  6493. /**
  6494. * The root Babylon mesh when loading the asset.
  6495. */
  6496. get: function () {
  6497. return this._rootBabylonMesh;
  6498. },
  6499. enumerable: false,
  6500. configurable: true
  6501. });
  6502. /** @hidden */
  6503. GLTFLoader.prototype.dispose = function () {
  6504. if (this._disposed) {
  6505. return;
  6506. }
  6507. this._disposed = true;
  6508. this._completePromises.length = 0;
  6509. for (var name_1 in this._extensions) {
  6510. var extension = this._extensions[name_1];
  6511. extension.dispose && extension.dispose();
  6512. delete this._extensions[name_1];
  6513. }
  6514. this._gltf = null;
  6515. this._babylonScene = null;
  6516. this._rootBabylonMesh = null;
  6517. this._parent.dispose();
  6518. };
  6519. /** @hidden */
  6520. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  6521. var _this = this;
  6522. if (fileName === void 0) { fileName = ""; }
  6523. return Promise.resolve().then(function () {
  6524. _this._babylonScene = scene;
  6525. _this._forAssetContainer = forAssetContainer;
  6526. _this._loadData(data);
  6527. var nodes = null;
  6528. if (meshesNames) {
  6529. var nodeMap_1 = {};
  6530. if (_this._gltf.nodes) {
  6531. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  6532. var node = _a[_i];
  6533. if (node.name) {
  6534. nodeMap_1[node.name] = node.index;
  6535. }
  6536. }
  6537. }
  6538. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  6539. nodes = names.map(function (name) {
  6540. var node = nodeMap_1[name];
  6541. if (node === undefined) {
  6542. throw new Error("Failed to find node '" + name + "'");
  6543. }
  6544. return node;
  6545. });
  6546. }
  6547. return _this._loadAsync(rootUrl, fileName, nodes, function () {
  6548. return {
  6549. meshes: _this._getMeshes(),
  6550. particleSystems: [],
  6551. skeletons: _this._getSkeletons(),
  6552. animationGroups: _this._getAnimationGroups(),
  6553. lights: _this._babylonLights,
  6554. transformNodes: _this._getTransformNodes(),
  6555. geometries: _this._getGeometries()
  6556. };
  6557. });
  6558. });
  6559. };
  6560. /** @hidden */
  6561. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  6562. var _this = this;
  6563. if (fileName === void 0) { fileName = ""; }
  6564. return Promise.resolve().then(function () {
  6565. _this._babylonScene = scene;
  6566. _this._loadData(data);
  6567. return _this._loadAsync(rootUrl, fileName, null, function () { return undefined; });
  6568. });
  6569. };
  6570. GLTFLoader.prototype._loadAsync = function (rootUrl, fileName, nodes, resultFunc) {
  6571. var _this = this;
  6572. return Promise.resolve().then(function () {
  6573. _this._rootUrl = rootUrl;
  6574. _this._uniqueRootUrl = (!babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(rootUrl, "file:") && fileName) ? rootUrl : "" + rootUrl + Date.now() + "/";
  6575. _this._fileName = fileName;
  6576. _this._loadExtensions();
  6577. _this._checkExtensions();
  6578. 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];
  6579. 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];
  6580. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  6581. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  6582. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  6583. _this._extensionsOnLoading();
  6584. var promises = new Array();
  6585. // Block the marking of materials dirty until the scene is loaded.
  6586. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  6587. _this._babylonScene.blockMaterialDirtyMechanism = true;
  6588. if (nodes) {
  6589. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  6590. }
  6591. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  6592. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  6593. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  6594. }
  6595. if (_this.parent.loadAllMaterials && _this._gltf.materials) {
  6596. for (var m = 0; m < _this._gltf.materials.length; ++m) {
  6597. var material = _this._gltf.materials[m];
  6598. var context_1 = "/materials/" + m;
  6599. var babylonDrawMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  6600. promises.push(_this._loadMaterialAsync(context_1, material, null, babylonDrawMode, function (material) { }));
  6601. }
  6602. }
  6603. // Restore the blocking of material dirty.
  6604. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  6605. if (_this._parent.compileMaterials) {
  6606. promises.push(_this._compileMaterialsAsync());
  6607. }
  6608. if (_this._parent.compileShadowGenerators) {
  6609. promises.push(_this._compileShadowGeneratorsAsync());
  6610. }
  6611. var resultPromise = Promise.all(promises).then(function () {
  6612. if (_this._rootBabylonMesh) {
  6613. _this._rootBabylonMesh.setEnabled(true);
  6614. }
  6615. _this._extensionsOnReady();
  6616. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  6617. _this._startAnimations();
  6618. return resultFunc();
  6619. });
  6620. resultPromise.then(function () {
  6621. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  6622. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  6623. if (!_this._disposed) {
  6624. Promise.all(_this._completePromises).then(function () {
  6625. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  6626. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  6627. _this._parent.onCompleteObservable.notifyObservers(undefined);
  6628. _this._parent.onCompleteObservable.clear();
  6629. _this.dispose();
  6630. }, function (error) {
  6631. _this._parent.onErrorObservable.notifyObservers(error);
  6632. _this._parent.onErrorObservable.clear();
  6633. _this.dispose();
  6634. });
  6635. }
  6636. });
  6637. });
  6638. return resultPromise;
  6639. }).catch(function (error) {
  6640. if (!_this._disposed) {
  6641. _this._parent.onErrorObservable.notifyObservers(error);
  6642. _this._parent.onErrorObservable.clear();
  6643. _this.dispose();
  6644. }
  6645. throw error;
  6646. });
  6647. };
  6648. GLTFLoader.prototype._loadData = function (data) {
  6649. this._gltf = data.json;
  6650. this._setupData();
  6651. if (data.bin) {
  6652. var buffers = this._gltf.buffers;
  6653. if (buffers && buffers[0] && !buffers[0].uri) {
  6654. var binaryBuffer = buffers[0];
  6655. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  6656. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  6657. }
  6658. this._bin = data.bin;
  6659. }
  6660. else {
  6661. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  6662. }
  6663. }
  6664. };
  6665. GLTFLoader.prototype._setupData = function () {
  6666. ArrayItem.Assign(this._gltf.accessors);
  6667. ArrayItem.Assign(this._gltf.animations);
  6668. ArrayItem.Assign(this._gltf.buffers);
  6669. ArrayItem.Assign(this._gltf.bufferViews);
  6670. ArrayItem.Assign(this._gltf.cameras);
  6671. ArrayItem.Assign(this._gltf.images);
  6672. ArrayItem.Assign(this._gltf.materials);
  6673. ArrayItem.Assign(this._gltf.meshes);
  6674. ArrayItem.Assign(this._gltf.nodes);
  6675. ArrayItem.Assign(this._gltf.samplers);
  6676. ArrayItem.Assign(this._gltf.scenes);
  6677. ArrayItem.Assign(this._gltf.skins);
  6678. ArrayItem.Assign(this._gltf.textures);
  6679. if (this._gltf.nodes) {
  6680. var nodeParents = {};
  6681. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  6682. var node = _a[_i];
  6683. if (node.children) {
  6684. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  6685. var index = _c[_b];
  6686. nodeParents[index] = node.index;
  6687. }
  6688. }
  6689. }
  6690. var rootNode = this._createRootNode();
  6691. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  6692. var node = _e[_d];
  6693. var parentIndex = nodeParents[node.index];
  6694. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  6695. }
  6696. }
  6697. };
  6698. GLTFLoader.prototype._loadExtensions = function () {
  6699. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  6700. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  6701. if (extension.name !== name_2) {
  6702. 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);
  6703. }
  6704. this._extensions.push(extension);
  6705. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  6706. }
  6707. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  6708. this._parent.onExtensionLoadedObservable.clear();
  6709. };
  6710. GLTFLoader.prototype._checkExtensions = function () {
  6711. if (this._gltf.extensionsRequired) {
  6712. var _loop_1 = function (name_3) {
  6713. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  6714. if (!available) {
  6715. throw new Error("Require extension " + name_3 + " is not available");
  6716. }
  6717. };
  6718. var this_1 = this;
  6719. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  6720. var name_3 = _a[_i];
  6721. _loop_1(name_3);
  6722. }
  6723. }
  6724. };
  6725. GLTFLoader.prototype._setState = function (state) {
  6726. this._state = state;
  6727. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  6728. };
  6729. GLTFLoader.prototype._createRootNode = function () {
  6730. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6731. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  6732. this._babylonScene._blockEntityCollection = false;
  6733. this._rootBabylonMesh.setEnabled(false);
  6734. var rootNode = {
  6735. _babylonTransformNode: this._rootBabylonMesh,
  6736. index: -1
  6737. };
  6738. switch (this._parent.coordinateSystemMode) {
  6739. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  6740. if (!this._babylonScene.useRightHandedSystem) {
  6741. rootNode.rotation = [0, 1, 0, 0];
  6742. rootNode.scale = [1, 1, -1];
  6743. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  6744. }
  6745. break;
  6746. }
  6747. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  6748. this._babylonScene.useRightHandedSystem = true;
  6749. break;
  6750. }
  6751. default: {
  6752. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  6753. }
  6754. }
  6755. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  6756. return rootNode;
  6757. };
  6758. /**
  6759. * Loads a glTF scene.
  6760. * @param context The context when loading the asset
  6761. * @param scene The glTF scene property
  6762. * @returns A promise that resolves when the load is complete
  6763. */
  6764. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  6765. var _this = this;
  6766. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  6767. if (extensionPromise) {
  6768. return extensionPromise;
  6769. }
  6770. var promises = new Array();
  6771. this.logOpen(context + " " + (scene.name || ""));
  6772. if (scene.nodes) {
  6773. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  6774. var index = _a[_i];
  6775. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  6776. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  6777. babylonMesh.parent = _this._rootBabylonMesh;
  6778. }));
  6779. }
  6780. }
  6781. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  6782. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  6783. if (this._gltf.nodes) {
  6784. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  6785. var node = _c[_b];
  6786. if (node._babylonTransformNode && node._babylonBones) {
  6787. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  6788. var babylonBone = _e[_d];
  6789. babylonBone.linkTransformNode(node._babylonTransformNode);
  6790. }
  6791. }
  6792. }
  6793. }
  6794. promises.push(this._loadAnimationsAsync());
  6795. this.logClose();
  6796. return Promise.all(promises).then(function () { });
  6797. };
  6798. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  6799. if (node._primitiveBabylonMeshes) {
  6800. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  6801. var babylonMesh = _a[_i];
  6802. callback(babylonMesh);
  6803. }
  6804. }
  6805. };
  6806. GLTFLoader.prototype._getGeometries = function () {
  6807. var geometries = new Array();
  6808. var nodes = this._gltf.nodes;
  6809. if (nodes) {
  6810. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  6811. var node = nodes_1[_i];
  6812. this._forEachPrimitive(node, function (babylonMesh) {
  6813. var geometry = babylonMesh.geometry;
  6814. if (geometry && geometries.indexOf(geometry) === -1) {
  6815. geometries.push(geometry);
  6816. }
  6817. });
  6818. }
  6819. }
  6820. return geometries;
  6821. };
  6822. GLTFLoader.prototype._getMeshes = function () {
  6823. var meshes = new Array();
  6824. // Root mesh is always first.
  6825. meshes.push(this._rootBabylonMesh);
  6826. var nodes = this._gltf.nodes;
  6827. if (nodes) {
  6828. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  6829. var node = nodes_2[_i];
  6830. this._forEachPrimitive(node, function (babylonMesh) {
  6831. meshes.push(babylonMesh);
  6832. });
  6833. }
  6834. }
  6835. return meshes;
  6836. };
  6837. GLTFLoader.prototype._getTransformNodes = function () {
  6838. var transformNodes = new Array();
  6839. var nodes = this._gltf.nodes;
  6840. if (nodes) {
  6841. for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
  6842. var node = nodes_3[_i];
  6843. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  6844. transformNodes.push(node._babylonTransformNode);
  6845. }
  6846. }
  6847. }
  6848. return transformNodes;
  6849. };
  6850. GLTFLoader.prototype._getSkeletons = function () {
  6851. var skeletons = new Array();
  6852. var skins = this._gltf.skins;
  6853. if (skins) {
  6854. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  6855. var skin = skins_1[_i];
  6856. if (skin._data) {
  6857. skeletons.push(skin._data.babylonSkeleton);
  6858. }
  6859. }
  6860. }
  6861. return skeletons;
  6862. };
  6863. GLTFLoader.prototype._getAnimationGroups = function () {
  6864. var animationGroups = new Array();
  6865. var animations = this._gltf.animations;
  6866. if (animations) {
  6867. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  6868. var animation = animations_1[_i];
  6869. if (animation._babylonAnimationGroup) {
  6870. animationGroups.push(animation._babylonAnimationGroup);
  6871. }
  6872. }
  6873. }
  6874. return animationGroups;
  6875. };
  6876. GLTFLoader.prototype._startAnimations = function () {
  6877. switch (this._parent.animationStartMode) {
  6878. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  6879. // do nothing
  6880. break;
  6881. }
  6882. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  6883. var babylonAnimationGroups = this._getAnimationGroups();
  6884. if (babylonAnimationGroups.length !== 0) {
  6885. babylonAnimationGroups[0].start(true);
  6886. }
  6887. break;
  6888. }
  6889. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  6890. var babylonAnimationGroups = this._getAnimationGroups();
  6891. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  6892. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  6893. babylonAnimationGroup.start(true);
  6894. }
  6895. break;
  6896. }
  6897. default: {
  6898. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  6899. return;
  6900. }
  6901. }
  6902. };
  6903. /**
  6904. * Loads a glTF node.
  6905. * @param context The context when loading the asset
  6906. * @param node The glTF node property
  6907. * @param assign A function called synchronously after parsing the glTF properties
  6908. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  6909. */
  6910. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  6911. var _this = this;
  6912. if (assign === void 0) { assign = function () { }; }
  6913. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  6914. if (extensionPromise) {
  6915. return extensionPromise;
  6916. }
  6917. if (node._babylonTransformNode) {
  6918. throw new Error(context + ": Invalid recursive node hierarchy");
  6919. }
  6920. var promises = new Array();
  6921. this.logOpen(context + " " + (node.name || ""));
  6922. var loadNode = function (babylonTransformNode) {
  6923. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  6924. GLTFLoader._LoadTransform(node, babylonTransformNode);
  6925. if (node.camera != undefined) {
  6926. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  6927. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  6928. babylonCamera.parent = babylonTransformNode;
  6929. }));
  6930. }
  6931. if (node.children) {
  6932. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  6933. var index = _a[_i];
  6934. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  6935. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  6936. childBabylonMesh.parent = babylonTransformNode;
  6937. }));
  6938. }
  6939. }
  6940. assign(babylonTransformNode);
  6941. };
  6942. if (node.mesh == undefined) {
  6943. var nodeName = node.name || "node" + node.index;
  6944. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6945. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  6946. this._babylonScene._blockEntityCollection = false;
  6947. loadNode(node._babylonTransformNode);
  6948. }
  6949. else {
  6950. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  6951. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  6952. }
  6953. this.logClose();
  6954. return Promise.all(promises).then(function () {
  6955. _this._forEachPrimitive(node, function (babylonMesh) {
  6956. if (babylonMesh.geometry && babylonMesh.geometry.useBoundingInfoFromGeometry) {
  6957. // simply apply the world matrices to the bounding info - the extends are already ok
  6958. babylonMesh._updateBoundingInfo();
  6959. }
  6960. else {
  6961. babylonMesh.refreshBoundingInfo(true);
  6962. }
  6963. });
  6964. return node._babylonTransformNode;
  6965. });
  6966. };
  6967. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  6968. var primitives = mesh.primitives;
  6969. if (!primitives || !primitives.length) {
  6970. throw new Error(context + ": Primitives are missing");
  6971. }
  6972. if (primitives[0].index == undefined) {
  6973. ArrayItem.Assign(primitives);
  6974. }
  6975. var promises = new Array();
  6976. this.logOpen(context + " " + (mesh.name || ""));
  6977. var name = node.name || "node" + node.index;
  6978. if (primitives.length === 1) {
  6979. var primitive = mesh.primitives[0];
  6980. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  6981. node._babylonTransformNode = babylonMesh;
  6982. node._primitiveBabylonMeshes = [babylonMesh];
  6983. }));
  6984. }
  6985. else {
  6986. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6987. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  6988. this._babylonScene._blockEntityCollection = false;
  6989. node._primitiveBabylonMeshes = [];
  6990. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  6991. var primitive = primitives_1[_i];
  6992. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  6993. babylonMesh.parent = node._babylonTransformNode;
  6994. node._primitiveBabylonMeshes.push(babylonMesh);
  6995. }));
  6996. }
  6997. }
  6998. if (node.skin != undefined) {
  6999. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  7000. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  7001. }
  7002. assign(node._babylonTransformNode);
  7003. this.logClose();
  7004. return Promise.all(promises).then(function () {
  7005. return node._babylonTransformNode;
  7006. });
  7007. };
  7008. /**
  7009. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  7010. * @param context The context when loading the asset
  7011. * @param name The mesh name when loading the asset
  7012. * @param node The glTF node when loading the asset
  7013. * @param mesh The glTF mesh when loading the asset
  7014. * @param primitive The glTF mesh primitive property
  7015. * @param assign A function called synchronously after parsing the glTF properties
  7016. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  7017. */
  7018. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7019. var _this = this;
  7020. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  7021. if (extensionPromise) {
  7022. return extensionPromise;
  7023. }
  7024. this.logOpen("" + context);
  7025. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  7026. var babylonAbstractMesh;
  7027. var promise;
  7028. if (shouldInstance && primitive._instanceData) {
  7029. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  7030. promise = primitive._instanceData.promise;
  7031. }
  7032. else {
  7033. var promises = new Array();
  7034. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7035. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  7036. this._babylonScene._blockEntityCollection = false;
  7037. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  7038. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  7039. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  7040. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  7041. _this._babylonScene._blockEntityCollection = _this._forAssetContainer;
  7042. babylonGeometry.applyToMesh(babylonMesh_1);
  7043. _this._babylonScene._blockEntityCollection = false;
  7044. });
  7045. }));
  7046. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  7047. if (primitive.material == undefined) {
  7048. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  7049. if (!babylonMaterial) {
  7050. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  7051. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7052. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  7053. }
  7054. babylonMesh_1.material = babylonMaterial;
  7055. }
  7056. else {
  7057. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  7058. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  7059. babylonMesh_1.material = babylonMaterial;
  7060. }));
  7061. }
  7062. promise = Promise.all(promises);
  7063. if (shouldInstance) {
  7064. primitive._instanceData = {
  7065. babylonSourceMesh: babylonMesh_1,
  7066. promise: promise
  7067. };
  7068. }
  7069. babylonAbstractMesh = babylonMesh_1;
  7070. }
  7071. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  7072. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  7073. assign(babylonAbstractMesh);
  7074. this.logClose();
  7075. return promise.then(function () {
  7076. return babylonAbstractMesh;
  7077. });
  7078. };
  7079. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  7080. var _this = this;
  7081. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  7082. if (extensionPromise) {
  7083. return extensionPromise;
  7084. }
  7085. var attributes = primitive.attributes;
  7086. if (!attributes) {
  7087. throw new Error(context + ": Attributes are missing");
  7088. }
  7089. var promises = new Array();
  7090. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  7091. if (primitive.indices == undefined) {
  7092. babylonMesh.isUnIndexed = true;
  7093. }
  7094. else {
  7095. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  7096. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7097. babylonGeometry.setIndices(data);
  7098. }));
  7099. }
  7100. var loadAttribute = function (attribute, kind, callback) {
  7101. if (attributes[attribute] == undefined) {
  7102. return;
  7103. }
  7104. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  7105. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  7106. babylonMesh._delayInfo.push(kind);
  7107. }
  7108. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  7109. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  7110. if (babylonVertexBuffer.getKind() === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
  7111. var mmin = accessor.min, mmax = accessor.max;
  7112. if (mmin !== undefined && mmax !== undefined) {
  7113. var min = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], max = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1];
  7114. min.copyFromFloats.apply(min, mmin);
  7115. max.copyFromFloats.apply(max, mmax);
  7116. babylonGeometry._boundingInfo = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["BoundingInfo"](min, max);
  7117. babylonGeometry.useBoundingInfoFromGeometry = true;
  7118. }
  7119. }
  7120. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  7121. }));
  7122. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  7123. babylonMesh.numBoneInfluencers = 8;
  7124. }
  7125. if (callback) {
  7126. callback(accessor);
  7127. }
  7128. };
  7129. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  7130. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  7131. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  7132. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  7133. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  7134. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  7135. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  7136. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  7137. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  7138. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  7139. if (accessor.type === "VEC4" /* VEC4 */) {
  7140. babylonMesh.hasVertexAlpha = true;
  7141. }
  7142. });
  7143. return Promise.all(promises).then(function () {
  7144. return babylonGeometry;
  7145. });
  7146. };
  7147. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  7148. if (!primitive.targets) {
  7149. return;
  7150. }
  7151. if (node._numMorphTargets == undefined) {
  7152. node._numMorphTargets = primitive.targets.length;
  7153. }
  7154. else if (primitive.targets.length !== node._numMorphTargets) {
  7155. throw new Error(context + ": Primitives do not have the same number of targets");
  7156. }
  7157. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  7158. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  7159. for (var index = 0; index < primitive.targets.length; index++) {
  7160. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  7161. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  7162. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  7163. // TODO: tell the target whether it has positions, normals, tangents
  7164. }
  7165. };
  7166. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  7167. if (!primitive.targets) {
  7168. return Promise.resolve();
  7169. }
  7170. var promises = new Array();
  7171. var morphTargetManager = babylonMesh.morphTargetManager;
  7172. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  7173. var babylonMorphTarget = morphTargetManager.getTarget(index);
  7174. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  7175. }
  7176. return Promise.all(promises).then(function () { });
  7177. };
  7178. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  7179. var _this = this;
  7180. var promises = new Array();
  7181. var loadAttribute = function (attribute, kind, setData) {
  7182. if (attributes[attribute] == undefined) {
  7183. return;
  7184. }
  7185. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  7186. if (!babylonVertexBuffer) {
  7187. return;
  7188. }
  7189. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  7190. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7191. setData(babylonVertexBuffer, data);
  7192. }));
  7193. };
  7194. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  7195. var positions = new Float32Array(data.length);
  7196. babylonVertexBuffer.forEach(data.length, function (value, index) {
  7197. positions[index] = data[index] + value;
  7198. });
  7199. babylonMorphTarget.setPositions(positions);
  7200. });
  7201. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  7202. var normals = new Float32Array(data.length);
  7203. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  7204. normals[index] = data[index] + value;
  7205. });
  7206. babylonMorphTarget.setNormals(normals);
  7207. });
  7208. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  7209. var tangents = new Float32Array(data.length / 3 * 4);
  7210. var dataIndex = 0;
  7211. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  7212. // Tangent data for morph targets is stored as xyz delta.
  7213. // The vertexData.tangent is stored as xyzw.
  7214. // So we need to skip every fourth vertexData.tangent.
  7215. if (((index + 1) % 4) !== 0) {
  7216. tangents[dataIndex] = data[dataIndex] + value;
  7217. dataIndex++;
  7218. }
  7219. });
  7220. babylonMorphTarget.setTangents(tangents);
  7221. });
  7222. return Promise.all(promises).then(function () { });
  7223. };
  7224. GLTFLoader._LoadTransform = function (node, babylonNode) {
  7225. // Ignore the TRS of skinned nodes.
  7226. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  7227. if (node.skin != undefined) {
  7228. return;
  7229. }
  7230. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  7231. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  7232. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  7233. if (node.matrix) {
  7234. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  7235. matrix.decompose(scaling, rotation, position);
  7236. }
  7237. else {
  7238. if (node.translation) {
  7239. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  7240. }
  7241. if (node.rotation) {
  7242. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  7243. }
  7244. if (node.scale) {
  7245. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  7246. }
  7247. }
  7248. babylonNode.position = position;
  7249. babylonNode.rotationQuaternion = rotation;
  7250. babylonNode.scaling = scaling;
  7251. };
  7252. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  7253. var _this = this;
  7254. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  7255. if (extensionPromise) {
  7256. return extensionPromise;
  7257. }
  7258. var assignSkeleton = function (skeleton) {
  7259. _this._forEachPrimitive(node, function (babylonMesh) {
  7260. babylonMesh.skeleton = skeleton;
  7261. });
  7262. };
  7263. if (skin._data) {
  7264. assignSkeleton(skin._data.babylonSkeleton);
  7265. return skin._data.promise;
  7266. }
  7267. var skeletonId = "skeleton" + skin.index;
  7268. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7269. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  7270. this._babylonScene._blockEntityCollection = false;
  7271. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  7272. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  7273. this._loadBones(context, skin, babylonSkeleton);
  7274. assignSkeleton(babylonSkeleton);
  7275. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  7276. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  7277. });
  7278. skin._data = {
  7279. babylonSkeleton: babylonSkeleton,
  7280. promise: promise
  7281. };
  7282. return promise;
  7283. };
  7284. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  7285. var babylonBones = {};
  7286. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  7287. var index = _a[_i];
  7288. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  7289. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  7290. }
  7291. };
  7292. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  7293. var babylonBone = babylonBones[node.index];
  7294. if (babylonBone) {
  7295. return babylonBone;
  7296. }
  7297. var babylonParentBone = null;
  7298. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  7299. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  7300. }
  7301. var boneIndex = skin.joints.indexOf(node.index);
  7302. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  7303. babylonBones[node.index] = babylonBone;
  7304. node._babylonBones = node._babylonBones || [];
  7305. node._babylonBones.push(babylonBone);
  7306. return babylonBone;
  7307. };
  7308. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  7309. if (skin.inverseBindMatrices == undefined) {
  7310. return Promise.resolve(null);
  7311. }
  7312. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  7313. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  7314. };
  7315. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  7316. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  7317. var babylonBone = _a[_i];
  7318. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  7319. var boneIndex = babylonBone._index;
  7320. if (inverseBindMatricesData && boneIndex !== -1) {
  7321. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  7322. baseMatrix.invertToRef(baseMatrix);
  7323. }
  7324. var babylonParentBone = babylonBone.getParent();
  7325. if (babylonParentBone) {
  7326. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  7327. }
  7328. babylonBone.setBindPose(baseMatrix);
  7329. babylonBone.updateMatrix(baseMatrix, false, false);
  7330. babylonBone._updateDifferenceMatrix(undefined, false);
  7331. }
  7332. };
  7333. GLTFLoader.prototype._getNodeMatrix = function (node) {
  7334. return node.matrix ?
  7335. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  7336. 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());
  7337. };
  7338. /**
  7339. * Loads a glTF camera.
  7340. * @param context The context when loading the asset
  7341. * @param camera The glTF camera property
  7342. * @param assign A function called synchronously after parsing the glTF properties
  7343. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  7344. */
  7345. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  7346. if (assign === void 0) { assign = function () { }; }
  7347. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  7348. if (extensionPromise) {
  7349. return extensionPromise;
  7350. }
  7351. var promises = new Array();
  7352. this.logOpen(context + " " + (camera.name || ""));
  7353. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7354. 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);
  7355. this._babylonScene._blockEntityCollection = false;
  7356. babylonCamera.ignoreParentScaling = true;
  7357. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  7358. switch (camera.type) {
  7359. case "perspective" /* PERSPECTIVE */: {
  7360. var perspective = camera.perspective;
  7361. if (!perspective) {
  7362. throw new Error(context + ": Camera perspective properties are missing");
  7363. }
  7364. babylonCamera.fov = perspective.yfov;
  7365. babylonCamera.minZ = perspective.znear;
  7366. babylonCamera.maxZ = perspective.zfar || 0;
  7367. break;
  7368. }
  7369. case "orthographic" /* ORTHOGRAPHIC */: {
  7370. if (!camera.orthographic) {
  7371. throw new Error(context + ": Camera orthographic properties are missing");
  7372. }
  7373. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  7374. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  7375. babylonCamera.orthoRight = camera.orthographic.xmag;
  7376. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  7377. babylonCamera.orthoTop = camera.orthographic.ymag;
  7378. babylonCamera.minZ = camera.orthographic.znear;
  7379. babylonCamera.maxZ = camera.orthographic.zfar;
  7380. break;
  7381. }
  7382. default: {
  7383. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  7384. }
  7385. }
  7386. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  7387. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  7388. assign(babylonCamera);
  7389. this.logClose();
  7390. return Promise.all(promises).then(function () {
  7391. return babylonCamera;
  7392. });
  7393. };
  7394. GLTFLoader.prototype._loadAnimationsAsync = function () {
  7395. var animations = this._gltf.animations;
  7396. if (!animations) {
  7397. return Promise.resolve();
  7398. }
  7399. var promises = new Array();
  7400. for (var index = 0; index < animations.length; index++) {
  7401. var animation = animations[index];
  7402. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation).then(function (animationGroup) {
  7403. // Delete the animation group if it ended up not having any animations in it.
  7404. if (animationGroup.targetedAnimations.length === 0) {
  7405. animationGroup.dispose();
  7406. }
  7407. }));
  7408. }
  7409. return Promise.all(promises).then(function () { });
  7410. };
  7411. /**
  7412. * Loads a glTF animation.
  7413. * @param context The context when loading the asset
  7414. * @param animation The glTF animation property
  7415. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  7416. */
  7417. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  7418. var promise = this._extensionsLoadAnimationAsync(context, animation);
  7419. if (promise) {
  7420. return promise;
  7421. }
  7422. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7423. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  7424. this._babylonScene._blockEntityCollection = false;
  7425. animation._babylonAnimationGroup = babylonAnimationGroup;
  7426. var promises = new Array();
  7427. ArrayItem.Assign(animation.channels);
  7428. ArrayItem.Assign(animation.samplers);
  7429. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  7430. var channel = _a[_i];
  7431. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  7432. }
  7433. return Promise.all(promises).then(function () {
  7434. babylonAnimationGroup.normalize(0);
  7435. return babylonAnimationGroup;
  7436. });
  7437. };
  7438. /**
  7439. * @hidden Loads a glTF animation channel.
  7440. * @param context The context when loading the asset
  7441. * @param animationContext The context of the animation when loading the asset
  7442. * @param animation The glTF animation property
  7443. * @param channel The glTF animation channel property
  7444. * @param babylonAnimationGroup The babylon animation group property
  7445. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  7446. * @returns A void promise when the channel load is complete
  7447. */
  7448. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  7449. var _this = this;
  7450. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  7451. if (channel.target.node == undefined) {
  7452. return Promise.resolve();
  7453. }
  7454. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  7455. // Ignore animations that have no animation targets.
  7456. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  7457. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  7458. return Promise.resolve();
  7459. }
  7460. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  7461. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  7462. var targetPath;
  7463. var animationType;
  7464. switch (channel.target.path) {
  7465. case "translation" /* TRANSLATION */: {
  7466. targetPath = "position";
  7467. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  7468. break;
  7469. }
  7470. case "rotation" /* ROTATION */: {
  7471. targetPath = "rotationQuaternion";
  7472. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  7473. break;
  7474. }
  7475. case "scale" /* SCALE */: {
  7476. targetPath = "scaling";
  7477. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  7478. break;
  7479. }
  7480. case "weights" /* WEIGHTS */: {
  7481. targetPath = "influence";
  7482. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  7483. break;
  7484. }
  7485. default: {
  7486. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  7487. }
  7488. }
  7489. var outputBufferOffset = 0;
  7490. var getNextOutputValue;
  7491. switch (targetPath) {
  7492. case "position": {
  7493. getNextOutputValue = function () {
  7494. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7495. outputBufferOffset += 3;
  7496. return value;
  7497. };
  7498. break;
  7499. }
  7500. case "rotationQuaternion": {
  7501. getNextOutputValue = function () {
  7502. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  7503. outputBufferOffset += 4;
  7504. return value;
  7505. };
  7506. break;
  7507. }
  7508. case "scaling": {
  7509. getNextOutputValue = function () {
  7510. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  7511. outputBufferOffset += 3;
  7512. return value;
  7513. };
  7514. break;
  7515. }
  7516. case "influence": {
  7517. getNextOutputValue = function () {
  7518. var value = new Array(targetNode._numMorphTargets);
  7519. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  7520. value[i] = data.output[outputBufferOffset++];
  7521. }
  7522. return value;
  7523. };
  7524. break;
  7525. }
  7526. }
  7527. var getNextKey;
  7528. switch (data.interpolation) {
  7529. case "STEP" /* STEP */: {
  7530. getNextKey = function (frameIndex) { return ({
  7531. frame: data.input[frameIndex],
  7532. value: getNextOutputValue(),
  7533. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  7534. }); };
  7535. break;
  7536. }
  7537. case "LINEAR" /* LINEAR */: {
  7538. getNextKey = function (frameIndex) { return ({
  7539. frame: data.input[frameIndex],
  7540. value: getNextOutputValue()
  7541. }); };
  7542. break;
  7543. }
  7544. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7545. getNextKey = function (frameIndex) { return ({
  7546. frame: data.input[frameIndex],
  7547. inTangent: getNextOutputValue(),
  7548. value: getNextOutputValue(),
  7549. outTangent: getNextOutputValue()
  7550. }); };
  7551. break;
  7552. }
  7553. }
  7554. var keys = new Array(data.input.length);
  7555. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  7556. keys[frameIndex] = getNextKey(frameIndex);
  7557. }
  7558. if (targetPath === "influence") {
  7559. var _loop_2 = function (targetIndex) {
  7560. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7561. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7562. babylonAnimation.setKeys(keys.map(function (key) { return ({
  7563. frame: key.frame,
  7564. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  7565. value: key.value[targetIndex],
  7566. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  7567. }); }));
  7568. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  7569. var babylonMesh = babylonAbstractMesh;
  7570. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  7571. var babylonAnimationClone = babylonAnimation.clone();
  7572. morphTarget.animations.push(babylonAnimationClone);
  7573. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  7574. });
  7575. };
  7576. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  7577. _loop_2(targetIndex);
  7578. }
  7579. }
  7580. else {
  7581. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  7582. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  7583. babylonAnimation.setKeys(keys);
  7584. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  7585. animationTargetOverride.animations.push(babylonAnimation);
  7586. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  7587. }
  7588. else {
  7589. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  7590. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  7591. }
  7592. }
  7593. });
  7594. };
  7595. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  7596. if (sampler._data) {
  7597. return sampler._data;
  7598. }
  7599. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  7600. switch (interpolation) {
  7601. case "STEP" /* STEP */:
  7602. case "LINEAR" /* LINEAR */:
  7603. case "CUBICSPLINE" /* CUBICSPLINE */: {
  7604. break;
  7605. }
  7606. default: {
  7607. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  7608. }
  7609. }
  7610. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  7611. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  7612. sampler._data = Promise.all([
  7613. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  7614. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  7615. ]).then(function (_a) {
  7616. var inputData = _a[0], outputData = _a[1];
  7617. return {
  7618. input: inputData,
  7619. interpolation: interpolation,
  7620. output: outputData,
  7621. };
  7622. });
  7623. return sampler._data;
  7624. };
  7625. /**
  7626. * Loads a glTF buffer.
  7627. * @param context The context when loading the asset
  7628. * @param buffer The glTF buffer property
  7629. * @param byteOffset The byte offset to use
  7630. * @param byteLength The byte length to use
  7631. * @returns A promise that resolves with the loaded data when the load is complete
  7632. */
  7633. GLTFLoader.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7634. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  7635. if (extensionPromise) {
  7636. return extensionPromise;
  7637. }
  7638. if (!buffer._data) {
  7639. if (buffer.uri) {
  7640. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  7641. }
  7642. else {
  7643. if (!this._bin) {
  7644. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  7645. }
  7646. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  7647. }
  7648. }
  7649. return buffer._data.then(function (data) {
  7650. try {
  7651. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  7652. }
  7653. catch (e) {
  7654. throw new Error(context + ": " + e.message);
  7655. }
  7656. });
  7657. };
  7658. /**
  7659. * Loads a glTF buffer view.
  7660. * @param context The context when loading the asset
  7661. * @param bufferView The glTF buffer view property
  7662. * @returns A promise that resolves with the loaded data when the load is complete
  7663. */
  7664. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  7665. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  7666. if (extensionPromise) {
  7667. return extensionPromise;
  7668. }
  7669. if (bufferView._data) {
  7670. return bufferView._data;
  7671. }
  7672. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  7673. bufferView._data = this.loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  7674. return bufferView._data;
  7675. };
  7676. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  7677. var _this = this;
  7678. if (accessor._data) {
  7679. return accessor._data;
  7680. }
  7681. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  7682. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  7683. var length = numComponents * accessor.count;
  7684. if (accessor.bufferView == undefined) {
  7685. accessor._data = Promise.resolve(new constructor(length));
  7686. }
  7687. else {
  7688. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7689. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  7690. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized && (!bufferView_1.byteStride || bufferView_1.byteStride === byteStride)) {
  7691. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  7692. }
  7693. else {
  7694. var typedArray_1 = new constructor(length);
  7695. 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) {
  7696. typedArray_1[index] = value;
  7697. });
  7698. return typedArray_1;
  7699. }
  7700. });
  7701. }
  7702. if (accessor.sparse) {
  7703. var sparse_1 = accessor.sparse;
  7704. accessor._data = accessor._data.then(function (data) {
  7705. var typedArray = data;
  7706. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  7707. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  7708. return Promise.all([
  7709. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  7710. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  7711. ]).then(function (_a) {
  7712. var indicesData = _a[0], valuesData = _a[1];
  7713. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  7714. var sparseLength = numComponents * sparse_1.count;
  7715. var values;
  7716. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  7717. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7718. }
  7719. else {
  7720. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  7721. values = new constructor(sparseLength);
  7722. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  7723. values[index] = value;
  7724. });
  7725. }
  7726. var valuesIndex = 0;
  7727. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  7728. var dataIndex = indices[indicesIndex] * numComponents;
  7729. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  7730. typedArray[dataIndex++] = values[valuesIndex++];
  7731. }
  7732. }
  7733. return typedArray;
  7734. });
  7735. });
  7736. }
  7737. return accessor._data;
  7738. };
  7739. /** @hidden */
  7740. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  7741. return this._loadAccessorAsync(context, accessor, Float32Array);
  7742. };
  7743. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  7744. if (accessor.type !== "SCALAR" /* SCALAR */) {
  7745. throw new Error(context + "/type: Invalid value " + accessor.type);
  7746. }
  7747. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  7748. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  7749. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  7750. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  7751. }
  7752. if (accessor._data) {
  7753. return accessor._data;
  7754. }
  7755. if (accessor.sparse) {
  7756. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  7757. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  7758. }
  7759. else {
  7760. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7761. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7762. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  7763. });
  7764. }
  7765. return accessor._data;
  7766. };
  7767. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  7768. var _this = this;
  7769. if (bufferView._babylonBuffer) {
  7770. return bufferView._babylonBuffer;
  7771. }
  7772. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  7773. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  7774. });
  7775. return bufferView._babylonBuffer;
  7776. };
  7777. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  7778. var _this = this;
  7779. if (accessor._babylonVertexBuffer) {
  7780. return accessor._babylonVertexBuffer;
  7781. }
  7782. if (accessor.sparse) {
  7783. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7784. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7785. });
  7786. }
  7787. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  7788. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  7789. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  7790. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7791. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7792. });
  7793. }
  7794. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  7795. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  7796. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  7797. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  7798. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  7799. });
  7800. }
  7801. else {
  7802. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  7803. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  7804. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  7805. 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);
  7806. });
  7807. }
  7808. return accessor._babylonVertexBuffer;
  7809. };
  7810. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  7811. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7812. throw new Error(context + ": Material type not supported");
  7813. }
  7814. var promises = new Array();
  7815. if (properties) {
  7816. if (properties.baseColorFactor) {
  7817. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  7818. babylonMaterial.alpha = properties.baseColorFactor[3];
  7819. }
  7820. else {
  7821. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  7822. }
  7823. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  7824. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  7825. if (properties.baseColorTexture) {
  7826. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  7827. texture.name = babylonMaterial.name + " (Base Color)";
  7828. babylonMaterial.albedoTexture = texture;
  7829. }));
  7830. }
  7831. if (properties.metallicRoughnessTexture) {
  7832. properties.metallicRoughnessTexture.nonColorData = true;
  7833. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  7834. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  7835. babylonMaterial.metallicTexture = texture;
  7836. }));
  7837. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  7838. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  7839. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  7840. }
  7841. }
  7842. return Promise.all(promises).then(function () { });
  7843. };
  7844. /** @hidden */
  7845. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7846. if (assign === void 0) { assign = function () { }; }
  7847. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  7848. if (extensionPromise) {
  7849. return extensionPromise;
  7850. }
  7851. material._data = material._data || {};
  7852. var babylonData = material._data[babylonDrawMode];
  7853. if (!babylonData) {
  7854. this.logOpen(context + " " + (material.name || ""));
  7855. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  7856. babylonData = {
  7857. babylonMaterial: babylonMaterial,
  7858. babylonMeshes: [],
  7859. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  7860. };
  7861. material._data[babylonDrawMode] = babylonData;
  7862. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  7863. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7864. this.logClose();
  7865. }
  7866. if (babylonMesh) {
  7867. babylonData.babylonMeshes.push(babylonMesh);
  7868. babylonMesh.onDisposeObservable.addOnce(function () {
  7869. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  7870. if (index !== -1) {
  7871. babylonData.babylonMeshes.splice(index, 1);
  7872. }
  7873. });
  7874. }
  7875. assign(babylonData.babylonMaterial);
  7876. return babylonData.promise.then(function () {
  7877. return babylonData.babylonMaterial;
  7878. });
  7879. };
  7880. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  7881. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7882. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  7883. this._babylonScene._blockEntityCollection = false;
  7884. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  7885. babylonMaterial.fillMode = babylonDrawMode;
  7886. babylonMaterial.enableSpecularAntiAliasing = true;
  7887. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  7888. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  7889. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7890. babylonMaterial.metallic = 1;
  7891. babylonMaterial.roughness = 1;
  7892. return babylonMaterial;
  7893. };
  7894. /**
  7895. * Creates a Babylon material from a glTF material.
  7896. * @param context The context when loading the asset
  7897. * @param material The glTF material property
  7898. * @param babylonDrawMode The draw mode for the Babylon material
  7899. * @returns The Babylon material
  7900. */
  7901. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  7902. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  7903. if (extensionPromise) {
  7904. return extensionPromise;
  7905. }
  7906. var name = material.name || "material" + material.index;
  7907. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  7908. return babylonMaterial;
  7909. };
  7910. /**
  7911. * Loads properties from a glTF material into a Babylon material.
  7912. * @param context The context when loading the asset
  7913. * @param material The glTF material property
  7914. * @param babylonMaterial The Babylon material
  7915. * @returns A promise that resolves when the load is complete
  7916. */
  7917. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7918. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  7919. if (extensionPromise) {
  7920. return extensionPromise;
  7921. }
  7922. var promises = new Array();
  7923. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  7924. if (material.pbrMetallicRoughness) {
  7925. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  7926. }
  7927. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  7928. return Promise.all(promises).then(function () { });
  7929. };
  7930. /**
  7931. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  7932. * @param context The context when loading the asset
  7933. * @param material The glTF material property
  7934. * @param babylonMaterial The Babylon material
  7935. * @returns A promise that resolves when the load is complete
  7936. */
  7937. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  7938. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7939. throw new Error(context + ": Material type not supported");
  7940. }
  7941. var promises = new Array();
  7942. 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);
  7943. if (material.doubleSided) {
  7944. babylonMaterial.backFaceCulling = false;
  7945. babylonMaterial.twoSidedLighting = true;
  7946. }
  7947. if (material.normalTexture) {
  7948. material.normalTexture.nonColorData = true;
  7949. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  7950. texture.name = babylonMaterial.name + " (Normal)";
  7951. babylonMaterial.bumpTexture = texture;
  7952. }));
  7953. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  7954. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  7955. if (material.normalTexture.scale != undefined) {
  7956. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  7957. }
  7958. babylonMaterial.forceIrradianceInFragment = true;
  7959. }
  7960. if (material.occlusionTexture) {
  7961. material.occlusionTexture.nonColorData = true;
  7962. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  7963. texture.name = babylonMaterial.name + " (Occlusion)";
  7964. babylonMaterial.ambientTexture = texture;
  7965. }));
  7966. babylonMaterial.useAmbientInGrayScale = true;
  7967. if (material.occlusionTexture.strength != undefined) {
  7968. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  7969. }
  7970. }
  7971. if (material.emissiveTexture) {
  7972. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  7973. texture.name = babylonMaterial.name + " (Emissive)";
  7974. babylonMaterial.emissiveTexture = texture;
  7975. }));
  7976. }
  7977. return Promise.all(promises).then(function () { });
  7978. };
  7979. /**
  7980. * Loads the alpha properties from a glTF material into a Babylon material.
  7981. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  7982. * @param context The context when loading the asset
  7983. * @param material The glTF material property
  7984. * @param babylonMaterial The Babylon material
  7985. */
  7986. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  7987. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7988. throw new Error(context + ": Material type not supported");
  7989. }
  7990. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  7991. switch (alphaMode) {
  7992. case "OPAQUE" /* OPAQUE */: {
  7993. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7994. break;
  7995. }
  7996. case "MASK" /* MASK */: {
  7997. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  7998. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  7999. if (babylonMaterial.albedoTexture) {
  8000. babylonMaterial.albedoTexture.hasAlpha = true;
  8001. }
  8002. break;
  8003. }
  8004. case "BLEND" /* BLEND */: {
  8005. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  8006. if (babylonMaterial.albedoTexture) {
  8007. babylonMaterial.albedoTexture.hasAlpha = true;
  8008. babylonMaterial.useAlphaFromAlbedoTexture = true;
  8009. }
  8010. break;
  8011. }
  8012. default: {
  8013. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  8014. }
  8015. }
  8016. };
  8017. /**
  8018. * Loads a glTF texture info.
  8019. * @param context The context when loading the asset
  8020. * @param textureInfo The glTF texture info property
  8021. * @param assign A function called synchronously after parsing the glTF properties
  8022. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  8023. */
  8024. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  8025. var _this = this;
  8026. if (assign === void 0) { assign = function () { }; }
  8027. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  8028. if (extensionPromise) {
  8029. return extensionPromise;
  8030. }
  8031. this.logOpen("" + context);
  8032. if (textureInfo.texCoord >= 2) {
  8033. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  8034. }
  8035. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  8036. texture._textureInfo = textureInfo;
  8037. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  8038. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  8039. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  8040. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  8041. assign(babylonTexture);
  8042. });
  8043. this.logClose();
  8044. return promise;
  8045. };
  8046. /** @hidden */
  8047. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  8048. if (assign === void 0) { assign = function () { }; }
  8049. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  8050. if (extensionPromise) {
  8051. return extensionPromise;
  8052. }
  8053. this.logOpen(context + " " + (texture.name || ""));
  8054. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  8055. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  8056. var promise = this._createTextureAsync(context, sampler, image, assign);
  8057. this.logClose();
  8058. return promise;
  8059. };
  8060. /** @hidden */
  8061. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign, textureLoaderOptions) {
  8062. var _this = this;
  8063. if (assign === void 0) { assign = function () { }; }
  8064. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  8065. var promises = new Array();
  8066. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  8067. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  8068. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  8069. if (!_this._disposed) {
  8070. deferred.resolve();
  8071. }
  8072. }, function (message, exception) {
  8073. if (!_this._disposed) {
  8074. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  8075. }
  8076. }, undefined, undefined, undefined, image.mimeType, textureLoaderOptions);
  8077. this._babylonScene._blockEntityCollection = false;
  8078. promises.push(deferred.promise);
  8079. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  8080. var name = image.uri || _this._fileName + "#image" + image.index;
  8081. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  8082. babylonTexture.updateURL(dataUrl, data);
  8083. }));
  8084. babylonTexture.wrapU = samplerData.wrapU;
  8085. babylonTexture.wrapV = samplerData.wrapV;
  8086. assign(babylonTexture);
  8087. return Promise.all(promises).then(function () {
  8088. return babylonTexture;
  8089. });
  8090. };
  8091. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  8092. if (!sampler._data) {
  8093. sampler._data = {
  8094. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  8095. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  8096. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  8097. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  8098. };
  8099. }
  8100. return sampler._data;
  8101. };
  8102. /**
  8103. * Loads a glTF image.
  8104. * @param context The context when loading the asset
  8105. * @param image The glTF image property
  8106. * @returns A promise that resolves with the loaded data when the load is complete
  8107. */
  8108. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  8109. if (!image._data) {
  8110. this.logOpen(context + " " + (image.name || ""));
  8111. if (image.uri) {
  8112. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  8113. }
  8114. else {
  8115. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  8116. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  8117. }
  8118. this.logClose();
  8119. }
  8120. return image._data;
  8121. };
  8122. /**
  8123. * Loads a glTF uri.
  8124. * @param context The context when loading the asset
  8125. * @param property The glTF property associated with the uri
  8126. * @param uri The base64 or relative uri
  8127. * @returns A promise that resolves with the loaded data when the load is complete
  8128. */
  8129. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  8130. var _this = this;
  8131. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  8132. if (extensionPromise) {
  8133. return extensionPromise;
  8134. }
  8135. if (!GLTFLoader._ValidateUri(uri)) {
  8136. throw new Error(context + ": '" + uri + "' is invalid");
  8137. }
  8138. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  8139. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  8140. this.log(context + ": Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  8141. return Promise.resolve(data);
  8142. }
  8143. this.log(context + ": Loading " + uri);
  8144. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  8145. return new Promise(function (resolve, reject) {
  8146. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  8147. if (!_this._disposed) {
  8148. _this.log(context + ": Loaded " + uri + " (" + data.byteLength + " bytes)");
  8149. resolve(new Uint8Array(data));
  8150. }
  8151. }, true, function (request) {
  8152. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  8153. });
  8154. });
  8155. });
  8156. };
  8157. /**
  8158. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  8159. * @param babylonObject the Babylon object with metadata
  8160. * @param pointer the JSON pointer
  8161. */
  8162. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  8163. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  8164. var gltf = (metadata.gltf = metadata.gltf || {});
  8165. var pointers = (gltf.pointers = gltf.pointers || []);
  8166. pointers.push(pointer);
  8167. };
  8168. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  8169. // Set defaults if undefined
  8170. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  8171. switch (mode) {
  8172. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  8173. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  8174. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  8175. default:
  8176. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  8177. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  8178. }
  8179. };
  8180. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  8181. // Set defaults if undefined
  8182. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  8183. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  8184. if (magFilter === 9729 /* LINEAR */) {
  8185. switch (minFilter) {
  8186. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  8187. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  8188. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  8189. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  8190. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  8191. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  8192. default:
  8193. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  8194. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  8195. }
  8196. }
  8197. else {
  8198. if (magFilter !== 9728 /* NEAREST */) {
  8199. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  8200. }
  8201. switch (minFilter) {
  8202. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  8203. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  8204. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  8205. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  8206. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  8207. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  8208. default:
  8209. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  8210. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  8211. }
  8212. }
  8213. };
  8214. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  8215. switch (componentType) {
  8216. case 5120 /* BYTE */: return Int8Array;
  8217. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  8218. case 5122 /* SHORT */: return Int16Array;
  8219. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  8220. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  8221. case 5126 /* FLOAT */: return Float32Array;
  8222. default: throw new Error(context + ": Invalid component type " + componentType);
  8223. }
  8224. };
  8225. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  8226. var buffer = bufferView.buffer;
  8227. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  8228. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  8229. try {
  8230. return new constructor(buffer, byteOffset, length);
  8231. }
  8232. catch (e) {
  8233. throw new Error(context + ": " + e);
  8234. }
  8235. };
  8236. GLTFLoader._GetNumComponents = function (context, type) {
  8237. switch (type) {
  8238. case "SCALAR": return 1;
  8239. case "VEC2": return 2;
  8240. case "VEC3": return 3;
  8241. case "VEC4": return 4;
  8242. case "MAT2": return 4;
  8243. case "MAT3": return 9;
  8244. case "MAT4": return 16;
  8245. }
  8246. throw new Error(context + ": Invalid type (" + type + ")");
  8247. };
  8248. GLTFLoader._ValidateUri = function (uri) {
  8249. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  8250. };
  8251. /** @hidden */
  8252. GLTFLoader._GetDrawMode = function (context, mode) {
  8253. if (mode == undefined) {
  8254. mode = 4 /* TRIANGLES */;
  8255. }
  8256. switch (mode) {
  8257. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  8258. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  8259. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  8260. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  8261. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  8262. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  8263. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  8264. }
  8265. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  8266. };
  8267. GLTFLoader.prototype._compileMaterialsAsync = function () {
  8268. var _this = this;
  8269. this._parent._startPerformanceCounter("Compile materials");
  8270. var promises = new Array();
  8271. if (this._gltf.materials) {
  8272. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  8273. var material = _a[_i];
  8274. if (material._data) {
  8275. for (var babylonDrawMode in material._data) {
  8276. var babylonData = material._data[babylonDrawMode];
  8277. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  8278. var babylonMesh = _c[_b];
  8279. // Ensure nonUniformScaling is set if necessary.
  8280. babylonMesh.computeWorldMatrix(true);
  8281. var babylonMaterial = babylonData.babylonMaterial;
  8282. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  8283. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  8284. if (this._parent.useClipPlane) {
  8285. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  8286. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  8287. }
  8288. }
  8289. }
  8290. }
  8291. }
  8292. }
  8293. return Promise.all(promises).then(function () {
  8294. _this._parent._endPerformanceCounter("Compile materials");
  8295. });
  8296. };
  8297. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  8298. var _this = this;
  8299. this._parent._startPerformanceCounter("Compile shadow generators");
  8300. var promises = new Array();
  8301. var lights = this._babylonScene.lights;
  8302. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  8303. var light = lights_1[_i];
  8304. var generator = light.getShadowGenerator();
  8305. if (generator) {
  8306. promises.push(generator.forceCompilationAsync());
  8307. }
  8308. }
  8309. return Promise.all(promises).then(function () {
  8310. _this._parent._endPerformanceCounter("Compile shadow generators");
  8311. });
  8312. };
  8313. GLTFLoader.prototype._forEachExtensions = function (action) {
  8314. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  8315. var extension = _a[_i];
  8316. if (extension.enabled) {
  8317. action(extension);
  8318. }
  8319. }
  8320. };
  8321. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  8322. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  8323. var extension = _a[_i];
  8324. if (extension.enabled) {
  8325. var id = extension.name + "." + functionName;
  8326. var loaderProperty = property;
  8327. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  8328. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  8329. if (!activeLoaderExtensionFunctions[id]) {
  8330. activeLoaderExtensionFunctions[id] = true;
  8331. try {
  8332. var result = actionAsync(extension);
  8333. if (result) {
  8334. return result;
  8335. }
  8336. }
  8337. finally {
  8338. delete activeLoaderExtensionFunctions[id];
  8339. }
  8340. }
  8341. }
  8342. }
  8343. return null;
  8344. };
  8345. GLTFLoader.prototype._extensionsOnLoading = function () {
  8346. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  8347. };
  8348. GLTFLoader.prototype._extensionsOnReady = function () {
  8349. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  8350. };
  8351. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  8352. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  8353. };
  8354. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  8355. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  8356. };
  8357. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  8358. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  8359. };
  8360. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  8361. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  8362. };
  8363. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  8364. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  8365. };
  8366. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  8367. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  8368. };
  8369. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  8370. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  8371. };
  8372. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  8373. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  8374. };
  8375. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  8376. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  8377. };
  8378. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  8379. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  8380. };
  8381. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  8382. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  8383. };
  8384. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  8385. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  8386. };
  8387. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  8388. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  8389. };
  8390. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  8391. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  8392. };
  8393. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  8394. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  8395. };
  8396. /**
  8397. * Helper method called by a loader extension to load an glTF extension.
  8398. * @param context The context when loading the asset
  8399. * @param property The glTF property to load the extension from
  8400. * @param extensionName The name of the extension to load
  8401. * @param actionAsync The action to run
  8402. * @returns The promise returned by actionAsync or null if the extension does not exist
  8403. */
  8404. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  8405. if (!property.extensions) {
  8406. return null;
  8407. }
  8408. var extensions = property.extensions;
  8409. var extension = extensions[extensionName];
  8410. if (!extension) {
  8411. return null;
  8412. }
  8413. return actionAsync(context + "/extensions/" + extensionName, extension);
  8414. };
  8415. /**
  8416. * Helper method called by a loader extension to load a glTF extra.
  8417. * @param context The context when loading the asset
  8418. * @param property The glTF property to load the extra from
  8419. * @param extensionName The name of the extension to load
  8420. * @param actionAsync The action to run
  8421. * @returns The promise returned by actionAsync or null if the extra does not exist
  8422. */
  8423. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  8424. if (!property.extras) {
  8425. return null;
  8426. }
  8427. var extras = property.extras;
  8428. var extra = extras[extensionName];
  8429. if (!extra) {
  8430. return null;
  8431. }
  8432. return actionAsync(context + "/extras/" + extensionName, extra);
  8433. };
  8434. /**
  8435. * Checks for presence of an extension.
  8436. * @param name The name of the extension to check
  8437. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  8438. */
  8439. GLTFLoader.prototype.isExtensionUsed = function (name) {
  8440. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  8441. };
  8442. /**
  8443. * Increments the indentation level and logs a message.
  8444. * @param message The message to log
  8445. */
  8446. GLTFLoader.prototype.logOpen = function (message) {
  8447. this._parent._logOpen(message);
  8448. };
  8449. /**
  8450. * Decrements the indentation level.
  8451. */
  8452. GLTFLoader.prototype.logClose = function () {
  8453. this._parent._logClose();
  8454. };
  8455. /**
  8456. * Logs a message
  8457. * @param message The message to log
  8458. */
  8459. GLTFLoader.prototype.log = function (message) {
  8460. this._parent._log(message);
  8461. };
  8462. /**
  8463. * Starts a performance counter.
  8464. * @param counterName The name of the performance counter
  8465. */
  8466. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  8467. this._parent._startPerformanceCounter(counterName);
  8468. };
  8469. /**
  8470. * Ends a performance counter.
  8471. * @param counterName The name of the performance counter
  8472. */
  8473. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  8474. this._parent._endPerformanceCounter(counterName);
  8475. };
  8476. GLTFLoader._RegisteredExtensions = {};
  8477. /**
  8478. * The default glTF sampler.
  8479. */
  8480. GLTFLoader.DefaultSampler = { index: -1 };
  8481. return GLTFLoader;
  8482. }());
  8483. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  8484. /***/ }),
  8485. /***/ "./glTF/2.0/glTFLoaderExtension.ts":
  8486. /*!*****************************************!*\
  8487. !*** ./glTF/2.0/glTFLoaderExtension.ts ***!
  8488. \*****************************************/
  8489. /*! no exports provided */
  8490. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8491. "use strict";
  8492. __webpack_require__.r(__webpack_exports__);
  8493. /***/ }),
  8494. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  8495. /*!******************************************!*\
  8496. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  8497. \******************************************/
  8498. /*! no exports provided */
  8499. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8500. "use strict";
  8501. __webpack_require__.r(__webpack_exports__);
  8502. /***/ }),
  8503. /***/ "./glTF/2.0/index.ts":
  8504. /*!***************************!*\
  8505. !*** ./glTF/2.0/index.ts ***!
  8506. \***************************/
  8507. /*! 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, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  8508. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8509. "use strict";
  8510. __webpack_require__.r(__webpack_exports__);
  8511. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  8512. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  8513. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  8514. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoaderExtension */ "./glTF/2.0/glTFLoaderExtension.ts");
  8515. /* empty/unused harmony star reexport *//* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8516. /* empty/unused harmony star reexport *//* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  8517. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_lights_image_based"]; });
  8518. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_mesh_gpu_instancing"]; });
  8519. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_meshopt_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_meshopt_compression"]; });
  8520. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_texture_webp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_texture_webp"]; });
  8521. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_draco_mesh_compression"]; });
  8522. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  8523. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  8524. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_unlit"]; });
  8525. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_clearcoat"]; });
  8526. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_sheen"]; });
  8527. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_specular"]; });
  8528. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_ior"]; });
  8529. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_variants"]; });
  8530. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_transmission"]; });
  8531. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_translucency", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_translucency"]; });
  8532. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_mesh_quantization"]; });
  8533. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_basisu"]; });
  8534. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_transform"]; });
  8535. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_audio_emitter"]; });
  8536. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_lod"]; });
  8537. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_minecraftMesh"]; });
  8538. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_sRGBFactors"]; });
  8539. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["ExtrasAsMetadata"]; });
  8540. /***/ }),
  8541. /***/ "./glTF/glTFFileLoader.ts":
  8542. /*!********************************!*\
  8543. !*** ./glTF/glTFFileLoader.ts ***!
  8544. \********************************/
  8545. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  8546. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8547. "use strict";
  8548. __webpack_require__.r(__webpack_exports__);
  8549. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  8550. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  8551. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  8552. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  8553. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  8554. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  8555. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8556. /**
  8557. * Mode that determines the coordinate system to use.
  8558. */
  8559. var GLTFLoaderCoordinateSystemMode;
  8560. (function (GLTFLoaderCoordinateSystemMode) {
  8561. /**
  8562. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  8563. */
  8564. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  8565. /**
  8566. * Sets the useRightHandedSystem flag on the scene.
  8567. */
  8568. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  8569. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  8570. /**
  8571. * Mode that determines what animations will start.
  8572. */
  8573. var GLTFLoaderAnimationStartMode;
  8574. (function (GLTFLoaderAnimationStartMode) {
  8575. /**
  8576. * No animation will start.
  8577. */
  8578. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  8579. /**
  8580. * The first animation will start.
  8581. */
  8582. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  8583. /**
  8584. * All animations will start.
  8585. */
  8586. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  8587. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  8588. /**
  8589. * Loader state.
  8590. */
  8591. var GLTFLoaderState;
  8592. (function (GLTFLoaderState) {
  8593. /**
  8594. * The asset is loading.
  8595. */
  8596. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  8597. /**
  8598. * The asset is ready for rendering.
  8599. */
  8600. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  8601. /**
  8602. * The asset is completely loaded.
  8603. */
  8604. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  8605. })(GLTFLoaderState || (GLTFLoaderState = {}));
  8606. /**
  8607. * File loader for loading glTF files into a scene.
  8608. */
  8609. var GLTFFileLoader = /** @class */ (function () {
  8610. function GLTFFileLoader() {
  8611. // --------------
  8612. // Common options
  8613. // --------------
  8614. /**
  8615. * Raised when the asset has been parsed
  8616. */
  8617. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8618. // ----------
  8619. // V2 options
  8620. // ----------
  8621. /**
  8622. * The coordinate system mode. Defaults to AUTO.
  8623. */
  8624. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  8625. /**
  8626. * The animation start mode. Defaults to FIRST.
  8627. */
  8628. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  8629. /**
  8630. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  8631. */
  8632. this.compileMaterials = false;
  8633. /**
  8634. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  8635. */
  8636. this.useClipPlane = false;
  8637. /**
  8638. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  8639. */
  8640. this.compileShadowGenerators = false;
  8641. /**
  8642. * Defines if the Alpha blended materials are only applied as coverage.
  8643. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  8644. * If true, no extra effects are applied to transparent pixels.
  8645. */
  8646. this.transparencyAsCoverage = false;
  8647. /**
  8648. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  8649. * Enabling will disable offline support and glTF validator.
  8650. * Defaults to false.
  8651. */
  8652. this.useRangeRequests = false;
  8653. /**
  8654. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  8655. */
  8656. this.createInstances = true;
  8657. /**
  8658. * 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.
  8659. */
  8660. this.alwaysComputeBoundingBox = false;
  8661. /**
  8662. * If true, load all materials defined in the file, even if not used by any mesh. Defaults to false.
  8663. */
  8664. this.loadAllMaterials = false;
  8665. /**
  8666. * Function called before loading a url referenced by the asset.
  8667. */
  8668. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8669. /**
  8670. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8671. * 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, ...)
  8672. */
  8673. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8674. /**
  8675. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  8676. */
  8677. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8678. /**
  8679. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  8680. */
  8681. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8682. /**
  8683. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  8684. */
  8685. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8686. /**
  8687. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  8688. * For assets with LODs, raised when all of the LODs are complete.
  8689. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8690. */
  8691. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8692. /**
  8693. * Observable raised when an error occurs.
  8694. */
  8695. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8696. /**
  8697. * Observable raised after the loader is disposed.
  8698. */
  8699. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8700. /**
  8701. * Observable raised after a loader extension is created.
  8702. * Set additional options for a loader extension in this event.
  8703. */
  8704. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8705. /**
  8706. * Defines if the loader should validate the asset.
  8707. */
  8708. this.validate = false;
  8709. /**
  8710. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  8711. */
  8712. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  8713. this._loader = null;
  8714. this._requests = new Array();
  8715. /**
  8716. * Name of the loader ("gltf")
  8717. */
  8718. this.name = "gltf";
  8719. /** @hidden */
  8720. this.extensions = {
  8721. ".gltf": { isBinary: false },
  8722. ".glb": { isBinary: true }
  8723. };
  8724. this._logIndentLevel = 0;
  8725. this._loggingEnabled = false;
  8726. /** @hidden */
  8727. this._log = this._logDisabled;
  8728. this._capturePerformanceCounters = false;
  8729. /** @hidden */
  8730. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8731. /** @hidden */
  8732. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8733. }
  8734. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  8735. /**
  8736. * Raised when the asset has been parsed
  8737. */
  8738. set: function (callback) {
  8739. if (this._onParsedObserver) {
  8740. this.onParsedObservable.remove(this._onParsedObserver);
  8741. }
  8742. this._onParsedObserver = this.onParsedObservable.add(callback);
  8743. },
  8744. enumerable: false,
  8745. configurable: true
  8746. });
  8747. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  8748. /**
  8749. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  8750. * 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, ...)
  8751. */
  8752. set: function (callback) {
  8753. if (this._onMeshLoadedObserver) {
  8754. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  8755. }
  8756. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  8757. },
  8758. enumerable: false,
  8759. configurable: true
  8760. });
  8761. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  8762. /**
  8763. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  8764. */
  8765. set: function (callback) {
  8766. if (this._onTextureLoadedObserver) {
  8767. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  8768. }
  8769. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  8770. },
  8771. enumerable: false,
  8772. configurable: true
  8773. });
  8774. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  8775. /**
  8776. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  8777. */
  8778. set: function (callback) {
  8779. if (this._onMaterialLoadedObserver) {
  8780. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  8781. }
  8782. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  8783. },
  8784. enumerable: false,
  8785. configurable: true
  8786. });
  8787. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  8788. /**
  8789. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  8790. */
  8791. set: function (callback) {
  8792. if (this._onCameraLoadedObserver) {
  8793. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  8794. }
  8795. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  8796. },
  8797. enumerable: false,
  8798. configurable: true
  8799. });
  8800. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  8801. /**
  8802. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  8803. * For assets with LODs, raised when all of the LODs are complete.
  8804. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  8805. */
  8806. set: function (callback) {
  8807. if (this._onCompleteObserver) {
  8808. this.onCompleteObservable.remove(this._onCompleteObserver);
  8809. }
  8810. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  8811. },
  8812. enumerable: false,
  8813. configurable: true
  8814. });
  8815. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  8816. /**
  8817. * Callback raised when an error occurs.
  8818. */
  8819. set: function (callback) {
  8820. if (this._onErrorObserver) {
  8821. this.onErrorObservable.remove(this._onErrorObserver);
  8822. }
  8823. this._onErrorObserver = this.onErrorObservable.add(callback);
  8824. },
  8825. enumerable: false,
  8826. configurable: true
  8827. });
  8828. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  8829. /**
  8830. * Callback raised after the loader is disposed.
  8831. */
  8832. set: function (callback) {
  8833. if (this._onDisposeObserver) {
  8834. this.onDisposeObservable.remove(this._onDisposeObserver);
  8835. }
  8836. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  8837. },
  8838. enumerable: false,
  8839. configurable: true
  8840. });
  8841. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  8842. /**
  8843. * Callback raised after a loader extension is created.
  8844. */
  8845. set: function (callback) {
  8846. if (this._onExtensionLoadedObserver) {
  8847. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  8848. }
  8849. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  8850. },
  8851. enumerable: false,
  8852. configurable: true
  8853. });
  8854. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  8855. /**
  8856. * Defines if the loader logging is enabled.
  8857. */
  8858. get: function () {
  8859. return this._loggingEnabled;
  8860. },
  8861. set: function (value) {
  8862. if (this._loggingEnabled === value) {
  8863. return;
  8864. }
  8865. this._loggingEnabled = value;
  8866. if (this._loggingEnabled) {
  8867. this._log = this._logEnabled;
  8868. }
  8869. else {
  8870. this._log = this._logDisabled;
  8871. }
  8872. },
  8873. enumerable: false,
  8874. configurable: true
  8875. });
  8876. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  8877. /**
  8878. * Defines if the loader should capture performance counters.
  8879. */
  8880. get: function () {
  8881. return this._capturePerformanceCounters;
  8882. },
  8883. set: function (value) {
  8884. if (this._capturePerformanceCounters === value) {
  8885. return;
  8886. }
  8887. this._capturePerformanceCounters = value;
  8888. if (this._capturePerformanceCounters) {
  8889. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  8890. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  8891. }
  8892. else {
  8893. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8894. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8895. }
  8896. },
  8897. enumerable: false,
  8898. configurable: true
  8899. });
  8900. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  8901. /**
  8902. * Callback raised after a loader extension is created.
  8903. */
  8904. set: function (callback) {
  8905. if (this._onValidatedObserver) {
  8906. this.onValidatedObservable.remove(this._onValidatedObserver);
  8907. }
  8908. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  8909. },
  8910. enumerable: false,
  8911. configurable: true
  8912. });
  8913. /**
  8914. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  8915. */
  8916. GLTFFileLoader.prototype.dispose = function () {
  8917. if (this._loader) {
  8918. this._loader.dispose();
  8919. this._loader = null;
  8920. }
  8921. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  8922. var request = _a[_i];
  8923. request.abort();
  8924. }
  8925. this._requests.length = 0;
  8926. delete this._progressCallback;
  8927. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8928. this.onMeshLoadedObservable.clear();
  8929. this.onTextureLoadedObservable.clear();
  8930. this.onMaterialLoadedObservable.clear();
  8931. this.onCameraLoadedObservable.clear();
  8932. this.onCompleteObservable.clear();
  8933. this.onExtensionLoadedObservable.clear();
  8934. this.onDisposeObservable.notifyObservers(undefined);
  8935. this.onDisposeObservable.clear();
  8936. };
  8937. /** @hidden */
  8938. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  8939. var _this = this;
  8940. this._progressCallback = onProgress;
  8941. if (useArrayBuffer) {
  8942. if (this.useRangeRequests) {
  8943. if (this.validate) {
  8944. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  8945. }
  8946. var fileRequest_1 = {
  8947. abort: function () { },
  8948. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  8949. };
  8950. var dataBuffer = {
  8951. readAsync: function (byteOffset, byteLength) {
  8952. return new Promise(function (resolve, reject) {
  8953. _this._requestFile(url, scene, function (data) {
  8954. resolve(new Uint8Array(data));
  8955. }, true, function (error) {
  8956. reject(error);
  8957. }, function (webRequest) {
  8958. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  8959. });
  8960. });
  8961. },
  8962. byteLength: 0
  8963. };
  8964. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  8965. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  8966. onSuccess(loaderData);
  8967. }, onError);
  8968. return fileRequest_1;
  8969. }
  8970. return this._requestFile(url, scene, function (data, request) {
  8971. var arrayBuffer = data;
  8972. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8973. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  8974. byteLength: arrayBuffer.byteLength
  8975. })).then(function (loaderData) {
  8976. onSuccess(loaderData, request);
  8977. }, onError);
  8978. }, true, onError);
  8979. }
  8980. return this._requestFile(url, scene, function (data, request) {
  8981. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  8982. onSuccess({ json: _this._parseJson(data) }, request);
  8983. }, useArrayBuffer, onError);
  8984. };
  8985. /** @hidden */
  8986. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  8987. var _this = this;
  8988. return scene._readFile(file, function (data) {
  8989. _this._validate(scene, data, "file:", file.name);
  8990. if (useArrayBuffer) {
  8991. var arrayBuffer_1 = data;
  8992. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8993. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  8994. byteLength: arrayBuffer_1.byteLength
  8995. })).then(onSuccess, onError);
  8996. }
  8997. else {
  8998. onSuccess({ json: _this._parseJson(data) });
  8999. }
  9000. }, onProgress, useArrayBuffer, onError);
  9001. };
  9002. /** @hidden */
  9003. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  9004. var _this = this;
  9005. return Promise.resolve().then(function () {
  9006. _this.onParsedObservable.notifyObservers(data);
  9007. _this.onParsedObservable.clear();
  9008. _this._log("Loading " + (fileName || ""));
  9009. _this._loader = _this._getLoader(data);
  9010. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  9011. });
  9012. };
  9013. /** @hidden */
  9014. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  9015. var _this = this;
  9016. return Promise.resolve().then(function () {
  9017. _this.onParsedObservable.notifyObservers(data);
  9018. _this.onParsedObservable.clear();
  9019. _this._log("Loading " + (fileName || ""));
  9020. _this._loader = _this._getLoader(data);
  9021. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  9022. });
  9023. };
  9024. /** @hidden */
  9025. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  9026. var _this = this;
  9027. return Promise.resolve().then(function () {
  9028. _this.onParsedObservable.notifyObservers(data);
  9029. _this.onParsedObservable.clear();
  9030. _this._log("Loading " + (fileName || ""));
  9031. _this._loader = _this._getLoader(data);
  9032. // Prepare the asset container.
  9033. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  9034. // Get materials/textures when loading to add to container
  9035. var materials = [];
  9036. _this.onMaterialLoadedObservable.add(function (material) {
  9037. materials.push(material);
  9038. material.onDisposeObservable.addOnce(function () {
  9039. var index = container.materials.indexOf(material);
  9040. if (index > -1) {
  9041. container.materials.splice(index, 1);
  9042. }
  9043. index = materials.indexOf(material);
  9044. if (index > -1) {
  9045. materials.splice(index, 1);
  9046. }
  9047. });
  9048. });
  9049. var textures = [];
  9050. _this.onTextureLoadedObservable.add(function (texture) {
  9051. textures.push(texture);
  9052. texture.onDisposeObservable.addOnce(function () {
  9053. var index = container.textures.indexOf(texture);
  9054. if (index > -1) {
  9055. container.textures.splice(index, 1);
  9056. }
  9057. index = textures.indexOf(texture);
  9058. if (index > -1) {
  9059. textures.splice(index, 1);
  9060. }
  9061. });
  9062. });
  9063. var cameras = [];
  9064. _this.onCameraLoadedObservable.add(function (camera) {
  9065. cameras.push(camera);
  9066. });
  9067. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  9068. Array.prototype.push.apply(container.geometries, result.geometries);
  9069. Array.prototype.push.apply(container.meshes, result.meshes);
  9070. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  9071. Array.prototype.push.apply(container.skeletons, result.skeletons);
  9072. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  9073. Array.prototype.push.apply(container.materials, materials);
  9074. Array.prototype.push.apply(container.textures, textures);
  9075. Array.prototype.push.apply(container.lights, result.lights);
  9076. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  9077. Array.prototype.push.apply(container.cameras, cameras);
  9078. return container;
  9079. });
  9080. });
  9081. };
  9082. /** @hidden */
  9083. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  9084. return (data.indexOf("asset") !== -1 && data.indexOf("version") !== -1)
  9085. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:base64," + GLTFFileLoader.magicBase64Encoded)
  9086. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded)
  9087. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded);
  9088. };
  9089. /** @hidden */
  9090. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  9091. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "base64," + GLTFFileLoader.magicBase64Encoded) ||
  9092. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded) ||
  9093. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded)) {
  9094. var arrayBuffer_2 = babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(data);
  9095. this._validate(scene, arrayBuffer_2);
  9096. return this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  9097. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_2, byteOffset, byteLength)); },
  9098. byteLength: arrayBuffer_2.byteLength
  9099. }));
  9100. }
  9101. this._validate(scene, data);
  9102. return Promise.resolve({ json: this._parseJson(data) });
  9103. };
  9104. /** @hidden */
  9105. GLTFFileLoader.prototype.createPlugin = function () {
  9106. return new GLTFFileLoader();
  9107. };
  9108. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  9109. /**
  9110. * The loader state or null if the loader is not active.
  9111. */
  9112. get: function () {
  9113. return this._loader ? this._loader.state : null;
  9114. },
  9115. enumerable: false,
  9116. configurable: true
  9117. });
  9118. /**
  9119. * Returns a promise that resolves when the asset is completely loaded.
  9120. * @returns a promise that resolves when the asset is completely loaded.
  9121. */
  9122. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  9123. var _this = this;
  9124. return new Promise(function (resolve, reject) {
  9125. _this.onCompleteObservable.addOnce(function () {
  9126. resolve();
  9127. });
  9128. _this.onErrorObservable.addOnce(function (reason) {
  9129. reject(reason);
  9130. });
  9131. });
  9132. };
  9133. /** @hidden */
  9134. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  9135. var _this = this;
  9136. var request = scene._loadFile(url, onSuccess, function (event) {
  9137. _this._onProgress(event, request);
  9138. }, undefined, useArrayBuffer, onError);
  9139. request.onCompleteObservable.add(function (request) {
  9140. _this._requests.splice(_this._requests.indexOf(request), 1);
  9141. });
  9142. this._requests.push(request);
  9143. return request;
  9144. };
  9145. /** @hidden */
  9146. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  9147. var _this = this;
  9148. var request = scene._requestFile(url, onSuccess, function (event) {
  9149. _this._onProgress(event, request);
  9150. }, undefined, useArrayBuffer, onError, onOpened);
  9151. request.onCompleteObservable.add(function (request) {
  9152. _this._requests.splice(_this._requests.indexOf(request), 1);
  9153. });
  9154. this._requests.push(request);
  9155. return request;
  9156. };
  9157. GLTFFileLoader.prototype._onProgress = function (event, request) {
  9158. if (!this._progressCallback) {
  9159. return;
  9160. }
  9161. request._lengthComputable = event.lengthComputable;
  9162. request._loaded = event.loaded;
  9163. request._total = event.total;
  9164. var lengthComputable = true;
  9165. var loaded = 0;
  9166. var total = 0;
  9167. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  9168. var request_1 = _a[_i];
  9169. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  9170. return;
  9171. }
  9172. lengthComputable = lengthComputable && request_1._lengthComputable;
  9173. loaded += request_1._loaded;
  9174. total += request_1._total;
  9175. }
  9176. this._progressCallback({
  9177. lengthComputable: lengthComputable,
  9178. loaded: loaded,
  9179. total: lengthComputable ? total : 0
  9180. });
  9181. };
  9182. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  9183. var _this = this;
  9184. if (rootUrl === void 0) { rootUrl = ""; }
  9185. if (fileName === void 0) { fileName = ""; }
  9186. if (!this.validate) {
  9187. return;
  9188. }
  9189. this._startPerformanceCounter("Validate JSON");
  9190. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  9191. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  9192. }).then(function (result) {
  9193. _this._endPerformanceCounter("Validate JSON");
  9194. _this.onValidatedObservable.notifyObservers(result);
  9195. _this.onValidatedObservable.clear();
  9196. }, function (reason) {
  9197. _this._endPerformanceCounter("Validate JSON");
  9198. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  9199. _this.onValidatedObservable.clear();
  9200. });
  9201. };
  9202. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  9203. var asset = loaderData.json.asset || {};
  9204. this._log("Asset version: " + asset.version);
  9205. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  9206. asset.generator && this._log("Asset generator: " + asset.generator);
  9207. var version = GLTFFileLoader._parseVersion(asset.version);
  9208. if (!version) {
  9209. throw new Error("Invalid version: " + asset.version);
  9210. }
  9211. if (asset.minVersion !== undefined) {
  9212. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  9213. if (!minVersion) {
  9214. throw new Error("Invalid minimum version: " + asset.minVersion);
  9215. }
  9216. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  9217. throw new Error("Incompatible minimum version: " + asset.minVersion);
  9218. }
  9219. }
  9220. var createLoaders = {
  9221. 1: GLTFFileLoader._CreateGLTF1Loader,
  9222. 2: GLTFFileLoader._CreateGLTF2Loader
  9223. };
  9224. var createLoader = createLoaders[version.major];
  9225. if (!createLoader) {
  9226. throw new Error("Unsupported version: " + asset.version);
  9227. }
  9228. return createLoader(this);
  9229. };
  9230. GLTFFileLoader.prototype._parseJson = function (json) {
  9231. this._startPerformanceCounter("Parse JSON");
  9232. this._log("JSON length: " + json.length);
  9233. var parsed = JSON.parse(json);
  9234. this._endPerformanceCounter("Parse JSON");
  9235. return parsed;
  9236. };
  9237. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  9238. var _this = this;
  9239. this._startPerformanceCounter("Unpack Binary");
  9240. // Read magic + version + length + json length + json format
  9241. return dataReader.loadAsync(20).then(function () {
  9242. var Binary = {
  9243. Magic: 0x46546C67
  9244. };
  9245. var magic = dataReader.readUint32();
  9246. if (magic !== Binary.Magic) {
  9247. throw new Error("Unexpected magic: " + magic);
  9248. }
  9249. var version = dataReader.readUint32();
  9250. if (_this.loggingEnabled) {
  9251. _this._log("Binary version: " + version);
  9252. }
  9253. var length = dataReader.readUint32();
  9254. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  9255. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  9256. }
  9257. var unpacked;
  9258. switch (version) {
  9259. case 1: {
  9260. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  9261. break;
  9262. }
  9263. case 2: {
  9264. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  9265. break;
  9266. }
  9267. default: {
  9268. throw new Error("Unsupported version: " + version);
  9269. }
  9270. }
  9271. _this._endPerformanceCounter("Unpack Binary");
  9272. return unpacked;
  9273. });
  9274. };
  9275. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  9276. var ContentFormat = {
  9277. JSON: 0
  9278. };
  9279. var contentLength = dataReader.readUint32();
  9280. var contentFormat = dataReader.readUint32();
  9281. if (contentFormat !== ContentFormat.JSON) {
  9282. throw new Error("Unexpected content format: " + contentFormat);
  9283. }
  9284. var bodyLength = length - dataReader.byteOffset;
  9285. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  9286. if (bodyLength !== 0) {
  9287. var startByteOffset_1 = dataReader.byteOffset;
  9288. data.bin = {
  9289. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  9290. byteLength: bodyLength
  9291. };
  9292. }
  9293. return Promise.resolve(data);
  9294. };
  9295. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  9296. var _this = this;
  9297. var ChunkFormat = {
  9298. JSON: 0x4E4F534A,
  9299. BIN: 0x004E4942
  9300. };
  9301. // Read the JSON chunk header.
  9302. var chunkLength = dataReader.readUint32();
  9303. var chunkFormat = dataReader.readUint32();
  9304. if (chunkFormat !== ChunkFormat.JSON) {
  9305. throw new Error("First chunk format is not JSON");
  9306. }
  9307. // Bail if there are no other chunks.
  9308. if (dataReader.byteOffset + chunkLength === length) {
  9309. return dataReader.loadAsync(chunkLength).then(function () {
  9310. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  9311. });
  9312. }
  9313. // Read the JSON chunk and the length and type of the next chunk.
  9314. return dataReader.loadAsync(chunkLength + 8).then(function () {
  9315. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  9316. var readAsync = function () {
  9317. var chunkLength = dataReader.readUint32();
  9318. var chunkFormat = dataReader.readUint32();
  9319. switch (chunkFormat) {
  9320. case ChunkFormat.JSON: {
  9321. throw new Error("Unexpected JSON chunk");
  9322. }
  9323. case ChunkFormat.BIN: {
  9324. var startByteOffset_2 = dataReader.byteOffset;
  9325. data.bin = {
  9326. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  9327. byteLength: chunkLength
  9328. };
  9329. dataReader.skipBytes(chunkLength);
  9330. break;
  9331. }
  9332. default: {
  9333. // ignore unrecognized chunkFormat
  9334. dataReader.skipBytes(chunkLength);
  9335. break;
  9336. }
  9337. }
  9338. if (dataReader.byteOffset !== length) {
  9339. return dataReader.loadAsync(8).then(readAsync);
  9340. }
  9341. return Promise.resolve(data);
  9342. };
  9343. return readAsync();
  9344. });
  9345. };
  9346. GLTFFileLoader._parseVersion = function (version) {
  9347. if (version === "1.0" || version === "1.0.1") {
  9348. return {
  9349. major: 1,
  9350. minor: 0
  9351. };
  9352. }
  9353. var match = (version + "").match(/^(\d+)\.(\d+)/);
  9354. if (!match) {
  9355. return null;
  9356. }
  9357. return {
  9358. major: parseInt(match[1]),
  9359. minor: parseInt(match[2])
  9360. };
  9361. };
  9362. GLTFFileLoader._compareVersion = function (a, b) {
  9363. if (a.major > b.major) {
  9364. return 1;
  9365. }
  9366. if (a.major < b.major) {
  9367. return -1;
  9368. }
  9369. if (a.minor > b.minor) {
  9370. return 1;
  9371. }
  9372. if (a.minor < b.minor) {
  9373. return -1;
  9374. }
  9375. return 0;
  9376. };
  9377. /** @hidden */
  9378. GLTFFileLoader.prototype._logOpen = function (message) {
  9379. this._log(message);
  9380. this._logIndentLevel++;
  9381. };
  9382. /** @hidden */
  9383. GLTFFileLoader.prototype._logClose = function () {
  9384. --this._logIndentLevel;
  9385. };
  9386. GLTFFileLoader.prototype._logEnabled = function (message) {
  9387. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  9388. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  9389. };
  9390. GLTFFileLoader.prototype._logDisabled = function (message) {
  9391. };
  9392. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  9393. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  9394. };
  9395. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  9396. };
  9397. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  9398. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  9399. };
  9400. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  9401. };
  9402. // ----------
  9403. // V1 options
  9404. // ----------
  9405. /**
  9406. * 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.
  9407. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  9408. * Defaults to true.
  9409. * @hidden
  9410. */
  9411. GLTFFileLoader.IncrementalLoading = true;
  9412. /**
  9413. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  9414. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  9415. * @hidden
  9416. */
  9417. GLTFFileLoader.HomogeneousCoordinates = false;
  9418. GLTFFileLoader.magicBase64Encoded = "Z2xURg"; // "glTF" base64 encoded (without the quotes!)
  9419. GLTFFileLoader._logSpaces = " ";
  9420. return GLTFFileLoader;
  9421. }());
  9422. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  9423. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  9424. }
  9425. /***/ }),
  9426. /***/ "./glTF/glTFValidation.ts":
  9427. /*!********************************!*\
  9428. !*** ./glTF/glTFValidation.ts ***!
  9429. \********************************/
  9430. /*! exports provided: GLTFValidation */
  9431. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9432. "use strict";
  9433. __webpack_require__.r(__webpack_exports__);
  9434. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  9435. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/observable");
  9436. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  9437. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  9438. var options = {
  9439. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  9440. };
  9441. if (fileName) {
  9442. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  9443. }
  9444. return (data instanceof ArrayBuffer)
  9445. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  9446. : GLTFValidator.validateString(data, options);
  9447. }
  9448. /**
  9449. * The worker function that gets converted to a blob url to pass into a worker.
  9450. */
  9451. function workerFunc() {
  9452. var pendingExternalResources = [];
  9453. onmessage = function (message) {
  9454. var data = message.data;
  9455. switch (data.id) {
  9456. case "init": {
  9457. importScripts(data.url);
  9458. break;
  9459. }
  9460. case "validate": {
  9461. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  9462. var index = pendingExternalResources.length;
  9463. pendingExternalResources.push({ resolve: resolve, reject: reject });
  9464. postMessage({ id: "getExternalResource", index: index, uri: uri });
  9465. }); }).then(function (value) {
  9466. postMessage({ id: "validate.resolve", value: value });
  9467. }, function (reason) {
  9468. postMessage({ id: "validate.reject", reason: reason });
  9469. });
  9470. break;
  9471. }
  9472. case "getExternalResource.resolve": {
  9473. pendingExternalResources[data.index].resolve(data.value);
  9474. break;
  9475. }
  9476. case "getExternalResource.reject": {
  9477. pendingExternalResources[data.index].reject(data.reason);
  9478. break;
  9479. }
  9480. }
  9481. };
  9482. }
  9483. /**
  9484. * glTF validation
  9485. */
  9486. var GLTFValidation = /** @class */ (function () {
  9487. function GLTFValidation() {
  9488. }
  9489. /**
  9490. * Validate a glTF asset using the glTF-Validator.
  9491. * @param data The JSON of a glTF or the array buffer of a binary glTF
  9492. * @param rootUrl The root url for the glTF
  9493. * @param fileName The file name for the glTF
  9494. * @param getExternalResource The callback to get external resources for the glTF validator
  9495. * @returns A promise that resolves with the glTF validation results once complete
  9496. */
  9497. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  9498. var _this = this;
  9499. if (typeof Worker === "function") {
  9500. return new Promise(function (resolve, reject) {
  9501. var workerContent = validateAsync + "(" + workerFunc + ")()";
  9502. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  9503. var worker = new Worker(workerBlobUrl);
  9504. var onError = function (error) {
  9505. worker.removeEventListener("error", onError);
  9506. worker.removeEventListener("message", onMessage);
  9507. reject(error);
  9508. };
  9509. var onMessage = function (message) {
  9510. var data = message.data;
  9511. switch (data.id) {
  9512. case "getExternalResource": {
  9513. getExternalResource(data.uri).then(function (value) {
  9514. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  9515. }, function (reason) {
  9516. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  9517. });
  9518. break;
  9519. }
  9520. case "validate.resolve": {
  9521. worker.removeEventListener("error", onError);
  9522. worker.removeEventListener("message", onMessage);
  9523. resolve(data.value);
  9524. break;
  9525. }
  9526. case "validate.reject": {
  9527. worker.removeEventListener("error", onError);
  9528. worker.removeEventListener("message", onMessage);
  9529. reject(data.reason);
  9530. }
  9531. }
  9532. };
  9533. worker.addEventListener("error", onError);
  9534. worker.addEventListener("message", onMessage);
  9535. worker.postMessage({ id: "init", url: _this.Configuration.url });
  9536. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  9537. });
  9538. }
  9539. else {
  9540. if (!this._LoadScriptPromise) {
  9541. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  9542. }
  9543. return this._LoadScriptPromise.then(function () {
  9544. return validateAsync(data, rootUrl, fileName, getExternalResource);
  9545. });
  9546. }
  9547. };
  9548. /**
  9549. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  9550. */
  9551. GLTFValidation.Configuration = {
  9552. url: "https://preview.babylonjs.com/gltf_validator.js"
  9553. };
  9554. return GLTFValidation;
  9555. }());
  9556. /***/ }),
  9557. /***/ "./glTF/index.ts":
  9558. /*!***********************!*\
  9559. !*** ./glTF/index.ts ***!
  9560. \***********************/
  9561. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  9562. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9563. "use strict";
  9564. __webpack_require__.r(__webpack_exports__);
  9565. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9566. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9567. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9568. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9569. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9570. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  9571. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9572. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  9573. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  9574. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  9575. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  9576. /***/ }),
  9577. /***/ "./index.ts":
  9578. /*!******************!*\
  9579. !*** ./index.ts ***!
  9580. \******************/
  9581. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9582. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9583. "use strict";
  9584. __webpack_require__.r(__webpack_exports__);
  9585. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  9586. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9587. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9588. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9589. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9590. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  9591. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  9592. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  9593. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  9594. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  9595. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  9596. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  9597. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  9598. /***/ }),
  9599. /***/ "./legacy/legacy-glTF.ts":
  9600. /*!*******************************!*\
  9601. !*** ./legacy/legacy-glTF.ts ***!
  9602. \*******************************/
  9603. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  9604. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9605. "use strict";
  9606. __webpack_require__.r(__webpack_exports__);
  9607. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  9608. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  9609. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  9610. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  9611. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  9612. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  9613. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9614. /**
  9615. * This is the entry point for the UMD module.
  9616. * The entry point for a future ESM package should be index.ts
  9617. */
  9618. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9619. if (typeof globalObject !== "undefined") {
  9620. globalObject.BABYLON = globalObject.BABYLON || {};
  9621. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  9622. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  9623. }
  9624. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  9625. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  9626. }
  9627. }
  9628. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9629. /***/ }),
  9630. /***/ "./legacy/legacy-glTF1.ts":
  9631. /*!********************************!*\
  9632. !*** ./legacy/legacy-glTF1.ts ***!
  9633. \********************************/
  9634. /*! exports provided: GLTF1 */
  9635. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9636. "use strict";
  9637. __webpack_require__.r(__webpack_exports__);
  9638. /* 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");
  9639. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  9640. /**
  9641. * This is the entry point for the UMD module.
  9642. * The entry point for a future ESM package should be index.ts
  9643. */
  9644. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9645. if (typeof globalObject !== "undefined") {
  9646. globalObject.BABYLON = globalObject.BABYLON || {};
  9647. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  9648. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  9649. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  9650. }
  9651. }
  9652. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9653. /***/ }),
  9654. /***/ "./legacy/legacy-glTF2.ts":
  9655. /*!********************************!*\
  9656. !*** ./legacy/legacy-glTF2.ts ***!
  9657. \********************************/
  9658. /*! exports provided: GLTF2 */
  9659. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9660. "use strict";
  9661. __webpack_require__.r(__webpack_exports__);
  9662. /* 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");
  9663. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  9664. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  9665. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  9666. /**
  9667. * This is the entry point for the UMD module.
  9668. * The entry point for a future ESM package should be index.ts
  9669. */
  9670. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9671. if (typeof globalObject !== "undefined") {
  9672. globalObject.BABYLON = globalObject.BABYLON || {};
  9673. var BABYLON = globalObject.BABYLON;
  9674. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  9675. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  9676. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  9677. var keys = [];
  9678. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  9679. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  9680. keys.push(key);
  9681. }
  9682. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  9683. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  9684. keys.push(key);
  9685. }
  9686. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  9687. // Prevent Reassignment.
  9688. if (keys.indexOf(key) > -1) {
  9689. continue;
  9690. }
  9691. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  9692. }
  9693. }
  9694. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9695. /***/ }),
  9696. /***/ "./legacy/legacy-objFileLoader.ts":
  9697. /*!****************************************!*\
  9698. !*** ./legacy/legacy-objFileLoader.ts ***!
  9699. \****************************************/
  9700. /*! exports provided: MTLFileLoader, OBJFileLoader */
  9701. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9702. "use strict";
  9703. __webpack_require__.r(__webpack_exports__);
  9704. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  9705. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  9706. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  9707. /**
  9708. * This is the entry point for the UMD module.
  9709. * The entry point for a future ESM package should be index.ts
  9710. */
  9711. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9712. if (typeof globalObject !== "undefined") {
  9713. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  9714. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  9715. }
  9716. }
  9717. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9718. /***/ }),
  9719. /***/ "./legacy/legacy-stlFileLoader.ts":
  9720. /*!****************************************!*\
  9721. !*** ./legacy/legacy-stlFileLoader.ts ***!
  9722. \****************************************/
  9723. /*! exports provided: STLFileLoader */
  9724. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9725. "use strict";
  9726. __webpack_require__.r(__webpack_exports__);
  9727. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  9728. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  9729. /**
  9730. * This is the entry point for the UMD module.
  9731. * The entry point for a future ESM package should be index.ts
  9732. */
  9733. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  9734. if (typeof globalObject !== "undefined") {
  9735. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  9736. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  9737. }
  9738. }
  9739. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  9740. /***/ }),
  9741. /***/ "./legacy/legacy.ts":
  9742. /*!**************************!*\
  9743. !*** ./legacy/legacy.ts ***!
  9744. \**************************/
  9745. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  9746. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  9747. "use strict";
  9748. __webpack_require__.r(__webpack_exports__);
  9749. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  9750. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  9751. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  9752. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  9753. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  9754. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  9755. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  9756. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  9757. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  9758. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  9759. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  9760. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  9761. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  9762. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  9763. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  9764. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  9765. /***/ }),
  9766. /***/ "babylonjs/Misc/observable":
  9767. /*!****************************************************************************************************!*\
  9768. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  9769. \****************************************************************************************************/
  9770. /*! no static exports found */
  9771. /***/ (function(module, exports) {
  9772. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__;
  9773. /***/ })
  9774. /******/ });
  9775. });
  9776. //# sourceMappingURL=babylonjs.loaders.js.map