babylon.glTF2Serializer.js 241 KB

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