babylon.glTF2Serializer.js 247 KB

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