babylonjs.serializers.js 288 KB

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