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