spine-phaser.js 529 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249
  1. "use strict";
  2. var spine = (() => {
  3. var __create = Object.create;
  4. var __defProp = Object.defineProperty;
  5. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  6. var __getOwnPropNames = Object.getOwnPropertyNames;
  7. var __getProtoOf = Object.getPrototypeOf;
  8. var __hasOwnProp = Object.prototype.hasOwnProperty;
  9. var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
  10. get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
  11. }) : x)(function(x) {
  12. if (typeof require !== "undefined")
  13. return require.apply(this, arguments);
  14. throw new Error('Dynamic require of "' + x + '" is not supported');
  15. });
  16. var __export = (target, all) => {
  17. for (var name in all)
  18. __defProp(target, name, { get: all[name], enumerable: true });
  19. };
  20. var __copyProps = (to, from, except, desc) => {
  21. if (from && typeof from === "object" || typeof from === "function") {
  22. for (let key of __getOwnPropNames(from))
  23. if (!__hasOwnProp.call(to, key) && key !== except)
  24. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  25. }
  26. return to;
  27. };
  28. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  29. // If the importer is in node compatibility mode or this is not an ESM
  30. // file that has been converted to a CommonJS file using a Babel-
  31. // compatible transform (i.e. "__esModule" has not been set), then set
  32. // "default" to the CommonJS "module.exports" for node compatibility.
  33. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  34. mod
  35. ));
  36. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  37. // spine-phaser/src/index.ts
  38. var src_exports = {};
  39. __export(src_exports, {
  40. Alpha: () => Alpha,
  41. AlphaMixin: () => AlphaMixin,
  42. AlphaTimeline: () => AlphaTimeline,
  43. Animation: () => Animation,
  44. AnimationState: () => AnimationState,
  45. AnimationStateAdapter: () => AnimationStateAdapter,
  46. AnimationStateData: () => AnimationStateData,
  47. AssetManager: () => AssetManager,
  48. AssetManagerBase: () => AssetManagerBase,
  49. AtlasAttachmentLoader: () => AtlasAttachmentLoader,
  50. Attachment: () => Attachment,
  51. AttachmentTimeline: () => AttachmentTimeline,
  52. BinaryInput: () => BinaryInput,
  53. BlendMode: () => BlendMode,
  54. Bone: () => Bone,
  55. BoneData: () => BoneData,
  56. BoundingBoxAttachment: () => BoundingBoxAttachment,
  57. CURRENT: () => CURRENT,
  58. CameraController: () => CameraController,
  59. ClippingAttachment: () => ClippingAttachment,
  60. Color: () => Color,
  61. Color2Attribute: () => Color2Attribute,
  62. ColorAttribute: () => ColorAttribute,
  63. ComputedSize: () => ComputedSize,
  64. ComputedSizeMixin: () => ComputedSizeMixin,
  65. ConstraintData: () => ConstraintData,
  66. CurveTimeline: () => CurveTimeline,
  67. CurveTimeline1: () => CurveTimeline1,
  68. CurveTimeline2: () => CurveTimeline2,
  69. DebugUtils: () => DebugUtils,
  70. DeformTimeline: () => DeformTimeline,
  71. Depth: () => Depth,
  72. DepthMixin: () => DepthMixin,
  73. Downloader: () => Downloader,
  74. DrawOrderTimeline: () => DrawOrderTimeline,
  75. Event: () => Event,
  76. EventData: () => EventData,
  77. EventQueue: () => EventQueue,
  78. EventTimeline: () => EventTimeline,
  79. EventType: () => EventType,
  80. FIRST: () => FIRST,
  81. FakeTexture: () => FakeTexture,
  82. Flip: () => Flip,
  83. FlipMixin: () => FlipMixin,
  84. GLTexture: () => GLTexture,
  85. HOLD_FIRST: () => HOLD_FIRST,
  86. HOLD_MIX: () => HOLD_MIX,
  87. HOLD_SUBSEQUENT: () => HOLD_SUBSEQUENT,
  88. IkConstraint: () => IkConstraint,
  89. IkConstraintData: () => IkConstraintData,
  90. IkConstraintTimeline: () => IkConstraintTimeline,
  91. Input: () => Input,
  92. IntSet: () => IntSet,
  93. Interpolation: () => Interpolation,
  94. LoadingScreen: () => LoadingScreen,
  95. M00: () => M00,
  96. M01: () => M01,
  97. M02: () => M02,
  98. M03: () => M03,
  99. M10: () => M10,
  100. M11: () => M11,
  101. M12: () => M12,
  102. M13: () => M13,
  103. M20: () => M20,
  104. M21: () => M21,
  105. M22: () => M22,
  106. M23: () => M23,
  107. M30: () => M30,
  108. M31: () => M31,
  109. M32: () => M32,
  110. M33: () => M33,
  111. ManagedWebGLRenderingContext: () => ManagedWebGLRenderingContext,
  112. MathUtils: () => MathUtils,
  113. Matrix4: () => Matrix42,
  114. Mesh: () => Mesh,
  115. MeshAttachment: () => MeshAttachment,
  116. MixBlend: () => MixBlend,
  117. MixDirection: () => MixDirection,
  118. Origin: () => Origin,
  119. OriginMixin: () => OriginMixin,
  120. OrthoCamera: () => OrthoCamera,
  121. PathAttachment: () => PathAttachment,
  122. PathConstraint: () => PathConstraint,
  123. PathConstraintData: () => PathConstraintData,
  124. PathConstraintMixTimeline: () => PathConstraintMixTimeline,
  125. PathConstraintPositionTimeline: () => PathConstraintPositionTimeline,
  126. PathConstraintSpacingTimeline: () => PathConstraintSpacingTimeline,
  127. PointAttachment: () => PointAttachment,
  128. PolygonBatcher: () => PolygonBatcher,
  129. Pool: () => Pool,
  130. Position2Attribute: () => Position2Attribute,
  131. Position3Attribute: () => Position3Attribute,
  132. PositionMode: () => PositionMode,
  133. Pow: () => Pow,
  134. PowOut: () => PowOut,
  135. RGB2Timeline: () => RGB2Timeline,
  136. RGBA2Timeline: () => RGBA2Timeline,
  137. RGBATimeline: () => RGBATimeline,
  138. RGBTimeline: () => RGBTimeline,
  139. RegionAttachment: () => RegionAttachment,
  140. ResizeMode: () => ResizeMode,
  141. RotateMode: () => RotateMode,
  142. RotateTimeline: () => RotateTimeline,
  143. SETUP: () => SETUP,
  144. SUBSEQUENT: () => SUBSEQUENT,
  145. ScaleTimeline: () => ScaleTimeline,
  146. ScaleXTimeline: () => ScaleXTimeline,
  147. ScaleYTimeline: () => ScaleYTimeline,
  148. SceneRenderer: () => SceneRenderer,
  149. ScrollFactor: () => ScrollFactor,
  150. ScrollFactorMixin: () => ScrollFactorMixin,
  151. SequenceTimeline: () => SequenceTimeline,
  152. SetupPoseBoundsProvider: () => SetupPoseBoundsProvider,
  153. Shader: () => Shader,
  154. ShapeRenderer: () => ShapeRenderer,
  155. ShapeType: () => ShapeType,
  156. ShearTimeline: () => ShearTimeline,
  157. ShearXTimeline: () => ShearXTimeline,
  158. ShearYTimeline: () => ShearYTimeline,
  159. Skeleton: () => Skeleton,
  160. SkeletonBinary: () => SkeletonBinary,
  161. SkeletonBounds: () => SkeletonBounds,
  162. SkeletonClipping: () => SkeletonClipping,
  163. SkeletonData: () => SkeletonData,
  164. SkeletonDebugRenderer: () => SkeletonDebugRenderer,
  165. SkeletonJson: () => SkeletonJson,
  166. SkeletonRenderer: () => SkeletonRenderer,
  167. Skin: () => Skin,
  168. SkinEntry: () => SkinEntry,
  169. SkinsAndAnimationBoundsProvider: () => SkinsAndAnimationBoundsProvider,
  170. Slot: () => Slot,
  171. SlotData: () => SlotData,
  172. SpacingMode: () => SpacingMode,
  173. SpineCanvas: () => SpineCanvas,
  174. SpineGameObject: () => SpineGameObject,
  175. SpinePlugin: () => SpinePlugin,
  176. StringSet: () => StringSet,
  177. TexCoordAttribute: () => TexCoordAttribute,
  178. Texture: () => Texture,
  179. TextureAtlas: () => TextureAtlas,
  180. TextureAtlasPage: () => TextureAtlasPage,
  181. TextureAtlasRegion: () => TextureAtlasRegion,
  182. TextureFilter: () => TextureFilter,
  183. TextureRegion: () => TextureRegion,
  184. TextureWrap: () => TextureWrap,
  185. TimeKeeper: () => TimeKeeper,
  186. Timeline: () => Timeline,
  187. Touch: () => Touch,
  188. TrackEntry: () => TrackEntry,
  189. Transform: () => Transform,
  190. TransformConstraint: () => TransformConstraint,
  191. TransformConstraintData: () => TransformConstraintData,
  192. TransformConstraintTimeline: () => TransformConstraintTimeline,
  193. TransformMixin: () => TransformMixin,
  194. TransformMode: () => TransformMode,
  195. TranslateTimeline: () => TranslateTimeline,
  196. TranslateXTimeline: () => TranslateXTimeline,
  197. TranslateYTimeline: () => TranslateYTimeline,
  198. Triangulator: () => Triangulator,
  199. Utils: () => Utils,
  200. Vector2: () => Vector2,
  201. Vector3: () => Vector3,
  202. VertexAttachment: () => VertexAttachment,
  203. VertexAttribute: () => VertexAttribute,
  204. VertexAttributeType: () => VertexAttributeType,
  205. Visible: () => Visible,
  206. VisibleMixin: () => VisibleMixin,
  207. WebGLBlendModeConverter: () => WebGLBlendModeConverter,
  208. WindowedMean: () => WindowedMean,
  209. createMixin: () => createMixin
  210. });
  211. // spine-phaser/src/require-shim.ts
  212. if (window.Phaser) {
  213. let prevRequire = window.require;
  214. window.require = (x) => {
  215. if (prevRequire)
  216. return prevRequire(x);
  217. else if (x === "Phaser")
  218. return window.Phaser;
  219. };
  220. }
  221. // spine-phaser/src/SpinePlugin.ts
  222. var import_phaser = __toESM(__require("Phaser"));
  223. // spine-phaser/src/keys.ts
  224. var SPINE_SKELETON_FILE_CACHE_KEY = "esotericsoftware.spine.skeletonFile.cache";
  225. var SPINE_ATLAS_CACHE_KEY = "esotericsoftware.spine.atlas.cache";
  226. var SPINE_SKELETON_DATA_FILE_TYPE = "spineSkeletonData";
  227. var SPINE_ATLAS_FILE_TYPE = "spineAtlasData";
  228. var SPINE_GAME_OBJECT_TYPE = "spine";
  229. var SPINE_CONTAINER_TYPE = "spineContainer";
  230. // spine-core/src/Utils.ts
  231. var IntSet = class {
  232. constructor() {
  233. this.array = new Array();
  234. }
  235. add(value) {
  236. let contains = this.contains(value);
  237. this.array[value | 0] = value | 0;
  238. return !contains;
  239. }
  240. contains(value) {
  241. return this.array[value | 0] != void 0;
  242. }
  243. remove(value) {
  244. this.array[value | 0] = void 0;
  245. }
  246. clear() {
  247. this.array.length = 0;
  248. }
  249. };
  250. var StringSet = class {
  251. constructor() {
  252. this.entries = {};
  253. this.size = 0;
  254. }
  255. add(value) {
  256. let contains = this.entries[value];
  257. this.entries[value] = true;
  258. if (!contains) {
  259. this.size++;
  260. return true;
  261. }
  262. return false;
  263. }
  264. addAll(values) {
  265. let oldSize = this.size;
  266. for (var i = 0, n = values.length; i < n; i++)
  267. this.add(values[i]);
  268. return oldSize != this.size;
  269. }
  270. contains(value) {
  271. return this.entries[value];
  272. }
  273. clear() {
  274. this.entries = {};
  275. this.size = 0;
  276. }
  277. };
  278. var _Color = class {
  279. constructor(r = 0, g = 0, b = 0, a = 0) {
  280. this.r = r;
  281. this.g = g;
  282. this.b = b;
  283. this.a = a;
  284. }
  285. set(r, g, b, a) {
  286. this.r = r;
  287. this.g = g;
  288. this.b = b;
  289. this.a = a;
  290. return this.clamp();
  291. }
  292. setFromColor(c) {
  293. this.r = c.r;
  294. this.g = c.g;
  295. this.b = c.b;
  296. this.a = c.a;
  297. return this;
  298. }
  299. setFromString(hex) {
  300. hex = hex.charAt(0) == "#" ? hex.substr(1) : hex;
  301. this.r = parseInt(hex.substr(0, 2), 16) / 255;
  302. this.g = parseInt(hex.substr(2, 2), 16) / 255;
  303. this.b = parseInt(hex.substr(4, 2), 16) / 255;
  304. this.a = hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255;
  305. return this;
  306. }
  307. add(r, g, b, a) {
  308. this.r += r;
  309. this.g += g;
  310. this.b += b;
  311. this.a += a;
  312. return this.clamp();
  313. }
  314. clamp() {
  315. if (this.r < 0)
  316. this.r = 0;
  317. else if (this.r > 1)
  318. this.r = 1;
  319. if (this.g < 0)
  320. this.g = 0;
  321. else if (this.g > 1)
  322. this.g = 1;
  323. if (this.b < 0)
  324. this.b = 0;
  325. else if (this.b > 1)
  326. this.b = 1;
  327. if (this.a < 0)
  328. this.a = 0;
  329. else if (this.a > 1)
  330. this.a = 1;
  331. return this;
  332. }
  333. static rgba8888ToColor(color, value) {
  334. color.r = ((value & 4278190080) >>> 24) / 255;
  335. color.g = ((value & 16711680) >>> 16) / 255;
  336. color.b = ((value & 65280) >>> 8) / 255;
  337. color.a = (value & 255) / 255;
  338. }
  339. static rgb888ToColor(color, value) {
  340. color.r = ((value & 16711680) >>> 16) / 255;
  341. color.g = ((value & 65280) >>> 8) / 255;
  342. color.b = (value & 255) / 255;
  343. }
  344. static fromString(hex) {
  345. return new _Color().setFromString(hex);
  346. }
  347. };
  348. var Color = _Color;
  349. Color.WHITE = new _Color(1, 1, 1, 1);
  350. Color.RED = new _Color(1, 0, 0, 1);
  351. Color.GREEN = new _Color(0, 1, 0, 1);
  352. Color.BLUE = new _Color(0, 0, 1, 1);
  353. Color.MAGENTA = new _Color(1, 0, 1, 1);
  354. var _MathUtils = class {
  355. static clamp(value, min, max) {
  356. if (value < min)
  357. return min;
  358. if (value > max)
  359. return max;
  360. return value;
  361. }
  362. static cosDeg(degrees) {
  363. return Math.cos(degrees * _MathUtils.degRad);
  364. }
  365. static sinDeg(degrees) {
  366. return Math.sin(degrees * _MathUtils.degRad);
  367. }
  368. static signum(value) {
  369. return value > 0 ? 1 : value < 0 ? -1 : 0;
  370. }
  371. static toInt(x) {
  372. return x > 0 ? Math.floor(x) : Math.ceil(x);
  373. }
  374. static cbrt(x) {
  375. let y = Math.pow(Math.abs(x), 1 / 3);
  376. return x < 0 ? -y : y;
  377. }
  378. static randomTriangular(min, max) {
  379. return _MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
  380. }
  381. static randomTriangularWith(min, max, mode) {
  382. let u = Math.random();
  383. let d = max - min;
  384. if (u <= (mode - min) / d)
  385. return min + Math.sqrt(u * d * (mode - min));
  386. return max - Math.sqrt((1 - u) * d * (max - mode));
  387. }
  388. static isPowerOfTwo(value) {
  389. return value && (value & value - 1) === 0;
  390. }
  391. };
  392. var MathUtils = _MathUtils;
  393. MathUtils.PI = 3.1415927;
  394. MathUtils.PI2 = _MathUtils.PI * 2;
  395. MathUtils.radiansToDegrees = 180 / _MathUtils.PI;
  396. MathUtils.radDeg = _MathUtils.radiansToDegrees;
  397. MathUtils.degreesToRadians = _MathUtils.PI / 180;
  398. MathUtils.degRad = _MathUtils.degreesToRadians;
  399. var Interpolation = class {
  400. apply(start, end, a) {
  401. return start + (end - start) * this.applyInternal(a);
  402. }
  403. };
  404. var Pow = class extends Interpolation {
  405. constructor(power) {
  406. super();
  407. this.power = 2;
  408. this.power = power;
  409. }
  410. applyInternal(a) {
  411. if (a <= 0.5)
  412. return Math.pow(a * 2, this.power) / 2;
  413. return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
  414. }
  415. };
  416. var PowOut = class extends Pow {
  417. constructor(power) {
  418. super(power);
  419. }
  420. applyInternal(a) {
  421. return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
  422. }
  423. };
  424. var _Utils = class {
  425. static arrayCopy(source, sourceStart, dest, destStart, numElements) {
  426. for (let i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  427. dest[j] = source[i];
  428. }
  429. }
  430. static arrayFill(array, fromIndex, toIndex, value) {
  431. for (let i = fromIndex; i < toIndex; i++)
  432. array[i] = value;
  433. }
  434. static setArraySize(array, size, value = 0) {
  435. let oldSize = array.length;
  436. if (oldSize == size)
  437. return array;
  438. array.length = size;
  439. if (oldSize < size) {
  440. for (let i = oldSize; i < size; i++)
  441. array[i] = value;
  442. }
  443. return array;
  444. }
  445. static ensureArrayCapacity(array, size, value = 0) {
  446. if (array.length >= size)
  447. return array;
  448. return _Utils.setArraySize(array, size, value);
  449. }
  450. static newArray(size, defaultValue) {
  451. let array = new Array(size);
  452. for (let i = 0; i < size; i++)
  453. array[i] = defaultValue;
  454. return array;
  455. }
  456. static newFloatArray(size) {
  457. if (_Utils.SUPPORTS_TYPED_ARRAYS)
  458. return new Float32Array(size);
  459. else {
  460. let array = new Array(size);
  461. for (let i = 0; i < array.length; i++)
  462. array[i] = 0;
  463. return array;
  464. }
  465. }
  466. static newShortArray(size) {
  467. if (_Utils.SUPPORTS_TYPED_ARRAYS)
  468. return new Int16Array(size);
  469. else {
  470. let array = new Array(size);
  471. for (let i = 0; i < array.length; i++)
  472. array[i] = 0;
  473. return array;
  474. }
  475. }
  476. static toFloatArray(array) {
  477. return _Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  478. }
  479. static toSinglePrecision(value) {
  480. return _Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
  481. }
  482. // This function is used to fix WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  483. static webkit602BugfixHelper(alpha, blend) {
  484. }
  485. static contains(array, element, identity = true) {
  486. for (var i = 0; i < array.length; i++)
  487. if (array[i] == element)
  488. return true;
  489. return false;
  490. }
  491. static enumValue(type, name) {
  492. return type[name[0].toUpperCase() + name.slice(1)];
  493. }
  494. };
  495. var Utils = _Utils;
  496. Utils.SUPPORTS_TYPED_ARRAYS = typeof Float32Array !== "undefined";
  497. var DebugUtils = class {
  498. static logBones(skeleton) {
  499. for (let i = 0; i < skeleton.bones.length; i++) {
  500. let bone = skeleton.bones[i];
  501. console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
  502. }
  503. }
  504. };
  505. var Pool = class {
  506. constructor(instantiator) {
  507. this.items = new Array();
  508. this.instantiator = instantiator;
  509. }
  510. obtain() {
  511. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  512. }
  513. free(item) {
  514. if (item.reset)
  515. item.reset();
  516. this.items.push(item);
  517. }
  518. freeAll(items) {
  519. for (let i = 0; i < items.length; i++)
  520. this.free(items[i]);
  521. }
  522. clear() {
  523. this.items.length = 0;
  524. }
  525. };
  526. var Vector2 = class {
  527. constructor(x = 0, y = 0) {
  528. this.x = x;
  529. this.y = y;
  530. }
  531. set(x, y) {
  532. this.x = x;
  533. this.y = y;
  534. return this;
  535. }
  536. length() {
  537. let x = this.x;
  538. let y = this.y;
  539. return Math.sqrt(x * x + y * y);
  540. }
  541. normalize() {
  542. let len = this.length();
  543. if (len != 0) {
  544. this.x /= len;
  545. this.y /= len;
  546. }
  547. return this;
  548. }
  549. };
  550. var TimeKeeper = class {
  551. constructor() {
  552. this.maxDelta = 0.064;
  553. this.framesPerSecond = 0;
  554. this.delta = 0;
  555. this.totalTime = 0;
  556. this.lastTime = Date.now() / 1e3;
  557. this.frameCount = 0;
  558. this.frameTime = 0;
  559. }
  560. update() {
  561. let now = Date.now() / 1e3;
  562. this.delta = now - this.lastTime;
  563. this.frameTime += this.delta;
  564. this.totalTime += this.delta;
  565. if (this.delta > this.maxDelta)
  566. this.delta = this.maxDelta;
  567. this.lastTime = now;
  568. this.frameCount++;
  569. if (this.frameTime > 1) {
  570. this.framesPerSecond = this.frameCount / this.frameTime;
  571. this.frameTime = 0;
  572. this.frameCount = 0;
  573. }
  574. }
  575. };
  576. var WindowedMean = class {
  577. constructor(windowSize = 32) {
  578. this.addedValues = 0;
  579. this.lastValue = 0;
  580. this.mean = 0;
  581. this.dirty = true;
  582. this.values = new Array(windowSize);
  583. }
  584. hasEnoughData() {
  585. return this.addedValues >= this.values.length;
  586. }
  587. addValue(value) {
  588. if (this.addedValues < this.values.length)
  589. this.addedValues++;
  590. this.values[this.lastValue++] = value;
  591. if (this.lastValue > this.values.length - 1)
  592. this.lastValue = 0;
  593. this.dirty = true;
  594. }
  595. getMean() {
  596. if (this.hasEnoughData()) {
  597. if (this.dirty) {
  598. let mean = 0;
  599. for (let i = 0; i < this.values.length; i++)
  600. mean += this.values[i];
  601. this.mean = mean / this.values.length;
  602. this.dirty = false;
  603. }
  604. return this.mean;
  605. }
  606. return 0;
  607. }
  608. };
  609. // spine-core/src/attachments/Attachment.ts
  610. var Attachment = class {
  611. constructor(name) {
  612. if (!name)
  613. throw new Error("name cannot be null.");
  614. this.name = name;
  615. }
  616. };
  617. var _VertexAttachment = class extends Attachment {
  618. constructor(name) {
  619. super(name);
  620. /** The unique ID for this attachment. */
  621. this.id = _VertexAttachment.nextID++;
  622. /** The bones which affect the {@link #getVertices()}. The array entries are, for each vertex, the number of bones affecting
  623. * the vertex followed by that many bone indices, which is the index of the bone in {@link Skeleton#bones}. Will be null
  624. * if this attachment has no weights. */
  625. this.bones = null;
  626. /** The vertex positions in the bone's coordinate system. For a non-weighted attachment, the values are `x,y`
  627. * entries for each vertex. For a weighted attachment, the values are `x,y,weight` entries for each bone affecting
  628. * each vertex. */
  629. this.vertices = [];
  630. /** The maximum number of world vertex values that can be output by
  631. * {@link #computeWorldVertices()} using the `count` parameter. */
  632. this.worldVerticesLength = 0;
  633. /** Timelines for the timeline attachment are also applied to this attachment.
  634. * May be null if no attachment-specific timelines should be applied. */
  635. this.timelineAttachment = this;
  636. }
  637. /** Transforms the attachment's local {@link #vertices} to world coordinates. If the slot's {@link Slot#deform} is
  638. * not empty, it is used to deform the vertices.
  639. *
  640. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  641. * Runtimes Guide.
  642. * @param start The index of the first {@link #vertices} value to transform. Each vertex has 2 values, x and y.
  643. * @param count The number of world vertex values to output. Must be <= {@link #worldVerticesLength} - `start`.
  644. * @param worldVertices The output world vertices. Must have a length >= `offset` + `count` *
  645. * `stride` / 2.
  646. * @param offset The `worldVertices` index to begin writing values.
  647. * @param stride The number of `worldVertices` entries between the value pairs written. */
  648. computeWorldVertices(slot, start, count, worldVertices2, offset, stride) {
  649. count = offset + (count >> 1) * stride;
  650. let skeleton = slot.bone.skeleton;
  651. let deformArray = slot.deform;
  652. let vertices = this.vertices;
  653. let bones = this.bones;
  654. if (!bones) {
  655. if (deformArray.length > 0)
  656. vertices = deformArray;
  657. let bone = slot.bone;
  658. let x = bone.worldX;
  659. let y = bone.worldY;
  660. let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  661. for (let v2 = start, w = offset; w < count; v2 += 2, w += stride) {
  662. let vx = vertices[v2], vy = vertices[v2 + 1];
  663. worldVertices2[w] = vx * a + vy * b + x;
  664. worldVertices2[w + 1] = vx * c + vy * d + y;
  665. }
  666. return;
  667. }
  668. let v = 0, skip = 0;
  669. for (let i = 0; i < start; i += 2) {
  670. let n = bones[v];
  671. v += n + 1;
  672. skip += n;
  673. }
  674. let skeletonBones = skeleton.bones;
  675. if (deformArray.length == 0) {
  676. for (let w = offset, b = skip * 3; w < count; w += stride) {
  677. let wx = 0, wy = 0;
  678. let n = bones[v++];
  679. n += v;
  680. for (; v < n; v++, b += 3) {
  681. let bone = skeletonBones[bones[v]];
  682. let vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  683. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  684. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  685. }
  686. worldVertices2[w] = wx;
  687. worldVertices2[w + 1] = wy;
  688. }
  689. } else {
  690. let deform = deformArray;
  691. for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  692. let wx = 0, wy = 0;
  693. let n = bones[v++];
  694. n += v;
  695. for (; v < n; v++, b += 3, f += 2) {
  696. let bone = skeletonBones[bones[v]];
  697. let vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  698. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  699. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  700. }
  701. worldVertices2[w] = wx;
  702. worldVertices2[w + 1] = wy;
  703. }
  704. }
  705. }
  706. /** Does not copy id (generated) or name (set on construction). **/
  707. copyTo(attachment) {
  708. if (this.bones) {
  709. attachment.bones = new Array(this.bones.length);
  710. Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
  711. } else
  712. attachment.bones = null;
  713. if (this.vertices) {
  714. attachment.vertices = Utils.newFloatArray(this.vertices.length);
  715. Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
  716. }
  717. attachment.worldVerticesLength = this.worldVerticesLength;
  718. attachment.timelineAttachment = this.timelineAttachment;
  719. }
  720. };
  721. var VertexAttachment = _VertexAttachment;
  722. VertexAttachment.nextID = 0;
  723. // spine-core/src/attachments/Sequence.ts
  724. var _Sequence = class {
  725. constructor(count) {
  726. this.id = _Sequence.nextID();
  727. this.start = 0;
  728. this.digits = 0;
  729. /** The index of the region to show for the setup pose. */
  730. this.setupIndex = 0;
  731. this.regions = new Array(count);
  732. }
  733. copy() {
  734. let copy = new _Sequence(this.regions.length);
  735. Utils.arrayCopy(this.regions, 0, copy.regions, 0, this.regions.length);
  736. copy.start = this.start;
  737. copy.digits = this.digits;
  738. copy.setupIndex = this.setupIndex;
  739. return copy;
  740. }
  741. apply(slot, attachment) {
  742. let index = slot.sequenceIndex;
  743. if (index == -1)
  744. index = this.setupIndex;
  745. if (index >= this.regions.length)
  746. index = this.regions.length - 1;
  747. let region = this.regions[index];
  748. if (attachment.region != region) {
  749. attachment.region = region;
  750. attachment.updateRegion();
  751. }
  752. }
  753. getPath(basePath, index) {
  754. let result = basePath;
  755. let frame = (this.start + index).toString();
  756. for (let i = this.digits - frame.length; i > 0; i--)
  757. result += "0";
  758. result += frame;
  759. return result;
  760. }
  761. static nextID() {
  762. return _Sequence._nextID++;
  763. }
  764. };
  765. var Sequence = _Sequence;
  766. Sequence._nextID = 0;
  767. var SequenceMode = /* @__PURE__ */ ((SequenceMode2) => {
  768. SequenceMode2[SequenceMode2["hold"] = 0] = "hold";
  769. SequenceMode2[SequenceMode2["once"] = 1] = "once";
  770. SequenceMode2[SequenceMode2["loop"] = 2] = "loop";
  771. SequenceMode2[SequenceMode2["pingpong"] = 3] = "pingpong";
  772. SequenceMode2[SequenceMode2["onceReverse"] = 4] = "onceReverse";
  773. SequenceMode2[SequenceMode2["loopReverse"] = 5] = "loopReverse";
  774. SequenceMode2[SequenceMode2["pingpongReverse"] = 6] = "pingpongReverse";
  775. return SequenceMode2;
  776. })(SequenceMode || {});
  777. var SequenceModeValues = [
  778. 0 /* hold */,
  779. 1 /* once */,
  780. 2 /* loop */,
  781. 3 /* pingpong */,
  782. 4 /* onceReverse */,
  783. 5 /* loopReverse */,
  784. 6 /* pingpongReverse */
  785. ];
  786. // spine-core/src/Animation.ts
  787. var Animation = class {
  788. constructor(name, timelines, duration) {
  789. this.timelines = [];
  790. this.timelineIds = new StringSet();
  791. if (!name)
  792. throw new Error("name cannot be null.");
  793. this.name = name;
  794. this.setTimelines(timelines);
  795. this.duration = duration;
  796. }
  797. setTimelines(timelines) {
  798. if (!timelines)
  799. throw new Error("timelines cannot be null.");
  800. this.timelines = timelines;
  801. this.timelineIds.clear();
  802. for (var i = 0; i < timelines.length; i++)
  803. this.timelineIds.addAll(timelines[i].getPropertyIds());
  804. }
  805. hasTimeline(ids) {
  806. for (let i = 0; i < ids.length; i++)
  807. if (this.timelineIds.contains(ids[i]))
  808. return true;
  809. return false;
  810. }
  811. /** Applies all the animation's timelines to the specified skeleton.
  812. *
  813. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
  814. * @param loop If true, the animation repeats after {@link #getDuration()}.
  815. * @param events May be null to ignore fired events. */
  816. apply(skeleton, lastTime, time, loop, events, alpha, blend, direction) {
  817. if (!skeleton)
  818. throw new Error("skeleton cannot be null.");
  819. if (loop && this.duration != 0) {
  820. time %= this.duration;
  821. if (lastTime > 0)
  822. lastTime %= this.duration;
  823. }
  824. let timelines = this.timelines;
  825. for (let i = 0, n = timelines.length; i < n; i++)
  826. timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
  827. }
  828. };
  829. var MixBlend = /* @__PURE__ */ ((MixBlend2) => {
  830. MixBlend2[MixBlend2["setup"] = 0] = "setup";
  831. MixBlend2[MixBlend2["first"] = 1] = "first";
  832. MixBlend2[MixBlend2["replace"] = 2] = "replace";
  833. MixBlend2[MixBlend2["add"] = 3] = "add";
  834. return MixBlend2;
  835. })(MixBlend || {});
  836. var MixDirection = /* @__PURE__ */ ((MixDirection2) => {
  837. MixDirection2[MixDirection2["mixIn"] = 0] = "mixIn";
  838. MixDirection2[MixDirection2["mixOut"] = 1] = "mixOut";
  839. return MixDirection2;
  840. })(MixDirection || {});
  841. var Property = {
  842. rotate: 0,
  843. x: 1,
  844. y: 2,
  845. scaleX: 3,
  846. scaleY: 4,
  847. shearX: 5,
  848. shearY: 6,
  849. rgb: 7,
  850. alpha: 8,
  851. rgb2: 9,
  852. attachment: 10,
  853. deform: 11,
  854. event: 12,
  855. drawOrder: 13,
  856. ikConstraint: 14,
  857. transformConstraint: 15,
  858. pathConstraintPosition: 16,
  859. pathConstraintSpacing: 17,
  860. pathConstraintMix: 18,
  861. sequence: 19
  862. };
  863. var Timeline = class {
  864. constructor(frameCount, propertyIds) {
  865. this.propertyIds = propertyIds;
  866. this.frames = Utils.newFloatArray(frameCount * this.getFrameEntries());
  867. }
  868. getPropertyIds() {
  869. return this.propertyIds;
  870. }
  871. getFrameEntries() {
  872. return 1;
  873. }
  874. getFrameCount() {
  875. return this.frames.length / this.getFrameEntries();
  876. }
  877. getDuration() {
  878. return this.frames[this.frames.length - this.getFrameEntries()];
  879. }
  880. static search1(frames, time) {
  881. let n = frames.length;
  882. for (let i = 1; i < n; i++)
  883. if (frames[i] > time)
  884. return i - 1;
  885. return n - 1;
  886. }
  887. static search(frames, time, step) {
  888. let n = frames.length;
  889. for (let i = step; i < n; i += step)
  890. if (frames[i] > time)
  891. return i - step;
  892. return n - step;
  893. }
  894. };
  895. var CurveTimeline = class extends Timeline {
  896. // type, x, y, ...
  897. constructor(frameCount, bezierCount, propertyIds) {
  898. super(frameCount, propertyIds);
  899. this.curves = Utils.newFloatArray(
  900. frameCount + bezierCount * 18
  901. /*BEZIER_SIZE*/
  902. );
  903. this.curves[frameCount - 1] = 1;
  904. }
  905. /** Sets the specified key frame to linear interpolation. */
  906. setLinear(frame) {
  907. this.curves[frame] = 0;
  908. }
  909. /** Sets the specified key frame to stepped interpolation. */
  910. setStepped(frame) {
  911. this.curves[frame] = 1;
  912. }
  913. /** Shrinks the storage for Bezier curves, for use when <code>bezierCount</code> (specified in the constructor) was larger
  914. * than the actual number of Bezier curves. */
  915. shrink(bezierCount) {
  916. let size = this.getFrameCount() + bezierCount * 18;
  917. if (this.curves.length > size) {
  918. let newCurves = Utils.newFloatArray(size);
  919. Utils.arrayCopy(this.curves, 0, newCurves, 0, size);
  920. this.curves = newCurves;
  921. }
  922. }
  923. /** Stores the segments for the specified Bezier curve. For timelines that modify multiple values, there may be more than
  924. * one curve per frame.
  925. * @param bezier The ordinal of this Bezier curve for this timeline, between 0 and <code>bezierCount - 1</code> (specified
  926. * in the constructor), inclusive.
  927. * @param frame Between 0 and <code>frameCount - 1</code>, inclusive.
  928. * @param value The index of the value for this frame that this curve is used for.
  929. * @param time1 The time for the first key.
  930. * @param value1 The value for the first key.
  931. * @param cx1 The time for the first Bezier handle.
  932. * @param cy1 The value for the first Bezier handle.
  933. * @param cx2 The time of the second Bezier handle.
  934. * @param cy2 The value for the second Bezier handle.
  935. * @param time2 The time for the second key.
  936. * @param value2 The value for the second key. */
  937. setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) {
  938. let curves = this.curves;
  939. let i = this.getFrameCount() + bezier * 18;
  940. if (value == 0)
  941. curves[frame] = 2 + i;
  942. let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03;
  943. let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 6e-3, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 6e-3;
  944. let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
  945. let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667;
  946. let x = time1 + dx, y = value1 + dy;
  947. for (let n = i + 18; i < n; i += 2) {
  948. curves[i] = x;
  949. curves[i + 1] = y;
  950. dx += ddx;
  951. dy += ddy;
  952. ddx += dddx;
  953. ddy += dddy;
  954. x += dx;
  955. y += dy;
  956. }
  957. }
  958. /** Returns the Bezier interpolated value for the specified time.
  959. * @param frameIndex The index into {@link #getFrames()} for the values of the frame before <code>time</code>.
  960. * @param valueOffset The offset from <code>frameIndex</code> to the value this curve is used for.
  961. * @param i The index of the Bezier segments. See {@link #getCurveType(int)}. */
  962. getBezierValue(time, frameIndex, valueOffset, i) {
  963. let curves = this.curves;
  964. if (curves[i] > time) {
  965. let x2 = this.frames[frameIndex], y2 = this.frames[frameIndex + valueOffset];
  966. return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2);
  967. }
  968. let n = i + 18;
  969. for (i += 2; i < n; i += 2) {
  970. if (curves[i] >= time) {
  971. let x2 = curves[i - 2], y2 = curves[i - 1];
  972. return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2);
  973. }
  974. }
  975. frameIndex += this.getFrameEntries();
  976. let x = curves[n - 2], y = curves[n - 1];
  977. return y + (time - x) / (this.frames[frameIndex] - x) * (this.frames[frameIndex + valueOffset] - y);
  978. }
  979. };
  980. var CurveTimeline1 = class extends CurveTimeline {
  981. constructor(frameCount, bezierCount, propertyId) {
  982. super(frameCount, bezierCount, [propertyId]);
  983. }
  984. getFrameEntries() {
  985. return 2;
  986. }
  987. /** Sets the time and value for the specified frame.
  988. * @param frame Between 0 and <code>frameCount</code>, inclusive.
  989. * @param time The frame time in seconds. */
  990. setFrame(frame, time, value) {
  991. frame <<= 1;
  992. this.frames[frame] = time;
  993. this.frames[
  994. frame + 1
  995. /*VALUE*/
  996. ] = value;
  997. }
  998. /** Returns the interpolated value for the specified time. */
  999. getCurveValue(time) {
  1000. let frames = this.frames;
  1001. let i = frames.length - 2;
  1002. for (let ii = 2; ii <= i; ii += 2) {
  1003. if (frames[ii] > time) {
  1004. i = ii - 2;
  1005. break;
  1006. }
  1007. }
  1008. let curveType = this.curves[i >> 1];
  1009. switch (curveType) {
  1010. case 0:
  1011. let before = frames[i], value = frames[
  1012. i + 1
  1013. /*VALUE*/
  1014. ];
  1015. return value + (time - before) / (frames[
  1016. i + 2
  1017. /*ENTRIES*/
  1018. ] - before) * (frames[
  1019. i + 2 + 1
  1020. /*VALUE*/
  1021. ] - value);
  1022. case 1:
  1023. return frames[
  1024. i + 1
  1025. /*VALUE*/
  1026. ];
  1027. }
  1028. return this.getBezierValue(
  1029. time,
  1030. i,
  1031. 1,
  1032. curveType - 2
  1033. /*BEZIER*/
  1034. );
  1035. }
  1036. };
  1037. var CurveTimeline2 = class extends CurveTimeline {
  1038. /** @param bezierCount The maximum number of Bezier curves. See {@link #shrink(int)}.
  1039. * @param propertyIds Unique identifiers for the properties the timeline modifies. */
  1040. constructor(frameCount, bezierCount, propertyId1, propertyId2) {
  1041. super(frameCount, bezierCount, [propertyId1, propertyId2]);
  1042. }
  1043. getFrameEntries() {
  1044. return 3;
  1045. }
  1046. /** Sets the time and values for the specified frame.
  1047. * @param frame Between 0 and <code>frameCount</code>, inclusive.
  1048. * @param time The frame time in seconds. */
  1049. setFrame(frame, time, value1, value2) {
  1050. frame *= 3;
  1051. this.frames[frame] = time;
  1052. this.frames[
  1053. frame + 1
  1054. /*VALUE1*/
  1055. ] = value1;
  1056. this.frames[
  1057. frame + 2
  1058. /*VALUE2*/
  1059. ] = value2;
  1060. }
  1061. };
  1062. var RotateTimeline = class extends CurveTimeline1 {
  1063. constructor(frameCount, bezierCount, boneIndex) {
  1064. super(frameCount, bezierCount, Property.rotate + "|" + boneIndex);
  1065. this.boneIndex = 0;
  1066. this.boneIndex = boneIndex;
  1067. }
  1068. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1069. let bone = skeleton.bones[this.boneIndex];
  1070. if (!bone.active)
  1071. return;
  1072. let frames = this.frames;
  1073. if (time < frames[0]) {
  1074. switch (blend) {
  1075. case 0 /* setup */:
  1076. bone.rotation = bone.data.rotation;
  1077. return;
  1078. case 1 /* first */:
  1079. bone.rotation += (bone.data.rotation - bone.rotation) * alpha;
  1080. }
  1081. return;
  1082. }
  1083. let r = this.getCurveValue(time);
  1084. switch (blend) {
  1085. case 0 /* setup */:
  1086. bone.rotation = bone.data.rotation + r * alpha;
  1087. break;
  1088. case 1 /* first */:
  1089. case 2 /* replace */:
  1090. r += bone.data.rotation - bone.rotation;
  1091. case 3 /* add */:
  1092. bone.rotation += r * alpha;
  1093. }
  1094. }
  1095. };
  1096. var TranslateTimeline = class extends CurveTimeline2 {
  1097. constructor(frameCount, bezierCount, boneIndex) {
  1098. super(
  1099. frameCount,
  1100. bezierCount,
  1101. Property.x + "|" + boneIndex,
  1102. Property.y + "|" + boneIndex
  1103. );
  1104. this.boneIndex = 0;
  1105. this.boneIndex = boneIndex;
  1106. }
  1107. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1108. let bone = skeleton.bones[this.boneIndex];
  1109. if (!bone.active)
  1110. return;
  1111. let frames = this.frames;
  1112. if (time < frames[0]) {
  1113. switch (blend) {
  1114. case 0 /* setup */:
  1115. bone.x = bone.data.x;
  1116. bone.y = bone.data.y;
  1117. return;
  1118. case 1 /* first */:
  1119. bone.x += (bone.data.x - bone.x) * alpha;
  1120. bone.y += (bone.data.y - bone.y) * alpha;
  1121. }
  1122. return;
  1123. }
  1124. let x = 0, y = 0;
  1125. let i = Timeline.search(
  1126. frames,
  1127. time,
  1128. 3
  1129. /*ENTRIES*/
  1130. );
  1131. let curveType = this.curves[
  1132. i / 3
  1133. /*ENTRIES*/
  1134. ];
  1135. switch (curveType) {
  1136. case 0:
  1137. let before = frames[i];
  1138. x = frames[
  1139. i + 1
  1140. /*VALUE1*/
  1141. ];
  1142. y = frames[
  1143. i + 2
  1144. /*VALUE2*/
  1145. ];
  1146. let t = (time - before) / (frames[
  1147. i + 3
  1148. /*ENTRIES*/
  1149. ] - before);
  1150. x += (frames[
  1151. i + 3 + 1
  1152. /*VALUE1*/
  1153. ] - x) * t;
  1154. y += (frames[
  1155. i + 3 + 2
  1156. /*VALUE2*/
  1157. ] - y) * t;
  1158. break;
  1159. case 1:
  1160. x = frames[
  1161. i + 1
  1162. /*VALUE1*/
  1163. ];
  1164. y = frames[
  1165. i + 2
  1166. /*VALUE2*/
  1167. ];
  1168. break;
  1169. default:
  1170. x = this.getBezierValue(
  1171. time,
  1172. i,
  1173. 1,
  1174. curveType - 2
  1175. /*BEZIER*/
  1176. );
  1177. y = this.getBezierValue(
  1178. time,
  1179. i,
  1180. 2,
  1181. curveType + 18 - 2
  1182. /*BEZIER*/
  1183. );
  1184. }
  1185. switch (blend) {
  1186. case 0 /* setup */:
  1187. bone.x = bone.data.x + x * alpha;
  1188. bone.y = bone.data.y + y * alpha;
  1189. break;
  1190. case 1 /* first */:
  1191. case 2 /* replace */:
  1192. bone.x += (bone.data.x + x - bone.x) * alpha;
  1193. bone.y += (bone.data.y + y - bone.y) * alpha;
  1194. break;
  1195. case 3 /* add */:
  1196. bone.x += x * alpha;
  1197. bone.y += y * alpha;
  1198. }
  1199. }
  1200. };
  1201. var TranslateXTimeline = class extends CurveTimeline1 {
  1202. constructor(frameCount, bezierCount, boneIndex) {
  1203. super(frameCount, bezierCount, Property.x + "|" + boneIndex);
  1204. this.boneIndex = 0;
  1205. this.boneIndex = boneIndex;
  1206. }
  1207. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1208. let bone = skeleton.bones[this.boneIndex];
  1209. if (!bone.active)
  1210. return;
  1211. let frames = this.frames;
  1212. if (time < frames[0]) {
  1213. switch (blend) {
  1214. case 0 /* setup */:
  1215. bone.x = bone.data.x;
  1216. return;
  1217. case 1 /* first */:
  1218. bone.x += (bone.data.x - bone.x) * alpha;
  1219. }
  1220. return;
  1221. }
  1222. let x = this.getCurveValue(time);
  1223. switch (blend) {
  1224. case 0 /* setup */:
  1225. bone.x = bone.data.x + x * alpha;
  1226. break;
  1227. case 1 /* first */:
  1228. case 2 /* replace */:
  1229. bone.x += (bone.data.x + x - bone.x) * alpha;
  1230. break;
  1231. case 3 /* add */:
  1232. bone.x += x * alpha;
  1233. }
  1234. }
  1235. };
  1236. var TranslateYTimeline = class extends CurveTimeline1 {
  1237. constructor(frameCount, bezierCount, boneIndex) {
  1238. super(frameCount, bezierCount, Property.y + "|" + boneIndex);
  1239. this.boneIndex = 0;
  1240. this.boneIndex = boneIndex;
  1241. }
  1242. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1243. let bone = skeleton.bones[this.boneIndex];
  1244. if (!bone.active)
  1245. return;
  1246. let frames = this.frames;
  1247. if (time < frames[0]) {
  1248. switch (blend) {
  1249. case 0 /* setup */:
  1250. bone.y = bone.data.y;
  1251. return;
  1252. case 1 /* first */:
  1253. bone.y += (bone.data.y - bone.y) * alpha;
  1254. }
  1255. return;
  1256. }
  1257. let y = this.getCurveValue(time);
  1258. switch (blend) {
  1259. case 0 /* setup */:
  1260. bone.y = bone.data.y + y * alpha;
  1261. break;
  1262. case 1 /* first */:
  1263. case 2 /* replace */:
  1264. bone.y += (bone.data.y + y - bone.y) * alpha;
  1265. break;
  1266. case 3 /* add */:
  1267. bone.y += y * alpha;
  1268. }
  1269. }
  1270. };
  1271. var ScaleTimeline = class extends CurveTimeline2 {
  1272. constructor(frameCount, bezierCount, boneIndex) {
  1273. super(
  1274. frameCount,
  1275. bezierCount,
  1276. Property.scaleX + "|" + boneIndex,
  1277. Property.scaleY + "|" + boneIndex
  1278. );
  1279. this.boneIndex = 0;
  1280. this.boneIndex = boneIndex;
  1281. }
  1282. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1283. let bone = skeleton.bones[this.boneIndex];
  1284. if (!bone.active)
  1285. return;
  1286. let frames = this.frames;
  1287. if (time < frames[0]) {
  1288. switch (blend) {
  1289. case 0 /* setup */:
  1290. bone.scaleX = bone.data.scaleX;
  1291. bone.scaleY = bone.data.scaleY;
  1292. return;
  1293. case 1 /* first */:
  1294. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  1295. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  1296. }
  1297. return;
  1298. }
  1299. let x, y;
  1300. let i = Timeline.search(
  1301. frames,
  1302. time,
  1303. 3
  1304. /*ENTRIES*/
  1305. );
  1306. let curveType = this.curves[
  1307. i / 3
  1308. /*ENTRIES*/
  1309. ];
  1310. switch (curveType) {
  1311. case 0:
  1312. let before = frames[i];
  1313. x = frames[
  1314. i + 1
  1315. /*VALUE1*/
  1316. ];
  1317. y = frames[
  1318. i + 2
  1319. /*VALUE2*/
  1320. ];
  1321. let t = (time - before) / (frames[
  1322. i + 3
  1323. /*ENTRIES*/
  1324. ] - before);
  1325. x += (frames[
  1326. i + 3 + 1
  1327. /*VALUE1*/
  1328. ] - x) * t;
  1329. y += (frames[
  1330. i + 3 + 2
  1331. /*VALUE2*/
  1332. ] - y) * t;
  1333. break;
  1334. case 1:
  1335. x = frames[
  1336. i + 1
  1337. /*VALUE1*/
  1338. ];
  1339. y = frames[
  1340. i + 2
  1341. /*VALUE2*/
  1342. ];
  1343. break;
  1344. default:
  1345. x = this.getBezierValue(
  1346. time,
  1347. i,
  1348. 1,
  1349. curveType - 2
  1350. /*BEZIER*/
  1351. );
  1352. y = this.getBezierValue(
  1353. time,
  1354. i,
  1355. 2,
  1356. curveType + 18 - 2
  1357. /*BEZIER*/
  1358. );
  1359. }
  1360. x *= bone.data.scaleX;
  1361. y *= bone.data.scaleY;
  1362. if (alpha == 1) {
  1363. if (blend == 3 /* add */) {
  1364. bone.scaleX += x - bone.data.scaleX;
  1365. bone.scaleY += y - bone.data.scaleY;
  1366. } else {
  1367. bone.scaleX = x;
  1368. bone.scaleY = y;
  1369. }
  1370. } else {
  1371. let bx = 0, by = 0;
  1372. if (direction == 1 /* mixOut */) {
  1373. switch (blend) {
  1374. case 0 /* setup */:
  1375. bx = bone.data.scaleX;
  1376. by = bone.data.scaleY;
  1377. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  1378. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  1379. break;
  1380. case 1 /* first */:
  1381. case 2 /* replace */:
  1382. bx = bone.scaleX;
  1383. by = bone.scaleY;
  1384. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  1385. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  1386. break;
  1387. case 3 /* add */:
  1388. bone.scaleX += (x - bone.data.scaleX) * alpha;
  1389. bone.scaleY += (y - bone.data.scaleY) * alpha;
  1390. }
  1391. } else {
  1392. switch (blend) {
  1393. case 0 /* setup */:
  1394. bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
  1395. by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
  1396. bone.scaleX = bx + (x - bx) * alpha;
  1397. bone.scaleY = by + (y - by) * alpha;
  1398. break;
  1399. case 1 /* first */:
  1400. case 2 /* replace */:
  1401. bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
  1402. by = Math.abs(bone.scaleY) * MathUtils.signum(y);
  1403. bone.scaleX = bx + (x - bx) * alpha;
  1404. bone.scaleY = by + (y - by) * alpha;
  1405. break;
  1406. case 3 /* add */:
  1407. bone.scaleX += (x - bone.data.scaleX) * alpha;
  1408. bone.scaleY += (y - bone.data.scaleY) * alpha;
  1409. }
  1410. }
  1411. }
  1412. }
  1413. };
  1414. var ScaleXTimeline = class extends CurveTimeline1 {
  1415. constructor(frameCount, bezierCount, boneIndex) {
  1416. super(frameCount, bezierCount, Property.scaleX + "|" + boneIndex);
  1417. this.boneIndex = 0;
  1418. this.boneIndex = boneIndex;
  1419. }
  1420. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1421. let bone = skeleton.bones[this.boneIndex];
  1422. if (!bone.active)
  1423. return;
  1424. let frames = this.frames;
  1425. if (time < frames[0]) {
  1426. switch (blend) {
  1427. case 0 /* setup */:
  1428. bone.scaleX = bone.data.scaleX;
  1429. return;
  1430. case 1 /* first */:
  1431. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  1432. }
  1433. return;
  1434. }
  1435. let x = this.getCurveValue(time) * bone.data.scaleX;
  1436. if (alpha == 1) {
  1437. if (blend == 3 /* add */)
  1438. bone.scaleX += x - bone.data.scaleX;
  1439. else
  1440. bone.scaleX = x;
  1441. } else {
  1442. let bx = 0;
  1443. if (direction == 1 /* mixOut */) {
  1444. switch (blend) {
  1445. case 0 /* setup */:
  1446. bx = bone.data.scaleX;
  1447. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  1448. break;
  1449. case 1 /* first */:
  1450. case 2 /* replace */:
  1451. bx = bone.scaleX;
  1452. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  1453. break;
  1454. case 3 /* add */:
  1455. bone.scaleX += (x - bone.data.scaleX) * alpha;
  1456. }
  1457. } else {
  1458. switch (blend) {
  1459. case 0 /* setup */:
  1460. bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
  1461. bone.scaleX = bx + (x - bx) * alpha;
  1462. break;
  1463. case 1 /* first */:
  1464. case 2 /* replace */:
  1465. bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
  1466. bone.scaleX = bx + (x - bx) * alpha;
  1467. break;
  1468. case 3 /* add */:
  1469. bone.scaleX += (x - bone.data.scaleX) * alpha;
  1470. }
  1471. }
  1472. }
  1473. }
  1474. };
  1475. var ScaleYTimeline = class extends CurveTimeline1 {
  1476. constructor(frameCount, bezierCount, boneIndex) {
  1477. super(frameCount, bezierCount, Property.scaleY + "|" + boneIndex);
  1478. this.boneIndex = 0;
  1479. this.boneIndex = boneIndex;
  1480. }
  1481. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1482. let bone = skeleton.bones[this.boneIndex];
  1483. if (!bone.active)
  1484. return;
  1485. let frames = this.frames;
  1486. if (time < frames[0]) {
  1487. switch (blend) {
  1488. case 0 /* setup */:
  1489. bone.scaleY = bone.data.scaleY;
  1490. return;
  1491. case 1 /* first */:
  1492. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  1493. }
  1494. return;
  1495. }
  1496. let y = this.getCurveValue(time) * bone.data.scaleY;
  1497. if (alpha == 1) {
  1498. if (blend == 3 /* add */)
  1499. bone.scaleY += y - bone.data.scaleY;
  1500. else
  1501. bone.scaleY = y;
  1502. } else {
  1503. let by = 0;
  1504. if (direction == 1 /* mixOut */) {
  1505. switch (blend) {
  1506. case 0 /* setup */:
  1507. by = bone.data.scaleY;
  1508. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  1509. break;
  1510. case 1 /* first */:
  1511. case 2 /* replace */:
  1512. by = bone.scaleY;
  1513. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  1514. break;
  1515. case 3 /* add */:
  1516. bone.scaleY += (y - bone.data.scaleY) * alpha;
  1517. }
  1518. } else {
  1519. switch (blend) {
  1520. case 0 /* setup */:
  1521. by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
  1522. bone.scaleY = by + (y - by) * alpha;
  1523. break;
  1524. case 1 /* first */:
  1525. case 2 /* replace */:
  1526. by = Math.abs(bone.scaleY) * MathUtils.signum(y);
  1527. bone.scaleY = by + (y - by) * alpha;
  1528. break;
  1529. case 3 /* add */:
  1530. bone.scaleY += (y - bone.data.scaleY) * alpha;
  1531. }
  1532. }
  1533. }
  1534. }
  1535. };
  1536. var ShearTimeline = class extends CurveTimeline2 {
  1537. constructor(frameCount, bezierCount, boneIndex) {
  1538. super(
  1539. frameCount,
  1540. bezierCount,
  1541. Property.shearX + "|" + boneIndex,
  1542. Property.shearY + "|" + boneIndex
  1543. );
  1544. this.boneIndex = 0;
  1545. this.boneIndex = boneIndex;
  1546. }
  1547. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1548. let bone = skeleton.bones[this.boneIndex];
  1549. if (!bone.active)
  1550. return;
  1551. let frames = this.frames;
  1552. if (time < frames[0]) {
  1553. switch (blend) {
  1554. case 0 /* setup */:
  1555. bone.shearX = bone.data.shearX;
  1556. bone.shearY = bone.data.shearY;
  1557. return;
  1558. case 1 /* first */:
  1559. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  1560. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  1561. }
  1562. return;
  1563. }
  1564. let x = 0, y = 0;
  1565. let i = Timeline.search(
  1566. frames,
  1567. time,
  1568. 3
  1569. /*ENTRIES*/
  1570. );
  1571. let curveType = this.curves[
  1572. i / 3
  1573. /*ENTRIES*/
  1574. ];
  1575. switch (curveType) {
  1576. case 0:
  1577. let before = frames[i];
  1578. x = frames[
  1579. i + 1
  1580. /*VALUE1*/
  1581. ];
  1582. y = frames[
  1583. i + 2
  1584. /*VALUE2*/
  1585. ];
  1586. let t = (time - before) / (frames[
  1587. i + 3
  1588. /*ENTRIES*/
  1589. ] - before);
  1590. x += (frames[
  1591. i + 3 + 1
  1592. /*VALUE1*/
  1593. ] - x) * t;
  1594. y += (frames[
  1595. i + 3 + 2
  1596. /*VALUE2*/
  1597. ] - y) * t;
  1598. break;
  1599. case 1:
  1600. x = frames[
  1601. i + 1
  1602. /*VALUE1*/
  1603. ];
  1604. y = frames[
  1605. i + 2
  1606. /*VALUE2*/
  1607. ];
  1608. break;
  1609. default:
  1610. x = this.getBezierValue(
  1611. time,
  1612. i,
  1613. 1,
  1614. curveType - 2
  1615. /*BEZIER*/
  1616. );
  1617. y = this.getBezierValue(
  1618. time,
  1619. i,
  1620. 2,
  1621. curveType + 18 - 2
  1622. /*BEZIER*/
  1623. );
  1624. }
  1625. switch (blend) {
  1626. case 0 /* setup */:
  1627. bone.shearX = bone.data.shearX + x * alpha;
  1628. bone.shearY = bone.data.shearY + y * alpha;
  1629. break;
  1630. case 1 /* first */:
  1631. case 2 /* replace */:
  1632. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  1633. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  1634. break;
  1635. case 3 /* add */:
  1636. bone.shearX += x * alpha;
  1637. bone.shearY += y * alpha;
  1638. }
  1639. }
  1640. };
  1641. var ShearXTimeline = class extends CurveTimeline1 {
  1642. constructor(frameCount, bezierCount, boneIndex) {
  1643. super(frameCount, bezierCount, Property.shearX + "|" + boneIndex);
  1644. this.boneIndex = 0;
  1645. this.boneIndex = boneIndex;
  1646. }
  1647. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1648. let bone = skeleton.bones[this.boneIndex];
  1649. if (!bone.active)
  1650. return;
  1651. let frames = this.frames;
  1652. if (time < frames[0]) {
  1653. switch (blend) {
  1654. case 0 /* setup */:
  1655. bone.shearX = bone.data.shearX;
  1656. return;
  1657. case 1 /* first */:
  1658. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  1659. }
  1660. return;
  1661. }
  1662. let x = this.getCurveValue(time);
  1663. switch (blend) {
  1664. case 0 /* setup */:
  1665. bone.shearX = bone.data.shearX + x * alpha;
  1666. break;
  1667. case 1 /* first */:
  1668. case 2 /* replace */:
  1669. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  1670. break;
  1671. case 3 /* add */:
  1672. bone.shearX += x * alpha;
  1673. }
  1674. }
  1675. };
  1676. var ShearYTimeline = class extends CurveTimeline1 {
  1677. constructor(frameCount, bezierCount, boneIndex) {
  1678. super(frameCount, bezierCount, Property.shearY + "|" + boneIndex);
  1679. this.boneIndex = 0;
  1680. this.boneIndex = boneIndex;
  1681. }
  1682. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1683. let bone = skeleton.bones[this.boneIndex];
  1684. if (!bone.active)
  1685. return;
  1686. let frames = this.frames;
  1687. if (time < frames[0]) {
  1688. switch (blend) {
  1689. case 0 /* setup */:
  1690. bone.shearY = bone.data.shearY;
  1691. return;
  1692. case 1 /* first */:
  1693. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  1694. }
  1695. return;
  1696. }
  1697. let y = this.getCurveValue(time);
  1698. switch (blend) {
  1699. case 0 /* setup */:
  1700. bone.shearY = bone.data.shearY + y * alpha;
  1701. break;
  1702. case 1 /* first */:
  1703. case 2 /* replace */:
  1704. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  1705. break;
  1706. case 3 /* add */:
  1707. bone.shearY += y * alpha;
  1708. }
  1709. }
  1710. };
  1711. var RGBATimeline = class extends CurveTimeline {
  1712. constructor(frameCount, bezierCount, slotIndex) {
  1713. super(frameCount, bezierCount, [
  1714. Property.rgb + "|" + slotIndex,
  1715. Property.alpha + "|" + slotIndex
  1716. ]);
  1717. this.slotIndex = 0;
  1718. this.slotIndex = slotIndex;
  1719. }
  1720. getFrameEntries() {
  1721. return 5;
  1722. }
  1723. /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */
  1724. setFrame(frame, time, r, g, b, a) {
  1725. frame *= 5;
  1726. this.frames[frame] = time;
  1727. this.frames[
  1728. frame + 1
  1729. /*R*/
  1730. ] = r;
  1731. this.frames[
  1732. frame + 2
  1733. /*G*/
  1734. ] = g;
  1735. this.frames[
  1736. frame + 3
  1737. /*B*/
  1738. ] = b;
  1739. this.frames[
  1740. frame + 4
  1741. /*A*/
  1742. ] = a;
  1743. }
  1744. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1745. let slot = skeleton.slots[this.slotIndex];
  1746. if (!slot.bone.active)
  1747. return;
  1748. let frames = this.frames;
  1749. let color = slot.color;
  1750. if (time < frames[0]) {
  1751. let setup = slot.data.color;
  1752. switch (blend) {
  1753. case 0 /* setup */:
  1754. color.setFromColor(setup);
  1755. return;
  1756. case 1 /* first */:
  1757. color.add(
  1758. (setup.r - color.r) * alpha,
  1759. (setup.g - color.g) * alpha,
  1760. (setup.b - color.b) * alpha,
  1761. (setup.a - color.a) * alpha
  1762. );
  1763. }
  1764. return;
  1765. }
  1766. let r = 0, g = 0, b = 0, a = 0;
  1767. let i = Timeline.search(
  1768. frames,
  1769. time,
  1770. 5
  1771. /*ENTRIES*/
  1772. );
  1773. let curveType = this.curves[
  1774. i / 5
  1775. /*ENTRIES*/
  1776. ];
  1777. switch (curveType) {
  1778. case 0:
  1779. let before = frames[i];
  1780. r = frames[
  1781. i + 1
  1782. /*R*/
  1783. ];
  1784. g = frames[
  1785. i + 2
  1786. /*G*/
  1787. ];
  1788. b = frames[
  1789. i + 3
  1790. /*B*/
  1791. ];
  1792. a = frames[
  1793. i + 4
  1794. /*A*/
  1795. ];
  1796. let t = (time - before) / (frames[
  1797. i + 5
  1798. /*ENTRIES*/
  1799. ] - before);
  1800. r += (frames[
  1801. i + 5 + 1
  1802. /*R*/
  1803. ] - r) * t;
  1804. g += (frames[
  1805. i + 5 + 2
  1806. /*G*/
  1807. ] - g) * t;
  1808. b += (frames[
  1809. i + 5 + 3
  1810. /*B*/
  1811. ] - b) * t;
  1812. a += (frames[
  1813. i + 5 + 4
  1814. /*A*/
  1815. ] - a) * t;
  1816. break;
  1817. case 1:
  1818. r = frames[
  1819. i + 1
  1820. /*R*/
  1821. ];
  1822. g = frames[
  1823. i + 2
  1824. /*G*/
  1825. ];
  1826. b = frames[
  1827. i + 3
  1828. /*B*/
  1829. ];
  1830. a = frames[
  1831. i + 4
  1832. /*A*/
  1833. ];
  1834. break;
  1835. default:
  1836. r = this.getBezierValue(
  1837. time,
  1838. i,
  1839. 1,
  1840. curveType - 2
  1841. /*BEZIER*/
  1842. );
  1843. g = this.getBezierValue(
  1844. time,
  1845. i,
  1846. 2,
  1847. curveType + 18 - 2
  1848. /*BEZIER*/
  1849. );
  1850. b = this.getBezierValue(
  1851. time,
  1852. i,
  1853. 3,
  1854. curveType + 18 * 2 - 2
  1855. /*BEZIER*/
  1856. );
  1857. a = this.getBezierValue(
  1858. time,
  1859. i,
  1860. 4,
  1861. curveType + 18 * 3 - 2
  1862. /*BEZIER*/
  1863. );
  1864. }
  1865. if (alpha == 1)
  1866. color.set(r, g, b, a);
  1867. else {
  1868. if (blend == 0 /* setup */)
  1869. color.setFromColor(slot.data.color);
  1870. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  1871. }
  1872. }
  1873. };
  1874. var RGBTimeline = class extends CurveTimeline {
  1875. constructor(frameCount, bezierCount, slotIndex) {
  1876. super(frameCount, bezierCount, [
  1877. Property.rgb + "|" + slotIndex
  1878. ]);
  1879. this.slotIndex = 0;
  1880. this.slotIndex = slotIndex;
  1881. }
  1882. getFrameEntries() {
  1883. return 4;
  1884. }
  1885. /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */
  1886. setFrame(frame, time, r, g, b) {
  1887. frame <<= 2;
  1888. this.frames[frame] = time;
  1889. this.frames[
  1890. frame + 1
  1891. /*R*/
  1892. ] = r;
  1893. this.frames[
  1894. frame + 2
  1895. /*G*/
  1896. ] = g;
  1897. this.frames[
  1898. frame + 3
  1899. /*B*/
  1900. ] = b;
  1901. }
  1902. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  1903. let slot = skeleton.slots[this.slotIndex];
  1904. if (!slot.bone.active)
  1905. return;
  1906. let frames = this.frames;
  1907. let color = slot.color;
  1908. if (time < frames[0]) {
  1909. let setup = slot.data.color;
  1910. switch (blend) {
  1911. case 0 /* setup */:
  1912. color.r = setup.r;
  1913. color.g = setup.g;
  1914. color.b = setup.b;
  1915. return;
  1916. case 1 /* first */:
  1917. color.r += (setup.r - color.r) * alpha;
  1918. color.g += (setup.g - color.g) * alpha;
  1919. color.b += (setup.b - color.b) * alpha;
  1920. }
  1921. return;
  1922. }
  1923. let r = 0, g = 0, b = 0;
  1924. let i = Timeline.search(
  1925. frames,
  1926. time,
  1927. 4
  1928. /*ENTRIES*/
  1929. );
  1930. let curveType = this.curves[i >> 2];
  1931. switch (curveType) {
  1932. case 0:
  1933. let before = frames[i];
  1934. r = frames[
  1935. i + 1
  1936. /*R*/
  1937. ];
  1938. g = frames[
  1939. i + 2
  1940. /*G*/
  1941. ];
  1942. b = frames[
  1943. i + 3
  1944. /*B*/
  1945. ];
  1946. let t = (time - before) / (frames[
  1947. i + 4
  1948. /*ENTRIES*/
  1949. ] - before);
  1950. r += (frames[
  1951. i + 4 + 1
  1952. /*R*/
  1953. ] - r) * t;
  1954. g += (frames[
  1955. i + 4 + 2
  1956. /*G*/
  1957. ] - g) * t;
  1958. b += (frames[
  1959. i + 4 + 3
  1960. /*B*/
  1961. ] - b) * t;
  1962. break;
  1963. case 1:
  1964. r = frames[
  1965. i + 1
  1966. /*R*/
  1967. ];
  1968. g = frames[
  1969. i + 2
  1970. /*G*/
  1971. ];
  1972. b = frames[
  1973. i + 3
  1974. /*B*/
  1975. ];
  1976. break;
  1977. default:
  1978. r = this.getBezierValue(
  1979. time,
  1980. i,
  1981. 1,
  1982. curveType - 2
  1983. /*BEZIER*/
  1984. );
  1985. g = this.getBezierValue(
  1986. time,
  1987. i,
  1988. 2,
  1989. curveType + 18 - 2
  1990. /*BEZIER*/
  1991. );
  1992. b = this.getBezierValue(
  1993. time,
  1994. i,
  1995. 3,
  1996. curveType + 18 * 2 - 2
  1997. /*BEZIER*/
  1998. );
  1999. }
  2000. if (alpha == 1) {
  2001. color.r = r;
  2002. color.g = g;
  2003. color.b = b;
  2004. } else {
  2005. if (blend == 0 /* setup */) {
  2006. let setup = slot.data.color;
  2007. color.r = setup.r;
  2008. color.g = setup.g;
  2009. color.b = setup.b;
  2010. }
  2011. color.r += (r - color.r) * alpha;
  2012. color.g += (g - color.g) * alpha;
  2013. color.b += (b - color.b) * alpha;
  2014. }
  2015. }
  2016. };
  2017. var AlphaTimeline = class extends CurveTimeline1 {
  2018. constructor(frameCount, bezierCount, slotIndex) {
  2019. super(frameCount, bezierCount, Property.alpha + "|" + slotIndex);
  2020. this.slotIndex = 0;
  2021. this.slotIndex = slotIndex;
  2022. }
  2023. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  2024. let slot = skeleton.slots[this.slotIndex];
  2025. if (!slot.bone.active)
  2026. return;
  2027. let color = slot.color;
  2028. if (time < this.frames[0]) {
  2029. let setup = slot.data.color;
  2030. switch (blend) {
  2031. case 0 /* setup */:
  2032. color.a = setup.a;
  2033. return;
  2034. case 1 /* first */:
  2035. color.a += (setup.a - color.a) * alpha;
  2036. }
  2037. return;
  2038. }
  2039. let a = this.getCurveValue(time);
  2040. if (alpha == 1)
  2041. color.a = a;
  2042. else {
  2043. if (blend == 0 /* setup */)
  2044. color.a = slot.data.color.a;
  2045. color.a += (a - color.a) * alpha;
  2046. }
  2047. }
  2048. };
  2049. var RGBA2Timeline = class extends CurveTimeline {
  2050. constructor(frameCount, bezierCount, slotIndex) {
  2051. super(frameCount, bezierCount, [
  2052. Property.rgb + "|" + slotIndex,
  2053. Property.alpha + "|" + slotIndex,
  2054. Property.rgb2 + "|" + slotIndex
  2055. ]);
  2056. this.slotIndex = 0;
  2057. this.slotIndex = slotIndex;
  2058. }
  2059. getFrameEntries() {
  2060. return 8;
  2061. }
  2062. /** Sets the time in seconds, light, and dark colors for the specified key frame. */
  2063. setFrame(frame, time, r, g, b, a, r2, g2, b2) {
  2064. frame <<= 3;
  2065. this.frames[frame] = time;
  2066. this.frames[
  2067. frame + 1
  2068. /*R*/
  2069. ] = r;
  2070. this.frames[
  2071. frame + 2
  2072. /*G*/
  2073. ] = g;
  2074. this.frames[
  2075. frame + 3
  2076. /*B*/
  2077. ] = b;
  2078. this.frames[
  2079. frame + 4
  2080. /*A*/
  2081. ] = a;
  2082. this.frames[
  2083. frame + 5
  2084. /*R2*/
  2085. ] = r2;
  2086. this.frames[
  2087. frame + 6
  2088. /*G2*/
  2089. ] = g2;
  2090. this.frames[
  2091. frame + 7
  2092. /*B2*/
  2093. ] = b2;
  2094. }
  2095. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  2096. let slot = skeleton.slots[this.slotIndex];
  2097. if (!slot.bone.active)
  2098. return;
  2099. let frames = this.frames;
  2100. let light = slot.color, dark = slot.darkColor;
  2101. if (time < frames[0]) {
  2102. let setupLight = slot.data.color, setupDark = slot.data.darkColor;
  2103. switch (blend) {
  2104. case 0 /* setup */:
  2105. light.setFromColor(setupLight);
  2106. dark.r = setupDark.r;
  2107. dark.g = setupDark.g;
  2108. dark.b = setupDark.b;
  2109. return;
  2110. case 1 /* first */:
  2111. light.add(
  2112. (setupLight.r - light.r) * alpha,
  2113. (setupLight.g - light.g) * alpha,
  2114. (setupLight.b - light.b) * alpha,
  2115. (setupLight.a - light.a) * alpha
  2116. );
  2117. dark.r += (setupDark.r - dark.r) * alpha;
  2118. dark.g += (setupDark.g - dark.g) * alpha;
  2119. dark.b += (setupDark.b - dark.b) * alpha;
  2120. }
  2121. return;
  2122. }
  2123. let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  2124. let i = Timeline.search(
  2125. frames,
  2126. time,
  2127. 8
  2128. /*ENTRIES*/
  2129. );
  2130. let curveType = this.curves[i >> 3];
  2131. switch (curveType) {
  2132. case 0:
  2133. let before = frames[i];
  2134. r = frames[
  2135. i + 1
  2136. /*R*/
  2137. ];
  2138. g = frames[
  2139. i + 2
  2140. /*G*/
  2141. ];
  2142. b = frames[
  2143. i + 3
  2144. /*B*/
  2145. ];
  2146. a = frames[
  2147. i + 4
  2148. /*A*/
  2149. ];
  2150. r2 = frames[
  2151. i + 5
  2152. /*R2*/
  2153. ];
  2154. g2 = frames[
  2155. i + 6
  2156. /*G2*/
  2157. ];
  2158. b2 = frames[
  2159. i + 7
  2160. /*B2*/
  2161. ];
  2162. let t = (time - before) / (frames[
  2163. i + 8
  2164. /*ENTRIES*/
  2165. ] - before);
  2166. r += (frames[
  2167. i + 8 + 1
  2168. /*R*/
  2169. ] - r) * t;
  2170. g += (frames[
  2171. i + 8 + 2
  2172. /*G*/
  2173. ] - g) * t;
  2174. b += (frames[
  2175. i + 8 + 3
  2176. /*B*/
  2177. ] - b) * t;
  2178. a += (frames[
  2179. i + 8 + 4
  2180. /*A*/
  2181. ] - a) * t;
  2182. r2 += (frames[
  2183. i + 8 + 5
  2184. /*R2*/
  2185. ] - r2) * t;
  2186. g2 += (frames[
  2187. i + 8 + 6
  2188. /*G2*/
  2189. ] - g2) * t;
  2190. b2 += (frames[
  2191. i + 8 + 7
  2192. /*B2*/
  2193. ] - b2) * t;
  2194. break;
  2195. case 1:
  2196. r = frames[
  2197. i + 1
  2198. /*R*/
  2199. ];
  2200. g = frames[
  2201. i + 2
  2202. /*G*/
  2203. ];
  2204. b = frames[
  2205. i + 3
  2206. /*B*/
  2207. ];
  2208. a = frames[
  2209. i + 4
  2210. /*A*/
  2211. ];
  2212. r2 = frames[
  2213. i + 5
  2214. /*R2*/
  2215. ];
  2216. g2 = frames[
  2217. i + 6
  2218. /*G2*/
  2219. ];
  2220. b2 = frames[
  2221. i + 7
  2222. /*B2*/
  2223. ];
  2224. break;
  2225. default:
  2226. r = this.getBezierValue(
  2227. time,
  2228. i,
  2229. 1,
  2230. curveType - 2
  2231. /*BEZIER*/
  2232. );
  2233. g = this.getBezierValue(
  2234. time,
  2235. i,
  2236. 2,
  2237. curveType + 18 - 2
  2238. /*BEZIER*/
  2239. );
  2240. b = this.getBezierValue(
  2241. time,
  2242. i,
  2243. 3,
  2244. curveType + 18 * 2 - 2
  2245. /*BEZIER*/
  2246. );
  2247. a = this.getBezierValue(
  2248. time,
  2249. i,
  2250. 4,
  2251. curveType + 18 * 3 - 2
  2252. /*BEZIER*/
  2253. );
  2254. r2 = this.getBezierValue(
  2255. time,
  2256. i,
  2257. 5,
  2258. curveType + 18 * 4 - 2
  2259. /*BEZIER*/
  2260. );
  2261. g2 = this.getBezierValue(
  2262. time,
  2263. i,
  2264. 6,
  2265. curveType + 18 * 5 - 2
  2266. /*BEZIER*/
  2267. );
  2268. b2 = this.getBezierValue(
  2269. time,
  2270. i,
  2271. 7,
  2272. curveType + 18 * 6 - 2
  2273. /*BEZIER*/
  2274. );
  2275. }
  2276. if (alpha == 1) {
  2277. light.set(r, g, b, a);
  2278. dark.r = r2;
  2279. dark.g = g2;
  2280. dark.b = b2;
  2281. } else {
  2282. if (blend == 0 /* setup */) {
  2283. light.setFromColor(slot.data.color);
  2284. let setupDark = slot.data.darkColor;
  2285. dark.r = setupDark.r;
  2286. dark.g = setupDark.g;
  2287. dark.b = setupDark.b;
  2288. }
  2289. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  2290. dark.r += (r2 - dark.r) * alpha;
  2291. dark.g += (g2 - dark.g) * alpha;
  2292. dark.b += (b2 - dark.b) * alpha;
  2293. }
  2294. }
  2295. };
  2296. var RGB2Timeline = class extends CurveTimeline {
  2297. constructor(frameCount, bezierCount, slotIndex) {
  2298. super(frameCount, bezierCount, [
  2299. Property.rgb + "|" + slotIndex,
  2300. Property.rgb2 + "|" + slotIndex
  2301. ]);
  2302. this.slotIndex = 0;
  2303. this.slotIndex = slotIndex;
  2304. }
  2305. getFrameEntries() {
  2306. return 7;
  2307. }
  2308. /** Sets the time in seconds, light, and dark colors for the specified key frame. */
  2309. setFrame(frame, time, r, g, b, r2, g2, b2) {
  2310. frame *= 7;
  2311. this.frames[frame] = time;
  2312. this.frames[
  2313. frame + 1
  2314. /*R*/
  2315. ] = r;
  2316. this.frames[
  2317. frame + 2
  2318. /*G*/
  2319. ] = g;
  2320. this.frames[
  2321. frame + 3
  2322. /*B*/
  2323. ] = b;
  2324. this.frames[
  2325. frame + 4
  2326. /*R2*/
  2327. ] = r2;
  2328. this.frames[
  2329. frame + 5
  2330. /*G2*/
  2331. ] = g2;
  2332. this.frames[
  2333. frame + 6
  2334. /*B2*/
  2335. ] = b2;
  2336. }
  2337. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  2338. let slot = skeleton.slots[this.slotIndex];
  2339. if (!slot.bone.active)
  2340. return;
  2341. let frames = this.frames;
  2342. let light = slot.color, dark = slot.darkColor;
  2343. if (time < frames[0]) {
  2344. let setupLight = slot.data.color, setupDark = slot.data.darkColor;
  2345. switch (blend) {
  2346. case 0 /* setup */:
  2347. light.r = setupLight.r;
  2348. light.g = setupLight.g;
  2349. light.b = setupLight.b;
  2350. dark.r = setupDark.r;
  2351. dark.g = setupDark.g;
  2352. dark.b = setupDark.b;
  2353. return;
  2354. case 1 /* first */:
  2355. light.r += (setupLight.r - light.r) * alpha;
  2356. light.g += (setupLight.g - light.g) * alpha;
  2357. light.b += (setupLight.b - light.b) * alpha;
  2358. dark.r += (setupDark.r - dark.r) * alpha;
  2359. dark.g += (setupDark.g - dark.g) * alpha;
  2360. dark.b += (setupDark.b - dark.b) * alpha;
  2361. }
  2362. return;
  2363. }
  2364. let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  2365. let i = Timeline.search(
  2366. frames,
  2367. time,
  2368. 7
  2369. /*ENTRIES*/
  2370. );
  2371. let curveType = this.curves[
  2372. i / 7
  2373. /*ENTRIES*/
  2374. ];
  2375. switch (curveType) {
  2376. case 0:
  2377. let before = frames[i];
  2378. r = frames[
  2379. i + 1
  2380. /*R*/
  2381. ];
  2382. g = frames[
  2383. i + 2
  2384. /*G*/
  2385. ];
  2386. b = frames[
  2387. i + 3
  2388. /*B*/
  2389. ];
  2390. r2 = frames[
  2391. i + 4
  2392. /*R2*/
  2393. ];
  2394. g2 = frames[
  2395. i + 5
  2396. /*G2*/
  2397. ];
  2398. b2 = frames[
  2399. i + 6
  2400. /*B2*/
  2401. ];
  2402. let t = (time - before) / (frames[
  2403. i + 7
  2404. /*ENTRIES*/
  2405. ] - before);
  2406. r += (frames[
  2407. i + 7 + 1
  2408. /*R*/
  2409. ] - r) * t;
  2410. g += (frames[
  2411. i + 7 + 2
  2412. /*G*/
  2413. ] - g) * t;
  2414. b += (frames[
  2415. i + 7 + 3
  2416. /*B*/
  2417. ] - b) * t;
  2418. r2 += (frames[
  2419. i + 7 + 4
  2420. /*R2*/
  2421. ] - r2) * t;
  2422. g2 += (frames[
  2423. i + 7 + 5
  2424. /*G2*/
  2425. ] - g2) * t;
  2426. b2 += (frames[
  2427. i + 7 + 6
  2428. /*B2*/
  2429. ] - b2) * t;
  2430. break;
  2431. case 1:
  2432. r = frames[
  2433. i + 1
  2434. /*R*/
  2435. ];
  2436. g = frames[
  2437. i + 2
  2438. /*G*/
  2439. ];
  2440. b = frames[
  2441. i + 3
  2442. /*B*/
  2443. ];
  2444. r2 = frames[
  2445. i + 4
  2446. /*R2*/
  2447. ];
  2448. g2 = frames[
  2449. i + 5
  2450. /*G2*/
  2451. ];
  2452. b2 = frames[
  2453. i + 6
  2454. /*B2*/
  2455. ];
  2456. break;
  2457. default:
  2458. r = this.getBezierValue(
  2459. time,
  2460. i,
  2461. 1,
  2462. curveType - 2
  2463. /*BEZIER*/
  2464. );
  2465. g = this.getBezierValue(
  2466. time,
  2467. i,
  2468. 2,
  2469. curveType + 18 - 2
  2470. /*BEZIER*/
  2471. );
  2472. b = this.getBezierValue(
  2473. time,
  2474. i,
  2475. 3,
  2476. curveType + 18 * 2 - 2
  2477. /*BEZIER*/
  2478. );
  2479. r2 = this.getBezierValue(
  2480. time,
  2481. i,
  2482. 4,
  2483. curveType + 18 * 3 - 2
  2484. /*BEZIER*/
  2485. );
  2486. g2 = this.getBezierValue(
  2487. time,
  2488. i,
  2489. 5,
  2490. curveType + 18 * 4 - 2
  2491. /*BEZIER*/
  2492. );
  2493. b2 = this.getBezierValue(
  2494. time,
  2495. i,
  2496. 6,
  2497. curveType + 18 * 5 - 2
  2498. /*BEZIER*/
  2499. );
  2500. }
  2501. if (alpha == 1) {
  2502. light.r = r;
  2503. light.g = g;
  2504. light.b = b;
  2505. dark.r = r2;
  2506. dark.g = g2;
  2507. dark.b = b2;
  2508. } else {
  2509. if (blend == 0 /* setup */) {
  2510. let setupLight = slot.data.color, setupDark = slot.data.darkColor;
  2511. light.r = setupLight.r;
  2512. light.g = setupLight.g;
  2513. light.b = setupLight.b;
  2514. dark.r = setupDark.r;
  2515. dark.g = setupDark.g;
  2516. dark.b = setupDark.b;
  2517. }
  2518. light.r += (r - light.r) * alpha;
  2519. light.g += (g - light.g) * alpha;
  2520. light.b += (b - light.b) * alpha;
  2521. dark.r += (r2 - dark.r) * alpha;
  2522. dark.g += (g2 - dark.g) * alpha;
  2523. dark.b += (b2 - dark.b) * alpha;
  2524. }
  2525. }
  2526. };
  2527. var AttachmentTimeline = class extends Timeline {
  2528. constructor(frameCount, slotIndex) {
  2529. super(frameCount, [
  2530. Property.attachment + "|" + slotIndex
  2531. ]);
  2532. this.slotIndex = 0;
  2533. this.slotIndex = slotIndex;
  2534. this.attachmentNames = new Array(frameCount);
  2535. }
  2536. getFrameCount() {
  2537. return this.frames.length;
  2538. }
  2539. /** Sets the time in seconds and the attachment name for the specified key frame. */
  2540. setFrame(frame, time, attachmentName) {
  2541. this.frames[frame] = time;
  2542. this.attachmentNames[frame] = attachmentName;
  2543. }
  2544. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  2545. let slot = skeleton.slots[this.slotIndex];
  2546. if (!slot.bone.active)
  2547. return;
  2548. if (direction == 1 /* mixOut */) {
  2549. if (blend == 0 /* setup */)
  2550. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  2551. return;
  2552. }
  2553. if (time < this.frames[0]) {
  2554. if (blend == 0 /* setup */ || blend == 1 /* first */)
  2555. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  2556. return;
  2557. }
  2558. this.setAttachment(skeleton, slot, this.attachmentNames[Timeline.search1(this.frames, time)]);
  2559. }
  2560. setAttachment(skeleton, slot, attachmentName) {
  2561. slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  2562. }
  2563. };
  2564. var DeformTimeline = class extends CurveTimeline {
  2565. constructor(frameCount, bezierCount, slotIndex, attachment) {
  2566. super(frameCount, bezierCount, [
  2567. Property.deform + "|" + slotIndex + "|" + attachment.id
  2568. ]);
  2569. this.slotIndex = 0;
  2570. this.slotIndex = slotIndex;
  2571. this.attachment = attachment;
  2572. this.vertices = new Array(frameCount);
  2573. }
  2574. getFrameCount() {
  2575. return this.frames.length;
  2576. }
  2577. /** Sets the time in seconds and the vertices for the specified key frame.
  2578. * @param vertices Vertex positions for an unweighted VertexAttachment, or deform offsets if it has weights. */
  2579. setFrame(frame, time, vertices) {
  2580. this.frames[frame] = time;
  2581. this.vertices[frame] = vertices;
  2582. }
  2583. /** @param value1 Ignored (0 is used for a deform timeline).
  2584. * @param value2 Ignored (1 is used for a deform timeline). */
  2585. setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) {
  2586. let curves = this.curves;
  2587. let i = this.getFrameCount() + bezier * 18;
  2588. if (value == 0)
  2589. curves[frame] = 2 + i;
  2590. let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06;
  2591. let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 6e-3, dddy = (cy1 - cy2 + 0.33333333) * 0.018;
  2592. let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
  2593. let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667;
  2594. let x = time1 + dx, y = dy;
  2595. for (let n = i + 18; i < n; i += 2) {
  2596. curves[i] = x;
  2597. curves[i + 1] = y;
  2598. dx += ddx;
  2599. dy += ddy;
  2600. ddx += dddx;
  2601. ddy += dddy;
  2602. x += dx;
  2603. y += dy;
  2604. }
  2605. }
  2606. getCurvePercent(time, frame) {
  2607. let curves = this.curves;
  2608. let i = curves[frame];
  2609. switch (i) {
  2610. case 0:
  2611. let x2 = this.frames[frame];
  2612. return (time - x2) / (this.frames[frame + this.getFrameEntries()] - x2);
  2613. case 1:
  2614. return 0;
  2615. }
  2616. i -= 2;
  2617. if (curves[i] > time) {
  2618. let x2 = this.frames[frame];
  2619. return curves[i + 1] * (time - x2) / (curves[i] - x2);
  2620. }
  2621. let n = i + 18;
  2622. for (i += 2; i < n; i += 2) {
  2623. if (curves[i] >= time) {
  2624. let x2 = curves[i - 2], y2 = curves[i - 1];
  2625. return y2 + (time - x2) / (curves[i] - x2) * (curves[i + 1] - y2);
  2626. }
  2627. }
  2628. let x = curves[n - 2], y = curves[n - 1];
  2629. return y + (1 - y) * (time - x) / (this.frames[frame + this.getFrameEntries()] - x);
  2630. }
  2631. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  2632. let slot = skeleton.slots[this.slotIndex];
  2633. if (!slot.bone.active)
  2634. return;
  2635. let slotAttachment = slot.getAttachment();
  2636. if (!slotAttachment)
  2637. return;
  2638. if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.timelineAttachment != this.attachment)
  2639. return;
  2640. let deform = slot.deform;
  2641. if (deform.length == 0)
  2642. blend = 0 /* setup */;
  2643. let vertices = this.vertices;
  2644. let vertexCount = vertices[0].length;
  2645. let frames = this.frames;
  2646. if (time < frames[0]) {
  2647. switch (blend) {
  2648. case 0 /* setup */:
  2649. deform.length = 0;
  2650. return;
  2651. case 1 /* first */:
  2652. if (alpha == 1) {
  2653. deform.length = 0;
  2654. return;
  2655. }
  2656. deform.length = vertexCount;
  2657. let vertexAttachment = slotAttachment;
  2658. if (!vertexAttachment.bones) {
  2659. let setupVertices = vertexAttachment.vertices;
  2660. for (var i = 0; i < vertexCount; i++)
  2661. deform[i] += (setupVertices[i] - deform[i]) * alpha;
  2662. } else {
  2663. alpha = 1 - alpha;
  2664. for (var i = 0; i < vertexCount; i++)
  2665. deform[i] *= alpha;
  2666. }
  2667. }
  2668. return;
  2669. }
  2670. deform.length = vertexCount;
  2671. if (time >= frames[frames.length - 1]) {
  2672. let lastVertices = vertices[frames.length - 1];
  2673. if (alpha == 1) {
  2674. if (blend == 3 /* add */) {
  2675. let vertexAttachment = slotAttachment;
  2676. if (!vertexAttachment.bones) {
  2677. let setupVertices = vertexAttachment.vertices;
  2678. for (let i2 = 0; i2 < vertexCount; i2++)
  2679. deform[i2] += lastVertices[i2] - setupVertices[i2];
  2680. } else {
  2681. for (let i2 = 0; i2 < vertexCount; i2++)
  2682. deform[i2] += lastVertices[i2];
  2683. }
  2684. } else
  2685. Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount);
  2686. } else {
  2687. switch (blend) {
  2688. case 0 /* setup */: {
  2689. let vertexAttachment2 = slotAttachment;
  2690. if (!vertexAttachment2.bones) {
  2691. let setupVertices = vertexAttachment2.vertices;
  2692. for (let i2 = 0; i2 < vertexCount; i2++) {
  2693. let setup = setupVertices[i2];
  2694. deform[i2] = setup + (lastVertices[i2] - setup) * alpha;
  2695. }
  2696. } else {
  2697. for (let i2 = 0; i2 < vertexCount; i2++)
  2698. deform[i2] = lastVertices[i2] * alpha;
  2699. }
  2700. break;
  2701. }
  2702. case 1 /* first */:
  2703. case 2 /* replace */:
  2704. for (let i2 = 0; i2 < vertexCount; i2++)
  2705. deform[i2] += (lastVertices[i2] - deform[i2]) * alpha;
  2706. break;
  2707. case 3 /* add */:
  2708. let vertexAttachment = slotAttachment;
  2709. if (!vertexAttachment.bones) {
  2710. let setupVertices = vertexAttachment.vertices;
  2711. for (let i2 = 0; i2 < vertexCount; i2++)
  2712. deform[i2] += (lastVertices[i2] - setupVertices[i2]) * alpha;
  2713. } else {
  2714. for (let i2 = 0; i2 < vertexCount; i2++)
  2715. deform[i2] += lastVertices[i2] * alpha;
  2716. }
  2717. }
  2718. }
  2719. return;
  2720. }
  2721. let frame = Timeline.search1(frames, time);
  2722. let percent = this.getCurvePercent(time, frame);
  2723. let prevVertices = vertices[frame];
  2724. let nextVertices = vertices[frame + 1];
  2725. if (alpha == 1) {
  2726. if (blend == 3 /* add */) {
  2727. let vertexAttachment = slotAttachment;
  2728. if (!vertexAttachment.bones) {
  2729. let setupVertices = vertexAttachment.vertices;
  2730. for (let i2 = 0; i2 < vertexCount; i2++) {
  2731. let prev = prevVertices[i2];
  2732. deform[i2] += prev + (nextVertices[i2] - prev) * percent - setupVertices[i2];
  2733. }
  2734. } else {
  2735. for (let i2 = 0; i2 < vertexCount; i2++) {
  2736. let prev = prevVertices[i2];
  2737. deform[i2] += prev + (nextVertices[i2] - prev) * percent;
  2738. }
  2739. }
  2740. } else {
  2741. for (let i2 = 0; i2 < vertexCount; i2++) {
  2742. let prev = prevVertices[i2];
  2743. deform[i2] = prev + (nextVertices[i2] - prev) * percent;
  2744. }
  2745. }
  2746. } else {
  2747. switch (blend) {
  2748. case 0 /* setup */: {
  2749. let vertexAttachment2 = slotAttachment;
  2750. if (!vertexAttachment2.bones) {
  2751. let setupVertices = vertexAttachment2.vertices;
  2752. for (let i2 = 0; i2 < vertexCount; i2++) {
  2753. let prev = prevVertices[i2], setup = setupVertices[i2];
  2754. deform[i2] = setup + (prev + (nextVertices[i2] - prev) * percent - setup) * alpha;
  2755. }
  2756. } else {
  2757. for (let i2 = 0; i2 < vertexCount; i2++) {
  2758. let prev = prevVertices[i2];
  2759. deform[i2] = (prev + (nextVertices[i2] - prev) * percent) * alpha;
  2760. }
  2761. }
  2762. break;
  2763. }
  2764. case 1 /* first */:
  2765. case 2 /* replace */:
  2766. for (let i2 = 0; i2 < vertexCount; i2++) {
  2767. let prev = prevVertices[i2];
  2768. deform[i2] += (prev + (nextVertices[i2] - prev) * percent - deform[i2]) * alpha;
  2769. }
  2770. break;
  2771. case 3 /* add */:
  2772. let vertexAttachment = slotAttachment;
  2773. if (!vertexAttachment.bones) {
  2774. let setupVertices = vertexAttachment.vertices;
  2775. for (let i2 = 0; i2 < vertexCount; i2++) {
  2776. let prev = prevVertices[i2];
  2777. deform[i2] += (prev + (nextVertices[i2] - prev) * percent - setupVertices[i2]) * alpha;
  2778. }
  2779. } else {
  2780. for (let i2 = 0; i2 < vertexCount; i2++) {
  2781. let prev = prevVertices[i2];
  2782. deform[i2] += (prev + (nextVertices[i2] - prev) * percent) * alpha;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. };
  2789. var _EventTimeline = class extends Timeline {
  2790. constructor(frameCount) {
  2791. super(frameCount, _EventTimeline.propertyIds);
  2792. this.events = new Array(frameCount);
  2793. }
  2794. getFrameCount() {
  2795. return this.frames.length;
  2796. }
  2797. /** Sets the time in seconds and the event for the specified key frame. */
  2798. setFrame(frame, event) {
  2799. this.frames[frame] = event.time;
  2800. this.events[frame] = event;
  2801. }
  2802. /** Fires events for frames > `lastTime` and <= `time`. */
  2803. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  2804. if (!firedEvents)
  2805. return;
  2806. let frames = this.frames;
  2807. let frameCount = this.frames.length;
  2808. if (lastTime > time) {
  2809. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction);
  2810. lastTime = -1;
  2811. } else if (lastTime >= frames[frameCount - 1])
  2812. return;
  2813. if (time < frames[0])
  2814. return;
  2815. let i = 0;
  2816. if (lastTime < frames[0])
  2817. i = 0;
  2818. else {
  2819. i = Timeline.search1(frames, lastTime) + 1;
  2820. let frameTime = frames[i];
  2821. while (i > 0) {
  2822. if (frames[i - 1] != frameTime)
  2823. break;
  2824. i--;
  2825. }
  2826. }
  2827. for (; i < frameCount && time >= frames[i]; i++)
  2828. firedEvents.push(this.events[i]);
  2829. }
  2830. };
  2831. var EventTimeline = _EventTimeline;
  2832. EventTimeline.propertyIds = ["" + Property.event];
  2833. var _DrawOrderTimeline = class extends Timeline {
  2834. constructor(frameCount) {
  2835. super(frameCount, _DrawOrderTimeline.propertyIds);
  2836. this.drawOrders = new Array(frameCount);
  2837. }
  2838. getFrameCount() {
  2839. return this.frames.length;
  2840. }
  2841. /** Sets the time in seconds and the draw order for the specified key frame.
  2842. * @param drawOrder For each slot in {@link Skeleton#slots}, the index of the new draw order. May be null to use setup pose
  2843. * draw order. */
  2844. setFrame(frame, time, drawOrder) {
  2845. this.frames[frame] = time;
  2846. this.drawOrders[frame] = drawOrder;
  2847. }
  2848. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  2849. if (direction == 1 /* mixOut */) {
  2850. if (blend == 0 /* setup */)
  2851. Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  2852. return;
  2853. }
  2854. if (time < this.frames[0]) {
  2855. if (blend == 0 /* setup */ || blend == 1 /* first */)
  2856. Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  2857. return;
  2858. }
  2859. let idx = Timeline.search1(this.frames, time);
  2860. let drawOrderToSetupIndex = this.drawOrders[idx];
  2861. if (!drawOrderToSetupIndex)
  2862. Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  2863. else {
  2864. let drawOrder = skeleton.drawOrder;
  2865. let slots = skeleton.slots;
  2866. for (let i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  2867. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  2868. }
  2869. }
  2870. };
  2871. var DrawOrderTimeline = _DrawOrderTimeline;
  2872. DrawOrderTimeline.propertyIds = ["" + Property.drawOrder];
  2873. var IkConstraintTimeline = class extends CurveTimeline {
  2874. constructor(frameCount, bezierCount, ikConstraintIndex) {
  2875. super(frameCount, bezierCount, [
  2876. Property.ikConstraint + "|" + ikConstraintIndex
  2877. ]);
  2878. /** The index of the IK constraint slot in {@link Skeleton#ikConstraints} that will be changed. */
  2879. this.ikConstraintIndex = 0;
  2880. this.ikConstraintIndex = ikConstraintIndex;
  2881. }
  2882. getFrameEntries() {
  2883. return 6;
  2884. }
  2885. /** Sets the time in seconds, mix, softness, bend direction, compress, and stretch for the specified key frame. */
  2886. setFrame(frame, time, mix, softness, bendDirection, compress, stretch) {
  2887. frame *= 6;
  2888. this.frames[frame] = time;
  2889. this.frames[
  2890. frame + 1
  2891. /*MIX*/
  2892. ] = mix;
  2893. this.frames[
  2894. frame + 2
  2895. /*SOFTNESS*/
  2896. ] = softness;
  2897. this.frames[
  2898. frame + 3
  2899. /*BEND_DIRECTION*/
  2900. ] = bendDirection;
  2901. this.frames[
  2902. frame + 4
  2903. /*COMPRESS*/
  2904. ] = compress ? 1 : 0;
  2905. this.frames[
  2906. frame + 5
  2907. /*STRETCH*/
  2908. ] = stretch ? 1 : 0;
  2909. }
  2910. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  2911. let constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  2912. if (!constraint.active)
  2913. return;
  2914. let frames = this.frames;
  2915. if (time < frames[0]) {
  2916. switch (blend) {
  2917. case 0 /* setup */:
  2918. constraint.mix = constraint.data.mix;
  2919. constraint.softness = constraint.data.softness;
  2920. constraint.bendDirection = constraint.data.bendDirection;
  2921. constraint.compress = constraint.data.compress;
  2922. constraint.stretch = constraint.data.stretch;
  2923. return;
  2924. case 1 /* first */:
  2925. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  2926. constraint.softness += (constraint.data.softness - constraint.softness) * alpha;
  2927. constraint.bendDirection = constraint.data.bendDirection;
  2928. constraint.compress = constraint.data.compress;
  2929. constraint.stretch = constraint.data.stretch;
  2930. }
  2931. return;
  2932. }
  2933. let mix = 0, softness = 0;
  2934. let i = Timeline.search(
  2935. frames,
  2936. time,
  2937. 6
  2938. /*ENTRIES*/
  2939. );
  2940. let curveType = this.curves[
  2941. i / 6
  2942. /*ENTRIES*/
  2943. ];
  2944. switch (curveType) {
  2945. case 0:
  2946. let before = frames[i];
  2947. mix = frames[
  2948. i + 1
  2949. /*MIX*/
  2950. ];
  2951. softness = frames[
  2952. i + 2
  2953. /*SOFTNESS*/
  2954. ];
  2955. let t = (time - before) / (frames[
  2956. i + 6
  2957. /*ENTRIES*/
  2958. ] - before);
  2959. mix += (frames[
  2960. i + 6 + 1
  2961. /*MIX*/
  2962. ] - mix) * t;
  2963. softness += (frames[
  2964. i + 6 + 2
  2965. /*SOFTNESS*/
  2966. ] - softness) * t;
  2967. break;
  2968. case 1:
  2969. mix = frames[
  2970. i + 1
  2971. /*MIX*/
  2972. ];
  2973. softness = frames[
  2974. i + 2
  2975. /*SOFTNESS*/
  2976. ];
  2977. break;
  2978. default:
  2979. mix = this.getBezierValue(
  2980. time,
  2981. i,
  2982. 1,
  2983. curveType - 2
  2984. /*BEZIER*/
  2985. );
  2986. softness = this.getBezierValue(
  2987. time,
  2988. i,
  2989. 2,
  2990. curveType + 18 - 2
  2991. /*BEZIER*/
  2992. );
  2993. }
  2994. if (blend == 0 /* setup */) {
  2995. constraint.mix = constraint.data.mix + (mix - constraint.data.mix) * alpha;
  2996. constraint.softness = constraint.data.softness + (softness - constraint.data.softness) * alpha;
  2997. if (direction == 1 /* mixOut */) {
  2998. constraint.bendDirection = constraint.data.bendDirection;
  2999. constraint.compress = constraint.data.compress;
  3000. constraint.stretch = constraint.data.stretch;
  3001. } else {
  3002. constraint.bendDirection = frames[
  3003. i + 3
  3004. /*BEND_DIRECTION*/
  3005. ];
  3006. constraint.compress = frames[
  3007. i + 4
  3008. /*COMPRESS*/
  3009. ] != 0;
  3010. constraint.stretch = frames[
  3011. i + 5
  3012. /*STRETCH*/
  3013. ] != 0;
  3014. }
  3015. } else {
  3016. constraint.mix += (mix - constraint.mix) * alpha;
  3017. constraint.softness += (softness - constraint.softness) * alpha;
  3018. if (direction == 0 /* mixIn */) {
  3019. constraint.bendDirection = frames[
  3020. i + 3
  3021. /*BEND_DIRECTION*/
  3022. ];
  3023. constraint.compress = frames[
  3024. i + 4
  3025. /*COMPRESS*/
  3026. ] != 0;
  3027. constraint.stretch = frames[
  3028. i + 5
  3029. /*STRETCH*/
  3030. ] != 0;
  3031. }
  3032. }
  3033. }
  3034. };
  3035. var TransformConstraintTimeline = class extends CurveTimeline {
  3036. constructor(frameCount, bezierCount, transformConstraintIndex) {
  3037. super(frameCount, bezierCount, [
  3038. Property.transformConstraint + "|" + transformConstraintIndex
  3039. ]);
  3040. /** The index of the transform constraint slot in {@link Skeleton#transformConstraints} that will be changed. */
  3041. this.transformConstraintIndex = 0;
  3042. this.transformConstraintIndex = transformConstraintIndex;
  3043. }
  3044. getFrameEntries() {
  3045. return 7;
  3046. }
  3047. /** The time in seconds, rotate mix, translate mix, scale mix, and shear mix for the specified key frame. */
  3048. setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY) {
  3049. let frames = this.frames;
  3050. frame *= 7;
  3051. frames[frame] = time;
  3052. frames[
  3053. frame + 1
  3054. /*ROTATE*/
  3055. ] = mixRotate;
  3056. frames[
  3057. frame + 2
  3058. /*X*/
  3059. ] = mixX;
  3060. frames[
  3061. frame + 3
  3062. /*Y*/
  3063. ] = mixY;
  3064. frames[
  3065. frame + 4
  3066. /*SCALEX*/
  3067. ] = mixScaleX;
  3068. frames[
  3069. frame + 5
  3070. /*SCALEY*/
  3071. ] = mixScaleY;
  3072. frames[
  3073. frame + 6
  3074. /*SHEARY*/
  3075. ] = mixShearY;
  3076. }
  3077. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3078. let constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  3079. if (!constraint.active)
  3080. return;
  3081. let frames = this.frames;
  3082. if (time < frames[0]) {
  3083. let data = constraint.data;
  3084. switch (blend) {
  3085. case 0 /* setup */:
  3086. constraint.mixRotate = data.mixRotate;
  3087. constraint.mixX = data.mixX;
  3088. constraint.mixY = data.mixY;
  3089. constraint.mixScaleX = data.mixScaleX;
  3090. constraint.mixScaleY = data.mixScaleY;
  3091. constraint.mixShearY = data.mixShearY;
  3092. return;
  3093. case 1 /* first */:
  3094. constraint.mixRotate += (data.mixRotate - constraint.mixRotate) * alpha;
  3095. constraint.mixX += (data.mixX - constraint.mixX) * alpha;
  3096. constraint.mixY += (data.mixY - constraint.mixY) * alpha;
  3097. constraint.mixScaleX += (data.mixScaleX - constraint.mixScaleX) * alpha;
  3098. constraint.mixScaleY += (data.mixScaleY - constraint.mixScaleY) * alpha;
  3099. constraint.mixShearY += (data.mixShearY - constraint.mixShearY) * alpha;
  3100. }
  3101. return;
  3102. }
  3103. let rotate, x, y, scaleX, scaleY, shearY;
  3104. let i = Timeline.search(
  3105. frames,
  3106. time,
  3107. 7
  3108. /*ENTRIES*/
  3109. );
  3110. let curveType = this.curves[
  3111. i / 7
  3112. /*ENTRIES*/
  3113. ];
  3114. switch (curveType) {
  3115. case 0:
  3116. let before = frames[i];
  3117. rotate = frames[
  3118. i + 1
  3119. /*ROTATE*/
  3120. ];
  3121. x = frames[
  3122. i + 2
  3123. /*X*/
  3124. ];
  3125. y = frames[
  3126. i + 3
  3127. /*Y*/
  3128. ];
  3129. scaleX = frames[
  3130. i + 4
  3131. /*SCALEX*/
  3132. ];
  3133. scaleY = frames[
  3134. i + 5
  3135. /*SCALEY*/
  3136. ];
  3137. shearY = frames[
  3138. i + 6
  3139. /*SHEARY*/
  3140. ];
  3141. let t = (time - before) / (frames[
  3142. i + 7
  3143. /*ENTRIES*/
  3144. ] - before);
  3145. rotate += (frames[
  3146. i + 7 + 1
  3147. /*ROTATE*/
  3148. ] - rotate) * t;
  3149. x += (frames[
  3150. i + 7 + 2
  3151. /*X*/
  3152. ] - x) * t;
  3153. y += (frames[
  3154. i + 7 + 3
  3155. /*Y*/
  3156. ] - y) * t;
  3157. scaleX += (frames[
  3158. i + 7 + 4
  3159. /*SCALEX*/
  3160. ] - scaleX) * t;
  3161. scaleY += (frames[
  3162. i + 7 + 5
  3163. /*SCALEY*/
  3164. ] - scaleY) * t;
  3165. shearY += (frames[
  3166. i + 7 + 6
  3167. /*SHEARY*/
  3168. ] - shearY) * t;
  3169. break;
  3170. case 1:
  3171. rotate = frames[
  3172. i + 1
  3173. /*ROTATE*/
  3174. ];
  3175. x = frames[
  3176. i + 2
  3177. /*X*/
  3178. ];
  3179. y = frames[
  3180. i + 3
  3181. /*Y*/
  3182. ];
  3183. scaleX = frames[
  3184. i + 4
  3185. /*SCALEX*/
  3186. ];
  3187. scaleY = frames[
  3188. i + 5
  3189. /*SCALEY*/
  3190. ];
  3191. shearY = frames[
  3192. i + 6
  3193. /*SHEARY*/
  3194. ];
  3195. break;
  3196. default:
  3197. rotate = this.getBezierValue(
  3198. time,
  3199. i,
  3200. 1,
  3201. curveType - 2
  3202. /*BEZIER*/
  3203. );
  3204. x = this.getBezierValue(
  3205. time,
  3206. i,
  3207. 2,
  3208. curveType + 18 - 2
  3209. /*BEZIER*/
  3210. );
  3211. y = this.getBezierValue(
  3212. time,
  3213. i,
  3214. 3,
  3215. curveType + 18 * 2 - 2
  3216. /*BEZIER*/
  3217. );
  3218. scaleX = this.getBezierValue(
  3219. time,
  3220. i,
  3221. 4,
  3222. curveType + 18 * 3 - 2
  3223. /*BEZIER*/
  3224. );
  3225. scaleY = this.getBezierValue(
  3226. time,
  3227. i,
  3228. 5,
  3229. curveType + 18 * 4 - 2
  3230. /*BEZIER*/
  3231. );
  3232. shearY = this.getBezierValue(
  3233. time,
  3234. i,
  3235. 6,
  3236. curveType + 18 * 5 - 2
  3237. /*BEZIER*/
  3238. );
  3239. }
  3240. if (blend == 0 /* setup */) {
  3241. let data = constraint.data;
  3242. constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha;
  3243. constraint.mixX = data.mixX + (x - data.mixX) * alpha;
  3244. constraint.mixY = data.mixY + (y - data.mixY) * alpha;
  3245. constraint.mixScaleX = data.mixScaleX + (scaleX - data.mixScaleX) * alpha;
  3246. constraint.mixScaleY = data.mixScaleY + (scaleY - data.mixScaleY) * alpha;
  3247. constraint.mixShearY = data.mixShearY + (shearY - data.mixShearY) * alpha;
  3248. } else {
  3249. constraint.mixRotate += (rotate - constraint.mixRotate) * alpha;
  3250. constraint.mixX += (x - constraint.mixX) * alpha;
  3251. constraint.mixY += (y - constraint.mixY) * alpha;
  3252. constraint.mixScaleX += (scaleX - constraint.mixScaleX) * alpha;
  3253. constraint.mixScaleY += (scaleY - constraint.mixScaleY) * alpha;
  3254. constraint.mixShearY += (shearY - constraint.mixShearY) * alpha;
  3255. }
  3256. }
  3257. };
  3258. var PathConstraintPositionTimeline = class extends CurveTimeline1 {
  3259. constructor(frameCount, bezierCount, pathConstraintIndex) {
  3260. super(frameCount, bezierCount, Property.pathConstraintPosition + "|" + pathConstraintIndex);
  3261. /** The index of the path constraint slot in {@link Skeleton#pathConstraints} that will be changed. */
  3262. this.pathConstraintIndex = 0;
  3263. this.pathConstraintIndex = pathConstraintIndex;
  3264. }
  3265. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3266. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  3267. if (!constraint.active)
  3268. return;
  3269. let frames = this.frames;
  3270. if (time < frames[0]) {
  3271. switch (blend) {
  3272. case 0 /* setup */:
  3273. constraint.position = constraint.data.position;
  3274. return;
  3275. case 1 /* first */:
  3276. constraint.position += (constraint.data.position - constraint.position) * alpha;
  3277. }
  3278. return;
  3279. }
  3280. let position = this.getCurveValue(time);
  3281. if (blend == 0 /* setup */)
  3282. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  3283. else
  3284. constraint.position += (position - constraint.position) * alpha;
  3285. }
  3286. };
  3287. var PathConstraintSpacingTimeline = class extends CurveTimeline1 {
  3288. constructor(frameCount, bezierCount, pathConstraintIndex) {
  3289. super(frameCount, bezierCount, Property.pathConstraintSpacing + "|" + pathConstraintIndex);
  3290. /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */
  3291. this.pathConstraintIndex = 0;
  3292. this.pathConstraintIndex = pathConstraintIndex;
  3293. }
  3294. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3295. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  3296. if (!constraint.active)
  3297. return;
  3298. let frames = this.frames;
  3299. if (time < frames[0]) {
  3300. switch (blend) {
  3301. case 0 /* setup */:
  3302. constraint.spacing = constraint.data.spacing;
  3303. return;
  3304. case 1 /* first */:
  3305. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  3306. }
  3307. return;
  3308. }
  3309. let spacing = this.getCurveValue(time);
  3310. if (blend == 0 /* setup */)
  3311. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  3312. else
  3313. constraint.spacing += (spacing - constraint.spacing) * alpha;
  3314. }
  3315. };
  3316. var PathConstraintMixTimeline = class extends CurveTimeline {
  3317. constructor(frameCount, bezierCount, pathConstraintIndex) {
  3318. super(frameCount, bezierCount, [
  3319. Property.pathConstraintMix + "|" + pathConstraintIndex
  3320. ]);
  3321. /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */
  3322. this.pathConstraintIndex = 0;
  3323. this.pathConstraintIndex = pathConstraintIndex;
  3324. }
  3325. getFrameEntries() {
  3326. return 4;
  3327. }
  3328. setFrame(frame, time, mixRotate, mixX, mixY) {
  3329. let frames = this.frames;
  3330. frame <<= 2;
  3331. frames[frame] = time;
  3332. frames[
  3333. frame + 1
  3334. /*ROTATE*/
  3335. ] = mixRotate;
  3336. frames[
  3337. frame + 2
  3338. /*X*/
  3339. ] = mixX;
  3340. frames[
  3341. frame + 3
  3342. /*Y*/
  3343. ] = mixY;
  3344. }
  3345. apply(skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3346. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  3347. if (!constraint.active)
  3348. return;
  3349. let frames = this.frames;
  3350. if (time < frames[0]) {
  3351. switch (blend) {
  3352. case 0 /* setup */:
  3353. constraint.mixRotate = constraint.data.mixRotate;
  3354. constraint.mixX = constraint.data.mixX;
  3355. constraint.mixY = constraint.data.mixY;
  3356. return;
  3357. case 1 /* first */:
  3358. constraint.mixRotate += (constraint.data.mixRotate - constraint.mixRotate) * alpha;
  3359. constraint.mixX += (constraint.data.mixX - constraint.mixX) * alpha;
  3360. constraint.mixY += (constraint.data.mixY - constraint.mixY) * alpha;
  3361. }
  3362. return;
  3363. }
  3364. let rotate, x, y;
  3365. let i = Timeline.search(
  3366. frames,
  3367. time,
  3368. 4
  3369. /*ENTRIES*/
  3370. );
  3371. let curveType = this.curves[i >> 2];
  3372. switch (curveType) {
  3373. case 0:
  3374. let before = frames[i];
  3375. rotate = frames[
  3376. i + 1
  3377. /*ROTATE*/
  3378. ];
  3379. x = frames[
  3380. i + 2
  3381. /*X*/
  3382. ];
  3383. y = frames[
  3384. i + 3
  3385. /*Y*/
  3386. ];
  3387. let t = (time - before) / (frames[
  3388. i + 4
  3389. /*ENTRIES*/
  3390. ] - before);
  3391. rotate += (frames[
  3392. i + 4 + 1
  3393. /*ROTATE*/
  3394. ] - rotate) * t;
  3395. x += (frames[
  3396. i + 4 + 2
  3397. /*X*/
  3398. ] - x) * t;
  3399. y += (frames[
  3400. i + 4 + 3
  3401. /*Y*/
  3402. ] - y) * t;
  3403. break;
  3404. case 1:
  3405. rotate = frames[
  3406. i + 1
  3407. /*ROTATE*/
  3408. ];
  3409. x = frames[
  3410. i + 2
  3411. /*X*/
  3412. ];
  3413. y = frames[
  3414. i + 3
  3415. /*Y*/
  3416. ];
  3417. break;
  3418. default:
  3419. rotate = this.getBezierValue(
  3420. time,
  3421. i,
  3422. 1,
  3423. curveType - 2
  3424. /*BEZIER*/
  3425. );
  3426. x = this.getBezierValue(
  3427. time,
  3428. i,
  3429. 2,
  3430. curveType + 18 - 2
  3431. /*BEZIER*/
  3432. );
  3433. y = this.getBezierValue(
  3434. time,
  3435. i,
  3436. 3,
  3437. curveType + 18 * 2 - 2
  3438. /*BEZIER*/
  3439. );
  3440. }
  3441. if (blend == 0 /* setup */) {
  3442. let data = constraint.data;
  3443. constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha;
  3444. constraint.mixX = data.mixX + (x - data.mixX) * alpha;
  3445. constraint.mixY = data.mixY + (y - data.mixY) * alpha;
  3446. } else {
  3447. constraint.mixRotate += (rotate - constraint.mixRotate) * alpha;
  3448. constraint.mixX += (x - constraint.mixX) * alpha;
  3449. constraint.mixY += (y - constraint.mixY) * alpha;
  3450. }
  3451. }
  3452. };
  3453. var _SequenceTimeline = class extends Timeline {
  3454. constructor(frameCount, slotIndex, attachment) {
  3455. super(frameCount, [
  3456. Property.sequence + "|" + slotIndex + "|" + attachment.sequence.id
  3457. ]);
  3458. this.slotIndex = slotIndex;
  3459. this.attachment = attachment;
  3460. }
  3461. getFrameEntries() {
  3462. return _SequenceTimeline.ENTRIES;
  3463. }
  3464. getSlotIndex() {
  3465. return this.slotIndex;
  3466. }
  3467. getAttachment() {
  3468. return this.attachment;
  3469. }
  3470. /** Sets the time, mode, index, and frame time for the specified frame.
  3471. * @param frame Between 0 and <code>frameCount</code>, inclusive.
  3472. * @param time Seconds between frames. */
  3473. setFrame(frame, time, mode, index, delay) {
  3474. let frames = this.frames;
  3475. frame *= _SequenceTimeline.ENTRIES;
  3476. frames[frame] = time;
  3477. frames[frame + _SequenceTimeline.MODE] = mode | index << 4;
  3478. frames[frame + _SequenceTimeline.DELAY] = delay;
  3479. }
  3480. apply(skeleton, lastTime, time, events, alpha, blend, direction) {
  3481. let slot = skeleton.slots[this.slotIndex];
  3482. if (!slot.bone.active)
  3483. return;
  3484. let slotAttachment = slot.attachment;
  3485. let attachment = this.attachment;
  3486. if (slotAttachment != attachment) {
  3487. if (!(slotAttachment instanceof VertexAttachment) || slotAttachment.timelineAttachment != attachment)
  3488. return;
  3489. }
  3490. let frames = this.frames;
  3491. if (time < frames[0]) {
  3492. if (blend == 0 /* setup */ || blend == 1 /* first */)
  3493. slot.sequenceIndex = -1;
  3494. return;
  3495. }
  3496. let i = Timeline.search(frames, time, _SequenceTimeline.ENTRIES);
  3497. let before = frames[i];
  3498. let modeAndIndex = frames[i + _SequenceTimeline.MODE];
  3499. let delay = frames[i + _SequenceTimeline.DELAY];
  3500. if (!this.attachment.sequence)
  3501. return;
  3502. let index = modeAndIndex >> 4, count = this.attachment.sequence.regions.length;
  3503. let mode = SequenceModeValues[modeAndIndex & 15];
  3504. if (mode != 0 /* hold */) {
  3505. index += (time - before) / delay + 1e-5 | 0;
  3506. switch (mode) {
  3507. case 1 /* once */:
  3508. index = Math.min(count - 1, index);
  3509. break;
  3510. case 2 /* loop */:
  3511. index %= count;
  3512. break;
  3513. case 3 /* pingpong */: {
  3514. let n = (count << 1) - 2;
  3515. index = n == 0 ? 0 : index % n;
  3516. if (index >= count)
  3517. index = n - index;
  3518. break;
  3519. }
  3520. case 4 /* onceReverse */:
  3521. index = Math.max(count - 1 - index, 0);
  3522. break;
  3523. case 5 /* loopReverse */:
  3524. index = count - 1 - index % count;
  3525. break;
  3526. case 6 /* pingpongReverse */: {
  3527. let n = (count << 1) - 2;
  3528. index = n == 0 ? 0 : (index + count - 1) % n;
  3529. if (index >= count)
  3530. index = n - index;
  3531. }
  3532. }
  3533. }
  3534. slot.sequenceIndex = index;
  3535. }
  3536. };
  3537. var SequenceTimeline = _SequenceTimeline;
  3538. SequenceTimeline.ENTRIES = 3;
  3539. SequenceTimeline.MODE = 1;
  3540. SequenceTimeline.DELAY = 2;
  3541. // spine-core/src/AnimationState.ts
  3542. var _AnimationState = class {
  3543. constructor(data) {
  3544. /** The list of tracks that currently have animations, which may contain null entries. */
  3545. this.tracks = new Array();
  3546. /** Multiplier for the delta time when the animation state is updated, causing time for all animations and mixes to play slower
  3547. * or faster. Defaults to 1.
  3548. *
  3549. * See TrackEntry {@link TrackEntry#timeScale} for affecting a single animation. */
  3550. this.timeScale = 1;
  3551. this.unkeyedState = 0;
  3552. this.events = new Array();
  3553. this.listeners = new Array();
  3554. this.queue = new EventQueue(this);
  3555. this.propertyIDs = new StringSet();
  3556. this.animationsChanged = false;
  3557. this.trackEntryPool = new Pool(() => new TrackEntry());
  3558. this.data = data;
  3559. }
  3560. static emptyAnimation() {
  3561. return _AnimationState._emptyAnimation;
  3562. }
  3563. /** Increments each track entry {@link TrackEntry#trackTime()}, setting queued animations as current if needed. */
  3564. update(delta) {
  3565. delta *= this.timeScale;
  3566. let tracks = this.tracks;
  3567. for (let i = 0, n = tracks.length; i < n; i++) {
  3568. let current = tracks[i];
  3569. if (!current)
  3570. continue;
  3571. current.animationLast = current.nextAnimationLast;
  3572. current.trackLast = current.nextTrackLast;
  3573. let currentDelta = delta * current.timeScale;
  3574. if (current.delay > 0) {
  3575. current.delay -= currentDelta;
  3576. if (current.delay > 0)
  3577. continue;
  3578. currentDelta = -current.delay;
  3579. current.delay = 0;
  3580. }
  3581. let next = current.next;
  3582. if (next) {
  3583. let nextTime = current.trackLast - next.delay;
  3584. if (nextTime >= 0) {
  3585. next.delay = 0;
  3586. next.trackTime += current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale;
  3587. current.trackTime += currentDelta;
  3588. this.setCurrent(i, next, true);
  3589. while (next.mixingFrom) {
  3590. next.mixTime += delta;
  3591. next = next.mixingFrom;
  3592. }
  3593. continue;
  3594. }
  3595. } else if (current.trackLast >= current.trackEnd && !current.mixingFrom) {
  3596. tracks[i] = null;
  3597. this.queue.end(current);
  3598. this.clearNext(current);
  3599. continue;
  3600. }
  3601. if (current.mixingFrom && this.updateMixingFrom(current, delta)) {
  3602. let from = current.mixingFrom;
  3603. current.mixingFrom = null;
  3604. if (from)
  3605. from.mixingTo = null;
  3606. while (from) {
  3607. this.queue.end(from);
  3608. from = from.mixingFrom;
  3609. }
  3610. }
  3611. current.trackTime += currentDelta;
  3612. }
  3613. this.queue.drain();
  3614. }
  3615. /** Returns true when all mixing from entries are complete. */
  3616. updateMixingFrom(to, delta) {
  3617. let from = to.mixingFrom;
  3618. if (!from)
  3619. return true;
  3620. let finished = this.updateMixingFrom(from, delta);
  3621. from.animationLast = from.nextAnimationLast;
  3622. from.trackLast = from.nextTrackLast;
  3623. if (to.mixTime > 0 && to.mixTime >= to.mixDuration) {
  3624. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  3625. to.mixingFrom = from.mixingFrom;
  3626. if (from.mixingFrom)
  3627. from.mixingFrom.mixingTo = to;
  3628. to.interruptAlpha = from.interruptAlpha;
  3629. this.queue.end(from);
  3630. }
  3631. return finished;
  3632. }
  3633. from.trackTime += delta * from.timeScale;
  3634. to.mixTime += delta;
  3635. return false;
  3636. }
  3637. /** Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the
  3638. * animation state can be applied to multiple skeletons to pose them identically.
  3639. * @returns True if any animations were applied. */
  3640. apply(skeleton) {
  3641. if (!skeleton)
  3642. throw new Error("skeleton cannot be null.");
  3643. if (this.animationsChanged)
  3644. this._animationsChanged();
  3645. let events = this.events;
  3646. let tracks = this.tracks;
  3647. let applied = false;
  3648. for (let i2 = 0, n2 = tracks.length; i2 < n2; i2++) {
  3649. let current = tracks[i2];
  3650. if (!current || current.delay > 0)
  3651. continue;
  3652. applied = true;
  3653. let blend = i2 == 0 ? 1 /* first */ : current.mixBlend;
  3654. let mix = current.alpha;
  3655. if (current.mixingFrom)
  3656. mix *= this.applyMixingFrom(current, skeleton, blend);
  3657. else if (current.trackTime >= current.trackEnd && !current.next)
  3658. mix = 0;
  3659. let animationLast = current.animationLast, animationTime = current.getAnimationTime(), applyTime = animationTime;
  3660. let applyEvents = events;
  3661. if (current.reverse) {
  3662. applyTime = current.animation.duration - applyTime;
  3663. applyEvents = null;
  3664. }
  3665. let timelines = current.animation.timelines;
  3666. let timelineCount = timelines.length;
  3667. if (i2 == 0 && mix == 1 || blend == 3 /* add */) {
  3668. for (let ii = 0; ii < timelineCount; ii++) {
  3669. Utils.webkit602BugfixHelper(mix, blend);
  3670. var timeline = timelines[ii];
  3671. if (timeline instanceof AttachmentTimeline)
  3672. this.applyAttachmentTimeline(timeline, skeleton, applyTime, blend, true);
  3673. else
  3674. timeline.apply(skeleton, animationLast, applyTime, applyEvents, mix, blend, 0 /* mixIn */);
  3675. }
  3676. } else {
  3677. let timelineMode = current.timelineMode;
  3678. let shortestRotation = current.shortestRotation;
  3679. let firstFrame = !shortestRotation && current.timelinesRotation.length != timelineCount << 1;
  3680. if (firstFrame)
  3681. current.timelinesRotation.length = timelineCount << 1;
  3682. for (let ii = 0; ii < timelineCount; ii++) {
  3683. let timeline2 = timelines[ii];
  3684. let timelineBlend = timelineMode[ii] == SUBSEQUENT ? blend : 0 /* setup */;
  3685. if (!shortestRotation && timeline2 instanceof RotateTimeline) {
  3686. this.applyRotateTimeline(timeline2, skeleton, applyTime, mix, timelineBlend, current.timelinesRotation, ii << 1, firstFrame);
  3687. } else if (timeline2 instanceof AttachmentTimeline) {
  3688. this.applyAttachmentTimeline(timeline2, skeleton, applyTime, blend, true);
  3689. } else {
  3690. Utils.webkit602BugfixHelper(mix, blend);
  3691. timeline2.apply(skeleton, animationLast, applyTime, applyEvents, mix, timelineBlend, 0 /* mixIn */);
  3692. }
  3693. }
  3694. }
  3695. this.queueEvents(current, animationTime);
  3696. events.length = 0;
  3697. current.nextAnimationLast = animationTime;
  3698. current.nextTrackLast = current.trackTime;
  3699. }
  3700. var setupState = this.unkeyedState + SETUP;
  3701. var slots = skeleton.slots;
  3702. for (var i = 0, n = skeleton.slots.length; i < n; i++) {
  3703. var slot = slots[i];
  3704. if (slot.attachmentState == setupState) {
  3705. var attachmentName = slot.data.attachmentName;
  3706. slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  3707. }
  3708. }
  3709. this.unkeyedState += 2;
  3710. this.queue.drain();
  3711. return applied;
  3712. }
  3713. applyMixingFrom(to, skeleton, blend) {
  3714. let from = to.mixingFrom;
  3715. if (from.mixingFrom)
  3716. this.applyMixingFrom(from, skeleton, blend);
  3717. let mix = 0;
  3718. if (to.mixDuration == 0) {
  3719. mix = 1;
  3720. if (blend == 1 /* first */)
  3721. blend = 0 /* setup */;
  3722. } else {
  3723. mix = to.mixTime / to.mixDuration;
  3724. if (mix > 1)
  3725. mix = 1;
  3726. if (blend != 1 /* first */)
  3727. blend = from.mixBlend;
  3728. }
  3729. let attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  3730. let timelines = from.animation.timelines;
  3731. let timelineCount = timelines.length;
  3732. let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
  3733. let animationLast = from.animationLast, animationTime = from.getAnimationTime(), applyTime = animationTime;
  3734. let events = null;
  3735. if (from.reverse)
  3736. applyTime = from.animation.duration - applyTime;
  3737. else if (mix < from.eventThreshold)
  3738. events = this.events;
  3739. if (blend == 3 /* add */) {
  3740. for (let i = 0; i < timelineCount; i++)
  3741. timelines[i].apply(skeleton, animationLast, applyTime, events, alphaMix, blend, 1 /* mixOut */);
  3742. } else {
  3743. let timelineMode = from.timelineMode;
  3744. let timelineHoldMix = from.timelineHoldMix;
  3745. let shortestRotation = from.shortestRotation;
  3746. let firstFrame = !shortestRotation && from.timelinesRotation.length != timelineCount << 1;
  3747. if (firstFrame)
  3748. from.timelinesRotation.length = timelineCount << 1;
  3749. from.totalAlpha = 0;
  3750. for (let i = 0; i < timelineCount; i++) {
  3751. let timeline = timelines[i];
  3752. let direction = 1 /* mixOut */;
  3753. let timelineBlend;
  3754. let alpha = 0;
  3755. switch (timelineMode[i]) {
  3756. case SUBSEQUENT:
  3757. if (!drawOrder && timeline instanceof DrawOrderTimeline)
  3758. continue;
  3759. timelineBlend = blend;
  3760. alpha = alphaMix;
  3761. break;
  3762. case FIRST:
  3763. timelineBlend = 0 /* setup */;
  3764. alpha = alphaMix;
  3765. break;
  3766. case HOLD_SUBSEQUENT:
  3767. timelineBlend = blend;
  3768. alpha = alphaHold;
  3769. break;
  3770. case HOLD_FIRST:
  3771. timelineBlend = 0 /* setup */;
  3772. alpha = alphaHold;
  3773. break;
  3774. default:
  3775. timelineBlend = 0 /* setup */;
  3776. let holdMix = timelineHoldMix[i];
  3777. alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
  3778. break;
  3779. }
  3780. from.totalAlpha += alpha;
  3781. if (!shortestRotation && timeline instanceof RotateTimeline)
  3782. this.applyRotateTimeline(timeline, skeleton, applyTime, alpha, timelineBlend, from.timelinesRotation, i << 1, firstFrame);
  3783. else if (timeline instanceof AttachmentTimeline)
  3784. this.applyAttachmentTimeline(timeline, skeleton, applyTime, timelineBlend, attachments);
  3785. else {
  3786. Utils.webkit602BugfixHelper(alpha, blend);
  3787. if (drawOrder && timeline instanceof DrawOrderTimeline && timelineBlend == 0 /* setup */)
  3788. direction = 0 /* mixIn */;
  3789. timeline.apply(skeleton, animationLast, applyTime, events, alpha, timelineBlend, direction);
  3790. }
  3791. }
  3792. }
  3793. if (to.mixDuration > 0)
  3794. this.queueEvents(from, animationTime);
  3795. this.events.length = 0;
  3796. from.nextAnimationLast = animationTime;
  3797. from.nextTrackLast = from.trackTime;
  3798. return mix;
  3799. }
  3800. applyAttachmentTimeline(timeline, skeleton, time, blend, attachments) {
  3801. var slot = skeleton.slots[timeline.slotIndex];
  3802. if (!slot.bone.active)
  3803. return;
  3804. if (time < timeline.frames[0]) {
  3805. if (blend == 0 /* setup */ || blend == 1 /* first */)
  3806. this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments);
  3807. } else
  3808. this.setAttachment(skeleton, slot, timeline.attachmentNames[Timeline.search1(timeline.frames, time)], attachments);
  3809. if (slot.attachmentState <= this.unkeyedState)
  3810. slot.attachmentState = this.unkeyedState + SETUP;
  3811. }
  3812. setAttachment(skeleton, slot, attachmentName, attachments) {
  3813. slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  3814. if (attachments)
  3815. slot.attachmentState = this.unkeyedState + CURRENT;
  3816. }
  3817. applyRotateTimeline(timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame) {
  3818. if (firstFrame)
  3819. timelinesRotation[i] = 0;
  3820. if (alpha == 1) {
  3821. timeline.apply(skeleton, 0, time, null, 1, blend, 0 /* mixIn */);
  3822. return;
  3823. }
  3824. let bone = skeleton.bones[timeline.boneIndex];
  3825. if (!bone.active)
  3826. return;
  3827. let frames = timeline.frames;
  3828. let r1 = 0, r2 = 0;
  3829. if (time < frames[0]) {
  3830. switch (blend) {
  3831. case 0 /* setup */:
  3832. bone.rotation = bone.data.rotation;
  3833. default:
  3834. return;
  3835. case 1 /* first */:
  3836. r1 = bone.rotation;
  3837. r2 = bone.data.rotation;
  3838. }
  3839. } else {
  3840. r1 = blend == 0 /* setup */ ? bone.data.rotation : bone.rotation;
  3841. r2 = bone.data.rotation + timeline.getCurveValue(time);
  3842. }
  3843. let total = 0, diff = r2 - r1;
  3844. diff -= (16384 - (16384.499999999996 - diff / 360 | 0)) * 360;
  3845. if (diff == 0) {
  3846. total = timelinesRotation[i];
  3847. } else {
  3848. let lastTotal = 0, lastDiff = 0;
  3849. if (firstFrame) {
  3850. lastTotal = 0;
  3851. lastDiff = diff;
  3852. } else {
  3853. lastTotal = timelinesRotation[i];
  3854. lastDiff = timelinesRotation[i + 1];
  3855. }
  3856. let current = diff > 0, dir = lastTotal >= 0;
  3857. if (MathUtils.signum(lastDiff) != MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  3858. if (Math.abs(lastTotal) > 180)
  3859. lastTotal += 360 * MathUtils.signum(lastTotal);
  3860. dir = current;
  3861. }
  3862. total = diff + lastTotal - lastTotal % 360;
  3863. if (dir != current)
  3864. total += 360 * MathUtils.signum(lastTotal);
  3865. timelinesRotation[i] = total;
  3866. }
  3867. timelinesRotation[i + 1] = diff;
  3868. bone.rotation = r1 + total * alpha;
  3869. }
  3870. queueEvents(entry, animationTime) {
  3871. let animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  3872. let duration = animationEnd - animationStart;
  3873. let trackLastWrapped = entry.trackLast % duration;
  3874. let events = this.events;
  3875. let i = 0, n = events.length;
  3876. for (; i < n; i++) {
  3877. let event = events[i];
  3878. if (event.time < trackLastWrapped)
  3879. break;
  3880. if (event.time > animationEnd)
  3881. continue;
  3882. this.queue.event(entry, event);
  3883. }
  3884. let complete = false;
  3885. if (entry.loop)
  3886. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  3887. else
  3888. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  3889. if (complete)
  3890. this.queue.complete(entry);
  3891. for (; i < n; i++) {
  3892. let event = events[i];
  3893. if (event.time < animationStart)
  3894. continue;
  3895. this.queue.event(entry, event);
  3896. }
  3897. }
  3898. /** Removes all animations from all tracks, leaving skeletons in their current pose.
  3899. *
  3900. * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose,
  3901. * rather than leaving them in their current pose. */
  3902. clearTracks() {
  3903. let oldDrainDisabled = this.queue.drainDisabled;
  3904. this.queue.drainDisabled = true;
  3905. for (let i = 0, n = this.tracks.length; i < n; i++)
  3906. this.clearTrack(i);
  3907. this.tracks.length = 0;
  3908. this.queue.drainDisabled = oldDrainDisabled;
  3909. this.queue.drain();
  3910. }
  3911. /** Removes all animations from the track, leaving skeletons in their current pose.
  3912. *
  3913. * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose,
  3914. * rather than leaving them in their current pose. */
  3915. clearTrack(trackIndex) {
  3916. if (trackIndex >= this.tracks.length)
  3917. return;
  3918. let current = this.tracks[trackIndex];
  3919. if (!current)
  3920. return;
  3921. this.queue.end(current);
  3922. this.clearNext(current);
  3923. let entry = current;
  3924. while (true) {
  3925. let from = entry.mixingFrom;
  3926. if (!from)
  3927. break;
  3928. this.queue.end(from);
  3929. entry.mixingFrom = null;
  3930. entry.mixingTo = null;
  3931. entry = from;
  3932. }
  3933. this.tracks[current.trackIndex] = null;
  3934. this.queue.drain();
  3935. }
  3936. setCurrent(index, current, interrupt) {
  3937. let from = this.expandToIndex(index);
  3938. this.tracks[index] = current;
  3939. current.previous = null;
  3940. if (from) {
  3941. if (interrupt)
  3942. this.queue.interrupt(from);
  3943. current.mixingFrom = from;
  3944. from.mixingTo = current;
  3945. current.mixTime = 0;
  3946. if (from.mixingFrom && from.mixDuration > 0)
  3947. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  3948. from.timelinesRotation.length = 0;
  3949. }
  3950. this.queue.start(current);
  3951. }
  3952. /** Sets an animation by name.
  3953. *
  3954. * See {@link #setAnimationWith()}. */
  3955. setAnimation(trackIndex, animationName, loop = false) {
  3956. let animation = this.data.skeletonData.findAnimation(animationName);
  3957. if (!animation)
  3958. throw new Error("Animation not found: " + animationName);
  3959. return this.setAnimationWith(trackIndex, animation, loop);
  3960. }
  3961. /** Sets the current animation for a track, discarding any queued animations. If the formerly current track entry was never
  3962. * applied to a skeleton, it is replaced (not mixed from).
  3963. * @param loop If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
  3964. * duration. In either case {@link TrackEntry#trackEnd} determines when the track is cleared.
  3965. * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept
  3966. * after the {@link AnimationStateListener#dispose()} event occurs. */
  3967. setAnimationWith(trackIndex, animation, loop = false) {
  3968. if (!animation)
  3969. throw new Error("animation cannot be null.");
  3970. let interrupt = true;
  3971. let current = this.expandToIndex(trackIndex);
  3972. if (current) {
  3973. if (current.nextTrackLast == -1) {
  3974. this.tracks[trackIndex] = current.mixingFrom;
  3975. this.queue.interrupt(current);
  3976. this.queue.end(current);
  3977. this.clearNext(current);
  3978. current = current.mixingFrom;
  3979. interrupt = false;
  3980. } else
  3981. this.clearNext(current);
  3982. }
  3983. let entry = this.trackEntry(trackIndex, animation, loop, current);
  3984. this.setCurrent(trackIndex, entry, interrupt);
  3985. this.queue.drain();
  3986. return entry;
  3987. }
  3988. /** Queues an animation by name.
  3989. *
  3990. * See {@link #addAnimationWith()}. */
  3991. addAnimation(trackIndex, animationName, loop = false, delay = 0) {
  3992. let animation = this.data.skeletonData.findAnimation(animationName);
  3993. if (!animation)
  3994. throw new Error("Animation not found: " + animationName);
  3995. return this.addAnimationWith(trackIndex, animation, loop, delay);
  3996. }
  3997. /** Adds an animation to be played after the current or last queued animation for a track. If the track is empty, it is
  3998. * equivalent to calling {@link #setAnimationWith()}.
  3999. * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry
  4000. * minus any mix duration (from the {@link AnimationStateData}) plus the specified `delay` (ie the mix
  4001. * ends at (`delay` = 0) or before (`delay` < 0) the previous track entry duration). If the
  4002. * previous entry is looping, its next loop completion is used instead of its duration.
  4003. * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept
  4004. * after the {@link AnimationStateListener#dispose()} event occurs. */
  4005. addAnimationWith(trackIndex, animation, loop = false, delay = 0) {
  4006. if (!animation)
  4007. throw new Error("animation cannot be null.");
  4008. let last = this.expandToIndex(trackIndex);
  4009. if (last) {
  4010. while (last.next)
  4011. last = last.next;
  4012. }
  4013. let entry = this.trackEntry(trackIndex, animation, loop, last);
  4014. if (!last) {
  4015. this.setCurrent(trackIndex, entry, true);
  4016. this.queue.drain();
  4017. } else {
  4018. last.next = entry;
  4019. entry.previous = last;
  4020. if (delay <= 0)
  4021. delay += last.getTrackComplete() - entry.mixDuration;
  4022. }
  4023. entry.delay = delay;
  4024. return entry;
  4025. }
  4026. /** Sets an empty animation for a track, discarding any queued animations, and sets the track entry's
  4027. * {@link TrackEntry#mixduration}. An empty animation has no timelines and serves as a placeholder for mixing in or out.
  4028. *
  4029. * Mixing out is done by setting an empty animation with a mix duration using either {@link #setEmptyAnimation()},
  4030. * {@link #setEmptyAnimations()}, or {@link #addEmptyAnimation()}. Mixing to an empty animation causes
  4031. * the previous animation to be applied less and less over the mix duration. Properties keyed in the previous animation
  4032. * transition to the value from lower tracks or to the setup pose value if no lower tracks key the property. A mix duration of
  4033. * 0 still mixes out over one frame.
  4034. *
  4035. * Mixing in is done by first setting an empty animation, then adding an animation using
  4036. * {@link #addAnimation()} and on the returned track entry, set the
  4037. * {@link TrackEntry#setMixDuration()}. Mixing from an empty animation causes the new animation to be applied more and
  4038. * more over the mix duration. Properties keyed in the new animation transition from the value from lower tracks or from the
  4039. * setup pose value if no lower tracks key the property to the value keyed in the new animation. */
  4040. setEmptyAnimation(trackIndex, mixDuration = 0) {
  4041. let entry = this.setAnimationWith(trackIndex, _AnimationState.emptyAnimation(), false);
  4042. entry.mixDuration = mixDuration;
  4043. entry.trackEnd = mixDuration;
  4044. return entry;
  4045. }
  4046. /** Adds an empty animation to be played after the current or last queued animation for a track, and sets the track entry's
  4047. * {@link TrackEntry#mixDuration}. If the track is empty, it is equivalent to calling
  4048. * {@link #setEmptyAnimation()}.
  4049. *
  4050. * See {@link #setEmptyAnimation()}.
  4051. * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry
  4052. * minus any mix duration plus the specified `delay` (ie the mix ends at (`delay` = 0) or
  4053. * before (`delay` < 0) the previous track entry duration). If the previous entry is looping, its next
  4054. * loop completion is used instead of its duration.
  4055. * @return A track entry to allow further customization of animation playback. References to the track entry must not be kept
  4056. * after the {@link AnimationStateListener#dispose()} event occurs. */
  4057. addEmptyAnimation(trackIndex, mixDuration = 0, delay = 0) {
  4058. let entry = this.addAnimationWith(trackIndex, _AnimationState.emptyAnimation(), false, delay);
  4059. if (delay <= 0)
  4060. entry.delay += entry.mixDuration - mixDuration;
  4061. entry.mixDuration = mixDuration;
  4062. entry.trackEnd = mixDuration;
  4063. return entry;
  4064. }
  4065. /** Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix
  4066. * duration. */
  4067. setEmptyAnimations(mixDuration = 0) {
  4068. let oldDrainDisabled = this.queue.drainDisabled;
  4069. this.queue.drainDisabled = true;
  4070. for (let i = 0, n = this.tracks.length; i < n; i++) {
  4071. let current = this.tracks[i];
  4072. if (current)
  4073. this.setEmptyAnimation(current.trackIndex, mixDuration);
  4074. }
  4075. this.queue.drainDisabled = oldDrainDisabled;
  4076. this.queue.drain();
  4077. }
  4078. expandToIndex(index) {
  4079. if (index < this.tracks.length)
  4080. return this.tracks[index];
  4081. Utils.ensureArrayCapacity(this.tracks, index + 1, null);
  4082. this.tracks.length = index + 1;
  4083. return null;
  4084. }
  4085. /** @param last May be null. */
  4086. trackEntry(trackIndex, animation, loop, last) {
  4087. let entry = this.trackEntryPool.obtain();
  4088. entry.reset();
  4089. entry.trackIndex = trackIndex;
  4090. entry.animation = animation;
  4091. entry.loop = loop;
  4092. entry.holdPrevious = false;
  4093. entry.reverse = false;
  4094. entry.shortestRotation = false;
  4095. entry.eventThreshold = 0;
  4096. entry.attachmentThreshold = 0;
  4097. entry.drawOrderThreshold = 0;
  4098. entry.animationStart = 0;
  4099. entry.animationEnd = animation.duration;
  4100. entry.animationLast = -1;
  4101. entry.nextAnimationLast = -1;
  4102. entry.delay = 0;
  4103. entry.trackTime = 0;
  4104. entry.trackLast = -1;
  4105. entry.nextTrackLast = -1;
  4106. entry.trackEnd = Number.MAX_VALUE;
  4107. entry.timeScale = 1;
  4108. entry.alpha = 1;
  4109. entry.mixTime = 0;
  4110. entry.mixDuration = !last ? 0 : this.data.getMix(last.animation, animation);
  4111. entry.interruptAlpha = 1;
  4112. entry.totalAlpha = 0;
  4113. entry.mixBlend = 2 /* replace */;
  4114. return entry;
  4115. }
  4116. /** Removes the {@link TrackEntry#getNext() next entry} and all entries after it for the specified entry. */
  4117. clearNext(entry) {
  4118. let next = entry.next;
  4119. while (next) {
  4120. this.queue.dispose(next);
  4121. next = next.next;
  4122. }
  4123. entry.next = null;
  4124. }
  4125. _animationsChanged() {
  4126. this.animationsChanged = false;
  4127. this.propertyIDs.clear();
  4128. let tracks = this.tracks;
  4129. for (let i = 0, n = tracks.length; i < n; i++) {
  4130. let entry = tracks[i];
  4131. if (!entry)
  4132. continue;
  4133. while (entry.mixingFrom)
  4134. entry = entry.mixingFrom;
  4135. do {
  4136. if (!entry.mixingTo || entry.mixBlend != 3 /* add */)
  4137. this.computeHold(entry);
  4138. entry = entry.mixingTo;
  4139. } while (entry);
  4140. }
  4141. }
  4142. computeHold(entry) {
  4143. let to = entry.mixingTo;
  4144. let timelines = entry.animation.timelines;
  4145. let timelinesCount = entry.animation.timelines.length;
  4146. let timelineMode = entry.timelineMode;
  4147. timelineMode.length = timelinesCount;
  4148. let timelineHoldMix = entry.timelineHoldMix;
  4149. timelineHoldMix.length = 0;
  4150. let propertyIDs = this.propertyIDs;
  4151. if (to && to.holdPrevious) {
  4152. for (let i = 0; i < timelinesCount; i++)
  4153. timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? HOLD_FIRST : HOLD_SUBSEQUENT;
  4154. return;
  4155. }
  4156. outer:
  4157. for (let i = 0; i < timelinesCount; i++) {
  4158. let timeline = timelines[i];
  4159. let ids = timeline.getPropertyIds();
  4160. if (!propertyIDs.addAll(ids))
  4161. timelineMode[i] = SUBSEQUENT;
  4162. else if (!to || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline || timeline instanceof EventTimeline || !to.animation.hasTimeline(ids)) {
  4163. timelineMode[i] = FIRST;
  4164. } else {
  4165. for (let next = to.mixingTo; next; next = next.mixingTo) {
  4166. if (next.animation.hasTimeline(ids))
  4167. continue;
  4168. if (entry.mixDuration > 0) {
  4169. timelineMode[i] = HOLD_MIX;
  4170. timelineHoldMix[i] = next;
  4171. continue outer;
  4172. }
  4173. break;
  4174. }
  4175. timelineMode[i] = HOLD_FIRST;
  4176. }
  4177. }
  4178. }
  4179. /** Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing. */
  4180. getCurrent(trackIndex) {
  4181. if (trackIndex >= this.tracks.length)
  4182. return null;
  4183. return this.tracks[trackIndex];
  4184. }
  4185. /** Adds a listener to receive events for all track entries. */
  4186. addListener(listener) {
  4187. if (!listener)
  4188. throw new Error("listener cannot be null.");
  4189. this.listeners.push(listener);
  4190. }
  4191. /** Removes the listener added with {@link #addListener()}. */
  4192. removeListener(listener) {
  4193. let index = this.listeners.indexOf(listener);
  4194. if (index >= 0)
  4195. this.listeners.splice(index, 1);
  4196. }
  4197. /** Removes all listeners added with {@link #addListener()}. */
  4198. clearListeners() {
  4199. this.listeners.length = 0;
  4200. }
  4201. /** Discards all listener notifications that have not yet been delivered. This can be useful to call from an
  4202. * {@link AnimationStateListener} when it is known that further notifications that may have been already queued for delivery
  4203. * are not wanted because new animations are being set. */
  4204. clearListenerNotifications() {
  4205. this.queue.clear();
  4206. }
  4207. };
  4208. var AnimationState = _AnimationState;
  4209. AnimationState._emptyAnimation = new Animation("<empty>", [], 0);
  4210. var TrackEntry = class {
  4211. constructor() {
  4212. /** The animation to apply for this track entry. */
  4213. this.animation = null;
  4214. this.previous = null;
  4215. /** The animation queued to start after this animation, or null. `next` makes up a linked list. */
  4216. this.next = null;
  4217. /** The track entry for the previous animation when mixing from the previous animation to this animation, or null if no
  4218. * mixing is currently occuring. When mixing from multiple animations, `mixingFrom` makes up a linked list. */
  4219. this.mixingFrom = null;
  4220. /** The track entry for the next animation when mixing from this animation to the next animation, or null if no mixing is
  4221. * currently occuring. When mixing to multiple animations, `mixingTo` makes up a linked list. */
  4222. this.mixingTo = null;
  4223. /** The listener for events generated by this track entry, or null.
  4224. *
  4225. * A track entry returned from {@link AnimationState#setAnimation()} is already the current animation
  4226. * for the track, so the track entry listener {@link AnimationStateListener#start()} will not be called. */
  4227. this.listener = null;
  4228. /** The index of the track where this track entry is either current or queued.
  4229. *
  4230. * See {@link AnimationState#getCurrent()}. */
  4231. this.trackIndex = 0;
  4232. /** If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
  4233. * duration. */
  4234. this.loop = false;
  4235. /** If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead
  4236. * of being mixed out.
  4237. *
  4238. * When mixing between animations that key the same property, if a lower track also keys that property then the value will
  4239. * briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0%
  4240. * while the second animation mixes from 0% to 100%. Setting `holdPrevious` to true applies the first animation
  4241. * at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which
  4242. * keys the property, only when a higher track also keys the property.
  4243. *
  4244. * Snapping will occur if `holdPrevious` is true and this animation does not key all the same properties as the
  4245. * previous animation. */
  4246. this.holdPrevious = false;
  4247. this.reverse = false;
  4248. this.shortestRotation = false;
  4249. /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the
  4250. * `eventThreshold`, event timelines are applied while this animation is being mixed out. Defaults to 0, so event
  4251. * timelines are not applied while this animation is being mixed out. */
  4252. this.eventThreshold = 0;
  4253. /** When the mix percentage ({@link #mixtime} / {@link #mixDuration}) is less than the
  4254. * `attachmentThreshold`, attachment timelines are applied while this animation is being mixed out. Defaults to
  4255. * 0, so attachment timelines are not applied while this animation is being mixed out. */
  4256. this.attachmentThreshold = 0;
  4257. /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the
  4258. * `drawOrderThreshold`, draw order timelines are applied while this animation is being mixed out. Defaults to 0,
  4259. * so draw order timelines are not applied while this animation is being mixed out. */
  4260. this.drawOrderThreshold = 0;
  4261. /** Seconds when this animation starts, both initially and after looping. Defaults to 0.
  4262. *
  4263. * When changing the `animationStart` time, it often makes sense to set {@link #animationLast} to the same
  4264. * value to prevent timeline keys before the start time from triggering. */
  4265. this.animationStart = 0;
  4266. /** Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will
  4267. * loop back to {@link #animationStart} at this time. Defaults to the animation {@link Animation#duration}. */
  4268. this.animationEnd = 0;
  4269. /** The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this
  4270. * animation is applied, event timelines will fire all events between the `animationLast` time (exclusive) and
  4271. * `animationTime` (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation
  4272. * is applied. */
  4273. this.animationLast = 0;
  4274. this.nextAnimationLast = 0;
  4275. /** Seconds to postpone playing the animation. When this track entry is the current track entry, `delay`
  4276. * postpones incrementing the {@link #trackTime}. When this track entry is queued, `delay` is the time from
  4277. * the start of the previous animation to when this track entry will become the current track entry (ie when the previous
  4278. * track entry {@link TrackEntry#trackTime} >= this track entry's `delay`).
  4279. *
  4280. * {@link #timeScale} affects the delay. */
  4281. this.delay = 0;
  4282. /** Current time in seconds this track entry has been the current track entry. The track time determines
  4283. * {@link #animationTime}. The track time can be set to start the animation at a time other than 0, without affecting
  4284. * looping. */
  4285. this.trackTime = 0;
  4286. this.trackLast = 0;
  4287. this.nextTrackLast = 0;
  4288. /** The track time in seconds when this animation will be removed from the track. Defaults to the highest possible float
  4289. * value, meaning the animation will be applied until a new animation is set or the track is cleared. If the track end time
  4290. * is reached, no other animations are queued for playback, and mixing from any previous animations is complete, then the
  4291. * properties keyed by the animation are set to the setup pose and the track is cleared.
  4292. *
  4293. * It may be desired to use {@link AnimationState#addEmptyAnimation()} rather than have the animation
  4294. * abruptly cease being applied. */
  4295. this.trackEnd = 0;
  4296. /** Multiplier for the delta time when this track entry is updated, causing time for this animation to pass slower or
  4297. * faster. Defaults to 1.
  4298. *
  4299. * {@link #mixTime} is not affected by track entry time scale, so {@link #mixDuration} may need to be adjusted to
  4300. * match the animation speed.
  4301. *
  4302. * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the
  4303. * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, assuming time scale to be 1. If
  4304. * the time scale is not 1, the delay may need to be adjusted.
  4305. *
  4306. * See AnimationState {@link AnimationState#timeScale} for affecting all animations. */
  4307. this.timeScale = 0;
  4308. /** Values < 1 mix this animation with the skeleton's current pose (usually the pose resulting from lower tracks). Defaults
  4309. * to 1, which overwrites the skeleton's current pose with this animation.
  4310. *
  4311. * Typically track 0 is used to completely pose the skeleton, then alpha is used on higher tracks. It doesn't make sense to
  4312. * use alpha on track 0 if the skeleton pose is from the last frame render. */
  4313. this.alpha = 0;
  4314. /** Seconds from 0 to the {@link #getMixDuration()} when mixing from the previous animation to this animation. May be
  4315. * slightly more than `mixDuration` when the mix is complete. */
  4316. this.mixTime = 0;
  4317. /** Seconds for mixing from the previous animation to this animation. Defaults to the value provided by AnimationStateData
  4318. * {@link AnimationStateData#getMix()} based on the animation before this animation (if any).
  4319. *
  4320. * A mix duration of 0 still mixes out over one frame to provide the track entry being mixed out a chance to revert the
  4321. * properties it was animating.
  4322. *
  4323. * The `mixDuration` can be set manually rather than use the value from
  4324. * {@link AnimationStateData#getMix()}. In that case, the `mixDuration` can be set for a new
  4325. * track entry only before {@link AnimationState#update(float)} is first called.
  4326. *
  4327. * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the
  4328. * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, not a mix duration set
  4329. * afterward. */
  4330. this.mixDuration = 0;
  4331. this.interruptAlpha = 0;
  4332. this.totalAlpha = 0;
  4333. /** Controls how properties keyed in the animation are mixed with lower tracks. Defaults to {@link MixBlend#replace}, which
  4334. * replaces the values from the lower tracks with the animation values. {@link MixBlend#add} adds the animation values to
  4335. * the values from the lower tracks.
  4336. *
  4337. * The `mixBlend` can be set for a new track entry only before {@link AnimationState#apply()} is first
  4338. * called. */
  4339. this.mixBlend = 2 /* replace */;
  4340. this.timelineMode = new Array();
  4341. this.timelineHoldMix = new Array();
  4342. this.timelinesRotation = new Array();
  4343. }
  4344. reset() {
  4345. this.next = null;
  4346. this.previous = null;
  4347. this.mixingFrom = null;
  4348. this.mixingTo = null;
  4349. this.animation = null;
  4350. this.listener = null;
  4351. this.timelineMode.length = 0;
  4352. this.timelineHoldMix.length = 0;
  4353. this.timelinesRotation.length = 0;
  4354. }
  4355. /** Uses {@link #trackTime} to compute the `animationTime`, which is between {@link #animationStart}
  4356. * and {@link #animationEnd}. When the `trackTime` is 0, the `animationTime` is equal to the
  4357. * `animationStart` time. */
  4358. getAnimationTime() {
  4359. if (this.loop) {
  4360. let duration = this.animationEnd - this.animationStart;
  4361. if (duration == 0)
  4362. return this.animationStart;
  4363. return this.trackTime % duration + this.animationStart;
  4364. }
  4365. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  4366. }
  4367. setAnimationLast(animationLast) {
  4368. this.animationLast = animationLast;
  4369. this.nextAnimationLast = animationLast;
  4370. }
  4371. /** Returns true if at least one loop has been completed.
  4372. *
  4373. * See {@link AnimationStateListener#complete()}. */
  4374. isComplete() {
  4375. return this.trackTime >= this.animationEnd - this.animationStart;
  4376. }
  4377. /** Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the
  4378. * long way around when using {@link #alpha} and starting animations on other tracks.
  4379. *
  4380. * Mixing with {@link MixBlend#replace} involves finding a rotation between two others, which has two possible solutions:
  4381. * the short way or the long way around. The two rotations likely change over time, so which direction is the short or long
  4382. * way also changes. If the short way was always chosen, bones would flip to the other side when that direction became the
  4383. * long way. TrackEntry chooses the short way the first time it is applied and remembers that direction. */
  4384. resetRotationDirections() {
  4385. this.timelinesRotation.length = 0;
  4386. }
  4387. getTrackComplete() {
  4388. let duration = this.animationEnd - this.animationStart;
  4389. if (duration != 0) {
  4390. if (this.loop)
  4391. return duration * (1 + (this.trackTime / duration | 0));
  4392. if (this.trackTime < duration)
  4393. return duration;
  4394. }
  4395. return this.trackTime;
  4396. }
  4397. };
  4398. var EventQueue = class {
  4399. constructor(animState) {
  4400. this.objects = [];
  4401. this.drainDisabled = false;
  4402. this.animState = animState;
  4403. }
  4404. start(entry) {
  4405. this.objects.push(EventType.start);
  4406. this.objects.push(entry);
  4407. this.animState.animationsChanged = true;
  4408. }
  4409. interrupt(entry) {
  4410. this.objects.push(EventType.interrupt);
  4411. this.objects.push(entry);
  4412. }
  4413. end(entry) {
  4414. this.objects.push(EventType.end);
  4415. this.objects.push(entry);
  4416. this.animState.animationsChanged = true;
  4417. }
  4418. dispose(entry) {
  4419. this.objects.push(EventType.dispose);
  4420. this.objects.push(entry);
  4421. }
  4422. complete(entry) {
  4423. this.objects.push(EventType.complete);
  4424. this.objects.push(entry);
  4425. }
  4426. event(entry, event) {
  4427. this.objects.push(EventType.event);
  4428. this.objects.push(entry);
  4429. this.objects.push(event);
  4430. }
  4431. drain() {
  4432. if (this.drainDisabled)
  4433. return;
  4434. this.drainDisabled = true;
  4435. let objects = this.objects;
  4436. let listeners = this.animState.listeners;
  4437. for (let i = 0; i < objects.length; i += 2) {
  4438. let type = objects[i];
  4439. let entry = objects[i + 1];
  4440. switch (type) {
  4441. case EventType.start:
  4442. if (entry.listener && entry.listener.start)
  4443. entry.listener.start(entry);
  4444. for (let ii = 0; ii < listeners.length; ii++) {
  4445. let listener = listeners[ii];
  4446. if (listener.start)
  4447. listener.start(entry);
  4448. }
  4449. break;
  4450. case EventType.interrupt:
  4451. if (entry.listener && entry.listener.interrupt)
  4452. entry.listener.interrupt(entry);
  4453. for (let ii = 0; ii < listeners.length; ii++) {
  4454. let listener = listeners[ii];
  4455. if (listener.interrupt)
  4456. listener.interrupt(entry);
  4457. }
  4458. break;
  4459. case EventType.end:
  4460. if (entry.listener && entry.listener.end)
  4461. entry.listener.end(entry);
  4462. for (let ii = 0; ii < listeners.length; ii++) {
  4463. let listener = listeners[ii];
  4464. if (listener.end)
  4465. listener.end(entry);
  4466. }
  4467. case EventType.dispose:
  4468. if (entry.listener && entry.listener.dispose)
  4469. entry.listener.dispose(entry);
  4470. for (let ii = 0; ii < listeners.length; ii++) {
  4471. let listener = listeners[ii];
  4472. if (listener.dispose)
  4473. listener.dispose(entry);
  4474. }
  4475. this.animState.trackEntryPool.free(entry);
  4476. break;
  4477. case EventType.complete:
  4478. if (entry.listener && entry.listener.complete)
  4479. entry.listener.complete(entry);
  4480. for (let ii = 0; ii < listeners.length; ii++) {
  4481. let listener = listeners[ii];
  4482. if (listener.complete)
  4483. listener.complete(entry);
  4484. }
  4485. break;
  4486. case EventType.event:
  4487. let event = objects[i++ + 2];
  4488. if (entry.listener && entry.listener.event)
  4489. entry.listener.event(entry, event);
  4490. for (let ii = 0; ii < listeners.length; ii++) {
  4491. let listener = listeners[ii];
  4492. if (listener.event)
  4493. listener.event(entry, event);
  4494. }
  4495. break;
  4496. }
  4497. }
  4498. this.clear();
  4499. this.drainDisabled = false;
  4500. }
  4501. clear() {
  4502. this.objects.length = 0;
  4503. }
  4504. };
  4505. var EventType = /* @__PURE__ */ ((EventType2) => {
  4506. EventType2[EventType2["start"] = 0] = "start";
  4507. EventType2[EventType2["interrupt"] = 1] = "interrupt";
  4508. EventType2[EventType2["end"] = 2] = "end";
  4509. EventType2[EventType2["dispose"] = 3] = "dispose";
  4510. EventType2[EventType2["complete"] = 4] = "complete";
  4511. EventType2[EventType2["event"] = 5] = "event";
  4512. return EventType2;
  4513. })(EventType || {});
  4514. var AnimationStateAdapter = class {
  4515. start(entry) {
  4516. }
  4517. interrupt(entry) {
  4518. }
  4519. end(entry) {
  4520. }
  4521. dispose(entry) {
  4522. }
  4523. complete(entry) {
  4524. }
  4525. event(entry, event) {
  4526. }
  4527. };
  4528. var SUBSEQUENT = 0;
  4529. var FIRST = 1;
  4530. var HOLD_SUBSEQUENT = 2;
  4531. var HOLD_FIRST = 3;
  4532. var HOLD_MIX = 4;
  4533. var SETUP = 1;
  4534. var CURRENT = 2;
  4535. // spine-core/src/AnimationStateData.ts
  4536. var AnimationStateData = class {
  4537. constructor(skeletonData) {
  4538. this.animationToMixTime = {};
  4539. /** The mix duration to use when no mix duration has been defined between two animations. */
  4540. this.defaultMix = 0;
  4541. if (!skeletonData)
  4542. throw new Error("skeletonData cannot be null.");
  4543. this.skeletonData = skeletonData;
  4544. }
  4545. /** Sets a mix duration by animation name.
  4546. *
  4547. * See {@link #setMixWith()}. */
  4548. setMix(fromName, toName, duration) {
  4549. let from = this.skeletonData.findAnimation(fromName);
  4550. if (!from)
  4551. throw new Error("Animation not found: " + fromName);
  4552. let to = this.skeletonData.findAnimation(toName);
  4553. if (!to)
  4554. throw new Error("Animation not found: " + toName);
  4555. this.setMixWith(from, to, duration);
  4556. }
  4557. /** Sets the mix duration when changing from the specified animation to the other.
  4558. *
  4559. * See {@link TrackEntry#mixDuration}. */
  4560. setMixWith(from, to, duration) {
  4561. if (!from)
  4562. throw new Error("from cannot be null.");
  4563. if (!to)
  4564. throw new Error("to cannot be null.");
  4565. let key = from.name + "." + to.name;
  4566. this.animationToMixTime[key] = duration;
  4567. }
  4568. /** Returns the mix duration to use when changing from the specified animation to the other, or the {@link #defaultMix} if
  4569. * no mix duration has been set. */
  4570. getMix(from, to) {
  4571. let key = from.name + "." + to.name;
  4572. let value = this.animationToMixTime[key];
  4573. return value === void 0 ? this.defaultMix : value;
  4574. }
  4575. };
  4576. // spine-core/src/attachments/BoundingBoxAttachment.ts
  4577. var BoundingBoxAttachment = class extends VertexAttachment {
  4578. constructor(name) {
  4579. super(name);
  4580. this.color = new Color(1, 1, 1, 1);
  4581. }
  4582. copy() {
  4583. let copy = new BoundingBoxAttachment(this.name);
  4584. this.copyTo(copy);
  4585. copy.color.setFromColor(this.color);
  4586. return copy;
  4587. }
  4588. };
  4589. // spine-core/src/attachments/ClippingAttachment.ts
  4590. var ClippingAttachment = class extends VertexAttachment {
  4591. // ce3a3aff
  4592. constructor(name) {
  4593. super(name);
  4594. /** Clipping is performed between the clipping polygon's slot and the end slot. Returns null if clipping is done until the end of
  4595. * the skeleton's rendering. */
  4596. this.endSlot = null;
  4597. // Nonessential.
  4598. /** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons
  4599. * are not usually rendered at runtime. */
  4600. this.color = new Color(0.2275, 0.2275, 0.8078, 1);
  4601. }
  4602. copy() {
  4603. let copy = new ClippingAttachment(this.name);
  4604. this.copyTo(copy);
  4605. copy.endSlot = this.endSlot;
  4606. copy.color.setFromColor(this.color);
  4607. return copy;
  4608. }
  4609. };
  4610. // spine-core/src/Texture.ts
  4611. var Texture = class {
  4612. constructor(image) {
  4613. this._image = image;
  4614. }
  4615. getImage() {
  4616. return this._image;
  4617. }
  4618. };
  4619. var TextureFilter = /* @__PURE__ */ ((TextureFilter3) => {
  4620. TextureFilter3[TextureFilter3["Nearest"] = 9728] = "Nearest";
  4621. TextureFilter3[TextureFilter3["Linear"] = 9729] = "Linear";
  4622. TextureFilter3[TextureFilter3["MipMap"] = 9987] = "MipMap";
  4623. TextureFilter3[TextureFilter3["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
  4624. TextureFilter3[TextureFilter3["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
  4625. TextureFilter3[TextureFilter3["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
  4626. TextureFilter3[TextureFilter3["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
  4627. return TextureFilter3;
  4628. })(TextureFilter || {});
  4629. var TextureWrap = /* @__PURE__ */ ((TextureWrap4) => {
  4630. TextureWrap4[TextureWrap4["MirroredRepeat"] = 33648] = "MirroredRepeat";
  4631. TextureWrap4[TextureWrap4["ClampToEdge"] = 33071] = "ClampToEdge";
  4632. TextureWrap4[TextureWrap4["Repeat"] = 10497] = "Repeat";
  4633. return TextureWrap4;
  4634. })(TextureWrap || {});
  4635. var TextureRegion = class {
  4636. constructor() {
  4637. this.u = 0;
  4638. this.v = 0;
  4639. this.u2 = 0;
  4640. this.v2 = 0;
  4641. this.width = 0;
  4642. this.height = 0;
  4643. this.degrees = 0;
  4644. this.offsetX = 0;
  4645. this.offsetY = 0;
  4646. this.originalWidth = 0;
  4647. this.originalHeight = 0;
  4648. }
  4649. };
  4650. var FakeTexture = class extends Texture {
  4651. setFilters(minFilter, magFilter) {
  4652. }
  4653. setWraps(uWrap, vWrap) {
  4654. }
  4655. dispose() {
  4656. }
  4657. };
  4658. // spine-core/src/TextureAtlas.ts
  4659. var TextureAtlas = class {
  4660. constructor(atlasText) {
  4661. this.pages = new Array();
  4662. this.regions = new Array();
  4663. let reader = new TextureAtlasReader(atlasText);
  4664. let entry = new Array(4);
  4665. let pageFields = {};
  4666. pageFields["size"] = (page2) => {
  4667. page2.width = parseInt(entry[1]);
  4668. page2.height = parseInt(entry[2]);
  4669. };
  4670. pageFields["format"] = () => {
  4671. };
  4672. pageFields["filter"] = (page2) => {
  4673. page2.minFilter = Utils.enumValue(TextureFilter, entry[1]);
  4674. page2.magFilter = Utils.enumValue(TextureFilter, entry[2]);
  4675. };
  4676. pageFields["repeat"] = (page2) => {
  4677. if (entry[1].indexOf("x") != -1)
  4678. page2.uWrap = 10497 /* Repeat */;
  4679. if (entry[1].indexOf("y") != -1)
  4680. page2.vWrap = 10497 /* Repeat */;
  4681. };
  4682. pageFields["pma"] = (page2) => {
  4683. page2.pma = entry[1] == "true";
  4684. };
  4685. var regionFields = {};
  4686. regionFields["xy"] = (region) => {
  4687. region.x = parseInt(entry[1]);
  4688. region.y = parseInt(entry[2]);
  4689. };
  4690. regionFields["size"] = (region) => {
  4691. region.width = parseInt(entry[1]);
  4692. region.height = parseInt(entry[2]);
  4693. };
  4694. regionFields["bounds"] = (region) => {
  4695. region.x = parseInt(entry[1]);
  4696. region.y = parseInt(entry[2]);
  4697. region.width = parseInt(entry[3]);
  4698. region.height = parseInt(entry[4]);
  4699. };
  4700. regionFields["offset"] = (region) => {
  4701. region.offsetX = parseInt(entry[1]);
  4702. region.offsetY = parseInt(entry[2]);
  4703. };
  4704. regionFields["orig"] = (region) => {
  4705. region.originalWidth = parseInt(entry[1]);
  4706. region.originalHeight = parseInt(entry[2]);
  4707. };
  4708. regionFields["offsets"] = (region) => {
  4709. region.offsetX = parseInt(entry[1]);
  4710. region.offsetY = parseInt(entry[2]);
  4711. region.originalWidth = parseInt(entry[3]);
  4712. region.originalHeight = parseInt(entry[4]);
  4713. };
  4714. regionFields["rotate"] = (region) => {
  4715. let value = entry[1];
  4716. if (value == "true")
  4717. region.degrees = 90;
  4718. else if (value != "false")
  4719. region.degrees = parseInt(value);
  4720. };
  4721. regionFields["index"] = (region) => {
  4722. region.index = parseInt(entry[1]);
  4723. };
  4724. let line = reader.readLine();
  4725. while (line && line.trim().length == 0)
  4726. line = reader.readLine();
  4727. while (true) {
  4728. if (!line || line.trim().length == 0)
  4729. break;
  4730. if (reader.readEntry(entry, line) == 0)
  4731. break;
  4732. line = reader.readLine();
  4733. }
  4734. let page = null;
  4735. let names = null;
  4736. let values = null;
  4737. while (true) {
  4738. if (line === null)
  4739. break;
  4740. if (line.trim().length == 0) {
  4741. page = null;
  4742. line = reader.readLine();
  4743. } else if (!page) {
  4744. page = new TextureAtlasPage(line.trim());
  4745. while (true) {
  4746. if (reader.readEntry(entry, line = reader.readLine()) == 0)
  4747. break;
  4748. let field = pageFields[entry[0]];
  4749. if (field)
  4750. field(page);
  4751. }
  4752. this.pages.push(page);
  4753. } else {
  4754. let region = new TextureAtlasRegion(page, line);
  4755. while (true) {
  4756. let count = reader.readEntry(entry, line = reader.readLine());
  4757. if (count == 0)
  4758. break;
  4759. let field = regionFields[entry[0]];
  4760. if (field)
  4761. field(region);
  4762. else {
  4763. if (!names)
  4764. names = [];
  4765. if (!values)
  4766. values = [];
  4767. names.push(entry[0]);
  4768. let entryValues = [];
  4769. for (let i = 0; i < count; i++)
  4770. entryValues.push(parseInt(entry[i + 1]));
  4771. values.push(entryValues);
  4772. }
  4773. }
  4774. if (region.originalWidth == 0 && region.originalHeight == 0) {
  4775. region.originalWidth = region.width;
  4776. region.originalHeight = region.height;
  4777. }
  4778. if (names && names.length > 0 && values && values.length > 0) {
  4779. region.names = names;
  4780. region.values = values;
  4781. names = null;
  4782. values = null;
  4783. }
  4784. region.u = region.x / page.width;
  4785. region.v = region.y / page.height;
  4786. if (region.degrees == 90) {
  4787. region.u2 = (region.x + region.height) / page.width;
  4788. region.v2 = (region.y + region.width) / page.height;
  4789. } else {
  4790. region.u2 = (region.x + region.width) / page.width;
  4791. region.v2 = (region.y + region.height) / page.height;
  4792. }
  4793. this.regions.push(region);
  4794. }
  4795. }
  4796. }
  4797. findRegion(name) {
  4798. for (let i = 0; i < this.regions.length; i++) {
  4799. if (this.regions[i].name == name) {
  4800. return this.regions[i];
  4801. }
  4802. }
  4803. return null;
  4804. }
  4805. setTextures(assetManager, pathPrefix = "") {
  4806. for (let page of this.pages)
  4807. page.setTexture(assetManager.get(pathPrefix + page.name));
  4808. }
  4809. dispose() {
  4810. var _a;
  4811. for (let i = 0; i < this.pages.length; i++) {
  4812. (_a = this.pages[i].texture) == null ? void 0 : _a.dispose();
  4813. }
  4814. }
  4815. };
  4816. var TextureAtlasReader = class {
  4817. constructor(text) {
  4818. this.index = 0;
  4819. this.lines = text.split(/\r\n|\r|\n/);
  4820. }
  4821. readLine() {
  4822. if (this.index >= this.lines.length)
  4823. return null;
  4824. return this.lines[this.index++];
  4825. }
  4826. readEntry(entry, line) {
  4827. if (!line)
  4828. return 0;
  4829. line = line.trim();
  4830. if (line.length == 0)
  4831. return 0;
  4832. let colon = line.indexOf(":");
  4833. if (colon == -1)
  4834. return 0;
  4835. entry[0] = line.substr(0, colon).trim();
  4836. for (let i = 1, lastMatch = colon + 1; ; i++) {
  4837. let comma = line.indexOf(",", lastMatch);
  4838. if (comma == -1) {
  4839. entry[i] = line.substr(lastMatch).trim();
  4840. return i;
  4841. }
  4842. entry[i] = line.substr(lastMatch, comma - lastMatch).trim();
  4843. lastMatch = comma + 1;
  4844. if (i == 4)
  4845. return 4;
  4846. }
  4847. }
  4848. };
  4849. var TextureAtlasPage = class {
  4850. constructor(name) {
  4851. this.minFilter = 9728 /* Nearest */;
  4852. this.magFilter = 9728 /* Nearest */;
  4853. this.uWrap = 33071 /* ClampToEdge */;
  4854. this.vWrap = 33071 /* ClampToEdge */;
  4855. this.texture = null;
  4856. this.width = 0;
  4857. this.height = 0;
  4858. this.pma = false;
  4859. this.regions = new Array();
  4860. this.name = name;
  4861. }
  4862. setTexture(texture) {
  4863. this.texture = texture;
  4864. texture.setFilters(this.minFilter, this.magFilter);
  4865. texture.setWraps(this.uWrap, this.vWrap);
  4866. for (let region of this.regions)
  4867. region.texture = texture;
  4868. }
  4869. };
  4870. var TextureAtlasRegion = class extends TextureRegion {
  4871. constructor(page, name) {
  4872. super();
  4873. this.x = 0;
  4874. this.y = 0;
  4875. this.offsetX = 0;
  4876. this.offsetY = 0;
  4877. this.originalWidth = 0;
  4878. this.originalHeight = 0;
  4879. this.index = 0;
  4880. this.degrees = 0;
  4881. this.names = null;
  4882. this.values = null;
  4883. this.page = page;
  4884. this.name = name;
  4885. page.regions.push(this);
  4886. }
  4887. };
  4888. // spine-core/src/attachments/MeshAttachment.ts
  4889. var MeshAttachment = class extends VertexAttachment {
  4890. constructor(name, path) {
  4891. super(name);
  4892. this.region = null;
  4893. /** The UV pair for each vertex, normalized within the texture region. */
  4894. this.regionUVs = [];
  4895. /** The UV pair for each vertex, normalized within the entire texture.
  4896. *
  4897. * See {@link #updateUVs}. */
  4898. this.uvs = [];
  4899. /** Triplets of vertex indices which describe the mesh's triangulation. */
  4900. this.triangles = [];
  4901. /** The color to tint the mesh. */
  4902. this.color = new Color(1, 1, 1, 1);
  4903. /** The width of the mesh's image. Available only when nonessential data was exported. */
  4904. this.width = 0;
  4905. /** The height of the mesh's image. Available only when nonessential data was exported. */
  4906. this.height = 0;
  4907. /** The number of entries at the beginning of {@link #vertices} that make up the mesh hull. */
  4908. this.hullLength = 0;
  4909. /** Vertex index pairs describing edges for controling triangulation. Mesh triangles will never cross edges. Only available if
  4910. * nonessential data was exported. Triangulation is not performed at runtime. */
  4911. this.edges = [];
  4912. this.parentMesh = null;
  4913. this.sequence = null;
  4914. this.tempColor = new Color(0, 0, 0, 0);
  4915. this.path = path;
  4916. }
  4917. /** Calculates {@link #uvs} using the {@link #regionUVs} and region. Must be called if the region, the region's properties, or
  4918. * the {@link #regionUVs} are changed. */
  4919. updateRegion() {
  4920. if (!this.region)
  4921. throw new Error("Region not set.");
  4922. let regionUVs = this.regionUVs;
  4923. if (!this.uvs || this.uvs.length != regionUVs.length)
  4924. this.uvs = Utils.newFloatArray(regionUVs.length);
  4925. let uvs = this.uvs;
  4926. let n = this.uvs.length;
  4927. let u = this.region.u, v = this.region.v, width = 0, height = 0;
  4928. if (this.region instanceof TextureAtlasRegion) {
  4929. let region = this.region, image = region.page.texture.getImage();
  4930. let textureWidth = image.width, textureHeight = image.height;
  4931. switch (region.degrees) {
  4932. case 90:
  4933. u -= (region.originalHeight - region.offsetY - region.height) / textureWidth;
  4934. v -= (region.originalWidth - region.offsetX - region.width) / textureHeight;
  4935. width = region.originalHeight / textureWidth;
  4936. height = region.originalWidth / textureHeight;
  4937. for (let i = 0; i < n; i += 2) {
  4938. uvs[i] = u + regionUVs[i + 1] * width;
  4939. uvs[i + 1] = v + (1 - regionUVs[i]) * height;
  4940. }
  4941. return;
  4942. case 180:
  4943. u -= (region.originalWidth - region.offsetX - region.width) / textureWidth;
  4944. v -= region.offsetY / textureHeight;
  4945. width = region.originalWidth / textureWidth;
  4946. height = region.originalHeight / textureHeight;
  4947. for (let i = 0; i < n; i += 2) {
  4948. uvs[i] = u + (1 - regionUVs[i]) * width;
  4949. uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
  4950. }
  4951. return;
  4952. case 270:
  4953. u -= region.offsetY / textureWidth;
  4954. v -= region.offsetX / textureHeight;
  4955. width = region.originalHeight / textureWidth;
  4956. height = region.originalWidth / textureHeight;
  4957. for (let i = 0; i < n; i += 2) {
  4958. uvs[i] = u + (1 - regionUVs[i + 1]) * width;
  4959. uvs[i + 1] = v + regionUVs[i] * height;
  4960. }
  4961. return;
  4962. }
  4963. u -= region.offsetX / textureWidth;
  4964. v -= (region.originalHeight - region.offsetY - region.height) / textureHeight;
  4965. width = region.originalWidth / textureWidth;
  4966. height = region.originalHeight / textureHeight;
  4967. } else if (!this.region) {
  4968. u = v = 0;
  4969. width = height = 1;
  4970. } else {
  4971. width = this.region.u2 - u;
  4972. height = this.region.v2 - v;
  4973. }
  4974. for (let i = 0; i < n; i += 2) {
  4975. uvs[i] = u + regionUVs[i] * width;
  4976. uvs[i + 1] = v + regionUVs[i + 1] * height;
  4977. }
  4978. }
  4979. /** The parent mesh if this is a linked mesh, else null. A linked mesh shares the {@link #bones}, {@link #vertices},
  4980. * {@link #regionUVs}, {@link #triangles}, {@link #hullLength}, {@link #edges}, {@link #width}, and {@link #height} with the
  4981. * parent mesh, but may have a different {@link #name} or {@link #path} (and therefore a different texture). */
  4982. getParentMesh() {
  4983. return this.parentMesh;
  4984. }
  4985. /** @param parentMesh May be null. */
  4986. setParentMesh(parentMesh) {
  4987. this.parentMesh = parentMesh;
  4988. if (parentMesh) {
  4989. this.bones = parentMesh.bones;
  4990. this.vertices = parentMesh.vertices;
  4991. this.worldVerticesLength = parentMesh.worldVerticesLength;
  4992. this.regionUVs = parentMesh.regionUVs;
  4993. this.triangles = parentMesh.triangles;
  4994. this.hullLength = parentMesh.hullLength;
  4995. this.worldVerticesLength = parentMesh.worldVerticesLength;
  4996. }
  4997. }
  4998. copy() {
  4999. if (this.parentMesh)
  5000. return this.newLinkedMesh();
  5001. let copy = new MeshAttachment(this.name, this.path);
  5002. copy.region = this.region;
  5003. copy.color.setFromColor(this.color);
  5004. this.copyTo(copy);
  5005. copy.regionUVs = new Array(this.regionUVs.length);
  5006. Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
  5007. copy.uvs = new Array(this.uvs.length);
  5008. Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
  5009. copy.triangles = new Array(this.triangles.length);
  5010. Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
  5011. copy.hullLength = this.hullLength;
  5012. copy.sequence = this.sequence != null ? this.sequence.copy() : null;
  5013. if (this.edges) {
  5014. copy.edges = new Array(this.edges.length);
  5015. Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
  5016. }
  5017. copy.width = this.width;
  5018. copy.height = this.height;
  5019. return copy;
  5020. }
  5021. computeWorldVertices(slot, start, count, worldVertices2, offset, stride) {
  5022. if (this.sequence != null)
  5023. this.sequence.apply(slot, this);
  5024. super.computeWorldVertices(slot, start, count, worldVertices2, offset, stride);
  5025. }
  5026. /** Returns a new mesh with the {@link #parentMesh} set to this mesh's parent mesh, if any, else to this mesh. **/
  5027. newLinkedMesh() {
  5028. let copy = new MeshAttachment(this.name, this.path);
  5029. copy.region = this.region;
  5030. copy.color.setFromColor(this.color);
  5031. copy.timelineAttachment = this.timelineAttachment;
  5032. copy.setParentMesh(this.parentMesh ? this.parentMesh : this);
  5033. if (copy.region != null)
  5034. copy.updateRegion();
  5035. return copy;
  5036. }
  5037. };
  5038. // spine-core/src/attachments/PathAttachment.ts
  5039. var PathAttachment = class extends VertexAttachment {
  5040. constructor(name) {
  5041. super(name);
  5042. /** The lengths along the path in the setup pose from the start of the path to the end of each Bezier curve. */
  5043. this.lengths = [];
  5044. /** If true, the start and end knots are connected. */
  5045. this.closed = false;
  5046. /** If true, additional calculations are performed to make calculating positions along the path more accurate. If false, fewer
  5047. * calculations are performed but calculating positions along the path is less accurate. */
  5048. this.constantSpeed = false;
  5049. /** The color of the path as it was in Spine. Available only when nonessential data was exported. Paths are not usually
  5050. * rendered at runtime. */
  5051. this.color = new Color(1, 1, 1, 1);
  5052. }
  5053. copy() {
  5054. let copy = new PathAttachment(this.name);
  5055. this.copyTo(copy);
  5056. copy.lengths = new Array(this.lengths.length);
  5057. Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
  5058. copy.closed = closed;
  5059. copy.constantSpeed = this.constantSpeed;
  5060. copy.color.setFromColor(this.color);
  5061. return copy;
  5062. }
  5063. };
  5064. // spine-core/src/attachments/PointAttachment.ts
  5065. var PointAttachment = class extends VertexAttachment {
  5066. constructor(name) {
  5067. super(name);
  5068. this.x = 0;
  5069. this.y = 0;
  5070. this.rotation = 0;
  5071. /** The color of the point attachment as it was in Spine. Available only when nonessential data was exported. Point attachments
  5072. * are not usually rendered at runtime. */
  5073. this.color = new Color(0.38, 0.94, 0, 1);
  5074. }
  5075. computeWorldPosition(bone, point) {
  5076. point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
  5077. point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
  5078. return point;
  5079. }
  5080. computeWorldRotation(bone) {
  5081. let cos = MathUtils.cosDeg(this.rotation), sin = MathUtils.sinDeg(this.rotation);
  5082. let x = cos * bone.a + sin * bone.b;
  5083. let y = cos * bone.c + sin * bone.d;
  5084. return Math.atan2(y, x) * MathUtils.radDeg;
  5085. }
  5086. copy() {
  5087. let copy = new PointAttachment(this.name);
  5088. copy.x = this.x;
  5089. copy.y = this.y;
  5090. copy.rotation = this.rotation;
  5091. copy.color.setFromColor(this.color);
  5092. return copy;
  5093. }
  5094. };
  5095. // spine-core/src/attachments/RegionAttachment.ts
  5096. var _RegionAttachment = class extends Attachment {
  5097. constructor(name, path) {
  5098. super(name);
  5099. /** The local x translation. */
  5100. this.x = 0;
  5101. /** The local y translation. */
  5102. this.y = 0;
  5103. /** The local scaleX. */
  5104. this.scaleX = 1;
  5105. /** The local scaleY. */
  5106. this.scaleY = 1;
  5107. /** The local rotation. */
  5108. this.rotation = 0;
  5109. /** The width of the region attachment in Spine. */
  5110. this.width = 0;
  5111. /** The height of the region attachment in Spine. */
  5112. this.height = 0;
  5113. /** The color to tint the region attachment. */
  5114. this.color = new Color(1, 1, 1, 1);
  5115. this.region = null;
  5116. this.sequence = null;
  5117. /** For each of the 4 vertices, a pair of <code>x,y</code> values that is the local position of the vertex.
  5118. *
  5119. * See {@link #updateOffset()}. */
  5120. this.offset = Utils.newFloatArray(8);
  5121. this.uvs = Utils.newFloatArray(8);
  5122. this.tempColor = new Color(1, 1, 1, 1);
  5123. this.path = path;
  5124. }
  5125. /** Calculates the {@link #offset} using the region settings. Must be called after changing region settings. */
  5126. updateRegion() {
  5127. if (!this.region)
  5128. throw new Error("Region not set.");
  5129. let region = this.region;
  5130. let uvs = this.uvs;
  5131. if (region == null) {
  5132. uvs[0] = 0;
  5133. uvs[1] = 0;
  5134. uvs[2] = 0;
  5135. uvs[3] = 1;
  5136. uvs[4] = 1;
  5137. uvs[5] = 1;
  5138. uvs[6] = 1;
  5139. uvs[7] = 0;
  5140. return;
  5141. }
  5142. let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  5143. let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  5144. let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  5145. let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  5146. let localX2 = localX + this.region.width * regionScaleX;
  5147. let localY2 = localY + this.region.height * regionScaleY;
  5148. let radians = this.rotation * Math.PI / 180;
  5149. let cos = Math.cos(radians);
  5150. let sin = Math.sin(radians);
  5151. let x = this.x, y = this.y;
  5152. let localXCos = localX * cos + x;
  5153. let localXSin = localX * sin;
  5154. let localYCos = localY * cos + y;
  5155. let localYSin = localY * sin;
  5156. let localX2Cos = localX2 * cos + x;
  5157. let localX2Sin = localX2 * sin;
  5158. let localY2Cos = localY2 * cos + y;
  5159. let localY2Sin = localY2 * sin;
  5160. let offset = this.offset;
  5161. offset[0] = localXCos - localYSin;
  5162. offset[1] = localYCos + localXSin;
  5163. offset[2] = localXCos - localY2Sin;
  5164. offset[3] = localY2Cos + localXSin;
  5165. offset[4] = localX2Cos - localY2Sin;
  5166. offset[5] = localY2Cos + localX2Sin;
  5167. offset[6] = localX2Cos - localYSin;
  5168. offset[7] = localYCos + localX2Sin;
  5169. if (region.degrees == 90) {
  5170. uvs[0] = region.u2;
  5171. uvs[1] = region.v2;
  5172. uvs[2] = region.u;
  5173. uvs[3] = region.v2;
  5174. uvs[4] = region.u;
  5175. uvs[5] = region.v;
  5176. uvs[6] = region.u2;
  5177. uvs[7] = region.v;
  5178. } else {
  5179. uvs[0] = region.u;
  5180. uvs[1] = region.v2;
  5181. uvs[2] = region.u;
  5182. uvs[3] = region.v;
  5183. uvs[4] = region.u2;
  5184. uvs[5] = region.v;
  5185. uvs[6] = region.u2;
  5186. uvs[7] = region.v2;
  5187. }
  5188. }
  5189. /** Transforms the attachment's four vertices to world coordinates. If the attachment has a {@link #sequence}, the region may
  5190. * be changed.
  5191. * <p>
  5192. * See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
  5193. * Runtimes Guide.
  5194. * @param worldVertices The output world vertices. Must have a length >= <code>offset</code> + 8.
  5195. * @param offset The <code>worldVertices</code> index to begin writing values.
  5196. * @param stride The number of <code>worldVertices</code> entries between the value pairs written. */
  5197. computeWorldVertices(slot, worldVertices2, offset, stride) {
  5198. if (this.sequence != null)
  5199. this.sequence.apply(slot, this);
  5200. let bone = slot.bone;
  5201. let vertexOffset = this.offset;
  5202. let x = bone.worldX, y = bone.worldY;
  5203. let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  5204. let offsetX = 0, offsetY = 0;
  5205. offsetX = vertexOffset[0];
  5206. offsetY = vertexOffset[1];
  5207. worldVertices2[offset] = offsetX * a + offsetY * b + x;
  5208. worldVertices2[offset + 1] = offsetX * c + offsetY * d + y;
  5209. offset += stride;
  5210. offsetX = vertexOffset[2];
  5211. offsetY = vertexOffset[3];
  5212. worldVertices2[offset] = offsetX * a + offsetY * b + x;
  5213. worldVertices2[offset + 1] = offsetX * c + offsetY * d + y;
  5214. offset += stride;
  5215. offsetX = vertexOffset[4];
  5216. offsetY = vertexOffset[5];
  5217. worldVertices2[offset] = offsetX * a + offsetY * b + x;
  5218. worldVertices2[offset + 1] = offsetX * c + offsetY * d + y;
  5219. offset += stride;
  5220. offsetX = vertexOffset[6];
  5221. offsetY = vertexOffset[7];
  5222. worldVertices2[offset] = offsetX * a + offsetY * b + x;
  5223. worldVertices2[offset + 1] = offsetX * c + offsetY * d + y;
  5224. }
  5225. copy() {
  5226. let copy = new _RegionAttachment(this.name, this.path);
  5227. copy.region = this.region;
  5228. copy.x = this.x;
  5229. copy.y = this.y;
  5230. copy.scaleX = this.scaleX;
  5231. copy.scaleY = this.scaleY;
  5232. copy.rotation = this.rotation;
  5233. copy.width = this.width;
  5234. copy.height = this.height;
  5235. Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
  5236. Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
  5237. copy.color.setFromColor(this.color);
  5238. copy.sequence = this.sequence != null ? this.sequence.copy() : null;
  5239. return copy;
  5240. }
  5241. };
  5242. var RegionAttachment = _RegionAttachment;
  5243. RegionAttachment.X1 = 0;
  5244. RegionAttachment.Y1 = 1;
  5245. RegionAttachment.C1R = 2;
  5246. RegionAttachment.C1G = 3;
  5247. RegionAttachment.C1B = 4;
  5248. RegionAttachment.C1A = 5;
  5249. RegionAttachment.U1 = 6;
  5250. RegionAttachment.V1 = 7;
  5251. RegionAttachment.X2 = 8;
  5252. RegionAttachment.Y2 = 9;
  5253. RegionAttachment.C2R = 10;
  5254. RegionAttachment.C2G = 11;
  5255. RegionAttachment.C2B = 12;
  5256. RegionAttachment.C2A = 13;
  5257. RegionAttachment.U2 = 14;
  5258. RegionAttachment.V2 = 15;
  5259. RegionAttachment.X3 = 16;
  5260. RegionAttachment.Y3 = 17;
  5261. RegionAttachment.C3R = 18;
  5262. RegionAttachment.C3G = 19;
  5263. RegionAttachment.C3B = 20;
  5264. RegionAttachment.C3A = 21;
  5265. RegionAttachment.U3 = 22;
  5266. RegionAttachment.V3 = 23;
  5267. RegionAttachment.X4 = 24;
  5268. RegionAttachment.Y4 = 25;
  5269. RegionAttachment.C4R = 26;
  5270. RegionAttachment.C4G = 27;
  5271. RegionAttachment.C4B = 28;
  5272. RegionAttachment.C4A = 29;
  5273. RegionAttachment.U4 = 30;
  5274. RegionAttachment.V4 = 31;
  5275. // spine-core/src/AtlasAttachmentLoader.ts
  5276. var AtlasAttachmentLoader = class {
  5277. constructor(atlas) {
  5278. this.atlas = atlas;
  5279. }
  5280. loadSequence(name, basePath, sequence) {
  5281. let regions = sequence.regions;
  5282. for (let i = 0, n = regions.length; i < n; i++) {
  5283. let path = sequence.getPath(basePath, i);
  5284. let region = this.atlas.findRegion(path);
  5285. if (region == null)
  5286. throw new Error("Region not found in atlas: " + path + " (sequence: " + name + ")");
  5287. regions[i] = region;
  5288. }
  5289. }
  5290. newRegionAttachment(skin, name, path, sequence) {
  5291. let attachment = new RegionAttachment(name, path);
  5292. if (sequence != null) {
  5293. this.loadSequence(name, path, sequence);
  5294. } else {
  5295. let region = this.atlas.findRegion(path);
  5296. if (!region)
  5297. throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  5298. attachment.region = region;
  5299. }
  5300. return attachment;
  5301. }
  5302. newMeshAttachment(skin, name, path, sequence) {
  5303. let attachment = new MeshAttachment(name, path);
  5304. if (sequence != null) {
  5305. this.loadSequence(name, path, sequence);
  5306. } else {
  5307. let region = this.atlas.findRegion(path);
  5308. if (!region)
  5309. throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  5310. attachment.region = region;
  5311. }
  5312. return attachment;
  5313. }
  5314. newBoundingBoxAttachment(skin, name) {
  5315. return new BoundingBoxAttachment(name);
  5316. }
  5317. newPathAttachment(skin, name) {
  5318. return new PathAttachment(name);
  5319. }
  5320. newPointAttachment(skin, name) {
  5321. return new PointAttachment(name);
  5322. }
  5323. newClippingAttachment(skin, name) {
  5324. return new ClippingAttachment(name);
  5325. }
  5326. };
  5327. // spine-core/src/BoneData.ts
  5328. var BoneData = class {
  5329. constructor(index, name, parent) {
  5330. /** The index of the bone in {@link Skeleton#getBones()}. */
  5331. this.index = 0;
  5332. /** @returns May be null. */
  5333. this.parent = null;
  5334. /** The bone's length. */
  5335. this.length = 0;
  5336. /** The local x translation. */
  5337. this.x = 0;
  5338. /** The local y translation. */
  5339. this.y = 0;
  5340. /** The local rotation. */
  5341. this.rotation = 0;
  5342. /** The local scaleX. */
  5343. this.scaleX = 1;
  5344. /** The local scaleY. */
  5345. this.scaleY = 1;
  5346. /** The local shearX. */
  5347. this.shearX = 0;
  5348. /** The local shearX. */
  5349. this.shearY = 0;
  5350. /** The transform mode for how parent world transforms affect this bone. */
  5351. this.transformMode = TransformMode.Normal;
  5352. /** When true, {@link Skeleton#updateWorldTransform()} only updates this bone if the {@link Skeleton#skin} contains this
  5353. * bone.
  5354. * @see Skin#bones */
  5355. this.skinRequired = false;
  5356. /** The color of the bone as it was in Spine. Available only when nonessential data was exported. Bones are not usually
  5357. * rendered at runtime. */
  5358. this.color = new Color();
  5359. if (index < 0)
  5360. throw new Error("index must be >= 0.");
  5361. if (!name)
  5362. throw new Error("name cannot be null.");
  5363. this.index = index;
  5364. this.name = name;
  5365. this.parent = parent;
  5366. }
  5367. };
  5368. var TransformMode = /* @__PURE__ */ ((TransformMode2) => {
  5369. TransformMode2[TransformMode2["Normal"] = 0] = "Normal";
  5370. TransformMode2[TransformMode2["OnlyTranslation"] = 1] = "OnlyTranslation";
  5371. TransformMode2[TransformMode2["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
  5372. TransformMode2[TransformMode2["NoScale"] = 3] = "NoScale";
  5373. TransformMode2[TransformMode2["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
  5374. return TransformMode2;
  5375. })(TransformMode || {});
  5376. // spine-core/src/Bone.ts
  5377. var Bone = class {
  5378. /** @param parent May be null. */
  5379. constructor(data, skeleton, parent) {
  5380. /** The parent bone, or null if this is the root bone. */
  5381. this.parent = null;
  5382. /** The immediate children of this bone. */
  5383. this.children = new Array();
  5384. /** The local x translation. */
  5385. this.x = 0;
  5386. /** The local y translation. */
  5387. this.y = 0;
  5388. /** The local rotation in degrees, counter clockwise. */
  5389. this.rotation = 0;
  5390. /** The local scaleX. */
  5391. this.scaleX = 0;
  5392. /** The local scaleY. */
  5393. this.scaleY = 0;
  5394. /** The local shearX. */
  5395. this.shearX = 0;
  5396. /** The local shearY. */
  5397. this.shearY = 0;
  5398. /** The applied local x translation. */
  5399. this.ax = 0;
  5400. /** The applied local y translation. */
  5401. this.ay = 0;
  5402. /** The applied local rotation in degrees, counter clockwise. */
  5403. this.arotation = 0;
  5404. /** The applied local scaleX. */
  5405. this.ascaleX = 0;
  5406. /** The applied local scaleY. */
  5407. this.ascaleY = 0;
  5408. /** The applied local shearX. */
  5409. this.ashearX = 0;
  5410. /** The applied local shearY. */
  5411. this.ashearY = 0;
  5412. /** Part of the world transform matrix for the X axis. If changed, {@link #updateAppliedTransform()} should be called. */
  5413. this.a = 0;
  5414. /** Part of the world transform matrix for the Y axis. If changed, {@link #updateAppliedTransform()} should be called. */
  5415. this.b = 0;
  5416. /** Part of the world transform matrix for the X axis. If changed, {@link #updateAppliedTransform()} should be called. */
  5417. this.c = 0;
  5418. /** Part of the world transform matrix for the Y axis. If changed, {@link #updateAppliedTransform()} should be called. */
  5419. this.d = 0;
  5420. /** The world X position. If changed, {@link #updateAppliedTransform()} should be called. */
  5421. this.worldY = 0;
  5422. /** The world Y position. If changed, {@link #updateAppliedTransform()} should be called. */
  5423. this.worldX = 0;
  5424. this.sorted = false;
  5425. this.active = false;
  5426. if (!data)
  5427. throw new Error("data cannot be null.");
  5428. if (!skeleton)
  5429. throw new Error("skeleton cannot be null.");
  5430. this.data = data;
  5431. this.skeleton = skeleton;
  5432. this.parent = parent;
  5433. this.setToSetupPose();
  5434. }
  5435. /** Returns false when the bone has not been computed because {@link BoneData#skinRequired} is true and the
  5436. * {@link Skeleton#skin active skin} does not {@link Skin#bones contain} this bone. */
  5437. isActive() {
  5438. return this.active;
  5439. }
  5440. /** Computes the world transform using the parent bone and this bone's local applied transform. */
  5441. update() {
  5442. this.updateWorldTransformWith(this.ax, this.ay, this.arotation, this.ascaleX, this.ascaleY, this.ashearX, this.ashearY);
  5443. }
  5444. /** Computes the world transform using the parent bone and this bone's local transform.
  5445. *
  5446. * See {@link #updateWorldTransformWith()}. */
  5447. updateWorldTransform() {
  5448. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  5449. }
  5450. /** Computes the world transform using the parent bone and the specified local transform. The applied transform is set to the
  5451. * specified local transform. Child bones are not updated.
  5452. *
  5453. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  5454. * Runtimes Guide. */
  5455. updateWorldTransformWith(x, y, rotation, scaleX, scaleY, shearX, shearY) {
  5456. this.ax = x;
  5457. this.ay = y;
  5458. this.arotation = rotation;
  5459. this.ascaleX = scaleX;
  5460. this.ascaleY = scaleY;
  5461. this.ashearX = shearX;
  5462. this.ashearY = shearY;
  5463. let parent = this.parent;
  5464. if (!parent) {
  5465. let skeleton = this.skeleton;
  5466. let rotationY = rotation + 90 + shearY;
  5467. let sx = skeleton.scaleX;
  5468. let sy = skeleton.scaleY;
  5469. this.a = MathUtils.cosDeg(rotation + shearX) * scaleX * sx;
  5470. this.b = MathUtils.cosDeg(rotationY) * scaleY * sx;
  5471. this.c = MathUtils.sinDeg(rotation + shearX) * scaleX * sy;
  5472. this.d = MathUtils.sinDeg(rotationY) * scaleY * sy;
  5473. this.worldX = x * sx + skeleton.x;
  5474. this.worldY = y * sy + skeleton.y;
  5475. return;
  5476. }
  5477. let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  5478. this.worldX = pa * x + pb * y + parent.worldX;
  5479. this.worldY = pc * x + pd * y + parent.worldY;
  5480. switch (this.data.transformMode) {
  5481. case 0 /* Normal */: {
  5482. let rotationY = rotation + 90 + shearY;
  5483. let la = MathUtils.cosDeg(rotation + shearX) * scaleX;
  5484. let lb = MathUtils.cosDeg(rotationY) * scaleY;
  5485. let lc = MathUtils.sinDeg(rotation + shearX) * scaleX;
  5486. let ld = MathUtils.sinDeg(rotationY) * scaleY;
  5487. this.a = pa * la + pb * lc;
  5488. this.b = pa * lb + pb * ld;
  5489. this.c = pc * la + pd * lc;
  5490. this.d = pc * lb + pd * ld;
  5491. return;
  5492. }
  5493. case 1 /* OnlyTranslation */: {
  5494. let rotationY = rotation + 90 + shearY;
  5495. this.a = MathUtils.cosDeg(rotation + shearX) * scaleX;
  5496. this.b = MathUtils.cosDeg(rotationY) * scaleY;
  5497. this.c = MathUtils.sinDeg(rotation + shearX) * scaleX;
  5498. this.d = MathUtils.sinDeg(rotationY) * scaleY;
  5499. break;
  5500. }
  5501. case 2 /* NoRotationOrReflection */: {
  5502. let s = pa * pa + pc * pc;
  5503. let prx = 0;
  5504. if (s > 1e-4) {
  5505. s = Math.abs(pa * pd - pb * pc) / s;
  5506. pa /= this.skeleton.scaleX;
  5507. pc /= this.skeleton.scaleY;
  5508. pb = pc * s;
  5509. pd = pa * s;
  5510. prx = Math.atan2(pc, pa) * MathUtils.radDeg;
  5511. } else {
  5512. pa = 0;
  5513. pc = 0;
  5514. prx = 90 - Math.atan2(pd, pb) * MathUtils.radDeg;
  5515. }
  5516. let rx = rotation + shearX - prx;
  5517. let ry = rotation + shearY - prx + 90;
  5518. let la = MathUtils.cosDeg(rx) * scaleX;
  5519. let lb = MathUtils.cosDeg(ry) * scaleY;
  5520. let lc = MathUtils.sinDeg(rx) * scaleX;
  5521. let ld = MathUtils.sinDeg(ry) * scaleY;
  5522. this.a = pa * la - pb * lc;
  5523. this.b = pa * lb - pb * ld;
  5524. this.c = pc * la + pd * lc;
  5525. this.d = pc * lb + pd * ld;
  5526. break;
  5527. }
  5528. case 3 /* NoScale */:
  5529. case 4 /* NoScaleOrReflection */: {
  5530. let cos = MathUtils.cosDeg(rotation);
  5531. let sin = MathUtils.sinDeg(rotation);
  5532. let za = (pa * cos + pb * sin) / this.skeleton.scaleX;
  5533. let zc = (pc * cos + pd * sin) / this.skeleton.scaleY;
  5534. let s = Math.sqrt(za * za + zc * zc);
  5535. if (s > 1e-5)
  5536. s = 1 / s;
  5537. za *= s;
  5538. zc *= s;
  5539. s = Math.sqrt(za * za + zc * zc);
  5540. if (this.data.transformMode == 3 /* NoScale */ && pa * pd - pb * pc < 0 != (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0))
  5541. s = -s;
  5542. let r = Math.PI / 2 + Math.atan2(zc, za);
  5543. let zb = Math.cos(r) * s;
  5544. let zd = Math.sin(r) * s;
  5545. let la = MathUtils.cosDeg(shearX) * scaleX;
  5546. let lb = MathUtils.cosDeg(90 + shearY) * scaleY;
  5547. let lc = MathUtils.sinDeg(shearX) * scaleX;
  5548. let ld = MathUtils.sinDeg(90 + shearY) * scaleY;
  5549. this.a = za * la + zb * lc;
  5550. this.b = za * lb + zb * ld;
  5551. this.c = zc * la + zd * lc;
  5552. this.d = zc * lb + zd * ld;
  5553. break;
  5554. }
  5555. }
  5556. this.a *= this.skeleton.scaleX;
  5557. this.b *= this.skeleton.scaleX;
  5558. this.c *= this.skeleton.scaleY;
  5559. this.d *= this.skeleton.scaleY;
  5560. }
  5561. /** Sets this bone's local transform to the setup pose. */
  5562. setToSetupPose() {
  5563. let data = this.data;
  5564. this.x = data.x;
  5565. this.y = data.y;
  5566. this.rotation = data.rotation;
  5567. this.scaleX = data.scaleX;
  5568. this.scaleY = data.scaleY;
  5569. this.shearX = data.shearX;
  5570. this.shearY = data.shearY;
  5571. }
  5572. /** The world rotation for the X axis, calculated using {@link #a} and {@link #c}. */
  5573. getWorldRotationX() {
  5574. return Math.atan2(this.c, this.a) * MathUtils.radDeg;
  5575. }
  5576. /** The world rotation for the Y axis, calculated using {@link #b} and {@link #d}. */
  5577. getWorldRotationY() {
  5578. return Math.atan2(this.d, this.b) * MathUtils.radDeg;
  5579. }
  5580. /** The magnitude (always positive) of the world scale X, calculated using {@link #a} and {@link #c}. */
  5581. getWorldScaleX() {
  5582. return Math.sqrt(this.a * this.a + this.c * this.c);
  5583. }
  5584. /** The magnitude (always positive) of the world scale Y, calculated using {@link #b} and {@link #d}. */
  5585. getWorldScaleY() {
  5586. return Math.sqrt(this.b * this.b + this.d * this.d);
  5587. }
  5588. /** Computes the applied transform values from the world transform.
  5589. *
  5590. * If the world transform is modified (by a constraint, {@link #rotateWorld(float)}, etc) then this method should be called so
  5591. * the applied transform matches the world transform. The applied transform may be needed by other code (eg to apply other
  5592. * constraints).
  5593. *
  5594. * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after
  5595. * calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. */
  5596. updateAppliedTransform() {
  5597. let parent = this.parent;
  5598. if (!parent) {
  5599. this.ax = this.worldX - this.skeleton.x;
  5600. this.ay = this.worldY - this.skeleton.y;
  5601. this.arotation = Math.atan2(this.c, this.a) * MathUtils.radDeg;
  5602. this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c);
  5603. this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d);
  5604. this.ashearX = 0;
  5605. this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * MathUtils.radDeg;
  5606. return;
  5607. }
  5608. let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  5609. let pid = 1 / (pa * pd - pb * pc);
  5610. let dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY;
  5611. this.ax = dx * pd * pid - dy * pb * pid;
  5612. this.ay = dy * pa * pid - dx * pc * pid;
  5613. let ia = pid * pd;
  5614. let id = pid * pa;
  5615. let ib = pid * pb;
  5616. let ic = pid * pc;
  5617. let ra = ia * this.a - ib * this.c;
  5618. let rb = ia * this.b - ib * this.d;
  5619. let rc = id * this.c - ic * this.a;
  5620. let rd = id * this.d - ic * this.b;
  5621. this.ashearX = 0;
  5622. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  5623. if (this.ascaleX > 1e-4) {
  5624. let det = ra * rd - rb * rc;
  5625. this.ascaleY = det / this.ascaleX;
  5626. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * MathUtils.radDeg;
  5627. this.arotation = Math.atan2(rc, ra) * MathUtils.radDeg;
  5628. } else {
  5629. this.ascaleX = 0;
  5630. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  5631. this.ashearY = 0;
  5632. this.arotation = 90 - Math.atan2(rd, rb) * MathUtils.radDeg;
  5633. }
  5634. }
  5635. /** Transforms a point from world coordinates to the bone's local coordinates. */
  5636. worldToLocal(world) {
  5637. let invDet = 1 / (this.a * this.d - this.b * this.c);
  5638. let x = world.x - this.worldX, y = world.y - this.worldY;
  5639. world.x = x * this.d * invDet - y * this.b * invDet;
  5640. world.y = y * this.a * invDet - x * this.c * invDet;
  5641. return world;
  5642. }
  5643. /** Transforms a point from the bone's local coordinates to world coordinates. */
  5644. localToWorld(local) {
  5645. let x = local.x, y = local.y;
  5646. local.x = x * this.a + y * this.b + this.worldX;
  5647. local.y = x * this.c + y * this.d + this.worldY;
  5648. return local;
  5649. }
  5650. /** Transforms a world rotation to a local rotation. */
  5651. worldToLocalRotation(worldRotation) {
  5652. let sin = MathUtils.sinDeg(worldRotation), cos = MathUtils.cosDeg(worldRotation);
  5653. return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * MathUtils.radDeg + this.rotation - this.shearX;
  5654. }
  5655. /** Transforms a local rotation to a world rotation. */
  5656. localToWorldRotation(localRotation) {
  5657. localRotation -= this.rotation - this.shearX;
  5658. let sin = MathUtils.sinDeg(localRotation), cos = MathUtils.cosDeg(localRotation);
  5659. return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * MathUtils.radDeg;
  5660. }
  5661. /** Rotates the world transform the specified amount.
  5662. * <p>
  5663. * After changes are made to the world transform, {@link #updateAppliedTransform()} should be called and {@link #update()} will
  5664. * need to be called on any child bones, recursively. */
  5665. rotateWorld(degrees) {
  5666. let a = this.a, b = this.b, c = this.c, d = this.d;
  5667. let cos = MathUtils.cosDeg(degrees), sin = MathUtils.sinDeg(degrees);
  5668. this.a = cos * a - sin * c;
  5669. this.b = cos * b - sin * d;
  5670. this.c = sin * a + cos * c;
  5671. this.d = sin * b + cos * d;
  5672. }
  5673. };
  5674. // spine-core/src/ConstraintData.ts
  5675. var ConstraintData = class {
  5676. constructor(name, order, skinRequired) {
  5677. this.name = name;
  5678. this.order = order;
  5679. this.skinRequired = skinRequired;
  5680. }
  5681. };
  5682. // spine-core/src/AssetManagerBase.ts
  5683. var AssetManagerBase = class {
  5684. constructor(textureLoader, pathPrefix = "", downloader = new Downloader()) {
  5685. this.pathPrefix = "";
  5686. this.assets = {};
  5687. this.errors = {};
  5688. this.toLoad = 0;
  5689. this.loaded = 0;
  5690. this.textureLoader = textureLoader;
  5691. this.pathPrefix = pathPrefix;
  5692. this.downloader = downloader;
  5693. }
  5694. start(path) {
  5695. this.toLoad++;
  5696. return this.pathPrefix + path;
  5697. }
  5698. success(callback, path, asset) {
  5699. this.toLoad--;
  5700. this.loaded++;
  5701. this.assets[path] = asset;
  5702. if (callback)
  5703. callback(path, asset);
  5704. }
  5705. error(callback, path, message) {
  5706. this.toLoad--;
  5707. this.loaded++;
  5708. this.errors[path] = message;
  5709. if (callback)
  5710. callback(path, message);
  5711. }
  5712. loadAll() {
  5713. let promise = new Promise((resolve, reject) => {
  5714. let check = () => {
  5715. if (this.isLoadingComplete()) {
  5716. if (this.hasErrors())
  5717. reject(this.errors);
  5718. else
  5719. resolve(this);
  5720. return;
  5721. }
  5722. requestAnimationFrame(check);
  5723. };
  5724. requestAnimationFrame(check);
  5725. });
  5726. return promise;
  5727. }
  5728. setRawDataURI(path, data) {
  5729. this.downloader.rawDataUris[this.pathPrefix + path] = data;
  5730. }
  5731. loadBinary(path, success = () => {
  5732. }, error = () => {
  5733. }) {
  5734. path = this.start(path);
  5735. this.downloader.downloadBinary(path, (data) => {
  5736. this.success(success, path, data);
  5737. }, (status, responseText) => {
  5738. this.error(error, path, `Couldn't load binary ${path}: status ${status}, ${responseText}`);
  5739. });
  5740. }
  5741. loadText(path, success = () => {
  5742. }, error = () => {
  5743. }) {
  5744. path = this.start(path);
  5745. this.downloader.downloadText(path, (data) => {
  5746. this.success(success, path, data);
  5747. }, (status, responseText) => {
  5748. this.error(error, path, `Couldn't load text ${path}: status ${status}, ${responseText}`);
  5749. });
  5750. }
  5751. loadJson(path, success = () => {
  5752. }, error = () => {
  5753. }) {
  5754. path = this.start(path);
  5755. this.downloader.downloadJson(path, (data) => {
  5756. this.success(success, path, data);
  5757. }, (status, responseText) => {
  5758. this.error(error, path, `Couldn't load JSON ${path}: status ${status}, ${responseText}`);
  5759. });
  5760. }
  5761. loadTexture(path, success = () => {
  5762. }, error = () => {
  5763. }) {
  5764. path = this.start(path);
  5765. let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document);
  5766. let isWebWorker = !isBrowser;
  5767. if (isWebWorker) {
  5768. fetch(path, { mode: "cors" }).then((response) => {
  5769. if (response.ok)
  5770. return response.blob();
  5771. this.error(error, path, `Couldn't load image: ${path}`);
  5772. return null;
  5773. }).then((blob) => {
  5774. return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
  5775. }).then((bitmap) => {
  5776. if (bitmap)
  5777. this.success(success, path, this.textureLoader(bitmap));
  5778. });
  5779. } else {
  5780. let image = new Image();
  5781. image.crossOrigin = "anonymous";
  5782. image.onload = () => {
  5783. this.success(success, path, this.textureLoader(image));
  5784. };
  5785. image.onerror = () => {
  5786. this.error(error, path, `Couldn't load image: ${path}`);
  5787. };
  5788. if (this.downloader.rawDataUris[path])
  5789. path = this.downloader.rawDataUris[path];
  5790. image.src = path;
  5791. }
  5792. }
  5793. loadTextureAtlas(path, success = () => {
  5794. }, error = () => {
  5795. }, fileAlias) {
  5796. let index = path.lastIndexOf("/");
  5797. let parent = index >= 0 ? path.substring(0, index + 1) : "";
  5798. path = this.start(path);
  5799. this.downloader.downloadText(path, (atlasText) => {
  5800. try {
  5801. let atlas = new TextureAtlas(atlasText);
  5802. let toLoad = atlas.pages.length, abort = false;
  5803. for (let page of atlas.pages) {
  5804. this.loadTexture(
  5805. !fileAlias ? parent + page.name : fileAlias[page.name],
  5806. (imagePath, texture) => {
  5807. if (!abort) {
  5808. page.setTexture(texture);
  5809. if (--toLoad == 0)
  5810. this.success(success, path, atlas);
  5811. }
  5812. },
  5813. (imagePath, message) => {
  5814. if (!abort)
  5815. this.error(error, path, `Couldn't load texture atlas ${path} page image: ${imagePath}`);
  5816. abort = true;
  5817. }
  5818. );
  5819. }
  5820. } catch (e) {
  5821. this.error(error, path, `Couldn't parse texture atlas ${path}: ${e.message}`);
  5822. }
  5823. }, (status, responseText) => {
  5824. this.error(error, path, `Couldn't load texture atlas ${path}: status ${status}, ${responseText}`);
  5825. });
  5826. }
  5827. get(path) {
  5828. return this.assets[this.pathPrefix + path];
  5829. }
  5830. require(path) {
  5831. path = this.pathPrefix + path;
  5832. let asset = this.assets[path];
  5833. if (asset)
  5834. return asset;
  5835. let error = this.errors[path];
  5836. throw Error("Asset not found: " + path + (error ? "\n" + error : ""));
  5837. }
  5838. remove(path) {
  5839. path = this.pathPrefix + path;
  5840. let asset = this.assets[path];
  5841. if (asset.dispose)
  5842. asset.dispose();
  5843. delete this.assets[path];
  5844. return asset;
  5845. }
  5846. removeAll() {
  5847. for (let key in this.assets) {
  5848. let asset = this.assets[key];
  5849. if (asset.dispose)
  5850. asset.dispose();
  5851. }
  5852. this.assets = {};
  5853. }
  5854. isLoadingComplete() {
  5855. return this.toLoad == 0;
  5856. }
  5857. getToLoad() {
  5858. return this.toLoad;
  5859. }
  5860. getLoaded() {
  5861. return this.loaded;
  5862. }
  5863. dispose() {
  5864. this.removeAll();
  5865. }
  5866. hasErrors() {
  5867. return Object.keys(this.errors).length > 0;
  5868. }
  5869. getErrors() {
  5870. return this.errors;
  5871. }
  5872. };
  5873. var Downloader = class {
  5874. constructor() {
  5875. this.callbacks = {};
  5876. this.rawDataUris = {};
  5877. }
  5878. dataUriToString(dataUri) {
  5879. if (!dataUri.startsWith("data:")) {
  5880. throw new Error("Not a data URI.");
  5881. }
  5882. let base64Idx = dataUri.indexOf("base64,");
  5883. if (base64Idx != -1) {
  5884. base64Idx += "base64,".length;
  5885. return atob(dataUri.substr(base64Idx));
  5886. } else {
  5887. return dataUri.substr(dataUri.indexOf(",") + 1);
  5888. }
  5889. }
  5890. base64ToUint8Array(base64) {
  5891. var binary_string = window.atob(base64);
  5892. var len = binary_string.length;
  5893. var bytes = new Uint8Array(len);
  5894. for (var i = 0; i < len; i++) {
  5895. bytes[i] = binary_string.charCodeAt(i);
  5896. }
  5897. return bytes;
  5898. }
  5899. dataUriToUint8Array(dataUri) {
  5900. if (!dataUri.startsWith("data:")) {
  5901. throw new Error("Not a data URI.");
  5902. }
  5903. let base64Idx = dataUri.indexOf("base64,");
  5904. if (base64Idx == -1)
  5905. throw new Error("Not a binary data URI.");
  5906. base64Idx += "base64,".length;
  5907. return this.base64ToUint8Array(dataUri.substr(base64Idx));
  5908. }
  5909. downloadText(url, success, error) {
  5910. if (this.start(url, success, error))
  5911. return;
  5912. if (this.rawDataUris[url]) {
  5913. try {
  5914. let dataUri = this.rawDataUris[url];
  5915. this.finish(url, 200, this.dataUriToString(dataUri));
  5916. } catch (e) {
  5917. this.finish(url, 400, JSON.stringify(e));
  5918. }
  5919. return;
  5920. }
  5921. let request = new XMLHttpRequest();
  5922. request.overrideMimeType("text/html");
  5923. request.open("GET", url, true);
  5924. let done = () => {
  5925. this.finish(url, request.status, request.responseText);
  5926. };
  5927. request.onload = done;
  5928. request.onerror = done;
  5929. request.send();
  5930. }
  5931. downloadJson(url, success, error) {
  5932. this.downloadText(url, (data) => {
  5933. success(JSON.parse(data));
  5934. }, error);
  5935. }
  5936. downloadBinary(url, success, error) {
  5937. if (this.start(url, success, error))
  5938. return;
  5939. if (this.rawDataUris[url]) {
  5940. try {
  5941. let dataUri = this.rawDataUris[url];
  5942. this.finish(url, 200, this.dataUriToUint8Array(dataUri));
  5943. } catch (e) {
  5944. this.finish(url, 400, JSON.stringify(e));
  5945. }
  5946. return;
  5947. }
  5948. let request = new XMLHttpRequest();
  5949. request.open("GET", url, true);
  5950. request.responseType = "arraybuffer";
  5951. let onerror = () => {
  5952. this.finish(url, request.status, request.response);
  5953. };
  5954. request.onload = () => {
  5955. if (request.status == 200 || request.status == 0)
  5956. this.finish(url, 200, new Uint8Array(request.response));
  5957. else
  5958. onerror();
  5959. };
  5960. request.onerror = onerror;
  5961. request.send();
  5962. }
  5963. start(url, success, error) {
  5964. let callbacks = this.callbacks[url];
  5965. try {
  5966. if (callbacks)
  5967. return true;
  5968. this.callbacks[url] = callbacks = [];
  5969. } finally {
  5970. callbacks.push(success, error);
  5971. }
  5972. }
  5973. finish(url, status, data) {
  5974. let callbacks = this.callbacks[url];
  5975. delete this.callbacks[url];
  5976. let args = status == 200 || status == 0 ? [data] : [status, data];
  5977. for (let i = args.length - 1, n = callbacks.length; i < n; i += 2)
  5978. callbacks[i].apply(null, args);
  5979. }
  5980. };
  5981. // spine-core/src/Event.ts
  5982. var Event = class {
  5983. constructor(time, data) {
  5984. this.intValue = 0;
  5985. this.floatValue = 0;
  5986. this.stringValue = null;
  5987. this.time = 0;
  5988. this.volume = 0;
  5989. this.balance = 0;
  5990. if (!data)
  5991. throw new Error("data cannot be null.");
  5992. this.time = time;
  5993. this.data = data;
  5994. }
  5995. };
  5996. // spine-core/src/EventData.ts
  5997. var EventData = class {
  5998. constructor(name) {
  5999. this.intValue = 0;
  6000. this.floatValue = 0;
  6001. this.stringValue = null;
  6002. this.audioPath = null;
  6003. this.volume = 0;
  6004. this.balance = 0;
  6005. this.name = name;
  6006. }
  6007. };
  6008. // spine-core/src/IkConstraint.ts
  6009. var IkConstraint = class {
  6010. constructor(data, skeleton) {
  6011. /** Controls the bend direction of the IK bones, either 1 or -1. */
  6012. this.bendDirection = 0;
  6013. /** When true and only a single bone is being constrained, if the target is too close, the bone is scaled to reach it. */
  6014. this.compress = false;
  6015. /** When true, if the target is out of range, the parent bone is scaled to reach it. If more than one bone is being constrained
  6016. * and the parent bone has local nonuniform scale, stretch is not applied. */
  6017. this.stretch = false;
  6018. /** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
  6019. this.mix = 1;
  6020. /** For two bone IK, the distance from the maximum reach of the bones that rotation will slow. */
  6021. this.softness = 0;
  6022. this.active = false;
  6023. if (!data)
  6024. throw new Error("data cannot be null.");
  6025. if (!skeleton)
  6026. throw new Error("skeleton cannot be null.");
  6027. this.data = data;
  6028. this.mix = data.mix;
  6029. this.softness = data.softness;
  6030. this.bendDirection = data.bendDirection;
  6031. this.compress = data.compress;
  6032. this.stretch = data.stretch;
  6033. this.bones = new Array();
  6034. for (let i = 0; i < data.bones.length; i++) {
  6035. let bone = skeleton.findBone(data.bones[i].name);
  6036. if (!bone)
  6037. throw new Error(`Couldn't find bone ${data.bones[i].name}`);
  6038. this.bones.push(bone);
  6039. }
  6040. let target = skeleton.findBone(data.target.name);
  6041. if (!target)
  6042. throw new Error(`Couldn't find bone ${data.target.name}`);
  6043. this.target = target;
  6044. }
  6045. isActive() {
  6046. return this.active;
  6047. }
  6048. update() {
  6049. if (this.mix == 0)
  6050. return;
  6051. let target = this.target;
  6052. let bones = this.bones;
  6053. switch (bones.length) {
  6054. case 1:
  6055. this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix);
  6056. break;
  6057. case 2:
  6058. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.data.uniform, this.softness, this.mix);
  6059. break;
  6060. }
  6061. }
  6062. /** Applies 1 bone IK. The target is specified in the world coordinate system. */
  6063. apply1(bone, targetX, targetY, compress, stretch, uniform, alpha) {
  6064. let p = bone.parent;
  6065. if (!p)
  6066. throw new Error("IK bone must have parent.");
  6067. let pa = p.a, pb = p.b, pc = p.c, pd = p.d;
  6068. let rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
  6069. switch (bone.data.transformMode) {
  6070. case 1 /* OnlyTranslation */:
  6071. tx = targetX - bone.worldX;
  6072. ty = targetY - bone.worldY;
  6073. break;
  6074. case 2 /* NoRotationOrReflection */:
  6075. let s = Math.abs(pa * pd - pb * pc) / Math.max(1e-4, pa * pa + pc * pc);
  6076. let sa = pa / bone.skeleton.scaleX;
  6077. let sc = pc / bone.skeleton.scaleY;
  6078. pb = -sc * s * bone.skeleton.scaleX;
  6079. pd = sa * s * bone.skeleton.scaleY;
  6080. rotationIK += Math.atan2(sc, sa) * MathUtils.radDeg;
  6081. default:
  6082. let x = targetX - p.worldX, y = targetY - p.worldY;
  6083. let d = pa * pd - pb * pc;
  6084. if (Math.abs(d) <= 1e-4) {
  6085. tx = 0;
  6086. ty = 0;
  6087. } else {
  6088. tx = (x * pd - y * pb) / d - bone.ax;
  6089. ty = (y * pa - x * pc) / d - bone.ay;
  6090. }
  6091. }
  6092. rotationIK += Math.atan2(ty, tx) * MathUtils.radDeg;
  6093. if (bone.ascaleX < 0)
  6094. rotationIK += 180;
  6095. if (rotationIK > 180)
  6096. rotationIK -= 360;
  6097. else if (rotationIK < -180)
  6098. rotationIK += 360;
  6099. let sx = bone.ascaleX, sy = bone.ascaleY;
  6100. if (compress || stretch) {
  6101. switch (bone.data.transformMode) {
  6102. case 3 /* NoScale */:
  6103. case 4 /* NoScaleOrReflection */:
  6104. tx = targetX - bone.worldX;
  6105. ty = targetY - bone.worldY;
  6106. }
  6107. let b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
  6108. if (compress && dd < b || stretch && dd > b && b > 1e-4) {
  6109. let s = (dd / b - 1) * alpha + 1;
  6110. sx *= s;
  6111. if (uniform)
  6112. sy *= s;
  6113. }
  6114. }
  6115. bone.updateWorldTransformWith(
  6116. bone.ax,
  6117. bone.ay,
  6118. bone.arotation + rotationIK * alpha,
  6119. sx,
  6120. sy,
  6121. bone.ashearX,
  6122. bone.ashearY
  6123. );
  6124. }
  6125. /** Applies 2 bone IK. The target is specified in the world coordinate system.
  6126. * @param child A direct descendant of the parent bone. */
  6127. apply2(parent, child, targetX, targetY, bendDir, stretch, uniform, softness, alpha) {
  6128. let px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, sx = psx, sy = psy, csx = child.ascaleX;
  6129. let os1 = 0, os2 = 0, s2 = 0;
  6130. if (psx < 0) {
  6131. psx = -psx;
  6132. os1 = 180;
  6133. s2 = -1;
  6134. } else {
  6135. os1 = 0;
  6136. s2 = 1;
  6137. }
  6138. if (psy < 0) {
  6139. psy = -psy;
  6140. s2 = -s2;
  6141. }
  6142. if (csx < 0) {
  6143. csx = -csx;
  6144. os2 = 180;
  6145. } else
  6146. os2 = 0;
  6147. let cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
  6148. let u = Math.abs(psx - psy) <= 1e-4;
  6149. if (!u || stretch) {
  6150. cy = 0;
  6151. cwx = a * cx + parent.worldX;
  6152. cwy = c * cx + parent.worldY;
  6153. } else {
  6154. cy = child.ay;
  6155. cwx = a * cx + b * cy + parent.worldX;
  6156. cwy = c * cx + d * cy + parent.worldY;
  6157. }
  6158. let pp = parent.parent;
  6159. if (!pp)
  6160. throw new Error("IK parent must itself have a parent.");
  6161. a = pp.a;
  6162. b = pp.b;
  6163. c = pp.c;
  6164. d = pp.d;
  6165. let id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY;
  6166. id = Math.abs(id) <= 1e-4 ? 0 : 1 / id;
  6167. let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  6168. let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
  6169. if (l1 < 1e-4) {
  6170. this.apply1(parent, targetX, targetY, false, stretch, false, alpha);
  6171. child.updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  6172. return;
  6173. }
  6174. x = targetX - pp.worldX;
  6175. y = targetY - pp.worldY;
  6176. let tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  6177. let dd = tx * tx + ty * ty;
  6178. if (softness != 0) {
  6179. softness *= psx * (csx + 1) * 0.5;
  6180. let td = Math.sqrt(dd), sd = td - l1 - l2 * psx + softness;
  6181. if (sd > 0) {
  6182. let p = Math.min(1, sd / (softness * 2)) - 1;
  6183. p = (sd - softness * (1 - p * p)) / td;
  6184. tx -= p * tx;
  6185. ty -= p * ty;
  6186. dd = tx * tx + ty * ty;
  6187. }
  6188. }
  6189. outer:
  6190. if (u) {
  6191. l2 *= psx;
  6192. let cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  6193. if (cos < -1) {
  6194. cos = -1;
  6195. a2 = Math.PI * bendDir;
  6196. } else if (cos > 1) {
  6197. cos = 1;
  6198. a2 = 0;
  6199. if (stretch) {
  6200. a = (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
  6201. sx *= a;
  6202. if (uniform)
  6203. sy *= a;
  6204. }
  6205. } else
  6206. a2 = Math.acos(cos) * bendDir;
  6207. a = l1 + l2 * cos;
  6208. b = l2 * Math.sin(a2);
  6209. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  6210. } else {
  6211. a = psx * l2;
  6212. b = psy * l2;
  6213. let aa = a * a, bb = b * b, ta = Math.atan2(ty, tx);
  6214. c = bb * l1 * l1 + aa * dd - aa * bb;
  6215. let c1 = -2 * bb * l1, c2 = bb - aa;
  6216. d = c1 * c1 - 4 * c2 * c;
  6217. if (d >= 0) {
  6218. let q = Math.sqrt(d);
  6219. if (c1 < 0)
  6220. q = -q;
  6221. q = -(c1 + q) * 0.5;
  6222. let r0 = q / c2, r1 = c / q;
  6223. let r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  6224. if (r * r <= dd) {
  6225. y = Math.sqrt(dd - r * r) * bendDir;
  6226. a1 = ta - Math.atan2(y, r);
  6227. a2 = Math.atan2(y / psy, (r - l1) / psx);
  6228. break outer;
  6229. }
  6230. }
  6231. let minAngle = MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  6232. let maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  6233. c = -a * l1 / (aa - bb);
  6234. if (c >= -1 && c <= 1) {
  6235. c = Math.acos(c);
  6236. x = a * Math.cos(c) + l1;
  6237. y = b * Math.sin(c);
  6238. d = x * x + y * y;
  6239. if (d < minDist) {
  6240. minAngle = c;
  6241. minDist = d;
  6242. minX = x;
  6243. minY = y;
  6244. }
  6245. if (d > maxDist) {
  6246. maxAngle = c;
  6247. maxDist = d;
  6248. maxX = x;
  6249. maxY = y;
  6250. }
  6251. }
  6252. if (dd <= (minDist + maxDist) * 0.5) {
  6253. a1 = ta - Math.atan2(minY * bendDir, minX);
  6254. a2 = minAngle * bendDir;
  6255. } else {
  6256. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  6257. a2 = maxAngle * bendDir;
  6258. }
  6259. }
  6260. let os = Math.atan2(cy, cx) * s2;
  6261. let rotation = parent.arotation;
  6262. a1 = (a1 - os) * MathUtils.radDeg + os1 - rotation;
  6263. if (a1 > 180)
  6264. a1 -= 360;
  6265. else if (a1 < -180)
  6266. a1 += 360;
  6267. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, sy, 0, 0);
  6268. rotation = child.arotation;
  6269. a2 = ((a2 + os) * MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  6270. if (a2 > 180)
  6271. a2 -= 360;
  6272. else if (a2 < -180)
  6273. a2 += 360;
  6274. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  6275. }
  6276. };
  6277. // spine-core/src/IkConstraintData.ts
  6278. var IkConstraintData = class extends ConstraintData {
  6279. constructor(name) {
  6280. super(name, 0, false);
  6281. /** The bones that are constrained by this IK constraint. */
  6282. this.bones = new Array();
  6283. /** The bone that is the IK target. */
  6284. this._target = null;
  6285. /** Controls the bend direction of the IK bones, either 1 or -1. */
  6286. this.bendDirection = 1;
  6287. /** When true and only a single bone is being constrained, if the target is too close, the bone is scaled to reach it. */
  6288. this.compress = false;
  6289. /** When true, if the target is out of range, the parent bone is scaled to reach it. If more than one bone is being constrained
  6290. * and the parent bone has local nonuniform scale, stretch is not applied. */
  6291. this.stretch = false;
  6292. /** When true, only a single bone is being constrained, and {@link #getCompress()} or {@link #getStretch()} is used, the bone
  6293. * is scaled on both the X and Y axes. */
  6294. this.uniform = false;
  6295. /** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
  6296. this.mix = 1;
  6297. /** For two bone IK, the distance from the maximum reach of the bones that rotation will slow. */
  6298. this.softness = 0;
  6299. }
  6300. set target(boneData) {
  6301. this._target = boneData;
  6302. }
  6303. get target() {
  6304. if (!this._target)
  6305. throw new Error("BoneData not set.");
  6306. else
  6307. return this._target;
  6308. }
  6309. };
  6310. // spine-core/src/PathConstraintData.ts
  6311. var PathConstraintData = class extends ConstraintData {
  6312. constructor(name) {
  6313. super(name, 0, false);
  6314. /** The bones that will be modified by this path constraint. */
  6315. this.bones = new Array();
  6316. /** The slot whose path attachment will be used to constrained the bones. */
  6317. this._target = null;
  6318. /** The mode for positioning the first bone on the path. */
  6319. this.positionMode = PositionMode.Fixed;
  6320. /** The mode for positioning the bones after the first bone on the path. */
  6321. this.spacingMode = SpacingMode.Fixed;
  6322. /** The mode for adjusting the rotation of the bones. */
  6323. this.rotateMode = RotateMode.Chain;
  6324. /** An offset added to the constrained bone rotation. */
  6325. this.offsetRotation = 0;
  6326. /** The position along the path. */
  6327. this.position = 0;
  6328. /** The spacing between bones. */
  6329. this.spacing = 0;
  6330. this.mixRotate = 0;
  6331. this.mixX = 0;
  6332. this.mixY = 0;
  6333. }
  6334. set target(slotData) {
  6335. this._target = slotData;
  6336. }
  6337. get target() {
  6338. if (!this._target)
  6339. throw new Error("SlotData not set.");
  6340. else
  6341. return this._target;
  6342. }
  6343. };
  6344. var PositionMode = /* @__PURE__ */ ((PositionMode2) => {
  6345. PositionMode2[PositionMode2["Fixed"] = 0] = "Fixed";
  6346. PositionMode2[PositionMode2["Percent"] = 1] = "Percent";
  6347. return PositionMode2;
  6348. })(PositionMode || {});
  6349. var SpacingMode = /* @__PURE__ */ ((SpacingMode2) => {
  6350. SpacingMode2[SpacingMode2["Length"] = 0] = "Length";
  6351. SpacingMode2[SpacingMode2["Fixed"] = 1] = "Fixed";
  6352. SpacingMode2[SpacingMode2["Percent"] = 2] = "Percent";
  6353. SpacingMode2[SpacingMode2["Proportional"] = 3] = "Proportional";
  6354. return SpacingMode2;
  6355. })(SpacingMode || {});
  6356. var RotateMode = /* @__PURE__ */ ((RotateMode2) => {
  6357. RotateMode2[RotateMode2["Tangent"] = 0] = "Tangent";
  6358. RotateMode2[RotateMode2["Chain"] = 1] = "Chain";
  6359. RotateMode2[RotateMode2["ChainScale"] = 2] = "ChainScale";
  6360. return RotateMode2;
  6361. })(RotateMode || {});
  6362. // spine-core/src/PathConstraint.ts
  6363. var _PathConstraint = class {
  6364. constructor(data, skeleton) {
  6365. /** The position along the path. */
  6366. this.position = 0;
  6367. /** The spacing between bones. */
  6368. this.spacing = 0;
  6369. this.mixRotate = 0;
  6370. this.mixX = 0;
  6371. this.mixY = 0;
  6372. this.spaces = new Array();
  6373. this.positions = new Array();
  6374. this.world = new Array();
  6375. this.curves = new Array();
  6376. this.lengths = new Array();
  6377. this.segments = new Array();
  6378. this.active = false;
  6379. if (!data)
  6380. throw new Error("data cannot be null.");
  6381. if (!skeleton)
  6382. throw new Error("skeleton cannot be null.");
  6383. this.data = data;
  6384. this.bones = new Array();
  6385. for (let i = 0, n = data.bones.length; i < n; i++) {
  6386. let bone = skeleton.findBone(data.bones[i].name);
  6387. if (!bone)
  6388. throw new Error(`Couldn't find bone ${data.bones[i].name}.`);
  6389. this.bones.push(bone);
  6390. }
  6391. let target = skeleton.findSlot(data.target.name);
  6392. if (!target)
  6393. throw new Error(`Couldn't find target bone ${data.target.name}`);
  6394. this.target = target;
  6395. this.position = data.position;
  6396. this.spacing = data.spacing;
  6397. this.mixRotate = data.mixRotate;
  6398. this.mixX = data.mixX;
  6399. this.mixY = data.mixY;
  6400. }
  6401. isActive() {
  6402. return this.active;
  6403. }
  6404. update() {
  6405. let attachment = this.target.getAttachment();
  6406. if (!(attachment instanceof PathAttachment))
  6407. return;
  6408. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY;
  6409. if (mixRotate == 0 && mixX == 0 && mixY == 0)
  6410. return;
  6411. let data = this.data;
  6412. let tangents = data.rotateMode == 0 /* Tangent */, scale = data.rotateMode == 2 /* ChainScale */;
  6413. let bones = this.bones;
  6414. let boneCount = bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  6415. let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths = scale ? this.lengths = Utils.setArraySize(this.lengths, boneCount) : [];
  6416. let spacing = this.spacing;
  6417. switch (data.spacingMode) {
  6418. case 2 /* Percent */:
  6419. if (scale) {
  6420. for (let i = 0, n = spacesCount - 1; i < n; i++) {
  6421. let bone = bones[i];
  6422. let setupLength = bone.data.length;
  6423. if (setupLength < _PathConstraint.epsilon)
  6424. lengths[i] = 0;
  6425. else {
  6426. let x = setupLength * bone.a, y = setupLength * bone.c;
  6427. lengths[i] = Math.sqrt(x * x + y * y);
  6428. }
  6429. }
  6430. }
  6431. Utils.arrayFill(spaces, 1, spacesCount, spacing);
  6432. break;
  6433. case 3 /* Proportional */:
  6434. let sum = 0;
  6435. for (let i = 0, n = spacesCount - 1; i < n; ) {
  6436. let bone = bones[i];
  6437. let setupLength = bone.data.length;
  6438. if (setupLength < _PathConstraint.epsilon) {
  6439. if (scale)
  6440. lengths[i] = 0;
  6441. spaces[++i] = spacing;
  6442. } else {
  6443. let x = setupLength * bone.a, y = setupLength * bone.c;
  6444. let length = Math.sqrt(x * x + y * y);
  6445. if (scale)
  6446. lengths[i] = length;
  6447. spaces[++i] = length;
  6448. sum += length;
  6449. }
  6450. }
  6451. if (sum > 0) {
  6452. sum = spacesCount / sum * spacing;
  6453. for (let i = 1; i < spacesCount; i++)
  6454. spaces[i] *= sum;
  6455. }
  6456. break;
  6457. default:
  6458. let lengthSpacing = data.spacingMode == 0 /* Length */;
  6459. for (let i = 0, n = spacesCount - 1; i < n; ) {
  6460. let bone = bones[i];
  6461. let setupLength = bone.data.length;
  6462. if (setupLength < _PathConstraint.epsilon) {
  6463. if (scale)
  6464. lengths[i] = 0;
  6465. spaces[++i] = spacing;
  6466. } else {
  6467. let x = setupLength * bone.a, y = setupLength * bone.c;
  6468. let length = Math.sqrt(x * x + y * y);
  6469. if (scale)
  6470. lengths[i] = length;
  6471. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
  6472. }
  6473. }
  6474. }
  6475. let positions = this.computeWorldPositions(attachment, spacesCount, tangents);
  6476. let boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  6477. let tip = false;
  6478. if (offsetRotation == 0)
  6479. tip = data.rotateMode == 1 /* Chain */;
  6480. else {
  6481. tip = false;
  6482. let p = this.target.bone;
  6483. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.degRad : -MathUtils.degRad;
  6484. }
  6485. for (let i = 0, p = 3; i < boneCount; i++, p += 3) {
  6486. let bone = bones[i];
  6487. bone.worldX += (boneX - bone.worldX) * mixX;
  6488. bone.worldY += (boneY - bone.worldY) * mixY;
  6489. let x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  6490. if (scale) {
  6491. let length = lengths[i];
  6492. if (length != 0) {
  6493. let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1;
  6494. bone.a *= s;
  6495. bone.c *= s;
  6496. }
  6497. }
  6498. boneX = x;
  6499. boneY = y;
  6500. if (mixRotate > 0) {
  6501. let a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
  6502. if (tangents)
  6503. r = positions[p - 1];
  6504. else if (spaces[i + 1] == 0)
  6505. r = positions[p + 2];
  6506. else
  6507. r = Math.atan2(dy, dx);
  6508. r -= Math.atan2(c, a);
  6509. if (tip) {
  6510. cos = Math.cos(r);
  6511. sin = Math.sin(r);
  6512. let length = bone.data.length;
  6513. boneX += (length * (cos * a - sin * c) - dx) * mixRotate;
  6514. boneY += (length * (sin * a + cos * c) - dy) * mixRotate;
  6515. } else {
  6516. r += offsetRotation;
  6517. }
  6518. if (r > MathUtils.PI)
  6519. r -= MathUtils.PI2;
  6520. else if (r < -MathUtils.PI)
  6521. r += MathUtils.PI2;
  6522. r *= mixRotate;
  6523. cos = Math.cos(r);
  6524. sin = Math.sin(r);
  6525. bone.a = cos * a - sin * c;
  6526. bone.b = cos * b - sin * d;
  6527. bone.c = sin * a + cos * c;
  6528. bone.d = sin * b + cos * d;
  6529. }
  6530. bone.updateAppliedTransform();
  6531. }
  6532. }
  6533. computeWorldPositions(path, spacesCount, tangents) {
  6534. let target = this.target;
  6535. let position = this.position;
  6536. let spaces = this.spaces, out = Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = this.world;
  6537. let closed2 = path.closed;
  6538. let verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = _PathConstraint.NONE;
  6539. if (!path.constantSpeed) {
  6540. let lengths = path.lengths;
  6541. curveCount -= closed2 ? 1 : 2;
  6542. let pathLength2 = lengths[curveCount];
  6543. if (this.data.positionMode == 1 /* Percent */)
  6544. position *= pathLength2;
  6545. let multiplier2;
  6546. switch (this.data.spacingMode) {
  6547. case 2 /* Percent */:
  6548. multiplier2 = pathLength2;
  6549. break;
  6550. case 3 /* Proportional */:
  6551. multiplier2 = pathLength2 / spacesCount;
  6552. break;
  6553. default:
  6554. multiplier2 = 1;
  6555. }
  6556. world = Utils.setArraySize(this.world, 8);
  6557. for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  6558. let space = spaces[i] * multiplier2;
  6559. position += space;
  6560. let p = position;
  6561. if (closed2) {
  6562. p %= pathLength2;
  6563. if (p < 0)
  6564. p += pathLength2;
  6565. curve = 0;
  6566. } else if (p < 0) {
  6567. if (prevCurve != _PathConstraint.BEFORE) {
  6568. prevCurve = _PathConstraint.BEFORE;
  6569. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  6570. }
  6571. this.addBeforePosition(p, world, 0, out, o);
  6572. continue;
  6573. } else if (p > pathLength2) {
  6574. if (prevCurve != _PathConstraint.AFTER) {
  6575. prevCurve = _PathConstraint.AFTER;
  6576. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  6577. }
  6578. this.addAfterPosition(p - pathLength2, world, 0, out, o);
  6579. continue;
  6580. }
  6581. for (; ; curve++) {
  6582. let length = lengths[curve];
  6583. if (p > length)
  6584. continue;
  6585. if (curve == 0)
  6586. p /= length;
  6587. else {
  6588. let prev = lengths[curve - 1];
  6589. p = (p - prev) / (length - prev);
  6590. }
  6591. break;
  6592. }
  6593. if (curve != prevCurve) {
  6594. prevCurve = curve;
  6595. if (closed2 && curve == curveCount) {
  6596. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  6597. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  6598. } else
  6599. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  6600. }
  6601. this.addCurvePosition(
  6602. p,
  6603. world[0],
  6604. world[1],
  6605. world[2],
  6606. world[3],
  6607. world[4],
  6608. world[5],
  6609. world[6],
  6610. world[7],
  6611. out,
  6612. o,
  6613. tangents || i > 0 && space == 0
  6614. );
  6615. }
  6616. return out;
  6617. }
  6618. if (closed2) {
  6619. verticesLength += 2;
  6620. world = Utils.setArraySize(this.world, verticesLength);
  6621. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  6622. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  6623. world[verticesLength - 2] = world[0];
  6624. world[verticesLength - 1] = world[1];
  6625. } else {
  6626. curveCount--;
  6627. verticesLength -= 4;
  6628. world = Utils.setArraySize(this.world, verticesLength);
  6629. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  6630. }
  6631. let curves = Utils.setArraySize(this.curves, curveCount);
  6632. let pathLength = 0;
  6633. let x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  6634. let tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  6635. for (let i = 0, w = 2; i < curveCount; i++, w += 6) {
  6636. cx1 = world[w];
  6637. cy1 = world[w + 1];
  6638. cx2 = world[w + 2];
  6639. cy2 = world[w + 3];
  6640. x2 = world[w + 4];
  6641. y2 = world[w + 5];
  6642. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  6643. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  6644. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  6645. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  6646. ddfx = tmpx * 2 + dddfx;
  6647. ddfy = tmpy * 2 + dddfy;
  6648. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  6649. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  6650. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6651. dfx += ddfx;
  6652. dfy += ddfy;
  6653. ddfx += dddfx;
  6654. ddfy += dddfy;
  6655. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6656. dfx += ddfx;
  6657. dfy += ddfy;
  6658. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6659. dfx += ddfx + dddfx;
  6660. dfy += ddfy + dddfy;
  6661. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6662. curves[i] = pathLength;
  6663. x1 = x2;
  6664. y1 = y2;
  6665. }
  6666. if (this.data.positionMode == 1 /* Percent */)
  6667. position *= pathLength;
  6668. let multiplier;
  6669. switch (this.data.spacingMode) {
  6670. case 2 /* Percent */:
  6671. multiplier = pathLength;
  6672. break;
  6673. case 3 /* Proportional */:
  6674. multiplier = pathLength / spacesCount;
  6675. break;
  6676. default:
  6677. multiplier = 1;
  6678. }
  6679. let segments = this.segments;
  6680. let curveLength = 0;
  6681. for (let i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  6682. let space = spaces[i] * multiplier;
  6683. position += space;
  6684. let p = position;
  6685. if (closed2) {
  6686. p %= pathLength;
  6687. if (p < 0)
  6688. p += pathLength;
  6689. curve = 0;
  6690. } else if (p < 0) {
  6691. this.addBeforePosition(p, world, 0, out, o);
  6692. continue;
  6693. } else if (p > pathLength) {
  6694. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  6695. continue;
  6696. }
  6697. for (; ; curve++) {
  6698. let length = curves[curve];
  6699. if (p > length)
  6700. continue;
  6701. if (curve == 0)
  6702. p /= length;
  6703. else {
  6704. let prev = curves[curve - 1];
  6705. p = (p - prev) / (length - prev);
  6706. }
  6707. break;
  6708. }
  6709. if (curve != prevCurve) {
  6710. prevCurve = curve;
  6711. let ii = curve * 6;
  6712. x1 = world[ii];
  6713. y1 = world[ii + 1];
  6714. cx1 = world[ii + 2];
  6715. cy1 = world[ii + 3];
  6716. cx2 = world[ii + 4];
  6717. cy2 = world[ii + 5];
  6718. x2 = world[ii + 6];
  6719. y2 = world[ii + 7];
  6720. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  6721. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  6722. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 6e-3;
  6723. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 6e-3;
  6724. ddfx = tmpx * 2 + dddfx;
  6725. ddfy = tmpy * 2 + dddfy;
  6726. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  6727. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  6728. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  6729. segments[0] = curveLength;
  6730. for (ii = 1; ii < 8; ii++) {
  6731. dfx += ddfx;
  6732. dfy += ddfy;
  6733. ddfx += dddfx;
  6734. ddfy += dddfy;
  6735. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6736. segments[ii] = curveLength;
  6737. }
  6738. dfx += ddfx;
  6739. dfy += ddfy;
  6740. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6741. segments[8] = curveLength;
  6742. dfx += ddfx + dddfx;
  6743. dfy += ddfy + dddfy;
  6744. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  6745. segments[9] = curveLength;
  6746. segment = 0;
  6747. }
  6748. p *= curveLength;
  6749. for (; ; segment++) {
  6750. let length = segments[segment];
  6751. if (p > length)
  6752. continue;
  6753. if (segment == 0)
  6754. p /= length;
  6755. else {
  6756. let prev = segments[segment - 1];
  6757. p = segment + (p - prev) / (length - prev);
  6758. }
  6759. break;
  6760. }
  6761. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || i > 0 && space == 0);
  6762. }
  6763. return out;
  6764. }
  6765. addBeforePosition(p, temp, i, out, o) {
  6766. let x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  6767. out[o] = x1 + p * Math.cos(r);
  6768. out[o + 1] = y1 + p * Math.sin(r);
  6769. out[o + 2] = r;
  6770. }
  6771. addAfterPosition(p, temp, i, out, o) {
  6772. let x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  6773. out[o] = x1 + p * Math.cos(r);
  6774. out[o + 1] = y1 + p * Math.sin(r);
  6775. out[o + 2] = r;
  6776. }
  6777. addCurvePosition(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  6778. if (p == 0 || isNaN(p)) {
  6779. out[o] = x1;
  6780. out[o + 1] = y1;
  6781. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  6782. return;
  6783. }
  6784. let tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  6785. let ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  6786. let x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  6787. out[o] = x;
  6788. out[o + 1] = y;
  6789. if (tangents) {
  6790. if (p < 1e-3)
  6791. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  6792. else
  6793. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  6794. }
  6795. }
  6796. };
  6797. var PathConstraint = _PathConstraint;
  6798. PathConstraint.NONE = -1;
  6799. PathConstraint.BEFORE = -2;
  6800. PathConstraint.AFTER = -3;
  6801. PathConstraint.epsilon = 1e-5;
  6802. // spine-core/src/Slot.ts
  6803. var Slot = class {
  6804. constructor(data, bone) {
  6805. /** The dark color used to tint the slot's attachment for two color tinting, or null if two color tinting is not used. The dark
  6806. * color's alpha is not used. */
  6807. this.darkColor = null;
  6808. this.attachment = null;
  6809. this.attachmentState = 0;
  6810. /** The index of the texture region to display when the slot's attachment has a {@link Sequence}. -1 represents the
  6811. * {@link Sequence#getSetupIndex()}. */
  6812. this.sequenceIndex = -1;
  6813. /** Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a
  6814. * weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions.
  6815. *
  6816. * See {@link VertexAttachment#computeWorldVertices()} and {@link DeformTimeline}. */
  6817. this.deform = new Array();
  6818. if (!data)
  6819. throw new Error("data cannot be null.");
  6820. if (!bone)
  6821. throw new Error("bone cannot be null.");
  6822. this.data = data;
  6823. this.bone = bone;
  6824. this.color = new Color();
  6825. this.darkColor = !data.darkColor ? null : new Color();
  6826. this.setToSetupPose();
  6827. }
  6828. /** The skeleton this slot belongs to. */
  6829. getSkeleton() {
  6830. return this.bone.skeleton;
  6831. }
  6832. /** The current attachment for the slot, or null if the slot has no attachment. */
  6833. getAttachment() {
  6834. return this.attachment;
  6835. }
  6836. /** Sets the slot's attachment and, if the attachment changed, resets {@link #sequenceIndex} and clears the {@link #deform}.
  6837. * The deform is not cleared if the old attachment has the same {@link VertexAttachment#getTimelineAttachment()} as the
  6838. * specified attachment. */
  6839. setAttachment(attachment) {
  6840. if (this.attachment == attachment)
  6841. return;
  6842. if (!(attachment instanceof VertexAttachment) || !(this.attachment instanceof VertexAttachment) || attachment.timelineAttachment != this.attachment.timelineAttachment) {
  6843. this.deform.length = 0;
  6844. }
  6845. this.attachment = attachment;
  6846. this.sequenceIndex = -1;
  6847. }
  6848. /** Sets this slot to the setup pose. */
  6849. setToSetupPose() {
  6850. this.color.setFromColor(this.data.color);
  6851. if (this.darkColor)
  6852. this.darkColor.setFromColor(this.data.darkColor);
  6853. if (!this.data.attachmentName)
  6854. this.attachment = null;
  6855. else {
  6856. this.attachment = null;
  6857. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  6858. }
  6859. }
  6860. };
  6861. // spine-core/src/TransformConstraint.ts
  6862. var TransformConstraint = class {
  6863. constructor(data, skeleton) {
  6864. this.mixRotate = 0;
  6865. this.mixX = 0;
  6866. this.mixY = 0;
  6867. this.mixScaleX = 0;
  6868. this.mixScaleY = 0;
  6869. this.mixShearY = 0;
  6870. this.temp = new Vector2();
  6871. this.active = false;
  6872. if (!data)
  6873. throw new Error("data cannot be null.");
  6874. if (!skeleton)
  6875. throw new Error("skeleton cannot be null.");
  6876. this.data = data;
  6877. this.mixRotate = data.mixRotate;
  6878. this.mixX = data.mixX;
  6879. this.mixY = data.mixY;
  6880. this.mixScaleX = data.mixScaleX;
  6881. this.mixScaleY = data.mixScaleY;
  6882. this.mixShearY = data.mixShearY;
  6883. this.bones = new Array();
  6884. for (let i = 0; i < data.bones.length; i++) {
  6885. let bone = skeleton.findBone(data.bones[i].name);
  6886. if (!bone)
  6887. throw new Error(`Couldn't find bone ${data.bones[i].name}.`);
  6888. this.bones.push(bone);
  6889. }
  6890. let target = skeleton.findBone(data.target.name);
  6891. if (!target)
  6892. throw new Error(`Couldn't find target bone ${data.target.name}.`);
  6893. this.target = target;
  6894. }
  6895. isActive() {
  6896. return this.active;
  6897. }
  6898. update() {
  6899. if (this.mixRotate == 0 && this.mixX == 0 && this.mixY == 0 && this.mixScaleX == 0 && this.mixScaleY == 0 && this.mixShearY == 0)
  6900. return;
  6901. if (this.data.local) {
  6902. if (this.data.relative)
  6903. this.applyRelativeLocal();
  6904. else
  6905. this.applyAbsoluteLocal();
  6906. } else {
  6907. if (this.data.relative)
  6908. this.applyRelativeWorld();
  6909. else
  6910. this.applyAbsoluteWorld();
  6911. }
  6912. }
  6913. applyAbsoluteWorld() {
  6914. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  6915. let translate = mixX != 0 || mixY != 0;
  6916. let target = this.target;
  6917. let ta = target.a, tb = target.b, tc = target.c, td = target.d;
  6918. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  6919. let offsetRotation = this.data.offsetRotation * degRadReflect;
  6920. let offsetShearY = this.data.offsetShearY * degRadReflect;
  6921. let bones = this.bones;
  6922. for (let i = 0, n = bones.length; i < n; i++) {
  6923. let bone = bones[i];
  6924. if (mixRotate != 0) {
  6925. let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6926. let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  6927. if (r > MathUtils.PI)
  6928. r -= MathUtils.PI2;
  6929. else if (r < -MathUtils.PI)
  6930. r += MathUtils.PI2;
  6931. r *= mixRotate;
  6932. let cos = Math.cos(r), sin = Math.sin(r);
  6933. bone.a = cos * a - sin * c;
  6934. bone.b = cos * b - sin * d;
  6935. bone.c = sin * a + cos * c;
  6936. bone.d = sin * b + cos * d;
  6937. }
  6938. if (translate) {
  6939. let temp = this.temp;
  6940. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  6941. bone.worldX += (temp.x - bone.worldX) * mixX;
  6942. bone.worldY += (temp.y - bone.worldY) * mixY;
  6943. }
  6944. if (mixScaleX != 0) {
  6945. let s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
  6946. if (s != 0)
  6947. s = (s + (Math.sqrt(ta * ta + tc * tc) - s + this.data.offsetScaleX) * mixScaleX) / s;
  6948. bone.a *= s;
  6949. bone.c *= s;
  6950. }
  6951. if (mixScaleY != 0) {
  6952. let s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
  6953. if (s != 0)
  6954. s = (s + (Math.sqrt(tb * tb + td * td) - s + this.data.offsetScaleY) * mixScaleY) / s;
  6955. bone.b *= s;
  6956. bone.d *= s;
  6957. }
  6958. if (mixShearY > 0) {
  6959. let b = bone.b, d = bone.d;
  6960. let by = Math.atan2(d, b);
  6961. let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
  6962. if (r > MathUtils.PI)
  6963. r -= MathUtils.PI2;
  6964. else if (r < -MathUtils.PI)
  6965. r += MathUtils.PI2;
  6966. r = by + (r + offsetShearY) * mixShearY;
  6967. let s = Math.sqrt(b * b + d * d);
  6968. bone.b = Math.cos(r) * s;
  6969. bone.d = Math.sin(r) * s;
  6970. }
  6971. bone.updateAppliedTransform();
  6972. }
  6973. }
  6974. applyRelativeWorld() {
  6975. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  6976. let translate = mixX != 0 || mixY != 0;
  6977. let target = this.target;
  6978. let ta = target.a, tb = target.b, tc = target.c, td = target.d;
  6979. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  6980. let offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  6981. let bones = this.bones;
  6982. for (let i = 0, n = bones.length; i < n; i++) {
  6983. let bone = bones[i];
  6984. if (mixRotate != 0) {
  6985. let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6986. let r = Math.atan2(tc, ta) + offsetRotation;
  6987. if (r > MathUtils.PI)
  6988. r -= MathUtils.PI2;
  6989. else if (r < -MathUtils.PI)
  6990. r += MathUtils.PI2;
  6991. r *= mixRotate;
  6992. let cos = Math.cos(r), sin = Math.sin(r);
  6993. bone.a = cos * a - sin * c;
  6994. bone.b = cos * b - sin * d;
  6995. bone.c = sin * a + cos * c;
  6996. bone.d = sin * b + cos * d;
  6997. }
  6998. if (translate) {
  6999. let temp = this.temp;
  7000. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  7001. bone.worldX += temp.x * mixX;
  7002. bone.worldY += temp.y * mixY;
  7003. }
  7004. if (mixScaleX != 0) {
  7005. let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * mixScaleX + 1;
  7006. bone.a *= s;
  7007. bone.c *= s;
  7008. }
  7009. if (mixScaleY != 0) {
  7010. let s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * mixScaleY + 1;
  7011. bone.b *= s;
  7012. bone.d *= s;
  7013. }
  7014. if (mixShearY > 0) {
  7015. let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  7016. if (r > MathUtils.PI)
  7017. r -= MathUtils.PI2;
  7018. else if (r < -MathUtils.PI)
  7019. r += MathUtils.PI2;
  7020. let b = bone.b, d = bone.d;
  7021. r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * mixShearY;
  7022. let s = Math.sqrt(b * b + d * d);
  7023. bone.b = Math.cos(r) * s;
  7024. bone.d = Math.sin(r) * s;
  7025. }
  7026. bone.updateAppliedTransform();
  7027. }
  7028. }
  7029. applyAbsoluteLocal() {
  7030. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  7031. let target = this.target;
  7032. let bones = this.bones;
  7033. for (let i = 0, n = bones.length; i < n; i++) {
  7034. let bone = bones[i];
  7035. let rotation = bone.arotation;
  7036. if (mixRotate != 0) {
  7037. let r = target.arotation - rotation + this.data.offsetRotation;
  7038. r -= (16384 - (16384.499999999996 - r / 360 | 0)) * 360;
  7039. rotation += r * mixRotate;
  7040. }
  7041. let x = bone.ax, y = bone.ay;
  7042. x += (target.ax - x + this.data.offsetX) * mixX;
  7043. y += (target.ay - y + this.data.offsetY) * mixY;
  7044. let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  7045. if (mixScaleX != 0 && scaleX != 0)
  7046. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * mixScaleX) / scaleX;
  7047. if (mixScaleY != 0 && scaleY != 0)
  7048. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * mixScaleY) / scaleY;
  7049. let shearY = bone.ashearY;
  7050. if (mixShearY != 0) {
  7051. let r = target.ashearY - shearY + this.data.offsetShearY;
  7052. r -= (16384 - (16384.499999999996 - r / 360 | 0)) * 360;
  7053. shearY += r * mixShearY;
  7054. }
  7055. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  7056. }
  7057. }
  7058. applyRelativeLocal() {
  7059. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  7060. let target = this.target;
  7061. let bones = this.bones;
  7062. for (let i = 0, n = bones.length; i < n; i++) {
  7063. let bone = bones[i];
  7064. let rotation = bone.arotation + (target.arotation + this.data.offsetRotation) * mixRotate;
  7065. let x = bone.ax + (target.ax + this.data.offsetX) * mixX;
  7066. let y = bone.ay + (target.ay + this.data.offsetY) * mixY;
  7067. let scaleX = bone.ascaleX * ((target.ascaleX - 1 + this.data.offsetScaleX) * mixScaleX + 1);
  7068. let scaleY = bone.ascaleY * ((target.ascaleY - 1 + this.data.offsetScaleY) * mixScaleY + 1);
  7069. let shearY = bone.ashearY + (target.ashearY + this.data.offsetShearY) * mixShearY;
  7070. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  7071. }
  7072. }
  7073. };
  7074. // spine-core/src/Skeleton.ts
  7075. var _Skeleton = class {
  7076. constructor(data) {
  7077. /** The list of bones and constraints, sorted in the order they should be updated, as computed by {@link #updateCache()}. */
  7078. this._updateCache = new Array();
  7079. /** The skeleton's current skin. May be null. */
  7080. this.skin = null;
  7081. /** Scales the entire skeleton on the X axis. This affects all bones, even if the bone's transform mode disallows scale
  7082. * inheritance. */
  7083. this.scaleX = 1;
  7084. /** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale
  7085. * inheritance. */
  7086. this._scaleY = 1;
  7087. /** Sets the skeleton X position, which is added to the root bone worldX position. */
  7088. this.x = 0;
  7089. /** Sets the skeleton Y position, which is added to the root bone worldY position. */
  7090. this.y = 0;
  7091. if (!data)
  7092. throw new Error("data cannot be null.");
  7093. this.data = data;
  7094. this.bones = new Array();
  7095. for (let i = 0; i < data.bones.length; i++) {
  7096. let boneData = data.bones[i];
  7097. let bone;
  7098. if (!boneData.parent)
  7099. bone = new Bone(boneData, this, null);
  7100. else {
  7101. let parent = this.bones[boneData.parent.index];
  7102. bone = new Bone(boneData, this, parent);
  7103. parent.children.push(bone);
  7104. }
  7105. this.bones.push(bone);
  7106. }
  7107. this.slots = new Array();
  7108. this.drawOrder = new Array();
  7109. for (let i = 0; i < data.slots.length; i++) {
  7110. let slotData = data.slots[i];
  7111. let bone = this.bones[slotData.boneData.index];
  7112. let slot = new Slot(slotData, bone);
  7113. this.slots.push(slot);
  7114. this.drawOrder.push(slot);
  7115. }
  7116. this.ikConstraints = new Array();
  7117. for (let i = 0; i < data.ikConstraints.length; i++) {
  7118. let ikConstraintData = data.ikConstraints[i];
  7119. this.ikConstraints.push(new IkConstraint(ikConstraintData, this));
  7120. }
  7121. this.transformConstraints = new Array();
  7122. for (let i = 0; i < data.transformConstraints.length; i++) {
  7123. let transformConstraintData = data.transformConstraints[i];
  7124. this.transformConstraints.push(new TransformConstraint(transformConstraintData, this));
  7125. }
  7126. this.pathConstraints = new Array();
  7127. for (let i = 0; i < data.pathConstraints.length; i++) {
  7128. let pathConstraintData = data.pathConstraints[i];
  7129. this.pathConstraints.push(new PathConstraint(pathConstraintData, this));
  7130. }
  7131. this.color = new Color(1, 1, 1, 1);
  7132. this.updateCache();
  7133. }
  7134. get scaleY() {
  7135. return _Skeleton.yDown ? -this._scaleY : this._scaleY;
  7136. }
  7137. set scaleY(scaleY) {
  7138. this._scaleY = scaleY;
  7139. }
  7140. /** Caches information about bones and constraints. Must be called if the {@link #getSkin()} is modified or if bones,
  7141. * constraints, or weighted path attachments are added or removed. */
  7142. updateCache() {
  7143. let updateCache = this._updateCache;
  7144. updateCache.length = 0;
  7145. let bones = this.bones;
  7146. for (let i = 0, n = bones.length; i < n; i++) {
  7147. let bone = bones[i];
  7148. bone.sorted = bone.data.skinRequired;
  7149. bone.active = !bone.sorted;
  7150. }
  7151. if (this.skin) {
  7152. let skinBones = this.skin.bones;
  7153. for (let i = 0, n = this.skin.bones.length; i < n; i++) {
  7154. let bone = this.bones[skinBones[i].index];
  7155. do {
  7156. bone.sorted = false;
  7157. bone.active = true;
  7158. bone = bone.parent;
  7159. } while (bone);
  7160. }
  7161. }
  7162. let ikConstraints = this.ikConstraints;
  7163. let transformConstraints = this.transformConstraints;
  7164. let pathConstraints = this.pathConstraints;
  7165. let ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  7166. let constraintCount = ikCount + transformCount + pathCount;
  7167. outer:
  7168. for (let i = 0; i < constraintCount; i++) {
  7169. for (let ii = 0; ii < ikCount; ii++) {
  7170. let constraint = ikConstraints[ii];
  7171. if (constraint.data.order == i) {
  7172. this.sortIkConstraint(constraint);
  7173. continue outer;
  7174. }
  7175. }
  7176. for (let ii = 0; ii < transformCount; ii++) {
  7177. let constraint = transformConstraints[ii];
  7178. if (constraint.data.order == i) {
  7179. this.sortTransformConstraint(constraint);
  7180. continue outer;
  7181. }
  7182. }
  7183. for (let ii = 0; ii < pathCount; ii++) {
  7184. let constraint = pathConstraints[ii];
  7185. if (constraint.data.order == i) {
  7186. this.sortPathConstraint(constraint);
  7187. continue outer;
  7188. }
  7189. }
  7190. }
  7191. for (let i = 0, n = bones.length; i < n; i++)
  7192. this.sortBone(bones[i]);
  7193. }
  7194. sortIkConstraint(constraint) {
  7195. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || this.skin && Utils.contains(this.skin.constraints, constraint.data, true));
  7196. if (!constraint.active)
  7197. return;
  7198. let target = constraint.target;
  7199. this.sortBone(target);
  7200. let constrained = constraint.bones;
  7201. let parent = constrained[0];
  7202. this.sortBone(parent);
  7203. if (constrained.length == 1) {
  7204. this._updateCache.push(constraint);
  7205. this.sortReset(parent.children);
  7206. } else {
  7207. let child = constrained[constrained.length - 1];
  7208. this.sortBone(child);
  7209. this._updateCache.push(constraint);
  7210. this.sortReset(parent.children);
  7211. child.sorted = true;
  7212. }
  7213. }
  7214. sortPathConstraint(constraint) {
  7215. constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || this.skin && Utils.contains(this.skin.constraints, constraint.data, true));
  7216. if (!constraint.active)
  7217. return;
  7218. let slot = constraint.target;
  7219. let slotIndex = slot.data.index;
  7220. let slotBone = slot.bone;
  7221. if (this.skin)
  7222. this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  7223. if (this.data.defaultSkin && this.data.defaultSkin != this.skin)
  7224. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  7225. for (let i = 0, n = this.data.skins.length; i < n; i++)
  7226. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  7227. let attachment = slot.getAttachment();
  7228. if (attachment instanceof PathAttachment)
  7229. this.sortPathConstraintAttachmentWith(attachment, slotBone);
  7230. let constrained = constraint.bones;
  7231. let boneCount = constrained.length;
  7232. for (let i = 0; i < boneCount; i++)
  7233. this.sortBone(constrained[i]);
  7234. this._updateCache.push(constraint);
  7235. for (let i = 0; i < boneCount; i++)
  7236. this.sortReset(constrained[i].children);
  7237. for (let i = 0; i < boneCount; i++)
  7238. constrained[i].sorted = true;
  7239. }
  7240. sortTransformConstraint(constraint) {
  7241. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || this.skin && Utils.contains(this.skin.constraints, constraint.data, true));
  7242. if (!constraint.active)
  7243. return;
  7244. this.sortBone(constraint.target);
  7245. let constrained = constraint.bones;
  7246. let boneCount = constrained.length;
  7247. if (constraint.data.local) {
  7248. for (let i = 0; i < boneCount; i++) {
  7249. let child = constrained[i];
  7250. this.sortBone(child.parent);
  7251. this.sortBone(child);
  7252. }
  7253. } else {
  7254. for (let i = 0; i < boneCount; i++) {
  7255. this.sortBone(constrained[i]);
  7256. }
  7257. }
  7258. this._updateCache.push(constraint);
  7259. for (let i = 0; i < boneCount; i++)
  7260. this.sortReset(constrained[i].children);
  7261. for (let i = 0; i < boneCount; i++)
  7262. constrained[i].sorted = true;
  7263. }
  7264. sortPathConstraintAttachment(skin, slotIndex, slotBone) {
  7265. let attachments = skin.attachments[slotIndex];
  7266. if (!attachments)
  7267. return;
  7268. for (let key in attachments) {
  7269. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  7270. }
  7271. }
  7272. sortPathConstraintAttachmentWith(attachment, slotBone) {
  7273. if (!(attachment instanceof PathAttachment))
  7274. return;
  7275. let pathBones = attachment.bones;
  7276. if (!pathBones)
  7277. this.sortBone(slotBone);
  7278. else {
  7279. let bones = this.bones;
  7280. for (let i = 0, n = pathBones.length; i < n; ) {
  7281. let nn = pathBones[i++];
  7282. nn += i;
  7283. while (i < nn)
  7284. this.sortBone(bones[pathBones[i++]]);
  7285. }
  7286. }
  7287. }
  7288. sortBone(bone) {
  7289. if (!bone)
  7290. return;
  7291. if (bone.sorted)
  7292. return;
  7293. let parent = bone.parent;
  7294. if (parent)
  7295. this.sortBone(parent);
  7296. bone.sorted = true;
  7297. this._updateCache.push(bone);
  7298. }
  7299. sortReset(bones) {
  7300. for (let i = 0, n = bones.length; i < n; i++) {
  7301. let bone = bones[i];
  7302. if (!bone.active)
  7303. continue;
  7304. if (bone.sorted)
  7305. this.sortReset(bone.children);
  7306. bone.sorted = false;
  7307. }
  7308. }
  7309. /** Updates the world transform for each bone and applies all constraints.
  7310. *
  7311. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  7312. * Runtimes Guide. */
  7313. updateWorldTransform() {
  7314. let bones = this.bones;
  7315. for (let i = 0, n = bones.length; i < n; i++) {
  7316. let bone = bones[i];
  7317. bone.ax = bone.x;
  7318. bone.ay = bone.y;
  7319. bone.arotation = bone.rotation;
  7320. bone.ascaleX = bone.scaleX;
  7321. bone.ascaleY = bone.scaleY;
  7322. bone.ashearX = bone.shearX;
  7323. bone.ashearY = bone.shearY;
  7324. }
  7325. let updateCache = this._updateCache;
  7326. for (let i = 0, n = updateCache.length; i < n; i++)
  7327. updateCache[i].update();
  7328. }
  7329. updateWorldTransformWith(parent) {
  7330. let rootBone = this.getRootBone();
  7331. if (!rootBone)
  7332. throw new Error("Root bone must not be null.");
  7333. let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  7334. rootBone.worldX = pa * this.x + pb * this.y + parent.worldX;
  7335. rootBone.worldY = pc * this.x + pd * this.y + parent.worldY;
  7336. let rotationY = rootBone.rotation + 90 + rootBone.shearY;
  7337. let la = MathUtils.cosDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
  7338. let lb = MathUtils.cosDeg(rotationY) * rootBone.scaleY;
  7339. let lc = MathUtils.sinDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
  7340. let ld = MathUtils.sinDeg(rotationY) * rootBone.scaleY;
  7341. rootBone.a = (pa * la + pb * lc) * this.scaleX;
  7342. rootBone.b = (pa * lb + pb * ld) * this.scaleX;
  7343. rootBone.c = (pc * la + pd * lc) * this.scaleY;
  7344. rootBone.d = (pc * lb + pd * ld) * this.scaleY;
  7345. let updateCache = this._updateCache;
  7346. for (let i = 0, n = updateCache.length; i < n; i++) {
  7347. let updatable = updateCache[i];
  7348. if (updatable != rootBone)
  7349. updatable.update();
  7350. }
  7351. }
  7352. /** Sets the bones, constraints, and slots to their setup pose values. */
  7353. setToSetupPose() {
  7354. this.setBonesToSetupPose();
  7355. this.setSlotsToSetupPose();
  7356. }
  7357. /** Sets the bones and constraints to their setup pose values. */
  7358. setBonesToSetupPose() {
  7359. let bones = this.bones;
  7360. for (let i = 0, n = bones.length; i < n; i++)
  7361. bones[i].setToSetupPose();
  7362. let ikConstraints = this.ikConstraints;
  7363. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  7364. let constraint = ikConstraints[i];
  7365. constraint.mix = constraint.data.mix;
  7366. constraint.softness = constraint.data.softness;
  7367. constraint.bendDirection = constraint.data.bendDirection;
  7368. constraint.compress = constraint.data.compress;
  7369. constraint.stretch = constraint.data.stretch;
  7370. }
  7371. let transformConstraints = this.transformConstraints;
  7372. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  7373. let constraint = transformConstraints[i];
  7374. let data = constraint.data;
  7375. constraint.mixRotate = data.mixRotate;
  7376. constraint.mixX = data.mixX;
  7377. constraint.mixY = data.mixY;
  7378. constraint.mixScaleX = data.mixScaleX;
  7379. constraint.mixScaleY = data.mixScaleY;
  7380. constraint.mixShearY = data.mixShearY;
  7381. }
  7382. let pathConstraints = this.pathConstraints;
  7383. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  7384. let constraint = pathConstraints[i];
  7385. let data = constraint.data;
  7386. constraint.position = data.position;
  7387. constraint.spacing = data.spacing;
  7388. constraint.mixRotate = data.mixRotate;
  7389. constraint.mixX = data.mixX;
  7390. constraint.mixY = data.mixY;
  7391. }
  7392. }
  7393. /** Sets the slots and draw order to their setup pose values. */
  7394. setSlotsToSetupPose() {
  7395. let slots = this.slots;
  7396. Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  7397. for (let i = 0, n = slots.length; i < n; i++)
  7398. slots[i].setToSetupPose();
  7399. }
  7400. /** @returns May return null. */
  7401. getRootBone() {
  7402. if (this.bones.length == 0)
  7403. return null;
  7404. return this.bones[0];
  7405. }
  7406. /** @returns May be null. */
  7407. findBone(boneName) {
  7408. if (!boneName)
  7409. throw new Error("boneName cannot be null.");
  7410. let bones = this.bones;
  7411. for (let i = 0, n = bones.length; i < n; i++) {
  7412. let bone = bones[i];
  7413. if (bone.data.name == boneName)
  7414. return bone;
  7415. }
  7416. return null;
  7417. }
  7418. /** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
  7419. * repeatedly.
  7420. * @returns May be null. */
  7421. findSlot(slotName) {
  7422. if (!slotName)
  7423. throw new Error("slotName cannot be null.");
  7424. let slots = this.slots;
  7425. for (let i = 0, n = slots.length; i < n; i++) {
  7426. let slot = slots[i];
  7427. if (slot.data.name == slotName)
  7428. return slot;
  7429. }
  7430. return null;
  7431. }
  7432. /** Sets a skin by name.
  7433. *
  7434. * See {@link #setSkin()}. */
  7435. setSkinByName(skinName) {
  7436. let skin = this.data.findSkin(skinName);
  7437. if (!skin)
  7438. throw new Error("Skin not found: " + skinName);
  7439. this.setSkin(skin);
  7440. }
  7441. /** Sets the skin used to look up attachments before looking in the {@link SkeletonData#defaultSkin default skin}. If the
  7442. * skin is changed, {@link #updateCache()} is called.
  7443. *
  7444. * Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. If there was no
  7445. * old skin, each slot's setup mode attachment is attached from the new skin.
  7446. *
  7447. * After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling
  7448. * {@link #setSlotsToSetupPose()}. Also, often {@link AnimationState#apply()} is called before the next time the
  7449. * skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin.
  7450. * @param newSkin May be null. */
  7451. setSkin(newSkin) {
  7452. if (newSkin == this.skin)
  7453. return;
  7454. if (newSkin) {
  7455. if (this.skin)
  7456. newSkin.attachAll(this, this.skin);
  7457. else {
  7458. let slots = this.slots;
  7459. for (let i = 0, n = slots.length; i < n; i++) {
  7460. let slot = slots[i];
  7461. let name = slot.data.attachmentName;
  7462. if (name) {
  7463. let attachment = newSkin.getAttachment(i, name);
  7464. if (attachment)
  7465. slot.setAttachment(attachment);
  7466. }
  7467. }
  7468. }
  7469. }
  7470. this.skin = newSkin;
  7471. this.updateCache();
  7472. }
  7473. /** Finds an attachment by looking in the {@link #skin} and {@link SkeletonData#defaultSkin} using the slot name and attachment
  7474. * name.
  7475. *
  7476. * See {@link #getAttachment()}.
  7477. * @returns May be null. */
  7478. getAttachmentByName(slotName, attachmentName) {
  7479. let slot = this.data.findSlot(slotName);
  7480. if (!slot)
  7481. throw new Error(`Can't find slot with name ${slotName}`);
  7482. return this.getAttachment(slot.index, attachmentName);
  7483. }
  7484. /** Finds an attachment by looking in the {@link #skin} and {@link SkeletonData#defaultSkin} using the slot index and
  7485. * attachment name. First the skin is checked and if the attachment was not found, the default skin is checked.
  7486. *
  7487. * See [Runtime skins](http://esotericsoftware.com/spine-runtime-skins) in the Spine Runtimes Guide.
  7488. * @returns May be null. */
  7489. getAttachment(slotIndex, attachmentName) {
  7490. if (!attachmentName)
  7491. throw new Error("attachmentName cannot be null.");
  7492. if (this.skin) {
  7493. let attachment = this.skin.getAttachment(slotIndex, attachmentName);
  7494. if (attachment)
  7495. return attachment;
  7496. }
  7497. if (this.data.defaultSkin)
  7498. return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  7499. return null;
  7500. }
  7501. /** A convenience method to set an attachment by finding the slot with {@link #findSlot()}, finding the attachment with
  7502. * {@link #getAttachment()}, then setting the slot's {@link Slot#attachment}.
  7503. * @param attachmentName May be null to clear the slot's attachment. */
  7504. setAttachment(slotName, attachmentName) {
  7505. if (!slotName)
  7506. throw new Error("slotName cannot be null.");
  7507. let slots = this.slots;
  7508. for (let i = 0, n = slots.length; i < n; i++) {
  7509. let slot = slots[i];
  7510. if (slot.data.name == slotName) {
  7511. let attachment = null;
  7512. if (attachmentName) {
  7513. attachment = this.getAttachment(i, attachmentName);
  7514. if (!attachment)
  7515. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  7516. }
  7517. slot.setAttachment(attachment);
  7518. return;
  7519. }
  7520. }
  7521. throw new Error("Slot not found: " + slotName);
  7522. }
  7523. /** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method
  7524. * than to call it repeatedly.
  7525. * @return May be null. */
  7526. findIkConstraint(constraintName) {
  7527. if (!constraintName)
  7528. throw new Error("constraintName cannot be null.");
  7529. let ikConstraints = this.ikConstraints;
  7530. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  7531. let ikConstraint = ikConstraints[i];
  7532. if (ikConstraint.data.name == constraintName)
  7533. return ikConstraint;
  7534. }
  7535. return null;
  7536. }
  7537. /** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of
  7538. * this method than to call it repeatedly.
  7539. * @return May be null. */
  7540. findTransformConstraint(constraintName) {
  7541. if (!constraintName)
  7542. throw new Error("constraintName cannot be null.");
  7543. let transformConstraints = this.transformConstraints;
  7544. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  7545. let constraint = transformConstraints[i];
  7546. if (constraint.data.name == constraintName)
  7547. return constraint;
  7548. }
  7549. return null;
  7550. }
  7551. /** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method
  7552. * than to call it repeatedly.
  7553. * @return May be null. */
  7554. findPathConstraint(constraintName) {
  7555. if (!constraintName)
  7556. throw new Error("constraintName cannot be null.");
  7557. let pathConstraints = this.pathConstraints;
  7558. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  7559. let constraint = pathConstraints[i];
  7560. if (constraint.data.name == constraintName)
  7561. return constraint;
  7562. }
  7563. return null;
  7564. }
  7565. /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose as `{ x: number, y: number, width: number, height: number }`.
  7566. * Note that this method will create temporary objects which can add to garbage collection pressure. Use `getBounds()` if garbage collection is a concern. */
  7567. getBoundsRect() {
  7568. let offset = new Vector2();
  7569. let size = new Vector2();
  7570. this.getBounds(offset, size);
  7571. return { x: offset.x, y: offset.y, width: size.x, height: size.y };
  7572. }
  7573. /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
  7574. * @param offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
  7575. * @param size An output value, the width and height of the AABB.
  7576. * @param temp Working memory to temporarily store attachments' computed world vertices. */
  7577. getBounds(offset, size, temp = new Array(2)) {
  7578. if (!offset)
  7579. throw new Error("offset cannot be null.");
  7580. if (!size)
  7581. throw new Error("size cannot be null.");
  7582. let drawOrder = this.drawOrder;
  7583. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  7584. for (let i = 0, n = drawOrder.length; i < n; i++) {
  7585. let slot = drawOrder[i];
  7586. if (!slot.bone.active)
  7587. continue;
  7588. let verticesLength = 0;
  7589. let vertices = null;
  7590. let attachment = slot.getAttachment();
  7591. if (attachment instanceof RegionAttachment) {
  7592. verticesLength = 8;
  7593. vertices = Utils.setArraySize(temp, verticesLength, 0);
  7594. attachment.computeWorldVertices(slot, vertices, 0, 2);
  7595. } else if (attachment instanceof MeshAttachment) {
  7596. let mesh = attachment;
  7597. verticesLength = mesh.worldVerticesLength;
  7598. vertices = Utils.setArraySize(temp, verticesLength, 0);
  7599. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  7600. }
  7601. if (vertices) {
  7602. for (let ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  7603. let x = vertices[ii], y = vertices[ii + 1];
  7604. minX = Math.min(minX, x);
  7605. minY = Math.min(minY, y);
  7606. maxX = Math.max(maxX, x);
  7607. maxY = Math.max(maxY, y);
  7608. }
  7609. }
  7610. }
  7611. offset.set(minX, minY);
  7612. size.set(maxX - minX, maxY - minY);
  7613. }
  7614. };
  7615. var Skeleton = _Skeleton;
  7616. Skeleton.yDown = false;
  7617. // spine-core/src/SkeletonData.ts
  7618. var SkeletonData = class {
  7619. constructor() {
  7620. /** The skeleton's name, which by default is the name of the skeleton data file, if possible. May be null. */
  7621. this.name = null;
  7622. /** The skeleton's bones, sorted parent first. The root bone is always the first bone. */
  7623. this.bones = new Array();
  7624. // Ordered parents first.
  7625. /** The skeleton's slots. */
  7626. this.slots = new Array();
  7627. // Setup pose draw order.
  7628. this.skins = new Array();
  7629. /** The skeleton's default skin. By default this skin contains all attachments that were not in a skin in Spine.
  7630. *
  7631. * See {@link Skeleton#getAttachmentByName()}.
  7632. * May be null. */
  7633. this.defaultSkin = null;
  7634. /** The skeleton's events. */
  7635. this.events = new Array();
  7636. /** The skeleton's animations. */
  7637. this.animations = new Array();
  7638. /** The skeleton's IK constraints. */
  7639. this.ikConstraints = new Array();
  7640. /** The skeleton's transform constraints. */
  7641. this.transformConstraints = new Array();
  7642. /** The skeleton's path constraints. */
  7643. this.pathConstraints = new Array();
  7644. /** The X coordinate of the skeleton's axis aligned bounding box in the setup pose. */
  7645. this.x = 0;
  7646. /** The Y coordinate of the skeleton's axis aligned bounding box in the setup pose. */
  7647. this.y = 0;
  7648. /** The width of the skeleton's axis aligned bounding box in the setup pose. */
  7649. this.width = 0;
  7650. /** The height of the skeleton's axis aligned bounding box in the setup pose. */
  7651. this.height = 0;
  7652. /** The Spine version used to export the skeleton data, or null. */
  7653. this.version = null;
  7654. /** The skeleton data hash. This value will change if any of the skeleton data has changed. May be null. */
  7655. this.hash = null;
  7656. // Nonessential
  7657. /** The dopesheet FPS in Spine. Available only when nonessential data was exported. */
  7658. this.fps = 0;
  7659. /** The path to the images directory as defined in Spine. Available only when nonessential data was exported. May be null. */
  7660. this.imagesPath = null;
  7661. /** The path to the audio directory as defined in Spine. Available only when nonessential data was exported. May be null. */
  7662. this.audioPath = null;
  7663. }
  7664. /** Finds a bone by comparing each bone's name. It is more efficient to cache the results of this method than to call it
  7665. * multiple times.
  7666. * @returns May be null. */
  7667. findBone(boneName) {
  7668. if (!boneName)
  7669. throw new Error("boneName cannot be null.");
  7670. let bones = this.bones;
  7671. for (let i = 0, n = bones.length; i < n; i++) {
  7672. let bone = bones[i];
  7673. if (bone.name == boneName)
  7674. return bone;
  7675. }
  7676. return null;
  7677. }
  7678. /** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
  7679. * multiple times.
  7680. * @returns May be null. */
  7681. findSlot(slotName) {
  7682. if (!slotName)
  7683. throw new Error("slotName cannot be null.");
  7684. let slots = this.slots;
  7685. for (let i = 0, n = slots.length; i < n; i++) {
  7686. let slot = slots[i];
  7687. if (slot.name == slotName)
  7688. return slot;
  7689. }
  7690. return null;
  7691. }
  7692. /** Finds a skin by comparing each skin's name. It is more efficient to cache the results of this method than to call it
  7693. * multiple times.
  7694. * @returns May be null. */
  7695. findSkin(skinName) {
  7696. if (!skinName)
  7697. throw new Error("skinName cannot be null.");
  7698. let skins = this.skins;
  7699. for (let i = 0, n = skins.length; i < n; i++) {
  7700. let skin = skins[i];
  7701. if (skin.name == skinName)
  7702. return skin;
  7703. }
  7704. return null;
  7705. }
  7706. /** Finds an event by comparing each events's name. It is more efficient to cache the results of this method than to call it
  7707. * multiple times.
  7708. * @returns May be null. */
  7709. findEvent(eventDataName) {
  7710. if (!eventDataName)
  7711. throw new Error("eventDataName cannot be null.");
  7712. let events = this.events;
  7713. for (let i = 0, n = events.length; i < n; i++) {
  7714. let event = events[i];
  7715. if (event.name == eventDataName)
  7716. return event;
  7717. }
  7718. return null;
  7719. }
  7720. /** Finds an animation by comparing each animation's name. It is more efficient to cache the results of this method than to
  7721. * call it multiple times.
  7722. * @returns May be null. */
  7723. findAnimation(animationName) {
  7724. if (!animationName)
  7725. throw new Error("animationName cannot be null.");
  7726. let animations = this.animations;
  7727. for (let i = 0, n = animations.length; i < n; i++) {
  7728. let animation = animations[i];
  7729. if (animation.name == animationName)
  7730. return animation;
  7731. }
  7732. return null;
  7733. }
  7734. /** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method
  7735. * than to call it multiple times.
  7736. * @return May be null. */
  7737. findIkConstraint(constraintName) {
  7738. if (!constraintName)
  7739. throw new Error("constraintName cannot be null.");
  7740. let ikConstraints = this.ikConstraints;
  7741. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  7742. let constraint = ikConstraints[i];
  7743. if (constraint.name == constraintName)
  7744. return constraint;
  7745. }
  7746. return null;
  7747. }
  7748. /** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of
  7749. * this method than to call it multiple times.
  7750. * @return May be null. */
  7751. findTransformConstraint(constraintName) {
  7752. if (!constraintName)
  7753. throw new Error("constraintName cannot be null.");
  7754. let transformConstraints = this.transformConstraints;
  7755. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  7756. let constraint = transformConstraints[i];
  7757. if (constraint.name == constraintName)
  7758. return constraint;
  7759. }
  7760. return null;
  7761. }
  7762. /** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method
  7763. * than to call it multiple times.
  7764. * @return May be null. */
  7765. findPathConstraint(constraintName) {
  7766. if (!constraintName)
  7767. throw new Error("constraintName cannot be null.");
  7768. let pathConstraints = this.pathConstraints;
  7769. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  7770. let constraint = pathConstraints[i];
  7771. if (constraint.name == constraintName)
  7772. return constraint;
  7773. }
  7774. return null;
  7775. }
  7776. };
  7777. // spine-core/src/Skin.ts
  7778. var SkinEntry = class {
  7779. constructor(slotIndex = 0, name, attachment) {
  7780. this.slotIndex = slotIndex;
  7781. this.name = name;
  7782. this.attachment = attachment;
  7783. }
  7784. };
  7785. var Skin = class {
  7786. constructor(name) {
  7787. this.attachments = new Array();
  7788. this.bones = Array();
  7789. this.constraints = new Array();
  7790. if (!name)
  7791. throw new Error("name cannot be null.");
  7792. this.name = name;
  7793. }
  7794. /** Adds an attachment to the skin for the specified slot index and name. */
  7795. setAttachment(slotIndex, name, attachment) {
  7796. if (!attachment)
  7797. throw new Error("attachment cannot be null.");
  7798. let attachments = this.attachments;
  7799. if (slotIndex >= attachments.length)
  7800. attachments.length = slotIndex + 1;
  7801. if (!attachments[slotIndex])
  7802. attachments[slotIndex] = {};
  7803. attachments[slotIndex][name] = attachment;
  7804. }
  7805. /** Adds all attachments, bones, and constraints from the specified skin to this skin. */
  7806. addSkin(skin) {
  7807. for (let i = 0; i < skin.bones.length; i++) {
  7808. let bone = skin.bones[i];
  7809. let contained = false;
  7810. for (let ii = 0; ii < this.bones.length; ii++) {
  7811. if (this.bones[ii] == bone) {
  7812. contained = true;
  7813. break;
  7814. }
  7815. }
  7816. if (!contained)
  7817. this.bones.push(bone);
  7818. }
  7819. for (let i = 0; i < skin.constraints.length; i++) {
  7820. let constraint = skin.constraints[i];
  7821. let contained = false;
  7822. for (let ii = 0; ii < this.constraints.length; ii++) {
  7823. if (this.constraints[ii] == constraint) {
  7824. contained = true;
  7825. break;
  7826. }
  7827. }
  7828. if (!contained)
  7829. this.constraints.push(constraint);
  7830. }
  7831. let attachments = skin.getAttachments();
  7832. for (let i = 0; i < attachments.length; i++) {
  7833. var attachment = attachments[i];
  7834. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  7835. }
  7836. }
  7837. /** Adds all bones and constraints and copies of all attachments from the specified skin to this skin. Mesh attachments are not
  7838. * copied, instead a new linked mesh is created. The attachment copies can be modified without affecting the originals. */
  7839. copySkin(skin) {
  7840. for (let i = 0; i < skin.bones.length; i++) {
  7841. let bone = skin.bones[i];
  7842. let contained = false;
  7843. for (let ii = 0; ii < this.bones.length; ii++) {
  7844. if (this.bones[ii] == bone) {
  7845. contained = true;
  7846. break;
  7847. }
  7848. }
  7849. if (!contained)
  7850. this.bones.push(bone);
  7851. }
  7852. for (let i = 0; i < skin.constraints.length; i++) {
  7853. let constraint = skin.constraints[i];
  7854. let contained = false;
  7855. for (let ii = 0; ii < this.constraints.length; ii++) {
  7856. if (this.constraints[ii] == constraint) {
  7857. contained = true;
  7858. break;
  7859. }
  7860. }
  7861. if (!contained)
  7862. this.constraints.push(constraint);
  7863. }
  7864. let attachments = skin.getAttachments();
  7865. for (let i = 0; i < attachments.length; i++) {
  7866. var attachment = attachments[i];
  7867. if (!attachment.attachment)
  7868. continue;
  7869. if (attachment.attachment instanceof MeshAttachment) {
  7870. attachment.attachment = attachment.attachment.newLinkedMesh();
  7871. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  7872. } else {
  7873. attachment.attachment = attachment.attachment.copy();
  7874. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  7875. }
  7876. }
  7877. }
  7878. /** Returns the attachment for the specified slot index and name, or null. */
  7879. getAttachment(slotIndex, name) {
  7880. let dictionary = this.attachments[slotIndex];
  7881. return dictionary ? dictionary[name] : null;
  7882. }
  7883. /** Removes the attachment in the skin for the specified slot index and name, if any. */
  7884. removeAttachment(slotIndex, name) {
  7885. let dictionary = this.attachments[slotIndex];
  7886. if (dictionary)
  7887. delete dictionary[name];
  7888. }
  7889. /** Returns all attachments in this skin. */
  7890. getAttachments() {
  7891. let entries = new Array();
  7892. for (var i = 0; i < this.attachments.length; i++) {
  7893. let slotAttachments = this.attachments[i];
  7894. if (slotAttachments) {
  7895. for (let name in slotAttachments) {
  7896. let attachment = slotAttachments[name];
  7897. if (attachment)
  7898. entries.push(new SkinEntry(i, name, attachment));
  7899. }
  7900. }
  7901. }
  7902. return entries;
  7903. }
  7904. /** Returns all attachments in this skin for the specified slot index. */
  7905. getAttachmentsForSlot(slotIndex, attachments) {
  7906. let slotAttachments = this.attachments[slotIndex];
  7907. if (slotAttachments) {
  7908. for (let name in slotAttachments) {
  7909. let attachment = slotAttachments[name];
  7910. if (attachment)
  7911. attachments.push(new SkinEntry(slotIndex, name, attachment));
  7912. }
  7913. }
  7914. }
  7915. /** Clears all attachments, bones, and constraints. */
  7916. clear() {
  7917. this.attachments.length = 0;
  7918. this.bones.length = 0;
  7919. this.constraints.length = 0;
  7920. }
  7921. /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
  7922. attachAll(skeleton, oldSkin) {
  7923. let slotIndex = 0;
  7924. for (let i = 0; i < skeleton.slots.length; i++) {
  7925. let slot = skeleton.slots[i];
  7926. let slotAttachment = slot.getAttachment();
  7927. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  7928. let dictionary = oldSkin.attachments[slotIndex];
  7929. for (let key in dictionary) {
  7930. let skinAttachment = dictionary[key];
  7931. if (slotAttachment == skinAttachment) {
  7932. let attachment = this.getAttachment(slotIndex, key);
  7933. if (attachment)
  7934. slot.setAttachment(attachment);
  7935. break;
  7936. }
  7937. }
  7938. }
  7939. slotIndex++;
  7940. }
  7941. }
  7942. };
  7943. // spine-core/src/SlotData.ts
  7944. var SlotData = class {
  7945. constructor(index, name, boneData) {
  7946. /** The index of the slot in {@link Skeleton#getSlots()}. */
  7947. this.index = 0;
  7948. /** The color used to tint the slot's attachment. If {@link #getDarkColor()} is set, this is used as the light color for two
  7949. * color tinting. */
  7950. this.color = new Color(1, 1, 1, 1);
  7951. /** The dark color used to tint the slot's attachment for two color tinting, or null if two color tinting is not used. The dark
  7952. * color's alpha is not used. */
  7953. this.darkColor = null;
  7954. /** The name of the attachment that is visible for this slot in the setup pose, or null if no attachment is visible. */
  7955. this.attachmentName = null;
  7956. /** The blend mode for drawing the slot's attachment. */
  7957. this.blendMode = BlendMode.Normal;
  7958. if (index < 0)
  7959. throw new Error("index must be >= 0.");
  7960. if (!name)
  7961. throw new Error("name cannot be null.");
  7962. if (!boneData)
  7963. throw new Error("boneData cannot be null.");
  7964. this.index = index;
  7965. this.name = name;
  7966. this.boneData = boneData;
  7967. }
  7968. };
  7969. var BlendMode = /* @__PURE__ */ ((BlendMode4) => {
  7970. BlendMode4[BlendMode4["Normal"] = 0] = "Normal";
  7971. BlendMode4[BlendMode4["Additive"] = 1] = "Additive";
  7972. BlendMode4[BlendMode4["Multiply"] = 2] = "Multiply";
  7973. BlendMode4[BlendMode4["Screen"] = 3] = "Screen";
  7974. return BlendMode4;
  7975. })(BlendMode || {});
  7976. // spine-core/src/TransformConstraintData.ts
  7977. var TransformConstraintData = class extends ConstraintData {
  7978. constructor(name) {
  7979. super(name, 0, false);
  7980. /** The bones that will be modified by this transform constraint. */
  7981. this.bones = new Array();
  7982. /** The target bone whose world transform will be copied to the constrained bones. */
  7983. this._target = null;
  7984. this.mixRotate = 0;
  7985. this.mixX = 0;
  7986. this.mixY = 0;
  7987. this.mixScaleX = 0;
  7988. this.mixScaleY = 0;
  7989. this.mixShearY = 0;
  7990. /** An offset added to the constrained bone rotation. */
  7991. this.offsetRotation = 0;
  7992. /** An offset added to the constrained bone X translation. */
  7993. this.offsetX = 0;
  7994. /** An offset added to the constrained bone Y translation. */
  7995. this.offsetY = 0;
  7996. /** An offset added to the constrained bone scaleX. */
  7997. this.offsetScaleX = 0;
  7998. /** An offset added to the constrained bone scaleY. */
  7999. this.offsetScaleY = 0;
  8000. /** An offset added to the constrained bone shearY. */
  8001. this.offsetShearY = 0;
  8002. this.relative = false;
  8003. this.local = false;
  8004. }
  8005. set target(boneData) {
  8006. this._target = boneData;
  8007. }
  8008. get target() {
  8009. if (!this._target)
  8010. throw new Error("BoneData not set.");
  8011. else
  8012. return this._target;
  8013. }
  8014. };
  8015. // spine-core/src/SkeletonBinary.ts
  8016. var SkeletonBinary = class {
  8017. constructor(attachmentLoader) {
  8018. /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at
  8019. * runtime than were used in Spine.
  8020. *
  8021. * See [Scaling](http://esotericsoftware.com/spine-loading-skeleton-data#Scaling) in the Spine Runtimes Guide. */
  8022. this.scale = 1;
  8023. this.linkedMeshes = new Array();
  8024. this.attachmentLoader = attachmentLoader;
  8025. }
  8026. readSkeletonData(binary) {
  8027. let scale = this.scale;
  8028. let skeletonData = new SkeletonData();
  8029. skeletonData.name = "";
  8030. let input = new BinaryInput(binary);
  8031. let lowHash = input.readInt32();
  8032. let highHash = input.readInt32();
  8033. skeletonData.hash = highHash == 0 && lowHash == 0 ? null : highHash.toString(16) + lowHash.toString(16);
  8034. skeletonData.version = input.readString();
  8035. skeletonData.x = input.readFloat();
  8036. skeletonData.y = input.readFloat();
  8037. skeletonData.width = input.readFloat();
  8038. skeletonData.height = input.readFloat();
  8039. let nonessential = input.readBoolean();
  8040. if (nonessential) {
  8041. skeletonData.fps = input.readFloat();
  8042. skeletonData.imagesPath = input.readString();
  8043. skeletonData.audioPath = input.readString();
  8044. }
  8045. let n = 0;
  8046. n = input.readInt(true);
  8047. for (let i = 0; i < n; i++) {
  8048. let str = input.readString();
  8049. if (!str)
  8050. throw new Error("String in string table must not be null.");
  8051. input.strings.push(str);
  8052. }
  8053. n = input.readInt(true);
  8054. for (let i = 0; i < n; i++) {
  8055. let name = input.readString();
  8056. if (!name)
  8057. throw new Error("Bone name must not be null.");
  8058. let parent = i == 0 ? null : skeletonData.bones[input.readInt(true)];
  8059. let data = new BoneData(i, name, parent);
  8060. data.rotation = input.readFloat();
  8061. data.x = input.readFloat() * scale;
  8062. data.y = input.readFloat() * scale;
  8063. data.scaleX = input.readFloat();
  8064. data.scaleY = input.readFloat();
  8065. data.shearX = input.readFloat();
  8066. data.shearY = input.readFloat();
  8067. data.length = input.readFloat() * scale;
  8068. data.transformMode = input.readInt(true);
  8069. data.skinRequired = input.readBoolean();
  8070. if (nonessential)
  8071. Color.rgba8888ToColor(data.color, input.readInt32());
  8072. skeletonData.bones.push(data);
  8073. }
  8074. n = input.readInt(true);
  8075. for (let i = 0; i < n; i++) {
  8076. let slotName = input.readString();
  8077. if (!slotName)
  8078. throw new Error("Slot name must not be null.");
  8079. let boneData = skeletonData.bones[input.readInt(true)];
  8080. let data = new SlotData(i, slotName, boneData);
  8081. Color.rgba8888ToColor(data.color, input.readInt32());
  8082. let darkColor = input.readInt32();
  8083. if (darkColor != -1)
  8084. Color.rgb888ToColor(data.darkColor = new Color(), darkColor);
  8085. data.attachmentName = input.readStringRef();
  8086. data.blendMode = input.readInt(true);
  8087. skeletonData.slots.push(data);
  8088. }
  8089. n = input.readInt(true);
  8090. for (let i = 0, nn; i < n; i++) {
  8091. let name = input.readString();
  8092. if (!name)
  8093. throw new Error("IK constraint data name must not be null.");
  8094. let data = new IkConstraintData(name);
  8095. data.order = input.readInt(true);
  8096. data.skinRequired = input.readBoolean();
  8097. nn = input.readInt(true);
  8098. for (let ii = 0; ii < nn; ii++)
  8099. data.bones.push(skeletonData.bones[input.readInt(true)]);
  8100. data.target = skeletonData.bones[input.readInt(true)];
  8101. data.mix = input.readFloat();
  8102. data.softness = input.readFloat() * scale;
  8103. data.bendDirection = input.readByte();
  8104. data.compress = input.readBoolean();
  8105. data.stretch = input.readBoolean();
  8106. data.uniform = input.readBoolean();
  8107. skeletonData.ikConstraints.push(data);
  8108. }
  8109. n = input.readInt(true);
  8110. for (let i = 0, nn; i < n; i++) {
  8111. let name = input.readString();
  8112. if (!name)
  8113. throw new Error("Transform constraint data name must not be null.");
  8114. let data = new TransformConstraintData(name);
  8115. data.order = input.readInt(true);
  8116. data.skinRequired = input.readBoolean();
  8117. nn = input.readInt(true);
  8118. for (let ii = 0; ii < nn; ii++)
  8119. data.bones.push(skeletonData.bones[input.readInt(true)]);
  8120. data.target = skeletonData.bones[input.readInt(true)];
  8121. data.local = input.readBoolean();
  8122. data.relative = input.readBoolean();
  8123. data.offsetRotation = input.readFloat();
  8124. data.offsetX = input.readFloat() * scale;
  8125. data.offsetY = input.readFloat() * scale;
  8126. data.offsetScaleX = input.readFloat();
  8127. data.offsetScaleY = input.readFloat();
  8128. data.offsetShearY = input.readFloat();
  8129. data.mixRotate = input.readFloat();
  8130. data.mixX = input.readFloat();
  8131. data.mixY = input.readFloat();
  8132. data.mixScaleX = input.readFloat();
  8133. data.mixScaleY = input.readFloat();
  8134. data.mixShearY = input.readFloat();
  8135. skeletonData.transformConstraints.push(data);
  8136. }
  8137. n = input.readInt(true);
  8138. for (let i = 0, nn; i < n; i++) {
  8139. let name = input.readString();
  8140. if (!name)
  8141. throw new Error("Path constraint data name must not be null.");
  8142. let data = new PathConstraintData(name);
  8143. data.order = input.readInt(true);
  8144. data.skinRequired = input.readBoolean();
  8145. nn = input.readInt(true);
  8146. for (let ii = 0; ii < nn; ii++)
  8147. data.bones.push(skeletonData.bones[input.readInt(true)]);
  8148. data.target = skeletonData.slots[input.readInt(true)];
  8149. data.positionMode = input.readInt(true);
  8150. data.spacingMode = input.readInt(true);
  8151. data.rotateMode = input.readInt(true);
  8152. data.offsetRotation = input.readFloat();
  8153. data.position = input.readFloat();
  8154. if (data.positionMode == 0 /* Fixed */)
  8155. data.position *= scale;
  8156. data.spacing = input.readFloat();
  8157. if (data.spacingMode == 0 /* Length */ || data.spacingMode == 1 /* Fixed */)
  8158. data.spacing *= scale;
  8159. data.mixRotate = input.readFloat();
  8160. data.mixX = input.readFloat();
  8161. data.mixY = input.readFloat();
  8162. skeletonData.pathConstraints.push(data);
  8163. }
  8164. let defaultSkin = this.readSkin(input, skeletonData, true, nonessential);
  8165. if (defaultSkin) {
  8166. skeletonData.defaultSkin = defaultSkin;
  8167. skeletonData.skins.push(defaultSkin);
  8168. }
  8169. {
  8170. let i = skeletonData.skins.length;
  8171. Utils.setArraySize(skeletonData.skins, n = i + input.readInt(true));
  8172. for (; i < n; i++) {
  8173. let skin = this.readSkin(input, skeletonData, false, nonessential);
  8174. if (!skin)
  8175. throw new Error("readSkin() should not have returned null.");
  8176. skeletonData.skins[i] = skin;
  8177. }
  8178. }
  8179. n = this.linkedMeshes.length;
  8180. for (let i = 0; i < n; i++) {
  8181. let linkedMesh = this.linkedMeshes[i];
  8182. let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  8183. if (!skin)
  8184. throw new Error("Not skin found for linked mesh.");
  8185. if (!linkedMesh.parent)
  8186. throw new Error("Linked mesh parent must not be null");
  8187. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  8188. if (!parent)
  8189. throw new Error(`Parent mesh not found: ${linkedMesh.parent}`);
  8190. linkedMesh.mesh.timelineAttachment = linkedMesh.inheritTimeline ? parent : linkedMesh.mesh;
  8191. linkedMesh.mesh.setParentMesh(parent);
  8192. if (linkedMesh.mesh.region != null)
  8193. linkedMesh.mesh.updateRegion();
  8194. }
  8195. this.linkedMeshes.length = 0;
  8196. n = input.readInt(true);
  8197. for (let i = 0; i < n; i++) {
  8198. let eventName = input.readStringRef();
  8199. if (!eventName)
  8200. throw new Error();
  8201. let data = new EventData(eventName);
  8202. data.intValue = input.readInt(false);
  8203. data.floatValue = input.readFloat();
  8204. data.stringValue = input.readString();
  8205. data.audioPath = input.readString();
  8206. if (data.audioPath) {
  8207. data.volume = input.readFloat();
  8208. data.balance = input.readFloat();
  8209. }
  8210. skeletonData.events.push(data);
  8211. }
  8212. n = input.readInt(true);
  8213. for (let i = 0; i < n; i++) {
  8214. let animationName = input.readString();
  8215. if (!animationName)
  8216. throw new Error("Animatio name must not be null.");
  8217. skeletonData.animations.push(this.readAnimation(input, animationName, skeletonData));
  8218. }
  8219. return skeletonData;
  8220. }
  8221. readSkin(input, skeletonData, defaultSkin, nonessential) {
  8222. let skin = null;
  8223. let slotCount = 0;
  8224. if (defaultSkin) {
  8225. slotCount = input.readInt(true);
  8226. if (slotCount == 0)
  8227. return null;
  8228. skin = new Skin("default");
  8229. } else {
  8230. let skinName = input.readStringRef();
  8231. if (!skinName)
  8232. throw new Error("Skin name must not be null.");
  8233. skin = new Skin(skinName);
  8234. skin.bones.length = input.readInt(true);
  8235. for (let i = 0, n = skin.bones.length; i < n; i++)
  8236. skin.bones[i] = skeletonData.bones[input.readInt(true)];
  8237. for (let i = 0, n = input.readInt(true); i < n; i++)
  8238. skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]);
  8239. for (let i = 0, n = input.readInt(true); i < n; i++)
  8240. skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]);
  8241. for (let i = 0, n = input.readInt(true); i < n; i++)
  8242. skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]);
  8243. slotCount = input.readInt(true);
  8244. }
  8245. for (let i = 0; i < slotCount; i++) {
  8246. let slotIndex = input.readInt(true);
  8247. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  8248. let name = input.readStringRef();
  8249. if (!name)
  8250. throw new Error("Attachment name must not be null");
  8251. let attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name, nonessential);
  8252. if (attachment)
  8253. skin.setAttachment(slotIndex, name, attachment);
  8254. }
  8255. }
  8256. return skin;
  8257. }
  8258. readAttachment(input, skeletonData, skin, slotIndex, attachmentName, nonessential) {
  8259. let scale = this.scale;
  8260. let name = input.readStringRef();
  8261. if (!name)
  8262. name = attachmentName;
  8263. switch (input.readByte()) {
  8264. case AttachmentType.Region: {
  8265. let path = input.readStringRef();
  8266. let rotation = input.readFloat();
  8267. let x = input.readFloat();
  8268. let y = input.readFloat();
  8269. let scaleX = input.readFloat();
  8270. let scaleY = input.readFloat();
  8271. let width = input.readFloat();
  8272. let height = input.readFloat();
  8273. let color = input.readInt32();
  8274. let sequence = this.readSequence(input);
  8275. if (!path)
  8276. path = name;
  8277. let region = this.attachmentLoader.newRegionAttachment(skin, name, path, sequence);
  8278. if (!region)
  8279. return null;
  8280. region.path = path;
  8281. region.x = x * scale;
  8282. region.y = y * scale;
  8283. region.scaleX = scaleX;
  8284. region.scaleY = scaleY;
  8285. region.rotation = rotation;
  8286. region.width = width * scale;
  8287. region.height = height * scale;
  8288. Color.rgba8888ToColor(region.color, color);
  8289. region.sequence = sequence;
  8290. if (sequence == null)
  8291. region.updateRegion();
  8292. return region;
  8293. }
  8294. case AttachmentType.BoundingBox: {
  8295. let vertexCount = input.readInt(true);
  8296. let vertices = this.readVertices(input, vertexCount);
  8297. let color = nonessential ? input.readInt32() : 0;
  8298. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  8299. if (!box)
  8300. return null;
  8301. box.worldVerticesLength = vertexCount << 1;
  8302. box.vertices = vertices.vertices;
  8303. box.bones = vertices.bones;
  8304. if (nonessential)
  8305. Color.rgba8888ToColor(box.color, color);
  8306. return box;
  8307. }
  8308. case AttachmentType.Mesh: {
  8309. let path = input.readStringRef();
  8310. let color = input.readInt32();
  8311. let vertexCount = input.readInt(true);
  8312. let uvs = this.readFloatArray(input, vertexCount << 1, 1);
  8313. let triangles = this.readShortArray(input);
  8314. let vertices = this.readVertices(input, vertexCount);
  8315. let hullLength = input.readInt(true);
  8316. let sequence = this.readSequence(input);
  8317. let edges = [];
  8318. let width = 0, height = 0;
  8319. if (nonessential) {
  8320. edges = this.readShortArray(input);
  8321. width = input.readFloat();
  8322. height = input.readFloat();
  8323. }
  8324. if (!path)
  8325. path = name;
  8326. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence);
  8327. if (!mesh)
  8328. return null;
  8329. mesh.path = path;
  8330. Color.rgba8888ToColor(mesh.color, color);
  8331. mesh.bones = vertices.bones;
  8332. mesh.vertices = vertices.vertices;
  8333. mesh.worldVerticesLength = vertexCount << 1;
  8334. mesh.triangles = triangles;
  8335. mesh.regionUVs = uvs;
  8336. if (sequence == null)
  8337. mesh.updateRegion();
  8338. mesh.hullLength = hullLength << 1;
  8339. mesh.sequence = sequence;
  8340. if (nonessential) {
  8341. mesh.edges = edges;
  8342. mesh.width = width * scale;
  8343. mesh.height = height * scale;
  8344. }
  8345. return mesh;
  8346. }
  8347. case AttachmentType.LinkedMesh: {
  8348. let path = input.readStringRef();
  8349. let color = input.readInt32();
  8350. let skinName = input.readStringRef();
  8351. let parent = input.readStringRef();
  8352. let inheritTimelines = input.readBoolean();
  8353. let sequence = this.readSequence(input);
  8354. let width = 0, height = 0;
  8355. if (nonessential) {
  8356. width = input.readFloat();
  8357. height = input.readFloat();
  8358. }
  8359. if (!path)
  8360. path = name;
  8361. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence);
  8362. if (!mesh)
  8363. return null;
  8364. mesh.path = path;
  8365. Color.rgba8888ToColor(mesh.color, color);
  8366. mesh.sequence = sequence;
  8367. if (nonessential) {
  8368. mesh.width = width * scale;
  8369. mesh.height = height * scale;
  8370. }
  8371. this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritTimelines));
  8372. return mesh;
  8373. }
  8374. case AttachmentType.Path: {
  8375. let closed2 = input.readBoolean();
  8376. let constantSpeed = input.readBoolean();
  8377. let vertexCount = input.readInt(true);
  8378. let vertices = this.readVertices(input, vertexCount);
  8379. let lengths = Utils.newArray(vertexCount / 3, 0);
  8380. for (let i = 0, n = lengths.length; i < n; i++)
  8381. lengths[i] = input.readFloat() * scale;
  8382. let color = nonessential ? input.readInt32() : 0;
  8383. let path = this.attachmentLoader.newPathAttachment(skin, name);
  8384. if (!path)
  8385. return null;
  8386. path.closed = closed2;
  8387. path.constantSpeed = constantSpeed;
  8388. path.worldVerticesLength = vertexCount << 1;
  8389. path.vertices = vertices.vertices;
  8390. path.bones = vertices.bones;
  8391. path.lengths = lengths;
  8392. if (nonessential)
  8393. Color.rgba8888ToColor(path.color, color);
  8394. return path;
  8395. }
  8396. case AttachmentType.Point: {
  8397. let rotation = input.readFloat();
  8398. let x = input.readFloat();
  8399. let y = input.readFloat();
  8400. let color = nonessential ? input.readInt32() : 0;
  8401. let point = this.attachmentLoader.newPointAttachment(skin, name);
  8402. if (!point)
  8403. return null;
  8404. point.x = x * scale;
  8405. point.y = y * scale;
  8406. point.rotation = rotation;
  8407. if (nonessential)
  8408. Color.rgba8888ToColor(point.color, color);
  8409. return point;
  8410. }
  8411. case AttachmentType.Clipping: {
  8412. let endSlotIndex = input.readInt(true);
  8413. let vertexCount = input.readInt(true);
  8414. let vertices = this.readVertices(input, vertexCount);
  8415. let color = nonessential ? input.readInt32() : 0;
  8416. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  8417. if (!clip)
  8418. return null;
  8419. clip.endSlot = skeletonData.slots[endSlotIndex];
  8420. clip.worldVerticesLength = vertexCount << 1;
  8421. clip.vertices = vertices.vertices;
  8422. clip.bones = vertices.bones;
  8423. if (nonessential)
  8424. Color.rgba8888ToColor(clip.color, color);
  8425. return clip;
  8426. }
  8427. }
  8428. return null;
  8429. }
  8430. readSequence(input) {
  8431. if (!input.readBoolean())
  8432. return null;
  8433. let sequence = new Sequence(input.readInt(true));
  8434. sequence.start = input.readInt(true);
  8435. sequence.digits = input.readInt(true);
  8436. sequence.setupIndex = input.readInt(true);
  8437. return sequence;
  8438. }
  8439. readVertices(input, vertexCount) {
  8440. let scale = this.scale;
  8441. let verticesLength = vertexCount << 1;
  8442. let vertices = new Vertices();
  8443. if (!input.readBoolean()) {
  8444. vertices.vertices = this.readFloatArray(input, verticesLength, scale);
  8445. return vertices;
  8446. }
  8447. let weights = new Array();
  8448. let bonesArray = new Array();
  8449. for (let i = 0; i < vertexCount; i++) {
  8450. let boneCount = input.readInt(true);
  8451. bonesArray.push(boneCount);
  8452. for (let ii = 0; ii < boneCount; ii++) {
  8453. bonesArray.push(input.readInt(true));
  8454. weights.push(input.readFloat() * scale);
  8455. weights.push(input.readFloat() * scale);
  8456. weights.push(input.readFloat());
  8457. }
  8458. }
  8459. vertices.vertices = Utils.toFloatArray(weights);
  8460. vertices.bones = bonesArray;
  8461. return vertices;
  8462. }
  8463. readFloatArray(input, n, scale) {
  8464. let array = new Array(n);
  8465. if (scale == 1) {
  8466. for (let i = 0; i < n; i++)
  8467. array[i] = input.readFloat();
  8468. } else {
  8469. for (let i = 0; i < n; i++)
  8470. array[i] = input.readFloat() * scale;
  8471. }
  8472. return array;
  8473. }
  8474. readShortArray(input) {
  8475. let n = input.readInt(true);
  8476. let array = new Array(n);
  8477. for (let i = 0; i < n; i++)
  8478. array[i] = input.readShort();
  8479. return array;
  8480. }
  8481. readAnimation(input, name, skeletonData) {
  8482. input.readInt(true);
  8483. let timelines = new Array();
  8484. let scale = this.scale;
  8485. let tempColor1 = new Color();
  8486. let tempColor2 = new Color();
  8487. for (let i = 0, n = input.readInt(true); i < n; i++) {
  8488. let slotIndex = input.readInt(true);
  8489. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  8490. let timelineType = input.readByte();
  8491. let frameCount = input.readInt(true);
  8492. let frameLast = frameCount - 1;
  8493. switch (timelineType) {
  8494. case SLOT_ATTACHMENT: {
  8495. let timeline = new AttachmentTimeline(frameCount, slotIndex);
  8496. for (let frame = 0; frame < frameCount; frame++)
  8497. timeline.setFrame(frame, input.readFloat(), input.readStringRef());
  8498. timelines.push(timeline);
  8499. break;
  8500. }
  8501. case SLOT_RGBA: {
  8502. let bezierCount = input.readInt(true);
  8503. let timeline = new RGBATimeline(frameCount, bezierCount, slotIndex);
  8504. let time = input.readFloat();
  8505. let r = input.readUnsignedByte() / 255;
  8506. let g = input.readUnsignedByte() / 255;
  8507. let b = input.readUnsignedByte() / 255;
  8508. let a = input.readUnsignedByte() / 255;
  8509. for (let frame = 0, bezier = 0; ; frame++) {
  8510. timeline.setFrame(frame, time, r, g, b, a);
  8511. if (frame == frameLast)
  8512. break;
  8513. let time2 = input.readFloat();
  8514. let r2 = input.readUnsignedByte() / 255;
  8515. let g2 = input.readUnsignedByte() / 255;
  8516. let b2 = input.readUnsignedByte() / 255;
  8517. let a2 = input.readUnsignedByte() / 255;
  8518. switch (input.readByte()) {
  8519. case CURVE_STEPPED:
  8520. timeline.setStepped(frame);
  8521. break;
  8522. case CURVE_BEZIER:
  8523. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
  8524. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
  8525. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
  8526. setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1);
  8527. }
  8528. time = time2;
  8529. r = r2;
  8530. g = g2;
  8531. b = b2;
  8532. a = a2;
  8533. }
  8534. timelines.push(timeline);
  8535. break;
  8536. }
  8537. case SLOT_RGB: {
  8538. let bezierCount = input.readInt(true);
  8539. let timeline = new RGBTimeline(frameCount, bezierCount, slotIndex);
  8540. let time = input.readFloat();
  8541. let r = input.readUnsignedByte() / 255;
  8542. let g = input.readUnsignedByte() / 255;
  8543. let b = input.readUnsignedByte() / 255;
  8544. for (let frame = 0, bezier = 0; ; frame++) {
  8545. timeline.setFrame(frame, time, r, g, b);
  8546. if (frame == frameLast)
  8547. break;
  8548. let time2 = input.readFloat();
  8549. let r2 = input.readUnsignedByte() / 255;
  8550. let g2 = input.readUnsignedByte() / 255;
  8551. let b2 = input.readUnsignedByte() / 255;
  8552. switch (input.readByte()) {
  8553. case CURVE_STEPPED:
  8554. timeline.setStepped(frame);
  8555. break;
  8556. case CURVE_BEZIER:
  8557. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
  8558. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
  8559. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
  8560. }
  8561. time = time2;
  8562. r = r2;
  8563. g = g2;
  8564. b = b2;
  8565. }
  8566. timelines.push(timeline);
  8567. break;
  8568. }
  8569. case SLOT_RGBA2: {
  8570. let bezierCount = input.readInt(true);
  8571. let timeline = new RGBA2Timeline(frameCount, bezierCount, slotIndex);
  8572. let time = input.readFloat();
  8573. let r = input.readUnsignedByte() / 255;
  8574. let g = input.readUnsignedByte() / 255;
  8575. let b = input.readUnsignedByte() / 255;
  8576. let a = input.readUnsignedByte() / 255;
  8577. let r2 = input.readUnsignedByte() / 255;
  8578. let g2 = input.readUnsignedByte() / 255;
  8579. let b2 = input.readUnsignedByte() / 255;
  8580. for (let frame = 0, bezier = 0; ; frame++) {
  8581. timeline.setFrame(frame, time, r, g, b, a, r2, g2, b2);
  8582. if (frame == frameLast)
  8583. break;
  8584. let time2 = input.readFloat();
  8585. let nr = input.readUnsignedByte() / 255;
  8586. let ng = input.readUnsignedByte() / 255;
  8587. let nb = input.readUnsignedByte() / 255;
  8588. let na = input.readUnsignedByte() / 255;
  8589. let nr2 = input.readUnsignedByte() / 255;
  8590. let ng2 = input.readUnsignedByte() / 255;
  8591. let nb2 = input.readUnsignedByte() / 255;
  8592. switch (input.readByte()) {
  8593. case CURVE_STEPPED:
  8594. timeline.setStepped(frame);
  8595. break;
  8596. case CURVE_BEZIER:
  8597. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
  8598. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
  8599. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
  8600. setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1);
  8601. setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1);
  8602. setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1);
  8603. setBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1);
  8604. }
  8605. time = time2;
  8606. r = nr;
  8607. g = ng;
  8608. b = nb;
  8609. a = na;
  8610. r2 = nr2;
  8611. g2 = ng2;
  8612. b2 = nb2;
  8613. }
  8614. timelines.push(timeline);
  8615. break;
  8616. }
  8617. case SLOT_RGB2: {
  8618. let bezierCount = input.readInt(true);
  8619. let timeline = new RGB2Timeline(frameCount, bezierCount, slotIndex);
  8620. let time = input.readFloat();
  8621. let r = input.readUnsignedByte() / 255;
  8622. let g = input.readUnsignedByte() / 255;
  8623. let b = input.readUnsignedByte() / 255;
  8624. let r2 = input.readUnsignedByte() / 255;
  8625. let g2 = input.readUnsignedByte() / 255;
  8626. let b2 = input.readUnsignedByte() / 255;
  8627. for (let frame = 0, bezier = 0; ; frame++) {
  8628. timeline.setFrame(frame, time, r, g, b, r2, g2, b2);
  8629. if (frame == frameLast)
  8630. break;
  8631. let time2 = input.readFloat();
  8632. let nr = input.readUnsignedByte() / 255;
  8633. let ng = input.readUnsignedByte() / 255;
  8634. let nb = input.readUnsignedByte() / 255;
  8635. let nr2 = input.readUnsignedByte() / 255;
  8636. let ng2 = input.readUnsignedByte() / 255;
  8637. let nb2 = input.readUnsignedByte() / 255;
  8638. switch (input.readByte()) {
  8639. case CURVE_STEPPED:
  8640. timeline.setStepped(frame);
  8641. break;
  8642. case CURVE_BEZIER:
  8643. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
  8644. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
  8645. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
  8646. setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1);
  8647. setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1);
  8648. setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1);
  8649. }
  8650. time = time2;
  8651. r = nr;
  8652. g = ng;
  8653. b = nb;
  8654. r2 = nr2;
  8655. g2 = ng2;
  8656. b2 = nb2;
  8657. }
  8658. timelines.push(timeline);
  8659. break;
  8660. }
  8661. case SLOT_ALPHA: {
  8662. let timeline = new AlphaTimeline(frameCount, input.readInt(true), slotIndex);
  8663. let time = input.readFloat(), a = input.readUnsignedByte() / 255;
  8664. for (let frame = 0, bezier = 0; ; frame++) {
  8665. timeline.setFrame(frame, time, a);
  8666. if (frame == frameLast)
  8667. break;
  8668. let time2 = input.readFloat();
  8669. let a2 = input.readUnsignedByte() / 255;
  8670. switch (input.readByte()) {
  8671. case CURVE_STEPPED:
  8672. timeline.setStepped(frame);
  8673. break;
  8674. case CURVE_BEZIER:
  8675. setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1);
  8676. }
  8677. time = time2;
  8678. a = a2;
  8679. }
  8680. timelines.push(timeline);
  8681. }
  8682. }
  8683. }
  8684. }
  8685. for (let i = 0, n = input.readInt(true); i < n; i++) {
  8686. let boneIndex = input.readInt(true);
  8687. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  8688. let type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true);
  8689. switch (type) {
  8690. case BONE_ROTATE:
  8691. timelines.push(readTimeline1(input, new RotateTimeline(frameCount, bezierCount, boneIndex), 1));
  8692. break;
  8693. case BONE_TRANSLATE:
  8694. timelines.push(readTimeline2(input, new TranslateTimeline(frameCount, bezierCount, boneIndex), scale));
  8695. break;
  8696. case BONE_TRANSLATEX:
  8697. timelines.push(readTimeline1(input, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale));
  8698. break;
  8699. case BONE_TRANSLATEY:
  8700. timelines.push(readTimeline1(input, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale));
  8701. break;
  8702. case BONE_SCALE:
  8703. timelines.push(readTimeline2(input, new ScaleTimeline(frameCount, bezierCount, boneIndex), 1));
  8704. break;
  8705. case BONE_SCALEX:
  8706. timelines.push(readTimeline1(input, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1));
  8707. break;
  8708. case BONE_SCALEY:
  8709. timelines.push(readTimeline1(input, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1));
  8710. break;
  8711. case BONE_SHEAR:
  8712. timelines.push(readTimeline2(input, new ShearTimeline(frameCount, bezierCount, boneIndex), 1));
  8713. break;
  8714. case BONE_SHEARX:
  8715. timelines.push(readTimeline1(input, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1));
  8716. break;
  8717. case BONE_SHEARY:
  8718. timelines.push(readTimeline1(input, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1));
  8719. }
  8720. }
  8721. }
  8722. for (let i = 0, n = input.readInt(true); i < n; i++) {
  8723. let index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1;
  8724. let timeline = new IkConstraintTimeline(frameCount, input.readInt(true), index);
  8725. let time = input.readFloat(), mix = input.readFloat(), softness = input.readFloat() * scale;
  8726. for (let frame = 0, bezier = 0; ; frame++) {
  8727. timeline.setFrame(frame, time, mix, softness, input.readByte(), input.readBoolean(), input.readBoolean());
  8728. if (frame == frameLast)
  8729. break;
  8730. let time2 = input.readFloat(), mix2 = input.readFloat(), softness2 = input.readFloat() * scale;
  8731. switch (input.readByte()) {
  8732. case CURVE_STEPPED:
  8733. timeline.setStepped(frame);
  8734. break;
  8735. case CURVE_BEZIER:
  8736. setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1);
  8737. setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale);
  8738. }
  8739. time = time2;
  8740. mix = mix2;
  8741. softness = softness2;
  8742. }
  8743. timelines.push(timeline);
  8744. }
  8745. for (let i = 0, n = input.readInt(true); i < n; i++) {
  8746. let index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1;
  8747. let timeline = new TransformConstraintTimeline(frameCount, input.readInt(true), index);
  8748. let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(), mixScaleX = input.readFloat(), mixScaleY = input.readFloat(), mixShearY = input.readFloat();
  8749. for (let frame = 0, bezier = 0; ; frame++) {
  8750. timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
  8751. if (frame == frameLast)
  8752. break;
  8753. let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(), mixScaleX2 = input.readFloat(), mixScaleY2 = input.readFloat(), mixShearY2 = input.readFloat();
  8754. switch (input.readByte()) {
  8755. case CURVE_STEPPED:
  8756. timeline.setStepped(frame);
  8757. break;
  8758. case CURVE_BEZIER:
  8759. setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  8760. setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
  8761. setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
  8762. setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
  8763. setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
  8764. setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1);
  8765. }
  8766. time = time2;
  8767. mixRotate = mixRotate2;
  8768. mixX = mixX2;
  8769. mixY = mixY2;
  8770. mixScaleX = mixScaleX2;
  8771. mixScaleY = mixScaleY2;
  8772. mixShearY = mixShearY2;
  8773. }
  8774. timelines.push(timeline);
  8775. }
  8776. for (let i = 0, n = input.readInt(true); i < n; i++) {
  8777. let index = input.readInt(true);
  8778. let data = skeletonData.pathConstraints[index];
  8779. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  8780. switch (input.readByte()) {
  8781. case PATH_POSITION:
  8782. timelines.push(readTimeline1(
  8783. input,
  8784. new PathConstraintPositionTimeline(input.readInt(true), input.readInt(true), index),
  8785. data.positionMode == 0 /* Fixed */ ? scale : 1
  8786. ));
  8787. break;
  8788. case PATH_SPACING:
  8789. timelines.push(readTimeline1(
  8790. input,
  8791. new PathConstraintSpacingTimeline(input.readInt(true), input.readInt(true), index),
  8792. data.spacingMode == 0 /* Length */ || data.spacingMode == 1 /* Fixed */ ? scale : 1
  8793. ));
  8794. break;
  8795. case PATH_MIX:
  8796. let timeline = new PathConstraintMixTimeline(input.readInt(true), input.readInt(true), index);
  8797. let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat();
  8798. for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1; ; frame++) {
  8799. timeline.setFrame(frame, time, mixRotate, mixX, mixY);
  8800. if (frame == frameLast)
  8801. break;
  8802. let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat();
  8803. switch (input.readByte()) {
  8804. case CURVE_STEPPED:
  8805. timeline.setStepped(frame);
  8806. break;
  8807. case CURVE_BEZIER:
  8808. setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  8809. setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
  8810. setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
  8811. }
  8812. time = time2;
  8813. mixRotate = mixRotate2;
  8814. mixX = mixX2;
  8815. mixY = mixY2;
  8816. }
  8817. timelines.push(timeline);
  8818. }
  8819. }
  8820. }
  8821. for (let i = 0, n = input.readInt(true); i < n; i++) {
  8822. let skin = skeletonData.skins[input.readInt(true)];
  8823. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  8824. let slotIndex = input.readInt(true);
  8825. for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
  8826. let attachmentName = input.readStringRef();
  8827. if (!attachmentName)
  8828. throw new Error("attachmentName must not be null.");
  8829. let attachment = skin.getAttachment(slotIndex, attachmentName);
  8830. let timelineType = input.readByte();
  8831. let frameCount = input.readInt(true);
  8832. let frameLast = frameCount - 1;
  8833. switch (timelineType) {
  8834. case ATTACHMENT_DEFORM: {
  8835. let vertexAttachment = attachment;
  8836. let weighted = vertexAttachment.bones;
  8837. let vertices = vertexAttachment.vertices;
  8838. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  8839. let bezierCount = input.readInt(true);
  8840. let timeline = new DeformTimeline(frameCount, bezierCount, slotIndex, vertexAttachment);
  8841. let time = input.readFloat();
  8842. for (let frame = 0, bezier = 0; ; frame++) {
  8843. let deform;
  8844. let end = input.readInt(true);
  8845. if (end == 0)
  8846. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  8847. else {
  8848. deform = Utils.newFloatArray(deformLength);
  8849. let start = input.readInt(true);
  8850. end += start;
  8851. if (scale == 1) {
  8852. for (let v = start; v < end; v++)
  8853. deform[v] = input.readFloat();
  8854. } else {
  8855. for (let v = start; v < end; v++)
  8856. deform[v] = input.readFloat() * scale;
  8857. }
  8858. if (!weighted) {
  8859. for (let v = 0, vn = deform.length; v < vn; v++)
  8860. deform[v] += vertices[v];
  8861. }
  8862. }
  8863. timeline.setFrame(frame, time, deform);
  8864. if (frame == frameLast)
  8865. break;
  8866. let time2 = input.readFloat();
  8867. switch (input.readByte()) {
  8868. case CURVE_STEPPED:
  8869. timeline.setStepped(frame);
  8870. break;
  8871. case CURVE_BEZIER:
  8872. setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
  8873. }
  8874. time = time2;
  8875. }
  8876. timelines.push(timeline);
  8877. break;
  8878. }
  8879. case ATTACHMENT_SEQUENCE: {
  8880. let timeline = new SequenceTimeline(frameCount, slotIndex, attachment);
  8881. for (let frame = 0; frame < frameCount; frame++) {
  8882. let time = input.readFloat();
  8883. let modeAndIndex = input.readInt32();
  8884. timeline.setFrame(
  8885. frame,
  8886. time,
  8887. SequenceModeValues[modeAndIndex & 15],
  8888. modeAndIndex >> 4,
  8889. input.readFloat()
  8890. );
  8891. }
  8892. timelines.push(timeline);
  8893. break;
  8894. }
  8895. }
  8896. }
  8897. }
  8898. }
  8899. let drawOrderCount = input.readInt(true);
  8900. if (drawOrderCount > 0) {
  8901. let timeline = new DrawOrderTimeline(drawOrderCount);
  8902. let slotCount = skeletonData.slots.length;
  8903. for (let i = 0; i < drawOrderCount; i++) {
  8904. let time = input.readFloat();
  8905. let offsetCount = input.readInt(true);
  8906. let drawOrder = Utils.newArray(slotCount, 0);
  8907. for (let ii = slotCount - 1; ii >= 0; ii--)
  8908. drawOrder[ii] = -1;
  8909. let unchanged = Utils.newArray(slotCount - offsetCount, 0);
  8910. let originalIndex = 0, unchangedIndex = 0;
  8911. for (let ii = 0; ii < offsetCount; ii++) {
  8912. let slotIndex = input.readInt(true);
  8913. while (originalIndex != slotIndex)
  8914. unchanged[unchangedIndex++] = originalIndex++;
  8915. drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
  8916. }
  8917. while (originalIndex < slotCount)
  8918. unchanged[unchangedIndex++] = originalIndex++;
  8919. for (let ii = slotCount - 1; ii >= 0; ii--)
  8920. if (drawOrder[ii] == -1)
  8921. drawOrder[ii] = unchanged[--unchangedIndex];
  8922. timeline.setFrame(i, time, drawOrder);
  8923. }
  8924. timelines.push(timeline);
  8925. }
  8926. let eventCount = input.readInt(true);
  8927. if (eventCount > 0) {
  8928. let timeline = new EventTimeline(eventCount);
  8929. for (let i = 0; i < eventCount; i++) {
  8930. let time = input.readFloat();
  8931. let eventData = skeletonData.events[input.readInt(true)];
  8932. let event = new Event(time, eventData);
  8933. event.intValue = input.readInt(false);
  8934. event.floatValue = input.readFloat();
  8935. event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
  8936. if (event.data.audioPath) {
  8937. event.volume = input.readFloat();
  8938. event.balance = input.readFloat();
  8939. }
  8940. timeline.setFrame(i, event);
  8941. }
  8942. timelines.push(timeline);
  8943. }
  8944. let duration = 0;
  8945. for (let i = 0, n = timelines.length; i < n; i++)
  8946. duration = Math.max(duration, timelines[i].getDuration());
  8947. return new Animation(name, timelines, duration);
  8948. }
  8949. };
  8950. var BinaryInput = class {
  8951. constructor(data, strings = new Array(), index = 0, buffer = new DataView(data.buffer)) {
  8952. this.strings = strings;
  8953. this.index = index;
  8954. this.buffer = buffer;
  8955. }
  8956. readByte() {
  8957. return this.buffer.getInt8(this.index++);
  8958. }
  8959. readUnsignedByte() {
  8960. return this.buffer.getUint8(this.index++);
  8961. }
  8962. readShort() {
  8963. let value = this.buffer.getInt16(this.index);
  8964. this.index += 2;
  8965. return value;
  8966. }
  8967. readInt32() {
  8968. let value = this.buffer.getInt32(this.index);
  8969. this.index += 4;
  8970. return value;
  8971. }
  8972. readInt(optimizePositive) {
  8973. let b = this.readByte();
  8974. let result = b & 127;
  8975. if ((b & 128) != 0) {
  8976. b = this.readByte();
  8977. result |= (b & 127) << 7;
  8978. if ((b & 128) != 0) {
  8979. b = this.readByte();
  8980. result |= (b & 127) << 14;
  8981. if ((b & 128) != 0) {
  8982. b = this.readByte();
  8983. result |= (b & 127) << 21;
  8984. if ((b & 128) != 0) {
  8985. b = this.readByte();
  8986. result |= (b & 127) << 28;
  8987. }
  8988. }
  8989. }
  8990. }
  8991. return optimizePositive ? result : result >>> 1 ^ -(result & 1);
  8992. }
  8993. readStringRef() {
  8994. let index = this.readInt(true);
  8995. return index == 0 ? null : this.strings[index - 1];
  8996. }
  8997. readString() {
  8998. let byteCount = this.readInt(true);
  8999. switch (byteCount) {
  9000. case 0:
  9001. return null;
  9002. case 1:
  9003. return "";
  9004. }
  9005. byteCount--;
  9006. let chars = "";
  9007. let charCount = 0;
  9008. for (let i = 0; i < byteCount; ) {
  9009. let b = this.readUnsignedByte();
  9010. switch (b >> 4) {
  9011. case 12:
  9012. case 13:
  9013. chars += String.fromCharCode((b & 31) << 6 | this.readByte() & 63);
  9014. i += 2;
  9015. break;
  9016. case 14:
  9017. chars += String.fromCharCode((b & 15) << 12 | (this.readByte() & 63) << 6 | this.readByte() & 63);
  9018. i += 3;
  9019. break;
  9020. default:
  9021. chars += String.fromCharCode(b);
  9022. i++;
  9023. }
  9024. }
  9025. return chars;
  9026. }
  9027. readFloat() {
  9028. let value = this.buffer.getFloat32(this.index);
  9029. this.index += 4;
  9030. return value;
  9031. }
  9032. readBoolean() {
  9033. return this.readByte() != 0;
  9034. }
  9035. };
  9036. var LinkedMesh = class {
  9037. constructor(mesh, skin, slotIndex, parent, inheritDeform) {
  9038. this.mesh = mesh;
  9039. this.skin = skin;
  9040. this.slotIndex = slotIndex;
  9041. this.parent = parent;
  9042. this.inheritTimeline = inheritDeform;
  9043. }
  9044. };
  9045. var Vertices = class {
  9046. constructor(bones = null, vertices = null) {
  9047. this.bones = bones;
  9048. this.vertices = vertices;
  9049. }
  9050. };
  9051. var AttachmentType = /* @__PURE__ */ ((AttachmentType2) => {
  9052. AttachmentType2[AttachmentType2["Region"] = 0] = "Region";
  9053. AttachmentType2[AttachmentType2["BoundingBox"] = 1] = "BoundingBox";
  9054. AttachmentType2[AttachmentType2["Mesh"] = 2] = "Mesh";
  9055. AttachmentType2[AttachmentType2["LinkedMesh"] = 3] = "LinkedMesh";
  9056. AttachmentType2[AttachmentType2["Path"] = 4] = "Path";
  9057. AttachmentType2[AttachmentType2["Point"] = 5] = "Point";
  9058. AttachmentType2[AttachmentType2["Clipping"] = 6] = "Clipping";
  9059. return AttachmentType2;
  9060. })(AttachmentType || {});
  9061. function readTimeline1(input, timeline, scale) {
  9062. let time = input.readFloat(), value = input.readFloat() * scale;
  9063. for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1; ; frame++) {
  9064. timeline.setFrame(frame, time, value);
  9065. if (frame == frameLast)
  9066. break;
  9067. let time2 = input.readFloat(), value2 = input.readFloat() * scale;
  9068. switch (input.readByte()) {
  9069. case CURVE_STEPPED:
  9070. timeline.setStepped(frame);
  9071. break;
  9072. case CURVE_BEZIER:
  9073. setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, scale);
  9074. }
  9075. time = time2;
  9076. value = value2;
  9077. }
  9078. return timeline;
  9079. }
  9080. function readTimeline2(input, timeline, scale) {
  9081. let time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale;
  9082. for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1; ; frame++) {
  9083. timeline.setFrame(frame, time, value1, value2);
  9084. if (frame == frameLast)
  9085. break;
  9086. let time2 = input.readFloat(), nvalue1 = input.readFloat() * scale, nvalue2 = input.readFloat() * scale;
  9087. switch (input.readByte()) {
  9088. case CURVE_STEPPED:
  9089. timeline.setStepped(frame);
  9090. break;
  9091. case CURVE_BEZIER:
  9092. setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
  9093. setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);
  9094. }
  9095. time = time2;
  9096. value1 = nvalue1;
  9097. value2 = nvalue2;
  9098. }
  9099. return timeline;
  9100. }
  9101. function setBezier(input, timeline, bezier, frame, value, time1, time2, value1, value2, scale) {
  9102. timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2);
  9103. }
  9104. var BONE_ROTATE = 0;
  9105. var BONE_TRANSLATE = 1;
  9106. var BONE_TRANSLATEX = 2;
  9107. var BONE_TRANSLATEY = 3;
  9108. var BONE_SCALE = 4;
  9109. var BONE_SCALEX = 5;
  9110. var BONE_SCALEY = 6;
  9111. var BONE_SHEAR = 7;
  9112. var BONE_SHEARX = 8;
  9113. var BONE_SHEARY = 9;
  9114. var SLOT_ATTACHMENT = 0;
  9115. var SLOT_RGBA = 1;
  9116. var SLOT_RGB = 2;
  9117. var SLOT_RGBA2 = 3;
  9118. var SLOT_RGB2 = 4;
  9119. var SLOT_ALPHA = 5;
  9120. var ATTACHMENT_DEFORM = 0;
  9121. var ATTACHMENT_SEQUENCE = 1;
  9122. var PATH_POSITION = 0;
  9123. var PATH_SPACING = 1;
  9124. var PATH_MIX = 2;
  9125. var CURVE_STEPPED = 1;
  9126. var CURVE_BEZIER = 2;
  9127. // spine-core/src/SkeletonBounds.ts
  9128. var SkeletonBounds = class {
  9129. constructor() {
  9130. /** The left edge of the axis aligned bounding box. */
  9131. this.minX = 0;
  9132. /** The bottom edge of the axis aligned bounding box. */
  9133. this.minY = 0;
  9134. /** The right edge of the axis aligned bounding box. */
  9135. this.maxX = 0;
  9136. /** The top edge of the axis aligned bounding box. */
  9137. this.maxY = 0;
  9138. /** The visible bounding boxes. */
  9139. this.boundingBoxes = new Array();
  9140. /** The world vertices for the bounding box polygons. */
  9141. this.polygons = new Array();
  9142. this.polygonPool = new Pool(() => {
  9143. return Utils.newFloatArray(16);
  9144. });
  9145. }
  9146. /** Clears any previous polygons, finds all visible bounding box attachments, and computes the world vertices for each bounding
  9147. * box's polygon.
  9148. * @param updateAabb If true, the axis aligned bounding box containing all the polygons is computed. If false, the
  9149. * SkeletonBounds AABB methods will always return true. */
  9150. update(skeleton, updateAabb) {
  9151. if (!skeleton)
  9152. throw new Error("skeleton cannot be null.");
  9153. let boundingBoxes = this.boundingBoxes;
  9154. let polygons = this.polygons;
  9155. let polygonPool = this.polygonPool;
  9156. let slots = skeleton.slots;
  9157. let slotCount = slots.length;
  9158. boundingBoxes.length = 0;
  9159. polygonPool.freeAll(polygons);
  9160. polygons.length = 0;
  9161. for (let i = 0; i < slotCount; i++) {
  9162. let slot = slots[i];
  9163. if (!slot.bone.active)
  9164. continue;
  9165. let attachment = slot.getAttachment();
  9166. if (attachment instanceof BoundingBoxAttachment) {
  9167. let boundingBox = attachment;
  9168. boundingBoxes.push(boundingBox);
  9169. let polygon = polygonPool.obtain();
  9170. if (polygon.length != boundingBox.worldVerticesLength) {
  9171. polygon = Utils.newFloatArray(boundingBox.worldVerticesLength);
  9172. }
  9173. polygons.push(polygon);
  9174. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  9175. }
  9176. }
  9177. if (updateAabb) {
  9178. this.aabbCompute();
  9179. } else {
  9180. this.minX = Number.POSITIVE_INFINITY;
  9181. this.minY = Number.POSITIVE_INFINITY;
  9182. this.maxX = Number.NEGATIVE_INFINITY;
  9183. this.maxY = Number.NEGATIVE_INFINITY;
  9184. }
  9185. }
  9186. aabbCompute() {
  9187. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  9188. let polygons = this.polygons;
  9189. for (let i = 0, n = polygons.length; i < n; i++) {
  9190. let polygon = polygons[i];
  9191. let vertices = polygon;
  9192. for (let ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  9193. let x = vertices[ii];
  9194. let y = vertices[ii + 1];
  9195. minX = Math.min(minX, x);
  9196. minY = Math.min(minY, y);
  9197. maxX = Math.max(maxX, x);
  9198. maxY = Math.max(maxY, y);
  9199. }
  9200. }
  9201. this.minX = minX;
  9202. this.minY = minY;
  9203. this.maxX = maxX;
  9204. this.maxY = maxY;
  9205. }
  9206. /** Returns true if the axis aligned bounding box contains the point. */
  9207. aabbContainsPoint(x, y) {
  9208. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  9209. }
  9210. /** Returns true if the axis aligned bounding box intersects the line segment. */
  9211. aabbIntersectsSegment(x1, y1, x2, y2) {
  9212. let minX = this.minX;
  9213. let minY = this.minY;
  9214. let maxX = this.maxX;
  9215. let maxY = this.maxY;
  9216. if (x1 <= minX && x2 <= minX || y1 <= minY && y2 <= minY || x1 >= maxX && x2 >= maxX || y1 >= maxY && y2 >= maxY)
  9217. return false;
  9218. let m = (y2 - y1) / (x2 - x1);
  9219. let y = m * (minX - x1) + y1;
  9220. if (y > minY && y < maxY)
  9221. return true;
  9222. y = m * (maxX - x1) + y1;
  9223. if (y > minY && y < maxY)
  9224. return true;
  9225. let x = (minY - y1) / m + x1;
  9226. if (x > minX && x < maxX)
  9227. return true;
  9228. x = (maxY - y1) / m + x1;
  9229. if (x > minX && x < maxX)
  9230. return true;
  9231. return false;
  9232. }
  9233. /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */
  9234. aabbIntersectsSkeleton(bounds) {
  9235. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  9236. }
  9237. /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more
  9238. * efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */
  9239. containsPoint(x, y) {
  9240. let polygons = this.polygons;
  9241. for (let i = 0, n = polygons.length; i < n; i++)
  9242. if (this.containsPointPolygon(polygons[i], x, y))
  9243. return this.boundingBoxes[i];
  9244. return null;
  9245. }
  9246. /** Returns true if the polygon contains the point. */
  9247. containsPointPolygon(polygon, x, y) {
  9248. let vertices = polygon;
  9249. let nn = polygon.length;
  9250. let prevIndex = nn - 2;
  9251. let inside = false;
  9252. for (let ii = 0; ii < nn; ii += 2) {
  9253. let vertexY = vertices[ii + 1];
  9254. let prevY = vertices[prevIndex + 1];
  9255. if (vertexY < y && prevY >= y || prevY < y && vertexY >= y) {
  9256. let vertexX = vertices[ii];
  9257. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x)
  9258. inside = !inside;
  9259. }
  9260. prevIndex = ii;
  9261. }
  9262. return inside;
  9263. }
  9264. /** Returns the first bounding box attachment that contains any part of the line segment, or null. When doing many checks, it
  9265. * is usually more efficient to only call this method if {@link #aabbIntersectsSegment()} returns
  9266. * true. */
  9267. intersectsSegment(x1, y1, x2, y2) {
  9268. let polygons = this.polygons;
  9269. for (let i = 0, n = polygons.length; i < n; i++)
  9270. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2))
  9271. return this.boundingBoxes[i];
  9272. return null;
  9273. }
  9274. /** Returns true if the polygon contains any part of the line segment. */
  9275. intersectsSegmentPolygon(polygon, x1, y1, x2, y2) {
  9276. let vertices = polygon;
  9277. let nn = polygon.length;
  9278. let width12 = x1 - x2, height12 = y1 - y2;
  9279. let det1 = x1 * y2 - y1 * x2;
  9280. let x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  9281. for (let ii = 0; ii < nn; ii += 2) {
  9282. let x4 = vertices[ii], y4 = vertices[ii + 1];
  9283. let det2 = x3 * y4 - y3 * x4;
  9284. let width34 = x3 - x4, height34 = y3 - y4;
  9285. let det3 = width12 * height34 - height12 * width34;
  9286. let x = (det1 * width34 - width12 * det2) / det3;
  9287. if ((x >= x3 && x <= x4 || x >= x4 && x <= x3) && (x >= x1 && x <= x2 || x >= x2 && x <= x1)) {
  9288. let y = (det1 * height34 - height12 * det2) / det3;
  9289. if ((y >= y3 && y <= y4 || y >= y4 && y <= y3) && (y >= y1 && y <= y2 || y >= y2 && y <= y1))
  9290. return true;
  9291. }
  9292. x3 = x4;
  9293. y3 = y4;
  9294. }
  9295. return false;
  9296. }
  9297. /** Returns the polygon for the specified bounding box, or null. */
  9298. getPolygon(boundingBox) {
  9299. if (!boundingBox)
  9300. throw new Error("boundingBox cannot be null.");
  9301. let index = this.boundingBoxes.indexOf(boundingBox);
  9302. return index == -1 ? null : this.polygons[index];
  9303. }
  9304. /** The width of the axis aligned bounding box. */
  9305. getWidth() {
  9306. return this.maxX - this.minX;
  9307. }
  9308. /** The height of the axis aligned bounding box. */
  9309. getHeight() {
  9310. return this.maxY - this.minY;
  9311. }
  9312. };
  9313. // spine-core/src/Triangulator.ts
  9314. var Triangulator = class {
  9315. constructor() {
  9316. this.convexPolygons = new Array();
  9317. this.convexPolygonsIndices = new Array();
  9318. this.indicesArray = new Array();
  9319. this.isConcaveArray = new Array();
  9320. this.triangles = new Array();
  9321. this.polygonPool = new Pool(() => {
  9322. return new Array();
  9323. });
  9324. this.polygonIndicesPool = new Pool(() => {
  9325. return new Array();
  9326. });
  9327. }
  9328. triangulate(verticesArray) {
  9329. let vertices = verticesArray;
  9330. let vertexCount = verticesArray.length >> 1;
  9331. let indices = this.indicesArray;
  9332. indices.length = 0;
  9333. for (let i = 0; i < vertexCount; i++)
  9334. indices[i] = i;
  9335. let isConcave = this.isConcaveArray;
  9336. isConcave.length = 0;
  9337. for (let i = 0, n = vertexCount; i < n; ++i)
  9338. isConcave[i] = Triangulator.isConcave(i, vertexCount, vertices, indices);
  9339. let triangles = this.triangles;
  9340. triangles.length = 0;
  9341. while (vertexCount > 3) {
  9342. let previous = vertexCount - 1, i = 0, next = 1;
  9343. while (true) {
  9344. outer:
  9345. if (!isConcave[i]) {
  9346. let p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1;
  9347. let p1x = vertices[p1], p1y = vertices[p1 + 1];
  9348. let p2x = vertices[p2], p2y = vertices[p2 + 1];
  9349. let p3x = vertices[p3], p3y = vertices[p3 + 1];
  9350. for (let ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
  9351. if (!isConcave[ii])
  9352. continue;
  9353. let v = indices[ii] << 1;
  9354. let vx = vertices[v], vy = vertices[v + 1];
  9355. if (Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
  9356. if (Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
  9357. if (Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy))
  9358. break outer;
  9359. }
  9360. }
  9361. }
  9362. break;
  9363. }
  9364. if (next == 0) {
  9365. do {
  9366. if (!isConcave[i])
  9367. break;
  9368. i--;
  9369. } while (i > 0);
  9370. break;
  9371. }
  9372. previous = i;
  9373. i = next;
  9374. next = (next + 1) % vertexCount;
  9375. }
  9376. triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
  9377. triangles.push(indices[i]);
  9378. triangles.push(indices[(i + 1) % vertexCount]);
  9379. indices.splice(i, 1);
  9380. isConcave.splice(i, 1);
  9381. vertexCount--;
  9382. let previousIndex = (vertexCount + i - 1) % vertexCount;
  9383. let nextIndex = i == vertexCount ? 0 : i;
  9384. isConcave[previousIndex] = Triangulator.isConcave(previousIndex, vertexCount, vertices, indices);
  9385. isConcave[nextIndex] = Triangulator.isConcave(nextIndex, vertexCount, vertices, indices);
  9386. }
  9387. if (vertexCount == 3) {
  9388. triangles.push(indices[2]);
  9389. triangles.push(indices[0]);
  9390. triangles.push(indices[1]);
  9391. }
  9392. return triangles;
  9393. }
  9394. decompose(verticesArray, triangles) {
  9395. let vertices = verticesArray;
  9396. let convexPolygons = this.convexPolygons;
  9397. this.polygonPool.freeAll(convexPolygons);
  9398. convexPolygons.length = 0;
  9399. let convexPolygonsIndices = this.convexPolygonsIndices;
  9400. this.polygonIndicesPool.freeAll(convexPolygonsIndices);
  9401. convexPolygonsIndices.length = 0;
  9402. let polygonIndices = this.polygonIndicesPool.obtain();
  9403. polygonIndices.length = 0;
  9404. let polygon = this.polygonPool.obtain();
  9405. polygon.length = 0;
  9406. let fanBaseIndex = -1, lastWinding = 0;
  9407. for (let i = 0, n = triangles.length; i < n; i += 3) {
  9408. let t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1;
  9409. let x1 = vertices[t1], y1 = vertices[t1 + 1];
  9410. let x2 = vertices[t2], y2 = vertices[t2 + 1];
  9411. let x3 = vertices[t3], y3 = vertices[t3 + 1];
  9412. let merged = false;
  9413. if (fanBaseIndex == t1) {
  9414. let o = polygon.length - 4;
  9415. let winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
  9416. let winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
  9417. if (winding1 == lastWinding && winding2 == lastWinding) {
  9418. polygon.push(x3);
  9419. polygon.push(y3);
  9420. polygonIndices.push(t3);
  9421. merged = true;
  9422. }
  9423. }
  9424. if (!merged) {
  9425. if (polygon.length > 0) {
  9426. convexPolygons.push(polygon);
  9427. convexPolygonsIndices.push(polygonIndices);
  9428. } else {
  9429. this.polygonPool.free(polygon);
  9430. this.polygonIndicesPool.free(polygonIndices);
  9431. }
  9432. polygon = this.polygonPool.obtain();
  9433. polygon.length = 0;
  9434. polygon.push(x1);
  9435. polygon.push(y1);
  9436. polygon.push(x2);
  9437. polygon.push(y2);
  9438. polygon.push(x3);
  9439. polygon.push(y3);
  9440. polygonIndices = this.polygonIndicesPool.obtain();
  9441. polygonIndices.length = 0;
  9442. polygonIndices.push(t1);
  9443. polygonIndices.push(t2);
  9444. polygonIndices.push(t3);
  9445. lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
  9446. fanBaseIndex = t1;
  9447. }
  9448. }
  9449. if (polygon.length > 0) {
  9450. convexPolygons.push(polygon);
  9451. convexPolygonsIndices.push(polygonIndices);
  9452. }
  9453. for (let i = 0, n = convexPolygons.length; i < n; i++) {
  9454. polygonIndices = convexPolygonsIndices[i];
  9455. if (polygonIndices.length == 0)
  9456. continue;
  9457. let firstIndex = polygonIndices[0];
  9458. let lastIndex = polygonIndices[polygonIndices.length - 1];
  9459. polygon = convexPolygons[i];
  9460. let o = polygon.length - 4;
  9461. let prevPrevX = polygon[o], prevPrevY = polygon[o + 1];
  9462. let prevX = polygon[o + 2], prevY = polygon[o + 3];
  9463. let firstX = polygon[0], firstY = polygon[1];
  9464. let secondX = polygon[2], secondY = polygon[3];
  9465. let winding = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
  9466. for (let ii = 0; ii < n; ii++) {
  9467. if (ii == i)
  9468. continue;
  9469. let otherIndices = convexPolygonsIndices[ii];
  9470. if (otherIndices.length != 3)
  9471. continue;
  9472. let otherFirstIndex = otherIndices[0];
  9473. let otherSecondIndex = otherIndices[1];
  9474. let otherLastIndex = otherIndices[2];
  9475. let otherPoly = convexPolygons[ii];
  9476. let x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1];
  9477. if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex)
  9478. continue;
  9479. let winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
  9480. let winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
  9481. if (winding1 == winding && winding2 == winding) {
  9482. otherPoly.length = 0;
  9483. otherIndices.length = 0;
  9484. polygon.push(x3);
  9485. polygon.push(y3);
  9486. polygonIndices.push(otherLastIndex);
  9487. prevPrevX = prevX;
  9488. prevPrevY = prevY;
  9489. prevX = x3;
  9490. prevY = y3;
  9491. ii = 0;
  9492. }
  9493. }
  9494. }
  9495. for (let i = convexPolygons.length - 1; i >= 0; i--) {
  9496. polygon = convexPolygons[i];
  9497. if (polygon.length == 0) {
  9498. convexPolygons.splice(i, 1);
  9499. this.polygonPool.free(polygon);
  9500. polygonIndices = convexPolygonsIndices[i];
  9501. convexPolygonsIndices.splice(i, 1);
  9502. this.polygonIndicesPool.free(polygonIndices);
  9503. }
  9504. }
  9505. return convexPolygons;
  9506. }
  9507. static isConcave(index, vertexCount, vertices, indices) {
  9508. let previous = indices[(vertexCount + index - 1) % vertexCount] << 1;
  9509. let current = indices[index] << 1;
  9510. let next = indices[(index + 1) % vertexCount] << 1;
  9511. return !this.positiveArea(
  9512. vertices[previous],
  9513. vertices[previous + 1],
  9514. vertices[current],
  9515. vertices[current + 1],
  9516. vertices[next],
  9517. vertices[next + 1]
  9518. );
  9519. }
  9520. static positiveArea(p1x, p1y, p2x, p2y, p3x, p3y) {
  9521. return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
  9522. }
  9523. static winding(p1x, p1y, p2x, p2y, p3x, p3y) {
  9524. let px = p2x - p1x, py = p2y - p1y;
  9525. return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
  9526. }
  9527. };
  9528. // spine-core/src/SkeletonClipping.ts
  9529. var SkeletonClipping = class {
  9530. constructor() {
  9531. this.triangulator = new Triangulator();
  9532. this.clippingPolygon = new Array();
  9533. this.clipOutput = new Array();
  9534. this.clippedVertices = new Array();
  9535. this.clippedTriangles = new Array();
  9536. this.scratch = new Array();
  9537. this.clipAttachment = null;
  9538. this.clippingPolygons = null;
  9539. }
  9540. clipStart(slot, clip) {
  9541. if (this.clipAttachment)
  9542. return 0;
  9543. this.clipAttachment = clip;
  9544. let n = clip.worldVerticesLength;
  9545. let vertices = Utils.setArraySize(this.clippingPolygon, n);
  9546. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  9547. let clippingPolygon = this.clippingPolygon;
  9548. SkeletonClipping.makeClockwise(clippingPolygon);
  9549. let clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon));
  9550. for (let i = 0, n2 = clippingPolygons.length; i < n2; i++) {
  9551. let polygon = clippingPolygons[i];
  9552. SkeletonClipping.makeClockwise(polygon);
  9553. polygon.push(polygon[0]);
  9554. polygon.push(polygon[1]);
  9555. }
  9556. return clippingPolygons.length;
  9557. }
  9558. clipEndWithSlot(slot) {
  9559. if (this.clipAttachment && this.clipAttachment.endSlot == slot.data)
  9560. this.clipEnd();
  9561. }
  9562. clipEnd() {
  9563. if (!this.clipAttachment)
  9564. return;
  9565. this.clipAttachment = null;
  9566. this.clippingPolygons = null;
  9567. this.clippedVertices.length = 0;
  9568. this.clippedTriangles.length = 0;
  9569. this.clippingPolygon.length = 0;
  9570. }
  9571. isClipping() {
  9572. return this.clipAttachment != null;
  9573. }
  9574. clipTriangles(vertices, verticesLength, triangles, trianglesLength, uvs, light, dark, twoColor) {
  9575. let clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
  9576. let clippedTriangles = this.clippedTriangles;
  9577. let polygons = this.clippingPolygons;
  9578. let polygonsCount = polygons.length;
  9579. let vertexSize = twoColor ? 12 : 8;
  9580. let index = 0;
  9581. clippedVertices.length = 0;
  9582. clippedTriangles.length = 0;
  9583. outer:
  9584. for (let i = 0; i < trianglesLength; i += 3) {
  9585. let vertexOffset = triangles[i] << 1;
  9586. let x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
  9587. let u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
  9588. vertexOffset = triangles[i + 1] << 1;
  9589. let x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
  9590. let u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
  9591. vertexOffset = triangles[i + 2] << 1;
  9592. let x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
  9593. let u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
  9594. for (let p = 0; p < polygonsCount; p++) {
  9595. let s = clippedVertices.length;
  9596. if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
  9597. let clipOutputLength = clipOutput.length;
  9598. if (clipOutputLength == 0)
  9599. continue;
  9600. let d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
  9601. let d = 1 / (d0 * d2 + d1 * (y1 - y3));
  9602. let clipOutputCount = clipOutputLength >> 1;
  9603. let clipOutputItems = this.clipOutput;
  9604. let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize);
  9605. for (let ii = 0; ii < clipOutputLength; ii += 2) {
  9606. let x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
  9607. clippedVerticesItems[s] = x;
  9608. clippedVerticesItems[s + 1] = y;
  9609. clippedVerticesItems[s + 2] = light.r;
  9610. clippedVerticesItems[s + 3] = light.g;
  9611. clippedVerticesItems[s + 4] = light.b;
  9612. clippedVerticesItems[s + 5] = light.a;
  9613. let c0 = x - x3, c1 = y - y3;
  9614. let a = (d0 * c0 + d1 * c1) * d;
  9615. let b = (d4 * c0 + d2 * c1) * d;
  9616. let c = 1 - a - b;
  9617. clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
  9618. clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c;
  9619. if (twoColor) {
  9620. clippedVerticesItems[s + 8] = dark.r;
  9621. clippedVerticesItems[s + 9] = dark.g;
  9622. clippedVerticesItems[s + 10] = dark.b;
  9623. clippedVerticesItems[s + 11] = dark.a;
  9624. }
  9625. s += vertexSize;
  9626. }
  9627. s = clippedTriangles.length;
  9628. let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2));
  9629. clipOutputCount--;
  9630. for (let ii = 1; ii < clipOutputCount; ii++) {
  9631. clippedTrianglesItems[s] = index;
  9632. clippedTrianglesItems[s + 1] = index + ii;
  9633. clippedTrianglesItems[s + 2] = index + ii + 1;
  9634. s += 3;
  9635. }
  9636. index += clipOutputCount + 1;
  9637. } else {
  9638. let clippedVerticesItems = Utils.setArraySize(clippedVertices, s + 3 * vertexSize);
  9639. clippedVerticesItems[s] = x1;
  9640. clippedVerticesItems[s + 1] = y1;
  9641. clippedVerticesItems[s + 2] = light.r;
  9642. clippedVerticesItems[s + 3] = light.g;
  9643. clippedVerticesItems[s + 4] = light.b;
  9644. clippedVerticesItems[s + 5] = light.a;
  9645. if (!twoColor) {
  9646. clippedVerticesItems[s + 6] = u1;
  9647. clippedVerticesItems[s + 7] = v1;
  9648. clippedVerticesItems[s + 8] = x2;
  9649. clippedVerticesItems[s + 9] = y2;
  9650. clippedVerticesItems[s + 10] = light.r;
  9651. clippedVerticesItems[s + 11] = light.g;
  9652. clippedVerticesItems[s + 12] = light.b;
  9653. clippedVerticesItems[s + 13] = light.a;
  9654. clippedVerticesItems[s + 14] = u2;
  9655. clippedVerticesItems[s + 15] = v2;
  9656. clippedVerticesItems[s + 16] = x3;
  9657. clippedVerticesItems[s + 17] = y3;
  9658. clippedVerticesItems[s + 18] = light.r;
  9659. clippedVerticesItems[s + 19] = light.g;
  9660. clippedVerticesItems[s + 20] = light.b;
  9661. clippedVerticesItems[s + 21] = light.a;
  9662. clippedVerticesItems[s + 22] = u3;
  9663. clippedVerticesItems[s + 23] = v3;
  9664. } else {
  9665. clippedVerticesItems[s + 6] = u1;
  9666. clippedVerticesItems[s + 7] = v1;
  9667. clippedVerticesItems[s + 8] = dark.r;
  9668. clippedVerticesItems[s + 9] = dark.g;
  9669. clippedVerticesItems[s + 10] = dark.b;
  9670. clippedVerticesItems[s + 11] = dark.a;
  9671. clippedVerticesItems[s + 12] = x2;
  9672. clippedVerticesItems[s + 13] = y2;
  9673. clippedVerticesItems[s + 14] = light.r;
  9674. clippedVerticesItems[s + 15] = light.g;
  9675. clippedVerticesItems[s + 16] = light.b;
  9676. clippedVerticesItems[s + 17] = light.a;
  9677. clippedVerticesItems[s + 18] = u2;
  9678. clippedVerticesItems[s + 19] = v2;
  9679. clippedVerticesItems[s + 20] = dark.r;
  9680. clippedVerticesItems[s + 21] = dark.g;
  9681. clippedVerticesItems[s + 22] = dark.b;
  9682. clippedVerticesItems[s + 23] = dark.a;
  9683. clippedVerticesItems[s + 24] = x3;
  9684. clippedVerticesItems[s + 25] = y3;
  9685. clippedVerticesItems[s + 26] = light.r;
  9686. clippedVerticesItems[s + 27] = light.g;
  9687. clippedVerticesItems[s + 28] = light.b;
  9688. clippedVerticesItems[s + 29] = light.a;
  9689. clippedVerticesItems[s + 30] = u3;
  9690. clippedVerticesItems[s + 31] = v3;
  9691. clippedVerticesItems[s + 32] = dark.r;
  9692. clippedVerticesItems[s + 33] = dark.g;
  9693. clippedVerticesItems[s + 34] = dark.b;
  9694. clippedVerticesItems[s + 35] = dark.a;
  9695. }
  9696. s = clippedTriangles.length;
  9697. let clippedTrianglesItems = Utils.setArraySize(clippedTriangles, s + 3);
  9698. clippedTrianglesItems[s] = index;
  9699. clippedTrianglesItems[s + 1] = index + 1;
  9700. clippedTrianglesItems[s + 2] = index + 2;
  9701. index += 3;
  9702. continue outer;
  9703. }
  9704. }
  9705. }
  9706. }
  9707. /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
  9708. * area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */
  9709. clip(x1, y1, x2, y2, x3, y3, clippingArea, output) {
  9710. let originalOutput = output;
  9711. let clipped = false;
  9712. let input;
  9713. if (clippingArea.length % 4 >= 2) {
  9714. input = output;
  9715. output = this.scratch;
  9716. } else
  9717. input = this.scratch;
  9718. input.length = 0;
  9719. input.push(x1);
  9720. input.push(y1);
  9721. input.push(x2);
  9722. input.push(y2);
  9723. input.push(x3);
  9724. input.push(y3);
  9725. input.push(x1);
  9726. input.push(y1);
  9727. output.length = 0;
  9728. let clippingVertices = clippingArea;
  9729. let clippingVerticesLast = clippingArea.length - 4;
  9730. for (let i = 0; ; i += 2) {
  9731. let edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
  9732. let edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
  9733. let deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
  9734. let inputVertices = input;
  9735. let inputVerticesLength = input.length - 2, outputStart = output.length;
  9736. for (let ii = 0; ii < inputVerticesLength; ii += 2) {
  9737. let inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
  9738. let inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
  9739. let side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
  9740. if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
  9741. if (side2) {
  9742. output.push(inputX2);
  9743. output.push(inputY2);
  9744. continue;
  9745. }
  9746. let c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  9747. let s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY);
  9748. if (Math.abs(s) > 1e-6) {
  9749. let ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s;
  9750. output.push(edgeX + (edgeX2 - edgeX) * ua);
  9751. output.push(edgeY + (edgeY2 - edgeY) * ua);
  9752. } else {
  9753. output.push(edgeX);
  9754. output.push(edgeY);
  9755. }
  9756. } else if (side2) {
  9757. let c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  9758. let s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY);
  9759. if (Math.abs(s) > 1e-6) {
  9760. let ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s;
  9761. output.push(edgeX + (edgeX2 - edgeX) * ua);
  9762. output.push(edgeY + (edgeY2 - edgeY) * ua);
  9763. } else {
  9764. output.push(edgeX);
  9765. output.push(edgeY);
  9766. }
  9767. output.push(inputX2);
  9768. output.push(inputY2);
  9769. }
  9770. clipped = true;
  9771. }
  9772. if (outputStart == output.length) {
  9773. originalOutput.length = 0;
  9774. return true;
  9775. }
  9776. output.push(output[0]);
  9777. output.push(output[1]);
  9778. if (i == clippingVerticesLast)
  9779. break;
  9780. let temp = output;
  9781. output = input;
  9782. output.length = 0;
  9783. input = temp;
  9784. }
  9785. if (originalOutput != output) {
  9786. originalOutput.length = 0;
  9787. for (let i = 0, n = output.length - 2; i < n; i++)
  9788. originalOutput[i] = output[i];
  9789. } else
  9790. originalOutput.length = originalOutput.length - 2;
  9791. return clipped;
  9792. }
  9793. static makeClockwise(polygon) {
  9794. let vertices = polygon;
  9795. let verticeslength = polygon.length;
  9796. let area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0;
  9797. for (let i = 0, n = verticeslength - 3; i < n; i += 2) {
  9798. p1x = vertices[i];
  9799. p1y = vertices[i + 1];
  9800. p2x = vertices[i + 2];
  9801. p2y = vertices[i + 3];
  9802. area += p1x * p2y - p2x * p1y;
  9803. }
  9804. if (area < 0)
  9805. return;
  9806. for (let i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
  9807. let x = vertices[i], y = vertices[i + 1];
  9808. let other = lastX - i;
  9809. vertices[i] = vertices[other];
  9810. vertices[i + 1] = vertices[other + 1];
  9811. vertices[other] = x;
  9812. vertices[other + 1] = y;
  9813. }
  9814. }
  9815. };
  9816. // spine-core/src/SkeletonJson.ts
  9817. var SkeletonJson = class {
  9818. constructor(attachmentLoader) {
  9819. /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at
  9820. * runtime than were used in Spine.
  9821. *
  9822. * See [Scaling](http://esotericsoftware.com/spine-loading-skeleton-data#Scaling) in the Spine Runtimes Guide. */
  9823. this.scale = 1;
  9824. this.linkedMeshes = new Array();
  9825. this.attachmentLoader = attachmentLoader;
  9826. }
  9827. readSkeletonData(json) {
  9828. let scale = this.scale;
  9829. let skeletonData = new SkeletonData();
  9830. let root = typeof json === "string" ? JSON.parse(json) : json;
  9831. let skeletonMap = root.skeleton;
  9832. if (skeletonMap) {
  9833. skeletonData.hash = skeletonMap.hash;
  9834. skeletonData.version = skeletonMap.spine;
  9835. skeletonData.x = skeletonMap.x;
  9836. skeletonData.y = skeletonMap.y;
  9837. skeletonData.width = skeletonMap.width;
  9838. skeletonData.height = skeletonMap.height;
  9839. skeletonData.fps = skeletonMap.fps;
  9840. skeletonData.imagesPath = skeletonMap.images;
  9841. }
  9842. if (root.bones) {
  9843. for (let i = 0; i < root.bones.length; i++) {
  9844. let boneMap = root.bones[i];
  9845. let parent = null;
  9846. let parentName = getValue(boneMap, "parent", null);
  9847. if (parentName)
  9848. parent = skeletonData.findBone(parentName);
  9849. let data = new BoneData(skeletonData.bones.length, boneMap.name, parent);
  9850. data.length = getValue(boneMap, "length", 0) * scale;
  9851. data.x = getValue(boneMap, "x", 0) * scale;
  9852. data.y = getValue(boneMap, "y", 0) * scale;
  9853. data.rotation = getValue(boneMap, "rotation", 0);
  9854. data.scaleX = getValue(boneMap, "scaleX", 1);
  9855. data.scaleY = getValue(boneMap, "scaleY", 1);
  9856. data.shearX = getValue(boneMap, "shearX", 0);
  9857. data.shearY = getValue(boneMap, "shearY", 0);
  9858. data.transformMode = Utils.enumValue(TransformMode, getValue(boneMap, "transform", "Normal"));
  9859. data.skinRequired = getValue(boneMap, "skin", false);
  9860. let color = getValue(boneMap, "color", null);
  9861. if (color)
  9862. data.color.setFromString(color);
  9863. skeletonData.bones.push(data);
  9864. }
  9865. }
  9866. if (root.slots) {
  9867. for (let i = 0; i < root.slots.length; i++) {
  9868. let slotMap = root.slots[i];
  9869. let boneData = skeletonData.findBone(slotMap.bone);
  9870. if (!boneData)
  9871. throw new Error(`Couldn't find bone ${slotMap.bone} for slot ${slotMap.name}`);
  9872. let data = new SlotData(skeletonData.slots.length, slotMap.name, boneData);
  9873. let color = getValue(slotMap, "color", null);
  9874. if (color)
  9875. data.color.setFromString(color);
  9876. let dark = getValue(slotMap, "dark", null);
  9877. if (dark)
  9878. data.darkColor = Color.fromString(dark);
  9879. data.attachmentName = getValue(slotMap, "attachment", null);
  9880. data.blendMode = Utils.enumValue(BlendMode, getValue(slotMap, "blend", "normal"));
  9881. skeletonData.slots.push(data);
  9882. }
  9883. }
  9884. if (root.ik) {
  9885. for (let i = 0; i < root.ik.length; i++) {
  9886. let constraintMap = root.ik[i];
  9887. let data = new IkConstraintData(constraintMap.name);
  9888. data.order = getValue(constraintMap, "order", 0);
  9889. data.skinRequired = getValue(constraintMap, "skin", false);
  9890. for (let ii = 0; ii < constraintMap.bones.length; ii++) {
  9891. let bone = skeletonData.findBone(constraintMap.bones[ii]);
  9892. if (!bone)
  9893. throw new Error(`Couldn't find bone ${constraintMap.bones[ii]} for IK constraint ${constraintMap.name}.`);
  9894. data.bones.push(bone);
  9895. }
  9896. let target = skeletonData.findBone(constraintMap.target);
  9897. ;
  9898. if (!target)
  9899. throw new Error(`Couldn't find target bone ${constraintMap.target} for IK constraint ${constraintMap.name}.`);
  9900. data.target = target;
  9901. data.mix = getValue(constraintMap, "mix", 1);
  9902. data.softness = getValue(constraintMap, "softness", 0) * scale;
  9903. data.bendDirection = getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  9904. data.compress = getValue(constraintMap, "compress", false);
  9905. data.stretch = getValue(constraintMap, "stretch", false);
  9906. data.uniform = getValue(constraintMap, "uniform", false);
  9907. skeletonData.ikConstraints.push(data);
  9908. }
  9909. }
  9910. if (root.transform) {
  9911. for (let i = 0; i < root.transform.length; i++) {
  9912. let constraintMap = root.transform[i];
  9913. let data = new TransformConstraintData(constraintMap.name);
  9914. data.order = getValue(constraintMap, "order", 0);
  9915. data.skinRequired = getValue(constraintMap, "skin", false);
  9916. for (let ii = 0; ii < constraintMap.bones.length; ii++) {
  9917. let boneName = constraintMap.bones[ii];
  9918. let bone = skeletonData.findBone(boneName);
  9919. if (!bone)
  9920. throw new Error(`Couldn't find bone ${boneName} for transform constraint ${constraintMap.name}.`);
  9921. data.bones.push(bone);
  9922. }
  9923. let targetName = constraintMap.target;
  9924. let target = skeletonData.findBone(targetName);
  9925. if (!target)
  9926. throw new Error(`Couldn't find target bone ${targetName} for transform constraint ${constraintMap.name}.`);
  9927. data.target = target;
  9928. data.local = getValue(constraintMap, "local", false);
  9929. data.relative = getValue(constraintMap, "relative", false);
  9930. data.offsetRotation = getValue(constraintMap, "rotation", 0);
  9931. data.offsetX = getValue(constraintMap, "x", 0) * scale;
  9932. data.offsetY = getValue(constraintMap, "y", 0) * scale;
  9933. data.offsetScaleX = getValue(constraintMap, "scaleX", 0);
  9934. data.offsetScaleY = getValue(constraintMap, "scaleY", 0);
  9935. data.offsetShearY = getValue(constraintMap, "shearY", 0);
  9936. data.mixRotate = getValue(constraintMap, "mixRotate", 1);
  9937. data.mixX = getValue(constraintMap, "mixX", 1);
  9938. data.mixY = getValue(constraintMap, "mixY", data.mixX);
  9939. data.mixScaleX = getValue(constraintMap, "mixScaleX", 1);
  9940. data.mixScaleY = getValue(constraintMap, "mixScaleY", data.mixScaleX);
  9941. data.mixShearY = getValue(constraintMap, "mixShearY", 1);
  9942. skeletonData.transformConstraints.push(data);
  9943. }
  9944. }
  9945. if (root.path) {
  9946. for (let i = 0; i < root.path.length; i++) {
  9947. let constraintMap = root.path[i];
  9948. let data = new PathConstraintData(constraintMap.name);
  9949. data.order = getValue(constraintMap, "order", 0);
  9950. data.skinRequired = getValue(constraintMap, "skin", false);
  9951. for (let ii = 0; ii < constraintMap.bones.length; ii++) {
  9952. let boneName = constraintMap.bones[ii];
  9953. let bone = skeletonData.findBone(boneName);
  9954. if (!bone)
  9955. throw new Error(`Couldn't find bone ${boneName} for path constraint ${constraintMap.name}.`);
  9956. data.bones.push(bone);
  9957. }
  9958. let targetName = constraintMap.target;
  9959. let target = skeletonData.findSlot(targetName);
  9960. if (!target)
  9961. throw new Error(`Couldn't find target slot ${targetName} for path constraint ${constraintMap.name}.`);
  9962. data.target = target;
  9963. data.positionMode = Utils.enumValue(PositionMode, getValue(constraintMap, "positionMode", "Percent"));
  9964. data.spacingMode = Utils.enumValue(SpacingMode, getValue(constraintMap, "spacingMode", "Length"));
  9965. data.rotateMode = Utils.enumValue(RotateMode, getValue(constraintMap, "rotateMode", "Tangent"));
  9966. data.offsetRotation = getValue(constraintMap, "rotation", 0);
  9967. data.position = getValue(constraintMap, "position", 0);
  9968. if (data.positionMode == 0 /* Fixed */)
  9969. data.position *= scale;
  9970. data.spacing = getValue(constraintMap, "spacing", 0);
  9971. if (data.spacingMode == 0 /* Length */ || data.spacingMode == 1 /* Fixed */)
  9972. data.spacing *= scale;
  9973. data.mixRotate = getValue(constraintMap, "mixRotate", 1);
  9974. data.mixX = getValue(constraintMap, "mixX", 1);
  9975. data.mixY = getValue(constraintMap, "mixY", data.mixX);
  9976. skeletonData.pathConstraints.push(data);
  9977. }
  9978. }
  9979. if (root.skins) {
  9980. for (let i = 0; i < root.skins.length; i++) {
  9981. let skinMap = root.skins[i];
  9982. let skin = new Skin(skinMap.name);
  9983. if (skinMap.bones) {
  9984. for (let ii = 0; ii < skinMap.bones.length; ii++) {
  9985. let boneName = skinMap.bones[ii];
  9986. let bone = skeletonData.findBone(boneName);
  9987. if (!bone)
  9988. throw new Error(`Couldn't find bone ${boneName} for skin ${skinMap.name}.`);
  9989. skin.bones.push(bone);
  9990. }
  9991. }
  9992. if (skinMap.ik) {
  9993. for (let ii = 0; ii < skinMap.ik.length; ii++) {
  9994. let constraintName = skinMap.ik[ii];
  9995. let constraint = skeletonData.findIkConstraint(constraintName);
  9996. if (!constraint)
  9997. throw new Error(`Couldn't find IK constraint ${constraintName} for skin ${skinMap.name}.`);
  9998. skin.constraints.push(constraint);
  9999. }
  10000. }
  10001. if (skinMap.transform) {
  10002. for (let ii = 0; ii < skinMap.transform.length; ii++) {
  10003. let constraintName = skinMap.transform[ii];
  10004. let constraint = skeletonData.findTransformConstraint(constraintName);
  10005. if (!constraint)
  10006. throw new Error(`Couldn't find transform constraint ${constraintName} for skin ${skinMap.name}.`);
  10007. skin.constraints.push(constraint);
  10008. }
  10009. }
  10010. if (skinMap.path) {
  10011. for (let ii = 0; ii < skinMap.path.length; ii++) {
  10012. let constraintName = skinMap.path[ii];
  10013. let constraint = skeletonData.findPathConstraint(constraintName);
  10014. if (!constraint)
  10015. throw new Error(`Couldn't find path constraint ${constraintName} for skin ${skinMap.name}.`);
  10016. skin.constraints.push(constraint);
  10017. }
  10018. }
  10019. for (let slotName in skinMap.attachments) {
  10020. let slot = skeletonData.findSlot(slotName);
  10021. if (!slot)
  10022. throw new Error(`Couldn't find slot ${slotName} for skin ${skinMap.name}.`);
  10023. let slotMap = skinMap.attachments[slotName];
  10024. for (let entryName in slotMap) {
  10025. let attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
  10026. if (attachment)
  10027. skin.setAttachment(slot.index, entryName, attachment);
  10028. }
  10029. }
  10030. skeletonData.skins.push(skin);
  10031. if (skin.name == "default")
  10032. skeletonData.defaultSkin = skin;
  10033. }
  10034. }
  10035. for (let i = 0, n = this.linkedMeshes.length; i < n; i++) {
  10036. let linkedMesh = this.linkedMeshes[i];
  10037. let skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  10038. if (!skin)
  10039. throw new Error(`Skin not found: ${linkedMesh.skin}`);
  10040. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  10041. if (!parent)
  10042. throw new Error(`Parent mesh not found: ${linkedMesh.parent}`);
  10043. linkedMesh.mesh.timelineAttachment = linkedMesh.inheritTimeline ? parent : linkedMesh.mesh;
  10044. linkedMesh.mesh.setParentMesh(parent);
  10045. if (linkedMesh.mesh.region != null)
  10046. linkedMesh.mesh.updateRegion();
  10047. }
  10048. this.linkedMeshes.length = 0;
  10049. if (root.events) {
  10050. for (let eventName in root.events) {
  10051. let eventMap = root.events[eventName];
  10052. let data = new EventData(eventName);
  10053. data.intValue = getValue(eventMap, "int", 0);
  10054. data.floatValue = getValue(eventMap, "float", 0);
  10055. data.stringValue = getValue(eventMap, "string", "");
  10056. data.audioPath = getValue(eventMap, "audio", null);
  10057. if (data.audioPath) {
  10058. data.volume = getValue(eventMap, "volume", 1);
  10059. data.balance = getValue(eventMap, "balance", 0);
  10060. }
  10061. skeletonData.events.push(data);
  10062. }
  10063. }
  10064. if (root.animations) {
  10065. for (let animationName in root.animations) {
  10066. let animationMap = root.animations[animationName];
  10067. this.readAnimation(animationMap, animationName, skeletonData);
  10068. }
  10069. }
  10070. return skeletonData;
  10071. }
  10072. readAttachment(map, skin, slotIndex, name, skeletonData) {
  10073. let scale = this.scale;
  10074. name = getValue(map, "name", name);
  10075. switch (getValue(map, "type", "region")) {
  10076. case "region": {
  10077. let path = getValue(map, "path", name);
  10078. let sequence = this.readSequence(getValue(map, "sequence", null));
  10079. let region = this.attachmentLoader.newRegionAttachment(skin, name, path, sequence);
  10080. if (!region)
  10081. return null;
  10082. region.path = path;
  10083. region.x = getValue(map, "x", 0) * scale;
  10084. region.y = getValue(map, "y", 0) * scale;
  10085. region.scaleX = getValue(map, "scaleX", 1);
  10086. region.scaleY = getValue(map, "scaleY", 1);
  10087. region.rotation = getValue(map, "rotation", 0);
  10088. region.width = map.width * scale;
  10089. region.height = map.height * scale;
  10090. region.sequence = sequence;
  10091. let color = getValue(map, "color", null);
  10092. if (color)
  10093. region.color.setFromString(color);
  10094. if (region.region != null)
  10095. region.updateRegion();
  10096. return region;
  10097. }
  10098. case "boundingbox": {
  10099. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  10100. if (!box)
  10101. return null;
  10102. this.readVertices(map, box, map.vertexCount << 1);
  10103. let color = getValue(map, "color", null);
  10104. if (color)
  10105. box.color.setFromString(color);
  10106. return box;
  10107. }
  10108. case "mesh":
  10109. case "linkedmesh": {
  10110. let path = getValue(map, "path", name);
  10111. let sequence = this.readSequence(getValue(map, "sequence", null));
  10112. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path, sequence);
  10113. if (!mesh)
  10114. return null;
  10115. mesh.path = path;
  10116. let color = getValue(map, "color", null);
  10117. if (color)
  10118. mesh.color.setFromString(color);
  10119. mesh.width = getValue(map, "width", 0) * scale;
  10120. mesh.height = getValue(map, "height", 0) * scale;
  10121. mesh.sequence = sequence;
  10122. let parent = getValue(map, "parent", null);
  10123. if (parent) {
  10124. this.linkedMeshes.push(new LinkedMesh2(mesh, getValue(map, "skin", null), slotIndex, parent, getValue(map, "timelines", true)));
  10125. return mesh;
  10126. }
  10127. let uvs = map.uvs;
  10128. this.readVertices(map, mesh, uvs.length);
  10129. mesh.triangles = map.triangles;
  10130. mesh.regionUVs = uvs;
  10131. if (mesh.region != null)
  10132. mesh.updateRegion();
  10133. mesh.edges = getValue(map, "edges", null);
  10134. mesh.hullLength = getValue(map, "hull", 0) * 2;
  10135. return mesh;
  10136. }
  10137. case "path": {
  10138. let path = this.attachmentLoader.newPathAttachment(skin, name);
  10139. if (!path)
  10140. return null;
  10141. path.closed = getValue(map, "closed", false);
  10142. path.constantSpeed = getValue(map, "constantSpeed", true);
  10143. let vertexCount = map.vertexCount;
  10144. this.readVertices(map, path, vertexCount << 1);
  10145. let lengths = Utils.newArray(vertexCount / 3, 0);
  10146. for (let i = 0; i < map.lengths.length; i++)
  10147. lengths[i] = map.lengths[i] * scale;
  10148. path.lengths = lengths;
  10149. let color = getValue(map, "color", null);
  10150. if (color)
  10151. path.color.setFromString(color);
  10152. return path;
  10153. }
  10154. case "point": {
  10155. let point = this.attachmentLoader.newPointAttachment(skin, name);
  10156. if (!point)
  10157. return null;
  10158. point.x = getValue(map, "x", 0) * scale;
  10159. point.y = getValue(map, "y", 0) * scale;
  10160. point.rotation = getValue(map, "rotation", 0);
  10161. let color = getValue(map, "color", null);
  10162. if (color)
  10163. point.color.setFromString(color);
  10164. return point;
  10165. }
  10166. case "clipping": {
  10167. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  10168. if (!clip)
  10169. return null;
  10170. let end = getValue(map, "end", null);
  10171. if (end)
  10172. clip.endSlot = skeletonData.findSlot(end);
  10173. let vertexCount = map.vertexCount;
  10174. this.readVertices(map, clip, vertexCount << 1);
  10175. let color = getValue(map, "color", null);
  10176. if (color)
  10177. clip.color.setFromString(color);
  10178. return clip;
  10179. }
  10180. }
  10181. return null;
  10182. }
  10183. readSequence(map) {
  10184. if (map == null)
  10185. return null;
  10186. let sequence = new Sequence(getValue(map, "count", 0));
  10187. sequence.start = getValue(map, "start", 1);
  10188. sequence.digits = getValue(map, "digits", 0);
  10189. sequence.setupIndex = getValue(map, "setup", 0);
  10190. return sequence;
  10191. }
  10192. readVertices(map, attachment, verticesLength) {
  10193. let scale = this.scale;
  10194. attachment.worldVerticesLength = verticesLength;
  10195. let vertices = map.vertices;
  10196. if (verticesLength == vertices.length) {
  10197. let scaledVertices = Utils.toFloatArray(vertices);
  10198. if (scale != 1) {
  10199. for (let i = 0, n = vertices.length; i < n; i++)
  10200. scaledVertices[i] *= scale;
  10201. }
  10202. attachment.vertices = scaledVertices;
  10203. return;
  10204. }
  10205. let weights = new Array();
  10206. let bones = new Array();
  10207. for (let i = 0, n = vertices.length; i < n; ) {
  10208. let boneCount = vertices[i++];
  10209. bones.push(boneCount);
  10210. for (let nn = i + boneCount * 4; i < nn; i += 4) {
  10211. bones.push(vertices[i]);
  10212. weights.push(vertices[i + 1] * scale);
  10213. weights.push(vertices[i + 2] * scale);
  10214. weights.push(vertices[i + 3]);
  10215. }
  10216. }
  10217. attachment.bones = bones;
  10218. attachment.vertices = Utils.toFloatArray(weights);
  10219. }
  10220. readAnimation(map, name, skeletonData) {
  10221. let scale = this.scale;
  10222. let timelines = new Array();
  10223. if (map.slots) {
  10224. for (let slotName in map.slots) {
  10225. let slotMap = map.slots[slotName];
  10226. let slot = skeletonData.findSlot(slotName);
  10227. if (!slot)
  10228. throw new Error("Slot not found: " + slotName);
  10229. let slotIndex = slot.index;
  10230. for (let timelineName in slotMap) {
  10231. let timelineMap = slotMap[timelineName];
  10232. if (!timelineMap)
  10233. continue;
  10234. let frames = timelineMap.length;
  10235. if (timelineName == "attachment") {
  10236. let timeline = new AttachmentTimeline(frames, slotIndex);
  10237. for (let frame = 0; frame < frames; frame++) {
  10238. let keyMap = timelineMap[frame];
  10239. timeline.setFrame(frame, getValue(keyMap, "time", 0), getValue(keyMap, "name", null));
  10240. }
  10241. timelines.push(timeline);
  10242. } else if (timelineName == "rgba") {
  10243. let timeline = new RGBATimeline(frames, frames << 2, slotIndex);
  10244. let keyMap = timelineMap[0];
  10245. let time = getValue(keyMap, "time", 0);
  10246. let color = Color.fromString(keyMap.color);
  10247. for (let frame = 0, bezier = 0; ; frame++) {
  10248. timeline.setFrame(frame, time, color.r, color.g, color.b, color.a);
  10249. let nextMap = timelineMap[frame + 1];
  10250. if (!nextMap) {
  10251. timeline.shrink(bezier);
  10252. break;
  10253. }
  10254. let time2 = getValue(nextMap, "time", 0);
  10255. let newColor = Color.fromString(nextMap.color);
  10256. let curve = keyMap.curve;
  10257. if (curve) {
  10258. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  10259. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  10260. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  10261. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1);
  10262. }
  10263. time = time2;
  10264. color = newColor;
  10265. keyMap = nextMap;
  10266. }
  10267. timelines.push(timeline);
  10268. } else if (timelineName == "rgb") {
  10269. let timeline = new RGBTimeline(frames, frames * 3, slotIndex);
  10270. let keyMap = timelineMap[0];
  10271. let time = getValue(keyMap, "time", 0);
  10272. let color = Color.fromString(keyMap.color);
  10273. for (let frame = 0, bezier = 0; ; frame++) {
  10274. timeline.setFrame(frame, time, color.r, color.g, color.b);
  10275. let nextMap = timelineMap[frame + 1];
  10276. if (!nextMap) {
  10277. timeline.shrink(bezier);
  10278. break;
  10279. }
  10280. let time2 = getValue(nextMap, "time", 0);
  10281. let newColor = Color.fromString(nextMap.color);
  10282. let curve = keyMap.curve;
  10283. if (curve) {
  10284. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  10285. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  10286. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  10287. }
  10288. time = time2;
  10289. color = newColor;
  10290. keyMap = nextMap;
  10291. }
  10292. timelines.push(timeline);
  10293. } else if (timelineName == "alpha") {
  10294. timelines.push(readTimeline12(timelineMap, new AlphaTimeline(frames, frames, slotIndex), 0, 1));
  10295. } else if (timelineName == "rgba2") {
  10296. let timeline = new RGBA2Timeline(frames, frames * 7, slotIndex);
  10297. let keyMap = timelineMap[0];
  10298. let time = getValue(keyMap, "time", 0);
  10299. let color = Color.fromString(keyMap.light);
  10300. let color2 = Color.fromString(keyMap.dark);
  10301. for (let frame = 0, bezier = 0; ; frame++) {
  10302. timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b);
  10303. let nextMap = timelineMap[frame + 1];
  10304. if (!nextMap) {
  10305. timeline.shrink(bezier);
  10306. break;
  10307. }
  10308. let time2 = getValue(nextMap, "time", 0);
  10309. let newColor = Color.fromString(nextMap.light);
  10310. let newColor2 = Color.fromString(nextMap.dark);
  10311. let curve = keyMap.curve;
  10312. if (curve) {
  10313. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  10314. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  10315. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  10316. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1);
  10317. bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1);
  10318. bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1);
  10319. bezier = readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1);
  10320. }
  10321. time = time2;
  10322. color = newColor;
  10323. color2 = newColor2;
  10324. keyMap = nextMap;
  10325. }
  10326. timelines.push(timeline);
  10327. } else if (timelineName == "rgb2") {
  10328. let timeline = new RGB2Timeline(frames, frames * 6, slotIndex);
  10329. let keyMap = timelineMap[0];
  10330. let time = getValue(keyMap, "time", 0);
  10331. let color = Color.fromString(keyMap.light);
  10332. let color2 = Color.fromString(keyMap.dark);
  10333. for (let frame = 0, bezier = 0; ; frame++) {
  10334. timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b);
  10335. let nextMap = timelineMap[frame + 1];
  10336. if (!nextMap) {
  10337. timeline.shrink(bezier);
  10338. break;
  10339. }
  10340. let time2 = getValue(nextMap, "time", 0);
  10341. let newColor = Color.fromString(nextMap.light);
  10342. let newColor2 = Color.fromString(nextMap.dark);
  10343. let curve = keyMap.curve;
  10344. if (curve) {
  10345. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  10346. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  10347. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  10348. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1);
  10349. bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1);
  10350. bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1);
  10351. }
  10352. time = time2;
  10353. color = newColor;
  10354. color2 = newColor2;
  10355. keyMap = nextMap;
  10356. }
  10357. timelines.push(timeline);
  10358. }
  10359. }
  10360. }
  10361. }
  10362. if (map.bones) {
  10363. for (let boneName in map.bones) {
  10364. let boneMap = map.bones[boneName];
  10365. let bone = skeletonData.findBone(boneName);
  10366. if (!bone)
  10367. throw new Error("Bone not found: " + boneName);
  10368. let boneIndex = bone.index;
  10369. for (let timelineName in boneMap) {
  10370. let timelineMap = boneMap[timelineName];
  10371. let frames = timelineMap.length;
  10372. if (frames == 0)
  10373. continue;
  10374. if (timelineName === "rotate") {
  10375. timelines.push(readTimeline12(timelineMap, new RotateTimeline(frames, frames, boneIndex), 0, 1));
  10376. } else if (timelineName === "translate") {
  10377. let timeline = new TranslateTimeline(frames, frames << 1, boneIndex);
  10378. timelines.push(readTimeline22(timelineMap, timeline, "x", "y", 0, scale));
  10379. } else if (timelineName === "translatex") {
  10380. let timeline = new TranslateXTimeline(frames, frames, boneIndex);
  10381. timelines.push(readTimeline12(timelineMap, timeline, 0, scale));
  10382. } else if (timelineName === "translatey") {
  10383. let timeline = new TranslateYTimeline(frames, frames, boneIndex);
  10384. timelines.push(readTimeline12(timelineMap, timeline, 0, scale));
  10385. } else if (timelineName === "scale") {
  10386. let timeline = new ScaleTimeline(frames, frames << 1, boneIndex);
  10387. timelines.push(readTimeline22(timelineMap, timeline, "x", "y", 1, 1));
  10388. } else if (timelineName === "scalex") {
  10389. let timeline = new ScaleXTimeline(frames, frames, boneIndex);
  10390. timelines.push(readTimeline12(timelineMap, timeline, 1, 1));
  10391. } else if (timelineName === "scaley") {
  10392. let timeline = new ScaleYTimeline(frames, frames, boneIndex);
  10393. timelines.push(readTimeline12(timelineMap, timeline, 1, 1));
  10394. } else if (timelineName === "shear") {
  10395. let timeline = new ShearTimeline(frames, frames << 1, boneIndex);
  10396. timelines.push(readTimeline22(timelineMap, timeline, "x", "y", 0, 1));
  10397. } else if (timelineName === "shearx") {
  10398. let timeline = new ShearXTimeline(frames, frames, boneIndex);
  10399. timelines.push(readTimeline12(timelineMap, timeline, 0, 1));
  10400. } else if (timelineName === "sheary") {
  10401. let timeline = new ShearYTimeline(frames, frames, boneIndex);
  10402. timelines.push(readTimeline12(timelineMap, timeline, 0, 1));
  10403. }
  10404. }
  10405. }
  10406. }
  10407. if (map.ik) {
  10408. for (let constraintName in map.ik) {
  10409. let constraintMap = map.ik[constraintName];
  10410. let keyMap = constraintMap[0];
  10411. if (!keyMap)
  10412. continue;
  10413. let constraint = skeletonData.findIkConstraint(constraintName);
  10414. if (!constraint)
  10415. throw new Error("IK Constraint not found: " + constraintName);
  10416. let constraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  10417. let timeline = new IkConstraintTimeline(constraintMap.length, constraintMap.length << 1, constraintIndex);
  10418. let time = getValue(keyMap, "time", 0);
  10419. let mix = getValue(keyMap, "mix", 1);
  10420. let softness = getValue(keyMap, "softness", 0) * scale;
  10421. for (let frame = 0, bezier = 0; ; frame++) {
  10422. timeline.setFrame(frame, time, mix, softness, getValue(keyMap, "bendPositive", true) ? 1 : -1, getValue(keyMap, "compress", false), getValue(keyMap, "stretch", false));
  10423. let nextMap = constraintMap[frame + 1];
  10424. if (!nextMap) {
  10425. timeline.shrink(bezier);
  10426. break;
  10427. }
  10428. let time2 = getValue(nextMap, "time", 0);
  10429. let mix2 = getValue(nextMap, "mix", 1);
  10430. let softness2 = getValue(nextMap, "softness", 0) * scale;
  10431. let curve = keyMap.curve;
  10432. if (curve) {
  10433. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1);
  10434. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, scale);
  10435. }
  10436. time = time2;
  10437. mix = mix2;
  10438. softness = softness2;
  10439. keyMap = nextMap;
  10440. }
  10441. timelines.push(timeline);
  10442. }
  10443. }
  10444. if (map.transform) {
  10445. for (let constraintName in map.transform) {
  10446. let timelineMap = map.transform[constraintName];
  10447. let keyMap = timelineMap[0];
  10448. if (!keyMap)
  10449. continue;
  10450. let constraint = skeletonData.findTransformConstraint(constraintName);
  10451. if (!constraint)
  10452. throw new Error("Transform constraint not found: " + constraintName);
  10453. let constraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  10454. let timeline = new TransformConstraintTimeline(timelineMap.length, timelineMap.length * 6, constraintIndex);
  10455. let time = getValue(keyMap, "time", 0);
  10456. let mixRotate = getValue(keyMap, "mixRotate", 1);
  10457. let mixX = getValue(keyMap, "mixX", 1);
  10458. let mixY = getValue(keyMap, "mixY", mixX);
  10459. let mixScaleX = getValue(keyMap, "mixScaleX", 1);
  10460. let mixScaleY = getValue(keyMap, "mixScaleY", mixScaleX);
  10461. let mixShearY = getValue(keyMap, "mixShearY", 1);
  10462. for (let frame = 0, bezier = 0; ; frame++) {
  10463. timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
  10464. let nextMap = timelineMap[frame + 1];
  10465. if (!nextMap) {
  10466. timeline.shrink(bezier);
  10467. break;
  10468. }
  10469. let time2 = getValue(nextMap, "time", 0);
  10470. let mixRotate2 = getValue(nextMap, "mixRotate", 1);
  10471. let mixX2 = getValue(nextMap, "mixX", 1);
  10472. let mixY2 = getValue(nextMap, "mixY", mixX2);
  10473. let mixScaleX2 = getValue(nextMap, "mixScaleX", 1);
  10474. let mixScaleY2 = getValue(nextMap, "mixScaleY", mixScaleX2);
  10475. let mixShearY2 = getValue(nextMap, "mixShearY", 1);
  10476. let curve = keyMap.curve;
  10477. if (curve) {
  10478. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  10479. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1);
  10480. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1);
  10481. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
  10482. bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
  10483. bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1);
  10484. }
  10485. time = time2;
  10486. mixRotate = mixRotate2;
  10487. mixX = mixX2;
  10488. mixY = mixY2;
  10489. mixScaleX = mixScaleX2;
  10490. mixScaleY = mixScaleY2;
  10491. mixScaleX = mixScaleX2;
  10492. keyMap = nextMap;
  10493. }
  10494. timelines.push(timeline);
  10495. }
  10496. }
  10497. if (map.path) {
  10498. for (let constraintName in map.path) {
  10499. let constraintMap = map.path[constraintName];
  10500. let constraint = skeletonData.findPathConstraint(constraintName);
  10501. if (!constraint)
  10502. throw new Error("Path constraint not found: " + constraintName);
  10503. let constraintIndex = skeletonData.pathConstraints.indexOf(constraint);
  10504. for (let timelineName in constraintMap) {
  10505. let timelineMap = constraintMap[timelineName];
  10506. let keyMap = timelineMap[0];
  10507. if (!keyMap)
  10508. continue;
  10509. let frames = timelineMap.length;
  10510. if (timelineName === "position") {
  10511. let timeline = new PathConstraintPositionTimeline(frames, frames, constraintIndex);
  10512. timelines.push(readTimeline12(timelineMap, timeline, 0, constraint.positionMode == 0 /* Fixed */ ? scale : 1));
  10513. } else if (timelineName === "spacing") {
  10514. let timeline = new PathConstraintSpacingTimeline(frames, frames, constraintIndex);
  10515. timelines.push(readTimeline12(timelineMap, timeline, 0, constraint.spacingMode == 0 /* Length */ || constraint.spacingMode == 1 /* Fixed */ ? scale : 1));
  10516. } else if (timelineName === "mix") {
  10517. let timeline = new PathConstraintMixTimeline(frames, frames * 3, constraintIndex);
  10518. let time = getValue(keyMap, "time", 0);
  10519. let mixRotate = getValue(keyMap, "mixRotate", 1);
  10520. let mixX = getValue(keyMap, "mixX", 1);
  10521. let mixY = getValue(keyMap, "mixY", mixX);
  10522. for (let frame = 0, bezier = 0; ; frame++) {
  10523. timeline.setFrame(frame, time, mixRotate, mixX, mixY);
  10524. let nextMap = timelineMap[frame + 1];
  10525. if (!nextMap) {
  10526. timeline.shrink(bezier);
  10527. break;
  10528. }
  10529. let time2 = getValue(nextMap, "time", 0);
  10530. let mixRotate2 = getValue(nextMap, "mixRotate", 1);
  10531. let mixX2 = getValue(nextMap, "mixX", 1);
  10532. let mixY2 = getValue(nextMap, "mixY", mixX2);
  10533. let curve = keyMap.curve;
  10534. if (curve) {
  10535. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  10536. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1);
  10537. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1);
  10538. }
  10539. time = time2;
  10540. mixRotate = mixRotate2;
  10541. mixX = mixX2;
  10542. mixY = mixY2;
  10543. keyMap = nextMap;
  10544. }
  10545. timelines.push(timeline);
  10546. }
  10547. }
  10548. }
  10549. }
  10550. if (map.attachments) {
  10551. for (let attachmentsName in map.attachments) {
  10552. let attachmentsMap = map.attachments[attachmentsName];
  10553. let skin = skeletonData.findSkin(attachmentsName);
  10554. if (!skin)
  10555. throw new Error("Skin not found: " + attachmentsName);
  10556. for (let slotMapName in attachmentsMap) {
  10557. let slotMap = attachmentsMap[slotMapName];
  10558. let slot = skeletonData.findSlot(slotMapName);
  10559. if (!slot)
  10560. throw new Error("Slot not found: " + slotMapName);
  10561. let slotIndex = slot.index;
  10562. for (let attachmentMapName in slotMap) {
  10563. let attachmentMap = slotMap[attachmentMapName];
  10564. let attachment = skin.getAttachment(slotIndex, attachmentMapName);
  10565. for (let timelineMapName in attachmentMap) {
  10566. let timelineMap = attachmentMap[timelineMapName];
  10567. let keyMap = timelineMap[0];
  10568. if (!keyMap)
  10569. continue;
  10570. if (timelineMapName == "deform") {
  10571. let weighted = attachment.bones;
  10572. let vertices = attachment.vertices;
  10573. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  10574. let timeline = new DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment);
  10575. let time = getValue(keyMap, "time", 0);
  10576. for (let frame = 0, bezier = 0; ; frame++) {
  10577. let deform;
  10578. let verticesValue = getValue(keyMap, "vertices", null);
  10579. if (!verticesValue)
  10580. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  10581. else {
  10582. deform = Utils.newFloatArray(deformLength);
  10583. let start = getValue(keyMap, "offset", 0);
  10584. Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  10585. if (scale != 1) {
  10586. for (let i = start, n = i + verticesValue.length; i < n; i++)
  10587. deform[i] *= scale;
  10588. }
  10589. if (!weighted) {
  10590. for (let i = 0; i < deformLength; i++)
  10591. deform[i] += vertices[i];
  10592. }
  10593. }
  10594. timeline.setFrame(frame, time, deform);
  10595. let nextMap = timelineMap[frame + 1];
  10596. if (!nextMap) {
  10597. timeline.shrink(bezier);
  10598. break;
  10599. }
  10600. let time2 = getValue(nextMap, "time", 0);
  10601. let curve = keyMap.curve;
  10602. if (curve)
  10603. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
  10604. time = time2;
  10605. keyMap = nextMap;
  10606. }
  10607. timelines.push(timeline);
  10608. } else if (timelineMapName == "sequence") {
  10609. let timeline = new SequenceTimeline(timelineMap.length, slotIndex, attachment);
  10610. let lastDelay = 0;
  10611. for (let frame = 0; frame < timelineMap.length; frame++) {
  10612. let delay = getValue(keyMap, "delay", lastDelay);
  10613. let time = getValue(keyMap, "time", 0);
  10614. let mode = SequenceMode[getValue(keyMap, "mode", "hold")];
  10615. let index = getValue(keyMap, "index", 0);
  10616. timeline.setFrame(frame, time, mode, index, delay);
  10617. lastDelay = delay;
  10618. keyMap = timelineMap[frame + 1];
  10619. }
  10620. timelines.push(timeline);
  10621. }
  10622. }
  10623. }
  10624. }
  10625. }
  10626. }
  10627. if (map.drawOrder) {
  10628. let timeline = new DrawOrderTimeline(map.drawOrder.length);
  10629. let slotCount = skeletonData.slots.length;
  10630. let frame = 0;
  10631. for (let i = 0; i < map.drawOrder.length; i++, frame++) {
  10632. let drawOrderMap = map.drawOrder[i];
  10633. let drawOrder = null;
  10634. let offsets = getValue(drawOrderMap, "offsets", null);
  10635. if (offsets) {
  10636. drawOrder = Utils.newArray(slotCount, -1);
  10637. let unchanged = Utils.newArray(slotCount - offsets.length, 0);
  10638. let originalIndex = 0, unchangedIndex = 0;
  10639. for (let ii = 0; ii < offsets.length; ii++) {
  10640. let offsetMap = offsets[ii];
  10641. let slot = skeletonData.findSlot(offsetMap.slot);
  10642. if (!slot)
  10643. throw new Error("Slot not found: " + slot);
  10644. let slotIndex = slot.index;
  10645. while (originalIndex != slotIndex)
  10646. unchanged[unchangedIndex++] = originalIndex++;
  10647. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  10648. }
  10649. while (originalIndex < slotCount)
  10650. unchanged[unchangedIndex++] = originalIndex++;
  10651. for (let ii = slotCount - 1; ii >= 0; ii--)
  10652. if (drawOrder[ii] == -1)
  10653. drawOrder[ii] = unchanged[--unchangedIndex];
  10654. }
  10655. timeline.setFrame(frame, getValue(drawOrderMap, "time", 0), drawOrder);
  10656. }
  10657. timelines.push(timeline);
  10658. }
  10659. if (map.events) {
  10660. let timeline = new EventTimeline(map.events.length);
  10661. let frame = 0;
  10662. for (let i = 0; i < map.events.length; i++, frame++) {
  10663. let eventMap = map.events[i];
  10664. let eventData = skeletonData.findEvent(eventMap.name);
  10665. if (!eventData)
  10666. throw new Error("Event not found: " + eventMap.name);
  10667. let event = new Event(Utils.toSinglePrecision(getValue(eventMap, "time", 0)), eventData);
  10668. event.intValue = getValue(eventMap, "int", eventData.intValue);
  10669. event.floatValue = getValue(eventMap, "float", eventData.floatValue);
  10670. event.stringValue = getValue(eventMap, "string", eventData.stringValue);
  10671. if (event.data.audioPath) {
  10672. event.volume = getValue(eventMap, "volume", 1);
  10673. event.balance = getValue(eventMap, "balance", 0);
  10674. }
  10675. timeline.setFrame(frame, event);
  10676. }
  10677. timelines.push(timeline);
  10678. }
  10679. let duration = 0;
  10680. for (let i = 0, n = timelines.length; i < n; i++)
  10681. duration = Math.max(duration, timelines[i].getDuration());
  10682. skeletonData.animations.push(new Animation(name, timelines, duration));
  10683. }
  10684. };
  10685. var LinkedMesh2 = class {
  10686. constructor(mesh, skin, slotIndex, parent, inheritDeform) {
  10687. this.mesh = mesh;
  10688. this.skin = skin;
  10689. this.slotIndex = slotIndex;
  10690. this.parent = parent;
  10691. this.inheritTimeline = inheritDeform;
  10692. }
  10693. };
  10694. function readTimeline12(keys, timeline, defaultValue, scale) {
  10695. let keyMap = keys[0];
  10696. let time = getValue(keyMap, "time", 0);
  10697. let value = getValue(keyMap, "value", defaultValue) * scale;
  10698. let bezier = 0;
  10699. for (let frame = 0; ; frame++) {
  10700. timeline.setFrame(frame, time, value);
  10701. let nextMap = keys[frame + 1];
  10702. if (!nextMap) {
  10703. timeline.shrink(bezier);
  10704. return timeline;
  10705. }
  10706. let time2 = getValue(nextMap, "time", 0);
  10707. let value2 = getValue(nextMap, "value", defaultValue) * scale;
  10708. if (keyMap.curve)
  10709. bezier = readCurve(keyMap.curve, timeline, bezier, frame, 0, time, time2, value, value2, scale);
  10710. time = time2;
  10711. value = value2;
  10712. keyMap = nextMap;
  10713. }
  10714. }
  10715. function readTimeline22(keys, timeline, name1, name2, defaultValue, scale) {
  10716. let keyMap = keys[0];
  10717. let time = getValue(keyMap, "time", 0);
  10718. let value1 = getValue(keyMap, name1, defaultValue) * scale;
  10719. let value2 = getValue(keyMap, name2, defaultValue) * scale;
  10720. let bezier = 0;
  10721. for (let frame = 0; ; frame++) {
  10722. timeline.setFrame(frame, time, value1, value2);
  10723. let nextMap = keys[frame + 1];
  10724. if (!nextMap) {
  10725. timeline.shrink(bezier);
  10726. return timeline;
  10727. }
  10728. let time2 = getValue(nextMap, "time", 0);
  10729. let nvalue1 = getValue(nextMap, name1, defaultValue) * scale;
  10730. let nvalue2 = getValue(nextMap, name2, defaultValue) * scale;
  10731. let curve = keyMap.curve;
  10732. if (curve) {
  10733. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale);
  10734. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale);
  10735. }
  10736. time = time2;
  10737. value1 = nvalue1;
  10738. value2 = nvalue2;
  10739. keyMap = nextMap;
  10740. }
  10741. }
  10742. function readCurve(curve, timeline, bezier, frame, value, time1, time2, value1, value2, scale) {
  10743. if (curve == "stepped") {
  10744. timeline.setStepped(frame);
  10745. return bezier;
  10746. }
  10747. let i = value << 2;
  10748. let cx1 = curve[i];
  10749. let cy1 = curve[i + 1] * scale;
  10750. let cx2 = curve[i + 2];
  10751. let cy2 = curve[i + 3] * scale;
  10752. timeline.setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2);
  10753. return bezier + 1;
  10754. }
  10755. function getValue(map, property, defaultValue) {
  10756. return map[property] !== void 0 ? map[property] : defaultValue;
  10757. }
  10758. // spine-core/src/polyfills.ts
  10759. (() => {
  10760. if (typeof Math.fround === "undefined") {
  10761. Math.fround = function(array) {
  10762. return function(x) {
  10763. return array[0] = x, array[0];
  10764. };
  10765. }(new Float32Array(1));
  10766. }
  10767. })();
  10768. // spine-webgl/src/WebGL.ts
  10769. var ManagedWebGLRenderingContext = class {
  10770. constructor(canvasOrContext, contextConfig = { alpha: "true" }) {
  10771. this.restorables = new Array();
  10772. if (!(canvasOrContext instanceof WebGLRenderingContext || typeof WebGL2RenderingContext !== "undefined" && canvasOrContext instanceof WebGL2RenderingContext)) {
  10773. let canvas = canvasOrContext;
  10774. this.gl = canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig);
  10775. this.canvas = canvas;
  10776. canvas.addEventListener("webglcontextlost", (e) => {
  10777. let event = e;
  10778. if (e)
  10779. e.preventDefault();
  10780. });
  10781. canvas.addEventListener("webglcontextrestored", (e) => {
  10782. for (let i = 0, n = this.restorables.length; i < n; i++)
  10783. this.restorables[i].restore();
  10784. });
  10785. } else {
  10786. this.gl = canvasOrContext;
  10787. this.canvas = this.gl.canvas;
  10788. }
  10789. }
  10790. addRestorable(restorable) {
  10791. this.restorables.push(restorable);
  10792. }
  10793. removeRestorable(restorable) {
  10794. let index = this.restorables.indexOf(restorable);
  10795. if (index > -1)
  10796. this.restorables.splice(index, 1);
  10797. }
  10798. };
  10799. var ONE = 1;
  10800. var ONE_MINUS_SRC_COLOR = 769;
  10801. var SRC_ALPHA = 770;
  10802. var ONE_MINUS_SRC_ALPHA = 771;
  10803. var DST_COLOR = 774;
  10804. var WebGLBlendModeConverter = class {
  10805. static getDestGLBlendMode(blendMode) {
  10806. switch (blendMode) {
  10807. case 0 /* Normal */:
  10808. return ONE_MINUS_SRC_ALPHA;
  10809. case 1 /* Additive */:
  10810. return ONE;
  10811. case 2 /* Multiply */:
  10812. return ONE_MINUS_SRC_ALPHA;
  10813. case 3 /* Screen */:
  10814. return ONE_MINUS_SRC_ALPHA;
  10815. default:
  10816. throw new Error("Unknown blend mode: " + blendMode);
  10817. }
  10818. }
  10819. static getSourceColorGLBlendMode(blendMode, premultipliedAlpha = false) {
  10820. switch (blendMode) {
  10821. case 0 /* Normal */:
  10822. return premultipliedAlpha ? ONE : SRC_ALPHA;
  10823. case 1 /* Additive */:
  10824. return premultipliedAlpha ? ONE : SRC_ALPHA;
  10825. case 2 /* Multiply */:
  10826. return DST_COLOR;
  10827. case 3 /* Screen */:
  10828. return ONE;
  10829. default:
  10830. throw new Error("Unknown blend mode: " + blendMode);
  10831. }
  10832. }
  10833. static getSourceAlphaGLBlendMode(blendMode) {
  10834. switch (blendMode) {
  10835. case 0 /* Normal */:
  10836. return ONE;
  10837. case 1 /* Additive */:
  10838. return ONE;
  10839. case 2 /* Multiply */:
  10840. return ONE_MINUS_SRC_ALPHA;
  10841. case 3 /* Screen */:
  10842. return ONE_MINUS_SRC_COLOR;
  10843. default:
  10844. throw new Error("Unknown blend mode: " + blendMode);
  10845. }
  10846. }
  10847. };
  10848. // spine-webgl/src/GLTexture.ts
  10849. var _GLTexture = class extends Texture {
  10850. constructor(context, image, useMipMaps = false) {
  10851. super(image);
  10852. this.texture = null;
  10853. this.boundUnit = 0;
  10854. this.useMipMaps = false;
  10855. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  10856. this.useMipMaps = useMipMaps;
  10857. this.restore();
  10858. this.context.addRestorable(this);
  10859. }
  10860. setFilters(minFilter, magFilter) {
  10861. let gl = this.context.gl;
  10862. this.bind();
  10863. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  10864. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, _GLTexture.validateMagFilter(magFilter));
  10865. this.useMipMaps = _GLTexture.usesMipMaps(minFilter);
  10866. if (this.useMipMaps)
  10867. gl.generateMipmap(gl.TEXTURE_2D);
  10868. }
  10869. static validateMagFilter(magFilter) {
  10870. switch (magFilter) {
  10871. case 9987 /* MipMap */:
  10872. case 9987 /* MipMapLinearLinear */:
  10873. case 9985 /* MipMapLinearNearest */:
  10874. case 9986 /* MipMapNearestLinear */:
  10875. case 9984 /* MipMapNearestNearest */:
  10876. return 9729 /* Linear */;
  10877. default:
  10878. return magFilter;
  10879. }
  10880. }
  10881. static usesMipMaps(filter) {
  10882. switch (filter) {
  10883. case 9987 /* MipMap */:
  10884. case 9987 /* MipMapLinearLinear */:
  10885. case 9985 /* MipMapLinearNearest */:
  10886. case 9986 /* MipMapNearestLinear */:
  10887. case 9984 /* MipMapNearestNearest */:
  10888. return true;
  10889. default:
  10890. return false;
  10891. }
  10892. }
  10893. setWraps(uWrap, vWrap) {
  10894. let gl = this.context.gl;
  10895. this.bind();
  10896. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap);
  10897. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap);
  10898. }
  10899. update(useMipMaps) {
  10900. let gl = this.context.gl;
  10901. if (!this.texture)
  10902. this.texture = this.context.gl.createTexture();
  10903. this.bind();
  10904. if (_GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL)
  10905. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  10906. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image);
  10907. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  10908. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  10909. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  10910. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  10911. if (useMipMaps)
  10912. gl.generateMipmap(gl.TEXTURE_2D);
  10913. }
  10914. restore() {
  10915. this.texture = null;
  10916. this.update(this.useMipMaps);
  10917. }
  10918. bind(unit = 0) {
  10919. let gl = this.context.gl;
  10920. this.boundUnit = unit;
  10921. gl.activeTexture(gl.TEXTURE0 + unit);
  10922. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  10923. }
  10924. unbind() {
  10925. let gl = this.context.gl;
  10926. gl.activeTexture(gl.TEXTURE0 + this.boundUnit);
  10927. gl.bindTexture(gl.TEXTURE_2D, null);
  10928. }
  10929. dispose() {
  10930. this.context.removeRestorable(this);
  10931. let gl = this.context.gl;
  10932. gl.deleteTexture(this.texture);
  10933. }
  10934. };
  10935. var GLTexture = _GLTexture;
  10936. GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL = false;
  10937. // spine-webgl/src/AssetManager.ts
  10938. var AssetManager = class extends AssetManagerBase {
  10939. constructor(context, pathPrefix = "", downloader = new Downloader()) {
  10940. super((image) => {
  10941. return new GLTexture(context, image);
  10942. }, pathPrefix, downloader);
  10943. }
  10944. };
  10945. // spine-webgl/src/Vector3.ts
  10946. var Vector3 = class {
  10947. constructor(x = 0, y = 0, z = 0) {
  10948. this.x = 0;
  10949. this.y = 0;
  10950. this.z = 0;
  10951. this.x = x;
  10952. this.y = y;
  10953. this.z = z;
  10954. }
  10955. setFrom(v) {
  10956. this.x = v.x;
  10957. this.y = v.y;
  10958. this.z = v.z;
  10959. return this;
  10960. }
  10961. set(x, y, z) {
  10962. this.x = x;
  10963. this.y = y;
  10964. this.z = z;
  10965. return this;
  10966. }
  10967. add(v) {
  10968. this.x += v.x;
  10969. this.y += v.y;
  10970. this.z += v.z;
  10971. return this;
  10972. }
  10973. sub(v) {
  10974. this.x -= v.x;
  10975. this.y -= v.y;
  10976. this.z -= v.z;
  10977. return this;
  10978. }
  10979. scale(s) {
  10980. this.x *= s;
  10981. this.y *= s;
  10982. this.z *= s;
  10983. return this;
  10984. }
  10985. normalize() {
  10986. let len = this.length();
  10987. if (len == 0)
  10988. return this;
  10989. len = 1 / len;
  10990. this.x *= len;
  10991. this.y *= len;
  10992. this.z *= len;
  10993. return this;
  10994. }
  10995. cross(v) {
  10996. return this.set(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
  10997. }
  10998. multiply(matrix) {
  10999. let l_mat = matrix.values;
  11000. return this.set(
  11001. this.x * l_mat[M00] + this.y * l_mat[M01] + this.z * l_mat[M02] + l_mat[M03],
  11002. this.x * l_mat[M10] + this.y * l_mat[M11] + this.z * l_mat[M12] + l_mat[M13],
  11003. this.x * l_mat[M20] + this.y * l_mat[M21] + this.z * l_mat[M22] + l_mat[M23]
  11004. );
  11005. }
  11006. project(matrix) {
  11007. let l_mat = matrix.values;
  11008. let l_w = 1 / (this.x * l_mat[M30] + this.y * l_mat[M31] + this.z * l_mat[M32] + l_mat[M33]);
  11009. return this.set(
  11010. (this.x * l_mat[M00] + this.y * l_mat[M01] + this.z * l_mat[M02] + l_mat[M03]) * l_w,
  11011. (this.x * l_mat[M10] + this.y * l_mat[M11] + this.z * l_mat[M12] + l_mat[M13]) * l_w,
  11012. (this.x * l_mat[M20] + this.y * l_mat[M21] + this.z * l_mat[M22] + l_mat[M23]) * l_w
  11013. );
  11014. }
  11015. dot(v) {
  11016. return this.x * v.x + this.y * v.y + this.z * v.z;
  11017. }
  11018. length() {
  11019. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  11020. }
  11021. distance(v) {
  11022. let a = v.x - this.x;
  11023. let b = v.y - this.y;
  11024. let c = v.z - this.z;
  11025. return Math.sqrt(a * a + b * b + c * c);
  11026. }
  11027. };
  11028. // spine-webgl/src/Matrix4.ts
  11029. var M00 = 0;
  11030. var M01 = 4;
  11031. var M02 = 8;
  11032. var M03 = 12;
  11033. var M10 = 1;
  11034. var M11 = 5;
  11035. var M12 = 9;
  11036. var M13 = 13;
  11037. var M20 = 2;
  11038. var M21 = 6;
  11039. var M22 = 10;
  11040. var M23 = 14;
  11041. var M30 = 3;
  11042. var M31 = 7;
  11043. var M32 = 11;
  11044. var M33 = 15;
  11045. var _Matrix4 = class {
  11046. constructor() {
  11047. this.temp = new Float32Array(16);
  11048. this.values = new Float32Array(16);
  11049. let v = this.values;
  11050. v[M00] = 1;
  11051. v[M11] = 1;
  11052. v[M22] = 1;
  11053. v[M33] = 1;
  11054. }
  11055. set(values) {
  11056. this.values.set(values);
  11057. return this;
  11058. }
  11059. transpose() {
  11060. let t = this.temp;
  11061. let v = this.values;
  11062. t[M00] = v[M00];
  11063. t[M01] = v[M10];
  11064. t[M02] = v[M20];
  11065. t[M03] = v[M30];
  11066. t[M10] = v[M01];
  11067. t[M11] = v[M11];
  11068. t[M12] = v[M21];
  11069. t[M13] = v[M31];
  11070. t[M20] = v[M02];
  11071. t[M21] = v[M12];
  11072. t[M22] = v[M22];
  11073. t[M23] = v[M32];
  11074. t[M30] = v[M03];
  11075. t[M31] = v[M13];
  11076. t[M32] = v[M23];
  11077. t[M33] = v[M33];
  11078. return this.set(t);
  11079. }
  11080. identity() {
  11081. let v = this.values;
  11082. v[M00] = 1;
  11083. v[M01] = 0;
  11084. v[M02] = 0;
  11085. v[M03] = 0;
  11086. v[M10] = 0;
  11087. v[M11] = 1;
  11088. v[M12] = 0;
  11089. v[M13] = 0;
  11090. v[M20] = 0;
  11091. v[M21] = 0;
  11092. v[M22] = 1;
  11093. v[M23] = 0;
  11094. v[M30] = 0;
  11095. v[M31] = 0;
  11096. v[M32] = 0;
  11097. v[M33] = 1;
  11098. return this;
  11099. }
  11100. invert() {
  11101. let v = this.values;
  11102. let t = this.temp;
  11103. let l_det = v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33];
  11104. if (l_det == 0)
  11105. throw new Error("non-invertible matrix");
  11106. let inv_det = 1 / l_det;
  11107. t[M00] = v[M12] * v[M23] * v[M31] - v[M13] * v[M22] * v[M31] + v[M13] * v[M21] * v[M32] - v[M11] * v[M23] * v[M32] - v[M12] * v[M21] * v[M33] + v[M11] * v[M22] * v[M33];
  11108. t[M01] = v[M03] * v[M22] * v[M31] - v[M02] * v[M23] * v[M31] - v[M03] * v[M21] * v[M32] + v[M01] * v[M23] * v[M32] + v[M02] * v[M21] * v[M33] - v[M01] * v[M22] * v[M33];
  11109. t[M02] = v[M02] * v[M13] * v[M31] - v[M03] * v[M12] * v[M31] + v[M03] * v[M11] * v[M32] - v[M01] * v[M13] * v[M32] - v[M02] * v[M11] * v[M33] + v[M01] * v[M12] * v[M33];
  11110. t[M03] = v[M03] * v[M12] * v[M21] - v[M02] * v[M13] * v[M21] - v[M03] * v[M11] * v[M22] + v[M01] * v[M13] * v[M22] + v[M02] * v[M11] * v[M23] - v[M01] * v[M12] * v[M23];
  11111. t[M10] = v[M13] * v[M22] * v[M30] - v[M12] * v[M23] * v[M30] - v[M13] * v[M20] * v[M32] + v[M10] * v[M23] * v[M32] + v[M12] * v[M20] * v[M33] - v[M10] * v[M22] * v[M33];
  11112. t[M11] = v[M02] * v[M23] * v[M30] - v[M03] * v[M22] * v[M30] + v[M03] * v[M20] * v[M32] - v[M00] * v[M23] * v[M32] - v[M02] * v[M20] * v[M33] + v[M00] * v[M22] * v[M33];
  11113. t[M12] = v[M03] * v[M12] * v[M30] - v[M02] * v[M13] * v[M30] - v[M03] * v[M10] * v[M32] + v[M00] * v[M13] * v[M32] + v[M02] * v[M10] * v[M33] - v[M00] * v[M12] * v[M33];
  11114. t[M13] = v[M02] * v[M13] * v[M20] - v[M03] * v[M12] * v[M20] + v[M03] * v[M10] * v[M22] - v[M00] * v[M13] * v[M22] - v[M02] * v[M10] * v[M23] + v[M00] * v[M12] * v[M23];
  11115. t[M20] = v[M11] * v[M23] * v[M30] - v[M13] * v[M21] * v[M30] + v[M13] * v[M20] * v[M31] - v[M10] * v[M23] * v[M31] - v[M11] * v[M20] * v[M33] + v[M10] * v[M21] * v[M33];
  11116. t[M21] = v[M03] * v[M21] * v[M30] - v[M01] * v[M23] * v[M30] - v[M03] * v[M20] * v[M31] + v[M00] * v[M23] * v[M31] + v[M01] * v[M20] * v[M33] - v[M00] * v[M21] * v[M33];
  11117. t[M22] = v[M01] * v[M13] * v[M30] - v[M03] * v[M11] * v[M30] + v[M03] * v[M10] * v[M31] - v[M00] * v[M13] * v[M31] - v[M01] * v[M10] * v[M33] + v[M00] * v[M11] * v[M33];
  11118. t[M23] = v[M03] * v[M11] * v[M20] - v[M01] * v[M13] * v[M20] - v[M03] * v[M10] * v[M21] + v[M00] * v[M13] * v[M21] + v[M01] * v[M10] * v[M23] - v[M00] * v[M11] * v[M23];
  11119. t[M30] = v[M12] * v[M21] * v[M30] - v[M11] * v[M22] * v[M30] - v[M12] * v[M20] * v[M31] + v[M10] * v[M22] * v[M31] + v[M11] * v[M20] * v[M32] - v[M10] * v[M21] * v[M32];
  11120. t[M31] = v[M01] * v[M22] * v[M30] - v[M02] * v[M21] * v[M30] + v[M02] * v[M20] * v[M31] - v[M00] * v[M22] * v[M31] - v[M01] * v[M20] * v[M32] + v[M00] * v[M21] * v[M32];
  11121. t[M32] = v[M02] * v[M11] * v[M30] - v[M01] * v[M12] * v[M30] - v[M02] * v[M10] * v[M31] + v[M00] * v[M12] * v[M31] + v[M01] * v[M10] * v[M32] - v[M00] * v[M11] * v[M32];
  11122. t[M33] = v[M01] * v[M12] * v[M20] - v[M02] * v[M11] * v[M20] + v[M02] * v[M10] * v[M21] - v[M00] * v[M12] * v[M21] - v[M01] * v[M10] * v[M22] + v[M00] * v[M11] * v[M22];
  11123. v[M00] = t[M00] * inv_det;
  11124. v[M01] = t[M01] * inv_det;
  11125. v[M02] = t[M02] * inv_det;
  11126. v[M03] = t[M03] * inv_det;
  11127. v[M10] = t[M10] * inv_det;
  11128. v[M11] = t[M11] * inv_det;
  11129. v[M12] = t[M12] * inv_det;
  11130. v[M13] = t[M13] * inv_det;
  11131. v[M20] = t[M20] * inv_det;
  11132. v[M21] = t[M21] * inv_det;
  11133. v[M22] = t[M22] * inv_det;
  11134. v[M23] = t[M23] * inv_det;
  11135. v[M30] = t[M30] * inv_det;
  11136. v[M31] = t[M31] * inv_det;
  11137. v[M32] = t[M32] * inv_det;
  11138. v[M33] = t[M33] * inv_det;
  11139. return this;
  11140. }
  11141. determinant() {
  11142. let v = this.values;
  11143. return v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33];
  11144. }
  11145. translate(x, y, z) {
  11146. let v = this.values;
  11147. v[M03] += x;
  11148. v[M13] += y;
  11149. v[M23] += z;
  11150. return this;
  11151. }
  11152. copy() {
  11153. return new _Matrix4().set(this.values);
  11154. }
  11155. projection(near, far, fovy, aspectRatio) {
  11156. this.identity();
  11157. let l_fd = 1 / Math.tan(fovy * (Math.PI / 180) / 2);
  11158. let l_a1 = (far + near) / (near - far);
  11159. let l_a2 = 2 * far * near / (near - far);
  11160. let v = this.values;
  11161. v[M00] = l_fd / aspectRatio;
  11162. v[M10] = 0;
  11163. v[M20] = 0;
  11164. v[M30] = 0;
  11165. v[M01] = 0;
  11166. v[M11] = l_fd;
  11167. v[M21] = 0;
  11168. v[M31] = 0;
  11169. v[M02] = 0;
  11170. v[M12] = 0;
  11171. v[M22] = l_a1;
  11172. v[M32] = -1;
  11173. v[M03] = 0;
  11174. v[M13] = 0;
  11175. v[M23] = l_a2;
  11176. v[M33] = 0;
  11177. return this;
  11178. }
  11179. ortho2d(x, y, width, height) {
  11180. return this.ortho(x, x + width, y, y + height, 0, 1);
  11181. }
  11182. ortho(left, right, bottom, top, near, far) {
  11183. this.identity();
  11184. let x_orth = 2 / (right - left);
  11185. let y_orth = 2 / (top - bottom);
  11186. let z_orth = -2 / (far - near);
  11187. let tx = -(right + left) / (right - left);
  11188. let ty = -(top + bottom) / (top - bottom);
  11189. let tz = -(far + near) / (far - near);
  11190. let v = this.values;
  11191. v[M00] = x_orth;
  11192. v[M10] = 0;
  11193. v[M20] = 0;
  11194. v[M30] = 0;
  11195. v[M01] = 0;
  11196. v[M11] = y_orth;
  11197. v[M21] = 0;
  11198. v[M31] = 0;
  11199. v[M02] = 0;
  11200. v[M12] = 0;
  11201. v[M22] = z_orth;
  11202. v[M32] = 0;
  11203. v[M03] = tx;
  11204. v[M13] = ty;
  11205. v[M23] = tz;
  11206. v[M33] = 1;
  11207. return this;
  11208. }
  11209. multiply(matrix) {
  11210. let t = this.temp;
  11211. let v = this.values;
  11212. let m = matrix.values;
  11213. t[M00] = v[M00] * m[M00] + v[M01] * m[M10] + v[M02] * m[M20] + v[M03] * m[M30];
  11214. t[M01] = v[M00] * m[M01] + v[M01] * m[M11] + v[M02] * m[M21] + v[M03] * m[M31];
  11215. t[M02] = v[M00] * m[M02] + v[M01] * m[M12] + v[M02] * m[M22] + v[M03] * m[M32];
  11216. t[M03] = v[M00] * m[M03] + v[M01] * m[M13] + v[M02] * m[M23] + v[M03] * m[M33];
  11217. t[M10] = v[M10] * m[M00] + v[M11] * m[M10] + v[M12] * m[M20] + v[M13] * m[M30];
  11218. t[M11] = v[M10] * m[M01] + v[M11] * m[M11] + v[M12] * m[M21] + v[M13] * m[M31];
  11219. t[M12] = v[M10] * m[M02] + v[M11] * m[M12] + v[M12] * m[M22] + v[M13] * m[M32];
  11220. t[M13] = v[M10] * m[M03] + v[M11] * m[M13] + v[M12] * m[M23] + v[M13] * m[M33];
  11221. t[M20] = v[M20] * m[M00] + v[M21] * m[M10] + v[M22] * m[M20] + v[M23] * m[M30];
  11222. t[M21] = v[M20] * m[M01] + v[M21] * m[M11] + v[M22] * m[M21] + v[M23] * m[M31];
  11223. t[M22] = v[M20] * m[M02] + v[M21] * m[M12] + v[M22] * m[M22] + v[M23] * m[M32];
  11224. t[M23] = v[M20] * m[M03] + v[M21] * m[M13] + v[M22] * m[M23] + v[M23] * m[M33];
  11225. t[M30] = v[M30] * m[M00] + v[M31] * m[M10] + v[M32] * m[M20] + v[M33] * m[M30];
  11226. t[M31] = v[M30] * m[M01] + v[M31] * m[M11] + v[M32] * m[M21] + v[M33] * m[M31];
  11227. t[M32] = v[M30] * m[M02] + v[M31] * m[M12] + v[M32] * m[M22] + v[M33] * m[M32];
  11228. t[M33] = v[M30] * m[M03] + v[M31] * m[M13] + v[M32] * m[M23] + v[M33] * m[M33];
  11229. return this.set(this.temp);
  11230. }
  11231. multiplyLeft(matrix) {
  11232. let t = this.temp;
  11233. let v = this.values;
  11234. let m = matrix.values;
  11235. t[M00] = m[M00] * v[M00] + m[M01] * v[M10] + m[M02] * v[M20] + m[M03] * v[M30];
  11236. t[M01] = m[M00] * v[M01] + m[M01] * v[M11] + m[M02] * v[M21] + m[M03] * v[M31];
  11237. t[M02] = m[M00] * v[M02] + m[M01] * v[M12] + m[M02] * v[M22] + m[M03] * v[M32];
  11238. t[M03] = m[M00] * v[M03] + m[M01] * v[M13] + m[M02] * v[M23] + m[M03] * v[M33];
  11239. t[M10] = m[M10] * v[M00] + m[M11] * v[M10] + m[M12] * v[M20] + m[M13] * v[M30];
  11240. t[M11] = m[M10] * v[M01] + m[M11] * v[M11] + m[M12] * v[M21] + m[M13] * v[M31];
  11241. t[M12] = m[M10] * v[M02] + m[M11] * v[M12] + m[M12] * v[M22] + m[M13] * v[M32];
  11242. t[M13] = m[M10] * v[M03] + m[M11] * v[M13] + m[M12] * v[M23] + m[M13] * v[M33];
  11243. t[M20] = m[M20] * v[M00] + m[M21] * v[M10] + m[M22] * v[M20] + m[M23] * v[M30];
  11244. t[M21] = m[M20] * v[M01] + m[M21] * v[M11] + m[M22] * v[M21] + m[M23] * v[M31];
  11245. t[M22] = m[M20] * v[M02] + m[M21] * v[M12] + m[M22] * v[M22] + m[M23] * v[M32];
  11246. t[M23] = m[M20] * v[M03] + m[M21] * v[M13] + m[M22] * v[M23] + m[M23] * v[M33];
  11247. t[M30] = m[M30] * v[M00] + m[M31] * v[M10] + m[M32] * v[M20] + m[M33] * v[M30];
  11248. t[M31] = m[M30] * v[M01] + m[M31] * v[M11] + m[M32] * v[M21] + m[M33] * v[M31];
  11249. t[M32] = m[M30] * v[M02] + m[M31] * v[M12] + m[M32] * v[M22] + m[M33] * v[M32];
  11250. t[M33] = m[M30] * v[M03] + m[M31] * v[M13] + m[M32] * v[M23] + m[M33] * v[M33];
  11251. return this.set(this.temp);
  11252. }
  11253. lookAt(position, direction, up) {
  11254. let xAxis = _Matrix4.xAxis, yAxis = _Matrix4.yAxis, zAxis = _Matrix4.zAxis;
  11255. zAxis.setFrom(direction).normalize();
  11256. xAxis.setFrom(direction).normalize();
  11257. xAxis.cross(up).normalize();
  11258. yAxis.setFrom(xAxis).cross(zAxis).normalize();
  11259. this.identity();
  11260. let val = this.values;
  11261. val[M00] = xAxis.x;
  11262. val[M01] = xAxis.y;
  11263. val[M02] = xAxis.z;
  11264. val[M10] = yAxis.x;
  11265. val[M11] = yAxis.y;
  11266. val[M12] = yAxis.z;
  11267. val[M20] = -zAxis.x;
  11268. val[M21] = -zAxis.y;
  11269. val[M22] = -zAxis.z;
  11270. _Matrix4.tmpMatrix.identity();
  11271. _Matrix4.tmpMatrix.values[M03] = -position.x;
  11272. _Matrix4.tmpMatrix.values[M13] = -position.y;
  11273. _Matrix4.tmpMatrix.values[M23] = -position.z;
  11274. this.multiply(_Matrix4.tmpMatrix);
  11275. return this;
  11276. }
  11277. };
  11278. var Matrix42 = _Matrix4;
  11279. Matrix42.xAxis = new Vector3();
  11280. Matrix42.yAxis = new Vector3();
  11281. Matrix42.zAxis = new Vector3();
  11282. Matrix42.tmpMatrix = new _Matrix4();
  11283. // spine-webgl/src/Camera.ts
  11284. var OrthoCamera = class {
  11285. constructor(viewportWidth, viewportHeight) {
  11286. this.position = new Vector3(0, 0, 0);
  11287. this.direction = new Vector3(0, 0, -1);
  11288. this.up = new Vector3(0, 1, 0);
  11289. this.near = 0;
  11290. this.far = 100;
  11291. this.zoom = 1;
  11292. this.viewportWidth = 0;
  11293. this.viewportHeight = 0;
  11294. this.projectionView = new Matrix42();
  11295. this.inverseProjectionView = new Matrix42();
  11296. this.projection = new Matrix42();
  11297. this.view = new Matrix42();
  11298. this.viewportWidth = viewportWidth;
  11299. this.viewportHeight = viewportHeight;
  11300. this.update();
  11301. }
  11302. update() {
  11303. let projection = this.projection;
  11304. let view = this.view;
  11305. let projectionView = this.projectionView;
  11306. let inverseProjectionView = this.inverseProjectionView;
  11307. let zoom = this.zoom, viewportWidth = this.viewportWidth, viewportHeight = this.viewportHeight;
  11308. projection.ortho(
  11309. zoom * (-viewportWidth / 2),
  11310. zoom * (viewportWidth / 2),
  11311. zoom * (-viewportHeight / 2),
  11312. zoom * (viewportHeight / 2),
  11313. this.near,
  11314. this.far
  11315. );
  11316. view.lookAt(this.position, this.direction, this.up);
  11317. projectionView.set(projection.values);
  11318. projectionView.multiply(view);
  11319. inverseProjectionView.set(projectionView.values).invert();
  11320. }
  11321. screenToWorld(screenCoords, screenWidth, screenHeight) {
  11322. let x = screenCoords.x, y = screenHeight - screenCoords.y - 1;
  11323. screenCoords.x = 2 * x / screenWidth - 1;
  11324. screenCoords.y = 2 * y / screenHeight - 1;
  11325. screenCoords.z = 2 * screenCoords.z - 1;
  11326. screenCoords.project(this.inverseProjectionView);
  11327. return screenCoords;
  11328. }
  11329. worldToScreen(worldCoords, screenWidth, screenHeight) {
  11330. worldCoords.project(this.projectionView);
  11331. worldCoords.x = screenWidth * (worldCoords.x + 1) / 2;
  11332. worldCoords.y = screenHeight * (worldCoords.y + 1) / 2;
  11333. worldCoords.z = (worldCoords.z + 1) / 2;
  11334. return worldCoords;
  11335. }
  11336. setViewport(viewportWidth, viewportHeight) {
  11337. this.viewportWidth = viewportWidth;
  11338. this.viewportHeight = viewportHeight;
  11339. }
  11340. };
  11341. // spine-webgl/src/Input.ts
  11342. var Input = class {
  11343. constructor(element) {
  11344. this.mouseX = 0;
  11345. this.mouseY = 0;
  11346. this.buttonDown = false;
  11347. this.touch0 = null;
  11348. this.touch1 = null;
  11349. this.initialPinchDistance = 0;
  11350. this.listeners = new Array();
  11351. this.eventListeners = [];
  11352. this.element = element;
  11353. this.setupCallbacks(element);
  11354. }
  11355. setupCallbacks(element) {
  11356. let mouseDown = (ev) => {
  11357. if (ev instanceof MouseEvent) {
  11358. let rect = element.getBoundingClientRect();
  11359. this.mouseX = ev.clientX - rect.left;
  11360. ;
  11361. this.mouseY = ev.clientY - rect.top;
  11362. this.buttonDown = true;
  11363. this.listeners.map((listener) => {
  11364. if (listener.down)
  11365. listener.down(this.mouseX, this.mouseY);
  11366. });
  11367. document.addEventListener("mousemove", mouseMove);
  11368. document.addEventListener("mouseup", mouseUp);
  11369. }
  11370. };
  11371. let mouseMove = (ev) => {
  11372. if (ev instanceof MouseEvent) {
  11373. let rect = element.getBoundingClientRect();
  11374. this.mouseX = ev.clientX - rect.left;
  11375. ;
  11376. this.mouseY = ev.clientY - rect.top;
  11377. this.listeners.map((listener) => {
  11378. if (this.buttonDown) {
  11379. if (listener.dragged)
  11380. listener.dragged(this.mouseX, this.mouseY);
  11381. } else {
  11382. if (listener.moved)
  11383. listener.moved(this.mouseX, this.mouseY);
  11384. }
  11385. });
  11386. }
  11387. };
  11388. let mouseUp = (ev) => {
  11389. if (ev instanceof MouseEvent) {
  11390. let rect = element.getBoundingClientRect();
  11391. this.mouseX = ev.clientX - rect.left;
  11392. ;
  11393. this.mouseY = ev.clientY - rect.top;
  11394. this.buttonDown = false;
  11395. this.listeners.map((listener) => {
  11396. if (listener.up)
  11397. listener.up(this.mouseX, this.mouseY);
  11398. });
  11399. document.removeEventListener("mousemove", mouseMove);
  11400. document.removeEventListener("mouseup", mouseUp);
  11401. }
  11402. };
  11403. let mouseWheel = (e) => {
  11404. e.preventDefault();
  11405. let deltaY = e.deltaY;
  11406. if (e.deltaMode == WheelEvent.DOM_DELTA_LINE)
  11407. deltaY *= 8;
  11408. if (e.deltaMode == WheelEvent.DOM_DELTA_PAGE)
  11409. deltaY *= 24;
  11410. this.listeners.map((listener) => {
  11411. if (listener.wheel)
  11412. listener.wheel(e.deltaY);
  11413. });
  11414. };
  11415. element.addEventListener("mousedown", mouseDown, true);
  11416. element.addEventListener("mousemove", mouseMove, true);
  11417. element.addEventListener("mouseup", mouseUp, true);
  11418. element.addEventListener("wheel", mouseWheel, true);
  11419. element.addEventListener("touchstart", (ev) => {
  11420. if (!this.touch0 || !this.touch1) {
  11421. var touches = ev.changedTouches;
  11422. let nativeTouch = touches.item(0);
  11423. if (!nativeTouch)
  11424. return;
  11425. let rect = element.getBoundingClientRect();
  11426. let x = nativeTouch.clientX - rect.left;
  11427. let y = nativeTouch.clientY - rect.top;
  11428. let touch = new Touch(nativeTouch.identifier, x, y);
  11429. this.mouseX = x;
  11430. this.mouseY = y;
  11431. this.buttonDown = true;
  11432. if (!this.touch0) {
  11433. this.touch0 = touch;
  11434. this.listeners.map((listener) => {
  11435. if (listener.down)
  11436. listener.down(touch.x, touch.y);
  11437. });
  11438. } else if (!this.touch1) {
  11439. this.touch1 = touch;
  11440. let dx = this.touch1.x - this.touch0.x;
  11441. let dy = this.touch1.x - this.touch0.x;
  11442. this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy);
  11443. this.listeners.map((listener) => {
  11444. if (listener.zoom)
  11445. listener.zoom(this.initialPinchDistance, this.initialPinchDistance);
  11446. });
  11447. }
  11448. }
  11449. ev.preventDefault();
  11450. }, false);
  11451. element.addEventListener("touchmove", (ev) => {
  11452. if (this.touch0) {
  11453. var touches = ev.changedTouches;
  11454. let rect = element.getBoundingClientRect();
  11455. for (var i = 0; i < touches.length; i++) {
  11456. var nativeTouch = touches[i];
  11457. let x = nativeTouch.clientX - rect.left;
  11458. let y = nativeTouch.clientY - rect.top;
  11459. if (this.touch0.identifier === nativeTouch.identifier) {
  11460. this.touch0.x = this.mouseX = x;
  11461. this.touch0.y = this.mouseY = y;
  11462. this.listeners.map((listener) => {
  11463. if (listener.dragged)
  11464. listener.dragged(x, y);
  11465. });
  11466. }
  11467. if (this.touch1 && this.touch1.identifier === nativeTouch.identifier) {
  11468. this.touch1.x = this.mouseX = x;
  11469. this.touch1.y = this.mouseY = y;
  11470. }
  11471. }
  11472. if (this.touch0 && this.touch1) {
  11473. let dx = this.touch1.x - this.touch0.x;
  11474. let dy = this.touch1.x - this.touch0.x;
  11475. let distance = Math.sqrt(dx * dx + dy * dy);
  11476. this.listeners.map((listener) => {
  11477. if (listener.zoom)
  11478. listener.zoom(this.initialPinchDistance, distance);
  11479. });
  11480. }
  11481. }
  11482. ev.preventDefault();
  11483. }, false);
  11484. let touchEnd = (ev) => {
  11485. if (this.touch0) {
  11486. var touches = ev.changedTouches;
  11487. let rect = element.getBoundingClientRect();
  11488. for (var i = 0; i < touches.length; i++) {
  11489. var nativeTouch = touches[i];
  11490. let x = nativeTouch.clientX - rect.left;
  11491. let y = nativeTouch.clientY - rect.top;
  11492. if (this.touch0.identifier === nativeTouch.identifier) {
  11493. this.touch0 = null;
  11494. this.mouseX = x;
  11495. this.mouseY = y;
  11496. this.listeners.map((listener) => {
  11497. if (listener.up)
  11498. listener.up(x, y);
  11499. });
  11500. if (!this.touch1) {
  11501. this.buttonDown = false;
  11502. break;
  11503. } else {
  11504. this.touch0 = this.touch1;
  11505. this.touch1 = null;
  11506. this.mouseX = this.touch0.x;
  11507. this.mouseX = this.touch0.x;
  11508. this.buttonDown = true;
  11509. this.listeners.map((listener) => {
  11510. if (listener.down)
  11511. listener.down(this.touch0.x, this.touch0.y);
  11512. });
  11513. }
  11514. }
  11515. if (this.touch1 && this.touch1.identifier) {
  11516. this.touch1 = null;
  11517. }
  11518. }
  11519. }
  11520. ev.preventDefault();
  11521. };
  11522. element.addEventListener("touchend", touchEnd, false);
  11523. element.addEventListener("touchcancel", touchEnd);
  11524. }
  11525. addListener(listener) {
  11526. this.listeners.push(listener);
  11527. }
  11528. removeListener(listener) {
  11529. let idx = this.listeners.indexOf(listener);
  11530. if (idx > -1) {
  11531. this.listeners.splice(idx, 1);
  11532. }
  11533. }
  11534. };
  11535. var Touch = class {
  11536. constructor(identifier, x, y) {
  11537. this.identifier = identifier;
  11538. this.x = x;
  11539. this.y = y;
  11540. }
  11541. };
  11542. // spine-webgl/src/CameraController.ts
  11543. var CameraController = class {
  11544. constructor(canvas, camera) {
  11545. this.canvas = canvas;
  11546. this.camera = camera;
  11547. let cameraX = 0, cameraY = 0, cameraZoom = 0;
  11548. let mouseX = 0, mouseY = 0;
  11549. let lastX = 0, lastY = 0;
  11550. let initialZoom = 0;
  11551. new Input(canvas).addListener({
  11552. down: (x, y) => {
  11553. cameraX = camera.position.x;
  11554. cameraY = camera.position.y;
  11555. mouseX = lastX = x;
  11556. mouseY = lastY = y;
  11557. initialZoom = camera.zoom;
  11558. },
  11559. dragged: (x, y) => {
  11560. let deltaX = x - mouseX;
  11561. let deltaY = y - mouseY;
  11562. let originWorld = camera.screenToWorld(new Vector3(0, 0), canvas.clientWidth, canvas.clientHeight);
  11563. let deltaWorld = camera.screenToWorld(new Vector3(deltaX, deltaY), canvas.clientWidth, canvas.clientHeight).sub(originWorld);
  11564. camera.position.set(cameraX - deltaWorld.x, cameraY - deltaWorld.y, 0);
  11565. camera.update();
  11566. lastX = x;
  11567. lastY = y;
  11568. },
  11569. wheel: (delta) => {
  11570. let zoomAmount = delta / 200 * camera.zoom;
  11571. let newZoom = camera.zoom + zoomAmount;
  11572. if (newZoom > 0) {
  11573. let x = 0, y = 0;
  11574. if (delta < 0) {
  11575. x = lastX;
  11576. y = lastY;
  11577. } else {
  11578. let viewCenter = new Vector3(canvas.clientWidth / 2 + 15, canvas.clientHeight / 2);
  11579. let mouseToCenterX = lastX - viewCenter.x;
  11580. let mouseToCenterY = canvas.clientHeight - 1 - lastY - viewCenter.y;
  11581. x = viewCenter.x - mouseToCenterX;
  11582. y = canvas.clientHeight - 1 - viewCenter.y + mouseToCenterY;
  11583. }
  11584. let oldDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
  11585. camera.zoom = newZoom;
  11586. camera.update();
  11587. let newDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
  11588. camera.position.add(oldDistance.sub(newDistance));
  11589. camera.update();
  11590. }
  11591. },
  11592. zoom: (initialDistance, distance) => {
  11593. let newZoom = initialDistance / distance;
  11594. camera.zoom = initialZoom * newZoom;
  11595. },
  11596. up: (x, y) => {
  11597. lastX = x;
  11598. lastY = y;
  11599. },
  11600. moved: (x, y) => {
  11601. lastX = x;
  11602. lastY = y;
  11603. }
  11604. });
  11605. }
  11606. };
  11607. // spine-webgl/src/Shader.ts
  11608. var _Shader = class {
  11609. constructor(context, vertexShader, fragmentShader) {
  11610. this.vertexShader = vertexShader;
  11611. this.fragmentShader = fragmentShader;
  11612. this.vs = null;
  11613. this.fs = null;
  11614. this.program = null;
  11615. this.tmp2x2 = new Float32Array(2 * 2);
  11616. this.tmp3x3 = new Float32Array(3 * 3);
  11617. this.tmp4x4 = new Float32Array(4 * 4);
  11618. this.vsSource = vertexShader;
  11619. this.fsSource = fragmentShader;
  11620. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  11621. this.context.addRestorable(this);
  11622. this.compile();
  11623. }
  11624. getProgram() {
  11625. return this.program;
  11626. }
  11627. getVertexShader() {
  11628. return this.vertexShader;
  11629. }
  11630. getFragmentShader() {
  11631. return this.fragmentShader;
  11632. }
  11633. getVertexShaderSource() {
  11634. return this.vsSource;
  11635. }
  11636. getFragmentSource() {
  11637. return this.fsSource;
  11638. }
  11639. compile() {
  11640. let gl = this.context.gl;
  11641. try {
  11642. this.vs = this.compileShader(gl.VERTEX_SHADER, this.vertexShader);
  11643. if (!this.vs)
  11644. throw new Error("Couldn't compile vertex shader.");
  11645. this.fs = this.compileShader(gl.FRAGMENT_SHADER, this.fragmentShader);
  11646. if (!this.fs)
  11647. throw new Error("Couldn#t compile fragment shader.");
  11648. this.program = this.compileProgram(this.vs, this.fs);
  11649. } catch (e) {
  11650. this.dispose();
  11651. throw e;
  11652. }
  11653. }
  11654. compileShader(type, source) {
  11655. let gl = this.context.gl;
  11656. let shader = gl.createShader(type);
  11657. if (!shader)
  11658. throw new Error("Couldn't create shader.");
  11659. gl.shaderSource(shader, source);
  11660. gl.compileShader(shader);
  11661. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  11662. let error = "Couldn't compile shader: " + gl.getShaderInfoLog(shader);
  11663. gl.deleteShader(shader);
  11664. if (!gl.isContextLost())
  11665. throw new Error(error);
  11666. }
  11667. return shader;
  11668. }
  11669. compileProgram(vs, fs) {
  11670. let gl = this.context.gl;
  11671. let program = gl.createProgram();
  11672. if (!program)
  11673. throw new Error("Couldn't compile program.");
  11674. gl.attachShader(program, vs);
  11675. gl.attachShader(program, fs);
  11676. gl.linkProgram(program);
  11677. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  11678. let error = "Couldn't compile shader program: " + gl.getProgramInfoLog(program);
  11679. gl.deleteProgram(program);
  11680. if (!gl.isContextLost())
  11681. throw new Error(error);
  11682. }
  11683. return program;
  11684. }
  11685. restore() {
  11686. this.compile();
  11687. }
  11688. bind() {
  11689. this.context.gl.useProgram(this.program);
  11690. }
  11691. unbind() {
  11692. this.context.gl.useProgram(null);
  11693. }
  11694. setUniformi(uniform, value) {
  11695. this.context.gl.uniform1i(this.getUniformLocation(uniform), value);
  11696. }
  11697. setUniformf(uniform, value) {
  11698. this.context.gl.uniform1f(this.getUniformLocation(uniform), value);
  11699. }
  11700. setUniform2f(uniform, value, value2) {
  11701. this.context.gl.uniform2f(this.getUniformLocation(uniform), value, value2);
  11702. }
  11703. setUniform3f(uniform, value, value2, value3) {
  11704. this.context.gl.uniform3f(this.getUniformLocation(uniform), value, value2, value3);
  11705. }
  11706. setUniform4f(uniform, value, value2, value3, value4) {
  11707. this.context.gl.uniform4f(this.getUniformLocation(uniform), value, value2, value3, value4);
  11708. }
  11709. setUniform2x2f(uniform, value) {
  11710. let gl = this.context.gl;
  11711. this.tmp2x2.set(value);
  11712. gl.uniformMatrix2fv(this.getUniformLocation(uniform), false, this.tmp2x2);
  11713. }
  11714. setUniform3x3f(uniform, value) {
  11715. let gl = this.context.gl;
  11716. this.tmp3x3.set(value);
  11717. gl.uniformMatrix3fv(this.getUniformLocation(uniform), false, this.tmp3x3);
  11718. }
  11719. setUniform4x4f(uniform, value) {
  11720. let gl = this.context.gl;
  11721. this.tmp4x4.set(value);
  11722. gl.uniformMatrix4fv(this.getUniformLocation(uniform), false, this.tmp4x4);
  11723. }
  11724. getUniformLocation(uniform) {
  11725. let gl = this.context.gl;
  11726. if (!this.program)
  11727. throw new Error("Shader not compiled.");
  11728. let location = gl.getUniformLocation(this.program, uniform);
  11729. if (!location && !gl.isContextLost())
  11730. throw new Error(`Couldn't find location for uniform ${uniform}`);
  11731. return location;
  11732. }
  11733. getAttributeLocation(attribute) {
  11734. let gl = this.context.gl;
  11735. if (!this.program)
  11736. throw new Error("Shader not compiled.");
  11737. let location = gl.getAttribLocation(this.program, attribute);
  11738. if (location == -1 && !gl.isContextLost())
  11739. throw new Error(`Couldn't find location for attribute ${attribute}`);
  11740. return location;
  11741. }
  11742. dispose() {
  11743. this.context.removeRestorable(this);
  11744. let gl = this.context.gl;
  11745. if (this.vs) {
  11746. gl.deleteShader(this.vs);
  11747. this.vs = null;
  11748. }
  11749. if (this.fs) {
  11750. gl.deleteShader(this.fs);
  11751. this.fs = null;
  11752. }
  11753. if (this.program) {
  11754. gl.deleteProgram(this.program);
  11755. this.program = null;
  11756. }
  11757. }
  11758. static newColoredTextured(context) {
  11759. let vs = `
  11760. attribute vec4 ${_Shader.POSITION};
  11761. attribute vec4 ${_Shader.COLOR};
  11762. attribute vec2 ${_Shader.TEXCOORDS};
  11763. uniform mat4 ${_Shader.MVP_MATRIX};
  11764. varying vec4 v_color;
  11765. varying vec2 v_texCoords;
  11766. void main () {
  11767. v_color = ${_Shader.COLOR};
  11768. v_texCoords = ${_Shader.TEXCOORDS};
  11769. gl_Position = ${_Shader.MVP_MATRIX} * ${_Shader.POSITION};
  11770. }
  11771. `;
  11772. let fs = `
  11773. #ifdef GL_ES
  11774. #define LOWP lowp
  11775. precision mediump float;
  11776. #else
  11777. #define LOWP
  11778. #endif
  11779. varying LOWP vec4 v_color;
  11780. varying vec2 v_texCoords;
  11781. uniform sampler2D u_texture;
  11782. void main () {
  11783. gl_FragColor = v_color * texture2D(u_texture, v_texCoords);
  11784. }
  11785. `;
  11786. return new _Shader(context, vs, fs);
  11787. }
  11788. static newTwoColoredTextured(context) {
  11789. let vs = `
  11790. attribute vec4 ${_Shader.POSITION};
  11791. attribute vec4 ${_Shader.COLOR};
  11792. attribute vec4 ${_Shader.COLOR2};
  11793. attribute vec2 ${_Shader.TEXCOORDS};
  11794. uniform mat4 ${_Shader.MVP_MATRIX};
  11795. varying vec4 v_light;
  11796. varying vec4 v_dark;
  11797. varying vec2 v_texCoords;
  11798. void main () {
  11799. v_light = ${_Shader.COLOR};
  11800. v_dark = ${_Shader.COLOR2};
  11801. v_texCoords = ${_Shader.TEXCOORDS};
  11802. gl_Position = ${_Shader.MVP_MATRIX} * ${_Shader.POSITION};
  11803. }
  11804. `;
  11805. let fs = `
  11806. #ifdef GL_ES
  11807. #define LOWP lowp
  11808. precision mediump float;
  11809. #else
  11810. #define LOWP
  11811. #endif
  11812. varying LOWP vec4 v_light;
  11813. varying LOWP vec4 v_dark;
  11814. varying vec2 v_texCoords;
  11815. uniform sampler2D u_texture;
  11816. void main () {
  11817. vec4 texColor = texture2D(u_texture, v_texCoords);
  11818. gl_FragColor.a = texColor.a * v_light.a;
  11819. gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;
  11820. }
  11821. `;
  11822. return new _Shader(context, vs, fs);
  11823. }
  11824. static newColored(context) {
  11825. let vs = `
  11826. attribute vec4 ${_Shader.POSITION};
  11827. attribute vec4 ${_Shader.COLOR};
  11828. uniform mat4 ${_Shader.MVP_MATRIX};
  11829. varying vec4 v_color;
  11830. void main () {
  11831. v_color = ${_Shader.COLOR};
  11832. gl_Position = ${_Shader.MVP_MATRIX} * ${_Shader.POSITION};
  11833. }
  11834. `;
  11835. let fs = `
  11836. #ifdef GL_ES
  11837. #define LOWP lowp
  11838. precision mediump float;
  11839. #else
  11840. #define LOWP
  11841. #endif
  11842. varying LOWP vec4 v_color;
  11843. void main () {
  11844. gl_FragColor = v_color;
  11845. }
  11846. `;
  11847. return new _Shader(context, vs, fs);
  11848. }
  11849. };
  11850. var Shader = _Shader;
  11851. Shader.MVP_MATRIX = "u_projTrans";
  11852. Shader.POSITION = "a_position";
  11853. Shader.COLOR = "a_color";
  11854. Shader.COLOR2 = "a_color2";
  11855. Shader.TEXCOORDS = "a_texCoords";
  11856. Shader.SAMPLER = "u_texture";
  11857. // spine-webgl/src/Mesh.ts
  11858. var Mesh = class {
  11859. constructor(context, attributes, maxVertices, maxIndices) {
  11860. this.attributes = attributes;
  11861. this.verticesBuffer = null;
  11862. this.verticesLength = 0;
  11863. this.dirtyVertices = false;
  11864. this.indicesBuffer = null;
  11865. this.indicesLength = 0;
  11866. this.dirtyIndices = false;
  11867. this.elementsPerVertex = 0;
  11868. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  11869. this.elementsPerVertex = 0;
  11870. for (let i = 0; i < attributes.length; i++) {
  11871. this.elementsPerVertex += attributes[i].numElements;
  11872. }
  11873. this.vertices = new Float32Array(maxVertices * this.elementsPerVertex);
  11874. this.indices = new Uint16Array(maxIndices);
  11875. this.context.addRestorable(this);
  11876. }
  11877. getAttributes() {
  11878. return this.attributes;
  11879. }
  11880. maxVertices() {
  11881. return this.vertices.length / this.elementsPerVertex;
  11882. }
  11883. numVertices() {
  11884. return this.verticesLength / this.elementsPerVertex;
  11885. }
  11886. setVerticesLength(length) {
  11887. this.dirtyVertices = true;
  11888. this.verticesLength = length;
  11889. }
  11890. getVertices() {
  11891. return this.vertices;
  11892. }
  11893. maxIndices() {
  11894. return this.indices.length;
  11895. }
  11896. numIndices() {
  11897. return this.indicesLength;
  11898. }
  11899. setIndicesLength(length) {
  11900. this.dirtyIndices = true;
  11901. this.indicesLength = length;
  11902. }
  11903. getIndices() {
  11904. return this.indices;
  11905. }
  11906. getVertexSizeInFloats() {
  11907. let size = 0;
  11908. for (var i = 0; i < this.attributes.length; i++) {
  11909. let attribute = this.attributes[i];
  11910. size += attribute.numElements;
  11911. }
  11912. return size;
  11913. }
  11914. setVertices(vertices) {
  11915. this.dirtyVertices = true;
  11916. if (vertices.length > this.vertices.length)
  11917. throw Error("Mesh can't store more than " + this.maxVertices() + " vertices");
  11918. this.vertices.set(vertices, 0);
  11919. this.verticesLength = vertices.length;
  11920. }
  11921. setIndices(indices) {
  11922. this.dirtyIndices = true;
  11923. if (indices.length > this.indices.length)
  11924. throw Error("Mesh can't store more than " + this.maxIndices() + " indices");
  11925. this.indices.set(indices, 0);
  11926. this.indicesLength = indices.length;
  11927. }
  11928. draw(shader, primitiveType) {
  11929. this.drawWithOffset(shader, primitiveType, 0, this.indicesLength > 0 ? this.indicesLength : this.verticesLength / this.elementsPerVertex);
  11930. }
  11931. drawWithOffset(shader, primitiveType, offset, count) {
  11932. let gl = this.context.gl;
  11933. if (this.dirtyVertices || this.dirtyIndices)
  11934. this.update();
  11935. this.bind(shader);
  11936. if (this.indicesLength > 0) {
  11937. gl.drawElements(primitiveType, count, gl.UNSIGNED_SHORT, offset * 2);
  11938. } else {
  11939. gl.drawArrays(primitiveType, offset, count);
  11940. }
  11941. this.unbind(shader);
  11942. }
  11943. bind(shader) {
  11944. let gl = this.context.gl;
  11945. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  11946. let offset = 0;
  11947. for (let i = 0; i < this.attributes.length; i++) {
  11948. let attrib = this.attributes[i];
  11949. let location = shader.getAttributeLocation(attrib.name);
  11950. gl.enableVertexAttribArray(location);
  11951. gl.vertexAttribPointer(location, attrib.numElements, gl.FLOAT, false, this.elementsPerVertex * 4, offset * 4);
  11952. offset += attrib.numElements;
  11953. }
  11954. if (this.indicesLength > 0)
  11955. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  11956. }
  11957. unbind(shader) {
  11958. let gl = this.context.gl;
  11959. for (let i = 0; i < this.attributes.length; i++) {
  11960. let attrib = this.attributes[i];
  11961. let location = shader.getAttributeLocation(attrib.name);
  11962. gl.disableVertexAttribArray(location);
  11963. }
  11964. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  11965. if (this.indicesLength > 0)
  11966. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  11967. }
  11968. update() {
  11969. let gl = this.context.gl;
  11970. if (this.dirtyVertices) {
  11971. if (!this.verticesBuffer) {
  11972. this.verticesBuffer = gl.createBuffer();
  11973. }
  11974. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  11975. gl.bufferData(gl.ARRAY_BUFFER, this.vertices.subarray(0, this.verticesLength), gl.DYNAMIC_DRAW);
  11976. this.dirtyVertices = false;
  11977. }
  11978. if (this.dirtyIndices) {
  11979. if (!this.indicesBuffer) {
  11980. this.indicesBuffer = gl.createBuffer();
  11981. }
  11982. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  11983. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices.subarray(0, this.indicesLength), gl.DYNAMIC_DRAW);
  11984. this.dirtyIndices = false;
  11985. }
  11986. }
  11987. restore() {
  11988. this.verticesBuffer = null;
  11989. this.indicesBuffer = null;
  11990. this.update();
  11991. }
  11992. dispose() {
  11993. this.context.removeRestorable(this);
  11994. let gl = this.context.gl;
  11995. gl.deleteBuffer(this.verticesBuffer);
  11996. gl.deleteBuffer(this.indicesBuffer);
  11997. }
  11998. };
  11999. var VertexAttribute = class {
  12000. constructor(name, type, numElements) {
  12001. this.name = name;
  12002. this.type = type;
  12003. this.numElements = numElements;
  12004. }
  12005. };
  12006. var Position2Attribute = class extends VertexAttribute {
  12007. constructor() {
  12008. super(Shader.POSITION, VertexAttributeType.Float, 2);
  12009. }
  12010. };
  12011. var Position3Attribute = class extends VertexAttribute {
  12012. constructor() {
  12013. super(Shader.POSITION, VertexAttributeType.Float, 3);
  12014. }
  12015. };
  12016. var TexCoordAttribute = class extends VertexAttribute {
  12017. constructor(unit = 0) {
  12018. super(Shader.TEXCOORDS + (unit == 0 ? "" : unit), VertexAttributeType.Float, 2);
  12019. }
  12020. };
  12021. var ColorAttribute = class extends VertexAttribute {
  12022. constructor() {
  12023. super(Shader.COLOR, VertexAttributeType.Float, 4);
  12024. }
  12025. };
  12026. var Color2Attribute = class extends VertexAttribute {
  12027. constructor() {
  12028. super(Shader.COLOR2, VertexAttributeType.Float, 4);
  12029. }
  12030. };
  12031. var VertexAttributeType = /* @__PURE__ */ ((VertexAttributeType2) => {
  12032. VertexAttributeType2[VertexAttributeType2["Float"] = 0] = "Float";
  12033. return VertexAttributeType2;
  12034. })(VertexAttributeType || {});
  12035. // spine-webgl/src/PolygonBatcher.ts
  12036. var _PolygonBatcher = class {
  12037. constructor(context, twoColorTint = true, maxVertices = 10920) {
  12038. this.drawCalls = 0;
  12039. this.isDrawing = false;
  12040. this.shader = null;
  12041. this.lastTexture = null;
  12042. this.verticesLength = 0;
  12043. this.indicesLength = 0;
  12044. this.cullWasEnabled = false;
  12045. if (maxVertices > 10920)
  12046. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  12047. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  12048. let attributes = twoColorTint ? [new Position2Attribute(), new ColorAttribute(), new TexCoordAttribute(), new Color2Attribute()] : [new Position2Attribute(), new ColorAttribute(), new TexCoordAttribute()];
  12049. this.mesh = new Mesh(context, attributes, maxVertices, maxVertices * 3);
  12050. let gl = this.context.gl;
  12051. this.srcColorBlend = gl.SRC_ALPHA;
  12052. this.srcAlphaBlend = gl.ONE;
  12053. this.dstBlend = gl.ONE_MINUS_SRC_ALPHA;
  12054. }
  12055. begin(shader) {
  12056. if (this.isDrawing)
  12057. throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()");
  12058. this.drawCalls = 0;
  12059. this.shader = shader;
  12060. this.lastTexture = null;
  12061. this.isDrawing = true;
  12062. let gl = this.context.gl;
  12063. gl.enable(gl.BLEND);
  12064. gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
  12065. if (_PolygonBatcher.disableCulling) {
  12066. this.cullWasEnabled = gl.isEnabled(gl.CULL_FACE);
  12067. if (this.cullWasEnabled)
  12068. gl.disable(gl.CULL_FACE);
  12069. }
  12070. }
  12071. setBlendMode(srcColorBlend, srcAlphaBlend, dstBlend) {
  12072. if (this.srcColorBlend == srcColorBlend && this.srcAlphaBlend == srcAlphaBlend && this.dstBlend == dstBlend)
  12073. return;
  12074. this.srcColorBlend = srcColorBlend;
  12075. this.srcAlphaBlend = srcAlphaBlend;
  12076. this.dstBlend = dstBlend;
  12077. if (this.isDrawing) {
  12078. this.flush();
  12079. let gl = this.context.gl;
  12080. gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
  12081. }
  12082. }
  12083. draw(texture, vertices, indices) {
  12084. if (texture != this.lastTexture) {
  12085. this.flush();
  12086. this.lastTexture = texture;
  12087. } else if (this.verticesLength + vertices.length > this.mesh.getVertices().length || this.indicesLength + indices.length > this.mesh.getIndices().length) {
  12088. this.flush();
  12089. }
  12090. let indexStart = this.mesh.numVertices();
  12091. this.mesh.getVertices().set(vertices, this.verticesLength);
  12092. this.verticesLength += vertices.length;
  12093. this.mesh.setVerticesLength(this.verticesLength);
  12094. let indicesArray = this.mesh.getIndices();
  12095. for (let i = this.indicesLength, j = 0; j < indices.length; i++, j++)
  12096. indicesArray[i] = indices[j] + indexStart;
  12097. this.indicesLength += indices.length;
  12098. this.mesh.setIndicesLength(this.indicesLength);
  12099. }
  12100. flush() {
  12101. if (this.verticesLength == 0)
  12102. return;
  12103. if (!this.lastTexture)
  12104. throw new Error("No texture set.");
  12105. if (!this.shader)
  12106. throw new Error("No shader set.");
  12107. this.lastTexture.bind();
  12108. this.mesh.draw(this.shader, this.context.gl.TRIANGLES);
  12109. this.verticesLength = 0;
  12110. this.indicesLength = 0;
  12111. this.mesh.setVerticesLength(0);
  12112. this.mesh.setIndicesLength(0);
  12113. this.drawCalls++;
  12114. _PolygonBatcher.globalDrawCalls++;
  12115. }
  12116. end() {
  12117. if (!this.isDrawing)
  12118. throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()");
  12119. if (this.verticesLength > 0 || this.indicesLength > 0)
  12120. this.flush();
  12121. this.shader = null;
  12122. this.lastTexture = null;
  12123. this.isDrawing = false;
  12124. let gl = this.context.gl;
  12125. gl.disable(gl.BLEND);
  12126. if (_PolygonBatcher.disableCulling) {
  12127. if (this.cullWasEnabled)
  12128. gl.enable(gl.CULL_FACE);
  12129. }
  12130. }
  12131. getDrawCalls() {
  12132. return this.drawCalls;
  12133. }
  12134. static getAndResetGlobalDrawCalls() {
  12135. let result = _PolygonBatcher.globalDrawCalls;
  12136. _PolygonBatcher.globalDrawCalls = 0;
  12137. return result;
  12138. }
  12139. dispose() {
  12140. this.mesh.dispose();
  12141. }
  12142. };
  12143. var PolygonBatcher = _PolygonBatcher;
  12144. PolygonBatcher.disableCulling = false;
  12145. PolygonBatcher.globalDrawCalls = 0;
  12146. // spine-webgl/src/ShapeRenderer.ts
  12147. var ShapeRenderer = class {
  12148. constructor(context, maxVertices = 10920) {
  12149. this.isDrawing = false;
  12150. this.shapeType = ShapeType.Filled;
  12151. this.color = new Color(1, 1, 1, 1);
  12152. this.shader = null;
  12153. this.vertexIndex = 0;
  12154. this.tmp = new Vector2();
  12155. if (maxVertices > 10920)
  12156. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  12157. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  12158. this.mesh = new Mesh(context, [new Position2Attribute(), new ColorAttribute()], maxVertices, 0);
  12159. let gl = this.context.gl;
  12160. this.srcColorBlend = gl.SRC_ALPHA;
  12161. this.srcAlphaBlend = gl.ONE;
  12162. this.dstBlend = gl.ONE_MINUS_SRC_ALPHA;
  12163. }
  12164. begin(shader) {
  12165. if (this.isDrawing)
  12166. throw new Error("ShapeRenderer.begin() has already been called");
  12167. this.shader = shader;
  12168. this.vertexIndex = 0;
  12169. this.isDrawing = true;
  12170. let gl = this.context.gl;
  12171. gl.enable(gl.BLEND);
  12172. gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
  12173. }
  12174. setBlendMode(srcColorBlend, srcAlphaBlend, dstBlend) {
  12175. this.srcColorBlend = srcColorBlend;
  12176. this.srcAlphaBlend = srcAlphaBlend;
  12177. this.dstBlend = dstBlend;
  12178. if (this.isDrawing) {
  12179. this.flush();
  12180. let gl = this.context.gl;
  12181. gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
  12182. }
  12183. }
  12184. setColor(color) {
  12185. this.color.setFromColor(color);
  12186. }
  12187. setColorWith(r, g, b, a) {
  12188. this.color.set(r, g, b, a);
  12189. }
  12190. point(x, y, color) {
  12191. this.check(ShapeType.Point, 1);
  12192. if (!color)
  12193. color = this.color;
  12194. this.vertex(x, y, color);
  12195. }
  12196. line(x, y, x2, y2, color) {
  12197. this.check(ShapeType.Line, 2);
  12198. let vertices = this.mesh.getVertices();
  12199. let idx = this.vertexIndex;
  12200. if (!color)
  12201. color = this.color;
  12202. this.vertex(x, y, color);
  12203. this.vertex(x2, y2, color);
  12204. }
  12205. triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  12206. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  12207. let vertices = this.mesh.getVertices();
  12208. let idx = this.vertexIndex;
  12209. if (!color)
  12210. color = this.color;
  12211. if (!color2)
  12212. color2 = this.color;
  12213. if (!color3)
  12214. color3 = this.color;
  12215. if (filled) {
  12216. this.vertex(x, y, color);
  12217. this.vertex(x2, y2, color2);
  12218. this.vertex(x3, y3, color3);
  12219. } else {
  12220. this.vertex(x, y, color);
  12221. this.vertex(x2, y2, color2);
  12222. this.vertex(x2, y2, color);
  12223. this.vertex(x3, y3, color2);
  12224. this.vertex(x3, y3, color);
  12225. this.vertex(x, y, color2);
  12226. }
  12227. }
  12228. quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  12229. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  12230. let vertices = this.mesh.getVertices();
  12231. let idx = this.vertexIndex;
  12232. if (!color)
  12233. color = this.color;
  12234. if (!color2)
  12235. color2 = this.color;
  12236. if (!color3)
  12237. color3 = this.color;
  12238. if (!color4)
  12239. color4 = this.color;
  12240. if (filled) {
  12241. this.vertex(x, y, color);
  12242. this.vertex(x2, y2, color2);
  12243. this.vertex(x3, y3, color3);
  12244. this.vertex(x3, y3, color3);
  12245. this.vertex(x4, y4, color4);
  12246. this.vertex(x, y, color);
  12247. } else {
  12248. this.vertex(x, y, color);
  12249. this.vertex(x2, y2, color2);
  12250. this.vertex(x2, y2, color2);
  12251. this.vertex(x3, y3, color3);
  12252. this.vertex(x3, y3, color3);
  12253. this.vertex(x4, y4, color4);
  12254. this.vertex(x4, y4, color4);
  12255. this.vertex(x, y, color);
  12256. }
  12257. }
  12258. rect(filled, x, y, width, height, color) {
  12259. this.quad(filled, x, y, x + width, y, x + width, y + height, x, y + height, color, color, color, color);
  12260. }
  12261. rectLine(filled, x1, y1, x2, y2, width, color) {
  12262. this.check(filled ? ShapeType.Filled : ShapeType.Line, 8);
  12263. if (!color)
  12264. color = this.color;
  12265. let t = this.tmp.set(y2 - y1, x1 - x2);
  12266. t.normalize();
  12267. width *= 0.5;
  12268. let tx = t.x * width;
  12269. let ty = t.y * width;
  12270. if (!filled) {
  12271. this.vertex(x1 + tx, y1 + ty, color);
  12272. this.vertex(x1 - tx, y1 - ty, color);
  12273. this.vertex(x2 + tx, y2 + ty, color);
  12274. this.vertex(x2 - tx, y2 - ty, color);
  12275. this.vertex(x2 + tx, y2 + ty, color);
  12276. this.vertex(x1 + tx, y1 + ty, color);
  12277. this.vertex(x2 - tx, y2 - ty, color);
  12278. this.vertex(x1 - tx, y1 - ty, color);
  12279. } else {
  12280. this.vertex(x1 + tx, y1 + ty, color);
  12281. this.vertex(x1 - tx, y1 - ty, color);
  12282. this.vertex(x2 + tx, y2 + ty, color);
  12283. this.vertex(x2 - tx, y2 - ty, color);
  12284. this.vertex(x2 + tx, y2 + ty, color);
  12285. this.vertex(x1 - tx, y1 - ty, color);
  12286. }
  12287. }
  12288. x(x, y, size) {
  12289. this.line(x - size, y - size, x + size, y + size);
  12290. this.line(x - size, y + size, x + size, y - size);
  12291. }
  12292. polygon(polygonVertices, offset, count, color) {
  12293. if (count < 3)
  12294. throw new Error("Polygon must contain at least 3 vertices");
  12295. this.check(ShapeType.Line, count * 2);
  12296. if (!color)
  12297. color = this.color;
  12298. let vertices = this.mesh.getVertices();
  12299. let idx = this.vertexIndex;
  12300. offset <<= 1;
  12301. count <<= 1;
  12302. let firstX = polygonVertices[offset];
  12303. let firstY = polygonVertices[offset + 1];
  12304. let last = offset + count;
  12305. for (let i = offset, n = offset + count - 2; i < n; i += 2) {
  12306. let x1 = polygonVertices[i];
  12307. let y1 = polygonVertices[i + 1];
  12308. let x2 = 0;
  12309. let y2 = 0;
  12310. if (i + 2 >= last) {
  12311. x2 = firstX;
  12312. y2 = firstY;
  12313. } else {
  12314. x2 = polygonVertices[i + 2];
  12315. y2 = polygonVertices[i + 3];
  12316. }
  12317. this.vertex(x1, y1, color);
  12318. this.vertex(x2, y2, color);
  12319. }
  12320. }
  12321. circle(filled, x, y, radius, color, segments = 0) {
  12322. if (segments == 0)
  12323. segments = Math.max(1, 6 * MathUtils.cbrt(radius) | 0);
  12324. if (segments <= 0)
  12325. throw new Error("segments must be > 0.");
  12326. if (!color)
  12327. color = this.color;
  12328. let angle = 2 * MathUtils.PI / segments;
  12329. let cos = Math.cos(angle);
  12330. let sin = Math.sin(angle);
  12331. let cx = radius, cy = 0;
  12332. if (!filled) {
  12333. this.check(ShapeType.Line, segments * 2 + 2);
  12334. for (let i = 0; i < segments; i++) {
  12335. this.vertex(x + cx, y + cy, color);
  12336. let temp2 = cx;
  12337. cx = cos * cx - sin * cy;
  12338. cy = sin * temp2 + cos * cy;
  12339. this.vertex(x + cx, y + cy, color);
  12340. }
  12341. this.vertex(x + cx, y + cy, color);
  12342. } else {
  12343. this.check(ShapeType.Filled, segments * 3 + 3);
  12344. segments--;
  12345. for (let i = 0; i < segments; i++) {
  12346. this.vertex(x, y, color);
  12347. this.vertex(x + cx, y + cy, color);
  12348. let temp2 = cx;
  12349. cx = cos * cx - sin * cy;
  12350. cy = sin * temp2 + cos * cy;
  12351. this.vertex(x + cx, y + cy, color);
  12352. }
  12353. this.vertex(x, y, color);
  12354. this.vertex(x + cx, y + cy, color);
  12355. }
  12356. let temp = cx;
  12357. cx = radius;
  12358. cy = 0;
  12359. this.vertex(x + cx, y + cy, color);
  12360. }
  12361. curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  12362. this.check(ShapeType.Line, segments * 2 + 2);
  12363. if (!color)
  12364. color = this.color;
  12365. let subdiv_step = 1 / segments;
  12366. let subdiv_step2 = subdiv_step * subdiv_step;
  12367. let subdiv_step3 = subdiv_step * subdiv_step * subdiv_step;
  12368. let pre1 = 3 * subdiv_step;
  12369. let pre2 = 3 * subdiv_step2;
  12370. let pre4 = 6 * subdiv_step2;
  12371. let pre5 = 6 * subdiv_step3;
  12372. let tmp1x = x1 - cx1 * 2 + cx2;
  12373. let tmp1y = y1 - cy1 * 2 + cy2;
  12374. let tmp2x = (cx1 - cx2) * 3 - x1 + x2;
  12375. let tmp2y = (cy1 - cy2) * 3 - y1 + y2;
  12376. let fx = x1;
  12377. let fy = y1;
  12378. let dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
  12379. let dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
  12380. let ddfx = tmp1x * pre4 + tmp2x * pre5;
  12381. let ddfy = tmp1y * pre4 + tmp2y * pre5;
  12382. let dddfx = tmp2x * pre5;
  12383. let dddfy = tmp2y * pre5;
  12384. while (segments-- > 0) {
  12385. this.vertex(fx, fy, color);
  12386. fx += dfx;
  12387. fy += dfy;
  12388. dfx += ddfx;
  12389. dfy += ddfy;
  12390. ddfx += dddfx;
  12391. ddfy += dddfy;
  12392. this.vertex(fx, fy, color);
  12393. }
  12394. this.vertex(fx, fy, color);
  12395. this.vertex(x2, y2, color);
  12396. }
  12397. vertex(x, y, color) {
  12398. let idx = this.vertexIndex;
  12399. let vertices = this.mesh.getVertices();
  12400. vertices[idx++] = x;
  12401. vertices[idx++] = y;
  12402. vertices[idx++] = color.r;
  12403. vertices[idx++] = color.g;
  12404. vertices[idx++] = color.b;
  12405. vertices[idx++] = color.a;
  12406. this.vertexIndex = idx;
  12407. }
  12408. end() {
  12409. if (!this.isDrawing)
  12410. throw new Error("ShapeRenderer.begin() has not been called");
  12411. this.flush();
  12412. let gl = this.context.gl;
  12413. gl.disable(gl.BLEND);
  12414. this.isDrawing = false;
  12415. }
  12416. flush() {
  12417. if (this.vertexIndex == 0)
  12418. return;
  12419. if (!this.shader)
  12420. throw new Error("No shader set.");
  12421. this.mesh.setVerticesLength(this.vertexIndex);
  12422. this.mesh.draw(this.shader, this.shapeType);
  12423. this.vertexIndex = 0;
  12424. }
  12425. check(shapeType, numVertices) {
  12426. if (!this.isDrawing)
  12427. throw new Error("ShapeRenderer.begin() has not been called");
  12428. if (this.shapeType == shapeType) {
  12429. if (this.mesh.maxVertices() - this.mesh.numVertices() < numVertices)
  12430. this.flush();
  12431. else
  12432. return;
  12433. } else {
  12434. this.flush();
  12435. this.shapeType = shapeType;
  12436. }
  12437. }
  12438. dispose() {
  12439. this.mesh.dispose();
  12440. }
  12441. };
  12442. var ShapeType = /* @__PURE__ */ ((ShapeType2) => {
  12443. ShapeType2[ShapeType2["Point"] = 0] = "Point";
  12444. ShapeType2[ShapeType2["Line"] = 1] = "Line";
  12445. ShapeType2[ShapeType2["Filled"] = 4] = "Filled";
  12446. return ShapeType2;
  12447. })(ShapeType || {});
  12448. // spine-webgl/src/SkeletonDebugRenderer.ts
  12449. var _SkeletonDebugRenderer = class {
  12450. constructor(context) {
  12451. this.boneLineColor = new Color(1, 0, 0, 1);
  12452. this.boneOriginColor = new Color(0, 1, 0, 1);
  12453. this.attachmentLineColor = new Color(0, 0, 1, 0.5);
  12454. this.triangleLineColor = new Color(1, 0.64, 0, 0.5);
  12455. this.pathColor = new Color().setFromString("FF7F00");
  12456. this.clipColor = new Color(0.8, 0, 0, 2);
  12457. this.aabbColor = new Color(0, 1, 0, 0.5);
  12458. this.drawBones = true;
  12459. this.drawRegionAttachments = true;
  12460. this.drawBoundingBoxes = true;
  12461. this.drawMeshHull = true;
  12462. this.drawMeshTriangles = true;
  12463. this.drawPaths = true;
  12464. this.drawSkeletonXY = false;
  12465. this.drawClipping = true;
  12466. this.premultipliedAlpha = false;
  12467. this.scale = 1;
  12468. this.boneWidth = 2;
  12469. this.bounds = new SkeletonBounds();
  12470. this.temp = new Array();
  12471. this.vertices = Utils.newFloatArray(2 * 1024);
  12472. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  12473. }
  12474. draw(shapes, skeleton, ignoredBones) {
  12475. let skeletonX = skeleton.x;
  12476. let skeletonY = skeleton.y;
  12477. let gl = this.context.gl;
  12478. let srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA;
  12479. shapes.setBlendMode(srcFunc, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  12480. let bones = skeleton.bones;
  12481. if (this.drawBones) {
  12482. shapes.setColor(this.boneLineColor);
  12483. for (let i = 0, n = bones.length; i < n; i++) {
  12484. let bone = bones[i];
  12485. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  12486. continue;
  12487. if (!bone.parent)
  12488. continue;
  12489. let x = bone.data.length * bone.a + bone.worldX;
  12490. let y = bone.data.length * bone.c + bone.worldY;
  12491. shapes.rectLine(true, bone.worldX, bone.worldY, x, y, this.boneWidth * this.scale);
  12492. }
  12493. if (this.drawSkeletonXY)
  12494. shapes.x(skeletonX, skeletonY, 4 * this.scale);
  12495. }
  12496. if (this.drawRegionAttachments) {
  12497. shapes.setColor(this.attachmentLineColor);
  12498. let slots = skeleton.slots;
  12499. for (let i = 0, n = slots.length; i < n; i++) {
  12500. let slot = slots[i];
  12501. let attachment = slot.getAttachment();
  12502. if (attachment instanceof RegionAttachment) {
  12503. let regionAttachment = attachment;
  12504. let vertices = this.vertices;
  12505. regionAttachment.computeWorldVertices(slot, vertices, 0, 2);
  12506. shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]);
  12507. shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]);
  12508. shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]);
  12509. shapes.line(vertices[6], vertices[7], vertices[0], vertices[1]);
  12510. }
  12511. }
  12512. }
  12513. if (this.drawMeshHull || this.drawMeshTriangles) {
  12514. let slots = skeleton.slots;
  12515. for (let i = 0, n = slots.length; i < n; i++) {
  12516. let slot = slots[i];
  12517. if (!slot.bone.active)
  12518. continue;
  12519. let attachment = slot.getAttachment();
  12520. if (!(attachment instanceof MeshAttachment))
  12521. continue;
  12522. let mesh = attachment;
  12523. let vertices = this.vertices;
  12524. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 2);
  12525. let triangles = mesh.triangles;
  12526. let hullLength = mesh.hullLength;
  12527. if (this.drawMeshTriangles) {
  12528. shapes.setColor(this.triangleLineColor);
  12529. for (let ii = 0, nn = triangles.length; ii < nn; ii += 3) {
  12530. let v1 = triangles[ii] * 2, v2 = triangles[ii + 1] * 2, v3 = triangles[ii + 2] * 2;
  12531. shapes.triangle(
  12532. false,
  12533. vertices[v1],
  12534. vertices[v1 + 1],
  12535. //
  12536. vertices[v2],
  12537. vertices[v2 + 1],
  12538. //
  12539. vertices[v3],
  12540. vertices[v3 + 1]
  12541. //
  12542. );
  12543. }
  12544. }
  12545. if (this.drawMeshHull && hullLength > 0) {
  12546. shapes.setColor(this.attachmentLineColor);
  12547. hullLength = (hullLength >> 1) * 2;
  12548. let lastX = vertices[hullLength - 2], lastY = vertices[hullLength - 1];
  12549. for (let ii = 0, nn = hullLength; ii < nn; ii += 2) {
  12550. let x = vertices[ii], y = vertices[ii + 1];
  12551. shapes.line(x, y, lastX, lastY);
  12552. lastX = x;
  12553. lastY = y;
  12554. }
  12555. }
  12556. }
  12557. }
  12558. if (this.drawBoundingBoxes) {
  12559. let bounds = this.bounds;
  12560. bounds.update(skeleton, true);
  12561. shapes.setColor(this.aabbColor);
  12562. shapes.rect(false, bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight());
  12563. let polygons = bounds.polygons;
  12564. let boxes = bounds.boundingBoxes;
  12565. for (let i = 0, n = polygons.length; i < n; i++) {
  12566. let polygon = polygons[i];
  12567. shapes.setColor(boxes[i].color);
  12568. shapes.polygon(polygon, 0, polygon.length);
  12569. }
  12570. }
  12571. if (this.drawPaths) {
  12572. let slots = skeleton.slots;
  12573. for (let i = 0, n = slots.length; i < n; i++) {
  12574. let slot = slots[i];
  12575. if (!slot.bone.active)
  12576. continue;
  12577. let attachment = slot.getAttachment();
  12578. if (!(attachment instanceof PathAttachment))
  12579. continue;
  12580. let path = attachment;
  12581. let nn = path.worldVerticesLength;
  12582. let world = this.temp = Utils.setArraySize(this.temp, nn, 0);
  12583. path.computeWorldVertices(slot, 0, nn, world, 0, 2);
  12584. let color = this.pathColor;
  12585. let x1 = world[2], y1 = world[3], x2 = 0, y2 = 0;
  12586. if (path.closed) {
  12587. shapes.setColor(color);
  12588. let cx1 = world[0], cy1 = world[1], cx2 = world[nn - 2], cy2 = world[nn - 1];
  12589. x2 = world[nn - 4];
  12590. y2 = world[nn - 3];
  12591. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  12592. shapes.setColor(_SkeletonDebugRenderer.LIGHT_GRAY);
  12593. shapes.line(x1, y1, cx1, cy1);
  12594. shapes.line(x2, y2, cx2, cy2);
  12595. }
  12596. nn -= 4;
  12597. for (let ii = 4; ii < nn; ii += 6) {
  12598. let cx1 = world[ii], cy1 = world[ii + 1], cx2 = world[ii + 2], cy2 = world[ii + 3];
  12599. x2 = world[ii + 4];
  12600. y2 = world[ii + 5];
  12601. shapes.setColor(color);
  12602. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  12603. shapes.setColor(_SkeletonDebugRenderer.LIGHT_GRAY);
  12604. shapes.line(x1, y1, cx1, cy1);
  12605. shapes.line(x2, y2, cx2, cy2);
  12606. x1 = x2;
  12607. y1 = y2;
  12608. }
  12609. }
  12610. }
  12611. if (this.drawBones) {
  12612. shapes.setColor(this.boneOriginColor);
  12613. for (let i = 0, n = bones.length; i < n; i++) {
  12614. let bone = bones[i];
  12615. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  12616. continue;
  12617. shapes.circle(true, bone.worldX, bone.worldY, 3 * this.scale, this.boneOriginColor, 8);
  12618. }
  12619. }
  12620. if (this.drawClipping) {
  12621. let slots = skeleton.slots;
  12622. shapes.setColor(this.clipColor);
  12623. for (let i = 0, n = slots.length; i < n; i++) {
  12624. let slot = slots[i];
  12625. if (!slot.bone.active)
  12626. continue;
  12627. let attachment = slot.getAttachment();
  12628. if (!(attachment instanceof ClippingAttachment))
  12629. continue;
  12630. let clip = attachment;
  12631. let nn = clip.worldVerticesLength;
  12632. let world = this.temp = Utils.setArraySize(this.temp, nn, 0);
  12633. clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
  12634. for (let i2 = 0, n2 = world.length; i2 < n2; i2 += 2) {
  12635. let x = world[i2];
  12636. let y = world[i2 + 1];
  12637. let x2 = world[(i2 + 2) % world.length];
  12638. let y2 = world[(i2 + 3) % world.length];
  12639. shapes.line(x, y, x2, y2);
  12640. }
  12641. }
  12642. }
  12643. }
  12644. dispose() {
  12645. }
  12646. };
  12647. var SkeletonDebugRenderer = _SkeletonDebugRenderer;
  12648. SkeletonDebugRenderer.LIGHT_GRAY = new Color(192 / 255, 192 / 255, 192 / 255, 1);
  12649. SkeletonDebugRenderer.GREEN = new Color(0, 1, 0, 1);
  12650. // spine-webgl/src/SkeletonRenderer.ts
  12651. var Renderable = class {
  12652. constructor(vertices, numVertices, numFloats) {
  12653. this.vertices = vertices;
  12654. this.numVertices = numVertices;
  12655. this.numFloats = numFloats;
  12656. }
  12657. };
  12658. var _SkeletonRenderer = class {
  12659. constructor(context, twoColorTint = true) {
  12660. this.premultipliedAlpha = false;
  12661. this.tempColor = new Color();
  12662. this.tempColor2 = new Color();
  12663. this.vertexSize = 2 + 2 + 4;
  12664. this.twoColorTint = false;
  12665. this.renderable = new Renderable([], 0, 0);
  12666. this.clipper = new SkeletonClipping();
  12667. this.temp = new Vector2();
  12668. this.temp2 = new Vector2();
  12669. this.temp3 = new Color();
  12670. this.temp4 = new Color();
  12671. this.twoColorTint = twoColorTint;
  12672. if (twoColorTint)
  12673. this.vertexSize += 4;
  12674. this.vertices = Utils.newFloatArray(this.vertexSize * 1024);
  12675. }
  12676. draw(batcher, skeleton, slotRangeStart = -1, slotRangeEnd = -1, transformer = null) {
  12677. let clipper = this.clipper;
  12678. let premultipliedAlpha = this.premultipliedAlpha;
  12679. let twoColorTint = this.twoColorTint;
  12680. let blendMode = null;
  12681. let tempPos = this.temp;
  12682. let tempUv = this.temp2;
  12683. let tempLight = this.temp3;
  12684. let tempDark = this.temp4;
  12685. let renderable = this.renderable;
  12686. let uvs;
  12687. let triangles;
  12688. let drawOrder = skeleton.drawOrder;
  12689. let attachmentColor;
  12690. let skeletonColor = skeleton.color;
  12691. let vertexSize = twoColorTint ? 12 : 8;
  12692. let inRange = false;
  12693. if (slotRangeStart == -1)
  12694. inRange = true;
  12695. for (let i = 0, n = drawOrder.length; i < n; i++) {
  12696. let clippedVertexSize = clipper.isClipping() ? 2 : vertexSize;
  12697. let slot = drawOrder[i];
  12698. if (!slot.bone.active) {
  12699. clipper.clipEndWithSlot(slot);
  12700. continue;
  12701. }
  12702. if (slotRangeStart >= 0 && slotRangeStart == slot.data.index) {
  12703. inRange = true;
  12704. }
  12705. if (!inRange) {
  12706. clipper.clipEndWithSlot(slot);
  12707. continue;
  12708. }
  12709. if (slotRangeEnd >= 0 && slotRangeEnd == slot.data.index) {
  12710. inRange = false;
  12711. }
  12712. let attachment = slot.getAttachment();
  12713. let texture;
  12714. if (attachment instanceof RegionAttachment) {
  12715. let region = attachment;
  12716. renderable.vertices = this.vertices;
  12717. renderable.numVertices = 4;
  12718. renderable.numFloats = clippedVertexSize << 2;
  12719. region.computeWorldVertices(slot, renderable.vertices, 0, clippedVertexSize);
  12720. triangles = _SkeletonRenderer.QUAD_TRIANGLES;
  12721. uvs = region.uvs;
  12722. texture = region.region.texture;
  12723. attachmentColor = region.color;
  12724. } else if (attachment instanceof MeshAttachment) {
  12725. let mesh = attachment;
  12726. renderable.vertices = this.vertices;
  12727. renderable.numVertices = mesh.worldVerticesLength >> 1;
  12728. renderable.numFloats = renderable.numVertices * clippedVertexSize;
  12729. if (renderable.numFloats > renderable.vertices.length) {
  12730. renderable.vertices = this.vertices = Utils.newFloatArray(renderable.numFloats);
  12731. }
  12732. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, renderable.vertices, 0, clippedVertexSize);
  12733. triangles = mesh.triangles;
  12734. texture = mesh.region.texture;
  12735. uvs = mesh.uvs;
  12736. attachmentColor = mesh.color;
  12737. } else if (attachment instanceof ClippingAttachment) {
  12738. let clip = attachment;
  12739. clipper.clipStart(slot, clip);
  12740. continue;
  12741. } else {
  12742. clipper.clipEndWithSlot(slot);
  12743. continue;
  12744. }
  12745. if (texture) {
  12746. let slotColor = slot.color;
  12747. let finalColor = this.tempColor;
  12748. finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
  12749. finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
  12750. finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
  12751. finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
  12752. if (premultipliedAlpha) {
  12753. finalColor.r *= finalColor.a;
  12754. finalColor.g *= finalColor.a;
  12755. finalColor.b *= finalColor.a;
  12756. }
  12757. let darkColor = this.tempColor2;
  12758. if (!slot.darkColor)
  12759. darkColor.set(0, 0, 0, 1);
  12760. else {
  12761. if (premultipliedAlpha) {
  12762. darkColor.r = slot.darkColor.r * finalColor.a;
  12763. darkColor.g = slot.darkColor.g * finalColor.a;
  12764. darkColor.b = slot.darkColor.b * finalColor.a;
  12765. } else {
  12766. darkColor.setFromColor(slot.darkColor);
  12767. }
  12768. darkColor.a = premultipliedAlpha ? 1 : 0;
  12769. }
  12770. let slotBlendMode = slot.data.blendMode;
  12771. if (slotBlendMode != blendMode) {
  12772. blendMode = slotBlendMode;
  12773. batcher.setBlendMode(
  12774. WebGLBlendModeConverter.getSourceColorGLBlendMode(blendMode, premultipliedAlpha),
  12775. WebGLBlendModeConverter.getSourceAlphaGLBlendMode(blendMode),
  12776. WebGLBlendModeConverter.getDestGLBlendMode(blendMode)
  12777. );
  12778. }
  12779. if (clipper.isClipping()) {
  12780. clipper.clipTriangles(renderable.vertices, renderable.numFloats, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint);
  12781. let clippedVertices = new Float32Array(clipper.clippedVertices);
  12782. let clippedTriangles = clipper.clippedTriangles;
  12783. if (transformer)
  12784. transformer(clippedVertices, clippedVertices.length, vertexSize);
  12785. batcher.draw(texture, clippedVertices, clippedTriangles);
  12786. } else {
  12787. let verts = renderable.vertices;
  12788. if (!twoColorTint) {
  12789. for (let v = 2, u = 0, n2 = renderable.numFloats; v < n2; v += vertexSize, u += 2) {
  12790. verts[v] = finalColor.r;
  12791. verts[v + 1] = finalColor.g;
  12792. verts[v + 2] = finalColor.b;
  12793. verts[v + 3] = finalColor.a;
  12794. verts[v + 4] = uvs[u];
  12795. verts[v + 5] = uvs[u + 1];
  12796. }
  12797. } else {
  12798. for (let v = 2, u = 0, n2 = renderable.numFloats; v < n2; v += vertexSize, u += 2) {
  12799. verts[v] = finalColor.r;
  12800. verts[v + 1] = finalColor.g;
  12801. verts[v + 2] = finalColor.b;
  12802. verts[v + 3] = finalColor.a;
  12803. verts[v + 4] = uvs[u];
  12804. verts[v + 5] = uvs[u + 1];
  12805. verts[v + 6] = darkColor.r;
  12806. verts[v + 7] = darkColor.g;
  12807. verts[v + 8] = darkColor.b;
  12808. verts[v + 9] = darkColor.a;
  12809. }
  12810. }
  12811. let view = renderable.vertices.subarray(0, renderable.numFloats);
  12812. if (transformer)
  12813. transformer(renderable.vertices, renderable.numFloats, vertexSize);
  12814. batcher.draw(texture, view, triangles);
  12815. }
  12816. }
  12817. clipper.clipEndWithSlot(slot);
  12818. }
  12819. clipper.clipEnd();
  12820. }
  12821. };
  12822. var SkeletonRenderer = _SkeletonRenderer;
  12823. SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  12824. // spine-webgl/src/SceneRenderer.ts
  12825. var quad = [
  12826. 0,
  12827. 0,
  12828. 1,
  12829. 1,
  12830. 1,
  12831. 1,
  12832. 0,
  12833. 0,
  12834. 0,
  12835. 0,
  12836. 1,
  12837. 1,
  12838. 1,
  12839. 1,
  12840. 0,
  12841. 0,
  12842. 0,
  12843. 0,
  12844. 1,
  12845. 1,
  12846. 1,
  12847. 1,
  12848. 0,
  12849. 0,
  12850. 0,
  12851. 0,
  12852. 1,
  12853. 1,
  12854. 1,
  12855. 1,
  12856. 0,
  12857. 0
  12858. ];
  12859. var QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  12860. var WHITE = new Color(1, 1, 1, 1);
  12861. var SceneRenderer = class {
  12862. constructor(canvas, context, twoColorTint = true) {
  12863. this.twoColorTint = false;
  12864. this.activeRenderer = null;
  12865. this.canvas = canvas;
  12866. this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context);
  12867. this.twoColorTint = twoColorTint;
  12868. this.camera = new OrthoCamera(canvas.width, canvas.height);
  12869. this.batcherShader = twoColorTint ? Shader.newTwoColoredTextured(this.context) : Shader.newColoredTextured(this.context);
  12870. this.batcher = new PolygonBatcher(this.context, twoColorTint);
  12871. this.shapesShader = Shader.newColored(this.context);
  12872. this.shapes = new ShapeRenderer(this.context);
  12873. this.skeletonRenderer = new SkeletonRenderer(this.context, twoColorTint);
  12874. this.skeletonDebugRenderer = new SkeletonDebugRenderer(this.context);
  12875. }
  12876. dispose() {
  12877. this.batcher.dispose();
  12878. this.batcherShader.dispose();
  12879. this.shapes.dispose();
  12880. this.shapesShader.dispose();
  12881. this.skeletonDebugRenderer.dispose();
  12882. }
  12883. begin() {
  12884. this.camera.update();
  12885. this.enableRenderer(this.batcher);
  12886. }
  12887. drawSkeleton(skeleton, premultipliedAlpha = false, slotRangeStart = -1, slotRangeEnd = -1, transform = null) {
  12888. this.enableRenderer(this.batcher);
  12889. this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
  12890. this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd, transform);
  12891. }
  12892. drawSkeletonDebug(skeleton, premultipliedAlpha = false, ignoredBones) {
  12893. this.enableRenderer(this.shapes);
  12894. this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha;
  12895. this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones);
  12896. }
  12897. drawTexture(texture, x, y, width, height, color) {
  12898. this.enableRenderer(this.batcher);
  12899. if (!color)
  12900. color = WHITE;
  12901. var i = 0;
  12902. quad[i++] = x;
  12903. quad[i++] = y;
  12904. quad[i++] = color.r;
  12905. quad[i++] = color.g;
  12906. quad[i++] = color.b;
  12907. quad[i++] = color.a;
  12908. quad[i++] = 0;
  12909. quad[i++] = 1;
  12910. if (this.twoColorTint) {
  12911. quad[i++] = 0;
  12912. quad[i++] = 0;
  12913. quad[i++] = 0;
  12914. quad[i++] = 0;
  12915. }
  12916. quad[i++] = x + width;
  12917. quad[i++] = y;
  12918. quad[i++] = color.r;
  12919. quad[i++] = color.g;
  12920. quad[i++] = color.b;
  12921. quad[i++] = color.a;
  12922. quad[i++] = 1;
  12923. quad[i++] = 1;
  12924. if (this.twoColorTint) {
  12925. quad[i++] = 0;
  12926. quad[i++] = 0;
  12927. quad[i++] = 0;
  12928. quad[i++] = 0;
  12929. }
  12930. quad[i++] = x + width;
  12931. quad[i++] = y + height;
  12932. quad[i++] = color.r;
  12933. quad[i++] = color.g;
  12934. quad[i++] = color.b;
  12935. quad[i++] = color.a;
  12936. quad[i++] = 1;
  12937. quad[i++] = 0;
  12938. if (this.twoColorTint) {
  12939. quad[i++] = 0;
  12940. quad[i++] = 0;
  12941. quad[i++] = 0;
  12942. quad[i++] = 0;
  12943. }
  12944. quad[i++] = x;
  12945. quad[i++] = y + height;
  12946. quad[i++] = color.r;
  12947. quad[i++] = color.g;
  12948. quad[i++] = color.b;
  12949. quad[i++] = color.a;
  12950. quad[i++] = 0;
  12951. quad[i++] = 0;
  12952. if (this.twoColorTint) {
  12953. quad[i++] = 0;
  12954. quad[i++] = 0;
  12955. quad[i++] = 0;
  12956. quad[i] = 0;
  12957. }
  12958. this.batcher.draw(texture, quad, QUAD_TRIANGLES);
  12959. }
  12960. drawTextureUV(texture, x, y, width, height, u, v, u2, v2, color) {
  12961. this.enableRenderer(this.batcher);
  12962. if (!color)
  12963. color = WHITE;
  12964. var i = 0;
  12965. quad[i++] = x;
  12966. quad[i++] = y;
  12967. quad[i++] = color.r;
  12968. quad[i++] = color.g;
  12969. quad[i++] = color.b;
  12970. quad[i++] = color.a;
  12971. quad[i++] = u;
  12972. quad[i++] = v;
  12973. if (this.twoColorTint) {
  12974. quad[i++] = 0;
  12975. quad[i++] = 0;
  12976. quad[i++] = 0;
  12977. quad[i++] = 0;
  12978. }
  12979. quad[i++] = x + width;
  12980. quad[i++] = y;
  12981. quad[i++] = color.r;
  12982. quad[i++] = color.g;
  12983. quad[i++] = color.b;
  12984. quad[i++] = color.a;
  12985. quad[i++] = u2;
  12986. quad[i++] = v;
  12987. if (this.twoColorTint) {
  12988. quad[i++] = 0;
  12989. quad[i++] = 0;
  12990. quad[i++] = 0;
  12991. quad[i++] = 0;
  12992. }
  12993. quad[i++] = x + width;
  12994. quad[i++] = y + height;
  12995. quad[i++] = color.r;
  12996. quad[i++] = color.g;
  12997. quad[i++] = color.b;
  12998. quad[i++] = color.a;
  12999. quad[i++] = u2;
  13000. quad[i++] = v2;
  13001. if (this.twoColorTint) {
  13002. quad[i++] = 0;
  13003. quad[i++] = 0;
  13004. quad[i++] = 0;
  13005. quad[i++] = 0;
  13006. }
  13007. quad[i++] = x;
  13008. quad[i++] = y + height;
  13009. quad[i++] = color.r;
  13010. quad[i++] = color.g;
  13011. quad[i++] = color.b;
  13012. quad[i++] = color.a;
  13013. quad[i++] = u;
  13014. quad[i++] = v2;
  13015. if (this.twoColorTint) {
  13016. quad[i++] = 0;
  13017. quad[i++] = 0;
  13018. quad[i++] = 0;
  13019. quad[i] = 0;
  13020. }
  13021. this.batcher.draw(texture, quad, QUAD_TRIANGLES);
  13022. }
  13023. drawTextureRotated(texture, x, y, width, height, pivotX, pivotY, angle, color) {
  13024. this.enableRenderer(this.batcher);
  13025. if (!color)
  13026. color = WHITE;
  13027. let worldOriginX = x + pivotX;
  13028. let worldOriginY = y + pivotY;
  13029. let fx = -pivotX;
  13030. let fy = -pivotY;
  13031. let fx2 = width - pivotX;
  13032. let fy2 = height - pivotY;
  13033. let p1x = fx;
  13034. let p1y = fy;
  13035. let p2x = fx;
  13036. let p2y = fy2;
  13037. let p3x = fx2;
  13038. let p3y = fy2;
  13039. let p4x = fx2;
  13040. let p4y = fy;
  13041. let x1 = 0;
  13042. let y1 = 0;
  13043. let x2 = 0;
  13044. let y2 = 0;
  13045. let x3 = 0;
  13046. let y3 = 0;
  13047. let x4 = 0;
  13048. let y4 = 0;
  13049. if (angle != 0) {
  13050. let cos = MathUtils.cosDeg(angle);
  13051. let sin = MathUtils.sinDeg(angle);
  13052. x1 = cos * p1x - sin * p1y;
  13053. y1 = sin * p1x + cos * p1y;
  13054. x4 = cos * p2x - sin * p2y;
  13055. y4 = sin * p2x + cos * p2y;
  13056. x3 = cos * p3x - sin * p3y;
  13057. y3 = sin * p3x + cos * p3y;
  13058. x2 = x3 + (x1 - x4);
  13059. y2 = y3 + (y1 - y4);
  13060. } else {
  13061. x1 = p1x;
  13062. y1 = p1y;
  13063. x4 = p2x;
  13064. y4 = p2y;
  13065. x3 = p3x;
  13066. y3 = p3y;
  13067. x2 = p4x;
  13068. y2 = p4y;
  13069. }
  13070. x1 += worldOriginX;
  13071. y1 += worldOriginY;
  13072. x2 += worldOriginX;
  13073. y2 += worldOriginY;
  13074. x3 += worldOriginX;
  13075. y3 += worldOriginY;
  13076. x4 += worldOriginX;
  13077. y4 += worldOriginY;
  13078. var i = 0;
  13079. quad[i++] = x1;
  13080. quad[i++] = y1;
  13081. quad[i++] = color.r;
  13082. quad[i++] = color.g;
  13083. quad[i++] = color.b;
  13084. quad[i++] = color.a;
  13085. quad[i++] = 0;
  13086. quad[i++] = 1;
  13087. if (this.twoColorTint) {
  13088. quad[i++] = 0;
  13089. quad[i++] = 0;
  13090. quad[i++] = 0;
  13091. quad[i++] = 0;
  13092. }
  13093. quad[i++] = x2;
  13094. quad[i++] = y2;
  13095. quad[i++] = color.r;
  13096. quad[i++] = color.g;
  13097. quad[i++] = color.b;
  13098. quad[i++] = color.a;
  13099. quad[i++] = 1;
  13100. quad[i++] = 1;
  13101. if (this.twoColorTint) {
  13102. quad[i++] = 0;
  13103. quad[i++] = 0;
  13104. quad[i++] = 0;
  13105. quad[i++] = 0;
  13106. }
  13107. quad[i++] = x3;
  13108. quad[i++] = y3;
  13109. quad[i++] = color.r;
  13110. quad[i++] = color.g;
  13111. quad[i++] = color.b;
  13112. quad[i++] = color.a;
  13113. quad[i++] = 1;
  13114. quad[i++] = 0;
  13115. if (this.twoColorTint) {
  13116. quad[i++] = 0;
  13117. quad[i++] = 0;
  13118. quad[i++] = 0;
  13119. quad[i++] = 0;
  13120. }
  13121. quad[i++] = x4;
  13122. quad[i++] = y4;
  13123. quad[i++] = color.r;
  13124. quad[i++] = color.g;
  13125. quad[i++] = color.b;
  13126. quad[i++] = color.a;
  13127. quad[i++] = 0;
  13128. quad[i++] = 0;
  13129. if (this.twoColorTint) {
  13130. quad[i++] = 0;
  13131. quad[i++] = 0;
  13132. quad[i++] = 0;
  13133. quad[i] = 0;
  13134. }
  13135. this.batcher.draw(texture, quad, QUAD_TRIANGLES);
  13136. }
  13137. drawRegion(region, x, y, width, height, color) {
  13138. this.enableRenderer(this.batcher);
  13139. if (!color)
  13140. color = WHITE;
  13141. var i = 0;
  13142. quad[i++] = x;
  13143. quad[i++] = y;
  13144. quad[i++] = color.r;
  13145. quad[i++] = color.g;
  13146. quad[i++] = color.b;
  13147. quad[i++] = color.a;
  13148. quad[i++] = region.u;
  13149. quad[i++] = region.v2;
  13150. if (this.twoColorTint) {
  13151. quad[i++] = 0;
  13152. quad[i++] = 0;
  13153. quad[i++] = 0;
  13154. quad[i++] = 0;
  13155. }
  13156. quad[i++] = x + width;
  13157. quad[i++] = y;
  13158. quad[i++] = color.r;
  13159. quad[i++] = color.g;
  13160. quad[i++] = color.b;
  13161. quad[i++] = color.a;
  13162. quad[i++] = region.u2;
  13163. quad[i++] = region.v2;
  13164. if (this.twoColorTint) {
  13165. quad[i++] = 0;
  13166. quad[i++] = 0;
  13167. quad[i++] = 0;
  13168. quad[i++] = 0;
  13169. }
  13170. quad[i++] = x + width;
  13171. quad[i++] = y + height;
  13172. quad[i++] = color.r;
  13173. quad[i++] = color.g;
  13174. quad[i++] = color.b;
  13175. quad[i++] = color.a;
  13176. quad[i++] = region.u2;
  13177. quad[i++] = region.v;
  13178. if (this.twoColorTint) {
  13179. quad[i++] = 0;
  13180. quad[i++] = 0;
  13181. quad[i++] = 0;
  13182. quad[i++] = 0;
  13183. }
  13184. quad[i++] = x;
  13185. quad[i++] = y + height;
  13186. quad[i++] = color.r;
  13187. quad[i++] = color.g;
  13188. quad[i++] = color.b;
  13189. quad[i++] = color.a;
  13190. quad[i++] = region.u;
  13191. quad[i++] = region.v;
  13192. if (this.twoColorTint) {
  13193. quad[i++] = 0;
  13194. quad[i++] = 0;
  13195. quad[i++] = 0;
  13196. quad[i] = 0;
  13197. }
  13198. this.batcher.draw(region.page.texture, quad, QUAD_TRIANGLES);
  13199. }
  13200. line(x, y, x2, y2, color, color2) {
  13201. this.enableRenderer(this.shapes);
  13202. this.shapes.line(x, y, x2, y2, color);
  13203. }
  13204. triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  13205. this.enableRenderer(this.shapes);
  13206. this.shapes.triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3);
  13207. }
  13208. quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  13209. this.enableRenderer(this.shapes);
  13210. this.shapes.quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4);
  13211. }
  13212. rect(filled, x, y, width, height, color) {
  13213. this.enableRenderer(this.shapes);
  13214. this.shapes.rect(filled, x, y, width, height, color);
  13215. }
  13216. rectLine(filled, x1, y1, x2, y2, width, color) {
  13217. this.enableRenderer(this.shapes);
  13218. this.shapes.rectLine(filled, x1, y1, x2, y2, width, color);
  13219. }
  13220. polygon(polygonVertices, offset, count, color) {
  13221. this.enableRenderer(this.shapes);
  13222. this.shapes.polygon(polygonVertices, offset, count, color);
  13223. }
  13224. circle(filled, x, y, radius, color, segments = 0) {
  13225. this.enableRenderer(this.shapes);
  13226. this.shapes.circle(filled, x, y, radius, color, segments);
  13227. }
  13228. curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  13229. this.enableRenderer(this.shapes);
  13230. this.shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color);
  13231. }
  13232. end() {
  13233. if (this.activeRenderer === this.batcher)
  13234. this.batcher.end();
  13235. else if (this.activeRenderer === this.shapes)
  13236. this.shapes.end();
  13237. this.activeRenderer = null;
  13238. }
  13239. resize(resizeMode) {
  13240. let canvas = this.canvas;
  13241. var dpr = window.devicePixelRatio || 1;
  13242. var w = Math.round(canvas.clientWidth * dpr);
  13243. var h = Math.round(canvas.clientHeight * dpr);
  13244. if (canvas.width != w || canvas.height != h) {
  13245. canvas.width = w;
  13246. canvas.height = h;
  13247. }
  13248. this.context.gl.viewport(0, 0, canvas.width, canvas.height);
  13249. if (resizeMode === ResizeMode.Expand)
  13250. this.camera.setViewport(w, h);
  13251. else if (resizeMode === ResizeMode.Fit) {
  13252. let sourceWidth = canvas.width, sourceHeight = canvas.height;
  13253. let targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHeight;
  13254. let targetRatio = targetHeight / targetWidth;
  13255. let sourceRatio = sourceHeight / sourceWidth;
  13256. let scale = targetRatio < sourceRatio ? targetWidth / sourceWidth : targetHeight / sourceHeight;
  13257. this.camera.setViewport(sourceWidth * scale, sourceHeight * scale);
  13258. }
  13259. this.camera.update();
  13260. }
  13261. enableRenderer(renderer) {
  13262. if (this.activeRenderer === renderer)
  13263. return;
  13264. this.end();
  13265. if (renderer instanceof PolygonBatcher) {
  13266. this.batcherShader.bind();
  13267. this.batcherShader.setUniform4x4f(Shader.MVP_MATRIX, this.camera.projectionView.values);
  13268. this.batcherShader.setUniformi("u_texture", 0);
  13269. this.batcher.begin(this.batcherShader);
  13270. this.activeRenderer = this.batcher;
  13271. } else if (renderer instanceof ShapeRenderer) {
  13272. this.shapesShader.bind();
  13273. this.shapesShader.setUniform4x4f(Shader.MVP_MATRIX, this.camera.projectionView.values);
  13274. this.shapes.begin(this.shapesShader);
  13275. this.activeRenderer = this.shapes;
  13276. } else
  13277. this.activeRenderer = this.skeletonDebugRenderer;
  13278. }
  13279. };
  13280. var ResizeMode = /* @__PURE__ */ ((ResizeMode2) => {
  13281. ResizeMode2[ResizeMode2["Stretch"] = 0] = "Stretch";
  13282. ResizeMode2[ResizeMode2["Expand"] = 1] = "Expand";
  13283. ResizeMode2[ResizeMode2["Fit"] = 2] = "Fit";
  13284. return ResizeMode2;
  13285. })(ResizeMode || {});
  13286. // spine-webgl/src/LoadingScreen.ts
  13287. var spinnerImage;
  13288. var logoImage;
  13289. var loaded = 0;
  13290. var FADE_IN = 1;
  13291. var FADE_OUT = 1;
  13292. var logoWidth = 165;
  13293. var logoHeight = 108;
  13294. var spinnerSize = 163;
  13295. var LoadingScreen = class {
  13296. constructor(renderer) {
  13297. this.logo = null;
  13298. this.spinner = null;
  13299. this.angle = 0;
  13300. this.fadeOut = 0;
  13301. this.fadeIn = 0;
  13302. this.timeKeeper = new TimeKeeper();
  13303. this.backgroundColor = new Color(0.135, 0.135, 0.135, 1);
  13304. this.tempColor = new Color();
  13305. this.renderer = renderer;
  13306. this.timeKeeper.maxDelta = 9;
  13307. if (!logoImage) {
  13308. let isSafari = navigator.userAgent.indexOf("Safari") > -1;
  13309. let onload = () => loaded++;
  13310. logoImage = new Image();
  13311. logoImage.src = SPINE_LOGO_DATA;
  13312. if (!isSafari)
  13313. logoImage.crossOrigin = "anonymous";
  13314. logoImage.onload = onload;
  13315. spinnerImage = new Image();
  13316. spinnerImage.src = SPINNER_DATA;
  13317. if (!isSafari)
  13318. spinnerImage.crossOrigin = "anonymous";
  13319. spinnerImage.onload = onload;
  13320. }
  13321. }
  13322. dispose() {
  13323. var _a, _b;
  13324. (_a = this.logo) == null ? void 0 : _a.dispose();
  13325. (_b = this.spinner) == null ? void 0 : _b.dispose();
  13326. }
  13327. draw(complete = false) {
  13328. if (loaded < 2 || complete && this.fadeOut > FADE_OUT)
  13329. return;
  13330. this.timeKeeper.update();
  13331. let a = Math.abs(Math.sin(this.timeKeeper.totalTime + 0.25));
  13332. this.angle -= this.timeKeeper.delta * 200 * (1 + 1.5 * Math.pow(a, 5));
  13333. let tempColor = this.tempColor;
  13334. let renderer = this.renderer;
  13335. let canvas = renderer.canvas;
  13336. let gl = renderer.context.gl;
  13337. renderer.resize(1 /* Expand */);
  13338. renderer.camera.position.set(canvas.width / 2, canvas.height / 2, 0);
  13339. renderer.batcher.setBlendMode(gl.ONE, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  13340. if (complete) {
  13341. this.fadeOut += this.timeKeeper.delta * (this.timeKeeper.totalTime < 1 ? 2 : 1);
  13342. if (this.fadeOut > FADE_OUT)
  13343. return;
  13344. tempColor.setFromColor(this.backgroundColor);
  13345. a = 1 - this.fadeOut / FADE_OUT;
  13346. a = 1 - (a - 1) * (a - 1);
  13347. tempColor.a *= a;
  13348. if (tempColor.a > 0) {
  13349. renderer.camera.zoom = 1;
  13350. renderer.begin();
  13351. renderer.quad(
  13352. true,
  13353. 0,
  13354. 0,
  13355. canvas.width,
  13356. 0,
  13357. canvas.width,
  13358. canvas.height,
  13359. 0,
  13360. canvas.height,
  13361. tempColor,
  13362. tempColor,
  13363. tempColor,
  13364. tempColor
  13365. );
  13366. renderer.end();
  13367. }
  13368. } else {
  13369. this.fadeIn += this.timeKeeper.delta;
  13370. if (this.backgroundColor.a > 0) {
  13371. gl.clearColor(this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a);
  13372. gl.clear(gl.COLOR_BUFFER_BIT);
  13373. }
  13374. a = 1;
  13375. }
  13376. a *= Math.min(this.fadeIn / FADE_IN, 1);
  13377. tempColor.set(a, a, a, a);
  13378. if (!this.logo) {
  13379. this.logo = new GLTexture(renderer.context, logoImage);
  13380. this.spinner = new GLTexture(renderer.context, spinnerImage);
  13381. }
  13382. renderer.camera.zoom = Math.max(1, spinnerSize / canvas.height);
  13383. renderer.begin();
  13384. renderer.drawTexture(this.logo, (canvas.width - logoWidth) / 2, (canvas.height - logoHeight) / 2, logoWidth, logoHeight, tempColor);
  13385. if (this.spinner)
  13386. renderer.drawTextureRotated(this.spinner, (canvas.width - spinnerSize) / 2, (canvas.height - spinnerSize) / 2, spinnerSize, spinnerSize, spinnerSize / 2, spinnerSize / 2, this.angle, tempColor);
  13387. renderer.end();
  13388. }
  13389. };
  13390. var SPINNER_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKMAAACjCAYAAADmbK6AAAALKElEQVR42u2de2iW5R/GPzuqcwfnnKfNmafl5tTNHWzqNi3DEMQykcAoJSsySkspjSIk0iD/07Kf4R+FnVBDUTshZGpWUEJaaiWFgZlUFmXmIe3HNXthyebeZ77P9H13ffBG8Y8H7ut7vff93N/7fu4vGGPiFZiez/Qtw9lytJajfzfw9z/j+efPOv7cV8W+lUNY2a8T/ayTCRsWFLJA5rtUO1LLkV5p9LJeJizQiHeqnlOtmVFtdTGrrZkJCxYXsTgaI6r9MY4/UpNItW4mFDaXsTlaM6qVZlBq3UwofFrJp0HMWJ9DvXUzobCznJ1BzFjWlTLrZkJh/TDWBzFjTgo51s2EgnKI0Rrx+FiOWzNzVaym91Syx5qZsGBWb2ZFa0ZN6dbMhAWTcpkUrRmXD2K5NTNhgVbH0Zpxbl/mWjMTFvRIo0e0ZpzcncnWzISKtvmiMWNRJ4qslwmVXRXsas2Ix8ZwzFqZsGFREYtaM+Oaa1ljrUzYkJ9G/ok6TlzKjJWZVFor0y7c1Zu7WjLiqiGsskamXdHopyT4vALmzS9k/t19uHtKHlOSIMn6xAtARjIZ1sFcUSZ0Y4La+G6M18hS2IlCn4a+WoC0JNL0d/dUupdnUj40g6EJ2VEdMnhrOG/p5f/jUXz8SgmvaGU6KpNRNsLVQV0OdXf24s63h/P2gWoOrBjMCr2GJFQnnxnIM3q5P1PPmaYv+4ev4/C6UtbpV2gzXCkgL5W8Bwt48OIc6ul6Tp+s4+SyASxLiI4+PYCn1bHzDZxvaQW6vZzto7MYnQIpNkf7kp5EuozYUroqEjcNKHHd0Tl9mBPN1pk+hFeieGBnBtog7UXjsj9pWg+m6duecw2cay1OC/uxMC47KmP9OIYfoz1YoC20J/rzRG4quTZK2EAyJGs20qwUbYw0aNRmUxtvfUW/uEtNzc1NB1/X8LVyd15hh82F43AvD+VlXcsSJEZa1CQ3ejleAO7oxR3RDP0XN91X4+NXYb8nkv7UNTwV7e0YTdu7I3g33t7tuaEbNwSZpps2fSyvs4M2Tjhot+jb0Xzbltj8r5j/xVt/6Z1Ob93U1ZYO691EhhzchcHeXosVjcNZysyezLw4xRZt05R+fTeuj8vOj+zKyG0j2aZcVVs6v+QalnjrMFZASQYl2nBoSyz06e3j/Xk8rgWYmMvEICu2pm1HOTuc7okV8FgRj0XukwzanhvCc/F+72TjoQjdObN1OFuDLmh0xP+WHtxiI10ukJlCprb4guiv1fP+avZrS1C7NAkliHZjDtZwMMgqbukAltpMlwuMy2FcEBPqvfLLar5Uqi0hBdEwryy+Mv5n6zkbjTBa+dlMlwvUZFETZKGiFM7tvbhdJ3gSVRO0wzIjnxmvl/J6a6JsGMYGrahtpssFeqbR841S3mhN80OjOaSDEdqd6SjaMKgzgzRK7q1ib3PT9sYyNo7JZoyNFNvRcVMZmy7WOvIuryv/Zvdmdt90+nY0bRp3AvROohFwdwW7dTG7RFlbwlqdrbOBYg005NAQmZU0HWt1rXMBH1Xw0dQ8pmqzoaPmdhun7bHZjNVe9qP9eFQfO1VkUmHjhAVUZ1GtnKFSbjrkrPfy4i4UW5t/6ZxM54J0CqxFe81KpGsQyE4h23oYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjLna+bdOy+IiFquIpGq16Pb79cNYv3IIK/X/ugx+Ui6TVKvYVU9Nc8gX8od8Ir/IN/KPfCQ/yVfyl/6/pfJvLChkQdD6wyqntquCXYuKWJSfRr6D0dEAxV3xlw/khyD+kd/ku/88cHo+09tS3LBpO1HHCVUqcIA6CqB4K+6X6x35L/JM2loXurlWmUmlA5XogOIcK8/If5HncrSWo7F6cKIWPjT/RXGOlWfkv8hzaWsN4uaaysE6WIkOKM6x8oz8F3kusXqo2vxC5jtYiQ4ozrH0TeS5qIZcrB7qkrwdA8U5Vp6R/yLPZV8V+2L14Cl5THGwEh1QnGPlGfkv8lyUlIzFQ1cNYVVHrcjZ0VCcFe9Y+Eb+izy3ceclUl43aFN52DXXssYpnY6a4qFS8ZcP2uIf+e7inRh6pdFrdTGrm8uiHx/L8T2V7NGWzvJBLJ/bl7mTuzO5qBNFDoiJID/IF/KHfCK/yDfyT3O7d/KbfNfS80hNIrU0g9L6HOq1x5iTQo6FNpeLfCQ/yVfyl3xmXYwxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHNk9z4JwJ0SqKTdQkbyEwhU393T6V7zzR6pieR3tE1ITeVXImhe6BXDGZFdRbVeank2TBhcaEMr0rwbixj49IBLL2/L/ffmMuNHfqO9tFZjJYBd1ewO3Lx+IcVfKhqna5nHZYR6XFPH+5R3eeI5t9fx/fvjeC9Jdew5OKZKqFR/RDVKL6vL/f9PJafmyvHsL+a/ff24V6NmjZQbGchVbY6UM2BluqHv1rCqzVZ1KQlkZboepCdQvacPsz5bjTfXao+yMEaDt7Wk9tSIMVGig3TejCtJSM2bSpkPjWPqd1S6Zao+lORSYWmgkOjORRNwZqd5ezMSiHLRooNr5XwWjS6/1XHX9vL2T67N7M1iyXa9JCrYjVrS1gbpJyw6hBfsmiNCYT0P9/A+Wj1/6qGr5YNYFlJBiWJogEzezLz/ZG8/9s4fgtSyuvNYbyp1IONFBtu7sHNv4/j9yAxUHWrdaWsG9+N8XHd+YxkMpSy+aySz841cC5oXbmHCnnI74yxAgZ3YbDeB4PEQCOpBpFNZWwa2ZWRcdnxLsl00crtRB0n2lLg8JNRfDKoM4NsolgBSmw/UMADba1+qpmqfyf6x1u/0a/og3I+aEunP6/i86osqmygcGarF4p54dex/Bo0LqfqOfVwIQ/HW5/RSkwV1oN2WLlHTc82TljAwM4M1O5LWwYKZTjibYXNS0N5KcjKTe10PadfLObFuJwK4ozp+UzXDBTUjL+M5ZcBnRkQV53dMIwNQTu6bSTbVEzbi5awuVByd2E/FgaN0Tc1fKOzBHHV2aAdVSdv6s5NNkp7cSH/++xAng2yyHx+CM/H21YhfdPp+0U1X0TbSZnXx8faG9Aop0MS0cToh1p+iLcpOkLj9t/JOk5eqoPHxnDsyf486an5yqCDK7XZ1O4oZ4dWyy3FSXHUAYq47uyYbMZoGmhpG3DlEFb6uNiVBhpyaHhnBO8oJmfqOROJjzIiP43hJ8UxITqqX56S2Hur2KsOnq3nrE6PPNKPRwrSKbAZrjTQNZmuE7oxYXMZmxWbw9dxWFu4W4ezVedOE6qzI7oyYkY+M7TPeWsPbk2UX1qioSN+E3OZqOR2cReKE+qQRFN0Pi7y73g/UawU1KzezJpXwLz5hczX1ueUPKYkNb6GJQZ+j7/aAfRZREsv+quGsMoamXZBW2Gt5eU0alorEzYsKmJRa/m4NdeyxlqZsCGa84DKnVorEzboC7podis69DfIJmwufHMc7famvvmxZiYsKOtKWbRm1OcW1syEBboSJFozLh/EcmtmwgIluaM14/phrLdmJixYXMTiaM24p5I91syEBTphFOR7Y2tmwgJNvUFOr+tov3UzoaAv44KYUatv62ZCoemdhtG0+hzqrZsJBR08DWLG0gxKrZu50qvpxos3U5NItW4mFPp1ot+lPlpq2lYXs9qamVBZUMiC1ox4pJYjvlfStAu6GmTLcLboMtPIV4/6im5fFfuUi9QIap2MiWP+D96R1vPmsD/fAAAAAElFTkSuQmCC";
  13391. var SPINE_LOGO_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKUAAABsCAYAAAALzHKmAAAQ7klEQVR42u3da4xdVRUA4D0zd2Y6nZY59DVtZ1puS9+lzC0YAi2UQ8AAQczFpPgA9VIeIQbirRqJ0cBUBVGjDr/QCKSNRSMmpuODxAdxqhgwxkhFjf6Sxh/+UUNVNGJCzR7uTvas7LXX2q9zzp3em6y0gTN3Zu75utZe5+yztxC9V+/Ve5X9En1Vjd7J6SFbLNF7naPw+l2jh7YHMBWssqMHtlsRdim4qsLtIawaPiHEQOLoNrA9iIkQDnRrVA1qD2LZ8ISoxYqKo13sQAtBWBayQWZUAXGRQM9JjCngDVY0UqJNDbQrMcaGmArdUKpIjbYiQLsCZCyIMQBy8QwnilR4Q5AuCpxFYvRFmBLbEiwKwpsSaWycVQGZBKMrwBjA9BhxDe57u2L2hOoKNCbOrgAZitEVYUxoKSMErQvSxYIzCkguRg5EF4AUhqUlhy/YUKSxcRaKsioYOQhD4I0yYxkR3PcJBcuFysmgsXAWBTMJyBCMIQh9kGGxXIXvexCQXbHGAMrBWTbM2CCpMSMLIxehC77lSJwXGth7M0FzoVJIXXDWQnGmhOkL0ic7YhhtWdGGkAuPAjUWGoF4faCmwBkbZmyUqUCyMqMLRA4+E6IsdTjidUHKBYrh9CnpRcH0ypKxsyOGEYNIIeTCOz91OIJ1QYoB5eAMyZo+MFNnyVTZ0YiRC9EGEMOyAgshxErHsL2XK1gOUgwohtM1a5YNM7Rsu4K0ZkcbRm4mpPBRwFZ5hg9eCqkrUB+csWGGogzNkqEgrdnRhpGLkINudaLgwvVB6oqzCjCTZElb2Y4B0gUjBtEG0ARnDRLjjoG9DwcshtQGlIPTljVjwUySLWNkyRCQVHa0ZUUTRAwgF91a33BEy0VKAcVwwqwZC2bqbOlUurllOxQkJzNyINoAYqjWhYYjWg5SCiiG05Q1U8FMjTIoS8YE6YORi1BHtJ4KIcQEEtTXUWAxpK44YVlPBdO1jCdFWTZIE8bVGEYMIRPcZGBw4HKQcoBiOE1ZMzbMgVQwU6JMAdKEEcuIJogUvg1YCCE2gsCO42DlIIVAKZwpYJaSLVNnSU6XjYHUmxhTmXaFaMO3EYkLqMC+FsLlIoVAKZzMrEnBhJeLfLNlKMrYWRIDCbOkFSSVHbHM6AKRC6/ODUewNqQ+OLlZkxpjUmV8MBbMUJSxyzY3Q1IgTRgxiBRCHdem0KDAUkBh9sRwwjEnAXMMgTnKhFlUtiwkS5rGka4g9SaGgxFmRC7AzTCEEBcyA36dDSsXqAtOLkysjGMwY5XxVChjZ0kuSCo7YlkRQsQQYtDEFsegsLoCxUp7Kpgps2UslFGzJGccSYHUmxhOZqwzEZqAbfUMCisHKIZzgsCpl3MTzMwTpi1bYp2477gyFKUxS7qWbdjY2EBS2dGE0QQRA7gNCyHEdhjE8RhUDlBT9tzgmjWZMFNlSy+Urk1OzCyJlW0XkK4YOQh1cDtcgwBrQmoDWkdgboBZE8mYsJSHlnFbJ+5bwmOPJ7lZkirbC8aRsMvmgtTHjBhGE0QbwJ2egUE1ITVlUC5OmDVdYNrKuN70xM6WoShjlW4464dbtiFIWK6x7GjESEHUUe0iYncnbMdQSE0Z1ITTNOb0hRmjjLtmS9dmJ2rp1jtuKktyyrb6YLEMCUHq2dGG0QQRQ7f72kzc+cJecerne8Wvv7JNPHPvenEkz8Sh3UtFc92QyGt9Yko/HgOLAIUZlItTz5ouMF3KuE+2jFLCQ1D6lm6fLMkBacuOJowYRBUXyfjuHjF3NhdnsfjvAfH6E9vFt9XxKgikEKgJZyyYalzOLeMu2bLbULI6bh+QGwmQ+rgRlumdGEQAao+K56bEL2woVUwOiev0r8OAUjiJrMmFCbvykGxZRAmPitK1dHM7bohyMsuyi/I8f0+e57fJYIKEZXpXo9E4mOf5XTKyLLvCBLETF8uY2SKepkC+dpX4T02Ivepr4HvZcOZ5fmee54fyPL+DmTUhzAs6n4n8bN5dr9f3YdkSg8nsxG0lPBVKVpNjG0/aGhzfLDmRZdnumZmZp8+c+cdZPV555fSr7Xb7s0jJ3i5Pcue4MxKkPPkvvXTqz/B92u32l0wYOzG1fkhcd/py8Rcbyq/vFM/KY1WA95h/3zzP71bfU6JsNpsfgj+P/FlbrdaDGExYyuXvLz8H+DudODH700ajcSM3W6Yu4alQ1spCOTd38jcKocTZbh9+9NixY99XJ8AEUkcpo9W64yH197m5k7+bnZ19QT+J09NHntQhwji/Jg58qi6++ofLxJ8gSFneVw2Ka4QQDfh1Ok4dZavVmtZ/nrm5k7/Vf55O1tRhboUw5+ZOvqyOl5+R/FyOHj32PYVU/tloNG5IXcKrhJIzngwp3fNjomazea/64BuNxts646f50lWv169utw9/DmtqdJQyZFaSJVuV6nq9fqMEof5/vV6/CYBqgJDlee+yAbF/+4i4ZWqZeNfaIfHWzn+Hx0KcEuU9+s8jv3ej0bhVlXOZydX/k0iRMeb8P0D5e6tj8zy/Xb9UJIc56h/yqVOnXul8lmuZ2bJslKmbHG7XrbpCmCXFRLvdfqQD6jTS3Jiy5I4OykM6ADV+1Eu1DmV6evopBORexzDi1L+X/HnGxsb2w3Hm9PSRJ9QxWPOTZdmlKht2hi+w6dkox5bqffI8fye3hDteGqKaHVsHXihKl0tB+h0cY+lute54AGRKDCW89LNTRynHb7ChUWVVjetOnJh9EYBUyPZeNCoOtsbFQwdXi4/esELcd+tq8cCHJ8UXp+viy9efLz7AgamjlKXc1AA1m83DoIRDlFubzeb96hhZLVTlgJ24gttutx+ONa50bHZKRenaeTs1OfpAfnr6yOOdE7EZdNwmlKocntXLNkA5JTGq47Ds+Lf94lWsyfnXleLfnIwJUN4DOnNYwuUxh2A3Ln9XULrfK8t3J27Tu3BVwiOjXJqoAy8UZej1yclGo3GTLN+gu3w+z/P3YaWbQqk3Ne12e4ZC+c8rxWsYytcPiP9RpZxCqWDKnxOiBNlyAUpOnGsoh4tA2Rm8X9xqtT6md5wyZmYe+0YRKL+1S/wYQ3n8zctBl5SBUv5djivfjMOPduIzcizeiYfr9foVvUwZG+XCuzibZKnSceZ5/v4QlKp8y7ElhnJlTeTP7BI/kllRYfzrfvHqFy4UX1vaL/aVlSmROzwbwdS29T2UcEwZF+V8ozM2lu1VY812u/15akypGh3TmFJesJbHHD167IdUxz3YJy5bNySuX1mbvy55CbMLtzU6tjGlsdFptVqfUMc0Go23F4wy1l2dSnbfvpMwVPe9WWVLDsrOJaF9MFu2Wq1PqmNkGce67xiXhTjdNwdlvV6/BgxfbPfBfVCetxi6b9/rlCup65QzM48dl2OjLMv26CibzeZ96sTIzEFdpwQXz9U1yrtVlpR/Zll2Fec65Y6l4pbbx8XHH9kknvzJlPjlHy8Tp29eKT5ou0aJoIT3w3dBlLDzVpfAJEZ1XOdaJZxnOSlvPMjPzxFljIvng914RwebsjYO7uhMyHu46sOfnf3Oz2TXDW6vvYxdFoIXz3Wc8J5zs9n8iOn2IrxTc2BM3Glqdp7dI553uaOjxrhwcob+MyuUpjs6WZZdon8OcigjPx8V+u+GTWFTSWEx3WYcdJ225jNDSE4q0GHCzlueHOyujn6bUWYgeb9ZZUaQPe+GzQ+Gc8+oOGhC+c1d4gfI16n3XDAhQ7+9qE9l01E2Go132GYKyXE1NiFDTcpoNpv3LOYJGWXNErJNW9sEp63p2RKiVPMn1bS1DgxsyhoGdGpmizj+xtXiDYnx7/vFmce3iWdW1cTVGEY4hQ2ZW0nNq8Qm/M6XbXm3S100lwGedFybuvNOibLI+ZS2ceU4eAxiEuvCkfmU8ycToDxETe6FgCBQHeqyAbFvfEhcO7BwDuXFCEbTZF840XeHK0jYcbs2OIGle0mVJ/mmnClEPQqxyTY5I8/zFhif7fSZee4bnrPOU4AssnRXHaVTCTd14dRDY3UbTIiSeFhsN/aMjgnqthFx880rxX3yATL5p3y4LPXzOaBkUyBjZMlYpbtQlIOBD475ZEusjMNSvkXe6VEoJVDkeZ2dzIfIFsRzU+JF2OyM9M9fTC/6SUYOyFQPjQ2nWiUjxnPfw5EeHqMWIqAeIFsAU847lJM2JM6xsewt1OIDLs99P7ZFHNdB/upS8XtPiD7PfLuCXJNolYyyFiNI/Zit65ItrOVafFbHcFohY7hPTN21Tjz4uc3iqfsnxKdX1MTl1OoYRFaMsToGB6Trw2JFP/OdZC2hJZ7ZkrMoAbbSGmelDJ91hFKuJeS7jlBMkJnrAqqJlgMUZS/dArPlGHNdSg5M3xXXtvquuEatvIYtDRhpxbUJuIgqsU5lGWtUploK0KuEU9mSW8YpmFQ556xNuYW7NiW13B+FkMiKHIy+C6eGgBxJvMR0oSv5hi6+z4HJyZoU0M2RVvDlrOQbcxVfX5AhZbuqy0v7ZstYMLHlAVlLTF9ALLbvu9Y5Zylpn/XOsd0ibIvxr2KCLHpp6SCUIdnSZSF+WzfOhem6GD+1KwR3Z4jNjrtDpNoZwmWd8yrupZN6Hx3fbMmFSe0Swdq2ZIPjxk1112Duo8OBGLrBkw/IoncdK2XHsdC9dHz204m50xh3tzFq1zFqtzHXrfCw7OgDsqyNnZLszVijsmXgrmNcmGtS78lIoMX2aJz03fKO2sDJddPQSCDPiQ1DfWBycY6XtXstc2PQKuxgG2McmXTPb9/9vmuJYXKyJrWjbeg+3xPM4O73nWqvbyw7xgZZSJbEUBa157cNJjdr2vb+5iA1YV3HxYscj30PDCEHIgcjtfm8K8hSsmRotkwFk5s1TTghUAopB6xrjHMBBkI0YYTZ0dZlxwLpkiWDULpmy5gwqayZgZNkA7oKQQCxctByYg0XIIEQQuRitGVHblMTA2ShKGPDpC6wu+DEgJqg2rDGDBtAF4Q6RAojp1xXGmSMbImVcR+YWNY04eQCtUG1ofUJ2/uvcETIgUhhdAE5GAlkKShjwHTNmhhODKgJqQ2sC14uOgyfD0IbRF+MlQaZAiZWyn2yJsTJATqGnHQO2Jhh+xlsACFCG0QbRtdyzQFZCZSxYPpmTS7Q5cjJHYNBYIkZpu99HoUQ/o4QIYSIZUZfjJ4ZMjZI32wZBDMU5yhy8pZTULl4XYP5fagMyEVoy4oupTpGduwnkloSlKEwY+AcQU4MhRTD6ovXBRwFzwWgCSEF0QVjJUGmgEllTS5OLlCIlIN1mS9mx/cZ5eLDALpCTI2RAhkTZQqYoTgpoCPECbaBHQ2ETL3PUl98ECAXYijG0OyYAmQoTG7W5ODkAF1CnVgm2JQx4okPA+gCMTbGskBGgRmaOblAh5GTORIrfKFx4VH4EIAxIXIxlg2SBbMvECY3e7oApbDaIgQu5/2HmeEKEINYiwSRi7EQkLFgumZOCuggctKGI4ULZN/vMeSLj0AYMytWEqMLzFg4fYDaoKaC6wvOFR4FkIPQFaILxrJAOsHsc/zlfYDWXE8qF22s8Pz5KHxcgEVALBtjJXBSSEOwFhk1Zgy4hitCT4hVw+gFs8/zwxqIBbUgyK7fcyA0PD9XX4iVxhiC0xdof6STWCsoBmKF7+cVCWFXQYyBMxRpf+STX1b0x45AhN0OMSrOGEirhrY/dfQAdjvS7oy+WCF6r1RIFxXWvlTRg1YVqFWBmxZbD99ig9pt0YPQw9rD1nstVri9V+/Ve3XrS/wfim4P5fIFxLoAAAAASUVORK5CYII=";
  13392. // spine-webgl/src/SpineCanvas.ts
  13393. var SpineCanvas = class {
  13394. /** Constructs a new spine canvas, rendering to the provided HTML canvas. */
  13395. constructor(canvas, config) {
  13396. /** Tracks the current time, delta, and other time related statistics. */
  13397. this.time = new TimeKeeper();
  13398. if (!config.pathPrefix)
  13399. config.pathPrefix = "";
  13400. if (!config.app)
  13401. config.app = {
  13402. loadAssets: () => {
  13403. },
  13404. initialize: () => {
  13405. },
  13406. update: () => {
  13407. },
  13408. render: () => {
  13409. },
  13410. error: () => {
  13411. }
  13412. };
  13413. if (config.webglConfig)
  13414. config.webglConfig = { alpha: true };
  13415. this.htmlCanvas = canvas;
  13416. this.context = new ManagedWebGLRenderingContext(canvas, config.webglConfig);
  13417. this.renderer = new SceneRenderer(canvas, this.context);
  13418. this.gl = this.context.gl;
  13419. this.assetManager = new AssetManager(this.context, config.pathPrefix);
  13420. this.input = new Input(canvas);
  13421. if (config.app.loadAssets)
  13422. config.app.loadAssets(this);
  13423. let loop = () => {
  13424. requestAnimationFrame(loop);
  13425. this.time.update();
  13426. if (config.app.update)
  13427. config.app.update(this, this.time.delta);
  13428. if (config.app.render)
  13429. config.app.render(this);
  13430. };
  13431. let waitForAssets = () => {
  13432. if (this.assetManager.isLoadingComplete()) {
  13433. if (this.assetManager.hasErrors()) {
  13434. if (config.app.error)
  13435. config.app.error(this, this.assetManager.getErrors());
  13436. } else {
  13437. if (config.app.initialize)
  13438. config.app.initialize(this);
  13439. loop();
  13440. }
  13441. return;
  13442. }
  13443. requestAnimationFrame(waitForAssets);
  13444. };
  13445. requestAnimationFrame(waitForAssets);
  13446. }
  13447. /** Clears the canvas with the given color. The color values are given in the range [0,1]. */
  13448. clear(r, g, b, a) {
  13449. this.gl.clearColor(r, g, b, a);
  13450. this.gl.clear(this.gl.COLOR_BUFFER_BIT);
  13451. }
  13452. };
  13453. // spine-phaser/src/mixins.ts
  13454. var components = Phaser.GameObjects.Components;
  13455. var ComputedSize = components.ComputedSize;
  13456. var Depth = components.Depth;
  13457. var Flip = components.Flip;
  13458. var ScrollFactor = components.ScrollFactor;
  13459. var Transform = components.Transform;
  13460. var Visible = components.Visible;
  13461. var Origin = components.Origin;
  13462. var Alpha = components.Alpha;
  13463. function createMixin(...component) {
  13464. return (BaseGameObject) => {
  13465. Phaser.Class.mixin(BaseGameObject, component);
  13466. return BaseGameObject;
  13467. };
  13468. }
  13469. var ComputedSizeMixin = createMixin(ComputedSize);
  13470. var DepthMixin = createMixin(Depth);
  13471. var FlipMixin = createMixin(Flip);
  13472. var ScrollFactorMixin = createMixin(ScrollFactor);
  13473. var TransformMixin = createMixin(Transform);
  13474. var VisibleMixin = createMixin(Visible);
  13475. var OriginMixin = createMixin(Origin);
  13476. var AlphaMixin = createMixin(Alpha);
  13477. // spine-phaser/src/SpineGameObject.ts
  13478. var BaseSpineGameObject = class extends Phaser.GameObjects.GameObject {
  13479. constructor(scene, type) {
  13480. super(scene, type);
  13481. }
  13482. };
  13483. var SetupPoseBoundsProvider = class {
  13484. calculateBounds(gameObject) {
  13485. if (!gameObject.skeleton)
  13486. return { x: 0, y: 0, width: 0, height: 0 };
  13487. const skeleton = new Skeleton(gameObject.skeleton.data);
  13488. skeleton.setToSetupPose();
  13489. skeleton.updateWorldTransform();
  13490. const bounds = skeleton.getBoundsRect();
  13491. return bounds.width == Number.NEGATIVE_INFINITY ? { x: 0, y: 0, width: 0, height: 0 } : bounds;
  13492. }
  13493. };
  13494. var SkinsAndAnimationBoundsProvider = class {
  13495. /**
  13496. * @param animation The animation to use for calculating the bounds. If null, the setup pose is used.
  13497. * @param skins The skins to use for calculating the bounds. If empty, the default skin is used.
  13498. * @param timeStep The time step to use for calculating the bounds. A smaller time step means more precision, but slower calculation.
  13499. */
  13500. constructor(animation, skins = [], timeStep = 0.05) {
  13501. this.animation = animation;
  13502. this.skins = skins;
  13503. this.timeStep = timeStep;
  13504. }
  13505. calculateBounds(gameObject) {
  13506. if (!gameObject.skeleton || !gameObject.animationState)
  13507. return { x: 0, y: 0, width: 0, height: 0 };
  13508. const animationState = new AnimationState(gameObject.animationState.data);
  13509. const skeleton = new Skeleton(gameObject.skeleton.data);
  13510. const data = skeleton.data;
  13511. if (this.skins.length > 0) {
  13512. let customSkin = new Skin("custom-skin");
  13513. for (const skinName of this.skins) {
  13514. const skin = data.findSkin(skinName);
  13515. if (skin == null)
  13516. continue;
  13517. customSkin.addSkin(skin);
  13518. }
  13519. skeleton.setSkin(customSkin);
  13520. }
  13521. skeleton.setToSetupPose();
  13522. const animation = this.animation != null ? data.findAnimation(this.animation) : null;
  13523. if (animation == null) {
  13524. skeleton.updateWorldTransform();
  13525. const bounds = skeleton.getBoundsRect();
  13526. return bounds.width == Number.NEGATIVE_INFINITY ? { x: 0, y: 0, width: 0, height: 0 } : bounds;
  13527. } else {
  13528. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  13529. animationState.clearTracks();
  13530. animationState.setAnimationWith(0, animation, false);
  13531. const steps = Math.max(animation.duration / this.timeStep, 1);
  13532. for (let i = 0; i < steps; i++) {
  13533. animationState.update(i > 0 ? this.timeStep : 0);
  13534. animationState.apply(skeleton);
  13535. skeleton.updateWorldTransform();
  13536. const bounds2 = skeleton.getBoundsRect();
  13537. minX = Math.min(minX, bounds2.x);
  13538. minY = Math.min(minY, bounds2.y);
  13539. maxX = Math.max(maxX, minX + bounds2.width);
  13540. maxY = Math.max(maxY, minY + bounds2.height);
  13541. }
  13542. const bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
  13543. return bounds.width == Number.NEGATIVE_INFINITY ? { x: 0, y: 0, width: 0, height: 0 } : bounds;
  13544. }
  13545. }
  13546. };
  13547. var SpineGameObject = class extends DepthMixin(OriginMixin(ComputedSizeMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(AlphaMixin(BaseSpineGameObject)))))))) {
  13548. constructor(scene, plugin, x, y, dataKey, atlasKey, boundsProvider = new SetupPoseBoundsProvider()) {
  13549. super(scene, SPINE_GAME_OBJECT_TYPE);
  13550. this.plugin = plugin;
  13551. this.boundsProvider = boundsProvider;
  13552. this.blendMode = -1;
  13553. this.beforeUpdateWorldTransforms = () => {
  13554. };
  13555. this.afterUpdateWorldTransforms = () => {
  13556. };
  13557. this.premultipliedAlpha = false;
  13558. this.setPosition(x, y);
  13559. this.premultipliedAlpha = this.plugin.isAtlasPremultiplied(atlasKey);
  13560. this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey);
  13561. this.animationStateData = new AnimationStateData(this.skeleton.data);
  13562. this.animationState = new AnimationState(this.animationStateData);
  13563. this.skeleton.updateWorldTransform();
  13564. this.updateSize();
  13565. }
  13566. updateSize() {
  13567. if (!this.skeleton)
  13568. return;
  13569. let bounds = this.boundsProvider.calculateBounds(this);
  13570. let self = this;
  13571. self.width = bounds.width;
  13572. self.height = bounds.height;
  13573. this.displayOriginX = -bounds.x;
  13574. this.displayOriginY = -bounds.y;
  13575. }
  13576. /** Converts a point from the skeleton coordinate system to the Phaser world coordinate system. */
  13577. skeletonToPhaserWorldCoordinates(point) {
  13578. let transform = this.getWorldTransformMatrix();
  13579. let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty;
  13580. let x = point.x;
  13581. let y = point.y;
  13582. point.x = x * a + y * c + tx;
  13583. point.y = x * b + y * d + ty;
  13584. }
  13585. /** Converts a point from the Phaser world coordinate system to the skeleton coordinate system. */
  13586. phaserWorldCoordinatesToSkeleton(point) {
  13587. let transform = this.getWorldTransformMatrix();
  13588. transform = transform.invert();
  13589. let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty;
  13590. let x = point.x;
  13591. let y = point.y;
  13592. point.x = x * a + y * c + tx;
  13593. point.y = x * b + y * d + ty;
  13594. }
  13595. /** Converts a point from the Phaser world coordinate system to the bone's local coordinate system. */
  13596. phaserWorldCoordinatesToBone(point, bone) {
  13597. this.phaserWorldCoordinatesToSkeleton(point);
  13598. if (bone.parent) {
  13599. bone.parent.worldToLocal(point);
  13600. } else {
  13601. bone.worldToLocal(point);
  13602. }
  13603. }
  13604. /**
  13605. * Updates the {@link AnimationState}, applies it to the {@link Skeleton}, then updates the world transforms of all bones.
  13606. * @param delta The time delta in milliseconds
  13607. */
  13608. updatePose(delta) {
  13609. this.animationState.update(delta / 1e3);
  13610. this.animationState.apply(this.skeleton);
  13611. this.beforeUpdateWorldTransforms(this);
  13612. this.skeleton.updateWorldTransform();
  13613. this.afterUpdateWorldTransforms(this);
  13614. }
  13615. preUpdate(time, delta) {
  13616. if (!this.skeleton || !this.animationState)
  13617. return;
  13618. this.updatePose(delta);
  13619. }
  13620. preDestroy() {
  13621. }
  13622. willRender(camera) {
  13623. if (!this.visible)
  13624. return false;
  13625. var GameObjectRenderMask = 15;
  13626. var result = !this.skeleton || !(GameObjectRenderMask !== this.renderFlags || this.cameraFilter !== 0 && this.cameraFilter & camera.id);
  13627. return result;
  13628. }
  13629. renderWebGL(renderer, src, camera, parentMatrix) {
  13630. if (!this.skeleton || !this.animationState || !this.plugin.webGLRenderer)
  13631. return;
  13632. let sceneRenderer = this.plugin.webGLRenderer;
  13633. if (renderer.newType) {
  13634. renderer.pipelines.clear();
  13635. sceneRenderer.begin();
  13636. }
  13637. camera.addToRenderList(src);
  13638. let transform = Phaser.GameObjects.GetCalcMatrix(src, camera, parentMatrix).calc;
  13639. let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty;
  13640. sceneRenderer.drawSkeleton(this.skeleton, this.premultipliedAlpha, -1, -1, (vertices, numVertices, stride) => {
  13641. for (let i = 0; i < numVertices; i += stride) {
  13642. let vx = vertices[i];
  13643. let vy = vertices[i + 1];
  13644. vertices[i] = vx * a + vy * c + tx;
  13645. vertices[i + 1] = vx * b + vy * d + ty;
  13646. }
  13647. });
  13648. if (!renderer.nextTypeMatch) {
  13649. sceneRenderer.end();
  13650. renderer.pipelines.rebind();
  13651. }
  13652. }
  13653. renderCanvas(renderer, src, camera, parentMatrix) {
  13654. if (!this.skeleton || !this.animationState || !this.plugin.canvasRenderer)
  13655. return;
  13656. let context = renderer.currentContext;
  13657. let skeletonRenderer = this.plugin.canvasRenderer;
  13658. skeletonRenderer.ctx = context;
  13659. camera.addToRenderList(src);
  13660. let transform = Phaser.GameObjects.GetCalcMatrix(src, camera, parentMatrix).calc;
  13661. let skeleton = this.skeleton;
  13662. skeleton.x = transform.tx;
  13663. skeleton.y = transform.ty;
  13664. skeleton.scaleX = transform.scaleX;
  13665. skeleton.scaleY = transform.scaleY;
  13666. let root = skeleton.getRootBone();
  13667. root.rotation = -MathUtils.radiansToDegrees * transform.rotationNormalized;
  13668. this.skeleton.updateWorldTransform();
  13669. context.save();
  13670. skeletonRenderer.draw(skeleton);
  13671. context.restore();
  13672. }
  13673. };
  13674. // spine-canvas/src/CanvasTexture.ts
  13675. var CanvasTexture = class extends Texture {
  13676. constructor(image) {
  13677. super(image);
  13678. }
  13679. setFilters(minFilter, magFilter) {
  13680. }
  13681. setWraps(uWrap, vWrap) {
  13682. }
  13683. dispose() {
  13684. }
  13685. };
  13686. // spine-canvas/src/SkeletonRenderer.ts
  13687. var worldVertices = Utils.newFloatArray(8);
  13688. var _SkeletonRenderer2 = class {
  13689. constructor(context) {
  13690. this.triangleRendering = false;
  13691. this.debugRendering = false;
  13692. this.vertices = Utils.newFloatArray(8 * 1024);
  13693. this.tempColor = new Color();
  13694. this.ctx = context;
  13695. }
  13696. draw(skeleton) {
  13697. if (this.triangleRendering)
  13698. this.drawTriangles(skeleton);
  13699. else
  13700. this.drawImages(skeleton);
  13701. }
  13702. drawImages(skeleton) {
  13703. let ctx = this.ctx;
  13704. let color = this.tempColor;
  13705. let skeletonColor = skeleton.color;
  13706. let drawOrder = skeleton.drawOrder;
  13707. if (this.debugRendering)
  13708. ctx.strokeStyle = "green";
  13709. for (let i = 0, n = drawOrder.length; i < n; i++) {
  13710. let slot = drawOrder[i];
  13711. let bone = slot.bone;
  13712. if (!bone.active)
  13713. continue;
  13714. let attachment = slot.getAttachment();
  13715. if (!(attachment instanceof RegionAttachment))
  13716. continue;
  13717. attachment.computeWorldVertices(slot, worldVertices, 0, 2);
  13718. let region = attachment.region;
  13719. let image = region.texture.getImage();
  13720. let slotColor = slot.color;
  13721. let regionColor = attachment.color;
  13722. color.set(
  13723. skeletonColor.r * slotColor.r * regionColor.r,
  13724. skeletonColor.g * slotColor.g * regionColor.g,
  13725. skeletonColor.b * slotColor.b * regionColor.b,
  13726. skeletonColor.a * slotColor.a * regionColor.a
  13727. );
  13728. ctx.save();
  13729. ctx.transform(bone.a, bone.c, bone.b, bone.d, bone.worldX, bone.worldY);
  13730. ctx.translate(attachment.offset[0], attachment.offset[1]);
  13731. ctx.rotate(attachment.rotation * Math.PI / 180);
  13732. let atlasScale = attachment.width / region.originalWidth;
  13733. ctx.scale(atlasScale * attachment.scaleX, atlasScale * attachment.scaleY);
  13734. let w = region.width, h = region.height;
  13735. ctx.translate(w / 2, h / 2);
  13736. if (attachment.region.degrees == 90) {
  13737. let t = w;
  13738. w = h;
  13739. h = t;
  13740. ctx.rotate(-Math.PI / 2);
  13741. }
  13742. ctx.scale(1, -1);
  13743. ctx.translate(-w / 2, -h / 2);
  13744. ctx.globalAlpha = color.a;
  13745. ctx.drawImage(image, image.width * region.u, image.height * region.v, w, h, 0, 0, w, h);
  13746. if (this.debugRendering)
  13747. ctx.strokeRect(0, 0, w, h);
  13748. ctx.restore();
  13749. }
  13750. }
  13751. drawTriangles(skeleton) {
  13752. let ctx = this.ctx;
  13753. let color = this.tempColor;
  13754. let skeletonColor = skeleton.color;
  13755. let drawOrder = skeleton.drawOrder;
  13756. let blendMode = null;
  13757. let vertices = this.vertices;
  13758. let triangles = null;
  13759. for (let i = 0, n = drawOrder.length; i < n; i++) {
  13760. let slot = drawOrder[i];
  13761. let attachment = slot.getAttachment();
  13762. let texture;
  13763. let region;
  13764. if (attachment instanceof RegionAttachment) {
  13765. let regionAttachment = attachment;
  13766. vertices = this.computeRegionVertices(slot, regionAttachment, false);
  13767. triangles = _SkeletonRenderer2.QUAD_TRIANGLES;
  13768. texture = regionAttachment.region.texture.getImage();
  13769. } else if (attachment instanceof MeshAttachment) {
  13770. let mesh = attachment;
  13771. vertices = this.computeMeshVertices(slot, mesh, false);
  13772. triangles = mesh.triangles;
  13773. texture = mesh.region.texture.getImage();
  13774. } else
  13775. continue;
  13776. if (texture) {
  13777. if (slot.data.blendMode != blendMode)
  13778. blendMode = slot.data.blendMode;
  13779. let slotColor = slot.color;
  13780. let attachmentColor = attachment.color;
  13781. color.set(
  13782. skeletonColor.r * slotColor.r * attachmentColor.r,
  13783. skeletonColor.g * slotColor.g * attachmentColor.g,
  13784. skeletonColor.b * slotColor.b * attachmentColor.b,
  13785. skeletonColor.a * slotColor.a * attachmentColor.a
  13786. );
  13787. ctx.globalAlpha = color.a;
  13788. for (var j = 0; j < triangles.length; j += 3) {
  13789. let t1 = triangles[j] * 8, t2 = triangles[j + 1] * 8, t3 = triangles[j + 2] * 8;
  13790. let x0 = vertices[t1], y0 = vertices[t1 + 1], u0 = vertices[t1 + 6], v0 = vertices[t1 + 7];
  13791. let x1 = vertices[t2], y1 = vertices[t2 + 1], u1 = vertices[t2 + 6], v1 = vertices[t2 + 7];
  13792. let x2 = vertices[t3], y2 = vertices[t3 + 1], u2 = vertices[t3 + 6], v2 = vertices[t3 + 7];
  13793. this.drawTriangle(texture, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
  13794. if (this.debugRendering) {
  13795. ctx.strokeStyle = "green";
  13796. ctx.beginPath();
  13797. ctx.moveTo(x0, y0);
  13798. ctx.lineTo(x1, y1);
  13799. ctx.lineTo(x2, y2);
  13800. ctx.lineTo(x0, y0);
  13801. ctx.stroke();
  13802. }
  13803. }
  13804. }
  13805. }
  13806. this.ctx.globalAlpha = 1;
  13807. }
  13808. // Adapted from http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
  13809. // Apache 2 licensed
  13810. drawTriangle(img, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2) {
  13811. let ctx = this.ctx;
  13812. u0 *= img.width;
  13813. v0 *= img.height;
  13814. u1 *= img.width;
  13815. v1 *= img.height;
  13816. u2 *= img.width;
  13817. v2 *= img.height;
  13818. ctx.beginPath();
  13819. ctx.moveTo(x0, y0);
  13820. ctx.lineTo(x1, y1);
  13821. ctx.lineTo(x2, y2);
  13822. ctx.closePath();
  13823. x1 -= x0;
  13824. y1 -= y0;
  13825. x2 -= x0;
  13826. y2 -= y0;
  13827. u1 -= u0;
  13828. v1 -= v0;
  13829. u2 -= u0;
  13830. v2 -= v0;
  13831. var det = 1 / (u1 * v2 - u2 * v1), a = (v2 * x1 - v1 * x2) * det, b = (v2 * y1 - v1 * y2) * det, c = (u1 * x2 - u2 * x1) * det, d = (u1 * y2 - u2 * y1) * det, e = x0 - a * u0 - c * v0, f = y0 - b * u0 - d * v0;
  13832. ctx.save();
  13833. ctx.transform(a, b, c, d, e, f);
  13834. ctx.clip();
  13835. ctx.drawImage(img, 0, 0);
  13836. ctx.restore();
  13837. }
  13838. computeRegionVertices(slot, region, pma) {
  13839. let skeletonColor = slot.bone.skeleton.color;
  13840. let slotColor = slot.color;
  13841. let regionColor = region.color;
  13842. let alpha = skeletonColor.a * slotColor.a * regionColor.a;
  13843. let multiplier = pma ? alpha : 1;
  13844. let color = this.tempColor;
  13845. color.set(
  13846. skeletonColor.r * slotColor.r * regionColor.r * multiplier,
  13847. skeletonColor.g * slotColor.g * regionColor.g * multiplier,
  13848. skeletonColor.b * slotColor.b * regionColor.b * multiplier,
  13849. alpha
  13850. );
  13851. region.computeWorldVertices(slot, this.vertices, 0, _SkeletonRenderer2.VERTEX_SIZE);
  13852. let vertices = this.vertices;
  13853. let uvs = region.uvs;
  13854. vertices[RegionAttachment.C1R] = color.r;
  13855. vertices[RegionAttachment.C1G] = color.g;
  13856. vertices[RegionAttachment.C1B] = color.b;
  13857. vertices[RegionAttachment.C1A] = color.a;
  13858. vertices[RegionAttachment.U1] = uvs[0];
  13859. vertices[RegionAttachment.V1] = uvs[1];
  13860. vertices[RegionAttachment.C2R] = color.r;
  13861. vertices[RegionAttachment.C2G] = color.g;
  13862. vertices[RegionAttachment.C2B] = color.b;
  13863. vertices[RegionAttachment.C2A] = color.a;
  13864. vertices[RegionAttachment.U2] = uvs[2];
  13865. vertices[RegionAttachment.V2] = uvs[3];
  13866. vertices[RegionAttachment.C3R] = color.r;
  13867. vertices[RegionAttachment.C3G] = color.g;
  13868. vertices[RegionAttachment.C3B] = color.b;
  13869. vertices[RegionAttachment.C3A] = color.a;
  13870. vertices[RegionAttachment.U3] = uvs[4];
  13871. vertices[RegionAttachment.V3] = uvs[5];
  13872. vertices[RegionAttachment.C4R] = color.r;
  13873. vertices[RegionAttachment.C4G] = color.g;
  13874. vertices[RegionAttachment.C4B] = color.b;
  13875. vertices[RegionAttachment.C4A] = color.a;
  13876. vertices[RegionAttachment.U4] = uvs[6];
  13877. vertices[RegionAttachment.V4] = uvs[7];
  13878. return vertices;
  13879. }
  13880. computeMeshVertices(slot, mesh, pma) {
  13881. let skeletonColor = slot.bone.skeleton.color;
  13882. let slotColor = slot.color;
  13883. let regionColor = mesh.color;
  13884. let alpha = skeletonColor.a * slotColor.a * regionColor.a;
  13885. let multiplier = pma ? alpha : 1;
  13886. let color = this.tempColor;
  13887. color.set(
  13888. skeletonColor.r * slotColor.r * regionColor.r * multiplier,
  13889. skeletonColor.g * slotColor.g * regionColor.g * multiplier,
  13890. skeletonColor.b * slotColor.b * regionColor.b * multiplier,
  13891. alpha
  13892. );
  13893. let vertexCount = mesh.worldVerticesLength / 2;
  13894. let vertices = this.vertices;
  13895. if (vertices.length < mesh.worldVerticesLength)
  13896. this.vertices = vertices = Utils.newFloatArray(mesh.worldVerticesLength);
  13897. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, _SkeletonRenderer2.VERTEX_SIZE);
  13898. let uvs = mesh.uvs;
  13899. for (let i = 0, u = 0, v = 2; i < vertexCount; i++) {
  13900. vertices[v++] = color.r;
  13901. vertices[v++] = color.g;
  13902. vertices[v++] = color.b;
  13903. vertices[v++] = color.a;
  13904. vertices[v++] = uvs[u++];
  13905. vertices[v++] = uvs[u++];
  13906. v += 2;
  13907. }
  13908. return vertices;
  13909. }
  13910. };
  13911. var SkeletonRenderer2 = _SkeletonRenderer2;
  13912. SkeletonRenderer2.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  13913. SkeletonRenderer2.VERTEX_SIZE = 2 + 2 + 4;
  13914. // spine-phaser/src/SpinePlugin.ts
  13915. var SpinePlugin = class extends import_phaser.default.Plugins.ScenePlugin {
  13916. constructor(scene, pluginManager, pluginKey) {
  13917. super(scene, pluginManager, pluginKey);
  13918. this.game = pluginManager.game;
  13919. this.isWebGL = this.game.config.renderType === 2;
  13920. this.gl = this.isWebGL ? this.game.renderer.gl : null;
  13921. this.webGLRenderer = null;
  13922. this.canvasRenderer = null;
  13923. this.skeletonDataCache = this.game.cache.addCustom(SPINE_SKELETON_FILE_CACHE_KEY);
  13924. this.atlasCache = this.game.cache.addCustom(SPINE_ATLAS_CACHE_KEY);
  13925. let skeletonJsonFileCallback = function(key, url, xhrSettings) {
  13926. let file = new SpineSkeletonDataFile(this, key, url, SpineSkeletonDataFileType.json, xhrSettings);
  13927. this.addFile(file.files);
  13928. return this;
  13929. };
  13930. pluginManager.registerFileType("spineJson", skeletonJsonFileCallback, scene);
  13931. let skeletonBinaryFileCallback = function(key, url, xhrSettings) {
  13932. let file = new SpineSkeletonDataFile(this, key, url, SpineSkeletonDataFileType.binary, xhrSettings);
  13933. this.addFile(file.files);
  13934. return this;
  13935. };
  13936. pluginManager.registerFileType("spineBinary", skeletonBinaryFileCallback, scene);
  13937. let atlasFileCallback = function(key, url, premultipliedAlpha, xhrSettings) {
  13938. let file = new SpineAtlasFile(this, key, url, premultipliedAlpha, xhrSettings);
  13939. this.addFile(file.files);
  13940. return this;
  13941. };
  13942. pluginManager.registerFileType("spineAtlas", atlasFileCallback, scene);
  13943. let self = this;
  13944. let addSpineGameObject = function(x, y, dataKey, atlasKey, boundsProvider) {
  13945. let gameObject = new SpineGameObject(scene, self, x, y, dataKey, atlasKey, boundsProvider);
  13946. this.displayList.add(gameObject);
  13947. this.updateList.add(gameObject);
  13948. return gameObject;
  13949. };
  13950. let makeSpineGameObject = function(config, addToScene = false) {
  13951. let x = config.x ? config.x : 0;
  13952. let y = config.y ? config.y : 0;
  13953. let boundsProvider = config.boundsProvider ? config.boundsProvider : void 0;
  13954. let gameObject = new SpineGameObject(this.scene, self, x, y, config.dataKey, config.atlasKey, boundsProvider);
  13955. if (addToScene !== void 0) {
  13956. config.add = addToScene;
  13957. }
  13958. return import_phaser.default.GameObjects.BuildGameObject(this.scene, gameObject, config);
  13959. };
  13960. pluginManager.registerGameObject(SPINE_GAME_OBJECT_TYPE, addSpineGameObject, makeSpineGameObject);
  13961. }
  13962. boot() {
  13963. Skeleton.yDown = true;
  13964. if (this.isWebGL) {
  13965. if (!this.webGLRenderer) {
  13966. this.webGLRenderer = new SceneRenderer(this.game.renderer.canvas, this.gl, true);
  13967. }
  13968. this.onResize();
  13969. this.game.scale.on(import_phaser.default.Scale.Events.RESIZE, this.onResize, this);
  13970. } else {
  13971. if (!this.canvasRenderer) {
  13972. this.canvasRenderer = new SkeletonRenderer2(this.scene.sys.context);
  13973. }
  13974. }
  13975. var eventEmitter = this.systems.events;
  13976. eventEmitter.once("shutdown", this.shutdown, this);
  13977. eventEmitter.once("destroy", this.destroy, this);
  13978. this.game.events.once("destroy", this.gameDestroy, this);
  13979. }
  13980. onResize() {
  13981. var phaserRenderer = this.game.renderer;
  13982. var sceneRenderer = this.webGLRenderer;
  13983. if (phaserRenderer && sceneRenderer) {
  13984. var viewportWidth = phaserRenderer.width;
  13985. var viewportHeight = phaserRenderer.height;
  13986. sceneRenderer.camera.position.x = viewportWidth / 2;
  13987. sceneRenderer.camera.position.y = viewportHeight / 2;
  13988. sceneRenderer.camera.up.y = -1;
  13989. sceneRenderer.camera.direction.z = 1;
  13990. sceneRenderer.camera.setViewport(viewportWidth, viewportHeight);
  13991. }
  13992. }
  13993. shutdown() {
  13994. this.systems.events.off("shutdown", this.shutdown, this);
  13995. if (this.isWebGL) {
  13996. this.game.scale.off(import_phaser.default.Scale.Events.RESIZE, this.onResize, this);
  13997. }
  13998. }
  13999. destroy() {
  14000. this.shutdown();
  14001. }
  14002. gameDestroy() {
  14003. this.pluginManager.removeGameObject(SPINE_GAME_OBJECT_TYPE, true, true);
  14004. this.pluginManager.removeGameObject(SPINE_CONTAINER_TYPE, true, true);
  14005. if (this.webGLRenderer)
  14006. this.webGLRenderer.dispose();
  14007. }
  14008. /** Returns the TextureAtlas instance for the given key */
  14009. getAtlas(atlasKey) {
  14010. let atlas;
  14011. if (this.atlasCache.exists(atlasKey)) {
  14012. atlas = this.atlasCache.get(atlasKey);
  14013. } else {
  14014. let atlasFile = this.game.cache.text.get(atlasKey);
  14015. atlas = new TextureAtlas(atlasFile.data);
  14016. if (this.isWebGL) {
  14017. let gl = this.gl;
  14018. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  14019. for (let atlasPage of atlas.pages) {
  14020. atlasPage.setTexture(new GLTexture(gl, this.game.textures.get(atlasKey + "!" + atlasPage.name).getSourceImage(), false));
  14021. }
  14022. } else {
  14023. for (let atlasPage of atlas.pages) {
  14024. atlasPage.setTexture(new CanvasTexture(this.game.textures.get(atlasKey + "!" + atlasPage.name).getSourceImage()));
  14025. }
  14026. }
  14027. this.atlasCache.add(atlasKey, atlas);
  14028. }
  14029. return atlas;
  14030. }
  14031. /** Returns whether the TextureAtlas uses premultiplied alpha */
  14032. isAtlasPremultiplied(atlasKey) {
  14033. let atlasFile = this.game.cache.text.get(atlasKey);
  14034. if (!atlasFile)
  14035. return false;
  14036. return atlasFile.premultipliedAlpha;
  14037. }
  14038. /** Returns the SkeletonData instance for the given data and atlas key */
  14039. getSkeletonData(dataKey, atlasKey) {
  14040. const atlas = this.getAtlas(atlasKey);
  14041. const combinedKey = dataKey + atlasKey;
  14042. let skeletonData;
  14043. if (this.skeletonDataCache.exists(combinedKey)) {
  14044. skeletonData = this.skeletonDataCache.get(combinedKey);
  14045. } else {
  14046. if (this.game.cache.json.exists(dataKey)) {
  14047. let jsonFile = this.game.cache.json.get(dataKey);
  14048. let json = new SkeletonJson(new AtlasAttachmentLoader(atlas));
  14049. skeletonData = json.readSkeletonData(jsonFile);
  14050. } else {
  14051. let binaryFile = this.game.cache.binary.get(dataKey);
  14052. let binary = new SkeletonBinary(new AtlasAttachmentLoader(atlas));
  14053. skeletonData = binary.readSkeletonData(new Uint8Array(binaryFile));
  14054. }
  14055. this.skeletonDataCache.add(combinedKey, skeletonData);
  14056. }
  14057. return skeletonData;
  14058. }
  14059. /** Creates a new Skeleton instance from the data and atlas. */
  14060. createSkeleton(dataKey, atlasKey) {
  14061. return new Skeleton(this.getSkeletonData(dataKey, atlasKey));
  14062. }
  14063. };
  14064. var SpineSkeletonDataFileType = /* @__PURE__ */ ((SpineSkeletonDataFileType2) => {
  14065. SpineSkeletonDataFileType2[SpineSkeletonDataFileType2["json"] = 0] = "json";
  14066. SpineSkeletonDataFileType2[SpineSkeletonDataFileType2["binary"] = 1] = "binary";
  14067. return SpineSkeletonDataFileType2;
  14068. })(SpineSkeletonDataFileType || {});
  14069. var SpineSkeletonDataFile = class extends import_phaser.default.Loader.MultiFile {
  14070. constructor(loader, key, url, fileType, xhrSettings) {
  14071. if (typeof key !== "string") {
  14072. const config = key;
  14073. key = config.key;
  14074. url = config.url;
  14075. fileType = config.type === "spineJson" ? 0 /* json */ : 1 /* binary */;
  14076. xhrSettings = config.xhrSettings;
  14077. }
  14078. let file = null;
  14079. let isJson = fileType == 0 /* json */;
  14080. if (isJson) {
  14081. file = new import_phaser.default.Loader.FileTypes.JSONFile(loader, {
  14082. key,
  14083. url,
  14084. extension: "json",
  14085. xhrSettings
  14086. });
  14087. } else {
  14088. file = new import_phaser.default.Loader.FileTypes.BinaryFile(loader, {
  14089. key,
  14090. url,
  14091. extension: "skel",
  14092. xhrSettings
  14093. });
  14094. }
  14095. super(loader, SPINE_SKELETON_DATA_FILE_TYPE, key, [file]);
  14096. this.fileType = fileType;
  14097. }
  14098. onFileComplete(file) {
  14099. this.pending--;
  14100. }
  14101. addToCache() {
  14102. if (this.isReadyToProcess())
  14103. this.files[0].addToCache();
  14104. }
  14105. };
  14106. var SpineAtlasFile = class extends import_phaser.default.Loader.MultiFile {
  14107. constructor(loader, key, url, premultipliedAlpha = true, xhrSettings) {
  14108. var _a;
  14109. if (typeof key !== "string") {
  14110. const config = key;
  14111. key = config.key;
  14112. url = config.url;
  14113. premultipliedAlpha = (_a = config.premultipliedAlpha) != null ? _a : true;
  14114. xhrSettings = config.xhrSettings;
  14115. }
  14116. super(loader, SPINE_ATLAS_FILE_TYPE, key, [
  14117. new import_phaser.default.Loader.FileTypes.TextFile(loader, {
  14118. key,
  14119. url,
  14120. xhrSettings,
  14121. extension: "atlas"
  14122. })
  14123. ]);
  14124. this.premultipliedAlpha = premultipliedAlpha;
  14125. this.premultipliedAlpha = premultipliedAlpha;
  14126. }
  14127. onFileComplete(file) {
  14128. if (this.files.indexOf(file) != -1) {
  14129. this.pending--;
  14130. if (file.type == "text") {
  14131. var lines = file.data.split(/\r\n|\r|\n/);
  14132. let textures = [];
  14133. textures.push(lines[0]);
  14134. for (var t = 1; t < lines.length; t++) {
  14135. var line = lines[t];
  14136. if (line.trim() === "" && t < lines.length - 1) {
  14137. line = lines[t + 1];
  14138. textures.push(line);
  14139. }
  14140. }
  14141. let basePath = file.src.match(/^.*\//);
  14142. for (var i = 0; i < textures.length; i++) {
  14143. var url = basePath + textures[i];
  14144. var key = file.key + "!" + textures[i];
  14145. var image = new import_phaser.default.Loader.FileTypes.ImageFile(this.loader, key, url);
  14146. if (!this.loader.keyExists(image)) {
  14147. this.addToMultiFile(image);
  14148. this.loader.addFile(image);
  14149. }
  14150. }
  14151. }
  14152. }
  14153. }
  14154. addToCache() {
  14155. if (this.isReadyToProcess()) {
  14156. let textureManager = this.loader.textureManager;
  14157. for (let file of this.files) {
  14158. if (file.type == "image") {
  14159. if (!textureManager.exists(file.key)) {
  14160. textureManager.addImage(file.key, file.data);
  14161. }
  14162. } else {
  14163. file.data = {
  14164. data: file.data,
  14165. premultipliedAlpha: this.premultipliedAlpha || file.data.indexOf("pma: true") >= 0
  14166. };
  14167. file.addToCache();
  14168. }
  14169. }
  14170. }
  14171. }
  14172. };
  14173. // spine-phaser/src/index.ts
  14174. window.spine = { SpinePlugin };
  14175. window["spine.SpinePlugin"] = SpinePlugin;
  14176. return __toCommonJS(src_exports);
  14177. })();
  14178. //# sourceMappingURL=spine-phaser.js.map