babylon.glTF2FileLoader.js 246 KB

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