babylonjs.serializers.js 227 KB

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