babylonjs.serializers.js 322 KB

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