babylon.glTF2FileLoader.js 253 KB

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