babylonjs.serializers.js 281 KB

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