babylon.glTF2Serializer.js 255 KB

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