babylonjs.serializers.js 274 KB

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