babylon.glTF2FileLoader.js 289 KB

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