babylon.glTFFileLoader.js 398 KB

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