babylon.glTF2FileLoader.js 212 KB

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