babylonjs.serializers.js 298 KB

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