babylon.glTFFileLoader.js 337 KB

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