babylon.glTF2Serializer.js 221 KB

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