babylonjs.serializers.js 284 KB

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