babylon.glTF2Serializer.js 257 KB

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