babylonjs.loaders.js 430 KB

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