babylon.glTF2FileLoader.js 244 KB

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