babylon.glTF2Serializer.js 218 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112
  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. this._options = options || {};
  1144. this._animationSampleRate = options && options.animationSampleRate ? options.animationSampleRate : 1 / 60;
  1145. this._glTFMaterialExporter = new _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"](this);
  1146. this._loadExtensions();
  1147. }
  1148. _Exporter.prototype._applyExtensions = function (property, actionAsync) {
  1149. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1150. var name_1 = _a[_i];
  1151. var extension = this._extensions[name_1];
  1152. if (extension.enabled) {
  1153. var exporterProperty = property;
  1154. exporterProperty._activeLoaderExtensions = exporterProperty._activeLoaderExtensions || {};
  1155. var activeLoaderExtensions = exporterProperty._activeLoaderExtensions;
  1156. if (!activeLoaderExtensions[name_1]) {
  1157. activeLoaderExtensions[name_1] = true;
  1158. try {
  1159. var result = actionAsync(extension);
  1160. if (result) {
  1161. return result;
  1162. }
  1163. }
  1164. finally {
  1165. delete activeLoaderExtensions[name_1];
  1166. delete exporterProperty._activeLoaderExtensions;
  1167. }
  1168. }
  1169. }
  1170. }
  1171. return null;
  1172. };
  1173. _Exporter.prototype._extensionsPreExportTextureAsync = function (context, babylonTexture, mimeType) {
  1174. return this._applyExtensions(babylonTexture, function (extension) { return extension.preExportTextureAsync && extension.preExportTextureAsync(context, babylonTexture, mimeType); });
  1175. };
  1176. _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
  1177. return this._applyExtensions(meshPrimitive, function (extension) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, meshPrimitive, babylonSubMesh, binaryWriter); });
  1178. };
  1179. _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode) {
  1180. return this._applyExtensions(node, function (extension) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode); });
  1181. };
  1182. _Exporter.prototype._forEachExtensions = function (action) {
  1183. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1184. var name_2 = _a[_i];
  1185. var extension = this._extensions[name_2];
  1186. if (extension.enabled) {
  1187. action(extension);
  1188. }
  1189. }
  1190. };
  1191. _Exporter.prototype._extensionsOnExporting = function () {
  1192. this._forEachExtensions(function (extension) { return extension.onExporting && extension.onExporting(); });
  1193. };
  1194. /**
  1195. * Load glTF serializer extensions
  1196. */
  1197. _Exporter.prototype._loadExtensions = function () {
  1198. for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
  1199. var name_3 = _a[_i];
  1200. var extension = _Exporter._ExtensionFactories[name_3](this);
  1201. this._extensions[name_3] = extension;
  1202. }
  1203. };
  1204. /**
  1205. * Registers a glTF exporter extension
  1206. * @param name Name of the extension to export
  1207. * @param factory The factory function that creates the exporter extension
  1208. */
  1209. _Exporter.RegisterExtension = function (name, factory) {
  1210. if (_Exporter.UnregisterExtension(name)) {
  1211. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Extension with the name " + name + " already exists");
  1212. }
  1213. _Exporter._ExtensionFactories[name] = factory;
  1214. _Exporter._ExtensionNames.push(name);
  1215. };
  1216. /**
  1217. * Un-registers an exporter extension
  1218. * @param name The name fo the exporter extension
  1219. * @returns A boolean indicating whether the extension has been un-registered
  1220. */
  1221. _Exporter.UnregisterExtension = function (name) {
  1222. if (!_Exporter._ExtensionFactories[name]) {
  1223. return false;
  1224. }
  1225. delete _Exporter._ExtensionFactories[name];
  1226. var index = _Exporter._ExtensionNames.indexOf(name);
  1227. if (index !== -1) {
  1228. _Exporter._ExtensionNames.splice(index, 1);
  1229. }
  1230. return true;
  1231. };
  1232. /**
  1233. * Lazy load a local engine with premultiplied alpha set to false
  1234. */
  1235. _Exporter.prototype._getLocalEngine = function () {
  1236. if (!this._localEngine) {
  1237. var localCanvas = document.createElement('canvas');
  1238. localCanvas.id = "WriteCanvas";
  1239. localCanvas.width = 2048;
  1240. localCanvas.height = 2048;
  1241. this._localEngine = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"](localCanvas, true, { premultipliedAlpha: false, preserveDrawingBuffer: true });
  1242. this._localEngine.setViewport(new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Viewport"](0, 0, 1, 1));
  1243. }
  1244. return this._localEngine;
  1245. };
  1246. _Exporter.prototype.reorderIndicesBasedOnPrimitiveMode = function (submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter) {
  1247. switch (primitiveMode) {
  1248. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode: {
  1249. if (!byteOffset) {
  1250. byteOffset = 0;
  1251. }
  1252. for (var i = submesh.indexStart, length_1 = submesh.indexStart + submesh.indexCount; i < length_1; i = i + 3) {
  1253. var index = byteOffset + i * 4;
  1254. // swap the second and third indices
  1255. var secondIndex = binaryWriter.getUInt32(index + 4);
  1256. var thirdIndex = binaryWriter.getUInt32(index + 8);
  1257. binaryWriter.setUInt32(thirdIndex, index + 4);
  1258. binaryWriter.setUInt32(secondIndex, index + 8);
  1259. }
  1260. break;
  1261. }
  1262. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode: {
  1263. for (var i = submesh.indexStart + submesh.indexCount - 1, start = submesh.indexStart; i >= start; --i) {
  1264. binaryWriter.setUInt32(babylonIndices[i], byteOffset);
  1265. byteOffset += 4;
  1266. }
  1267. break;
  1268. }
  1269. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode: {
  1270. if (submesh.indexCount >= 3) {
  1271. binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 2], byteOffset + 4);
  1272. binaryWriter.setUInt32(babylonIndices[submesh.indexStart + 1], byteOffset + 8);
  1273. }
  1274. break;
  1275. }
  1276. }
  1277. };
  1278. /**
  1279. * Reorders the vertex attribute data based on the primitive mode. This is necessary when indices are not available and the winding order is
  1280. * clock-wise during export to glTF
  1281. * @param submesh BabylonJS submesh
  1282. * @param primitiveMode Primitive mode of the mesh
  1283. * @param sideOrientation the winding order of the submesh
  1284. * @param vertexBufferKind The type of vertex attribute
  1285. * @param meshAttributeArray The vertex attribute data
  1286. * @param byteOffset The offset to the binary data
  1287. * @param binaryWriter The binary data for the glTF file
  1288. */
  1289. _Exporter.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1290. if (this._convertToRightHandedSystem && sideOrientation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation) {
  1291. switch (primitiveMode) {
  1292. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode: {
  1293. this.reorderTriangleFillMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  1294. break;
  1295. }
  1296. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode: {
  1297. this.reorderTriangleStripDrawMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  1298. break;
  1299. }
  1300. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode: {
  1301. this.reorderTriangleFanMode(submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter);
  1302. break;
  1303. }
  1304. }
  1305. }
  1306. };
  1307. /**
  1308. * Reorders the vertex attributes in the correct triangle mode order . This is necessary when indices are not available and the winding order is
  1309. * clock-wise during export to glTF
  1310. * @param submesh BabylonJS submesh
  1311. * @param primitiveMode Primitive mode of the mesh
  1312. * @param sideOrientation the winding order of the submesh
  1313. * @param vertexBufferKind The type of vertex attribute
  1314. * @param meshAttributeArray The vertex attribute data
  1315. * @param byteOffset The offset to the binary data
  1316. * @param binaryWriter The binary data for the glTF file
  1317. */
  1318. _Exporter.prototype.reorderTriangleFillMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1319. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  1320. if (vertexBuffer) {
  1321. var stride = vertexBuffer.byteStride / babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  1322. if (submesh.verticesCount % 3 !== 0) {
  1323. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('The submesh vertices for the triangle fill mode is not divisible by 3!');
  1324. }
  1325. else {
  1326. var vertexData = [];
  1327. var index = 0;
  1328. switch (vertexBufferKind) {
  1329. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind:
  1330. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind: {
  1331. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  1332. index = x * stride;
  1333. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index));
  1334. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  1335. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index + stride));
  1336. }
  1337. break;
  1338. }
  1339. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind: {
  1340. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  1341. index = x * stride;
  1342. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index));
  1343. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index + 2 * stride));
  1344. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index + stride));
  1345. }
  1346. break;
  1347. }
  1348. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind: {
  1349. var size = vertexBuffer.getSize();
  1350. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {
  1351. index = x * stride;
  1352. if (size === 4) {
  1353. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index));
  1354. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index + 2 * stride));
  1355. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index + stride));
  1356. }
  1357. else {
  1358. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index));
  1359. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  1360. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index + stride));
  1361. }
  1362. }
  1363. break;
  1364. }
  1365. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind:
  1366. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind: {
  1367. for (var x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
  1368. index = x * stride;
  1369. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].FromArray(meshAttributeArray, index));
  1370. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].FromArray(meshAttributeArray, index + 2 * stride));
  1371. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].FromArray(meshAttributeArray, index + stride));
  1372. }
  1373. break;
  1374. }
  1375. default: {
  1376. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  1377. }
  1378. }
  1379. this.writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter);
  1380. }
  1381. }
  1382. else {
  1383. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("reorderTriangleFillMode: Vertex Buffer Kind " + vertexBufferKind + " not present!");
  1384. }
  1385. };
  1386. /**
  1387. * Reorders the vertex attributes in the correct triangle strip order. This is necessary when indices are not available and the winding order is
  1388. * clock-wise during export to glTF
  1389. * @param submesh BabylonJS submesh
  1390. * @param primitiveMode Primitive mode of the mesh
  1391. * @param sideOrientation the winding order of the submesh
  1392. * @param vertexBufferKind The type of vertex attribute
  1393. * @param meshAttributeArray The vertex attribute data
  1394. * @param byteOffset The offset to the binary data
  1395. * @param binaryWriter The binary data for the glTF file
  1396. */
  1397. _Exporter.prototype.reorderTriangleStripDrawMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1398. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  1399. if (vertexBuffer) {
  1400. var stride = vertexBuffer.byteStride / babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  1401. var vertexData = [];
  1402. var index = 0;
  1403. switch (vertexBufferKind) {
  1404. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind:
  1405. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind: {
  1406. index = submesh.verticesStart;
  1407. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index + 2 * stride));
  1408. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index + stride));
  1409. break;
  1410. }
  1411. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind: {
  1412. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1413. index = x * stride;
  1414. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index));
  1415. }
  1416. break;
  1417. }
  1418. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind: {
  1419. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1420. index = x * stride;
  1421. 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));
  1422. }
  1423. break;
  1424. }
  1425. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind:
  1426. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind: {
  1427. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1428. index = x * stride;
  1429. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].FromArray(meshAttributeArray, index));
  1430. }
  1431. break;
  1432. }
  1433. default: {
  1434. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  1435. }
  1436. }
  1437. this.writeVertexAttributeData(vertexData, byteOffset + 12, vertexBufferKind, meshAttributeArray, binaryWriter);
  1438. }
  1439. else {
  1440. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("reorderTriangleStripDrawMode: Vertex buffer kind " + vertexBufferKind + " not present!");
  1441. }
  1442. };
  1443. /**
  1444. * Reorders the vertex attributes in the correct triangle fan order. This is necessary when indices are not available and the winding order is
  1445. * clock-wise during export to glTF
  1446. * @param submesh BabylonJS submesh
  1447. * @param primitiveMode Primitive mode of the mesh
  1448. * @param sideOrientation the winding order of the submesh
  1449. * @param vertexBufferKind The type of vertex attribute
  1450. * @param meshAttributeArray The vertex attribute data
  1451. * @param byteOffset The offset to the binary data
  1452. * @param binaryWriter The binary data for the glTF file
  1453. */
  1454. _Exporter.prototype.reorderTriangleFanMode = function (submesh, primitiveMode, sideOrientation, vertexBufferKind, meshAttributeArray, byteOffset, binaryWriter) {
  1455. var vertexBuffer = this.getVertexBufferFromMesh(vertexBufferKind, submesh.getMesh());
  1456. if (vertexBuffer) {
  1457. var stride = vertexBuffer.byteStride / babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].GetTypeByteLength(vertexBuffer.type);
  1458. var vertexData = [];
  1459. var index = 0;
  1460. switch (vertexBufferKind) {
  1461. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind:
  1462. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind: {
  1463. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1464. index = x * stride;
  1465. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index));
  1466. }
  1467. break;
  1468. }
  1469. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind: {
  1470. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1471. index = x * stride;
  1472. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index));
  1473. }
  1474. break;
  1475. }
  1476. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind: {
  1477. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1478. index = x * stride;
  1479. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index));
  1480. 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));
  1481. }
  1482. break;
  1483. }
  1484. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind:
  1485. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind: {
  1486. for (var x = submesh.verticesStart + submesh.verticesCount - 1; x >= submesh.verticesStart; --x) {
  1487. index = x * stride;
  1488. vertexData.push(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"].FromArray(meshAttributeArray, index));
  1489. }
  1490. break;
  1491. }
  1492. default: {
  1493. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported Vertex Buffer type: " + vertexBufferKind);
  1494. }
  1495. }
  1496. this.writeVertexAttributeData(vertexData, byteOffset, vertexBufferKind, meshAttributeArray, binaryWriter);
  1497. }
  1498. else {
  1499. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("reorderTriangleFanMode: Vertex buffer kind " + vertexBufferKind + " not present!");
  1500. }
  1501. };
  1502. /**
  1503. * Writes the vertex attribute data to binary
  1504. * @param vertices The vertices to write to the binary writer
  1505. * @param byteOffset The offset into the binary writer to overwrite binary data
  1506. * @param vertexAttributeKind The vertex attribute type
  1507. * @param meshAttributeArray The vertex attribute data
  1508. * @param binaryWriter The writer containing the binary data
  1509. */
  1510. _Exporter.prototype.writeVertexAttributeData = function (vertices, byteOffset, vertexAttributeKind, meshAttributeArray, binaryWriter) {
  1511. for (var _i = 0, vertices_1 = vertices; _i < vertices_1.length; _i++) {
  1512. var vertex = vertices_1[_i];
  1513. if (this._convertToRightHandedSystem && !(vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind) && !(vertex instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"])) {
  1514. if (vertex instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"]) {
  1515. if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind) {
  1516. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(vertex);
  1517. }
  1518. else if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind) {
  1519. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(vertex);
  1520. }
  1521. else {
  1522. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('Unsupported vertex attribute kind!');
  1523. }
  1524. }
  1525. else {
  1526. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedVector4FromRef(vertex);
  1527. }
  1528. }
  1529. if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind) {
  1530. vertex.normalize();
  1531. }
  1532. else if (vertexAttributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind && vertex instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"]) {
  1533. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._NormalizeTangentFromRef(vertex);
  1534. }
  1535. for (var _a = 0, _b = vertex.asArray(); _a < _b.length; _a++) {
  1536. var component = _b[_a];
  1537. binaryWriter.setFloat32(component, byteOffset);
  1538. byteOffset += 4;
  1539. }
  1540. }
  1541. };
  1542. /**
  1543. * Writes mesh attribute data to a data buffer
  1544. * Returns the bytelength of the data
  1545. * @param vertexBufferKind Indicates what kind of vertex data is being passed in
  1546. * @param meshAttributeArray Array containing the attribute data
  1547. * @param binaryWriter The buffer to write the binary data to
  1548. * @param indices Used to specify the order of the vertex data
  1549. */
  1550. _Exporter.prototype.writeAttributeData = function (vertexBufferKind, meshAttributeArray, byteStride, binaryWriter) {
  1551. var stride = byteStride / 4;
  1552. var vertexAttributes = [];
  1553. var index;
  1554. switch (vertexBufferKind) {
  1555. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind: {
  1556. for (var k = 0, length_2 = meshAttributeArray.length / stride; k < length_2; ++k) {
  1557. index = k * stride;
  1558. var vertexData = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index);
  1559. if (this._convertToRightHandedSystem) {
  1560. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(vertexData);
  1561. }
  1562. vertexAttributes.push(vertexData.asArray());
  1563. }
  1564. break;
  1565. }
  1566. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind: {
  1567. for (var k = 0, length_3 = meshAttributeArray.length / stride; k < length_3; ++k) {
  1568. index = k * stride;
  1569. var vertexData = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(meshAttributeArray, index);
  1570. if (this._convertToRightHandedSystem) {
  1571. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedNormalVector3FromRef(vertexData);
  1572. }
  1573. vertexData.normalize();
  1574. vertexAttributes.push(vertexData.asArray());
  1575. }
  1576. break;
  1577. }
  1578. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind: {
  1579. for (var k = 0, length_4 = meshAttributeArray.length / stride; k < length_4; ++k) {
  1580. index = k * stride;
  1581. var vertexData = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector4"].FromArray(meshAttributeArray, index);
  1582. if (this._convertToRightHandedSystem) {
  1583. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedVector4FromRef(vertexData);
  1584. }
  1585. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._NormalizeTangentFromRef(vertexData);
  1586. vertexAttributes.push(vertexData.asArray());
  1587. }
  1588. break;
  1589. }
  1590. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind: {
  1591. for (var k = 0, length_5 = meshAttributeArray.length / stride; k < length_5; ++k) {
  1592. index = k * stride;
  1593. 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);
  1594. vertexAttributes.push(vertexData.asArray());
  1595. }
  1596. break;
  1597. }
  1598. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind:
  1599. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind: {
  1600. for (var k = 0, length_6 = meshAttributeArray.length / stride; k < length_6; ++k) {
  1601. index = k * stride;
  1602. vertexAttributes.push(this._convertToRightHandedSystem ? [meshAttributeArray[index], meshAttributeArray[index + 1]] : [meshAttributeArray[index], meshAttributeArray[index + 1]]);
  1603. }
  1604. break;
  1605. }
  1606. default: {
  1607. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
  1608. vertexAttributes = [];
  1609. }
  1610. }
  1611. for (var _i = 0, vertexAttributes_1 = vertexAttributes; _i < vertexAttributes_1.length; _i++) {
  1612. var vertexAttribute = vertexAttributes_1[_i];
  1613. for (var _a = 0, vertexAttribute_1 = vertexAttribute; _a < vertexAttribute_1.length; _a++) {
  1614. var component = vertexAttribute_1[_a];
  1615. binaryWriter.setFloat32(component);
  1616. }
  1617. }
  1618. };
  1619. /**
  1620. * Generates glTF json data
  1621. * @param shouldUseGlb Indicates whether the json should be written for a glb file
  1622. * @param glTFPrefix Text to use when prefixing a glTF file
  1623. * @param prettyPrint Indicates whether the json file should be pretty printed (true) or not (false)
  1624. * @returns json data as string
  1625. */
  1626. _Exporter.prototype.generateJSON = function (shouldUseGlb, glTFPrefix, prettyPrint) {
  1627. var _this = this;
  1628. var buffer = { byteLength: this._totalByteLength };
  1629. var imageName;
  1630. var imageData;
  1631. var bufferView;
  1632. var byteOffset = this._totalByteLength;
  1633. if (buffer.byteLength) {
  1634. this._glTF.buffers = [buffer];
  1635. }
  1636. if (this._nodes && this._nodes.length) {
  1637. this._glTF.nodes = this._nodes;
  1638. }
  1639. if (this._meshes && this._meshes.length) {
  1640. this._glTF.meshes = this._meshes;
  1641. }
  1642. if (this._scenes && this._scenes.length) {
  1643. this._glTF.scenes = this._scenes;
  1644. this._glTF.scene = 0;
  1645. }
  1646. if (this._bufferViews && this._bufferViews.length) {
  1647. this._glTF.bufferViews = this._bufferViews;
  1648. }
  1649. if (this._accessors && this._accessors.length) {
  1650. this._glTF.accessors = this._accessors;
  1651. }
  1652. if (this._animations && this._animations.length) {
  1653. this._glTF.animations = this._animations;
  1654. }
  1655. if (this._materials && this._materials.length) {
  1656. this._glTF.materials = this._materials;
  1657. }
  1658. if (this._textures && this._textures.length) {
  1659. this._glTF.textures = this._textures;
  1660. }
  1661. if (this._samplers && this._samplers.length) {
  1662. this._glTF.samplers = this._samplers;
  1663. }
  1664. if (this._images && this._images.length) {
  1665. if (!shouldUseGlb) {
  1666. this._glTF.images = this._images;
  1667. }
  1668. else {
  1669. this._glTF.images = [];
  1670. this._images.forEach(function (image) {
  1671. if (image.uri) {
  1672. imageData = _this._imageData[image.uri];
  1673. imageName = image.uri.split('.')[0] + " image";
  1674. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._CreateBufferView(0, byteOffset, imageData.data.length, undefined, imageName);
  1675. byteOffset += imageData.data.buffer.byteLength;
  1676. _this._bufferViews.push(bufferView);
  1677. image.bufferView = _this._bufferViews.length - 1;
  1678. image.name = imageName;
  1679. image.mimeType = imageData.mimeType;
  1680. image.uri = undefined;
  1681. if (!_this._glTF.images) {
  1682. _this._glTF.images = [];
  1683. }
  1684. _this._glTF.images.push(image);
  1685. }
  1686. });
  1687. // Replace uri with bufferview and mime type for glb
  1688. buffer.byteLength = byteOffset;
  1689. }
  1690. }
  1691. if (!shouldUseGlb) {
  1692. buffer.uri = glTFPrefix + ".bin";
  1693. }
  1694. var jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);
  1695. return jsonText;
  1696. };
  1697. /**
  1698. * Generates data for .gltf and .bin files based on the glTF prefix string
  1699. * @param glTFPrefix Text to use when prefixing a glTF file
  1700. * @returns GLTFData with glTF file data
  1701. */
  1702. _Exporter.prototype._generateGLTFAsync = function (glTFPrefix) {
  1703. var _this = this;
  1704. return this._generateBinaryAsync().then(function (binaryBuffer) {
  1705. _this._extensionsOnExporting();
  1706. var jsonText = _this.generateJSON(false, glTFPrefix, true);
  1707. var bin = new Blob([binaryBuffer], { type: 'application/octet-stream' });
  1708. var glTFFileName = glTFPrefix + '.gltf';
  1709. var glTFBinFile = glTFPrefix + '.bin';
  1710. var container = new _glTFData__WEBPACK_IMPORTED_MODULE_3__["GLTFData"]();
  1711. container.glTFFiles[glTFFileName] = jsonText;
  1712. container.glTFFiles[glTFBinFile] = bin;
  1713. if (_this._imageData) {
  1714. for (var image in _this._imageData) {
  1715. container.glTFFiles[image] = new Blob([_this._imageData[image].data], { type: _this._imageData[image].mimeType });
  1716. }
  1717. }
  1718. return container;
  1719. });
  1720. };
  1721. /**
  1722. * Creates a binary buffer for glTF
  1723. * @returns array buffer for binary data
  1724. */
  1725. _Exporter.prototype._generateBinaryAsync = function () {
  1726. var _this = this;
  1727. var binaryWriter = new _BinaryWriter(4);
  1728. return this.createSceneAsync(this._babylonScene, binaryWriter).then(function () {
  1729. if (_this._localEngine) {
  1730. _this._localEngine.dispose();
  1731. }
  1732. return binaryWriter.getArrayBuffer();
  1733. });
  1734. };
  1735. /**
  1736. * Pads the number to a multiple of 4
  1737. * @param num number to pad
  1738. * @returns padded number
  1739. */
  1740. _Exporter.prototype._getPadding = function (num) {
  1741. var remainder = num % 4;
  1742. var padding = remainder === 0 ? remainder : 4 - remainder;
  1743. return padding;
  1744. };
  1745. /**
  1746. * Generates a glb file from the json and binary data
  1747. * Returns an object with the glb file name as the key and data as the value
  1748. * @param glTFPrefix
  1749. * @returns object with glb filename as key and data as value
  1750. */
  1751. _Exporter.prototype._generateGLBAsync = function (glTFPrefix) {
  1752. var _this = this;
  1753. return this._generateBinaryAsync().then(function (binaryBuffer) {
  1754. _this._extensionsOnExporting();
  1755. var jsonText = _this.generateJSON(true);
  1756. var glbFileName = glTFPrefix + '.glb';
  1757. var headerLength = 12;
  1758. var chunkLengthPrefix = 8;
  1759. var jsonLength = jsonText.length;
  1760. var imageByteLength = 0;
  1761. for (var key in _this._imageData) {
  1762. imageByteLength += _this._imageData[key].data.byteLength;
  1763. }
  1764. var jsonPadding = _this._getPadding(jsonLength);
  1765. var binPadding = _this._getPadding(binaryBuffer.byteLength);
  1766. var imagePadding = _this._getPadding(imageByteLength);
  1767. var byteLength = headerLength + (2 * chunkLengthPrefix) + jsonLength + jsonPadding + binaryBuffer.byteLength + binPadding + imageByteLength + imagePadding;
  1768. //header
  1769. var headerBuffer = new ArrayBuffer(headerLength);
  1770. var headerBufferView = new DataView(headerBuffer);
  1771. headerBufferView.setUint32(0, 0x46546C67, true); //glTF
  1772. headerBufferView.setUint32(4, 2, true); // version
  1773. headerBufferView.setUint32(8, byteLength, true); // total bytes in file
  1774. //json chunk
  1775. var jsonChunkBuffer = new ArrayBuffer(chunkLengthPrefix + jsonLength + jsonPadding);
  1776. var jsonChunkBufferView = new DataView(jsonChunkBuffer);
  1777. jsonChunkBufferView.setUint32(0, jsonLength + jsonPadding, true);
  1778. jsonChunkBufferView.setUint32(4, 0x4E4F534A, true);
  1779. //json chunk bytes
  1780. var jsonData = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix);
  1781. for (var i = 0; i < jsonLength; ++i) {
  1782. jsonData[i] = jsonText.charCodeAt(i);
  1783. }
  1784. //json padding
  1785. var jsonPaddingView = new Uint8Array(jsonChunkBuffer, chunkLengthPrefix + jsonLength);
  1786. for (var i = 0; i < jsonPadding; ++i) {
  1787. jsonPaddingView[i] = 0x20;
  1788. }
  1789. //binary chunk
  1790. var binaryChunkBuffer = new ArrayBuffer(chunkLengthPrefix);
  1791. var binaryChunkBufferView = new DataView(binaryChunkBuffer);
  1792. binaryChunkBufferView.setUint32(0, binaryBuffer.byteLength + imageByteLength + imagePadding, true);
  1793. binaryChunkBufferView.setUint32(4, 0x004E4942, true);
  1794. // binary padding
  1795. var binPaddingBuffer = new ArrayBuffer(binPadding);
  1796. var binPaddingView = new Uint8Array(binPaddingBuffer);
  1797. for (var i = 0; i < binPadding; ++i) {
  1798. binPaddingView[i] = 0;
  1799. }
  1800. var imagePaddingBuffer = new ArrayBuffer(imagePadding);
  1801. var imagePaddingView = new Uint8Array(imagePaddingBuffer);
  1802. for (var i = 0; i < imagePadding; ++i) {
  1803. imagePaddingView[i] = 0;
  1804. }
  1805. var glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];
  1806. // binary data
  1807. for (var key in _this._imageData) {
  1808. glbData.push(_this._imageData[key].data.buffer);
  1809. }
  1810. glbData.push(binPaddingBuffer);
  1811. glbData.push(imagePaddingBuffer);
  1812. var glbFile = new Blob(glbData, { type: 'application/octet-stream' });
  1813. var container = new _glTFData__WEBPACK_IMPORTED_MODULE_3__["GLTFData"]();
  1814. container.glTFFiles[glbFileName] = glbFile;
  1815. if (_this._localEngine != null) {
  1816. _this._localEngine.dispose();
  1817. }
  1818. return container;
  1819. });
  1820. };
  1821. /**
  1822. * Sets the TRS for each node
  1823. * @param node glTF Node for storing the transformation data
  1824. * @param babylonTransformNode Babylon mesh used as the source for the transformation data
  1825. */
  1826. _Exporter.prototype.setNodeTransformation = function (node, babylonTransformNode) {
  1827. if (!babylonTransformNode.getPivotPoint().equalsToFloats(0, 0, 0)) {
  1828. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Pivot points are not supported in the glTF serializer");
  1829. }
  1830. if (!babylonTransformNode.position.equalsToFloats(0, 0, 0)) {
  1831. node.translation = this._convertToRightHandedSystem ? _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3(babylonTransformNode.position).asArray() : babylonTransformNode.position.asArray();
  1832. }
  1833. if (!babylonTransformNode.scaling.equalsToFloats(1, 1, 1)) {
  1834. node.scale = babylonTransformNode.scaling.asArray();
  1835. }
  1836. var rotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(babylonTransformNode.rotation.y, babylonTransformNode.rotation.x, babylonTransformNode.rotation.z);
  1837. if (babylonTransformNode.rotationQuaternion) {
  1838. rotationQuaternion.multiplyInPlace(babylonTransformNode.rotationQuaternion);
  1839. }
  1840. if (!(rotationQuaternion.x === 0 && rotationQuaternion.y === 0 && rotationQuaternion.z === 0 && rotationQuaternion.w === 1)) {
  1841. if (this._convertToRightHandedSystem) {
  1842. _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(rotationQuaternion);
  1843. }
  1844. node.rotation = rotationQuaternion.normalize().asArray();
  1845. }
  1846. };
  1847. _Exporter.prototype.getVertexBufferFromMesh = function (attributeKind, bufferMesh) {
  1848. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  1849. var vertexBuffer = bufferMesh.getVertexBuffer(attributeKind);
  1850. if (vertexBuffer) {
  1851. return vertexBuffer;
  1852. }
  1853. }
  1854. return null;
  1855. };
  1856. /**
  1857. * Creates a bufferview based on the vertices type for the Babylon mesh
  1858. * @param kind Indicates the type of vertices data
  1859. * @param babylonTransformNode The Babylon mesh to get the vertices data from
  1860. * @param binaryWriter The buffer to write the bufferview data to
  1861. */
  1862. _Exporter.prototype.createBufferViewKind = function (kind, babylonTransformNode, binaryWriter, byteStride) {
  1863. var bufferMesh = babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"] ?
  1864. babylonTransformNode : babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["InstancedMesh"] ?
  1865. babylonTransformNode.sourceMesh : null;
  1866. if (bufferMesh) {
  1867. var vertexData = bufferMesh.getVerticesData(kind);
  1868. if (vertexData) {
  1869. var byteLength = vertexData.length * 4;
  1870. var bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, byteStride, kind + " - " + bufferMesh.name);
  1871. this._bufferViews.push(bufferView);
  1872. this.writeAttributeData(kind, vertexData, byteStride, binaryWriter);
  1873. }
  1874. }
  1875. };
  1876. /**
  1877. * The primitive mode of the Babylon mesh
  1878. * @param babylonMesh The BabylonJS mesh
  1879. */
  1880. _Exporter.prototype.getMeshPrimitiveMode = function (babylonMesh) {
  1881. if (babylonMesh instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["LinesMesh"]) {
  1882. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode;
  1883. }
  1884. return babylonMesh.material ? babylonMesh.material.fillMode : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode;
  1885. };
  1886. /**
  1887. * Sets the primitive mode of the glTF mesh primitive
  1888. * @param meshPrimitive glTF mesh primitive
  1889. * @param primitiveMode The primitive mode
  1890. */
  1891. _Exporter.prototype.setPrimitiveMode = function (meshPrimitive, primitiveMode) {
  1892. switch (primitiveMode) {
  1893. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFillMode: {
  1894. // glTF defaults to using Triangle Mode
  1895. break;
  1896. }
  1897. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleStripDrawMode: {
  1898. meshPrimitive.mode = 5 /* TRIANGLE_STRIP */;
  1899. break;
  1900. }
  1901. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].TriangleFanDrawMode: {
  1902. meshPrimitive.mode = 6 /* TRIANGLE_FAN */;
  1903. break;
  1904. }
  1905. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].PointListDrawMode: {
  1906. meshPrimitive.mode = 0 /* POINTS */;
  1907. }
  1908. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].PointFillMode: {
  1909. meshPrimitive.mode = 0 /* POINTS */;
  1910. break;
  1911. }
  1912. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].LineLoopDrawMode: {
  1913. meshPrimitive.mode = 2 /* LINE_LOOP */;
  1914. break;
  1915. }
  1916. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].LineListDrawMode: {
  1917. meshPrimitive.mode = 1 /* LINES */;
  1918. break;
  1919. }
  1920. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].LineStripDrawMode: {
  1921. meshPrimitive.mode = 3 /* LINE_STRIP */;
  1922. break;
  1923. }
  1924. }
  1925. };
  1926. /**
  1927. * Sets the vertex attribute accessor based of the glTF mesh primitive
  1928. * @param meshPrimitive glTF mesh primitive
  1929. * @param attributeKind vertex attribute
  1930. * @returns boolean specifying if uv coordinates are present
  1931. */
  1932. _Exporter.prototype.setAttributeKind = function (meshPrimitive, attributeKind) {
  1933. switch (attributeKind) {
  1934. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind: {
  1935. meshPrimitive.attributes.POSITION = this._accessors.length - 1;
  1936. break;
  1937. }
  1938. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind: {
  1939. meshPrimitive.attributes.NORMAL = this._accessors.length - 1;
  1940. break;
  1941. }
  1942. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind: {
  1943. meshPrimitive.attributes.COLOR_0 = this._accessors.length - 1;
  1944. break;
  1945. }
  1946. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind: {
  1947. meshPrimitive.attributes.TANGENT = this._accessors.length - 1;
  1948. break;
  1949. }
  1950. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind: {
  1951. meshPrimitive.attributes.TEXCOORD_0 = this._accessors.length - 1;
  1952. break;
  1953. }
  1954. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind: {
  1955. meshPrimitive.attributes.TEXCOORD_1 = this._accessors.length - 1;
  1956. break;
  1957. }
  1958. default: {
  1959. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unsupported Vertex Buffer Type: " + attributeKind);
  1960. }
  1961. }
  1962. };
  1963. /**
  1964. * Sets data for the primitive attributes of each submesh
  1965. * @param mesh glTF Mesh object to store the primitive attribute information
  1966. * @param babylonTransformNode Babylon mesh to get the primitive attribute data from
  1967. * @param binaryWriter Buffer to write the attribute data to
  1968. */
  1969. _Exporter.prototype.setPrimitiveAttributesAsync = function (mesh, babylonTransformNode, binaryWriter) {
  1970. var promises = [];
  1971. var bufferMesh = null;
  1972. var bufferView;
  1973. var minMax;
  1974. if (babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Mesh"]) {
  1975. bufferMesh = babylonTransformNode;
  1976. }
  1977. else if (babylonTransformNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["InstancedMesh"]) {
  1978. bufferMesh = babylonTransformNode.sourceMesh;
  1979. }
  1980. var attributeData = [
  1981. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind, accessorType: "VEC3" /* VEC3 */, byteStride: 12 },
  1982. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].NormalKind, accessorType: "VEC3" /* VEC3 */, byteStride: 12 },
  1983. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].ColorKind, accessorType: "VEC4" /* VEC4 */, byteStride: 16 },
  1984. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].TangentKind, accessorType: "VEC4" /* VEC4 */, byteStride: 16 },
  1985. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind, accessorType: "VEC2" /* VEC2 */, byteStride: 8 },
  1986. { kind: babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind, accessorType: "VEC2" /* VEC2 */, byteStride: 8 },
  1987. ];
  1988. if (bufferMesh) {
  1989. var indexBufferViewIndex = null;
  1990. var primitiveMode = this.getMeshPrimitiveMode(bufferMesh);
  1991. var vertexAttributeBufferViews = {};
  1992. // For each BabylonMesh, create bufferviews for each 'kind'
  1993. for (var _i = 0, attributeData_1 = attributeData; _i < attributeData_1.length; _i++) {
  1994. var attribute = attributeData_1[_i];
  1995. var attributeKind = attribute.kind;
  1996. if (bufferMesh.isVerticesDataPresent(attributeKind)) {
  1997. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  1998. attribute.byteStride = vertexBuffer ? vertexBuffer.getSize() * 4 : babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].DeduceStride(attributeKind) * 4;
  1999. if (attribute.byteStride === 12) {
  2000. attribute.accessorType = "VEC3" /* VEC3 */;
  2001. }
  2002. this.createBufferViewKind(attributeKind, babylonTransformNode, binaryWriter, attribute.byteStride);
  2003. attribute.bufferViewIndex = this._bufferViews.length - 1;
  2004. vertexAttributeBufferViews[attributeKind] = attribute.bufferViewIndex;
  2005. }
  2006. }
  2007. if (bufferMesh.getTotalIndices()) {
  2008. var indices = bufferMesh.getIndices();
  2009. if (indices) {
  2010. var byteLength = indices.length * 4;
  2011. bufferView = _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, "Indices - " + bufferMesh.name);
  2012. this._bufferViews.push(bufferView);
  2013. indexBufferViewIndex = this._bufferViews.length - 1;
  2014. for (var k = 0, length_7 = indices.length; k < length_7; ++k) {
  2015. binaryWriter.setUInt32(indices[k]);
  2016. }
  2017. }
  2018. }
  2019. if (bufferMesh.subMeshes) {
  2020. // go through all mesh primitives (submeshes)
  2021. for (var _a = 0, _b = bufferMesh.subMeshes; _a < _b.length; _a++) {
  2022. var submesh = _b[_a];
  2023. var babylonMaterial = submesh.getMaterial() || bufferMesh.getScene().defaultMaterial;
  2024. var materialIndex = null;
  2025. if (babylonMaterial) {
  2026. if (bufferMesh instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["LinesMesh"]) {
  2027. // get the color from the lines mesh and set it in the material
  2028. var material = {
  2029. name: bufferMesh.name + ' material'
  2030. };
  2031. if (!bufferMesh.color.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White()) || bufferMesh.alpha < 1) {
  2032. material.pbrMetallicRoughness = {
  2033. baseColorFactor: bufferMesh.color.asArray().concat([bufferMesh.alpha])
  2034. };
  2035. }
  2036. this._materials.push(material);
  2037. materialIndex = this._materials.length - 1;
  2038. }
  2039. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["MultiMaterial"]) {
  2040. var subMaterial = babylonMaterial.subMaterials[submesh.materialIndex];
  2041. if (subMaterial) {
  2042. babylonMaterial = subMaterial;
  2043. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  2044. }
  2045. }
  2046. else {
  2047. materialIndex = this._materialMap[babylonMaterial.uniqueId];
  2048. }
  2049. }
  2050. var glTFMaterial = materialIndex != null ? this._materials[materialIndex] : null;
  2051. var meshPrimitive = { attributes: {} };
  2052. this.setPrimitiveMode(meshPrimitive, primitiveMode);
  2053. for (var _c = 0, attributeData_2 = attributeData; _c < attributeData_2.length; _c++) {
  2054. var attribute = attributeData_2[_c];
  2055. var attributeKind = attribute.kind;
  2056. if (attributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UVKind || attributeKind === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].UV2Kind) {
  2057. if (glTFMaterial && !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
  2058. continue;
  2059. }
  2060. }
  2061. var vertexData = bufferMesh.getVerticesData(attributeKind);
  2062. if (vertexData) {
  2063. var vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
  2064. if (vertexBuffer) {
  2065. var stride = vertexBuffer.getSize();
  2066. var bufferViewIndex = attribute.bufferViewIndex;
  2067. if (bufferViewIndex != undefined) { // check to see if bufferviewindex has a numeric value assigned.
  2068. minMax = { min: null, max: null };
  2069. if (attributeKind == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["VertexBuffer"].PositionKind) {
  2070. minMax = _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride, this._convertToRightHandedSystem);
  2071. }
  2072. 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);
  2073. this._accessors.push(accessor);
  2074. this.setAttributeKind(meshPrimitive, attributeKind);
  2075. }
  2076. }
  2077. }
  2078. }
  2079. if (indexBufferViewIndex) {
  2080. // Create accessor
  2081. 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);
  2082. this._accessors.push(accessor);
  2083. meshPrimitive.indices = this._accessors.length - 1;
  2084. }
  2085. if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
  2086. var sideOrientation = babylonMaterial.sideOrientation;
  2087. // Only reverse the winding if we have a clockwise winding
  2088. if (sideOrientation === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Material"].ClockWiseSideOrientation) {
  2089. var byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
  2090. if (byteOffset == null) {
  2091. byteOffset = 0;
  2092. }
  2093. var babylonIndices = null;
  2094. if (indexBufferViewIndex != null) {
  2095. babylonIndices = bufferMesh.getIndices();
  2096. }
  2097. if (babylonIndices) {
  2098. this.reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
  2099. }
  2100. else {
  2101. for (var _d = 0, attributeData_3 = attributeData; _d < attributeData_3.length; _d++) {
  2102. var attribute = attributeData_3[_d];
  2103. var vertexData = bufferMesh.getVerticesData(attribute.kind);
  2104. if (vertexData) {
  2105. var byteOffset_1 = this._bufferViews[vertexAttributeBufferViews[attribute.kind]].byteOffset;
  2106. if (!byteOffset_1) {
  2107. byteOffset_1 = 0;
  2108. }
  2109. this.reorderVertexAttributeDataBasedOnPrimitiveMode(submesh, primitiveMode, sideOrientation, attribute.kind, vertexData, byteOffset_1, binaryWriter);
  2110. }
  2111. }
  2112. }
  2113. }
  2114. meshPrimitive.material = materialIndex;
  2115. }
  2116. mesh.primitives.push(meshPrimitive);
  2117. var promise = this._extensionsPostExportMeshPrimitiveAsync("postExport", meshPrimitive, submesh, binaryWriter);
  2118. if (promise) {
  2119. promises.push();
  2120. }
  2121. }
  2122. }
  2123. }
  2124. return Promise.all(promises).then(function () {
  2125. /* do nothing */
  2126. });
  2127. };
  2128. /**
  2129. * Creates a glTF scene based on the array of meshes
  2130. * Returns the the total byte offset
  2131. * @param babylonScene Babylon scene to get the mesh data from
  2132. * @param binaryWriter Buffer to write binary data to
  2133. */
  2134. _Exporter.prototype.createSceneAsync = function (babylonScene, binaryWriter) {
  2135. var _this = this;
  2136. var scene = { nodes: [] };
  2137. var glTFNodeIndex;
  2138. var glTFNode;
  2139. var directDescendents;
  2140. var nodes = babylonScene.transformNodes.concat(babylonScene.meshes, babylonScene.lights);
  2141. return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
  2142. return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, binaryWriter).then(function (nodeMap) {
  2143. _this._nodeMap = nodeMap;
  2144. _this._totalByteLength = binaryWriter.getByteOffset();
  2145. if (_this._totalByteLength == undefined) {
  2146. throw new Error("undefined byte length!");
  2147. }
  2148. // Build Hierarchy with the node map.
  2149. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  2150. var babylonNode = nodes_1[_i];
  2151. glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
  2152. if (glTFNodeIndex !== undefined) {
  2153. glTFNode = _this._nodes[glTFNodeIndex];
  2154. if (babylonNode.metadata) {
  2155. if (_this._options.metadataSelector) {
  2156. glTFNode.extras = _this._options.metadataSelector(babylonNode.metadata);
  2157. }
  2158. else if (babylonNode.metadata.gltf) {
  2159. glTFNode.extras = babylonNode.metadata.gltf.extras;
  2160. }
  2161. }
  2162. if (!babylonNode.parent) {
  2163. if (_this._options.shouldExportNode && !_this._options.shouldExportNode(babylonNode)) {
  2164. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Omitting " + babylonNode.name + " from scene.");
  2165. }
  2166. else {
  2167. if (_this._convertToRightHandedSystem) {
  2168. if (glTFNode.translation) {
  2169. glTFNode.translation[2] *= -1;
  2170. glTFNode.translation[0] *= -1;
  2171. }
  2172. 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();
  2173. }
  2174. scene.nodes.push(glTFNodeIndex);
  2175. }
  2176. }
  2177. directDescendents = babylonNode.getDescendants(true);
  2178. if (!glTFNode.children && directDescendents && directDescendents.length) {
  2179. var children = [];
  2180. for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
  2181. var descendent = directDescendents_1[_a];
  2182. if (_this._nodeMap[descendent.uniqueId] != null) {
  2183. children.push(_this._nodeMap[descendent.uniqueId]);
  2184. }
  2185. }
  2186. if (children.length) {
  2187. glTFNode.children = children;
  2188. }
  2189. }
  2190. }
  2191. }
  2192. if (scene.nodes.length) {
  2193. _this._scenes.push(scene);
  2194. }
  2195. });
  2196. });
  2197. };
  2198. /**
  2199. * Creates a mapping of Node unique id to node index and handles animations
  2200. * @param babylonScene Babylon Scene
  2201. * @param nodes Babylon transform nodes
  2202. * @param binaryWriter Buffer to write binary data to
  2203. * @returns Node mapping of unique id to index
  2204. */
  2205. _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, binaryWriter) {
  2206. var _this = this;
  2207. var promiseChain = Promise.resolve();
  2208. var nodeMap = {};
  2209. var nodeIndex;
  2210. var runtimeGLTFAnimation = {
  2211. name: 'runtime animations',
  2212. channels: [],
  2213. samplers: []
  2214. };
  2215. var idleGLTFAnimations = [];
  2216. var _loop_1 = function (babylonNode) {
  2217. if (!this_1._options.shouldExportNode || this_1._options.shouldExportNode(babylonNode)) {
  2218. promiseChain = promiseChain.then(function () {
  2219. return _this.createNodeAsync(babylonNode, binaryWriter).then(function (node) {
  2220. var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode);
  2221. if (promise == null) {
  2222. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Not exporting node " + babylonNode.name);
  2223. return Promise.resolve();
  2224. }
  2225. else {
  2226. return promise.then(function (node) {
  2227. var directDescendents = babylonNode.getDescendants(true, function (node) { return (node instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Node"]); });
  2228. if (directDescendents.length || node.mesh != null || (node.extensions)) {
  2229. _this._nodes.push(node);
  2230. nodeIndex = _this._nodes.length - 1;
  2231. nodeMap[babylonNode.uniqueId] = nodeIndex;
  2232. }
  2233. if (!babylonScene.animationGroups.length && babylonNode.animations.length) {
  2234. _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
  2235. }
  2236. });
  2237. }
  2238. });
  2239. });
  2240. }
  2241. else {
  2242. "Excluding node " + babylonNode.name;
  2243. }
  2244. };
  2245. var this_1 = this;
  2246. for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
  2247. var babylonNode = nodes_2[_i];
  2248. _loop_1(babylonNode);
  2249. }
  2250. return promiseChain.then(function () {
  2251. if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
  2252. _this._animations.push(runtimeGLTFAnimation);
  2253. }
  2254. idleGLTFAnimations.forEach(function (idleGLTFAnimation) {
  2255. if (idleGLTFAnimation.channels.length && idleGLTFAnimation.samplers.length) {
  2256. _this._animations.push(idleGLTFAnimation);
  2257. }
  2258. });
  2259. if (babylonScene.animationGroups.length) {
  2260. _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromAnimationGroups(babylonScene, _this._animations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
  2261. }
  2262. return nodeMap;
  2263. });
  2264. };
  2265. /**
  2266. * Creates a glTF node from a Babylon mesh
  2267. * @param babylonMesh Source Babylon mesh
  2268. * @param binaryWriter Buffer for storing geometry data
  2269. * @returns glTF node
  2270. */
  2271. _Exporter.prototype.createNodeAsync = function (babylonNode, binaryWriter) {
  2272. var _this = this;
  2273. return Promise.resolve().then(function () {
  2274. // create node to hold translation/rotation/scale and the mesh
  2275. var node = {};
  2276. // create mesh
  2277. var mesh = { primitives: [] };
  2278. if (babylonNode.name) {
  2279. node.name = babylonNode.name;
  2280. }
  2281. if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
  2282. // Set transformation
  2283. _this.setNodeTransformation(node, babylonNode);
  2284. return _this.setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(function () {
  2285. if (mesh.primitives.length) {
  2286. _this._meshes.push(mesh);
  2287. node.mesh = _this._meshes.length - 1;
  2288. }
  2289. return node;
  2290. });
  2291. }
  2292. else {
  2293. return node;
  2294. }
  2295. });
  2296. };
  2297. _Exporter._ExtensionNames = new Array();
  2298. _Exporter._ExtensionFactories = {};
  2299. return _Exporter;
  2300. }());
  2301. /**
  2302. * @hidden
  2303. *
  2304. * Stores glTF binary data. If the array buffer byte length is exceeded, it doubles in size dynamically
  2305. */
  2306. var _BinaryWriter = /** @class */ (function () {
  2307. /**
  2308. * Initialize binary writer with an initial byte length
  2309. * @param byteLength Initial byte length of the array buffer
  2310. */
  2311. function _BinaryWriter(byteLength) {
  2312. this._arrayBuffer = new ArrayBuffer(byteLength);
  2313. this._dataView = new DataView(this._arrayBuffer);
  2314. this._byteOffset = 0;
  2315. }
  2316. /**
  2317. * Resize the array buffer to the specified byte length
  2318. * @param byteLength
  2319. */
  2320. _BinaryWriter.prototype.resizeBuffer = function (byteLength) {
  2321. var newBuffer = new ArrayBuffer(byteLength);
  2322. var oldUint8Array = new Uint8Array(this._arrayBuffer);
  2323. var newUint8Array = new Uint8Array(newBuffer);
  2324. for (var i = 0, length_8 = newUint8Array.byteLength; i < length_8; ++i) {
  2325. newUint8Array[i] = oldUint8Array[i];
  2326. }
  2327. this._arrayBuffer = newBuffer;
  2328. this._dataView = new DataView(this._arrayBuffer);
  2329. return newBuffer;
  2330. };
  2331. /**
  2332. * Get an array buffer with the length of the byte offset
  2333. * @returns ArrayBuffer resized to the byte offset
  2334. */
  2335. _BinaryWriter.prototype.getArrayBuffer = function () {
  2336. return this.resizeBuffer(this.getByteOffset());
  2337. };
  2338. /**
  2339. * Get the byte offset of the array buffer
  2340. * @returns byte offset
  2341. */
  2342. _BinaryWriter.prototype.getByteOffset = function () {
  2343. if (this._byteOffset == undefined) {
  2344. throw new Error("Byte offset is undefined!");
  2345. }
  2346. return this._byteOffset;
  2347. };
  2348. /**
  2349. * Stores an UInt8 in the array buffer
  2350. * @param entry
  2351. * @param byteOffset If defined, specifies where to set the value as an offset.
  2352. */
  2353. _BinaryWriter.prototype.setUInt8 = function (entry, byteOffset) {
  2354. if (byteOffset != null) {
  2355. if (byteOffset < this._byteOffset) {
  2356. this._dataView.setUint8(byteOffset, entry);
  2357. }
  2358. else {
  2359. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2360. }
  2361. }
  2362. else {
  2363. if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
  2364. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2365. }
  2366. this._dataView.setUint8(this._byteOffset++, entry);
  2367. }
  2368. };
  2369. /**
  2370. * Gets an UInt32 in the array buffer
  2371. * @param entry
  2372. * @param byteOffset If defined, specifies where to set the value as an offset.
  2373. */
  2374. _BinaryWriter.prototype.getUInt32 = function (byteOffset) {
  2375. if (byteOffset < this._byteOffset) {
  2376. return this._dataView.getUint32(byteOffset, true);
  2377. }
  2378. else {
  2379. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2380. throw new Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2381. }
  2382. };
  2383. _BinaryWriter.prototype.getVector3Float32FromRef = function (vector3, byteOffset) {
  2384. if (byteOffset + 8 > this._byteOffset) {
  2385. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2386. }
  2387. else {
  2388. vector3.x = this._dataView.getFloat32(byteOffset, true);
  2389. vector3.y = this._dataView.getFloat32(byteOffset + 4, true);
  2390. vector3.z = this._dataView.getFloat32(byteOffset + 8, true);
  2391. }
  2392. };
  2393. _BinaryWriter.prototype.setVector3Float32FromRef = function (vector3, byteOffset) {
  2394. if (byteOffset + 8 > this._byteOffset) {
  2395. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2396. }
  2397. else {
  2398. this._dataView.setFloat32(byteOffset, vector3.x, true);
  2399. this._dataView.setFloat32(byteOffset + 4, vector3.y, true);
  2400. this._dataView.setFloat32(byteOffset + 8, vector3.z, true);
  2401. }
  2402. };
  2403. _BinaryWriter.prototype.getVector4Float32FromRef = function (vector4, byteOffset) {
  2404. if (byteOffset + 12 > this._byteOffset) {
  2405. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2406. }
  2407. else {
  2408. vector4.x = this._dataView.getFloat32(byteOffset, true);
  2409. vector4.y = this._dataView.getFloat32(byteOffset + 4, true);
  2410. vector4.z = this._dataView.getFloat32(byteOffset + 8, true);
  2411. vector4.w = this._dataView.getFloat32(byteOffset + 12, true);
  2412. }
  2413. };
  2414. _BinaryWriter.prototype.setVector4Float32FromRef = function (vector4, byteOffset) {
  2415. if (byteOffset + 12 > this._byteOffset) {
  2416. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
  2417. }
  2418. else {
  2419. this._dataView.setFloat32(byteOffset, vector4.x, true);
  2420. this._dataView.setFloat32(byteOffset + 4, vector4.y, true);
  2421. this._dataView.setFloat32(byteOffset + 8, vector4.z, true);
  2422. this._dataView.setFloat32(byteOffset + 12, vector4.w, true);
  2423. }
  2424. };
  2425. /**
  2426. * Stores a Float32 in the array buffer
  2427. * @param entry
  2428. */
  2429. _BinaryWriter.prototype.setFloat32 = function (entry, byteOffset) {
  2430. if (isNaN(entry)) {
  2431. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('Invalid data being written!');
  2432. }
  2433. if (byteOffset != null) {
  2434. if (byteOffset < this._byteOffset) {
  2435. this._dataView.setFloat32(byteOffset, entry, true);
  2436. }
  2437. else {
  2438. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary length!');
  2439. }
  2440. }
  2441. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  2442. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2443. }
  2444. this._dataView.setFloat32(this._byteOffset, entry, true);
  2445. this._byteOffset += 4;
  2446. };
  2447. /**
  2448. * Stores an UInt32 in the array buffer
  2449. * @param entry
  2450. * @param byteOffset If defined, specifies where to set the value as an offset.
  2451. */
  2452. _BinaryWriter.prototype.setUInt32 = function (entry, byteOffset) {
  2453. if (byteOffset != null) {
  2454. if (byteOffset < this._byteOffset) {
  2455. this._dataView.setUint32(byteOffset, entry, true);
  2456. }
  2457. else {
  2458. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error('BinaryWriter: byteoffset is greater than the current binary buffer length!');
  2459. }
  2460. }
  2461. else {
  2462. if (this._byteOffset + 4 > this._arrayBuffer.byteLength) {
  2463. this.resizeBuffer(this._arrayBuffer.byteLength * 2);
  2464. }
  2465. this._dataView.setUint32(this._byteOffset, entry, true);
  2466. this._byteOffset += 4;
  2467. }
  2468. };
  2469. return _BinaryWriter;
  2470. }());
  2471. /***/ }),
  2472. /***/ "./glTF/2.0/glTFExporterExtension.ts":
  2473. /*!*******************************************!*\
  2474. !*** ./glTF/2.0/glTFExporterExtension.ts ***!
  2475. \*******************************************/
  2476. /*! exports provided: __IGLTFExporterExtensionV2 */
  2477. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2478. "use strict";
  2479. __webpack_require__.r(__webpack_exports__);
  2480. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return __IGLTFExporterExtensionV2; });
  2481. /** @hidden */
  2482. var __IGLTFExporterExtensionV2 = 0; // I am here to allow dts to be created
  2483. /***/ }),
  2484. /***/ "./glTF/2.0/glTFMaterialExporter.ts":
  2485. /*!******************************************!*\
  2486. !*** ./glTF/2.0/glTFMaterialExporter.ts ***!
  2487. \******************************************/
  2488. /*! exports provided: _GLTFMaterialExporter */
  2489. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2490. "use strict";
  2491. __webpack_require__.r(__webpack_exports__);
  2492. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _GLTFMaterialExporter; });
  2493. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  2494. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  2495. /**
  2496. * Utility methods for working with glTF material conversion properties. This class should only be used internally
  2497. * @hidden
  2498. */
  2499. var _GLTFMaterialExporter = /** @class */ (function () {
  2500. function _GLTFMaterialExporter(exporter) {
  2501. /**
  2502. * Mapping to store textures
  2503. */
  2504. this._textureMap = {};
  2505. this._textureMap = {};
  2506. this._exporter = exporter;
  2507. }
  2508. /**
  2509. * Specifies if two colors are approximately equal in value
  2510. * @param color1 first color to compare to
  2511. * @param color2 second color to compare to
  2512. * @param epsilon threshold value
  2513. */
  2514. _GLTFMaterialExporter.FuzzyEquals = function (color1, color2, epsilon) {
  2515. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.r, color2.r, epsilon) &&
  2516. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.g, color2.g, epsilon) &&
  2517. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(color1.b, color2.b, epsilon);
  2518. };
  2519. /**
  2520. * Gets the materials from a Babylon scene and converts them to glTF materials
  2521. * @param scene babylonjs scene
  2522. * @param mimeType texture mime type
  2523. * @param images array of images
  2524. * @param textures array of textures
  2525. * @param materials array of materials
  2526. * @param imageData mapping of texture names to base64 textures
  2527. * @param hasTextureCoords specifies if texture coordinates are present on the material
  2528. */
  2529. _GLTFMaterialExporter.prototype._convertMaterialsToGLTFAsync = function (babylonMaterials, mimeType, hasTextureCoords) {
  2530. var promises = [];
  2531. for (var _i = 0, babylonMaterials_1 = babylonMaterials; _i < babylonMaterials_1.length; _i++) {
  2532. var babylonMaterial = babylonMaterials_1[_i];
  2533. if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["StandardMaterial"]) {
  2534. promises.push(this._convertStandardMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2535. }
  2536. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMetallicRoughnessMaterial"]) {
  2537. promises.push(this._convertPBRMetallicRoughnessMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2538. }
  2539. else if (babylonMaterial instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["PBRMaterial"]) {
  2540. promises.push(this._convertPBRMaterialAsync(babylonMaterial, mimeType, hasTextureCoords));
  2541. }
  2542. else {
  2543. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Unsupported material type: " + babylonMaterial.name);
  2544. }
  2545. }
  2546. return Promise.all(promises).then(function () { });
  2547. };
  2548. /**
  2549. * Makes a copy of the glTF material without the texture parameters
  2550. * @param originalMaterial original glTF material
  2551. * @returns glTF material without texture parameters
  2552. */
  2553. _GLTFMaterialExporter.prototype._stripTexturesFromMaterial = function (originalMaterial) {
  2554. var newMaterial = {};
  2555. if (originalMaterial) {
  2556. newMaterial.name = originalMaterial.name;
  2557. newMaterial.doubleSided = originalMaterial.doubleSided;
  2558. newMaterial.alphaMode = originalMaterial.alphaMode;
  2559. newMaterial.alphaCutoff = originalMaterial.alphaCutoff;
  2560. newMaterial.emissiveFactor = originalMaterial.emissiveFactor;
  2561. var originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;
  2562. if (originalPBRMetallicRoughness) {
  2563. newMaterial.pbrMetallicRoughness = {};
  2564. newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;
  2565. newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;
  2566. newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;
  2567. }
  2568. }
  2569. return newMaterial;
  2570. };
  2571. /**
  2572. * Specifies if the material has any texture parameters present
  2573. * @param material glTF Material
  2574. * @returns boolean specifying if texture parameters are present
  2575. */
  2576. _GLTFMaterialExporter.prototype._hasTexturesPresent = function (material) {
  2577. if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {
  2578. return true;
  2579. }
  2580. var pbrMat = material.pbrMetallicRoughness;
  2581. if (pbrMat) {
  2582. if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {
  2583. return true;
  2584. }
  2585. }
  2586. return false;
  2587. };
  2588. /**
  2589. * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
  2590. * @param babylonStandardMaterial
  2591. * @returns glTF Metallic Roughness Material representation
  2592. */
  2593. _GLTFMaterialExporter.prototype._convertToGLTFPBRMetallicRoughness = function (babylonStandardMaterial) {
  2594. var P0 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 1);
  2595. var P1 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 0.1);
  2596. var P2 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](0, 0.1);
  2597. var P3 = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector2"](1300, 0.1);
  2598. /**
  2599. * Given the control points, solve for x based on a given t for a cubic bezier curve
  2600. * @param t a value between 0 and 1
  2601. * @param p0 first control point
  2602. * @param p1 second control point
  2603. * @param p2 third control point
  2604. * @param p3 fourth control point
  2605. * @returns number result of cubic bezier curve at the specified t
  2606. */
  2607. function _cubicBezierCurve(t, p0, p1, p2, p3) {
  2608. return ((1 - t) * (1 - t) * (1 - t) * p0 +
  2609. 3 * (1 - t) * (1 - t) * t * p1 +
  2610. 3 * (1 - t) * t * t * p2 +
  2611. t * t * t * p3);
  2612. }
  2613. /**
  2614. * Evaluates a specified specular power value to determine the appropriate roughness value,
  2615. * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)
  2616. * and roughness on the ordinant axis (y-axis)
  2617. * @param specularPower specular power of standard material
  2618. * @returns Number representing the roughness value
  2619. */
  2620. function _solveForRoughness(specularPower) {
  2621. var t = Math.pow(specularPower / P3.x, 0.333333);
  2622. return _cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);
  2623. }
  2624. var diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace().scale(0.5);
  2625. var opacity = babylonStandardMaterial.alpha;
  2626. var specularPower = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);
  2627. var roughness = _solveForRoughness(specularPower);
  2628. var glTFPbrMetallicRoughness = {
  2629. baseColorFactor: [
  2630. diffuse.r,
  2631. diffuse.g,
  2632. diffuse.b,
  2633. opacity
  2634. ],
  2635. metallicFactor: 0,
  2636. roughnessFactor: roughness,
  2637. };
  2638. return glTFPbrMetallicRoughness;
  2639. };
  2640. /**
  2641. * Computes the metallic factor
  2642. * @param diffuse diffused value
  2643. * @param specular specular value
  2644. * @param oneMinusSpecularStrength one minus the specular strength
  2645. * @returns metallic value
  2646. */
  2647. _GLTFMaterialExporter._SolveMetallic = function (diffuse, specular, oneMinusSpecularStrength) {
  2648. if (specular < this._DielectricSpecular.r) {
  2649. this._DielectricSpecular;
  2650. return 0;
  2651. }
  2652. var a = this._DielectricSpecular.r;
  2653. var b = diffuse * oneMinusSpecularStrength / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;
  2654. var c = this._DielectricSpecular.r - specular;
  2655. var D = b * b - 4.0 * a * c;
  2656. return babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scalar"].Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);
  2657. };
  2658. /**
  2659. * Sets the glTF alpha mode to a glTF material from the Babylon Material
  2660. * @param glTFMaterial glTF material
  2661. * @param babylonMaterial Babylon material
  2662. */
  2663. _GLTFMaterialExporter._SetAlphaMode = function (glTFMaterial, babylonMaterial) {
  2664. if (babylonMaterial.needAlphaBlending()) {
  2665. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  2666. }
  2667. else if (babylonMaterial.needAlphaTesting()) {
  2668. glTFMaterial.alphaMode = "MASK" /* MASK */;
  2669. glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;
  2670. }
  2671. };
  2672. /**
  2673. * Converts a Babylon Standard Material to a glTF Material
  2674. * @param babylonStandardMaterial BJS Standard Material
  2675. * @param mimeType mime type to use for the textures
  2676. * @param images array of glTF image interfaces
  2677. * @param textures array of glTF texture interfaces
  2678. * @param materials array of glTF material interfaces
  2679. * @param imageData map of image file name to data
  2680. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  2681. */
  2682. _GLTFMaterialExporter.prototype._convertStandardMaterialAsync = function (babylonStandardMaterial, mimeType, hasTextureCoords) {
  2683. var materialMap = this._exporter._materialMap;
  2684. var materials = this._exporter._materials;
  2685. var promises = [];
  2686. var glTFPbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);
  2687. var glTFMaterial = { name: babylonStandardMaterial.name };
  2688. if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {
  2689. if (!babylonStandardMaterial.twoSidedLighting) {
  2690. 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.");
  2691. }
  2692. glTFMaterial.doubleSided = true;
  2693. }
  2694. if (hasTextureCoords) {
  2695. if (babylonStandardMaterial.diffuseTexture) {
  2696. promises.push(this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then(function (glTFTexture) {
  2697. if (glTFTexture) {
  2698. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  2699. }
  2700. }));
  2701. }
  2702. if (babylonStandardMaterial.bumpTexture) {
  2703. promises.push(this._exportTextureAsync(babylonStandardMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  2704. if (glTFTexture) {
  2705. glTFMaterial.normalTexture = glTFTexture;
  2706. if (babylonStandardMaterial.bumpTexture != null && babylonStandardMaterial.bumpTexture.level !== 1) {
  2707. glTFMaterial.normalTexture.scale = babylonStandardMaterial.bumpTexture.level;
  2708. }
  2709. }
  2710. }));
  2711. }
  2712. if (babylonStandardMaterial.emissiveTexture) {
  2713. glTFMaterial.emissiveFactor = [1.0, 1.0, 1.0];
  2714. promises.push(this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then(function (glTFEmissiveTexture) {
  2715. if (glTFEmissiveTexture) {
  2716. glTFMaterial.emissiveTexture = glTFEmissiveTexture;
  2717. }
  2718. }));
  2719. }
  2720. if (babylonStandardMaterial.ambientTexture) {
  2721. promises.push(this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  2722. if (glTFTexture) {
  2723. var occlusionTexture = {
  2724. index: glTFTexture.index
  2725. };
  2726. glTFMaterial.occlusionTexture = occlusionTexture;
  2727. occlusionTexture.strength = 1.0;
  2728. }
  2729. }));
  2730. }
  2731. }
  2732. if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {
  2733. if (babylonStandardMaterial.alphaMode === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"].ALPHA_COMBINE) {
  2734. glTFMaterial.alphaMode = "BLEND" /* BLEND */;
  2735. }
  2736. else {
  2737. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(babylonStandardMaterial.name + ": glTF 2.0 does not support alpha mode: " + babylonStandardMaterial.alphaMode.toString());
  2738. }
  2739. }
  2740. if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter.FuzzyEquals(babylonStandardMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  2741. glTFMaterial.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();
  2742. }
  2743. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  2744. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonStandardMaterial);
  2745. materials.push(glTFMaterial);
  2746. materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;
  2747. return Promise.all(promises).then(function () { });
  2748. };
  2749. /**
  2750. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  2751. * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
  2752. * @param mimeType mime type to use for the textures
  2753. * @param images array of glTF image interfaces
  2754. * @param textures array of glTF texture interfaces
  2755. * @param materials array of glTF material interfaces
  2756. * @param imageData map of image file name to data
  2757. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  2758. */
  2759. _GLTFMaterialExporter.prototype._convertPBRMetallicRoughnessMaterialAsync = function (babylonPBRMetalRoughMaterial, mimeType, hasTextureCoords) {
  2760. var materialMap = this._exporter._materialMap;
  2761. var materials = this._exporter._materials;
  2762. var promises = [];
  2763. var glTFPbrMetallicRoughness = {};
  2764. if (babylonPBRMetalRoughMaterial.baseColor) {
  2765. glTFPbrMetallicRoughness.baseColorFactor = [
  2766. babylonPBRMetalRoughMaterial.baseColor.r,
  2767. babylonPBRMetalRoughMaterial.baseColor.g,
  2768. babylonPBRMetalRoughMaterial.baseColor.b,
  2769. babylonPBRMetalRoughMaterial.alpha
  2770. ];
  2771. }
  2772. if (babylonPBRMetalRoughMaterial.metallic != null && babylonPBRMetalRoughMaterial.metallic !== 1) {
  2773. glTFPbrMetallicRoughness.metallicFactor = babylonPBRMetalRoughMaterial.metallic;
  2774. }
  2775. if (babylonPBRMetalRoughMaterial.roughness != null && babylonPBRMetalRoughMaterial.roughness !== 1) {
  2776. glTFPbrMetallicRoughness.roughnessFactor = babylonPBRMetalRoughMaterial.roughness;
  2777. }
  2778. var glTFMaterial = {
  2779. name: babylonPBRMetalRoughMaterial.name
  2780. };
  2781. if (babylonPBRMetalRoughMaterial.doubleSided) {
  2782. glTFMaterial.doubleSided = babylonPBRMetalRoughMaterial.doubleSided;
  2783. }
  2784. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMetalRoughMaterial);
  2785. if (hasTextureCoords) {
  2786. if (babylonPBRMetalRoughMaterial.baseTexture != null) {
  2787. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.baseTexture, mimeType).then(function (glTFTexture) {
  2788. if (glTFTexture) {
  2789. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  2790. }
  2791. }));
  2792. }
  2793. if (babylonPBRMetalRoughMaterial.normalTexture) {
  2794. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.normalTexture, mimeType).then(function (glTFTexture) {
  2795. if (glTFTexture) {
  2796. glTFMaterial.normalTexture = glTFTexture;
  2797. if (babylonPBRMetalRoughMaterial.normalTexture.level !== 1) {
  2798. glTFMaterial.normalTexture.scale = babylonPBRMetalRoughMaterial.normalTexture.level;
  2799. }
  2800. }
  2801. }));
  2802. }
  2803. if (babylonPBRMetalRoughMaterial.occlusionTexture) {
  2804. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.occlusionTexture, mimeType).then(function (glTFTexture) {
  2805. if (glTFTexture) {
  2806. glTFMaterial.occlusionTexture = glTFTexture;
  2807. if (babylonPBRMetalRoughMaterial.occlusionStrength != null) {
  2808. glTFMaterial.occlusionTexture.strength = babylonPBRMetalRoughMaterial.occlusionStrength;
  2809. }
  2810. }
  2811. }));
  2812. }
  2813. if (babylonPBRMetalRoughMaterial.emissiveTexture) {
  2814. promises.push(this._exportTextureAsync(babylonPBRMetalRoughMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  2815. if (glTFTexture) {
  2816. glTFMaterial.emissiveTexture = glTFTexture;
  2817. }
  2818. }));
  2819. }
  2820. }
  2821. if (_GLTFMaterialExporter.FuzzyEquals(babylonPBRMetalRoughMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  2822. glTFMaterial.emissiveFactor = babylonPBRMetalRoughMaterial.emissiveColor.asArray();
  2823. }
  2824. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  2825. materials.push(glTFMaterial);
  2826. materialMap[babylonPBRMetalRoughMaterial.uniqueId] = materials.length - 1;
  2827. return Promise.all(promises).then(function () { });
  2828. };
  2829. /**
  2830. * Converts an image typed array buffer to a base64 image
  2831. * @param buffer typed array buffer
  2832. * @param width width of the image
  2833. * @param height height of the image
  2834. * @param mimeType mimetype of the image
  2835. * @returns base64 image string
  2836. */
  2837. _GLTFMaterialExporter.prototype._createBase64FromCanvasAsync = function (buffer, width, height, mimeType) {
  2838. var _this = this;
  2839. return new Promise(function (resolve, reject) {
  2840. var hostingScene;
  2841. var textureType = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"].TEXTURETYPE_UNSIGNED_INT;
  2842. var engine = _this._exporter._getLocalEngine();
  2843. hostingScene = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Scene"](engine);
  2844. // Create a temporary texture with the texture buffer data
  2845. 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);
  2846. 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);
  2847. postProcess.getEffect().executeWhenCompiled(function () {
  2848. postProcess.onApply = function (effect) {
  2849. effect._bindTexture("textureSampler", tempTexture);
  2850. };
  2851. // Set the size of the texture
  2852. engine.setSize(width, height);
  2853. hostingScene.postProcessManager.directRender([postProcess], null);
  2854. postProcess.dispose();
  2855. tempTexture.dispose();
  2856. // Read data from WebGL
  2857. var canvas = engine.getRenderingCanvas();
  2858. if (canvas) {
  2859. if (!canvas.toBlob) { // fallback for browsers without "canvas.toBlob"
  2860. var dataURL = canvas.toDataURL();
  2861. resolve(dataURL);
  2862. }
  2863. else {
  2864. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].ToBlob(canvas, function (blob) {
  2865. if (blob) {
  2866. var fileReader = new FileReader();
  2867. fileReader.onload = function (event) {
  2868. var base64String = event.target.result;
  2869. hostingScene.dispose();
  2870. resolve(base64String);
  2871. };
  2872. fileReader.readAsDataURL(blob);
  2873. }
  2874. else {
  2875. reject("gltfMaterialExporter: Failed to get blob from image canvas!");
  2876. }
  2877. });
  2878. }
  2879. }
  2880. else {
  2881. reject("Engine is missing a canvas!");
  2882. }
  2883. });
  2884. });
  2885. };
  2886. /**
  2887. * Generates a white texture based on the specified width and height
  2888. * @param width width of the texture in pixels
  2889. * @param height height of the texture in pixels
  2890. * @param scene babylonjs scene
  2891. * @returns white texture
  2892. */
  2893. _GLTFMaterialExporter.prototype._createWhiteTexture = function (width, height, scene) {
  2894. var data = new Uint8Array(width * height * 4);
  2895. for (var i = 0; i < data.length; i = i + 4) {
  2896. data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xFF;
  2897. }
  2898. var rawTexture = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["RawTexture"].CreateRGBATexture(data, width, height, scene);
  2899. return rawTexture;
  2900. };
  2901. /**
  2902. * 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
  2903. * @param texture1 first texture to resize
  2904. * @param texture2 second texture to resize
  2905. * @param scene babylonjs scene
  2906. * @returns resized textures or null
  2907. */
  2908. _GLTFMaterialExporter.prototype._resizeTexturesToSameDimensions = function (texture1, texture2, scene) {
  2909. var texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };
  2910. var texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };
  2911. var resizedTexture1;
  2912. var resizedTexture2;
  2913. if (texture1Size.width < texture2Size.width) {
  2914. if (texture1 && texture1 instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"]) {
  2915. resizedTexture1 = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TextureTools"].CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);
  2916. }
  2917. else {
  2918. resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);
  2919. }
  2920. resizedTexture2 = texture2;
  2921. }
  2922. else if (texture1Size.width > texture2Size.width) {
  2923. if (texture2 && texture2 instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"]) {
  2924. resizedTexture2 = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TextureTools"].CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);
  2925. }
  2926. else {
  2927. resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);
  2928. }
  2929. resizedTexture1 = texture1;
  2930. }
  2931. else {
  2932. resizedTexture1 = texture1;
  2933. resizedTexture2 = texture2;
  2934. }
  2935. return {
  2936. "texture1": resizedTexture1,
  2937. "texture2": resizedTexture2
  2938. };
  2939. };
  2940. /**
  2941. * Converts an array of pixels to a Float32Array
  2942. * Throws an error if the pixel format is not supported
  2943. * @param pixels - array buffer containing pixel values
  2944. * @returns Float32 of pixels
  2945. */
  2946. _GLTFMaterialExporter.prototype._convertPixelArrayToFloat32 = function (pixels) {
  2947. if (pixels instanceof Uint8Array) {
  2948. var length_1 = pixels.length;
  2949. var buffer = new Float32Array(pixels.length);
  2950. for (var i = 0; i < length_1; ++i) {
  2951. buffer[i] = pixels[i] / 255;
  2952. }
  2953. return buffer;
  2954. }
  2955. else if (pixels instanceof Float32Array) {
  2956. return pixels;
  2957. }
  2958. else {
  2959. throw new Error('Unsupported pixel format!');
  2960. }
  2961. };
  2962. /**
  2963. * Convert Specular Glossiness Textures to Metallic Roughness
  2964. * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness
  2965. * @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js
  2966. * @param diffuseTexture texture used to store diffuse information
  2967. * @param specularGlossinessTexture texture used to store specular and glossiness information
  2968. * @param factors specular glossiness material factors
  2969. * @param mimeType the mime type to use for the texture
  2970. * @returns pbr metallic roughness interface or null
  2971. */
  2972. _GLTFMaterialExporter.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync = function (diffuseTexture, specularGlossinessTexture, factors, mimeType) {
  2973. var promises = [];
  2974. if (!(diffuseTexture || specularGlossinessTexture)) {
  2975. return Promise.reject('_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!');
  2976. }
  2977. var scene = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;
  2978. if (scene) {
  2979. var resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);
  2980. var diffuseSize = resizedTextures.texture1.getSize();
  2981. var diffuseBuffer = void 0;
  2982. var specularGlossinessBuffer = void 0;
  2983. var width = diffuseSize.width;
  2984. var height = diffuseSize.height;
  2985. var diffusePixels = resizedTextures.texture1.readPixels();
  2986. var specularPixels = resizedTextures.texture2.readPixels();
  2987. if (diffusePixels) {
  2988. diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);
  2989. }
  2990. else {
  2991. return Promise.reject("Failed to retrieve pixels from diffuse texture!");
  2992. }
  2993. if (specularPixels) {
  2994. specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);
  2995. }
  2996. else {
  2997. return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");
  2998. }
  2999. var byteLength = specularGlossinessBuffer.byteLength;
  3000. var metallicRoughnessBuffer = new Uint8Array(byteLength);
  3001. var baseColorBuffer = new Uint8Array(byteLength);
  3002. var strideSize = 4;
  3003. var maxBaseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black();
  3004. var maxMetallic = 0;
  3005. var maxRoughness = 0;
  3006. for (var h = 0; h < height; ++h) {
  3007. for (var w = 0; w < width; ++w) {
  3008. var offset = (width * h + w) * strideSize;
  3009. var diffuseColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2]).toLinearSpace().multiply(factors.diffuseColor);
  3010. var specularColor = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2]).toLinearSpace().multiply(factors.specularColor);
  3011. var glossiness = (specularGlossinessBuffer[offset + 3]) * factors.glossiness;
  3012. var specularGlossiness = {
  3013. diffuseColor: diffuseColor,
  3014. specularColor: specularColor,
  3015. glossiness: glossiness
  3016. };
  3017. var metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);
  3018. maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);
  3019. maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);
  3020. maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);
  3021. maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic);
  3022. maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness);
  3023. baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;
  3024. baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;
  3025. baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;
  3026. baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;
  3027. metallicRoughnessBuffer[offset] = 0;
  3028. metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness * 255;
  3029. metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic * 255;
  3030. metallicRoughnessBuffer[offset + 3] = 255;
  3031. }
  3032. }
  3033. // Retrieves the metallic roughness factors from the maximum texture values.
  3034. var metallicRoughnessFactors_1 = {
  3035. baseColor: maxBaseColor,
  3036. metallic: maxMetallic,
  3037. roughness: maxRoughness
  3038. };
  3039. var writeOutMetallicRoughnessTexture = false;
  3040. var writeOutBaseColorTexture = false;
  3041. for (var h = 0; h < height; ++h) {
  3042. for (var w = 0; w < width; ++w) {
  3043. var destinationOffset = (width * h + w) * strideSize;
  3044. baseColorBuffer[destinationOffset] /= metallicRoughnessFactors_1.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.r : 1;
  3045. baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.g : 1;
  3046. baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.baseColor.b : 1;
  3047. var linearBaseColorPixel = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromInts(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);
  3048. var sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace();
  3049. baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;
  3050. baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;
  3051. baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;
  3052. if (!_GLTFMaterialExporter.FuzzyEquals(sRGBBaseColorPixel, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  3053. writeOutBaseColorTexture = true;
  3054. }
  3055. metallicRoughnessBuffer[destinationOffset + 1] /= metallicRoughnessFactors_1.roughness > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.roughness : 1;
  3056. metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors_1.metallic > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors_1.metallic : 1;
  3057. var metallicRoughnessPixel = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);
  3058. if (!_GLTFMaterialExporter.FuzzyEquals(metallicRoughnessPixel, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon)) {
  3059. writeOutMetallicRoughnessTexture = true;
  3060. }
  3061. }
  3062. }
  3063. if (writeOutMetallicRoughnessTexture) {
  3064. var promise = this._createBase64FromCanvasAsync(metallicRoughnessBuffer, width, height, mimeType).then(function (metallicRoughnessBase64) {
  3065. metallicRoughnessFactors_1.metallicRoughnessTextureBase64 = metallicRoughnessBase64;
  3066. });
  3067. promises.push(promise);
  3068. }
  3069. if (writeOutBaseColorTexture) {
  3070. var promise = this._createBase64FromCanvasAsync(baseColorBuffer, width, height, mimeType).then(function (baseColorBase64) {
  3071. metallicRoughnessFactors_1.baseColorTextureBase64 = baseColorBase64;
  3072. });
  3073. promises.push(promise);
  3074. }
  3075. return Promise.all(promises).then(function () {
  3076. return metallicRoughnessFactors_1;
  3077. });
  3078. }
  3079. else {
  3080. return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");
  3081. }
  3082. };
  3083. /**
  3084. * Converts specular glossiness material properties to metallic roughness
  3085. * @param specularGlossiness interface with specular glossiness material properties
  3086. * @returns interface with metallic roughness material properties
  3087. */
  3088. _GLTFMaterialExporter.prototype._convertSpecularGlossinessToMetallicRoughness = function (specularGlossiness) {
  3089. var diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);
  3090. var specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);
  3091. var oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);
  3092. var metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);
  3093. var baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon));
  3094. var baseColorFromSpecular = specularGlossiness.specularColor.subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic)).scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));
  3095. var baseColor = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);
  3096. baseColor = baseColor.clampToRef(0, 1, baseColor);
  3097. var metallicRoughness = {
  3098. baseColor: baseColor,
  3099. metallic: metallic,
  3100. roughness: 1 - specularGlossiness.glossiness
  3101. };
  3102. return metallicRoughness;
  3103. };
  3104. /**
  3105. * Calculates the surface reflectance, independent of lighting conditions
  3106. * @param color Color source to calculate brightness from
  3107. * @returns number representing the perceived brightness, or zero if color is undefined
  3108. */
  3109. _GLTFMaterialExporter.prototype._getPerceivedBrightness = function (color) {
  3110. if (color) {
  3111. return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);
  3112. }
  3113. return 0;
  3114. };
  3115. /**
  3116. * Returns the maximum color component value
  3117. * @param color
  3118. * @returns maximum color component value, or zero if color is null or undefined
  3119. */
  3120. _GLTFMaterialExporter.prototype._getMaxComponent = function (color) {
  3121. if (color) {
  3122. return Math.max(color.r, Math.max(color.g, color.b));
  3123. }
  3124. return 0;
  3125. };
  3126. /**
  3127. * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors
  3128. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3129. * @param mimeType mime type to use for the textures
  3130. * @param images array of glTF image interfaces
  3131. * @param textures array of glTF texture interfaces
  3132. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  3133. * @param imageData map of image file name to data
  3134. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3135. * @returns glTF PBR Metallic Roughness factors
  3136. */
  3137. _GLTFMaterialExporter.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  3138. var promises = [];
  3139. var metallicRoughness = {
  3140. baseColor: babylonPBRMaterial.albedoColor,
  3141. metallic: babylonPBRMaterial.metallic,
  3142. roughness: babylonPBRMaterial.roughness
  3143. };
  3144. if (hasTextureCoords) {
  3145. if (babylonPBRMaterial.albedoTexture) {
  3146. promises.push(this._exportTextureAsync(babylonPBRMaterial.albedoTexture, mimeType).then(function (glTFTexture) {
  3147. if (glTFTexture) {
  3148. glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
  3149. }
  3150. }));
  3151. }
  3152. if (babylonPBRMaterial.metallicTexture) {
  3153. promises.push(this._exportTextureAsync(babylonPBRMaterial.metallicTexture, mimeType).then(function (glTFTexture) {
  3154. if (glTFTexture) {
  3155. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;
  3156. }
  3157. }));
  3158. }
  3159. }
  3160. return Promise.all(promises).then(function () {
  3161. return metallicRoughness;
  3162. });
  3163. };
  3164. _GLTFMaterialExporter.prototype._getGLTFTextureSampler = function (texture) {
  3165. var sampler = this._getGLTFTextureWrapModesSampler(texture);
  3166. var samplingMode = texture instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"] ? texture.samplingMode : null;
  3167. if (samplingMode != null) {
  3168. switch (samplingMode) {
  3169. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR: {
  3170. sampler.magFilter = 9729 /* LINEAR */;
  3171. sampler.minFilter = 9729 /* LINEAR */;
  3172. break;
  3173. }
  3174. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST: {
  3175. sampler.magFilter = 9729 /* LINEAR */;
  3176. sampler.minFilter = 9728 /* NEAREST */;
  3177. break;
  3178. }
  3179. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR: {
  3180. sampler.magFilter = 9728 /* NEAREST */;
  3181. sampler.minFilter = 9729 /* LINEAR */;
  3182. break;
  3183. }
  3184. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPLINEAR: {
  3185. sampler.magFilter = 9728 /* NEAREST */;
  3186. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  3187. break;
  3188. }
  3189. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST: {
  3190. sampler.magFilter = 9728 /* NEAREST */;
  3191. sampler.minFilter = 9728 /* NEAREST */;
  3192. break;
  3193. }
  3194. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_LINEAR_MIPNEAREST: {
  3195. sampler.magFilter = 9728 /* NEAREST */;
  3196. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  3197. break;
  3198. }
  3199. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPNEAREST: {
  3200. sampler.magFilter = 9729 /* LINEAR */;
  3201. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  3202. break;
  3203. }
  3204. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_NEAREST_MIPLINEAR: {
  3205. sampler.magFilter = 9729 /* LINEAR */;
  3206. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  3207. break;
  3208. }
  3209. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPLINEAR: {
  3210. sampler.magFilter = 9728 /* NEAREST */;
  3211. sampler.minFilter = 9986 /* NEAREST_MIPMAP_LINEAR */;
  3212. break;
  3213. }
  3214. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPLINEAR: {
  3215. sampler.magFilter = 9729 /* LINEAR */;
  3216. sampler.minFilter = 9987 /* LINEAR_MIPMAP_LINEAR */;
  3217. break;
  3218. }
  3219. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].LINEAR_LINEAR_MIPNEAREST: {
  3220. sampler.magFilter = 9729 /* LINEAR */;
  3221. sampler.minFilter = 9985 /* LINEAR_MIPMAP_NEAREST */;
  3222. break;
  3223. }
  3224. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].NEAREST_NEAREST_MIPNEAREST: {
  3225. sampler.magFilter = 9728 /* NEAREST */;
  3226. sampler.minFilter = 9984 /* NEAREST_MIPMAP_NEAREST */;
  3227. break;
  3228. }
  3229. }
  3230. }
  3231. return sampler;
  3232. };
  3233. _GLTFMaterialExporter.prototype._getGLTFTextureWrapMode = function (wrapMode) {
  3234. switch (wrapMode) {
  3235. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].WRAP_ADDRESSMODE: {
  3236. return 10497 /* REPEAT */;
  3237. }
  3238. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].CLAMP_ADDRESSMODE: {
  3239. return 33071 /* CLAMP_TO_EDGE */;
  3240. }
  3241. case babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Texture"].MIRROR_ADDRESSMODE: {
  3242. return 33648 /* MIRRORED_REPEAT */;
  3243. }
  3244. default: {
  3245. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported Texture Wrap Mode " + wrapMode + "!");
  3246. return 10497 /* REPEAT */;
  3247. }
  3248. }
  3249. };
  3250. _GLTFMaterialExporter.prototype._getGLTFTextureWrapModesSampler = function (texture) {
  3251. 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);
  3252. 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);
  3253. if (wrapS === 10497 /* REPEAT */ && wrapT === 10497 /* REPEAT */) { // default wrapping mode in glTF, so omitting
  3254. return {};
  3255. }
  3256. return { wrapS: wrapS, wrapT: wrapT };
  3257. };
  3258. /**
  3259. * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors
  3260. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3261. * @param mimeType mime type to use for the textures
  3262. * @param images array of glTF image interfaces
  3263. * @param textures array of glTF texture interfaces
  3264. * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface
  3265. * @param imageData map of image file name to data
  3266. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3267. * @returns glTF PBR Metallic Roughness factors
  3268. */
  3269. _GLTFMaterialExporter.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync = function (babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords) {
  3270. var _this = this;
  3271. return Promise.resolve().then(function () {
  3272. var samplers = _this._exporter._samplers;
  3273. var textures = _this._exporter._textures;
  3274. var specGloss = {
  3275. diffuseColor: babylonPBRMaterial.albedoColor || babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(),
  3276. specularColor: babylonPBRMaterial.reflectivityColor || babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(),
  3277. glossiness: babylonPBRMaterial.microSurface || 1,
  3278. };
  3279. var samplerIndex = null;
  3280. var sampler = _this._getGLTFTextureSampler(babylonPBRMaterial.albedoTexture);
  3281. if (sampler.magFilter != null && sampler.minFilter != null && sampler.wrapS != null && sampler.wrapT != null) {
  3282. samplers.push(sampler);
  3283. samplerIndex = samplers.length - 1;
  3284. }
  3285. if (babylonPBRMaterial.reflectivityTexture && !babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha) {
  3286. return Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported");
  3287. }
  3288. if ((babylonPBRMaterial.albedoTexture || babylonPBRMaterial.reflectivityTexture) && hasTextureCoords) {
  3289. return _this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(babylonPBRMaterial.albedoTexture, babylonPBRMaterial.reflectivityTexture, specGloss, mimeType).then(function (metallicRoughnessFactors) {
  3290. if (metallicRoughnessFactors.baseColorTextureBase64) {
  3291. var glTFBaseColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.baseColorTextureBase64, "bjsBaseColorTexture_" + (textures.length) + ".png", mimeType, babylonPBRMaterial.albedoTexture ? babylonPBRMaterial.albedoTexture.coordinatesIndex : null, samplerIndex);
  3292. if (glTFBaseColorTexture) {
  3293. glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
  3294. }
  3295. }
  3296. if (metallicRoughnessFactors.metallicRoughnessTextureBase64) {
  3297. var glTFMRColorTexture = _this._getTextureInfoFromBase64(metallicRoughnessFactors.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + (textures.length) + ".png", mimeType, babylonPBRMaterial.reflectivityTexture ? babylonPBRMaterial.reflectivityTexture.coordinatesIndex : null, samplerIndex);
  3298. if (glTFMRColorTexture) {
  3299. glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
  3300. }
  3301. }
  3302. return metallicRoughnessFactors;
  3303. });
  3304. }
  3305. else {
  3306. return _this._convertSpecularGlossinessToMetallicRoughness(specGloss);
  3307. }
  3308. });
  3309. };
  3310. /**
  3311. * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
  3312. * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
  3313. * @param mimeType mime type to use for the textures
  3314. * @param images array of glTF image interfaces
  3315. * @param textures array of glTF texture interfaces
  3316. * @param materials array of glTF material interfaces
  3317. * @param imageData map of image file name to data
  3318. * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
  3319. */
  3320. _GLTFMaterialExporter.prototype._convertPBRMaterialAsync = function (babylonPBRMaterial, mimeType, hasTextureCoords) {
  3321. var _this = this;
  3322. var glTFPbrMetallicRoughness = {};
  3323. var glTFMaterial = {
  3324. name: babylonPBRMaterial.name
  3325. };
  3326. var useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();
  3327. if (useMetallicRoughness) {
  3328. if (babylonPBRMaterial.albedoColor) {
  3329. glTFPbrMetallicRoughness.baseColorFactor = [
  3330. babylonPBRMaterial.albedoColor.r,
  3331. babylonPBRMaterial.albedoColor.g,
  3332. babylonPBRMaterial.albedoColor.b,
  3333. babylonPBRMaterial.alpha
  3334. ];
  3335. }
  3336. return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  3337. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  3338. });
  3339. }
  3340. else {
  3341. return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then(function (metallicRoughness) {
  3342. return _this.setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);
  3343. });
  3344. }
  3345. };
  3346. _GLTFMaterialExporter.prototype.setMetallicRoughnessPbrMaterial = function (metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords) {
  3347. var materialMap = this._exporter._materialMap;
  3348. var materials = this._exporter._materials;
  3349. var promises = [];
  3350. if (metallicRoughness) {
  3351. _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial);
  3352. if (!(_GLTFMaterialExporter.FuzzyEquals(metallicRoughness.baseColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White(), _GLTFMaterialExporter._Epsilon) && babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon)) {
  3353. glTFPbrMetallicRoughness.baseColorFactor = [
  3354. metallicRoughness.baseColor.r,
  3355. metallicRoughness.baseColor.g,
  3356. metallicRoughness.baseColor.b,
  3357. babylonPBRMaterial.alpha
  3358. ];
  3359. }
  3360. if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {
  3361. glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;
  3362. }
  3363. if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {
  3364. glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;
  3365. }
  3366. if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {
  3367. if (!babylonPBRMaterial.twoSidedLighting) {
  3368. 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.");
  3369. }
  3370. glTFMaterial.doubleSided = true;
  3371. }
  3372. if (hasTextureCoords) {
  3373. if (babylonPBRMaterial.bumpTexture) {
  3374. var promise = this._exportTextureAsync(babylonPBRMaterial.bumpTexture, mimeType).then(function (glTFTexture) {
  3375. if (glTFTexture) {
  3376. glTFMaterial.normalTexture = glTFTexture;
  3377. if (babylonPBRMaterial.bumpTexture.level !== 1) {
  3378. glTFMaterial.normalTexture.scale = babylonPBRMaterial.bumpTexture.level;
  3379. }
  3380. }
  3381. });
  3382. promises.push(promise);
  3383. }
  3384. if (babylonPBRMaterial.ambientTexture) {
  3385. var promise = this._exportTextureAsync(babylonPBRMaterial.ambientTexture, mimeType).then(function (glTFTexture) {
  3386. if (glTFTexture) {
  3387. var occlusionTexture = {
  3388. index: glTFTexture.index
  3389. };
  3390. glTFMaterial.occlusionTexture = occlusionTexture;
  3391. if (babylonPBRMaterial.ambientTextureStrength) {
  3392. occlusionTexture.strength = babylonPBRMaterial.ambientTextureStrength;
  3393. }
  3394. }
  3395. });
  3396. promises.push(promise);
  3397. }
  3398. if (babylonPBRMaterial.emissiveTexture) {
  3399. var promise = this._exportTextureAsync(babylonPBRMaterial.emissiveTexture, mimeType).then(function (glTFTexture) {
  3400. if (glTFTexture) {
  3401. glTFMaterial.emissiveTexture = glTFTexture;
  3402. }
  3403. });
  3404. promises.push(promise);
  3405. }
  3406. }
  3407. if (!_GLTFMaterialExporter.FuzzyEquals(babylonPBRMaterial.emissiveColor, babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].Black(), _GLTFMaterialExporter._Epsilon)) {
  3408. glTFMaterial.emissiveFactor = babylonPBRMaterial.emissiveColor.asArray();
  3409. }
  3410. glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
  3411. materials.push(glTFMaterial);
  3412. materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;
  3413. }
  3414. return Promise.all(promises).then(function (result) { });
  3415. };
  3416. _GLTFMaterialExporter.prototype.getPixelsFromTexture = function (babylonTexture) {
  3417. var pixels = babylonTexture.textureType === babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Engine"].TEXTURETYPE_UNSIGNED_INT ? babylonTexture.readPixels() : babylonTexture.readPixels();
  3418. return pixels;
  3419. };
  3420. /**
  3421. * Extracts a texture from a Babylon texture into file data and glTF data
  3422. * @param babylonTexture Babylon texture to extract
  3423. * @param mimeType Mime Type of the babylonTexture
  3424. * @return glTF texture info, or null if the texture format is not supported
  3425. */
  3426. _GLTFMaterialExporter.prototype._exportTextureAsync = function (babylonTexture, mimeType) {
  3427. var _this = this;
  3428. var extensionPromise = this._exporter._extensionsPreExportTextureAsync("exporter", babylonTexture, mimeType);
  3429. if (!extensionPromise) {
  3430. return this._exportTextureInfoAsync(babylonTexture, mimeType);
  3431. }
  3432. return extensionPromise.then(function (texture) {
  3433. if (!texture) {
  3434. return _this._exportTextureInfoAsync(babylonTexture, mimeType);
  3435. }
  3436. return _this._exportTextureInfoAsync(texture, mimeType);
  3437. });
  3438. };
  3439. _GLTFMaterialExporter.prototype._exportTextureInfoAsync = function (babylonTexture, mimeType) {
  3440. var _this = this;
  3441. return Promise.resolve().then(function () {
  3442. var textureUid = babylonTexture.uid;
  3443. if (textureUid in _this._textureMap) {
  3444. return _this._textureMap[textureUid];
  3445. }
  3446. else {
  3447. var samplers = _this._exporter._samplers;
  3448. var sampler = _this._getGLTFTextureSampler(babylonTexture);
  3449. var samplerIndex_1 = null;
  3450. // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler
  3451. var foundSamplerIndex = null;
  3452. for (var i = 0; i < samplers.length; ++i) {
  3453. var s = samplers[i];
  3454. if (s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter &&
  3455. s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT) {
  3456. foundSamplerIndex = i;
  3457. break;
  3458. }
  3459. }
  3460. if (foundSamplerIndex == null) {
  3461. samplers.push(sampler);
  3462. samplerIndex_1 = samplers.length - 1;
  3463. }
  3464. else {
  3465. samplerIndex_1 = foundSamplerIndex;
  3466. }
  3467. var pixels = _this.getPixelsFromTexture(babylonTexture);
  3468. var size = babylonTexture.getSize();
  3469. return _this._createBase64FromCanvasAsync(pixels, size.width, size.height, mimeType).then(function (base64Data) {
  3470. var textureInfo = _this._getTextureInfoFromBase64(base64Data, babylonTexture.name.replace(/\.\/|\/|\.\\|\\/g, "_"), mimeType, babylonTexture.coordinatesIndex, samplerIndex_1);
  3471. if (textureInfo) {
  3472. _this._textureMap[textureUid] = textureInfo;
  3473. }
  3474. return textureInfo;
  3475. });
  3476. }
  3477. });
  3478. };
  3479. /**
  3480. * Builds a texture from base64 string
  3481. * @param base64Texture base64 texture string
  3482. * @param baseTextureName Name to use for the texture
  3483. * @param mimeType image mime type for the texture
  3484. * @param images array of images
  3485. * @param textures array of textures
  3486. * @param imageData map of image data
  3487. * @returns glTF texture info, or null if the texture format is not supported
  3488. */
  3489. _GLTFMaterialExporter.prototype._getTextureInfoFromBase64 = function (base64Texture, baseTextureName, mimeType, texCoordIndex, samplerIndex) {
  3490. var textures = this._exporter._textures;
  3491. var images = this._exporter._images;
  3492. var imageData = this._exporter._imageData;
  3493. var textureInfo = null;
  3494. var glTFTexture = {
  3495. source: images.length,
  3496. name: baseTextureName
  3497. };
  3498. if (samplerIndex != null) {
  3499. glTFTexture.sampler = samplerIndex;
  3500. }
  3501. var binStr = atob(base64Texture.split(',')[1]);
  3502. var arrBuff = new ArrayBuffer(binStr.length);
  3503. var arr = new Uint8Array(arrBuff);
  3504. for (var i = 0, length_2 = binStr.length; i < length_2; ++i) {
  3505. arr[i] = binStr.charCodeAt(i);
  3506. }
  3507. var imageValues = { data: arr, mimeType: mimeType };
  3508. var extension = mimeType === "image/jpeg" /* JPEG */ ? '.jpeg' : '.png';
  3509. var textureName = baseTextureName + extension;
  3510. var originalTextureName = textureName;
  3511. if (textureName in imageData) {
  3512. textureName = baseTextureName + "_" + babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].RandomId() + extension;
  3513. }
  3514. imageData[textureName] = imageValues;
  3515. if (mimeType === "image/jpeg" /* JPEG */ || mimeType === "image/png" /* PNG */) {
  3516. var glTFImage = {
  3517. name: baseTextureName,
  3518. uri: textureName
  3519. };
  3520. var foundIndex = null;
  3521. for (var i = 0; i < images.length; ++i) {
  3522. if (images[i].uri === originalTextureName) {
  3523. foundIndex = i;
  3524. break;
  3525. }
  3526. }
  3527. if (foundIndex == null) {
  3528. images.push(glTFImage);
  3529. glTFTexture.source = images.length - 1;
  3530. }
  3531. else {
  3532. glTFTexture.source = foundIndex;
  3533. }
  3534. textures.push(glTFTexture);
  3535. textureInfo = {
  3536. index: textures.length - 1
  3537. };
  3538. if (texCoordIndex != null) {
  3539. textureInfo.texCoord = texCoordIndex;
  3540. }
  3541. }
  3542. else {
  3543. babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Error("Unsupported texture mime type " + mimeType);
  3544. }
  3545. return textureInfo;
  3546. };
  3547. /**
  3548. * Represents the dielectric specular values for R, G and B
  3549. */
  3550. _GLTFMaterialExporter._DielectricSpecular = new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"](0.04, 0.04, 0.04);
  3551. /**
  3552. * Allows the maximum specular power to be defined for material calculations
  3553. */
  3554. _GLTFMaterialExporter._MaxSpecularPower = 1024;
  3555. /**
  3556. * Numeric tolerance value
  3557. */
  3558. _GLTFMaterialExporter._Epsilon = 1e-6;
  3559. return _GLTFMaterialExporter;
  3560. }());
  3561. /***/ }),
  3562. /***/ "./glTF/2.0/glTFSerializer.ts":
  3563. /*!************************************!*\
  3564. !*** ./glTF/2.0/glTFSerializer.ts ***!
  3565. \************************************/
  3566. /*! exports provided: GLTF2Export */
  3567. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3568. "use strict";
  3569. __webpack_require__.r(__webpack_exports__);
  3570. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return GLTF2Export; });
  3571. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  3572. /**
  3573. * Class for generating glTF data from a Babylon scene.
  3574. */
  3575. var GLTF2Export = /** @class */ (function () {
  3576. function GLTF2Export() {
  3577. }
  3578. /**
  3579. * Exports the geometry of the scene to .gltf file format asynchronously
  3580. * @param scene Babylon scene with scene hierarchy information
  3581. * @param filePrefix File prefix to use when generating the glTF file
  3582. * @param options Exporter options
  3583. * @returns Returns an object with a .gltf file and associates texture names
  3584. * as keys and their data and paths as values
  3585. */
  3586. GLTF2Export.GLTFAsync = function (scene, filePrefix, options) {
  3587. return scene.whenReadyAsync().then(function () {
  3588. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  3589. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  3590. return gltfGenerator._generateGLTFAsync(glTFPrefix);
  3591. });
  3592. };
  3593. GLTF2Export._PreExportAsync = function (scene, options) {
  3594. return Promise.resolve().then(function () {
  3595. if (options && options.exportWithoutWaitingForScene) {
  3596. return Promise.resolve();
  3597. }
  3598. else {
  3599. return scene.whenReadyAsync();
  3600. }
  3601. });
  3602. };
  3603. GLTF2Export._PostExportAsync = function (scene, glTFData, options) {
  3604. return Promise.resolve().then(function () {
  3605. if (options && options.exportWithoutWaitingForScene) {
  3606. return glTFData;
  3607. }
  3608. else {
  3609. return glTFData;
  3610. }
  3611. });
  3612. };
  3613. /**
  3614. * Exports the geometry of the scene to .glb file format asychronously
  3615. * @param scene Babylon scene with scene hierarchy information
  3616. * @param filePrefix File prefix to use when generating glb file
  3617. * @param options Exporter options
  3618. * @returns Returns an object with a .glb filename as key and data as value
  3619. */
  3620. GLTF2Export.GLBAsync = function (scene, filePrefix, options) {
  3621. var _this = this;
  3622. return this._PreExportAsync(scene, options).then(function () {
  3623. var glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
  3624. var gltfGenerator = new _glTFExporter__WEBPACK_IMPORTED_MODULE_0__["_Exporter"](scene, options);
  3625. return gltfGenerator._generateGLBAsync(glTFPrefix).then(function (glTFData) {
  3626. return _this._PostExportAsync(scene, glTFData, options);
  3627. });
  3628. });
  3629. };
  3630. return GLTF2Export;
  3631. }());
  3632. /***/ }),
  3633. /***/ "./glTF/2.0/glTFUtilities.ts":
  3634. /*!***********************************!*\
  3635. !*** ./glTF/2.0/glTFUtilities.ts ***!
  3636. \***********************************/
  3637. /*! exports provided: _GLTFUtilities */
  3638. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3639. "use strict";
  3640. __webpack_require__.r(__webpack_exports__);
  3641. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _GLTFUtilities; });
  3642. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
  3643. /* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
  3644. /**
  3645. * @hidden
  3646. */
  3647. var _GLTFUtilities = /** @class */ (function () {
  3648. function _GLTFUtilities() {
  3649. }
  3650. /**
  3651. * Creates a buffer view based on the supplied arguments
  3652. * @param bufferIndex index value of the specified buffer
  3653. * @param byteOffset byte offset value
  3654. * @param byteLength byte length of the bufferView
  3655. * @param byteStride byte distance between conequential elements
  3656. * @param name name of the buffer view
  3657. * @returns bufferView for glTF
  3658. */
  3659. _GLTFUtilities._CreateBufferView = function (bufferIndex, byteOffset, byteLength, byteStride, name) {
  3660. var bufferview = { buffer: bufferIndex, byteLength: byteLength };
  3661. if (byteOffset) {
  3662. bufferview.byteOffset = byteOffset;
  3663. }
  3664. if (name) {
  3665. bufferview.name = name;
  3666. }
  3667. if (byteStride) {
  3668. bufferview.byteStride = byteStride;
  3669. }
  3670. return bufferview;
  3671. };
  3672. /**
  3673. * Creates an accessor based on the supplied arguments
  3674. * @param bufferviewIndex The index of the bufferview referenced by this accessor
  3675. * @param name The name of the accessor
  3676. * @param type The type of the accessor
  3677. * @param componentType The datatype of components in the attribute
  3678. * @param count The number of attributes referenced by this accessor
  3679. * @param byteOffset The offset relative to the start of the bufferView in bytes
  3680. * @param min Minimum value of each component in this attribute
  3681. * @param max Maximum value of each component in this attribute
  3682. * @returns accessor for glTF
  3683. */
  3684. _GLTFUtilities._CreateAccessor = function (bufferviewIndex, name, type, componentType, count, byteOffset, min, max) {
  3685. var accessor = { name: name, bufferView: bufferviewIndex, componentType: componentType, count: count, type: type };
  3686. if (min != null) {
  3687. accessor.min = min;
  3688. }
  3689. if (max != null) {
  3690. accessor.max = max;
  3691. }
  3692. if (byteOffset != null) {
  3693. accessor.byteOffset = byteOffset;
  3694. }
  3695. return accessor;
  3696. };
  3697. /**
  3698. * Calculates the minimum and maximum values of an array of position floats
  3699. * @param positions Positions array of a mesh
  3700. * @param vertexStart Starting vertex offset to calculate min and max values
  3701. * @param vertexCount Number of vertices to check for min and max values
  3702. * @returns min number array and max number array
  3703. */
  3704. _GLTFUtilities._CalculateMinMaxPositions = function (positions, vertexStart, vertexCount, convertToRightHandedSystem) {
  3705. var min = [Infinity, Infinity, Infinity];
  3706. var max = [-Infinity, -Infinity, -Infinity];
  3707. var positionStrideSize = 3;
  3708. var indexOffset;
  3709. var position;
  3710. var vector;
  3711. if (vertexCount) {
  3712. for (var i = vertexStart, length_1 = vertexStart + vertexCount; i < length_1; ++i) {
  3713. indexOffset = positionStrideSize * i;
  3714. position = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].FromArray(positions, indexOffset);
  3715. if (convertToRightHandedSystem) {
  3716. _GLTFUtilities._GetRightHandedPositionVector3FromRef(position);
  3717. }
  3718. vector = position.asArray();
  3719. for (var j = 0; j < positionStrideSize; ++j) {
  3720. var num = vector[j];
  3721. if (num < min[j]) {
  3722. min[j] = num;
  3723. }
  3724. if (num > max[j]) {
  3725. max[j] = num;
  3726. }
  3727. ++indexOffset;
  3728. }
  3729. }
  3730. }
  3731. return { min: min, max: max };
  3732. };
  3733. /**
  3734. * Converts a new right-handed Vector3
  3735. * @param vector vector3 array
  3736. * @returns right-handed Vector3
  3737. */
  3738. _GLTFUtilities._GetRightHandedPositionVector3 = function (vector) {
  3739. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  3740. };
  3741. /**
  3742. * Converts a Vector3 to right-handed
  3743. * @param vector Vector3 to convert to right-handed
  3744. */
  3745. _GLTFUtilities._GetRightHandedPositionVector3FromRef = function (vector) {
  3746. vector.z *= -1;
  3747. };
  3748. /**
  3749. * Converts a three element number array to right-handed
  3750. * @param vector number array to convert to right-handed
  3751. */
  3752. _GLTFUtilities._GetRightHandedPositionArray3FromRef = function (vector) {
  3753. vector[2] *= -1;
  3754. };
  3755. /**
  3756. * Converts a new right-handed Vector3
  3757. * @param vector vector3 array
  3758. * @returns right-handed Vector3
  3759. */
  3760. _GLTFUtilities._GetRightHandedNormalVector3 = function (vector) {
  3761. return new babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"](vector.x, vector.y, -vector.z);
  3762. };
  3763. /**
  3764. * Converts a Vector3 to right-handed
  3765. * @param vector Vector3 to convert to right-handed
  3766. */
  3767. _GLTFUtilities._GetRightHandedNormalVector3FromRef = function (vector) {
  3768. vector.z *= -1;
  3769. };
  3770. /**
  3771. * Converts a three element number array to right-handed
  3772. * @param vector number array to convert to right-handed
  3773. */
  3774. _GLTFUtilities._GetRightHandedNormalArray3FromRef = function (vector) {
  3775. vector[2] *= -1;
  3776. };
  3777. /**
  3778. * Converts a Vector4 to right-handed
  3779. * @param vector Vector4 to convert to right-handed
  3780. */
  3781. _GLTFUtilities._GetRightHandedVector4FromRef = function (vector) {
  3782. vector.z *= -1;
  3783. vector.w *= -1;
  3784. };
  3785. /**
  3786. * Converts a Vector4 to right-handed
  3787. * @param vector Vector4 to convert to right-handed
  3788. */
  3789. _GLTFUtilities._GetRightHandedArray4FromRef = function (vector) {
  3790. vector[2] *= -1;
  3791. vector[3] *= -1;
  3792. };
  3793. /**
  3794. * Converts a Quaternion to right-handed
  3795. * @param quaternion Source quaternion to convert to right-handed
  3796. */
  3797. _GLTFUtilities._GetRightHandedQuaternionFromRef = function (quaternion) {
  3798. quaternion.x *= -1;
  3799. quaternion.y *= -1;
  3800. };
  3801. /**
  3802. * Converts a Quaternion to right-handed
  3803. * @param quaternion Source quaternion to convert to right-handed
  3804. */
  3805. _GLTFUtilities._GetRightHandedQuaternionArrayFromRef = function (quaternion) {
  3806. quaternion[0] *= -1;
  3807. quaternion[1] *= -1;
  3808. };
  3809. _GLTFUtilities._NormalizeTangentFromRef = function (tangent) {
  3810. var length = Math.sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z);
  3811. if (length > 0) {
  3812. tangent.x /= length;
  3813. tangent.y /= length;
  3814. tangent.z /= length;
  3815. }
  3816. };
  3817. return _GLTFUtilities;
  3818. }());
  3819. /***/ }),
  3820. /***/ "./glTF/2.0/index.ts":
  3821. /*!***************************!*\
  3822. !*** ./glTF/2.0/index.ts ***!
  3823. \***************************/
  3824. /*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
  3825. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3826. "use strict";
  3827. __webpack_require__.r(__webpack_exports__);
  3828. /* harmony import */ var _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./glTFAnimation */ "./glTF/2.0/glTFAnimation.ts");
  3829. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTFAnimation__WEBPACK_IMPORTED_MODULE_0__["_GLTFAnimation"]; });
  3830. /* harmony import */ var _glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./glTFData */ "./glTF/2.0/glTFData.ts");
  3831. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTFData__WEBPACK_IMPORTED_MODULE_1__["GLTFData"]; });
  3832. /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./glTFExporter */ "./glTF/2.0/glTFExporter.ts");
  3833. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_Exporter"]; });
  3834. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTFExporter__WEBPACK_IMPORTED_MODULE_2__["_BinaryWriter"]; });
  3835. /* harmony import */ var _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./glTFExporterExtension */ "./glTF/2.0/glTFExporterExtension.ts");
  3836. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTFExporterExtension__WEBPACK_IMPORTED_MODULE_3__["__IGLTFExporterExtensionV2"]; });
  3837. /* harmony import */ var _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./glTFMaterialExporter */ "./glTF/2.0/glTFMaterialExporter.ts");
  3838. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  3839. /* harmony import */ var _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  3840. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__["GLTF2Export"]; });
  3841. /* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
  3842. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTFUtilities__WEBPACK_IMPORTED_MODULE_6__["_GLTFUtilities"]; });
  3843. /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
  3844. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_texture_transform"]; });
  3845. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_lights_punctual"]; });
  3846. /***/ }),
  3847. /***/ "./glTF/2.0/shaders/textureTransform.fragment.ts":
  3848. /*!*******************************************************!*\
  3849. !*** ./glTF/2.0/shaders/textureTransform.fragment.ts ***!
  3850. \*******************************************************/
  3851. /*! exports provided: textureTransformPixelShader */
  3852. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3853. "use strict";
  3854. __webpack_require__.r(__webpack_exports__);
  3855. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "textureTransformPixelShader", function() { return textureTransformPixelShader; });
  3856. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Maths/math");
  3857. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  3858. var name = 'textureTransformPixelShader';
  3859. 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}";
  3860. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  3861. /** @hidden */
  3862. var textureTransformPixelShader = { name: name, shader: shader };
  3863. /***/ }),
  3864. /***/ "./glTF/glTFFileExporter.ts":
  3865. /*!**********************************!*\
  3866. !*** ./glTF/glTFFileExporter.ts ***!
  3867. \**********************************/
  3868. /*! exports provided: __IGLTFExporterExtension */
  3869. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3870. "use strict";
  3871. __webpack_require__.r(__webpack_exports__);
  3872. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return __IGLTFExporterExtension; });
  3873. /** @hidden */
  3874. var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
  3875. /***/ }),
  3876. /***/ "./legacy/legacy-glTF2Serializer.ts":
  3877. /*!******************************************!*\
  3878. !*** ./legacy/legacy-glTF2Serializer.ts ***!
  3879. \******************************************/
  3880. /*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
  3881. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  3882. "use strict";
  3883. __webpack_require__.r(__webpack_exports__);
  3884. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTF/glTFFileExporter */ "./glTF/glTFFileExporter.ts");
  3885. /* harmony import */ var _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTF/2.0/glTFData */ "./glTF/2.0/glTFData.ts");
  3886. /* harmony import */ var _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTF/2.0/glTFSerializer */ "./glTF/2.0/glTFSerializer.ts");
  3887. /* harmony import */ var _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../glTF/2.0/Extensions */ "./glTF/2.0/Extensions/index.ts");
  3888. /* harmony import */ var _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../glTF/2.0 */ "./glTF/2.0/index.ts");
  3889. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtension", function() { return _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__["__IGLTFExporterExtension"]; });
  3890. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTFData", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTFData"]; });
  3891. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GLTF2Export", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["GLTF2Export"]; });
  3892. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFAnimation", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]; });
  3893. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_Exporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_Exporter"]; });
  3894. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_BinaryWriter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_BinaryWriter"]; });
  3895. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "__IGLTFExporterExtensionV2", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["__IGLTFExporterExtensionV2"]; });
  3896. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFMaterialExporter", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFMaterialExporter"]; });
  3897. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_GLTFUtilities", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["_GLTFUtilities"]; });
  3898. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_texture_transform"]; });
  3899. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_lights_punctual"]; });
  3900. /**
  3901. * This is the entry point for the UMD module.
  3902. * The entry point for a future ESM package should be index.ts
  3903. */
  3904. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  3905. if (typeof globalObject !== "undefined") {
  3906. globalObject.BABYLON = globalObject.BABYLON || {};
  3907. var BABYLON = globalObject.BABYLON;
  3908. BABYLON.GLTF2 = BABYLON.GLTF2 || {};
  3909. BABYLON.GLTF2.Exporter = BABYLON.GLTF2.Exporter || {};
  3910. BABYLON.GLTF2.Exporter.Extensions = BABYLON.GLTF2.Exporter.Extensions || {};
  3911. var keys = [];
  3912. for (var key in _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__) {
  3913. BABYLON[key] = _glTF_glTFFileExporter__WEBPACK_IMPORTED_MODULE_0__[key];
  3914. keys.push(key);
  3915. }
  3916. for (var key in _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__) {
  3917. BABYLON[key] = _glTF_2_0_glTFData__WEBPACK_IMPORTED_MODULE_1__[key];
  3918. keys.push(key);
  3919. }
  3920. for (var key in _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__) {
  3921. BABYLON[key] = _glTF_2_0_glTFSerializer__WEBPACK_IMPORTED_MODULE_2__[key];
  3922. keys.push(key);
  3923. }
  3924. for (var key in _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__) {
  3925. BABYLON.GLTF2.Exporter.Extensions[key] = _glTF_2_0_Extensions__WEBPACK_IMPORTED_MODULE_3__[key];
  3926. keys.push(key);
  3927. }
  3928. for (var key in _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__) {
  3929. // Prevent Reassignment.
  3930. if (keys.indexOf(key) > -1) {
  3931. continue;
  3932. }
  3933. BABYLON.GLTF2.Exporter[key] = _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__[key];
  3934. }
  3935. }
  3936. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  3937. /***/ }),
  3938. /***/ "babylonjs/Maths/math":
  3939. /*!****************************************************************************************************!*\
  3940. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  3941. \****************************************************************************************************/
  3942. /*! no static exports found */
  3943. /***/ (function(module, exports) {
  3944. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Maths_math__;
  3945. /***/ })
  3946. /******/ });
  3947. });
  3948. //# sourceMappingURL=babylon.glTF2Serializer.js.map