babylon.glTF2FileLoader.js 243 KB

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