babylonjs.serializers.js 328 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906
  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:/Repos/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 (Object.prototype.hasOwnProperty.call(b, 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, o) {
  230. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, 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 (k !== "default" && Object.prototype.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. /**
  540. * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
  541. */
  542. var KHR_lights_punctual = /** @class */ (function () {
  543. /** @hidden */
  544. function KHR_lights_punctual(exporter) {
  545. /** The name of this extension. */
  546. this.name = NAME;
  547. /** Defines whether this extension is enabled. */
  548. this.enabled = true;
  549. /** Defines whether this extension is required */
  550. this.required = false;
  551. this._exporter = exporter;
  552. }
  553. /** @hidden */
  554. KHR_lights_punctual.prototype.dispose = function () {
  555. this._lights = null;
  556. };
  557. Object.defineProperty(KHR_lights_punctual.prototype, "wasUsed", {
  558. /** @hidden */
  559. get: function () {
  560. return !!this._lights;
  561. },
  562. enumerable: false,
  563. configurable: true
  564. });
  565. /** @hidden */
  566. KHR_lights_punctual.prototype.onExporting = function () {
  567. this._exporter._glTF.extensions[NAME] = this._lights;
  568. };
  569. /**
  570. * Define this method to modify the default behavior when exporting a node
  571. * @param context The context when exporting the node
  572. * @param node glTF node
  573. * @param babylonNode BabylonJS node
  574. * @param nodeMap Node mapping of unique id to glTF node index
  575. * @returns nullable INode promise
  576. */
  577. KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode, nodeMap) {
  578. var _this = this;
  579. return new Promise(function (resolve, reject) {
  580. if (node && babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["ShadowLight"]) {
  581. var babylonLight = babylonNode;
  582. var light = void 0;
  583. var lightType = (babylonLight.getTypeID() == babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_POINTLIGHT ? "point" /* POINT */ : (babylonLight.getTypeID() == babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_DIRECTIONALLIGHT ? "directional" /* DIRECTIONAL */ : (babylonLight.getTypeID() == babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_SPOTLIGHT ? "spot" /* SPOT */ : null)));
  584. if (lightType == null) {
  585. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Light " + babylonLight.name + " is not supported in " + NAME);
  586. }
  587. else {
  588. var lightPosition = babylonLight.position.clone();
  589. var convertToRightHandedSystem = _this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];
  590. if (!lightPosition.equals(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero())) {
  591. if (convertToRightHandedSystem) {
  592. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(lightPosition);
  593. }
  594. node.translation = lightPosition.asArray();
  595. }
  596. if (lightType !== "point" /* POINT */) {
  597. var localAxis = babylonLight.direction;
  598. var yaw = -Math.atan2(localAxis.z * (_this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;
  599. var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
  600. var pitch = -Math.atan2(localAxis.y, len);
  601. var lightRotationQuaternion = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(yaw, pitch, 0);
  602. if (convertToRightHandedSystem) {
  603. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
  604. }
  605. if (!lightRotationQuaternion.equals(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity())) {
  606. node.rotation = lightRotationQuaternion.asArray();
  607. }
  608. }
  609. if (babylonLight.falloffType !== babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF) {
  610. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(context + ": Light falloff for " + babylonLight.name + " does not match the " + NAME + " specification!");
  611. }
  612. light = {
  613. type: lightType
  614. };
  615. if (!babylonLight.diffuse.equals(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Color3"].White())) {
  616. light.color = babylonLight.diffuse.asArray();
  617. }
  618. if (babylonLight.intensity !== 1.0) {
  619. light.intensity = babylonLight.intensity;
  620. }
  621. if (babylonLight.range !== Number.MAX_VALUE) {
  622. light.range = babylonLight.range;
  623. }
  624. if (lightType === "spot" /* SPOT */) {
  625. var babylonSpotLight = babylonLight;
  626. if (babylonSpotLight.angle !== Math.PI / 2.0) {
  627. if (light.spot == null) {
  628. light.spot = {};
  629. }
  630. light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
  631. }
  632. if (babylonSpotLight.innerAngle !== 0) {
  633. if (light.spot == null) {
  634. light.spot = {};
  635. }
  636. light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
  637. }
  638. }
  639. if (_this._lights == null) {
  640. _this._lights = {
  641. lights: []
  642. };
  643. }
  644. _this._lights.lights.push(light);
  645. var lightReference = {
  646. light: _this._lights.lights.length - 1
  647. };
  648. // Avoid duplicating the Light's parent node if possible.
  649. var parentBabylonNode = babylonNode.parent;
  650. if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {
  651. var parentNode = _this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];
  652. if (parentNode) {
  653. var parentNodeLocalMatrix = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[0];
  654. var parentInvertNodeLocalMatrix = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[1];
  655. 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();
  656. 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();
  657. 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();
  658. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);
  659. parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);
  660. // Convert light local matrix to local matrix relative to grandparent, facing -Z
  661. var lightLocalMatrix = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Matrix[2];
  662. 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();
  663. // Undo directional light positional offset
  664. if (babylonLight instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["DirectionalLight"]) {
  665. nodeLocalTranslation.subtractInPlace(_this._exporter._babylonScene.useRightHandedSystem ? babylonLight.direction : _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3(babylonLight.direction));
  666. }
  667. 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);
  668. if (node.rotation) {
  669. nodeLocalRotation.multiplyInPlace(new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"](node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));
  670. }
  671. 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();
  672. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);
  673. lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);
  674. var parentNewScale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[0];
  675. var parentNewRotationQuaternion = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Quaternion[0];
  676. var parentNewTranslation = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TmpVectors"].Vector3[1];
  677. lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);
  678. parentNode.scale = parentNewScale.asArray();
  679. parentNode.rotation = parentNewRotationQuaternion.asArray();
  680. parentNode.translation = parentNewTranslation.asArray();
  681. if (parentNode.extensions == null) {
  682. parentNode.extensions = {};
  683. }
  684. parentNode.extensions[NAME] = lightReference;
  685. // Do not export the original node
  686. resolve(null);
  687. return;
  688. }
  689. }
  690. if (node.extensions == null) {
  691. node.extensions = {};
  692. }
  693. node.extensions[NAME] = lightReference;
  694. }
  695. }
  696. resolve(node);
  697. });
  698. };
  699. return KHR_lights_punctual;
  700. }());
  701. _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
  702. /***/ }),
  703. /***/ "./glTF/2.0/Extensions/KHR_materials_sheen.ts":
  704. /*!****************************************************!*\
  705. !*** ./glTF/2.0/Extensions/KHR_materials_sheen.ts ***!
  706. \****************************************************/
  707. /*! exports provided: KHR_materials_sheen */
  708. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  709. "use strict";
  710. __webpack_require__.r(__webpack_exports__);
  711. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return KHR_materials_sheen; });
  712. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  713. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Maths/math.vector");
  714. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__);
  715. var NAME = "KHR_materials_sheen";
  716. /**
  717. * @hidden
  718. */
  719. var KHR_materials_sheen = /** @class */ (function () {
  720. function KHR_materials_sheen(exporter) {
  721. /** Name of this extension */
  722. this.name = NAME;
  723. /** Defines whether this extension is enabled */
  724. this.enabled = true;
  725. /** Defines whether this extension is required */
  726. this.required = false;
  727. /** Reference to the glTF exporter */
  728. this._textureInfos = [];
  729. this._exportedTextures = [];
  730. this._wasUsed = false;
  731. }
  732. KHR_materials_sheen.prototype.dispose = function () {
  733. this._textureInfos = [];
  734. this._exportedTextures = [];
  735. };
  736. Object.defineProperty(KHR_materials_sheen.prototype, "wasUsed", {
  737. /** @hidden */
  738. get: function () {
  739. return this._wasUsed;
  740. },
  741. enumerable: false,
  742. configurable: true
  743. });
  744. KHR_materials_sheen.prototype._getTextureIndex = function (babylonTexture) {
  745. var textureIndex = this._exportedTextures.indexOf(babylonTexture);
  746. if (textureIndex === -1 && babylonTexture.reservedDataStore) {
  747. textureIndex = this._exportedTextures.indexOf(babylonTexture.reservedDataStore.source);
  748. }
  749. return textureIndex;
  750. };
  751. KHR_materials_sheen.prototype.postExportTexture = function (context, textureInfo, babylonTexture) {
  752. var textureIndex = this._getTextureIndex(babylonTexture);
  753. if (textureIndex > -1) {
  754. this._textureInfos[textureIndex] = textureInfo;
  755. }
  756. };
  757. KHR_materials_sheen.prototype.postExportMaterialAdditionalTextures = function (context, node, babylonMaterial) {
  758. if (babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  759. if (babylonMaterial.sheen.isEnabled && babylonMaterial.sheen.texture) {
  760. this._exportedTextures.push(babylonMaterial.sheen.texture);
  761. return [babylonMaterial.sheen.texture];
  762. }
  763. }
  764. return [];
  765. };
  766. KHR_materials_sheen.prototype.postExportMaterialAsync = function (context, node, babylonMaterial) {
  767. var _this = this;
  768. return new Promise(function (resolve, reject) {
  769. var _a;
  770. if (babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  771. if (!babylonMaterial.sheen.isEnabled) {
  772. resolve(node);
  773. return;
  774. }
  775. _this._wasUsed = true;
  776. if (node.extensions == null) {
  777. node.extensions = {};
  778. }
  779. var sheenInfo = {
  780. sheenColorFactor: babylonMaterial.sheen.color.asArray(),
  781. sheenRoughnessFactor: (_a = babylonMaterial.sheen.roughness) !== null && _a !== void 0 ? _a : 0
  782. };
  783. if (babylonMaterial.sheen.texture) {
  784. var textureIndex = _this._getTextureIndex(babylonMaterial.sheen.texture);
  785. if (textureIndex > -1) {
  786. sheenInfo.sheenColorTexture = _this._textureInfos[textureIndex];
  787. }
  788. }
  789. if (babylonMaterial.sheen.textureRoughness && !babylonMaterial.sheen.useRoughnessFromMainTexture) {
  790. var textureIndex = _this._getTextureIndex(babylonMaterial.sheen.textureRoughness);
  791. if (textureIndex > -1) {
  792. sheenInfo.sheenRoughnessTexture = _this._textureInfos[textureIndex];
  793. }
  794. }
  795. else if (babylonMaterial.sheen.texture && babylonMaterial.sheen.useRoughnessFromMainTexture) {
  796. var textureIndex = _this._getTextureIndex(babylonMaterial.sheen.texture);
  797. if (textureIndex > -1) {
  798. sheenInfo.sheenRoughnessTexture = _this._textureInfos[textureIndex];
  799. }
  800. }
  801. node.extensions[NAME] = sheenInfo;
  802. }
  803. resolve(node);
  804. });
  805. };
  806. return KHR_materials_sheen;
  807. }());
  808. _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_materials_sheen(exporter); });
  809. /***/ }),
  810. /***/ "./glTF/2.0/Extensions/KHR_materials_unlit.ts":
  811. /*!****************************************************!*\
  812. !*** ./glTF/2.0/Extensions/KHR_materials_unlit.ts ***!
  813. \****************************************************/
  814. /*! exports provided: KHR_materials_unlit */
  815. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  816. "use strict";
  817. __webpack_require__.r(__webpack_exports__);
  818. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return KHR_materials_unlit; });
  819. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  820. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Materials/PBR/pbrMaterial */ "babylonjs/Maths/math.vector");
  821. /* harmony import */ var babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__);
  822. var NAME = "KHR_materials_unlit";
  823. /**
  824. * @hidden
  825. */
  826. var KHR_materials_unlit = /** @class */ (function () {
  827. function KHR_materials_unlit(exporter) {
  828. /** Name of this extension */
  829. this.name = NAME;
  830. /** Defines whether this extension is enabled */
  831. this.enabled = true;
  832. /** Defines whether this extension is required */
  833. this.required = false;
  834. this._wasUsed = false;
  835. }
  836. Object.defineProperty(KHR_materials_unlit.prototype, "wasUsed", {
  837. /** @hidden */
  838. get: function () {
  839. return this._wasUsed;
  840. },
  841. enumerable: false,
  842. configurable: true
  843. });
  844. KHR_materials_unlit.prototype.dispose = function () {
  845. };
  846. KHR_materials_unlit.prototype.postExportMaterialAsync = function (context, node, babylonMaterial) {
  847. var _this = this;
  848. return new Promise(function (resolve, reject) {
  849. var unlitMaterial = false;
  850. if (babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["PBRMaterial"]) {
  851. unlitMaterial = babylonMaterial.unlit;
  852. }
  853. else if (babylonMaterial instanceof babylonjs_Materials_PBR_pbrMaterial__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]) {
  854. unlitMaterial = babylonMaterial.disableLighting;
  855. }
  856. if (unlitMaterial) {
  857. _this._wasUsed = true;
  858. if (node.extensions == null) {
  859. node.extensions = {};
  860. }
  861. node.extensions[NAME] = {};
  862. }
  863. resolve(node);
  864. });
  865. };
  866. return KHR_materials_unlit;
  867. }());
  868. _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_materials_unlit(exporter); });
  869. /***/ }),
  870. /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
  871. /*!******************************************************!*\
  872. !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
  873. \******************************************************/
  874. /*! exports provided: KHR_texture_transform */
  875. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  876. "use strict";
  877. __webpack_require__.r(__webpack_exports__);
  878. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return KHR_texture_transform; });
  879. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Misc/tools */ "babylonjs/Maths/math.vector");
  880. /* harmony import */ var babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__);
  881. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  882. /* harmony import */ var _shaders_textureTransform_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../shaders/textureTransform.fragment */ "./glTF/2.0/shaders/textureTransform.fragment.ts");
  883. var NAME = "KHR_texture_transform";
  884. /**
  885. * @hidden
  886. */
  887. var KHR_texture_transform = /** @class */ (function () {
  888. function KHR_texture_transform(exporter) {
  889. this._recordedTextures = [];
  890. /** Name of this extension */
  891. this.name = NAME;
  892. /** Defines whether this extension is enabled */
  893. this.enabled = true;
  894. /** Defines whether this extension is required */
  895. this.required = false;
  896. /** Reference to the glTF exporter */
  897. this._wasUsed = false;
  898. }
  899. KHR_texture_transform.prototype.dispose = function () {
  900. for (var _i = 0, _a = this._recordedTextures; _i < _a.length; _i++) {
  901. var texture = _a[_i];
  902. texture.dispose();
  903. }
  904. };
  905. Object.defineProperty(KHR_texture_transform.prototype, "wasUsed", {
  906. /** @hidden */
  907. get: function () {
  908. return this._wasUsed;
  909. },
  910. enumerable: false,
  911. configurable: true
  912. });
  913. KHR_texture_transform.prototype.postExportTexture = function (context, textureInfo, babylonTexture) {
  914. var canUseExtension = babylonTexture && ((babylonTexture.uAng === 0 && babylonTexture.wAng === 0 && babylonTexture.vAng === 0) || (babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0));
  915. if (canUseExtension) {
  916. var textureTransform = {};
  917. var transformIsRequired = false;
  918. if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {
  919. textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];
  920. transformIsRequired = true;
  921. }
  922. if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
  923. textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];
  924. transformIsRequired = true;
  925. }
  926. if (babylonTexture.wAng !== 0) {
  927. textureTransform.rotation = babylonTexture.wAng;
  928. transformIsRequired = true;
  929. }
  930. if (babylonTexture.coordinatesIndex !== 0) {
  931. textureTransform.texCoord = babylonTexture.coordinatesIndex;
  932. transformIsRequired = true;
  933. }
  934. if (!transformIsRequired) {
  935. return;
  936. }
  937. this._wasUsed = true;
  938. if (!textureInfo.extensions) {
  939. textureInfo.extensions = {};
  940. }
  941. textureInfo.extensions[NAME] = textureTransform;
  942. }
  943. };
  944. KHR_texture_transform.prototype.preExportTextureAsync = function (context, babylonTexture, mimeType) {
  945. var _this = this;
  946. return new Promise(function (resolve, reject) {
  947. var scene = babylonTexture.getScene();
  948. if (!scene) {
  949. reject(context + ": \"scene\" is not defined for Babylon texture " + babylonTexture.name + "!");
  950. return;
  951. }
  952. var bakeTextureTransform = false;
  953. /*
  954. * The KHR_texture_transform schema only supports rotation around the origin.
  955. * the texture must be baked to preserve appearance.
  956. * see: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates
  957. */
  958. if ((babylonTexture.uAng !== 0 || babylonTexture.wAng !== 0 || babylonTexture.vAng !== 0) && (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)) {
  959. bakeTextureTransform = true;
  960. }
  961. if (!bakeTextureTransform) {
  962. resolve(babylonTexture);
  963. return;
  964. }
  965. return _this._textureTransformTextureAsync(babylonTexture, scene)
  966. .then(function (proceduralTexture) {
  967. resolve(proceduralTexture);
  968. })
  969. .catch(function (e) {
  970. reject(e);
  971. });
  972. });
  973. };
  974. /**
  975. * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
  976. * @param babylonTexture
  977. * @param offset
  978. * @param rotation
  979. * @param scale
  980. * @param scene
  981. */
  982. KHR_texture_transform.prototype._textureTransformTextureAsync = function (babylonTexture, scene) {
  983. var _this = this;
  984. return new Promise(function (resolve) {
  985. var proceduralTexture = new babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["ProceduralTexture"]("" + babylonTexture.name, babylonTexture.getSize(), "textureTransform", scene);
  986. if (!proceduralTexture) {
  987. babylonjs_Misc_tools__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Cannot create procedural texture for " + babylonTexture.name + "!");
  988. resolve(babylonTexture);
  989. }
  990. proceduralTexture.reservedDataStore = {
  991. hidden: true,
  992. source: babylonTexture
  993. };
  994. _this._recordedTextures.push(proceduralTexture);
  995. proceduralTexture.coordinatesIndex = babylonTexture.coordinatesIndex;
  996. proceduralTexture.setTexture("textureSampler", babylonTexture);
  997. proceduralTexture.setMatrix("textureTransformMat", babylonTexture.getTextureMatrix());
  998. // isReady trigger creation of effect if it doesnt exist yet
  999. if (proceduralTexture.isReady()) {
  1000. proceduralTexture.render();
  1001. resolve(proceduralTexture);
  1002. }
  1003. else {
  1004. proceduralTexture.getEffect().executeWhenCompiled(function () {
  1005. proceduralTexture.render();
  1006. resolve(proceduralTexture);
  1007. });
  1008. }
  1009. });
  1010. };
  1011. return KHR_texture_transform;
  1012. }());
  1013. _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_texture_transform(exporter); });
  1014. /***/ }),
  1015. /***/ "./glTF/2.0/Extensions/index.ts":
  1016. /*!**************************************!*\
  1017. !*** ./glTF/2.0/Extensions/index.ts ***!
  1018. \**************************************/
  1019. /*! exports provided: KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen, KHR_materials_unlit */
  1020. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1021. "use strict";
  1022. __webpack_require__.r(__webpack_exports__);
  1023. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  1024. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__["KHR_texture_transform"]; });
  1025. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  1026. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  1027. /* harmony import */ var _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./KHR_materials_sheen */ "./glTF/2.0/Extensions/KHR_materials_sheen.ts");
  1028. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _KHR_materials_sheen__WEBPACK_IMPORTED_MODULE_2__["KHR_materials_sheen"]; });
  1029. /* harmony import */ var _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./KHR_materials_unlit */ "./glTF/2.0/Extensions/KHR_materials_unlit.ts");
  1030. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _KHR_materials_unlit__WEBPACK_IMPORTED_MODULE_3__["KHR_materials_unlit"]; });
  1031. /***/ }),
  1032. /***/ "./glTF/2.0/glTFAnimation.ts":
  1033. /*!***********************************!*\
  1034. !*** ./glTF/2.0/glTFAnimation.ts ***!
  1035. \***********************************/
  1036. /*! exports provided: _GLTFAnimation */
  1037. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1038. "use strict";
  1039. __webpack_require__.r(__webpack_exports__);
  1040. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _GLTFAnimation; });
  1041. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Maths/math.vector");
  1042. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  1043. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  1044. /**
  1045. * @hidden
  1046. * Enum for handling in tangent and out tangent.
  1047. */
  1048. var _TangentType;
  1049. (function (_TangentType) {
  1050. /**
  1051. * Specifies that input tangents are used.
  1052. */
  1053. _TangentType[_TangentType["INTANGENT"] = 0] = "INTANGENT";
  1054. /**
  1055. * Specifies that output tangents are used.
  1056. */
  1057. _TangentType[_TangentType["OUTTANGENT"] = 1] = "OUTTANGENT";
  1058. })(_TangentType || (_TangentType = {}));
  1059. /**
  1060. * @hidden
  1061. * Utility class for generating glTF animation data from BabylonJS.
  1062. */
  1063. var _GLTFAnimation = /** @class */ (function () {
  1064. function _GLTFAnimation() {
  1065. }
  1066. /**
  1067. * @ignore
  1068. *
  1069. * Creates glTF channel animation from BabylonJS animation.
  1070. * @param babylonTransformNode - BabylonJS mesh.
  1071. * @param animation - animation.
  1072. * @param animationChannelTargetPath - The target animation channel.
  1073. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  1074. * @param useQuaternion - Specifies if quaternions are used.
  1075. * @returns nullable IAnimationData
  1076. */
  1077. _GLTFAnimation._CreateNodeAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
  1078. var inputs = [];
  1079. var outputs = [];
  1080. var keyFrames = animation.getKeys();
  1081. var minMaxKeyFrames = _GLTFAnimation.calculateMinMaxKeyFrames(keyFrames);
  1082. var interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
  1083. var frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
  1084. var interpolation = interpolationOrBake.interpolationType;
  1085. var shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
  1086. if (shouldBakeAnimation) {
  1087. _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
  1088. }
  1089. else {
  1090. if (interpolation === "LINEAR" /* LINEAR */ || interpolation === "STEP" /* STEP */) {
  1091. _GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  1092. }
  1093. else if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
  1094. _GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  1095. }
  1096. else {
  1097. _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
  1098. }
  1099. }
  1100. if (inputs.length && outputs.length) {
  1101. var result = {
  1102. inputs: inputs,
  1103. outputs: outputs,
  1104. samplerInterpolation: interpolation,
  1105. inputsMin: shouldBakeAnimation ? minMaxKeyFrames.min : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minMaxKeyFrames.min / animation.framePerSecond),
  1106. inputsMax: shouldBakeAnimation ? minMaxKeyFrames.max : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minMaxKeyFrames.max / animation.framePerSecond)
  1107. };
  1108. return result;
  1109. }
  1110. return null;
  1111. };
  1112. _GLTFAnimation._DeduceAnimationInfo = function (animation) {
  1113. var animationChannelTargetPath = null;
  1114. var dataAccessorType = "VEC3" /* VEC3 */;
  1115. var useQuaternion = false;
  1116. var property = animation.targetProperty.split('.');
  1117. switch (property[0]) {
  1118. case 'scaling': {
  1119. animationChannelTargetPath = "scale" /* SCALE */;
  1120. break;
  1121. }
  1122. case 'position': {
  1123. animationChannelTargetPath = "translation" /* TRANSLATION */;
  1124. break;
  1125. }
  1126. case 'rotation': {
  1127. dataAccessorType = "VEC4" /* VEC4 */;
  1128. animationChannelTargetPath = "rotation" /* ROTATION */;
  1129. break;
  1130. }
  1131. case 'rotationQuaternion': {
  1132. dataAccessorType = "VEC4" /* VEC4 */;
  1133. useQuaternion = true;
  1134. animationChannelTargetPath = "rotation" /* ROTATION */;
  1135. break;
  1136. }
  1137. case 'influence': {
  1138. dataAccessorType = "SCALAR" /* SCALAR */;
  1139. animationChannelTargetPath = "weights" /* WEIGHTS */;
  1140. break;
  1141. }
  1142. default: {
  1143. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported animatable property " + property[0]);
  1144. }
  1145. }
  1146. if (animationChannelTargetPath) {
  1147. return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
  1148. }
  1149. else {
  1150. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('animation channel target path and data accessor type could be deduced');
  1151. }
  1152. return null;
  1153. };
  1154. /**
  1155. * @ignore
  1156. * Create node animations from the transform node animations
  1157. * @param babylonNode
  1158. * @param runtimeGLTFAnimation
  1159. * @param idleGLTFAnimations
  1160. * @param nodeMap
  1161. * @param nodes
  1162. * @param binaryWriter
  1163. * @param bufferViews
  1164. * @param accessors
  1165. * @param convertToRightHandedSystem
  1166. * @param animationSampleRate
  1167. */
  1168. _GLTFAnimation._CreateNodeAnimationFromNodeAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
  1169. var glTFAnimation;
  1170. if (babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
  1171. if (babylonNode.animations) {
  1172. for (var _i = 0, _a = babylonNode.animations; _i < _a.length; _i++) {
  1173. var animation = _a[_i];
  1174. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
  1175. if (animationInfo) {
  1176. glTFAnimation = {
  1177. name: animation.name,
  1178. samplers: [],
  1179. channels: []
  1180. };
  1181. _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
  1182. if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
  1183. idleGLTFAnimations.push(glTFAnimation);
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. };
  1190. /**
  1191. * @ignore
  1192. * Create individual morph animations from the mesh's morph target animation tracks
  1193. * @param babylonNode
  1194. * @param runtimeGLTFAnimation
  1195. * @param idleGLTFAnimations
  1196. * @param nodeMap
  1197. * @param nodes
  1198. * @param binaryWriter
  1199. * @param bufferViews
  1200. * @param accessors
  1201. * @param convertToRightHandedSystem
  1202. * @param animationSampleRate
  1203. */
  1204. _GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
  1205. var glTFAnimation;
  1206. if (babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Mesh"]) {
  1207. var morphTargetManager = babylonNode.morphTargetManager;
  1208. if (morphTargetManager) {
  1209. for (var i = 0; i < morphTargetManager.numTargets; ++i) {
  1210. var morphTarget = morphTargetManager.getTarget(i);
  1211. for (var _i = 0, _a = morphTarget.animations; _i < _a.length; _i++) {
  1212. var animation = _a[_i];
  1213. var combinedAnimation = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Animation"]("" + animation.name, "influence", animation.framePerSecond, animation.dataType, animation.loopMode, animation.enableBlending);
  1214. var combinedAnimationKeys = [];
  1215. var animationKeys = animation.getKeys();
  1216. for (var j = 0; j < animationKeys.length; ++j) {
  1217. var animationKey = animationKeys[j];
  1218. for (var k = 0; k < morphTargetManager.numTargets; ++k) {
  1219. if (k == i) {
  1220. combinedAnimationKeys.push(animationKey);
  1221. }
  1222. else {
  1223. combinedAnimationKeys.push({ frame: animationKey.frame, value: 0 });
  1224. }
  1225. }
  1226. }
  1227. combinedAnimation.setKeys(combinedAnimationKeys);
  1228. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimation);
  1229. if (animationInfo) {
  1230. glTFAnimation = {
  1231. name: combinedAnimation.name,
  1232. samplers: [],
  1233. channels: []
  1234. };
  1235. _GLTFAnimation.AddAnimation(animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, combinedAnimation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate, morphTargetManager.numTargets);
  1236. if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
  1237. idleGLTFAnimations.push(glTFAnimation);
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. };
  1245. /**
  1246. * @ignore
  1247. * Create node and morph animations from the animation groups
  1248. * @param babylonScene
  1249. * @param glTFAnimations
  1250. * @param nodeMap
  1251. * @param nodes
  1252. * @param binaryWriter
  1253. * @param bufferViews
  1254. * @param accessors
  1255. * @param convertToRightHandedSystemMap
  1256. * @param animationSampleRate
  1257. */
  1258. _GLTFAnimation._CreateNodeAndMorphAnimationFromAnimationGroups = function (babylonScene, glTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystemMap, animationSampleRate) {
  1259. var _a;
  1260. var glTFAnimation;
  1261. if (babylonScene.animationGroups) {
  1262. var animationGroups = babylonScene.animationGroups;
  1263. var _loop_1 = function (animationGroup) {
  1264. var morphAnimations = new Map();
  1265. var sampleAnimations = new Map();
  1266. var morphAnimationMeshes = new Set();
  1267. var animationGroupFrameDiff = animationGroup.to - animationGroup.from;
  1268. glTFAnimation = {
  1269. name: animationGroup.name,
  1270. channels: [],
  1271. samplers: []
  1272. };
  1273. var _loop_2 = function (i) {
  1274. var targetAnimation = animationGroup.targetedAnimations[i];
  1275. var target = targetAnimation.target;
  1276. var animation = targetAnimation.animation;
  1277. 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"]) {
  1278. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
  1279. if (animationInfo) {
  1280. var babylonTransformNode = target instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TransformNode"] ? target : target[0];
  1281. var convertToRightHandedSystem = convertToRightHandedSystemMap[babylonTransformNode.uniqueId];
  1282. _GLTFAnimation.AddAnimation("" + animation.name, glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
  1283. }
  1284. }
  1285. else if (target instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"] || target.length === 1 && target[0] instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"]) {
  1286. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
  1287. if (animationInfo) {
  1288. var babylonMorphTarget_1 = target instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["MorphTarget"] ? target : target[0];
  1289. if (babylonMorphTarget_1) {
  1290. var babylonMorphTargetManager_1 = babylonScene.morphTargetManagers.find(function (morphTargetManager) {
  1291. for (var j = 0; j < morphTargetManager.numTargets; ++j) {
  1292. if (morphTargetManager.getTarget(j) === babylonMorphTarget_1) {
  1293. return true;
  1294. }
  1295. }
  1296. return false;
  1297. });
  1298. if (babylonMorphTargetManager_1) {
  1299. var babylonMesh = babylonScene.meshes.find(function (mesh) {
  1300. return mesh.morphTargetManager === babylonMorphTargetManager_1;
  1301. });
  1302. if (babylonMesh) {
  1303. if (!morphAnimations.has(babylonMesh)) {
  1304. morphAnimations.set(babylonMesh, new Map());
  1305. }
  1306. (_a = morphAnimations.get(babylonMesh)) === null || _a === void 0 ? void 0 : _a.set(babylonMorphTarget_1, animation);
  1307. morphAnimationMeshes.add(babylonMesh);
  1308. sampleAnimations.set(babylonMesh, animation);
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. };
  1315. for (var i = 0; i < animationGroup.targetedAnimations.length; ++i) {
  1316. _loop_2(i);
  1317. }
  1318. morphAnimationMeshes.forEach(function (mesh) {
  1319. var morphTargetManager = mesh.morphTargetManager;
  1320. var combinedAnimationGroup = null;
  1321. var animationKeys = [];
  1322. var sampleAnimation = sampleAnimations.get(mesh);
  1323. var sampleAnimationKeys = sampleAnimation.getKeys();
  1324. var numAnimationKeys = sampleAnimationKeys.length;
  1325. /*
  1326. Due to how glTF expects morph target animation data to be formatted, we need to rearrange the individual morph target animation tracks,
  1327. such that we have a single animation, where a given keyframe input value has successive output values for each morph target belonging to the manager.
  1328. See: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
  1329. We do this via constructing a new Animation track, and interleaving the frames of each morph target animation track in the current Animation Group
  1330. We reuse the Babylon Animation data structure for ease of handling export of cubic spline animation keys, and to reuse the
  1331. existing _GLTFAnimation.AddAnimation codepath with minimal modification, however the constructed Babylon Animation is NOT intended for use in-engine.
  1332. */
  1333. for (var i = 0; i < numAnimationKeys; ++i) {
  1334. for (var j = 0; j < morphTargetManager.numTargets; ++j) {
  1335. var morphTarget = morphTargetManager.getTarget(j);
  1336. var animationsByMorphTarget = morphAnimations.get(mesh);
  1337. if (animationsByMorphTarget) {
  1338. var morphTargetAnimation = animationsByMorphTarget.get(morphTarget);
  1339. if (morphTargetAnimation) {
  1340. if (!combinedAnimationGroup) {
  1341. combinedAnimationGroup = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Animation"](animationGroup.name + "_" + mesh.name + "_MorphWeightAnimation", "influence", morphTargetAnimation.framePerSecond, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT, morphTargetAnimation.loopMode, morphTargetAnimation.enableBlending);
  1342. }
  1343. animationKeys.push(morphTargetAnimation.getKeys()[i]);
  1344. }
  1345. else {
  1346. animationKeys.push({ frame: animationGroup.from + (animationGroupFrameDiff / numAnimationKeys) * i,
  1347. value: morphTarget.influence,
  1348. inTangent: sampleAnimationKeys[0].inTangent ? 0 : undefined,
  1349. outTangent: sampleAnimationKeys[0].outTangent ? 0 : undefined
  1350. });
  1351. }
  1352. }
  1353. }
  1354. }
  1355. combinedAnimationGroup.setKeys(animationKeys);
  1356. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(combinedAnimationGroup);
  1357. if (animationInfo) {
  1358. _GLTFAnimation.AddAnimation(animationGroup.name + "_" + mesh.name + "_MorphWeightAnimation", glTFAnimation, mesh, combinedAnimationGroup, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, false, animationInfo.useQuaternion, animationSampleRate, morphTargetManager === null || morphTargetManager === void 0 ? void 0 : morphTargetManager.numTargets);
  1359. }
  1360. });
  1361. if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
  1362. glTFAnimations.push(glTFAnimation);
  1363. }
  1364. };
  1365. for (var _i = 0, animationGroups_1 = animationGroups; _i < animationGroups_1.length; _i++) {
  1366. var animationGroup = animationGroups_1[_i];
  1367. _loop_1(animationGroup);
  1368. }
  1369. }
  1370. };
  1371. _GLTFAnimation.AddAnimation = function (name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate, morphAnimationChannels) {
  1372. var animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate);
  1373. var bufferView;
  1374. var accessor;
  1375. var keyframeAccessorIndex;
  1376. var dataAccessorIndex;
  1377. var outputLength;
  1378. var animationSampler;
  1379. var animationChannel;
  1380. if (animationData) {
  1381. /*
  1382. * Now that we have the glTF converted morph target animation data,
  1383. * we can remove redundant input data so that we have n input frames,
  1384. * and morphAnimationChannels * n output frames
  1385. */
  1386. if (morphAnimationChannels) {
  1387. var index = 0;
  1388. var currentInput = 0;
  1389. var newInputs = [];
  1390. while (animationData.inputs.length > 0) {
  1391. currentInput = animationData.inputs.shift();
  1392. if (index % morphAnimationChannels == 0) {
  1393. newInputs.push(currentInput);
  1394. }
  1395. index++;
  1396. }
  1397. animationData.inputs = newInputs;
  1398. }
  1399. var nodeIndex = nodeMap[babylonTransformNode.uniqueId];
  1400. // Creates buffer view and accessor for key frames.
  1401. var byteLength = animationData.inputs.length * 4;
  1402. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, name + " keyframe data view");
  1403. bufferViews.push(bufferView);
  1404. animationData.inputs.forEach(function (input) {
  1405. binaryWriter.setFloat32(input);
  1406. });
  1407. 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]);
  1408. accessors.push(accessor);
  1409. keyframeAccessorIndex = accessors.length - 1;
  1410. // create bufferview and accessor for keyed values.
  1411. outputLength = animationData.outputs.length;
  1412. byteLength = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetDataAccessorElementCount(dataAccessorType) * 4 * animationData.outputs.length;
  1413. // check for in and out tangents
  1414. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, name + " data view");
  1415. bufferViews.push(bufferView);
  1416. animationData.outputs.forEach(function (output) {
  1417. output.forEach(function (entry) {
  1418. binaryWriter.setFloat32(entry);
  1419. });
  1420. });
  1421. accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateAccessor(bufferViews.length - 1, name + " data", dataAccessorType, 5126 /* FLOAT */, outputLength, null, null, null);
  1422. accessors.push(accessor);
  1423. dataAccessorIndex = accessors.length - 1;
  1424. // create sampler
  1425. animationSampler = {
  1426. interpolation: animationData.samplerInterpolation,
  1427. input: keyframeAccessorIndex,
  1428. output: dataAccessorIndex
  1429. };
  1430. glTFAnimation.samplers.push(animationSampler);
  1431. // create channel
  1432. animationChannel = {
  1433. sampler: glTFAnimation.samplers.length - 1,
  1434. target: {
  1435. node: nodeIndex,
  1436. path: animationChannelTargetPath
  1437. }
  1438. };
  1439. glTFAnimation.channels.push(animationChannel);
  1440. }
  1441. };
  1442. /**
  1443. * Create a baked animation
  1444. * @param babylonTransformNode BabylonJS mesh
  1445. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  1446. * @param animationChannelTargetPath animation target channel
  1447. * @param minFrame minimum animation frame
  1448. * @param maxFrame maximum animation frame
  1449. * @param fps frames per second of the animation
  1450. * @param inputs input key frames of the animation
  1451. * @param outputs output key frame data of the animation
  1452. * @param convertToRightHandedSystem converts the values to right-handed
  1453. * @param useQuaternion specifies if quaternions should be used
  1454. */
  1455. _GLTFAnimation._CreateBakedAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion) {
  1456. var value;
  1457. var quaternionCache = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  1458. var previousTime = null;
  1459. var time;
  1460. var maxUsedFrame = null;
  1461. var currKeyFrame = null;
  1462. var nextKeyFrame = null;
  1463. var prevKeyFrame = null;
  1464. var endFrame = null;
  1465. minMaxFrames.min = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minFrame / fps);
  1466. var keyFrames = animation.getKeys();
  1467. for (var i = 0, length_1 = keyFrames.length; i < length_1; ++i) {
  1468. endFrame = null;
  1469. currKeyFrame = keyFrames[i];
  1470. if (i + 1 < length_1) {
  1471. nextKeyFrame = keyFrames[i + 1];
  1472. if (currKeyFrame.value.equals && currKeyFrame.value.equals(nextKeyFrame.value) || currKeyFrame.value === nextKeyFrame.value) {
  1473. if (i === 0) { // set the first frame to itself
  1474. endFrame = currKeyFrame.frame;
  1475. }
  1476. else {
  1477. continue;
  1478. }
  1479. }
  1480. else {
  1481. endFrame = nextKeyFrame.frame;
  1482. }
  1483. }
  1484. else {
  1485. // at the last key frame
  1486. prevKeyFrame = keyFrames[i - 1];
  1487. if (currKeyFrame.value.equals && currKeyFrame.value.equals(prevKeyFrame.value) || currKeyFrame.value === prevKeyFrame.value) {
  1488. continue;
  1489. }
  1490. else {
  1491. endFrame = maxFrame;
  1492. }
  1493. }
  1494. if (endFrame) {
  1495. for (var f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {
  1496. time = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(f / fps);
  1497. if (time === previousTime) {
  1498. continue;
  1499. }
  1500. previousTime = time;
  1501. maxUsedFrame = time;
  1502. var state = {
  1503. key: 0,
  1504. repeatCount: 0,
  1505. loopMode: animation.loopMode
  1506. };
  1507. value = animation._interpolate(f, state);
  1508. _GLTFAnimation._SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  1509. }
  1510. }
  1511. }
  1512. if (maxUsedFrame) {
  1513. minMaxFrames.max = maxUsedFrame;
  1514. }
  1515. };
  1516. _GLTFAnimation._ConvertFactorToVector3OrQuaternion = function (factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
  1517. var property;
  1518. var componentName;
  1519. var value = null;
  1520. var basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1521. 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.
  1522. property = animation.targetProperty.split('.');
  1523. componentName = property ? property[1] : ''; // x, y, or z component
  1524. 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);
  1525. switch (componentName) {
  1526. case 'x': {
  1527. value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  1528. break;
  1529. }
  1530. case 'y': {
  1531. value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  1532. break;
  1533. }
  1534. case 'z': {
  1535. value[componentName] = (convertToRightHandedSystem && !useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  1536. break;
  1537. }
  1538. case 'w': {
  1539. value.w = factor;
  1540. break;
  1541. }
  1542. default: {
  1543. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("glTFAnimation: Unsupported component type \"" + componentName + "\" for scale animation!");
  1544. }
  1545. }
  1546. }
  1547. return value;
  1548. };
  1549. _GLTFAnimation._SetInterpolatedValue = function (babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  1550. var animationType = animation.dataType;
  1551. var cacheValue;
  1552. inputs.push(time);
  1553. if (typeof value === "number" && babylonTransformNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
  1554. value = this._ConvertFactorToVector3OrQuaternion(value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1555. }
  1556. if (value) {
  1557. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1558. if (useQuaternion) {
  1559. quaternionCache = value;
  1560. }
  1561. else {
  1562. cacheValue = value;
  1563. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);
  1564. }
  1565. if (convertToRightHandedSystem) {
  1566. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(quaternionCache);
  1567. if (!babylonTransformNode.parent) {
  1568. quaternionCache = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(quaternionCache);
  1569. }
  1570. }
  1571. outputs.push(quaternionCache.asArray());
  1572. }
  1573. else if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
  1574. outputs.push([value]);
  1575. }
  1576. else { // scaling and position animation
  1577. cacheValue = value;
  1578. if (convertToRightHandedSystem && (animationChannelTargetPath !== "scale" /* SCALE */)) {
  1579. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(cacheValue);
  1580. if (!babylonTransformNode.parent) {
  1581. cacheValue.x *= -1;
  1582. cacheValue.z *= -1;
  1583. }
  1584. }
  1585. outputs.push(cacheValue.asArray());
  1586. }
  1587. }
  1588. };
  1589. /**
  1590. * Creates linear animation from the animation key frames
  1591. * @param babylonTransformNode BabylonJS mesh
  1592. * @param animation BabylonJS animation
  1593. * @param animationChannelTargetPath The target animation channel
  1594. * @param frameDelta The difference between the last and first frame of the animation
  1595. * @param inputs Array to store the key frame times
  1596. * @param outputs Array to store the key frame data
  1597. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1598. * @param useQuaternion Specifies if quaternions are used in the animation
  1599. */
  1600. _GLTFAnimation._CreateLinearOrStepAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  1601. for (var _i = 0, _a = animation.getKeys(); _i < _a.length; _i++) {
  1602. var keyFrame = _a[_i];
  1603. inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
  1604. _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  1605. }
  1606. };
  1607. /**
  1608. * Creates cubic spline animation from the animation key frames
  1609. * @param babylonTransformNode BabylonJS mesh
  1610. * @param animation BabylonJS animation
  1611. * @param animationChannelTargetPath The target animation channel
  1612. * @param frameDelta The difference between the last and first frame of the animation
  1613. * @param inputs Array to store the key frame times
  1614. * @param outputs Array to store the key frame data
  1615. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  1616. * @param useQuaternion Specifies if quaternions are used in the animation
  1617. */
  1618. _GLTFAnimation._CreateCubicSplineAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  1619. animation.getKeys().forEach(function (keyFrame) {
  1620. inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
  1621. _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  1622. _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  1623. _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  1624. });
  1625. };
  1626. _GLTFAnimation._GetBasePositionRotationOrScale = function (babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
  1627. var basePositionRotationOrScale;
  1628. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1629. if (useQuaternion) {
  1630. if (babylonTransformNode.rotationQuaternion) {
  1631. basePositionRotationOrScale = babylonTransformNode.rotationQuaternion.asArray();
  1632. if (convertToRightHandedSystem) {
  1633. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(basePositionRotationOrScale);
  1634. if (!babylonTransformNode.parent) {
  1635. 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();
  1636. }
  1637. }
  1638. }
  1639. else {
  1640. basePositionRotationOrScale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity().asArray();
  1641. }
  1642. }
  1643. else {
  1644. basePositionRotationOrScale = babylonTransformNode.rotation.asArray();
  1645. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalArray3FromRef(basePositionRotationOrScale);
  1646. }
  1647. }
  1648. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1649. basePositionRotationOrScale = babylonTransformNode.position.asArray();
  1650. if (convertToRightHandedSystem) {
  1651. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionArray3FromRef(basePositionRotationOrScale);
  1652. }
  1653. }
  1654. else { // scale
  1655. basePositionRotationOrScale = babylonTransformNode.scaling.asArray();
  1656. }
  1657. return basePositionRotationOrScale;
  1658. };
  1659. /**
  1660. * Adds a key frame value
  1661. * @param keyFrame
  1662. * @param animation
  1663. * @param outputs
  1664. * @param animationChannelTargetPath
  1665. * @param basePositionRotationOrScale
  1666. * @param convertToRightHandedSystem
  1667. * @param useQuaternion
  1668. */
  1669. _GLTFAnimation._AddKeyframeValue = function (keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion) {
  1670. var value;
  1671. var newPositionRotationOrScale;
  1672. var animationType = animation.dataType;
  1673. if (animationType === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3) {
  1674. value = keyFrame.value.asArray();
  1675. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1676. var array = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(value);
  1677. var rotationQuaternion = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(array.y, array.x, array.z);
  1678. if (convertToRightHandedSystem) {
  1679. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(rotationQuaternion);
  1680. if (!babylonTransformNode.parent) {
  1681. rotationQuaternion = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(rotationQuaternion);
  1682. }
  1683. }
  1684. value = rotationQuaternion.asArray();
  1685. }
  1686. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1687. if (convertToRightHandedSystem) {
  1688. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalArray3FromRef(value);
  1689. if (!babylonTransformNode.parent) {
  1690. value[0] *= -1;
  1691. value[2] *= -1;
  1692. }
  1693. }
  1694. }
  1695. outputs.push(value); // scale vector.
  1696. }
  1697. else if (animationType === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_FLOAT) {
  1698. if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
  1699. outputs.push([keyFrame.value]);
  1700. }
  1701. else { // handles single component x, y, z or w component animation by using a base property and animating over a component.
  1702. newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1703. if (newPositionRotationOrScale) {
  1704. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1705. var posRotScale = useQuaternion ? newPositionRotationOrScale : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();
  1706. if (convertToRightHandedSystem) {
  1707. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(posRotScale);
  1708. if (!babylonTransformNode.parent) {
  1709. posRotScale = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(posRotScale);
  1710. }
  1711. }
  1712. outputs.push(posRotScale.asArray());
  1713. }
  1714. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1715. if (convertToRightHandedSystem) {
  1716. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(newPositionRotationOrScale);
  1717. if (!babylonTransformNode.parent) {
  1718. newPositionRotationOrScale.x *= -1;
  1719. newPositionRotationOrScale.z *= -1;
  1720. }
  1721. }
  1722. }
  1723. outputs.push(newPositionRotationOrScale.asArray());
  1724. }
  1725. }
  1726. }
  1727. else if (animationType === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION) {
  1728. value = keyFrame.value.normalize().asArray();
  1729. if (convertToRightHandedSystem) {
  1730. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(value);
  1731. if (!babylonTransformNode.parent) {
  1732. 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();
  1733. }
  1734. }
  1735. outputs.push(value);
  1736. }
  1737. else {
  1738. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('glTFAnimation: Unsupported key frame values for animation!');
  1739. }
  1740. };
  1741. /**
  1742. * Determine the interpolation based on the key frames
  1743. * @param keyFrames
  1744. * @param animationChannelTargetPath
  1745. * @param useQuaternion
  1746. */
  1747. _GLTFAnimation._DeduceInterpolation = function (keyFrames, animationChannelTargetPath, useQuaternion) {
  1748. var interpolationType;
  1749. var shouldBakeAnimation = false;
  1750. var key;
  1751. if (animationChannelTargetPath === "rotation" /* ROTATION */ && !useQuaternion) {
  1752. return { interpolationType: "LINEAR" /* LINEAR */, shouldBakeAnimation: true };
  1753. }
  1754. for (var i = 0, length_2 = keyFrames.length; i < length_2; ++i) {
  1755. key = keyFrames[i];
  1756. if (key.inTangent || key.outTangent) {
  1757. if (interpolationType) {
  1758. if (interpolationType !== "CUBICSPLINE" /* CUBICSPLINE */) {
  1759. interpolationType = "LINEAR" /* LINEAR */;
  1760. shouldBakeAnimation = true;
  1761. break;
  1762. }
  1763. }
  1764. else {
  1765. interpolationType = "CUBICSPLINE" /* CUBICSPLINE */;
  1766. }
  1767. }
  1768. else {
  1769. if (interpolationType) {
  1770. if (interpolationType === "CUBICSPLINE" /* CUBICSPLINE */ ||
  1771. (key.interpolation && (key.interpolation === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP) && interpolationType !== "STEP" /* STEP */)) {
  1772. interpolationType = "LINEAR" /* LINEAR */;
  1773. shouldBakeAnimation = true;
  1774. break;
  1775. }
  1776. }
  1777. else {
  1778. if (key.interpolation && (key.interpolation === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP)) {
  1779. interpolationType = "STEP" /* STEP */;
  1780. }
  1781. else {
  1782. interpolationType = "LINEAR" /* LINEAR */;
  1783. }
  1784. }
  1785. }
  1786. }
  1787. if (!interpolationType) {
  1788. interpolationType = "LINEAR" /* LINEAR */;
  1789. }
  1790. return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
  1791. };
  1792. /**
  1793. * Adds an input tangent or output tangent to the output data
  1794. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  1795. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  1796. * @param outputs The animation data by keyframe
  1797. * @param animationChannelTargetPath The target animation channel
  1798. * @param interpolation The interpolation type
  1799. * @param keyFrame The key frame with the animation data
  1800. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  1801. * @param useQuaternion Specifies if quaternions are used
  1802. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  1803. */
  1804. _GLTFAnimation.AddSplineTangent = function (babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem) {
  1805. var tangent;
  1806. var tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
  1807. if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
  1808. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1809. if (tangentValue) {
  1810. if (useQuaternion) {
  1811. tangent = tangentValue.asArray();
  1812. }
  1813. else {
  1814. var array = tangentValue;
  1815. tangent = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(array.y, array.x, array.z).asArray();
  1816. }
  1817. if (convertToRightHandedSystem) {
  1818. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(tangent);
  1819. if (!babylonTransformNode.parent) {
  1820. 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();
  1821. }
  1822. }
  1823. }
  1824. else {
  1825. tangent = [0, 0, 0, 0];
  1826. }
  1827. }
  1828. else if (animationChannelTargetPath === "weights" /* WEIGHTS */) {
  1829. if (tangentValue) {
  1830. tangent = [tangentValue];
  1831. }
  1832. else {
  1833. tangent = [0];
  1834. }
  1835. }
  1836. else {
  1837. if (tangentValue) {
  1838. tangent = tangentValue.asArray();
  1839. if (convertToRightHandedSystem) {
  1840. if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1841. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionArray3FromRef(tangent);
  1842. if (!babylonTransformNode.parent) {
  1843. tangent[0] *= -1; // x
  1844. tangent[2] *= -1; // z
  1845. }
  1846. }
  1847. }
  1848. }
  1849. else {
  1850. tangent = [0, 0, 0];
  1851. }
  1852. }
  1853. outputs.push(tangent);
  1854. }
  1855. };
  1856. /**
  1857. * Get the minimum and maximum key frames' frame values
  1858. * @param keyFrames animation key frames
  1859. * @returns the minimum and maximum key frame value
  1860. */
  1861. _GLTFAnimation.calculateMinMaxKeyFrames = function (keyFrames) {
  1862. var min = Infinity;
  1863. var max = -Infinity;
  1864. keyFrames.forEach(function (keyFrame) {
  1865. min = Math.min(min, keyFrame.frame);
  1866. max = Math.max(max, keyFrame.frame);
  1867. });
  1868. return { min: min, max: max };
  1869. };
  1870. return _GLTFAnimation;
  1871. }());
  1872. /***/ }),
  1873. /***/ "./glTF/2.0/glTFData.ts":
  1874. /*!******************************!*\
  1875. !*** ./glTF/2.0/glTFData.ts ***!
  1876. \******************************/
  1877. /*! exports provided: GLTFData */
  1878. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1879. "use strict";
  1880. __webpack_require__.r(__webpack_exports__);
  1881. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return GLTFData; });
  1882. /**
  1883. * Class for holding and downloading glTF file data
  1884. */
  1885. var GLTFData = /** @class */ (function () {
  1886. /**
  1887. * Initializes the glTF file object
  1888. */
  1889. function GLTFData() {
  1890. this.glTFFiles = {};
  1891. }
  1892. /**
  1893. * Downloads the glTF data as files based on their names and data
  1894. */
  1895. GLTFData.prototype.downloadFiles = function () {
  1896. /**
  1897. * Checks for a matching suffix at the end of a string (for ES5 and lower)
  1898. * @param str Source string
  1899. * @param suffix Suffix to search for in the source string
  1900. * @returns Boolean indicating whether the suffix was found (true) or not (false)
  1901. */
  1902. function endsWith(str, suffix) {
  1903. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  1904. }
  1905. for (var key in this.glTFFiles) {
  1906. var link = document.createElement('a');
  1907. document.body.appendChild(link);
  1908. link.setAttribute("type", "hidden");
  1909. link.download = key;
  1910. var blob = this.glTFFiles[key];
  1911. var mimeType = void 0;
  1912. if (endsWith(key, ".glb")) {
  1913. mimeType = { type: "model/gltf-binary" };
  1914. }
  1915. else if (endsWith(key, ".bin")) {
  1916. mimeType = { type: "application/octet-stream" };
  1917. }
  1918. else if (endsWith(key, ".gltf")) {
  1919. mimeType = { type: "model/gltf+json" };
  1920. }
  1921. else if (endsWith(key, ".jpeg" || false)) {
  1922. mimeType = { type: "image/jpeg" /* JPEG */ };
  1923. }
  1924. else if (endsWith(key, ".png")) {
  1925. mimeType = { type: "image/png" /* PNG */ };
  1926. }
  1927. link.href = window.URL.createObjectURL(new Blob([blob], mimeType));
  1928. link.click();
  1929. }
  1930. };
  1931. return GLTFData;
  1932. }());
  1933. /***/ }),
  1934. /***/ "./glTF/2.0/glTFExporter.ts":
  1935. /*!**********************************!*\
  1936. !*** ./glTF/2.0/glTFExporter.ts ***!
  1937. \**********************************/
  1938. /*! exports provided: _Exporter, _BinaryWriter */
  1939. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1940. "use strict";
  1941. __webpack_require__.r(__webpack_exports__);
  1942. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _Exporter; });
  1943. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _BinaryWriter; });
  1944. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  1945. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Maths/math.vector");
  1946. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  1947. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  1948. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  1949. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  1950. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  1951. /**
  1952. * Converts Babylon Scene into glTF 2.0.
  1953. * @hidden
  1954. */
  1955. var _Exporter = /** @class */ (function () {
  1956. /**
  1957. * Creates a glTF Exporter instance, which can accept optional exporter options
  1958. * @param babylonScene Babylon scene object
  1959. * @param options Options to modify the behavior of the exporter
  1960. */
  1961. function _Exporter(babylonScene, options) {
  1962. /*
  1963. * Specifies if root Babylon empty nodes that act as a coordinate space transform should be included in export
  1964. */
  1965. this._includeCoordinateSystemConversionNodes = false;
  1966. this._extensions = {};
  1967. this._glTF = {
  1968. asset: { generator: "BabylonJS", version: "2.0" }
  1969. };
  1970. this._babylonScene = babylonScene;
  1971. this._bufferViews = [];
  1972. this._accessors = [];
  1973. this._meshes = [];
  1974. this._scenes = [];
  1975. this._nodes = [];
  1976. this._images = [];
  1977. this._materials = [];
  1978. this._materialMap = [];
  1979. this._textures = [];
  1980. this._samplers = [];
  1981. this._skins = [];
  1982. this._animations = [];
  1983. this._imageData = {};
  1984. this._orderedImageData = [];
  1985. this._options = options || {};
  1986. this._animationSampleRate = options && options.animationSampleRate ? options.animationSampleRate : 1 / 60;
  1987. this._includeCoordinateSystemConversionNodes = options && options.includeCoordinateSystemConversionNodes ? true : false;
  1988. this._glTFMaterialExporter = new _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_2__["_GLTFMaterialExporter"](this);
  1989. this._loadExtensions();
  1990. }
  1991. _Exporter.prototype._applyExtension = function (node, extensions, index, actionAsync) {
  1992. var _this = this;
  1993. if (index >= extensions.length) {
  1994. return Promise.resolve(node);
  1995. }
  1996. var currentPromise = actionAsync(extensions[index], node);
  1997. if (!currentPromise) {
  1998. return this._applyExtension(node, extensions, index + 1, actionAsync);
  1999. }
  2000. return currentPromise.then(function (newNode) { return _this._applyExtension(newNode, extensions, index + 1, actionAsync); });
  2001. };
  2002. _Exporter.prototype._applyExtensions = function (node, actionAsync) {
  2003. var extensions = [];
  2004. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  2005. var name_1 = _a[_i];
  2006. extensions.push(this._extensions[name_1]);
  2007. }
  2008. return this._applyExtension(node, extensions, 0, actionAsync);
  2009. };
  2010. _Exporter.prototype._extensionsPreExportTextureAsync = function (context, babylonTexture, mimeType) {
  2011. return this._applyExtensions(babylonTexture, function (extension, node) { return extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType); });
  2012. };
  2013. _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
  2014. return this._applyExtensions(meshPrimitive, function (extension, node) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter); });
  2015. };
  2016. _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode, nodeMap) {
  2017. return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap); });
  2018. };
  2019. _Exporter.prototype._extensionsPostExportMaterialAsync = function (context, material, babylonMaterial) {
  2020. return this._applyExtensions(material, function (extension, node) { return extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial); });
  2021. };
  2022. _Exporter.prototype._extensionsPostExportMaterialAdditionalTextures = function (context, material, babylonMaterial) {
  2023. var output = [];
  2024. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  2025. var name_2 = _a[_i];
  2026. var extension = this._extensions[name_2];
  2027. if (extension.postExportMaterialAdditionalTextures) {
  2028. output.push.apply(output, extension.postExportMaterialAdditionalTextures(context, material, babylonMaterial));
  2029. }
  2030. }
  2031. return output;
  2032. };
  2033. _Exporter.prototype._extensionsPostExportTextures = function (context, textureInfo, babylonTexture) {
  2034. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  2035. var name_3 = _a[_i];
  2036. var extension = this._extensions[name_3];
  2037. if (extension.postExportTexture) {
  2038. extension.postExportTexture(context, textureInfo, babylonTexture);
  2039. }
  2040. }
  2041. };
  2042. _Exporter.prototype._forEachExtensions = function (action) {
  2043. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  2044. var name_4 = _a[_i];
  2045. var extension = this._extensions[name_4];
  2046. if (extension.enabled) {
  2047. action(extension);
  2048. }
  2049. }
  2050. };
  2051. _Exporter.prototype._extensionsOnExporting = function () {
  2052. var _this = this;
  2053. this._forEachExtensions(function (extension) {
  2054. if (extension.wasUsed) {
  2055. if (_this._glTF.extensionsUsed == null) {
  2056. _this._glTF.extensionsUsed = [];
  2057. }
  2058. if (_this._glTF.extensionsUsed.indexOf(extension.name) === -1) {
  2059. _this._glTF.extensionsUsed.push(extension.name);
  2060. }
  2061. if (extension.required) {
  2062. if (_this._glTF.extensionsRequired == null) {
  2063. _this._glTF.extensionsRequired = [];
  2064. }
  2065. if (_this._glTF.extensionsRequired.indexOf(extension.name) === -1) {
  2066. _this._glTF.extensionsRequired.push(extension.name);
  2067. }
  2068. }
  2069. if (_this._glTF.extensions == null) {
  2070. _this._glTF.extensions = {};
  2071. }
  2072. if (extension.onExporting) {
  2073. extension.onExporting();
  2074. }
  2075. }
  2076. });
  2077. };
  2078. /**
  2079. * Load glTF serializer extensions
  2080. */
  2081. _Exporter.prototype._loadExtensions = function () {
  2082. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  2083. var name_5 = _a[_i];
  2084. var extension = _Exporter._ExtensionFactories[name_5](this);
  2085. this._extensions[name_5] = extension;
  2086. }
  2087. };
  2088. _Exporter.prototype.dispose = function () {
  2089. for (var extensionKey in this._extensions) {
  2090. var extension = this._extensions[extensionKey];
  2091. extension.dispose();
  2092. }
  2093. };
  2094. /**
  2095. * Registers a glTF exporter extension
  2096. * @param name Name of the extension to export
  2097. * @param factory The factory function that creates the exporter extension
  2098. */
  2099. _Exporter.RegisterExtension = function (name, factory) {
  2100. if (_Exporter.UnregisterExtension(name)) {
  2101. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Extension with the name " + name + " already exists");
  2102. }
  2103. _Exporter._ExtensionFactories[name] = factory;
  2104. _Exporter._ExtensionNames.push(name);
  2105. };
  2106. /**
  2107. * Un-registers an exporter extension
  2108. * @param name The name fo the exporter extension
  2109. * @returns A boolean indicating whether the extension has been un-registered
  2110. */
  2111. _Exporter.UnregisterExtension = function (name) {
  2112. if (!_Exporter._ExtensionFactories[name]) {
  2113. return false;
  2114. }
  2115. delete _Exporter._ExtensionFactories[name];
  2116. var index = _Exporter._ExtensionNames.indexOf(name);
  2117. if (index !== -1) {
  2118. _Exporter._ExtensionNames.splice(index, 1);
  2119. }
  2120. return true;
  2121. };
  2122. _Exporter.prototype.reorderIndicesBasedOnPrimitiveMode = function (submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter) {
  2123. switch (primitiveMode) {
  2124. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode: {
  2125. if (!byteOffset) {
  2126. byteOffset = 0;
  2127. }
  2128. for (var i = submesh.indexStart, length_1 = submesh.indexStart + submesh.indexCount; i < length_1; i = i + 3) {
  2129. var index = byteOffset + i * 4;
  2130. // swap the second and third indices
  2131. var secondIndex = binaryWriter.getUInt32(index + 4);
  2132. var thirdIndex = binaryWriter.getUInt32(index + 8);
  2133. binaryWriter.setUInt32(thirdIndex, index + 4);
  2134. binaryWriter.setUInt32(secondIndex, index + 8);
  2135. }
  2136. break;
  2137. }
  2138. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFanDrawMode: {
  2139. for (var i = submesh.indexStart + submesh.indexCount - 1, start = submesh.indexStart; i >= start; --i) {
  2140. binaryWriter.setUInt32(babylonIndices[i], byteOffset);
  2141. byteOffset += 4;
  2142. }
  2143. break;
  2144. }
  2145. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleStripDrawMode: {
  2146. if (submesh.indexCount >= 3) {
  2147. binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 2], byteOffset + 4);
  2148. binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 1], byteOffset + 8);
  2149. }
  2150. break;
  2151. }
  2152. }
  2153. };
  2154. /**
  2155. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  2156. * clock-wise during export to glTF
  2157. * @param submesh BabylonJS submesh
  2158. * @param primitiveMode Primitive mode of the mesh
  2159. * @param sideOrientation the winding order of the submesh
  2160. * @param vertexBufferKind The type of vertex attribute
  2161. * @param meshAttributeArray The vertex attribute data
  2162. * @param byteOffset The offset to the binary data
  2163. * @param binaryWriter The binary data for the glTF file
  2164. * @param convertToRightHandedSystem Converts the values to right-handed
  2165. */
  2166. _Exporter.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
  2167. if (convertToRightHandedSystem && sideOrientation === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].ClockWiseSideOrientation) {
  2168. switch (primitiveMode) {
  2169. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode: {
  2170. this.reorderTriangleFillMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem);
  2171. break;
  2172. }
  2173. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleStripDrawMode: {
  2174. this.reorderTriangleStripDrawMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem);
  2175. break;
  2176. }
  2177. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFanDrawMode: {
  2178. this.reorderTriangleFanMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem);
  2179. break;
  2180. }
  2181. }
  2182. }
  2183. };
  2184. /**
  2185. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  2186. * clock-wise during export to glTF
  2187. * @param submesh BabylonJS submesh
  2188. * @param primitiveMode Primitive mode of the mesh
  2189. * @param sideOrientation the winding order of the submesh
  2190. * @param vertexBufferKind The type of vertex attribute
  2191. * @param meshAttributeArray The vertex attribute data
  2192. * @param byteOffset The offset to the binary data
  2193. * @param binaryWriter The binary data for the glTF file
  2194. * @param convertToRightHandedSystem Converts the values to right-handed
  2195. */
  2196. _Exporter.prototype.reorderTriangleFillMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
  2197. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  2198. if (vertexBuffer) {
  2199. var stride = vertexBuffer.byteStride / babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  2200. if (submesh.verticesCount % 3 !== 0) {
  2201. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('The submesh vertices for the triangle fill mode is not divisible by 3!');
  2202. }
  2203. else {
  2204. var vertexData = [];
  2205. var index = 0;
  2206. switch (vertexBufferKind) {
  2207. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind:
  2208. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  2209. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  2210. index = x * stride;
  2211. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  2212. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  2213. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + stride));
  2214. }
  2215. break;
  2216. }
  2217. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  2218. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  2219. index = x * stride;
  2220. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  2221. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + 2 * stride));
  2222. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + stride));
  2223. }
  2224. break;
  2225. }
  2226. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  2227. var size = vertexBuffer.getSize();
  2228. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {
  2229. index = x * stride;
  2230. if (size === 4) {
  2231. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  2232. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + 2 * stride));
  2233. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index + stride));
  2234. }
  2235. else {
  2236. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  2237. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  2238. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + stride));
  2239. }
  2240. }
  2241. break;
  2242. }
  2243. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  2244. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  2245. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  2246. index = x * stride;
  2247. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index));
  2248. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index + 2 * stride));
  2249. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index + stride));
  2250. }
  2251. break;
  2252. }
  2253. default: {
  2254. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  2255. }
  2256. }
  2257. this.writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem);
  2258. }
  2259. }
  2260. else {
  2261. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("reorderTriangleFillMode: Vertex Buffer Kind " + vertexBufferKind + " not present!");
  2262. }
  2263. };
  2264. /**
  2265. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  2266. * clock-wise during export to glTF
  2267. * @param submesh BabylonJS submesh
  2268. * @param primitiveMode Primitive mode of the mesh
  2269. * @param sideOrientation the winding order of the submesh
  2270. * @param vertexBufferKind The type of vertex attribute
  2271. * @param meshAttributeArray The vertex attribute data
  2272. * @param byteOffset The offset to the binary data
  2273. * @param binaryWriter The binary data for the glTF file
  2274. * @param convertToRightHandedSystem Converts the values to right-handed
  2275. */
  2276. _Exporter.prototype.reorderTriangleStripDrawMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
  2277. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  2278. if (vertexBuffer) {
  2279. var stride = vertexBuffer.byteStride / babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  2280. var vertexData = [];
  2281. var index = 0;
  2282. switch (vertexBufferKind) {
  2283. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind:
  2284. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  2285. index = submesh.verticesStart;
  2286. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  2287. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index + stride));
  2288. break;
  2289. }
  2290. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  2291. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2292. index = x * stride;
  2293. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  2294. }
  2295. break;
  2296. }
  2297. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  2298. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2299. index = x * stride;
  2300. 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));
  2301. }
  2302. break;
  2303. }
  2304. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  2305. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  2306. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2307. index = x * stride;
  2308. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index));
  2309. }
  2310. break;
  2311. }
  2312. default: {
  2313. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  2314. }
  2315. }
  2316. this.writeVertexAttributeData(vertexData, byteOffset + 12, vertexBufferKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem);
  2317. }
  2318. else {
  2319. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("reorderTriangleStripDrawMode: Vertex buffer kind " + vertexBufferKind + " not present!");
  2320. }
  2321. };
  2322. /**
  2323. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  2324. * clock-wise during export to glTF
  2325. * @param submesh BabylonJS submesh
  2326. * @param primitiveMode Primitive mode of the mesh
  2327. * @param sideOrientation the winding order of the submesh
  2328. * @param vertexBufferKind The type of vertex attribute
  2329. * @param meshAttributeArray The vertex attribute data
  2330. * @param byteOffset The offset to the binary data
  2331. * @param binaryWriter The binary data for the glTF file
  2332. * @param convertToRightHandedSystem Converts the values to right-handed
  2333. */
  2334. _Exporter.prototype.reorderTriangleFanMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter, convertToRightHandedSystem) {
  2335. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  2336. if (vertexBuffer) {
  2337. var stride = vertexBuffer.byteStride / babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  2338. var vertexData = [];
  2339. var index = 0;
  2340. switch (vertexBufferKind) {
  2341. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind:
  2342. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  2343. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2344. index = x * stride;
  2345. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index));
  2346. }
  2347. break;
  2348. }
  2349. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  2350. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2351. index = x * stride;
  2352. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  2353. }
  2354. break;
  2355. }
  2356. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  2357. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2358. index = x * stride;
  2359. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index));
  2360. 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));
  2361. }
  2362. break;
  2363. }
  2364. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  2365. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  2366. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  2367. index = x * stride;
  2368. vertexData.push(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"].FromArray(meshAttributeArray, index));
  2369. }
  2370. break;
  2371. }
  2372. default: {
  2373. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  2374. }
  2375. }
  2376. this.writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem);
  2377. }
  2378. else {
  2379. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("reorderTriangleFanMode: Vertex buffer kind " + vertexBufferKind + " not present!");
  2380. }
  2381. };
  2382. /**
  2383. * Writes the vertex attribute data to binary
  2384. * @param vertices The vertices to write to the binary writer
  2385. * @param byteOffset The offset into the binary writer to overwrite binary data
  2386. * @param vertexAttributeKind The vertex attribute type
  2387. * @param meshAttributeArray The vertex attribute data
  2388. * @param binaryWriter The writer containing the binary data
  2389. * @param convertToRightHandedSystem Converts the values to right-handed
  2390. */
  2391. _Exporter.prototype.writeVertexAttributeData = function (vertices, byteOffset, vertexAttributeKind, meshAttributeArray, binaryWriter, convertToRightHandedSystem) {
  2392. for (var _i = 0, vertices_1 = vertices; _i < vertices_1.length; _i++) {
  2393. var vertex = vertices_1[_i];
  2394. if (convertToRightHandedSystem && !(vertexAttributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind) && !(vertex instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"])) {
  2395. if (vertex instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"]) {
  2396. if (vertexAttributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind) {
  2397. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(vertex);
  2398. }
  2399. else if (vertexAttributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind) {
  2400. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(vertex);
  2401. }
  2402. else {
  2403. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('Unsupported vertex attribute kind!');
  2404. }
  2405. }
  2406. else {
  2407. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedVector4FromRef(vertex);
  2408. }
  2409. }
  2410. if (vertexAttributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind) {
  2411. vertex.normalize();
  2412. }
  2413. else if (vertexAttributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind && vertex instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"]) {
  2414. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._NormalizeTangentFromRef(vertex);
  2415. }
  2416. for (var _a = 0, _b = vertex.asArray(); _a < _b.length; _a++) {
  2417. var component = _b[_a];
  2418. binaryWriter.setFloat32(component, byteOffset);
  2419. byteOffset += 4;
  2420. }
  2421. }
  2422. };
  2423. /**
  2424. * Writes mesh attribute data to a data buffer
  2425. * Returns the bytelength of the data
  2426. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  2427. * @param meshAttributeArray Array containing the attribute data
  2428. * @param byteStride Specifies the space between data
  2429. * @param binaryWriter The buffer to write the binary data to
  2430. * @param convertToRightHandedSystem Converts the values to right-handed
  2431. */
  2432. _Exporter.prototype.writeAttributeData = function (vertexBufferKind, attributeComponentKind, meshAttributeArray, stride, binaryWriter, convertToRightHandedSystem, babylonTransformNode) {
  2433. var vertexAttributes = [];
  2434. var index;
  2435. switch (vertexBufferKind) {
  2436. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind: {
  2437. for (var k = 0, length_2 = meshAttributeArray.length / stride; k < length_2; ++k) {
  2438. index = k * stride;
  2439. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index);
  2440. if (convertToRightHandedSystem) {
  2441. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(vertexData);
  2442. }
  2443. vertexAttributes.push(vertexData.asArray());
  2444. }
  2445. break;
  2446. }
  2447. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  2448. for (var k = 0, length_3 = meshAttributeArray.length / stride; k < length_3; ++k) {
  2449. index = k * stride;
  2450. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index);
  2451. if (convertToRightHandedSystem) {
  2452. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(vertexData);
  2453. }
  2454. vertexData.normalize();
  2455. vertexAttributes.push(vertexData.asArray());
  2456. }
  2457. break;
  2458. }
  2459. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  2460. for (var k = 0, length_4 = meshAttributeArray.length / stride; k < length_4; ++k) {
  2461. index = k * stride;
  2462. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index);
  2463. if (convertToRightHandedSystem) {
  2464. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedVector4FromRef(vertexData);
  2465. }
  2466. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._NormalizeTangentFromRef(vertexData);
  2467. vertexAttributes.push(vertexData.asArray());
  2468. }
  2469. break;
  2470. }
  2471. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  2472. var meshMaterial = babylonTransformNode.material;
  2473. var convertToLinear = meshMaterial ? (meshMaterial instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]) : true;
  2474. var vertexData = stride === 3 ? new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"]() : new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"]();
  2475. for (var k = 0, length_5 = meshAttributeArray.length / stride; k < length_5; ++k) {
  2476. index = k * stride;
  2477. if (stride === 3) {
  2478. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromArrayToRef(meshAttributeArray, index, vertexData);
  2479. if (convertToLinear) {
  2480. vertexData.toLinearSpaceToRef(vertexData);
  2481. }
  2482. }
  2483. else {
  2484. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color4"].FromArrayToRef(meshAttributeArray, index, vertexData);
  2485. if (convertToLinear) {
  2486. vertexData.toLinearSpaceToRef(vertexData);
  2487. }
  2488. }
  2489. vertexAttributes.push(vertexData.asArray());
  2490. }
  2491. break;
  2492. }
  2493. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind:
  2494. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  2495. for (var k = 0, length_6 = meshAttributeArray.length / stride; k < length_6; ++k) {
  2496. index = k * stride;
  2497. vertexAttributes.push(convertToRightHandedSystem ? [meshAttributeArray[index], meshAttributeArray[index + 1]] : [meshAttributeArray[index], meshAttributeArray[index + 1]]);
  2498. }
  2499. break;
  2500. }
  2501. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesIndicesKind:
  2502. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesIndicesExtraKind: {
  2503. for (var k = 0, length_7 = meshAttributeArray.length / stride; k < length_7; ++k) {
  2504. index = k * stride;
  2505. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index);
  2506. vertexAttributes.push(vertexData.asArray());
  2507. }
  2508. break;
  2509. }
  2510. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesWeightsKind:
  2511. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesWeightsExtraKind: {
  2512. for (var k = 0, length_8 = meshAttributeArray.length / stride; k < length_8; ++k) {
  2513. index = k * stride;
  2514. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index);
  2515. vertexAttributes.push(vertexData.asArray());
  2516. }
  2517. break;
  2518. }
  2519. default: {
  2520. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
  2521. vertexAttributes = [];
  2522. }
  2523. }
  2524. var writeBinaryFunc;
  2525. switch (attributeComponentKind) {
  2526. case 5121 /* UNSIGNED_BYTE */: {
  2527. writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);
  2528. break;
  2529. }
  2530. case 5123 /* UNSIGNED_SHORT */: {
  2531. writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);
  2532. break;
  2533. }
  2534. case 5125 /* UNSIGNED_INT */: {
  2535. writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);
  2536. }
  2537. case 5126 /* FLOAT */: {
  2538. writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);
  2539. break;
  2540. }
  2541. default: {
  2542. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Attribute Component kind: " + attributeComponentKind);
  2543. return;
  2544. }
  2545. }
  2546. for (var _i = 0, vertexAttributes_1 = vertexAttributes; _i < vertexAttributes_1.length; _i++) {
  2547. var vertexAttribute = vertexAttributes_1[_i];
  2548. for (var _a = 0, vertexAttribute_1 = vertexAttribute; _a < vertexAttribute_1.length; _a++) {
  2549. var component = vertexAttribute_1[_a];
  2550. writeBinaryFunc(component);
  2551. }
  2552. }
  2553. };
  2554. /**
  2555. * Writes mesh attribute data to a data buffer
  2556. * Returns the bytelength of the data
  2557. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  2558. * @param meshAttributeArray Array containing the attribute data
  2559. * @param byteStride Specifies the space between data
  2560. * @param binaryWriter The buffer to write the binary data to
  2561. * @param convertToRightHandedSystem Converts the values to right-handed
  2562. */
  2563. _Exporter.prototype.writeMorphTargetAttributeData = function (vertexBufferKind, attributeComponentKind, meshPrimitive, morphTarget, meshAttributeArray, morphTargetAttributeArray, stride, binaryWriter, convertToRightHandedSystem, minMax) {
  2564. var vertexAttributes = [];
  2565. var index;
  2566. var difference = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"]();
  2567. var difference4 = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"](0, 0, 0, 0);
  2568. switch (vertexBufferKind) {
  2569. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind: {
  2570. for (var k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {
  2571. index = meshPrimitive.indexStart + k * stride;
  2572. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index);
  2573. var morphData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(morphTargetAttributeArray, index);
  2574. difference = morphData.subtractToRef(vertexData, difference);
  2575. if (convertToRightHandedSystem) {
  2576. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(difference);
  2577. }
  2578. if (minMax) {
  2579. minMax.min.copyFromFloats(Math.min(difference.x, minMax.min.x), Math.min(difference.y, minMax.min.y), Math.min(difference.z, minMax.min.z));
  2580. minMax.max.copyFromFloats(Math.max(difference.x, minMax.max.x), Math.max(difference.y, minMax.max.y), Math.max(difference.z, minMax.max.z));
  2581. }
  2582. vertexAttributes.push(difference.asArray());
  2583. }
  2584. break;
  2585. }
  2586. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  2587. for (var k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {
  2588. index = meshPrimitive.indexStart + k * stride;
  2589. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(meshAttributeArray, index);
  2590. vertexData.normalize();
  2591. var morphData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].FromArray(morphTargetAttributeArray, index);
  2592. morphData.normalize();
  2593. difference = morphData.subtractToRef(vertexData, difference);
  2594. if (convertToRightHandedSystem) {
  2595. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(difference);
  2596. }
  2597. vertexAttributes.push(difference.asArray());
  2598. }
  2599. break;
  2600. }
  2601. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  2602. for (var k = meshPrimitive.verticesStart; k < meshPrimitive.verticesCount; ++k) {
  2603. index = meshPrimitive.indexStart + k * (stride + 1);
  2604. var vertexData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(meshAttributeArray, index);
  2605. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._NormalizeTangentFromRef(vertexData);
  2606. var morphData = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector4"].FromArray(morphTargetAttributeArray, index);
  2607. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._NormalizeTangentFromRef(morphData);
  2608. difference4 = morphData.subtractToRef(vertexData, difference4);
  2609. if (convertToRightHandedSystem) {
  2610. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedVector4FromRef(difference4);
  2611. }
  2612. vertexAttributes.push([difference4.x, difference4.y, difference4.z]);
  2613. }
  2614. break;
  2615. }
  2616. default: {
  2617. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
  2618. vertexAttributes = [];
  2619. }
  2620. }
  2621. var writeBinaryFunc;
  2622. switch (attributeComponentKind) {
  2623. case 5121 /* UNSIGNED_BYTE */: {
  2624. writeBinaryFunc = binaryWriter.setUInt8.bind(binaryWriter);
  2625. break;
  2626. }
  2627. case 5123 /* UNSIGNED_SHORT */: {
  2628. writeBinaryFunc = binaryWriter.setUInt16.bind(binaryWriter);
  2629. break;
  2630. }
  2631. case 5125 /* UNSIGNED_INT */: {
  2632. writeBinaryFunc = binaryWriter.setUInt32.bind(binaryWriter);
  2633. }
  2634. case 5126 /* FLOAT */: {
  2635. writeBinaryFunc = binaryWriter.setFloat32.bind(binaryWriter);
  2636. break;
  2637. }
  2638. default: {
  2639. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Attribute Component kind: " + attributeComponentKind);
  2640. return;
  2641. }
  2642. }
  2643. for (var _i = 0, vertexAttributes_2 = vertexAttributes; _i < vertexAttributes_2.length; _i++) {
  2644. var vertexAttribute = vertexAttributes_2[_i];
  2645. for (var _a = 0, vertexAttribute_2 = vertexAttribute; _a < vertexAttribute_2.length; _a++) {
  2646. var component = vertexAttribute_2[_a];
  2647. writeBinaryFunc(component);
  2648. }
  2649. }
  2650. };
  2651. /**
  2652. * Generates glTF json data
  2653. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  2654. * @param glTFPrefix Text to use when prefixing a glTF file
  2655. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  2656. * @returns json data as string
  2657. */
  2658. _Exporter.prototype.generateJSON = function (shouldUseGlb, glTFPrefix, prettyPrint) {
  2659. var _this = this;
  2660. var buffer = { byteLength: this._totalByteLength };
  2661. var imageName;
  2662. var imageData;
  2663. var bufferView;
  2664. var byteOffset = this._totalByteLength;
  2665. if (buffer.byteLength) {
  2666. this._glTF.buffers = [buffer];
  2667. }
  2668. if (this._nodes && this._nodes.length) {
  2669. this._glTF.nodes = this._nodes;
  2670. }
  2671. if (this._meshes && this._meshes.length) {
  2672. this._glTF.meshes = this._meshes;
  2673. }
  2674. if (this._scenes && this._scenes.length) {
  2675. this._glTF.scenes = this._scenes;
  2676. this._glTF.scene = 0;
  2677. }
  2678. if (this._bufferViews && this._bufferViews.length) {
  2679. this._glTF.bufferViews = this._bufferViews;
  2680. }
  2681. if (this._accessors && this._accessors.length) {
  2682. this._glTF.accessors = this._accessors;
  2683. }
  2684. if (this._animations && this._animations.length) {
  2685. this._glTF.animations = this._animations;
  2686. }
  2687. if (this._materials && this._materials.length) {
  2688. this._glTF.materials = this._materials;
  2689. }
  2690. if (this._textures && this._textures.length) {
  2691. this._glTF.textures = this._textures;
  2692. }
  2693. if (this._samplers && this._samplers.length) {
  2694. this._glTF.samplers = this._samplers;
  2695. }
  2696. if (this._skins && this._skins.length) {
  2697. this._glTF.skins = this._skins;
  2698. }
  2699. if (this._images && this._images.length) {
  2700. if (!shouldUseGlb) {
  2701. this._glTF.images = this._images;
  2702. }
  2703. else {
  2704. this._glTF.images = [];
  2705. this._images.forEach(function (image) {
  2706. if (image.uri) {
  2707. imageData = _this._imageData[image.uri];
  2708. _this._orderedImageData.push(imageData);
  2709. imageName = image.uri.split('.')[0] + " image";
  2710. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, byteOffset, imageData.data.length, undefined, imageName);
  2711. byteOffset += imageData.data.buffer.byteLength;
  2712. _this._bufferViews.push(bufferView);
  2713. image.bufferView = _this._bufferViews.length - 1;
  2714. image.name = imageName;
  2715. image.mimeType = imageData.mimeType;
  2716. image.uri = undefined;
  2717. if (!_this._glTF.images) {
  2718. _this._glTF.images = [];
  2719. }
  2720. _this._glTF.images.push(image);
  2721. }
  2722. });
  2723. // Replace uri with bufferview and mime type for glb
  2724. buffer.byteLength = byteOffset;
  2725. }
  2726. }
  2727. if (!shouldUseGlb) {
  2728. buffer.uri = glTFPrefix + ".bin";
  2729. }
  2730. var jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);
  2731. return jsonText;
  2732. };
  2733. /**
  2734. * Generates data for .gltf and .bin files based on the glTF prefix string
  2735. * @param glTFPrefix Text to use when prefixing a glTF file
  2736. * @param dispose Dispose the exporter
  2737. * @returns GLTFData with glTF file data
  2738. */
  2739. _Exporter.prototype._generateGLTFAsync = function (glTFPrefix, dispose) {
  2740. var _this = this;
  2741. if (dispose === void 0) { dispose = true; }
  2742. return this._generateBinaryAsync().then(function (binaryBuffer) {
  2743. _this._extensionsOnExporting();
  2744. var jsonText = _this.generateJSON(false, glTFPrefix, true);
  2745. var bin = new Blob([binaryBuffer], { type: 'application/octet-stream' });
  2746. var glTFFileName = glTFPrefix + '.gltf';
  2747. var glTFBinFile = glTFPrefix + '.bin';
  2748. var container = new _glTFData__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]();
  2749. container.glTFFiles[glTFFileName] = jsonText;
  2750. container.glTFFiles[glTFBinFile] = bin;
  2751. if (_this._imageData) {
  2752. for (var image in _this._imageData) {
  2753. container.glTFFiles[image] = new Blob([_this._imageData[image].data], { type: _this._imageData[image].mimeType });
  2754. }
  2755. }
  2756. if (dispose) {
  2757. _this.dispose();
  2758. }
  2759. return container;
  2760. });
  2761. };
  2762. /**
  2763. * Creates a binary buffer for glTF
  2764. * @returns array buffer for binary data
  2765. */
  2766. _Exporter.prototype._generateBinaryAsync = function () {
  2767. var _this = this;
  2768. var binaryWriter = new _BinaryWriter(4);
  2769. return this.createSceneAsync(this._babylonScene, binaryWriter).then(function () {
  2770. if (_this._localEngine) {
  2771. _this._localEngine.dispose();
  2772. }
  2773. return binaryWriter.getArrayBuffer();
  2774. });
  2775. };
  2776. /**
  2777. * Pads the number to a multiple of 4
  2778. * @param num number to pad
  2779. * @returns padded number
  2780. */
  2781. _Exporter.prototype._getPadding = function (num) {
  2782. var remainder = num % 4;
  2783. var padding = remainder === 0 ? remainder : 4 - remainder;
  2784. return padding;
  2785. };
  2786. /**
  2787. * @hidden
  2788. */
  2789. _Exporter.prototype._generateGLBAsync = function (glTFPrefix, dispose) {
  2790. var _this = this;
  2791. if (dispose === void 0) { dispose = true; }
  2792. return this._generateBinaryAsync().then(function (binaryBuffer) {
  2793. _this._extensionsOnExporting();
  2794. var jsonText = _this.generateJSON(true);
  2795. var glbFileName = glTFPrefix + '.glb';
  2796. var headerLength = 12;
  2797. var chunkLengthPrefix = 8;
  2798. var jsonLength = jsonText.length;
  2799. var imageByteLength = 0;
  2800. for (var i = 0; i < _this._orderedImageData.length; ++i) {
  2801. imageByteLength += _this._orderedImageData[i].data.byteLength;
  2802. }
  2803. var jsonPadding = _this._getPadding(jsonLength);
  2804. var binPadding = _this._getPadding(binaryBuffer.byteLength);
  2805. var imagePadding = _this._getPadding(imageByteLength);
  2806. var byteLength = headerLength + (2 * chunkLengthPrefix) + jsonLength + jsonPadding + binaryBuffer.byteLength + binPadding + imageByteLength + imagePadding;
  2807. //header
  2808. var headerBuffer = new ArrayBuffer(headerLength);
  2809. var headerBufferView = new DataView(headerBuffer);
  2810. headerBufferView.setUint32(0, 0x46546C67, true); //glTF
  2811. headerBufferView.setUint32(4, 2, true); // version
  2812. headerBufferView.setUint32(8, byteLength, true); // total bytes in file
  2813. //json chunk
  2814. var jsonChunkBuffer = new ArrayBuffer(chunkLengthPrefix + jsonLength + jsonPadding);
  2815. var jsonChunkBufferView = new DataView(jsonChunkBuffer);
  2816. jsonChunkBufferView.setUint32(0, jsonLength + jsonPadding, true);
  2817. jsonChunkBufferView.setUint32(4, 0x4E4F534A, true);
  2818. //json chunk bytes
  2819. var jsonData = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix);
  2820. for (var i = 0; i < jsonLength; ++i) {
  2821. jsonData[i] = jsonText.charCodeAt(i);
  2822. }
  2823. //json padding
  2824. var jsonPaddingView = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix + jsonLength);
  2825. for (var i = 0; i < jsonPadding; ++i) {
  2826. jsonPaddingView[i] = 0x20;
  2827. }
  2828. //binary chunk
  2829. var binaryChunkBuffer = new ArrayBuffer(chunkLengthPrefix);
  2830. var binaryChunkBufferView = new DataView(binaryChunkBuffer);
  2831. binaryChunkBufferView.setUint32(0, binaryBuffer.byteLength + imageByteLength + imagePadding, true);
  2832. binaryChunkBufferView.setUint32(4, 0x004E4942, true);
  2833. // binary padding
  2834. var binPaddingBuffer = new ArrayBuffer(binPadding);
  2835. var binPaddingView = new Uint8Array(binPaddingBuffer);
  2836. for (var i = 0; i < binPadding; ++i) {
  2837. binPaddingView[i] = 0;
  2838. }
  2839. var imagePaddingBuffer = new ArrayBuffer(imagePadding);
  2840. var imagePaddingView = new Uint8Array(imagePaddingBuffer);
  2841. for (var i = 0; i < imagePadding; ++i) {
  2842. imagePaddingView[i] = 0;
  2843. }
  2844. var glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];
  2845. // binary data
  2846. for (var i = 0; i < _this._orderedImageData.length; ++i) {
  2847. glbData.push(_this._orderedImageData[i].data.buffer);
  2848. }
  2849. glbData.push(binPaddingBuffer);
  2850. glbData.push(imagePaddingBuffer);
  2851. var glbFile = new Blob(glbData, { type: 'application/octet-stream' });
  2852. var container = new _glTFData__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]();
  2853. container.glTFFiles[glbFileName] = glbFile;
  2854. if (_this._localEngine != null) {
  2855. _this._localEngine.dispose();
  2856. }
  2857. if (dispose) {
  2858. _this.dispose();
  2859. }
  2860. return container;
  2861. });
  2862. };
  2863. /**
  2864. * Sets the TRS for each node
  2865. * @param node glTF Node for storing the transformation data
  2866. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  2867. * @param convertToRightHandedSystem Converts the values to right-handed
  2868. */
  2869. _Exporter.prototype.setNodeTransformation = function (node, babylonTransformNode, convertToRightHandedSystem) {
  2870. if (!babylonTransformNode.getPivotPoint().equalsToFloats(0, 0, 0)) {
  2871. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Pivot points are not supported in the glTF serializer");
  2872. }
  2873. if (!babylonTransformNode.position.equalsToFloats(0, 0, 0)) {
  2874. node.translation = convertToRightHandedSystem ? _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedPositionVector3(babylonTransformNode.position).asArray() : babylonTransformNode.position.asArray();
  2875. }
  2876. if (!babylonTransformNode.scaling.equalsToFloats(1, 1, 1)) {
  2877. node.scale = babylonTransformNode.scaling.asArray();
  2878. }
  2879. var rotationQuaternion = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].RotationYawPitchRoll(babylonTransformNode.rotation.y, babylonTransformNode.rotation.x, babylonTransformNode.rotation.z);
  2880. if (babylonTransformNode.rotationQuaternion) {
  2881. rotationQuaternion.multiplyInPlace(babylonTransformNode.rotationQuaternion);
  2882. }
  2883. if (!(rotationQuaternion.x === 0 && rotationQuaternion.y === 0 && rotationQuaternion.z === 0 && rotationQuaternion.w === 1)) {
  2884. if (convertToRightHandedSystem) {
  2885. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(rotationQuaternion);
  2886. }
  2887. node.rotation = rotationQuaternion.normalize().asArray();
  2888. }
  2889. };
  2890. _Exporter.prototype.getVertexBufferFromMesh = function (attributeKind, bufferMesh) {
  2891. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  2892. var vertexBuffer = bufferMesh.getVertexBuffer(attributeKind);
  2893. if (vertexBuffer) {
  2894. return vertexBuffer;
  2895. }
  2896. }
  2897. return null;
  2898. };
  2899. /**
  2900. * Creates a bufferview based on the vertices type for the Babylon mesh
  2901. * @param kind Indicates the type of vertices data
  2902. * @param componentType Indicates the numerical type used to store the data
  2903. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  2904. * @param binaryWriter The buffer to write the bufferview data to
  2905. * @param convertToRightHandedSystem Converts the values to right-handed
  2906. */
  2907. _Exporter.prototype.createBufferViewKind = function (kind, attributeComponentKind, babylonTransformNode, binaryWriter, byteStride, convertToRightHandedSystem) {
  2908. var bufferMesh = babylonTransformNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"] ?
  2909. babylonTransformNode : babylonTransformNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["InstancedMesh"] ?
  2910. babylonTransformNode.sourceMesh : null;
  2911. if (bufferMesh) {
  2912. var vertexBuffer = bufferMesh.getVertexBuffer(kind);
  2913. var vertexData = bufferMesh.getVerticesData(kind);
  2914. if (vertexBuffer && vertexData) {
  2915. var typeByteLength = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(attributeComponentKind);
  2916. var byteLength = vertexData.length * typeByteLength;
  2917. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, kind + " - " + bufferMesh.name);
  2918. this._bufferViews.push(bufferView);
  2919. this.writeAttributeData(kind, attributeComponentKind, vertexData, byteStride / typeByteLength, binaryWriter, convertToRightHandedSystem, babylonTransformNode);
  2920. }
  2921. }
  2922. };
  2923. /**
  2924. * Creates a bufferview based on the vertices type for the Babylon mesh
  2925. * @param babylonSubMesh The Babylon submesh that the morph target is applied to
  2926. * @param babylonMorphTarget the morph target to be exported
  2927. * @param binaryWriter The buffer to write the bufferview data to
  2928. * @param convertToRightHandedSystem Converts the values to right-handed
  2929. */
  2930. _Exporter.prototype.setMorphTargetAttributes = function (babylonSubMesh, meshPrimitive, babylonMorphTarget, binaryWriter, convertToRightHandedSystem) {
  2931. if (babylonMorphTarget) {
  2932. if (!meshPrimitive.targets) {
  2933. meshPrimitive.targets = [];
  2934. }
  2935. var target = {};
  2936. if (babylonMorphTarget.hasNormals) {
  2937. var vertexNormals = babylonSubMesh.getMesh().getVerticesData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind);
  2938. var morphNormals = babylonMorphTarget.getNormals();
  2939. var count = babylonSubMesh.verticesCount;
  2940. var byteStride = 12; // 3 x 4 byte floats
  2941. var byteLength = count * byteStride;
  2942. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + "_NORMAL");
  2943. this._bufferViews.push(bufferView);
  2944. var bufferViewIndex = this._bufferViews.length - 1;
  2945. var accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + " - " + "NORMAL", "VEC3" /* VEC3 */, 5126 /* FLOAT */, count, 0, null, null);
  2946. this._accessors.push(accessor);
  2947. target.NORMAL = this._accessors.length - 1;
  2948. this.writeMorphTargetAttributeData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind, 5126 /* FLOAT */, babylonSubMesh, babylonMorphTarget, vertexNormals, morphNormals, byteStride / 4, binaryWriter, convertToRightHandedSystem);
  2949. }
  2950. if (babylonMorphTarget.hasPositions) {
  2951. var vertexPositions = babylonSubMesh.getMesh().getVerticesData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind);
  2952. var morphPositions = babylonMorphTarget.getPositions();
  2953. var count = babylonSubMesh.verticesCount;
  2954. var byteStride = 12; // 3 x 4 byte floats
  2955. var byteLength = count * byteStride;
  2956. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + "_POSITION");
  2957. this._bufferViews.push(bufferView);
  2958. var bufferViewIndex = this._bufferViews.length - 1;
  2959. var minMax = { min: new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](Infinity, Infinity, Infinity), max: new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](-Infinity, -Infinity, -Infinity) };
  2960. var accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + " - " + "POSITION", "VEC3" /* VEC3 */, 5126 /* FLOAT */, count, 0, null, null);
  2961. this._accessors.push(accessor);
  2962. target.POSITION = this._accessors.length - 1;
  2963. this.writeMorphTargetAttributeData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind, 5126 /* FLOAT */, babylonSubMesh, babylonMorphTarget, vertexPositions, morphPositions, byteStride / 4, binaryWriter, convertToRightHandedSystem, minMax);
  2964. accessor.min = minMax.min.asArray();
  2965. accessor.max = minMax.max.asArray();
  2966. }
  2967. if (babylonMorphTarget.hasTangents) {
  2968. var vertexTangents = babylonSubMesh.getMesh().getVerticesData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind);
  2969. var morphTangents = babylonMorphTarget.getTangents();
  2970. var count = babylonSubMesh.verticesCount;
  2971. var byteStride = 12; // 3 x 4 byte floats
  2972. var byteLength = count * byteStride;
  2973. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, babylonMorphTarget.name + "_NORMAL");
  2974. this._bufferViews.push(bufferView);
  2975. var bufferViewIndex = this._bufferViews.length - 1;
  2976. var accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(bufferViewIndex, babylonMorphTarget.name + " - " + "TANGENT", "VEC3" /* VEC3 */, 5126 /* FLOAT */, count, 0, null, null);
  2977. this._accessors.push(accessor);
  2978. target.TANGENT = this._accessors.length - 1;
  2979. this.writeMorphTargetAttributeData(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind, 5126 /* FLOAT */, babylonSubMesh, babylonMorphTarget, vertexTangents, morphTangents, byteStride / 4, binaryWriter, convertToRightHandedSystem);
  2980. }
  2981. meshPrimitive.targets.push(target);
  2982. }
  2983. };
  2984. /**
  2985. * The primitive mode of the Babylon mesh
  2986. * @param babylonMesh The BabylonJS mesh
  2987. */
  2988. _Exporter.prototype.getMeshPrimitiveMode = function (babylonMesh) {
  2989. if (babylonMesh instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["LinesMesh"]) {
  2990. return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].LineListDrawMode;
  2991. }
  2992. return babylonMesh.material ? babylonMesh.material.fillMode : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode;
  2993. };
  2994. /**
  2995. * Sets the primitive mode of the glTF mesh primitive
  2996. * @param meshPrimitive glTF mesh primitive
  2997. * @param primitiveMode The primitive mode
  2998. */
  2999. _Exporter.prototype.setPrimitiveMode = function (meshPrimitive, primitiveMode) {
  3000. switch (primitiveMode) {
  3001. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFillMode: {
  3002. // glTF defaults to using Triangle Mode
  3003. break;
  3004. }
  3005. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleStripDrawMode: {
  3006. meshPrimitive.mode = 5 /* TRIANGLE_STRIP */;
  3007. break;
  3008. }
  3009. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].TriangleFanDrawMode: {
  3010. meshPrimitive.mode = 6 /* TRIANGLE_FAN */;
  3011. break;
  3012. }
  3013. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].PointListDrawMode: {
  3014. meshPrimitive.mode = 0 /* POINTS */;
  3015. }
  3016. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].PointFillMode: {
  3017. meshPrimitive.mode = 0 /* POINTS */;
  3018. break;
  3019. }
  3020. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].LineLoopDrawMode: {
  3021. meshPrimitive.mode = 2 /* LINE_LOOP */;
  3022. break;
  3023. }
  3024. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].LineListDrawMode: {
  3025. meshPrimitive.mode = 1 /* LINES */;
  3026. break;
  3027. }
  3028. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].LineStripDrawMode: {
  3029. meshPrimitive.mode = 3 /* LINE_STRIP */;
  3030. break;
  3031. }
  3032. }
  3033. };
  3034. /**
  3035. * Sets the vertex attribute accessor based of the glTF mesh primitive
  3036. * @param meshPrimitive glTF mesh primitive
  3037. * @param attributeKind vertex attribute
  3038. * @returns boolean specifying if uv coordinates are present
  3039. */
  3040. _Exporter.prototype.setAttributeKind = function (meshPrimitive, attributeKind) {
  3041. switch (attributeKind) {
  3042. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind: {
  3043. meshPrimitive.attributes.POSITION = this._accessors.length - 1;
  3044. break;
  3045. }
  3046. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind: {
  3047. meshPrimitive.attributes.NORMAL = this._accessors.length - 1;
  3048. break;
  3049. }
  3050. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind: {
  3051. meshPrimitive.attributes.COLOR_0 = this._accessors.length - 1;
  3052. break;
  3053. }
  3054. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind: {
  3055. meshPrimitive.attributes.TANGENT = this._accessors.length - 1;
  3056. break;
  3057. }
  3058. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind: {
  3059. meshPrimitive.attributes.TEXCOORD_0 = this._accessors.length - 1;
  3060. break;
  3061. }
  3062. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind: {
  3063. meshPrimitive.attributes.TEXCOORD_1 = this._accessors.length - 1;
  3064. break;
  3065. }
  3066. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesIndicesKind: {
  3067. meshPrimitive.attributes.JOINTS_0 = this._accessors.length - 1;
  3068. break;
  3069. }
  3070. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesIndicesExtraKind: {
  3071. meshPrimitive.attributes.JOINTS_1 = this._accessors.length - 1;
  3072. break;
  3073. }
  3074. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesWeightsKind: {
  3075. meshPrimitive.attributes.WEIGHTS_0 = this._accessors.length - 1;
  3076. break;
  3077. }
  3078. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesWeightsExtraKind: {
  3079. meshPrimitive.attributes.WEIGHTS_1 = this._accessors.length - 1;
  3080. break;
  3081. }
  3082. default: {
  3083. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported Vertex Buffer Type: " + attributeKind);
  3084. }
  3085. }
  3086. };
  3087. /**
  3088. * Sets data for the primitive attributes of each submesh
  3089. * @param mesh glTF Mesh object to store the primitive attribute information
  3090. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  3091. * @param binaryWriter Buffer to write the attribute data to
  3092. * @param convertToRightHandedSystem Converts the values to right-handed
  3093. */
  3094. _Exporter.prototype.setPrimitiveAttributesAsync = function (mesh, babylonTransformNode, binaryWriter, convertToRightHandedSystem) {
  3095. var _a;
  3096. var promises = [];
  3097. var bufferMesh = null;
  3098. var bufferView;
  3099. var minMax;
  3100. if (babylonTransformNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  3101. bufferMesh = babylonTransformNode;
  3102. }
  3103. else if (babylonTransformNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["InstancedMesh"]) {
  3104. bufferMesh = babylonTransformNode.sourceMesh;
  3105. }
  3106. var attributeData = [
  3107. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind, accessorType: "VEC3" /* VEC3 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 12 },
  3108. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind, accessorType: "VEC3" /* VEC3 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 12 },
  3109. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
  3110. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].TangentKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
  3111. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind, accessorType: "VEC2" /* VEC2 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 8 },
  3112. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind, accessorType: "VEC2" /* VEC2 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 8 },
  3113. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesIndicesKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5123 /* UNSIGNED_SHORT */, byteStride: 8 },
  3114. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesIndicesExtraKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5123 /* UNSIGNED_SHORT */, byteStride: 8 },
  3115. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesWeightsKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
  3116. { kind: babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].MatricesWeightsExtraKind, accessorType: "VEC4" /* VEC4 */, accessorComponentType: 5126 /* FLOAT */, byteStride: 16 },
  3117. ];
  3118. if (bufferMesh) {
  3119. var indexBufferViewIndex = null;
  3120. var primitiveMode = this.getMeshPrimitiveMode(bufferMesh);
  3121. var vertexAttributeBufferViews = {};
  3122. var morphTargetManager = bufferMesh.morphTargetManager;
  3123. // For each BabylonMesh, create bufferviews for each 'kind'
  3124. for (var _i = 0, attributeData_1 = attributeData; _i < attributeData_1.length; _i++) {
  3125. var attribute = attributeData_1[_i];
  3126. var attributeKind = attribute.kind;
  3127. var attributeComponentKind = attribute.accessorComponentType;
  3128. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  3129. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  3130. attribute.byteStride = vertexBuffer ? vertexBuffer.getSize() * babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].GetTypeByteLength(attribute.accessorComponentType) : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].DeduceStride(attributeKind) * 4;
  3131. if (attribute.byteStride === 12) {
  3132. attribute.accessorType = "VEC3" /* VEC3 */;
  3133. }
  3134. this.createBufferViewKind(attributeKind, attributeComponentKind, babylonTransformNode, binaryWriter, attribute.byteStride, convertToRightHandedSystem);
  3135. attribute.bufferViewIndex = this._bufferViews.length - 1;
  3136. vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;
  3137. }
  3138. }
  3139. if (bufferMesh.getTotalIndices()) {
  3140. var indices = bufferMesh.getIndices();
  3141. if (indices) {
  3142. var byteLength = indices.length * 4;
  3143. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "Indices - " + bufferMesh.name);
  3144. this._bufferViews.push(bufferView);
  3145. indexBufferViewIndex = this._bufferViews.length - 1;
  3146. for (var k = 0, length_9 = indices.length; k < length_9; ++k) {
  3147. binaryWriter.setUInt32(indices[k]);
  3148. }
  3149. }
  3150. }
  3151. if (bufferMesh.subMeshes) {
  3152. // go through all mesh primitives (submeshes)
  3153. for (var _b = 0, _c = bufferMesh.subMeshes; _b < _c.length; _b++) {
  3154. var submesh = _c[_b];
  3155. var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
  3156. var materialIndex = null;
  3157. if (babylonMaterial) {
  3158. if (bufferMesh instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["LinesMesh"]) {
  3159. // get the color from the lines mesh and set it in the material
  3160. var material = {
  3161. name: bufferMesh.name + ' material'
  3162. };
  3163. if (!bufferMesh.color.equals(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].White()) || bufferMesh.alpha < 1) {
  3164. material.pbrMetallicRoughness = {
  3165. baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha])
  3166. };
  3167. }
  3168. this._materials.push(material);
  3169. materialIndex = this._materials.length - 1;
  3170. }
  3171. else if (babylonMaterial instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["MultiMaterial"]) {
  3172. var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
  3173. if (subMaterial) {
  3174. babylonMaterial = subMaterial;
  3175. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  3176. }
  3177. }
  3178. else {
  3179. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  3180. }
  3181. }
  3182. var glTFMaterial = materialIndex != null ? this._materials[materialIndex] : null;
  3183. var meshPrimitive = { attributes: {} };
  3184. this.setPrimitiveMode(meshPrimitive, primitiveMode);
  3185. for (var _d = 0, attributeData_2 = attributeData; _d < attributeData_2.length; _d++) {
  3186. var attribute = attributeData_2[_d];
  3187. var attributeKind = attribute.kind;
  3188. if (attributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind || attributeKind === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind) {
  3189. if (glTFMaterial && !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
  3190. continue;
  3191. }
  3192. }
  3193. var vertexData = bufferMesh.getVerticesData(attributeKind);
  3194. if (vertexData) {
  3195. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  3196. if (vertexBuffer) {
  3197. var stride = vertexBuffer.getSize();
  3198. var bufferViewIndex = attribute.bufferViewIndex;
  3199. if (bufferViewIndex != undefined) { // check to see if bufferviewindex has a numeric value assigned.
  3200. minMax = { min: null, max: null };
  3201. if (attributeKind == babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind) {
  3202. minMax = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride, convertToRightHandedSystem);
  3203. }
  3204. var accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(bufferViewIndex, attributeKind + " - " + babylonTransformNode.name, attribute.accessorType, attribute.accessorComponentType, vertexData.length / stride, 0, minMax.min, minMax.max);
  3205. this._accessors.push(accessor);
  3206. this.setAttributeKind(meshPrimitive, attributeKind);
  3207. }
  3208. }
  3209. }
  3210. }
  3211. if (indexBufferViewIndex) {
  3212. // Create accessor
  3213. 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);
  3214. this._accessors.push(accessor);
  3215. meshPrimitive.indices = this._accessors.length - 1;
  3216. }
  3217. if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
  3218. var sideOrientation = bufferMesh.overrideMaterialSideOrientation !== null ? bufferMesh.overrideMaterialSideOrientation : babylonMaterial.sideOrientation;
  3219. if ((sideOrientation == babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Material"].ClockWiseSideOrientation && this._babylonScene.useRightHandedSystem)
  3220. || (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))) {
  3221. var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
  3222. if (byteOffset == null) {
  3223. byteOffset = 0;
  3224. }
  3225. var babylonIndices = null;
  3226. if (indexBufferViewIndex != null) {
  3227. babylonIndices = bufferMesh.getIndices();
  3228. }
  3229. if (babylonIndices) {
  3230. this.reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
  3231. }
  3232. else {
  3233. for (var _e = 0, attributeData_3 = attributeData; _e < attributeData_3.length; _e++) {
  3234. var attribute = attributeData_3[_e];
  3235. var vertexData = bufferMesh.getVerticesData(attribute.kind);
  3236. if (vertexData) {
  3237. var byteOffset_1 = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset;
  3238. if (!byteOffset_1) {
  3239. byteOffset_1 = 0;
  3240. }
  3241. this.reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, attribute.kind, vertexData, byteOffset_1, binaryWriter, convertToRightHandedSystem);
  3242. }
  3243. }
  3244. }
  3245. }
  3246. meshPrimitive.material = materialIndex;
  3247. }
  3248. if (morphTargetManager) {
  3249. var target = void 0;
  3250. for (var i = 0; i < morphTargetManager.numTargets; ++i) {
  3251. target = morphTargetManager.getTarget(i);
  3252. this.setMorphTargetAttributes(submesh, meshPrimitive, target, binaryWriter, convertToRightHandedSystem);
  3253. }
  3254. }
  3255. mesh.primitives.push(meshPrimitive);
  3256. var promise = this._extensionsPostExportMeshPrimitiveAsync("postExport", meshPrimitive, submesh, binaryWriter);
  3257. if (promise) {
  3258. promises.push();
  3259. }
  3260. }
  3261. }
  3262. }
  3263. return Promise.all(promises).then(function () {
  3264. /* do nothing */
  3265. });
  3266. };
  3267. /**
  3268. * Check if the node is used to convert its descendants from a right handed coordinate system to the Babylon scene's coordinate system.
  3269. * @param node The node to check
  3270. * @returns True if the node is used to convert its descendants from right-handed to left-handed. False otherwise
  3271. */
  3272. _Exporter.prototype.isBabylonCoordinateSystemConvertingNode = function (node) {
  3273. if (node instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["TransformNode"]) {
  3274. if (node.name !== "__root__") {
  3275. return false;
  3276. }
  3277. // Transform
  3278. var matrix = node.getWorldMatrix();
  3279. 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());
  3280. var matrixProduct = matrix.multiply(matrixToLeftHanded);
  3281. var matrixIdentity = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Matrix"].IdentityReadOnly;
  3282. for (var i = 0; i < 16; i++) {
  3283. if (Math.abs(matrixProduct.m[i] - matrixIdentity.m[i]) > babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Epsilon"]) {
  3284. return false;
  3285. }
  3286. }
  3287. // Geometry
  3288. if ((node instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"] && node.geometry !== null) ||
  3289. (node instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["InstancedMesh"] && node.sourceMesh.geometry !== null)) {
  3290. return false;
  3291. }
  3292. if (this._includeCoordinateSystemConversionNodes) {
  3293. return false;
  3294. }
  3295. return true;
  3296. }
  3297. return false;
  3298. };
  3299. /**
  3300. * Creates a glTF scene based on the array of meshes
  3301. * Returns the the total byte offset
  3302. * @param babylonScene Babylon scene to get the mesh data from
  3303. * @param binaryWriter Buffer to write binary data to
  3304. */
  3305. _Exporter.prototype.createSceneAsync = function (babylonScene, binaryWriter) {
  3306. var _this = this;
  3307. var scene = { nodes: [] };
  3308. var glTFNodeIndex;
  3309. var glTFNode;
  3310. var directDescendents;
  3311. var nodes = Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__spreadArrays"])(babylonScene.transformNodes, babylonScene.meshes, babylonScene.lights);
  3312. var rootNodesToLeftHanded = [];
  3313. this._convertToRightHandedSystem = !babylonScene.useRightHandedSystem;
  3314. this._convertToRightHandedSystemMap = {};
  3315. // Set default values for all nodes
  3316. babylonScene.rootNodes.forEach(function (rootNode) {
  3317. _this._convertToRightHandedSystemMap[rootNode.uniqueId] = _this._convertToRightHandedSystem;
  3318. rootNode.getDescendants(false).forEach(function (descendant) {
  3319. _this._convertToRightHandedSystemMap[descendant.uniqueId] = _this._convertToRightHandedSystem;
  3320. });
  3321. });
  3322. // Check if root nodes converting to left-handed are present
  3323. babylonScene.rootNodes.forEach(function (rootNode) {
  3324. if (_this.isBabylonCoordinateSystemConvertingNode(rootNode)) {
  3325. rootNodesToLeftHanded.push(rootNode);
  3326. // Exclude the node from list of nodes to export
  3327. var indexRootNode = nodes.indexOf(rootNode);
  3328. if (indexRootNode !== -1) { // should always be true
  3329. nodes.splice(indexRootNode, 1);
  3330. }
  3331. // Cancel conversion to right handed system
  3332. rootNode.getDescendants(false).forEach(function (descendant) {
  3333. _this._convertToRightHandedSystemMap[descendant.uniqueId] = false;
  3334. });
  3335. }
  3336. });
  3337. return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
  3338. return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, binaryWriter).then(function (nodeMap) {
  3339. return _this.createSkinsAsync(babylonScene, nodeMap, binaryWriter).then(function (skinMap) {
  3340. _this._nodeMap = nodeMap;
  3341. _this._totalByteLength = binaryWriter.getByteOffset();
  3342. if (_this._totalByteLength == undefined) {
  3343. throw new Error("undefined byte length!");
  3344. }
  3345. // Build Hierarchy with the node map.
  3346. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  3347. var babylonNode = nodes_1[_i];
  3348. glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
  3349. if (glTFNodeIndex !== undefined) {
  3350. glTFNode = _this._nodes[glTFNodeIndex];
  3351. if (babylonNode.metadata) {
  3352. if (_this._options.metadataSelector) {
  3353. glTFNode.extras = _this._options.metadataSelector(babylonNode.metadata);
  3354. }
  3355. else if (babylonNode.metadata.gltf) {
  3356. glTFNode.extras = babylonNode.metadata.gltf.extras;
  3357. }
  3358. }
  3359. if (!babylonNode.parent || rootNodesToLeftHanded.indexOf(babylonNode.parent) !== -1) {
  3360. if (_this._options.shouldExportNode && !_this._options.shouldExportNode(babylonNode)) {
  3361. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Log("Omitting " + babylonNode.name + " from scene.");
  3362. }
  3363. else {
  3364. var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
  3365. if (convertToRightHandedSystem) {
  3366. if (glTFNode.translation) {
  3367. glTFNode.translation[2] *= -1;
  3368. glTFNode.translation[0] *= -1;
  3369. }
  3370. 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();
  3371. }
  3372. scene.nodes.push(glTFNodeIndex);
  3373. }
  3374. }
  3375. if (babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  3376. var babylonMesh = babylonNode;
  3377. if (babylonMesh.skeleton) {
  3378. glTFNode.skin = skinMap[babylonMesh.skeleton.uniqueId];
  3379. }
  3380. }
  3381. directDescendents = babylonNode.getDescendants(true);
  3382. if (!glTFNode.children && directDescendents && directDescendents.length) {
  3383. var children = [];
  3384. for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
  3385. var descendent = directDescendents_1[_a];
  3386. if (_this._nodeMap[descendent.uniqueId] != null) {
  3387. children.push(_this._nodeMap[descendent.uniqueId]);
  3388. }
  3389. }
  3390. if (children.length) {
  3391. glTFNode.children = children;
  3392. }
  3393. }
  3394. }
  3395. }
  3396. if (scene.nodes.length) {
  3397. _this._scenes.push(scene);
  3398. }
  3399. });
  3400. });
  3401. });
  3402. };
  3403. /**
  3404. * Creates a mapping of Node unique id to node index and handles animations
  3405. * @param babylonScene Babylon Scene
  3406. * @param nodes Babylon transform nodes
  3407. * @param binaryWriter Buffer to write binary data to
  3408. * @returns Node mapping of unique id to index
  3409. */
  3410. _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, binaryWriter) {
  3411. var _this = this;
  3412. var promiseChain = Promise.resolve();
  3413. var nodeMap = {};
  3414. var nodeIndex;
  3415. var runtimeGLTFAnimation = {
  3416. name: 'runtime animations',
  3417. channels: [],
  3418. samplers: []
  3419. };
  3420. var idleGLTFAnimations = [];
  3421. var _loop_1 = function (babylonNode) {
  3422. if (!this_1._options.shouldExportNode || this_1._options.shouldExportNode(babylonNode)) {
  3423. promiseChain = promiseChain.then(function () {
  3424. var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
  3425. return _this.createNodeAsync(babylonNode, binaryWriter, convertToRightHandedSystem, nodeMap).then(function (node) {
  3426. var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap);
  3427. if (promise == null) {
  3428. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Not exporting node " + babylonNode.name);
  3429. return Promise.resolve();
  3430. }
  3431. else {
  3432. return promise.then(function (node) {
  3433. if (!node) {
  3434. return;
  3435. }
  3436. _this._nodes.push(node);
  3437. nodeIndex = _this._nodes.length - 1;
  3438. nodeMap[babylonNode.uniqueId] = nodeIndex;
  3439. if (!babylonScene.animationGroups.length) {
  3440. _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__["_GLTFAnimation"]._CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
  3441. if (babylonNode.animations.length) {
  3442. _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__["_GLTFAnimation"]._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
  3443. }
  3444. }
  3445. });
  3446. }
  3447. });
  3448. });
  3449. }
  3450. else {
  3451. "Excluding node " + babylonNode.name;
  3452. }
  3453. };
  3454. var this_1 = this;
  3455. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  3456. var babylonNode = nodes_2[_i];
  3457. _loop_1(babylonNode);
  3458. }
  3459. return promiseChain.then(function () {
  3460. if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
  3461. _this._animations.push(runtimeGLTFAnimation);
  3462. }
  3463. idleGLTFAnimations.forEach(function (idleGLTFAnimation) {
  3464. if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {
  3465. _this._animations.push(idleGLTFAnimation);
  3466. }
  3467. });
  3468. if (babylonScene.animationGroups.length) {
  3469. _glTFAnimation__WEBPACK_IMPORTED_MODULE_5__["_GLTFAnimation"]._CreateNodeAndMorphAnimationFromAnimationGroups(babylonScene, _this._animations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystemMap, _this._animationSampleRate);
  3470. }
  3471. return nodeMap;
  3472. });
  3473. };
  3474. /**
  3475. * Creates a glTF node from a Babylon mesh
  3476. * @param babylonMesh Source Babylon mesh
  3477. * @param binaryWriter Buffer for storing geometry data
  3478. * @param convertToRightHandedSystem Converts the values to right-handed
  3479. * @param nodeMap Node mapping of unique id to glTF node index
  3480. * @returns glTF node
  3481. */
  3482. _Exporter.prototype.createNodeAsync = function (babylonNode, binaryWriter, convertToRightHandedSystem, nodeMap) {
  3483. var _this = this;
  3484. return Promise.resolve().then(function () {
  3485. // create node to hold translation/rotation/scale and the mesh
  3486. var node = {};
  3487. // create mesh
  3488. var mesh = { primitives: [] };
  3489. if (babylonNode.name) {
  3490. node.name = babylonNode.name;
  3491. }
  3492. if (babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["TransformNode"]) {
  3493. // Set transformation
  3494. _this.setNodeTransformation(node, babylonNode, convertToRightHandedSystem);
  3495. if (babylonNode instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Mesh"]) {
  3496. var morphTargetManager = babylonNode.morphTargetManager;
  3497. if (morphTargetManager && morphTargetManager.numTargets > 0) {
  3498. mesh.weights = [];
  3499. for (var i = 0; i < morphTargetManager.numTargets; ++i) {
  3500. mesh.weights.push(morphTargetManager.getTarget(i).influence);
  3501. }
  3502. }
  3503. }
  3504. return _this.setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter, convertToRightHandedSystem).then(function () {
  3505. if (mesh.primitives.length) {
  3506. _this._meshes.push(mesh);
  3507. node.mesh = _this._meshes.length - 1;
  3508. }
  3509. return node;
  3510. });
  3511. }
  3512. else {
  3513. return node;
  3514. }
  3515. });
  3516. };
  3517. /**
  3518. * Creates a glTF skin from a Babylon skeleton
  3519. * @param babylonScene Babylon Scene
  3520. * @param nodes Babylon transform nodes
  3521. * @param binaryWriter Buffer to write binary data to
  3522. * @returns Node mapping of unique id to index
  3523. */
  3524. _Exporter.prototype.createSkinsAsync = function (babylonScene, nodeMap, binaryWriter) {
  3525. var promiseChain = Promise.resolve();
  3526. var skinMap = {};
  3527. var _loop_2 = function (skeleton) {
  3528. // create skin
  3529. var skin = { joints: [] };
  3530. var inverseBindMatrices = [];
  3531. var skeletonMesh = babylonScene.meshes.find(function (mesh) { mesh.skeleton === skeleton; });
  3532. skin.skeleton = skeleton.overrideMesh === null ? (skeletonMesh ? nodeMap[skeletonMesh.uniqueId] : undefined) : nodeMap[skeleton.overrideMesh.uniqueId];
  3533. var boneIndexMap = {};
  3534. var boneIndexMax = -1;
  3535. var boneIndex = -1;
  3536. for (var _i = 0, _a = skeleton.bones; _i < _a.length; _i++) {
  3537. var bone = _a[_i];
  3538. boneIndex = bone.getIndex();
  3539. if (boneIndex > -1) {
  3540. boneIndexMap[boneIndex] = bone;
  3541. }
  3542. boneIndexMax = Math.max(boneIndexMax, boneIndex);
  3543. }
  3544. for (var i = 0; i <= boneIndexMax; ++i) {
  3545. var bone = boneIndexMap[i];
  3546. var transformNode = bone.getTransformNode();
  3547. if (transformNode) {
  3548. var boneMatrix = bone.getInvertedAbsoluteTransform();
  3549. if (this_2._convertToRightHandedSystem) {
  3550. _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._GetRightHandedMatrixFromRef(boneMatrix);
  3551. }
  3552. inverseBindMatrices.push(boneMatrix);
  3553. skin.joints.push(nodeMap[transformNode.uniqueId]);
  3554. }
  3555. }
  3556. // create buffer view for inverse bind matrices
  3557. var byteStride = 64; // 4 x 4 matrix of 32 bit float
  3558. var byteLength = inverseBindMatrices.length * byteStride;
  3559. var bufferViewOffset = binaryWriter.getByteOffset();
  3560. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateBufferView(0, bufferViewOffset, byteLength, byteStride, "InverseBindMatrices" + " - " + skeleton.name);
  3561. this_2._bufferViews.push(bufferView);
  3562. var bufferViewIndex = this_2._bufferViews.length - 1;
  3563. var bindMatrixAccessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_3__["_GLTFUtilities"]._CreateAccessor(bufferViewIndex, "InverseBindMatrices" + " - " + skeleton.name, "MAT4" /* MAT4 */, 5126 /* FLOAT */, inverseBindMatrices.length, null, null, null);
  3564. var inverseBindAccessorIndex = this_2._accessors.push(bindMatrixAccessor) - 1;
  3565. skin.inverseBindMatrices = inverseBindAccessorIndex;
  3566. this_2._skins.push(skin);
  3567. skinMap[skeleton.uniqueId] = this_2._skins.length - 1;
  3568. inverseBindMatrices.forEach(function (mat) {
  3569. mat.m.forEach(function (cell) {
  3570. binaryWriter.setFloat32(cell);
  3571. });
  3572. });
  3573. };
  3574. var this_2 = this;
  3575. for (var _i = 0, _a = babylonScene.skeletons; _i < _a.length; _i++) {
  3576. var skeleton = _a[_i];
  3577. _loop_2(skeleton);
  3578. }
  3579. return promiseChain.then(function () {
  3580. return skinMap;
  3581. });
  3582. };
  3583. _Exporter._ExtensionNames = new Array();
  3584. _Exporter._ExtensionFactories = {};
  3585. return _Exporter;
  3586. }());
  3587. /**
  3588. * @hidden
  3589. *
  3590. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  3591. */
  3592. var _BinaryWriter = /** @class */ (function () {
  3593. /**
  3594. * Initialize binary writer with an initial byte length
  3595. * @param byteLength Initial byte length of the array buffer
  3596. */
  3597. function _BinaryWriter(byteLength) {
  3598. this._arrayBuffer = new ArrayBuffer(byteLength);
  3599. this._dataView = new DataView(this._arrayBuffer);
  3600. this._byteOffset = 0;
  3601. }
  3602. /**
  3603. * Resize the array buffer to the specified byte length
  3604. * @param byteLength
  3605. */
  3606. _BinaryWriter.prototype.resizeBuffer = function (byteLength) {
  3607. var newBuffer = new ArrayBuffer(byteLength);
  3608. var oldUint8Array = new Uint8Array(this._arrayBuffer);
  3609. var newUint8Array = new Uint8Array(newBuffer);
  3610. for (var i = 0, length_10 = newUint8Array.byteLength; i < length_10; ++i) {
  3611. newUint8Array[i] = oldUint8Array[i];
  3612. }
  3613. this._arrayBuffer = newBuffer;
  3614. this._dataView = new DataView(this._arrayBuffer);
  3615. return newBuffer;
  3616. };
  3617. /**
  3618. * Get an array buffer with the length of the byte offset
  3619. * @returns ArrayBuffer resized to the byte offset
  3620. */
  3621. _BinaryWriter.prototype.getArrayBuffer = function () {
  3622. return this.resizeBuffer(this.getByteOffset());
  3623. };
  3624. /**
  3625. * Get the byte offset of the array buffer
  3626. * @returns byte offset
  3627. */
  3628. _BinaryWriter.prototype.getByteOffset = function () {
  3629. if (this._byteOffset == undefined) {
  3630. throw new Error("Byte offset is undefined!");
  3631. }
  3632. return this._byteOffset;
  3633. };
  3634. /**
  3635. * Stores an UInt8 in the array buffer
  3636. * @param entry
  3637. * @param byteOffset If defined, specifies where to set the value as an offset.
  3638. */
  3639. _BinaryWriter.prototype.setUInt8 = function (entry, byteOffset) {
  3640. if (byteOffset != null) {
  3641. if (byteOffset < this._byteOffset) {
  3642. this._dataView.setUint8(byteOffset, entry);
  3643. }
  3644. else {
  3645. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  3646. }
  3647. }
  3648. else {
  3649. if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
  3650. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  3651. }
  3652. this._dataView.setUint8(this._byteOffset, entry);
  3653. this._byteOffset += 1;
  3654. }
  3655. };
  3656. /**
  3657. * Stores an UInt16 in the array buffer
  3658. * @param entry
  3659. * @param byteOffset If defined, specifies where to set the value as an offset.
  3660. */
  3661. _BinaryWriter.prototype.setUInt16 = function (entry, byteOffset) {
  3662. if (byteOffset != null) {
  3663. if (byteOffset < this._byteOffset) {
  3664. this._dataView.setUint16(byteOffset, entry, true);
  3665. }
  3666. else {
  3667. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  3668. }
  3669. }
  3670. else {
  3671. if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {
  3672. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  3673. }
  3674. this._dataView.setUint16(this._byteOffset, entry, true);
  3675. this._byteOffset += 2;
  3676. }
  3677. };
  3678. /**
  3679. * Gets an UInt32 in the array buffer
  3680. * @param entry
  3681. * @param byteOffset If defined, specifies where to set the value as an offset.
  3682. */
  3683. _BinaryWriter.prototype.getUInt32 = function (byteOffset) {
  3684. if (byteOffset < this._byteOffset) {
  3685. return this._dataView.getUint32(byteOffset, true);
  3686. }
  3687. else {
  3688. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  3689. throw new Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  3690. }
  3691. };
  3692. _BinaryWriter.prototype.getVector3Float32FromRef = function (vector3, byteOffset) {
  3693. if (byteOffset + 8 > this._byteOffset) {
  3694. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  3695. }
  3696. else {
  3697. vector3.x = this._dataView.getFloat32(byteOffset, true);
  3698. vector3.y = this._dataView.getFloat32(byteOffset + 4, true);
  3699. vector3.z = this._dataView.getFloat32(byteOffset + 8, true);
  3700. }
  3701. };
  3702. _BinaryWriter.prototype.setVector3Float32FromRef = function (vector3, byteOffset) {
  3703. if (byteOffset + 8 > this._byteOffset) {
  3704. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  3705. }
  3706. else {
  3707. this._dataView.setFloat32(byteOffset, vector3.x, true);
  3708. this._dataView.setFloat32(byteOffset + 4, vector3.y, true);
  3709. this._dataView.setFloat32(byteOffset + 8, vector3.z, true);
  3710. }
  3711. };
  3712. _BinaryWriter.prototype.getVector4Float32FromRef = function (vector4, byteOffset) {
  3713. if (byteOffset + 12 > this._byteOffset) {
  3714. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  3715. }
  3716. else {
  3717. vector4.x = this._dataView.getFloat32(byteOffset, true);
  3718. vector4.y = this._dataView.getFloat32(byteOffset + 4, true);
  3719. vector4.z = this._dataView.getFloat32(byteOffset + 8, true);
  3720. vector4.w = this._dataView.getFloat32(byteOffset + 12, true);
  3721. }
  3722. };
  3723. _BinaryWriter.prototype.setVector4Float32FromRef = function (vector4, byteOffset) {
  3724. if (byteOffset + 12 > this._byteOffset) {
  3725. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  3726. }
  3727. else {
  3728. this._dataView.setFloat32(byteOffset, vector4.x, true);
  3729. this._dataView.setFloat32(byteOffset + 4, vector4.y, true);
  3730. this._dataView.setFloat32(byteOffset + 8, vector4.z, true);
  3731. this._dataView.setFloat32(byteOffset + 12, vector4.w, true);
  3732. }
  3733. };
  3734. /**
  3735. * Stores a Float32 in the array buffer
  3736. * @param entry
  3737. */
  3738. _BinaryWriter.prototype.setFloat32 = function (entry, byteOffset) {
  3739. if (isNaN(entry)) {
  3740. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('Invalid data being written!');
  3741. }
  3742. if (byteOffset != null) {
  3743. if (byteOffset < this._byteOffset) {
  3744. this._dataView.setFloat32(byteOffset, entry, true);
  3745. }
  3746. else {
  3747. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary length!');
  3748. }
  3749. }
  3750. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  3751. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  3752. }
  3753. this._dataView.setFloat32(this._byteOffset, entry, true);
  3754. this._byteOffset += 4;
  3755. };
  3756. /**
  3757. * Stores an UInt32 in the array buffer
  3758. * @param entry
  3759. * @param byteOffset If defined, specifies where to set the value as an offset.
  3760. */
  3761. _BinaryWriter.prototype.setUInt32 = function (entry, byteOffset) {
  3762. if (byteOffset != null) {
  3763. if (byteOffset < this._byteOffset) {
  3764. this._dataView.setUint32(byteOffset, entry, true);
  3765. }
  3766. else {
  3767. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  3768. }
  3769. }
  3770. else {
  3771. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  3772. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  3773. }
  3774. this._dataView.setUint32(this._byteOffset, entry, true);
  3775. this._byteOffset += 4;
  3776. }
  3777. };
  3778. return _BinaryWriter;
  3779. }());
  3780. /***/ }),
  3781. /***/ "./glTF/2.0/glTFExporterExtension.ts":
  3782. /*!*******************************************!*\
  3783. !*** ./glTF/2.0/glTFExporterExtension.ts ***!
  3784. \*******************************************/
  3785. /*! exports provided: __IGLTFExporterExtensionV2 */
  3786. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3787. "use strict";
  3788. __webpack_require__.r(__webpack_exports__);
  3789. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return __IGLTFExporterExtensionV2; });
  3790. /** @hidden */
  3791. var __IGLTFExporterExtensionV2 = 0; // I am here to allow dts to be created
  3792. /***/ }),
  3793. /***/ "./glTF/2.0/glTFMaterialExporter.ts":
  3794. /*!******************************************!*\
  3795. !*** ./glTF/2.0/glTFMaterialExporter.ts ***!
  3796. \******************************************/
  3797. /*! exports provided: _GLTFMaterialExporter */
  3798. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3799. "use strict";
  3800. __webpack_require__.r(__webpack_exports__);
  3801. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _GLTFMaterialExporter; });
  3802. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  3803. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Maths/math.vector");
  3804. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__);
  3805. /**
  3806. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  3807. * @hidden
  3808. */
  3809. var _GLTFMaterialExporter = /** @class */ (function () {
  3810. function _GLTFMaterialExporter(exporter) {
  3811. /**
  3812. * Mapping to store textures
  3813. */
  3814. this._textureMap = {};
  3815. this._textureMap = {};
  3816. this._exporter = exporter;
  3817. }
  3818. /**
  3819. * Specifies if two colors are approximately equal in value
  3820. * @param color1 first color to compare to
  3821. * @param color2 second color to compare to
  3822. * @param epsilon threshold value
  3823. */
  3824. _GLTFMaterialExporter.FuzzyEquals = function (color1, color2, epsilon) {
  3825. return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Scalar"].WithinEpsilon(color1.r, color2.r, epsilon) &&
  3826. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Scalar"].WithinEpsilon(color1.g, color2.g, epsilon) &&
  3827. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Scalar"].WithinEpsilon(color1.b, color2.b, epsilon);
  3828. };
  3829. /**
  3830. * Gets the materials from a Babylon scene and converts them to glTF materials
  3831. * @param scene babylonjs scene
  3832. * @param mimeType texture mime type
  3833. * @param images array of images
  3834. * @param textures array of textures
  3835. * @param materials array of materials
  3836. * @param imageData mapping of texture names to base64 textures
  3837. * @param hasTextureCoords specifies if texture coordinates are present on the material
  3838. */
  3839. _GLTFMaterialExporter.prototype._convertMaterialsToGLTFAsync = function (babylonMaterials, mimeType, hasTextureCoords) {
  3840. var promises = [];
  3841. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  3842. var babylonMaterial = babylonMaterials_1[_i];
  3843. if (babylonMaterial instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["StandardMaterial"]) {
  3844. promises.push(this._convertStandardMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  3845. }
  3846. else if (babylonMaterial instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["PBRBaseMaterial"]) {
  3847. promises.push(this._convertPBRMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  3848. }
  3849. else {
  3850. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn("Unsupported material type: " + babylonMaterial.name);
  3851. }
  3852. }
  3853. return Promise.all(promises).then(function () { });
  3854. };
  3855. /**
  3856. * Makes a copy of the glTF material without the texture parameters
  3857. * @param originalMaterial original glTF material
  3858. * @returns glTF material without texture parameters
  3859. */
  3860. _GLTFMaterialExporter.prototype._stripTexturesFromMaterial = function (originalMaterial) {
  3861. var newMaterial = {};
  3862. if (originalMaterial) {
  3863. newMaterial.name = originalMaterial.name;
  3864. newMaterial.doubleSided = originalMaterial.doubleSided;
  3865. newMaterial.alphaMode = originalMaterial.alphaMode;
  3866. newMaterial.alphaCutoff = originalMaterial.alphaCutoff;
  3867. newMaterial.emissiveFactor = originalMaterial.emissiveFactor;
  3868. var originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;
  3869. if (originalPBRMetallicRoughness) {
  3870. newMaterial.pbrMetallicRoughness = {};
  3871. newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;
  3872. newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;
  3873. newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;
  3874. }
  3875. }
  3876. return newMaterial;
  3877. };
  3878. /**
  3879. * Specifies if the material has any texture parameters present
  3880. * @param material glTF Material
  3881. * @returns boolean specifying if texture parameters are present
  3882. */
  3883. _GLTFMaterialExporter.prototype._hasTexturesPresent = function (material) {
  3884. if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {
  3885. return true;
  3886. }
  3887. var pbrMat = material.pbrMetallicRoughness;
  3888. if (pbrMat) {
  3889. if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {
  3890. return true;
  3891. }
  3892. }
  3893. return false;
  3894. };
  3895. /**
  3896. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  3897. * @param babylonStandardMaterial
  3898. * @returns glTF Metallic Roughness Material representation
  3899. */
  3900. _GLTFMaterialExporter.prototype._convertToGLTFPBRMetallicRoughness = function (babylonStandardMaterial) {
  3901. var P0 = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"](0, 1);
  3902. var P1 = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"](0, 0.1);
  3903. var P2 = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"](0, 0.1);
  3904. var P3 = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector2"](1300, 0.1);
  3905. /**
  3906. * Given the control points, solve for x based on a given t for a cubic bezier curve
  3907. * @param t a value between 0 and 1
  3908. * @param p0 first control point
  3909. * @param p1 second control point
  3910. * @param p2 third control point
  3911. * @param p3 fourth control point
  3912. * @returns number result of cubic bezier curve at the specified t
  3913. */
  3914. function _cubicBezierCurve(t, p0, p1, p2, p3) {
  3915. return ((1 - t) * (1 - t) * (1 - t) * p0 +
  3916. 3 * (1 - t) * (1 - t) * t * p1 +
  3917. 3 * (1 - t) * t * t * p2 +
  3918. t * t * t * p3);
  3919. }
  3920. /**
  3921. * Evaluates a specified specular power value to determine the appropriate roughness value,
  3922. * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)
  3923. * and roughness on the ordinant axis (y-axis)
  3924. * @param specularPower specular power of standard material
  3925. * @returns Number representing the roughness value
  3926. */
  3927. function _solveForRoughness(specularPower) {
  3928. var t = Math.pow(specularPower / P3.x, 0.333333);
  3929. return _cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);
  3930. }
  3931. var diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace().scale(0.5);
  3932. var opacity = babylonStandardMaterial.alpha;
  3933. var specularPower = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Scalar"].Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);
  3934. var roughness = _solveForRoughness(specularPower);
  3935. var glTFPbrMetallicRoughness = {
  3936. baseColorFactor: [
  3937. diffuse.r,
  3938. diffuse.g,
  3939. diffuse.b,
  3940. opacity
  3941. ],
  3942. metallicFactor: 0,
  3943. roughnessFactor: roughness,
  3944. };
  3945. return glTFPbrMetallicRoughness;
  3946. };
  3947. /**
  3948. * Computes the metallic factor
  3949. * @param diffuse diffused value
  3950. * @param specular specular value
  3951. * @param oneMinusSpecularStrength one minus the specular strength
  3952. * @returns metallic value
  3953. */
  3954. _GLTFMaterialExporter._SolveMetallic = function (diffuse, specular, oneMinusSpecularStrength) {
  3955. if (specular < this._DielectricSpecular.r) {
  3956. this._DielectricSpecular;
  3957. return 0;
  3958. }
  3959. var a = this._DielectricSpecular.r;
  3960. var b = diffuse * oneMinusSpecularStrength / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;
  3961. var c = this._DielectricSpecular.r - specular;
  3962. var D = b * b - 4.0 * a * c;
  3963. return babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Scalar"].Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);
  3964. };
  3965. /**
  3966. * Sets the glTF alpha mode to a glTF material from the Babylon Material
  3967. * @param glTFMaterial glTF material
  3968. * @param babylonMaterial Babylon material
  3969. */
  3970. _GLTFMaterialExporter._SetAlphaMode = function (glTFMaterial, babylonMaterial) {
  3971. if (babylonMaterial.needAlphaBlending()) {
  3972. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  3973. }
  3974. else if (babylonMaterial.needAlphaTesting()) {
  3975. glTFMaterial.alphaMode = "MASK" /* MASK */;
  3976. glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;
  3977. }
  3978. };
  3979. /**
  3980. * Converts a Babylon Standard Material to a glTF Material
  3981. * @param babylonStandardMaterial BJS Standard Material
  3982. * @param mimeType mime type to use for the textures
  3983. * @param images array of glTF image interfaces
  3984. * @param textures array of glTF texture interfaces
  3985. * @param materials array of glTF material interfaces
  3986. * @param imageData map of image file name to data
  3987. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3988. */
  3989. _GLTFMaterialExporter.prototype._convertStandardMaterialAsync = function (babylonStandardMaterial, mimeType, hasTextureCoords) {
  3990. var materialMap = this._exporter._materialMap;
  3991. var materials = this._exporter._materials;
  3992. var promises = [];
  3993. var glTFPbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);
  3994. var glTFMaterial = { name: babylonStandardMaterial.name };
  3995. if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {
  3996. if (!babylonStandardMaterial.twoSidedLighting) {
  3997. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn(babylonStandardMaterial.name + ": Back-face culling enabled and two-sided lighting disabled is not supported in glTF.");
  3998. }
  3999. glTFMaterial.doubleSided = true;
  4000. }
  4001. if (hasTextureCoords) {
  4002. if (babylonStandardMaterial.diffuseTexture) {
  4003. promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then(function (glTFTexture) {
  4004. if (glTFTexture) {
  4005. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  4006. }
  4007. }));
  4008. }
  4009. if (babylonStandardMaterial.bumpTexture) {
  4010. promises.push(this._exportTextureAsync(babylonStandardMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  4011. if (glTFTexture) {
  4012. glTFMaterial.normalTexture = glTFTexture;
  4013. if (babylonStandardMaterial.bumpTexture != null && babylonStandardMaterial.bumpTexture.level !== 1) {
  4014. glTFMaterial.normalTexture.scale = babylonStandardMaterial.bumpTexture.level;
  4015. }
  4016. }
  4017. }));
  4018. }
  4019. if (babylonStandardMaterial.emissiveTexture) {
  4020. glTFMaterial.emissiveFactor = [1.0, 1.0, 1.0];
  4021. promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then(function (glTFEmissiveTexture) {
  4022. if (glTFEmissiveTexture) {
  4023. glTFMaterial.emissiveTexture = glTFEmissiveTexture;
  4024. }
  4025. }));
  4026. }
  4027. if (babylonStandardMaterial.ambientTexture) {
  4028. promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  4029. if (glTFTexture) {
  4030. var occlusionTexture = {
  4031. index: glTFTexture.index
  4032. };
  4033. glTFMaterial.occlusionTexture = occlusionTexture;
  4034. occlusionTexture.strength = 1.0;
  4035. }
  4036. }));
  4037. }
  4038. }
  4039. if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {
  4040. if (babylonStandardMaterial.alphaMode === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].ALPHA_COMBINE) {
  4041. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  4042. }
  4043. else {
  4044. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn(babylonStandardMaterial.name + ": glTF 2.0 does not support alpha mode: " + babylonStandardMaterial.alphaMode.toString());
  4045. }
  4046. }
  4047. if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter.FuzzyEquals(babylonStandardMaterial.emissiveColor, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  4048. glTFMaterial.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();
  4049. }
  4050. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  4051. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonStandardMaterial);
  4052. materials.push(glTFMaterial);
  4053. materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;
  4054. return this._finishMaterial(promises, glTFMaterial, babylonStandardMaterial, mimeType);
  4055. };
  4056. _GLTFMaterialExporter.prototype._finishMaterial = function (promises, glTFMaterial, babylonMaterial, mimeType) {
  4057. var _this = this;
  4058. return Promise.all(promises).then(function () {
  4059. var textures = _this._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial", glTFMaterial, babylonMaterial);
  4060. var tasks = null;
  4061. for (var _i = 0, textures_1 = textures; _i < textures_1.length; _i++) {
  4062. var texture = textures_1[_i];
  4063. if (!tasks) {
  4064. tasks = [];
  4065. }
  4066. tasks.push(_this._exportTextureAsync(texture, mimeType));
  4067. }
  4068. if (!tasks) {
  4069. tasks = [Promise.resolve(null)];
  4070. }
  4071. return Promise.all(tasks).then(function () {
  4072. var extensionWork = _this._exporter._extensionsPostExportMaterialAsync("exportMaterial", glTFMaterial, babylonMaterial);
  4073. if (!extensionWork) {
  4074. return glTFMaterial;
  4075. }
  4076. return extensionWork.then(function () { return glTFMaterial; });
  4077. });
  4078. });
  4079. };
  4080. /**
  4081. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  4082. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  4083. * @param mimeType mime type to use for the textures
  4084. * @param images array of glTF image interfaces
  4085. * @param textures array of glTF texture interfaces
  4086. * @param materials array of glTF material interfaces
  4087. * @param imageData map of image file name to data
  4088. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  4089. */
  4090. _GLTFMaterialExporter.prototype._convertPBRMetallicRoughnessMaterialAsync = function (babylonPBRMetalRoughMaterial, mimeType, hasTextureCoords) {
  4091. var materialMap = this._exporter._materialMap;
  4092. var materials = this._exporter._materials;
  4093. var promises = [];
  4094. var glTFPbrMetallicRoughness = {};
  4095. if (babylonPBRMetalRoughMaterial.baseColor) {
  4096. glTFPbrMetallicRoughness.baseColorFactor = [
  4097. babylonPBRMetalRoughMaterial.baseColor.r,
  4098. babylonPBRMetalRoughMaterial.baseColor.g,
  4099. babylonPBRMetalRoughMaterial.baseColor.b,
  4100. babylonPBRMetalRoughMaterial.alpha
  4101. ];
  4102. }
  4103. if (babylonPBRMetalRoughMaterial.metallic != null && babylonPBRMetalRoughMaterial.metallic !== 1) {
  4104. glTFPbrMetallicRoughness.metallicFactor = babylonPBRMetalRoughMaterial.metallic;
  4105. }
  4106. if (babylonPBRMetalRoughMaterial.roughness != null && babylonPBRMetalRoughMaterial.roughness !== 1) {
  4107. glTFPbrMetallicRoughness.roughnessFactor = babylonPBRMetalRoughMaterial.roughness;
  4108. }
  4109. var glTFMaterial = {
  4110. name: babylonPBRMetalRoughMaterial.name
  4111. };
  4112. if (babylonPBRMetalRoughMaterial.doubleSided) {
  4113. glTFMaterial.doubleSided = babylonPBRMetalRoughMaterial.doubleSided;
  4114. }
  4115. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMetalRoughMaterial);
  4116. if (hasTextureCoords) {
  4117. if (babylonPBRMetalRoughMaterial.baseTexture != null) {
  4118. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.baseTexture, mimeType).then(function (glTFTexture) {
  4119. if (glTFTexture) {
  4120. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  4121. }
  4122. }));
  4123. }
  4124. if (babylonPBRMetalRoughMaterial.normalTexture) {
  4125. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.normalTexture, mimeType).then(function (glTFTexture) {
  4126. if (glTFTexture) {
  4127. glTFMaterial.normalTexture = glTFTexture;
  4128. if (babylonPBRMetalRoughMaterial.normalTexture.level !== 1) {
  4129. glTFMaterial.normalTexture.scale = babylonPBRMetalRoughMaterial.normalTexture.level;
  4130. }
  4131. }
  4132. }));
  4133. }
  4134. if (babylonPBRMetalRoughMaterial.occlusionTexture) {
  4135. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.occlusionTexture, mimeType).then(function (glTFTexture) {
  4136. if (glTFTexture) {
  4137. glTFMaterial.occlusionTexture = glTFTexture;
  4138. if (babylonPBRMetalRoughMaterial.occlusionStrength != null) {
  4139. glTFMaterial.occlusionTexture.strength = babylonPBRMetalRoughMaterial.occlusionStrength;
  4140. }
  4141. }
  4142. }));
  4143. }
  4144. if (babylonPBRMetalRoughMaterial.emissiveTexture) {
  4145. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  4146. if (glTFTexture) {
  4147. glTFMaterial.emissiveTexture = glTFTexture;
  4148. }
  4149. }));
  4150. }
  4151. }
  4152. if (_GLTFMaterialExporter.FuzzyEquals(babylonPBRMetalRoughMaterial.emissiveColor, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  4153. glTFMaterial.emissiveFactor = babylonPBRMetalRoughMaterial.emissiveColor.asArray();
  4154. }
  4155. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  4156. materials.push(glTFMaterial);
  4157. materialMap[babylonPBRMetalRoughMaterial.uniqueId] = materials.length - 1;
  4158. return this._finishMaterial(promises, glTFMaterial, babylonPBRMetalRoughMaterial, mimeType);
  4159. };
  4160. /**
  4161. * Converts an image typed array buffer to a base64 image
  4162. * @param buffer typed array buffer
  4163. * @param width width of the image
  4164. * @param height height of the image
  4165. * @param mimeType mimetype of the image
  4166. * @returns base64 image string
  4167. */
  4168. _GLTFMaterialExporter.prototype._createBase64FromCanvasAsync = function (buffer, width, height, mimeType) {
  4169. var _this = this;
  4170. return new Promise(function (resolve, reject) { return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(_this, void 0, void 0, function () {
  4171. var textureType, hostingScene, engine, tempTexture, data, base64;
  4172. return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__generator"])(this, function (_a) {
  4173. switch (_a.label) {
  4174. case 0:
  4175. textureType = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].TEXTURETYPE_UNSIGNED_INT;
  4176. hostingScene = this._exporter._babylonScene;
  4177. engine = hostingScene.getEngine();
  4178. tempTexture = engine.createRawTexture(buffer, width, height, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].TEXTUREFORMAT_RGBA, false, true, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE, null, textureType);
  4179. return [4 /*yield*/, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["TextureTools"].ApplyPostProcess("pass", tempTexture, hostingScene, textureType, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].TEXTURE_NEAREST_SAMPLINGMODE, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].TEXTUREFORMAT_RGBA)];
  4180. case 1:
  4181. _a.sent();
  4182. return [4 /*yield*/, engine._readTexturePixels(tempTexture, width, height)];
  4183. case 2:
  4184. data = _a.sent();
  4185. return [4 /*yield*/, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].DumpDataAsync(width, height, data, mimeType, undefined, true, false)];
  4186. case 3:
  4187. base64 = _a.sent();
  4188. resolve(base64);
  4189. return [2 /*return*/];
  4190. }
  4191. });
  4192. }); });
  4193. };
  4194. /**
  4195. * Generates a white texture based on the specified width and height
  4196. * @param width width of the texture in pixels
  4197. * @param height height of the texture in pixels
  4198. * @param scene babylonjs scene
  4199. * @returns white texture
  4200. */
  4201. _GLTFMaterialExporter.prototype._createWhiteTexture = function (width, height, scene) {
  4202. var data = new Uint8Array(width * height * 4);
  4203. for (var i = 0; i < data.length; i = i + 4) {
  4204. data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xFF;
  4205. }
  4206. var rawTexture = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["RawTexture"].CreateRGBATexture(data, width, height, scene);
  4207. return rawTexture;
  4208. };
  4209. /**
  4210. * 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
  4211. * @param texture1 first texture to resize
  4212. * @param texture2 second texture to resize
  4213. * @param scene babylonjs scene
  4214. * @returns resized textures or null
  4215. */
  4216. _GLTFMaterialExporter.prototype._resizeTexturesToSameDimensions = function (texture1, texture2, scene) {
  4217. var texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };
  4218. var texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };
  4219. var resizedTexture1;
  4220. var resizedTexture2;
  4221. if (texture1Size.width < texture2Size.width) {
  4222. if (texture1 && texture1 instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"]) {
  4223. resizedTexture1 = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["TextureTools"].CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);
  4224. }
  4225. else {
  4226. resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);
  4227. }
  4228. resizedTexture2 = texture2;
  4229. }
  4230. else if (texture1Size.width > texture2Size.width) {
  4231. if (texture2 && texture2 instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"]) {
  4232. resizedTexture2 = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["TextureTools"].CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);
  4233. }
  4234. else {
  4235. resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);
  4236. }
  4237. resizedTexture1 = texture1;
  4238. }
  4239. else {
  4240. resizedTexture1 = texture1;
  4241. resizedTexture2 = texture2;
  4242. }
  4243. return {
  4244. "texture1": resizedTexture1,
  4245. "texture2": resizedTexture2
  4246. };
  4247. };
  4248. /**
  4249. * Converts an array of pixels to a Float32Array
  4250. * Throws an error if the pixel format is not supported
  4251. * @param pixels - array buffer containing pixel values
  4252. * @returns Float32 of pixels
  4253. */
  4254. _GLTFMaterialExporter.prototype._convertPixelArrayToFloat32 = function (pixels) {
  4255. if (pixels instanceof Uint8Array) {
  4256. var length_1 = pixels.length;
  4257. var buffer = new Float32Array(pixels.length);
  4258. for (var i = 0; i < length_1; ++i) {
  4259. buffer[i] = pixels[i] / 255;
  4260. }
  4261. return buffer;
  4262. }
  4263. else if (pixels instanceof Float32Array) {
  4264. return pixels;
  4265. }
  4266. else {
  4267. throw new Error('Unsupported pixel format!');
  4268. }
  4269. };
  4270. /**
  4271. * Convert Specular Glossiness Textures to Metallic Roughness
  4272. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  4273. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  4274. * @param diffuseTexture texture used to store diffuse information
  4275. * @param specularGlossinessTexture texture used to store specular and glossiness information
  4276. * @param factors specular glossiness material factors
  4277. * @param mimeType the mime type to use for the texture
  4278. * @returns pbr metallic roughness interface or null
  4279. */
  4280. _GLTFMaterialExporter.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync = function (diffuseTexture, specularGlossinessTexture, factors, mimeType) {
  4281. return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(this, void 0, void 0, function () {
  4282. var promises, scene, resizedTextures, diffuseSize, diffuseBuffer, specularGlossinessBuffer, width, height, diffusePixels, specularPixels, byteLength, metallicRoughnessBuffer, baseColorBuffer, strideSize, maxBaseColor, maxMetallic, maxRoughness, h, w, offset, diffuseColor, specularColor, glossiness, specularGlossiness, metallicRoughness, metallicRoughnessFactors_1, writeOutMetallicRoughnessTexture, writeOutBaseColorTexture, h, w, destinationOffset, linearBaseColorPixel, sRGBBaseColorPixel, metallicRoughnessPixel, promise, promise;
  4283. return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__generator"])(this, function (_a) {
  4284. switch (_a.label) {
  4285. case 0:
  4286. promises = [];
  4287. if (!(diffuseTexture || specularGlossinessTexture)) {
  4288. return [2 /*return*/, Promise.reject('_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!')];
  4289. }
  4290. scene = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;
  4291. if (!scene) return [3 /*break*/, 3];
  4292. resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);
  4293. diffuseSize = resizedTextures.texture1.getSize();
  4294. diffuseBuffer = void 0;
  4295. specularGlossinessBuffer = void 0;
  4296. width = diffuseSize.width;
  4297. height = diffuseSize.height;
  4298. return [4 /*yield*/, resizedTextures.texture1.readPixels()];
  4299. case 1:
  4300. diffusePixels = _a.sent();
  4301. return [4 /*yield*/, resizedTextures.texture2.readPixels()];
  4302. case 2:
  4303. specularPixels = _a.sent();
  4304. if (diffusePixels) {
  4305. diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);
  4306. }
  4307. else {
  4308. return [2 /*return*/, Promise.reject("Failed to retrieve pixels from diffuse texture!")];
  4309. }
  4310. if (specularPixels) {
  4311. specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);
  4312. }
  4313. else {
  4314. return [2 /*return*/, Promise.reject("Failed to retrieve pixels from specular glossiness texture!")];
  4315. }
  4316. byteLength = specularGlossinessBuffer.byteLength;
  4317. metallicRoughnessBuffer = new Uint8Array(byteLength);
  4318. baseColorBuffer = new Uint8Array(byteLength);
  4319. strideSize = 4;
  4320. maxBaseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].Black();
  4321. maxMetallic = 0;
  4322. maxRoughness = 0;
  4323. for (h = 0; h < height; ++h) {
  4324. for (w = 0; w < width; ++w) {
  4325. offset = (width * h + w) * strideSize;
  4326. diffuseColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2]).toLinearSpace().multiply(factors.diffuseColor);
  4327. specularColor = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2]).toLinearSpace().multiply(factors.specularColor);
  4328. glossiness = (specularGlossinessBuffer[offset + 3]) * factors.glossiness;
  4329. specularGlossiness = {
  4330. diffuseColor: diffuseColor,
  4331. specularColor: specularColor,
  4332. glossiness: glossiness
  4333. };
  4334. metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);
  4335. maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);
  4336. maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);
  4337. maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);
  4338. maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic);
  4339. maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness);
  4340. baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;
  4341. baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;
  4342. baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;
  4343. baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;
  4344. metallicRoughnessBuffer[offset] = 0;
  4345. metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness * 255;
  4346. metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic * 255;
  4347. metallicRoughnessBuffer[offset + 3] = 255;
  4348. }
  4349. }
  4350. metallicRoughnessFactors_1 = {
  4351. baseColor: maxBaseColor,
  4352. metallic: maxMetallic,
  4353. roughness: maxRoughness
  4354. };
  4355. writeOutMetallicRoughnessTexture = false;
  4356. writeOutBaseColorTexture = false;
  4357. for (h = 0; h < height; ++h) {
  4358. for (w = 0; w < width; ++w) {
  4359. destinationOffset = (width * h + w) * strideSize;
  4360. baseColorBuffer[destinationOffset] /= metallicRoughnessFactors_1.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.r : 1;
  4361. baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.g : 1;
  4362. baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.b : 1;
  4363. linearBaseColorPixel = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromInts(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);
  4364. sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace();
  4365. baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;
  4366. baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;
  4367. baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;
  4368. if (!_GLTFMaterialExporter.FuzzyEquals(sRGBBaseColorPixel, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  4369. writeOutBaseColorTexture = true;
  4370. }
  4371. metallicRoughnessBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.roughness > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.roughness : 1;
  4372. metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.metallic > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.metallic : 1;
  4373. metallicRoughnessPixel = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);
  4374. if (!_GLTFMaterialExporter.FuzzyEquals(metallicRoughnessPixel, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  4375. writeOutMetallicRoughnessTexture = true;
  4376. }
  4377. }
  4378. }
  4379. if (writeOutMetallicRoughnessTexture) {
  4380. promise = this._createBase64FromCanvasAsync(metallicRoughnessBuffer, width, height, mimeType).then(function (metallicRoughnessBase64) {
  4381. metallicRoughnessFactors_1.metallicRoughnessTextureBase64 = metallicRoughnessBase64;
  4382. });
  4383. promises.push(promise);
  4384. }
  4385. if (writeOutBaseColorTexture) {
  4386. promise = this._createBase64FromCanvasAsync(baseColorBuffer, width, height, mimeType).then(function (baseColorBase64) {
  4387. metallicRoughnessFactors_1.baseColorTextureBase64 = baseColorBase64;
  4388. });
  4389. promises.push(promise);
  4390. }
  4391. return [2 /*return*/, Promise.all(promises).then(function () {
  4392. return metallicRoughnessFactors_1;
  4393. })];
  4394. case 3: return [2 /*return*/, Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")];
  4395. }
  4396. });
  4397. });
  4398. };
  4399. /**
  4400. * Converts specular glossiness material properties to metallic roughness
  4401. * @param specularGlossiness interface with specular glossiness material properties
  4402. * @returns interface with metallic roughness material properties
  4403. */
  4404. _GLTFMaterialExporter.prototype._convertSpecularGlossinessToMetallicRoughness = function (specularGlossiness) {
  4405. var diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);
  4406. var specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);
  4407. var oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);
  4408. var metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);
  4409. var baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon));
  4410. var baseColorFromSpecular = specularGlossiness.specularColor.subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic)).scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));
  4411. var baseColor = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);
  4412. baseColor = baseColor.clampToRef(0, 1, baseColor);
  4413. var metallicRoughness = {
  4414. baseColor: baseColor,
  4415. metallic: metallic,
  4416. roughness: 1 - specularGlossiness.glossiness
  4417. };
  4418. return metallicRoughness;
  4419. };
  4420. /**
  4421. * Calculates the surface reflectance, independent of lighting conditions
  4422. * @param color Color source to calculate brightness from
  4423. * @returns number representing the perceived brightness, or zero if color is undefined
  4424. */
  4425. _GLTFMaterialExporter.prototype._getPerceivedBrightness = function (color) {
  4426. if (color) {
  4427. return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);
  4428. }
  4429. return 0;
  4430. };
  4431. /**
  4432. * Returns the maximum color component value
  4433. * @param color
  4434. * @returns maximum color component value, or zero if color is null or undefined
  4435. */
  4436. _GLTFMaterialExporter.prototype._getMaxComponent = function (color) {
  4437. if (color) {
  4438. return Math.max(color.r, Math.max(color.g, color.b));
  4439. }
  4440. return 0;
  4441. };
  4442. /**
  4443. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  4444. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  4445. * @param mimeType mime type to use for the textures
  4446. * @param images array of glTF image interfaces
  4447. * @param textures array of glTF texture interfaces
  4448. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  4449. * @param imageData map of image file name to data
  4450. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  4451. * @returns glTF PBR Metallic Roughness factors
  4452. */
  4453. _GLTFMaterialExporter.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  4454. var promises = [];
  4455. var baseColor = babylonPBRMaterial.albedoColor || babylonPBRMaterial.baseColor;
  4456. var metallic = babylonPBRMaterial.metallic || babylonPBRMaterial.metallic;
  4457. var roughness = babylonPBRMaterial.roughness || babylonPBRMaterial.roughness;
  4458. var metallicRoughness = {
  4459. baseColor: baseColor,
  4460. metallic: metallic,
  4461. roughness: roughness
  4462. };
  4463. if (hasTextureCoords) {
  4464. var albedoTexture = babylonPBRMaterial.albedoTexture || babylonPBRMaterial.baseTexture;
  4465. if (albedoTexture) {
  4466. promises.push(this._exportTextureAsync(babylonPBRMaterial.albedoTexture, mimeType).then(function (glTFTexture) {
  4467. if (glTFTexture) {
  4468. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  4469. }
  4470. }));
  4471. }
  4472. var metallicTexture = babylonPBRMaterial.metallicTexture || babylonPBRMaterial.metallicRoughnessTexture;
  4473. if (metallicTexture) {
  4474. promises.push(this._exportTextureAsync(metallicTexture, mimeType).then(function (glTFTexture) {
  4475. if (glTFTexture) {
  4476. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;
  4477. }
  4478. }));
  4479. }
  4480. }
  4481. return Promise.all(promises).then(function () {
  4482. return metallicRoughness;
  4483. });
  4484. };
  4485. _GLTFMaterialExporter.prototype._getGLTFTextureSampler = function (texture) {
  4486. var sampler = this._getGLTFTextureWrapModesSampler(texture);
  4487. var samplingMode = texture instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"] ? texture.samplingMode : null;
  4488. if (samplingMode != null) {
  4489. switch (samplingMode) {
  4490. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].LINEAR_LINEAR: {
  4491. sampler.magFilter = 9729 /* LINEAR */;
  4492. sampler.minFilter = 9729 /* LINEAR */;
  4493. break;
  4494. }
  4495. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].LINEAR_NEAREST: {
  4496. sampler.magFilter = 9729 /* LINEAR */;
  4497. sampler.minFilter = 9728 /* NEAREST */;
  4498. break;
  4499. }
  4500. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_LINEAR: {
  4501. sampler.magFilter = 9728 /* NEAREST */;
  4502. sampler.minFilter = 9729 /* LINEAR */;
  4503. break;
  4504. }
  4505. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_LINEAR_MIPLINEAR: {
  4506. sampler.magFilter = 9728 /* NEAREST */;
  4507. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  4508. break;
  4509. }
  4510. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_NEAREST: {
  4511. sampler.magFilter = 9728 /* NEAREST */;
  4512. sampler.minFilter = 9728 /* NEAREST */;
  4513. break;
  4514. }
  4515. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_LINEAR_MIPNEAREST: {
  4516. sampler.magFilter = 9728 /* NEAREST */;
  4517. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  4518. break;
  4519. }
  4520. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].LINEAR_NEAREST_MIPNEAREST: {
  4521. sampler.magFilter = 9729 /* LINEAR */;
  4522. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  4523. break;
  4524. }
  4525. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].LINEAR_NEAREST_MIPLINEAR: {
  4526. sampler.magFilter = 9729 /* LINEAR */;
  4527. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  4528. break;
  4529. }
  4530. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_NEAREST_MIPLINEAR: {
  4531. sampler.magFilter = 9728 /* NEAREST */;
  4532. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  4533. break;
  4534. }
  4535. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].LINEAR_LINEAR_MIPLINEAR: {
  4536. sampler.magFilter = 9729 /* LINEAR */;
  4537. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  4538. break;
  4539. }
  4540. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].LINEAR_LINEAR_MIPNEAREST: {
  4541. sampler.magFilter = 9729 /* LINEAR */;
  4542. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  4543. break;
  4544. }
  4545. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_NEAREST_MIPNEAREST: {
  4546. sampler.magFilter = 9728 /* NEAREST */;
  4547. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  4548. break;
  4549. }
  4550. }
  4551. }
  4552. return sampler;
  4553. };
  4554. _GLTFMaterialExporter.prototype._getGLTFTextureWrapMode = function (wrapMode) {
  4555. switch (wrapMode) {
  4556. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE: {
  4557. return 10497 /* REPEAT */;
  4558. }
  4559. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE: {
  4560. return 33071 /* CLAMP_TO_EDGE */;
  4561. }
  4562. case babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].MIRROR_ADDRESSMODE: {
  4563. return 33648 /* MIRRORED_REPEAT */;
  4564. }
  4565. default: {
  4566. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported Texture Wrap Mode " + wrapMode + "!");
  4567. return 10497 /* REPEAT */;
  4568. }
  4569. }
  4570. };
  4571. _GLTFMaterialExporter.prototype._getGLTFTextureWrapModesSampler = function (texture) {
  4572. var wrapS = this._getGLTFTextureWrapMode(texture instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"] ? texture.wrapU : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE);
  4573. var wrapT = this._getGLTFTextureWrapMode(texture instanceof babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"] ? texture.wrapV : babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE);
  4574. if (wrapS === 10497 /* REPEAT */ && wrapT === 10497 /* REPEAT */) { // default wrapping mode in glTF, so omitting
  4575. return {};
  4576. }
  4577. return { wrapS: wrapS, wrapT: wrapT };
  4578. };
  4579. /**
  4580. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  4581. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  4582. * @param mimeType mime type to use for the textures
  4583. * @param images array of glTF image interfaces
  4584. * @param textures array of glTF texture interfaces
  4585. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  4586. * @param imageData map of image file name to data
  4587. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  4588. * @returns glTF PBR Metallic Roughness factors
  4589. */
  4590. _GLTFMaterialExporter.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  4591. var _this = this;
  4592. return Promise.resolve().then(function () {
  4593. var samplers = _this._exporter._samplers;
  4594. var textures = _this._exporter._textures;
  4595. var diffuseColor = babylonPBRMaterial.albedoColor || babylonPBRMaterial.diffuseColor || babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].White();
  4596. var specularColor = babylonPBRMaterial.reflectivityColor || babylonPBRMaterial.specularColor || babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].White();
  4597. var glossiness = babylonPBRMaterial.microSurface || babylonPBRMaterial.glossiness || 1;
  4598. var specGloss = {
  4599. diffuseColor: diffuseColor,
  4600. specularColor: specularColor,
  4601. glossiness: glossiness,
  4602. };
  4603. var samplerIndex = null;
  4604. var albedoTexture = babylonPBRMaterial.albedoTexture || babylonPBRMaterial.diffuseTexture;
  4605. var reflectivityTexture = babylonPBRMaterial.reflectivityTexture || babylonPBRMaterial.specularGlossinessTexture;
  4606. var sampler = _this._getGLTFTextureSampler(albedoTexture);
  4607. if (sampler.magFilter != null && sampler.minFilter != null && sampler.wrapS != null && sampler.wrapT != null) {
  4608. samplers.push(sampler);
  4609. samplerIndex = samplers.length - 1;
  4610. }
  4611. var useMicrosurfaceFromReflectivityMapAlpha = babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha || babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha;
  4612. if (reflectivityTexture && !useMicrosurfaceFromReflectivityMapAlpha) {
  4613. return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");
  4614. }
  4615. if ((albedoTexture || reflectivityTexture) && hasTextureCoords) {
  4616. return _this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(albedoTexture, reflectivityTexture, specGloss, mimeType).then(function (metallicRoughnessFactors) {
  4617. if (metallicRoughnessFactors.baseColorTextureBase64) {
  4618. var glTFBaseColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.baseColorTextureBase64, "bjsBaseColorTexture_" + (textures.length) + ".png", mimeType, albedoTexture ? albedoTexture.coordinatesIndex : null, samplerIndex);
  4619. if (glTFBaseColorTexture) {
  4620. glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
  4621. }
  4622. }
  4623. if (metallicRoughnessFactors.metallicRoughnessTextureBase64) {
  4624. var glTFMRColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + (textures.length) + ".png", mimeType, reflectivityTexture ? reflectivityTexture.coordinatesIndex : null, samplerIndex);
  4625. if (glTFMRColorTexture) {
  4626. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
  4627. }
  4628. }
  4629. return metallicRoughnessFactors;
  4630. });
  4631. }
  4632. else {
  4633. return _this._convertSpecularGlossinessToMetallicRoughness(specGloss);
  4634. }
  4635. });
  4636. };
  4637. /**
  4638. * Converts a Babylon PBR Base Material to a glTF Material
  4639. * @param babylonPBRMaterial BJS PBR Base Material
  4640. * @param mimeType mime type to use for the textures
  4641. * @param images array of glTF image interfaces
  4642. * @param textures array of glTF texture interfaces
  4643. * @param materials array of glTF material interfaces
  4644. * @param imageData map of image file name to data
  4645. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  4646. */
  4647. _GLTFMaterialExporter.prototype._convertPBRMaterialAsync = function (babylonPBRMaterial, mimeType, hasTextureCoords) {
  4648. var _this = this;
  4649. var glTFPbrMetallicRoughness = {};
  4650. var glTFMaterial = {
  4651. name: babylonPBRMaterial.name
  4652. };
  4653. var useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();
  4654. if (useMetallicRoughness) {
  4655. var albedoColor = babylonPBRMaterial.albedoColor || babylonPBRMaterial.diffuseColor || babylonPBRMaterial.baseColor;
  4656. var alpha = babylonPBRMaterial.alpha;
  4657. if (albedoColor) {
  4658. glTFPbrMetallicRoughness.baseColorFactor = [
  4659. albedoColor.r,
  4660. albedoColor.g,
  4661. albedoColor.b,
  4662. alpha
  4663. ];
  4664. }
  4665. return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  4666. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  4667. });
  4668. }
  4669. else {
  4670. return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  4671. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  4672. });
  4673. }
  4674. };
  4675. _GLTFMaterialExporter.prototype.setMetallicRoughnessPbrMaterial = function (metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords) {
  4676. var materialMap = this._exporter._materialMap;
  4677. var materials = this._exporter._materials;
  4678. var promises = [];
  4679. if (metallicRoughness) {
  4680. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial);
  4681. if (!(_GLTFMaterialExporter.FuzzyEquals(metallicRoughness.baseColor, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].White(), _GLTFMaterialExporter._Epsilon) && babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon)) {
  4682. glTFPbrMetallicRoughness.baseColorFactor = [
  4683. metallicRoughness.baseColor.r,
  4684. metallicRoughness.baseColor.g,
  4685. metallicRoughness.baseColor.b,
  4686. babylonPBRMaterial.alpha
  4687. ];
  4688. }
  4689. if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {
  4690. glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;
  4691. }
  4692. if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {
  4693. glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;
  4694. }
  4695. if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {
  4696. if (!(babylonPBRMaterial.twoSidedLighting || babylonPBRMaterial.doubleSided)) {
  4697. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Warn(babylonPBRMaterial.name + ": Back-face culling enabled and two-sided lighting disabled is not supported in glTF.");
  4698. }
  4699. glTFMaterial.doubleSided = true;
  4700. }
  4701. if (hasTextureCoords) {
  4702. var bumpTexture_1 = babylonPBRMaterial.bumpTexture || babylonPBRMaterial.normalTexture;
  4703. if (bumpTexture_1) {
  4704. var promise = this._exportTextureAsync(bumpTexture_1, mimeType).then(function (glTFTexture) {
  4705. if (glTFTexture) {
  4706. glTFMaterial.normalTexture = glTFTexture;
  4707. if (bumpTexture_1.level !== 1) {
  4708. glTFMaterial.normalTexture.scale = bumpTexture_1.level;
  4709. }
  4710. }
  4711. });
  4712. promises.push(promise);
  4713. }
  4714. var ambientTexture = babylonPBRMaterial.ambientTexture || babylonPBRMaterial.occlusionTexture;
  4715. if (ambientTexture) {
  4716. var promise = this._exportTextureAsync(ambientTexture, mimeType).then(function (glTFTexture) {
  4717. if (glTFTexture) {
  4718. var occlusionTexture = {
  4719. index: glTFTexture.index,
  4720. texCoord: glTFTexture.texCoord
  4721. };
  4722. glTFMaterial.occlusionTexture = occlusionTexture;
  4723. var ambientTextureStrength = babylonPBRMaterial.ambientTextureStrength || babylonPBRMaterial.occlusionStrength;
  4724. if (ambientTextureStrength) {
  4725. occlusionTexture.strength = ambientTextureStrength;
  4726. }
  4727. }
  4728. });
  4729. promises.push(promise);
  4730. }
  4731. var emissiveTexture = babylonPBRMaterial.emissiveTexture || babylonPBRMaterial.emissiveTexture;
  4732. if (emissiveTexture) {
  4733. var promise = this._exportTextureAsync(emissiveTexture, mimeType).then(function (glTFTexture) {
  4734. if (glTFTexture) {
  4735. glTFMaterial.emissiveTexture = glTFTexture;
  4736. }
  4737. });
  4738. promises.push(promise);
  4739. }
  4740. }
  4741. var emissiveColor = babylonPBRMaterial.emissiveColor || babylonPBRMaterial.emissiveColor;
  4742. if (!_GLTFMaterialExporter.FuzzyEquals(emissiveColor, babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  4743. glTFMaterial.emissiveFactor = emissiveColor.asArray();
  4744. }
  4745. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  4746. materials.push(glTFMaterial);
  4747. materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;
  4748. }
  4749. return this._finishMaterial(promises, glTFMaterial, babylonPBRMaterial, mimeType);
  4750. };
  4751. _GLTFMaterialExporter.prototype.getPixelsFromTexture = function (babylonTexture) {
  4752. var pixels = babylonTexture.textureType === babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Constants"].TEXTURETYPE_UNSIGNED_INT ? babylonTexture.readPixels() : babylonTexture.readPixels();
  4753. return pixels;
  4754. };
  4755. /**
  4756. * Extracts a texture from a Babylon texture into file data and glTF data
  4757. * @param babylonTexture Babylon texture to extract
  4758. * @param mimeType Mime Type of the babylonTexture
  4759. * @return glTF texture info, or null if the texture format is not supported
  4760. */
  4761. _GLTFMaterialExporter.prototype._exportTextureAsync = function (babylonTexture, mimeType) {
  4762. var _this = this;
  4763. var extensionPromise = this._exporter._extensionsPreExportTextureAsync("exporter", babylonTexture, mimeType);
  4764. if (!extensionPromise) {
  4765. return this._exportTextureInfoAsync(babylonTexture, mimeType);
  4766. }
  4767. return extensionPromise.then(function (texture) {
  4768. if (!texture) {
  4769. return _this._exportTextureInfoAsync(babylonTexture, mimeType);
  4770. }
  4771. return _this._exportTextureInfoAsync(texture, mimeType);
  4772. });
  4773. };
  4774. _GLTFMaterialExporter.prototype._exportTextureInfoAsync = function (babylonTexture, mimeType) {
  4775. var _this = this;
  4776. return Promise.resolve().then(function () { return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__awaiter"])(_this, void 0, void 0, function () {
  4777. var textureUid, pixels, samplers, sampler, samplerIndex_1, foundSamplerIndex, i, s, size;
  4778. var _this = this;
  4779. return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__generator"])(this, function (_a) {
  4780. switch (_a.label) {
  4781. case 0:
  4782. textureUid = babylonTexture.uid;
  4783. if (!(textureUid in this._textureMap)) return [3 /*break*/, 1];
  4784. return [2 /*return*/, this._textureMap[textureUid]];
  4785. case 1: return [4 /*yield*/, this.getPixelsFromTexture(babylonTexture)];
  4786. case 2:
  4787. pixels = _a.sent();
  4788. if (!pixels) {
  4789. return [2 /*return*/, null];
  4790. }
  4791. samplers = this._exporter._samplers;
  4792. sampler = this._getGLTFTextureSampler(babylonTexture);
  4793. samplerIndex_1 = null;
  4794. foundSamplerIndex = null;
  4795. for (i = 0; i < samplers.length; ++i) {
  4796. s = samplers[i];
  4797. if (s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter &&
  4798. s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT) {
  4799. foundSamplerIndex = i;
  4800. break;
  4801. }
  4802. }
  4803. if (foundSamplerIndex == null) {
  4804. samplers.push(sampler);
  4805. samplerIndex_1 = samplers.length - 1;
  4806. }
  4807. else {
  4808. samplerIndex_1 = foundSamplerIndex;
  4809. }
  4810. size = babylonTexture.getSize();
  4811. // Preserve texture mime type if defined
  4812. if (babylonTexture.mimeType) {
  4813. switch (babylonTexture.mimeType) {
  4814. case "image/jpeg":
  4815. mimeType = "image/jpeg" /* JPEG */;
  4816. break;
  4817. case "image/png":
  4818. mimeType = "image/png" /* PNG */;
  4819. break;
  4820. }
  4821. }
  4822. return [2 /*return*/, this._createBase64FromCanvasAsync(pixels, size.width, size.height, mimeType).then(function (base64Data) {
  4823. var textureInfo = _this._getTextureInfoFromBase64(base64Data, babylonTexture.name.replace(/\.\/|\/|\.\\|\\/g, "_"), mimeType, babylonTexture.coordinatesIndex, samplerIndex_1);
  4824. if (textureInfo) {
  4825. _this._textureMap[textureUid] = textureInfo;
  4826. _this._exporter._extensionsPostExportTextures("linkTextureInfo", textureInfo, babylonTexture);
  4827. }
  4828. return textureInfo;
  4829. })];
  4830. }
  4831. });
  4832. }); });
  4833. };
  4834. /**
  4835. * Builds a texture from base64 string
  4836. * @param base64Texture base64 texture string
  4837. * @param baseTextureName Name to use for the texture
  4838. * @param mimeType image mime type for the texture
  4839. * @param images array of images
  4840. * @param textures array of textures
  4841. * @param imageData map of image data
  4842. * @returns glTF texture info, or null if the texture format is not supported
  4843. */
  4844. _GLTFMaterialExporter.prototype._getTextureInfoFromBase64 = function (base64Texture, baseTextureName, mimeType, texCoordIndex, samplerIndex) {
  4845. var textures = this._exporter._textures;
  4846. var images = this._exporter._images;
  4847. var imageData = this._exporter._imageData;
  4848. var textureInfo = null;
  4849. var glTFTexture = {
  4850. source: images.length,
  4851. name: baseTextureName
  4852. };
  4853. if (samplerIndex != null) {
  4854. glTFTexture.sampler = samplerIndex;
  4855. }
  4856. var binStr = atob(base64Texture.split(',')[1]);
  4857. var arrBuff = new ArrayBuffer(binStr.length);
  4858. var arr = new Uint8Array(arrBuff);
  4859. for (var i = 0, length_2 = binStr.length; i < length_2; ++i) {
  4860. arr[i] = binStr.charCodeAt(i);
  4861. }
  4862. var imageValues = { data: arr, mimeType: mimeType };
  4863. var extension = mimeType === "image/jpeg" /* JPEG */ ? '.jpeg' : '.png';
  4864. var textureName = baseTextureName + extension;
  4865. var originalTextureName = textureName;
  4866. if (textureName in imageData) {
  4867. textureName = baseTextureName + "_" + babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].RandomId() + extension;
  4868. }
  4869. imageData[textureName] = imageValues;
  4870. if (mimeType === "image/jpeg" /* JPEG */ || mimeType === "image/png" /* PNG */) {
  4871. var glTFImage = {
  4872. name: baseTextureName,
  4873. uri: textureName
  4874. };
  4875. var foundIndex = null;
  4876. for (var i = 0; i < images.length; ++i) {
  4877. if (images[i].uri === originalTextureName) {
  4878. foundIndex = i;
  4879. break;
  4880. }
  4881. }
  4882. if (foundIndex == null) {
  4883. images.push(glTFImage);
  4884. glTFTexture.source = images.length - 1;
  4885. }
  4886. else {
  4887. glTFTexture.source = foundIndex;
  4888. }
  4889. textures.push(glTFTexture);
  4890. textureInfo = {
  4891. index: textures.length - 1
  4892. };
  4893. if (texCoordIndex != null) {
  4894. textureInfo.texCoord = texCoordIndex;
  4895. }
  4896. }
  4897. else {
  4898. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Tools"].Error("Unsupported texture mime type " + mimeType);
  4899. }
  4900. return textureInfo;
  4901. };
  4902. /**
  4903. * Represents the dielectric specular values for R, G and B
  4904. */
  4905. _GLTFMaterialExporter._DielectricSpecular = new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.04, 0.04, 0.04);
  4906. /**
  4907. * Allows the maximum specular power to be defined for material calculations
  4908. */
  4909. _GLTFMaterialExporter._MaxSpecularPower = 1024;
  4910. /**
  4911. * Numeric tolerance value
  4912. */
  4913. _GLTFMaterialExporter._Epsilon = 1e-6;
  4914. return _GLTFMaterialExporter;
  4915. }());
  4916. /***/ }),
  4917. /***/ "./glTF/2.0/glTFSerializer.ts":
  4918. /*!************************************!*\
  4919. !*** ./glTF/2.0/glTFSerializer.ts ***!
  4920. \************************************/
  4921. /*! exports provided: GLTF2Export */
  4922. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4923. "use strict";
  4924. __webpack_require__.r(__webpack_exports__);
  4925. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return GLTF2Export; });
  4926. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  4927. /**
  4928. * Class for generating glTF data from a Babylon scene.
  4929. */
  4930. var GLTF2Export = /** @class */ (function () {
  4931. function GLTF2Export() {
  4932. }
  4933. /**
  4934. * Exports the geometry of the scene to .gltf file format asynchronously
  4935. * @param scene Babylon scene with scene hierarchy information
  4936. * @param filePrefix File prefix to use when generating the glTF file
  4937. * @param options Exporter options
  4938. * @returns Returns an object with a .gltf file and associates texture names
  4939. * as keys and their data and paths as values
  4940. */
  4941. GLTF2Export.GLTFAsync = function (scene, filePrefix, options) {
  4942. return scene.whenReadyAsync().then(function () {
  4943. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  4944. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  4945. return gltfGenerator._generateGLTFAsync(glTFPrefix);
  4946. });
  4947. };
  4948. GLTF2Export._PreExportAsync = function (scene, options) {
  4949. return Promise.resolve().then(function () {
  4950. if (options && options.exportWithoutWaitingForScene) {
  4951. return Promise.resolve();
  4952. }
  4953. else {
  4954. return scene.whenReadyAsync();
  4955. }
  4956. });
  4957. };
  4958. GLTF2Export._PostExportAsync = function (scene, glTFData, options) {
  4959. return Promise.resolve().then(function () {
  4960. if (options && options.exportWithoutWaitingForScene) {
  4961. return glTFData;
  4962. }
  4963. else {
  4964. return glTFData;
  4965. }
  4966. });
  4967. };
  4968. /**
  4969. * Exports the geometry of the scene to .glb file format asychronously
  4970. * @param scene Babylon scene with scene hierarchy information
  4971. * @param filePrefix File prefix to use when generating glb file
  4972. * @param options Exporter options
  4973. * @returns Returns an object with a .glb filename as key and data as value
  4974. */
  4975. GLTF2Export.GLBAsync = function (scene, filePrefix, options) {
  4976. var _this = this;
  4977. return this._PreExportAsync(scene, options).then(function () {
  4978. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  4979. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  4980. return gltfGenerator._generateGLBAsync(glTFPrefix).then(function (glTFData) {
  4981. return _this._PostExportAsync(scene, glTFData, options);
  4982. });
  4983. });
  4984. };
  4985. return GLTF2Export;
  4986. }());
  4987. /***/ }),
  4988. /***/ "./glTF/2.0/glTFUtilities.ts":
  4989. /*!***********************************!*\
  4990. !*** ./glTF/2.0/glTFUtilities.ts ***!
  4991. \***********************************/
  4992. /*! exports provided: _GLTFUtilities */
  4993. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4994. "use strict";
  4995. __webpack_require__.r(__webpack_exports__);
  4996. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _GLTFUtilities; });
  4997. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math.vector */ "babylonjs/Maths/math.vector");
  4998. /* harmony import */ var babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__);
  4999. /**
  5000. * @hidden
  5001. */
  5002. var _GLTFUtilities = /** @class */ (function () {
  5003. function _GLTFUtilities() {
  5004. }
  5005. /**
  5006. * Creates a buffer view based on the supplied arguments
  5007. * @param bufferIndex index value of the specified buffer
  5008. * @param byteOffset byte offset value
  5009. * @param byteLength byte length of the bufferView
  5010. * @param byteStride byte distance between conequential elements
  5011. * @param name name of the buffer view
  5012. * @returns bufferView for glTF
  5013. */
  5014. _GLTFUtilities._CreateBufferView = function (bufferIndex, byteOffset, byteLength, byteStride, name) {
  5015. var bufferview = { buffer: bufferIndex, byteLength: byteLength };
  5016. if (byteOffset) {
  5017. bufferview.byteOffset = byteOffset;
  5018. }
  5019. if (name) {
  5020. bufferview.name = name;
  5021. }
  5022. if (byteStride) {
  5023. bufferview.byteStride = byteStride;
  5024. }
  5025. return bufferview;
  5026. };
  5027. /**
  5028. * Creates an accessor based on the supplied arguments
  5029. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  5030. * @param name The name of the accessor
  5031. * @param type The type of the accessor
  5032. * @param componentType The datatype of components in the attribute
  5033. * @param count The number of attributes referenced by this accessor
  5034. * @param byteOffset The offset relative to the start of the bufferView in bytes
  5035. * @param min Minimum value of each component in this attribute
  5036. * @param max Maximum value of each component in this attribute
  5037. * @returns accessor for glTF
  5038. */
  5039. _GLTFUtilities._CreateAccessor = function (bufferviewIndex, name, type, componentType, count, byteOffset, min, max) {
  5040. var accessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };
  5041. if (min != null) {
  5042. accessor.min = min;
  5043. }
  5044. if (max != null) {
  5045. accessor.max = max;
  5046. }
  5047. if (byteOffset != null) {
  5048. accessor.byteOffset = byteOffset;
  5049. }
  5050. return accessor;
  5051. };
  5052. /**
  5053. * Calculates the minimum and maximum values of an array of position floats
  5054. * @param positions Positions array of a mesh
  5055. * @param vertexStart Starting vertex offset to calculate min and max values
  5056. * @param vertexCount Number of vertices to check for min and max values
  5057. * @returns min number array and max number array
  5058. */
  5059. _GLTFUtilities._CalculateMinMaxPositions = function (positions, vertexStart, vertexCount, convertToRightHandedSystem) {
  5060. var min = [Infinity, Infinity, Infinity];
  5061. var max = [-Infinity, -Infinity, -Infinity];
  5062. var positionStrideSize = 3;
  5063. var indexOffset;
  5064. var position;
  5065. var vector;
  5066. if (vertexCount) {
  5067. for (var i = vertexStart, length_1 = vertexStart + vertexCount; i < length_1; ++i) {
  5068. indexOffset = positionStrideSize * i;
  5069. position = babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(positions, indexOffset);
  5070. if (convertToRightHandedSystem) {
  5071. _GLTFUtilities._GetRightHandedPositionVector3FromRef(position);
  5072. }
  5073. vector = position.asArray();
  5074. for (var j = 0; j < positionStrideSize; ++j) {
  5075. var num = vector[j];
  5076. if (num < min[j]) {
  5077. min[j] = num;
  5078. }
  5079. if (num > max[j]) {
  5080. max[j] = num;
  5081. }
  5082. ++indexOffset;
  5083. }
  5084. }
  5085. }
  5086. return { min: min, max: max };
  5087. };
  5088. /**
  5089. * Converts a new right-handed Vector3
  5090. * @param vector vector3 array
  5091. * @returns right-handed Vector3
  5092. */
  5093. _GLTFUtilities._GetRightHandedPositionVector3 = function (vector) {
  5094. return new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  5095. };
  5096. /**
  5097. * Converts a Vector3 to right-handed
  5098. * @param vector Vector3 to convert to right-handed
  5099. */
  5100. _GLTFUtilities._GetRightHandedPositionVector3FromRef = function (vector) {
  5101. vector.z *= -1;
  5102. };
  5103. /**
  5104. * Converts a three element number array to right-handed
  5105. * @param vector number array to convert to right-handed
  5106. */
  5107. _GLTFUtilities._GetRightHandedPositionArray3FromRef = function (vector) {
  5108. vector[2] *= -1;
  5109. };
  5110. /**
  5111. * Converts a new right-handed Vector3
  5112. * @param vector vector3 array
  5113. * @returns right-handed Vector3
  5114. */
  5115. _GLTFUtilities._GetRightHandedNormalVector3 = function (vector) {
  5116. return new babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  5117. };
  5118. /**
  5119. * Converts a Vector3 to right-handed
  5120. * @param vector Vector3 to convert to right-handed
  5121. */
  5122. _GLTFUtilities._GetRightHandedNormalVector3FromRef = function (vector) {
  5123. vector.z *= -1;
  5124. };
  5125. /**
  5126. * Converts a three element number array to right-handed
  5127. * @param vector number array to convert to right-handed
  5128. */
  5129. _GLTFUtilities._GetRightHandedNormalArray3FromRef = function (vector) {
  5130. vector[2] *= -1;
  5131. };
  5132. /**
  5133. * Converts a Vector4 to right-handed
  5134. * @param vector Vector4 to convert to right-handed
  5135. */
  5136. _GLTFUtilities._GetRightHandedVector4FromRef = function (vector) {
  5137. vector.z *= -1;
  5138. vector.w *= -1;
  5139. };
  5140. /**
  5141. * Converts a Vector4 to right-handed
  5142. * @param vector Vector4 to convert to right-handed
  5143. */
  5144. _GLTFUtilities._GetRightHandedArray4FromRef = function (vector) {
  5145. vector[2] *= -1;
  5146. vector[3] *= -1;
  5147. };
  5148. /**
  5149. * Converts a Quaternion to right-handed
  5150. * @param quaternion Source quaternion to convert to right-handed
  5151. */
  5152. _GLTFUtilities._GetRightHandedQuaternionFromRef = function (quaternion) {
  5153. quaternion.x *= -1;
  5154. quaternion.y *= -1;
  5155. };
  5156. /**
  5157. * Converts a Quaternion to right-handed
  5158. * @param quaternion Source quaternion to convert to right-handed
  5159. */
  5160. _GLTFUtilities._GetRightHandedQuaternionArrayFromRef = function (quaternion) {
  5161. quaternion[0] *= -1;
  5162. quaternion[1] *= -1;
  5163. };
  5164. _GLTFUtilities._NormalizeTangentFromRef = function (tangent) {
  5165. var length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);
  5166. if (length > 0) {
  5167. tangent.x /= length;
  5168. tangent.y /= length;
  5169. tangent.z /= length;
  5170. }
  5171. };
  5172. _GLTFUtilities._GetRightHandedMatrixFromRef = function (matrix) {
  5173. var m = matrix.m;
  5174. babylonjs_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Matrix"].FromValuesToRef(m[0], m[1], -m[2], m[3], m[4], m[5], -m[6], m[7], -m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15], matrix);
  5175. };
  5176. _GLTFUtilities._GetDataAccessorElementCount = function (accessorType) {
  5177. switch (accessorType) {
  5178. case "MAT2" /* MAT2 */:
  5179. return 4;
  5180. case "MAT3" /* MAT3 */:
  5181. return 9;
  5182. case "MAT4" /* MAT4 */:
  5183. return 16;
  5184. case "SCALAR" /* SCALAR */:
  5185. return 1;
  5186. case "VEC2" /* VEC2 */:
  5187. return 2;
  5188. case "VEC3" /* VEC3 */:
  5189. return 3;
  5190. case "VEC4" /* VEC4 */:
  5191. return 4;
  5192. }
  5193. };
  5194. return _GLTFUtilities;
  5195. }());
  5196. /***/ }),
  5197. /***/ "./glTF/2.0/index.ts":
  5198. /*!***************************!*\
  5199. !*** ./glTF/2.0/index.ts ***!
  5200. \***************************/
  5201. /*! exports provided: _GLTFAnimation, GLTFData, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, GLTF2Export, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen, KHR_materials_unlit */
  5202. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5203. "use strict";
  5204. __webpack_require__.r(__webpack_exports__);
  5205. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  5206. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__["_GLTFAnimation"]; });
  5207. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  5208. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTFData__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  5209. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  5210. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_Exporter"]; });
  5211. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_BinaryWriter"]; });
  5212. /* harmony import */ var _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFExporterExtension */ "./glTF/2.0/glTFExporterExtension.ts");
  5213. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__["__IGLTFExporterExtensionV2"]; });
  5214. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  5215. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  5216. /* harmony import */ var _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  5217. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__["GLTF2Export"]; });
  5218. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  5219. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__["_GLTFUtilities"]; });
  5220. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  5221. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_texture_transform"]; });
  5222. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_lights_punctual"]; });
  5223. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_sheen"]; });
  5224. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_materials_unlit"]; });
  5225. /***/ }),
  5226. /***/ "./glTF/2.0/shaders/textureTransform.fragment.ts":
  5227. /*!*******************************************************!*\
  5228. !*** ./glTF/2.0/shaders/textureTransform.fragment.ts ***!
  5229. \*******************************************************/
  5230. /*! exports provided: textureTransformPixelShader */
  5231. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5232. "use strict";
  5233. __webpack_require__.r(__webpack_exports__);
  5234. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textureTransformPixelShader", function() { return textureTransformPixelShader; });
  5235. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Maths/math.vector");
  5236. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  5237. var name = 'textureTransformPixelShader';
  5238. 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}";
  5239. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  5240. /** @hidden */
  5241. var textureTransformPixelShader = { name: name, shader: shader };
  5242. /***/ }),
  5243. /***/ "./glTF/glTFFileExporter.ts":
  5244. /*!**********************************!*\
  5245. !*** ./glTF/glTFFileExporter.ts ***!
  5246. \**********************************/
  5247. /*! exports provided: __IGLTFExporterExtension */
  5248. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5249. "use strict";
  5250. __webpack_require__.r(__webpack_exports__);
  5251. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return __IGLTFExporterExtension; });
  5252. /** @hidden */
  5253. var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
  5254. /***/ }),
  5255. /***/ "./glTF/index.ts":
  5256. /*!***********************!*\
  5257. !*** ./glTF/index.ts ***!
  5258. \***********************/
  5259. /*! exports provided: __IGLTFExporterExtension, _GLTFAnimation, GLTFData, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, GLTF2Export, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen, KHR_materials_unlit */
  5260. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5261. "use strict";
  5262. __webpack_require__.r(__webpack_exports__);
  5263. /* harmony import */ var _glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileExporter */ "./glTF/glTFFileExporter.ts");
  5264. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__["__IGLTFExporterExtension"]; });
  5265. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  5266. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_GLTFAnimation"]; });
  5267. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  5268. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_Exporter"]; });
  5269. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_BinaryWriter"]; });
  5270. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtensionV2"]; });
  5271. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"]; });
  5272. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["GLTF2Export"]; });
  5273. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]; });
  5274. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  5275. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  5276. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  5277. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  5278. /***/ }),
  5279. /***/ "./index.ts":
  5280. /*!******************!*\
  5281. !*** ./index.ts ***!
  5282. \******************/
  5283. /*! exports provided: OBJExport, __IGLTFExporterExtension, _GLTFAnimation, GLTFData, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, GLTF2Export, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen, KHR_materials_unlit, STLExport */
  5284. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5285. "use strict";
  5286. __webpack_require__.r(__webpack_exports__);
  5287. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  5288. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJExport"]; });
  5289. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  5290. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtension"]; });
  5291. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_GLTFAnimation"]; });
  5292. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  5293. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_Exporter"]; });
  5294. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_BinaryWriter"]; });
  5295. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtensionV2"]; });
  5296. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"]; });
  5297. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["GLTF2Export"]; });
  5298. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]; });
  5299. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  5300. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  5301. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  5302. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  5303. /* harmony import */ var _stl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./stl */ "./stl/index.ts");
  5304. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _stl__WEBPACK_IMPORTED_MODULE_2__["STLExport"]; });
  5305. /***/ }),
  5306. /***/ "./legacy/legacy-glTF2Serializer.ts":
  5307. /*!******************************************!*\
  5308. !*** ./legacy/legacy-glTF2Serializer.ts ***!
  5309. \******************************************/
  5310. /*! exports provided: __IGLTFExporterExtension, _GLTFAnimation, GLTFData, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, GLTF2Export, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen, KHR_materials_unlit */
  5311. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5312. "use strict";
  5313. __webpack_require__.r(__webpack_exports__);
  5314. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileExporter */ "./glTF/glTFFileExporter.ts");
  5315. /* harmony import */ var _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFData */ "./glTF/2.0/glTFData.ts");
  5316. /* harmony import */ var _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0/glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  5317. /* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  5318. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  5319. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__["__IGLTFExporterExtension"]; });
  5320. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]; });
  5321. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]; });
  5322. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_Exporter"]; });
  5323. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_BinaryWriter"]; });
  5324. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["__IGLTFExporterExtensionV2"]; });
  5325. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  5326. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTF2Export"]; });
  5327. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFUtilities"]; });
  5328. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_texture_transform"]; });
  5329. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_lights_punctual"]; });
  5330. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_sheen"]; });
  5331. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_materials_unlit"]; });
  5332. /**
  5333. * This is the entry point for the UMD module.
  5334. * The entry point for a future ESM package should be index.ts
  5335. */
  5336. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5337. if (typeof globalObject !== "undefined") {
  5338. globalObject.BABYLON = globalObject.BABYLON || {};
  5339. var BABYLON = globalObject.BABYLON;
  5340. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  5341. BABYLON.GLTF2.Exporter = BABYLON.GLTF2.Exporter || {};
  5342. BABYLON.GLTF2.Exporter.Extensions = BABYLON.GLTF2.Exporter.Extensions || {};
  5343. var keys = [];
  5344. for (var key in _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__) {
  5345. BABYLON[key] = _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__[key];
  5346. keys.push(key);
  5347. }
  5348. for (var key in _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__) {
  5349. BABYLON[key] = _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__[key];
  5350. keys.push(key);
  5351. }
  5352. for (var key in _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__) {
  5353. BABYLON[key] = _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__[key];
  5354. keys.push(key);
  5355. }
  5356. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__) {
  5357. BABYLON.GLTF2.Exporter.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__[key];
  5358. keys.push(key);
  5359. }
  5360. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__) {
  5361. // Prevent Reassignment.
  5362. if (keys.indexOf(key) > -1) {
  5363. continue;
  5364. }
  5365. BABYLON.GLTF2.Exporter[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__[key];
  5366. }
  5367. }
  5368. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5369. /***/ }),
  5370. /***/ "./legacy/legacy-objSerializer.ts":
  5371. /*!****************************************!*\
  5372. !*** ./legacy/legacy-objSerializer.ts ***!
  5373. \****************************************/
  5374. /*! exports provided: OBJExport */
  5375. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5376. "use strict";
  5377. __webpack_require__.r(__webpack_exports__);
  5378. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  5379. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJExport"]; });
  5380. /**
  5381. * This is the entry point for the UMD module.
  5382. * The entry point for a future ESM package should be index.ts
  5383. */
  5384. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5385. if (typeof globalObject !== "undefined") {
  5386. for (var serializer in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  5387. globalObject.BABYLON[serializer] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[serializer];
  5388. }
  5389. }
  5390. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5391. /***/ }),
  5392. /***/ "./legacy/legacy-stlSerializer.ts":
  5393. /*!****************************************!*\
  5394. !*** ./legacy/legacy-stlSerializer.ts ***!
  5395. \****************************************/
  5396. /*! exports provided: STLExport */
  5397. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5398. "use strict";
  5399. __webpack_require__.r(__webpack_exports__);
  5400. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _stl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../stl */ "./stl/index.ts");
  5401. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _stl__WEBPACK_IMPORTED_MODULE_0__["STLExport"]; });
  5402. /**
  5403. * This is the entry point for the UMD module.
  5404. * The entry point for a future ESM package should be index.ts
  5405. */
  5406. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  5407. if (typeof globalObject !== "undefined") {
  5408. for (var serializer in _stl__WEBPACK_IMPORTED_MODULE_0__) {
  5409. globalObject.BABYLON[serializer] = _stl__WEBPACK_IMPORTED_MODULE_0__[serializer];
  5410. }
  5411. }
  5412. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  5413. /***/ }),
  5414. /***/ "./legacy/legacy.ts":
  5415. /*!**************************!*\
  5416. !*** ./legacy/legacy.ts ***!
  5417. \**************************/
  5418. /*! exports provided: __IGLTFExporterExtension, _GLTFAnimation, GLTFData, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, GLTF2Export, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual, KHR_materials_sheen, KHR_materials_unlit, OBJExport, STLExport */
  5419. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5420. "use strict";
  5421. __webpack_require__.r(__webpack_exports__);
  5422. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  5423. /* harmony import */ var _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2Serializer */ "./legacy/legacy-glTF2Serializer.ts");
  5424. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtension"]; });
  5425. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_GLTFAnimation"]; });
  5426. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  5427. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_Exporter"]; });
  5428. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_BinaryWriter"]; });
  5429. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtensionV2"]; });
  5430. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"]; });
  5431. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["GLTF2Export"]; });
  5432. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]; });
  5433. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  5434. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  5435. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_sheen", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_sheen"]; });
  5436. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_materials_unlit", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_materials_unlit"]; });
  5437. /* harmony import */ var _legacy_objSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-objSerializer */ "./legacy/legacy-objSerializer.ts");
  5438. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _legacy_objSerializer__WEBPACK_IMPORTED_MODULE_2__["OBJExport"]; });
  5439. /* harmony import */ var _legacy_stlSerializer__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-stlSerializer */ "./legacy/legacy-stlSerializer.ts");
  5440. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _legacy_stlSerializer__WEBPACK_IMPORTED_MODULE_3__["STLExport"]; });
  5441. /***/ }),
  5442. /***/ "./stl/index.ts":
  5443. /*!**********************!*\
  5444. !*** ./stl/index.ts ***!
  5445. \**********************/
  5446. /*! exports provided: STLExport */
  5447. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5448. "use strict";
  5449. __webpack_require__.r(__webpack_exports__);
  5450. /* harmony import */ var _stlSerializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlSerializer */ "./stl/stlSerializer.ts");
  5451. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _stlSerializer__WEBPACK_IMPORTED_MODULE_0__["STLExport"]; });
  5452. /***/ }),
  5453. /***/ "./stl/stlSerializer.ts":
  5454. /*!******************************!*\
  5455. !*** ./stl/stlSerializer.ts ***!
  5456. \******************************/
  5457. /*! exports provided: STLExport */
  5458. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5459. "use strict";
  5460. __webpack_require__.r(__webpack_exports__);
  5461. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return STLExport; });
  5462. /* harmony import */ var babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/buffer */ "babylonjs/Maths/math.vector");
  5463. /* harmony import */ var babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__);
  5464. /**
  5465. * Class for generating STL data from a Babylon scene.
  5466. */
  5467. var STLExport = /** @class */ (function () {
  5468. function STLExport() {
  5469. }
  5470. /**
  5471. * Exports the geometry of a Mesh array in .STL file format (ASCII)
  5472. * @param meshes list defines the mesh to serialize
  5473. * @param download triggers the automatic download of the file.
  5474. * @param fileName changes the downloads fileName.
  5475. * @param binary changes the STL to a binary type.
  5476. * @param isLittleEndian toggle for binary type exporter.
  5477. * @param doNotBakeTransform toggle if meshes transforms should be baked or not.
  5478. * @returns the STL as UTF8 string
  5479. */
  5480. STLExport.CreateSTL = function (meshes, download, fileName, binary, isLittleEndian, doNotBakeTransform) {
  5481. //Binary support adapted from https://gist.github.com/paulkaplan/6d5f0ab2c7e8fdc68a61
  5482. if (download === void 0) { download = true; }
  5483. if (fileName === void 0) { fileName = 'stlmesh'; }
  5484. if (binary === void 0) { binary = false; }
  5485. if (isLittleEndian === void 0) { isLittleEndian = true; }
  5486. if (doNotBakeTransform === void 0) { doNotBakeTransform = false; }
  5487. var getFaceData = function (indices, vertices, i) {
  5488. var id = [indices[i] * 3, indices[i + 1] * 3, indices[i + 2] * 3];
  5489. var v = [
  5490. new babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vertices[id[0]], vertices[id[0] + 2], vertices[id[0] + 1]),
  5491. new babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vertices[id[1]], vertices[id[1] + 2], vertices[id[1] + 1]),
  5492. new babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vertices[id[2]], vertices[id[2] + 2], vertices[id[2] + 1])
  5493. ];
  5494. var p1p2 = v[0].subtract(v[1]);
  5495. var p3p2 = v[2].subtract(v[1]);
  5496. var n = (babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Cross(p3p2, p1p2)).normalize();
  5497. return { v: v, n: n };
  5498. };
  5499. var writeVector = function (dataview, offset, vector, isLittleEndian) {
  5500. offset = writeFloat(dataview, offset, vector.x, isLittleEndian);
  5501. offset = writeFloat(dataview, offset, vector.y, isLittleEndian);
  5502. return writeFloat(dataview, offset, vector.z, isLittleEndian);
  5503. };
  5504. var writeFloat = function (dataview, offset, value, isLittleEndian) {
  5505. dataview.setFloat32(offset, value, isLittleEndian);
  5506. return offset + 4;
  5507. };
  5508. var data;
  5509. var faceCount = 0;
  5510. var offset = 0;
  5511. if (binary) {
  5512. for (var i = 0; i < meshes.length; i++) {
  5513. var mesh = meshes[i];
  5514. var indices = mesh.getIndices();
  5515. faceCount += indices ? indices.length / 3 : 0;
  5516. }
  5517. var bufferSize = 84 + (50 * faceCount);
  5518. var buffer = new ArrayBuffer(bufferSize);
  5519. data = new DataView(buffer);
  5520. offset += 80;
  5521. data.setUint32(offset, faceCount, isLittleEndian);
  5522. offset += 4;
  5523. }
  5524. else {
  5525. data = 'solid stlmesh\r\n';
  5526. }
  5527. for (var i = 0; i < meshes.length; i++) {
  5528. var mesh = meshes[i];
  5529. if (!doNotBakeTransform) {
  5530. mesh.bakeCurrentTransformIntoVertices();
  5531. }
  5532. var vertices = mesh.getVerticesData(babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind) || [];
  5533. var indices = mesh.getIndices() || [];
  5534. for (var i_1 = 0; i_1 < indices.length; i_1 += 3) {
  5535. var fd = getFaceData(indices, vertices, i_1);
  5536. if (binary) {
  5537. offset = writeVector(data, offset, fd.n, isLittleEndian);
  5538. offset = writeVector(data, offset, fd.v[0], isLittleEndian);
  5539. offset = writeVector(data, offset, fd.v[1], isLittleEndian);
  5540. offset = writeVector(data, offset, fd.v[2], isLittleEndian);
  5541. offset += 2;
  5542. }
  5543. else {
  5544. data += 'facet normal ' + fd.n.x + ' ' + fd.n.y + ' ' + fd.n.z + '\r\n';
  5545. data += '\touter loop\r\n';
  5546. data += '\t\tvertex ' + fd.v[0].x + ' ' + fd.v[0].y + ' ' + fd.v[0].z + '\r\n';
  5547. data += '\t\tvertex ' + fd.v[1].x + ' ' + fd.v[1].y + ' ' + fd.v[1].z + '\r\n';
  5548. data += '\t\tvertex ' + fd.v[2].x + ' ' + fd.v[2].y + ' ' + fd.v[2].z + '\r\n';
  5549. data += '\tendloop\r\n';
  5550. data += 'endfacet\r\n';
  5551. }
  5552. }
  5553. }
  5554. if (!binary) {
  5555. data += 'endsolid stlmesh';
  5556. }
  5557. if (download) {
  5558. var a = document.createElement('a');
  5559. var blob = new Blob([data], { 'type': 'application/octet-stream' });
  5560. a.href = window.URL.createObjectURL(blob);
  5561. a.download = fileName + ".stl";
  5562. a.click();
  5563. }
  5564. return data;
  5565. };
  5566. return STLExport;
  5567. }());
  5568. /***/ }),
  5569. /***/ "babylonjs/Maths/math.vector":
  5570. /*!****************************************************************************************************!*\
  5571. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  5572. \****************************************************************************************************/
  5573. /*! no static exports found */
  5574. /***/ (function(module, exports) {
  5575. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math_vector__;
  5576. /***/ })
  5577. /******/ });
  5578. });
  5579. //# sourceMappingURL=babylonjs.serializers.js.map