babylon.glTF2FileLoader.js 274 KB

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