babylon.glTF2FileLoader.js 285 KB

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