babylonjs.serializers.js 247 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660
  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_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  448. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__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 texture_transform_extension = {};
  472. if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {
  473. texture_transform_extension.offset = [babylonTexture.uOffset, babylonTexture.vOffset];
  474. }
  475. if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
  476. texture_transform_extension.scale = [babylonTexture.uScale, babylonTexture.vScale];
  477. }
  478. if (babylonTexture.wAng !== 0) {
  479. texture_transform_extension.rotation = babylonTexture.wAng;
  480. }
  481. if (!Object.keys(texture_transform_extension).length) {
  482. resolve(babylonTexture);
  483. }
  484. var scale = texture_transform_extension.scale ? new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](texture_transform_extension.scale[0], texture_transform_extension.scale[1]) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].One();
  485. var rotation = texture_transform_extension.rotation != null ? texture_transform_extension.rotation : 0;
  486. var offset = texture_transform_extension.offset ? new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](texture_transform_extension.offset[0], texture_transform_extension.offset[1]) : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].Zero();
  487. var scene = babylonTexture.getScene();
  488. if (!scene) {
  489. reject(context + ": \"scene\" is not defined for Babylon texture " + babylonTexture.name + "!");
  490. }
  491. else {
  492. _this.textureTransformTextureAsync(babylonTexture, offset, rotation, scale, scene).then(function (texture) {
  493. resolve(texture);
  494. });
  495. }
  496. });
  497. };
  498. /**
  499. * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
  500. * @param babylonTexture
  501. * @param offset
  502. * @param rotation
  503. * @param scale
  504. * @param scene
  505. */
  506. KHR_texture_transform.prototype.textureTransformTextureAsync = function (babylonTexture, offset, rotation, scale, scene) {
  507. return new Promise(function (resolve, reject) {
  508. var proceduralTexture = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["ProceduralTexture"]("" + babylonTexture.name, babylonTexture.getSize(), "textureTransform", scene);
  509. if (!proceduralTexture) {
  510. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Cannot create procedural texture for " + babylonTexture.name + "!");
  511. resolve(babylonTexture);
  512. }
  513. proceduralTexture.setTexture("textureSampler", babylonTexture);
  514. proceduralTexture.setMatrix("textureTransformMat", babylonTexture.getTextureMatrix());
  515. // isReady trigger creation of effect if it doesnt exist yet
  516. if (proceduralTexture.isReady()) {
  517. proceduralTexture.render();
  518. resolve(proceduralTexture);
  519. }
  520. else {
  521. proceduralTexture.getEffect().executeWhenCompiled(function () {
  522. proceduralTexture.render();
  523. resolve(proceduralTexture);
  524. });
  525. }
  526. });
  527. };
  528. return KHR_texture_transform;
  529. }());
  530. _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_texture_transform(exporter); });
  531. /***/ }),
  532. /***/ "./glTF/2.0/Extensions/index.ts":
  533. /*!**************************************!*\
  534. !*** ./glTF/2.0/Extensions/index.ts ***!
  535. \**************************************/
  536. /*! exports provided: KHR_texture_transform, KHR_lights_punctual */
  537. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  538. "use strict";
  539. __webpack_require__.r(__webpack_exports__);
  540. /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
  541. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__["KHR_texture_transform"]; });
  542. /* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
  543. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  544. /***/ }),
  545. /***/ "./glTF/2.0/glTFAnimation.ts":
  546. /*!***********************************!*\
  547. !*** ./glTF/2.0/glTFAnimation.ts ***!
  548. \***********************************/
  549. /*! exports provided: _GLTFAnimation */
  550. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  551. "use strict";
  552. __webpack_require__.r(__webpack_exports__);
  553. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _GLTFAnimation; });
  554. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  555. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  556. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  557. /**
  558. * @hidden
  559. * Enum for handling in tangent and out tangent.
  560. */
  561. var _TangentType;
  562. (function (_TangentType) {
  563. /**
  564. * Specifies that input tangents are used.
  565. */
  566. _TangentType[_TangentType["INTANGENT"] = 0] = "INTANGENT";
  567. /**
  568. * Specifies that output tangents are used.
  569. */
  570. _TangentType[_TangentType["OUTTANGENT"] = 1] = "OUTTANGENT";
  571. })(_TangentType || (_TangentType = {}));
  572. /**
  573. * @hidden
  574. * Utility class for generating glTF animation data from BabylonJS.
  575. */
  576. var _GLTFAnimation = /** @class */ (function () {
  577. function _GLTFAnimation() {
  578. }
  579. /**
  580. * @ignore
  581. *
  582. * Creates glTF channel animation from BabylonJS animation.
  583. * @param babylonTransformNode - BabylonJS mesh.
  584. * @param animation - animation.
  585. * @param animationChannelTargetPath - The target animation channel.
  586. * @param convertToRightHandedSystem - Specifies if the values should be converted to right-handed.
  587. * @param useQuaternion - Specifies if quaternions are used.
  588. * @returns nullable IAnimationData
  589. */
  590. _GLTFAnimation._CreateNodeAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
  591. var inputs = [];
  592. var outputs = [];
  593. var keyFrames = animation.getKeys();
  594. var minMaxKeyFrames = _GLTFAnimation.calculateMinMaxKeyFrames(keyFrames);
  595. var interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
  596. var frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
  597. var interpolation = interpolationOrBake.interpolationType;
  598. var shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
  599. if (shouldBakeAnimation) {
  600. _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
  601. }
  602. else {
  603. if (interpolation === "LINEAR" /* LINEAR */ || interpolation === "STEP" /* STEP */) {
  604. _GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  605. }
  606. else if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
  607. _GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  608. }
  609. else {
  610. _GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
  611. }
  612. }
  613. if (inputs.length && outputs.length) {
  614. var result = {
  615. inputs: inputs,
  616. outputs: outputs,
  617. samplerInterpolation: interpolation,
  618. inputsMin: shouldBakeAnimation ? minMaxKeyFrames.min : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minMaxKeyFrames.min / animation.framePerSecond),
  619. inputsMax: shouldBakeAnimation ? minMaxKeyFrames.max : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minMaxKeyFrames.max / animation.framePerSecond)
  620. };
  621. return result;
  622. }
  623. return null;
  624. };
  625. _GLTFAnimation._DeduceAnimationInfo = function (animation) {
  626. var animationChannelTargetPath = null;
  627. var dataAccessorType = "VEC3" /* VEC3 */;
  628. var useQuaternion = false;
  629. var property = animation.targetProperty.split('.');
  630. switch (property[0]) {
  631. case 'scaling': {
  632. animationChannelTargetPath = "scale" /* SCALE */;
  633. break;
  634. }
  635. case 'position': {
  636. animationChannelTargetPath = "translation" /* TRANSLATION */;
  637. break;
  638. }
  639. case 'rotation': {
  640. dataAccessorType = "VEC4" /* VEC4 */;
  641. animationChannelTargetPath = "rotation" /* ROTATION */;
  642. break;
  643. }
  644. case 'rotationQuaternion': {
  645. dataAccessorType = "VEC4" /* VEC4 */;
  646. useQuaternion = true;
  647. animationChannelTargetPath = "rotation" /* ROTATION */;
  648. break;
  649. }
  650. default: {
  651. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported animatable property " + property[0]);
  652. }
  653. }
  654. if (animationChannelTargetPath) {
  655. return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
  656. }
  657. else {
  658. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('animation channel target path and data accessor type could be deduced');
  659. }
  660. return null;
  661. };
  662. /**
  663. * @ignore
  664. * Create node animations from the transform node animations
  665. * @param babylonNode
  666. * @param runtimeGLTFAnimation
  667. * @param idleGLTFAnimations
  668. * @param nodeMap
  669. * @param nodes
  670. * @param binaryWriter
  671. * @param bufferViews
  672. * @param accessors
  673. * @param convertToRightHandedSystem
  674. */
  675. _GLTFAnimation._CreateNodeAnimationFromNodeAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
  676. var glTFAnimation;
  677. if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
  678. if (babylonNode.animations) {
  679. for (var _i = 0, _a = babylonNode.animations; _i < _a.length; _i++) {
  680. var animation = _a[_i];
  681. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
  682. if (animationInfo) {
  683. glTFAnimation = {
  684. name: animation.name,
  685. samplers: [],
  686. channels: []
  687. };
  688. _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
  689. if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
  690. idleGLTFAnimations.push(glTFAnimation);
  691. }
  692. }
  693. }
  694. }
  695. }
  696. };
  697. /**
  698. * @ignore
  699. * Create node animations from the animation groups
  700. * @param babylonScene
  701. * @param glTFAnimations
  702. * @param nodeMap
  703. * @param nodes
  704. * @param binaryWriter
  705. * @param bufferViews
  706. * @param accessors
  707. * @param convertToRightHandedSystem
  708. */
  709. _GLTFAnimation._CreateNodeAnimationFromAnimationGroups = function (babylonScene, glTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
  710. var glTFAnimation;
  711. if (babylonScene.animationGroups) {
  712. var animationGroups = babylonScene.animationGroups;
  713. for (var _i = 0, animationGroups_1 = animationGroups; _i < animationGroups_1.length; _i++) {
  714. var animationGroup = animationGroups_1[_i];
  715. glTFAnimation = {
  716. name: animationGroup.name,
  717. channels: [],
  718. samplers: []
  719. };
  720. for (var _a = 0, _b = animationGroup.targetedAnimations; _a < _b.length; _a++) {
  721. var targetAnimation = _b[_a];
  722. var target = targetAnimation.target;
  723. var animation = targetAnimation.animation;
  724. 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
  725. var animationInfo = _GLTFAnimation._DeduceAnimationInfo(targetAnimation.animation);
  726. if (animationInfo) {
  727. var babylonMesh = target instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"] ? target : target[0];
  728. _GLTFAnimation.AddAnimation("" + animation.name, glTFAnimation, babylonMesh, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
  729. }
  730. }
  731. }
  732. if (glTFAnimation.channels.length && glTFAnimation.samplers.length) {
  733. glTFAnimations.push(glTFAnimation);
  734. }
  735. }
  736. }
  737. };
  738. _GLTFAnimation.AddAnimation = function (name, glTFAnimation, babylonTransformNode, animation, dataAccessorType, animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, useQuaternion, animationSampleRate) {
  739. var animationData = _GLTFAnimation._CreateNodeAnimation(babylonTransformNode, animation, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion, animationSampleRate);
  740. var bufferView;
  741. var accessor;
  742. var keyframeAccessorIndex;
  743. var dataAccessorIndex;
  744. var outputLength;
  745. var animationSampler;
  746. var animationChannel;
  747. if (animationData) {
  748. var nodeIndex = nodeMap[babylonTransformNode.uniqueId];
  749. // Creates buffer view and accessor for key frames.
  750. var byteLength = animationData.inputs.length * 4;
  751. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, name + " keyframe data view");
  752. bufferViews.push(bufferView);
  753. animationData.inputs.forEach(function (input) {
  754. binaryWriter.setFloat32(input);
  755. });
  756. 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]);
  757. accessors.push(accessor);
  758. keyframeAccessorIndex = accessors.length - 1;
  759. // create bufferview and accessor for keyed values.
  760. outputLength = animationData.outputs.length;
  761. byteLength = dataAccessorType === "VEC3" /* VEC3 */ ? animationData.outputs.length * 12 : animationData.outputs.length * 16;
  762. // check for in and out tangents
  763. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, name + " data view");
  764. bufferViews.push(bufferView);
  765. animationData.outputs.forEach(function (output) {
  766. output.forEach(function (entry) {
  767. binaryWriter.setFloat32(entry);
  768. });
  769. });
  770. accessor = _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._CreateAccessor(bufferViews.length - 1, name + " data", dataAccessorType, 5126 /* FLOAT */, outputLength, null, null, null);
  771. accessors.push(accessor);
  772. dataAccessorIndex = accessors.length - 1;
  773. // create sampler
  774. animationSampler = {
  775. interpolation: animationData.samplerInterpolation,
  776. input: keyframeAccessorIndex,
  777. output: dataAccessorIndex
  778. };
  779. glTFAnimation.samplers.push(animationSampler);
  780. // create channel
  781. animationChannel = {
  782. sampler: glTFAnimation.samplers.length - 1,
  783. target: {
  784. node: nodeIndex,
  785. path: animationChannelTargetPath
  786. }
  787. };
  788. glTFAnimation.channels.push(animationChannel);
  789. }
  790. };
  791. /**
  792. * Create a baked animation
  793. * @param babylonTransformNode BabylonJS mesh
  794. * @param animation BabylonJS animation corresponding to the BabylonJS mesh
  795. * @param animationChannelTargetPath animation target channel
  796. * @param minFrame minimum animation frame
  797. * @param maxFrame maximum animation frame
  798. * @param fps frames per second of the animation
  799. * @param inputs input key frames of the animation
  800. * @param outputs output key frame data of the animation
  801. * @param convertToRightHandedSystem converts the values to right-handed
  802. * @param useQuaternion specifies if quaternions should be used
  803. */
  804. _GLTFAnimation._CreateBakedAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, minFrame, maxFrame, fps, sampleRate, inputs, outputs, minMaxFrames, convertToRightHandedSystem, useQuaternion) {
  805. var value;
  806. var quaternionCache = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity();
  807. var previousTime = null;
  808. var time;
  809. var maxUsedFrame = null;
  810. var currKeyFrame = null;
  811. var nextKeyFrame = null;
  812. var prevKeyFrame = null;
  813. var endFrame = null;
  814. minMaxFrames.min = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(minFrame / fps);
  815. var keyFrames = animation.getKeys();
  816. for (var i = 0, length_1 = keyFrames.length; i < length_1; ++i) {
  817. endFrame = null;
  818. currKeyFrame = keyFrames[i];
  819. if (i + 1 < length_1) {
  820. nextKeyFrame = keyFrames[i + 1];
  821. if (currKeyFrame.value.equals(nextKeyFrame.value)) {
  822. if (i === 0) { // set the first frame to itself
  823. endFrame = currKeyFrame.frame;
  824. }
  825. else {
  826. continue;
  827. }
  828. }
  829. else {
  830. endFrame = nextKeyFrame.frame;
  831. }
  832. }
  833. else {
  834. // at the last key frame
  835. prevKeyFrame = keyFrames[i - 1];
  836. if (currKeyFrame.value.equals(prevKeyFrame.value)) {
  837. continue;
  838. }
  839. else {
  840. endFrame = maxFrame;
  841. }
  842. }
  843. if (endFrame) {
  844. for (var f = currKeyFrame.frame; f <= endFrame; f += sampleRate) {
  845. time = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].FloatRound(f / fps);
  846. if (time === previousTime) {
  847. continue;
  848. }
  849. previousTime = time;
  850. maxUsedFrame = time;
  851. value = animation._interpolate(f, 0, undefined, animation.loopMode);
  852. _GLTFAnimation._SetInterpolatedValue(babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion);
  853. }
  854. }
  855. }
  856. if (maxUsedFrame) {
  857. minMaxFrames.max = maxUsedFrame;
  858. }
  859. };
  860. _GLTFAnimation._ConvertFactorToVector3OrQuaternion = function (factor, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
  861. var property;
  862. var componentName;
  863. var value = null;
  864. var basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  865. 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.
  866. property = animation.targetProperty.split('.');
  867. componentName = property ? property[1] : ''; // x, y, or z component
  868. value = useQuaternion ? babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray(basePositionRotationOrScale).normalize() : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(basePositionRotationOrScale);
  869. switch (componentName) {
  870. case 'x': {
  871. value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  872. break;
  873. }
  874. case 'y': {
  875. value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  876. break;
  877. }
  878. case 'z': {
  879. value[componentName] = (convertToRightHandedSystem && !useQuaternion && (animationChannelTargetPath !== "scale" /* SCALE */)) ? -factor : factor;
  880. break;
  881. }
  882. case 'w': {
  883. value.w = factor;
  884. break;
  885. }
  886. default: {
  887. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("glTFAnimation: Unsupported component type \"" + componentName + "\" for scale animation!");
  888. }
  889. }
  890. }
  891. return value;
  892. };
  893. _GLTFAnimation._SetInterpolatedValue = function (babylonTransformNode, value, time, animation, animationChannelTargetPath, quaternionCache, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  894. var animationType = animation.dataType;
  895. var cacheValue;
  896. inputs.push(time);
  897. if (typeof value === "number") {
  898. value = this._ConvertFactorToVector3OrQuaternion(value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  899. }
  900. if (value) {
  901. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  902. if (useQuaternion) {
  903. quaternionCache = value;
  904. }
  905. else {
  906. cacheValue = value;
  907. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);
  908. }
  909. if (convertToRightHandedSystem) {
  910. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(quaternionCache);
  911. if (!babylonTransformNode.parent) {
  912. quaternionCache = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(quaternionCache);
  913. }
  914. }
  915. outputs.push(quaternionCache.asArray());
  916. }
  917. else {
  918. cacheValue = value;
  919. if (convertToRightHandedSystem && (animationChannelTargetPath !== "scale" /* SCALE */)) {
  920. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(cacheValue);
  921. if (!babylonTransformNode.parent) {
  922. cacheValue.x *= -1;
  923. cacheValue.z *= -1;
  924. }
  925. }
  926. outputs.push(cacheValue.asArray());
  927. }
  928. }
  929. };
  930. /**
  931. * Creates linear animation from the animation key frames
  932. * @param babylonTransformNode BabylonJS mesh
  933. * @param animation BabylonJS animation
  934. * @param animationChannelTargetPath The target animation channel
  935. * @param frameDelta The difference between the last and first frame of the animation
  936. * @param inputs Array to store the key frame times
  937. * @param outputs Array to store the key frame data
  938. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  939. * @param useQuaternion Specifies if quaternions are used in the animation
  940. */
  941. _GLTFAnimation._CreateLinearOrStepAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  942. for (var _i = 0, _a = animation.getKeys(); _i < _a.length; _i++) {
  943. var keyFrame = _a[_i];
  944. inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
  945. _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  946. }
  947. };
  948. /**
  949. * Creates cubic spline animation from the animation key frames
  950. * @param babylonTransformNode BabylonJS mesh
  951. * @param animation BabylonJS animation
  952. * @param animationChannelTargetPath The target animation channel
  953. * @param frameDelta The difference between the last and first frame of the animation
  954. * @param inputs Array to store the key frame times
  955. * @param outputs Array to store the key frame data
  956. * @param convertToRightHandedSystem Specifies if the position data should be converted to right handed
  957. * @param useQuaternion Specifies if quaternions are used in the animation
  958. */
  959. _GLTFAnimation._CreateCubicSplineAnimation = function (babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion) {
  960. animation.getKeys().forEach(function (keyFrame) {
  961. inputs.push(keyFrame.frame / animation.framePerSecond); // keyframes in seconds.
  962. _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.INTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  963. _GLTFAnimation._AddKeyframeValue(keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion);
  964. _GLTFAnimation.AddSplineTangent(babylonTransformNode, _TangentType.OUTTANGENT, outputs, animationChannelTargetPath, "CUBICSPLINE" /* CUBICSPLINE */, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem);
  965. });
  966. };
  967. _GLTFAnimation._GetBasePositionRotationOrScale = function (babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion) {
  968. var basePositionRotationOrScale;
  969. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  970. if (useQuaternion) {
  971. if (babylonTransformNode.rotationQuaternion) {
  972. basePositionRotationOrScale = babylonTransformNode.rotationQuaternion.asArray();
  973. if (convertToRightHandedSystem) {
  974. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(basePositionRotationOrScale);
  975. if (!babylonTransformNode.parent) {
  976. 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();
  977. }
  978. }
  979. }
  980. else {
  981. basePositionRotationOrScale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity().asArray();
  982. }
  983. }
  984. else {
  985. basePositionRotationOrScale = babylonTransformNode.rotation.asArray();
  986. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalArray3FromRef(basePositionRotationOrScale);
  987. }
  988. }
  989. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  990. basePositionRotationOrScale = babylonTransformNode.position.asArray();
  991. if (convertToRightHandedSystem) {
  992. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionArray3FromRef(basePositionRotationOrScale);
  993. }
  994. }
  995. else { // scale
  996. basePositionRotationOrScale = babylonTransformNode.scaling.asArray();
  997. }
  998. return basePositionRotationOrScale;
  999. };
  1000. /**
  1001. * Adds a key frame value
  1002. * @param keyFrame
  1003. * @param animation
  1004. * @param outputs
  1005. * @param animationChannelTargetPath
  1006. * @param basePositionRotationOrScale
  1007. * @param convertToRightHandedSystem
  1008. * @param useQuaternion
  1009. */
  1010. _GLTFAnimation._AddKeyframeValue = function (keyFrame, animation, outputs, animationChannelTargetPath, babylonTransformNode, convertToRightHandedSystem, useQuaternion) {
  1011. var value;
  1012. var newPositionRotationOrScale;
  1013. var animationType = animation.dataType;
  1014. if (animationType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_VECTOR3) {
  1015. value = keyFrame.value.asArray();
  1016. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1017. var array = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(value);
  1018. var rotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(array.y, array.x, array.z);
  1019. if (convertToRightHandedSystem) {
  1020. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(rotationQuaternion);
  1021. if (!babylonTransformNode.parent) {
  1022. rotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(rotationQuaternion);
  1023. }
  1024. }
  1025. value = rotationQuaternion.asArray();
  1026. }
  1027. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1028. if (convertToRightHandedSystem) {
  1029. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalArray3FromRef(value);
  1030. if (!babylonTransformNode.parent) {
  1031. value[0] *= -1;
  1032. value[2] *= -1;
  1033. }
  1034. }
  1035. }
  1036. outputs.push(value); // scale vector.
  1037. }
  1038. 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.
  1039. newPositionRotationOrScale = this._ConvertFactorToVector3OrQuaternion(keyFrame.value, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
  1040. if (newPositionRotationOrScale) {
  1041. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1042. var posRotScale = useQuaternion ? newPositionRotationOrScale : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(newPositionRotationOrScale.y, newPositionRotationOrScale.x, newPositionRotationOrScale.z).normalize();
  1043. if (convertToRightHandedSystem) {
  1044. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(posRotScale);
  1045. if (!babylonTransformNode.parent) {
  1046. posRotScale = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromArray([0, 1, 0, 0]).multiply(posRotScale);
  1047. }
  1048. }
  1049. outputs.push(posRotScale.asArray());
  1050. }
  1051. else if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1052. if (convertToRightHandedSystem) {
  1053. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(newPositionRotationOrScale);
  1054. if (!babylonTransformNode.parent) {
  1055. newPositionRotationOrScale.x *= -1;
  1056. newPositionRotationOrScale.z *= -1;
  1057. }
  1058. }
  1059. }
  1060. outputs.push(newPositionRotationOrScale.asArray());
  1061. }
  1062. }
  1063. else if (animationType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Animation"].ANIMATIONTYPE_QUATERNION) {
  1064. value = keyFrame.value.normalize().asArray();
  1065. if (convertToRightHandedSystem) {
  1066. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(value);
  1067. if (!babylonTransformNode.parent) {
  1068. 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();
  1069. }
  1070. }
  1071. outputs.push(value);
  1072. }
  1073. else {
  1074. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('glTFAnimation: Unsupported key frame values for animation!');
  1075. }
  1076. };
  1077. /**
  1078. * Determine the interpolation based on the key frames
  1079. * @param keyFrames
  1080. * @param animationChannelTargetPath
  1081. * @param useQuaternion
  1082. */
  1083. _GLTFAnimation._DeduceInterpolation = function (keyFrames, animationChannelTargetPath, useQuaternion) {
  1084. var interpolationType;
  1085. var shouldBakeAnimation = false;
  1086. var key;
  1087. if (animationChannelTargetPath === "rotation" /* ROTATION */ && !useQuaternion) {
  1088. return { interpolationType: "LINEAR" /* LINEAR */, shouldBakeAnimation: true };
  1089. }
  1090. for (var i = 0, length_2 = keyFrames.length; i < length_2; ++i) {
  1091. key = keyFrames[i];
  1092. if (key.inTangent || key.outTangent) {
  1093. if (interpolationType) {
  1094. if (interpolationType !== "CUBICSPLINE" /* CUBICSPLINE */) {
  1095. interpolationType = "LINEAR" /* LINEAR */;
  1096. shouldBakeAnimation = true;
  1097. break;
  1098. }
  1099. }
  1100. else {
  1101. interpolationType = "CUBICSPLINE" /* CUBICSPLINE */;
  1102. }
  1103. }
  1104. else {
  1105. if (interpolationType) {
  1106. if (interpolationType === "CUBICSPLINE" /* CUBICSPLINE */ ||
  1107. (key.interpolation && (key.interpolation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP) && interpolationType !== "STEP" /* STEP */)) {
  1108. interpolationType = "LINEAR" /* LINEAR */;
  1109. shouldBakeAnimation = true;
  1110. break;
  1111. }
  1112. }
  1113. else {
  1114. if (key.interpolation && (key.interpolation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["AnimationKeyInterpolation"].STEP)) {
  1115. interpolationType = "STEP" /* STEP */;
  1116. }
  1117. else {
  1118. interpolationType = "LINEAR" /* LINEAR */;
  1119. }
  1120. }
  1121. }
  1122. }
  1123. if (!interpolationType) {
  1124. interpolationType = "LINEAR" /* LINEAR */;
  1125. }
  1126. return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
  1127. };
  1128. /**
  1129. * Adds an input tangent or output tangent to the output data
  1130. * If an input tangent or output tangent is missing, it uses the zero vector or zero quaternion
  1131. * @param tangentType Specifies which type of tangent to handle (inTangent or outTangent)
  1132. * @param outputs The animation data by keyframe
  1133. * @param animationChannelTargetPath The target animation channel
  1134. * @param interpolation The interpolation type
  1135. * @param keyFrame The key frame with the animation data
  1136. * @param frameDelta Time difference between two frames used to scale the tangent by the frame delta
  1137. * @param useQuaternion Specifies if quaternions are used
  1138. * @param convertToRightHandedSystem Specifies if the values should be converted to right-handed
  1139. */
  1140. _GLTFAnimation.AddSplineTangent = function (babylonTransformNode, tangentType, outputs, animationChannelTargetPath, interpolation, keyFrame, frameDelta, useQuaternion, convertToRightHandedSystem) {
  1141. var tangent;
  1142. var tangentValue = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
  1143. if (interpolation === "CUBICSPLINE" /* CUBICSPLINE */) {
  1144. if (animationChannelTargetPath === "rotation" /* ROTATION */) {
  1145. if (tangentValue) {
  1146. if (useQuaternion) {
  1147. tangent = tangentValue.scale(frameDelta).asArray();
  1148. }
  1149. else {
  1150. var array = tangentValue.scale(frameDelta);
  1151. tangent = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(array.y, array.x, array.z).asArray();
  1152. }
  1153. if (convertToRightHandedSystem) {
  1154. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedQuaternionArrayFromRef(tangent);
  1155. if (!babylonTransformNode.parent) {
  1156. 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();
  1157. }
  1158. }
  1159. }
  1160. else {
  1161. tangent = [0, 0, 0, 0];
  1162. }
  1163. }
  1164. else {
  1165. if (tangentValue) {
  1166. tangent = tangentValue.scale(frameDelta).asArray();
  1167. if (convertToRightHandedSystem) {
  1168. if (animationChannelTargetPath === "translation" /* TRANSLATION */) {
  1169. _glTFUtilities__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]._GetRightHandedPositionArray3FromRef(tangent);
  1170. if (!babylonTransformNode.parent) {
  1171. tangent[0] *= -1; // x
  1172. tangent[2] *= -1; // z
  1173. }
  1174. }
  1175. }
  1176. }
  1177. else {
  1178. tangent = [0, 0, 0];
  1179. }
  1180. }
  1181. outputs.push(tangent);
  1182. }
  1183. };
  1184. /**
  1185. * Get the minimum and maximum key frames' frame values
  1186. * @param keyFrames animation key frames
  1187. * @returns the minimum and maximum key frame value
  1188. */
  1189. _GLTFAnimation.calculateMinMaxKeyFrames = function (keyFrames) {
  1190. var min = Infinity;
  1191. var max = -Infinity;
  1192. keyFrames.forEach(function (keyFrame) {
  1193. min = Math.min(min, keyFrame.frame);
  1194. max = Math.max(max, keyFrame.frame);
  1195. });
  1196. return { min: min, max: max };
  1197. };
  1198. return _GLTFAnimation;
  1199. }());
  1200. /***/ }),
  1201. /***/ "./glTF/2.0/glTFData.ts":
  1202. /*!******************************!*\
  1203. !*** ./glTF/2.0/glTFData.ts ***!
  1204. \******************************/
  1205. /*! exports provided: GLTFData */
  1206. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1207. "use strict";
  1208. __webpack_require__.r(__webpack_exports__);
  1209. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return GLTFData; });
  1210. /**
  1211. * Class for holding and downloading glTF file data
  1212. */
  1213. var GLTFData = /** @class */ (function () {
  1214. /**
  1215. * Initializes the glTF file object
  1216. */
  1217. function GLTFData() {
  1218. this.glTFFiles = {};
  1219. }
  1220. /**
  1221. * Downloads the glTF data as files based on their names and data
  1222. */
  1223. GLTFData.prototype.downloadFiles = function () {
  1224. /**
  1225. * Checks for a matching suffix at the end of a string (for ES5 and lower)
  1226. * @param str Source string
  1227. * @param suffix Suffix to search for in the source string
  1228. * @returns Boolean indicating whether the suffix was found (true) or not (false)
  1229. */
  1230. function endsWith(str, suffix) {
  1231. return str.indexOf(suffix, str.length - suffix.length) !== -1;
  1232. }
  1233. for (var key in this.glTFFiles) {
  1234. var link = document.createElement('a');
  1235. document.body.appendChild(link);
  1236. link.setAttribute("type", "hidden");
  1237. link.download = key;
  1238. var blob = this.glTFFiles[key];
  1239. var mimeType = void 0;
  1240. if (endsWith(key, ".glb")) {
  1241. mimeType = { type: "model/gltf-binary" };
  1242. }
  1243. else if (endsWith(key, ".bin")) {
  1244. mimeType = { type: "application/octet-stream" };
  1245. }
  1246. else if (endsWith(key, ".gltf")) {
  1247. mimeType = { type: "model/gltf+json" };
  1248. }
  1249. else if (endsWith(key, ".jpeg" || false)) {
  1250. mimeType = { type: "image/jpeg" /* JPEG */ };
  1251. }
  1252. else if (endsWith(key, ".png")) {
  1253. mimeType = { type: "image/png" /* PNG */ };
  1254. }
  1255. link.href = window.URL.createObjectURL(new Blob([blob], mimeType));
  1256. link.click();
  1257. }
  1258. };
  1259. return GLTFData;
  1260. }());
  1261. /***/ }),
  1262. /***/ "./glTF/2.0/glTFExporter.ts":
  1263. /*!**********************************!*\
  1264. !*** ./glTF/2.0/glTFExporter.ts ***!
  1265. \**********************************/
  1266. /*! exports provided: _Exporter, _BinaryWriter */
  1267. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1268. "use strict";
  1269. __webpack_require__.r(__webpack_exports__);
  1270. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _Exporter; });
  1271. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _BinaryWriter; });
  1272. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  1273. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  1274. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  1275. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  1276. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  1277. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  1278. /**
  1279. * Converts Babylon Scene into glTF 2.0.
  1280. * @hidden
  1281. */
  1282. var _Exporter = /** @class */ (function () {
  1283. /**
  1284. * Creates a glTF Exporter instance, which can accept optional exporter options
  1285. * @param babylonScene Babylon scene object
  1286. * @param options Options to modify the behavior of the exporter
  1287. */
  1288. function _Exporter(babylonScene, options) {
  1289. this._extensions = {};
  1290. this._glTF = {
  1291. asset: { generator: "BabylonJS", version: "2.0" }
  1292. };
  1293. this._babylonScene = babylonScene;
  1294. this._bufferViews = [];
  1295. this._accessors = [];
  1296. this._meshes = [];
  1297. this._scenes = [];
  1298. this._nodes = [];
  1299. this._images = [];
  1300. this._materials = [];
  1301. this._materialMap = [];
  1302. this._textures = [];
  1303. this._samplers = [];
  1304. this._animations = [];
  1305. this._imageData = {};
  1306. this._convertToRightHandedSystem = this._babylonScene.useRightHandedSystem ? false : true;
  1307. var _options = options || {};
  1308. this._shouldExportNode = _options.shouldExportNode ? _options.shouldExportNode : function (babylonNode) { return true; };
  1309. this._animationSampleRate = _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 uvCoordsPresent;
  2139. var minMax;
  2140. if (babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"]) {
  2141. bufferMesh = babylonTransformNode;
  2142. }
  2143. else if (babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["InstancedMesh"]) {
  2144. bufferMesh = babylonTransformNode.sourceMesh;
  2145. }
  2146. var attributeData = [
  2147. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, accessorType: "VEC3" /* VEC3 */, byteStride: 12 },
  2148. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, accessorType: "VEC3" /* VEC3 */, byteStride: 12 },
  2149. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, accessorType: "VEC4" /* VEC4 */, byteStride: 16 },
  2150. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, accessorType: "VEC4" /* VEC4 */, byteStride: 16 },
  2151. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind, accessorType: "VEC2" /* VEC2 */, byteStride: 8 },
  2152. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind, accessorType: "VEC2" /* VEC2 */, byteStride: 8 },
  2153. ];
  2154. if (bufferMesh) {
  2155. var indexBufferViewIndex = null;
  2156. var primitiveMode = this.getMeshPrimitiveMode(bufferMesh);
  2157. var vertexAttributeBufferViews = {};
  2158. // For each BabylonMesh, create bufferviews for each 'kind'
  2159. for (var _i = 0, attributeData_1 = attributeData; _i < attributeData_1.length; _i++) {
  2160. var attribute = attributeData_1[_i];
  2161. var attributeKind = attribute.kind;
  2162. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  2163. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  2164. attribute.byteStride = vertexBuffer ? vertexBuffer.getSize() * 4 : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].DeduceStride(attributeKind) * 4;
  2165. if (attribute.byteStride === 12) {
  2166. attribute.accessorType = "VEC3" /* VEC3 */;
  2167. }
  2168. this.createBufferViewKind(attributeKind, babylonTransformNode, binaryWriter, attribute.byteStride);
  2169. attribute.bufferViewIndex = this._bufferViews.length - 1;
  2170. vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;
  2171. }
  2172. }
  2173. if (bufferMesh.getTotalIndices()) {
  2174. var indices = bufferMesh.getIndices();
  2175. if (indices) {
  2176. var byteLength = indices.length * 4;
  2177. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "Indices - " + bufferMesh.name);
  2178. this._bufferViews.push(bufferView);
  2179. indexBufferViewIndex = this._bufferViews.length - 1;
  2180. for (var k = 0, length_7 = indices.length; k < length_7; ++k) {
  2181. binaryWriter.setUInt32(indices[k]);
  2182. }
  2183. }
  2184. }
  2185. if (bufferMesh.subMeshes) {
  2186. // go through all mesh primitives (submeshes)
  2187. for (var _a = 0, _b = bufferMesh.subMeshes; _a < _b.length; _a++) {
  2188. var submesh = _b[_a];
  2189. uvCoordsPresent = false;
  2190. var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
  2191. var materialIndex = null;
  2192. if (babylonMaterial) {
  2193. if (bufferMesh instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["LinesMesh"]) {
  2194. // get the color from the lines mesh and set it in the material
  2195. var material = {
  2196. name: bufferMesh.name + ' material'
  2197. };
  2198. if (!bufferMesh.color.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White()) || bufferMesh.alpha < 1) {
  2199. material.pbrMetallicRoughness = {
  2200. baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha])
  2201. };
  2202. }
  2203. this._materials.push(material);
  2204. materialIndex = this._materials.length - 1;
  2205. }
  2206. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["MultiMaterial"]) {
  2207. var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
  2208. if (subMaterial) {
  2209. babylonMaterial = subMaterial;
  2210. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  2211. }
  2212. }
  2213. else {
  2214. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  2215. }
  2216. }
  2217. var glTFMaterial = materialIndex != null ? this._materials[materialIndex] : null;
  2218. var meshPrimitive = { attributes: {} };
  2219. this.setPrimitiveMode(meshPrimitive, primitiveMode);
  2220. for (var _c = 0, attributeData_2 = attributeData; _c < attributeData_2.length; _c++) {
  2221. var attribute = attributeData_2[_c];
  2222. var attributeKind = attribute.kind;
  2223. if (attributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind || attributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind) {
  2224. if (glTFMaterial && !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
  2225. continue;
  2226. }
  2227. }
  2228. var vertexData = bufferMesh.getVerticesData(attributeKind);
  2229. if (vertexData) {
  2230. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  2231. if (vertexBuffer) {
  2232. var stride = vertexBuffer.getSize();
  2233. var bufferViewIndex = attribute.bufferViewIndex;
  2234. if (bufferViewIndex != undefined) { // check to see if bufferviewindex has a numeric value assigned.
  2235. minMax = { min: null, max: null };
  2236. if (attributeKind == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind) {
  2237. minMax = _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride, this._convertToRightHandedSystem);
  2238. }
  2239. 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);
  2240. this._accessors.push(accessor);
  2241. this.setAttributeKind(meshPrimitive, attributeKind);
  2242. if (meshPrimitive.attributes.TEXCOORD_0 != null || meshPrimitive.attributes.TEXCOORD_1 != null) {
  2243. uvCoordsPresent = true;
  2244. }
  2245. }
  2246. }
  2247. }
  2248. }
  2249. if (indexBufferViewIndex) {
  2250. // Create accessor
  2251. 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);
  2252. this._accessors.push(accessor);
  2253. meshPrimitive.indices = this._accessors.length - 1;
  2254. }
  2255. if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
  2256. var sideOrientation = babylonMaterial.sideOrientation;
  2257. if (this._convertToRightHandedSystem && sideOrientation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation) {
  2258. //Overwrite the indices to be counter-clockwise
  2259. var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
  2260. if (byteOffset == null) {
  2261. byteOffset = 0;
  2262. }
  2263. var babylonIndices = null;
  2264. if (indexBufferViewIndex != null) {
  2265. babylonIndices = bufferMesh.getIndices();
  2266. }
  2267. if (babylonIndices) {
  2268. this.reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
  2269. }
  2270. else {
  2271. for (var _d = 0, attributeData_3 = attributeData; _d < attributeData_3.length; _d++) {
  2272. var attribute = attributeData_3[_d];
  2273. var vertexData = bufferMesh.getVerticesData(attribute.kind);
  2274. if (vertexData) {
  2275. var byteOffset_1 = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset;
  2276. if (!byteOffset_1) {
  2277. byteOffset_1 = 0;
  2278. }
  2279. this.reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, attribute.kind, vertexData, byteOffset_1, binaryWriter);
  2280. }
  2281. }
  2282. }
  2283. }
  2284. if (!uvCoordsPresent && this._glTFMaterialExporter._hasTexturesPresent(this._materials[materialIndex])) {
  2285. var newMat = this._glTFMaterialExporter._stripTexturesFromMaterial(this._materials[materialIndex]);
  2286. this._materials.push(newMat);
  2287. materialIndex = this._materials.length - 1;
  2288. }
  2289. meshPrimitive.material = materialIndex;
  2290. }
  2291. mesh.primitives.push(meshPrimitive);
  2292. var promise = this._extensionsPostExportMeshPrimitiveAsync("postExport", meshPrimitive, submesh, binaryWriter);
  2293. if (promise) {
  2294. promises.push();
  2295. }
  2296. }
  2297. }
  2298. }
  2299. return Promise.all(promises).then(function () {
  2300. /* do nothing */
  2301. });
  2302. };
  2303. /**
  2304. * Creates a glTF scene based on the array of meshes
  2305. * Returns the the total byte offset
  2306. * @param babylonScene Babylon scene to get the mesh data from
  2307. * @param binaryWriter Buffer to write binary data to
  2308. */
  2309. _Exporter.prototype.createSceneAsync = function (babylonScene, binaryWriter) {
  2310. var _this = this;
  2311. var scene = { nodes: [] };
  2312. var glTFNodeIndex;
  2313. var glTFNode;
  2314. var directDescendents;
  2315. var nodes = babylonScene.transformNodes.concat(babylonScene.meshes, babylonScene.lights);
  2316. return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
  2317. return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, _this._shouldExportNode, binaryWriter).then(function (nodeMap) {
  2318. _this._nodeMap = nodeMap;
  2319. _this._totalByteLength = binaryWriter.getByteOffset();
  2320. if (_this._totalByteLength == undefined) {
  2321. throw new Error("undefined byte length!");
  2322. }
  2323. // Build Hierarchy with the node map.
  2324. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2325. var babylonNode = nodes_1[_i];
  2326. glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
  2327. if (glTFNodeIndex !== undefined) {
  2328. glTFNode = _this._nodes[glTFNodeIndex];
  2329. if (!babylonNode.parent) {
  2330. if (!_this._shouldExportNode(babylonNode)) {
  2331. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Omitting " + babylonNode.name + " from scene.");
  2332. }
  2333. else {
  2334. if (_this._convertToRightHandedSystem) {
  2335. if (glTFNode.translation) {
  2336. glTFNode.translation[2] *= -1;
  2337. glTFNode.translation[0] *= -1;
  2338. }
  2339. 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();
  2340. }
  2341. scene.nodes.push(glTFNodeIndex);
  2342. }
  2343. }
  2344. directDescendents = babylonNode.getDescendants(true);
  2345. if (!glTFNode.children && directDescendents && directDescendents.length) {
  2346. var children = [];
  2347. for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
  2348. var descendent = directDescendents_1[_a];
  2349. if (_this._nodeMap[descendent.uniqueId] != null) {
  2350. children.push(_this._nodeMap[descendent.uniqueId]);
  2351. }
  2352. }
  2353. if (children.length) {
  2354. glTFNode.children = children;
  2355. }
  2356. }
  2357. }
  2358. }
  2359. if (scene.nodes.length) {
  2360. _this._scenes.push(scene);
  2361. }
  2362. });
  2363. });
  2364. };
  2365. /**
  2366. * Creates a mapping of Node unique id to node index and handles animations
  2367. * @param babylonScene Babylon Scene
  2368. * @param nodes Babylon transform nodes
  2369. * @param shouldExportNode Callback specifying if a transform node should be exported
  2370. * @param binaryWriter Buffer to write binary data to
  2371. * @returns Node mapping of unique id to index
  2372. */
  2373. _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, shouldExportNode, binaryWriter) {
  2374. var _this = this;
  2375. var promiseChain = Promise.resolve();
  2376. var nodeMap = {};
  2377. var nodeIndex;
  2378. var runtimeGLTFAnimation = {
  2379. name: 'runtime animations',
  2380. channels: [],
  2381. samplers: []
  2382. };
  2383. var idleGLTFAnimations = [];
  2384. var _loop_1 = function (babylonNode) {
  2385. if (shouldExportNode(babylonNode)) {
  2386. promiseChain = promiseChain.then(function () {
  2387. return _this.createNodeAsync(babylonNode, binaryWriter).then(function (node) {
  2388. var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode);
  2389. if (promise == null) {
  2390. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Not exporting node " + babylonNode.name);
  2391. return Promise.resolve();
  2392. }
  2393. else {
  2394. return promise.then(function (node) {
  2395. var directDescendents = babylonNode.getDescendants(true, function (node) { return (node instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Node"]); });
  2396. if (directDescendents.length || node.mesh != null || (node.extensions)) {
  2397. _this._nodes.push(node);
  2398. nodeIndex = _this._nodes.length - 1;
  2399. nodeMap[babylonNode.uniqueId] = nodeIndex;
  2400. }
  2401. if (!babylonScene.animationGroups.length && babylonNode.animations.length) {
  2402. _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
  2403. }
  2404. });
  2405. }
  2406. });
  2407. });
  2408. }
  2409. else {
  2410. "Excluding node " + babylonNode.name;
  2411. }
  2412. };
  2413. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  2414. var babylonNode = nodes_2[_i];
  2415. _loop_1(babylonNode);
  2416. }
  2417. return promiseChain.then(function () {
  2418. if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
  2419. _this._animations.push(runtimeGLTFAnimation);
  2420. }
  2421. idleGLTFAnimations.forEach(function (idleGLTFAnimation) {
  2422. if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {
  2423. _this._animations.push(idleGLTFAnimation);
  2424. }
  2425. });
  2426. if (babylonScene.animationGroups.length) {
  2427. _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromAnimationGroups(babylonScene, _this._animations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
  2428. }
  2429. return nodeMap;
  2430. });
  2431. };
  2432. /**
  2433. * Creates a glTF node from a Babylon mesh
  2434. * @param babylonMesh Source Babylon mesh
  2435. * @param binaryWriter Buffer for storing geometry data
  2436. * @returns glTF node
  2437. */
  2438. _Exporter.prototype.createNodeAsync = function (babylonNode, binaryWriter) {
  2439. var _this = this;
  2440. return Promise.resolve().then(function () {
  2441. // create node to hold translation/rotation/scale and the mesh
  2442. var node = {};
  2443. // create mesh
  2444. var mesh = { primitives: [] };
  2445. if (babylonNode.name) {
  2446. node.name = babylonNode.name;
  2447. }
  2448. if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
  2449. // Set transformation
  2450. _this.setNodeTransformation(node, babylonNode);
  2451. return _this.setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(function () {
  2452. if (mesh.primitives.length) {
  2453. _this._meshes.push(mesh);
  2454. node.mesh = _this._meshes.length - 1;
  2455. }
  2456. return node;
  2457. });
  2458. }
  2459. else {
  2460. return node;
  2461. }
  2462. });
  2463. };
  2464. _Exporter._ExtensionNames = new Array();
  2465. _Exporter._ExtensionFactories = {};
  2466. return _Exporter;
  2467. }());
  2468. /**
  2469. * @hidden
  2470. *
  2471. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  2472. */
  2473. var _BinaryWriter = /** @class */ (function () {
  2474. /**
  2475. * Initialize binary writer with an initial byte length
  2476. * @param byteLength Initial byte length of the array buffer
  2477. */
  2478. function _BinaryWriter(byteLength) {
  2479. this._arrayBuffer = new ArrayBuffer(byteLength);
  2480. this._dataView = new DataView(this._arrayBuffer);
  2481. this._byteOffset = 0;
  2482. }
  2483. /**
  2484. * Resize the array buffer to the specified byte length
  2485. * @param byteLength
  2486. */
  2487. _BinaryWriter.prototype.resizeBuffer = function (byteLength) {
  2488. var newBuffer = new ArrayBuffer(byteLength);
  2489. var oldUint8Array = new Uint8Array(this._arrayBuffer);
  2490. var newUint8Array = new Uint8Array(newBuffer);
  2491. for (var i = 0, length_8 = newUint8Array.byteLength; i < length_8; ++i) {
  2492. newUint8Array[i] = oldUint8Array[i];
  2493. }
  2494. this._arrayBuffer = newBuffer;
  2495. this._dataView = new DataView(this._arrayBuffer);
  2496. return newBuffer;
  2497. };
  2498. /**
  2499. * Get an array buffer with the length of the byte offset
  2500. * @returns ArrayBuffer resized to the byte offset
  2501. */
  2502. _BinaryWriter.prototype.getArrayBuffer = function () {
  2503. return this.resizeBuffer(this.getByteOffset());
  2504. };
  2505. /**
  2506. * Get the byte offset of the array buffer
  2507. * @returns byte offset
  2508. */
  2509. _BinaryWriter.prototype.getByteOffset = function () {
  2510. if (this._byteOffset == undefined) {
  2511. throw new Error("Byte offset is undefined!");
  2512. }
  2513. return this._byteOffset;
  2514. };
  2515. /**
  2516. * Stores an UInt8 in the array buffer
  2517. * @param entry
  2518. * @param byteOffset If defined, specifies where to set the value as an offset.
  2519. */
  2520. _BinaryWriter.prototype.setUInt8 = function (entry, byteOffset) {
  2521. if (byteOffset != null) {
  2522. if (byteOffset < this._byteOffset) {
  2523. this._dataView.setUint8(byteOffset, entry);
  2524. }
  2525. else {
  2526. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2527. }
  2528. }
  2529. else {
  2530. if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
  2531. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2532. }
  2533. this._dataView.setUint8(this._byteOffset++, entry);
  2534. }
  2535. };
  2536. /**
  2537. * Gets an UInt32 in the array buffer
  2538. * @param entry
  2539. * @param byteOffset If defined, specifies where to set the value as an offset.
  2540. */
  2541. _BinaryWriter.prototype.getUInt32 = function (byteOffset) {
  2542. if (byteOffset < this._byteOffset) {
  2543. return this._dataView.getUint32(byteOffset, true);
  2544. }
  2545. else {
  2546. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2547. throw new Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2548. }
  2549. };
  2550. _BinaryWriter.prototype.getVector3Float32FromRef = function (vector3, byteOffset) {
  2551. if (byteOffset + 8 > this._byteOffset) {
  2552. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2553. }
  2554. else {
  2555. vector3.x = this._dataView.getFloat32(byteOffset, true);
  2556. vector3.y = this._dataView.getFloat32(byteOffset + 4, true);
  2557. vector3.z = this._dataView.getFloat32(byteOffset + 8, true);
  2558. }
  2559. };
  2560. _BinaryWriter.prototype.setVector3Float32FromRef = function (vector3, byteOffset) {
  2561. if (byteOffset + 8 > this._byteOffset) {
  2562. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2563. }
  2564. else {
  2565. this._dataView.setFloat32(byteOffset, vector3.x, true);
  2566. this._dataView.setFloat32(byteOffset + 4, vector3.y, true);
  2567. this._dataView.setFloat32(byteOffset + 8, vector3.z, true);
  2568. }
  2569. };
  2570. _BinaryWriter.prototype.getVector4Float32FromRef = function (vector4, byteOffset) {
  2571. if (byteOffset + 12 > this._byteOffset) {
  2572. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2573. }
  2574. else {
  2575. vector4.x = this._dataView.getFloat32(byteOffset, true);
  2576. vector4.y = this._dataView.getFloat32(byteOffset + 4, true);
  2577. vector4.z = this._dataView.getFloat32(byteOffset + 8, true);
  2578. vector4.w = this._dataView.getFloat32(byteOffset + 12, true);
  2579. }
  2580. };
  2581. _BinaryWriter.prototype.setVector4Float32FromRef = function (vector4, byteOffset) {
  2582. if (byteOffset + 12 > this._byteOffset) {
  2583. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2584. }
  2585. else {
  2586. this._dataView.setFloat32(byteOffset, vector4.x, true);
  2587. this._dataView.setFloat32(byteOffset + 4, vector4.y, true);
  2588. this._dataView.setFloat32(byteOffset + 8, vector4.z, true);
  2589. this._dataView.setFloat32(byteOffset + 12, vector4.w, true);
  2590. }
  2591. };
  2592. /**
  2593. * Stores a Float32 in the array buffer
  2594. * @param entry
  2595. */
  2596. _BinaryWriter.prototype.setFloat32 = function (entry, byteOffset) {
  2597. if (isNaN(entry)) {
  2598. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('Invalid data being written!');
  2599. }
  2600. if (byteOffset != null) {
  2601. if (byteOffset < this._byteOffset) {
  2602. this._dataView.setFloat32(byteOffset, entry, true);
  2603. }
  2604. else {
  2605. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary length!');
  2606. }
  2607. }
  2608. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  2609. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2610. }
  2611. this._dataView.setFloat32(this._byteOffset, entry, true);
  2612. this._byteOffset += 4;
  2613. };
  2614. /**
  2615. * Stores an UInt32 in the array buffer
  2616. * @param entry
  2617. * @param byteOffset If defined, specifies where to set the value as an offset.
  2618. */
  2619. _BinaryWriter.prototype.setUInt32 = function (entry, byteOffset) {
  2620. if (byteOffset != null) {
  2621. if (byteOffset < this._byteOffset) {
  2622. this._dataView.setUint32(byteOffset, entry, true);
  2623. }
  2624. else {
  2625. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2626. }
  2627. }
  2628. else {
  2629. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  2630. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2631. }
  2632. this._dataView.setUint32(this._byteOffset, entry, true);
  2633. this._byteOffset += 4;
  2634. }
  2635. };
  2636. return _BinaryWriter;
  2637. }());
  2638. /***/ }),
  2639. /***/ "./glTF/2.0/glTFExporterExtension.ts":
  2640. /*!*******************************************!*\
  2641. !*** ./glTF/2.0/glTFExporterExtension.ts ***!
  2642. \*******************************************/
  2643. /*! exports provided: __IGLTFExporterExtensionV2 */
  2644. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2645. "use strict";
  2646. __webpack_require__.r(__webpack_exports__);
  2647. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return __IGLTFExporterExtensionV2; });
  2648. /** @hidden */
  2649. var __IGLTFExporterExtensionV2 = 0; // I am here to allow dts to be created
  2650. /***/ }),
  2651. /***/ "./glTF/2.0/glTFMaterialExporter.ts":
  2652. /*!******************************************!*\
  2653. !*** ./glTF/2.0/glTFMaterialExporter.ts ***!
  2654. \******************************************/
  2655. /*! exports provided: _GLTFMaterialExporter */
  2656. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2657. "use strict";
  2658. __webpack_require__.r(__webpack_exports__);
  2659. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _GLTFMaterialExporter; });
  2660. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  2661. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  2662. /**
  2663. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  2664. * @hidden
  2665. */
  2666. var _GLTFMaterialExporter = /** @class */ (function () {
  2667. function _GLTFMaterialExporter(exporter) {
  2668. /**
  2669. * Mapping to store textures
  2670. */
  2671. this._textureMap = {};
  2672. this._textureMap = {};
  2673. this._exporter = exporter;
  2674. }
  2675. /**
  2676. * Specifies if two colors are approximately equal in value
  2677. * @param color1 first color to compare to
  2678. * @param color2 second color to compare to
  2679. * @param epsilon threshold value
  2680. */
  2681. _GLTFMaterialExporter.FuzzyEquals = function (color1, color2, epsilon) {
  2682. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.r, color2.r, epsilon) &&
  2683. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.g, color2.g, epsilon) &&
  2684. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.b, color2.b, epsilon);
  2685. };
  2686. /**
  2687. * Gets the materials from a Babylon scene and converts them to glTF materials
  2688. * @param scene babylonjs scene
  2689. * @param mimeType texture mime type
  2690. * @param images array of images
  2691. * @param textures array of textures
  2692. * @param materials array of materials
  2693. * @param imageData mapping of texture names to base64 textures
  2694. * @param hasTextureCoords specifies if texture coordinates are present on the material
  2695. */
  2696. _GLTFMaterialExporter.prototype._convertMaterialsToGLTFAsync = function (babylonMaterials, mimeType, hasTextureCoords) {
  2697. var promises = [];
  2698. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  2699. var babylonMaterial = babylonMaterials_1[_i];
  2700. if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"]) {
  2701. promises.push(this._convertStandardMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2702. }
  2703. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMetallicRoughnessMaterial"]) {
  2704. promises.push(this._convertPBRMetallicRoughnessMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2705. }
  2706. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"]) {
  2707. promises.push(this._convertPBRMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2708. }
  2709. else {
  2710. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unsupported material type: " + babylonMaterial.name);
  2711. }
  2712. }
  2713. return Promise.all(promises).then(function () { });
  2714. };
  2715. /**
  2716. * Makes a copy of the glTF material without the texture parameters
  2717. * @param originalMaterial original glTF material
  2718. * @returns glTF material without texture parameters
  2719. */
  2720. _GLTFMaterialExporter.prototype._stripTexturesFromMaterial = function (originalMaterial) {
  2721. var newMaterial = {};
  2722. if (originalMaterial) {
  2723. newMaterial.name = originalMaterial.name;
  2724. newMaterial.doubleSided = originalMaterial.doubleSided;
  2725. newMaterial.alphaMode = originalMaterial.alphaMode;
  2726. newMaterial.alphaCutoff = originalMaterial.alphaCutoff;
  2727. newMaterial.emissiveFactor = originalMaterial.emissiveFactor;
  2728. var originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;
  2729. if (originalPBRMetallicRoughness) {
  2730. newMaterial.pbrMetallicRoughness = {};
  2731. newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;
  2732. newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;
  2733. newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;
  2734. }
  2735. }
  2736. return newMaterial;
  2737. };
  2738. /**
  2739. * Specifies if the material has any texture parameters present
  2740. * @param material glTF Material
  2741. * @returns boolean specifying if texture parameters are present
  2742. */
  2743. _GLTFMaterialExporter.prototype._hasTexturesPresent = function (material) {
  2744. if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {
  2745. return true;
  2746. }
  2747. var pbrMat = material.pbrMetallicRoughness;
  2748. if (pbrMat) {
  2749. if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {
  2750. return true;
  2751. }
  2752. }
  2753. return false;
  2754. };
  2755. /**
  2756. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  2757. * @param babylonStandardMaterial
  2758. * @returns glTF Metallic Roughness Material representation
  2759. */
  2760. _GLTFMaterialExporter.prototype._convertToGLTFPBRMetallicRoughness = function (babylonStandardMaterial) {
  2761. var P0 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 1);
  2762. var P1 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 0.1);
  2763. var P2 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 0.1);
  2764. var P3 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1300, 0.1);
  2765. /**
  2766. * Given the control points, solve for x based on a given t for a cubic bezier curve
  2767. * @param t a value between 0 and 1
  2768. * @param p0 first control point
  2769. * @param p1 second control point
  2770. * @param p2 third control point
  2771. * @param p3 fourth control point
  2772. * @returns number result of cubic bezier curve at the specified t
  2773. */
  2774. function _cubicBezierCurve(t, p0, p1, p2, p3) {
  2775. return ((1 - t) * (1 - t) * (1 - t) * p0 +
  2776. 3 * (1 - t) * (1 - t) * t * p1 +
  2777. 3 * (1 - t) * t * t * p2 +
  2778. t * t * t * p3);
  2779. }
  2780. /**
  2781. * Evaluates a specified specular power value to determine the appropriate roughness value,
  2782. * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)
  2783. * and roughness on the ordinant axis (y-axis)
  2784. * @param specularPower specular power of standard material
  2785. * @returns Number representing the roughness value
  2786. */
  2787. function _solveForRoughness(specularPower) {
  2788. var t = Math.pow(specularPower / P3.x, 0.333333);
  2789. return _cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);
  2790. }
  2791. var diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace().scale(0.5);
  2792. var opacity = babylonStandardMaterial.alpha;
  2793. var specularPower = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);
  2794. var roughness = _solveForRoughness(specularPower);
  2795. var glTFPbrMetallicRoughness = {
  2796. baseColorFactor: [
  2797. diffuse.r,
  2798. diffuse.g,
  2799. diffuse.b,
  2800. opacity
  2801. ],
  2802. metallicFactor: 0,
  2803. roughnessFactor: roughness,
  2804. };
  2805. return glTFPbrMetallicRoughness;
  2806. };
  2807. /**
  2808. * Computes the metallic factor
  2809. * @param diffuse diffused value
  2810. * @param specular specular value
  2811. * @param oneMinusSpecularStrength one minus the specular strength
  2812. * @returns metallic value
  2813. */
  2814. _GLTFMaterialExporter._SolveMetallic = function (diffuse, specular, oneMinusSpecularStrength) {
  2815. if (specular < this._DielectricSpecular.r) {
  2816. this._DielectricSpecular;
  2817. return 0;
  2818. }
  2819. var a = this._DielectricSpecular.r;
  2820. var b = diffuse * oneMinusSpecularStrength / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;
  2821. var c = this._DielectricSpecular.r - specular;
  2822. var D = b * b - 4.0 * a * c;
  2823. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);
  2824. };
  2825. /**
  2826. * Gets the glTF alpha mode from the Babylon Material
  2827. * @param babylonMaterial Babylon Material
  2828. * @returns The Babylon alpha mode value
  2829. */
  2830. _GLTFMaterialExporter.prototype._getAlphaMode = function (babylonMaterial) {
  2831. if (babylonMaterial.needAlphaBlending()) {
  2832. return "BLEND" /* BLEND */;
  2833. }
  2834. else if (babylonMaterial.needAlphaTesting()) {
  2835. return "MASK" /* MASK */;
  2836. }
  2837. else {
  2838. return "OPAQUE" /* OPAQUE */;
  2839. }
  2840. };
  2841. /**
  2842. * Converts a Babylon Standard Material to a glTF Material
  2843. * @param babylonStandardMaterial BJS Standard Material
  2844. * @param mimeType mime type to use for the textures
  2845. * @param images array of glTF image interfaces
  2846. * @param textures array of glTF texture interfaces
  2847. * @param materials array of glTF material interfaces
  2848. * @param imageData map of image file name to data
  2849. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  2850. */
  2851. _GLTFMaterialExporter.prototype._convertStandardMaterialAsync = function (babylonStandardMaterial, mimeType, hasTextureCoords) {
  2852. var materialMap = this._exporter._materialMap;
  2853. var materials = this._exporter._materials;
  2854. var alphaMode = this._getAlphaMode(babylonStandardMaterial);
  2855. var promises = [];
  2856. var glTFPbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);
  2857. var glTFMaterial = { name: babylonStandardMaterial.name };
  2858. if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {
  2859. if (!babylonStandardMaterial.twoSidedLighting) {
  2860. 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.");
  2861. }
  2862. glTFMaterial.doubleSided = true;
  2863. }
  2864. if (hasTextureCoords) {
  2865. if (babylonStandardMaterial.diffuseTexture) {
  2866. promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then(function (glTFTexture) {
  2867. if (glTFTexture) {
  2868. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  2869. }
  2870. }));
  2871. }
  2872. if (babylonStandardMaterial.bumpTexture) {
  2873. promises.push(this._exportTextureAsync(babylonStandardMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  2874. if (glTFTexture) {
  2875. glTFMaterial.normalTexture = glTFTexture;
  2876. if (babylonStandardMaterial.bumpTexture != null && babylonStandardMaterial.bumpTexture.level !== 1) {
  2877. glTFMaterial.normalTexture.scale = babylonStandardMaterial.bumpTexture.level;
  2878. }
  2879. }
  2880. }));
  2881. }
  2882. if (babylonStandardMaterial.emissiveTexture) {
  2883. glTFMaterial.emissiveFactor = [1.0, 1.0, 1.0];
  2884. promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then(function (glTFEmissiveTexture) {
  2885. if (glTFEmissiveTexture) {
  2886. glTFMaterial.emissiveTexture = glTFEmissiveTexture;
  2887. }
  2888. }));
  2889. }
  2890. if (babylonStandardMaterial.ambientTexture) {
  2891. promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  2892. if (glTFTexture) {
  2893. var occlusionTexture = {
  2894. index: glTFTexture.index
  2895. };
  2896. glTFMaterial.occlusionTexture = occlusionTexture;
  2897. occlusionTexture.strength = 1.0;
  2898. }
  2899. }));
  2900. }
  2901. }
  2902. if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {
  2903. if (babylonStandardMaterial.alphaMode === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"].ALPHA_COMBINE) {
  2904. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  2905. }
  2906. else {
  2907. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(babylonStandardMaterial.name + ": glTF 2.0 does not support alpha mode: " + babylonStandardMaterial.alphaMode.toString());
  2908. }
  2909. }
  2910. if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter.FuzzyEquals(babylonStandardMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  2911. glTFMaterial.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();
  2912. }
  2913. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  2914. if (alphaMode !== "OPAQUE" /* OPAQUE */) {
  2915. switch (alphaMode) {
  2916. case "BLEND" /* BLEND */: {
  2917. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  2918. break;
  2919. }
  2920. case "MASK" /* MASK */: {
  2921. glTFMaterial.alphaMode = "MASK" /* MASK */;
  2922. glTFMaterial.alphaCutoff = babylonStandardMaterial.alphaCutOff;
  2923. break;
  2924. }
  2925. default: {
  2926. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unsupported alpha mode " + alphaMode);
  2927. }
  2928. }
  2929. }
  2930. materials.push(glTFMaterial);
  2931. materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;
  2932. return Promise.all(promises).then(function () { });
  2933. };
  2934. /**
  2935. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  2936. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  2937. * @param mimeType mime type to use for the textures
  2938. * @param images array of glTF image interfaces
  2939. * @param textures array of glTF texture interfaces
  2940. * @param materials array of glTF material interfaces
  2941. * @param imageData map of image file name to data
  2942. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  2943. */
  2944. _GLTFMaterialExporter.prototype._convertPBRMetallicRoughnessMaterialAsync = function (babylonPBRMetalRoughMaterial, mimeType, hasTextureCoords) {
  2945. var materialMap = this._exporter._materialMap;
  2946. var materials = this._exporter._materials;
  2947. var promises = [];
  2948. var glTFPbrMetallicRoughness = {};
  2949. if (babylonPBRMetalRoughMaterial.baseColor) {
  2950. glTFPbrMetallicRoughness.baseColorFactor = [
  2951. babylonPBRMetalRoughMaterial.baseColor.r,
  2952. babylonPBRMetalRoughMaterial.baseColor.g,
  2953. babylonPBRMetalRoughMaterial.baseColor.b,
  2954. babylonPBRMetalRoughMaterial.alpha
  2955. ];
  2956. }
  2957. if (babylonPBRMetalRoughMaterial.metallic != null && babylonPBRMetalRoughMaterial.metallic !== 1) {
  2958. glTFPbrMetallicRoughness.metallicFactor = babylonPBRMetalRoughMaterial.metallic;
  2959. }
  2960. if (babylonPBRMetalRoughMaterial.roughness != null && babylonPBRMetalRoughMaterial.roughness !== 1) {
  2961. glTFPbrMetallicRoughness.roughnessFactor = babylonPBRMetalRoughMaterial.roughness;
  2962. }
  2963. var glTFMaterial = {
  2964. name: babylonPBRMetalRoughMaterial.name
  2965. };
  2966. if (babylonPBRMetalRoughMaterial.doubleSided) {
  2967. glTFMaterial.doubleSided = babylonPBRMetalRoughMaterial.doubleSided;
  2968. }
  2969. var alphaMode = null;
  2970. if (babylonPBRMetalRoughMaterial.transparencyMode != null) {
  2971. alphaMode = this._getAlphaMode(babylonPBRMetalRoughMaterial);
  2972. if (alphaMode) {
  2973. if (alphaMode !== "OPAQUE" /* OPAQUE */) { //glTF defaults to opaque
  2974. glTFMaterial.alphaMode = alphaMode;
  2975. if (alphaMode === "MASK" /* MASK */) {
  2976. glTFMaterial.alphaCutoff = babylonPBRMetalRoughMaterial.alphaCutOff;
  2977. }
  2978. }
  2979. }
  2980. }
  2981. if (hasTextureCoords) {
  2982. if (babylonPBRMetalRoughMaterial.baseTexture != null) {
  2983. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.baseTexture, mimeType).then(function (glTFTexture) {
  2984. if (glTFTexture) {
  2985. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  2986. }
  2987. }));
  2988. }
  2989. if (babylonPBRMetalRoughMaterial.normalTexture) {
  2990. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.normalTexture, mimeType).then(function (glTFTexture) {
  2991. if (glTFTexture) {
  2992. glTFMaterial.normalTexture = glTFTexture;
  2993. if (babylonPBRMetalRoughMaterial.normalTexture.level !== 1) {
  2994. glTFMaterial.normalTexture.scale = babylonPBRMetalRoughMaterial.normalTexture.level;
  2995. }
  2996. }
  2997. }));
  2998. }
  2999. if (babylonPBRMetalRoughMaterial.occlusionTexture) {
  3000. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.occlusionTexture, mimeType).then(function (glTFTexture) {
  3001. if (glTFTexture) {
  3002. glTFMaterial.occlusionTexture = glTFTexture;
  3003. if (babylonPBRMetalRoughMaterial.occlusionStrength != null) {
  3004. glTFMaterial.occlusionTexture.strength = babylonPBRMetalRoughMaterial.occlusionStrength;
  3005. }
  3006. }
  3007. }));
  3008. }
  3009. if (babylonPBRMetalRoughMaterial.emissiveTexture) {
  3010. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  3011. if (glTFTexture) {
  3012. glTFMaterial.emissiveTexture = glTFTexture;
  3013. }
  3014. }));
  3015. }
  3016. }
  3017. if (_GLTFMaterialExporter.FuzzyEquals(babylonPBRMetalRoughMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  3018. glTFMaterial.emissiveFactor = babylonPBRMetalRoughMaterial.emissiveColor.asArray();
  3019. }
  3020. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  3021. materials.push(glTFMaterial);
  3022. materialMap[babylonPBRMetalRoughMaterial.uniqueId] = materials.length - 1;
  3023. return Promise.all(promises).then(function () { });
  3024. };
  3025. /**
  3026. * Converts an image typed array buffer to a base64 image
  3027. * @param buffer typed array buffer
  3028. * @param width width of the image
  3029. * @param height height of the image
  3030. * @param mimeType mimetype of the image
  3031. * @returns base64 image string
  3032. */
  3033. _GLTFMaterialExporter.prototype._createBase64FromCanvasAsync = function (buffer, width, height, mimeType) {
  3034. var _this = this;
  3035. return new Promise(function (resolve, reject) {
  3036. var hostingScene;
  3037. var textureType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"].TEXTURETYPE_UNSIGNED_INT;
  3038. var engine = _this._exporter._getLocalEngine();
  3039. hostingScene = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scene"](engine);
  3040. // Create a temporary texture with the texture buffer data
  3041. 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);
  3042. 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);
  3043. postProcess.getEffect().executeWhenCompiled(function () {
  3044. postProcess.onApply = function (effect) {
  3045. effect._bindTexture("textureSampler", tempTexture);
  3046. };
  3047. // Set the size of the texture
  3048. engine.setSize(width, height);
  3049. hostingScene.postProcessManager.directRender([postProcess], null);
  3050. postProcess.dispose();
  3051. tempTexture.dispose();
  3052. // Read data from WebGL
  3053. var canvas = engine.getRenderingCanvas();
  3054. if (canvas) {
  3055. if (!canvas.toBlob) { // fallback for browsers without "canvas.toBlob"
  3056. var dataURL = canvas.toDataURL();
  3057. resolve(dataURL);
  3058. }
  3059. else {
  3060. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToBlob(canvas, function (blob) {
  3061. if (blob) {
  3062. var fileReader = new FileReader();
  3063. fileReader.onload = function (event) {
  3064. var base64String = event.target.result;
  3065. hostingScene.dispose();
  3066. resolve(base64String);
  3067. };
  3068. fileReader.readAsDataURL(blob);
  3069. }
  3070. else {
  3071. reject("gltfMaterialExporter: Failed to get blob from image canvas!");
  3072. }
  3073. });
  3074. }
  3075. }
  3076. else {
  3077. reject("Engine is missing a canvas!");
  3078. }
  3079. });
  3080. });
  3081. };
  3082. /**
  3083. * Generates a white texture based on the specified width and height
  3084. * @param width width of the texture in pixels
  3085. * @param height height of the texture in pixels
  3086. * @param scene babylonjs scene
  3087. * @returns white texture
  3088. */
  3089. _GLTFMaterialExporter.prototype._createWhiteTexture = function (width, height, scene) {
  3090. var data = new Uint8Array(width * height * 4);
  3091. for (var i = 0; i < data.length; i = i + 4) {
  3092. data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xFF;
  3093. }
  3094. var rawTexture = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["RawTexture"].CreateRGBATexture(data, width, height, scene);
  3095. return rawTexture;
  3096. };
  3097. /**
  3098. * 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
  3099. * @param texture1 first texture to resize
  3100. * @param texture2 second texture to resize
  3101. * @param scene babylonjs scene
  3102. * @returns resized textures or null
  3103. */
  3104. _GLTFMaterialExporter.prototype._resizeTexturesToSameDimensions = function (texture1, texture2, scene) {
  3105. var texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };
  3106. var texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };
  3107. var resizedTexture1;
  3108. var resizedTexture2;
  3109. if (texture1Size.width < texture2Size.width) {
  3110. if (texture1 && texture1 instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"]) {
  3111. resizedTexture1 = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TextureTools"].CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);
  3112. }
  3113. else {
  3114. resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);
  3115. }
  3116. resizedTexture2 = texture2;
  3117. }
  3118. else if (texture1Size.width > texture2Size.width) {
  3119. if (texture2 && texture2 instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"]) {
  3120. resizedTexture2 = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TextureTools"].CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);
  3121. }
  3122. else {
  3123. resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);
  3124. }
  3125. resizedTexture1 = texture1;
  3126. }
  3127. else {
  3128. resizedTexture1 = texture1;
  3129. resizedTexture2 = texture2;
  3130. }
  3131. return {
  3132. "texture1": resizedTexture1,
  3133. "texture2": resizedTexture2
  3134. };
  3135. };
  3136. /**
  3137. * Converts an array of pixels to a Float32Array
  3138. * Throws an error if the pixel format is not supported
  3139. * @param pixels - array buffer containing pixel values
  3140. * @returns Float32 of pixels
  3141. */
  3142. _GLTFMaterialExporter.prototype._convertPixelArrayToFloat32 = function (pixels) {
  3143. if (pixels instanceof Uint8Array) {
  3144. var length_1 = pixels.length;
  3145. var buffer = new Float32Array(pixels.length);
  3146. for (var i = 0; i < length_1; ++i) {
  3147. buffer[i] = pixels[i] / 255;
  3148. }
  3149. return buffer;
  3150. }
  3151. else if (pixels instanceof Float32Array) {
  3152. return pixels;
  3153. }
  3154. else {
  3155. throw new Error('Unsupported pixel format!');
  3156. }
  3157. };
  3158. /**
  3159. * Convert Specular Glossiness Textures to Metallic Roughness
  3160. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  3161. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  3162. * @param diffuseTexture texture used to store diffuse information
  3163. * @param specularGlossinessTexture texture used to store specular and glossiness information
  3164. * @param factors specular glossiness material factors
  3165. * @param mimeType the mime type to use for the texture
  3166. * @returns pbr metallic roughness interface or null
  3167. */
  3168. _GLTFMaterialExporter.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync = function (diffuseTexture, specularGlossinessTexture, factors, mimeType) {
  3169. var promises = [];
  3170. if (!(diffuseTexture || specularGlossinessTexture)) {
  3171. return Promise.reject('_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!');
  3172. }
  3173. var scene = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;
  3174. if (scene) {
  3175. var resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);
  3176. var diffuseSize = resizedTextures.texture1.getSize();
  3177. var diffuseBuffer = void 0;
  3178. var specularGlossinessBuffer = void 0;
  3179. var width = diffuseSize.width;
  3180. var height = diffuseSize.height;
  3181. var diffusePixels = resizedTextures.texture1.readPixels();
  3182. var specularPixels = resizedTextures.texture2.readPixels();
  3183. if (diffusePixels) {
  3184. diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);
  3185. }
  3186. else {
  3187. return Promise.reject("Failed to retrieve pixels from diffuse texture!");
  3188. }
  3189. if (specularPixels) {
  3190. specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);
  3191. }
  3192. else {
  3193. return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");
  3194. }
  3195. var byteLength = specularGlossinessBuffer.byteLength;
  3196. var metallicRoughnessBuffer = new Uint8Array(byteLength);
  3197. var baseColorBuffer = new Uint8Array(byteLength);
  3198. var strideSize = 4;
  3199. var maxBaseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  3200. var maxMetallic = 0;
  3201. var maxRoughness = 0;
  3202. for (var h = 0; h < height; ++h) {
  3203. for (var w = 0; w < width; ++w) {
  3204. var offset = (width * h + w) * strideSize;
  3205. var diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2]).toLinearSpace().multiply(factors.diffuseColor);
  3206. var specularColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2]).toLinearSpace().multiply(factors.specularColor);
  3207. var glossiness = (specularGlossinessBuffer[offset + 3]) * factors.glossiness;
  3208. var specularGlossiness = {
  3209. diffuseColor: diffuseColor,
  3210. specularColor: specularColor,
  3211. glossiness: glossiness
  3212. };
  3213. var metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);
  3214. maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);
  3215. maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);
  3216. maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);
  3217. maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic);
  3218. maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness);
  3219. baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;
  3220. baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;
  3221. baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;
  3222. baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;
  3223. metallicRoughnessBuffer[offset] = 0;
  3224. metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness * 255;
  3225. metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic * 255;
  3226. metallicRoughnessBuffer[offset + 3] = 255;
  3227. }
  3228. }
  3229. // Retrieves the metallic roughness factors from the maximum texture values.
  3230. var metallicRoughnessFactors_1 = {
  3231. baseColor: maxBaseColor,
  3232. metallic: maxMetallic,
  3233. roughness: maxRoughness
  3234. };
  3235. var writeOutMetallicRoughnessTexture = false;
  3236. var writeOutBaseColorTexture = false;
  3237. for (var h = 0; h < height; ++h) {
  3238. for (var w = 0; w < width; ++w) {
  3239. var destinationOffset = (width * h + w) * strideSize;
  3240. baseColorBuffer[destinationOffset] /= metallicRoughnessFactors_1.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.r : 1;
  3241. baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.g : 1;
  3242. baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.b : 1;
  3243. var linearBaseColorPixel = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromInts(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);
  3244. var sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace();
  3245. baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;
  3246. baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;
  3247. baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;
  3248. if (!_GLTFMaterialExporter.FuzzyEquals(sRGBBaseColorPixel, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  3249. writeOutBaseColorTexture = true;
  3250. }
  3251. metallicRoughnessBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.roughness > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.roughness : 1;
  3252. metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.metallic > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.metallic : 1;
  3253. var metallicRoughnessPixel = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);
  3254. if (!_GLTFMaterialExporter.FuzzyEquals(metallicRoughnessPixel, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  3255. writeOutMetallicRoughnessTexture = true;
  3256. }
  3257. }
  3258. }
  3259. if (writeOutMetallicRoughnessTexture) {
  3260. var promise = this._createBase64FromCanvasAsync(metallicRoughnessBuffer, width, height, mimeType).then(function (metallicRoughnessBase64) {
  3261. metallicRoughnessFactors_1.metallicRoughnessTextureBase64 = metallicRoughnessBase64;
  3262. });
  3263. promises.push(promise);
  3264. }
  3265. if (writeOutBaseColorTexture) {
  3266. var promise = this._createBase64FromCanvasAsync(baseColorBuffer, width, height, mimeType).then(function (baseColorBase64) {
  3267. metallicRoughnessFactors_1.baseColorTextureBase64 = baseColorBase64;
  3268. });
  3269. promises.push(promise);
  3270. }
  3271. return Promise.all(promises).then(function () {
  3272. return metallicRoughnessFactors_1;
  3273. });
  3274. }
  3275. else {
  3276. return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");
  3277. }
  3278. };
  3279. /**
  3280. * Converts specular glossiness material properties to metallic roughness
  3281. * @param specularGlossiness interface with specular glossiness material properties
  3282. * @returns interface with metallic roughness material properties
  3283. */
  3284. _GLTFMaterialExporter.prototype._convertSpecularGlossinessToMetallicRoughness = function (specularGlossiness) {
  3285. var diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);
  3286. var specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);
  3287. var oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);
  3288. var metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);
  3289. var baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon));
  3290. var baseColorFromSpecular = specularGlossiness.specularColor.subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic)).scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));
  3291. var baseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);
  3292. baseColor = baseColor.clampToRef(0, 1, baseColor);
  3293. var metallicRoughness = {
  3294. baseColor: baseColor,
  3295. metallic: metallic,
  3296. roughness: 1 - specularGlossiness.glossiness
  3297. };
  3298. return metallicRoughness;
  3299. };
  3300. /**
  3301. * Calculates the surface reflectance, independent of lighting conditions
  3302. * @param color Color source to calculate brightness from
  3303. * @returns number representing the perceived brightness, or zero if color is undefined
  3304. */
  3305. _GLTFMaterialExporter.prototype._getPerceivedBrightness = function (color) {
  3306. if (color) {
  3307. return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);
  3308. }
  3309. return 0;
  3310. };
  3311. /**
  3312. * Returns the maximum color component value
  3313. * @param color
  3314. * @returns maximum color component value, or zero if color is null or undefined
  3315. */
  3316. _GLTFMaterialExporter.prototype._getMaxComponent = function (color) {
  3317. if (color) {
  3318. return Math.max(color.r, Math.max(color.g, color.b));
  3319. }
  3320. return 0;
  3321. };
  3322. /**
  3323. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  3324. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3325. * @param mimeType mime type to use for the textures
  3326. * @param images array of glTF image interfaces
  3327. * @param textures array of glTF texture interfaces
  3328. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  3329. * @param imageData map of image file name to data
  3330. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3331. * @returns glTF PBR Metallic Roughness factors
  3332. */
  3333. _GLTFMaterialExporter.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  3334. var promises = [];
  3335. var metallicRoughness = {
  3336. baseColor: babylonPBRMaterial.albedoColor,
  3337. metallic: babylonPBRMaterial.metallic,
  3338. roughness: babylonPBRMaterial.roughness
  3339. };
  3340. if (hasTextureCoords) {
  3341. if (babylonPBRMaterial.albedoTexture) {
  3342. promises.push(this._exportTextureAsync(babylonPBRMaterial.albedoTexture, mimeType).then(function (glTFTexture) {
  3343. if (glTFTexture) {
  3344. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  3345. }
  3346. }));
  3347. }
  3348. if (babylonPBRMaterial.metallicTexture) {
  3349. promises.push(this._exportTextureAsync(babylonPBRMaterial.metallicTexture, mimeType).then(function (glTFTexture) {
  3350. if (glTFTexture) {
  3351. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;
  3352. }
  3353. }));
  3354. }
  3355. }
  3356. return Promise.all(promises).then(function () {
  3357. return metallicRoughness;
  3358. });
  3359. };
  3360. _GLTFMaterialExporter.prototype._getGLTFTextureSampler = function (texture) {
  3361. var sampler = this._getGLTFTextureWrapModesSampler(texture);
  3362. var samplingMode = texture instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"] ? texture.samplingMode : null;
  3363. if (samplingMode != null) {
  3364. switch (samplingMode) {
  3365. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR: {
  3366. sampler.magFilter = 9729 /* LINEAR */;
  3367. sampler.minFilter = 9729 /* LINEAR */;
  3368. break;
  3369. }
  3370. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST: {
  3371. sampler.magFilter = 9729 /* LINEAR */;
  3372. sampler.minFilter = 9728 /* NEAREST */;
  3373. break;
  3374. }
  3375. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR: {
  3376. sampler.magFilter = 9728 /* NEAREST */;
  3377. sampler.minFilter = 9729 /* LINEAR */;
  3378. break;
  3379. }
  3380. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR: {
  3381. sampler.magFilter = 9728 /* NEAREST */;
  3382. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  3383. break;
  3384. }
  3385. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST: {
  3386. sampler.magFilter = 9728 /* NEAREST */;
  3387. sampler.minFilter = 9728 /* NEAREST */;
  3388. break;
  3389. }
  3390. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST: {
  3391. sampler.magFilter = 9728 /* NEAREST */;
  3392. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  3393. break;
  3394. }
  3395. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST: {
  3396. sampler.magFilter = 9729 /* LINEAR */;
  3397. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  3398. break;
  3399. }
  3400. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR: {
  3401. sampler.magFilter = 9729 /* LINEAR */;
  3402. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  3403. break;
  3404. }
  3405. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR: {
  3406. sampler.magFilter = 9728 /* NEAREST */;
  3407. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  3408. break;
  3409. }
  3410. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR: {
  3411. sampler.magFilter = 9729 /* LINEAR */;
  3412. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  3413. break;
  3414. }
  3415. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST: {
  3416. sampler.magFilter = 9729 /* LINEAR */;
  3417. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  3418. break;
  3419. }
  3420. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST: {
  3421. sampler.magFilter = 9728 /* NEAREST */;
  3422. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  3423. break;
  3424. }
  3425. }
  3426. }
  3427. return sampler;
  3428. };
  3429. _GLTFMaterialExporter.prototype._getGLTFTextureWrapMode = function (wrapMode) {
  3430. switch (wrapMode) {
  3431. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE: {
  3432. return 10497 /* REPEAT */;
  3433. }
  3434. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE: {
  3435. return 33071 /* CLAMP_TO_EDGE */;
  3436. }
  3437. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE: {
  3438. return 33648 /* MIRRORED_REPEAT */;
  3439. }
  3440. default: {
  3441. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported Texture Wrap Mode " + wrapMode + "!");
  3442. return 10497 /* REPEAT */;
  3443. }
  3444. }
  3445. };
  3446. _GLTFMaterialExporter.prototype._getGLTFTextureWrapModesSampler = function (texture) {
  3447. 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);
  3448. 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);
  3449. if (wrapS === 10497 /* REPEAT */ && wrapT === 10497 /* REPEAT */) { // default wrapping mode in glTF, so omitting
  3450. return {};
  3451. }
  3452. return { wrapS: wrapS, wrapT: wrapT };
  3453. };
  3454. /**
  3455. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  3456. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3457. * @param mimeType mime type to use for the textures
  3458. * @param images array of glTF image interfaces
  3459. * @param textures array of glTF texture interfaces
  3460. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  3461. * @param imageData map of image file name to data
  3462. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3463. * @returns glTF PBR Metallic Roughness factors
  3464. */
  3465. _GLTFMaterialExporter.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  3466. var _this = this;
  3467. return Promise.resolve().then(function () {
  3468. var samplers = _this._exporter._samplers;
  3469. var textures = _this._exporter._textures;
  3470. var specGloss = {
  3471. diffuseColor: babylonPBRMaterial.albedoColor || babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(),
  3472. specularColor: babylonPBRMaterial.reflectivityColor || babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(),
  3473. glossiness: babylonPBRMaterial.microSurface || 1,
  3474. };
  3475. var samplerIndex = null;
  3476. var sampler = _this._getGLTFTextureSampler(babylonPBRMaterial.albedoTexture);
  3477. if (sampler.magFilter != null && sampler.minFilter != null && sampler.wrapS != null && sampler.wrapT != null) {
  3478. samplers.push(sampler);
  3479. samplerIndex = samplers.length - 1;
  3480. }
  3481. if (babylonPBRMaterial.reflectivityTexture && !babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha) {
  3482. return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");
  3483. }
  3484. if ((babylonPBRMaterial.albedoTexture || babylonPBRMaterial.reflectivityTexture) && hasTextureCoords) {
  3485. return _this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(babylonPBRMaterial.albedoTexture, babylonPBRMaterial.reflectivityTexture, specGloss, mimeType).then(function (metallicRoughnessFactors) {
  3486. if (metallicRoughnessFactors.baseColorTextureBase64) {
  3487. var glTFBaseColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.baseColorTextureBase64, "bjsBaseColorTexture_" + (textures.length) + ".png", mimeType, babylonPBRMaterial.albedoTexture ? babylonPBRMaterial.albedoTexture.coordinatesIndex : null, samplerIndex);
  3488. if (glTFBaseColorTexture) {
  3489. glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
  3490. }
  3491. }
  3492. if (metallicRoughnessFactors.metallicRoughnessTextureBase64) {
  3493. var glTFMRColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + (textures.length) + ".png", mimeType, babylonPBRMaterial.reflectivityTexture ? babylonPBRMaterial.reflectivityTexture.coordinatesIndex : null, samplerIndex);
  3494. if (glTFMRColorTexture) {
  3495. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
  3496. }
  3497. }
  3498. return metallicRoughnessFactors;
  3499. });
  3500. }
  3501. else {
  3502. return _this._convertSpecularGlossinessToMetallicRoughness(specGloss);
  3503. }
  3504. });
  3505. };
  3506. /**
  3507. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  3508. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3509. * @param mimeType mime type to use for the textures
  3510. * @param images array of glTF image interfaces
  3511. * @param textures array of glTF texture interfaces
  3512. * @param materials array of glTF material interfaces
  3513. * @param imageData map of image file name to data
  3514. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3515. */
  3516. _GLTFMaterialExporter.prototype._convertPBRMaterialAsync = function (babylonPBRMaterial, mimeType, hasTextureCoords) {
  3517. var _this = this;
  3518. var glTFPbrMetallicRoughness = {};
  3519. var glTFMaterial = {
  3520. name: babylonPBRMaterial.name
  3521. };
  3522. var useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();
  3523. if (useMetallicRoughness) {
  3524. if (babylonPBRMaterial.albedoColor) {
  3525. glTFPbrMetallicRoughness.baseColorFactor = [
  3526. babylonPBRMaterial.albedoColor.r,
  3527. babylonPBRMaterial.albedoColor.g,
  3528. babylonPBRMaterial.albedoColor.b,
  3529. babylonPBRMaterial.alpha
  3530. ];
  3531. }
  3532. return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  3533. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  3534. });
  3535. }
  3536. else {
  3537. return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  3538. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  3539. });
  3540. }
  3541. };
  3542. _GLTFMaterialExporter.prototype.setMetallicRoughnessPbrMaterial = function (metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords) {
  3543. var materialMap = this._exporter._materialMap;
  3544. var materials = this._exporter._materials;
  3545. var promises = [];
  3546. if (metallicRoughness) {
  3547. var alphaMode = null;
  3548. if (babylonPBRMaterial.transparencyMode != null) {
  3549. alphaMode = this._getAlphaMode(babylonPBRMaterial);
  3550. if (alphaMode) {
  3551. if (alphaMode !== "OPAQUE" /* OPAQUE */) { //glTF defaults to opaque
  3552. glTFMaterial.alphaMode = alphaMode;
  3553. if (alphaMode === "MASK" /* MASK */) {
  3554. glTFMaterial.alphaCutoff = babylonPBRMaterial.alphaCutOff;
  3555. }
  3556. }
  3557. }
  3558. }
  3559. if (!(_GLTFMaterialExporter.FuzzyEquals(metallicRoughness.baseColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon) && babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon)) {
  3560. glTFPbrMetallicRoughness.baseColorFactor = [
  3561. metallicRoughness.baseColor.r,
  3562. metallicRoughness.baseColor.g,
  3563. metallicRoughness.baseColor.b,
  3564. babylonPBRMaterial.alpha
  3565. ];
  3566. }
  3567. if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {
  3568. glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;
  3569. }
  3570. if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {
  3571. glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;
  3572. }
  3573. if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {
  3574. if (!babylonPBRMaterial.twoSidedLighting) {
  3575. 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.");
  3576. }
  3577. glTFMaterial.doubleSided = true;
  3578. }
  3579. if (hasTextureCoords) {
  3580. if (babylonPBRMaterial.bumpTexture) {
  3581. var promise = this._exportTextureAsync(babylonPBRMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  3582. if (glTFTexture) {
  3583. glTFMaterial.normalTexture = glTFTexture;
  3584. if (babylonPBRMaterial.bumpTexture.level !== 1) {
  3585. glTFMaterial.normalTexture.scale = babylonPBRMaterial.bumpTexture.level;
  3586. }
  3587. }
  3588. });
  3589. promises.push(promise);
  3590. }
  3591. if (babylonPBRMaterial.ambientTexture) {
  3592. var promise = this._exportTextureAsync(babylonPBRMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  3593. if (glTFTexture) {
  3594. var occlusionTexture = {
  3595. index: glTFTexture.index
  3596. };
  3597. glTFMaterial.occlusionTexture = occlusionTexture;
  3598. if (babylonPBRMaterial.ambientTextureStrength) {
  3599. occlusionTexture.strength = babylonPBRMaterial.ambientTextureStrength;
  3600. }
  3601. }
  3602. });
  3603. promises.push(promise);
  3604. }
  3605. if (babylonPBRMaterial.emissiveTexture) {
  3606. var promise = this._exportTextureAsync(babylonPBRMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  3607. if (glTFTexture) {
  3608. glTFMaterial.emissiveTexture = glTFTexture;
  3609. }
  3610. });
  3611. promises.push(promise);
  3612. }
  3613. }
  3614. if (!_GLTFMaterialExporter.FuzzyEquals(babylonPBRMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  3615. glTFMaterial.emissiveFactor = babylonPBRMaterial.emissiveColor.asArray();
  3616. }
  3617. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  3618. materials.push(glTFMaterial);
  3619. materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;
  3620. }
  3621. return Promise.all(promises).then(function (result) { });
  3622. };
  3623. _GLTFMaterialExporter.prototype.getPixelsFromTexture = function (babylonTexture) {
  3624. var pixels = babylonTexture.textureType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"].TEXTURETYPE_UNSIGNED_INT ? babylonTexture.readPixels() : babylonTexture.readPixels();
  3625. return pixels;
  3626. };
  3627. /**
  3628. * Extracts a texture from a Babylon texture into file data and glTF data
  3629. * @param babylonTexture Babylon texture to extract
  3630. * @param mimeType Mime Type of the babylonTexture
  3631. * @return glTF texture info, or null if the texture format is not supported
  3632. */
  3633. _GLTFMaterialExporter.prototype._exportTextureAsync = function (babylonTexture, mimeType) {
  3634. var _this = this;
  3635. var extensionPromise = this._exporter._extensionsPreExportTextureAsync("exporter", babylonTexture, mimeType);
  3636. if (!extensionPromise) {
  3637. return this._exportTextureInfoAsync(babylonTexture, mimeType);
  3638. }
  3639. return extensionPromise.then(function (texture) {
  3640. if (!texture) {
  3641. return _this._exportTextureInfoAsync(babylonTexture, mimeType);
  3642. }
  3643. return _this._exportTextureInfoAsync(texture, mimeType);
  3644. });
  3645. };
  3646. _GLTFMaterialExporter.prototype._exportTextureInfoAsync = function (babylonTexture, mimeType) {
  3647. var _this = this;
  3648. return Promise.resolve().then(function () {
  3649. var textureUid = babylonTexture.uid;
  3650. if (textureUid in _this._textureMap) {
  3651. return _this._textureMap[textureUid];
  3652. }
  3653. else {
  3654. var samplers = _this._exporter._samplers;
  3655. var sampler = _this._getGLTFTextureSampler(babylonTexture);
  3656. var samplerIndex_1 = null;
  3657. // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler
  3658. var foundSamplerIndex = null;
  3659. for (var i = 0; i < samplers.length; ++i) {
  3660. var s = samplers[i];
  3661. if (s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter &&
  3662. s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT) {
  3663. foundSamplerIndex = i;
  3664. break;
  3665. }
  3666. }
  3667. if (foundSamplerIndex == null) {
  3668. samplers.push(sampler);
  3669. samplerIndex_1 = samplers.length - 1;
  3670. }
  3671. else {
  3672. samplerIndex_1 = foundSamplerIndex;
  3673. }
  3674. var pixels = _this.getPixelsFromTexture(babylonTexture);
  3675. var size = babylonTexture.getSize();
  3676. return _this._createBase64FromCanvasAsync(pixels, size.width, size.height, mimeType).then(function (base64Data) {
  3677. var textureInfo = _this._getTextureInfoFromBase64(base64Data, babylonTexture.name.replace(/\.\/|\/|\.\\|\\/g, "_"), mimeType, babylonTexture.coordinatesIndex, samplerIndex_1);
  3678. if (textureInfo) {
  3679. _this._textureMap[textureUid] = textureInfo;
  3680. }
  3681. return textureInfo;
  3682. });
  3683. }
  3684. });
  3685. };
  3686. /**
  3687. * Builds a texture from base64 string
  3688. * @param base64Texture base64 texture string
  3689. * @param baseTextureName Name to use for the texture
  3690. * @param mimeType image mime type for the texture
  3691. * @param images array of images
  3692. * @param textures array of textures
  3693. * @param imageData map of image data
  3694. * @returns glTF texture info, or null if the texture format is not supported
  3695. */
  3696. _GLTFMaterialExporter.prototype._getTextureInfoFromBase64 = function (base64Texture, baseTextureName, mimeType, texCoordIndex, samplerIndex) {
  3697. var textures = this._exporter._textures;
  3698. var images = this._exporter._images;
  3699. var imageData = this._exporter._imageData;
  3700. var textureInfo = null;
  3701. var glTFTexture = {
  3702. source: images.length,
  3703. name: baseTextureName
  3704. };
  3705. if (samplerIndex != null) {
  3706. glTFTexture.sampler = samplerIndex;
  3707. }
  3708. var binStr = atob(base64Texture.split(',')[1]);
  3709. var arrBuff = new ArrayBuffer(binStr.length);
  3710. var arr = new Uint8Array(arrBuff);
  3711. for (var i = 0, length_2 = binStr.length; i < length_2; ++i) {
  3712. arr[i] = binStr.charCodeAt(i);
  3713. }
  3714. var imageValues = { data: arr, mimeType: mimeType };
  3715. var extension = mimeType === "image/jpeg" /* JPEG */ ? '.jpeg' : '.png';
  3716. var textureName = baseTextureName + extension;
  3717. if (textureName in imageData) {
  3718. textureName = baseTextureName + "_" + babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].RandomId() + extension;
  3719. }
  3720. imageData[textureName] = imageValues;
  3721. if (mimeType === "image/jpeg" /* JPEG */ || mimeType === "image/png" /* PNG */) {
  3722. var glTFImage = {
  3723. name: baseTextureName,
  3724. uri: textureName
  3725. };
  3726. var foundIndex = null;
  3727. for (var i = 0; i < images.length; ++i) {
  3728. if (images[i].uri === textureName) {
  3729. foundIndex = i;
  3730. break;
  3731. }
  3732. }
  3733. if (foundIndex == null) {
  3734. images.push(glTFImage);
  3735. glTFTexture.source = images.length - 1;
  3736. }
  3737. else {
  3738. glTFTexture.source = foundIndex;
  3739. }
  3740. textures.push(glTFTexture);
  3741. textureInfo = {
  3742. index: textures.length - 1
  3743. };
  3744. if (texCoordIndex != null) {
  3745. textureInfo.texCoord = texCoordIndex;
  3746. }
  3747. }
  3748. else {
  3749. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported texture mime type " + mimeType);
  3750. }
  3751. return textureInfo;
  3752. };
  3753. /**
  3754. * Represents the dielectric specular values for R, G and B
  3755. */
  3756. _GLTFMaterialExporter._DielectricSpecular = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](0.04, 0.04, 0.04);
  3757. /**
  3758. * Allows the maximum specular power to be defined for material calculations
  3759. */
  3760. _GLTFMaterialExporter._MaxSpecularPower = 1024;
  3761. /**
  3762. * Numeric tolerance value
  3763. */
  3764. _GLTFMaterialExporter._Epsilon = 1e-6;
  3765. return _GLTFMaterialExporter;
  3766. }());
  3767. /***/ }),
  3768. /***/ "./glTF/2.0/glTFSerializer.ts":
  3769. /*!************************************!*\
  3770. !*** ./glTF/2.0/glTFSerializer.ts ***!
  3771. \************************************/
  3772. /*! exports provided: GLTF2Export */
  3773. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3774. "use strict";
  3775. __webpack_require__.r(__webpack_exports__);
  3776. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return GLTF2Export; });
  3777. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  3778. /**
  3779. * Class for generating glTF data from a Babylon scene.
  3780. */
  3781. var GLTF2Export = /** @class */ (function () {
  3782. function GLTF2Export() {
  3783. }
  3784. /**
  3785. * Exports the geometry of the scene to .gltf file format asynchronously
  3786. * @param scene Babylon scene with scene hierarchy information
  3787. * @param filePrefix File prefix to use when generating the glTF file
  3788. * @param options Exporter options
  3789. * @returns Returns an object with a .gltf file and associates texture names
  3790. * as keys and their data and paths as values
  3791. */
  3792. GLTF2Export.GLTFAsync = function (scene, filePrefix, options) {
  3793. return scene.whenReadyAsync().then(function () {
  3794. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  3795. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  3796. return gltfGenerator._generateGLTFAsync(glTFPrefix);
  3797. });
  3798. };
  3799. GLTF2Export._PreExportAsync = function (scene, options) {
  3800. return Promise.resolve().then(function () {
  3801. if (options && options.exportWithoutWaitingForScene) {
  3802. return Promise.resolve();
  3803. }
  3804. else {
  3805. return scene.whenReadyAsync();
  3806. }
  3807. });
  3808. };
  3809. GLTF2Export._PostExportAsync = function (scene, glTFData, options) {
  3810. return Promise.resolve().then(function () {
  3811. if (options && options.exportWithoutWaitingForScene) {
  3812. return glTFData;
  3813. }
  3814. else {
  3815. return glTFData;
  3816. }
  3817. });
  3818. };
  3819. /**
  3820. * Exports the geometry of the scene to .glb file format asychronously
  3821. * @param scene Babylon scene with scene hierarchy information
  3822. * @param filePrefix File prefix to use when generating glb file
  3823. * @param options Exporter options
  3824. * @returns Returns an object with a .glb filename as key and data as value
  3825. */
  3826. GLTF2Export.GLBAsync = function (scene, filePrefix, options) {
  3827. var _this = this;
  3828. return this._PreExportAsync(scene, options).then(function () {
  3829. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  3830. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  3831. return gltfGenerator._generateGLBAsync(glTFPrefix).then(function (glTFData) {
  3832. return _this._PostExportAsync(scene, glTFData, options);
  3833. });
  3834. });
  3835. };
  3836. return GLTF2Export;
  3837. }());
  3838. /***/ }),
  3839. /***/ "./glTF/2.0/glTFUtilities.ts":
  3840. /*!***********************************!*\
  3841. !*** ./glTF/2.0/glTFUtilities.ts ***!
  3842. \***********************************/
  3843. /*! exports provided: _GLTFUtilities */
  3844. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3845. "use strict";
  3846. __webpack_require__.r(__webpack_exports__);
  3847. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _GLTFUtilities; });
  3848. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  3849. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  3850. /**
  3851. * @hidden
  3852. */
  3853. var _GLTFUtilities = /** @class */ (function () {
  3854. function _GLTFUtilities() {
  3855. }
  3856. /**
  3857. * Creates a buffer view based on the supplied arguments
  3858. * @param bufferIndex index value of the specified buffer
  3859. * @param byteOffset byte offset value
  3860. * @param byteLength byte length of the bufferView
  3861. * @param byteStride byte distance between conequential elements
  3862. * @param name name of the buffer view
  3863. * @returns bufferView for glTF
  3864. */
  3865. _GLTFUtilities._CreateBufferView = function (bufferIndex, byteOffset, byteLength, byteStride, name) {
  3866. var bufferview = { buffer: bufferIndex, byteLength: byteLength };
  3867. if (byteOffset) {
  3868. bufferview.byteOffset = byteOffset;
  3869. }
  3870. if (name) {
  3871. bufferview.name = name;
  3872. }
  3873. if (byteStride) {
  3874. bufferview.byteStride = byteStride;
  3875. }
  3876. return bufferview;
  3877. };
  3878. /**
  3879. * Creates an accessor based on the supplied arguments
  3880. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  3881. * @param name The name of the accessor
  3882. * @param type The type of the accessor
  3883. * @param componentType The datatype of components in the attribute
  3884. * @param count The number of attributes referenced by this accessor
  3885. * @param byteOffset The offset relative to the start of the bufferView in bytes
  3886. * @param min Minimum value of each component in this attribute
  3887. * @param max Maximum value of each component in this attribute
  3888. * @returns accessor for glTF
  3889. */
  3890. _GLTFUtilities._CreateAccessor = function (bufferviewIndex, name, type, componentType, count, byteOffset, min, max) {
  3891. var accessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };
  3892. if (min != null) {
  3893. accessor.min = min;
  3894. }
  3895. if (max != null) {
  3896. accessor.max = max;
  3897. }
  3898. if (byteOffset != null) {
  3899. accessor.byteOffset = byteOffset;
  3900. }
  3901. return accessor;
  3902. };
  3903. /**
  3904. * Calculates the minimum and maximum values of an array of position floats
  3905. * @param positions Positions array of a mesh
  3906. * @param vertexStart Starting vertex offset to calculate min and max values
  3907. * @param vertexCount Number of vertices to check for min and max values
  3908. * @returns min number array and max number array
  3909. */
  3910. _GLTFUtilities._CalculateMinMaxPositions = function (positions, vertexStart, vertexCount, convertToRightHandedSystem) {
  3911. var min = [Infinity, Infinity, Infinity];
  3912. var max = [-Infinity, -Infinity, -Infinity];
  3913. var positionStrideSize = 3;
  3914. var indexOffset;
  3915. var position;
  3916. var vector;
  3917. if (vertexCount) {
  3918. for (var i = vertexStart, length_1 = vertexStart + vertexCount; i < length_1; ++i) {
  3919. indexOffset = positionStrideSize * i;
  3920. position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(positions, indexOffset);
  3921. if (convertToRightHandedSystem) {
  3922. _GLTFUtilities._GetRightHandedPositionVector3FromRef(position);
  3923. }
  3924. vector = position.asArray();
  3925. for (var j = 0; j < positionStrideSize; ++j) {
  3926. var num = vector[j];
  3927. if (num < min[j]) {
  3928. min[j] = num;
  3929. }
  3930. if (num > max[j]) {
  3931. max[j] = num;
  3932. }
  3933. ++indexOffset;
  3934. }
  3935. }
  3936. }
  3937. return { min: min, max: max };
  3938. };
  3939. /**
  3940. * Converts a new right-handed Vector3
  3941. * @param vector vector3 array
  3942. * @returns right-handed Vector3
  3943. */
  3944. _GLTFUtilities._GetRightHandedPositionVector3 = function (vector) {
  3945. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  3946. };
  3947. /**
  3948. * Converts a Vector3 to right-handed
  3949. * @param vector Vector3 to convert to right-handed
  3950. */
  3951. _GLTFUtilities._GetRightHandedPositionVector3FromRef = function (vector) {
  3952. vector.z *= -1;
  3953. };
  3954. /**
  3955. * Converts a three element number array to right-handed
  3956. * @param vector number array to convert to right-handed
  3957. */
  3958. _GLTFUtilities._GetRightHandedPositionArray3FromRef = function (vector) {
  3959. vector[2] *= -1;
  3960. };
  3961. /**
  3962. * Converts a new right-handed Vector3
  3963. * @param vector vector3 array
  3964. * @returns right-handed Vector3
  3965. */
  3966. _GLTFUtilities._GetRightHandedNormalVector3 = function (vector) {
  3967. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  3968. };
  3969. /**
  3970. * Converts a Vector3 to right-handed
  3971. * @param vector Vector3 to convert to right-handed
  3972. */
  3973. _GLTFUtilities._GetRightHandedNormalVector3FromRef = function (vector) {
  3974. vector.z *= -1;
  3975. };
  3976. /**
  3977. * Converts a three element number array to right-handed
  3978. * @param vector number array to convert to right-handed
  3979. */
  3980. _GLTFUtilities._GetRightHandedNormalArray3FromRef = function (vector) {
  3981. vector[2] *= -1;
  3982. };
  3983. /**
  3984. * Converts a Vector4 to right-handed
  3985. * @param vector Vector4 to convert to right-handed
  3986. */
  3987. _GLTFUtilities._GetRightHandedVector4FromRef = function (vector) {
  3988. vector.z *= -1;
  3989. vector.w *= -1;
  3990. };
  3991. /**
  3992. * Converts a Vector4 to right-handed
  3993. * @param vector Vector4 to convert to right-handed
  3994. */
  3995. _GLTFUtilities._GetRightHandedArray4FromRef = function (vector) {
  3996. vector[2] *= -1;
  3997. vector[3] *= -1;
  3998. };
  3999. /**
  4000. * Converts a Quaternion to right-handed
  4001. * @param quaternion Source quaternion to convert to right-handed
  4002. */
  4003. _GLTFUtilities._GetRightHandedQuaternionFromRef = function (quaternion) {
  4004. quaternion.x *= -1;
  4005. quaternion.y *= -1;
  4006. };
  4007. /**
  4008. * Converts a Quaternion to right-handed
  4009. * @param quaternion Source quaternion to convert to right-handed
  4010. */
  4011. _GLTFUtilities._GetRightHandedQuaternionArrayFromRef = function (quaternion) {
  4012. quaternion[0] *= -1;
  4013. quaternion[1] *= -1;
  4014. };
  4015. _GLTFUtilities._NormalizeTangentFromRef = function (tangent) {
  4016. var length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);
  4017. if (length > 0) {
  4018. tangent.x /= length;
  4019. tangent.y /= length;
  4020. tangent.z /= length;
  4021. }
  4022. };
  4023. return _GLTFUtilities;
  4024. }());
  4025. /***/ }),
  4026. /***/ "./glTF/2.0/index.ts":
  4027. /*!***************************!*\
  4028. !*** ./glTF/2.0/index.ts ***!
  4029. \***************************/
  4030. /*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
  4031. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4032. "use strict";
  4033. __webpack_require__.r(__webpack_exports__);
  4034. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  4035. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__["_GLTFAnimation"]; });
  4036. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  4037. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTFData__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  4038. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  4039. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_Exporter"]; });
  4040. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_BinaryWriter"]; });
  4041. /* harmony import */ var _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFExporterExtension */ "./glTF/2.0/glTFExporterExtension.ts");
  4042. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__["__IGLTFExporterExtensionV2"]; });
  4043. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  4044. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  4045. /* harmony import */ var _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  4046. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__["GLTF2Export"]; });
  4047. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  4048. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__["_GLTFUtilities"]; });
  4049. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  4050. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_texture_transform"]; });
  4051. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_lights_punctual"]; });
  4052. /***/ }),
  4053. /***/ "./glTF/2.0/shaders/textureTransform.fragment.ts":
  4054. /*!*******************************************************!*\
  4055. !*** ./glTF/2.0/shaders/textureTransform.fragment.ts ***!
  4056. \*******************************************************/
  4057. /*! exports provided: textureTransformPixelShader */
  4058. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4059. "use strict";
  4060. __webpack_require__.r(__webpack_exports__);
  4061. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textureTransformPixelShader", function() { return textureTransformPixelShader; });
  4062. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Maths/math");
  4063. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  4064. var name = 'textureTransformPixelShader';
  4065. var shader = "precision highp float;\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 textureTransformMat;\nvoid main(void) {\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;\ngl_FragColor=texture2D(textureSampler,uvTransformed);\n}";
  4066. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  4067. /** @hidden */
  4068. var textureTransformPixelShader = { name: name, shader: shader };
  4069. /***/ }),
  4070. /***/ "./glTF/glTFFileExporter.ts":
  4071. /*!**********************************!*\
  4072. !*** ./glTF/glTFFileExporter.ts ***!
  4073. \**********************************/
  4074. /*! exports provided: __IGLTFExporterExtension */
  4075. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4076. "use strict";
  4077. __webpack_require__.r(__webpack_exports__);
  4078. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return __IGLTFExporterExtension; });
  4079. /** @hidden */
  4080. var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
  4081. /***/ }),
  4082. /***/ "./glTF/index.ts":
  4083. /*!***********************!*\
  4084. !*** ./glTF/index.ts ***!
  4085. \***********************/
  4086. /*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
  4087. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4088. "use strict";
  4089. __webpack_require__.r(__webpack_exports__);
  4090. /* harmony import */ var _glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFFileExporter */ "./glTF/glTFFileExporter.ts");
  4091. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__["__IGLTFExporterExtension"]; });
  4092. /* harmony import */ var _2_0__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./2.0 */ "./glTF/2.0/index.ts");
  4093. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  4094. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["GLTF2Export"]; });
  4095. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_GLTFAnimation"]; });
  4096. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_Exporter"]; });
  4097. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_BinaryWriter"]; });
  4098. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtensionV2"]; });
  4099. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"]; });
  4100. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]; });
  4101. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  4102. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  4103. /***/ }),
  4104. /***/ "./index.ts":
  4105. /*!******************!*\
  4106. !*** ./index.ts ***!
  4107. \******************/
  4108. /*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, OBJExport, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, STLExport, KHR_texture_transform, KHR_lights_punctual */
  4109. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4110. "use strict";
  4111. __webpack_require__.r(__webpack_exports__);
  4112. /* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./OBJ */ "./OBJ/index.ts");
  4113. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJExport"]; });
  4114. /* harmony import */ var _glTF__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTF */ "./glTF/index.ts");
  4115. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtension"]; });
  4116. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  4117. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["GLTF2Export"]; });
  4118. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_GLTFAnimation"]; });
  4119. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_Exporter"]; });
  4120. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_BinaryWriter"]; });
  4121. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtensionV2"]; });
  4122. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"]; });
  4123. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]; });
  4124. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  4125. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  4126. /* harmony import */ var _stl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./stl */ "./stl/index.ts");
  4127. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _stl__WEBPACK_IMPORTED_MODULE_2__["STLExport"]; });
  4128. /***/ }),
  4129. /***/ "./legacy/legacy-glTF2Serializer.ts":
  4130. /*!******************************************!*\
  4131. !*** ./legacy/legacy-glTF2Serializer.ts ***!
  4132. \******************************************/
  4133. /*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
  4134. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4135. "use strict";
  4136. __webpack_require__.r(__webpack_exports__);
  4137. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileExporter */ "./glTF/glTFFileExporter.ts");
  4138. /* harmony import */ var _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFData */ "./glTF/2.0/glTFData.ts");
  4139. /* harmony import */ var _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0/glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  4140. /* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  4141. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  4142. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__["__IGLTFExporterExtension"]; });
  4143. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]; });
  4144. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTF2Export"]; });
  4145. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]; });
  4146. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_Exporter"]; });
  4147. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_BinaryWriter"]; });
  4148. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["__IGLTFExporterExtensionV2"]; });
  4149. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  4150. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFUtilities"]; });
  4151. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_texture_transform"]; });
  4152. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_lights_punctual"]; });
  4153. /**
  4154. * This is the entry point for the UMD module.
  4155. * The entry point for a future ESM package should be index.ts
  4156. */
  4157. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4158. if (typeof globalObject !== "undefined") {
  4159. globalObject.BABYLON = globalObject.BABYLON || {};
  4160. var BABYLON = globalObject.BABYLON;
  4161. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  4162. BABYLON.GLTF2.Exporter = BABYLON.GLTF2.Exporter || {};
  4163. BABYLON.GLTF2.Exporter.Extensions = BABYLON.GLTF2.Exporter.Extensions || {};
  4164. var keys = [];
  4165. for (var key in _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__) {
  4166. BABYLON[key] = _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__[key];
  4167. keys.push(key);
  4168. }
  4169. for (var key in _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__) {
  4170. BABYLON[key] = _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__[key];
  4171. keys.push(key);
  4172. }
  4173. for (var key in _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__) {
  4174. BABYLON[key] = _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__[key];
  4175. keys.push(key);
  4176. }
  4177. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__) {
  4178. BABYLON.GLTF2.Exporter.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__[key];
  4179. keys.push(key);
  4180. }
  4181. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__) {
  4182. // Prevent Reassignment.
  4183. if (keys.indexOf(key) > -1) {
  4184. continue;
  4185. }
  4186. BABYLON.GLTF2.Exporter[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__[key];
  4187. }
  4188. }
  4189. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4190. /***/ }),
  4191. /***/ "./legacy/legacy-objSerializer.ts":
  4192. /*!****************************************!*\
  4193. !*** ./legacy/legacy-objSerializer.ts ***!
  4194. \****************************************/
  4195. /*! exports provided: OBJExport */
  4196. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4197. "use strict";
  4198. __webpack_require__.r(__webpack_exports__);
  4199. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _OBJ__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../OBJ */ "./OBJ/index.ts");
  4200. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _OBJ__WEBPACK_IMPORTED_MODULE_0__["OBJExport"]; });
  4201. /**
  4202. * This is the entry point for the UMD module.
  4203. * The entry point for a future ESM package should be index.ts
  4204. */
  4205. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4206. if (typeof globalObject !== "undefined") {
  4207. for (var serializer in _OBJ__WEBPACK_IMPORTED_MODULE_0__) {
  4208. globalObject.BABYLON[serializer] = _OBJ__WEBPACK_IMPORTED_MODULE_0__[serializer];
  4209. }
  4210. }
  4211. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4212. /***/ }),
  4213. /***/ "./legacy/legacy-stlSerializer.ts":
  4214. /*!****************************************!*\
  4215. !*** ./legacy/legacy-stlSerializer.ts ***!
  4216. \****************************************/
  4217. /*! exports provided: STLExport */
  4218. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4219. "use strict";
  4220. __webpack_require__.r(__webpack_exports__);
  4221. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _stl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../stl */ "./stl/index.ts");
  4222. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _stl__WEBPACK_IMPORTED_MODULE_0__["STLExport"]; });
  4223. /**
  4224. * This is the entry point for the UMD module.
  4225. * The entry point for a future ESM package should be index.ts
  4226. */
  4227. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  4228. if (typeof globalObject !== "undefined") {
  4229. for (var serializer in _stl__WEBPACK_IMPORTED_MODULE_0__) {
  4230. globalObject.BABYLON[serializer] = _stl__WEBPACK_IMPORTED_MODULE_0__[serializer];
  4231. }
  4232. }
  4233. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  4234. /***/ }),
  4235. /***/ "./legacy/legacy.ts":
  4236. /*!**************************!*\
  4237. !*** ./legacy/legacy.ts ***!
  4238. \**************************/
  4239. /*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, OBJExport, STLExport, KHR_texture_transform, KHR_lights_punctual */
  4240. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4241. "use strict";
  4242. __webpack_require__.r(__webpack_exports__);
  4243. /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../index */ "./index.ts");
  4244. /* harmony import */ var _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./legacy-glTF2Serializer */ "./legacy/legacy-glTF2Serializer.ts");
  4245. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtension"]; });
  4246. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  4247. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["GLTF2Export"]; });
  4248. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_GLTFAnimation"]; });
  4249. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_Exporter"]; });
  4250. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_BinaryWriter"]; });
  4251. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["__IGLTFExporterExtensionV2"]; });
  4252. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"]; });
  4253. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["_GLTFUtilities"]; });
  4254. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
  4255. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
  4256. /* harmony import */ var _legacy_objSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-objSerializer */ "./legacy/legacy-objSerializer.ts");
  4257. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _legacy_objSerializer__WEBPACK_IMPORTED_MODULE_2__["OBJExport"]; });
  4258. /* harmony import */ var _legacy_stlSerializer__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./legacy-stlSerializer */ "./legacy/legacy-stlSerializer.ts");
  4259. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _legacy_stlSerializer__WEBPACK_IMPORTED_MODULE_3__["STLExport"]; });
  4260. /***/ }),
  4261. /***/ "./stl/index.ts":
  4262. /*!**********************!*\
  4263. !*** ./stl/index.ts ***!
  4264. \**********************/
  4265. /*! exports provided: STLExport */
  4266. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4267. "use strict";
  4268. __webpack_require__.r(__webpack_exports__);
  4269. /* harmony import */ var _stlSerializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./stlSerializer */ "./stl/stlSerializer.ts");
  4270. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return _stlSerializer__WEBPACK_IMPORTED_MODULE_0__["STLExport"]; });
  4271. /***/ }),
  4272. /***/ "./stl/stlSerializer.ts":
  4273. /*!******************************!*\
  4274. !*** ./stl/stlSerializer.ts ***!
  4275. \******************************/
  4276. /*! exports provided: STLExport */
  4277. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4278. "use strict";
  4279. __webpack_require__.r(__webpack_exports__);
  4280. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "STLExport", function() { return STLExport; });
  4281. /* harmony import */ var babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Meshes/buffer */ "babylonjs/Maths/math");
  4282. /* harmony import */ var babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__);
  4283. /**
  4284. * Class for generating STL data from a Babylon scene.
  4285. */
  4286. var STLExport = /** @class */ (function () {
  4287. function STLExport() {
  4288. }
  4289. /**
  4290. * Exports the geometry of a Mesh array in .STL file format (ASCII)
  4291. * @param meshes list defines the mesh to serialize
  4292. * @param download triggers the automatic download of the file.
  4293. * @param fileName changes the downloads fileName.
  4294. * @param binary changes the STL to a binary type.
  4295. * @param isLittleEndian toggle for binary type exporter.
  4296. * @returns the STL as UTF8 string
  4297. */
  4298. STLExport.CreateSTL = function (meshes, download, fileName, binary, isLittleEndian) {
  4299. //Binary support adapted from https://gist.github.com/paulkaplan/6d5f0ab2c7e8fdc68a61
  4300. if (download === void 0) { download = true; }
  4301. if (fileName === void 0) { fileName = 'STL_Mesh'; }
  4302. if (binary === void 0) { binary = false; }
  4303. if (isLittleEndian === void 0) { isLittleEndian = true; }
  4304. var getFaceData = function (indices, vertices, i) {
  4305. var id = [indices[i] * 3, indices[i + 1] * 3, indices[i + 2] * 3];
  4306. var v = [
  4307. new babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vertices[id[0]], vertices[id[0] + 1], vertices[id[0] + 2]),
  4308. new babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vertices[id[1]], vertices[id[1] + 1], vertices[id[1] + 2]),
  4309. new babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vertices[id[2]], vertices[id[2] + 1], vertices[id[2] + 2])
  4310. ];
  4311. var p1p2 = v[0].subtract(v[1]);
  4312. var p3p2 = v[2].subtract(v[1]);
  4313. var n = (babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Cross(p1p2, p3p2)).normalize();
  4314. return { v: v, n: n };
  4315. };
  4316. var writeVector = function (dataview, offset, vector, isLittleEndian) {
  4317. offset = writeFloat(dataview, offset, vector.x, isLittleEndian);
  4318. offset = writeFloat(dataview, offset, vector.y, isLittleEndian);
  4319. return writeFloat(dataview, offset, vector.z, isLittleEndian);
  4320. };
  4321. var writeFloat = function (dataview, offset, value, isLittleEndian) {
  4322. dataview.setFloat32(offset, value, isLittleEndian);
  4323. return offset + 4;
  4324. };
  4325. var data;
  4326. var faceCount = 0;
  4327. var offset = 0;
  4328. if (binary) {
  4329. for (var i = 0; i < meshes.length; i++) {
  4330. var mesh = meshes[i];
  4331. var indices = mesh.getIndices();
  4332. faceCount += indices ? indices.length : 0;
  4333. }
  4334. var bufferSize = 84 + (50 * faceCount);
  4335. var buffer = new ArrayBuffer(bufferSize);
  4336. data = new DataView(buffer);
  4337. offset += 80;
  4338. data.setUint32(offset, faceCount, isLittleEndian);
  4339. offset += 4;
  4340. }
  4341. else {
  4342. data = 'solid exportedMesh\r\n';
  4343. }
  4344. for (var i = 0; i < meshes.length; i++) {
  4345. var mesh = meshes[i];
  4346. mesh.bakeCurrentTransformIntoVertices();
  4347. var vertices = mesh.getVerticesData(babylonjs_Meshes_buffer__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind) || [];
  4348. var indices = mesh.getIndices() || [];
  4349. for (var i_1 = 0; i_1 < indices.length; i_1 += 3) {
  4350. var fd = getFaceData(indices, vertices, i_1);
  4351. if (binary) {
  4352. offset = writeVector(data, offset, fd.n, isLittleEndian);
  4353. offset = writeVector(data, offset, fd.v[0], isLittleEndian);
  4354. offset = writeVector(data, offset, fd.v[1], isLittleEndian);
  4355. offset = writeVector(data, offset, fd.v[2], isLittleEndian);
  4356. offset += 2;
  4357. }
  4358. else {
  4359. data += 'facet normal ' + fd.n.x + ' ' + fd.n.y + ' ' + fd.n.z + '\r\n';
  4360. data += '\touter loop\r\n';
  4361. data += '\t\tvertex ' + fd.v[0].x + ' ' + fd.v[0].y + ' ' + fd.v[0].z + '\r\n';
  4362. data += '\t\tvertex ' + fd.v[1].x + ' ' + fd.v[1].y + ' ' + fd.v[1].z + '\r\n';
  4363. data += '\t\tvertex ' + fd.v[2].x + ' ' + fd.v[2].y + ' ' + fd.v[2].z + '\r\n';
  4364. data += '\tendloop\r\n';
  4365. data += 'endfacet\r\n';
  4366. }
  4367. }
  4368. }
  4369. if (!binary) {
  4370. data += 'endsolid exportedMesh';
  4371. }
  4372. if (download) {
  4373. var a = document.createElement('a');
  4374. var blob = new Blob([data], { 'type': 'application/octet-stream' });
  4375. a.href = window.URL.createObjectURL(blob);
  4376. if (!fileName) {
  4377. fileName = "STL_Mesh";
  4378. }
  4379. a.download = fileName + ".stl";
  4380. a.click();
  4381. }
  4382. return data;
  4383. };
  4384. return STLExport;
  4385. }());
  4386. /***/ }),
  4387. /***/ "babylonjs/Maths/math":
  4388. /*!****************************************************************************************************!*\
  4389. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  4390. \****************************************************************************************************/
  4391. /*! no static exports found */
  4392. /***/ (function(module, exports) {
  4393. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__;
  4394. /***/ })
  4395. /******/ });
  4396. });
  4397. //# sourceMappingURL=babylonjs.serializers.js.map