babylonjs.loaders.js 439 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888
  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, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./OBJ/index.ts":
  324. /*!**********************!*\
  325. !*** ./OBJ/index.ts ***!
  326. \**********************/
  327. /*! exports provided: MTLFileLoader, OBJFileLoader */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  333. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  334. /***/ }),
  335. /***/ "./OBJ/objFileLoader.ts":
  336. /*!******************************!*\
  337. !*** ./OBJ/objFileLoader.ts ***!
  338. \******************************/
  339. /*! exports provided: MTLFileLoader, OBJFileLoader */
  340. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  341. "use strict";
  342. __webpack_require__.r(__webpack_exports__);
  343. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  344. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  345. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  346. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  347. /**
  348. * Class reading and parsing the MTL file bundled with the obj file.
  349. */
  350. var MTLFileLoader = /** @class */ (function () {
  351. function MTLFileLoader() {
  352. /**
  353. * All material loaded from the mtl will be set here
  354. */
  355. this.materials = [];
  356. }
  357. /**
  358. * This function will read the mtl file and create each material described inside
  359. * This function could be improve by adding :
  360. * -some component missing (Ni, Tf...)
  361. * -including the specific options available
  362. *
  363. * @param scene defines the scene the material will be created in
  364. * @param data defines the mtl data to parse
  365. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  366. */
  367. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl) {
  368. if (data instanceof ArrayBuffer) {
  369. return;
  370. }
  371. //Split the lines from the file
  372. var lines = data.split('\n');
  373. //Space char
  374. var delimiter_pattern = /\s+/;
  375. //Array with RGB colors
  376. var color;
  377. //New material
  378. var material = null;
  379. //Look at each line
  380. for (var i = 0; i < lines.length; i++) {
  381. var line = lines[i].trim();
  382. // Blank line or comment
  383. if (line.length === 0 || line.charAt(0) === '#') {
  384. continue;
  385. }
  386. //Get the first parameter (keyword)
  387. var pos = line.indexOf(' ');
  388. var key = (pos >= 0) ? line.substring(0, pos) : line;
  389. key = key.toLowerCase();
  390. //Get the data following the key
  391. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  392. //This mtl keyword will create the new material
  393. if (key === "newmtl") {
  394. //Check if it is the first material.
  395. // Materials specifications are described after this keyword.
  396. if (material) {
  397. //Add the previous material in the material array.
  398. this.materials.push(material);
  399. }
  400. //Create a new material.
  401. // value is the name of the material read in the mtl file
  402. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"](value, scene);
  403. }
  404. else if (key === "kd" && material) {
  405. // Diffuse color (color under white light) using RGB values
  406. //value = "r g b"
  407. color = value.split(delimiter_pattern, 3).map(parseFloat);
  408. //color = [r,g,b]
  409. //Set tghe color into the material
  410. material.diffuseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  411. }
  412. else if (key === "ka" && material) {
  413. // Ambient color (color under shadow) using RGB values
  414. //value = "r g b"
  415. color = value.split(delimiter_pattern, 3).map(parseFloat);
  416. //color = [r,g,b]
  417. //Set tghe color into the material
  418. material.ambientColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  419. }
  420. else if (key === "ks" && material) {
  421. // Specular color (color when light is reflected from shiny surface) using RGB values
  422. //value = "r g b"
  423. color = value.split(delimiter_pattern, 3).map(parseFloat);
  424. //color = [r,g,b]
  425. //Set the color into the material
  426. material.specularColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  427. }
  428. else if (key === "ke" && material) {
  429. // Emissive color using RGB values
  430. color = value.split(delimiter_pattern, 3).map(parseFloat);
  431. material.emissiveColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  432. }
  433. else if (key === "ns" && material) {
  434. //value = "Integer"
  435. material.specularPower = parseFloat(value);
  436. }
  437. else if (key === "d" && material) {
  438. //d is dissolve for current material. It mean alpha for BABYLON
  439. material.alpha = parseFloat(value);
  440. //Texture
  441. //This part can be improved by adding the possible options of texture
  442. }
  443. else if (key === "map_ka" && material) {
  444. // ambient texture map with a loaded image
  445. //We must first get the folder of the image
  446. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  447. }
  448. else if (key === "map_kd" && material) {
  449. // Diffuse texture map with a loaded image
  450. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  451. }
  452. else if (key === "map_ks" && material) {
  453. // Specular texture map with a loaded image
  454. //We must first get the folder of the image
  455. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  456. }
  457. else if (key === "map_ns") {
  458. //Specular
  459. //Specular highlight component
  460. //We must first get the folder of the image
  461. //
  462. //Not supported by BABYLON
  463. //
  464. // continue;
  465. }
  466. else if (key === "map_bump" && material) {
  467. //The bump texture
  468. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  469. }
  470. else if (key === "map_d" && material) {
  471. // The dissolve of the material
  472. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  473. //Options for illumination
  474. }
  475. else if (key === "illum") {
  476. //Illumination
  477. if (value === "0") {
  478. //That mean Kd == Kd
  479. }
  480. else if (value === "1") {
  481. //Color on and Ambient on
  482. }
  483. else if (value === "2") {
  484. //Highlight on
  485. }
  486. else if (value === "3") {
  487. //Reflection on and Ray trace on
  488. }
  489. else if (value === "4") {
  490. //Transparency: Glass on, Reflection: Ray trace on
  491. }
  492. else if (value === "5") {
  493. //Reflection: Fresnel on and Ray trace on
  494. }
  495. else if (value === "6") {
  496. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  497. }
  498. else if (value === "7") {
  499. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  500. }
  501. else if (value === "8") {
  502. //Reflection on and Ray trace off
  503. }
  504. else if (value === "9") {
  505. //Transparency: Glass on, Reflection: Ray trace off
  506. }
  507. else if (value === "10") {
  508. //Casts shadows onto invisible surfaces
  509. }
  510. }
  511. else {
  512. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  513. }
  514. }
  515. //At the end of the file, add the last material
  516. if (material) {
  517. this.materials.push(material);
  518. }
  519. };
  520. /**
  521. * Gets the texture for the material.
  522. *
  523. * If the material is imported from input file,
  524. * We sanitize the url to ensure it takes the textre from aside the material.
  525. *
  526. * @param rootUrl The root url to load from
  527. * @param value The value stored in the mtl
  528. * @return The Texture
  529. */
  530. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  531. if (!value) {
  532. return null;
  533. }
  534. var url = rootUrl;
  535. // Load from input file.
  536. if (rootUrl === "file:") {
  537. var lastDelimiter = value.lastIndexOf("\\");
  538. if (lastDelimiter === -1) {
  539. lastDelimiter = value.lastIndexOf("/");
  540. }
  541. if (lastDelimiter > -1) {
  542. url += value.substr(lastDelimiter + 1);
  543. }
  544. else {
  545. url += value;
  546. }
  547. }
  548. // Not from input file.
  549. else {
  550. url += value;
  551. }
  552. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, scene, false, OBJFileLoader.INVERT_TEXTURE_Y);
  553. };
  554. return MTLFileLoader;
  555. }());
  556. /**
  557. * OBJ file type loader.
  558. * This is a babylon scene loader plugin.
  559. */
  560. var OBJFileLoader = /** @class */ (function () {
  561. /**
  562. * Creates loader for .OBJ files
  563. *
  564. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  565. */
  566. function OBJFileLoader(meshLoadOptions) {
  567. /**
  568. * Defines the name of the plugin.
  569. */
  570. this.name = "obj";
  571. /**
  572. * Defines the extension the plugin is able to load.
  573. */
  574. this.extensions = ".obj";
  575. /** @hidden */
  576. this.obj = /^o/;
  577. /** @hidden */
  578. this.group = /^g/;
  579. /** @hidden */
  580. this.mtllib = /^mtllib /;
  581. /** @hidden */
  582. this.usemtl = /^usemtl /;
  583. /** @hidden */
  584. this.smooth = /^s /;
  585. /** @hidden */
  586. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+){3,7}/;
  587. // vn float float float
  588. /** @hidden */
  589. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  590. // vt float float
  591. /** @hidden */
  592. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  593. // f vertex vertex vertex ...
  594. /** @hidden */
  595. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  596. // f vertex/uvs vertex/uvs vertex/uvs ...
  597. /** @hidden */
  598. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  599. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  600. /** @hidden */
  601. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  602. // f vertex//normal vertex//normal vertex//normal ...
  603. /** @hidden */
  604. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  605. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  606. /** @hidden */
  607. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  608. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  609. }
  610. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  611. get: function () {
  612. return {
  613. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  614. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  615. InvertY: OBJFileLoader.INVERT_Y,
  616. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  617. UVScaling: OBJFileLoader.UV_SCALING,
  618. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  619. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  620. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  621. };
  622. },
  623. enumerable: true,
  624. configurable: true
  625. });
  626. /**
  627. * Calls synchronously the MTL file attached to this obj.
  628. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  629. * Without this function materials are not displayed in the first frame (but displayed after).
  630. * In consequence it is impossible to get material information in your HTML file
  631. *
  632. * @param url The URL of the MTL file
  633. * @param rootUrl
  634. * @param onSuccess Callback function to be called when the MTL file is loaded
  635. * @private
  636. */
  637. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  638. //The complete path to the mtl file
  639. var pathOfFile = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  640. // Loads through the babylon tools to allow fileInput search.
  641. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  642. onFailure(pathOfFile, exception);
  643. });
  644. };
  645. /**
  646. * Instantiates a OBJ file loader plugin.
  647. * @returns the created plugin
  648. */
  649. OBJFileLoader.prototype.createPlugin = function () {
  650. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  651. };
  652. /**
  653. * If the data string can be loaded directly.
  654. *
  655. * @param data string containing the file data
  656. * @returns if the data can be loaded directly
  657. */
  658. OBJFileLoader.prototype.canDirectLoad = function (data) {
  659. return false;
  660. };
  661. /**
  662. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  663. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  664. * @param scene the scene the meshes should be added to
  665. * @param data the OBJ data to load
  666. * @param rootUrl root url to load from
  667. * @param onProgress event that fires when loading progress has occured
  668. * @param fileName Defines the name of the file to load
  669. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  670. */
  671. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  672. //get the meshes from OBJ file
  673. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  674. return {
  675. meshes: meshes,
  676. particleSystems: [],
  677. skeletons: [],
  678. animationGroups: []
  679. };
  680. });
  681. };
  682. /**
  683. * Imports all objects from the loaded OBJ data and adds them to the scene
  684. * @param scene the scene the objects should be added to
  685. * @param data the OBJ data to load
  686. * @param rootUrl root url to load from
  687. * @param onProgress event that fires when loading progress has occured
  688. * @param fileName Defines the name of the file to load
  689. * @returns a promise which completes when objects have been loaded to the scene
  690. */
  691. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  692. //Get the 3D model
  693. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  694. // return void
  695. });
  696. };
  697. /**
  698. * Load into an asset container.
  699. * @param scene The scene to load into
  700. * @param data The data to import
  701. * @param rootUrl The root url for scene and resources
  702. * @param onProgress The callback when the load progresses
  703. * @param fileName Defines the name of the file to load
  704. * @returns The loaded asset container
  705. */
  706. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  707. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  708. var container = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  709. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  710. result.meshes.forEach(function (mesh) {
  711. var material = mesh.material;
  712. if (material) {
  713. // Materials
  714. if (container.materials.indexOf(material) == -1) {
  715. container.materials.push(material);
  716. // Textures
  717. var textures = material.getActiveTextures();
  718. textures.forEach(function (t) {
  719. if (container.textures.indexOf(t) == -1) {
  720. container.textures.push(t);
  721. }
  722. });
  723. }
  724. }
  725. });
  726. container.removeAllFromScene();
  727. return container;
  728. });
  729. };
  730. /**
  731. * Read the OBJ file and create an Array of meshes.
  732. * Each mesh contains all information given by the OBJ and the MTL file.
  733. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  734. *
  735. * @param meshesNames
  736. * @param scene Scene The scene where are displayed the data
  737. * @param data String The content of the obj file
  738. * @param rootUrl String The path to the folder
  739. * @returns Array<AbstractMesh>
  740. * @private
  741. */
  742. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  743. var _this = this;
  744. var positions = []; //values for the positions of vertices
  745. var normals = []; //Values for the normals
  746. var uvs = []; //Values for the textures
  747. var colors = [];
  748. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  749. var handledMesh; //The current mesh of meshes array
  750. var indicesForBabylon = []; //The list of indices for VertexData
  751. var wrappedPositionForBabylon = []; //The list of position in vectors
  752. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  753. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  754. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  755. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  756. var curPositionInIndices = 0;
  757. var hasMeshes = false; //Meshes are defined in the file
  758. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  759. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  760. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  761. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  762. var triangles = []; //Indices from new triangles coming from polygons
  763. var materialNameFromObj = ""; //The name of the current material
  764. var fileToLoad = ""; //The name of the mtlFile to load
  765. var materialsFromMTLFile = new MTLFileLoader();
  766. var objMeshName = ""; //The name of the current obj mesh
  767. var increment = 1; //Id for meshes created by the multimaterial
  768. var isFirstMaterial = true;
  769. var grayColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  770. /**
  771. * Search for obj in the given array.
  772. * This function is called to check if a couple of data already exists in an array.
  773. *
  774. * If found, returns the index of the founded tuple index. Returns -1 if not found
  775. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  776. * @param obj Array<number>
  777. * @returns {boolean}
  778. */
  779. var isInArray = function (arr, obj) {
  780. if (!arr[obj[0]]) {
  781. arr[obj[0]] = { normals: [], idx: [] };
  782. }
  783. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  784. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  785. };
  786. var isInArrayUV = function (arr, obj) {
  787. if (!arr[obj[0]]) {
  788. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  789. }
  790. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  791. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  792. return arr[obj[0]].idx[idx];
  793. }
  794. return -1;
  795. };
  796. /**
  797. * This function set the data for each triangle.
  798. * Data are position, normals and uvs
  799. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  800. * If the tuple already exist, add only their indice
  801. *
  802. * @param indicePositionFromObj Integer The index in positions array
  803. * @param indiceUvsFromObj Integer The index in uvs array
  804. * @param indiceNormalFromObj Integer The index in normals array
  805. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  806. * @param textureVectorFromOBJ Vector3 The value of uvs
  807. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  808. */
  809. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  810. //Check if this tuple already exists in the list of tuples
  811. var _index;
  812. if (_this._meshLoadOptions.OptimizeWithUV) {
  813. _index = isInArrayUV(tuplePosNorm, [
  814. indicePositionFromObj,
  815. indiceNormalFromObj,
  816. indiceUvsFromObj
  817. ]);
  818. }
  819. else {
  820. _index = isInArray(tuplePosNorm, [
  821. indicePositionFromObj,
  822. indiceNormalFromObj
  823. ]);
  824. }
  825. //If it not exists
  826. if (_index === -1) {
  827. //Add an new indice.
  828. //The array of indices is only an array with his length equal to the number of triangles - 1.
  829. //We add vertices data in this order
  830. indicesForBabylon.push(wrappedPositionForBabylon.length);
  831. //Push the position of vertice for Babylon
  832. //Each element is a Vector3(x,y,z)
  833. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  834. //Push the uvs for Babylon
  835. //Each element is a Vector3(u,v)
  836. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  837. //Push the normals for Babylon
  838. //Each element is a Vector3(x,y,z)
  839. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  840. if (positionColorsFromOBJ !== undefined) {
  841. //Push the colors for Babylon
  842. //Each element is a BABYLON.Color4(r,g,b,a)
  843. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  844. }
  845. //Add the tuple in the comparison list
  846. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  847. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  848. if (_this._meshLoadOptions.OptimizeWithUV) {
  849. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  850. }
  851. }
  852. else {
  853. //The tuple already exists
  854. //Add the index of the already existing tuple
  855. //At this index we can get the value of position, normal, color and uvs of vertex
  856. indicesForBabylon.push(_index);
  857. }
  858. };
  859. /**
  860. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  861. */
  862. var unwrapData = function () {
  863. //Every array has the same length
  864. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  865. //Push the x, y, z values of each element in the unwrapped array
  866. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  867. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  868. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  869. }
  870. if (_this._meshLoadOptions.ImportVertexColors === true) {
  871. //Push the r, g, b, a values of each element in the unwrapped array
  872. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  873. }
  874. // Reset arrays for the next new meshes
  875. wrappedPositionForBabylon = [];
  876. wrappedNormalsForBabylon = [];
  877. wrappedUvsForBabylon = [];
  878. wrappedColorsForBabylon = [];
  879. tuplePosNorm = [];
  880. curPositionInIndices = 0;
  881. };
  882. /**
  883. * Create triangles from polygons
  884. * It is important to notice that a triangle is a polygon
  885. * We get 5 patterns of face defined in OBJ File :
  886. * facePattern1 = ["1","2","3","4","5","6"]
  887. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  888. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  889. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  890. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  891. * Each pattern is divided by the same method
  892. * @param face Array[String] The indices of elements
  893. * @param v Integer The variable to increment
  894. */
  895. var getTriangles = function (faces, v) {
  896. //Work for each element of the array
  897. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  898. //Add on the triangle variable the indexes to obtain triangles
  899. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  900. }
  901. //Result obtained after 2 iterations:
  902. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  903. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  904. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  905. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  906. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  907. };
  908. /**
  909. * Create triangles and push the data for each polygon for the pattern 1
  910. * In this pattern we get vertice positions
  911. * @param face
  912. * @param v
  913. */
  914. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  915. //Get the indices of triangles for each polygon
  916. getTriangles(face, v);
  917. //For each element in the triangles array.
  918. //This var could contains 1 to an infinity of triangles
  919. for (var k = 0; k < triangles.length; k++) {
  920. // Set position indice
  921. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  922. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  923. positions[indicePositionFromObj], //Get the vectors data
  924. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  925. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  926. }
  927. //Reset variable for the next line
  928. triangles = [];
  929. };
  930. /**
  931. * Create triangles and push the data for each polygon for the pattern 2
  932. * In this pattern we get vertice positions and uvsu
  933. * @param face
  934. * @param v
  935. */
  936. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  937. //Get the indices of triangles for each polygon
  938. getTriangles(face, v);
  939. for (var k = 0; k < triangles.length; k++) {
  940. //triangle[k] = "1/1"
  941. //Split the data for getting position and uv
  942. var point = triangles[k].split("/"); // ["1", "1"]
  943. //Set position indice
  944. var indicePositionFromObj = parseInt(point[0]) - 1;
  945. //Set uv indice
  946. var indiceUvsFromObj = parseInt(point[1]) - 1;
  947. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  948. positions[indicePositionFromObj], //Get the values for each element
  949. uvs[indiceUvsFromObj], babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  950. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  951. }
  952. //Reset variable for the next line
  953. triangles = [];
  954. };
  955. /**
  956. * Create triangles and push the data for each polygon for the pattern 3
  957. * In this pattern we get vertice positions, uvs and normals
  958. * @param face
  959. * @param v
  960. */
  961. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  962. //Get the indices of triangles for each polygon
  963. getTriangles(face, v);
  964. for (var k = 0; k < triangles.length; k++) {
  965. //triangle[k] = "1/1/1"
  966. //Split the data for getting position, uv, and normals
  967. var point = triangles[k].split("/"); // ["1", "1", "1"]
  968. // Set position indice
  969. var indicePositionFromObj = parseInt(point[0]) - 1;
  970. // Set uv indice
  971. var indiceUvsFromObj = parseInt(point[1]) - 1;
  972. // Set normal indice
  973. var indiceNormalFromObj = parseInt(point[2]) - 1;
  974. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  975. );
  976. }
  977. //Reset variable for the next line
  978. triangles = [];
  979. };
  980. /**
  981. * Create triangles and push the data for each polygon for the pattern 4
  982. * In this pattern we get vertice positions and normals
  983. * @param face
  984. * @param v
  985. */
  986. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  987. getTriangles(face, v);
  988. for (var k = 0; k < triangles.length; k++) {
  989. //triangle[k] = "1//1"
  990. //Split the data for getting position and normals
  991. var point = triangles[k].split("//"); // ["1", "1"]
  992. // We check indices, and normals
  993. var indicePositionFromObj = parseInt(point[0]) - 1;
  994. var indiceNormalFromObj = parseInt(point[1]) - 1;
  995. setData(indicePositionFromObj, 1, //Default value for uv
  996. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  997. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  998. }
  999. //Reset variable for the next line
  1000. triangles = [];
  1001. };
  1002. /**
  1003. * Create triangles and push the data for each polygon for the pattern 3
  1004. * In this pattern we get vertice positions, uvs and normals
  1005. * @param face
  1006. * @param v
  1007. */
  1008. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1009. //Get the indices of triangles for each polygon
  1010. getTriangles(face, v);
  1011. for (var k = 0; k < triangles.length; k++) {
  1012. //triangle[k] = "-1/-1/-1"
  1013. //Split the data for getting position, uv, and normals
  1014. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1015. // Set position indice
  1016. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1017. // Set uv indice
  1018. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1019. // Set normal indice
  1020. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1021. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1022. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1023. }
  1024. //Reset variable for the next line
  1025. triangles = [];
  1026. };
  1027. var addPreviousObjMesh = function () {
  1028. //Check if it is not the first mesh. Otherwise we don't have data.
  1029. if (meshesFromObj.length > 0) {
  1030. //Get the previous mesh for applying the data about the faces
  1031. //=> in obj file, faces definition append after the name of the mesh
  1032. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1033. //Set the data into Array for the mesh
  1034. unwrapData();
  1035. // Reverse tab. Otherwise face are displayed in the wrong sens
  1036. indicesForBabylon.reverse();
  1037. //Set the information for the mesh
  1038. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1039. handledMesh.indices = indicesForBabylon.slice();
  1040. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1041. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1042. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1043. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1044. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1045. }
  1046. //Reset the array for the next mesh
  1047. indicesForBabylon = [];
  1048. unwrappedPositionsForBabylon = [];
  1049. unwrappedColorsForBabylon = [];
  1050. unwrappedNormalsForBabylon = [];
  1051. unwrappedUVForBabylon = [];
  1052. }
  1053. };
  1054. //Main function
  1055. //Split the file into lines
  1056. var lines = data.split('\n');
  1057. //Look at each line
  1058. for (var i = 0; i < lines.length; i++) {
  1059. var line = lines[i].trim().replace(/\s\s/g, " ");
  1060. var result;
  1061. //Comment or newLine
  1062. if (line.length === 0 || line.charAt(0) === '#') {
  1063. continue;
  1064. //Get information about one position possible for the vertices
  1065. }
  1066. else if (this.vertexPattern.test(line)) {
  1067. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1068. // Value of result with line: "v 1.0 2.0 3.0"
  1069. // ["v", "1.0", "2.0", "3.0"]
  1070. // Create a Vector3 with the position x, y, z
  1071. positions.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1072. if (this._meshLoadOptions.ImportVertexColors === true) {
  1073. if (result.length >= 7) {
  1074. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1075. colors.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color4"](parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
  1076. }
  1077. else {
  1078. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1079. colors.push(grayColor);
  1080. }
  1081. }
  1082. }
  1083. else if ((result = this.normalPattern.exec(line)) !== null) {
  1084. //Create a Vector3 with the normals x, y, z
  1085. //Value of result
  1086. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1087. //Add the Vector in the list of normals
  1088. normals.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1089. }
  1090. else if ((result = this.uvPattern.exec(line)) !== null) {
  1091. //Create a Vector2 with the normals u, v
  1092. //Value of result
  1093. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1094. //Add the Vector in the list of uvs
  1095. uvs.push(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
  1096. //Identify patterns of faces
  1097. //Face could be defined in different type of pattern
  1098. }
  1099. else if ((result = this.facePattern3.exec(line)) !== null) {
  1100. //Value of result:
  1101. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1102. //Set the data for this face
  1103. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1104. 1);
  1105. }
  1106. else if ((result = this.facePattern4.exec(line)) !== null) {
  1107. //Value of result:
  1108. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1109. //Set the data for this face
  1110. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1111. 1);
  1112. }
  1113. else if ((result = this.facePattern5.exec(line)) !== null) {
  1114. //Value of result:
  1115. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1116. //Set the data for this face
  1117. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1118. 1);
  1119. }
  1120. else if ((result = this.facePattern2.exec(line)) !== null) {
  1121. //Value of result:
  1122. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1123. //Set the data for this face
  1124. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1125. 1);
  1126. }
  1127. else if ((result = this.facePattern1.exec(line)) !== null) {
  1128. //Value of result
  1129. //["f 1 2 3", "1 2 3"...]
  1130. //Set the data for this face
  1131. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1132. 1);
  1133. //Define a mesh or an object
  1134. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1135. }
  1136. else if (this.group.test(line) || this.obj.test(line)) {
  1137. //Create a new mesh corresponding to the name of the group.
  1138. //Definition of the mesh
  1139. var objMesh = {
  1140. name: line.substring(2).trim(),
  1141. indices: undefined,
  1142. positions: undefined,
  1143. normals: undefined,
  1144. uvs: undefined,
  1145. colors: undefined,
  1146. materialName: ""
  1147. };
  1148. addPreviousObjMesh();
  1149. //Push the last mesh created with only the name
  1150. meshesFromObj.push(objMesh);
  1151. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1152. hasMeshes = true;
  1153. isFirstMaterial = true;
  1154. increment = 1;
  1155. //Keyword for applying a material
  1156. }
  1157. else if (this.usemtl.test(line)) {
  1158. //Get the name of the material
  1159. materialNameFromObj = line.substring(7).trim();
  1160. //If this new material is in the same mesh
  1161. if (!isFirstMaterial) {
  1162. //Set the data for the previous mesh
  1163. addPreviousObjMesh();
  1164. //Create a new mesh
  1165. var objMesh =
  1166. //Set the name of the current obj mesh
  1167. {
  1168. name: objMeshName + "_mm" + increment.toString(),
  1169. indices: undefined,
  1170. positions: undefined,
  1171. normals: undefined,
  1172. uvs: undefined,
  1173. colors: undefined,
  1174. materialName: materialNameFromObj
  1175. };
  1176. increment++;
  1177. //If meshes are already defined
  1178. meshesFromObj.push(objMesh);
  1179. }
  1180. //Set the material name if the previous line define a mesh
  1181. if (hasMeshes && isFirstMaterial) {
  1182. //Set the material name to the previous mesh (1 material per mesh)
  1183. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1184. isFirstMaterial = false;
  1185. }
  1186. //Keyword for loading the mtl file
  1187. }
  1188. else if (this.mtllib.test(line)) {
  1189. //Get the name of mtl file
  1190. fileToLoad = line.substring(7).trim();
  1191. //Apply smoothing
  1192. }
  1193. else if (this.smooth.test(line)) {
  1194. // smooth shading => apply smoothing
  1195. //Today I don't know it work with babylon and with obj.
  1196. //With the obj file an integer is set
  1197. }
  1198. else {
  1199. //If there is another possibility
  1200. console.log("Unhandled expression at line : " + line);
  1201. }
  1202. }
  1203. //At the end of the file, add the last mesh into the meshesFromObj array
  1204. if (hasMeshes) {
  1205. //Set the data for the last mesh
  1206. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1207. //Reverse indices for displaying faces in the good sense
  1208. indicesForBabylon.reverse();
  1209. //Get the good array
  1210. unwrapData();
  1211. //Set array
  1212. handledMesh.indices = indicesForBabylon;
  1213. handledMesh.positions = unwrappedPositionsForBabylon;
  1214. handledMesh.normals = unwrappedNormalsForBabylon;
  1215. handledMesh.uvs = unwrappedUVForBabylon;
  1216. if (this._meshLoadOptions.ImportVertexColors === true) {
  1217. handledMesh.colors = unwrappedColorsForBabylon;
  1218. }
  1219. }
  1220. //If any o or g keyword found, create a mesh with a random id
  1221. if (!hasMeshes) {
  1222. // reverse tab of indices
  1223. indicesForBabylon.reverse();
  1224. //Get positions normals uvs
  1225. unwrapData();
  1226. //Set data for one mesh
  1227. meshesFromObj.push({
  1228. name: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1229. indices: indicesForBabylon,
  1230. positions: unwrappedPositionsForBabylon,
  1231. colors: unwrappedColorsForBabylon,
  1232. normals: unwrappedNormalsForBabylon,
  1233. uvs: unwrappedUVForBabylon,
  1234. materialName: materialNameFromObj
  1235. });
  1236. }
  1237. //Create a Mesh list
  1238. var babylonMeshesArray = []; //The mesh for babylon
  1239. var materialToUse = new Array();
  1240. //Set data for each mesh
  1241. for (var j = 0; j < meshesFromObj.length; j++) {
  1242. //check meshesNames (stlFileLoader)
  1243. if (meshesNames && meshesFromObj[j].name) {
  1244. if (meshesNames instanceof Array) {
  1245. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1246. continue;
  1247. }
  1248. }
  1249. else {
  1250. if (meshesFromObj[j].name !== meshesNames) {
  1251. continue;
  1252. }
  1253. }
  1254. }
  1255. //Get the current mesh
  1256. //Set the data with VertexBuffer for each mesh
  1257. handledMesh = meshesFromObj[j];
  1258. //Create a Mesh with the name of the obj mesh
  1259. var babylonMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1260. //Push the name of the material to an array
  1261. //This is indispensable for the importMesh function
  1262. materialToUse.push(meshesFromObj[j].materialName);
  1263. var vertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1264. //Set the data for the babylonMesh
  1265. vertexData.uvs = handledMesh.uvs;
  1266. vertexData.indices = handledMesh.indices;
  1267. vertexData.positions = handledMesh.positions;
  1268. if (this._meshLoadOptions.ComputeNormals === true) {
  1269. var normals_1 = new Array();
  1270. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1271. vertexData.normals = normals_1;
  1272. }
  1273. else {
  1274. vertexData.normals = handledMesh.normals;
  1275. }
  1276. if (this._meshLoadOptions.ImportVertexColors === true) {
  1277. vertexData.colors = handledMesh.colors;
  1278. }
  1279. //Set the data from the VertexBuffer to the current Mesh
  1280. vertexData.applyToMesh(babylonMesh);
  1281. if (this._meshLoadOptions.InvertY) {
  1282. babylonMesh.scaling.y *= -1;
  1283. }
  1284. //Push the mesh into an array
  1285. babylonMeshesArray.push(babylonMesh);
  1286. }
  1287. var mtlPromises = [];
  1288. //load the materials
  1289. //Check if we have a file to load
  1290. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1291. //Load the file synchronously
  1292. mtlPromises.push(new Promise(function (resolve, reject) {
  1293. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1294. try {
  1295. //Create materials thanks MTLLoader function
  1296. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl);
  1297. //Look at each material loaded in the mtl file
  1298. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1299. //Three variables to get all meshes with the same material
  1300. var startIndex = 0;
  1301. var _indices = [];
  1302. var _index;
  1303. //The material from MTL file is used in the meshes loaded
  1304. //Push the indice in an array
  1305. //Check if the material is not used for another mesh
  1306. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1307. _indices.push(_index);
  1308. startIndex = _index + 1;
  1309. }
  1310. //If the material is not used dispose it
  1311. if (_index === -1 && _indices.length === 0) {
  1312. //If the material is not needed, remove it
  1313. materialsFromMTLFile.materials[n].dispose();
  1314. }
  1315. else {
  1316. for (var o = 0; o < _indices.length; o++) {
  1317. //Apply the material to the Mesh for each mesh with the material
  1318. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1319. }
  1320. }
  1321. }
  1322. resolve();
  1323. }
  1324. catch (e) {
  1325. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1326. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1327. resolve();
  1328. }
  1329. else {
  1330. reject(e);
  1331. }
  1332. }
  1333. }, function (pathOfFile, exception) {
  1334. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1335. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1336. resolve();
  1337. }
  1338. else {
  1339. reject(exception);
  1340. }
  1341. });
  1342. }));
  1343. }
  1344. //Return an array with all Mesh
  1345. return Promise.all(mtlPromises).then(function () {
  1346. return babylonMeshesArray;
  1347. });
  1348. };
  1349. /**
  1350. * Defines if UVs are optimized by default during load.
  1351. */
  1352. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1353. /**
  1354. * Invert model on y-axis (does a model scaling inversion)
  1355. */
  1356. OBJFileLoader.INVERT_Y = false;
  1357. /**
  1358. * Invert Y-Axis of referenced textures on load
  1359. */
  1360. OBJFileLoader.INVERT_TEXTURE_Y = true;
  1361. /**
  1362. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1363. */
  1364. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1365. /**
  1366. * Compute the normals for the model, even if normals are present in the file.
  1367. */
  1368. OBJFileLoader.COMPUTE_NORMALS = false;
  1369. /**
  1370. * Defines custom scaling of UV coordinates of loaded meshes.
  1371. */
  1372. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1373. /**
  1374. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1375. */
  1376. OBJFileLoader.SKIP_MATERIALS = false;
  1377. /**
  1378. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1379. *
  1380. * Defaults to true for backwards compatibility.
  1381. */
  1382. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1383. return OBJFileLoader;
  1384. }());
  1385. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1386. //Add this loader into the register plugin
  1387. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1388. }
  1389. /***/ }),
  1390. /***/ "./STL/index.ts":
  1391. /*!**********************!*\
  1392. !*** ./STL/index.ts ***!
  1393. \**********************/
  1394. /*! exports provided: STLFileLoader */
  1395. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1396. "use strict";
  1397. __webpack_require__.r(__webpack_exports__);
  1398. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1399. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1400. /***/ }),
  1401. /***/ "./STL/stlFileLoader.ts":
  1402. /*!******************************!*\
  1403. !*** ./STL/stlFileLoader.ts ***!
  1404. \******************************/
  1405. /*! exports provided: STLFileLoader */
  1406. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1407. "use strict";
  1408. __webpack_require__.r(__webpack_exports__);
  1409. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1410. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/observable");
  1411. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1412. /**
  1413. * STL file type loader.
  1414. * This is a babylon scene loader plugin.
  1415. */
  1416. var STLFileLoader = /** @class */ (function () {
  1417. function STLFileLoader() {
  1418. /** @hidden */
  1419. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  1420. /** @hidden */
  1421. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1422. /** @hidden */
  1423. this.normalPattern = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1424. /** @hidden */
  1425. this.vertexPattern = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1426. /**
  1427. * Defines the name of the plugin.
  1428. */
  1429. this.name = "stl";
  1430. /**
  1431. * Defines the extensions the stl loader is able to load.
  1432. * force data to come in as an ArrayBuffer
  1433. * we'll convert to string if it looks like it's an ASCII .stl
  1434. */
  1435. this.extensions = {
  1436. ".stl": { isBinary: true },
  1437. };
  1438. }
  1439. /**
  1440. * Import meshes into a scene.
  1441. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1442. * @param scene The scene to import into
  1443. * @param data The data to import
  1444. * @param rootUrl The root url for scene and resources
  1445. * @param meshes The meshes array to import into
  1446. * @param particleSystems The particle systems array to import into
  1447. * @param skeletons The skeletons array to import into
  1448. * @param onError The callback when import fails
  1449. * @returns True if successful or false otherwise
  1450. */
  1451. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1452. var matches;
  1453. if (typeof data !== "string") {
  1454. if (this._isBinary(data)) {
  1455. // binary .stl
  1456. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1457. this._parseBinary(babylonMesh, data);
  1458. if (meshes) {
  1459. meshes.push(babylonMesh);
  1460. }
  1461. return true;
  1462. }
  1463. // ASCII .stl
  1464. // convert to string
  1465. var array_buffer = new Uint8Array(data);
  1466. var str = '';
  1467. for (var i = 0; i < data.byteLength; i++) {
  1468. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1469. }
  1470. data = str;
  1471. }
  1472. //if arrived here, data is a string, containing the STLA data.
  1473. while (matches = this.solidPattern.exec(data)) {
  1474. var meshName = matches[1];
  1475. var meshNameFromEnd = matches[3];
  1476. if (meshName != meshNameFromEnd) {
  1477. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1478. return false;
  1479. }
  1480. // check meshesNames
  1481. if (meshesNames && meshName) {
  1482. if (meshesNames instanceof Array) {
  1483. if (!meshesNames.indexOf(meshName)) {
  1484. continue;
  1485. }
  1486. }
  1487. else {
  1488. if (meshName !== meshesNames) {
  1489. continue;
  1490. }
  1491. }
  1492. }
  1493. // stl mesh name can be empty as well
  1494. meshName = meshName || "stlmesh";
  1495. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1496. this._parseASCII(babylonMesh, matches[2]);
  1497. if (meshes) {
  1498. meshes.push(babylonMesh);
  1499. }
  1500. }
  1501. return true;
  1502. };
  1503. /**
  1504. * Load into a scene.
  1505. * @param scene The scene to load into
  1506. * @param data The data to import
  1507. * @param rootUrl The root url for scene and resources
  1508. * @param onError The callback when import fails
  1509. * @returns true if successful or false otherwise
  1510. */
  1511. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1512. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1513. return result;
  1514. };
  1515. /**
  1516. * Load into an asset container.
  1517. * @param scene The scene to load into
  1518. * @param data The data to import
  1519. * @param rootUrl The root url for scene and resources
  1520. * @param onError The callback when import fails
  1521. * @returns The loaded asset container
  1522. */
  1523. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1524. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1525. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1526. container.removeAllFromScene();
  1527. return container;
  1528. };
  1529. STLFileLoader.prototype._isBinary = function (data) {
  1530. // check if file size is correct for binary stl
  1531. var faceSize, nFaces, reader;
  1532. reader = new DataView(data);
  1533. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1534. nFaces = reader.getUint32(80, true);
  1535. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1536. return true;
  1537. }
  1538. // check characters higher than ASCII to confirm binary
  1539. var fileLength = reader.byteLength;
  1540. for (var index = 0; index < fileLength; index++) {
  1541. if (reader.getUint8(index) > 127) {
  1542. return true;
  1543. }
  1544. }
  1545. return false;
  1546. };
  1547. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1548. var reader = new DataView(data);
  1549. var faces = reader.getUint32(80, true);
  1550. var dataOffset = 84;
  1551. var faceLength = 12 * 4 + 2;
  1552. var offset = 0;
  1553. var positions = new Float32Array(faces * 3 * 3);
  1554. var normals = new Float32Array(faces * 3 * 3);
  1555. var indices = new Uint32Array(faces * 3);
  1556. var indicesCount = 0;
  1557. for (var face = 0; face < faces; face++) {
  1558. var start = dataOffset + face * faceLength;
  1559. var normalX = reader.getFloat32(start, true);
  1560. var normalY = reader.getFloat32(start + 4, true);
  1561. var normalZ = reader.getFloat32(start + 8, true);
  1562. for (var i = 1; i <= 3; i++) {
  1563. var vertexstart = start + i * 12;
  1564. // ordering is intentional to match ascii import
  1565. positions[offset] = reader.getFloat32(vertexstart, true);
  1566. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1567. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1568. normals[offset] = normalX;
  1569. normals[offset + 2] = normalY;
  1570. normals[offset + 1] = normalZ;
  1571. offset += 3;
  1572. }
  1573. indices[indicesCount] = indicesCount++;
  1574. indices[indicesCount] = indicesCount++;
  1575. indices[indicesCount] = indicesCount++;
  1576. }
  1577. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1578. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1579. mesh.setIndices(indices);
  1580. mesh.computeWorldMatrix(true);
  1581. };
  1582. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1583. var positions = [];
  1584. var normals = [];
  1585. var indices = [];
  1586. var indicesCount = 0;
  1587. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1588. var matches;
  1589. while (matches = this.facetsPattern.exec(solidData)) {
  1590. var facet = matches[1];
  1591. //one normal per face
  1592. var normalMatches = this.normalPattern.exec(facet);
  1593. this.normalPattern.lastIndex = 0;
  1594. if (!normalMatches) {
  1595. continue;
  1596. }
  1597. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1598. var vertexMatch;
  1599. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1600. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1601. normals.push(normal[0], normal[1], normal[2]);
  1602. }
  1603. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1604. this.vertexPattern.lastIndex = 0;
  1605. }
  1606. this.facetsPattern.lastIndex = 0;
  1607. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1608. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1609. mesh.setIndices(indices);
  1610. mesh.computeWorldMatrix(true);
  1611. };
  1612. return STLFileLoader;
  1613. }());
  1614. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1615. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1616. }
  1617. /***/ }),
  1618. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1619. /*!*****************************************!*\
  1620. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1621. \*****************************************/
  1622. /*! exports provided: GLTFBinaryExtension */
  1623. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1624. "use strict";
  1625. __webpack_require__.r(__webpack_exports__);
  1626. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1627. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1628. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1629. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1630. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1631. var BinaryExtensionBufferName = "binary_glTF";
  1632. /** @hidden */
  1633. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1634. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1635. function GLTFBinaryExtension() {
  1636. return _super.call(this, "KHR_binary_glTF") || this;
  1637. }
  1638. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1639. var extensionsUsed = data.json.extensionsUsed;
  1640. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1641. return false;
  1642. }
  1643. this._bin = data.bin;
  1644. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1645. return true;
  1646. };
  1647. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1648. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1649. return false;
  1650. }
  1651. if (id !== BinaryExtensionBufferName) {
  1652. return false;
  1653. }
  1654. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1655. return true;
  1656. };
  1657. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1658. var texture = gltfRuntime.textures[id];
  1659. var source = gltfRuntime.images[texture.source];
  1660. if (!source.extensions || !(this.name in source.extensions)) {
  1661. return false;
  1662. }
  1663. var sourceExt = source.extensions[this.name];
  1664. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1665. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1666. onSuccess(buffer);
  1667. return true;
  1668. };
  1669. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1670. var shader = gltfRuntime.shaders[id];
  1671. if (!shader.extensions || !(this.name in shader.extensions)) {
  1672. return false;
  1673. }
  1674. var binaryExtensionShader = shader.extensions[this.name];
  1675. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1676. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1677. setTimeout(function () {
  1678. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1679. onSuccess(shaderString);
  1680. });
  1681. return true;
  1682. };
  1683. return GLTFBinaryExtension;
  1684. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1685. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1686. /***/ }),
  1687. /***/ "./glTF/1.0/glTFLoader.ts":
  1688. /*!********************************!*\
  1689. !*** ./glTF/1.0/glTFLoader.ts ***!
  1690. \********************************/
  1691. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1692. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1693. "use strict";
  1694. __webpack_require__.r(__webpack_exports__);
  1695. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1696. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1697. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1698. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1699. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  1700. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  1701. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1702. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1703. /**
  1704. * Tokenizer. Used for shaders compatibility
  1705. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1706. */
  1707. var ETokenType;
  1708. (function (ETokenType) {
  1709. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1710. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1711. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1712. })(ETokenType || (ETokenType = {}));
  1713. var Tokenizer = /** @class */ (function () {
  1714. function Tokenizer(toParse) {
  1715. this._pos = 0;
  1716. this.currentToken = ETokenType.UNKNOWN;
  1717. this.currentIdentifier = "";
  1718. this.currentString = "";
  1719. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1720. this._toParse = toParse;
  1721. this._maxPos = toParse.length;
  1722. }
  1723. Tokenizer.prototype.getNextToken = function () {
  1724. if (this.isEnd()) {
  1725. return ETokenType.END_OF_INPUT;
  1726. }
  1727. this.currentString = this.read();
  1728. this.currentToken = ETokenType.UNKNOWN;
  1729. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1730. this.currentToken = ETokenType.IDENTIFIER;
  1731. this.currentIdentifier = this.currentString;
  1732. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1733. this.currentIdentifier += this.currentString;
  1734. this.forward();
  1735. }
  1736. }
  1737. return this.currentToken;
  1738. };
  1739. Tokenizer.prototype.peek = function () {
  1740. return this._toParse[this._pos];
  1741. };
  1742. Tokenizer.prototype.read = function () {
  1743. return this._toParse[this._pos++];
  1744. };
  1745. Tokenizer.prototype.forward = function () {
  1746. this._pos++;
  1747. };
  1748. Tokenizer.prototype.isEnd = function () {
  1749. return this._pos >= this._maxPos;
  1750. };
  1751. return Tokenizer;
  1752. }());
  1753. /**
  1754. * Values
  1755. */
  1756. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1757. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1758. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1759. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1760. /**
  1761. * Parse
  1762. */
  1763. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1764. for (var buf in parsedBuffers) {
  1765. var parsedBuffer = parsedBuffers[buf];
  1766. gltfRuntime.buffers[buf] = parsedBuffer;
  1767. gltfRuntime.buffersCount++;
  1768. }
  1769. };
  1770. var parseShaders = function (parsedShaders, gltfRuntime) {
  1771. for (var sha in parsedShaders) {
  1772. var parsedShader = parsedShaders[sha];
  1773. gltfRuntime.shaders[sha] = parsedShader;
  1774. gltfRuntime.shaderscount++;
  1775. }
  1776. };
  1777. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1778. for (var object in parsedObjects) {
  1779. var parsedObject = parsedObjects[object];
  1780. gltfRuntime[runtimeProperty][object] = parsedObject;
  1781. }
  1782. };
  1783. /**
  1784. * Utils
  1785. */
  1786. var normalizeUVs = function (buffer) {
  1787. if (!buffer) {
  1788. return;
  1789. }
  1790. for (var i = 0; i < buffer.length / 2; i++) {
  1791. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1792. }
  1793. };
  1794. var getAttribute = function (attributeParameter) {
  1795. if (attributeParameter.semantic === "NORMAL") {
  1796. return "normal";
  1797. }
  1798. else if (attributeParameter.semantic === "POSITION") {
  1799. return "position";
  1800. }
  1801. else if (attributeParameter.semantic === "JOINT") {
  1802. return "matricesIndices";
  1803. }
  1804. else if (attributeParameter.semantic === "WEIGHT") {
  1805. return "matricesWeights";
  1806. }
  1807. else if (attributeParameter.semantic === "COLOR") {
  1808. return "color";
  1809. }
  1810. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1811. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1812. return "uv" + (channel === 0 ? "" : channel + 1);
  1813. }
  1814. return null;
  1815. };
  1816. /**
  1817. * Loads and creates animations
  1818. */
  1819. var loadAnimations = function (gltfRuntime) {
  1820. for (var anim in gltfRuntime.animations) {
  1821. var animation = gltfRuntime.animations[anim];
  1822. if (!animation.channels || !animation.samplers) {
  1823. continue;
  1824. }
  1825. var lastAnimation = null;
  1826. for (var i = 0; i < animation.channels.length; i++) {
  1827. // Get parameters and load buffers
  1828. var channel = animation.channels[i];
  1829. var sampler = animation.samplers[channel.sampler];
  1830. if (!sampler) {
  1831. continue;
  1832. }
  1833. var inputData = null;
  1834. var outputData = null;
  1835. if (animation.parameters) {
  1836. inputData = animation.parameters[sampler.input];
  1837. outputData = animation.parameters[sampler.output];
  1838. }
  1839. else {
  1840. inputData = sampler.input;
  1841. outputData = sampler.output;
  1842. }
  1843. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1844. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1845. var targetID = channel.target.id;
  1846. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1847. if (targetNode === null) {
  1848. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1849. }
  1850. if (targetNode === null) {
  1851. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1852. continue;
  1853. }
  1854. var isBone = targetNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1855. // Get target path (position, rotation or scaling)
  1856. var targetPath = channel.target.path;
  1857. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1858. if (targetPathIndex !== -1) {
  1859. targetPath = babylonAnimationPaths[targetPathIndex];
  1860. }
  1861. // Determine animation type
  1862. var animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1863. if (!isBone) {
  1864. if (targetPath === "rotationQuaternion") {
  1865. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1866. targetNode.rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1867. }
  1868. else {
  1869. animationType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1870. }
  1871. }
  1872. // Create animation and key frames
  1873. var babylonAnimation = null;
  1874. var keys = [];
  1875. var arrayOffset = 0;
  1876. var modifyKey = false;
  1877. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1878. babylonAnimation = lastAnimation;
  1879. modifyKey = true;
  1880. }
  1881. if (!modifyKey) {
  1882. 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);
  1883. }
  1884. // For each frame
  1885. for (var j = 0; j < bufferInput.length; j++) {
  1886. var value = null;
  1887. if (targetPath === "rotationQuaternion") { // VEC4
  1888. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1889. arrayOffset += 4;
  1890. }
  1891. else { // Position and scaling are VEC3
  1892. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1893. arrayOffset += 3;
  1894. }
  1895. if (isBone) {
  1896. var bone = targetNode;
  1897. var translation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1898. var rotationQuaternion = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1899. var scaling = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1900. // Warning on decompose
  1901. var mat = bone.getBaseMatrix();
  1902. if (modifyKey && lastAnimation) {
  1903. mat = lastAnimation.getKeys()[j].value;
  1904. }
  1905. mat.decompose(scaling, rotationQuaternion, translation);
  1906. if (targetPath === "position") {
  1907. translation = value;
  1908. }
  1909. else if (targetPath === "rotationQuaternion") {
  1910. rotationQuaternion = value;
  1911. }
  1912. else {
  1913. scaling = value;
  1914. }
  1915. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1916. }
  1917. if (!modifyKey) {
  1918. keys.push({
  1919. frame: bufferInput[j],
  1920. value: value
  1921. });
  1922. }
  1923. else if (lastAnimation) {
  1924. lastAnimation.getKeys()[j].value = value;
  1925. }
  1926. }
  1927. // Finish
  1928. if (!modifyKey && babylonAnimation) {
  1929. babylonAnimation.setKeys(keys);
  1930. targetNode.animations.push(babylonAnimation);
  1931. }
  1932. lastAnimation = babylonAnimation;
  1933. gltfRuntime.scene.stopAnimation(targetNode);
  1934. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  1935. }
  1936. }
  1937. };
  1938. /**
  1939. * Returns the bones transformation matrix
  1940. */
  1941. var configureBoneTransformation = function (node) {
  1942. var mat = null;
  1943. if (node.translation || node.rotation || node.scale) {
  1944. var scale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  1945. var rotation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  1946. var position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  1947. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  1948. }
  1949. else {
  1950. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1951. }
  1952. return mat;
  1953. };
  1954. /**
  1955. * Returns the parent bone
  1956. */
  1957. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  1958. // Try to find
  1959. for (var i = 0; i < newSkeleton.bones.length; i++) {
  1960. if (newSkeleton.bones[i].name === jointName) {
  1961. return newSkeleton.bones[i];
  1962. }
  1963. }
  1964. // Not found, search in gltf nodes
  1965. var nodes = gltfRuntime.nodes;
  1966. for (var nde in nodes) {
  1967. var node = nodes[nde];
  1968. if (!node.jointName) {
  1969. continue;
  1970. }
  1971. var children = node.children;
  1972. for (var i = 0; i < children.length; i++) {
  1973. var child = gltfRuntime.nodes[children[i]];
  1974. if (!child.jointName) {
  1975. continue;
  1976. }
  1977. if (child.jointName === jointName) {
  1978. var mat = configureBoneTransformation(node);
  1979. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  1980. bone.id = nde;
  1981. return bone;
  1982. }
  1983. }
  1984. }
  1985. return null;
  1986. };
  1987. /**
  1988. * Returns the appropriate root node
  1989. */
  1990. var getNodeToRoot = function (nodesToRoot, id) {
  1991. for (var i = 0; i < nodesToRoot.length; i++) {
  1992. var nodeToRoot = nodesToRoot[i];
  1993. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  1994. var child = nodeToRoot.node.children[j];
  1995. if (child === id) {
  1996. return nodeToRoot.bone;
  1997. }
  1998. }
  1999. }
  2000. return null;
  2001. };
  2002. /**
  2003. * Returns the node with the joint name
  2004. */
  2005. var getJointNode = function (gltfRuntime, jointName) {
  2006. var nodes = gltfRuntime.nodes;
  2007. var node = nodes[jointName];
  2008. if (node) {
  2009. return {
  2010. node: node,
  2011. id: jointName
  2012. };
  2013. }
  2014. for (var nde in nodes) {
  2015. node = nodes[nde];
  2016. if (node.jointName === jointName) {
  2017. return {
  2018. node: node,
  2019. id: nde
  2020. };
  2021. }
  2022. }
  2023. return null;
  2024. };
  2025. /**
  2026. * Checks if a nodes is in joints
  2027. */
  2028. var nodeIsInJoints = function (skins, id) {
  2029. for (var i = 0; i < skins.jointNames.length; i++) {
  2030. if (skins.jointNames[i] === id) {
  2031. return true;
  2032. }
  2033. }
  2034. return false;
  2035. };
  2036. /**
  2037. * Fills the nodes to root for bones and builds hierarchy
  2038. */
  2039. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2040. // Creates nodes for root
  2041. for (var nde in gltfRuntime.nodes) {
  2042. var node = gltfRuntime.nodes[nde];
  2043. var id = nde;
  2044. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2045. continue;
  2046. }
  2047. // Create node to root bone
  2048. var mat = configureBoneTransformation(node);
  2049. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2050. bone.id = id;
  2051. nodesToRoot.push({ bone: bone, node: node, id: id });
  2052. }
  2053. // Parenting
  2054. for (var i = 0; i < nodesToRoot.length; i++) {
  2055. var nodeToRoot = nodesToRoot[i];
  2056. var children = nodeToRoot.node.children;
  2057. for (var j = 0; j < children.length; j++) {
  2058. var child = null;
  2059. for (var k = 0; k < nodesToRoot.length; k++) {
  2060. if (nodesToRoot[k].id === children[j]) {
  2061. child = nodesToRoot[k];
  2062. break;
  2063. }
  2064. }
  2065. if (child) {
  2066. child.bone._parent = nodeToRoot.bone;
  2067. nodeToRoot.bone.children.push(child.bone);
  2068. }
  2069. }
  2070. }
  2071. };
  2072. /**
  2073. * Imports a skeleton
  2074. */
  2075. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2076. if (!newSkeleton) {
  2077. newSkeleton = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2078. }
  2079. if (!skins.babylonSkeleton) {
  2080. return newSkeleton;
  2081. }
  2082. // Find the root bones
  2083. var nodesToRoot = [];
  2084. var nodesToRootToAdd = [];
  2085. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2086. newSkeleton.bones = [];
  2087. // Joints
  2088. for (var i = 0; i < skins.jointNames.length; i++) {
  2089. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2090. if (!jointNode) {
  2091. continue;
  2092. }
  2093. var node = jointNode.node;
  2094. if (!node) {
  2095. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2096. continue;
  2097. }
  2098. var id = jointNode.id;
  2099. // Optimize, if the bone already exists...
  2100. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2101. if (existingBone) {
  2102. newSkeleton.bones.push(existingBone);
  2103. continue;
  2104. }
  2105. // Search for parent bone
  2106. var foundBone = false;
  2107. var parentBone = null;
  2108. for (var j = 0; j < i; j++) {
  2109. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2110. if (!jointNode_1) {
  2111. continue;
  2112. }
  2113. var joint = jointNode_1.node;
  2114. if (!joint) {
  2115. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2116. continue;
  2117. }
  2118. var children = joint.children;
  2119. if (!children) {
  2120. continue;
  2121. }
  2122. foundBone = false;
  2123. for (var k = 0; k < children.length; k++) {
  2124. if (children[k] === id) {
  2125. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2126. foundBone = true;
  2127. break;
  2128. }
  2129. }
  2130. if (foundBone) {
  2131. break;
  2132. }
  2133. }
  2134. // Create bone
  2135. var mat = configureBoneTransformation(node);
  2136. if (!parentBone && nodesToRoot.length > 0) {
  2137. parentBone = getNodeToRoot(nodesToRoot, id);
  2138. if (parentBone) {
  2139. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2140. nodesToRootToAdd.push(parentBone);
  2141. }
  2142. }
  2143. }
  2144. var bone = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2145. bone.id = id;
  2146. }
  2147. // Polish
  2148. var bones = newSkeleton.bones;
  2149. newSkeleton.bones = [];
  2150. for (var i = 0; i < skins.jointNames.length; i++) {
  2151. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2152. if (!jointNode) {
  2153. continue;
  2154. }
  2155. for (var j = 0; j < bones.length; j++) {
  2156. if (bones[j].id === jointNode.id) {
  2157. newSkeleton.bones.push(bones[j]);
  2158. break;
  2159. }
  2160. }
  2161. }
  2162. newSkeleton.prepare();
  2163. // Finish
  2164. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2165. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2166. }
  2167. return newSkeleton;
  2168. };
  2169. /**
  2170. * Imports a mesh and its geometries
  2171. */
  2172. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2173. if (!newMesh) {
  2174. newMesh = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2175. newMesh.id = id;
  2176. }
  2177. if (!node.babylonNode) {
  2178. return newMesh;
  2179. }
  2180. var subMaterials = [];
  2181. var vertexData = null;
  2182. var verticesStarts = new Array();
  2183. var verticesCounts = new Array();
  2184. var indexStarts = new Array();
  2185. var indexCounts = new Array();
  2186. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2187. var meshID = meshes[meshIndex];
  2188. var mesh = gltfRuntime.meshes[meshID];
  2189. if (!mesh) {
  2190. continue;
  2191. }
  2192. // Positions, normals and UVs
  2193. for (var i = 0; i < mesh.primitives.length; i++) {
  2194. // Temporary vertex data
  2195. var tempVertexData = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2196. var primitive = mesh.primitives[i];
  2197. if (primitive.mode !== 4) {
  2198. // continue;
  2199. }
  2200. var attributes = primitive.attributes;
  2201. var accessor = null;
  2202. var buffer = null;
  2203. // Set positions, normal and uvs
  2204. for (var semantic in attributes) {
  2205. // Link accessor and buffer view
  2206. accessor = gltfRuntime.accessors[attributes[semantic]];
  2207. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2208. if (semantic === "NORMAL") {
  2209. tempVertexData.normals = new Float32Array(buffer.length);
  2210. tempVertexData.normals.set(buffer);
  2211. }
  2212. else if (semantic === "POSITION") {
  2213. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2214. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2215. for (var j = 0; j < buffer.length; j += 4) {
  2216. tempVertexData.positions[j] = buffer[j];
  2217. tempVertexData.positions[j + 1] = buffer[j + 1];
  2218. tempVertexData.positions[j + 2] = buffer[j + 2];
  2219. }
  2220. }
  2221. else {
  2222. tempVertexData.positions = new Float32Array(buffer.length);
  2223. tempVertexData.positions.set(buffer);
  2224. }
  2225. verticesCounts.push(tempVertexData.positions.length);
  2226. }
  2227. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2228. var channel = Number(semantic.split("_")[1]);
  2229. var uvKind = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2230. var uvs = new Float32Array(buffer.length);
  2231. uvs.set(buffer);
  2232. normalizeUVs(uvs);
  2233. tempVertexData.set(uvs, uvKind);
  2234. }
  2235. else if (semantic === "JOINT") {
  2236. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2237. tempVertexData.matricesIndices.set(buffer);
  2238. }
  2239. else if (semantic === "WEIGHT") {
  2240. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2241. tempVertexData.matricesWeights.set(buffer);
  2242. }
  2243. else if (semantic === "COLOR") {
  2244. tempVertexData.colors = new Float32Array(buffer.length);
  2245. tempVertexData.colors.set(buffer);
  2246. }
  2247. }
  2248. // Indices
  2249. accessor = gltfRuntime.accessors[primitive.indices];
  2250. if (accessor) {
  2251. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2252. tempVertexData.indices = new Int32Array(buffer.length);
  2253. tempVertexData.indices.set(buffer);
  2254. indexCounts.push(tempVertexData.indices.length);
  2255. }
  2256. else {
  2257. // Set indices on the fly
  2258. var indices = [];
  2259. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2260. indices.push(j);
  2261. }
  2262. tempVertexData.indices = new Int32Array(indices);
  2263. indexCounts.push(tempVertexData.indices.length);
  2264. }
  2265. if (!vertexData) {
  2266. vertexData = tempVertexData;
  2267. }
  2268. else {
  2269. vertexData.merge(tempVertexData);
  2270. }
  2271. // Sub material
  2272. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2273. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2274. // Update vertices start and index start
  2275. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2276. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2277. }
  2278. }
  2279. var material;
  2280. if (subMaterials.length > 1) {
  2281. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2282. material.subMaterials = subMaterials;
  2283. }
  2284. else {
  2285. material = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2286. }
  2287. if (subMaterials.length === 1) {
  2288. material = subMaterials[0];
  2289. }
  2290. if (!newMesh.material) {
  2291. newMesh.material = material;
  2292. }
  2293. // Apply geometry
  2294. new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2295. newMesh.computeWorldMatrix(true);
  2296. // Apply submeshes
  2297. newMesh.subMeshes = [];
  2298. var index = 0;
  2299. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2300. var meshID = meshes[meshIndex];
  2301. var mesh = gltfRuntime.meshes[meshID];
  2302. if (!mesh) {
  2303. continue;
  2304. }
  2305. for (var i = 0; i < mesh.primitives.length; i++) {
  2306. if (mesh.primitives[i].mode !== 4) {
  2307. //continue;
  2308. }
  2309. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2310. index++;
  2311. }
  2312. }
  2313. // Finish
  2314. return newMesh;
  2315. };
  2316. /**
  2317. * Configure node transformation from position, rotation and scaling
  2318. */
  2319. var configureNode = function (newNode, position, rotation, scaling) {
  2320. if (newNode.position) {
  2321. newNode.position = position;
  2322. }
  2323. if (newNode.rotationQuaternion || newNode.rotation) {
  2324. newNode.rotationQuaternion = rotation;
  2325. }
  2326. if (newNode.scaling) {
  2327. newNode.scaling = scaling;
  2328. }
  2329. };
  2330. /**
  2331. * Configures node from transformation matrix
  2332. */
  2333. var configureNodeFromMatrix = function (newNode, node, parent) {
  2334. if (node.matrix) {
  2335. var position = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2336. var rotation = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2337. var scaling = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2338. var mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2339. mat.decompose(scaling, rotation, position);
  2340. configureNode(newNode, position, rotation, scaling);
  2341. }
  2342. else if (node.translation && node.rotation && node.scale) {
  2343. 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));
  2344. }
  2345. newNode.computeWorldMatrix(true);
  2346. };
  2347. /**
  2348. * Imports a node
  2349. */
  2350. var importNode = function (gltfRuntime, node, id, parent) {
  2351. var lastNode = null;
  2352. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2353. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2354. return null;
  2355. }
  2356. }
  2357. // Meshes
  2358. if (node.skin) {
  2359. if (node.meshes) {
  2360. var skin = gltfRuntime.skins[node.skin];
  2361. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2362. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2363. if (newMesh.skeleton === null) {
  2364. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2365. if (!skin.babylonSkeleton) {
  2366. skin.babylonSkeleton = newMesh.skeleton;
  2367. }
  2368. }
  2369. lastNode = newMesh;
  2370. }
  2371. }
  2372. else if (node.meshes) {
  2373. /**
  2374. * Improve meshes property
  2375. */
  2376. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2377. lastNode = newMesh;
  2378. }
  2379. // Lights
  2380. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2381. var light = gltfRuntime.lights[node.light];
  2382. if (light) {
  2383. if (light.type === "ambient") {
  2384. var ambienLight = light[light.type];
  2385. var hemiLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["HemisphericLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2386. hemiLight.name = node.name || "";
  2387. if (ambienLight.color) {
  2388. hemiLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2389. }
  2390. lastNode = hemiLight;
  2391. }
  2392. else if (light.type === "directional") {
  2393. var directionalLight = light[light.type];
  2394. var dirLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["DirectionalLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2395. dirLight.name = node.name || "";
  2396. if (directionalLight.color) {
  2397. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2398. }
  2399. lastNode = dirLight;
  2400. }
  2401. else if (light.type === "point") {
  2402. var pointLight = light[light.type];
  2403. var ptLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["PointLight"](node.light, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), gltfRuntime.scene);
  2404. ptLight.name = node.name || "";
  2405. if (pointLight.color) {
  2406. ptLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2407. }
  2408. lastNode = ptLight;
  2409. }
  2410. else if (light.type === "spot") {
  2411. var spotLight = light[light.type];
  2412. 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);
  2413. spLight.name = node.name || "";
  2414. if (spotLight.color) {
  2415. spLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2416. }
  2417. if (spotLight.fallOfAngle) {
  2418. spLight.angle = spotLight.fallOfAngle;
  2419. }
  2420. if (spotLight.fallOffExponent) {
  2421. spLight.exponent = spotLight.fallOffExponent;
  2422. }
  2423. lastNode = spLight;
  2424. }
  2425. }
  2426. }
  2427. // Cameras
  2428. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2429. var camera = gltfRuntime.cameras[node.camera];
  2430. if (camera) {
  2431. if (camera.type === "orthographic") {
  2432. 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);
  2433. orthoCamera.name = node.name || "";
  2434. orthoCamera.mode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2435. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2436. lastNode = orthoCamera;
  2437. }
  2438. else if (camera.type === "perspective") {
  2439. var perspectiveCamera = camera[camera.type];
  2440. 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);
  2441. persCamera.name = node.name || "";
  2442. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2443. if (!perspectiveCamera.aspectRatio) {
  2444. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2445. }
  2446. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2447. persCamera.maxZ = perspectiveCamera.zfar;
  2448. persCamera.minZ = perspectiveCamera.znear;
  2449. }
  2450. lastNode = persCamera;
  2451. }
  2452. }
  2453. }
  2454. // Empty node
  2455. if (!node.jointName) {
  2456. if (node.babylonNode) {
  2457. return node.babylonNode;
  2458. }
  2459. else if (lastNode === null) {
  2460. var dummy = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2461. node.babylonNode = dummy;
  2462. lastNode = dummy;
  2463. }
  2464. }
  2465. if (lastNode !== null) {
  2466. if (node.matrix && lastNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2467. configureNodeFromMatrix(lastNode, node, parent);
  2468. }
  2469. else {
  2470. var translation = node.translation || [0, 0, 0];
  2471. var rotation = node.rotation || [0, 0, 0, 1];
  2472. var scale = node.scale || [1, 1, 1];
  2473. 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));
  2474. }
  2475. lastNode.updateCache(true);
  2476. node.babylonNode = lastNode;
  2477. }
  2478. return lastNode;
  2479. };
  2480. /**
  2481. * Traverses nodes and creates them
  2482. */
  2483. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2484. if (meshIncluded === void 0) { meshIncluded = false; }
  2485. var node = gltfRuntime.nodes[id];
  2486. var newNode = null;
  2487. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2488. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2489. meshIncluded = true;
  2490. }
  2491. else {
  2492. meshIncluded = false;
  2493. }
  2494. }
  2495. else {
  2496. meshIncluded = true;
  2497. }
  2498. if (!node.jointName && meshIncluded) {
  2499. newNode = importNode(gltfRuntime, node, id, parent);
  2500. if (newNode !== null) {
  2501. newNode.id = id;
  2502. newNode.parent = parent;
  2503. }
  2504. }
  2505. if (node.children) {
  2506. for (var i = 0; i < node.children.length; i++) {
  2507. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2508. }
  2509. }
  2510. };
  2511. /**
  2512. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2513. */
  2514. var postLoad = function (gltfRuntime) {
  2515. // Nodes
  2516. var currentScene = gltfRuntime.currentScene;
  2517. if (currentScene) {
  2518. for (var i = 0; i < currentScene.nodes.length; i++) {
  2519. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2520. }
  2521. }
  2522. else {
  2523. for (var thing in gltfRuntime.scenes) {
  2524. currentScene = gltfRuntime.scenes[thing];
  2525. for (var i = 0; i < currentScene.nodes.length; i++) {
  2526. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2527. }
  2528. }
  2529. }
  2530. // Set animations
  2531. loadAnimations(gltfRuntime);
  2532. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2533. var skeleton = gltfRuntime.scene.skeletons[i];
  2534. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2535. }
  2536. };
  2537. /**
  2538. * onBind shaderrs callback to set uniforms and matrices
  2539. */
  2540. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2541. var materialValues = material.values || technique.parameters;
  2542. for (var unif in unTreatedUniforms) {
  2543. var uniform = unTreatedUniforms[unif];
  2544. var type = uniform.type;
  2545. 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) {
  2546. if (uniform.semantic && !uniform.source && !uniform.node) {
  2547. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2548. }
  2549. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2550. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2551. if (source === null) {
  2552. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2553. }
  2554. if (source === null) {
  2555. continue;
  2556. }
  2557. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2558. }
  2559. }
  2560. else {
  2561. var value = materialValues[technique.uniforms[unif]];
  2562. if (!value) {
  2563. continue;
  2564. }
  2565. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2566. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2567. if (texture === null || texture === undefined) {
  2568. continue;
  2569. }
  2570. shaderMaterial.getEffect().setTexture(unif, texture);
  2571. }
  2572. else {
  2573. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2574. }
  2575. }
  2576. }
  2577. onSuccess(shaderMaterial);
  2578. };
  2579. /**
  2580. * Prepare uniforms to send the only one time
  2581. * Loads the appropriate textures
  2582. */
  2583. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2584. var materialValues = material.values || technique.parameters;
  2585. var techniqueUniforms = technique.uniforms;
  2586. /**
  2587. * Prepare values here (not matrices)
  2588. */
  2589. for (var unif in unTreatedUniforms) {
  2590. var uniform = unTreatedUniforms[unif];
  2591. var type = uniform.type;
  2592. var value = materialValues[techniqueUniforms[unif]];
  2593. if (value === undefined) {
  2594. // In case the value is the same for all materials
  2595. value = uniform.value;
  2596. }
  2597. if (!value) {
  2598. continue;
  2599. }
  2600. var onLoadTexture = function (uniformName) {
  2601. return function (texture) {
  2602. if (uniform.value && uniformName) {
  2603. // Static uniform
  2604. shaderMaterial.setTexture(uniformName, texture);
  2605. delete unTreatedUniforms[uniformName];
  2606. }
  2607. };
  2608. };
  2609. // Texture (sampler2D)
  2610. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2611. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2612. }
  2613. // Others
  2614. else {
  2615. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2616. // Static uniform
  2617. delete unTreatedUniforms[unif];
  2618. }
  2619. }
  2620. }
  2621. };
  2622. /**
  2623. * Shader compilation failed
  2624. */
  2625. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2626. return function (effect, error) {
  2627. shaderMaterial.dispose(true);
  2628. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2629. };
  2630. };
  2631. /**
  2632. * Shader compilation success
  2633. */
  2634. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2635. return function (_) {
  2636. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2637. shaderMaterial.onBind = function (mesh) {
  2638. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2639. };
  2640. };
  2641. };
  2642. /**
  2643. * Returns the appropriate uniform if already handled by babylon
  2644. */
  2645. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2646. for (var unif in technique.uniforms) {
  2647. var uniform = technique.uniforms[unif];
  2648. var uniformParameter = technique.parameters[uniform];
  2649. if (tokenizer.currentIdentifier === unif) {
  2650. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2651. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2652. if (transformIndex !== -1) {
  2653. delete unTreatedUniforms[unif];
  2654. return babylonTransforms[transformIndex];
  2655. }
  2656. }
  2657. }
  2658. }
  2659. return tokenizer.currentIdentifier;
  2660. };
  2661. /**
  2662. * All shaders loaded. Create materials one by one
  2663. */
  2664. var importMaterials = function (gltfRuntime) {
  2665. // Create materials
  2666. for (var mat in gltfRuntime.materials) {
  2667. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2668. }
  2669. };
  2670. /**
  2671. * Implementation of the base glTF spec
  2672. * @hidden
  2673. */
  2674. var GLTFLoaderBase = /** @class */ (function () {
  2675. function GLTFLoaderBase() {
  2676. }
  2677. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2678. var gltfRuntime = {
  2679. extensions: {},
  2680. accessors: {},
  2681. buffers: {},
  2682. bufferViews: {},
  2683. meshes: {},
  2684. lights: {},
  2685. cameras: {},
  2686. nodes: {},
  2687. images: {},
  2688. textures: {},
  2689. shaders: {},
  2690. programs: {},
  2691. samplers: {},
  2692. techniques: {},
  2693. materials: {},
  2694. animations: {},
  2695. skins: {},
  2696. extensionsUsed: [],
  2697. scenes: {},
  2698. buffersCount: 0,
  2699. shaderscount: 0,
  2700. scene: scene,
  2701. rootUrl: rootUrl,
  2702. loadedBufferCount: 0,
  2703. loadedBufferViews: {},
  2704. loadedShaderCount: 0,
  2705. importOnlyMeshes: false,
  2706. dummyNodes: []
  2707. };
  2708. // Parse
  2709. if (parsedData.extensions) {
  2710. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2711. }
  2712. if (parsedData.extensionsUsed) {
  2713. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2714. }
  2715. if (parsedData.buffers) {
  2716. parseBuffers(parsedData.buffers, gltfRuntime);
  2717. }
  2718. if (parsedData.bufferViews) {
  2719. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2720. }
  2721. if (parsedData.accessors) {
  2722. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2723. }
  2724. if (parsedData.meshes) {
  2725. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2726. }
  2727. if (parsedData.lights) {
  2728. parseObject(parsedData.lights, "lights", gltfRuntime);
  2729. }
  2730. if (parsedData.cameras) {
  2731. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2732. }
  2733. if (parsedData.nodes) {
  2734. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2735. }
  2736. if (parsedData.images) {
  2737. parseObject(parsedData.images, "images", gltfRuntime);
  2738. }
  2739. if (parsedData.textures) {
  2740. parseObject(parsedData.textures, "textures", gltfRuntime);
  2741. }
  2742. if (parsedData.shaders) {
  2743. parseShaders(parsedData.shaders, gltfRuntime);
  2744. }
  2745. if (parsedData.programs) {
  2746. parseObject(parsedData.programs, "programs", gltfRuntime);
  2747. }
  2748. if (parsedData.samplers) {
  2749. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2750. }
  2751. if (parsedData.techniques) {
  2752. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2753. }
  2754. if (parsedData.materials) {
  2755. parseObject(parsedData.materials, "materials", gltfRuntime);
  2756. }
  2757. if (parsedData.animations) {
  2758. parseObject(parsedData.animations, "animations", gltfRuntime);
  2759. }
  2760. if (parsedData.skins) {
  2761. parseObject(parsedData.skins, "skins", gltfRuntime);
  2762. }
  2763. if (parsedData.scenes) {
  2764. gltfRuntime.scenes = parsedData.scenes;
  2765. }
  2766. if (parsedData.scene && parsedData.scenes) {
  2767. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2768. }
  2769. return gltfRuntime;
  2770. };
  2771. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2772. var buffer = gltfRuntime.buffers[id];
  2773. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2774. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2775. }
  2776. else {
  2777. 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) {
  2778. if (request) {
  2779. onError(request.status + " " + request.statusText);
  2780. }
  2781. });
  2782. }
  2783. };
  2784. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2785. var texture = gltfRuntime.textures[id];
  2786. if (!texture || !texture.source) {
  2787. onError("");
  2788. return;
  2789. }
  2790. if (texture.babylonTexture) {
  2791. onSuccess(null);
  2792. return;
  2793. }
  2794. var source = gltfRuntime.images[texture.source];
  2795. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2796. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2797. }
  2798. else {
  2799. 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) {
  2800. if (request) {
  2801. onError(request.status + " " + request.statusText);
  2802. }
  2803. });
  2804. }
  2805. };
  2806. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2807. var texture = gltfRuntime.textures[id];
  2808. if (texture.babylonTexture) {
  2809. onSuccess(texture.babylonTexture);
  2810. return;
  2811. }
  2812. var sampler = gltfRuntime.samplers[texture.sampler];
  2813. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2814. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2815. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2816. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2817. var samplingMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2818. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2819. var blobURL = URL.createObjectURL(blob);
  2820. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2821. var newTexture = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2822. if (sampler.wrapS !== undefined) {
  2823. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2824. }
  2825. if (sampler.wrapT !== undefined) {
  2826. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2827. }
  2828. newTexture.name = id;
  2829. texture.babylonTexture = newTexture;
  2830. onSuccess(newTexture);
  2831. };
  2832. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2833. var shader = gltfRuntime.shaders[id];
  2834. if (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2835. var shaderString = atob(shader.uri.split(",")[1]);
  2836. if (onSuccess) {
  2837. onSuccess(shaderString);
  2838. }
  2839. }
  2840. else {
  2841. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2842. if (request && onError) {
  2843. onError(request.status + " " + request.statusText);
  2844. }
  2845. });
  2846. }
  2847. };
  2848. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2849. var material = gltfRuntime.materials[id];
  2850. if (!material.technique) {
  2851. if (onError) {
  2852. onError("No technique found.");
  2853. }
  2854. return;
  2855. }
  2856. var technique = gltfRuntime.techniques[material.technique];
  2857. if (!technique) {
  2858. var defaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2859. defaultMaterial.diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2860. defaultMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2861. onSuccess(defaultMaterial);
  2862. return;
  2863. }
  2864. var program = gltfRuntime.programs[technique.program];
  2865. var states = technique.states;
  2866. var vertexShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2867. var pixelShader = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2868. var newVertexShader = "";
  2869. var newPixelShader = "";
  2870. var vertexTokenizer = new Tokenizer(vertexShader);
  2871. var pixelTokenizer = new Tokenizer(pixelShader);
  2872. var unTreatedUniforms = {};
  2873. var uniforms = [];
  2874. var attributes = [];
  2875. var samplers = [];
  2876. // Fill uniform, sampler2D and attributes
  2877. for (var unif in technique.uniforms) {
  2878. var uniform = technique.uniforms[unif];
  2879. var uniformParameter = technique.parameters[uniform];
  2880. unTreatedUniforms[unif] = uniformParameter;
  2881. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2882. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2883. if (transformIndex !== -1) {
  2884. uniforms.push(babylonTransforms[transformIndex]);
  2885. delete unTreatedUniforms[unif];
  2886. }
  2887. else {
  2888. uniforms.push(unif);
  2889. }
  2890. }
  2891. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2892. samplers.push(unif);
  2893. }
  2894. else {
  2895. uniforms.push(unif);
  2896. }
  2897. }
  2898. for (var attr in technique.attributes) {
  2899. var attribute = technique.attributes[attr];
  2900. var attributeParameter = technique.parameters[attribute];
  2901. if (attributeParameter.semantic) {
  2902. var name_1 = getAttribute(attributeParameter);
  2903. if (name_1) {
  2904. attributes.push(name_1);
  2905. }
  2906. }
  2907. }
  2908. // Configure vertex shader
  2909. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2910. var tokenType = vertexTokenizer.currentToken;
  2911. if (tokenType !== ETokenType.IDENTIFIER) {
  2912. newVertexShader += vertexTokenizer.currentString;
  2913. continue;
  2914. }
  2915. var foundAttribute = false;
  2916. for (var attr in technique.attributes) {
  2917. var attribute = technique.attributes[attr];
  2918. var attributeParameter = technique.parameters[attribute];
  2919. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  2920. newVertexShader += getAttribute(attributeParameter);
  2921. foundAttribute = true;
  2922. break;
  2923. }
  2924. }
  2925. if (foundAttribute) {
  2926. continue;
  2927. }
  2928. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  2929. }
  2930. // Configure pixel shader
  2931. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  2932. var tokenType = pixelTokenizer.currentToken;
  2933. if (tokenType !== ETokenType.IDENTIFIER) {
  2934. newPixelShader += pixelTokenizer.currentString;
  2935. continue;
  2936. }
  2937. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  2938. }
  2939. // Create shader material
  2940. var shaderPath = {
  2941. vertex: program.vertexShader + id,
  2942. fragment: program.fragmentShader + id
  2943. };
  2944. var options = {
  2945. attributes: attributes,
  2946. uniforms: uniforms,
  2947. samplers: samplers,
  2948. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  2949. };
  2950. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  2951. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  2952. var shaderMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  2953. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  2954. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  2955. shaderMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2956. if (states && states.functions) {
  2957. var functions = states.functions;
  2958. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  2959. shaderMaterial.backFaceCulling = false;
  2960. }
  2961. var blendFunc = functions.blendFuncSeparate;
  2962. if (blendFunc) {
  2963. 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) {
  2964. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  2965. }
  2966. 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) {
  2967. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  2968. }
  2969. 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) {
  2970. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  2971. }
  2972. 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) {
  2973. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  2974. }
  2975. 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) {
  2976. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  2977. }
  2978. 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) {
  2979. shaderMaterial.alphaMode = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  2980. }
  2981. }
  2982. }
  2983. };
  2984. return GLTFLoaderBase;
  2985. }());
  2986. /**
  2987. * glTF V1 Loader
  2988. * @hidden
  2989. */
  2990. var GLTFLoader = /** @class */ (function () {
  2991. function GLTFLoader() {
  2992. this.state = null;
  2993. }
  2994. GLTFLoader.RegisterExtension = function (extension) {
  2995. if (GLTFLoader.Extensions[extension.name]) {
  2996. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  2997. return;
  2998. }
  2999. GLTFLoader.Extensions[extension.name] = extension;
  3000. };
  3001. GLTFLoader.prototype.dispose = function () {
  3002. // do nothing
  3003. };
  3004. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, onSuccess, onProgress, onError) {
  3005. var _this = this;
  3006. scene.useRightHandedSystem = true;
  3007. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3008. gltfRuntime.importOnlyMeshes = true;
  3009. if (meshesNames === "") {
  3010. gltfRuntime.importMeshesNames = [];
  3011. }
  3012. else if (typeof meshesNames === "string") {
  3013. gltfRuntime.importMeshesNames = [meshesNames];
  3014. }
  3015. else if (meshesNames && !(meshesNames instanceof Array)) {
  3016. gltfRuntime.importMeshesNames = [meshesNames];
  3017. }
  3018. else {
  3019. gltfRuntime.importMeshesNames = [];
  3020. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3021. }
  3022. // Create nodes
  3023. _this._createNodes(gltfRuntime);
  3024. var meshes = new Array();
  3025. var skeletons = new Array();
  3026. // Fill arrays of meshes and skeletons
  3027. for (var nde in gltfRuntime.nodes) {
  3028. var node = gltfRuntime.nodes[nde];
  3029. if (node.babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3030. meshes.push(node.babylonNode);
  3031. }
  3032. }
  3033. for (var skl in gltfRuntime.skins) {
  3034. var skin = gltfRuntime.skins[skl];
  3035. if (skin.babylonSkeleton instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3036. skeletons.push(skin.babylonSkeleton);
  3037. }
  3038. }
  3039. // Load buffers, shaders, materials, etc.
  3040. _this._loadBuffersAsync(gltfRuntime, function () {
  3041. _this._loadShadersAsync(gltfRuntime, function () {
  3042. importMaterials(gltfRuntime);
  3043. postLoad(gltfRuntime);
  3044. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3045. onSuccess(meshes, skeletons);
  3046. }
  3047. });
  3048. }, onProgress);
  3049. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3050. onSuccess(meshes, skeletons);
  3051. }
  3052. }, onError);
  3053. return true;
  3054. };
  3055. /**
  3056. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3057. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3058. * @param scene the scene the meshes should be added to
  3059. * @param data gltf data containing information of the meshes in a loaded file
  3060. * @param rootUrl root url to load from
  3061. * @param onProgress event that fires when loading progress has occured
  3062. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3063. */
  3064. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress) {
  3065. var _this = this;
  3066. return new Promise(function (resolve, reject) {
  3067. _this._importMeshAsync(meshesNames, scene, data, rootUrl, function (meshes, skeletons) {
  3068. resolve({
  3069. meshes: meshes,
  3070. particleSystems: [],
  3071. skeletons: skeletons,
  3072. animationGroups: []
  3073. });
  3074. }, onProgress, function (message) {
  3075. reject(new Error(message));
  3076. });
  3077. });
  3078. };
  3079. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, onSuccess, onProgress, onError) {
  3080. var _this = this;
  3081. scene.useRightHandedSystem = true;
  3082. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3083. // Load runtime extensios
  3084. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3085. // Create nodes
  3086. _this._createNodes(gltfRuntime);
  3087. // Load buffers, shaders, materials, etc.
  3088. _this._loadBuffersAsync(gltfRuntime, function () {
  3089. _this._loadShadersAsync(gltfRuntime, function () {
  3090. importMaterials(gltfRuntime);
  3091. postLoad(gltfRuntime);
  3092. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3093. onSuccess();
  3094. }
  3095. });
  3096. });
  3097. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3098. onSuccess();
  3099. }
  3100. }, onError);
  3101. }, onError);
  3102. };
  3103. /**
  3104. * Imports all objects from a loaded gltf file and adds them to the scene
  3105. * @param scene the scene the objects should be added to
  3106. * @param data gltf data containing information of the meshes in a loaded file
  3107. * @param rootUrl root url to load from
  3108. * @param onProgress event that fires when loading progress has occured
  3109. * @returns a promise which completes when objects have been loaded to the scene
  3110. */
  3111. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3112. var _this = this;
  3113. return new Promise(function (resolve, reject) {
  3114. _this._loadAsync(scene, data, rootUrl, function () {
  3115. resolve();
  3116. }, onProgress, function (message) {
  3117. reject(new Error(message));
  3118. });
  3119. });
  3120. };
  3121. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3122. var hasShaders = false;
  3123. var processShader = function (sha, shader) {
  3124. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3125. if (shaderString instanceof ArrayBuffer) {
  3126. return;
  3127. }
  3128. gltfRuntime.loadedShaderCount++;
  3129. if (shaderString) {
  3130. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3131. }
  3132. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3133. onload();
  3134. }
  3135. }, function () {
  3136. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3137. });
  3138. };
  3139. for (var sha in gltfRuntime.shaders) {
  3140. hasShaders = true;
  3141. var shader = gltfRuntime.shaders[sha];
  3142. if (shader) {
  3143. processShader.bind(this, sha, shader)();
  3144. }
  3145. else {
  3146. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3147. }
  3148. }
  3149. if (!hasShaders) {
  3150. onload();
  3151. }
  3152. };
  3153. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3154. var hasBuffers = false;
  3155. var processBuffer = function (buf, buffer) {
  3156. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3157. gltfRuntime.loadedBufferCount++;
  3158. if (bufferView) {
  3159. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3160. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3161. }
  3162. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3163. }
  3164. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3165. onLoad();
  3166. }
  3167. }, function () {
  3168. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3169. });
  3170. };
  3171. for (var buf in gltfRuntime.buffers) {
  3172. hasBuffers = true;
  3173. var buffer = gltfRuntime.buffers[buf];
  3174. if (buffer) {
  3175. processBuffer.bind(this, buf, buffer)();
  3176. }
  3177. else {
  3178. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3179. }
  3180. }
  3181. if (!hasBuffers) {
  3182. onLoad();
  3183. }
  3184. };
  3185. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3186. var currentScene = gltfRuntime.currentScene;
  3187. if (currentScene) {
  3188. // Only one scene even if multiple scenes are defined
  3189. for (var i = 0; i < currentScene.nodes.length; i++) {
  3190. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3191. }
  3192. }
  3193. else {
  3194. // Load all scenes
  3195. for (var thing in gltfRuntime.scenes) {
  3196. currentScene = gltfRuntime.scenes[thing];
  3197. for (var i = 0; i < currentScene.nodes.length; i++) {
  3198. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3199. }
  3200. }
  3201. }
  3202. };
  3203. GLTFLoader.Extensions = {};
  3204. return GLTFLoader;
  3205. }());
  3206. /** @hidden */
  3207. var GLTFLoaderExtension = /** @class */ (function () {
  3208. function GLTFLoaderExtension(name) {
  3209. this._name = name;
  3210. }
  3211. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3212. get: function () {
  3213. return this._name;
  3214. },
  3215. enumerable: true,
  3216. configurable: true
  3217. });
  3218. /**
  3219. * Defines an override for loading the runtime
  3220. * Return true to stop further extensions from loading the runtime
  3221. */
  3222. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3223. return false;
  3224. };
  3225. /**
  3226. * Defines an onverride for creating gltf runtime
  3227. * Return true to stop further extensions from creating the runtime
  3228. */
  3229. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3230. return false;
  3231. };
  3232. /**
  3233. * Defines an override for loading buffers
  3234. * Return true to stop further extensions from loading this buffer
  3235. */
  3236. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3237. return false;
  3238. };
  3239. /**
  3240. * Defines an override for loading texture buffers
  3241. * Return true to stop further extensions from loading this texture data
  3242. */
  3243. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3244. return false;
  3245. };
  3246. /**
  3247. * Defines an override for creating textures
  3248. * Return true to stop further extensions from loading this texture
  3249. */
  3250. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3251. return false;
  3252. };
  3253. /**
  3254. * Defines an override for loading shader strings
  3255. * Return true to stop further extensions from loading this shader data
  3256. */
  3257. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3258. return false;
  3259. };
  3260. /**
  3261. * Defines an override for loading materials
  3262. * Return true to stop further extensions from loading this material
  3263. */
  3264. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3265. return false;
  3266. };
  3267. // ---------
  3268. // Utilities
  3269. // ---------
  3270. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3271. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3272. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3273. }, function () {
  3274. setTimeout(function () {
  3275. if (!onSuccess) {
  3276. return;
  3277. }
  3278. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3279. });
  3280. });
  3281. };
  3282. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3283. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3284. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3285. }, function () {
  3286. setTimeout(function () {
  3287. onSuccess();
  3288. });
  3289. });
  3290. };
  3291. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3292. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3293. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3294. }, function () {
  3295. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3296. });
  3297. };
  3298. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3299. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3300. if (buffer) {
  3301. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3302. }
  3303. }, onError);
  3304. };
  3305. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3306. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3307. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3308. }, function () {
  3309. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3310. });
  3311. };
  3312. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3313. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3314. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3315. }, function () {
  3316. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3317. });
  3318. };
  3319. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3320. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3321. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3322. }, function () {
  3323. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3324. });
  3325. };
  3326. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3327. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3328. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3329. }, function () {
  3330. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3331. });
  3332. };
  3333. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3334. for (var extensionName in GLTFLoader.Extensions) {
  3335. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3336. if (func(loaderExtension)) {
  3337. return;
  3338. }
  3339. }
  3340. defaultFunc();
  3341. };
  3342. return GLTFLoaderExtension;
  3343. }());
  3344. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3345. /***/ }),
  3346. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3347. /*!******************************************!*\
  3348. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3349. \******************************************/
  3350. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3351. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3352. "use strict";
  3353. __webpack_require__.r(__webpack_exports__);
  3354. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3355. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3356. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3357. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3358. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3359. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3360. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3361. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3362. /**
  3363. * Enums
  3364. * @hidden
  3365. */
  3366. var EComponentType;
  3367. (function (EComponentType) {
  3368. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3369. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3370. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3371. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3372. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3373. })(EComponentType || (EComponentType = {}));
  3374. /** @hidden */
  3375. var EShaderType;
  3376. (function (EShaderType) {
  3377. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3378. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3379. })(EShaderType || (EShaderType = {}));
  3380. /** @hidden */
  3381. var EParameterType;
  3382. (function (EParameterType) {
  3383. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3384. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3385. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3386. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3387. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3388. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3389. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3390. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3391. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3392. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3393. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3394. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3395. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3396. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3397. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3398. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3399. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3400. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3401. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3402. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3403. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3404. })(EParameterType || (EParameterType = {}));
  3405. /** @hidden */
  3406. var ETextureWrapMode;
  3407. (function (ETextureWrapMode) {
  3408. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3409. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3410. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3411. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3412. /** @hidden */
  3413. var ETextureFilterType;
  3414. (function (ETextureFilterType) {
  3415. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3416. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3417. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3418. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3419. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3420. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3421. })(ETextureFilterType || (ETextureFilterType = {}));
  3422. /** @hidden */
  3423. var ETextureFormat;
  3424. (function (ETextureFormat) {
  3425. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3426. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3427. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3428. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3429. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3430. })(ETextureFormat || (ETextureFormat = {}));
  3431. /** @hidden */
  3432. var ECullingType;
  3433. (function (ECullingType) {
  3434. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3435. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3436. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3437. })(ECullingType || (ECullingType = {}));
  3438. /** @hidden */
  3439. var EBlendingFunction;
  3440. (function (EBlendingFunction) {
  3441. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3442. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3443. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3444. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3445. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3446. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3447. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3448. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3449. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3450. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3451. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3452. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3453. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3454. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3455. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3456. })(EBlendingFunction || (EBlendingFunction = {}));
  3457. /***/ }),
  3458. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3459. /*!*************************************!*\
  3460. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3461. \*************************************/
  3462. /*! exports provided: GLTFUtils */
  3463. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3464. "use strict";
  3465. __webpack_require__.r(__webpack_exports__);
  3466. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3467. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3468. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  3469. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  3470. /**
  3471. * Utils functions for GLTF
  3472. * @hidden
  3473. */
  3474. var GLTFUtils = /** @class */ (function () {
  3475. function GLTFUtils() {
  3476. }
  3477. /**
  3478. * Sets the given "parameter" matrix
  3479. * @param scene: the Scene object
  3480. * @param source: the source node where to pick the matrix
  3481. * @param parameter: the GLTF technique parameter
  3482. * @param uniformName: the name of the shader's uniform
  3483. * @param shaderMaterial: the shader material
  3484. */
  3485. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3486. var mat = null;
  3487. if (parameter.semantic === "MODEL") {
  3488. mat = source.getWorldMatrix();
  3489. }
  3490. else if (parameter.semantic === "PROJECTION") {
  3491. mat = scene.getProjectionMatrix();
  3492. }
  3493. else if (parameter.semantic === "VIEW") {
  3494. mat = scene.getViewMatrix();
  3495. }
  3496. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3497. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3498. }
  3499. else if (parameter.semantic === "MODELVIEW") {
  3500. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3501. }
  3502. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3503. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3504. }
  3505. else if (parameter.semantic === "MODELINVERSE") {
  3506. mat = source.getWorldMatrix().invert();
  3507. }
  3508. else if (parameter.semantic === "VIEWINVERSE") {
  3509. mat = scene.getViewMatrix().invert();
  3510. }
  3511. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3512. mat = scene.getProjectionMatrix().invert();
  3513. }
  3514. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3515. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3516. }
  3517. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3518. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3519. }
  3520. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3521. mat = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3522. }
  3523. else {
  3524. debugger;
  3525. }
  3526. if (mat) {
  3527. switch (parameter.type) {
  3528. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3529. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3530. break;
  3531. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3532. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3533. break;
  3534. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3535. shaderMaterial.setMatrix(uniformName, mat);
  3536. break;
  3537. default: break;
  3538. }
  3539. }
  3540. };
  3541. /**
  3542. * Sets the given "parameter" matrix
  3543. * @param shaderMaterial: the shader material
  3544. * @param uniform: the name of the shader's uniform
  3545. * @param value: the value of the uniform
  3546. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3547. */
  3548. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3549. switch (type) {
  3550. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3551. shaderMaterial.setFloat(uniform, value);
  3552. return true;
  3553. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3554. shaderMaterial.setVector2(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3555. return true;
  3556. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3557. shaderMaterial.setVector3(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3558. return true;
  3559. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3560. shaderMaterial.setVector4(uniform, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3561. return true;
  3562. default: return false;
  3563. }
  3564. };
  3565. /**
  3566. * Returns the wrap mode of the texture
  3567. * @param mode: the mode value
  3568. */
  3569. GLTFUtils.GetWrapMode = function (mode) {
  3570. switch (mode) {
  3571. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3572. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3573. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3574. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3575. }
  3576. };
  3577. /**
  3578. * Returns the byte stride giving an accessor
  3579. * @param accessor: the GLTF accessor objet
  3580. */
  3581. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3582. // Needs this function since "byteStride" isn't requiered in glTF format
  3583. var type = accessor.type;
  3584. switch (type) {
  3585. case "VEC2": return 2;
  3586. case "VEC3": return 3;
  3587. case "VEC4": return 4;
  3588. case "MAT2": return 4;
  3589. case "MAT3": return 9;
  3590. case "MAT4": return 16;
  3591. default: return 1;
  3592. }
  3593. };
  3594. /**
  3595. * Returns the texture filter mode giving a mode value
  3596. * @param mode: the filter mode value
  3597. */
  3598. GLTFUtils.GetTextureFilterMode = function (mode) {
  3599. switch (mode) {
  3600. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3601. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3602. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3603. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3604. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3605. default: return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3606. }
  3607. };
  3608. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3609. var byteOffset = bufferView.byteOffset + byteOffset;
  3610. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3611. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3612. throw new Error("Buffer access is out of range");
  3613. }
  3614. var buffer = loadedBufferView.buffer;
  3615. byteOffset += loadedBufferView.byteOffset;
  3616. switch (componentType) {
  3617. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3618. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3619. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3620. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3621. default: return new Float32Array(buffer, byteOffset, byteLength);
  3622. }
  3623. };
  3624. /**
  3625. * Returns a buffer from its accessor
  3626. * @param gltfRuntime: the GLTF runtime
  3627. * @param accessor: the GLTF accessor
  3628. */
  3629. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3630. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3631. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3632. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3633. };
  3634. /**
  3635. * Decodes a buffer view into a string
  3636. * @param view: the buffer view
  3637. */
  3638. GLTFUtils.DecodeBufferToText = function (view) {
  3639. var result = "";
  3640. var length = view.byteLength;
  3641. for (var i = 0; i < length; ++i) {
  3642. result += String.fromCharCode(view[i]);
  3643. }
  3644. return result;
  3645. };
  3646. /**
  3647. * Returns the default material of gltf. Related to
  3648. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3649. * @param scene: the Babylon.js scene
  3650. */
  3651. GLTFUtils.GetDefaultMaterial = function (scene) {
  3652. if (!GLTFUtils._DefaultMaterial) {
  3653. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3654. "precision highp float;",
  3655. "",
  3656. "uniform mat4 worldView;",
  3657. "uniform mat4 projection;",
  3658. "",
  3659. "attribute vec3 position;",
  3660. "",
  3661. "void main(void)",
  3662. "{",
  3663. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3664. "}"
  3665. ].join("\n");
  3666. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3667. "precision highp float;",
  3668. "",
  3669. "uniform vec4 u_emission;",
  3670. "",
  3671. "void main(void)",
  3672. "{",
  3673. " gl_FragColor = u_emission;",
  3674. "}"
  3675. ].join("\n");
  3676. var shaderPath = {
  3677. vertex: "GLTFDefaultMaterial",
  3678. fragment: "GLTFDefaultMaterial"
  3679. };
  3680. var options = {
  3681. attributes: ["position"],
  3682. uniforms: ["worldView", "projection", "u_emission"],
  3683. samplers: new Array(),
  3684. needAlphaBlending: false
  3685. };
  3686. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3687. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3688. }
  3689. return GLTFUtils._DefaultMaterial;
  3690. };
  3691. // The GLTF default material
  3692. GLTFUtils._DefaultMaterial = null;
  3693. return GLTFUtils;
  3694. }());
  3695. /***/ }),
  3696. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3697. /*!**************************************************!*\
  3698. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3699. \**************************************************/
  3700. /*! exports provided: GLTFMaterialsCommonExtension */
  3701. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3702. "use strict";
  3703. __webpack_require__.r(__webpack_exports__);
  3704. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3705. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3706. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3707. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  3708. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__);
  3709. /** @hidden */
  3710. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3711. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3712. function GLTFMaterialsCommonExtension() {
  3713. return _super.call(this, "KHR_materials_common") || this;
  3714. }
  3715. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3716. if (!gltfRuntime.extensions) {
  3717. return false;
  3718. }
  3719. var extension = gltfRuntime.extensions[this.name];
  3720. if (!extension) {
  3721. return false;
  3722. }
  3723. // Create lights
  3724. var lights = extension.lights;
  3725. if (lights) {
  3726. for (var thing in lights) {
  3727. var light = lights[thing];
  3728. switch (light.type) {
  3729. case "ambient":
  3730. 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);
  3731. var ambient = light.ambient;
  3732. if (ambient) {
  3733. ambientLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3734. }
  3735. break;
  3736. case "point":
  3737. 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);
  3738. var point = light.point;
  3739. if (point) {
  3740. pointLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3741. }
  3742. break;
  3743. case "directional":
  3744. 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);
  3745. var directional = light.directional;
  3746. if (directional) {
  3747. dirLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3748. }
  3749. break;
  3750. case "spot":
  3751. var spot = light.spot;
  3752. if (spot) {
  3753. 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);
  3754. spotLight.diffuse = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3755. }
  3756. break;
  3757. default:
  3758. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3759. break;
  3760. }
  3761. }
  3762. }
  3763. return false;
  3764. };
  3765. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3766. var material = gltfRuntime.materials[id];
  3767. if (!material || !material.extensions) {
  3768. return false;
  3769. }
  3770. var extension = material.extensions[this.name];
  3771. if (!extension) {
  3772. return false;
  3773. }
  3774. var standardMaterial = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3775. standardMaterial.sideOrientation = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3776. if (extension.technique === "CONSTANT") {
  3777. standardMaterial.disableLighting = true;
  3778. }
  3779. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3780. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3781. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3782. // Ambient
  3783. if (typeof extension.values.ambient === "string") {
  3784. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3785. }
  3786. else {
  3787. standardMaterial.ambientColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3788. }
  3789. // Diffuse
  3790. if (typeof extension.values.diffuse === "string") {
  3791. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3792. }
  3793. else {
  3794. standardMaterial.diffuseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3795. }
  3796. // Emission
  3797. if (typeof extension.values.emission === "string") {
  3798. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3799. }
  3800. else {
  3801. standardMaterial.emissiveColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3802. }
  3803. // Specular
  3804. if (typeof extension.values.specular === "string") {
  3805. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3806. }
  3807. else {
  3808. standardMaterial.specularColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3809. }
  3810. return true;
  3811. };
  3812. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3813. // Create buffer from texture url
  3814. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3815. // Create texture from buffer
  3816. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3817. }, onError);
  3818. };
  3819. return GLTFMaterialsCommonExtension;
  3820. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3821. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3822. /***/ }),
  3823. /***/ "./glTF/1.0/index.ts":
  3824. /*!***************************!*\
  3825. !*** ./glTF/1.0/index.ts ***!
  3826. \***************************/
  3827. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3828. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3829. "use strict";
  3830. __webpack_require__.r(__webpack_exports__);
  3831. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3832. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3833. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3834. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3835. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3836. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3837. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3838. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3839. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3840. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3841. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3842. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3843. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3844. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3845. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3846. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3847. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3848. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3849. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3850. /***/ }),
  3851. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3852. /*!*******************************************************!*\
  3853. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3854. \*******************************************************/
  3855. /*! exports provided: EXT_lights_image_based */
  3856. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3857. "use strict";
  3858. __webpack_require__.r(__webpack_exports__);
  3859. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3860. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/observable");
  3861. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3862. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3863. var NAME = "EXT_lights_image_based";
  3864. /**
  3865. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3866. */
  3867. var EXT_lights_image_based = /** @class */ (function () {
  3868. /** @hidden */
  3869. function EXT_lights_image_based(loader) {
  3870. /**
  3871. * The name of this extension.
  3872. */
  3873. this.name = NAME;
  3874. this._loader = loader;
  3875. this.enabled = this._loader.isExtensionUsed(NAME);
  3876. }
  3877. /** @hidden */
  3878. EXT_lights_image_based.prototype.dispose = function () {
  3879. delete this._loader;
  3880. delete this._lights;
  3881. };
  3882. /** @hidden */
  3883. EXT_lights_image_based.prototype.onLoading = function () {
  3884. var extensions = this._loader.gltf.extensions;
  3885. if (extensions && extensions[this.name]) {
  3886. var extension = extensions[this.name];
  3887. this._lights = extension.lights;
  3888. }
  3889. };
  3890. /** @hidden */
  3891. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3892. var _this = this;
  3893. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3894. var promises = new Array();
  3895. promises.push(_this._loader.loadSceneAsync(context, scene));
  3896. _this._loader.logOpen("" + extensionContext);
  3897. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3898. promises.push(_this._loadLightAsync("#/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3899. _this._loader.babylonScene.environmentTexture = texture;
  3900. }));
  3901. _this._loader.logClose();
  3902. return Promise.all(promises).then(function () { });
  3903. });
  3904. };
  3905. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3906. var _this = this;
  3907. if (!light._loaded) {
  3908. var promises = new Array();
  3909. this._loader.logOpen("" + context);
  3910. var imageData_1 = new Array(light.specularImages.length);
  3911. var _loop_1 = function (mipmap) {
  3912. var faces = light.specularImages[mipmap];
  3913. imageData_1[mipmap] = new Array(faces.length);
  3914. var _loop_2 = function (face) {
  3915. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  3916. this_1._loader.logOpen("" + specularImageContext);
  3917. var index = faces[face];
  3918. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  3919. promises.push(this_1._loader.loadImageAsync("#/images/" + index, image).then(function (data) {
  3920. imageData_1[mipmap][face] = data;
  3921. }));
  3922. this_1._loader.logClose();
  3923. };
  3924. for (var face = 0; face < faces.length; face++) {
  3925. _loop_2(face);
  3926. }
  3927. };
  3928. var this_1 = this;
  3929. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  3930. _loop_1(mipmap);
  3931. }
  3932. this._loader.logClose();
  3933. light._loaded = Promise.all(promises).then(function () {
  3934. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  3935. light._babylonTexture = babylonTexture;
  3936. if (light.intensity != undefined) {
  3937. babylonTexture.level = light.intensity;
  3938. }
  3939. if (light.rotation) {
  3940. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  3941. // Invert the rotation so that positive rotation is counter-clockwise.
  3942. if (!_this._loader.babylonScene.useRightHandedSystem) {
  3943. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  3944. }
  3945. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  3946. }
  3947. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  3948. sphericalHarmonics.scaleInPlace(light.intensity);
  3949. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  3950. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  3951. // Compute the lod generation scale to fit exactly to the number of levels available.
  3952. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  3953. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  3954. });
  3955. }
  3956. return light._loaded.then(function () {
  3957. return light._babylonTexture;
  3958. });
  3959. };
  3960. return EXT_lights_image_based;
  3961. }());
  3962. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  3963. /***/ }),
  3964. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  3965. /*!*************************************************!*\
  3966. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  3967. \*************************************************/
  3968. /*! exports provided: ExtrasAsMetadata */
  3969. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3970. "use strict";
  3971. __webpack_require__.r(__webpack_exports__);
  3972. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  3973. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3974. var NAME = "ExtrasAsMetadata";
  3975. /**
  3976. * Store glTF extras (if present) in BJS objects' metadata
  3977. */
  3978. var ExtrasAsMetadata = /** @class */ (function () {
  3979. /** @hidden */
  3980. function ExtrasAsMetadata(loader) {
  3981. /**
  3982. * The name of this extension.
  3983. */
  3984. this.name = NAME;
  3985. /**
  3986. * Defines whether this extension is enabled.
  3987. */
  3988. this.enabled = true;
  3989. this._loader = loader;
  3990. }
  3991. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  3992. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  3993. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  3994. var gltf = (metadata.gltf = metadata.gltf || {});
  3995. gltf.extras = gltfProp.extras;
  3996. }
  3997. };
  3998. /** @hidden */
  3999. ExtrasAsMetadata.prototype.dispose = function () {
  4000. delete this._loader;
  4001. };
  4002. /** @hidden */
  4003. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4004. var _this = this;
  4005. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4006. _this._assignExtras(babylonTransformNode, node);
  4007. assign(babylonTransformNode);
  4008. });
  4009. };
  4010. /** @hidden */
  4011. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4012. var _this = this;
  4013. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4014. _this._assignExtras(babylonCamera, camera);
  4015. assign(babylonCamera);
  4016. });
  4017. };
  4018. /** @hidden */
  4019. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4020. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4021. this._assignExtras(babylonMaterial, material);
  4022. return babylonMaterial;
  4023. };
  4024. return ExtrasAsMetadata;
  4025. }());
  4026. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4027. /***/ }),
  4028. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4029. /*!***********************************************************!*\
  4030. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4031. \***********************************************************/
  4032. /*! exports provided: KHR_draco_mesh_compression */
  4033. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4034. "use strict";
  4035. __webpack_require__.r(__webpack_exports__);
  4036. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4037. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/observable");
  4038. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4039. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4040. var NAME = "KHR_draco_mesh_compression";
  4041. /**
  4042. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4043. */
  4044. var KHR_draco_mesh_compression = /** @class */ (function () {
  4045. /** @hidden */
  4046. function KHR_draco_mesh_compression(loader) {
  4047. /**
  4048. * The name of this extension.
  4049. */
  4050. this.name = NAME;
  4051. this._loader = loader;
  4052. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4053. }
  4054. /** @hidden */
  4055. KHR_draco_mesh_compression.prototype.dispose = function () {
  4056. delete this.dracoCompression;
  4057. delete this._loader;
  4058. };
  4059. /** @hidden */
  4060. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4061. var _this = this;
  4062. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4063. if (primitive.mode != undefined) {
  4064. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4065. primitive.mode !== 4 /* TRIANGLES */) {
  4066. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4067. }
  4068. // TODO: handle triangle strips
  4069. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4070. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4071. }
  4072. }
  4073. var attributes = {};
  4074. var loadAttribute = function (name, kind) {
  4075. var uniqueId = extension.attributes[name];
  4076. if (uniqueId == undefined) {
  4077. return;
  4078. }
  4079. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4080. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4081. babylonMesh._delayInfo.push(kind);
  4082. }
  4083. attributes[kind] = uniqueId;
  4084. };
  4085. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4086. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4087. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4088. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4089. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4090. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4091. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4092. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4093. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4094. if (!bufferView._dracoBabylonGeometry) {
  4095. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4096. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4097. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4098. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4099. babylonVertexData.applyToGeometry(babylonGeometry);
  4100. return babylonGeometry;
  4101. }).catch(function (error) {
  4102. throw new Error(context + ": " + error.message);
  4103. });
  4104. });
  4105. }
  4106. return bufferView._dracoBabylonGeometry;
  4107. });
  4108. };
  4109. return KHR_draco_mesh_compression;
  4110. }());
  4111. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4112. /***/ }),
  4113. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4114. /*!****************************************************!*\
  4115. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4116. \****************************************************/
  4117. /*! exports provided: KHR_lights */
  4118. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4119. "use strict";
  4120. __webpack_require__.r(__webpack_exports__);
  4121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4122. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  4123. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4124. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4125. var NAME = "KHR_lights_punctual";
  4126. var LightType;
  4127. (function (LightType) {
  4128. LightType["DIRECTIONAL"] = "directional";
  4129. LightType["POINT"] = "point";
  4130. LightType["SPOT"] = "spot";
  4131. })(LightType || (LightType = {}));
  4132. /**
  4133. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  4134. */
  4135. var KHR_lights = /** @class */ (function () {
  4136. /** @hidden */
  4137. function KHR_lights(loader) {
  4138. /**
  4139. * The name of this extension.
  4140. */
  4141. this.name = NAME;
  4142. this._loader = loader;
  4143. this.enabled = this._loader.isExtensionUsed(NAME);
  4144. }
  4145. /** @hidden */
  4146. KHR_lights.prototype.dispose = function () {
  4147. delete this._loader;
  4148. delete this._lights;
  4149. };
  4150. /** @hidden */
  4151. KHR_lights.prototype.onLoading = function () {
  4152. var extensions = this._loader.gltf.extensions;
  4153. if (extensions && extensions[this.name]) {
  4154. var extension = extensions[this.name];
  4155. this._lights = extension.lights;
  4156. }
  4157. };
  4158. /** @hidden */
  4159. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4160. var _this = this;
  4161. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4162. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4163. var babylonLight;
  4164. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4165. var name = light.name || babylonMesh.name;
  4166. switch (light.type) {
  4167. case LightType.DIRECTIONAL: {
  4168. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  4169. break;
  4170. }
  4171. case LightType.POINT: {
  4172. babylonLight = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  4173. break;
  4174. }
  4175. case LightType.SPOT: {
  4176. 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);
  4177. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4178. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4179. babylonLight = babylonSpotLight;
  4180. break;
  4181. }
  4182. default: {
  4183. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4184. }
  4185. }
  4186. babylonLight.falloffType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4187. babylonLight.diffuse = light.color ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4188. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4189. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4190. babylonLight.parent = babylonMesh;
  4191. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4192. assign(babylonMesh);
  4193. });
  4194. });
  4195. };
  4196. return KHR_lights;
  4197. }());
  4198. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4199. /***/ }),
  4200. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4201. /*!********************************************************!*\
  4202. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4203. \********************************************************/
  4204. /*! exports provided: KHR_materials_clearcoat */
  4205. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4206. "use strict";
  4207. __webpack_require__.r(__webpack_exports__);
  4208. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4209. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4210. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4211. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4212. var NAME = "KHR_materials_clearcoat";
  4213. /**
  4214. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4215. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4216. * !!! Experimental Extension Subject to Changes !!!
  4217. */
  4218. var KHR_materials_clearcoat = /** @class */ (function () {
  4219. /** @hidden */
  4220. function KHR_materials_clearcoat(loader) {
  4221. /**
  4222. * The name of this extension.
  4223. */
  4224. this.name = NAME;
  4225. /**
  4226. * Defines a number that determines the order the extensions are applied.
  4227. */
  4228. this.order = 220;
  4229. this._loader = loader;
  4230. this.enabled = this._loader.isExtensionUsed(NAME);
  4231. }
  4232. /** @hidden */
  4233. KHR_materials_clearcoat.prototype.dispose = function () {
  4234. delete this._loader;
  4235. };
  4236. /** @hidden */
  4237. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4238. var _this = this;
  4239. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4240. var promises = new Array();
  4241. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4242. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4243. return Promise.all(promises).then(function () { });
  4244. });
  4245. };
  4246. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4247. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4248. throw new Error(context + ": Material type not supported");
  4249. }
  4250. var promises = new Array();
  4251. babylonMaterial.clearCoat.isEnabled = true;
  4252. if (properties.clearcoatFactor != undefined) {
  4253. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4254. }
  4255. else {
  4256. babylonMaterial.clearCoat.intensity = 0;
  4257. }
  4258. if (properties.clearcoatTexture) {
  4259. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4260. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4261. babylonMaterial.clearCoat.texture = texture;
  4262. }));
  4263. }
  4264. if (properties.clearcoatRoughnessFactor != undefined) {
  4265. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4266. }
  4267. else {
  4268. babylonMaterial.clearCoat.roughness = 0;
  4269. }
  4270. if (properties.clearcoatRoughnessTexture) {
  4271. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4272. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4273. babylonMaterial.clearCoat.texture = texture;
  4274. }));
  4275. }
  4276. if (properties.clearcoatNormalTexture) {
  4277. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4278. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4279. babylonMaterial.clearCoat.bumpTexture = texture;
  4280. }));
  4281. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4282. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4283. if (properties.clearcoatNormalTexture.scale != undefined) {
  4284. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4285. }
  4286. }
  4287. return Promise.all(promises).then(function () { });
  4288. };
  4289. return KHR_materials_clearcoat;
  4290. }());
  4291. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4292. /***/ }),
  4293. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4294. /*!********************************************************************!*\
  4295. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4296. \********************************************************************/
  4297. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4298. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4299. "use strict";
  4300. __webpack_require__.r(__webpack_exports__);
  4301. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4302. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  4303. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4304. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4305. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4306. /**
  4307. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4308. */
  4309. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4310. /** @hidden */
  4311. function KHR_materials_pbrSpecularGlossiness(loader) {
  4312. /**
  4313. * The name of this extension.
  4314. */
  4315. this.name = NAME;
  4316. /**
  4317. * Defines a number that determines the order the extensions are applied.
  4318. */
  4319. this.order = 200;
  4320. this._loader = loader;
  4321. this.enabled = this._loader.isExtensionUsed(NAME);
  4322. }
  4323. /** @hidden */
  4324. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4325. delete this._loader;
  4326. };
  4327. /** @hidden */
  4328. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4329. var _this = this;
  4330. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4331. var promises = new Array();
  4332. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4333. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4334. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4335. return Promise.all(promises).then(function () { });
  4336. });
  4337. };
  4338. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4339. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4340. throw new Error(context + ": Material type not supported");
  4341. }
  4342. var promises = new Array();
  4343. babylonMaterial.metallic = null;
  4344. babylonMaterial.roughness = null;
  4345. if (properties.diffuseFactor) {
  4346. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4347. babylonMaterial.alpha = properties.diffuseFactor[3];
  4348. }
  4349. else {
  4350. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4351. }
  4352. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4353. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4354. if (properties.diffuseTexture) {
  4355. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4356. texture.name = babylonMaterial.name + " (Diffuse)";
  4357. babylonMaterial.albedoTexture = texture;
  4358. }));
  4359. }
  4360. if (properties.specularGlossinessTexture) {
  4361. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4362. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4363. babylonMaterial.reflectivityTexture = texture;
  4364. }));
  4365. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4366. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4367. }
  4368. return Promise.all(promises).then(function () { });
  4369. };
  4370. return KHR_materials_pbrSpecularGlossiness;
  4371. }());
  4372. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4373. /***/ }),
  4374. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4375. /*!****************************************************!*\
  4376. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4377. \****************************************************/
  4378. /*! exports provided: KHR_materials_sheen */
  4379. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4380. "use strict";
  4381. __webpack_require__.r(__webpack_exports__);
  4382. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4383. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4384. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4385. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4386. var NAME = "KHR_materials_sheen";
  4387. /**
  4388. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4389. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4390. * !!! Experimental Extension Subject to Changes !!!
  4391. */
  4392. var KHR_materials_sheen = /** @class */ (function () {
  4393. /** @hidden */
  4394. function KHR_materials_sheen(loader) {
  4395. /**
  4396. * The name of this extension.
  4397. */
  4398. this.name = NAME;
  4399. /**
  4400. * Defines a number that determines the order the extensions are applied.
  4401. */
  4402. this.order = 240;
  4403. this._loader = loader;
  4404. this.enabled = this._loader.isExtensionUsed(NAME);
  4405. }
  4406. /** @hidden */
  4407. KHR_materials_sheen.prototype.dispose = function () {
  4408. delete this._loader;
  4409. };
  4410. /** @hidden */
  4411. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4412. var _this = this;
  4413. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4414. var promises = new Array();
  4415. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4416. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4417. return Promise.all(promises).then(function () { });
  4418. });
  4419. };
  4420. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4421. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4422. throw new Error(context + ": Material type not supported");
  4423. }
  4424. var promises = new Array();
  4425. babylonMaterial.sheen.isEnabled = true;
  4426. if (properties.sheenFactor != undefined) {
  4427. babylonMaterial.sheen.intensity = properties.sheenFactor;
  4428. }
  4429. else {
  4430. babylonMaterial.sheen.intensity = 0;
  4431. }
  4432. if (properties.sheenColor != undefined) {
  4433. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.sheenColor);
  4434. }
  4435. if (properties.sheenTexture) {
  4436. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.sheenTexture, function (texture) {
  4437. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  4438. babylonMaterial.sheen.texture = texture;
  4439. }));
  4440. }
  4441. return Promise.all(promises).then(function () { });
  4442. };
  4443. return KHR_materials_sheen;
  4444. }());
  4445. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4446. /***/ }),
  4447. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4448. /*!*******************************************************!*\
  4449. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4450. \*******************************************************/
  4451. /*! exports provided: KHR_materials_specular */
  4452. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4453. "use strict";
  4454. __webpack_require__.r(__webpack_exports__);
  4455. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4456. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  4457. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4458. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4459. var NAME = "KHR_materials_specular";
  4460. /**
  4461. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4462. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4463. * !!! Experimental Extension Subject to Changes !!!
  4464. */
  4465. var KHR_materials_specular = /** @class */ (function () {
  4466. /** @hidden */
  4467. function KHR_materials_specular(loader) {
  4468. /**
  4469. * The name of this extension.
  4470. */
  4471. this.name = NAME;
  4472. /**
  4473. * Defines a number that determines the order the extensions are applied.
  4474. */
  4475. this.order = 230;
  4476. this._loader = loader;
  4477. this.enabled = this._loader.isExtensionUsed(NAME);
  4478. }
  4479. /** @hidden */
  4480. KHR_materials_specular.prototype.dispose = function () {
  4481. delete this._loader;
  4482. };
  4483. /** @hidden */
  4484. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4485. var _this = this;
  4486. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4487. var promises = new Array();
  4488. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4489. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4490. return Promise.all(promises).then(function () { });
  4491. });
  4492. };
  4493. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4494. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4495. throw new Error(context + ": Material type not supported");
  4496. }
  4497. if (properties.specularFactor !== undefined) {
  4498. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4499. }
  4500. if (properties.specularTexture) {
  4501. // This does not allow a separate sampler for it at the moment but is currently under discussion.
  4502. babylonMaterial.useMetallicF0FactorFromMetallicTexture = true;
  4503. }
  4504. return Promise.resolve();
  4505. };
  4506. return KHR_materials_specular;
  4507. }());
  4508. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4509. /***/ }),
  4510. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  4511. /*!****************************************************!*\
  4512. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  4513. \****************************************************/
  4514. /*! exports provided: KHR_materials_unlit */
  4515. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4516. "use strict";
  4517. __webpack_require__.r(__webpack_exports__);
  4518. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  4519. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  4520. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4521. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4522. var NAME = "KHR_materials_unlit";
  4523. /**
  4524. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4525. */
  4526. var KHR_materials_unlit = /** @class */ (function () {
  4527. /** @hidden */
  4528. function KHR_materials_unlit(loader) {
  4529. /**
  4530. * The name of this extension.
  4531. */
  4532. this.name = NAME;
  4533. /**
  4534. * Defines a number that determines the order the extensions are applied.
  4535. */
  4536. this.order = 210;
  4537. this._loader = loader;
  4538. this.enabled = this._loader.isExtensionUsed(NAME);
  4539. }
  4540. /** @hidden */
  4541. KHR_materials_unlit.prototype.dispose = function () {
  4542. delete this._loader;
  4543. };
  4544. /** @hidden */
  4545. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4546. var _this = this;
  4547. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  4548. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  4549. });
  4550. };
  4551. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  4552. if (!(babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4553. throw new Error(context + ": Material type not supported");
  4554. }
  4555. var promises = new Array();
  4556. babylonMaterial.unlit = true;
  4557. var properties = material.pbrMetallicRoughness;
  4558. if (properties) {
  4559. if (properties.baseColorFactor) {
  4560. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  4561. babylonMaterial.alpha = properties.baseColorFactor[3];
  4562. }
  4563. else {
  4564. babylonMaterial.albedoColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4565. }
  4566. if (properties.baseColorTexture) {
  4567. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  4568. texture.name = babylonMaterial.name + " (Base Color)";
  4569. babylonMaterial.albedoTexture = texture;
  4570. }));
  4571. }
  4572. }
  4573. if (material.doubleSided) {
  4574. babylonMaterial.backFaceCulling = false;
  4575. babylonMaterial.twoSidedLighting = true;
  4576. }
  4577. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4578. return Promise.all(promises).then(function () { });
  4579. };
  4580. return KHR_materials_unlit;
  4581. }());
  4582. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  4583. /***/ }),
  4584. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  4585. /*!******************************************************!*\
  4586. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  4587. \******************************************************/
  4588. /*! exports provided: KHR_texture_transform */
  4589. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4590. "use strict";
  4591. __webpack_require__.r(__webpack_exports__);
  4592. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  4593. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/observable");
  4594. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  4595. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4596. var NAME = "KHR_texture_transform";
  4597. /**
  4598. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/README.md)
  4599. */
  4600. var KHR_texture_transform = /** @class */ (function () {
  4601. /** @hidden */
  4602. function KHR_texture_transform(loader) {
  4603. /**
  4604. * The name of this extension.
  4605. */
  4606. this.name = NAME;
  4607. this._loader = loader;
  4608. this.enabled = this._loader.isExtensionUsed(NAME);
  4609. }
  4610. /** @hidden */
  4611. KHR_texture_transform.prototype.dispose = function () {
  4612. delete this._loader;
  4613. };
  4614. /** @hidden */
  4615. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  4616. var _this = this;
  4617. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  4618. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  4619. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  4620. throw new Error(extensionContext + ": Texture type not supported");
  4621. }
  4622. if (extension.offset) {
  4623. babylonTexture.uOffset = extension.offset[0];
  4624. babylonTexture.vOffset = extension.offset[1];
  4625. }
  4626. // Always rotate around the origin.
  4627. babylonTexture.uRotationCenter = 0;
  4628. babylonTexture.vRotationCenter = 0;
  4629. if (extension.rotation) {
  4630. babylonTexture.wAng = -extension.rotation;
  4631. }
  4632. if (extension.scale) {
  4633. babylonTexture.uScale = extension.scale[0];
  4634. babylonTexture.vScale = extension.scale[1];
  4635. }
  4636. if (extension.texCoord != undefined) {
  4637. babylonTexture.coordinatesIndex = extension.texCoord;
  4638. }
  4639. assign(babylonTexture);
  4640. });
  4641. });
  4642. };
  4643. return KHR_texture_transform;
  4644. }());
  4645. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  4646. /***/ }),
  4647. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  4648. /*!***************************************************!*\
  4649. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  4650. \***************************************************/
  4651. /*! exports provided: MSFT_audio_emitter */
  4652. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4653. "use strict";
  4654. __webpack_require__.r(__webpack_exports__);
  4655. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  4656. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Misc/observable");
  4657. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4658. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4659. var NAME = "MSFT_audio_emitter";
  4660. /**
  4661. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4662. */
  4663. var MSFT_audio_emitter = /** @class */ (function () {
  4664. /** @hidden */
  4665. function MSFT_audio_emitter(loader) {
  4666. /**
  4667. * The name of this extension.
  4668. */
  4669. this.name = NAME;
  4670. this._loader = loader;
  4671. this.enabled = this._loader.isExtensionUsed(NAME);
  4672. }
  4673. /** @hidden */
  4674. MSFT_audio_emitter.prototype.dispose = function () {
  4675. delete this._loader;
  4676. delete this._clips;
  4677. delete this._emitters;
  4678. };
  4679. /** @hidden */
  4680. MSFT_audio_emitter.prototype.onLoading = function () {
  4681. var extensions = this._loader.gltf.extensions;
  4682. if (extensions && extensions[this.name]) {
  4683. var extension = extensions[this.name];
  4684. this._clips = extension.clips;
  4685. this._emitters = extension.emitters;
  4686. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  4687. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  4688. }
  4689. };
  4690. /** @hidden */
  4691. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  4692. var _this = this;
  4693. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  4694. var promises = new Array();
  4695. promises.push(_this._loader.loadSceneAsync(context, scene));
  4696. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4697. var emitterIndex = _a[_i];
  4698. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4699. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  4700. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4701. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  4702. }
  4703. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  4704. }
  4705. return Promise.all(promises).then(function () { });
  4706. });
  4707. };
  4708. /** @hidden */
  4709. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  4710. var _this = this;
  4711. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4712. var promises = new Array();
  4713. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  4714. var _loop_1 = function (emitterIndex) {
  4715. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4716. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  4717. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  4718. var sound = _a[_i];
  4719. sound.attachToMesh(babylonMesh);
  4720. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4721. sound.setLocalDirectionToMesh(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  4722. 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);
  4723. }
  4724. }
  4725. }));
  4726. };
  4727. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4728. var emitterIndex = _a[_i];
  4729. _loop_1(emitterIndex);
  4730. }
  4731. assign(babylonMesh);
  4732. }).then(function (babylonMesh) {
  4733. return Promise.all(promises).then(function () {
  4734. return babylonMesh;
  4735. });
  4736. });
  4737. });
  4738. };
  4739. /** @hidden */
  4740. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  4741. var _this = this;
  4742. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  4743. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  4744. var promises = new Array();
  4745. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  4746. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  4747. var event_1 = _a[_i];
  4748. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  4749. }
  4750. return Promise.all(promises).then(function () {
  4751. return babylonAnimationGroup;
  4752. });
  4753. });
  4754. });
  4755. };
  4756. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  4757. if (clip._objectURL) {
  4758. return clip._objectURL;
  4759. }
  4760. var promise;
  4761. if (clip.uri) {
  4762. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  4763. }
  4764. else {
  4765. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  4766. promise = this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView);
  4767. }
  4768. clip._objectURL = promise.then(function (data) {
  4769. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  4770. });
  4771. return clip._objectURL;
  4772. };
  4773. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  4774. var _this = this;
  4775. emitter._babylonSounds = emitter._babylonSounds || [];
  4776. if (!emitter._babylonData) {
  4777. var clipPromises = new Array();
  4778. var name_1 = emitter.name || "emitter" + emitter.index;
  4779. var options_1 = {
  4780. loop: false,
  4781. autoplay: false,
  4782. volume: emitter.volume == undefined ? 1 : emitter.volume,
  4783. };
  4784. var _loop_2 = function (i) {
  4785. var clipContext = "#/extensions/" + this_1.name + "/clips";
  4786. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  4787. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  4788. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  4789. sound.refDistance = emitter.refDistance || 1;
  4790. sound.maxDistance = emitter.maxDistance || 256;
  4791. sound.rolloffFactor = emitter.rolloffFactor || 1;
  4792. sound.distanceModel = emitter.distanceModel || 'exponential';
  4793. sound._positionInEmitterSpace = true;
  4794. }));
  4795. };
  4796. var this_1 = this;
  4797. for (var i = 0; i < emitter.clips.length; i++) {
  4798. _loop_2(i);
  4799. }
  4800. var promise = Promise.all(clipPromises).then(function () {
  4801. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  4802. var weightedSound = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  4803. if (emitter.innerAngle) {
  4804. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  4805. }
  4806. if (emitter.outerAngle) {
  4807. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  4808. }
  4809. if (emitter.volume) {
  4810. weightedSound.volume = emitter.volume;
  4811. }
  4812. emitter._babylonData.sound = weightedSound;
  4813. });
  4814. emitter._babylonData = {
  4815. loaded: promise
  4816. };
  4817. }
  4818. return emitter._babylonData.loaded;
  4819. };
  4820. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  4821. switch (action) {
  4822. case "play" /* play */: {
  4823. return function (currentFrame) {
  4824. var frameOffset = (startOffset || 0) + (currentFrame - time);
  4825. sound.play(frameOffset);
  4826. };
  4827. }
  4828. case "stop" /* stop */: {
  4829. return function (currentFrame) {
  4830. sound.stop();
  4831. };
  4832. }
  4833. case "pause" /* pause */: {
  4834. return function (currentFrame) {
  4835. sound.pause();
  4836. };
  4837. }
  4838. default: {
  4839. throw new Error(context + ": Unsupported action " + action);
  4840. }
  4841. }
  4842. };
  4843. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  4844. var _this = this;
  4845. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  4846. return Promise.resolve();
  4847. }
  4848. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  4849. var emitterIndex = event.emitter;
  4850. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("#/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  4851. return this._loadEmitterAsync(context, emitter).then(function () {
  4852. var sound = emitter._babylonData.sound;
  4853. if (sound) {
  4854. var babylonAnimationEvent = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  4855. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  4856. // Make sure all started audio stops when this animation is terminated.
  4857. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  4858. sound.stop();
  4859. });
  4860. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  4861. sound.pause();
  4862. });
  4863. }
  4864. });
  4865. };
  4866. return MSFT_audio_emitter;
  4867. }());
  4868. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  4869. /***/ }),
  4870. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  4871. /*!*****************************************!*\
  4872. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  4873. \*****************************************/
  4874. /*! exports provided: MSFT_lod */
  4875. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4876. "use strict";
  4877. __webpack_require__.r(__webpack_exports__);
  4878. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  4879. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  4880. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  4881. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4882. var NAME = "MSFT_lod";
  4883. /**
  4884. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  4885. */
  4886. var MSFT_lod = /** @class */ (function () {
  4887. /** @hidden */
  4888. function MSFT_lod(loader) {
  4889. /**
  4890. * The name of this extension.
  4891. */
  4892. this.name = NAME;
  4893. /**
  4894. * Defines a number that determines the order the extensions are applied.
  4895. */
  4896. this.order = 100;
  4897. /**
  4898. * Maximum number of LODs to load, starting from the lowest LOD.
  4899. */
  4900. this.maxLODsToLoad = 10;
  4901. /**
  4902. * Observable raised when all node LODs of one level are loaded.
  4903. * The event data is the index of the loaded LOD starting from zero.
  4904. * Dispose the loader to cancel the loading of the next level of LODs.
  4905. */
  4906. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4907. /**
  4908. * Observable raised when all material LODs of one level are loaded.
  4909. * The event data is the index of the loaded LOD starting from zero.
  4910. * Dispose the loader to cancel the loading of the next level of LODs.
  4911. */
  4912. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4913. this._nodeIndexLOD = null;
  4914. this._nodeSignalLODs = new Array();
  4915. this._nodePromiseLODs = new Array();
  4916. this._materialIndexLOD = null;
  4917. this._materialSignalLODs = new Array();
  4918. this._materialPromiseLODs = new Array();
  4919. this._indexLOD = null;
  4920. this._bufferLODs = new Array();
  4921. this._loader = loader;
  4922. this.enabled = this._loader.isExtensionUsed(NAME);
  4923. }
  4924. /** @hidden */
  4925. MSFT_lod.prototype.dispose = function () {
  4926. this._disposeUnusedMaterials();
  4927. delete this._loader;
  4928. this._nodeIndexLOD = null;
  4929. this._nodeSignalLODs.length = 0;
  4930. this._nodePromiseLODs.length = 0;
  4931. this._materialIndexLOD = null;
  4932. this._materialSignalLODs.length = 0;
  4933. this._materialPromiseLODs.length = 0;
  4934. this._indexLOD = null;
  4935. this._bufferLODs.length = 0;
  4936. this.onMaterialLODsLoadedObservable.clear();
  4937. this.onNodeLODsLoadedObservable.clear();
  4938. };
  4939. /** @hidden */
  4940. MSFT_lod.prototype.onReady = function () {
  4941. var _this = this;
  4942. var _loop_1 = function (indexLOD) {
  4943. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  4944. if (indexLOD !== 0) {
  4945. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  4946. }
  4947. _this._loader.log("Loaded node LOD " + indexLOD);
  4948. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  4949. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  4950. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  4951. if (_this._nodeSignalLODs[indexLOD]) {
  4952. _this._nodeSignalLODs[indexLOD].resolve();
  4953. }
  4954. }
  4955. });
  4956. this_1._loader._completePromises.push(promise);
  4957. };
  4958. var this_1 = this;
  4959. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  4960. _loop_1(indexLOD);
  4961. }
  4962. var _loop_2 = function (indexLOD) {
  4963. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  4964. if (indexLOD !== 0) {
  4965. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  4966. }
  4967. _this._loader.log("Loaded material LOD " + indexLOD);
  4968. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  4969. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  4970. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  4971. if (_this._materialSignalLODs[indexLOD]) {
  4972. _this._materialSignalLODs[indexLOD].resolve();
  4973. }
  4974. }
  4975. });
  4976. this_2._loader._completePromises.push(promise);
  4977. };
  4978. var this_2 = this;
  4979. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  4980. _loop_2(indexLOD);
  4981. }
  4982. for (var indexLOD = 1; indexLOD < this._bufferLODs.length; indexLOD++) {
  4983. this._loadBufferLOD(indexLOD);
  4984. }
  4985. };
  4986. /** @hidden */
  4987. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  4988. var _this = this;
  4989. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4990. var firstPromise;
  4991. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  4992. _this._loader.logOpen("" + extensionContext);
  4993. var _loop_3 = function (indexLOD) {
  4994. var nodeLOD = nodeLODs[indexLOD];
  4995. _this._indexLOD = indexLOD;
  4996. if (indexLOD !== 0) {
  4997. _this._nodeIndexLOD = indexLOD;
  4998. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  4999. }
  5000. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5001. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5002. if (indexLOD !== 0) {
  5003. // TODO: should not rely on _babylonTransformNode
  5004. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5005. if (previousNodeLOD._babylonTransformNode) {
  5006. previousNodeLOD._babylonTransformNode.dispose();
  5007. delete previousNodeLOD._babylonTransformNode;
  5008. _this._disposeUnusedMaterials();
  5009. }
  5010. }
  5011. babylonMesh.setEnabled(true);
  5012. return babylonMesh;
  5013. });
  5014. if (indexLOD === 0) {
  5015. firstPromise = promise;
  5016. if (_this._bufferLODs.length !== 0) {
  5017. _this._loadBufferLOD(0);
  5018. }
  5019. }
  5020. else {
  5021. _this._nodeIndexLOD = null;
  5022. }
  5023. _this._indexLOD = null;
  5024. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5025. _this._nodePromiseLODs[indexLOD].push(promise);
  5026. };
  5027. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5028. _loop_3(indexLOD);
  5029. }
  5030. _this._loader.logClose();
  5031. return firstPromise;
  5032. });
  5033. };
  5034. /** @hidden */
  5035. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5036. var _this = this;
  5037. // Don't load material LODs if already loading a node LOD.
  5038. if (this._indexLOD) {
  5039. return null;
  5040. }
  5041. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5042. var firstPromise;
  5043. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5044. _this._loader.logOpen("" + extensionContext);
  5045. var _loop_4 = function (indexLOD) {
  5046. var materialLOD = materialLODs[indexLOD];
  5047. _this._indexLOD = indexLOD;
  5048. if (indexLOD !== 0) {
  5049. _this._materialIndexLOD = indexLOD;
  5050. }
  5051. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5052. if (indexLOD === 0) {
  5053. assign(babylonMaterial);
  5054. }
  5055. }).then(function (babylonMaterial) {
  5056. if (indexLOD !== 0) {
  5057. assign(babylonMaterial);
  5058. // TODO: should not rely on _data
  5059. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5060. if (previousDataLOD[babylonDrawMode]) {
  5061. previousDataLOD[babylonDrawMode].babylonMaterial.dispose();
  5062. delete previousDataLOD[babylonDrawMode];
  5063. }
  5064. }
  5065. return babylonMaterial;
  5066. });
  5067. if (indexLOD === 0) {
  5068. firstPromise = promise;
  5069. if (_this._bufferLODs.length !== 0) {
  5070. _this._loadBufferLOD(0);
  5071. }
  5072. }
  5073. else {
  5074. _this._materialIndexLOD = null;
  5075. }
  5076. _this._indexLOD = null;
  5077. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5078. _this._materialPromiseLODs[indexLOD].push(promise);
  5079. };
  5080. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5081. _loop_4(indexLOD);
  5082. }
  5083. _this._loader.logClose();
  5084. return firstPromise;
  5085. });
  5086. };
  5087. /** @hidden */
  5088. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5089. var _this = this;
  5090. // Defer the loading of uris if loading a material or node LOD.
  5091. if (this._materialIndexLOD !== null) {
  5092. this._loader.log("deferred");
  5093. var previousIndexLOD = this._materialIndexLOD - 1;
  5094. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5095. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5096. return _this._loader.loadUriAsync(context, property, uri);
  5097. });
  5098. }
  5099. else if (this._nodeIndexLOD !== null) {
  5100. this._loader.log("deferred");
  5101. var previousIndexLOD = this._nodeIndexLOD - 1;
  5102. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5103. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5104. return _this._loader.loadUriAsync(context, property, uri);
  5105. });
  5106. }
  5107. return null;
  5108. };
  5109. /** @hidden */
  5110. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5111. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5112. if (!this._loader.bin) {
  5113. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5114. }
  5115. // Non-LOD buffers will be bucketed into the first LOD.
  5116. var indexLOD = this._indexLOD || 0;
  5117. var start = byteOffset;
  5118. var end = start + byteLength - 1;
  5119. var bufferLOD_1 = this._bufferLODs[indexLOD];
  5120. if (bufferLOD_1) {
  5121. bufferLOD_1.start = Math.min(bufferLOD_1.start, start);
  5122. bufferLOD_1.end = Math.max(bufferLOD_1.end, end);
  5123. }
  5124. else {
  5125. bufferLOD_1 = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5126. this._bufferLODs[indexLOD] = bufferLOD_1;
  5127. }
  5128. return bufferLOD_1.loaded.promise.then(function (data) {
  5129. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD_1.start, byteLength);
  5130. });
  5131. }
  5132. return null;
  5133. };
  5134. MSFT_lod.prototype._loadBufferLOD = function (indexLOD) {
  5135. var bufferLOD = this._bufferLODs[indexLOD];
  5136. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5137. bufferLOD.loaded.resolve(data);
  5138. }, function (error) {
  5139. bufferLOD.loaded.reject(error);
  5140. });
  5141. };
  5142. /**
  5143. * Gets an array of LOD properties from lowest to highest.
  5144. */
  5145. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5146. if (this.maxLODsToLoad <= 0) {
  5147. throw new Error("maxLODsToLoad must be greater than zero");
  5148. }
  5149. var properties = new Array();
  5150. for (var i = ids.length - 1; i >= 0; i--) {
  5151. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5152. if (properties.length === this.maxLODsToLoad) {
  5153. return properties;
  5154. }
  5155. }
  5156. properties.push(property);
  5157. return properties;
  5158. };
  5159. MSFT_lod.prototype._disposeUnusedMaterials = function () {
  5160. // TODO: should not rely on _data
  5161. var materials = this._loader.gltf.materials;
  5162. if (materials) {
  5163. for (var _i = 0, materials_1 = materials; _i < materials_1.length; _i++) {
  5164. var material = materials_1[_i];
  5165. if (material._data) {
  5166. var _loop_5 = function (drawMode) {
  5167. var data = material._data[drawMode];
  5168. if (data.babylonMeshes.every(function (babylonMesh) { return babylonMesh.material !== data.babylonMaterial; })) {
  5169. // TODO: check if texture is in use instead of force disposing textures
  5170. data.babylonMaterial.dispose(false, true);
  5171. delete material._data[drawMode];
  5172. }
  5173. };
  5174. for (var drawMode in material._data) {
  5175. _loop_5(drawMode);
  5176. }
  5177. }
  5178. }
  5179. }
  5180. };
  5181. return MSFT_lod;
  5182. }());
  5183. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5184. /***/ }),
  5185. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5186. /*!***************************************************!*\
  5187. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5188. \***************************************************/
  5189. /*! exports provided: MSFT_minecraftMesh */
  5190. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5191. "use strict";
  5192. __webpack_require__.r(__webpack_exports__);
  5193. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5194. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  5195. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5196. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5197. var NAME = "MSFT_minecraftMesh";
  5198. /** @hidden */
  5199. var MSFT_minecraftMesh = /** @class */ (function () {
  5200. function MSFT_minecraftMesh(loader) {
  5201. this.name = NAME;
  5202. this._loader = loader;
  5203. this.enabled = this._loader.isExtensionUsed(NAME);
  5204. }
  5205. MSFT_minecraftMesh.prototype.dispose = function () {
  5206. delete this._loader;
  5207. };
  5208. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5209. var _this = this;
  5210. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5211. if (extra) {
  5212. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5213. throw new Error(extraContext + ": Material type not supported");
  5214. }
  5215. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5216. if (babylonMaterial.needAlphaBlending()) {
  5217. babylonMaterial.forceDepthWrite = true;
  5218. babylonMaterial.separateCullingPass = true;
  5219. }
  5220. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5221. babylonMaterial.twoSidedLighting = true;
  5222. return promise;
  5223. }
  5224. return null;
  5225. });
  5226. };
  5227. return MSFT_minecraftMesh;
  5228. }());
  5229. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5230. /***/ }),
  5231. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5232. /*!*************************************************!*\
  5233. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5234. \*************************************************/
  5235. /*! exports provided: MSFT_sRGBFactors */
  5236. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5237. "use strict";
  5238. __webpack_require__.r(__webpack_exports__);
  5239. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5240. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/observable");
  5241. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5242. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5243. var NAME = "MSFT_sRGBFactors";
  5244. /** @hidden */
  5245. var MSFT_sRGBFactors = /** @class */ (function () {
  5246. function MSFT_sRGBFactors(loader) {
  5247. this.name = NAME;
  5248. this._loader = loader;
  5249. this.enabled = this._loader.isExtensionUsed(NAME);
  5250. }
  5251. MSFT_sRGBFactors.prototype.dispose = function () {
  5252. delete this._loader;
  5253. };
  5254. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5255. var _this = this;
  5256. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5257. if (extra) {
  5258. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5259. throw new Error(extraContext + ": Material type not supported");
  5260. }
  5261. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5262. if (!babylonMaterial.albedoTexture) {
  5263. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5264. }
  5265. if (!babylonMaterial.reflectivityTexture) {
  5266. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5267. }
  5268. return promise;
  5269. }
  5270. return null;
  5271. });
  5272. };
  5273. return MSFT_sRGBFactors;
  5274. }());
  5275. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5276. /***/ }),
  5277. /***/ "./glTF/2.0/Extensions/index.ts":
  5278. /*!**************************************!*\
  5279. !*** ./glTF/2.0/Extensions/index.ts ***!
  5280. \**************************************/
  5281. /*! exports provided: EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  5282. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5283. "use strict";
  5284. __webpack_require__.r(__webpack_exports__);
  5285. /* 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");
  5286. /* 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"]; });
  5287. /* 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");
  5288. /* 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"]; });
  5289. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5290. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  5291. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5292. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  5293. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5294. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  5295. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5296. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_clearcoat"]; });
  5297. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5298. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_sheen"]; });
  5299. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5300. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_specular"]; });
  5301. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5302. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_8__["KHR_texture_transform"]; });
  5303. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5304. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_9__["MSFT_audio_emitter"]; });
  5305. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5306. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_10__["MSFT_lod"]; });
  5307. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5308. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_11__["MSFT_minecraftMesh"]; });
  5309. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5310. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_12__["MSFT_sRGBFactors"]; });
  5311. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5312. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_13__["ExtrasAsMetadata"]; });
  5313. /***/ }),
  5314. /***/ "./glTF/2.0/glTFLoader.ts":
  5315. /*!********************************!*\
  5316. !*** ./glTF/2.0/glTFLoader.ts ***!
  5317. \********************************/
  5318. /*! exports provided: ArrayItem, GLTFLoader */
  5319. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5320. "use strict";
  5321. __webpack_require__.r(__webpack_exports__);
  5322. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5323. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5324. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/observable");
  5325. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5326. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5327. /**
  5328. * Helper class for working with arrays when loading the glTF asset
  5329. */
  5330. var ArrayItem = /** @class */ (function () {
  5331. function ArrayItem() {
  5332. }
  5333. /**
  5334. * Gets an item from the given array.
  5335. * @param context The context when loading the asset
  5336. * @param array The array to get the item from
  5337. * @param index The index to the array
  5338. * @returns The array item
  5339. */
  5340. ArrayItem.Get = function (context, array, index) {
  5341. if (!array || index == undefined || !array[index]) {
  5342. throw new Error(context + ": Failed to find index (" + index + ")");
  5343. }
  5344. return array[index];
  5345. };
  5346. /**
  5347. * Assign an `index` field to each item of the given array.
  5348. * @param array The array of items
  5349. */
  5350. ArrayItem.Assign = function (array) {
  5351. if (array) {
  5352. for (var index = 0; index < array.length; index++) {
  5353. array[index].index = index;
  5354. }
  5355. }
  5356. };
  5357. return ArrayItem;
  5358. }());
  5359. /**
  5360. * The glTF 2.0 loader
  5361. */
  5362. var GLTFLoader = /** @class */ (function () {
  5363. /** @hidden */
  5364. function GLTFLoader(parent) {
  5365. /** @hidden */
  5366. this._completePromises = new Array();
  5367. this._disposed = false;
  5368. this._state = null;
  5369. this._extensions = new Array();
  5370. this._defaultBabylonMaterialData = {};
  5371. this._requests = new Array();
  5372. this._parent = parent;
  5373. }
  5374. /**
  5375. * Registers a loader extension.
  5376. * @param name The name of the loader extension.
  5377. * @param factory The factory function that creates the loader extension.
  5378. */
  5379. GLTFLoader.RegisterExtension = function (name, factory) {
  5380. if (GLTFLoader.UnregisterExtension(name)) {
  5381. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  5382. }
  5383. GLTFLoader._RegisteredExtensions[name] = {
  5384. factory: factory
  5385. };
  5386. };
  5387. /**
  5388. * Unregisters a loader extension.
  5389. * @param name The name of the loader extension.
  5390. * @returns A boolean indicating whether the extension has been unregistered
  5391. */
  5392. GLTFLoader.UnregisterExtension = function (name) {
  5393. if (!GLTFLoader._RegisteredExtensions[name]) {
  5394. return false;
  5395. }
  5396. delete GLTFLoader._RegisteredExtensions[name];
  5397. return true;
  5398. };
  5399. Object.defineProperty(GLTFLoader.prototype, "state", {
  5400. /**
  5401. * Gets the loader state.
  5402. */
  5403. get: function () {
  5404. return this._state;
  5405. },
  5406. enumerable: true,
  5407. configurable: true
  5408. });
  5409. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  5410. /**
  5411. * The object that represents the glTF JSON.
  5412. */
  5413. get: function () {
  5414. return this._gltf;
  5415. },
  5416. enumerable: true,
  5417. configurable: true
  5418. });
  5419. Object.defineProperty(GLTFLoader.prototype, "bin", {
  5420. /**
  5421. * The BIN chunk of a binary glTF.
  5422. */
  5423. get: function () {
  5424. return this._bin;
  5425. },
  5426. enumerable: true,
  5427. configurable: true
  5428. });
  5429. Object.defineProperty(GLTFLoader.prototype, "parent", {
  5430. /**
  5431. * The parent file loader.
  5432. */
  5433. get: function () {
  5434. return this._parent;
  5435. },
  5436. enumerable: true,
  5437. configurable: true
  5438. });
  5439. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  5440. /**
  5441. * The Babylon scene when loading the asset.
  5442. */
  5443. get: function () {
  5444. return this._babylonScene;
  5445. },
  5446. enumerable: true,
  5447. configurable: true
  5448. });
  5449. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  5450. /**
  5451. * The root Babylon mesh when loading the asset.
  5452. */
  5453. get: function () {
  5454. return this._rootBabylonMesh;
  5455. },
  5456. enumerable: true,
  5457. configurable: true
  5458. });
  5459. /** @hidden */
  5460. GLTFLoader.prototype.dispose = function () {
  5461. if (this._disposed) {
  5462. return;
  5463. }
  5464. this._disposed = true;
  5465. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  5466. var request = _a[_i];
  5467. request.abort();
  5468. }
  5469. this._requests.length = 0;
  5470. this._completePromises.length = 0;
  5471. for (var name_1 in this._extensions) {
  5472. var extension = this._extensions[name_1];
  5473. extension.dispose && extension.dispose();
  5474. delete this._extensions[name_1];
  5475. }
  5476. delete this._gltf;
  5477. delete this._babylonScene;
  5478. delete this._rootBabylonMesh;
  5479. delete this._progressCallback;
  5480. this._parent._clear();
  5481. };
  5482. /** @hidden */
  5483. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  5484. var _this = this;
  5485. return Promise.resolve().then(function () {
  5486. _this._babylonScene = scene;
  5487. _this._rootUrl = rootUrl;
  5488. _this._fileName = fileName || "scene";
  5489. _this._progressCallback = onProgress;
  5490. _this._loadData(data);
  5491. var nodes = null;
  5492. if (meshesNames) {
  5493. var nodeMap_1 = {};
  5494. if (_this._gltf.nodes) {
  5495. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  5496. var node = _a[_i];
  5497. if (node.name) {
  5498. nodeMap_1[node.name] = node.index;
  5499. }
  5500. }
  5501. }
  5502. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  5503. nodes = names.map(function (name) {
  5504. var node = nodeMap_1[name];
  5505. if (node === undefined) {
  5506. throw new Error("Failed to find node '" + name + "'");
  5507. }
  5508. return node;
  5509. });
  5510. }
  5511. return _this._loadAsync(nodes, function () {
  5512. return {
  5513. meshes: _this._getMeshes(),
  5514. particleSystems: [],
  5515. skeletons: _this._getSkeletons(),
  5516. animationGroups: _this._getAnimationGroups()
  5517. };
  5518. });
  5519. });
  5520. };
  5521. /** @hidden */
  5522. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  5523. var _this = this;
  5524. return Promise.resolve().then(function () {
  5525. _this._babylonScene = scene;
  5526. _this._rootUrl = rootUrl;
  5527. _this._fileName = fileName || "scene";
  5528. _this._progressCallback = onProgress;
  5529. _this._loadData(data);
  5530. return _this._loadAsync(null, function () { return undefined; });
  5531. });
  5532. };
  5533. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  5534. var _this = this;
  5535. return Promise.resolve().then(function () {
  5536. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  5537. _this._loadExtensions();
  5538. _this._checkExtensions();
  5539. 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];
  5540. 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];
  5541. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  5542. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  5543. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  5544. _this._extensionsOnLoading();
  5545. var promises = new Array();
  5546. // Block the marking of materials dirty until the scene is loaded.
  5547. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  5548. _this._babylonScene.blockMaterialDirtyMechanism = true;
  5549. if (nodes) {
  5550. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  5551. }
  5552. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  5553. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  5554. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  5555. }
  5556. // Restore the blocking of material dirty.
  5557. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  5558. if (_this._parent.compileMaterials) {
  5559. promises.push(_this._compileMaterialsAsync());
  5560. }
  5561. if (_this._parent.compileShadowGenerators) {
  5562. promises.push(_this._compileShadowGeneratorsAsync());
  5563. }
  5564. var resultPromise = Promise.all(promises).then(function () {
  5565. if (_this._rootBabylonMesh) {
  5566. _this._rootBabylonMesh.setEnabled(true);
  5567. }
  5568. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  5569. _this._extensionsOnReady();
  5570. _this._startAnimations();
  5571. return resultFunc();
  5572. });
  5573. resultPromise.then(function () {
  5574. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  5575. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  5576. if (!_this._disposed) {
  5577. Promise.all(_this._completePromises).then(function () {
  5578. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  5579. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  5580. _this._parent.onCompleteObservable.notifyObservers(undefined);
  5581. _this._parent.onCompleteObservable.clear();
  5582. _this.dispose();
  5583. }, function (error) {
  5584. _this._parent.onErrorObservable.notifyObservers(error);
  5585. _this._parent.onErrorObservable.clear();
  5586. _this.dispose();
  5587. });
  5588. }
  5589. });
  5590. });
  5591. return resultPromise;
  5592. }, function (error) {
  5593. if (!_this._disposed) {
  5594. _this._parent.onErrorObservable.notifyObservers(error);
  5595. _this._parent.onErrorObservable.clear();
  5596. _this.dispose();
  5597. }
  5598. throw error;
  5599. });
  5600. };
  5601. GLTFLoader.prototype._loadData = function (data) {
  5602. this._gltf = data.json;
  5603. this._setupData();
  5604. if (data.bin) {
  5605. var buffers = this._gltf.buffers;
  5606. if (buffers && buffers[0] && !buffers[0].uri) {
  5607. var binaryBuffer = buffers[0];
  5608. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  5609. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  5610. }
  5611. this._bin = data.bin;
  5612. }
  5613. else {
  5614. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  5615. }
  5616. }
  5617. };
  5618. GLTFLoader.prototype._setupData = function () {
  5619. ArrayItem.Assign(this._gltf.accessors);
  5620. ArrayItem.Assign(this._gltf.animations);
  5621. ArrayItem.Assign(this._gltf.buffers);
  5622. ArrayItem.Assign(this._gltf.bufferViews);
  5623. ArrayItem.Assign(this._gltf.cameras);
  5624. ArrayItem.Assign(this._gltf.images);
  5625. ArrayItem.Assign(this._gltf.materials);
  5626. ArrayItem.Assign(this._gltf.meshes);
  5627. ArrayItem.Assign(this._gltf.nodes);
  5628. ArrayItem.Assign(this._gltf.samplers);
  5629. ArrayItem.Assign(this._gltf.scenes);
  5630. ArrayItem.Assign(this._gltf.skins);
  5631. ArrayItem.Assign(this._gltf.textures);
  5632. if (this._gltf.nodes) {
  5633. var nodeParents = {};
  5634. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  5635. var node = _a[_i];
  5636. if (node.children) {
  5637. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  5638. var index = _c[_b];
  5639. nodeParents[index] = node.index;
  5640. }
  5641. }
  5642. }
  5643. var rootNode = this._createRootNode();
  5644. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  5645. var node = _e[_d];
  5646. var parentIndex = nodeParents[node.index];
  5647. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  5648. }
  5649. }
  5650. };
  5651. GLTFLoader.prototype._loadExtensions = function () {
  5652. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  5653. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  5654. if (extension.name !== name_2) {
  5655. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("The name of the glTF loader extension instance does not match the registered name: " + extension.name + " !== " + name_2);
  5656. }
  5657. this._extensions.push(extension);
  5658. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  5659. }
  5660. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  5661. this._parent.onExtensionLoadedObservable.clear();
  5662. };
  5663. GLTFLoader.prototype._checkExtensions = function () {
  5664. if (this._gltf.extensionsRequired) {
  5665. var _loop_1 = function (name_3) {
  5666. var extension = this_1._extensions.find(function (extension) { return extension.name === name_3; });
  5667. if (!extension || !extension.enabled) {
  5668. throw new Error("Require extension " + name_3 + " is not available");
  5669. }
  5670. };
  5671. var this_1 = this;
  5672. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  5673. var name_3 = _a[_i];
  5674. _loop_1(name_3);
  5675. }
  5676. }
  5677. };
  5678. GLTFLoader.prototype._setState = function (state) {
  5679. this._state = state;
  5680. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  5681. };
  5682. GLTFLoader.prototype._createRootNode = function () {
  5683. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  5684. this._rootBabylonMesh.setEnabled(false);
  5685. var rootNode = {
  5686. _babylonTransformNode: this._rootBabylonMesh,
  5687. index: -1
  5688. };
  5689. switch (this._parent.coordinateSystemMode) {
  5690. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  5691. if (!this._babylonScene.useRightHandedSystem) {
  5692. rootNode.rotation = [0, 1, 0, 0];
  5693. rootNode.scale = [1, 1, -1];
  5694. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  5695. }
  5696. break;
  5697. }
  5698. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  5699. this._babylonScene.useRightHandedSystem = true;
  5700. break;
  5701. }
  5702. default: {
  5703. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  5704. }
  5705. }
  5706. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  5707. return rootNode;
  5708. };
  5709. /**
  5710. * Loads a glTF scene.
  5711. * @param context The context when loading the asset
  5712. * @param scene The glTF scene property
  5713. * @returns A promise that resolves when the load is complete
  5714. */
  5715. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  5716. var _this = this;
  5717. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  5718. if (extensionPromise) {
  5719. return extensionPromise;
  5720. }
  5721. var promises = new Array();
  5722. this.logOpen(context + " " + (scene.name || ""));
  5723. if (scene.nodes) {
  5724. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  5725. var index = _a[_i];
  5726. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  5727. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  5728. babylonMesh.parent = _this._rootBabylonMesh;
  5729. }));
  5730. }
  5731. }
  5732. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  5733. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  5734. if (this._gltf.nodes) {
  5735. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  5736. var node = _c[_b];
  5737. if (node._babylonTransformNode && node._babylonBones) {
  5738. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  5739. var babylonBone = _e[_d];
  5740. babylonBone.linkTransformNode(node._babylonTransformNode);
  5741. }
  5742. }
  5743. }
  5744. }
  5745. promises.push(this._loadAnimationsAsync());
  5746. this.logClose();
  5747. return Promise.all(promises).then(function () { });
  5748. };
  5749. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  5750. if (node._primitiveBabylonMeshes) {
  5751. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  5752. var babylonMesh = _a[_i];
  5753. callback(babylonMesh);
  5754. }
  5755. }
  5756. };
  5757. GLTFLoader.prototype._getMeshes = function () {
  5758. var meshes = new Array();
  5759. // Root mesh is always first.
  5760. meshes.push(this._rootBabylonMesh);
  5761. var nodes = this._gltf.nodes;
  5762. if (nodes) {
  5763. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  5764. var node = nodes_1[_i];
  5765. this._forEachPrimitive(node, function (babylonMesh) {
  5766. meshes.push(babylonMesh);
  5767. });
  5768. }
  5769. }
  5770. return meshes;
  5771. };
  5772. GLTFLoader.prototype._getSkeletons = function () {
  5773. var skeletons = new Array();
  5774. var skins = this._gltf.skins;
  5775. if (skins) {
  5776. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  5777. var skin = skins_1[_i];
  5778. if (skin._data) {
  5779. skeletons.push(skin._data.babylonSkeleton);
  5780. }
  5781. }
  5782. }
  5783. return skeletons;
  5784. };
  5785. GLTFLoader.prototype._getAnimationGroups = function () {
  5786. var animationGroups = new Array();
  5787. var animations = this._gltf.animations;
  5788. if (animations) {
  5789. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  5790. var animation = animations_1[_i];
  5791. if (animation._babylonAnimationGroup) {
  5792. animationGroups.push(animation._babylonAnimationGroup);
  5793. }
  5794. }
  5795. }
  5796. return animationGroups;
  5797. };
  5798. GLTFLoader.prototype._startAnimations = function () {
  5799. switch (this._parent.animationStartMode) {
  5800. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  5801. // do nothing
  5802. break;
  5803. }
  5804. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  5805. var babylonAnimationGroups = this._getAnimationGroups();
  5806. if (babylonAnimationGroups.length !== 0) {
  5807. babylonAnimationGroups[0].start(true);
  5808. }
  5809. break;
  5810. }
  5811. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  5812. var babylonAnimationGroups = this._getAnimationGroups();
  5813. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  5814. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  5815. babylonAnimationGroup.start(true);
  5816. }
  5817. break;
  5818. }
  5819. default: {
  5820. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  5821. return;
  5822. }
  5823. }
  5824. };
  5825. /**
  5826. * Loads a glTF node.
  5827. * @param context The context when loading the asset
  5828. * @param node The glTF node property
  5829. * @param assign A function called synchronously after parsing the glTF properties
  5830. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  5831. */
  5832. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  5833. var _this = this;
  5834. if (assign === void 0) { assign = function () { }; }
  5835. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  5836. if (extensionPromise) {
  5837. return extensionPromise;
  5838. }
  5839. if (node._babylonTransformNode) {
  5840. throw new Error(context + ": Invalid recursive node hierarchy");
  5841. }
  5842. var promises = new Array();
  5843. this.logOpen(context + " " + (node.name || ""));
  5844. var loadNode = function (babylonTransformNode) {
  5845. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  5846. GLTFLoader._LoadTransform(node, babylonTransformNode);
  5847. if (node.camera != undefined) {
  5848. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  5849. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  5850. babylonCamera.parent = babylonTransformNode;
  5851. }));
  5852. }
  5853. if (node.children) {
  5854. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  5855. var index = _a[_i];
  5856. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  5857. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  5858. childBabylonMesh.parent = babylonTransformNode;
  5859. }));
  5860. }
  5861. }
  5862. assign(babylonTransformNode);
  5863. };
  5864. if (node.mesh == undefined) {
  5865. var nodeName = node.name || "node" + node.index;
  5866. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  5867. loadNode(node._babylonTransformNode);
  5868. }
  5869. else {
  5870. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  5871. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  5872. }
  5873. this.logClose();
  5874. return Promise.all(promises).then(function () {
  5875. _this._forEachPrimitive(node, function (babylonMesh) {
  5876. babylonMesh.refreshBoundingInfo(true);
  5877. });
  5878. return node._babylonTransformNode;
  5879. });
  5880. };
  5881. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  5882. var primitives = mesh.primitives;
  5883. if (!primitives || !primitives.length) {
  5884. throw new Error(context + ": Primitives are missing");
  5885. }
  5886. if (primitives[0].index == undefined) {
  5887. ArrayItem.Assign(primitives);
  5888. }
  5889. var promises = new Array();
  5890. this.logOpen(context + " " + (mesh.name || ""));
  5891. var name = node.name || "node" + node.index;
  5892. if (primitives.length === 1) {
  5893. var primitive = mesh.primitives[0];
  5894. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  5895. node._babylonTransformNode = babylonMesh;
  5896. node._primitiveBabylonMeshes = [babylonMesh];
  5897. }));
  5898. }
  5899. else {
  5900. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  5901. node._primitiveBabylonMeshes = [];
  5902. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  5903. var primitive = primitives_1[_i];
  5904. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  5905. babylonMesh.parent = node._babylonTransformNode;
  5906. node._primitiveBabylonMeshes.push(babylonMesh);
  5907. }));
  5908. }
  5909. }
  5910. if (node.skin != undefined) {
  5911. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  5912. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  5913. }
  5914. assign(node._babylonTransformNode);
  5915. this.logClose();
  5916. return Promise.all(promises).then(function () {
  5917. return node._babylonTransformNode;
  5918. });
  5919. };
  5920. /**
  5921. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  5922. * @param context The context when loading the asset
  5923. * @param name The mesh name when loading the asset
  5924. * @param node The glTF node when loading the asset
  5925. * @param mesh The glTF mesh when loading the asset
  5926. * @param primitive The glTF mesh primitive property
  5927. * @param assign A function called synchronously after parsing the glTF properties
  5928. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  5929. */
  5930. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  5931. var _this = this;
  5932. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  5933. if (extensionPromise) {
  5934. return extensionPromise;
  5935. }
  5936. this.logOpen("" + context);
  5937. var shouldInstance = this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  5938. var babylonAbstractMesh;
  5939. var promise;
  5940. if (shouldInstance && primitive._instanceData) {
  5941. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  5942. promise = primitive._instanceData.promise;
  5943. }
  5944. else {
  5945. var promises = new Array();
  5946. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  5947. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  5948. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  5949. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  5950. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  5951. babylonGeometry.applyToMesh(babylonMesh_1);
  5952. });
  5953. }));
  5954. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  5955. if (primitive.material == undefined) {
  5956. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  5957. if (!babylonMaterial) {
  5958. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  5959. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  5960. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  5961. }
  5962. babylonMesh_1.material = babylonMaterial;
  5963. }
  5964. else {
  5965. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  5966. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  5967. babylonMesh_1.material = babylonMaterial;
  5968. }));
  5969. }
  5970. promise = Promise.all(promises);
  5971. if (shouldInstance) {
  5972. primitive._instanceData = {
  5973. babylonSourceMesh: babylonMesh_1,
  5974. promise: promise
  5975. };
  5976. }
  5977. babylonAbstractMesh = babylonMesh_1;
  5978. }
  5979. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  5980. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  5981. assign(babylonAbstractMesh);
  5982. this.logClose();
  5983. return promise.then(function () {
  5984. return babylonAbstractMesh;
  5985. });
  5986. };
  5987. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  5988. var _this = this;
  5989. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  5990. if (extensionPromise) {
  5991. return extensionPromise;
  5992. }
  5993. var attributes = primitive.attributes;
  5994. if (!attributes) {
  5995. throw new Error(context + ": Attributes are missing");
  5996. }
  5997. var promises = new Array();
  5998. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  5999. if (primitive.indices == undefined) {
  6000. babylonMesh.isUnIndexed = true;
  6001. }
  6002. else {
  6003. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6004. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6005. babylonGeometry.setIndices(data);
  6006. }));
  6007. }
  6008. var loadAttribute = function (attribute, kind, callback) {
  6009. if (attributes[attribute] == undefined) {
  6010. return;
  6011. }
  6012. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6013. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6014. babylonMesh._delayInfo.push(kind);
  6015. }
  6016. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6017. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6018. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6019. }));
  6020. if (callback) {
  6021. callback(accessor);
  6022. }
  6023. };
  6024. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6025. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6026. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6027. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6028. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6029. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6030. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6031. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6032. if (accessor.type === "VEC4" /* VEC4 */) {
  6033. babylonMesh.hasVertexAlpha = true;
  6034. }
  6035. });
  6036. return Promise.all(promises).then(function () {
  6037. return babylonGeometry;
  6038. });
  6039. };
  6040. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6041. if (!primitive.targets) {
  6042. return;
  6043. }
  6044. if (node._numMorphTargets == undefined) {
  6045. node._numMorphTargets = primitive.targets.length;
  6046. }
  6047. else if (primitive.targets.length !== node._numMorphTargets) {
  6048. throw new Error(context + ": Primitives do not have the same number of targets");
  6049. }
  6050. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6051. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6052. for (var index = 0; index < primitive.targets.length; index++) {
  6053. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6054. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6055. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6056. // TODO: tell the target whether it has positions, normals, tangents
  6057. }
  6058. };
  6059. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6060. if (!primitive.targets) {
  6061. return Promise.resolve();
  6062. }
  6063. var promises = new Array();
  6064. var morphTargetManager = babylonMesh.morphTargetManager;
  6065. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6066. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6067. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6068. }
  6069. return Promise.all(promises).then(function () { });
  6070. };
  6071. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6072. var _this = this;
  6073. var promises = new Array();
  6074. var loadAttribute = function (attribute, kind, setData) {
  6075. if (attributes[attribute] == undefined) {
  6076. return;
  6077. }
  6078. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6079. if (!babylonVertexBuffer) {
  6080. return;
  6081. }
  6082. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6083. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6084. setData(babylonVertexBuffer, data);
  6085. }));
  6086. };
  6087. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6088. var positions = new Float32Array(data.length);
  6089. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6090. positions[index] = data[index] + value;
  6091. });
  6092. babylonMorphTarget.setPositions(positions);
  6093. });
  6094. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6095. var normals = new Float32Array(data.length);
  6096. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6097. normals[index] = data[index] + value;
  6098. });
  6099. babylonMorphTarget.setNormals(normals);
  6100. });
  6101. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6102. var tangents = new Float32Array(data.length / 3 * 4);
  6103. var dataIndex = 0;
  6104. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6105. // Tangent data for morph targets is stored as xyz delta.
  6106. // The vertexData.tangent is stored as xyzw.
  6107. // So we need to skip every fourth vertexData.tangent.
  6108. if (((index + 1) % 4) !== 0) {
  6109. tangents[dataIndex] = data[dataIndex] + value;
  6110. dataIndex++;
  6111. }
  6112. });
  6113. babylonMorphTarget.setTangents(tangents);
  6114. });
  6115. return Promise.all(promises).then(function () { });
  6116. };
  6117. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6118. // Ignore the TRS of skinned nodes.
  6119. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6120. if (node.skin != undefined) {
  6121. return;
  6122. }
  6123. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6124. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6125. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6126. if (node.matrix) {
  6127. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6128. matrix.decompose(scaling, rotation, position);
  6129. }
  6130. else {
  6131. if (node.translation) {
  6132. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6133. }
  6134. if (node.rotation) {
  6135. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6136. }
  6137. if (node.scale) {
  6138. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6139. }
  6140. }
  6141. babylonNode.position = position;
  6142. babylonNode.rotationQuaternion = rotation;
  6143. babylonNode.scaling = scaling;
  6144. };
  6145. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6146. var _this = this;
  6147. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6148. if (extensionPromise) {
  6149. return extensionPromise;
  6150. }
  6151. var assignSkeleton = function (skeleton) {
  6152. _this._forEachPrimitive(node, function (babylonMesh) {
  6153. babylonMesh.skeleton = skeleton;
  6154. });
  6155. };
  6156. if (skin._data) {
  6157. assignSkeleton(skin._data.babylonSkeleton);
  6158. return skin._data.promise;
  6159. }
  6160. var skeletonId = "skeleton" + skin.index;
  6161. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6162. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6163. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6164. this._loadBones(context, skin, babylonSkeleton);
  6165. assignSkeleton(babylonSkeleton);
  6166. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6167. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6168. });
  6169. skin._data = {
  6170. babylonSkeleton: babylonSkeleton,
  6171. promise: promise
  6172. };
  6173. return promise;
  6174. };
  6175. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6176. var babylonBones = {};
  6177. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6178. var index = _a[_i];
  6179. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6180. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6181. }
  6182. };
  6183. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6184. var babylonBone = babylonBones[node.index];
  6185. if (babylonBone) {
  6186. return babylonBone;
  6187. }
  6188. var babylonParentBone = null;
  6189. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6190. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6191. }
  6192. var boneIndex = skin.joints.indexOf(node.index);
  6193. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6194. babylonBones[node.index] = babylonBone;
  6195. node._babylonBones = node._babylonBones || [];
  6196. node._babylonBones.push(babylonBone);
  6197. return babylonBone;
  6198. };
  6199. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6200. if (skin.inverseBindMatrices == undefined) {
  6201. return Promise.resolve(null);
  6202. }
  6203. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6204. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6205. };
  6206. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6207. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6208. var babylonBone = _a[_i];
  6209. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6210. var boneIndex = babylonBone._index;
  6211. if (inverseBindMatricesData && boneIndex !== -1) {
  6212. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6213. baseMatrix.invertToRef(baseMatrix);
  6214. }
  6215. var babylonParentBone = babylonBone.getParent();
  6216. if (babylonParentBone) {
  6217. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6218. }
  6219. babylonBone.updateMatrix(baseMatrix, false, false);
  6220. babylonBone._updateDifferenceMatrix(undefined, false);
  6221. }
  6222. };
  6223. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6224. return node.matrix ?
  6225. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6226. 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());
  6227. };
  6228. /**
  6229. * Loads a glTF camera.
  6230. * @param context The context when loading the asset
  6231. * @param camera The glTF camera property
  6232. * @param assign A function called synchronously after parsing the glTF properties
  6233. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6234. */
  6235. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6236. if (assign === void 0) { assign = function () { }; }
  6237. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6238. if (extensionPromise) {
  6239. return extensionPromise;
  6240. }
  6241. var promises = new Array();
  6242. this.logOpen(context + " " + (camera.name || ""));
  6243. 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);
  6244. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6245. switch (camera.type) {
  6246. case "perspective" /* PERSPECTIVE */: {
  6247. var perspective = camera.perspective;
  6248. if (!perspective) {
  6249. throw new Error(context + ": Camera perspective properties are missing");
  6250. }
  6251. babylonCamera.fov = perspective.yfov;
  6252. babylonCamera.minZ = perspective.znear;
  6253. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6254. break;
  6255. }
  6256. case "orthographic" /* ORTHOGRAPHIC */: {
  6257. if (!camera.orthographic) {
  6258. throw new Error(context + ": Camera orthographic properties are missing");
  6259. }
  6260. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6261. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6262. babylonCamera.orthoRight = camera.orthographic.xmag;
  6263. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6264. babylonCamera.orthoTop = camera.orthographic.ymag;
  6265. babylonCamera.minZ = camera.orthographic.znear;
  6266. babylonCamera.maxZ = camera.orthographic.zfar;
  6267. break;
  6268. }
  6269. default: {
  6270. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6271. }
  6272. }
  6273. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6274. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6275. assign(babylonCamera);
  6276. return Promise.all(promises).then(function () {
  6277. return babylonCamera;
  6278. });
  6279. };
  6280. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6281. var animations = this._gltf.animations;
  6282. if (!animations) {
  6283. return Promise.resolve();
  6284. }
  6285. var promises = new Array();
  6286. for (var index = 0; index < animations.length; index++) {
  6287. var animation = animations[index];
  6288. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6289. }
  6290. return Promise.all(promises).then(function () { });
  6291. };
  6292. /**
  6293. * Loads a glTF animation.
  6294. * @param context The context when loading the asset
  6295. * @param animation The glTF animation property
  6296. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6297. */
  6298. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6299. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6300. if (promise) {
  6301. return promise;
  6302. }
  6303. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6304. animation._babylonAnimationGroup = babylonAnimationGroup;
  6305. var promises = new Array();
  6306. ArrayItem.Assign(animation.channels);
  6307. ArrayItem.Assign(animation.samplers);
  6308. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6309. var channel = _a[_i];
  6310. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6311. }
  6312. return Promise.all(promises).then(function () {
  6313. babylonAnimationGroup.normalize(0);
  6314. return babylonAnimationGroup;
  6315. });
  6316. };
  6317. /**
  6318. * @hidden Loads a glTF animation channel.
  6319. * @param context The context when loading the asset
  6320. * @param animationContext The context of the animation when loading the asset
  6321. * @param animation The glTF animation property
  6322. * @param channel The glTF animation channel property
  6323. * @param babylonAnimationGroup The babylon animation group property
  6324. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6325. * @returns A void promise when the channel load is complete
  6326. */
  6327. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6328. var _this = this;
  6329. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6330. if (channel.target.node == undefined) {
  6331. return Promise.resolve();
  6332. }
  6333. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6334. // Ignore animations that have no animation targets.
  6335. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6336. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6337. return Promise.resolve();
  6338. }
  6339. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6340. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6341. var targetPath;
  6342. var animationType;
  6343. switch (channel.target.path) {
  6344. case "translation" /* TRANSLATION */: {
  6345. targetPath = "position";
  6346. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6347. break;
  6348. }
  6349. case "rotation" /* ROTATION */: {
  6350. targetPath = "rotationQuaternion";
  6351. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  6352. break;
  6353. }
  6354. case "scale" /* SCALE */: {
  6355. targetPath = "scaling";
  6356. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6357. break;
  6358. }
  6359. case "weights" /* WEIGHTS */: {
  6360. targetPath = "influence";
  6361. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  6362. break;
  6363. }
  6364. default: {
  6365. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  6366. }
  6367. }
  6368. var outputBufferOffset = 0;
  6369. var getNextOutputValue;
  6370. switch (targetPath) {
  6371. case "position": {
  6372. getNextOutputValue = function () {
  6373. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6374. outputBufferOffset += 3;
  6375. return value;
  6376. };
  6377. break;
  6378. }
  6379. case "rotationQuaternion": {
  6380. getNextOutputValue = function () {
  6381. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  6382. outputBufferOffset += 4;
  6383. return value;
  6384. };
  6385. break;
  6386. }
  6387. case "scaling": {
  6388. getNextOutputValue = function () {
  6389. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6390. outputBufferOffset += 3;
  6391. return value;
  6392. };
  6393. break;
  6394. }
  6395. case "influence": {
  6396. getNextOutputValue = function () {
  6397. var value = new Array(targetNode._numMorphTargets);
  6398. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  6399. value[i] = data.output[outputBufferOffset++];
  6400. }
  6401. return value;
  6402. };
  6403. break;
  6404. }
  6405. }
  6406. var getNextKey;
  6407. switch (data.interpolation) {
  6408. case "STEP" /* STEP */: {
  6409. getNextKey = function (frameIndex) { return ({
  6410. frame: data.input[frameIndex],
  6411. value: getNextOutputValue(),
  6412. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  6413. }); };
  6414. break;
  6415. }
  6416. case "LINEAR" /* LINEAR */: {
  6417. getNextKey = function (frameIndex) { return ({
  6418. frame: data.input[frameIndex],
  6419. value: getNextOutputValue()
  6420. }); };
  6421. break;
  6422. }
  6423. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6424. getNextKey = function (frameIndex) { return ({
  6425. frame: data.input[frameIndex],
  6426. inTangent: getNextOutputValue(),
  6427. value: getNextOutputValue(),
  6428. outTangent: getNextOutputValue()
  6429. }); };
  6430. break;
  6431. }
  6432. }
  6433. var keys = new Array(data.input.length);
  6434. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  6435. keys[frameIndex] = getNextKey(frameIndex);
  6436. }
  6437. if (targetPath === "influence") {
  6438. var _loop_2 = function (targetIndex) {
  6439. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6440. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6441. babylonAnimation.setKeys(keys.map(function (key) { return ({
  6442. frame: key.frame,
  6443. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  6444. value: key.value[targetIndex],
  6445. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  6446. }); }));
  6447. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  6448. var babylonMesh = babylonAbstractMesh;
  6449. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  6450. var babylonAnimationClone = babylonAnimation.clone();
  6451. morphTarget.animations.push(babylonAnimationClone);
  6452. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  6453. });
  6454. };
  6455. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  6456. _loop_2(targetIndex);
  6457. }
  6458. }
  6459. else {
  6460. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6461. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6462. babylonAnimation.setKeys(keys);
  6463. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  6464. animationTargetOverride.animations.push(babylonAnimation);
  6465. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  6466. }
  6467. else {
  6468. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  6469. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  6470. }
  6471. }
  6472. });
  6473. };
  6474. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  6475. if (sampler._data) {
  6476. return sampler._data;
  6477. }
  6478. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  6479. switch (interpolation) {
  6480. case "STEP" /* STEP */:
  6481. case "LINEAR" /* LINEAR */:
  6482. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6483. break;
  6484. }
  6485. default: {
  6486. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  6487. }
  6488. }
  6489. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  6490. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  6491. sampler._data = Promise.all([
  6492. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  6493. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  6494. ]).then(function (_a) {
  6495. var inputData = _a[0], outputData = _a[1];
  6496. return {
  6497. input: inputData,
  6498. interpolation: interpolation,
  6499. output: outputData,
  6500. };
  6501. });
  6502. return sampler._data;
  6503. };
  6504. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6505. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  6506. if (extensionPromise) {
  6507. return extensionPromise;
  6508. }
  6509. if (!buffer._data) {
  6510. if (buffer.uri) {
  6511. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  6512. }
  6513. else {
  6514. if (!this._bin) {
  6515. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6516. }
  6517. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  6518. }
  6519. }
  6520. return buffer._data.then(function (data) {
  6521. try {
  6522. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  6523. }
  6524. catch (e) {
  6525. throw new Error(context + ": " + e.message);
  6526. }
  6527. });
  6528. };
  6529. /**
  6530. * Loads a glTF buffer view.
  6531. * @param context The context when loading the asset
  6532. * @param bufferView The glTF buffer view property
  6533. * @returns A promise that resolves with the loaded data when the load is complete
  6534. */
  6535. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  6536. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  6537. if (extensionPromise) {
  6538. return extensionPromise;
  6539. }
  6540. if (bufferView._data) {
  6541. return bufferView._data;
  6542. }
  6543. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  6544. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  6545. return bufferView._data;
  6546. };
  6547. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  6548. var _this = this;
  6549. if (accessor._data) {
  6550. return accessor._data;
  6551. }
  6552. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  6553. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  6554. var length = numComponents * accessor.count;
  6555. if (accessor.bufferView == undefined) {
  6556. accessor._data = Promise.resolve(new constructor(length));
  6557. }
  6558. else {
  6559. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6560. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  6561. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6562. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  6563. }
  6564. else {
  6565. var typedArray_1 = new constructor(length);
  6566. 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) {
  6567. typedArray_1[index] = value;
  6568. });
  6569. return typedArray_1;
  6570. }
  6571. });
  6572. }
  6573. if (accessor.sparse) {
  6574. var sparse_1 = accessor.sparse;
  6575. accessor._data = accessor._data.then(function (data) {
  6576. var typedArray = data;
  6577. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  6578. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  6579. return Promise.all([
  6580. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  6581. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  6582. ]).then(function (_a) {
  6583. var indicesData = _a[0], valuesData = _a[1];
  6584. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  6585. var sparseLength = numComponents * sparse_1.count;
  6586. var values;
  6587. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6588. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6589. }
  6590. else {
  6591. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6592. values = new constructor(sparseLength);
  6593. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  6594. values[index] = value;
  6595. });
  6596. }
  6597. var valuesIndex = 0;
  6598. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  6599. var dataIndex = indices[indicesIndex] * numComponents;
  6600. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  6601. typedArray[dataIndex++] = values[valuesIndex++];
  6602. }
  6603. }
  6604. return typedArray;
  6605. });
  6606. });
  6607. }
  6608. return accessor._data;
  6609. };
  6610. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  6611. return this._loadAccessorAsync(context, accessor, Float32Array);
  6612. };
  6613. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  6614. if (accessor.type !== "SCALAR" /* SCALAR */) {
  6615. throw new Error(context + "/type: Invalid value " + accessor.type);
  6616. }
  6617. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  6618. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  6619. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  6620. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  6621. }
  6622. if (accessor._data) {
  6623. return accessor._data;
  6624. }
  6625. if (accessor.sparse) {
  6626. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  6627. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  6628. }
  6629. else {
  6630. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6631. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6632. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  6633. });
  6634. }
  6635. return accessor._data;
  6636. };
  6637. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  6638. var _this = this;
  6639. if (bufferView._babylonBuffer) {
  6640. return bufferView._babylonBuffer;
  6641. }
  6642. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6643. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  6644. });
  6645. return bufferView._babylonBuffer;
  6646. };
  6647. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  6648. var _this = this;
  6649. if (accessor._babylonVertexBuffer) {
  6650. return accessor._babylonVertexBuffer;
  6651. }
  6652. if (accessor.sparse) {
  6653. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6654. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6655. });
  6656. }
  6657. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  6658. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  6659. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  6660. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6661. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6662. });
  6663. }
  6664. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  6665. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  6666. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind) {
  6667. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6668. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6669. });
  6670. }
  6671. else {
  6672. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6673. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  6674. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  6675. 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);
  6676. });
  6677. }
  6678. return accessor._babylonVertexBuffer;
  6679. };
  6680. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  6681. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6682. throw new Error(context + ": Material type not supported");
  6683. }
  6684. var promises = new Array();
  6685. if (properties) {
  6686. if (properties.baseColorFactor) {
  6687. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  6688. babylonMaterial.alpha = properties.baseColorFactor[3];
  6689. }
  6690. else {
  6691. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  6692. }
  6693. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  6694. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  6695. if (properties.baseColorTexture) {
  6696. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  6697. texture.name = babylonMaterial.name + " (Base Color)";
  6698. babylonMaterial.albedoTexture = texture;
  6699. }));
  6700. }
  6701. if (properties.metallicRoughnessTexture) {
  6702. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  6703. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  6704. babylonMaterial.metallicTexture = texture;
  6705. }));
  6706. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  6707. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  6708. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  6709. }
  6710. }
  6711. return Promise.all(promises).then(function () { });
  6712. };
  6713. /** @hidden */
  6714. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  6715. if (assign === void 0) { assign = function () { }; }
  6716. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  6717. if (extensionPromise) {
  6718. return extensionPromise;
  6719. }
  6720. material._data = material._data || {};
  6721. var babylonData = material._data[babylonDrawMode];
  6722. if (!babylonData) {
  6723. this.logOpen(context + " " + (material.name || ""));
  6724. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  6725. babylonData = {
  6726. babylonMaterial: babylonMaterial,
  6727. babylonMeshes: [],
  6728. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  6729. };
  6730. material._data[babylonDrawMode] = babylonData;
  6731. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  6732. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6733. this.logClose();
  6734. }
  6735. babylonData.babylonMeshes.push(babylonMesh);
  6736. babylonMesh.onDisposeObservable.addOnce(function () {
  6737. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  6738. if (index !== -1) {
  6739. babylonData.babylonMeshes.splice(index, 1);
  6740. }
  6741. });
  6742. assign(babylonData.babylonMaterial);
  6743. return babylonData.promise.then(function () {
  6744. return babylonData.babylonMaterial;
  6745. });
  6746. };
  6747. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  6748. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  6749. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  6750. babylonMaterial.fillMode = babylonDrawMode;
  6751. babylonMaterial.enableSpecularAntiAliasing = true;
  6752. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  6753. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  6754. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6755. babylonMaterial.metallic = 1;
  6756. babylonMaterial.roughness = 1;
  6757. return babylonMaterial;
  6758. };
  6759. /**
  6760. * Creates a Babylon material from a glTF material.
  6761. * @param context The context when loading the asset
  6762. * @param material The glTF material property
  6763. * @param babylonDrawMode The draw mode for the Babylon material
  6764. * @returns The Babylon material
  6765. */
  6766. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  6767. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  6768. if (extensionPromise) {
  6769. return extensionPromise;
  6770. }
  6771. var name = material.name || "material" + material.index;
  6772. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  6773. return babylonMaterial;
  6774. };
  6775. /**
  6776. * Loads properties from a glTF material into a Babylon material.
  6777. * @param context The context when loading the asset
  6778. * @param material The glTF material property
  6779. * @param babylonMaterial The Babylon material
  6780. * @returns A promise that resolves when the load is complete
  6781. */
  6782. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  6783. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  6784. if (extensionPromise) {
  6785. return extensionPromise;
  6786. }
  6787. var promises = new Array();
  6788. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  6789. if (material.pbrMetallicRoughness) {
  6790. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  6791. }
  6792. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  6793. return Promise.all(promises).then(function () { });
  6794. };
  6795. /**
  6796. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  6797. * @param context The context when loading the asset
  6798. * @param material The glTF material property
  6799. * @param babylonMaterial The Babylon material
  6800. * @returns A promise that resolves when the load is complete
  6801. */
  6802. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  6803. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6804. throw new Error(context + ": Material type not supported");
  6805. }
  6806. var promises = new Array();
  6807. 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);
  6808. if (material.doubleSided) {
  6809. babylonMaterial.backFaceCulling = false;
  6810. babylonMaterial.twoSidedLighting = true;
  6811. }
  6812. if (material.normalTexture) {
  6813. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  6814. texture.name = babylonMaterial.name + " (Normal)";
  6815. babylonMaterial.bumpTexture = texture;
  6816. }));
  6817. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  6818. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  6819. if (material.normalTexture.scale != undefined) {
  6820. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  6821. }
  6822. babylonMaterial.forceIrradianceInFragment = true;
  6823. }
  6824. if (material.occlusionTexture) {
  6825. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  6826. texture.name = babylonMaterial.name + " (Occlusion)";
  6827. babylonMaterial.ambientTexture = texture;
  6828. }));
  6829. babylonMaterial.useAmbientInGrayScale = true;
  6830. if (material.occlusionTexture.strength != undefined) {
  6831. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  6832. }
  6833. }
  6834. if (material.emissiveTexture) {
  6835. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  6836. texture.name = babylonMaterial.name + " (Emissive)";
  6837. babylonMaterial.emissiveTexture = texture;
  6838. }));
  6839. }
  6840. return Promise.all(promises).then(function () { });
  6841. };
  6842. /**
  6843. * Loads the alpha properties from a glTF material into a Babylon material.
  6844. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  6845. * @param context The context when loading the asset
  6846. * @param material The glTF material property
  6847. * @param babylonMaterial The Babylon material
  6848. */
  6849. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  6850. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6851. throw new Error(context + ": Material type not supported");
  6852. }
  6853. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  6854. switch (alphaMode) {
  6855. case "OPAQUE" /* OPAQUE */: {
  6856. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  6857. break;
  6858. }
  6859. case "MASK" /* MASK */: {
  6860. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  6861. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  6862. if (babylonMaterial.albedoTexture) {
  6863. babylonMaterial.albedoTexture.hasAlpha = true;
  6864. }
  6865. break;
  6866. }
  6867. case "BLEND" /* BLEND */: {
  6868. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  6869. if (babylonMaterial.albedoTexture) {
  6870. babylonMaterial.albedoTexture.hasAlpha = true;
  6871. babylonMaterial.useAlphaFromAlbedoTexture = true;
  6872. }
  6873. break;
  6874. }
  6875. default: {
  6876. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  6877. }
  6878. }
  6879. };
  6880. /**
  6881. * Loads a glTF texture info.
  6882. * @param context The context when loading the asset
  6883. * @param textureInfo The glTF texture info property
  6884. * @param assign A function called synchronously after parsing the glTF properties
  6885. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  6886. */
  6887. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  6888. var _this = this;
  6889. if (assign === void 0) { assign = function () { }; }
  6890. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  6891. if (extensionPromise) {
  6892. return extensionPromise;
  6893. }
  6894. this.logOpen("" + context);
  6895. if (textureInfo.texCoord >= 2) {
  6896. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  6897. }
  6898. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  6899. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  6900. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  6901. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  6902. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  6903. assign(babylonTexture);
  6904. });
  6905. this.logClose();
  6906. return promise;
  6907. };
  6908. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  6909. var _this = this;
  6910. if (assign === void 0) { assign = function () { }; }
  6911. var promises = new Array();
  6912. this.logOpen(context + " " + (texture.name || ""));
  6913. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  6914. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  6915. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  6916. var url = null;
  6917. if (image.uri) {
  6918. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  6919. url = image.uri;
  6920. }
  6921. else if (this._babylonScene.getEngine().textureFormatInUse) {
  6922. // 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
  6923. url = this._rootUrl + image.uri;
  6924. }
  6925. }
  6926. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  6927. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  6928. if (!_this._disposed) {
  6929. deferred.resolve();
  6930. }
  6931. }, function (message, exception) {
  6932. if (!_this._disposed) {
  6933. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  6934. }
  6935. }, undefined, undefined, undefined, image.mimeType);
  6936. promises.push(deferred.promise);
  6937. if (!url) {
  6938. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  6939. var name = image.uri || _this._fileName + "#image" + image.index;
  6940. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  6941. babylonTexture.updateURL(dataUrl, data);
  6942. }));
  6943. }
  6944. babylonTexture.wrapU = samplerData.wrapU;
  6945. babylonTexture.wrapV = samplerData.wrapV;
  6946. assign(babylonTexture);
  6947. this.logClose();
  6948. return Promise.all(promises).then(function () {
  6949. return babylonTexture;
  6950. });
  6951. };
  6952. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  6953. if (!sampler._data) {
  6954. sampler._data = {
  6955. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  6956. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  6957. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  6958. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  6959. };
  6960. }
  6961. return sampler._data;
  6962. };
  6963. /**
  6964. * Loads a glTF image.
  6965. * @param context The context when loading the asset
  6966. * @param image The glTF image property
  6967. * @returns A promise that resolves with the loaded data when the load is complete
  6968. */
  6969. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  6970. if (!image._data) {
  6971. this.logOpen(context + " " + (image.name || ""));
  6972. if (image.uri) {
  6973. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  6974. }
  6975. else {
  6976. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  6977. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  6978. }
  6979. this.logClose();
  6980. }
  6981. return image._data;
  6982. };
  6983. /**
  6984. * Loads a glTF uri.
  6985. * @param context The context when loading the asset
  6986. * @param property The glTF property associated with the uri
  6987. * @param uri The base64 or relative uri
  6988. * @returns A promise that resolves with the loaded data when the load is complete
  6989. */
  6990. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  6991. var _this = this;
  6992. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  6993. if (extensionPromise) {
  6994. return extensionPromise;
  6995. }
  6996. if (!GLTFLoader._ValidateUri(uri)) {
  6997. throw new Error(context + ": '" + uri + "' is invalid");
  6998. }
  6999. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7000. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7001. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7002. return Promise.resolve(data);
  7003. }
  7004. this.log("Loading " + uri);
  7005. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7006. return new Promise(function (resolve, reject) {
  7007. if (!_this._disposed) {
  7008. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  7009. if (!_this._disposed) {
  7010. var data = new Uint8Array(fileData);
  7011. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  7012. resolve(data);
  7013. }
  7014. }, function (event) {
  7015. if (!_this._disposed) {
  7016. if (request_1) {
  7017. request_1._lengthComputable = event.lengthComputable;
  7018. request_1._loaded = event.loaded;
  7019. request_1._total = event.total;
  7020. }
  7021. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  7022. try {
  7023. _this._onProgress();
  7024. }
  7025. catch (e) {
  7026. reject(e);
  7027. }
  7028. }
  7029. }
  7030. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  7031. if (!_this._disposed) {
  7032. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7033. }
  7034. });
  7035. _this._requests.push(request_1);
  7036. }
  7037. });
  7038. });
  7039. };
  7040. GLTFLoader.prototype._onProgress = function () {
  7041. if (!this._progressCallback) {
  7042. return;
  7043. }
  7044. var lengthComputable = true;
  7045. var loaded = 0;
  7046. var total = 0;
  7047. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  7048. var request = _a[_i];
  7049. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  7050. return;
  7051. }
  7052. lengthComputable = lengthComputable && request._lengthComputable;
  7053. loaded += request._loaded;
  7054. total += request._total;
  7055. }
  7056. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  7057. };
  7058. /**
  7059. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7060. * @param babylonObject the Babylon object with metadata
  7061. * @param pointer the JSON pointer
  7062. */
  7063. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7064. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7065. var gltf = (metadata.gltf = metadata.gltf || {});
  7066. var pointers = (gltf.pointers = gltf.pointers || []);
  7067. pointers.push(pointer);
  7068. };
  7069. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7070. // Set defaults if undefined
  7071. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7072. switch (mode) {
  7073. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7074. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7075. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7076. default:
  7077. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7078. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7079. }
  7080. };
  7081. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7082. // Set defaults if undefined
  7083. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7084. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7085. if (magFilter === 9729 /* LINEAR */) {
  7086. switch (minFilter) {
  7087. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7088. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7089. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7090. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7091. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7092. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7093. default:
  7094. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7095. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7096. }
  7097. }
  7098. else {
  7099. if (magFilter !== 9728 /* NEAREST */) {
  7100. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7101. }
  7102. switch (minFilter) {
  7103. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7104. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7105. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7106. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7107. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7108. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7109. default:
  7110. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7111. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7112. }
  7113. }
  7114. };
  7115. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7116. switch (componentType) {
  7117. case 5120 /* BYTE */: return Int8Array;
  7118. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7119. case 5122 /* SHORT */: return Int16Array;
  7120. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7121. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7122. case 5126 /* FLOAT */: return Float32Array;
  7123. default: throw new Error(context + ": Invalid component type " + componentType);
  7124. }
  7125. };
  7126. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7127. var buffer = bufferView.buffer;
  7128. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7129. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7130. try {
  7131. return new constructor(buffer, byteOffset, length);
  7132. }
  7133. catch (e) {
  7134. throw new Error(context + ": " + e);
  7135. }
  7136. };
  7137. GLTFLoader._GetNumComponents = function (context, type) {
  7138. switch (type) {
  7139. case "SCALAR": return 1;
  7140. case "VEC2": return 2;
  7141. case "VEC3": return 3;
  7142. case "VEC4": return 4;
  7143. case "MAT2": return 4;
  7144. case "MAT3": return 9;
  7145. case "MAT4": return 16;
  7146. }
  7147. throw new Error(context + ": Invalid type (" + type + ")");
  7148. };
  7149. GLTFLoader._ValidateUri = function (uri) {
  7150. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7151. };
  7152. GLTFLoader._GetDrawMode = function (context, mode) {
  7153. if (mode == undefined) {
  7154. mode = 4 /* TRIANGLES */;
  7155. }
  7156. switch (mode) {
  7157. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7158. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7159. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7160. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7161. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7162. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7163. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7164. }
  7165. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7166. };
  7167. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7168. var _this = this;
  7169. this._parent._startPerformanceCounter("Compile materials");
  7170. var promises = new Array();
  7171. if (this._gltf.materials) {
  7172. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7173. var material = _a[_i];
  7174. if (material._data) {
  7175. for (var babylonDrawMode in material._data) {
  7176. var babylonData = material._data[babylonDrawMode];
  7177. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7178. var babylonMesh = _c[_b];
  7179. // Ensure nonUniformScaling is set if necessary.
  7180. babylonMesh.computeWorldMatrix(true);
  7181. var babylonMaterial = babylonData.babylonMaterial;
  7182. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7183. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7184. if (this._parent.useClipPlane) {
  7185. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7186. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7187. }
  7188. }
  7189. }
  7190. }
  7191. }
  7192. }
  7193. return Promise.all(promises).then(function () {
  7194. _this._parent._endPerformanceCounter("Compile materials");
  7195. });
  7196. };
  7197. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7198. var _this = this;
  7199. this._parent._startPerformanceCounter("Compile shadow generators");
  7200. var promises = new Array();
  7201. var lights = this._babylonScene.lights;
  7202. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7203. var light = lights_1[_i];
  7204. var generator = light.getShadowGenerator();
  7205. if (generator) {
  7206. promises.push(generator.forceCompilationAsync());
  7207. }
  7208. }
  7209. return Promise.all(promises).then(function () {
  7210. _this._parent._endPerformanceCounter("Compile shadow generators");
  7211. });
  7212. };
  7213. GLTFLoader.prototype._forEachExtensions = function (action) {
  7214. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7215. var extension = _a[_i];
  7216. if (extension.enabled) {
  7217. action(extension);
  7218. }
  7219. }
  7220. };
  7221. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7222. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7223. var extension = _a[_i];
  7224. if (extension.enabled) {
  7225. var id = extension.name + "." + functionName;
  7226. var loaderProperty = property;
  7227. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7228. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7229. if (!activeLoaderExtensionFunctions[id]) {
  7230. activeLoaderExtensionFunctions[id] = true;
  7231. try {
  7232. var result = actionAsync(extension);
  7233. if (result) {
  7234. return result;
  7235. }
  7236. }
  7237. finally {
  7238. delete activeLoaderExtensionFunctions[id];
  7239. }
  7240. }
  7241. }
  7242. }
  7243. return null;
  7244. };
  7245. GLTFLoader.prototype._extensionsOnLoading = function () {
  7246. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7247. };
  7248. GLTFLoader.prototype._extensionsOnReady = function () {
  7249. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7250. };
  7251. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7252. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7253. };
  7254. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7255. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7256. };
  7257. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7258. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7259. };
  7260. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7261. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7262. };
  7263. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7264. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7265. };
  7266. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7267. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7268. };
  7269. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7270. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7271. };
  7272. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7273. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7274. };
  7275. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7276. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7277. };
  7278. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7279. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7280. };
  7281. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7282. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7283. };
  7284. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7285. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7286. };
  7287. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7288. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7289. };
  7290. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7291. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7292. };
  7293. /**
  7294. * Helper method called by a loader extension to load an glTF extension.
  7295. * @param context The context when loading the asset
  7296. * @param property The glTF property to load the extension from
  7297. * @param extensionName The name of the extension to load
  7298. * @param actionAsync The action to run
  7299. * @returns The promise returned by actionAsync or null if the extension does not exist
  7300. */
  7301. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7302. if (!property.extensions) {
  7303. return null;
  7304. }
  7305. var extensions = property.extensions;
  7306. var extension = extensions[extensionName];
  7307. if (!extension) {
  7308. return null;
  7309. }
  7310. return actionAsync(context + "/extensions/" + extensionName, extension);
  7311. };
  7312. /**
  7313. * Helper method called by a loader extension to load a glTF extra.
  7314. * @param context The context when loading the asset
  7315. * @param property The glTF property to load the extra from
  7316. * @param extensionName The name of the extension to load
  7317. * @param actionAsync The action to run
  7318. * @returns The promise returned by actionAsync or null if the extra does not exist
  7319. */
  7320. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7321. if (!property.extras) {
  7322. return null;
  7323. }
  7324. var extras = property.extras;
  7325. var extra = extras[extensionName];
  7326. if (!extra) {
  7327. return null;
  7328. }
  7329. return actionAsync(context + "/extras/" + extensionName, extra);
  7330. };
  7331. /**
  7332. * Checks for presence of an extension.
  7333. * @param name The name of the extension to check
  7334. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7335. */
  7336. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7337. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7338. };
  7339. /**
  7340. * Increments the indentation level and logs a message.
  7341. * @param message The message to log
  7342. */
  7343. GLTFLoader.prototype.logOpen = function (message) {
  7344. this._parent._logOpen(message);
  7345. };
  7346. /**
  7347. * Decrements the indentation level.
  7348. */
  7349. GLTFLoader.prototype.logClose = function () {
  7350. this._parent._logClose();
  7351. };
  7352. /**
  7353. * Logs a message
  7354. * @param message The message to log
  7355. */
  7356. GLTFLoader.prototype.log = function (message) {
  7357. this._parent._log(message);
  7358. };
  7359. /**
  7360. * Starts a performance counter.
  7361. * @param counterName The name of the performance counter
  7362. */
  7363. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7364. this._parent._startPerformanceCounter(counterName);
  7365. };
  7366. /**
  7367. * Ends a performance counter.
  7368. * @param counterName The name of the performance counter
  7369. */
  7370. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7371. this._parent._endPerformanceCounter(counterName);
  7372. };
  7373. GLTFLoader._DefaultSampler = { index: -1 };
  7374. GLTFLoader._RegisteredExtensions = {};
  7375. return GLTFLoader;
  7376. }());
  7377. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  7378. /***/ }),
  7379. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  7380. /*!******************************************!*\
  7381. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  7382. \******************************************/
  7383. /*! no static exports found */
  7384. /***/ (function(module, exports) {
  7385. /***/ }),
  7386. /***/ "./glTF/2.0/index.ts":
  7387. /*!***************************!*\
  7388. !*** ./glTF/2.0/index.ts ***!
  7389. \***************************/
  7390. /*! exports provided: ArrayItem, GLTFLoader, EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  7391. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7392. "use strict";
  7393. __webpack_require__.r(__webpack_exports__);
  7394. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  7395. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  7396. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  7397. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  7398. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  7399. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  7400. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  7401. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  7402. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  7403. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  7404. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  7405. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  7406. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  7407. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  7408. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  7409. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  7410. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  7411. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  7412. /***/ }),
  7413. /***/ "./glTF/glTFFileLoader.ts":
  7414. /*!********************************!*\
  7415. !*** ./glTF/glTFFileLoader.ts ***!
  7416. \********************************/
  7417. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  7418. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7419. "use strict";
  7420. __webpack_require__.r(__webpack_exports__);
  7421. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  7422. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  7423. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  7424. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  7425. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  7426. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  7427. /**
  7428. * Mode that determines the coordinate system to use.
  7429. */
  7430. var GLTFLoaderCoordinateSystemMode;
  7431. (function (GLTFLoaderCoordinateSystemMode) {
  7432. /**
  7433. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  7434. */
  7435. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  7436. /**
  7437. * Sets the useRightHandedSystem flag on the scene.
  7438. */
  7439. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  7440. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  7441. /**
  7442. * Mode that determines what animations will start.
  7443. */
  7444. var GLTFLoaderAnimationStartMode;
  7445. (function (GLTFLoaderAnimationStartMode) {
  7446. /**
  7447. * No animation will start.
  7448. */
  7449. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  7450. /**
  7451. * The first animation will start.
  7452. */
  7453. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  7454. /**
  7455. * All animations will start.
  7456. */
  7457. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  7458. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  7459. /**
  7460. * Loader state.
  7461. */
  7462. var GLTFLoaderState;
  7463. (function (GLTFLoaderState) {
  7464. /**
  7465. * The asset is loading.
  7466. */
  7467. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  7468. /**
  7469. * The asset is ready for rendering.
  7470. */
  7471. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  7472. /**
  7473. * The asset is completely loaded.
  7474. */
  7475. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  7476. })(GLTFLoaderState || (GLTFLoaderState = {}));
  7477. /**
  7478. * File loader for loading glTF files into a scene.
  7479. */
  7480. var GLTFFileLoader = /** @class */ (function () {
  7481. function GLTFFileLoader() {
  7482. // --------------
  7483. // Common options
  7484. // --------------
  7485. /**
  7486. * Raised when the asset has been parsed
  7487. */
  7488. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7489. // ----------
  7490. // V2 options
  7491. // ----------
  7492. /**
  7493. * The coordinate system mode. Defaults to AUTO.
  7494. */
  7495. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  7496. /**
  7497. * The animation start mode. Defaults to FIRST.
  7498. */
  7499. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  7500. /**
  7501. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  7502. */
  7503. this.compileMaterials = false;
  7504. /**
  7505. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  7506. */
  7507. this.useClipPlane = false;
  7508. /**
  7509. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  7510. */
  7511. this.compileShadowGenerators = false;
  7512. /**
  7513. * Defines if the Alpha blended materials are only applied as coverage.
  7514. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  7515. * If true, no extra effects are applied to transparent pixels.
  7516. */
  7517. this.transparencyAsCoverage = false;
  7518. /**
  7519. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  7520. * Enabling will disable offline support and glTF validator.
  7521. * Defaults to false.
  7522. */
  7523. this.useRangeRequests = false;
  7524. /**
  7525. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  7526. */
  7527. this.createInstances = true;
  7528. /**
  7529. * Function called before loading a url referenced by the asset.
  7530. */
  7531. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7532. /**
  7533. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7534. */
  7535. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7536. /**
  7537. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  7538. */
  7539. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7540. /**
  7541. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  7542. */
  7543. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7544. /**
  7545. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  7546. */
  7547. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7548. /**
  7549. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  7550. * For assets with LODs, raised when all of the LODs are complete.
  7551. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7552. */
  7553. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7554. /**
  7555. * Observable raised when an error occurs.
  7556. */
  7557. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7558. /**
  7559. * Observable raised after the loader is disposed.
  7560. */
  7561. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7562. /**
  7563. * Observable raised after a loader extension is created.
  7564. * Set additional options for a loader extension in this event.
  7565. */
  7566. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7567. /**
  7568. * Defines if the loader should validate the asset.
  7569. */
  7570. this.validate = false;
  7571. /**
  7572. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  7573. */
  7574. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7575. this._loader = null;
  7576. /**
  7577. * Name of the loader ("gltf")
  7578. */
  7579. this.name = "gltf";
  7580. /** @hidden */
  7581. this.extensions = {
  7582. ".gltf": { isBinary: false },
  7583. ".glb": { isBinary: true }
  7584. };
  7585. this._logIndentLevel = 0;
  7586. this._loggingEnabled = false;
  7587. /** @hidden */
  7588. this._log = this._logDisabled;
  7589. this._capturePerformanceCounters = false;
  7590. /** @hidden */
  7591. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7592. /** @hidden */
  7593. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7594. }
  7595. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  7596. /**
  7597. * Raised when the asset has been parsed
  7598. */
  7599. set: function (callback) {
  7600. if (this._onParsedObserver) {
  7601. this.onParsedObservable.remove(this._onParsedObserver);
  7602. }
  7603. this._onParsedObserver = this.onParsedObservable.add(callback);
  7604. },
  7605. enumerable: true,
  7606. configurable: true
  7607. });
  7608. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  7609. /**
  7610. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7611. */
  7612. set: function (callback) {
  7613. if (this._onMeshLoadedObserver) {
  7614. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  7615. }
  7616. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  7617. },
  7618. enumerable: true,
  7619. configurable: true
  7620. });
  7621. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  7622. /**
  7623. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  7624. */
  7625. set: function (callback) {
  7626. if (this._onTextureLoadedObserver) {
  7627. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  7628. }
  7629. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  7630. },
  7631. enumerable: true,
  7632. configurable: true
  7633. });
  7634. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  7635. /**
  7636. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  7637. */
  7638. set: function (callback) {
  7639. if (this._onMaterialLoadedObserver) {
  7640. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  7641. }
  7642. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  7643. },
  7644. enumerable: true,
  7645. configurable: true
  7646. });
  7647. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  7648. /**
  7649. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  7650. */
  7651. set: function (callback) {
  7652. if (this._onCameraLoadedObserver) {
  7653. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  7654. }
  7655. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  7656. },
  7657. enumerable: true,
  7658. configurable: true
  7659. });
  7660. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  7661. /**
  7662. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  7663. * For assets with LODs, raised when all of the LODs are complete.
  7664. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7665. */
  7666. set: function (callback) {
  7667. if (this._onCompleteObserver) {
  7668. this.onCompleteObservable.remove(this._onCompleteObserver);
  7669. }
  7670. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  7671. },
  7672. enumerable: true,
  7673. configurable: true
  7674. });
  7675. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  7676. /**
  7677. * Callback raised when an error occurs.
  7678. */
  7679. set: function (callback) {
  7680. if (this._onErrorObserver) {
  7681. this.onErrorObservable.remove(this._onErrorObserver);
  7682. }
  7683. this._onErrorObserver = this.onErrorObservable.add(callback);
  7684. },
  7685. enumerable: true,
  7686. configurable: true
  7687. });
  7688. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  7689. /**
  7690. * Callback raised after the loader is disposed.
  7691. */
  7692. set: function (callback) {
  7693. if (this._onDisposeObserver) {
  7694. this.onDisposeObservable.remove(this._onDisposeObserver);
  7695. }
  7696. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  7697. },
  7698. enumerable: true,
  7699. configurable: true
  7700. });
  7701. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  7702. /**
  7703. * Callback raised after a loader extension is created.
  7704. */
  7705. set: function (callback) {
  7706. if (this._onExtensionLoadedObserver) {
  7707. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  7708. }
  7709. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  7710. },
  7711. enumerable: true,
  7712. configurable: true
  7713. });
  7714. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  7715. /**
  7716. * Defines if the loader logging is enabled.
  7717. */
  7718. get: function () {
  7719. return this._loggingEnabled;
  7720. },
  7721. set: function (value) {
  7722. if (this._loggingEnabled === value) {
  7723. return;
  7724. }
  7725. this._loggingEnabled = value;
  7726. if (this._loggingEnabled) {
  7727. this._log = this._logEnabled;
  7728. }
  7729. else {
  7730. this._log = this._logDisabled;
  7731. }
  7732. },
  7733. enumerable: true,
  7734. configurable: true
  7735. });
  7736. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  7737. /**
  7738. * Defines if the loader should capture performance counters.
  7739. */
  7740. get: function () {
  7741. return this._capturePerformanceCounters;
  7742. },
  7743. set: function (value) {
  7744. if (this._capturePerformanceCounters === value) {
  7745. return;
  7746. }
  7747. this._capturePerformanceCounters = value;
  7748. if (this._capturePerformanceCounters) {
  7749. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  7750. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  7751. }
  7752. else {
  7753. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7754. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7755. }
  7756. },
  7757. enumerable: true,
  7758. configurable: true
  7759. });
  7760. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  7761. /**
  7762. * Callback raised after a loader extension is created.
  7763. */
  7764. set: function (callback) {
  7765. if (this._onValidatedObserver) {
  7766. this.onValidatedObservable.remove(this._onValidatedObserver);
  7767. }
  7768. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  7769. },
  7770. enumerable: true,
  7771. configurable: true
  7772. });
  7773. /**
  7774. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  7775. */
  7776. GLTFFileLoader.prototype.dispose = function () {
  7777. if (this._loader) {
  7778. this._loader.dispose();
  7779. this._loader = null;
  7780. }
  7781. this._clear();
  7782. this.onDisposeObservable.notifyObservers(undefined);
  7783. this.onDisposeObservable.clear();
  7784. };
  7785. /** @hidden */
  7786. GLTFFileLoader.prototype._clear = function () {
  7787. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7788. this.onMeshLoadedObservable.clear();
  7789. this.onTextureLoadedObservable.clear();
  7790. this.onMaterialLoadedObservable.clear();
  7791. this.onCameraLoadedObservable.clear();
  7792. this.onCompleteObservable.clear();
  7793. this.onExtensionLoadedObservable.clear();
  7794. };
  7795. /** @hidden */
  7796. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  7797. var _this = this;
  7798. if (useArrayBuffer) {
  7799. if (this.useRangeRequests) {
  7800. if (this.validate) {
  7801. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  7802. }
  7803. var fileRequests_1 = new Array();
  7804. var aggregatedFileRequest_1 = {
  7805. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  7806. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  7807. };
  7808. var dataBuffer_1 = {
  7809. readAsync: function (byteOffset, byteLength) {
  7810. return new Promise(function (resolve, reject) {
  7811. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  7812. dataBuffer_1.byteLength = Number(webRequest.getResponseHeader("Content-Range").split("/")[1]);
  7813. resolve(new Uint8Array(data));
  7814. }, onProgress, true, true, function (error) {
  7815. reject(error);
  7816. }, function (webRequest) {
  7817. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  7818. }));
  7819. });
  7820. },
  7821. byteLength: 0
  7822. };
  7823. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  7824. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  7825. onSuccess(loaderData);
  7826. }, onError);
  7827. return aggregatedFileRequest_1;
  7828. }
  7829. return scene._requestFile(url, function (data, request) {
  7830. var arrayBuffer = data;
  7831. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7832. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  7833. byteLength: arrayBuffer.byteLength
  7834. })).then(function (loaderData) {
  7835. onSuccess(loaderData, request);
  7836. }, onError);
  7837. }, onProgress, true, true, onError);
  7838. }
  7839. return scene._requestFile(url, function (data, response) {
  7840. _this._validateAsync(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  7841. onSuccess({ json: _this._parseJson(data) }, response);
  7842. }, onProgress, true, false, onError);
  7843. };
  7844. /** @hidden */
  7845. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  7846. var _this = this;
  7847. return scene._readFile(file, function (data) {
  7848. _this._validateAsync(scene, data, "file:", file.name);
  7849. if (useArrayBuffer) {
  7850. var arrayBuffer_1 = data;
  7851. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  7852. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  7853. byteLength: arrayBuffer_1.byteLength
  7854. })).then(onSuccess, onError);
  7855. }
  7856. else {
  7857. onSuccess({ json: _this._parseJson(data) });
  7858. }
  7859. }, onProgress, useArrayBuffer, onError);
  7860. };
  7861. /** @hidden */
  7862. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  7863. var _this = this;
  7864. return Promise.resolve().then(function () {
  7865. _this.onParsedObservable.notifyObservers(data);
  7866. _this.onParsedObservable.clear();
  7867. _this._log("Loading " + (fileName || ""));
  7868. _this._loader = _this._getLoader(data);
  7869. return _this._loader.importMeshAsync(meshesNames, scene, data, rootUrl, onProgress, fileName);
  7870. });
  7871. };
  7872. /** @hidden */
  7873. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7874. var _this = this;
  7875. return Promise.resolve().then(function () {
  7876. _this.onParsedObservable.notifyObservers(data);
  7877. _this.onParsedObservable.clear();
  7878. _this._log("Loading " + (fileName || ""));
  7879. _this._loader = _this._getLoader(data);
  7880. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  7881. });
  7882. };
  7883. /** @hidden */
  7884. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  7885. var _this = this;
  7886. return Promise.resolve().then(function () {
  7887. _this.onParsedObservable.notifyObservers(data);
  7888. _this.onParsedObservable.clear();
  7889. _this._log("Loading " + (fileName || ""));
  7890. _this._loader = _this._getLoader(data);
  7891. // Get materials/textures when loading to add to container
  7892. var materials = [];
  7893. _this.onMaterialLoadedObservable.add(function (material) {
  7894. materials.push(material);
  7895. });
  7896. var textures = [];
  7897. _this.onTextureLoadedObservable.add(function (texture) {
  7898. textures.push(texture);
  7899. });
  7900. return _this._loader.importMeshAsync(null, scene, data, rootUrl, onProgress, fileName).then(function (result) {
  7901. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  7902. Array.prototype.push.apply(container.meshes, result.meshes);
  7903. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  7904. Array.prototype.push.apply(container.skeletons, result.skeletons);
  7905. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  7906. Array.prototype.push.apply(container.materials, materials);
  7907. Array.prototype.push.apply(container.textures, textures);
  7908. container.removeAllFromScene();
  7909. return container;
  7910. });
  7911. });
  7912. };
  7913. /** @hidden */
  7914. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  7915. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  7916. };
  7917. /** @hidden */
  7918. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  7919. this._validateAsync(scene, data);
  7920. return { json: this._parseJson(data) };
  7921. };
  7922. /** @hidden */
  7923. GLTFFileLoader.prototype.createPlugin = function () {
  7924. return new GLTFFileLoader();
  7925. };
  7926. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  7927. /**
  7928. * The loader state or null if the loader is not active.
  7929. */
  7930. get: function () {
  7931. return this._loader ? this._loader.state : null;
  7932. },
  7933. enumerable: true,
  7934. configurable: true
  7935. });
  7936. /**
  7937. * Returns a promise that resolves when the asset is completely loaded.
  7938. * @returns a promise that resolves when the asset is completely loaded.
  7939. */
  7940. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  7941. var _this = this;
  7942. return new Promise(function (resolve, reject) {
  7943. _this.onCompleteObservable.addOnce(function () {
  7944. resolve();
  7945. });
  7946. _this.onErrorObservable.addOnce(function (reason) {
  7947. reject(reason);
  7948. });
  7949. });
  7950. };
  7951. GLTFFileLoader.prototype._validateAsync = function (scene, data, rootUrl, fileName) {
  7952. var _this = this;
  7953. if (rootUrl === void 0) { rootUrl = ""; }
  7954. if (!this.validate || typeof GLTFValidator === "undefined") {
  7955. return Promise.resolve();
  7956. }
  7957. this._startPerformanceCounter("Validate JSON");
  7958. var options = {
  7959. externalResourceFunction: function (uri) {
  7960. return _this.preprocessUrlAsync(rootUrl + uri)
  7961. .then(function (url) { return scene._loadFileAsync(url, undefined, true, true); })
  7962. .then(function (data) { return new Uint8Array(data); });
  7963. }
  7964. };
  7965. if (fileName) {
  7966. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  7967. }
  7968. var promise = (data instanceof ArrayBuffer)
  7969. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  7970. : GLTFValidator.validateString(data, options);
  7971. return promise.then(function (result) {
  7972. _this._endPerformanceCounter("Validate JSON");
  7973. _this.onValidatedObservable.notifyObservers(result);
  7974. _this.onValidatedObservable.clear();
  7975. }, function (reason) {
  7976. _this._endPerformanceCounter("Validate JSON");
  7977. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason);
  7978. _this.onValidatedObservable.clear();
  7979. });
  7980. };
  7981. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  7982. var asset = loaderData.json.asset || {};
  7983. this._log("Asset version: " + asset.version);
  7984. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  7985. asset.generator && this._log("Asset generator: " + asset.generator);
  7986. var version = GLTFFileLoader._parseVersion(asset.version);
  7987. if (!version) {
  7988. throw new Error("Invalid version: " + asset.version);
  7989. }
  7990. if (asset.minVersion !== undefined) {
  7991. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  7992. if (!minVersion) {
  7993. throw new Error("Invalid minimum version: " + asset.minVersion);
  7994. }
  7995. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  7996. throw new Error("Incompatible minimum version: " + asset.minVersion);
  7997. }
  7998. }
  7999. var createLoaders = {
  8000. 1: GLTFFileLoader._CreateGLTF1Loader,
  8001. 2: GLTFFileLoader._CreateGLTF2Loader
  8002. };
  8003. var createLoader = createLoaders[version.major];
  8004. if (!createLoader) {
  8005. throw new Error("Unsupported version: " + asset.version);
  8006. }
  8007. return createLoader(this);
  8008. };
  8009. GLTFFileLoader.prototype._parseJson = function (json) {
  8010. this._startPerformanceCounter("Parse JSON");
  8011. this._log("JSON length: " + json.length);
  8012. var parsed = JSON.parse(json);
  8013. this._endPerformanceCounter("Parse JSON");
  8014. return parsed;
  8015. };
  8016. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8017. var _this = this;
  8018. this._startPerformanceCounter("Unpack Binary");
  8019. // Read magic + version + length + json length + json format
  8020. return dataReader.loadAsync(20).then(function () {
  8021. var Binary = {
  8022. Magic: 0x46546C67
  8023. };
  8024. var magic = dataReader.readUint32();
  8025. if (magic !== Binary.Magic) {
  8026. throw new Error("Unexpected magic: " + magic);
  8027. }
  8028. var version = dataReader.readUint32();
  8029. if (_this.loggingEnabled) {
  8030. _this._log("Binary version: " + version);
  8031. }
  8032. var length = dataReader.readUint32();
  8033. if (length !== dataReader.buffer.byteLength) {
  8034. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8035. }
  8036. var unpacked;
  8037. switch (version) {
  8038. case 1: {
  8039. unpacked = _this._unpackBinaryV1Async(dataReader);
  8040. break;
  8041. }
  8042. case 2: {
  8043. unpacked = _this._unpackBinaryV2Async(dataReader);
  8044. break;
  8045. }
  8046. default: {
  8047. throw new Error("Unsupported version: " + version);
  8048. }
  8049. }
  8050. _this._endPerformanceCounter("Unpack Binary");
  8051. return unpacked;
  8052. });
  8053. };
  8054. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader) {
  8055. var ContentFormat = {
  8056. JSON: 0
  8057. };
  8058. var contentLength = dataReader.readUint32();
  8059. var contentFormat = dataReader.readUint32();
  8060. if (contentFormat !== ContentFormat.JSON) {
  8061. throw new Error("Unexpected content format: " + contentFormat);
  8062. }
  8063. var bodyLength = dataReader.buffer.byteLength - dataReader.byteOffset;
  8064. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8065. if (bodyLength !== 0) {
  8066. var startByteOffset_1 = dataReader.byteOffset;
  8067. data.bin = {
  8068. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8069. byteLength: bodyLength
  8070. };
  8071. }
  8072. return Promise.resolve(data);
  8073. };
  8074. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader) {
  8075. var _this = this;
  8076. var ChunkFormat = {
  8077. JSON: 0x4E4F534A,
  8078. BIN: 0x004E4942
  8079. };
  8080. // Read the JSON chunk header.
  8081. var chunkLength = dataReader.readUint32();
  8082. var chunkFormat = dataReader.readUint32();
  8083. if (chunkFormat !== ChunkFormat.JSON) {
  8084. throw new Error("First chunk format is not JSON");
  8085. }
  8086. // Bail if there are no other chunks.
  8087. if (dataReader.byteOffset + chunkLength === dataReader.buffer.byteLength) {
  8088. return dataReader.loadAsync(chunkLength).then(function () {
  8089. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8090. });
  8091. }
  8092. // Read the JSON chunk and the length and type of the next chunk.
  8093. return dataReader.loadAsync(chunkLength + 8).then(function () {
  8094. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8095. var readAsync = function () {
  8096. var chunkLength = dataReader.readUint32();
  8097. var chunkFormat = dataReader.readUint32();
  8098. switch (chunkFormat) {
  8099. case ChunkFormat.JSON: {
  8100. throw new Error("Unexpected JSON chunk");
  8101. }
  8102. case ChunkFormat.BIN: {
  8103. var startByteOffset_2 = dataReader.byteOffset;
  8104. data.bin = {
  8105. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8106. byteLength: chunkLength
  8107. };
  8108. dataReader.skipBytes(chunkLength);
  8109. break;
  8110. }
  8111. default: {
  8112. // ignore unrecognized chunkFormat
  8113. dataReader.skipBytes(chunkLength);
  8114. break;
  8115. }
  8116. }
  8117. if (dataReader.byteOffset !== dataReader.buffer.byteLength) {
  8118. return dataReader.loadAsync(8).then(readAsync);
  8119. }
  8120. return Promise.resolve(data);
  8121. };
  8122. return readAsync();
  8123. });
  8124. };
  8125. GLTFFileLoader._parseVersion = function (version) {
  8126. if (version === "1.0" || version === "1.0.1") {
  8127. return {
  8128. major: 1,
  8129. minor: 0
  8130. };
  8131. }
  8132. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8133. if (!match) {
  8134. return null;
  8135. }
  8136. return {
  8137. major: parseInt(match[1]),
  8138. minor: parseInt(match[2])
  8139. };
  8140. };
  8141. GLTFFileLoader._compareVersion = function (a, b) {
  8142. if (a.major > b.major) {
  8143. return 1;
  8144. }
  8145. if (a.major < b.major) {
  8146. return -1;
  8147. }
  8148. if (a.minor > b.minor) {
  8149. return 1;
  8150. }
  8151. if (a.minor < b.minor) {
  8152. return -1;
  8153. }
  8154. return 0;
  8155. };
  8156. /** @hidden */
  8157. GLTFFileLoader.prototype._logOpen = function (message) {
  8158. this._log(message);
  8159. this._logIndentLevel++;
  8160. };
  8161. /** @hidden */
  8162. GLTFFileLoader.prototype._logClose = function () {
  8163. --this._logIndentLevel;
  8164. };
  8165. GLTFFileLoader.prototype._logEnabled = function (message) {
  8166. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8167. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8168. };
  8169. GLTFFileLoader.prototype._logDisabled = function (message) {
  8170. };
  8171. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8172. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8173. };
  8174. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8175. };
  8176. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8177. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8178. };
  8179. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8180. };
  8181. // ----------
  8182. // V1 options
  8183. // ----------
  8184. /**
  8185. * 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.
  8186. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8187. * Defaults to true.
  8188. * @hidden
  8189. */
  8190. GLTFFileLoader.IncrementalLoading = true;
  8191. /**
  8192. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8193. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8194. * @hidden
  8195. */
  8196. GLTFFileLoader.HomogeneousCoordinates = false;
  8197. GLTFFileLoader._logSpaces = " ";
  8198. return GLTFFileLoader;
  8199. }());
  8200. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8201. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8202. }
  8203. /***/ }),
  8204. /***/ "./glTF/index.ts":
  8205. /*!***********************!*\
  8206. !*** ./glTF/index.ts ***!
  8207. \***********************/
  8208. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTF1, GLTF2 */
  8209. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8210. "use strict";
  8211. __webpack_require__.r(__webpack_exports__);
  8212. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8213. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8214. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8215. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8216. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8217. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  8218. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_1__; });
  8219. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  8220. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_2__; });
  8221. /***/ }),
  8222. /***/ "./index.ts":
  8223. /*!******************!*\
  8224. !*** ./index.ts ***!
  8225. \******************/
  8226. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTF1, GLTF2, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8227. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8228. "use strict";
  8229. __webpack_require__.r(__webpack_exports__);
  8230. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  8231. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8232. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8233. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8234. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8235. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  8236. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  8237. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  8238. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  8239. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  8240. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  8241. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  8242. /***/ }),
  8243. /***/ "./legacy/legacy-glTF.ts":
  8244. /*!*******************************!*\
  8245. !*** ./legacy/legacy-glTF.ts ***!
  8246. \*******************************/
  8247. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  8248. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8249. "use strict";
  8250. __webpack_require__.r(__webpack_exports__);
  8251. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8252. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8253. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8254. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8255. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8256. /**
  8257. * This is the entry point for the UMD module.
  8258. * The entry point for a future ESM package should be index.ts
  8259. */
  8260. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8261. if (typeof globalObject !== "undefined") {
  8262. globalObject.BABYLON = globalObject.BABYLON || {};
  8263. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  8264. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  8265. }
  8266. }
  8267. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8268. /***/ }),
  8269. /***/ "./legacy/legacy-glTF1.ts":
  8270. /*!********************************!*\
  8271. !*** ./legacy/legacy-glTF1.ts ***!
  8272. \********************************/
  8273. /*! exports provided: GLTF1 */
  8274. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8275. "use strict";
  8276. __webpack_require__.r(__webpack_exports__);
  8277. /* 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");
  8278. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  8279. /**
  8280. * This is the entry point for the UMD module.
  8281. * The entry point for a future ESM package should be index.ts
  8282. */
  8283. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8284. if (typeof globalObject !== "undefined") {
  8285. globalObject.BABYLON = globalObject.BABYLON || {};
  8286. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  8287. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  8288. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  8289. }
  8290. }
  8291. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8292. /***/ }),
  8293. /***/ "./legacy/legacy-glTF2.ts":
  8294. /*!********************************!*\
  8295. !*** ./legacy/legacy-glTF2.ts ***!
  8296. \********************************/
  8297. /*! exports provided: GLTF2 */
  8298. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8299. "use strict";
  8300. __webpack_require__.r(__webpack_exports__);
  8301. /* 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");
  8302. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8303. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  8304. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  8305. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  8306. /**
  8307. * This is the entry point for the UMD module.
  8308. * The entry point for a future ESM package should be index.ts
  8309. */
  8310. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8311. if (typeof globalObject !== "undefined") {
  8312. globalObject.BABYLON = globalObject.BABYLON || {};
  8313. var BABYLON = globalObject.BABYLON;
  8314. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  8315. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  8316. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  8317. var keys = [];
  8318. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  8319. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  8320. keys.push(key);
  8321. }
  8322. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  8323. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  8324. keys.push(key);
  8325. }
  8326. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  8327. // Prevent Reassignment.
  8328. if (keys.indexOf(key) > -1) {
  8329. continue;
  8330. }
  8331. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  8332. }
  8333. }
  8334. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8335. /***/ }),
  8336. /***/ "./legacy/legacy-objFileLoader.ts":
  8337. /*!****************************************!*\
  8338. !*** ./legacy/legacy-objFileLoader.ts ***!
  8339. \****************************************/
  8340. /*! exports provided: MTLFileLoader, OBJFileLoader */
  8341. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8342. "use strict";
  8343. __webpack_require__.r(__webpack_exports__);
  8344. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  8345. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  8346. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  8347. /**
  8348. * This is the entry point for the UMD module.
  8349. * The entry point for a future ESM package should be index.ts
  8350. */
  8351. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8352. if (typeof globalObject !== "undefined") {
  8353. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  8354. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  8355. }
  8356. }
  8357. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8358. /***/ }),
  8359. /***/ "./legacy/legacy-stlFileLoader.ts":
  8360. /*!****************************************!*\
  8361. !*** ./legacy/legacy-stlFileLoader.ts ***!
  8362. \****************************************/
  8363. /*! exports provided: STLFileLoader */
  8364. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8365. "use strict";
  8366. __webpack_require__.r(__webpack_exports__);
  8367. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  8368. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  8369. /**
  8370. * This is the entry point for the UMD module.
  8371. * The entry point for a future ESM package should be index.ts
  8372. */
  8373. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8374. if (typeof globalObject !== "undefined") {
  8375. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  8376. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  8377. }
  8378. }
  8379. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8380. /***/ }),
  8381. /***/ "./legacy/legacy.ts":
  8382. /*!**************************!*\
  8383. !*** ./legacy/legacy.ts ***!
  8384. \**************************/
  8385. /*! exports provided: GLTF1, GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8386. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8387. "use strict";
  8388. __webpack_require__.r(__webpack_exports__);
  8389. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  8390. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  8391. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  8392. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  8393. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  8394. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  8395. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  8396. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  8397. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  8398. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  8399. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  8400. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  8401. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  8402. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  8403. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  8404. /***/ }),
  8405. /***/ "babylonjs/Misc/observable":
  8406. /*!****************************************************************************************************!*\
  8407. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  8408. \****************************************************************************************************/
  8409. /*! no static exports found */
  8410. /***/ (function(module, exports) {
  8411. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__;
  8412. /***/ })
  8413. /******/ });
  8414. });
  8415. //# sourceMappingURL=babylonjs.loaders.js.map