babylonjs.serializers.js 273 KB

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