babylonjs.loaders.js 416 KB

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