babylonjs.serializers.js 244 KB

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