babylonjs.serializers.js 282 KB

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