babylon.glTFFileLoader.js 359 KB

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