babylonjs.loaders.js 467 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391
  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.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. /***/ "./OBJ/index.ts":
  324. /*!**********************!*\
  325. !*** ./OBJ/index.ts ***!
  326. \**********************/
  327. /*! exports provided: MTLFileLoader, OBJFileLoader */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  332. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  333. /* harmony import */ var _objFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./objFileLoader */ "./OBJ/objFileLoader.ts");
  334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _objFileLoader__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  335. /***/ }),
  336. /***/ "./OBJ/mtlFileLoader.ts":
  337. /*!******************************!*\
  338. !*** ./OBJ/mtlFileLoader.ts ***!
  339. \******************************/
  340. /*! exports provided: MTLFileLoader */
  341. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  342. "use strict";
  343. __webpack_require__.r(__webpack_exports__);
  344. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return MTLFileLoader; });
  345. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  346. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  347. /**
  348. * Class reading and parsing the MTL file bundled with the obj file.
  349. */
  350. var MTLFileLoader = /** @class */ (function () {
  351. function MTLFileLoader() {
  352. /**
  353. * All material loaded from the mtl will be set here
  354. */
  355. this.materials = [];
  356. }
  357. /**
  358. * This function will read the mtl file and create each material described inside
  359. * This function could be improve by adding :
  360. * -some component missing (Ni, Tf...)
  361. * -including the specific options available
  362. *
  363. * @param scene defines the scene the material will be created in
  364. * @param data defines the mtl data to parse
  365. * @param rootUrl defines the rooturl to use in order to load relative dependencies
  366. * @param forAssetContainer defines if the material should be registered in the scene
  367. */
  368. MTLFileLoader.prototype.parseMTL = function (scene, data, rootUrl, forAssetContainer) {
  369. if (data instanceof ArrayBuffer) {
  370. return;
  371. }
  372. //Split the lines from the file
  373. var lines = data.split('\n');
  374. //Space char
  375. var delimiter_pattern = /\s+/;
  376. //Array with RGB colors
  377. var color;
  378. //New material
  379. var material = null;
  380. //Look at each line
  381. for (var i = 0; i < lines.length; i++) {
  382. var line = lines[i].trim();
  383. // Blank line or comment
  384. if (line.length === 0 || line.charAt(0) === '#') {
  385. continue;
  386. }
  387. //Get the first parameter (keyword)
  388. var pos = line.indexOf(' ');
  389. var key = (pos >= 0) ? line.substring(0, pos) : line;
  390. key = key.toLowerCase();
  391. //Get the data following the key
  392. var value = (pos >= 0) ? line.substring(pos + 1).trim() : "";
  393. //This mtl keyword will create the new material
  394. if (key === "newmtl") {
  395. //Check if it is the first material.
  396. // Materials specifications are described after this keyword.
  397. if (material) {
  398. //Add the previous material in the material array.
  399. this.materials.push(material);
  400. }
  401. //Create a new material.
  402. // value is the name of the material read in the mtl file
  403. scene._blockEntityCollection = forAssetContainer;
  404. material = new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"](value, scene);
  405. scene._blockEntityCollection = false;
  406. }
  407. else if (key === "kd" && material) {
  408. // Diffuse color (color under white light) using RGB values
  409. //value = "r g b"
  410. color = value.split(delimiter_pattern, 3).map(parseFloat);
  411. //color = [r,g,b]
  412. //Set tghe color into the material
  413. material.diffuseColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  414. }
  415. else if (key === "ka" && material) {
  416. // Ambient color (color under shadow) using RGB values
  417. //value = "r g b"
  418. color = value.split(delimiter_pattern, 3).map(parseFloat);
  419. //color = [r,g,b]
  420. //Set tghe color into the material
  421. material.ambientColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  422. }
  423. else if (key === "ks" && material) {
  424. // Specular color (color when light is reflected from shiny surface) using RGB values
  425. //value = "r g b"
  426. color = value.split(delimiter_pattern, 3).map(parseFloat);
  427. //color = [r,g,b]
  428. //Set the color into the material
  429. material.specularColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  430. }
  431. else if (key === "ke" && material) {
  432. // Emissive color using RGB values
  433. color = value.split(delimiter_pattern, 3).map(parseFloat);
  434. material.emissiveColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(color);
  435. }
  436. else if (key === "ns" && material) {
  437. //value = "Integer"
  438. material.specularPower = parseFloat(value);
  439. }
  440. else if (key === "d" && material) {
  441. //d is dissolve for current material. It mean alpha for BABYLON
  442. material.alpha = parseFloat(value);
  443. //Texture
  444. //This part can be improved by adding the possible options of texture
  445. }
  446. else if (key === "map_ka" && material) {
  447. // ambient texture map with a loaded image
  448. //We must first get the folder of the image
  449. material.ambientTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  450. }
  451. else if (key === "map_kd" && material) {
  452. // Diffuse texture map with a loaded image
  453. material.diffuseTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  454. }
  455. else if (key === "map_ks" && material) {
  456. // Specular texture map with a loaded image
  457. //We must first get the folder of the image
  458. material.specularTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  459. }
  460. else if (key === "map_ns") {
  461. //Specular
  462. //Specular highlight component
  463. //We must first get the folder of the image
  464. //
  465. //Not supported by BABYLON
  466. //
  467. // continue;
  468. }
  469. else if (key === "map_bump" && material) {
  470. //The bump texture
  471. material.bumpTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  472. }
  473. else if (key === "map_d" && material) {
  474. // The dissolve of the material
  475. material.opacityTexture = MTLFileLoader._getTexture(rootUrl, value, scene);
  476. //Options for illumination
  477. }
  478. else if (key === "illum") {
  479. //Illumination
  480. if (value === "0") {
  481. //That mean Kd == Kd
  482. }
  483. else if (value === "1") {
  484. //Color on and Ambient on
  485. }
  486. else if (value === "2") {
  487. //Highlight on
  488. }
  489. else if (value === "3") {
  490. //Reflection on and Ray trace on
  491. }
  492. else if (value === "4") {
  493. //Transparency: Glass on, Reflection: Ray trace on
  494. }
  495. else if (value === "5") {
  496. //Reflection: Fresnel on and Ray trace on
  497. }
  498. else if (value === "6") {
  499. //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
  500. }
  501. else if (value === "7") {
  502. //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
  503. }
  504. else if (value === "8") {
  505. //Reflection on and Ray trace off
  506. }
  507. else if (value === "9") {
  508. //Transparency: Glass on, Reflection: Ray trace off
  509. }
  510. else if (value === "10") {
  511. //Casts shadows onto invisible surfaces
  512. }
  513. }
  514. else {
  515. // console.log("Unhandled expression at line : " + i +'\n' + "with value : " + line);
  516. }
  517. }
  518. //At the end of the file, add the last material
  519. if (material) {
  520. this.materials.push(material);
  521. }
  522. };
  523. /**
  524. * Gets the texture for the material.
  525. *
  526. * If the material is imported from input file,
  527. * We sanitize the url to ensure it takes the textre from aside the material.
  528. *
  529. * @param rootUrl The root url to load from
  530. * @param value The value stored in the mtl
  531. * @return The Texture
  532. */
  533. MTLFileLoader._getTexture = function (rootUrl, value, scene) {
  534. if (!value) {
  535. return null;
  536. }
  537. var url = rootUrl;
  538. // Load from input file.
  539. if (rootUrl === "file:") {
  540. var lastDelimiter = value.lastIndexOf("\\");
  541. if (lastDelimiter === -1) {
  542. lastDelimiter = value.lastIndexOf("/");
  543. }
  544. if (lastDelimiter > -1) {
  545. url += value.substr(lastDelimiter + 1);
  546. }
  547. else {
  548. url += value;
  549. }
  550. }
  551. // Not from input file.
  552. else {
  553. url += value;
  554. }
  555. return new babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);
  556. };
  557. /**
  558. * Invert Y-Axis of referenced textures on load
  559. */
  560. MTLFileLoader.INVERT_TEXTURE_Y = true;
  561. return MTLFileLoader;
  562. }());
  563. /***/ }),
  564. /***/ "./OBJ/objFileLoader.ts":
  565. /*!******************************!*\
  566. !*** ./OBJ/objFileLoader.ts ***!
  567. \******************************/
  568. /*! exports provided: OBJFileLoader */
  569. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  570. "use strict";
  571. __webpack_require__.r(__webpack_exports__);
  572. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return OBJFileLoader; });
  573. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  574. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  575. /* harmony import */ var _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mtlFileLoader */ "./OBJ/mtlFileLoader.ts");
  576. /**
  577. * OBJ file type loader.
  578. * This is a babylon scene loader plugin.
  579. */
  580. var OBJFileLoader = /** @class */ (function () {
  581. /**
  582. * Creates loader for .OBJ files
  583. *
  584. * @param meshLoadOptions options for loading and parsing OBJ/MTL files.
  585. */
  586. function OBJFileLoader(meshLoadOptions) {
  587. /**
  588. * Defines the name of the plugin.
  589. */
  590. this.name = "obj";
  591. /**
  592. * Defines the extension the plugin is able to load.
  593. */
  594. this.extensions = ".obj";
  595. /** @hidden */
  596. this.obj = /^o/;
  597. /** @hidden */
  598. this.group = /^g/;
  599. /** @hidden */
  600. this.mtllib = /^mtllib /;
  601. /** @hidden */
  602. this.usemtl = /^usemtl /;
  603. /** @hidden */
  604. this.smooth = /^s /;
  605. /** @hidden */
  606. this.vertexPattern = /v( +[\d|\.|\+|\-|e|E]+){3,7}/;
  607. // vn float float float
  608. /** @hidden */
  609. this.normalPattern = /vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  610. // vt float float
  611. /** @hidden */
  612. this.uvPattern = /vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/;
  613. // f vertex vertex vertex ...
  614. /** @hidden */
  615. this.facePattern1 = /f\s+(([\d]{1,}[\s]?){3,})+/;
  616. // f vertex/uvs vertex/uvs vertex/uvs ...
  617. /** @hidden */
  618. this.facePattern2 = /f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  619. // f vertex/uvs/normal vertex/uvs/normal vertex/uvs/normal ...
  620. /** @hidden */
  621. this.facePattern3 = /f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/;
  622. // f vertex//normal vertex//normal vertex//normal ...
  623. /** @hidden */
  624. this.facePattern4 = /f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/;
  625. // f -vertex/-uvs/-normal -vertex/-uvs/-normal -vertex/-uvs/-normal ...
  626. /** @hidden */
  627. this.facePattern5 = /f\s+(((-[\d]{1,}\/-[\d]{1,}\/-[\d]{1,}[\s]?){3,})+)/;
  628. this._forAssetContainer = false;
  629. this._meshLoadOptions = meshLoadOptions || OBJFileLoader.currentMeshLoadOptions;
  630. }
  631. Object.defineProperty(OBJFileLoader, "INVERT_TEXTURE_Y", {
  632. /**
  633. * Invert Y-Axis of referenced textures on load
  634. */
  635. get: function () {
  636. return _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y;
  637. },
  638. set: function (value) {
  639. _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"].INVERT_TEXTURE_Y = value;
  640. },
  641. enumerable: true,
  642. configurable: true
  643. });
  644. Object.defineProperty(OBJFileLoader, "currentMeshLoadOptions", {
  645. get: function () {
  646. return {
  647. ComputeNormals: OBJFileLoader.COMPUTE_NORMALS,
  648. ImportVertexColors: OBJFileLoader.IMPORT_VERTEX_COLORS,
  649. InvertY: OBJFileLoader.INVERT_Y,
  650. InvertTextureY: OBJFileLoader.INVERT_TEXTURE_Y,
  651. UVScaling: OBJFileLoader.UV_SCALING,
  652. MaterialLoadingFailsSilently: OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY,
  653. OptimizeWithUV: OBJFileLoader.OPTIMIZE_WITH_UV,
  654. SkipMaterials: OBJFileLoader.SKIP_MATERIALS
  655. };
  656. },
  657. enumerable: true,
  658. configurable: true
  659. });
  660. /**
  661. * Calls synchronously the MTL file attached to this obj.
  662. * Load function or importMesh function don't enable to load 2 files in the same time asynchronously.
  663. * Without this function materials are not displayed in the first frame (but displayed after).
  664. * In consequence it is impossible to get material information in your HTML file
  665. *
  666. * @param url The URL of the MTL file
  667. * @param rootUrl
  668. * @param onSuccess Callback function to be called when the MTL file is loaded
  669. * @private
  670. */
  671. OBJFileLoader.prototype._loadMTL = function (url, rootUrl, onSuccess, onFailure) {
  672. //The complete path to the mtl file
  673. var pathOfFile = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].BaseUrl + rootUrl + url;
  674. // Loads through the babylon tools to allow fileInput search.
  675. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(pathOfFile, onSuccess, undefined, undefined, false, function (request, exception) {
  676. onFailure(pathOfFile, exception);
  677. });
  678. };
  679. /**
  680. * Instantiates a OBJ file loader plugin.
  681. * @returns the created plugin
  682. */
  683. OBJFileLoader.prototype.createPlugin = function () {
  684. return new OBJFileLoader(OBJFileLoader.currentMeshLoadOptions);
  685. };
  686. /**
  687. * If the data string can be loaded directly.
  688. *
  689. * @param data string containing the file data
  690. * @returns if the data can be loaded directly
  691. */
  692. OBJFileLoader.prototype.canDirectLoad = function (data) {
  693. return false;
  694. };
  695. /**
  696. * Imports one or more meshes from the loaded OBJ data and adds them to the scene
  697. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  698. * @param scene the scene the meshes should be added to
  699. * @param data the OBJ data to load
  700. * @param rootUrl root url to load from
  701. * @param onProgress event that fires when loading progress has occured
  702. * @param fileName Defines the name of the file to load
  703. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  704. */
  705. OBJFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  706. //get the meshes from OBJ file
  707. return this._parseSolid(meshesNames, scene, data, rootUrl).then(function (meshes) {
  708. return {
  709. meshes: meshes,
  710. particleSystems: [],
  711. skeletons: [],
  712. animationGroups: []
  713. };
  714. });
  715. };
  716. /**
  717. * Imports all objects from the loaded OBJ data and adds them to the scene
  718. * @param scene the scene the objects should be added to
  719. * @param data the OBJ data to load
  720. * @param rootUrl root url to load from
  721. * @param onProgress event that fires when loading progress has occured
  722. * @param fileName Defines the name of the file to load
  723. * @returns a promise which completes when objects have been loaded to the scene
  724. */
  725. OBJFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  726. //Get the 3D model
  727. return this.importMeshAsync(null, scene, data, rootUrl, onProgress).then(function () {
  728. // return void
  729. });
  730. };
  731. /**
  732. * Load into an asset container.
  733. * @param scene The scene to load into
  734. * @param data The data to import
  735. * @param rootUrl The root url for scene and resources
  736. * @param onProgress The callback when the load progresses
  737. * @param fileName Defines the name of the file to load
  738. * @returns The loaded asset container
  739. */
  740. OBJFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  741. var _this = this;
  742. this._forAssetContainer = true;
  743. return this.importMeshAsync(null, scene, data, rootUrl).then(function (result) {
  744. var container = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  745. result.meshes.forEach(function (mesh) { return container.meshes.push(mesh); });
  746. result.meshes.forEach(function (mesh) {
  747. var material = mesh.material;
  748. if (material) {
  749. // Materials
  750. if (container.materials.indexOf(material) == -1) {
  751. container.materials.push(material);
  752. // Textures
  753. var textures = material.getActiveTextures();
  754. textures.forEach(function (t) {
  755. if (container.textures.indexOf(t) == -1) {
  756. container.textures.push(t);
  757. }
  758. });
  759. }
  760. }
  761. });
  762. _this._forAssetContainer = false;
  763. return container;
  764. }).catch(function (ex) {
  765. _this._forAssetContainer = false;
  766. throw ex;
  767. });
  768. };
  769. /**
  770. * Read the OBJ file and create an Array of meshes.
  771. * Each mesh contains all information given by the OBJ and the MTL file.
  772. * i.e. vertices positions and indices, optional normals values, optional UV values, optional material
  773. *
  774. * @param meshesNames
  775. * @param scene Scene The scene where are displayed the data
  776. * @param data String The content of the obj file
  777. * @param rootUrl String The path to the folder
  778. * @returns Array<AbstractMesh>
  779. * @private
  780. */
  781. OBJFileLoader.prototype._parseSolid = function (meshesNames, scene, data, rootUrl) {
  782. var _this = this;
  783. var positions = []; //values for the positions of vertices
  784. var normals = []; //Values for the normals
  785. var uvs = []; //Values for the textures
  786. var colors = [];
  787. var meshesFromObj = []; //[mesh] Contains all the obj meshes
  788. var handledMesh; //The current mesh of meshes array
  789. var indicesForBabylon = []; //The list of indices for VertexData
  790. var wrappedPositionForBabylon = []; //The list of position in vectors
  791. var wrappedUvsForBabylon = []; //Array with all value of uvs to match with the indices
  792. var wrappedColorsForBabylon = []; // Array with all color values to match with the indices
  793. var wrappedNormalsForBabylon = []; //Array with all value of normals to match with the indices
  794. var tuplePosNorm = []; //Create a tuple with indice of Position, Normal, UV [pos, norm, uvs]
  795. var curPositionInIndices = 0;
  796. var hasMeshes = false; //Meshes are defined in the file
  797. var unwrappedPositionsForBabylon = []; //Value of positionForBabylon w/o Vector3() [x,y,z]
  798. var unwrappedColorsForBabylon = []; // Value of colorForBabylon w/o Color4() [r,g,b,a]
  799. var unwrappedNormalsForBabylon = []; //Value of normalsForBabylon w/o Vector3() [x,y,z]
  800. var unwrappedUVForBabylon = []; //Value of uvsForBabylon w/o Vector3() [x,y,z]
  801. var triangles = []; //Indices from new triangles coming from polygons
  802. var materialNameFromObj = ""; //The name of the current material
  803. var fileToLoad = ""; //The name of the mtlFile to load
  804. var materialsFromMTLFile = new _mtlFileLoader__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]();
  805. var objMeshName = ""; //The name of the current obj mesh
  806. var increment = 1; //Id for meshes created by the multimaterial
  807. var isFirstMaterial = true;
  808. var grayColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](0.5, 0.5, 0.5, 1);
  809. /**
  810. * Search for obj in the given array.
  811. * This function is called to check if a couple of data already exists in an array.
  812. *
  813. * If found, returns the index of the founded tuple index. Returns -1 if not found
  814. * @param arr Array<{ normals: Array<number>, idx: Array<number> }>
  815. * @param obj Array<number>
  816. * @returns {boolean}
  817. */
  818. var isInArray = function (arr, obj) {
  819. if (!arr[obj[0]]) {
  820. arr[obj[0]] = { normals: [], idx: [] };
  821. }
  822. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  823. return idx === -1 ? -1 : arr[obj[0]].idx[idx];
  824. };
  825. var isInArrayUV = function (arr, obj) {
  826. if (!arr[obj[0]]) {
  827. arr[obj[0]] = { normals: [], idx: [], uv: [] };
  828. }
  829. var idx = arr[obj[0]].normals.indexOf(obj[1]);
  830. if (idx != 1 && (obj[2] === arr[obj[0]].uv[idx])) {
  831. return arr[obj[0]].idx[idx];
  832. }
  833. return -1;
  834. };
  835. /**
  836. * This function set the data for each triangle.
  837. * Data are position, normals and uvs
  838. * If a tuple of (position, normal) is not set, add the data into the corresponding array
  839. * If the tuple already exist, add only their indice
  840. *
  841. * @param indicePositionFromObj Integer The index in positions array
  842. * @param indiceUvsFromObj Integer The index in uvs array
  843. * @param indiceNormalFromObj Integer The index in normals array
  844. * @param positionVectorFromOBJ Vector3 The value of position at index objIndice
  845. * @param textureVectorFromOBJ Vector3 The value of uvs
  846. * @param normalsVectorFromOBJ Vector3 The value of normals at index objNormale
  847. */
  848. var setData = function (indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positionVectorFromOBJ, textureVectorFromOBJ, normalsVectorFromOBJ, positionColorsFromOBJ) {
  849. //Check if this tuple already exists in the list of tuples
  850. var _index;
  851. if (_this._meshLoadOptions.OptimizeWithUV) {
  852. _index = isInArrayUV(tuplePosNorm, [
  853. indicePositionFromObj,
  854. indiceNormalFromObj,
  855. indiceUvsFromObj
  856. ]);
  857. }
  858. else {
  859. _index = isInArray(tuplePosNorm, [
  860. indicePositionFromObj,
  861. indiceNormalFromObj
  862. ]);
  863. }
  864. //If it not exists
  865. if (_index === -1) {
  866. //Add an new indice.
  867. //The array of indices is only an array with his length equal to the number of triangles - 1.
  868. //We add vertices data in this order
  869. indicesForBabylon.push(wrappedPositionForBabylon.length);
  870. //Push the position of vertice for Babylon
  871. //Each element is a Vector3(x,y,z)
  872. wrappedPositionForBabylon.push(positionVectorFromOBJ);
  873. //Push the uvs for Babylon
  874. //Each element is a Vector3(u,v)
  875. wrappedUvsForBabylon.push(textureVectorFromOBJ);
  876. //Push the normals for Babylon
  877. //Each element is a Vector3(x,y,z)
  878. wrappedNormalsForBabylon.push(normalsVectorFromOBJ);
  879. if (positionColorsFromOBJ !== undefined) {
  880. //Push the colors for Babylon
  881. //Each element is a BABYLON.Color4(r,g,b,a)
  882. wrappedColorsForBabylon.push(positionColorsFromOBJ);
  883. }
  884. //Add the tuple in the comparison list
  885. tuplePosNorm[indicePositionFromObj].normals.push(indiceNormalFromObj);
  886. tuplePosNorm[indicePositionFromObj].idx.push(curPositionInIndices++);
  887. if (_this._meshLoadOptions.OptimizeWithUV) {
  888. tuplePosNorm[indicePositionFromObj].uv.push(indiceUvsFromObj);
  889. }
  890. }
  891. else {
  892. //The tuple already exists
  893. //Add the index of the already existing tuple
  894. //At this index we can get the value of position, normal, color and uvs of vertex
  895. indicesForBabylon.push(_index);
  896. }
  897. };
  898. /**
  899. * Transform Vector() and BABYLON.Color() objects into numbers in an array
  900. */
  901. var unwrapData = function () {
  902. //Every array has the same length
  903. for (var l = 0; l < wrappedPositionForBabylon.length; l++) {
  904. //Push the x, y, z values of each element in the unwrapped array
  905. unwrappedPositionsForBabylon.push(wrappedPositionForBabylon[l].x, wrappedPositionForBabylon[l].y, wrappedPositionForBabylon[l].z);
  906. unwrappedNormalsForBabylon.push(wrappedNormalsForBabylon[l].x, wrappedNormalsForBabylon[l].y, wrappedNormalsForBabylon[l].z);
  907. unwrappedUVForBabylon.push(wrappedUvsForBabylon[l].x, wrappedUvsForBabylon[l].y); //z is an optional value not supported by BABYLON
  908. }
  909. if (_this._meshLoadOptions.ImportVertexColors === true) {
  910. //Push the r, g, b, a values of each element in the unwrapped array
  911. unwrappedColorsForBabylon.push(wrappedColorsForBabylon[l].r, wrappedColorsForBabylon[l].g, wrappedColorsForBabylon[l].b, wrappedColorsForBabylon[l].a);
  912. }
  913. // Reset arrays for the next new meshes
  914. wrappedPositionForBabylon = [];
  915. wrappedNormalsForBabylon = [];
  916. wrappedUvsForBabylon = [];
  917. wrappedColorsForBabylon = [];
  918. tuplePosNorm = [];
  919. curPositionInIndices = 0;
  920. };
  921. /**
  922. * Create triangles from polygons
  923. * It is important to notice that a triangle is a polygon
  924. * We get 5 patterns of face defined in OBJ File :
  925. * facePattern1 = ["1","2","3","4","5","6"]
  926. * facePattern2 = ["1/1","2/2","3/3","4/4","5/5","6/6"]
  927. * facePattern3 = ["1/1/1","2/2/2","3/3/3","4/4/4","5/5/5","6/6/6"]
  928. * facePattern4 = ["1//1","2//2","3//3","4//4","5//5","6//6"]
  929. * facePattern5 = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-4/-4/-4","-5/-5/-5","-6/-6/-6"]
  930. * Each pattern is divided by the same method
  931. * @param face Array[String] The indices of elements
  932. * @param v Integer The variable to increment
  933. */
  934. var getTriangles = function (faces, v) {
  935. //Work for each element of the array
  936. for (var faceIndex = v; faceIndex < faces.length - 1; faceIndex++) {
  937. //Add on the triangle variable the indexes to obtain triangles
  938. triangles.push(faces[0], faces[faceIndex], faces[faceIndex + 1]);
  939. }
  940. //Result obtained after 2 iterations:
  941. //Pattern1 => triangle = ["1","2","3","1","3","4"];
  942. //Pattern2 => triangle = ["1/1","2/2","3/3","1/1","3/3","4/4"];
  943. //Pattern3 => triangle = ["1/1/1","2/2/2","3/3/3","1/1/1","3/3/3","4/4/4"];
  944. //Pattern4 => triangle = ["1//1","2//2","3//3","1//1","3//3","4//4"];
  945. //Pattern5 => triangle = ["-1/-1/-1","-2/-2/-2","-3/-3/-3","-1/-1/-1","-3/-3/-3","-4/-4/-4"];
  946. };
  947. /**
  948. * Create triangles and push the data for each polygon for the pattern 1
  949. * In this pattern we get vertice positions
  950. * @param face
  951. * @param v
  952. */
  953. var setDataForCurrentFaceWithPattern1 = function (face, v) {
  954. //Get the indices of triangles for each polygon
  955. getTriangles(face, v);
  956. //For each element in the triangles array.
  957. //This var could contains 1 to an infinity of triangles
  958. for (var k = 0; k < triangles.length; k++) {
  959. // Set position indice
  960. var indicePositionFromObj = parseInt(triangles[k]) - 1;
  961. setData(indicePositionFromObj, 0, 0, //In the pattern 1, normals and uvs are not defined
  962. positions[indicePositionFromObj], //Get the vectors data
  963. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Create default vectors
  964. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  965. }
  966. //Reset variable for the next line
  967. triangles = [];
  968. };
  969. /**
  970. * Create triangles and push the data for each polygon for the pattern 2
  971. * In this pattern we get vertice positions and uvsu
  972. * @param face
  973. * @param v
  974. */
  975. var setDataForCurrentFaceWithPattern2 = function (face, v) {
  976. //Get the indices of triangles for each polygon
  977. getTriangles(face, v);
  978. for (var k = 0; k < triangles.length; k++) {
  979. //triangle[k] = "1/1"
  980. //Split the data for getting position and uv
  981. var point = triangles[k].split("/"); // ["1", "1"]
  982. //Set position indice
  983. var indicePositionFromObj = parseInt(point[0]) - 1;
  984. //Set uv indice
  985. var indiceUvsFromObj = parseInt(point[1]) - 1;
  986. setData(indicePositionFromObj, indiceUvsFromObj, 0, //Default value for normals
  987. positions[indicePositionFromObj], //Get the values for each element
  988. uvs[indiceUvsFromObj], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Up(), //Default value for normals
  989. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  990. }
  991. //Reset variable for the next line
  992. triangles = [];
  993. };
  994. /**
  995. * Create triangles and push the data for each polygon for the pattern 3
  996. * In this pattern we get vertice positions, uvs and normals
  997. * @param face
  998. * @param v
  999. */
  1000. var setDataForCurrentFaceWithPattern3 = function (face, v) {
  1001. //Get the indices of triangles for each polygon
  1002. getTriangles(face, v);
  1003. for (var k = 0; k < triangles.length; k++) {
  1004. //triangle[k] = "1/1/1"
  1005. //Split the data for getting position, uv, and normals
  1006. var point = triangles[k].split("/"); // ["1", "1", "1"]
  1007. // Set position indice
  1008. var indicePositionFromObj = parseInt(point[0]) - 1;
  1009. // Set uv indice
  1010. var indiceUvsFromObj = parseInt(point[1]) - 1;
  1011. // Set normal indice
  1012. var indiceNormalFromObj = parseInt(point[2]) - 1;
  1013. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj] //Set the vector for each component
  1014. );
  1015. }
  1016. //Reset variable for the next line
  1017. triangles = [];
  1018. };
  1019. /**
  1020. * Create triangles and push the data for each polygon for the pattern 4
  1021. * In this pattern we get vertice positions and normals
  1022. * @param face
  1023. * @param v
  1024. */
  1025. var setDataForCurrentFaceWithPattern4 = function (face, v) {
  1026. getTriangles(face, v);
  1027. for (var k = 0; k < triangles.length; k++) {
  1028. //triangle[k] = "1//1"
  1029. //Split the data for getting position and normals
  1030. var point = triangles[k].split("//"); // ["1", "1"]
  1031. // We check indices, and normals
  1032. var indicePositionFromObj = parseInt(point[0]) - 1;
  1033. var indiceNormalFromObj = parseInt(point[1]) - 1;
  1034. setData(indicePositionFromObj, 1, //Default value for uv
  1035. indiceNormalFromObj, positions[indicePositionFromObj], //Get each vector of data
  1036. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero(), normals[indiceNormalFromObj], _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1037. }
  1038. //Reset variable for the next line
  1039. triangles = [];
  1040. };
  1041. /**
  1042. * Create triangles and push the data for each polygon for the pattern 3
  1043. * In this pattern we get vertice positions, uvs and normals
  1044. * @param face
  1045. * @param v
  1046. */
  1047. var setDataForCurrentFaceWithPattern5 = function (face, v) {
  1048. //Get the indices of triangles for each polygon
  1049. getTriangles(face, v);
  1050. for (var k = 0; k < triangles.length; k++) {
  1051. //triangle[k] = "-1/-1/-1"
  1052. //Split the data for getting position, uv, and normals
  1053. var point = triangles[k].split("/"); // ["-1", "-1", "-1"]
  1054. // Set position indice
  1055. var indicePositionFromObj = positions.length + parseInt(point[0]);
  1056. // Set uv indice
  1057. var indiceUvsFromObj = uvs.length + parseInt(point[1]);
  1058. // Set normal indice
  1059. var indiceNormalFromObj = normals.length + parseInt(point[2]);
  1060. setData(indicePositionFromObj, indiceUvsFromObj, indiceNormalFromObj, positions[indicePositionFromObj], uvs[indiceUvsFromObj], normals[indiceNormalFromObj], //Set the vector for each component
  1061. _this._meshLoadOptions.ImportVertexColors === true ? colors[indicePositionFromObj] : undefined);
  1062. }
  1063. //Reset variable for the next line
  1064. triangles = [];
  1065. };
  1066. var addPreviousObjMesh = function () {
  1067. //Check if it is not the first mesh. Otherwise we don't have data.
  1068. if (meshesFromObj.length > 0) {
  1069. //Get the previous mesh for applying the data about the faces
  1070. //=> in obj file, faces definition append after the name of the mesh
  1071. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1072. //Set the data into Array for the mesh
  1073. unwrapData();
  1074. // Reverse tab. Otherwise face are displayed in the wrong sens
  1075. indicesForBabylon.reverse();
  1076. //Set the information for the mesh
  1077. //Slice the array to avoid rewriting because of the fact this is the same var which be rewrited
  1078. handledMesh.indices = indicesForBabylon.slice();
  1079. handledMesh.positions = unwrappedPositionsForBabylon.slice();
  1080. handledMesh.normals = unwrappedNormalsForBabylon.slice();
  1081. handledMesh.uvs = unwrappedUVForBabylon.slice();
  1082. if (_this._meshLoadOptions.ImportVertexColors === true) {
  1083. handledMesh.colors = unwrappedColorsForBabylon.slice();
  1084. }
  1085. //Reset the array for the next mesh
  1086. indicesForBabylon = [];
  1087. unwrappedPositionsForBabylon = [];
  1088. unwrappedColorsForBabylon = [];
  1089. unwrappedNormalsForBabylon = [];
  1090. unwrappedUVForBabylon = [];
  1091. }
  1092. };
  1093. //Main function
  1094. //Split the file into lines
  1095. var lines = data.split('\n');
  1096. //Look at each line
  1097. for (var i = 0; i < lines.length; i++) {
  1098. var line = lines[i].trim().replace(/\s\s/g, " ");
  1099. var result;
  1100. //Comment or newLine
  1101. if (line.length === 0 || line.charAt(0) === '#') {
  1102. continue;
  1103. //Get information about one position possible for the vertices
  1104. }
  1105. else if (this.vertexPattern.test(line)) {
  1106. result = line.match(/[^ ]+/g); // match will return non-null due to passing regex pattern
  1107. // Value of result with line: "v 1.0 2.0 3.0"
  1108. // ["v", "1.0", "2.0", "3.0"]
  1109. // Create a Vector3 with the position x, y, z
  1110. positions.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1111. if (this._meshLoadOptions.ImportVertexColors === true) {
  1112. if (result.length >= 7) {
  1113. // TODO: if these numbers are > 1 we can use Color4.FromInts(r,g,b,a)
  1114. colors.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color4"](parseFloat(result[4]), parseFloat(result[5]), parseFloat(result[6]), (result.length === 7 || result[7] === undefined) ? 1 : parseFloat(result[7])));
  1115. }
  1116. else {
  1117. // TODO: maybe push NULL and if all are NULL to skip (and remove grayColor var).
  1118. colors.push(grayColor);
  1119. }
  1120. }
  1121. }
  1122. else if ((result = this.normalPattern.exec(line)) !== null) {
  1123. //Create a Vector3 with the normals x, y, z
  1124. //Value of result
  1125. // ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
  1126. //Add the Vector in the list of normals
  1127. normals.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3])));
  1128. }
  1129. else if ((result = this.uvPattern.exec(line)) !== null) {
  1130. //Create a Vector2 with the normals u, v
  1131. //Value of result
  1132. // ["vt 0.1 0.2 0.3", "0.1", "0.2"]
  1133. //Add the Vector in the list of uvs
  1134. uvs.push(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](parseFloat(result[1]) * OBJFileLoader.UV_SCALING.x, parseFloat(result[2]) * OBJFileLoader.UV_SCALING.y));
  1135. //Identify patterns of faces
  1136. //Face could be defined in different type of pattern
  1137. }
  1138. else if ((result = this.facePattern3.exec(line)) !== null) {
  1139. //Value of result:
  1140. //["f 1/1/1 2/2/2 3/3/3", "1/1/1 2/2/2 3/3/3"...]
  1141. //Set the data for this face
  1142. setDataForCurrentFaceWithPattern3(result[1].trim().split(" "), // ["1/1/1", "2/2/2", "3/3/3"]
  1143. 1);
  1144. }
  1145. else if ((result = this.facePattern4.exec(line)) !== null) {
  1146. //Value of result:
  1147. //["f 1//1 2//2 3//3", "1//1 2//2 3//3"...]
  1148. //Set the data for this face
  1149. setDataForCurrentFaceWithPattern4(result[1].trim().split(" "), // ["1//1", "2//2", "3//3"]
  1150. 1);
  1151. }
  1152. else if ((result = this.facePattern5.exec(line)) !== null) {
  1153. //Value of result:
  1154. //["f -1/-1/-1 -2/-2/-2 -3/-3/-3", "-1/-1/-1 -2/-2/-2 -3/-3/-3"...]
  1155. //Set the data for this face
  1156. setDataForCurrentFaceWithPattern5(result[1].trim().split(" "), // ["-1/-1/-1", "-2/-2/-2", "-3/-3/-3"]
  1157. 1);
  1158. }
  1159. else if ((result = this.facePattern2.exec(line)) !== null) {
  1160. //Value of result:
  1161. //["f 1/1 2/2 3/3", "1/1 2/2 3/3"...]
  1162. //Set the data for this face
  1163. setDataForCurrentFaceWithPattern2(result[1].trim().split(" "), // ["1/1", "2/2", "3/3"]
  1164. 1);
  1165. }
  1166. else if ((result = this.facePattern1.exec(line)) !== null) {
  1167. //Value of result
  1168. //["f 1 2 3", "1 2 3"...]
  1169. //Set the data for this face
  1170. setDataForCurrentFaceWithPattern1(result[1].trim().split(" "), // ["1", "2", "3"]
  1171. 1);
  1172. //Define a mesh or an object
  1173. //Each time this keyword is analysed, create a new Object with all data for creating a babylonMesh
  1174. }
  1175. else if (this.group.test(line) || this.obj.test(line)) {
  1176. //Create a new mesh corresponding to the name of the group.
  1177. //Definition of the mesh
  1178. var objMesh = {
  1179. name: line.substring(2).trim(),
  1180. indices: undefined,
  1181. positions: undefined,
  1182. normals: undefined,
  1183. uvs: undefined,
  1184. colors: undefined,
  1185. materialName: ""
  1186. };
  1187. addPreviousObjMesh();
  1188. //Push the last mesh created with only the name
  1189. meshesFromObj.push(objMesh);
  1190. //Set this variable to indicate that now meshesFromObj has objects defined inside
  1191. hasMeshes = true;
  1192. isFirstMaterial = true;
  1193. increment = 1;
  1194. //Keyword for applying a material
  1195. }
  1196. else if (this.usemtl.test(line)) {
  1197. //Get the name of the material
  1198. materialNameFromObj = line.substring(7).trim();
  1199. //If this new material is in the same mesh
  1200. if (!isFirstMaterial || !hasMeshes) {
  1201. //Set the data for the previous mesh
  1202. addPreviousObjMesh();
  1203. //Create a new mesh
  1204. var objMesh =
  1205. //Set the name of the current obj mesh
  1206. {
  1207. name: (objMeshName || "mesh") + "_mm" + increment.toString(),
  1208. indices: undefined,
  1209. positions: undefined,
  1210. normals: undefined,
  1211. uvs: undefined,
  1212. colors: undefined,
  1213. materialName: materialNameFromObj
  1214. };
  1215. increment++;
  1216. //If meshes are already defined
  1217. meshesFromObj.push(objMesh);
  1218. hasMeshes = true;
  1219. }
  1220. //Set the material name if the previous line define a mesh
  1221. if (hasMeshes && isFirstMaterial) {
  1222. //Set the material name to the previous mesh (1 material per mesh)
  1223. meshesFromObj[meshesFromObj.length - 1].materialName = materialNameFromObj;
  1224. isFirstMaterial = false;
  1225. }
  1226. //Keyword for loading the mtl file
  1227. }
  1228. else if (this.mtllib.test(line)) {
  1229. //Get the name of mtl file
  1230. fileToLoad = line.substring(7).trim();
  1231. //Apply smoothing
  1232. }
  1233. else if (this.smooth.test(line)) {
  1234. // smooth shading => apply smoothing
  1235. //Today I don't know it work with babylon and with obj.
  1236. //With the obj file an integer is set
  1237. }
  1238. else {
  1239. //If there is another possibility
  1240. console.log("Unhandled expression at line : " + line);
  1241. }
  1242. }
  1243. //At the end of the file, add the last mesh into the meshesFromObj array
  1244. if (hasMeshes) {
  1245. //Set the data for the last mesh
  1246. handledMesh = meshesFromObj[meshesFromObj.length - 1];
  1247. //Reverse indices for displaying faces in the good sense
  1248. indicesForBabylon.reverse();
  1249. //Get the good array
  1250. unwrapData();
  1251. //Set array
  1252. handledMesh.indices = indicesForBabylon;
  1253. handledMesh.positions = unwrappedPositionsForBabylon;
  1254. handledMesh.normals = unwrappedNormalsForBabylon;
  1255. handledMesh.uvs = unwrappedUVForBabylon;
  1256. if (this._meshLoadOptions.ImportVertexColors === true) {
  1257. handledMesh.colors = unwrappedColorsForBabylon;
  1258. }
  1259. }
  1260. //If any o or g keyword found, create a mesh with a random id
  1261. if (!hasMeshes) {
  1262. // reverse tab of indices
  1263. indicesForBabylon.reverse();
  1264. //Get positions normals uvs
  1265. unwrapData();
  1266. //Set data for one mesh
  1267. meshesFromObj.push({
  1268. name: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Geometry"].RandomId(),
  1269. indices: indicesForBabylon,
  1270. positions: unwrappedPositionsForBabylon,
  1271. colors: unwrappedColorsForBabylon,
  1272. normals: unwrappedNormalsForBabylon,
  1273. uvs: unwrappedUVForBabylon,
  1274. materialName: materialNameFromObj
  1275. });
  1276. }
  1277. //Create a Mesh list
  1278. var babylonMeshesArray = []; //The mesh for babylon
  1279. var materialToUse = new Array();
  1280. //Set data for each mesh
  1281. for (var j = 0; j < meshesFromObj.length; j++) {
  1282. //check meshesNames (stlFileLoader)
  1283. if (meshesNames && meshesFromObj[j].name) {
  1284. if (meshesNames instanceof Array) {
  1285. if (meshesNames.indexOf(meshesFromObj[j].name) === -1) {
  1286. continue;
  1287. }
  1288. }
  1289. else {
  1290. if (meshesFromObj[j].name !== meshesNames) {
  1291. continue;
  1292. }
  1293. }
  1294. }
  1295. //Get the current mesh
  1296. //Set the data with VertexBuffer for each mesh
  1297. handledMesh = meshesFromObj[j];
  1298. //Create a Mesh with the name of the obj mesh
  1299. scene._blockEntityCollection = this._forAssetContainer;
  1300. var babylonMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshesFromObj[j].name, scene);
  1301. scene._blockEntityCollection = false;
  1302. //Push the name of the material to an array
  1303. //This is indispensable for the importMesh function
  1304. materialToUse.push(meshesFromObj[j].materialName);
  1305. var vertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"](); //The container for the values
  1306. //Set the data for the babylonMesh
  1307. vertexData.uvs = handledMesh.uvs;
  1308. vertexData.indices = handledMesh.indices;
  1309. vertexData.positions = handledMesh.positions;
  1310. if (this._meshLoadOptions.ComputeNormals === true) {
  1311. var normals_1 = new Array();
  1312. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["VertexData"].ComputeNormals(handledMesh.positions, handledMesh.indices, normals_1);
  1313. vertexData.normals = normals_1;
  1314. }
  1315. else {
  1316. vertexData.normals = handledMesh.normals;
  1317. }
  1318. if (this._meshLoadOptions.ImportVertexColors === true) {
  1319. vertexData.colors = handledMesh.colors;
  1320. }
  1321. //Set the data from the VertexBuffer to the current Mesh
  1322. vertexData.applyToMesh(babylonMesh);
  1323. if (this._meshLoadOptions.InvertY) {
  1324. babylonMesh.scaling.y *= -1;
  1325. }
  1326. //Push the mesh into an array
  1327. babylonMeshesArray.push(babylonMesh);
  1328. }
  1329. var mtlPromises = [];
  1330. //load the materials
  1331. //Check if we have a file to load
  1332. if (fileToLoad !== "" && this._meshLoadOptions.SkipMaterials === false) {
  1333. //Load the file synchronously
  1334. mtlPromises.push(new Promise(function (resolve, reject) {
  1335. _this._loadMTL(fileToLoad, rootUrl, function (dataLoaded) {
  1336. try {
  1337. //Create materials thanks MTLLoader function
  1338. materialsFromMTLFile.parseMTL(scene, dataLoaded, rootUrl, _this._forAssetContainer);
  1339. //Look at each material loaded in the mtl file
  1340. for (var n = 0; n < materialsFromMTLFile.materials.length; n++) {
  1341. //Three variables to get all meshes with the same material
  1342. var startIndex = 0;
  1343. var _indices = [];
  1344. var _index;
  1345. //The material from MTL file is used in the meshes loaded
  1346. //Push the indice in an array
  1347. //Check if the material is not used for another mesh
  1348. while ((_index = materialToUse.indexOf(materialsFromMTLFile.materials[n].name, startIndex)) > -1) {
  1349. _indices.push(_index);
  1350. startIndex = _index + 1;
  1351. }
  1352. //If the material is not used dispose it
  1353. if (_index === -1 && _indices.length === 0) {
  1354. //If the material is not needed, remove it
  1355. materialsFromMTLFile.materials[n].dispose();
  1356. }
  1357. else {
  1358. for (var o = 0; o < _indices.length; o++) {
  1359. //Apply the material to the Mesh for each mesh with the material
  1360. babylonMeshesArray[_indices[o]].material = materialsFromMTLFile.materials[n];
  1361. }
  1362. }
  1363. }
  1364. resolve();
  1365. }
  1366. catch (e) {
  1367. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error processing MTL file: '" + fileToLoad + "'");
  1368. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1369. resolve();
  1370. }
  1371. else {
  1372. reject(e);
  1373. }
  1374. }
  1375. }, function (pathOfFile, exception) {
  1376. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Error downloading MTL file: '" + fileToLoad + "'");
  1377. if (_this._meshLoadOptions.MaterialLoadingFailsSilently) {
  1378. resolve();
  1379. }
  1380. else {
  1381. reject(exception);
  1382. }
  1383. });
  1384. }));
  1385. }
  1386. //Return an array with all Mesh
  1387. return Promise.all(mtlPromises).then(function () {
  1388. return babylonMeshesArray;
  1389. });
  1390. };
  1391. /**
  1392. * Defines if UVs are optimized by default during load.
  1393. */
  1394. OBJFileLoader.OPTIMIZE_WITH_UV = true;
  1395. /**
  1396. * Invert model on y-axis (does a model scaling inversion)
  1397. */
  1398. OBJFileLoader.INVERT_Y = false;
  1399. /**
  1400. * Include in meshes the vertex colors available in some OBJ files. This is not part of OBJ standard.
  1401. */
  1402. OBJFileLoader.IMPORT_VERTEX_COLORS = false;
  1403. /**
  1404. * Compute the normals for the model, even if normals are present in the file.
  1405. */
  1406. OBJFileLoader.COMPUTE_NORMALS = false;
  1407. /**
  1408. * Defines custom scaling of UV coordinates of loaded meshes.
  1409. */
  1410. OBJFileLoader.UV_SCALING = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1, 1);
  1411. /**
  1412. * Skip loading the materials even if defined in the OBJ file (materials are ignored).
  1413. */
  1414. OBJFileLoader.SKIP_MATERIALS = false;
  1415. /**
  1416. * When a material fails to load OBJ loader will silently fail and onSuccess() callback will be triggered.
  1417. *
  1418. * Defaults to true for backwards compatibility.
  1419. */
  1420. OBJFileLoader.MATERIAL_LOADING_FAILS_SILENTLY = true;
  1421. return OBJFileLoader;
  1422. }());
  1423. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1424. //Add this loader into the register plugin
  1425. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new OBJFileLoader());
  1426. }
  1427. /***/ }),
  1428. /***/ "./STL/index.ts":
  1429. /*!**********************!*\
  1430. !*** ./STL/index.ts ***!
  1431. \**********************/
  1432. /*! exports provided: STLFileLoader */
  1433. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1434. "use strict";
  1435. __webpack_require__.r(__webpack_exports__);
  1436. /* harmony import */ var _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlFileLoader */ "./STL/stlFileLoader.ts");
  1437. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _stlFileLoader__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  1438. /***/ }),
  1439. /***/ "./STL/stlFileLoader.ts":
  1440. /*!******************************!*\
  1441. !*** ./STL/stlFileLoader.ts ***!
  1442. \******************************/
  1443. /*! exports provided: STLFileLoader */
  1444. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1445. "use strict";
  1446. __webpack_require__.r(__webpack_exports__);
  1447. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return STLFileLoader; });
  1448. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  1449. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  1450. /**
  1451. * STL file type loader.
  1452. * This is a babylon scene loader plugin.
  1453. */
  1454. var STLFileLoader = /** @class */ (function () {
  1455. function STLFileLoader() {
  1456. /** @hidden */
  1457. this.solidPattern = /solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g;
  1458. /** @hidden */
  1459. this.facetsPattern = /facet([\s\S]*?)endfacet/g;
  1460. /** @hidden */
  1461. this.normalPattern = /normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1462. /** @hidden */
  1463. this.vertexPattern = /vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g;
  1464. /**
  1465. * Defines the name of the plugin.
  1466. */
  1467. this.name = "stl";
  1468. /**
  1469. * Defines the extensions the stl loader is able to load.
  1470. * force data to come in as an ArrayBuffer
  1471. * we'll convert to string if it looks like it's an ASCII .stl
  1472. */
  1473. this.extensions = {
  1474. ".stl": { isBinary: true },
  1475. };
  1476. }
  1477. /**
  1478. * Import meshes into a scene.
  1479. * @param meshesNames An array of mesh names, a single mesh name, or empty string for all meshes that filter what meshes are imported
  1480. * @param scene The scene to import into
  1481. * @param data The data to import
  1482. * @param rootUrl The root url for scene and resources
  1483. * @param meshes The meshes array to import into
  1484. * @param particleSystems The particle systems array to import into
  1485. * @param skeletons The skeletons array to import into
  1486. * @param onError The callback when import fails
  1487. * @returns True if successful or false otherwise
  1488. */
  1489. STLFileLoader.prototype.importMesh = function (meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons) {
  1490. var matches;
  1491. if (typeof data !== "string") {
  1492. if (this._isBinary(data)) {
  1493. // binary .stl
  1494. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("stlmesh", scene);
  1495. this._parseBinary(babylonMesh, data);
  1496. if (meshes) {
  1497. meshes.push(babylonMesh);
  1498. }
  1499. return true;
  1500. }
  1501. // ASCII .stl
  1502. // convert to string
  1503. var array_buffer = new Uint8Array(data);
  1504. var str = '';
  1505. for (var i = 0; i < data.byteLength; i++) {
  1506. str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
  1507. }
  1508. data = str;
  1509. }
  1510. //if arrived here, data is a string, containing the STLA data.
  1511. while (matches = this.solidPattern.exec(data)) {
  1512. var meshName = matches[1];
  1513. var meshNameFromEnd = matches[3];
  1514. if (meshName != meshNameFromEnd) {
  1515. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Error in STL, solid name != endsolid name");
  1516. return false;
  1517. }
  1518. // check meshesNames
  1519. if (meshesNames && meshName) {
  1520. if (meshesNames instanceof Array) {
  1521. if (!meshesNames.indexOf(meshName)) {
  1522. continue;
  1523. }
  1524. }
  1525. else {
  1526. if (meshName !== meshesNames) {
  1527. continue;
  1528. }
  1529. }
  1530. }
  1531. // stl mesh name can be empty as well
  1532. meshName = meshName || "stlmesh";
  1533. var babylonMesh = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Mesh"](meshName, scene);
  1534. this._parseASCII(babylonMesh, matches[2]);
  1535. if (meshes) {
  1536. meshes.push(babylonMesh);
  1537. }
  1538. }
  1539. return true;
  1540. };
  1541. /**
  1542. * Load into a scene.
  1543. * @param scene The scene to load into
  1544. * @param data The data to import
  1545. * @param rootUrl The root url for scene and resources
  1546. * @param onError The callback when import fails
  1547. * @returns true if successful or false otherwise
  1548. */
  1549. STLFileLoader.prototype.load = function (scene, data, rootUrl) {
  1550. var result = this.importMesh(null, scene, data, rootUrl, null, null, null);
  1551. return result;
  1552. };
  1553. /**
  1554. * Load into an asset container.
  1555. * @param scene The scene to load into
  1556. * @param data The data to import
  1557. * @param rootUrl The root url for scene and resources
  1558. * @param onError The callback when import fails
  1559. * @returns The loaded asset container
  1560. */
  1561. STLFileLoader.prototype.loadAssetContainer = function (scene, data, rootUrl, onError) {
  1562. var container = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  1563. scene._blockEntityCollection = true;
  1564. this.importMesh(null, scene, data, rootUrl, container.meshes, null, null);
  1565. scene._blockEntityCollection = false;
  1566. return container;
  1567. };
  1568. STLFileLoader.prototype._isBinary = function (data) {
  1569. // check if file size is correct for binary stl
  1570. var faceSize, nFaces, reader;
  1571. reader = new DataView(data);
  1572. faceSize = (32 / 8 * 3) + ((32 / 8 * 3) * 3) + (16 / 8);
  1573. nFaces = reader.getUint32(80, true);
  1574. if (80 + (32 / 8) + (nFaces * faceSize) === reader.byteLength) {
  1575. return true;
  1576. }
  1577. // check characters higher than ASCII to confirm binary
  1578. var fileLength = reader.byteLength;
  1579. for (var index = 0; index < fileLength; index++) {
  1580. if (reader.getUint8(index) > 127) {
  1581. return true;
  1582. }
  1583. }
  1584. return false;
  1585. };
  1586. STLFileLoader.prototype._parseBinary = function (mesh, data) {
  1587. var reader = new DataView(data);
  1588. var faces = reader.getUint32(80, true);
  1589. var dataOffset = 84;
  1590. var faceLength = 12 * 4 + 2;
  1591. var offset = 0;
  1592. var positions = new Float32Array(faces * 3 * 3);
  1593. var normals = new Float32Array(faces * 3 * 3);
  1594. var indices = new Uint32Array(faces * 3);
  1595. var indicesCount = 0;
  1596. for (var face = 0; face < faces; face++) {
  1597. var start = dataOffset + face * faceLength;
  1598. var normalX = reader.getFloat32(start, true);
  1599. var normalY = reader.getFloat32(start + 4, true);
  1600. var normalZ = reader.getFloat32(start + 8, true);
  1601. for (var i = 1; i <= 3; i++) {
  1602. var vertexstart = start + i * 12;
  1603. // ordering is intentional to match ascii import
  1604. positions[offset] = reader.getFloat32(vertexstart, true);
  1605. positions[offset + 2] = reader.getFloat32(vertexstart + 4, true);
  1606. positions[offset + 1] = reader.getFloat32(vertexstart + 8, true);
  1607. normals[offset] = normalX;
  1608. normals[offset + 2] = normalY;
  1609. normals[offset + 1] = normalZ;
  1610. offset += 3;
  1611. }
  1612. indices[indicesCount] = indicesCount++;
  1613. indices[indicesCount] = indicesCount++;
  1614. indices[indicesCount] = indicesCount++;
  1615. }
  1616. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1617. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1618. mesh.setIndices(indices);
  1619. mesh.computeWorldMatrix(true);
  1620. };
  1621. STLFileLoader.prototype._parseASCII = function (mesh, solidData) {
  1622. var positions = [];
  1623. var normals = [];
  1624. var indices = [];
  1625. var indicesCount = 0;
  1626. //load facets, ignoring loop as the standard doesn't define it can contain more than vertices
  1627. var matches;
  1628. while (matches = this.facetsPattern.exec(solidData)) {
  1629. var facet = matches[1];
  1630. //one normal per face
  1631. var normalMatches = this.normalPattern.exec(facet);
  1632. this.normalPattern.lastIndex = 0;
  1633. if (!normalMatches) {
  1634. continue;
  1635. }
  1636. var normal = [Number(normalMatches[1]), Number(normalMatches[5]), Number(normalMatches[3])];
  1637. var vertexMatch;
  1638. while (vertexMatch = this.vertexPattern.exec(facet)) {
  1639. positions.push(Number(vertexMatch[1]), Number(vertexMatch[5]), Number(vertexMatch[3]));
  1640. normals.push(normal[0], normal[1], normal[2]);
  1641. }
  1642. indices.push(indicesCount++, indicesCount++, indicesCount++);
  1643. this.vertexPattern.lastIndex = 0;
  1644. }
  1645. this.facetsPattern.lastIndex = 0;
  1646. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, positions);
  1647. mesh.setVerticesData(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, normals);
  1648. mesh.setIndices(indices);
  1649. mesh.computeWorldMatrix(true);
  1650. };
  1651. return STLFileLoader;
  1652. }());
  1653. if (babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  1654. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new STLFileLoader());
  1655. }
  1656. /***/ }),
  1657. /***/ "./glTF/1.0/glTFBinaryExtension.ts":
  1658. /*!*****************************************!*\
  1659. !*** ./glTF/1.0/glTFBinaryExtension.ts ***!
  1660. \*****************************************/
  1661. /*! exports provided: GLTFBinaryExtension */
  1662. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1663. "use strict";
  1664. __webpack_require__.r(__webpack_exports__);
  1665. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return GLTFBinaryExtension; });
  1666. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1667. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  1668. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1669. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1670. var BinaryExtensionBufferName = "binary_glTF";
  1671. /** @hidden */
  1672. var GLTFBinaryExtension = /** @class */ (function (_super) {
  1673. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFBinaryExtension, _super);
  1674. function GLTFBinaryExtension() {
  1675. return _super.call(this, "KHR_binary_glTF") || this;
  1676. }
  1677. GLTFBinaryExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  1678. var extensionsUsed = data.json.extensionsUsed;
  1679. if (!extensionsUsed || extensionsUsed.indexOf(this.name) === -1 || !data.bin) {
  1680. return false;
  1681. }
  1682. this._bin = data.bin;
  1683. onSuccess(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateRuntime(data.json, scene, rootUrl));
  1684. return true;
  1685. };
  1686. GLTFBinaryExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1687. if (gltfRuntime.extensionsUsed.indexOf(this.name) === -1) {
  1688. return false;
  1689. }
  1690. if (id !== BinaryExtensionBufferName) {
  1691. return false;
  1692. }
  1693. this._bin.readAsync(0, this._bin.byteLength).then(onSuccess, function (error) { return onError(error.message); });
  1694. return true;
  1695. };
  1696. GLTFBinaryExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  1697. var texture = gltfRuntime.textures[id];
  1698. var source = gltfRuntime.images[texture.source];
  1699. if (!source.extensions || !(this.name in source.extensions)) {
  1700. return false;
  1701. }
  1702. var sourceExt = source.extensions[this.name];
  1703. var bufferView = gltfRuntime.bufferViews[sourceExt.bufferView];
  1704. var buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1705. onSuccess(buffer);
  1706. return true;
  1707. };
  1708. GLTFBinaryExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  1709. var shader = gltfRuntime.shaders[id];
  1710. if (!shader.extensions || !(this.name in shader.extensions)) {
  1711. return false;
  1712. }
  1713. var binaryExtensionShader = shader.extensions[this.name];
  1714. var bufferView = gltfRuntime.bufferViews[binaryExtensionShader.bufferView];
  1715. var shaderBytes = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromBufferView(gltfRuntime, bufferView, 0, bufferView.byteLength, _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_3__["EComponentType"].UNSIGNED_BYTE);
  1716. setTimeout(function () {
  1717. var shaderString = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].DecodeBufferToText(shaderBytes);
  1718. onSuccess(shaderString);
  1719. });
  1720. return true;
  1721. };
  1722. return GLTFBinaryExtension;
  1723. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  1724. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFBinaryExtension());
  1725. /***/ }),
  1726. /***/ "./glTF/1.0/glTFLoader.ts":
  1727. /*!********************************!*\
  1728. !*** ./glTF/1.0/glTFLoader.ts ***!
  1729. \********************************/
  1730. /*! exports provided: GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension */
  1731. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1732. "use strict";
  1733. __webpack_require__.r(__webpack_exports__);
  1734. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return GLTFLoaderBase; });
  1735. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  1736. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return GLTFLoaderExtension; });
  1737. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  1738. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  1739. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  1740. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  1741. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  1742. /**
  1743. * Tokenizer. Used for shaders compatibility
  1744. * Automatically map world, view, projection, worldViewProjection, attributes and so on
  1745. */
  1746. var ETokenType;
  1747. (function (ETokenType) {
  1748. ETokenType[ETokenType["IDENTIFIER"] = 1] = "IDENTIFIER";
  1749. ETokenType[ETokenType["UNKNOWN"] = 2] = "UNKNOWN";
  1750. ETokenType[ETokenType["END_OF_INPUT"] = 3] = "END_OF_INPUT";
  1751. })(ETokenType || (ETokenType = {}));
  1752. var Tokenizer = /** @class */ (function () {
  1753. function Tokenizer(toParse) {
  1754. this._pos = 0;
  1755. this.currentToken = ETokenType.UNKNOWN;
  1756. this.currentIdentifier = "";
  1757. this.currentString = "";
  1758. this.isLetterOrDigitPattern = /^[a-zA-Z0-9]+$/;
  1759. this._toParse = toParse;
  1760. this._maxPos = toParse.length;
  1761. }
  1762. Tokenizer.prototype.getNextToken = function () {
  1763. if (this.isEnd()) {
  1764. return ETokenType.END_OF_INPUT;
  1765. }
  1766. this.currentString = this.read();
  1767. this.currentToken = ETokenType.UNKNOWN;
  1768. if (this.currentString === "_" || this.isLetterOrDigitPattern.test(this.currentString)) {
  1769. this.currentToken = ETokenType.IDENTIFIER;
  1770. this.currentIdentifier = this.currentString;
  1771. while (!this.isEnd() && (this.isLetterOrDigitPattern.test(this.currentString = this.peek()) || this.currentString === "_")) {
  1772. this.currentIdentifier += this.currentString;
  1773. this.forward();
  1774. }
  1775. }
  1776. return this.currentToken;
  1777. };
  1778. Tokenizer.prototype.peek = function () {
  1779. return this._toParse[this._pos];
  1780. };
  1781. Tokenizer.prototype.read = function () {
  1782. return this._toParse[this._pos++];
  1783. };
  1784. Tokenizer.prototype.forward = function () {
  1785. this._pos++;
  1786. };
  1787. Tokenizer.prototype.isEnd = function () {
  1788. return this._pos >= this._maxPos;
  1789. };
  1790. return Tokenizer;
  1791. }());
  1792. /**
  1793. * Values
  1794. */
  1795. var glTFTransforms = ["MODEL", "VIEW", "PROJECTION", "MODELVIEW", "MODELVIEWPROJECTION", "JOINTMATRIX"];
  1796. var babylonTransforms = ["world", "view", "projection", "worldView", "worldViewProjection", "mBones"];
  1797. var glTFAnimationPaths = ["translation", "rotation", "scale"];
  1798. var babylonAnimationPaths = ["position", "rotationQuaternion", "scaling"];
  1799. /**
  1800. * Parse
  1801. */
  1802. var parseBuffers = function (parsedBuffers, gltfRuntime) {
  1803. for (var buf in parsedBuffers) {
  1804. var parsedBuffer = parsedBuffers[buf];
  1805. gltfRuntime.buffers[buf] = parsedBuffer;
  1806. gltfRuntime.buffersCount++;
  1807. }
  1808. };
  1809. var parseShaders = function (parsedShaders, gltfRuntime) {
  1810. for (var sha in parsedShaders) {
  1811. var parsedShader = parsedShaders[sha];
  1812. gltfRuntime.shaders[sha] = parsedShader;
  1813. gltfRuntime.shaderscount++;
  1814. }
  1815. };
  1816. var parseObject = function (parsedObjects, runtimeProperty, gltfRuntime) {
  1817. for (var object in parsedObjects) {
  1818. var parsedObject = parsedObjects[object];
  1819. gltfRuntime[runtimeProperty][object] = parsedObject;
  1820. }
  1821. };
  1822. /**
  1823. * Utils
  1824. */
  1825. var normalizeUVs = function (buffer) {
  1826. if (!buffer) {
  1827. return;
  1828. }
  1829. for (var i = 0; i < buffer.length / 2; i++) {
  1830. buffer[i * 2 + 1] = 1.0 - buffer[i * 2 + 1];
  1831. }
  1832. };
  1833. var getAttribute = function (attributeParameter) {
  1834. if (attributeParameter.semantic === "NORMAL") {
  1835. return "normal";
  1836. }
  1837. else if (attributeParameter.semantic === "POSITION") {
  1838. return "position";
  1839. }
  1840. else if (attributeParameter.semantic === "JOINT") {
  1841. return "matricesIndices";
  1842. }
  1843. else if (attributeParameter.semantic === "WEIGHT") {
  1844. return "matricesWeights";
  1845. }
  1846. else if (attributeParameter.semantic === "COLOR") {
  1847. return "color";
  1848. }
  1849. else if (attributeParameter.semantic && attributeParameter.semantic.indexOf("TEXCOORD_") !== -1) {
  1850. var channel = Number(attributeParameter.semantic.split("_")[1]);
  1851. return "uv" + (channel === 0 ? "" : channel + 1);
  1852. }
  1853. return null;
  1854. };
  1855. /**
  1856. * Loads and creates animations
  1857. */
  1858. var loadAnimations = function (gltfRuntime) {
  1859. for (var anim in gltfRuntime.animations) {
  1860. var animation = gltfRuntime.animations[anim];
  1861. if (!animation.channels || !animation.samplers) {
  1862. continue;
  1863. }
  1864. var lastAnimation = null;
  1865. for (var i = 0; i < animation.channels.length; i++) {
  1866. // Get parameters and load buffers
  1867. var channel = animation.channels[i];
  1868. var sampler = animation.samplers[channel.sampler];
  1869. if (!sampler) {
  1870. continue;
  1871. }
  1872. var inputData = null;
  1873. var outputData = null;
  1874. if (animation.parameters) {
  1875. inputData = animation.parameters[sampler.input];
  1876. outputData = animation.parameters[sampler.output];
  1877. }
  1878. else {
  1879. inputData = sampler.input;
  1880. outputData = sampler.output;
  1881. }
  1882. var bufferInput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[inputData]);
  1883. var bufferOutput = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, gltfRuntime.accessors[outputData]);
  1884. var targetID = channel.target.id;
  1885. var targetNode = gltfRuntime.scene.getNodeByID(targetID);
  1886. if (targetNode === null) {
  1887. targetNode = gltfRuntime.scene.getNodeByName(targetID);
  1888. }
  1889. if (targetNode === null) {
  1890. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Creating animation named " + anim + ". But cannot find node named " + targetID + " to attach to");
  1891. continue;
  1892. }
  1893. var isBone = targetNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"];
  1894. // Get target path (position, rotation or scaling)
  1895. var targetPath = channel.target.path;
  1896. var targetPathIndex = glTFAnimationPaths.indexOf(targetPath);
  1897. if (targetPathIndex !== -1) {
  1898. targetPath = babylonAnimationPaths[targetPathIndex];
  1899. }
  1900. // Determine animation type
  1901. var animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_MATRIX;
  1902. if (!isBone) {
  1903. if (targetPath === "rotationQuaternion") {
  1904. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_QUATERNION;
  1905. targetNode.rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1906. }
  1907. else {
  1908. animationType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Animation"].ANIMATIONTYPE_VECTOR3;
  1909. }
  1910. }
  1911. // Create animation and key frames
  1912. var babylonAnimation = null;
  1913. var keys = [];
  1914. var arrayOffset = 0;
  1915. var modifyKey = false;
  1916. if (isBone && lastAnimation && lastAnimation.getKeys().length === bufferInput.length) {
  1917. babylonAnimation = lastAnimation;
  1918. modifyKey = true;
  1919. }
  1920. if (!modifyKey) {
  1921. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  1922. 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);
  1923. gltfRuntime.scene._blockEntityCollection = false;
  1924. }
  1925. // For each frame
  1926. for (var j = 0; j < bufferInput.length; j++) {
  1927. var value = null;
  1928. if (targetPath === "rotationQuaternion") { // VEC4
  1929. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2], bufferOutput[arrayOffset + 3]]);
  1930. arrayOffset += 4;
  1931. }
  1932. else { // Position and scaling are VEC3
  1933. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray([bufferOutput[arrayOffset], bufferOutput[arrayOffset + 1], bufferOutput[arrayOffset + 2]]);
  1934. arrayOffset += 3;
  1935. }
  1936. if (isBone) {
  1937. var bone = targetNode;
  1938. var translation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1939. var rotationQuaternion = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  1940. var scaling = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  1941. // Warning on decompose
  1942. var mat = bone.getBaseMatrix();
  1943. if (modifyKey && lastAnimation) {
  1944. mat = lastAnimation.getKeys()[j].value;
  1945. }
  1946. mat.decompose(scaling, rotationQuaternion, translation);
  1947. if (targetPath === "position") {
  1948. translation = value;
  1949. }
  1950. else if (targetPath === "rotationQuaternion") {
  1951. rotationQuaternion = value;
  1952. }
  1953. else {
  1954. scaling = value;
  1955. }
  1956. value = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scaling, rotationQuaternion, translation);
  1957. }
  1958. if (!modifyKey) {
  1959. keys.push({
  1960. frame: bufferInput[j],
  1961. value: value
  1962. });
  1963. }
  1964. else if (lastAnimation) {
  1965. lastAnimation.getKeys()[j].value = value;
  1966. }
  1967. }
  1968. // Finish
  1969. if (!modifyKey && babylonAnimation) {
  1970. babylonAnimation.setKeys(keys);
  1971. targetNode.animations.push(babylonAnimation);
  1972. }
  1973. lastAnimation = babylonAnimation;
  1974. gltfRuntime.scene.stopAnimation(targetNode);
  1975. gltfRuntime.scene.beginAnimation(targetNode, 0, bufferInput[bufferInput.length - 1], true, 1.0);
  1976. }
  1977. }
  1978. };
  1979. /**
  1980. * Returns the bones transformation matrix
  1981. */
  1982. var configureBoneTransformation = function (node) {
  1983. var mat = null;
  1984. if (node.translation || node.rotation || node.scale) {
  1985. var scale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.scale || [1, 1, 1]);
  1986. var rotation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(node.rotation || [0, 0, 0, 1]);
  1987. var position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(node.translation || [0, 0, 0]);
  1988. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Compose(scale, rotation, position);
  1989. }
  1990. else {
  1991. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  1992. }
  1993. return mat;
  1994. };
  1995. /**
  1996. * Returns the parent bone
  1997. */
  1998. var getParentBone = function (gltfRuntime, skins, jointName, newSkeleton) {
  1999. // Try to find
  2000. for (var i = 0; i < newSkeleton.bones.length; i++) {
  2001. if (newSkeleton.bones[i].name === jointName) {
  2002. return newSkeleton.bones[i];
  2003. }
  2004. }
  2005. // Not found, search in gltf nodes
  2006. var nodes = gltfRuntime.nodes;
  2007. for (var nde in nodes) {
  2008. var node = nodes[nde];
  2009. if (!node.jointName) {
  2010. continue;
  2011. }
  2012. var children = node.children;
  2013. for (var i = 0; i < children.length; i++) {
  2014. var child = gltfRuntime.nodes[children[i]];
  2015. if (!child.jointName) {
  2016. continue;
  2017. }
  2018. if (child.jointName === jointName) {
  2019. var mat = configureBoneTransformation(node);
  2020. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, getParentBone(gltfRuntime, skins, node.jointName, newSkeleton), mat);
  2021. bone.id = nde;
  2022. return bone;
  2023. }
  2024. }
  2025. }
  2026. return null;
  2027. };
  2028. /**
  2029. * Returns the appropriate root node
  2030. */
  2031. var getNodeToRoot = function (nodesToRoot, id) {
  2032. for (var i = 0; i < nodesToRoot.length; i++) {
  2033. var nodeToRoot = nodesToRoot[i];
  2034. for (var j = 0; j < nodeToRoot.node.children.length; j++) {
  2035. var child = nodeToRoot.node.children[j];
  2036. if (child === id) {
  2037. return nodeToRoot.bone;
  2038. }
  2039. }
  2040. }
  2041. return null;
  2042. };
  2043. /**
  2044. * Returns the node with the joint name
  2045. */
  2046. var getJointNode = function (gltfRuntime, jointName) {
  2047. var nodes = gltfRuntime.nodes;
  2048. var node = nodes[jointName];
  2049. if (node) {
  2050. return {
  2051. node: node,
  2052. id: jointName
  2053. };
  2054. }
  2055. for (var nde in nodes) {
  2056. node = nodes[nde];
  2057. if (node.jointName === jointName) {
  2058. return {
  2059. node: node,
  2060. id: nde
  2061. };
  2062. }
  2063. }
  2064. return null;
  2065. };
  2066. /**
  2067. * Checks if a nodes is in joints
  2068. */
  2069. var nodeIsInJoints = function (skins, id) {
  2070. for (var i = 0; i < skins.jointNames.length; i++) {
  2071. if (skins.jointNames[i] === id) {
  2072. return true;
  2073. }
  2074. }
  2075. return false;
  2076. };
  2077. /**
  2078. * Fills the nodes to root for bones and builds hierarchy
  2079. */
  2080. var getNodesToRoot = function (gltfRuntime, newSkeleton, skins, nodesToRoot) {
  2081. // Creates nodes for root
  2082. for (var nde in gltfRuntime.nodes) {
  2083. var node = gltfRuntime.nodes[nde];
  2084. var id = nde;
  2085. if (!node.jointName || nodeIsInJoints(skins, node.jointName)) {
  2086. continue;
  2087. }
  2088. // Create node to root bone
  2089. var mat = configureBoneTransformation(node);
  2090. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.name || "", newSkeleton, null, mat);
  2091. bone.id = id;
  2092. nodesToRoot.push({ bone: bone, node: node, id: id });
  2093. }
  2094. // Parenting
  2095. for (var i = 0; i < nodesToRoot.length; i++) {
  2096. var nodeToRoot = nodesToRoot[i];
  2097. var children = nodeToRoot.node.children;
  2098. for (var j = 0; j < children.length; j++) {
  2099. var child = null;
  2100. for (var k = 0; k < nodesToRoot.length; k++) {
  2101. if (nodesToRoot[k].id === children[j]) {
  2102. child = nodesToRoot[k];
  2103. break;
  2104. }
  2105. }
  2106. if (child) {
  2107. child.bone._parent = nodeToRoot.bone;
  2108. nodeToRoot.bone.children.push(child.bone);
  2109. }
  2110. }
  2111. }
  2112. };
  2113. /**
  2114. * Imports a skeleton
  2115. */
  2116. var importSkeleton = function (gltfRuntime, skins, mesh, newSkeleton, id) {
  2117. if (!newSkeleton) {
  2118. newSkeleton = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"](skins.name || "", "", gltfRuntime.scene);
  2119. }
  2120. if (!skins.babylonSkeleton) {
  2121. return newSkeleton;
  2122. }
  2123. // Find the root bones
  2124. var nodesToRoot = [];
  2125. var nodesToRootToAdd = [];
  2126. getNodesToRoot(gltfRuntime, newSkeleton, skins, nodesToRoot);
  2127. newSkeleton.bones = [];
  2128. // Joints
  2129. for (var i = 0; i < skins.jointNames.length; i++) {
  2130. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2131. if (!jointNode) {
  2132. continue;
  2133. }
  2134. var node = jointNode.node;
  2135. if (!node) {
  2136. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[i] + " does not exist");
  2137. continue;
  2138. }
  2139. var id = jointNode.id;
  2140. // Optimize, if the bone already exists...
  2141. var existingBone = gltfRuntime.scene.getBoneByID(id);
  2142. if (existingBone) {
  2143. newSkeleton.bones.push(existingBone);
  2144. continue;
  2145. }
  2146. // Search for parent bone
  2147. var foundBone = false;
  2148. var parentBone = null;
  2149. for (var j = 0; j < i; j++) {
  2150. var jointNode_1 = getJointNode(gltfRuntime, skins.jointNames[j]);
  2151. if (!jointNode_1) {
  2152. continue;
  2153. }
  2154. var joint = jointNode_1.node;
  2155. if (!joint) {
  2156. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Joint named " + skins.jointNames[j] + " does not exist when looking for parent");
  2157. continue;
  2158. }
  2159. var children = joint.children;
  2160. if (!children) {
  2161. continue;
  2162. }
  2163. foundBone = false;
  2164. for (var k = 0; k < children.length; k++) {
  2165. if (children[k] === id) {
  2166. parentBone = getParentBone(gltfRuntime, skins, skins.jointNames[j], newSkeleton);
  2167. foundBone = true;
  2168. break;
  2169. }
  2170. }
  2171. if (foundBone) {
  2172. break;
  2173. }
  2174. }
  2175. // Create bone
  2176. var mat = configureBoneTransformation(node);
  2177. if (!parentBone && nodesToRoot.length > 0) {
  2178. parentBone = getNodeToRoot(nodesToRoot, id);
  2179. if (parentBone) {
  2180. if (nodesToRootToAdd.indexOf(parentBone) === -1) {
  2181. nodesToRootToAdd.push(parentBone);
  2182. }
  2183. }
  2184. }
  2185. var bone = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Bone"](node.jointName || "", newSkeleton, parentBone, mat);
  2186. bone.id = id;
  2187. }
  2188. // Polish
  2189. var bones = newSkeleton.bones;
  2190. newSkeleton.bones = [];
  2191. for (var i = 0; i < skins.jointNames.length; i++) {
  2192. var jointNode = getJointNode(gltfRuntime, skins.jointNames[i]);
  2193. if (!jointNode) {
  2194. continue;
  2195. }
  2196. for (var j = 0; j < bones.length; j++) {
  2197. if (bones[j].id === jointNode.id) {
  2198. newSkeleton.bones.push(bones[j]);
  2199. break;
  2200. }
  2201. }
  2202. }
  2203. newSkeleton.prepare();
  2204. // Finish
  2205. for (var i = 0; i < nodesToRootToAdd.length; i++) {
  2206. newSkeleton.bones.push(nodesToRootToAdd[i]);
  2207. }
  2208. return newSkeleton;
  2209. };
  2210. /**
  2211. * Imports a mesh and its geometries
  2212. */
  2213. var importMesh = function (gltfRuntime, node, meshes, id, newMesh) {
  2214. if (!newMesh) {
  2215. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2216. newMesh = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2217. gltfRuntime.scene._blockEntityCollection = false;
  2218. newMesh.id = id;
  2219. }
  2220. if (!node.babylonNode) {
  2221. return newMesh;
  2222. }
  2223. var subMaterials = [];
  2224. var vertexData = null;
  2225. var verticesStarts = new Array();
  2226. var verticesCounts = new Array();
  2227. var indexStarts = new Array();
  2228. var indexCounts = new Array();
  2229. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2230. var meshID = meshes[meshIndex];
  2231. var mesh = gltfRuntime.meshes[meshID];
  2232. if (!mesh) {
  2233. continue;
  2234. }
  2235. // Positions, normals and UVs
  2236. for (var i = 0; i < mesh.primitives.length; i++) {
  2237. // Temporary vertex data
  2238. var tempVertexData = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexData"]();
  2239. var primitive = mesh.primitives[i];
  2240. if (primitive.mode !== 4) {
  2241. // continue;
  2242. }
  2243. var attributes = primitive.attributes;
  2244. var accessor = null;
  2245. var buffer = null;
  2246. // Set positions, normal and uvs
  2247. for (var semantic in attributes) {
  2248. // Link accessor and buffer view
  2249. accessor = gltfRuntime.accessors[attributes[semantic]];
  2250. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2251. if (semantic === "NORMAL") {
  2252. tempVertexData.normals = new Float32Array(buffer.length);
  2253. tempVertexData.normals.set(buffer);
  2254. }
  2255. else if (semantic === "POSITION") {
  2256. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].HomogeneousCoordinates) {
  2257. tempVertexData.positions = new Float32Array(buffer.length - buffer.length / 4);
  2258. for (var j = 0; j < buffer.length; j += 4) {
  2259. tempVertexData.positions[j] = buffer[j];
  2260. tempVertexData.positions[j + 1] = buffer[j + 1];
  2261. tempVertexData.positions[j + 2] = buffer[j + 2];
  2262. }
  2263. }
  2264. else {
  2265. tempVertexData.positions = new Float32Array(buffer.length);
  2266. tempVertexData.positions.set(buffer);
  2267. }
  2268. verticesCounts.push(tempVertexData.positions.length);
  2269. }
  2270. else if (semantic.indexOf("TEXCOORD_") !== -1) {
  2271. var channel = Number(semantic.split("_")[1]);
  2272. var uvKind = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind + (channel === 0 ? "" : (channel + 1));
  2273. var uvs = new Float32Array(buffer.length);
  2274. uvs.set(buffer);
  2275. normalizeUVs(uvs);
  2276. tempVertexData.set(uvs, uvKind);
  2277. }
  2278. else if (semantic === "JOINT") {
  2279. tempVertexData.matricesIndices = new Float32Array(buffer.length);
  2280. tempVertexData.matricesIndices.set(buffer);
  2281. }
  2282. else if (semantic === "WEIGHT") {
  2283. tempVertexData.matricesWeights = new Float32Array(buffer.length);
  2284. tempVertexData.matricesWeights.set(buffer);
  2285. }
  2286. else if (semantic === "COLOR") {
  2287. tempVertexData.colors = new Float32Array(buffer.length);
  2288. tempVertexData.colors.set(buffer);
  2289. }
  2290. }
  2291. // Indices
  2292. accessor = gltfRuntime.accessors[primitive.indices];
  2293. if (accessor) {
  2294. buffer = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetBufferFromAccessor(gltfRuntime, accessor);
  2295. tempVertexData.indices = new Int32Array(buffer.length);
  2296. tempVertexData.indices.set(buffer);
  2297. indexCounts.push(tempVertexData.indices.length);
  2298. }
  2299. else {
  2300. // Set indices on the fly
  2301. var indices = [];
  2302. for (var j = 0; j < tempVertexData.positions.length / 3; j++) {
  2303. indices.push(j);
  2304. }
  2305. tempVertexData.indices = new Int32Array(indices);
  2306. indexCounts.push(tempVertexData.indices.length);
  2307. }
  2308. if (!vertexData) {
  2309. vertexData = tempVertexData;
  2310. }
  2311. else {
  2312. vertexData.merge(tempVertexData);
  2313. }
  2314. // Sub material
  2315. var material_1 = gltfRuntime.scene.getMaterialByID(primitive.material);
  2316. subMaterials.push(material_1 === null ? _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetDefaultMaterial(gltfRuntime.scene) : material_1);
  2317. // Update vertices start and index start
  2318. verticesStarts.push(verticesStarts.length === 0 ? 0 : verticesStarts[verticesStarts.length - 1] + verticesCounts[verticesCounts.length - 2]);
  2319. indexStarts.push(indexStarts.length === 0 ? 0 : indexStarts[indexStarts.length - 1] + indexCounts[indexCounts.length - 2]);
  2320. }
  2321. }
  2322. var material;
  2323. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2324. if (subMaterials.length > 1) {
  2325. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]("multimat" + id, gltfRuntime.scene);
  2326. material.subMaterials = subMaterials;
  2327. }
  2328. else {
  2329. material = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]("multimat" + id, gltfRuntime.scene);
  2330. }
  2331. if (subMaterials.length === 1) {
  2332. material = subMaterials[0];
  2333. }
  2334. if (!newMesh.material) {
  2335. newMesh.material = material;
  2336. }
  2337. // Apply geometry
  2338. new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Geometry"](id, gltfRuntime.scene, vertexData, false, newMesh);
  2339. newMesh.computeWorldMatrix(true);
  2340. gltfRuntime.scene._blockEntityCollection = false;
  2341. // Apply submeshes
  2342. newMesh.subMeshes = [];
  2343. var index = 0;
  2344. for (var meshIndex = 0; meshIndex < meshes.length; meshIndex++) {
  2345. var meshID = meshes[meshIndex];
  2346. var mesh = gltfRuntime.meshes[meshID];
  2347. if (!mesh) {
  2348. continue;
  2349. }
  2350. for (var i = 0; i < mesh.primitives.length; i++) {
  2351. if (mesh.primitives[i].mode !== 4) {
  2352. //continue;
  2353. }
  2354. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["SubMesh"].AddToMesh(index, verticesStarts[index], verticesCounts[index], indexStarts[index], indexCounts[index], newMesh, newMesh, true);
  2355. index++;
  2356. }
  2357. }
  2358. // Finish
  2359. return newMesh;
  2360. };
  2361. /**
  2362. * Configure node transformation from position, rotation and scaling
  2363. */
  2364. var configureNode = function (newNode, position, rotation, scaling) {
  2365. if (newNode.position) {
  2366. newNode.position = position;
  2367. }
  2368. if (newNode.rotationQuaternion || newNode.rotation) {
  2369. newNode.rotationQuaternion = rotation;
  2370. }
  2371. if (newNode.scaling) {
  2372. newNode.scaling = scaling;
  2373. }
  2374. };
  2375. /**
  2376. * Configures node from transformation matrix
  2377. */
  2378. var configureNodeFromMatrix = function (newNode, node, parent) {
  2379. if (node.matrix) {
  2380. var position = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2381. var rotation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
  2382. var scaling = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  2383. var mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].FromArray(node.matrix);
  2384. mat.decompose(scaling, rotation, position);
  2385. configureNode(newNode, position, rotation, scaling);
  2386. }
  2387. else if (node.translation && node.rotation && node.scale) {
  2388. 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));
  2389. }
  2390. newNode.computeWorldMatrix(true);
  2391. };
  2392. /**
  2393. * Imports a node
  2394. */
  2395. var importNode = function (gltfRuntime, node, id, parent) {
  2396. var lastNode = null;
  2397. if (gltfRuntime.importOnlyMeshes && (node.skin || node.meshes)) {
  2398. if (gltfRuntime.importMeshesNames && gltfRuntime.importMeshesNames.length > 0 && gltfRuntime.importMeshesNames.indexOf(node.name || "") === -1) {
  2399. return null;
  2400. }
  2401. }
  2402. // Meshes
  2403. if (node.skin) {
  2404. if (node.meshes) {
  2405. var skin = gltfRuntime.skins[node.skin];
  2406. var newMesh = importMesh(gltfRuntime, node, node.meshes, id, node.babylonNode);
  2407. newMesh.skeleton = gltfRuntime.scene.getLastSkeletonByID(node.skin);
  2408. if (newMesh.skeleton === null) {
  2409. newMesh.skeleton = importSkeleton(gltfRuntime, skin, newMesh, skin.babylonSkeleton, node.skin);
  2410. if (!skin.babylonSkeleton) {
  2411. skin.babylonSkeleton = newMesh.skeleton;
  2412. }
  2413. }
  2414. lastNode = newMesh;
  2415. }
  2416. }
  2417. else if (node.meshes) {
  2418. /**
  2419. * Improve meshes property
  2420. */
  2421. var newMesh = importMesh(gltfRuntime, node, node.mesh ? [node.mesh] : node.meshes, id, node.babylonNode);
  2422. lastNode = newMesh;
  2423. }
  2424. // Lights
  2425. else if (node.light && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2426. var light = gltfRuntime.lights[node.light];
  2427. if (light) {
  2428. if (light.type === "ambient") {
  2429. var ambienLight = light[light.type];
  2430. 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);
  2431. hemiLight.name = node.name || "";
  2432. if (ambienLight.color) {
  2433. hemiLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(ambienLight.color);
  2434. }
  2435. lastNode = hemiLight;
  2436. }
  2437. else if (light.type === "directional") {
  2438. var directionalLight = light[light.type];
  2439. 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);
  2440. dirLight.name = node.name || "";
  2441. if (directionalLight.color) {
  2442. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(directionalLight.color);
  2443. }
  2444. lastNode = dirLight;
  2445. }
  2446. else if (light.type === "point") {
  2447. var pointLight = light[light.type];
  2448. 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);
  2449. ptLight.name = node.name || "";
  2450. if (pointLight.color) {
  2451. ptLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(pointLight.color);
  2452. }
  2453. lastNode = ptLight;
  2454. }
  2455. else if (light.type === "spot") {
  2456. var spotLight = light[light.type];
  2457. 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);
  2458. spLight.name = node.name || "";
  2459. if (spotLight.color) {
  2460. spLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArray(spotLight.color);
  2461. }
  2462. if (spotLight.fallOfAngle) {
  2463. spLight.angle = spotLight.fallOfAngle;
  2464. }
  2465. if (spotLight.fallOffExponent) {
  2466. spLight.exponent = spotLight.fallOffExponent;
  2467. }
  2468. lastNode = spLight;
  2469. }
  2470. }
  2471. }
  2472. // Cameras
  2473. else if (node.camera && !node.babylonNode && !gltfRuntime.importOnlyMeshes) {
  2474. var camera = gltfRuntime.cameras[node.camera];
  2475. if (camera) {
  2476. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2477. if (camera.type === "orthographic") {
  2478. 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);
  2479. orthoCamera.name = node.name || "";
  2480. orthoCamera.mode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Camera"].ORTHOGRAPHIC_CAMERA;
  2481. orthoCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2482. lastNode = orthoCamera;
  2483. }
  2484. else if (camera.type === "perspective") {
  2485. var perspectiveCamera = camera[camera.type];
  2486. 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);
  2487. persCamera.name = node.name || "";
  2488. persCamera.attachControl(gltfRuntime.scene.getEngine().getInputElement());
  2489. if (!perspectiveCamera.aspectRatio) {
  2490. perspectiveCamera.aspectRatio = gltfRuntime.scene.getEngine().getRenderWidth() / gltfRuntime.scene.getEngine().getRenderHeight();
  2491. }
  2492. if (perspectiveCamera.znear && perspectiveCamera.zfar) {
  2493. persCamera.maxZ = perspectiveCamera.zfar;
  2494. persCamera.minZ = perspectiveCamera.znear;
  2495. }
  2496. lastNode = persCamera;
  2497. }
  2498. gltfRuntime.scene._blockEntityCollection = false;
  2499. }
  2500. }
  2501. // Empty node
  2502. if (!node.jointName) {
  2503. if (node.babylonNode) {
  2504. return node.babylonNode;
  2505. }
  2506. else if (lastNode === null) {
  2507. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2508. var dummy = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"](node.name || "", gltfRuntime.scene);
  2509. gltfRuntime.scene._blockEntityCollection = false;
  2510. node.babylonNode = dummy;
  2511. lastNode = dummy;
  2512. }
  2513. }
  2514. if (lastNode !== null) {
  2515. if (node.matrix && lastNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2516. configureNodeFromMatrix(lastNode, node, parent);
  2517. }
  2518. else {
  2519. var translation = node.translation || [0, 0, 0];
  2520. var rotation = node.rotation || [0, 0, 0, 1];
  2521. var scale = node.scale || [1, 1, 1];
  2522. 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));
  2523. }
  2524. lastNode.updateCache(true);
  2525. node.babylonNode = lastNode;
  2526. }
  2527. return lastNode;
  2528. };
  2529. /**
  2530. * Traverses nodes and creates them
  2531. */
  2532. var traverseNodes = function (gltfRuntime, id, parent, meshIncluded) {
  2533. if (meshIncluded === void 0) { meshIncluded = false; }
  2534. var node = gltfRuntime.nodes[id];
  2535. var newNode = null;
  2536. if (gltfRuntime.importOnlyMeshes && !meshIncluded && gltfRuntime.importMeshesNames) {
  2537. if (gltfRuntime.importMeshesNames.indexOf(node.name || "") !== -1 || gltfRuntime.importMeshesNames.length === 0) {
  2538. meshIncluded = true;
  2539. }
  2540. else {
  2541. meshIncluded = false;
  2542. }
  2543. }
  2544. else {
  2545. meshIncluded = true;
  2546. }
  2547. if (!node.jointName && meshIncluded) {
  2548. newNode = importNode(gltfRuntime, node, id, parent);
  2549. if (newNode !== null) {
  2550. newNode.id = id;
  2551. newNode.parent = parent;
  2552. }
  2553. }
  2554. if (node.children) {
  2555. for (var i = 0; i < node.children.length; i++) {
  2556. traverseNodes(gltfRuntime, node.children[i], newNode, meshIncluded);
  2557. }
  2558. }
  2559. };
  2560. /**
  2561. * do stuff after buffers, shaders are loaded (e.g. hook up materials, load animations, etc.)
  2562. */
  2563. var postLoad = function (gltfRuntime) {
  2564. // Nodes
  2565. var currentScene = gltfRuntime.currentScene;
  2566. if (currentScene) {
  2567. for (var i = 0; i < currentScene.nodes.length; i++) {
  2568. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2569. }
  2570. }
  2571. else {
  2572. for (var thing in gltfRuntime.scenes) {
  2573. currentScene = gltfRuntime.scenes[thing];
  2574. for (var i = 0; i < currentScene.nodes.length; i++) {
  2575. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  2576. }
  2577. }
  2578. }
  2579. // Set animations
  2580. loadAnimations(gltfRuntime);
  2581. for (var i = 0; i < gltfRuntime.scene.skeletons.length; i++) {
  2582. var skeleton = gltfRuntime.scene.skeletons[i];
  2583. gltfRuntime.scene.beginAnimation(skeleton, 0, Number.MAX_VALUE, true, 1.0);
  2584. }
  2585. };
  2586. /**
  2587. * onBind shaderrs callback to set uniforms and matrices
  2588. */
  2589. var onBindShaderMaterial = function (mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess) {
  2590. var materialValues = material.values || technique.parameters;
  2591. for (var unif in unTreatedUniforms) {
  2592. var uniform = unTreatedUniforms[unif];
  2593. var type = uniform.type;
  2594. 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) {
  2595. if (uniform.semantic && !uniform.source && !uniform.node) {
  2596. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, mesh, uniform, unif, shaderMaterial.getEffect());
  2597. }
  2598. else if (uniform.semantic && (uniform.source || uniform.node)) {
  2599. var source = gltfRuntime.scene.getNodeByName(uniform.source || uniform.node || "");
  2600. if (source === null) {
  2601. source = gltfRuntime.scene.getNodeByID(uniform.source || uniform.node || "");
  2602. }
  2603. if (source === null) {
  2604. continue;
  2605. }
  2606. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetMatrix(gltfRuntime.scene, source, uniform, unif, shaderMaterial.getEffect());
  2607. }
  2608. }
  2609. else {
  2610. var value = materialValues[technique.uniforms[unif]];
  2611. if (!value) {
  2612. continue;
  2613. }
  2614. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2615. var texture = gltfRuntime.textures[material.values ? value : uniform.value].babylonTexture;
  2616. if (texture === null || texture === undefined) {
  2617. continue;
  2618. }
  2619. shaderMaterial.getEffect().setTexture(unif, texture);
  2620. }
  2621. else {
  2622. _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform((shaderMaterial.getEffect()), unif, value, type);
  2623. }
  2624. }
  2625. }
  2626. onSuccess(shaderMaterial);
  2627. };
  2628. /**
  2629. * Prepare uniforms to send the only one time
  2630. * Loads the appropriate textures
  2631. */
  2632. var prepareShaderMaterialUniforms = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms) {
  2633. var materialValues = material.values || technique.parameters;
  2634. var techniqueUniforms = technique.uniforms;
  2635. /**
  2636. * Prepare values here (not matrices)
  2637. */
  2638. for (var unif in unTreatedUniforms) {
  2639. var uniform = unTreatedUniforms[unif];
  2640. var type = uniform.type;
  2641. var value = materialValues[techniqueUniforms[unif]];
  2642. if (value === undefined) {
  2643. // In case the value is the same for all materials
  2644. value = uniform.value;
  2645. }
  2646. if (!value) {
  2647. continue;
  2648. }
  2649. var onLoadTexture = function (uniformName) {
  2650. return function (texture) {
  2651. if (uniform.value && uniformName) {
  2652. // Static uniform
  2653. shaderMaterial.setTexture(uniformName, texture);
  2654. delete unTreatedUniforms[uniformName];
  2655. }
  2656. };
  2657. };
  2658. // Texture (sampler2D)
  2659. if (type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2660. GLTFLoaderExtension.LoadTextureAsync(gltfRuntime, material.values ? value : uniform.value, onLoadTexture(unif), function () { return onLoadTexture(null); });
  2661. }
  2662. // Others
  2663. else {
  2664. if (uniform.value && _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].SetUniform(shaderMaterial, unif, material.values ? value : uniform.value, type)) {
  2665. // Static uniform
  2666. delete unTreatedUniforms[unif];
  2667. }
  2668. }
  2669. }
  2670. };
  2671. /**
  2672. * Shader compilation failed
  2673. */
  2674. var onShaderCompileError = function (program, shaderMaterial, onError) {
  2675. return function (effect, error) {
  2676. shaderMaterial.dispose(true);
  2677. onError("Cannot compile program named " + program.name + ". Error: " + error + ". Default material will be applied");
  2678. };
  2679. };
  2680. /**
  2681. * Shader compilation success
  2682. */
  2683. var onShaderCompileSuccess = function (gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess) {
  2684. return function (_) {
  2685. prepareShaderMaterialUniforms(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms);
  2686. shaderMaterial.onBind = function (mesh) {
  2687. onBindShaderMaterial(mesh, gltfRuntime, unTreatedUniforms, shaderMaterial, technique, material, onSuccess);
  2688. };
  2689. };
  2690. };
  2691. /**
  2692. * Returns the appropriate uniform if already handled by babylon
  2693. */
  2694. var parseShaderUniforms = function (tokenizer, technique, unTreatedUniforms) {
  2695. for (var unif in technique.uniforms) {
  2696. var uniform = technique.uniforms[unif];
  2697. var uniformParameter = technique.parameters[uniform];
  2698. if (tokenizer.currentIdentifier === unif) {
  2699. if (uniformParameter.semantic && !uniformParameter.source && !uniformParameter.node) {
  2700. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2701. if (transformIndex !== -1) {
  2702. delete unTreatedUniforms[unif];
  2703. return babylonTransforms[transformIndex];
  2704. }
  2705. }
  2706. }
  2707. }
  2708. return tokenizer.currentIdentifier;
  2709. };
  2710. /**
  2711. * All shaders loaded. Create materials one by one
  2712. */
  2713. var importMaterials = function (gltfRuntime) {
  2714. // Create materials
  2715. for (var mat in gltfRuntime.materials) {
  2716. GLTFLoaderExtension.LoadMaterialAsync(gltfRuntime, mat, function (material) { }, function () { });
  2717. }
  2718. };
  2719. /**
  2720. * Implementation of the base glTF spec
  2721. * @hidden
  2722. */
  2723. var GLTFLoaderBase = /** @class */ (function () {
  2724. function GLTFLoaderBase() {
  2725. }
  2726. GLTFLoaderBase.CreateRuntime = function (parsedData, scene, rootUrl) {
  2727. var gltfRuntime = {
  2728. extensions: {},
  2729. accessors: {},
  2730. buffers: {},
  2731. bufferViews: {},
  2732. meshes: {},
  2733. lights: {},
  2734. cameras: {},
  2735. nodes: {},
  2736. images: {},
  2737. textures: {},
  2738. shaders: {},
  2739. programs: {},
  2740. samplers: {},
  2741. techniques: {},
  2742. materials: {},
  2743. animations: {},
  2744. skins: {},
  2745. extensionsUsed: [],
  2746. scenes: {},
  2747. buffersCount: 0,
  2748. shaderscount: 0,
  2749. scene: scene,
  2750. rootUrl: rootUrl,
  2751. loadedBufferCount: 0,
  2752. loadedBufferViews: {},
  2753. loadedShaderCount: 0,
  2754. importOnlyMeshes: false,
  2755. dummyNodes: [],
  2756. forAssetContainer: false
  2757. };
  2758. // Parse
  2759. if (parsedData.extensions) {
  2760. parseObject(parsedData.extensions, "extensions", gltfRuntime);
  2761. }
  2762. if (parsedData.extensionsUsed) {
  2763. parseObject(parsedData.extensionsUsed, "extensionsUsed", gltfRuntime);
  2764. }
  2765. if (parsedData.buffers) {
  2766. parseBuffers(parsedData.buffers, gltfRuntime);
  2767. }
  2768. if (parsedData.bufferViews) {
  2769. parseObject(parsedData.bufferViews, "bufferViews", gltfRuntime);
  2770. }
  2771. if (parsedData.accessors) {
  2772. parseObject(parsedData.accessors, "accessors", gltfRuntime);
  2773. }
  2774. if (parsedData.meshes) {
  2775. parseObject(parsedData.meshes, "meshes", gltfRuntime);
  2776. }
  2777. if (parsedData.lights) {
  2778. parseObject(parsedData.lights, "lights", gltfRuntime);
  2779. }
  2780. if (parsedData.cameras) {
  2781. parseObject(parsedData.cameras, "cameras", gltfRuntime);
  2782. }
  2783. if (parsedData.nodes) {
  2784. parseObject(parsedData.nodes, "nodes", gltfRuntime);
  2785. }
  2786. if (parsedData.images) {
  2787. parseObject(parsedData.images, "images", gltfRuntime);
  2788. }
  2789. if (parsedData.textures) {
  2790. parseObject(parsedData.textures, "textures", gltfRuntime);
  2791. }
  2792. if (parsedData.shaders) {
  2793. parseShaders(parsedData.shaders, gltfRuntime);
  2794. }
  2795. if (parsedData.programs) {
  2796. parseObject(parsedData.programs, "programs", gltfRuntime);
  2797. }
  2798. if (parsedData.samplers) {
  2799. parseObject(parsedData.samplers, "samplers", gltfRuntime);
  2800. }
  2801. if (parsedData.techniques) {
  2802. parseObject(parsedData.techniques, "techniques", gltfRuntime);
  2803. }
  2804. if (parsedData.materials) {
  2805. parseObject(parsedData.materials, "materials", gltfRuntime);
  2806. }
  2807. if (parsedData.animations) {
  2808. parseObject(parsedData.animations, "animations", gltfRuntime);
  2809. }
  2810. if (parsedData.skins) {
  2811. parseObject(parsedData.skins, "skins", gltfRuntime);
  2812. }
  2813. if (parsedData.scenes) {
  2814. gltfRuntime.scenes = parsedData.scenes;
  2815. }
  2816. if (parsedData.scene && parsedData.scenes) {
  2817. gltfRuntime.currentScene = parsedData.scenes[parsedData.scene];
  2818. }
  2819. return gltfRuntime;
  2820. };
  2821. GLTFLoaderBase.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  2822. var buffer = gltfRuntime.buffers[id];
  2823. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(buffer.uri)) {
  2824. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(buffer.uri))); });
  2825. }
  2826. else {
  2827. 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) {
  2828. if (request) {
  2829. onError(request.status + " " + request.statusText);
  2830. }
  2831. });
  2832. }
  2833. };
  2834. GLTFLoaderBase.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  2835. var texture = gltfRuntime.textures[id];
  2836. if (!texture || !texture.source) {
  2837. onError("");
  2838. return;
  2839. }
  2840. if (texture.babylonTexture) {
  2841. onSuccess(null);
  2842. return;
  2843. }
  2844. var source = gltfRuntime.images[texture.source];
  2845. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(source.uri)) {
  2846. setTimeout(function () { return onSuccess(new Uint8Array(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DecodeBase64(source.uri))); });
  2847. }
  2848. else {
  2849. 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) {
  2850. if (request) {
  2851. onError(request.status + " " + request.statusText);
  2852. }
  2853. });
  2854. }
  2855. };
  2856. GLTFLoaderBase.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  2857. var texture = gltfRuntime.textures[id];
  2858. if (texture.babylonTexture) {
  2859. onSuccess(texture.babylonTexture);
  2860. return;
  2861. }
  2862. var sampler = gltfRuntime.samplers[texture.sampler];
  2863. var createMipMaps = (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST) ||
  2864. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_LINEAR) ||
  2865. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST) ||
  2866. (sampler.minFilter === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR);
  2867. var samplingMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  2868. var blob = buffer == null ? new Blob() : new Blob([buffer]);
  2869. var blobURL = URL.createObjectURL(blob);
  2870. var revokeBlobURL = function () { return URL.revokeObjectURL(blobURL); };
  2871. var newTexture = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"](blobURL, gltfRuntime.scene, !createMipMaps, true, samplingMode, revokeBlobURL, revokeBlobURL);
  2872. if (sampler.wrapS !== undefined) {
  2873. newTexture.wrapU = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapS);
  2874. }
  2875. if (sampler.wrapT !== undefined) {
  2876. newTexture.wrapV = _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_2__["GLTFUtils"].GetWrapMode(sampler.wrapT);
  2877. }
  2878. newTexture.name = id;
  2879. texture.babylonTexture = newTexture;
  2880. onSuccess(newTexture);
  2881. };
  2882. GLTFLoaderBase.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  2883. var shader = gltfRuntime.shaders[id];
  2884. if (babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].IsBase64(shader.uri)) {
  2885. var shaderString = atob(shader.uri.split(",")[1]);
  2886. if (onSuccess) {
  2887. onSuccess(shaderString);
  2888. }
  2889. }
  2890. else {
  2891. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].LoadFile(gltfRuntime.rootUrl + shader.uri, onSuccess, undefined, undefined, false, function (request) {
  2892. if (request && onError) {
  2893. onError(request.status + " " + request.statusText);
  2894. }
  2895. });
  2896. }
  2897. };
  2898. GLTFLoaderBase.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  2899. var material = gltfRuntime.materials[id];
  2900. if (!material.technique) {
  2901. if (onError) {
  2902. onError("No technique found.");
  2903. }
  2904. return;
  2905. }
  2906. var technique = gltfRuntime.techniques[material.technique];
  2907. if (!technique) {
  2908. gltfRuntime.scene._blockEntityCollection = gltfRuntime.forAssetContainer;
  2909. var defaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"](id, gltfRuntime.scene);
  2910. gltfRuntime.scene._blockEntityCollection = false;
  2911. defaultMaterial.diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.5, 0.5, 0.5);
  2912. defaultMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  2913. onSuccess(defaultMaterial);
  2914. return;
  2915. }
  2916. var program = gltfRuntime.programs[technique.program];
  2917. var states = technique.states;
  2918. var vertexShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + "VertexShader"];
  2919. var pixelShader = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + "PixelShader"];
  2920. var newVertexShader = "";
  2921. var newPixelShader = "";
  2922. var vertexTokenizer = new Tokenizer(vertexShader);
  2923. var pixelTokenizer = new Tokenizer(pixelShader);
  2924. var unTreatedUniforms = {};
  2925. var uniforms = [];
  2926. var attributes = [];
  2927. var samplers = [];
  2928. // Fill uniform, sampler2D and attributes
  2929. for (var unif in technique.uniforms) {
  2930. var uniform = technique.uniforms[unif];
  2931. var uniformParameter = technique.parameters[uniform];
  2932. unTreatedUniforms[unif] = uniformParameter;
  2933. if (uniformParameter.semantic && !uniformParameter.node && !uniformParameter.source) {
  2934. var transformIndex = glTFTransforms.indexOf(uniformParameter.semantic);
  2935. if (transformIndex !== -1) {
  2936. uniforms.push(babylonTransforms[transformIndex]);
  2937. delete unTreatedUniforms[unif];
  2938. }
  2939. else {
  2940. uniforms.push(unif);
  2941. }
  2942. }
  2943. else if (uniformParameter.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].SAMPLER_2D) {
  2944. samplers.push(unif);
  2945. }
  2946. else {
  2947. uniforms.push(unif);
  2948. }
  2949. }
  2950. for (var attr in technique.attributes) {
  2951. var attribute = technique.attributes[attr];
  2952. var attributeParameter = technique.parameters[attribute];
  2953. if (attributeParameter.semantic) {
  2954. var name_1 = getAttribute(attributeParameter);
  2955. if (name_1) {
  2956. attributes.push(name_1);
  2957. }
  2958. }
  2959. }
  2960. // Configure vertex shader
  2961. while (!vertexTokenizer.isEnd() && vertexTokenizer.getNextToken()) {
  2962. var tokenType = vertexTokenizer.currentToken;
  2963. if (tokenType !== ETokenType.IDENTIFIER) {
  2964. newVertexShader += vertexTokenizer.currentString;
  2965. continue;
  2966. }
  2967. var foundAttribute = false;
  2968. for (var attr in technique.attributes) {
  2969. var attribute = technique.attributes[attr];
  2970. var attributeParameter = technique.parameters[attribute];
  2971. if (vertexTokenizer.currentIdentifier === attr && attributeParameter.semantic) {
  2972. newVertexShader += getAttribute(attributeParameter);
  2973. foundAttribute = true;
  2974. break;
  2975. }
  2976. }
  2977. if (foundAttribute) {
  2978. continue;
  2979. }
  2980. newVertexShader += parseShaderUniforms(vertexTokenizer, technique, unTreatedUniforms);
  2981. }
  2982. // Configure pixel shader
  2983. while (!pixelTokenizer.isEnd() && pixelTokenizer.getNextToken()) {
  2984. var tokenType = pixelTokenizer.currentToken;
  2985. if (tokenType !== ETokenType.IDENTIFIER) {
  2986. newPixelShader += pixelTokenizer.currentString;
  2987. continue;
  2988. }
  2989. newPixelShader += parseShaderUniforms(pixelTokenizer, technique, unTreatedUniforms);
  2990. }
  2991. // Create shader material
  2992. var shaderPath = {
  2993. vertex: program.vertexShader + id,
  2994. fragment: program.fragmentShader + id
  2995. };
  2996. var options = {
  2997. attributes: attributes,
  2998. uniforms: uniforms,
  2999. samplers: samplers,
  3000. needAlphaBlending: states && states.enable && states.enable.indexOf(3042) !== -1
  3001. };
  3002. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.vertexShader + id + "VertexShader"] = newVertexShader;
  3003. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[program.fragmentShader + id + "PixelShader"] = newPixelShader;
  3004. var shaderMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"](id, gltfRuntime.scene, shaderPath, options);
  3005. shaderMaterial.onError = onShaderCompileError(program, shaderMaterial, onError);
  3006. shaderMaterial.onCompiled = onShaderCompileSuccess(gltfRuntime, shaderMaterial, technique, material, unTreatedUniforms, onSuccess);
  3007. shaderMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].CounterClockWiseSideOrientation;
  3008. if (states && states.functions) {
  3009. var functions = states.functions;
  3010. if (functions.cullFace && functions.cullFace[0] !== _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ECullingType"].BACK) {
  3011. shaderMaterial.backFaceCulling = false;
  3012. }
  3013. var blendFunc = functions.blendFuncSeparate;
  3014. if (blendFunc) {
  3015. 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) {
  3016. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE;
  3017. }
  3018. 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) {
  3019. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ONEONE;
  3020. }
  3021. 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) {
  3022. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_ADD;
  3023. }
  3024. 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) {
  3025. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_SUBTRACT;
  3026. }
  3027. 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) {
  3028. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MULTIPLY;
  3029. }
  3030. 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) {
  3031. shaderMaterial.alphaMode = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_MAXIMIZED;
  3032. }
  3033. }
  3034. }
  3035. };
  3036. return GLTFLoaderBase;
  3037. }());
  3038. /**
  3039. * glTF V1 Loader
  3040. * @hidden
  3041. */
  3042. var GLTFLoader = /** @class */ (function () {
  3043. function GLTFLoader() {
  3044. this.state = null;
  3045. }
  3046. GLTFLoader.RegisterExtension = function (extension) {
  3047. if (GLTFLoader.Extensions[extension.name]) {
  3048. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Tool with the same name \"" + extension.name + "\" already exists");
  3049. return;
  3050. }
  3051. GLTFLoader.Extensions[extension.name] = extension;
  3052. };
  3053. GLTFLoader.prototype.dispose = function () {
  3054. // do nothing
  3055. };
  3056. GLTFLoader.prototype._importMeshAsync = function (meshesNames, scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3057. var _this = this;
  3058. scene.useRightHandedSystem = true;
  3059. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3060. gltfRuntime.forAssetContainer = forAssetContainer;
  3061. gltfRuntime.importOnlyMeshes = true;
  3062. if (meshesNames === "") {
  3063. gltfRuntime.importMeshesNames = [];
  3064. }
  3065. else if (typeof meshesNames === "string") {
  3066. gltfRuntime.importMeshesNames = [meshesNames];
  3067. }
  3068. else if (meshesNames && !(meshesNames instanceof Array)) {
  3069. gltfRuntime.importMeshesNames = [meshesNames];
  3070. }
  3071. else {
  3072. gltfRuntime.importMeshesNames = [];
  3073. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Argument meshesNames must be of type string or string[]");
  3074. }
  3075. // Create nodes
  3076. _this._createNodes(gltfRuntime);
  3077. var meshes = new Array();
  3078. var skeletons = new Array();
  3079. // Fill arrays of meshes and skeletons
  3080. for (var nde in gltfRuntime.nodes) {
  3081. var node = gltfRuntime.nodes[nde];
  3082. if (node.babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["AbstractMesh"]) {
  3083. meshes.push(node.babylonNode);
  3084. }
  3085. }
  3086. for (var skl in gltfRuntime.skins) {
  3087. var skin = gltfRuntime.skins[skl];
  3088. if (skin.babylonSkeleton instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Skeleton"]) {
  3089. skeletons.push(skin.babylonSkeleton);
  3090. }
  3091. }
  3092. // Load buffers, shaders, materials, etc.
  3093. _this._loadBuffersAsync(gltfRuntime, function () {
  3094. _this._loadShadersAsync(gltfRuntime, function () {
  3095. importMaterials(gltfRuntime);
  3096. postLoad(gltfRuntime);
  3097. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3098. onSuccess(meshes, skeletons);
  3099. }
  3100. });
  3101. }, onProgress);
  3102. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading && onSuccess) {
  3103. onSuccess(meshes, skeletons);
  3104. }
  3105. }, onError);
  3106. return true;
  3107. };
  3108. /**
  3109. * Imports one or more meshes from a loaded gltf file and adds them to the scene
  3110. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3111. * @param scene the scene the meshes should be added to
  3112. * @param forAssetContainer defines if the entities must be stored in the scene
  3113. * @param data gltf data containing information of the meshes in a loaded file
  3114. * @param rootUrl root url to load from
  3115. * @param onProgress event that fires when loading progress has occured
  3116. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3117. */
  3118. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress) {
  3119. var _this = this;
  3120. return new Promise(function (resolve, reject) {
  3121. _this._importMeshAsync(meshesNames, scene, data, rootUrl, forAssetContainer, function (meshes, skeletons) {
  3122. resolve({
  3123. meshes: meshes,
  3124. particleSystems: [],
  3125. skeletons: skeletons,
  3126. animationGroups: [],
  3127. lights: [],
  3128. transformNodes: []
  3129. });
  3130. }, onProgress, function (message) {
  3131. reject(new Error(message));
  3132. });
  3133. });
  3134. };
  3135. GLTFLoader.prototype._loadAsync = function (scene, data, rootUrl, forAssetContainer, onSuccess, onProgress, onError) {
  3136. var _this = this;
  3137. scene.useRightHandedSystem = true;
  3138. GLTFLoaderExtension.LoadRuntimeAsync(scene, data, rootUrl, function (gltfRuntime) {
  3139. // Load runtime extensios
  3140. GLTFLoaderExtension.LoadRuntimeExtensionsAsync(gltfRuntime, function () {
  3141. // Create nodes
  3142. _this._createNodes(gltfRuntime);
  3143. // Load buffers, shaders, materials, etc.
  3144. _this._loadBuffersAsync(gltfRuntime, function () {
  3145. _this._loadShadersAsync(gltfRuntime, function () {
  3146. importMaterials(gltfRuntime);
  3147. postLoad(gltfRuntime);
  3148. if (!_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3149. onSuccess();
  3150. }
  3151. });
  3152. });
  3153. if (_glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"].IncrementalLoading) {
  3154. onSuccess();
  3155. }
  3156. }, onError);
  3157. }, onError);
  3158. };
  3159. /**
  3160. * Imports all objects from a loaded gltf file and adds them to the scene
  3161. * @param scene the scene the objects should be added to
  3162. * @param data gltf data containing information of the meshes in a loaded file
  3163. * @param rootUrl root url to load from
  3164. * @param onProgress event that fires when loading progress has occured
  3165. * @returns a promise which completes when objects have been loaded to the scene
  3166. */
  3167. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress) {
  3168. var _this = this;
  3169. return new Promise(function (resolve, reject) {
  3170. _this._loadAsync(scene, data, rootUrl, false, function () {
  3171. resolve();
  3172. }, onProgress, function (message) {
  3173. reject(new Error(message));
  3174. });
  3175. });
  3176. };
  3177. GLTFLoader.prototype._loadShadersAsync = function (gltfRuntime, onload) {
  3178. var hasShaders = false;
  3179. var processShader = function (sha, shader) {
  3180. GLTFLoaderExtension.LoadShaderStringAsync(gltfRuntime, sha, function (shaderString) {
  3181. if (shaderString instanceof ArrayBuffer) {
  3182. return;
  3183. }
  3184. gltfRuntime.loadedShaderCount++;
  3185. if (shaderString) {
  3186. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore[sha + (shader.type === _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EShaderType"].VERTEX ? "VertexShader" : "PixelShader")] = shaderString;
  3187. }
  3188. if (gltfRuntime.loadedShaderCount === gltfRuntime.shaderscount) {
  3189. onload();
  3190. }
  3191. }, function () {
  3192. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading shader program named " + sha + " located at " + shader.uri);
  3193. });
  3194. };
  3195. for (var sha in gltfRuntime.shaders) {
  3196. hasShaders = true;
  3197. var shader = gltfRuntime.shaders[sha];
  3198. if (shader) {
  3199. processShader.bind(this, sha, shader)();
  3200. }
  3201. else {
  3202. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No shader named: " + sha);
  3203. }
  3204. }
  3205. if (!hasShaders) {
  3206. onload();
  3207. }
  3208. };
  3209. GLTFLoader.prototype._loadBuffersAsync = function (gltfRuntime, onLoad, onProgress) {
  3210. var hasBuffers = false;
  3211. var processBuffer = function (buf, buffer) {
  3212. GLTFLoaderExtension.LoadBufferAsync(gltfRuntime, buf, function (bufferView) {
  3213. gltfRuntime.loadedBufferCount++;
  3214. if (bufferView) {
  3215. if (bufferView.byteLength != gltfRuntime.buffers[buf].byteLength) {
  3216. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Buffer named " + buf + " is length " + bufferView.byteLength + ". Expected: " + buffer.byteLength); // Improve error message
  3217. }
  3218. gltfRuntime.loadedBufferViews[buf] = bufferView;
  3219. }
  3220. if (gltfRuntime.loadedBufferCount === gltfRuntime.buffersCount) {
  3221. onLoad();
  3222. }
  3223. }, function () {
  3224. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Error when loading buffer named " + buf + " located at " + buffer.uri);
  3225. });
  3226. };
  3227. for (var buf in gltfRuntime.buffers) {
  3228. hasBuffers = true;
  3229. var buffer = gltfRuntime.buffers[buf];
  3230. if (buffer) {
  3231. processBuffer.bind(this, buf, buffer)();
  3232. }
  3233. else {
  3234. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("No buffer named: " + buf);
  3235. }
  3236. }
  3237. if (!hasBuffers) {
  3238. onLoad();
  3239. }
  3240. };
  3241. GLTFLoader.prototype._createNodes = function (gltfRuntime) {
  3242. var currentScene = gltfRuntime.currentScene;
  3243. if (currentScene) {
  3244. // Only one scene even if multiple scenes are defined
  3245. for (var i = 0; i < currentScene.nodes.length; i++) {
  3246. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3247. }
  3248. }
  3249. else {
  3250. // Load all scenes
  3251. for (var thing in gltfRuntime.scenes) {
  3252. currentScene = gltfRuntime.scenes[thing];
  3253. for (var i = 0; i < currentScene.nodes.length; i++) {
  3254. traverseNodes(gltfRuntime, currentScene.nodes[i], null);
  3255. }
  3256. }
  3257. }
  3258. };
  3259. GLTFLoader.Extensions = {};
  3260. return GLTFLoader;
  3261. }());
  3262. /** @hidden */
  3263. var GLTFLoaderExtension = /** @class */ (function () {
  3264. function GLTFLoaderExtension(name) {
  3265. this._name = name;
  3266. }
  3267. Object.defineProperty(GLTFLoaderExtension.prototype, "name", {
  3268. get: function () {
  3269. return this._name;
  3270. },
  3271. enumerable: true,
  3272. configurable: true
  3273. });
  3274. /**
  3275. * Defines an override for loading the runtime
  3276. * Return true to stop further extensions from loading the runtime
  3277. */
  3278. GLTFLoaderExtension.prototype.loadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3279. return false;
  3280. };
  3281. /**
  3282. * Defines an onverride for creating gltf runtime
  3283. * Return true to stop further extensions from creating the runtime
  3284. */
  3285. GLTFLoaderExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3286. return false;
  3287. };
  3288. /**
  3289. * Defines an override for loading buffers
  3290. * Return true to stop further extensions from loading this buffer
  3291. */
  3292. GLTFLoaderExtension.prototype.loadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3293. return false;
  3294. };
  3295. /**
  3296. * Defines an override for loading texture buffers
  3297. * Return true to stop further extensions from loading this texture data
  3298. */
  3299. GLTFLoaderExtension.prototype.loadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3300. return false;
  3301. };
  3302. /**
  3303. * Defines an override for creating textures
  3304. * Return true to stop further extensions from loading this texture
  3305. */
  3306. GLTFLoaderExtension.prototype.createTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3307. return false;
  3308. };
  3309. /**
  3310. * Defines an override for loading shader strings
  3311. * Return true to stop further extensions from loading this shader data
  3312. */
  3313. GLTFLoaderExtension.prototype.loadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3314. return false;
  3315. };
  3316. /**
  3317. * Defines an override for loading materials
  3318. * Return true to stop further extensions from loading this material
  3319. */
  3320. GLTFLoaderExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3321. return false;
  3322. };
  3323. // ---------
  3324. // Utilities
  3325. // ---------
  3326. GLTFLoaderExtension.LoadRuntimeAsync = function (scene, data, rootUrl, onSuccess, onError) {
  3327. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3328. return loaderExtension.loadRuntimeAsync(scene, data, rootUrl, onSuccess, onError);
  3329. }, function () {
  3330. setTimeout(function () {
  3331. if (!onSuccess) {
  3332. return;
  3333. }
  3334. onSuccess(GLTFLoaderBase.CreateRuntime(data.json, scene, rootUrl));
  3335. });
  3336. });
  3337. };
  3338. GLTFLoaderExtension.LoadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3339. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3340. return loaderExtension.loadRuntimeExtensionsAsync(gltfRuntime, onSuccess, onError);
  3341. }, function () {
  3342. setTimeout(function () {
  3343. onSuccess();
  3344. });
  3345. });
  3346. };
  3347. GLTFLoaderExtension.LoadBufferAsync = function (gltfRuntime, id, onSuccess, onError, onProgress) {
  3348. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3349. return loaderExtension.loadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3350. }, function () {
  3351. GLTFLoaderBase.LoadBufferAsync(gltfRuntime, id, onSuccess, onError, onProgress);
  3352. });
  3353. };
  3354. GLTFLoaderExtension.LoadTextureAsync = function (gltfRuntime, id, onSuccess, onError) {
  3355. GLTFLoaderExtension.LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3356. if (buffer) {
  3357. GLTFLoaderExtension.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3358. }
  3359. }, onError);
  3360. };
  3361. GLTFLoaderExtension.LoadShaderStringAsync = function (gltfRuntime, id, onSuccess, onError) {
  3362. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3363. return loaderExtension.loadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3364. }, function () {
  3365. GLTFLoaderBase.LoadShaderStringAsync(gltfRuntime, id, onSuccess, onError);
  3366. });
  3367. };
  3368. GLTFLoaderExtension.LoadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3369. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3370. return loaderExtension.loadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3371. }, function () {
  3372. GLTFLoaderBase.LoadMaterialAsync(gltfRuntime, id, onSuccess, onError);
  3373. });
  3374. };
  3375. GLTFLoaderExtension.LoadTextureBufferAsync = function (gltfRuntime, id, onSuccess, onError) {
  3376. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3377. return loaderExtension.loadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3378. }, function () {
  3379. GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, onSuccess, onError);
  3380. });
  3381. };
  3382. GLTFLoaderExtension.CreateTextureAsync = function (gltfRuntime, id, buffer, onSuccess, onError) {
  3383. GLTFLoaderExtension.ApplyExtensions(function (loaderExtension) {
  3384. return loaderExtension.createTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3385. }, function () {
  3386. GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, onSuccess, onError);
  3387. });
  3388. };
  3389. GLTFLoaderExtension.ApplyExtensions = function (func, defaultFunc) {
  3390. for (var extensionName in GLTFLoader.Extensions) {
  3391. var loaderExtension = GLTFLoader.Extensions[extensionName];
  3392. if (func(loaderExtension)) {
  3393. return;
  3394. }
  3395. }
  3396. defaultFunc();
  3397. };
  3398. return GLTFLoaderExtension;
  3399. }());
  3400. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_3__["GLTFFileLoader"]._CreateGLTF1Loader = function () { return new GLTFLoader(); };
  3401. /***/ }),
  3402. /***/ "./glTF/1.0/glTFLoaderInterfaces.ts":
  3403. /*!******************************************!*\
  3404. !*** ./glTF/1.0/glTFLoaderInterfaces.ts ***!
  3405. \******************************************/
  3406. /*! exports provided: EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction */
  3407. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3408. "use strict";
  3409. __webpack_require__.r(__webpack_exports__);
  3410. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return EComponentType; });
  3411. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return EShaderType; });
  3412. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return EParameterType; });
  3413. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return ETextureWrapMode; });
  3414. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return ETextureFilterType; });
  3415. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return ETextureFormat; });
  3416. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return ECullingType; });
  3417. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return EBlendingFunction; });
  3418. /**
  3419. * Enums
  3420. * @hidden
  3421. */
  3422. var EComponentType;
  3423. (function (EComponentType) {
  3424. EComponentType[EComponentType["BYTE"] = 5120] = "BYTE";
  3425. EComponentType[EComponentType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3426. EComponentType[EComponentType["SHORT"] = 5122] = "SHORT";
  3427. EComponentType[EComponentType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3428. EComponentType[EComponentType["FLOAT"] = 5126] = "FLOAT";
  3429. })(EComponentType || (EComponentType = {}));
  3430. /** @hidden */
  3431. var EShaderType;
  3432. (function (EShaderType) {
  3433. EShaderType[EShaderType["FRAGMENT"] = 35632] = "FRAGMENT";
  3434. EShaderType[EShaderType["VERTEX"] = 35633] = "VERTEX";
  3435. })(EShaderType || (EShaderType = {}));
  3436. /** @hidden */
  3437. var EParameterType;
  3438. (function (EParameterType) {
  3439. EParameterType[EParameterType["BYTE"] = 5120] = "BYTE";
  3440. EParameterType[EParameterType["UNSIGNED_BYTE"] = 5121] = "UNSIGNED_BYTE";
  3441. EParameterType[EParameterType["SHORT"] = 5122] = "SHORT";
  3442. EParameterType[EParameterType["UNSIGNED_SHORT"] = 5123] = "UNSIGNED_SHORT";
  3443. EParameterType[EParameterType["INT"] = 5124] = "INT";
  3444. EParameterType[EParameterType["UNSIGNED_INT"] = 5125] = "UNSIGNED_INT";
  3445. EParameterType[EParameterType["FLOAT"] = 5126] = "FLOAT";
  3446. EParameterType[EParameterType["FLOAT_VEC2"] = 35664] = "FLOAT_VEC2";
  3447. EParameterType[EParameterType["FLOAT_VEC3"] = 35665] = "FLOAT_VEC3";
  3448. EParameterType[EParameterType["FLOAT_VEC4"] = 35666] = "FLOAT_VEC4";
  3449. EParameterType[EParameterType["INT_VEC2"] = 35667] = "INT_VEC2";
  3450. EParameterType[EParameterType["INT_VEC3"] = 35668] = "INT_VEC3";
  3451. EParameterType[EParameterType["INT_VEC4"] = 35669] = "INT_VEC4";
  3452. EParameterType[EParameterType["BOOL"] = 35670] = "BOOL";
  3453. EParameterType[EParameterType["BOOL_VEC2"] = 35671] = "BOOL_VEC2";
  3454. EParameterType[EParameterType["BOOL_VEC3"] = 35672] = "BOOL_VEC3";
  3455. EParameterType[EParameterType["BOOL_VEC4"] = 35673] = "BOOL_VEC4";
  3456. EParameterType[EParameterType["FLOAT_MAT2"] = 35674] = "FLOAT_MAT2";
  3457. EParameterType[EParameterType["FLOAT_MAT3"] = 35675] = "FLOAT_MAT3";
  3458. EParameterType[EParameterType["FLOAT_MAT4"] = 35676] = "FLOAT_MAT4";
  3459. EParameterType[EParameterType["SAMPLER_2D"] = 35678] = "SAMPLER_2D";
  3460. })(EParameterType || (EParameterType = {}));
  3461. /** @hidden */
  3462. var ETextureWrapMode;
  3463. (function (ETextureWrapMode) {
  3464. ETextureWrapMode[ETextureWrapMode["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
  3465. ETextureWrapMode[ETextureWrapMode["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
  3466. ETextureWrapMode[ETextureWrapMode["REPEAT"] = 10497] = "REPEAT";
  3467. })(ETextureWrapMode || (ETextureWrapMode = {}));
  3468. /** @hidden */
  3469. var ETextureFilterType;
  3470. (function (ETextureFilterType) {
  3471. ETextureFilterType[ETextureFilterType["NEAREST"] = 9728] = "NEAREST";
  3472. ETextureFilterType[ETextureFilterType["LINEAR"] = 9728] = "LINEAR";
  3473. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
  3474. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
  3475. ETextureFilterType[ETextureFilterType["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
  3476. ETextureFilterType[ETextureFilterType["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
  3477. })(ETextureFilterType || (ETextureFilterType = {}));
  3478. /** @hidden */
  3479. var ETextureFormat;
  3480. (function (ETextureFormat) {
  3481. ETextureFormat[ETextureFormat["ALPHA"] = 6406] = "ALPHA";
  3482. ETextureFormat[ETextureFormat["RGB"] = 6407] = "RGB";
  3483. ETextureFormat[ETextureFormat["RGBA"] = 6408] = "RGBA";
  3484. ETextureFormat[ETextureFormat["LUMINANCE"] = 6409] = "LUMINANCE";
  3485. ETextureFormat[ETextureFormat["LUMINANCE_ALPHA"] = 6410] = "LUMINANCE_ALPHA";
  3486. })(ETextureFormat || (ETextureFormat = {}));
  3487. /** @hidden */
  3488. var ECullingType;
  3489. (function (ECullingType) {
  3490. ECullingType[ECullingType["FRONT"] = 1028] = "FRONT";
  3491. ECullingType[ECullingType["BACK"] = 1029] = "BACK";
  3492. ECullingType[ECullingType["FRONT_AND_BACK"] = 1032] = "FRONT_AND_BACK";
  3493. })(ECullingType || (ECullingType = {}));
  3494. /** @hidden */
  3495. var EBlendingFunction;
  3496. (function (EBlendingFunction) {
  3497. EBlendingFunction[EBlendingFunction["ZERO"] = 0] = "ZERO";
  3498. EBlendingFunction[EBlendingFunction["ONE"] = 1] = "ONE";
  3499. EBlendingFunction[EBlendingFunction["SRC_COLOR"] = 768] = "SRC_COLOR";
  3500. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_COLOR"] = 769] = "ONE_MINUS_SRC_COLOR";
  3501. EBlendingFunction[EBlendingFunction["DST_COLOR"] = 774] = "DST_COLOR";
  3502. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_COLOR"] = 775] = "ONE_MINUS_DST_COLOR";
  3503. EBlendingFunction[EBlendingFunction["SRC_ALPHA"] = 770] = "SRC_ALPHA";
  3504. EBlendingFunction[EBlendingFunction["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
  3505. EBlendingFunction[EBlendingFunction["DST_ALPHA"] = 772] = "DST_ALPHA";
  3506. EBlendingFunction[EBlendingFunction["ONE_MINUS_DST_ALPHA"] = 773] = "ONE_MINUS_DST_ALPHA";
  3507. EBlendingFunction[EBlendingFunction["CONSTANT_COLOR"] = 32769] = "CONSTANT_COLOR";
  3508. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_COLOR"] = 32770] = "ONE_MINUS_CONSTANT_COLOR";
  3509. EBlendingFunction[EBlendingFunction["CONSTANT_ALPHA"] = 32771] = "CONSTANT_ALPHA";
  3510. EBlendingFunction[EBlendingFunction["ONE_MINUS_CONSTANT_ALPHA"] = 32772] = "ONE_MINUS_CONSTANT_ALPHA";
  3511. EBlendingFunction[EBlendingFunction["SRC_ALPHA_SATURATE"] = 776] = "SRC_ALPHA_SATURATE";
  3512. })(EBlendingFunction || (EBlendingFunction = {}));
  3513. /***/ }),
  3514. /***/ "./glTF/1.0/glTFLoaderUtils.ts":
  3515. /*!*************************************!*\
  3516. !*** ./glTF/1.0/glTFLoaderUtils.ts ***!
  3517. \*************************************/
  3518. /*! exports provided: GLTFUtils */
  3519. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3520. "use strict";
  3521. __webpack_require__.r(__webpack_exports__);
  3522. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return GLTFUtils; });
  3523. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3524. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3525. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  3526. /**
  3527. * Utils functions for GLTF
  3528. * @hidden
  3529. */
  3530. var GLTFUtils = /** @class */ (function () {
  3531. function GLTFUtils() {
  3532. }
  3533. /**
  3534. * Sets the given "parameter" matrix
  3535. * @param scene: the Scene object
  3536. * @param source: the source node where to pick the matrix
  3537. * @param parameter: the GLTF technique parameter
  3538. * @param uniformName: the name of the shader's uniform
  3539. * @param shaderMaterial: the shader material
  3540. */
  3541. GLTFUtils.SetMatrix = function (scene, source, parameter, uniformName, shaderMaterial) {
  3542. var mat = null;
  3543. if (parameter.semantic === "MODEL") {
  3544. mat = source.getWorldMatrix();
  3545. }
  3546. else if (parameter.semantic === "PROJECTION") {
  3547. mat = scene.getProjectionMatrix();
  3548. }
  3549. else if (parameter.semantic === "VIEW") {
  3550. mat = scene.getViewMatrix();
  3551. }
  3552. else if (parameter.semantic === "MODELVIEWINVERSETRANSPOSE") {
  3553. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().multiply(scene.getViewMatrix()).invert());
  3554. }
  3555. else if (parameter.semantic === "MODELVIEW") {
  3556. mat = source.getWorldMatrix().multiply(scene.getViewMatrix());
  3557. }
  3558. else if (parameter.semantic === "MODELVIEWPROJECTION") {
  3559. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix());
  3560. }
  3561. else if (parameter.semantic === "MODELINVERSE") {
  3562. mat = source.getWorldMatrix().invert();
  3563. }
  3564. else if (parameter.semantic === "VIEWINVERSE") {
  3565. mat = scene.getViewMatrix().invert();
  3566. }
  3567. else if (parameter.semantic === "PROJECTIONINVERSE") {
  3568. mat = scene.getProjectionMatrix().invert();
  3569. }
  3570. else if (parameter.semantic === "MODELVIEWINVERSE") {
  3571. mat = source.getWorldMatrix().multiply(scene.getViewMatrix()).invert();
  3572. }
  3573. else if (parameter.semantic === "MODELVIEWPROJECTIONINVERSE") {
  3574. mat = source.getWorldMatrix().multiply(scene.getTransformMatrix()).invert();
  3575. }
  3576. else if (parameter.semantic === "MODELINVERSETRANSPOSE") {
  3577. mat = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].Transpose(source.getWorldMatrix().invert());
  3578. }
  3579. else {
  3580. debugger;
  3581. }
  3582. if (mat) {
  3583. switch (parameter.type) {
  3584. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT2:
  3585. shaderMaterial.setMatrix2x2(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix2x2(mat));
  3586. break;
  3587. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT3:
  3588. shaderMaterial.setMatrix3x3(uniformName, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].GetAsMatrix3x3(mat));
  3589. break;
  3590. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_MAT4:
  3591. shaderMaterial.setMatrix(uniformName, mat);
  3592. break;
  3593. default: break;
  3594. }
  3595. }
  3596. };
  3597. /**
  3598. * Sets the given "parameter" matrix
  3599. * @param shaderMaterial: the shader material
  3600. * @param uniform: the name of the shader's uniform
  3601. * @param value: the value of the uniform
  3602. * @param type: the uniform's type (EParameterType FLOAT, VEC2, VEC3 or VEC4)
  3603. */
  3604. GLTFUtils.SetUniform = function (shaderMaterial, uniform, value, type) {
  3605. switch (type) {
  3606. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT:
  3607. shaderMaterial.setFloat(uniform, value);
  3608. return true;
  3609. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC2:
  3610. shaderMaterial.setVector2(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(value));
  3611. return true;
  3612. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC3:
  3613. shaderMaterial.setVector3(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(value));
  3614. return true;
  3615. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EParameterType"].FLOAT_VEC4:
  3616. shaderMaterial.setVector4(uniform, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(value));
  3617. return true;
  3618. default: return false;
  3619. }
  3620. };
  3621. /**
  3622. * Returns the wrap mode of the texture
  3623. * @param mode: the mode value
  3624. */
  3625. GLTFUtils.GetWrapMode = function (mode) {
  3626. switch (mode) {
  3627. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].CLAMP_TO_EDGE: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  3628. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].MIRRORED_REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE;
  3629. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureWrapMode"].REPEAT: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3630. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  3631. }
  3632. };
  3633. /**
  3634. * Returns the byte stride giving an accessor
  3635. * @param accessor: the GLTF accessor objet
  3636. */
  3637. GLTFUtils.GetByteStrideFromType = function (accessor) {
  3638. // Needs this function since "byteStride" isn't requiered in glTF format
  3639. var type = accessor.type;
  3640. switch (type) {
  3641. case "VEC2": return 2;
  3642. case "VEC3": return 3;
  3643. case "VEC4": return 4;
  3644. case "MAT2": return 4;
  3645. case "MAT3": return 9;
  3646. case "MAT4": return 16;
  3647. default: return 1;
  3648. }
  3649. };
  3650. /**
  3651. * Returns the texture filter mode giving a mode value
  3652. * @param mode: the filter mode value
  3653. */
  3654. GLTFUtils.GetTextureFilterMode = function (mode) {
  3655. switch (mode) {
  3656. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR:
  3657. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_NEAREST:
  3658. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].LINEAR_MIPMAP_LINEAR: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE;
  3659. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST:
  3660. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["ETextureFilterType"].NEAREST_MIPMAP_NEAREST: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE;
  3661. default: return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].BILINEAR_SAMPLINGMODE;
  3662. }
  3663. };
  3664. GLTFUtils.GetBufferFromBufferView = function (gltfRuntime, bufferView, byteOffset, byteLength, componentType) {
  3665. var byteOffset = bufferView.byteOffset + byteOffset;
  3666. var loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
  3667. if (byteOffset + byteLength > loadedBufferView.byteLength) {
  3668. throw new Error("Buffer access is out of range");
  3669. }
  3670. var buffer = loadedBufferView.buffer;
  3671. byteOffset += loadedBufferView.byteOffset;
  3672. switch (componentType) {
  3673. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].BYTE: return new Int8Array(buffer, byteOffset, byteLength);
  3674. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_BYTE: return new Uint8Array(buffer, byteOffset, byteLength);
  3675. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].SHORT: return new Int16Array(buffer, byteOffset, byteLength);
  3676. case _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_0__["EComponentType"].UNSIGNED_SHORT: return new Uint16Array(buffer, byteOffset, byteLength);
  3677. default: return new Float32Array(buffer, byteOffset, byteLength);
  3678. }
  3679. };
  3680. /**
  3681. * Returns a buffer from its accessor
  3682. * @param gltfRuntime: the GLTF runtime
  3683. * @param accessor: the GLTF accessor
  3684. */
  3685. GLTFUtils.GetBufferFromAccessor = function (gltfRuntime, accessor) {
  3686. var bufferView = gltfRuntime.bufferViews[accessor.bufferView];
  3687. var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
  3688. return GLTFUtils.GetBufferFromBufferView(gltfRuntime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
  3689. };
  3690. /**
  3691. * Decodes a buffer view into a string
  3692. * @param view: the buffer view
  3693. */
  3694. GLTFUtils.DecodeBufferToText = function (view) {
  3695. var result = "";
  3696. var length = view.byteLength;
  3697. for (var i = 0; i < length; ++i) {
  3698. result += String.fromCharCode(view[i]);
  3699. }
  3700. return result;
  3701. };
  3702. /**
  3703. * Returns the default material of gltf. Related to
  3704. * https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a-default-material
  3705. * @param scene: the Babylon.js scene
  3706. */
  3707. GLTFUtils.GetDefaultMaterial = function (scene) {
  3708. if (!GLTFUtils._DefaultMaterial) {
  3709. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialVertexShader"] = [
  3710. "precision highp float;",
  3711. "",
  3712. "uniform mat4 worldView;",
  3713. "uniform mat4 projection;",
  3714. "",
  3715. "attribute vec3 position;",
  3716. "",
  3717. "void main(void)",
  3718. "{",
  3719. " gl_Position = projection * worldView * vec4(position, 1.0);",
  3720. "}"
  3721. ].join("\n");
  3722. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Effect"].ShadersStore["GLTFDefaultMaterialPixelShader"] = [
  3723. "precision highp float;",
  3724. "",
  3725. "uniform vec4 u_emission;",
  3726. "",
  3727. "void main(void)",
  3728. "{",
  3729. " gl_FragColor = u_emission;",
  3730. "}"
  3731. ].join("\n");
  3732. var shaderPath = {
  3733. vertex: "GLTFDefaultMaterial",
  3734. fragment: "GLTFDefaultMaterial"
  3735. };
  3736. var options = {
  3737. attributes: ["position"],
  3738. uniforms: ["worldView", "projection", "u_emission"],
  3739. samplers: new Array(),
  3740. needAlphaBlending: false
  3741. };
  3742. GLTFUtils._DefaultMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["ShaderMaterial"]("GLTFDefaultMaterial", scene, shaderPath, options);
  3743. GLTFUtils._DefaultMaterial.setColor4("u_emission", new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"](0.5, 0.5, 0.5, 1.0));
  3744. }
  3745. return GLTFUtils._DefaultMaterial;
  3746. };
  3747. // The GLTF default material
  3748. GLTFUtils._DefaultMaterial = null;
  3749. return GLTFUtils;
  3750. }());
  3751. /***/ }),
  3752. /***/ "./glTF/1.0/glTFMaterialsCommonExtension.ts":
  3753. /*!**************************************************!*\
  3754. !*** ./glTF/1.0/glTFMaterialsCommonExtension.ts ***!
  3755. \**************************************************/
  3756. /*! exports provided: GLTFMaterialsCommonExtension */
  3757. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3758. "use strict";
  3759. __webpack_require__.r(__webpack_exports__);
  3760. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return GLTFMaterialsCommonExtension; });
  3761. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3762. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3763. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  3764. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__);
  3765. /** @hidden */
  3766. var GLTFMaterialsCommonExtension = /** @class */ (function (_super) {
  3767. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(GLTFMaterialsCommonExtension, _super);
  3768. function GLTFMaterialsCommonExtension() {
  3769. return _super.call(this, "KHR_materials_common") || this;
  3770. }
  3771. GLTFMaterialsCommonExtension.prototype.loadRuntimeExtensionsAsync = function (gltfRuntime, onSuccess, onError) {
  3772. if (!gltfRuntime.extensions) {
  3773. return false;
  3774. }
  3775. var extension = gltfRuntime.extensions[this.name];
  3776. if (!extension) {
  3777. return false;
  3778. }
  3779. // Create lights
  3780. var lights = extension.lights;
  3781. if (lights) {
  3782. for (var thing in lights) {
  3783. var light = lights[thing];
  3784. switch (light.type) {
  3785. case "ambient":
  3786. 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);
  3787. var ambient = light.ambient;
  3788. if (ambient) {
  3789. ambientLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(ambient.color || [1, 1, 1]);
  3790. }
  3791. break;
  3792. case "point":
  3793. 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);
  3794. var point = light.point;
  3795. if (point) {
  3796. pointLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(point.color || [1, 1, 1]);
  3797. }
  3798. break;
  3799. case "directional":
  3800. 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);
  3801. var directional = light.directional;
  3802. if (directional) {
  3803. dirLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(directional.color || [1, 1, 1]);
  3804. }
  3805. break;
  3806. case "spot":
  3807. var spot = light.spot;
  3808. if (spot) {
  3809. 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);
  3810. spotLight.diffuse = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(spot.color || [1, 1, 1]);
  3811. }
  3812. break;
  3813. default:
  3814. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Tools"].Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported");
  3815. break;
  3816. }
  3817. }
  3818. }
  3819. return false;
  3820. };
  3821. GLTFMaterialsCommonExtension.prototype.loadMaterialAsync = function (gltfRuntime, id, onSuccess, onError) {
  3822. var material = gltfRuntime.materials[id];
  3823. if (!material || !material.extensions) {
  3824. return false;
  3825. }
  3826. var extension = material.extensions[this.name];
  3827. if (!extension) {
  3828. return false;
  3829. }
  3830. var standardMaterial = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["StandardMaterial"](id, gltfRuntime.scene);
  3831. standardMaterial.sideOrientation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Material"].CounterClockWiseSideOrientation;
  3832. if (extension.technique === "CONSTANT") {
  3833. standardMaterial.disableLighting = true;
  3834. }
  3835. standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
  3836. standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
  3837. standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
  3838. // Ambient
  3839. if (typeof extension.values.ambient === "string") {
  3840. this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
  3841. }
  3842. else {
  3843. standardMaterial.ambientColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.ambient || [0, 0, 0]);
  3844. }
  3845. // Diffuse
  3846. if (typeof extension.values.diffuse === "string") {
  3847. this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
  3848. }
  3849. else {
  3850. standardMaterial.diffuseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.diffuse || [0, 0, 0]);
  3851. }
  3852. // Emission
  3853. if (typeof extension.values.emission === "string") {
  3854. this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
  3855. }
  3856. else {
  3857. standardMaterial.emissiveColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.emission || [0, 0, 0]);
  3858. }
  3859. // Specular
  3860. if (typeof extension.values.specular === "string") {
  3861. this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
  3862. }
  3863. else {
  3864. standardMaterial.specularColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_2__["Color3"].FromArray(extension.values.specular || [0, 0, 0]);
  3865. }
  3866. return true;
  3867. };
  3868. GLTFMaterialsCommonExtension.prototype._loadTexture = function (gltfRuntime, id, material, propertyPath, onError) {
  3869. // Create buffer from texture url
  3870. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].LoadTextureBufferAsync(gltfRuntime, id, function (buffer) {
  3871. // Create texture from buffer
  3872. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"].CreateTextureAsync(gltfRuntime, id, buffer, function (texture) { return material[propertyPath] = texture; }, onError);
  3873. }, onError);
  3874. };
  3875. return GLTFMaterialsCommonExtension;
  3876. }(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]));
  3877. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(new GLTFMaterialsCommonExtension());
  3878. /***/ }),
  3879. /***/ "./glTF/1.0/index.ts":
  3880. /*!***************************!*\
  3881. !*** ./glTF/1.0/index.ts ***!
  3882. \***************************/
  3883. /*! exports provided: GLTFBinaryExtension, GLTFLoaderBase, GLTFLoader, GLTFLoaderExtension, EComponentType, EShaderType, EParameterType, ETextureWrapMode, ETextureFilterType, ETextureFormat, ECullingType, EBlendingFunction, GLTFUtils, GLTFMaterialsCommonExtension */
  3884. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3885. "use strict";
  3886. __webpack_require__.r(__webpack_exports__);
  3887. /* harmony import */ var _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFBinaryExtension */ "./glTF/1.0/glTFBinaryExtension.ts");
  3888. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFBinaryExtension", function() { return _glTFBinaryExtension__WEBPACK_IMPORTED_MODULE_0__["GLTFBinaryExtension"]; });
  3889. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/1.0/glTFLoader.ts");
  3890. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderBase", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderBase"]; });
  3891. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"]; });
  3892. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderExtension", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderExtension"]; });
  3893. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/1.0/glTFLoaderInterfaces.ts");
  3894. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EComponentType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EComponentType"]; });
  3895. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EShaderType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EShaderType"]; });
  3896. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EParameterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EParameterType"]; });
  3897. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureWrapMode", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureWrapMode"]; });
  3898. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFilterType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFilterType"]; });
  3899. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ETextureFormat", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ETextureFormat"]; });
  3900. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ECullingType", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["ECullingType"]; });
  3901. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EBlendingFunction", function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__["EBlendingFunction"]; });
  3902. /* harmony import */ var _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFLoaderUtils */ "./glTF/1.0/glTFLoaderUtils.ts");
  3903. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFUtils", function() { return _glTFLoaderUtils__WEBPACK_IMPORTED_MODULE_3__["GLTFUtils"]; });
  3904. /* harmony import */ var _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialsCommonExtension */ "./glTF/1.0/glTFMaterialsCommonExtension.ts");
  3905. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFMaterialsCommonExtension", function() { return _glTFMaterialsCommonExtension__WEBPACK_IMPORTED_MODULE_4__["GLTFMaterialsCommonExtension"]; });
  3906. /***/ }),
  3907. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  3908. /*!*******************************************************!*\
  3909. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  3910. \*******************************************************/
  3911. /*! exports provided: EXT_lights_image_based */
  3912. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3913. "use strict";
  3914. __webpack_require__.r(__webpack_exports__);
  3915. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  3916. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  3917. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  3918. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3919. var NAME = "EXT_lights_image_based";
  3920. /**
  3921. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  3922. */
  3923. var EXT_lights_image_based = /** @class */ (function () {
  3924. /** @hidden */
  3925. function EXT_lights_image_based(loader) {
  3926. /**
  3927. * The name of this extension.
  3928. */
  3929. this.name = NAME;
  3930. this._loader = loader;
  3931. this.enabled = this._loader.isExtensionUsed(NAME);
  3932. }
  3933. /** @hidden */
  3934. EXT_lights_image_based.prototype.dispose = function () {
  3935. delete this._loader;
  3936. delete this._lights;
  3937. };
  3938. /** @hidden */
  3939. EXT_lights_image_based.prototype.onLoading = function () {
  3940. var extensions = this._loader.gltf.extensions;
  3941. if (extensions && extensions[this.name]) {
  3942. var extension = extensions[this.name];
  3943. this._lights = extension.lights;
  3944. }
  3945. };
  3946. /** @hidden */
  3947. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  3948. var _this = this;
  3949. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  3950. var promises = new Array();
  3951. promises.push(_this._loader.loadSceneAsync(context, scene));
  3952. _this._loader.logOpen("" + extensionContext);
  3953. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  3954. promises.push(_this._loadLightAsync("#/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  3955. _this._loader.babylonScene.environmentTexture = texture;
  3956. }));
  3957. _this._loader.logClose();
  3958. return Promise.all(promises).then(function () { });
  3959. });
  3960. };
  3961. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  3962. var _this = this;
  3963. if (!light._loaded) {
  3964. var promises = new Array();
  3965. this._loader.logOpen("" + context);
  3966. var imageData_1 = new Array(light.specularImages.length);
  3967. var _loop_1 = function (mipmap) {
  3968. var faces = light.specularImages[mipmap];
  3969. imageData_1[mipmap] = new Array(faces.length);
  3970. var _loop_2 = function (face) {
  3971. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  3972. this_1._loader.logOpen("" + specularImageContext);
  3973. var index = faces[face];
  3974. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  3975. promises.push(this_1._loader.loadImageAsync("#/images/" + index, image).then(function (data) {
  3976. imageData_1[mipmap][face] = data;
  3977. }));
  3978. this_1._loader.logClose();
  3979. };
  3980. for (var face = 0; face < faces.length; face++) {
  3981. _loop_2(face);
  3982. }
  3983. };
  3984. var this_1 = this;
  3985. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  3986. _loop_1(mipmap);
  3987. }
  3988. this._loader.logClose();
  3989. light._loaded = Promise.all(promises).then(function () {
  3990. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  3991. light._babylonTexture = babylonTexture;
  3992. if (light.intensity != undefined) {
  3993. babylonTexture.level = light.intensity;
  3994. }
  3995. if (light.rotation) {
  3996. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  3997. // Invert the rotation so that positive rotation is counter-clockwise.
  3998. if (!_this._loader.babylonScene.useRightHandedSystem) {
  3999. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  4000. }
  4001. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  4002. }
  4003. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  4004. sphericalHarmonics.scaleInPlace(light.intensity);
  4005. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  4006. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  4007. // Compute the lod generation scale to fit exactly to the number of levels available.
  4008. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  4009. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  4010. });
  4011. }
  4012. return light._loaded.then(function () {
  4013. return light._babylonTexture;
  4014. });
  4015. };
  4016. return EXT_lights_image_based;
  4017. }());
  4018. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  4019. /***/ }),
  4020. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  4021. /*!*************************************************!*\
  4022. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  4023. \*************************************************/
  4024. /*! exports provided: ExtrasAsMetadata */
  4025. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4026. "use strict";
  4027. __webpack_require__.r(__webpack_exports__);
  4028. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  4029. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4030. var NAME = "ExtrasAsMetadata";
  4031. /**
  4032. * Store glTF extras (if present) in BJS objects' metadata
  4033. */
  4034. var ExtrasAsMetadata = /** @class */ (function () {
  4035. /** @hidden */
  4036. function ExtrasAsMetadata(loader) {
  4037. /**
  4038. * The name of this extension.
  4039. */
  4040. this.name = NAME;
  4041. /**
  4042. * Defines whether this extension is enabled.
  4043. */
  4044. this.enabled = true;
  4045. this._loader = loader;
  4046. }
  4047. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  4048. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  4049. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  4050. var gltf = (metadata.gltf = metadata.gltf || {});
  4051. gltf.extras = gltfProp.extras;
  4052. }
  4053. };
  4054. /** @hidden */
  4055. ExtrasAsMetadata.prototype.dispose = function () {
  4056. delete this._loader;
  4057. };
  4058. /** @hidden */
  4059. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  4060. var _this = this;
  4061. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  4062. _this._assignExtras(babylonTransformNode, node);
  4063. assign(babylonTransformNode);
  4064. });
  4065. };
  4066. /** @hidden */
  4067. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  4068. var _this = this;
  4069. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  4070. _this._assignExtras(babylonCamera, camera);
  4071. assign(babylonCamera);
  4072. });
  4073. };
  4074. /** @hidden */
  4075. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  4076. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  4077. this._assignExtras(babylonMaterial, material);
  4078. return babylonMaterial;
  4079. };
  4080. return ExtrasAsMetadata;
  4081. }());
  4082. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  4083. /***/ }),
  4084. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  4085. /*!***********************************************************!*\
  4086. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  4087. \***********************************************************/
  4088. /*! exports provided: KHR_draco_mesh_compression */
  4089. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4090. "use strict";
  4091. __webpack_require__.r(__webpack_exports__);
  4092. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  4093. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  4094. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  4095. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4096. var NAME = "KHR_draco_mesh_compression";
  4097. /**
  4098. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  4099. */
  4100. var KHR_draco_mesh_compression = /** @class */ (function () {
  4101. /** @hidden */
  4102. function KHR_draco_mesh_compression(loader) {
  4103. /**
  4104. * The name of this extension.
  4105. */
  4106. this.name = NAME;
  4107. this._loader = loader;
  4108. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  4109. }
  4110. /** @hidden */
  4111. KHR_draco_mesh_compression.prototype.dispose = function () {
  4112. delete this.dracoCompression;
  4113. delete this._loader;
  4114. };
  4115. /** @hidden */
  4116. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  4117. var _this = this;
  4118. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  4119. if (primitive.mode != undefined) {
  4120. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  4121. primitive.mode !== 4 /* TRIANGLES */) {
  4122. throw new Error(context + ": Unsupported mode " + primitive.mode);
  4123. }
  4124. // TODO: handle triangle strips
  4125. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  4126. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  4127. }
  4128. }
  4129. var attributes = {};
  4130. var loadAttribute = function (name, kind) {
  4131. var uniqueId = extension.attributes[name];
  4132. if (uniqueId == undefined) {
  4133. return;
  4134. }
  4135. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  4136. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  4137. babylonMesh._delayInfo.push(kind);
  4138. }
  4139. attributes[kind] = uniqueId;
  4140. };
  4141. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  4142. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  4143. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  4144. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  4145. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  4146. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  4147. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  4148. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  4149. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  4150. if (!bufferView._dracoBabylonGeometry) {
  4151. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  4152. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  4153. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  4154. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  4155. babylonVertexData.applyToGeometry(babylonGeometry);
  4156. return babylonGeometry;
  4157. }).catch(function (error) {
  4158. throw new Error(context + ": " + error.message);
  4159. });
  4160. });
  4161. }
  4162. return bufferView._dracoBabylonGeometry;
  4163. });
  4164. };
  4165. return KHR_draco_mesh_compression;
  4166. }());
  4167. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  4168. /***/ }),
  4169. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  4170. /*!****************************************************!*\
  4171. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  4172. \****************************************************/
  4173. /*! exports provided: KHR_lights */
  4174. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4175. "use strict";
  4176. __webpack_require__.r(__webpack_exports__);
  4177. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  4178. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4179. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4180. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4181. var NAME = "KHR_lights_punctual";
  4182. var LightType;
  4183. (function (LightType) {
  4184. LightType["DIRECTIONAL"] = "directional";
  4185. LightType["POINT"] = "point";
  4186. LightType["SPOT"] = "spot";
  4187. })(LightType || (LightType = {}));
  4188. /**
  4189. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  4190. */
  4191. var KHR_lights = /** @class */ (function () {
  4192. /** @hidden */
  4193. function KHR_lights(loader) {
  4194. /**
  4195. * The name of this extension.
  4196. */
  4197. this.name = NAME;
  4198. this._loader = loader;
  4199. this.enabled = this._loader.isExtensionUsed(NAME);
  4200. }
  4201. /** @hidden */
  4202. KHR_lights.prototype.dispose = function () {
  4203. delete this._loader;
  4204. delete this._lights;
  4205. };
  4206. /** @hidden */
  4207. KHR_lights.prototype.onLoading = function () {
  4208. var extensions = this._loader.gltf.extensions;
  4209. if (extensions && extensions[this.name]) {
  4210. var extension = extensions[this.name];
  4211. this._lights = extension.lights;
  4212. }
  4213. };
  4214. /** @hidden */
  4215. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  4216. var _this = this;
  4217. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4218. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  4219. var babylonLight;
  4220. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  4221. var name = light.name || babylonMesh.name;
  4222. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  4223. switch (light.type) {
  4224. case LightType.DIRECTIONAL: {
  4225. 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);
  4226. break;
  4227. }
  4228. case LightType.POINT: {
  4229. 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);
  4230. break;
  4231. }
  4232. case LightType.SPOT: {
  4233. 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);
  4234. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  4235. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  4236. babylonLight = babylonSpotLight;
  4237. break;
  4238. }
  4239. default: {
  4240. _this._loader.babylonScene._blockEntityCollection = false;
  4241. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  4242. }
  4243. }
  4244. _this._loader.babylonScene._blockEntityCollection = false;
  4245. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  4246. 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();
  4247. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  4248. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  4249. babylonLight.parent = babylonMesh;
  4250. _this._loader._babylonLights.push(babylonLight);
  4251. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  4252. assign(babylonMesh);
  4253. });
  4254. });
  4255. };
  4256. return KHR_lights;
  4257. }());
  4258. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  4259. /***/ }),
  4260. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  4261. /*!********************************************************!*\
  4262. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  4263. \********************************************************/
  4264. /*! exports provided: KHR_materials_clearcoat */
  4265. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4266. "use strict";
  4267. __webpack_require__.r(__webpack_exports__);
  4268. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  4269. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4270. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4271. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4272. var NAME = "KHR_materials_clearcoat";
  4273. /**
  4274. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4275. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  4276. * !!! Experimental Extension Subject to Changes !!!
  4277. */
  4278. var KHR_materials_clearcoat = /** @class */ (function () {
  4279. /** @hidden */
  4280. function KHR_materials_clearcoat(loader) {
  4281. /**
  4282. * The name of this extension.
  4283. */
  4284. this.name = NAME;
  4285. /**
  4286. * Defines a number that determines the order the extensions are applied.
  4287. */
  4288. this.order = 190;
  4289. this._loader = loader;
  4290. this.enabled = this._loader.isExtensionUsed(NAME);
  4291. }
  4292. /** @hidden */
  4293. KHR_materials_clearcoat.prototype.dispose = function () {
  4294. delete this._loader;
  4295. };
  4296. /** @hidden */
  4297. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4298. var _this = this;
  4299. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4300. var promises = new Array();
  4301. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4302. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  4303. return Promise.all(promises).then(function () { });
  4304. });
  4305. };
  4306. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  4307. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4308. throw new Error(context + ": Material type not supported");
  4309. }
  4310. var promises = new Array();
  4311. babylonMaterial.clearCoat.isEnabled = true;
  4312. if (properties.clearcoatFactor != undefined) {
  4313. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  4314. }
  4315. else {
  4316. babylonMaterial.clearCoat.intensity = 0;
  4317. }
  4318. if (properties.clearcoatTexture) {
  4319. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  4320. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  4321. babylonMaterial.clearCoat.texture = texture;
  4322. }));
  4323. }
  4324. if (properties.clearcoatRoughnessFactor != undefined) {
  4325. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  4326. }
  4327. else {
  4328. babylonMaterial.clearCoat.roughness = 0;
  4329. }
  4330. if (properties.clearcoatRoughnessTexture) {
  4331. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  4332. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  4333. babylonMaterial.clearCoat.texture = texture;
  4334. }));
  4335. }
  4336. if (properties.clearcoatNormalTexture) {
  4337. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  4338. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  4339. babylonMaterial.clearCoat.bumpTexture = texture;
  4340. }));
  4341. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  4342. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  4343. if (properties.clearcoatNormalTexture.scale != undefined) {
  4344. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  4345. }
  4346. }
  4347. return Promise.all(promises).then(function () { });
  4348. };
  4349. return KHR_materials_clearcoat;
  4350. }());
  4351. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  4352. /***/ }),
  4353. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  4354. /*!********************************************************************!*\
  4355. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  4356. \********************************************************************/
  4357. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  4358. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4359. "use strict";
  4360. __webpack_require__.r(__webpack_exports__);
  4361. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  4362. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4363. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4364. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4365. var NAME = "KHR_materials_pbrSpecularGlossiness";
  4366. /**
  4367. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  4368. */
  4369. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  4370. /** @hidden */
  4371. function KHR_materials_pbrSpecularGlossiness(loader) {
  4372. /**
  4373. * The name of this extension.
  4374. */
  4375. this.name = NAME;
  4376. /**
  4377. * Defines a number that determines the order the extensions are applied.
  4378. */
  4379. this.order = 200;
  4380. this._loader = loader;
  4381. this.enabled = this._loader.isExtensionUsed(NAME);
  4382. }
  4383. /** @hidden */
  4384. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  4385. delete this._loader;
  4386. };
  4387. /** @hidden */
  4388. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4389. var _this = this;
  4390. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4391. var promises = new Array();
  4392. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  4393. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  4394. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4395. return Promise.all(promises).then(function () { });
  4396. });
  4397. };
  4398. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  4399. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4400. throw new Error(context + ": Material type not supported");
  4401. }
  4402. var promises = new Array();
  4403. babylonMaterial.metallic = null;
  4404. babylonMaterial.roughness = null;
  4405. if (properties.diffuseFactor) {
  4406. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  4407. babylonMaterial.alpha = properties.diffuseFactor[3];
  4408. }
  4409. else {
  4410. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4411. }
  4412. 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();
  4413. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  4414. if (properties.diffuseTexture) {
  4415. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  4416. texture.name = babylonMaterial.name + " (Diffuse)";
  4417. babylonMaterial.albedoTexture = texture;
  4418. }));
  4419. }
  4420. if (properties.specularGlossinessTexture) {
  4421. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  4422. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  4423. babylonMaterial.reflectivityTexture = texture;
  4424. }));
  4425. babylonMaterial.reflectivityTexture.hasAlpha = true;
  4426. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  4427. }
  4428. return Promise.all(promises).then(function () { });
  4429. };
  4430. return KHR_materials_pbrSpecularGlossiness;
  4431. }());
  4432. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  4433. /***/ }),
  4434. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  4435. /*!****************************************************!*\
  4436. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  4437. \****************************************************/
  4438. /*! exports provided: KHR_materials_sheen */
  4439. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4440. "use strict";
  4441. __webpack_require__.r(__webpack_exports__);
  4442. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  4443. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4444. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4445. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4446. var NAME = "KHR_materials_sheen";
  4447. /**
  4448. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  4449. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4450. * !!! Experimental Extension Subject to Changes !!!
  4451. */
  4452. var KHR_materials_sheen = /** @class */ (function () {
  4453. /** @hidden */
  4454. function KHR_materials_sheen(loader) {
  4455. /**
  4456. * The name of this extension.
  4457. */
  4458. this.name = NAME;
  4459. /**
  4460. * Defines a number that determines the order the extensions are applied.
  4461. */
  4462. this.order = 190;
  4463. this._loader = loader;
  4464. this.enabled = this._loader.isExtensionUsed(NAME);
  4465. }
  4466. /** @hidden */
  4467. KHR_materials_sheen.prototype.dispose = function () {
  4468. delete this._loader;
  4469. };
  4470. /** @hidden */
  4471. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4472. var _this = this;
  4473. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4474. var promises = new Array();
  4475. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4476. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  4477. return Promise.all(promises).then(function () { });
  4478. });
  4479. };
  4480. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  4481. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4482. throw new Error(context + ": Material type not supported");
  4483. }
  4484. var promises = new Array();
  4485. babylonMaterial.sheen.isEnabled = true;
  4486. if (properties.intensityFactor != undefined) {
  4487. babylonMaterial.sheen.intensity = properties.intensityFactor;
  4488. }
  4489. else {
  4490. babylonMaterial.sheen.intensity = 0;
  4491. }
  4492. if (properties.colorFactor != undefined) {
  4493. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.colorFactor);
  4494. }
  4495. if (properties.colorIntensityTexture) {
  4496. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.colorIntensityTexture, function (texture) {
  4497. texture.name = babylonMaterial.name + " (Sheen Intensity)";
  4498. babylonMaterial.sheen.texture = texture;
  4499. }));
  4500. }
  4501. if (properties.roughnessFactor !== undefined) {
  4502. babylonMaterial.sheen.roughness = properties.roughnessFactor;
  4503. }
  4504. else {
  4505. babylonMaterial.sheen.roughness = 0;
  4506. }
  4507. babylonMaterial.sheen.albedoScaling = true;
  4508. return Promise.all(promises).then(function () { });
  4509. };
  4510. return KHR_materials_sheen;
  4511. }());
  4512. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  4513. /***/ }),
  4514. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  4515. /*!*******************************************************!*\
  4516. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  4517. \*******************************************************/
  4518. /*! exports provided: KHR_materials_specular */
  4519. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4520. "use strict";
  4521. __webpack_require__.r(__webpack_exports__);
  4522. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  4523. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  4524. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  4525. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4526. var NAME = "KHR_materials_specular";
  4527. /**
  4528. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  4529. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  4530. * !!! Experimental Extension Subject to Changes !!!
  4531. */
  4532. var KHR_materials_specular = /** @class */ (function () {
  4533. /** @hidden */
  4534. function KHR_materials_specular(loader) {
  4535. /**
  4536. * The name of this extension.
  4537. */
  4538. this.name = NAME;
  4539. /**
  4540. * Defines a number that determines the order the extensions are applied.
  4541. */
  4542. this.order = 190;
  4543. this._loader = loader;
  4544. this.enabled = this._loader.isExtensionUsed(NAME);
  4545. }
  4546. /** @hidden */
  4547. KHR_materials_specular.prototype.dispose = function () {
  4548. delete this._loader;
  4549. };
  4550. /** @hidden */
  4551. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4552. var _this = this;
  4553. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  4554. var promises = new Array();
  4555. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  4556. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  4557. return Promise.all(promises).then(function () { });
  4558. });
  4559. };
  4560. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  4561. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4562. throw new Error(context + ": Material type not supported");
  4563. }
  4564. if (properties.specularFactor !== undefined) {
  4565. babylonMaterial.metallicF0Factor = properties.specularFactor;
  4566. }
  4567. if (properties.specularTexture) {
  4568. // This does not allow a separate sampler for it at the moment but is currently under discussion.
  4569. babylonMaterial.useMetallicF0FactorFromMetallicTexture = true;
  4570. }
  4571. return Promise.resolve();
  4572. };
  4573. return KHR_materials_specular;
  4574. }());
  4575. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  4576. /***/ }),
  4577. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  4578. /*!****************************************************!*\
  4579. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  4580. \****************************************************/
  4581. /*! exports provided: KHR_materials_unlit */
  4582. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4583. "use strict";
  4584. __webpack_require__.r(__webpack_exports__);
  4585. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  4586. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  4587. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  4588. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4589. var NAME = "KHR_materials_unlit";
  4590. /**
  4591. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  4592. */
  4593. var KHR_materials_unlit = /** @class */ (function () {
  4594. /** @hidden */
  4595. function KHR_materials_unlit(loader) {
  4596. /**
  4597. * The name of this extension.
  4598. */
  4599. this.name = NAME;
  4600. /**
  4601. * Defines a number that determines the order the extensions are applied.
  4602. */
  4603. this.order = 210;
  4604. this._loader = loader;
  4605. this.enabled = this._loader.isExtensionUsed(NAME);
  4606. }
  4607. /** @hidden */
  4608. KHR_materials_unlit.prototype.dispose = function () {
  4609. delete this._loader;
  4610. };
  4611. /** @hidden */
  4612. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4613. var _this = this;
  4614. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  4615. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  4616. });
  4617. };
  4618. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  4619. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  4620. throw new Error(context + ": Material type not supported");
  4621. }
  4622. var promises = new Array();
  4623. babylonMaterial.unlit = true;
  4624. var properties = material.pbrMetallicRoughness;
  4625. if (properties) {
  4626. if (properties.baseColorFactor) {
  4627. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  4628. babylonMaterial.alpha = properties.baseColorFactor[3];
  4629. }
  4630. else {
  4631. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  4632. }
  4633. if (properties.baseColorTexture) {
  4634. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  4635. texture.name = babylonMaterial.name + " (Base Color)";
  4636. babylonMaterial.albedoTexture = texture;
  4637. }));
  4638. }
  4639. }
  4640. if (material.doubleSided) {
  4641. babylonMaterial.backFaceCulling = false;
  4642. babylonMaterial.twoSidedLighting = true;
  4643. }
  4644. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  4645. return Promise.all(promises).then(function () { });
  4646. };
  4647. return KHR_materials_unlit;
  4648. }());
  4649. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  4650. /***/ }),
  4651. /***/ "./glTF/2.0/Extensions/KHR_mesh_instancing.ts":
  4652. /*!****************************************************!*\
  4653. !*** ./glTF/2.0/Extensions/KHR_mesh_instancing.ts ***!
  4654. \****************************************************/
  4655. /*! exports provided: KHR_mesh_instancing */
  4656. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4657. "use strict";
  4658. __webpack_require__.r(__webpack_exports__);
  4659. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_instancing", function() { return KHR_mesh_instancing; });
  4660. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4661. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4662. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4663. var NAME = "KHR_mesh_instancing";
  4664. /**
  4665. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  4666. * [Playground Sample](//TODO)
  4667. * !!! Experimental Extension Subject to Changes !!!
  4668. */
  4669. var KHR_mesh_instancing = /** @class */ (function () {
  4670. /** @hidden */
  4671. function KHR_mesh_instancing(loader) {
  4672. /**
  4673. * The name of this extension.
  4674. */
  4675. this.name = NAME;
  4676. this._loader = loader;
  4677. this.enabled = this._loader.isExtensionUsed(NAME);
  4678. }
  4679. /** @hidden */
  4680. KHR_mesh_instancing.prototype.dispose = function () {
  4681. delete this._loader;
  4682. };
  4683. /** @hidden */
  4684. KHR_mesh_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  4685. var _this = this;
  4686. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4687. return _this._loader.loadNodeAsync("#/nodes/" + node.index, node, function (babylonTransformNode) {
  4688. var promises = new Array();
  4689. var instanceCount = null;
  4690. var loadAttribute = function (attribute, assignBufferFunc) {
  4691. if (extension.attributes[attribute] == undefined) {
  4692. return;
  4693. }
  4694. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  4695. if (instanceCount === null) {
  4696. instanceCount = accessor.count;
  4697. }
  4698. else if (instanceCount !== accessor.count) {
  4699. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  4700. }
  4701. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor).then(function (data) {
  4702. assignBufferFunc(data);
  4703. }));
  4704. };
  4705. var translationBuffer = null;
  4706. var rotationBuffer = null;
  4707. var scaleBuffer = null;
  4708. loadAttribute("TRANSLATION", function (data) { translationBuffer = data; });
  4709. loadAttribute("ROTATION", function (data) { rotationBuffer = data; });
  4710. loadAttribute("SCALE", function (data) { scaleBuffer = data; });
  4711. return Promise.all(promises).then(function () {
  4712. if (instanceCount) {
  4713. var instanceName = "";
  4714. var instance = null;
  4715. var digitLength = instanceCount.toString().length;
  4716. for (var i = 0; i < instanceCount; ++i) {
  4717. if (node._primitiveBabylonMeshes) {
  4718. for (var j = 0; j < node._primitiveBabylonMeshes.length; ++j) {
  4719. var babylonMeshPrimitive = node._primitiveBabylonMeshes[j];
  4720. instanceName = (babylonMeshPrimitive.name || babylonMeshPrimitive.id) + "_" + babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["StringTools"].PadNumber(i, digitLength);
  4721. if (babylonMeshPrimitive.isAnInstance) {
  4722. instance = babylonMeshPrimitive.sourceMesh.createInstance(instanceName);
  4723. }
  4724. else if (babylonMeshPrimitive.createInstance) {
  4725. instance = babylonMeshPrimitive.createInstance(instanceName);
  4726. }
  4727. if (instance) {
  4728. instance.setParent(babylonMeshPrimitive);
  4729. translationBuffer ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(translationBuffer, i * 3, instance.position)
  4730. : instance.position.set(0, 0, 0);
  4731. rotationBuffer ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArrayToRef(rotationBuffer, i * 4, instance.rotationQuaternion)
  4732. : instance.rotationQuaternion.set(0, 0, 0, 1);
  4733. scaleBuffer ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(scaleBuffer, i * 3, instance.scaling)
  4734. : instance.scaling.set(1, 1, 1);
  4735. }
  4736. }
  4737. }
  4738. }
  4739. }
  4740. assign(babylonTransformNode);
  4741. return babylonTransformNode;
  4742. });
  4743. });
  4744. });
  4745. };
  4746. return KHR_mesh_instancing;
  4747. }());
  4748. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_instancing(loader); });
  4749. /***/ }),
  4750. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  4751. /*!******************************************************!*\
  4752. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  4753. \******************************************************/
  4754. /*! exports provided: KHR_mesh_quantization */
  4755. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4756. "use strict";
  4757. __webpack_require__.r(__webpack_exports__);
  4758. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  4759. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4760. var NAME = "KHR_mesh_quantization";
  4761. /**
  4762. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  4763. */
  4764. var KHR_mesh_quantization = /** @class */ (function () {
  4765. /** @hidden */
  4766. function KHR_mesh_quantization(loader) {
  4767. /**
  4768. * The name of this extension.
  4769. */
  4770. this.name = NAME;
  4771. this.enabled = loader.isExtensionUsed(NAME);
  4772. }
  4773. /** @hidden */
  4774. KHR_mesh_quantization.prototype.dispose = function () {
  4775. };
  4776. return KHR_mesh_quantization;
  4777. }());
  4778. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  4779. /***/ }),
  4780. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  4781. /*!***************************************************!*\
  4782. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  4783. \***************************************************/
  4784. /*! exports provided: KHR_texture_basisu */
  4785. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4786. "use strict";
  4787. __webpack_require__.r(__webpack_exports__);
  4788. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  4789. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4790. var NAME = "KHR_texture_basisu";
  4791. /**
  4792. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  4793. * !!! Experimental Extension Subject to Changes !!!
  4794. */
  4795. var KHR_texture_basisu = /** @class */ (function () {
  4796. /** @hidden */
  4797. function KHR_texture_basisu(loader) {
  4798. /** The name of this extension. */
  4799. this.name = NAME;
  4800. this._loader = loader;
  4801. this.enabled = loader.isExtensionUsed(NAME);
  4802. }
  4803. /** @hidden */
  4804. KHR_texture_basisu.prototype.dispose = function () {
  4805. delete this._loader;
  4806. };
  4807. /** @hidden */
  4808. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  4809. var _this = this;
  4810. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  4811. 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));
  4812. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  4813. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  4814. babylonTexture.gammaSpace = false;
  4815. assign(babylonTexture);
  4816. });
  4817. });
  4818. };
  4819. return KHR_texture_basisu;
  4820. }());
  4821. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  4822. /***/ }),
  4823. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  4824. /*!******************************************************!*\
  4825. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  4826. \******************************************************/
  4827. /*! exports provided: KHR_texture_transform */
  4828. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4829. "use strict";
  4830. __webpack_require__.r(__webpack_exports__);
  4831. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  4832. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  4833. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  4834. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4835. var NAME = "KHR_texture_transform";
  4836. /**
  4837. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  4838. */
  4839. var KHR_texture_transform = /** @class */ (function () {
  4840. /** @hidden */
  4841. function KHR_texture_transform(loader) {
  4842. /**
  4843. * The name of this extension.
  4844. */
  4845. this.name = NAME;
  4846. this._loader = loader;
  4847. this.enabled = this._loader.isExtensionUsed(NAME);
  4848. }
  4849. /** @hidden */
  4850. KHR_texture_transform.prototype.dispose = function () {
  4851. delete this._loader;
  4852. };
  4853. /** @hidden */
  4854. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  4855. var _this = this;
  4856. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  4857. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  4858. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  4859. throw new Error(extensionContext + ": Texture type not supported");
  4860. }
  4861. if (extension.offset) {
  4862. babylonTexture.uOffset = extension.offset[0];
  4863. babylonTexture.vOffset = extension.offset[1];
  4864. }
  4865. // Always rotate around the origin.
  4866. babylonTexture.uRotationCenter = 0;
  4867. babylonTexture.vRotationCenter = 0;
  4868. if (extension.rotation) {
  4869. babylonTexture.wAng = -extension.rotation;
  4870. }
  4871. if (extension.scale) {
  4872. babylonTexture.uScale = extension.scale[0];
  4873. babylonTexture.vScale = extension.scale[1];
  4874. }
  4875. if (extension.texCoord != undefined) {
  4876. babylonTexture.coordinatesIndex = extension.texCoord;
  4877. }
  4878. assign(babylonTexture);
  4879. });
  4880. });
  4881. };
  4882. return KHR_texture_transform;
  4883. }());
  4884. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  4885. /***/ }),
  4886. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  4887. /*!***************************************************!*\
  4888. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  4889. \***************************************************/
  4890. /*! exports provided: MSFT_audio_emitter */
  4891. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4892. "use strict";
  4893. __webpack_require__.r(__webpack_exports__);
  4894. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  4895. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  4896. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4897. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4898. var NAME = "MSFT_audio_emitter";
  4899. /**
  4900. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  4901. */
  4902. var MSFT_audio_emitter = /** @class */ (function () {
  4903. /** @hidden */
  4904. function MSFT_audio_emitter(loader) {
  4905. /**
  4906. * The name of this extension.
  4907. */
  4908. this.name = NAME;
  4909. this._loader = loader;
  4910. this.enabled = this._loader.isExtensionUsed(NAME);
  4911. }
  4912. /** @hidden */
  4913. MSFT_audio_emitter.prototype.dispose = function () {
  4914. delete this._loader;
  4915. delete this._clips;
  4916. delete this._emitters;
  4917. };
  4918. /** @hidden */
  4919. MSFT_audio_emitter.prototype.onLoading = function () {
  4920. var extensions = this._loader.gltf.extensions;
  4921. if (extensions && extensions[this.name]) {
  4922. var extension = extensions[this.name];
  4923. this._clips = extension.clips;
  4924. this._emitters = extension.emitters;
  4925. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  4926. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  4927. }
  4928. };
  4929. /** @hidden */
  4930. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  4931. var _this = this;
  4932. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  4933. var promises = new Array();
  4934. promises.push(_this._loader.loadSceneAsync(context, scene));
  4935. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4936. var emitterIndex = _a[_i];
  4937. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4938. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  4939. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4940. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  4941. }
  4942. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  4943. }
  4944. return Promise.all(promises).then(function () { });
  4945. });
  4946. };
  4947. /** @hidden */
  4948. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  4949. var _this = this;
  4950. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  4951. var promises = new Array();
  4952. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  4953. var _loop_1 = function (emitterIndex) {
  4954. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  4955. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  4956. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  4957. var sound = _a[_i];
  4958. sound.attachToMesh(babylonMesh);
  4959. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  4960. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  4961. 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);
  4962. }
  4963. }
  4964. }));
  4965. };
  4966. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  4967. var emitterIndex = _a[_i];
  4968. _loop_1(emitterIndex);
  4969. }
  4970. assign(babylonMesh);
  4971. }).then(function (babylonMesh) {
  4972. return Promise.all(promises).then(function () {
  4973. return babylonMesh;
  4974. });
  4975. });
  4976. });
  4977. };
  4978. /** @hidden */
  4979. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  4980. var _this = this;
  4981. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  4982. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  4983. var promises = new Array();
  4984. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  4985. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  4986. var event_1 = _a[_i];
  4987. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  4988. }
  4989. return Promise.all(promises).then(function () {
  4990. return babylonAnimationGroup;
  4991. });
  4992. });
  4993. });
  4994. };
  4995. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  4996. if (clip._objectURL) {
  4997. return clip._objectURL;
  4998. }
  4999. var promise;
  5000. if (clip.uri) {
  5001. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  5002. }
  5003. else {
  5004. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  5005. promise = this._loader.loadBufferViewAsync("#/bufferViews/" + bufferView.index, bufferView);
  5006. }
  5007. clip._objectURL = promise.then(function (data) {
  5008. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  5009. });
  5010. return clip._objectURL;
  5011. };
  5012. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  5013. var _this = this;
  5014. emitter._babylonSounds = emitter._babylonSounds || [];
  5015. if (!emitter._babylonData) {
  5016. var clipPromises = new Array();
  5017. var name_1 = emitter.name || "emitter" + emitter.index;
  5018. var options_1 = {
  5019. loop: false,
  5020. autoplay: false,
  5021. volume: emitter.volume == undefined ? 1 : emitter.volume,
  5022. };
  5023. var _loop_2 = function (i) {
  5024. var clipContext = "#/extensions/" + this_1.name + "/clips";
  5025. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  5026. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  5027. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  5028. sound.refDistance = emitter.refDistance || 1;
  5029. sound.maxDistance = emitter.maxDistance || 256;
  5030. sound.rolloffFactor = emitter.rolloffFactor || 1;
  5031. sound.distanceModel = emitter.distanceModel || 'exponential';
  5032. sound._positionInEmitterSpace = true;
  5033. }));
  5034. };
  5035. var this_1 = this;
  5036. for (var i = 0; i < emitter.clips.length; i++) {
  5037. _loop_2(i);
  5038. }
  5039. var promise = Promise.all(clipPromises).then(function () {
  5040. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  5041. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  5042. if (emitter.innerAngle) {
  5043. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  5044. }
  5045. if (emitter.outerAngle) {
  5046. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  5047. }
  5048. if (emitter.volume) {
  5049. weightedSound.volume = emitter.volume;
  5050. }
  5051. emitter._babylonData.sound = weightedSound;
  5052. });
  5053. emitter._babylonData = {
  5054. loaded: promise
  5055. };
  5056. }
  5057. return emitter._babylonData.loaded;
  5058. };
  5059. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  5060. switch (action) {
  5061. case "play" /* play */: {
  5062. return function (currentFrame) {
  5063. var frameOffset = (startOffset || 0) + (currentFrame - time);
  5064. sound.play(frameOffset);
  5065. };
  5066. }
  5067. case "stop" /* stop */: {
  5068. return function (currentFrame) {
  5069. sound.stop();
  5070. };
  5071. }
  5072. case "pause" /* pause */: {
  5073. return function (currentFrame) {
  5074. sound.pause();
  5075. };
  5076. }
  5077. default: {
  5078. throw new Error(context + ": Unsupported action " + action);
  5079. }
  5080. }
  5081. };
  5082. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  5083. var _this = this;
  5084. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  5085. return Promise.resolve();
  5086. }
  5087. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  5088. var emitterIndex = event.emitter;
  5089. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("#/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  5090. return this._loadEmitterAsync(context, emitter).then(function () {
  5091. var sound = emitter._babylonData.sound;
  5092. if (sound) {
  5093. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  5094. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  5095. // Make sure all started audio stops when this animation is terminated.
  5096. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  5097. sound.stop();
  5098. });
  5099. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  5100. sound.pause();
  5101. });
  5102. }
  5103. });
  5104. };
  5105. return MSFT_audio_emitter;
  5106. }());
  5107. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  5108. /***/ }),
  5109. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  5110. /*!*****************************************!*\
  5111. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  5112. \*****************************************/
  5113. /*! exports provided: MSFT_lod */
  5114. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5115. "use strict";
  5116. __webpack_require__.r(__webpack_exports__);
  5117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  5118. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  5119. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  5120. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5121. var NAME = "MSFT_lod";
  5122. /**
  5123. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  5124. */
  5125. var MSFT_lod = /** @class */ (function () {
  5126. /** @hidden */
  5127. function MSFT_lod(loader) {
  5128. /**
  5129. * The name of this extension.
  5130. */
  5131. this.name = NAME;
  5132. /**
  5133. * Defines a number that determines the order the extensions are applied.
  5134. */
  5135. this.order = 100;
  5136. /**
  5137. * Maximum number of LODs to load, starting from the lowest LOD.
  5138. */
  5139. this.maxLODsToLoad = 10;
  5140. /**
  5141. * Observable raised when all node LODs of one level are loaded.
  5142. * The event data is the index of the loaded LOD starting from zero.
  5143. * Dispose the loader to cancel the loading of the next level of LODs.
  5144. */
  5145. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5146. /**
  5147. * Observable raised when all material LODs of one level are loaded.
  5148. * The event data is the index of the loaded LOD starting from zero.
  5149. * Dispose the loader to cancel the loading of the next level of LODs.
  5150. */
  5151. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  5152. this._nodeIndexLOD = null;
  5153. this._nodeSignalLODs = new Array();
  5154. this._nodePromiseLODs = new Array();
  5155. this._materialIndexLOD = null;
  5156. this._materialSignalLODs = new Array();
  5157. this._materialPromiseLODs = new Array();
  5158. this._indexLOD = null;
  5159. this._bufferLODs = new Array();
  5160. this._loader = loader;
  5161. this.enabled = this._loader.isExtensionUsed(NAME);
  5162. }
  5163. /** @hidden */
  5164. MSFT_lod.prototype.dispose = function () {
  5165. delete this._loader;
  5166. this._nodeIndexLOD = null;
  5167. this._nodeSignalLODs.length = 0;
  5168. this._nodePromiseLODs.length = 0;
  5169. this._materialIndexLOD = null;
  5170. this._materialSignalLODs.length = 0;
  5171. this._materialPromiseLODs.length = 0;
  5172. this._indexLOD = null;
  5173. this._bufferLODs.length = 0;
  5174. this.onMaterialLODsLoadedObservable.clear();
  5175. this.onNodeLODsLoadedObservable.clear();
  5176. };
  5177. /** @hidden */
  5178. MSFT_lod.prototype.onReady = function () {
  5179. var _this = this;
  5180. var _loop_1 = function (indexLOD) {
  5181. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  5182. if (indexLOD !== 0) {
  5183. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  5184. }
  5185. _this._loader.log("Loaded node LOD " + indexLOD);
  5186. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  5187. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  5188. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  5189. if (_this._nodeSignalLODs[indexLOD]) {
  5190. _this._nodeSignalLODs[indexLOD].resolve();
  5191. }
  5192. }
  5193. });
  5194. this_1._loader._completePromises.push(promise);
  5195. };
  5196. var this_1 = this;
  5197. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  5198. _loop_1(indexLOD);
  5199. }
  5200. var _loop_2 = function (indexLOD) {
  5201. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  5202. if (indexLOD !== 0) {
  5203. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  5204. }
  5205. _this._loader.log("Loaded material LOD " + indexLOD);
  5206. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  5207. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  5208. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  5209. if (_this._materialSignalLODs[indexLOD]) {
  5210. _this._materialSignalLODs[indexLOD].resolve();
  5211. }
  5212. }
  5213. });
  5214. this_2._loader._completePromises.push(promise);
  5215. };
  5216. var this_2 = this;
  5217. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  5218. _loop_2(indexLOD);
  5219. }
  5220. for (var indexLOD = 1; indexLOD < this._bufferLODs.length; indexLOD++) {
  5221. this._loadBufferLOD(indexLOD);
  5222. }
  5223. };
  5224. /** @hidden */
  5225. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  5226. var promise = this._loader.loadSceneAsync(context, scene);
  5227. if (this._bufferLODs.length !== 0) {
  5228. this._loadBufferLOD(0);
  5229. }
  5230. return promise;
  5231. };
  5232. /** @hidden */
  5233. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  5234. var _this = this;
  5235. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  5236. var firstPromise;
  5237. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  5238. _this._loader.logOpen("" + extensionContext);
  5239. var _loop_3 = function (indexLOD) {
  5240. var nodeLOD = nodeLODs[indexLOD];
  5241. _this._indexLOD = indexLOD;
  5242. if (indexLOD !== 0) {
  5243. _this._nodeIndexLOD = indexLOD;
  5244. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5245. }
  5246. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  5247. var promise = _this._loader.loadNodeAsync("#/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  5248. if (indexLOD !== 0) {
  5249. // TODO: should not rely on _babylonTransformNode
  5250. var previousNodeLOD = nodeLODs[indexLOD - 1];
  5251. if (previousNodeLOD._babylonTransformNode) {
  5252. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  5253. delete previousNodeLOD._babylonTransformNode;
  5254. }
  5255. }
  5256. babylonMesh.setEnabled(true);
  5257. return babylonMesh;
  5258. });
  5259. if (indexLOD === 0) {
  5260. firstPromise = promise;
  5261. }
  5262. else {
  5263. _this._nodeIndexLOD = null;
  5264. }
  5265. _this._indexLOD = null;
  5266. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  5267. _this._nodePromiseLODs[indexLOD].push(promise);
  5268. };
  5269. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  5270. _loop_3(indexLOD);
  5271. }
  5272. _this._loader.logClose();
  5273. return firstPromise;
  5274. });
  5275. };
  5276. /** @hidden */
  5277. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  5278. var _this = this;
  5279. // Don't load material LODs if already loading a node LOD.
  5280. if (this._indexLOD) {
  5281. return null;
  5282. }
  5283. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  5284. var firstPromise;
  5285. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  5286. _this._loader.logOpen("" + extensionContext);
  5287. var _loop_4 = function (indexLOD) {
  5288. var materialLOD = materialLODs[indexLOD];
  5289. _this._indexLOD = indexLOD;
  5290. if (indexLOD !== 0) {
  5291. _this._materialIndexLOD = indexLOD;
  5292. }
  5293. var promise = _this._loader._loadMaterialAsync("#/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  5294. if (indexLOD === 0) {
  5295. assign(babylonMaterial);
  5296. }
  5297. }).then(function (babylonMaterial) {
  5298. if (indexLOD !== 0) {
  5299. assign(babylonMaterial);
  5300. // TODO: should not rely on _data
  5301. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  5302. if (previousDataLOD[babylonDrawMode]) {
  5303. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  5304. delete previousDataLOD[babylonDrawMode];
  5305. }
  5306. }
  5307. return babylonMaterial;
  5308. });
  5309. if (indexLOD === 0) {
  5310. firstPromise = promise;
  5311. }
  5312. else {
  5313. _this._materialIndexLOD = null;
  5314. }
  5315. _this._indexLOD = null;
  5316. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  5317. _this._materialPromiseLODs[indexLOD].push(promise);
  5318. };
  5319. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  5320. _loop_4(indexLOD);
  5321. }
  5322. _this._loader.logClose();
  5323. return firstPromise;
  5324. });
  5325. };
  5326. /** @hidden */
  5327. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  5328. var _this = this;
  5329. // Defer the loading of uris if loading a material or node LOD.
  5330. if (this._materialIndexLOD !== null) {
  5331. this._loader.log("deferred");
  5332. var previousIndexLOD = this._materialIndexLOD - 1;
  5333. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5334. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  5335. return _this._loader.loadUriAsync(context, property, uri);
  5336. });
  5337. }
  5338. else if (this._nodeIndexLOD !== null) {
  5339. this._loader.log("deferred");
  5340. var previousIndexLOD = this._nodeIndexLOD - 1;
  5341. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  5342. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  5343. return _this._loader.loadUriAsync(context, property, uri);
  5344. });
  5345. }
  5346. return null;
  5347. };
  5348. /** @hidden */
  5349. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  5350. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  5351. if (!this._loader.bin) {
  5352. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  5353. }
  5354. // Non-LOD buffers will be bucketed into the first LOD.
  5355. var indexLOD = this._indexLOD || 0;
  5356. var start = byteOffset;
  5357. var end = start + byteLength - 1;
  5358. var bufferLOD_1 = this._bufferLODs[indexLOD];
  5359. if (bufferLOD_1) {
  5360. bufferLOD_1.start = Math.min(bufferLOD_1.start, start);
  5361. bufferLOD_1.end = Math.max(bufferLOD_1.end, end);
  5362. }
  5363. else {
  5364. bufferLOD_1 = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  5365. this._bufferLODs[indexLOD] = bufferLOD_1;
  5366. }
  5367. return bufferLOD_1.loaded.promise.then(function (data) {
  5368. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD_1.start, byteLength);
  5369. });
  5370. }
  5371. return null;
  5372. };
  5373. MSFT_lod.prototype._loadBufferLOD = function (indexLOD) {
  5374. var bufferLOD = this._bufferLODs[indexLOD];
  5375. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  5376. bufferLOD.loaded.resolve(data);
  5377. }, function (error) {
  5378. bufferLOD.loaded.reject(error);
  5379. });
  5380. };
  5381. /**
  5382. * Gets an array of LOD properties from lowest to highest.
  5383. */
  5384. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  5385. if (this.maxLODsToLoad <= 0) {
  5386. throw new Error("maxLODsToLoad must be greater than zero");
  5387. }
  5388. var properties = new Array();
  5389. for (var i = ids.length - 1; i >= 0; i--) {
  5390. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  5391. if (properties.length === this.maxLODsToLoad) {
  5392. return properties;
  5393. }
  5394. }
  5395. properties.push(property);
  5396. return properties;
  5397. };
  5398. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  5399. var _this = this;
  5400. var babylonMaterials = new Array();
  5401. var babylonMaterial = babylonTransformNode.material;
  5402. if (babylonMaterial) {
  5403. babylonMaterials.push(babylonMaterial);
  5404. }
  5405. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  5406. var babylonMesh = _a[_i];
  5407. if (babylonMesh.material) {
  5408. babylonMaterials.push(babylonMesh.material);
  5409. }
  5410. }
  5411. babylonTransformNode.dispose();
  5412. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  5413. this._disposeMaterials(babylonMaterialsToDispose);
  5414. };
  5415. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  5416. var babylonTextures = {};
  5417. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  5418. var babylonMaterial = babylonMaterials_1[_i];
  5419. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  5420. var babylonTexture = _b[_a];
  5421. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  5422. }
  5423. babylonMaterial.dispose();
  5424. }
  5425. for (var uniqueId in babylonTextures) {
  5426. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  5427. var babylonMaterial = _d[_c];
  5428. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  5429. delete babylonTextures[uniqueId];
  5430. }
  5431. }
  5432. }
  5433. for (var uniqueId in babylonTextures) {
  5434. babylonTextures[uniqueId].dispose();
  5435. }
  5436. };
  5437. return MSFT_lod;
  5438. }());
  5439. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  5440. /***/ }),
  5441. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  5442. /*!***************************************************!*\
  5443. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  5444. \***************************************************/
  5445. /*! exports provided: MSFT_minecraftMesh */
  5446. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5447. "use strict";
  5448. __webpack_require__.r(__webpack_exports__);
  5449. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  5450. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5451. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5452. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5453. var NAME = "MSFT_minecraftMesh";
  5454. /** @hidden */
  5455. var MSFT_minecraftMesh = /** @class */ (function () {
  5456. function MSFT_minecraftMesh(loader) {
  5457. this.name = NAME;
  5458. this._loader = loader;
  5459. this.enabled = this._loader.isExtensionUsed(NAME);
  5460. }
  5461. MSFT_minecraftMesh.prototype.dispose = function () {
  5462. delete this._loader;
  5463. };
  5464. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5465. var _this = this;
  5466. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5467. if (extra) {
  5468. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5469. throw new Error(extraContext + ": Material type not supported");
  5470. }
  5471. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5472. if (babylonMaterial.needAlphaBlending()) {
  5473. babylonMaterial.forceDepthWrite = true;
  5474. babylonMaterial.separateCullingPass = true;
  5475. }
  5476. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  5477. babylonMaterial.twoSidedLighting = true;
  5478. return promise;
  5479. }
  5480. return null;
  5481. });
  5482. };
  5483. return MSFT_minecraftMesh;
  5484. }());
  5485. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  5486. /***/ }),
  5487. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  5488. /*!*************************************************!*\
  5489. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  5490. \*************************************************/
  5491. /*! exports provided: MSFT_sRGBFactors */
  5492. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5493. "use strict";
  5494. __webpack_require__.r(__webpack_exports__);
  5495. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  5496. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  5497. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  5498. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  5499. var NAME = "MSFT_sRGBFactors";
  5500. /** @hidden */
  5501. var MSFT_sRGBFactors = /** @class */ (function () {
  5502. function MSFT_sRGBFactors(loader) {
  5503. this.name = NAME;
  5504. this._loader = loader;
  5505. this.enabled = this._loader.isExtensionUsed(NAME);
  5506. }
  5507. MSFT_sRGBFactors.prototype.dispose = function () {
  5508. delete this._loader;
  5509. };
  5510. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  5511. var _this = this;
  5512. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  5513. if (extra) {
  5514. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  5515. throw new Error(extraContext + ": Material type not supported");
  5516. }
  5517. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  5518. if (!babylonMaterial.albedoTexture) {
  5519. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  5520. }
  5521. if (!babylonMaterial.reflectivityTexture) {
  5522. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  5523. }
  5524. return promise;
  5525. }
  5526. return null;
  5527. });
  5528. };
  5529. return MSFT_sRGBFactors;
  5530. }());
  5531. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  5532. /***/ }),
  5533. /***/ "./glTF/2.0/Extensions/index.ts":
  5534. /*!**************************************!*\
  5535. !*** ./glTF/2.0/Extensions/index.ts ***!
  5536. \**************************************/
  5537. /*! exports provided: EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_mesh_instancing, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  5538. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5539. "use strict";
  5540. __webpack_require__.r(__webpack_exports__);
  5541. /* 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");
  5542. /* 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"]; });
  5543. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  5544. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  5545. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  5546. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_2__["KHR_lights"]; });
  5547. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  5548. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  5549. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  5550. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  5551. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  5552. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_clearcoat"]; });
  5553. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  5554. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_sheen"]; });
  5555. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  5556. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_specular"]; });
  5557. /* harmony import */ var _KHR_mesh_instancing__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_mesh_instancing */ "./glTF/2.0/Extensions/KHR_mesh_instancing.ts");
  5558. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_instancing", function() { return _KHR_mesh_instancing__WEBPACK_IMPORTED_MODULE_8__["KHR_mesh_instancing"]; });
  5559. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  5560. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_9__["KHR_mesh_quantization"]; });
  5561. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  5562. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_10__["KHR_texture_basisu"]; });
  5563. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  5564. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_11__["KHR_texture_transform"]; });
  5565. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  5566. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_12__["MSFT_audio_emitter"]; });
  5567. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  5568. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_13__["MSFT_lod"]; });
  5569. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  5570. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_14__["MSFT_minecraftMesh"]; });
  5571. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  5572. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_15__["MSFT_sRGBFactors"]; });
  5573. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  5574. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_16__["ExtrasAsMetadata"]; });
  5575. /***/ }),
  5576. /***/ "./glTF/2.0/glTFLoader.ts":
  5577. /*!********************************!*\
  5578. !*** ./glTF/2.0/glTFLoader.ts ***!
  5579. \********************************/
  5580. /*! exports provided: ArrayItem, GLTFLoader */
  5581. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5582. "use strict";
  5583. __webpack_require__.r(__webpack_exports__);
  5584. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  5585. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  5586. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  5587. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  5588. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5589. /**
  5590. * Helper class for working with arrays when loading the glTF asset
  5591. */
  5592. var ArrayItem = /** @class */ (function () {
  5593. function ArrayItem() {
  5594. }
  5595. /**
  5596. * Gets an item from the given array.
  5597. * @param context The context when loading the asset
  5598. * @param array The array to get the item from
  5599. * @param index The index to the array
  5600. * @returns The array item
  5601. */
  5602. ArrayItem.Get = function (context, array, index) {
  5603. if (!array || index == undefined || !array[index]) {
  5604. throw new Error(context + ": Failed to find index (" + index + ")");
  5605. }
  5606. return array[index];
  5607. };
  5608. /**
  5609. * Assign an `index` field to each item of the given array.
  5610. * @param array The array of items
  5611. */
  5612. ArrayItem.Assign = function (array) {
  5613. if (array) {
  5614. for (var index = 0; index < array.length; index++) {
  5615. array[index].index = index;
  5616. }
  5617. }
  5618. };
  5619. return ArrayItem;
  5620. }());
  5621. /**
  5622. * The glTF 2.0 loader
  5623. */
  5624. var GLTFLoader = /** @class */ (function () {
  5625. /** @hidden */
  5626. function GLTFLoader(parent) {
  5627. /** @hidden */
  5628. this._completePromises = new Array();
  5629. /** @hidden */
  5630. this._forAssetContainer = false;
  5631. /** Storage */
  5632. this._babylonLights = [];
  5633. this._disposed = false;
  5634. this._state = null;
  5635. this._extensions = new Array();
  5636. this._defaultBabylonMaterialData = {};
  5637. this._requests = new Array();
  5638. this._parent = parent;
  5639. }
  5640. /**
  5641. * Registers a loader extension.
  5642. * @param name The name of the loader extension.
  5643. * @param factory The factory function that creates the loader extension.
  5644. */
  5645. GLTFLoader.RegisterExtension = function (name, factory) {
  5646. if (GLTFLoader.UnregisterExtension(name)) {
  5647. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  5648. }
  5649. GLTFLoader._RegisteredExtensions[name] = {
  5650. factory: factory
  5651. };
  5652. };
  5653. /**
  5654. * Unregisters a loader extension.
  5655. * @param name The name of the loader extension.
  5656. * @returns A boolean indicating whether the extension has been unregistered
  5657. */
  5658. GLTFLoader.UnregisterExtension = function (name) {
  5659. if (!GLTFLoader._RegisteredExtensions[name]) {
  5660. return false;
  5661. }
  5662. delete GLTFLoader._RegisteredExtensions[name];
  5663. return true;
  5664. };
  5665. Object.defineProperty(GLTFLoader.prototype, "state", {
  5666. /**
  5667. * The loader state.
  5668. */
  5669. get: function () {
  5670. return this._state;
  5671. },
  5672. enumerable: true,
  5673. configurable: true
  5674. });
  5675. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  5676. /**
  5677. * The object that represents the glTF JSON.
  5678. */
  5679. get: function () {
  5680. return this._gltf;
  5681. },
  5682. enumerable: true,
  5683. configurable: true
  5684. });
  5685. Object.defineProperty(GLTFLoader.prototype, "bin", {
  5686. /**
  5687. * The BIN chunk of a binary glTF.
  5688. */
  5689. get: function () {
  5690. return this._bin;
  5691. },
  5692. enumerable: true,
  5693. configurable: true
  5694. });
  5695. Object.defineProperty(GLTFLoader.prototype, "parent", {
  5696. /**
  5697. * The parent file loader.
  5698. */
  5699. get: function () {
  5700. return this._parent;
  5701. },
  5702. enumerable: true,
  5703. configurable: true
  5704. });
  5705. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  5706. /**
  5707. * The Babylon scene when loading the asset.
  5708. */
  5709. get: function () {
  5710. return this._babylonScene;
  5711. },
  5712. enumerable: true,
  5713. configurable: true
  5714. });
  5715. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  5716. /**
  5717. * The root Babylon mesh when loading the asset.
  5718. */
  5719. get: function () {
  5720. return this._rootBabylonMesh;
  5721. },
  5722. enumerable: true,
  5723. configurable: true
  5724. });
  5725. /** @hidden */
  5726. GLTFLoader.prototype.dispose = function () {
  5727. if (this._disposed) {
  5728. return;
  5729. }
  5730. this._disposed = true;
  5731. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  5732. var request = _a[_i];
  5733. request.abort();
  5734. }
  5735. this._requests.length = 0;
  5736. this._completePromises.length = 0;
  5737. for (var name_1 in this._extensions) {
  5738. var extension = this._extensions[name_1];
  5739. extension.dispose && extension.dispose();
  5740. delete this._extensions[name_1];
  5741. }
  5742. delete this._gltf;
  5743. delete this._babylonScene;
  5744. delete this._rootBabylonMesh;
  5745. delete this._progressCallback;
  5746. this._parent._clear();
  5747. };
  5748. /** @hidden */
  5749. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  5750. var _this = this;
  5751. return Promise.resolve().then(function () {
  5752. _this._babylonScene = scene;
  5753. _this._rootUrl = rootUrl;
  5754. _this._fileName = fileName || "scene";
  5755. _this._progressCallback = onProgress;
  5756. _this._forAssetContainer = forAssetContainer;
  5757. _this._loadData(data);
  5758. var nodes = null;
  5759. if (meshesNames) {
  5760. var nodeMap_1 = {};
  5761. if (_this._gltf.nodes) {
  5762. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  5763. var node = _a[_i];
  5764. if (node.name) {
  5765. nodeMap_1[node.name] = node.index;
  5766. }
  5767. }
  5768. }
  5769. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  5770. nodes = names.map(function (name) {
  5771. var node = nodeMap_1[name];
  5772. if (node === undefined) {
  5773. throw new Error("Failed to find node '" + name + "'");
  5774. }
  5775. return node;
  5776. });
  5777. }
  5778. return _this._loadAsync(nodes, function () {
  5779. return {
  5780. meshes: _this._getMeshes(),
  5781. particleSystems: [],
  5782. skeletons: _this._getSkeletons(),
  5783. animationGroups: _this._getAnimationGroups(),
  5784. lights: _this._babylonLights,
  5785. transformNodes: _this._getTransformNodes()
  5786. };
  5787. });
  5788. });
  5789. };
  5790. /** @hidden */
  5791. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  5792. var _this = this;
  5793. return Promise.resolve().then(function () {
  5794. _this._babylonScene = scene;
  5795. _this._rootUrl = rootUrl;
  5796. _this._fileName = fileName || "scene";
  5797. _this._progressCallback = onProgress;
  5798. _this._loadData(data);
  5799. return _this._loadAsync(null, function () { return undefined; });
  5800. });
  5801. };
  5802. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  5803. var _this = this;
  5804. return Promise.resolve().then(function () {
  5805. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  5806. _this._loadExtensions();
  5807. _this._checkExtensions();
  5808. 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];
  5809. 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];
  5810. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  5811. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  5812. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  5813. _this._extensionsOnLoading();
  5814. var promises = new Array();
  5815. // Block the marking of materials dirty until the scene is loaded.
  5816. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  5817. _this._babylonScene.blockMaterialDirtyMechanism = true;
  5818. if (nodes) {
  5819. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  5820. }
  5821. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  5822. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  5823. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  5824. }
  5825. // Restore the blocking of material dirty.
  5826. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  5827. if (_this._parent.compileMaterials) {
  5828. promises.push(_this._compileMaterialsAsync());
  5829. }
  5830. if (_this._parent.compileShadowGenerators) {
  5831. promises.push(_this._compileShadowGeneratorsAsync());
  5832. }
  5833. var resultPromise = Promise.all(promises).then(function () {
  5834. if (_this._rootBabylonMesh) {
  5835. _this._rootBabylonMesh.setEnabled(true);
  5836. }
  5837. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  5838. _this._extensionsOnReady();
  5839. _this._startAnimations();
  5840. return resultFunc();
  5841. });
  5842. resultPromise.then(function () {
  5843. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  5844. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  5845. if (!_this._disposed) {
  5846. Promise.all(_this._completePromises).then(function () {
  5847. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  5848. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  5849. _this._parent.onCompleteObservable.notifyObservers(undefined);
  5850. _this._parent.onCompleteObservable.clear();
  5851. _this.dispose();
  5852. }, function (error) {
  5853. _this._parent.onErrorObservable.notifyObservers(error);
  5854. _this._parent.onErrorObservable.clear();
  5855. _this.dispose();
  5856. });
  5857. }
  5858. });
  5859. });
  5860. return resultPromise;
  5861. }, function (error) {
  5862. if (!_this._disposed) {
  5863. _this._parent.onErrorObservable.notifyObservers(error);
  5864. _this._parent.onErrorObservable.clear();
  5865. _this.dispose();
  5866. }
  5867. throw error;
  5868. });
  5869. };
  5870. GLTFLoader.prototype._loadData = function (data) {
  5871. this._gltf = data.json;
  5872. this._setupData();
  5873. if (data.bin) {
  5874. var buffers = this._gltf.buffers;
  5875. if (buffers && buffers[0] && !buffers[0].uri) {
  5876. var binaryBuffer = buffers[0];
  5877. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  5878. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  5879. }
  5880. this._bin = data.bin;
  5881. }
  5882. else {
  5883. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  5884. }
  5885. }
  5886. };
  5887. GLTFLoader.prototype._setupData = function () {
  5888. ArrayItem.Assign(this._gltf.accessors);
  5889. ArrayItem.Assign(this._gltf.animations);
  5890. ArrayItem.Assign(this._gltf.buffers);
  5891. ArrayItem.Assign(this._gltf.bufferViews);
  5892. ArrayItem.Assign(this._gltf.cameras);
  5893. ArrayItem.Assign(this._gltf.images);
  5894. ArrayItem.Assign(this._gltf.materials);
  5895. ArrayItem.Assign(this._gltf.meshes);
  5896. ArrayItem.Assign(this._gltf.nodes);
  5897. ArrayItem.Assign(this._gltf.samplers);
  5898. ArrayItem.Assign(this._gltf.scenes);
  5899. ArrayItem.Assign(this._gltf.skins);
  5900. ArrayItem.Assign(this._gltf.textures);
  5901. if (this._gltf.nodes) {
  5902. var nodeParents = {};
  5903. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  5904. var node = _a[_i];
  5905. if (node.children) {
  5906. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  5907. var index = _c[_b];
  5908. nodeParents[index] = node.index;
  5909. }
  5910. }
  5911. }
  5912. var rootNode = this._createRootNode();
  5913. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  5914. var node = _e[_d];
  5915. var parentIndex = nodeParents[node.index];
  5916. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  5917. }
  5918. }
  5919. };
  5920. GLTFLoader.prototype._loadExtensions = function () {
  5921. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  5922. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  5923. if (extension.name !== name_2) {
  5924. 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);
  5925. }
  5926. this._extensions.push(extension);
  5927. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  5928. }
  5929. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  5930. this._parent.onExtensionLoadedObservable.clear();
  5931. };
  5932. GLTFLoader.prototype._checkExtensions = function () {
  5933. if (this._gltf.extensionsRequired) {
  5934. var _loop_1 = function (name_3) {
  5935. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  5936. if (!available) {
  5937. throw new Error("Require extension " + name_3 + " is not available");
  5938. }
  5939. };
  5940. var this_1 = this;
  5941. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  5942. var name_3 = _a[_i];
  5943. _loop_1(name_3);
  5944. }
  5945. }
  5946. };
  5947. GLTFLoader.prototype._setState = function (state) {
  5948. this._state = state;
  5949. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  5950. };
  5951. GLTFLoader.prototype._createRootNode = function () {
  5952. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  5953. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  5954. this._babylonScene._blockEntityCollection = false;
  5955. this._rootBabylonMesh.setEnabled(false);
  5956. var rootNode = {
  5957. _babylonTransformNode: this._rootBabylonMesh,
  5958. index: -1
  5959. };
  5960. switch (this._parent.coordinateSystemMode) {
  5961. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  5962. if (!this._babylonScene.useRightHandedSystem) {
  5963. rootNode.rotation = [0, 1, 0, 0];
  5964. rootNode.scale = [1, 1, -1];
  5965. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  5966. }
  5967. break;
  5968. }
  5969. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  5970. this._babylonScene.useRightHandedSystem = true;
  5971. break;
  5972. }
  5973. default: {
  5974. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  5975. }
  5976. }
  5977. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  5978. return rootNode;
  5979. };
  5980. /**
  5981. * Loads a glTF scene.
  5982. * @param context The context when loading the asset
  5983. * @param scene The glTF scene property
  5984. * @returns A promise that resolves when the load is complete
  5985. */
  5986. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  5987. var _this = this;
  5988. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  5989. if (extensionPromise) {
  5990. return extensionPromise;
  5991. }
  5992. var promises = new Array();
  5993. this.logOpen(context + " " + (scene.name || ""));
  5994. if (scene.nodes) {
  5995. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  5996. var index = _a[_i];
  5997. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  5998. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  5999. babylonMesh.parent = _this._rootBabylonMesh;
  6000. }));
  6001. }
  6002. }
  6003. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  6004. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  6005. if (this._gltf.nodes) {
  6006. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  6007. var node = _c[_b];
  6008. if (node._babylonTransformNode && node._babylonBones) {
  6009. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  6010. var babylonBone = _e[_d];
  6011. babylonBone.linkTransformNode(node._babylonTransformNode);
  6012. }
  6013. }
  6014. }
  6015. }
  6016. promises.push(this._loadAnimationsAsync());
  6017. this.logClose();
  6018. return Promise.all(promises).then(function () { });
  6019. };
  6020. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  6021. if (node._primitiveBabylonMeshes) {
  6022. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  6023. var babylonMesh = _a[_i];
  6024. callback(babylonMesh);
  6025. }
  6026. }
  6027. };
  6028. GLTFLoader.prototype._getMeshes = function () {
  6029. var meshes = new Array();
  6030. // Root mesh is always first.
  6031. meshes.push(this._rootBabylonMesh);
  6032. var nodes = this._gltf.nodes;
  6033. if (nodes) {
  6034. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  6035. var node = nodes_1[_i];
  6036. this._forEachPrimitive(node, function (babylonMesh) {
  6037. meshes.push(babylonMesh);
  6038. });
  6039. }
  6040. }
  6041. return meshes;
  6042. };
  6043. GLTFLoader.prototype._getTransformNodes = function () {
  6044. var transformNodes = new Array();
  6045. var nodes = this._gltf.nodes;
  6046. if (nodes) {
  6047. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  6048. var node = nodes_2[_i];
  6049. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  6050. transformNodes.push(node._babylonTransformNode);
  6051. }
  6052. }
  6053. }
  6054. return transformNodes;
  6055. };
  6056. GLTFLoader.prototype._getSkeletons = function () {
  6057. var skeletons = new Array();
  6058. var skins = this._gltf.skins;
  6059. if (skins) {
  6060. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  6061. var skin = skins_1[_i];
  6062. if (skin._data) {
  6063. skeletons.push(skin._data.babylonSkeleton);
  6064. }
  6065. }
  6066. }
  6067. return skeletons;
  6068. };
  6069. GLTFLoader.prototype._getAnimationGroups = function () {
  6070. var animationGroups = new Array();
  6071. var animations = this._gltf.animations;
  6072. if (animations) {
  6073. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  6074. var animation = animations_1[_i];
  6075. if (animation._babylonAnimationGroup) {
  6076. animationGroups.push(animation._babylonAnimationGroup);
  6077. }
  6078. }
  6079. }
  6080. return animationGroups;
  6081. };
  6082. GLTFLoader.prototype._startAnimations = function () {
  6083. switch (this._parent.animationStartMode) {
  6084. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  6085. // do nothing
  6086. break;
  6087. }
  6088. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  6089. var babylonAnimationGroups = this._getAnimationGroups();
  6090. if (babylonAnimationGroups.length !== 0) {
  6091. babylonAnimationGroups[0].start(true);
  6092. }
  6093. break;
  6094. }
  6095. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  6096. var babylonAnimationGroups = this._getAnimationGroups();
  6097. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  6098. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  6099. babylonAnimationGroup.start(true);
  6100. }
  6101. break;
  6102. }
  6103. default: {
  6104. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  6105. return;
  6106. }
  6107. }
  6108. };
  6109. /**
  6110. * Loads a glTF node.
  6111. * @param context The context when loading the asset
  6112. * @param node The glTF node property
  6113. * @param assign A function called synchronously after parsing the glTF properties
  6114. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  6115. */
  6116. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  6117. var _this = this;
  6118. if (assign === void 0) { assign = function () { }; }
  6119. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  6120. if (extensionPromise) {
  6121. return extensionPromise;
  6122. }
  6123. if (node._babylonTransformNode) {
  6124. throw new Error(context + ": Invalid recursive node hierarchy");
  6125. }
  6126. var promises = new Array();
  6127. this.logOpen(context + " " + (node.name || ""));
  6128. var loadNode = function (babylonTransformNode) {
  6129. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  6130. GLTFLoader._LoadTransform(node, babylonTransformNode);
  6131. if (node.camera != undefined) {
  6132. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  6133. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  6134. babylonCamera.parent = babylonTransformNode;
  6135. }));
  6136. }
  6137. if (node.children) {
  6138. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  6139. var index = _a[_i];
  6140. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  6141. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  6142. childBabylonMesh.parent = babylonTransformNode;
  6143. }));
  6144. }
  6145. }
  6146. assign(babylonTransformNode);
  6147. };
  6148. if (node.mesh == undefined) {
  6149. var nodeName = node.name || "node" + node.index;
  6150. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6151. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  6152. this._babylonScene._blockEntityCollection = false;
  6153. loadNode(node._babylonTransformNode);
  6154. }
  6155. else {
  6156. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  6157. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  6158. }
  6159. this.logClose();
  6160. return Promise.all(promises).then(function () {
  6161. _this._forEachPrimitive(node, function (babylonMesh) {
  6162. babylonMesh.refreshBoundingInfo(true);
  6163. });
  6164. return node._babylonTransformNode;
  6165. });
  6166. };
  6167. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  6168. var primitives = mesh.primitives;
  6169. if (!primitives || !primitives.length) {
  6170. throw new Error(context + ": Primitives are missing");
  6171. }
  6172. if (primitives[0].index == undefined) {
  6173. ArrayItem.Assign(primitives);
  6174. }
  6175. var promises = new Array();
  6176. this.logOpen(context + " " + (mesh.name || ""));
  6177. var name = node.name || "node" + node.index;
  6178. if (primitives.length === 1) {
  6179. var primitive = mesh.primitives[0];
  6180. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  6181. node._babylonTransformNode = babylonMesh;
  6182. node._primitiveBabylonMeshes = [babylonMesh];
  6183. }));
  6184. }
  6185. else {
  6186. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  6187. node._primitiveBabylonMeshes = [];
  6188. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  6189. var primitive = primitives_1[_i];
  6190. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  6191. babylonMesh.parent = node._babylonTransformNode;
  6192. node._primitiveBabylonMeshes.push(babylonMesh);
  6193. }));
  6194. }
  6195. }
  6196. if (node.skin != undefined) {
  6197. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  6198. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  6199. }
  6200. assign(node._babylonTransformNode);
  6201. this.logClose();
  6202. return Promise.all(promises).then(function () {
  6203. return node._babylonTransformNode;
  6204. });
  6205. };
  6206. /**
  6207. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  6208. * @param context The context when loading the asset
  6209. * @param name The mesh name when loading the asset
  6210. * @param node The glTF node when loading the asset
  6211. * @param mesh The glTF mesh when loading the asset
  6212. * @param primitive The glTF mesh primitive property
  6213. * @param assign A function called synchronously after parsing the glTF properties
  6214. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  6215. */
  6216. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  6217. var _this = this;
  6218. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  6219. if (extensionPromise) {
  6220. return extensionPromise;
  6221. }
  6222. this.logOpen("" + context);
  6223. var shouldInstance = this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  6224. var babylonAbstractMesh;
  6225. var promise;
  6226. if (shouldInstance && primitive._instanceData) {
  6227. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  6228. promise = primitive._instanceData.promise;
  6229. }
  6230. else {
  6231. var promises = new Array();
  6232. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6233. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  6234. this._babylonScene._blockEntityCollection = false;
  6235. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  6236. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  6237. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  6238. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  6239. babylonGeometry.applyToMesh(babylonMesh_1);
  6240. });
  6241. }));
  6242. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  6243. if (primitive.material == undefined) {
  6244. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  6245. if (!babylonMaterial) {
  6246. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  6247. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  6248. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  6249. }
  6250. babylonMesh_1.material = babylonMaterial;
  6251. }
  6252. else {
  6253. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  6254. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  6255. babylonMesh_1.material = babylonMaterial;
  6256. }));
  6257. }
  6258. promise = Promise.all(promises);
  6259. if (shouldInstance) {
  6260. primitive._instanceData = {
  6261. babylonSourceMesh: babylonMesh_1,
  6262. promise: promise
  6263. };
  6264. }
  6265. babylonAbstractMesh = babylonMesh_1;
  6266. }
  6267. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  6268. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  6269. assign(babylonAbstractMesh);
  6270. this.logClose();
  6271. return promise.then(function () {
  6272. return babylonAbstractMesh;
  6273. });
  6274. };
  6275. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  6276. var _this = this;
  6277. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  6278. if (extensionPromise) {
  6279. return extensionPromise;
  6280. }
  6281. var attributes = primitive.attributes;
  6282. if (!attributes) {
  6283. throw new Error(context + ": Attributes are missing");
  6284. }
  6285. var promises = new Array();
  6286. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  6287. if (primitive.indices == undefined) {
  6288. babylonMesh.isUnIndexed = true;
  6289. }
  6290. else {
  6291. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  6292. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6293. babylonGeometry.setIndices(data);
  6294. }));
  6295. }
  6296. var loadAttribute = function (attribute, kind, callback) {
  6297. if (attributes[attribute] == undefined) {
  6298. return;
  6299. }
  6300. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  6301. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  6302. babylonMesh._delayInfo.push(kind);
  6303. }
  6304. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6305. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  6306. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  6307. }));
  6308. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6309. babylonMesh.numBoneInfluencers = 8;
  6310. }
  6311. if (callback) {
  6312. callback(accessor);
  6313. }
  6314. };
  6315. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  6316. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  6317. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  6318. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  6319. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  6320. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  6321. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  6322. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  6323. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  6324. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  6325. if (accessor.type === "VEC4" /* VEC4 */) {
  6326. babylonMesh.hasVertexAlpha = true;
  6327. }
  6328. });
  6329. return Promise.all(promises).then(function () {
  6330. return babylonGeometry;
  6331. });
  6332. };
  6333. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  6334. if (!primitive.targets) {
  6335. return;
  6336. }
  6337. if (node._numMorphTargets == undefined) {
  6338. node._numMorphTargets = primitive.targets.length;
  6339. }
  6340. else if (primitive.targets.length !== node._numMorphTargets) {
  6341. throw new Error(context + ": Primitives do not have the same number of targets");
  6342. }
  6343. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  6344. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  6345. for (var index = 0; index < primitive.targets.length; index++) {
  6346. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  6347. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  6348. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  6349. // TODO: tell the target whether it has positions, normals, tangents
  6350. }
  6351. };
  6352. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  6353. if (!primitive.targets) {
  6354. return Promise.resolve();
  6355. }
  6356. var promises = new Array();
  6357. var morphTargetManager = babylonMesh.morphTargetManager;
  6358. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  6359. var babylonMorphTarget = morphTargetManager.getTarget(index);
  6360. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  6361. }
  6362. return Promise.all(promises).then(function () { });
  6363. };
  6364. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  6365. var _this = this;
  6366. var promises = new Array();
  6367. var loadAttribute = function (attribute, kind, setData) {
  6368. if (attributes[attribute] == undefined) {
  6369. return;
  6370. }
  6371. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  6372. if (!babylonVertexBuffer) {
  6373. return;
  6374. }
  6375. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  6376. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6377. setData(babylonVertexBuffer, data);
  6378. }));
  6379. };
  6380. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  6381. var positions = new Float32Array(data.length);
  6382. babylonVertexBuffer.forEach(data.length, function (value, index) {
  6383. positions[index] = data[index] + value;
  6384. });
  6385. babylonMorphTarget.setPositions(positions);
  6386. });
  6387. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  6388. var normals = new Float32Array(data.length);
  6389. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  6390. normals[index] = data[index] + value;
  6391. });
  6392. babylonMorphTarget.setNormals(normals);
  6393. });
  6394. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  6395. var tangents = new Float32Array(data.length / 3 * 4);
  6396. var dataIndex = 0;
  6397. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  6398. // Tangent data for morph targets is stored as xyz delta.
  6399. // The vertexData.tangent is stored as xyzw.
  6400. // So we need to skip every fourth vertexData.tangent.
  6401. if (((index + 1) % 4) !== 0) {
  6402. tangents[dataIndex] = data[dataIndex] + value;
  6403. dataIndex++;
  6404. }
  6405. });
  6406. babylonMorphTarget.setTangents(tangents);
  6407. });
  6408. return Promise.all(promises).then(function () { });
  6409. };
  6410. GLTFLoader._LoadTransform = function (node, babylonNode) {
  6411. // Ignore the TRS of skinned nodes.
  6412. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6413. if (node.skin != undefined) {
  6414. return;
  6415. }
  6416. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  6417. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  6418. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  6419. if (node.matrix) {
  6420. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  6421. matrix.decompose(scaling, rotation, position);
  6422. }
  6423. else {
  6424. if (node.translation) {
  6425. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  6426. }
  6427. if (node.rotation) {
  6428. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  6429. }
  6430. if (node.scale) {
  6431. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  6432. }
  6433. }
  6434. babylonNode.position = position;
  6435. babylonNode.rotationQuaternion = rotation;
  6436. babylonNode.scaling = scaling;
  6437. };
  6438. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  6439. var _this = this;
  6440. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  6441. if (extensionPromise) {
  6442. return extensionPromise;
  6443. }
  6444. var assignSkeleton = function (skeleton) {
  6445. _this._forEachPrimitive(node, function (babylonMesh) {
  6446. babylonMesh.skeleton = skeleton;
  6447. });
  6448. };
  6449. if (skin._data) {
  6450. assignSkeleton(skin._data.babylonSkeleton);
  6451. return skin._data.promise;
  6452. }
  6453. var skeletonId = "skeleton" + skin.index;
  6454. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6455. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  6456. this._babylonScene._blockEntityCollection = false;
  6457. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  6458. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  6459. this._loadBones(context, skin, babylonSkeleton);
  6460. assignSkeleton(babylonSkeleton);
  6461. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  6462. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  6463. });
  6464. skin._data = {
  6465. babylonSkeleton: babylonSkeleton,
  6466. promise: promise
  6467. };
  6468. return promise;
  6469. };
  6470. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  6471. var babylonBones = {};
  6472. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  6473. var index = _a[_i];
  6474. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  6475. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  6476. }
  6477. };
  6478. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  6479. var babylonBone = babylonBones[node.index];
  6480. if (babylonBone) {
  6481. return babylonBone;
  6482. }
  6483. var babylonParentBone = null;
  6484. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  6485. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  6486. }
  6487. var boneIndex = skin.joints.indexOf(node.index);
  6488. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  6489. babylonBones[node.index] = babylonBone;
  6490. node._babylonBones = node._babylonBones || [];
  6491. node._babylonBones.push(babylonBone);
  6492. return babylonBone;
  6493. };
  6494. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  6495. if (skin.inverseBindMatrices == undefined) {
  6496. return Promise.resolve(null);
  6497. }
  6498. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  6499. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  6500. };
  6501. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  6502. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  6503. var babylonBone = _a[_i];
  6504. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  6505. var boneIndex = babylonBone._index;
  6506. if (inverseBindMatricesData && boneIndex !== -1) {
  6507. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  6508. baseMatrix.invertToRef(baseMatrix);
  6509. }
  6510. var babylonParentBone = babylonBone.getParent();
  6511. if (babylonParentBone) {
  6512. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  6513. }
  6514. babylonBone.updateMatrix(baseMatrix, false, false);
  6515. babylonBone._updateDifferenceMatrix(undefined, false);
  6516. }
  6517. };
  6518. GLTFLoader.prototype._getNodeMatrix = function (node) {
  6519. return node.matrix ?
  6520. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  6521. 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());
  6522. };
  6523. /**
  6524. * Loads a glTF camera.
  6525. * @param context The context when loading the asset
  6526. * @param camera The glTF camera property
  6527. * @param assign A function called synchronously after parsing the glTF properties
  6528. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  6529. */
  6530. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  6531. if (assign === void 0) { assign = function () { }; }
  6532. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  6533. if (extensionPromise) {
  6534. return extensionPromise;
  6535. }
  6536. var promises = new Array();
  6537. this.logOpen(context + " " + (camera.name || ""));
  6538. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6539. 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);
  6540. this._babylonScene._blockEntityCollection = false;
  6541. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  6542. switch (camera.type) {
  6543. case "perspective" /* PERSPECTIVE */: {
  6544. var perspective = camera.perspective;
  6545. if (!perspective) {
  6546. throw new Error(context + ": Camera perspective properties are missing");
  6547. }
  6548. babylonCamera.fov = perspective.yfov;
  6549. babylonCamera.minZ = perspective.znear;
  6550. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  6551. break;
  6552. }
  6553. case "orthographic" /* ORTHOGRAPHIC */: {
  6554. if (!camera.orthographic) {
  6555. throw new Error(context + ": Camera orthographic properties are missing");
  6556. }
  6557. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  6558. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  6559. babylonCamera.orthoRight = camera.orthographic.xmag;
  6560. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  6561. babylonCamera.orthoTop = camera.orthographic.ymag;
  6562. babylonCamera.minZ = camera.orthographic.znear;
  6563. babylonCamera.maxZ = camera.orthographic.zfar;
  6564. break;
  6565. }
  6566. default: {
  6567. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  6568. }
  6569. }
  6570. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  6571. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  6572. assign(babylonCamera);
  6573. return Promise.all(promises).then(function () {
  6574. return babylonCamera;
  6575. });
  6576. };
  6577. GLTFLoader.prototype._loadAnimationsAsync = function () {
  6578. var animations = this._gltf.animations;
  6579. if (!animations) {
  6580. return Promise.resolve();
  6581. }
  6582. var promises = new Array();
  6583. for (var index = 0; index < animations.length; index++) {
  6584. var animation = animations[index];
  6585. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  6586. }
  6587. return Promise.all(promises).then(function () { });
  6588. };
  6589. /**
  6590. * Loads a glTF animation.
  6591. * @param context The context when loading the asset
  6592. * @param animation The glTF animation property
  6593. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  6594. */
  6595. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  6596. var promise = this._extensionsLoadAnimationAsync(context, animation);
  6597. if (promise) {
  6598. return promise;
  6599. }
  6600. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  6601. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  6602. this._babylonScene._blockEntityCollection = false;
  6603. animation._babylonAnimationGroup = babylonAnimationGroup;
  6604. var promises = new Array();
  6605. ArrayItem.Assign(animation.channels);
  6606. ArrayItem.Assign(animation.samplers);
  6607. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  6608. var channel = _a[_i];
  6609. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  6610. }
  6611. return Promise.all(promises).then(function () {
  6612. babylonAnimationGroup.normalize(0);
  6613. return babylonAnimationGroup;
  6614. });
  6615. };
  6616. /**
  6617. * @hidden Loads a glTF animation channel.
  6618. * @param context The context when loading the asset
  6619. * @param animationContext The context of the animation when loading the asset
  6620. * @param animation The glTF animation property
  6621. * @param channel The glTF animation channel property
  6622. * @param babylonAnimationGroup The babylon animation group property
  6623. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  6624. * @returns A void promise when the channel load is complete
  6625. */
  6626. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  6627. var _this = this;
  6628. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  6629. if (channel.target.node == undefined) {
  6630. return Promise.resolve();
  6631. }
  6632. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  6633. // Ignore animations that have no animation targets.
  6634. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  6635. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  6636. return Promise.resolve();
  6637. }
  6638. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  6639. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  6640. var targetPath;
  6641. var animationType;
  6642. switch (channel.target.path) {
  6643. case "translation" /* TRANSLATION */: {
  6644. targetPath = "position";
  6645. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6646. break;
  6647. }
  6648. case "rotation" /* ROTATION */: {
  6649. targetPath = "rotationQuaternion";
  6650. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  6651. break;
  6652. }
  6653. case "scale" /* SCALE */: {
  6654. targetPath = "scaling";
  6655. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  6656. break;
  6657. }
  6658. case "weights" /* WEIGHTS */: {
  6659. targetPath = "influence";
  6660. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  6661. break;
  6662. }
  6663. default: {
  6664. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  6665. }
  6666. }
  6667. var outputBufferOffset = 0;
  6668. var getNextOutputValue;
  6669. switch (targetPath) {
  6670. case "position": {
  6671. getNextOutputValue = function () {
  6672. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6673. outputBufferOffset += 3;
  6674. return value;
  6675. };
  6676. break;
  6677. }
  6678. case "rotationQuaternion": {
  6679. getNextOutputValue = function () {
  6680. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  6681. outputBufferOffset += 4;
  6682. return value;
  6683. };
  6684. break;
  6685. }
  6686. case "scaling": {
  6687. getNextOutputValue = function () {
  6688. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  6689. outputBufferOffset += 3;
  6690. return value;
  6691. };
  6692. break;
  6693. }
  6694. case "influence": {
  6695. getNextOutputValue = function () {
  6696. var value = new Array(targetNode._numMorphTargets);
  6697. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  6698. value[i] = data.output[outputBufferOffset++];
  6699. }
  6700. return value;
  6701. };
  6702. break;
  6703. }
  6704. }
  6705. var getNextKey;
  6706. switch (data.interpolation) {
  6707. case "STEP" /* STEP */: {
  6708. getNextKey = function (frameIndex) { return ({
  6709. frame: data.input[frameIndex],
  6710. value: getNextOutputValue(),
  6711. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  6712. }); };
  6713. break;
  6714. }
  6715. case "LINEAR" /* LINEAR */: {
  6716. getNextKey = function (frameIndex) { return ({
  6717. frame: data.input[frameIndex],
  6718. value: getNextOutputValue()
  6719. }); };
  6720. break;
  6721. }
  6722. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6723. getNextKey = function (frameIndex) { return ({
  6724. frame: data.input[frameIndex],
  6725. inTangent: getNextOutputValue(),
  6726. value: getNextOutputValue(),
  6727. outTangent: getNextOutputValue()
  6728. }); };
  6729. break;
  6730. }
  6731. }
  6732. var keys = new Array(data.input.length);
  6733. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  6734. keys[frameIndex] = getNextKey(frameIndex);
  6735. }
  6736. if (targetPath === "influence") {
  6737. var _loop_2 = function (targetIndex) {
  6738. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6739. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6740. babylonAnimation.setKeys(keys.map(function (key) { return ({
  6741. frame: key.frame,
  6742. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  6743. value: key.value[targetIndex],
  6744. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  6745. }); }));
  6746. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  6747. var babylonMesh = babylonAbstractMesh;
  6748. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  6749. var babylonAnimationClone = babylonAnimation.clone();
  6750. morphTarget.animations.push(babylonAnimationClone);
  6751. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  6752. });
  6753. };
  6754. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  6755. _loop_2(targetIndex);
  6756. }
  6757. }
  6758. else {
  6759. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  6760. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  6761. babylonAnimation.setKeys(keys);
  6762. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  6763. animationTargetOverride.animations.push(babylonAnimation);
  6764. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  6765. }
  6766. else {
  6767. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  6768. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  6769. }
  6770. }
  6771. });
  6772. };
  6773. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  6774. if (sampler._data) {
  6775. return sampler._data;
  6776. }
  6777. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  6778. switch (interpolation) {
  6779. case "STEP" /* STEP */:
  6780. case "LINEAR" /* LINEAR */:
  6781. case "CUBICSPLINE" /* CUBICSPLINE */: {
  6782. break;
  6783. }
  6784. default: {
  6785. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  6786. }
  6787. }
  6788. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  6789. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  6790. sampler._data = Promise.all([
  6791. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  6792. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  6793. ]).then(function (_a) {
  6794. var inputData = _a[0], outputData = _a[1];
  6795. return {
  6796. input: inputData,
  6797. interpolation: interpolation,
  6798. output: outputData,
  6799. };
  6800. });
  6801. return sampler._data;
  6802. };
  6803. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  6804. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  6805. if (extensionPromise) {
  6806. return extensionPromise;
  6807. }
  6808. if (!buffer._data) {
  6809. if (buffer.uri) {
  6810. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  6811. }
  6812. else {
  6813. if (!this._bin) {
  6814. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  6815. }
  6816. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  6817. }
  6818. }
  6819. return buffer._data.then(function (data) {
  6820. try {
  6821. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  6822. }
  6823. catch (e) {
  6824. throw new Error(context + ": " + e.message);
  6825. }
  6826. });
  6827. };
  6828. /**
  6829. * Loads a glTF buffer view.
  6830. * @param context The context when loading the asset
  6831. * @param bufferView The glTF buffer view property
  6832. * @returns A promise that resolves with the loaded data when the load is complete
  6833. */
  6834. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  6835. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  6836. if (extensionPromise) {
  6837. return extensionPromise;
  6838. }
  6839. if (bufferView._data) {
  6840. return bufferView._data;
  6841. }
  6842. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  6843. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  6844. return bufferView._data;
  6845. };
  6846. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  6847. var _this = this;
  6848. if (accessor._data) {
  6849. return accessor._data;
  6850. }
  6851. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  6852. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  6853. var length = numComponents * accessor.count;
  6854. if (accessor.bufferView == undefined) {
  6855. accessor._data = Promise.resolve(new constructor(length));
  6856. }
  6857. else {
  6858. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6859. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  6860. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6861. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  6862. }
  6863. else {
  6864. var typedArray_1 = new constructor(length);
  6865. 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) {
  6866. typedArray_1[index] = value;
  6867. });
  6868. return typedArray_1;
  6869. }
  6870. });
  6871. }
  6872. if (accessor.sparse) {
  6873. var sparse_1 = accessor.sparse;
  6874. accessor._data = accessor._data.then(function (data) {
  6875. var typedArray = data;
  6876. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  6877. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  6878. return Promise.all([
  6879. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  6880. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  6881. ]).then(function (_a) {
  6882. var indicesData = _a[0], valuesData = _a[1];
  6883. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  6884. var sparseLength = numComponents * sparse_1.count;
  6885. var values;
  6886. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  6887. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6888. }
  6889. else {
  6890. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  6891. values = new constructor(sparseLength);
  6892. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  6893. values[index] = value;
  6894. });
  6895. }
  6896. var valuesIndex = 0;
  6897. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  6898. var dataIndex = indices[indicesIndex] * numComponents;
  6899. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  6900. typedArray[dataIndex++] = values[valuesIndex++];
  6901. }
  6902. }
  6903. return typedArray;
  6904. });
  6905. });
  6906. }
  6907. return accessor._data;
  6908. };
  6909. /** @hidden */
  6910. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  6911. return this._loadAccessorAsync(context, accessor, Float32Array);
  6912. };
  6913. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  6914. if (accessor.type !== "SCALAR" /* SCALAR */) {
  6915. throw new Error(context + "/type: Invalid value " + accessor.type);
  6916. }
  6917. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  6918. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  6919. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  6920. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  6921. }
  6922. if (accessor._data) {
  6923. return accessor._data;
  6924. }
  6925. if (accessor.sparse) {
  6926. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  6927. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  6928. }
  6929. else {
  6930. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6931. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6932. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  6933. });
  6934. }
  6935. return accessor._data;
  6936. };
  6937. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  6938. var _this = this;
  6939. if (bufferView._babylonBuffer) {
  6940. return bufferView._babylonBuffer;
  6941. }
  6942. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  6943. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  6944. });
  6945. return bufferView._babylonBuffer;
  6946. };
  6947. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  6948. var _this = this;
  6949. if (accessor._babylonVertexBuffer) {
  6950. return accessor._babylonVertexBuffer;
  6951. }
  6952. if (accessor.sparse) {
  6953. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6954. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6955. });
  6956. }
  6957. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  6958. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  6959. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  6960. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6961. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6962. });
  6963. }
  6964. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  6965. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  6966. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  6967. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  6968. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  6969. });
  6970. }
  6971. else {
  6972. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  6973. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  6974. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  6975. 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);
  6976. });
  6977. }
  6978. return accessor._babylonVertexBuffer;
  6979. };
  6980. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  6981. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  6982. throw new Error(context + ": Material type not supported");
  6983. }
  6984. var promises = new Array();
  6985. if (properties) {
  6986. if (properties.baseColorFactor) {
  6987. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  6988. babylonMaterial.alpha = properties.baseColorFactor[3];
  6989. }
  6990. else {
  6991. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  6992. }
  6993. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  6994. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  6995. if (properties.baseColorTexture) {
  6996. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  6997. texture.name = babylonMaterial.name + " (Base Color)";
  6998. babylonMaterial.albedoTexture = texture;
  6999. }));
  7000. }
  7001. if (properties.metallicRoughnessTexture) {
  7002. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  7003. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  7004. babylonMaterial.metallicTexture = texture;
  7005. }));
  7006. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  7007. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  7008. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  7009. }
  7010. }
  7011. return Promise.all(promises).then(function () { });
  7012. };
  7013. /** @hidden */
  7014. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7015. if (assign === void 0) { assign = function () { }; }
  7016. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  7017. if (extensionPromise) {
  7018. return extensionPromise;
  7019. }
  7020. material._data = material._data || {};
  7021. var babylonData = material._data[babylonDrawMode];
  7022. if (!babylonData) {
  7023. this.logOpen(context + " " + (material.name || ""));
  7024. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  7025. babylonData = {
  7026. babylonMaterial: babylonMaterial,
  7027. babylonMeshes: [],
  7028. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  7029. };
  7030. material._data[babylonDrawMode] = babylonData;
  7031. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  7032. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  7033. this.logClose();
  7034. }
  7035. babylonData.babylonMeshes.push(babylonMesh);
  7036. babylonMesh.onDisposeObservable.addOnce(function () {
  7037. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  7038. if (index !== -1) {
  7039. babylonData.babylonMeshes.splice(index, 1);
  7040. }
  7041. });
  7042. assign(babylonData.babylonMaterial);
  7043. return babylonData.promise.then(function () {
  7044. return babylonData.babylonMaterial;
  7045. });
  7046. };
  7047. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  7048. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7049. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  7050. this._babylonScene._blockEntityCollection = false;
  7051. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  7052. babylonMaterial.fillMode = babylonDrawMode;
  7053. babylonMaterial.enableSpecularAntiAliasing = true;
  7054. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  7055. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  7056. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7057. babylonMaterial.metallic = 1;
  7058. babylonMaterial.roughness = 1;
  7059. return babylonMaterial;
  7060. };
  7061. /**
  7062. * Creates a Babylon material from a glTF material.
  7063. * @param context The context when loading the asset
  7064. * @param material The glTF material property
  7065. * @param babylonDrawMode The draw mode for the Babylon material
  7066. * @returns The Babylon material
  7067. */
  7068. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  7069. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  7070. if (extensionPromise) {
  7071. return extensionPromise;
  7072. }
  7073. var name = material.name || "material" + material.index;
  7074. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  7075. return babylonMaterial;
  7076. };
  7077. /**
  7078. * Loads properties from a glTF material into a Babylon material.
  7079. * @param context The context when loading the asset
  7080. * @param material The glTF material property
  7081. * @param babylonMaterial The Babylon material
  7082. * @returns A promise that resolves when the load is complete
  7083. */
  7084. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7085. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  7086. if (extensionPromise) {
  7087. return extensionPromise;
  7088. }
  7089. var promises = new Array();
  7090. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  7091. if (material.pbrMetallicRoughness) {
  7092. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  7093. }
  7094. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  7095. return Promise.all(promises).then(function () { });
  7096. };
  7097. /**
  7098. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  7099. * @param context The context when loading the asset
  7100. * @param material The glTF material property
  7101. * @param babylonMaterial The Babylon material
  7102. * @returns A promise that resolves when the load is complete
  7103. */
  7104. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  7105. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7106. throw new Error(context + ": Material type not supported");
  7107. }
  7108. var promises = new Array();
  7109. 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);
  7110. if (material.doubleSided) {
  7111. babylonMaterial.backFaceCulling = false;
  7112. babylonMaterial.twoSidedLighting = true;
  7113. }
  7114. if (material.normalTexture) {
  7115. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  7116. texture.name = babylonMaterial.name + " (Normal)";
  7117. babylonMaterial.bumpTexture = texture;
  7118. }));
  7119. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  7120. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  7121. if (material.normalTexture.scale != undefined) {
  7122. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  7123. }
  7124. babylonMaterial.forceIrradianceInFragment = true;
  7125. }
  7126. if (material.occlusionTexture) {
  7127. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  7128. texture.name = babylonMaterial.name + " (Occlusion)";
  7129. babylonMaterial.ambientTexture = texture;
  7130. }));
  7131. babylonMaterial.useAmbientInGrayScale = true;
  7132. if (material.occlusionTexture.strength != undefined) {
  7133. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  7134. }
  7135. }
  7136. if (material.emissiveTexture) {
  7137. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  7138. texture.name = babylonMaterial.name + " (Emissive)";
  7139. babylonMaterial.emissiveTexture = texture;
  7140. }));
  7141. }
  7142. return Promise.all(promises).then(function () { });
  7143. };
  7144. /**
  7145. * Loads the alpha properties from a glTF material into a Babylon material.
  7146. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  7147. * @param context The context when loading the asset
  7148. * @param material The glTF material property
  7149. * @param babylonMaterial The Babylon material
  7150. */
  7151. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  7152. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  7153. throw new Error(context + ": Material type not supported");
  7154. }
  7155. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  7156. switch (alphaMode) {
  7157. case "OPAQUE" /* OPAQUE */: {
  7158. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  7159. break;
  7160. }
  7161. case "MASK" /* MASK */: {
  7162. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  7163. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  7164. if (babylonMaterial.albedoTexture) {
  7165. babylonMaterial.albedoTexture.hasAlpha = true;
  7166. }
  7167. break;
  7168. }
  7169. case "BLEND" /* BLEND */: {
  7170. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  7171. if (babylonMaterial.albedoTexture) {
  7172. babylonMaterial.albedoTexture.hasAlpha = true;
  7173. babylonMaterial.useAlphaFromAlbedoTexture = true;
  7174. }
  7175. break;
  7176. }
  7177. default: {
  7178. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  7179. }
  7180. }
  7181. };
  7182. /**
  7183. * Loads a glTF texture info.
  7184. * @param context The context when loading the asset
  7185. * @param textureInfo The glTF texture info property
  7186. * @param assign A function called synchronously after parsing the glTF properties
  7187. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  7188. */
  7189. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  7190. var _this = this;
  7191. if (assign === void 0) { assign = function () { }; }
  7192. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  7193. if (extensionPromise) {
  7194. return extensionPromise;
  7195. }
  7196. this.logOpen("" + context);
  7197. if (textureInfo.texCoord >= 2) {
  7198. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  7199. }
  7200. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  7201. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  7202. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  7203. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  7204. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  7205. assign(babylonTexture);
  7206. });
  7207. this.logClose();
  7208. return promise;
  7209. };
  7210. /** @hidden */
  7211. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  7212. if (assign === void 0) { assign = function () { }; }
  7213. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  7214. if (extensionPromise) {
  7215. return extensionPromise;
  7216. }
  7217. this.logOpen(context + " " + (texture.name || ""));
  7218. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  7219. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  7220. var promise = this._createTextureAsync(context, sampler, image, assign);
  7221. this.logClose();
  7222. return promise;
  7223. };
  7224. /** @hidden */
  7225. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign) {
  7226. var _this = this;
  7227. if (assign === void 0) { assign = function () { }; }
  7228. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  7229. var promises = new Array();
  7230. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  7231. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  7232. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  7233. if (!_this._disposed) {
  7234. deferred.resolve();
  7235. }
  7236. }, function (message, exception) {
  7237. if (!_this._disposed) {
  7238. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  7239. }
  7240. }, undefined, undefined, undefined, image.mimeType);
  7241. this._babylonScene._blockEntityCollection = false;
  7242. promises.push(deferred.promise);
  7243. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  7244. var name = image.uri || _this._fileName + "#image" + image.index;
  7245. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  7246. babylonTexture.updateURL(dataUrl, data);
  7247. }));
  7248. babylonTexture.wrapU = samplerData.wrapU;
  7249. babylonTexture.wrapV = samplerData.wrapV;
  7250. assign(babylonTexture);
  7251. return Promise.all(promises).then(function () {
  7252. return babylonTexture;
  7253. });
  7254. };
  7255. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  7256. if (!sampler._data) {
  7257. sampler._data = {
  7258. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  7259. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  7260. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  7261. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  7262. };
  7263. }
  7264. return sampler._data;
  7265. };
  7266. /**
  7267. * Loads a glTF image.
  7268. * @param context The context when loading the asset
  7269. * @param image The glTF image property
  7270. * @returns A promise that resolves with the loaded data when the load is complete
  7271. */
  7272. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  7273. if (!image._data) {
  7274. this.logOpen(context + " " + (image.name || ""));
  7275. if (image.uri) {
  7276. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  7277. }
  7278. else {
  7279. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  7280. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  7281. }
  7282. this.logClose();
  7283. }
  7284. return image._data;
  7285. };
  7286. /**
  7287. * Loads a glTF uri.
  7288. * @param context The context when loading the asset
  7289. * @param property The glTF property associated with the uri
  7290. * @param uri The base64 or relative uri
  7291. * @returns A promise that resolves with the loaded data when the load is complete
  7292. */
  7293. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  7294. var _this = this;
  7295. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  7296. if (extensionPromise) {
  7297. return extensionPromise;
  7298. }
  7299. if (!GLTFLoader._ValidateUri(uri)) {
  7300. throw new Error(context + ": '" + uri + "' is invalid");
  7301. }
  7302. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  7303. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  7304. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  7305. return Promise.resolve(data);
  7306. }
  7307. this.log("Loading " + uri);
  7308. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  7309. return new Promise(function (resolve, reject) {
  7310. if (!_this._disposed) {
  7311. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  7312. if (!_this._disposed) {
  7313. var data = new Uint8Array(fileData);
  7314. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  7315. resolve(data);
  7316. }
  7317. }, function (event) {
  7318. if (!_this._disposed) {
  7319. if (request_1) {
  7320. request_1._lengthComputable = event.lengthComputable;
  7321. request_1._loaded = event.loaded;
  7322. request_1._total = event.total;
  7323. }
  7324. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  7325. try {
  7326. _this._onProgress();
  7327. }
  7328. catch (e) {
  7329. reject(e);
  7330. }
  7331. }
  7332. }
  7333. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  7334. if (!_this._disposed) {
  7335. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  7336. }
  7337. });
  7338. _this._requests.push(request_1);
  7339. }
  7340. });
  7341. });
  7342. };
  7343. GLTFLoader.prototype._onProgress = function () {
  7344. if (!this._progressCallback) {
  7345. return;
  7346. }
  7347. var lengthComputable = true;
  7348. var loaded = 0;
  7349. var total = 0;
  7350. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  7351. var request = _a[_i];
  7352. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  7353. return;
  7354. }
  7355. lengthComputable = lengthComputable && request._lengthComputable;
  7356. loaded += request._loaded;
  7357. total += request._total;
  7358. }
  7359. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  7360. };
  7361. /**
  7362. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  7363. * @param babylonObject the Babylon object with metadata
  7364. * @param pointer the JSON pointer
  7365. */
  7366. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  7367. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  7368. var gltf = (metadata.gltf = metadata.gltf || {});
  7369. var pointers = (gltf.pointers = gltf.pointers || []);
  7370. pointers.push(pointer);
  7371. };
  7372. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  7373. // Set defaults if undefined
  7374. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  7375. switch (mode) {
  7376. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  7377. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  7378. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7379. default:
  7380. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  7381. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  7382. }
  7383. };
  7384. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  7385. // Set defaults if undefined
  7386. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  7387. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  7388. if (magFilter === 9729 /* LINEAR */) {
  7389. switch (minFilter) {
  7390. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  7391. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  7392. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  7393. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  7394. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  7395. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7396. default:
  7397. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7398. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  7399. }
  7400. }
  7401. else {
  7402. if (magFilter !== 9728 /* NEAREST */) {
  7403. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  7404. }
  7405. switch (minFilter) {
  7406. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  7407. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  7408. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7409. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  7410. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  7411. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  7412. default:
  7413. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  7414. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  7415. }
  7416. }
  7417. };
  7418. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  7419. switch (componentType) {
  7420. case 5120 /* BYTE */: return Int8Array;
  7421. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  7422. case 5122 /* SHORT */: return Int16Array;
  7423. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  7424. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  7425. case 5126 /* FLOAT */: return Float32Array;
  7426. default: throw new Error(context + ": Invalid component type " + componentType);
  7427. }
  7428. };
  7429. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  7430. var buffer = bufferView.buffer;
  7431. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  7432. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  7433. try {
  7434. return new constructor(buffer, byteOffset, length);
  7435. }
  7436. catch (e) {
  7437. throw new Error(context + ": " + e);
  7438. }
  7439. };
  7440. GLTFLoader._GetNumComponents = function (context, type) {
  7441. switch (type) {
  7442. case "SCALAR": return 1;
  7443. case "VEC2": return 2;
  7444. case "VEC3": return 3;
  7445. case "VEC4": return 4;
  7446. case "MAT2": return 4;
  7447. case "MAT3": return 9;
  7448. case "MAT4": return 16;
  7449. }
  7450. throw new Error(context + ": Invalid type (" + type + ")");
  7451. };
  7452. GLTFLoader._ValidateUri = function (uri) {
  7453. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  7454. };
  7455. GLTFLoader._GetDrawMode = function (context, mode) {
  7456. if (mode == undefined) {
  7457. mode = 4 /* TRIANGLES */;
  7458. }
  7459. switch (mode) {
  7460. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  7461. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  7462. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  7463. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  7464. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  7465. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  7466. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  7467. }
  7468. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  7469. };
  7470. GLTFLoader.prototype._compileMaterialsAsync = function () {
  7471. var _this = this;
  7472. this._parent._startPerformanceCounter("Compile materials");
  7473. var promises = new Array();
  7474. if (this._gltf.materials) {
  7475. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  7476. var material = _a[_i];
  7477. if (material._data) {
  7478. for (var babylonDrawMode in material._data) {
  7479. var babylonData = material._data[babylonDrawMode];
  7480. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  7481. var babylonMesh = _c[_b];
  7482. // Ensure nonUniformScaling is set if necessary.
  7483. babylonMesh.computeWorldMatrix(true);
  7484. var babylonMaterial = babylonData.babylonMaterial;
  7485. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  7486. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  7487. if (this._parent.useClipPlane) {
  7488. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  7489. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  7490. }
  7491. }
  7492. }
  7493. }
  7494. }
  7495. }
  7496. return Promise.all(promises).then(function () {
  7497. _this._parent._endPerformanceCounter("Compile materials");
  7498. });
  7499. };
  7500. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  7501. var _this = this;
  7502. this._parent._startPerformanceCounter("Compile shadow generators");
  7503. var promises = new Array();
  7504. var lights = this._babylonScene.lights;
  7505. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  7506. var light = lights_1[_i];
  7507. var generator = light.getShadowGenerator();
  7508. if (generator) {
  7509. promises.push(generator.forceCompilationAsync());
  7510. }
  7511. }
  7512. return Promise.all(promises).then(function () {
  7513. _this._parent._endPerformanceCounter("Compile shadow generators");
  7514. });
  7515. };
  7516. GLTFLoader.prototype._forEachExtensions = function (action) {
  7517. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7518. var extension = _a[_i];
  7519. if (extension.enabled) {
  7520. action(extension);
  7521. }
  7522. }
  7523. };
  7524. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  7525. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  7526. var extension = _a[_i];
  7527. if (extension.enabled) {
  7528. var id = extension.name + "." + functionName;
  7529. var loaderProperty = property;
  7530. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  7531. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  7532. if (!activeLoaderExtensionFunctions[id]) {
  7533. activeLoaderExtensionFunctions[id] = true;
  7534. try {
  7535. var result = actionAsync(extension);
  7536. if (result) {
  7537. return result;
  7538. }
  7539. }
  7540. finally {
  7541. delete activeLoaderExtensionFunctions[id];
  7542. }
  7543. }
  7544. }
  7545. }
  7546. return null;
  7547. };
  7548. GLTFLoader.prototype._extensionsOnLoading = function () {
  7549. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  7550. };
  7551. GLTFLoader.prototype._extensionsOnReady = function () {
  7552. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  7553. };
  7554. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  7555. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  7556. };
  7557. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  7558. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  7559. };
  7560. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  7561. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  7562. };
  7563. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  7564. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  7565. };
  7566. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  7567. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  7568. };
  7569. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  7570. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  7571. };
  7572. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  7573. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  7574. };
  7575. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  7576. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  7577. };
  7578. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  7579. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  7580. };
  7581. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  7582. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  7583. };
  7584. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  7585. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  7586. };
  7587. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  7588. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  7589. };
  7590. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  7591. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  7592. };
  7593. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  7594. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  7595. };
  7596. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  7597. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  7598. };
  7599. /**
  7600. * Helper method called by a loader extension to load an glTF extension.
  7601. * @param context The context when loading the asset
  7602. * @param property The glTF property to load the extension from
  7603. * @param extensionName The name of the extension to load
  7604. * @param actionAsync The action to run
  7605. * @returns The promise returned by actionAsync or null if the extension does not exist
  7606. */
  7607. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  7608. if (!property.extensions) {
  7609. return null;
  7610. }
  7611. var extensions = property.extensions;
  7612. var extension = extensions[extensionName];
  7613. if (!extension) {
  7614. return null;
  7615. }
  7616. return actionAsync(context + "/extensions/" + extensionName, extension);
  7617. };
  7618. /**
  7619. * Helper method called by a loader extension to load a glTF extra.
  7620. * @param context The context when loading the asset
  7621. * @param property The glTF property to load the extra from
  7622. * @param extensionName The name of the extension to load
  7623. * @param actionAsync The action to run
  7624. * @returns The promise returned by actionAsync or null if the extra does not exist
  7625. */
  7626. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  7627. if (!property.extras) {
  7628. return null;
  7629. }
  7630. var extras = property.extras;
  7631. var extra = extras[extensionName];
  7632. if (!extra) {
  7633. return null;
  7634. }
  7635. return actionAsync(context + "/extras/" + extensionName, extra);
  7636. };
  7637. /**
  7638. * Checks for presence of an extension.
  7639. * @param name The name of the extension to check
  7640. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  7641. */
  7642. GLTFLoader.prototype.isExtensionUsed = function (name) {
  7643. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  7644. };
  7645. /**
  7646. * Increments the indentation level and logs a message.
  7647. * @param message The message to log
  7648. */
  7649. GLTFLoader.prototype.logOpen = function (message) {
  7650. this._parent._logOpen(message);
  7651. };
  7652. /**
  7653. * Decrements the indentation level.
  7654. */
  7655. GLTFLoader.prototype.logClose = function () {
  7656. this._parent._logClose();
  7657. };
  7658. /**
  7659. * Logs a message
  7660. * @param message The message to log
  7661. */
  7662. GLTFLoader.prototype.log = function (message) {
  7663. this._parent._log(message);
  7664. };
  7665. /**
  7666. * Starts a performance counter.
  7667. * @param counterName The name of the performance counter
  7668. */
  7669. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  7670. this._parent._startPerformanceCounter(counterName);
  7671. };
  7672. /**
  7673. * Ends a performance counter.
  7674. * @param counterName The name of the performance counter
  7675. */
  7676. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  7677. this._parent._endPerformanceCounter(counterName);
  7678. };
  7679. GLTFLoader._RegisteredExtensions = {};
  7680. /**
  7681. * The default glTF sampler.
  7682. */
  7683. GLTFLoader.DefaultSampler = { index: -1 };
  7684. return GLTFLoader;
  7685. }());
  7686. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  7687. /***/ }),
  7688. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  7689. /*!******************************************!*\
  7690. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  7691. \******************************************/
  7692. /*! no static exports found */
  7693. /***/ (function(module, exports) {
  7694. /***/ }),
  7695. /***/ "./glTF/2.0/index.ts":
  7696. /*!***************************!*\
  7697. !*** ./glTF/2.0/index.ts ***!
  7698. \***************************/
  7699. /*! exports provided: ArrayItem, GLTFLoader, EXT_lights_image_based, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_mesh_instancing, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  7700. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7701. "use strict";
  7702. __webpack_require__.r(__webpack_exports__);
  7703. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  7704. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  7705. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  7706. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  7707. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  7708. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  7709. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  7710. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  7711. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  7712. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_clearcoat"]; });
  7713. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  7714. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_specular"]; });
  7715. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_instancing"]; });
  7716. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_mesh_quantization"]; });
  7717. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_basisu"]; });
  7718. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  7719. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  7720. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  7721. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  7722. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  7723. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["ExtrasAsMetadata"]; });
  7724. /***/ }),
  7725. /***/ "./glTF/glTFFileLoader.ts":
  7726. /*!********************************!*\
  7727. !*** ./glTF/glTFFileLoader.ts ***!
  7728. \********************************/
  7729. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  7730. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  7731. "use strict";
  7732. __webpack_require__.r(__webpack_exports__);
  7733. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  7734. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  7735. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  7736. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  7737. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  7738. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  7739. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  7740. /**
  7741. * Mode that determines the coordinate system to use.
  7742. */
  7743. var GLTFLoaderCoordinateSystemMode;
  7744. (function (GLTFLoaderCoordinateSystemMode) {
  7745. /**
  7746. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  7747. */
  7748. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  7749. /**
  7750. * Sets the useRightHandedSystem flag on the scene.
  7751. */
  7752. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  7753. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  7754. /**
  7755. * Mode that determines what animations will start.
  7756. */
  7757. var GLTFLoaderAnimationStartMode;
  7758. (function (GLTFLoaderAnimationStartMode) {
  7759. /**
  7760. * No animation will start.
  7761. */
  7762. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  7763. /**
  7764. * The first animation will start.
  7765. */
  7766. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  7767. /**
  7768. * All animations will start.
  7769. */
  7770. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  7771. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  7772. /**
  7773. * Loader state.
  7774. */
  7775. var GLTFLoaderState;
  7776. (function (GLTFLoaderState) {
  7777. /**
  7778. * The asset is loading.
  7779. */
  7780. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  7781. /**
  7782. * The asset is ready for rendering.
  7783. */
  7784. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  7785. /**
  7786. * The asset is completely loaded.
  7787. */
  7788. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  7789. })(GLTFLoaderState || (GLTFLoaderState = {}));
  7790. /**
  7791. * File loader for loading glTF files into a scene.
  7792. */
  7793. var GLTFFileLoader = /** @class */ (function () {
  7794. function GLTFFileLoader() {
  7795. // --------------
  7796. // Common options
  7797. // --------------
  7798. /**
  7799. * Raised when the asset has been parsed
  7800. */
  7801. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7802. // ----------
  7803. // V2 options
  7804. // ----------
  7805. /**
  7806. * The coordinate system mode. Defaults to AUTO.
  7807. */
  7808. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  7809. /**
  7810. * The animation start mode. Defaults to FIRST.
  7811. */
  7812. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  7813. /**
  7814. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  7815. */
  7816. this.compileMaterials = false;
  7817. /**
  7818. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  7819. */
  7820. this.useClipPlane = false;
  7821. /**
  7822. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  7823. */
  7824. this.compileShadowGenerators = false;
  7825. /**
  7826. * Defines if the Alpha blended materials are only applied as coverage.
  7827. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  7828. * If true, no extra effects are applied to transparent pixels.
  7829. */
  7830. this.transparencyAsCoverage = false;
  7831. /**
  7832. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  7833. * Enabling will disable offline support and glTF validator.
  7834. * Defaults to false.
  7835. */
  7836. this.useRangeRequests = false;
  7837. /**
  7838. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  7839. */
  7840. this.createInstances = true;
  7841. /**
  7842. * Function called before loading a url referenced by the asset.
  7843. */
  7844. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  7845. /**
  7846. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7847. */
  7848. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7849. /**
  7850. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  7851. */
  7852. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7853. /**
  7854. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  7855. */
  7856. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7857. /**
  7858. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  7859. */
  7860. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7861. /**
  7862. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  7863. * For assets with LODs, raised when all of the LODs are complete.
  7864. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7865. */
  7866. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7867. /**
  7868. * Observable raised when an error occurs.
  7869. */
  7870. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7871. /**
  7872. * Observable raised after the loader is disposed.
  7873. */
  7874. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7875. /**
  7876. * Observable raised after a loader extension is created.
  7877. * Set additional options for a loader extension in this event.
  7878. */
  7879. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7880. /**
  7881. * Defines if the loader should validate the asset.
  7882. */
  7883. this.validate = false;
  7884. /**
  7885. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  7886. */
  7887. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  7888. this._loader = null;
  7889. /**
  7890. * Name of the loader ("gltf")
  7891. */
  7892. this.name = "gltf";
  7893. /** @hidden */
  7894. this.extensions = {
  7895. ".gltf": { isBinary: false },
  7896. ".glb": { isBinary: true }
  7897. };
  7898. this._logIndentLevel = 0;
  7899. this._loggingEnabled = false;
  7900. /** @hidden */
  7901. this._log = this._logDisabled;
  7902. this._capturePerformanceCounters = false;
  7903. /** @hidden */
  7904. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  7905. /** @hidden */
  7906. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  7907. }
  7908. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  7909. /**
  7910. * Raised when the asset has been parsed
  7911. */
  7912. set: function (callback) {
  7913. if (this._onParsedObserver) {
  7914. this.onParsedObservable.remove(this._onParsedObserver);
  7915. }
  7916. this._onParsedObserver = this.onParsedObservable.add(callback);
  7917. },
  7918. enumerable: true,
  7919. configurable: true
  7920. });
  7921. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  7922. /**
  7923. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  7924. */
  7925. set: function (callback) {
  7926. if (this._onMeshLoadedObserver) {
  7927. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  7928. }
  7929. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  7930. },
  7931. enumerable: true,
  7932. configurable: true
  7933. });
  7934. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  7935. /**
  7936. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  7937. */
  7938. set: function (callback) {
  7939. if (this._onTextureLoadedObserver) {
  7940. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  7941. }
  7942. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  7943. },
  7944. enumerable: true,
  7945. configurable: true
  7946. });
  7947. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  7948. /**
  7949. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  7950. */
  7951. set: function (callback) {
  7952. if (this._onMaterialLoadedObserver) {
  7953. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  7954. }
  7955. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  7956. },
  7957. enumerable: true,
  7958. configurable: true
  7959. });
  7960. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  7961. /**
  7962. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  7963. */
  7964. set: function (callback) {
  7965. if (this._onCameraLoadedObserver) {
  7966. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  7967. }
  7968. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  7969. },
  7970. enumerable: true,
  7971. configurable: true
  7972. });
  7973. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  7974. /**
  7975. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  7976. * For assets with LODs, raised when all of the LODs are complete.
  7977. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  7978. */
  7979. set: function (callback) {
  7980. if (this._onCompleteObserver) {
  7981. this.onCompleteObservable.remove(this._onCompleteObserver);
  7982. }
  7983. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  7984. },
  7985. enumerable: true,
  7986. configurable: true
  7987. });
  7988. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  7989. /**
  7990. * Callback raised when an error occurs.
  7991. */
  7992. set: function (callback) {
  7993. if (this._onErrorObserver) {
  7994. this.onErrorObservable.remove(this._onErrorObserver);
  7995. }
  7996. this._onErrorObserver = this.onErrorObservable.add(callback);
  7997. },
  7998. enumerable: true,
  7999. configurable: true
  8000. });
  8001. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  8002. /**
  8003. * Callback raised after the loader is disposed.
  8004. */
  8005. set: function (callback) {
  8006. if (this._onDisposeObserver) {
  8007. this.onDisposeObservable.remove(this._onDisposeObserver);
  8008. }
  8009. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  8010. },
  8011. enumerable: true,
  8012. configurable: true
  8013. });
  8014. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  8015. /**
  8016. * Callback raised after a loader extension is created.
  8017. */
  8018. set: function (callback) {
  8019. if (this._onExtensionLoadedObserver) {
  8020. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  8021. }
  8022. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  8023. },
  8024. enumerable: true,
  8025. configurable: true
  8026. });
  8027. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  8028. /**
  8029. * Defines if the loader logging is enabled.
  8030. */
  8031. get: function () {
  8032. return this._loggingEnabled;
  8033. },
  8034. set: function (value) {
  8035. if (this._loggingEnabled === value) {
  8036. return;
  8037. }
  8038. this._loggingEnabled = value;
  8039. if (this._loggingEnabled) {
  8040. this._log = this._logEnabled;
  8041. }
  8042. else {
  8043. this._log = this._logDisabled;
  8044. }
  8045. },
  8046. enumerable: true,
  8047. configurable: true
  8048. });
  8049. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  8050. /**
  8051. * Defines if the loader should capture performance counters.
  8052. */
  8053. get: function () {
  8054. return this._capturePerformanceCounters;
  8055. },
  8056. set: function (value) {
  8057. if (this._capturePerformanceCounters === value) {
  8058. return;
  8059. }
  8060. this._capturePerformanceCounters = value;
  8061. if (this._capturePerformanceCounters) {
  8062. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  8063. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  8064. }
  8065. else {
  8066. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  8067. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  8068. }
  8069. },
  8070. enumerable: true,
  8071. configurable: true
  8072. });
  8073. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  8074. /**
  8075. * Callback raised after a loader extension is created.
  8076. */
  8077. set: function (callback) {
  8078. if (this._onValidatedObserver) {
  8079. this.onValidatedObservable.remove(this._onValidatedObserver);
  8080. }
  8081. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  8082. },
  8083. enumerable: true,
  8084. configurable: true
  8085. });
  8086. /**
  8087. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  8088. */
  8089. GLTFFileLoader.prototype.dispose = function () {
  8090. if (this._loader) {
  8091. this._loader.dispose();
  8092. this._loader = null;
  8093. }
  8094. this._clear();
  8095. this.onDisposeObservable.notifyObservers(undefined);
  8096. this.onDisposeObservable.clear();
  8097. };
  8098. /** @hidden */
  8099. GLTFFileLoader.prototype._clear = function () {
  8100. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  8101. this.onMeshLoadedObservable.clear();
  8102. this.onTextureLoadedObservable.clear();
  8103. this.onMaterialLoadedObservable.clear();
  8104. this.onCameraLoadedObservable.clear();
  8105. this.onCompleteObservable.clear();
  8106. this.onExtensionLoadedObservable.clear();
  8107. };
  8108. /** @hidden */
  8109. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  8110. var _this = this;
  8111. if (useArrayBuffer) {
  8112. if (this.useRangeRequests) {
  8113. if (this.validate) {
  8114. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  8115. }
  8116. var fileRequests_1 = new Array();
  8117. var aggregatedFileRequest_1 = {
  8118. abort: function () { return fileRequests_1.forEach(function (fileRequest) { return fileRequest.abort(); }); },
  8119. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  8120. };
  8121. var dataBuffer_1 = {
  8122. readAsync: function (byteOffset, byteLength) {
  8123. return new Promise(function (resolve, reject) {
  8124. fileRequests_1.push(scene._requestFile(url, function (data, webRequest) {
  8125. var contentRange = webRequest.getResponseHeader("Content-Range");
  8126. if (contentRange) {
  8127. dataBuffer_1.byteLength = Number(contentRange.split("/")[1]);
  8128. }
  8129. resolve(new Uint8Array(data));
  8130. }, onProgress, true, true, function (error) {
  8131. reject(error);
  8132. }, function (webRequest) {
  8133. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  8134. }));
  8135. });
  8136. },
  8137. byteLength: 0
  8138. };
  8139. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer_1)).then(function (loaderData) {
  8140. aggregatedFileRequest_1.onCompleteObservable.notifyObservers(aggregatedFileRequest_1);
  8141. onSuccess(loaderData);
  8142. }, onError);
  8143. return aggregatedFileRequest_1;
  8144. }
  8145. return scene._requestFile(url, function (data, request) {
  8146. var arrayBuffer = data;
  8147. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8148. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  8149. byteLength: arrayBuffer.byteLength
  8150. })).then(function (loaderData) {
  8151. onSuccess(loaderData, request);
  8152. }, onError);
  8153. }, onProgress, true, true, onError);
  8154. }
  8155. return scene._requestFile(url, function (data, response) {
  8156. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  8157. onSuccess({ json: _this._parseJson(data) }, response);
  8158. }, onProgress, true, false, onError);
  8159. };
  8160. /** @hidden */
  8161. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  8162. var _this = this;
  8163. return scene._readFile(file, function (data) {
  8164. _this._validate(scene, data, "file:", file.name);
  8165. if (useArrayBuffer) {
  8166. var arrayBuffer_1 = data;
  8167. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  8168. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  8169. byteLength: arrayBuffer_1.byteLength
  8170. })).then(onSuccess, onError);
  8171. }
  8172. else {
  8173. onSuccess({ json: _this._parseJson(data) });
  8174. }
  8175. }, onProgress, useArrayBuffer, onError);
  8176. };
  8177. /** @hidden */
  8178. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  8179. var _this = this;
  8180. return Promise.resolve().then(function () {
  8181. _this.onParsedObservable.notifyObservers(data);
  8182. _this.onParsedObservable.clear();
  8183. _this._log("Loading " + (fileName || ""));
  8184. _this._loader = _this._getLoader(data);
  8185. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  8186. });
  8187. };
  8188. /** @hidden */
  8189. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  8190. var _this = this;
  8191. return Promise.resolve().then(function () {
  8192. _this.onParsedObservable.notifyObservers(data);
  8193. _this.onParsedObservable.clear();
  8194. _this._log("Loading " + (fileName || ""));
  8195. _this._loader = _this._getLoader(data);
  8196. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  8197. });
  8198. };
  8199. /** @hidden */
  8200. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  8201. var _this = this;
  8202. return Promise.resolve().then(function () {
  8203. _this.onParsedObservable.notifyObservers(data);
  8204. _this.onParsedObservable.clear();
  8205. _this._log("Loading " + (fileName || ""));
  8206. _this._loader = _this._getLoader(data);
  8207. // Get materials/textures when loading to add to container
  8208. var materials = [];
  8209. _this.onMaterialLoadedObservable.add(function (material) {
  8210. materials.push(material);
  8211. });
  8212. var textures = [];
  8213. _this.onTextureLoadedObservable.add(function (texture) {
  8214. textures.push(texture);
  8215. });
  8216. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  8217. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  8218. Array.prototype.push.apply(container.meshes, result.meshes);
  8219. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  8220. Array.prototype.push.apply(container.skeletons, result.skeletons);
  8221. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  8222. Array.prototype.push.apply(container.materials, materials);
  8223. Array.prototype.push.apply(container.textures, textures);
  8224. Array.prototype.push.apply(container.lights, result.lights);
  8225. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  8226. return container;
  8227. });
  8228. });
  8229. };
  8230. /** @hidden */
  8231. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  8232. return data.indexOf("asset") !== -1 && data.indexOf("version") !== -1;
  8233. };
  8234. /** @hidden */
  8235. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  8236. this._validate(scene, data);
  8237. return { json: this._parseJson(data) };
  8238. };
  8239. /** @hidden */
  8240. GLTFFileLoader.prototype.createPlugin = function () {
  8241. return new GLTFFileLoader();
  8242. };
  8243. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  8244. /**
  8245. * The loader state or null if the loader is not active.
  8246. */
  8247. get: function () {
  8248. return this._loader ? this._loader.state : null;
  8249. },
  8250. enumerable: true,
  8251. configurable: true
  8252. });
  8253. /**
  8254. * Returns a promise that resolves when the asset is completely loaded.
  8255. * @returns a promise that resolves when the asset is completely loaded.
  8256. */
  8257. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  8258. var _this = this;
  8259. return new Promise(function (resolve, reject) {
  8260. _this.onCompleteObservable.addOnce(function () {
  8261. resolve();
  8262. });
  8263. _this.onErrorObservable.addOnce(function (reason) {
  8264. reject(reason);
  8265. });
  8266. });
  8267. };
  8268. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  8269. var _this = this;
  8270. if (rootUrl === void 0) { rootUrl = ""; }
  8271. if (fileName === void 0) { fileName = ""; }
  8272. if (!this.validate) {
  8273. return;
  8274. }
  8275. this._startPerformanceCounter("Validate JSON");
  8276. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  8277. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  8278. }).then(function (result) {
  8279. _this._endPerformanceCounter("Validate JSON");
  8280. _this.onValidatedObservable.notifyObservers(result);
  8281. _this.onValidatedObservable.clear();
  8282. }, function (reason) {
  8283. _this._endPerformanceCounter("Validate JSON");
  8284. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  8285. _this.onValidatedObservable.clear();
  8286. });
  8287. };
  8288. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  8289. var asset = loaderData.json.asset || {};
  8290. this._log("Asset version: " + asset.version);
  8291. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  8292. asset.generator && this._log("Asset generator: " + asset.generator);
  8293. var version = GLTFFileLoader._parseVersion(asset.version);
  8294. if (!version) {
  8295. throw new Error("Invalid version: " + asset.version);
  8296. }
  8297. if (asset.minVersion !== undefined) {
  8298. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  8299. if (!minVersion) {
  8300. throw new Error("Invalid minimum version: " + asset.minVersion);
  8301. }
  8302. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  8303. throw new Error("Incompatible minimum version: " + asset.minVersion);
  8304. }
  8305. }
  8306. var createLoaders = {
  8307. 1: GLTFFileLoader._CreateGLTF1Loader,
  8308. 2: GLTFFileLoader._CreateGLTF2Loader
  8309. };
  8310. var createLoader = createLoaders[version.major];
  8311. if (!createLoader) {
  8312. throw new Error("Unsupported version: " + asset.version);
  8313. }
  8314. return createLoader(this);
  8315. };
  8316. GLTFFileLoader.prototype._parseJson = function (json) {
  8317. this._startPerformanceCounter("Parse JSON");
  8318. this._log("JSON length: " + json.length);
  8319. var parsed = JSON.parse(json);
  8320. this._endPerformanceCounter("Parse JSON");
  8321. return parsed;
  8322. };
  8323. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  8324. var _this = this;
  8325. this._startPerformanceCounter("Unpack Binary");
  8326. // Read magic + version + length + json length + json format
  8327. return dataReader.loadAsync(20).then(function () {
  8328. var Binary = {
  8329. Magic: 0x46546C67
  8330. };
  8331. var magic = dataReader.readUint32();
  8332. if (magic !== Binary.Magic) {
  8333. throw new Error("Unexpected magic: " + magic);
  8334. }
  8335. var version = dataReader.readUint32();
  8336. if (_this.loggingEnabled) {
  8337. _this._log("Binary version: " + version);
  8338. }
  8339. var length = dataReader.readUint32();
  8340. if (dataReader.buffer.byteLength != 0 && length !== dataReader.buffer.byteLength) {
  8341. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  8342. }
  8343. var unpacked;
  8344. switch (version) {
  8345. case 1: {
  8346. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  8347. break;
  8348. }
  8349. case 2: {
  8350. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  8351. break;
  8352. }
  8353. default: {
  8354. throw new Error("Unsupported version: " + version);
  8355. }
  8356. }
  8357. _this._endPerformanceCounter("Unpack Binary");
  8358. return unpacked;
  8359. });
  8360. };
  8361. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  8362. var ContentFormat = {
  8363. JSON: 0
  8364. };
  8365. var contentLength = dataReader.readUint32();
  8366. var contentFormat = dataReader.readUint32();
  8367. if (contentFormat !== ContentFormat.JSON) {
  8368. throw new Error("Unexpected content format: " + contentFormat);
  8369. }
  8370. var bodyLength = length - dataReader.byteOffset;
  8371. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  8372. if (bodyLength !== 0) {
  8373. var startByteOffset_1 = dataReader.byteOffset;
  8374. data.bin = {
  8375. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  8376. byteLength: bodyLength
  8377. };
  8378. }
  8379. return Promise.resolve(data);
  8380. };
  8381. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  8382. var _this = this;
  8383. var ChunkFormat = {
  8384. JSON: 0x4E4F534A,
  8385. BIN: 0x004E4942
  8386. };
  8387. // Read the JSON chunk header.
  8388. var chunkLength = dataReader.readUint32();
  8389. var chunkFormat = dataReader.readUint32();
  8390. if (chunkFormat !== ChunkFormat.JSON) {
  8391. throw new Error("First chunk format is not JSON");
  8392. }
  8393. // Bail if there are no other chunks.
  8394. if (dataReader.byteOffset + chunkLength === length) {
  8395. return dataReader.loadAsync(chunkLength).then(function () {
  8396. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8397. });
  8398. }
  8399. // Read the JSON chunk and the length and type of the next chunk.
  8400. return dataReader.loadAsync(chunkLength + 8).then(function () {
  8401. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  8402. var readAsync = function () {
  8403. var chunkLength = dataReader.readUint32();
  8404. var chunkFormat = dataReader.readUint32();
  8405. switch (chunkFormat) {
  8406. case ChunkFormat.JSON: {
  8407. throw new Error("Unexpected JSON chunk");
  8408. }
  8409. case ChunkFormat.BIN: {
  8410. var startByteOffset_2 = dataReader.byteOffset;
  8411. data.bin = {
  8412. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  8413. byteLength: chunkLength
  8414. };
  8415. dataReader.skipBytes(chunkLength);
  8416. break;
  8417. }
  8418. default: {
  8419. // ignore unrecognized chunkFormat
  8420. dataReader.skipBytes(chunkLength);
  8421. break;
  8422. }
  8423. }
  8424. if (dataReader.byteOffset !== length) {
  8425. return dataReader.loadAsync(8).then(readAsync);
  8426. }
  8427. return Promise.resolve(data);
  8428. };
  8429. return readAsync();
  8430. });
  8431. };
  8432. GLTFFileLoader._parseVersion = function (version) {
  8433. if (version === "1.0" || version === "1.0.1") {
  8434. return {
  8435. major: 1,
  8436. minor: 0
  8437. };
  8438. }
  8439. var match = (version + "").match(/^(\d+)\.(\d+)/);
  8440. if (!match) {
  8441. return null;
  8442. }
  8443. return {
  8444. major: parseInt(match[1]),
  8445. minor: parseInt(match[2])
  8446. };
  8447. };
  8448. GLTFFileLoader._compareVersion = function (a, b) {
  8449. if (a.major > b.major) {
  8450. return 1;
  8451. }
  8452. if (a.major < b.major) {
  8453. return -1;
  8454. }
  8455. if (a.minor > b.minor) {
  8456. return 1;
  8457. }
  8458. if (a.minor < b.minor) {
  8459. return -1;
  8460. }
  8461. return 0;
  8462. };
  8463. /** @hidden */
  8464. GLTFFileLoader.prototype._logOpen = function (message) {
  8465. this._log(message);
  8466. this._logIndentLevel++;
  8467. };
  8468. /** @hidden */
  8469. GLTFFileLoader.prototype._logClose = function () {
  8470. --this._logIndentLevel;
  8471. };
  8472. GLTFFileLoader.prototype._logEnabled = function (message) {
  8473. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  8474. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  8475. };
  8476. GLTFFileLoader.prototype._logDisabled = function (message) {
  8477. };
  8478. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  8479. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  8480. };
  8481. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  8482. };
  8483. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  8484. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  8485. };
  8486. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  8487. };
  8488. // ----------
  8489. // V1 options
  8490. // ----------
  8491. /**
  8492. * 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.
  8493. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  8494. * Defaults to true.
  8495. * @hidden
  8496. */
  8497. GLTFFileLoader.IncrementalLoading = true;
  8498. /**
  8499. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  8500. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  8501. * @hidden
  8502. */
  8503. GLTFFileLoader.HomogeneousCoordinates = false;
  8504. GLTFFileLoader._logSpaces = " ";
  8505. return GLTFFileLoader;
  8506. }());
  8507. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  8508. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  8509. }
  8510. /***/ }),
  8511. /***/ "./glTF/glTFValidation.ts":
  8512. /*!********************************!*\
  8513. !*** ./glTF/glTFValidation.ts ***!
  8514. \********************************/
  8515. /*! exports provided: GLTFValidation */
  8516. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8517. "use strict";
  8518. __webpack_require__.r(__webpack_exports__);
  8519. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  8520. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  8521. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  8522. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  8523. var options = {
  8524. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  8525. };
  8526. if (fileName) {
  8527. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  8528. }
  8529. return (data instanceof ArrayBuffer)
  8530. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  8531. : GLTFValidator.validateString(data, options);
  8532. }
  8533. /**
  8534. * The worker function that gets converted to a blob url to pass into a worker.
  8535. */
  8536. function workerFunc() {
  8537. var pendingExternalResources = [];
  8538. onmessage = function (message) {
  8539. var data = message.data;
  8540. switch (data.id) {
  8541. case "init": {
  8542. importScripts(data.url);
  8543. break;
  8544. }
  8545. case "validate": {
  8546. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  8547. var index = pendingExternalResources.length;
  8548. pendingExternalResources.push({ resolve: resolve, reject: reject });
  8549. postMessage({ id: "getExternalResource", index: index, uri: uri });
  8550. }); }).then(function (value) {
  8551. postMessage({ id: "validate.resolve", value: value });
  8552. }, function (reason) {
  8553. postMessage({ id: "validate.reject", reason: reason });
  8554. });
  8555. break;
  8556. }
  8557. case "getExternalResource.resolve": {
  8558. pendingExternalResources[data.index].resolve(data.value);
  8559. break;
  8560. }
  8561. case "getExternalResource.reject": {
  8562. pendingExternalResources[data.index].reject(data.reason);
  8563. break;
  8564. }
  8565. }
  8566. };
  8567. }
  8568. /**
  8569. * glTF validation
  8570. */
  8571. var GLTFValidation = /** @class */ (function () {
  8572. function GLTFValidation() {
  8573. }
  8574. /**
  8575. * Validate a glTF asset using the glTF-Validator.
  8576. * @param data The JSON of a glTF or the array buffer of a binary glTF
  8577. * @param rootUrl The root url for the glTF
  8578. * @param fileName The file name for the glTF
  8579. * @param getExternalResource The callback to get external resources for the glTF validator
  8580. * @returns A promise that resolves with the glTF validation results once complete
  8581. */
  8582. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  8583. var _this = this;
  8584. if (typeof Worker === "function") {
  8585. return new Promise(function (resolve, reject) {
  8586. var workerContent = validateAsync + "(" + workerFunc + ")()";
  8587. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  8588. var worker = new Worker(workerBlobUrl);
  8589. var onError = function (error) {
  8590. worker.removeEventListener("error", onError);
  8591. worker.removeEventListener("message", onMessage);
  8592. reject(error);
  8593. };
  8594. var onMessage = function (message) {
  8595. var data = message.data;
  8596. switch (data.id) {
  8597. case "getExternalResource": {
  8598. getExternalResource(data.uri).then(function (value) {
  8599. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  8600. }, function (reason) {
  8601. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  8602. });
  8603. break;
  8604. }
  8605. case "validate.resolve": {
  8606. worker.removeEventListener("error", onError);
  8607. worker.removeEventListener("message", onMessage);
  8608. resolve(data.value);
  8609. break;
  8610. }
  8611. case "validate.reject": {
  8612. worker.removeEventListener("error", onError);
  8613. worker.removeEventListener("message", onMessage);
  8614. reject(data.reason);
  8615. }
  8616. }
  8617. };
  8618. worker.addEventListener("error", onError);
  8619. worker.addEventListener("message", onMessage);
  8620. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  8621. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  8622. });
  8623. }
  8624. else {
  8625. if (!this._LoadScriptPromise) {
  8626. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  8627. }
  8628. return this._LoadScriptPromise.then(function () {
  8629. return validateAsync(data, rootUrl, fileName, getExternalResource);
  8630. });
  8631. }
  8632. };
  8633. /**
  8634. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  8635. */
  8636. GLTFValidation.Configuration = {
  8637. url: "https://preview.babylonjs.com/gltf_validator.js"
  8638. };
  8639. return GLTFValidation;
  8640. }());
  8641. /***/ }),
  8642. /***/ "./glTF/index.ts":
  8643. /*!***********************!*\
  8644. !*** ./glTF/index.ts ***!
  8645. \***********************/
  8646. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2 */
  8647. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8648. "use strict";
  8649. __webpack_require__.r(__webpack_exports__);
  8650. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8651. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8652. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8653. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8654. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8655. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  8656. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8657. /* harmony import */ var _1_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./1.0 */ "./glTF/1.0/index.ts");
  8658. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _1_0__WEBPACK_IMPORTED_MODULE_2__; });
  8659. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  8660. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_3__; });
  8661. /***/ }),
  8662. /***/ "./index.ts":
  8663. /*!******************!*\
  8664. !*** ./index.ts ***!
  8665. \******************/
  8666. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF1, GLTF2, STLFileLoader, MTLFileLoader, OBJFileLoader */
  8667. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8668. "use strict";
  8669. __webpack_require__.r(__webpack_exports__);
  8670. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  8671. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8672. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8673. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8674. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8675. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  8676. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF1"]; });
  8677. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_0__["GLTF2"]; });
  8678. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  8679. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["MTLFileLoader"]; });
  8680. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_1__["OBJFileLoader"]; });
  8681. /* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./STL */ "./STL/index.ts");
  8682. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_2__["STLFileLoader"]; });
  8683. /***/ }),
  8684. /***/ "./legacy/legacy-glTF.ts":
  8685. /*!*******************************!*\
  8686. !*** ./legacy/legacy-glTF.ts ***!
  8687. \*******************************/
  8688. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  8689. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8690. "use strict";
  8691. __webpack_require__.r(__webpack_exports__);
  8692. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  8693. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  8694. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  8695. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  8696. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  8697. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  8698. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8699. /**
  8700. * This is the entry point for the UMD module.
  8701. * The entry point for a future ESM package should be index.ts
  8702. */
  8703. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8704. if (typeof globalObject !== "undefined") {
  8705. globalObject.BABYLON = globalObject.BABYLON || {};
  8706. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  8707. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  8708. }
  8709. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  8710. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  8711. }
  8712. }
  8713. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8714. /***/ }),
  8715. /***/ "./legacy/legacy-glTF1.ts":
  8716. /*!********************************!*\
  8717. !*** ./legacy/legacy-glTF1.ts ***!
  8718. \********************************/
  8719. /*! exports provided: GLTF1 */
  8720. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8721. "use strict";
  8722. __webpack_require__.r(__webpack_exports__);
  8723. /* 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");
  8724. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__; });
  8725. /**
  8726. * This is the entry point for the UMD module.
  8727. * The entry point for a future ESM package should be index.ts
  8728. */
  8729. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8730. if (typeof globalObject !== "undefined") {
  8731. globalObject.BABYLON = globalObject.BABYLON || {};
  8732. globalObject.BABYLON.GLTF1 = globalObject.BABYLON.GLTF1 || {};
  8733. for (var key in _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__) {
  8734. globalObject.BABYLON.GLTF1[key] = _glTF_1_0__WEBPACK_IMPORTED_MODULE_0__[key];
  8735. }
  8736. }
  8737. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8738. /***/ }),
  8739. /***/ "./legacy/legacy-glTF2.ts":
  8740. /*!********************************!*\
  8741. !*** ./legacy/legacy-glTF2.ts ***!
  8742. \********************************/
  8743. /*! exports provided: GLTF2 */
  8744. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8745. "use strict";
  8746. __webpack_require__.r(__webpack_exports__);
  8747. /* 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");
  8748. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  8749. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  8750. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  8751. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  8752. /**
  8753. * This is the entry point for the UMD module.
  8754. * The entry point for a future ESM package should be index.ts
  8755. */
  8756. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8757. if (typeof globalObject !== "undefined") {
  8758. globalObject.BABYLON = globalObject.BABYLON || {};
  8759. var BABYLON = globalObject.BABYLON;
  8760. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  8761. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  8762. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  8763. var keys = [];
  8764. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  8765. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  8766. keys.push(key);
  8767. }
  8768. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  8769. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  8770. keys.push(key);
  8771. }
  8772. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  8773. // Prevent Reassignment.
  8774. if (keys.indexOf(key) > -1) {
  8775. continue;
  8776. }
  8777. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  8778. }
  8779. }
  8780. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8781. /***/ }),
  8782. /***/ "./legacy/legacy-objFileLoader.ts":
  8783. /*!****************************************!*\
  8784. !*** ./legacy/legacy-objFileLoader.ts ***!
  8785. \****************************************/
  8786. /*! exports provided: MTLFileLoader, OBJFileLoader */
  8787. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8788. "use strict";
  8789. __webpack_require__.r(__webpack_exports__);
  8790. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  8791. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["MTLFileLoader"]; });
  8792. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJFileLoader"]; });
  8793. /**
  8794. * This is the entry point for the UMD module.
  8795. * The entry point for a future ESM package should be index.ts
  8796. */
  8797. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8798. if (typeof globalObject !== "undefined") {
  8799. for (var key in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  8800. globalObject.BABYLON[key] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[key];
  8801. }
  8802. }
  8803. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8804. /***/ }),
  8805. /***/ "./legacy/legacy-stlFileLoader.ts":
  8806. /*!****************************************!*\
  8807. !*** ./legacy/legacy-stlFileLoader.ts ***!
  8808. \****************************************/
  8809. /*! exports provided: STLFileLoader */
  8810. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8811. "use strict";
  8812. __webpack_require__.r(__webpack_exports__);
  8813. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _STL__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../STL */ "./STL/index.ts");
  8814. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _STL__WEBPACK_IMPORTED_MODULE_0__["STLFileLoader"]; });
  8815. /**
  8816. * This is the entry point for the UMD module.
  8817. * The entry point for a future ESM package should be index.ts
  8818. */
  8819. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  8820. if (typeof globalObject !== "undefined") {
  8821. for (var key in _STL__WEBPACK_IMPORTED_MODULE_0__) {
  8822. globalObject.BABYLON[key] = _STL__WEBPACK_IMPORTED_MODULE_0__[key];
  8823. }
  8824. }
  8825. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  8826. /***/ }),
  8827. /***/ "./legacy/legacy.ts":
  8828. /*!**************************!*\
  8829. !*** ./legacy/legacy.ts ***!
  8830. \**************************/
  8831. /*! exports provided: GLTF1, GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, MTLFileLoader, OBJFileLoader, STLFileLoader */
  8832. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8833. "use strict";
  8834. __webpack_require__.r(__webpack_exports__);
  8835. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  8836. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  8837. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"]; });
  8838. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"]; });
  8839. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"]; });
  8840. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]; });
  8841. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  8842. /* harmony import */ var _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-glTF1 */ "./legacy/legacy-glTF1.ts");
  8843. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF1", function() { return _legacy_glTF1__WEBPACK_IMPORTED_MODULE_2__["GLTF1"]; });
  8844. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  8845. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_3__["GLTF2"]; });
  8846. /* harmony import */ var _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./legacy-objFileLoader */ "./legacy/legacy-objFileLoader.ts");
  8847. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MTLFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["MTLFileLoader"]; });
  8848. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJFileLoader", function() { return _legacy_objFileLoader__WEBPACK_IMPORTED_MODULE_4__["OBJFileLoader"]; });
  8849. /* harmony import */ var _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./legacy-stlFileLoader */ "./legacy/legacy-stlFileLoader.ts");
  8850. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLFileLoader", function() { return _legacy_stlFileLoader__WEBPACK_IMPORTED_MODULE_5__["STLFileLoader"]; });
  8851. /***/ }),
  8852. /***/ "babylonjs/Misc/tools":
  8853. /*!****************************************************************************************************!*\
  8854. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  8855. \****************************************************************************************************/
  8856. /*! no static exports found */
  8857. /***/ (function(module, exports) {
  8858. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  8859. /***/ })
  8860. /******/ });
  8861. });
  8862. //# sourceMappingURL=babylonjs.loaders.js.map