babylon.glTF2FileLoader.js 239 KB

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