babylon.glTF2Serializer.js 218 KB

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