babylon.glTF2Serializer.js 299 KB

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