babylon.glTF2FileLoader.js 294 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-loaders", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-loaders"] = factory(require("babylonjs"));
  8. else
  9. root["LOADERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-glTF2FileLoader.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/webpack/buildin/global.js":
  99. /*!***********************************!*\
  100. !*** (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 || new Function("return 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. /***/ "./glTF/2.0/Extensions/EXT_lights_image_based.ts":
  122. /*!*******************************************************!*\
  123. !*** ./glTF/2.0/Extensions/EXT_lights_image_based.ts ***!
  124. \*******************************************************/
  125. /*! exports provided: EXT_lights_image_based */
  126. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  127. "use strict";
  128. __webpack_require__.r(__webpack_exports__);
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return EXT_lights_image_based; });
  130. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.scalar */ "babylonjs/Misc/tools");
  131. /* harmony import */ var babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  133. var NAME = "EXT_lights_image_based";
  134. /**
  135. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
  136. */
  137. var EXT_lights_image_based = /** @class */ (function () {
  138. /** @hidden */
  139. function EXT_lights_image_based(loader) {
  140. /**
  141. * The name of this extension.
  142. */
  143. this.name = NAME;
  144. this._loader = loader;
  145. this.enabled = this._loader.isExtensionUsed(NAME);
  146. }
  147. /** @hidden */
  148. EXT_lights_image_based.prototype.dispose = function () {
  149. delete this._loader;
  150. delete this._lights;
  151. };
  152. /** @hidden */
  153. EXT_lights_image_based.prototype.onLoading = function () {
  154. var extensions = this._loader.gltf.extensions;
  155. if (extensions && extensions[this.name]) {
  156. var extension = extensions[this.name];
  157. this._lights = extension.lights;
  158. }
  159. };
  160. /** @hidden */
  161. EXT_lights_image_based.prototype.loadSceneAsync = function (context, scene) {
  162. var _this = this;
  163. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  164. var promises = new Array();
  165. promises.push(_this._loader.loadSceneAsync(context, scene));
  166. _this._loader.logOpen("" + extensionContext);
  167. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/light", _this._lights, extension.light);
  168. promises.push(_this._loadLightAsync("/extensions/" + _this.name + "/lights/" + extension.light, light).then(function (texture) {
  169. _this._loader.babylonScene.environmentTexture = texture;
  170. }));
  171. _this._loader.logClose();
  172. return Promise.all(promises).then(function () { });
  173. });
  174. };
  175. EXT_lights_image_based.prototype._loadLightAsync = function (context, light) {
  176. var _this = this;
  177. if (!light._loaded) {
  178. var promises = new Array();
  179. this._loader.logOpen("" + context);
  180. var imageData_1 = new Array(light.specularImages.length);
  181. var _loop_1 = function (mipmap) {
  182. var faces = light.specularImages[mipmap];
  183. imageData_1[mipmap] = new Array(faces.length);
  184. var _loop_2 = function (face) {
  185. var specularImageContext = context + "/specularImages/" + mipmap + "/" + face;
  186. this_1._loader.logOpen("" + specularImageContext);
  187. var index = faces[face];
  188. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(specularImageContext, this_1._loader.gltf.images, index);
  189. promises.push(this_1._loader.loadImageAsync("/images/" + index, image).then(function (data) {
  190. imageData_1[mipmap][face] = data;
  191. }));
  192. this_1._loader.logClose();
  193. };
  194. for (var face = 0; face < faces.length; face++) {
  195. _loop_2(face);
  196. }
  197. };
  198. var this_1 = this;
  199. for (var mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
  200. _loop_1(mipmap);
  201. }
  202. this._loader.logClose();
  203. light._loaded = Promise.all(promises).then(function () {
  204. var babylonTexture = new babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["RawCubeTexture"](_this._loader.babylonScene, null, light.specularImageSize);
  205. babylonTexture.name = light.name || "environment";
  206. light._babylonTexture = babylonTexture;
  207. if (light.intensity != undefined) {
  208. babylonTexture.level = light.intensity;
  209. }
  210. if (light.rotation) {
  211. var rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(light.rotation);
  212. // Invert the rotation so that positive rotation is counter-clockwise.
  213. if (!_this._loader.babylonScene.useRightHandedSystem) {
  214. rotation = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Inverse(rotation);
  215. }
  216. babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
  217. }
  218. var sphericalHarmonics = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalHarmonics"].FromArray(light.irradianceCoefficients);
  219. sphericalHarmonics.scaleInPlace(light.intensity);
  220. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  221. var sphericalPolynomial = babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["SphericalPolynomial"].FromHarmonics(sphericalHarmonics);
  222. // Compute the lod generation scale to fit exactly to the number of levels available.
  223. var lodGenerationScale = (imageData_1.length - 1) / babylonjs_Maths_math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Log2(light.specularImageSize);
  224. return babylonTexture.updateRGBDAsync(imageData_1, sphericalPolynomial, lodGenerationScale);
  225. });
  226. }
  227. return light._loaded.then(function () {
  228. return light._babylonTexture;
  229. });
  230. };
  231. return EXT_lights_image_based;
  232. }());
  233. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_lights_image_based(loader); });
  234. /***/ }),
  235. /***/ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts":
  236. /*!********************************************************!*\
  237. !*** ./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts ***!
  238. \********************************************************/
  239. /*! exports provided: EXT_mesh_gpu_instancing */
  240. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  241. "use strict";
  242. __webpack_require__.r(__webpack_exports__);
  243. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return EXT_mesh_gpu_instancing; });
  244. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  245. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  246. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  247. var NAME = "EXT_mesh_gpu_instancing";
  248. /**
  249. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1691)
  250. * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
  251. * !!! Experimental Extension Subject to Changes !!!
  252. */
  253. var EXT_mesh_gpu_instancing = /** @class */ (function () {
  254. /** @hidden */
  255. function EXT_mesh_gpu_instancing(loader) {
  256. /**
  257. * The name of this extension.
  258. */
  259. this.name = NAME;
  260. this._loader = loader;
  261. this.enabled = this._loader.isExtensionUsed(NAME);
  262. }
  263. /** @hidden */
  264. EXT_mesh_gpu_instancing.prototype.dispose = function () {
  265. delete this._loader;
  266. };
  267. /** @hidden */
  268. EXT_mesh_gpu_instancing.prototype.loadNodeAsync = function (context, node, assign) {
  269. var _this = this;
  270. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  271. _this._loader._disableInstancedMesh++;
  272. var promise = _this._loader.loadNodeAsync("/nodes/" + node.index, node, assign);
  273. _this._loader._disableInstancedMesh--;
  274. if (!node._primitiveBabylonMeshes) {
  275. return promise;
  276. }
  277. var promises = new Array();
  278. var instanceCount = 0;
  279. var loadAttribute = function (attribute) {
  280. if (extension.attributes[attribute] == undefined) {
  281. promises.push(Promise.resolve(null));
  282. return;
  283. }
  284. var accessor = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/attributes/" + attribute, _this._loader.gltf.accessors, extension.attributes[attribute]);
  285. promises.push(_this._loader._loadFloatAccessorAsync("/accessors/" + accessor.bufferView, accessor));
  286. if (instanceCount === 0) {
  287. instanceCount = accessor.count;
  288. }
  289. else if (instanceCount !== accessor.count) {
  290. throw new Error(extensionContext + "/attributes: Instance buffer accessors do not have the same count.");
  291. }
  292. };
  293. loadAttribute("TRANSLATION");
  294. loadAttribute("ROTATION");
  295. loadAttribute("SCALE");
  296. return promise.then(function (babylonTransformNode) {
  297. return Promise.all(promises).then(function (_a) {
  298. var translationBuffer = _a[0], rotationBuffer = _a[1], scaleBuffer = _a[2];
  299. var matrices = new Float32Array(instanceCount * 16);
  300. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0].copyFromFloats(0, 0, 0); // translation
  301. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
  302. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1].copyFromFloats(1, 1, 1); // scale
  303. for (var i = 0; i < instanceCount; ++i) {
  304. translationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(translationBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0]);
  305. rotationBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArrayToRef(rotationBuffer, i * 4, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0]);
  306. scaleBuffer && babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArrayToRef(scaleBuffer, i * 3, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1]);
  307. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0]);
  308. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0].copyToArray(matrices, i * 16);
  309. }
  310. for (var _i = 0, _b = node._primitiveBabylonMeshes; _i < _b.length; _i++) {
  311. var babylonMesh = _b[_i];
  312. babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
  313. }
  314. return babylonTransformNode;
  315. });
  316. });
  317. });
  318. };
  319. return EXT_mesh_gpu_instancing;
  320. }());
  321. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new EXT_mesh_gpu_instancing(loader); });
  322. /***/ }),
  323. /***/ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts":
  324. /*!*************************************************!*\
  325. !*** ./glTF/2.0/Extensions/ExtrasAsMetadata.ts ***!
  326. \*************************************************/
  327. /*! exports provided: ExtrasAsMetadata */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return ExtrasAsMetadata; });
  332. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  333. var NAME = "ExtrasAsMetadata";
  334. /**
  335. * Store glTF extras (if present) in BJS objects' metadata
  336. */
  337. var ExtrasAsMetadata = /** @class */ (function () {
  338. /** @hidden */
  339. function ExtrasAsMetadata(loader) {
  340. /**
  341. * The name of this extension.
  342. */
  343. this.name = NAME;
  344. /**
  345. * Defines whether this extension is enabled.
  346. */
  347. this.enabled = true;
  348. this._loader = loader;
  349. }
  350. ExtrasAsMetadata.prototype._assignExtras = function (babylonObject, gltfProp) {
  351. if (gltfProp.extras && Object.keys(gltfProp.extras).length > 0) {
  352. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  353. var gltf = (metadata.gltf = metadata.gltf || {});
  354. gltf.extras = gltfProp.extras;
  355. }
  356. };
  357. /** @hidden */
  358. ExtrasAsMetadata.prototype.dispose = function () {
  359. delete this._loader;
  360. };
  361. /** @hidden */
  362. ExtrasAsMetadata.prototype.loadNodeAsync = function (context, node, assign) {
  363. var _this = this;
  364. return this._loader.loadNodeAsync(context, node, function (babylonTransformNode) {
  365. _this._assignExtras(babylonTransformNode, node);
  366. assign(babylonTransformNode);
  367. });
  368. };
  369. /** @hidden */
  370. ExtrasAsMetadata.prototype.loadCameraAsync = function (context, camera, assign) {
  371. var _this = this;
  372. return this._loader.loadCameraAsync(context, camera, function (babylonCamera) {
  373. _this._assignExtras(babylonCamera, camera);
  374. assign(babylonCamera);
  375. });
  376. };
  377. /** @hidden */
  378. ExtrasAsMetadata.prototype.createMaterial = function (context, material, babylonDrawMode) {
  379. var babylonMaterial = this._loader.createMaterial(context, material, babylonDrawMode);
  380. this._assignExtras(babylonMaterial, material);
  381. return babylonMaterial;
  382. };
  383. return ExtrasAsMetadata;
  384. }());
  385. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new ExtrasAsMetadata(loader); });
  386. /***/ }),
  387. /***/ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts":
  388. /*!***********************************************************!*\
  389. !*** ./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts ***!
  390. \***********************************************************/
  391. /*! exports provided: KHR_draco_mesh_compression */
  392. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  393. "use strict";
  394. __webpack_require__.r(__webpack_exports__);
  395. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return KHR_draco_mesh_compression; });
  396. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/Compression/dracoCompression */ "babylonjs/Misc/tools");
  397. /* harmony import */ var babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__);
  398. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  399. var NAME = "KHR_draco_mesh_compression";
  400. /**
  401. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression)
  402. */
  403. var KHR_draco_mesh_compression = /** @class */ (function () {
  404. /** @hidden */
  405. function KHR_draco_mesh_compression(loader) {
  406. /**
  407. * The name of this extension.
  408. */
  409. this.name = NAME;
  410. this._loader = loader;
  411. this.enabled = babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].DecoderAvailable && this._loader.isExtensionUsed(NAME);
  412. }
  413. /** @hidden */
  414. KHR_draco_mesh_compression.prototype.dispose = function () {
  415. delete this.dracoCompression;
  416. delete this._loader;
  417. };
  418. /** @hidden */
  419. KHR_draco_mesh_compression.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  420. var _this = this;
  421. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  422. if (primitive.mode != undefined) {
  423. if (primitive.mode !== 5 /* TRIANGLE_STRIP */ &&
  424. primitive.mode !== 4 /* TRIANGLES */) {
  425. throw new Error(context + ": Unsupported mode " + primitive.mode);
  426. }
  427. // TODO: handle triangle strips
  428. if (primitive.mode === 5 /* TRIANGLE_STRIP */) {
  429. throw new Error(context + ": Mode " + primitive.mode + " is not currently supported");
  430. }
  431. }
  432. var attributes = {};
  433. var loadAttribute = function (name, kind) {
  434. var uniqueId = extension.attributes[name];
  435. if (uniqueId == undefined) {
  436. return;
  437. }
  438. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  439. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  440. babylonMesh._delayInfo.push(kind);
  441. }
  442. attributes[kind] = uniqueId;
  443. };
  444. loadAttribute("POSITION", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  445. loadAttribute("NORMAL", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  446. loadAttribute("TANGENT", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  447. loadAttribute("TEXCOORD_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  448. loadAttribute("TEXCOORD_1", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  449. loadAttribute("JOINTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  450. loadAttribute("WEIGHTS_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  451. loadAttribute("COLOR_0", babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind);
  452. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._loader.gltf.bufferViews, extension.bufferView);
  453. if (!bufferView._dracoBabylonGeometry) {
  454. bufferView._dracoBabylonGeometry = _this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  455. var dracoCompression = _this.dracoCompression || babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["DracoCompression"].Default;
  456. return dracoCompression.decodeMeshAsync(data, attributes).then(function (babylonVertexData) {
  457. var babylonGeometry = new babylonjs_Meshes_Compression_dracoCompression__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, _this._loader.babylonScene);
  458. babylonVertexData.applyToGeometry(babylonGeometry);
  459. return babylonGeometry;
  460. }).catch(function (error) {
  461. throw new Error(context + ": " + error.message);
  462. });
  463. });
  464. }
  465. return bufferView._dracoBabylonGeometry;
  466. });
  467. };
  468. return KHR_draco_mesh_compression;
  469. }());
  470. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_draco_mesh_compression(loader); });
  471. /***/ }),
  472. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  473. /*!****************************************************!*\
  474. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  475. \****************************************************/
  476. /*! exports provided: KHR_lights */
  477. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  478. "use strict";
  479. __webpack_require__.r(__webpack_exports__);
  480. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return KHR_lights; });
  481. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  482. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  483. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  484. var NAME = "KHR_lights_punctual";
  485. /**
  486. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual)
  487. */
  488. var KHR_lights = /** @class */ (function () {
  489. /** @hidden */
  490. function KHR_lights(loader) {
  491. /**
  492. * The name of this extension.
  493. */
  494. this.name = NAME;
  495. this._loader = loader;
  496. this.enabled = this._loader.isExtensionUsed(NAME);
  497. }
  498. /** @hidden */
  499. KHR_lights.prototype.dispose = function () {
  500. delete this._loader;
  501. delete this._lights;
  502. };
  503. /** @hidden */
  504. KHR_lights.prototype.onLoading = function () {
  505. var extensions = this._loader.gltf.extensions;
  506. if (extensions && extensions[this.name]) {
  507. var extension = extensions[this.name];
  508. this._lights = extension.lights;
  509. }
  510. };
  511. /** @hidden */
  512. KHR_lights.prototype.loadNodeAsync = function (context, node, assign) {
  513. var _this = this;
  514. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  515. return _this._loader.loadNodeAsync(context, node, function (babylonMesh) {
  516. var babylonLight;
  517. var light = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext, _this._lights, extension.light);
  518. var name = light.name || babylonMesh.name;
  519. _this._loader.babylonScene._blockEntityCollection = _this._loader._forAssetContainer;
  520. switch (light.type) {
  521. case "directional" /* DIRECTIONAL */: {
  522. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), _this._loader.babylonScene);
  523. break;
  524. }
  525. case "point" /* POINT */: {
  526. babylonLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["PointLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), _this._loader.babylonScene);
  527. break;
  528. }
  529. case "spot" /* SPOT */: {
  530. var babylonSpotLight = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["SpotLight"](name, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Backward(), 0, 1, _this._loader.babylonScene);
  531. babylonSpotLight.angle = ((light.spot && light.spot.outerConeAngle) || Math.PI / 4) * 2;
  532. babylonSpotLight.innerAngle = ((light.spot && light.spot.innerConeAngle) || 0) * 2;
  533. babylonLight = babylonSpotLight;
  534. break;
  535. }
  536. default: {
  537. _this._loader.babylonScene._blockEntityCollection = false;
  538. throw new Error(extensionContext + ": Invalid light type (" + light.type + ")");
  539. }
  540. }
  541. _this._loader.babylonScene._blockEntityCollection = false;
  542. babylonLight.falloffType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF;
  543. babylonLight.diffuse = light.color ? babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(light.color) : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  544. babylonLight.intensity = light.intensity == undefined ? 1 : light.intensity;
  545. babylonLight.range = light.range == undefined ? Number.MAX_VALUE : light.range;
  546. babylonLight.parent = babylonMesh;
  547. _this._loader._babylonLights.push(babylonLight);
  548. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].AddPointerMetadata(babylonLight, extensionContext);
  549. assign(babylonMesh);
  550. });
  551. });
  552. };
  553. return KHR_lights;
  554. }());
  555. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_lights(loader); });
  556. /***/ }),
  557. /***/ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts":
  558. /*!********************************************************!*\
  559. !*** ./glTF/2.0/Extensions/KHR_materials_clearcoat.ts ***!
  560. \********************************************************/
  561. /*! exports provided: KHR_materials_clearcoat */
  562. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  563. "use strict";
  564. __webpack_require__.r(__webpack_exports__);
  565. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return KHR_materials_clearcoat; });
  566. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  567. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  568. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  569. var NAME = "KHR_materials_clearcoat";
  570. /**
  571. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1677)
  572. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)
  573. * !!! Experimental Extension Subject to Changes !!!
  574. */
  575. var KHR_materials_clearcoat = /** @class */ (function () {
  576. /** @hidden */
  577. function KHR_materials_clearcoat(loader) {
  578. /**
  579. * The name of this extension.
  580. */
  581. this.name = NAME;
  582. /**
  583. * Defines a number that determines the order the extensions are applied.
  584. */
  585. this.order = 190;
  586. this._loader = loader;
  587. this.enabled = this._loader.isExtensionUsed(NAME);
  588. }
  589. /** @hidden */
  590. KHR_materials_clearcoat.prototype.dispose = function () {
  591. delete this._loader;
  592. };
  593. /** @hidden */
  594. KHR_materials_clearcoat.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  595. var _this = this;
  596. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  597. var promises = new Array();
  598. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  599. promises.push(_this._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));
  600. return Promise.all(promises).then(function () { });
  601. });
  602. };
  603. KHR_materials_clearcoat.prototype._loadClearCoatPropertiesAsync = function (context, properties, babylonMaterial) {
  604. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  605. throw new Error(context + ": Material type not supported");
  606. }
  607. var promises = new Array();
  608. babylonMaterial.clearCoat.isEnabled = true;
  609. if (properties.clearcoatFactor != undefined) {
  610. babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;
  611. }
  612. else {
  613. babylonMaterial.clearCoat.intensity = 0;
  614. }
  615. if (properties.clearcoatTexture) {
  616. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatTexture", properties.clearcoatTexture, function (texture) {
  617. texture.name = babylonMaterial.name + " (ClearCoat Intensity)";
  618. babylonMaterial.clearCoat.texture = texture;
  619. }));
  620. }
  621. if (properties.clearcoatRoughnessFactor != undefined) {
  622. babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;
  623. }
  624. else {
  625. babylonMaterial.clearCoat.roughness = 0;
  626. }
  627. if (properties.clearcoatRoughnessTexture) {
  628. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatRoughnessTexture", properties.clearcoatRoughnessTexture, function (texture) {
  629. texture.name = babylonMaterial.name + " (ClearCoat Roughness)";
  630. babylonMaterial.clearCoat.texture = texture;
  631. }));
  632. }
  633. if (properties.clearcoatNormalTexture) {
  634. promises.push(this._loader.loadTextureInfoAsync(context + "/clearcoatNormalTexture", properties.clearcoatNormalTexture, function (texture) {
  635. texture.name = babylonMaterial.name + " (ClearCoat Normal)";
  636. babylonMaterial.clearCoat.bumpTexture = texture;
  637. }));
  638. babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;
  639. babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;
  640. if (properties.clearcoatNormalTexture.scale != undefined) {
  641. babylonMaterial.clearCoat.bumpTexture.level = properties.clearcoatNormalTexture.scale;
  642. }
  643. }
  644. return Promise.all(promises).then(function () { });
  645. };
  646. return KHR_materials_clearcoat;
  647. }());
  648. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_clearcoat(loader); });
  649. /***/ }),
  650. /***/ "./glTF/2.0/Extensions/KHR_materials_ior.ts":
  651. /*!**************************************************!*\
  652. !*** ./glTF/2.0/Extensions/KHR_materials_ior.ts ***!
  653. \**************************************************/
  654. /*! exports provided: KHR_materials_ior */
  655. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  656. "use strict";
  657. __webpack_require__.r(__webpack_exports__);
  658. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return KHR_materials_ior; });
  659. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  660. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  661. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  662. var NAME = "KHR_materials_ior";
  663. /**
  664. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1718)
  665. * !!! Experimental Extension Subject to Changes !!!
  666. */
  667. var KHR_materials_ior = /** @class */ (function () {
  668. /** @hidden */
  669. function KHR_materials_ior(loader) {
  670. /**
  671. * The name of this extension.
  672. */
  673. this.name = NAME;
  674. /**
  675. * Defines a number that determines the order the extensions are applied.
  676. */
  677. this.order = 180;
  678. this._loader = loader;
  679. this.enabled = this._loader.isExtensionUsed(NAME);
  680. }
  681. /** @hidden */
  682. KHR_materials_ior.prototype.dispose = function () {
  683. delete this._loader;
  684. };
  685. /** @hidden */
  686. KHR_materials_ior.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  687. var _this = this;
  688. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  689. var promises = new Array();
  690. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  691. promises.push(_this._loadIorPropertiesAsync(extensionContext, extension, babylonMaterial));
  692. return Promise.all(promises).then(function () { });
  693. });
  694. };
  695. KHR_materials_ior.prototype._loadIorPropertiesAsync = function (context, properties, babylonMaterial) {
  696. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  697. throw new Error(context + ": Material type not supported");
  698. }
  699. if (properties.ior !== undefined) {
  700. babylonMaterial.indexOfRefraction = properties.ior;
  701. }
  702. else {
  703. babylonMaterial.indexOfRefraction = KHR_materials_ior._DEFAULT_IOR;
  704. }
  705. return Promise.resolve();
  706. };
  707. /**
  708. * Default ior Value from the spec.
  709. */
  710. KHR_materials_ior._DEFAULT_IOR = 1.5;
  711. return KHR_materials_ior;
  712. }());
  713. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_ior(loader); });
  714. /***/ }),
  715. /***/ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts":
  716. /*!********************************************************************!*\
  717. !*** ./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts ***!
  718. \********************************************************************/
  719. /*! exports provided: KHR_materials_pbrSpecularGlossiness */
  720. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  721. "use strict";
  722. __webpack_require__.r(__webpack_exports__);
  723. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return KHR_materials_pbrSpecularGlossiness; });
  724. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  725. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  726. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  727. var NAME = "KHR_materials_pbrSpecularGlossiness";
  728. /**
  729. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness)
  730. */
  731. var KHR_materials_pbrSpecularGlossiness = /** @class */ (function () {
  732. /** @hidden */
  733. function KHR_materials_pbrSpecularGlossiness(loader) {
  734. /**
  735. * The name of this extension.
  736. */
  737. this.name = NAME;
  738. /**
  739. * Defines a number that determines the order the extensions are applied.
  740. */
  741. this.order = 200;
  742. this._loader = loader;
  743. this.enabled = this._loader.isExtensionUsed(NAME);
  744. }
  745. /** @hidden */
  746. KHR_materials_pbrSpecularGlossiness.prototype.dispose = function () {
  747. delete this._loader;
  748. };
  749. /** @hidden */
  750. KHR_materials_pbrSpecularGlossiness.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  751. var _this = this;
  752. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  753. var promises = new Array();
  754. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  755. promises.push(_this._loadSpecularGlossinessPropertiesAsync(extensionContext, material, extension, babylonMaterial));
  756. _this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  757. return Promise.all(promises).then(function () { });
  758. });
  759. };
  760. KHR_materials_pbrSpecularGlossiness.prototype._loadSpecularGlossinessPropertiesAsync = function (context, material, properties, babylonMaterial) {
  761. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  762. throw new Error(context + ": Material type not supported");
  763. }
  764. var promises = new Array();
  765. babylonMaterial.metallic = null;
  766. babylonMaterial.roughness = null;
  767. if (properties.diffuseFactor) {
  768. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.diffuseFactor);
  769. babylonMaterial.alpha = properties.diffuseFactor[3];
  770. }
  771. else {
  772. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  773. }
  774. babylonMaterial.reflectivityColor = properties.specularFactor ? babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularFactor) : babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  775. babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;
  776. if (properties.diffuseTexture) {
  777. promises.push(this._loader.loadTextureInfoAsync(context + "/diffuseTexture", properties.diffuseTexture, function (texture) {
  778. texture.name = babylonMaterial.name + " (Diffuse)";
  779. babylonMaterial.albedoTexture = texture;
  780. }));
  781. }
  782. if (properties.specularGlossinessTexture) {
  783. promises.push(this._loader.loadTextureInfoAsync(context + "/specularGlossinessTexture", properties.specularGlossinessTexture, function (texture) {
  784. texture.name = babylonMaterial.name + " (Specular Glossiness)";
  785. babylonMaterial.reflectivityTexture = texture;
  786. }));
  787. babylonMaterial.reflectivityTexture.hasAlpha = true;
  788. babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;
  789. }
  790. return Promise.all(promises).then(function () { });
  791. };
  792. return KHR_materials_pbrSpecularGlossiness;
  793. }());
  794. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_pbrSpecularGlossiness(loader); });
  795. /***/ }),
  796. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  797. /*!****************************************************!*\
  798. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  799. \****************************************************/
  800. /*! exports provided: KHR_materials_sheen */
  801. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  802. "use strict";
  803. __webpack_require__.r(__webpack_exports__);
  804. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  805. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  806. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  807. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  808. var NAME = "KHR_materials_sheen";
  809. /**
  810. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1688)
  811. * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)
  812. * !!! Experimental Extension Subject to Changes !!!
  813. */
  814. var KHR_materials_sheen = /** @class */ (function () {
  815. /** @hidden */
  816. function KHR_materials_sheen(loader) {
  817. /**
  818. * The name of this extension.
  819. */
  820. this.name = NAME;
  821. /**
  822. * Defines a number that determines the order the extensions are applied.
  823. */
  824. this.order = 190;
  825. this._loader = loader;
  826. this.enabled = this._loader.isExtensionUsed(NAME);
  827. }
  828. /** @hidden */
  829. KHR_materials_sheen.prototype.dispose = function () {
  830. delete this._loader;
  831. };
  832. /** @hidden */
  833. KHR_materials_sheen.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  834. var _this = this;
  835. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  836. var promises = new Array();
  837. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  838. promises.push(_this._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));
  839. return Promise.all(promises).then(function () { });
  840. });
  841. };
  842. KHR_materials_sheen.prototype._loadSheenPropertiesAsync = function (context, properties, babylonMaterial) {
  843. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  844. throw new Error(context + ": Material type not supported");
  845. }
  846. var promises = new Array();
  847. babylonMaterial.sheen.isEnabled = true;
  848. babylonMaterial.sheen.intensity = 1;
  849. if (properties.sheenColorFactor != undefined) {
  850. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.sheenColorFactor);
  851. }
  852. else {
  853. babylonMaterial.sheen.color = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  854. }
  855. if (properties.sheenTexture) {
  856. promises.push(this._loader.loadTextureInfoAsync(context + "/sheenTexture", properties.sheenTexture, function (texture) {
  857. texture.name = babylonMaterial.name + " (Sheen Color)";
  858. babylonMaterial.sheen.texture = texture;
  859. }));
  860. }
  861. if (properties.sheenRoughnessFactor !== undefined) {
  862. babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;
  863. }
  864. else {
  865. babylonMaterial.sheen.roughness = 0;
  866. }
  867. babylonMaterial.sheen.albedoScaling = true;
  868. return Promise.all(promises).then(function () { });
  869. };
  870. return KHR_materials_sheen;
  871. }());
  872. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_sheen(loader); });
  873. /***/ }),
  874. /***/ "./glTF/2.0/Extensions/KHR_materials_specular.ts":
  875. /*!*******************************************************!*\
  876. !*** ./glTF/2.0/Extensions/KHR_materials_specular.ts ***!
  877. \*******************************************************/
  878. /*! exports provided: KHR_materials_specular */
  879. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  880. "use strict";
  881. __webpack_require__.r(__webpack_exports__);
  882. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return KHR_materials_specular; });
  883. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  884. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  885. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  886. var NAME = "KHR_materials_specular";
  887. /**
  888. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1719)
  889. * !!! Experimental Extension Subject to Changes !!!
  890. */
  891. var KHR_materials_specular = /** @class */ (function () {
  892. /** @hidden */
  893. function KHR_materials_specular(loader) {
  894. /**
  895. * The name of this extension.
  896. */
  897. this.name = NAME;
  898. /**
  899. * Defines a number that determines the order the extensions are applied.
  900. */
  901. this.order = 190;
  902. this._loader = loader;
  903. this.enabled = this._loader.isExtensionUsed(NAME);
  904. }
  905. /** @hidden */
  906. KHR_materials_specular.prototype.dispose = function () {
  907. delete this._loader;
  908. };
  909. /** @hidden */
  910. KHR_materials_specular.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  911. var _this = this;
  912. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  913. var promises = new Array();
  914. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  915. promises.push(_this._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));
  916. return Promise.all(promises).then(function () { });
  917. });
  918. };
  919. KHR_materials_specular.prototype._loadSpecularPropertiesAsync = function (context, properties, babylonMaterial) {
  920. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  921. throw new Error(context + ": Material type not supported");
  922. }
  923. var promises = new Array();
  924. if (properties.specularFactor !== undefined) {
  925. babylonMaterial.metallicF0Factor = properties.specularFactor;
  926. }
  927. if (properties.specularColorFactor !== undefined) {
  928. babylonMaterial.metallicReflectanceColor = babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.specularColorFactor);
  929. }
  930. if (properties.specularTexture) {
  931. promises.push(this._loader.loadTextureInfoAsync(context + "/specularTexture", properties.specularTexture, function (texture) {
  932. texture.name = babylonMaterial.name + " (Specular F0 Color)";
  933. babylonMaterial.metallicReflectanceTexture = texture;
  934. }));
  935. }
  936. return Promise.all(promises).then(function () { });
  937. };
  938. return KHR_materials_specular;
  939. }());
  940. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_specular(loader); });
  941. /***/ }),
  942. /***/ "./glTF/2.0/Extensions/KHR_materials_transmission.ts":
  943. /*!***********************************************************!*\
  944. !*** ./glTF/2.0/Extensions/KHR_materials_transmission.ts ***!
  945. \***********************************************************/
  946. /*! exports provided: KHR_materials_transmission */
  947. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  948. "use strict";
  949. __webpack_require__.r(__webpack_exports__);
  950. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return KHR_materials_transmission; });
  951. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  952. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  953. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  954. var NAME = "KHR_materials_transmission";
  955. /**
  956. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1698)
  957. * !!! Experimental Extension Subject to Changes !!!
  958. */
  959. var KHR_materials_transmission = /** @class */ (function () {
  960. /** @hidden */
  961. function KHR_materials_transmission(loader) {
  962. /**
  963. * The name of this extension.
  964. */
  965. this.name = NAME;
  966. /**
  967. * Defines a number that determines the order the extensions are applied.
  968. */
  969. this.order = 175;
  970. this._loader = loader;
  971. this.enabled = this._loader.isExtensionUsed(NAME);
  972. if (this.enabled) {
  973. loader._parent.transparencyAsCoverage = true;
  974. }
  975. }
  976. /** @hidden */
  977. KHR_materials_transmission.prototype.dispose = function () {
  978. delete this._loader;
  979. };
  980. /** @hidden */
  981. KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  982. var _this = this;
  983. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  984. var promises = new Array();
  985. promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  986. promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
  987. promises.push(_this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
  988. return Promise.all(promises).then(function () { });
  989. });
  990. };
  991. KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
  992. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  993. throw new Error(context + ": Material type not supported");
  994. }
  995. var pbrMaterial = babylonMaterial;
  996. // Enables "refraction" texture which represents transmitted light.
  997. pbrMaterial.subSurface.isRefractionEnabled = true;
  998. // Since this extension models thin-surface transmission only, we must make IOR = 1.0
  999. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
  1000. // Albedo colour will tint transmission.
  1001. pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
  1002. if (extension.transmissionFactor !== undefined) {
  1003. pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
  1004. }
  1005. else {
  1006. pbrMaterial.subSurface.refractionIntensity = 0.0;
  1007. pbrMaterial.subSurface.isRefractionEnabled = false;
  1008. return Promise.resolve();
  1009. }
  1010. if (extension.transmissionTexture) {
  1011. return this._loader.loadTextureInfoAsync(context + "/transmissionTexture", extension.transmissionTexture)
  1012. .then(function (texture) {
  1013. pbrMaterial.subSurface.thicknessTexture = texture;
  1014. pbrMaterial.subSurface.useMaskFromThicknessTexture = true;
  1015. });
  1016. }
  1017. else {
  1018. return Promise.resolve();
  1019. }
  1020. };
  1021. return KHR_materials_transmission;
  1022. }());
  1023. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
  1024. /***/ }),
  1025. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  1026. /*!****************************************************!*\
  1027. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  1028. \****************************************************/
  1029. /*! exports provided: KHR_materials_unlit */
  1030. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1031. "use strict";
  1032. __webpack_require__.r(__webpack_exports__);
  1033. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  1034. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.color */ "babylonjs/Misc/tools");
  1035. /* harmony import */ var babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__);
  1036. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1037. var NAME = "KHR_materials_unlit";
  1038. /**
  1039. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit)
  1040. */
  1041. var KHR_materials_unlit = /** @class */ (function () {
  1042. /** @hidden */
  1043. function KHR_materials_unlit(loader) {
  1044. /**
  1045. * The name of this extension.
  1046. */
  1047. this.name = NAME;
  1048. /**
  1049. * Defines a number that determines the order the extensions are applied.
  1050. */
  1051. this.order = 210;
  1052. this._loader = loader;
  1053. this.enabled = this._loader.isExtensionUsed(NAME);
  1054. }
  1055. /** @hidden */
  1056. KHR_materials_unlit.prototype.dispose = function () {
  1057. delete this._loader;
  1058. };
  1059. /** @hidden */
  1060. KHR_materials_unlit.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  1061. var _this = this;
  1062. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function () {
  1063. return _this._loadUnlitPropertiesAsync(context, material, babylonMaterial);
  1064. });
  1065. };
  1066. KHR_materials_unlit.prototype._loadUnlitPropertiesAsync = function (context, material, babylonMaterial) {
  1067. if (!(babylonMaterial instanceof babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  1068. throw new Error(context + ": Material type not supported");
  1069. }
  1070. var promises = new Array();
  1071. babylonMaterial.unlit = true;
  1072. var properties = material.pbrMetallicRoughness;
  1073. if (properties) {
  1074. if (properties.baseColorFactor) {
  1075. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  1076. babylonMaterial.alpha = properties.baseColorFactor[3];
  1077. }
  1078. else {
  1079. babylonMaterial.albedoColor = babylonjs_Maths_math_color__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  1080. }
  1081. if (properties.baseColorTexture) {
  1082. promises.push(this._loader.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  1083. texture.name = babylonMaterial.name + " (Base Color)";
  1084. babylonMaterial.albedoTexture = texture;
  1085. }));
  1086. }
  1087. }
  1088. if (material.doubleSided) {
  1089. babylonMaterial.backFaceCulling = false;
  1090. babylonMaterial.twoSidedLighting = true;
  1091. }
  1092. this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);
  1093. return Promise.all(promises).then(function () { });
  1094. };
  1095. return KHR_materials_unlit;
  1096. }());
  1097. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_unlit(loader); });
  1098. /***/ }),
  1099. /***/ "./glTF/2.0/Extensions/KHR_materials_variants.ts":
  1100. /*!*******************************************************!*\
  1101. !*** ./glTF/2.0/Extensions/KHR_materials_variants.ts ***!
  1102. \*******************************************************/
  1103. /*! exports provided: KHR_materials_variants */
  1104. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1105. "use strict";
  1106. __webpack_require__.r(__webpack_exports__);
  1107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return KHR_materials_variants; });
  1108. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1109. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Meshes/mesh */ "babylonjs/Misc/tools");
  1110. /* harmony import */ var babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__);
  1111. var NAME = "KHR_materials_variants";
  1112. /**
  1113. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1681)
  1114. * !!! Experimental Extension Subject to Changes !!!
  1115. */
  1116. var KHR_materials_variants = /** @class */ (function () {
  1117. /** @hidden */
  1118. function KHR_materials_variants(loader) {
  1119. /**
  1120. * The name of this extension.
  1121. */
  1122. this.name = NAME;
  1123. this._loader = loader;
  1124. this.enabled = this._loader.isExtensionUsed(NAME);
  1125. }
  1126. /** @hidden */
  1127. KHR_materials_variants.prototype.dispose = function () {
  1128. delete this._loader;
  1129. };
  1130. /**
  1131. * Gets the list of available variant tag names for this asset.
  1132. * @param rootMesh The glTF root mesh
  1133. * @returns the list of all the variant names for this model
  1134. */
  1135. KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
  1136. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1137. if (!extensionMetadata) {
  1138. return [];
  1139. }
  1140. return Object.keys(extensionMetadata.variants);
  1141. };
  1142. /**
  1143. * Gets the list of available variant tag names for this asset.
  1144. * @param rootMesh The glTF root mesh
  1145. * @returns the list of all the variant names for this model
  1146. */
  1147. KHR_materials_variants.prototype.getAvailableVariants = function (rootMesh) {
  1148. return KHR_materials_variants.GetAvailableVariants(rootMesh);
  1149. };
  1150. /**
  1151. * Select a variant given a variant tag name or a list of variant tag names.
  1152. * @param rootMesh The glTF root mesh
  1153. * @param variantName The variant name(s) to select.
  1154. */
  1155. KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
  1156. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1157. if (!extensionMetadata) {
  1158. throw new Error("Cannot select variant on a glTF mesh that does not have the " + NAME + " extension");
  1159. }
  1160. var select = function (variantName) {
  1161. var entries = extensionMetadata.variants[variantName];
  1162. if (entries) {
  1163. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  1164. var entry = entries_1[_i];
  1165. entry.mesh.material = entry.material;
  1166. }
  1167. }
  1168. };
  1169. if (variantName instanceof Array) {
  1170. for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
  1171. var name_1 = variantName_1[_i];
  1172. select(name_1);
  1173. }
  1174. }
  1175. else {
  1176. select(variantName);
  1177. }
  1178. extensionMetadata.lastSelected = variantName;
  1179. };
  1180. /**
  1181. * Select a variant given a variant tag name or a list of variant tag names.
  1182. * @param rootMesh The glTF root mesh
  1183. * @param variantName The variant name(s) to select.
  1184. */
  1185. KHR_materials_variants.prototype.selectVariant = function (rootMesh, variantName) {
  1186. return KHR_materials_variants.SelectVariant(rootMesh, variantName);
  1187. };
  1188. /**
  1189. * Reset back to the original before selecting a variant.
  1190. * @param rootMesh The glTF root mesh
  1191. */
  1192. KHR_materials_variants.Reset = function (rootMesh) {
  1193. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1194. if (!extensionMetadata) {
  1195. throw new Error("Cannot reset on a glTF mesh that does not have the " + NAME + " extension");
  1196. }
  1197. for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
  1198. var entry = _a[_i];
  1199. entry.mesh.material = entry.material;
  1200. }
  1201. extensionMetadata.lastSelected = null;
  1202. };
  1203. /**
  1204. * Reset back to the original before selecting a variant.
  1205. * @param rootMesh The glTF root mesh
  1206. */
  1207. KHR_materials_variants.prototype.reset = function (rootMesh) {
  1208. return KHR_materials_variants.Reset(rootMesh);
  1209. };
  1210. /**
  1211. * Gets the last selected variant tag name(s) or null if original.
  1212. * @param rootMesh The glTF root mesh
  1213. * @returns The selected variant tag name(s).
  1214. */
  1215. KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
  1216. var extensionMetadata = this._GetExtensionMetadata(rootMesh);
  1217. if (!extensionMetadata) {
  1218. throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the " + NAME + " extension");
  1219. }
  1220. return extensionMetadata.lastSelected;
  1221. };
  1222. /**
  1223. * Gets the last selected variant tag name(s) or null if original.
  1224. * @param rootMesh The glTF root mesh
  1225. * @returns The selected variant tag name(s).
  1226. */
  1227. KHR_materials_variants.prototype.getLastSelectedVariant = function (rootMesh) {
  1228. return KHR_materials_variants.GetLastSelectedVariant(rootMesh);
  1229. };
  1230. KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
  1231. var _a, _b;
  1232. return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
  1233. };
  1234. /** @hidden */
  1235. KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  1236. var _this = this;
  1237. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
  1238. var promises = new Array();
  1239. promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
  1240. assign(babylonMesh);
  1241. if (babylonMesh instanceof babylonjs_Meshes_mesh__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  1242. var babylonDrawMode = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]._GetDrawMode(context, primitive.mode);
  1243. var root = _this._loader.rootBabylonMesh;
  1244. var metadata = (root.metadata = root.metadata || {});
  1245. var gltf = (metadata.gltf = metadata.gltf || {});
  1246. var extensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
  1247. // Store the original material.
  1248. extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });
  1249. // For each mapping, look at the tags and make a new entry for them.
  1250. var variants_1 = extensionMetadata.variants;
  1251. for (var _i = 0, _a = extension.mapping; _i < _a.length; _i++) {
  1252. var mapping = _a[_i];
  1253. var _loop_1 = function (tag) {
  1254. var material = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get("#/materials/", _this._loader.gltf.materials, mapping.material);
  1255. promises.push(_this._loader._loadMaterialAsync("#/materials/" + mapping.material, material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1256. variants_1[tag] = variants_1[tag] || [];
  1257. variants_1[tag].push({
  1258. mesh: babylonMesh,
  1259. material: babylonMaterial
  1260. });
  1261. }));
  1262. };
  1263. for (var _b = 0, _c = mapping.tags; _b < _c.length; _b++) {
  1264. var tag = _c[_b];
  1265. _loop_1(tag);
  1266. }
  1267. }
  1268. }
  1269. }));
  1270. return Promise.all(promises).then(function (_a) {
  1271. var babylonMesh = _a[0];
  1272. return babylonMesh;
  1273. });
  1274. });
  1275. };
  1276. return KHR_materials_variants;
  1277. }());
  1278. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
  1279. /***/ }),
  1280. /***/ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts":
  1281. /*!******************************************************!*\
  1282. !*** ./glTF/2.0/Extensions/KHR_mesh_quantization.ts ***!
  1283. \******************************************************/
  1284. /*! exports provided: KHR_mesh_quantization */
  1285. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1286. "use strict";
  1287. __webpack_require__.r(__webpack_exports__);
  1288. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return KHR_mesh_quantization; });
  1289. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1290. var NAME = "KHR_mesh_quantization";
  1291. /**
  1292. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization)
  1293. */
  1294. var KHR_mesh_quantization = /** @class */ (function () {
  1295. /** @hidden */
  1296. function KHR_mesh_quantization(loader) {
  1297. /**
  1298. * The name of this extension.
  1299. */
  1300. this.name = NAME;
  1301. this.enabled = loader.isExtensionUsed(NAME);
  1302. }
  1303. /** @hidden */
  1304. KHR_mesh_quantization.prototype.dispose = function () {
  1305. };
  1306. return KHR_mesh_quantization;
  1307. }());
  1308. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_mesh_quantization(loader); });
  1309. /***/ }),
  1310. /***/ "./glTF/2.0/Extensions/KHR_texture_basisu.ts":
  1311. /*!***************************************************!*\
  1312. !*** ./glTF/2.0/Extensions/KHR_texture_basisu.ts ***!
  1313. \***************************************************/
  1314. /*! exports provided: KHR_texture_basisu */
  1315. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1316. "use strict";
  1317. __webpack_require__.r(__webpack_exports__);
  1318. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return KHR_texture_basisu; });
  1319. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1320. var NAME = "KHR_texture_basisu";
  1321. /**
  1322. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1751)
  1323. * !!! Experimental Extension Subject to Changes !!!
  1324. */
  1325. var KHR_texture_basisu = /** @class */ (function () {
  1326. /** @hidden */
  1327. function KHR_texture_basisu(loader) {
  1328. /** The name of this extension. */
  1329. this.name = NAME;
  1330. this._loader = loader;
  1331. this.enabled = loader.isExtensionUsed(NAME);
  1332. }
  1333. /** @hidden */
  1334. KHR_texture_basisu.prototype.dispose = function () {
  1335. delete this._loader;
  1336. };
  1337. /** @hidden */
  1338. KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
  1339. var _this = this;
  1340. return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
  1341. var sampler = (texture.sampler == undefined ? _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].DefaultSampler : _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(context + "/sampler", _this._loader.gltf.samplers, texture.sampler));
  1342. var image = _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"].Get(extensionContext + "/source", _this._loader.gltf.images, extension.source);
  1343. return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
  1344. babylonTexture.gammaSpace = false;
  1345. assign(babylonTexture);
  1346. });
  1347. });
  1348. };
  1349. return KHR_texture_basisu;
  1350. }());
  1351. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_basisu(loader); });
  1352. /***/ }),
  1353. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  1354. /*!******************************************************!*\
  1355. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  1356. \******************************************************/
  1357. /*! exports provided: KHR_texture_transform */
  1358. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1359. "use strict";
  1360. __webpack_require__.r(__webpack_exports__);
  1361. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  1362. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/Textures/texture */ "babylonjs/Misc/tools");
  1363. /* harmony import */ var babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__);
  1364. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1365. var NAME = "KHR_texture_transform";
  1366. /**
  1367. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)
  1368. */
  1369. var KHR_texture_transform = /** @class */ (function () {
  1370. /** @hidden */
  1371. function KHR_texture_transform(loader) {
  1372. /**
  1373. * The name of this extension.
  1374. */
  1375. this.name = NAME;
  1376. this._loader = loader;
  1377. this.enabled = this._loader.isExtensionUsed(NAME);
  1378. }
  1379. /** @hidden */
  1380. KHR_texture_transform.prototype.dispose = function () {
  1381. delete this._loader;
  1382. };
  1383. /** @hidden */
  1384. KHR_texture_transform.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  1385. var _this = this;
  1386. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
  1387. return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
  1388. if (!(babylonTexture instanceof babylonjs_Materials_Textures_texture__WEBPACK_IMPORTED_MODULE_0__["Texture"])) {
  1389. throw new Error(extensionContext + ": Texture type not supported");
  1390. }
  1391. if (extension.offset) {
  1392. babylonTexture.uOffset = extension.offset[0];
  1393. babylonTexture.vOffset = extension.offset[1];
  1394. }
  1395. // Always rotate around the origin.
  1396. babylonTexture.uRotationCenter = 0;
  1397. babylonTexture.vRotationCenter = 0;
  1398. if (extension.rotation) {
  1399. babylonTexture.wAng = -extension.rotation;
  1400. }
  1401. if (extension.scale) {
  1402. babylonTexture.uScale = extension.scale[0];
  1403. babylonTexture.vScale = extension.scale[1];
  1404. }
  1405. if (extension.texCoord != undefined) {
  1406. babylonTexture.coordinatesIndex = extension.texCoord;
  1407. }
  1408. assign(babylonTexture);
  1409. });
  1410. });
  1411. };
  1412. return KHR_texture_transform;
  1413. }());
  1414. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_texture_transform(loader); });
  1415. /***/ }),
  1416. /***/ "./glTF/2.0/Extensions/KHR_xmp.ts":
  1417. /*!****************************************!*\
  1418. !*** ./glTF/2.0/Extensions/KHR_xmp.ts ***!
  1419. \****************************************/
  1420. /*! exports provided: KHR_xmp */
  1421. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1422. "use strict";
  1423. __webpack_require__.r(__webpack_exports__);
  1424. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return KHR_xmp; });
  1425. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1426. var NAME = "KHR_xmp";
  1427. /**
  1428. * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1553)
  1429. * !!! Experimental Extension Subject to Changes !!!
  1430. */
  1431. var KHR_xmp = /** @class */ (function () {
  1432. /** @hidden */
  1433. function KHR_xmp(loader) {
  1434. /**
  1435. * The name of this extension.
  1436. */
  1437. this.name = NAME;
  1438. /**
  1439. * Defines a number that determines the order the extensions are applied.
  1440. */
  1441. this.order = 100;
  1442. this._loader = loader;
  1443. this.enabled = this._loader.isExtensionUsed(NAME);
  1444. }
  1445. /** @hidden */
  1446. KHR_xmp.prototype.dispose = function () {
  1447. delete this._loader;
  1448. };
  1449. /**
  1450. * Called after the loader state changes to LOADING.
  1451. */
  1452. KHR_xmp.prototype.onLoading = function () {
  1453. var _a, _b, _c;
  1454. var xmp_gltf = (_a = this._loader.gltf.extensions) === null || _a === void 0 ? void 0 : _a.KHR_xmp;
  1455. var xmp_node = (_c = (_b = this._loader.gltf.asset) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c.KHR_xmp;
  1456. if (xmp_gltf && xmp_node) {
  1457. var packet = +xmp_node.packet;
  1458. if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {
  1459. this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};
  1460. this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];
  1461. }
  1462. }
  1463. };
  1464. return KHR_xmp;
  1465. }());
  1466. _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new KHR_xmp(loader); });
  1467. /***/ }),
  1468. /***/ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts":
  1469. /*!***************************************************!*\
  1470. !*** ./glTF/2.0/Extensions/MSFT_audio_emitter.ts ***!
  1471. \***************************************************/
  1472. /*! exports provided: MSFT_audio_emitter */
  1473. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1474. "use strict";
  1475. __webpack_require__.r(__webpack_exports__);
  1476. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return MSFT_audio_emitter; });
  1477. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Misc/tools");
  1478. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  1479. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1480. var NAME = "MSFT_audio_emitter";
  1481. /**
  1482. * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
  1483. */
  1484. var MSFT_audio_emitter = /** @class */ (function () {
  1485. /** @hidden */
  1486. function MSFT_audio_emitter(loader) {
  1487. /**
  1488. * The name of this extension.
  1489. */
  1490. this.name = NAME;
  1491. this._loader = loader;
  1492. this.enabled = this._loader.isExtensionUsed(NAME);
  1493. }
  1494. /** @hidden */
  1495. MSFT_audio_emitter.prototype.dispose = function () {
  1496. delete this._loader;
  1497. delete this._clips;
  1498. delete this._emitters;
  1499. };
  1500. /** @hidden */
  1501. MSFT_audio_emitter.prototype.onLoading = function () {
  1502. var extensions = this._loader.gltf.extensions;
  1503. if (extensions && extensions[this.name]) {
  1504. var extension = extensions[this.name];
  1505. this._clips = extension.clips;
  1506. this._emitters = extension.emitters;
  1507. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._clips);
  1508. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(this._emitters);
  1509. }
  1510. };
  1511. /** @hidden */
  1512. MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
  1513. var _this = this;
  1514. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
  1515. var promises = new Array();
  1516. promises.push(_this._loader.loadSceneAsync(context, scene));
  1517. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  1518. var emitterIndex = _a[_i];
  1519. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  1520. if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
  1521. emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  1522. throw new Error(extensionContext + ": Direction or Distance properties are not allowed on emitters attached to a scene");
  1523. }
  1524. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter));
  1525. }
  1526. return Promise.all(promises).then(function () { });
  1527. });
  1528. };
  1529. /** @hidden */
  1530. MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
  1531. var _this = this;
  1532. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  1533. var promises = new Array();
  1534. return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
  1535. var _loop_1 = function (emitterIndex) {
  1536. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(extensionContext + "/emitters", _this._emitters, emitterIndex);
  1537. promises.push(_this._loadEmitterAsync(extensionContext + "/emitters/" + emitter.index, emitter).then(function () {
  1538. for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
  1539. var sound = _a[_i];
  1540. sound.attachToMesh(babylonMesh);
  1541. if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
  1542. sound.setLocalDirectionToMesh(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Forward());
  1543. sound.setDirectionalCone(2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
  1544. }
  1545. }
  1546. }));
  1547. };
  1548. for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
  1549. var emitterIndex = _a[_i];
  1550. _loop_1(emitterIndex);
  1551. }
  1552. assign(babylonMesh);
  1553. }).then(function (babylonMesh) {
  1554. return Promise.all(promises).then(function () {
  1555. return babylonMesh;
  1556. });
  1557. });
  1558. });
  1559. };
  1560. /** @hidden */
  1561. MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
  1562. var _this = this;
  1563. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
  1564. return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
  1565. var promises = new Array();
  1566. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Assign(extension.events);
  1567. for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
  1568. var event_1 = _a[_i];
  1569. promises.push(_this._loadAnimationEventAsync(extensionContext + "/events/" + event_1.index, context, animation, event_1, babylonAnimationGroup));
  1570. }
  1571. return Promise.all(promises).then(function () {
  1572. return babylonAnimationGroup;
  1573. });
  1574. });
  1575. });
  1576. };
  1577. MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
  1578. if (clip._objectURL) {
  1579. return clip._objectURL;
  1580. }
  1581. var promise;
  1582. if (clip.uri) {
  1583. promise = this._loader.loadUriAsync(context, clip, clip.uri);
  1584. }
  1585. else {
  1586. var bufferView = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/bufferView", this._loader.gltf.bufferViews, clip.bufferView);
  1587. promise = this._loader.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  1588. }
  1589. clip._objectURL = promise.then(function (data) {
  1590. return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
  1591. });
  1592. return clip._objectURL;
  1593. };
  1594. MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
  1595. var _this = this;
  1596. emitter._babylonSounds = emitter._babylonSounds || [];
  1597. if (!emitter._babylonData) {
  1598. var clipPromises = new Array();
  1599. var name_1 = emitter.name || "emitter" + emitter.index;
  1600. var options_1 = {
  1601. loop: false,
  1602. autoplay: false,
  1603. volume: emitter.volume == undefined ? 1 : emitter.volume,
  1604. };
  1605. var _loop_2 = function (i) {
  1606. var clipContext = "/extensions/" + this_1.name + "/clips";
  1607. var clip = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(clipContext, this_1._clips, emitter.clips[i].clip);
  1608. clipPromises.push(this_1._loadClipAsync(clipContext + "/" + emitter.clips[i].clip, clip).then(function (objectURL) {
  1609. var sound = emitter._babylonSounds[i] = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Sound"](name_1, objectURL, _this._loader.babylonScene, null, options_1);
  1610. sound.refDistance = emitter.refDistance || 1;
  1611. sound.maxDistance = emitter.maxDistance || 256;
  1612. sound.rolloffFactor = emitter.rolloffFactor || 1;
  1613. sound.distanceModel = emitter.distanceModel || 'exponential';
  1614. sound._positionInEmitterSpace = true;
  1615. }));
  1616. };
  1617. var this_1 = this;
  1618. for (var i = 0; i < emitter.clips.length; i++) {
  1619. _loop_2(i);
  1620. }
  1621. var promise = Promise.all(clipPromises).then(function () {
  1622. var weights = emitter.clips.map(function (clip) { return clip.weight || 1; });
  1623. var weightedSound = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["WeightedSound"](emitter.loop || false, emitter._babylonSounds, weights);
  1624. if (emitter.innerAngle) {
  1625. weightedSound.directionalConeInnerAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.innerAngle);
  1626. }
  1627. if (emitter.outerAngle) {
  1628. weightedSound.directionalConeOuterAngle = 2 * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToDegrees(emitter.outerAngle);
  1629. }
  1630. if (emitter.volume) {
  1631. weightedSound.volume = emitter.volume;
  1632. }
  1633. emitter._babylonData.sound = weightedSound;
  1634. });
  1635. emitter._babylonData = {
  1636. loaded: promise
  1637. };
  1638. }
  1639. return emitter._babylonData.loaded;
  1640. };
  1641. MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
  1642. switch (action) {
  1643. case "play" /* play */: {
  1644. return function (currentFrame) {
  1645. var frameOffset = (startOffset || 0) + (currentFrame - time);
  1646. sound.play(frameOffset);
  1647. };
  1648. }
  1649. case "stop" /* stop */: {
  1650. return function (currentFrame) {
  1651. sound.stop();
  1652. };
  1653. }
  1654. case "pause" /* pause */: {
  1655. return function (currentFrame) {
  1656. sound.pause();
  1657. };
  1658. }
  1659. default: {
  1660. throw new Error(context + ": Unsupported action " + action);
  1661. }
  1662. }
  1663. };
  1664. MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
  1665. var _this = this;
  1666. if (babylonAnimationGroup.targetedAnimations.length == 0) {
  1667. return Promise.resolve();
  1668. }
  1669. var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
  1670. var emitterIndex = event.emitter;
  1671. var emitter = _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get("/extensions/" + this.name + "/emitters", this._emitters, emitterIndex);
  1672. return this._loadEmitterAsync(context, emitter).then(function () {
  1673. var sound = emitter._babylonData.sound;
  1674. if (sound) {
  1675. var babylonAnimationEvent = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationEvent"](event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
  1676. babylonAnimation.animation.addEvent(babylonAnimationEvent);
  1677. // Make sure all started audio stops when this animation is terminated.
  1678. babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
  1679. sound.stop();
  1680. });
  1681. babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
  1682. sound.pause();
  1683. });
  1684. }
  1685. });
  1686. };
  1687. return MSFT_audio_emitter;
  1688. }());
  1689. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
  1690. /***/ }),
  1691. /***/ "./glTF/2.0/Extensions/MSFT_lod.ts":
  1692. /*!*****************************************!*\
  1693. !*** ./glTF/2.0/Extensions/MSFT_lod.ts ***!
  1694. \*****************************************/
  1695. /*! exports provided: MSFT_lod */
  1696. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1697. "use strict";
  1698. __webpack_require__.r(__webpack_exports__);
  1699. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return MSFT_lod; });
  1700. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  1701. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  1702. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  1703. var NAME = "MSFT_lod";
  1704. /**
  1705. * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_lod)
  1706. */
  1707. var MSFT_lod = /** @class */ (function () {
  1708. /** @hidden */
  1709. function MSFT_lod(loader) {
  1710. /**
  1711. * The name of this extension.
  1712. */
  1713. this.name = NAME;
  1714. /**
  1715. * Defines a number that determines the order the extensions are applied.
  1716. */
  1717. this.order = 100;
  1718. /**
  1719. * Maximum number of LODs to load, starting from the lowest LOD.
  1720. */
  1721. this.maxLODsToLoad = 10;
  1722. /**
  1723. * Observable raised when all node LODs of one level are loaded.
  1724. * The event data is the index of the loaded LOD starting from zero.
  1725. * Dispose the loader to cancel the loading of the next level of LODs.
  1726. */
  1727. this.onNodeLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  1728. /**
  1729. * Observable raised when all material LODs of one level are loaded.
  1730. * The event data is the index of the loaded LOD starting from zero.
  1731. * Dispose the loader to cancel the loading of the next level of LODs.
  1732. */
  1733. this.onMaterialLODsLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  1734. this._bufferLODs = new Array();
  1735. this._nodeIndexLOD = null;
  1736. this._nodeSignalLODs = new Array();
  1737. this._nodePromiseLODs = new Array();
  1738. this._nodeBufferLODs = new Array();
  1739. this._materialIndexLOD = null;
  1740. this._materialSignalLODs = new Array();
  1741. this._materialPromiseLODs = new Array();
  1742. this._materialBufferLODs = new Array();
  1743. this._loader = loader;
  1744. this.enabled = this._loader.isExtensionUsed(NAME);
  1745. }
  1746. /** @hidden */
  1747. MSFT_lod.prototype.dispose = function () {
  1748. delete this._loader;
  1749. this._nodeIndexLOD = null;
  1750. this._nodeSignalLODs.length = 0;
  1751. this._nodePromiseLODs.length = 0;
  1752. this._nodeBufferLODs.length = 0;
  1753. this._materialIndexLOD = null;
  1754. this._materialSignalLODs.length = 0;
  1755. this._materialPromiseLODs.length = 0;
  1756. this._materialBufferLODs.length = 0;
  1757. this.onMaterialLODsLoadedObservable.clear();
  1758. this.onNodeLODsLoadedObservable.clear();
  1759. };
  1760. /** @hidden */
  1761. MSFT_lod.prototype.onReady = function () {
  1762. var _this = this;
  1763. var _loop_1 = function (indexLOD) {
  1764. var promise = Promise.all(this_1._nodePromiseLODs[indexLOD]).then(function () {
  1765. if (indexLOD !== 0) {
  1766. _this._loader.endPerformanceCounter("Node LOD " + indexLOD);
  1767. _this._loader.log("Loaded node LOD " + indexLOD);
  1768. }
  1769. _this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);
  1770. if (indexLOD !== _this._nodePromiseLODs.length - 1) {
  1771. _this._loader.startPerformanceCounter("Node LOD " + (indexLOD + 1));
  1772. _this._loadBufferLOD(_this._nodeBufferLODs, indexLOD + 1);
  1773. if (_this._nodeSignalLODs[indexLOD]) {
  1774. _this._nodeSignalLODs[indexLOD].resolve();
  1775. }
  1776. }
  1777. });
  1778. this_1._loader._completePromises.push(promise);
  1779. };
  1780. var this_1 = this;
  1781. for (var indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {
  1782. _loop_1(indexLOD);
  1783. }
  1784. var _loop_2 = function (indexLOD) {
  1785. var promise = Promise.all(this_2._materialPromiseLODs[indexLOD]).then(function () {
  1786. if (indexLOD !== 0) {
  1787. _this._loader.endPerformanceCounter("Material LOD " + indexLOD);
  1788. _this._loader.log("Loaded material LOD " + indexLOD);
  1789. }
  1790. _this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);
  1791. if (indexLOD !== _this._materialPromiseLODs.length - 1) {
  1792. _this._loader.startPerformanceCounter("Material LOD " + (indexLOD + 1));
  1793. _this._loadBufferLOD(_this._materialBufferLODs, indexLOD + 1);
  1794. if (_this._materialSignalLODs[indexLOD]) {
  1795. _this._materialSignalLODs[indexLOD].resolve();
  1796. }
  1797. }
  1798. });
  1799. this_2._loader._completePromises.push(promise);
  1800. };
  1801. var this_2 = this;
  1802. for (var indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {
  1803. _loop_2(indexLOD);
  1804. }
  1805. };
  1806. /** @hidden */
  1807. MSFT_lod.prototype.loadSceneAsync = function (context, scene) {
  1808. var promise = this._loader.loadSceneAsync(context, scene);
  1809. this._loadBufferLOD(this._bufferLODs, 0);
  1810. return promise;
  1811. };
  1812. /** @hidden */
  1813. MSFT_lod.prototype.loadNodeAsync = function (context, node, assign) {
  1814. var _this = this;
  1815. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
  1816. var firstPromise;
  1817. var nodeLODs = _this._getLODs(extensionContext, node, _this._loader.gltf.nodes, extension.ids);
  1818. _this._loader.logOpen("" + extensionContext);
  1819. var _loop_3 = function (indexLOD) {
  1820. var nodeLOD = nodeLODs[indexLOD];
  1821. if (indexLOD !== 0) {
  1822. _this._nodeIndexLOD = indexLOD;
  1823. _this._nodeSignalLODs[indexLOD] = _this._nodeSignalLODs[indexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1824. }
  1825. var assign_1 = function (babylonTransformNode) { babylonTransformNode.setEnabled(false); };
  1826. var promise = _this._loader.loadNodeAsync("/nodes/" + nodeLOD.index, nodeLOD, assign_1).then(function (babylonMesh) {
  1827. if (indexLOD !== 0) {
  1828. // TODO: should not rely on _babylonTransformNode
  1829. var previousNodeLOD = nodeLODs[indexLOD - 1];
  1830. if (previousNodeLOD._babylonTransformNode) {
  1831. _this._disposeTransformNode(previousNodeLOD._babylonTransformNode);
  1832. delete previousNodeLOD._babylonTransformNode;
  1833. }
  1834. }
  1835. babylonMesh.setEnabled(true);
  1836. return babylonMesh;
  1837. });
  1838. _this._nodePromiseLODs[indexLOD] = _this._nodePromiseLODs[indexLOD] || [];
  1839. if (indexLOD === 0) {
  1840. firstPromise = promise;
  1841. }
  1842. else {
  1843. _this._nodeIndexLOD = null;
  1844. _this._nodePromiseLODs[indexLOD].push(promise);
  1845. }
  1846. };
  1847. for (var indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {
  1848. _loop_3(indexLOD);
  1849. }
  1850. _this._loader.logClose();
  1851. return firstPromise;
  1852. });
  1853. };
  1854. /** @hidden */
  1855. MSFT_lod.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  1856. var _this = this;
  1857. // Don't load material LODs if already loading a node LOD.
  1858. if (this._nodeIndexLOD) {
  1859. return null;
  1860. }
  1861. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
  1862. var firstPromise;
  1863. var materialLODs = _this._getLODs(extensionContext, material, _this._loader.gltf.materials, extension.ids);
  1864. _this._loader.logOpen("" + extensionContext);
  1865. var _loop_4 = function (indexLOD) {
  1866. var materialLOD = materialLODs[indexLOD];
  1867. if (indexLOD !== 0) {
  1868. _this._materialIndexLOD = indexLOD;
  1869. }
  1870. var promise = _this._loader._loadMaterialAsync("/materials/" + materialLOD.index, materialLOD, babylonMesh, babylonDrawMode, function (babylonMaterial) {
  1871. if (indexLOD === 0) {
  1872. assign(babylonMaterial);
  1873. }
  1874. }).then(function (babylonMaterial) {
  1875. if (indexLOD !== 0) {
  1876. assign(babylonMaterial);
  1877. // TODO: should not rely on _data
  1878. var previousDataLOD = materialLODs[indexLOD - 1]._data;
  1879. if (previousDataLOD[babylonDrawMode]) {
  1880. _this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);
  1881. delete previousDataLOD[babylonDrawMode];
  1882. }
  1883. }
  1884. return babylonMaterial;
  1885. });
  1886. _this._materialPromiseLODs[indexLOD] = _this._materialPromiseLODs[indexLOD] || [];
  1887. if (indexLOD === 0) {
  1888. firstPromise = promise;
  1889. }
  1890. else {
  1891. _this._materialIndexLOD = null;
  1892. _this._materialPromiseLODs[indexLOD].push(promise);
  1893. }
  1894. };
  1895. for (var indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {
  1896. _loop_4(indexLOD);
  1897. }
  1898. _this._loader.logClose();
  1899. return firstPromise;
  1900. });
  1901. };
  1902. /** @hidden */
  1903. MSFT_lod.prototype._loadUriAsync = function (context, property, uri) {
  1904. var _this = this;
  1905. // Defer the loading of uris if loading a node or material LOD.
  1906. if (this._nodeIndexLOD !== null) {
  1907. this._loader.log("deferred");
  1908. var previousIndexLOD = this._nodeIndexLOD - 1;
  1909. this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1910. return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(function () {
  1911. return _this._loader.loadUriAsync(context, property, uri);
  1912. });
  1913. }
  1914. else if (this._materialIndexLOD !== null) {
  1915. this._loader.log("deferred");
  1916. var previousIndexLOD = this._materialIndexLOD - 1;
  1917. this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  1918. return this._materialSignalLODs[previousIndexLOD].promise.then(function () {
  1919. return _this._loader.loadUriAsync(context, property, uri);
  1920. });
  1921. }
  1922. return null;
  1923. };
  1924. /** @hidden */
  1925. MSFT_lod.prototype.loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  1926. if (this._loader.parent.useRangeRequests && !buffer.uri) {
  1927. if (!this._loader.bin) {
  1928. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  1929. }
  1930. var loadAsync = function (bufferLODs, indexLOD) {
  1931. var start = byteOffset;
  1932. var end = start + byteLength - 1;
  1933. var bufferLOD = bufferLODs[indexLOD];
  1934. if (bufferLOD) {
  1935. bufferLOD.start = Math.min(bufferLOD.start, start);
  1936. bufferLOD.end = Math.max(bufferLOD.end, end);
  1937. }
  1938. else {
  1939. bufferLOD = { start: start, end: end, loaded: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Deferred"]() };
  1940. bufferLODs[indexLOD] = bufferLOD;
  1941. }
  1942. return bufferLOD.loaded.promise.then(function (data) {
  1943. return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);
  1944. });
  1945. };
  1946. this._loader.log("deferred");
  1947. if (this._nodeIndexLOD !== null) {
  1948. return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);
  1949. }
  1950. else if (this._materialIndexLOD !== null) {
  1951. return loadAsync(this._materialBufferLODs, this._materialIndexLOD);
  1952. }
  1953. else {
  1954. return loadAsync(this._bufferLODs, 0);
  1955. }
  1956. }
  1957. return null;
  1958. };
  1959. MSFT_lod.prototype._loadBufferLOD = function (bufferLODs, indexLOD) {
  1960. var bufferLOD = bufferLODs[indexLOD];
  1961. if (bufferLOD) {
  1962. this._loader.log("Loading buffer range [" + bufferLOD.start + "-" + bufferLOD.end + "]");
  1963. this._loader.bin.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(function (data) {
  1964. bufferLOD.loaded.resolve(data);
  1965. }, function (error) {
  1966. bufferLOD.loaded.reject(error);
  1967. });
  1968. }
  1969. };
  1970. /**
  1971. * Gets an array of LOD properties from lowest to highest.
  1972. */
  1973. MSFT_lod.prototype._getLODs = function (context, property, array, ids) {
  1974. if (this.maxLODsToLoad <= 0) {
  1975. throw new Error("maxLODsToLoad must be greater than zero");
  1976. }
  1977. var properties = new Array();
  1978. for (var i = ids.length - 1; i >= 0; i--) {
  1979. properties.push(_glTFLoader__WEBPACK_IMPORTED_MODULE_1__["ArrayItem"].Get(context + "/ids/" + ids[i], array, ids[i]));
  1980. if (properties.length === this.maxLODsToLoad) {
  1981. return properties;
  1982. }
  1983. }
  1984. properties.push(property);
  1985. return properties;
  1986. };
  1987. MSFT_lod.prototype._disposeTransformNode = function (babylonTransformNode) {
  1988. var _this = this;
  1989. var babylonMaterials = new Array();
  1990. var babylonMaterial = babylonTransformNode.material;
  1991. if (babylonMaterial) {
  1992. babylonMaterials.push(babylonMaterial);
  1993. }
  1994. for (var _i = 0, _a = babylonTransformNode.getChildMeshes(); _i < _a.length; _i++) {
  1995. var babylonMesh = _a[_i];
  1996. if (babylonMesh.material) {
  1997. babylonMaterials.push(babylonMesh.material);
  1998. }
  1999. }
  2000. babylonTransformNode.dispose();
  2001. var babylonMaterialsToDispose = babylonMaterials.filter(function (babylonMaterial) { return _this._loader.babylonScene.meshes.every(function (mesh) { return mesh.material != babylonMaterial; }); });
  2002. this._disposeMaterials(babylonMaterialsToDispose);
  2003. };
  2004. MSFT_lod.prototype._disposeMaterials = function (babylonMaterials) {
  2005. var babylonTextures = {};
  2006. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  2007. var babylonMaterial = babylonMaterials_1[_i];
  2008. for (var _a = 0, _b = babylonMaterial.getActiveTextures(); _a < _b.length; _a++) {
  2009. var babylonTexture = _b[_a];
  2010. babylonTextures[babylonTexture.uniqueId] = babylonTexture;
  2011. }
  2012. babylonMaterial.dispose();
  2013. }
  2014. for (var uniqueId in babylonTextures) {
  2015. for (var _c = 0, _d = this._loader.babylonScene.materials; _c < _d.length; _c++) {
  2016. var babylonMaterial = _d[_c];
  2017. if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {
  2018. delete babylonTextures[uniqueId];
  2019. }
  2020. }
  2021. }
  2022. for (var uniqueId in babylonTextures) {
  2023. babylonTextures[uniqueId].dispose();
  2024. }
  2025. };
  2026. return MSFT_lod;
  2027. }());
  2028. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_lod(loader); });
  2029. /***/ }),
  2030. /***/ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts":
  2031. /*!***************************************************!*\
  2032. !*** ./glTF/2.0/Extensions/MSFT_minecraftMesh.ts ***!
  2033. \***************************************************/
  2034. /*! exports provided: MSFT_minecraftMesh */
  2035. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2036. "use strict";
  2037. __webpack_require__.r(__webpack_exports__);
  2038. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return MSFT_minecraftMesh; });
  2039. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  2040. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2041. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2042. var NAME = "MSFT_minecraftMesh";
  2043. /** @hidden */
  2044. var MSFT_minecraftMesh = /** @class */ (function () {
  2045. function MSFT_minecraftMesh(loader) {
  2046. this.name = NAME;
  2047. this._loader = loader;
  2048. this.enabled = this._loader.isExtensionUsed(NAME);
  2049. }
  2050. MSFT_minecraftMesh.prototype.dispose = function () {
  2051. delete this._loader;
  2052. };
  2053. MSFT_minecraftMesh.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2054. var _this = this;
  2055. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  2056. if (extra) {
  2057. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2058. throw new Error(extraContext + ": Material type not supported");
  2059. }
  2060. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  2061. if (babylonMaterial.needAlphaBlending()) {
  2062. babylonMaterial.forceDepthWrite = true;
  2063. babylonMaterial.separateCullingPass = true;
  2064. }
  2065. babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;
  2066. babylonMaterial.twoSidedLighting = true;
  2067. return promise;
  2068. }
  2069. return null;
  2070. });
  2071. };
  2072. return MSFT_minecraftMesh;
  2073. }());
  2074. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_minecraftMesh(loader); });
  2075. /***/ }),
  2076. /***/ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts":
  2077. /*!*************************************************!*\
  2078. !*** ./glTF/2.0/Extensions/MSFT_sRGBFactors.ts ***!
  2079. \*************************************************/
  2080. /*! exports provided: MSFT_sRGBFactors */
  2081. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2082. "use strict";
  2083. __webpack_require__.r(__webpack_exports__);
  2084. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return MSFT_sRGBFactors; });
  2085. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Misc/tools");
  2086. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__);
  2087. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  2088. var NAME = "MSFT_sRGBFactors";
  2089. /** @hidden */
  2090. var MSFT_sRGBFactors = /** @class */ (function () {
  2091. function MSFT_sRGBFactors(loader) {
  2092. this.name = NAME;
  2093. this._loader = loader;
  2094. this.enabled = this._loader.isExtensionUsed(NAME);
  2095. }
  2096. MSFT_sRGBFactors.prototype.dispose = function () {
  2097. delete this._loader;
  2098. };
  2099. MSFT_sRGBFactors.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2100. var _this = this;
  2101. return _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].LoadExtraAsync(context, material, this.name, function (extraContext, extra) {
  2102. if (extra) {
  2103. if (!(babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2104. throw new Error(extraContext + ": Material type not supported");
  2105. }
  2106. var promise = _this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);
  2107. if (!babylonMaterial.albedoTexture) {
  2108. babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor);
  2109. }
  2110. if (!babylonMaterial.reflectivityTexture) {
  2111. babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor);
  2112. }
  2113. return promise;
  2114. }
  2115. return null;
  2116. });
  2117. };
  2118. return MSFT_sRGBFactors;
  2119. }());
  2120. _glTFLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoader"].RegisterExtension(NAME, function (loader) { return new MSFT_sRGBFactors(loader); });
  2121. /***/ }),
  2122. /***/ "./glTF/2.0/Extensions/index.ts":
  2123. /*!**************************************!*\
  2124. !*** ./glTF/2.0/Extensions/index.ts ***!
  2125. \**************************************/
  2126. /*! exports provided: EXT_lights_image_based, EXT_mesh_gpu_instancing, KHR_draco_mesh_compression, KHR_lights, KHR_materials_pbrSpecularGlossiness, KHR_materials_unlit, KHR_materials_clearcoat, KHR_materials_sheen, KHR_materials_specular, KHR_materials_ior, KHR_materials_variants, KHR_materials_transmission, KHR_mesh_quantization, KHR_texture_basisu, KHR_texture_transform, KHR_xmp, MSFT_audio_emitter, MSFT_lod, MSFT_minecraftMesh, MSFT_sRGBFactors, ExtrasAsMetadata */
  2127. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2128. "use strict";
  2129. __webpack_require__.r(__webpack_exports__);
  2130. /* harmony import */ var _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EXT_lights_image_based */ "./glTF/2.0/Extensions/EXT_lights_image_based.ts");
  2131. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _EXT_lights_image_based__WEBPACK_IMPORTED_MODULE_0__["EXT_lights_image_based"]; });
  2132. /* harmony import */ var _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EXT_mesh_gpu_instancing */ "./glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts");
  2133. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_1__["EXT_mesh_gpu_instancing"]; });
  2134. /* harmony import */ var _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_draco_mesh_compression */ "./glTF/2.0/Extensions/KHR_draco_mesh_compression.ts");
  2135. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _KHR_draco_mesh_compression__WEBPACK_IMPORTED_MODULE_2__["KHR_draco_mesh_compression"]; });
  2136. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  2137. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  2138. /* harmony import */ var _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./KHR_materials_pbrSpecularGlossiness */ "./glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts");
  2139. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _KHR_materials_pbrSpecularGlossiness__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_pbrSpecularGlossiness"]; });
  2140. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  2141. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_5__["KHR_materials_unlit"]; });
  2142. /* harmony import */ var _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./KHR_materials_clearcoat */ "./glTF/2.0/Extensions/KHR_materials_clearcoat.ts");
  2143. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_6__["KHR_materials_clearcoat"]; });
  2144. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  2145. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  2146. /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_specular */ "./glTF/2.0/Extensions/KHR_materials_specular.ts");
  2147. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_8__["KHR_materials_specular"]; });
  2148. /* harmony import */ var _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_ior */ "./glTF/2.0/Extensions/KHR_materials_ior.ts");
  2149. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_9__["KHR_materials_ior"]; });
  2150. /* harmony import */ var _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./KHR_materials_variants */ "./glTF/2.0/Extensions/KHR_materials_variants.ts");
  2151. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _KHR_materials_variants__WEBPACK_IMPORTED_MODULE_10__["KHR_materials_variants"]; });
  2152. /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./KHR_materials_transmission */ "./glTF/2.0/Extensions/KHR_materials_transmission.ts");
  2153. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_11__["KHR_materials_transmission"]; });
  2154. /* harmony import */ var _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./KHR_mesh_quantization */ "./glTF/2.0/Extensions/KHR_mesh_quantization.ts");
  2155. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _KHR_mesh_quantization__WEBPACK_IMPORTED_MODULE_12__["KHR_mesh_quantization"]; });
  2156. /* harmony import */ var _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./KHR_texture_basisu */ "./glTF/2.0/Extensions/KHR_texture_basisu.ts");
  2157. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _KHR_texture_basisu__WEBPACK_IMPORTED_MODULE_13__["KHR_texture_basisu"]; });
  2158. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  2159. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_14__["KHR_texture_transform"]; });
  2160. /* harmony import */ var _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./KHR_xmp */ "./glTF/2.0/Extensions/KHR_xmp.ts");
  2161. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _KHR_xmp__WEBPACK_IMPORTED_MODULE_15__["KHR_xmp"]; });
  2162. /* harmony import */ var _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./MSFT_audio_emitter */ "./glTF/2.0/Extensions/MSFT_audio_emitter.ts");
  2163. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _MSFT_audio_emitter__WEBPACK_IMPORTED_MODULE_16__["MSFT_audio_emitter"]; });
  2164. /* harmony import */ var _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./MSFT_lod */ "./glTF/2.0/Extensions/MSFT_lod.ts");
  2165. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _MSFT_lod__WEBPACK_IMPORTED_MODULE_17__["MSFT_lod"]; });
  2166. /* harmony import */ var _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./MSFT_minecraftMesh */ "./glTF/2.0/Extensions/MSFT_minecraftMesh.ts");
  2167. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _MSFT_minecraftMesh__WEBPACK_IMPORTED_MODULE_18__["MSFT_minecraftMesh"]; });
  2168. /* harmony import */ var _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./MSFT_sRGBFactors */ "./glTF/2.0/Extensions/MSFT_sRGBFactors.ts");
  2169. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _MSFT_sRGBFactors__WEBPACK_IMPORTED_MODULE_19__["MSFT_sRGBFactors"]; });
  2170. /* harmony import */ var _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./ExtrasAsMetadata */ "./glTF/2.0/Extensions/ExtrasAsMetadata.ts");
  2171. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _ExtrasAsMetadata__WEBPACK_IMPORTED_MODULE_20__["ExtrasAsMetadata"]; });
  2172. /***/ }),
  2173. /***/ "./glTF/2.0/glTFLoader.ts":
  2174. /*!********************************!*\
  2175. !*** ./glTF/2.0/glTFLoader.ts ***!
  2176. \********************************/
  2177. /*! exports provided: ArrayItem, GLTFLoader */
  2178. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2179. "use strict";
  2180. __webpack_require__.r(__webpack_exports__);
  2181. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return ArrayItem; });
  2182. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return GLTFLoader; });
  2183. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/deferred */ "babylonjs/Misc/tools");
  2184. /* harmony import */ var babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__);
  2185. /* harmony import */ var _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  2186. /**
  2187. * Helper class for working with arrays when loading the glTF asset
  2188. */
  2189. var ArrayItem = /** @class */ (function () {
  2190. function ArrayItem() {
  2191. }
  2192. /**
  2193. * Gets an item from the given array.
  2194. * @param context The context when loading the asset
  2195. * @param array The array to get the item from
  2196. * @param index The index to the array
  2197. * @returns The array item
  2198. */
  2199. ArrayItem.Get = function (context, array, index) {
  2200. if (!array || index == undefined || !array[index]) {
  2201. throw new Error(context + ": Failed to find index (" + index + ")");
  2202. }
  2203. return array[index];
  2204. };
  2205. /**
  2206. * Assign an `index` field to each item of the given array.
  2207. * @param array The array of items
  2208. */
  2209. ArrayItem.Assign = function (array) {
  2210. if (array) {
  2211. for (var index = 0; index < array.length; index++) {
  2212. array[index].index = index;
  2213. }
  2214. }
  2215. };
  2216. return ArrayItem;
  2217. }());
  2218. /**
  2219. * The glTF 2.0 loader
  2220. */
  2221. var GLTFLoader = /** @class */ (function () {
  2222. /** @hidden */
  2223. function GLTFLoader(parent) {
  2224. /** @hidden */
  2225. this._completePromises = new Array();
  2226. /** @hidden */
  2227. this._forAssetContainer = false;
  2228. /** Storage */
  2229. this._babylonLights = [];
  2230. /** @hidden */
  2231. this._disableInstancedMesh = 0;
  2232. this._disposed = false;
  2233. this._state = null;
  2234. this._extensions = new Array();
  2235. this._defaultBabylonMaterialData = {};
  2236. this._parent = parent;
  2237. }
  2238. /**
  2239. * Registers a loader extension.
  2240. * @param name The name of the loader extension.
  2241. * @param factory The factory function that creates the loader extension.
  2242. */
  2243. GLTFLoader.RegisterExtension = function (name, factory) {
  2244. if (GLTFLoader.UnregisterExtension(name)) {
  2245. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Extension with the name '" + name + "' already exists");
  2246. }
  2247. GLTFLoader._RegisteredExtensions[name] = {
  2248. factory: factory
  2249. };
  2250. };
  2251. /**
  2252. * Unregisters a loader extension.
  2253. * @param name The name of the loader extension.
  2254. * @returns A boolean indicating whether the extension has been unregistered
  2255. */
  2256. GLTFLoader.UnregisterExtension = function (name) {
  2257. if (!GLTFLoader._RegisteredExtensions[name]) {
  2258. return false;
  2259. }
  2260. delete GLTFLoader._RegisteredExtensions[name];
  2261. return true;
  2262. };
  2263. Object.defineProperty(GLTFLoader.prototype, "state", {
  2264. /**
  2265. * The loader state.
  2266. */
  2267. get: function () {
  2268. return this._state;
  2269. },
  2270. enumerable: false,
  2271. configurable: true
  2272. });
  2273. Object.defineProperty(GLTFLoader.prototype, "gltf", {
  2274. /**
  2275. * The object that represents the glTF JSON.
  2276. */
  2277. get: function () {
  2278. return this._gltf;
  2279. },
  2280. enumerable: false,
  2281. configurable: true
  2282. });
  2283. Object.defineProperty(GLTFLoader.prototype, "bin", {
  2284. /**
  2285. * The BIN chunk of a binary glTF.
  2286. */
  2287. get: function () {
  2288. return this._bin;
  2289. },
  2290. enumerable: false,
  2291. configurable: true
  2292. });
  2293. Object.defineProperty(GLTFLoader.prototype, "parent", {
  2294. /**
  2295. * The parent file loader.
  2296. */
  2297. get: function () {
  2298. return this._parent;
  2299. },
  2300. enumerable: false,
  2301. configurable: true
  2302. });
  2303. Object.defineProperty(GLTFLoader.prototype, "babylonScene", {
  2304. /**
  2305. * The Babylon scene when loading the asset.
  2306. */
  2307. get: function () {
  2308. return this._babylonScene;
  2309. },
  2310. enumerable: false,
  2311. configurable: true
  2312. });
  2313. Object.defineProperty(GLTFLoader.prototype, "rootBabylonMesh", {
  2314. /**
  2315. * The root Babylon mesh when loading the asset.
  2316. */
  2317. get: function () {
  2318. return this._rootBabylonMesh;
  2319. },
  2320. enumerable: false,
  2321. configurable: true
  2322. });
  2323. /** @hidden */
  2324. GLTFLoader.prototype.dispose = function () {
  2325. if (this._disposed) {
  2326. return;
  2327. }
  2328. this._disposed = true;
  2329. this._completePromises.length = 0;
  2330. for (var name_1 in this._extensions) {
  2331. var extension = this._extensions[name_1];
  2332. extension.dispose && extension.dispose();
  2333. delete this._extensions[name_1];
  2334. }
  2335. delete this._gltf;
  2336. delete this._babylonScene;
  2337. delete this._rootBabylonMesh;
  2338. this._parent.dispose();
  2339. };
  2340. /** @hidden */
  2341. GLTFLoader.prototype.importMeshAsync = function (meshesNames, scene, forAssetContainer, data, rootUrl, onProgress, fileName) {
  2342. var _this = this;
  2343. return Promise.resolve().then(function () {
  2344. _this._babylonScene = scene;
  2345. _this._rootUrl = rootUrl;
  2346. _this._fileName = fileName || "scene";
  2347. _this._forAssetContainer = forAssetContainer;
  2348. _this._loadData(data);
  2349. var nodes = null;
  2350. if (meshesNames) {
  2351. var nodeMap_1 = {};
  2352. if (_this._gltf.nodes) {
  2353. for (var _i = 0, _a = _this._gltf.nodes; _i < _a.length; _i++) {
  2354. var node = _a[_i];
  2355. if (node.name) {
  2356. nodeMap_1[node.name] = node.index;
  2357. }
  2358. }
  2359. }
  2360. var names = (meshesNames instanceof Array) ? meshesNames : [meshesNames];
  2361. nodes = names.map(function (name) {
  2362. var node = nodeMap_1[name];
  2363. if (node === undefined) {
  2364. throw new Error("Failed to find node '" + name + "'");
  2365. }
  2366. return node;
  2367. });
  2368. }
  2369. return _this._loadAsync(nodes, function () {
  2370. return {
  2371. meshes: _this._getMeshes(),
  2372. particleSystems: [],
  2373. skeletons: _this._getSkeletons(),
  2374. animationGroups: _this._getAnimationGroups(),
  2375. lights: _this._babylonLights,
  2376. transformNodes: _this._getTransformNodes()
  2377. };
  2378. });
  2379. });
  2380. };
  2381. /** @hidden */
  2382. GLTFLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  2383. var _this = this;
  2384. return Promise.resolve().then(function () {
  2385. _this._babylonScene = scene;
  2386. _this._rootUrl = rootUrl;
  2387. _this._fileName = fileName || "scene";
  2388. _this._loadData(data);
  2389. return _this._loadAsync(null, function () { return undefined; });
  2390. });
  2391. };
  2392. GLTFLoader.prototype._loadAsync = function (nodes, resultFunc) {
  2393. var _this = this;
  2394. return Promise.resolve().then(function () {
  2395. _this._uniqueRootUrl = (_this._rootUrl.indexOf("file:") === -1 && _this._fileName) ? _this._rootUrl : "" + _this._rootUrl + Date.now() + "/";
  2396. _this._loadExtensions();
  2397. _this._checkExtensions();
  2398. var loadingToReadyCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY];
  2399. var loadingToCompleteCounterName = _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING] + " => " + _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE];
  2400. _this._parent._startPerformanceCounter(loadingToReadyCounterName);
  2401. _this._parent._startPerformanceCounter(loadingToCompleteCounterName);
  2402. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING);
  2403. _this._extensionsOnLoading();
  2404. var promises = new Array();
  2405. // Block the marking of materials dirty until the scene is loaded.
  2406. var oldBlockMaterialDirtyMechanism = _this._babylonScene.blockMaterialDirtyMechanism;
  2407. _this._babylonScene.blockMaterialDirtyMechanism = true;
  2408. if (nodes) {
  2409. promises.push(_this.loadSceneAsync("/nodes", { nodes: nodes, index: -1 }));
  2410. }
  2411. else if (_this._gltf.scene != undefined || (_this._gltf.scenes && _this._gltf.scenes[0])) {
  2412. var scene = ArrayItem.Get("/scene", _this._gltf.scenes, _this._gltf.scene || 0);
  2413. promises.push(_this.loadSceneAsync("/scenes/" + scene.index, scene));
  2414. }
  2415. // Restore the blocking of material dirty.
  2416. _this._babylonScene.blockMaterialDirtyMechanism = oldBlockMaterialDirtyMechanism;
  2417. if (_this._parent.compileMaterials) {
  2418. promises.push(_this._compileMaterialsAsync());
  2419. }
  2420. if (_this._parent.compileShadowGenerators) {
  2421. promises.push(_this._compileShadowGeneratorsAsync());
  2422. }
  2423. var resultPromise = Promise.all(promises).then(function () {
  2424. if (_this._rootBabylonMesh) {
  2425. _this._rootBabylonMesh.setEnabled(true);
  2426. }
  2427. _this._extensionsOnReady();
  2428. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].READY);
  2429. _this._startAnimations();
  2430. return resultFunc();
  2431. });
  2432. resultPromise.then(function () {
  2433. _this._parent._endPerformanceCounter(loadingToReadyCounterName);
  2434. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].SetImmediate(function () {
  2435. if (!_this._disposed) {
  2436. Promise.all(_this._completePromises).then(function () {
  2437. _this._parent._endPerformanceCounter(loadingToCompleteCounterName);
  2438. _this._setState(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].COMPLETE);
  2439. _this._parent.onCompleteObservable.notifyObservers(undefined);
  2440. _this._parent.onCompleteObservable.clear();
  2441. _this.dispose();
  2442. }, function (error) {
  2443. _this._parent.onErrorObservable.notifyObservers(error);
  2444. _this._parent.onErrorObservable.clear();
  2445. _this.dispose();
  2446. });
  2447. }
  2448. });
  2449. });
  2450. return resultPromise;
  2451. }).catch(function (error) {
  2452. if (!_this._disposed) {
  2453. _this._parent.onErrorObservable.notifyObservers(error);
  2454. _this._parent.onErrorObservable.clear();
  2455. _this.dispose();
  2456. }
  2457. throw error;
  2458. });
  2459. };
  2460. GLTFLoader.prototype._loadData = function (data) {
  2461. this._gltf = data.json;
  2462. this._setupData();
  2463. if (data.bin) {
  2464. var buffers = this._gltf.buffers;
  2465. if (buffers && buffers[0] && !buffers[0].uri) {
  2466. var binaryBuffer = buffers[0];
  2467. if (binaryBuffer.byteLength < data.bin.byteLength - 3 || binaryBuffer.byteLength > data.bin.byteLength) {
  2468. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Binary buffer length (" + binaryBuffer.byteLength + ") from JSON does not match chunk length (" + data.bin.byteLength + ")");
  2469. }
  2470. this._bin = data.bin;
  2471. }
  2472. else {
  2473. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Unexpected BIN chunk");
  2474. }
  2475. }
  2476. };
  2477. GLTFLoader.prototype._setupData = function () {
  2478. ArrayItem.Assign(this._gltf.accessors);
  2479. ArrayItem.Assign(this._gltf.animations);
  2480. ArrayItem.Assign(this._gltf.buffers);
  2481. ArrayItem.Assign(this._gltf.bufferViews);
  2482. ArrayItem.Assign(this._gltf.cameras);
  2483. ArrayItem.Assign(this._gltf.images);
  2484. ArrayItem.Assign(this._gltf.materials);
  2485. ArrayItem.Assign(this._gltf.meshes);
  2486. ArrayItem.Assign(this._gltf.nodes);
  2487. ArrayItem.Assign(this._gltf.samplers);
  2488. ArrayItem.Assign(this._gltf.scenes);
  2489. ArrayItem.Assign(this._gltf.skins);
  2490. ArrayItem.Assign(this._gltf.textures);
  2491. if (this._gltf.nodes) {
  2492. var nodeParents = {};
  2493. for (var _i = 0, _a = this._gltf.nodes; _i < _a.length; _i++) {
  2494. var node = _a[_i];
  2495. if (node.children) {
  2496. for (var _b = 0, _c = node.children; _b < _c.length; _b++) {
  2497. var index = _c[_b];
  2498. nodeParents[index] = node.index;
  2499. }
  2500. }
  2501. }
  2502. var rootNode = this._createRootNode();
  2503. for (var _d = 0, _e = this._gltf.nodes; _d < _e.length; _d++) {
  2504. var node = _e[_d];
  2505. var parentIndex = nodeParents[node.index];
  2506. node.parent = parentIndex === undefined ? rootNode : this._gltf.nodes[parentIndex];
  2507. }
  2508. }
  2509. };
  2510. GLTFLoader.prototype._loadExtensions = function () {
  2511. for (var name_2 in GLTFLoader._RegisteredExtensions) {
  2512. var extension = GLTFLoader._RegisteredExtensions[name_2].factory(this);
  2513. if (extension.name !== name_2) {
  2514. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("The name of the glTF loader extension instance does not match the registered name: " + extension.name + " !== " + name_2);
  2515. }
  2516. this._extensions.push(extension);
  2517. this._parent.onExtensionLoadedObservable.notifyObservers(extension);
  2518. }
  2519. this._extensions.sort(function (a, b) { return (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE); });
  2520. this._parent.onExtensionLoadedObservable.clear();
  2521. };
  2522. GLTFLoader.prototype._checkExtensions = function () {
  2523. if (this._gltf.extensionsRequired) {
  2524. var _loop_1 = function (name_3) {
  2525. var available = this_1._extensions.some(function (extension) { return extension.name === name_3 && extension.enabled; });
  2526. if (!available) {
  2527. throw new Error("Require extension " + name_3 + " is not available");
  2528. }
  2529. };
  2530. var this_1 = this;
  2531. for (var _i = 0, _a = this._gltf.extensionsRequired; _i < _a.length; _i++) {
  2532. var name_3 = _a[_i];
  2533. _loop_1(name_3);
  2534. }
  2535. }
  2536. };
  2537. GLTFLoader.prototype._setState = function (state) {
  2538. this._state = state;
  2539. this.log(_glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"][this._state]);
  2540. };
  2541. GLTFLoader.prototype._createRootNode = function () {
  2542. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2543. this._rootBabylonMesh = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"]("__root__", this._babylonScene);
  2544. this._babylonScene._blockEntityCollection = false;
  2545. this._rootBabylonMesh.setEnabled(false);
  2546. var rootNode = {
  2547. _babylonTransformNode: this._rootBabylonMesh,
  2548. index: -1
  2549. };
  2550. switch (this._parent.coordinateSystemMode) {
  2551. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].AUTO: {
  2552. if (!this._babylonScene.useRightHandedSystem) {
  2553. rootNode.rotation = [0, 1, 0, 0];
  2554. rootNode.scale = [1, 1, -1];
  2555. GLTFLoader._LoadTransform(rootNode, this._rootBabylonMesh);
  2556. }
  2557. break;
  2558. }
  2559. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderCoordinateSystemMode"].FORCE_RIGHT_HANDED: {
  2560. this._babylonScene.useRightHandedSystem = true;
  2561. break;
  2562. }
  2563. default: {
  2564. throw new Error("Invalid coordinate system mode (" + this._parent.coordinateSystemMode + ")");
  2565. }
  2566. }
  2567. this._parent.onMeshLoadedObservable.notifyObservers(this._rootBabylonMesh);
  2568. return rootNode;
  2569. };
  2570. /**
  2571. * Loads a glTF scene.
  2572. * @param context The context when loading the asset
  2573. * @param scene The glTF scene property
  2574. * @returns A promise that resolves when the load is complete
  2575. */
  2576. GLTFLoader.prototype.loadSceneAsync = function (context, scene) {
  2577. var _this = this;
  2578. var extensionPromise = this._extensionsLoadSceneAsync(context, scene);
  2579. if (extensionPromise) {
  2580. return extensionPromise;
  2581. }
  2582. var promises = new Array();
  2583. this.logOpen(context + " " + (scene.name || ""));
  2584. if (scene.nodes) {
  2585. for (var _i = 0, _a = scene.nodes; _i < _a.length; _i++) {
  2586. var index = _a[_i];
  2587. var node = ArrayItem.Get(context + "/nodes/" + index, this._gltf.nodes, index);
  2588. promises.push(this.loadNodeAsync("/nodes/" + node.index, node, function (babylonMesh) {
  2589. babylonMesh.parent = _this._rootBabylonMesh;
  2590. }));
  2591. }
  2592. }
  2593. // Link all Babylon bones for each glTF node with the corresponding Babylon transform node.
  2594. // A glTF joint is a pointer to a glTF node in the glTF node hierarchy similar to Unity3D.
  2595. if (this._gltf.nodes) {
  2596. for (var _b = 0, _c = this._gltf.nodes; _b < _c.length; _b++) {
  2597. var node = _c[_b];
  2598. if (node._babylonTransformNode && node._babylonBones) {
  2599. for (var _d = 0, _e = node._babylonBones; _d < _e.length; _d++) {
  2600. var babylonBone = _e[_d];
  2601. babylonBone.linkTransformNode(node._babylonTransformNode);
  2602. }
  2603. }
  2604. }
  2605. }
  2606. promises.push(this._loadAnimationsAsync());
  2607. this.logClose();
  2608. return Promise.all(promises).then(function () { });
  2609. };
  2610. GLTFLoader.prototype._forEachPrimitive = function (node, callback) {
  2611. if (node._primitiveBabylonMeshes) {
  2612. for (var _i = 0, _a = node._primitiveBabylonMeshes; _i < _a.length; _i++) {
  2613. var babylonMesh = _a[_i];
  2614. callback(babylonMesh);
  2615. }
  2616. }
  2617. };
  2618. GLTFLoader.prototype._getMeshes = function () {
  2619. var meshes = new Array();
  2620. // Root mesh is always first.
  2621. meshes.push(this._rootBabylonMesh);
  2622. var nodes = this._gltf.nodes;
  2623. if (nodes) {
  2624. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2625. var node = nodes_1[_i];
  2626. this._forEachPrimitive(node, function (babylonMesh) {
  2627. meshes.push(babylonMesh);
  2628. });
  2629. }
  2630. }
  2631. return meshes;
  2632. };
  2633. GLTFLoader.prototype._getTransformNodes = function () {
  2634. var transformNodes = new Array();
  2635. var nodes = this._gltf.nodes;
  2636. if (nodes) {
  2637. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  2638. var node = nodes_2[_i];
  2639. if (node._babylonTransformNode && node._babylonTransformNode.getClassName() === "TransformNode") {
  2640. transformNodes.push(node._babylonTransformNode);
  2641. }
  2642. }
  2643. }
  2644. return transformNodes;
  2645. };
  2646. GLTFLoader.prototype._getSkeletons = function () {
  2647. var skeletons = new Array();
  2648. var skins = this._gltf.skins;
  2649. if (skins) {
  2650. for (var _i = 0, skins_1 = skins; _i < skins_1.length; _i++) {
  2651. var skin = skins_1[_i];
  2652. if (skin._data) {
  2653. skeletons.push(skin._data.babylonSkeleton);
  2654. }
  2655. }
  2656. }
  2657. return skeletons;
  2658. };
  2659. GLTFLoader.prototype._getAnimationGroups = function () {
  2660. var animationGroups = new Array();
  2661. var animations = this._gltf.animations;
  2662. if (animations) {
  2663. for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
  2664. var animation = animations_1[_i];
  2665. if (animation._babylonAnimationGroup) {
  2666. animationGroups.push(animation._babylonAnimationGroup);
  2667. }
  2668. }
  2669. }
  2670. return animationGroups;
  2671. };
  2672. GLTFLoader.prototype._startAnimations = function () {
  2673. switch (this._parent.animationStartMode) {
  2674. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].NONE: {
  2675. // do nothing
  2676. break;
  2677. }
  2678. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].FIRST: {
  2679. var babylonAnimationGroups = this._getAnimationGroups();
  2680. if (babylonAnimationGroups.length !== 0) {
  2681. babylonAnimationGroups[0].start(true);
  2682. }
  2683. break;
  2684. }
  2685. case _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderAnimationStartMode"].ALL: {
  2686. var babylonAnimationGroups = this._getAnimationGroups();
  2687. for (var _i = 0, babylonAnimationGroups_1 = babylonAnimationGroups; _i < babylonAnimationGroups_1.length; _i++) {
  2688. var babylonAnimationGroup = babylonAnimationGroups_1[_i];
  2689. babylonAnimationGroup.start(true);
  2690. }
  2691. break;
  2692. }
  2693. default: {
  2694. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("Invalid animation start mode (" + this._parent.animationStartMode + ")");
  2695. return;
  2696. }
  2697. }
  2698. };
  2699. /**
  2700. * Loads a glTF node.
  2701. * @param context The context when loading the asset
  2702. * @param node The glTF node property
  2703. * @param assign A function called synchronously after parsing the glTF properties
  2704. * @returns A promise that resolves with the loaded Babylon mesh when the load is complete
  2705. */
  2706. GLTFLoader.prototype.loadNodeAsync = function (context, node, assign) {
  2707. var _this = this;
  2708. if (assign === void 0) { assign = function () { }; }
  2709. var extensionPromise = this._extensionsLoadNodeAsync(context, node, assign);
  2710. if (extensionPromise) {
  2711. return extensionPromise;
  2712. }
  2713. if (node._babylonTransformNode) {
  2714. throw new Error(context + ": Invalid recursive node hierarchy");
  2715. }
  2716. var promises = new Array();
  2717. this.logOpen(context + " " + (node.name || ""));
  2718. var loadNode = function (babylonTransformNode) {
  2719. GLTFLoader.AddPointerMetadata(babylonTransformNode, context);
  2720. GLTFLoader._LoadTransform(node, babylonTransformNode);
  2721. if (node.camera != undefined) {
  2722. var camera = ArrayItem.Get(context + "/camera", _this._gltf.cameras, node.camera);
  2723. promises.push(_this.loadCameraAsync("/cameras/" + camera.index, camera, function (babylonCamera) {
  2724. babylonCamera.parent = babylonTransformNode;
  2725. }));
  2726. }
  2727. if (node.children) {
  2728. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  2729. var index = _a[_i];
  2730. var childNode = ArrayItem.Get(context + "/children/" + index, _this._gltf.nodes, index);
  2731. promises.push(_this.loadNodeAsync("/nodes/" + childNode.index, childNode, function (childBabylonMesh) {
  2732. childBabylonMesh.parent = babylonTransformNode;
  2733. }));
  2734. }
  2735. }
  2736. assign(babylonTransformNode);
  2737. };
  2738. if (node.mesh == undefined) {
  2739. var nodeName = node.name || "node" + node.index;
  2740. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2741. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](nodeName, this._babylonScene);
  2742. this._babylonScene._blockEntityCollection = false;
  2743. loadNode(node._babylonTransformNode);
  2744. }
  2745. else {
  2746. var mesh = ArrayItem.Get(context + "/mesh", this._gltf.meshes, node.mesh);
  2747. promises.push(this._loadMeshAsync("/meshes/" + mesh.index, node, mesh, loadNode));
  2748. }
  2749. this.logClose();
  2750. return Promise.all(promises).then(function () {
  2751. _this._forEachPrimitive(node, function (babylonMesh) {
  2752. if (babylonMesh.geometry && babylonMesh.geometry.useBoundingInfoFromGeometry) {
  2753. // simply apply the world matrices to the bounding info - the extends are already ok
  2754. babylonMesh._updateBoundingInfo();
  2755. }
  2756. else {
  2757. babylonMesh.refreshBoundingInfo(true);
  2758. }
  2759. });
  2760. return node._babylonTransformNode;
  2761. });
  2762. };
  2763. GLTFLoader.prototype._loadMeshAsync = function (context, node, mesh, assign) {
  2764. var primitives = mesh.primitives;
  2765. if (!primitives || !primitives.length) {
  2766. throw new Error(context + ": Primitives are missing");
  2767. }
  2768. if (primitives[0].index == undefined) {
  2769. ArrayItem.Assign(primitives);
  2770. }
  2771. var promises = new Array();
  2772. this.logOpen(context + " " + (mesh.name || ""));
  2773. var name = node.name || "node" + node.index;
  2774. if (primitives.length === 1) {
  2775. var primitive = mesh.primitives[0];
  2776. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name, node, mesh, primitive, function (babylonMesh) {
  2777. node._babylonTransformNode = babylonMesh;
  2778. node._primitiveBabylonMeshes = [babylonMesh];
  2779. }));
  2780. }
  2781. else {
  2782. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2783. node._babylonTransformNode = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TransformNode"](name, this._babylonScene);
  2784. this._babylonScene._blockEntityCollection = false;
  2785. node._primitiveBabylonMeshes = [];
  2786. for (var _i = 0, primitives_1 = primitives; _i < primitives_1.length; _i++) {
  2787. var primitive = primitives_1[_i];
  2788. promises.push(this._loadMeshPrimitiveAsync(context + "/primitives/" + primitive.index, name + "_primitive" + primitive.index, node, mesh, primitive, function (babylonMesh) {
  2789. babylonMesh.parent = node._babylonTransformNode;
  2790. node._primitiveBabylonMeshes.push(babylonMesh);
  2791. }));
  2792. }
  2793. }
  2794. if (node.skin != undefined) {
  2795. var skin = ArrayItem.Get(context + "/skin", this._gltf.skins, node.skin);
  2796. promises.push(this._loadSkinAsync("/skins/" + skin.index, node, skin));
  2797. }
  2798. assign(node._babylonTransformNode);
  2799. this.logClose();
  2800. return Promise.all(promises).then(function () {
  2801. return node._babylonTransformNode;
  2802. });
  2803. };
  2804. /**
  2805. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  2806. * @param context The context when loading the asset
  2807. * @param name The mesh name when loading the asset
  2808. * @param node The glTF node when loading the asset
  2809. * @param mesh The glTF mesh when loading the asset
  2810. * @param primitive The glTF mesh primitive property
  2811. * @param assign A function called synchronously after parsing the glTF properties
  2812. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  2813. */
  2814. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  2815. var _this = this;
  2816. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  2817. if (extensionPromise) {
  2818. return extensionPromise;
  2819. }
  2820. this.logOpen("" + context);
  2821. var shouldInstance = (this._disableInstancedMesh === 0) && this._parent.createInstances && (node.skin == undefined && !mesh.primitives[0].targets);
  2822. var babylonAbstractMesh;
  2823. var promise;
  2824. if (shouldInstance && primitive._instanceData) {
  2825. babylonAbstractMesh = primitive._instanceData.babylonSourceMesh.createInstance(name);
  2826. promise = primitive._instanceData.promise;
  2827. }
  2828. else {
  2829. var promises = new Array();
  2830. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  2831. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  2832. this._babylonScene._blockEntityCollection = false;
  2833. babylonMesh_1.overrideMaterialSideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  2834. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  2835. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  2836. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  2837. babylonGeometry.applyToMesh(babylonMesh_1);
  2838. });
  2839. }));
  2840. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  2841. if (primitive.material == undefined) {
  2842. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  2843. if (!babylonMaterial) {
  2844. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  2845. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2846. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  2847. }
  2848. babylonMesh_1.material = babylonMaterial;
  2849. }
  2850. else {
  2851. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  2852. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  2853. babylonMesh_1.material = babylonMaterial;
  2854. }));
  2855. }
  2856. promise = Promise.all(promises);
  2857. if (shouldInstance) {
  2858. primitive._instanceData = {
  2859. babylonSourceMesh: babylonMesh_1,
  2860. promise: promise
  2861. };
  2862. }
  2863. babylonAbstractMesh = babylonMesh_1;
  2864. }
  2865. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  2866. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  2867. assign(babylonAbstractMesh);
  2868. this.logClose();
  2869. return promise.then(function () {
  2870. return babylonAbstractMesh;
  2871. });
  2872. };
  2873. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  2874. var _this = this;
  2875. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  2876. if (extensionPromise) {
  2877. return extensionPromise;
  2878. }
  2879. var attributes = primitive.attributes;
  2880. if (!attributes) {
  2881. throw new Error(context + ": Attributes are missing");
  2882. }
  2883. var promises = new Array();
  2884. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  2885. if (primitive.indices == undefined) {
  2886. babylonMesh.isUnIndexed = true;
  2887. }
  2888. else {
  2889. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  2890. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2891. babylonGeometry.setIndices(data);
  2892. }));
  2893. }
  2894. var loadAttribute = function (attribute, kind, callback) {
  2895. if (attributes[attribute] == undefined) {
  2896. return;
  2897. }
  2898. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  2899. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  2900. babylonMesh._delayInfo.push(kind);
  2901. }
  2902. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2903. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  2904. if (babylonVertexBuffer.getKind() === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind && !_this.parent.alwaysComputeBoundingBox && !babylonMesh.skeleton) {
  2905. var mmin = accessor.min, mmax = accessor.max;
  2906. if (mmin !== undefined && mmax !== undefined) {
  2907. var min = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0], max = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1];
  2908. min.copyFromFloats.apply(min, mmin);
  2909. max.copyFromFloats.apply(max, mmax);
  2910. babylonGeometry._boundingInfo = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["BoundingInfo"](min, max);
  2911. babylonGeometry.useBoundingInfoFromGeometry = true;
  2912. }
  2913. }
  2914. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  2915. }));
  2916. if (kind == babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  2917. babylonMesh.numBoneInfluencers = 8;
  2918. }
  2919. if (callback) {
  2920. callback(accessor);
  2921. }
  2922. };
  2923. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  2924. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  2925. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  2926. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  2927. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  2928. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  2929. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  2930. loadAttribute("JOINTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind);
  2931. loadAttribute("WEIGHTS_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsExtraKind);
  2932. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  2933. if (accessor.type === "VEC4" /* VEC4 */) {
  2934. babylonMesh.hasVertexAlpha = true;
  2935. }
  2936. });
  2937. return Promise.all(promises).then(function () {
  2938. return babylonGeometry;
  2939. });
  2940. };
  2941. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  2942. if (!primitive.targets) {
  2943. return;
  2944. }
  2945. if (node._numMorphTargets == undefined) {
  2946. node._numMorphTargets = primitive.targets.length;
  2947. }
  2948. else if (primitive.targets.length !== node._numMorphTargets) {
  2949. throw new Error(context + ": Primitives do not have the same number of targets");
  2950. }
  2951. var targetNames = mesh.extras ? mesh.extras.targetNames : null;
  2952. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"](babylonMesh.getScene());
  2953. for (var index = 0; index < primitive.targets.length; index++) {
  2954. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  2955. var name_4 = targetNames ? targetNames[index] : "morphTarget" + index;
  2956. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"](name_4, weight, babylonMesh.getScene()));
  2957. // TODO: tell the target whether it has positions, normals, tangents
  2958. }
  2959. };
  2960. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  2961. if (!primitive.targets) {
  2962. return Promise.resolve();
  2963. }
  2964. var promises = new Array();
  2965. var morphTargetManager = babylonMesh.morphTargetManager;
  2966. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  2967. var babylonMorphTarget = morphTargetManager.getTarget(index);
  2968. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  2969. }
  2970. return Promise.all(promises).then(function () { });
  2971. };
  2972. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  2973. var _this = this;
  2974. var promises = new Array();
  2975. var loadAttribute = function (attribute, kind, setData) {
  2976. if (attributes[attribute] == undefined) {
  2977. return;
  2978. }
  2979. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  2980. if (!babylonVertexBuffer) {
  2981. return;
  2982. }
  2983. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  2984. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2985. setData(babylonVertexBuffer, data);
  2986. }));
  2987. };
  2988. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  2989. var positions = new Float32Array(data.length);
  2990. babylonVertexBuffer.forEach(data.length, function (value, index) {
  2991. positions[index] = data[index] + value;
  2992. });
  2993. babylonMorphTarget.setPositions(positions);
  2994. });
  2995. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  2996. var normals = new Float32Array(data.length);
  2997. babylonVertexBuffer.forEach(normals.length, function (value, index) {
  2998. normals[index] = data[index] + value;
  2999. });
  3000. babylonMorphTarget.setNormals(normals);
  3001. });
  3002. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  3003. var tangents = new Float32Array(data.length / 3 * 4);
  3004. var dataIndex = 0;
  3005. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  3006. // Tangent data for morph targets is stored as xyz delta.
  3007. // The vertexData.tangent is stored as xyzw.
  3008. // So we need to skip every fourth vertexData.tangent.
  3009. if (((index + 1) % 4) !== 0) {
  3010. tangents[dataIndex] = data[dataIndex] + value;
  3011. dataIndex++;
  3012. }
  3013. });
  3014. babylonMorphTarget.setTangents(tangents);
  3015. });
  3016. return Promise.all(promises).then(function () { });
  3017. };
  3018. GLTFLoader._LoadTransform = function (node, babylonNode) {
  3019. // Ignore the TRS of skinned nodes.
  3020. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  3021. if (node.skin != undefined) {
  3022. return;
  3023. }
  3024. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  3025. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  3026. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  3027. if (node.matrix) {
  3028. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  3029. matrix.decompose(scaling, rotation, position);
  3030. }
  3031. else {
  3032. if (node.translation) {
  3033. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  3034. }
  3035. if (node.rotation) {
  3036. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  3037. }
  3038. if (node.scale) {
  3039. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  3040. }
  3041. }
  3042. babylonNode.position = position;
  3043. babylonNode.rotationQuaternion = rotation;
  3044. babylonNode.scaling = scaling;
  3045. };
  3046. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  3047. var _this = this;
  3048. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  3049. if (extensionPromise) {
  3050. return extensionPromise;
  3051. }
  3052. var assignSkeleton = function (skeleton) {
  3053. _this._forEachPrimitive(node, function (babylonMesh) {
  3054. babylonMesh.skeleton = skeleton;
  3055. });
  3056. };
  3057. if (skin._data) {
  3058. assignSkeleton(skin._data.babylonSkeleton);
  3059. return skin._data.promise;
  3060. }
  3061. var skeletonId = "skeleton" + skin.index;
  3062. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3063. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  3064. this._babylonScene._blockEntityCollection = false;
  3065. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  3066. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  3067. this._loadBones(context, skin, babylonSkeleton);
  3068. assignSkeleton(babylonSkeleton);
  3069. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  3070. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  3071. });
  3072. skin._data = {
  3073. babylonSkeleton: babylonSkeleton,
  3074. promise: promise
  3075. };
  3076. return promise;
  3077. };
  3078. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  3079. var babylonBones = {};
  3080. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  3081. var index = _a[_i];
  3082. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  3083. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  3084. }
  3085. };
  3086. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  3087. var babylonBone = babylonBones[node.index];
  3088. if (babylonBone) {
  3089. return babylonBone;
  3090. }
  3091. var babylonParentBone = null;
  3092. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  3093. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  3094. }
  3095. var boneIndex = skin.joints.indexOf(node.index);
  3096. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  3097. babylonBones[node.index] = babylonBone;
  3098. node._babylonBones = node._babylonBones || [];
  3099. node._babylonBones.push(babylonBone);
  3100. return babylonBone;
  3101. };
  3102. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  3103. if (skin.inverseBindMatrices == undefined) {
  3104. return Promise.resolve(null);
  3105. }
  3106. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  3107. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  3108. };
  3109. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  3110. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  3111. var babylonBone = _a[_i];
  3112. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  3113. var boneIndex = babylonBone._index;
  3114. if (inverseBindMatricesData && boneIndex !== -1) {
  3115. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  3116. baseMatrix.invertToRef(baseMatrix);
  3117. }
  3118. var babylonParentBone = babylonBone.getParent();
  3119. if (babylonParentBone) {
  3120. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  3121. }
  3122. babylonBone.setRestPose(baseMatrix);
  3123. babylonBone.updateMatrix(baseMatrix, false, false);
  3124. babylonBone._updateDifferenceMatrix(undefined, false);
  3125. }
  3126. };
  3127. GLTFLoader.prototype._getNodeMatrix = function (node) {
  3128. return node.matrix ?
  3129. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  3130. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Compose(node.scale ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One(), node.rotation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity(), node.translation ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation) : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero());
  3131. };
  3132. /**
  3133. * Loads a glTF camera.
  3134. * @param context The context when loading the asset
  3135. * @param camera The glTF camera property
  3136. * @param assign A function called synchronously after parsing the glTF properties
  3137. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  3138. */
  3139. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  3140. if (assign === void 0) { assign = function () { }; }
  3141. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  3142. if (extensionPromise) {
  3143. return extensionPromise;
  3144. }
  3145. var promises = new Array();
  3146. this.logOpen(context + " " + (camera.name || ""));
  3147. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3148. var babylonCamera = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["FreeCamera"](camera.name || "camera" + camera.index, babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero(), this._babylonScene, false);
  3149. this._babylonScene._blockEntityCollection = false;
  3150. babylonCamera.ignoreParentScaling = true;
  3151. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  3152. switch (camera.type) {
  3153. case "perspective" /* PERSPECTIVE */: {
  3154. var perspective = camera.perspective;
  3155. if (!perspective) {
  3156. throw new Error(context + ": Camera perspective properties are missing");
  3157. }
  3158. babylonCamera.fov = perspective.yfov;
  3159. babylonCamera.minZ = perspective.znear;
  3160. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  3161. break;
  3162. }
  3163. case "orthographic" /* ORTHOGRAPHIC */: {
  3164. if (!camera.orthographic) {
  3165. throw new Error(context + ": Camera orthographic properties are missing");
  3166. }
  3167. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  3168. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  3169. babylonCamera.orthoRight = camera.orthographic.xmag;
  3170. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  3171. babylonCamera.orthoTop = camera.orthographic.ymag;
  3172. babylonCamera.minZ = camera.orthographic.znear;
  3173. babylonCamera.maxZ = camera.orthographic.zfar;
  3174. break;
  3175. }
  3176. default: {
  3177. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  3178. }
  3179. }
  3180. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  3181. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  3182. assign(babylonCamera);
  3183. this.logClose();
  3184. return Promise.all(promises).then(function () {
  3185. return babylonCamera;
  3186. });
  3187. };
  3188. GLTFLoader.prototype._loadAnimationsAsync = function () {
  3189. var animations = this._gltf.animations;
  3190. if (!animations) {
  3191. return Promise.resolve();
  3192. }
  3193. var promises = new Array();
  3194. for (var index = 0; index < animations.length; index++) {
  3195. var animation = animations[index];
  3196. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  3197. }
  3198. return Promise.all(promises).then(function () { });
  3199. };
  3200. /**
  3201. * Loads a glTF animation.
  3202. * @param context The context when loading the asset
  3203. * @param animation The glTF animation property
  3204. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  3205. */
  3206. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  3207. var promise = this._extensionsLoadAnimationAsync(context, animation);
  3208. if (promise) {
  3209. return promise;
  3210. }
  3211. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3212. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  3213. this._babylonScene._blockEntityCollection = false;
  3214. animation._babylonAnimationGroup = babylonAnimationGroup;
  3215. var promises = new Array();
  3216. ArrayItem.Assign(animation.channels);
  3217. ArrayItem.Assign(animation.samplers);
  3218. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  3219. var channel = _a[_i];
  3220. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  3221. }
  3222. return Promise.all(promises).then(function () {
  3223. babylonAnimationGroup.normalize(0);
  3224. return babylonAnimationGroup;
  3225. });
  3226. };
  3227. /**
  3228. * @hidden Loads a glTF animation channel.
  3229. * @param context The context when loading the asset
  3230. * @param animationContext The context of the animation when loading the asset
  3231. * @param animation The glTF animation property
  3232. * @param channel The glTF animation channel property
  3233. * @param babylonAnimationGroup The babylon animation group property
  3234. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  3235. * @returns A void promise when the channel load is complete
  3236. */
  3237. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  3238. var _this = this;
  3239. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  3240. if (channel.target.node == undefined) {
  3241. return Promise.resolve();
  3242. }
  3243. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  3244. // Ignore animations that have no animation targets.
  3245. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  3246. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  3247. return Promise.resolve();
  3248. }
  3249. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  3250. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  3251. var targetPath;
  3252. var animationType;
  3253. switch (channel.target.path) {
  3254. case "translation" /* TRANSLATION */: {
  3255. targetPath = "position";
  3256. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  3257. break;
  3258. }
  3259. case "rotation" /* ROTATION */: {
  3260. targetPath = "rotationQuaternion";
  3261. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  3262. break;
  3263. }
  3264. case "scale" /* SCALE */: {
  3265. targetPath = "scaling";
  3266. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  3267. break;
  3268. }
  3269. case "weights" /* WEIGHTS */: {
  3270. targetPath = "influence";
  3271. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  3272. break;
  3273. }
  3274. default: {
  3275. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  3276. }
  3277. }
  3278. var outputBufferOffset = 0;
  3279. var getNextOutputValue;
  3280. switch (targetPath) {
  3281. case "position": {
  3282. getNextOutputValue = function () {
  3283. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  3284. outputBufferOffset += 3;
  3285. return value;
  3286. };
  3287. break;
  3288. }
  3289. case "rotationQuaternion": {
  3290. getNextOutputValue = function () {
  3291. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  3292. outputBufferOffset += 4;
  3293. return value;
  3294. };
  3295. break;
  3296. }
  3297. case "scaling": {
  3298. getNextOutputValue = function () {
  3299. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  3300. outputBufferOffset += 3;
  3301. return value;
  3302. };
  3303. break;
  3304. }
  3305. case "influence": {
  3306. getNextOutputValue = function () {
  3307. var value = new Array(targetNode._numMorphTargets);
  3308. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  3309. value[i] = data.output[outputBufferOffset++];
  3310. }
  3311. return value;
  3312. };
  3313. break;
  3314. }
  3315. }
  3316. var getNextKey;
  3317. switch (data.interpolation) {
  3318. case "STEP" /* STEP */: {
  3319. getNextKey = function (frameIndex) { return ({
  3320. frame: data.input[frameIndex],
  3321. value: getNextOutputValue(),
  3322. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  3323. }); };
  3324. break;
  3325. }
  3326. case "LINEAR" /* LINEAR */: {
  3327. getNextKey = function (frameIndex) { return ({
  3328. frame: data.input[frameIndex],
  3329. value: getNextOutputValue()
  3330. }); };
  3331. break;
  3332. }
  3333. case "CUBICSPLINE" /* CUBICSPLINE */: {
  3334. getNextKey = function (frameIndex) { return ({
  3335. frame: data.input[frameIndex],
  3336. inTangent: getNextOutputValue(),
  3337. value: getNextOutputValue(),
  3338. outTangent: getNextOutputValue()
  3339. }); };
  3340. break;
  3341. }
  3342. }
  3343. var keys = new Array(data.input.length);
  3344. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  3345. keys[frameIndex] = getNextKey(frameIndex);
  3346. }
  3347. if (targetPath === "influence") {
  3348. var _loop_2 = function (targetIndex) {
  3349. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  3350. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  3351. babylonAnimation.setKeys(keys.map(function (key) { return ({
  3352. frame: key.frame,
  3353. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  3354. value: key.value[targetIndex],
  3355. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  3356. }); }));
  3357. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  3358. var babylonMesh = babylonAbstractMesh;
  3359. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  3360. var babylonAnimationClone = babylonAnimation.clone();
  3361. morphTarget.animations.push(babylonAnimationClone);
  3362. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  3363. });
  3364. };
  3365. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  3366. _loop_2(targetIndex);
  3367. }
  3368. }
  3369. else {
  3370. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  3371. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  3372. babylonAnimation.setKeys(keys);
  3373. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  3374. animationTargetOverride.animations.push(babylonAnimation);
  3375. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  3376. }
  3377. else {
  3378. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  3379. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  3380. }
  3381. }
  3382. });
  3383. };
  3384. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  3385. if (sampler._data) {
  3386. return sampler._data;
  3387. }
  3388. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  3389. switch (interpolation) {
  3390. case "STEP" /* STEP */:
  3391. case "LINEAR" /* LINEAR */:
  3392. case "CUBICSPLINE" /* CUBICSPLINE */: {
  3393. break;
  3394. }
  3395. default: {
  3396. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  3397. }
  3398. }
  3399. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  3400. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  3401. sampler._data = Promise.all([
  3402. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  3403. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  3404. ]).then(function (_a) {
  3405. var inputData = _a[0], outputData = _a[1];
  3406. return {
  3407. input: inputData,
  3408. interpolation: interpolation,
  3409. output: outputData,
  3410. };
  3411. });
  3412. return sampler._data;
  3413. };
  3414. GLTFLoader.prototype._loadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  3415. var extensionPromise = this._extensionsLoadBufferAsync(context, buffer, byteOffset, byteLength);
  3416. if (extensionPromise) {
  3417. return extensionPromise;
  3418. }
  3419. if (!buffer._data) {
  3420. if (buffer.uri) {
  3421. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  3422. }
  3423. else {
  3424. if (!this._bin) {
  3425. throw new Error(context + ": Uri is missing or the binary glTF is missing its binary chunk");
  3426. }
  3427. buffer._data = this._bin.readAsync(0, buffer.byteLength);
  3428. }
  3429. }
  3430. return buffer._data.then(function (data) {
  3431. try {
  3432. return new Uint8Array(data.buffer, data.byteOffset + byteOffset, byteLength);
  3433. }
  3434. catch (e) {
  3435. throw new Error(context + ": " + e.message);
  3436. }
  3437. });
  3438. };
  3439. /**
  3440. * Loads a glTF buffer view.
  3441. * @param context The context when loading the asset
  3442. * @param bufferView The glTF buffer view property
  3443. * @returns A promise that resolves with the loaded data when the load is complete
  3444. */
  3445. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  3446. var extensionPromise = this._extensionsLoadBufferViewAsync(context, bufferView);
  3447. if (extensionPromise) {
  3448. return extensionPromise;
  3449. }
  3450. if (bufferView._data) {
  3451. return bufferView._data;
  3452. }
  3453. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  3454. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer, (bufferView.byteOffset || 0), bufferView.byteLength);
  3455. return bufferView._data;
  3456. };
  3457. GLTFLoader.prototype._loadAccessorAsync = function (context, accessor, constructor) {
  3458. var _this = this;
  3459. if (accessor._data) {
  3460. return accessor._data;
  3461. }
  3462. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  3463. var byteStride = numComponents * babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType);
  3464. var length = numComponents * accessor.count;
  3465. if (accessor.bufferView == undefined) {
  3466. accessor._data = Promise.resolve(new constructor(length));
  3467. }
  3468. else {
  3469. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3470. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView_1.index, bufferView_1).then(function (data) {
  3471. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  3472. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  3473. }
  3474. else {
  3475. var typedArray_1 = new constructor(length);
  3476. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(data, accessor.byteOffset || 0, bufferView_1.byteStride || byteStride, numComponents, accessor.componentType, typedArray_1.length, accessor.normalized || false, function (value, index) {
  3477. typedArray_1[index] = value;
  3478. });
  3479. return typedArray_1;
  3480. }
  3481. });
  3482. }
  3483. if (accessor.sparse) {
  3484. var sparse_1 = accessor.sparse;
  3485. accessor._data = accessor._data.then(function (data) {
  3486. var typedArray = data;
  3487. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  3488. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  3489. return Promise.all([
  3490. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  3491. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  3492. ]).then(function (_a) {
  3493. var indicesData = _a[0], valuesData = _a[1];
  3494. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  3495. var sparseLength = numComponents * sparse_1.count;
  3496. var values;
  3497. if (accessor.componentType === 5126 /* FLOAT */ && !accessor.normalized) {
  3498. values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  3499. }
  3500. else {
  3501. var sparseData = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, sparseLength);
  3502. values = new constructor(sparseLength);
  3503. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ForEach(sparseData, 0, byteStride, numComponents, accessor.componentType, values.length, accessor.normalized || false, function (value, index) {
  3504. values[index] = value;
  3505. });
  3506. }
  3507. var valuesIndex = 0;
  3508. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  3509. var dataIndex = indices[indicesIndex] * numComponents;
  3510. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  3511. typedArray[dataIndex++] = values[valuesIndex++];
  3512. }
  3513. }
  3514. return typedArray;
  3515. });
  3516. });
  3517. }
  3518. return accessor._data;
  3519. };
  3520. /** @hidden */
  3521. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  3522. return this._loadAccessorAsync(context, accessor, Float32Array);
  3523. };
  3524. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  3525. if (accessor.type !== "SCALAR" /* SCALAR */) {
  3526. throw new Error(context + "/type: Invalid value " + accessor.type);
  3527. }
  3528. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  3529. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  3530. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  3531. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  3532. }
  3533. if (accessor._data) {
  3534. return accessor._data;
  3535. }
  3536. if (accessor.sparse) {
  3537. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", accessor.componentType);
  3538. accessor._data = this._loadAccessorAsync(context, accessor, constructor);
  3539. }
  3540. else {
  3541. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3542. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  3543. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  3544. });
  3545. }
  3546. return accessor._data;
  3547. };
  3548. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  3549. var _this = this;
  3550. if (bufferView._babylonBuffer) {
  3551. return bufferView._babylonBuffer;
  3552. }
  3553. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  3554. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  3555. });
  3556. return bufferView._babylonBuffer;
  3557. };
  3558. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  3559. var _this = this;
  3560. if (accessor._babylonVertexBuffer) {
  3561. return accessor._babylonVertexBuffer;
  3562. }
  3563. if (accessor.sparse) {
  3564. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3565. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3566. });
  3567. }
  3568. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  3569. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  3570. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("Accessor byte offset is not a multiple of component type byte length");
  3571. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3572. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3573. });
  3574. }
  3575. // Load joint indices as a float array since the shaders expect float data but glTF uses unsigned byte/short.
  3576. // This prevents certain platforms (e.g. D3D) from having to convert the data to float on the fly.
  3577. else if (kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind || kind === babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesExtraKind) {
  3578. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  3579. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  3580. });
  3581. }
  3582. else {
  3583. var bufferView_2 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  3584. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_2, kind).then(function (babylonBuffer) {
  3585. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  3586. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), babylonBuffer, kind, false, false, bufferView_2.byteStride, false, accessor.byteOffset, size, accessor.componentType, accessor.normalized, true);
  3587. });
  3588. }
  3589. return accessor._babylonVertexBuffer;
  3590. };
  3591. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  3592. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3593. throw new Error(context + ": Material type not supported");
  3594. }
  3595. var promises = new Array();
  3596. if (properties) {
  3597. if (properties.baseColorFactor) {
  3598. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  3599. babylonMaterial.alpha = properties.baseColorFactor[3];
  3600. }
  3601. else {
  3602. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  3603. }
  3604. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  3605. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  3606. if (properties.baseColorTexture) {
  3607. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  3608. texture.name = babylonMaterial.name + " (Base Color)";
  3609. babylonMaterial.albedoTexture = texture;
  3610. }));
  3611. }
  3612. if (properties.metallicRoughnessTexture) {
  3613. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  3614. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  3615. babylonMaterial.metallicTexture = texture;
  3616. }));
  3617. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  3618. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  3619. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  3620. }
  3621. }
  3622. return Promise.all(promises).then(function () { });
  3623. };
  3624. /** @hidden */
  3625. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3626. if (assign === void 0) { assign = function () { }; }
  3627. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  3628. if (extensionPromise) {
  3629. return extensionPromise;
  3630. }
  3631. material._data = material._data || {};
  3632. var babylonData = material._data[babylonDrawMode];
  3633. if (!babylonData) {
  3634. this.logOpen(context + " " + (material.name || ""));
  3635. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  3636. babylonData = {
  3637. babylonMaterial: babylonMaterial,
  3638. babylonMeshes: [],
  3639. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  3640. };
  3641. material._data[babylonDrawMode] = babylonData;
  3642. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  3643. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  3644. this.logClose();
  3645. }
  3646. babylonData.babylonMeshes.push(babylonMesh);
  3647. babylonMesh.onDisposeObservable.addOnce(function () {
  3648. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  3649. if (index !== -1) {
  3650. babylonData.babylonMeshes.splice(index, 1);
  3651. }
  3652. });
  3653. assign(babylonData.babylonMaterial);
  3654. return babylonData.promise.then(function () {
  3655. return babylonData.babylonMaterial;
  3656. });
  3657. };
  3658. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  3659. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3660. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  3661. this._babylonScene._blockEntityCollection = false;
  3662. // Moved to mesh so user can change materials on gltf meshes: babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
  3663. babylonMaterial.fillMode = babylonDrawMode;
  3664. babylonMaterial.enableSpecularAntiAliasing = true;
  3665. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  3666. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  3667. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  3668. babylonMaterial.metallic = 1;
  3669. babylonMaterial.roughness = 1;
  3670. return babylonMaterial;
  3671. };
  3672. /**
  3673. * Creates a Babylon material from a glTF material.
  3674. * @param context The context when loading the asset
  3675. * @param material The glTF material property
  3676. * @param babylonDrawMode The draw mode for the Babylon material
  3677. * @returns The Babylon material
  3678. */
  3679. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  3680. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  3681. if (extensionPromise) {
  3682. return extensionPromise;
  3683. }
  3684. var name = material.name || "material" + material.index;
  3685. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  3686. return babylonMaterial;
  3687. };
  3688. /**
  3689. * Loads properties from a glTF material into a Babylon material.
  3690. * @param context The context when loading the asset
  3691. * @param material The glTF material property
  3692. * @param babylonMaterial The Babylon material
  3693. * @returns A promise that resolves when the load is complete
  3694. */
  3695. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3696. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  3697. if (extensionPromise) {
  3698. return extensionPromise;
  3699. }
  3700. var promises = new Array();
  3701. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  3702. if (material.pbrMetallicRoughness) {
  3703. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  3704. }
  3705. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  3706. return Promise.all(promises).then(function () { });
  3707. };
  3708. /**
  3709. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  3710. * @param context The context when loading the asset
  3711. * @param material The glTF material property
  3712. * @param babylonMaterial The Babylon material
  3713. * @returns A promise that resolves when the load is complete
  3714. */
  3715. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  3716. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3717. throw new Error(context + ": Material type not supported");
  3718. }
  3719. var promises = new Array();
  3720. babylonMaterial.emissiveColor = material.emissiveFactor ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(material.emissiveFactor) : new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"](0, 0, 0);
  3721. if (material.doubleSided) {
  3722. babylonMaterial.backFaceCulling = false;
  3723. babylonMaterial.twoSidedLighting = true;
  3724. }
  3725. if (material.normalTexture) {
  3726. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  3727. texture.name = babylonMaterial.name + " (Normal)";
  3728. babylonMaterial.bumpTexture = texture;
  3729. }));
  3730. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  3731. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  3732. if (material.normalTexture.scale != undefined) {
  3733. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  3734. }
  3735. babylonMaterial.forceIrradianceInFragment = true;
  3736. }
  3737. if (material.occlusionTexture) {
  3738. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  3739. texture.name = babylonMaterial.name + " (Occlusion)";
  3740. babylonMaterial.ambientTexture = texture;
  3741. }));
  3742. babylonMaterial.useAmbientInGrayScale = true;
  3743. if (material.occlusionTexture.strength != undefined) {
  3744. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  3745. }
  3746. }
  3747. if (material.emissiveTexture) {
  3748. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  3749. texture.name = babylonMaterial.name + " (Emissive)";
  3750. babylonMaterial.emissiveTexture = texture;
  3751. }));
  3752. }
  3753. return Promise.all(promises).then(function () { });
  3754. };
  3755. /**
  3756. * Loads the alpha properties from a glTF material into a Babylon material.
  3757. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  3758. * @param context The context when loading the asset
  3759. * @param material The glTF material property
  3760. * @param babylonMaterial The Babylon material
  3761. */
  3762. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  3763. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  3764. throw new Error(context + ": Material type not supported");
  3765. }
  3766. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  3767. switch (alphaMode) {
  3768. case "OPAQUE" /* OPAQUE */: {
  3769. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  3770. break;
  3771. }
  3772. case "MASK" /* MASK */: {
  3773. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  3774. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  3775. if (babylonMaterial.albedoTexture) {
  3776. babylonMaterial.albedoTexture.hasAlpha = true;
  3777. }
  3778. break;
  3779. }
  3780. case "BLEND" /* BLEND */: {
  3781. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  3782. if (babylonMaterial.albedoTexture) {
  3783. babylonMaterial.albedoTexture.hasAlpha = true;
  3784. babylonMaterial.useAlphaFromAlbedoTexture = true;
  3785. }
  3786. break;
  3787. }
  3788. default: {
  3789. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  3790. }
  3791. }
  3792. };
  3793. /**
  3794. * Loads a glTF texture info.
  3795. * @param context The context when loading the asset
  3796. * @param textureInfo The glTF texture info property
  3797. * @param assign A function called synchronously after parsing the glTF properties
  3798. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  3799. */
  3800. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  3801. var _this = this;
  3802. if (assign === void 0) { assign = function () { }; }
  3803. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  3804. if (extensionPromise) {
  3805. return extensionPromise;
  3806. }
  3807. this.logOpen("" + context);
  3808. if (textureInfo.texCoord >= 2) {
  3809. throw new Error(context + "/texCoord: Invalid value (" + textureInfo.texCoord + ")");
  3810. }
  3811. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  3812. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  3813. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  3814. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  3815. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  3816. assign(babylonTexture);
  3817. });
  3818. this.logClose();
  3819. return promise;
  3820. };
  3821. /** @hidden */
  3822. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  3823. if (assign === void 0) { assign = function () { }; }
  3824. var extensionPromise = this._extensionsLoadTextureAsync(context, texture, assign);
  3825. if (extensionPromise) {
  3826. return extensionPromise;
  3827. }
  3828. this.logOpen(context + " " + (texture.name || ""));
  3829. var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  3830. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  3831. var promise = this._createTextureAsync(context, sampler, image, assign);
  3832. this.logClose();
  3833. return promise;
  3834. };
  3835. /** @hidden */
  3836. GLTFLoader.prototype._createTextureAsync = function (context, sampler, image, assign) {
  3837. var _this = this;
  3838. if (assign === void 0) { assign = function () { }; }
  3839. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  3840. var promises = new Array();
  3841. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  3842. this._babylonScene._blockEntityCollection = this._forAssetContainer;
  3843. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](null, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  3844. if (!_this._disposed) {
  3845. deferred.resolve();
  3846. }
  3847. }, function (message, exception) {
  3848. if (!_this._disposed) {
  3849. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  3850. }
  3851. }, undefined, undefined, undefined, image.mimeType);
  3852. this._babylonScene._blockEntityCollection = false;
  3853. promises.push(deferred.promise);
  3854. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  3855. var name = image.uri || _this._fileName + "#image" + image.index;
  3856. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  3857. babylonTexture.updateURL(dataUrl, data);
  3858. }));
  3859. babylonTexture.wrapU = samplerData.wrapU;
  3860. babylonTexture.wrapV = samplerData.wrapV;
  3861. assign(babylonTexture);
  3862. return Promise.all(promises).then(function () {
  3863. return babylonTexture;
  3864. });
  3865. };
  3866. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  3867. if (!sampler._data) {
  3868. sampler._data = {
  3869. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  3870. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  3871. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  3872. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  3873. };
  3874. }
  3875. return sampler._data;
  3876. };
  3877. /**
  3878. * Loads a glTF image.
  3879. * @param context The context when loading the asset
  3880. * @param image The glTF image property
  3881. * @returns A promise that resolves with the loaded data when the load is complete
  3882. */
  3883. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  3884. if (!image._data) {
  3885. this.logOpen(context + " " + (image.name || ""));
  3886. if (image.uri) {
  3887. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  3888. }
  3889. else {
  3890. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  3891. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  3892. }
  3893. this.logClose();
  3894. }
  3895. return image._data;
  3896. };
  3897. /**
  3898. * Loads a glTF uri.
  3899. * @param context The context when loading the asset
  3900. * @param property The glTF property associated with the uri
  3901. * @param uri The base64 or relative uri
  3902. * @returns A promise that resolves with the loaded data when the load is complete
  3903. */
  3904. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  3905. var _this = this;
  3906. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  3907. if (extensionPromise) {
  3908. return extensionPromise;
  3909. }
  3910. if (!GLTFLoader._ValidateUri(uri)) {
  3911. throw new Error(context + ": '" + uri + "' is invalid");
  3912. }
  3913. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  3914. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  3915. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  3916. return Promise.resolve(data);
  3917. }
  3918. this.log("Loading " + uri);
  3919. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  3920. return new Promise(function (resolve, reject) {
  3921. _this._parent._loadFile(url, _this._babylonScene, function (data) {
  3922. if (!_this._disposed) {
  3923. _this.log("Loaded " + uri + " (" + data.byteLength + " bytes)");
  3924. resolve(new Uint8Array(data));
  3925. }
  3926. }, true, function (request) {
  3927. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  3928. });
  3929. });
  3930. });
  3931. };
  3932. /**
  3933. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  3934. * @param babylonObject the Babylon object with metadata
  3935. * @param pointer the JSON pointer
  3936. */
  3937. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  3938. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  3939. var gltf = (metadata.gltf = metadata.gltf || {});
  3940. var pointers = (gltf.pointers = gltf.pointers || []);
  3941. pointers.push(pointer);
  3942. };
  3943. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  3944. // Set defaults if undefined
  3945. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  3946. switch (mode) {
  3947. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  3948. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  3949. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  3950. default:
  3951. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Invalid value (" + mode + ")");
  3952. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  3953. }
  3954. };
  3955. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  3956. // Set defaults if undefined
  3957. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  3958. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  3959. if (magFilter === 9729 /* LINEAR */) {
  3960. switch (minFilter) {
  3961. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  3962. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  3963. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  3964. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  3965. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  3966. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  3967. default:
  3968. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3969. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  3970. }
  3971. }
  3972. else {
  3973. if (magFilter !== 9728 /* NEAREST */) {
  3974. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  3975. }
  3976. switch (minFilter) {
  3977. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  3978. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  3979. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3980. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  3981. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  3982. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  3983. default:
  3984. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  3985. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  3986. }
  3987. }
  3988. };
  3989. GLTFLoader._GetTypedArrayConstructor = function (context, componentType) {
  3990. switch (componentType) {
  3991. case 5120 /* BYTE */: return Int8Array;
  3992. case 5121 /* UNSIGNED_BYTE */: return Uint8Array;
  3993. case 5122 /* SHORT */: return Int16Array;
  3994. case 5123 /* UNSIGNED_SHORT */: return Uint16Array;
  3995. case 5125 /* UNSIGNED_INT */: return Uint32Array;
  3996. case 5126 /* FLOAT */: return Float32Array;
  3997. default: throw new Error(context + ": Invalid component type " + componentType);
  3998. }
  3999. };
  4000. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  4001. var buffer = bufferView.buffer;
  4002. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  4003. var constructor = GLTFLoader._GetTypedArrayConstructor(context + "/componentType", componentType);
  4004. try {
  4005. return new constructor(buffer, byteOffset, length);
  4006. }
  4007. catch (e) {
  4008. throw new Error(context + ": " + e);
  4009. }
  4010. };
  4011. GLTFLoader._GetNumComponents = function (context, type) {
  4012. switch (type) {
  4013. case "SCALAR": return 1;
  4014. case "VEC2": return 2;
  4015. case "VEC3": return 3;
  4016. case "VEC4": return 4;
  4017. case "MAT2": return 4;
  4018. case "MAT3": return 9;
  4019. case "MAT4": return 16;
  4020. }
  4021. throw new Error(context + ": Invalid type (" + type + ")");
  4022. };
  4023. GLTFLoader._ValidateUri = function (uri) {
  4024. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  4025. };
  4026. /** @hidden */
  4027. GLTFLoader._GetDrawMode = function (context, mode) {
  4028. if (mode == undefined) {
  4029. mode = 4 /* TRIANGLES */;
  4030. }
  4031. switch (mode) {
  4032. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  4033. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  4034. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  4035. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  4036. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  4037. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  4038. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  4039. }
  4040. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  4041. };
  4042. GLTFLoader.prototype._compileMaterialsAsync = function () {
  4043. var _this = this;
  4044. this._parent._startPerformanceCounter("Compile materials");
  4045. var promises = new Array();
  4046. if (this._gltf.materials) {
  4047. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  4048. var material = _a[_i];
  4049. if (material._data) {
  4050. for (var babylonDrawMode in material._data) {
  4051. var babylonData = material._data[babylonDrawMode];
  4052. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  4053. var babylonMesh = _c[_b];
  4054. // Ensure nonUniformScaling is set if necessary.
  4055. babylonMesh.computeWorldMatrix(true);
  4056. var babylonMaterial = babylonData.babylonMaterial;
  4057. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  4058. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { useInstances: true }));
  4059. if (this._parent.useClipPlane) {
  4060. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  4061. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true, useInstances: true }));
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. return Promise.all(promises).then(function () {
  4069. _this._parent._endPerformanceCounter("Compile materials");
  4070. });
  4071. };
  4072. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  4073. var _this = this;
  4074. this._parent._startPerformanceCounter("Compile shadow generators");
  4075. var promises = new Array();
  4076. var lights = this._babylonScene.lights;
  4077. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  4078. var light = lights_1[_i];
  4079. var generator = light.getShadowGenerator();
  4080. if (generator) {
  4081. promises.push(generator.forceCompilationAsync());
  4082. }
  4083. }
  4084. return Promise.all(promises).then(function () {
  4085. _this._parent._endPerformanceCounter("Compile shadow generators");
  4086. });
  4087. };
  4088. GLTFLoader.prototype._forEachExtensions = function (action) {
  4089. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  4090. var extension = _a[_i];
  4091. if (extension.enabled) {
  4092. action(extension);
  4093. }
  4094. }
  4095. };
  4096. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  4097. for (var _i = 0, _a = this._extensions; _i < _a.length; _i++) {
  4098. var extension = _a[_i];
  4099. if (extension.enabled) {
  4100. var id = extension.name + "." + functionName;
  4101. var loaderProperty = property;
  4102. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  4103. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  4104. if (!activeLoaderExtensionFunctions[id]) {
  4105. activeLoaderExtensionFunctions[id] = true;
  4106. try {
  4107. var result = actionAsync(extension);
  4108. if (result) {
  4109. return result;
  4110. }
  4111. }
  4112. finally {
  4113. delete activeLoaderExtensionFunctions[id];
  4114. }
  4115. }
  4116. }
  4117. }
  4118. return null;
  4119. };
  4120. GLTFLoader.prototype._extensionsOnLoading = function () {
  4121. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  4122. };
  4123. GLTFLoader.prototype._extensionsOnReady = function () {
  4124. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  4125. };
  4126. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  4127. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  4128. };
  4129. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  4130. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  4131. };
  4132. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  4133. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  4134. };
  4135. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  4136. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  4137. };
  4138. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  4139. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  4140. };
  4141. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  4142. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  4143. };
  4144. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  4145. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  4146. };
  4147. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  4148. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  4149. };
  4150. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  4151. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  4152. };
  4153. GLTFLoader.prototype._extensionsLoadTextureAsync = function (context, texture, assign) {
  4154. return this._applyExtensions(texture, "loadTexture", function (extension) { return extension._loadTextureAsync && extension._loadTextureAsync(context, texture, assign); });
  4155. };
  4156. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  4157. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  4158. };
  4159. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  4160. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  4161. };
  4162. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  4163. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  4164. };
  4165. GLTFLoader.prototype._extensionsLoadBufferViewAsync = function (context, bufferView) {
  4166. return this._applyExtensions(bufferView, "loadBufferView", function (extension) { return extension.loadBufferViewAsync && extension.loadBufferViewAsync(context, bufferView); });
  4167. };
  4168. GLTFLoader.prototype._extensionsLoadBufferAsync = function (context, buffer, byteOffset, byteLength) {
  4169. return this._applyExtensions(buffer, "loadBuffer", function (extension) { return extension.loadBufferAsync && extension.loadBufferAsync(context, buffer, byteOffset, byteLength); });
  4170. };
  4171. /**
  4172. * Helper method called by a loader extension to load an glTF extension.
  4173. * @param context The context when loading the asset
  4174. * @param property The glTF property to load the extension from
  4175. * @param extensionName The name of the extension to load
  4176. * @param actionAsync The action to run
  4177. * @returns The promise returned by actionAsync or null if the extension does not exist
  4178. */
  4179. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  4180. if (!property.extensions) {
  4181. return null;
  4182. }
  4183. var extensions = property.extensions;
  4184. var extension = extensions[extensionName];
  4185. if (!extension) {
  4186. return null;
  4187. }
  4188. return actionAsync(context + "/extensions/" + extensionName, extension);
  4189. };
  4190. /**
  4191. * Helper method called by a loader extension to load a glTF extra.
  4192. * @param context The context when loading the asset
  4193. * @param property The glTF property to load the extra from
  4194. * @param extensionName The name of the extension to load
  4195. * @param actionAsync The action to run
  4196. * @returns The promise returned by actionAsync or null if the extra does not exist
  4197. */
  4198. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  4199. if (!property.extras) {
  4200. return null;
  4201. }
  4202. var extras = property.extras;
  4203. var extra = extras[extensionName];
  4204. if (!extra) {
  4205. return null;
  4206. }
  4207. return actionAsync(context + "/extras/" + extensionName, extra);
  4208. };
  4209. /**
  4210. * Checks for presence of an extension.
  4211. * @param name The name of the extension to check
  4212. * @returns A boolean indicating the presence of the given extension name in `extensionsUsed`
  4213. */
  4214. GLTFLoader.prototype.isExtensionUsed = function (name) {
  4215. return !!this._gltf.extensionsUsed && this._gltf.extensionsUsed.indexOf(name) !== -1;
  4216. };
  4217. /**
  4218. * Increments the indentation level and logs a message.
  4219. * @param message The message to log
  4220. */
  4221. GLTFLoader.prototype.logOpen = function (message) {
  4222. this._parent._logOpen(message);
  4223. };
  4224. /**
  4225. * Decrements the indentation level.
  4226. */
  4227. GLTFLoader.prototype.logClose = function () {
  4228. this._parent._logClose();
  4229. };
  4230. /**
  4231. * Logs a message
  4232. * @param message The message to log
  4233. */
  4234. GLTFLoader.prototype.log = function (message) {
  4235. this._parent._log(message);
  4236. };
  4237. /**
  4238. * Starts a performance counter.
  4239. * @param counterName The name of the performance counter
  4240. */
  4241. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  4242. this._parent._startPerformanceCounter(counterName);
  4243. };
  4244. /**
  4245. * Ends a performance counter.
  4246. * @param counterName The name of the performance counter
  4247. */
  4248. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  4249. this._parent._endPerformanceCounter(counterName);
  4250. };
  4251. GLTFLoader._RegisteredExtensions = {};
  4252. /**
  4253. * The default glTF sampler.
  4254. */
  4255. GLTFLoader.DefaultSampler = { index: -1 };
  4256. return GLTFLoader;
  4257. }());
  4258. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  4259. /***/ }),
  4260. /***/ "./glTF/2.0/glTFLoaderExtension.ts":
  4261. /*!*****************************************!*\
  4262. !*** ./glTF/2.0/glTFLoaderExtension.ts ***!
  4263. \*****************************************/
  4264. /*! no static exports found */
  4265. /***/ (function(module, exports) {
  4266. /***/ }),
  4267. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  4268. /*!******************************************!*\
  4269. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  4270. \******************************************/
  4271. /*! no static exports found */
  4272. /***/ (function(module, exports) {
  4273. /***/ }),
  4274. /***/ "./glTF/2.0/index.ts":
  4275. /*!***************************!*\
  4276. !*** ./glTF/2.0/index.ts ***!
  4277. \***************************/
  4278. /*! no static exports found */
  4279. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4280. "use strict";
  4281. __webpack_require__.r(__webpack_exports__);
  4282. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  4283. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  4284. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  4285. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFLoaderExtension */ "./glTF/2.0/glTFLoaderExtension.ts");
  4286. /* harmony import */ var _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__);
  4287. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__) if(["ArrayItem","GLTFLoader","default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _glTFLoaderExtension__WEBPACK_IMPORTED_MODULE_1__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  4288. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  4289. /* harmony import */ var _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__);
  4290. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__) if(["ArrayItem","GLTFLoader","default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_2__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  4291. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  4292. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_lights_image_based"]; });
  4293. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_mesh_gpu_instancing", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["EXT_mesh_gpu_instancing"]; });
  4294. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_draco_mesh_compression"]; });
  4295. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_lights"]; });
  4296. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_pbrSpecularGlossiness"]; });
  4297. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_unlit"]; });
  4298. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_clearcoat", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_clearcoat"]; });
  4299. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_sheen"]; });
  4300. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_specular", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_specular"]; });
  4301. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_ior", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_ior"]; });
  4302. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_variants", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_variants"]; });
  4303. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_transmission", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_transmission"]; });
  4304. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_mesh_quantization", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_mesh_quantization"]; });
  4305. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_basisu", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_basisu"]; });
  4306. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_texture_transform"]; });
  4307. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_xmp", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["KHR_xmp"]; });
  4308. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_audio_emitter"]; });
  4309. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_lod"]; });
  4310. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_minecraftMesh"]; });
  4311. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["MSFT_sRGBFactors"]; });
  4312. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ExtrasAsMetadata", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_3__["ExtrasAsMetadata"]; });
  4313. /***/ }),
  4314. /***/ "./glTF/glTFFileLoader.ts":
  4315. /*!********************************!*\
  4316. !*** ./glTF/glTFFileLoader.ts ***!
  4317. \********************************/
  4318. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  4319. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4320. "use strict";
  4321. __webpack_require__.r(__webpack_exports__);
  4322. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  4323. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  4324. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  4325. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  4326. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/tools");
  4327. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  4328. /* harmony import */ var _glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFValidation */ "./glTF/glTFValidation.ts");
  4329. /**
  4330. * Mode that determines the coordinate system to use.
  4331. */
  4332. var GLTFLoaderCoordinateSystemMode;
  4333. (function (GLTFLoaderCoordinateSystemMode) {
  4334. /**
  4335. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  4336. */
  4337. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  4338. /**
  4339. * Sets the useRightHandedSystem flag on the scene.
  4340. */
  4341. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  4342. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  4343. /**
  4344. * Mode that determines what animations will start.
  4345. */
  4346. var GLTFLoaderAnimationStartMode;
  4347. (function (GLTFLoaderAnimationStartMode) {
  4348. /**
  4349. * No animation will start.
  4350. */
  4351. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  4352. /**
  4353. * The first animation will start.
  4354. */
  4355. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  4356. /**
  4357. * All animations will start.
  4358. */
  4359. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  4360. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  4361. /**
  4362. * Loader state.
  4363. */
  4364. var GLTFLoaderState;
  4365. (function (GLTFLoaderState) {
  4366. /**
  4367. * The asset is loading.
  4368. */
  4369. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  4370. /**
  4371. * The asset is ready for rendering.
  4372. */
  4373. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  4374. /**
  4375. * The asset is completely loaded.
  4376. */
  4377. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  4378. })(GLTFLoaderState || (GLTFLoaderState = {}));
  4379. /**
  4380. * File loader for loading glTF files into a scene.
  4381. */
  4382. var GLTFFileLoader = /** @class */ (function () {
  4383. function GLTFFileLoader() {
  4384. // --------------
  4385. // Common options
  4386. // --------------
  4387. /**
  4388. * Raised when the asset has been parsed
  4389. */
  4390. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4391. // ----------
  4392. // V2 options
  4393. // ----------
  4394. /**
  4395. * The coordinate system mode. Defaults to AUTO.
  4396. */
  4397. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  4398. /**
  4399. * The animation start mode. Defaults to FIRST.
  4400. */
  4401. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  4402. /**
  4403. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  4404. */
  4405. this.compileMaterials = false;
  4406. /**
  4407. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  4408. */
  4409. this.useClipPlane = false;
  4410. /**
  4411. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  4412. */
  4413. this.compileShadowGenerators = false;
  4414. /**
  4415. * Defines if the Alpha blended materials are only applied as coverage.
  4416. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  4417. * If true, no extra effects are applied to transparent pixels.
  4418. */
  4419. this.transparencyAsCoverage = false;
  4420. /**
  4421. * Defines if the loader should use range requests when load binary glTF files from HTTP.
  4422. * Enabling will disable offline support and glTF validator.
  4423. * Defaults to false.
  4424. */
  4425. this.useRangeRequests = false;
  4426. /**
  4427. * Defines if the loader should create instances when multiple glTF nodes point to the same glTF mesh. Defaults to true.
  4428. */
  4429. this.createInstances = true;
  4430. /**
  4431. * Defines if the loader should always compute the bounding boxes of meshes and not use the min/max values from the position accessor. Defaults to false.
  4432. */
  4433. this.alwaysComputeBoundingBox = false;
  4434. /**
  4435. * Function called before loading a url referenced by the asset.
  4436. */
  4437. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  4438. /**
  4439. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  4440. */
  4441. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4442. /**
  4443. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  4444. */
  4445. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4446. /**
  4447. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  4448. */
  4449. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4450. /**
  4451. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  4452. */
  4453. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4454. /**
  4455. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  4456. * For assets with LODs, raised when all of the LODs are complete.
  4457. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  4458. */
  4459. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4460. /**
  4461. * Observable raised when an error occurs.
  4462. */
  4463. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4464. /**
  4465. * Observable raised after the loader is disposed.
  4466. */
  4467. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4468. /**
  4469. * Observable raised after a loader extension is created.
  4470. * Set additional options for a loader extension in this event.
  4471. */
  4472. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4473. /**
  4474. * Defines if the loader should validate the asset.
  4475. */
  4476. this.validate = false;
  4477. /**
  4478. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  4479. */
  4480. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  4481. this._loader = null;
  4482. this._requests = new Array();
  4483. /**
  4484. * Name of the loader ("gltf")
  4485. */
  4486. this.name = "gltf";
  4487. /** @hidden */
  4488. this.extensions = {
  4489. ".gltf": { isBinary: false },
  4490. ".glb": { isBinary: true }
  4491. };
  4492. this._logIndentLevel = 0;
  4493. this._loggingEnabled = false;
  4494. /** @hidden */
  4495. this._log = this._logDisabled;
  4496. this._capturePerformanceCounters = false;
  4497. /** @hidden */
  4498. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  4499. /** @hidden */
  4500. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  4501. }
  4502. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  4503. /**
  4504. * Raised when the asset has been parsed
  4505. */
  4506. set: function (callback) {
  4507. if (this._onParsedObserver) {
  4508. this.onParsedObservable.remove(this._onParsedObserver);
  4509. }
  4510. this._onParsedObserver = this.onParsedObservable.add(callback);
  4511. },
  4512. enumerable: false,
  4513. configurable: true
  4514. });
  4515. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  4516. /**
  4517. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  4518. */
  4519. set: function (callback) {
  4520. if (this._onMeshLoadedObserver) {
  4521. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  4522. }
  4523. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  4524. },
  4525. enumerable: false,
  4526. configurable: true
  4527. });
  4528. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  4529. /**
  4530. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  4531. */
  4532. set: function (callback) {
  4533. if (this._onTextureLoadedObserver) {
  4534. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  4535. }
  4536. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  4537. },
  4538. enumerable: false,
  4539. configurable: true
  4540. });
  4541. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  4542. /**
  4543. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  4544. */
  4545. set: function (callback) {
  4546. if (this._onMaterialLoadedObserver) {
  4547. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  4548. }
  4549. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  4550. },
  4551. enumerable: false,
  4552. configurable: true
  4553. });
  4554. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  4555. /**
  4556. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  4557. */
  4558. set: function (callback) {
  4559. if (this._onCameraLoadedObserver) {
  4560. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  4561. }
  4562. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  4563. },
  4564. enumerable: false,
  4565. configurable: true
  4566. });
  4567. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  4568. /**
  4569. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  4570. * For assets with LODs, raised when all of the LODs are complete.
  4571. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  4572. */
  4573. set: function (callback) {
  4574. if (this._onCompleteObserver) {
  4575. this.onCompleteObservable.remove(this._onCompleteObserver);
  4576. }
  4577. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  4578. },
  4579. enumerable: false,
  4580. configurable: true
  4581. });
  4582. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  4583. /**
  4584. * Callback raised when an error occurs.
  4585. */
  4586. set: function (callback) {
  4587. if (this._onErrorObserver) {
  4588. this.onErrorObservable.remove(this._onErrorObserver);
  4589. }
  4590. this._onErrorObserver = this.onErrorObservable.add(callback);
  4591. },
  4592. enumerable: false,
  4593. configurable: true
  4594. });
  4595. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  4596. /**
  4597. * Callback raised after the loader is disposed.
  4598. */
  4599. set: function (callback) {
  4600. if (this._onDisposeObserver) {
  4601. this.onDisposeObservable.remove(this._onDisposeObserver);
  4602. }
  4603. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  4604. },
  4605. enumerable: false,
  4606. configurable: true
  4607. });
  4608. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  4609. /**
  4610. * Callback raised after a loader extension is created.
  4611. */
  4612. set: function (callback) {
  4613. if (this._onExtensionLoadedObserver) {
  4614. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  4615. }
  4616. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  4617. },
  4618. enumerable: false,
  4619. configurable: true
  4620. });
  4621. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  4622. /**
  4623. * Defines if the loader logging is enabled.
  4624. */
  4625. get: function () {
  4626. return this._loggingEnabled;
  4627. },
  4628. set: function (value) {
  4629. if (this._loggingEnabled === value) {
  4630. return;
  4631. }
  4632. this._loggingEnabled = value;
  4633. if (this._loggingEnabled) {
  4634. this._log = this._logEnabled;
  4635. }
  4636. else {
  4637. this._log = this._logDisabled;
  4638. }
  4639. },
  4640. enumerable: false,
  4641. configurable: true
  4642. });
  4643. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  4644. /**
  4645. * Defines if the loader should capture performance counters.
  4646. */
  4647. get: function () {
  4648. return this._capturePerformanceCounters;
  4649. },
  4650. set: function (value) {
  4651. if (this._capturePerformanceCounters === value) {
  4652. return;
  4653. }
  4654. this._capturePerformanceCounters = value;
  4655. if (this._capturePerformanceCounters) {
  4656. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  4657. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  4658. }
  4659. else {
  4660. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  4661. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  4662. }
  4663. },
  4664. enumerable: false,
  4665. configurable: true
  4666. });
  4667. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  4668. /**
  4669. * Callback raised after a loader extension is created.
  4670. */
  4671. set: function (callback) {
  4672. if (this._onValidatedObserver) {
  4673. this.onValidatedObservable.remove(this._onValidatedObserver);
  4674. }
  4675. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  4676. },
  4677. enumerable: false,
  4678. configurable: true
  4679. });
  4680. /**
  4681. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  4682. */
  4683. GLTFFileLoader.prototype.dispose = function () {
  4684. if (this._loader) {
  4685. this._loader.dispose();
  4686. this._loader = null;
  4687. }
  4688. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4689. var request = _a[_i];
  4690. request.abort();
  4691. }
  4692. this._requests.length = 0;
  4693. delete this._progressCallback;
  4694. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  4695. this.onMeshLoadedObservable.clear();
  4696. this.onTextureLoadedObservable.clear();
  4697. this.onMaterialLoadedObservable.clear();
  4698. this.onCameraLoadedObservable.clear();
  4699. this.onCompleteObservable.clear();
  4700. this.onExtensionLoadedObservable.clear();
  4701. this.onDisposeObservable.notifyObservers(undefined);
  4702. this.onDisposeObservable.clear();
  4703. };
  4704. /** @hidden */
  4705. GLTFFileLoader.prototype.requestFile = function (scene, url, onSuccess, onProgress, useArrayBuffer, onError) {
  4706. var _this = this;
  4707. this._progressCallback = onProgress;
  4708. if (useArrayBuffer) {
  4709. if (this.useRangeRequests) {
  4710. if (this.validate) {
  4711. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn("glTF validation is not supported when range requests are enabled");
  4712. }
  4713. var fileRequest_1 = {
  4714. abort: function () { },
  4715. onCompleteObservable: new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]()
  4716. };
  4717. var dataBuffer = {
  4718. readAsync: function (byteOffset, byteLength) {
  4719. return new Promise(function (resolve, reject) {
  4720. _this._requestFile(url, scene, function (data) {
  4721. resolve(new Uint8Array(data));
  4722. }, true, function (error) {
  4723. reject(error);
  4724. }, function (webRequest) {
  4725. webRequest.setRequestHeader("Range", "bytes=" + byteOffset + "-" + (byteOffset + byteLength - 1));
  4726. });
  4727. });
  4728. },
  4729. byteLength: 0
  4730. };
  4731. this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"](dataBuffer)).then(function (loaderData) {
  4732. fileRequest_1.onCompleteObservable.notifyObservers(fileRequest_1);
  4733. onSuccess(loaderData);
  4734. }, onError);
  4735. return fileRequest_1;
  4736. }
  4737. return this._requestFile(url, scene, function (data, request) {
  4738. var arrayBuffer = data;
  4739. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4740. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer, byteOffset, byteLength)); },
  4741. byteLength: arrayBuffer.byteLength
  4742. })).then(function (loaderData) {
  4743. onSuccess(loaderData, request);
  4744. }, onError);
  4745. }, true, onError);
  4746. }
  4747. return this._requestFile(url, scene, function (data, request) {
  4748. _this._validate(scene, data, babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFolderPath(url), babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetFilename(url));
  4749. onSuccess({ json: _this._parseJson(data) }, request);
  4750. }, useArrayBuffer, onError);
  4751. };
  4752. /** @hidden */
  4753. GLTFFileLoader.prototype.readFile = function (scene, file, onSuccess, onProgress, useArrayBuffer, onError) {
  4754. var _this = this;
  4755. return scene._readFile(file, function (data) {
  4756. _this._validate(scene, data, "file:", file.name);
  4757. if (useArrayBuffer) {
  4758. var arrayBuffer_1 = data;
  4759. _this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4760. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_1, byteOffset, byteLength)); },
  4761. byteLength: arrayBuffer_1.byteLength
  4762. })).then(onSuccess, onError);
  4763. }
  4764. else {
  4765. onSuccess({ json: _this._parseJson(data) });
  4766. }
  4767. }, onProgress, useArrayBuffer, onError);
  4768. };
  4769. /** @hidden */
  4770. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  4771. var _this = this;
  4772. return Promise.resolve().then(function () {
  4773. _this.onParsedObservable.notifyObservers(data);
  4774. _this.onParsedObservable.clear();
  4775. _this._log("Loading " + (fileName || ""));
  4776. _this._loader = _this._getLoader(data);
  4777. return _this._loader.importMeshAsync(meshesNames, scene, false, data, rootUrl, onProgress, fileName);
  4778. });
  4779. };
  4780. /** @hidden */
  4781. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4782. var _this = this;
  4783. return Promise.resolve().then(function () {
  4784. _this.onParsedObservable.notifyObservers(data);
  4785. _this.onParsedObservable.clear();
  4786. _this._log("Loading " + (fileName || ""));
  4787. _this._loader = _this._getLoader(data);
  4788. return _this._loader.loadAsync(scene, data, rootUrl, onProgress, fileName);
  4789. });
  4790. };
  4791. /** @hidden */
  4792. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  4793. var _this = this;
  4794. return Promise.resolve().then(function () {
  4795. _this.onParsedObservable.notifyObservers(data);
  4796. _this.onParsedObservable.clear();
  4797. _this._log("Loading " + (fileName || ""));
  4798. _this._loader = _this._getLoader(data);
  4799. // Prepare the asset container.
  4800. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  4801. // Get materials/textures when loading to add to container
  4802. var materials = [];
  4803. _this.onMaterialLoadedObservable.add(function (material) {
  4804. materials.push(material);
  4805. material.onDisposeObservable.addOnce(function () {
  4806. var index = container.materials.indexOf(material);
  4807. if (index > -1) {
  4808. container.materials.splice(index, 1);
  4809. }
  4810. index = materials.indexOf(material);
  4811. if (index > -1) {
  4812. materials.splice(index, 1);
  4813. }
  4814. });
  4815. });
  4816. var textures = [];
  4817. _this.onTextureLoadedObservable.add(function (texture) {
  4818. textures.push(texture);
  4819. texture.onDisposeObservable.addOnce(function () {
  4820. var index = container.textures.indexOf(texture);
  4821. if (index > -1) {
  4822. container.textures.splice(index, 1);
  4823. }
  4824. index = textures.indexOf(texture);
  4825. if (index > -1) {
  4826. textures.splice(index, 1);
  4827. }
  4828. });
  4829. });
  4830. var cameras = [];
  4831. _this.onCameraLoadedObservable.add(function (camera) {
  4832. cameras.push(camera);
  4833. });
  4834. return _this._loader.importMeshAsync(null, scene, true, data, rootUrl, onProgress, fileName).then(function (result) {
  4835. Array.prototype.push.apply(container.meshes, result.meshes);
  4836. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  4837. Array.prototype.push.apply(container.skeletons, result.skeletons);
  4838. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  4839. Array.prototype.push.apply(container.materials, materials);
  4840. Array.prototype.push.apply(container.textures, textures);
  4841. Array.prototype.push.apply(container.lights, result.lights);
  4842. Array.prototype.push.apply(container.transformNodes, result.transformNodes);
  4843. Array.prototype.push.apply(container.cameras, cameras);
  4844. return container;
  4845. });
  4846. });
  4847. };
  4848. /** @hidden */
  4849. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  4850. return (data.indexOf("asset") !== -1 && data.indexOf("version") !== -1)
  4851. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:base64," + GLTFFileLoader.magicBase64Encoded)
  4852. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded)
  4853. || babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "data:model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded);
  4854. };
  4855. /** @hidden */
  4856. GLTFFileLoader.prototype.directLoad = function (scene, data) {
  4857. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "base64," + GLTFFileLoader.magicBase64Encoded) ||
  4858. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "application/octet-stream;base64," + GLTFFileLoader.magicBase64Encoded) ||
  4859. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["StringTools"].StartsWith(data, "model/gltf-binary;base64," + GLTFFileLoader.magicBase64Encoded)) {
  4860. var arrayBuffer_2 = babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(data);
  4861. this._validate(scene, arrayBuffer_2);
  4862. return this._unpackBinaryAsync(new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["DataReader"]({
  4863. readAsync: function (byteOffset, byteLength) { return Promise.resolve(new Uint8Array(arrayBuffer_2, byteOffset, byteLength)); },
  4864. byteLength: arrayBuffer_2.byteLength
  4865. }));
  4866. }
  4867. this._validate(scene, data);
  4868. return Promise.resolve({ json: this._parseJson(data) });
  4869. };
  4870. /** @hidden */
  4871. GLTFFileLoader.prototype.createPlugin = function () {
  4872. return new GLTFFileLoader();
  4873. };
  4874. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  4875. /**
  4876. * The loader state or null if the loader is not active.
  4877. */
  4878. get: function () {
  4879. return this._loader ? this._loader.state : null;
  4880. },
  4881. enumerable: false,
  4882. configurable: true
  4883. });
  4884. /**
  4885. * Returns a promise that resolves when the asset is completely loaded.
  4886. * @returns a promise that resolves when the asset is completely loaded.
  4887. */
  4888. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  4889. var _this = this;
  4890. return new Promise(function (resolve, reject) {
  4891. _this.onCompleteObservable.addOnce(function () {
  4892. resolve();
  4893. });
  4894. _this.onErrorObservable.addOnce(function (reason) {
  4895. reject(reason);
  4896. });
  4897. });
  4898. };
  4899. /** @hidden */
  4900. GLTFFileLoader.prototype._loadFile = function (url, scene, onSuccess, useArrayBuffer, onError) {
  4901. var _this = this;
  4902. var request = scene._loadFile(url, onSuccess, function (event) {
  4903. _this._onProgress(event, request);
  4904. }, undefined, useArrayBuffer, onError);
  4905. request.onCompleteObservable.add(function (request) {
  4906. _this._requests.splice(_this._requests.indexOf(request), 1);
  4907. });
  4908. this._requests.push(request);
  4909. return request;
  4910. };
  4911. /** @hidden */
  4912. GLTFFileLoader.prototype._requestFile = function (url, scene, onSuccess, useArrayBuffer, onError, onOpened) {
  4913. var _this = this;
  4914. var request = scene._requestFile(url, onSuccess, function (event) {
  4915. _this._onProgress(event, request);
  4916. }, undefined, useArrayBuffer, onError, onOpened);
  4917. request.onCompleteObservable.add(function (request) {
  4918. _this._requests.splice(_this._requests.indexOf(request), 1);
  4919. });
  4920. this._requests.push(request);
  4921. return request;
  4922. };
  4923. GLTFFileLoader.prototype._onProgress = function (event, request) {
  4924. if (!this._progressCallback) {
  4925. return;
  4926. }
  4927. request._lengthComputable = event.lengthComputable;
  4928. request._loaded = event.loaded;
  4929. request._total = event.total;
  4930. var lengthComputable = true;
  4931. var loaded = 0;
  4932. var total = 0;
  4933. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  4934. var request_1 = _a[_i];
  4935. if (request_1._lengthComputable === undefined || request_1._loaded === undefined || request_1._total === undefined) {
  4936. return;
  4937. }
  4938. lengthComputable = lengthComputable && request_1._lengthComputable;
  4939. loaded += request_1._loaded;
  4940. total += request_1._total;
  4941. }
  4942. this._progressCallback({
  4943. lengthComputable: lengthComputable,
  4944. loaded: loaded,
  4945. total: lengthComputable ? total : 0
  4946. });
  4947. };
  4948. GLTFFileLoader.prototype._validate = function (scene, data, rootUrl, fileName) {
  4949. var _this = this;
  4950. if (rootUrl === void 0) { rootUrl = ""; }
  4951. if (fileName === void 0) { fileName = ""; }
  4952. if (!this.validate) {
  4953. return;
  4954. }
  4955. this._startPerformanceCounter("Validate JSON");
  4956. _glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"].ValidateAsync(data, rootUrl, fileName, function (uri) {
  4957. return _this.preprocessUrlAsync(rootUrl + uri).then(function (url) { return scene._loadFileAsync(url, undefined, true, true); });
  4958. }).then(function (result) {
  4959. _this._endPerformanceCounter("Validate JSON");
  4960. _this.onValidatedObservable.notifyObservers(result);
  4961. _this.onValidatedObservable.clear();
  4962. }, function (reason) {
  4963. _this._endPerformanceCounter("Validate JSON");
  4964. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason.message);
  4965. _this.onValidatedObservable.clear();
  4966. });
  4967. };
  4968. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  4969. var asset = loaderData.json.asset || {};
  4970. this._log("Asset version: " + asset.version);
  4971. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  4972. asset.generator && this._log("Asset generator: " + asset.generator);
  4973. var version = GLTFFileLoader._parseVersion(asset.version);
  4974. if (!version) {
  4975. throw new Error("Invalid version: " + asset.version);
  4976. }
  4977. if (asset.minVersion !== undefined) {
  4978. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  4979. if (!minVersion) {
  4980. throw new Error("Invalid minimum version: " + asset.minVersion);
  4981. }
  4982. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  4983. throw new Error("Incompatible minimum version: " + asset.minVersion);
  4984. }
  4985. }
  4986. var createLoaders = {
  4987. 1: GLTFFileLoader._CreateGLTF1Loader,
  4988. 2: GLTFFileLoader._CreateGLTF2Loader
  4989. };
  4990. var createLoader = createLoaders[version.major];
  4991. if (!createLoader) {
  4992. throw new Error("Unsupported version: " + asset.version);
  4993. }
  4994. return createLoader(this);
  4995. };
  4996. GLTFFileLoader.prototype._parseJson = function (json) {
  4997. this._startPerformanceCounter("Parse JSON");
  4998. this._log("JSON length: " + json.length);
  4999. var parsed = JSON.parse(json);
  5000. this._endPerformanceCounter("Parse JSON");
  5001. return parsed;
  5002. };
  5003. GLTFFileLoader.prototype._unpackBinaryAsync = function (dataReader) {
  5004. var _this = this;
  5005. this._startPerformanceCounter("Unpack Binary");
  5006. // Read magic + version + length + json length + json format
  5007. return dataReader.loadAsync(20).then(function () {
  5008. var Binary = {
  5009. Magic: 0x46546C67
  5010. };
  5011. var magic = dataReader.readUint32();
  5012. if (magic !== Binary.Magic) {
  5013. throw new Error("Unexpected magic: " + magic);
  5014. }
  5015. var version = dataReader.readUint32();
  5016. if (_this.loggingEnabled) {
  5017. _this._log("Binary version: " + version);
  5018. }
  5019. var length = dataReader.readUint32();
  5020. if (dataReader.buffer.byteLength !== 0 && length !== dataReader.buffer.byteLength) {
  5021. throw new Error("Length in header does not match actual data length: " + length + " != " + dataReader.buffer.byteLength);
  5022. }
  5023. var unpacked;
  5024. switch (version) {
  5025. case 1: {
  5026. unpacked = _this._unpackBinaryV1Async(dataReader, length);
  5027. break;
  5028. }
  5029. case 2: {
  5030. unpacked = _this._unpackBinaryV2Async(dataReader, length);
  5031. break;
  5032. }
  5033. default: {
  5034. throw new Error("Unsupported version: " + version);
  5035. }
  5036. }
  5037. _this._endPerformanceCounter("Unpack Binary");
  5038. return unpacked;
  5039. });
  5040. };
  5041. GLTFFileLoader.prototype._unpackBinaryV1Async = function (dataReader, length) {
  5042. var ContentFormat = {
  5043. JSON: 0
  5044. };
  5045. var contentLength = dataReader.readUint32();
  5046. var contentFormat = dataReader.readUint32();
  5047. if (contentFormat !== ContentFormat.JSON) {
  5048. throw new Error("Unexpected content format: " + contentFormat);
  5049. }
  5050. var bodyLength = length - dataReader.byteOffset;
  5051. var data = { json: this._parseJson(dataReader.readString(contentLength)), bin: null };
  5052. if (bodyLength !== 0) {
  5053. var startByteOffset_1 = dataReader.byteOffset;
  5054. data.bin = {
  5055. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_1 + byteOffset, byteLength); },
  5056. byteLength: bodyLength
  5057. };
  5058. }
  5059. return Promise.resolve(data);
  5060. };
  5061. GLTFFileLoader.prototype._unpackBinaryV2Async = function (dataReader, length) {
  5062. var _this = this;
  5063. var ChunkFormat = {
  5064. JSON: 0x4E4F534A,
  5065. BIN: 0x004E4942
  5066. };
  5067. // Read the JSON chunk header.
  5068. var chunkLength = dataReader.readUint32();
  5069. var chunkFormat = dataReader.readUint32();
  5070. if (chunkFormat !== ChunkFormat.JSON) {
  5071. throw new Error("First chunk format is not JSON");
  5072. }
  5073. // Bail if there are no other chunks.
  5074. if (dataReader.byteOffset + chunkLength === length) {
  5075. return dataReader.loadAsync(chunkLength).then(function () {
  5076. return { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  5077. });
  5078. }
  5079. // Read the JSON chunk and the length and type of the next chunk.
  5080. return dataReader.loadAsync(chunkLength + 8).then(function () {
  5081. var data = { json: _this._parseJson(dataReader.readString(chunkLength)), bin: null };
  5082. var readAsync = function () {
  5083. var chunkLength = dataReader.readUint32();
  5084. var chunkFormat = dataReader.readUint32();
  5085. switch (chunkFormat) {
  5086. case ChunkFormat.JSON: {
  5087. throw new Error("Unexpected JSON chunk");
  5088. }
  5089. case ChunkFormat.BIN: {
  5090. var startByteOffset_2 = dataReader.byteOffset;
  5091. data.bin = {
  5092. readAsync: function (byteOffset, byteLength) { return dataReader.buffer.readAsync(startByteOffset_2 + byteOffset, byteLength); },
  5093. byteLength: chunkLength
  5094. };
  5095. dataReader.skipBytes(chunkLength);
  5096. break;
  5097. }
  5098. default: {
  5099. // ignore unrecognized chunkFormat
  5100. dataReader.skipBytes(chunkLength);
  5101. break;
  5102. }
  5103. }
  5104. if (dataReader.byteOffset !== length) {
  5105. return dataReader.loadAsync(8).then(readAsync);
  5106. }
  5107. return Promise.resolve(data);
  5108. };
  5109. return readAsync();
  5110. });
  5111. };
  5112. GLTFFileLoader._parseVersion = function (version) {
  5113. if (version === "1.0" || version === "1.0.1") {
  5114. return {
  5115. major: 1,
  5116. minor: 0
  5117. };
  5118. }
  5119. var match = (version + "").match(/^(\d+)\.(\d+)/);
  5120. if (!match) {
  5121. return null;
  5122. }
  5123. return {
  5124. major: parseInt(match[1]),
  5125. minor: parseInt(match[2])
  5126. };
  5127. };
  5128. GLTFFileLoader._compareVersion = function (a, b) {
  5129. if (a.major > b.major) {
  5130. return 1;
  5131. }
  5132. if (a.major < b.major) {
  5133. return -1;
  5134. }
  5135. if (a.minor > b.minor) {
  5136. return 1;
  5137. }
  5138. if (a.minor < b.minor) {
  5139. return -1;
  5140. }
  5141. return 0;
  5142. };
  5143. /** @hidden */
  5144. GLTFFileLoader.prototype._logOpen = function (message) {
  5145. this._log(message);
  5146. this._logIndentLevel++;
  5147. };
  5148. /** @hidden */
  5149. GLTFFileLoader.prototype._logClose = function () {
  5150. --this._logIndentLevel;
  5151. };
  5152. GLTFFileLoader.prototype._logEnabled = function (message) {
  5153. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  5154. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("" + spaces + message);
  5155. };
  5156. GLTFFileLoader.prototype._logDisabled = function (message) {
  5157. };
  5158. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  5159. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  5160. };
  5161. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  5162. };
  5163. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  5164. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  5165. };
  5166. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  5167. };
  5168. // ----------
  5169. // V1 options
  5170. // ----------
  5171. /**
  5172. * 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.
  5173. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  5174. * Defaults to true.
  5175. * @hidden
  5176. */
  5177. GLTFFileLoader.IncrementalLoading = true;
  5178. /**
  5179. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  5180. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  5181. * @hidden
  5182. */
  5183. GLTFFileLoader.HomogeneousCoordinates = false;
  5184. GLTFFileLoader.magicBase64Encoded = "Z2xURg"; // "glTF" base64 encoded (without the quotes!)
  5185. GLTFFileLoader._logSpaces = " ";
  5186. return GLTFFileLoader;
  5187. }());
  5188. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  5189. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  5190. }
  5191. /***/ }),
  5192. /***/ "./glTF/glTFValidation.ts":
  5193. /*!********************************!*\
  5194. !*** ./glTF/glTFValidation.ts ***!
  5195. \********************************/
  5196. /*! exports provided: GLTFValidation */
  5197. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5198. "use strict";
  5199. __webpack_require__.r(__webpack_exports__);
  5200. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return GLTFValidation; });
  5201. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Misc/tools");
  5202. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  5203. function validateAsync(data, rootUrl, fileName, getExternalResource) {
  5204. var options = {
  5205. externalResourceFunction: function (uri) { return getExternalResource(uri).then(function (value) { return new Uint8Array(value); }); }
  5206. };
  5207. if (fileName) {
  5208. options.uri = (rootUrl === "file:" ? fileName : rootUrl + fileName);
  5209. }
  5210. return (data instanceof ArrayBuffer)
  5211. ? GLTFValidator.validateBytes(new Uint8Array(data), options)
  5212. : GLTFValidator.validateString(data, options);
  5213. }
  5214. /**
  5215. * The worker function that gets converted to a blob url to pass into a worker.
  5216. */
  5217. function workerFunc() {
  5218. var pendingExternalResources = [];
  5219. onmessage = function (message) {
  5220. var data = message.data;
  5221. switch (data.id) {
  5222. case "init": {
  5223. importScripts(data.url);
  5224. break;
  5225. }
  5226. case "validate": {
  5227. validateAsync(data.data, data.rootUrl, data.fileName, function (uri) { return new Promise(function (resolve, reject) {
  5228. var index = pendingExternalResources.length;
  5229. pendingExternalResources.push({ resolve: resolve, reject: reject });
  5230. postMessage({ id: "getExternalResource", index: index, uri: uri });
  5231. }); }).then(function (value) {
  5232. postMessage({ id: "validate.resolve", value: value });
  5233. }, function (reason) {
  5234. postMessage({ id: "validate.reject", reason: reason });
  5235. });
  5236. break;
  5237. }
  5238. case "getExternalResource.resolve": {
  5239. pendingExternalResources[data.index].resolve(data.value);
  5240. break;
  5241. }
  5242. case "getExternalResource.reject": {
  5243. pendingExternalResources[data.index].reject(data.reason);
  5244. break;
  5245. }
  5246. }
  5247. };
  5248. }
  5249. /**
  5250. * glTF validation
  5251. */
  5252. var GLTFValidation = /** @class */ (function () {
  5253. function GLTFValidation() {
  5254. }
  5255. /**
  5256. * Validate a glTF asset using the glTF-Validator.
  5257. * @param data The JSON of a glTF or the array buffer of a binary glTF
  5258. * @param rootUrl The root url for the glTF
  5259. * @param fileName The file name for the glTF
  5260. * @param getExternalResource The callback to get external resources for the glTF validator
  5261. * @returns A promise that resolves with the glTF validation results once complete
  5262. */
  5263. GLTFValidation.ValidateAsync = function (data, rootUrl, fileName, getExternalResource) {
  5264. var _this = this;
  5265. if (typeof Worker === "function") {
  5266. return new Promise(function (resolve, reject) {
  5267. var workerContent = validateAsync + "(" + workerFunc + ")()";
  5268. var workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: "application/javascript" }));
  5269. var worker = new Worker(workerBlobUrl);
  5270. var onError = function (error) {
  5271. worker.removeEventListener("error", onError);
  5272. worker.removeEventListener("message", onMessage);
  5273. reject(error);
  5274. };
  5275. var onMessage = function (message) {
  5276. var data = message.data;
  5277. switch (data.id) {
  5278. case "getExternalResource": {
  5279. getExternalResource(data.uri).then(function (value) {
  5280. worker.postMessage({ id: "getExternalResource.resolve", index: data.index, value: value }, [value]);
  5281. }, function (reason) {
  5282. worker.postMessage({ id: "getExternalResource.reject", index: data.index, reason: reason });
  5283. });
  5284. break;
  5285. }
  5286. case "validate.resolve": {
  5287. worker.removeEventListener("error", onError);
  5288. worker.removeEventListener("message", onMessage);
  5289. resolve(data.value);
  5290. break;
  5291. }
  5292. case "validate.reject": {
  5293. worker.removeEventListener("error", onError);
  5294. worker.removeEventListener("message", onMessage);
  5295. reject(data.reason);
  5296. }
  5297. }
  5298. };
  5299. worker.addEventListener("error", onError);
  5300. worker.addEventListener("message", onMessage);
  5301. worker.postMessage({ id: "init", url: babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].GetAbsoluteUrl(_this.Configuration.url) });
  5302. worker.postMessage({ id: "validate", data: data, rootUrl: rootUrl, fileName: fileName });
  5303. });
  5304. }
  5305. else {
  5306. if (!this._LoadScriptPromise) {
  5307. this._LoadScriptPromise = babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadScriptAsync(this.Configuration.url);
  5308. }
  5309. return this._LoadScriptPromise.then(function () {
  5310. return validateAsync(data, rootUrl, fileName, getExternalResource);
  5311. });
  5312. }
  5313. };
  5314. /**
  5315. * The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
  5316. */
  5317. GLTFValidation.Configuration = {
  5318. url: "https://preview.babylonjs.com/gltf_validator.js"
  5319. };
  5320. return GLTFValidation;
  5321. }());
  5322. /***/ }),
  5323. /***/ "./legacy/legacy-glTF.ts":
  5324. /*!*******************************!*\
  5325. !*** ./legacy/legacy-glTF.ts ***!
  5326. \*******************************/
  5327. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation */
  5328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5329. "use strict";
  5330. __webpack_require__.r(__webpack_exports__);
  5331. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  5332. /* harmony import */ var _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/glTFValidation */ "./glTF/glTFValidation.ts");
  5333. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  5334. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  5335. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  5336. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  5337. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__["GLTFValidation"]; });
  5338. /**
  5339. * This is the entry point for the UMD module.
  5340. * The entry point for a future ESM package should be index.ts
  5341. */
  5342. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5343. if (typeof globalObject !== "undefined") {
  5344. globalObject.BABYLON = globalObject.BABYLON || {};
  5345. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  5346. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  5347. }
  5348. for (var key in _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__) {
  5349. globalObject.BABYLON[key] = _glTF_glTFValidation__WEBPACK_IMPORTED_MODULE_1__[key];
  5350. }
  5351. }
  5352. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5353. /***/ }),
  5354. /***/ "./legacy/legacy-glTF2.ts":
  5355. /*!********************************!*\
  5356. !*** ./legacy/legacy-glTF2.ts ***!
  5357. \********************************/
  5358. /*! exports provided: GLTF2 */
  5359. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5360. "use strict";
  5361. __webpack_require__.r(__webpack_exports__);
  5362. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  5363. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  5364. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  5365. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  5366. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  5367. /**
  5368. * This is the entry point for the UMD module.
  5369. * The entry point for a future ESM package should be index.ts
  5370. */
  5371. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5372. if (typeof globalObject !== "undefined") {
  5373. globalObject.BABYLON = globalObject.BABYLON || {};
  5374. var BABYLON = globalObject.BABYLON;
  5375. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  5376. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  5377. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  5378. var keys = [];
  5379. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  5380. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  5381. keys.push(key);
  5382. }
  5383. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  5384. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  5385. keys.push(key);
  5386. }
  5387. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  5388. // Prevent Reassignment.
  5389. if (keys.indexOf(key) > -1) {
  5390. continue;
  5391. }
  5392. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  5393. }
  5394. }
  5395. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5396. /***/ }),
  5397. /***/ "./legacy/legacy-glTF2FileLoader.ts":
  5398. /*!******************************************!*\
  5399. !*** ./legacy/legacy-glTF2FileLoader.ts ***!
  5400. \******************************************/
  5401. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader, GLTFValidation, GLTF2 */
  5402. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5403. "use strict";
  5404. __webpack_require__.r(__webpack_exports__);
  5405. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  5406. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  5407. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  5408. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  5409. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  5410. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFValidation", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFValidation"]; });
  5411. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  5412. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__["GLTF2"]; });
  5413. /***/ }),
  5414. /***/ "babylonjs/Misc/tools":
  5415. /*!****************************************************************************************************!*\
  5416. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  5417. \****************************************************************************************************/
  5418. /*! no static exports found */
  5419. /***/ (function(module, exports) {
  5420. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_tools__;
  5421. /***/ })
  5422. /******/ });
  5423. });
  5424. //# sourceMappingURL=babylon.glTF2FileLoader.js.map