babylonjs.loaders.js 408 KB

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