babylon.glTF2Serializer.js 231 KB

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