babylon.glTF2Serializer.js 219 KB

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