babylonjs.loaders.js 401 KB

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