babylon.glTF2Serializer.js 300 KB

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