babylon.glTF2FileLoader.js 273 KB

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