babylonjs.serializers.js 281 KB

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