babylonjs.serializers.js 257 KB

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