babylon.glTF2FileLoader.js 212 KB

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