babylonjs.serializers.js 288 KB

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