babylonjs.serializers.js 244 KB

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