babylonjs.loaders.js 410 KB

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