babylonjs.serializers.js 323 KB

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