babylon.glTF2FileLoader.js 215 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296
  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. /**
  1801. * @hidden Define this method to modify the default behavior when loading data for mesh primitives.
  1802. * @param context The context when loading the asset
  1803. * @param name The mesh name when loading the asset
  1804. * @param node The glTF node when loading the asset
  1805. * @param mesh The glTF mesh when loading the asset
  1806. * @param primitive The glTF mesh primitive property
  1807. * @param assign A function called synchronously after parsing the glTF properties
  1808. * @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
  1809. */
  1810. GLTFLoader.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  1811. var _this = this;
  1812. var extensionPromise = this._extensionsLoadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign);
  1813. if (extensionPromise) {
  1814. return extensionPromise;
  1815. }
  1816. this.logOpen("" + context);
  1817. var canInstance = (node.skin == undefined && !mesh.primitives[0].targets);
  1818. var babylonAbstractMesh;
  1819. var promise;
  1820. var instanceData = primitive._instanceData;
  1821. if (canInstance && instanceData) {
  1822. babylonAbstractMesh = instanceData.babylonSourceMesh.createInstance(name);
  1823. promise = instanceData.promise;
  1824. }
  1825. else {
  1826. var promises = new Array();
  1827. var babylonMesh_1 = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Mesh"](name, this._babylonScene);
  1828. this._createMorphTargets(context, node, mesh, primitive, babylonMesh_1);
  1829. promises.push(this._loadVertexDataAsync(context, primitive, babylonMesh_1).then(function (babylonGeometry) {
  1830. return _this._loadMorphTargetsAsync(context, primitive, babylonMesh_1, babylonGeometry).then(function () {
  1831. babylonGeometry.applyToMesh(babylonMesh_1);
  1832. });
  1833. }));
  1834. var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
  1835. if (primitive.material == undefined) {
  1836. var babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
  1837. if (!babylonMaterial) {
  1838. babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
  1839. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  1840. this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
  1841. }
  1842. babylonMesh_1.material = babylonMaterial;
  1843. }
  1844. else {
  1845. var material = ArrayItem.Get(context + "/material", this._gltf.materials, primitive.material);
  1846. promises.push(this._loadMaterialAsync("/materials/" + material.index, material, babylonMesh_1, babylonDrawMode, function (babylonMaterial) {
  1847. babylonMesh_1.material = babylonMaterial;
  1848. }));
  1849. }
  1850. promise = Promise.all(promises);
  1851. if (canInstance) {
  1852. primitive._instanceData = {
  1853. babylonSourceMesh: babylonMesh_1,
  1854. promise: promise
  1855. };
  1856. }
  1857. babylonAbstractMesh = babylonMesh_1;
  1858. }
  1859. GLTFLoader.AddPointerMetadata(babylonAbstractMesh, context);
  1860. this._parent.onMeshLoadedObservable.notifyObservers(babylonAbstractMesh);
  1861. assign(babylonAbstractMesh);
  1862. this.logClose();
  1863. return promise.then(function () {
  1864. return babylonAbstractMesh;
  1865. });
  1866. };
  1867. GLTFLoader.prototype._loadVertexDataAsync = function (context, primitive, babylonMesh) {
  1868. var _this = this;
  1869. var extensionPromise = this._extensionsLoadVertexDataAsync(context, primitive, babylonMesh);
  1870. if (extensionPromise) {
  1871. return extensionPromise;
  1872. }
  1873. var attributes = primitive.attributes;
  1874. if (!attributes) {
  1875. throw new Error(context + ": Attributes are missing");
  1876. }
  1877. var promises = new Array();
  1878. var babylonGeometry = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Geometry"](babylonMesh.name, this._babylonScene);
  1879. if (primitive.indices == undefined) {
  1880. babylonMesh.isUnIndexed = true;
  1881. }
  1882. else {
  1883. var accessor = ArrayItem.Get(context + "/indices", this._gltf.accessors, primitive.indices);
  1884. promises.push(this._loadIndicesAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  1885. babylonGeometry.setIndices(data);
  1886. }));
  1887. }
  1888. var loadAttribute = function (attribute, kind, callback) {
  1889. if (attributes[attribute] == undefined) {
  1890. return;
  1891. }
  1892. babylonMesh._delayInfo = babylonMesh._delayInfo || [];
  1893. if (babylonMesh._delayInfo.indexOf(kind) === -1) {
  1894. babylonMesh._delayInfo.push(kind);
  1895. }
  1896. var accessor = ArrayItem.Get(context + "/attributes/" + attribute, _this._gltf.accessors, attributes[attribute]);
  1897. promises.push(_this._loadVertexAccessorAsync("/accessors/" + accessor.index, accessor, kind).then(function (babylonVertexBuffer) {
  1898. babylonGeometry.setVerticesBuffer(babylonVertexBuffer, accessor.count);
  1899. }));
  1900. if (callback) {
  1901. callback(accessor);
  1902. }
  1903. };
  1904. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind);
  1905. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind);
  1906. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind);
  1907. loadAttribute("TEXCOORD_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind);
  1908. loadAttribute("TEXCOORD_1", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind);
  1909. loadAttribute("JOINTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesIndicesKind);
  1910. loadAttribute("WEIGHTS_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].MatricesWeightsKind);
  1911. loadAttribute("COLOR_0", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, function (accessor) {
  1912. if (accessor.type === "VEC4" /* VEC4 */) {
  1913. babylonMesh.hasVertexAlpha = true;
  1914. }
  1915. });
  1916. return Promise.all(promises).then(function () {
  1917. return babylonGeometry;
  1918. });
  1919. };
  1920. GLTFLoader.prototype._createMorphTargets = function (context, node, mesh, primitive, babylonMesh) {
  1921. if (!primitive.targets) {
  1922. return;
  1923. }
  1924. if (node._numMorphTargets == undefined) {
  1925. node._numMorphTargets = primitive.targets.length;
  1926. }
  1927. else if (primitive.targets.length !== node._numMorphTargets) {
  1928. throw new Error(context + ": Primitives do not have the same number of targets");
  1929. }
  1930. babylonMesh.morphTargetManager = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTargetManager"]();
  1931. for (var index = 0; index < primitive.targets.length; index++) {
  1932. var weight = node.weights ? node.weights[index] : mesh.weights ? mesh.weights[index] : 0;
  1933. babylonMesh.morphTargetManager.addTarget(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"]("morphTarget" + index, weight));
  1934. // TODO: tell the target whether it has positions, normals, tangents
  1935. }
  1936. };
  1937. GLTFLoader.prototype._loadMorphTargetsAsync = function (context, primitive, babylonMesh, babylonGeometry) {
  1938. if (!primitive.targets) {
  1939. return Promise.resolve();
  1940. }
  1941. var promises = new Array();
  1942. var morphTargetManager = babylonMesh.morphTargetManager;
  1943. for (var index = 0; index < morphTargetManager.numTargets; index++) {
  1944. var babylonMorphTarget = morphTargetManager.getTarget(index);
  1945. promises.push(this._loadMorphTargetVertexDataAsync(context + "/targets/" + index, babylonGeometry, primitive.targets[index], babylonMorphTarget));
  1946. }
  1947. return Promise.all(promises).then(function () { });
  1948. };
  1949. GLTFLoader.prototype._loadMorphTargetVertexDataAsync = function (context, babylonGeometry, attributes, babylonMorphTarget) {
  1950. var _this = this;
  1951. var promises = new Array();
  1952. var loadAttribute = function (attribute, kind, setData) {
  1953. if (attributes[attribute] == undefined) {
  1954. return;
  1955. }
  1956. var babylonVertexBuffer = babylonGeometry.getVertexBuffer(kind);
  1957. if (!babylonVertexBuffer) {
  1958. return;
  1959. }
  1960. var accessor = ArrayItem.Get(context + "/" + attribute, _this._gltf.accessors, attributes[attribute]);
  1961. promises.push(_this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  1962. setData(babylonVertexBuffer, data);
  1963. }));
  1964. };
  1965. loadAttribute("POSITION", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, function (babylonVertexBuffer, data) {
  1966. babylonVertexBuffer.forEach(data.length, function (value, index) {
  1967. data[index] += value;
  1968. });
  1969. babylonMorphTarget.setPositions(data);
  1970. });
  1971. loadAttribute("NORMAL", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, function (babylonVertexBuffer, data) {
  1972. babylonVertexBuffer.forEach(data.length, function (value, index) {
  1973. data[index] += value;
  1974. });
  1975. babylonMorphTarget.setNormals(data);
  1976. });
  1977. loadAttribute("TANGENT", babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, function (babylonVertexBuffer, data) {
  1978. var dataIndex = 0;
  1979. babylonVertexBuffer.forEach(data.length / 3 * 4, function (value, index) {
  1980. // Tangent data for morph targets is stored as xyz delta.
  1981. // The vertexData.tangent is stored as xyzw.
  1982. // So we need to skip every fourth vertexData.tangent.
  1983. if (((index + 1) % 4) !== 0) {
  1984. data[dataIndex++] += value;
  1985. }
  1986. });
  1987. babylonMorphTarget.setTangents(data);
  1988. });
  1989. return Promise.all(promises).then(function () { });
  1990. };
  1991. GLTFLoader._LoadTransform = function (node, babylonNode) {
  1992. // Ignore the TRS of skinned nodes.
  1993. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  1994. if (node.skin != undefined) {
  1995. return;
  1996. }
  1997. var position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero();
  1998. var rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  1999. var scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].One();
  2000. if (node.matrix) {
  2001. var matrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix);
  2002. matrix.decompose(scaling, rotation, position);
  2003. }
  2004. else {
  2005. if (node.translation) {
  2006. position = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.translation);
  2007. }
  2008. if (node.rotation) {
  2009. rotation = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(node.rotation);
  2010. }
  2011. if (node.scale) {
  2012. scaling = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(node.scale);
  2013. }
  2014. }
  2015. babylonNode.position = position;
  2016. babylonNode.rotationQuaternion = rotation;
  2017. babylonNode.scaling = scaling;
  2018. };
  2019. GLTFLoader.prototype._loadSkinAsync = function (context, node, skin) {
  2020. var _this = this;
  2021. var extensionPromise = this._extensionsLoadSkinAsync(context, node, skin);
  2022. if (extensionPromise) {
  2023. return extensionPromise;
  2024. }
  2025. var assignSkeleton = function (skeleton) {
  2026. _this._forEachPrimitive(node, function (babylonMesh) {
  2027. babylonMesh.skeleton = skeleton;
  2028. });
  2029. };
  2030. if (skin._data) {
  2031. assignSkeleton(skin._data.babylonSkeleton);
  2032. return skin._data.promise;
  2033. }
  2034. var skeletonId = "skeleton" + skin.index;
  2035. var babylonSkeleton = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Skeleton"](skin.name || skeletonId, skeletonId, this._babylonScene);
  2036. // See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
  2037. babylonSkeleton.overrideMesh = this._rootBabylonMesh;
  2038. this._loadBones(context, skin, babylonSkeleton);
  2039. assignSkeleton(babylonSkeleton);
  2040. var promise = this._loadSkinInverseBindMatricesDataAsync(context, skin).then(function (inverseBindMatricesData) {
  2041. _this._updateBoneMatrices(babylonSkeleton, inverseBindMatricesData);
  2042. });
  2043. skin._data = {
  2044. babylonSkeleton: babylonSkeleton,
  2045. promise: promise
  2046. };
  2047. return promise;
  2048. };
  2049. GLTFLoader.prototype._loadBones = function (context, skin, babylonSkeleton) {
  2050. var babylonBones = {};
  2051. for (var _i = 0, _a = skin.joints; _i < _a.length; _i++) {
  2052. var index = _a[_i];
  2053. var node = ArrayItem.Get(context + "/joints/" + index, this._gltf.nodes, index);
  2054. this._loadBone(node, skin, babylonSkeleton, babylonBones);
  2055. }
  2056. };
  2057. GLTFLoader.prototype._loadBone = function (node, skin, babylonSkeleton, babylonBones) {
  2058. var babylonBone = babylonBones[node.index];
  2059. if (babylonBone) {
  2060. return babylonBone;
  2061. }
  2062. var babylonParentBone = null;
  2063. if (node.parent && node.parent._babylonTransformNode !== this._rootBabylonMesh) {
  2064. babylonParentBone = this._loadBone(node.parent, skin, babylonSkeleton, babylonBones);
  2065. }
  2066. var boneIndex = skin.joints.indexOf(node.index);
  2067. babylonBone = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Bone"](node.name || "joint" + node.index, babylonSkeleton, babylonParentBone, this._getNodeMatrix(node), null, null, boneIndex);
  2068. babylonBones[node.index] = babylonBone;
  2069. node._babylonBones = node._babylonBones || [];
  2070. node._babylonBones.push(babylonBone);
  2071. return babylonBone;
  2072. };
  2073. GLTFLoader.prototype._loadSkinInverseBindMatricesDataAsync = function (context, skin) {
  2074. if (skin.inverseBindMatrices == undefined) {
  2075. return Promise.resolve(null);
  2076. }
  2077. var accessor = ArrayItem.Get(context + "/inverseBindMatrices", this._gltf.accessors, skin.inverseBindMatrices);
  2078. return this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor);
  2079. };
  2080. GLTFLoader.prototype._updateBoneMatrices = function (babylonSkeleton, inverseBindMatricesData) {
  2081. for (var _i = 0, _a = babylonSkeleton.bones; _i < _a.length; _i++) {
  2082. var babylonBone = _a[_i];
  2083. var baseMatrix = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].Identity();
  2084. var boneIndex = babylonBone._index;
  2085. if (inverseBindMatricesData && boneIndex !== -1) {
  2086. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArrayToRef(inverseBindMatricesData, boneIndex * 16, baseMatrix);
  2087. baseMatrix.invertToRef(baseMatrix);
  2088. }
  2089. var babylonParentBone = babylonBone.getParent();
  2090. if (babylonParentBone) {
  2091. baseMatrix.multiplyToRef(babylonParentBone.getInvertedAbsoluteTransform(), baseMatrix);
  2092. }
  2093. babylonBone.updateMatrix(baseMatrix, false, false);
  2094. babylonBone._updateDifferenceMatrix(undefined, false);
  2095. }
  2096. };
  2097. GLTFLoader.prototype._getNodeMatrix = function (node) {
  2098. return node.matrix ?
  2099. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromArray(node.matrix) :
  2100. 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());
  2101. };
  2102. /**
  2103. * Loads a glTF camera.
  2104. * @param context The context when loading the asset
  2105. * @param camera The glTF camera property
  2106. * @param assign A function called synchronously after parsing the glTF properties
  2107. * @returns A promise that resolves with the loaded Babylon camera when the load is complete
  2108. */
  2109. GLTFLoader.prototype.loadCameraAsync = function (context, camera, assign) {
  2110. if (assign === void 0) { assign = function () { }; }
  2111. var extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
  2112. if (extensionPromise) {
  2113. return extensionPromise;
  2114. }
  2115. var promises = new Array();
  2116. this.logOpen(context + " " + (camera.name || ""));
  2117. 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);
  2118. babylonCamera.rotation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"](0, Math.PI, 0);
  2119. switch (camera.type) {
  2120. case "perspective" /* PERSPECTIVE */: {
  2121. var perspective = camera.perspective;
  2122. if (!perspective) {
  2123. throw new Error(context + ": Camera perspective properties are missing");
  2124. }
  2125. babylonCamera.fov = perspective.yfov;
  2126. babylonCamera.minZ = perspective.znear;
  2127. babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
  2128. break;
  2129. }
  2130. case "orthographic" /* ORTHOGRAPHIC */: {
  2131. if (!camera.orthographic) {
  2132. throw new Error(context + ": Camera orthographic properties are missing");
  2133. }
  2134. babylonCamera.mode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Camera"].ORTHOGRAPHIC_CAMERA;
  2135. babylonCamera.orthoLeft = -camera.orthographic.xmag;
  2136. babylonCamera.orthoRight = camera.orthographic.xmag;
  2137. babylonCamera.orthoBottom = -camera.orthographic.ymag;
  2138. babylonCamera.orthoTop = camera.orthographic.ymag;
  2139. babylonCamera.minZ = camera.orthographic.znear;
  2140. babylonCamera.maxZ = camera.orthographic.zfar;
  2141. break;
  2142. }
  2143. default: {
  2144. throw new Error(context + ": Invalid camera type (" + camera.type + ")");
  2145. }
  2146. }
  2147. GLTFLoader.AddPointerMetadata(babylonCamera, context);
  2148. this._parent.onCameraLoadedObservable.notifyObservers(babylonCamera);
  2149. assign(babylonCamera);
  2150. return Promise.all(promises).then(function () {
  2151. return babylonCamera;
  2152. });
  2153. };
  2154. GLTFLoader.prototype._loadAnimationsAsync = function () {
  2155. var animations = this._gltf.animations;
  2156. if (!animations) {
  2157. return Promise.resolve();
  2158. }
  2159. var promises = new Array();
  2160. for (var index = 0; index < animations.length; index++) {
  2161. var animation = animations[index];
  2162. promises.push(this.loadAnimationAsync("/animations/" + animation.index, animation));
  2163. }
  2164. return Promise.all(promises).then(function () { });
  2165. };
  2166. /**
  2167. * Loads a glTF animation.
  2168. * @param context The context when loading the asset
  2169. * @param animation The glTF animation property
  2170. * @returns A promise that resolves with the loaded Babylon animation group when the load is complete
  2171. */
  2172. GLTFLoader.prototype.loadAnimationAsync = function (context, animation) {
  2173. var promise = this._extensionsLoadAnimationAsync(context, animation);
  2174. if (promise) {
  2175. return promise;
  2176. }
  2177. var babylonAnimationGroup = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationGroup"](animation.name || "animation" + animation.index, this._babylonScene);
  2178. animation._babylonAnimationGroup = babylonAnimationGroup;
  2179. var promises = new Array();
  2180. ArrayItem.Assign(animation.channels);
  2181. ArrayItem.Assign(animation.samplers);
  2182. for (var _i = 0, _a = animation.channels; _i < _a.length; _i++) {
  2183. var channel = _a[_i];
  2184. promises.push(this._loadAnimationChannelAsync(context + "/channels/" + channel.index, context, animation, channel, babylonAnimationGroup));
  2185. }
  2186. return Promise.all(promises).then(function () {
  2187. babylonAnimationGroup.normalize(0);
  2188. return babylonAnimationGroup;
  2189. });
  2190. };
  2191. /**
  2192. * @hidden Loads a glTF animation channel.
  2193. * @param context The context when loading the asset
  2194. * @param animationContext The context of the animation when loading the asset
  2195. * @param animation The glTF animation property
  2196. * @param channel The glTF animation channel property
  2197. * @param babylonAnimationGroup The babylon animation group property
  2198. * @param animationTargetOverride The babylon animation channel target override property. My be null.
  2199. * @returns A void promise when the channel load is complete
  2200. */
  2201. GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup, animationTargetOverride) {
  2202. var _this = this;
  2203. if (animationTargetOverride === void 0) { animationTargetOverride = null; }
  2204. if (channel.target.node == undefined) {
  2205. return Promise.resolve();
  2206. }
  2207. var targetNode = ArrayItem.Get(context + "/target/node", this._gltf.nodes, channel.target.node);
  2208. // Ignore animations that have no animation targets.
  2209. if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
  2210. (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonTransformNode)) {
  2211. return Promise.resolve();
  2212. }
  2213. var sampler = ArrayItem.Get(context + "/sampler", animation.samplers, channel.sampler);
  2214. return this._loadAnimationSamplerAsync(animationContext + "/samplers/" + channel.sampler, sampler).then(function (data) {
  2215. var targetPath;
  2216. var animationType;
  2217. switch (channel.target.path) {
  2218. case "translation" /* TRANSLATION */: {
  2219. targetPath = "position";
  2220. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  2221. break;
  2222. }
  2223. case "rotation" /* ROTATION */: {
  2224. targetPath = "rotationQuaternion";
  2225. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION;
  2226. break;
  2227. }
  2228. case "scale" /* SCALE */: {
  2229. targetPath = "scaling";
  2230. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3;
  2231. break;
  2232. }
  2233. case "weights" /* WEIGHTS */: {
  2234. targetPath = "influence";
  2235. animationType = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT;
  2236. break;
  2237. }
  2238. default: {
  2239. throw new Error(context + "/target/path: Invalid value (" + channel.target.path + ")");
  2240. }
  2241. }
  2242. var outputBufferOffset = 0;
  2243. var getNextOutputValue;
  2244. switch (targetPath) {
  2245. case "position": {
  2246. getNextOutputValue = function () {
  2247. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  2248. outputBufferOffset += 3;
  2249. return value;
  2250. };
  2251. break;
  2252. }
  2253. case "rotationQuaternion": {
  2254. getNextOutputValue = function () {
  2255. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(data.output, outputBufferOffset);
  2256. outputBufferOffset += 4;
  2257. return value;
  2258. };
  2259. break;
  2260. }
  2261. case "scaling": {
  2262. getNextOutputValue = function () {
  2263. var value = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(data.output, outputBufferOffset);
  2264. outputBufferOffset += 3;
  2265. return value;
  2266. };
  2267. break;
  2268. }
  2269. case "influence": {
  2270. getNextOutputValue = function () {
  2271. var value = new Array(targetNode._numMorphTargets);
  2272. for (var i = 0; i < targetNode._numMorphTargets; i++) {
  2273. value[i] = data.output[outputBufferOffset++];
  2274. }
  2275. return value;
  2276. };
  2277. break;
  2278. }
  2279. }
  2280. var getNextKey;
  2281. switch (data.interpolation) {
  2282. case "STEP" /* STEP */: {
  2283. getNextKey = function (frameIndex) { return ({
  2284. frame: data.input[frameIndex],
  2285. value: getNextOutputValue(),
  2286. interpolation: babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP
  2287. }); };
  2288. break;
  2289. }
  2290. case "LINEAR" /* LINEAR */: {
  2291. getNextKey = function (frameIndex) { return ({
  2292. frame: data.input[frameIndex],
  2293. value: getNextOutputValue()
  2294. }); };
  2295. break;
  2296. }
  2297. case "CUBICSPLINE" /* CUBICSPLINE */: {
  2298. getNextKey = function (frameIndex) { return ({
  2299. frame: data.input[frameIndex],
  2300. inTangent: getNextOutputValue(),
  2301. value: getNextOutputValue(),
  2302. outTangent: getNextOutputValue()
  2303. }); };
  2304. break;
  2305. }
  2306. }
  2307. var keys = new Array(data.input.length);
  2308. for (var frameIndex = 0; frameIndex < data.input.length; frameIndex++) {
  2309. keys[frameIndex] = getNextKey(frameIndex);
  2310. }
  2311. if (targetPath === "influence") {
  2312. var _loop_1 = function (targetIndex) {
  2313. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  2314. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  2315. babylonAnimation.setKeys(keys.map(function (key) { return ({
  2316. frame: key.frame,
  2317. inTangent: key.inTangent ? key.inTangent[targetIndex] : undefined,
  2318. value: key.value[targetIndex],
  2319. outTangent: key.outTangent ? key.outTangent[targetIndex] : undefined
  2320. }); }));
  2321. _this._forEachPrimitive(targetNode, function (babylonAbstractMesh) {
  2322. var babylonMesh = babylonAbstractMesh;
  2323. var morphTarget = babylonMesh.morphTargetManager.getTarget(targetIndex);
  2324. var babylonAnimationClone = babylonAnimation.clone();
  2325. morphTarget.animations.push(babylonAnimationClone);
  2326. babylonAnimationGroup.addTargetedAnimation(babylonAnimationClone, morphTarget);
  2327. });
  2328. };
  2329. for (var targetIndex = 0; targetIndex < targetNode._numMorphTargets; targetIndex++) {
  2330. _loop_1(targetIndex);
  2331. }
  2332. }
  2333. else {
  2334. var animationName = babylonAnimationGroup.name + "_channel" + babylonAnimationGroup.targetedAnimations.length;
  2335. var babylonAnimation = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationName, targetPath, 1, animationType);
  2336. babylonAnimation.setKeys(keys);
  2337. if (animationTargetOverride != null && animationTargetOverride.animations != null) {
  2338. animationTargetOverride.animations.push(babylonAnimation);
  2339. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, animationTargetOverride);
  2340. }
  2341. else {
  2342. targetNode._babylonTransformNode.animations.push(babylonAnimation);
  2343. babylonAnimationGroup.addTargetedAnimation(babylonAnimation, targetNode._babylonTransformNode);
  2344. }
  2345. }
  2346. });
  2347. };
  2348. GLTFLoader.prototype._loadAnimationSamplerAsync = function (context, sampler) {
  2349. if (sampler._data) {
  2350. return sampler._data;
  2351. }
  2352. var interpolation = sampler.interpolation || "LINEAR" /* LINEAR */;
  2353. switch (interpolation) {
  2354. case "STEP" /* STEP */:
  2355. case "LINEAR" /* LINEAR */:
  2356. case "CUBICSPLINE" /* CUBICSPLINE */: {
  2357. break;
  2358. }
  2359. default: {
  2360. throw new Error(context + "/interpolation: Invalid value (" + sampler.interpolation + ")");
  2361. }
  2362. }
  2363. var inputAccessor = ArrayItem.Get(context + "/input", this._gltf.accessors, sampler.input);
  2364. var outputAccessor = ArrayItem.Get(context + "/output", this._gltf.accessors, sampler.output);
  2365. sampler._data = Promise.all([
  2366. this._loadFloatAccessorAsync("/accessors/" + inputAccessor.index, inputAccessor),
  2367. this._loadFloatAccessorAsync("/accessors/" + outputAccessor.index, outputAccessor)
  2368. ]).then(function (_a) {
  2369. var inputData = _a[0], outputData = _a[1];
  2370. return {
  2371. input: inputData,
  2372. interpolation: interpolation,
  2373. output: outputData,
  2374. };
  2375. });
  2376. return sampler._data;
  2377. };
  2378. GLTFLoader.prototype._loadBufferAsync = function (context, buffer) {
  2379. if (buffer._data) {
  2380. return buffer._data;
  2381. }
  2382. if (!buffer.uri) {
  2383. throw new Error(context + "/uri: Value is missing");
  2384. }
  2385. buffer._data = this.loadUriAsync(context + "/uri", buffer, buffer.uri);
  2386. return buffer._data;
  2387. };
  2388. /**
  2389. * Loads a glTF buffer view.
  2390. * @param context The context when loading the asset
  2391. * @param bufferView The glTF buffer view property
  2392. * @returns A promise that resolves with the loaded data when the load is complete
  2393. */
  2394. GLTFLoader.prototype.loadBufferViewAsync = function (context, bufferView) {
  2395. if (bufferView._data) {
  2396. return bufferView._data;
  2397. }
  2398. var buffer = ArrayItem.Get(context + "/buffer", this._gltf.buffers, bufferView.buffer);
  2399. bufferView._data = this._loadBufferAsync("/buffers/" + buffer.index, buffer).then(function (data) {
  2400. try {
  2401. return new Uint8Array(data.buffer, data.byteOffset + (bufferView.byteOffset || 0), bufferView.byteLength);
  2402. }
  2403. catch (e) {
  2404. throw new Error(context + ": " + e.message);
  2405. }
  2406. });
  2407. return bufferView._data;
  2408. };
  2409. GLTFLoader.prototype._loadIndicesAccessorAsync = function (context, accessor) {
  2410. if (accessor.type !== "SCALAR" /* SCALAR */) {
  2411. throw new Error(context + "/type: Invalid value " + accessor.type);
  2412. }
  2413. if (accessor.componentType !== 5121 /* UNSIGNED_BYTE */ &&
  2414. accessor.componentType !== 5123 /* UNSIGNED_SHORT */ &&
  2415. accessor.componentType !== 5125 /* UNSIGNED_INT */) {
  2416. throw new Error(context + "/componentType: Invalid value " + accessor.componentType);
  2417. }
  2418. if (accessor._data) {
  2419. return accessor._data;
  2420. }
  2421. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  2422. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2423. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
  2424. });
  2425. return accessor._data;
  2426. };
  2427. GLTFLoader.prototype._loadFloatAccessorAsync = function (context, accessor) {
  2428. // TODO: support normalized and stride
  2429. var _this = this;
  2430. if (accessor.componentType !== 5126 /* FLOAT */) {
  2431. throw new Error("Invalid component type " + accessor.componentType);
  2432. }
  2433. if (accessor._data) {
  2434. return accessor._data;
  2435. }
  2436. var numComponents = GLTFLoader._GetNumComponents(context, accessor.type);
  2437. var length = numComponents * accessor.count;
  2438. if (accessor.bufferView == undefined) {
  2439. accessor._data = Promise.resolve(new Float32Array(length));
  2440. }
  2441. else {
  2442. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  2443. accessor._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2444. return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, length);
  2445. });
  2446. }
  2447. if (accessor.sparse) {
  2448. var sparse_1 = accessor.sparse;
  2449. accessor._data = accessor._data.then(function (view) {
  2450. var data = view;
  2451. var indicesBufferView = ArrayItem.Get(context + "/sparse/indices/bufferView", _this._gltf.bufferViews, sparse_1.indices.bufferView);
  2452. var valuesBufferView = ArrayItem.Get(context + "/sparse/values/bufferView", _this._gltf.bufferViews, sparse_1.values.bufferView);
  2453. return Promise.all([
  2454. _this.loadBufferViewAsync("/bufferViews/" + indicesBufferView.index, indicesBufferView),
  2455. _this.loadBufferViewAsync("/bufferViews/" + valuesBufferView.index, valuesBufferView)
  2456. ]).then(function (_a) {
  2457. var indicesData = _a[0], valuesData = _a[1];
  2458. var indices = GLTFLoader._GetTypedArray(context + "/sparse/indices", sparse_1.indices.componentType, indicesData, sparse_1.indices.byteOffset, sparse_1.count);
  2459. var values = GLTFLoader._GetTypedArray(context + "/sparse/values", accessor.componentType, valuesData, sparse_1.values.byteOffset, numComponents * sparse_1.count);
  2460. var valuesIndex = 0;
  2461. for (var indicesIndex = 0; indicesIndex < indices.length; indicesIndex++) {
  2462. var dataIndex = indices[indicesIndex] * numComponents;
  2463. for (var componentIndex = 0; componentIndex < numComponents; componentIndex++) {
  2464. data[dataIndex++] = values[valuesIndex++];
  2465. }
  2466. }
  2467. return data;
  2468. });
  2469. });
  2470. }
  2471. return accessor._data;
  2472. };
  2473. GLTFLoader.prototype._loadVertexBufferViewAsync = function (bufferView, kind) {
  2474. var _this = this;
  2475. if (bufferView._babylonBuffer) {
  2476. return bufferView._babylonBuffer;
  2477. }
  2478. bufferView._babylonBuffer = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView).then(function (data) {
  2479. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Buffer"](_this._babylonScene.getEngine(), data, false);
  2480. });
  2481. return bufferView._babylonBuffer;
  2482. };
  2483. GLTFLoader.prototype._loadVertexAccessorAsync = function (context, accessor, kind) {
  2484. var _this = this;
  2485. if (accessor._babylonVertexBuffer) {
  2486. return accessor._babylonVertexBuffer;
  2487. }
  2488. if (accessor.sparse) {
  2489. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2490. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  2491. });
  2492. }
  2493. // HACK: If byte offset is not a multiple of component type byte length then load as a float array instead of using Babylon buffers.
  2494. else if (accessor.byteOffset && accessor.byteOffset % babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(accessor.componentType) !== 0) {
  2495. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Accessor byte offset is not a multiple of component type byte length");
  2496. accessor._babylonVertexBuffer = this._loadFloatAccessorAsync("/accessors/" + accessor.index, accessor).then(function (data) {
  2497. return new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"](_this._babylonScene.getEngine(), data, kind, false);
  2498. });
  2499. }
  2500. else {
  2501. var bufferView_1 = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, accessor.bufferView);
  2502. accessor._babylonVertexBuffer = this._loadVertexBufferViewAsync(bufferView_1, kind).then(function (babylonBuffer) {
  2503. var size = GLTFLoader._GetNumComponents(context, accessor.type);
  2504. 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);
  2505. });
  2506. }
  2507. return accessor._babylonVertexBuffer;
  2508. };
  2509. GLTFLoader.prototype._loadMaterialMetallicRoughnessPropertiesAsync = function (context, properties, babylonMaterial) {
  2510. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2511. throw new Error(context + ": Material type not supported");
  2512. }
  2513. var promises = new Array();
  2514. if (properties) {
  2515. if (properties.baseColorFactor) {
  2516. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromArray(properties.baseColorFactor);
  2517. babylonMaterial.alpha = properties.baseColorFactor[3];
  2518. }
  2519. else {
  2520. babylonMaterial.albedoColor = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Color3"].White();
  2521. }
  2522. babylonMaterial.metallic = properties.metallicFactor == undefined ? 1 : properties.metallicFactor;
  2523. babylonMaterial.roughness = properties.roughnessFactor == undefined ? 1 : properties.roughnessFactor;
  2524. if (properties.baseColorTexture) {
  2525. promises.push(this.loadTextureInfoAsync(context + "/baseColorTexture", properties.baseColorTexture, function (texture) {
  2526. texture.name = babylonMaterial.name + " (Base Color)";
  2527. babylonMaterial.albedoTexture = texture;
  2528. }));
  2529. }
  2530. if (properties.metallicRoughnessTexture) {
  2531. promises.push(this.loadTextureInfoAsync(context + "/metallicRoughnessTexture", properties.metallicRoughnessTexture, function (texture) {
  2532. texture.name = babylonMaterial.name + " (Metallic Roughness)";
  2533. babylonMaterial.metallicTexture = texture;
  2534. }));
  2535. babylonMaterial.useMetallnessFromMetallicTextureBlue = true;
  2536. babylonMaterial.useRoughnessFromMetallicTextureGreen = true;
  2537. babylonMaterial.useRoughnessFromMetallicTextureAlpha = false;
  2538. }
  2539. }
  2540. return Promise.all(promises).then(function () { });
  2541. };
  2542. /** @hidden */
  2543. GLTFLoader.prototype._loadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  2544. if (assign === void 0) { assign = function () { }; }
  2545. var extensionPromise = this._extensionsLoadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign);
  2546. if (extensionPromise) {
  2547. return extensionPromise;
  2548. }
  2549. material._data = material._data || {};
  2550. var babylonData = material._data[babylonDrawMode];
  2551. if (!babylonData) {
  2552. this.logOpen(context + " " + (material.name || ""));
  2553. var babylonMaterial = this.createMaterial(context, material, babylonDrawMode);
  2554. babylonData = {
  2555. babylonMaterial: babylonMaterial,
  2556. babylonMeshes: [],
  2557. promise: this.loadMaterialPropertiesAsync(context, material, babylonMaterial)
  2558. };
  2559. material._data[babylonDrawMode] = babylonData;
  2560. GLTFLoader.AddPointerMetadata(babylonMaterial, context);
  2561. this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
  2562. this.logClose();
  2563. }
  2564. babylonData.babylonMeshes.push(babylonMesh);
  2565. babylonMesh.onDisposeObservable.addOnce(function () {
  2566. var index = babylonData.babylonMeshes.indexOf(babylonMesh);
  2567. if (index !== -1) {
  2568. babylonData.babylonMeshes.splice(index, 1);
  2569. }
  2570. });
  2571. assign(babylonData.babylonMaterial);
  2572. return babylonData.promise.then(function () {
  2573. return babylonData.babylonMaterial;
  2574. });
  2575. };
  2576. GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
  2577. var babylonMaterial = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"](name, this._babylonScene);
  2578. babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].CounterClockWiseSideOrientation : babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation;
  2579. babylonMaterial.fillMode = babylonDrawMode;
  2580. babylonMaterial.enableSpecularAntiAliasing = true;
  2581. babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
  2582. babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
  2583. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  2584. babylonMaterial.metallic = 1;
  2585. babylonMaterial.roughness = 1;
  2586. return babylonMaterial;
  2587. };
  2588. /**
  2589. * Creates a Babylon material from a glTF material.
  2590. * @param context The context when loading the asset
  2591. * @param material The glTF material property
  2592. * @param babylonDrawMode The draw mode for the Babylon material
  2593. * @returns The Babylon material
  2594. */
  2595. GLTFLoader.prototype.createMaterial = function (context, material, babylonDrawMode) {
  2596. var extensionPromise = this._extensionsCreateMaterial(context, material, babylonDrawMode);
  2597. if (extensionPromise) {
  2598. return extensionPromise;
  2599. }
  2600. var name = material.name || "material" + material.index;
  2601. var babylonMaterial = this._createDefaultMaterial(name, babylonDrawMode);
  2602. return babylonMaterial;
  2603. };
  2604. /**
  2605. * Loads properties from a glTF material into a Babylon material.
  2606. * @param context The context when loading the asset
  2607. * @param material The glTF material property
  2608. * @param babylonMaterial The Babylon material
  2609. * @returns A promise that resolves when the load is complete
  2610. */
  2611. GLTFLoader.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  2612. var extensionPromise = this._extensionsLoadMaterialPropertiesAsync(context, material, babylonMaterial);
  2613. if (extensionPromise) {
  2614. return extensionPromise;
  2615. }
  2616. var promises = new Array();
  2617. promises.push(this.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
  2618. if (material.pbrMetallicRoughness) {
  2619. promises.push(this._loadMaterialMetallicRoughnessPropertiesAsync(context + "/pbrMetallicRoughness", material.pbrMetallicRoughness, babylonMaterial));
  2620. }
  2621. this.loadMaterialAlphaProperties(context, material, babylonMaterial);
  2622. return Promise.all(promises).then(function () { });
  2623. };
  2624. /**
  2625. * Loads the normal, occlusion, and emissive properties from a glTF material into a Babylon material.
  2626. * @param context The context when loading the asset
  2627. * @param material The glTF material property
  2628. * @param babylonMaterial The Babylon material
  2629. * @returns A promise that resolves when the load is complete
  2630. */
  2631. GLTFLoader.prototype.loadMaterialBasePropertiesAsync = function (context, material, babylonMaterial) {
  2632. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2633. throw new Error(context + ": Material type not supported");
  2634. }
  2635. var promises = new Array();
  2636. 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);
  2637. if (material.doubleSided) {
  2638. babylonMaterial.backFaceCulling = false;
  2639. babylonMaterial.twoSidedLighting = true;
  2640. }
  2641. if (material.normalTexture) {
  2642. promises.push(this.loadTextureInfoAsync(context + "/normalTexture", material.normalTexture, function (texture) {
  2643. texture.name = babylonMaterial.name + " (Normal)";
  2644. babylonMaterial.bumpTexture = texture;
  2645. }));
  2646. babylonMaterial.invertNormalMapX = !this._babylonScene.useRightHandedSystem;
  2647. babylonMaterial.invertNormalMapY = this._babylonScene.useRightHandedSystem;
  2648. if (material.normalTexture.scale != undefined) {
  2649. babylonMaterial.bumpTexture.level = material.normalTexture.scale;
  2650. }
  2651. babylonMaterial.forceIrradianceInFragment = true;
  2652. }
  2653. if (material.occlusionTexture) {
  2654. promises.push(this.loadTextureInfoAsync(context + "/occlusionTexture", material.occlusionTexture, function (texture) {
  2655. texture.name = babylonMaterial.name + " (Occlusion)";
  2656. babylonMaterial.ambientTexture = texture;
  2657. }));
  2658. babylonMaterial.useAmbientInGrayScale = true;
  2659. if (material.occlusionTexture.strength != undefined) {
  2660. babylonMaterial.ambientTextureStrength = material.occlusionTexture.strength;
  2661. }
  2662. }
  2663. if (material.emissiveTexture) {
  2664. promises.push(this.loadTextureInfoAsync(context + "/emissiveTexture", material.emissiveTexture, function (texture) {
  2665. texture.name = babylonMaterial.name + " (Emissive)";
  2666. babylonMaterial.emissiveTexture = texture;
  2667. }));
  2668. }
  2669. return Promise.all(promises).then(function () { });
  2670. };
  2671. /**
  2672. * Loads the alpha properties from a glTF material into a Babylon material.
  2673. * Must be called after the setting the albedo texture of the Babylon material when the material has an albedo texture.
  2674. * @param context The context when loading the asset
  2675. * @param material The glTF material property
  2676. * @param babylonMaterial The Babylon material
  2677. */
  2678. GLTFLoader.prototype.loadMaterialAlphaProperties = function (context, material, babylonMaterial) {
  2679. if (!(babylonMaterial instanceof babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"])) {
  2680. throw new Error(context + ": Material type not supported");
  2681. }
  2682. var alphaMode = material.alphaMode || "OPAQUE" /* OPAQUE */;
  2683. switch (alphaMode) {
  2684. case "OPAQUE" /* OPAQUE */: {
  2685. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_OPAQUE;
  2686. break;
  2687. }
  2688. case "MASK" /* MASK */: {
  2689. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHATEST;
  2690. babylonMaterial.alphaCutOff = (material.alphaCutoff == undefined ? 0.5 : material.alphaCutoff);
  2691. if (babylonMaterial.albedoTexture) {
  2692. babylonMaterial.albedoTexture.hasAlpha = true;
  2693. }
  2694. break;
  2695. }
  2696. case "BLEND" /* BLEND */: {
  2697. babylonMaterial.transparencyMode = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"].PBRMATERIAL_ALPHABLEND;
  2698. if (babylonMaterial.albedoTexture) {
  2699. babylonMaterial.albedoTexture.hasAlpha = true;
  2700. babylonMaterial.useAlphaFromAlbedoTexture = true;
  2701. }
  2702. break;
  2703. }
  2704. default: {
  2705. throw new Error(context + "/alphaMode: Invalid value (" + material.alphaMode + ")");
  2706. }
  2707. }
  2708. };
  2709. /**
  2710. * Loads a glTF texture info.
  2711. * @param context The context when loading the asset
  2712. * @param textureInfo The glTF texture info property
  2713. * @param assign A function called synchronously after parsing the glTF properties
  2714. * @returns A promise that resolves with the loaded Babylon texture when the load is complete
  2715. */
  2716. GLTFLoader.prototype.loadTextureInfoAsync = function (context, textureInfo, assign) {
  2717. var _this = this;
  2718. if (assign === void 0) { assign = function () { }; }
  2719. var extensionPromise = this._extensionsLoadTextureInfoAsync(context, textureInfo, assign);
  2720. if (extensionPromise) {
  2721. return extensionPromise;
  2722. }
  2723. this.logOpen("" + context);
  2724. var texture = ArrayItem.Get(context + "/index", this._gltf.textures, textureInfo.index);
  2725. var promise = this._loadTextureAsync("/textures/" + textureInfo.index, texture, function (babylonTexture) {
  2726. babylonTexture.coordinatesIndex = textureInfo.texCoord || 0;
  2727. GLTFLoader.AddPointerMetadata(babylonTexture, context);
  2728. _this._parent.onTextureLoadedObservable.notifyObservers(babylonTexture);
  2729. assign(babylonTexture);
  2730. });
  2731. this.logClose();
  2732. return promise;
  2733. };
  2734. GLTFLoader.prototype._loadTextureAsync = function (context, texture, assign) {
  2735. var _this = this;
  2736. if (assign === void 0) { assign = function () { }; }
  2737. var promises = new Array();
  2738. this.logOpen(context + " " + (texture.name || ""));
  2739. var sampler = (texture.sampler == undefined ? GLTFLoader._DefaultSampler : ArrayItem.Get(context + "/sampler", this._gltf.samplers, texture.sampler));
  2740. var samplerData = this._loadSampler("/samplers/" + sampler.index, sampler);
  2741. var image = ArrayItem.Get(context + "/source", this._gltf.images, texture.source);
  2742. var url = null;
  2743. if (image.uri) {
  2744. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(image.uri)) {
  2745. url = image.uri;
  2746. }
  2747. else if (this._babylonScene.getEngine().textureFormatInUse) {
  2748. // 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
  2749. url = this._rootUrl + image.uri;
  2750. }
  2751. }
  2752. var deferred = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Deferred"]();
  2753. var babylonTexture = new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"](url, this._babylonScene, samplerData.noMipMaps, false, samplerData.samplingMode, function () {
  2754. if (!_this._disposed) {
  2755. deferred.resolve();
  2756. }
  2757. }, function (message, exception) {
  2758. if (!_this._disposed) {
  2759. deferred.reject(new Error(context + ": " + ((exception && exception.message) ? exception.message : message || "Failed to load texture")));
  2760. }
  2761. });
  2762. promises.push(deferred.promise);
  2763. if (!url) {
  2764. promises.push(this.loadImageAsync("/images/" + image.index, image).then(function (data) {
  2765. var name = image.uri || _this._fileName + "#image" + image.index;
  2766. var dataUrl = "data:" + _this._uniqueRootUrl + name;
  2767. babylonTexture.updateURL(dataUrl, new Blob([data], { type: image.mimeType }));
  2768. }));
  2769. }
  2770. babylonTexture.wrapU = samplerData.wrapU;
  2771. babylonTexture.wrapV = samplerData.wrapV;
  2772. assign(babylonTexture);
  2773. this.logClose();
  2774. return Promise.all(promises).then(function () {
  2775. return babylonTexture;
  2776. });
  2777. };
  2778. GLTFLoader.prototype._loadSampler = function (context, sampler) {
  2779. if (!sampler._data) {
  2780. sampler._data = {
  2781. noMipMaps: (sampler.minFilter === 9728 /* NEAREST */ || sampler.minFilter === 9729 /* LINEAR */),
  2782. samplingMode: GLTFLoader._GetTextureSamplingMode(context, sampler),
  2783. wrapU: GLTFLoader._GetTextureWrapMode(context + "/wrapS", sampler.wrapS),
  2784. wrapV: GLTFLoader._GetTextureWrapMode(context + "/wrapT", sampler.wrapT)
  2785. };
  2786. }
  2787. return sampler._data;
  2788. };
  2789. /**
  2790. * Loads a glTF image.
  2791. * @param context The context when loading the asset
  2792. * @param image The glTF image property
  2793. * @returns A promise that resolves with the loaded data when the load is complete
  2794. */
  2795. GLTFLoader.prototype.loadImageAsync = function (context, image) {
  2796. if (!image._data) {
  2797. this.logOpen(context + " " + (image.name || ""));
  2798. if (image.uri) {
  2799. image._data = this.loadUriAsync(context + "/uri", image, image.uri);
  2800. }
  2801. else {
  2802. var bufferView = ArrayItem.Get(context + "/bufferView", this._gltf.bufferViews, image.bufferView);
  2803. image._data = this.loadBufferViewAsync("/bufferViews/" + bufferView.index, bufferView);
  2804. }
  2805. this.logClose();
  2806. }
  2807. return image._data;
  2808. };
  2809. /**
  2810. * Loads a glTF uri.
  2811. * @param context The context when loading the asset
  2812. * @param property The glTF property associated with the uri
  2813. * @param uri The base64 or relative uri
  2814. * @returns A promise that resolves with the loaded data when the load is complete
  2815. */
  2816. GLTFLoader.prototype.loadUriAsync = function (context, property, uri) {
  2817. var _this = this;
  2818. var extensionPromise = this._extensionsLoadUriAsync(context, property, uri);
  2819. if (extensionPromise) {
  2820. return extensionPromise;
  2821. }
  2822. if (!GLTFLoader._ValidateUri(uri)) {
  2823. throw new Error(context + ": '" + uri + "' is invalid");
  2824. }
  2825. if (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri)) {
  2826. var data = new Uint8Array(babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].DecodeBase64(uri));
  2827. this.log("Decoded " + uri.substr(0, 64) + "... (" + data.length + " bytes)");
  2828. return Promise.resolve(data);
  2829. }
  2830. this.log("Loading " + uri);
  2831. return this._parent.preprocessUrlAsync(this._rootUrl + uri).then(function (url) {
  2832. return new Promise(function (resolve, reject) {
  2833. if (!_this._disposed) {
  2834. var request_1 = babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].LoadFile(url, function (fileData) {
  2835. if (!_this._disposed) {
  2836. var data = new Uint8Array(fileData);
  2837. _this.log("Loaded " + uri + " (" + data.length + " bytes)");
  2838. resolve(data);
  2839. }
  2840. }, function (event) {
  2841. if (!_this._disposed) {
  2842. if (request_1) {
  2843. request_1._lengthComputable = event.lengthComputable;
  2844. request_1._loaded = event.loaded;
  2845. request_1._total = event.total;
  2846. }
  2847. if (_this._state === _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFLoaderState"].LOADING) {
  2848. try {
  2849. _this._onProgress();
  2850. }
  2851. catch (e) {
  2852. reject(e);
  2853. }
  2854. }
  2855. }
  2856. }, _this._babylonScene.offlineProvider, true, function (request, exception) {
  2857. if (!_this._disposed) {
  2858. reject(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["LoadFileError"](context + ": Failed to load '" + uri + "'" + (request ? ": " + request.status + " " + request.statusText : ""), request));
  2859. }
  2860. });
  2861. _this._requests.push(request_1);
  2862. }
  2863. });
  2864. });
  2865. };
  2866. GLTFLoader.prototype._onProgress = function () {
  2867. if (!this._progressCallback) {
  2868. return;
  2869. }
  2870. var lengthComputable = true;
  2871. var loaded = 0;
  2872. var total = 0;
  2873. for (var _i = 0, _a = this._requests; _i < _a.length; _i++) {
  2874. var request = _a[_i];
  2875. if (request._lengthComputable === undefined || request._loaded === undefined || request._total === undefined) {
  2876. return;
  2877. }
  2878. lengthComputable = lengthComputable && request._lengthComputable;
  2879. loaded += request._loaded;
  2880. total += request._total;
  2881. }
  2882. this._progressCallback(new babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["SceneLoaderProgressEvent"](lengthComputable, loaded, lengthComputable ? total : 0));
  2883. };
  2884. /**
  2885. * Adds a JSON pointer to the metadata of the Babylon object at `<object>.metadata.gltf.pointers`.
  2886. * @param babylonObject the Babylon object with metadata
  2887. * @param pointer the JSON pointer
  2888. */
  2889. GLTFLoader.AddPointerMetadata = function (babylonObject, pointer) {
  2890. var metadata = (babylonObject.metadata = babylonObject.metadata || {});
  2891. var gltf = (metadata.gltf = metadata.gltf || {});
  2892. var pointers = (gltf.pointers = gltf.pointers || []);
  2893. pointers.push(pointer);
  2894. };
  2895. GLTFLoader._GetTextureWrapMode = function (context, mode) {
  2896. // Set defaults if undefined
  2897. mode = mode == undefined ? 10497 /* REPEAT */ : mode;
  2898. switch (mode) {
  2899. case 33071 /* CLAMP_TO_EDGE */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE;
  2900. case 33648 /* MIRRORED_REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE;
  2901. case 10497 /* REPEAT */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  2902. default:
  2903. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Invalid value (" + mode + ")");
  2904. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE;
  2905. }
  2906. };
  2907. GLTFLoader._GetTextureSamplingMode = function (context, sampler) {
  2908. // Set defaults if undefined
  2909. var magFilter = sampler.magFilter == undefined ? 9729 /* LINEAR */ : sampler.magFilter;
  2910. var minFilter = sampler.minFilter == undefined ? 9987 /* LINEAR_MIPMAP_LINEAR */ : sampler.minFilter;
  2911. if (magFilter === 9729 /* LINEAR */) {
  2912. switch (minFilter) {
  2913. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST;
  2914. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR;
  2915. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST;
  2916. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST;
  2917. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR;
  2918. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  2919. default:
  2920. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  2921. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR;
  2922. }
  2923. }
  2924. else {
  2925. if (magFilter !== 9728 /* NEAREST */) {
  2926. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/magFilter: Invalid value (" + magFilter + ")");
  2927. }
  2928. switch (minFilter) {
  2929. case 9728 /* NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST;
  2930. case 9729 /* LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR;
  2931. case 9984 /* NEAREST_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  2932. case 9985 /* LINEAR_MIPMAP_NEAREST */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST;
  2933. case 9986 /* NEAREST_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR;
  2934. case 9987 /* LINEAR_MIPMAP_LINEAR */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR;
  2935. default:
  2936. babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + "/minFilter: Invalid value (" + minFilter + ")");
  2937. return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST;
  2938. }
  2939. }
  2940. };
  2941. GLTFLoader._GetTypedArray = function (context, componentType, bufferView, byteOffset, length) {
  2942. var buffer = bufferView.buffer;
  2943. byteOffset = bufferView.byteOffset + (byteOffset || 0);
  2944. try {
  2945. switch (componentType) {
  2946. case 5120 /* BYTE */: return new Int8Array(buffer, byteOffset, length);
  2947. case 5121 /* UNSIGNED_BYTE */: return new Uint8Array(buffer, byteOffset, length);
  2948. case 5122 /* SHORT */: return new Int16Array(buffer, byteOffset, length);
  2949. case 5123 /* UNSIGNED_SHORT */: return new Uint16Array(buffer, byteOffset, length);
  2950. case 5125 /* UNSIGNED_INT */: return new Uint32Array(buffer, byteOffset, length);
  2951. case 5126 /* FLOAT */: return new Float32Array(buffer, byteOffset, length);
  2952. default: throw new Error("Invalid component type " + componentType);
  2953. }
  2954. }
  2955. catch (e) {
  2956. throw new Error(context + ": " + e);
  2957. }
  2958. };
  2959. GLTFLoader._GetNumComponents = function (context, type) {
  2960. switch (type) {
  2961. case "SCALAR": return 1;
  2962. case "VEC2": return 2;
  2963. case "VEC3": return 3;
  2964. case "VEC4": return 4;
  2965. case "MAT2": return 4;
  2966. case "MAT3": return 9;
  2967. case "MAT4": return 16;
  2968. }
  2969. throw new Error(context + ": Invalid type (" + type + ")");
  2970. };
  2971. GLTFLoader._ValidateUri = function (uri) {
  2972. return (babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Tools"].IsBase64(uri) || uri.indexOf("..") === -1);
  2973. };
  2974. GLTFLoader._GetDrawMode = function (context, mode) {
  2975. if (mode == undefined) {
  2976. mode = 4 /* TRIANGLES */;
  2977. }
  2978. switch (mode) {
  2979. case 0 /* POINTS */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode;
  2980. case 1 /* LINES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  2981. case 2 /* LINE_LOOP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode;
  2982. case 3 /* LINE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode;
  2983. case 4 /* TRIANGLES */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  2984. case 5 /* TRIANGLE_STRIP */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode;
  2985. case 6 /* TRIANGLE_FAN */: return babylonjs_Misc_deferred__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode;
  2986. }
  2987. throw new Error(context + ": Invalid mesh primitive mode (" + mode + ")");
  2988. };
  2989. GLTFLoader.prototype._compileMaterialsAsync = function () {
  2990. var _this = this;
  2991. this._parent._startPerformanceCounter("Compile materials");
  2992. var promises = new Array();
  2993. if (this._gltf.materials) {
  2994. for (var _i = 0, _a = this._gltf.materials; _i < _a.length; _i++) {
  2995. var material = _a[_i];
  2996. if (material._data) {
  2997. for (var babylonDrawMode in material._data) {
  2998. var babylonData = material._data[babylonDrawMode];
  2999. for (var _b = 0, _c = babylonData.babylonMeshes; _b < _c.length; _b++) {
  3000. var babylonMesh = _c[_b];
  3001. // Ensure nonUniformScaling is set if necessary.
  3002. babylonMesh.computeWorldMatrix(true);
  3003. var babylonMaterial = babylonData.babylonMaterial;
  3004. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh));
  3005. if (this._parent.useClipPlane) {
  3006. promises.push(babylonMaterial.forceCompilationAsync(babylonMesh, { clipPlane: true }));
  3007. }
  3008. }
  3009. }
  3010. }
  3011. }
  3012. }
  3013. return Promise.all(promises).then(function () {
  3014. _this._parent._endPerformanceCounter("Compile materials");
  3015. });
  3016. };
  3017. GLTFLoader.prototype._compileShadowGeneratorsAsync = function () {
  3018. var _this = this;
  3019. this._parent._startPerformanceCounter("Compile shadow generators");
  3020. var promises = new Array();
  3021. var lights = this._babylonScene.lights;
  3022. for (var _i = 0, lights_1 = lights; _i < lights_1.length; _i++) {
  3023. var light = lights_1[_i];
  3024. var generator = light.getShadowGenerator();
  3025. if (generator) {
  3026. promises.push(generator.forceCompilationAsync());
  3027. }
  3028. }
  3029. return Promise.all(promises).then(function () {
  3030. _this._parent._endPerformanceCounter("Compile shadow generators");
  3031. });
  3032. };
  3033. GLTFLoader.prototype._forEachExtensions = function (action) {
  3034. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  3035. var name_4 = _a[_i];
  3036. var extension = this._extensions[name_4];
  3037. if (extension.enabled) {
  3038. action(extension);
  3039. }
  3040. }
  3041. };
  3042. GLTFLoader.prototype._applyExtensions = function (property, functionName, actionAsync) {
  3043. for (var _i = 0, _a = GLTFLoader._ExtensionNames; _i < _a.length; _i++) {
  3044. var name_5 = _a[_i];
  3045. var extension = this._extensions[name_5];
  3046. if (extension.enabled) {
  3047. var id = name_5 + "." + functionName;
  3048. var loaderProperty = property;
  3049. loaderProperty._activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions || {};
  3050. var activeLoaderExtensionFunctions = loaderProperty._activeLoaderExtensionFunctions;
  3051. if (!activeLoaderExtensionFunctions[id]) {
  3052. activeLoaderExtensionFunctions[id] = true;
  3053. try {
  3054. var result = actionAsync(extension);
  3055. if (result) {
  3056. return result;
  3057. }
  3058. }
  3059. finally {
  3060. delete activeLoaderExtensionFunctions[id];
  3061. }
  3062. }
  3063. }
  3064. }
  3065. return null;
  3066. };
  3067. GLTFLoader.prototype._extensionsOnLoading = function () {
  3068. this._forEachExtensions(function (extension) { return extension.onLoading && extension.onLoading(); });
  3069. };
  3070. GLTFLoader.prototype._extensionsOnReady = function () {
  3071. this._forEachExtensions(function (extension) { return extension.onReady && extension.onReady(); });
  3072. };
  3073. GLTFLoader.prototype._extensionsLoadSceneAsync = function (context, scene) {
  3074. return this._applyExtensions(scene, "loadScene", function (extension) { return extension.loadSceneAsync && extension.loadSceneAsync(context, scene); });
  3075. };
  3076. GLTFLoader.prototype._extensionsLoadNodeAsync = function (context, node, assign) {
  3077. return this._applyExtensions(node, "loadNode", function (extension) { return extension.loadNodeAsync && extension.loadNodeAsync(context, node, assign); });
  3078. };
  3079. GLTFLoader.prototype._extensionsLoadCameraAsync = function (context, camera, assign) {
  3080. return this._applyExtensions(camera, "loadCamera", function (extension) { return extension.loadCameraAsync && extension.loadCameraAsync(context, camera, assign); });
  3081. };
  3082. GLTFLoader.prototype._extensionsLoadVertexDataAsync = function (context, primitive, babylonMesh) {
  3083. return this._applyExtensions(primitive, "loadVertexData", function (extension) { return extension._loadVertexDataAsync && extension._loadVertexDataAsync(context, primitive, babylonMesh); });
  3084. };
  3085. GLTFLoader.prototype._extensionsLoadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
  3086. return this._applyExtensions(primitive, "loadMeshPrimitive", function (extension) { return extension._loadMeshPrimitiveAsync && extension._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, assign); });
  3087. };
  3088. GLTFLoader.prototype._extensionsLoadMaterialAsync = function (context, material, babylonMesh, babylonDrawMode, assign) {
  3089. return this._applyExtensions(material, "loadMaterial", function (extension) { return extension._loadMaterialAsync && extension._loadMaterialAsync(context, material, babylonMesh, babylonDrawMode, assign); });
  3090. };
  3091. GLTFLoader.prototype._extensionsCreateMaterial = function (context, material, babylonDrawMode) {
  3092. return this._applyExtensions(material, "createMaterial", function (extension) { return extension.createMaterial && extension.createMaterial(context, material, babylonDrawMode); });
  3093. };
  3094. GLTFLoader.prototype._extensionsLoadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
  3095. return this._applyExtensions(material, "loadMaterialProperties", function (extension) { return extension.loadMaterialPropertiesAsync && extension.loadMaterialPropertiesAsync(context, material, babylonMaterial); });
  3096. };
  3097. GLTFLoader.prototype._extensionsLoadTextureInfoAsync = function (context, textureInfo, assign) {
  3098. return this._applyExtensions(textureInfo, "loadTextureInfo", function (extension) { return extension.loadTextureInfoAsync && extension.loadTextureInfoAsync(context, textureInfo, assign); });
  3099. };
  3100. GLTFLoader.prototype._extensionsLoadAnimationAsync = function (context, animation) {
  3101. return this._applyExtensions(animation, "loadAnimation", function (extension) { return extension.loadAnimationAsync && extension.loadAnimationAsync(context, animation); });
  3102. };
  3103. GLTFLoader.prototype._extensionsLoadSkinAsync = function (context, node, skin) {
  3104. return this._applyExtensions(skin, "loadSkin", function (extension) { return extension._loadSkinAsync && extension._loadSkinAsync(context, node, skin); });
  3105. };
  3106. GLTFLoader.prototype._extensionsLoadUriAsync = function (context, property, uri) {
  3107. return this._applyExtensions(property, "loadUri", function (extension) { return extension._loadUriAsync && extension._loadUriAsync(context, property, uri); });
  3108. };
  3109. /**
  3110. * Helper method called by a loader extension to load an glTF extension.
  3111. * @param context The context when loading the asset
  3112. * @param property The glTF property to load the extension from
  3113. * @param extensionName The name of the extension to load
  3114. * @param actionAsync The action to run
  3115. * @returns The promise returned by actionAsync or null if the extension does not exist
  3116. */
  3117. GLTFLoader.LoadExtensionAsync = function (context, property, extensionName, actionAsync) {
  3118. if (!property.extensions) {
  3119. return null;
  3120. }
  3121. var extensions = property.extensions;
  3122. var extension = extensions[extensionName];
  3123. if (!extension) {
  3124. return null;
  3125. }
  3126. return actionAsync(context + "/extensions/" + extensionName, extension);
  3127. };
  3128. /**
  3129. * Helper method called by a loader extension to load a glTF extra.
  3130. * @param context The context when loading the asset
  3131. * @param property The glTF property to load the extra from
  3132. * @param extensionName The name of the extension to load
  3133. * @param actionAsync The action to run
  3134. * @returns The promise returned by actionAsync or null if the extra does not exist
  3135. */
  3136. GLTFLoader.LoadExtraAsync = function (context, property, extensionName, actionAsync) {
  3137. if (!property.extras) {
  3138. return null;
  3139. }
  3140. var extras = property.extras;
  3141. var extra = extras[extensionName];
  3142. if (!extra) {
  3143. return null;
  3144. }
  3145. return actionAsync(context + "/extras/" + extensionName, extra);
  3146. };
  3147. /**
  3148. * Increments the indentation level and logs a message.
  3149. * @param message The message to log
  3150. */
  3151. GLTFLoader.prototype.logOpen = function (message) {
  3152. this._parent._logOpen(message);
  3153. };
  3154. /**
  3155. * Decrements the indentation level.
  3156. */
  3157. GLTFLoader.prototype.logClose = function () {
  3158. this._parent._logClose();
  3159. };
  3160. /**
  3161. * Logs a message
  3162. * @param message The message to log
  3163. */
  3164. GLTFLoader.prototype.log = function (message) {
  3165. this._parent._log(message);
  3166. };
  3167. /**
  3168. * Starts a performance counter.
  3169. * @param counterName The name of the performance counter
  3170. */
  3171. GLTFLoader.prototype.startPerformanceCounter = function (counterName) {
  3172. this._parent._startPerformanceCounter(counterName);
  3173. };
  3174. /**
  3175. * Ends a performance counter.
  3176. * @param counterName The name of the performance counter
  3177. */
  3178. GLTFLoader.prototype.endPerformanceCounter = function (counterName) {
  3179. this._parent._endPerformanceCounter(counterName);
  3180. };
  3181. GLTFLoader._DefaultSampler = { index: -1 };
  3182. GLTFLoader._ExtensionNames = new Array();
  3183. GLTFLoader._ExtensionFactories = {};
  3184. return GLTFLoader;
  3185. }());
  3186. _glTFFileLoader__WEBPACK_IMPORTED_MODULE_1__["GLTFFileLoader"]._CreateGLTF2Loader = function (parent) { return new GLTFLoader(parent); };
  3187. /***/ }),
  3188. /***/ "./glTF/2.0/glTFLoaderInterfaces.ts":
  3189. /*!******************************************!*\
  3190. !*** ./glTF/2.0/glTFLoaderInterfaces.ts ***!
  3191. \******************************************/
  3192. /*! no static exports found */
  3193. /***/ (function(module, exports) {
  3194. /***/ }),
  3195. /***/ "./glTF/2.0/index.ts":
  3196. /*!***************************!*\
  3197. !*** ./glTF/2.0/index.ts ***!
  3198. \***************************/
  3199. /*! 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 */
  3200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3201. "use strict";
  3202. __webpack_require__.r(__webpack_exports__);
  3203. /* harmony import */ var _glTFLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFLoader */ "./glTF/2.0/glTFLoader.ts");
  3204. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ArrayItem", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["ArrayItem"]; });
  3205. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoader", function() { return _glTFLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoader"]; });
  3206. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  3207. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EXT_lights_image_based", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["EXT_lights_image_based"]; });
  3208. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_draco_mesh_compression", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_draco_mesh_compression"]; });
  3209. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_lights"]; });
  3210. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_pbrSpecularGlossiness", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_pbrSpecularGlossiness"]; });
  3211. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  3212. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  3213. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_audio_emitter", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_audio_emitter"]; });
  3214. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_lod", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_lod"]; });
  3215. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_minecraftMesh", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_minecraftMesh"]; });
  3216. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MSFT_sRGBFactors", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_1__["MSFT_sRGBFactors"]; });
  3217. /***/ }),
  3218. /***/ "./glTF/glTFFileLoader.ts":
  3219. /*!********************************!*\
  3220. !*** ./glTF/glTFFileLoader.ts ***!
  3221. \********************************/
  3222. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  3223. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3224. "use strict";
  3225. __webpack_require__.r(__webpack_exports__);
  3226. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return GLTFLoaderCoordinateSystemMode; });
  3227. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return GLTFLoaderAnimationStartMode; });
  3228. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return GLTFLoaderState; });
  3229. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return GLTFFileLoader; });
  3230. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/observable */ "babylonjs/Misc/observable");
  3231. /* harmony import */ var babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__);
  3232. /**
  3233. * Mode that determines the coordinate system to use.
  3234. */
  3235. var GLTFLoaderCoordinateSystemMode;
  3236. (function (GLTFLoaderCoordinateSystemMode) {
  3237. /**
  3238. * Automatically convert the glTF right-handed data to the appropriate system based on the current coordinate system mode of the scene.
  3239. */
  3240. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["AUTO"] = 0] = "AUTO";
  3241. /**
  3242. * Sets the useRightHandedSystem flag on the scene.
  3243. */
  3244. GLTFLoaderCoordinateSystemMode[GLTFLoaderCoordinateSystemMode["FORCE_RIGHT_HANDED"] = 1] = "FORCE_RIGHT_HANDED";
  3245. })(GLTFLoaderCoordinateSystemMode || (GLTFLoaderCoordinateSystemMode = {}));
  3246. /**
  3247. * Mode that determines what animations will start.
  3248. */
  3249. var GLTFLoaderAnimationStartMode;
  3250. (function (GLTFLoaderAnimationStartMode) {
  3251. /**
  3252. * No animation will start.
  3253. */
  3254. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["NONE"] = 0] = "NONE";
  3255. /**
  3256. * The first animation will start.
  3257. */
  3258. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["FIRST"] = 1] = "FIRST";
  3259. /**
  3260. * All animations will start.
  3261. */
  3262. GLTFLoaderAnimationStartMode[GLTFLoaderAnimationStartMode["ALL"] = 2] = "ALL";
  3263. })(GLTFLoaderAnimationStartMode || (GLTFLoaderAnimationStartMode = {}));
  3264. /**
  3265. * Loader state.
  3266. */
  3267. var GLTFLoaderState;
  3268. (function (GLTFLoaderState) {
  3269. /**
  3270. * The asset is loading.
  3271. */
  3272. GLTFLoaderState[GLTFLoaderState["LOADING"] = 0] = "LOADING";
  3273. /**
  3274. * The asset is ready for rendering.
  3275. */
  3276. GLTFLoaderState[GLTFLoaderState["READY"] = 1] = "READY";
  3277. /**
  3278. * The asset is completely loaded.
  3279. */
  3280. GLTFLoaderState[GLTFLoaderState["COMPLETE"] = 2] = "COMPLETE";
  3281. })(GLTFLoaderState || (GLTFLoaderState = {}));
  3282. /**
  3283. * File loader for loading glTF files into a scene.
  3284. */
  3285. var GLTFFileLoader = /** @class */ (function () {
  3286. function GLTFFileLoader() {
  3287. // --------------
  3288. // Common options
  3289. // --------------
  3290. /**
  3291. * Raised when the asset has been parsed
  3292. */
  3293. this.onParsedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3294. // ----------
  3295. // V2 options
  3296. // ----------
  3297. /**
  3298. * The coordinate system mode. Defaults to AUTO.
  3299. */
  3300. this.coordinateSystemMode = GLTFLoaderCoordinateSystemMode.AUTO;
  3301. /**
  3302. * The animation start mode. Defaults to FIRST.
  3303. */
  3304. this.animationStartMode = GLTFLoaderAnimationStartMode.FIRST;
  3305. /**
  3306. * Defines if the loader should compile materials before raising the success callback. Defaults to false.
  3307. */
  3308. this.compileMaterials = false;
  3309. /**
  3310. * Defines if the loader should also compile materials with clip planes. Defaults to false.
  3311. */
  3312. this.useClipPlane = false;
  3313. /**
  3314. * Defines if the loader should compile shadow generators before raising the success callback. Defaults to false.
  3315. */
  3316. this.compileShadowGenerators = false;
  3317. /**
  3318. * Defines if the Alpha blended materials are only applied as coverage.
  3319. * If false, (default) The luminance of each pixel will reduce its opacity to simulate the behaviour of most physical materials.
  3320. * If true, no extra effects are applied to transparent pixels.
  3321. */
  3322. this.transparencyAsCoverage = false;
  3323. /**
  3324. * Function called before loading a url referenced by the asset.
  3325. */
  3326. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  3327. /**
  3328. * Observable raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  3329. */
  3330. this.onMeshLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3331. /**
  3332. * Observable raised when the loader creates a texture after parsing the glTF properties of the texture.
  3333. */
  3334. this.onTextureLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3335. /**
  3336. * Observable raised when the loader creates a material after parsing the glTF properties of the material.
  3337. */
  3338. this.onMaterialLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3339. /**
  3340. * Observable raised when the loader creates a camera after parsing the glTF properties of the camera.
  3341. */
  3342. this.onCameraLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3343. /**
  3344. * Observable raised when the asset is completely loaded, immediately before the loader is disposed.
  3345. * For assets with LODs, raised when all of the LODs are complete.
  3346. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  3347. */
  3348. this.onCompleteObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3349. /**
  3350. * Observable raised when an error occurs.
  3351. */
  3352. this.onErrorObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3353. /**
  3354. * Observable raised after the loader is disposed.
  3355. */
  3356. this.onDisposeObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3357. /**
  3358. * Observable raised after a loader extension is created.
  3359. * Set additional options for a loader extension in this event.
  3360. */
  3361. this.onExtensionLoadedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3362. /**
  3363. * Defines if the loader should validate the asset.
  3364. */
  3365. this.validate = false;
  3366. /**
  3367. * Observable raised after validation when validate is set to true. The event data is the result of the validation.
  3368. */
  3369. this.onValidatedObservable = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
  3370. this._loader = null;
  3371. /**
  3372. * Name of the loader ("gltf")
  3373. */
  3374. this.name = "gltf";
  3375. /**
  3376. * Supported file extensions of the loader (.gltf, .glb)
  3377. */
  3378. this.extensions = {
  3379. ".gltf": { isBinary: false },
  3380. ".glb": { isBinary: true }
  3381. };
  3382. this._logIndentLevel = 0;
  3383. this._loggingEnabled = false;
  3384. /** @hidden */
  3385. this._log = this._logDisabled;
  3386. this._capturePerformanceCounters = false;
  3387. /** @hidden */
  3388. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  3389. /** @hidden */
  3390. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  3391. }
  3392. Object.defineProperty(GLTFFileLoader.prototype, "onParsed", {
  3393. /**
  3394. * Raised when the asset has been parsed
  3395. */
  3396. set: function (callback) {
  3397. if (this._onParsedObserver) {
  3398. this.onParsedObservable.remove(this._onParsedObserver);
  3399. }
  3400. this._onParsedObserver = this.onParsedObservable.add(callback);
  3401. },
  3402. enumerable: true,
  3403. configurable: true
  3404. });
  3405. Object.defineProperty(GLTFFileLoader.prototype, "onMeshLoaded", {
  3406. /**
  3407. * Callback raised when the loader creates a mesh after parsing the glTF properties of the mesh.
  3408. */
  3409. set: function (callback) {
  3410. if (this._onMeshLoadedObserver) {
  3411. this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver);
  3412. }
  3413. this._onMeshLoadedObserver = this.onMeshLoadedObservable.add(callback);
  3414. },
  3415. enumerable: true,
  3416. configurable: true
  3417. });
  3418. Object.defineProperty(GLTFFileLoader.prototype, "onTextureLoaded", {
  3419. /**
  3420. * Callback raised when the loader creates a texture after parsing the glTF properties of the texture.
  3421. */
  3422. set: function (callback) {
  3423. if (this._onTextureLoadedObserver) {
  3424. this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver);
  3425. }
  3426. this._onTextureLoadedObserver = this.onTextureLoadedObservable.add(callback);
  3427. },
  3428. enumerable: true,
  3429. configurable: true
  3430. });
  3431. Object.defineProperty(GLTFFileLoader.prototype, "onMaterialLoaded", {
  3432. /**
  3433. * Callback raised when the loader creates a material after parsing the glTF properties of the material.
  3434. */
  3435. set: function (callback) {
  3436. if (this._onMaterialLoadedObserver) {
  3437. this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver);
  3438. }
  3439. this._onMaterialLoadedObserver = this.onMaterialLoadedObservable.add(callback);
  3440. },
  3441. enumerable: true,
  3442. configurable: true
  3443. });
  3444. Object.defineProperty(GLTFFileLoader.prototype, "onCameraLoaded", {
  3445. /**
  3446. * Callback raised when the loader creates a camera after parsing the glTF properties of the camera.
  3447. */
  3448. set: function (callback) {
  3449. if (this._onCameraLoadedObserver) {
  3450. this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver);
  3451. }
  3452. this._onCameraLoadedObserver = this.onCameraLoadedObservable.add(callback);
  3453. },
  3454. enumerable: true,
  3455. configurable: true
  3456. });
  3457. Object.defineProperty(GLTFFileLoader.prototype, "onComplete", {
  3458. /**
  3459. * Callback raised when the asset is completely loaded, immediately before the loader is disposed.
  3460. * For assets with LODs, raised when all of the LODs are complete.
  3461. * For assets without LODs, raised when the model is complete, immediately after the loader resolves the returned promise.
  3462. */
  3463. set: function (callback) {
  3464. if (this._onCompleteObserver) {
  3465. this.onCompleteObservable.remove(this._onCompleteObserver);
  3466. }
  3467. this._onCompleteObserver = this.onCompleteObservable.add(callback);
  3468. },
  3469. enumerable: true,
  3470. configurable: true
  3471. });
  3472. Object.defineProperty(GLTFFileLoader.prototype, "onError", {
  3473. /**
  3474. * Callback raised when an error occurs.
  3475. */
  3476. set: function (callback) {
  3477. if (this._onErrorObserver) {
  3478. this.onErrorObservable.remove(this._onErrorObserver);
  3479. }
  3480. this._onErrorObserver = this.onErrorObservable.add(callback);
  3481. },
  3482. enumerable: true,
  3483. configurable: true
  3484. });
  3485. Object.defineProperty(GLTFFileLoader.prototype, "onDispose", {
  3486. /**
  3487. * Callback raised after the loader is disposed.
  3488. */
  3489. set: function (callback) {
  3490. if (this._onDisposeObserver) {
  3491. this.onDisposeObservable.remove(this._onDisposeObserver);
  3492. }
  3493. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  3494. },
  3495. enumerable: true,
  3496. configurable: true
  3497. });
  3498. Object.defineProperty(GLTFFileLoader.prototype, "onExtensionLoaded", {
  3499. /**
  3500. * Callback raised after a loader extension is created.
  3501. */
  3502. set: function (callback) {
  3503. if (this._onExtensionLoadedObserver) {
  3504. this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver);
  3505. }
  3506. this._onExtensionLoadedObserver = this.onExtensionLoadedObservable.add(callback);
  3507. },
  3508. enumerable: true,
  3509. configurable: true
  3510. });
  3511. Object.defineProperty(GLTFFileLoader.prototype, "loggingEnabled", {
  3512. /**
  3513. * Defines if the loader logging is enabled.
  3514. */
  3515. get: function () {
  3516. return this._loggingEnabled;
  3517. },
  3518. set: function (value) {
  3519. if (this._loggingEnabled === value) {
  3520. return;
  3521. }
  3522. this._loggingEnabled = value;
  3523. if (this._loggingEnabled) {
  3524. this._log = this._logEnabled;
  3525. }
  3526. else {
  3527. this._log = this._logDisabled;
  3528. }
  3529. },
  3530. enumerable: true,
  3531. configurable: true
  3532. });
  3533. Object.defineProperty(GLTFFileLoader.prototype, "capturePerformanceCounters", {
  3534. /**
  3535. * Defines if the loader should capture performance counters.
  3536. */
  3537. get: function () {
  3538. return this._capturePerformanceCounters;
  3539. },
  3540. set: function (value) {
  3541. if (this._capturePerformanceCounters === value) {
  3542. return;
  3543. }
  3544. this._capturePerformanceCounters = value;
  3545. if (this._capturePerformanceCounters) {
  3546. this._startPerformanceCounter = this._startPerformanceCounterEnabled;
  3547. this._endPerformanceCounter = this._endPerformanceCounterEnabled;
  3548. }
  3549. else {
  3550. this._startPerformanceCounter = this._startPerformanceCounterDisabled;
  3551. this._endPerformanceCounter = this._endPerformanceCounterDisabled;
  3552. }
  3553. },
  3554. enumerable: true,
  3555. configurable: true
  3556. });
  3557. Object.defineProperty(GLTFFileLoader.prototype, "onValidated", {
  3558. /**
  3559. * Callback raised after a loader extension is created.
  3560. */
  3561. set: function (callback) {
  3562. if (this._onValidatedObserver) {
  3563. this.onValidatedObservable.remove(this._onValidatedObserver);
  3564. }
  3565. this._onValidatedObserver = this.onValidatedObservable.add(callback);
  3566. },
  3567. enumerable: true,
  3568. configurable: true
  3569. });
  3570. /**
  3571. * Disposes the loader, releases resources during load, and cancels any outstanding requests.
  3572. */
  3573. GLTFFileLoader.prototype.dispose = function () {
  3574. if (this._loader) {
  3575. this._loader.dispose();
  3576. this._loader = null;
  3577. }
  3578. this._clear();
  3579. this.onDisposeObservable.notifyObservers(undefined);
  3580. this.onDisposeObservable.clear();
  3581. };
  3582. /** @hidden */
  3583. GLTFFileLoader.prototype._clear = function () {
  3584. this.preprocessUrlAsync = function (url) { return Promise.resolve(url); };
  3585. this.onMeshLoadedObservable.clear();
  3586. this.onTextureLoadedObservable.clear();
  3587. this.onMaterialLoadedObservable.clear();
  3588. this.onCameraLoadedObservable.clear();
  3589. this.onCompleteObservable.clear();
  3590. this.onExtensionLoadedObservable.clear();
  3591. };
  3592. /**
  3593. * Imports one or more meshes from the loaded glTF data and adds them to the scene
  3594. * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
  3595. * @param scene the scene the meshes should be added to
  3596. * @param data the glTF data to load
  3597. * @param rootUrl root url to load from
  3598. * @param onProgress event that fires when loading progress has occured
  3599. * @param fileName Defines the name of the file to load
  3600. * @returns a promise containg the loaded meshes, particles, skeletons and animations
  3601. */
  3602. GLTFFileLoader.prototype.importMeshAsync = function (meshesNames, scene, data, rootUrl, onProgress, fileName) {
  3603. var _this = this;
  3604. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3605. _this._log("Loading " + (fileName || ""));
  3606. _this._loader = _this._getLoader(loaderData);
  3607. return _this._loader.importMeshAsync(meshesNames, scene, loaderData, rootUrl, onProgress, fileName);
  3608. });
  3609. };
  3610. /**
  3611. * Imports all objects from the loaded glTF data and adds them to the scene
  3612. * @param scene the scene the objects should be added to
  3613. * @param data the glTF data to load
  3614. * @param rootUrl root url to load from
  3615. * @param onProgress event that fires when loading progress has occured
  3616. * @param fileName Defines the name of the file to load
  3617. * @returns a promise which completes when objects have been loaded to the scene
  3618. */
  3619. GLTFFileLoader.prototype.loadAsync = function (scene, data, rootUrl, onProgress, fileName) {
  3620. var _this = this;
  3621. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3622. _this._log("Loading " + (fileName || ""));
  3623. _this._loader = _this._getLoader(loaderData);
  3624. return _this._loader.loadAsync(scene, loaderData, rootUrl, onProgress, fileName);
  3625. });
  3626. };
  3627. /**
  3628. * Load into an asset container.
  3629. * @param scene The scene to load into
  3630. * @param data The data to import
  3631. * @param rootUrl The root url for scene and resources
  3632. * @param onProgress The callback when the load progresses
  3633. * @param fileName Defines the name of the file to load
  3634. * @returns The loaded asset container
  3635. */
  3636. GLTFFileLoader.prototype.loadAssetContainerAsync = function (scene, data, rootUrl, onProgress, fileName) {
  3637. var _this = this;
  3638. return this._parseAsync(scene, data, rootUrl, fileName).then(function (loaderData) {
  3639. _this._log("Loading " + (fileName || ""));
  3640. _this._loader = _this._getLoader(loaderData);
  3641. // Get materials/textures when loading to add to container
  3642. var materials = [];
  3643. _this.onMaterialLoadedObservable.add(function (material) {
  3644. materials.push(material);
  3645. });
  3646. var textures = [];
  3647. _this.onTextureLoadedObservable.add(function (texture) {
  3648. textures.push(texture);
  3649. });
  3650. return _this._loader.importMeshAsync(null, scene, loaderData, rootUrl, onProgress, fileName).then(function (result) {
  3651. var container = new babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["AssetContainer"](scene);
  3652. Array.prototype.push.apply(container.meshes, result.meshes);
  3653. Array.prototype.push.apply(container.particleSystems, result.particleSystems);
  3654. Array.prototype.push.apply(container.skeletons, result.skeletons);
  3655. Array.prototype.push.apply(container.animationGroups, result.animationGroups);
  3656. Array.prototype.push.apply(container.materials, materials);
  3657. Array.prototype.push.apply(container.textures, textures);
  3658. container.removeAllFromScene();
  3659. return container;
  3660. });
  3661. });
  3662. };
  3663. /**
  3664. * If the data string can be loaded directly.
  3665. * @param data string contianing the file data
  3666. * @returns if the data can be loaded directly
  3667. */
  3668. GLTFFileLoader.prototype.canDirectLoad = function (data) {
  3669. return ((data.indexOf("scene") !== -1) && (data.indexOf("node") !== -1));
  3670. };
  3671. /**
  3672. * Instantiates a glTF file loader plugin.
  3673. * @returns the created plugin
  3674. */
  3675. GLTFFileLoader.prototype.createPlugin = function () {
  3676. return new GLTFFileLoader();
  3677. };
  3678. Object.defineProperty(GLTFFileLoader.prototype, "loaderState", {
  3679. /**
  3680. * The loader state or null if the loader is not active.
  3681. */
  3682. get: function () {
  3683. return this._loader ? this._loader.state : null;
  3684. },
  3685. enumerable: true,
  3686. configurable: true
  3687. });
  3688. /**
  3689. * Returns a promise that resolves when the asset is completely loaded.
  3690. * @returns a promise that resolves when the asset is completely loaded.
  3691. */
  3692. GLTFFileLoader.prototype.whenCompleteAsync = function () {
  3693. var _this = this;
  3694. return new Promise(function (resolve, reject) {
  3695. _this.onCompleteObservable.addOnce(function () {
  3696. resolve();
  3697. });
  3698. _this.onErrorObservable.addOnce(function (reason) {
  3699. reject(reason);
  3700. });
  3701. });
  3702. };
  3703. GLTFFileLoader.prototype._parseAsync = function (scene, data, rootUrl, fileName) {
  3704. var _this = this;
  3705. return Promise.resolve().then(function () {
  3706. var unpacked = (data instanceof ArrayBuffer) ? _this._unpackBinary(data) : { json: data, bin: null };
  3707. return _this._validateAsync(scene, unpacked.json, rootUrl, fileName).then(function () {
  3708. _this._startPerformanceCounter("Parse JSON");
  3709. _this._log("JSON length: " + unpacked.json.length);
  3710. var loaderData = {
  3711. json: JSON.parse(unpacked.json),
  3712. bin: unpacked.bin
  3713. };
  3714. _this._endPerformanceCounter("Parse JSON");
  3715. _this.onParsedObservable.notifyObservers(loaderData);
  3716. _this.onParsedObservable.clear();
  3717. return loaderData;
  3718. });
  3719. });
  3720. };
  3721. GLTFFileLoader.prototype._validateAsync = function (scene, json, rootUrl, fileName) {
  3722. var _this = this;
  3723. if (!this.validate || typeof GLTFValidator === "undefined") {
  3724. return Promise.resolve();
  3725. }
  3726. this._startPerformanceCounter("Validate JSON");
  3727. var options = {
  3728. externalResourceFunction: function (uri) {
  3729. return _this.preprocessUrlAsync(rootUrl + uri)
  3730. .then(function (url) { return scene._loadFileAsync(url, true, true); })
  3731. .then(function (data) { return new Uint8Array(data); });
  3732. }
  3733. };
  3734. if (fileName && fileName.substr(0, 5) !== "data:") {
  3735. options.uri = (rootUrl === "file:" ? fileName : "" + rootUrl + fileName);
  3736. }
  3737. return GLTFValidator.validateString(json, options).then(function (result) {
  3738. _this._endPerformanceCounter("Validate JSON");
  3739. _this.onValidatedObservable.notifyObservers(result);
  3740. _this.onValidatedObservable.clear();
  3741. }, function (reason) {
  3742. _this._endPerformanceCounter("Validate JSON");
  3743. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Failed to validate: " + reason);
  3744. _this.onValidatedObservable.clear();
  3745. });
  3746. };
  3747. GLTFFileLoader.prototype._getLoader = function (loaderData) {
  3748. var asset = loaderData.json.asset || {};
  3749. this._log("Asset version: " + asset.version);
  3750. asset.minVersion && this._log("Asset minimum version: " + asset.minVersion);
  3751. asset.generator && this._log("Asset generator: " + asset.generator);
  3752. var version = GLTFFileLoader._parseVersion(asset.version);
  3753. if (!version) {
  3754. throw new Error("Invalid version: " + asset.version);
  3755. }
  3756. if (asset.minVersion !== undefined) {
  3757. var minVersion = GLTFFileLoader._parseVersion(asset.minVersion);
  3758. if (!minVersion) {
  3759. throw new Error("Invalid minimum version: " + asset.minVersion);
  3760. }
  3761. if (GLTFFileLoader._compareVersion(minVersion, { major: 2, minor: 0 }) > 0) {
  3762. throw new Error("Incompatible minimum version: " + asset.minVersion);
  3763. }
  3764. }
  3765. var createLoaders = {
  3766. 1: GLTFFileLoader._CreateGLTF1Loader,
  3767. 2: GLTFFileLoader._CreateGLTF2Loader
  3768. };
  3769. var createLoader = createLoaders[version.major];
  3770. if (!createLoader) {
  3771. throw new Error("Unsupported version: " + asset.version);
  3772. }
  3773. return createLoader(this);
  3774. };
  3775. GLTFFileLoader.prototype._unpackBinary = function (data) {
  3776. this._startPerformanceCounter("Unpack binary");
  3777. this._log("Binary length: " + data.byteLength);
  3778. var Binary = {
  3779. Magic: 0x46546C67
  3780. };
  3781. var binaryReader = new BinaryReader(data);
  3782. var magic = binaryReader.readUint32();
  3783. if (magic !== Binary.Magic) {
  3784. throw new Error("Unexpected magic: " + magic);
  3785. }
  3786. var version = binaryReader.readUint32();
  3787. if (this.loggingEnabled) {
  3788. this._log("Binary version: " + version);
  3789. }
  3790. var unpacked;
  3791. switch (version) {
  3792. case 1: {
  3793. unpacked = this._unpackBinaryV1(binaryReader);
  3794. break;
  3795. }
  3796. case 2: {
  3797. unpacked = this._unpackBinaryV2(binaryReader);
  3798. break;
  3799. }
  3800. default: {
  3801. throw new Error("Unsupported version: " + version);
  3802. }
  3803. }
  3804. this._endPerformanceCounter("Unpack binary");
  3805. return unpacked;
  3806. };
  3807. GLTFFileLoader.prototype._unpackBinaryV1 = function (binaryReader) {
  3808. var ContentFormat = {
  3809. JSON: 0
  3810. };
  3811. var length = binaryReader.readUint32();
  3812. if (length != binaryReader.getLength()) {
  3813. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  3814. }
  3815. var contentLength = binaryReader.readUint32();
  3816. var contentFormat = binaryReader.readUint32();
  3817. var content;
  3818. switch (contentFormat) {
  3819. case ContentFormat.JSON: {
  3820. content = GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(contentLength));
  3821. break;
  3822. }
  3823. default: {
  3824. throw new Error("Unexpected content format: " + contentFormat);
  3825. }
  3826. }
  3827. var bytesRemaining = binaryReader.getLength() - binaryReader.getPosition();
  3828. var body = binaryReader.readUint8Array(bytesRemaining);
  3829. return {
  3830. json: content,
  3831. bin: body
  3832. };
  3833. };
  3834. GLTFFileLoader.prototype._unpackBinaryV2 = function (binaryReader) {
  3835. var ChunkFormat = {
  3836. JSON: 0x4E4F534A,
  3837. BIN: 0x004E4942
  3838. };
  3839. var length = binaryReader.readUint32();
  3840. if (length !== binaryReader.getLength()) {
  3841. throw new Error("Length in header does not match actual data length: " + length + " != " + binaryReader.getLength());
  3842. }
  3843. // JSON chunk
  3844. var chunkLength = binaryReader.readUint32();
  3845. var chunkFormat = binaryReader.readUint32();
  3846. if (chunkFormat !== ChunkFormat.JSON) {
  3847. throw new Error("First chunk format is not JSON");
  3848. }
  3849. var json = GLTFFileLoader._decodeBufferToText(binaryReader.readUint8Array(chunkLength));
  3850. // Look for BIN chunk
  3851. var bin = null;
  3852. while (binaryReader.getPosition() < binaryReader.getLength()) {
  3853. var chunkLength_1 = binaryReader.readUint32();
  3854. var chunkFormat_1 = binaryReader.readUint32();
  3855. switch (chunkFormat_1) {
  3856. case ChunkFormat.JSON: {
  3857. throw new Error("Unexpected JSON chunk");
  3858. }
  3859. case ChunkFormat.BIN: {
  3860. bin = binaryReader.readUint8Array(chunkLength_1);
  3861. break;
  3862. }
  3863. default: {
  3864. // ignore unrecognized chunkFormat
  3865. binaryReader.skipBytes(chunkLength_1);
  3866. break;
  3867. }
  3868. }
  3869. }
  3870. return {
  3871. json: json,
  3872. bin: bin
  3873. };
  3874. };
  3875. GLTFFileLoader._parseVersion = function (version) {
  3876. if (version === "1.0" || version === "1.0.1") {
  3877. return {
  3878. major: 1,
  3879. minor: 0
  3880. };
  3881. }
  3882. var match = (version + "").match(/^(\d+)\.(\d+)/);
  3883. if (!match) {
  3884. return null;
  3885. }
  3886. return {
  3887. major: parseInt(match[1]),
  3888. minor: parseInt(match[2])
  3889. };
  3890. };
  3891. GLTFFileLoader._compareVersion = function (a, b) {
  3892. if (a.major > b.major) {
  3893. return 1;
  3894. }
  3895. if (a.major < b.major) {
  3896. return -1;
  3897. }
  3898. if (a.minor > b.minor) {
  3899. return 1;
  3900. }
  3901. if (a.minor < b.minor) {
  3902. return -1;
  3903. }
  3904. return 0;
  3905. };
  3906. GLTFFileLoader._decodeBufferToText = function (buffer) {
  3907. if (typeof TextDecoder !== "undefined") {
  3908. return new TextDecoder().decode(buffer);
  3909. }
  3910. var result = "";
  3911. var length = buffer.byteLength;
  3912. for (var i = 0; i < length; i++) {
  3913. result += String.fromCharCode(buffer[i]);
  3914. }
  3915. return result;
  3916. };
  3917. /** @hidden */
  3918. GLTFFileLoader.prototype._logOpen = function (message) {
  3919. this._log(message);
  3920. this._logIndentLevel++;
  3921. };
  3922. /** @hidden */
  3923. GLTFFileLoader.prototype._logClose = function () {
  3924. --this._logIndentLevel;
  3925. };
  3926. GLTFFileLoader.prototype._logEnabled = function (message) {
  3927. var spaces = GLTFFileLoader._logSpaces.substr(0, this._logIndentLevel * 2);
  3928. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("" + spaces + message);
  3929. };
  3930. GLTFFileLoader.prototype._logDisabled = function (message) {
  3931. };
  3932. GLTFFileLoader.prototype._startPerformanceCounterEnabled = function (counterName) {
  3933. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].StartPerformanceCounter(counterName);
  3934. };
  3935. GLTFFileLoader.prototype._startPerformanceCounterDisabled = function (counterName) {
  3936. };
  3937. GLTFFileLoader.prototype._endPerformanceCounterEnabled = function (counterName) {
  3938. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Tools"].EndPerformanceCounter(counterName);
  3939. };
  3940. GLTFFileLoader.prototype._endPerformanceCounterDisabled = function (counterName) {
  3941. };
  3942. // ----------
  3943. // V1 options
  3944. // ----------
  3945. /**
  3946. * 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.
  3947. * Textures always loads asynchronously. For example, the success callback can compute the bounding information of the loaded meshes when incremental loading is disabled.
  3948. * Defaults to true.
  3949. * @hidden
  3950. */
  3951. GLTFFileLoader.IncrementalLoading = true;
  3952. /**
  3953. * Set this property to true in order to work with homogeneous coordinates, available with some converters and exporters.
  3954. * Defaults to false. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.
  3955. * @hidden
  3956. */
  3957. GLTFFileLoader.HomogeneousCoordinates = false;
  3958. GLTFFileLoader._logSpaces = " ";
  3959. return GLTFFileLoader;
  3960. }());
  3961. var BinaryReader = /** @class */ (function () {
  3962. function BinaryReader(arrayBuffer) {
  3963. this._arrayBuffer = arrayBuffer;
  3964. this._dataView = new DataView(arrayBuffer);
  3965. this._byteOffset = 0;
  3966. }
  3967. BinaryReader.prototype.getPosition = function () {
  3968. return this._byteOffset;
  3969. };
  3970. BinaryReader.prototype.getLength = function () {
  3971. return this._arrayBuffer.byteLength;
  3972. };
  3973. BinaryReader.prototype.readUint32 = function () {
  3974. var value = this._dataView.getUint32(this._byteOffset, true);
  3975. this._byteOffset += 4;
  3976. return value;
  3977. };
  3978. BinaryReader.prototype.readUint8Array = function (length) {
  3979. var value = new Uint8Array(this._arrayBuffer, this._byteOffset, length);
  3980. this._byteOffset += length;
  3981. return value;
  3982. };
  3983. BinaryReader.prototype.skipBytes = function (length) {
  3984. this._byteOffset += length;
  3985. };
  3986. return BinaryReader;
  3987. }());
  3988. if (babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"]) {
  3989. babylonjs_Misc_observable__WEBPACK_IMPORTED_MODULE_0__["SceneLoader"].RegisterPlugin(new GLTFFileLoader());
  3990. }
  3991. /***/ }),
  3992. /***/ "./legacy/legacy-glTF.ts":
  3993. /*!*******************************!*\
  3994. !*** ./legacy/legacy-glTF.ts ***!
  3995. \*******************************/
  3996. /*! exports provided: GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  3997. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3998. "use strict";
  3999. __webpack_require__.r(__webpack_exports__);
  4000. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileLoader */ "./glTF/glTFFileLoader.ts");
  4001. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  4002. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  4003. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  4004. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  4005. /**
  4006. * This is the entry point for the UMD module.
  4007. * The entry point for a future ESM package should be index.ts
  4008. */
  4009. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4010. if (typeof globalObject !== "undefined") {
  4011. globalObject.BABYLON = globalObject.BABYLON || {};
  4012. for (var key in _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__) {
  4013. globalObject.BABYLON[key] = _glTF_glTFFileLoader__WEBPACK_IMPORTED_MODULE_0__[key];
  4014. }
  4015. }
  4016. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4017. /***/ }),
  4018. /***/ "./legacy/legacy-glTF2.ts":
  4019. /*!********************************!*\
  4020. !*** ./legacy/legacy-glTF2.ts ***!
  4021. \********************************/
  4022. /*! exports provided: GLTF2 */
  4023. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4024. "use strict";
  4025. __webpack_require__.r(__webpack_exports__);
  4026. /* 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");
  4027. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFLoaderInterfaces */ "./glTF/2.0/glTFLoaderInterfaces.ts");
  4028. /* harmony import */ var _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__);
  4029. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  4030. /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__; });
  4031. /**
  4032. * This is the entry point for the UMD module.
  4033. * The entry point for a future ESM package should be index.ts
  4034. */
  4035. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4036. if (typeof globalObject !== "undefined") {
  4037. globalObject.BABYLON = globalObject.BABYLON || {};
  4038. var BABYLON = globalObject.BABYLON;
  4039. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  4040. BABYLON.GLTF2.Loader = BABYLON.GLTF2.Loader || {};
  4041. BABYLON.GLTF2.Loader.Extensions = BABYLON.GLTF2.Loader.Extensions || {};
  4042. var keys = [];
  4043. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__) {
  4044. BABYLON.GLTF2.Loader.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_0__[key];
  4045. keys.push(key);
  4046. }
  4047. for (var key in _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__) {
  4048. BABYLON.GLTF2.Loader[key] = _glTF_2_0_glTFLoaderInterfaces__WEBPACK_IMPORTED_MODULE_1__[key];
  4049. keys.push(key);
  4050. }
  4051. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__) {
  4052. // Prevent Reassignment.
  4053. if (keys.indexOf(key) > -1) {
  4054. continue;
  4055. }
  4056. BABYLON.GLTF2[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_2__[key];
  4057. }
  4058. }
  4059. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4060. /***/ }),
  4061. /***/ "./legacy/legacy-glTF2FileLoader.ts":
  4062. /*!******************************************!*\
  4063. !*** ./legacy/legacy-glTF2FileLoader.ts ***!
  4064. \******************************************/
  4065. /*! exports provided: GLTF2, GLTFLoaderCoordinateSystemMode, GLTFLoaderAnimationStartMode, GLTFLoaderState, GLTFFileLoader */
  4066. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4067. "use strict";
  4068. __webpack_require__.r(__webpack_exports__);
  4069. /* harmony import */ var _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./legacy-glTF */ "./legacy/legacy-glTF.ts");
  4070. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderCoordinateSystemMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderCoordinateSystemMode"]; });
  4071. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderAnimationStartMode", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderAnimationStartMode"]; });
  4072. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFLoaderState", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFLoaderState"]; });
  4073. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFFileLoader", function() { return _legacy_glTF__WEBPACK_IMPORTED_MODULE_0__["GLTFFileLoader"]; });
  4074. /* harmony import */ var _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2 */ "./legacy/legacy-glTF2.ts");
  4075. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2", function() { return _legacy_glTF2__WEBPACK_IMPORTED_MODULE_1__["GLTF2"]; });
  4076. /***/ }),
  4077. /***/ "babylonjs/Misc/observable":
  4078. /*!****************************************************************************************************!*\
  4079. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  4080. \****************************************************************************************************/
  4081. /*! no static exports found */
  4082. /***/ (function(module, exports) {
  4083. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_observable__;
  4084. /***/ })
  4085. /******/ });
  4086. });
  4087. //# sourceMappingURL=babylon.glTF2FileLoader.js.map