babylonjs.serializers.js 201 KB

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