babylonjs.loaders.js 343 KB

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