babylonjs.serializers.js 266 KB

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