babylon.glTF2Serializer.js 242 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578
  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-serializers", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-serializers"] = factory(require("babylonjs"));
  8. else
  9. root["SERIALIZERS"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__) {
  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-glTF2Serializer.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!*****************************************************************!*\
  100. !*** C:/Dev/Babylon/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \*****************************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
  324. /*!****************************************************!*\
  325. !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
  326. \****************************************************/
  327. /*! exports provided: KHR_lights_punctual */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return KHR_lights_punctual; });
  332. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  333. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  334. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  335. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  336. var NAME = "KHR_lights_punctual";
  337. var LightType;
  338. (function (LightType) {
  339. LightType["DIRECTIONAL"] = "directional";
  340. LightType["POINT"] = "point";
  341. LightType["SPOT"] = "spot";
  342. })(LightType || (LightType = {}));
  343. /**
  344. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  345. */
  346. var KHR_lights_punctual = /** @class */ (function () {
  347. /** @hidden */
  348. function KHR_lights_punctual(exporter) {
  349. /** The name of this extension. */
  350. this.name = NAME;
  351. /** Defines whether this extension is enabled. */
  352. this.enabled = true;
  353. /** Defines whether this extension is required */
  354. this.required = false;
  355. this._exporter = exporter;
  356. }
  357. /** @hidden */
  358. KHR_lights_punctual.prototype.dispose = function () {
  359. delete this._lights;
  360. };
  361. Object.defineProperty(KHR_lights_punctual.prototype, "wasUsed", {
  362. /** @hidden */
  363. get: function () {
  364. return !!this._lights;
  365. },
  366. enumerable: true,
  367. configurable: true
  368. });
  369. /** @hidden */
  370. KHR_lights_punctual.prototype.onExporting = function () {
  371. this._exporter._glTF.extensions[NAME] = this._lights;
  372. };
  373. /**
  374. * Define this method to modify the default behavior when exporting a node
  375. * @param context The context when exporting the node
  376. * @param node glTF node
  377. * @param babylonNode BabylonJS node
  378. * @returns nullable INode promise
  379. */
  380. KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode) {
  381. var _this = this;
  382. return new Promise(function (resolve, reject) {
  383. if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["ShadowLight"]) {
  384. var babylonLight = babylonNode;
  385. var light = void 0;
  386. var lightType = (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_POINTLIGHT ? LightType.POINT : (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_DIRECTIONALLIGHT ? LightType.DIRECTIONAL : (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_SPOTLIGHT ? LightType.SPOT : null)));
  387. if (lightType == null) {
  388. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Light " + babylonLight.name + " is not supported in " + NAME);
  389. }
  390. else {
  391. var lightPosition = babylonLight.position.clone();
  392. if (!lightPosition.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero())) {
  393. if (_this._exporter._convertToRightHandedSystem) {
  394. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(lightPosition);
  395. }
  396. node.translation = lightPosition.asArray();
  397. }
  398. if (lightType !== LightType.POINT) {
  399. var localAxis = babylonLight.direction;
  400. var yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;
  401. var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
  402. var pitch = -Math.atan2(localAxis.y, len);
  403. var lightRotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(yaw, pitch, 0);
  404. if (_this._exporter._convertToRightHandedSystem) {
  405. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
  406. }
  407. if (!lightRotationQuaternion.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity())) {
  408. node.rotation = lightRotationQuaternion.asArray();
  409. }
  410. }
  411. if (babylonLight.falloffType !== babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF) {
  412. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Light falloff for " + babylonLight.name + " does not match the " + NAME + " specification!");
  413. }
  414. light = {
  415. type: lightType
  416. };
  417. if (!babylonLight.diffuse.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White())) {
  418. light.color = babylonLight.diffuse.asArray();
  419. }
  420. if (babylonLight.intensity !== 1.0) {
  421. light.intensity = babylonLight.intensity;
  422. }
  423. if (babylonLight.range !== Number.MAX_VALUE) {
  424. light.range = babylonLight.range;
  425. }
  426. if (lightType === LightType.SPOT) {
  427. var babylonSpotLight = babylonLight;
  428. if (babylonSpotLight.angle !== Math.PI / 2.0) {
  429. if (light.spot == null) {
  430. light.spot = {};
  431. }
  432. light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
  433. }
  434. if (babylonSpotLight.innerAngle !== 0) {
  435. if (light.spot == null) {
  436. light.spot = {};
  437. }
  438. light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
  439. }
  440. }
  441. if (_this._lights == null) {
  442. _this._lights = {
  443. lights: []
  444. };
  445. }
  446. _this._lights.lights.push(light);
  447. if (node.extensions == null) {
  448. node.extensions = {};
  449. }
  450. var lightReference = {
  451. light: _this._lights.lights.length - 1
  452. };
  453. node.extensions[NAME] = lightReference;
  454. }
  455. }
  456. resolve(node);
  457. });
  458. };
  459. return KHR_lights_punctual;
  460. }());
  461. _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
  462. /***/ }),
  463. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  464. /*!****************************************************!*\
  465. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  466. \****************************************************/
  467. /*! exports provided: KHR_materials_sheen */
  468. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  469. "use strict";
  470. __webpack_require__.r(__webpack_exports__);
  471. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  472. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  473. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Maths/math");
  474. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__);
  475. var NAME = "KHR_materials_sheen";
  476. /**
  477. * @hidden
  478. */
  479. var KHR_materials_sheen = /** @class */ (function () {
  480. function KHR_materials_sheen(exporter) {
  481. /** Name of this extension */
  482. this.name = NAME;
  483. /** Defines whether this extension is enabled */
  484. this.enabled = true;
  485. /** Defines whether this extension is required */
  486. this.required = false;
  487. /** Reference to the glTF exporter */
  488. this._textureInfos = [];
  489. this._exportedTextures = [];
  490. this._wasUsed = false;
  491. }
  492. KHR_materials_sheen.prototype.dispose = function () {
  493. this._textureInfos = [];
  494. this._exportedTextures = [];
  495. };
  496. Object.defineProperty(KHR_materials_sheen.prototype, "wasUsed", {
  497. /** @hidden */
  498. get: function () {
  499. return this._wasUsed;
  500. },
  501. enumerable: true,
  502. configurable: true
  503. });
  504. KHR_materials_sheen.prototype._getTextureIndex = function (babylonTexture) {
  505. var textureIndex = this._exportedTextures.indexOf(babylonTexture);
  506. if (textureIndex === -1 && babylonTexture.reservedDataStore) {
  507. textureIndex = this._exportedTextures.indexOf(babylonTexture.reservedDataStore.source);
  508. }
  509. return textureIndex;
  510. };
  511. KHR_materials_sheen.prototype.postExportTexture = function (context, textureInfo, babylonTexture) {
  512. var textureIndex = this._getTextureIndex(babylonTexture);
  513. if (textureIndex > -1) {
  514. this._textureInfos[textureIndex] = textureInfo;
  515. }
  516. };
  517. KHR_materials_sheen.prototype.postExportMaterialAdditionalTextures = function (context, node, babylonMaterial) {
  518. if (babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  519. if (babylonMaterial.sheen.isEnabled && babylonMaterial.sheen.texture) {
  520. this._exportedTextures.push(babylonMaterial.sheen.texture);
  521. return [babylonMaterial.sheen.texture];
  522. }
  523. }
  524. return [];
  525. };
  526. KHR_materials_sheen.prototype.postExportMaterialAsync = function (context, node, babylonMaterial) {
  527. var _this = this;
  528. return new Promise(function (resolve, reject) {
  529. if (babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  530. if (!babylonMaterial.sheen.isEnabled) {
  531. resolve(node);
  532. return;
  533. }
  534. _this._wasUsed = true;
  535. if (node.extensions == null) {
  536. node.extensions = {};
  537. }
  538. var sheenInfo = {
  539. colorFactor: babylonMaterial.sheen.color.asArray(),
  540. intensityFactor: babylonMaterial.sheen.intensity
  541. };
  542. if (babylonMaterial.sheen.texture) {
  543. var textureIndex = _this._getTextureIndex(babylonMaterial.sheen.texture);
  544. if (textureIndex > -1) {
  545. sheenInfo.colorIntensityTexture = _this._textureInfos[textureIndex];
  546. }
  547. }
  548. node.extensions[NAME] = sheenInfo;
  549. }
  550. resolve(node);
  551. });
  552. };
  553. return KHR_materials_sheen;
  554. }());
  555. _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_materials_sheen(exporter); });
  556. /***/ }),
  557. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  558. /*!******************************************************!*\
  559. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  560. \******************************************************/
  561. /*! exports provided: KHR_texture_transform */
  562. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  563. "use strict";
  564. __webpack_require__.r(__webpack_exports__);
  565. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  566. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Maths/math");
  567. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  568. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  569. /* harmony import */ var _shaders_textureTransform_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../shaders/textureTransform.fragment */ "./glTF/2.0/shaders/textureTransform.fragment.ts");
  570. var NAME = "KHR_texture_transform";
  571. /**
  572. * @hidden
  573. */
  574. var KHR_texture_transform = /** @class */ (function () {
  575. function KHR_texture_transform(exporter) {
  576. this._recordedTextures = [];
  577. /** Name of this extension */
  578. this.name = NAME;
  579. /** Defines whether this extension is enabled */
  580. this.enabled = true;
  581. /** Defines whether this extension is required */
  582. this.required = false;
  583. /** Reference to the glTF exporter */
  584. this._wasUsed = false;
  585. }
  586. KHR_texture_transform.prototype.dispose = function () {
  587. for (var _i = 0, _a = this._recordedTextures; _i < _a.length; _i++) {
  588. var texture = _a[_i];
  589. texture.dispose();
  590. }
  591. };
  592. Object.defineProperty(KHR_texture_transform.prototype, "wasUsed", {
  593. /** @hidden */
  594. get: function () {
  595. return this._wasUsed;
  596. },
  597. enumerable: true,
  598. configurable: true
  599. });
  600. KHR_texture_transform.prototype.postExportTexture = function (context, textureInfo, babylonTexture) {
  601. if (babylonTexture && babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0) {
  602. var textureTransform = {};
  603. var transformIsRequired = false;
  604. if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {
  605. textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];
  606. transformIsRequired = true;
  607. }
  608. if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
  609. textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];
  610. transformIsRequired = true;
  611. }
  612. if (babylonTexture.wAng !== 0) {
  613. textureTransform.rotation = babylonTexture.wAng;
  614. transformIsRequired = true;
  615. }
  616. if (babylonTexture.coordinatesIndex !== 0) {
  617. textureTransform.texCoord = babylonTexture.coordinatesIndex;
  618. transformIsRequired = true;
  619. }
  620. if (!transformIsRequired) {
  621. return;
  622. }
  623. this._wasUsed = true;
  624. if (!textureInfo.extensions) {
  625. textureInfo.extensions = {};
  626. }
  627. textureInfo.extensions[NAME] = textureTransform;
  628. }
  629. };
  630. KHR_texture_transform.prototype.preExportTextureAsync = function (context, babylonTexture, mimeType) {
  631. var _this = this;
  632. return new Promise(function (resolve, reject) {
  633. var scene = babylonTexture.getScene();
  634. if (!scene) {
  635. reject(context + ": \"scene\" is not defined for Babylon texture " + babylonTexture.name + "!");
  636. return;
  637. }
  638. var transformIsRequired = false;
  639. if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {
  640. transformIsRequired = true;
  641. }
  642. if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
  643. transformIsRequired = true;
  644. }
  645. if (babylonTexture.wAng !== 0) {
  646. transformIsRequired = true;
  647. }
  648. if (!transformIsRequired) {
  649. resolve(babylonTexture);
  650. return;
  651. }
  652. // Do we need to flatten the transform?
  653. if (babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0) {
  654. resolve(babylonTexture);
  655. return;
  656. }
  657. return _this._textureTransformTextureAsync(babylonTexture, scene)
  658. .then(function (proceduralTexture) {
  659. resolve(proceduralTexture);
  660. })
  661. .catch(function (e) {
  662. reject(e);
  663. });
  664. });
  665. };
  666. /**
  667. * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
  668. * @param babylonTexture
  669. * @param offset
  670. * @param rotation
  671. * @param scale
  672. * @param scene
  673. */
  674. KHR_texture_transform.prototype._textureTransformTextureAsync = function (babylonTexture, scene) {
  675. var _this = this;
  676. return new Promise(function (resolve) {
  677. var proceduralTexture = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["ProceduralTexture"]("" + babylonTexture.name, babylonTexture.getSize(), "textureTransform", scene);
  678. if (!proceduralTexture) {
  679. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Cannot create procedural texture for " + babylonTexture.name + "!");
  680. resolve(babylonTexture);
  681. }
  682. proceduralTexture.reservedDataStore = {
  683. hidden: true,
  684. source: babylonTexture
  685. };
  686. _this._recordedTextures.push(proceduralTexture);
  687. proceduralTexture.coordinatesIndex = babylonTexture.coordinatesIndex;
  688. proceduralTexture.setTexture("textureSampler", babylonTexture);
  689. proceduralTexture.setMatrix("textureTransformMat", babylonTexture.getTextureMatrix());
  690. // isReady trigger creation of effect if it doesnt exist yet
  691. if (proceduralTexture.isReady()) {
  692. proceduralTexture.render();
  693. resolve(proceduralTexture);
  694. }
  695. else {
  696. proceduralTexture.getEffect().executeWhenCompiled(function () {
  697. proceduralTexture.render();
  698. resolve(proceduralTexture);
  699. });
  700. }
  701. });
  702. };
  703. return KHR_texture_transform;
  704. }());
  705. _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_texture_transform(exporter); });
  706. /***/ }),
  707. /***/ "./glTF/2.0/Extensions/index.ts":
  708. /*!**************************************!*\
  709. !*** ./glTF/2.0/Extensions/index.ts ***!
  710. \**************************************/
  711. /*! exports provided: KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen */
  712. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  713. "use strict";
  714. __webpack_require__.r(__webpack_exports__);
  715. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  716. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__["KHR_texture_transform"]; });
  717. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  718. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  719. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  720. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_2__["KHR_materials_sheen"]; });
  721. /***/ }),
  722. /***/ "./glTF/2.0/glTFAnimation.ts":
  723. /*!***********************************!*\
  724. !*** ./glTF/2.0/glTFAnimation.ts ***!
  725. \***********************************/
  726. /*! exports provided: _GLTFAnimation */
  727. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  728. "use strict";
  729. __webpack_require__.r(__webpack_exports__);
  730. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _GLTFAnimation; });
  731. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  732. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  733. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  734. /**
  735. * @hidden
  736. * Enum for handling in tangent and out tangent.
  737. */
  738. var _TangentType;
  739. (function (_TangentType) {
  740. /**
  741. * Specifies that input tangents are used.
  742. */
  743. _TangentType[_TangentType["INTANGENT"] = 0] = "INTANGENT";
  744. /**
  745. * Specifies that output tangents are used.
  746. */
  747. _TangentType[_TangentType["OUTTANGENT"] = 1] = "OUTTANGENT";
  748. })(_TangentType || (_TangentType = {}));
  749. /**
  750. * @hidden
  751. * Utility class for generating glTF animation data from BabylonJS.
  752. */
  753. var _GLTFAnimation = /** @class */ (function () {
  754. function _GLTFAnimation() {
  755. }
  756. /**
  757. * @ignore
  758. *
  759. * Creates glTF channel animation from BabylonJS animation.
  760. * @param babylonTransformNode - BabylonJS mesh.
  761. * @param animation - animation.
  762. * @param animationChannelTargetPath - The target animation channel.
  763. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  764. * @param useQuaternion - Specifies if quaternions are used.
  765. * @returns nullable IAnimationData
  766. */
  767. _GLTFAnimation._CreateNodeAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
  768. var inputs = [];
  769. var outputs = [];
  770. var keyFrames = animation.getKeys();
  771. var minMaxKeyFrames = _GLTFAnimation.calculateMinMaxKeyFrames(keyFrames);
  772. var interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
  773. var frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
  774. var interpolation = interpolationOrBake.interpolationType;
  775. var shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
  776. if (shouldBakeAnimation) {
  777. _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
  778. }
  779. else {
  780. if (interpolation === "LINEAR" /* LINEAR */ || interpolation === "STEP" /* STEP */) {
  781. _GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  782. }
  783. else if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
  784. _GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  785. }
  786. else {
  787. _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
  788. }
  789. }
  790. if (inputs.length && outputs.length) {
  791. var result = {
  792. inputs: inputs,
  793. outputs: outputs,
  794. samplerInterpolation: interpolation,
  795. inputsMin: shouldBakeAnimation ? minMaxKeyFrames.min : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minMaxKeyFrames.min / animation.framePerSecond),
  796. inputsMax: shouldBakeAnimation ? minMaxKeyFrames.max : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minMaxKeyFrames.max / animation.framePerSecond)
  797. };
  798. return result;
  799. }
  800. return null;
  801. };
  802. _GLTFAnimation._DeduceAnimationInfo = function (animation) {
  803. var animationChannelTargetPath = null;
  804. var dataAccessorType = "VEC3" /* VEC3 */;
  805. var useQuaternion = false;
  806. var property = animation.targetProperty.split('.');
  807. switch (property[0]) {
  808. case 'scaling': {
  809. animationChannelTargetPath = "scale" /* SCALE */;
  810. break;
  811. }
  812. case 'position': {
  813. animationChannelTargetPath = "translation" /* TRANSLATION */;
  814. break;
  815. }
  816. case 'rotation': {
  817. dataAccessorType = "VEC4" /* VEC4 */;
  818. animationChannelTargetPath = "rotation" /* ROTATION */;
  819. break;
  820. }
  821. case 'rotationQuaternion': {
  822. dataAccessorType = "VEC4" /* VEC4 */;
  823. useQuaternion = true;
  824. animationChannelTargetPath = "rotation" /* ROTATION */;
  825. break;
  826. }
  827. default: {
  828. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported animatable property " + property[0]);
  829. }
  830. }
  831. if (animationChannelTargetPath) {
  832. return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
  833. }
  834. else {
  835. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('animation channel target path and data accessor type could be deduced');
  836. }
  837. return null;
  838. };
  839. /**
  840. * @ignore
  841. * Create node animations from the transform node animations
  842. * @param babylonNode
  843. * @param runtimeGLTFAnimation
  844. * @param idleGLTFAnimations
  845. * @param nodeMap
  846. * @param nodes
  847. * @param binaryWriter
  848. * @param bufferViews
  849. * @param accessors
  850. * @param convertToRightHandedSystem
  851. */
  852. _GLTFAnimation._CreateNodeAnimationFromNodeAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
  853. var glTFAnimation;
  854. if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
  855. if (babylonNode.animations) {
  856. for (var _i = 0, _a = babylonNode.animations; _i < _a.length; _i++) {
  857. var animation = _a[_i];
  858. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
  859. if (animationInfo) {
  860. glTFAnimation = {
  861. name: animation.name,
  862. samplers: [],
  863. channels: []
  864. };
  865. _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
  866. if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
  867. idleGLTFAnimations.push(glTFAnimation);
  868. }
  869. }
  870. }
  871. }
  872. }
  873. };
  874. /**
  875. * @ignore
  876. * Create node animations from the animation groups
  877. * @param babylonScene
  878. * @param glTFAnimations
  879. * @param nodeMap
  880. * @param nodes
  881. * @param binaryWriter
  882. * @param bufferViews
  883. * @param accessors
  884. * @param convertToRightHandedSystem
  885. */
  886. _GLTFAnimation._CreateNodeAnimationFromAnimationGroups = function (babylonScene, glTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
  887. var glTFAnimation;
  888. if (babylonScene.animationGroups) {
  889. var animationGroups = babylonScene.animationGroups;
  890. for (var _i = 0, animationGroups_1 = animationGroups; _i < animationGroups_1.length; _i++) {
  891. var animationGroup = animationGroups_1[_i];
  892. glTFAnimation = {
  893. name: animationGroup.name,
  894. channels: [],
  895. samplers: []
  896. };
  897. for (var _a = 0, _b = animationGroup.targetedAnimations; _a < _b.length; _a++) {
  898. var targetAnimation = _b[_a];
  899. var target = targetAnimation.target;
  900. var animation = targetAnimation.animation;
  901. if (target instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"] || target.length === 1 && target[0] instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"]) { // TODO: Update to support bones
  902. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
  903. if (animationInfo) {
  904. var babylonMesh = target instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"] ? target : target[0];
  905. _GLTFAnimation.AddAnimation("" + animation.name, glTFAnimation, babylonMesh, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
  906. }
  907. }
  908. }
  909. if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
  910. glTFAnimations.push(glTFAnimation);
  911. }
  912. }
  913. }
  914. };
  915. _GLTFAnimation.AddAnimation = function (name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
  916. var animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate);
  917. var bufferView;
  918. var accessor;
  919. var keyframeAccessorIndex;
  920. var dataAccessorIndex;
  921. var outputLength;
  922. var animationSampler;
  923. var animationChannel;
  924. if (animationData) {
  925. var nodeIndex = nodeMap[babylonTransformNode.uniqueId];
  926. // Creates buffer view and accessor for key frames.
  927. var byteLength = animationData.inputs.length * 4;
  928. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, name + " keyframe data view");
  929. bufferViews.push(bufferView);
  930. animationData.inputs.forEach(function (input) {
  931. binaryWriter.setFloat32(input);
  932. });
  933. accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateAccessor(bufferViews.length - 1, name + " keyframes", "SCALAR" /* SCALAR */, 5126 /* FLOAT */, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
  934. accessors.push(accessor);
  935. keyframeAccessorIndex = accessors.length - 1;
  936. // create bufferview and accessor for keyed values.
  937. outputLength = animationData.outputs.length;
  938. byteLength = dataAccessorType === "VEC3" /* VEC3 */ ? animationData.outputs.length * 12 : animationData.outputs.length * 16;
  939. // check for in and out tangents
  940. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, name + " data view");
  941. bufferViews.push(bufferView);
  942. animationData.outputs.forEach(function (output) {
  943. output.forEach(function (entry) {
  944. binaryWriter.setFloat32(entry);
  945. });
  946. });
  947. accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateAccessor(bufferViews.length - 1, name + " data", dataAccessorType, 5126 /* FLOAT */, outputLength, null, null, null);
  948. accessors.push(accessor);
  949. dataAccessorIndex = accessors.length - 1;
  950. // create sampler
  951. animationSampler = {
  952. interpolation: animationData.samplerInterpolation,
  953. input: keyframeAccessorIndex,
  954. output: dataAccessorIndex
  955. };
  956. glTFAnimation.samplers.push(animationSampler);
  957. // create channel
  958. animationChannel = {
  959. sampler: glTFAnimation.samplers.length - 1,
  960. target: {
  961. node: nodeIndex,
  962. path: animationChannelTargetPath
  963. }
  964. };
  965. glTFAnimation.channels.push(animationChannel);
  966. }
  967. };
  968. /**
  969. * Create a baked animation
  970. * @param babylonTransformNode BabylonJS mesh
  971. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  972. * @param animationChannelTargetPath animation target channel
  973. * @param minFrame minimum animation frame
  974. * @param maxFrame maximum animation frame
  975. * @param fps frames per second of the animation
  976. * @param inputs input key frames of the animation
  977. * @param outputs output key frame data of the animation
  978. * @param convertToRightHandedSystem converts the values to right-handed
  979. * @param useQuaternion specifies if quaternions should be used
  980. */
  981. _GLTFAnimation._CreateBakedAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion) {
  982. var value;
  983. var quaternionCache = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  984. var previousTime = null;
  985. var time;
  986. var maxUsedFrame = null;
  987. var currKeyFrame = null;
  988. var nextKeyFrame = null;
  989. var prevKeyFrame = null;
  990. var endFrame = null;
  991. minMaxFrames.min = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minFrame / fps);
  992. var keyFrames = animation.getKeys();
  993. for (var i = 0, length_1 = keyFrames.length; i < length_1; ++i) {
  994. endFrame = null;
  995. currKeyFrame = keyFrames[i];
  996. if (i + 1 < length_1) {
  997. nextKeyFrame = keyFrames[i + 1];
  998. if (currKeyFrame.value.equals && currKeyFrame.value.equals(nextKeyFrame.value) || currKeyFrame.value === nextKeyFrame.value) {
  999. if (i === 0) { // set the first frame to itself
  1000. endFrame = currKeyFrame.frame;
  1001. }
  1002. else {
  1003. continue;
  1004. }
  1005. }
  1006. else {
  1007. endFrame = nextKeyFrame.frame;
  1008. }
  1009. }
  1010. else {
  1011. // at the last key frame
  1012. prevKeyFrame = keyFrames[i - 1];
  1013. if (currKeyFrame.value.equals && currKeyFrame.value.equals(prevKeyFrame.value) || currKeyFrame.value === prevKeyFrame.value) {
  1014. continue;
  1015. }
  1016. else {
  1017. endFrame = maxFrame;
  1018. }
  1019. }
  1020. if (endFrame) {
  1021. for (var f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {
  1022. time = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(f / fps);
  1023. if (time === previousTime) {
  1024. continue;
  1025. }
  1026. previousTime = time;
  1027. maxUsedFrame = time;
  1028. var state = {
  1029. key: 0,
  1030. repeatCount: 0,
  1031. loopMode: animation.loopMode
  1032. };
  1033. value = animation._interpolate(f, state);
  1034. _GLTFAnimation._SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  1035. }
  1036. }
  1037. }
  1038. if (maxUsedFrame) {
  1039. minMaxFrames.max = maxUsedFrame;
  1040. }
  1041. };
  1042. _GLTFAnimation._ConvertFactorToVector3OrQuaternion = function (factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
  1043. var property;
  1044. var componentName;
  1045. var value = null;
  1046. var basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1047. if (animationType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT) { // handles single component x, y, z or w component animation by using a base property and animating over a component.
  1048. property = animation.targetProperty.split('.');
  1049. componentName = property ? property[1] : ''; // x, y, or z component
  1050. value = useQuaternion ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(basePositionRotationOrScale).normalize() : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(basePositionRotationOrScale);
  1051. switch (componentName) {
  1052. case 'x': {
  1053. value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  1054. break;
  1055. }
  1056. case 'y': {
  1057. value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  1058. break;
  1059. }
  1060. case 'z': {
  1061. value[componentName] = (convertToRightHandedSystem && !useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  1062. break;
  1063. }
  1064. case 'w': {
  1065. value.w = factor;
  1066. break;
  1067. }
  1068. default: {
  1069. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("glTFAnimation: Unsupported component type \"" + componentName + "\" for scale animation!");
  1070. }
  1071. }
  1072. }
  1073. return value;
  1074. };
  1075. _GLTFAnimation._SetInterpolatedValue = function (babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  1076. var animationType = animation.dataType;
  1077. var cacheValue;
  1078. inputs.push(time);
  1079. if (typeof value === "number") {
  1080. value = this._ConvertFactorToVector3OrQuaternion(value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1081. }
  1082. if (value) {
  1083. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1084. if (useQuaternion) {
  1085. quaternionCache = value;
  1086. }
  1087. else {
  1088. cacheValue = value;
  1089. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);
  1090. }
  1091. if (convertToRightHandedSystem) {
  1092. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(quaternionCache);
  1093. if (!babylonTransformNode.parent) {
  1094. quaternionCache = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(quaternionCache);
  1095. }
  1096. }
  1097. outputs.push(quaternionCache.asArray());
  1098. }
  1099. else {
  1100. cacheValue = value;
  1101. if (convertToRightHandedSystem && (animationChannelTargetPath !== "scale" /* SCALE */)) {
  1102. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(cacheValue);
  1103. if (!babylonTransformNode.parent) {
  1104. cacheValue.x *= -1;
  1105. cacheValue.z *= -1;
  1106. }
  1107. }
  1108. outputs.push(cacheValue.asArray());
  1109. }
  1110. }
  1111. };
  1112. /**
  1113. * Creates linear animation from the animation key frames
  1114. * @param babylonTransformNode BabylonJS mesh
  1115. * @param animation BabylonJS animation
  1116. * @param animationChannelTargetPath The target animation channel
  1117. * @param frameDelta The difference between the last and first frame of the animation
  1118. * @param inputs Array to store the key frame times
  1119. * @param outputs Array to store the key frame data
  1120. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1121. * @param useQuaternion Specifies if quaternions are used in the animation
  1122. */
  1123. _GLTFAnimation._CreateLinearOrStepAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  1124. for (var _i = 0, _a = animation.getKeys(); _i < _a.length; _i++) {
  1125. var keyFrame = _a[_i];
  1126. inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
  1127. _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  1128. }
  1129. };
  1130. /**
  1131. * Creates cubic spline animation from the animation key frames
  1132. * @param babylonTransformNode BabylonJS mesh
  1133. * @param animation BabylonJS animation
  1134. * @param animationChannelTargetPath The target animation channel
  1135. * @param frameDelta The difference between the last and first frame of the animation
  1136. * @param inputs Array to store the key frame times
  1137. * @param outputs Array to store the key frame data
  1138. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1139. * @param useQuaternion Specifies if quaternions are used in the animation
  1140. */
  1141. _GLTFAnimation._CreateCubicSplineAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  1142. animation.getKeys().forEach(function (keyFrame) {
  1143. inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
  1144. _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  1145. _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  1146. _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  1147. });
  1148. };
  1149. _GLTFAnimation._GetBasePositionRotationOrScale = function (babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
  1150. var basePositionRotationOrScale;
  1151. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1152. if (useQuaternion) {
  1153. if (babylonTransformNode.rotationQuaternion) {
  1154. basePositionRotationOrScale = babylonTransformNode.rotationQuaternion.asArray();
  1155. if (convertToRightHandedSystem) {
  1156. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(basePositionRotationOrScale);
  1157. if (!babylonTransformNode.parent) {
  1158. basePositionRotationOrScale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(basePositionRotationOrScale)).asArray();
  1159. }
  1160. }
  1161. }
  1162. else {
  1163. basePositionRotationOrScale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity().asArray();
  1164. }
  1165. }
  1166. else {
  1167. basePositionRotationOrScale = babylonTransformNode.rotation.asArray();
  1168. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalArray3FromRef(basePositionRotationOrScale);
  1169. }
  1170. }
  1171. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1172. basePositionRotationOrScale = babylonTransformNode.position.asArray();
  1173. if (convertToRightHandedSystem) {
  1174. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionArray3FromRef(basePositionRotationOrScale);
  1175. }
  1176. }
  1177. else { // scale
  1178. basePositionRotationOrScale = babylonTransformNode.scaling.asArray();
  1179. }
  1180. return basePositionRotationOrScale;
  1181. };
  1182. /**
  1183. * Adds a key frame value
  1184. * @param keyFrame
  1185. * @param animation
  1186. * @param outputs
  1187. * @param animationChannelTargetPath
  1188. * @param basePositionRotationOrScale
  1189. * @param convertToRightHandedSystem
  1190. * @param useQuaternion
  1191. */
  1192. _GLTFAnimation._AddKeyframeValue = function (keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion) {
  1193. var value;
  1194. var newPositionRotationOrScale;
  1195. var animationType = animation.dataType;
  1196. if (animationType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3) {
  1197. value = keyFrame.value.asArray();
  1198. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1199. var array = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(value);
  1200. var rotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(array.y, array.x, array.z);
  1201. if (convertToRightHandedSystem) {
  1202. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(rotationQuaternion);
  1203. if (!babylonTransformNode.parent) {
  1204. rotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(rotationQuaternion);
  1205. }
  1206. }
  1207. value = rotationQuaternion.asArray();
  1208. }
  1209. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1210. if (convertToRightHandedSystem) {
  1211. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalArray3FromRef(value);
  1212. if (!babylonTransformNode.parent) {
  1213. value[0] *= -1;
  1214. value[2] *= -1;
  1215. }
  1216. }
  1217. }
  1218. outputs.push(value); // scale vector.
  1219. }
  1220. else if (animationType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT) { // handles single component x, y, z or w component animation by using a base property and animating over a component.
  1221. newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1222. if (newPositionRotationOrScale) {
  1223. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1224. var posRotScale = useQuaternion ? newPositionRotationOrScale : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();
  1225. if (convertToRightHandedSystem) {
  1226. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(posRotScale);
  1227. if (!babylonTransformNode.parent) {
  1228. posRotScale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(posRotScale);
  1229. }
  1230. }
  1231. outputs.push(posRotScale.asArray());
  1232. }
  1233. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1234. if (convertToRightHandedSystem) {
  1235. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(newPositionRotationOrScale);
  1236. if (!babylonTransformNode.parent) {
  1237. newPositionRotationOrScale.x *= -1;
  1238. newPositionRotationOrScale.z *= -1;
  1239. }
  1240. }
  1241. }
  1242. outputs.push(newPositionRotationOrScale.asArray());
  1243. }
  1244. }
  1245. else if (animationType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION) {
  1246. value = keyFrame.value.normalize().asArray();
  1247. if (convertToRightHandedSystem) {
  1248. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(value);
  1249. if (!babylonTransformNode.parent) {
  1250. value = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(value)).asArray();
  1251. }
  1252. }
  1253. outputs.push(value);
  1254. }
  1255. else {
  1256. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('glTFAnimation: Unsupported key frame values for animation!');
  1257. }
  1258. };
  1259. /**
  1260. * Determine the interpolation based on the key frames
  1261. * @param keyFrames
  1262. * @param animationChannelTargetPath
  1263. * @param useQuaternion
  1264. */
  1265. _GLTFAnimation._DeduceInterpolation = function (keyFrames, animationChannelTargetPath, useQuaternion) {
  1266. var interpolationType;
  1267. var shouldBakeAnimation = false;
  1268. var key;
  1269. if (animationChannelTargetPath === "rotation" /* ROTATION */ && !useQuaternion) {
  1270. return { interpolationType: "LINEAR" /* LINEAR */, shouldBakeAnimation: true };
  1271. }
  1272. for (var i = 0, length_2 = keyFrames.length; i < length_2; ++i) {
  1273. key = keyFrames[i];
  1274. if (key.inTangent || key.outTangent) {
  1275. if (interpolationType) {
  1276. if (interpolationType !== "CUBICSPLINE" /* CUBICSPLINE */) {
  1277. interpolationType = "LINEAR" /* LINEAR */;
  1278. shouldBakeAnimation = true;
  1279. break;
  1280. }
  1281. }
  1282. else {
  1283. interpolationType = "CUBICSPLINE" /* CUBICSPLINE */;
  1284. }
  1285. }
  1286. else {
  1287. if (interpolationType) {
  1288. if (interpolationType === "CUBICSPLINE" /* CUBICSPLINE */ ||
  1289. (key.interpolation && (key.interpolation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP) && interpolationType !== "STEP" /* STEP */)) {
  1290. interpolationType = "LINEAR" /* LINEAR */;
  1291. shouldBakeAnimation = true;
  1292. break;
  1293. }
  1294. }
  1295. else {
  1296. if (key.interpolation && (key.interpolation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP)) {
  1297. interpolationType = "STEP" /* STEP */;
  1298. }
  1299. else {
  1300. interpolationType = "LINEAR" /* LINEAR */;
  1301. }
  1302. }
  1303. }
  1304. }
  1305. if (!interpolationType) {
  1306. interpolationType = "LINEAR" /* LINEAR */;
  1307. }
  1308. return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
  1309. };
  1310. /**
  1311. * Adds an input tangent or output tangent to the output data
  1312. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  1313. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  1314. * @param outputs The animation data by keyframe
  1315. * @param animationChannelTargetPath The target animation channel
  1316. * @param interpolation The interpolation type
  1317. * @param keyFrame The key frame with the animation data
  1318. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  1319. * @param useQuaternion Specifies if quaternions are used
  1320. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  1321. */
  1322. _GLTFAnimation.AddSplineTangent = function (babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem) {
  1323. var tangent;
  1324. var tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
  1325. if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
  1326. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1327. if (tangentValue) {
  1328. if (useQuaternion) {
  1329. tangent = tangentValue.scale(frameDelta).asArray();
  1330. }
  1331. else {
  1332. var array = tangentValue.scale(frameDelta);
  1333. tangent = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(array.y, array.x, array.z).asArray();
  1334. }
  1335. if (convertToRightHandedSystem) {
  1336. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(tangent);
  1337. if (!babylonTransformNode.parent) {
  1338. tangent = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(tangent)).asArray();
  1339. }
  1340. }
  1341. }
  1342. else {
  1343. tangent = [0, 0, 0, 0];
  1344. }
  1345. }
  1346. else {
  1347. if (tangentValue) {
  1348. tangent = tangentValue.scale(frameDelta).asArray();
  1349. if (convertToRightHandedSystem) {
  1350. if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1351. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionArray3FromRef(tangent);
  1352. if (!babylonTransformNode.parent) {
  1353. tangent[0] *= -1; // x
  1354. tangent[2] *= -1; // z
  1355. }
  1356. }
  1357. }
  1358. }
  1359. else {
  1360. tangent = [0, 0, 0];
  1361. }
  1362. }
  1363. outputs.push(tangent);
  1364. }
  1365. };
  1366. /**
  1367. * Get the minimum and maximum key frames' frame values
  1368. * @param keyFrames animation key frames
  1369. * @returns the minimum and maximum key frame value
  1370. */
  1371. _GLTFAnimation.calculateMinMaxKeyFrames = function (keyFrames) {
  1372. var min = Infinity;
  1373. var max = -Infinity;
  1374. keyFrames.forEach(function (keyFrame) {
  1375. min = Math.min(min, keyFrame.frame);
  1376. max = Math.max(max, keyFrame.frame);
  1377. });
  1378. return { min: min, max: max };
  1379. };
  1380. return _GLTFAnimation;
  1381. }());
  1382. /***/ }),
  1383. /***/ "./glTF/2.0/glTFData.ts":
  1384. /*!******************************!*\
  1385. !*** ./glTF/2.0/glTFData.ts ***!
  1386. \******************************/
  1387. /*! exports provided: GLTFData */
  1388. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1389. "use strict";
  1390. __webpack_require__.r(__webpack_exports__);
  1391. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return GLTFData; });
  1392. /**
  1393. * Class for holding and downloading glTF file data
  1394. */
  1395. var GLTFData = /** @class */ (function () {
  1396. /**
  1397. * Initializes the glTF file object
  1398. */
  1399. function GLTFData() {
  1400. this.glTFFiles = {};
  1401. }
  1402. /**
  1403. * Downloads the glTF data as files based on their names and data
  1404. */
  1405. GLTFData.prototype.downloadFiles = function () {
  1406. /**
  1407. * Checks for a matching suffix at the end of a string (for ES5 and lower)
  1408. * @param str Source string
  1409. * @param suffix Suffix to search for in the source string
  1410. * @returns Boolean indicating whether the suffix was found (true) or not (false)
  1411. */
  1412. function endsWith(str, suffix) {
  1413. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  1414. }
  1415. for (var key in this.glTFFiles) {
  1416. var link = document.createElement('a');
  1417. document.body.appendChild(link);
  1418. link.setAttribute("type", "hidden");
  1419. link.download = key;
  1420. var blob = this.glTFFiles[key];
  1421. var mimeType = void 0;
  1422. if (endsWith(key, ".glb")) {
  1423. mimeType = { type: "model/gltf-binary" };
  1424. }
  1425. else if (endsWith(key, ".bin")) {
  1426. mimeType = { type: "application/octet-stream" };
  1427. }
  1428. else if (endsWith(key, ".gltf")) {
  1429. mimeType = { type: "model/gltf+json" };
  1430. }
  1431. else if (endsWith(key, ".jpeg" || false)) {
  1432. mimeType = { type: "image/jpeg" /* JPEG */ };
  1433. }
  1434. else if (endsWith(key, ".png")) {
  1435. mimeType = { type: "image/png" /* PNG */ };
  1436. }
  1437. link.href = window.URL.createObjectURL(new Blob([blob], mimeType));
  1438. link.click();
  1439. }
  1440. };
  1441. return GLTFData;
  1442. }());
  1443. /***/ }),
  1444. /***/ "./glTF/2.0/glTFExporter.ts":
  1445. /*!**********************************!*\
  1446. !*** ./glTF/2.0/glTFExporter.ts ***!
  1447. \**********************************/
  1448. /*! exports provided: _Exporter, _BinaryWriter */
  1449. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1450. "use strict";
  1451. __webpack_require__.r(__webpack_exports__);
  1452. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _Exporter; });
  1453. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _BinaryWriter; });
  1454. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1455. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  1456. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__);
  1457. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  1458. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  1459. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  1460. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  1461. /**
  1462. * Converts Babylon Scene into glTF 2.0.
  1463. * @hidden
  1464. */
  1465. var _Exporter = /** @class */ (function () {
  1466. /**
  1467. * Creates a glTF Exporter instance, which can accept optional exporter options
  1468. * @param babylonScene Babylon scene object
  1469. * @param options Options to modify the behavior of the exporter
  1470. */
  1471. function _Exporter(babylonScene, options) {
  1472. this._extensions = {};
  1473. this._glTF = {
  1474. asset: { generator: "BabylonJS", version: "2.0" }
  1475. };
  1476. this._babylonScene = babylonScene;
  1477. this._bufferViews = [];
  1478. this._accessors = [];
  1479. this._meshes = [];
  1480. this._scenes = [];
  1481. this._nodes = [];
  1482. this._images = [];
  1483. this._materials = [];
  1484. this._materialMap = [];
  1485. this._textures = [];
  1486. this._samplers = [];
  1487. this._animations = [];
  1488. this._imageData = {};
  1489. this._convertToRightHandedSystem = !this._babylonScene.useRightHandedSystem;
  1490. this._options = options || {};
  1491. this._animationSampleRate = options && options.animationSampleRate ? options.animationSampleRate : 1 / 60;
  1492. this._glTFMaterialExporter = new _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_2__["_GLTFMaterialExporter"](this);
  1493. this._loadExtensions();
  1494. }
  1495. _Exporter.prototype._applyExtension = function (node, extensions, index, actionAsync) {
  1496. var _this = this;
  1497. if (index >= extensions.length) {
  1498. return Promise.resolve(node);
  1499. }
  1500. var currentPromise = actionAsync(extensions[index], node);
  1501. if (!currentPromise) {
  1502. return this._applyExtension(node, extensions, index + 1, actionAsync);
  1503. }
  1504. return currentPromise.then(function (newNode) { return _this._applyExtension(newNode || node, extensions, index + 1, actionAsync); });
  1505. };
  1506. _Exporter.prototype._applyExtensions = function (node, actionAsync) {
  1507. var extensions = [];
  1508. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1509. var name_1 = _a[_i];
  1510. extensions.push(this._extensions[name_1]);
  1511. }
  1512. return this._applyExtension(node, extensions, 0, actionAsync);
  1513. };
  1514. _Exporter.prototype._extensionsPreExportTextureAsync = function (context, babylonTexture, mimeType) {
  1515. return this._applyExtensions(babylonTexture, function (extension, node) { return extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType); });
  1516. };
  1517. _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
  1518. return this._applyExtensions(meshPrimitive, function (extension, node) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter); });
  1519. };
  1520. _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode) {
  1521. return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode); });
  1522. };
  1523. _Exporter.prototype._extensionsPostExportMaterialAsync = function (context, material, babylonMaterial) {
  1524. return this._applyExtensions(material, function (extension, node) { return extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial); });
  1525. };
  1526. _Exporter.prototype._extensionsPostExportMaterialAdditionalTextures = function (context, material, babylonMaterial) {
  1527. var output = [];
  1528. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1529. var name_2 = _a[_i];
  1530. var extension = this._extensions[name_2];
  1531. if (extension.postExportMaterialAdditionalTextures) {
  1532. output.push.apply(output, extension.postExportMaterialAdditionalTextures(context, material, babylonMaterial));
  1533. }
  1534. }
  1535. return output;
  1536. };
  1537. _Exporter.prototype._extensionsPostExportTextures = function (context, textureInfo, babylonTexture) {
  1538. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1539. var name_3 = _a[_i];
  1540. var extension = this._extensions[name_3];
  1541. if (extension.postExportTexture) {
  1542. extension.postExportTexture(context, textureInfo, babylonTexture);
  1543. }
  1544. }
  1545. };
  1546. _Exporter.prototype._forEachExtensions = function (action) {
  1547. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1548. var name_4 = _a[_i];
  1549. var extension = this._extensions[name_4];
  1550. if (extension.enabled) {
  1551. action(extension);
  1552. }
  1553. }
  1554. };
  1555. _Exporter.prototype._extensionsOnExporting = function () {
  1556. var _this = this;
  1557. this._forEachExtensions(function (extension) {
  1558. if (extension.wasUsed) {
  1559. if (_this._glTF.extensionsUsed == null) {
  1560. _this._glTF.extensionsUsed = [];
  1561. }
  1562. if (_this._glTF.extensionsUsed.indexOf(extension.name) === -1) {
  1563. _this._glTF.extensionsUsed.push(extension.name);
  1564. }
  1565. if (extension.required) {
  1566. if (_this._glTF.extensionsRequired == null) {
  1567. _this._glTF.extensionsRequired = [];
  1568. }
  1569. if (_this._glTF.extensionsRequired.indexOf(extension.name) === -1) {
  1570. _this._glTF.extensionsRequired.push(extension.name);
  1571. }
  1572. }
  1573. if (_this._glTF.extensions == null) {
  1574. _this._glTF.extensions = {};
  1575. }
  1576. if (extension.onExporting) {
  1577. extension.onExporting();
  1578. }
  1579. }
  1580. });
  1581. };
  1582. /**
  1583. * Load glTF serializer extensions
  1584. */
  1585. _Exporter.prototype._loadExtensions = function () {
  1586. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1587. var name_5 = _a[_i];
  1588. var extension = _Exporter._ExtensionFactories[name_5](this);
  1589. this._extensions[name_5] = extension;
  1590. }
  1591. };
  1592. _Exporter.prototype.dispose = function () {
  1593. for (var extensionKey in this._extensions) {
  1594. var extension = this._extensions[extensionKey];
  1595. extension.dispose();
  1596. }
  1597. };
  1598. /**
  1599. * Registers a glTF exporter extension
  1600. * @param name Name of the extension to export
  1601. * @param factory The factory function that creates the exporter extension
  1602. */
  1603. _Exporter.RegisterExtension = function (name, factory) {
  1604. if (_Exporter.UnregisterExtension(name)) {
  1605. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Extension with the name " + name + " already exists");
  1606. }
  1607. _Exporter._ExtensionFactories[name] = factory;
  1608. _Exporter._ExtensionNames.push(name);
  1609. };
  1610. /**
  1611. * Un-registers an exporter extension
  1612. * @param name The name fo the exporter extension
  1613. * @returns A boolean indicating whether the extension has been un-registered
  1614. */
  1615. _Exporter.UnregisterExtension = function (name) {
  1616. if (!_Exporter._ExtensionFactories[name]) {
  1617. return false;
  1618. }
  1619. delete _Exporter._ExtensionFactories[name];
  1620. var index = _Exporter._ExtensionNames.indexOf(name);
  1621. if (index !== -1) {
  1622. _Exporter._ExtensionNames.splice(index, 1);
  1623. }
  1624. return true;
  1625. };
  1626. /**
  1627. * Lazy load a local engine with premultiplied alpha set to false
  1628. */
  1629. _Exporter.prototype._getLocalEngine = function () {
  1630. if (!this._localEngine) {
  1631. var localCanvas = document.createElement('canvas');
  1632. localCanvas.id = "WriteCanvas";
  1633. localCanvas.width = 2048;
  1634. localCanvas.height = 2048;
  1635. this._localEngine = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Engine"](localCanvas, true, { premultipliedAlpha: false, preserveDrawingBuffer: true });
  1636. this._localEngine.setViewport(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Viewport"](0, 0, 1, 1));
  1637. }
  1638. return this._localEngine;
  1639. };
  1640. _Exporter.prototype.reorderIndicesBasedOnPrimitiveMode = function (submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter) {
  1641. switch (primitiveMode) {
  1642. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode: {
  1643. if (!byteOffset) {
  1644. byteOffset = 0;
  1645. }
  1646. for (var i = submesh.indexStart, length_1 = submesh.indexStart + submesh.indexCount; i < length_1; i = i + 3) {
  1647. var index = byteOffset + i * 4;
  1648. // swap the second and third indices
  1649. var secondIndex = binaryWriter.getUInt32(index + 4);
  1650. var thirdIndex = binaryWriter.getUInt32(index + 8);
  1651. binaryWriter.setUInt32(thirdIndex, index + 4);
  1652. binaryWriter.setUInt32(secondIndex, index + 8);
  1653. }
  1654. break;
  1655. }
  1656. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFanDrawMode: {
  1657. for (var i = submesh.indexStart + submesh.indexCount - 1, start = submesh.indexStart; i >= start; --i) {
  1658. binaryWriter.setUInt32(babylonIndices[i], byteOffset);
  1659. byteOffset += 4;
  1660. }
  1661. break;
  1662. }
  1663. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleStripDrawMode: {
  1664. if (submesh.indexCount >= 3) {
  1665. binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 2], byteOffset + 4);
  1666. binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 1], byteOffset + 8);
  1667. }
  1668. break;
  1669. }
  1670. }
  1671. };
  1672. /**
  1673. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  1674. * clock-wise during export to glTF
  1675. * @param submesh BabylonJS submesh
  1676. * @param primitiveMode Primitive mode of the mesh
  1677. * @param sideOrientation the winding order of the submesh
  1678. * @param vertexBufferKind The type of vertex attribute
  1679. * @param meshAttributeArray The vertex attribute data
  1680. * @param byteOffset The offset to the binary data
  1681. * @param binaryWriter The binary data for the glTF file
  1682. */
  1683. _Exporter.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1684. if (this._convertToRightHandedSystem && sideOrientation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].ClockWiseSideOrientation) {
  1685. switch (primitiveMode) {
  1686. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode: {
  1687. this.reorderTriangleFillMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  1688. break;
  1689. }
  1690. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleStripDrawMode: {
  1691. this.reorderTriangleStripDrawMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  1692. break;
  1693. }
  1694. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFanDrawMode: {
  1695. this.reorderTriangleFanMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  1696. break;
  1697. }
  1698. }
  1699. }
  1700. };
  1701. /**
  1702. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  1703. * clock-wise during export to glTF
  1704. * @param submesh BabylonJS submesh
  1705. * @param primitiveMode Primitive mode of the mesh
  1706. * @param sideOrientation the winding order of the submesh
  1707. * @param vertexBufferKind The type of vertex attribute
  1708. * @param meshAttributeArray The vertex attribute data
  1709. * @param byteOffset The offset to the binary data
  1710. * @param binaryWriter The binary data for the glTF file
  1711. */
  1712. _Exporter.prototype.reorderTriangleFillMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1713. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  1714. if (vertexBuffer) {
  1715. var stride = vertexBuffer.byteStride / babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  1716. if (submesh.verticesCount % 3 !== 0) {
  1717. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('The submesh vertices for the triangle fill mode is not divisible by 3!');
  1718. }
  1719. else {
  1720. var vertexData = [];
  1721. var index = 0;
  1722. switch (vertexBufferKind) {
  1723. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind:
  1724. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  1725. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  1726. index = x * stride;
  1727. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  1728. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  1729. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + stride));
  1730. }
  1731. break;
  1732. }
  1733. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  1734. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  1735. index = x * stride;
  1736. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  1737. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + 2 * stride));
  1738. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + stride));
  1739. }
  1740. break;
  1741. }
  1742. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  1743. var size = vertexBuffer.getSize();
  1744. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {
  1745. index = x * stride;
  1746. if (size === 4) {
  1747. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  1748. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + 2 * stride));
  1749. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + stride));
  1750. }
  1751. else {
  1752. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  1753. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  1754. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + stride));
  1755. }
  1756. }
  1757. break;
  1758. }
  1759. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  1760. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  1761. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  1762. index = x * stride;
  1763. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index));
  1764. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index + 2 * stride));
  1765. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index + stride));
  1766. }
  1767. break;
  1768. }
  1769. default: {
  1770. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  1771. }
  1772. }
  1773. this.writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter);
  1774. }
  1775. }
  1776. else {
  1777. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("reorderTriangleFillMode: Vertex Buffer Kind " + vertexBufferKind + " not present!");
  1778. }
  1779. };
  1780. /**
  1781. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  1782. * clock-wise during export to glTF
  1783. * @param submesh BabylonJS submesh
  1784. * @param primitiveMode Primitive mode of the mesh
  1785. * @param sideOrientation the winding order of the submesh
  1786. * @param vertexBufferKind The type of vertex attribute
  1787. * @param meshAttributeArray The vertex attribute data
  1788. * @param byteOffset The offset to the binary data
  1789. * @param binaryWriter The binary data for the glTF file
  1790. */
  1791. _Exporter.prototype.reorderTriangleStripDrawMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1792. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  1793. if (vertexBuffer) {
  1794. var stride = vertexBuffer.byteStride / babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  1795. var vertexData = [];
  1796. var index = 0;
  1797. switch (vertexBufferKind) {
  1798. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind:
  1799. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  1800. index = submesh.verticesStart;
  1801. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  1802. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + stride));
  1803. break;
  1804. }
  1805. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  1806. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1807. index = x * stride;
  1808. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  1809. }
  1810. break;
  1811. }
  1812. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  1813. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1814. index = x * stride;
  1815. vertexBuffer.getSize() === 4 ? vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index)) : vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  1816. }
  1817. break;
  1818. }
  1819. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  1820. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  1821. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1822. index = x * stride;
  1823. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index));
  1824. }
  1825. break;
  1826. }
  1827. default: {
  1828. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  1829. }
  1830. }
  1831. this.writeVertexAttributeData(vertexData, byteOffset + 12, vertexBufferKind, meshAttributeArray, binaryWriter);
  1832. }
  1833. else {
  1834. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("reorderTriangleStripDrawMode: Vertex buffer kind " + vertexBufferKind + " not present!");
  1835. }
  1836. };
  1837. /**
  1838. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  1839. * clock-wise during export to glTF
  1840. * @param submesh BabylonJS submesh
  1841. * @param primitiveMode Primitive mode of the mesh
  1842. * @param sideOrientation the winding order of the submesh
  1843. * @param vertexBufferKind The type of vertex attribute
  1844. * @param meshAttributeArray The vertex attribute data
  1845. * @param byteOffset The offset to the binary data
  1846. * @param binaryWriter The binary data for the glTF file
  1847. */
  1848. _Exporter.prototype.reorderTriangleFanMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1849. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  1850. if (vertexBuffer) {
  1851. var stride = vertexBuffer.byteStride / babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  1852. var vertexData = [];
  1853. var index = 0;
  1854. switch (vertexBufferKind) {
  1855. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind:
  1856. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  1857. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1858. index = x * stride;
  1859. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  1860. }
  1861. break;
  1862. }
  1863. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  1864. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1865. index = x * stride;
  1866. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  1867. }
  1868. break;
  1869. }
  1870. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  1871. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1872. index = x * stride;
  1873. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  1874. vertexBuffer.getSize() === 4 ? vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index)) : vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  1875. }
  1876. break;
  1877. }
  1878. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  1879. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  1880. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1881. index = x * stride;
  1882. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index));
  1883. }
  1884. break;
  1885. }
  1886. default: {
  1887. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  1888. }
  1889. }
  1890. this.writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter);
  1891. }
  1892. else {
  1893. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("reorderTriangleFanMode: Vertex buffer kind " + vertexBufferKind + " not present!");
  1894. }
  1895. };
  1896. /**
  1897. * Writes the vertex attribute data to binary
  1898. * @param vertices The vertices to write to the binary writer
  1899. * @param byteOffset The offset into the binary writer to overwrite binary data
  1900. * @param vertexAttributeKind The vertex attribute type
  1901. * @param meshAttributeArray The vertex attribute data
  1902. * @param binaryWriter The writer containing the binary data
  1903. */
  1904. _Exporter.prototype.writeVertexAttributeData = function (vertices, byteOffset, vertexAttributeKind, meshAttributeArray, binaryWriter) {
  1905. for (var _i = 0, vertices_1 = vertices; _i < vertices_1.length; _i++) {
  1906. var vertex = vertices_1[_i];
  1907. if (this._convertToRightHandedSystem && !(vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind) && !(vertex instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector2"])) {
  1908. if (vertex instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"]) {
  1909. if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind) {
  1910. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(vertex);
  1911. }
  1912. else if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind) {
  1913. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(vertex);
  1914. }
  1915. else {
  1916. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('Unsupported vertex attribute kind!');
  1917. }
  1918. }
  1919. else {
  1920. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedVector4FromRef(vertex);
  1921. }
  1922. }
  1923. if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind) {
  1924. vertex.normalize();
  1925. }
  1926. else if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind && vertex instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"]) {
  1927. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._NormalizeTangentFromRef(vertex);
  1928. }
  1929. for (var _a = 0, _b = vertex.asArray(); _a < _b.length; _a++) {
  1930. var component = _b[_a];
  1931. binaryWriter.setFloat32(component, byteOffset);
  1932. byteOffset += 4;
  1933. }
  1934. }
  1935. };
  1936. /**
  1937. * Writes mesh attribute data to a data buffer
  1938. * Returns the bytelength of the data
  1939. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  1940. * @param meshAttributeArray Array containing the attribute data
  1941. * @param binaryWriter The buffer to write the binary data to
  1942. * @param indices Used to specify the order of the vertex data
  1943. */
  1944. _Exporter.prototype.writeAttributeData = function (vertexBufferKind, meshAttributeArray, byteStride, binaryWriter) {
  1945. var stride = byteStride / 4;
  1946. var vertexAttributes = [];
  1947. var index;
  1948. switch (vertexBufferKind) {
  1949. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind: {
  1950. for (var k = 0, length_2 = meshAttributeArray.length / stride; k < length_2; ++k) {
  1951. index = k * stride;
  1952. var vertexData = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index);
  1953. if (this._convertToRightHandedSystem) {
  1954. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(vertexData);
  1955. }
  1956. vertexAttributes.push(vertexData.asArray());
  1957. }
  1958. break;
  1959. }
  1960. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  1961. for (var k = 0, length_3 = meshAttributeArray.length / stride; k < length_3; ++k) {
  1962. index = k * stride;
  1963. var vertexData = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index);
  1964. if (this._convertToRightHandedSystem) {
  1965. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(vertexData);
  1966. }
  1967. vertexData.normalize();
  1968. vertexAttributes.push(vertexData.asArray());
  1969. }
  1970. break;
  1971. }
  1972. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  1973. for (var k = 0, length_4 = meshAttributeArray.length / stride; k < length_4; ++k) {
  1974. index = k * stride;
  1975. var vertexData = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index);
  1976. if (this._convertToRightHandedSystem) {
  1977. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedVector4FromRef(vertexData);
  1978. }
  1979. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._NormalizeTangentFromRef(vertexData);
  1980. vertexAttributes.push(vertexData.asArray());
  1981. }
  1982. break;
  1983. }
  1984. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  1985. for (var k = 0, length_5 = meshAttributeArray.length / stride; k < length_5; ++k) {
  1986. index = k * stride;
  1987. var vertexData = stride === 3 ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index);
  1988. vertexAttributes.push(vertexData.asArray());
  1989. }
  1990. break;
  1991. }
  1992. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  1993. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  1994. for (var k = 0, length_6 = meshAttributeArray.length / stride; k < length_6; ++k) {
  1995. index = k * stride;
  1996. vertexAttributes.push(this._convertToRightHandedSystem ? [meshAttributeArray[index], meshAttributeArray[index + 1]] : [meshAttributeArray[index], meshAttributeArray[index + 1]]);
  1997. }
  1998. break;
  1999. }
  2000. default: {
  2001. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
  2002. vertexAttributes = [];
  2003. }
  2004. }
  2005. for (var _i = 0, vertexAttributes_1 = vertexAttributes; _i < vertexAttributes_1.length; _i++) {
  2006. var vertexAttribute = vertexAttributes_1[_i];
  2007. for (var _a = 0, vertexAttribute_1 = vertexAttribute; _a < vertexAttribute_1.length; _a++) {
  2008. var component = vertexAttribute_1[_a];
  2009. binaryWriter.setFloat32(component);
  2010. }
  2011. }
  2012. };
  2013. /**
  2014. * Generates glTF json data
  2015. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  2016. * @param glTFPrefix Text to use when prefixing a glTF file
  2017. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  2018. * @returns json data as string
  2019. */
  2020. _Exporter.prototype.generateJSON = function (shouldUseGlb, glTFPrefix, prettyPrint) {
  2021. var _this = this;
  2022. var buffer = { byteLength: this._totalByteLength };
  2023. var imageName;
  2024. var imageData;
  2025. var bufferView;
  2026. var byteOffset = this._totalByteLength;
  2027. if (buffer.byteLength) {
  2028. this._glTF.buffers = [buffer];
  2029. }
  2030. if (this._nodes && this._nodes.length) {
  2031. this._glTF.nodes = this._nodes;
  2032. }
  2033. if (this._meshes && this._meshes.length) {
  2034. this._glTF.meshes = this._meshes;
  2035. }
  2036. if (this._scenes && this._scenes.length) {
  2037. this._glTF.scenes = this._scenes;
  2038. this._glTF.scene = 0;
  2039. }
  2040. if (this._bufferViews && this._bufferViews.length) {
  2041. this._glTF.bufferViews = this._bufferViews;
  2042. }
  2043. if (this._accessors && this._accessors.length) {
  2044. this._glTF.accessors = this._accessors;
  2045. }
  2046. if (this._animations && this._animations.length) {
  2047. this._glTF.animations = this._animations;
  2048. }
  2049. if (this._materials && this._materials.length) {
  2050. this._glTF.materials = this._materials;
  2051. }
  2052. if (this._textures && this._textures.length) {
  2053. this._glTF.textures = this._textures;
  2054. }
  2055. if (this._samplers && this._samplers.length) {
  2056. this._glTF.samplers = this._samplers;
  2057. }
  2058. if (this._images && this._images.length) {
  2059. if (!shouldUseGlb) {
  2060. this._glTF.images = this._images;
  2061. }
  2062. else {
  2063. this._glTF.images = [];
  2064. this._images.forEach(function (image) {
  2065. if (image.uri) {
  2066. imageData = _this._imageData[image.uri];
  2067. imageName = image.uri.split('.')[0] + " image";
  2068. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, byteOffset, imageData.data.length, undefined, imageName);
  2069. byteOffset += imageData.data.buffer.byteLength;
  2070. _this._bufferViews.push(bufferView);
  2071. image.bufferView = _this._bufferViews.length - 1;
  2072. image.name = imageName;
  2073. image.mimeType = imageData.mimeType;
  2074. image.uri = undefined;
  2075. if (!_this._glTF.images) {
  2076. _this._glTF.images = [];
  2077. }
  2078. _this._glTF.images.push(image);
  2079. }
  2080. });
  2081. // Replace uri with bufferview and mime type for glb
  2082. buffer.byteLength = byteOffset;
  2083. }
  2084. }
  2085. if (!shouldUseGlb) {
  2086. buffer.uri = glTFPrefix + ".bin";
  2087. }
  2088. var jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);
  2089. return jsonText;
  2090. };
  2091. /**
  2092. * Generates data for .gltf and .bin files based on the glTF prefix string
  2093. * @param glTFPrefix Text to use when prefixing a glTF file
  2094. * @param dispose Dispose the exporter
  2095. * @returns GLTFData with glTF file data
  2096. */
  2097. _Exporter.prototype._generateGLTFAsync = function (glTFPrefix, dispose) {
  2098. var _this = this;
  2099. if (dispose === void 0) { dispose = true; }
  2100. return this._generateBinaryAsync().then(function (binaryBuffer) {
  2101. _this._extensionsOnExporting();
  2102. var jsonText = _this.generateJSON(false, glTFPrefix, true);
  2103. var bin = new Blob([binaryBuffer], { type: 'application/octet-stream' });
  2104. var glTFFileName = glTFPrefix + '.gltf';
  2105. var glTFBinFile = glTFPrefix + '.bin';
  2106. var container = new _glTFData__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]();
  2107. container.glTFFiles[glTFFileName] = jsonText;
  2108. container.glTFFiles[glTFBinFile] = bin;
  2109. if (_this._imageData) {
  2110. for (var image in _this._imageData) {
  2111. container.glTFFiles[image] = new Blob([_this._imageData[image].data], { type: _this._imageData[image].mimeType });
  2112. }
  2113. }
  2114. if (dispose) {
  2115. _this.dispose();
  2116. }
  2117. return container;
  2118. });
  2119. };
  2120. /**
  2121. * Creates a binary buffer for glTF
  2122. * @returns array buffer for binary data
  2123. */
  2124. _Exporter.prototype._generateBinaryAsync = function () {
  2125. var _this = this;
  2126. var binaryWriter = new _BinaryWriter(4);
  2127. return this.createSceneAsync(this._babylonScene, binaryWriter).then(function () {
  2128. if (_this._localEngine) {
  2129. _this._localEngine.dispose();
  2130. }
  2131. return binaryWriter.getArrayBuffer();
  2132. });
  2133. };
  2134. /**
  2135. * Pads the number to a multiple of 4
  2136. * @param num number to pad
  2137. * @returns padded number
  2138. */
  2139. _Exporter.prototype._getPadding = function (num) {
  2140. var remainder = num % 4;
  2141. var padding = remainder === 0 ? remainder : 4 - remainder;
  2142. return padding;
  2143. };
  2144. /**
  2145. * @hidden
  2146. */
  2147. _Exporter.prototype._generateGLBAsync = function (glTFPrefix, dispose) {
  2148. var _this = this;
  2149. if (dispose === void 0) { dispose = true; }
  2150. return this._generateBinaryAsync().then(function (binaryBuffer) {
  2151. _this._extensionsOnExporting();
  2152. var jsonText = _this.generateJSON(true);
  2153. var glbFileName = glTFPrefix + '.glb';
  2154. var headerLength = 12;
  2155. var chunkLengthPrefix = 8;
  2156. var jsonLength = jsonText.length;
  2157. var imageByteLength = 0;
  2158. for (var key in _this._imageData) {
  2159. imageByteLength += _this._imageData[key].data.byteLength;
  2160. }
  2161. var jsonPadding = _this._getPadding(jsonLength);
  2162. var binPadding = _this._getPadding(binaryBuffer.byteLength);
  2163. var imagePadding = _this._getPadding(imageByteLength);
  2164. var byteLength = headerLength + (2 * chunkLengthPrefix) + jsonLength + jsonPadding + binaryBuffer.byteLength + binPadding + imageByteLength + imagePadding;
  2165. //header
  2166. var headerBuffer = new ArrayBuffer(headerLength);
  2167. var headerBufferView = new DataView(headerBuffer);
  2168. headerBufferView.setUint32(0, 0x46546C67, true); //glTF
  2169. headerBufferView.setUint32(4, 2, true); // version
  2170. headerBufferView.setUint32(8, byteLength, true); // total bytes in file
  2171. //json chunk
  2172. var jsonChunkBuffer = new ArrayBuffer(chunkLengthPrefix + jsonLength + jsonPadding);
  2173. var jsonChunkBufferView = new DataView(jsonChunkBuffer);
  2174. jsonChunkBufferView.setUint32(0, jsonLength + jsonPadding, true);
  2175. jsonChunkBufferView.setUint32(4, 0x4E4F534A, true);
  2176. //json chunk bytes
  2177. var jsonData = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix);
  2178. for (var i = 0; i < jsonLength; ++i) {
  2179. jsonData[i] = jsonText.charCodeAt(i);
  2180. }
  2181. //json padding
  2182. var jsonPaddingView = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix + jsonLength);
  2183. for (var i = 0; i < jsonPadding; ++i) {
  2184. jsonPaddingView[i] = 0x20;
  2185. }
  2186. //binary chunk
  2187. var binaryChunkBuffer = new ArrayBuffer(chunkLengthPrefix);
  2188. var binaryChunkBufferView = new DataView(binaryChunkBuffer);
  2189. binaryChunkBufferView.setUint32(0, binaryBuffer.byteLength + imageByteLength + imagePadding, true);
  2190. binaryChunkBufferView.setUint32(4, 0x004E4942, true);
  2191. // binary padding
  2192. var binPaddingBuffer = new ArrayBuffer(binPadding);
  2193. var binPaddingView = new Uint8Array(binPaddingBuffer);
  2194. for (var i = 0; i < binPadding; ++i) {
  2195. binPaddingView[i] = 0;
  2196. }
  2197. var imagePaddingBuffer = new ArrayBuffer(imagePadding);
  2198. var imagePaddingView = new Uint8Array(imagePaddingBuffer);
  2199. for (var i = 0; i < imagePadding; ++i) {
  2200. imagePaddingView[i] = 0;
  2201. }
  2202. var glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];
  2203. // binary data
  2204. for (var key in _this._imageData) {
  2205. glbData.push(_this._imageData[key].data.buffer);
  2206. }
  2207. glbData.push(binPaddingBuffer);
  2208. glbData.push(imagePaddingBuffer);
  2209. var glbFile = new Blob(glbData, { type: 'application/octet-stream' });
  2210. var container = new _glTFData__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]();
  2211. container.glTFFiles[glbFileName] = glbFile;
  2212. if (_this._localEngine != null) {
  2213. _this._localEngine.dispose();
  2214. }
  2215. if (dispose) {
  2216. _this.dispose();
  2217. }
  2218. return container;
  2219. });
  2220. };
  2221. /**
  2222. * Sets the TRS for each node
  2223. * @param node glTF Node for storing the transformation data
  2224. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  2225. */
  2226. _Exporter.prototype.setNodeTransformation = function (node, babylonTransformNode) {
  2227. if (!babylonTransformNode.getPivotPoint().equalsToFloats(0, 0, 0)) {
  2228. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Pivot points are not supported in the glTF serializer");
  2229. }
  2230. if (!babylonTransformNode.position.equalsToFloats(0, 0, 0)) {
  2231. node.translation = this._convertToRightHandedSystem ? _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3(babylonTransformNode.position).asArray() : babylonTransformNode.position.asArray();
  2232. }
  2233. if (!babylonTransformNode.scaling.equalsToFloats(1, 1, 1)) {
  2234. node.scale = babylonTransformNode.scaling.asArray();
  2235. }
  2236. var rotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].RotationYawPitchRoll(babylonTransformNode.rotation.y, babylonTransformNode.rotation.x, babylonTransformNode.rotation.z);
  2237. if (babylonTransformNode.rotationQuaternion) {
  2238. rotationQuaternion.multiplyInPlace(babylonTransformNode.rotationQuaternion);
  2239. }
  2240. if (!(rotationQuaternion.x === 0 && rotationQuaternion.y === 0 && rotationQuaternion.z === 0 && rotationQuaternion.w === 1)) {
  2241. if (this._convertToRightHandedSystem) {
  2242. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(rotationQuaternion);
  2243. }
  2244. node.rotation = rotationQuaternion.normalize().asArray();
  2245. }
  2246. };
  2247. _Exporter.prototype.getVertexBufferFromMesh = function (attributeKind, bufferMesh) {
  2248. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  2249. var vertexBuffer = bufferMesh.getVertexBuffer(attributeKind);
  2250. if (vertexBuffer) {
  2251. return vertexBuffer;
  2252. }
  2253. }
  2254. return null;
  2255. };
  2256. /**
  2257. * Creates a bufferview based on the vertices type for the Babylon mesh
  2258. * @param kind Indicates the type of vertices data
  2259. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  2260. * @param binaryWriter The buffer to write the bufferview data to
  2261. */
  2262. _Exporter.prototype.createBufferViewKind = function (kind, babylonTransformNode, binaryWriter, byteStride) {
  2263. var bufferMesh = babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"] ?
  2264. babylonTransformNode : babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["InstancedMesh"] ?
  2265. babylonTransformNode.sourceMesh : null;
  2266. if (bufferMesh) {
  2267. var vertexData = bufferMesh.getVerticesData(kind);
  2268. if (vertexData) {
  2269. var byteLength = vertexData.length * 4;
  2270. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, kind + " - " + bufferMesh.name);
  2271. this._bufferViews.push(bufferView);
  2272. this.writeAttributeData(kind, vertexData, byteStride, binaryWriter);
  2273. }
  2274. }
  2275. };
  2276. /**
  2277. * The primitive mode of the Babylon mesh
  2278. * @param babylonMesh The BabylonJS mesh
  2279. */
  2280. _Exporter.prototype.getMeshPrimitiveMode = function (babylonMesh) {
  2281. if (babylonMesh instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["LinesMesh"]) {
  2282. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].LineListDrawMode;
  2283. }
  2284. return babylonMesh.material ? babylonMesh.material.fillMode : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode;
  2285. };
  2286. /**
  2287. * Sets the primitive mode of the glTF mesh primitive
  2288. * @param meshPrimitive glTF mesh primitive
  2289. * @param primitiveMode The primitive mode
  2290. */
  2291. _Exporter.prototype.setPrimitiveMode = function (meshPrimitive, primitiveMode) {
  2292. switch (primitiveMode) {
  2293. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode: {
  2294. // glTF defaults to using Triangle Mode
  2295. break;
  2296. }
  2297. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleStripDrawMode: {
  2298. meshPrimitive.mode = 5 /* TRIANGLE_STRIP */;
  2299. break;
  2300. }
  2301. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFanDrawMode: {
  2302. meshPrimitive.mode = 6 /* TRIANGLE_FAN */;
  2303. break;
  2304. }
  2305. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].PointListDrawMode: {
  2306. meshPrimitive.mode = 0 /* POINTS */;
  2307. }
  2308. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].PointFillMode: {
  2309. meshPrimitive.mode = 0 /* POINTS */;
  2310. break;
  2311. }
  2312. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].LineLoopDrawMode: {
  2313. meshPrimitive.mode = 2 /* LINE_LOOP */;
  2314. break;
  2315. }
  2316. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].LineListDrawMode: {
  2317. meshPrimitive.mode = 1 /* LINES */;
  2318. break;
  2319. }
  2320. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].LineStripDrawMode: {
  2321. meshPrimitive.mode = 3 /* LINE_STRIP */;
  2322. break;
  2323. }
  2324. }
  2325. };
  2326. /**
  2327. * Sets the vertex attribute accessor based of the glTF mesh primitive
  2328. * @param meshPrimitive glTF mesh primitive
  2329. * @param attributeKind vertex attribute
  2330. * @returns boolean specifying if uv coordinates are present
  2331. */
  2332. _Exporter.prototype.setAttributeKind = function (meshPrimitive, attributeKind) {
  2333. switch (attributeKind) {
  2334. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind: {
  2335. meshPrimitive.attributes.POSITION = this._accessors.length - 1;
  2336. break;
  2337. }
  2338. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  2339. meshPrimitive.attributes.NORMAL = this._accessors.length - 1;
  2340. break;
  2341. }
  2342. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  2343. meshPrimitive.attributes.COLOR_0 = this._accessors.length - 1;
  2344. break;
  2345. }
  2346. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  2347. meshPrimitive.attributes.TANGENT = this._accessors.length - 1;
  2348. break;
  2349. }
  2350. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind: {
  2351. meshPrimitive.attributes.TEXCOORD_0 = this._accessors.length - 1;
  2352. break;
  2353. }
  2354. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  2355. meshPrimitive.attributes.TEXCOORD_1 = this._accessors.length - 1;
  2356. break;
  2357. }
  2358. default: {
  2359. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Vertex Buffer Type: " + attributeKind);
  2360. }
  2361. }
  2362. };
  2363. /**
  2364. * Sets data for the primitive attributes of each submesh
  2365. * @param mesh glTF Mesh object to store the primitive attribute information
  2366. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  2367. * @param binaryWriter Buffer to write the attribute data to
  2368. */
  2369. _Exporter.prototype.setPrimitiveAttributesAsync = function (mesh, babylonTransformNode, binaryWriter) {
  2370. var promises = [];
  2371. var bufferMesh = null;
  2372. var bufferView;
  2373. var minMax;
  2374. if (babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  2375. bufferMesh = babylonTransformNode;
  2376. }
  2377. else if (babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["InstancedMesh"]) {
  2378. bufferMesh = babylonTransformNode.sourceMesh;
  2379. }
  2380. var attributeData = [
  2381. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind, accessorType: "VEC3" /* VEC3 */, byteStride: 12 },
  2382. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind, accessorType: "VEC3" /* VEC3 */, byteStride: 12 },
  2383. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind, accessorType: "VEC4" /* VEC4 */, byteStride: 16 },
  2384. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind, accessorType: "VEC4" /* VEC4 */, byteStride: 16 },
  2385. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind, accessorType: "VEC2" /* VEC2 */, byteStride: 8 },
  2386. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind, accessorType: "VEC2" /* VEC2 */, byteStride: 8 },
  2387. ];
  2388. if (bufferMesh) {
  2389. var indexBufferViewIndex = null;
  2390. var primitiveMode = this.getMeshPrimitiveMode(bufferMesh);
  2391. var vertexAttributeBufferViews = {};
  2392. // For each BabylonMesh, create bufferviews for each 'kind'
  2393. for (var _i = 0, attributeData_1 = attributeData; _i < attributeData_1.length; _i++) {
  2394. var attribute = attributeData_1[_i];
  2395. var attributeKind = attribute.kind;
  2396. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  2397. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  2398. attribute.byteStride = vertexBuffer ? vertexBuffer.getSize() * 4 : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].DeduceStride(attributeKind) * 4;
  2399. if (attribute.byteStride === 12) {
  2400. attribute.accessorType = "VEC3" /* VEC3 */;
  2401. }
  2402. this.createBufferViewKind(attributeKind, babylonTransformNode, binaryWriter, attribute.byteStride);
  2403. attribute.bufferViewIndex = this._bufferViews.length - 1;
  2404. vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;
  2405. }
  2406. }
  2407. if (bufferMesh.getTotalIndices()) {
  2408. var indices = bufferMesh.getIndices();
  2409. if (indices) {
  2410. var byteLength = indices.length * 4;
  2411. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "Indices - " + bufferMesh.name);
  2412. this._bufferViews.push(bufferView);
  2413. indexBufferViewIndex = this._bufferViews.length - 1;
  2414. for (var k = 0, length_7 = indices.length; k < length_7; ++k) {
  2415. binaryWriter.setUInt32(indices[k]);
  2416. }
  2417. }
  2418. }
  2419. if (bufferMesh.subMeshes) {
  2420. // go through all mesh primitives (submeshes)
  2421. for (var _a = 0, _b = bufferMesh.subMeshes; _a < _b.length; _a++) {
  2422. var submesh = _b[_a];
  2423. var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
  2424. var materialIndex = null;
  2425. if (babylonMaterial) {
  2426. if (bufferMesh instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["LinesMesh"]) {
  2427. // get the color from the lines mesh and set it in the material
  2428. var material = {
  2429. name: bufferMesh.name + ' material'
  2430. };
  2431. if (!bufferMesh.color.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Color3"].White()) || bufferMesh.alpha < 1) {
  2432. material.pbrMetallicRoughness = {
  2433. baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha])
  2434. };
  2435. }
  2436. this._materials.push(material);
  2437. materialIndex = this._materials.length - 1;
  2438. }
  2439. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]) {
  2440. var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
  2441. if (subMaterial) {
  2442. babylonMaterial = subMaterial;
  2443. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  2444. }
  2445. }
  2446. else {
  2447. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  2448. }
  2449. }
  2450. var glTFMaterial = materialIndex != null ? this._materials[materialIndex] : null;
  2451. var meshPrimitive = { attributes: {} };
  2452. this.setPrimitiveMode(meshPrimitive, primitiveMode);
  2453. for (var _c = 0, attributeData_2 = attributeData; _c < attributeData_2.length; _c++) {
  2454. var attribute = attributeData_2[_c];
  2455. var attributeKind = attribute.kind;
  2456. if (attributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind || attributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind) {
  2457. if (glTFMaterial && !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
  2458. continue;
  2459. }
  2460. }
  2461. var vertexData = bufferMesh.getVerticesData(attributeKind);
  2462. if (vertexData) {
  2463. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  2464. if (vertexBuffer) {
  2465. var stride = vertexBuffer.getSize();
  2466. var bufferViewIndex = attribute.bufferViewIndex;
  2467. if (bufferViewIndex != undefined) { // check to see if bufferviewindex has a numeric value assigned.
  2468. minMax = { min: null, max: null };
  2469. if (attributeKind == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind) {
  2470. minMax = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride, this._convertToRightHandedSystem);
  2471. }
  2472. var accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(bufferViewIndex, attributeKind + " - " + babylonTransformNode.name, attribute.accessorType, 5126 /* FLOAT */, vertexData.length / stride, 0, minMax.min, minMax.max);
  2473. this._accessors.push(accessor);
  2474. this.setAttributeKind(meshPrimitive, attributeKind);
  2475. }
  2476. }
  2477. }
  2478. }
  2479. if (indexBufferViewIndex) {
  2480. // Create accessor
  2481. var accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(indexBufferViewIndex, "indices - " + babylonTransformNode.name, "SCALAR" /* SCALAR */, 5125 /* UNSIGNED_INT */, submesh.indexCount, submesh.indexStart * 4, null, null);
  2482. this._accessors.push(accessor);
  2483. meshPrimitive.indices = this._accessors.length - 1;
  2484. }
  2485. if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
  2486. var sideOrientation = bufferMesh.overrideMaterialSideOrientation !== null ? bufferMesh.overrideMaterialSideOrientation : babylonMaterial.sideOrientation;
  2487. // Only reverse the winding if we have a clockwise winding
  2488. if (sideOrientation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Material"].ClockWiseSideOrientation) {
  2489. var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
  2490. if (byteOffset == null) {
  2491. byteOffset = 0;
  2492. }
  2493. var babylonIndices = null;
  2494. if (indexBufferViewIndex != null) {
  2495. babylonIndices = bufferMesh.getIndices();
  2496. }
  2497. if (babylonIndices) {
  2498. this.reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
  2499. }
  2500. else {
  2501. for (var _d = 0, attributeData_3 = attributeData; _d < attributeData_3.length; _d++) {
  2502. var attribute = attributeData_3[_d];
  2503. var vertexData = bufferMesh.getVerticesData(attribute.kind);
  2504. if (vertexData) {
  2505. var byteOffset_1 = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset;
  2506. if (!byteOffset_1) {
  2507. byteOffset_1 = 0;
  2508. }
  2509. this.reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, attribute.kind, vertexData, byteOffset_1, binaryWriter);
  2510. }
  2511. }
  2512. }
  2513. }
  2514. meshPrimitive.material = materialIndex;
  2515. }
  2516. mesh.primitives.push(meshPrimitive);
  2517. var promise = this._extensionsPostExportMeshPrimitiveAsync("postExport", meshPrimitive, submesh, binaryWriter);
  2518. if (promise) {
  2519. promises.push();
  2520. }
  2521. }
  2522. }
  2523. }
  2524. return Promise.all(promises).then(function () {
  2525. /* do nothing */
  2526. });
  2527. };
  2528. /**
  2529. * Creates a glTF scene based on the array of meshes
  2530. * Returns the the total byte offset
  2531. * @param babylonScene Babylon scene to get the mesh data from
  2532. * @param binaryWriter Buffer to write binary data to
  2533. */
  2534. _Exporter.prototype.createSceneAsync = function (babylonScene, binaryWriter) {
  2535. var _this = this;
  2536. var scene = { nodes: [] };
  2537. var glTFNodeIndex;
  2538. var glTFNode;
  2539. var directDescendents;
  2540. var nodes = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__spreadArrays"])(babylonScene.transformNodes, babylonScene.meshes, babylonScene.lights);
  2541. return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
  2542. return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, binaryWriter).then(function (nodeMap) {
  2543. _this._nodeMap = nodeMap;
  2544. _this._totalByteLength = binaryWriter.getByteOffset();
  2545. if (_this._totalByteLength == undefined) {
  2546. throw new Error("undefined byte length!");
  2547. }
  2548. // Build Hierarchy with the node map.
  2549. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2550. var babylonNode = nodes_1[_i];
  2551. glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
  2552. if (glTFNodeIndex !== undefined) {
  2553. glTFNode = _this._nodes[glTFNodeIndex];
  2554. if (babylonNode.metadata) {
  2555. if (_this._options.metadataSelector) {
  2556. glTFNode.extras = _this._options.metadataSelector(babylonNode.metadata);
  2557. }
  2558. else if (babylonNode.metadata.gltf) {
  2559. glTFNode.extras = babylonNode.metadata.gltf.extras;
  2560. }
  2561. }
  2562. if (!babylonNode.parent) {
  2563. if (_this._options.shouldExportNode && !_this._options.shouldExportNode(babylonNode)) {
  2564. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Log("Omitting " + babylonNode.name + " from scene.");
  2565. }
  2566. else {
  2567. if (_this._convertToRightHandedSystem) {
  2568. if (glTFNode.translation) {
  2569. glTFNode.translation[2] *= -1;
  2570. glTFNode.translation[0] *= -1;
  2571. }
  2572. glTFNode.rotation = glTFNode.rotation ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray(glTFNode.rotation)).asArray() : (babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromArray([0, 1, 0, 0])).asArray();
  2573. }
  2574. scene.nodes.push(glTFNodeIndex);
  2575. }
  2576. }
  2577. directDescendents = babylonNode.getDescendants(true);
  2578. if (!glTFNode.children && directDescendents && directDescendents.length) {
  2579. var children = [];
  2580. for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
  2581. var descendent = directDescendents_1[_a];
  2582. if (_this._nodeMap[descendent.uniqueId] != null) {
  2583. children.push(_this._nodeMap[descendent.uniqueId]);
  2584. }
  2585. }
  2586. if (children.length) {
  2587. glTFNode.children = children;
  2588. }
  2589. }
  2590. }
  2591. }
  2592. if (scene.nodes.length) {
  2593. _this._scenes.push(scene);
  2594. }
  2595. });
  2596. });
  2597. };
  2598. /**
  2599. * Creates a mapping of Node unique id to node index and handles animations
  2600. * @param babylonScene Babylon Scene
  2601. * @param nodes Babylon transform nodes
  2602. * @param binaryWriter Buffer to write binary data to
  2603. * @returns Node mapping of unique id to index
  2604. */
  2605. _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, binaryWriter) {
  2606. var _this = this;
  2607. var promiseChain = Promise.resolve();
  2608. var nodeMap = {};
  2609. var nodeIndex;
  2610. var runtimeGLTFAnimation = {
  2611. name: 'runtime animations',
  2612. channels: [],
  2613. samplers: []
  2614. };
  2615. var idleGLTFAnimations = [];
  2616. var _loop_1 = function (babylonNode) {
  2617. if (!this_1._options.shouldExportNode || this_1._options.shouldExportNode(babylonNode)) {
  2618. promiseChain = promiseChain.then(function () {
  2619. return _this.createNodeAsync(babylonNode, binaryWriter).then(function (node) {
  2620. var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode);
  2621. if (promise == null) {
  2622. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Not exporting node " + babylonNode.name);
  2623. return Promise.resolve();
  2624. }
  2625. else {
  2626. return promise.then(function (node) {
  2627. if (!node) {
  2628. return;
  2629. }
  2630. _this._nodes.push(node);
  2631. nodeIndex = _this._nodes.length - 1;
  2632. nodeMap[babylonNode.uniqueId] = nodeIndex;
  2633. if (!babylonScene.animationGroups.length && babylonNode.animations.length) {
  2634. _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__["_GLTFAnimation"]._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
  2635. }
  2636. });
  2637. }
  2638. });
  2639. });
  2640. }
  2641. else {
  2642. "Excluding node " + babylonNode.name;
  2643. }
  2644. };
  2645. var this_1 = this;
  2646. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  2647. var babylonNode = nodes_2[_i];
  2648. _loop_1(babylonNode);
  2649. }
  2650. return promiseChain.then(function () {
  2651. if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
  2652. _this._animations.push(runtimeGLTFAnimation);
  2653. }
  2654. idleGLTFAnimations.forEach(function (idleGLTFAnimation) {
  2655. if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {
  2656. _this._animations.push(idleGLTFAnimation);
  2657. }
  2658. });
  2659. if (babylonScene.animationGroups.length) {
  2660. _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__["_GLTFAnimation"]._CreateNodeAnimationFromAnimationGroups(babylonScene, _this._animations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
  2661. }
  2662. return nodeMap;
  2663. });
  2664. };
  2665. /**
  2666. * Creates a glTF node from a Babylon mesh
  2667. * @param babylonMesh Source Babylon mesh
  2668. * @param binaryWriter Buffer for storing geometry data
  2669. * @returns glTF node
  2670. */
  2671. _Exporter.prototype.createNodeAsync = function (babylonNode, binaryWriter) {
  2672. var _this = this;
  2673. return Promise.resolve().then(function () {
  2674. // create node to hold translation/rotation/scale and the mesh
  2675. var node = {};
  2676. // create mesh
  2677. var mesh = { primitives: [] };
  2678. if (babylonNode.name) {
  2679. node.name = babylonNode.name;
  2680. }
  2681. if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["TransformNode"]) {
  2682. // Set transformation
  2683. _this.setNodeTransformation(node, babylonNode);
  2684. return _this.setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(function () {
  2685. if (mesh.primitives.length) {
  2686. _this._meshes.push(mesh);
  2687. node.mesh = _this._meshes.length - 1;
  2688. }
  2689. return node;
  2690. });
  2691. }
  2692. else {
  2693. return node;
  2694. }
  2695. });
  2696. };
  2697. _Exporter._ExtensionNames = new Array();
  2698. _Exporter._ExtensionFactories = {};
  2699. return _Exporter;
  2700. }());
  2701. /**
  2702. * @hidden
  2703. *
  2704. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  2705. */
  2706. var _BinaryWriter = /** @class */ (function () {
  2707. /**
  2708. * Initialize binary writer with an initial byte length
  2709. * @param byteLength Initial byte length of the array buffer
  2710. */
  2711. function _BinaryWriter(byteLength) {
  2712. this._arrayBuffer = new ArrayBuffer(byteLength);
  2713. this._dataView = new DataView(this._arrayBuffer);
  2714. this._byteOffset = 0;
  2715. }
  2716. /**
  2717. * Resize the array buffer to the specified byte length
  2718. * @param byteLength
  2719. */
  2720. _BinaryWriter.prototype.resizeBuffer = function (byteLength) {
  2721. var newBuffer = new ArrayBuffer(byteLength);
  2722. var oldUint8Array = new Uint8Array(this._arrayBuffer);
  2723. var newUint8Array = new Uint8Array(newBuffer);
  2724. for (var i = 0, length_8 = newUint8Array.byteLength; i < length_8; ++i) {
  2725. newUint8Array[i] = oldUint8Array[i];
  2726. }
  2727. this._arrayBuffer = newBuffer;
  2728. this._dataView = new DataView(this._arrayBuffer);
  2729. return newBuffer;
  2730. };
  2731. /**
  2732. * Get an array buffer with the length of the byte offset
  2733. * @returns ArrayBuffer resized to the byte offset
  2734. */
  2735. _BinaryWriter.prototype.getArrayBuffer = function () {
  2736. return this.resizeBuffer(this.getByteOffset());
  2737. };
  2738. /**
  2739. * Get the byte offset of the array buffer
  2740. * @returns byte offset
  2741. */
  2742. _BinaryWriter.prototype.getByteOffset = function () {
  2743. if (this._byteOffset == undefined) {
  2744. throw new Error("Byte offset is undefined!");
  2745. }
  2746. return this._byteOffset;
  2747. };
  2748. /**
  2749. * Stores an UInt8 in the array buffer
  2750. * @param entry
  2751. * @param byteOffset If defined, specifies where to set the value as an offset.
  2752. */
  2753. _BinaryWriter.prototype.setUInt8 = function (entry, byteOffset) {
  2754. if (byteOffset != null) {
  2755. if (byteOffset < this._byteOffset) {
  2756. this._dataView.setUint8(byteOffset, entry);
  2757. }
  2758. else {
  2759. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2760. }
  2761. }
  2762. else {
  2763. if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
  2764. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2765. }
  2766. this._dataView.setUint8(this._byteOffset++, entry);
  2767. }
  2768. };
  2769. /**
  2770. * Gets an UInt32 in the array buffer
  2771. * @param entry
  2772. * @param byteOffset If defined, specifies where to set the value as an offset.
  2773. */
  2774. _BinaryWriter.prototype.getUInt32 = function (byteOffset) {
  2775. if (byteOffset < this._byteOffset) {
  2776. return this._dataView.getUint32(byteOffset, true);
  2777. }
  2778. else {
  2779. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2780. throw new Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2781. }
  2782. };
  2783. _BinaryWriter.prototype.getVector3Float32FromRef = function (vector3, byteOffset) {
  2784. if (byteOffset + 8 > this._byteOffset) {
  2785. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2786. }
  2787. else {
  2788. vector3.x = this._dataView.getFloat32(byteOffset, true);
  2789. vector3.y = this._dataView.getFloat32(byteOffset + 4, true);
  2790. vector3.z = this._dataView.getFloat32(byteOffset + 8, true);
  2791. }
  2792. };
  2793. _BinaryWriter.prototype.setVector3Float32FromRef = function (vector3, byteOffset) {
  2794. if (byteOffset + 8 > this._byteOffset) {
  2795. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2796. }
  2797. else {
  2798. this._dataView.setFloat32(byteOffset, vector3.x, true);
  2799. this._dataView.setFloat32(byteOffset + 4, vector3.y, true);
  2800. this._dataView.setFloat32(byteOffset + 8, vector3.z, true);
  2801. }
  2802. };
  2803. _BinaryWriter.prototype.getVector4Float32FromRef = function (vector4, byteOffset) {
  2804. if (byteOffset + 12 > this._byteOffset) {
  2805. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2806. }
  2807. else {
  2808. vector4.x = this._dataView.getFloat32(byteOffset, true);
  2809. vector4.y = this._dataView.getFloat32(byteOffset + 4, true);
  2810. vector4.z = this._dataView.getFloat32(byteOffset + 8, true);
  2811. vector4.w = this._dataView.getFloat32(byteOffset + 12, true);
  2812. }
  2813. };
  2814. _BinaryWriter.prototype.setVector4Float32FromRef = function (vector4, byteOffset) {
  2815. if (byteOffset + 12 > this._byteOffset) {
  2816. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2817. }
  2818. else {
  2819. this._dataView.setFloat32(byteOffset, vector4.x, true);
  2820. this._dataView.setFloat32(byteOffset + 4, vector4.y, true);
  2821. this._dataView.setFloat32(byteOffset + 8, vector4.z, true);
  2822. this._dataView.setFloat32(byteOffset + 12, vector4.w, true);
  2823. }
  2824. };
  2825. /**
  2826. * Stores a Float32 in the array buffer
  2827. * @param entry
  2828. */
  2829. _BinaryWriter.prototype.setFloat32 = function (entry, byteOffset) {
  2830. if (isNaN(entry)) {
  2831. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('Invalid data being written!');
  2832. }
  2833. if (byteOffset != null) {
  2834. if (byteOffset < this._byteOffset) {
  2835. this._dataView.setFloat32(byteOffset, entry, true);
  2836. }
  2837. else {
  2838. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary length!');
  2839. }
  2840. }
  2841. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  2842. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2843. }
  2844. this._dataView.setFloat32(this._byteOffset, entry, true);
  2845. this._byteOffset += 4;
  2846. };
  2847. /**
  2848. * Stores an UInt32 in the array buffer
  2849. * @param entry
  2850. * @param byteOffset If defined, specifies where to set the value as an offset.
  2851. */
  2852. _BinaryWriter.prototype.setUInt32 = function (entry, byteOffset) {
  2853. if (byteOffset != null) {
  2854. if (byteOffset < this._byteOffset) {
  2855. this._dataView.setUint32(byteOffset, entry, true);
  2856. }
  2857. else {
  2858. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2859. }
  2860. }
  2861. else {
  2862. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  2863. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2864. }
  2865. this._dataView.setUint32(this._byteOffset, entry, true);
  2866. this._byteOffset += 4;
  2867. }
  2868. };
  2869. return _BinaryWriter;
  2870. }());
  2871. /***/ }),
  2872. /***/ "./glTF/2.0/glTFExporterExtension.ts":
  2873. /*!*******************************************!*\
  2874. !*** ./glTF/2.0/glTFExporterExtension.ts ***!
  2875. \*******************************************/
  2876. /*! exports provided: __IGLTFExporterExtensionV2 */
  2877. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2878. "use strict";
  2879. __webpack_require__.r(__webpack_exports__);
  2880. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return __IGLTFExporterExtensionV2; });
  2881. /** @hidden */
  2882. var __IGLTFExporterExtensionV2 = 0; // I am here to allow dts to be created
  2883. /***/ }),
  2884. /***/ "./glTF/2.0/glTFMaterialExporter.ts":
  2885. /*!******************************************!*\
  2886. !*** ./glTF/2.0/glTFMaterialExporter.ts ***!
  2887. \******************************************/
  2888. /*! exports provided: _GLTFMaterialExporter */
  2889. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2890. "use strict";
  2891. __webpack_require__.r(__webpack_exports__);
  2892. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _GLTFMaterialExporter; });
  2893. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  2894. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  2895. /**
  2896. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  2897. * @hidden
  2898. */
  2899. var _GLTFMaterialExporter = /** @class */ (function () {
  2900. function _GLTFMaterialExporter(exporter) {
  2901. /**
  2902. * Mapping to store textures
  2903. */
  2904. this._textureMap = {};
  2905. this._textureMap = {};
  2906. this._exporter = exporter;
  2907. }
  2908. /**
  2909. * Specifies if two colors are approximately equal in value
  2910. * @param color1 first color to compare to
  2911. * @param color2 second color to compare to
  2912. * @param epsilon threshold value
  2913. */
  2914. _GLTFMaterialExporter.FuzzyEquals = function (color1, color2, epsilon) {
  2915. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.r, color2.r, epsilon) &&
  2916. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.g, color2.g, epsilon) &&
  2917. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.b, color2.b, epsilon);
  2918. };
  2919. /**
  2920. * Gets the materials from a Babylon scene and converts them to glTF materials
  2921. * @param scene babylonjs scene
  2922. * @param mimeType texture mime type
  2923. * @param images array of images
  2924. * @param textures array of textures
  2925. * @param materials array of materials
  2926. * @param imageData mapping of texture names to base64 textures
  2927. * @param hasTextureCoords specifies if texture coordinates are present on the material
  2928. */
  2929. _GLTFMaterialExporter.prototype._convertMaterialsToGLTFAsync = function (babylonMaterials, mimeType, hasTextureCoords) {
  2930. var promises = [];
  2931. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  2932. var babylonMaterial = babylonMaterials_1[_i];
  2933. if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"]) {
  2934. promises.push(this._convertStandardMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2935. }
  2936. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMetallicRoughnessMaterial"]) {
  2937. promises.push(this._convertPBRMetallicRoughnessMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2938. }
  2939. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"]) {
  2940. promises.push(this._convertPBRMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2941. }
  2942. else {
  2943. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unsupported material type: " + babylonMaterial.name);
  2944. }
  2945. }
  2946. return Promise.all(promises).then(function () { });
  2947. };
  2948. /**
  2949. * Makes a copy of the glTF material without the texture parameters
  2950. * @param originalMaterial original glTF material
  2951. * @returns glTF material without texture parameters
  2952. */
  2953. _GLTFMaterialExporter.prototype._stripTexturesFromMaterial = function (originalMaterial) {
  2954. var newMaterial = {};
  2955. if (originalMaterial) {
  2956. newMaterial.name = originalMaterial.name;
  2957. newMaterial.doubleSided = originalMaterial.doubleSided;
  2958. newMaterial.alphaMode = originalMaterial.alphaMode;
  2959. newMaterial.alphaCutoff = originalMaterial.alphaCutoff;
  2960. newMaterial.emissiveFactor = originalMaterial.emissiveFactor;
  2961. var originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;
  2962. if (originalPBRMetallicRoughness) {
  2963. newMaterial.pbrMetallicRoughness = {};
  2964. newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;
  2965. newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;
  2966. newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;
  2967. }
  2968. }
  2969. return newMaterial;
  2970. };
  2971. /**
  2972. * Specifies if the material has any texture parameters present
  2973. * @param material glTF Material
  2974. * @returns boolean specifying if texture parameters are present
  2975. */
  2976. _GLTFMaterialExporter.prototype._hasTexturesPresent = function (material) {
  2977. if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {
  2978. return true;
  2979. }
  2980. var pbrMat = material.pbrMetallicRoughness;
  2981. if (pbrMat) {
  2982. if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {
  2983. return true;
  2984. }
  2985. }
  2986. return false;
  2987. };
  2988. /**
  2989. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  2990. * @param babylonStandardMaterial
  2991. * @returns glTF Metallic Roughness Material representation
  2992. */
  2993. _GLTFMaterialExporter.prototype._convertToGLTFPBRMetallicRoughness = function (babylonStandardMaterial) {
  2994. var P0 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 1);
  2995. var P1 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 0.1);
  2996. var P2 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 0.1);
  2997. var P3 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1300, 0.1);
  2998. /**
  2999. * Given the control points, solve for x based on a given t for a cubic bezier curve
  3000. * @param t a value between 0 and 1
  3001. * @param p0 first control point
  3002. * @param p1 second control point
  3003. * @param p2 third control point
  3004. * @param p3 fourth control point
  3005. * @returns number result of cubic bezier curve at the specified t
  3006. */
  3007. function _cubicBezierCurve(t, p0, p1, p2, p3) {
  3008. return ((1 - t) * (1 - t) * (1 - t) * p0 +
  3009. 3 * (1 - t) * (1 - t) * t * p1 +
  3010. 3 * (1 - t) * t * t * p2 +
  3011. t * t * t * p3);
  3012. }
  3013. /**
  3014. * Evaluates a specified specular power value to determine the appropriate roughness value,
  3015. * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)
  3016. * and roughness on the ordinant axis (y-axis)
  3017. * @param specularPower specular power of standard material
  3018. * @returns Number representing the roughness value
  3019. */
  3020. function _solveForRoughness(specularPower) {
  3021. var t = Math.pow(specularPower / P3.x, 0.333333);
  3022. return _cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);
  3023. }
  3024. var diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace().scale(0.5);
  3025. var opacity = babylonStandardMaterial.alpha;
  3026. var specularPower = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);
  3027. var roughness = _solveForRoughness(specularPower);
  3028. var glTFPbrMetallicRoughness = {
  3029. baseColorFactor: [
  3030. diffuse.r,
  3031. diffuse.g,
  3032. diffuse.b,
  3033. opacity
  3034. ],
  3035. metallicFactor: 0,
  3036. roughnessFactor: roughness,
  3037. };
  3038. return glTFPbrMetallicRoughness;
  3039. };
  3040. /**
  3041. * Computes the metallic factor
  3042. * @param diffuse diffused value
  3043. * @param specular specular value
  3044. * @param oneMinusSpecularStrength one minus the specular strength
  3045. * @returns metallic value
  3046. */
  3047. _GLTFMaterialExporter._SolveMetallic = function (diffuse, specular, oneMinusSpecularStrength) {
  3048. if (specular < this._DielectricSpecular.r) {
  3049. this._DielectricSpecular;
  3050. return 0;
  3051. }
  3052. var a = this._DielectricSpecular.r;
  3053. var b = diffuse * oneMinusSpecularStrength / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;
  3054. var c = this._DielectricSpecular.r - specular;
  3055. var D = b * b - 4.0 * a * c;
  3056. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);
  3057. };
  3058. /**
  3059. * Sets the glTF alpha mode to a glTF material from the Babylon Material
  3060. * @param glTFMaterial glTF material
  3061. * @param babylonMaterial Babylon material
  3062. */
  3063. _GLTFMaterialExporter._SetAlphaMode = function (glTFMaterial, babylonMaterial) {
  3064. if (babylonMaterial.needAlphaBlending()) {
  3065. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  3066. }
  3067. else if (babylonMaterial.needAlphaTesting()) {
  3068. glTFMaterial.alphaMode = "MASK" /* MASK */;
  3069. glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;
  3070. }
  3071. };
  3072. /**
  3073. * Converts a Babylon Standard Material to a glTF Material
  3074. * @param babylonStandardMaterial BJS Standard Material
  3075. * @param mimeType mime type to use for the textures
  3076. * @param images array of glTF image interfaces
  3077. * @param textures array of glTF texture interfaces
  3078. * @param materials array of glTF material interfaces
  3079. * @param imageData map of image file name to data
  3080. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3081. */
  3082. _GLTFMaterialExporter.prototype._convertStandardMaterialAsync = function (babylonStandardMaterial, mimeType, hasTextureCoords) {
  3083. var materialMap = this._exporter._materialMap;
  3084. var materials = this._exporter._materials;
  3085. var promises = [];
  3086. var glTFPbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);
  3087. var glTFMaterial = { name: babylonStandardMaterial.name };
  3088. if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {
  3089. if (!babylonStandardMaterial.twoSidedLighting) {
  3090. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(babylonStandardMaterial.name + ": Back-face culling enabled and two-sided lighting disabled is not supported in glTF.");
  3091. }
  3092. glTFMaterial.doubleSided = true;
  3093. }
  3094. if (hasTextureCoords) {
  3095. if (babylonStandardMaterial.diffuseTexture) {
  3096. promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then(function (glTFTexture) {
  3097. if (glTFTexture) {
  3098. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  3099. }
  3100. }));
  3101. }
  3102. if (babylonStandardMaterial.bumpTexture) {
  3103. promises.push(this._exportTextureAsync(babylonStandardMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  3104. if (glTFTexture) {
  3105. glTFMaterial.normalTexture = glTFTexture;
  3106. if (babylonStandardMaterial.bumpTexture != null && babylonStandardMaterial.bumpTexture.level !== 1) {
  3107. glTFMaterial.normalTexture.scale = babylonStandardMaterial.bumpTexture.level;
  3108. }
  3109. }
  3110. }));
  3111. }
  3112. if (babylonStandardMaterial.emissiveTexture) {
  3113. glTFMaterial.emissiveFactor = [1.0, 1.0, 1.0];
  3114. promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then(function (glTFEmissiveTexture) {
  3115. if (glTFEmissiveTexture) {
  3116. glTFMaterial.emissiveTexture = glTFEmissiveTexture;
  3117. }
  3118. }));
  3119. }
  3120. if (babylonStandardMaterial.ambientTexture) {
  3121. promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  3122. if (glTFTexture) {
  3123. var occlusionTexture = {
  3124. index: glTFTexture.index
  3125. };
  3126. glTFMaterial.occlusionTexture = occlusionTexture;
  3127. occlusionTexture.strength = 1.0;
  3128. }
  3129. }));
  3130. }
  3131. }
  3132. if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {
  3133. if (babylonStandardMaterial.alphaMode === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Constants"].ALPHA_COMBINE) {
  3134. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  3135. }
  3136. else {
  3137. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(babylonStandardMaterial.name + ": glTF 2.0 does not support alpha mode: " + babylonStandardMaterial.alphaMode.toString());
  3138. }
  3139. }
  3140. if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter.FuzzyEquals(babylonStandardMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  3141. glTFMaterial.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();
  3142. }
  3143. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  3144. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonStandardMaterial);
  3145. materials.push(glTFMaterial);
  3146. materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;
  3147. return this._finishMaterial(promises, glTFMaterial, babylonStandardMaterial, mimeType);
  3148. };
  3149. _GLTFMaterialExporter.prototype._finishMaterial = function (promises, glTFMaterial, babylonMaterial, mimeType) {
  3150. var _this = this;
  3151. return Promise.all(promises).then(function () {
  3152. var textures = _this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial", glTFMaterial, babylonMaterial);
  3153. var tasks = null;
  3154. for (var _i = 0, textures_1 = textures; _i < textures_1.length; _i++) {
  3155. var texture = textures_1[_i];
  3156. if (!tasks) {
  3157. tasks = [];
  3158. }
  3159. tasks.push(_this._exportTextureAsync(texture, mimeType));
  3160. }
  3161. if (!tasks) {
  3162. tasks = [Promise.resolve(null)];
  3163. }
  3164. return Promise.all(tasks).then(function () {
  3165. var extensionWork = _this._exporter._extensionsPostExportMaterialAsync("exportMaterial", glTFMaterial, babylonMaterial);
  3166. if (!extensionWork) {
  3167. return glTFMaterial;
  3168. }
  3169. return extensionWork.then(function () { return glTFMaterial; });
  3170. });
  3171. });
  3172. };
  3173. /**
  3174. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  3175. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  3176. * @param mimeType mime type to use for the textures
  3177. * @param images array of glTF image interfaces
  3178. * @param textures array of glTF texture interfaces
  3179. * @param materials array of glTF material interfaces
  3180. * @param imageData map of image file name to data
  3181. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3182. */
  3183. _GLTFMaterialExporter.prototype._convertPBRMetallicRoughnessMaterialAsync = function (babylonPBRMetalRoughMaterial, mimeType, hasTextureCoords) {
  3184. var materialMap = this._exporter._materialMap;
  3185. var materials = this._exporter._materials;
  3186. var promises = [];
  3187. var glTFPbrMetallicRoughness = {};
  3188. if (babylonPBRMetalRoughMaterial.baseColor) {
  3189. glTFPbrMetallicRoughness.baseColorFactor = [
  3190. babylonPBRMetalRoughMaterial.baseColor.r,
  3191. babylonPBRMetalRoughMaterial.baseColor.g,
  3192. babylonPBRMetalRoughMaterial.baseColor.b,
  3193. babylonPBRMetalRoughMaterial.alpha
  3194. ];
  3195. }
  3196. if (babylonPBRMetalRoughMaterial.metallic != null && babylonPBRMetalRoughMaterial.metallic !== 1) {
  3197. glTFPbrMetallicRoughness.metallicFactor = babylonPBRMetalRoughMaterial.metallic;
  3198. }
  3199. if (babylonPBRMetalRoughMaterial.roughness != null && babylonPBRMetalRoughMaterial.roughness !== 1) {
  3200. glTFPbrMetallicRoughness.roughnessFactor = babylonPBRMetalRoughMaterial.roughness;
  3201. }
  3202. var glTFMaterial = {
  3203. name: babylonPBRMetalRoughMaterial.name
  3204. };
  3205. if (babylonPBRMetalRoughMaterial.doubleSided) {
  3206. glTFMaterial.doubleSided = babylonPBRMetalRoughMaterial.doubleSided;
  3207. }
  3208. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMetalRoughMaterial);
  3209. if (hasTextureCoords) {
  3210. if (babylonPBRMetalRoughMaterial.baseTexture != null) {
  3211. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.baseTexture, mimeType).then(function (glTFTexture) {
  3212. if (glTFTexture) {
  3213. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  3214. }
  3215. }));
  3216. }
  3217. if (babylonPBRMetalRoughMaterial.normalTexture) {
  3218. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.normalTexture, mimeType).then(function (glTFTexture) {
  3219. if (glTFTexture) {
  3220. glTFMaterial.normalTexture = glTFTexture;
  3221. if (babylonPBRMetalRoughMaterial.normalTexture.level !== 1) {
  3222. glTFMaterial.normalTexture.scale = babylonPBRMetalRoughMaterial.normalTexture.level;
  3223. }
  3224. }
  3225. }));
  3226. }
  3227. if (babylonPBRMetalRoughMaterial.occlusionTexture) {
  3228. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.occlusionTexture, mimeType).then(function (glTFTexture) {
  3229. if (glTFTexture) {
  3230. glTFMaterial.occlusionTexture = glTFTexture;
  3231. if (babylonPBRMetalRoughMaterial.occlusionStrength != null) {
  3232. glTFMaterial.occlusionTexture.strength = babylonPBRMetalRoughMaterial.occlusionStrength;
  3233. }
  3234. }
  3235. }));
  3236. }
  3237. if (babylonPBRMetalRoughMaterial.emissiveTexture) {
  3238. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  3239. if (glTFTexture) {
  3240. glTFMaterial.emissiveTexture = glTFTexture;
  3241. }
  3242. }));
  3243. }
  3244. }
  3245. if (_GLTFMaterialExporter.FuzzyEquals(babylonPBRMetalRoughMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  3246. glTFMaterial.emissiveFactor = babylonPBRMetalRoughMaterial.emissiveColor.asArray();
  3247. }
  3248. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  3249. materials.push(glTFMaterial);
  3250. materialMap[babylonPBRMetalRoughMaterial.uniqueId] = materials.length - 1;
  3251. return this._finishMaterial(promises, glTFMaterial, babylonPBRMetalRoughMaterial, mimeType);
  3252. };
  3253. /**
  3254. * Converts an image typed array buffer to a base64 image
  3255. * @param buffer typed array buffer
  3256. * @param width width of the image
  3257. * @param height height of the image
  3258. * @param mimeType mimetype of the image
  3259. * @returns base64 image string
  3260. */
  3261. _GLTFMaterialExporter.prototype._createBase64FromCanvasAsync = function (buffer, width, height, mimeType) {
  3262. var _this = this;
  3263. return new Promise(function (resolve, reject) {
  3264. var hostingScene;
  3265. var textureType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Constants"].TEXTURETYPE_UNSIGNED_INT;
  3266. var engine = _this._exporter._getLocalEngine();
  3267. hostingScene = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scene"](engine);
  3268. // Create a temporary texture with the texture buffer data
  3269. var tempTexture = engine.createRawTexture(buffer, width, height, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Constants"].TEXTUREFORMAT_RGBA, false, true, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_SAMPLINGMODE, null, textureType);
  3270. var postProcess = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PostProcess"]("pass", "pass", null, null, 1, null, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_SAMPLINGMODE, engine, false, undefined, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Constants"].TEXTURETYPE_UNSIGNED_INT, undefined, null, false);
  3271. postProcess.getEffect().executeWhenCompiled(function () {
  3272. postProcess.onApply = function (effect) {
  3273. effect._bindTexture("textureSampler", tempTexture);
  3274. };
  3275. // Set the size of the texture
  3276. engine.setSize(width, height);
  3277. hostingScene.postProcessManager.directRender([postProcess], null);
  3278. postProcess.dispose();
  3279. tempTexture.dispose();
  3280. // Read data from WebGL
  3281. var canvas = engine.getRenderingCanvas();
  3282. if (canvas) {
  3283. if (!canvas.toBlob) { // fallback for browsers without "canvas.toBlob"
  3284. var dataURL = canvas.toDataURL();
  3285. resolve(dataURL);
  3286. }
  3287. else {
  3288. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToBlob(canvas, function (blob) {
  3289. if (blob) {
  3290. var fileReader = new FileReader();
  3291. fileReader.onload = function (event) {
  3292. var base64String = event.target.result;
  3293. hostingScene.dispose();
  3294. resolve(base64String);
  3295. };
  3296. fileReader.readAsDataURL(blob);
  3297. }
  3298. else {
  3299. reject("gltfMaterialExporter: Failed to get blob from image canvas!");
  3300. }
  3301. });
  3302. }
  3303. }
  3304. else {
  3305. reject("Engine is missing a canvas!");
  3306. }
  3307. });
  3308. });
  3309. };
  3310. /**
  3311. * Generates a white texture based on the specified width and height
  3312. * @param width width of the texture in pixels
  3313. * @param height height of the texture in pixels
  3314. * @param scene babylonjs scene
  3315. * @returns white texture
  3316. */
  3317. _GLTFMaterialExporter.prototype._createWhiteTexture = function (width, height, scene) {
  3318. var data = new Uint8Array(width * height * 4);
  3319. for (var i = 0; i < data.length; i = i + 4) {
  3320. data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xFF;
  3321. }
  3322. var rawTexture = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["RawTexture"].CreateRGBATexture(data, width, height, scene);
  3323. return rawTexture;
  3324. };
  3325. /**
  3326. * Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null
  3327. * @param texture1 first texture to resize
  3328. * @param texture2 second texture to resize
  3329. * @param scene babylonjs scene
  3330. * @returns resized textures or null
  3331. */
  3332. _GLTFMaterialExporter.prototype._resizeTexturesToSameDimensions = function (texture1, texture2, scene) {
  3333. var texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };
  3334. var texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };
  3335. var resizedTexture1;
  3336. var resizedTexture2;
  3337. if (texture1Size.width < texture2Size.width) {
  3338. if (texture1 && texture1 instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"]) {
  3339. resizedTexture1 = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TextureTools"].CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);
  3340. }
  3341. else {
  3342. resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);
  3343. }
  3344. resizedTexture2 = texture2;
  3345. }
  3346. else if (texture1Size.width > texture2Size.width) {
  3347. if (texture2 && texture2 instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"]) {
  3348. resizedTexture2 = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TextureTools"].CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);
  3349. }
  3350. else {
  3351. resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);
  3352. }
  3353. resizedTexture1 = texture1;
  3354. }
  3355. else {
  3356. resizedTexture1 = texture1;
  3357. resizedTexture2 = texture2;
  3358. }
  3359. return {
  3360. "texture1": resizedTexture1,
  3361. "texture2": resizedTexture2
  3362. };
  3363. };
  3364. /**
  3365. * Converts an array of pixels to a Float32Array
  3366. * Throws an error if the pixel format is not supported
  3367. * @param pixels - array buffer containing pixel values
  3368. * @returns Float32 of pixels
  3369. */
  3370. _GLTFMaterialExporter.prototype._convertPixelArrayToFloat32 = function (pixels) {
  3371. if (pixels instanceof Uint8Array) {
  3372. var length_1 = pixels.length;
  3373. var buffer = new Float32Array(pixels.length);
  3374. for (var i = 0; i < length_1; ++i) {
  3375. buffer[i] = pixels[i] / 255;
  3376. }
  3377. return buffer;
  3378. }
  3379. else if (pixels instanceof Float32Array) {
  3380. return pixels;
  3381. }
  3382. else {
  3383. throw new Error('Unsupported pixel format!');
  3384. }
  3385. };
  3386. /**
  3387. * Convert Specular Glossiness Textures to Metallic Roughness
  3388. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  3389. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  3390. * @param diffuseTexture texture used to store diffuse information
  3391. * @param specularGlossinessTexture texture used to store specular and glossiness information
  3392. * @param factors specular glossiness material factors
  3393. * @param mimeType the mime type to use for the texture
  3394. * @returns pbr metallic roughness interface or null
  3395. */
  3396. _GLTFMaterialExporter.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync = function (diffuseTexture, specularGlossinessTexture, factors, mimeType) {
  3397. var promises = [];
  3398. if (!(diffuseTexture || specularGlossinessTexture)) {
  3399. return Promise.reject('_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!');
  3400. }
  3401. var scene = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;
  3402. if (scene) {
  3403. var resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);
  3404. var diffuseSize = resizedTextures.texture1.getSize();
  3405. var diffuseBuffer = void 0;
  3406. var specularGlossinessBuffer = void 0;
  3407. var width = diffuseSize.width;
  3408. var height = diffuseSize.height;
  3409. var diffusePixels = resizedTextures.texture1.readPixels();
  3410. var specularPixels = resizedTextures.texture2.readPixels();
  3411. if (diffusePixels) {
  3412. diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);
  3413. }
  3414. else {
  3415. return Promise.reject("Failed to retrieve pixels from diffuse texture!");
  3416. }
  3417. if (specularPixels) {
  3418. specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);
  3419. }
  3420. else {
  3421. return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");
  3422. }
  3423. var byteLength = specularGlossinessBuffer.byteLength;
  3424. var metallicRoughnessBuffer = new Uint8Array(byteLength);
  3425. var baseColorBuffer = new Uint8Array(byteLength);
  3426. var strideSize = 4;
  3427. var maxBaseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  3428. var maxMetallic = 0;
  3429. var maxRoughness = 0;
  3430. for (var h = 0; h < height; ++h) {
  3431. for (var w = 0; w < width; ++w) {
  3432. var offset = (width * h + w) * strideSize;
  3433. var diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2]).toLinearSpace().multiply(factors.diffuseColor);
  3434. var specularColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2]).toLinearSpace().multiply(factors.specularColor);
  3435. var glossiness = (specularGlossinessBuffer[offset + 3]) * factors.glossiness;
  3436. var specularGlossiness = {
  3437. diffuseColor: diffuseColor,
  3438. specularColor: specularColor,
  3439. glossiness: glossiness
  3440. };
  3441. var metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);
  3442. maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);
  3443. maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);
  3444. maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);
  3445. maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic);
  3446. maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness);
  3447. baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;
  3448. baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;
  3449. baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;
  3450. baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;
  3451. metallicRoughnessBuffer[offset] = 0;
  3452. metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness * 255;
  3453. metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic * 255;
  3454. metallicRoughnessBuffer[offset + 3] = 255;
  3455. }
  3456. }
  3457. // Retrieves the metallic roughness factors from the maximum texture values.
  3458. var metallicRoughnessFactors_1 = {
  3459. baseColor: maxBaseColor,
  3460. metallic: maxMetallic,
  3461. roughness: maxRoughness
  3462. };
  3463. var writeOutMetallicRoughnessTexture = false;
  3464. var writeOutBaseColorTexture = false;
  3465. for (var h = 0; h < height; ++h) {
  3466. for (var w = 0; w < width; ++w) {
  3467. var destinationOffset = (width * h + w) * strideSize;
  3468. baseColorBuffer[destinationOffset] /= metallicRoughnessFactors_1.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.r : 1;
  3469. baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.g : 1;
  3470. baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.b : 1;
  3471. var linearBaseColorPixel = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromInts(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);
  3472. var sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace();
  3473. baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;
  3474. baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;
  3475. baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;
  3476. if (!_GLTFMaterialExporter.FuzzyEquals(sRGBBaseColorPixel, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  3477. writeOutBaseColorTexture = true;
  3478. }
  3479. metallicRoughnessBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.roughness > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.roughness : 1;
  3480. metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.metallic > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.metallic : 1;
  3481. var metallicRoughnessPixel = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);
  3482. if (!_GLTFMaterialExporter.FuzzyEquals(metallicRoughnessPixel, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  3483. writeOutMetallicRoughnessTexture = true;
  3484. }
  3485. }
  3486. }
  3487. if (writeOutMetallicRoughnessTexture) {
  3488. var promise = this._createBase64FromCanvasAsync(metallicRoughnessBuffer, width, height, mimeType).then(function (metallicRoughnessBase64) {
  3489. metallicRoughnessFactors_1.metallicRoughnessTextureBase64 = metallicRoughnessBase64;
  3490. });
  3491. promises.push(promise);
  3492. }
  3493. if (writeOutBaseColorTexture) {
  3494. var promise = this._createBase64FromCanvasAsync(baseColorBuffer, width, height, mimeType).then(function (baseColorBase64) {
  3495. metallicRoughnessFactors_1.baseColorTextureBase64 = baseColorBase64;
  3496. });
  3497. promises.push(promise);
  3498. }
  3499. return Promise.all(promises).then(function () {
  3500. return metallicRoughnessFactors_1;
  3501. });
  3502. }
  3503. else {
  3504. return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");
  3505. }
  3506. };
  3507. /**
  3508. * Converts specular glossiness material properties to metallic roughness
  3509. * @param specularGlossiness interface with specular glossiness material properties
  3510. * @returns interface with metallic roughness material properties
  3511. */
  3512. _GLTFMaterialExporter.prototype._convertSpecularGlossinessToMetallicRoughness = function (specularGlossiness) {
  3513. var diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);
  3514. var specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);
  3515. var oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);
  3516. var metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);
  3517. var baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon));
  3518. var baseColorFromSpecular = specularGlossiness.specularColor.subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic)).scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));
  3519. var baseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);
  3520. baseColor = baseColor.clampToRef(0, 1, baseColor);
  3521. var metallicRoughness = {
  3522. baseColor: baseColor,
  3523. metallic: metallic,
  3524. roughness: 1 - specularGlossiness.glossiness
  3525. };
  3526. return metallicRoughness;
  3527. };
  3528. /**
  3529. * Calculates the surface reflectance, independent of lighting conditions
  3530. * @param color Color source to calculate brightness from
  3531. * @returns number representing the perceived brightness, or zero if color is undefined
  3532. */
  3533. _GLTFMaterialExporter.prototype._getPerceivedBrightness = function (color) {
  3534. if (color) {
  3535. return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);
  3536. }
  3537. return 0;
  3538. };
  3539. /**
  3540. * Returns the maximum color component value
  3541. * @param color
  3542. * @returns maximum color component value, or zero if color is null or undefined
  3543. */
  3544. _GLTFMaterialExporter.prototype._getMaxComponent = function (color) {
  3545. if (color) {
  3546. return Math.max(color.r, Math.max(color.g, color.b));
  3547. }
  3548. return 0;
  3549. };
  3550. /**
  3551. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  3552. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3553. * @param mimeType mime type to use for the textures
  3554. * @param images array of glTF image interfaces
  3555. * @param textures array of glTF texture interfaces
  3556. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  3557. * @param imageData map of image file name to data
  3558. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3559. * @returns glTF PBR Metallic Roughness factors
  3560. */
  3561. _GLTFMaterialExporter.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  3562. var promises = [];
  3563. var metallicRoughness = {
  3564. baseColor: babylonPBRMaterial.albedoColor,
  3565. metallic: babylonPBRMaterial.metallic,
  3566. roughness: babylonPBRMaterial.roughness
  3567. };
  3568. if (hasTextureCoords) {
  3569. if (babylonPBRMaterial.albedoTexture) {
  3570. promises.push(this._exportTextureAsync(babylonPBRMaterial.albedoTexture, mimeType).then(function (glTFTexture) {
  3571. if (glTFTexture) {
  3572. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  3573. }
  3574. }));
  3575. }
  3576. if (babylonPBRMaterial.metallicTexture) {
  3577. promises.push(this._exportTextureAsync(babylonPBRMaterial.metallicTexture, mimeType).then(function (glTFTexture) {
  3578. if (glTFTexture) {
  3579. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;
  3580. }
  3581. }));
  3582. }
  3583. }
  3584. return Promise.all(promises).then(function () {
  3585. return metallicRoughness;
  3586. });
  3587. };
  3588. _GLTFMaterialExporter.prototype._getGLTFTextureSampler = function (texture) {
  3589. var sampler = this._getGLTFTextureWrapModesSampler(texture);
  3590. var samplingMode = texture instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"] ? texture.samplingMode : null;
  3591. if (samplingMode != null) {
  3592. switch (samplingMode) {
  3593. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR: {
  3594. sampler.magFilter = 9729 /* LINEAR */;
  3595. sampler.minFilter = 9729 /* LINEAR */;
  3596. break;
  3597. }
  3598. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST: {
  3599. sampler.magFilter = 9729 /* LINEAR */;
  3600. sampler.minFilter = 9728 /* NEAREST */;
  3601. break;
  3602. }
  3603. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR: {
  3604. sampler.magFilter = 9728 /* NEAREST */;
  3605. sampler.minFilter = 9729 /* LINEAR */;
  3606. break;
  3607. }
  3608. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR: {
  3609. sampler.magFilter = 9728 /* NEAREST */;
  3610. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  3611. break;
  3612. }
  3613. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST: {
  3614. sampler.magFilter = 9728 /* NEAREST */;
  3615. sampler.minFilter = 9728 /* NEAREST */;
  3616. break;
  3617. }
  3618. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST: {
  3619. sampler.magFilter = 9728 /* NEAREST */;
  3620. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  3621. break;
  3622. }
  3623. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST: {
  3624. sampler.magFilter = 9729 /* LINEAR */;
  3625. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  3626. break;
  3627. }
  3628. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR: {
  3629. sampler.magFilter = 9729 /* LINEAR */;
  3630. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  3631. break;
  3632. }
  3633. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR: {
  3634. sampler.magFilter = 9728 /* NEAREST */;
  3635. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  3636. break;
  3637. }
  3638. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR: {
  3639. sampler.magFilter = 9729 /* LINEAR */;
  3640. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  3641. break;
  3642. }
  3643. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST: {
  3644. sampler.magFilter = 9729 /* LINEAR */;
  3645. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  3646. break;
  3647. }
  3648. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST: {
  3649. sampler.magFilter = 9728 /* NEAREST */;
  3650. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  3651. break;
  3652. }
  3653. }
  3654. }
  3655. return sampler;
  3656. };
  3657. _GLTFMaterialExporter.prototype._getGLTFTextureWrapMode = function (wrapMode) {
  3658. switch (wrapMode) {
  3659. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE: {
  3660. return 10497 /* REPEAT */;
  3661. }
  3662. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE: {
  3663. return 33071 /* CLAMP_TO_EDGE */;
  3664. }
  3665. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE: {
  3666. return 33648 /* MIRRORED_REPEAT */;
  3667. }
  3668. default: {
  3669. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported Texture Wrap Mode " + wrapMode + "!");
  3670. return 10497 /* REPEAT */;
  3671. }
  3672. }
  3673. };
  3674. _GLTFMaterialExporter.prototype._getGLTFTextureWrapModesSampler = function (texture) {
  3675. var wrapS = this._getGLTFTextureWrapMode(texture instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"] ? texture.wrapU : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE);
  3676. var wrapT = this._getGLTFTextureWrapMode(texture instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"] ? texture.wrapV : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE);
  3677. if (wrapS === 10497 /* REPEAT */ && wrapT === 10497 /* REPEAT */) { // default wrapping mode in glTF, so omitting
  3678. return {};
  3679. }
  3680. return { wrapS: wrapS, wrapT: wrapT };
  3681. };
  3682. /**
  3683. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  3684. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3685. * @param mimeType mime type to use for the textures
  3686. * @param images array of glTF image interfaces
  3687. * @param textures array of glTF texture interfaces
  3688. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  3689. * @param imageData map of image file name to data
  3690. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3691. * @returns glTF PBR Metallic Roughness factors
  3692. */
  3693. _GLTFMaterialExporter.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  3694. var _this = this;
  3695. return Promise.resolve().then(function () {
  3696. var samplers = _this._exporter._samplers;
  3697. var textures = _this._exporter._textures;
  3698. var specGloss = {
  3699. diffuseColor: babylonPBRMaterial.albedoColor || babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(),
  3700. specularColor: babylonPBRMaterial.reflectivityColor || babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(),
  3701. glossiness: babylonPBRMaterial.microSurface || 1,
  3702. };
  3703. var samplerIndex = null;
  3704. var sampler = _this._getGLTFTextureSampler(babylonPBRMaterial.albedoTexture);
  3705. if (sampler.magFilter != null && sampler.minFilter != null && sampler.wrapS != null && sampler.wrapT != null) {
  3706. samplers.push(sampler);
  3707. samplerIndex = samplers.length - 1;
  3708. }
  3709. if (babylonPBRMaterial.reflectivityTexture && !babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha) {
  3710. return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");
  3711. }
  3712. if ((babylonPBRMaterial.albedoTexture || babylonPBRMaterial.reflectivityTexture) && hasTextureCoords) {
  3713. return _this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(babylonPBRMaterial.albedoTexture, babylonPBRMaterial.reflectivityTexture, specGloss, mimeType).then(function (metallicRoughnessFactors) {
  3714. if (metallicRoughnessFactors.baseColorTextureBase64) {
  3715. var glTFBaseColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.baseColorTextureBase64, "bjsBaseColorTexture_" + (textures.length) + ".png", mimeType, babylonPBRMaterial.albedoTexture ? babylonPBRMaterial.albedoTexture.coordinatesIndex : null, samplerIndex);
  3716. if (glTFBaseColorTexture) {
  3717. glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
  3718. }
  3719. }
  3720. if (metallicRoughnessFactors.metallicRoughnessTextureBase64) {
  3721. var glTFMRColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + (textures.length) + ".png", mimeType, babylonPBRMaterial.reflectivityTexture ? babylonPBRMaterial.reflectivityTexture.coordinatesIndex : null, samplerIndex);
  3722. if (glTFMRColorTexture) {
  3723. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
  3724. }
  3725. }
  3726. return metallicRoughnessFactors;
  3727. });
  3728. }
  3729. else {
  3730. return _this._convertSpecularGlossinessToMetallicRoughness(specGloss);
  3731. }
  3732. });
  3733. };
  3734. /**
  3735. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  3736. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3737. * @param mimeType mime type to use for the textures
  3738. * @param images array of glTF image interfaces
  3739. * @param textures array of glTF texture interfaces
  3740. * @param materials array of glTF material interfaces
  3741. * @param imageData map of image file name to data
  3742. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3743. */
  3744. _GLTFMaterialExporter.prototype._convertPBRMaterialAsync = function (babylonPBRMaterial, mimeType, hasTextureCoords) {
  3745. var _this = this;
  3746. var glTFPbrMetallicRoughness = {};
  3747. var glTFMaterial = {
  3748. name: babylonPBRMaterial.name
  3749. };
  3750. var useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();
  3751. if (useMetallicRoughness) {
  3752. if (babylonPBRMaterial.albedoColor) {
  3753. glTFPbrMetallicRoughness.baseColorFactor = [
  3754. babylonPBRMaterial.albedoColor.r,
  3755. babylonPBRMaterial.albedoColor.g,
  3756. babylonPBRMaterial.albedoColor.b,
  3757. babylonPBRMaterial.alpha
  3758. ];
  3759. }
  3760. return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  3761. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  3762. });
  3763. }
  3764. else {
  3765. return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  3766. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  3767. });
  3768. }
  3769. };
  3770. _GLTFMaterialExporter.prototype.setMetallicRoughnessPbrMaterial = function (metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords) {
  3771. var materialMap = this._exporter._materialMap;
  3772. var materials = this._exporter._materials;
  3773. var promises = [];
  3774. if (metallicRoughness) {
  3775. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial);
  3776. if (!(_GLTFMaterialExporter.FuzzyEquals(metallicRoughness.baseColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon) && babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon)) {
  3777. glTFPbrMetallicRoughness.baseColorFactor = [
  3778. metallicRoughness.baseColor.r,
  3779. metallicRoughness.baseColor.g,
  3780. metallicRoughness.baseColor.b,
  3781. babylonPBRMaterial.alpha
  3782. ];
  3783. }
  3784. if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {
  3785. glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;
  3786. }
  3787. if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {
  3788. glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;
  3789. }
  3790. if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {
  3791. if (!babylonPBRMaterial.twoSidedLighting) {
  3792. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(babylonPBRMaterial.name + ": Back-face culling enabled and two-sided lighting disabled is not supported in glTF.");
  3793. }
  3794. glTFMaterial.doubleSided = true;
  3795. }
  3796. if (hasTextureCoords) {
  3797. if (babylonPBRMaterial.bumpTexture) {
  3798. var promise = this._exportTextureAsync(babylonPBRMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  3799. if (glTFTexture) {
  3800. glTFMaterial.normalTexture = glTFTexture;
  3801. if (babylonPBRMaterial.bumpTexture.level !== 1) {
  3802. glTFMaterial.normalTexture.scale = babylonPBRMaterial.bumpTexture.level;
  3803. }
  3804. }
  3805. });
  3806. promises.push(promise);
  3807. }
  3808. if (babylonPBRMaterial.ambientTexture) {
  3809. var promise = this._exportTextureAsync(babylonPBRMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  3810. if (glTFTexture) {
  3811. var occlusionTexture = {
  3812. index: glTFTexture.index,
  3813. texCoord: glTFTexture.texCoord
  3814. };
  3815. glTFMaterial.occlusionTexture = occlusionTexture;
  3816. if (babylonPBRMaterial.ambientTextureStrength) {
  3817. occlusionTexture.strength = babylonPBRMaterial.ambientTextureStrength;
  3818. }
  3819. }
  3820. });
  3821. promises.push(promise);
  3822. }
  3823. if (babylonPBRMaterial.emissiveTexture) {
  3824. var promise = this._exportTextureAsync(babylonPBRMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  3825. if (glTFTexture) {
  3826. glTFMaterial.emissiveTexture = glTFTexture;
  3827. }
  3828. });
  3829. promises.push(promise);
  3830. }
  3831. }
  3832. if (!_GLTFMaterialExporter.FuzzyEquals(babylonPBRMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  3833. glTFMaterial.emissiveFactor = babylonPBRMaterial.emissiveColor.asArray();
  3834. }
  3835. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  3836. materials.push(glTFMaterial);
  3837. materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;
  3838. }
  3839. return this._finishMaterial(promises, glTFMaterial, babylonPBRMaterial, mimeType);
  3840. };
  3841. _GLTFMaterialExporter.prototype.getPixelsFromTexture = function (babylonTexture) {
  3842. var pixels = babylonTexture.textureType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Constants"].TEXTURETYPE_UNSIGNED_INT ? babylonTexture.readPixels() : babylonTexture.readPixels();
  3843. return pixels;
  3844. };
  3845. /**
  3846. * Extracts a texture from a Babylon texture into file data and glTF data
  3847. * @param babylonTexture Babylon texture to extract
  3848. * @param mimeType Mime Type of the babylonTexture
  3849. * @return glTF texture info, or null if the texture format is not supported
  3850. */
  3851. _GLTFMaterialExporter.prototype._exportTextureAsync = function (babylonTexture, mimeType) {
  3852. var _this = this;
  3853. var extensionPromise = this._exporter._extensionsPreExportTextureAsync("exporter", babylonTexture, mimeType);
  3854. if (!extensionPromise) {
  3855. return this._exportTextureInfoAsync(babylonTexture, mimeType);
  3856. }
  3857. return extensionPromise.then(function (texture) {
  3858. if (!texture) {
  3859. return _this._exportTextureInfoAsync(babylonTexture, mimeType);
  3860. }
  3861. return _this._exportTextureInfoAsync(texture, mimeType);
  3862. });
  3863. };
  3864. _GLTFMaterialExporter.prototype._exportTextureInfoAsync = function (babylonTexture, mimeType) {
  3865. var _this = this;
  3866. return Promise.resolve().then(function () {
  3867. var textureUid = babylonTexture.uid;
  3868. if (textureUid in _this._textureMap) {
  3869. return _this._textureMap[textureUid];
  3870. }
  3871. else {
  3872. var samplers = _this._exporter._samplers;
  3873. var sampler = _this._getGLTFTextureSampler(babylonTexture);
  3874. var samplerIndex_1 = null;
  3875. // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler
  3876. var foundSamplerIndex = null;
  3877. for (var i = 0; i < samplers.length; ++i) {
  3878. var s = samplers[i];
  3879. if (s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter &&
  3880. s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT) {
  3881. foundSamplerIndex = i;
  3882. break;
  3883. }
  3884. }
  3885. if (foundSamplerIndex == null) {
  3886. samplers.push(sampler);
  3887. samplerIndex_1 = samplers.length - 1;
  3888. }
  3889. else {
  3890. samplerIndex_1 = foundSamplerIndex;
  3891. }
  3892. var pixels = _this.getPixelsFromTexture(babylonTexture);
  3893. var size = babylonTexture.getSize();
  3894. return _this._createBase64FromCanvasAsync(pixels, size.width, size.height, mimeType).then(function (base64Data) {
  3895. var textureInfo = _this._getTextureInfoFromBase64(base64Data, babylonTexture.name.replace(/\.\/|\/|\.\\|\\/g, "_"), mimeType, babylonTexture.coordinatesIndex, samplerIndex_1);
  3896. if (textureInfo) {
  3897. _this._textureMap[textureUid] = textureInfo;
  3898. _this._exporter._extensionsPostExportTextures("linkTextureInfo", textureInfo, babylonTexture);
  3899. }
  3900. return textureInfo;
  3901. });
  3902. }
  3903. });
  3904. };
  3905. /**
  3906. * Builds a texture from base64 string
  3907. * @param base64Texture base64 texture string
  3908. * @param baseTextureName Name to use for the texture
  3909. * @param mimeType image mime type for the texture
  3910. * @param images array of images
  3911. * @param textures array of textures
  3912. * @param imageData map of image data
  3913. * @returns glTF texture info, or null if the texture format is not supported
  3914. */
  3915. _GLTFMaterialExporter.prototype._getTextureInfoFromBase64 = function (base64Texture, baseTextureName, mimeType, texCoordIndex, samplerIndex) {
  3916. var textures = this._exporter._textures;
  3917. var images = this._exporter._images;
  3918. var imageData = this._exporter._imageData;
  3919. var textureInfo = null;
  3920. var glTFTexture = {
  3921. source: images.length,
  3922. name: baseTextureName
  3923. };
  3924. if (samplerIndex != null) {
  3925. glTFTexture.sampler = samplerIndex;
  3926. }
  3927. var binStr = atob(base64Texture.split(',')[1]);
  3928. var arrBuff = new ArrayBuffer(binStr.length);
  3929. var arr = new Uint8Array(arrBuff);
  3930. for (var i = 0, length_2 = binStr.length; i < length_2; ++i) {
  3931. arr[i] = binStr.charCodeAt(i);
  3932. }
  3933. var imageValues = { data: arr, mimeType: mimeType };
  3934. var extension = mimeType === "image/jpeg" /* JPEG */ ? '.jpeg' : '.png';
  3935. var textureName = baseTextureName + extension;
  3936. var originalTextureName = textureName;
  3937. if (textureName in imageData) {
  3938. textureName = baseTextureName + "_" + babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].RandomId() + extension;
  3939. }
  3940. imageData[textureName] = imageValues;
  3941. if (mimeType === "image/jpeg" /* JPEG */ || mimeType === "image/png" /* PNG */) {
  3942. var glTFImage = {
  3943. name: baseTextureName,
  3944. uri: textureName
  3945. };
  3946. var foundIndex = null;
  3947. for (var i = 0; i < images.length; ++i) {
  3948. if (images[i].uri === originalTextureName) {
  3949. foundIndex = i;
  3950. break;
  3951. }
  3952. }
  3953. if (foundIndex == null) {
  3954. images.push(glTFImage);
  3955. glTFTexture.source = images.length - 1;
  3956. }
  3957. else {
  3958. glTFTexture.source = foundIndex;
  3959. }
  3960. textures.push(glTFTexture);
  3961. textureInfo = {
  3962. index: textures.length - 1
  3963. };
  3964. if (texCoordIndex != null) {
  3965. textureInfo.texCoord = texCoordIndex;
  3966. }
  3967. }
  3968. else {
  3969. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported texture mime type " + mimeType);
  3970. }
  3971. return textureInfo;
  3972. };
  3973. /**
  3974. * Represents the dielectric specular values for R, G and B
  3975. */
  3976. _GLTFMaterialExporter._DielectricSpecular = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](0.04, 0.04, 0.04);
  3977. /**
  3978. * Allows the maximum specular power to be defined for material calculations
  3979. */
  3980. _GLTFMaterialExporter._MaxSpecularPower = 1024;
  3981. /**
  3982. * Numeric tolerance value
  3983. */
  3984. _GLTFMaterialExporter._Epsilon = 1e-6;
  3985. return _GLTFMaterialExporter;
  3986. }());
  3987. /***/ }),
  3988. /***/ "./glTF/2.0/glTFSerializer.ts":
  3989. /*!************************************!*\
  3990. !*** ./glTF/2.0/glTFSerializer.ts ***!
  3991. \************************************/
  3992. /*! exports provided: GLTF2Export */
  3993. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3994. "use strict";
  3995. __webpack_require__.r(__webpack_exports__);
  3996. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return GLTF2Export; });
  3997. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  3998. /**
  3999. * Class for generating glTF data from a Babylon scene.
  4000. */
  4001. var GLTF2Export = /** @class */ (function () {
  4002. function GLTF2Export() {
  4003. }
  4004. /**
  4005. * Exports the geometry of the scene to .gltf file format asynchronously
  4006. * @param scene Babylon scene with scene hierarchy information
  4007. * @param filePrefix File prefix to use when generating the glTF file
  4008. * @param options Exporter options
  4009. * @returns Returns an object with a .gltf file and associates texture names
  4010. * as keys and their data and paths as values
  4011. */
  4012. GLTF2Export.GLTFAsync = function (scene, filePrefix, options) {
  4013. return scene.whenReadyAsync().then(function () {
  4014. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  4015. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  4016. return gltfGenerator._generateGLTFAsync(glTFPrefix);
  4017. });
  4018. };
  4019. GLTF2Export._PreExportAsync = function (scene, options) {
  4020. return Promise.resolve().then(function () {
  4021. if (options && options.exportWithoutWaitingForScene) {
  4022. return Promise.resolve();
  4023. }
  4024. else {
  4025. return scene.whenReadyAsync();
  4026. }
  4027. });
  4028. };
  4029. GLTF2Export._PostExportAsync = function (scene, glTFData, options) {
  4030. return Promise.resolve().then(function () {
  4031. if (options && options.exportWithoutWaitingForScene) {
  4032. return glTFData;
  4033. }
  4034. else {
  4035. return glTFData;
  4036. }
  4037. });
  4038. };
  4039. /**
  4040. * Exports the geometry of the scene to .glb file format asychronously
  4041. * @param scene Babylon scene with scene hierarchy information
  4042. * @param filePrefix File prefix to use when generating glb file
  4043. * @param options Exporter options
  4044. * @returns Returns an object with a .glb filename as key and data as value
  4045. */
  4046. GLTF2Export.GLBAsync = function (scene, filePrefix, options) {
  4047. var _this = this;
  4048. return this._PreExportAsync(scene, options).then(function () {
  4049. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  4050. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  4051. return gltfGenerator._generateGLBAsync(glTFPrefix).then(function (glTFData) {
  4052. return _this._PostExportAsync(scene, glTFData, options);
  4053. });
  4054. });
  4055. };
  4056. return GLTF2Export;
  4057. }());
  4058. /***/ }),
  4059. /***/ "./glTF/2.0/glTFUtilities.ts":
  4060. /*!***********************************!*\
  4061. !*** ./glTF/2.0/glTFUtilities.ts ***!
  4062. \***********************************/
  4063. /*! exports provided: _GLTFUtilities */
  4064. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4065. "use strict";
  4066. __webpack_require__.r(__webpack_exports__);
  4067. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _GLTFUtilities; });
  4068. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  4069. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  4070. /**
  4071. * @hidden
  4072. */
  4073. var _GLTFUtilities = /** @class */ (function () {
  4074. function _GLTFUtilities() {
  4075. }
  4076. /**
  4077. * Creates a buffer view based on the supplied arguments
  4078. * @param bufferIndex index value of the specified buffer
  4079. * @param byteOffset byte offset value
  4080. * @param byteLength byte length of the bufferView
  4081. * @param byteStride byte distance between conequential elements
  4082. * @param name name of the buffer view
  4083. * @returns bufferView for glTF
  4084. */
  4085. _GLTFUtilities._CreateBufferView = function (bufferIndex, byteOffset, byteLength, byteStride, name) {
  4086. var bufferview = { buffer: bufferIndex, byteLength: byteLength };
  4087. if (byteOffset) {
  4088. bufferview.byteOffset = byteOffset;
  4089. }
  4090. if (name) {
  4091. bufferview.name = name;
  4092. }
  4093. if (byteStride) {
  4094. bufferview.byteStride = byteStride;
  4095. }
  4096. return bufferview;
  4097. };
  4098. /**
  4099. * Creates an accessor based on the supplied arguments
  4100. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  4101. * @param name The name of the accessor
  4102. * @param type The type of the accessor
  4103. * @param componentType The datatype of components in the attribute
  4104. * @param count The number of attributes referenced by this accessor
  4105. * @param byteOffset The offset relative to the start of the bufferView in bytes
  4106. * @param min Minimum value of each component in this attribute
  4107. * @param max Maximum value of each component in this attribute
  4108. * @returns accessor for glTF
  4109. */
  4110. _GLTFUtilities._CreateAccessor = function (bufferviewIndex, name, type, componentType, count, byteOffset, min, max) {
  4111. var accessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };
  4112. if (min != null) {
  4113. accessor.min = min;
  4114. }
  4115. if (max != null) {
  4116. accessor.max = max;
  4117. }
  4118. if (byteOffset != null) {
  4119. accessor.byteOffset = byteOffset;
  4120. }
  4121. return accessor;
  4122. };
  4123. /**
  4124. * Calculates the minimum and maximum values of an array of position floats
  4125. * @param positions Positions array of a mesh
  4126. * @param vertexStart Starting vertex offset to calculate min and max values
  4127. * @param vertexCount Number of vertices to check for min and max values
  4128. * @returns min number array and max number array
  4129. */
  4130. _GLTFUtilities._CalculateMinMaxPositions = function (positions, vertexStart, vertexCount, convertToRightHandedSystem) {
  4131. var min = [Infinity, Infinity, Infinity];
  4132. var max = [-Infinity, -Infinity, -Infinity];
  4133. var positionStrideSize = 3;
  4134. var indexOffset;
  4135. var position;
  4136. var vector;
  4137. if (vertexCount) {
  4138. for (var i = vertexStart, length_1 = vertexStart + vertexCount; i < length_1; ++i) {
  4139. indexOffset = positionStrideSize * i;
  4140. position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(positions, indexOffset);
  4141. if (convertToRightHandedSystem) {
  4142. _GLTFUtilities._GetRightHandedPositionVector3FromRef(position);
  4143. }
  4144. vector = position.asArray();
  4145. for (var j = 0; j < positionStrideSize; ++j) {
  4146. var num = vector[j];
  4147. if (num < min[j]) {
  4148. min[j] = num;
  4149. }
  4150. if (num > max[j]) {
  4151. max[j] = num;
  4152. }
  4153. ++indexOffset;
  4154. }
  4155. }
  4156. }
  4157. return { min: min, max: max };
  4158. };
  4159. /**
  4160. * Converts a new right-handed Vector3
  4161. * @param vector vector3 array
  4162. * @returns right-handed Vector3
  4163. */
  4164. _GLTFUtilities._GetRightHandedPositionVector3 = function (vector) {
  4165. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  4166. };
  4167. /**
  4168. * Converts a Vector3 to right-handed
  4169. * @param vector Vector3 to convert to right-handed
  4170. */
  4171. _GLTFUtilities._GetRightHandedPositionVector3FromRef = function (vector) {
  4172. vector.z *= -1;
  4173. };
  4174. /**
  4175. * Converts a three element number array to right-handed
  4176. * @param vector number array to convert to right-handed
  4177. */
  4178. _GLTFUtilities._GetRightHandedPositionArray3FromRef = function (vector) {
  4179. vector[2] *= -1;
  4180. };
  4181. /**
  4182. * Converts a new right-handed Vector3
  4183. * @param vector vector3 array
  4184. * @returns right-handed Vector3
  4185. */
  4186. _GLTFUtilities._GetRightHandedNormalVector3 = function (vector) {
  4187. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  4188. };
  4189. /**
  4190. * Converts a Vector3 to right-handed
  4191. * @param vector Vector3 to convert to right-handed
  4192. */
  4193. _GLTFUtilities._GetRightHandedNormalVector3FromRef = function (vector) {
  4194. vector.z *= -1;
  4195. };
  4196. /**
  4197. * Converts a three element number array to right-handed
  4198. * @param vector number array to convert to right-handed
  4199. */
  4200. _GLTFUtilities._GetRightHandedNormalArray3FromRef = function (vector) {
  4201. vector[2] *= -1;
  4202. };
  4203. /**
  4204. * Converts a Vector4 to right-handed
  4205. * @param vector Vector4 to convert to right-handed
  4206. */
  4207. _GLTFUtilities._GetRightHandedVector4FromRef = function (vector) {
  4208. vector.z *= -1;
  4209. vector.w *= -1;
  4210. };
  4211. /**
  4212. * Converts a Vector4 to right-handed
  4213. * @param vector Vector4 to convert to right-handed
  4214. */
  4215. _GLTFUtilities._GetRightHandedArray4FromRef = function (vector) {
  4216. vector[2] *= -1;
  4217. vector[3] *= -1;
  4218. };
  4219. /**
  4220. * Converts a Quaternion to right-handed
  4221. * @param quaternion Source quaternion to convert to right-handed
  4222. */
  4223. _GLTFUtilities._GetRightHandedQuaternionFromRef = function (quaternion) {
  4224. quaternion.x *= -1;
  4225. quaternion.y *= -1;
  4226. };
  4227. /**
  4228. * Converts a Quaternion to right-handed
  4229. * @param quaternion Source quaternion to convert to right-handed
  4230. */
  4231. _GLTFUtilities._GetRightHandedQuaternionArrayFromRef = function (quaternion) {
  4232. quaternion[0] *= -1;
  4233. quaternion[1] *= -1;
  4234. };
  4235. _GLTFUtilities._NormalizeTangentFromRef = function (tangent) {
  4236. var length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);
  4237. if (length > 0) {
  4238. tangent.x /= length;
  4239. tangent.y /= length;
  4240. tangent.z /= length;
  4241. }
  4242. };
  4243. return _GLTFUtilities;
  4244. }());
  4245. /***/ }),
  4246. /***/ "./glTF/2.0/index.ts":
  4247. /*!***************************!*\
  4248. !*** ./glTF/2.0/index.ts ***!
  4249. \***************************/
  4250. /*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen */
  4251. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4252. "use strict";
  4253. __webpack_require__.r(__webpack_exports__);
  4254. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  4255. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__["_GLTFAnimation"]; });
  4256. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  4257. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTFData__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  4258. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  4259. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_Exporter"]; });
  4260. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_BinaryWriter"]; });
  4261. /* harmony import */ var _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFExporterExtension */ "./glTF/2.0/glTFExporterExtension.ts");
  4262. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__["__IGLTFExporterExtensionV2"]; });
  4263. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  4264. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  4265. /* harmony import */ var _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  4266. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__["GLTF2Export"]; });
  4267. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  4268. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__["_GLTFUtilities"]; });
  4269. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  4270. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_texture_transform"]; });
  4271. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_lights_punctual"]; });
  4272. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  4273. /***/ }),
  4274. /***/ "./glTF/2.0/shaders/textureTransform.fragment.ts":
  4275. /*!*******************************************************!*\
  4276. !*** ./glTF/2.0/shaders/textureTransform.fragment.ts ***!
  4277. \*******************************************************/
  4278. /*! exports provided: textureTransformPixelShader */
  4279. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4280. "use strict";
  4281. __webpack_require__.r(__webpack_exports__);
  4282. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textureTransformPixelShader", function() { return textureTransformPixelShader; });
  4283. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Maths/math");
  4284. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  4285. var name = 'textureTransformPixelShader';
  4286. var shader = "precision highp float;\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 textureTransformMat;\nvoid main(void) {\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;\ngl_FragColor=texture2D(textureSampler,uvTransformed);\n}";
  4287. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  4288. /** @hidden */
  4289. var textureTransformPixelShader = { name: name, shader: shader };
  4290. /***/ }),
  4291. /***/ "./glTF/glTFFileExporter.ts":
  4292. /*!**********************************!*\
  4293. !*** ./glTF/glTFFileExporter.ts ***!
  4294. \**********************************/
  4295. /*! exports provided: __IGLTFExporterExtension */
  4296. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4297. "use strict";
  4298. __webpack_require__.r(__webpack_exports__);
  4299. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return __IGLTFExporterExtension; });
  4300. /** @hidden */
  4301. var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
  4302. /***/ }),
  4303. /***/ "./legacy/legacy-glTF2Serializer.ts":
  4304. /*!******************************************!*\
  4305. !*** ./legacy/legacy-glTF2Serializer.ts ***!
  4306. \******************************************/
  4307. /*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen */
  4308. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4309. "use strict";
  4310. __webpack_require__.r(__webpack_exports__);
  4311. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileExporter */ "./glTF/glTFFileExporter.ts");
  4312. /* harmony import */ var _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFData */ "./glTF/2.0/glTFData.ts");
  4313. /* harmony import */ var _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0/glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  4314. /* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  4315. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  4316. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__["__IGLTFExporterExtension"]; });
  4317. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]; });
  4318. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTF2Export"]; });
  4319. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]; });
  4320. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_Exporter"]; });
  4321. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_BinaryWriter"]; });
  4322. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["__IGLTFExporterExtensionV2"]; });
  4323. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  4324. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFUtilities"]; });
  4325. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_texture_transform"]; });
  4326. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_lights_punctual"]; });
  4327. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_sheen"]; });
  4328. /**
  4329. * This is the entry point for the UMD module.
  4330. * The entry point for a future ESM package should be index.ts
  4331. */
  4332. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4333. if (typeof globalObject !== "undefined") {
  4334. globalObject.BABYLON = globalObject.BABYLON || {};
  4335. var BABYLON = globalObject.BABYLON;
  4336. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  4337. BABYLON.GLTF2.Exporter = BABYLON.GLTF2.Exporter || {};
  4338. BABYLON.GLTF2.Exporter.Extensions = BABYLON.GLTF2.Exporter.Extensions || {};
  4339. var keys = [];
  4340. for (var key in _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__) {
  4341. BABYLON[key] = _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__[key];
  4342. keys.push(key);
  4343. }
  4344. for (var key in _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__) {
  4345. BABYLON[key] = _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__[key];
  4346. keys.push(key);
  4347. }
  4348. for (var key in _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__) {
  4349. BABYLON[key] = _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__[key];
  4350. keys.push(key);
  4351. }
  4352. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__) {
  4353. BABYLON.GLTF2.Exporter.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__[key];
  4354. keys.push(key);
  4355. }
  4356. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__) {
  4357. // Prevent Reassignment.
  4358. if (keys.indexOf(key) > -1) {
  4359. continue;
  4360. }
  4361. BABYLON.GLTF2.Exporter[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__[key];
  4362. }
  4363. }
  4364. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4365. /***/ }),
  4366. /***/ "babylonjs/Maths/math":
  4367. /*!****************************************************************************************************!*\
  4368. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  4369. \****************************************************************************************************/
  4370. /*! no static exports found */
  4371. /***/ (function(module, exports) {
  4372. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__;
  4373. /***/ })
  4374. /******/ });
  4375. });
  4376. //# sourceMappingURL=babylon.glTF2Serializer.js.map