babylonjs.serializers.js 244 KB

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