babylon.glTF2Serializer.js 270 KB

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