babylon.glTF2FileLoader.js 219 KB

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