babylon.glTF2FileLoader.js 246 KB

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