babylon.glTF2Serializer.js 221 KB

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