babylonjs.loaders.js 416 KB

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