babylon.glTF2Serializer.js 246 KB

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