pixi-spine.js 1.1 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180
  1. /* eslint-disable */
  2. /*!
  3. * pixi-spine - v3.0.4
  4. * Compiled Sun, 04 Jul 2021 14:05:16 UTC
  5. *
  6. * pixi-spine is licensed under SPINE-LICENSE
  7. * http://esotericsoftware.com/spine-runtimes-license
  8. *
  9. * Copyright 2019-2020, Ivan Igorevich Popelyshev <ivan.popelyshev@gmail.com>, All Rights Reserved
  10. */
  11. this.PIXI = this.PIXI || {};
  12. this.PIXI.spine = this.PIXI.spine || {};
  13. (function (global, factory) {
  14. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pixi/loaders'), require('@pixi/core'), require('@pixi/constants'), require('@pixi/math'), require('@pixi/display'), require('@pixi/sprite'), require('@pixi/mesh-extras'), require('@pixi/graphics'), require('@pixi/utils')) :
  15. typeof define === 'function' && define.amd ? define(['exports', '@pixi/loaders', '@pixi/core', '@pixi/constants', '@pixi/math', '@pixi/display', '@pixi/sprite', '@pixi/mesh-extras', '@pixi/graphics', '@pixi/utils'], factory) :
  16. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pixi_spine = {}, global.PIXI, global.PIXI, global.PIXI, global.PIXI, global.PIXI, global.PIXI, global.PIXI, global.PIXI, global.PIXI.utils));
  17. }(this, (function (exports, loaders, core, constants, math, display, sprite, meshExtras, graphics, utils) { 'use strict';
  18. /* eslint-disable */
  19. /**
  20. * @public
  21. */
  22. (function (AttachmentType) {
  23. const Region = 0; AttachmentType[AttachmentType["Region"] = Region] = "Region"; const BoundingBox = Region + 1; AttachmentType[AttachmentType["BoundingBox"] = BoundingBox] = "BoundingBox"; const Mesh = BoundingBox + 1; AttachmentType[AttachmentType["Mesh"] = Mesh] = "Mesh"; const LinkedMesh = Mesh + 1; AttachmentType[AttachmentType["LinkedMesh"] = LinkedMesh] = "LinkedMesh"; const Path = LinkedMesh + 1; AttachmentType[AttachmentType["Path"] = Path] = "Path"; const Point = Path + 1; AttachmentType[AttachmentType["Point"] = Point] = "Point"; const Clipping = Point + 1; AttachmentType[AttachmentType["Clipping"] = Clipping] = "Clipping";
  24. })(exports.AttachmentType || (exports.AttachmentType = {}));
  25. /**
  26. * @public
  27. */
  28. class BinaryInput {
  29. constructor(data, strings = new Array(), index = 0, buffer = new DataView(data.buffer)) {this.strings = strings;this.index = index;this.buffer = buffer;
  30. }
  31. readByte() {
  32. return this.buffer.getInt8(this.index++);
  33. }
  34. readUnsignedByte() {
  35. return this.buffer.getUint8(this.index++);
  36. }
  37. readShort() {
  38. let value = this.buffer.getInt16(this.index);
  39. this.index += 2;
  40. return value;
  41. }
  42. readInt32() {
  43. let value = this.buffer.getInt32(this.index);
  44. this.index += 4;
  45. return value;
  46. }
  47. readInt(optimizePositive) {
  48. let b = this.readByte();
  49. let result = b & 0x7F;
  50. if ((b & 0x80) != 0) {
  51. b = this.readByte();
  52. result |= (b & 0x7F) << 7;
  53. if ((b & 0x80) != 0) {
  54. b = this.readByte();
  55. result |= (b & 0x7F) << 14;
  56. if ((b & 0x80) != 0) {
  57. b = this.readByte();
  58. result |= (b & 0x7F) << 21;
  59. if ((b & 0x80) != 0) {
  60. b = this.readByte();
  61. result |= (b & 0x7F) << 28;
  62. }
  63. }
  64. }
  65. }
  66. return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
  67. }
  68. readStringRef () {
  69. let index = this.readInt(true);
  70. return index == 0 ? null : this.strings[index - 1];
  71. }
  72. readString () {
  73. let byteCount = this.readInt(true);
  74. switch (byteCount) {
  75. case 0:
  76. return null;
  77. case 1:
  78. return "";
  79. }
  80. byteCount--;
  81. let chars = "";
  82. for (let i = 0; i < byteCount;) {
  83. let b = this.readByte();
  84. switch (b >> 4) {
  85. case 12:
  86. case 13:
  87. chars += String.fromCharCode(((b & 0x1F) << 6 | this.readByte() & 0x3F));
  88. i += 2;
  89. break;
  90. case 14:
  91. chars += String.fromCharCode(((b & 0x0F) << 12 | (this.readByte() & 0x3F) << 6 | this.readByte() & 0x3F));
  92. i += 3;
  93. break;
  94. default:
  95. chars += String.fromCharCode(b);
  96. i++;
  97. }
  98. }
  99. return chars;
  100. }
  101. readFloat () {
  102. let value = this.buffer.getFloat32(this.index);
  103. this.index += 4;
  104. return value;
  105. }
  106. readBoolean () {
  107. return this.readByte() != 0;
  108. }
  109. }
  110. /**
  111. * @public
  112. */
  113. function filterFromString (text) {
  114. switch (text.toLowerCase()) {
  115. case "nearest": return exports.TextureFilter.Nearest;
  116. case "linear": return exports.TextureFilter.Linear;
  117. case "mipmap": return exports.TextureFilter.MipMap;
  118. case "mipmapnearestnearest": return exports.TextureFilter.MipMapNearestNearest;
  119. case "mipmaplinearnearest": return exports.TextureFilter.MipMapLinearNearest;
  120. case "mipmapnearestlinear": return exports.TextureFilter.MipMapNearestLinear;
  121. case "mipmaplinearlinear": return exports.TextureFilter.MipMapLinearLinear;
  122. default: throw new Error(`Unknown texture filter ${text}`);
  123. }
  124. }
  125. /**
  126. * @public
  127. */
  128. function wrapFromString (text) {
  129. switch (text.toLowerCase()) {
  130. case "mirroredtepeat": return exports.TextureWrap.MirroredRepeat;
  131. case "clamptoedge": return exports.TextureWrap.ClampToEdge;
  132. case "repeat": return exports.TextureWrap.Repeat;
  133. default: throw new Error(`Unknown texture wrap ${text}`);
  134. }
  135. }
  136. /**
  137. * @public
  138. */
  139. (function (TextureFilter) {
  140. const Nearest = 9728; TextureFilter[TextureFilter["Nearest"] = Nearest] = "Nearest"; // WebGLRenderingContext.NEAREST
  141. const Linear = 9729; TextureFilter[TextureFilter["Linear"] = Linear] = "Linear"; // WebGLRenderingContext.LINEAR
  142. const MipMap = 9987; TextureFilter[TextureFilter["MipMap"] = MipMap] = "MipMap"; // WebGLRenderingContext.LINEAR_MIPMAP_LINEAR
  143. const MipMapNearestNearest = 9984; TextureFilter[TextureFilter["MipMapNearestNearest"] = MipMapNearestNearest] = "MipMapNearestNearest"; // WebGLRenderingContext.NEAREST_MIPMAP_NEAREST
  144. const MipMapLinearNearest = 9985; TextureFilter[TextureFilter["MipMapLinearNearest"] = MipMapLinearNearest] = "MipMapLinearNearest"; // WebGLRenderingContext.LINEAR_MIPMAP_NEAREST
  145. const MipMapNearestLinear = 9986; TextureFilter[TextureFilter["MipMapNearestLinear"] = MipMapNearestLinear] = "MipMapNearestLinear"; // WebGLRenderingContext.NEAREST_MIPMAP_LINEAR
  146. const MipMapLinearLinear = 9987; TextureFilter[TextureFilter["MipMapLinearLinear"] = MipMapLinearLinear] = "MipMapLinearLinear"; // WebGLRenderingContext.LINEAR_MIPMAP_LINEAR
  147. })(exports.TextureFilter || (exports.TextureFilter = {}));
  148. /**
  149. * @public
  150. */
  151. (function (TextureWrap) {
  152. const MirroredRepeat = 33648; TextureWrap[TextureWrap["MirroredRepeat"] = MirroredRepeat] = "MirroredRepeat"; // WebGLRenderingContext.MIRRORED_REPEAT
  153. const ClampToEdge = 33071; TextureWrap[TextureWrap["ClampToEdge"] = ClampToEdge] = "ClampToEdge"; // WebGLRenderingContext.CLAMP_TO_EDGE
  154. const Repeat = 10497; TextureWrap[TextureWrap["Repeat"] = Repeat] = "Repeat"; // WebGLRenderingContext.REPEAT
  155. })(exports.TextureWrap || (exports.TextureWrap = {}));
  156. /**
  157. * @public
  158. */
  159. class TextureRegion {constructor() { TextureRegion.prototype.__init.call(this);TextureRegion.prototype.__init2.call(this);TextureRegion.prototype.__init3.call(this); }
  160. //thats for overrides
  161. __init() {this.size = null;}
  162. __init2() {this.names = null;}
  163. __init3() {this.values = null;}
  164. get width() {
  165. const tex = this.texture;
  166. if (tex.trim) {
  167. return tex.trim.width;
  168. }
  169. return tex.orig.width;
  170. }
  171. get height() {
  172. const tex = this.texture;
  173. if (tex.trim) {
  174. return tex.trim.height;
  175. }
  176. return tex.orig.height;
  177. }
  178. get u() {
  179. return (this.texture )._uvs.x0;
  180. }
  181. get v() {
  182. return (this.texture )._uvs.y0;
  183. }
  184. get u2() {
  185. return (this.texture )._uvs.x2;
  186. }
  187. get v2() {
  188. return (this.texture )._uvs.y2;
  189. }
  190. get offsetX() {
  191. const tex = this.texture;
  192. return tex.trim ? tex.trim.x : 0;
  193. }
  194. get offsetY() {
  195. console.warn("Deprecation Warning: @Hackerham: I guess, if you are using PIXI-SPINE ATLAS region.offsetY, you want a texture, right? Use region.texture from now on.");
  196. return this.spineOffsetY;
  197. }
  198. get pixiOffsetY() {
  199. const tex = this.texture;
  200. return tex.trim ? tex.trim.y : 0;
  201. }
  202. get spineOffsetY() {
  203. let tex = this.texture;
  204. return this.originalHeight - this.height - (tex.trim ? tex.trim.y : 0);
  205. }
  206. get originalWidth() {
  207. return this.texture.orig.width;
  208. }
  209. get originalHeight() {
  210. return this.texture.orig.height;
  211. }
  212. get x() {
  213. return this.texture.frame.x;
  214. }
  215. get y() {
  216. return this.texture.frame.y;
  217. }
  218. get rotate() {
  219. return this.texture.rotate !== 0;
  220. }
  221. get degrees() {
  222. return (360 - this.texture.rotate * 45) % 360;
  223. }
  224. }
  225. class RegionFields {constructor() { RegionFields.prototype.__init.call(this);RegionFields.prototype.__init2.call(this);RegionFields.prototype.__init3.call(this);RegionFields.prototype.__init4.call(this);RegionFields.prototype.__init5.call(this);RegionFields.prototype.__init6.call(this);RegionFields.prototype.__init7.call(this);RegionFields.prototype.__init8.call(this);RegionFields.prototype.__init9.call(this);RegionFields.prototype.__init10.call(this); }
  226. __init() {this.x = 0;}
  227. __init2() {this.y = 0;}
  228. __init3() {this.width = 0;}
  229. __init4() {this.height = 0;}
  230. __init5() {this.offsetX = 0;}
  231. __init6() {this.offsetY = 0;}
  232. __init7() {this.originalWidth = 0;}
  233. __init8() {this.originalHeight = 0;}
  234. __init9() {this.rotate = 0;}
  235. __init10() {this.index = 0;}
  236. }
  237. /**
  238. * @public
  239. */
  240. class TextureAtlas {
  241. __init11() {this.pages = new Array();}
  242. __init12() {this.regions = new Array();}
  243. constructor(atlasText, textureLoader, callback) {TextureAtlas.prototype.__init11.call(this);TextureAtlas.prototype.__init12.call(this);
  244. if (atlasText) {
  245. this.addSpineAtlas(atlasText, textureLoader, callback);
  246. }
  247. }
  248. addTexture(name, texture) {
  249. let pages = this.pages;
  250. let page = null;
  251. for (let i = 0; i < pages.length; i++) {
  252. if (pages[i].baseTexture === texture.baseTexture) {
  253. page = pages[i];
  254. break;
  255. }
  256. }
  257. if (page === null) {
  258. page = new TextureAtlasPage();
  259. page.name = 'texturePage';
  260. let baseTexture = texture.baseTexture;
  261. page.width = baseTexture.realWidth;
  262. page.height = baseTexture.realHeight;
  263. page.baseTexture = baseTexture;
  264. //those fields are not relevant in Pixi
  265. page.minFilter = page.magFilter = exports.TextureFilter.Nearest;
  266. page.uWrap = exports.TextureWrap.ClampToEdge;
  267. page.vWrap = exports.TextureWrap.ClampToEdge;
  268. pages.push(page);
  269. }
  270. let region = new TextureAtlasRegion();
  271. region.name = name;
  272. region.page = page;
  273. region.texture = texture;
  274. region.index = -1;
  275. this.regions.push(region);
  276. return region;
  277. }
  278. addTextureHash(textures, stripExtension) {
  279. for (let key in textures) {
  280. if (textures.hasOwnProperty(key)) {
  281. this.addTexture(stripExtension && key.indexOf('.') !== -1 ? key.substr(0, key.lastIndexOf('.')) : key, textures[key]);
  282. }
  283. }
  284. }
  285. addSpineAtlas(atlasText, textureLoader, callback) {
  286. return this.load(atlasText, textureLoader, callback);
  287. }
  288. load(atlasText, textureLoader, callback) {
  289. if (textureLoader == null)
  290. throw new Error("textureLoader cannot be null.");
  291. let reader = new TextureAtlasReader(atlasText);
  292. let entry = new Array(4);
  293. let page = null;
  294. let pageFields = {};
  295. let region = null;
  296. pageFields["size"] = () => {
  297. page.width = parseInt(entry[1]);
  298. page.height = parseInt(entry[2]);
  299. };
  300. pageFields["format"] = () => {
  301. // page.format = Format[tuple[0]]; we don't need format in WebGL
  302. };
  303. pageFields["filter"] = () => {
  304. page.minFilter = filterFromString(entry[1]);
  305. page.magFilter = filterFromString(entry[2]);
  306. };
  307. pageFields["repeat"] = () => {
  308. if (entry[1].indexOf('x') != -1) page.uWrap = exports.TextureWrap.Repeat;
  309. if (entry[1].indexOf('y') != -1) page.vWrap = exports.TextureWrap.Repeat;
  310. };
  311. pageFields["pma"] = () => {
  312. page.pma = entry[1] == "true";
  313. };
  314. let regionFields = {};
  315. regionFields["xy"] = () => { // Deprecated, use bounds.
  316. region.x = parseInt(entry[1]);
  317. region.y = parseInt(entry[2]);
  318. };
  319. regionFields["size"] = () => { // Deprecated, use bounds.
  320. region.width = parseInt(entry[1]);
  321. region.height = parseInt(entry[2]);
  322. };
  323. regionFields["bounds"] = () => {
  324. region.x = parseInt(entry[1]);
  325. region.y = parseInt(entry[2]);
  326. region.width = parseInt(entry[3]);
  327. region.height = parseInt(entry[4]);
  328. };
  329. regionFields["offset"] = () => { // Deprecated, use offsets.
  330. region.offsetX = parseInt(entry[1]);
  331. region.offsetY = parseInt(entry[2]);
  332. };
  333. regionFields["orig"] = () => { // Deprecated, use offsets.
  334. region.originalWidth = parseInt(entry[1]);
  335. region.originalHeight = parseInt(entry[2]);
  336. };
  337. regionFields["offsets"] = () => {
  338. region.offsetX = parseInt(entry[1]);
  339. region.offsetY = parseInt(entry[2]);
  340. region.originalWidth = parseInt(entry[3]);
  341. region.originalHeight = parseInt(entry[4]);
  342. };
  343. regionFields["rotate"] = () => {
  344. let rotateValue = entry[1];
  345. let rotate = 0;
  346. if (rotateValue.toLocaleLowerCase() == "true") {
  347. rotate = 6;
  348. } else if (rotateValue.toLocaleLowerCase() == "false") {
  349. rotate = 0;
  350. } else {
  351. rotate = ((720 - parseFloat(rotateValue)) % 360) / 45;
  352. }
  353. region.rotate = rotate;
  354. };
  355. regionFields["index"] = () => {
  356. region.index = parseInt(entry[1]);
  357. };
  358. let line = reader.readLine();
  359. // Ignore empty lines before first entry.
  360. while (line != null && line.trim().length == 0)
  361. line = reader.readLine();
  362. // Header entries.
  363. while (true) {
  364. if (line == null || line.trim().length == 0) break;
  365. if (reader.readEntry(entry, line) == 0) break; // Silently ignore all header fields.
  366. line = reader.readLine();
  367. }
  368. let iterateParser = () => {
  369. while (true) {
  370. if (line == null) {
  371. return callback && callback(this);
  372. }
  373. if (line.trim().length == 0) {
  374. page = null;
  375. line = reader.readLine();
  376. } else if (page === null) {
  377. page = new TextureAtlasPage();
  378. page.name = line.trim();
  379. while (true) {
  380. if (reader.readEntry(entry, line = reader.readLine()) == 0) break;
  381. let field = pageFields[entry[0]];
  382. if (field) field();
  383. }
  384. this.pages.push(page);
  385. textureLoader(page.name, (texture) => {
  386. if (texture === null) {
  387. this.pages.splice(this.pages.indexOf(page), 1);
  388. return callback && callback(null);
  389. }
  390. page.baseTexture = texture;
  391. //TODO: set scaleMode and mipmapMode from spine
  392. if (page.pma) {
  393. texture.alphaMode = constants.ALPHA_MODES.PMA;
  394. }
  395. if (!texture.valid) {
  396. texture.setSize(page.width, page.height);
  397. }
  398. this.pages.push(page);
  399. page.setFilters();
  400. if (!page.width || !page.height) {
  401. page.width = texture.realWidth;
  402. page.height = texture.realHeight;
  403. if (!page.width || !page.height) {
  404. console.log("ERROR spine atlas page " + page.name + ": meshes wont work if you dont specify size in atlas (http://www.html5gamedevs.com/topic/18888-pixi-spines-and-meshes/?p=107121)");
  405. }
  406. }
  407. iterateParser();
  408. });
  409. this.pages.push(page);
  410. break;
  411. } else {
  412. region = new RegionFields();
  413. let atlasRegion = new TextureAtlasRegion();
  414. atlasRegion.name = line;
  415. atlasRegion.page = page;
  416. let names = null;
  417. let values = null;
  418. while (true) {
  419. let count = reader.readEntry(entry, line = reader.readLine());
  420. if (count == 0) break;
  421. let field = regionFields[entry[0]];
  422. if (field)
  423. field();
  424. else {
  425. if (names == null) {
  426. names = [];
  427. values = [];
  428. }
  429. names.push(entry[0]);
  430. let entryValues = [];
  431. for (let i = 0; i < count; i++)
  432. entryValues.push(parseInt(entry[i + 1]));
  433. values.push(entryValues);
  434. }
  435. }
  436. if (region.originalWidth == 0 && region.originalHeight == 0) {
  437. region.originalWidth = region.width;
  438. region.originalHeight = region.height;
  439. }
  440. let resolution = page.baseTexture.resolution;
  441. region.x /= resolution;
  442. region.y /= resolution;
  443. region.width /= resolution;
  444. region.height /= resolution;
  445. region.originalWidth /= resolution;
  446. region.originalHeight /= resolution;
  447. region.offsetX /= resolution;
  448. region.offsetY /= resolution;
  449. const swapWH = region.rotate % 4 !== 0;
  450. let frame = new math.Rectangle(region.x, region.y, swapWH ? region.height : region.width, swapWH ? region.width : region.height);
  451. let orig = new math.Rectangle(0, 0, region.originalWidth, region.originalHeight);
  452. let trim = new math.Rectangle(region.offsetX, region.originalHeight - region.height - region.offsetY, region.width, region.height);
  453. atlasRegion.texture = new core.Texture(atlasRegion.page.baseTexture, frame, orig, trim, region.rotate);
  454. atlasRegion.index = region.index;
  455. atlasRegion.texture.updateUvs();
  456. this.regions.push(atlasRegion);
  457. }
  458. }
  459. };
  460. iterateParser();
  461. }
  462. findRegion(name) {
  463. for (let i = 0; i < this.regions.length; i++) {
  464. if (this.regions[i].name == name) {
  465. return this.regions[i];
  466. }
  467. }
  468. return null;
  469. }
  470. dispose() {
  471. for (let i = 0; i < this.pages.length; i++) {
  472. this.pages[i].baseTexture.dispose();
  473. }
  474. }
  475. }
  476. /**
  477. * @public
  478. */
  479. class TextureAtlasReader {
  480. __init13() {this.index = 0;}
  481. constructor(text) {TextureAtlasReader.prototype.__init13.call(this);
  482. this.lines = text.split(/\r\n|\r|\n/);
  483. }
  484. readLine() {
  485. if (this.index >= this.lines.length)
  486. return null;
  487. return this.lines[this.index++];
  488. }
  489. readEntry (entry, line) {
  490. if (line == null) return 0;
  491. line = line.trim();
  492. if (line.length == 0) return 0;
  493. let colon = line.indexOf(':');
  494. if (colon == -1) return 0;
  495. entry[0] = line.substr(0, colon).trim();
  496. for (let i = 1, lastMatch = colon + 1;; i++) {
  497. let comma = line.indexOf(',', lastMatch);
  498. if (comma == -1) {
  499. entry[i] = line.substr(lastMatch).trim();
  500. return i;
  501. }
  502. entry[i] = line.substr(lastMatch, comma - lastMatch).trim();
  503. lastMatch = comma + 1;
  504. if (i == 4) return 4;
  505. }
  506. }
  507. }
  508. /**
  509. * @public
  510. */
  511. class TextureAtlasPage {constructor() { TextureAtlasPage.prototype.__init14.call(this);TextureAtlasPage.prototype.__init15.call(this);TextureAtlasPage.prototype.__init16.call(this);TextureAtlasPage.prototype.__init17.call(this); }
  512. __init14() {this.minFilter = exports.TextureFilter.Nearest;}
  513. __init15() {this.magFilter = exports.TextureFilter.Nearest;}
  514. __init16() {this.uWrap = exports.TextureWrap.ClampToEdge;}
  515. __init17() {this.vWrap = exports.TextureWrap.ClampToEdge;}
  516. setFilters() {
  517. let tex = this.baseTexture;
  518. let filter = this.minFilter;
  519. if (filter == exports.TextureFilter.Linear) {
  520. tex.scaleMode = constants.SCALE_MODES.LINEAR;
  521. } else if (this.minFilter == exports.TextureFilter.Nearest) {
  522. tex.scaleMode = constants.SCALE_MODES.NEAREST;
  523. } else {
  524. tex.mipmap = constants.MIPMAP_MODES.POW2;
  525. if (filter == exports.TextureFilter.MipMapNearestNearest) {
  526. tex.scaleMode = constants.SCALE_MODES.NEAREST;
  527. } else {
  528. tex.scaleMode = constants.SCALE_MODES.LINEAR;
  529. }
  530. }
  531. }
  532. }
  533. /**
  534. * @public
  535. */
  536. class TextureAtlasRegion extends TextureRegion {
  537. }
  538. let fround_polyfill = (function(array) {
  539. return function(x) {
  540. return array[0] = x, array[0];
  541. };
  542. })(new Float32Array(1));
  543. let fround =
  544. (Math ).fround || fround_polyfill;
  545. /**
  546. * @public
  547. */
  548. /**
  549. * @public
  550. */
  551. class IntSet {constructor() { IntSet.prototype.__init.call(this); }
  552. __init() {this.array = new Array();}
  553. add (value) {
  554. let contains = this.contains(value);
  555. this.array[value | 0] = value | 0;
  556. return !contains;
  557. }
  558. contains (value) {
  559. return this.array[value | 0] != undefined;
  560. }
  561. remove (value) {
  562. this.array[value | 0] = undefined;
  563. }
  564. clear () {
  565. this.array.length = 0;
  566. }
  567. }
  568. /**
  569. * @public
  570. */
  571. class StringSet {constructor() { StringSet.prototype.__init2.call(this);StringSet.prototype.__init3.call(this); }
  572. __init2() {this.entries = {};}
  573. __init3() {this.size = 0;}
  574. add (value) {
  575. let contains = this.entries[value];
  576. this.entries[value] = true;
  577. if (!contains) this.size++;
  578. return contains != true;
  579. }
  580. addAll (values) {
  581. let oldSize = this.size;
  582. for (var i = 0, n = values.length; i < n; i++) {
  583. this.add(values[i]);
  584. }
  585. return oldSize != this.size;
  586. }
  587. contains (value) {
  588. let contains = this.entries[value];
  589. return contains == true;
  590. }
  591. clear () {
  592. this.entries = {};
  593. this.size = 0;
  594. }
  595. }
  596. /**
  597. * @public
  598. */
  599. /**
  600. * @public
  601. */
  602. class Color {
  603. static __initStatic() {this.WHITE = new Color(1, 1, 1, 1);}
  604. static __initStatic2() {this.RED = new Color(1, 0, 0, 1);}
  605. static __initStatic3() {this.GREEN = new Color(0, 1, 0, 1);}
  606. static __initStatic4() {this.BLUE = new Color(0, 0, 1, 1);}
  607. static __initStatic5() {this.MAGENTA = new Color(1, 0, 1, 1);}
  608. constructor ( r = 0, g = 0, b = 0, a = 0) {this.r = r;this.g = g;this.b = b;this.a = a;
  609. }
  610. set (r, g, b, a) {
  611. this.r = r;
  612. this.g = g;
  613. this.b = b;
  614. this.a = a;
  615. this.clamp();
  616. return this;
  617. }
  618. setFromColor (c) {
  619. this.r = c.r;
  620. this.g = c.g;
  621. this.b = c.b;
  622. this.a = c.a;
  623. return this;
  624. }
  625. setFromString (hex) {
  626. hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
  627. this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
  628. this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
  629. this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
  630. this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
  631. return this;
  632. }
  633. add (r, g, b, a) {
  634. this.r += r;
  635. this.g += g;
  636. this.b += b;
  637. this.a += a;
  638. this.clamp();
  639. return this;
  640. }
  641. clamp () {
  642. if (this.r < 0) this.r = 0;
  643. else if (this.r > 1) this.r = 1;
  644. if (this.g < 0) this.g = 0;
  645. else if (this.g > 1) this.g = 1;
  646. if (this.b < 0) this.b = 0;
  647. else if (this.b > 1) this.b = 1;
  648. if (this.a < 0) this.a = 0;
  649. else if (this.a > 1) this.a = 1;
  650. return this;
  651. }
  652. static rgba8888ToColor(color, value) {
  653. color.r = ((value & 0xff000000) >>> 24) / 255;
  654. color.g = ((value & 0x00ff0000) >>> 16) / 255;
  655. color.b = ((value & 0x0000ff00) >>> 8) / 255;
  656. color.a = ((value & 0x000000ff)) / 255;
  657. }
  658. static rgb888ToColor (color, value) {
  659. color.r = ((value & 0x00ff0000) >>> 16) / 255;
  660. color.g = ((value & 0x0000ff00) >>> 8) / 255;
  661. color.b = ((value & 0x000000ff)) / 255;
  662. }
  663. } Color.__initStatic(); Color.__initStatic2(); Color.__initStatic3(); Color.__initStatic4(); Color.__initStatic5();
  664. /**
  665. * @public
  666. */
  667. class MathUtils {
  668. static __initStatic6() {this.PI = 3.1415927;}
  669. static __initStatic7() {this.PI2 = MathUtils.PI * 2;}
  670. static __initStatic8() {this.radiansToDegrees = 180 / MathUtils.PI;}
  671. static __initStatic9() {this.radDeg = MathUtils.radiansToDegrees;}
  672. static __initStatic10() {this.degreesToRadians = MathUtils.PI / 180;}
  673. static __initStatic11() {this.degRad = MathUtils.degreesToRadians;}
  674. static clamp (value, min, max) {
  675. if (value < min) return min;
  676. if (value > max) return max;
  677. return value;
  678. }
  679. static cosDeg (degrees) {
  680. return Math.cos(degrees * MathUtils.degRad);
  681. }
  682. static sinDeg (degrees) {
  683. return Math.sin(degrees * MathUtils.degRad);
  684. }
  685. static signum (value) {
  686. return value > 0 ? 1 : value < 0 ? -1 : 0;
  687. }
  688. static toInt (x) {
  689. return x > 0 ? Math.floor(x) : Math.ceil(x);
  690. }
  691. static cbrt (x) {
  692. let y = Math.pow(Math.abs(x), 1/3);
  693. return x < 0 ? -y : y;
  694. }
  695. static randomTriangular (min, max) {
  696. return MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
  697. }
  698. static randomTriangularWith (min, max, mode) {
  699. let u = Math.random();
  700. let d = max - min;
  701. if (u <= (mode - min) / d) return min + Math.sqrt(u * d * (mode - min));
  702. return max - Math.sqrt((1 - u) * d * (max - mode));
  703. }
  704. } MathUtils.__initStatic6(); MathUtils.__initStatic7(); MathUtils.__initStatic8(); MathUtils.__initStatic9(); MathUtils.__initStatic10(); MathUtils.__initStatic11();
  705. /**
  706. * @public
  707. */
  708. class Interpolation {
  709. apply(start, end, a) {
  710. return start + (end - start) * this.applyInternal(a);
  711. }
  712. }
  713. /**
  714. * @public
  715. */
  716. class Pow extends Interpolation {
  717. __init4() {this.power = 2;}
  718. constructor (power) {
  719. super();Pow.prototype.__init4.call(this); this.power = power;
  720. }
  721. applyInternal (a) {
  722. if (a <= 0.5) return Math.pow(a * 2, this.power) / 2;
  723. return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
  724. }
  725. }
  726. /**
  727. * @public
  728. */
  729. class PowOut extends Pow {
  730. constructor (power) {
  731. super(power);
  732. }
  733. applyInternal (a) {
  734. return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
  735. }
  736. }
  737. /**
  738. * @public
  739. */
  740. class Utils {
  741. static __initStatic12() {this.SUPPORTS_TYPED_ARRAYS = typeof(Float32Array) !== "undefined";}
  742. static arrayCopy (source, sourceStart, dest, destStart, numElements) {
  743. for (let i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  744. dest[j] = source[i];
  745. }
  746. }
  747. static arrayFill (array, fromIndex, toIndex, value) {
  748. for (let i = fromIndex; i < toIndex; i++)
  749. array[i] = value;
  750. }
  751. static setArraySize (array, size, value = 0) {
  752. let oldSize = array.length;
  753. if (oldSize == size) return array;
  754. array.length = size;
  755. if (oldSize < size) {
  756. for (let i = oldSize; i < size; i++) array[i] = value;
  757. }
  758. return array;
  759. }
  760. static ensureArrayCapacity (array, size, value = 0) {
  761. if (array.length >= size) return array;
  762. return Utils.setArraySize(array, size, value);
  763. }
  764. static newArray (size, defaultValue) {
  765. let array = new Array(size);
  766. for (let i = 0; i < size; i++) array[i] = defaultValue;
  767. return array;
  768. }
  769. static newFloatArray (size) {
  770. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  771. return new Float32Array(size)
  772. } else {
  773. let array = new Array(size);
  774. for (let i = 0; i < array.length; i++) array[i] = 0;
  775. return array;
  776. }
  777. }
  778. static newShortArray (size) {
  779. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  780. return new Int16Array(size)
  781. } else {
  782. let array = new Array(size);
  783. for (let i = 0; i < array.length; i++) array[i] = 0;
  784. return array;
  785. }
  786. }
  787. static toFloatArray (array) {
  788. return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  789. }
  790. static toSinglePrecision (value) {
  791. return Utils.SUPPORTS_TYPED_ARRAYS ? fround(value) : value;
  792. }
  793. // This function is used to fix WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  794. static webkit602BugfixHelper (alpha, blend) {
  795. }
  796. static contains (array, element, identity = true) {
  797. for (let i = 0; i < array.length; i++) {
  798. if (array[i] == element) return true;
  799. }
  800. return false;
  801. }
  802. } Utils.__initStatic12();
  803. /**
  804. * @public
  805. */
  806. class DebugUtils {
  807. static logBones(skeleton) {
  808. for (let i = 0; i < skeleton.bones.length; i++) {
  809. let bone = skeleton.bones[i];
  810. let mat = bone.matrix;
  811. console.log(bone.data.name + ", " + mat.a + ", " + mat.b + ", " + mat.c + ", " + mat.d + ", " + mat.tx + ", " + mat.ty);
  812. }
  813. }
  814. }
  815. /**
  816. * @public
  817. */
  818. class Pool {
  819. __init5() {this.items = new Array();}
  820. constructor (instantiator) {Pool.prototype.__init5.call(this);
  821. this.instantiator = instantiator;
  822. }
  823. obtain () {
  824. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  825. }
  826. free (item) {
  827. if ((item ).reset) (item ).reset();
  828. this.items.push(item);
  829. }
  830. freeAll (items) {
  831. for (let i = 0; i < items.length; i++) {
  832. this.free(items[i]);
  833. }
  834. }
  835. clear () {
  836. this.items.length = 0;
  837. }
  838. }
  839. /**
  840. * @public
  841. */
  842. class Vector2 {
  843. constructor ( x = 0, y = 0) {this.x = x;this.y = y;
  844. }
  845. set (x, y) {
  846. this.x = x;
  847. this.y = y;
  848. return this;
  849. }
  850. length () {
  851. let x = this.x;
  852. let y = this.y;
  853. return Math.sqrt(x * x + y * y);
  854. }
  855. normalize () {
  856. let len = this.length();
  857. if (len != 0) {
  858. this.x /= len;
  859. this.y /= len;
  860. }
  861. return this;
  862. }
  863. }
  864. /**
  865. * @public
  866. */
  867. class TimeKeeper {constructor() { TimeKeeper.prototype.__init6.call(this);TimeKeeper.prototype.__init7.call(this);TimeKeeper.prototype.__init8.call(this);TimeKeeper.prototype.__init9.call(this);TimeKeeper.prototype.__init10.call(this);TimeKeeper.prototype.__init11.call(this);TimeKeeper.prototype.__init12.call(this); }
  868. __init6() {this.maxDelta = 0.064;}
  869. __init7() {this.framesPerSecond = 0;}
  870. __init8() {this.delta = 0;}
  871. __init9() {this.totalTime = 0;}
  872. __init10() {this.lastTime = Date.now() / 1000;}
  873. __init11() {this.frameCount = 0;}
  874. __init12() {this.frameTime = 0;}
  875. update () {
  876. let now = Date.now() / 1000;
  877. this.delta = now - this.lastTime;
  878. this.frameTime += this.delta;
  879. this.totalTime += this.delta;
  880. if (this.delta > this.maxDelta) this.delta = this.maxDelta;
  881. this.lastTime = now;
  882. this.frameCount++;
  883. if (this.frameTime > 1) {
  884. this.framesPerSecond = this.frameCount / this.frameTime;
  885. this.frameTime = 0;
  886. this.frameCount = 0;
  887. }
  888. }
  889. }
  890. /**
  891. * @public
  892. */
  893. /**
  894. * @public
  895. */
  896. class WindowedMean {
  897. __init13() {this.addedValues = 0;}
  898. __init14() {this.lastValue = 0;}
  899. __init15() {this.mean = 0;}
  900. __init16() {this.dirty = true;}
  901. constructor (windowSize = 32) {WindowedMean.prototype.__init13.call(this);WindowedMean.prototype.__init14.call(this);WindowedMean.prototype.__init15.call(this);WindowedMean.prototype.__init16.call(this);
  902. this.values = new Array(windowSize);
  903. }
  904. hasEnoughData () {
  905. return this.addedValues >= this.values.length;
  906. }
  907. addValue (value) {
  908. if (this.addedValues < this.values.length)
  909. this.addedValues++;
  910. this.values[this.lastValue++] = value;
  911. if (this.lastValue > this.values.length - 1) this.lastValue = 0;
  912. this.dirty = true;
  913. }
  914. getMean () {
  915. if (this.hasEnoughData()) {
  916. if (this.dirty) {
  917. let mean = 0;
  918. for (let i = 0; i < this.values.length; i++) {
  919. mean += this.values[i];
  920. }
  921. this.mean = mean / this.values.length;
  922. this.dirty = false;
  923. }
  924. return this.mean;
  925. } else {
  926. return 0;
  927. }
  928. }
  929. }
  930. /**
  931. * @public
  932. */
  933. let settings = {
  934. yDown: true,
  935. /**
  936. * pixi-spine gives option to not fail at certain parsing errors
  937. * spine-ts fails here
  938. */
  939. FAIL_ON_NON_EXISTING_SKIN: false,
  940. /**
  941. * past Spine.globalAutoUpdate
  942. */
  943. GLOBAL_AUTO_UPDATE: true,
  944. /**
  945. * past Spine.globalDelayLimit
  946. */
  947. GLOBAL_DELAY_LIMIT: 0,
  948. };
  949. let tempRgb = [0, 0, 0];
  950. /**
  951. * @public
  952. */
  953. /**
  954. * @public
  955. */
  956. class SpineSprite extends sprite.Sprite {constructor(...args) { super(...args); SpineSprite.prototype.__init.call(this);SpineSprite.prototype.__init2.call(this); }
  957. __init() {this.region = null;}
  958. __init2() {this.attachment = null;}
  959. }
  960. /**
  961. * @public
  962. */
  963. class SpineMesh extends meshExtras.SimpleMesh {
  964. __init3() {this.region = null;}
  965. __init4() {this.attachment = null;}
  966. constructor(texture, vertices, uvs, indices, drawMode) {
  967. super(texture, vertices, uvs, indices, drawMode);SpineMesh.prototype.__init3.call(this);SpineMesh.prototype.__init4.call(this); }
  968. }
  969. /**
  970. * A class that enables the you to import and run your spine animations in pixi.
  971. * The Spine animation data needs to be loaded using either the Loader or a SpineLoader before it can be used by this class
  972. * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
  973. *
  974. * ```js
  975. * let spineAnimation = new spine(spineData);
  976. * ```
  977. *
  978. * @public
  979. * @class
  980. * @extends Container
  981. * @memberof spine
  982. * @param spineData {object} The spine data loaded from a spine atlas.
  983. */
  984. class SpineBase
  985. extends display.Container {
  986. constructor(spineData) {
  987. super();
  988. if (!spineData) {
  989. throw new Error('The spineData param is required.');
  990. }
  991. if ((typeof spineData) === "string") {
  992. throw new Error('spineData param cant be string. Please use spine.Spine.fromAtlas("YOUR_RESOURCE_NAME") from now on.');
  993. }
  994. /**
  995. * The spineData object
  996. *
  997. * @member {object}
  998. */
  999. this.spineData = spineData;
  1000. /**
  1001. * A spine Skeleton object
  1002. *
  1003. * @member {object}
  1004. */
  1005. this.createSkeleton(spineData);
  1006. /**
  1007. * An array of containers
  1008. *
  1009. * @member {Container[]}
  1010. */
  1011. this.slotContainers = [];
  1012. this.tempClipContainers = [];
  1013. for (let i = 0, n = this.skeleton.slots.length; i < n; i++) {
  1014. let slot = this.skeleton.slots[i];
  1015. let attachment = slot.getAttachment();
  1016. let slotContainer = this.newContainer();
  1017. this.slotContainers.push(slotContainer);
  1018. this.addChild(slotContainer);
  1019. this.tempClipContainers.push(null);
  1020. if (!attachment) {
  1021. continue;
  1022. }
  1023. if (attachment.type === exports.AttachmentType.Region) {
  1024. let spriteName = (attachment.region ).name;
  1025. let sprite = this.createSprite(slot, attachment , spriteName);
  1026. slot.currentSprite = sprite;
  1027. slot.currentSpriteName = spriteName;
  1028. slotContainer.addChild(sprite);
  1029. } else if (attachment.type === exports.AttachmentType.Mesh) {
  1030. let mesh = this.createMesh(slot, attachment);
  1031. slot.currentMesh = mesh;
  1032. slot.currentMeshId = attachment.id;
  1033. slot.currentMeshName = attachment.name;
  1034. slotContainer.addChild(mesh);
  1035. } else if (attachment.type === exports.AttachmentType.Clipping) {
  1036. this.createGraphics(slot, attachment);
  1037. slotContainer.addChild(slot.clippingContainer);
  1038. slotContainer.addChild(slot.currentGraphics);
  1039. }
  1040. }
  1041. /**
  1042. * The tint applied to all spine slots. This is a [r,g,b] value. A value of [1,1,1] will remove any tint effect.
  1043. *
  1044. * @member {number}
  1045. * @memberof spine.Spine#
  1046. */
  1047. this.tintRgb = new Float32Array([1, 1, 1]);
  1048. this.autoUpdate = true;
  1049. this.visible = true;
  1050. }
  1051. /**
  1052. * If this flag is set to true, the spine animation will be automatically updated every
  1053. * time the object id drawn. The down side of this approach is that the delta time is
  1054. * automatically calculated and you could miss out on cool effects like slow motion,
  1055. * pause, skip ahead and the sorts. Most of these effects can be achieved even with
  1056. * autoUpdate enabled but are harder to achieve.
  1057. *
  1058. * @member {boolean}
  1059. * @memberof spine.Spine#
  1060. * @default true
  1061. */
  1062. get autoUpdate() {
  1063. return this._autoUpdate;
  1064. }
  1065. set autoUpdate(value) {
  1066. if (value !== this._autoUpdate) {
  1067. this._autoUpdate = value;
  1068. this.updateTransform = value ? SpineBase.prototype.autoUpdateTransform : display.Container.prototype.updateTransform;
  1069. }
  1070. }
  1071. /**
  1072. * The tint applied to the spine object. This is a hex value. A value of 0xFFFFFF will remove any tint effect.
  1073. *
  1074. * @member {number}
  1075. * @memberof spine.Spine#
  1076. * @default 0xFFFFFF
  1077. */
  1078. get tint() {
  1079. return utils.rgb2hex(this.tintRgb );
  1080. }
  1081. set tint(value) {
  1082. this.tintRgb = utils.hex2rgb(value, this.tintRgb );
  1083. }
  1084. /**
  1085. * Limit value for the update dt with Spine.globalDelayLimit
  1086. * that can be overridden with localDelayLimit
  1087. * @return {number} - Maximum processed dt value for the update
  1088. */
  1089. get delayLimit() {
  1090. let limit = typeof this.localDelayLimit !== "undefined" ?
  1091. this.localDelayLimit : settings.GLOBAL_DELAY_LIMIT;
  1092. // If limit is 0, this means there is no limit for the delay
  1093. return limit || Number.MAX_VALUE
  1094. }
  1095. /**
  1096. * Update the spine skeleton and its animations by delta time (dt)
  1097. *
  1098. * @param dt {number} Delta time. Time by which the animation should be updated
  1099. */
  1100. update(dt) {
  1101. // Limit delta value to avoid animation jumps
  1102. let delayLimit = this.delayLimit;
  1103. if (dt > delayLimit) dt = delayLimit;
  1104. this.state.update(dt);
  1105. this.state.apply(this.skeleton);
  1106. //check we haven't been destroyed via a spine event callback in state update
  1107. if (!this.skeleton)
  1108. return;
  1109. this.skeleton.updateWorldTransform();
  1110. let slots = this.skeleton.slots;
  1111. // in case pixi has double tint
  1112. let globalClr = (this ).color;
  1113. let light = null, dark = null;
  1114. if (globalClr) {
  1115. light = globalClr.light;
  1116. dark = globalClr.dark;
  1117. } else {
  1118. light = this.tintRgb;
  1119. }
  1120. // let thack = false;
  1121. for (let i = 0, n = slots.length; i < n; i++) {
  1122. let slot = slots[i];
  1123. let attachment = slot.getAttachment();
  1124. let slotContainer = this.slotContainers[i];
  1125. if (!attachment) {
  1126. slotContainer.visible = false;
  1127. continue;
  1128. }
  1129. let spriteColor = null;
  1130. let attColor = (attachment ).color;
  1131. switch (attachment.type) {
  1132. case exports.AttachmentType.Region:
  1133. let region = (attachment ).region;
  1134. if (region) {
  1135. if (slot.currentMesh) {
  1136. slot.currentMesh.visible = false;
  1137. slot.currentMesh = null;
  1138. slot.currentMeshId = undefined;
  1139. slot.currentMeshName = undefined;
  1140. }
  1141. let ar = region ;
  1142. if (!slot.currentSpriteName || slot.currentSpriteName !== ar.name) {
  1143. let spriteName = ar.name;
  1144. if (slot.currentSprite) {
  1145. slot.currentSprite.visible = false;
  1146. }
  1147. slot.sprites = slot.sprites || {};
  1148. if (slot.sprites[spriteName] !== undefined) {
  1149. slot.sprites[spriteName].visible = true;
  1150. } else {
  1151. let sprite = this.createSprite(slot, attachment , spriteName);
  1152. slotContainer.addChild(sprite);
  1153. }
  1154. slot.currentSprite = slot.sprites[spriteName];
  1155. slot.currentSpriteName = spriteName;
  1156. // force sprite update when attachment name is same.
  1157. // issues https://github.com/pixijs/pixi-spine/issues/318
  1158. } else if (slot.currentSpriteName === ar.name && !slot.hackRegion) {
  1159. this.setSpriteRegion(attachment , slot.currentSprite, region);
  1160. }
  1161. }
  1162. let transform = slotContainer.transform;
  1163. transform.setFromMatrix(slot.bone.matrix);
  1164. if (slot.currentSprite.color) {
  1165. //YAY! double - tint!
  1166. spriteColor = slot.currentSprite.color;
  1167. } else {
  1168. tempRgb[0] = light[0] * slot.color.r * attColor.r;
  1169. tempRgb[1] = light[1] * slot.color.g * attColor.g;
  1170. tempRgb[2] = light[2] * slot.color.b * attColor.b;
  1171. slot.currentSprite.tint = utils.rgb2hex(tempRgb);
  1172. }
  1173. slot.currentSprite.blendMode = slot.blendMode;
  1174. break;
  1175. case exports.AttachmentType.Mesh:
  1176. if (slot.currentSprite) {
  1177. //TODO: refactor this thing, switch it on and off for container
  1178. slot.currentSprite.visible = false;
  1179. slot.currentSprite = null;
  1180. slot.currentSpriteName = undefined;
  1181. //TODO: refactor this shit
  1182. const transform = new math.Transform();
  1183. (transform )._parentID = -1;
  1184. (transform )._worldID = (slotContainer.transform )._worldID;
  1185. slotContainer.transform = transform;
  1186. }
  1187. const id = (attachment ).id;
  1188. if (!slot.currentMeshId || slot.currentMeshId !== id) {
  1189. let meshId = id;
  1190. if (slot.currentMesh) {
  1191. slot.currentMesh.visible = false;
  1192. }
  1193. slot.meshes = slot.meshes || {};
  1194. if (slot.meshes[meshId] !== undefined) {
  1195. slot.meshes[meshId].visible = true;
  1196. } else {
  1197. let mesh = this.createMesh(slot, attachment );
  1198. slotContainer.addChild(mesh);
  1199. }
  1200. slot.currentMesh = slot.meshes[meshId];
  1201. slot.currentMeshName = attachment.name;
  1202. slot.currentMeshId = meshId;
  1203. }
  1204. (attachment ).computeWorldVerticesOld(slot, slot.currentMesh.vertices);
  1205. if (slot.currentMesh.color) {
  1206. // pixi-heaven
  1207. spriteColor = slot.currentMesh.color;
  1208. } else {
  1209. tempRgb[0] = light[0] * slot.color.r * attColor.r;
  1210. tempRgb[1] = light[1] * slot.color.g * attColor.g;
  1211. tempRgb[2] = light[2] * slot.color.b * attColor.b;
  1212. slot.currentMesh.tint = utils.rgb2hex(tempRgb);
  1213. }
  1214. slot.currentMesh.blendMode = slot.blendMode;
  1215. break;
  1216. case exports.AttachmentType.Clipping:
  1217. if (!slot.currentGraphics) {
  1218. this.createGraphics(slot, attachment );
  1219. slotContainer.addChild(slot.clippingContainer);
  1220. slotContainer.addChild(slot.currentGraphics);
  1221. }
  1222. this.updateGraphics(slot, attachment );
  1223. slotContainer.alpha = 1.0;
  1224. slotContainer.visible = true;
  1225. continue;
  1226. default:
  1227. slotContainer.visible = false;
  1228. continue;
  1229. }
  1230. slotContainer.visible = true;
  1231. // pixi has double tint
  1232. if (spriteColor) {
  1233. let r0 = slot.color.r * attColor.r;
  1234. let g0 = slot.color.g * attColor.g;
  1235. let b0 = slot.color.b * attColor.b;
  1236. //YAY! double-tint!
  1237. spriteColor.setLight(
  1238. light[0] * r0 + dark[0] * (1.0 - r0),
  1239. light[1] * g0 + dark[1] * (1.0 - g0),
  1240. light[2] * b0 + dark[2] * (1.0 - b0),
  1241. );
  1242. if (slot.darkColor) {
  1243. r0 = slot.darkColor.r;
  1244. g0 = slot.darkColor.g;
  1245. b0 = slot.darkColor.b;
  1246. } else {
  1247. r0 = 0.0;
  1248. g0 = 0.0;
  1249. b0 = 0.0;
  1250. }
  1251. spriteColor.setDark(
  1252. light[0] * r0 + dark[0] * (1 - r0),
  1253. light[1] * g0 + dark[1] * (1 - g0),
  1254. light[2] * b0 + dark[2] * (1 - b0),
  1255. );
  1256. }
  1257. slotContainer.alpha = slot.color.a;
  1258. }
  1259. //== this is clipping implementation ===
  1260. //TODO: remove parent hacks when pixi masks allow it
  1261. let drawOrder = this.skeleton.drawOrder;
  1262. let clippingAttachment = null;
  1263. let clippingContainer = null;
  1264. for (let i = 0, n = drawOrder.length; i < n; i++) {
  1265. let slot = slots[drawOrder[i].data.index];
  1266. let slotContainer = this.slotContainers[drawOrder[i].data.index];
  1267. if (!clippingContainer) {
  1268. //Adding null check as it is possible for slotContainer.parent to be null in the event of a spine being disposed off in its loop callback
  1269. if (slotContainer.parent !== null && slotContainer.parent !== this) {
  1270. slotContainer.parent.removeChild(slotContainer);
  1271. //silend add hack
  1272. (slotContainer ).parent = this;
  1273. }
  1274. }
  1275. if (slot.currentGraphics && slot.getAttachment()) {
  1276. clippingContainer = slot.clippingContainer;
  1277. clippingAttachment = slot.getAttachment() ;
  1278. clippingContainer.children.length = 0;
  1279. this.children[i] = slotContainer;
  1280. if (clippingAttachment.endSlot === slot.data) {
  1281. clippingAttachment.endSlot = null;
  1282. }
  1283. } else {
  1284. if (clippingContainer) {
  1285. let c = this.tempClipContainers[i];
  1286. if (!c) {
  1287. c = this.tempClipContainers[i] = this.newContainer();
  1288. c.visible = false;
  1289. }
  1290. this.children[i] = c;
  1291. //silent remove hack
  1292. (slotContainer ).parent = null;
  1293. clippingContainer.addChild(slotContainer);
  1294. if (clippingAttachment.endSlot == slot.data) {
  1295. clippingContainer.renderable = true;
  1296. clippingContainer = null;
  1297. clippingAttachment = null;
  1298. }
  1299. } else {
  1300. this.children[i] = slotContainer;
  1301. }
  1302. }
  1303. }
  1304. };
  1305. setSpriteRegion(attachment, sprite, region) {
  1306. // prevent setters calling when attachment and region is same
  1307. if (sprite.attachment === attachment && sprite.region === region) {
  1308. return;
  1309. }
  1310. sprite.region = region;
  1311. sprite.attachment = attachment;
  1312. sprite.texture = region.texture;
  1313. sprite.rotation = attachment.rotation * MathUtils.degRad;
  1314. sprite.position.x = attachment.x;
  1315. sprite.position.y = attachment.y;
  1316. sprite.alpha = attachment.color.a;
  1317. if (!region.size) {
  1318. sprite.scale.x = attachment.scaleX * attachment.width / region.originalWidth;
  1319. sprite.scale.y = -attachment.scaleY * attachment.height / region.originalHeight;
  1320. } else {
  1321. //hacked!
  1322. sprite.scale.x = region.size.width / region.originalWidth;
  1323. sprite.scale.y = -region.size.height / region.originalHeight;
  1324. }
  1325. }
  1326. setMeshRegion(attachment, mesh, region) {
  1327. if (mesh.attachment === attachment && mesh.region === region) {
  1328. return;
  1329. }
  1330. mesh.region = region;
  1331. mesh.attachment = attachment;
  1332. mesh.texture = region.texture;
  1333. region.texture.updateUvs();
  1334. mesh.uvBuffer.update(attachment.regionUVs);
  1335. }
  1336. /**
  1337. * When autoupdate is set to yes this function is used as pixi's updateTransform function
  1338. *
  1339. * @private
  1340. */
  1341. autoUpdateTransform() {
  1342. if (settings.GLOBAL_AUTO_UPDATE) {
  1343. this.lastTime = this.lastTime || Date.now();
  1344. let timeDelta = (Date.now() - this.lastTime) * 0.001;
  1345. this.lastTime = Date.now();
  1346. this.update(timeDelta);
  1347. } else {
  1348. this.lastTime = 0;
  1349. }
  1350. display.Container.prototype.updateTransform.call(this);
  1351. };
  1352. /**
  1353. * Create a new sprite to be used with core.RegionAttachment
  1354. *
  1355. * @param slot {spine.Slot} The slot to which the attachment is parented
  1356. * @param attachment {spine.RegionAttachment} The attachment that the sprite will represent
  1357. * @private
  1358. */
  1359. createSprite(slot, attachment, defName) {
  1360. let region = attachment.region;
  1361. if (slot.hackAttachment === attachment) {
  1362. region = slot.hackRegion;
  1363. }
  1364. let texture = region.texture;
  1365. let sprite = this.newSprite(texture);
  1366. sprite.anchor.set(0.5);
  1367. this.setSpriteRegion(attachment, sprite, attachment.region);
  1368. slot.sprites = slot.sprites || {};
  1369. slot.sprites[defName] = sprite;
  1370. return sprite;
  1371. };
  1372. /**
  1373. * Creates a Strip from the spine data
  1374. * @param slot {spine.Slot} The slot to which the attachment is parented
  1375. * @param attachment {spine.RegionAttachment} The attachment that the sprite will represent
  1376. * @private
  1377. */
  1378. createMesh(slot, attachment) {
  1379. let region = attachment.region;
  1380. if (slot.hackAttachment === attachment) {
  1381. region = slot.hackRegion;
  1382. slot.hackAttachment = null;
  1383. slot.hackRegion = null;
  1384. }
  1385. let strip = this.newMesh(
  1386. region.texture,
  1387. new Float32Array(attachment.regionUVs.length),
  1388. attachment.regionUVs,
  1389. new Uint16Array(attachment.triangles),
  1390. constants.DRAW_MODES.TRIANGLES);
  1391. if (typeof (strip )._canvasPadding !== "undefined") {
  1392. (strip )._canvasPadding = 1.5;
  1393. }
  1394. strip.alpha = attachment.color.a;
  1395. strip.region = attachment.region;
  1396. this.setMeshRegion(attachment, strip, region);
  1397. slot.meshes = slot.meshes || {};
  1398. slot.meshes[attachment.id] = strip;
  1399. return strip;
  1400. };
  1401. static __initStatic() {this.clippingPolygon = [];}
  1402. //@ts-ignore
  1403. createGraphics(slot, clip) {
  1404. let graphics = this.newGraphics();
  1405. let poly = new math.Polygon([]);
  1406. graphics.clear();
  1407. graphics.beginFill(0xffffff, 1);
  1408. graphics.drawPolygon(poly );
  1409. graphics.renderable = false;
  1410. slot.currentGraphics = graphics;
  1411. slot.clippingContainer = this.newContainer();
  1412. slot.clippingContainer.mask = slot.currentGraphics;
  1413. return graphics;
  1414. }
  1415. updateGraphics(slot, clip) {
  1416. let geom = slot.currentGraphics.geometry;
  1417. let vertices = (geom.graphicsData[0].shape ).points;
  1418. let n = clip.worldVerticesLength;
  1419. vertices.length = n;
  1420. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  1421. geom.invalidate();
  1422. }
  1423. /**
  1424. * Changes texture in attachment in specific slot.
  1425. *
  1426. * PIXI runtime feature, it was made to satisfy our users.
  1427. *
  1428. * @param slotIndex {number}
  1429. * @param [texture = null] {PIXI.Texture} If null, take default (original) texture
  1430. * @param [size = null] {PIXI.Point} sometimes we need new size for region attachment, you can pass 'texture.orig' there
  1431. * @returns {boolean} Success flag
  1432. */
  1433. hackTextureBySlotIndex(slotIndex, texture = null, size = null) {
  1434. let slot = this.skeleton.slots[slotIndex];
  1435. if (!slot) {
  1436. return false;
  1437. }
  1438. let attachment = slot.getAttachment();
  1439. let region = attachment.region;
  1440. if (texture) {
  1441. region = new TextureRegion();
  1442. region.texture = texture;
  1443. region.size = size;
  1444. slot.hackRegion = region;
  1445. slot.hackAttachment = attachment;
  1446. } else {
  1447. slot.hackRegion = null;
  1448. slot.hackAttachment = null;
  1449. }
  1450. if (slot.currentSprite && slot.currentSprite.region != region) {
  1451. this.setSpriteRegion(attachment, slot.currentSprite, region);
  1452. slot.currentSprite.region = region;
  1453. } else if (slot.currentMesh && slot.currentMesh.region != region) {
  1454. this.setMeshRegion(attachment, slot.currentMesh, region);
  1455. }
  1456. return true;
  1457. }
  1458. /**
  1459. * Changes texture in attachment in specific slot.
  1460. *
  1461. * PIXI runtime feature, it was made to satisfy our users.
  1462. *
  1463. * @param slotName {string}
  1464. * @param [texture = null] {PIXI.Texture} If null, take default (original) texture
  1465. * @param [size = null] {PIXI.Point} sometimes we need new size for region attachment, you can pass 'texture.orig' there
  1466. * @returns {boolean} Success flag
  1467. */
  1468. hackTextureBySlotName(slotName, texture = null, size = null) {
  1469. let index = this.skeleton.findSlotIndex(slotName);
  1470. if (index == -1) {
  1471. return false;
  1472. }
  1473. return this.hackTextureBySlotIndex(index, texture, size);
  1474. }
  1475. /**
  1476. * Changes texture of an attachment
  1477. *
  1478. * PIXI runtime feature, it was made to satisfy our users.
  1479. *
  1480. * @param slotName {string}
  1481. * @param attachmentName {string}
  1482. * @param [texture = null] {PIXI.Texture} If null, take default (original) texture
  1483. * @param [size = null] {PIXI.Point} sometimes we need new size for region attachment, you can pass 'texture.orig' there
  1484. * @returns {boolean} Success flag
  1485. */
  1486. hackTextureAttachment(slotName, attachmentName, texture, size = null) {
  1487. // changes the texture of an attachment at the skeleton level
  1488. const slotIndex = this.skeleton.findSlotIndex(slotName);
  1489. const attachment = this.skeleton.getAttachmentByName(slotName, attachmentName);
  1490. attachment.region.texture = texture;
  1491. const slot = this.skeleton.slots[slotIndex];
  1492. if (!slot) {
  1493. return false
  1494. }
  1495. // gets the currently active attachment in this slot
  1496. const currentAttachment = slot.getAttachment();
  1497. if (attachmentName === currentAttachment.name) {
  1498. // if the attachment we are changing is currently active, change the the live texture
  1499. let region = attachment.region;
  1500. if (texture) {
  1501. region = new TextureRegion();
  1502. region.texture = texture;
  1503. region.size = size;
  1504. slot.hackRegion = region;
  1505. slot.hackAttachment = currentAttachment;
  1506. } else {
  1507. slot.hackRegion = null;
  1508. slot.hackAttachment = null;
  1509. }
  1510. if (slot.currentSprite && slot.currentSprite.region != region) {
  1511. this.setSpriteRegion(currentAttachment, slot.currentSprite, region);
  1512. slot.currentSprite.region = region;
  1513. } else if (slot.currentMesh && slot.currentMesh.region != region) {
  1514. this.setMeshRegion(currentAttachment, slot.currentMesh, region);
  1515. }
  1516. return true
  1517. }
  1518. return false
  1519. }
  1520. //those methods can be overriden to spawn different classes
  1521. newContainer() {
  1522. return new display.Container();
  1523. }
  1524. newSprite(tex) {
  1525. return new SpineSprite(tex);
  1526. }
  1527. newGraphics() {
  1528. return new graphics.Graphics();
  1529. }
  1530. newMesh(texture, vertices, uvs, indices, drawMode) {
  1531. return new SpineMesh(texture, vertices, uvs, indices, drawMode);
  1532. }
  1533. transformHack() {
  1534. return 1;
  1535. }
  1536. /**
  1537. * Hack for pixi-display and pixi-lights. Every attachment name ending with a suffix will be added to different layer
  1538. * @param nameSuffix
  1539. * @param group
  1540. * @param outGroup
  1541. */
  1542. hackAttachmentGroups(nameSuffix, group, outGroup) {
  1543. if (!nameSuffix) {
  1544. return undefined;
  1545. }
  1546. const list_d = [], list_n = [];
  1547. for (let i = 0, len = this.skeleton.slots.length; i < len; i++) {
  1548. const slot = this.skeleton.slots[i];
  1549. const name = slot.currentSpriteName || slot.currentMeshName || "";
  1550. const target = slot.currentSprite || slot.currentMesh;
  1551. if (name.endsWith(nameSuffix)) {
  1552. target.parentGroup = group;
  1553. list_n.push(target);
  1554. } else if (outGroup && target) {
  1555. target.parentGroup = outGroup;
  1556. list_d.push(target);
  1557. }
  1558. }
  1559. return [list_d, list_n];
  1560. };
  1561. destroy(options) {
  1562. for (let i = 0, n = this.skeleton.slots.length; i < n; i++) {
  1563. let slot = this.skeleton.slots[i];
  1564. for (let name in slot.meshes) {
  1565. slot.meshes[name].destroy(options);
  1566. }
  1567. slot.meshes = null;
  1568. for (let name in slot.sprites) {
  1569. slot.sprites[name].destroy(options);
  1570. }
  1571. slot.sprites = null;
  1572. }
  1573. for (let i = 0, n = this.slotContainers.length; i < n; i++) {
  1574. this.slotContainers[i].destroy(options);
  1575. }
  1576. this.spineData = null;
  1577. this.skeleton = null;
  1578. this.slotContainers = null;
  1579. this.stateData = null;
  1580. this.state = null;
  1581. this.tempClipContainers = null;
  1582. super.destroy(options);
  1583. }
  1584. } SpineBase.__initStatic();
  1585. /**
  1586. * The visibility of the spine object. If false the object will not be drawn,
  1587. * the updateTransform function will not be called, and the spine will not be automatically updated.
  1588. *
  1589. * @member {boolean}
  1590. * @memberof spine.Spine#
  1591. * @default true
  1592. */
  1593. Object.defineProperty(SpineBase.prototype, 'visible', {
  1594. get: function () {
  1595. return this._visible;
  1596. },
  1597. set: function (value) {
  1598. if (value !== this._visible) {
  1599. this._visible = value;
  1600. if (value) {
  1601. this.lastTime = 0;
  1602. }
  1603. }
  1604. }
  1605. });
  1606. /* eslint-disable */
  1607. function isJson(resource) {
  1608. return resource.type === loaders.LoaderResource.TYPE.JSON;
  1609. }
  1610. function isBuffer(resource) {
  1611. return resource.xhrType === (loaders.LoaderResource ).XHR_RESPONSE_TYPE.BUFFER;
  1612. }
  1613. loaders.LoaderResource.setExtensionXhrType('skel', loaders.LoaderResource.XHR_RESPONSE_TYPE.BUFFER);
  1614. /**
  1615. * @public
  1616. */
  1617. class AbstractSpineParser {
  1618. genMiddleware() {
  1619. const self = this;
  1620. return {
  1621. use( resource, next) {
  1622. // skip if no data, its not json, or it isn't atlas data
  1623. if (!resource.data) {
  1624. return next();
  1625. }
  1626. const isJsonSpineModel = isJson(resource) && resource.data.bones;
  1627. const isBinarySpineModel = isBuffer(resource) && (resource.extension === 'skel' || resource.metadata
  1628. && (resource.metadata ).spineMetadata);
  1629. if (!isJsonSpineModel && !isBinarySpineModel) {
  1630. return next();
  1631. }
  1632. let parser = null;
  1633. let dataToParse = resource.data;
  1634. if (isJsonSpineModel) {
  1635. parser = self.createJsonParser();
  1636. } else {
  1637. parser = self.createBinaryParser();
  1638. if (resource.data instanceof ArrayBuffer) {
  1639. dataToParse = new Uint8Array(resource.data);
  1640. }
  1641. }
  1642. const metadata = (resource.metadata || {}) ;
  1643. const metadataSkeletonScale = metadata ? (metadata ).spineSkeletonScale : null;
  1644. if (metadataSkeletonScale) {
  1645. parser.scale = metadataSkeletonScale;
  1646. }
  1647. const metadataAtlas = metadata.spineAtlas;
  1648. if (metadataAtlas === false) {
  1649. return next();
  1650. }
  1651. if (metadataAtlas && metadataAtlas.pages) {
  1652. self.parseData(resource, parser, metadataAtlas, dataToParse);
  1653. return next();
  1654. }
  1655. const metadataAtlasSuffix = metadata.spineAtlasSuffix || '.atlas';
  1656. /**
  1657. * use a bit of hackery to load the atlas file, here we assume that the .json, .atlas and .png files
  1658. * that correspond to the spine file are in the same base URL and that the .json and .atlas files
  1659. * have the same name
  1660. */
  1661. let atlasPath = resource.url;
  1662. let queryStringPos = atlasPath.indexOf('?');
  1663. if (queryStringPos > 0) {
  1664. //remove querystring
  1665. atlasPath = atlasPath.substr(0, queryStringPos);
  1666. }
  1667. atlasPath = atlasPath.substr(0, atlasPath.lastIndexOf('.')) + metadataAtlasSuffix;
  1668. // use atlas path as a params. (no need to use same atlas file name with json file name)
  1669. if (metadata.spineAtlasFile) {
  1670. atlasPath = metadata.spineAtlasFile;
  1671. }
  1672. //remove the baseUrl
  1673. atlasPath = atlasPath.replace(this.baseUrl, '');
  1674. const atlasOptions = {
  1675. crossOrigin: resource.crossOrigin,
  1676. xhrType: loaders.LoaderResource.XHR_RESPONSE_TYPE.TEXT,
  1677. metadata: metadata.spineMetadata || null,
  1678. parentResource: resource
  1679. };
  1680. const imageOptions = {
  1681. crossOrigin: resource.crossOrigin,
  1682. metadata: metadata.imageMetadata || null,
  1683. parentResource: resource
  1684. };
  1685. let baseUrl = resource.url.substr(0, resource.url.lastIndexOf('/') + 1);
  1686. //remove the baseUrl
  1687. baseUrl = baseUrl.replace(this.baseUrl, '');
  1688. const namePrefix = metadata.imageNamePrefix || (resource.name + '_atlas_page_');
  1689. const adapter = metadata.images ? staticImageLoader(metadata.images)
  1690. : metadata.image ? staticImageLoader({'default': metadata.image})
  1691. : metadata.imageLoader ? metadata.imageLoader(this, namePrefix, baseUrl, imageOptions)
  1692. : imageLoaderAdapter(this, namePrefix, baseUrl, imageOptions);
  1693. function createSkeletonWithRawAtlas(rawData) {
  1694. new TextureAtlas(rawData, adapter, function(spineAtlas) {
  1695. if (spineAtlas) {
  1696. self.parseData(resource, parser, spineAtlas, dataToParse);
  1697. }
  1698. next();
  1699. });
  1700. }
  1701. if (metadata.atlasRawData) {
  1702. createSkeletonWithRawAtlas(metadata.atlasRawData);
  1703. } else {
  1704. this.add(resource.name + '_atlas', atlasPath, atlasOptions, function (atlasResource) {
  1705. if (!atlasResource.error) {
  1706. createSkeletonWithRawAtlas(atlasResource.data);
  1707. } else {
  1708. next();
  1709. }
  1710. });
  1711. }
  1712. }
  1713. }
  1714. }
  1715. }
  1716. /**
  1717. * @public
  1718. */
  1719. function imageLoaderAdapter(loader, namePrefix, baseUrl, imageOptions) {
  1720. if (baseUrl && baseUrl.lastIndexOf('/') !== (baseUrl.length - 1)) {
  1721. baseUrl += '/';
  1722. }
  1723. return function (line, callback) {
  1724. const name = namePrefix + line;
  1725. const url = baseUrl + line;
  1726. const cachedResource = loader.resources[name];
  1727. if (cachedResource) {
  1728. const done = () => {
  1729. callback(cachedResource.texture.baseTexture);
  1730. };
  1731. if (cachedResource.texture) {
  1732. done();
  1733. } else {
  1734. cachedResource.onAfterMiddleware.add(done);
  1735. }
  1736. } else {
  1737. loader.add(name, url, imageOptions, (resource) => {
  1738. if (!resource.error) {
  1739. if (line.indexOf('-pma.') >= 0) {
  1740. resource.texture.baseTexture.alphaMode = constants.ALPHA_MODES.PMA;
  1741. }
  1742. callback(resource.texture.baseTexture);
  1743. } else {
  1744. callback(null);
  1745. }
  1746. });
  1747. }
  1748. }
  1749. }
  1750. /**
  1751. * @public
  1752. */
  1753. function syncImageLoaderAdapter(baseUrl, crossOrigin) {
  1754. if (baseUrl && baseUrl.lastIndexOf('/') !== (baseUrl.length - 1)) {
  1755. baseUrl += '/';
  1756. }
  1757. return function (line, callback) {
  1758. callback(core.BaseTexture.from(line, crossOrigin));
  1759. }
  1760. }
  1761. /**
  1762. * @public
  1763. */
  1764. function staticImageLoader(pages) {
  1765. return function (line, callback) {
  1766. let page = pages[line] || pages['default'] ;
  1767. if (page && page.baseTexture)
  1768. callback(page.baseTexture);
  1769. else
  1770. callback(page);
  1771. }
  1772. }
  1773. /* eslint-disable */
  1774. /**
  1775. * @public
  1776. */
  1777. class Attachment {
  1778. constructor(name) {
  1779. if (name == null) throw new Error("name cannot be null.");
  1780. this.name = name;
  1781. }
  1782. }
  1783. /**
  1784. * @public
  1785. */
  1786. class VertexAttachment extends Attachment {
  1787. static __initStatic() {this.nextID = 0;}
  1788. __init() {this.id = (VertexAttachment.nextID++ & 65535) << 11;}
  1789. __init2() {this.worldVerticesLength = 0;}
  1790. __init3() {this.deformAttachment = this;}
  1791. constructor(name) {
  1792. super(name);VertexAttachment.prototype.__init.call(this);VertexAttachment.prototype.__init2.call(this);VertexAttachment.prototype.__init3.call(this); }
  1793. computeWorldVerticesOld(slot, worldVertices) {
  1794. this.computeWorldVertices(slot, 0, this.worldVerticesLength, worldVertices, 0, 2);
  1795. }
  1796. /** Transforms local vertices to world coordinates.
  1797. * @param start The index of the first local vertex value to transform. Each vertex has 2 values, x and y.
  1798. * @param count The number of world vertex values to output. Must be <= {@link #getWorldVerticesLength()} - start.
  1799. * @param worldVertices The output world vertices. Must have a length >= offset + count.
  1800. * @param offset The worldVertices index to begin writing values. */
  1801. computeWorldVertices (slot, start, count, worldVertices, offset, stride) {
  1802. count = offset + (count >> 1) * stride;
  1803. let skeleton = slot.bone.skeleton;
  1804. let deformArray = slot.deform;
  1805. let vertices = this.vertices;
  1806. let bones = this.bones;
  1807. if (bones == null) {
  1808. if (deformArray.length > 0) vertices = deformArray;
  1809. let mat = slot.bone.matrix;
  1810. let x = mat.tx;
  1811. let y = mat.ty;
  1812. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  1813. for (let v = start, w = offset; w < count; v += 2, w += stride) {
  1814. let vx = vertices[v], vy = vertices[v + 1];
  1815. worldVertices[w] = vx * a + vy * b + x;
  1816. worldVertices[w + 1] = vx * c + vy * d + y;
  1817. }
  1818. return;
  1819. }
  1820. let v = 0, skip = 0;
  1821. for (let i = 0; i < start; i += 2) {
  1822. let n = bones[v];
  1823. v += n + 1;
  1824. skip += n;
  1825. }
  1826. let skeletonBones = skeleton.bones;
  1827. if (deformArray.length == 0) {
  1828. for (let w = offset, b = skip * 3; w < count; w += stride) {
  1829. let wx = 0, wy = 0;
  1830. let n = bones[v++];
  1831. n += v;
  1832. for (; v < n; v++, b += 3) {
  1833. let mat = skeletonBones[bones[v]].matrix;
  1834. let vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  1835. wx += (vx * mat.a + vy * mat.c + mat.tx) * weight;
  1836. wy += (vx * mat.b + vy * mat.d + mat.ty) * weight;
  1837. }
  1838. worldVertices[w] = wx;
  1839. worldVertices[w + 1] = wy;
  1840. }
  1841. } else {
  1842. let deform = deformArray;
  1843. for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  1844. let wx = 0, wy = 0;
  1845. let n = bones[v++];
  1846. n += v;
  1847. for (; v < n; v++, b += 3, f += 2) {
  1848. let mat = skeletonBones[bones[v]].matrix;
  1849. let vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  1850. wx += (vx * mat.a + vy * mat.c + mat.tx) * weight;
  1851. wy += (vx * mat.b + vy * mat.d + mat.ty) * weight;
  1852. }
  1853. worldVertices[w] = wx;
  1854. worldVertices[w + 1] = wy;
  1855. }
  1856. }
  1857. }
  1858. copyTo (attachment) {
  1859. if (this.bones != null) {
  1860. attachment.bones = new Array(this.bones.length);
  1861. Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
  1862. } else
  1863. attachment.bones = null;
  1864. if (this.vertices != null) {
  1865. attachment.vertices = Utils.newFloatArray(this.vertices.length);
  1866. Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
  1867. } else
  1868. attachment.vertices = null;
  1869. attachment.worldVerticesLength = this.worldVerticesLength;
  1870. attachment.deformAttachment = this.deformAttachment;
  1871. }
  1872. } VertexAttachment.__initStatic();
  1873. /**
  1874. * @public
  1875. */
  1876. class BoundingBoxAttachment extends VertexAttachment {
  1877. __init() {this.type = exports.AttachmentType.BoundingBox;}
  1878. __init2() {this.color = new Color(1, 1, 1, 1);}
  1879. constructor (name) {
  1880. super(name);BoundingBoxAttachment.prototype.__init.call(this);BoundingBoxAttachment.prototype.__init2.call(this); }
  1881. copy () {
  1882. let copy = new BoundingBoxAttachment(this.name);
  1883. this.copyTo(copy);
  1884. copy.color.setFromColor(this.color);
  1885. return copy;
  1886. }
  1887. }
  1888. /**
  1889. * @public
  1890. */
  1891. class ClippingAttachment extends VertexAttachment {
  1892. __init() {this.type = exports.AttachmentType.Clipping;}
  1893. // Nonessential.
  1894. __init2() {this.color = new Color(0.2275, 0.2275, 0.8078, 1);} // ce3a3aff
  1895. constructor (name) {
  1896. super(name);ClippingAttachment.prototype.__init.call(this);ClippingAttachment.prototype.__init2.call(this); }
  1897. copy () {
  1898. let copy = new ClippingAttachment(this.name);
  1899. this.copyTo(copy);
  1900. copy.endSlot = this.endSlot;
  1901. copy.color.setFromColor(this.color);
  1902. return copy;
  1903. }
  1904. }
  1905. /**
  1906. * @public
  1907. */
  1908. class MeshAttachment extends VertexAttachment {
  1909. __init() {this.type = exports.AttachmentType.Mesh;}
  1910. __init2() {this.color = new Color(1, 1, 1, 1);}
  1911. __init3() {this.tempColor = new Color(0, 0, 0, 0);}
  1912. constructor (name) {
  1913. super(name);MeshAttachment.prototype.__init.call(this);MeshAttachment.prototype.__init2.call(this);MeshAttachment.prototype.__init3.call(this); }
  1914. getParentMesh () {
  1915. return this.parentMesh;
  1916. }
  1917. /** @param parentMesh May be null. */
  1918. setParentMesh (parentMesh) {
  1919. this.parentMesh = parentMesh;
  1920. if (parentMesh != null) {
  1921. this.bones = parentMesh.bones;
  1922. this.vertices = parentMesh.vertices;
  1923. this.worldVerticesLength = parentMesh.worldVerticesLength;
  1924. this.regionUVs = parentMesh.regionUVs;
  1925. this.triangles = parentMesh.triangles;
  1926. this.hullLength = parentMesh.hullLength;
  1927. this.worldVerticesLength = parentMesh.worldVerticesLength;
  1928. }
  1929. }
  1930. copy () {
  1931. if (this.parentMesh != null) return this.newLinkedMesh();
  1932. let copy = new MeshAttachment(this.name);
  1933. copy.region = this.region;
  1934. copy.path = this.path;
  1935. copy.color.setFromColor(this.color);
  1936. this.copyTo(copy);
  1937. copy.regionUVs = new Float32Array(this.regionUVs.length);
  1938. Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
  1939. copy.triangles = new Array(this.triangles.length);
  1940. Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
  1941. copy.hullLength = this.hullLength;
  1942. // Nonessential.
  1943. if (this.edges != null) {
  1944. copy.edges = new Array(this.edges.length);
  1945. Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
  1946. }
  1947. copy.width = this.width;
  1948. copy.height = this.height;
  1949. return copy;
  1950. }
  1951. newLinkedMesh () {
  1952. let copy = new MeshAttachment(this.name);
  1953. copy.region = this.region;
  1954. copy.path = this.path;
  1955. copy.color.setFromColor(this.color);
  1956. copy.deformAttachment = this.deformAttachment;
  1957. copy.setParentMesh(this.parentMesh != null ? this.parentMesh : this);
  1958. // copy.updateUVs();
  1959. return copy;
  1960. }
  1961. }
  1962. /**
  1963. * @public
  1964. */
  1965. class PathAttachment extends VertexAttachment {
  1966. __init() {this.type = exports.AttachmentType.Path;}
  1967. __init2() {this.closed = false;} __init3() {this.constantSpeed = false;}
  1968. __init4() {this.color = new Color(1, 1, 1, 1);}
  1969. constructor (name) {
  1970. super(name);PathAttachment.prototype.__init.call(this);PathAttachment.prototype.__init2.call(this);PathAttachment.prototype.__init3.call(this);PathAttachment.prototype.__init4.call(this); }
  1971. copy () {
  1972. let copy = new PathAttachment(this.name);
  1973. this.copyTo(copy);
  1974. copy.lengths = new Array(this.lengths.length);
  1975. Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
  1976. copy.closed = closed;
  1977. copy.constantSpeed = this.constantSpeed;
  1978. copy.color.setFromColor(this.color);
  1979. return copy;
  1980. }
  1981. }
  1982. /**
  1983. * @public
  1984. */
  1985. class PointAttachment extends VertexAttachment {
  1986. __init() {this.type = exports.AttachmentType.Point;}
  1987. __init2() {this.color = new Color(0.38, 0.94, 0, 1);}
  1988. constructor (name) {
  1989. super(name);PointAttachment.prototype.__init.call(this);PointAttachment.prototype.__init2.call(this); }
  1990. computeWorldPosition(bone, point) {
  1991. const mat = bone.matrix;
  1992. point.x = this.x * mat.a + this.y * mat.c + bone.worldX;
  1993. point.y = this.x * mat.b + this.y * mat.d + bone.worldY;
  1994. return point;
  1995. }
  1996. computeWorldRotation(bone) {
  1997. const mat = bone.matrix;
  1998. let cos = MathUtils.cosDeg(this.rotation), sin = MathUtils.sinDeg(this.rotation);
  1999. let x = cos * mat.a + sin * mat.c;
  2000. let y = cos * mat.b + sin * mat.d;
  2001. return Math.atan2(y, x) * MathUtils.radDeg;
  2002. }
  2003. copy () {
  2004. let copy = new PointAttachment(this.name);
  2005. copy.x = this.x;
  2006. copy.y = this.y;
  2007. copy.rotation = this.rotation;
  2008. copy.color.setFromColor(this.color);
  2009. return copy;
  2010. }
  2011. }
  2012. /**
  2013. * @public
  2014. */
  2015. class RegionAttachment extends Attachment {
  2016. __init() {this.type = exports.AttachmentType.Region;}
  2017. static __initStatic() {this.OX1 = 0;}
  2018. static __initStatic2() {this.OY1 = 1;}
  2019. static __initStatic3() {this.OX2 = 2;}
  2020. static __initStatic4() {this.OY2 = 3;}
  2021. static __initStatic5() {this.OX3 = 4;}
  2022. static __initStatic6() {this.OY3 = 5;}
  2023. static __initStatic7() {this.OX4 = 6;}
  2024. static __initStatic8() {this.OY4 = 7;}
  2025. static __initStatic9() {this.X1 = 0;}
  2026. static __initStatic10() {this.Y1 = 1;}
  2027. static __initStatic11() {this.C1R = 2;}
  2028. static __initStatic12() {this.C1G = 3;}
  2029. static __initStatic13() {this.C1B = 4;}
  2030. static __initStatic14() {this.C1A = 5;}
  2031. static __initStatic15() {this.U1 = 6;}
  2032. static __initStatic16() {this.V1 = 7;}
  2033. static __initStatic17() {this.X2 = 8;}
  2034. static __initStatic18() {this.Y2 = 9;}
  2035. static __initStatic19() {this.C2R = 10;}
  2036. static __initStatic20() {this.C2G = 11;}
  2037. static __initStatic21() {this.C2B = 12;}
  2038. static __initStatic22() {this.C2A = 13;}
  2039. static __initStatic23() {this.U2 = 14;}
  2040. static __initStatic24() {this.V2 = 15;}
  2041. static __initStatic25() {this.X3 = 16;}
  2042. static __initStatic26() {this.Y3 = 17;}
  2043. static __initStatic27() {this.C3R = 18;}
  2044. static __initStatic28() {this.C3G = 19;}
  2045. static __initStatic29() {this.C3B = 20;}
  2046. static __initStatic30() {this.C3A = 21;}
  2047. static __initStatic31() {this.U3 = 22;}
  2048. static __initStatic32() {this.V3 = 23;}
  2049. static __initStatic33() {this.X4 = 24;}
  2050. static __initStatic34() {this.Y4 = 25;}
  2051. static __initStatic35() {this.C4R = 26;}
  2052. static __initStatic36() {this.C4G = 27;}
  2053. static __initStatic37() {this.C4B = 28;}
  2054. static __initStatic38() {this.C4A = 29;}
  2055. static __initStatic39() {this.U4 = 30;}
  2056. static __initStatic40() {this.V4 = 31;}
  2057. __init2() {this.x = 0;}
  2058. __init3() {this.y = 0;}
  2059. __init4() {this.scaleX = 1;}
  2060. __init5() {this.scaleY = 1;}
  2061. __init6() {this.rotation = 0;}
  2062. __init7() {this.width = 0;}
  2063. __init8() {this.height = 0;}
  2064. __init9() {this.color = new Color(1, 1, 1, 1);}
  2065. __init10() {this.offset = Utils.newFloatArray(8);}
  2066. __init11() {this.uvs = Utils.newFloatArray(8);}
  2067. __init12() {this.tempColor = new Color(1, 1, 1, 1);}
  2068. constructor(name) {
  2069. super(name);RegionAttachment.prototype.__init.call(this);RegionAttachment.prototype.__init2.call(this);RegionAttachment.prototype.__init3.call(this);RegionAttachment.prototype.__init4.call(this);RegionAttachment.prototype.__init5.call(this);RegionAttachment.prototype.__init6.call(this);RegionAttachment.prototype.__init7.call(this);RegionAttachment.prototype.__init8.call(this);RegionAttachment.prototype.__init9.call(this);RegionAttachment.prototype.__init10.call(this);RegionAttachment.prototype.__init11.call(this);RegionAttachment.prototype.__init12.call(this); }
  2070. updateOffset() {
  2071. let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  2072. let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  2073. let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  2074. let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  2075. let localX2 = localX + this.region.width * regionScaleX;
  2076. let localY2 = localY + this.region.height * regionScaleY;
  2077. let radians = this.rotation * Math.PI / 180;
  2078. let cos = Math.cos(radians);
  2079. let sin = Math.sin(radians);
  2080. let localXCos = localX * cos + this.x;
  2081. let localXSin = localX * sin;
  2082. let localYCos = localY * cos + this.y;
  2083. let localYSin = localY * sin;
  2084. let localX2Cos = localX2 * cos + this.x;
  2085. let localX2Sin = localX2 * sin;
  2086. let localY2Cos = localY2 * cos + this.y;
  2087. let localY2Sin = localY2 * sin;
  2088. let offset = this.offset;
  2089. offset[RegionAttachment.OX1] = localXCos - localYSin;
  2090. offset[RegionAttachment.OY1] = localYCos + localXSin;
  2091. offset[RegionAttachment.OX2] = localXCos - localY2Sin;
  2092. offset[RegionAttachment.OY2] = localY2Cos + localXSin;
  2093. offset[RegionAttachment.OX3] = localX2Cos - localY2Sin;
  2094. offset[RegionAttachment.OY3] = localY2Cos + localX2Sin;
  2095. offset[RegionAttachment.OX4] = localX2Cos - localYSin;
  2096. offset[RegionAttachment.OY4] = localYCos + localX2Sin;
  2097. }
  2098. setRegion(region) {
  2099. this.region = region;
  2100. let uvs = this.uvs;
  2101. if (region.rotate) {
  2102. uvs[2] = region.u;
  2103. uvs[3] = region.v2;
  2104. uvs[4] = region.u;
  2105. uvs[5] = region.v;
  2106. uvs[6] = region.u2;
  2107. uvs[7] = region.v;
  2108. uvs[0] = region.u2;
  2109. uvs[1] = region.v2;
  2110. } else {
  2111. uvs[0] = region.u;
  2112. uvs[1] = region.v2;
  2113. uvs[2] = region.u;
  2114. uvs[3] = region.v;
  2115. uvs[4] = region.u2;
  2116. uvs[5] = region.v;
  2117. uvs[6] = region.u2;
  2118. uvs[7] = region.v2;
  2119. }
  2120. }
  2121. computeWorldVertices(bone, worldVertices, offset, stride) {
  2122. let vertexOffset = this.offset;
  2123. let mat = bone.matrix;
  2124. let x = mat.tx, y = mat.ty;
  2125. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  2126. let offsetX = 0, offsetY = 0;
  2127. offsetX = vertexOffset[RegionAttachment.OX1];
  2128. offsetY = vertexOffset[RegionAttachment.OY1];
  2129. worldVertices[offset] = offsetX * a + offsetY * b + x; // br
  2130. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2131. offset += stride;
  2132. offsetX = vertexOffset[RegionAttachment.OX2];
  2133. offsetY = vertexOffset[RegionAttachment.OY2];
  2134. worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
  2135. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2136. offset += stride;
  2137. offsetX = vertexOffset[RegionAttachment.OX3];
  2138. offsetY = vertexOffset[RegionAttachment.OY3];
  2139. worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
  2140. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2141. offset += stride;
  2142. offsetX = vertexOffset[RegionAttachment.OX4];
  2143. offsetY = vertexOffset[RegionAttachment.OY4];
  2144. worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
  2145. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2146. }
  2147. copy () {
  2148. let copy = new RegionAttachment(this.name);
  2149. copy.region = this.region;
  2150. copy.rendererObject = this.rendererObject;
  2151. copy.path = this.path;
  2152. copy.x = this.x;
  2153. copy.y = this.y;
  2154. copy.scaleX = this.scaleX;
  2155. copy.scaleY = this.scaleY;
  2156. copy.rotation = this.rotation;
  2157. copy.width = this.width;
  2158. copy.height = this.height;
  2159. Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
  2160. Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
  2161. copy.color.setFromColor(this.color);
  2162. return copy;
  2163. }
  2164. } RegionAttachment.__initStatic(); RegionAttachment.__initStatic2(); RegionAttachment.__initStatic3(); RegionAttachment.__initStatic4(); RegionAttachment.__initStatic5(); RegionAttachment.__initStatic6(); RegionAttachment.__initStatic7(); RegionAttachment.__initStatic8(); RegionAttachment.__initStatic9(); RegionAttachment.__initStatic10(); RegionAttachment.__initStatic11(); RegionAttachment.__initStatic12(); RegionAttachment.__initStatic13(); RegionAttachment.__initStatic14(); RegionAttachment.__initStatic15(); RegionAttachment.__initStatic16(); RegionAttachment.__initStatic17(); RegionAttachment.__initStatic18(); RegionAttachment.__initStatic19(); RegionAttachment.__initStatic20(); RegionAttachment.__initStatic21(); RegionAttachment.__initStatic22(); RegionAttachment.__initStatic23(); RegionAttachment.__initStatic24(); RegionAttachment.__initStatic25(); RegionAttachment.__initStatic26(); RegionAttachment.__initStatic27(); RegionAttachment.__initStatic28(); RegionAttachment.__initStatic29(); RegionAttachment.__initStatic30(); RegionAttachment.__initStatic31(); RegionAttachment.__initStatic32(); RegionAttachment.__initStatic33(); RegionAttachment.__initStatic34(); RegionAttachment.__initStatic35(); RegionAttachment.__initStatic36(); RegionAttachment.__initStatic37(); RegionAttachment.__initStatic38(); RegionAttachment.__initStatic39(); RegionAttachment.__initStatic40();
  2165. /**
  2166. * @public
  2167. */
  2168. class JitterEffect {
  2169. __init() {this.jitterX = 0;}
  2170. __init2() {this.jitterY = 0;}
  2171. constructor (jitterX, jitterY) {JitterEffect.prototype.__init.call(this);JitterEffect.prototype.__init2.call(this);
  2172. this.jitterX = jitterX;
  2173. this.jitterY = jitterY;
  2174. }
  2175. begin(skeleton) {
  2176. }
  2177. transform(position, uv, light, dark) {
  2178. position.x += MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  2179. position.y += MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  2180. }
  2181. end() {
  2182. }
  2183. }
  2184. /**
  2185. * @public
  2186. */
  2187. class SwirlEffect {
  2188. static __initStatic() {this.interpolation = new PowOut(2);}
  2189. __init() {this.centerX = 0;}
  2190. __init2() {this.centerY = 0;}
  2191. __init3() {this.radius = 0;}
  2192. __init4() {this.angle = 0;}
  2193. __init5() {this.worldX = 0;}
  2194. __init6() {this.worldY = 0;}
  2195. constructor (radius) {SwirlEffect.prototype.__init.call(this);SwirlEffect.prototype.__init2.call(this);SwirlEffect.prototype.__init3.call(this);SwirlEffect.prototype.__init4.call(this);SwirlEffect.prototype.__init5.call(this);SwirlEffect.prototype.__init6.call(this);
  2196. this.radius = radius;
  2197. }
  2198. begin(skeleton) {
  2199. this.worldX = skeleton.x + this.centerX;
  2200. this.worldY = skeleton.y + this.centerY;
  2201. }
  2202. transform(position, uv, light, dark) {
  2203. let radAngle = this.angle * MathUtils.degreesToRadians;
  2204. let x = position.x - this.worldX;
  2205. let y = position.y - this.worldY;
  2206. let dist = Math.sqrt(x * x + y * y);
  2207. if (dist < this.radius) {
  2208. let theta = SwirlEffect.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  2209. let cos = Math.cos(theta);
  2210. let sin = Math.sin(theta);
  2211. position.x = cos * x - sin * y + this.worldX;
  2212. position.y = sin * x + cos * y + this.worldY;
  2213. }
  2214. }
  2215. end() {
  2216. }
  2217. } SwirlEffect.__initStatic();
  2218. /** A simple container for a list of timelines and a name. */
  2219. /**
  2220. * @public
  2221. */
  2222. class Animation {
  2223. /** The animation's name, which is unique across all animations in the skeleton. */
  2224. /** The duration of the animation in seconds, which is the highest time of all keys in the timeline. */
  2225. constructor (name, timelines, duration) {
  2226. if (name == null) throw new Error("name cannot be null.");
  2227. if (timelines == null) throw new Error("timelines cannot be null.");
  2228. this.name = name;
  2229. this.timelines = timelines;
  2230. this.timelineIds = [];
  2231. for (var i = 0; i < timelines.length; i++)
  2232. this.timelineIds[timelines[i].getPropertyId()] = true;
  2233. this.duration = duration;
  2234. }
  2235. hasTimeline (id) {
  2236. return this.timelineIds[id] == true;
  2237. }
  2238. /** Applies all the animation's timelines to the specified skeleton.
  2239. *
  2240. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
  2241. * @param loop If true, the animation repeats after {@link #getDuration()}.
  2242. * @param events May be null to ignore fired events. */
  2243. apply (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
  2244. if (skeleton == null) throw new Error("skeleton cannot be null.");
  2245. if (loop && this.duration != 0) {
  2246. time %= this.duration;
  2247. if (lastTime > 0) lastTime %= this.duration;
  2248. }
  2249. let timelines = this.timelines;
  2250. for (let i = 0, n = timelines.length; i < n; i++)
  2251. timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
  2252. }
  2253. /** @param target After the first and before the last value.
  2254. * @returns index of first value greater than the target. */
  2255. static binarySearch (values, target, step = 1) {
  2256. let low = 0;
  2257. let high = values.length / step - 2;
  2258. if (high == 0) return step;
  2259. let current = high >>> 1;
  2260. while (true) {
  2261. if (values[(current + 1) * step] <= target)
  2262. low = current + 1;
  2263. else
  2264. high = current;
  2265. if (low == high) return (low + 1) * step;
  2266. current = (low + high) >>> 1;
  2267. }
  2268. }
  2269. static linearSearch (values, target, step) {
  2270. for (let i = 0, last = values.length - step; i <= last; i += step)
  2271. if (values[i] > target) return i;
  2272. return -1;
  2273. }
  2274. }
  2275. /** The interface for all timelines. */
  2276. /**
  2277. * @public
  2278. */
  2279. /** Controls how a timeline value is mixed with the setup pose value or current pose value when a timeline's `alpha`
  2280. * < 1.
  2281. *
  2282. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}. */
  2283. /**
  2284. * @public
  2285. */
  2286. var MixBlend; (function (MixBlend) {
  2287. /** Transitions from the setup value to the timeline value (the current value is not used). Before the first key, the setup
  2288. * value is set. */
  2289. const setup = 0; MixBlend[MixBlend["setup"] = setup] = "setup";
  2290. /** Transitions from the current value to the timeline value. Before the first key, transitions from the current value to
  2291. * the setup value. Timelines which perform instant transitions, such as {@link DrawOrderTimeline} or
  2292. * {@link AttachmentTimeline}, use the setup value before the first key.
  2293. *
  2294. * `first` is intended for the first animations applied, not for animations layered on top of those. */
  2295. const first = setup + 1; MixBlend[MixBlend["first"] = first] = "first";
  2296. /** Transitions from the current value to the timeline value. No change is made before the first key (the current value is
  2297. * kept until the first key).
  2298. *
  2299. * `replace` is intended for animations layered on top of others, not for the first animations applied. */
  2300. const replace = first + 1; MixBlend[MixBlend["replace"] = replace] = "replace";
  2301. /** Transitions from the current value to the current value plus the timeline value. No change is made before the first key
  2302. * (the current value is kept until the first key).
  2303. *
  2304. * `add` is intended for animations layered on top of others, not for the first animations applied. Properties
  2305. * keyed by additive animations must be set manually or by another animation before applying the additive animations, else
  2306. * the property values will increase continually. */
  2307. const add = replace + 1; MixBlend[MixBlend["add"] = add] = "add";
  2308. })(MixBlend || (MixBlend = {}));
  2309. /** Indicates whether a timeline's `alpha` is mixing out over time toward 0 (the setup or current pose value) or
  2310. * mixing in toward 1 (the timeline's value).
  2311. *
  2312. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}. */
  2313. /**
  2314. * @public
  2315. */
  2316. var MixDirection; (function (MixDirection) {
  2317. const mixIn = 0; MixDirection[MixDirection["mixIn"] = mixIn] = "mixIn"; const mixOut = mixIn + 1; MixDirection[MixDirection["mixOut"] = mixOut] = "mixOut";
  2318. })(MixDirection || (MixDirection = {}));
  2319. /**
  2320. * @public
  2321. */
  2322. var TimelineType; (function (TimelineType) {
  2323. const rotate = 0; TimelineType[TimelineType["rotate"] = rotate] = "rotate"; const translate = rotate + 1; TimelineType[TimelineType["translate"] = translate] = "translate"; const scale = translate + 1; TimelineType[TimelineType["scale"] = scale] = "scale"; const shear = scale + 1; TimelineType[TimelineType["shear"] = shear] = "shear";
  2324. const attachment = shear + 1; TimelineType[TimelineType["attachment"] = attachment] = "attachment"; const color = attachment + 1; TimelineType[TimelineType["color"] = color] = "color"; const deform = color + 1; TimelineType[TimelineType["deform"] = deform] = "deform";
  2325. const event = deform + 1; TimelineType[TimelineType["event"] = event] = "event"; const drawOrder = event + 1; TimelineType[TimelineType["drawOrder"] = drawOrder] = "drawOrder";
  2326. const ikConstraint = drawOrder + 1; TimelineType[TimelineType["ikConstraint"] = ikConstraint] = "ikConstraint"; const transformConstraint = ikConstraint + 1; TimelineType[TimelineType["transformConstraint"] = transformConstraint] = "transformConstraint";
  2327. const pathConstraintPosition = transformConstraint + 1; TimelineType[TimelineType["pathConstraintPosition"] = pathConstraintPosition] = "pathConstraintPosition"; const pathConstraintSpacing = pathConstraintPosition + 1; TimelineType[TimelineType["pathConstraintSpacing"] = pathConstraintSpacing] = "pathConstraintSpacing"; const pathConstraintMix = pathConstraintSpacing + 1; TimelineType[TimelineType["pathConstraintMix"] = pathConstraintMix] = "pathConstraintMix";
  2328. const twoColor = pathConstraintMix + 1; TimelineType[TimelineType["twoColor"] = twoColor] = "twoColor";
  2329. })(TimelineType || (TimelineType = {}));
  2330. /** The base class for timelines that use interpolation between key frame values. */
  2331. /**
  2332. * @public
  2333. */
  2334. class CurveTimeline {
  2335. static __initStatic() {this.LINEAR = 0;} static __initStatic2() {this.STEPPED = 1;} static __initStatic3() {this.BEZIER = 2;}
  2336. static __initStatic4() {this.BEZIER_SIZE = 10 * 2 - 1;}
  2337. // type, x, y, ...
  2338. constructor (frameCount) {
  2339. if (frameCount <= 0) throw new Error("frameCount must be > 0: " + frameCount);
  2340. this.curves = Utils.newFloatArray((frameCount - 1) * CurveTimeline.BEZIER_SIZE);
  2341. }
  2342. /** The number of key frames for this timeline. */
  2343. getFrameCount () {
  2344. return this.curves.length / CurveTimeline.BEZIER_SIZE + 1;
  2345. }
  2346. /** Sets the specified key frame to linear interpolation. */
  2347. setLinear (frameIndex) {
  2348. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.LINEAR;
  2349. }
  2350. /** Sets the specified key frame to stepped interpolation. */
  2351. setStepped (frameIndex) {
  2352. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.STEPPED;
  2353. }
  2354. /** Returns the interpolation type for the specified key frame.
  2355. * @returns Linear is 0, stepped is 1, Bezier is 2. */
  2356. getCurveType (frameIndex) {
  2357. let index = frameIndex * CurveTimeline.BEZIER_SIZE;
  2358. if (index == this.curves.length) return CurveTimeline.LINEAR;
  2359. let type = this.curves[index];
  2360. if (type == CurveTimeline.LINEAR) return CurveTimeline.LINEAR;
  2361. if (type == CurveTimeline.STEPPED) return CurveTimeline.STEPPED;
  2362. return CurveTimeline.BEZIER;
  2363. }
  2364. /** Sets the specified key frame to Bezier interpolation. `cx1` and `cx2` are from 0 to 1,
  2365. * representing the percent of time between the two key frames. `cy1` and `cy2` are the percent of the
  2366. * difference between the key frame's values. */
  2367. setCurve (frameIndex, cx1, cy1, cx2, cy2) {
  2368. let tmpx = (-cx1 * 2 + cx2) * 0.03, tmpy = (-cy1 * 2 + cy2) * 0.03;
  2369. let dddfx = ((cx1 - cx2) * 3 + 1) * 0.006, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006;
  2370. let ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
  2371. let dfx = cx1 * 0.3 + tmpx + dddfx * 0.16666667, dfy = cy1 * 0.3 + tmpy + dddfy * 0.16666667;
  2372. let i = frameIndex * CurveTimeline.BEZIER_SIZE;
  2373. let curves = this.curves;
  2374. curves[i++] = CurveTimeline.BEZIER;
  2375. let x = dfx, y = dfy;
  2376. for (let n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  2377. curves[i] = x;
  2378. curves[i + 1] = y;
  2379. dfx += ddfx;
  2380. dfy += ddfy;
  2381. ddfx += dddfx;
  2382. ddfy += dddfy;
  2383. x += dfx;
  2384. y += dfy;
  2385. }
  2386. }
  2387. /** Returns the interpolated percentage for the specified key frame and linear percentage. */
  2388. getCurvePercent (frameIndex, percent) {
  2389. percent = MathUtils.clamp(percent, 0, 1);
  2390. let curves = this.curves;
  2391. let i = frameIndex * CurveTimeline.BEZIER_SIZE;
  2392. let type = curves[i];
  2393. if (type == CurveTimeline.LINEAR) return percent;
  2394. if (type == CurveTimeline.STEPPED) return 0;
  2395. i++;
  2396. let x = 0;
  2397. for (let start = i, n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  2398. x = curves[i];
  2399. if (x >= percent) {
  2400. let prevX, prevY;
  2401. if (i == start) {
  2402. prevX = 0;
  2403. prevY = 0;
  2404. } else {
  2405. prevX = curves[i - 2];
  2406. prevY = curves[i - 1];
  2407. }
  2408. return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
  2409. }
  2410. }
  2411. let y = curves[i - 1];
  2412. return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
  2413. }
  2414. } CurveTimeline.__initStatic(); CurveTimeline.__initStatic2(); CurveTimeline.__initStatic3(); CurveTimeline.__initStatic4();
  2415. /** Changes a bone's local {@link Bone#rotation}. */
  2416. /**
  2417. * @public
  2418. */
  2419. class RotateTimeline extends CurveTimeline {
  2420. static __initStatic5() {this.ENTRIES = 2;}
  2421. static __initStatic6() {this.PREV_TIME = -2;} static __initStatic7() {this.PREV_ROTATION = -1;}
  2422. static __initStatic8() {this.ROTATION = 1;}
  2423. /** The index of the bone in {@link Skeleton#bones} that will be changed. */
  2424. /** The time in seconds and rotation in degrees for each key frame. */
  2425. // time, degrees, ...
  2426. constructor (frameCount) {
  2427. super(frameCount);
  2428. this.frames = Utils.newFloatArray(frameCount << 1);
  2429. }
  2430. getPropertyId () {
  2431. return (TimelineType.rotate << 24) + this.boneIndex;
  2432. }
  2433. /** Sets the time and angle of the specified keyframe. */
  2434. setFrame (frameIndex, time, degrees) {
  2435. frameIndex <<= 1;
  2436. this.frames[frameIndex] = time;
  2437. this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
  2438. }
  2439. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2440. let frames = this.frames;
  2441. let bone = skeleton.bones[this.boneIndex];
  2442. if (!bone.active) return;
  2443. if (time < frames[0]) {
  2444. switch (blend) {
  2445. case MixBlend.setup:
  2446. bone.rotation = bone.data.rotation;
  2447. return;
  2448. case MixBlend.first:
  2449. let r = bone.data.rotation - bone.rotation;
  2450. bone.rotation += (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  2451. }
  2452. return;
  2453. }
  2454. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) { // Time is after last frame.
  2455. let r = frames[frames.length + RotateTimeline.PREV_ROTATION];
  2456. switch (blend) {
  2457. case MixBlend.setup:
  2458. bone.rotation = bone.data.rotation + r * alpha;
  2459. break;
  2460. case MixBlend.first:
  2461. case MixBlend.replace:
  2462. r += bone.data.rotation - bone.rotation;
  2463. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; // Wrap within -180 and 180.
  2464. case MixBlend.add:
  2465. bone.rotation += r * alpha;
  2466. }
  2467. return;
  2468. }
  2469. // Interpolate between the previous frame and the current frame.
  2470. let frame = Animation.binarySearch(frames, time, RotateTimeline.ENTRIES);
  2471. let prevRotation = frames[frame + RotateTimeline.PREV_ROTATION];
  2472. let frameTime = frames[frame];
  2473. let percent = this.getCurvePercent((frame >> 1) - 1,
  2474. 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
  2475. let r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
  2476. r = prevRotation + (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * percent;
  2477. switch (blend) {
  2478. case MixBlend.setup:
  2479. bone.rotation = bone.data.rotation + (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  2480. break;
  2481. case MixBlend.first:
  2482. case MixBlend.replace:
  2483. r += bone.data.rotation - bone.rotation;
  2484. case MixBlend.add:
  2485. bone.rotation += (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  2486. }
  2487. }
  2488. } RotateTimeline.__initStatic5(); RotateTimeline.__initStatic6(); RotateTimeline.__initStatic7(); RotateTimeline.__initStatic8();
  2489. /** Changes a bone's local {@link Bone#x} and {@link Bone#y}. */
  2490. /**
  2491. * @public
  2492. */
  2493. class TranslateTimeline extends CurveTimeline {
  2494. static __initStatic9() {this.ENTRIES = 3;}
  2495. static __initStatic10() {this.PREV_TIME = -3;} static __initStatic11() {this.PREV_X = -2;} static __initStatic12() {this.PREV_Y = -1;}
  2496. static __initStatic13() {this.X = 1;} static __initStatic14() {this.Y = 2;}
  2497. /** The index of the bone in {@link Skeleton#bones} that will be changed. */
  2498. /** The time in seconds, x, and y values for each key frame. */
  2499. // time, x, y, ...
  2500. constructor (frameCount) {
  2501. super(frameCount);
  2502. this.frames = Utils.newFloatArray(frameCount * TranslateTimeline.ENTRIES);
  2503. }
  2504. getPropertyId () {
  2505. return (TimelineType.translate << 24) + this.boneIndex;
  2506. }
  2507. /** Sets the time in seconds, x, and y values for the specified key frame. */
  2508. setFrame (frameIndex, time, x, y) {
  2509. frameIndex *= TranslateTimeline.ENTRIES;
  2510. this.frames[frameIndex] = time;
  2511. this.frames[frameIndex + TranslateTimeline.X] = x;
  2512. this.frames[frameIndex + TranslateTimeline.Y] = y;
  2513. }
  2514. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2515. let frames = this.frames;
  2516. let bone = skeleton.bones[this.boneIndex];
  2517. if (!bone.active) return;
  2518. if (time < frames[0]) {
  2519. switch (blend) {
  2520. case MixBlend.setup:
  2521. bone.x = bone.data.x;
  2522. bone.y = bone.data.y;
  2523. return;
  2524. case MixBlend.first:
  2525. bone.x += (bone.data.x - bone.x) * alpha;
  2526. bone.y += (bone.data.y - bone.y) * alpha;
  2527. }
  2528. return;
  2529. }
  2530. let x = 0, y = 0;
  2531. if (time >= frames[frames.length - TranslateTimeline.ENTRIES]) { // Time is after last frame.
  2532. x = frames[frames.length + TranslateTimeline.PREV_X];
  2533. y = frames[frames.length + TranslateTimeline.PREV_Y];
  2534. } else {
  2535. // Interpolate between the previous frame and the current frame.
  2536. let frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
  2537. x = frames[frame + TranslateTimeline.PREV_X];
  2538. y = frames[frame + TranslateTimeline.PREV_Y];
  2539. let frameTime = frames[frame];
  2540. let percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1,
  2541. 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
  2542. x += (frames[frame + TranslateTimeline.X] - x) * percent;
  2543. y += (frames[frame + TranslateTimeline.Y] - y) * percent;
  2544. }
  2545. switch (blend) {
  2546. case MixBlend.setup:
  2547. bone.x = bone.data.x + x * alpha;
  2548. bone.y = bone.data.y + y * alpha;
  2549. break;
  2550. case MixBlend.first:
  2551. case MixBlend.replace:
  2552. bone.x += (bone.data.x + x - bone.x) * alpha;
  2553. bone.y += (bone.data.y + y - bone.y) * alpha;
  2554. break;
  2555. case MixBlend.add:
  2556. bone.x += x * alpha;
  2557. bone.y += y * alpha;
  2558. }
  2559. }
  2560. } TranslateTimeline.__initStatic9(); TranslateTimeline.__initStatic10(); TranslateTimeline.__initStatic11(); TranslateTimeline.__initStatic12(); TranslateTimeline.__initStatic13(); TranslateTimeline.__initStatic14();
  2561. /** Changes a bone's local {@link Bone#scaleX)} and {@link Bone#scaleY}. */
  2562. /**
  2563. * @public
  2564. */
  2565. class ScaleTimeline extends TranslateTimeline {
  2566. constructor (frameCount) {
  2567. super(frameCount);
  2568. }
  2569. getPropertyId () {
  2570. return (TimelineType.scale << 24) + this.boneIndex;
  2571. }
  2572. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2573. let frames = this.frames;
  2574. let bone = skeleton.bones[this.boneIndex];
  2575. if (!bone.active) return;
  2576. if (time < frames[0]) {
  2577. switch (blend) {
  2578. case MixBlend.setup:
  2579. bone.scaleX = bone.data.scaleX;
  2580. bone.scaleY = bone.data.scaleY;
  2581. return;
  2582. case MixBlend.first:
  2583. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  2584. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  2585. }
  2586. return;
  2587. }
  2588. let x = 0, y = 0;
  2589. if (time >= frames[frames.length - ScaleTimeline.ENTRIES]) { // Time is after last frame.
  2590. x = frames[frames.length + ScaleTimeline.PREV_X] * bone.data.scaleX;
  2591. y = frames[frames.length + ScaleTimeline.PREV_Y] * bone.data.scaleY;
  2592. } else {
  2593. // Interpolate between the previous frame and the current frame.
  2594. let frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
  2595. x = frames[frame + ScaleTimeline.PREV_X];
  2596. y = frames[frame + ScaleTimeline.PREV_Y];
  2597. let frameTime = frames[frame];
  2598. let percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1,
  2599. 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
  2600. x = (x + (frames[frame + ScaleTimeline.X] - x) * percent) * bone.data.scaleX;
  2601. y = (y + (frames[frame + ScaleTimeline.Y] - y) * percent) * bone.data.scaleY;
  2602. }
  2603. if (alpha == 1) {
  2604. if (blend == MixBlend.add) {
  2605. bone.scaleX += x - bone.data.scaleX;
  2606. bone.scaleY += y - bone.data.scaleY;
  2607. } else {
  2608. bone.scaleX = x;
  2609. bone.scaleY = y;
  2610. }
  2611. } else {
  2612. let bx = 0, by = 0;
  2613. if (direction == MixDirection.mixOut) {
  2614. switch (blend) {
  2615. case MixBlend.setup:
  2616. bx = bone.data.scaleX;
  2617. by = bone.data.scaleY;
  2618. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  2619. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  2620. break;
  2621. case MixBlend.first:
  2622. case MixBlend.replace:
  2623. bx = bone.scaleX;
  2624. by = bone.scaleY;
  2625. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  2626. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  2627. break;
  2628. case MixBlend.add:
  2629. bx = bone.scaleX;
  2630. by = bone.scaleY;
  2631. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  2632. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - bone.data.scaleY) * alpha;
  2633. }
  2634. } else {
  2635. switch (blend) {
  2636. case MixBlend.setup:
  2637. bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
  2638. by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
  2639. bone.scaleX = bx + (x - bx) * alpha;
  2640. bone.scaleY = by + (y - by) * alpha;
  2641. break;
  2642. case MixBlend.first:
  2643. case MixBlend.replace:
  2644. bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
  2645. by = Math.abs(bone.scaleY) * MathUtils.signum(y);
  2646. bone.scaleX = bx + (x - bx) * alpha;
  2647. bone.scaleY = by + (y - by) * alpha;
  2648. break;
  2649. case MixBlend.add:
  2650. bx = MathUtils.signum(x);
  2651. by = MathUtils.signum(y);
  2652. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  2653. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. /** Changes a bone's local {@link Bone#shearX} and {@link Bone#shearY}. */
  2660. /**
  2661. * @public
  2662. */
  2663. class ShearTimeline extends TranslateTimeline {
  2664. constructor (frameCount) {
  2665. super(frameCount);
  2666. }
  2667. getPropertyId () {
  2668. return (TimelineType.shear << 24) + this.boneIndex;
  2669. }
  2670. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2671. let frames = this.frames;
  2672. let bone = skeleton.bones[this.boneIndex];
  2673. if (!bone.active) return;
  2674. if (time < frames[0]) {
  2675. switch (blend) {
  2676. case MixBlend.setup:
  2677. bone.shearX = bone.data.shearX;
  2678. bone.shearY = bone.data.shearY;
  2679. return;
  2680. case MixBlend.first:
  2681. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  2682. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  2683. }
  2684. return;
  2685. }
  2686. let x = 0, y = 0;
  2687. if (time >= frames[frames.length - ShearTimeline.ENTRIES]) { // Time is after last frame.
  2688. x = frames[frames.length + ShearTimeline.PREV_X];
  2689. y = frames[frames.length + ShearTimeline.PREV_Y];
  2690. } else {
  2691. // Interpolate between the previous frame and the current frame.
  2692. let frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
  2693. x = frames[frame + ShearTimeline.PREV_X];
  2694. y = frames[frame + ShearTimeline.PREV_Y];
  2695. let frameTime = frames[frame];
  2696. let percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1,
  2697. 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
  2698. x = x + (frames[frame + ShearTimeline.X] - x) * percent;
  2699. y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
  2700. }
  2701. switch (blend) {
  2702. case MixBlend.setup:
  2703. bone.shearX = bone.data.shearX + x * alpha;
  2704. bone.shearY = bone.data.shearY + y * alpha;
  2705. break;
  2706. case MixBlend.first:
  2707. case MixBlend.replace:
  2708. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  2709. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  2710. break;
  2711. case MixBlend.add:
  2712. bone.shearX += x * alpha;
  2713. bone.shearY += y * alpha;
  2714. }
  2715. }
  2716. }
  2717. /** Changes a slot's {@link Slot#color}. */
  2718. /**
  2719. * @public
  2720. */
  2721. class ColorTimeline extends CurveTimeline {
  2722. static __initStatic15() {this.ENTRIES = 5;}
  2723. static __initStatic16() {this.PREV_TIME = -5;} static __initStatic17() {this.PREV_R = -4;} static __initStatic18() {this.PREV_G = -3;} static __initStatic19() {this.PREV_B = -2;} static __initStatic20() {this.PREV_A = -1;}
  2724. static __initStatic21() {this.R = 1;} static __initStatic22() {this.G = 2;} static __initStatic23() {this.B = 3;} static __initStatic24() {this.A = 4;}
  2725. /** The index of the slot in {@link Skeleton#slots} that will be changed. */
  2726. /** The time in seconds, red, green, blue, and alpha values for each key frame. */
  2727. // time, r, g, b, a, ...
  2728. constructor (frameCount) {
  2729. super(frameCount);
  2730. this.frames = Utils.newFloatArray(frameCount * ColorTimeline.ENTRIES);
  2731. }
  2732. getPropertyId () {
  2733. return (TimelineType.color << 24) + this.slotIndex;
  2734. }
  2735. /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */
  2736. setFrame (frameIndex, time, r, g, b, a) {
  2737. frameIndex *= ColorTimeline.ENTRIES;
  2738. this.frames[frameIndex] = time;
  2739. this.frames[frameIndex + ColorTimeline.R] = r;
  2740. this.frames[frameIndex + ColorTimeline.G] = g;
  2741. this.frames[frameIndex + ColorTimeline.B] = b;
  2742. this.frames[frameIndex + ColorTimeline.A] = a;
  2743. }
  2744. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2745. let slot = skeleton.slots[this.slotIndex];
  2746. if (!slot.bone.active) return;
  2747. let frames = this.frames;
  2748. if (time < frames[0]) {
  2749. switch (blend) {
  2750. case MixBlend.setup:
  2751. slot.color.setFromColor(slot.data.color);
  2752. return;
  2753. case MixBlend.first:
  2754. let color = slot.color, setup = slot.data.color;
  2755. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
  2756. (setup.a - color.a) * alpha);
  2757. }
  2758. return;
  2759. }
  2760. let r = 0, g = 0, b = 0, a = 0;
  2761. if (time >= frames[frames.length - ColorTimeline.ENTRIES]) { // Time is after last frame.
  2762. let i = frames.length;
  2763. r = frames[i + ColorTimeline.PREV_R];
  2764. g = frames[i + ColorTimeline.PREV_G];
  2765. b = frames[i + ColorTimeline.PREV_B];
  2766. a = frames[i + ColorTimeline.PREV_A];
  2767. } else {
  2768. // Interpolate between the previous frame and the current frame.
  2769. let frame = Animation.binarySearch(frames, time, ColorTimeline.ENTRIES);
  2770. r = frames[frame + ColorTimeline.PREV_R];
  2771. g = frames[frame + ColorTimeline.PREV_G];
  2772. b = frames[frame + ColorTimeline.PREV_B];
  2773. a = frames[frame + ColorTimeline.PREV_A];
  2774. let frameTime = frames[frame];
  2775. let percent = this.getCurvePercent(frame / ColorTimeline.ENTRIES - 1,
  2776. 1 - (time - frameTime) / (frames[frame + ColorTimeline.PREV_TIME] - frameTime));
  2777. r += (frames[frame + ColorTimeline.R] - r) * percent;
  2778. g += (frames[frame + ColorTimeline.G] - g) * percent;
  2779. b += (frames[frame + ColorTimeline.B] - b) * percent;
  2780. a += (frames[frame + ColorTimeline.A] - a) * percent;
  2781. }
  2782. if (alpha == 1)
  2783. slot.color.set(r, g, b, a);
  2784. else {
  2785. let color = slot.color;
  2786. if (blend == MixBlend.setup) color.setFromColor(slot.data.color);
  2787. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  2788. }
  2789. }
  2790. } ColorTimeline.__initStatic15(); ColorTimeline.__initStatic16(); ColorTimeline.__initStatic17(); ColorTimeline.__initStatic18(); ColorTimeline.__initStatic19(); ColorTimeline.__initStatic20(); ColorTimeline.__initStatic21(); ColorTimeline.__initStatic22(); ColorTimeline.__initStatic23(); ColorTimeline.__initStatic24();
  2791. /** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting. */
  2792. /**
  2793. * @public
  2794. */
  2795. class TwoColorTimeline extends CurveTimeline {
  2796. static __initStatic25() {this.ENTRIES = 8;}
  2797. static __initStatic26() {this.PREV_TIME = -8;} static __initStatic27() {this.PREV_R = -7;} static __initStatic28() {this.PREV_G = -6;} static __initStatic29() {this.PREV_B = -5;} static __initStatic30() {this.PREV_A = -4;}
  2798. static __initStatic31() {this.PREV_R2 = -3;} static __initStatic32() {this.PREV_G2 = -2;} static __initStatic33() {this.PREV_B2 = -1;}
  2799. static __initStatic34() {this.R = 1;} static __initStatic35() {this.G = 2;} static __initStatic36() {this.B = 3;} static __initStatic37() {this.A = 4;} static __initStatic38() {this.R2 = 5;} static __initStatic39() {this.G2 = 6;} static __initStatic40() {this.B2 = 7;}
  2800. /** The index of the slot in {@link Skeleton#slots()} that will be changed. The {@link Slot#darkColor()} must not be
  2801. * null. */
  2802. /** The time in seconds, red, green, blue, and alpha values of the color, red, green, blue of the dark color, for each key frame. */
  2803. // time, r, g, b, a, r2, g2, b2, ...
  2804. constructor (frameCount) {
  2805. super(frameCount);
  2806. this.frames = Utils.newFloatArray(frameCount * TwoColorTimeline.ENTRIES);
  2807. }
  2808. getPropertyId () {
  2809. return (TimelineType.twoColor << 24) + this.slotIndex;
  2810. }
  2811. /** Sets the time in seconds, light, and dark colors for the specified key frame. */
  2812. setFrame (frameIndex, time, r, g, b, a, r2, g2, b2) {
  2813. frameIndex *= TwoColorTimeline.ENTRIES;
  2814. this.frames[frameIndex] = time;
  2815. this.frames[frameIndex + TwoColorTimeline.R] = r;
  2816. this.frames[frameIndex + TwoColorTimeline.G] = g;
  2817. this.frames[frameIndex + TwoColorTimeline.B] = b;
  2818. this.frames[frameIndex + TwoColorTimeline.A] = a;
  2819. this.frames[frameIndex + TwoColorTimeline.R2] = r2;
  2820. this.frames[frameIndex + TwoColorTimeline.G2] = g2;
  2821. this.frames[frameIndex + TwoColorTimeline.B2] = b2;
  2822. }
  2823. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2824. let slot = skeleton.slots[this.slotIndex];
  2825. if (!slot.bone.active) return;
  2826. let frames = this.frames;
  2827. if (time < frames[0]) {
  2828. switch (blend) {
  2829. case MixBlend.setup:
  2830. slot.color.setFromColor(slot.data.color);
  2831. slot.darkColor.setFromColor(slot.data.darkColor);
  2832. return;
  2833. case MixBlend.first:
  2834. let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  2835. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha,
  2836. (setupLight.a - light.a) * alpha);
  2837. dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
  2838. }
  2839. return;
  2840. }
  2841. let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  2842. if (time >= frames[frames.length - TwoColorTimeline.ENTRIES]) { // Time is after last frame.
  2843. let i = frames.length;
  2844. r = frames[i + TwoColorTimeline.PREV_R];
  2845. g = frames[i + TwoColorTimeline.PREV_G];
  2846. b = frames[i + TwoColorTimeline.PREV_B];
  2847. a = frames[i + TwoColorTimeline.PREV_A];
  2848. r2 = frames[i + TwoColorTimeline.PREV_R2];
  2849. g2 = frames[i + TwoColorTimeline.PREV_G2];
  2850. b2 = frames[i + TwoColorTimeline.PREV_B2];
  2851. } else {
  2852. // Interpolate between the previous frame and the current frame.
  2853. let frame = Animation.binarySearch(frames, time, TwoColorTimeline.ENTRIES);
  2854. r = frames[frame + TwoColorTimeline.PREV_R];
  2855. g = frames[frame + TwoColorTimeline.PREV_G];
  2856. b = frames[frame + TwoColorTimeline.PREV_B];
  2857. a = frames[frame + TwoColorTimeline.PREV_A];
  2858. r2 = frames[frame + TwoColorTimeline.PREV_R2];
  2859. g2 = frames[frame + TwoColorTimeline.PREV_G2];
  2860. b2 = frames[frame + TwoColorTimeline.PREV_B2];
  2861. let frameTime = frames[frame];
  2862. let percent = this.getCurvePercent(frame / TwoColorTimeline.ENTRIES - 1,
  2863. 1 - (time - frameTime) / (frames[frame + TwoColorTimeline.PREV_TIME] - frameTime));
  2864. r += (frames[frame + TwoColorTimeline.R] - r) * percent;
  2865. g += (frames[frame + TwoColorTimeline.G] - g) * percent;
  2866. b += (frames[frame + TwoColorTimeline.B] - b) * percent;
  2867. a += (frames[frame + TwoColorTimeline.A] - a) * percent;
  2868. r2 += (frames[frame + TwoColorTimeline.R2] - r2) * percent;
  2869. g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
  2870. b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
  2871. }
  2872. if (alpha == 1) {
  2873. slot.color.set(r, g, b, a);
  2874. slot.darkColor.set(r2, g2, b2, 1);
  2875. } else {
  2876. let light = slot.color, dark = slot.darkColor;
  2877. if (blend == MixBlend.setup) {
  2878. light.setFromColor(slot.data.color);
  2879. dark.setFromColor(slot.data.darkColor);
  2880. }
  2881. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  2882. dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
  2883. }
  2884. }
  2885. } TwoColorTimeline.__initStatic25(); TwoColorTimeline.__initStatic26(); TwoColorTimeline.__initStatic27(); TwoColorTimeline.__initStatic28(); TwoColorTimeline.__initStatic29(); TwoColorTimeline.__initStatic30(); TwoColorTimeline.__initStatic31(); TwoColorTimeline.__initStatic32(); TwoColorTimeline.__initStatic33(); TwoColorTimeline.__initStatic34(); TwoColorTimeline.__initStatic35(); TwoColorTimeline.__initStatic36(); TwoColorTimeline.__initStatic37(); TwoColorTimeline.__initStatic38(); TwoColorTimeline.__initStatic39(); TwoColorTimeline.__initStatic40();
  2886. /** Changes a slot's {@link Slot#attachment}. */
  2887. /**
  2888. * @public
  2889. */
  2890. class AttachmentTimeline {
  2891. /** The index of the slot in {@link Skeleton#slots} that will be changed. */
  2892. /** The time in seconds for each key frame. */
  2893. // time, ...
  2894. /** The attachment name for each key frame. May contain null values to clear the attachment. */
  2895. constructor (frameCount) {
  2896. this.frames = Utils.newFloatArray(frameCount);
  2897. this.attachmentNames = new Array(frameCount);
  2898. }
  2899. getPropertyId () {
  2900. return (TimelineType.attachment << 24) + this.slotIndex;
  2901. }
  2902. /** The number of key frames for this timeline. */
  2903. getFrameCount () {
  2904. return this.frames.length;
  2905. }
  2906. /** Sets the time in seconds and the attachment name for the specified key frame. */
  2907. setFrame (frameIndex, time, attachmentName) {
  2908. this.frames[frameIndex] = time;
  2909. this.attachmentNames[frameIndex] = attachmentName;
  2910. }
  2911. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  2912. let slot = skeleton.slots[this.slotIndex];
  2913. if (!slot.bone.active) return;
  2914. if (direction == MixDirection.mixOut) {
  2915. if (blend == MixBlend.setup)
  2916. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  2917. return;
  2918. }
  2919. let frames = this.frames;
  2920. if (time < frames[0]) {
  2921. if (blend == MixBlend.setup || blend == MixBlend.first) this.setAttachment(skeleton, slot, slot.data.attachmentName);
  2922. return;
  2923. }
  2924. let frameIndex = 0;
  2925. if (time >= frames[frames.length - 1]) // Time is after last frame.
  2926. frameIndex = frames.length - 1;
  2927. else
  2928. frameIndex = Animation.binarySearch(frames, time, 1) - 1;
  2929. let attachmentName = this.attachmentNames[frameIndex];
  2930. skeleton.slots[this.slotIndex]
  2931. .setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  2932. }
  2933. setAttachment(skeleton, slot, attachmentName) {
  2934. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  2935. }
  2936. }
  2937. let zeros = null;
  2938. /** Changes a slot's {@link Slot#deform} to deform a {@link VertexAttachment}. */
  2939. /**
  2940. * @public
  2941. */
  2942. class DeformTimeline extends CurveTimeline {
  2943. /** The index of the slot in {@link Skeleton#getSlots()} that will be changed. */
  2944. /** The attachment that will be deformed. */
  2945. /** The time in seconds for each key frame. */
  2946. // time, ...
  2947. /** The vertices for each key frame. */
  2948. constructor (frameCount) {
  2949. super(frameCount);
  2950. this.frames = Utils.newFloatArray(frameCount);
  2951. this.frameVertices = new Array(frameCount);
  2952. if (zeros == null) zeros = Utils.newFloatArray(64);
  2953. }
  2954. getPropertyId () {
  2955. return (TimelineType.deform << 27) + + this.attachment.id + this.slotIndex;
  2956. }
  2957. /** Sets the time in seconds and the vertices for the specified key frame.
  2958. * @param vertices Vertex positions for an unweighted VertexAttachment, or deform offsets if it has weights. */
  2959. setFrame (frameIndex, time, vertices) {
  2960. this.frames[frameIndex] = time;
  2961. this.frameVertices[frameIndex] = vertices;
  2962. }
  2963. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  2964. let slot = skeleton.slots[this.slotIndex];
  2965. if (!slot.bone.active) return;
  2966. let slotAttachment = slot.getAttachment();
  2967. if (!(slotAttachment instanceof VertexAttachment) || !((slotAttachment).deformAttachment == this.attachment)) return;
  2968. let deformArray = slot.deform;
  2969. if (deformArray.length == 0) blend = MixBlend.setup;
  2970. let frameVertices = this.frameVertices;
  2971. let vertexCount = frameVertices[0].length;
  2972. let frames = this.frames;
  2973. if (time < frames[0]) {
  2974. let vertexAttachment = slotAttachment;
  2975. switch (blend) {
  2976. case MixBlend.setup:
  2977. deformArray.length = 0;
  2978. return;
  2979. case MixBlend.first:
  2980. if (alpha == 1) {
  2981. deformArray.length = 0;
  2982. break;
  2983. }
  2984. let deform = Utils.setArraySize(deformArray, vertexCount);
  2985. if (vertexAttachment.bones == null) {
  2986. // Unweighted vertex positions.
  2987. let setupVertices = vertexAttachment.vertices;
  2988. for (var i = 0; i < vertexCount; i++)
  2989. deform[i] += (setupVertices[i] - deform[i]) * alpha;
  2990. } else {
  2991. // Weighted deform offsets.
  2992. alpha = 1 - alpha;
  2993. for (var i = 0; i < vertexCount; i++)
  2994. deform[i] *= alpha;
  2995. }
  2996. }
  2997. return;
  2998. }
  2999. let deform = Utils.setArraySize(deformArray, vertexCount);
  3000. if (time >= frames[frames.length - 1]) { // Time is after last frame.
  3001. let lastVertices = frameVertices[frames.length - 1];
  3002. if (alpha == 1) {
  3003. if (blend == MixBlend.add) {
  3004. let vertexAttachment = slotAttachment ;
  3005. if (vertexAttachment.bones == null) {
  3006. // Unweighted vertex positions, with alpha.
  3007. let setupVertices = vertexAttachment.vertices;
  3008. for (let i = 0; i < vertexCount; i++) {
  3009. deform[i] += lastVertices[i] - setupVertices[i];
  3010. }
  3011. } else {
  3012. // Weighted deform offsets, with alpha.
  3013. for (let i = 0; i < vertexCount; i++)
  3014. deform[i] += lastVertices[i];
  3015. }
  3016. } else {
  3017. Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount);
  3018. }
  3019. } else {
  3020. switch (blend) {
  3021. case MixBlend.setup: {
  3022. let vertexAttachment = slotAttachment ;
  3023. if (vertexAttachment.bones == null) {
  3024. // Unweighted vertex positions, with alpha.
  3025. let setupVertices = vertexAttachment.vertices;
  3026. for (let i = 0; i < vertexCount; i++) {
  3027. let setup = setupVertices[i];
  3028. deform[i] = setup + (lastVertices[i] - setup) * alpha;
  3029. }
  3030. } else {
  3031. // Weighted deform offsets, with alpha.
  3032. for (let i = 0; i < vertexCount; i++)
  3033. deform[i] = lastVertices[i] * alpha;
  3034. }
  3035. break;
  3036. }
  3037. case MixBlend.first:
  3038. case MixBlend.replace:
  3039. for (let i = 0; i < vertexCount; i++)
  3040. deform[i] += (lastVertices[i] - deform[i]) * alpha;
  3041. break;
  3042. case MixBlend.add:
  3043. let vertexAttachment = slotAttachment ;
  3044. if (vertexAttachment.bones == null) {
  3045. // Unweighted vertex positions, with alpha.
  3046. let setupVertices = vertexAttachment.vertices;
  3047. for (let i = 0; i < vertexCount; i++) {
  3048. deform[i] += (lastVertices[i] - setupVertices[i]) * alpha;
  3049. }
  3050. } else {
  3051. // Weighted deform offsets, with alpha.
  3052. for (let i = 0; i < vertexCount; i++)
  3053. deform[i] += lastVertices[i] * alpha;
  3054. }
  3055. }
  3056. }
  3057. return;
  3058. }
  3059. // Interpolate between the previous frame and the current frame.
  3060. let frame = Animation.binarySearch(frames, time);
  3061. let prevVertices = frameVertices[frame - 1];
  3062. let nextVertices = frameVertices[frame];
  3063. let frameTime = frames[frame];
  3064. let percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
  3065. if (alpha == 1) {
  3066. if (blend == MixBlend.add) {
  3067. let vertexAttachment = slotAttachment ;
  3068. if (vertexAttachment.bones == null) {
  3069. // Unweighted vertex positions, with alpha.
  3070. let setupVertices = vertexAttachment.vertices;
  3071. for (let i = 0; i < vertexCount; i++) {
  3072. let prev = prevVertices[i];
  3073. deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
  3074. }
  3075. } else {
  3076. // Weighted deform offsets, with alpha.
  3077. for (let i = 0; i < vertexCount; i++) {
  3078. let prev = prevVertices[i];
  3079. deform[i] += prev + (nextVertices[i] - prev) * percent;
  3080. }
  3081. }
  3082. } else {
  3083. for (let i = 0; i < vertexCount; i++) {
  3084. let prev = prevVertices[i];
  3085. deform[i] = prev + (nextVertices[i] - prev) * percent;
  3086. }
  3087. }
  3088. } else {
  3089. switch (blend) {
  3090. case MixBlend.setup: {
  3091. let vertexAttachment = slotAttachment ;
  3092. if (vertexAttachment.bones == null) {
  3093. // Unweighted vertex positions, with alpha.
  3094. let setupVertices = vertexAttachment.vertices;
  3095. for (let i = 0; i < vertexCount; i++) {
  3096. let prev = prevVertices[i], setup = setupVertices[i];
  3097. deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
  3098. }
  3099. } else {
  3100. // Weighted deform offsets, with alpha.
  3101. for (let i = 0; i < vertexCount; i++) {
  3102. let prev = prevVertices[i];
  3103. deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
  3104. }
  3105. }
  3106. break;
  3107. }
  3108. case MixBlend.first:
  3109. case MixBlend.replace:
  3110. for (let i = 0; i < vertexCount; i++) {
  3111. let prev = prevVertices[i];
  3112. deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha;
  3113. }
  3114. break;
  3115. case MixBlend.add:
  3116. let vertexAttachment = slotAttachment ;
  3117. if (vertexAttachment.bones == null) {
  3118. // Unweighted vertex positions, with alpha.
  3119. let setupVertices = vertexAttachment.vertices;
  3120. for (let i = 0; i < vertexCount; i++) {
  3121. let prev = prevVertices[i];
  3122. deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha;
  3123. }
  3124. } else {
  3125. // Weighted deform offsets, with alpha.
  3126. for (let i = 0; i < vertexCount; i++) {
  3127. let prev = prevVertices[i];
  3128. deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
  3129. }
  3130. }
  3131. }
  3132. }
  3133. }
  3134. }
  3135. /** Fires an {@link Event} when specific animation times are reached. */
  3136. /**
  3137. * @public
  3138. */
  3139. class EventTimeline {
  3140. /** The time in seconds for each key frame. */
  3141. // time, ...
  3142. /** The event for each key frame. */
  3143. constructor (frameCount) {
  3144. this.frames = Utils.newFloatArray(frameCount);
  3145. this.events = new Array(frameCount);
  3146. }
  3147. getPropertyId () {
  3148. return TimelineType.event << 24;
  3149. }
  3150. /** The number of key frames for this timeline. */
  3151. getFrameCount () {
  3152. return this.frames.length;
  3153. }
  3154. /** Sets the time in seconds and the event for the specified key frame. */
  3155. setFrame (frameIndex, event) {
  3156. this.frames[frameIndex] = event.time;
  3157. this.events[frameIndex] = event;
  3158. }
  3159. /** Fires events for frames > `lastTime` and <= `time`. */
  3160. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3161. if (firedEvents == null) return;
  3162. let frames = this.frames;
  3163. let frameCount = this.frames.length;
  3164. if (lastTime > time) { // Fire events after last time for looped animations.
  3165. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction);
  3166. lastTime = -1;
  3167. } else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
  3168. return;
  3169. if (time < frames[0]) return; // Time is before first frame.
  3170. let frame = 0;
  3171. if (lastTime < frames[0])
  3172. frame = 0;
  3173. else {
  3174. frame = Animation.binarySearch(frames, lastTime);
  3175. let frameTime = frames[frame];
  3176. while (frame > 0) { // Fire multiple events with the same frame.
  3177. if (frames[frame - 1] != frameTime) break;
  3178. frame--;
  3179. }
  3180. }
  3181. for (; frame < frameCount && time >= frames[frame]; frame++)
  3182. firedEvents.push(this.events[frame]);
  3183. }
  3184. }
  3185. /** Changes a skeleton's {@link Skeleton#drawOrder}. */
  3186. /**
  3187. * @public
  3188. */
  3189. class DrawOrderTimeline {
  3190. /** The time in seconds for each key frame. */
  3191. // time, ...
  3192. /** The draw order for each key frame. See {@link #setFrame(int, float, int[])}. */
  3193. constructor (frameCount) {
  3194. this.frames = Utils.newFloatArray(frameCount);
  3195. this.drawOrders = new Array(frameCount);
  3196. }
  3197. getPropertyId () {
  3198. return TimelineType.drawOrder << 24;
  3199. }
  3200. /** The number of key frames for this timeline. */
  3201. getFrameCount () {
  3202. return this.frames.length;
  3203. }
  3204. /** Sets the time in seconds and the draw order for the specified key frame.
  3205. * @param drawOrder For each slot in {@link Skeleton#slots}, the index of the new draw order. May be null to use setup pose
  3206. * draw order. */
  3207. setFrame (frameIndex, time, drawOrder) {
  3208. this.frames[frameIndex] = time;
  3209. this.drawOrders[frameIndex] = drawOrder;
  3210. }
  3211. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3212. let drawOrder = skeleton.drawOrder;
  3213. let slots = skeleton.slots;
  3214. if (direction == MixDirection.mixOut && blend == MixBlend.setup) {
  3215. Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  3216. return;
  3217. }
  3218. let frames = this.frames;
  3219. if (time < frames[0]) {
  3220. if (blend == MixBlend.setup || blend == MixBlend.first) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  3221. return;
  3222. }
  3223. let frame = 0;
  3224. if (time >= frames[frames.length - 1]) // Time is after last frame.
  3225. frame = frames.length - 1;
  3226. else
  3227. frame = Animation.binarySearch(frames, time) - 1;
  3228. let drawOrderToSetupIndex = this.drawOrders[frame];
  3229. if (drawOrderToSetupIndex == null)
  3230. Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  3231. else {
  3232. for (let i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  3233. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  3234. }
  3235. }
  3236. }
  3237. /** Changes an IK constraint's {@link IkConstraint#mix}, {@link IkConstraint#softness},
  3238. * {@link IkConstraint#bendDirection}, {@link IkConstraint#stretch}, and {@link IkConstraint#compress}. */
  3239. /**
  3240. * @public
  3241. */
  3242. class IkConstraintTimeline extends CurveTimeline {
  3243. static __initStatic41() {this.ENTRIES = 6;}
  3244. static __initStatic42() {this.PREV_TIME = -6;} static __initStatic43() {this.PREV_MIX = -5;} static __initStatic44() {this.PREV_SOFTNESS = -4;} static __initStatic45() {this.PREV_BEND_DIRECTION = -3;} static __initStatic46() {this.PREV_COMPRESS = -2;} static __initStatic47() {this.PREV_STRETCH = -1;}
  3245. static __initStatic48() {this.MIX = 1;} static __initStatic49() {this.SOFTNESS = 2;} static __initStatic50() {this.BEND_DIRECTION = 3;} static __initStatic51() {this.COMPRESS = 4;} static __initStatic52() {this.STRETCH = 5;}
  3246. /** The index of the IK constraint slot in {@link Skeleton#ikConstraints} that will be changed. */
  3247. /** The time in seconds, mix, softness, bend direction, compress, and stretch for each key frame. */
  3248. // time, mix, softness, bendDirection, compress, stretch, ...
  3249. constructor (frameCount) {
  3250. super(frameCount);
  3251. this.frames = Utils.newFloatArray(frameCount * IkConstraintTimeline.ENTRIES);
  3252. }
  3253. getPropertyId () {
  3254. return (TimelineType.ikConstraint << 24) + this.ikConstraintIndex;
  3255. }
  3256. /** Sets the time in seconds, mix, softness, bend direction, compress, and stretch for the specified key frame. */
  3257. setFrame (frameIndex, time, mix, softness, bendDirection, compress, stretch) {
  3258. frameIndex *= IkConstraintTimeline.ENTRIES;
  3259. this.frames[frameIndex] = time;
  3260. this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
  3261. this.frames[frameIndex + IkConstraintTimeline.SOFTNESS] = softness;
  3262. this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
  3263. this.frames[frameIndex + IkConstraintTimeline.COMPRESS] = compress ? 1 : 0;
  3264. this.frames[frameIndex + IkConstraintTimeline.STRETCH] = stretch ? 1 : 0;
  3265. }
  3266. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3267. let frames = this.frames;
  3268. let constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  3269. if (!constraint.active) return;
  3270. if (time < frames[0]) {
  3271. switch (blend) {
  3272. case MixBlend.setup:
  3273. constraint.mix = constraint.data.mix;
  3274. constraint.softness = constraint.data.softness;
  3275. constraint.bendDirection = constraint.data.bendDirection;
  3276. constraint.compress = constraint.data.compress;
  3277. constraint.stretch = constraint.data.stretch;
  3278. return;
  3279. case MixBlend.first:
  3280. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  3281. constraint.softness += (constraint.data.softness - constraint.softness) * alpha;
  3282. constraint.bendDirection = constraint.data.bendDirection;
  3283. constraint.compress = constraint.data.compress;
  3284. constraint.stretch = constraint.data.stretch;
  3285. }
  3286. return;
  3287. }
  3288. if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) { // Time is after last frame.
  3289. if (blend == MixBlend.setup) {
  3290. constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
  3291. constraint.softness = constraint.data.softness
  3292. + (frames[frames.length + IkConstraintTimeline.PREV_SOFTNESS] - constraint.data.softness) * alpha;
  3293. if (direction == MixDirection.mixOut) {
  3294. constraint.bendDirection = constraint.data.bendDirection;
  3295. constraint.compress = constraint.data.compress;
  3296. constraint.stretch = constraint.data.stretch;
  3297. } else {
  3298. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  3299. constraint.compress = frames[frames.length + IkConstraintTimeline.PREV_COMPRESS] != 0;
  3300. constraint.stretch = frames[frames.length + IkConstraintTimeline.PREV_STRETCH] != 0;
  3301. }
  3302. } else {
  3303. constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
  3304. constraint.softness += (frames[frames.length + IkConstraintTimeline.PREV_SOFTNESS] - constraint.softness) * alpha;
  3305. if (direction == MixDirection.mixIn) {
  3306. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  3307. constraint.compress = frames[frames.length + IkConstraintTimeline.PREV_COMPRESS] != 0;
  3308. constraint.stretch = frames[frames.length + IkConstraintTimeline.PREV_STRETCH] != 0;
  3309. }
  3310. }
  3311. return;
  3312. }
  3313. // Interpolate between the previous frame and the current frame.
  3314. let frame = Animation.binarySearch(frames, time, IkConstraintTimeline.ENTRIES);
  3315. let mix = frames[frame + IkConstraintTimeline.PREV_MIX];
  3316. let softness = frames[frame + IkConstraintTimeline.PREV_SOFTNESS];
  3317. let frameTime = frames[frame];
  3318. let percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1,
  3319. 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
  3320. if (blend == MixBlend.setup) {
  3321. constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha;
  3322. constraint.softness = constraint.data.softness
  3323. + (softness + (frames[frame + IkConstraintTimeline.SOFTNESS] - softness) * percent - constraint.data.softness) * alpha;
  3324. if (direction == MixDirection.mixOut) {
  3325. constraint.bendDirection = constraint.data.bendDirection;
  3326. constraint.compress = constraint.data.compress;
  3327. constraint.stretch = constraint.data.stretch;
  3328. } else {
  3329. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  3330. constraint.compress = frames[frame + IkConstraintTimeline.PREV_COMPRESS] != 0;
  3331. constraint.stretch = frames[frame + IkConstraintTimeline.PREV_STRETCH] != 0;
  3332. }
  3333. } else {
  3334. constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
  3335. constraint.softness += (softness + (frames[frame + IkConstraintTimeline.SOFTNESS] - softness) * percent - constraint.softness) * alpha;
  3336. if (direction == MixDirection.mixIn) {
  3337. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  3338. constraint.compress = frames[frame + IkConstraintTimeline.PREV_COMPRESS] != 0;
  3339. constraint.stretch = frames[frame + IkConstraintTimeline.PREV_STRETCH] != 0;
  3340. }
  3341. }
  3342. }
  3343. } IkConstraintTimeline.__initStatic41(); IkConstraintTimeline.__initStatic42(); IkConstraintTimeline.__initStatic43(); IkConstraintTimeline.__initStatic44(); IkConstraintTimeline.__initStatic45(); IkConstraintTimeline.__initStatic46(); IkConstraintTimeline.__initStatic47(); IkConstraintTimeline.__initStatic48(); IkConstraintTimeline.__initStatic49(); IkConstraintTimeline.__initStatic50(); IkConstraintTimeline.__initStatic51(); IkConstraintTimeline.__initStatic52();
  3344. /** Changes a transform constraint's {@link TransformConstraint#rotateMix}, {@link TransformConstraint#translateMix},
  3345. * {@link TransformConstraint#scaleMix}, and {@link TransformConstraint#shearMix}. */
  3346. /**
  3347. * @public
  3348. */
  3349. class TransformConstraintTimeline extends CurveTimeline {
  3350. static __initStatic53() {this.ENTRIES = 5;}
  3351. static __initStatic54() {this.PREV_TIME = -5;} static __initStatic55() {this.PREV_ROTATE = -4;} static __initStatic56() {this.PREV_TRANSLATE = -3;} static __initStatic57() {this.PREV_SCALE = -2;} static __initStatic58() {this.PREV_SHEAR = -1;}
  3352. static __initStatic59() {this.ROTATE = 1;} static __initStatic60() {this.TRANSLATE = 2;} static __initStatic61() {this.SCALE = 3;} static __initStatic62() {this.SHEAR = 4;}
  3353. /** The index of the transform constraint slot in {@link Skeleton#transformConstraints} that will be changed. */
  3354. /** The time in seconds, rotate mix, translate mix, scale mix, and shear mix for each key frame. */
  3355. // time, rotate mix, translate mix, scale mix, shear mix, ...
  3356. constructor (frameCount) {
  3357. super(frameCount);
  3358. this.frames = Utils.newFloatArray(frameCount * TransformConstraintTimeline.ENTRIES);
  3359. }
  3360. getPropertyId () {
  3361. return (TimelineType.transformConstraint << 24) + this.transformConstraintIndex;
  3362. }
  3363. /** The time in seconds, rotate mix, translate mix, scale mix, and shear mix for the specified key frame. */
  3364. setFrame (frameIndex, time, rotateMix, translateMix, scaleMix, shearMix) {
  3365. frameIndex *= TransformConstraintTimeline.ENTRIES;
  3366. this.frames[frameIndex] = time;
  3367. this.frames[frameIndex + TransformConstraintTimeline.ROTATE] = rotateMix;
  3368. this.frames[frameIndex + TransformConstraintTimeline.TRANSLATE] = translateMix;
  3369. this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
  3370. this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
  3371. }
  3372. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3373. let frames = this.frames;
  3374. let constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  3375. if (!constraint.active) return;
  3376. if (time < frames[0]) {
  3377. let data = constraint.data;
  3378. switch (blend) {
  3379. case MixBlend.setup:
  3380. constraint.rotateMix = data.rotateMix;
  3381. constraint.translateMix = data.translateMix;
  3382. constraint.scaleMix = data.scaleMix;
  3383. constraint.shearMix = data.shearMix;
  3384. return;
  3385. case MixBlend.first:
  3386. constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
  3387. constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
  3388. constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
  3389. constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
  3390. }
  3391. return;
  3392. }
  3393. let rotate = 0, translate = 0, scale = 0, shear = 0;
  3394. if (time >= frames[frames.length - TransformConstraintTimeline.ENTRIES]) { // Time is after last frame.
  3395. let i = frames.length;
  3396. rotate = frames[i + TransformConstraintTimeline.PREV_ROTATE];
  3397. translate = frames[i + TransformConstraintTimeline.PREV_TRANSLATE];
  3398. scale = frames[i + TransformConstraintTimeline.PREV_SCALE];
  3399. shear = frames[i + TransformConstraintTimeline.PREV_SHEAR];
  3400. } else {
  3401. // Interpolate between the previous frame and the current frame.
  3402. let frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
  3403. rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
  3404. translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
  3405. scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
  3406. shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
  3407. let frameTime = frames[frame];
  3408. let percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1,
  3409. 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
  3410. rotate += (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent;
  3411. translate += (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent;
  3412. scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
  3413. shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
  3414. }
  3415. if (blend == MixBlend.setup) {
  3416. let data = constraint.data;
  3417. constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
  3418. constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
  3419. constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
  3420. constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
  3421. } else {
  3422. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  3423. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  3424. constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
  3425. constraint.shearMix += (shear - constraint.shearMix) * alpha;
  3426. }
  3427. }
  3428. } TransformConstraintTimeline.__initStatic53(); TransformConstraintTimeline.__initStatic54(); TransformConstraintTimeline.__initStatic55(); TransformConstraintTimeline.__initStatic56(); TransformConstraintTimeline.__initStatic57(); TransformConstraintTimeline.__initStatic58(); TransformConstraintTimeline.__initStatic59(); TransformConstraintTimeline.__initStatic60(); TransformConstraintTimeline.__initStatic61(); TransformConstraintTimeline.__initStatic62();
  3429. /** Changes a path constraint's {@link PathConstraint#position}. */
  3430. /**
  3431. * @public
  3432. */
  3433. class PathConstraintPositionTimeline extends CurveTimeline {
  3434. static __initStatic63() {this.ENTRIES = 2;}
  3435. static __initStatic64() {this.PREV_TIME = -2;} static __initStatic65() {this.PREV_VALUE = -1;}
  3436. static __initStatic66() {this.VALUE = 1;}
  3437. /** The index of the path constraint slot in {@link Skeleton#pathConstraints} that will be changed. */
  3438. /** The time in seconds and path constraint position for each key frame. */
  3439. // time, position, ...
  3440. constructor (frameCount) {
  3441. super(frameCount);
  3442. this.frames = Utils.newFloatArray(frameCount * PathConstraintPositionTimeline.ENTRIES);
  3443. }
  3444. getPropertyId () {
  3445. return (TimelineType.pathConstraintPosition << 24) + this.pathConstraintIndex;
  3446. }
  3447. /** Sets the time in seconds and path constraint position for the specified key frame. */
  3448. setFrame (frameIndex, time, value) {
  3449. frameIndex *= PathConstraintPositionTimeline.ENTRIES;
  3450. this.frames[frameIndex] = time;
  3451. this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
  3452. }
  3453. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3454. let frames = this.frames;
  3455. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  3456. if (!constraint.active) return;
  3457. if (time < frames[0]) {
  3458. switch (blend) {
  3459. case MixBlend.setup:
  3460. constraint.position = constraint.data.position;
  3461. return;
  3462. case MixBlend.first:
  3463. constraint.position += (constraint.data.position - constraint.position) * alpha;
  3464. }
  3465. return;
  3466. }
  3467. let position = 0;
  3468. if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES]) // Time is after last frame.
  3469. position = frames[frames.length + PathConstraintPositionTimeline.PREV_VALUE];
  3470. else {
  3471. // Interpolate between the previous frame and the current frame.
  3472. let frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
  3473. position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
  3474. let frameTime = frames[frame];
  3475. let percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1,
  3476. 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
  3477. position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
  3478. }
  3479. if (blend == MixBlend.setup)
  3480. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  3481. else
  3482. constraint.position += (position - constraint.position) * alpha;
  3483. }
  3484. } PathConstraintPositionTimeline.__initStatic63(); PathConstraintPositionTimeline.__initStatic64(); PathConstraintPositionTimeline.__initStatic65(); PathConstraintPositionTimeline.__initStatic66();
  3485. /** Changes a path constraint's {@link PathConstraint#spacing}. */
  3486. /**
  3487. * @public
  3488. */
  3489. class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
  3490. constructor (frameCount) {
  3491. super(frameCount);
  3492. }
  3493. getPropertyId () {
  3494. return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
  3495. }
  3496. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3497. let frames = this.frames;
  3498. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  3499. if (!constraint.active) return;
  3500. if (time < frames[0]) {
  3501. switch (blend) {
  3502. case MixBlend.setup:
  3503. constraint.spacing = constraint.data.spacing;
  3504. return;
  3505. case MixBlend.first:
  3506. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  3507. }
  3508. return;
  3509. }
  3510. let spacing = 0;
  3511. if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES]) // Time is after last frame.
  3512. spacing = frames[frames.length + PathConstraintSpacingTimeline.PREV_VALUE];
  3513. else {
  3514. // Interpolate between the previous frame and the current frame.
  3515. let frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
  3516. spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
  3517. let frameTime = frames[frame];
  3518. let percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1,
  3519. 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
  3520. spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
  3521. }
  3522. if (blend == MixBlend.setup)
  3523. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  3524. else
  3525. constraint.spacing += (spacing - constraint.spacing) * alpha;
  3526. }
  3527. }
  3528. /** Changes a transform constraint's {@link PathConstraint#rotateMix} and
  3529. * {@link TransformConstraint#translateMix}. */
  3530. /**
  3531. * @public
  3532. */
  3533. class PathConstraintMixTimeline extends CurveTimeline {
  3534. static __initStatic67() {this.ENTRIES = 3;}
  3535. static __initStatic68() {this.PREV_TIME = -3;} static __initStatic69() {this.PREV_ROTATE = -2;} static __initStatic70() {this.PREV_TRANSLATE = -1;}
  3536. static __initStatic71() {this.ROTATE = 1;} static __initStatic72() {this.TRANSLATE = 2;}
  3537. /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */
  3538. /** The time in seconds, rotate mix, and translate mix for each key frame. */
  3539. // time, rotate mix, translate mix, ...
  3540. constructor (frameCount) {
  3541. super(frameCount);
  3542. this.frames = Utils.newFloatArray(frameCount * PathConstraintMixTimeline.ENTRIES);
  3543. }
  3544. getPropertyId () {
  3545. return (TimelineType.pathConstraintMix << 24) + this.pathConstraintIndex;
  3546. }
  3547. /** The time in seconds, rotate mix, and translate mix for the specified key frame. */
  3548. setFrame (frameIndex, time, rotateMix, translateMix) {
  3549. frameIndex *= PathConstraintMixTimeline.ENTRIES;
  3550. this.frames[frameIndex] = time;
  3551. this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
  3552. this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
  3553. }
  3554. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  3555. let frames = this.frames;
  3556. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  3557. if (!constraint.active) return;
  3558. if (time < frames[0]) {
  3559. switch (blend) {
  3560. case MixBlend.setup:
  3561. constraint.rotateMix = constraint.data.rotateMix;
  3562. constraint.translateMix = constraint.data.translateMix;
  3563. return;
  3564. case MixBlend.first:
  3565. constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
  3566. constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
  3567. }
  3568. return;
  3569. }
  3570. let rotate = 0, translate = 0;
  3571. if (time >= frames[frames.length - PathConstraintMixTimeline.ENTRIES]) { // Time is after last frame.
  3572. rotate = frames[frames.length + PathConstraintMixTimeline.PREV_ROTATE];
  3573. translate = frames[frames.length + PathConstraintMixTimeline.PREV_TRANSLATE];
  3574. } else {
  3575. // Interpolate between the previous frame and the current frame.
  3576. let frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
  3577. rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
  3578. translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
  3579. let frameTime = frames[frame];
  3580. let percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1,
  3581. 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
  3582. rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
  3583. translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
  3584. }
  3585. if (blend == MixBlend.setup) {
  3586. constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
  3587. constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
  3588. } else {
  3589. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  3590. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  3591. }
  3592. }
  3593. } PathConstraintMixTimeline.__initStatic67(); PathConstraintMixTimeline.__initStatic68(); PathConstraintMixTimeline.__initStatic69(); PathConstraintMixTimeline.__initStatic70(); PathConstraintMixTimeline.__initStatic71(); PathConstraintMixTimeline.__initStatic72();
  3594. /** Applies animations over time, queues animations for later playback, mixes (crossfading) between animations, and applies
  3595. * multiple animations on top of each other (layering).
  3596. *
  3597. * See [Applying Animations](http://esotericsoftware.com/spine-applying-animations/) in the Spine Runtimes Guide. */
  3598. /**
  3599. * @public
  3600. */
  3601. class AnimationState {
  3602. static __initStatic() {this.emptyAnimation = new Animation("<empty>", [], 0);}
  3603. /** 1. A previously applied timeline has set this property.
  3604. *
  3605. * Result: Mix from the current pose to the timeline pose. */
  3606. static __initStatic2() {this.SUBSEQUENT = 0;}
  3607. /** 1. This is the first timeline to set this property.
  3608. * 2. The next track entry applied after this one does not have a timeline to set this property.
  3609. *
  3610. * Result: Mix from the setup pose to the timeline pose. */
  3611. static __initStatic3() {this.FIRST = 1;}
  3612. /** 1) A previously applied timeline has set this property.<br>
  3613. * 2) The next track entry to be applied does have a timeline to set this property.<br>
  3614. * 3) The next track entry after that one does not have a timeline to set this property.<br>
  3615. * Result: Mix from the current pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading
  3616. * animations that key the same property. A subsequent timeline will set this property using a mix. */
  3617. static __initStatic4() {this.HOLD_SUBSEQUENT = 2;}
  3618. /** 1) This is the first timeline to set this property.<br>
  3619. * 2) The next track entry to be applied does have a timeline to set this property.<br>
  3620. * 3) The next track entry after that one does not have a timeline to set this property.<br>
  3621. * Result: Mix from the setup pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading animations
  3622. * that key the same property. A subsequent timeline will set this property using a mix. */
  3623. static __initStatic5() {this.HOLD_FIRST = 3;}
  3624. /** 1. This is the first timeline to set this property.
  3625. * 2. The next track entry to be applied does have a timeline to set this property.
  3626. * 3. The next track entry after that one does have a timeline to set this property.
  3627. * 4. timelineHoldMix stores the first subsequent track entry that does not have a timeline to set this property.
  3628. *
  3629. * Result: The same as HOLD except the mix percentage from the timelineHoldMix track entry is used. This handles when more than
  3630. * 2 track entries in a row have a timeline that sets the same property.
  3631. *
  3632. * Eg, A -> B -> C -> D where A, B, and C have a timeline setting same property, but D does not. When A is applied, to avoid
  3633. * "dipping" A is not mixed out, however D (the first entry that doesn't set the property) mixing in is used to mix out A
  3634. * (which affects B and C). Without using D to mix out, A would be applied fully until mixing completes, then snap into
  3635. * place. */
  3636. static __initStatic6() {this.HOLD_MIX = 4;}
  3637. static __initStatic7() {this.SETUP = 1;}
  3638. static __initStatic8() {this.CURRENT = 2;}
  3639. /** The AnimationStateData to look up mix durations. */
  3640. /** The list of tracks that currently have animations, which may contain null entries. */
  3641. __init() {this.tracks = new Array();}
  3642. /** Multiplier for the delta time when the animation state is updated, causing time for all animations and mixes to play slower
  3643. * or faster. Defaults to 1.
  3644. *
  3645. * See TrackEntry {@link TrackEntry#timeScale} for affecting a single animation. */
  3646. __init2() {this.timeScale = 1;}
  3647. __init3() {this.unkeyedState = 0;}
  3648. __init4() {this.events = new Array();}
  3649. __init5() {this.listeners = new Array();}
  3650. __init6() {this.queue = new EventQueue(this);}
  3651. __init7() {this.propertyIDs = new IntSet();}
  3652. __init8() {this.animationsChanged = false;}
  3653. __init9() {this.trackEntryPool = new Pool(() => new TrackEntry());}
  3654. constructor (data) {AnimationState.prototype.__init.call(this);AnimationState.prototype.__init2.call(this);AnimationState.prototype.__init3.call(this);AnimationState.prototype.__init4.call(this);AnimationState.prototype.__init5.call(this);AnimationState.prototype.__init6.call(this);AnimationState.prototype.__init7.call(this);AnimationState.prototype.__init8.call(this);AnimationState.prototype.__init9.call(this);
  3655. this.data = data;
  3656. }
  3657. /** Increments each track entry {@link TrackEntry#trackTime()}, setting queued animations as current if needed. */
  3658. update (delta) {
  3659. delta *= this.timeScale;
  3660. let tracks = this.tracks;
  3661. for (let i = 0, n = tracks.length; i < n; i++) {
  3662. let current = tracks[i];
  3663. if (current == null) continue;
  3664. current.animationLast = current.nextAnimationLast;
  3665. current.trackLast = current.nextTrackLast;
  3666. let currentDelta = delta * current.timeScale;
  3667. if (current.delay > 0) {
  3668. current.delay -= currentDelta;
  3669. if (current.delay > 0) continue;
  3670. currentDelta = -current.delay;
  3671. current.delay = 0;
  3672. }
  3673. let next = current.next;
  3674. if (next != null) {
  3675. // When the next entry's delay is passed, change to the next entry, preserving leftover time.
  3676. let nextTime = current.trackLast - next.delay;
  3677. if (nextTime >= 0) {
  3678. next.delay = 0;
  3679. next.trackTime += current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale;
  3680. current.trackTime += currentDelta;
  3681. this.setCurrent(i, next, true);
  3682. while (next.mixingFrom != null) {
  3683. next.mixTime += delta;
  3684. next = next.mixingFrom;
  3685. }
  3686. continue;
  3687. }
  3688. } else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  3689. tracks[i] = null;
  3690. this.queue.end(current);
  3691. this.disposeNext(current);
  3692. continue;
  3693. }
  3694. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  3695. // End mixing from entries once all have completed.
  3696. let from = current.mixingFrom;
  3697. current.mixingFrom = null;
  3698. if (from != null) from.mixingTo = null;
  3699. while (from != null) {
  3700. this.queue.end(from);
  3701. from = from.mixingFrom;
  3702. }
  3703. }
  3704. current.trackTime += currentDelta;
  3705. }
  3706. this.queue.drain();
  3707. }
  3708. /** Returns true when all mixing from entries are complete. */
  3709. updateMixingFrom (to, delta) {
  3710. let from = to.mixingFrom;
  3711. if (from == null) return true;
  3712. let finished = this.updateMixingFrom(from, delta);
  3713. from.animationLast = from.nextAnimationLast;
  3714. from.trackLast = from.nextTrackLast;
  3715. // Require mixTime > 0 to ensure the mixing from entry was applied at least once.
  3716. if (to.mixTime > 0 && to.mixTime >= to.mixDuration) {
  3717. // Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
  3718. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  3719. to.mixingFrom = from.mixingFrom;
  3720. if (from.mixingFrom != null) from.mixingFrom.mixingTo = to;
  3721. to.interruptAlpha = from.interruptAlpha;
  3722. this.queue.end(from);
  3723. }
  3724. return finished;
  3725. }
  3726. from.trackTime += delta * from.timeScale;
  3727. to.mixTime += delta;
  3728. return false;
  3729. }
  3730. /** Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the
  3731. * animation state can be applied to multiple skeletons to pose them identically.
  3732. * @returns True if any animations were applied. */
  3733. apply (skeleton) {
  3734. if (skeleton == null) throw new Error("skeleton cannot be null.");
  3735. if (this.animationsChanged) this._animationsChanged();
  3736. let events = this.events;
  3737. let tracks = this.tracks;
  3738. let applied = false;
  3739. for (let i = 0, n = tracks.length; i < n; i++) {
  3740. let current = tracks[i];
  3741. if (current == null || current.delay > 0) continue;
  3742. applied = true;
  3743. let blend = i == 0 ? MixBlend.first : current.mixBlend;
  3744. // Apply mixing from entries first.
  3745. let mix = current.alpha;
  3746. if (current.mixingFrom != null)
  3747. mix *= this.applyMixingFrom(current, skeleton, blend);
  3748. else if (current.trackTime >= current.trackEnd && current.next == null)
  3749. mix = 0;
  3750. // Apply current entry.
  3751. let animationLast = current.animationLast, animationTime = current.getAnimationTime();
  3752. let timelineCount = current.animation.timelines.length;
  3753. let timelines = current.animation.timelines;
  3754. if ((i == 0 && mix == 1) || blend == MixBlend.add) {
  3755. for (let ii = 0; ii < timelineCount; ii++) {
  3756. // Fixes issue #302 on IOS9 where mix, blend sometimes became undefined and caused assets
  3757. // to sometimes stop rendering when using color correction, as their RGBA values become NaN.
  3758. // (https://github.com/pixijs/pixi-spine/issues/302)
  3759. Utils.webkit602BugfixHelper(mix, blend);
  3760. var timeline = timelines[ii];
  3761. if (timeline instanceof AttachmentTimeline)
  3762. this.applyAttachmentTimeline(timeline, skeleton, animationTime, blend, true);
  3763. else
  3764. timeline.apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection.mixIn);
  3765. }
  3766. } else {
  3767. let timelineMode = current.timelineMode;
  3768. let firstFrame = current.timelinesRotation.length == 0;
  3769. if (firstFrame) Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  3770. let timelinesRotation = current.timelinesRotation;
  3771. for (let ii = 0; ii < timelineCount; ii++) {
  3772. let timeline = timelines[ii];
  3773. let timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : MixBlend.setup;
  3774. if (timeline instanceof RotateTimeline) {
  3775. this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
  3776. } else if (timeline instanceof AttachmentTimeline) {
  3777. this.applyAttachmentTimeline(timeline, skeleton, animationTime, blend, true);
  3778. } else {
  3779. // This fixes the WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  3780. Utils.webkit602BugfixHelper(mix, blend);
  3781. timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, MixDirection.mixIn);
  3782. }
  3783. }
  3784. }
  3785. this.queueEvents(current, animationTime);
  3786. events.length = 0;
  3787. current.nextAnimationLast = animationTime;
  3788. current.nextTrackLast = current.trackTime;
  3789. }
  3790. // Set slots attachments to the setup pose, if needed. This occurs if an animation that is mixing out sets attachments so
  3791. // subsequent timelines see any deform, but the subsequent timelines don't set an attachment (eg they are also mixing out or
  3792. // the time is before the first key).
  3793. var setupState = this.unkeyedState + AnimationState.SETUP;
  3794. var slots = skeleton.slots;
  3795. for (var i = 0, n = skeleton.slots.length; i < n; i++) {
  3796. var slot = slots[i];
  3797. if (slot.attachmentState == setupState) {
  3798. var attachmentName = slot.data.attachmentName;
  3799. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  3800. }
  3801. }
  3802. this.unkeyedState += 2; // Increasing after each use avoids the need to reset attachmentState for every slot.
  3803. this.queue.drain();
  3804. return applied;
  3805. }
  3806. applyMixingFrom (to, skeleton, blend) {
  3807. let from = to.mixingFrom;
  3808. if (from.mixingFrom != null) this.applyMixingFrom(from, skeleton, blend);
  3809. let mix = 0;
  3810. if (to.mixDuration == 0) { // Single frame mix to undo mixingFrom changes.
  3811. mix = 1;
  3812. if (blend == MixBlend.first) blend = MixBlend.setup;
  3813. } else {
  3814. mix = to.mixTime / to.mixDuration;
  3815. if (mix > 1) mix = 1;
  3816. if (blend != MixBlend.first) blend = from.mixBlend;
  3817. }
  3818. let events = mix < from.eventThreshold ? this.events : null;
  3819. let attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  3820. let animationLast = from.animationLast, animationTime = from.getAnimationTime();
  3821. let timelineCount = from.animation.timelines.length;
  3822. let timelines = from.animation.timelines;
  3823. let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
  3824. if (blend == MixBlend.add) {
  3825. for (let i = 0; i < timelineCount; i++)
  3826. timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection.mixOut);
  3827. } else {
  3828. let timelineMode = from.timelineMode;
  3829. let timelineHoldMix = from.timelineHoldMix;
  3830. let firstFrame = from.timelinesRotation.length == 0;
  3831. if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  3832. let timelinesRotation = from.timelinesRotation;
  3833. from.totalAlpha = 0;
  3834. for (let i = 0; i < timelineCount; i++) {
  3835. let timeline = timelines[i];
  3836. let direction = MixDirection.mixOut;
  3837. let timelineBlend;
  3838. let alpha = 0;
  3839. switch (timelineMode[i]) {
  3840. case AnimationState.SUBSEQUENT:
  3841. if (!drawOrder && timeline instanceof DrawOrderTimeline) continue;
  3842. timelineBlend = blend;
  3843. alpha = alphaMix;
  3844. break;
  3845. case AnimationState.FIRST:
  3846. timelineBlend = MixBlend.setup;
  3847. alpha = alphaMix;
  3848. break;
  3849. case AnimationState.HOLD_SUBSEQUENT:
  3850. timelineBlend = blend;
  3851. alpha = alphaHold;
  3852. break;
  3853. case AnimationState.HOLD_FIRST:
  3854. timelineBlend = MixBlend.setup;
  3855. alpha = alphaHold;
  3856. break;
  3857. default:
  3858. timelineBlend = MixBlend.setup;
  3859. let holdMix = timelineHoldMix[i];
  3860. alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
  3861. break;
  3862. }
  3863. from.totalAlpha += alpha;
  3864. if (timeline instanceof RotateTimeline)
  3865. this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame);
  3866. else if (timeline instanceof AttachmentTimeline)
  3867. this.applyAttachmentTimeline(timeline, skeleton, animationTime, timelineBlend, attachments);
  3868. else {
  3869. // This fixes the WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  3870. Utils.webkit602BugfixHelper(alpha, blend);
  3871. if (drawOrder && timeline instanceof DrawOrderTimeline && timelineBlend == MixBlend.setup)
  3872. direction = MixDirection.mixIn;
  3873. timeline.apply(skeleton, animationLast, animationTime, events, alpha, timelineBlend, direction);
  3874. }
  3875. }
  3876. }
  3877. if (to.mixDuration > 0) this.queueEvents(from, animationTime);
  3878. this.events.length = 0;
  3879. from.nextAnimationLast = animationTime;
  3880. from.nextTrackLast = from.trackTime;
  3881. return mix;
  3882. }
  3883. applyAttachmentTimeline (timeline, skeleton, time, blend, attachments) {
  3884. var slot = skeleton.slots[timeline.slotIndex];
  3885. if (!slot.bone.active) return;
  3886. var frames = timeline.frames;
  3887. if (time < frames[0]) { // Time is before first frame.
  3888. if (blend == MixBlend.setup || blend == MixBlend.first)
  3889. this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments);
  3890. }
  3891. else {
  3892. var frameIndex;
  3893. if (time >= frames[frames.length - 1]) // Time is after last frame.
  3894. frameIndex = frames.length - 1;
  3895. else
  3896. frameIndex = Animation.binarySearch(frames, time) - 1;
  3897. this.setAttachment(skeleton, slot, timeline.attachmentNames[frameIndex], attachments);
  3898. }
  3899. // If an attachment wasn't set (ie before the first frame or attachments is false), set the setup attachment later.
  3900. if (slot.attachmentState <= this.unkeyedState) slot.attachmentState = this.unkeyedState + AnimationState.SETUP;
  3901. }
  3902. setAttachment (skeleton, slot, attachmentName, attachments) {
  3903. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  3904. if (attachments) slot.attachmentState = this.unkeyedState + AnimationState.CURRENT;
  3905. }
  3906. applyRotateTimeline (timeline, skeleton, time, alpha, blend,
  3907. timelinesRotation, i, firstFrame) {
  3908. if (firstFrame) timelinesRotation[i] = 0;
  3909. if (alpha == 1) {
  3910. timeline.apply(skeleton, 0, time, null, 1, blend, MixDirection.mixIn);
  3911. return;
  3912. }
  3913. let rotateTimeline = timeline ;
  3914. let frames = rotateTimeline.frames;
  3915. let bone = skeleton.bones[rotateTimeline.boneIndex];
  3916. if (!bone.active) return;
  3917. let r1 = 0, r2 = 0;
  3918. if (time < frames[0]) {
  3919. switch (blend) {
  3920. case MixBlend.setup:
  3921. bone.rotation = bone.data.rotation;
  3922. default:
  3923. return;
  3924. case MixBlend.first:
  3925. r1 = bone.rotation;
  3926. r2 = bone.data.rotation;
  3927. }
  3928. } else {
  3929. r1 = blend == MixBlend.setup ? bone.data.rotation : bone.rotation;
  3930. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) // Time is after last frame.
  3931. r2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION];
  3932. else {
  3933. // Interpolate between the previous frame and the current frame.
  3934. let frame = Animation.binarySearch(frames, time, RotateTimeline.ENTRIES);
  3935. let prevRotation = frames[frame + RotateTimeline.PREV_ROTATION];
  3936. let frameTime = frames[frame];
  3937. let percent = rotateTimeline.getCurvePercent((frame >> 1) - 1,
  3938. 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
  3939. r2 = frames[frame + RotateTimeline.ROTATION] - prevRotation;
  3940. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  3941. r2 = prevRotation + r2 * percent + bone.data.rotation;
  3942. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  3943. }
  3944. }
  3945. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
  3946. let total = 0, diff = r2 - r1;
  3947. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  3948. if (diff == 0) {
  3949. total = timelinesRotation[i];
  3950. } else {
  3951. let lastTotal = 0, lastDiff = 0;
  3952. if (firstFrame) {
  3953. lastTotal = 0;
  3954. lastDiff = diff;
  3955. } else {
  3956. lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops.
  3957. lastDiff = timelinesRotation[i + 1]; // Difference between bones.
  3958. }
  3959. let current = diff > 0, dir = lastTotal >= 0;
  3960. // Detect cross at 0 (not 180).
  3961. if (MathUtils.signum(lastDiff) != MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  3962. // A cross after a 360 rotation is a loop.
  3963. if (Math.abs(lastTotal) > 180) lastTotal += 360 * MathUtils.signum(lastTotal);
  3964. dir = current;
  3965. }
  3966. total = diff + lastTotal - lastTotal % 360; // Store loops as part of lastTotal.
  3967. if (dir != current) total += 360 * MathUtils.signum(lastTotal);
  3968. timelinesRotation[i] = total;
  3969. }
  3970. timelinesRotation[i + 1] = diff;
  3971. r1 += total * alpha;
  3972. bone.rotation = r1 - (16384 - ((16384.499999999996 - r1 / 360) | 0)) * 360;
  3973. }
  3974. queueEvents (entry, animationTime) {
  3975. let animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  3976. let duration = animationEnd - animationStart;
  3977. let trackLastWrapped = entry.trackLast % duration;
  3978. // Queue events before complete.
  3979. let events = this.events;
  3980. let i = 0, n = events.length;
  3981. for (; i < n; i++) {
  3982. let event = events[i];
  3983. if (event.time < trackLastWrapped) break;
  3984. if (event.time > animationEnd) continue; // Discard events outside animation start/end.
  3985. this.queue.event(entry, event);
  3986. }
  3987. // Queue complete if completed a loop iteration or the animation.
  3988. let complete = false;
  3989. if (entry.loop)
  3990. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  3991. else
  3992. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  3993. if (complete) this.queue.complete(entry);
  3994. // Queue events after complete.
  3995. for (; i < n; i++) {
  3996. let event = events[i];
  3997. if (event.time < animationStart) continue; // Discard events outside animation start/end.
  3998. this.queue.event(entry, events[i]);
  3999. }
  4000. }
  4001. /** Removes all animations from all tracks, leaving skeletons in their current pose.
  4002. *
  4003. * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose,
  4004. * rather than leaving them in their current pose. */
  4005. clearTracks () {
  4006. let oldDrainDisabled = this.queue.drainDisabled;
  4007. this.queue.drainDisabled = true;
  4008. for (let i = 0, n = this.tracks.length; i < n; i++)
  4009. this.clearTrack(i);
  4010. this.tracks.length = 0;
  4011. this.queue.drainDisabled = oldDrainDisabled;
  4012. this.queue.drain();
  4013. }
  4014. /** Removes all animations from the track, leaving skeletons in their current pose.
  4015. *
  4016. * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose,
  4017. * rather than leaving them in their current pose. */
  4018. clearTrack (trackIndex) {
  4019. if (trackIndex >= this.tracks.length) return;
  4020. let current = this.tracks[trackIndex];
  4021. if (current == null) return;
  4022. this.queue.end(current);
  4023. this.disposeNext(current);
  4024. let entry = current;
  4025. while (true) {
  4026. let from = entry.mixingFrom;
  4027. if (from == null) break;
  4028. this.queue.end(from);
  4029. entry.mixingFrom = null;
  4030. entry.mixingTo = null;
  4031. entry = from;
  4032. }
  4033. this.tracks[current.trackIndex] = null;
  4034. this.queue.drain();
  4035. }
  4036. setCurrent (index, current, interrupt) {
  4037. let from = this.expandToIndex(index);
  4038. this.tracks[index] = current;
  4039. if (from != null) {
  4040. if (interrupt) this.queue.interrupt(from);
  4041. current.mixingFrom = from;
  4042. from.mixingTo = current;
  4043. current.mixTime = 0;
  4044. // Store the interrupted mix percentage.
  4045. if (from.mixingFrom != null && from.mixDuration > 0)
  4046. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  4047. from.timelinesRotation.length = 0; // Reset rotation for mixing out, in case entry was mixed in.
  4048. }
  4049. this.queue.start(current);
  4050. }
  4051. /** Sets an animation by name.
  4052. *
  4053. * {@link #setAnimationWith(}. */
  4054. setAnimation (trackIndex, animationName, loop) {
  4055. let animation = this.data.skeletonData.findAnimation(animationName);
  4056. if (animation == null) throw new Error("Animation not found: " + animationName);
  4057. return this.setAnimationWith(trackIndex, animation, loop);
  4058. }
  4059. /** Sets the current animation for a track, discarding any queued animations. If the formerly current track entry was never
  4060. * applied to a skeleton, it is replaced (not mixed from).
  4061. * @param loop If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
  4062. * duration. In either case {@link TrackEntry#trackEnd} determines when the track is cleared.
  4063. * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept
  4064. * after the {@link AnimationStateListener#dispose()} event occurs. */
  4065. setAnimationWith (trackIndex, animation, loop) {
  4066. if (animation == null) throw new Error("animation cannot be null.");
  4067. let interrupt = true;
  4068. let current = this.expandToIndex(trackIndex);
  4069. if (current != null) {
  4070. if (current.nextTrackLast == -1) {
  4071. // Don't mix from an entry that was never applied.
  4072. this.tracks[trackIndex] = current.mixingFrom;
  4073. this.queue.interrupt(current);
  4074. this.queue.end(current);
  4075. this.disposeNext(current);
  4076. current = current.mixingFrom;
  4077. interrupt = false;
  4078. } else
  4079. this.disposeNext(current);
  4080. }
  4081. let entry = this.trackEntry(trackIndex, animation, loop, current);
  4082. this.setCurrent(trackIndex, entry, interrupt);
  4083. this.queue.drain();
  4084. return entry;
  4085. }
  4086. /** Queues an animation by name.
  4087. *
  4088. * See {@link #addAnimationWith()}. */
  4089. addAnimation (trackIndex, animationName, loop, delay) {
  4090. let animation = this.data.skeletonData.findAnimation(animationName);
  4091. if (animation == null) throw new Error("Animation not found: " + animationName);
  4092. return this.addAnimationWith(trackIndex, animation, loop, delay);
  4093. }
  4094. /** Adds an animation to be played after the current or last queued animation for a track. If the track is empty, it is
  4095. * equivalent to calling {@link #setAnimationWith()}.
  4096. * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry
  4097. * minus any mix duration (from the {@link AnimationStateData}) plus the specified `delay` (ie the mix
  4098. * ends at (`delay` = 0) or before (`delay` < 0) the previous track entry duration). If the
  4099. * previous entry is looping, its next loop completion is used instead of its duration.
  4100. * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept
  4101. * after the {@link AnimationStateListener#dispose()} event occurs. */
  4102. addAnimationWith (trackIndex, animation, loop, delay) {
  4103. if (animation == null) throw new Error("animation cannot be null.");
  4104. let last = this.expandToIndex(trackIndex);
  4105. if (last != null) {
  4106. while (last.next != null)
  4107. last = last.next;
  4108. }
  4109. let entry = this.trackEntry(trackIndex, animation, loop, last);
  4110. if (last == null) {
  4111. this.setCurrent(trackIndex, entry, true);
  4112. this.queue.drain();
  4113. } else {
  4114. last.next = entry;
  4115. if (delay <= 0) {
  4116. let duration = last.animationEnd - last.animationStart;
  4117. if (duration != 0) {
  4118. if (last.loop)
  4119. delay += duration * (1 + ((last.trackTime / duration) | 0));
  4120. else
  4121. delay += Math.max(duration, last.trackTime);
  4122. delay -= this.data.getMix(last.animation, animation);
  4123. } else
  4124. delay = last.trackTime;
  4125. }
  4126. }
  4127. entry.delay = delay;
  4128. return entry;
  4129. }
  4130. /** Sets an empty animation for a track, discarding any queued animations, and sets the track entry's
  4131. * {@link TrackEntry#mixduration}. An empty animation has no timelines and serves as a placeholder for mixing in or out.
  4132. *
  4133. * Mixing out is done by setting an empty animation with a mix duration using either {@link #setEmptyAnimation()},
  4134. * {@link #setEmptyAnimations()}, or {@link #addEmptyAnimation()}. Mixing to an empty animation causes
  4135. * the previous animation to be applied less and less over the mix duration. Properties keyed in the previous animation
  4136. * transition to the value from lower tracks or to the setup pose value if no lower tracks key the property. A mix duration of
  4137. * 0 still mixes out over one frame.
  4138. *
  4139. * Mixing in is done by first setting an empty animation, then adding an animation using
  4140. * {@link #addAnimation()} and on the returned track entry, set the
  4141. * {@link TrackEntry#setMixDuration()}. Mixing from an empty animation causes the new animation to be applied more and
  4142. * more over the mix duration. Properties keyed in the new animation transition from the value from lower tracks or from the
  4143. * setup pose value if no lower tracks key the property to the value keyed in the new animation. */
  4144. setEmptyAnimation (trackIndex, mixDuration) {
  4145. let entry = this.setAnimationWith(trackIndex, AnimationState.emptyAnimation, false);
  4146. entry.mixDuration = mixDuration;
  4147. entry.trackEnd = mixDuration;
  4148. return entry;
  4149. }
  4150. /** Adds an empty animation to be played after the current or last queued animation for a track, and sets the track entry's
  4151. * {@link TrackEntry#mixDuration}. If the track is empty, it is equivalent to calling
  4152. * {@link #setEmptyAnimation()}.
  4153. *
  4154. * See {@link #setEmptyAnimation()}.
  4155. * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry
  4156. * minus any mix duration plus the specified `delay` (ie the mix ends at (`delay` = 0) or
  4157. * before (`delay` < 0) the previous track entry duration). If the previous entry is looping, its next
  4158. * loop completion is used instead of its duration.
  4159. * @return A track entry to allow further customization of animation playback. References to the track entry must not be kept
  4160. * after the {@link AnimationStateListener#dispose()} event occurs. */
  4161. addEmptyAnimation (trackIndex, mixDuration, delay) {
  4162. if (delay <= 0) delay -= mixDuration;
  4163. let entry = this.addAnimationWith(trackIndex, AnimationState.emptyAnimation, false, delay);
  4164. entry.mixDuration = mixDuration;
  4165. entry.trackEnd = mixDuration;
  4166. return entry;
  4167. }
  4168. /** Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix
  4169. * duration. */
  4170. setEmptyAnimations (mixDuration) {
  4171. let oldDrainDisabled = this.queue.drainDisabled;
  4172. this.queue.drainDisabled = true;
  4173. for (let i = 0, n = this.tracks.length; i < n; i++) {
  4174. let current = this.tracks[i];
  4175. if (current != null) this.setEmptyAnimation(current.trackIndex, mixDuration);
  4176. }
  4177. this.queue.drainDisabled = oldDrainDisabled;
  4178. this.queue.drain();
  4179. }
  4180. expandToIndex (index) {
  4181. if (index < this.tracks.length) return this.tracks[index];
  4182. Utils.ensureArrayCapacity(this.tracks, index + 1, null);
  4183. this.tracks.length = index + 1;
  4184. return null;
  4185. }
  4186. /** @param last May be null. */
  4187. trackEntry (trackIndex, animation, loop, last) {
  4188. let entry = this.trackEntryPool.obtain();
  4189. entry.trackIndex = trackIndex;
  4190. entry.animation = animation;
  4191. entry.loop = loop;
  4192. entry.holdPrevious = false;
  4193. entry.eventThreshold = 0;
  4194. entry.attachmentThreshold = 0;
  4195. entry.drawOrderThreshold = 0;
  4196. entry.animationStart = 0;
  4197. entry.animationEnd = animation.duration;
  4198. entry.animationLast = -1;
  4199. entry.nextAnimationLast = -1;
  4200. entry.delay = 0;
  4201. entry.trackTime = 0;
  4202. entry.trackLast = -1;
  4203. entry.nextTrackLast = -1;
  4204. entry.trackEnd = Number.MAX_VALUE;
  4205. entry.timeScale = 1;
  4206. entry.alpha = 1;
  4207. entry.interruptAlpha = 1;
  4208. entry.mixTime = 0;
  4209. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  4210. entry.mixBlend = MixBlend.replace;
  4211. return entry;
  4212. }
  4213. disposeNext (entry) {
  4214. let next = entry.next;
  4215. while (next != null) {
  4216. this.queue.dispose(next);
  4217. next = next.next;
  4218. }
  4219. entry.next = null;
  4220. }
  4221. _animationsChanged () {
  4222. this.animationsChanged = false;
  4223. this.propertyIDs.clear();
  4224. for (let i = 0, n = this.tracks.length; i < n; i++) {
  4225. let entry = this.tracks[i];
  4226. if (entry == null) continue;
  4227. while (entry.mixingFrom != null)
  4228. entry = entry.mixingFrom;
  4229. do {
  4230. if (entry.mixingFrom == null || entry.mixBlend != MixBlend.add) this.computeHold(entry);
  4231. entry = entry.mixingTo;
  4232. } while (entry != null)
  4233. }
  4234. }
  4235. computeHold (entry) {
  4236. let to = entry.mixingTo;
  4237. let timelines = entry.animation.timelines;
  4238. let timelinesCount = entry.animation.timelines.length;
  4239. let timelineMode = Utils.setArraySize(entry.timelineMode, timelinesCount);
  4240. entry.timelineHoldMix.length = 0;
  4241. let timelineDipMix = Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
  4242. let propertyIDs = this.propertyIDs;
  4243. if (to != null && to.holdPrevious) {
  4244. for (let i = 0; i < timelinesCount; i++) {
  4245. timelineMode[i] = propertyIDs.add(timelines[i].getPropertyId()) ? AnimationState.HOLD_FIRST : AnimationState.HOLD_SUBSEQUENT;
  4246. }
  4247. return;
  4248. }
  4249. outer:
  4250. for (let i = 0; i < timelinesCount; i++) {
  4251. let timeline = timelines[i];
  4252. let id = timeline.getPropertyId();
  4253. if (!propertyIDs.add(id))
  4254. timelineMode[i] = AnimationState.SUBSEQUENT;
  4255. else if (to == null || timeline instanceof AttachmentTimeline || timeline instanceof DrawOrderTimeline
  4256. || timeline instanceof EventTimeline || !to.animation.hasTimeline(id)) {
  4257. timelineMode[i] = AnimationState.FIRST;
  4258. } else {
  4259. for (let next = to.mixingTo; next != null; next = next.mixingTo) {
  4260. if (next.animation.hasTimeline(id)) continue;
  4261. if (entry.mixDuration > 0) {
  4262. timelineMode[i] = AnimationState.HOLD_MIX;
  4263. timelineDipMix[i] = next;
  4264. continue outer;
  4265. }
  4266. break;
  4267. }
  4268. timelineMode[i] = AnimationState.HOLD_FIRST;
  4269. }
  4270. }
  4271. }
  4272. /** Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing. */
  4273. getCurrent (trackIndex) {
  4274. if (trackIndex >= this.tracks.length) return null;
  4275. return this.tracks[trackIndex];
  4276. }
  4277. /** Adds a listener to receive events for all track entries. */
  4278. addListener (listener) {
  4279. if (listener == null) throw new Error("listener cannot be null.");
  4280. this.listeners.push(listener);
  4281. }
  4282. /** Removes the listener added with {@link #addListener()}. */
  4283. removeListener (listener) {
  4284. let index = this.listeners.indexOf(listener);
  4285. if (index >= 0) this.listeners.splice(index, 1);
  4286. }
  4287. /** Removes all listeners added with {@link #addListener()}. */
  4288. clearListeners () {
  4289. this.listeners.length = 0;
  4290. }
  4291. /** Discards all listener notifications that have not yet been delivered. This can be useful to call from an
  4292. * {@link AnimationStateListener} when it is known that further notifications that may have been already queued for delivery
  4293. * are not wanted because new animations are being set. */
  4294. clearListenerNotifications () {
  4295. this.queue.clear();
  4296. }
  4297. //deprecated stuff
  4298. static __initStatic9() {this.deprecatedWarning1 = false;}
  4299. setAnimationByName(trackIndex, animationName, loop) {
  4300. if (!AnimationState.deprecatedWarning1) {
  4301. AnimationState.deprecatedWarning1 = true;
  4302. console.warn("Spine Deprecation Warning: AnimationState.setAnimationByName is deprecated, please use setAnimation from now on.");
  4303. }
  4304. this.setAnimation(trackIndex, animationName, loop);
  4305. }
  4306. static __initStatic10() {this.deprecatedWarning2 = false;}
  4307. addAnimationByName(trackIndex, animationName, loop, delay) {
  4308. if (!AnimationState.deprecatedWarning2) {
  4309. AnimationState.deprecatedWarning2 = true;
  4310. console.warn("Spine Deprecation Warning: AnimationState.addAnimationByName is deprecated, please use addAnimation from now on.");
  4311. }
  4312. this.addAnimation(trackIndex, animationName, loop, delay);
  4313. }
  4314. static __initStatic11() {this.deprecatedWarning3 = false;}
  4315. hasAnimation(animationName) {
  4316. let animation = this.data.skeletonData.findAnimation(animationName);
  4317. return animation !== null;
  4318. }
  4319. hasAnimationByName(animationName) {
  4320. if (!AnimationState.deprecatedWarning3) {
  4321. AnimationState.deprecatedWarning3 = true;
  4322. console.warn("Spine Deprecation Warning: AnimationState.hasAnimationByName is deprecated, please use hasAnimation from now on.");
  4323. }
  4324. return this.hasAnimation(animationName);
  4325. }
  4326. } AnimationState.__initStatic(); AnimationState.__initStatic2(); AnimationState.__initStatic3(); AnimationState.__initStatic4(); AnimationState.__initStatic5(); AnimationState.__initStatic6(); AnimationState.__initStatic7(); AnimationState.__initStatic8(); AnimationState.__initStatic9(); AnimationState.__initStatic10(); AnimationState.__initStatic11();
  4327. /** Stores settings and other state for the playback of an animation on an {@link AnimationState} track.
  4328. *
  4329. * References to a track entry must not be kept after the {@link AnimationStateListener#dispose()} event occurs. */
  4330. /**
  4331. * @public
  4332. */
  4333. class TrackEntry {constructor() { TrackEntry.prototype.__init10.call(this);TrackEntry.prototype.__init11.call(this);TrackEntry.prototype.__init12.call(this);TrackEntry.prototype.__init13.call(this); }
  4334. /** The animation to apply for this track entry. */
  4335. /** The animation queued to start after this animation, or null. `next` makes up a linked list. */
  4336. /** The track entry for the previous animation when mixing from the previous animation to this animation, or null if no
  4337. * mixing is currently occuring. When mixing from multiple animations, `mixingFrom` makes up a linked list. */
  4338. /** The track entry for the next animation when mixing from this animation to the next animation, or null if no mixing is
  4339. * currently occuring. When mixing to multiple animations, `mixingTo` makes up a linked list. */
  4340. /** The listener for events generated by this track entry, or null.
  4341. *
  4342. * A track entry returned from {@link AnimationState#setAnimation()} is already the current animation
  4343. * for the track, so the track entry listener {@link AnimationStateListener#start()} will not be called. */
  4344. /** The index of the track where this track entry is either current or queued.
  4345. *
  4346. * See {@link AnimationState#getCurrent()}. */
  4347. /** If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
  4348. * duration. */
  4349. /** If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead
  4350. * of being mixed out.
  4351. *
  4352. * When mixing between animations that key the same property, if a lower track also keys that property then the value will
  4353. * briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0%
  4354. * while the second animation mixes from 0% to 100%. Setting `holdPrevious` to true applies the first animation
  4355. * at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which
  4356. * keys the property, only when a higher track also keys the property.
  4357. *
  4358. * Snapping will occur if `holdPrevious` is true and this animation does not key all the same properties as the
  4359. * previous animation. */
  4360. /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the
  4361. * `eventThreshold`, event timelines are applied while this animation is being mixed out. Defaults to 0, so event
  4362. * timelines are not applied while this animation is being mixed out. */
  4363. /** When the mix percentage ({@link #mixtime} / {@link #mixDuration}) is less than the
  4364. * `attachmentThreshold`, attachment timelines are applied while this animation is being mixed out. Defaults to
  4365. * 0, so attachment timelines are not applied while this animation is being mixed out. */
  4366. /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the
  4367. * `drawOrderThreshold`, draw order timelines are applied while this animation is being mixed out. Defaults to 0,
  4368. * so draw order timelines are not applied while this animation is being mixed out. */
  4369. /** Seconds when this animation starts, both initially and after looping. Defaults to 0.
  4370. *
  4371. * When changing the `animationStart` time, it often makes sense to set {@link #animationLast} to the same
  4372. * value to prevent timeline keys before the start time from triggering. */
  4373. /** Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will
  4374. * loop back to {@link #animationStart} at this time. Defaults to the animation {@link Animation#duration}. */
  4375. /** The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this
  4376. * animation is applied, event timelines will fire all events between the `animationLast` time (exclusive) and
  4377. * `animationTime` (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation
  4378. * is applied. */
  4379. /** Seconds to postpone playing the animation. When this track entry is the current track entry, `delay`
  4380. * postpones incrementing the {@link #trackTime}. When this track entry is queued, `delay` is the time from
  4381. * the start of the previous animation to when this track entry will become the current track entry (ie when the previous
  4382. * track entry {@link TrackEntry#trackTime} >= this track entry's `delay`).
  4383. *
  4384. * {@link #timeScale} affects the delay. */
  4385. /** Current time in seconds this track entry has been the current track entry. The track time determines
  4386. * {@link #animationTime}. The track time can be set to start the animation at a time other than 0, without affecting
  4387. * looping. */
  4388. /** The track time in seconds when this animation will be removed from the track. Defaults to the highest possible float
  4389. * value, meaning the animation will be applied until a new animation is set or the track is cleared. If the track end time
  4390. * is reached, no other animations are queued for playback, and mixing from any previous animations is complete, then the
  4391. * properties keyed by the animation are set to the setup pose and the track is cleared.
  4392. *
  4393. * It may be desired to use {@link AnimationState#addEmptyAnimation()} rather than have the animation
  4394. * abruptly cease being applied. */
  4395. /** Multiplier for the delta time when this track entry is updated, causing time for this animation to pass slower or
  4396. * faster. Defaults to 1.
  4397. *
  4398. * {@link #mixTime} is not affected by track entry time scale, so {@link #mixDuration} may need to be adjusted to
  4399. * match the animation speed.
  4400. *
  4401. * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the
  4402. * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, assuming time scale to be 1. If
  4403. * the time scale is not 1, the delay may need to be adjusted.
  4404. *
  4405. * See AnimationState {@link AnimationState#timeScale} for affecting all animations. */
  4406. /** Values < 1 mix this animation with the skeleton's current pose (usually the pose resulting from lower tracks). Defaults
  4407. * to 1, which overwrites the skeleton's current pose with this animation.
  4408. *
  4409. * Typically track 0 is used to completely pose the skeleton, then alpha is used on higher tracks. It doesn't make sense to
  4410. * use alpha on track 0 if the skeleton pose is from the last frame render. */
  4411. /** Seconds from 0 to the {@link #getMixDuration()} when mixing from the previous animation to this animation. May be
  4412. * slightly more than `mixDuration` when the mix is complete. */
  4413. /** Seconds for mixing from the previous animation to this animation. Defaults to the value provided by AnimationStateData
  4414. * {@link AnimationStateData#getMix()} based on the animation before this animation (if any).
  4415. *
  4416. * A mix duration of 0 still mixes out over one frame to provide the track entry being mixed out a chance to revert the
  4417. * properties it was animating.
  4418. *
  4419. * The `mixDuration` can be set manually rather than use the value from
  4420. * {@link AnimationStateData#getMix()}. In that case, the `mixDuration` can be set for a new
  4421. * track entry only before {@link AnimationState#update(float)} is first called.
  4422. *
  4423. * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the
  4424. * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, not a mix duration set
  4425. * afterward. */
  4426. /** Controls how properties keyed in the animation are mixed with lower tracks. Defaults to {@link MixBlend#replace}, which
  4427. * replaces the values from the lower tracks with the animation values. {@link MixBlend#add} adds the animation values to
  4428. * the values from the lower tracks.
  4429. *
  4430. * The `mixBlend` can be set for a new track entry only before {@link AnimationState#apply()} is first
  4431. * called. */
  4432. __init10() {this.mixBlend = MixBlend.replace;}
  4433. __init11() {this.timelineMode = new Array();}
  4434. __init12() {this.timelineHoldMix = new Array();}
  4435. __init13() {this.timelinesRotation = new Array();}
  4436. reset () {
  4437. this.next = null;
  4438. this.mixingFrom = null;
  4439. this.mixingTo = null;
  4440. this.animation = null;
  4441. this.listener = null;
  4442. this.timelineMode.length = 0;
  4443. this.timelineHoldMix.length = 0;
  4444. this.timelinesRotation.length = 0;
  4445. }
  4446. /** Uses {@link #trackTime} to compute the `animationTime`, which is between {@link #animationStart}
  4447. * and {@link #animationEnd}. When the `trackTime` is 0, the `animationTime` is equal to the
  4448. * `animationStart` time. */
  4449. getAnimationTime () {
  4450. if (this.loop) {
  4451. let duration = this.animationEnd - this.animationStart;
  4452. if (duration == 0) return this.animationStart;
  4453. return (this.trackTime % duration) + this.animationStart;
  4454. }
  4455. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  4456. }
  4457. setAnimationLast(animationLast) {
  4458. this.animationLast = animationLast;
  4459. this.nextAnimationLast = animationLast;
  4460. }
  4461. /** Returns true if at least one loop has been completed.
  4462. *
  4463. * See {@link AnimationStateListener#complete()}. */
  4464. isComplete () {
  4465. return this.trackTime >= this.animationEnd - this.animationStart;
  4466. }
  4467. /** Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the
  4468. * long way around when using {@link #alpha} and starting animations on other tracks.
  4469. *
  4470. * Mixing with {@link MixBlend#replace} involves finding a rotation between two others, which has two possible solutions:
  4471. * the short way or the long way around. The two rotations likely change over time, so which direction is the short or long
  4472. * way also changes. If the short way was always chosen, bones would flip to the other side when that direction became the
  4473. * long way. TrackEntry chooses the short way the first time it is applied and remembers that direction. */
  4474. resetRotationDirections () {
  4475. this.timelinesRotation.length = 0;
  4476. }
  4477. //deprecated stuff
  4478. static __initStatic12() {this.deprecatedWarning1 = false;}
  4479. static __initStatic13() {this.deprecatedWarning2 = false;}
  4480. get time() {
  4481. if (!TrackEntry.deprecatedWarning1) {
  4482. TrackEntry.deprecatedWarning1 = true;
  4483. console.warn("Spine Deprecation Warning: TrackEntry.time is deprecated, please use trackTime from now on.");
  4484. }
  4485. return this.trackTime;
  4486. }
  4487. set time(value) {
  4488. if (!TrackEntry.deprecatedWarning1) {
  4489. TrackEntry.deprecatedWarning1 = true;
  4490. console.warn("Spine Deprecation Warning: TrackEntry.time is deprecated, please use trackTime from now on.");
  4491. }
  4492. this.trackTime = value;
  4493. }
  4494. get endTime() {
  4495. if (!TrackEntry.deprecatedWarning2) {
  4496. TrackEntry.deprecatedWarning2 = true;
  4497. console.warn("Spine Deprecation Warning: TrackEntry.endTime is deprecated, please use trackEnd from now on.");
  4498. }
  4499. return this.trackTime;
  4500. }
  4501. set endTime(value) {
  4502. if (!TrackEntry.deprecatedWarning2) {
  4503. TrackEntry.deprecatedWarning2 = true;
  4504. console.warn("Spine Deprecation Warning: TrackEntry.endTime is deprecated, please use trackEnd from now on.");
  4505. }
  4506. this.trackTime = value;
  4507. }
  4508. loopsCount() {
  4509. return Math.floor(this.trackTime / this.trackEnd);
  4510. }
  4511. } TrackEntry.__initStatic12(); TrackEntry.__initStatic13();
  4512. /**
  4513. * @public
  4514. */
  4515. class EventQueue {
  4516. __init14() {this.objects = [];}
  4517. __init15() {this.drainDisabled = false;}
  4518. constructor(animState) {EventQueue.prototype.__init14.call(this);EventQueue.prototype.__init15.call(this);
  4519. this.animState = animState;
  4520. }
  4521. start (entry) {
  4522. this.objects.push(EventType.start);
  4523. this.objects.push(entry);
  4524. this.animState.animationsChanged = true;
  4525. }
  4526. interrupt (entry) {
  4527. this.objects.push(EventType.interrupt);
  4528. this.objects.push(entry);
  4529. }
  4530. end (entry) {
  4531. this.objects.push(EventType.end);
  4532. this.objects.push(entry);
  4533. this.animState.animationsChanged = true;
  4534. }
  4535. dispose (entry) {
  4536. this.objects.push(EventType.dispose);
  4537. this.objects.push(entry);
  4538. }
  4539. complete (entry) {
  4540. this.objects.push(EventType.complete);
  4541. this.objects.push(entry);
  4542. }
  4543. event (entry, event) {
  4544. this.objects.push(EventType.event);
  4545. this.objects.push(entry);
  4546. this.objects.push(event);
  4547. }
  4548. static __initStatic14() {this.deprecatedWarning1 = false;}
  4549. deprecateStuff() {
  4550. if (!EventQueue.deprecatedWarning1) {
  4551. EventQueue.deprecatedWarning1 = true;
  4552. console.warn("Spine Deprecation Warning: onComplete, onStart, onEnd, onEvent art deprecated, please use listeners from now on. 'state.addListener({ complete: function(track, event) { } })'");
  4553. }
  4554. return true;
  4555. }
  4556. drain () {
  4557. if (this.drainDisabled) return;
  4558. this.drainDisabled = true;
  4559. let objects = this.objects;
  4560. let listeners = this.animState.listeners;
  4561. for (let i = 0; i < objects.length; i += 2) {
  4562. let type = objects[i] ;
  4563. let entry = objects[i + 1] ;
  4564. switch (type) {
  4565. case EventType.start:
  4566. if (entry.listener != null && entry.listener.start) entry.listener.start(entry);
  4567. for (let ii = 0; ii < listeners.length; ii++)
  4568. if (listeners[ii].start) listeners[ii].start(entry);
  4569. //deprecation
  4570. entry.onStart && this.deprecateStuff() && entry.onStart(entry.trackIndex);
  4571. this.animState.onStart && this.deprecateStuff() && this.deprecateStuff && this.animState.onStart(entry.trackIndex);
  4572. break;
  4573. case EventType.interrupt:
  4574. if (entry.listener != null && entry.listener.interrupt) entry.listener.interrupt(entry);
  4575. for (let ii = 0; ii < listeners.length; ii++)
  4576. if (listeners[ii].interrupt) listeners[ii].interrupt(entry);
  4577. break;
  4578. case EventType.end:
  4579. if (entry.listener != null && entry.listener.end) entry.listener.end(entry);
  4580. for (let ii = 0; ii < listeners.length; ii++)
  4581. if (listeners[ii].end) listeners[ii].end(entry);
  4582. //deprecation
  4583. entry.onEnd && this.deprecateStuff() && entry.onEnd(entry.trackIndex);
  4584. this.animState.onEnd && this.deprecateStuff() && this.animState.onEnd(entry.trackIndex);
  4585. // Fall through.
  4586. case EventType.dispose:
  4587. if (entry.listener != null && entry.listener.dispose) entry.listener.dispose(entry);
  4588. for (let ii = 0; ii < listeners.length; ii++)
  4589. if (listeners[ii].dispose) listeners[ii].dispose(entry);
  4590. this.animState.trackEntryPool.free(entry);
  4591. break;
  4592. case EventType.complete:
  4593. if (entry.listener != null && entry.listener.complete) entry.listener.complete(entry);
  4594. for (let ii = 0; ii < listeners.length; ii++)
  4595. if (listeners[ii].complete) listeners[ii].complete(entry);
  4596. //deprecation
  4597. let count = MathUtils.toInt(entry.loopsCount()) ;
  4598. entry.onComplete && this.deprecateStuff() && entry.onComplete(entry.trackIndex, count);
  4599. this.animState.onComplete && this.deprecateStuff() && this.animState.onComplete(entry.trackIndex, count);
  4600. break;
  4601. case EventType.event:
  4602. let event = objects[i++ + 2] ;
  4603. if (entry.listener != null && entry.listener.event) entry.listener.event(entry, event);
  4604. for (let ii = 0; ii < listeners.length; ii++)
  4605. if (listeners[ii].event) listeners[ii].event(entry, event);
  4606. //deprecation
  4607. entry.onEvent && this.deprecateStuff() && entry.onEvent(entry.trackIndex, event);
  4608. this.animState.onEvent && this.deprecateStuff() && this.animState.onEvent(entry.trackIndex, event);
  4609. break;
  4610. }
  4611. }
  4612. this.clear();
  4613. this.drainDisabled = false;
  4614. }
  4615. clear () {
  4616. this.objects.length = 0;
  4617. }
  4618. } EventQueue.__initStatic14();
  4619. /**
  4620. * @public
  4621. */
  4622. var EventType; (function (EventType) {
  4623. const start = 0; EventType[EventType["start"] = start] = "start"; const interrupt = start + 1; EventType[EventType["interrupt"] = interrupt] = "interrupt"; const end = interrupt + 1; EventType[EventType["end"] = end] = "end"; const dispose = end + 1; EventType[EventType["dispose"] = dispose] = "dispose"; const complete = dispose + 1; EventType[EventType["complete"] = complete] = "complete"; const event = complete + 1; EventType[EventType["event"] = event] = "event";
  4624. })(EventType || (EventType = {}));
  4625. /**
  4626. * @public
  4627. */
  4628. /**
  4629. * @public
  4630. */
  4631. class AnimationStateAdapter {
  4632. start (entry) {
  4633. }
  4634. interrupt (entry) {
  4635. }
  4636. end (entry) {
  4637. }
  4638. dispose (entry) {
  4639. }
  4640. complete (entry) {
  4641. }
  4642. event (entry, event) {
  4643. }
  4644. }
  4645. /**
  4646. * @public
  4647. */
  4648. class AnimationStateData {
  4649. __init() {this.animationToMixTime = {};}
  4650. __init2() {this.defaultMix = 0;}
  4651. constructor(skeletonData) {AnimationStateData.prototype.__init.call(this);AnimationStateData.prototype.__init2.call(this);
  4652. if (skeletonData == null) throw new Error("skeletonData cannot be null.");
  4653. this.skeletonData = skeletonData;
  4654. }
  4655. setMix(fromName, toName, duration) {
  4656. let from = this.skeletonData.findAnimation(fromName);
  4657. if (from == null) throw new Error("Animation not found: " + fromName);
  4658. let to = this.skeletonData.findAnimation(toName);
  4659. if (to == null) throw new Error("Animation not found: " + toName);
  4660. this.setMixWith(from, to, duration);
  4661. }
  4662. static __initStatic() {this.deprecatedWarning1 = false;}
  4663. setMixByName(fromName, toName, duration) {
  4664. if (!AnimationStateData.deprecatedWarning1) {
  4665. AnimationStateData.deprecatedWarning1 = true;
  4666. console.warn("Deprecation Warning: AnimationStateData.setMixByName is deprecated, please use setMix from now on.");
  4667. }
  4668. this.setMix(fromName, toName, duration);
  4669. }
  4670. setMixWith(from, to, duration) {
  4671. if (from == null) throw new Error("from cannot be null.");
  4672. if (to == null) throw new Error("to cannot be null.");
  4673. let key = from.name + "." + to.name;
  4674. this.animationToMixTime[key] = duration;
  4675. }
  4676. getMix(from, to) {
  4677. let key = from.name + "." + to.name;
  4678. let value = this.animationToMixTime[key];
  4679. return value === undefined ? this.defaultMix : value;
  4680. }
  4681. } AnimationStateData.__initStatic();
  4682. /**
  4683. * @public
  4684. */
  4685. class AtlasAttachmentLoader {
  4686. constructor(atlas) {
  4687. this.atlas = atlas;
  4688. }
  4689. /** @return May be null to not load an attachment. */
  4690. newRegionAttachment(skin, name, path) {
  4691. let region = this.atlas.findRegion(path);
  4692. if (region == null) throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  4693. let attachment = new RegionAttachment(name);
  4694. attachment.region = region;
  4695. return attachment;
  4696. }
  4697. /** @return May be null to not load an attachment. */
  4698. newMeshAttachment(skin, name, path) {
  4699. let region = this.atlas.findRegion(path);
  4700. if (region == null) throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  4701. let attachment = new MeshAttachment(name);
  4702. attachment.region = region;
  4703. return attachment;
  4704. }
  4705. /** @return May be null to not load an attachment. */
  4706. newBoundingBoxAttachment(skin, name) {
  4707. return new BoundingBoxAttachment(name);
  4708. }
  4709. /** @return May be null to not load an attachment */
  4710. newPathAttachment(skin, name) {
  4711. return new PathAttachment(name);
  4712. }
  4713. newPointAttachment(skin, name) {
  4714. return new PointAttachment(name);
  4715. }
  4716. newClippingAttachment(skin, name) {
  4717. return new ClippingAttachment(name);
  4718. }
  4719. }
  4720. /**
  4721. * @public
  4722. */
  4723. class BoneData {
  4724. __init() {this.x = 0;}
  4725. __init2() {this.y = 0;}
  4726. __init3() {this.rotation = 0;}
  4727. __init4() {this.scaleX = 1;}
  4728. __init5() {this.scaleY = 1;}
  4729. __init6() {this.shearX = 0;}
  4730. __init7() {this.shearY = 0;}
  4731. __init8() {this.transformMode = TransformMode.Normal;}
  4732. __init9() {this.skinRequired = false;}
  4733. __init10() {this.color = new Color();}
  4734. constructor(index, name, parent) {BoneData.prototype.__init.call(this);BoneData.prototype.__init2.call(this);BoneData.prototype.__init3.call(this);BoneData.prototype.__init4.call(this);BoneData.prototype.__init5.call(this);BoneData.prototype.__init6.call(this);BoneData.prototype.__init7.call(this);BoneData.prototype.__init8.call(this);BoneData.prototype.__init9.call(this);BoneData.prototype.__init10.call(this);
  4735. if (index < 0) throw new Error("index must be >= 0.");
  4736. if (name == null) throw new Error("name cannot be null.");
  4737. this.index = index;
  4738. this.name = name;
  4739. this.parent = parent;
  4740. }
  4741. }
  4742. /**
  4743. * @public
  4744. */
  4745. var TransformMode; (function (TransformMode) {
  4746. const Normal = 0; TransformMode[TransformMode["Normal"] = Normal] = "Normal"; const OnlyTranslation = Normal + 1; TransformMode[TransformMode["OnlyTranslation"] = OnlyTranslation] = "OnlyTranslation"; const NoRotationOrReflection = OnlyTranslation + 1; TransformMode[TransformMode["NoRotationOrReflection"] = NoRotationOrReflection] = "NoRotationOrReflection"; const NoScale = NoRotationOrReflection + 1; TransformMode[TransformMode["NoScale"] = NoScale] = "NoScale"; const NoScaleOrReflection = NoScale + 1; TransformMode[TransformMode["NoScaleOrReflection"] = NoScaleOrReflection] = "NoScaleOrReflection";
  4747. })(TransformMode || (TransformMode = {}));
  4748. /**
  4749. * @public
  4750. */
  4751. class Bone {
  4752. //be careful! Spine b,c is c,b in pixi matrix
  4753. __init() {this.matrix = new math.Matrix();}
  4754. get worldX() {
  4755. return this.matrix.tx;
  4756. }
  4757. get worldY() {
  4758. return this.matrix.ty;
  4759. }
  4760. __init2() {this.children = new Array();}
  4761. __init3() {this.x = 0;}
  4762. __init4() {this.y = 0;}
  4763. __init5() {this.rotation = 0;}
  4764. __init6() {this.scaleX = 0;}
  4765. __init7() {this.scaleY = 0;}
  4766. __init8() {this.shearX = 0;}
  4767. __init9() {this.shearY = 0;}
  4768. __init10() {this.ax = 0;}
  4769. __init11() {this.ay = 0;}
  4770. __init12() {this.arotation = 0;}
  4771. __init13() {this.ascaleX = 0;}
  4772. __init14() {this.ascaleY = 0;}
  4773. __init15() {this.ashearX = 0;}
  4774. __init16() {this.ashearY = 0;}
  4775. __init17() {this.appliedValid = false;}
  4776. __init18() {this.sorted = false;}
  4777. __init19() {this.active = false;}
  4778. /** @param parent May be null. */
  4779. constructor(data, skeleton, parent) {Bone.prototype.__init.call(this);Bone.prototype.__init2.call(this);Bone.prototype.__init3.call(this);Bone.prototype.__init4.call(this);Bone.prototype.__init5.call(this);Bone.prototype.__init6.call(this);Bone.prototype.__init7.call(this);Bone.prototype.__init8.call(this);Bone.prototype.__init9.call(this);Bone.prototype.__init10.call(this);Bone.prototype.__init11.call(this);Bone.prototype.__init12.call(this);Bone.prototype.__init13.call(this);Bone.prototype.__init14.call(this);Bone.prototype.__init15.call(this);Bone.prototype.__init16.call(this);Bone.prototype.__init17.call(this);Bone.prototype.__init18.call(this);Bone.prototype.__init19.call(this);
  4780. if (data == null) throw new Error("data cannot be null.");
  4781. if (skeleton == null) throw new Error("skeleton cannot be null.");
  4782. this.data = data;
  4783. this.skeleton = skeleton;
  4784. this.parent = parent;
  4785. this.setToSetupPose();
  4786. }
  4787. isActive () {
  4788. return this.active;
  4789. }
  4790. /** Same as {@link #updateWorldTransform()}. This method exists for Bone to implement {@link Updatable}. */
  4791. update() {
  4792. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  4793. }
  4794. /** Computes the world transform using the parent bone and this bone's local transform. */
  4795. updateWorldTransform() {
  4796. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  4797. }
  4798. /** Computes the world transform using the parent bone and the specified local transform. */
  4799. updateWorldTransformWith(x, y, rotation, scaleX, scaleY, shearX, shearY) {
  4800. this.ax = x;
  4801. this.ay = y;
  4802. this.arotation = rotation;
  4803. this.ascaleX = scaleX;
  4804. this.ascaleY = scaleY;
  4805. this.ashearX = shearX;
  4806. this.ashearY = shearY;
  4807. this.appliedValid = true;
  4808. let parent = this.parent;
  4809. let m = this.matrix;
  4810. let sx = this.skeleton.scaleX;
  4811. let sy = settings.yDown? -this.skeleton.scaleY : this.skeleton.scaleY;
  4812. if (parent == null) { // Root bone.
  4813. let skeleton = this.skeleton;
  4814. let rotationY = rotation + 90 + shearY;
  4815. m.a = MathUtils.cosDeg(rotation + shearX) * scaleX * sx;
  4816. m.c = MathUtils.cosDeg(rotationY) * scaleY * sx;
  4817. m.b = MathUtils.sinDeg(rotation + shearX) * scaleX * sy;
  4818. m.d = MathUtils.sinDeg(rotationY) * scaleY * sy;
  4819. m.tx = x * sx + skeleton.x;
  4820. m.ty = y * sy + skeleton.y;
  4821. return;
  4822. }
  4823. let pa = parent.matrix.a, pb = parent.matrix.c, pc = parent.matrix.b, pd = parent.matrix.d;
  4824. m.tx = pa * x + pb * y + parent.matrix.tx;
  4825. m.ty = pc * x + pd * y + parent.matrix.ty;
  4826. switch (this.data.transformMode) {
  4827. case TransformMode.Normal: {
  4828. let rotationY = rotation + 90 + shearY;
  4829. let la = MathUtils.cosDeg(rotation + shearX) * scaleX;
  4830. let lb = MathUtils.cosDeg(rotationY) * scaleY;
  4831. let lc = MathUtils.sinDeg(rotation + shearX) * scaleX;
  4832. let ld = MathUtils.sinDeg(rotationY) * scaleY;
  4833. m.a = pa * la + pb * lc;
  4834. m.c = pa * lb + pb * ld;
  4835. m.b = pc * la + pd * lc;
  4836. m.d = pc * lb + pd * ld;
  4837. return;
  4838. }
  4839. case TransformMode.OnlyTranslation: {
  4840. let rotationY = rotation + 90 + shearY;
  4841. m.a = MathUtils.cosDeg(rotation + shearX) * scaleX;
  4842. m.c = MathUtils.cosDeg(rotationY) * scaleY;
  4843. m.b = MathUtils.sinDeg(rotation + shearX) * scaleX;
  4844. m.d = MathUtils.sinDeg(rotationY) * scaleY;
  4845. break;
  4846. }
  4847. case TransformMode.NoRotationOrReflection: {
  4848. let s = pa * pa + pc * pc;
  4849. let prx = 0;
  4850. if (s > 0.0001) {
  4851. s = Math.abs(pa * pd - pb * pc) / s;
  4852. pa /= this.skeleton.scaleX;
  4853. pc /= this.skeleton.scaleY;
  4854. pb = pc * s;
  4855. pd = pa * s;
  4856. prx = Math.atan2(pc, pa) * MathUtils.radDeg;
  4857. } else {
  4858. pa = 0;
  4859. pc = 0;
  4860. prx = 90 - Math.atan2(pd, pb) * MathUtils.radDeg;
  4861. }
  4862. let rx = rotation + shearX - prx;
  4863. let ry = rotation + shearY - prx + 90;
  4864. let la = MathUtils.cosDeg(rx) * scaleX;
  4865. let lb = MathUtils.cosDeg(ry) * scaleY;
  4866. let lc = MathUtils.sinDeg(rx) * scaleX;
  4867. let ld = MathUtils.sinDeg(ry) * scaleY;
  4868. m.a = pa * la - pb * lc;
  4869. m.c = pa * lb - pb * ld;
  4870. m.b = pc * la + pd * lc;
  4871. m.d = pc * lb + pd * ld;
  4872. break;
  4873. }
  4874. case TransformMode.NoScale:
  4875. case TransformMode.NoScaleOrReflection: {
  4876. let cos = MathUtils.cosDeg(rotation);
  4877. let sin = MathUtils.sinDeg(rotation);
  4878. let za = (pa * cos + pb * sin) / sx;
  4879. let zc = (pc * cos + pd * sin) / sy;
  4880. let s = Math.sqrt(za * za + zc * zc);
  4881. if (s > 0.00001) s = 1 / s;
  4882. za *= s;
  4883. zc *= s;
  4884. s = Math.sqrt(za * za + zc * zc);
  4885. if (
  4886. this.data.transformMode == TransformMode.NoScale
  4887. && (pa * pd - pb * pc < 0) != (settings.yDown?
  4888. (this.skeleton.scaleX < 0 != this.skeleton.scaleY > 0) :
  4889. (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0))
  4890. ) s = -s;
  4891. let r = Math.PI / 2 + Math.atan2(zc, za);
  4892. let zb = Math.cos(r) * s;
  4893. let zd = Math.sin(r) * s;
  4894. let la = MathUtils.cosDeg(shearX) * scaleX;
  4895. let lb = MathUtils.cosDeg(90 + shearY) * scaleY;
  4896. let lc = MathUtils.sinDeg(shearX) * scaleX;
  4897. let ld = MathUtils.sinDeg(90 + shearY) * scaleY;
  4898. m.a = za * la + zb * lc;
  4899. m.c = za * lb + zb * ld;
  4900. m.b = zc * la + zd * lc;
  4901. m.d = zc * lb + zd * ld;
  4902. break;
  4903. }
  4904. }
  4905. m.a *= sx;
  4906. m.c *= sx;
  4907. m.b *= sy;
  4908. m.d *= sy;
  4909. }
  4910. setToSetupPose() {
  4911. let data = this.data;
  4912. this.x = data.x;
  4913. this.y = data.y;
  4914. this.rotation = data.rotation;
  4915. this.scaleX = data.scaleX;
  4916. this.scaleY = data.scaleY;
  4917. this.shearX = data.shearX;
  4918. this.shearY = data.shearY;
  4919. }
  4920. getWorldRotationX() {
  4921. return Math.atan2(this.matrix.b, this.matrix.a) * MathUtils.radDeg;
  4922. }
  4923. getWorldRotationY() {
  4924. return Math.atan2(this.matrix.d, this.matrix.c) * MathUtils.radDeg;
  4925. }
  4926. getWorldScaleX() {
  4927. let m = this.matrix;
  4928. return Math.sqrt(m.a * m.a + m.c * m.c);
  4929. }
  4930. getWorldScaleY() {
  4931. let m = this.matrix;
  4932. return Math.sqrt(m.b * m.b + m.d * m.d);
  4933. }
  4934. /** Computes the individual applied transform values from the world transform. This can be useful to perform processing using
  4935. * the applied transform after the world transform has been modified directly (eg, by a constraint).
  4936. * <p>
  4937. * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. */
  4938. updateAppliedTransform() {
  4939. this.appliedValid = true;
  4940. let parent = this.parent;
  4941. let m = this.matrix;
  4942. if (parent == null) {
  4943. this.ax = m.tx;
  4944. this.ay = m.ty;
  4945. this.arotation = Math.atan2(m.b, m.a) * MathUtils.radDeg;
  4946. this.ascaleX = Math.sqrt(m.a * m.a + m.b * m.b);
  4947. this.ascaleY = Math.sqrt(m.c * m.c + m.d * m.d);
  4948. this.ashearX = 0;
  4949. this.ashearY = Math.atan2(m.a * m.c + m.b * m.d, m.a * m.d - m.b * m.c) * MathUtils.radDeg;
  4950. return;
  4951. }
  4952. let pm = parent.matrix;
  4953. let pid = 1 / (pm.a * pm.d - pm.b * pm.c);
  4954. let dx = m.tx - pm.tx, dy = m.ty - pm.ty;
  4955. this.ax = (dx * pm.d * pid - dy * pm.c * pid);
  4956. this.ay = (dy * pm.a * pid - dx * pm.b * pid);
  4957. let ia = pid * pm.d;
  4958. let id = pid * pm.a;
  4959. let ib = pid * pm.c;
  4960. let ic = pid * pm.b;
  4961. let ra = ia * m.a - ib * m.b;
  4962. let rb = ia * m.c - ib * m.d;
  4963. let rc = id * m.b - ic * m.a;
  4964. let rd = id * m.d - ic * m.c;
  4965. this.ashearX = 0;
  4966. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  4967. if (this.ascaleX > 0.0001) {
  4968. let det = ra * rd - rb * rc;
  4969. this.ascaleY = det / this.ascaleX;
  4970. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * MathUtils.radDeg;
  4971. this.arotation = Math.atan2(rc, ra) * MathUtils.radDeg;
  4972. } else {
  4973. this.ascaleX = 0;
  4974. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  4975. this.ashearY = 0;
  4976. this.arotation = 90 - Math.atan2(rd, rb) * MathUtils.radDeg;
  4977. }
  4978. }
  4979. worldToLocal(world) {
  4980. let m = this.matrix;
  4981. let a = m.a, b = m.c, c = m.b, d = m.d;
  4982. let invDet = 1 / (a * d - b * c);
  4983. let x = world.x - m.tx, y = world.y - m.ty;
  4984. world.x = (x * d * invDet - y * b * invDet);
  4985. world.y = (y * a * invDet - x * c * invDet);
  4986. return world;
  4987. }
  4988. localToWorld(local) {
  4989. let m = this.matrix;
  4990. let x = local.x, y = local.y;
  4991. local.x = x * m.a + y * m.c + m.tx;
  4992. local.y = x * m.b + y * m.d + m.ty;
  4993. return local;
  4994. }
  4995. worldToLocalRotation (worldRotation) {
  4996. let sin = MathUtils.sinDeg(worldRotation), cos = MathUtils.cosDeg(worldRotation);
  4997. let mat = this.matrix;
  4998. return Math.atan2(mat.a * sin - mat.b * cos, mat.d * cos - mat.c * sin) * MathUtils.radDeg;
  4999. }
  5000. localToWorldRotation (localRotation) {
  5001. let sin = MathUtils.sinDeg(localRotation), cos = MathUtils.cosDeg(localRotation);
  5002. let mat = this.matrix;
  5003. return Math.atan2(cos * mat.b + sin * mat.d, cos * mat.a + sin * mat.c) * MathUtils.radDeg;
  5004. }
  5005. rotateWorld (degrees) {
  5006. let mat = this.matrix;
  5007. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  5008. let cos = MathUtils.cosDeg(degrees), sin = MathUtils.sinDeg(degrees);
  5009. mat.a = cos * a - sin * c;
  5010. mat.c = cos * b - sin * d;
  5011. mat.b = sin * a + cos * c;
  5012. mat.d = sin * b + cos * d;
  5013. this.appliedValid = false;
  5014. }
  5015. }
  5016. /**
  5017. * @public
  5018. */
  5019. class ConstraintData {
  5020. constructor( name, order, skinRequired) {this.name = name;this.order = order;this.skinRequired = skinRequired; }
  5021. }
  5022. /**
  5023. * @public
  5024. */
  5025. class Event {
  5026. constructor(time, data) {
  5027. if (data == null) throw new Error("data cannot be null.");
  5028. this.time = time;
  5029. this.data = data;
  5030. }
  5031. }
  5032. /**
  5033. * @public
  5034. */
  5035. class EventData {
  5036. constructor (name) {
  5037. this.name = name;
  5038. }
  5039. }
  5040. /**
  5041. * @public
  5042. */
  5043. class IkConstraint {
  5044. __init() {this.bendDirection = 0;}
  5045. __init2() {this.compress = false;}
  5046. __init3() {this.stretch = false;}
  5047. __init4() {this.mix = 1;}
  5048. __init5() {this.softness = 0;}
  5049. __init6() {this.active = false;}
  5050. constructor (data, skeleton) {IkConstraint.prototype.__init.call(this);IkConstraint.prototype.__init2.call(this);IkConstraint.prototype.__init3.call(this);IkConstraint.prototype.__init4.call(this);IkConstraint.prototype.__init5.call(this);IkConstraint.prototype.__init6.call(this);
  5051. if (data == null) throw new Error("data cannot be null.");
  5052. if (skeleton == null) throw new Error("skeleton cannot be null.");
  5053. this.data = data;
  5054. this.mix = data.mix;
  5055. this.softness = data.softness;
  5056. this.bendDirection = data.bendDirection;
  5057. this.compress = data.compress;
  5058. this.stretch = data.stretch;
  5059. this.bones = new Array();
  5060. for (let i = 0; i < data.bones.length; i++)
  5061. this.bones.push(skeleton.findBone(data.bones[i].name));
  5062. this.target = skeleton.findBone(data.target.name);
  5063. }
  5064. isActive () {
  5065. return this.active;
  5066. }
  5067. apply () {
  5068. this.update();
  5069. }
  5070. update () {
  5071. let target = this.target;
  5072. let bones = this.bones;
  5073. switch (bones.length) {
  5074. case 1:
  5075. this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix);
  5076. break;
  5077. case 2:
  5078. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.softness, this.mix);
  5079. break;
  5080. }
  5081. }
  5082. /** Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified in the world
  5083. * coordinate system. */
  5084. apply1 (bone, targetX, targetY, compress, stretch, uniform, alpha) {
  5085. if (!bone.appliedValid) bone.updateAppliedTransform();
  5086. let p = bone.parent.matrix;
  5087. let pa = p.a, pb = p.c, pc = p.b, pd = p.d;
  5088. let rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
  5089. switch(bone.data.transformMode) {
  5090. case TransformMode.OnlyTranslation:
  5091. tx = targetX - bone.worldX;
  5092. ty = targetY - bone.worldY;
  5093. break;
  5094. case TransformMode.NoRotationOrReflection:
  5095. let s = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
  5096. let sa = pa / bone.skeleton.scaleX;
  5097. let sc = pc / bone.skeleton.scaleY;
  5098. pb = -sc * s * bone.skeleton.scaleX;
  5099. pd = sa * s * bone.skeleton.scaleY;
  5100. rotationIK += Math.atan2(sc, sa) * MathUtils.radDeg;
  5101. // Fall through
  5102. default:
  5103. let x = targetX - p.tx, y = targetY - p.ty;
  5104. let d = pa * pd - pb * pc;
  5105. tx = (x * pd - y * pb) / d - bone.ax;
  5106. ty = (y * pa - x * pc) / d - bone.ay;
  5107. }
  5108. rotationIK += Math.atan2(ty, tx) * MathUtils.radDeg;
  5109. if (bone.ascaleX < 0) rotationIK += 180;
  5110. if (rotationIK > 180)
  5111. rotationIK -= 360;
  5112. else if (rotationIK < -180) rotationIK += 360;
  5113. let sx = bone.ascaleX, sy = bone.ascaleY;
  5114. if (compress || stretch) {
  5115. switch (bone.data.transformMode) {
  5116. case TransformMode.NoScale:
  5117. case TransformMode.NoScaleOrReflection:
  5118. tx = targetX - bone.worldX;
  5119. ty = targetY - bone.worldY;
  5120. }
  5121. let b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
  5122. if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
  5123. let s = (dd / b - 1) * alpha + 1;
  5124. sx *= s;
  5125. if (uniform) sy *= s;
  5126. }
  5127. }
  5128. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX,
  5129. bone.ashearY);
  5130. }
  5131. /** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The
  5132. * target is specified in the world coordinate system.
  5133. * @param child A direct descendant of the parent bone. */
  5134. apply2 (parent, child, targetX, targetY, bendDir, stretch, softness, alpha) {
  5135. if (alpha == 0) {
  5136. child.updateWorldTransform();
  5137. return;
  5138. }
  5139. if (!parent.appliedValid) parent.updateAppliedTransform();
  5140. if (!child.appliedValid) child.updateAppliedTransform();
  5141. let px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
  5142. let pmat = parent.matrix;
  5143. let os1 = 0, os2 = 0, s2 = 0;
  5144. if (psx < 0) {
  5145. psx = -psx;
  5146. os1 = 180;
  5147. s2 = -1;
  5148. } else {
  5149. os1 = 0;
  5150. s2 = 1;
  5151. }
  5152. if (psy < 0) {
  5153. psy = -psy;
  5154. s2 = -s2;
  5155. }
  5156. if (csx < 0) {
  5157. csx = -csx;
  5158. os2 = 180;
  5159. } else
  5160. os2 = 0;
  5161. let cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = pmat.a, b = pmat.c, c = pmat.b, d = pmat.d;
  5162. let u = Math.abs(psx - psy) <= 0.0001;
  5163. if (!u) {
  5164. cy = 0;
  5165. cwx = a * cx + pmat.tx;
  5166. cwy = c * cx + pmat.ty;
  5167. } else {
  5168. cy = child.ay;
  5169. cwx = a * cx + b * cy + pmat.tx;
  5170. cwy = c * cx + d * cy + pmat.ty;
  5171. }
  5172. let pp = parent.parent.matrix;
  5173. a = pp.a;
  5174. b = pp.c;
  5175. c = pp.b;
  5176. d = pp.d;
  5177. let id = 1 / (a * d - b * c), x = cwx - pp.tx, y = cwy - pp.ty;
  5178. let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  5179. let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
  5180. if (l1 < 0.0001) {
  5181. this.apply1(parent, targetX, targetY, false, stretch, false, alpha);
  5182. child.updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  5183. return;
  5184. }
  5185. x = targetX - pp.tx;
  5186. y = targetY - pp.ty;
  5187. let tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  5188. let dd = tx * tx + ty * ty;
  5189. if (softness != 0) {
  5190. softness *= psx * (csx + 1) / 2;
  5191. let td = Math.sqrt(dd), sd = td - l1 - l2 * psx + softness;
  5192. if (sd > 0) {
  5193. let p = Math.min(1, sd / (softness * 2)) - 1;
  5194. p = (sd - softness * (1 - p * p)) / td;
  5195. tx -= p * tx;
  5196. ty -= p * ty;
  5197. dd = tx * tx + ty * ty;
  5198. }
  5199. }
  5200. outer:
  5201. if (u) {
  5202. l2 *= psx;
  5203. let cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  5204. if (cos < -1)
  5205. cos = -1;
  5206. else if (cos > 1) {
  5207. cos = 1;
  5208. if (stretch) sx *= (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
  5209. }
  5210. a2 = Math.acos(cos) * bendDir;
  5211. a = l1 + l2 * cos;
  5212. b = l2 * Math.sin(a2);
  5213. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  5214. } else {
  5215. a = psx * l2;
  5216. b = psy * l2;
  5217. let aa = a * a, bb = b * b, ta = Math.atan2(ty, tx);
  5218. c = bb * l1 * l1 + aa * dd - aa * bb;
  5219. let c1 = -2 * bb * l1, c2 = bb - aa;
  5220. d = c1 * c1 - 4 * c2 * c;
  5221. if (d >= 0) {
  5222. let q = Math.sqrt(d);
  5223. if (c1 < 0) q = -q;
  5224. q = -(c1 + q) / 2;
  5225. let r0 = q / c2, r1 = c / q;
  5226. let r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  5227. if (r * r <= dd) {
  5228. y = Math.sqrt(dd - r * r) * bendDir;
  5229. a1 = ta - Math.atan2(y, r);
  5230. a2 = Math.atan2(y / psy, (r - l1) / psx);
  5231. break outer;
  5232. }
  5233. }
  5234. let minAngle = MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  5235. let maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  5236. c = -a * l1 / (aa - bb);
  5237. if (c >= -1 && c <= 1) {
  5238. c = Math.acos(c);
  5239. x = a * Math.cos(c) + l1;
  5240. y = b * Math.sin(c);
  5241. d = x * x + y * y;
  5242. if (d < minDist) {
  5243. minAngle = c;
  5244. minDist = d;
  5245. minX = x;
  5246. minY = y;
  5247. }
  5248. if (d > maxDist) {
  5249. maxAngle = c;
  5250. maxDist = d;
  5251. maxX = x;
  5252. maxY = y;
  5253. }
  5254. }
  5255. if (dd <= (minDist + maxDist) / 2) {
  5256. a1 = ta - Math.atan2(minY * bendDir, minX);
  5257. a2 = minAngle * bendDir;
  5258. } else {
  5259. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  5260. a2 = maxAngle * bendDir;
  5261. }
  5262. }
  5263. let os = Math.atan2(cy, cx) * s2;
  5264. let rotation = parent.arotation;
  5265. a1 = (a1 - os) * MathUtils.radDeg + os1 - rotation;
  5266. if (a1 > 180)
  5267. a1 -= 360;
  5268. else if (a1 < -180) a1 += 360;
  5269. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, parent.ascaleY, 0, 0);
  5270. rotation = child.arotation;
  5271. a2 = ((a2 + os) * MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  5272. if (a2 > 180)
  5273. a2 -= 360;
  5274. else if (a2 < -180) a2 += 360;
  5275. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  5276. }
  5277. }
  5278. /**
  5279. * @public
  5280. */
  5281. class IkConstraintData extends ConstraintData {
  5282. __init() {this.bones = new Array();}
  5283. __init2() {this.bendDirection = 1;}
  5284. __init3() {this.compress = false;}
  5285. __init4() {this.stretch = false;}
  5286. __init5() {this.uniform = false;}
  5287. __init6() {this.mix = 1;}
  5288. __init7() {this.softness = 0;}
  5289. constructor (name) {
  5290. super(name, 0, false);IkConstraintData.prototype.__init.call(this);IkConstraintData.prototype.__init2.call(this);IkConstraintData.prototype.__init3.call(this);IkConstraintData.prototype.__init4.call(this);IkConstraintData.prototype.__init5.call(this);IkConstraintData.prototype.__init6.call(this);IkConstraintData.prototype.__init7.call(this); }
  5291. }
  5292. /**
  5293. * @public
  5294. */
  5295. class PathConstraintData extends ConstraintData {
  5296. __init() {this.bones = new Array();}
  5297. constructor (name) {
  5298. super(name, 0, false);PathConstraintData.prototype.__init.call(this); }
  5299. }
  5300. /**
  5301. * @public
  5302. */
  5303. var PositionMode; (function (PositionMode) {
  5304. const Fixed = 0; PositionMode[PositionMode["Fixed"] = Fixed] = "Fixed"; const Percent = Fixed + 1; PositionMode[PositionMode["Percent"] = Percent] = "Percent";
  5305. })(PositionMode || (PositionMode = {}));
  5306. /**
  5307. * @public
  5308. */
  5309. var SpacingMode; (function (SpacingMode) {
  5310. const Length = 0; SpacingMode[SpacingMode["Length"] = Length] = "Length"; const Fixed = Length + 1; SpacingMode[SpacingMode["Fixed"] = Fixed] = "Fixed"; const Percent = Fixed + 1; SpacingMode[SpacingMode["Percent"] = Percent] = "Percent";
  5311. })(SpacingMode || (SpacingMode = {}));
  5312. /**
  5313. * @public
  5314. */
  5315. var RotateMode; (function (RotateMode) {
  5316. const Tangent = 0; RotateMode[RotateMode["Tangent"] = Tangent] = "Tangent"; const Chain = Tangent + 1; RotateMode[RotateMode["Chain"] = Chain] = "Chain"; const ChainScale = Chain + 1; RotateMode[RotateMode["ChainScale"] = ChainScale] = "ChainScale";
  5317. })(RotateMode || (RotateMode = {}));
  5318. /**
  5319. * @public
  5320. */
  5321. class PathConstraint {
  5322. static __initStatic() {this.NONE = -1;} static __initStatic2() {this.BEFORE = -2;} static __initStatic3() {this.AFTER = -3;}
  5323. static __initStatic4() {this.epsilon = 0.00001;}
  5324. __init() {this.position = 0;} __init2() {this.spacing = 0;} __init3() {this.rotateMix = 0;} __init4() {this.translateMix = 0;}
  5325. __init5() {this.spaces = new Array();} __init6() {this.positions = new Array();}
  5326. __init7() {this.world = new Array();} __init8() {this.curves = new Array();} __init9() {this.lengths = new Array();}
  5327. __init10() {this.segments = new Array();}
  5328. __init11() {this.active = false;}
  5329. constructor (data, skeleton) {PathConstraint.prototype.__init.call(this);PathConstraint.prototype.__init2.call(this);PathConstraint.prototype.__init3.call(this);PathConstraint.prototype.__init4.call(this);PathConstraint.prototype.__init5.call(this);PathConstraint.prototype.__init6.call(this);PathConstraint.prototype.__init7.call(this);PathConstraint.prototype.__init8.call(this);PathConstraint.prototype.__init9.call(this);PathConstraint.prototype.__init10.call(this);PathConstraint.prototype.__init11.call(this);
  5330. if (data == null) throw new Error("data cannot be null.");
  5331. if (skeleton == null) throw new Error("skeleton cannot be null.");
  5332. this.data = data;
  5333. this.bones = new Array();
  5334. for (let i = 0, n = data.bones.length; i < n; i++)
  5335. this.bones.push(skeleton.findBone(data.bones[i].name));
  5336. this.target = skeleton.findSlot(data.target.name);
  5337. this.position = data.position;
  5338. this.spacing = data.spacing;
  5339. this.rotateMix = data.rotateMix;
  5340. this.translateMix = data.translateMix;
  5341. }
  5342. isActive () {
  5343. return this.active;
  5344. }
  5345. apply () {
  5346. this.update();
  5347. }
  5348. update () {
  5349. let attachment = this.target.getAttachment();
  5350. if (!(attachment instanceof PathAttachment)) return;
  5351. let rotateMix = this.rotateMix, translateMix = this.translateMix;
  5352. let translate = translateMix > 0, rotate = rotateMix > 0;
  5353. if (!translate && !rotate) return;
  5354. let data = this.data;
  5355. let spacingMode = data.spacingMode;
  5356. let lengthSpacing = spacingMode == SpacingMode.Length;
  5357. let rotateMode = data.rotateMode;
  5358. let tangents = rotateMode == RotateMode.Tangent, scale = rotateMode == RotateMode.ChainScale;
  5359. let boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  5360. let bones = this.bones;
  5361. let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths = null;
  5362. let spacing = this.spacing;
  5363. if (scale || lengthSpacing) {
  5364. if (scale) lengths = Utils.setArraySize(this.lengths, boneCount);
  5365. for (let i = 0, n = spacesCount - 1; i < n;) {
  5366. let bone = bones[i];
  5367. let setupLength = bone.data.length;
  5368. if (setupLength < PathConstraint.epsilon) {
  5369. if (scale) lengths[i] = 0;
  5370. spaces[++i] = 0;
  5371. } else {
  5372. let x = setupLength * bone.matrix.a, y = setupLength * bone.matrix.b;
  5373. let length = Math.sqrt(x * x + y * y);
  5374. if (scale) lengths[i] = length;
  5375. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
  5376. }
  5377. }
  5378. } else {
  5379. for (let i = 1; i < spacesCount; i++)
  5380. spaces[i] = spacing;
  5381. }
  5382. let positions = this.computeWorldPositions(attachment, spacesCount, tangents,
  5383. data.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent);
  5384. let boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  5385. let tip = false;
  5386. if (offsetRotation == 0)
  5387. tip = rotateMode == RotateMode.Chain;
  5388. else {
  5389. tip = false;
  5390. let p = this.target.bone.matrix;
  5391. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.degRad : -MathUtils.degRad;
  5392. }
  5393. for (let i = 0, p = 3; i < boneCount; i++, p += 3) {
  5394. let bone = bones[i];
  5395. let mat = bone.matrix;
  5396. mat.tx += (boneX - mat.tx) * translateMix;
  5397. mat.ty += (boneY - mat.ty) * translateMix;
  5398. let x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  5399. if (scale) {
  5400. let length = lengths[i];
  5401. if (length != 0) {
  5402. let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * rotateMix + 1;
  5403. mat.a *= s;
  5404. mat.b *= s;
  5405. }
  5406. }
  5407. boneX = x;
  5408. boneY = y;
  5409. if (rotate) {
  5410. let a = mat.a, b = mat.c, c = mat.b, d = mat.d, r = 0, cos = 0, sin = 0;
  5411. if (tangents)
  5412. r = positions[p - 1];
  5413. else if (spaces[i + 1] == 0)
  5414. r = positions[p + 2];
  5415. else
  5416. r = Math.atan2(dy, dx);
  5417. r -= Math.atan2(c, a);
  5418. if (tip) {
  5419. cos = Math.cos(r);
  5420. sin = Math.sin(r);
  5421. let length = bone.data.length;
  5422. boneX += (length * (cos * a - sin * c) - dx) * rotateMix;
  5423. boneY += (length * (sin * a + cos * c) - dy) * rotateMix;
  5424. } else {
  5425. r += offsetRotation;
  5426. }
  5427. if (r > MathUtils.PI)
  5428. r -= MathUtils.PI2;
  5429. else if (r < -MathUtils.PI) //
  5430. r += MathUtils.PI2;
  5431. r *= rotateMix;
  5432. cos = Math.cos(r);
  5433. sin = Math.sin(r);
  5434. mat.a = cos * a - sin * c;
  5435. mat.c = cos * b - sin * d;
  5436. mat.b = sin * a + cos * c;
  5437. mat.d = sin * b + cos * d;
  5438. }
  5439. bone.appliedValid = false;
  5440. }
  5441. }
  5442. computeWorldPositions (path, spacesCount, tangents, percentPosition,
  5443. percentSpacing) {
  5444. let target = this.target;
  5445. let position = this.position;
  5446. let spaces = this.spaces, out = Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  5447. let closed = path.closed;
  5448. let verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint.NONE;
  5449. if (!path.constantSpeed) {
  5450. let lengths = path.lengths;
  5451. curveCount -= closed ? 1 : 2;
  5452. let pathLength = lengths[curveCount];
  5453. if (percentPosition) position *= pathLength;
  5454. if (percentSpacing) {
  5455. for (let i = 0; i < spacesCount; i++)
  5456. spaces[i] *= pathLength;
  5457. }
  5458. world = Utils.setArraySize(this.world, 8);
  5459. for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  5460. let space = spaces[i];
  5461. position += space;
  5462. let p = position;
  5463. if (closed) {
  5464. p %= pathLength;
  5465. if (p < 0) p += pathLength;
  5466. curve = 0;
  5467. } else if (p < 0) {
  5468. if (prevCurve != PathConstraint.BEFORE) {
  5469. prevCurve = PathConstraint.BEFORE;
  5470. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  5471. }
  5472. this.addBeforePosition(p, world, 0, out, o);
  5473. continue;
  5474. } else if (p > pathLength) {
  5475. if (prevCurve != PathConstraint.AFTER) {
  5476. prevCurve = PathConstraint.AFTER;
  5477. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  5478. }
  5479. this.addAfterPosition(p - pathLength, world, 0, out, o);
  5480. continue;
  5481. }
  5482. // Determine curve containing position.
  5483. for (;; curve++) {
  5484. let length = lengths[curve];
  5485. if (p > length) continue;
  5486. if (curve == 0)
  5487. p /= length;
  5488. else {
  5489. let prev = lengths[curve - 1];
  5490. p = (p - prev) / (length - prev);
  5491. }
  5492. break;
  5493. }
  5494. if (curve != prevCurve) {
  5495. prevCurve = curve;
  5496. if (closed && curve == curveCount) {
  5497. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  5498. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  5499. } else
  5500. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  5501. }
  5502. this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o,
  5503. tangents || (i > 0 && space == 0));
  5504. }
  5505. return out;
  5506. }
  5507. // World vertices.
  5508. if (closed) {
  5509. verticesLength += 2;
  5510. world = Utils.setArraySize(this.world, verticesLength);
  5511. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  5512. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  5513. world[verticesLength - 2] = world[0];
  5514. world[verticesLength - 1] = world[1];
  5515. } else {
  5516. curveCount--;
  5517. verticesLength -= 4;
  5518. world = Utils.setArraySize(this.world, verticesLength);
  5519. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  5520. }
  5521. // Curve lengths.
  5522. let curves = Utils.setArraySize(this.curves, curveCount);
  5523. let pathLength = 0;
  5524. let x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  5525. let tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  5526. for (let i = 0, w = 2; i < curveCount; i++, w += 6) {
  5527. cx1 = world[w];
  5528. cy1 = world[w + 1];
  5529. cx2 = world[w + 2];
  5530. cy2 = world[w + 3];
  5531. x2 = world[w + 4];
  5532. y2 = world[w + 5];
  5533. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  5534. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  5535. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  5536. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  5537. ddfx = tmpx * 2 + dddfx;
  5538. ddfy = tmpy * 2 + dddfy;
  5539. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  5540. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  5541. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5542. dfx += ddfx;
  5543. dfy += ddfy;
  5544. ddfx += dddfx;
  5545. ddfy += dddfy;
  5546. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5547. dfx += ddfx;
  5548. dfy += ddfy;
  5549. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5550. dfx += ddfx + dddfx;
  5551. dfy += ddfy + dddfy;
  5552. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5553. curves[i] = pathLength;
  5554. x1 = x2;
  5555. y1 = y2;
  5556. }
  5557. if (percentPosition) position *= pathLength;
  5558. if (percentSpacing) {
  5559. for (let i = 0; i < spacesCount; i++)
  5560. spaces[i] *= pathLength;
  5561. }
  5562. let segments = this.segments;
  5563. let curveLength = 0;
  5564. for (let i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  5565. let space = spaces[i];
  5566. position += space;
  5567. let p = position;
  5568. if (closed) {
  5569. p %= pathLength;
  5570. if (p < 0) p += pathLength;
  5571. curve = 0;
  5572. } else if (p < 0) {
  5573. this.addBeforePosition(p, world, 0, out, o);
  5574. continue;
  5575. } else if (p > pathLength) {
  5576. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  5577. continue;
  5578. }
  5579. // Determine curve containing position.
  5580. for (;; curve++) {
  5581. let length = curves[curve];
  5582. if (p > length) continue;
  5583. if (curve == 0)
  5584. p /= length;
  5585. else {
  5586. let prev = curves[curve - 1];
  5587. p = (p - prev) / (length - prev);
  5588. }
  5589. break;
  5590. }
  5591. // Curve segment lengths.
  5592. if (curve != prevCurve) {
  5593. prevCurve = curve;
  5594. let ii = curve * 6;
  5595. x1 = world[ii];
  5596. y1 = world[ii + 1];
  5597. cx1 = world[ii + 2];
  5598. cy1 = world[ii + 3];
  5599. cx2 = world[ii + 4];
  5600. cy2 = world[ii + 5];
  5601. x2 = world[ii + 6];
  5602. y2 = world[ii + 7];
  5603. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  5604. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  5605. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  5606. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  5607. ddfx = tmpx * 2 + dddfx;
  5608. ddfy = tmpy * 2 + dddfy;
  5609. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  5610. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  5611. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  5612. segments[0] = curveLength;
  5613. for (ii = 1; ii < 8; ii++) {
  5614. dfx += ddfx;
  5615. dfy += ddfy;
  5616. ddfx += dddfx;
  5617. ddfy += dddfy;
  5618. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5619. segments[ii] = curveLength;
  5620. }
  5621. dfx += ddfx;
  5622. dfy += ddfy;
  5623. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5624. segments[8] = curveLength;
  5625. dfx += ddfx + dddfx;
  5626. dfy += ddfy + dddfy;
  5627. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  5628. segments[9] = curveLength;
  5629. segment = 0;
  5630. }
  5631. // Weight by segment length.
  5632. p *= curveLength;
  5633. for (;; segment++) {
  5634. let length = segments[segment];
  5635. if (p > length) continue;
  5636. if (segment == 0)
  5637. p /= length;
  5638. else {
  5639. let prev = segments[segment - 1];
  5640. p = segment + (p - prev) / (length - prev);
  5641. }
  5642. break;
  5643. }
  5644. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  5645. }
  5646. return out;
  5647. }
  5648. addBeforePosition (p, temp, i, out, o) {
  5649. let x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  5650. out[o] = x1 + p * Math.cos(r);
  5651. out[o + 1] = y1 + p * Math.sin(r);
  5652. out[o + 2] = r;
  5653. }
  5654. addAfterPosition (p, temp, i, out, o) {
  5655. let x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  5656. out[o] = x1 + p * Math.cos(r);
  5657. out[o + 1] = y1 + p * Math.sin(r);
  5658. out[o + 2] = r;
  5659. }
  5660. addCurvePosition (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2,
  5661. out, o, tangents) {
  5662. if (p == 0 || isNaN(p)) p = 0.0001;
  5663. let tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  5664. let ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  5665. let x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  5666. out[o] = x;
  5667. out[o + 1] = y;
  5668. if (tangents) out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  5669. }
  5670. } PathConstraint.__initStatic(); PathConstraint.__initStatic2(); PathConstraint.__initStatic3(); PathConstraint.__initStatic4();
  5671. /**
  5672. * @public
  5673. */
  5674. class Slot {
  5675. //this is canon
  5676. __init() {this.deform = new Array();}
  5677. constructor (data, bone) {Slot.prototype.__init.call(this);
  5678. if (data == null) throw new Error("data cannot be null.");
  5679. if (bone == null) throw new Error("bone cannot be null.");
  5680. this.data = data;
  5681. this.bone = bone;
  5682. this.color = new Color();
  5683. this.darkColor = data.darkColor == null ? null : new Color();
  5684. this.setToSetupPose();
  5685. this.blendMode = this.data.blendMode;
  5686. }
  5687. /** @return May be null. */
  5688. getAttachment () {
  5689. return this.attachment;
  5690. }
  5691. /** Sets the attachment and if it changed, resets {@link #getAttachmentTime()} and clears {@link #getAttachmentVertices()}.
  5692. * @param attachment May be null. */
  5693. setAttachment (attachment) {
  5694. if (this.attachment == attachment) return;
  5695. this.attachment = attachment;
  5696. this.attachmentTime = this.bone.skeleton.time;
  5697. this.deform.length = 0;
  5698. }
  5699. setAttachmentTime (time) {
  5700. this.attachmentTime = this.bone.skeleton.time - time;
  5701. }
  5702. /** Returns the time since the attachment was set. */
  5703. getAttachmentTime () {
  5704. return this.bone.skeleton.time - this.attachmentTime;
  5705. }
  5706. setToSetupPose () {
  5707. this.color.setFromColor(this.data.color);
  5708. if (this.darkColor != null) this.darkColor.setFromColor(this.data.darkColor);
  5709. if (this.data.attachmentName == null)
  5710. this.attachment = null;
  5711. else {
  5712. this.attachment = null;
  5713. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  5714. }
  5715. }
  5716. }
  5717. /**
  5718. * @public
  5719. */
  5720. class TransformConstraint {
  5721. __init() {this.rotateMix = 0;}
  5722. __init2() {this.translateMix = 0;}
  5723. __init3() {this.scaleMix = 0;}
  5724. __init4() {this.shearMix = 0;}
  5725. __init5() {this.temp = new Vector2();}
  5726. __init6() {this.active = false;}
  5727. constructor(data, skeleton) {TransformConstraint.prototype.__init.call(this);TransformConstraint.prototype.__init2.call(this);TransformConstraint.prototype.__init3.call(this);TransformConstraint.prototype.__init4.call(this);TransformConstraint.prototype.__init5.call(this);TransformConstraint.prototype.__init6.call(this);
  5728. if (data == null) throw new Error("data cannot be null.");
  5729. if (skeleton == null) throw new Error("skeleton cannot be null.");
  5730. this.data = data;
  5731. this.rotateMix = data.rotateMix;
  5732. this.translateMix = data.translateMix;
  5733. this.scaleMix = data.scaleMix;
  5734. this.shearMix = data.shearMix;
  5735. this.bones = new Array();
  5736. for (let i = 0; i < data.bones.length; i++)
  5737. this.bones.push(skeleton.findBone(data.bones[i].name));
  5738. this.target = skeleton.findBone(data.target.name);
  5739. }
  5740. isActive () {
  5741. return this.active;
  5742. }
  5743. apply() {
  5744. this.update();
  5745. }
  5746. update() {
  5747. if (this.data.local) {
  5748. if (this.data.relative)
  5749. this.applyRelativeLocal();
  5750. else
  5751. this.applyAbsoluteLocal();
  5752. } else {
  5753. if (this.data.relative)
  5754. this.applyRelativeWorld();
  5755. else
  5756. this.applyAbsoluteWorld();
  5757. }
  5758. }
  5759. applyAbsoluteWorld() {
  5760. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  5761. shearMix = this.shearMix;
  5762. let target = this.target;
  5763. let targetMat = target.matrix;
  5764. let ta = targetMat.a, tb = targetMat.c, tc = targetMat.b, td = targetMat.d;
  5765. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  5766. let offsetRotation = this.data.offsetRotation * degRadReflect;
  5767. let offsetShearY = this.data.offsetShearY * degRadReflect;
  5768. let bones = this.bones;
  5769. for (let i = 0, n = bones.length; i < n; i++) {
  5770. let bone = bones[i];
  5771. let modified = false;
  5772. let mat = bone.matrix;
  5773. if (rotateMix != 0) {
  5774. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  5775. let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  5776. if (r > MathUtils.PI)
  5777. r -= MathUtils.PI2;
  5778. else if (r < -MathUtils.PI)
  5779. r += MathUtils.PI2;
  5780. r *= rotateMix;
  5781. let cos = Math.cos(r), sin = Math.sin(r);
  5782. mat.a = cos * a - sin * c;
  5783. mat.c = cos * b - sin * d;
  5784. mat.b = sin * a + cos * c;
  5785. mat.d = sin * b + cos * d;
  5786. modified = true;
  5787. }
  5788. if (translateMix != 0) {
  5789. let temp = this.temp;
  5790. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  5791. mat.tx += (temp.x - mat.tx) * translateMix;
  5792. mat.ty += (temp.y - mat.ty) * translateMix;
  5793. modified = true;
  5794. }
  5795. if (scaleMix > 0) {
  5796. let s = Math.sqrt(mat.a * mat.a + mat.b * mat.b);
  5797. let ts = Math.sqrt(ta * ta + tc * tc);
  5798. if (s > 0.00001) s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
  5799. mat.a *= s;
  5800. mat.b *= s;
  5801. s = Math.sqrt(mat.c * mat.c + mat.d * mat.d);
  5802. ts = Math.sqrt(tb * tb + td * td);
  5803. if (s > 0.00001) s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
  5804. mat.c *= s;
  5805. mat.d *= s;
  5806. modified = true;
  5807. }
  5808. if (shearMix > 0) {
  5809. let b = mat.c, d = mat.d;
  5810. let by = Math.atan2(d, b);
  5811. let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(mat.b, mat.a));
  5812. if (r > MathUtils.PI)
  5813. r -= MathUtils.PI2;
  5814. else if (r < -MathUtils.PI)
  5815. r += MathUtils.PI2;
  5816. r = by + (r + offsetShearY) * shearMix;
  5817. let s = Math.sqrt(b * b + d * d);
  5818. mat.c = Math.cos(r) * s;
  5819. mat.d = Math.sin(r) * s;
  5820. modified = true;
  5821. }
  5822. if (modified) bone.appliedValid = false;
  5823. }
  5824. }
  5825. applyRelativeWorld() {
  5826. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  5827. shearMix = this.shearMix;
  5828. let target = this.target;
  5829. let targetMat = target.matrix;
  5830. let ta = targetMat.a, tb = targetMat.c, tc = targetMat.b, td = targetMat.d;
  5831. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  5832. let offsetRotation = this.data.offsetRotation * degRadReflect,
  5833. offsetShearY = this.data.offsetShearY * degRadReflect;
  5834. let bones = this.bones;
  5835. for (let i = 0, n = bones.length; i < n; i++) {
  5836. let bone = bones[i];
  5837. let modified = false;
  5838. let mat = bone.matrix;
  5839. if (rotateMix != 0) {
  5840. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  5841. let r = Math.atan2(tc, ta) + offsetRotation;
  5842. if (r > MathUtils.PI)
  5843. r -= MathUtils.PI2;
  5844. else if (r < -MathUtils.PI) r += MathUtils.PI2;
  5845. r *= rotateMix;
  5846. let cos = Math.cos(r), sin = Math.sin(r);
  5847. mat.a = cos * a - sin * c;
  5848. mat.c = cos * b - sin * d;
  5849. mat.b = sin * a + cos * c;
  5850. mat.d = sin * b + cos * d;
  5851. modified = true;
  5852. }
  5853. if (translateMix != 0) {
  5854. let temp = this.temp;
  5855. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  5856. mat.tx += temp.x * translateMix;
  5857. mat.ty += temp.y * translateMix;
  5858. modified = true;
  5859. }
  5860. if (scaleMix > 0) {
  5861. let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
  5862. mat.a *= s;
  5863. mat.b *= s;
  5864. s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
  5865. mat.c *= s;
  5866. mat.d *= s;
  5867. modified = true;
  5868. }
  5869. if (shearMix > 0) {
  5870. let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  5871. if (r > MathUtils.PI)
  5872. r -= MathUtils.PI2;
  5873. else if (r < -MathUtils.PI) r += MathUtils.PI2;
  5874. let b = mat.c, d = mat.d;
  5875. r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * shearMix;
  5876. let s = Math.sqrt(b * b + d * d);
  5877. mat.c = Math.cos(r) * s;
  5878. mat.d = Math.sin(r) * s;
  5879. modified = true;
  5880. }
  5881. if (modified) bone.appliedValid = false;
  5882. }
  5883. }
  5884. applyAbsoluteLocal() {
  5885. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  5886. shearMix = this.shearMix;
  5887. let target = this.target;
  5888. if (!target.appliedValid) target.updateAppliedTransform();
  5889. let bones = this.bones;
  5890. for (let i = 0, n = bones.length; i < n; i++) {
  5891. let bone = bones[i];
  5892. if (!bone.appliedValid) bone.updateAppliedTransform();
  5893. let rotation = bone.arotation;
  5894. if (rotateMix != 0) {
  5895. let r = target.arotation - rotation + this.data.offsetRotation;
  5896. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  5897. rotation += r * rotateMix;
  5898. }
  5899. let x = bone.ax, y = bone.ay;
  5900. if (translateMix != 0) {
  5901. x += (target.ax - x + this.data.offsetX) * translateMix;
  5902. y += (target.ay - y + this.data.offsetY) * translateMix;
  5903. }
  5904. let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  5905. if (scaleMix > 0) {
  5906. if (scaleX > 0.00001) scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
  5907. if (scaleY > 0.00001) scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
  5908. }
  5909. let shearY = bone.ashearY;
  5910. if (shearMix > 0) {
  5911. let r = target.ashearY - shearY + this.data.offsetShearY;
  5912. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  5913. bone.shearY += r * shearMix;
  5914. }
  5915. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  5916. }
  5917. }
  5918. applyRelativeLocal() {
  5919. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  5920. shearMix = this.shearMix;
  5921. let target = this.target;
  5922. if (!target.appliedValid) target.updateAppliedTransform();
  5923. let bones = this.bones;
  5924. for (let i = 0, n = bones.length; i < n; i++) {
  5925. let bone = bones[i];
  5926. if (!bone.appliedValid) bone.updateAppliedTransform();
  5927. let rotation = bone.arotation;
  5928. if (rotateMix != 0) rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
  5929. let x = bone.ax, y = bone.ay;
  5930. if (translateMix != 0) {
  5931. x += (target.ax + this.data.offsetX) * translateMix;
  5932. y += (target.ay + this.data.offsetY) * translateMix;
  5933. }
  5934. let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  5935. if (scaleMix > 0) {
  5936. if (scaleX > 0.00001) scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
  5937. if (scaleY > 0.00001) scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
  5938. }
  5939. let shearY = bone.ashearY;
  5940. if (shearMix > 0) shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
  5941. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  5942. }
  5943. }
  5944. }
  5945. /**
  5946. * @public
  5947. */
  5948. class Skeleton {
  5949. __init() {this._updateCache = new Array();}
  5950. __init2() {this.updateCacheReset = new Array();}
  5951. __init3() {this.time = 0;}
  5952. __init4() {this.scaleX = 1;} __init5() {this.scaleY = 1;}
  5953. __init6() {this.x = 0;} __init7() {this.y = 0;}
  5954. constructor (data) {Skeleton.prototype.__init.call(this);Skeleton.prototype.__init2.call(this);Skeleton.prototype.__init3.call(this);Skeleton.prototype.__init4.call(this);Skeleton.prototype.__init5.call(this);Skeleton.prototype.__init6.call(this);Skeleton.prototype.__init7.call(this);
  5955. if (data == null) throw new Error("data cannot be null.");
  5956. this.data = data;
  5957. this.bones = new Array();
  5958. for (let i = 0; i < data.bones.length; i++) {
  5959. let boneData = data.bones[i];
  5960. let bone;
  5961. if (boneData.parent == null)
  5962. bone = new Bone(boneData, this, null);
  5963. else {
  5964. let parent = this.bones[boneData.parent.index];
  5965. bone = new Bone(boneData, this, parent);
  5966. parent.children.push(bone);
  5967. }
  5968. this.bones.push(bone);
  5969. }
  5970. this.slots = new Array();
  5971. this.drawOrder = new Array();
  5972. for (let i = 0; i < data.slots.length; i++) {
  5973. let slotData = data.slots[i];
  5974. let bone = this.bones[slotData.boneData.index];
  5975. let slot = new Slot(slotData, bone);
  5976. this.slots.push(slot);
  5977. this.drawOrder.push(slot);
  5978. }
  5979. this.ikConstraints = new Array();
  5980. for (let i = 0; i < data.ikConstraints.length; i++) {
  5981. let ikConstraintData = data.ikConstraints[i];
  5982. this.ikConstraints.push(new IkConstraint(ikConstraintData, this));
  5983. }
  5984. this.transformConstraints = new Array();
  5985. for (let i = 0; i < data.transformConstraints.length; i++) {
  5986. let transformConstraintData = data.transformConstraints[i];
  5987. this.transformConstraints.push(new TransformConstraint(transformConstraintData, this));
  5988. }
  5989. this.pathConstraints = new Array();
  5990. for (let i = 0; i < data.pathConstraints.length; i++) {
  5991. let pathConstraintData = data.pathConstraints[i];
  5992. this.pathConstraints.push(new PathConstraint(pathConstraintData, this));
  5993. }
  5994. this.color = new Color(1, 1, 1, 1);
  5995. this.updateCache();
  5996. }
  5997. updateCache () {
  5998. let updateCache = this._updateCache;
  5999. updateCache.length = 0;
  6000. this.updateCacheReset.length = 0;
  6001. let bones = this.bones;
  6002. for (let i = 0, n = bones.length; i < n; i++) {
  6003. let bone = bones[i];
  6004. bone.sorted = bone.data.skinRequired;
  6005. bone.active = !bone.sorted;
  6006. }
  6007. if (this.skin != null) {
  6008. let skinBones = this.skin.bones;
  6009. for (let i = 0, n = this.skin.bones.length; i < n; i++) {
  6010. let bone = this.bones[skinBones[i].index];
  6011. do {
  6012. bone.sorted = false;
  6013. bone.active = true;
  6014. bone = bone.parent;
  6015. } while (bone != null);
  6016. }
  6017. }
  6018. // IK first, lowest hierarchy depth first.
  6019. let ikConstraints = this.ikConstraints;
  6020. let transformConstraints = this.transformConstraints;
  6021. let pathConstraints = this.pathConstraints;
  6022. let ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  6023. let constraintCount = ikCount + transformCount + pathCount;
  6024. outer:
  6025. for (let i = 0; i < constraintCount; i++) {
  6026. for (let ii = 0; ii < ikCount; ii++) {
  6027. let constraint = ikConstraints[ii];
  6028. if (constraint.data.order == i) {
  6029. this.sortIkConstraint(constraint);
  6030. continue outer;
  6031. }
  6032. }
  6033. for (let ii = 0; ii < transformCount; ii++) {
  6034. let constraint = transformConstraints[ii];
  6035. if (constraint.data.order == i) {
  6036. this.sortTransformConstraint(constraint);
  6037. continue outer;
  6038. }
  6039. }
  6040. for (let ii = 0; ii < pathCount; ii++) {
  6041. let constraint = pathConstraints[ii];
  6042. if (constraint.data.order == i) {
  6043. this.sortPathConstraint(constraint);
  6044. continue outer;
  6045. }
  6046. }
  6047. }
  6048. for (let i = 0, n = bones.length; i < n; i++)
  6049. this.sortBone(bones[i]);
  6050. }
  6051. sortIkConstraint (constraint) {
  6052. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)));
  6053. if (!constraint.active) return;
  6054. let target = constraint.target;
  6055. this.sortBone(target);
  6056. let constrained = constraint.bones;
  6057. let parent = constrained[0];
  6058. this.sortBone(parent);
  6059. if (constrained.length > 1) {
  6060. let child = constrained[constrained.length - 1];
  6061. if (!(this._updateCache.indexOf(child) > -1)) this.updateCacheReset.push(child);
  6062. }
  6063. this._updateCache.push(constraint);
  6064. this.sortReset(parent.children);
  6065. constrained[constrained.length - 1].sorted = true;
  6066. }
  6067. sortPathConstraint (constraint) {
  6068. constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || (this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)));
  6069. if (!constraint.active) return;
  6070. let slot = constraint.target;
  6071. let slotIndex = slot.data.index;
  6072. let slotBone = slot.bone;
  6073. if (this.skin != null) this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  6074. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  6075. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  6076. for (let i = 0, n = this.data.skins.length; i < n; i++)
  6077. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  6078. let attachment = slot.getAttachment();
  6079. if (attachment instanceof PathAttachment) this.sortPathConstraintAttachmentWith(attachment, slotBone);
  6080. let constrained = constraint.bones;
  6081. let boneCount = constrained.length;
  6082. for (let i = 0; i < boneCount; i++)
  6083. this.sortBone(constrained[i]);
  6084. this._updateCache.push(constraint);
  6085. for (let i = 0; i < boneCount; i++)
  6086. this.sortReset(constrained[i].children);
  6087. for (let i = 0; i < boneCount; i++)
  6088. constrained[i].sorted = true;
  6089. }
  6090. sortTransformConstraint (constraint) {
  6091. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)));
  6092. if (!constraint.active) return;
  6093. this.sortBone(constraint.target);
  6094. let constrained = constraint.bones;
  6095. let boneCount = constrained.length;
  6096. if (constraint.data.local) {
  6097. for (let i = 0; i < boneCount; i++) {
  6098. let child = constrained[i];
  6099. this.sortBone(child.parent);
  6100. if (!(this._updateCache.indexOf(child) > -1)) this.updateCacheReset.push(child);
  6101. }
  6102. } else {
  6103. for (let i = 0; i < boneCount; i++) {
  6104. this.sortBone(constrained[i]);
  6105. }
  6106. }
  6107. this._updateCache.push(constraint);
  6108. for (let ii = 0; ii < boneCount; ii++)
  6109. this.sortReset(constrained[ii].children);
  6110. for (let ii = 0; ii < boneCount; ii++)
  6111. constrained[ii].sorted = true;
  6112. }
  6113. sortPathConstraintAttachment (skin, slotIndex, slotBone) {
  6114. let attachments = skin.attachments[slotIndex];
  6115. if (!attachments) return;
  6116. for (let key in attachments) {
  6117. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  6118. }
  6119. }
  6120. sortPathConstraintAttachmentWith (attachment, slotBone) {
  6121. if (!(attachment instanceof PathAttachment)) return;
  6122. let pathBones = (attachment).bones;
  6123. if (pathBones == null)
  6124. this.sortBone(slotBone);
  6125. else {
  6126. let bones = this.bones;
  6127. let i = 0;
  6128. while (i < pathBones.length) {
  6129. let boneCount = pathBones[i++];
  6130. for (let n = i + boneCount; i < n; i++) {
  6131. let boneIndex = pathBones[i];
  6132. this.sortBone(bones[boneIndex]);
  6133. }
  6134. }
  6135. }
  6136. }
  6137. sortBone (bone) {
  6138. if (bone.sorted) return;
  6139. let parent = bone.parent;
  6140. if (parent != null) this.sortBone(parent);
  6141. bone.sorted = true;
  6142. this._updateCache.push(bone);
  6143. }
  6144. sortReset (bones) {
  6145. for (let i = 0, n = bones.length; i < n; i++) {
  6146. let bone = bones[i];
  6147. if (!bone.active) continue;
  6148. if (bone.sorted) this.sortReset(bone.children);
  6149. bone.sorted = false;
  6150. }
  6151. }
  6152. /** Updates the world transform for each bone and applies constraints. */
  6153. updateWorldTransform () {
  6154. let updateCacheReset = this.updateCacheReset;
  6155. for (let i = 0, n = updateCacheReset.length; i < n; i++) {
  6156. let bone = updateCacheReset[i] ;
  6157. bone.ax = bone.x;
  6158. bone.ay = bone.y;
  6159. bone.arotation = bone.rotation;
  6160. bone.ascaleX = bone.scaleX;
  6161. bone.ascaleY = bone.scaleY;
  6162. bone.ashearX = bone.shearX;
  6163. bone.ashearY = bone.shearY;
  6164. bone.appliedValid = true;
  6165. }
  6166. let updateCache = this._updateCache;
  6167. for (let i = 0, n = updateCache.length; i < n; i++)
  6168. updateCache[i].update();
  6169. }
  6170. /** Sets the bones, constraints, and slots to their setup pose values. */
  6171. setToSetupPose () {
  6172. this.setBonesToSetupPose();
  6173. this.setSlotsToSetupPose();
  6174. }
  6175. /** Sets the bones and constraints to their setup pose values. */
  6176. setBonesToSetupPose () {
  6177. let bones = this.bones;
  6178. for (let i = 0, n = bones.length; i < n; i++)
  6179. bones[i].setToSetupPose();
  6180. let ikConstraints = this.ikConstraints;
  6181. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  6182. let constraint = ikConstraints[i];
  6183. constraint.mix = constraint.data.mix;
  6184. constraint.softness = constraint.data.softness;
  6185. constraint.bendDirection = constraint.data.bendDirection;
  6186. constraint.compress = constraint.data.compress;
  6187. constraint.stretch = constraint.data.stretch;
  6188. }
  6189. let transformConstraints = this.transformConstraints;
  6190. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  6191. let constraint = transformConstraints[i];
  6192. let data = constraint.data;
  6193. constraint.rotateMix = data.rotateMix;
  6194. constraint.translateMix = data.translateMix;
  6195. constraint.scaleMix = data.scaleMix;
  6196. constraint.shearMix = data.shearMix;
  6197. }
  6198. let pathConstraints = this.pathConstraints;
  6199. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  6200. let constraint = pathConstraints[i];
  6201. let data = constraint.data;
  6202. constraint.position = data.position;
  6203. constraint.spacing = data.spacing;
  6204. constraint.rotateMix = data.rotateMix;
  6205. constraint.translateMix = data.translateMix;
  6206. }
  6207. }
  6208. setSlotsToSetupPose () {
  6209. let slots = this.slots;
  6210. Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  6211. for (let i = 0, n = slots.length; i < n; i++)
  6212. slots[i].setToSetupPose();
  6213. }
  6214. /** @return May return null. */
  6215. getRootBone () {
  6216. if (this.bones.length == 0) return null;
  6217. return this.bones[0];
  6218. }
  6219. /** @return May be null. */
  6220. findBone (boneName) {
  6221. if (boneName == null) throw new Error("boneName cannot be null.");
  6222. let bones = this.bones;
  6223. for (let i = 0, n = bones.length; i < n; i++) {
  6224. let bone = bones[i];
  6225. if (bone.data.name == boneName) return bone;
  6226. }
  6227. return null;
  6228. }
  6229. /** @return -1 if the bone was not found. */
  6230. findBoneIndex (boneName) {
  6231. if (boneName == null) throw new Error("boneName cannot be null.");
  6232. let bones = this.bones;
  6233. for (let i = 0, n = bones.length; i < n; i++)
  6234. if (bones[i].data.name == boneName) return i;
  6235. return -1;
  6236. }
  6237. /** @return May be null. */
  6238. findSlot (slotName) {
  6239. if (slotName == null) throw new Error("slotName cannot be null.");
  6240. let slots = this.slots;
  6241. for (let i = 0, n = slots.length; i < n; i++) {
  6242. let slot = slots[i];
  6243. if (slot.data.name == slotName) return slot;
  6244. }
  6245. return null;
  6246. }
  6247. /** @return -1 if the bone was not found. */
  6248. findSlotIndex (slotName) {
  6249. if (slotName == null) throw new Error("slotName cannot be null.");
  6250. let slots = this.slots;
  6251. for (let i = 0, n = slots.length; i < n; i++)
  6252. if (slots[i].data.name == slotName) return i;
  6253. return -1;
  6254. }
  6255. /** Sets a skin by name.
  6256. * @see #setSkin(Skin) */
  6257. setSkinByName (skinName) {
  6258. let skin = this.data.findSkin(skinName);
  6259. if (skin == null) throw new Error("Skin not found: " + skinName);
  6260. this.setSkin(skin);
  6261. }
  6262. /** Sets the skin used to look up attachments before looking in the {@link SkeletonData#getDefaultSkin() default skin}.
  6263. * Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. If there was no
  6264. * old skin, each slot's setup mode attachment is attached from the new skin.
  6265. * @param newSkin May be null. */
  6266. setSkin (newSkin) {
  6267. if (newSkin == this.skin) return;
  6268. if (newSkin != null) {
  6269. if (this.skin != null)
  6270. newSkin.attachAll(this, this.skin);
  6271. else {
  6272. let slots = this.slots;
  6273. for (let i = 0, n = slots.length; i < n; i++) {
  6274. let slot = slots[i];
  6275. let name = slot.data.attachmentName;
  6276. if (name != null) {
  6277. let attachment = newSkin.getAttachment(i, name);
  6278. if (attachment != null) slot.setAttachment(attachment);
  6279. }
  6280. }
  6281. }
  6282. }
  6283. this.skin = newSkin;
  6284. this.updateCache();
  6285. }
  6286. /** @return May be null. */
  6287. getAttachmentByName (slotName, attachmentName) {
  6288. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  6289. }
  6290. /** @return May be null. */
  6291. getAttachment (slotIndex, attachmentName) {
  6292. if (attachmentName == null) throw new Error("attachmentName cannot be null.");
  6293. if (this.skin != null) {
  6294. let attachment = this.skin.getAttachment(slotIndex, attachmentName);
  6295. if (attachment != null) return attachment;
  6296. }
  6297. if (this.data.defaultSkin != null) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  6298. return null;
  6299. }
  6300. /** @param attachmentName May be null. */
  6301. setAttachment (slotName, attachmentName) {
  6302. if (slotName == null) throw new Error("slotName cannot be null.");
  6303. let slots = this.slots;
  6304. for (let i = 0, n = slots.length; i < n; i++) {
  6305. let slot = slots[i];
  6306. if (slot.data.name == slotName) {
  6307. let attachment = null;
  6308. if (attachmentName != null) {
  6309. attachment = this.getAttachment(i, attachmentName);
  6310. if (attachment == null)
  6311. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  6312. }
  6313. slot.setAttachment(attachment);
  6314. return;
  6315. }
  6316. }
  6317. throw new Error("Slot not found: " + slotName);
  6318. }
  6319. /** @return May be null. */
  6320. findIkConstraint (constraintName) {
  6321. if (constraintName == null) throw new Error("constraintName cannot be null.");
  6322. let ikConstraints = this.ikConstraints;
  6323. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  6324. let ikConstraint = ikConstraints[i];
  6325. if (ikConstraint.data.name == constraintName) return ikConstraint;
  6326. }
  6327. return null;
  6328. }
  6329. /** @return May be null. */
  6330. findTransformConstraint (constraintName) {
  6331. if (constraintName == null) throw new Error("constraintName cannot be null.");
  6332. let transformConstraints = this.transformConstraints;
  6333. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  6334. let constraint = transformConstraints[i];
  6335. if (constraint.data.name == constraintName) return constraint;
  6336. }
  6337. return null;
  6338. }
  6339. /** @return May be null. */
  6340. findPathConstraint (constraintName) {
  6341. if (constraintName == null) throw new Error("constraintName cannot be null.");
  6342. let pathConstraints = this.pathConstraints;
  6343. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  6344. let constraint = pathConstraints[i];
  6345. if (constraint.data.name == constraintName) return constraint;
  6346. }
  6347. return null;
  6348. }
  6349. /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
  6350. * @param offset The distance from the skeleton origin to the bottom left corner of the AABB.
  6351. * @param size The width and height of the AABB.
  6352. * @param temp Working memory */
  6353. getBounds (offset, size, temp = new Array(2)) {
  6354. if (offset == null) throw new Error("offset cannot be null.");
  6355. if (size == null) throw new Error("size cannot be null.");
  6356. let drawOrder = this.drawOrder;
  6357. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  6358. for (let i = 0, n = drawOrder.length; i < n; i++) {
  6359. let slot = drawOrder[i];
  6360. if (!slot.bone.active) continue;
  6361. let verticesLength = 0;
  6362. let vertices = null;
  6363. let attachment = slot.getAttachment();
  6364. if (attachment instanceof RegionAttachment) {
  6365. verticesLength = 8;
  6366. vertices = Utils.setArraySize(temp, verticesLength, 0);
  6367. (attachment).computeWorldVertices(slot.bone, vertices, 0, 2);
  6368. } else if (attachment instanceof MeshAttachment) {
  6369. let mesh = (attachment);
  6370. verticesLength = mesh.worldVerticesLength;
  6371. vertices = Utils.setArraySize(temp, verticesLength, 0);
  6372. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  6373. }
  6374. if (vertices != null) {
  6375. for (let ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  6376. let x = vertices[ii], y = vertices[ii + 1];
  6377. minX = Math.min(minX, x);
  6378. minY = Math.min(minY, y);
  6379. maxX = Math.max(maxX, x);
  6380. maxY = Math.max(maxY, y);
  6381. }
  6382. }
  6383. }
  6384. offset.set(minX, minY);
  6385. size.set(maxX - minX, maxY - minY);
  6386. }
  6387. update (delta) {
  6388. this.time += delta;
  6389. }
  6390. get flipX() {
  6391. return this.scaleX == -1;
  6392. }
  6393. set flipX(value) {
  6394. if (!Skeleton.deprecatedWarning1) {
  6395. Skeleton.deprecatedWarning1 = true;
  6396. console.warn("Spine Deprecation Warning: `Skeleton.flipX/flipY` was deprecated, please use scaleX/scaleY");
  6397. }
  6398. this.scaleX = value ? 1.0 : -1.0;
  6399. }
  6400. get flipY() {
  6401. return this.scaleY == -1;
  6402. }
  6403. set flipY(value) {
  6404. if (!Skeleton.deprecatedWarning1) {
  6405. Skeleton.deprecatedWarning1 = true;
  6406. console.warn("Spine Deprecation Warning: `Skeleton.flipX/flipY` was deprecated, please use scaleX/scaleY");
  6407. }
  6408. this.scaleY = value ? 1.0 : -1.0;
  6409. }
  6410. static __initStatic() {this.deprecatedWarning1 = false;}
  6411. } Skeleton.__initStatic();
  6412. /**
  6413. * @public
  6414. */
  6415. class SkeletonData {constructor() { SkeletonData.prototype.__init.call(this);SkeletonData.prototype.__init2.call(this);SkeletonData.prototype.__init3.call(this);SkeletonData.prototype.__init4.call(this);SkeletonData.prototype.__init5.call(this);SkeletonData.prototype.__init6.call(this);SkeletonData.prototype.__init7.call(this);SkeletonData.prototype.__init8.call(this);SkeletonData.prototype.__init9.call(this); }
  6416. __init() {this.bones = new Array();} // Ordered parents first.
  6417. __init2() {this.slots = new Array();} // Setup pose draw order.
  6418. __init3() {this.skins = new Array();}
  6419. __init4() {this.events = new Array();}
  6420. __init5() {this.animations = new Array();}
  6421. __init6() {this.ikConstraints = new Array();}
  6422. __init7() {this.transformConstraints = new Array();}
  6423. __init8() {this.pathConstraints = new Array();}
  6424. // Nonessential
  6425. __init9() {this.fps = 0;}
  6426. findBone (boneName) {
  6427. if (boneName == null) throw new Error("boneName cannot be null.");
  6428. let bones = this.bones;
  6429. for (let i = 0, n = bones.length; i < n; i++) {
  6430. let bone = bones[i];
  6431. if (bone.name == boneName) return bone;
  6432. }
  6433. return null;
  6434. }
  6435. findBoneIndex (boneName) {
  6436. if (boneName == null) throw new Error("boneName cannot be null.");
  6437. let bones = this.bones;
  6438. for (let i = 0, n = bones.length; i < n; i++)
  6439. if (bones[i].name == boneName) return i;
  6440. return -1;
  6441. }
  6442. findSlot (slotName) {
  6443. if (slotName == null) throw new Error("slotName cannot be null.");
  6444. let slots = this.slots;
  6445. for (let i = 0, n = slots.length; i < n; i++) {
  6446. let slot = slots[i];
  6447. if (slot.name == slotName) return slot;
  6448. }
  6449. return null;
  6450. }
  6451. findSlotIndex (slotName) {
  6452. if (slotName == null) throw new Error("slotName cannot be null.");
  6453. let slots = this.slots;
  6454. for (let i = 0, n = slots.length; i < n; i++)
  6455. if (slots[i].name == slotName) return i;
  6456. return -1;
  6457. }
  6458. findSkin (skinName) {
  6459. if (skinName == null) throw new Error("skinName cannot be null.");
  6460. let skins = this.skins;
  6461. for (let i = 0, n = skins.length; i < n; i++) {
  6462. let skin = skins[i];
  6463. if (skin.name == skinName) return skin;
  6464. }
  6465. return null;
  6466. }
  6467. findEvent (eventDataName) {
  6468. if (eventDataName == null) throw new Error("eventDataName cannot be null.");
  6469. let events = this.events;
  6470. for (let i = 0, n = events.length; i < n; i++) {
  6471. let event = events[i];
  6472. if (event.name == eventDataName) return event;
  6473. }
  6474. return null;
  6475. }
  6476. findAnimation (animationName) {
  6477. if (animationName == null) throw new Error("animationName cannot be null.");
  6478. let animations = this.animations;
  6479. for (let i = 0, n = animations.length; i < n; i++) {
  6480. let animation = animations[i];
  6481. if (animation.name == animationName) return animation;
  6482. }
  6483. return null;
  6484. }
  6485. findIkConstraint (constraintName) {
  6486. if (constraintName == null) throw new Error("constraintName cannot be null.");
  6487. let ikConstraints = this.ikConstraints;
  6488. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  6489. let constraint = ikConstraints[i];
  6490. if (constraint.name == constraintName) return constraint;
  6491. }
  6492. return null;
  6493. }
  6494. findTransformConstraint (constraintName) {
  6495. if (constraintName == null) throw new Error("constraintName cannot be null.");
  6496. let transformConstraints = this.transformConstraints;
  6497. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  6498. let constraint = transformConstraints[i];
  6499. if (constraint.name == constraintName) return constraint;
  6500. }
  6501. return null;
  6502. }
  6503. findPathConstraint (constraintName) {
  6504. if (constraintName == null) throw new Error("constraintName cannot be null.");
  6505. let pathConstraints = this.pathConstraints;
  6506. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  6507. let constraint = pathConstraints[i];
  6508. if (constraint.name == constraintName) return constraint;
  6509. }
  6510. return null;
  6511. }
  6512. findPathConstraintIndex (pathConstraintName) {
  6513. if (pathConstraintName == null) throw new Error("pathConstraintName cannot be null.");
  6514. let pathConstraints = this.pathConstraints;
  6515. for (let i = 0, n = pathConstraints.length; i < n; i++)
  6516. if (pathConstraints[i].name == pathConstraintName) return i;
  6517. return -1;
  6518. }
  6519. }
  6520. /**
  6521. * @public
  6522. */
  6523. class SlotData {
  6524. __init() {this.color = new Color(1, 1, 1, 1);}
  6525. constructor (index, name, boneData) {SlotData.prototype.__init.call(this);
  6526. if (index < 0) throw new Error("index must be >= 0.");
  6527. if (name == null) throw new Error("name cannot be null.");
  6528. if (boneData == null) throw new Error("boneData cannot be null.");
  6529. this.index = index;
  6530. this.name = name;
  6531. this.boneData = boneData;
  6532. }
  6533. }
  6534. /**
  6535. * @public
  6536. */
  6537. class TransformConstraintData extends ConstraintData {
  6538. __init() {this.bones = new Array();}
  6539. __init2() {this.rotateMix = 0;} __init3() {this.translateMix = 0;} __init4() {this.scaleMix = 0;} __init5() {this.shearMix = 0;}
  6540. __init6() {this.offsetRotation = 0;} __init7() {this.offsetX = 0;} __init8() {this.offsetY = 0;} __init9() {this.offsetScaleX = 0;} __init10() {this.offsetScaleY = 0;} __init11() {this.offsetShearY = 0;}
  6541. __init12() {this.relative = false;}
  6542. __init13() {this.local = false;}
  6543. constructor (name) {
  6544. super(name, 0, false);TransformConstraintData.prototype.__init.call(this);TransformConstraintData.prototype.__init2.call(this);TransformConstraintData.prototype.__init3.call(this);TransformConstraintData.prototype.__init4.call(this);TransformConstraintData.prototype.__init5.call(this);TransformConstraintData.prototype.__init6.call(this);TransformConstraintData.prototype.__init7.call(this);TransformConstraintData.prototype.__init8.call(this);TransformConstraintData.prototype.__init9.call(this);TransformConstraintData.prototype.__init10.call(this);TransformConstraintData.prototype.__init11.call(this);TransformConstraintData.prototype.__init12.call(this);TransformConstraintData.prototype.__init13.call(this); }
  6545. }
  6546. /**
  6547. * @public
  6548. */
  6549. class SkinEntry {
  6550. constructor( slotIndex, name, attachment) {this.slotIndex = slotIndex;this.name = name;this.attachment = attachment; }
  6551. }
  6552. /**
  6553. * @public
  6554. */
  6555. class Skin {
  6556. __init() {this.attachments = new Array();}
  6557. __init2() {this.bones = Array();}
  6558. __init3() {this.constraints = new Array();}
  6559. constructor (name) {Skin.prototype.__init.call(this);Skin.prototype.__init2.call(this);Skin.prototype.__init3.call(this);
  6560. if (name == null) throw new Error("name cannot be null.");
  6561. this.name = name;
  6562. }
  6563. setAttachment (slotIndex, name, attachment) {
  6564. if (attachment == null) throw new Error("attachment cannot be null.");
  6565. let attachments = this.attachments;
  6566. if (slotIndex >= attachments.length) attachments.length = slotIndex + 1;
  6567. if (!attachments[slotIndex]) attachments[slotIndex] = { };
  6568. attachments[slotIndex][name] = attachment;
  6569. }
  6570. addSkin (skin) {
  6571. for(let i = 0; i < skin.bones.length; i++) {
  6572. let bone = skin.bones[i];
  6573. let contained = false;
  6574. for (let j = 0; j < this.bones.length; j++) {
  6575. if (this.bones[j] == bone) {
  6576. contained = true;
  6577. break;
  6578. }
  6579. }
  6580. if (!contained) this.bones.push(bone);
  6581. }
  6582. for(let i = 0; i < skin.constraints.length; i++) {
  6583. let constraint = skin.constraints[i];
  6584. let contained = false;
  6585. for (let j = 0; j < this.constraints.length; j++) {
  6586. if (this.constraints[j] == constraint) {
  6587. contained = true;
  6588. break;
  6589. }
  6590. }
  6591. if (!contained) this.constraints.push(constraint);
  6592. }
  6593. let attachments = skin.getAttachments();
  6594. for (let i = 0; i < attachments.length; i++) {
  6595. var attachment = attachments[i];
  6596. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  6597. }
  6598. }
  6599. copySkin (skin) {
  6600. for(let i = 0; i < skin.bones.length; i++) {
  6601. let bone = skin.bones[i];
  6602. let contained = false;
  6603. for (let j = 0; j < this.bones.length; j++) {
  6604. if (this.bones[j] == bone) {
  6605. contained = true;
  6606. break;
  6607. }
  6608. }
  6609. if (!contained) this.bones.push(bone);
  6610. }
  6611. for(let i = 0; i < skin.constraints.length; i++) {
  6612. let constraint = skin.constraints[i];
  6613. let contained = false;
  6614. for (let j = 0; j < this.constraints.length; j++) {
  6615. if (this.constraints[j] == constraint) {
  6616. contained = true;
  6617. break;
  6618. }
  6619. }
  6620. if (!contained) this.constraints.push(constraint);
  6621. }
  6622. let attachments = skin.getAttachments();
  6623. for (let i = 0; i < attachments.length; i++) {
  6624. var attachment = attachments[i];
  6625. if (attachment.attachment == null) continue;
  6626. if (attachment.attachment instanceof MeshAttachment) {
  6627. attachment.attachment = attachment.attachment.newLinkedMesh();
  6628. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  6629. } else {
  6630. attachment.attachment = attachment.attachment.copy();
  6631. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  6632. }
  6633. }
  6634. }
  6635. /** @return May be null. */
  6636. getAttachment (slotIndex, name) {
  6637. let dictionary = this.attachments[slotIndex];
  6638. return dictionary ? dictionary[name] : null;
  6639. }
  6640. removeAttachment (slotIndex, name) {
  6641. let dictionary = this.attachments[slotIndex];
  6642. if (dictionary) dictionary[name] = null;
  6643. }
  6644. getAttachments () {
  6645. let entries = new Array();
  6646. for (var i = 0; i < this.attachments.length; i++) {
  6647. let slotAttachments = this.attachments[i];
  6648. if (slotAttachments) {
  6649. for (let name in slotAttachments) {
  6650. let attachment = slotAttachments[name];
  6651. if (attachment) entries.push(new SkinEntry(i, name, attachment));
  6652. }
  6653. }
  6654. }
  6655. return entries;
  6656. }
  6657. getAttachmentsForSlot (slotIndex, attachments) {
  6658. let slotAttachments = this.attachments[slotIndex];
  6659. if (slotAttachments) {
  6660. for (let name in slotAttachments) {
  6661. let attachment = slotAttachments[name];
  6662. if (attachment) attachments.push(new SkinEntry(slotIndex, name, attachment));
  6663. }
  6664. }
  6665. }
  6666. clear () {
  6667. this.attachments.length = 0;
  6668. this.bones.length = 0;
  6669. this.constraints.length = 0;
  6670. }
  6671. /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
  6672. attachAll (skeleton, oldSkin) {
  6673. let slotIndex = 0;
  6674. for (let i = 0; i < skeleton.slots.length; i++) {
  6675. let slot = skeleton.slots[i];
  6676. let slotAttachment = slot.getAttachment();
  6677. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  6678. let dictionary = oldSkin.attachments[slotIndex];
  6679. for (let key in dictionary) {
  6680. let skinAttachment = dictionary[key];
  6681. if (slotAttachment == skinAttachment) {
  6682. let attachment = this.getAttachment(slotIndex, key);
  6683. if (attachment != null) slot.setAttachment(attachment);
  6684. break;
  6685. }
  6686. }
  6687. }
  6688. slotIndex++;
  6689. }
  6690. }
  6691. }
  6692. /**
  6693. * @public
  6694. */
  6695. class SkeletonBinary {
  6696. static __initStatic() {this.AttachmentTypeValues = [ 0 /*AttachmentType.Region*/, 1/*AttachmentType.BoundingBox*/, 2/*AttachmentType.Mesh*/, 3/*AttachmentType.LinkedMesh*/, 4/*AttachmentType.Path*/, 5/*AttachmentType.Point*/, 6/*AttachmentType.Clipping*/ ];}
  6697. static __initStatic2() {this.TransformModeValues = [TransformMode.Normal, TransformMode.OnlyTranslation, TransformMode.NoRotationOrReflection, TransformMode.NoScale, TransformMode.NoScaleOrReflection];}
  6698. static __initStatic3() {this.PositionModeValues = [ PositionMode.Fixed, PositionMode.Percent ];}
  6699. static __initStatic4() {this.SpacingModeValues = [ SpacingMode.Length, SpacingMode.Fixed, SpacingMode.Percent];}
  6700. static __initStatic5() {this.RotateModeValues = [ RotateMode.Tangent, RotateMode.Chain, RotateMode.ChainScale ];}
  6701. static __initStatic6() {this.BlendModeValues = [ constants.BLEND_MODES.NORMAL, constants.BLEND_MODES.ADD, constants.BLEND_MODES.MULTIPLY, constants.BLEND_MODES.SCREEN];}
  6702. static __initStatic7() {this.BONE_ROTATE = 0;}
  6703. static __initStatic8() {this.BONE_TRANSLATE = 1;}
  6704. static __initStatic9() {this.BONE_SCALE = 2;}
  6705. static __initStatic10() {this.BONE_SHEAR = 3;}
  6706. static __initStatic11() {this.SLOT_ATTACHMENT = 0;}
  6707. static __initStatic12() {this.SLOT_COLOR = 1;}
  6708. static __initStatic13() {this.SLOT_TWO_COLOR = 2;}
  6709. static __initStatic14() {this.PATH_POSITION = 0;}
  6710. static __initStatic15() {this.PATH_SPACING = 1;}
  6711. static __initStatic16() {this.PATH_MIX = 2;}
  6712. static __initStatic17() {this.CURVE_LINEAR = 0;}
  6713. static __initStatic18() {this.CURVE_STEPPED = 1;}
  6714. static __initStatic19() {this.CURVE_BEZIER = 2;}
  6715. __init() {this.scale = 1;}
  6716. __init2() {this.linkedMeshes = new Array();}
  6717. constructor (attachmentLoader) {SkeletonBinary.prototype.__init.call(this);SkeletonBinary.prototype.__init2.call(this);
  6718. this.attachmentLoader = attachmentLoader;
  6719. }
  6720. readSkeletonData (binary) {
  6721. let scale = this.scale;
  6722. let skeletonData = new SkeletonData();
  6723. skeletonData.name = ""; // BOZO
  6724. let input = new BinaryInput(binary);
  6725. skeletonData.hash = input.readString();
  6726. skeletonData.version = input.readString();
  6727. if (skeletonData.version === '3.8.75')
  6728. {
  6729. let error = `Unsupported skeleton data, 3.8.75 is deprecated, please export with a newer version of Spine.`;
  6730. console.error(error);
  6731. }
  6732. skeletonData.x = input.readFloat();
  6733. skeletonData.y = input.readFloat();
  6734. skeletonData.width = input.readFloat();
  6735. skeletonData.height = input.readFloat();
  6736. let nonessential = input.readBoolean();
  6737. if (nonessential) {
  6738. skeletonData.fps = input.readFloat();
  6739. skeletonData.imagesPath = input.readString();
  6740. skeletonData.audioPath = input.readString();
  6741. }
  6742. let n = 0;
  6743. // Strings.
  6744. n = input.readInt(true);
  6745. for (let i = 0; i < n; i++)
  6746. input.strings.push(input.readString());
  6747. // Bones.
  6748. n = input.readInt(true);
  6749. for (let i = 0; i < n; i++) {
  6750. let name = input.readString();
  6751. let parent = i == 0 ? null : skeletonData.bones[input.readInt(true)];
  6752. let data = new BoneData(i, name, parent);
  6753. data.rotation = input.readFloat();
  6754. data.x = input.readFloat() * scale;
  6755. data.y = input.readFloat() * scale;
  6756. data.scaleX = input.readFloat();
  6757. data.scaleY = input.readFloat();
  6758. data.shearX = input.readFloat();
  6759. data.shearY = input.readFloat();
  6760. data.length = input.readFloat() * scale;
  6761. data.transformMode = SkeletonBinary.TransformModeValues[input.readInt(true)];
  6762. data.skinRequired = input.readBoolean();
  6763. if (nonessential) Color.rgba8888ToColor(data.color, input.readInt32());
  6764. skeletonData.bones.push(data);
  6765. }
  6766. // Slots.
  6767. n = input.readInt(true);
  6768. for (let i = 0; i < n; i++) {
  6769. let slotName = input.readString();
  6770. let boneData = skeletonData.bones[input.readInt(true)];
  6771. let data = new SlotData(i, slotName, boneData);
  6772. Color.rgba8888ToColor(data.color, input.readInt32());
  6773. let darkColor = input.readInt32();
  6774. if (darkColor != -1) Color.rgb888ToColor(data.darkColor = new Color(), darkColor);
  6775. data.attachmentName = input.readStringRef();
  6776. data.blendMode = SkeletonBinary.BlendModeValues[input.readInt(true)];
  6777. skeletonData.slots.push(data);
  6778. }
  6779. // IK constraints.
  6780. n = input.readInt(true);
  6781. for (let i = 0, nn; i < n; i++) {
  6782. let data = new IkConstraintData(input.readString());
  6783. data.order = input.readInt(true);
  6784. data.skinRequired = input.readBoolean();
  6785. nn = input.readInt(true);
  6786. for (let ii = 0; ii < nn; ii++)
  6787. data.bones.push(skeletonData.bones[input.readInt(true)]);
  6788. data.target = skeletonData.bones[input.readInt(true)];
  6789. data.mix = input.readFloat();
  6790. data.softness = input.readFloat() * scale;
  6791. data.bendDirection = input.readByte();
  6792. data.compress = input.readBoolean();
  6793. data.stretch = input.readBoolean();
  6794. data.uniform = input.readBoolean();
  6795. skeletonData.ikConstraints.push(data);
  6796. }
  6797. // Transform constraints.
  6798. n = input.readInt(true);
  6799. for (let i = 0, nn; i < n; i++) {
  6800. let data = new TransformConstraintData(input.readString());
  6801. data.order = input.readInt(true);
  6802. data.skinRequired = input.readBoolean();
  6803. nn = input.readInt(true);
  6804. for (let ii = 0; ii < nn; ii++)
  6805. data.bones.push(skeletonData.bones[input.readInt(true)]);
  6806. data.target = skeletonData.bones[input.readInt(true)];
  6807. data.local = input.readBoolean();
  6808. data.relative = input.readBoolean();
  6809. data.offsetRotation = input.readFloat();
  6810. data.offsetX = input.readFloat() * scale;
  6811. data.offsetY = input.readFloat() * scale;
  6812. data.offsetScaleX = input.readFloat();
  6813. data.offsetScaleY = input.readFloat();
  6814. data.offsetShearY = input.readFloat();
  6815. data.rotateMix = input.readFloat();
  6816. data.translateMix = input.readFloat();
  6817. data.scaleMix = input.readFloat();
  6818. data.shearMix = input.readFloat();
  6819. skeletonData.transformConstraints.push(data);
  6820. }
  6821. // Path constraints.
  6822. n = input.readInt(true);
  6823. for (let i = 0, nn; i < n; i++) {
  6824. let data = new PathConstraintData(input.readString());
  6825. data.order = input.readInt(true);
  6826. data.skinRequired = input.readBoolean();
  6827. nn = input.readInt(true);
  6828. for (let ii = 0; ii < nn; ii++)
  6829. data.bones.push(skeletonData.bones[input.readInt(true)]);
  6830. data.target = skeletonData.slots[input.readInt(true)];
  6831. data.positionMode = SkeletonBinary.PositionModeValues[input.readInt(true)];
  6832. data.spacingMode = SkeletonBinary.SpacingModeValues[input.readInt(true)];
  6833. data.rotateMode = SkeletonBinary.RotateModeValues[input.readInt(true)];
  6834. data.offsetRotation = input.readFloat();
  6835. data.position = input.readFloat();
  6836. if (data.positionMode == PositionMode.Fixed) data.position *= scale;
  6837. data.spacing = input.readFloat();
  6838. if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale;
  6839. data.rotateMix = input.readFloat();
  6840. data.translateMix = input.readFloat();
  6841. skeletonData.pathConstraints.push(data);
  6842. }
  6843. // Default skin.
  6844. let defaultSkin = this.readSkin(input, skeletonData, true, nonessential);
  6845. if (defaultSkin != null) {
  6846. skeletonData.defaultSkin = defaultSkin;
  6847. skeletonData.skins.push(defaultSkin);
  6848. }
  6849. // Skins.
  6850. {
  6851. let i = skeletonData.skins.length;
  6852. Utils.setArraySize(skeletonData.skins, n = i + input.readInt(true));
  6853. for (; i < n; i++)
  6854. skeletonData.skins[i] = this.readSkin(input, skeletonData, false, nonessential);
  6855. }
  6856. // Linked meshes.
  6857. n = this.linkedMeshes.length;
  6858. for (let i = 0; i < n; i++) {
  6859. let linkedMesh = this.linkedMeshes[i];
  6860. let skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  6861. if (skin == null) throw new Error("Skin not found: " + linkedMesh.skin);
  6862. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  6863. if (parent == null) throw new Error("Parent mesh not found: " + linkedMesh.parent);
  6864. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent : linkedMesh.mesh;
  6865. linkedMesh.mesh.setParentMesh(parent );
  6866. // linkedMesh.mesh.updateUVs();
  6867. }
  6868. this.linkedMeshes.length = 0;
  6869. // Events.
  6870. n = input.readInt(true);
  6871. for (let i = 0; i < n; i++) {
  6872. let data = new EventData(input.readStringRef());
  6873. data.intValue = input.readInt(false);
  6874. data.floatValue = input.readFloat();
  6875. data.stringValue = input.readString();
  6876. data.audioPath = input.readString();
  6877. if (data.audioPath != null) {
  6878. data.volume = input.readFloat();
  6879. data.balance = input.readFloat();
  6880. }
  6881. skeletonData.events.push(data);
  6882. }
  6883. // Animations.
  6884. n = input.readInt(true);
  6885. for (let i = 0; i < n; i++)
  6886. skeletonData.animations.push(this.readAnimation(input, input.readString(), skeletonData));
  6887. return skeletonData;
  6888. }
  6889. readSkin (input, skeletonData, defaultSkin, nonessential) {
  6890. let skin = null;
  6891. let slotCount = 0;
  6892. if (defaultSkin) {
  6893. slotCount = input.readInt(true);
  6894. if (slotCount == 0) return null;
  6895. skin = new Skin("default");
  6896. } else {
  6897. skin = new Skin(input.readStringRef());
  6898. skin.bones.length = input.readInt(true);
  6899. for (let i = 0, n = skin.bones.length; i < n; i++)
  6900. skin.bones[i] = skeletonData.bones[input.readInt(true)];
  6901. for (let i = 0, n = input.readInt(true); i < n; i++)
  6902. skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]);
  6903. for (let i = 0, n = input.readInt(true); i < n; i++)
  6904. skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]);
  6905. for (let i = 0, n = input.readInt(true); i < n; i++)
  6906. skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]);
  6907. slotCount = input.readInt(true);
  6908. }
  6909. for (let i = 0; i < slotCount; i++) {
  6910. let slotIndex = input.readInt(true);
  6911. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  6912. let name = input.readStringRef();
  6913. let attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name, nonessential);
  6914. if (attachment != null) skin.setAttachment(slotIndex, name, attachment);
  6915. }
  6916. }
  6917. return skin;
  6918. }
  6919. readAttachment(input, skeletonData, skin, slotIndex, attachmentName, nonessential) {
  6920. let scale = this.scale;
  6921. let name = input.readStringRef();
  6922. if (name == null) name = attachmentName;
  6923. let typeIndex = input.readByte();
  6924. let type = SkeletonBinary.AttachmentTypeValues[typeIndex];
  6925. switch (type) {
  6926. case exports.AttachmentType.Region: {
  6927. let path = input.readStringRef();
  6928. let rotation = input.readFloat();
  6929. let x = input.readFloat();
  6930. let y = input.readFloat();
  6931. let scaleX = input.readFloat();
  6932. let scaleY = input.readFloat();
  6933. let width = input.readFloat();
  6934. let height = input.readFloat();
  6935. let color = input.readInt32();
  6936. if (path == null) path = name;
  6937. let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  6938. if (region == null) return null;
  6939. region.path = path;
  6940. region.x = x * scale;
  6941. region.y = y * scale;
  6942. region.scaleX = scaleX;
  6943. region.scaleY = scaleY;
  6944. region.rotation = rotation;
  6945. region.width = width * scale;
  6946. region.height = height * scale;
  6947. Color.rgba8888ToColor(region.color, color);
  6948. // region.updateOffset();
  6949. return region;
  6950. }
  6951. case exports.AttachmentType.BoundingBox: {
  6952. let vertexCount = input.readInt(true);
  6953. let vertices = this.readVertices(input, vertexCount);
  6954. let color = nonessential ? input.readInt32() : 0;
  6955. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  6956. if (box == null) return null;
  6957. box.worldVerticesLength = vertexCount << 1;
  6958. box.vertices = vertices.vertices;
  6959. box.bones = vertices.bones;
  6960. if (nonessential) Color.rgba8888ToColor(box.color, color);
  6961. return box;
  6962. }
  6963. case exports.AttachmentType.Mesh: {
  6964. let path = input.readStringRef();
  6965. let color = input.readInt32();
  6966. let vertexCount = input.readInt(true);
  6967. let uvs = this.readFloatArray(input, vertexCount << 1, 1);
  6968. let triangles = this.readShortArray(input);
  6969. let vertices = this.readVertices(input, vertexCount);
  6970. let hullLength = input.readInt(true);
  6971. let edges = null;
  6972. let width = 0, height = 0;
  6973. if (nonessential) {
  6974. edges = this.readShortArray(input);
  6975. width = input.readFloat();
  6976. height = input.readFloat();
  6977. }
  6978. if (path == null) path = name;
  6979. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  6980. if (mesh == null) return null;
  6981. mesh.path = path;
  6982. Color.rgba8888ToColor(mesh.color, color);
  6983. mesh.bones = vertices.bones;
  6984. mesh.vertices = vertices.vertices;
  6985. mesh.worldVerticesLength = vertexCount << 1;
  6986. mesh.triangles = triangles;
  6987. mesh.regionUVs = new Float32Array(uvs);
  6988. // mesh.updateUVs();
  6989. mesh.hullLength = hullLength << 1;
  6990. if (nonessential) {
  6991. mesh.edges = edges;
  6992. mesh.width = width * scale;
  6993. mesh.height = height * scale;
  6994. }
  6995. return mesh;
  6996. }
  6997. case exports.AttachmentType.LinkedMesh: {
  6998. let path = input.readStringRef();
  6999. let color = input.readInt32();
  7000. let skinName = input.readStringRef();
  7001. let parent = input.readStringRef();
  7002. let inheritDeform = input.readBoolean();
  7003. let width = 0, height = 0;
  7004. if (nonessential) {
  7005. width = input.readFloat();
  7006. height = input.readFloat();
  7007. }
  7008. if (path == null) path = name;
  7009. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  7010. if (mesh == null) return null;
  7011. mesh.path = path;
  7012. Color.rgba8888ToColor(mesh.color, color);
  7013. if (nonessential) {
  7014. mesh.width = width * scale;
  7015. mesh.height = height * scale;
  7016. }
  7017. this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent, inheritDeform));
  7018. return mesh;
  7019. }
  7020. case exports.AttachmentType.Path: {
  7021. let closed = input.readBoolean();
  7022. let constantSpeed = input.readBoolean();
  7023. let vertexCount = input.readInt(true);
  7024. let vertices = this.readVertices(input, vertexCount);
  7025. let lengths = Utils.newArray(vertexCount / 3, 0);
  7026. for (let i = 0, n = lengths.length; i < n; i++)
  7027. lengths[i] = input.readFloat() * scale;
  7028. let color = nonessential ? input.readInt32() : 0;
  7029. let path = this.attachmentLoader.newPathAttachment(skin, name);
  7030. if (path == null) return null;
  7031. path.closed = closed;
  7032. path.constantSpeed = constantSpeed;
  7033. path.worldVerticesLength = vertexCount << 1;
  7034. path.vertices = vertices.vertices;
  7035. path.bones = vertices.bones;
  7036. path.lengths = lengths;
  7037. if (nonessential) Color.rgba8888ToColor(path.color, color);
  7038. return path;
  7039. }
  7040. case exports.AttachmentType.Point: {
  7041. let rotation = input.readFloat();
  7042. let x = input.readFloat();
  7043. let y = input.readFloat();
  7044. let color = nonessential ? input.readInt32() : 0;
  7045. let point = this.attachmentLoader.newPointAttachment(skin, name);
  7046. if (point == null) return null;
  7047. point.x = x * scale;
  7048. point.y = y * scale;
  7049. point.rotation = rotation;
  7050. if (nonessential) Color.rgba8888ToColor(point.color, color);
  7051. return point;
  7052. }
  7053. case exports.AttachmentType.Clipping: {
  7054. let endSlotIndex = input.readInt(true);
  7055. let vertexCount = input.readInt(true);
  7056. let vertices = this.readVertices(input, vertexCount);
  7057. let color = nonessential ? input.readInt32() : 0;
  7058. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  7059. if (clip == null) return null;
  7060. clip.endSlot = skeletonData.slots[endSlotIndex];
  7061. clip.worldVerticesLength = vertexCount << 1;
  7062. clip.vertices = vertices.vertices;
  7063. clip.bones = vertices.bones;
  7064. if (nonessential) Color.rgba8888ToColor(clip.color, color);
  7065. return clip;
  7066. }
  7067. }
  7068. return null;
  7069. }
  7070. readVertices (input, vertexCount) {
  7071. let verticesLength = vertexCount << 1;
  7072. let vertices = new Vertices();
  7073. let scale = this.scale;
  7074. if (!input.readBoolean()) {
  7075. vertices.vertices = this.readFloatArray(input, verticesLength, scale);
  7076. return vertices;
  7077. }
  7078. let weights = new Array();
  7079. let bonesArray = new Array();
  7080. for (let i = 0; i < vertexCount; i++) {
  7081. let boneCount = input.readInt(true);
  7082. bonesArray.push(boneCount);
  7083. for (let ii = 0; ii < boneCount; ii++) {
  7084. bonesArray.push(input.readInt(true));
  7085. weights.push(input.readFloat() * scale);
  7086. weights.push(input.readFloat() * scale);
  7087. weights.push(input.readFloat());
  7088. }
  7089. }
  7090. vertices.vertices = Utils.toFloatArray(weights);
  7091. vertices.bones = bonesArray;
  7092. return vertices;
  7093. }
  7094. readFloatArray (input, n, scale) {
  7095. let array = new Array(n);
  7096. if (scale == 1) {
  7097. for (let i = 0; i < n; i++)
  7098. array[i] = input.readFloat();
  7099. } else {
  7100. for (let i = 0; i < n; i++)
  7101. array[i] = input.readFloat() * scale;
  7102. }
  7103. return array;
  7104. }
  7105. readShortArray (input) {
  7106. let n = input.readInt(true);
  7107. let array = new Array(n);
  7108. for (let i = 0; i < n; i++)
  7109. array[i] = input.readShort();
  7110. return array;
  7111. }
  7112. readAnimation (input, name, skeletonData) {
  7113. let timelines = new Array();
  7114. let scale = this.scale;
  7115. let duration = 0;
  7116. let tempColor1 = new Color();
  7117. let tempColor2 = new Color();
  7118. // Slot timelines.
  7119. for (let i = 0, n = input.readInt(true); i < n; i++) {
  7120. let slotIndex = input.readInt(true);
  7121. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  7122. let timelineType = input.readByte();
  7123. let frameCount = input.readInt(true);
  7124. switch (timelineType) {
  7125. case SkeletonBinary.SLOT_ATTACHMENT: {
  7126. let timeline = new AttachmentTimeline(frameCount);
  7127. timeline.slotIndex = slotIndex;
  7128. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++)
  7129. timeline.setFrame(frameIndex, input.readFloat(), input.readStringRef());
  7130. timelines.push(timeline);
  7131. duration = Math.max(duration, timeline.frames[frameCount - 1]);
  7132. break;
  7133. }
  7134. case SkeletonBinary.SLOT_COLOR: {
  7135. let timeline = new ColorTimeline(frameCount);
  7136. timeline.slotIndex = slotIndex;
  7137. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7138. let time = input.readFloat();
  7139. Color.rgba8888ToColor(tempColor1, input.readInt32());
  7140. timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a);
  7141. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7142. }
  7143. timelines.push(timeline);
  7144. duration = Math.max(duration, timeline.frames[(frameCount - 1) * ColorTimeline.ENTRIES]);
  7145. break;
  7146. }
  7147. case SkeletonBinary.SLOT_TWO_COLOR: {
  7148. let timeline = new TwoColorTimeline(frameCount);
  7149. timeline.slotIndex = slotIndex;
  7150. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7151. let time = input.readFloat();
  7152. Color.rgba8888ToColor(tempColor1, input.readInt32());
  7153. Color.rgb888ToColor(tempColor2, input.readInt32());
  7154. timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a, tempColor2.r,
  7155. tempColor2.g, tempColor2.b);
  7156. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7157. }
  7158. timelines.push(timeline);
  7159. duration = Math.max(duration, timeline.frames[(frameCount - 1) * TwoColorTimeline.ENTRIES]);
  7160. break;
  7161. }
  7162. }
  7163. }
  7164. }
  7165. // Bone timelines.
  7166. for (let i = 0, n = input.readInt(true); i < n; i++) {
  7167. let boneIndex = input.readInt(true);
  7168. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  7169. let timelineType = input.readByte();
  7170. let frameCount = input.readInt(true);
  7171. switch (timelineType) {
  7172. case SkeletonBinary.BONE_ROTATE: {
  7173. let timeline = new RotateTimeline(frameCount);
  7174. timeline.boneIndex = boneIndex;
  7175. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7176. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat());
  7177. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7178. }
  7179. timelines.push(timeline);
  7180. duration = Math.max(duration, timeline.frames[(frameCount - 1) * RotateTimeline.ENTRIES]);
  7181. break;
  7182. }
  7183. case SkeletonBinary.BONE_TRANSLATE:
  7184. case SkeletonBinary.BONE_SCALE:
  7185. case SkeletonBinary.BONE_SHEAR: {
  7186. let timeline;
  7187. let timelineScale = 1;
  7188. if (timelineType == SkeletonBinary.BONE_SCALE)
  7189. timeline = new ScaleTimeline(frameCount);
  7190. else if (timelineType == SkeletonBinary.BONE_SHEAR)
  7191. timeline = new ShearTimeline(frameCount);
  7192. else {
  7193. timeline = new TranslateTimeline(frameCount);
  7194. timelineScale = scale;
  7195. }
  7196. timeline.boneIndex = boneIndex;
  7197. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7198. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale,
  7199. input.readFloat() * timelineScale);
  7200. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7201. }
  7202. timelines.push(timeline);
  7203. duration = Math.max(duration, timeline.frames[(frameCount - 1) * TranslateTimeline.ENTRIES]);
  7204. break;
  7205. }
  7206. }
  7207. }
  7208. }
  7209. // IK constraint timelines.
  7210. for (let i = 0, n = input.readInt(true); i < n; i++) {
  7211. let index = input.readInt(true);
  7212. let frameCount = input.readInt(true);
  7213. let timeline = new IkConstraintTimeline(frameCount);
  7214. timeline.ikConstraintIndex = index;
  7215. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7216. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat() * scale, input.readByte(), input.readBoolean(),
  7217. input.readBoolean());
  7218. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7219. }
  7220. timelines.push(timeline);
  7221. duration = Math.max(duration, timeline.frames[(frameCount - 1) * IkConstraintTimeline.ENTRIES]);
  7222. }
  7223. // Transform constraint timelines.
  7224. for (let i = 0, n = input.readInt(true); i < n; i++) {
  7225. let index = input.readInt(true);
  7226. let frameCount = input.readInt(true);
  7227. let timeline = new TransformConstraintTimeline(frameCount);
  7228. timeline.transformConstraintIndex = index;
  7229. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7230. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat(),
  7231. input.readFloat());
  7232. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7233. }
  7234. timelines.push(timeline);
  7235. duration = Math.max(duration, timeline.frames[(frameCount - 1) * TransformConstraintTimeline.ENTRIES]);
  7236. }
  7237. // Path constraint timelines.
  7238. for (let i = 0, n = input.readInt(true); i < n; i++) {
  7239. let index = input.readInt(true);
  7240. let data = skeletonData.pathConstraints[index];
  7241. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  7242. let timelineType = input.readByte();
  7243. let frameCount = input.readInt(true);
  7244. switch (timelineType) {
  7245. case SkeletonBinary.PATH_POSITION:
  7246. case SkeletonBinary.PATH_SPACING: {
  7247. let timeline;
  7248. let timelineScale = 1;
  7249. if (timelineType == SkeletonBinary.PATH_SPACING) {
  7250. timeline = new PathConstraintSpacingTimeline(frameCount);
  7251. if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) timelineScale = scale;
  7252. } else {
  7253. timeline = new PathConstraintPositionTimeline(frameCount);
  7254. if (data.positionMode == PositionMode.Fixed) timelineScale = scale;
  7255. }
  7256. timeline.pathConstraintIndex = index;
  7257. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7258. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale);
  7259. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7260. }
  7261. timelines.push(timeline);
  7262. duration = Math.max(duration, timeline.frames[(frameCount - 1) * PathConstraintPositionTimeline.ENTRIES]);
  7263. break;
  7264. }
  7265. case SkeletonBinary.PATH_MIX: {
  7266. let timeline = new PathConstraintMixTimeline(frameCount);
  7267. timeline.pathConstraintIndex = index;
  7268. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7269. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat());
  7270. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7271. }
  7272. timelines.push(timeline);
  7273. duration = Math.max(duration, timeline.frames[(frameCount - 1) * PathConstraintMixTimeline.ENTRIES]);
  7274. break;
  7275. }
  7276. }
  7277. }
  7278. }
  7279. // Deform timelines.
  7280. for (let i = 0, n = input.readInt(true); i < n; i++) {
  7281. let skin = skeletonData.skins[input.readInt(true)];
  7282. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  7283. let slotIndex = input.readInt(true);
  7284. for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
  7285. let attachment = skin.getAttachment(slotIndex, input.readStringRef()) ;
  7286. let weighted = attachment.bones != null;
  7287. let vertices = attachment.vertices;
  7288. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  7289. let frameCount = input.readInt(true);
  7290. let timeline = new DeformTimeline(frameCount);
  7291. timeline.slotIndex = slotIndex;
  7292. timeline.attachment = attachment;
  7293. for (let frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  7294. let time = input.readFloat();
  7295. let deform;
  7296. let end = input.readInt(true);
  7297. if (end == 0)
  7298. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  7299. else {
  7300. deform = Utils.newFloatArray(deformLength);
  7301. let start = input.readInt(true);
  7302. end += start;
  7303. if (scale == 1) {
  7304. for (let v = start; v < end; v++)
  7305. deform[v] = input.readFloat();
  7306. } else {
  7307. for (let v = start; v < end; v++)
  7308. deform[v] = input.readFloat() * scale;
  7309. }
  7310. if (!weighted) {
  7311. for (let v = 0, vn = deform.length; v < vn; v++)
  7312. deform[v] += vertices[v];
  7313. }
  7314. }
  7315. timeline.setFrame(frameIndex, time, deform);
  7316. if (frameIndex < frameCount - 1) this.readCurve(input, frameIndex, timeline);
  7317. }
  7318. timelines.push(timeline);
  7319. duration = Math.max(duration, timeline.frames[frameCount - 1]);
  7320. }
  7321. }
  7322. }
  7323. // Draw order timeline.
  7324. let drawOrderCount = input.readInt(true);
  7325. if (drawOrderCount > 0) {
  7326. let timeline = new DrawOrderTimeline(drawOrderCount);
  7327. let slotCount = skeletonData.slots.length;
  7328. for (let i = 0; i < drawOrderCount; i++) {
  7329. let time = input.readFloat();
  7330. let offsetCount = input.readInt(true);
  7331. let drawOrder = Utils.newArray(slotCount, 0);
  7332. for (let ii = slotCount - 1; ii >= 0; ii--)
  7333. drawOrder[ii] = -1;
  7334. let unchanged = Utils.newArray(slotCount - offsetCount, 0);
  7335. let originalIndex = 0, unchangedIndex = 0;
  7336. for (let ii = 0; ii < offsetCount; ii++) {
  7337. let slotIndex = input.readInt(true);
  7338. // Collect unchanged items.
  7339. while (originalIndex != slotIndex)
  7340. unchanged[unchangedIndex++] = originalIndex++;
  7341. // Set changed items.
  7342. drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
  7343. }
  7344. // Collect remaining unchanged items.
  7345. while (originalIndex < slotCount)
  7346. unchanged[unchangedIndex++] = originalIndex++;
  7347. // Fill in unchanged items.
  7348. for (let ii = slotCount - 1; ii >= 0; ii--)
  7349. if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex];
  7350. timeline.setFrame(i, time, drawOrder);
  7351. }
  7352. timelines.push(timeline);
  7353. duration = Math.max(duration, timeline.frames[drawOrderCount - 1]);
  7354. }
  7355. // Event timeline.
  7356. let eventCount = input.readInt(true);
  7357. if (eventCount > 0) {
  7358. let timeline = new EventTimeline(eventCount);
  7359. for (let i = 0; i < eventCount; i++) {
  7360. let time = input.readFloat();
  7361. let eventData = skeletonData.events[input.readInt(true)];
  7362. let event = new Event(time, eventData);
  7363. event.intValue = input.readInt(false);
  7364. event.floatValue = input.readFloat();
  7365. event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
  7366. if (event.data.audioPath != null) {
  7367. event.volume = input.readFloat();
  7368. event.balance = input.readFloat();
  7369. }
  7370. timeline.setFrame(i, event);
  7371. }
  7372. timelines.push(timeline);
  7373. duration = Math.max(duration, timeline.frames[eventCount - 1]);
  7374. }
  7375. return new Animation(name, timelines, duration);
  7376. }
  7377. readCurve (input, frameIndex, timeline) {
  7378. switch (input.readByte()) {
  7379. case SkeletonBinary.CURVE_STEPPED:
  7380. timeline.setStepped(frameIndex);
  7381. break;
  7382. case SkeletonBinary.CURVE_BEZIER:
  7383. this.setCurve(timeline, frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat());
  7384. break;
  7385. }
  7386. }
  7387. setCurve (timeline, frameIndex, cx1, cy1, cx2, cy2) {
  7388. timeline.setCurve(frameIndex, cx1, cy1, cx2, cy2);
  7389. }
  7390. } SkeletonBinary.__initStatic(); SkeletonBinary.__initStatic2(); SkeletonBinary.__initStatic3(); SkeletonBinary.__initStatic4(); SkeletonBinary.__initStatic5(); SkeletonBinary.__initStatic6(); SkeletonBinary.__initStatic7(); SkeletonBinary.__initStatic8(); SkeletonBinary.__initStatic9(); SkeletonBinary.__initStatic10(); SkeletonBinary.__initStatic11(); SkeletonBinary.__initStatic12(); SkeletonBinary.__initStatic13(); SkeletonBinary.__initStatic14(); SkeletonBinary.__initStatic15(); SkeletonBinary.__initStatic16(); SkeletonBinary.__initStatic17(); SkeletonBinary.__initStatic18(); SkeletonBinary.__initStatic19();
  7391. class LinkedMesh {
  7392. constructor (mesh, skin, slotIndex, parent, inheritDeform) {
  7393. this.mesh = mesh;
  7394. this.skin = skin;
  7395. this.slotIndex = slotIndex;
  7396. this.parent = parent;
  7397. this.inheritDeform = inheritDeform;
  7398. }
  7399. }
  7400. class Vertices {
  7401. constructor( bones = null, vertices = null) {this.bones = bones;this.vertices = vertices; }
  7402. }
  7403. /**
  7404. * @public
  7405. */
  7406. class SkeletonBounds {constructor() { SkeletonBounds.prototype.__init.call(this);SkeletonBounds.prototype.__init2.call(this);SkeletonBounds.prototype.__init3.call(this);SkeletonBounds.prototype.__init4.call(this);SkeletonBounds.prototype.__init5.call(this);SkeletonBounds.prototype.__init6.call(this);SkeletonBounds.prototype.__init7.call(this); }
  7407. __init() {this.minX = 0;} __init2() {this.minY = 0;} __init3() {this.maxX = 0;} __init4() {this.maxY = 0;}
  7408. __init5() {this.boundingBoxes = new Array();}
  7409. __init6() {this.polygons = new Array();}
  7410. __init7() {this.polygonPool = new Pool(() => {
  7411. return Utils.newFloatArray(16);
  7412. });}
  7413. update (skeleton, updateAabb) {
  7414. if (skeleton == null) throw new Error("skeleton cannot be null.");
  7415. let boundingBoxes = this.boundingBoxes;
  7416. let polygons = this.polygons;
  7417. let polygonPool = this.polygonPool;
  7418. let slots = skeleton.slots;
  7419. let slotCount = slots.length;
  7420. boundingBoxes.length = 0;
  7421. polygonPool.freeAll(polygons);
  7422. polygons.length = 0;
  7423. for (let i = 0; i < slotCount; i++) {
  7424. let slot = slots[i];
  7425. if (!slot.bone.active) continue;
  7426. let attachment = slot.getAttachment();
  7427. if (attachment instanceof BoundingBoxAttachment) {
  7428. let boundingBox = attachment ;
  7429. boundingBoxes.push(boundingBox);
  7430. let polygon = polygonPool.obtain();
  7431. if (polygon.length != boundingBox.worldVerticesLength) {
  7432. polygon = Utils.newFloatArray(boundingBox.worldVerticesLength);
  7433. }
  7434. polygons.push(polygon);
  7435. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  7436. }
  7437. }
  7438. if (updateAabb) {
  7439. this.aabbCompute();
  7440. } else {
  7441. this.minX = Number.POSITIVE_INFINITY;
  7442. this.minY = Number.POSITIVE_INFINITY;
  7443. this.maxX = Number.NEGATIVE_INFINITY;
  7444. this.maxY = Number.NEGATIVE_INFINITY;
  7445. }
  7446. }
  7447. aabbCompute () {
  7448. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  7449. let polygons = this.polygons;
  7450. for (let i = 0, n = polygons.length; i < n; i++) {
  7451. let polygon = polygons[i];
  7452. let vertices = polygon;
  7453. for (let ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  7454. let x = vertices[ii];
  7455. let y = vertices[ii + 1];
  7456. minX = Math.min(minX, x);
  7457. minY = Math.min(minY, y);
  7458. maxX = Math.max(maxX, x);
  7459. maxY = Math.max(maxY, y);
  7460. }
  7461. }
  7462. this.minX = minX;
  7463. this.minY = minY;
  7464. this.maxX = maxX;
  7465. this.maxY = maxY;
  7466. }
  7467. /** Returns true if the axis aligned bounding box contains the point. */
  7468. aabbContainsPoint (x, y) {
  7469. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  7470. }
  7471. /** Returns true if the axis aligned bounding box intersects the line segment. */
  7472. aabbIntersectsSegment (x1, y1, x2, y2) {
  7473. let minX = this.minX;
  7474. let minY = this.minY;
  7475. let maxX = this.maxX;
  7476. let maxY = this.maxY;
  7477. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  7478. return false;
  7479. let m = (y2 - y1) / (x2 - x1);
  7480. let y = m * (minX - x1) + y1;
  7481. if (y > minY && y < maxY) return true;
  7482. y = m * (maxX - x1) + y1;
  7483. if (y > minY && y < maxY) return true;
  7484. let x = (minY - y1) / m + x1;
  7485. if (x > minX && x < maxX) return true;
  7486. x = (maxY - y1) / m + x1;
  7487. if (x > minX && x < maxX) return true;
  7488. return false;
  7489. }
  7490. /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */
  7491. aabbIntersectsSkeleton (bounds) {
  7492. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  7493. }
  7494. /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more
  7495. * efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */
  7496. containsPoint (x, y) {
  7497. let polygons = this.polygons;
  7498. for (let i = 0, n = polygons.length; i < n; i++)
  7499. if (this.containsPointPolygon(polygons[i], x, y)) return this.boundingBoxes[i];
  7500. return null;
  7501. }
  7502. /** Returns true if the polygon contains the point. */
  7503. containsPointPolygon (polygon, x, y) {
  7504. let vertices = polygon;
  7505. let nn = polygon.length;
  7506. let prevIndex = nn - 2;
  7507. let inside = false;
  7508. for (let ii = 0; ii < nn; ii += 2) {
  7509. let vertexY = vertices[ii + 1];
  7510. let prevY = vertices[prevIndex + 1];
  7511. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  7512. let vertexX = vertices[ii];
  7513. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) inside = !inside;
  7514. }
  7515. prevIndex = ii;
  7516. }
  7517. return inside;
  7518. }
  7519. /** Returns the first bounding box attachment that contains any part of the line segment, or null. When doing many checks, it
  7520. * is usually more efficient to only call this method if {@link #aabbIntersectsSegment(float, float, float, float)} returns
  7521. * true. */
  7522. intersectsSegment (x1, y1, x2, y2) {
  7523. let polygons = this.polygons;
  7524. for (let i = 0, n = polygons.length; i < n; i++)
  7525. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2)) return this.boundingBoxes[i];
  7526. return null;
  7527. }
  7528. /** Returns true if the polygon contains any part of the line segment. */
  7529. intersectsSegmentPolygon (polygon, x1, y1, x2, y2) {
  7530. let vertices = polygon;
  7531. let nn = polygon.length;
  7532. let width12 = x1 - x2, height12 = y1 - y2;
  7533. let det1 = x1 * y2 - y1 * x2;
  7534. let x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  7535. for (let ii = 0; ii < nn; ii += 2) {
  7536. let x4 = vertices[ii], y4 = vertices[ii + 1];
  7537. let det2 = x3 * y4 - y3 * x4;
  7538. let width34 = x3 - x4, height34 = y3 - y4;
  7539. let det3 = width12 * height34 - height12 * width34;
  7540. let x = (det1 * width34 - width12 * det2) / det3;
  7541. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  7542. let y = (det1 * height34 - height12 * det2) / det3;
  7543. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) return true;
  7544. }
  7545. x3 = x4;
  7546. y3 = y4;
  7547. }
  7548. return false;
  7549. }
  7550. /** Returns the polygon for the specified bounding box, or null. */
  7551. getPolygon (boundingBox) {
  7552. if (boundingBox == null) throw new Error("boundingBox cannot be null.");
  7553. let index = this.boundingBoxes.indexOf(boundingBox);
  7554. return index == -1 ? null : this.polygons[index];
  7555. }
  7556. getWidth () {
  7557. return this.maxX - this.minX;
  7558. }
  7559. getHeight () {
  7560. return this.maxY - this.minY;
  7561. }
  7562. }
  7563. /**
  7564. * @public
  7565. */
  7566. class SkeletonJson {
  7567. __init() {this.scale = 1;}
  7568. __init2() {this.linkedMeshes = new Array();}
  7569. constructor (attachmentLoader) {SkeletonJson.prototype.__init.call(this);SkeletonJson.prototype.__init2.call(this);
  7570. this.attachmentLoader = attachmentLoader;
  7571. }
  7572. readSkeletonData (json) {
  7573. let scale = this.scale;
  7574. let skeletonData = new SkeletonData();
  7575. let root = typeof(json) === "string" ? JSON.parse(json) : json;
  7576. // Skeleton
  7577. let skeletonMap = root.skeleton;
  7578. if (skeletonMap != null) {
  7579. skeletonData.hash = skeletonMap.hash;
  7580. skeletonData.version = skeletonMap.spine;
  7581. if (skeletonData.version.substr(0, 3) !== '3.8') {
  7582. let error = `Spine 3.8 loader cant load version ${skeletonMap.spine}. Please configure your pixi-spine bundle`;
  7583. console.error(error);
  7584. }
  7585. if (skeletonData.version === '3.8.75')
  7586. {
  7587. let error = `Unsupported skeleton data, 3.8.75 is deprecated, please export with a newer version of Spine.`;
  7588. console.error(error);
  7589. }
  7590. skeletonData.x = skeletonMap.x;
  7591. skeletonData.y = skeletonMap.y;
  7592. skeletonData.width = skeletonMap.width;
  7593. skeletonData.height = skeletonMap.height;
  7594. skeletonData.fps = skeletonMap.fps;
  7595. skeletonData.imagesPath = skeletonMap.images;
  7596. }
  7597. // Bones
  7598. if (root.bones) {
  7599. for (let i = 0; i < root.bones.length; i++) {
  7600. let boneMap = root.bones[i];
  7601. let parent = null;
  7602. let parentName = this.getValue(boneMap, "parent", null);
  7603. if (parentName != null) {
  7604. parent = skeletonData.findBone(parentName);
  7605. if (parent == null) throw new Error("Parent bone not found: " + parentName);
  7606. }
  7607. let data = new BoneData(skeletonData.bones.length, boneMap.name, parent);
  7608. data.length = this.getValue(boneMap, "length", 0) * scale;
  7609. data.x = this.getValue(boneMap, "x", 0) * scale;
  7610. data.y = this.getValue(boneMap, "y", 0) * scale;
  7611. data.rotation = this.getValue(boneMap, "rotation", 0);
  7612. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  7613. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  7614. data.shearX = this.getValue(boneMap, "shearX", 0);
  7615. data.shearY = this.getValue(boneMap, "shearY", 0);
  7616. data.transformMode = SkeletonJson.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  7617. data.skinRequired = this.getValue(boneMap, "skin", false);
  7618. skeletonData.bones.push(data);
  7619. }
  7620. }
  7621. // Slots.
  7622. if (root.slots) {
  7623. for (let i = 0; i < root.slots.length; i++) {
  7624. let slotMap = root.slots[i];
  7625. let slotName = slotMap.name;
  7626. let boneName = slotMap.bone;
  7627. let boneData = skeletonData.findBone(boneName);
  7628. if (boneData == null) throw new Error("Slot bone not found: " + boneName);
  7629. let data = new SlotData(skeletonData.slots.length, slotName, boneData);
  7630. let color = this.getValue(slotMap, "color", null);
  7631. if (color != null) data.color.setFromString(color);
  7632. let dark = this.getValue(slotMap, "dark", null);
  7633. if (dark != null) {
  7634. data.darkColor = new Color(1, 1, 1, 1);
  7635. data.darkColor.setFromString(dark);
  7636. }
  7637. data.attachmentName = this.getValue(slotMap, "attachment", null);
  7638. data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  7639. skeletonData.slots.push(data);
  7640. }
  7641. }
  7642. // IK constraints
  7643. if (root.ik) {
  7644. for (let i = 0; i < root.ik.length; i++) {
  7645. let constraintMap = root.ik[i];
  7646. let data = new IkConstraintData(constraintMap.name);
  7647. data.order = this.getValue(constraintMap, "order", 0);
  7648. data.skinRequired = this.getValue(constraintMap, "skin", false);
  7649. for (let j = 0; j < constraintMap.bones.length; j++) {
  7650. let boneName = constraintMap.bones[j];
  7651. let bone = skeletonData.findBone(boneName);
  7652. if (bone == null) throw new Error("IK bone not found: " + boneName);
  7653. data.bones.push(bone);
  7654. }
  7655. let targetName = constraintMap.target;
  7656. data.target = skeletonData.findBone(targetName);
  7657. if (data.target == null) throw new Error("IK target bone not found: " + targetName);
  7658. data.mix = this.getValue(constraintMap, "mix", 1);
  7659. data.softness = this.getValue(constraintMap, "softness", 0) * scale;
  7660. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  7661. data.compress = this.getValue(constraintMap, "compress", false);
  7662. data.stretch = this.getValue(constraintMap, "stretch", false);
  7663. data.uniform = this.getValue(constraintMap, "uniform", false);
  7664. skeletonData.ikConstraints.push(data);
  7665. }
  7666. }
  7667. // Transform constraints.
  7668. if (root.transform) {
  7669. for (let i = 0; i < root.transform.length; i++) {
  7670. let constraintMap = root.transform[i];
  7671. let data = new TransformConstraintData(constraintMap.name);
  7672. data.order = this.getValue(constraintMap, "order", 0);
  7673. data.skinRequired = this.getValue(constraintMap, "skin", false);
  7674. for (let j = 0; j < constraintMap.bones.length; j++) {
  7675. let boneName = constraintMap.bones[j];
  7676. let bone = skeletonData.findBone(boneName);
  7677. if (bone == null) throw new Error("Transform constraint bone not found: " + boneName);
  7678. data.bones.push(bone);
  7679. }
  7680. let targetName = constraintMap.target;
  7681. data.target = skeletonData.findBone(targetName);
  7682. if (data.target == null) throw new Error("Transform constraint target bone not found: " + targetName);
  7683. data.local = this.getValue(constraintMap, "local", false);
  7684. data.relative = this.getValue(constraintMap, "relative", false);
  7685. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  7686. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  7687. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  7688. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  7689. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  7690. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  7691. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  7692. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  7693. data.scaleMix = this.getValue(constraintMap, "scaleMix", 1);
  7694. data.shearMix = this.getValue(constraintMap, "shearMix", 1);
  7695. skeletonData.transformConstraints.push(data);
  7696. }
  7697. }
  7698. // Path constraints.
  7699. if (root.path) {
  7700. for (let i = 0; i < root.path.length; i++) {
  7701. let constraintMap = root.path[i];
  7702. let data = new PathConstraintData(constraintMap.name);
  7703. data.order = this.getValue(constraintMap, "order", 0);
  7704. data.skinRequired = this.getValue(constraintMap, "skin", false);
  7705. for (let j = 0; j < constraintMap.bones.length; j++) {
  7706. let boneName = constraintMap.bones[j];
  7707. let bone = skeletonData.findBone(boneName);
  7708. if (bone == null) throw new Error("Transform constraint bone not found: " + boneName);
  7709. data.bones.push(bone);
  7710. }
  7711. let targetName = constraintMap.target;
  7712. data.target = skeletonData.findSlot(targetName);
  7713. if (data.target == null) throw new Error("Path target slot not found: " + targetName);
  7714. data.positionMode = SkeletonJson.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  7715. data.spacingMode = SkeletonJson.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  7716. data.rotateMode = SkeletonJson.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  7717. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  7718. data.position = this.getValue(constraintMap, "position", 0);
  7719. if (data.positionMode == PositionMode.Fixed) data.position *= scale;
  7720. data.spacing = this.getValue(constraintMap, "spacing", 0);
  7721. if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) data.spacing *= scale;
  7722. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  7723. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  7724. skeletonData.pathConstraints.push(data);
  7725. }
  7726. }
  7727. // Skins.
  7728. if (root.skins) {
  7729. for (let i = 0; i < root.skins.length; i++) {
  7730. let skinMap = root.skins[i];
  7731. let skin = new Skin(skinMap.name);
  7732. if (skinMap.bones) {
  7733. for (let ii = 0; ii < skinMap.bones.length; ii++) {
  7734. let bone = skeletonData.findBone(skinMap.bones[ii]);
  7735. if (bone == null) throw new Error("Skin bone not found: " + skinMap.bones[i]);
  7736. skin.bones.push(bone);
  7737. }
  7738. }
  7739. if (skinMap.ik) {
  7740. for (let ii = 0; ii < skinMap.ik.length; ii++) {
  7741. let constraint = skeletonData.findIkConstraint(skinMap.ik[ii]);
  7742. if (constraint == null) throw new Error("Skin IK constraint not found: " + skinMap.ik[i]);
  7743. skin.constraints.push(constraint);
  7744. }
  7745. }
  7746. if (skinMap.transform) {
  7747. for (let ii = 0; ii < skinMap.transform.length; ii++) {
  7748. let constraint = skeletonData.findTransformConstraint(skinMap.transform[ii]);
  7749. if (constraint == null) throw new Error("Skin transform constraint not found: " + skinMap.transform[i]);
  7750. skin.constraints.push(constraint);
  7751. }
  7752. }
  7753. if (skinMap.path) {
  7754. for (let ii = 0; ii < skinMap.path.length; ii++) {
  7755. let constraint = skeletonData.findPathConstraint(skinMap.path[ii]);
  7756. if (constraint == null) throw new Error("Skin path constraint not found: " + skinMap.path[i]);
  7757. skin.constraints.push(constraint);
  7758. }
  7759. }
  7760. for (let slotName in skinMap.attachments) {
  7761. let slot = skeletonData.findSlot(slotName);
  7762. if (slot == null) throw new Error("Slot not found: " + slotName);
  7763. let slotMap = skinMap.attachments[slotName];
  7764. for (let entryName in slotMap) {
  7765. let attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
  7766. if (attachment != null) skin.setAttachment(slot.index, entryName, attachment);
  7767. }
  7768. }
  7769. skeletonData.skins.push(skin);
  7770. if (skin.name == "default") skeletonData.defaultSkin = skin;
  7771. }
  7772. }
  7773. // Linked meshes.
  7774. for (let i = 0, n = this.linkedMeshes.length; i < n; i++) {
  7775. let linkedMesh = this.linkedMeshes[i];
  7776. let skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  7777. if (skin == null) throw new Error("Skin not found: " + linkedMesh.skin);
  7778. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  7779. if (parent == null) throw new Error("Parent mesh not found: " + linkedMesh.parent);
  7780. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent : linkedMesh.mesh;
  7781. linkedMesh.mesh.setParentMesh( parent);
  7782. // linkedMesh.mesh.updateUVs();
  7783. }
  7784. this.linkedMeshes.length = 0;
  7785. // Events.
  7786. if (root.events) {
  7787. for (let eventName in root.events) {
  7788. let eventMap = root.events[eventName];
  7789. let data = new EventData(eventName);
  7790. data.intValue = this.getValue(eventMap, "int", 0);
  7791. data.floatValue = this.getValue(eventMap, "float", 0);
  7792. data.stringValue = this.getValue(eventMap, "string", "");
  7793. data.audioPath = this.getValue(eventMap, "audio", null);
  7794. if (data.audioPath != null) {
  7795. data.volume = this.getValue(eventMap, "volume", 1);
  7796. data.balance = this.getValue(eventMap, "balance", 0);
  7797. }
  7798. skeletonData.events.push(data);
  7799. }
  7800. }
  7801. // Animations.
  7802. if (root.animations) {
  7803. for (let animationName in root.animations) {
  7804. let animationMap = root.animations[animationName];
  7805. this.readAnimation(animationMap, animationName, skeletonData);
  7806. }
  7807. }
  7808. return skeletonData;
  7809. }
  7810. readAttachment (map, skin, slotIndex, name, skeletonData) {
  7811. let scale = this.scale;
  7812. name = this.getValue(map, "name", name);
  7813. let type = this.getValue(map, "type", "region");
  7814. switch (type) {
  7815. case "region": {
  7816. let path = this.getValue(map, "path", name);
  7817. let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  7818. if (region == null) return null;
  7819. region.path = path;
  7820. region.x = this.getValue(map, "x", 0) * scale;
  7821. region.y = this.getValue(map, "y", 0) * scale;
  7822. region.scaleX = this.getValue(map, "scaleX", 1);
  7823. region.scaleY = this.getValue(map, "scaleY", 1);
  7824. region.rotation = this.getValue(map, "rotation", 0);
  7825. region.width = map.width * scale;
  7826. region.height = map.height * scale;
  7827. let color = this.getValue(map, "color", null);
  7828. if (color != null) region.color.setFromString(color);
  7829. // region.updateOffset();
  7830. return region;
  7831. }
  7832. case "boundingbox": {
  7833. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  7834. if (box == null) return null;
  7835. this.readVertices(map, box, map.vertexCount << 1);
  7836. let color = this.getValue(map, "color", null);
  7837. if (color != null) box.color.setFromString(color);
  7838. return box;
  7839. }
  7840. case "mesh":
  7841. case "linkedmesh": {
  7842. let path = this.getValue(map, "path", name);
  7843. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  7844. if (mesh == null) return null;
  7845. mesh.path = path;
  7846. let color = this.getValue(map, "color", null);
  7847. if (color != null) mesh.color.setFromString(color);
  7848. mesh.width = this.getValue(map, "width", 0) * scale;
  7849. mesh.height = this.getValue(map, "height", 0) * scale;
  7850. let parent = this.getValue(map, "parent", null);
  7851. if (parent != null) {
  7852. this.linkedMeshes.push(new LinkedMesh$1(mesh, this.getValue(map, "skin", null), slotIndex, parent, this.getValue(map, "deform", true)));
  7853. return mesh;
  7854. }
  7855. let uvs = map.uvs;
  7856. this.readVertices(map, mesh, uvs.length);
  7857. mesh.triangles = map.triangles;
  7858. mesh.regionUVs = new Float32Array(uvs);
  7859. // mesh.updateUVs();
  7860. mesh.edges = this.getValue(map, "edges", null);
  7861. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  7862. return mesh;
  7863. }
  7864. case "path": {
  7865. let path = this.attachmentLoader.newPathAttachment(skin, name);
  7866. if (path == null) return null;
  7867. path.closed = this.getValue(map, "closed", false);
  7868. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  7869. let vertexCount = map.vertexCount;
  7870. this.readVertices(map, path, vertexCount << 1);
  7871. let lengths = Utils.newArray(vertexCount / 3, 0);
  7872. for (let i = 0; i < map.lengths.length; i++)
  7873. lengths[i] = map.lengths[i] * scale;
  7874. path.lengths = lengths;
  7875. let color = this.getValue(map, "color", null);
  7876. if (color != null) path.color.setFromString(color);
  7877. return path;
  7878. }
  7879. case "point": {
  7880. let point = this.attachmentLoader.newPointAttachment(skin, name);
  7881. if (point == null) return null;
  7882. point.x = this.getValue(map, "x", 0) * scale;
  7883. point.y = this.getValue(map, "y", 0) * scale;
  7884. point.rotation = this.getValue(map, "rotation", 0);
  7885. let color = this.getValue(map, "color", null);
  7886. if (color != null) point.color.setFromString(color);
  7887. return point;
  7888. }
  7889. case "clipping": {
  7890. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  7891. if (clip == null) return null;
  7892. let end = this.getValue(map, "end", null);
  7893. if (end != null) {
  7894. let slot = skeletonData.findSlot(end);
  7895. if (slot == null) throw new Error("Clipping end slot not found: " + end);
  7896. clip.endSlot = slot;
  7897. }
  7898. let vertexCount = map.vertexCount;
  7899. this.readVertices(map, clip, vertexCount << 1);
  7900. let color = this.getValue(map, "color", null);
  7901. if (color != null) clip.color.setFromString(color);
  7902. return clip;
  7903. }
  7904. }
  7905. return null;
  7906. }
  7907. readVertices (map, attachment, verticesLength) {
  7908. let scale = this.scale;
  7909. attachment.worldVerticesLength = verticesLength;
  7910. let vertices = map.vertices;
  7911. if (verticesLength == vertices.length) {
  7912. let scaledVertices = Utils.toFloatArray(vertices);
  7913. if (scale != 1) {
  7914. for (let i = 0, n = vertices.length; i < n; i++)
  7915. scaledVertices[i] *= scale;
  7916. }
  7917. attachment.vertices = scaledVertices;
  7918. return;
  7919. }
  7920. let weights = new Array();
  7921. let bones = new Array();
  7922. for (let i = 0, n = vertices.length; i < n;) {
  7923. let boneCount = vertices[i++];
  7924. bones.push(boneCount);
  7925. for (let nn = i + boneCount * 4; i < nn; i += 4) {
  7926. bones.push(vertices[i]);
  7927. weights.push(vertices[i + 1] * scale);
  7928. weights.push(vertices[i + 2] * scale);
  7929. weights.push(vertices[i + 3]);
  7930. }
  7931. }
  7932. attachment.bones = bones;
  7933. attachment.vertices = Utils.toFloatArray(weights);
  7934. }
  7935. readAnimation (map, name, skeletonData) {
  7936. let scale = this.scale;
  7937. let timelines = new Array();
  7938. let duration = 0;
  7939. // Slot timelines.
  7940. if (map.slots) {
  7941. for (let slotName in map.slots) {
  7942. let slotMap = map.slots[slotName];
  7943. let slotIndex = skeletonData.findSlotIndex(slotName);
  7944. if (slotIndex == -1) throw new Error("Slot not found: " + slotName);
  7945. for (let timelineName in slotMap) {
  7946. let timelineMap = slotMap[timelineName];
  7947. if (timelineName == "attachment") {
  7948. let timeline = new AttachmentTimeline(timelineMap.length);
  7949. timeline.slotIndex = slotIndex;
  7950. let frameIndex = 0;
  7951. for (let i = 0; i < timelineMap.length; i++) {
  7952. let valueMap = timelineMap[i];
  7953. timeline.setFrame(frameIndex++, this.getValue(valueMap, "time", 0), valueMap.name);
  7954. }
  7955. timelines.push(timeline);
  7956. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  7957. } else if (timelineName == "color") {
  7958. let timeline = new ColorTimeline(timelineMap.length);
  7959. timeline.slotIndex = slotIndex;
  7960. let frameIndex = 0;
  7961. for (let i = 0; i < timelineMap.length; i++) {
  7962. let valueMap = timelineMap[i];
  7963. let color = new Color();
  7964. color.setFromString(valueMap.color || "ffffffff");
  7965. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), color.r, color.g, color.b, color.a);
  7966. this.readCurve(valueMap, timeline, frameIndex);
  7967. frameIndex++;
  7968. }
  7969. timelines.push(timeline);
  7970. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * ColorTimeline.ENTRIES]);
  7971. } else if (timelineName == "twoColor") {
  7972. let timeline = new TwoColorTimeline(timelineMap.length);
  7973. timeline.slotIndex = slotIndex;
  7974. let frameIndex = 0;
  7975. for (let i = 0; i < timelineMap.length; i++) {
  7976. let valueMap = timelineMap[i];
  7977. let light = new Color();
  7978. let dark = new Color();
  7979. light.setFromString(valueMap.light);
  7980. dark.setFromString(valueMap.dark);
  7981. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
  7982. this.readCurve(valueMap, timeline, frameIndex);
  7983. frameIndex++;
  7984. }
  7985. timelines.push(timeline);
  7986. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * TwoColorTimeline.ENTRIES]);
  7987. } else
  7988. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  7989. }
  7990. }
  7991. }
  7992. // Bone timelines.
  7993. if (map.bones) {
  7994. for (let boneName in map.bones) {
  7995. let boneMap = map.bones[boneName];
  7996. let boneIndex = skeletonData.findBoneIndex(boneName);
  7997. if (boneIndex == -1) throw new Error("Bone not found: " + boneName);
  7998. for (let timelineName in boneMap) {
  7999. let timelineMap = boneMap[timelineName];
  8000. if (timelineName === "rotate") {
  8001. let timeline = new RotateTimeline(timelineMap.length);
  8002. timeline.boneIndex = boneIndex;
  8003. let frameIndex = 0;
  8004. for (let i = 0; i < timelineMap.length; i++) {
  8005. let valueMap = timelineMap[i];
  8006. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "angle", 0));
  8007. this.readCurve(valueMap, timeline, frameIndex);
  8008. frameIndex++;
  8009. }
  8010. timelines.push(timeline);
  8011. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * RotateTimeline.ENTRIES]);
  8012. } else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
  8013. let timeline = null;
  8014. let timelineScale = 1, defaultValue = 0;
  8015. if (timelineName === "scale") {
  8016. timeline = new ScaleTimeline(timelineMap.length);
  8017. defaultValue = 1;
  8018. } else if (timelineName === "shear")
  8019. timeline = new ShearTimeline(timelineMap.length);
  8020. else {
  8021. timeline = new TranslateTimeline(timelineMap.length);
  8022. timelineScale = scale;
  8023. }
  8024. timeline.boneIndex = boneIndex;
  8025. let frameIndex = 0;
  8026. for (let i = 0; i < timelineMap.length; i++) {
  8027. let valueMap = timelineMap[i];
  8028. let x = this.getValue(valueMap, "x", defaultValue), y = this.getValue(valueMap, "y", defaultValue);
  8029. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), x * timelineScale, y * timelineScale);
  8030. this.readCurve(valueMap, timeline, frameIndex);
  8031. frameIndex++;
  8032. }
  8033. timelines.push(timeline);
  8034. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * TranslateTimeline.ENTRIES]);
  8035. } else
  8036. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  8037. }
  8038. }
  8039. }
  8040. // IK constraint timelines.
  8041. if (map.ik) {
  8042. for (let constraintName in map.ik) {
  8043. let constraintMap = map.ik[constraintName];
  8044. let constraint = skeletonData.findIkConstraint(constraintName);
  8045. let timeline = new IkConstraintTimeline(constraintMap.length);
  8046. timeline.ikConstraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  8047. let frameIndex = 0;
  8048. for (let i = 0; i < constraintMap.length; i++) {
  8049. let valueMap = constraintMap[i];
  8050. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "mix", 1), this.getValue(valueMap, "softness", 0) * scale,
  8051. this.getValue(valueMap, "bendPositive", true) ? 1 : -1, this.getValue(valueMap, "compress", false), this.getValue(valueMap, "stretch", false));
  8052. this.readCurve(valueMap, timeline, frameIndex);
  8053. frameIndex++;
  8054. }
  8055. timelines.push(timeline);
  8056. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * IkConstraintTimeline.ENTRIES]);
  8057. }
  8058. }
  8059. // Transform constraint timelines.
  8060. if (map.transform) {
  8061. for (let constraintName in map.transform) {
  8062. let constraintMap = map.transform[constraintName];
  8063. let constraint = skeletonData.findTransformConstraint(constraintName);
  8064. let timeline = new TransformConstraintTimeline(constraintMap.length);
  8065. timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  8066. let frameIndex = 0;
  8067. for (let i = 0; i < constraintMap.length; i++) {
  8068. let valueMap = constraintMap[i];
  8069. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "rotateMix", 1),
  8070. this.getValue(valueMap, "translateMix", 1), this.getValue(valueMap, "scaleMix", 1), this.getValue(valueMap, "shearMix", 1));
  8071. this.readCurve(valueMap, timeline, frameIndex);
  8072. frameIndex++;
  8073. }
  8074. timelines.push(timeline);
  8075. duration = Math.max(duration,
  8076. timeline.frames[(timeline.getFrameCount() - 1) * TransformConstraintTimeline.ENTRIES]);
  8077. }
  8078. }
  8079. // Path constraint timelines.
  8080. if (map.path) {
  8081. for (let constraintName in map.path) {
  8082. let constraintMap = map.path[constraintName];
  8083. let index = skeletonData.findPathConstraintIndex(constraintName);
  8084. if (index == -1) throw new Error("Path constraint not found: " + constraintName);
  8085. let data = skeletonData.pathConstraints[index];
  8086. for (let timelineName in constraintMap) {
  8087. let timelineMap = constraintMap[timelineName];
  8088. if (timelineName === "position" || timelineName === "spacing") {
  8089. let timeline = null;
  8090. let timelineScale = 1;
  8091. if (timelineName === "spacing") {
  8092. timeline = new PathConstraintSpacingTimeline(timelineMap.length);
  8093. if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) timelineScale = scale;
  8094. } else {
  8095. timeline = new PathConstraintPositionTimeline(timelineMap.length);
  8096. if (data.positionMode == PositionMode.Fixed) timelineScale = scale;
  8097. }
  8098. timeline.pathConstraintIndex = index;
  8099. let frameIndex = 0;
  8100. for (let i = 0; i < timelineMap.length; i++) {
  8101. let valueMap = timelineMap[i];
  8102. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, timelineName, 0) * timelineScale);
  8103. this.readCurve(valueMap, timeline, frameIndex);
  8104. frameIndex++;
  8105. }
  8106. timelines.push(timeline);
  8107. duration = Math.max(duration,
  8108. timeline.frames[(timeline.getFrameCount() - 1) * PathConstraintPositionTimeline.ENTRIES]);
  8109. } else if (timelineName === "mix") {
  8110. let timeline = new PathConstraintMixTimeline(timelineMap.length);
  8111. timeline.pathConstraintIndex = index;
  8112. let frameIndex = 0;
  8113. for (let i = 0; i < timelineMap.length; i++) {
  8114. let valueMap = timelineMap[i];
  8115. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "rotateMix", 1),
  8116. this.getValue(valueMap, "translateMix", 1));
  8117. this.readCurve(valueMap, timeline, frameIndex);
  8118. frameIndex++;
  8119. }
  8120. timelines.push(timeline);
  8121. duration = Math.max(duration,
  8122. timeline.frames[(timeline.getFrameCount() - 1) * PathConstraintMixTimeline.ENTRIES]);
  8123. }
  8124. }
  8125. }
  8126. }
  8127. // Deform timelines.
  8128. if (map.deform) {
  8129. for (let deformName in map.deform) {
  8130. let deformMap = map.deform[deformName];
  8131. let skin = skeletonData.findSkin(deformName);
  8132. if (skin == null) {
  8133. if (settings.FAIL_ON_NON_EXISTING_SKIN) {
  8134. throw new Error("Skin not found: " + deformName);
  8135. } else {
  8136. continue;
  8137. }
  8138. }
  8139. for (let slotName in deformMap) {
  8140. let slotMap = deformMap[slotName];
  8141. let slotIndex = skeletonData.findSlotIndex(slotName);
  8142. if (slotIndex == -1) throw new Error("Slot not found: " + slotMap.name);
  8143. for (let timelineName in slotMap) {
  8144. let timelineMap = slotMap[timelineName];
  8145. let attachment = skin.getAttachment(slotIndex, timelineName);
  8146. if (attachment == null) throw new Error("Deform attachment not found: " + timelineMap.name);
  8147. let weighted = attachment.bones != null;
  8148. let vertices = attachment.vertices;
  8149. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  8150. let timeline = new DeformTimeline(timelineMap.length);
  8151. timeline.slotIndex = slotIndex;
  8152. timeline.attachment = attachment;
  8153. let frameIndex = 0;
  8154. for (let j = 0; j < timelineMap.length; j++) {
  8155. let valueMap = timelineMap[j];
  8156. let deform;
  8157. let verticesValue = this.getValue(valueMap, "vertices", null);
  8158. if (verticesValue == null)
  8159. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  8160. else {
  8161. deform = Utils.newFloatArray(deformLength);
  8162. let start = this.getValue(valueMap, "offset", 0);
  8163. Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  8164. if (scale != 1) {
  8165. for (let i = start, n = i + verticesValue.length; i < n; i++)
  8166. deform[i] *= scale;
  8167. }
  8168. if (!weighted) {
  8169. for (let i = 0; i < deformLength; i++)
  8170. deform[i] += vertices[i];
  8171. }
  8172. }
  8173. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), deform);
  8174. this.readCurve(valueMap, timeline, frameIndex);
  8175. frameIndex++;
  8176. }
  8177. timelines.push(timeline);
  8178. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  8179. }
  8180. }
  8181. }
  8182. }
  8183. // Draw order timeline.
  8184. let drawOrderNode = map.drawOrder;
  8185. if (drawOrderNode == null) drawOrderNode = map.draworder;
  8186. if (drawOrderNode != null) {
  8187. let timeline = new DrawOrderTimeline(drawOrderNode.length);
  8188. let slotCount = skeletonData.slots.length;
  8189. let frameIndex = 0;
  8190. for (let j = 0; j < drawOrderNode.length; j++) {
  8191. let drawOrderMap = drawOrderNode[j];
  8192. let drawOrder = null;
  8193. let offsets = this.getValue(drawOrderMap, "offsets", null);
  8194. if (offsets != null) {
  8195. drawOrder = Utils.newArray(slotCount, -1);
  8196. let unchanged = Utils.newArray(slotCount - offsets.length, 0);
  8197. let originalIndex = 0, unchangedIndex = 0;
  8198. for (let i = 0; i < offsets.length; i++) {
  8199. let offsetMap = offsets[i];
  8200. let slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  8201. if (slotIndex == -1) throw new Error("Slot not found: " + offsetMap.slot);
  8202. // Collect unchanged items.
  8203. while (originalIndex != slotIndex)
  8204. unchanged[unchangedIndex++] = originalIndex++;
  8205. // Set changed items.
  8206. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  8207. }
  8208. // Collect remaining unchanged items.
  8209. while (originalIndex < slotCount)
  8210. unchanged[unchangedIndex++] = originalIndex++;
  8211. // Fill in unchanged items.
  8212. for (let i = slotCount - 1; i >= 0; i--)
  8213. if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex];
  8214. }
  8215. timeline.setFrame(frameIndex++, this.getValue(drawOrderMap, "time", 0), drawOrder);
  8216. }
  8217. timelines.push(timeline);
  8218. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  8219. }
  8220. // Event timeline.
  8221. if (map.events) {
  8222. let timeline = new EventTimeline(map.events.length);
  8223. let frameIndex = 0;
  8224. for (let i = 0; i < map.events.length; i++) {
  8225. let eventMap = map.events[i];
  8226. let eventData = skeletonData.findEvent(eventMap.name);
  8227. if (eventData == null) throw new Error("Event not found: " + eventMap.name);
  8228. let event = new Event(Utils.toSinglePrecision(this.getValue(eventMap, "time", 0)), eventData);
  8229. event.intValue = this.getValue(eventMap, "int", eventData.intValue);
  8230. event.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  8231. event.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  8232. if (event.data.audioPath != null) {
  8233. event.volume = this.getValue(eventMap, "volume", 1);
  8234. event.balance = this.getValue(eventMap, "balance", 0);
  8235. }
  8236. timeline.setFrame(frameIndex++, event);
  8237. }
  8238. timelines.push(timeline);
  8239. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  8240. }
  8241. if (isNaN(duration)) {
  8242. throw new Error("Error while parsing animation, duration is NaN");
  8243. }
  8244. skeletonData.animations.push(new Animation(name, timelines, duration));
  8245. }
  8246. readCurve (map, timeline, frameIndex) {
  8247. if (!map.hasOwnProperty("curve")) return;
  8248. if (map.curve === "stepped")
  8249. timeline.setStepped(frameIndex);
  8250. else {
  8251. let curve = map.curve;
  8252. timeline.setCurve(frameIndex, curve, this.getValue(map, "c2", 0), this.getValue(map, "c3", 1), this.getValue(map, "c4", 1));
  8253. }
  8254. }
  8255. getValue (map, prop, defaultValue) {
  8256. return map[prop] !== undefined ? map[prop] : defaultValue;
  8257. }
  8258. static blendModeFromString (str) {
  8259. str = str.toLowerCase();
  8260. if (str == "normal") return constants.BLEND_MODES.NORMAL;
  8261. if (str == "additive") return constants.BLEND_MODES.ADD;
  8262. if (str == "multiply") return constants.BLEND_MODES.MULTIPLY;
  8263. if (str == "screen") return constants.BLEND_MODES.SCREEN;
  8264. throw new Error(`Unknown blend mode: ${str}`);
  8265. }
  8266. static positionModeFromString (str) {
  8267. str = str.toLowerCase();
  8268. if (str == "fixed") return PositionMode.Fixed;
  8269. if (str == "percent") return PositionMode.Percent;
  8270. throw new Error(`Unknown position mode: ${str}`);
  8271. }
  8272. static spacingModeFromString (str) {
  8273. str = str.toLowerCase();
  8274. if (str == "length") return SpacingMode.Length;
  8275. if (str == "fixed") return SpacingMode.Fixed;
  8276. if (str == "percent") return SpacingMode.Percent;
  8277. throw new Error(`Unknown position mode: ${str}`);
  8278. }
  8279. static rotateModeFromString (str) {
  8280. str = str.toLowerCase();
  8281. if (str == "tangent") return RotateMode.Tangent;
  8282. if (str == "chain") return RotateMode.Chain;
  8283. if (str == "chainscale") return RotateMode.ChainScale;
  8284. throw new Error(`Unknown rotate mode: ${str}`);
  8285. }
  8286. static transformModeFromString(str) {
  8287. str = str.toLowerCase();
  8288. if (str == "normal") return TransformMode.Normal;
  8289. if (str == "onlytranslation") return TransformMode.OnlyTranslation;
  8290. if (str == "norotationorreflection") return TransformMode.NoRotationOrReflection;
  8291. if (str == "noscale") return TransformMode.NoScale;
  8292. if (str == "noscaleorreflection") return TransformMode.NoScaleOrReflection;
  8293. throw new Error(`Unknown transform mode: ${str}`);
  8294. }
  8295. }
  8296. class LinkedMesh$1 {
  8297. constructor (mesh, skin, slotIndex, parent, inheritDeform) {
  8298. this.mesh = mesh;
  8299. this.skin = skin;
  8300. this.slotIndex = slotIndex;
  8301. this.parent = parent;
  8302. this.inheritDeform = inheritDeform;
  8303. }
  8304. }
  8305. /**
  8306. * @public
  8307. */
  8308. class Spine extends SpineBase {
  8309. createSkeleton(spineData) {
  8310. this.skeleton = new Skeleton(spineData);
  8311. this.skeleton.updateWorldTransform();
  8312. this.stateData = new AnimationStateData(spineData);
  8313. this.state = new AnimationState(this.stateData);
  8314. }
  8315. }
  8316. var spine38 = /*#__PURE__*/Object.freeze({
  8317. __proto__: null,
  8318. Animation: Animation,
  8319. AnimationState: AnimationState,
  8320. AnimationStateAdapter: AnimationStateAdapter,
  8321. AnimationStateData: AnimationStateData,
  8322. AtlasAttachmentLoader: AtlasAttachmentLoader,
  8323. Attachment: Attachment,
  8324. AttachmentTimeline: AttachmentTimeline,
  8325. Bone: Bone,
  8326. BoneData: BoneData,
  8327. BoundingBoxAttachment: BoundingBoxAttachment,
  8328. ClippingAttachment: ClippingAttachment,
  8329. ColorTimeline: ColorTimeline,
  8330. ConstraintData: ConstraintData,
  8331. CurveTimeline: CurveTimeline,
  8332. DeformTimeline: DeformTimeline,
  8333. DrawOrderTimeline: DrawOrderTimeline,
  8334. Event: Event,
  8335. EventData: EventData,
  8336. EventQueue: EventQueue,
  8337. EventTimeline: EventTimeline,
  8338. get EventType () { return EventType; },
  8339. IkConstraint: IkConstraint,
  8340. IkConstraintData: IkConstraintData,
  8341. IkConstraintTimeline: IkConstraintTimeline,
  8342. JitterEffect: JitterEffect,
  8343. MeshAttachment: MeshAttachment,
  8344. get MixBlend () { return MixBlend; },
  8345. get MixDirection () { return MixDirection; },
  8346. PathAttachment: PathAttachment,
  8347. PathConstraint: PathConstraint,
  8348. PathConstraintData: PathConstraintData,
  8349. PathConstraintMixTimeline: PathConstraintMixTimeline,
  8350. PathConstraintPositionTimeline: PathConstraintPositionTimeline,
  8351. PathConstraintSpacingTimeline: PathConstraintSpacingTimeline,
  8352. PointAttachment: PointAttachment,
  8353. get PositionMode () { return PositionMode; },
  8354. RegionAttachment: RegionAttachment,
  8355. get RotateMode () { return RotateMode; },
  8356. RotateTimeline: RotateTimeline,
  8357. ScaleTimeline: ScaleTimeline,
  8358. ShearTimeline: ShearTimeline,
  8359. Skeleton: Skeleton,
  8360. SkeletonBinary: SkeletonBinary,
  8361. SkeletonBounds: SkeletonBounds,
  8362. SkeletonData: SkeletonData,
  8363. SkeletonJson: SkeletonJson,
  8364. Skin: Skin,
  8365. SkinEntry: SkinEntry,
  8366. Slot: Slot,
  8367. SlotData: SlotData,
  8368. get SpacingMode () { return SpacingMode; },
  8369. Spine: Spine,
  8370. SwirlEffect: SwirlEffect,
  8371. get TimelineType () { return TimelineType; },
  8372. TrackEntry: TrackEntry,
  8373. TransformConstraint: TransformConstraint,
  8374. TransformConstraintData: TransformConstraintData,
  8375. TransformConstraintTimeline: TransformConstraintTimeline,
  8376. get TransformMode () { return TransformMode; },
  8377. TranslateTimeline: TranslateTimeline,
  8378. TwoColorTimeline: TwoColorTimeline,
  8379. VertexAttachment: VertexAttachment
  8380. });
  8381. /* eslint-disable */
  8382. /**
  8383. * @public
  8384. */
  8385. class Attachment$1 {
  8386. constructor(name) {
  8387. if (name == null) throw new Error("name cannot be null.");
  8388. this.name = name;
  8389. }
  8390. }
  8391. /**
  8392. * @public
  8393. */
  8394. class VertexAttachment$1 extends Attachment$1 {
  8395. static __initStatic() {this.nextID = 0;}
  8396. __init() {this.id = (VertexAttachment$1.nextID++ & 65535) << 11;}
  8397. __init2() {this.worldVerticesLength = 0;}
  8398. constructor(name) {
  8399. super(name);VertexAttachment$1.prototype.__init.call(this);VertexAttachment$1.prototype.__init2.call(this); }
  8400. computeWorldVerticesOld(slot, worldVertices) {
  8401. this.computeWorldVertices(slot, 0, this.worldVerticesLength, worldVertices, 0, 2);
  8402. }
  8403. /** Transforms local vertices to world coordinates.
  8404. * @param start The index of the first local vertex value to transform. Each vertex has 2 values, x and y.
  8405. * @param count The number of world vertex values to output. Must be <= {@link #getWorldVerticesLength()} - start.
  8406. * @param worldVertices The output world vertices. Must have a length >= offset + count.
  8407. * @param offset The worldVertices index to begin writing values. */
  8408. computeWorldVertices(slot, start, count, worldVertices, offset, stride) {
  8409. count = offset + (count >> 1) * stride;
  8410. let skeleton = slot.bone.skeleton;
  8411. let deformArray = slot.attachmentVertices;
  8412. let vertices = this.vertices;
  8413. let bones = this.bones;
  8414. if (bones == null) {
  8415. if (deformArray.length > 0) vertices = deformArray;
  8416. let mat = slot.bone.matrix;
  8417. let x = mat.tx;
  8418. let y = mat.ty;
  8419. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  8420. for (let v = start, w = offset; w < count; v += 2, w += stride) {
  8421. let vx = vertices[v], vy = vertices[v + 1];
  8422. worldVertices[w] = vx * a + vy * b + x;
  8423. worldVertices[w + 1] = vx * c + vy * d + y;
  8424. }
  8425. return;
  8426. }
  8427. let v = 0, skip = 0;
  8428. for (let i = 0; i < start; i += 2) {
  8429. let n = bones[v];
  8430. v += n + 1;
  8431. skip += n;
  8432. }
  8433. let skeletonBones = skeleton.bones;
  8434. if (deformArray.length == 0) {
  8435. for (let w = offset, b = skip * 3; w < count; w += stride) {
  8436. let wx = 0, wy = 0;
  8437. let n = bones[v++];
  8438. n += v;
  8439. for (; v < n; v++, b += 3) {
  8440. let mat = skeletonBones[bones[v]].matrix;
  8441. let vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  8442. wx += (vx * mat.a + vy * mat.c + mat.tx) * weight;
  8443. wy += (vx * mat.b + vy * mat.d + mat.ty) * weight;
  8444. }
  8445. worldVertices[w] = wx;
  8446. worldVertices[w + 1] = wy;
  8447. }
  8448. } else {
  8449. let deform = deformArray;
  8450. for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  8451. let wx = 0, wy = 0;
  8452. let n = bones[v++];
  8453. n += v;
  8454. for (; v < n; v++, b += 3, f += 2) {
  8455. let mat = skeletonBones[bones[v]].matrix;
  8456. let vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1],
  8457. weight = vertices[b + 2];
  8458. wx += (vx * mat.a + vy * mat.c + mat.tx) * weight;
  8459. wy += (vx * mat.b + vy * mat.d + mat.ty) * weight;
  8460. }
  8461. worldVertices[w] = wx;
  8462. worldVertices[w + 1] = wy;
  8463. }
  8464. }
  8465. }
  8466. /** Returns true if a deform originally applied to the specified attachment should be applied to this attachment. */
  8467. applyDeform(sourceAttachment) {
  8468. return this == sourceAttachment;
  8469. }
  8470. } VertexAttachment$1.__initStatic();
  8471. /**
  8472. * @public
  8473. */
  8474. class BoundingBoxAttachment$1 extends VertexAttachment$1 {
  8475. __init() {this.type = exports.AttachmentType.BoundingBox;}
  8476. __init2() {this.color = new Color(1, 1, 1, 1);}
  8477. constructor(name) {
  8478. super(name);BoundingBoxAttachment$1.prototype.__init.call(this);BoundingBoxAttachment$1.prototype.__init2.call(this); }
  8479. }
  8480. /**
  8481. * @public
  8482. */
  8483. class ClippingAttachment$1 extends VertexAttachment$1 {
  8484. __init() {this.type = exports.AttachmentType.Clipping;}
  8485. // Nonessential.
  8486. __init2() {this.color = new Color(0.2275, 0.2275, 0.8078, 1);} // ce3a3aff
  8487. constructor(name) {
  8488. super(name);ClippingAttachment$1.prototype.__init.call(this);ClippingAttachment$1.prototype.__init2.call(this); }
  8489. }
  8490. /**
  8491. * @public
  8492. */
  8493. class MeshAttachment$1 extends VertexAttachment$1 {
  8494. __init() {this.type = exports.AttachmentType.Mesh;}
  8495. __init2() {this.color = new Color(1, 1, 1, 1);}
  8496. __init3() {this.inheritDeform = false;}
  8497. __init4() {this.tempColor = new Color(0, 0, 0, 0);}
  8498. constructor (name) {
  8499. super(name);MeshAttachment$1.prototype.__init.call(this);MeshAttachment$1.prototype.__init2.call(this);MeshAttachment$1.prototype.__init3.call(this);MeshAttachment$1.prototype.__init4.call(this); }
  8500. applyDeform (sourceAttachment) {
  8501. return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
  8502. }
  8503. getParentMesh () {
  8504. return this.parentMesh;
  8505. }
  8506. /** @param parentMesh May be null. */
  8507. setParentMesh (parentMesh) {
  8508. this.parentMesh = parentMesh;
  8509. if (parentMesh != null) {
  8510. this.bones = parentMesh.bones;
  8511. this.vertices = parentMesh.vertices;
  8512. this.worldVerticesLength = parentMesh.worldVerticesLength;
  8513. this.regionUVs = parentMesh.regionUVs;
  8514. this.triangles = parentMesh.triangles;
  8515. this.hullLength = parentMesh.hullLength;
  8516. this.worldVerticesLength = parentMesh.worldVerticesLength;
  8517. }
  8518. }
  8519. //computeWorldVerticesWith(slot, 0, this.worldVerticesLength, worldVertices, 0);
  8520. }
  8521. /**
  8522. * @public
  8523. */
  8524. class PathAttachment$1 extends VertexAttachment$1 {
  8525. __init() {this.type = exports.AttachmentType.Path;}
  8526. __init2() {this.closed = false;}
  8527. __init3() {this.constantSpeed = false;}
  8528. __init4() {this.color = new Color(1, 1, 1, 1);}
  8529. constructor(name) {
  8530. super(name);PathAttachment$1.prototype.__init.call(this);PathAttachment$1.prototype.__init2.call(this);PathAttachment$1.prototype.__init3.call(this);PathAttachment$1.prototype.__init4.call(this); }
  8531. }
  8532. /**
  8533. * @public
  8534. */
  8535. class PointAttachment$1 extends VertexAttachment$1 {
  8536. __init() {this.type = exports.AttachmentType.Point;}
  8537. __init2() {this.color = new Color(0.38, 0.94, 0, 1);}
  8538. constructor(name) {
  8539. super(name);PointAttachment$1.prototype.__init.call(this);PointAttachment$1.prototype.__init2.call(this); }
  8540. computeWorldPosition(bone, point) {
  8541. const mat = bone.matrix;
  8542. point.x = this.x * mat.a + this.y * mat.c + bone.worldX;
  8543. point.y = this.x * mat.b + this.y * mat.d + bone.worldY;
  8544. return point;
  8545. }
  8546. computeWorldRotation(bone) {
  8547. const mat = bone.matrix;
  8548. let cos = MathUtils.cosDeg(this.rotation), sin = MathUtils.sinDeg(this.rotation);
  8549. let x = cos * mat.a + sin * mat.c;
  8550. let y = cos * mat.b + sin * mat.d;
  8551. return Math.atan2(y, x) * MathUtils.radDeg;
  8552. }
  8553. }
  8554. /**
  8555. * @public
  8556. */
  8557. class RegionAttachment$1 extends Attachment$1 {
  8558. __init() {this.type = exports.AttachmentType.Region;}
  8559. static __initStatic() {this.OX1 = 0;}
  8560. static __initStatic2() {this.OY1 = 1;}
  8561. static __initStatic3() {this.OX2 = 2;}
  8562. static __initStatic4() {this.OY2 = 3;}
  8563. static __initStatic5() {this.OX3 = 4;}
  8564. static __initStatic6() {this.OY3 = 5;}
  8565. static __initStatic7() {this.OX4 = 6;}
  8566. static __initStatic8() {this.OY4 = 7;}
  8567. static __initStatic9() {this.X1 = 0;}
  8568. static __initStatic10() {this.Y1 = 1;}
  8569. static __initStatic11() {this.C1R = 2;}
  8570. static __initStatic12() {this.C1G = 3;}
  8571. static __initStatic13() {this.C1B = 4;}
  8572. static __initStatic14() {this.C1A = 5;}
  8573. static __initStatic15() {this.U1 = 6;}
  8574. static __initStatic16() {this.V1 = 7;}
  8575. static __initStatic17() {this.X2 = 8;}
  8576. static __initStatic18() {this.Y2 = 9;}
  8577. static __initStatic19() {this.C2R = 10;}
  8578. static __initStatic20() {this.C2G = 11;}
  8579. static __initStatic21() {this.C2B = 12;}
  8580. static __initStatic22() {this.C2A = 13;}
  8581. static __initStatic23() {this.U2 = 14;}
  8582. static __initStatic24() {this.V2 = 15;}
  8583. static __initStatic25() {this.X3 = 16;}
  8584. static __initStatic26() {this.Y3 = 17;}
  8585. static __initStatic27() {this.C3R = 18;}
  8586. static __initStatic28() {this.C3G = 19;}
  8587. static __initStatic29() {this.C3B = 20;}
  8588. static __initStatic30() {this.C3A = 21;}
  8589. static __initStatic31() {this.U3 = 22;}
  8590. static __initStatic32() {this.V3 = 23;}
  8591. static __initStatic33() {this.X4 = 24;}
  8592. static __initStatic34() {this.Y4 = 25;}
  8593. static __initStatic35() {this.C4R = 26;}
  8594. static __initStatic36() {this.C4G = 27;}
  8595. static __initStatic37() {this.C4B = 28;}
  8596. static __initStatic38() {this.C4A = 29;}
  8597. static __initStatic39() {this.U4 = 30;}
  8598. static __initStatic40() {this.V4 = 31;}
  8599. __init2() {this.x = 0;}
  8600. __init3() {this.y = 0;}
  8601. __init4() {this.scaleX = 1;}
  8602. __init5() {this.scaleY = 1;}
  8603. __init6() {this.rotation = 0;}
  8604. __init7() {this.width = 0;}
  8605. __init8() {this.height = 0;}
  8606. __init9() {this.color = new Color(1, 1, 1, 1);}
  8607. __init10() {this.offset = Utils.newFloatArray(8);}
  8608. __init11() {this.uvs = Utils.newFloatArray(8);}
  8609. __init12() {this.tempColor = new Color(1, 1, 1, 1);}
  8610. constructor(name) {
  8611. super(name);RegionAttachment$1.prototype.__init.call(this);RegionAttachment$1.prototype.__init2.call(this);RegionAttachment$1.prototype.__init3.call(this);RegionAttachment$1.prototype.__init4.call(this);RegionAttachment$1.prototype.__init5.call(this);RegionAttachment$1.prototype.__init6.call(this);RegionAttachment$1.prototype.__init7.call(this);RegionAttachment$1.prototype.__init8.call(this);RegionAttachment$1.prototype.__init9.call(this);RegionAttachment$1.prototype.__init10.call(this);RegionAttachment$1.prototype.__init11.call(this);RegionAttachment$1.prototype.__init12.call(this); }
  8612. updateOffset() {
  8613. let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  8614. let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  8615. let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  8616. let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  8617. let localX2 = localX + this.region.width * regionScaleX;
  8618. let localY2 = localY + this.region.height * regionScaleY;
  8619. let radians = this.rotation * Math.PI / 180;
  8620. let cos = Math.cos(radians);
  8621. let sin = Math.sin(radians);
  8622. let localXCos = localX * cos + this.x;
  8623. let localXSin = localX * sin;
  8624. let localYCos = localY * cos + this.y;
  8625. let localYSin = localY * sin;
  8626. let localX2Cos = localX2 * cos + this.x;
  8627. let localX2Sin = localX2 * sin;
  8628. let localY2Cos = localY2 * cos + this.y;
  8629. let localY2Sin = localY2 * sin;
  8630. let offset = this.offset;
  8631. offset[RegionAttachment$1.OX1] = localXCos - localYSin;
  8632. offset[RegionAttachment$1.OY1] = localYCos + localXSin;
  8633. offset[RegionAttachment$1.OX2] = localXCos - localY2Sin;
  8634. offset[RegionAttachment$1.OY2] = localY2Cos + localXSin;
  8635. offset[RegionAttachment$1.OX3] = localX2Cos - localY2Sin;
  8636. offset[RegionAttachment$1.OY3] = localY2Cos + localX2Sin;
  8637. offset[RegionAttachment$1.OX4] = localX2Cos - localYSin;
  8638. offset[RegionAttachment$1.OY4] = localYCos + localX2Sin;
  8639. }
  8640. setRegion(region) {
  8641. this.region = region;
  8642. let uvs = this.uvs;
  8643. if (region.rotate) {
  8644. uvs[2] = region.u;
  8645. uvs[3] = region.v2;
  8646. uvs[4] = region.u;
  8647. uvs[5] = region.v;
  8648. uvs[6] = region.u2;
  8649. uvs[7] = region.v;
  8650. uvs[0] = region.u2;
  8651. uvs[1] = region.v2;
  8652. } else {
  8653. uvs[0] = region.u;
  8654. uvs[1] = region.v2;
  8655. uvs[2] = region.u;
  8656. uvs[3] = region.v;
  8657. uvs[4] = region.u2;
  8658. uvs[5] = region.v;
  8659. uvs[6] = region.u2;
  8660. uvs[7] = region.v2;
  8661. }
  8662. }
  8663. computeWorldVertices(bone, worldVertices, offset, stride) {
  8664. let vertexOffset = this.offset;
  8665. let mat = bone.matrix;
  8666. let x = mat.tx, y = mat.ty;
  8667. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  8668. let offsetX = 0, offsetY = 0;
  8669. offsetX = vertexOffset[RegionAttachment$1.OX1];
  8670. offsetY = vertexOffset[RegionAttachment$1.OY1];
  8671. worldVertices[offset] = offsetX * a + offsetY * b + x; // br
  8672. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8673. offset += stride;
  8674. offsetX = vertexOffset[RegionAttachment$1.OX2];
  8675. offsetY = vertexOffset[RegionAttachment$1.OY2];
  8676. worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
  8677. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8678. offset += stride;
  8679. offsetX = vertexOffset[RegionAttachment$1.OX3];
  8680. offsetY = vertexOffset[RegionAttachment$1.OY3];
  8681. worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
  8682. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8683. offset += stride;
  8684. offsetX = vertexOffset[RegionAttachment$1.OX4];
  8685. offsetY = vertexOffset[RegionAttachment$1.OY4];
  8686. worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
  8687. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8688. }
  8689. } RegionAttachment$1.__initStatic(); RegionAttachment$1.__initStatic2(); RegionAttachment$1.__initStatic3(); RegionAttachment$1.__initStatic4(); RegionAttachment$1.__initStatic5(); RegionAttachment$1.__initStatic6(); RegionAttachment$1.__initStatic7(); RegionAttachment$1.__initStatic8(); RegionAttachment$1.__initStatic9(); RegionAttachment$1.__initStatic10(); RegionAttachment$1.__initStatic11(); RegionAttachment$1.__initStatic12(); RegionAttachment$1.__initStatic13(); RegionAttachment$1.__initStatic14(); RegionAttachment$1.__initStatic15(); RegionAttachment$1.__initStatic16(); RegionAttachment$1.__initStatic17(); RegionAttachment$1.__initStatic18(); RegionAttachment$1.__initStatic19(); RegionAttachment$1.__initStatic20(); RegionAttachment$1.__initStatic21(); RegionAttachment$1.__initStatic22(); RegionAttachment$1.__initStatic23(); RegionAttachment$1.__initStatic24(); RegionAttachment$1.__initStatic25(); RegionAttachment$1.__initStatic26(); RegionAttachment$1.__initStatic27(); RegionAttachment$1.__initStatic28(); RegionAttachment$1.__initStatic29(); RegionAttachment$1.__initStatic30(); RegionAttachment$1.__initStatic31(); RegionAttachment$1.__initStatic32(); RegionAttachment$1.__initStatic33(); RegionAttachment$1.__initStatic34(); RegionAttachment$1.__initStatic35(); RegionAttachment$1.__initStatic36(); RegionAttachment$1.__initStatic37(); RegionAttachment$1.__initStatic38(); RegionAttachment$1.__initStatic39(); RegionAttachment$1.__initStatic40();
  8690. /**
  8691. * @public
  8692. */
  8693. class JitterEffect$1 {
  8694. __init() {this.jitterX = 0;}
  8695. __init2() {this.jitterY = 0;}
  8696. constructor (jitterX, jitterY) {JitterEffect$1.prototype.__init.call(this);JitterEffect$1.prototype.__init2.call(this);
  8697. this.jitterX = jitterX;
  8698. this.jitterY = jitterY;
  8699. }
  8700. begin(skeleton) {
  8701. }
  8702. transform(position, uv, light, dark) {
  8703. position.x += MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  8704. position.y += MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  8705. }
  8706. end() {
  8707. }
  8708. }
  8709. /**
  8710. * @public
  8711. */
  8712. class SwirlEffect$1 {
  8713. static __initStatic() {this.interpolation = new PowOut(2);}
  8714. __init() {this.centerX = 0;}
  8715. __init2() {this.centerY = 0;}
  8716. __init3() {this.radius = 0;}
  8717. __init4() {this.angle = 0;}
  8718. __init5() {this.worldX = 0;}
  8719. __init6() {this.worldY = 0;}
  8720. constructor (radius) {SwirlEffect$1.prototype.__init.call(this);SwirlEffect$1.prototype.__init2.call(this);SwirlEffect$1.prototype.__init3.call(this);SwirlEffect$1.prototype.__init4.call(this);SwirlEffect$1.prototype.__init5.call(this);SwirlEffect$1.prototype.__init6.call(this);
  8721. this.radius = radius;
  8722. }
  8723. begin(skeleton) {
  8724. this.worldX = skeleton.x + this.centerX;
  8725. this.worldY = skeleton.y + this.centerY;
  8726. }
  8727. transform(position, uv, light, dark) {
  8728. let radAngle = this.angle * MathUtils.degreesToRadians;
  8729. let x = position.x - this.worldX;
  8730. let y = position.y - this.worldY;
  8731. let dist = Math.sqrt(x * x + y * y);
  8732. if (dist < this.radius) {
  8733. let theta = SwirlEffect$1.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  8734. let cos = Math.cos(theta);
  8735. let sin = Math.sin(theta);
  8736. position.x = cos * x - sin * y + this.worldX;
  8737. position.y = sin * x + cos * y + this.worldY;
  8738. }
  8739. }
  8740. end() {
  8741. }
  8742. } SwirlEffect$1.__initStatic();
  8743. /**
  8744. * @public
  8745. */
  8746. class Animation$1 {
  8747. constructor (name, timelines, duration) {
  8748. if (name == null) throw new Error("name cannot be null.");
  8749. if (timelines == null) throw new Error("timelines cannot be null.");
  8750. this.name = name;
  8751. this.timelines = timelines;
  8752. this.duration = duration;
  8753. }
  8754. apply (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
  8755. if (skeleton == null) throw new Error("skeleton cannot be null.");
  8756. if (loop && this.duration != 0) {
  8757. time %= this.duration;
  8758. if (lastTime > 0) lastTime %= this.duration;
  8759. }
  8760. let timelines = this.timelines;
  8761. for (let i = 0, n = timelines.length; i < n; i++)
  8762. timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
  8763. }
  8764. static binarySearch (values, target, step = 1) {
  8765. let low = 0;
  8766. let high = values.length / step - 2;
  8767. if (high == 0) return step;
  8768. let current = high >>> 1;
  8769. while (true) {
  8770. if (values[(current + 1) * step] <= target)
  8771. low = current + 1;
  8772. else
  8773. high = current;
  8774. if (low == high) return (low + 1) * step;
  8775. current = (low + high) >>> 1;
  8776. }
  8777. }
  8778. static linearSearch (values, target, step) {
  8779. for (let i = 0, last = values.length - step; i <= last; i += step)
  8780. if (values[i] > target) return i;
  8781. return -1;
  8782. }
  8783. }
  8784. /**
  8785. * @public
  8786. */
  8787. /**
  8788. * @public
  8789. */
  8790. var MixBlend$1; (function (MixBlend) {
  8791. const setup = 0; MixBlend[MixBlend["setup"] = setup] = "setup";
  8792. const first = setup + 1; MixBlend[MixBlend["first"] = first] = "first";
  8793. const replace = first + 1; MixBlend[MixBlend["replace"] = replace] = "replace";
  8794. const add = replace + 1; MixBlend[MixBlend["add"] = add] = "add";
  8795. })(MixBlend$1 || (MixBlend$1 = {}));
  8796. /**
  8797. * @public
  8798. */
  8799. var MixDirection$1; (function (MixDirection) {
  8800. MixDirection[MixDirection["in"] = 0] = "in"; const out = (0) + 1; MixDirection[MixDirection["out"] = out] = "out";
  8801. })(MixDirection$1 || (MixDirection$1 = {}));
  8802. /**
  8803. * @public
  8804. */
  8805. var TimelineType$1; (function (TimelineType) {
  8806. const rotate = 0; TimelineType[TimelineType["rotate"] = rotate] = "rotate"; const translate = rotate + 1; TimelineType[TimelineType["translate"] = translate] = "translate"; const scale = translate + 1; TimelineType[TimelineType["scale"] = scale] = "scale"; const shear = scale + 1; TimelineType[TimelineType["shear"] = shear] = "shear";
  8807. const attachment = shear + 1; TimelineType[TimelineType["attachment"] = attachment] = "attachment"; const color = attachment + 1; TimelineType[TimelineType["color"] = color] = "color"; const deform = color + 1; TimelineType[TimelineType["deform"] = deform] = "deform";
  8808. const event = deform + 1; TimelineType[TimelineType["event"] = event] = "event"; const drawOrder = event + 1; TimelineType[TimelineType["drawOrder"] = drawOrder] = "drawOrder";
  8809. const ikConstraint = drawOrder + 1; TimelineType[TimelineType["ikConstraint"] = ikConstraint] = "ikConstraint"; const transformConstraint = ikConstraint + 1; TimelineType[TimelineType["transformConstraint"] = transformConstraint] = "transformConstraint";
  8810. const pathConstraintPosition = transformConstraint + 1; TimelineType[TimelineType["pathConstraintPosition"] = pathConstraintPosition] = "pathConstraintPosition"; const pathConstraintSpacing = pathConstraintPosition + 1; TimelineType[TimelineType["pathConstraintSpacing"] = pathConstraintSpacing] = "pathConstraintSpacing"; const pathConstraintMix = pathConstraintSpacing + 1; TimelineType[TimelineType["pathConstraintMix"] = pathConstraintMix] = "pathConstraintMix";
  8811. const twoColor = pathConstraintMix + 1; TimelineType[TimelineType["twoColor"] = twoColor] = "twoColor";
  8812. })(TimelineType$1 || (TimelineType$1 = {}));
  8813. /**
  8814. * @public
  8815. */
  8816. class CurveTimeline$1 {
  8817. static __initStatic() {this.LINEAR = 0;} static __initStatic2() {this.STEPPED = 1;} static __initStatic3() {this.BEZIER = 2;}
  8818. static __initStatic4() {this.BEZIER_SIZE = 10 * 2 - 1;}
  8819. // type, x, y, ...
  8820. constructor (frameCount) {
  8821. if (frameCount <= 0) throw new Error("frameCount must be > 0: " + frameCount);
  8822. this.curves = Utils.newFloatArray((frameCount - 1) * CurveTimeline$1.BEZIER_SIZE);
  8823. }
  8824. getFrameCount () {
  8825. return this.curves.length / CurveTimeline$1.BEZIER_SIZE + 1;
  8826. }
  8827. setLinear (frameIndex) {
  8828. this.curves[frameIndex * CurveTimeline$1.BEZIER_SIZE] = CurveTimeline$1.LINEAR;
  8829. }
  8830. setStepped (frameIndex) {
  8831. this.curves[frameIndex * CurveTimeline$1.BEZIER_SIZE] = CurveTimeline$1.STEPPED;
  8832. }
  8833. getCurveType (frameIndex) {
  8834. let index = frameIndex * CurveTimeline$1.BEZIER_SIZE;
  8835. if (index == this.curves.length) return CurveTimeline$1.LINEAR;
  8836. let type = this.curves[index];
  8837. if (type == CurveTimeline$1.LINEAR) return CurveTimeline$1.LINEAR;
  8838. if (type == CurveTimeline$1.STEPPED) return CurveTimeline$1.STEPPED;
  8839. return CurveTimeline$1.BEZIER;
  8840. }
  8841. /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
  8842. * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
  8843. * the difference between the keyframe's values. */
  8844. setCurve (frameIndex, cx1, cy1, cx2, cy2) {
  8845. let tmpx = (-cx1 * 2 + cx2) * 0.03, tmpy = (-cy1 * 2 + cy2) * 0.03;
  8846. let dddfx = ((cx1 - cx2) * 3 + 1) * 0.006, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006;
  8847. let ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
  8848. let dfx = cx1 * 0.3 + tmpx + dddfx * 0.16666667, dfy = cy1 * 0.3 + tmpy + dddfy * 0.16666667;
  8849. let i = frameIndex * CurveTimeline$1.BEZIER_SIZE;
  8850. let curves = this.curves;
  8851. curves[i++] = CurveTimeline$1.BEZIER;
  8852. let x = dfx, y = dfy;
  8853. for (let n = i + CurveTimeline$1.BEZIER_SIZE - 1; i < n; i += 2) {
  8854. curves[i] = x;
  8855. curves[i + 1] = y;
  8856. dfx += ddfx;
  8857. dfy += ddfy;
  8858. ddfx += dddfx;
  8859. ddfy += dddfy;
  8860. x += dfx;
  8861. y += dfy;
  8862. }
  8863. }
  8864. getCurvePercent (frameIndex, percent) {
  8865. percent = MathUtils.clamp(percent, 0, 1);
  8866. let curves = this.curves;
  8867. let i = frameIndex * CurveTimeline$1.BEZIER_SIZE;
  8868. let type = curves[i];
  8869. if (type == CurveTimeline$1.LINEAR) return percent;
  8870. if (type == CurveTimeline$1.STEPPED) return 0;
  8871. i++;
  8872. let x = 0;
  8873. for (let start = i, n = i + CurveTimeline$1.BEZIER_SIZE - 1; i < n; i += 2) {
  8874. x = curves[i];
  8875. if (x >= percent) {
  8876. let prevX, prevY;
  8877. if (i == start) {
  8878. prevX = 0;
  8879. prevY = 0;
  8880. } else {
  8881. prevX = curves[i - 2];
  8882. prevY = curves[i - 1];
  8883. }
  8884. return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
  8885. }
  8886. }
  8887. let y = curves[i - 1];
  8888. return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
  8889. }
  8890. } CurveTimeline$1.__initStatic(); CurveTimeline$1.__initStatic2(); CurveTimeline$1.__initStatic3(); CurveTimeline$1.__initStatic4();
  8891. /**
  8892. * @public
  8893. */
  8894. class RotateTimeline$1 extends CurveTimeline$1 {
  8895. static __initStatic5() {this.ENTRIES = 2;}
  8896. static __initStatic6() {this.PREV_TIME = -2;} static __initStatic7() {this.PREV_ROTATION = -1;}
  8897. static __initStatic8() {this.ROTATION = 1;}
  8898. // time, degrees, ...
  8899. constructor (frameCount) {
  8900. super(frameCount);
  8901. this.frames = Utils.newFloatArray(frameCount << 1);
  8902. }
  8903. getPropertyId () {
  8904. return (TimelineType$1.rotate << 24) + this.boneIndex;
  8905. }
  8906. /** Sets the time and angle of the specified keyframe. */
  8907. setFrame (frameIndex, time, degrees) {
  8908. frameIndex <<= 1;
  8909. this.frames[frameIndex] = time;
  8910. this.frames[frameIndex + RotateTimeline$1.ROTATION] = degrees;
  8911. }
  8912. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  8913. let frames = this.frames;
  8914. let bone = skeleton.bones[this.boneIndex];
  8915. if (time < frames[0]) {
  8916. switch (blend) {
  8917. case MixBlend$1.setup:
  8918. bone.rotation = bone.data.rotation;
  8919. return;
  8920. case MixBlend$1.first:
  8921. let r = bone.data.rotation - bone.rotation;
  8922. bone.rotation += (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  8923. }
  8924. return;
  8925. }
  8926. if (time >= frames[frames.length - RotateTimeline$1.ENTRIES]) { // Time is after last frame.
  8927. let r = frames[frames.length + RotateTimeline$1.PREV_ROTATION];
  8928. switch (blend) {
  8929. case MixBlend$1.setup:
  8930. bone.rotation = bone.data.rotation + r * alpha;
  8931. break;
  8932. case MixBlend$1.first:
  8933. case MixBlend$1.replace:
  8934. r += bone.data.rotation - bone.rotation;
  8935. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360; // Wrap within -180 and 180.
  8936. case MixBlend$1.add:
  8937. bone.rotation += r * alpha;
  8938. }
  8939. return;
  8940. }
  8941. // Interpolate between the previous frame and the current frame.
  8942. let frame = Animation$1.binarySearch(frames, time, RotateTimeline$1.ENTRIES);
  8943. let prevRotation = frames[frame + RotateTimeline$1.PREV_ROTATION];
  8944. let frameTime = frames[frame];
  8945. let percent = this.getCurvePercent((frame >> 1) - 1,
  8946. 1 - (time - frameTime) / (frames[frame + RotateTimeline$1.PREV_TIME] - frameTime));
  8947. let r = frames[frame + RotateTimeline$1.ROTATION] - prevRotation;
  8948. r = prevRotation + (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * percent;
  8949. switch (blend) {
  8950. case MixBlend$1.setup:
  8951. bone.rotation = bone.data.rotation + (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  8952. break;
  8953. case MixBlend$1.first:
  8954. case MixBlend$1.replace:
  8955. r += bone.data.rotation - bone.rotation;
  8956. case MixBlend$1.add:
  8957. bone.rotation += (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  8958. }
  8959. }
  8960. } RotateTimeline$1.__initStatic5(); RotateTimeline$1.__initStatic6(); RotateTimeline$1.__initStatic7(); RotateTimeline$1.__initStatic8();
  8961. /**
  8962. * @public
  8963. */
  8964. class TranslateTimeline$1 extends CurveTimeline$1 {
  8965. static __initStatic9() {this.ENTRIES = 3;}
  8966. static __initStatic10() {this.PREV_TIME = -3;} static __initStatic11() {this.PREV_X = -2;} static __initStatic12() {this.PREV_Y = -1;}
  8967. static __initStatic13() {this.X = 1;} static __initStatic14() {this.Y = 2;}
  8968. // time, x, y, ...
  8969. constructor (frameCount) {
  8970. super(frameCount);
  8971. this.frames = Utils.newFloatArray(frameCount * TranslateTimeline$1.ENTRIES);
  8972. }
  8973. getPropertyId () {
  8974. return (TimelineType$1.translate << 24) + this.boneIndex;
  8975. }
  8976. /** Sets the time and value of the specified keyframe. */
  8977. setFrame (frameIndex, time, x, y) {
  8978. frameIndex *= TranslateTimeline$1.ENTRIES;
  8979. this.frames[frameIndex] = time;
  8980. this.frames[frameIndex + TranslateTimeline$1.X] = x;
  8981. this.frames[frameIndex + TranslateTimeline$1.Y] = y;
  8982. }
  8983. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  8984. let frames = this.frames;
  8985. let bone = skeleton.bones[this.boneIndex];
  8986. if (time < frames[0]) {
  8987. switch (blend) {
  8988. case MixBlend$1.setup:
  8989. bone.x = bone.data.x;
  8990. bone.y = bone.data.y;
  8991. return;
  8992. case MixBlend$1.first:
  8993. bone.x += (bone.data.x - bone.x) * alpha;
  8994. bone.y += (bone.data.y - bone.y) * alpha;
  8995. }
  8996. return;
  8997. }
  8998. let x = 0, y = 0;
  8999. if (time >= frames[frames.length - TranslateTimeline$1.ENTRIES]) { // Time is after last frame.
  9000. x = frames[frames.length + TranslateTimeline$1.PREV_X];
  9001. y = frames[frames.length + TranslateTimeline$1.PREV_Y];
  9002. } else {
  9003. // Interpolate between the previous frame and the current frame.
  9004. let frame = Animation$1.binarySearch(frames, time, TranslateTimeline$1.ENTRIES);
  9005. x = frames[frame + TranslateTimeline$1.PREV_X];
  9006. y = frames[frame + TranslateTimeline$1.PREV_Y];
  9007. let frameTime = frames[frame];
  9008. let percent = this.getCurvePercent(frame / TranslateTimeline$1.ENTRIES - 1,
  9009. 1 - (time - frameTime) / (frames[frame + TranslateTimeline$1.PREV_TIME] - frameTime));
  9010. x += (frames[frame + TranslateTimeline$1.X] - x) * percent;
  9011. y += (frames[frame + TranslateTimeline$1.Y] - y) * percent;
  9012. }
  9013. switch (blend) {
  9014. case MixBlend$1.setup:
  9015. bone.x = bone.data.x + x * alpha;
  9016. bone.y = bone.data.y + y * alpha;
  9017. break;
  9018. case MixBlend$1.first:
  9019. case MixBlend$1.replace:
  9020. bone.x += (bone.data.x + x - bone.x) * alpha;
  9021. bone.y += (bone.data.y + y - bone.y) * alpha;
  9022. break;
  9023. case MixBlend$1.add:
  9024. bone.x += x * alpha;
  9025. bone.y += y * alpha;
  9026. }
  9027. }
  9028. } TranslateTimeline$1.__initStatic9(); TranslateTimeline$1.__initStatic10(); TranslateTimeline$1.__initStatic11(); TranslateTimeline$1.__initStatic12(); TranslateTimeline$1.__initStatic13(); TranslateTimeline$1.__initStatic14();
  9029. /**
  9030. * @public
  9031. */
  9032. class ScaleTimeline$1 extends TranslateTimeline$1 {
  9033. constructor (frameCount) {
  9034. super(frameCount);
  9035. }
  9036. getPropertyId () {
  9037. return (TimelineType$1.scale << 24) + this.boneIndex;
  9038. }
  9039. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  9040. let frames = this.frames;
  9041. let bone = skeleton.bones[this.boneIndex];
  9042. if (time < frames[0]) {
  9043. switch (blend) {
  9044. case MixBlend$1.setup:
  9045. bone.scaleX = bone.data.scaleX;
  9046. bone.scaleY = bone.data.scaleY;
  9047. return;
  9048. case MixBlend$1.first:
  9049. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  9050. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  9051. }
  9052. return;
  9053. }
  9054. let x = 0, y = 0;
  9055. if (time >= frames[frames.length - ScaleTimeline$1.ENTRIES]) { // Time is after last frame.
  9056. x = frames[frames.length + ScaleTimeline$1.PREV_X] * bone.data.scaleX;
  9057. y = frames[frames.length + ScaleTimeline$1.PREV_Y] * bone.data.scaleY;
  9058. } else {
  9059. // Interpolate between the previous frame and the current frame.
  9060. let frame = Animation$1.binarySearch(frames, time, ScaleTimeline$1.ENTRIES);
  9061. x = frames[frame + ScaleTimeline$1.PREV_X];
  9062. y = frames[frame + ScaleTimeline$1.PREV_Y];
  9063. let frameTime = frames[frame];
  9064. let percent = this.getCurvePercent(frame / ScaleTimeline$1.ENTRIES - 1,
  9065. 1 - (time - frameTime) / (frames[frame + ScaleTimeline$1.PREV_TIME] - frameTime));
  9066. x = (x + (frames[frame + ScaleTimeline$1.X] - x) * percent) * bone.data.scaleX;
  9067. y = (y + (frames[frame + ScaleTimeline$1.Y] - y) * percent) * bone.data.scaleY;
  9068. }
  9069. if (alpha == 1) {
  9070. if (blend == MixBlend$1.add) {
  9071. bone.scaleX += x - bone.data.scaleX;
  9072. bone.scaleY += y - bone.data.scaleY;
  9073. } else {
  9074. bone.scaleX = x;
  9075. bone.scaleY = y;
  9076. }
  9077. } else {
  9078. let bx = 0, by = 0;
  9079. if (direction == MixDirection$1.out) {
  9080. switch (blend) {
  9081. case MixBlend$1.setup:
  9082. bx = bone.data.scaleX;
  9083. by = bone.data.scaleY;
  9084. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  9085. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  9086. break;
  9087. case MixBlend$1.first:
  9088. case MixBlend$1.replace:
  9089. bx = bone.scaleX;
  9090. by = bone.scaleY;
  9091. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  9092. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  9093. break;
  9094. case MixBlend$1.add:
  9095. bx = bone.scaleX;
  9096. by = bone.scaleY;
  9097. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  9098. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - bone.data.scaleY) * alpha;
  9099. }
  9100. } else {
  9101. switch (blend) {
  9102. case MixBlend$1.setup:
  9103. bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
  9104. by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
  9105. bone.scaleX = bx + (x - bx) * alpha;
  9106. bone.scaleY = by + (y - by) * alpha;
  9107. break;
  9108. case MixBlend$1.first:
  9109. case MixBlend$1.replace:
  9110. bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
  9111. by = Math.abs(bone.scaleY) * MathUtils.signum(y);
  9112. bone.scaleX = bx + (x - bx) * alpha;
  9113. bone.scaleY = by + (y - by) * alpha;
  9114. break;
  9115. case MixBlend$1.add:
  9116. bx = MathUtils.signum(x);
  9117. by = MathUtils.signum(y);
  9118. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  9119. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  9120. }
  9121. }
  9122. }
  9123. }
  9124. }
  9125. /**
  9126. * @public
  9127. */
  9128. class ShearTimeline$1 extends TranslateTimeline$1 {
  9129. constructor (frameCount) {
  9130. super(frameCount);
  9131. }
  9132. getPropertyId () {
  9133. return (TimelineType$1.shear << 24) + this.boneIndex;
  9134. }
  9135. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  9136. let frames = this.frames;
  9137. let bone = skeleton.bones[this.boneIndex];
  9138. if (time < frames[0]) {
  9139. switch (blend) {
  9140. case MixBlend$1.setup:
  9141. bone.shearX = bone.data.shearX;
  9142. bone.shearY = bone.data.shearY;
  9143. return;
  9144. case MixBlend$1.first:
  9145. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  9146. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  9147. }
  9148. return;
  9149. }
  9150. let x = 0, y = 0;
  9151. if (time >= frames[frames.length - ShearTimeline$1.ENTRIES]) { // Time is after last frame.
  9152. x = frames[frames.length + ShearTimeline$1.PREV_X];
  9153. y = frames[frames.length + ShearTimeline$1.PREV_Y];
  9154. } else {
  9155. // Interpolate between the previous frame and the current frame.
  9156. let frame = Animation$1.binarySearch(frames, time, ShearTimeline$1.ENTRIES);
  9157. x = frames[frame + ShearTimeline$1.PREV_X];
  9158. y = frames[frame + ShearTimeline$1.PREV_Y];
  9159. let frameTime = frames[frame];
  9160. let percent = this.getCurvePercent(frame / ShearTimeline$1.ENTRIES - 1,
  9161. 1 - (time - frameTime) / (frames[frame + ShearTimeline$1.PREV_TIME] - frameTime));
  9162. x = x + (frames[frame + ShearTimeline$1.X] - x) * percent;
  9163. y = y + (frames[frame + ShearTimeline$1.Y] - y) * percent;
  9164. }
  9165. switch (blend) {
  9166. case MixBlend$1.setup:
  9167. bone.shearX = bone.data.shearX + x * alpha;
  9168. bone.shearY = bone.data.shearY + y * alpha;
  9169. break;
  9170. case MixBlend$1.first:
  9171. case MixBlend$1.replace:
  9172. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  9173. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  9174. break;
  9175. case MixBlend$1.add:
  9176. bone.shearX += x * alpha;
  9177. bone.shearY += y * alpha;
  9178. }
  9179. }
  9180. }
  9181. /**
  9182. * @public
  9183. */
  9184. class ColorTimeline$1 extends CurveTimeline$1 {
  9185. static __initStatic15() {this.ENTRIES = 5;}
  9186. static __initStatic16() {this.PREV_TIME = -5;} static __initStatic17() {this.PREV_R = -4;} static __initStatic18() {this.PREV_G = -3;} static __initStatic19() {this.PREV_B = -2;} static __initStatic20() {this.PREV_A = -1;}
  9187. static __initStatic21() {this.R = 1;} static __initStatic22() {this.G = 2;} static __initStatic23() {this.B = 3;} static __initStatic24() {this.A = 4;}
  9188. // time, r, g, b, a, ...
  9189. constructor (frameCount) {
  9190. super(frameCount);
  9191. this.frames = Utils.newFloatArray(frameCount * ColorTimeline$1.ENTRIES);
  9192. }
  9193. getPropertyId () {
  9194. return (TimelineType$1.color << 24) + this.slotIndex;
  9195. }
  9196. /** Sets the time and value of the specified keyframe. */
  9197. setFrame (frameIndex, time, r, g, b, a) {
  9198. frameIndex *= ColorTimeline$1.ENTRIES;
  9199. this.frames[frameIndex] = time;
  9200. this.frames[frameIndex + ColorTimeline$1.R] = r;
  9201. this.frames[frameIndex + ColorTimeline$1.G] = g;
  9202. this.frames[frameIndex + ColorTimeline$1.B] = b;
  9203. this.frames[frameIndex + ColorTimeline$1.A] = a;
  9204. }
  9205. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  9206. let slot = skeleton.slots[this.slotIndex];
  9207. let frames = this.frames;
  9208. if (time < frames[0]) {
  9209. switch (blend) {
  9210. case MixBlend$1.setup:
  9211. slot.color.setFromColor(slot.data.color);
  9212. return;
  9213. case MixBlend$1.first:
  9214. let color = slot.color, setup = slot.data.color;
  9215. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
  9216. (setup.a - color.a) * alpha);
  9217. }
  9218. return;
  9219. }
  9220. let r = 0, g = 0, b = 0, a = 0;
  9221. if (time >= frames[frames.length - ColorTimeline$1.ENTRIES]) { // Time is after last frame.
  9222. let i = frames.length;
  9223. r = frames[i + ColorTimeline$1.PREV_R];
  9224. g = frames[i + ColorTimeline$1.PREV_G];
  9225. b = frames[i + ColorTimeline$1.PREV_B];
  9226. a = frames[i + ColorTimeline$1.PREV_A];
  9227. } else {
  9228. // Interpolate between the previous frame and the current frame.
  9229. let frame = Animation$1.binarySearch(frames, time, ColorTimeline$1.ENTRIES);
  9230. r = frames[frame + ColorTimeline$1.PREV_R];
  9231. g = frames[frame + ColorTimeline$1.PREV_G];
  9232. b = frames[frame + ColorTimeline$1.PREV_B];
  9233. a = frames[frame + ColorTimeline$1.PREV_A];
  9234. let frameTime = frames[frame];
  9235. let percent = this.getCurvePercent(frame / ColorTimeline$1.ENTRIES - 1,
  9236. 1 - (time - frameTime) / (frames[frame + ColorTimeline$1.PREV_TIME] - frameTime));
  9237. r += (frames[frame + ColorTimeline$1.R] - r) * percent;
  9238. g += (frames[frame + ColorTimeline$1.G] - g) * percent;
  9239. b += (frames[frame + ColorTimeline$1.B] - b) * percent;
  9240. a += (frames[frame + ColorTimeline$1.A] - a) * percent;
  9241. }
  9242. if (alpha == 1)
  9243. slot.color.set(r, g, b, a);
  9244. else {
  9245. let color = slot.color;
  9246. if (blend == MixBlend$1.setup) color.setFromColor(slot.data.color);
  9247. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  9248. }
  9249. }
  9250. } ColorTimeline$1.__initStatic15(); ColorTimeline$1.__initStatic16(); ColorTimeline$1.__initStatic17(); ColorTimeline$1.__initStatic18(); ColorTimeline$1.__initStatic19(); ColorTimeline$1.__initStatic20(); ColorTimeline$1.__initStatic21(); ColorTimeline$1.__initStatic22(); ColorTimeline$1.__initStatic23(); ColorTimeline$1.__initStatic24();
  9251. /**
  9252. * @public
  9253. */
  9254. class TwoColorTimeline$1 extends CurveTimeline$1 {
  9255. static __initStatic25() {this.ENTRIES = 8;}
  9256. static __initStatic26() {this.PREV_TIME = -8;} static __initStatic27() {this.PREV_R = -7;} static __initStatic28() {this.PREV_G = -6;} static __initStatic29() {this.PREV_B = -5;} static __initStatic30() {this.PREV_A = -4;}
  9257. static __initStatic31() {this.PREV_R2 = -3;} static __initStatic32() {this.PREV_G2 = -2;} static __initStatic33() {this.PREV_B2 = -1;}
  9258. static __initStatic34() {this.R = 1;} static __initStatic35() {this.G = 2;} static __initStatic36() {this.B = 3;} static __initStatic37() {this.A = 4;} static __initStatic38() {this.R2 = 5;} static __initStatic39() {this.G2 = 6;} static __initStatic40() {this.B2 = 7;}
  9259. // time, r, g, b, a, r2, g2, b2, ...
  9260. constructor (frameCount) {
  9261. super(frameCount);
  9262. this.frames = Utils.newFloatArray(frameCount * TwoColorTimeline$1.ENTRIES);
  9263. }
  9264. getPropertyId () {
  9265. return (TimelineType$1.twoColor << 24) + this.slotIndex;
  9266. }
  9267. /** Sets the time and value of the specified keyframe. */
  9268. setFrame (frameIndex, time, r, g, b, a, r2, g2, b2) {
  9269. frameIndex *= TwoColorTimeline$1.ENTRIES;
  9270. this.frames[frameIndex] = time;
  9271. this.frames[frameIndex + TwoColorTimeline$1.R] = r;
  9272. this.frames[frameIndex + TwoColorTimeline$1.G] = g;
  9273. this.frames[frameIndex + TwoColorTimeline$1.B] = b;
  9274. this.frames[frameIndex + TwoColorTimeline$1.A] = a;
  9275. this.frames[frameIndex + TwoColorTimeline$1.R2] = r2;
  9276. this.frames[frameIndex + TwoColorTimeline$1.G2] = g2;
  9277. this.frames[frameIndex + TwoColorTimeline$1.B2] = b2;
  9278. }
  9279. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  9280. let slot = skeleton.slots[this.slotIndex];
  9281. let frames = this.frames;
  9282. if (time < frames[0]) {
  9283. switch (blend) {
  9284. case MixBlend$1.setup:
  9285. slot.color.setFromColor(slot.data.color);
  9286. slot.darkColor.setFromColor(slot.data.darkColor);
  9287. return;
  9288. case MixBlend$1.first:
  9289. let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  9290. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha,
  9291. (setupLight.a - light.a) * alpha);
  9292. dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
  9293. }
  9294. return;
  9295. }
  9296. let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  9297. if (time >= frames[frames.length - TwoColorTimeline$1.ENTRIES]) { // Time is after last frame.
  9298. let i = frames.length;
  9299. r = frames[i + TwoColorTimeline$1.PREV_R];
  9300. g = frames[i + TwoColorTimeline$1.PREV_G];
  9301. b = frames[i + TwoColorTimeline$1.PREV_B];
  9302. a = frames[i + TwoColorTimeline$1.PREV_A];
  9303. r2 = frames[i + TwoColorTimeline$1.PREV_R2];
  9304. g2 = frames[i + TwoColorTimeline$1.PREV_G2];
  9305. b2 = frames[i + TwoColorTimeline$1.PREV_B2];
  9306. } else {
  9307. // Interpolate between the previous frame and the current frame.
  9308. let frame = Animation$1.binarySearch(frames, time, TwoColorTimeline$1.ENTRIES);
  9309. r = frames[frame + TwoColorTimeline$1.PREV_R];
  9310. g = frames[frame + TwoColorTimeline$1.PREV_G];
  9311. b = frames[frame + TwoColorTimeline$1.PREV_B];
  9312. a = frames[frame + TwoColorTimeline$1.PREV_A];
  9313. r2 = frames[frame + TwoColorTimeline$1.PREV_R2];
  9314. g2 = frames[frame + TwoColorTimeline$1.PREV_G2];
  9315. b2 = frames[frame + TwoColorTimeline$1.PREV_B2];
  9316. let frameTime = frames[frame];
  9317. let percent = this.getCurvePercent(frame / TwoColorTimeline$1.ENTRIES - 1,
  9318. 1 - (time - frameTime) / (frames[frame + TwoColorTimeline$1.PREV_TIME] - frameTime));
  9319. r += (frames[frame + TwoColorTimeline$1.R] - r) * percent;
  9320. g += (frames[frame + TwoColorTimeline$1.G] - g) * percent;
  9321. b += (frames[frame + TwoColorTimeline$1.B] - b) * percent;
  9322. a += (frames[frame + TwoColorTimeline$1.A] - a) * percent;
  9323. r2 += (frames[frame + TwoColorTimeline$1.R2] - r2) * percent;
  9324. g2 += (frames[frame + TwoColorTimeline$1.G2] - g2) * percent;
  9325. b2 += (frames[frame + TwoColorTimeline$1.B2] - b2) * percent;
  9326. }
  9327. if (alpha == 1) {
  9328. slot.color.set(r, g, b, a);
  9329. slot.darkColor.set(r2, g2, b2, 1);
  9330. } else {
  9331. let light = slot.color, dark = slot.darkColor;
  9332. if (blend == MixBlend$1.setup) {
  9333. light.setFromColor(slot.data.color);
  9334. dark.setFromColor(slot.data.darkColor);
  9335. }
  9336. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  9337. dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
  9338. }
  9339. }
  9340. } TwoColorTimeline$1.__initStatic25(); TwoColorTimeline$1.__initStatic26(); TwoColorTimeline$1.__initStatic27(); TwoColorTimeline$1.__initStatic28(); TwoColorTimeline$1.__initStatic29(); TwoColorTimeline$1.__initStatic30(); TwoColorTimeline$1.__initStatic31(); TwoColorTimeline$1.__initStatic32(); TwoColorTimeline$1.__initStatic33(); TwoColorTimeline$1.__initStatic34(); TwoColorTimeline$1.__initStatic35(); TwoColorTimeline$1.__initStatic36(); TwoColorTimeline$1.__initStatic37(); TwoColorTimeline$1.__initStatic38(); TwoColorTimeline$1.__initStatic39(); TwoColorTimeline$1.__initStatic40();
  9341. /**
  9342. * @public
  9343. */
  9344. class AttachmentTimeline$1 {
  9345. // time, ...
  9346. constructor (frameCount) {
  9347. this.frames = Utils.newFloatArray(frameCount);
  9348. this.attachmentNames = new Array(frameCount);
  9349. }
  9350. getPropertyId () {
  9351. return (TimelineType$1.attachment << 24) + this.slotIndex;
  9352. }
  9353. getFrameCount () {
  9354. return this.frames.length;
  9355. }
  9356. /** Sets the time and value of the specified keyframe. */
  9357. setFrame (frameIndex, time, attachmentName) {
  9358. this.frames[frameIndex] = time;
  9359. this.attachmentNames[frameIndex] = attachmentName;
  9360. }
  9361. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  9362. let slot = skeleton.slots[this.slotIndex];
  9363. if (direction == MixDirection$1.out && blend == MixBlend$1.setup) {
  9364. let attachmentName = slot.data.attachmentName;
  9365. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  9366. return;
  9367. }
  9368. let frames = this.frames;
  9369. if (time < frames[0]) {
  9370. if (blend == MixBlend$1.setup || blend == MixBlend$1.first) {
  9371. let attachmentName = slot.data.attachmentName;
  9372. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  9373. }
  9374. return;
  9375. }
  9376. let frameIndex = 0;
  9377. if (time >= frames[frames.length - 1]) // Time is after last frame.
  9378. frameIndex = frames.length - 1;
  9379. else
  9380. frameIndex = Animation$1.binarySearch(frames, time, 1) - 1;
  9381. let attachmentName = this.attachmentNames[frameIndex];
  9382. skeleton.slots[this.slotIndex]
  9383. .setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  9384. }
  9385. }
  9386. let zeros$1 = null;
  9387. /**
  9388. * @public
  9389. */
  9390. class DeformTimeline$1 extends CurveTimeline$1 {
  9391. // time, ...
  9392. constructor (frameCount) {
  9393. super(frameCount);
  9394. this.frames = Utils.newFloatArray(frameCount);
  9395. this.frameVertices = new Array(frameCount);
  9396. if (zeros$1 == null) zeros$1 = Utils.newFloatArray(64);
  9397. }
  9398. getPropertyId () {
  9399. return (TimelineType$1.deform << 27) + + this.attachment.id + this.slotIndex;
  9400. }
  9401. /** Sets the time of the specified keyframe. */
  9402. setFrame (frameIndex, time, vertices) {
  9403. this.frames[frameIndex] = time;
  9404. this.frameVertices[frameIndex] = vertices;
  9405. }
  9406. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9407. let slot = skeleton.slots[this.slotIndex];
  9408. let slotAttachment = slot.getAttachment();
  9409. if (!(slotAttachment instanceof VertexAttachment$1) || !(slotAttachment).applyDeform(this.attachment)) return;
  9410. let verticesArray = slot.attachmentVertices;
  9411. if (verticesArray.length == 0) blend = MixBlend$1.setup;
  9412. let frameVertices = this.frameVertices;
  9413. let vertexCount = frameVertices[0].length;
  9414. let frames = this.frames;
  9415. if (time < frames[0]) {
  9416. let vertexAttachment = slotAttachment;
  9417. switch (blend) {
  9418. case MixBlend$1.setup:
  9419. verticesArray.length = 0;
  9420. return;
  9421. case MixBlend$1.first:
  9422. if (alpha == 1) {
  9423. verticesArray.length = 0;
  9424. break;
  9425. }
  9426. let vertices = Utils.setArraySize(verticesArray, vertexCount);
  9427. if (vertexAttachment.bones == null) {
  9428. // Unweighted vertex positions.
  9429. let setupVertices = vertexAttachment.vertices;
  9430. for (let i = 0; i < vertexCount; i++)
  9431. vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
  9432. } else {
  9433. // Weighted deform offsets.
  9434. alpha = 1 - alpha;
  9435. for (let i = 0; i < vertexCount; i++)
  9436. vertices[i] *= alpha;
  9437. }
  9438. }
  9439. return;
  9440. }
  9441. let vertices = Utils.setArraySize(verticesArray, vertexCount);
  9442. if (time >= frames[frames.length - 1]) { // Time is after last frame.
  9443. let lastVertices = frameVertices[frames.length - 1];
  9444. if (alpha == 1) {
  9445. if (blend == MixBlend$1.add) {
  9446. let vertexAttachment = slotAttachment ;
  9447. if (vertexAttachment.bones == null) {
  9448. // Unweighted vertex positions, with alpha.
  9449. let setupVertices = vertexAttachment.vertices;
  9450. for (let i = 0; i < vertexCount; i++) {
  9451. vertices[i] += lastVertices[i] - setupVertices[i];
  9452. }
  9453. } else {
  9454. // Weighted deform offsets, with alpha.
  9455. for (let i = 0; i < vertexCount; i++)
  9456. vertices[i] += lastVertices[i];
  9457. }
  9458. } else {
  9459. Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
  9460. }
  9461. } else {
  9462. switch (blend) {
  9463. case MixBlend$1.setup: {
  9464. let vertexAttachment = slotAttachment ;
  9465. if (vertexAttachment.bones == null) {
  9466. // Unweighted vertex positions, with alpha.
  9467. let setupVertices = vertexAttachment.vertices;
  9468. for (let i = 0; i < vertexCount; i++) {
  9469. let setup = setupVertices[i];
  9470. vertices[i] = setup + (lastVertices[i] - setup) * alpha;
  9471. }
  9472. } else {
  9473. // Weighted deform offsets, with alpha.
  9474. for (let i = 0; i < vertexCount; i++)
  9475. vertices[i] = lastVertices[i] * alpha;
  9476. }
  9477. break;
  9478. }
  9479. case MixBlend$1.first:
  9480. case MixBlend$1.replace:
  9481. for (let i = 0; i < vertexCount; i++)
  9482. vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
  9483. case MixBlend$1.add:
  9484. let vertexAttachment = slotAttachment ;
  9485. if (vertexAttachment.bones == null) {
  9486. // Unweighted vertex positions, with alpha.
  9487. let setupVertices = vertexAttachment.vertices;
  9488. for (let i = 0; i < vertexCount; i++) {
  9489. vertices[i] += (lastVertices[i] - setupVertices[i]) * alpha;
  9490. }
  9491. } else {
  9492. // Weighted deform offsets, with alpha.
  9493. for (let i = 0; i < vertexCount; i++)
  9494. vertices[i] += lastVertices[i] * alpha;
  9495. }
  9496. }
  9497. }
  9498. return;
  9499. }
  9500. // Interpolate between the previous frame and the current frame.
  9501. let frame = Animation$1.binarySearch(frames, time);
  9502. let prevVertices = frameVertices[frame - 1];
  9503. let nextVertices = frameVertices[frame];
  9504. let frameTime = frames[frame];
  9505. let percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
  9506. if (alpha == 1) {
  9507. if (blend == MixBlend$1.add) {
  9508. let vertexAttachment = slotAttachment ;
  9509. if (vertexAttachment.bones == null) {
  9510. // Unweighted vertex positions, with alpha.
  9511. let setupVertices = vertexAttachment.vertices;
  9512. for (let i = 0; i < vertexCount; i++) {
  9513. let prev = prevVertices[i];
  9514. vertices[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
  9515. }
  9516. } else {
  9517. // Weighted deform offsets, with alpha.
  9518. for (let i = 0; i < vertexCount; i++) {
  9519. let prev = prevVertices[i];
  9520. vertices[i] += prev + (nextVertices[i] - prev) * percent;
  9521. }
  9522. }
  9523. } else {
  9524. for (let i = 0; i < vertexCount; i++) {
  9525. let prev = prevVertices[i];
  9526. vertices[i] = prev + (nextVertices[i] - prev) * percent;
  9527. }
  9528. }
  9529. } else {
  9530. switch (blend) {
  9531. case MixBlend$1.setup: {
  9532. let vertexAttachment = slotAttachment ;
  9533. if (vertexAttachment.bones == null) {
  9534. // Unweighted vertex positions, with alpha.
  9535. let setupVertices = vertexAttachment.vertices;
  9536. for (let i = 0; i < vertexCount; i++) {
  9537. let prev = prevVertices[i], setup = setupVertices[i];
  9538. vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
  9539. }
  9540. } else {
  9541. // Weighted deform offsets, with alpha.
  9542. for (let i = 0; i < vertexCount; i++) {
  9543. let prev = prevVertices[i];
  9544. vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
  9545. }
  9546. }
  9547. break;
  9548. }
  9549. case MixBlend$1.first:
  9550. case MixBlend$1.replace:
  9551. for (let i = 0; i < vertexCount; i++) {
  9552. let prev = prevVertices[i];
  9553. vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
  9554. }
  9555. break;
  9556. case MixBlend$1.add:
  9557. let vertexAttachment = slotAttachment ;
  9558. if (vertexAttachment.bones == null) {
  9559. // Unweighted vertex positions, with alpha.
  9560. let setupVertices = vertexAttachment.vertices;
  9561. for (let i = 0; i < vertexCount; i++) {
  9562. let prev = prevVertices[i];
  9563. vertices[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha;
  9564. }
  9565. } else {
  9566. // Weighted deform offsets, with alpha.
  9567. for (let i = 0; i < vertexCount; i++) {
  9568. let prev = prevVertices[i];
  9569. vertices[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
  9570. }
  9571. }
  9572. }
  9573. }
  9574. }
  9575. }
  9576. /**
  9577. * @public
  9578. */
  9579. class EventTimeline$1 {
  9580. // time, ...
  9581. constructor (frameCount) {
  9582. this.frames = Utils.newFloatArray(frameCount);
  9583. this.events = new Array(frameCount);
  9584. }
  9585. getPropertyId () {
  9586. return TimelineType$1.event << 24;
  9587. }
  9588. getFrameCount () {
  9589. return this.frames.length;
  9590. }
  9591. /** Sets the time of the specified keyframe. */
  9592. setFrame (frameIndex, event) {
  9593. this.frames[frameIndex] = event.time;
  9594. this.events[frameIndex] = event;
  9595. }
  9596. /** Fires events for frames > lastTime and <= time. */
  9597. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9598. if (firedEvents == null) return;
  9599. let frames = this.frames;
  9600. let frameCount = this.frames.length;
  9601. if (lastTime > time) { // Fire events after last time for looped animations.
  9602. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction);
  9603. lastTime = -1;
  9604. } else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
  9605. return;
  9606. if (time < frames[0]) return; // Time is before first frame.
  9607. let frame = 0;
  9608. if (lastTime < frames[0])
  9609. frame = 0;
  9610. else {
  9611. frame = Animation$1.binarySearch(frames, lastTime);
  9612. let frameTime = frames[frame];
  9613. while (frame > 0) { // Fire multiple events with the same frame.
  9614. if (frames[frame - 1] != frameTime) break;
  9615. frame--;
  9616. }
  9617. }
  9618. for (; frame < frameCount && time >= frames[frame]; frame++)
  9619. firedEvents.push(this.events[frame]);
  9620. }
  9621. }
  9622. /**
  9623. * @public
  9624. */
  9625. class DrawOrderTimeline$1 {
  9626. // time, ...
  9627. constructor (frameCount) {
  9628. this.frames = Utils.newFloatArray(frameCount);
  9629. this.drawOrders = new Array(frameCount);
  9630. }
  9631. getPropertyId () {
  9632. return TimelineType$1.drawOrder << 24;
  9633. }
  9634. getFrameCount () {
  9635. return this.frames.length;
  9636. }
  9637. /** Sets the time of the specified keyframe.
  9638. * @param drawOrder May be null to use bind pose draw order. */
  9639. setFrame (frameIndex, time, drawOrder) {
  9640. this.frames[frameIndex] = time;
  9641. this.drawOrders[frameIndex] = drawOrder;
  9642. }
  9643. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9644. let drawOrder = skeleton.drawOrder;
  9645. let slots = skeleton.slots;
  9646. if (direction == MixDirection$1.out && blend == MixBlend$1.setup) {
  9647. Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  9648. return;
  9649. }
  9650. let frames = this.frames;
  9651. if (time < frames[0]) {
  9652. if (blend == MixBlend$1.setup || blend == MixBlend$1.first) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  9653. return;
  9654. }
  9655. let frame = 0;
  9656. if (time >= frames[frames.length - 1]) // Time is after last frame.
  9657. frame = frames.length - 1;
  9658. else
  9659. frame = Animation$1.binarySearch(frames, time) - 1;
  9660. let drawOrderToSetupIndex = this.drawOrders[frame];
  9661. if (drawOrderToSetupIndex == null)
  9662. Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  9663. else {
  9664. for (let i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  9665. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  9666. }
  9667. }
  9668. }
  9669. /**
  9670. * @public
  9671. */
  9672. class IkConstraintTimeline$1 extends CurveTimeline$1 {
  9673. static __initStatic41() {this.ENTRIES = 5;}
  9674. static __initStatic42() {this.PREV_TIME = -5;} static __initStatic43() {this.PREV_MIX = -4;} static __initStatic44() {this.PREV_BEND_DIRECTION = -3;} static __initStatic45() {this.PREV_COMPRESS = -2;} static __initStatic46() {this.PREV_STRETCH = -1;}
  9675. static __initStatic47() {this.MIX = 1;} static __initStatic48() {this.BEND_DIRECTION = 2;} static __initStatic49() {this.COMPRESS = 3;} static __initStatic50() {this.STRETCH = 4;}
  9676. // time, mix, bendDirection, compress, stretch, ...
  9677. constructor (frameCount) {
  9678. super(frameCount);
  9679. this.frames = Utils.newFloatArray(frameCount * IkConstraintTimeline$1.ENTRIES);
  9680. }
  9681. getPropertyId () {
  9682. return (TimelineType$1.ikConstraint << 24) + this.ikConstraintIndex;
  9683. }
  9684. /** Sets the time, mix and bend direction of the specified keyframe. */
  9685. setFrame (frameIndex, time, mix, bendDirection, compress, stretch) {
  9686. frameIndex *= IkConstraintTimeline$1.ENTRIES;
  9687. this.frames[frameIndex] = time;
  9688. this.frames[frameIndex + IkConstraintTimeline$1.MIX] = mix;
  9689. this.frames[frameIndex + IkConstraintTimeline$1.BEND_DIRECTION] = bendDirection;
  9690. this.frames[frameIndex + IkConstraintTimeline$1.COMPRESS] = compress ? 1 : 0;
  9691. this.frames[frameIndex + IkConstraintTimeline$1.STRETCH] = stretch ? 1 : 0;
  9692. }
  9693. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9694. let frames = this.frames;
  9695. let constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  9696. if (time < frames[0]) {
  9697. switch (blend) {
  9698. case MixBlend$1.setup:
  9699. constraint.mix = constraint.data.mix;
  9700. constraint.bendDirection = constraint.data.bendDirection;
  9701. constraint.compress = constraint.data.compress;
  9702. constraint.stretch = constraint.data.stretch;
  9703. return;
  9704. case MixBlend$1.first:
  9705. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  9706. constraint.bendDirection = constraint.data.bendDirection;
  9707. constraint.compress = constraint.data.compress;
  9708. constraint.stretch = constraint.data.stretch;
  9709. }
  9710. return;
  9711. }
  9712. if (time >= frames[frames.length - IkConstraintTimeline$1.ENTRIES]) { // Time is after last frame.
  9713. if (blend == MixBlend$1.setup) {
  9714. constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline$1.PREV_MIX] - constraint.data.mix) * alpha;
  9715. if (direction == MixDirection$1.out) {
  9716. constraint.bendDirection = constraint.data.bendDirection;
  9717. constraint.compress = constraint.data.compress;
  9718. constraint.stretch = constraint.data.stretch;
  9719. } else {
  9720. constraint.bendDirection = frames[frames.length + IkConstraintTimeline$1.PREV_BEND_DIRECTION];
  9721. constraint.compress = frames[frames.length + IkConstraintTimeline$1.PREV_COMPRESS] != 0;
  9722. constraint.stretch = frames[frames.length + IkConstraintTimeline$1.PREV_STRETCH] != 0;
  9723. }
  9724. } else {
  9725. constraint.mix += (frames[frames.length + IkConstraintTimeline$1.PREV_MIX] - constraint.mix) * alpha;
  9726. if (direction == MixDirection$1.in) {
  9727. constraint.bendDirection = frames[frames.length + IkConstraintTimeline$1.PREV_BEND_DIRECTION];
  9728. constraint.compress = frames[frames.length + IkConstraintTimeline$1.PREV_COMPRESS] != 0;
  9729. constraint.stretch = frames[frames.length + IkConstraintTimeline$1.PREV_STRETCH] != 0;
  9730. }
  9731. }
  9732. return;
  9733. }
  9734. // Interpolate between the previous frame and the current frame.
  9735. let frame = Animation$1.binarySearch(frames, time, IkConstraintTimeline$1.ENTRIES);
  9736. let mix = frames[frame + IkConstraintTimeline$1.PREV_MIX];
  9737. let frameTime = frames[frame];
  9738. let percent = this.getCurvePercent(frame / IkConstraintTimeline$1.ENTRIES - 1,
  9739. 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline$1.PREV_TIME] - frameTime));
  9740. if (blend == MixBlend$1.setup) {
  9741. constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline$1.MIX] - mix) * percent - constraint.data.mix) * alpha;
  9742. if (direction == MixDirection$1.out) {
  9743. constraint.bendDirection = constraint.data.bendDirection;
  9744. constraint.compress = constraint.data.compress;
  9745. constraint.stretch = constraint.data.stretch;
  9746. } else {
  9747. constraint.bendDirection = frames[frame + IkConstraintTimeline$1.PREV_BEND_DIRECTION];
  9748. constraint.compress = frames[frame + IkConstraintTimeline$1.PREV_COMPRESS] != 0;
  9749. constraint.stretch = frames[frame + IkConstraintTimeline$1.PREV_STRETCH] != 0;
  9750. }
  9751. } else {
  9752. constraint.mix += (mix + (frames[frame + IkConstraintTimeline$1.MIX] - mix) * percent - constraint.mix) * alpha;
  9753. if (direction == MixDirection$1.in) {
  9754. constraint.bendDirection = frames[frame + IkConstraintTimeline$1.PREV_BEND_DIRECTION];
  9755. constraint.compress = frames[frame + IkConstraintTimeline$1.PREV_COMPRESS] != 0;
  9756. constraint.stretch = frames[frame + IkConstraintTimeline$1.PREV_STRETCH] != 0;
  9757. }
  9758. }
  9759. }
  9760. } IkConstraintTimeline$1.__initStatic41(); IkConstraintTimeline$1.__initStatic42(); IkConstraintTimeline$1.__initStatic43(); IkConstraintTimeline$1.__initStatic44(); IkConstraintTimeline$1.__initStatic45(); IkConstraintTimeline$1.__initStatic46(); IkConstraintTimeline$1.__initStatic47(); IkConstraintTimeline$1.__initStatic48(); IkConstraintTimeline$1.__initStatic49(); IkConstraintTimeline$1.__initStatic50();
  9761. /**
  9762. * @public
  9763. */
  9764. class TransformConstraintTimeline$1 extends CurveTimeline$1 {
  9765. static __initStatic51() {this.ENTRIES = 5;}
  9766. static __initStatic52() {this.PREV_TIME = -5;} static __initStatic53() {this.PREV_ROTATE = -4;} static __initStatic54() {this.PREV_TRANSLATE = -3;} static __initStatic55() {this.PREV_SCALE = -2;} static __initStatic56() {this.PREV_SHEAR = -1;}
  9767. static __initStatic57() {this.ROTATE = 1;} static __initStatic58() {this.TRANSLATE = 2;} static __initStatic59() {this.SCALE = 3;} static __initStatic60() {this.SHEAR = 4;}
  9768. // time, rotate mix, translate mix, scale mix, shear mix, ...
  9769. constructor (frameCount) {
  9770. super(frameCount);
  9771. this.frames = Utils.newFloatArray(frameCount * TransformConstraintTimeline$1.ENTRIES);
  9772. }
  9773. getPropertyId () {
  9774. return (TimelineType$1.transformConstraint << 24) + this.transformConstraintIndex;
  9775. }
  9776. /** Sets the time and mixes of the specified keyframe. */
  9777. setFrame (frameIndex, time, rotateMix, translateMix, scaleMix, shearMix) {
  9778. frameIndex *= TransformConstraintTimeline$1.ENTRIES;
  9779. this.frames[frameIndex] = time;
  9780. this.frames[frameIndex + TransformConstraintTimeline$1.ROTATE] = rotateMix;
  9781. this.frames[frameIndex + TransformConstraintTimeline$1.TRANSLATE] = translateMix;
  9782. this.frames[frameIndex + TransformConstraintTimeline$1.SCALE] = scaleMix;
  9783. this.frames[frameIndex + TransformConstraintTimeline$1.SHEAR] = shearMix;
  9784. }
  9785. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9786. let frames = this.frames;
  9787. let constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  9788. if (time < frames[0]) {
  9789. let data = constraint.data;
  9790. switch (blend) {
  9791. case MixBlend$1.setup:
  9792. constraint.rotateMix = data.rotateMix;
  9793. constraint.translateMix = data.translateMix;
  9794. constraint.scaleMix = data.scaleMix;
  9795. constraint.shearMix = data.shearMix;
  9796. return;
  9797. case MixBlend$1.first:
  9798. constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
  9799. constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
  9800. constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
  9801. constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
  9802. }
  9803. return;
  9804. }
  9805. let rotate = 0, translate = 0, scale = 0, shear = 0;
  9806. if (time >= frames[frames.length - TransformConstraintTimeline$1.ENTRIES]) { // Time is after last frame.
  9807. let i = frames.length;
  9808. rotate = frames[i + TransformConstraintTimeline$1.PREV_ROTATE];
  9809. translate = frames[i + TransformConstraintTimeline$1.PREV_TRANSLATE];
  9810. scale = frames[i + TransformConstraintTimeline$1.PREV_SCALE];
  9811. shear = frames[i + TransformConstraintTimeline$1.PREV_SHEAR];
  9812. } else {
  9813. // Interpolate between the previous frame and the current frame.
  9814. let frame = Animation$1.binarySearch(frames, time, TransformConstraintTimeline$1.ENTRIES);
  9815. rotate = frames[frame + TransformConstraintTimeline$1.PREV_ROTATE];
  9816. translate = frames[frame + TransformConstraintTimeline$1.PREV_TRANSLATE];
  9817. scale = frames[frame + TransformConstraintTimeline$1.PREV_SCALE];
  9818. shear = frames[frame + TransformConstraintTimeline$1.PREV_SHEAR];
  9819. let frameTime = frames[frame];
  9820. let percent = this.getCurvePercent(frame / TransformConstraintTimeline$1.ENTRIES - 1,
  9821. 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline$1.PREV_TIME] - frameTime));
  9822. rotate += (frames[frame + TransformConstraintTimeline$1.ROTATE] - rotate) * percent;
  9823. translate += (frames[frame + TransformConstraintTimeline$1.TRANSLATE] - translate) * percent;
  9824. scale += (frames[frame + TransformConstraintTimeline$1.SCALE] - scale) * percent;
  9825. shear += (frames[frame + TransformConstraintTimeline$1.SHEAR] - shear) * percent;
  9826. }
  9827. if (blend == MixBlend$1.setup) {
  9828. let data = constraint.data;
  9829. constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
  9830. constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
  9831. constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
  9832. constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
  9833. } else {
  9834. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  9835. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  9836. constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
  9837. constraint.shearMix += (shear - constraint.shearMix) * alpha;
  9838. }
  9839. }
  9840. } TransformConstraintTimeline$1.__initStatic51(); TransformConstraintTimeline$1.__initStatic52(); TransformConstraintTimeline$1.__initStatic53(); TransformConstraintTimeline$1.__initStatic54(); TransformConstraintTimeline$1.__initStatic55(); TransformConstraintTimeline$1.__initStatic56(); TransformConstraintTimeline$1.__initStatic57(); TransformConstraintTimeline$1.__initStatic58(); TransformConstraintTimeline$1.__initStatic59(); TransformConstraintTimeline$1.__initStatic60();
  9841. /**
  9842. * @public
  9843. */
  9844. class PathConstraintPositionTimeline$1 extends CurveTimeline$1 {
  9845. static __initStatic61() {this.ENTRIES = 2;}
  9846. static __initStatic62() {this.PREV_TIME = -2;} static __initStatic63() {this.PREV_VALUE = -1;}
  9847. static __initStatic64() {this.VALUE = 1;}
  9848. // time, position, ...
  9849. constructor (frameCount) {
  9850. super(frameCount);
  9851. this.frames = Utils.newFloatArray(frameCount * PathConstraintPositionTimeline$1.ENTRIES);
  9852. }
  9853. getPropertyId () {
  9854. return (TimelineType$1.pathConstraintPosition << 24) + this.pathConstraintIndex;
  9855. }
  9856. /** Sets the time and value of the specified keyframe. */
  9857. setFrame (frameIndex, time, value) {
  9858. frameIndex *= PathConstraintPositionTimeline$1.ENTRIES;
  9859. this.frames[frameIndex] = time;
  9860. this.frames[frameIndex + PathConstraintPositionTimeline$1.VALUE] = value;
  9861. }
  9862. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9863. let frames = this.frames;
  9864. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  9865. if (time < frames[0]) {
  9866. switch (blend) {
  9867. case MixBlend$1.setup:
  9868. constraint.position = constraint.data.position;
  9869. return;
  9870. case MixBlend$1.first:
  9871. constraint.position += (constraint.data.position - constraint.position) * alpha;
  9872. }
  9873. return;
  9874. }
  9875. let position = 0;
  9876. if (time >= frames[frames.length - PathConstraintPositionTimeline$1.ENTRIES]) // Time is after last frame.
  9877. position = frames[frames.length + PathConstraintPositionTimeline$1.PREV_VALUE];
  9878. else {
  9879. // Interpolate between the previous frame and the current frame.
  9880. let frame = Animation$1.binarySearch(frames, time, PathConstraintPositionTimeline$1.ENTRIES);
  9881. position = frames[frame + PathConstraintPositionTimeline$1.PREV_VALUE];
  9882. let frameTime = frames[frame];
  9883. let percent = this.getCurvePercent(frame / PathConstraintPositionTimeline$1.ENTRIES - 1,
  9884. 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline$1.PREV_TIME] - frameTime));
  9885. position += (frames[frame + PathConstraintPositionTimeline$1.VALUE] - position) * percent;
  9886. }
  9887. if (blend == MixBlend$1.setup)
  9888. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  9889. else
  9890. constraint.position += (position - constraint.position) * alpha;
  9891. }
  9892. } PathConstraintPositionTimeline$1.__initStatic61(); PathConstraintPositionTimeline$1.__initStatic62(); PathConstraintPositionTimeline$1.__initStatic63(); PathConstraintPositionTimeline$1.__initStatic64();
  9893. /**
  9894. * @public
  9895. */
  9896. class PathConstraintSpacingTimeline$1 extends PathConstraintPositionTimeline$1 {
  9897. constructor (frameCount) {
  9898. super(frameCount);
  9899. }
  9900. getPropertyId () {
  9901. return (TimelineType$1.pathConstraintSpacing << 24) + this.pathConstraintIndex;
  9902. }
  9903. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9904. let frames = this.frames;
  9905. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  9906. if (time < frames[0]) {
  9907. switch (blend) {
  9908. case MixBlend$1.setup:
  9909. constraint.spacing = constraint.data.spacing;
  9910. return;
  9911. case MixBlend$1.first:
  9912. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  9913. }
  9914. return;
  9915. }
  9916. let spacing = 0;
  9917. if (time >= frames[frames.length - PathConstraintSpacingTimeline$1.ENTRIES]) // Time is after last frame.
  9918. spacing = frames[frames.length + PathConstraintSpacingTimeline$1.PREV_VALUE];
  9919. else {
  9920. // Interpolate between the previous frame and the current frame.
  9921. let frame = Animation$1.binarySearch(frames, time, PathConstraintSpacingTimeline$1.ENTRIES);
  9922. spacing = frames[frame + PathConstraintSpacingTimeline$1.PREV_VALUE];
  9923. let frameTime = frames[frame];
  9924. let percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline$1.ENTRIES - 1,
  9925. 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline$1.PREV_TIME] - frameTime));
  9926. spacing += (frames[frame + PathConstraintSpacingTimeline$1.VALUE] - spacing) * percent;
  9927. }
  9928. if (blend == MixBlend$1.setup)
  9929. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  9930. else
  9931. constraint.spacing += (spacing - constraint.spacing) * alpha;
  9932. }
  9933. }
  9934. /**
  9935. * @public
  9936. */
  9937. class PathConstraintMixTimeline$1 extends CurveTimeline$1 {
  9938. static __initStatic65() {this.ENTRIES = 3;}
  9939. static __initStatic66() {this.PREV_TIME = -3;} static __initStatic67() {this.PREV_ROTATE = -2;} static __initStatic68() {this.PREV_TRANSLATE = -1;}
  9940. static __initStatic69() {this.ROTATE = 1;} static __initStatic70() {this.TRANSLATE = 2;}
  9941. // time, rotate mix, translate mix, ...
  9942. constructor (frameCount) {
  9943. super(frameCount);
  9944. this.frames = Utils.newFloatArray(frameCount * PathConstraintMixTimeline$1.ENTRIES);
  9945. }
  9946. getPropertyId () {
  9947. return (TimelineType$1.pathConstraintMix << 24) + this.pathConstraintIndex;
  9948. }
  9949. /** Sets the time and mixes of the specified keyframe. */
  9950. setFrame (frameIndex, time, rotateMix, translateMix) {
  9951. frameIndex *= PathConstraintMixTimeline$1.ENTRIES;
  9952. this.frames[frameIndex] = time;
  9953. this.frames[frameIndex + PathConstraintMixTimeline$1.ROTATE] = rotateMix;
  9954. this.frames[frameIndex + PathConstraintMixTimeline$1.TRANSLATE] = translateMix;
  9955. }
  9956. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  9957. let frames = this.frames;
  9958. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  9959. if (time < frames[0]) {
  9960. switch (blend) {
  9961. case MixBlend$1.setup:
  9962. constraint.rotateMix = constraint.data.rotateMix;
  9963. constraint.translateMix = constraint.data.translateMix;
  9964. return;
  9965. case MixBlend$1.first:
  9966. constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
  9967. constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
  9968. }
  9969. return;
  9970. }
  9971. let rotate = 0, translate = 0;
  9972. if (time >= frames[frames.length - PathConstraintMixTimeline$1.ENTRIES]) { // Time is after last frame.
  9973. rotate = frames[frames.length + PathConstraintMixTimeline$1.PREV_ROTATE];
  9974. translate = frames[frames.length + PathConstraintMixTimeline$1.PREV_TRANSLATE];
  9975. } else {
  9976. // Interpolate between the previous frame and the current frame.
  9977. let frame = Animation$1.binarySearch(frames, time, PathConstraintMixTimeline$1.ENTRIES);
  9978. rotate = frames[frame + PathConstraintMixTimeline$1.PREV_ROTATE];
  9979. translate = frames[frame + PathConstraintMixTimeline$1.PREV_TRANSLATE];
  9980. let frameTime = frames[frame];
  9981. let percent = this.getCurvePercent(frame / PathConstraintMixTimeline$1.ENTRIES - 1,
  9982. 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline$1.PREV_TIME] - frameTime));
  9983. rotate += (frames[frame + PathConstraintMixTimeline$1.ROTATE] - rotate) * percent;
  9984. translate += (frames[frame + PathConstraintMixTimeline$1.TRANSLATE] - translate) * percent;
  9985. }
  9986. if (blend == MixBlend$1.setup) {
  9987. constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
  9988. constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
  9989. } else {
  9990. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  9991. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  9992. }
  9993. }
  9994. } PathConstraintMixTimeline$1.__initStatic65(); PathConstraintMixTimeline$1.__initStatic66(); PathConstraintMixTimeline$1.__initStatic67(); PathConstraintMixTimeline$1.__initStatic68(); PathConstraintMixTimeline$1.__initStatic69(); PathConstraintMixTimeline$1.__initStatic70();
  9995. /**
  9996. * @public
  9997. */
  9998. class AnimationState$1 {
  9999. static __initStatic() {this.emptyAnimation = new Animation$1("<empty>", [], 0);}
  10000. static __initStatic2() {this.SUBSEQUENT = 0;}
  10001. static __initStatic3() {this.FIRST = 1;}
  10002. static __initStatic4() {this.HOLD = 2;}
  10003. static __initStatic5() {this.HOLD_MIX = 3;}
  10004. __init() {this.tracks = new Array();}
  10005. __init2() {this.events = new Array();}
  10006. __init3() {this.listeners = new Array();}
  10007. __init4() {this.queue = new EventQueue$1(this);}
  10008. __init5() {this.propertyIDs = new IntSet();}
  10009. __init6() {this.animationsChanged = false;}
  10010. __init7() {this.timeScale = 1;}
  10011. __init8() {this.trackEntryPool = new Pool(() => new TrackEntry$1());}
  10012. constructor (data) {AnimationState$1.prototype.__init.call(this);AnimationState$1.prototype.__init2.call(this);AnimationState$1.prototype.__init3.call(this);AnimationState$1.prototype.__init4.call(this);AnimationState$1.prototype.__init5.call(this);AnimationState$1.prototype.__init6.call(this);AnimationState$1.prototype.__init7.call(this);AnimationState$1.prototype.__init8.call(this);
  10013. this.data = data;
  10014. }
  10015. update (delta) {
  10016. delta *= this.timeScale;
  10017. let tracks = this.tracks;
  10018. for (let i = 0, n = tracks.length; i < n; i++) {
  10019. let current = tracks[i];
  10020. if (current == null) continue;
  10021. current.animationLast = current.nextAnimationLast;
  10022. current.trackLast = current.nextTrackLast;
  10023. let currentDelta = delta * current.timeScale;
  10024. if (current.delay > 0) {
  10025. current.delay -= currentDelta;
  10026. if (current.delay > 0) continue;
  10027. currentDelta = -current.delay;
  10028. current.delay = 0;
  10029. }
  10030. let next = current.next;
  10031. if (next != null) {
  10032. // When the next entry's delay is passed, change to the next entry, preserving leftover time.
  10033. let nextTime = current.trackLast - next.delay;
  10034. if (nextTime >= 0) {
  10035. next.delay = 0;
  10036. next.trackTime = current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale;
  10037. current.trackTime += currentDelta;
  10038. this.setCurrent(i, next, true);
  10039. while (next.mixingFrom != null) {
  10040. next.mixTime += delta;
  10041. next = next.mixingFrom;
  10042. }
  10043. continue;
  10044. }
  10045. } else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  10046. tracks[i] = null;
  10047. this.queue.end(current);
  10048. this.disposeNext(current);
  10049. continue;
  10050. }
  10051. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  10052. // End mixing from entries once all have completed.
  10053. let from = current.mixingFrom;
  10054. current.mixingFrom = null;
  10055. if (from != null) from.mixingTo = null;
  10056. while (from != null) {
  10057. this.queue.end(from);
  10058. from = from.mixingFrom;
  10059. }
  10060. }
  10061. current.trackTime += currentDelta;
  10062. }
  10063. this.queue.drain();
  10064. }
  10065. updateMixingFrom (to, delta) {
  10066. let from = to.mixingFrom;
  10067. if (from == null) return true;
  10068. let finished = this.updateMixingFrom(from, delta);
  10069. from.animationLast = from.nextAnimationLast;
  10070. from.trackLast = from.nextTrackLast;
  10071. // Require mixTime > 0 to ensure the mixing from entry was applied at least once.
  10072. if (to.mixTime > 0 && to.mixTime >= to.mixDuration) {
  10073. // Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
  10074. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  10075. to.mixingFrom = from.mixingFrom;
  10076. if (from.mixingFrom != null) from.mixingFrom.mixingTo = to;
  10077. to.interruptAlpha = from.interruptAlpha;
  10078. this.queue.end(from);
  10079. }
  10080. return finished;
  10081. }
  10082. from.trackTime += delta * from.timeScale;
  10083. to.mixTime += delta;
  10084. return false;
  10085. }
  10086. apply (skeleton) {
  10087. if (skeleton == null) throw new Error("skeleton cannot be null.");
  10088. if (this.animationsChanged) this._animationsChanged();
  10089. let events = this.events;
  10090. let tracks = this.tracks;
  10091. let applied = false;
  10092. for (let i = 0, n = tracks.length; i < n; i++) {
  10093. let current = tracks[i];
  10094. if (current == null || current.delay > 0) continue;
  10095. applied = true;
  10096. let blend = i == 0 ? MixBlend$1.first : current.mixBlend;
  10097. // Apply mixing from entries first.
  10098. let mix = current.alpha;
  10099. if (current.mixingFrom != null)
  10100. mix *= this.applyMixingFrom(current, skeleton, blend);
  10101. else if (current.trackTime >= current.trackEnd && current.next == null)
  10102. mix = 0;
  10103. // Apply current entry.
  10104. let animationLast = current.animationLast, animationTime = current.getAnimationTime();
  10105. let timelineCount = current.animation.timelines.length;
  10106. let timelines = current.animation.timelines;
  10107. if ((i == 0 && mix == 1) || blend == MixBlend$1.add) {
  10108. for (let ii = 0; ii < timelineCount; ii++) {
  10109. // Fixes issue #302 on IOS9 where mix, blend sometimes became undefined and caused assets
  10110. // to sometimes stop rendering when using color correction, as their RGBA values become NaN.
  10111. // (https://github.com/pixijs/pixi-spine/issues/302)
  10112. Utils.webkit602BugfixHelper(mix, blend);
  10113. timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection$1.in);
  10114. }
  10115. } else {
  10116. let timelineMode = current.timelineMode;
  10117. let firstFrame = current.timelinesRotation.length == 0;
  10118. if (firstFrame) Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  10119. let timelinesRotation = current.timelinesRotation;
  10120. for (let ii = 0; ii < timelineCount; ii++) {
  10121. let timeline = timelines[ii];
  10122. let timelineBlend = timelineMode[ii] == AnimationState$1.SUBSEQUENT ? blend : MixBlend$1.setup;
  10123. if (timeline instanceof RotateTimeline$1) {
  10124. this.applyRotateTimeline(timeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
  10125. } else {
  10126. // This fixes the WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  10127. Utils.webkit602BugfixHelper(mix, blend);
  10128. timeline.apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, MixDirection$1.in);
  10129. }
  10130. }
  10131. }
  10132. this.queueEvents(current, animationTime);
  10133. events.length = 0;
  10134. current.nextAnimationLast = animationTime;
  10135. current.nextTrackLast = current.trackTime;
  10136. }
  10137. this.queue.drain();
  10138. return applied;
  10139. }
  10140. applyMixingFrom (to, skeleton, blend) {
  10141. let from = to.mixingFrom;
  10142. if (from.mixingFrom != null) this.applyMixingFrom(from, skeleton, blend);
  10143. let mix = 0;
  10144. if (to.mixDuration == 0) { // Single frame mix to undo mixingFrom changes.
  10145. mix = 1;
  10146. if (blend == MixBlend$1.first) blend = MixBlend$1.setup;
  10147. } else {
  10148. mix = to.mixTime / to.mixDuration;
  10149. if (mix > 1) mix = 1;
  10150. if (blend != MixBlend$1.first) blend = from.mixBlend;
  10151. }
  10152. let events = mix < from.eventThreshold ? this.events : null;
  10153. let attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  10154. let animationLast = from.animationLast, animationTime = from.getAnimationTime();
  10155. let timelineCount = from.animation.timelines.length;
  10156. let timelines = from.animation.timelines;
  10157. let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
  10158. if (blend == MixBlend$1.add) {
  10159. for (let i = 0; i < timelineCount; i++)
  10160. timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, MixDirection$1.out);
  10161. } else {
  10162. let timelineMode = from.timelineMode;
  10163. let timelineHoldMix = from.timelineHoldMix;
  10164. let firstFrame = from.timelinesRotation.length == 0;
  10165. if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  10166. let timelinesRotation = from.timelinesRotation;
  10167. from.totalAlpha = 0;
  10168. for (let i = 0; i < timelineCount; i++) {
  10169. let timeline = timelines[i];
  10170. let direction = MixDirection$1.out;
  10171. let timelineBlend;
  10172. let alpha = 0;
  10173. switch (timelineMode[i]) {
  10174. case AnimationState$1.SUBSEQUENT:
  10175. if (!attachments && timeline instanceof AttachmentTimeline$1) continue;
  10176. if (!drawOrder && timeline instanceof DrawOrderTimeline$1) continue;
  10177. timelineBlend = blend;
  10178. alpha = alphaMix;
  10179. break;
  10180. case AnimationState$1.FIRST:
  10181. timelineBlend = MixBlend$1.setup;
  10182. alpha = alphaMix;
  10183. break;
  10184. case AnimationState$1.HOLD:
  10185. timelineBlend = MixBlend$1.setup;
  10186. alpha = alphaHold;
  10187. break;
  10188. default:
  10189. timelineBlend = MixBlend$1.setup;
  10190. let holdMix = timelineHoldMix[i];
  10191. alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
  10192. break;
  10193. }
  10194. from.totalAlpha += alpha;
  10195. if (timeline instanceof RotateTimeline$1)
  10196. this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame);
  10197. else {
  10198. // This fixes the WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  10199. Utils.webkit602BugfixHelper(alpha, blend);
  10200. if (timelineBlend == MixBlend$1.setup) {
  10201. if (timeline instanceof AttachmentTimeline$1) {
  10202. if (attachments) direction = MixDirection$1.out;
  10203. } else if (timeline instanceof DrawOrderTimeline$1) {
  10204. if (drawOrder) direction = MixDirection$1.out;
  10205. }
  10206. }
  10207. timeline.apply(skeleton, animationLast, animationTime, events, alpha, timelineBlend, direction);
  10208. }
  10209. }
  10210. }
  10211. if (to.mixDuration > 0) this.queueEvents(from, animationTime);
  10212. this.events.length = 0;
  10213. from.nextAnimationLast = animationTime;
  10214. from.nextTrackLast = from.trackTime;
  10215. return mix;
  10216. }
  10217. applyRotateTimeline (timeline, skeleton, time, alpha, blend,
  10218. timelinesRotation, i, firstFrame) {
  10219. if (firstFrame) timelinesRotation[i] = 0;
  10220. if (alpha == 1) {
  10221. timeline.apply(skeleton, 0, time, null, 1, blend, MixDirection$1.in);
  10222. return;
  10223. }
  10224. let rotateTimeline = timeline ;
  10225. let frames = rotateTimeline.frames;
  10226. let bone = skeleton.bones[rotateTimeline.boneIndex];
  10227. let r1 = 0, r2 = 0;
  10228. if (time < frames[0]) {
  10229. switch (blend) {
  10230. case MixBlend$1.setup:
  10231. bone.rotation = bone.data.rotation;
  10232. default:
  10233. return;
  10234. case MixBlend$1.first:
  10235. r1 = bone.rotation;
  10236. r2 = bone.data.rotation;
  10237. }
  10238. } else {
  10239. r1 = blend == MixBlend$1.setup ? bone.data.rotation : bone.rotation;
  10240. if (time >= frames[frames.length - RotateTimeline$1.ENTRIES]) // Time is after last frame.
  10241. r2 = bone.data.rotation + frames[frames.length + RotateTimeline$1.PREV_ROTATION];
  10242. else {
  10243. // Interpolate between the previous frame and the current frame.
  10244. let frame = Animation$1.binarySearch(frames, time, RotateTimeline$1.ENTRIES);
  10245. let prevRotation = frames[frame + RotateTimeline$1.PREV_ROTATION];
  10246. let frameTime = frames[frame];
  10247. let percent = rotateTimeline.getCurvePercent((frame >> 1) - 1,
  10248. 1 - (time - frameTime) / (frames[frame + RotateTimeline$1.PREV_TIME] - frameTime));
  10249. r2 = frames[frame + RotateTimeline$1.ROTATION] - prevRotation;
  10250. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  10251. r2 = prevRotation + r2 * percent + bone.data.rotation;
  10252. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  10253. }
  10254. }
  10255. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
  10256. let total = 0, diff = r2 - r1;
  10257. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  10258. if (diff == 0) {
  10259. total = timelinesRotation[i];
  10260. } else {
  10261. let lastTotal = 0, lastDiff = 0;
  10262. if (firstFrame) {
  10263. lastTotal = 0;
  10264. lastDiff = diff;
  10265. } else {
  10266. lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops.
  10267. lastDiff = timelinesRotation[i + 1]; // Difference between bones.
  10268. }
  10269. let current = diff > 0, dir = lastTotal >= 0;
  10270. // Detect cross at 0 (not 180).
  10271. if (MathUtils.signum(lastDiff) != MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  10272. // A cross after a 360 rotation is a loop.
  10273. if (Math.abs(lastTotal) > 180) lastTotal += 360 * MathUtils.signum(lastTotal);
  10274. dir = current;
  10275. }
  10276. total = diff + lastTotal - lastTotal % 360; // Store loops as part of lastTotal.
  10277. if (dir != current) total += 360 * MathUtils.signum(lastTotal);
  10278. timelinesRotation[i] = total;
  10279. }
  10280. timelinesRotation[i + 1] = diff;
  10281. r1 += total * alpha;
  10282. bone.rotation = r1 - (16384 - ((16384.499999999996 - r1 / 360) | 0)) * 360;
  10283. }
  10284. queueEvents (entry, animationTime) {
  10285. let animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  10286. let duration = animationEnd - animationStart;
  10287. let trackLastWrapped = entry.trackLast % duration;
  10288. // Queue events before complete.
  10289. let events = this.events;
  10290. let i = 0, n = events.length;
  10291. for (; i < n; i++) {
  10292. let event = events[i];
  10293. if (event.time < trackLastWrapped) break;
  10294. if (event.time > animationEnd) continue; // Discard events outside animation start/end.
  10295. this.queue.event(entry, event);
  10296. }
  10297. // Queue complete if completed a loop iteration or the animation.
  10298. let complete = false;
  10299. if (entry.loop)
  10300. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  10301. else
  10302. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  10303. if (complete) this.queue.complete(entry);
  10304. // Queue events after complete.
  10305. for (; i < n; i++) {
  10306. let event = events[i];
  10307. if (event.time < animationStart) continue; // Discard events outside animation start/end.
  10308. this.queue.event(entry, events[i]);
  10309. }
  10310. }
  10311. clearTracks () {
  10312. let oldDrainDisabled = this.queue.drainDisabled;
  10313. this.queue.drainDisabled = true;
  10314. for (let i = 0, n = this.tracks.length; i < n; i++)
  10315. this.clearTrack(i);
  10316. this.tracks.length = 0;
  10317. this.queue.drainDisabled = oldDrainDisabled;
  10318. this.queue.drain();
  10319. }
  10320. clearTrack (trackIndex) {
  10321. if (trackIndex >= this.tracks.length) return;
  10322. let current = this.tracks[trackIndex];
  10323. if (current == null) return;
  10324. this.queue.end(current);
  10325. this.disposeNext(current);
  10326. let entry = current;
  10327. while (true) {
  10328. let from = entry.mixingFrom;
  10329. if (from == null) break;
  10330. this.queue.end(from);
  10331. entry.mixingFrom = null;
  10332. entry.mixingTo = null;
  10333. entry = from;
  10334. }
  10335. this.tracks[current.trackIndex] = null;
  10336. this.queue.drain();
  10337. }
  10338. setCurrent (index, current, interrupt) {
  10339. let from = this.expandToIndex(index);
  10340. this.tracks[index] = current;
  10341. if (from != null) {
  10342. if (interrupt) this.queue.interrupt(from);
  10343. current.mixingFrom = from;
  10344. from.mixingTo = current;
  10345. current.mixTime = 0;
  10346. // Store the interrupted mix percentage.
  10347. if (from.mixingFrom != null && from.mixDuration > 0)
  10348. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  10349. from.timelinesRotation.length = 0; // Reset rotation for mixing out, in case entry was mixed in.
  10350. }
  10351. this.queue.start(current);
  10352. }
  10353. setAnimation (trackIndex, animationName, loop) {
  10354. let animation = this.data.skeletonData.findAnimation(animationName);
  10355. if (animation == null) throw new Error("Animation not found: " + animationName);
  10356. return this.setAnimationWith(trackIndex, animation, loop);
  10357. }
  10358. setAnimationWith (trackIndex, animation, loop) {
  10359. if (animation == null) throw new Error("animation cannot be null.");
  10360. let interrupt = true;
  10361. let current = this.expandToIndex(trackIndex);
  10362. if (current != null) {
  10363. if (current.nextTrackLast == -1) {
  10364. // Don't mix from an entry that was never applied.
  10365. this.tracks[trackIndex] = current.mixingFrom;
  10366. this.queue.interrupt(current);
  10367. this.queue.end(current);
  10368. this.disposeNext(current);
  10369. current = current.mixingFrom;
  10370. interrupt = false;
  10371. } else
  10372. this.disposeNext(current);
  10373. }
  10374. let entry = this.trackEntry(trackIndex, animation, loop, current);
  10375. this.setCurrent(trackIndex, entry, interrupt);
  10376. this.queue.drain();
  10377. return entry;
  10378. }
  10379. addAnimation (trackIndex, animationName, loop, delay) {
  10380. let animation = this.data.skeletonData.findAnimation(animationName);
  10381. if (animation == null) throw new Error("Animation not found: " + animationName);
  10382. return this.addAnimationWith(trackIndex, animation, loop, delay);
  10383. }
  10384. addAnimationWith (trackIndex, animation, loop, delay) {
  10385. if (animation == null) throw new Error("animation cannot be null.");
  10386. let last = this.expandToIndex(trackIndex);
  10387. if (last != null) {
  10388. while (last.next != null)
  10389. last = last.next;
  10390. }
  10391. let entry = this.trackEntry(trackIndex, animation, loop, last);
  10392. if (last == null) {
  10393. this.setCurrent(trackIndex, entry, true);
  10394. this.queue.drain();
  10395. } else {
  10396. last.next = entry;
  10397. if (delay <= 0) {
  10398. let duration = last.animationEnd - last.animationStart;
  10399. if (duration != 0) {
  10400. if (last.loop)
  10401. delay += duration * (1 + ((last.trackTime / duration) | 0));
  10402. else
  10403. delay += Math.max(duration, last.trackTime);
  10404. delay -= this.data.getMix(last.animation, animation);
  10405. } else
  10406. delay = last.trackTime;
  10407. }
  10408. }
  10409. entry.delay = delay;
  10410. return entry;
  10411. }
  10412. setEmptyAnimation (trackIndex, mixDuration) {
  10413. let entry = this.setAnimationWith(trackIndex, AnimationState$1.emptyAnimation, false);
  10414. entry.mixDuration = mixDuration;
  10415. entry.trackEnd = mixDuration;
  10416. return entry;
  10417. }
  10418. addEmptyAnimation (trackIndex, mixDuration, delay) {
  10419. if (delay <= 0) delay -= mixDuration;
  10420. let entry = this.addAnimationWith(trackIndex, AnimationState$1.emptyAnimation, false, delay);
  10421. entry.mixDuration = mixDuration;
  10422. entry.trackEnd = mixDuration;
  10423. return entry;
  10424. }
  10425. setEmptyAnimations (mixDuration) {
  10426. let oldDrainDisabled = this.queue.drainDisabled;
  10427. this.queue.drainDisabled = true;
  10428. for (let i = 0, n = this.tracks.length; i < n; i++) {
  10429. let current = this.tracks[i];
  10430. if (current != null) this.setEmptyAnimation(current.trackIndex, mixDuration);
  10431. }
  10432. this.queue.drainDisabled = oldDrainDisabled;
  10433. this.queue.drain();
  10434. }
  10435. expandToIndex (index) {
  10436. if (index < this.tracks.length) return this.tracks[index];
  10437. Utils.ensureArrayCapacity(this.tracks, index - this.tracks.length + 1, null);
  10438. this.tracks.length = index + 1;
  10439. return null;
  10440. }
  10441. trackEntry (trackIndex, animation, loop, last) {
  10442. let entry = this.trackEntryPool.obtain();
  10443. entry.trackIndex = trackIndex;
  10444. entry.animation = animation;
  10445. entry.loop = loop;
  10446. entry.holdPrevious = false;
  10447. entry.eventThreshold = 0;
  10448. entry.attachmentThreshold = 0;
  10449. entry.drawOrderThreshold = 0;
  10450. entry.animationStart = 0;
  10451. entry.animationEnd = animation.duration;
  10452. entry.animationLast = -1;
  10453. entry.nextAnimationLast = -1;
  10454. entry.delay = 0;
  10455. entry.trackTime = 0;
  10456. entry.trackLast = -1;
  10457. entry.nextTrackLast = -1;
  10458. entry.trackEnd = Number.MAX_VALUE;
  10459. entry.timeScale = 1;
  10460. entry.alpha = 1;
  10461. entry.interruptAlpha = 1;
  10462. entry.mixTime = 0;
  10463. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  10464. return entry;
  10465. }
  10466. disposeNext (entry) {
  10467. let next = entry.next;
  10468. while (next != null) {
  10469. this.queue.dispose(next);
  10470. next = next.next;
  10471. }
  10472. entry.next = null;
  10473. }
  10474. _animationsChanged () {
  10475. this.animationsChanged = false;
  10476. this.propertyIDs.clear();
  10477. for (let i = 0, n = this.tracks.length; i < n; i++) {
  10478. let entry = this.tracks[i];
  10479. if (entry == null) continue;
  10480. while (entry.mixingFrom != null)
  10481. entry = entry.mixingFrom;
  10482. do {
  10483. if (entry.mixingFrom == null || entry.mixBlend != MixBlend$1.add) this.setTimelineModes(entry);
  10484. entry = entry.mixingTo;
  10485. } while (entry != null)
  10486. }
  10487. }
  10488. setTimelineModes (entry) {
  10489. let to = entry.mixingTo;
  10490. let timelines = entry.animation.timelines;
  10491. let timelinesCount = entry.animation.timelines.length;
  10492. let timelineMode = Utils.setArraySize(entry.timelineMode, timelinesCount);
  10493. entry.timelineHoldMix.length = 0;
  10494. let timelineDipMix = Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
  10495. let propertyIDs = this.propertyIDs;
  10496. if (to != null && to.holdPrevious) {
  10497. for (let i = 0; i < timelinesCount; i++) {
  10498. propertyIDs.add(timelines[i].getPropertyId());
  10499. timelineMode[i] = AnimationState$1.HOLD;
  10500. }
  10501. return;
  10502. }
  10503. outer:
  10504. for (let i = 0; i < timelinesCount; i++) {
  10505. let id = timelines[i].getPropertyId();
  10506. if (!propertyIDs.add(id))
  10507. timelineMode[i] = AnimationState$1.SUBSEQUENT;
  10508. else if (to == null || !this.hasTimeline(to, id))
  10509. timelineMode[i] = AnimationState$1.FIRST;
  10510. else {
  10511. for (let next = to.mixingTo; next != null; next = next.mixingTo) {
  10512. if (this.hasTimeline(next, id)) continue;
  10513. if (entry.mixDuration > 0) {
  10514. timelineMode[i] = AnimationState$1.HOLD_MIX;
  10515. timelineDipMix[i] = next;
  10516. continue outer;
  10517. }
  10518. break;
  10519. }
  10520. timelineMode[i] = AnimationState$1.HOLD;
  10521. }
  10522. }
  10523. }
  10524. hasTimeline (entry, id) {
  10525. let timelines = entry.animation.timelines;
  10526. for (let i = 0, n = timelines.length; i < n; i++)
  10527. if (timelines[i].getPropertyId() == id) return true;
  10528. return false;
  10529. }
  10530. getCurrent (trackIndex) {
  10531. if (trackIndex >= this.tracks.length) return null;
  10532. return this.tracks[trackIndex];
  10533. }
  10534. addListener (listener) {
  10535. if (listener == null) throw new Error("listener cannot be null.");
  10536. this.listeners.push(listener);
  10537. }
  10538. /** Removes the listener added with {@link #addListener(AnimationStateListener)}. */
  10539. removeListener (listener) {
  10540. let index = this.listeners.indexOf(listener);
  10541. if (index >= 0) this.listeners.splice(index, 1);
  10542. }
  10543. clearListeners () {
  10544. this.listeners.length = 0;
  10545. }
  10546. clearListenerNotifications () {
  10547. this.queue.clear();
  10548. }
  10549. //deprecated stuff
  10550. static __initStatic6() {this.deprecatedWarning1 = false;}
  10551. setAnimationByName(trackIndex, animationName, loop) {
  10552. if (!AnimationState$1.deprecatedWarning1) {
  10553. AnimationState$1.deprecatedWarning1 = true;
  10554. console.warn("Spine Deprecation Warning: AnimationState.setAnimationByName is deprecated, please use setAnimation from now on.");
  10555. }
  10556. this.setAnimation(trackIndex, animationName, loop);
  10557. }
  10558. static __initStatic7() {this.deprecatedWarning2 = false;}
  10559. addAnimationByName(trackIndex, animationName, loop, delay) {
  10560. if (!AnimationState$1.deprecatedWarning2) {
  10561. AnimationState$1.deprecatedWarning2 = true;
  10562. console.warn("Spine Deprecation Warning: AnimationState.addAnimationByName is deprecated, please use addAnimation from now on.");
  10563. }
  10564. this.addAnimation(trackIndex, animationName, loop, delay);
  10565. }
  10566. static __initStatic8() {this.deprecatedWarning3 = false;}
  10567. hasAnimation(animationName) {
  10568. let animation = this.data.skeletonData.findAnimation(animationName);
  10569. return animation !== null;
  10570. }
  10571. hasAnimationByName(animationName) {
  10572. if (!AnimationState$1.deprecatedWarning3) {
  10573. AnimationState$1.deprecatedWarning3 = true;
  10574. console.warn("Spine Deprecation Warning: AnimationState.hasAnimationByName is deprecated, please use hasAnimation from now on.");
  10575. }
  10576. return this.hasAnimation(animationName);
  10577. }
  10578. } AnimationState$1.__initStatic(); AnimationState$1.__initStatic2(); AnimationState$1.__initStatic3(); AnimationState$1.__initStatic4(); AnimationState$1.__initStatic5(); AnimationState$1.__initStatic6(); AnimationState$1.__initStatic7(); AnimationState$1.__initStatic8();
  10579. /**
  10580. * @public
  10581. */
  10582. class TrackEntry$1 {constructor() { TrackEntry$1.prototype.__init9.call(this);TrackEntry$1.prototype.__init10.call(this);TrackEntry$1.prototype.__init11.call(this);TrackEntry$1.prototype.__init12.call(this); }
  10583. __init9() {this.mixBlend = MixBlend$1.replace;}
  10584. __init10() {this.timelineMode = new Array();}
  10585. __init11() {this.timelineHoldMix = new Array();}
  10586. __init12() {this.timelinesRotation = new Array();}
  10587. reset () {
  10588. this.next = null;
  10589. this.mixingFrom = null;
  10590. this.mixingTo = null;
  10591. this.animation = null;
  10592. this.listener = null;
  10593. this.timelineMode.length = 0;
  10594. this.timelineHoldMix.length = 0;
  10595. this.timelinesRotation.length = 0;
  10596. }
  10597. getAnimationTime () {
  10598. if (this.loop) {
  10599. let duration = this.animationEnd - this.animationStart;
  10600. if (duration == 0) return this.animationStart;
  10601. return (this.trackTime % duration) + this.animationStart;
  10602. }
  10603. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  10604. }
  10605. setAnimationLast(animationLast) {
  10606. this.animationLast = animationLast;
  10607. this.nextAnimationLast = animationLast;
  10608. }
  10609. isComplete () {
  10610. return this.trackTime >= this.animationEnd - this.animationStart;
  10611. }
  10612. resetRotationDirections () {
  10613. this.timelinesRotation.length = 0;
  10614. }
  10615. //deprecated stuff
  10616. static __initStatic9() {this.deprecatedWarning1 = false;}
  10617. static __initStatic10() {this.deprecatedWarning2 = false;}
  10618. get time() {
  10619. if (!TrackEntry$1.deprecatedWarning1) {
  10620. TrackEntry$1.deprecatedWarning1 = true;
  10621. console.warn("Spine Deprecation Warning: TrackEntry.time is deprecated, please use trackTime from now on.");
  10622. }
  10623. return this.trackTime;
  10624. }
  10625. set time(value) {
  10626. if (!TrackEntry$1.deprecatedWarning1) {
  10627. TrackEntry$1.deprecatedWarning1 = true;
  10628. console.warn("Spine Deprecation Warning: TrackEntry.time is deprecated, please use trackTime from now on.");
  10629. }
  10630. this.trackTime = value;
  10631. }
  10632. get endTime() {
  10633. if (!TrackEntry$1.deprecatedWarning2) {
  10634. TrackEntry$1.deprecatedWarning2 = true;
  10635. console.warn("Spine Deprecation Warning: TrackEntry.endTime is deprecated, please use trackEnd from now on.");
  10636. }
  10637. return this.trackTime;
  10638. }
  10639. set endTime(value) {
  10640. if (!TrackEntry$1.deprecatedWarning2) {
  10641. TrackEntry$1.deprecatedWarning2 = true;
  10642. console.warn("Spine Deprecation Warning: TrackEntry.endTime is deprecated, please use trackEnd from now on.");
  10643. }
  10644. this.trackTime = value;
  10645. }
  10646. loopsCount() {
  10647. return Math.floor(this.trackTime / this.trackEnd);
  10648. }
  10649. } TrackEntry$1.__initStatic9(); TrackEntry$1.__initStatic10();
  10650. /**
  10651. * @public
  10652. */
  10653. class EventQueue$1 {
  10654. __init13() {this.objects = [];}
  10655. __init14() {this.drainDisabled = false;}
  10656. constructor(animState) {EventQueue$1.prototype.__init13.call(this);EventQueue$1.prototype.__init14.call(this);
  10657. this.animState = animState;
  10658. }
  10659. start (entry) {
  10660. this.objects.push(EventType$1.start);
  10661. this.objects.push(entry);
  10662. this.animState.animationsChanged = true;
  10663. }
  10664. interrupt (entry) {
  10665. this.objects.push(EventType$1.interrupt);
  10666. this.objects.push(entry);
  10667. }
  10668. end (entry) {
  10669. this.objects.push(EventType$1.end);
  10670. this.objects.push(entry);
  10671. this.animState.animationsChanged = true;
  10672. }
  10673. dispose (entry) {
  10674. this.objects.push(EventType$1.dispose);
  10675. this.objects.push(entry);
  10676. }
  10677. complete (entry) {
  10678. this.objects.push(EventType$1.complete);
  10679. this.objects.push(entry);
  10680. }
  10681. event (entry, event) {
  10682. this.objects.push(EventType$1.event);
  10683. this.objects.push(entry);
  10684. this.objects.push(event);
  10685. }
  10686. static __initStatic11() {this.deprecatedWarning1 = false;}
  10687. deprecateStuff() {
  10688. if (!EventQueue$1.deprecatedWarning1) {
  10689. EventQueue$1.deprecatedWarning1 = true;
  10690. console.warn("Spine Deprecation Warning: onComplete, onStart, onEnd, onEvent art deprecated, please use listeners from now on. 'state.addListener({ complete: function(track, event) { } })'");
  10691. }
  10692. return true;
  10693. }
  10694. drain () {
  10695. if (this.drainDisabled) return;
  10696. this.drainDisabled = true;
  10697. let objects = this.objects;
  10698. let listeners = this.animState.listeners;
  10699. for (let i = 0; i < objects.length; i += 2) {
  10700. let type = objects[i] ;
  10701. let entry = objects[i + 1] ;
  10702. switch (type) {
  10703. case EventType$1.start:
  10704. if (entry.listener != null && entry.listener.start) entry.listener.start(entry);
  10705. for (let ii = 0; ii < listeners.length; ii++)
  10706. if (listeners[ii].start) listeners[ii].start(entry);
  10707. //deprecation
  10708. entry.onStart && this.deprecateStuff() && entry.onStart(entry.trackIndex);
  10709. this.animState.onStart && this.deprecateStuff() && this.deprecateStuff && this.animState.onStart(entry.trackIndex);
  10710. break;
  10711. case EventType$1.interrupt:
  10712. if (entry.listener != null && entry.listener.interrupt) entry.listener.interrupt(entry);
  10713. for (let ii = 0; ii < listeners.length; ii++)
  10714. if (listeners[ii].interrupt) listeners[ii].interrupt(entry);
  10715. break;
  10716. case EventType$1.end:
  10717. if (entry.listener != null && entry.listener.end) entry.listener.end(entry);
  10718. for (let ii = 0; ii < listeners.length; ii++)
  10719. if (listeners[ii].end) listeners[ii].end(entry);
  10720. //deprecation
  10721. entry.onEnd && this.deprecateStuff() && entry.onEnd(entry.trackIndex);
  10722. this.animState.onEnd && this.deprecateStuff() && this.animState.onEnd(entry.trackIndex);
  10723. // Fall through.
  10724. case EventType$1.dispose:
  10725. if (entry.listener != null && entry.listener.dispose) entry.listener.dispose(entry);
  10726. for (let ii = 0; ii < listeners.length; ii++)
  10727. if (listeners[ii].dispose) listeners[ii].dispose(entry);
  10728. this.animState.trackEntryPool.free(entry);
  10729. break;
  10730. case EventType$1.complete:
  10731. if (entry.listener != null && entry.listener.complete) entry.listener.complete(entry);
  10732. for (let ii = 0; ii < listeners.length; ii++)
  10733. if (listeners[ii].complete) listeners[ii].complete(entry);
  10734. //deprecation
  10735. let count = MathUtils.toInt(entry.loopsCount()) ;
  10736. entry.onComplete && this.deprecateStuff() && entry.onComplete(entry.trackIndex, count);
  10737. this.animState.onComplete && this.deprecateStuff() && this.animState.onComplete(entry.trackIndex, count);
  10738. break;
  10739. case EventType$1.event:
  10740. let event = objects[i++ + 2] ;
  10741. if (entry.listener != null && entry.listener.event) entry.listener.event(entry, event);
  10742. for (let ii = 0; ii < listeners.length; ii++)
  10743. if (listeners[ii].event) listeners[ii].event(entry, event);
  10744. //deprecation
  10745. entry.onEvent && this.deprecateStuff() && entry.onEvent(entry.trackIndex, event);
  10746. this.animState.onEvent && this.deprecateStuff() && this.animState.onEvent(entry.trackIndex, event);
  10747. break;
  10748. }
  10749. }
  10750. this.clear();
  10751. this.drainDisabled = false;
  10752. }
  10753. clear () {
  10754. this.objects.length = 0;
  10755. }
  10756. } EventQueue$1.__initStatic11();
  10757. /**
  10758. * @public
  10759. */
  10760. var EventType$1; (function (EventType) {
  10761. const start = 0; EventType[EventType["start"] = start] = "start"; const interrupt = start + 1; EventType[EventType["interrupt"] = interrupt] = "interrupt"; const end = interrupt + 1; EventType[EventType["end"] = end] = "end"; const dispose = end + 1; EventType[EventType["dispose"] = dispose] = "dispose"; const complete = dispose + 1; EventType[EventType["complete"] = complete] = "complete"; const event = complete + 1; EventType[EventType["event"] = event] = "event";
  10762. })(EventType$1 || (EventType$1 = {}));
  10763. /**
  10764. * @public
  10765. */
  10766. /**
  10767. * @public
  10768. */
  10769. class AnimationStateAdapter2 {
  10770. start (entry) {
  10771. }
  10772. interrupt (entry) {
  10773. }
  10774. end (entry) {
  10775. }
  10776. dispose (entry) {
  10777. }
  10778. complete (entry) {
  10779. }
  10780. event (entry, event) {
  10781. }
  10782. }
  10783. /**
  10784. * @public
  10785. */
  10786. class AnimationStateData$1 {
  10787. __init() {this.animationToMixTime = {};}
  10788. __init2() {this.defaultMix = 0;}
  10789. constructor(skeletonData) {AnimationStateData$1.prototype.__init.call(this);AnimationStateData$1.prototype.__init2.call(this);
  10790. if (skeletonData == null) throw new Error("skeletonData cannot be null.");
  10791. this.skeletonData = skeletonData;
  10792. }
  10793. setMix(fromName, toName, duration) {
  10794. let from = this.skeletonData.findAnimation(fromName);
  10795. if (from == null) throw new Error("Animation not found: " + fromName);
  10796. let to = this.skeletonData.findAnimation(toName);
  10797. if (to == null) throw new Error("Animation not found: " + toName);
  10798. this.setMixWith(from, to, duration);
  10799. }
  10800. static __initStatic() {this.deprecatedWarning1 = false;}
  10801. setMixByName(fromName, toName, duration) {
  10802. if (!AnimationStateData$1.deprecatedWarning1) {
  10803. AnimationStateData$1.deprecatedWarning1 = true;
  10804. console.warn("Deprecation Warning: AnimationStateData.setMixByName is deprecated, please use setMix from now on.");
  10805. }
  10806. this.setMix(fromName, toName, duration);
  10807. }
  10808. setMixWith(from, to, duration) {
  10809. if (from == null) throw new Error("from cannot be null.");
  10810. if (to == null) throw new Error("to cannot be null.");
  10811. let key = from.name + "." + to.name;
  10812. this.animationToMixTime[key] = duration;
  10813. }
  10814. getMix(from, to) {
  10815. let key = from.name + "." + to.name;
  10816. let value = this.animationToMixTime[key];
  10817. return value === undefined ? this.defaultMix : value;
  10818. }
  10819. } AnimationStateData$1.__initStatic();
  10820. /**
  10821. * @public
  10822. */
  10823. class AtlasAttachmentLoader$1 {
  10824. constructor(atlas) {
  10825. this.atlas = atlas;
  10826. }
  10827. /** @return May be null to not load an attachment. */
  10828. newRegionAttachment(skin, name, path) {
  10829. let region = this.atlas.findRegion(path);
  10830. if (region == null) throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  10831. let attachment = new RegionAttachment$1(name);
  10832. attachment.region = region;
  10833. return attachment;
  10834. }
  10835. /** @return May be null to not load an attachment. */
  10836. newMeshAttachment(skin, name, path) {
  10837. let region = this.atlas.findRegion(path);
  10838. if (region == null) throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  10839. let attachment = new MeshAttachment$1(name);
  10840. attachment.region = region;
  10841. return attachment;
  10842. }
  10843. /** @return May be null to not load an attachment. */
  10844. newBoundingBoxAttachment(skin, name) {
  10845. return new BoundingBoxAttachment$1(name);
  10846. }
  10847. /** @return May be null to not load an attachment */
  10848. newPathAttachment(skin, name) {
  10849. return new PathAttachment$1(name);
  10850. }
  10851. newPointAttachment(skin, name) {
  10852. return new PointAttachment$1(name);
  10853. }
  10854. newClippingAttachment(skin, name) {
  10855. return new ClippingAttachment$1(name);
  10856. }
  10857. }
  10858. /**
  10859. * @public
  10860. */
  10861. class BoneData$1 {
  10862. __init() {this.x = 0;}
  10863. __init2() {this.y = 0;}
  10864. __init3() {this.rotation = 0;}
  10865. __init4() {this.scaleX = 1;}
  10866. __init5() {this.scaleY = 1;}
  10867. __init6() {this.shearX = 0;}
  10868. __init7() {this.shearY = 0;}
  10869. __init8() {this.transformMode = TransformMode$1.Normal;}
  10870. constructor(index, name, parent) {BoneData$1.prototype.__init.call(this);BoneData$1.prototype.__init2.call(this);BoneData$1.prototype.__init3.call(this);BoneData$1.prototype.__init4.call(this);BoneData$1.prototype.__init5.call(this);BoneData$1.prototype.__init6.call(this);BoneData$1.prototype.__init7.call(this);BoneData$1.prototype.__init8.call(this);
  10871. if (index < 0) throw new Error("index must be >= 0.");
  10872. if (name == null) throw new Error("name cannot be null.");
  10873. this.index = index;
  10874. this.name = name;
  10875. this.parent = parent;
  10876. }
  10877. }
  10878. /**
  10879. * @public
  10880. */
  10881. var TransformMode$1; (function (TransformMode) {
  10882. const Normal = 0; TransformMode[TransformMode["Normal"] = Normal] = "Normal"; const OnlyTranslation = Normal + 1; TransformMode[TransformMode["OnlyTranslation"] = OnlyTranslation] = "OnlyTranslation"; const NoRotationOrReflection = OnlyTranslation + 1; TransformMode[TransformMode["NoRotationOrReflection"] = NoRotationOrReflection] = "NoRotationOrReflection"; const NoScale = NoRotationOrReflection + 1; TransformMode[TransformMode["NoScale"] = NoScale] = "NoScale"; const NoScaleOrReflection = NoScale + 1; TransformMode[TransformMode["NoScaleOrReflection"] = NoScaleOrReflection] = "NoScaleOrReflection";
  10883. })(TransformMode$1 || (TransformMode$1 = {}));
  10884. /**
  10885. * @public
  10886. */
  10887. class Bone$1 {
  10888. //be careful! Spine b,c is c,b in pixi matrix
  10889. __init() {this.matrix = new math.Matrix();}
  10890. get worldX() {
  10891. return this.matrix.tx;
  10892. }
  10893. get worldY() {
  10894. return this.matrix.ty;
  10895. }
  10896. __init2() {this.children = new Array();}
  10897. __init3() {this.x = 0;}
  10898. __init4() {this.y = 0;}
  10899. __init5() {this.rotation = 0;}
  10900. __init6() {this.scaleX = 0;}
  10901. __init7() {this.scaleY = 0;}
  10902. __init8() {this.shearX = 0;}
  10903. __init9() {this.shearY = 0;}
  10904. __init10() {this.ax = 0;}
  10905. __init11() {this.ay = 0;}
  10906. __init12() {this.arotation = 0;}
  10907. __init13() {this.ascaleX = 0;}
  10908. __init14() {this.ascaleY = 0;}
  10909. __init15() {this.ashearX = 0;}
  10910. __init16() {this.ashearY = 0;}
  10911. __init17() {this.appliedValid = false;}
  10912. __init18() {this.sorted = false;}
  10913. /** @param parent May be null. */
  10914. constructor(data, skeleton, parent) {Bone$1.prototype.__init.call(this);Bone$1.prototype.__init2.call(this);Bone$1.prototype.__init3.call(this);Bone$1.prototype.__init4.call(this);Bone$1.prototype.__init5.call(this);Bone$1.prototype.__init6.call(this);Bone$1.prototype.__init7.call(this);Bone$1.prototype.__init8.call(this);Bone$1.prototype.__init9.call(this);Bone$1.prototype.__init10.call(this);Bone$1.prototype.__init11.call(this);Bone$1.prototype.__init12.call(this);Bone$1.prototype.__init13.call(this);Bone$1.prototype.__init14.call(this);Bone$1.prototype.__init15.call(this);Bone$1.prototype.__init16.call(this);Bone$1.prototype.__init17.call(this);Bone$1.prototype.__init18.call(this);
  10915. if (data == null) throw new Error("data cannot be null.");
  10916. if (skeleton == null) throw new Error("skeleton cannot be null.");
  10917. this.data = data;
  10918. this.skeleton = skeleton;
  10919. this.parent = parent;
  10920. this.setToSetupPose();
  10921. }
  10922. /** Same as {@link #updateWorldTransform()}. This method exists for Bone to implement {@link Updatable}. */
  10923. update() {
  10924. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  10925. }
  10926. /** Computes the world transform using the parent bone and this bone's local transform. */
  10927. updateWorldTransform() {
  10928. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  10929. }
  10930. /** Computes the world transform using the parent bone and the specified local transform. */
  10931. updateWorldTransformWith(x, y, rotation, scaleX, scaleY, shearX, shearY) {
  10932. this.ax = x;
  10933. this.ay = y;
  10934. this.arotation = rotation;
  10935. this.ascaleX = scaleX;
  10936. this.ascaleY = scaleY;
  10937. this.ashearX = shearX;
  10938. this.ashearY = shearY;
  10939. this.appliedValid = true;
  10940. let parent = this.parent;
  10941. let m = this.matrix;
  10942. let sx = this.skeleton.scaleX;
  10943. let sy = settings.yDown? -this.skeleton.scaleY : this.skeleton.scaleY;
  10944. if (parent == null) { // Root bone.
  10945. let skeleton = this.skeleton;
  10946. let rotationY = rotation + 90 + shearY;
  10947. m.a = MathUtils.cosDeg(rotation + shearX) * scaleX * sx;
  10948. m.c = MathUtils.cosDeg(rotationY) * scaleY * sx;
  10949. m.b = MathUtils.sinDeg(rotation + shearX) * scaleX * sy;
  10950. m.d = MathUtils.sinDeg(rotationY) * scaleY * sy;
  10951. m.tx = x * sx + skeleton.x;
  10952. m.ty = y * sy + skeleton.y;
  10953. return;
  10954. }
  10955. let pa = parent.matrix.a, pb = parent.matrix.c, pc = parent.matrix.b, pd = parent.matrix.d;
  10956. m.tx = pa * x + pb * y + parent.matrix.tx;
  10957. m.ty = pc * x + pd * y + parent.matrix.ty;
  10958. switch (this.data.transformMode) {
  10959. case TransformMode$1.Normal: {
  10960. let rotationY = rotation + 90 + shearY;
  10961. let la = MathUtils.cosDeg(rotation + shearX) * scaleX;
  10962. let lb = MathUtils.cosDeg(rotationY) * scaleY;
  10963. let lc = MathUtils.sinDeg(rotation + shearX) * scaleX;
  10964. let ld = MathUtils.sinDeg(rotationY) * scaleY;
  10965. m.a = pa * la + pb * lc;
  10966. m.c = pa * lb + pb * ld;
  10967. m.b = pc * la + pd * lc;
  10968. m.d = pc * lb + pd * ld;
  10969. return;
  10970. }
  10971. case TransformMode$1.OnlyTranslation: {
  10972. let rotationY = rotation + 90 + shearY;
  10973. m.a = MathUtils.cosDeg(rotation + shearX) * scaleX;
  10974. m.c = MathUtils.cosDeg(rotationY) * scaleY;
  10975. m.b = MathUtils.sinDeg(rotation + shearX) * scaleX;
  10976. m.d = MathUtils.sinDeg(rotationY) * scaleY;
  10977. break;
  10978. }
  10979. case TransformMode$1.NoRotationOrReflection: {
  10980. let s = pa * pa + pc * pc;
  10981. let prx = 0;
  10982. if (s > 0.0001) {
  10983. s = Math.abs(pa * pd - pb * pc) / s;
  10984. pb = pc * s;
  10985. pd = pa * s;
  10986. prx = Math.atan2(pc, pa) * MathUtils.radDeg;
  10987. } else {
  10988. pa = 0;
  10989. pc = 0;
  10990. prx = 90 - Math.atan2(pd, pb) * MathUtils.radDeg;
  10991. }
  10992. let rx = rotation + shearX - prx;
  10993. let ry = rotation + shearY - prx + 90;
  10994. let la = MathUtils.cosDeg(rx) * scaleX;
  10995. let lb = MathUtils.cosDeg(ry) * scaleY;
  10996. let lc = MathUtils.sinDeg(rx) * scaleX;
  10997. let ld = MathUtils.sinDeg(ry) * scaleY;
  10998. m.a = pa * la - pb * lc;
  10999. m.c = pa * lb - pb * ld;
  11000. m.b = pc * la + pd * lc;
  11001. m.d = pc * lb + pd * ld;
  11002. break;
  11003. }
  11004. case TransformMode$1.NoScale:
  11005. case TransformMode$1.NoScaleOrReflection: {
  11006. let cos = MathUtils.cosDeg(rotation);
  11007. let sin = MathUtils.sinDeg(rotation);
  11008. let za = (pa * cos + pb * sin) / sx;
  11009. let zc = (pc * cos + pd * sin) / sy;
  11010. let s = Math.sqrt(za * za + zc * zc);
  11011. if (s > 0.00001) s = 1 / s;
  11012. za *= s;
  11013. zc *= s;
  11014. s = Math.sqrt(za * za + zc * zc);
  11015. if (
  11016. this.data.transformMode == TransformMode$1.NoScale
  11017. && (pa * pd - pb * pc < 0) != (settings.yDown?
  11018. (this.skeleton.scaleX < 0 != this.skeleton.scaleY > 0) :
  11019. (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0))
  11020. ) s = -s;
  11021. let r = Math.PI / 2 + Math.atan2(zc, za);
  11022. let zb = Math.cos(r) * s;
  11023. let zd = Math.sin(r) * s;
  11024. let la = MathUtils.cosDeg(shearX) * scaleX;
  11025. let lb = MathUtils.cosDeg(90 + shearY) * scaleY;
  11026. let lc = MathUtils.sinDeg(shearX) * scaleX;
  11027. let ld = MathUtils.sinDeg(90 + shearY) * scaleY;
  11028. m.a = za * la + zb * lc;
  11029. m.c = za * lb + zb * ld;
  11030. m.b = zc * la + zd * lc;
  11031. m.d = zc * lb + zd * ld;
  11032. break;
  11033. }
  11034. }
  11035. m.a *= sx;
  11036. m.c *= sx;
  11037. m.b *= sy;
  11038. m.d *= sy;
  11039. }
  11040. setToSetupPose() {
  11041. let data = this.data;
  11042. this.x = data.x;
  11043. this.y = data.y;
  11044. this.rotation = data.rotation;
  11045. this.scaleX = data.scaleX;
  11046. this.scaleY = data.scaleY;
  11047. this.shearX = data.shearX;
  11048. this.shearY = data.shearY;
  11049. }
  11050. getWorldRotationX() {
  11051. return Math.atan2(this.matrix.b, this.matrix.a) * MathUtils.radDeg;
  11052. }
  11053. getWorldRotationY() {
  11054. return Math.atan2(this.matrix.d, this.matrix.c) * MathUtils.radDeg;
  11055. }
  11056. getWorldScaleX() {
  11057. let m = this.matrix;
  11058. return Math.sqrt(m.a * m.a + m.c * m.c);
  11059. }
  11060. getWorldScaleY() {
  11061. let m = this.matrix;
  11062. return Math.sqrt(m.b * m.b + m.d * m.d);
  11063. }
  11064. /** Computes the individual applied transform values from the world transform. This can be useful to perform processing using
  11065. * the applied transform after the world transform has been modified directly (eg, by a constraint).
  11066. * <p>
  11067. * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. */
  11068. updateAppliedTransform() {
  11069. this.appliedValid = true;
  11070. let parent = this.parent;
  11071. let m = this.matrix;
  11072. if (parent == null) {
  11073. this.ax = m.tx;
  11074. this.ay = m.ty;
  11075. this.arotation = Math.atan2(m.b, m.a) * MathUtils.radDeg;
  11076. this.ascaleX = Math.sqrt(m.a * m.a + m.b * m.b);
  11077. this.ascaleY = Math.sqrt(m.c * m.c + m.d * m.d);
  11078. this.ashearX = 0;
  11079. this.ashearY = Math.atan2(m.a * m.c + m.b * m.d, m.a * m.d - m.b * m.c) * MathUtils.radDeg;
  11080. return;
  11081. }
  11082. let pm = parent.matrix;
  11083. let pid = 1 / (pm.a * pm.d - pm.b * pm.c);
  11084. let dx = m.tx - pm.tx, dy = m.ty - pm.ty;
  11085. this.ax = (dx * pm.d * pid - dy * pm.c * pid);
  11086. this.ay = (dy * pm.a * pid - dx * pm.b * pid);
  11087. let ia = pid * pm.d;
  11088. let id = pid * pm.a;
  11089. let ib = pid * pm.c;
  11090. let ic = pid * pm.b;
  11091. let ra = ia * m.a - ib * m.b;
  11092. let rb = ia * m.c - ib * m.d;
  11093. let rc = id * m.b - ic * m.a;
  11094. let rd = id * m.d - ic * m.c;
  11095. this.ashearX = 0;
  11096. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  11097. if (this.ascaleX > 0.0001) {
  11098. let det = ra * rd - rb * rc;
  11099. this.ascaleY = det / this.ascaleX;
  11100. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * MathUtils.radDeg;
  11101. this.arotation = Math.atan2(rc, ra) * MathUtils.radDeg;
  11102. } else {
  11103. this.ascaleX = 0;
  11104. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  11105. this.ashearY = 0;
  11106. this.arotation = 90 - Math.atan2(rd, rb) * MathUtils.radDeg;
  11107. }
  11108. }
  11109. worldToLocal(world) {
  11110. let m = this.matrix;
  11111. let a = m.a, b = m.c, c = m.b, d = m.d;
  11112. let invDet = 1 / (a * d - b * c);
  11113. let x = world.x - m.tx, y = world.y - m.ty;
  11114. world.x = (x * d * invDet - y * b * invDet);
  11115. world.y = (y * a * invDet - x * c * invDet);
  11116. return world;
  11117. }
  11118. localToWorld(local) {
  11119. let m = this.matrix;
  11120. let x = local.x, y = local.y;
  11121. local.x = x * m.a + y * m.c + m.tx;
  11122. local.y = x * m.b + y * m.d + m.ty;
  11123. return local;
  11124. }
  11125. worldToLocalRotation (worldRotation) {
  11126. let sin = MathUtils.sinDeg(worldRotation), cos = MathUtils.cosDeg(worldRotation);
  11127. let mat = this.matrix;
  11128. return Math.atan2(mat.a * sin - mat.b * cos, mat.d * cos - mat.c * sin) * MathUtils.radDeg;
  11129. }
  11130. localToWorldRotation (localRotation) {
  11131. let sin = MathUtils.sinDeg(localRotation), cos = MathUtils.cosDeg(localRotation);
  11132. let mat = this.matrix;
  11133. return Math.atan2(cos * mat.b + sin * mat.d, cos * mat.a + sin * mat.c) * MathUtils.radDeg;
  11134. }
  11135. rotateWorld (degrees) {
  11136. let mat = this.matrix;
  11137. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  11138. let cos = MathUtils.cosDeg(degrees), sin = MathUtils.sinDeg(degrees);
  11139. mat.a = cos * a - sin * c;
  11140. mat.c = cos * b - sin * d;
  11141. mat.b = sin * a + cos * c;
  11142. mat.d = sin * b + cos * d;
  11143. this.appliedValid = false;
  11144. }
  11145. }
  11146. /**
  11147. * @public
  11148. */
  11149. class Event$1 {
  11150. constructor(time, data) {
  11151. if (data == null) throw new Error("data cannot be null.");
  11152. this.time = time;
  11153. this.data = data;
  11154. }
  11155. }
  11156. /**
  11157. * @public
  11158. */
  11159. class EventData$1 {
  11160. constructor (name) {
  11161. this.name = name;
  11162. }
  11163. }
  11164. /**
  11165. * @public
  11166. */
  11167. class IkConstraint$1 {
  11168. __init() {this.bendDirection = 0;}
  11169. __init2() {this.compress = false;}
  11170. __init3() {this.stretch = false;}
  11171. __init4() {this.mix = 1;}
  11172. constructor (data, skeleton) {IkConstraint$1.prototype.__init.call(this);IkConstraint$1.prototype.__init2.call(this);IkConstraint$1.prototype.__init3.call(this);IkConstraint$1.prototype.__init4.call(this);
  11173. if (data == null) throw new Error("data cannot be null.");
  11174. if (skeleton == null) throw new Error("skeleton cannot be null.");
  11175. this.data = data;
  11176. this.mix = data.mix;
  11177. this.bendDirection = data.bendDirection;
  11178. this.compress = data.compress;
  11179. this.stretch = data.stretch;
  11180. this.bones = new Array();
  11181. for (let i = 0; i < data.bones.length; i++)
  11182. this.bones.push(skeleton.findBone(data.bones[i].name));
  11183. this.target = skeleton.findBone(data.target.name);
  11184. }
  11185. getOrder () {
  11186. return this.data.order;
  11187. }
  11188. apply () {
  11189. this.update();
  11190. }
  11191. update () {
  11192. let target = this.target;
  11193. let bones = this.bones;
  11194. switch (bones.length) {
  11195. case 1:
  11196. this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix);
  11197. break;
  11198. case 2:
  11199. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.mix);
  11200. break;
  11201. }
  11202. }
  11203. /** Adjusts the bone rotation so the tip is as close to the target position as possible. The target is specified in the world
  11204. * coordinate system. */
  11205. apply1 (bone, targetX, targetY, compress, stretch, uniform, alpha) {
  11206. if (!bone.appliedValid) bone.updateAppliedTransform();
  11207. let p = bone.parent.matrix;
  11208. let id = 1 / (p.a * p.d - p.b * p.c);
  11209. let x = targetX - p.tx, y = targetY - p.ty;
  11210. let tx = (x * p.d - y * p.c) * id - bone.ax, ty = (y * p.a - x * p.b) * id - bone.ay;
  11211. let rotationIK = Math.atan2(ty, tx) * MathUtils.radDeg - bone.ashearX - bone.arotation;
  11212. if (bone.ascaleX < 0) rotationIK += 180;
  11213. if (rotationIK > 180)
  11214. rotationIK -= 360;
  11215. else if (rotationIK < -180) rotationIK += 360;
  11216. let sx = bone.ascaleX, sy = bone.ascaleY;
  11217. if (compress || stretch) {
  11218. let b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
  11219. if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
  11220. let s = (dd / b - 1) * alpha + 1;
  11221. sx *= s;
  11222. if (uniform) sy *= s;
  11223. }
  11224. }
  11225. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX,
  11226. bone.ashearY);
  11227. }
  11228. /** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The
  11229. * target is specified in the world coordinate system.
  11230. * @param child A direct descendant of the parent bone. */
  11231. apply2 (parent, child, targetX, targetY, bendDir, stretch, alpha) {
  11232. if (alpha == 0) {
  11233. child.updateWorldTransform();
  11234. return;
  11235. }
  11236. if (!parent.appliedValid) parent.updateAppliedTransform();
  11237. if (!child.appliedValid) child.updateAppliedTransform();
  11238. let px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
  11239. let pmat = parent.matrix;
  11240. let os1 = 0, os2 = 0, s2 = 0;
  11241. if (psx < 0) {
  11242. psx = -psx;
  11243. os1 = 180;
  11244. s2 = -1;
  11245. } else {
  11246. os1 = 0;
  11247. s2 = 1;
  11248. }
  11249. if (psy < 0) {
  11250. psy = -psy;
  11251. s2 = -s2;
  11252. }
  11253. if (csx < 0) {
  11254. csx = -csx;
  11255. os2 = 180;
  11256. } else
  11257. os2 = 0;
  11258. let cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = pmat.a, b = pmat.c, c = pmat.b, d = pmat.d;
  11259. let u = Math.abs(psx - psy) <= 0.0001;
  11260. if (!u) {
  11261. cy = 0;
  11262. cwx = a * cx + pmat.tx;
  11263. cwy = c * cx + pmat.ty;
  11264. } else {
  11265. cy = child.ay;
  11266. cwx = a * cx + b * cy + pmat.tx;
  11267. cwy = c * cx + d * cy + pmat.ty;
  11268. }
  11269. let pp = parent.parent.matrix;
  11270. a = pp.a;
  11271. b = pp.c;
  11272. c = pp.b;
  11273. d = pp.d;
  11274. let id = 1 / (a * d - b * c), x = targetX - pp.tx, y = targetY - pp.ty;
  11275. let tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py, dd = tx * tx + ty * ty;
  11276. x = cwx - pp.tx;
  11277. y = cwy - pp.ty;
  11278. let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  11279. let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1 = 0, a2 = 0;
  11280. outer:
  11281. if (u) {
  11282. l2 *= psx;
  11283. let cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  11284. if (cos < -1)
  11285. cos = -1;
  11286. else if (cos > 1) {
  11287. cos = 1;
  11288. if (stretch && l1 + l2 > 0.0001) sx *= (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
  11289. }
  11290. a2 = Math.acos(cos) * bendDir;
  11291. a = l1 + l2 * cos;
  11292. b = l2 * Math.sin(a2);
  11293. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  11294. } else {
  11295. a = psx * l2;
  11296. b = psy * l2;
  11297. let aa = a * a, bb = b * b, ta = Math.atan2(ty, tx);
  11298. c = bb * l1 * l1 + aa * dd - aa * bb;
  11299. let c1 = -2 * bb * l1, c2 = bb - aa;
  11300. d = c1 * c1 - 4 * c2 * c;
  11301. if (d >= 0) {
  11302. let q = Math.sqrt(d);
  11303. if (c1 < 0) q = -q;
  11304. q = -(c1 + q) / 2;
  11305. let r0 = q / c2, r1 = c / q;
  11306. let r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  11307. if (r * r <= dd) {
  11308. y = Math.sqrt(dd - r * r) * bendDir;
  11309. a1 = ta - Math.atan2(y, r);
  11310. a2 = Math.atan2(y / psy, (r - l1) / psx);
  11311. break outer;
  11312. }
  11313. }
  11314. let minAngle = MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  11315. let maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  11316. c = -a * l1 / (aa - bb);
  11317. if (c >= -1 && c <= 1) {
  11318. c = Math.acos(c);
  11319. x = a * Math.cos(c) + l1;
  11320. y = b * Math.sin(c);
  11321. d = x * x + y * y;
  11322. if (d < minDist) {
  11323. minAngle = c;
  11324. minDist = d;
  11325. minX = x;
  11326. minY = y;
  11327. }
  11328. if (d > maxDist) {
  11329. maxAngle = c;
  11330. maxDist = d;
  11331. maxX = x;
  11332. maxY = y;
  11333. }
  11334. }
  11335. if (dd <= (minDist + maxDist) / 2) {
  11336. a1 = ta - Math.atan2(minY * bendDir, minX);
  11337. a2 = minAngle * bendDir;
  11338. } else {
  11339. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  11340. a2 = maxAngle * bendDir;
  11341. }
  11342. }
  11343. let os = Math.atan2(cy, cx) * s2;
  11344. let rotation = parent.arotation;
  11345. a1 = (a1 - os) * MathUtils.radDeg + os1 - rotation;
  11346. if (a1 > 180)
  11347. a1 -= 360;
  11348. else if (a1 < -180) a1 += 360;
  11349. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, parent.ascaleY, 0, 0);
  11350. rotation = child.arotation;
  11351. a2 = ((a2 + os) * MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  11352. if (a2 > 180)
  11353. a2 -= 360;
  11354. else if (a2 < -180) a2 += 360;
  11355. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  11356. }
  11357. }
  11358. /**
  11359. * @public
  11360. */
  11361. class IkConstraintData$1 {
  11362. __init() {this.order = 0;}
  11363. __init2() {this.bones = new Array();}
  11364. __init3() {this.bendDirection = 1;}
  11365. __init4() {this.compress = false;}
  11366. __init5() {this.stretch = false;}
  11367. __init6() {this.uniform = false;}
  11368. __init7() {this.mix = 1;}
  11369. constructor (name) {IkConstraintData$1.prototype.__init.call(this);IkConstraintData$1.prototype.__init2.call(this);IkConstraintData$1.prototype.__init3.call(this);IkConstraintData$1.prototype.__init4.call(this);IkConstraintData$1.prototype.__init5.call(this);IkConstraintData$1.prototype.__init6.call(this);IkConstraintData$1.prototype.__init7.call(this);
  11370. this.name = name;
  11371. }
  11372. }
  11373. /**
  11374. * @public
  11375. */
  11376. class PathConstraintData$1 {
  11377. __init() {this.order = 0;}
  11378. __init2() {this.bones = new Array();}
  11379. constructor(name) {PathConstraintData$1.prototype.__init.call(this);PathConstraintData$1.prototype.__init2.call(this);
  11380. this.name = name;
  11381. }
  11382. }
  11383. /**
  11384. * @public
  11385. */
  11386. var PositionMode$1; (function (PositionMode) {
  11387. const Fixed = 0; PositionMode[PositionMode["Fixed"] = Fixed] = "Fixed"; const Percent = Fixed + 1; PositionMode[PositionMode["Percent"] = Percent] = "Percent";
  11388. })(PositionMode$1 || (PositionMode$1 = {}));
  11389. /**
  11390. * @public
  11391. */
  11392. var SpacingMode$1; (function (SpacingMode) {
  11393. const Length = 0; SpacingMode[SpacingMode["Length"] = Length] = "Length"; const Fixed = Length + 1; SpacingMode[SpacingMode["Fixed"] = Fixed] = "Fixed"; const Percent = Fixed + 1; SpacingMode[SpacingMode["Percent"] = Percent] = "Percent";
  11394. })(SpacingMode$1 || (SpacingMode$1 = {}));
  11395. /**
  11396. * @public
  11397. */
  11398. var RotateMode$1; (function (RotateMode) {
  11399. const Tangent = 0; RotateMode[RotateMode["Tangent"] = Tangent] = "Tangent"; const Chain = Tangent + 1; RotateMode[RotateMode["Chain"] = Chain] = "Chain"; const ChainScale = Chain + 1; RotateMode[RotateMode["ChainScale"] = ChainScale] = "ChainScale";
  11400. })(RotateMode$1 || (RotateMode$1 = {}));
  11401. /**
  11402. * @public
  11403. */
  11404. class PathConstraint$1 {
  11405. static __initStatic() {this.NONE = -1;} static __initStatic2() {this.BEFORE = -2;} static __initStatic3() {this.AFTER = -3;}
  11406. static __initStatic4() {this.epsilon = 0.00001;}
  11407. __init() {this.position = 0;} __init2() {this.spacing = 0;} __init3() {this.rotateMix = 0;} __init4() {this.translateMix = 0;}
  11408. __init5() {this.spaces = new Array();} __init6() {this.positions = new Array();}
  11409. __init7() {this.world = new Array();} __init8() {this.curves = new Array();} __init9() {this.lengths = new Array();}
  11410. __init10() {this.segments = new Array();}
  11411. constructor (data, skeleton) {PathConstraint$1.prototype.__init.call(this);PathConstraint$1.prototype.__init2.call(this);PathConstraint$1.prototype.__init3.call(this);PathConstraint$1.prototype.__init4.call(this);PathConstraint$1.prototype.__init5.call(this);PathConstraint$1.prototype.__init6.call(this);PathConstraint$1.prototype.__init7.call(this);PathConstraint$1.prototype.__init8.call(this);PathConstraint$1.prototype.__init9.call(this);PathConstraint$1.prototype.__init10.call(this);
  11412. if (data == null) throw new Error("data cannot be null.");
  11413. if (skeleton == null) throw new Error("skeleton cannot be null.");
  11414. this.data = data;
  11415. this.bones = new Array();
  11416. for (let i = 0, n = data.bones.length; i < n; i++)
  11417. this.bones.push(skeleton.findBone(data.bones[i].name));
  11418. this.target = skeleton.findSlot(data.target.name);
  11419. this.position = data.position;
  11420. this.spacing = data.spacing;
  11421. this.rotateMix = data.rotateMix;
  11422. this.translateMix = data.translateMix;
  11423. }
  11424. apply () {
  11425. this.update();
  11426. }
  11427. update () {
  11428. let attachment = this.target.getAttachment();
  11429. if (!(attachment instanceof PathAttachment$1)) return;
  11430. let rotateMix = this.rotateMix, translateMix = this.translateMix;
  11431. let translate = translateMix > 0, rotate = rotateMix > 0;
  11432. if (!translate && !rotate) return;
  11433. let data = this.data;
  11434. let spacingMode = data.spacingMode;
  11435. let lengthSpacing = spacingMode == SpacingMode$1.Length;
  11436. let rotateMode = data.rotateMode;
  11437. let tangents = rotateMode == RotateMode$1.Tangent, scale = rotateMode == RotateMode$1.ChainScale;
  11438. let boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  11439. let bones = this.bones;
  11440. let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths = null;
  11441. let spacing = this.spacing;
  11442. if (scale || lengthSpacing) {
  11443. if (scale) lengths = Utils.setArraySize(this.lengths, boneCount);
  11444. for (let i = 0, n = spacesCount - 1; i < n;) {
  11445. let bone = bones[i];
  11446. let setupLength = bone.data.length;
  11447. if (setupLength < PathConstraint$1.epsilon) {
  11448. if (scale) lengths[i] = 0;
  11449. spaces[++i] = 0;
  11450. } else {
  11451. let x = setupLength * bone.matrix.a, y = setupLength * bone.matrix.b;
  11452. let length = Math.sqrt(x * x + y * y);
  11453. if (scale) lengths[i] = length;
  11454. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
  11455. }
  11456. }
  11457. } else {
  11458. for (let i = 1; i < spacesCount; i++)
  11459. spaces[i] = spacing;
  11460. }
  11461. let positions = this.computeWorldPositions(attachment, spacesCount, tangents,
  11462. data.positionMode == PositionMode$1.Percent, spacingMode == SpacingMode$1.Percent);
  11463. let boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  11464. let tip = false;
  11465. if (offsetRotation == 0)
  11466. tip = rotateMode == RotateMode$1.Chain;
  11467. else {
  11468. tip = false;
  11469. let p = this.target.bone.matrix;
  11470. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.degRad : -MathUtils.degRad;
  11471. }
  11472. for (let i = 0, p = 3; i < boneCount; i++, p += 3) {
  11473. let bone = bones[i];
  11474. let mat = bone.matrix;
  11475. mat.tx += (boneX - mat.tx) * translateMix;
  11476. mat.ty += (boneY - mat.ty) * translateMix;
  11477. let x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  11478. if (scale) {
  11479. let length = lengths[i];
  11480. if (length != 0) {
  11481. let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * rotateMix + 1;
  11482. mat.a *= s;
  11483. mat.b *= s;
  11484. }
  11485. }
  11486. boneX = x;
  11487. boneY = y;
  11488. if (rotate) {
  11489. let a = mat.a, b = mat.c, c = mat.b, d = mat.d, r = 0, cos = 0, sin = 0;
  11490. if (tangents)
  11491. r = positions[p - 1];
  11492. else if (spaces[i + 1] == 0)
  11493. r = positions[p + 2];
  11494. else
  11495. r = Math.atan2(dy, dx);
  11496. r -= Math.atan2(c, a);
  11497. if (tip) {
  11498. cos = Math.cos(r);
  11499. sin = Math.sin(r);
  11500. let length = bone.data.length;
  11501. boneX += (length * (cos * a - sin * c) - dx) * rotateMix;
  11502. boneY += (length * (sin * a + cos * c) - dy) * rotateMix;
  11503. } else {
  11504. r += offsetRotation;
  11505. }
  11506. if (r > MathUtils.PI)
  11507. r -= MathUtils.PI2;
  11508. else if (r < -MathUtils.PI) //
  11509. r += MathUtils.PI2;
  11510. r *= rotateMix;
  11511. cos = Math.cos(r);
  11512. sin = Math.sin(r);
  11513. mat.a = cos * a - sin * c;
  11514. mat.c = cos * b - sin * d;
  11515. mat.b = sin * a + cos * c;
  11516. mat.d = sin * b + cos * d;
  11517. }
  11518. bone.appliedValid = false;
  11519. }
  11520. }
  11521. computeWorldPositions (path, spacesCount, tangents, percentPosition,
  11522. percentSpacing) {
  11523. let target = this.target;
  11524. let position = this.position;
  11525. let spaces = this.spaces, out = Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  11526. let closed = path.closed;
  11527. let verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint$1.NONE;
  11528. if (!path.constantSpeed) {
  11529. let lengths = path.lengths;
  11530. curveCount -= closed ? 1 : 2;
  11531. let pathLength = lengths[curveCount];
  11532. if (percentPosition) position *= pathLength;
  11533. if (percentSpacing) {
  11534. for (let i = 0; i < spacesCount; i++)
  11535. spaces[i] *= pathLength;
  11536. }
  11537. world = Utils.setArraySize(this.world, 8);
  11538. for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  11539. let space = spaces[i];
  11540. position += space;
  11541. let p = position;
  11542. if (closed) {
  11543. p %= pathLength;
  11544. if (p < 0) p += pathLength;
  11545. curve = 0;
  11546. } else if (p < 0) {
  11547. if (prevCurve != PathConstraint$1.BEFORE) {
  11548. prevCurve = PathConstraint$1.BEFORE;
  11549. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  11550. }
  11551. this.addBeforePosition(p, world, 0, out, o);
  11552. continue;
  11553. } else if (p > pathLength) {
  11554. if (prevCurve != PathConstraint$1.AFTER) {
  11555. prevCurve = PathConstraint$1.AFTER;
  11556. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  11557. }
  11558. this.addAfterPosition(p - pathLength, world, 0, out, o);
  11559. continue;
  11560. }
  11561. // Determine curve containing position.
  11562. for (;; curve++) {
  11563. let length = lengths[curve];
  11564. if (p > length) continue;
  11565. if (curve == 0)
  11566. p /= length;
  11567. else {
  11568. let prev = lengths[curve - 1];
  11569. p = (p - prev) / (length - prev);
  11570. }
  11571. break;
  11572. }
  11573. if (curve != prevCurve) {
  11574. prevCurve = curve;
  11575. if (closed && curve == curveCount) {
  11576. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  11577. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  11578. } else
  11579. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  11580. }
  11581. this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o,
  11582. tangents || (i > 0 && space == 0));
  11583. }
  11584. return out;
  11585. }
  11586. // World vertices.
  11587. if (closed) {
  11588. verticesLength += 2;
  11589. world = Utils.setArraySize(this.world, verticesLength);
  11590. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  11591. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  11592. world[verticesLength - 2] = world[0];
  11593. world[verticesLength - 1] = world[1];
  11594. } else {
  11595. curveCount--;
  11596. verticesLength -= 4;
  11597. world = Utils.setArraySize(this.world, verticesLength);
  11598. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  11599. }
  11600. // Curve lengths.
  11601. let curves = Utils.setArraySize(this.curves, curveCount);
  11602. let pathLength = 0;
  11603. let x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  11604. let tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  11605. for (let i = 0, w = 2; i < curveCount; i++, w += 6) {
  11606. cx1 = world[w];
  11607. cy1 = world[w + 1];
  11608. cx2 = world[w + 2];
  11609. cy2 = world[w + 3];
  11610. x2 = world[w + 4];
  11611. y2 = world[w + 5];
  11612. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  11613. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  11614. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  11615. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  11616. ddfx = tmpx * 2 + dddfx;
  11617. ddfy = tmpy * 2 + dddfy;
  11618. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  11619. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  11620. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11621. dfx += ddfx;
  11622. dfy += ddfy;
  11623. ddfx += dddfx;
  11624. ddfy += dddfy;
  11625. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11626. dfx += ddfx;
  11627. dfy += ddfy;
  11628. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11629. dfx += ddfx + dddfx;
  11630. dfy += ddfy + dddfy;
  11631. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11632. curves[i] = pathLength;
  11633. x1 = x2;
  11634. y1 = y2;
  11635. }
  11636. if (percentPosition) position *= pathLength;
  11637. if (percentSpacing) {
  11638. for (let i = 0; i < spacesCount; i++)
  11639. spaces[i] *= pathLength;
  11640. }
  11641. let segments = this.segments;
  11642. let curveLength = 0;
  11643. for (let i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  11644. let space = spaces[i];
  11645. position += space;
  11646. let p = position;
  11647. if (closed) {
  11648. p %= pathLength;
  11649. if (p < 0) p += pathLength;
  11650. curve = 0;
  11651. } else if (p < 0) {
  11652. this.addBeforePosition(p, world, 0, out, o);
  11653. continue;
  11654. } else if (p > pathLength) {
  11655. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  11656. continue;
  11657. }
  11658. // Determine curve containing position.
  11659. for (;; curve++) {
  11660. let length = curves[curve];
  11661. if (p > length) continue;
  11662. if (curve == 0)
  11663. p /= length;
  11664. else {
  11665. let prev = curves[curve - 1];
  11666. p = (p - prev) / (length - prev);
  11667. }
  11668. break;
  11669. }
  11670. // Curve segment lengths.
  11671. if (curve != prevCurve) {
  11672. prevCurve = curve;
  11673. let ii = curve * 6;
  11674. x1 = world[ii];
  11675. y1 = world[ii + 1];
  11676. cx1 = world[ii + 2];
  11677. cy1 = world[ii + 3];
  11678. cx2 = world[ii + 4];
  11679. cy2 = world[ii + 5];
  11680. x2 = world[ii + 6];
  11681. y2 = world[ii + 7];
  11682. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  11683. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  11684. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  11685. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  11686. ddfx = tmpx * 2 + dddfx;
  11687. ddfy = tmpy * 2 + dddfy;
  11688. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  11689. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  11690. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  11691. segments[0] = curveLength;
  11692. for (ii = 1; ii < 8; ii++) {
  11693. dfx += ddfx;
  11694. dfy += ddfy;
  11695. ddfx += dddfx;
  11696. ddfy += dddfy;
  11697. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11698. segments[ii] = curveLength;
  11699. }
  11700. dfx += ddfx;
  11701. dfy += ddfy;
  11702. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11703. segments[8] = curveLength;
  11704. dfx += ddfx + dddfx;
  11705. dfy += ddfy + dddfy;
  11706. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  11707. segments[9] = curveLength;
  11708. segment = 0;
  11709. }
  11710. // Weight by segment length.
  11711. p *= curveLength;
  11712. for (;; segment++) {
  11713. let length = segments[segment];
  11714. if (p > length) continue;
  11715. if (segment == 0)
  11716. p /= length;
  11717. else {
  11718. let prev = segments[segment - 1];
  11719. p = segment + (p - prev) / (length - prev);
  11720. }
  11721. break;
  11722. }
  11723. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  11724. }
  11725. return out;
  11726. }
  11727. addBeforePosition (p, temp, i, out, o) {
  11728. let x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  11729. out[o] = x1 + p * Math.cos(r);
  11730. out[o + 1] = y1 + p * Math.sin(r);
  11731. out[o + 2] = r;
  11732. }
  11733. addAfterPosition (p, temp, i, out, o) {
  11734. let x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  11735. out[o] = x1 + p * Math.cos(r);
  11736. out[o + 1] = y1 + p * Math.sin(r);
  11737. out[o + 2] = r;
  11738. }
  11739. addCurvePosition (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2,
  11740. out, o, tangents) {
  11741. if (p == 0 || isNaN(p)) p = 0.0001;
  11742. let tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  11743. let ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  11744. let x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  11745. out[o] = x;
  11746. out[o + 1] = y;
  11747. if (tangents) out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  11748. }
  11749. getOrder () {
  11750. return this.data.order;
  11751. }
  11752. } PathConstraint$1.__initStatic(); PathConstraint$1.__initStatic2(); PathConstraint$1.__initStatic3(); PathConstraint$1.__initStatic4();
  11753. /**
  11754. * @public
  11755. */
  11756. class Slot$1 {
  11757. //this is canon
  11758. __init() {this.attachmentVertices = new Array();}
  11759. constructor (data, bone) {Slot$1.prototype.__init.call(this);
  11760. if (data == null) throw new Error("data cannot be null.");
  11761. if (bone == null) throw new Error("bone cannot be null.");
  11762. this.data = data;
  11763. this.bone = bone;
  11764. this.color = new Color();
  11765. this.darkColor = data.darkColor == null ? null : new Color();
  11766. this.setToSetupPose();
  11767. this.blendMode = this.data.blendMode;
  11768. }
  11769. /** @return May be null. */
  11770. getAttachment () {
  11771. return this.attachment;
  11772. }
  11773. /** Sets the attachment and if it changed, resets {@link #getAttachmentTime()} and clears {@link #getAttachmentVertices()}.
  11774. * @param attachment May be null. */
  11775. setAttachment (attachment) {
  11776. if (this.attachment == attachment) return;
  11777. this.attachment = attachment;
  11778. this.attachmentTime = this.bone.skeleton.time;
  11779. this.attachmentVertices.length = 0;
  11780. }
  11781. setAttachmentTime (time) {
  11782. this.attachmentTime = this.bone.skeleton.time - time;
  11783. }
  11784. /** Returns the time since the attachment was set. */
  11785. getAttachmentTime () {
  11786. return this.bone.skeleton.time - this.attachmentTime;
  11787. }
  11788. setToSetupPose () {
  11789. this.color.setFromColor(this.data.color);
  11790. if (this.darkColor != null) this.darkColor.setFromColor(this.data.darkColor);
  11791. if (this.data.attachmentName == null)
  11792. this.attachment = null;
  11793. else {
  11794. this.attachment = null;
  11795. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  11796. }
  11797. }
  11798. }
  11799. /**
  11800. * @public
  11801. */
  11802. class TransformConstraint$1 {
  11803. __init() {this.rotateMix = 0;}
  11804. __init2() {this.translateMix = 0;}
  11805. __init3() {this.scaleMix = 0;}
  11806. __init4() {this.shearMix = 0;}
  11807. __init5() {this.temp = new Vector2();}
  11808. constructor(data, skeleton) {TransformConstraint$1.prototype.__init.call(this);TransformConstraint$1.prototype.__init2.call(this);TransformConstraint$1.prototype.__init3.call(this);TransformConstraint$1.prototype.__init4.call(this);TransformConstraint$1.prototype.__init5.call(this);
  11809. if (data == null) throw new Error("data cannot be null.");
  11810. if (skeleton == null) throw new Error("skeleton cannot be null.");
  11811. this.data = data;
  11812. this.rotateMix = data.rotateMix;
  11813. this.translateMix = data.translateMix;
  11814. this.scaleMix = data.scaleMix;
  11815. this.shearMix = data.shearMix;
  11816. this.bones = new Array();
  11817. for (let i = 0; i < data.bones.length; i++)
  11818. this.bones.push(skeleton.findBone(data.bones[i].name));
  11819. this.target = skeleton.findBone(data.target.name);
  11820. }
  11821. apply() {
  11822. this.update();
  11823. }
  11824. update() {
  11825. if (this.data.local) {
  11826. if (this.data.relative)
  11827. this.applyRelativeLocal();
  11828. else
  11829. this.applyAbsoluteLocal();
  11830. } else {
  11831. if (this.data.relative)
  11832. this.applyRelativeWorld();
  11833. else
  11834. this.applyAbsoluteWorld();
  11835. }
  11836. }
  11837. applyAbsoluteWorld() {
  11838. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  11839. shearMix = this.shearMix;
  11840. let target = this.target;
  11841. let targetMat = target.matrix;
  11842. let ta = targetMat.a, tb = targetMat.c, tc = targetMat.b, td = targetMat.d;
  11843. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  11844. let offsetRotation = this.data.offsetRotation * degRadReflect;
  11845. let offsetShearY = this.data.offsetShearY * degRadReflect;
  11846. let bones = this.bones;
  11847. for (let i = 0, n = bones.length; i < n; i++) {
  11848. let bone = bones[i];
  11849. let modified = false;
  11850. let mat = bone.matrix;
  11851. if (rotateMix != 0) {
  11852. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  11853. let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  11854. if (r > MathUtils.PI)
  11855. r -= MathUtils.PI2;
  11856. else if (r < -MathUtils.PI)
  11857. r += MathUtils.PI2;
  11858. r *= rotateMix;
  11859. let cos = Math.cos(r), sin = Math.sin(r);
  11860. mat.a = cos * a - sin * c;
  11861. mat.c = cos * b - sin * d;
  11862. mat.b = sin * a + cos * c;
  11863. mat.d = sin * b + cos * d;
  11864. modified = true;
  11865. }
  11866. if (translateMix != 0) {
  11867. let temp = this.temp;
  11868. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  11869. mat.tx += (temp.x - mat.tx) * translateMix;
  11870. mat.ty += (temp.y - mat.ty) * translateMix;
  11871. modified = true;
  11872. }
  11873. if (scaleMix > 0) {
  11874. let s = Math.sqrt(mat.a * mat.a + mat.b * mat.b);
  11875. let ts = Math.sqrt(ta * ta + tc * tc);
  11876. if (s > 0.00001) s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
  11877. mat.a *= s;
  11878. mat.b *= s;
  11879. s = Math.sqrt(mat.c * mat.c + mat.d * mat.d);
  11880. ts = Math.sqrt(tb * tb + td * td);
  11881. if (s > 0.00001) s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
  11882. mat.c *= s;
  11883. mat.d *= s;
  11884. modified = true;
  11885. }
  11886. if (shearMix > 0) {
  11887. let b = mat.c, d = mat.d;
  11888. let by = Math.atan2(d, b);
  11889. let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(mat.b, mat.a));
  11890. if (r > MathUtils.PI)
  11891. r -= MathUtils.PI2;
  11892. else if (r < -MathUtils.PI)
  11893. r += MathUtils.PI2;
  11894. r = by + (r + offsetShearY) * shearMix;
  11895. let s = Math.sqrt(b * b + d * d);
  11896. mat.c = Math.cos(r) * s;
  11897. mat.d = Math.sin(r) * s;
  11898. modified = true;
  11899. }
  11900. if (modified) bone.appliedValid = false;
  11901. }
  11902. }
  11903. applyRelativeWorld() {
  11904. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  11905. shearMix = this.shearMix;
  11906. let target = this.target;
  11907. let targetMat = target.matrix;
  11908. let ta = targetMat.a, tb = targetMat.c, tc = targetMat.b, td = targetMat.d;
  11909. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  11910. let offsetRotation = this.data.offsetRotation * degRadReflect,
  11911. offsetShearY = this.data.offsetShearY * degRadReflect;
  11912. let bones = this.bones;
  11913. for (let i = 0, n = bones.length; i < n; i++) {
  11914. let bone = bones[i];
  11915. let modified = false;
  11916. let mat = bone.matrix;
  11917. if (rotateMix != 0) {
  11918. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  11919. let r = Math.atan2(tc, ta) + offsetRotation;
  11920. if (r > MathUtils.PI)
  11921. r -= MathUtils.PI2;
  11922. else if (r < -MathUtils.PI) r += MathUtils.PI2;
  11923. r *= rotateMix;
  11924. let cos = Math.cos(r), sin = Math.sin(r);
  11925. mat.a = cos * a - sin * c;
  11926. mat.c = cos * b - sin * d;
  11927. mat.b = sin * a + cos * c;
  11928. mat.d = sin * b + cos * d;
  11929. modified = true;
  11930. }
  11931. if (translateMix != 0) {
  11932. let temp = this.temp;
  11933. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  11934. mat.tx += temp.x * translateMix;
  11935. mat.ty += temp.y * translateMix;
  11936. modified = true;
  11937. }
  11938. if (scaleMix > 0) {
  11939. let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
  11940. mat.a *= s;
  11941. mat.b *= s;
  11942. s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
  11943. mat.c *= s;
  11944. mat.d *= s;
  11945. modified = true;
  11946. }
  11947. if (shearMix > 0) {
  11948. let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  11949. if (r > MathUtils.PI)
  11950. r -= MathUtils.PI2;
  11951. else if (r < -MathUtils.PI) r += MathUtils.PI2;
  11952. let b = mat.c, d = mat.d;
  11953. r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * shearMix;
  11954. let s = Math.sqrt(b * b + d * d);
  11955. mat.c = Math.cos(r) * s;
  11956. mat.d = Math.sin(r) * s;
  11957. modified = true;
  11958. }
  11959. if (modified) bone.appliedValid = false;
  11960. }
  11961. }
  11962. applyAbsoluteLocal() {
  11963. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  11964. shearMix = this.shearMix;
  11965. let target = this.target;
  11966. if (!target.appliedValid) target.updateAppliedTransform();
  11967. let bones = this.bones;
  11968. for (let i = 0, n = bones.length; i < n; i++) {
  11969. let bone = bones[i];
  11970. if (!bone.appliedValid) bone.updateAppliedTransform();
  11971. let rotation = bone.arotation;
  11972. if (rotateMix != 0) {
  11973. let r = target.arotation - rotation + this.data.offsetRotation;
  11974. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  11975. rotation += r * rotateMix;
  11976. }
  11977. let x = bone.ax, y = bone.ay;
  11978. if (translateMix != 0) {
  11979. x += (target.ax - x + this.data.offsetX) * translateMix;
  11980. y += (target.ay - y + this.data.offsetY) * translateMix;
  11981. }
  11982. let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  11983. if (scaleMix > 0) {
  11984. if (scaleX > 0.00001) scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
  11985. if (scaleY > 0.00001) scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
  11986. }
  11987. let shearY = bone.ashearY;
  11988. if (shearMix > 0) {
  11989. let r = target.ashearY - shearY + this.data.offsetShearY;
  11990. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  11991. bone.shearY += r * shearMix;
  11992. }
  11993. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  11994. }
  11995. }
  11996. applyRelativeLocal() {
  11997. let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix,
  11998. shearMix = this.shearMix;
  11999. let target = this.target;
  12000. if (!target.appliedValid) target.updateAppliedTransform();
  12001. let bones = this.bones;
  12002. for (let i = 0, n = bones.length; i < n; i++) {
  12003. let bone = bones[i];
  12004. if (!bone.appliedValid) bone.updateAppliedTransform();
  12005. let rotation = bone.arotation;
  12006. if (rotateMix != 0) rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
  12007. let x = bone.ax, y = bone.ay;
  12008. if (translateMix != 0) {
  12009. x += (target.ax + this.data.offsetX) * translateMix;
  12010. y += (target.ay + this.data.offsetY) * translateMix;
  12011. }
  12012. let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  12013. if (scaleMix > 0) {
  12014. if (scaleX > 0.00001) scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
  12015. if (scaleY > 0.00001) scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
  12016. }
  12017. let shearY = bone.ashearY;
  12018. if (shearMix > 0) shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
  12019. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  12020. }
  12021. }
  12022. getOrder() {
  12023. return this.data.order;
  12024. }
  12025. }
  12026. /**
  12027. * @public
  12028. */
  12029. class Skeleton$1 {
  12030. __init() {this._updateCache = new Array();}
  12031. __init2() {this.updateCacheReset = new Array();}
  12032. __init3() {this.time = 0;}
  12033. __init4() {this.scaleX = 1;} __init5() {this.scaleY = 1;}
  12034. __init6() {this.x = 0;} __init7() {this.y = 0;}
  12035. constructor (data) {Skeleton$1.prototype.__init.call(this);Skeleton$1.prototype.__init2.call(this);Skeleton$1.prototype.__init3.call(this);Skeleton$1.prototype.__init4.call(this);Skeleton$1.prototype.__init5.call(this);Skeleton$1.prototype.__init6.call(this);Skeleton$1.prototype.__init7.call(this);
  12036. if (data == null) throw new Error("data cannot be null.");
  12037. this.data = data;
  12038. this.bones = new Array();
  12039. for (let i = 0; i < data.bones.length; i++) {
  12040. let boneData = data.bones[i];
  12041. let bone;
  12042. if (boneData.parent == null)
  12043. bone = new Bone$1(boneData, this, null);
  12044. else {
  12045. let parent = this.bones[boneData.parent.index];
  12046. bone = new Bone$1(boneData, this, parent);
  12047. parent.children.push(bone);
  12048. }
  12049. this.bones.push(bone);
  12050. }
  12051. this.slots = new Array();
  12052. this.drawOrder = new Array();
  12053. for (let i = 0; i < data.slots.length; i++) {
  12054. let slotData = data.slots[i];
  12055. let bone = this.bones[slotData.boneData.index];
  12056. let slot = new Slot$1(slotData, bone);
  12057. this.slots.push(slot);
  12058. this.drawOrder.push(slot);
  12059. }
  12060. this.ikConstraints = new Array();
  12061. for (let i = 0; i < data.ikConstraints.length; i++) {
  12062. let ikConstraintData = data.ikConstraints[i];
  12063. this.ikConstraints.push(new IkConstraint$1(ikConstraintData, this));
  12064. }
  12065. this.transformConstraints = new Array();
  12066. for (let i = 0; i < data.transformConstraints.length; i++) {
  12067. let transformConstraintData = data.transformConstraints[i];
  12068. this.transformConstraints.push(new TransformConstraint$1(transformConstraintData, this));
  12069. }
  12070. this.pathConstraints = new Array();
  12071. for (let i = 0; i < data.pathConstraints.length; i++) {
  12072. let pathConstraintData = data.pathConstraints[i];
  12073. this.pathConstraints.push(new PathConstraint$1(pathConstraintData, this));
  12074. }
  12075. this.color = new Color(1, 1, 1, 1);
  12076. this.updateCache();
  12077. }
  12078. updateCache () {
  12079. let updateCache = this._updateCache;
  12080. updateCache.length = 0;
  12081. this.updateCacheReset.length = 0;
  12082. let bones = this.bones;
  12083. for (let i = 0, n = bones.length; i < n; i++)
  12084. bones[i].sorted = false;
  12085. // IK first, lowest hierarchy depth first.
  12086. let ikConstraints = this.ikConstraints;
  12087. let transformConstraints = this.transformConstraints;
  12088. let pathConstraints = this.pathConstraints;
  12089. let ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  12090. let constraintCount = ikCount + transformCount + pathCount;
  12091. outer:
  12092. for (let i = 0; i < constraintCount; i++) {
  12093. for (let ii = 0; ii < ikCount; ii++) {
  12094. let constraint = ikConstraints[ii];
  12095. if (constraint.data.order == i) {
  12096. this.sortIkConstraint(constraint);
  12097. continue outer;
  12098. }
  12099. }
  12100. for (let ii = 0; ii < transformCount; ii++) {
  12101. let constraint = transformConstraints[ii];
  12102. if (constraint.data.order == i) {
  12103. this.sortTransformConstraint(constraint);
  12104. continue outer;
  12105. }
  12106. }
  12107. for (let ii = 0; ii < pathCount; ii++) {
  12108. let constraint = pathConstraints[ii];
  12109. if (constraint.data.order == i) {
  12110. this.sortPathConstraint(constraint);
  12111. continue outer;
  12112. }
  12113. }
  12114. }
  12115. for (let i = 0, n = bones.length; i < n; i++)
  12116. this.sortBone(bones[i]);
  12117. }
  12118. sortIkConstraint (constraint) {
  12119. let target = constraint.target;
  12120. this.sortBone(target);
  12121. let constrained = constraint.bones;
  12122. let parent = constrained[0];
  12123. this.sortBone(parent);
  12124. if (constrained.length > 1) {
  12125. let child = constrained[constrained.length - 1];
  12126. if (!(this._updateCache.indexOf(child) > -1)) this.updateCacheReset.push(child);
  12127. }
  12128. this._updateCache.push(constraint);
  12129. this.sortReset(parent.children);
  12130. constrained[constrained.length - 1].sorted = true;
  12131. }
  12132. sortPathConstraint (constraint) {
  12133. let slot = constraint.target;
  12134. let slotIndex = slot.data.index;
  12135. let slotBone = slot.bone;
  12136. if (this.skin != null) this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  12137. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  12138. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  12139. for (let i = 0, n = this.data.skins.length; i < n; i++)
  12140. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  12141. let attachment = slot.getAttachment();
  12142. if (attachment instanceof PathAttachment$1) this.sortPathConstraintAttachmentWith(attachment, slotBone);
  12143. let constrained = constraint.bones;
  12144. let boneCount = constrained.length;
  12145. for (let i = 0; i < boneCount; i++)
  12146. this.sortBone(constrained[i]);
  12147. this._updateCache.push(constraint);
  12148. for (let i = 0; i < boneCount; i++)
  12149. this.sortReset(constrained[i].children);
  12150. for (let i = 0; i < boneCount; i++)
  12151. constrained[i].sorted = true;
  12152. }
  12153. sortTransformConstraint (constraint) {
  12154. this.sortBone(constraint.target);
  12155. let constrained = constraint.bones;
  12156. let boneCount = constrained.length;
  12157. if (constraint.data.local) {
  12158. for (let i = 0; i < boneCount; i++) {
  12159. let child = constrained[i];
  12160. this.sortBone(child.parent);
  12161. if (!(this._updateCache.indexOf(child) > -1)) this.updateCacheReset.push(child);
  12162. }
  12163. } else {
  12164. for (let i = 0; i < boneCount; i++) {
  12165. this.sortBone(constrained[i]);
  12166. }
  12167. }
  12168. this._updateCache.push(constraint);
  12169. for (let ii = 0; ii < boneCount; ii++)
  12170. this.sortReset(constrained[ii].children);
  12171. for (let ii = 0; ii < boneCount; ii++)
  12172. constrained[ii].sorted = true;
  12173. }
  12174. sortPathConstraintAttachment (skin, slotIndex, slotBone) {
  12175. let attachments = skin.attachments[slotIndex];
  12176. if (!attachments) return;
  12177. for (let key in attachments) {
  12178. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  12179. }
  12180. }
  12181. sortPathConstraintAttachmentWith (attachment, slotBone) {
  12182. if (!(attachment instanceof PathAttachment$1)) return;
  12183. let pathBones = (attachment).bones;
  12184. if (pathBones == null)
  12185. this.sortBone(slotBone);
  12186. else {
  12187. let bones = this.bones;
  12188. let i = 0;
  12189. while (i < pathBones.length) {
  12190. let boneCount = pathBones[i++];
  12191. for (let n = i + boneCount; i < n; i++) {
  12192. let boneIndex = pathBones[i];
  12193. this.sortBone(bones[boneIndex]);
  12194. }
  12195. }
  12196. }
  12197. }
  12198. sortBone (bone) {
  12199. if (bone.sorted) return;
  12200. let parent = bone.parent;
  12201. if (parent != null) this.sortBone(parent);
  12202. bone.sorted = true;
  12203. this._updateCache.push(bone);
  12204. }
  12205. sortReset (bones) {
  12206. for (let i = 0, n = bones.length; i < n; i++) {
  12207. let bone = bones[i];
  12208. if (bone.sorted) this.sortReset(bone.children);
  12209. bone.sorted = false;
  12210. }
  12211. }
  12212. /** Updates the world transform for each bone and applies constraints. */
  12213. updateWorldTransform () {
  12214. let updateCacheReset = this.updateCacheReset;
  12215. for (let i = 0, n = updateCacheReset.length; i < n; i++) {
  12216. let bone = updateCacheReset[i] ;
  12217. bone.ax = bone.x;
  12218. bone.ay = bone.y;
  12219. bone.arotation = bone.rotation;
  12220. bone.ascaleX = bone.scaleX;
  12221. bone.ascaleY = bone.scaleY;
  12222. bone.ashearX = bone.shearX;
  12223. bone.ashearY = bone.shearY;
  12224. bone.appliedValid = true;
  12225. }
  12226. let updateCache = this._updateCache;
  12227. for (let i = 0, n = updateCache.length; i < n; i++)
  12228. updateCache[i].update();
  12229. }
  12230. /** Sets the bones, constraints, and slots to their setup pose values. */
  12231. setToSetupPose () {
  12232. this.setBonesToSetupPose();
  12233. this.setSlotsToSetupPose();
  12234. }
  12235. /** Sets the bones and constraints to their setup pose values. */
  12236. setBonesToSetupPose () {
  12237. let bones = this.bones;
  12238. for (let i = 0, n = bones.length; i < n; i++)
  12239. bones[i].setToSetupPose();
  12240. let ikConstraints = this.ikConstraints;
  12241. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  12242. let constraint = ikConstraints[i];
  12243. constraint.bendDirection = constraint.data.bendDirection;
  12244. constraint.mix = constraint.data.mix;
  12245. }
  12246. let transformConstraints = this.transformConstraints;
  12247. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  12248. let constraint = transformConstraints[i];
  12249. let data = constraint.data;
  12250. constraint.rotateMix = data.rotateMix;
  12251. constraint.translateMix = data.translateMix;
  12252. constraint.scaleMix = data.scaleMix;
  12253. constraint.shearMix = data.shearMix;
  12254. }
  12255. let pathConstraints = this.pathConstraints;
  12256. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  12257. let constraint = pathConstraints[i];
  12258. let data = constraint.data;
  12259. constraint.position = data.position;
  12260. constraint.spacing = data.spacing;
  12261. constraint.rotateMix = data.rotateMix;
  12262. constraint.translateMix = data.translateMix;
  12263. }
  12264. }
  12265. setSlotsToSetupPose () {
  12266. let slots = this.slots;
  12267. Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  12268. for (let i = 0, n = slots.length; i < n; i++)
  12269. slots[i].setToSetupPose();
  12270. }
  12271. /** @return May return null. */
  12272. getRootBone () {
  12273. if (this.bones.length == 0) return null;
  12274. return this.bones[0];
  12275. }
  12276. /** @return May be null. */
  12277. findBone (boneName) {
  12278. if (boneName == null) throw new Error("boneName cannot be null.");
  12279. let bones = this.bones;
  12280. for (let i = 0, n = bones.length; i < n; i++) {
  12281. let bone = bones[i];
  12282. if (bone.data.name == boneName) return bone;
  12283. }
  12284. return null;
  12285. }
  12286. /** @return -1 if the bone was not found. */
  12287. findBoneIndex (boneName) {
  12288. if (boneName == null) throw new Error("boneName cannot be null.");
  12289. let bones = this.bones;
  12290. for (let i = 0, n = bones.length; i < n; i++)
  12291. if (bones[i].data.name == boneName) return i;
  12292. return -1;
  12293. }
  12294. /** @return May be null. */
  12295. findSlot (slotName) {
  12296. if (slotName == null) throw new Error("slotName cannot be null.");
  12297. let slots = this.slots;
  12298. for (let i = 0, n = slots.length; i < n; i++) {
  12299. let slot = slots[i];
  12300. if (slot.data.name == slotName) return slot;
  12301. }
  12302. return null;
  12303. }
  12304. /** @return -1 if the bone was not found. */
  12305. findSlotIndex (slotName) {
  12306. if (slotName == null) throw new Error("slotName cannot be null.");
  12307. let slots = this.slots;
  12308. for (let i = 0, n = slots.length; i < n; i++)
  12309. if (slots[i].data.name == slotName) return i;
  12310. return -1;
  12311. }
  12312. /** Sets a skin by name.
  12313. * @see #setSkin(Skin) */
  12314. setSkinByName (skinName) {
  12315. let skin = this.data.findSkin(skinName);
  12316. if (skin == null) throw new Error("Skin not found: " + skinName);
  12317. this.setSkin(skin);
  12318. }
  12319. /** Sets the skin used to look up attachments before looking in the {@link SkeletonData#getDefaultSkin() default skin}.
  12320. * Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. If there was no
  12321. * old skin, each slot's setup mode attachment is attached from the new skin.
  12322. * @param newSkin May be null. */
  12323. setSkin (newSkin) {
  12324. if (newSkin != null) {
  12325. if (this.skin != null)
  12326. newSkin.attachAll(this, this.skin);
  12327. else {
  12328. let slots = this.slots;
  12329. for (let i = 0, n = slots.length; i < n; i++) {
  12330. let slot = slots[i];
  12331. let name = slot.data.attachmentName;
  12332. if (name != null) {
  12333. let attachment = newSkin.getAttachment(i, name);
  12334. if (attachment != null) slot.setAttachment(attachment);
  12335. }
  12336. }
  12337. }
  12338. }
  12339. this.skin = newSkin;
  12340. }
  12341. /** @return May be null. */
  12342. getAttachmentByName (slotName, attachmentName) {
  12343. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  12344. }
  12345. /** @return May be null. */
  12346. getAttachment (slotIndex, attachmentName) {
  12347. if (attachmentName == null) throw new Error("attachmentName cannot be null.");
  12348. if (this.skin != null) {
  12349. let attachment = this.skin.getAttachment(slotIndex, attachmentName);
  12350. if (attachment != null) return attachment;
  12351. }
  12352. if (this.data.defaultSkin != null) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  12353. return null;
  12354. }
  12355. /** @param attachmentName May be null. */
  12356. setAttachment (slotName, attachmentName) {
  12357. if (slotName == null) throw new Error("slotName cannot be null.");
  12358. let slots = this.slots;
  12359. for (let i = 0, n = slots.length; i < n; i++) {
  12360. let slot = slots[i];
  12361. if (slot.data.name == slotName) {
  12362. let attachment = null;
  12363. if (attachmentName != null) {
  12364. attachment = this.getAttachment(i, attachmentName);
  12365. if (attachment == null)
  12366. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  12367. }
  12368. slot.setAttachment(attachment);
  12369. return;
  12370. }
  12371. }
  12372. throw new Error("Slot not found: " + slotName);
  12373. }
  12374. /** @return May be null. */
  12375. findIkConstraint (constraintName) {
  12376. if (constraintName == null) throw new Error("constraintName cannot be null.");
  12377. let ikConstraints = this.ikConstraints;
  12378. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  12379. let ikConstraint = ikConstraints[i];
  12380. if (ikConstraint.data.name == constraintName) return ikConstraint;
  12381. }
  12382. return null;
  12383. }
  12384. /** @return May be null. */
  12385. findTransformConstraint (constraintName) {
  12386. if (constraintName == null) throw new Error("constraintName cannot be null.");
  12387. let transformConstraints = this.transformConstraints;
  12388. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  12389. let constraint = transformConstraints[i];
  12390. if (constraint.data.name == constraintName) return constraint;
  12391. }
  12392. return null;
  12393. }
  12394. /** @return May be null. */
  12395. findPathConstraint (constraintName) {
  12396. if (constraintName == null) throw new Error("constraintName cannot be null.");
  12397. let pathConstraints = this.pathConstraints;
  12398. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  12399. let constraint = pathConstraints[i];
  12400. if (constraint.data.name == constraintName) return constraint;
  12401. }
  12402. return null;
  12403. }
  12404. /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
  12405. * @param offset The distance from the skeleton origin to the bottom left corner of the AABB.
  12406. * @param size The width and height of the AABB.
  12407. * @param temp Working memory */
  12408. getBounds (offset, size, temp) {
  12409. if (offset == null) throw new Error("offset cannot be null.");
  12410. if (size == null) throw new Error("size cannot be null.");
  12411. let drawOrder = this.drawOrder;
  12412. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  12413. for (let i = 0, n = drawOrder.length; i < n; i++) {
  12414. let slot = drawOrder[i];
  12415. let verticesLength = 0;
  12416. let vertices = null;
  12417. let attachment = slot.getAttachment();
  12418. if (attachment instanceof RegionAttachment$1) {
  12419. verticesLength = 8;
  12420. vertices = Utils.setArraySize(temp, verticesLength, 0);
  12421. (attachment).computeWorldVertices(slot.bone, vertices, 0, 2);
  12422. } else if (attachment instanceof MeshAttachment$1) {
  12423. let mesh = (attachment);
  12424. verticesLength = mesh.worldVerticesLength;
  12425. vertices = Utils.setArraySize(temp, verticesLength, 0);
  12426. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  12427. }
  12428. if (vertices != null) {
  12429. for (let ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  12430. let x = vertices[ii], y = vertices[ii + 1];
  12431. minX = Math.min(minX, x);
  12432. minY = Math.min(minY, y);
  12433. maxX = Math.max(maxX, x);
  12434. maxY = Math.max(maxY, y);
  12435. }
  12436. }
  12437. }
  12438. offset.set(minX, minY);
  12439. size.set(maxX - minX, maxY - minY);
  12440. }
  12441. update (delta) {
  12442. this.time += delta;
  12443. }
  12444. get flipX() {
  12445. return this.scaleX == -1;
  12446. }
  12447. set flipX(value) {
  12448. if (!Skeleton$1.deprecatedWarning1) {
  12449. Skeleton$1.deprecatedWarning1 = true;
  12450. console.warn("Spine Deprecation Warning: `Skeleton.flipX/flipY` was deprecated, please use scaleX/scaleY");
  12451. }
  12452. this.scaleX = value ? 1.0 : -1.0;
  12453. }
  12454. get flipY() {
  12455. return this.scaleY == -1;
  12456. }
  12457. set flipY(value) {
  12458. if (!Skeleton$1.deprecatedWarning1) {
  12459. Skeleton$1.deprecatedWarning1 = true;
  12460. console.warn("Spine Deprecation Warning: `Skeleton.flipX/flipY` was deprecated, please use scaleX/scaleY");
  12461. }
  12462. this.scaleY = value ? 1.0 : -1.0;
  12463. }
  12464. static __initStatic() {this.deprecatedWarning1 = false;}
  12465. } Skeleton$1.__initStatic();
  12466. /**
  12467. * @public
  12468. */
  12469. class SkeletonBounds$1 {constructor() { SkeletonBounds$1.prototype.__init.call(this);SkeletonBounds$1.prototype.__init2.call(this);SkeletonBounds$1.prototype.__init3.call(this);SkeletonBounds$1.prototype.__init4.call(this);SkeletonBounds$1.prototype.__init5.call(this);SkeletonBounds$1.prototype.__init6.call(this);SkeletonBounds$1.prototype.__init7.call(this); }
  12470. __init() {this.minX = 0;} __init2() {this.minY = 0;} __init3() {this.maxX = 0;} __init4() {this.maxY = 0;}
  12471. __init5() {this.boundingBoxes = new Array();}
  12472. __init6() {this.polygons = new Array();}
  12473. __init7() {this.polygonPool = new Pool(() => {
  12474. return Utils.newFloatArray(16);
  12475. });}
  12476. update (skeleton, updateAabb) {
  12477. if (skeleton == null) throw new Error("skeleton cannot be null.");
  12478. let boundingBoxes = this.boundingBoxes;
  12479. let polygons = this.polygons;
  12480. let polygonPool = this.polygonPool;
  12481. let slots = skeleton.slots;
  12482. let slotCount = slots.length;
  12483. boundingBoxes.length = 0;
  12484. polygonPool.freeAll(polygons);
  12485. polygons.length = 0;
  12486. for (let i = 0; i < slotCount; i++) {
  12487. let slot = slots[i];
  12488. let attachment = slot.getAttachment();
  12489. if (attachment instanceof BoundingBoxAttachment$1) {
  12490. let boundingBox = attachment ;
  12491. boundingBoxes.push(boundingBox);
  12492. let polygon = polygonPool.obtain();
  12493. if (polygon.length != boundingBox.worldVerticesLength) {
  12494. polygon = Utils.newFloatArray(boundingBox.worldVerticesLength);
  12495. }
  12496. polygons.push(polygon);
  12497. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  12498. }
  12499. }
  12500. if (updateAabb) {
  12501. this.aabbCompute();
  12502. } else {
  12503. this.minX = Number.POSITIVE_INFINITY;
  12504. this.minY = Number.POSITIVE_INFINITY;
  12505. this.maxX = Number.NEGATIVE_INFINITY;
  12506. this.maxY = Number.NEGATIVE_INFINITY;
  12507. }
  12508. }
  12509. aabbCompute () {
  12510. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  12511. let polygons = this.polygons;
  12512. for (let i = 0, n = polygons.length; i < n; i++) {
  12513. let polygon = polygons[i];
  12514. let vertices = polygon;
  12515. for (let ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  12516. let x = vertices[ii];
  12517. let y = vertices[ii + 1];
  12518. minX = Math.min(minX, x);
  12519. minY = Math.min(minY, y);
  12520. maxX = Math.max(maxX, x);
  12521. maxY = Math.max(maxY, y);
  12522. }
  12523. }
  12524. this.minX = minX;
  12525. this.minY = minY;
  12526. this.maxX = maxX;
  12527. this.maxY = maxY;
  12528. }
  12529. /** Returns true if the axis aligned bounding box contains the point. */
  12530. aabbContainsPoint (x, y) {
  12531. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  12532. }
  12533. /** Returns true if the axis aligned bounding box intersects the line segment. */
  12534. aabbIntersectsSegment (x1, y1, x2, y2) {
  12535. let minX = this.minX;
  12536. let minY = this.minY;
  12537. let maxX = this.maxX;
  12538. let maxY = this.maxY;
  12539. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  12540. return false;
  12541. let m = (y2 - y1) / (x2 - x1);
  12542. let y = m * (minX - x1) + y1;
  12543. if (y > minY && y < maxY) return true;
  12544. y = m * (maxX - x1) + y1;
  12545. if (y > minY && y < maxY) return true;
  12546. let x = (minY - y1) / m + x1;
  12547. if (x > minX && x < maxX) return true;
  12548. x = (maxY - y1) / m + x1;
  12549. if (x > minX && x < maxX) return true;
  12550. return false;
  12551. }
  12552. /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */
  12553. aabbIntersectsSkeleton (bounds) {
  12554. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  12555. }
  12556. /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more
  12557. * efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */
  12558. containsPoint (x, y) {
  12559. let polygons = this.polygons;
  12560. for (let i = 0, n = polygons.length; i < n; i++)
  12561. if (this.containsPointPolygon(polygons[i], x, y)) return this.boundingBoxes[i];
  12562. return null;
  12563. }
  12564. /** Returns true if the polygon contains the point. */
  12565. containsPointPolygon (polygon, x, y) {
  12566. let vertices = polygon;
  12567. let nn = polygon.length;
  12568. let prevIndex = nn - 2;
  12569. let inside = false;
  12570. for (let ii = 0; ii < nn; ii += 2) {
  12571. let vertexY = vertices[ii + 1];
  12572. let prevY = vertices[prevIndex + 1];
  12573. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  12574. let vertexX = vertices[ii];
  12575. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) inside = !inside;
  12576. }
  12577. prevIndex = ii;
  12578. }
  12579. return inside;
  12580. }
  12581. /** Returns the first bounding box attachment that contains any part of the line segment, or null. When doing many checks, it
  12582. * is usually more efficient to only call this method if {@link #aabbIntersectsSegment(float, float, float, float)} returns
  12583. * true. */
  12584. intersectsSegment (x1, y1, x2, y2) {
  12585. let polygons = this.polygons;
  12586. for (let i = 0, n = polygons.length; i < n; i++)
  12587. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2)) return this.boundingBoxes[i];
  12588. return null;
  12589. }
  12590. /** Returns true if the polygon contains any part of the line segment. */
  12591. intersectsSegmentPolygon (polygon, x1, y1, x2, y2) {
  12592. let vertices = polygon;
  12593. let nn = polygon.length;
  12594. let width12 = x1 - x2, height12 = y1 - y2;
  12595. let det1 = x1 * y2 - y1 * x2;
  12596. let x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  12597. for (let ii = 0; ii < nn; ii += 2) {
  12598. let x4 = vertices[ii], y4 = vertices[ii + 1];
  12599. let det2 = x3 * y4 - y3 * x4;
  12600. let width34 = x3 - x4, height34 = y3 - y4;
  12601. let det3 = width12 * height34 - height12 * width34;
  12602. let x = (det1 * width34 - width12 * det2) / det3;
  12603. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  12604. let y = (det1 * height34 - height12 * det2) / det3;
  12605. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) return true;
  12606. }
  12607. x3 = x4;
  12608. y3 = y4;
  12609. }
  12610. return false;
  12611. }
  12612. /** Returns the polygon for the specified bounding box, or null. */
  12613. getPolygon (boundingBox) {
  12614. if (boundingBox == null) throw new Error("boundingBox cannot be null.");
  12615. let index = this.boundingBoxes.indexOf(boundingBox);
  12616. return index == -1 ? null : this.polygons[index];
  12617. }
  12618. getWidth () {
  12619. return this.maxX - this.minX;
  12620. }
  12621. getHeight () {
  12622. return this.maxY - this.minY;
  12623. }
  12624. }
  12625. /**
  12626. * @public
  12627. */
  12628. class SkeletonData$1 {constructor() { SkeletonData$1.prototype.__init.call(this);SkeletonData$1.prototype.__init2.call(this);SkeletonData$1.prototype.__init3.call(this);SkeletonData$1.prototype.__init4.call(this);SkeletonData$1.prototype.__init5.call(this);SkeletonData$1.prototype.__init6.call(this);SkeletonData$1.prototype.__init7.call(this);SkeletonData$1.prototype.__init8.call(this);SkeletonData$1.prototype.__init9.call(this); }
  12629. __init() {this.bones = new Array();} // Ordered parents first.
  12630. __init2() {this.slots = new Array();} // Setup pose draw order.
  12631. __init3() {this.skins = new Array();}
  12632. __init4() {this.events = new Array();}
  12633. __init5() {this.animations = new Array();}
  12634. __init6() {this.ikConstraints = new Array();}
  12635. __init7() {this.transformConstraints = new Array();}
  12636. __init8() {this.pathConstraints = new Array();}
  12637. // Nonessential
  12638. __init9() {this.fps = 0;}
  12639. findBone(boneName) {
  12640. if (boneName == null) throw new Error("boneName cannot be null.");
  12641. let bones = this.bones;
  12642. for (let i = 0, n = bones.length; i < n; i++) {
  12643. let bone = bones[i];
  12644. if (bone.name == boneName) return bone;
  12645. }
  12646. return null;
  12647. }
  12648. findBoneIndex(boneName) {
  12649. if (boneName == null) throw new Error("boneName cannot be null.");
  12650. let bones = this.bones;
  12651. for (let i = 0, n = bones.length; i < n; i++)
  12652. if (bones[i].name == boneName) return i;
  12653. return -1;
  12654. }
  12655. findSlot(slotName) {
  12656. if (slotName == null) throw new Error("slotName cannot be null.");
  12657. let slots = this.slots;
  12658. for (let i = 0, n = slots.length; i < n; i++) {
  12659. let slot = slots[i];
  12660. if (slot.name == slotName) return slot;
  12661. }
  12662. return null;
  12663. }
  12664. findSlotIndex(slotName) {
  12665. if (slotName == null) throw new Error("slotName cannot be null.");
  12666. let slots = this.slots;
  12667. for (let i = 0, n = slots.length; i < n; i++)
  12668. if (slots[i].name == slotName) return i;
  12669. return -1;
  12670. }
  12671. findSkin(skinName) {
  12672. if (skinName == null) throw new Error("skinName cannot be null.");
  12673. let skins = this.skins;
  12674. for (let i = 0, n = skins.length; i < n; i++) {
  12675. let skin = skins[i];
  12676. if (skin.name == skinName) return skin;
  12677. }
  12678. return null;
  12679. }
  12680. findEvent(eventDataName) {
  12681. if (eventDataName == null) throw new Error("eventDataName cannot be null.");
  12682. let events = this.events;
  12683. for (let i = 0, n = events.length; i < n; i++) {
  12684. let event = events[i];
  12685. if (event.name == eventDataName) return event;
  12686. }
  12687. return null;
  12688. }
  12689. findAnimation(animationName) {
  12690. if (animationName == null) throw new Error("animationName cannot be null.");
  12691. let animations = this.animations;
  12692. for (let i = 0, n = animations.length; i < n; i++) {
  12693. let animation = animations[i];
  12694. if (animation.name == animationName) return animation;
  12695. }
  12696. return null;
  12697. }
  12698. findIkConstraint(constraintName) {
  12699. if (constraintName == null) throw new Error("constraintName cannot be null.");
  12700. let ikConstraints = this.ikConstraints;
  12701. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  12702. let constraint = ikConstraints[i];
  12703. if (constraint.name == constraintName) return constraint;
  12704. }
  12705. return null;
  12706. }
  12707. findTransformConstraint(constraintName) {
  12708. if (constraintName == null) throw new Error("constraintName cannot be null.");
  12709. let transformConstraints = this.transformConstraints;
  12710. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  12711. let constraint = transformConstraints[i];
  12712. if (constraint.name == constraintName) return constraint;
  12713. }
  12714. return null;
  12715. }
  12716. findPathConstraint(constraintName) {
  12717. if (constraintName == null) throw new Error("constraintName cannot be null.");
  12718. let pathConstraints = this.pathConstraints;
  12719. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  12720. let constraint = pathConstraints[i];
  12721. if (constraint.name == constraintName) return constraint;
  12722. }
  12723. return null;
  12724. }
  12725. findPathConstraintIndex(pathConstraintName) {
  12726. if (pathConstraintName == null) throw new Error("pathConstraintName cannot be null.");
  12727. let pathConstraints = this.pathConstraints;
  12728. for (let i = 0, n = pathConstraints.length; i < n; i++)
  12729. if (pathConstraints[i].name == pathConstraintName) return i;
  12730. return -1;
  12731. }
  12732. }
  12733. /**
  12734. * @public
  12735. */
  12736. class SlotData$1 {
  12737. __init() {this.color = new Color(1, 1, 1, 1);}
  12738. constructor (index, name, boneData) {SlotData$1.prototype.__init.call(this);
  12739. if (index < 0) throw new Error("index must be >= 0.");
  12740. if (name == null) throw new Error("name cannot be null.");
  12741. if (boneData == null) throw new Error("boneData cannot be null.");
  12742. this.index = index;
  12743. this.name = name;
  12744. this.boneData = boneData;
  12745. }
  12746. }
  12747. /**
  12748. * @public
  12749. */
  12750. class TransformConstraintData$1 {
  12751. __init() {this.order = 0;}
  12752. __init2() {this.bones = new Array();}
  12753. __init3() {this.rotateMix = 0;} __init4() {this.translateMix = 0;} __init5() {this.scaleMix = 0;} __init6() {this.shearMix = 0;}
  12754. __init7() {this.offsetRotation = 0;} __init8() {this.offsetX = 0;} __init9() {this.offsetY = 0;} __init10() {this.offsetScaleX = 0;} __init11() {this.offsetScaleY = 0;} __init12() {this.offsetShearY = 0;}
  12755. __init13() {this.relative = false;}
  12756. __init14() {this.local = false;}
  12757. constructor (name) {TransformConstraintData$1.prototype.__init.call(this);TransformConstraintData$1.prototype.__init2.call(this);TransformConstraintData$1.prototype.__init3.call(this);TransformConstraintData$1.prototype.__init4.call(this);TransformConstraintData$1.prototype.__init5.call(this);TransformConstraintData$1.prototype.__init6.call(this);TransformConstraintData$1.prototype.__init7.call(this);TransformConstraintData$1.prototype.__init8.call(this);TransformConstraintData$1.prototype.__init9.call(this);TransformConstraintData$1.prototype.__init10.call(this);TransformConstraintData$1.prototype.__init11.call(this);TransformConstraintData$1.prototype.__init12.call(this);TransformConstraintData$1.prototype.__init13.call(this);TransformConstraintData$1.prototype.__init14.call(this);
  12758. if (name == null) throw new Error("name cannot be null.");
  12759. this.name = name;
  12760. }
  12761. }
  12762. /**
  12763. * @public
  12764. */
  12765. class Skin$1 {
  12766. __init() {this.attachments = new Array();}
  12767. constructor(name) {Skin$1.prototype.__init.call(this);
  12768. if (name == null) throw new Error("name cannot be null.");
  12769. this.name = name;
  12770. }
  12771. addAttachment(slotIndex, name, attachment) {
  12772. if (attachment == null) throw new Error("attachment cannot be null.");
  12773. let attachments = this.attachments;
  12774. if (slotIndex >= attachments.length) attachments.length = slotIndex + 1;
  12775. if (!attachments[slotIndex]) attachments[slotIndex] = {};
  12776. attachments[slotIndex][name] = attachment;
  12777. }
  12778. /** @return May be null. */
  12779. getAttachment(slotIndex, name) {
  12780. let dictionary = this.attachments[slotIndex];
  12781. return dictionary ? dictionary[name] : null;
  12782. }
  12783. /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
  12784. attachAll(skeleton, oldSkin) {
  12785. let slotIndex = 0;
  12786. for (let i = 0; i < skeleton.slots.length; i++) {
  12787. let slot = skeleton.slots[i];
  12788. let slotAttachment = slot.getAttachment();
  12789. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  12790. let dictionary = oldSkin.attachments[slotIndex];
  12791. for (let key in dictionary) {
  12792. let skinAttachment = dictionary[key];
  12793. if (slotAttachment == skinAttachment) {
  12794. let attachment = this.getAttachment(slotIndex, key);
  12795. if (attachment != null) slot.setAttachment(attachment);
  12796. break;
  12797. }
  12798. }
  12799. }
  12800. slotIndex++;
  12801. }
  12802. }
  12803. }
  12804. /**
  12805. * @public
  12806. */
  12807. class SkeletonJson$1 {
  12808. __init() {this.scale = 1;}
  12809. __init2() {this.linkedMeshes = new Array();}
  12810. constructor (attachmentLoader) {SkeletonJson$1.prototype.__init.call(this);SkeletonJson$1.prototype.__init2.call(this);
  12811. this.attachmentLoader = attachmentLoader;
  12812. }
  12813. readSkeletonData (json) {
  12814. let scale = this.scale;
  12815. let skeletonData = new SkeletonData$1();
  12816. let root = typeof(json) === "string" ? JSON.parse(json) : json;
  12817. // Skeleton
  12818. let skeletonMap = root.skeleton;
  12819. if (skeletonMap != null) {
  12820. skeletonData.hash = skeletonMap.hash;
  12821. skeletonData.version = skeletonMap.spine;
  12822. skeletonData.width = skeletonMap.width;
  12823. skeletonData.height = skeletonMap.height;
  12824. skeletonData.fps = skeletonMap.fps;
  12825. skeletonData.imagesPath = skeletonMap.images;
  12826. }
  12827. // Bones
  12828. if (root.bones) {
  12829. for (let i = 0; i < root.bones.length; i++) {
  12830. let boneMap = root.bones[i];
  12831. let parent = null;
  12832. let parentName = this.getValue(boneMap, "parent", null);
  12833. if (parentName != null) {
  12834. parent = skeletonData.findBone(parentName);
  12835. if (parent == null) throw new Error("Parent bone not found: " + parentName);
  12836. }
  12837. let data = new BoneData$1(skeletonData.bones.length, boneMap.name, parent);
  12838. data.length = this.getValue(boneMap, "length", 0) * scale;
  12839. data.x = this.getValue(boneMap, "x", 0) * scale;
  12840. data.y = this.getValue(boneMap, "y", 0) * scale;
  12841. data.rotation = this.getValue(boneMap, "rotation", 0);
  12842. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  12843. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  12844. data.shearX = this.getValue(boneMap, "shearX", 0);
  12845. data.shearY = this.getValue(boneMap, "shearY", 0);
  12846. data.transformMode = SkeletonJson$1.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  12847. skeletonData.bones.push(data);
  12848. }
  12849. }
  12850. // Slots.
  12851. if (root.slots) {
  12852. for (let i = 0; i < root.slots.length; i++) {
  12853. let slotMap = root.slots[i];
  12854. let slotName = slotMap.name;
  12855. let boneName = slotMap.bone;
  12856. let boneData = skeletonData.findBone(boneName);
  12857. if (boneData == null) throw new Error("Slot bone not found: " + boneName);
  12858. let data = new SlotData$1(skeletonData.slots.length, slotName, boneData);
  12859. let color = this.getValue(slotMap, "color", null);
  12860. if (color != null) data.color.setFromString(color);
  12861. let dark = this.getValue(slotMap, "dark", null);
  12862. if (dark != null) {
  12863. data.darkColor = new Color(1, 1, 1, 1);
  12864. data.darkColor.setFromString(dark);
  12865. }
  12866. data.attachmentName = this.getValue(slotMap, "attachment", null);
  12867. data.blendMode = SkeletonJson$1.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  12868. skeletonData.slots.push(data);
  12869. }
  12870. }
  12871. // IK constraints
  12872. if (root.ik) {
  12873. for (let i = 0; i < root.ik.length; i++) {
  12874. let constraintMap = root.ik[i];
  12875. let data = new IkConstraintData$1(constraintMap.name);
  12876. data.order = this.getValue(constraintMap, "order", 0);
  12877. for (let j = 0; j < constraintMap.bones.length; j++) {
  12878. let boneName = constraintMap.bones[j];
  12879. let bone = skeletonData.findBone(boneName);
  12880. if (bone == null) throw new Error("IK bone not found: " + boneName);
  12881. data.bones.push(bone);
  12882. }
  12883. let targetName = constraintMap.target;
  12884. data.target = skeletonData.findBone(targetName);
  12885. if (data.target == null) throw new Error("IK target bone not found: " + targetName);
  12886. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  12887. data.mix = this.getValue(constraintMap, "mix", 1);
  12888. skeletonData.ikConstraints.push(data);
  12889. }
  12890. }
  12891. // Transform constraints.
  12892. if (root.transform) {
  12893. for (let i = 0; i < root.transform.length; i++) {
  12894. let constraintMap = root.transform[i];
  12895. let data = new TransformConstraintData$1(constraintMap.name);
  12896. data.order = this.getValue(constraintMap, "order", 0);
  12897. for (let j = 0; j < constraintMap.bones.length; j++) {
  12898. let boneName = constraintMap.bones[j];
  12899. let bone = skeletonData.findBone(boneName);
  12900. if (bone == null) throw new Error("Transform constraint bone not found: " + boneName);
  12901. data.bones.push(bone);
  12902. }
  12903. let targetName = constraintMap.target;
  12904. data.target = skeletonData.findBone(targetName);
  12905. if (data.target == null) throw new Error("Transform constraint target bone not found: " + targetName);
  12906. data.local = this.getValue(constraintMap, "local", false);
  12907. data.relative = this.getValue(constraintMap, "relative", false);
  12908. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  12909. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  12910. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  12911. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  12912. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  12913. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  12914. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  12915. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  12916. data.scaleMix = this.getValue(constraintMap, "scaleMix", 1);
  12917. data.shearMix = this.getValue(constraintMap, "shearMix", 1);
  12918. skeletonData.transformConstraints.push(data);
  12919. }
  12920. }
  12921. // Path constraints.
  12922. if (root.path) {
  12923. for (let i = 0; i < root.path.length; i++) {
  12924. let constraintMap = root.path[i];
  12925. let data = new PathConstraintData$1(constraintMap.name);
  12926. data.order = this.getValue(constraintMap, "order", 0);
  12927. for (let j = 0; j < constraintMap.bones.length; j++) {
  12928. let boneName = constraintMap.bones[j];
  12929. let bone = skeletonData.findBone(boneName);
  12930. if (bone == null) throw new Error("Transform constraint bone not found: " + boneName);
  12931. data.bones.push(bone);
  12932. }
  12933. let targetName = constraintMap.target;
  12934. data.target = skeletonData.findSlot(targetName);
  12935. if (data.target == null) throw new Error("Path target slot not found: " + targetName);
  12936. data.positionMode = SkeletonJson$1.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  12937. data.spacingMode = SkeletonJson$1.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  12938. data.rotateMode = SkeletonJson$1.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  12939. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  12940. data.position = this.getValue(constraintMap, "position", 0);
  12941. if (data.positionMode == PositionMode$1.Fixed) data.position *= scale;
  12942. data.spacing = this.getValue(constraintMap, "spacing", 0);
  12943. if (data.spacingMode == SpacingMode$1.Length || data.spacingMode == SpacingMode$1.Fixed) data.spacing *= scale;
  12944. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  12945. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  12946. skeletonData.pathConstraints.push(data);
  12947. }
  12948. }
  12949. // Skins.
  12950. if (root.skins) {
  12951. for (let skinName in root.skins) {
  12952. let skinMap = root.skins[skinName];
  12953. let skin = new Skin$1(skinName);
  12954. for (let slotName in skinMap) {
  12955. let slotIndex = skeletonData.findSlotIndex(slotName);
  12956. if (slotIndex == -1) throw new Error("Slot not found: " + slotName);
  12957. let slotMap = skinMap[slotName];
  12958. for (let entryName in slotMap) {
  12959. let attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
  12960. if (attachment != null) skin.addAttachment(slotIndex, entryName, attachment);
  12961. }
  12962. }
  12963. skeletonData.skins.push(skin);
  12964. if (skin.name == "default") skeletonData.defaultSkin = skin;
  12965. }
  12966. }
  12967. // Linked meshes.
  12968. for (let i = 0, n = this.linkedMeshes.length; i < n; i++) {
  12969. let linkedMesh = this.linkedMeshes[i];
  12970. let skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  12971. if (skin == null) throw new Error("Skin not found: " + linkedMesh.skin);
  12972. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  12973. if (parent == null) throw new Error("Parent mesh not found: " + linkedMesh.parent);
  12974. linkedMesh.mesh.setParentMesh( parent);
  12975. //linkedMesh.mesh.updateUVs();
  12976. }
  12977. this.linkedMeshes.length = 0;
  12978. // Events.
  12979. if (root.events) {
  12980. for (let eventName in root.events) {
  12981. let eventMap = root.events[eventName];
  12982. let data = new EventData$1(eventName);
  12983. data.intValue = this.getValue(eventMap, "int", 0);
  12984. data.floatValue = this.getValue(eventMap, "float", 0);
  12985. data.stringValue = this.getValue(eventMap, "string", "");
  12986. data.audioPath = this.getValue(eventMap, "audio", null);
  12987. if (data.audioPath != null) {
  12988. data.volume = this.getValue(eventMap, "volume", 1);
  12989. data.balance = this.getValue(eventMap, "balance", 0);
  12990. }
  12991. skeletonData.events.push(data);
  12992. }
  12993. }
  12994. // Animations.
  12995. if (root.animations) {
  12996. for (let animationName in root.animations) {
  12997. let animationMap = root.animations[animationName];
  12998. this.readAnimation(animationMap, animationName, skeletonData);
  12999. }
  13000. }
  13001. return skeletonData;
  13002. }
  13003. readAttachment (map, skin, slotIndex, name, skeletonData) {
  13004. let scale = this.scale;
  13005. name = this.getValue(map, "name", name);
  13006. let type = this.getValue(map, "type", "region");
  13007. switch (type) {
  13008. case "region": {
  13009. let path = this.getValue(map, "path", name);
  13010. let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  13011. if (region == null) return null;
  13012. region.path = path;
  13013. region.x = this.getValue(map, "x", 0) * scale;
  13014. region.y = this.getValue(map, "y", 0) * scale;
  13015. region.scaleX = this.getValue(map, "scaleX", 1);
  13016. region.scaleY = this.getValue(map, "scaleY", 1);
  13017. region.rotation = this.getValue(map, "rotation", 0);
  13018. region.width = map.width * scale;
  13019. region.height = map.height * scale;
  13020. let color = this.getValue(map, "color", null);
  13021. if (color != null) region.color.setFromString(color);
  13022. //region.updateOffset();
  13023. return region;
  13024. }
  13025. case "boundingbox": {
  13026. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  13027. if (box == null) return null;
  13028. this.readVertices(map, box, map.vertexCount << 1);
  13029. let color = this.getValue(map, "color", null);
  13030. if (color != null) box.color.setFromString(color);
  13031. return box;
  13032. }
  13033. case "mesh":
  13034. case "linkedmesh": {
  13035. let path = this.getValue(map, "path", name);
  13036. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  13037. if (mesh == null) return null;
  13038. mesh.path = path;
  13039. let color = this.getValue(map, "color", null);
  13040. if (color != null) mesh.color.setFromString(color);
  13041. let parent = this.getValue(map, "parent", null);
  13042. if (parent != null) {
  13043. mesh.inheritDeform = this.getValue(map, "deform", true);
  13044. this.linkedMeshes.push(new LinkedMesh$2(mesh, this.getValue(map, "skin", null), slotIndex, parent));
  13045. return mesh;
  13046. }
  13047. let uvs = map.uvs;
  13048. this.readVertices(map, mesh, uvs.length);
  13049. mesh.triangles = map.triangles;
  13050. mesh.regionUVs = new Float32Array(uvs);
  13051. //mesh.updateUVs();
  13052. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  13053. return mesh;
  13054. }
  13055. case "path": {
  13056. let path = this.attachmentLoader.newPathAttachment(skin, name);
  13057. if (path == null) return null;
  13058. path.closed = this.getValue(map, "closed", false);
  13059. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  13060. let vertexCount = map.vertexCount;
  13061. this.readVertices(map, path, vertexCount << 1);
  13062. let lengths = Utils.newArray(vertexCount / 3, 0);
  13063. for (let i = 0; i < map.lengths.length; i++)
  13064. lengths[i] = map.lengths[i] * scale;
  13065. path.lengths = lengths;
  13066. let color = this.getValue(map, "color", null);
  13067. if (color != null) path.color.setFromString(color);
  13068. return path;
  13069. }
  13070. case "point": {
  13071. let point = this.attachmentLoader.newPointAttachment(skin, name);
  13072. if (point == null) return null;
  13073. point.x = this.getValue(map, "x", 0) * scale;
  13074. point.y = this.getValue(map, "y", 0) * scale;
  13075. point.rotation = this.getValue(map, "rotation", 0);
  13076. let color = this.getValue(map, "color", null);
  13077. if (color != null) point.color.setFromString(color);
  13078. return point;
  13079. }
  13080. case "clipping": {
  13081. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  13082. if (clip == null) return null;
  13083. let end = this.getValue(map, "end", null);
  13084. if (end != null) {
  13085. let slot = skeletonData.findSlot(end);
  13086. if (slot == null) throw new Error("Clipping end slot not found: " + end);
  13087. clip.endSlot = slot;
  13088. }
  13089. let vertexCount = map.vertexCount;
  13090. this.readVertices(map, clip, vertexCount << 1);
  13091. let color = this.getValue(map, "color", null);
  13092. if (color != null) clip.color.setFromString(color);
  13093. return clip;
  13094. }
  13095. }
  13096. return null;
  13097. }
  13098. readVertices (map, attachment, verticesLength) {
  13099. let scale = this.scale;
  13100. attachment.worldVerticesLength = verticesLength;
  13101. let vertices = map.vertices;
  13102. if (verticesLength == vertices.length) {
  13103. let scaledVertices = Utils.toFloatArray(vertices);
  13104. if (scale != 1) {
  13105. for (let i = 0, n = vertices.length; i < n; i++)
  13106. scaledVertices[i] *= scale;
  13107. }
  13108. attachment.vertices = scaledVertices;
  13109. return;
  13110. }
  13111. let weights = new Array();
  13112. let bones = new Array();
  13113. for (let i = 0, n = vertices.length; i < n;) {
  13114. let boneCount = vertices[i++];
  13115. bones.push(boneCount);
  13116. for (let nn = i + boneCount * 4; i < nn; i += 4) {
  13117. bones.push(vertices[i]);
  13118. weights.push(vertices[i + 1] * scale);
  13119. weights.push(vertices[i + 2] * scale);
  13120. weights.push(vertices[i + 3]);
  13121. }
  13122. }
  13123. attachment.bones = bones;
  13124. attachment.vertices = Utils.toFloatArray(weights);
  13125. }
  13126. readAnimation (map, name, skeletonData) {
  13127. let scale = this.scale;
  13128. let timelines = new Array();
  13129. let duration = 0;
  13130. // Slot timelines.
  13131. if (map.slots) {
  13132. for (let slotName in map.slots) {
  13133. let slotMap = map.slots[slotName];
  13134. let slotIndex = skeletonData.findSlotIndex(slotName);
  13135. if (slotIndex == -1) throw new Error("Slot not found: " + slotName);
  13136. for (let timelineName in slotMap) {
  13137. let timelineMap = slotMap[timelineName];
  13138. if (timelineName == "attachment") {
  13139. let timeline = new AttachmentTimeline$1(timelineMap.length);
  13140. timeline.slotIndex = slotIndex;
  13141. let frameIndex = 0;
  13142. for (let i = 0; i < timelineMap.length; i++) {
  13143. let valueMap = timelineMap[i];
  13144. timeline.setFrame(frameIndex++, valueMap.time, valueMap.name);
  13145. }
  13146. timelines.push(timeline);
  13147. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  13148. } else if (timelineName == "color") {
  13149. let timeline = new ColorTimeline$1(timelineMap.length);
  13150. timeline.slotIndex = slotIndex;
  13151. let frameIndex = 0;
  13152. for (let i = 0; i < timelineMap.length; i++) {
  13153. let valueMap = timelineMap[i];
  13154. let color = new Color();
  13155. color.setFromString(valueMap.color || "ffffffff");
  13156. timeline.setFrame(frameIndex, valueMap.time, color.r, color.g, color.b, color.a);
  13157. this.readCurve(valueMap, timeline, frameIndex);
  13158. frameIndex++;
  13159. }
  13160. timelines.push(timeline);
  13161. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * ColorTimeline$1.ENTRIES]);
  13162. } else if (timelineName == "twoColor") {
  13163. let timeline = new TwoColorTimeline$1(timelineMap.length);
  13164. timeline.slotIndex = slotIndex;
  13165. let frameIndex = 0;
  13166. for (let i = 0; i < timelineMap.length; i++) {
  13167. let valueMap = timelineMap[i];
  13168. let light = new Color();
  13169. let dark = new Color();
  13170. light.setFromString(valueMap.light);
  13171. dark.setFromString(valueMap.dark);
  13172. timeline.setFrame(frameIndex, valueMap.time, light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
  13173. this.readCurve(valueMap, timeline, frameIndex);
  13174. frameIndex++;
  13175. }
  13176. timelines.push(timeline);
  13177. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * TwoColorTimeline$1.ENTRIES]);
  13178. } else
  13179. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  13180. }
  13181. }
  13182. }
  13183. // Bone timelines.
  13184. if (map.bones) {
  13185. for (let boneName in map.bones) {
  13186. let boneMap = map.bones[boneName];
  13187. let boneIndex = skeletonData.findBoneIndex(boneName);
  13188. if (boneIndex == -1) throw new Error("Bone not found: " + boneName);
  13189. for (let timelineName in boneMap) {
  13190. let timelineMap = boneMap[timelineName];
  13191. if (timelineName === "rotate") {
  13192. let timeline = new RotateTimeline$1(timelineMap.length);
  13193. timeline.boneIndex = boneIndex;
  13194. let frameIndex = 0;
  13195. for (let i = 0; i < timelineMap.length; i++) {
  13196. let valueMap = timelineMap[i];
  13197. timeline.setFrame(frameIndex, valueMap.time, valueMap.angle);
  13198. this.readCurve(valueMap, timeline, frameIndex);
  13199. frameIndex++;
  13200. }
  13201. timelines.push(timeline);
  13202. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * RotateTimeline$1.ENTRIES]);
  13203. } else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
  13204. let timeline = null;
  13205. let timelineScale = 1;
  13206. if (timelineName === "scale")
  13207. timeline = new ScaleTimeline$1(timelineMap.length);
  13208. else if (timelineName === "shear")
  13209. timeline = new ShearTimeline$1(timelineMap.length);
  13210. else {
  13211. timeline = new TranslateTimeline$1(timelineMap.length);
  13212. timelineScale = scale;
  13213. }
  13214. timeline.boneIndex = boneIndex;
  13215. let frameIndex = 0;
  13216. for (let i = 0; i < timelineMap.length; i++) {
  13217. let valueMap = timelineMap[i];
  13218. let x = this.getValue(valueMap, "x", 0), y = this.getValue(valueMap, "y", 0);
  13219. timeline.setFrame(frameIndex, valueMap.time, x * timelineScale, y * timelineScale);
  13220. this.readCurve(valueMap, timeline, frameIndex);
  13221. frameIndex++;
  13222. }
  13223. timelines.push(timeline);
  13224. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * TranslateTimeline$1.ENTRIES]);
  13225. } else
  13226. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  13227. }
  13228. }
  13229. }
  13230. // IK constraint timelines.
  13231. if (map.ik) {
  13232. for (let constraintName in map.ik) {
  13233. let constraintMap = map.ik[constraintName];
  13234. let constraint = skeletonData.findIkConstraint(constraintName);
  13235. let timeline = new IkConstraintTimeline$1(constraintMap.length);
  13236. timeline.ikConstraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  13237. let frameIndex = 0;
  13238. for (let i = 0; i < constraintMap.length; i++) {
  13239. let valueMap = constraintMap[i];
  13240. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "mix", 1),
  13241. this.getValue(valueMap, "bendPositive", true) ? 1 : -1, this.getValue(valueMap, "compress", false), this.getValue(valueMap, "stretch", false));
  13242. this.readCurve(valueMap, timeline, frameIndex);
  13243. frameIndex++;
  13244. }
  13245. timelines.push(timeline);
  13246. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * IkConstraintTimeline$1.ENTRIES]);
  13247. }
  13248. }
  13249. // Transform constraint timelines.
  13250. if (map.transform) {
  13251. for (let constraintName in map.transform) {
  13252. let constraintMap = map.transform[constraintName];
  13253. let constraint = skeletonData.findTransformConstraint(constraintName);
  13254. let timeline = new TransformConstraintTimeline$1(constraintMap.length);
  13255. timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  13256. let frameIndex = 0;
  13257. for (let i = 0; i < constraintMap.length; i++) {
  13258. let valueMap = constraintMap[i];
  13259. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1),
  13260. this.getValue(valueMap, "translateMix", 1), this.getValue(valueMap, "scaleMix", 1), this.getValue(valueMap, "shearMix", 1));
  13261. this.readCurve(valueMap, timeline, frameIndex);
  13262. frameIndex++;
  13263. }
  13264. timelines.push(timeline);
  13265. duration = Math.max(duration,
  13266. timeline.frames[(timeline.getFrameCount() - 1) * TransformConstraintTimeline$1.ENTRIES]);
  13267. }
  13268. }
  13269. // Path constraint timelines.
  13270. if (map.paths) {
  13271. for (let constraintName in map.paths) {
  13272. let constraintMap = map.paths[constraintName];
  13273. let index = skeletonData.findPathConstraintIndex(constraintName);
  13274. if (index == -1) throw new Error("Path constraint not found: " + constraintName);
  13275. let data = skeletonData.pathConstraints[index];
  13276. for (let timelineName in constraintMap) {
  13277. let timelineMap = constraintMap[timelineName];
  13278. if (timelineName === "position" || timelineName === "spacing") {
  13279. let timeline = null;
  13280. let timelineScale = 1;
  13281. if (timelineName === "spacing") {
  13282. timeline = new PathConstraintSpacingTimeline$1(timelineMap.length);
  13283. if (data.spacingMode == SpacingMode$1.Length || data.spacingMode == SpacingMode$1.Fixed) timelineScale = scale;
  13284. } else {
  13285. timeline = new PathConstraintPositionTimeline$1(timelineMap.length);
  13286. if (data.positionMode == PositionMode$1.Fixed) timelineScale = scale;
  13287. }
  13288. timeline.pathConstraintIndex = index;
  13289. let frameIndex = 0;
  13290. for (let i = 0; i < timelineMap.length; i++) {
  13291. let valueMap = timelineMap[i];
  13292. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, timelineName, 0) * timelineScale);
  13293. this.readCurve(valueMap, timeline, frameIndex);
  13294. frameIndex++;
  13295. }
  13296. timelines.push(timeline);
  13297. duration = Math.max(duration,
  13298. timeline.frames[(timeline.getFrameCount() - 1) * PathConstraintPositionTimeline$1.ENTRIES]);
  13299. } else if (timelineName === "mix") {
  13300. let timeline = new PathConstraintMixTimeline$1(timelineMap.length);
  13301. timeline.pathConstraintIndex = index;
  13302. let frameIndex = 0;
  13303. for (let i = 0; i < timelineMap.length; i++) {
  13304. let valueMap = timelineMap[i];
  13305. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1),
  13306. this.getValue(valueMap, "translateMix", 1));
  13307. this.readCurve(valueMap, timeline, frameIndex);
  13308. frameIndex++;
  13309. }
  13310. timelines.push(timeline);
  13311. duration = Math.max(duration,
  13312. timeline.frames[(timeline.getFrameCount() - 1) * PathConstraintMixTimeline$1.ENTRIES]);
  13313. }
  13314. }
  13315. }
  13316. }
  13317. // Deform timelines.
  13318. if (map.deform) {
  13319. for (let deformName in map.deform) {
  13320. let deformMap = map.deform[deformName];
  13321. let skin = skeletonData.findSkin(deformName);
  13322. if (skin == null) {
  13323. if (settings.FAIL_ON_NON_EXISTING_SKIN) {
  13324. throw new Error("Skin not found: " + deformName);
  13325. } else {
  13326. continue;
  13327. }
  13328. } for (let slotName in deformMap) {
  13329. let slotMap = deformMap[slotName];
  13330. let slotIndex = skeletonData.findSlotIndex(slotName);
  13331. if (slotIndex == -1) throw new Error("Slot not found: " + slotMap.name);
  13332. for (let timelineName in slotMap) {
  13333. let timelineMap = slotMap[timelineName];
  13334. let attachment = skin.getAttachment(slotIndex, timelineName);
  13335. if (attachment == null) throw new Error("Deform attachment not found: " + timelineMap.name);
  13336. let weighted = attachment.bones != null;
  13337. let vertices = attachment.vertices;
  13338. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  13339. let timeline = new DeformTimeline$1(timelineMap.length);
  13340. timeline.slotIndex = slotIndex;
  13341. timeline.attachment = attachment;
  13342. let frameIndex = 0;
  13343. for (let j = 0; j < timelineMap.length; j++) {
  13344. let valueMap = timelineMap[j];
  13345. let deform;
  13346. let verticesValue = this.getValue(valueMap, "vertices", null);
  13347. if (verticesValue == null)
  13348. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  13349. else {
  13350. deform = Utils.newFloatArray(deformLength);
  13351. let start = this.getValue(valueMap, "offset", 0);
  13352. Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  13353. if (scale != 1) {
  13354. for (let i = start, n = i + verticesValue.length; i < n; i++)
  13355. deform[i] *= scale;
  13356. }
  13357. if (!weighted) {
  13358. for (let i = 0; i < deformLength; i++)
  13359. deform[i] += vertices[i];
  13360. }
  13361. }
  13362. timeline.setFrame(frameIndex, valueMap.time, deform);
  13363. this.readCurve(valueMap, timeline, frameIndex);
  13364. frameIndex++;
  13365. }
  13366. timelines.push(timeline);
  13367. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  13368. }
  13369. }
  13370. }
  13371. }
  13372. // Draw order timeline.
  13373. let drawOrderNode = map.drawOrder;
  13374. if (drawOrderNode == null) drawOrderNode = map.draworder;
  13375. if (drawOrderNode != null) {
  13376. let timeline = new DrawOrderTimeline$1(drawOrderNode.length);
  13377. let slotCount = skeletonData.slots.length;
  13378. let frameIndex = 0;
  13379. for (let j = 0; j < drawOrderNode.length; j++) {
  13380. let drawOrderMap = drawOrderNode[j];
  13381. let drawOrder = null;
  13382. let offsets = this.getValue(drawOrderMap, "offsets", null);
  13383. if (offsets != null) {
  13384. drawOrder = Utils.newArray(slotCount, -1);
  13385. let unchanged = Utils.newArray(slotCount - offsets.length, 0);
  13386. let originalIndex = 0, unchangedIndex = 0;
  13387. for (let i = 0; i < offsets.length; i++) {
  13388. let offsetMap = offsets[i];
  13389. let slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  13390. if (slotIndex == -1) throw new Error("Slot not found: " + offsetMap.slot);
  13391. // Collect unchanged items.
  13392. while (originalIndex != slotIndex)
  13393. unchanged[unchangedIndex++] = originalIndex++;
  13394. // Set changed items.
  13395. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  13396. }
  13397. // Collect remaining unchanged items.
  13398. while (originalIndex < slotCount)
  13399. unchanged[unchangedIndex++] = originalIndex++;
  13400. // Fill in unchanged items.
  13401. for (let i = slotCount - 1; i >= 0; i--)
  13402. if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex];
  13403. }
  13404. timeline.setFrame(frameIndex++, drawOrderMap.time, drawOrder);
  13405. }
  13406. timelines.push(timeline);
  13407. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  13408. }
  13409. // Event timeline.
  13410. if (map.events) {
  13411. let timeline = new EventTimeline$1(map.events.length);
  13412. let frameIndex = 0;
  13413. for (let i = 0; i < map.events.length; i++) {
  13414. let eventMap = map.events[i];
  13415. let eventData = skeletonData.findEvent(eventMap.name);
  13416. if (eventData == null) throw new Error("Event not found: " + eventMap.name);
  13417. let event = new Event$1(Utils.toSinglePrecision(eventMap.time), eventData);
  13418. event.intValue = this.getValue(eventMap, "int", eventData.intValue);
  13419. event.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  13420. event.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  13421. if (event.data.audioPath != null) {
  13422. event.volume = this.getValue(eventMap, "volume", 1);
  13423. event.balance = this.getValue(eventMap, "balance", 0);
  13424. }
  13425. timeline.setFrame(frameIndex++, event);
  13426. }
  13427. timelines.push(timeline);
  13428. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  13429. }
  13430. if (isNaN(duration)) {
  13431. throw new Error("Error while parsing animation, duration is NaN");
  13432. }
  13433. skeletonData.animations.push(new Animation$1(name, timelines, duration));
  13434. }
  13435. readCurve (map, timeline, frameIndex) {
  13436. if (!map.curve) return;
  13437. if (map.curve === "stepped")
  13438. timeline.setStepped(frameIndex);
  13439. else if (Object.prototype.toString.call(map.curve) === '[object Array]') {
  13440. let curve = map.curve;
  13441. timeline.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]);
  13442. }
  13443. }
  13444. getValue (map, prop, defaultValue) {
  13445. return map[prop] !== undefined ? map[prop] : defaultValue;
  13446. }
  13447. static blendModeFromString (str) {
  13448. str = str.toLowerCase();
  13449. if (str == "normal") return constants.BLEND_MODES.NORMAL;
  13450. if (str == "additive") return constants.BLEND_MODES.ADD;
  13451. if (str == "multiply") return constants.BLEND_MODES.MULTIPLY;
  13452. if (str == "screen") return constants.BLEND_MODES.SCREEN;
  13453. throw new Error(`Unknown blend mode: ${str}`);
  13454. }
  13455. static positionModeFromString (str) {
  13456. str = str.toLowerCase();
  13457. if (str == "fixed") return PositionMode$1.Fixed;
  13458. if (str == "percent") return PositionMode$1.Percent;
  13459. throw new Error(`Unknown position mode: ${str}`);
  13460. }
  13461. static spacingModeFromString (str) {
  13462. str = str.toLowerCase();
  13463. if (str == "length") return SpacingMode$1.Length;
  13464. if (str == "fixed") return SpacingMode$1.Fixed;
  13465. if (str == "percent") return SpacingMode$1.Percent;
  13466. throw new Error(`Unknown position mode: ${str}`);
  13467. }
  13468. static rotateModeFromString (str) {
  13469. str = str.toLowerCase();
  13470. if (str == "tangent") return RotateMode$1.Tangent;
  13471. if (str == "chain") return RotateMode$1.Chain;
  13472. if (str == "chainscale") return RotateMode$1.ChainScale;
  13473. throw new Error(`Unknown rotate mode: ${str}`);
  13474. }
  13475. static transformModeFromString(str) {
  13476. str = str.toLowerCase();
  13477. if (str == "normal") return TransformMode$1.Normal;
  13478. if (str == "onlytranslation") return TransformMode$1.OnlyTranslation;
  13479. if (str == "norotationorreflection") return TransformMode$1.NoRotationOrReflection;
  13480. if (str == "noscale") return TransformMode$1.NoScale;
  13481. if (str == "noscaleorreflection") return TransformMode$1.NoScaleOrReflection;
  13482. throw new Error(`Unknown transform mode: ${str}`);
  13483. }
  13484. }
  13485. class LinkedMesh$2 {
  13486. constructor (mesh, skin, slotIndex, parent) {
  13487. this.mesh = mesh;
  13488. this.skin = skin;
  13489. this.slotIndex = slotIndex;
  13490. this.parent = parent;
  13491. }
  13492. }
  13493. /**
  13494. * @public
  13495. */
  13496. class Spine$1 extends SpineBase {
  13497. createSkeleton(spineData) {
  13498. this.skeleton = new Skeleton$1(spineData);
  13499. this.skeleton.updateWorldTransform();
  13500. this.stateData = new AnimationStateData$1(spineData);
  13501. this.state = new AnimationState$1(this.stateData);
  13502. }
  13503. }
  13504. var spine37 = /*#__PURE__*/Object.freeze({
  13505. __proto__: null,
  13506. Animation: Animation$1,
  13507. AnimationState: AnimationState$1,
  13508. AnimationStateAdapter2: AnimationStateAdapter2,
  13509. AnimationStateData: AnimationStateData$1,
  13510. AtlasAttachmentLoader: AtlasAttachmentLoader$1,
  13511. Attachment: Attachment$1,
  13512. AttachmentTimeline: AttachmentTimeline$1,
  13513. Bone: Bone$1,
  13514. BoneData: BoneData$1,
  13515. BoundingBoxAttachment: BoundingBoxAttachment$1,
  13516. ClippingAttachment: ClippingAttachment$1,
  13517. ColorTimeline: ColorTimeline$1,
  13518. CurveTimeline: CurveTimeline$1,
  13519. DeformTimeline: DeformTimeline$1,
  13520. DrawOrderTimeline: DrawOrderTimeline$1,
  13521. Event: Event$1,
  13522. EventData: EventData$1,
  13523. EventQueue: EventQueue$1,
  13524. EventTimeline: EventTimeline$1,
  13525. get EventType () { return EventType$1; },
  13526. IkConstraint: IkConstraint$1,
  13527. IkConstraintData: IkConstraintData$1,
  13528. IkConstraintTimeline: IkConstraintTimeline$1,
  13529. JitterEffect: JitterEffect$1,
  13530. MeshAttachment: MeshAttachment$1,
  13531. get MixBlend () { return MixBlend$1; },
  13532. get MixDirection () { return MixDirection$1; },
  13533. PathAttachment: PathAttachment$1,
  13534. PathConstraint: PathConstraint$1,
  13535. PathConstraintData: PathConstraintData$1,
  13536. PathConstraintMixTimeline: PathConstraintMixTimeline$1,
  13537. PathConstraintPositionTimeline: PathConstraintPositionTimeline$1,
  13538. PathConstraintSpacingTimeline: PathConstraintSpacingTimeline$1,
  13539. PointAttachment: PointAttachment$1,
  13540. get PositionMode () { return PositionMode$1; },
  13541. RegionAttachment: RegionAttachment$1,
  13542. get RotateMode () { return RotateMode$1; },
  13543. RotateTimeline: RotateTimeline$1,
  13544. ScaleTimeline: ScaleTimeline$1,
  13545. ShearTimeline: ShearTimeline$1,
  13546. Skeleton: Skeleton$1,
  13547. SkeletonBounds: SkeletonBounds$1,
  13548. SkeletonData: SkeletonData$1,
  13549. SkeletonJson: SkeletonJson$1,
  13550. Skin: Skin$1,
  13551. Slot: Slot$1,
  13552. SlotData: SlotData$1,
  13553. get SpacingMode () { return SpacingMode$1; },
  13554. Spine: Spine$1,
  13555. SwirlEffect: SwirlEffect$1,
  13556. get TimelineType () { return TimelineType$1; },
  13557. TrackEntry: TrackEntry$1,
  13558. TransformConstraint: TransformConstraint$1,
  13559. TransformConstraintData: TransformConstraintData$1,
  13560. TransformConstraintTimeline: TransformConstraintTimeline$1,
  13561. get TransformMode () { return TransformMode$1; },
  13562. TranslateTimeline: TranslateTimeline$1,
  13563. TwoColorTimeline: TwoColorTimeline$1,
  13564. VertexAttachment: VertexAttachment$1
  13565. });
  13566. /* eslint-disable */
  13567. /**
  13568. * @public
  13569. */
  13570. class Attachment$2 {
  13571. constructor (name) {
  13572. if (name == null) throw new Error("name cannot be null.");
  13573. this.name = name;
  13574. }
  13575. }
  13576. /**
  13577. * Base class for an attachment with vertices that are transformed by one or more bones and can be deformed by a slot's
  13578. * {@link Slot#deform}.
  13579. * @public
  13580. */
  13581. class VertexAttachment$2 extends Attachment$2 {
  13582. static __initStatic() {this.nextID = 0;}
  13583. /** The unique ID for this attachment. */
  13584. __init() {this.id = VertexAttachment$2.nextID++;}
  13585. /** The bones which affect the {@link #getVertices()}. The array entries are, for each vertex, the number of bones affecting
  13586. * the vertex followed by that many bone indices, which is the index of the bone in {@link Skeleton#bones}. Will be null
  13587. * if this attachment has no weights. */
  13588. /** The vertex positions in the bone's coordinate system. For a non-weighted attachment, the values are `x,y`
  13589. * entries for each vertex. For a weighted attachment, the values are `x,y,weight` entries for each bone affecting
  13590. * each vertex. */
  13591. /** The maximum number of world vertex values that can be output by
  13592. * {@link #computeWorldVertices()} using the `count` parameter. */
  13593. __init2() {this.worldVerticesLength = 0;}
  13594. /** Deform keys for the deform attachment are also applied to this attachment. May be null if no deform keys should be applied. */
  13595. __init3() {this.deformAttachment = this;}
  13596. constructor (name) {
  13597. super(name);VertexAttachment$2.prototype.__init.call(this);VertexAttachment$2.prototype.__init2.call(this);VertexAttachment$2.prototype.__init3.call(this); }
  13598. computeWorldVerticesOld(slot, worldVertices) {
  13599. this.computeWorldVertices(slot, 0, this.worldVerticesLength, worldVertices, 0, 2);
  13600. }
  13601. /** Transforms the attachment's local {@link #vertices} to world coordinates. If the slot's {@link Slot#deform} is
  13602. * not empty, it is used to deform the vertices.
  13603. *
  13604. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  13605. * Runtimes Guide.
  13606. * @param start The index of the first {@link #vertices} value to transform. Each vertex has 2 values, x and y.
  13607. * @param count The number of world vertex values to output. Must be <= {@link #worldVerticesLength} - `start`.
  13608. * @param worldVertices The output world vertices. Must have a length >= `offset` + `count` *
  13609. * `stride` / 2.
  13610. * @param offset The `worldVertices` index to begin writing values.
  13611. * @param stride The number of `worldVertices` entries between the value pairs written. */
  13612. computeWorldVertices (slot, start, count, worldVertices, offset, stride) {
  13613. count = offset + (count >> 1) * stride;
  13614. let skeleton = slot.bone.skeleton;
  13615. let deformArray = slot.deform;
  13616. let vertices = this.vertices;
  13617. let bones = this.bones;
  13618. if (bones == null) {
  13619. if (deformArray.length > 0) vertices = deformArray;
  13620. let mat = slot.bone.matrix;
  13621. let x = mat.tx;
  13622. let y = mat.ty;
  13623. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  13624. for (let v = start, w = offset; w < count; v += 2, w += stride) {
  13625. let vx = vertices[v], vy = vertices[v + 1];
  13626. worldVertices[w] = vx * a + vy * b + x;
  13627. worldVertices[w + 1] = vx * c + vy * d + y;
  13628. }
  13629. return;
  13630. }
  13631. let v = 0, skip = 0;
  13632. for (let i = 0; i < start; i += 2) {
  13633. let n = bones[v];
  13634. v += n + 1;
  13635. skip += n;
  13636. }
  13637. let skeletonBones = skeleton.bones;
  13638. if (deformArray.length == 0) {
  13639. for (let w = offset, b = skip * 3; w < count; w += stride) {
  13640. let wx = 0, wy = 0;
  13641. let n = bones[v++];
  13642. n += v;
  13643. for (; v < n; v++, b += 3) {
  13644. let mat = skeletonBones[bones[v]].matrix;
  13645. let vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  13646. wx += (vx * mat.a + vy * mat.c + mat.tx) * weight;
  13647. wy += (vx * mat.b + vy * mat.d + mat.ty) * weight;
  13648. }
  13649. worldVertices[w] = wx;
  13650. worldVertices[w + 1] = wy;
  13651. }
  13652. } else {
  13653. let deform = deformArray;
  13654. for (let w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  13655. let wx = 0, wy = 0;
  13656. let n = bones[v++];
  13657. n += v;
  13658. for (; v < n; v++, b += 3, f += 2) {
  13659. let mat = skeletonBones[bones[v]].matrix;
  13660. let vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  13661. wx += (vx * mat.a + vy * mat.c + mat.tx) * weight;
  13662. wy += (vx * mat.b + vy * mat.d + mat.ty) * weight;
  13663. }
  13664. worldVertices[w] = wx;
  13665. worldVertices[w + 1] = wy;
  13666. }
  13667. }
  13668. }
  13669. /** Does not copy id (generated) or name (set on construction). **/
  13670. copyTo (attachment) {
  13671. if (this.bones != null) {
  13672. attachment.bones = new Array(this.bones.length);
  13673. Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
  13674. } else
  13675. attachment.bones = null;
  13676. if (this.vertices != null) {
  13677. attachment.vertices = Utils.newFloatArray(this.vertices.length);
  13678. Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
  13679. } else
  13680. attachment.vertices = null;
  13681. attachment.worldVerticesLength = this.worldVerticesLength;
  13682. attachment.deformAttachment = this.deformAttachment;
  13683. }
  13684. } VertexAttachment$2.__initStatic();
  13685. /**
  13686. * @public
  13687. */
  13688. class BoundingBoxAttachment$2 extends VertexAttachment$2 {
  13689. __init() {this.type = exports.AttachmentType.BoundingBox;}
  13690. __init2() {this.color = new Color(1, 1, 1, 1);}
  13691. constructor (name) {
  13692. super(name);BoundingBoxAttachment$2.prototype.__init.call(this);BoundingBoxAttachment$2.prototype.__init2.call(this); }
  13693. copy () {
  13694. let copy = new BoundingBoxAttachment$2(this.name);
  13695. this.copyTo(copy);
  13696. copy.color.setFromColor(this.color);
  13697. return copy;
  13698. }
  13699. }
  13700. /**
  13701. * @public
  13702. */
  13703. class ClippingAttachment$2 extends VertexAttachment$2 {
  13704. __init() {this.type = exports.AttachmentType.Clipping;}
  13705. // Nonessential.
  13706. /** The color of the clipping polygon as it was in Spine. Available only when nonessential data was exported. Clipping polygons
  13707. * are not usually rendered at runtime. */
  13708. __init2() {this.color = new Color(0.2275, 0.2275, 0.8078, 1);} // ce3a3aff
  13709. constructor (name) {
  13710. super(name);ClippingAttachment$2.prototype.__init.call(this);ClippingAttachment$2.prototype.__init2.call(this); }
  13711. copy () {
  13712. let copy = new ClippingAttachment$2(this.name);
  13713. this.copyTo(copy);
  13714. copy.endSlot = this.endSlot;
  13715. copy.color.setFromColor(this.color);
  13716. return copy;
  13717. }
  13718. }
  13719. /**
  13720. * @public
  13721. */
  13722. class MeshAttachment$2 extends VertexAttachment$2 {
  13723. __init() {this.type = exports.AttachmentType.Mesh;}
  13724. /** The name of the texture region for this attachment. */
  13725. /** The UV pair for each vertex, normalized within the texture region. */
  13726. /** Triplets of vertex indices which describe the mesh's triangulation. */
  13727. /** The color to tint the mesh. */
  13728. __init2() {this.color = new Color(1, 1, 1, 1);}
  13729. /** The width of the mesh's image. Available only when nonessential data was exported. */
  13730. /** The height of the mesh's image. Available only when nonessential data was exported. */
  13731. /** The number of entries at the beginning of {@link #vertices} that make up the mesh hull. */
  13732. /** Vertex index pairs describing edges for controling triangulation. Mesh triangles will never cross edges. Only available if
  13733. * nonessential data was exported. Triangulation is not performed at runtime. */
  13734. __init3() {this.tempColor = new Color(0, 0, 0, 0);}
  13735. constructor (name) {
  13736. super(name);MeshAttachment$2.prototype.__init.call(this);MeshAttachment$2.prototype.__init2.call(this);MeshAttachment$2.prototype.__init3.call(this); }
  13737. /** The parent mesh if this is a linked mesh, else null. A linked mesh shares the {@link #bones}, {@link #vertices},
  13738. * {@link #regionUVs}, {@link #triangles}, {@link #hullLength}, {@link #edges}, {@link #width}, and {@link #height} with the
  13739. * parent mesh, but may have a different {@link #name} or {@link #path} (and therefore a different texture). */
  13740. getParentMesh () {
  13741. return this.parentMesh;
  13742. }
  13743. /** @param parentMesh May be null. */
  13744. setParentMesh (parentMesh) {
  13745. this.parentMesh = parentMesh;
  13746. if (parentMesh != null) {
  13747. this.bones = parentMesh.bones;
  13748. this.vertices = parentMesh.vertices;
  13749. this.worldVerticesLength = parentMesh.worldVerticesLength;
  13750. this.regionUVs = parentMesh.regionUVs;
  13751. this.triangles = parentMesh.triangles;
  13752. this.hullLength = parentMesh.hullLength;
  13753. this.worldVerticesLength = parentMesh.worldVerticesLength;
  13754. }
  13755. }
  13756. copy () {
  13757. if (this.parentMesh != null) return this.newLinkedMesh();
  13758. let copy = new MeshAttachment$2(this.name);
  13759. copy.region = this.region;
  13760. copy.path = this.path;
  13761. copy.color.setFromColor(this.color);
  13762. this.copyTo(copy);
  13763. copy.regionUVs = new Float32Array(this.regionUVs.length);
  13764. Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
  13765. copy.triangles = new Array(this.triangles.length);
  13766. Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
  13767. copy.hullLength = this.hullLength;
  13768. // Nonessential.
  13769. if (this.edges != null) {
  13770. copy.edges = new Array(this.edges.length);
  13771. Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
  13772. }
  13773. copy.width = this.width;
  13774. copy.height = this.height;
  13775. return copy;
  13776. }
  13777. /** Returns a new mesh with the {@link #parentMesh} set to this mesh's parent mesh, if any, else to this mesh. **/
  13778. newLinkedMesh () {
  13779. let copy = new MeshAttachment$2(this.name);
  13780. copy.region = this.region;
  13781. copy.path = this.path;
  13782. copy.color.setFromColor(this.color);
  13783. copy.deformAttachment = this.deformAttachment;
  13784. copy.setParentMesh(this.parentMesh != null ? this.parentMesh : this);
  13785. // copy.updateUVs();
  13786. return copy;
  13787. }
  13788. }
  13789. /**
  13790. * @public
  13791. */
  13792. class PathAttachment$2 extends VertexAttachment$2 {
  13793. __init() {this.type = exports.AttachmentType.Path;}
  13794. /** The lengths along the path in the setup pose from the start of the path to the end of each Bezier curve. */
  13795. /** If true, the start and end knots are connected. */
  13796. __init2() {this.closed = false;}
  13797. /** If true, additional calculations are performed to make calculating positions along the path more accurate. If false, fewer
  13798. * calculations are performed but calculating positions along the path is less accurate. */
  13799. __init3() {this.constantSpeed = false;}
  13800. /** The color of the path as it was in Spine. Available only when nonessential data was exported. Paths are not usually
  13801. * rendered at runtime. */
  13802. __init4() {this.color = new Color(1, 1, 1, 1);}
  13803. constructor (name) {
  13804. super(name);PathAttachment$2.prototype.__init.call(this);PathAttachment$2.prototype.__init2.call(this);PathAttachment$2.prototype.__init3.call(this);PathAttachment$2.prototype.__init4.call(this); }
  13805. copy () {
  13806. let copy = new PathAttachment$2(this.name);
  13807. this.copyTo(copy);
  13808. copy.lengths = new Array(this.lengths.length);
  13809. Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
  13810. copy.closed = closed;
  13811. copy.constantSpeed = this.constantSpeed;
  13812. copy.color.setFromColor(this.color);
  13813. return copy;
  13814. }
  13815. }
  13816. /**
  13817. * @public
  13818. */
  13819. class PointAttachment$2 extends VertexAttachment$2 {
  13820. __init() {this.type = exports.AttachmentType.Point;}
  13821. /** The color of the point attachment as it was in Spine. Available only when nonessential data was exported. Point attachments
  13822. * are not usually rendered at runtime. */
  13823. __init2() {this.color = new Color(0.38, 0.94, 0, 1);}
  13824. constructor (name) {
  13825. super(name);PointAttachment$2.prototype.__init.call(this);PointAttachment$2.prototype.__init2.call(this); }
  13826. computeWorldPosition (bone, point) {
  13827. const mat = bone.matrix;
  13828. point.x = this.x * mat.a + this.y * mat.c + bone.worldX;
  13829. point.y = this.x * mat.b + this.y * mat.d + bone.worldY;
  13830. return point;
  13831. }
  13832. computeWorldRotation (bone) {
  13833. const mat = bone.matrix;
  13834. let cos = MathUtils.cosDeg(this.rotation), sin = MathUtils.sinDeg(this.rotation);
  13835. let x = cos * mat.a + sin * mat.c;
  13836. let y = cos * mat.b + sin * mat.d;
  13837. return Math.atan2(y, x) * MathUtils.radDeg;
  13838. }
  13839. copy () {
  13840. let copy = new PointAttachment$2(this.name);
  13841. copy.x = this.x;
  13842. copy.y = this.y;
  13843. copy.rotation = this.rotation;
  13844. copy.color.setFromColor(this.color);
  13845. return copy;
  13846. }
  13847. }
  13848. /**
  13849. * @public
  13850. */
  13851. class RegionAttachment$2 extends Attachment$2 {
  13852. __init() {this.type = exports.AttachmentType.Region;}
  13853. static __initStatic() {this.OX1 = 0;}
  13854. static __initStatic2() {this.OY1 = 1;}
  13855. static __initStatic3() {this.OX2 = 2;}
  13856. static __initStatic4() {this.OY2 = 3;}
  13857. static __initStatic5() {this.OX3 = 4;}
  13858. static __initStatic6() {this.OY3 = 5;}
  13859. static __initStatic7() {this.OX4 = 6;}
  13860. static __initStatic8() {this.OY4 = 7;}
  13861. static __initStatic9() {this.X1 = 0;}
  13862. static __initStatic10() {this.Y1 = 1;}
  13863. static __initStatic11() {this.C1R = 2;}
  13864. static __initStatic12() {this.C1G = 3;}
  13865. static __initStatic13() {this.C1B = 4;}
  13866. static __initStatic14() {this.C1A = 5;}
  13867. static __initStatic15() {this.U1 = 6;}
  13868. static __initStatic16() {this.V1 = 7;}
  13869. static __initStatic17() {this.X2 = 8;}
  13870. static __initStatic18() {this.Y2 = 9;}
  13871. static __initStatic19() {this.C2R = 10;}
  13872. static __initStatic20() {this.C2G = 11;}
  13873. static __initStatic21() {this.C2B = 12;}
  13874. static __initStatic22() {this.C2A = 13;}
  13875. static __initStatic23() {this.U2 = 14;}
  13876. static __initStatic24() {this.V2 = 15;}
  13877. static __initStatic25() {this.X3 = 16;}
  13878. static __initStatic26() {this.Y3 = 17;}
  13879. static __initStatic27() {this.C3R = 18;}
  13880. static __initStatic28() {this.C3G = 19;}
  13881. static __initStatic29() {this.C3B = 20;}
  13882. static __initStatic30() {this.C3A = 21;}
  13883. static __initStatic31() {this.U3 = 22;}
  13884. static __initStatic32() {this.V3 = 23;}
  13885. static __initStatic33() {this.X4 = 24;}
  13886. static __initStatic34() {this.Y4 = 25;}
  13887. static __initStatic35() {this.C4R = 26;}
  13888. static __initStatic36() {this.C4G = 27;}
  13889. static __initStatic37() {this.C4B = 28;}
  13890. static __initStatic38() {this.C4A = 29;}
  13891. static __initStatic39() {this.U4 = 30;}
  13892. static __initStatic40() {this.V4 = 31;}
  13893. /** The local x translation. */
  13894. __init2() {this.x = 0;}
  13895. /** The local y translation. */
  13896. __init3() {this.y = 0;}
  13897. /** The local scaleX. */
  13898. __init4() {this.scaleX = 1;}
  13899. /** The local scaleY. */
  13900. __init5() {this.scaleY = 1;}
  13901. /** The local rotation. */
  13902. __init6() {this.rotation = 0;}
  13903. /** The width of the region attachment in Spine. */
  13904. __init7() {this.width = 0;}
  13905. /** The height of the region attachment in Spine. */
  13906. __init8() {this.height = 0;}
  13907. /** The color to tint the region attachment. */
  13908. __init9() {this.color = new Color(1, 1, 1, 1);}
  13909. /** The name of the texture region for this attachment. */
  13910. /** For each of the 4 vertices, a pair of <code>x,y</code> values that is the local position of the vertex.
  13911. *
  13912. * See {@link #updateOffset()}. */
  13913. __init10() {this.offset = Utils.newFloatArray(8);}
  13914. __init11() {this.uvs = Utils.newFloatArray(8);}
  13915. __init12() {this.tempColor = new Color(1, 1, 1, 1);}
  13916. constructor (name) {
  13917. super(name);RegionAttachment$2.prototype.__init.call(this);RegionAttachment$2.prototype.__init2.call(this);RegionAttachment$2.prototype.__init3.call(this);RegionAttachment$2.prototype.__init4.call(this);RegionAttachment$2.prototype.__init5.call(this);RegionAttachment$2.prototype.__init6.call(this);RegionAttachment$2.prototype.__init7.call(this);RegionAttachment$2.prototype.__init8.call(this);RegionAttachment$2.prototype.__init9.call(this);RegionAttachment$2.prototype.__init10.call(this);RegionAttachment$2.prototype.__init11.call(this);RegionAttachment$2.prototype.__init12.call(this); }
  13918. /** Calculates the {@link #offset} using the region settings. Must be called after changing region settings. */
  13919. updateOffset () {
  13920. let regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  13921. let regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  13922. let localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  13923. let localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  13924. let localX2 = localX + this.region.width * regionScaleX;
  13925. let localY2 = localY + this.region.height * regionScaleY;
  13926. let radians = this.rotation * Math.PI / 180;
  13927. let cos = Math.cos(radians);
  13928. let sin = Math.sin(radians);
  13929. let localXCos = localX * cos + this.x;
  13930. let localXSin = localX * sin;
  13931. let localYCos = localY * cos + this.y;
  13932. let localYSin = localY * sin;
  13933. let localX2Cos = localX2 * cos + this.x;
  13934. let localX2Sin = localX2 * sin;
  13935. let localY2Cos = localY2 * cos + this.y;
  13936. let localY2Sin = localY2 * sin;
  13937. let offset = this.offset;
  13938. offset[RegionAttachment$2.OX1] = localXCos - localYSin;
  13939. offset[RegionAttachment$2.OY1] = localYCos + localXSin;
  13940. offset[RegionAttachment$2.OX2] = localXCos - localY2Sin;
  13941. offset[RegionAttachment$2.OY2] = localY2Cos + localXSin;
  13942. offset[RegionAttachment$2.OX3] = localX2Cos - localY2Sin;
  13943. offset[RegionAttachment$2.OY3] = localY2Cos + localX2Sin;
  13944. offset[RegionAttachment$2.OX4] = localX2Cos - localYSin;
  13945. offset[RegionAttachment$2.OY4] = localYCos + localX2Sin;
  13946. }
  13947. setRegion (region) {
  13948. this.region = region;
  13949. let uvs = this.uvs;
  13950. if (region.degrees == 90) {
  13951. uvs[2] = region.u;
  13952. uvs[3] = region.v2;
  13953. uvs[4] = region.u;
  13954. uvs[5] = region.v;
  13955. uvs[6] = region.u2;
  13956. uvs[7] = region.v;
  13957. uvs[0] = region.u2;
  13958. uvs[1] = region.v2;
  13959. } else {
  13960. uvs[0] = region.u;
  13961. uvs[1] = region.v2;
  13962. uvs[2] = region.u;
  13963. uvs[3] = region.v;
  13964. uvs[4] = region.u2;
  13965. uvs[5] = region.v;
  13966. uvs[6] = region.u2;
  13967. uvs[7] = region.v2;
  13968. }
  13969. }
  13970. /** Transforms the attachment's four vertices to world coordinates.
  13971. *
  13972. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  13973. * Runtimes Guide.
  13974. * @param worldVertices The output world vertices. Must have a length >= `offset` + 8.
  13975. * @param offset The `worldVertices` index to begin writing values.
  13976. * @param stride The number of `worldVertices` entries between the value pairs written. */
  13977. computeWorldVertices (bone, worldVertices, offset, stride) {
  13978. let vertexOffset = this.offset;
  13979. let mat = bone.matrix;
  13980. let x = mat.tx, y = mat.ty;
  13981. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  13982. let offsetX = 0, offsetY = 0;
  13983. offsetX = vertexOffset[RegionAttachment$2.OX1];
  13984. offsetY = vertexOffset[RegionAttachment$2.OY1];
  13985. worldVertices[offset] = offsetX * a + offsetY * b + x; // br
  13986. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  13987. offset += stride;
  13988. offsetX = vertexOffset[RegionAttachment$2.OX2];
  13989. offsetY = vertexOffset[RegionAttachment$2.OY2];
  13990. worldVertices[offset] = offsetX * a + offsetY * b + x; // bl
  13991. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  13992. offset += stride;
  13993. offsetX = vertexOffset[RegionAttachment$2.OX3];
  13994. offsetY = vertexOffset[RegionAttachment$2.OY3];
  13995. worldVertices[offset] = offsetX * a + offsetY * b + x; // ul
  13996. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  13997. offset += stride;
  13998. offsetX = vertexOffset[RegionAttachment$2.OX4];
  13999. offsetY = vertexOffset[RegionAttachment$2.OY4];
  14000. worldVertices[offset] = offsetX * a + offsetY * b + x; // ur
  14001. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  14002. }
  14003. copy () {
  14004. let copy = new RegionAttachment$2(this.name);
  14005. copy.region = this.region;
  14006. copy.rendererObject = this.rendererObject;
  14007. copy.path = this.path;
  14008. copy.x = this.x;
  14009. copy.y = this.y;
  14010. copy.scaleX = this.scaleX;
  14011. copy.scaleY = this.scaleY;
  14012. copy.rotation = this.rotation;
  14013. copy.width = this.width;
  14014. copy.height = this.height;
  14015. Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
  14016. Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
  14017. copy.color.setFromColor(this.color);
  14018. return copy;
  14019. }
  14020. } RegionAttachment$2.__initStatic(); RegionAttachment$2.__initStatic2(); RegionAttachment$2.__initStatic3(); RegionAttachment$2.__initStatic4(); RegionAttachment$2.__initStatic5(); RegionAttachment$2.__initStatic6(); RegionAttachment$2.__initStatic7(); RegionAttachment$2.__initStatic8(); RegionAttachment$2.__initStatic9(); RegionAttachment$2.__initStatic10(); RegionAttachment$2.__initStatic11(); RegionAttachment$2.__initStatic12(); RegionAttachment$2.__initStatic13(); RegionAttachment$2.__initStatic14(); RegionAttachment$2.__initStatic15(); RegionAttachment$2.__initStatic16(); RegionAttachment$2.__initStatic17(); RegionAttachment$2.__initStatic18(); RegionAttachment$2.__initStatic19(); RegionAttachment$2.__initStatic20(); RegionAttachment$2.__initStatic21(); RegionAttachment$2.__initStatic22(); RegionAttachment$2.__initStatic23(); RegionAttachment$2.__initStatic24(); RegionAttachment$2.__initStatic25(); RegionAttachment$2.__initStatic26(); RegionAttachment$2.__initStatic27(); RegionAttachment$2.__initStatic28(); RegionAttachment$2.__initStatic29(); RegionAttachment$2.__initStatic30(); RegionAttachment$2.__initStatic31(); RegionAttachment$2.__initStatic32(); RegionAttachment$2.__initStatic33(); RegionAttachment$2.__initStatic34(); RegionAttachment$2.__initStatic35(); RegionAttachment$2.__initStatic36(); RegionAttachment$2.__initStatic37(); RegionAttachment$2.__initStatic38(); RegionAttachment$2.__initStatic39(); RegionAttachment$2.__initStatic40();
  14021. /**
  14022. * @public
  14023. */
  14024. class JitterEffect$2 {
  14025. __init() {this.jitterX = 0;}
  14026. __init2() {this.jitterY = 0;}
  14027. constructor (jitterX, jitterY) {JitterEffect$2.prototype.__init.call(this);JitterEffect$2.prototype.__init2.call(this);
  14028. this.jitterX = jitterX;
  14029. this.jitterY = jitterY;
  14030. }
  14031. //@ts-ignore
  14032. begin(skeleton) {
  14033. }
  14034. //@ts-ignore
  14035. transform(position, uv, light, dark) {
  14036. position.x += MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  14037. position.y += MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  14038. }
  14039. end() {
  14040. }
  14041. }
  14042. /**
  14043. * @public
  14044. */
  14045. class SwirlEffect$2 {
  14046. static __initStatic() {this.interpolation = new PowOut(2);}
  14047. __init() {this.centerX = 0;}
  14048. __init2() {this.centerY = 0;}
  14049. __init3() {this.radius = 0;}
  14050. __init4() {this.angle = 0;}
  14051. __init5() {this.worldX = 0;}
  14052. __init6() {this.worldY = 0;}
  14053. constructor (radius) {SwirlEffect$2.prototype.__init.call(this);SwirlEffect$2.prototype.__init2.call(this);SwirlEffect$2.prototype.__init3.call(this);SwirlEffect$2.prototype.__init4.call(this);SwirlEffect$2.prototype.__init5.call(this);SwirlEffect$2.prototype.__init6.call(this);
  14054. this.radius = radius;
  14055. }
  14056. begin(skeleton) {
  14057. this.worldX = skeleton.x + this.centerX;
  14058. this.worldY = skeleton.y + this.centerY;
  14059. }
  14060. //@ts-ignore
  14061. transform(position, uv, light, dark) {
  14062. let radAngle = this.angle * MathUtils.degreesToRadians;
  14063. let x = position.x - this.worldX;
  14064. let y = position.y - this.worldY;
  14065. let dist = Math.sqrt(x * x + y * y);
  14066. if (dist < this.radius) {
  14067. let theta = SwirlEffect$2.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  14068. let cos = Math.cos(theta);
  14069. let sin = Math.sin(theta);
  14070. position.x = cos * x - sin * y + this.worldX;
  14071. position.y = sin * x + cos * y + this.worldY;
  14072. }
  14073. }
  14074. end() {
  14075. }
  14076. } SwirlEffect$2.__initStatic();
  14077. /**
  14078. * A simple container for a list of timelines and a name.
  14079. * @public
  14080. * */
  14081. class Animation$2 {
  14082. /** The animation's name, which is unique across all animations in the skeleton. */
  14083. /** The duration of the animation in seconds, which is the highest time of all keys in the timeline. */
  14084. constructor (name, timelines, duration) {
  14085. if (name == null) throw new Error("name cannot be null.");
  14086. if (timelines == null) throw new Error("timelines cannot be null.");
  14087. this.name = name;
  14088. this.timelines = timelines;
  14089. this.timelineIds = new StringSet();
  14090. for (var i = 0; i < timelines.length; i++)
  14091. this.timelineIds.addAll(timelines[i].getPropertyIds());
  14092. this.duration = duration;
  14093. }
  14094. hasTimeline(ids) {
  14095. for (let i = 0; i < ids.length; i++) {
  14096. if (this.timelineIds.contains(ids[i])) return true;
  14097. }
  14098. return false;
  14099. }
  14100. /** Applies all the animation's timelines to the specified skeleton.
  14101. *
  14102. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
  14103. * @param loop If true, the animation repeats after {@link #getDuration()}.
  14104. * @param events May be null to ignore fired events. */
  14105. apply (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
  14106. if (skeleton == null) throw new Error("skeleton cannot be null.");
  14107. if (loop && this.duration != 0) {
  14108. time %= this.duration;
  14109. if (lastTime > 0) lastTime %= this.duration;
  14110. }
  14111. let timelines = this.timelines;
  14112. for (let i = 0, n = timelines.length; i < n; i++)
  14113. timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
  14114. }
  14115. static search (frames, time) {
  14116. let n = frames.length;
  14117. for (let i = 1; i < n; i++)
  14118. if (frames[i] > time) return i - 1;
  14119. return n - 1;
  14120. }
  14121. static search2 (values, time, step) {
  14122. let n = values.length;
  14123. for (let i = step; i < n; i += step)
  14124. if (values[i] > time) return i - step;
  14125. return n - step;
  14126. }
  14127. }
  14128. /** Controls how a timeline value is mixed with the setup pose value or current pose value when a timeline's `alpha`
  14129. * < 1.
  14130. *
  14131. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
  14132. * @public
  14133. * */
  14134. var MixBlend$2; (function (MixBlend) {
  14135. /** Transitions from the setup value to the timeline value (the current value is not used). Before the first key, the setup
  14136. * value is set. */
  14137. const setup = 0; MixBlend[MixBlend["setup"] = setup] = "setup";
  14138. /** Transitions from the current value to the timeline value. Before the first key, transitions from the current value to
  14139. * the setup value. Timelines which perform instant transitions, such as {@link DrawOrderTimeline} or
  14140. * {@link AttachmentTimeline}, use the setup value before the first key.
  14141. *
  14142. * `first` is intended for the first animations applied, not for animations layered on top of those. */
  14143. const first = setup + 1; MixBlend[MixBlend["first"] = first] = "first";
  14144. /** Transitions from the current value to the timeline value. No change is made before the first key (the current value is
  14145. * kept until the first key).
  14146. *
  14147. * `replace` is intended for animations layered on top of others, not for the first animations applied. */
  14148. const replace = first + 1; MixBlend[MixBlend["replace"] = replace] = "replace";
  14149. /** Transitions from the current value to the current value plus the timeline value. No change is made before the first key
  14150. * (the current value is kept until the first key).
  14151. *
  14152. * `add` is intended for animations layered on top of others, not for the first animations applied. Properties
  14153. * keyed by additive animations must be set manually or by another animation before applying the additive animations, else
  14154. * the property values will increase continually. */
  14155. const add = replace + 1; MixBlend[MixBlend["add"] = add] = "add";
  14156. })(MixBlend$2 || (MixBlend$2 = {}));
  14157. /** Indicates whether a timeline's `alpha` is mixing out over time toward 0 (the setup or current pose value) or
  14158. * mixing in toward 1 (the timeline's value).
  14159. *
  14160. * See Timeline {@link Timeline#apply(Skeleton, float, float, Array, float, MixBlend, MixDirection)}.
  14161. * @public
  14162. * */
  14163. var MixDirection$2; (function (MixDirection) {
  14164. const mixIn = 0; MixDirection[MixDirection["mixIn"] = mixIn] = "mixIn"; const mixOut = mixIn + 1; MixDirection[MixDirection["mixOut"] = mixOut] = "mixOut";
  14165. })(MixDirection$2 || (MixDirection$2 = {}));
  14166. /**
  14167. * @public
  14168. */
  14169. var Property; (function (Property) {
  14170. const rotate = 0; Property[Property["rotate"] = rotate] = "rotate"; const x = rotate + 1; Property[Property["x"] = x] = "x"; const y = x + 1; Property[Property["y"] = y] = "y"; const scaleX = y + 1; Property[Property["scaleX"] = scaleX] = "scaleX"; const scaleY = scaleX + 1; Property[Property["scaleY"] = scaleY] = "scaleY"; const shearX = scaleY + 1; Property[Property["shearX"] = shearX] = "shearX"; const shearY = shearX + 1; Property[Property["shearY"] = shearY] = "shearY"; //
  14171. const rgb = shearY + 1; Property[Property["rgb"] = rgb] = "rgb"; const alpha = rgb + 1; Property[Property["alpha"] = alpha] = "alpha"; const rgb2 = alpha + 1; Property[Property["rgb2"] = rgb2] = "rgb2"; //
  14172. const attachment = rgb2 + 1; Property[Property["attachment"] = attachment] = "attachment"; const deform = attachment + 1; Property[Property["deform"] = deform] = "deform"; //
  14173. const event = deform + 1; Property[Property["event"] = event] = "event"; const drawOrder = event + 1; Property[Property["drawOrder"] = drawOrder] = "drawOrder"; //
  14174. const ikConstraint = drawOrder + 1; Property[Property["ikConstraint"] = ikConstraint] = "ikConstraint"; const transformConstraint = ikConstraint + 1; Property[Property["transformConstraint"] = transformConstraint] = "transformConstraint"; //
  14175. const pathConstraintPosition = transformConstraint + 1; Property[Property["pathConstraintPosition"] = pathConstraintPosition] = "pathConstraintPosition"; const pathConstraintSpacing = pathConstraintPosition + 1; Property[Property["pathConstraintSpacing"] = pathConstraintSpacing] = "pathConstraintSpacing"; const pathConstraintMix = pathConstraintSpacing + 1; Property[Property["pathConstraintMix"] = pathConstraintMix] = "pathConstraintMix";
  14176. })(Property || (Property = {}));
  14177. /** The interface for all timelines.
  14178. * @public
  14179. * */
  14180. class Timeline {
  14181. constructor(frameCount, propertyIds) {
  14182. this.propertyIds = propertyIds;
  14183. this.frames = Utils.newFloatArray(frameCount * this.getFrameEntries());
  14184. }
  14185. getPropertyIds () {
  14186. return this.propertyIds;
  14187. }
  14188. getFrameCount () {
  14189. return this.frames.length / this.getFrameEntries();
  14190. }
  14191. getDuration () {
  14192. return this.frames[this.frames.length - this.getFrameEntries()];
  14193. }
  14194. }
  14195. /**
  14196. * @public
  14197. */
  14198. /** The base class for timelines that use interpolation between key frame values.
  14199. * @public
  14200. * */
  14201. class CurveTimeline$2 extends Timeline {
  14202. static __initStatic() {this.LINEAR = 0;} static __initStatic2() {this.STEPPED = 1;} static __initStatic3() {this.BEZIER = 2;}
  14203. static __initStatic4() {this.BEZIER_SIZE = 18;}
  14204. // type, x, y, ...
  14205. constructor (frameCount, bezierCount, propertyIds) {
  14206. super(frameCount, propertyIds);
  14207. this.curves = Utils.newFloatArray(frameCount + bezierCount * CurveTimeline$2.BEZIER_SIZE);
  14208. this.curves[frameCount - 1] = CurveTimeline$2.STEPPED;
  14209. }
  14210. /** Sets the specified key frame to linear interpolation. */
  14211. setLinear (frame) {
  14212. this.curves[frame] = CurveTimeline$2.LINEAR;
  14213. }
  14214. /** Sets the specified key frame to stepped interpolation. */
  14215. setStepped (frame) {
  14216. this.curves[frame] = CurveTimeline$2.STEPPED;
  14217. }
  14218. /** Shrinks the storage for Bezier curves, for use when <code>bezierCount</code> (specified in the constructor) was larger
  14219. * than the actual number of Bezier curves. */
  14220. shrink (bezierCount) {
  14221. let size = this.getFrameCount() + bezierCount * CurveTimeline$2.BEZIER_SIZE;
  14222. if (this.curves.length > size) {
  14223. let newCurves = Utils.newFloatArray(size);
  14224. Utils.arrayCopy(this.curves, 0, newCurves, 0, size);
  14225. this.curves = newCurves;
  14226. }
  14227. }
  14228. /** Stores the segments for the specified Bezier curve. For timelines that modify multiple values, there may be more than
  14229. * one curve per frame.
  14230. * @param bezier The ordinal of this Bezier curve for this timeline, between 0 and <code>bezierCount - 1</code> (specified
  14231. * in the constructor), inclusive.
  14232. * @param frame Between 0 and <code>frameCount - 1</code>, inclusive.
  14233. * @param value The index of the value for this frame that this curve is used for.
  14234. * @param time1 The time for the first key.
  14235. * @param value1 The value for the first key.
  14236. * @param cx1 The time for the first Bezier handle.
  14237. * @param cy1 The value for the first Bezier handle.
  14238. * @param cx2 The time of the second Bezier handle.
  14239. * @param cy2 The value for the second Bezier handle.
  14240. * @param time2 The time for the second key.
  14241. * @param value2 The value for the second key. */
  14242. setBezier (bezier, frame, value, time1, value1, cx1, cy1, cx2,
  14243. cy2, time2, value2) {
  14244. let curves = this.curves;
  14245. let i = this.getFrameCount() + bezier * CurveTimeline$2.BEZIER_SIZE;
  14246. if (value == 0) curves[frame] = CurveTimeline$2.BEZIER + i;
  14247. let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03;
  14248. let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 0.006;
  14249. let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
  14250. let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667;
  14251. let x = time1 + dx, y = value1 + dy;
  14252. for (let n = i + CurveTimeline$2.BEZIER_SIZE; i < n; i += 2) {
  14253. curves[i] = x;
  14254. curves[i + 1] = y;
  14255. dx += ddx;
  14256. dy += ddy;
  14257. ddx += dddx;
  14258. ddy += dddy;
  14259. x += dx;
  14260. y += dy;
  14261. }
  14262. }
  14263. /** Returns the Bezier interpolated value for the specified time.
  14264. * @param frameIndex The index into {@link #getFrames()} for the values of the frame before <code>time</code>.
  14265. * @param valueOffset The offset from <code>frameIndex</code> to the value this curve is used for.
  14266. * @param i The index of the Bezier segments. See {@link #getCurveType(int)}. */
  14267. getBezierValue (time, frameIndex, valueOffset, i) {
  14268. let curves = this.curves;
  14269. let frames = this.frames;
  14270. if (curves[i] > time) {
  14271. let x = frames[frameIndex], y = frames[frameIndex + valueOffset];
  14272. return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y);
  14273. }
  14274. let n = i + CurveTimeline$2.BEZIER_SIZE;
  14275. for (i += 2; i < n; i += 2) {
  14276. if (curves[i] >= time) {
  14277. let x = curves[i - 2], y = curves[i - 1];
  14278. return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y);
  14279. }
  14280. }
  14281. frameIndex += this.getFrameEntries();
  14282. let x = curves[n - 2], y = curves[n - 1];
  14283. return y + (time - x) / (frames[frameIndex] - x) * (frames[frameIndex + valueOffset] - y);
  14284. }
  14285. } CurveTimeline$2.__initStatic(); CurveTimeline$2.__initStatic2(); CurveTimeline$2.__initStatic3(); CurveTimeline$2.__initStatic4();
  14286. /**
  14287. * @public
  14288. */
  14289. class CurveTimeline1 extends CurveTimeline$2 {
  14290. static __initStatic5() {this.ENTRIES = 2;}
  14291. static __initStatic6() {this.VALUE = 1;}
  14292. constructor(frameCount, bezierCount, propertyIds) {
  14293. super(frameCount, bezierCount, propertyIds);
  14294. }
  14295. getFrameEntries() {
  14296. return CurveTimeline1.ENTRIES;
  14297. }
  14298. /** Sets the time and value for the specified frame.
  14299. * @param frame Between 0 and <code>frameCount</code>, inclusive.
  14300. * @param time The frame time in seconds. */
  14301. setFrame (frame, time, value) {
  14302. frame <<= 1;
  14303. this.frames[frame] = time;
  14304. this.frames[frame + CurveTimeline1.VALUE] = value;
  14305. }
  14306. /** Returns the interpolated value for the specified time. */
  14307. getCurveValue (time) {
  14308. let frames = this.frames;
  14309. let i = frames.length - 2;
  14310. for (let ii = 2; ii <= i; ii += 2) {
  14311. if (frames[ii] > time) {
  14312. i = ii - 2;
  14313. break;
  14314. }
  14315. }
  14316. let curveType = this.curves[i >> 1];
  14317. switch (curveType) {
  14318. case CurveTimeline$2.LINEAR:
  14319. let before = frames[i], value = frames[i + CurveTimeline1.VALUE];
  14320. return value + (time - before) / (frames[i + CurveTimeline1.ENTRIES] - before) * (frames[i + CurveTimeline1.ENTRIES + CurveTimeline1.VALUE] - value);
  14321. case CurveTimeline$2.STEPPED:
  14322. return frames[i + CurveTimeline1.VALUE];
  14323. }
  14324. return this.getBezierValue(time, i, CurveTimeline1.VALUE, curveType - CurveTimeline1.BEZIER);
  14325. }
  14326. } CurveTimeline1.__initStatic5(); CurveTimeline1.__initStatic6();
  14327. /** The base class for a {@link CurveTimeline} which sets two properties.
  14328. * @public
  14329. * */
  14330. class CurveTimeline2 extends CurveTimeline$2 {
  14331. static __initStatic7() {this.ENTRIES = 3;}
  14332. static __initStatic8() {this.VALUE1 = 1;}
  14333. static __initStatic9() {this.VALUE2 = 2;}
  14334. /** @param bezierCount The maximum number of Bezier curves. See {@link #shrink(int)}.
  14335. * @param propertyIds Unique identifiers for the properties the timeline modifies. */
  14336. constructor (frameCount, bezierCount, propertyIds) {
  14337. super(frameCount, bezierCount, propertyIds);
  14338. }
  14339. getFrameEntries () {
  14340. return CurveTimeline2.ENTRIES;
  14341. }
  14342. /** Sets the time and values for the specified frame.
  14343. * @param frame Between 0 and <code>frameCount</code>, inclusive.
  14344. * @param time The frame time in seconds. */
  14345. setFrame (frame, time, value1, value2) {
  14346. frame *= CurveTimeline2.ENTRIES;
  14347. let frames = this.frames;
  14348. frames[frame] = time;
  14349. frames[frame + CurveTimeline2.VALUE1] = value1;
  14350. frames[frame + CurveTimeline2.VALUE2] = value2;
  14351. }
  14352. } CurveTimeline2.__initStatic7(); CurveTimeline2.__initStatic8(); CurveTimeline2.__initStatic9();
  14353. /** Changes a bone's local {@link Bone#rotation}.
  14354. * @public
  14355. * */
  14356. class RotateTimeline$2 extends CurveTimeline1 {
  14357. __init() {this.boneIndex = 0;}
  14358. constructor (frameCount, bezierCount, boneIndex) {
  14359. super(frameCount, bezierCount, [
  14360. Property.rotate + "|" + boneIndex
  14361. ]);RotateTimeline$2.prototype.__init.call(this); this.boneIndex = boneIndex;
  14362. }
  14363. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14364. let frames = this.frames;
  14365. let bone = skeleton.bones[this.boneIndex];
  14366. if (!bone.active) return;
  14367. if (time < frames[0]) {
  14368. switch (blend) {
  14369. case MixBlend$2.setup:
  14370. bone.rotation = bone.data.rotation;
  14371. return;
  14372. case MixBlend$2.first:
  14373. bone.rotation += (bone.data.rotation - bone.rotation) * alpha;
  14374. }
  14375. return;
  14376. }
  14377. let r = this.getCurveValue(time);
  14378. switch (blend) {
  14379. case MixBlend$2.setup:
  14380. bone.rotation = bone.data.rotation + r * alpha;
  14381. break;
  14382. case MixBlend$2.first:
  14383. case MixBlend$2.replace:
  14384. r += bone.data.rotation - bone.rotation;
  14385. case MixBlend$2.add:
  14386. bone.rotation += r * alpha;
  14387. }
  14388. }
  14389. }
  14390. /** Changes a bone's local {@link Bone#x} and {@link Bone#y}.
  14391. * @public
  14392. * */
  14393. class TranslateTimeline$2 extends CurveTimeline2 {
  14394. __init2() {this.boneIndex = 0;}
  14395. constructor (frameCount, bezierCount, boneIndex) {
  14396. super(frameCount, bezierCount, [
  14397. Property.x + "|" + boneIndex,
  14398. Property.y + "|" + boneIndex,
  14399. ]);TranslateTimeline$2.prototype.__init2.call(this); this.boneIndex = boneIndex;
  14400. }
  14401. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14402. let frames = this.frames;
  14403. let bone = skeleton.bones[this.boneIndex];
  14404. if (!bone.active) return;
  14405. if (time < frames[0]) {
  14406. switch (blend) {
  14407. case MixBlend$2.setup:
  14408. bone.x = bone.data.x;
  14409. bone.y = bone.data.y;
  14410. return;
  14411. case MixBlend$2.first:
  14412. bone.x += (bone.data.x - bone.x) * alpha;
  14413. bone.y += (bone.data.y - bone.y) * alpha;
  14414. }
  14415. return;
  14416. }
  14417. let x = 0, y = 0;
  14418. let i = Animation$2.search2(frames, time, CurveTimeline2.ENTRIES);
  14419. let curveType = this.curves[i / CurveTimeline2.ENTRIES];
  14420. switch (curveType) {
  14421. case CurveTimeline$2.LINEAR:
  14422. let before = frames[i];
  14423. x = frames[i + CurveTimeline2.VALUE1];
  14424. y = frames[i + CurveTimeline2.VALUE2];
  14425. let t = (time - before) / (frames[i + CurveTimeline2.ENTRIES] - before);
  14426. x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t;
  14427. y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t;
  14428. break;
  14429. case CurveTimeline$2.STEPPED:
  14430. x = frames[i + CurveTimeline2.VALUE1];
  14431. y = frames[i + CurveTimeline2.VALUE2];
  14432. break;
  14433. default:
  14434. x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline$2.BEZIER);
  14435. y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline$2.BEZIER_SIZE - CurveTimeline$2.BEZIER);
  14436. }
  14437. switch (blend) {
  14438. case MixBlend$2.setup:
  14439. bone.x = bone.data.x + x * alpha;
  14440. bone.y = bone.data.y + y * alpha;
  14441. break;
  14442. case MixBlend$2.first:
  14443. case MixBlend$2.replace:
  14444. bone.x += (bone.data.x + x - bone.x) * alpha;
  14445. bone.y += (bone.data.y + y - bone.y) * alpha;
  14446. break;
  14447. case MixBlend$2.add:
  14448. bone.x += x * alpha;
  14449. bone.y += y * alpha;
  14450. }
  14451. }
  14452. }
  14453. /** Changes a bone's local {@link Bone#x}.
  14454. * @public
  14455. * */
  14456. class TranslateXTimeline extends CurveTimeline1 {
  14457. __init3() {this.boneIndex = 0;}
  14458. constructor (frameCount, bezierCount, boneIndex) {
  14459. super(frameCount, bezierCount, [
  14460. Property.x + "|" + boneIndex
  14461. ]);TranslateXTimeline.prototype.__init3.call(this); this.boneIndex = boneIndex;
  14462. }
  14463. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14464. let frames = this.frames;
  14465. let bone = skeleton.bones[this.boneIndex];
  14466. if (!bone.active) return;
  14467. if (time < frames[0]) {
  14468. switch (blend) {
  14469. case MixBlend$2.setup:
  14470. bone.x = bone.data.x;
  14471. return;
  14472. case MixBlend$2.first:
  14473. bone.x += (bone.data.x - bone.x) * alpha;
  14474. }
  14475. return;
  14476. }
  14477. let x = this.getCurveValue(time);
  14478. switch (blend) {
  14479. case MixBlend$2.setup:
  14480. bone.x = bone.data.x + x * alpha;
  14481. break;
  14482. case MixBlend$2.first:
  14483. case MixBlend$2.replace:
  14484. bone.x += (bone.data.x + x - bone.x) * alpha;
  14485. break;
  14486. case MixBlend$2.add:
  14487. bone.x += x * alpha;
  14488. }
  14489. }
  14490. }
  14491. /** Changes a bone's local {@link Bone#x}.
  14492. * @public
  14493. * */
  14494. class TranslateYTimeline extends CurveTimeline1 {
  14495. __init4() {this.boneIndex = 0;}
  14496. constructor (frameCount, bezierCount, boneIndex) {
  14497. super(frameCount, bezierCount, [
  14498. Property.y + "|" + boneIndex
  14499. ]);TranslateYTimeline.prototype.__init4.call(this); this.boneIndex = boneIndex;
  14500. }
  14501. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14502. let frames = this.frames;
  14503. let bone = skeleton.bones[this.boneIndex];
  14504. if (!bone.active) return;
  14505. if (time < frames[0]) {
  14506. switch (blend) {
  14507. case MixBlend$2.setup:
  14508. bone.y = bone.data.y;
  14509. return;
  14510. case MixBlend$2.first:
  14511. bone.y += (bone.data.y - bone.y) * alpha;
  14512. }
  14513. return;
  14514. }
  14515. let y = this.getCurveValue(time);
  14516. switch (blend) {
  14517. case MixBlend$2.setup:
  14518. bone.y = bone.data.y + y * alpha;
  14519. break;
  14520. case MixBlend$2.first:
  14521. case MixBlend$2.replace:
  14522. bone.y += (bone.data.y + y - bone.y) * alpha;
  14523. break;
  14524. case MixBlend$2.add:
  14525. bone.y += y * alpha;
  14526. }
  14527. }
  14528. }
  14529. /** Changes a bone's local {@link Bone#scaleX)} and {@link Bone#scaleY}.
  14530. * @public
  14531. * */
  14532. class ScaleTimeline$2 extends CurveTimeline2 {
  14533. __init5() {this.boneIndex = 0;}
  14534. constructor (frameCount, bezierCount, boneIndex) {
  14535. super(frameCount, bezierCount, [
  14536. Property.scaleX + "|" + boneIndex,
  14537. Property.scaleY + "|" + boneIndex
  14538. ]);ScaleTimeline$2.prototype.__init5.call(this); this.boneIndex = boneIndex;
  14539. }
  14540. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14541. let frames = this.frames;
  14542. let bone = skeleton.bones[this.boneIndex];
  14543. if (!bone.active) return;
  14544. if (time < frames[0]) {
  14545. switch (blend) {
  14546. case MixBlend$2.setup:
  14547. bone.scaleX = bone.data.scaleX;
  14548. bone.scaleY = bone.data.scaleY;
  14549. return;
  14550. case MixBlend$2.first:
  14551. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  14552. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  14553. }
  14554. return;
  14555. }
  14556. let x = 0, y = 0;
  14557. let i = Animation$2.search2(frames, time, CurveTimeline2.ENTRIES);
  14558. let curveType = this.curves[i / CurveTimeline2.ENTRIES];
  14559. switch (curveType) {
  14560. case CurveTimeline$2.LINEAR:
  14561. let before = frames[i];
  14562. x = frames[i + CurveTimeline2.VALUE1];
  14563. y = frames[i + CurveTimeline2.VALUE2];
  14564. let t = (time - before) / (frames[i + CurveTimeline2.ENTRIES] - before);
  14565. x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t;
  14566. y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t;
  14567. break;
  14568. case CurveTimeline$2.STEPPED:
  14569. x = frames[i + CurveTimeline2.VALUE1];
  14570. y = frames[i + CurveTimeline2.VALUE2];
  14571. break;
  14572. default:
  14573. x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline2.BEZIER);
  14574. y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline2.BEZIER_SIZE - CurveTimeline2.BEZIER);
  14575. }
  14576. x *= bone.data.scaleX;
  14577. y *= bone.data.scaleY;
  14578. if (alpha == 1) {
  14579. if (blend == MixBlend$2.add) {
  14580. bone.scaleX += x - bone.data.scaleX;
  14581. bone.scaleY += y - bone.data.scaleY;
  14582. } else {
  14583. bone.scaleX = x;
  14584. bone.scaleY = y;
  14585. }
  14586. } else {
  14587. let bx = 0, by = 0;
  14588. if (direction == MixDirection$2.mixOut) {
  14589. switch (blend) {
  14590. case MixBlend$2.setup:
  14591. bx = bone.data.scaleX;
  14592. by = bone.data.scaleY;
  14593. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  14594. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  14595. break;
  14596. case MixBlend$2.first:
  14597. case MixBlend$2.replace:
  14598. bx = bone.scaleX;
  14599. by = bone.scaleY;
  14600. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  14601. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  14602. break;
  14603. case MixBlend$2.add:
  14604. bx = bone.scaleX;
  14605. by = bone.scaleY;
  14606. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  14607. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - bone.data.scaleY) * alpha;
  14608. }
  14609. } else {
  14610. switch (blend) {
  14611. case MixBlend$2.setup:
  14612. bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
  14613. by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
  14614. bone.scaleX = bx + (x - bx) * alpha;
  14615. bone.scaleY = by + (y - by) * alpha;
  14616. break;
  14617. case MixBlend$2.first:
  14618. case MixBlend$2.replace:
  14619. bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
  14620. by = Math.abs(bone.scaleY) * MathUtils.signum(y);
  14621. bone.scaleX = bx + (x - bx) * alpha;
  14622. bone.scaleY = by + (y - by) * alpha;
  14623. break;
  14624. case MixBlend$2.add:
  14625. bx = MathUtils.signum(x);
  14626. by = MathUtils.signum(y);
  14627. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  14628. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  14629. }
  14630. }
  14631. }
  14632. }
  14633. }
  14634. /** Changes a bone's local {@link Bone#scaleX)} and {@link Bone#scaleY}.
  14635. * @public
  14636. * */
  14637. class ScaleXTimeline extends CurveTimeline1 {
  14638. __init6() {this.boneIndex = 0;}
  14639. constructor (frameCount, bezierCount, boneIndex) {
  14640. super(frameCount, bezierCount, [
  14641. Property.scaleX + "|" + boneIndex
  14642. ]);ScaleXTimeline.prototype.__init6.call(this); this.boneIndex = boneIndex;
  14643. }
  14644. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14645. let frames = this.frames;
  14646. let bone = skeleton.bones[this.boneIndex];
  14647. if (!bone.active) return;
  14648. if (time < frames[0]) {
  14649. switch (blend) {
  14650. case MixBlend$2.setup:
  14651. bone.scaleX = bone.data.scaleX;
  14652. return;
  14653. case MixBlend$2.first:
  14654. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  14655. }
  14656. return;
  14657. }
  14658. let x = this.getCurveValue(time) * bone.data.scaleX;
  14659. if (alpha == 1) {
  14660. if (blend == MixBlend$2.add)
  14661. bone.scaleX += x - bone.data.scaleX;
  14662. else
  14663. bone.scaleX = x;
  14664. } else {
  14665. // Mixing out uses sign of setup or current pose, else use sign of key.
  14666. let bx = 0;
  14667. if (direction == MixDirection$2.mixOut) {
  14668. switch (blend) {
  14669. case MixBlend$2.setup:
  14670. bx = bone.data.scaleX;
  14671. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  14672. break;
  14673. case MixBlend$2.first:
  14674. case MixBlend$2.replace:
  14675. bx = bone.scaleX;
  14676. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bx) * alpha;
  14677. break;
  14678. case MixBlend$2.add:
  14679. bx = bone.scaleX;
  14680. bone.scaleX = bx + (Math.abs(x) * MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  14681. }
  14682. } else {
  14683. switch (blend) {
  14684. case MixBlend$2.setup:
  14685. bx = Math.abs(bone.data.scaleX) * MathUtils.signum(x);
  14686. bone.scaleX = bx + (x - bx) * alpha;
  14687. break;
  14688. case MixBlend$2.first:
  14689. case MixBlend$2.replace:
  14690. bx = Math.abs(bone.scaleX) * MathUtils.signum(x);
  14691. bone.scaleX = bx + (x - bx) * alpha;
  14692. break;
  14693. case MixBlend$2.add:
  14694. bx = MathUtils.signum(x);
  14695. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  14696. }
  14697. }
  14698. }
  14699. }
  14700. }
  14701. /** Changes a bone's local {@link Bone#scaleX)} and {@link Bone#scaleY}.
  14702. * @public
  14703. * */
  14704. class ScaleYTimeline extends CurveTimeline1 {
  14705. __init7() {this.boneIndex = 0;}
  14706. constructor (frameCount, bezierCount, boneIndex) {
  14707. super(frameCount, bezierCount, [
  14708. Property.scaleY + "|" + boneIndex
  14709. ]);ScaleYTimeline.prototype.__init7.call(this); this.boneIndex = boneIndex;
  14710. }
  14711. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14712. let frames = this.frames;
  14713. let bone = skeleton.bones[this.boneIndex];
  14714. if (!bone.active) return;
  14715. if (time < frames[0]) {
  14716. switch (blend) {
  14717. case MixBlend$2.setup:
  14718. bone.scaleY = bone.data.scaleY;
  14719. return;
  14720. case MixBlend$2.first:
  14721. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  14722. }
  14723. return;
  14724. }
  14725. let y = this.getCurveValue(time) * bone.data.scaleY;
  14726. if (alpha == 1) {
  14727. if (blend == MixBlend$2.add)
  14728. bone.scaleY += y - bone.data.scaleY;
  14729. else
  14730. bone.scaleY = y;
  14731. } else {
  14732. // Mixing out uses sign of setup or current pose, else use sign of key.
  14733. let by = 0;
  14734. if (direction == MixDirection$2.mixOut) {
  14735. switch (blend) {
  14736. case MixBlend$2.setup:
  14737. by = bone.data.scaleY;
  14738. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  14739. break;
  14740. case MixBlend$2.first:
  14741. case MixBlend$2.replace:
  14742. by = bone.scaleY;
  14743. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - by) * alpha;
  14744. break;
  14745. case MixBlend$2.add:
  14746. by = bone.scaleY;
  14747. bone.scaleY = by + (Math.abs(y) * MathUtils.signum(by) - bone.data.scaleY) * alpha;
  14748. }
  14749. } else {
  14750. switch (blend) {
  14751. case MixBlend$2.setup:
  14752. by = Math.abs(bone.data.scaleY) * MathUtils.signum(y);
  14753. bone.scaleY = by + (y - by) * alpha;
  14754. break;
  14755. case MixBlend$2.first:
  14756. case MixBlend$2.replace:
  14757. by = Math.abs(bone.scaleY) * MathUtils.signum(y);
  14758. bone.scaleY = by + (y - by) * alpha;
  14759. break;
  14760. case MixBlend$2.add:
  14761. by = MathUtils.signum(y);
  14762. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  14763. }
  14764. }
  14765. }
  14766. }
  14767. }
  14768. /** Changes a bone's local {@link Bone#shearX} and {@link Bone#shearY}.
  14769. * @public
  14770. * */
  14771. class ShearTimeline$2 extends CurveTimeline2 {
  14772. __init8() {this.boneIndex = 0;}
  14773. constructor (frameCount, bezierCount, boneIndex) {
  14774. super(frameCount, bezierCount, [
  14775. Property.shearX + "|" + boneIndex,
  14776. Property.shearY + "|" + boneIndex
  14777. ]);ShearTimeline$2.prototype.__init8.call(this); this.boneIndex = boneIndex;
  14778. }
  14779. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14780. let frames = this.frames;
  14781. let bone = skeleton.bones[this.boneIndex];
  14782. if (!bone.active) return;
  14783. if (time < frames[0]) {
  14784. switch (blend) {
  14785. case MixBlend$2.setup:
  14786. bone.shearX = bone.data.shearX;
  14787. bone.shearY = bone.data.shearY;
  14788. return;
  14789. case MixBlend$2.first:
  14790. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  14791. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  14792. }
  14793. return;
  14794. }
  14795. let x = 0, y = 0;
  14796. let i = Animation$2.search2(frames, time, CurveTimeline2.ENTRIES);
  14797. let curveType = this.curves[i / CurveTimeline2.ENTRIES];
  14798. switch (curveType) {
  14799. case CurveTimeline2.LINEAR:
  14800. let before = frames[i];
  14801. x = frames[i + CurveTimeline2.VALUE1];
  14802. y = frames[i + CurveTimeline2.VALUE2];
  14803. let t = (time - before) / (frames[i + CurveTimeline2.ENTRIES] - before);
  14804. x += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE1] - x) * t;
  14805. y += (frames[i + CurveTimeline2.ENTRIES + CurveTimeline2.VALUE2] - y) * t;
  14806. break;
  14807. case CurveTimeline2.STEPPED:
  14808. x = frames[i + CurveTimeline2.VALUE1];
  14809. y = frames[i + CurveTimeline2.VALUE2];
  14810. break;
  14811. default:
  14812. x = this.getBezierValue(time, i, CurveTimeline2.VALUE1, curveType - CurveTimeline2.BEZIER);
  14813. y = this.getBezierValue(time, i, CurveTimeline2.VALUE2, curveType + CurveTimeline2.BEZIER_SIZE - CurveTimeline2.BEZIER);
  14814. }
  14815. switch (blend) {
  14816. case MixBlend$2.setup:
  14817. bone.shearX = bone.data.shearX + x * alpha;
  14818. bone.shearY = bone.data.shearY + y * alpha;
  14819. break;
  14820. case MixBlend$2.first:
  14821. case MixBlend$2.replace:
  14822. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  14823. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  14824. break;
  14825. case MixBlend$2.add:
  14826. bone.shearX += x * alpha;
  14827. bone.shearY += y * alpha;
  14828. }
  14829. }
  14830. }
  14831. /** Changes a bone's local {@link Bone#shearX} and {@link Bone#shearY}.
  14832. * @public
  14833. * */
  14834. class ShearXTimeline extends CurveTimeline1 {
  14835. __init9() {this.boneIndex = 0;}
  14836. constructor (frameCount, bezierCount, boneIndex) {
  14837. super(frameCount, bezierCount, [
  14838. Property.shearX + "|" + boneIndex
  14839. ]);ShearXTimeline.prototype.__init9.call(this); this.boneIndex = boneIndex;
  14840. }
  14841. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14842. let frames = this.frames;
  14843. let bone = skeleton.bones[this.boneIndex];
  14844. if (!bone.active) return;
  14845. if (time < frames[0]) {
  14846. switch (blend) {
  14847. case MixBlend$2.setup:
  14848. bone.shearX = bone.data.shearX;
  14849. return;
  14850. case MixBlend$2.first:
  14851. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  14852. }
  14853. return;
  14854. }
  14855. let x = this.getCurveValue(time);
  14856. switch (blend) {
  14857. case MixBlend$2.setup:
  14858. bone.shearX = bone.data.shearX + x * alpha;
  14859. break;
  14860. case MixBlend$2.first:
  14861. case MixBlend$2.replace:
  14862. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  14863. break;
  14864. case MixBlend$2.add:
  14865. bone.shearX += x * alpha;
  14866. }
  14867. }
  14868. }
  14869. /** Changes a bone's local {@link Bone#shearX} and {@link Bone#shearY}.
  14870. * @public
  14871. * */
  14872. class ShearYTimeline extends CurveTimeline1 {
  14873. __init10() {this.boneIndex = 0;}
  14874. constructor (frameCount, bezierCount, boneIndex) {
  14875. super(frameCount, bezierCount, [
  14876. Property.shearY + "|" + boneIndex
  14877. ]);ShearYTimeline.prototype.__init10.call(this); this.boneIndex = boneIndex;
  14878. }
  14879. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14880. let frames = this.frames;
  14881. let bone = skeleton.bones[this.boneIndex];
  14882. if (!bone.active) return;
  14883. if (time < frames[0]) {
  14884. switch (blend) {
  14885. case MixBlend$2.setup:
  14886. bone.shearY = bone.data.shearY;
  14887. return;
  14888. case MixBlend$2.first:
  14889. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  14890. }
  14891. return;
  14892. }
  14893. let y = this.getCurveValue(time);
  14894. switch (blend) {
  14895. case MixBlend$2.setup:
  14896. bone.shearY = bone.data.shearY + y * alpha;
  14897. break;
  14898. case MixBlend$2.first:
  14899. case MixBlend$2.replace:
  14900. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  14901. break;
  14902. case MixBlend$2.add:
  14903. bone.shearY += y * alpha;
  14904. }
  14905. }
  14906. }
  14907. /** Changes a slot's {@link Slot#color}.
  14908. * @public
  14909. * */
  14910. class RGBATimeline extends CurveTimeline$2 {
  14911. static __initStatic10() {this.ENTRIES = 5;}
  14912. static __initStatic11() {this.R = 1;} static __initStatic12() {this.G = 2;} static __initStatic13() {this.B = 3;} static __initStatic14() {this.A = 4;}
  14913. __init11() {this.slotIndex = 0;}
  14914. constructor (frameCount, bezierCount, slotIndex) {
  14915. super(frameCount, bezierCount, [
  14916. Property.rgb + "|" + slotIndex,
  14917. Property.alpha + "|" + slotIndex
  14918. ]);RGBATimeline.prototype.__init11.call(this); this.slotIndex = slotIndex;
  14919. }
  14920. getFrameEntries () {
  14921. return RGBATimeline.ENTRIES;
  14922. }
  14923. /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */
  14924. setFrame (frame, time, r, g, b, a) {
  14925. frame *= RGBATimeline.ENTRIES;
  14926. this.frames[frame] = time;
  14927. this.frames[frame + RGBATimeline.R] = r;
  14928. this.frames[frame + RGBATimeline.G] = g;
  14929. this.frames[frame + RGBATimeline.B] = b;
  14930. this.frames[frame + RGBATimeline.A] = a;
  14931. }
  14932. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  14933. let slot = skeleton.slots[this.slotIndex];
  14934. if (!slot.bone.active) return;
  14935. let frames = this.frames;
  14936. if (time < frames[0]) {
  14937. let color = slot.color, setup = slot.data.color;
  14938. switch (blend) {
  14939. case MixBlend$2.setup:
  14940. color.setFromColor(slot.data.color);
  14941. return;
  14942. case MixBlend$2.first:
  14943. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha,
  14944. (setup.a - color.a) * alpha);
  14945. }
  14946. return;
  14947. }
  14948. let r = 0, g = 0, b = 0, a = 0;
  14949. let i = Animation$2.search2(frames, time, RGBATimeline.ENTRIES);
  14950. let curveType = this.curves[i / RGBATimeline.ENTRIES];
  14951. switch (curveType) {
  14952. case RGBATimeline.LINEAR:
  14953. let before = frames[i];
  14954. r = frames[i + RGBATimeline.R];
  14955. g = frames[i + RGBATimeline.G];
  14956. b = frames[i + RGBATimeline.B];
  14957. a = frames[i + RGBATimeline.A];
  14958. let t = (time - before) / (frames[i + RGBATimeline.ENTRIES] - before);
  14959. r += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.R] - r) * t;
  14960. g += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.G] - g) * t;
  14961. b += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.B] - b) * t;
  14962. a += (frames[i + RGBATimeline.ENTRIES + RGBATimeline.A] - a) * t;
  14963. break;
  14964. case RGBATimeline.STEPPED:
  14965. r = frames[i + RGBATimeline.R];
  14966. g = frames[i + RGBATimeline.G];
  14967. b = frames[i + RGBATimeline.B];
  14968. a = frames[i + RGBATimeline.A];
  14969. break;
  14970. default:
  14971. r = this.getBezierValue(time, i, RGBATimeline.R, curveType - RGBATimeline.BEZIER);
  14972. g = this.getBezierValue(time, i, RGBATimeline.G, curveType + RGBATimeline.BEZIER_SIZE - RGBATimeline.BEZIER);
  14973. b = this.getBezierValue(time, i, RGBATimeline.B, curveType + RGBATimeline.BEZIER_SIZE * 2 - RGBATimeline.BEZIER);
  14974. a = this.getBezierValue(time, i, RGBATimeline.A, curveType + RGBATimeline.BEZIER_SIZE * 3 - RGBATimeline.BEZIER);
  14975. }
  14976. let color = slot.color;
  14977. if (alpha == 1)
  14978. color.set(r, g, b, a);
  14979. else {
  14980. if (blend == MixBlend$2.setup) color.setFromColor(slot.data.color);
  14981. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  14982. }
  14983. }
  14984. } RGBATimeline.__initStatic10(); RGBATimeline.__initStatic11(); RGBATimeline.__initStatic12(); RGBATimeline.__initStatic13(); RGBATimeline.__initStatic14();
  14985. /** Changes a slot's {@link Slot#color}.
  14986. * @public
  14987. * */
  14988. class RGBTimeline extends CurveTimeline$2 {
  14989. static __initStatic15() {this.ENTRIES = 4;}
  14990. static __initStatic16() {this.R = 1;} static __initStatic17() {this.G = 2;} static __initStatic18() {this.B = 3;}
  14991. __init12() {this.slotIndex = 0;}
  14992. constructor (frameCount, bezierCount, slotIndex) {
  14993. super(frameCount, bezierCount, [
  14994. Property.rgb + "|" + slotIndex
  14995. ]);RGBTimeline.prototype.__init12.call(this); this.slotIndex = slotIndex;
  14996. }
  14997. getFrameEntries () {
  14998. return RGBTimeline.ENTRIES;
  14999. }
  15000. /** Sets the time in seconds, red, green, blue, and alpha for the specified key frame. */
  15001. setFrame (frame, time, r, g, b) {
  15002. frame *= RGBTimeline.ENTRIES;
  15003. this.frames[frame] = time;
  15004. this.frames[frame + RGBTimeline.R] = r;
  15005. this.frames[frame + RGBTimeline.G] = g;
  15006. this.frames[frame + RGBTimeline.B] = b;
  15007. }
  15008. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  15009. let slot = skeleton.slots[this.slotIndex];
  15010. if (!slot.bone.active) return;
  15011. let frames = this.frames;
  15012. if (time < frames[0]) {
  15013. let color = slot.color, setup = slot.data.color;
  15014. switch (blend) {
  15015. case MixBlend$2.setup:
  15016. color.r = setup.r;
  15017. color.g = setup.g;
  15018. color.b = setup.b;
  15019. return;
  15020. case MixBlend$2.first:
  15021. color.r += (setup.r - color.r) * alpha;
  15022. color.g += (setup.g - color.g) * alpha;
  15023. color.b += (setup.b - color.b) * alpha;
  15024. }
  15025. return;
  15026. }
  15027. let r = 0, g = 0, b = 0;
  15028. let i = Animation$2.search2(frames, time, RGBTimeline.ENTRIES);
  15029. let curveType = this.curves[i / RGBTimeline.ENTRIES];
  15030. switch (curveType) {
  15031. case RGBTimeline.LINEAR:
  15032. let before = frames[i];
  15033. r = frames[i + RGBTimeline.R];
  15034. g = frames[i + RGBTimeline.G];
  15035. b = frames[i + RGBTimeline.B];
  15036. let t = (time - before) / (frames[i + RGBTimeline.ENTRIES] - before);
  15037. r += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.R] - r) * t;
  15038. g += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.G] - g) * t;
  15039. b += (frames[i + RGBTimeline.ENTRIES + RGBTimeline.B] - b) * t;
  15040. break;
  15041. case RGBATimeline.STEPPED:
  15042. r = frames[i + RGBTimeline.R];
  15043. g = frames[i + RGBTimeline.G];
  15044. b = frames[i + RGBTimeline.B];
  15045. break;
  15046. default:
  15047. r = this.getBezierValue(time, i, RGBTimeline.R, curveType - RGBTimeline.BEZIER);
  15048. g = this.getBezierValue(time, i, RGBTimeline.G, curveType + RGBTimeline.BEZIER_SIZE - RGBTimeline.BEZIER);
  15049. b = this.getBezierValue(time, i, RGBTimeline.B, curveType + RGBTimeline.BEZIER_SIZE * 2 - RGBTimeline.BEZIER);
  15050. }
  15051. let color = slot.color;
  15052. if (alpha == 1) {
  15053. color.r = r;
  15054. color.g = g;
  15055. color.b = b;
  15056. } else {
  15057. if (blend == MixBlend$2.setup) {
  15058. let setup = slot.data.color;
  15059. color.r = setup.r;
  15060. color.g = setup.g;
  15061. color.b = setup.b;
  15062. }
  15063. color.r += (r - color.r) * alpha;
  15064. color.g += (g - color.g) * alpha;
  15065. color.b += (b - color.b) * alpha;
  15066. }
  15067. }
  15068. } RGBTimeline.__initStatic15(); RGBTimeline.__initStatic16(); RGBTimeline.__initStatic17(); RGBTimeline.__initStatic18();
  15069. /** Changes a bone's local {@link Bone#shearX} and {@link Bone#shearY}.
  15070. * @public
  15071. * */
  15072. class AlphaTimeline extends CurveTimeline1 {
  15073. __init13() {this.slotIndex = 0;}
  15074. constructor (frameCount, bezierCount, slotIndex) {
  15075. super(frameCount, bezierCount, [
  15076. Property.alpha + "|" + slotIndex
  15077. ]);AlphaTimeline.prototype.__init13.call(this); this.slotIndex = slotIndex;
  15078. }
  15079. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  15080. let frames = this.frames;
  15081. let slot = skeleton.slots[this.slotIndex];
  15082. if (!slot.bone.active) return;
  15083. if (time < frames[0]) { // Time is before first frame.
  15084. let color = slot.color, setup = slot.data.color;
  15085. switch (blend) {
  15086. case MixBlend$2.setup:
  15087. color.a = setup.a;
  15088. return;
  15089. case MixBlend$2.first:
  15090. color.a += (setup.a - color.a) * alpha;
  15091. }
  15092. return;
  15093. }
  15094. let a = this.getCurveValue(time);
  15095. if (alpha == 1)
  15096. slot.color.a = a;
  15097. else {
  15098. if (blend == MixBlend$2.setup) slot.color.a = slot.data.color.a;
  15099. slot.color.a += (a - slot.color.a) * alpha;
  15100. }
  15101. }
  15102. }
  15103. /** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting.
  15104. * @public
  15105. * */
  15106. class RGBA2Timeline extends CurveTimeline$2 {
  15107. static __initStatic19() {this.ENTRIES = 8;}
  15108. static __initStatic20() {this.R = 1;} static __initStatic21() {this.G = 2;} static __initStatic22() {this.B = 3;} static __initStatic23() {this.A = 4;} static __initStatic24() {this.R2 = 5;} static __initStatic25() {this.G2 = 6;} static __initStatic26() {this.B2 = 7;}
  15109. __init14() {this.slotIndex = 0;}
  15110. constructor (frameCount, bezierCount, slotIndex) {
  15111. super(frameCount, bezierCount, [
  15112. Property.rgb + "|" + slotIndex,
  15113. Property.alpha + "|" + slotIndex,
  15114. Property.rgb2 + "|" + slotIndex
  15115. ]);RGBA2Timeline.prototype.__init14.call(this); this.slotIndex = slotIndex;
  15116. }
  15117. getFrameEntries () {
  15118. return RGBA2Timeline.ENTRIES;
  15119. }
  15120. /** Sets the time in seconds, light, and dark colors for the specified key frame. */
  15121. setFrame (frame, time, r, g, b, a, r2, g2, b2) {
  15122. frame *= RGBA2Timeline.ENTRIES;
  15123. this.frames[frame] = time;
  15124. this.frames[frame + RGBA2Timeline.R] = r;
  15125. this.frames[frame + RGBA2Timeline.G] = g;
  15126. this.frames[frame + RGBA2Timeline.B] = b;
  15127. this.frames[frame + RGBA2Timeline.A] = a;
  15128. this.frames[frame + RGBA2Timeline.R2] = r2;
  15129. this.frames[frame + RGBA2Timeline.G2] = g2;
  15130. this.frames[frame + RGBA2Timeline.B2] = b2;
  15131. }
  15132. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  15133. let slot = skeleton.slots[this.slotIndex];
  15134. if (!slot.bone.active) return;
  15135. let frames = this.frames;
  15136. if (time < frames[0]) {
  15137. let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  15138. switch (blend) {
  15139. case MixBlend$2.setup:
  15140. light.setFromColor(setupLight);
  15141. dark.r = setupDark.r;
  15142. dark.g = setupDark.g;
  15143. dark.b = setupDark.b;
  15144. return;
  15145. case MixBlend$2.first:
  15146. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha,
  15147. (setupLight.a - light.a) * alpha);
  15148. dark.r += (setupDark.r - dark.r) * alpha;
  15149. dark.g += (setupDark.g - dark.g) * alpha;
  15150. dark.b += (setupDark.b - dark.b) * alpha;
  15151. }
  15152. return;
  15153. }
  15154. let r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  15155. let i = Animation$2.search2(frames, time, RGBA2Timeline.ENTRIES);
  15156. let curveType = this.curves[i >> 3];
  15157. switch (curveType) {
  15158. case RGBA2Timeline.LINEAR:
  15159. let before = frames[i];
  15160. r = frames[i + RGBA2Timeline.R];
  15161. g = frames[i + RGBA2Timeline.G];
  15162. b = frames[i + RGBA2Timeline.B];
  15163. a = frames[i + RGBA2Timeline.A];
  15164. r2 = frames[i + RGBA2Timeline.R2];
  15165. g2 = frames[i + RGBA2Timeline.G2];
  15166. b2 = frames[i + RGBA2Timeline.B2];
  15167. let t = (time - before) / (frames[i + RGBA2Timeline.ENTRIES] - before);
  15168. r += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.R] - r) * t;
  15169. g += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.G] - g) * t;
  15170. b += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.B] - b) * t;
  15171. a += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.A] - a) * t;
  15172. r2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.R2] - r2) * t;
  15173. g2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.G2] - g2) * t;
  15174. b2 += (frames[i + RGBA2Timeline.ENTRIES + RGBA2Timeline.B2] - b2) * t;
  15175. break;
  15176. case RGBA2Timeline.STEPPED:
  15177. r = frames[i + RGBA2Timeline.R];
  15178. g = frames[i + RGBA2Timeline.G];
  15179. b = frames[i + RGBA2Timeline.B];
  15180. a = frames[i + RGBA2Timeline.A];
  15181. r2 = frames[i + RGBA2Timeline.R2];
  15182. g2 = frames[i + RGBA2Timeline.G2];
  15183. b2 = frames[i + RGBA2Timeline.B2];
  15184. break;
  15185. default:
  15186. r = this.getBezierValue(time, i, RGBA2Timeline.R, curveType - RGBA2Timeline.BEZIER);
  15187. g = this.getBezierValue(time, i, RGBA2Timeline.G, curveType + RGBA2Timeline.BEZIER_SIZE - RGBA2Timeline.BEZIER);
  15188. b = this.getBezierValue(time, i, RGBA2Timeline.B, curveType + RGBA2Timeline.BEZIER_SIZE * 2 - RGBA2Timeline.BEZIER);
  15189. a = this.getBezierValue(time, i, RGBA2Timeline.A, curveType + RGBA2Timeline.BEZIER_SIZE * 3 - RGBA2Timeline.BEZIER);
  15190. r2 = this.getBezierValue(time, i, RGBA2Timeline.R2, curveType + RGBA2Timeline.BEZIER_SIZE * 4 - RGBA2Timeline.BEZIER);
  15191. g2 = this.getBezierValue(time, i, RGBA2Timeline.G2, curveType + RGBA2Timeline.BEZIER_SIZE * 5 - RGBA2Timeline.BEZIER);
  15192. b2 = this.getBezierValue(time, i, RGBA2Timeline.B2, curveType + RGBA2Timeline.BEZIER_SIZE * 6 - RGBA2Timeline.BEZIER);
  15193. }
  15194. let light = slot.color, dark = slot.darkColor;
  15195. if (alpha == 1) {
  15196. light.set(r, g, b, a);
  15197. dark.r = r2;
  15198. dark.g = g2;
  15199. dark.b = b2;
  15200. } else {
  15201. if (blend == MixBlend$2.setup) {
  15202. light.setFromColor(slot.data.color);
  15203. dark.setFromColor(slot.data.darkColor);
  15204. }
  15205. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  15206. dark.r += (r2 - dark.r) * alpha;
  15207. dark.g += (g2 - dark.g) * alpha;
  15208. dark.b += (b2 - dark.b) * alpha;
  15209. }
  15210. }
  15211. } RGBA2Timeline.__initStatic19(); RGBA2Timeline.__initStatic20(); RGBA2Timeline.__initStatic21(); RGBA2Timeline.__initStatic22(); RGBA2Timeline.__initStatic23(); RGBA2Timeline.__initStatic24(); RGBA2Timeline.__initStatic25(); RGBA2Timeline.__initStatic26();
  15212. /** Changes a slot's {@link Slot#color} and {@link Slot#darkColor} for two color tinting.
  15213. * @public
  15214. * */
  15215. class RGB2Timeline extends CurveTimeline$2 {
  15216. static __initStatic27() {this.ENTRIES = 7;}
  15217. static __initStatic28() {this.R = 1;} static __initStatic29() {this.G = 2;} static __initStatic30() {this.B = 3;} static __initStatic31() {this.R2 = 4;} static __initStatic32() {this.G2 = 5;} static __initStatic33() {this.B2 = 6;}
  15218. __init15() {this.slotIndex = 0;}
  15219. constructor (frameCount, bezierCount, slotIndex) {
  15220. super(frameCount, bezierCount, [
  15221. Property.rgb + "|" + slotIndex,
  15222. Property.rgb2 + "|" + slotIndex
  15223. ]);RGB2Timeline.prototype.__init15.call(this); this.slotIndex = slotIndex;
  15224. }
  15225. getFrameEntries () {
  15226. return RGB2Timeline.ENTRIES;
  15227. }
  15228. /** Sets the time in seconds, light, and dark colors for the specified key frame. */
  15229. setFrame (frame, time, r, g, b, r2, g2, b2) {
  15230. frame *= RGB2Timeline.ENTRIES;
  15231. this.frames[frame] = time;
  15232. this.frames[frame + RGB2Timeline.R] = r;
  15233. this.frames[frame + RGB2Timeline.G] = g;
  15234. this.frames[frame + RGB2Timeline.B] = b;
  15235. this.frames[frame + RGB2Timeline.R2] = r2;
  15236. this.frames[frame + RGB2Timeline.G2] = g2;
  15237. this.frames[frame + RGB2Timeline.B2] = b2;
  15238. }
  15239. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  15240. let slot = skeleton.slots[this.slotIndex];
  15241. if (!slot.bone.active) return;
  15242. let frames = this.frames;
  15243. if (time < frames[0]) {
  15244. let light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  15245. switch (blend) {
  15246. case MixBlend$2.setup:
  15247. light.r = setupLight.r;
  15248. light.g = setupLight.g;
  15249. light.b = setupLight.b;
  15250. dark.r = setupDark.r;
  15251. dark.g = setupDark.g;
  15252. dark.b = setupDark.b;
  15253. return;
  15254. case MixBlend$2.first:
  15255. light.r += (setupLight.r - light.r) * alpha;
  15256. light.g += (setupLight.g - light.g) * alpha;
  15257. light.b += (setupLight.b - light.b) * alpha;
  15258. dark.r += (setupDark.r - dark.r) * alpha;
  15259. dark.g += (setupDark.g - dark.g) * alpha;
  15260. dark.b += (setupDark.b - dark.b) * alpha;
  15261. }
  15262. return;
  15263. }
  15264. // @ts-ignore
  15265. let r = 0, g = 0, b = 0, r2 = 0, g2 = 0, b2 = 0;
  15266. let i = Animation$2.search2(frames, time, RGB2Timeline.ENTRIES);
  15267. let curveType = this.curves[i >> 3];
  15268. switch (curveType) {
  15269. case RGB2Timeline.LINEAR:
  15270. let before = frames[i];
  15271. r = frames[i + RGB2Timeline.R];
  15272. g = frames[i + RGB2Timeline.G];
  15273. b = frames[i + RGB2Timeline.B];
  15274. r2 = frames[i + RGB2Timeline.R2];
  15275. g2 = frames[i + RGB2Timeline.G2];
  15276. b2 = frames[i + RGB2Timeline.B2];
  15277. let t = (time - before) / (frames[i + RGB2Timeline.ENTRIES] - before);
  15278. r += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.R] - r) * t;
  15279. g += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.G] - g) * t;
  15280. b += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.B] - b) * t;
  15281. r2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.R2] - r2) * t;
  15282. g2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.G2] - g2) * t;
  15283. b2 += (frames[i + RGB2Timeline.ENTRIES + RGB2Timeline.B2] - b2) * t;
  15284. break;
  15285. case RGB2Timeline.STEPPED:
  15286. r = frames[i + RGB2Timeline.R];
  15287. g = frames[i + RGB2Timeline.G];
  15288. b = frames[i + RGB2Timeline.B];
  15289. r2 = frames[i + RGB2Timeline.R2];
  15290. g2 = frames[i + RGB2Timeline.G2];
  15291. b2 = frames[i + RGB2Timeline.B2];
  15292. break;
  15293. default:
  15294. r = this.getBezierValue(time, i, RGB2Timeline.R, curveType - RGB2Timeline.BEZIER);
  15295. g = this.getBezierValue(time, i, RGB2Timeline.G, curveType + RGB2Timeline.BEZIER_SIZE - RGB2Timeline.BEZIER);
  15296. b = this.getBezierValue(time, i, RGB2Timeline.B, curveType + RGB2Timeline.BEZIER_SIZE * 2 - RGB2Timeline.BEZIER);
  15297. r2 = this.getBezierValue(time, i, RGB2Timeline.R2, curveType + RGB2Timeline.BEZIER_SIZE * 3 - RGB2Timeline.BEZIER);
  15298. g2 = this.getBezierValue(time, i, RGB2Timeline.G2, curveType + RGB2Timeline.BEZIER_SIZE * 4 - RGB2Timeline.BEZIER);
  15299. b2 = this.getBezierValue(time, i, RGB2Timeline.B2, curveType + RGB2Timeline.BEZIER_SIZE * 5 - RGB2Timeline.BEZIER);
  15300. }
  15301. let light = slot.color, dark = slot.darkColor;
  15302. if (alpha == 1) {
  15303. light.r = r;
  15304. light.g = g;
  15305. light.b = b;
  15306. dark.r = r2;
  15307. dark.g = g2;
  15308. dark.b = b2;
  15309. } else {
  15310. if (blend == MixBlend$2.setup) {
  15311. let setupLight = slot.data.color, setupDark = slot.data.darkColor;
  15312. light.r = setupLight.r;
  15313. light.g = setupLight.g;
  15314. light.b = setupLight.b;
  15315. dark.r = setupDark.r;
  15316. dark.g = setupDark.g;
  15317. dark.b = setupDark.b;
  15318. }
  15319. light.r += (r - light.r) * alpha;
  15320. light.g += (g - light.g) * alpha;
  15321. light.b += (b - light.b) * alpha;
  15322. dark.r += (r2 - dark.r) * alpha;
  15323. dark.g += (g2 - dark.g) * alpha;
  15324. dark.b += (b2 - dark.b) * alpha;
  15325. }
  15326. }
  15327. } RGB2Timeline.__initStatic27(); RGB2Timeline.__initStatic28(); RGB2Timeline.__initStatic29(); RGB2Timeline.__initStatic30(); RGB2Timeline.__initStatic31(); RGB2Timeline.__initStatic32(); RGB2Timeline.__initStatic33();
  15328. /** Changes a slot's {@link Slot#attachment}.
  15329. * @public
  15330. * */
  15331. class AttachmentTimeline$2 extends Timeline {
  15332. __init16() {this.slotIndex = 0;}
  15333. /** The attachment name for each key frame. May contain null values to clear the attachment. */
  15334. constructor (frameCount, slotIndex) {
  15335. super(frameCount, [
  15336. Property.attachment + "|" + slotIndex
  15337. ]);AttachmentTimeline$2.prototype.__init16.call(this); this.slotIndex = slotIndex;
  15338. this.attachmentNames = new Array(frameCount);
  15339. }
  15340. getFrameEntries () {
  15341. return 1;
  15342. }
  15343. /** The number of key frames for this timeline. */
  15344. getFrameCount () {
  15345. return this.frames.length;
  15346. }
  15347. /** Sets the time in seconds and the attachment name for the specified key frame. */
  15348. setFrame (frame, time, attachmentName) {
  15349. this.frames[frame] = time;
  15350. this.attachmentNames[frame] = attachmentName;
  15351. }
  15352. apply (skeleton, lastTime, time, events, alpha, blend, direction) {
  15353. let slot = skeleton.slots[this.slotIndex];
  15354. if (!slot.bone.active) return;
  15355. if (direction == MixDirection$2.mixOut) {
  15356. if (blend == MixBlend$2.setup)
  15357. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  15358. return;
  15359. }
  15360. let frames = this.frames;
  15361. if (time < frames[0]) {
  15362. if (blend == MixBlend$2.setup || blend == MixBlend$2.first) this.setAttachment(skeleton, slot, slot.data.attachmentName);
  15363. return;
  15364. }
  15365. this.setAttachment(skeleton, slot, this.attachmentNames[Animation$2.search(frames, time)]);
  15366. }
  15367. setAttachment(skeleton, slot, attachmentName) {
  15368. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  15369. }
  15370. }
  15371. let zeros$2 = null;
  15372. /** Changes a slot's {@link Slot#deform} to deform a {@link VertexAttachment}.
  15373. * @public
  15374. * */
  15375. class DeformTimeline$2 extends CurveTimeline$2 {
  15376. __init17() {this.slotIndex = 0;}
  15377. /** The attachment that will be deformed. */
  15378. /** The vertices for each key frame. */
  15379. constructor (frameCount, bezierCount, slotIndex, attachment) {
  15380. super(frameCount, bezierCount, [
  15381. Property.deform + "|" + slotIndex + "|" + attachment.id
  15382. ]);DeformTimeline$2.prototype.__init17.call(this); this.slotIndex = slotIndex;
  15383. this.attachment = attachment;
  15384. this.vertices = new Array(frameCount);
  15385. if (zeros$2 == null) zeros$2 = Utils.newFloatArray(64);
  15386. }
  15387. getFrameEntries () {
  15388. return 1;
  15389. }
  15390. /** Sets the time in seconds and the vertices for the specified key frame.
  15391. * @param vertices Vertex positions for an unweighted VertexAttachment, or deform offsets if it has weights. */
  15392. setFrame (frame, time, vertices) {
  15393. this.frames[frame] = time;
  15394. this.vertices[frame] = vertices;
  15395. }
  15396. /** @param value1 Ignored (0 is used for a deform timeline).
  15397. * @param value2 Ignored (1 is used for a deform timeline). */
  15398. setBezier (bezier, frame, value, time1, value1, cx1, cy1, cx2,
  15399. cy2, time2, value2) {
  15400. let curves = this.curves;
  15401. let i = this.getFrameCount() + bezier * DeformTimeline$2.BEZIER_SIZE;
  15402. if (value == 0) curves[frame] = DeformTimeline$2.BEZIER + i;
  15403. let tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06;
  15404. let dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = (cy1 - cy2 + 0.33333333) * 0.018;
  15405. let ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
  15406. let dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667;
  15407. let x = time1 + dx, y = dy;
  15408. for (let n = i + DeformTimeline$2.BEZIER_SIZE; i < n; i += 2) {
  15409. curves[i] = x;
  15410. curves[i + 1] = y;
  15411. dx += ddx;
  15412. dy += ddy;
  15413. ddx += dddx;
  15414. ddy += dddy;
  15415. x += dx;
  15416. y += dy;
  15417. }
  15418. }
  15419. getCurvePercent (time, frame) {
  15420. let curves = this.curves;
  15421. let frames = this.frames;
  15422. let i = curves[frame];
  15423. switch (i) {
  15424. case DeformTimeline$2.LINEAR:
  15425. let x = frames[frame];
  15426. return (time - x) / (frames[frame + this.getFrameEntries()] - x);
  15427. case DeformTimeline$2.STEPPED:
  15428. return 0;
  15429. }
  15430. i -= DeformTimeline$2.BEZIER;
  15431. if (curves[i] > time) {
  15432. let x = frames[frame];
  15433. return curves[i + 1] * (time - x) / (curves[i] - x);
  15434. }
  15435. let n = i + DeformTimeline$2.BEZIER_SIZE;
  15436. for (i += 2; i < n; i += 2) {
  15437. if (curves[i] >= time) {
  15438. let x = curves[i - 2], y = curves[i - 1];
  15439. return y + (time - x) / (curves[i] - x) * (curves[i + 1] - y);
  15440. }
  15441. }
  15442. let x = curves[n - 2], y = curves[n - 1];
  15443. return y + (1 - y) * (time - x) / (frames[frame + this.getFrameEntries()] - x);
  15444. }
  15445. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15446. let slot = skeleton.slots[this.slotIndex];
  15447. if (!slot.bone.active) return;
  15448. let slotAttachment = slot.getAttachment();
  15449. if (!(slotAttachment instanceof VertexAttachment$2) || !((slotAttachment).deformAttachment == this.attachment)) return;
  15450. let deformArray = slot.deform;
  15451. if (deformArray.length == 0) blend = MixBlend$2.setup;
  15452. let vertices = this.vertices;
  15453. let vertexCount = vertices[0].length;
  15454. let frames = this.frames;
  15455. if (time < frames[0]) {
  15456. let vertexAttachment = slotAttachment;
  15457. switch (blend) {
  15458. case MixBlend$2.setup:
  15459. deformArray.length = 0;
  15460. return;
  15461. case MixBlend$2.first:
  15462. if (alpha == 1) {
  15463. deformArray.length = 0;
  15464. break;
  15465. }
  15466. let deform = Utils.setArraySize(deformArray, vertexCount);
  15467. if (vertexAttachment.bones == null) {
  15468. // Unweighted vertex positions.
  15469. let setupVertices = vertexAttachment.vertices;
  15470. for (var i = 0; i < vertexCount; i++)
  15471. deform[i] += (setupVertices[i] - deform[i]) * alpha;
  15472. } else {
  15473. // Weighted deform offsets.
  15474. alpha = 1 - alpha;
  15475. for (var i = 0; i < vertexCount; i++)
  15476. deform[i] *= alpha;
  15477. }
  15478. }
  15479. return;
  15480. }
  15481. let deform = Utils.setArraySize(deformArray, vertexCount);
  15482. if (time >= frames[frames.length - 1]) { // Time is after last frame.
  15483. let lastVertices = vertices[frames.length - 1];
  15484. if (alpha == 1) {
  15485. if (blend == MixBlend$2.add) {
  15486. let vertexAttachment = slotAttachment ;
  15487. if (vertexAttachment.bones == null) {
  15488. // Unweighted vertex positions, with alpha.
  15489. let setupVertices = vertexAttachment.vertices;
  15490. for (let i = 0; i < vertexCount; i++) {
  15491. deform[i] += lastVertices[i] - setupVertices[i];
  15492. }
  15493. } else {
  15494. // Weighted deform offsets, with alpha.
  15495. for (let i = 0; i < vertexCount; i++)
  15496. deform[i] += lastVertices[i];
  15497. }
  15498. } else {
  15499. Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount);
  15500. }
  15501. } else {
  15502. switch (blend) {
  15503. case MixBlend$2.setup: {
  15504. let vertexAttachment = slotAttachment ;
  15505. if (vertexAttachment.bones == null) {
  15506. // Unweighted vertex positions, with alpha.
  15507. let setupVertices = vertexAttachment.vertices;
  15508. for (let i = 0; i < vertexCount; i++) {
  15509. let setup = setupVertices[i];
  15510. deform[i] = setup + (lastVertices[i] - setup) * alpha;
  15511. }
  15512. } else {
  15513. // Weighted deform offsets, with alpha.
  15514. for (let i = 0; i < vertexCount; i++)
  15515. deform[i] = lastVertices[i] * alpha;
  15516. }
  15517. break;
  15518. }
  15519. case MixBlend$2.first:
  15520. case MixBlend$2.replace:
  15521. for (let i = 0; i < vertexCount; i++)
  15522. deform[i] += (lastVertices[i] - deform[i]) * alpha;
  15523. break;
  15524. case MixBlend$2.add:
  15525. let vertexAttachment = slotAttachment ;
  15526. if (vertexAttachment.bones == null) {
  15527. // Unweighted vertex positions, with alpha.
  15528. let setupVertices = vertexAttachment.vertices;
  15529. for (let i = 0; i < vertexCount; i++) {
  15530. deform[i] += (lastVertices[i] - setupVertices[i]) * alpha;
  15531. }
  15532. } else {
  15533. // Weighted deform offsets, with alpha.
  15534. for (let i = 0; i < vertexCount; i++)
  15535. deform[i] += lastVertices[i] * alpha;
  15536. }
  15537. }
  15538. }
  15539. return;
  15540. }
  15541. // Interpolate between the previous frame and the current frame.
  15542. let frame = Animation$2.search(frames, time);
  15543. let percent = this.getCurvePercent(time, frame);
  15544. let prevVertices = vertices[frame];
  15545. let nextVertices = vertices[frame + 1];
  15546. if (alpha == 1) {
  15547. if (blend == MixBlend$2.add) {
  15548. let vertexAttachment = slotAttachment ;
  15549. if (vertexAttachment.bones == null) {
  15550. // Unweighted vertex positions, with alpha.
  15551. let setupVertices = vertexAttachment.vertices;
  15552. for (let i = 0; i < vertexCount; i++) {
  15553. let prev = prevVertices[i];
  15554. deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i];
  15555. }
  15556. } else {
  15557. // Weighted deform offsets, with alpha.
  15558. for (let i = 0; i < vertexCount; i++) {
  15559. let prev = prevVertices[i];
  15560. deform[i] += prev + (nextVertices[i] - prev) * percent;
  15561. }
  15562. }
  15563. } else {
  15564. for (let i = 0; i < vertexCount; i++) {
  15565. let prev = prevVertices[i];
  15566. deform[i] = prev + (nextVertices[i] - prev) * percent;
  15567. }
  15568. }
  15569. } else {
  15570. switch (blend) {
  15571. case MixBlend$2.setup: {
  15572. let vertexAttachment = slotAttachment ;
  15573. if (vertexAttachment.bones == null) {
  15574. // Unweighted vertex positions, with alpha.
  15575. let setupVertices = vertexAttachment.vertices;
  15576. for (let i = 0; i < vertexCount; i++) {
  15577. let prev = prevVertices[i], setup = setupVertices[i];
  15578. deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
  15579. }
  15580. } else {
  15581. // Weighted deform offsets, with alpha.
  15582. for (let i = 0; i < vertexCount; i++) {
  15583. let prev = prevVertices[i];
  15584. deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
  15585. }
  15586. }
  15587. break;
  15588. }
  15589. case MixBlend$2.first:
  15590. case MixBlend$2.replace:
  15591. for (let i = 0; i < vertexCount; i++) {
  15592. let prev = prevVertices[i];
  15593. deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha;
  15594. }
  15595. break;
  15596. case MixBlend$2.add:
  15597. let vertexAttachment = slotAttachment ;
  15598. if (vertexAttachment.bones == null) {
  15599. // Unweighted vertex positions, with alpha.
  15600. let setupVertices = vertexAttachment.vertices;
  15601. for (let i = 0; i < vertexCount; i++) {
  15602. let prev = prevVertices[i];
  15603. deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha;
  15604. }
  15605. } else {
  15606. // Weighted deform offsets, with alpha.
  15607. for (let i = 0; i < vertexCount; i++) {
  15608. let prev = prevVertices[i];
  15609. deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha;
  15610. }
  15611. }
  15612. }
  15613. }
  15614. }
  15615. }
  15616. /** Fires an {@link Event} when specific animation times are reached.
  15617. * @public
  15618. * */
  15619. class EventTimeline$2 extends Timeline {
  15620. static __initStatic34() {this.propertyIds = [ "" + Property.event ];}
  15621. /** The event for each key frame. */
  15622. constructor (frameCount) {
  15623. super(frameCount, EventTimeline$2.propertyIds);
  15624. this.events = new Array(frameCount);
  15625. }
  15626. getFrameEntries () {
  15627. return 1;
  15628. }
  15629. /** Sets the time in seconds and the event for the specified key frame. */
  15630. setFrame (frame, event) {
  15631. this.frames[frame] = event.time;
  15632. this.events[frame] = event;
  15633. }
  15634. /** Fires events for frames > `lastTime` and <= `time`. */
  15635. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15636. if (firedEvents == null) return;
  15637. let frames = this.frames;
  15638. let frameCount = this.frames.length;
  15639. if (lastTime > time) { // Fire events after last time for looped animations.
  15640. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction);
  15641. lastTime = -1;
  15642. } else if (lastTime >= frames[frameCount - 1]) // Last time is after last frame.
  15643. return;
  15644. if (time < frames[0]) return; // Time is before first frame.
  15645. let i = 0;
  15646. if (lastTime < frames[0])
  15647. i = 0;
  15648. else {
  15649. i = Animation$2.search(frames, lastTime) + 1;
  15650. let frameTime = frames[i];
  15651. while (i > 0) { // Fire multiple events with the same frame.
  15652. if (frames[i - 1] != frameTime) break;
  15653. i--;
  15654. }
  15655. }
  15656. for (; i < frameCount && time >= frames[i]; i++)
  15657. firedEvents.push(this.events[i]);
  15658. }
  15659. } EventTimeline$2.__initStatic34();
  15660. /** Changes a skeleton's {@link Skeleton#drawOrder}.
  15661. * @public
  15662. * */
  15663. class DrawOrderTimeline$2 extends Timeline {
  15664. static __initStatic35() {this.propertyIds = [ "" + Property.drawOrder ];}
  15665. /** The draw order for each key frame. See {@link #setFrame(int, float, int[])}. */
  15666. constructor (frameCount) {
  15667. super(frameCount, DrawOrderTimeline$2.propertyIds);
  15668. this.drawOrders = new Array(frameCount);
  15669. }
  15670. getFrameEntries () {
  15671. return 1;
  15672. }
  15673. /** Sets the time in seconds and the draw order for the specified key frame.
  15674. * @param drawOrder For each slot in {@link Skeleton#slots}, the index of the new draw order. May be null to use setup pose
  15675. * draw order. */
  15676. setFrame (frame, time, drawOrder) {
  15677. this.frames[frame] = time;
  15678. this.drawOrders[frame] = drawOrder;
  15679. }
  15680. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15681. let drawOrder = skeleton.drawOrder;
  15682. let slots = skeleton.slots;
  15683. if (direction == MixDirection$2.mixOut) {
  15684. if (blend == MixBlend$2.setup) Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  15685. return;
  15686. }
  15687. let frames = this.frames;
  15688. if (time < frames[0]) {
  15689. if (blend == MixBlend$2.setup || blend == MixBlend$2.first) Utils.arrayCopy(skeleton.slots, 0, drawOrder, 0, skeleton.slots.length);
  15690. return;
  15691. }
  15692. let drawOrderToSetupIndex = this.drawOrders[Animation$2.search(frames, time)];
  15693. if (drawOrderToSetupIndex == null)
  15694. Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  15695. else {
  15696. for (let i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  15697. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  15698. }
  15699. }
  15700. } DrawOrderTimeline$2.__initStatic35();
  15701. /** Changes an IK constraint's {@link IkConstraint#mix}, {@link IkConstraint#softness},
  15702. * {@link IkConstraint#bendDirection}, {@link IkConstraint#stretch}, and {@link IkConstraint#compress}.
  15703. * @public
  15704. * */
  15705. class IkConstraintTimeline$2 extends CurveTimeline$2 {
  15706. static __initStatic36() {this.ENTRIES = 6;}
  15707. static __initStatic37() {this.MIX = 1;} static __initStatic38() {this.SOFTNESS = 2;} static __initStatic39() {this.BEND_DIRECTION = 3;} static __initStatic40() {this.COMPRESS = 4;} static __initStatic41() {this.STRETCH = 5;}
  15708. /** The index of the IK constraint slot in {@link Skeleton#ikConstraints} that will be changed. */
  15709. constructor (frameCount, bezierCount, ikConstraintIndex) {
  15710. super(frameCount, bezierCount, [
  15711. Property.ikConstraint + "|" + ikConstraintIndex
  15712. ]);
  15713. this.ikConstraintIndex = ikConstraintIndex;
  15714. }
  15715. getFrameEntries () {
  15716. return IkConstraintTimeline$2.ENTRIES;
  15717. }
  15718. /** Sets the time in seconds, mix, softness, bend direction, compress, and stretch for the specified key frame. */
  15719. setFrame (frame, time, mix, softness, bendDirection, compress, stretch) {
  15720. frame *= IkConstraintTimeline$2.ENTRIES;
  15721. this.frames[frame] = time;
  15722. this.frames[frame + IkConstraintTimeline$2.MIX] = mix;
  15723. this.frames[frame + IkConstraintTimeline$2.SOFTNESS] = softness;
  15724. this.frames[frame + IkConstraintTimeline$2.BEND_DIRECTION] = bendDirection;
  15725. this.frames[frame + IkConstraintTimeline$2.COMPRESS] = compress ? 1 : 0;
  15726. this.frames[frame + IkConstraintTimeline$2.STRETCH] = stretch ? 1 : 0;
  15727. }
  15728. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15729. let frames = this.frames;
  15730. let constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  15731. if (!constraint.active) return;
  15732. if (time < frames[0]) {
  15733. switch (blend) {
  15734. case MixBlend$2.setup:
  15735. constraint.mix = constraint.data.mix;
  15736. constraint.softness = constraint.data.softness;
  15737. constraint.bendDirection = constraint.data.bendDirection;
  15738. constraint.compress = constraint.data.compress;
  15739. constraint.stretch = constraint.data.stretch;
  15740. return;
  15741. case MixBlend$2.first:
  15742. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  15743. constraint.softness += (constraint.data.softness - constraint.softness) * alpha;
  15744. constraint.bendDirection = constraint.data.bendDirection;
  15745. constraint.compress = constraint.data.compress;
  15746. constraint.stretch = constraint.data.stretch;
  15747. }
  15748. return;
  15749. }
  15750. let mix = 0, softness = 0;
  15751. let i = Animation$2.search2(frames, time, IkConstraintTimeline$2.ENTRIES);
  15752. let curveType = this.curves[i / IkConstraintTimeline$2.ENTRIES];
  15753. switch (curveType) {
  15754. case IkConstraintTimeline$2.LINEAR:
  15755. let before = frames[i];
  15756. mix = frames[i + IkConstraintTimeline$2.MIX];
  15757. softness = frames[i + IkConstraintTimeline$2.SOFTNESS];
  15758. let t = (time - before) / (frames[i + IkConstraintTimeline$2.ENTRIES] - before);
  15759. mix += (frames[i + IkConstraintTimeline$2.ENTRIES + IkConstraintTimeline$2.MIX] - mix) * t;
  15760. softness += (frames[i + IkConstraintTimeline$2.ENTRIES + IkConstraintTimeline$2.SOFTNESS] - softness) * t;
  15761. break;
  15762. case IkConstraintTimeline$2.STEPPED:
  15763. mix = frames[i + IkConstraintTimeline$2.MIX];
  15764. softness = frames[i + IkConstraintTimeline$2.SOFTNESS];
  15765. break;
  15766. default:
  15767. mix = this.getBezierValue(time, i, IkConstraintTimeline$2.MIX, curveType - IkConstraintTimeline$2.BEZIER);
  15768. softness = this.getBezierValue(time, i, IkConstraintTimeline$2.SOFTNESS, curveType + IkConstraintTimeline$2.BEZIER_SIZE - IkConstraintTimeline$2.BEZIER);
  15769. }
  15770. if (blend == MixBlend$2.setup) {
  15771. constraint.mix = constraint.data.mix + (mix - constraint.data.mix) * alpha;
  15772. constraint.softness = constraint.data.softness + (softness - constraint.data.softness) * alpha;
  15773. if (direction == MixDirection$2.mixOut) {
  15774. constraint.bendDirection = constraint.data.bendDirection;
  15775. constraint.compress = constraint.data.compress;
  15776. constraint.stretch = constraint.data.stretch;
  15777. } else {
  15778. constraint.bendDirection = frames[i + IkConstraintTimeline$2.BEND_DIRECTION];
  15779. constraint.compress = frames[i + IkConstraintTimeline$2.COMPRESS] != 0;
  15780. constraint.stretch = frames[i + IkConstraintTimeline$2.STRETCH] != 0;
  15781. }
  15782. } else {
  15783. constraint.mix += (mix - constraint.mix) * alpha;
  15784. constraint.softness += (softness - constraint.softness) * alpha;
  15785. if (direction == MixDirection$2.mixIn) {
  15786. constraint.bendDirection = frames[i + IkConstraintTimeline$2.BEND_DIRECTION];
  15787. constraint.compress = frames[i + IkConstraintTimeline$2.COMPRESS] != 0;
  15788. constraint.stretch = frames[i + IkConstraintTimeline$2.STRETCH] != 0;
  15789. }
  15790. }
  15791. }
  15792. } IkConstraintTimeline$2.__initStatic36(); IkConstraintTimeline$2.__initStatic37(); IkConstraintTimeline$2.__initStatic38(); IkConstraintTimeline$2.__initStatic39(); IkConstraintTimeline$2.__initStatic40(); IkConstraintTimeline$2.__initStatic41();
  15793. /** Changes a transform constraint's {@link TransformConstraint#rotateMix}, {@link TransformConstraint#translateMix},
  15794. * {@link TransformConstraint#scaleMix}, and {@link TransformConstraint#shearMix}.
  15795. * @public
  15796. * */
  15797. class TransformConstraintTimeline$2 extends CurveTimeline$2 {
  15798. static __initStatic42() {this.ENTRIES = 7;}
  15799. static __initStatic43() {this.ROTATE = 1;} static __initStatic44() {this.X = 2;} static __initStatic45() {this.Y = 3;} static __initStatic46() {this.SCALEX = 4;} static __initStatic47() {this.SCALEY = 5;} static __initStatic48() {this.SHEARY = 6;}
  15800. /** The index of the transform constraint slot in {@link Skeleton#transformConstraints} that will be changed. */
  15801. constructor (frameCount, bezierCount, transformConstraintIndex) {
  15802. super(frameCount, bezierCount, [
  15803. Property.transformConstraint + "|" + transformConstraintIndex
  15804. ]);
  15805. this.transformConstraintIndex = transformConstraintIndex;
  15806. }
  15807. getFrameEntries () {
  15808. return TransformConstraintTimeline$2.ENTRIES;
  15809. }
  15810. /** The time in seconds, rotate mix, translate mix, scale mix, and shear mix for the specified key frame. */
  15811. setFrame (frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY,
  15812. mixShearY) {
  15813. let frames = this.frames;
  15814. frame *= TransformConstraintTimeline$2.ENTRIES;
  15815. this.frames[frame] = time;
  15816. frames[frame + TransformConstraintTimeline$2.ROTATE] = mixRotate;
  15817. frames[frame + TransformConstraintTimeline$2.X] = mixX;
  15818. frames[frame + TransformConstraintTimeline$2.Y] = mixY;
  15819. frames[frame + TransformConstraintTimeline$2.SCALEX] = mixScaleX;
  15820. frames[frame + TransformConstraintTimeline$2.SCALEY] = mixScaleY;
  15821. frames[frame + TransformConstraintTimeline$2.SHEARY] = mixShearY;
  15822. }
  15823. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15824. let frames = this.frames;
  15825. let constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  15826. if (!constraint.active) return;
  15827. if (time < frames[0]) {
  15828. let data = constraint.data;
  15829. switch (blend) {
  15830. case MixBlend$2.setup:
  15831. constraint.mixRotate = data.mixRotate;
  15832. constraint.mixX = data.mixX;
  15833. constraint.mixY = data.mixY;
  15834. constraint.mixScaleX = data.mixScaleX;
  15835. constraint.mixScaleY = data.mixScaleY;
  15836. constraint.mixShearY = data.mixShearY;
  15837. return;
  15838. case MixBlend$2.first:
  15839. constraint.mixRotate += (data.mixRotate - constraint.mixRotate) * alpha;
  15840. constraint.mixX += (data.mixX - constraint.mixX) * alpha;
  15841. constraint.mixY += (data.mixY - constraint.mixY) * alpha;
  15842. constraint.mixScaleX += (data.mixScaleX - constraint.mixScaleX) * alpha;
  15843. constraint.mixScaleY += (data.mixScaleY - constraint.mixScaleY) * alpha;
  15844. constraint.mixShearY += (data.mixShearY - constraint.mixShearY) * alpha;
  15845. }
  15846. return;
  15847. }
  15848. let rotate, x, y, scaleX, scaleY, shearY;
  15849. let i = Animation$2.search2(frames, time, TransformConstraintTimeline$2.ENTRIES);
  15850. let curveType = this.curves[i / TransformConstraintTimeline$2.ENTRIES];
  15851. let ROTATE = TransformConstraintTimeline$2.ROTATE;
  15852. let X = TransformConstraintTimeline$2.X;
  15853. let Y = TransformConstraintTimeline$2.Y;
  15854. let SCALEX = TransformConstraintTimeline$2.SCALEX;
  15855. let SCALEY = TransformConstraintTimeline$2.SCALEY;
  15856. let SHEARY = TransformConstraintTimeline$2.SHEARY;
  15857. let ENTRIES = TransformConstraintTimeline$2.ENTRIES;
  15858. let BEZIER = TransformConstraintTimeline$2.BEZIER;
  15859. let BEZIER_SIZE = TransformConstraintTimeline$2.BEZIER_SIZE;
  15860. switch (curveType) {
  15861. case TransformConstraintTimeline$2.LINEAR:
  15862. let before = frames[i];
  15863. rotate = frames[i + ROTATE];
  15864. x = frames[i + X];
  15865. y = frames[i + Y];
  15866. scaleX = frames[i + SCALEX];
  15867. scaleY = frames[i + SCALEY];
  15868. shearY = frames[i + SHEARY];
  15869. let t = (time - before) / (frames[i + ENTRIES] - before);
  15870. rotate += (frames[i + ENTRIES + ROTATE] - rotate) * t;
  15871. x += (frames[i + ENTRIES + X] - x) * t;
  15872. y += (frames[i + ENTRIES + Y] - y) * t;
  15873. scaleX += (frames[i + ENTRIES + SCALEX] - scaleX) * t;
  15874. scaleY += (frames[i + ENTRIES + SCALEY] - scaleY) * t;
  15875. shearY += (frames[i + ENTRIES + SHEARY] - shearY) * t;
  15876. break;
  15877. case TransformConstraintTimeline$2.STEPPED:
  15878. rotate = frames[i + ROTATE];
  15879. x = frames[i + X];
  15880. y = frames[i + Y];
  15881. scaleX = frames[i + SCALEX];
  15882. scaleY = frames[i + SCALEY];
  15883. shearY = frames[i + SHEARY];
  15884. break;
  15885. default:
  15886. rotate = this.getBezierValue(time, i, ROTATE, curveType - BEZIER);
  15887. x = this.getBezierValue(time, i, X, curveType + BEZIER_SIZE - BEZIER);
  15888. y = this.getBezierValue(time, i, Y, curveType + BEZIER_SIZE * 2 - BEZIER);
  15889. scaleX = this.getBezierValue(time, i, SCALEX, curveType + BEZIER_SIZE * 3 - BEZIER);
  15890. scaleY = this.getBezierValue(time, i, SCALEY, curveType + BEZIER_SIZE * 4 - BEZIER);
  15891. shearY = this.getBezierValue(time, i, SHEARY, curveType + BEZIER_SIZE * 5 - BEZIER);
  15892. }
  15893. if (blend == MixBlend$2.setup) {
  15894. let data = constraint.data;
  15895. constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha;
  15896. constraint.mixX = data.mixX + (x - data.mixX) * alpha;
  15897. constraint.mixY = data.mixY + (y - data.mixY) * alpha;
  15898. constraint.mixScaleX = data.mixScaleX + (scaleX - data.mixScaleX) * alpha;
  15899. constraint.mixScaleY = data.mixScaleY + (scaleY - data.mixScaleY) * alpha;
  15900. constraint.mixShearY = data.mixShearY + (shearY - data.mixShearY) * alpha;
  15901. } else {
  15902. constraint.mixRotate += (rotate - constraint.mixRotate) * alpha;
  15903. constraint.mixX += (x - constraint.mixX) * alpha;
  15904. constraint.mixY += (y - constraint.mixY) * alpha;
  15905. constraint.mixScaleX += (scaleX - constraint.mixScaleX) * alpha;
  15906. constraint.mixScaleY += (scaleY - constraint.mixScaleY) * alpha;
  15907. constraint.mixShearY += (shearY - constraint.mixShearY) * alpha;
  15908. }
  15909. }
  15910. } TransformConstraintTimeline$2.__initStatic42(); TransformConstraintTimeline$2.__initStatic43(); TransformConstraintTimeline$2.__initStatic44(); TransformConstraintTimeline$2.__initStatic45(); TransformConstraintTimeline$2.__initStatic46(); TransformConstraintTimeline$2.__initStatic47(); TransformConstraintTimeline$2.__initStatic48();
  15911. /** Changes a path constraint's {@link PathConstraint#position}.
  15912. * @public
  15913. * */
  15914. class PathConstraintPositionTimeline$2 extends CurveTimeline1 {
  15915. /** The index of the path constraint slot in {@link Skeleton#pathConstraints} that will be changed. */
  15916. constructor (frameCount, bezierCount, pathConstraintIndex) {
  15917. super(frameCount, bezierCount, [
  15918. Property.pathConstraintPosition + "|" + pathConstraintIndex
  15919. ]);
  15920. this.pathConstraintIndex = pathConstraintIndex;
  15921. }
  15922. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15923. let frames = this.frames;
  15924. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  15925. if (!constraint.active) return;
  15926. if (time < frames[0]) {
  15927. switch (blend) {
  15928. case MixBlend$2.setup:
  15929. constraint.position = constraint.data.position;
  15930. return;
  15931. case MixBlend$2.first:
  15932. constraint.position += (constraint.data.position - constraint.position) * alpha;
  15933. }
  15934. return;
  15935. }
  15936. let position = this.getCurveValue(time);
  15937. if (blend == MixBlend$2.setup)
  15938. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  15939. else
  15940. constraint.position += (position - constraint.position) * alpha;
  15941. }
  15942. }
  15943. /** Changes a path constraint's {@link PathConstraint#spacing}.
  15944. * @public
  15945. * */
  15946. class PathConstraintSpacingTimeline$2 extends CurveTimeline1 {
  15947. /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */
  15948. __init18() {this.pathConstraintIndex = 0;}
  15949. constructor (frameCount, bezierCount, pathConstraintIndex) {
  15950. super(frameCount, bezierCount, [
  15951. Property.pathConstraintSpacing + "|" + pathConstraintIndex
  15952. ]);PathConstraintSpacingTimeline$2.prototype.__init18.call(this); this.pathConstraintIndex = pathConstraintIndex;
  15953. }
  15954. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  15955. let frames = this.frames;
  15956. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  15957. if (!constraint.active) return;
  15958. if (time < frames[0]) {
  15959. switch (blend) {
  15960. case MixBlend$2.setup:
  15961. constraint.spacing = constraint.data.spacing;
  15962. return;
  15963. case MixBlend$2.first:
  15964. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  15965. }
  15966. return;
  15967. }
  15968. let spacing = this.getCurveValue(time);
  15969. if (blend == MixBlend$2.setup)
  15970. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  15971. else
  15972. constraint.spacing += (spacing - constraint.spacing) * alpha;
  15973. }
  15974. }
  15975. /** Changes a transform constraint's {@link PathConstraint#getMixRotate()}, {@link PathConstraint#getMixX()}, and
  15976. * {@link PathConstraint#getMixY()}.
  15977. * @public
  15978. * */
  15979. class PathConstraintMixTimeline$2 extends CurveTimeline$2 {
  15980. /** The index of the path constraint slot in {@link Skeleton#getPathConstraints()} that will be changed. */
  15981. __init19() {this.pathConstraintIndex = 0;}
  15982. static __initStatic49() {this.ENTRIES = 4;}
  15983. static __initStatic50() {this.ROTATE = 1;} static __initStatic51() {this.X = 2;} static __initStatic52() {this.Y = 3;}
  15984. constructor (frameCount, bezierCount, pathConstraintIndex) {
  15985. super(frameCount, bezierCount, [
  15986. Property.pathConstraintMix + "|" + pathConstraintIndex
  15987. ]);PathConstraintMixTimeline$2.prototype.__init19.call(this); this.pathConstraintIndex = pathConstraintIndex;
  15988. }
  15989. getFrameEntries() {
  15990. return PathConstraintMixTimeline$2.ENTRIES;
  15991. }
  15992. setFrame (frame, time, mixRotate, mixX, mixY) {
  15993. let frames = this.frames;
  15994. frame <<= 2;
  15995. frames[frame] = time;
  15996. frames[frame + PathConstraintMixTimeline$2.ROTATE] = mixRotate;
  15997. frames[frame + PathConstraintMixTimeline$2.X] = mixX;
  15998. frames[frame + PathConstraintMixTimeline$2.Y] = mixY;
  15999. }
  16000. apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  16001. let frames = this.frames;
  16002. let constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  16003. if (!constraint.active) return;
  16004. if (time < frames[0]) {
  16005. switch (blend) {
  16006. case MixBlend$2.setup:
  16007. constraint.mixRotate = constraint.data.mixRotate;
  16008. constraint.mixX = constraint.data.mixX;
  16009. constraint.mixY = constraint.data.mixY;
  16010. return;
  16011. case MixBlend$2.first:
  16012. constraint.mixRotate += (constraint.data.mixRotate - constraint.mixRotate) * alpha;
  16013. constraint.mixX += (constraint.data.mixX - constraint.mixX) * alpha;
  16014. constraint.mixY += (constraint.data.mixY - constraint.mixY) * alpha;
  16015. }
  16016. return;
  16017. }
  16018. let rotate, x, y;
  16019. let i = Animation$2.search2(frames, time, PathConstraintMixTimeline$2.ENTRIES);
  16020. let curveType = this.curves[i >> 2];
  16021. switch (curveType) {
  16022. case PathConstraintMixTimeline$2.LINEAR:
  16023. let before = frames[i];
  16024. rotate = frames[i + PathConstraintMixTimeline$2.ROTATE];
  16025. x = frames[i + PathConstraintMixTimeline$2.X];
  16026. y = frames[i + PathConstraintMixTimeline$2.Y];
  16027. let t = (time - before) / (frames[i + PathConstraintMixTimeline$2.ENTRIES] - before);
  16028. rotate += (frames[i + PathConstraintMixTimeline$2.ENTRIES + PathConstraintMixTimeline$2.ROTATE] - rotate) * t;
  16029. x += (frames[i + PathConstraintMixTimeline$2.ENTRIES + PathConstraintMixTimeline$2.X] - x) * t;
  16030. y += (frames[i + PathConstraintMixTimeline$2.ENTRIES + PathConstraintMixTimeline$2.Y] - y) * t;
  16031. break;
  16032. case PathConstraintMixTimeline$2.STEPPED:
  16033. rotate = frames[i + PathConstraintMixTimeline$2.ROTATE];
  16034. x = frames[i + PathConstraintMixTimeline$2.X];
  16035. y = frames[i + PathConstraintMixTimeline$2.Y];
  16036. break;
  16037. default:
  16038. rotate = this.getBezierValue(time, i, PathConstraintMixTimeline$2.ROTATE, curveType - PathConstraintMixTimeline$2.BEZIER);
  16039. x = this.getBezierValue(time, i, PathConstraintMixTimeline$2.X, curveType + PathConstraintMixTimeline$2.BEZIER_SIZE - PathConstraintMixTimeline$2.BEZIER);
  16040. y = this.getBezierValue(time, i, PathConstraintMixTimeline$2.Y, curveType + PathConstraintMixTimeline$2.BEZIER_SIZE * 2 - PathConstraintMixTimeline$2.BEZIER);
  16041. }
  16042. if (blend == MixBlend$2.setup) {
  16043. let data = constraint.data;
  16044. constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha;
  16045. constraint.mixX = data.mixX + (x - data.mixX) * alpha;
  16046. constraint.mixY = data.mixY + (y - data.mixY) * alpha;
  16047. } else {
  16048. constraint.mixRotate += (rotate - constraint.mixRotate) * alpha;
  16049. constraint.mixX += (x - constraint.mixX) * alpha;
  16050. constraint.mixY += (y - constraint.mixY) * alpha;
  16051. }
  16052. }
  16053. } PathConstraintMixTimeline$2.__initStatic49(); PathConstraintMixTimeline$2.__initStatic50(); PathConstraintMixTimeline$2.__initStatic51(); PathConstraintMixTimeline$2.__initStatic52();
  16054. /** Applies animations over time, queues animations for later playback, mixes (crossfading) between animations, and applies
  16055. * multiple animations on top of each other (layering).
  16056. *
  16057. * See [Applying Animations](http://esotericsoftware.com/spine-applying-animations/) in the Spine Runtimes Guide.
  16058. * @public
  16059. * */
  16060. class AnimationState$2 {
  16061. static __initStatic() {this._emptyAnimation = null;}
  16062. static emptyAnimation() {
  16063. if (AnimationState$2._emptyAnimation == null) AnimationState$2._emptyAnimation = new Animation$2("<empty>", [], 0);
  16064. return AnimationState$2._emptyAnimation;
  16065. }
  16066. /** 1. A previously applied timeline has set this property.
  16067. *
  16068. * Result: Mix from the current pose to the timeline pose. */
  16069. static __initStatic2() {this.SUBSEQUENT = 0;}
  16070. /** 1. This is the first timeline to set this property.
  16071. * 2. The next track entry applied after this one does not have a timeline to set this property.
  16072. *
  16073. * Result: Mix from the setup pose to the timeline pose. */
  16074. static __initStatic3() {this.FIRST = 1;}
  16075. /** 1) A previously applied timeline has set this property.<br>
  16076. * 2) The next track entry to be applied does have a timeline to set this property.<br>
  16077. * 3) The next track entry after that one does not have a timeline to set this property.<br>
  16078. * Result: Mix from the current pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading
  16079. * animations that key the same property. A subsequent timeline will set this property using a mix. */
  16080. static __initStatic4() {this.HOLD_SUBSEQUENT = 2;}
  16081. /** 1) This is the first timeline to set this property.<br>
  16082. * 2) The next track entry to be applied does have a timeline to set this property.<br>
  16083. * 3) The next track entry after that one does not have a timeline to set this property.<br>
  16084. * Result: Mix from the setup pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading animations
  16085. * that key the same property. A subsequent timeline will set this property using a mix. */
  16086. static __initStatic5() {this.HOLD_FIRST = 3;}
  16087. /** 1. This is the first timeline to set this property.
  16088. * 2. The next track entry to be applied does have a timeline to set this property.
  16089. * 3. The next track entry after that one does have a timeline to set this property.
  16090. * 4. timelineHoldMix stores the first subsequent track entry that does not have a timeline to set this property.
  16091. *
  16092. * Result: The same as HOLD except the mix percentage from the timelineHoldMix track entry is used. This handles when more than
  16093. * 2 track entries in a row have a timeline that sets the same property.
  16094. *
  16095. * Eg, A -> B -> C -> D where A, B, and C have a timeline setting same property, but D does not. When A is applied, to avoid
  16096. * "dipping" A is not mixed out, however D (the first entry that doesn't set the property) mixing in is used to mix out A
  16097. * (which affects B and C). Without using D to mix out, A would be applied fully until mixing completes, then snap into
  16098. * place. */
  16099. static __initStatic6() {this.HOLD_MIX = 4;}
  16100. static __initStatic7() {this.SETUP = 1;}
  16101. static __initStatic8() {this.CURRENT = 2;}
  16102. /** The AnimationStateData to look up mix durations. */
  16103. /** The list of tracks that currently have animations, which may contain null entries. */
  16104. __init() {this.tracks = new Array();}
  16105. /** Multiplier for the delta time when the animation state is updated, causing time for all animations and mixes to play slower
  16106. * or faster. Defaults to 1.
  16107. *
  16108. * See TrackEntry {@link TrackEntry#timeScale} for affecting a single animation. */
  16109. __init2() {this.timeScale = 1;}
  16110. __init3() {this.unkeyedState = 0;}
  16111. __init4() {this.events = new Array();}
  16112. __init5() {this.listeners = new Array();}
  16113. __init6() {this.queue = new EventQueue$2(this);}
  16114. __init7() {this.propertyIDs = new StringSet();}
  16115. __init8() {this.animationsChanged = false;}
  16116. __init9() {this.trackEntryPool = new Pool(() => new TrackEntry$2());}
  16117. constructor (data) {AnimationState$2.prototype.__init.call(this);AnimationState$2.prototype.__init2.call(this);AnimationState$2.prototype.__init3.call(this);AnimationState$2.prototype.__init4.call(this);AnimationState$2.prototype.__init5.call(this);AnimationState$2.prototype.__init6.call(this);AnimationState$2.prototype.__init7.call(this);AnimationState$2.prototype.__init8.call(this);AnimationState$2.prototype.__init9.call(this);
  16118. this.data = data;
  16119. }
  16120. /** Increments each track entry {@link TrackEntry#trackTime()}, setting queued animations as current if needed. */
  16121. update (delta) {
  16122. delta *= this.timeScale;
  16123. let tracks = this.tracks;
  16124. for (let i = 0, n = tracks.length; i < n; i++) {
  16125. let current = tracks[i];
  16126. if (current == null) continue;
  16127. current.animationLast = current.nextAnimationLast;
  16128. current.trackLast = current.nextTrackLast;
  16129. let currentDelta = delta * current.timeScale;
  16130. if (current.delay > 0) {
  16131. current.delay -= currentDelta;
  16132. if (current.delay > 0) continue;
  16133. currentDelta = -current.delay;
  16134. current.delay = 0;
  16135. }
  16136. let next = current.next;
  16137. if (next != null) {
  16138. // When the next entry's delay is passed, change to the next entry, preserving leftover time.
  16139. let nextTime = current.trackLast - next.delay;
  16140. if (nextTime >= 0) {
  16141. next.delay = 0;
  16142. next.trackTime += current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale;
  16143. current.trackTime += currentDelta;
  16144. this.setCurrent(i, next, true);
  16145. while (next.mixingFrom != null) {
  16146. next.mixTime += delta;
  16147. next = next.mixingFrom;
  16148. }
  16149. continue;
  16150. }
  16151. } else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  16152. tracks[i] = null;
  16153. this.queue.end(current);
  16154. this.disposeNext(current);
  16155. continue;
  16156. }
  16157. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  16158. // End mixing from entries once all have completed.
  16159. let from = current.mixingFrom;
  16160. current.mixingFrom = null;
  16161. if (from != null) from.mixingTo = null;
  16162. while (from != null) {
  16163. this.queue.end(from);
  16164. from = from.mixingFrom;
  16165. }
  16166. }
  16167. current.trackTime += currentDelta;
  16168. }
  16169. this.queue.drain();
  16170. }
  16171. /** Returns true when all mixing from entries are complete. */
  16172. updateMixingFrom (to, delta) {
  16173. let from = to.mixingFrom;
  16174. if (from == null) return true;
  16175. let finished = this.updateMixingFrom(from, delta);
  16176. from.animationLast = from.nextAnimationLast;
  16177. from.trackLast = from.nextTrackLast;
  16178. // Require mixTime > 0 to ensure the mixing from entry was applied at least once.
  16179. if (to.mixTime > 0 && to.mixTime >= to.mixDuration) {
  16180. // Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
  16181. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  16182. to.mixingFrom = from.mixingFrom;
  16183. if (from.mixingFrom != null) from.mixingFrom.mixingTo = to;
  16184. to.interruptAlpha = from.interruptAlpha;
  16185. this.queue.end(from);
  16186. }
  16187. return finished;
  16188. }
  16189. from.trackTime += delta * from.timeScale;
  16190. to.mixTime += delta;
  16191. return false;
  16192. }
  16193. /** Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the
  16194. * animation state can be applied to multiple skeletons to pose them identically.
  16195. * @returns True if any animations were applied. */
  16196. apply (skeleton) {
  16197. if (skeleton == null) throw new Error("skeleton cannot be null.");
  16198. if (this.animationsChanged) this._animationsChanged();
  16199. let events = this.events;
  16200. let tracks = this.tracks;
  16201. let applied = false;
  16202. for (let i = 0, n = tracks.length; i < n; i++) {
  16203. let current = tracks[i];
  16204. if (current == null || current.delay > 0) continue;
  16205. applied = true;
  16206. let blend = i == 0 ? MixBlend$2.first : current.mixBlend;
  16207. // Apply mixing from entries first.
  16208. let mix = current.alpha;
  16209. if (current.mixingFrom != null)
  16210. mix *= this.applyMixingFrom(current, skeleton, blend);
  16211. else if (current.trackTime >= current.trackEnd && current.next == null)
  16212. mix = 0;
  16213. // Apply current entry.
  16214. let animationLast = current.animationLast, animationTime = current.getAnimationTime(), applyTime = animationTime;
  16215. let applyEvents = events;
  16216. if (current.reverse) {
  16217. applyTime = current.animation.duration - applyTime;
  16218. applyEvents = null;
  16219. }
  16220. let timelineCount = current.animation.timelines.length;
  16221. let timelines = current.animation.timelines;
  16222. if ((i == 0 && mix == 1) || blend == MixBlend$2.add) {
  16223. for (let ii = 0; ii < timelineCount; ii++) {
  16224. // Fixes issue #302 on IOS9 where mix, blend sometimes became undefined and caused assets
  16225. // to sometimes stop rendering when using color correction, as their RGBA values become NaN.
  16226. // (https://github.com/pixijs/pixi-spine/issues/302)
  16227. Utils.webkit602BugfixHelper(mix, blend);
  16228. var timeline = timelines[ii];
  16229. if (timeline instanceof AttachmentTimeline$2)
  16230. this.applyAttachmentTimeline(timeline, skeleton, applyTime, blend, true);
  16231. else
  16232. timeline.apply(skeleton, animationLast, applyTime, applyEvents, mix, blend, MixDirection$2.mixIn);
  16233. }
  16234. } else {
  16235. let timelineMode = current.timelineMode;
  16236. let firstFrame = current.timelinesRotation.length == 0;
  16237. if (firstFrame) Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  16238. let timelinesRotation = current.timelinesRotation;
  16239. for (let ii = 0; ii < timelineCount; ii++) {
  16240. let timeline = timelines[ii];
  16241. let timelineBlend = timelineMode[ii] == AnimationState$2.SUBSEQUENT ? blend : MixBlend$2.setup;
  16242. if (timeline instanceof RotateTimeline$2) {
  16243. this.applyRotateTimeline(timeline, skeleton, applyTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
  16244. } else if (timeline instanceof AttachmentTimeline$2) {
  16245. this.applyAttachmentTimeline(timeline, skeleton, applyTime, blend, true);
  16246. } else {
  16247. // This fixes the WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  16248. Utils.webkit602BugfixHelper(mix, blend);
  16249. timeline.apply(skeleton, animationLast, applyTime, applyEvents, mix, timelineBlend, MixDirection$2.mixIn);
  16250. }
  16251. }
  16252. }
  16253. this.queueEvents(current, animationTime);
  16254. events.length = 0;
  16255. current.nextAnimationLast = animationTime;
  16256. current.nextTrackLast = current.trackTime;
  16257. }
  16258. // Set slots attachments to the setup pose, if needed. This occurs if an animation that is mixing out sets attachments so
  16259. // subsequent timelines see any deform, but the subsequent timelines don't set an attachment (eg they are also mixing out or
  16260. // the time is before the first key).
  16261. var setupState = this.unkeyedState + AnimationState$2.SETUP;
  16262. var slots = skeleton.slots;
  16263. for (var i = 0, n = skeleton.slots.length; i < n; i++) {
  16264. var slot = slots[i];
  16265. if (slot.attachmentState == setupState) {
  16266. var attachmentName = slot.data.attachmentName;
  16267. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  16268. }
  16269. }
  16270. this.unkeyedState += 2; // Increasing after each use avoids the need to reset attachmentState for every slot.
  16271. this.queue.drain();
  16272. return applied;
  16273. }
  16274. applyMixingFrom (to, skeleton, blend) {
  16275. let from = to.mixingFrom;
  16276. if (from.mixingFrom != null) this.applyMixingFrom(from, skeleton, blend);
  16277. let mix = 0;
  16278. if (to.mixDuration == 0) { // Single frame mix to undo mixingFrom changes.
  16279. mix = 1;
  16280. if (blend == MixBlend$2.first) blend = MixBlend$2.setup;
  16281. } else {
  16282. mix = to.mixTime / to.mixDuration;
  16283. if (mix > 1) mix = 1;
  16284. if (blend != MixBlend$2.first) blend = from.mixBlend;
  16285. }
  16286. let attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  16287. let timelineCount = from.animation.timelines.length;
  16288. let timelines = from.animation.timelines;
  16289. let alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
  16290. let animationLast = from.animationLast, animationTime = from.getAnimationTime(), applyTime = animationTime;
  16291. let events = null;
  16292. // let events = mix < from.eventThreshold ? this.events : null;
  16293. if (from.reverse) {
  16294. applyTime = from.animation.duration - applyTime;
  16295. } else {
  16296. if (mix < from.eventThreshold) events = this.events;
  16297. }
  16298. if (blend == MixBlend$2.add) {
  16299. for (let i = 0; i < timelineCount; i++)
  16300. timelines[i].apply(skeleton, animationLast, applyTime, events, alphaMix, blend, MixDirection$2.mixOut);
  16301. } else {
  16302. let timelineMode = from.timelineMode;
  16303. let timelineHoldMix = from.timelineHoldMix;
  16304. let firstFrame = from.timelinesRotation.length == 0;
  16305. if (firstFrame) Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  16306. let timelinesRotation = from.timelinesRotation;
  16307. from.totalAlpha = 0;
  16308. for (let i = 0; i < timelineCount; i++) {
  16309. let timeline = timelines[i];
  16310. let direction = MixDirection$2.mixOut;
  16311. let timelineBlend;
  16312. let alpha = 0;
  16313. switch (timelineMode[i]) {
  16314. case AnimationState$2.SUBSEQUENT:
  16315. if (!drawOrder && timeline instanceof DrawOrderTimeline$2) continue;
  16316. timelineBlend = blend;
  16317. alpha = alphaMix;
  16318. break;
  16319. case AnimationState$2.FIRST:
  16320. timelineBlend = MixBlend$2.setup;
  16321. alpha = alphaMix;
  16322. break;
  16323. case AnimationState$2.HOLD_SUBSEQUENT:
  16324. timelineBlend = blend;
  16325. alpha = alphaHold;
  16326. break;
  16327. case AnimationState$2.HOLD_FIRST:
  16328. timelineBlend = MixBlend$2.setup;
  16329. alpha = alphaHold;
  16330. break;
  16331. default:
  16332. timelineBlend = MixBlend$2.setup;
  16333. let holdMix = timelineHoldMix[i];
  16334. alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
  16335. break;
  16336. }
  16337. from.totalAlpha += alpha;
  16338. if (timeline instanceof RotateTimeline$2)
  16339. this.applyRotateTimeline(timeline, skeleton, applyTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame);
  16340. else if (timeline instanceof AttachmentTimeline$2)
  16341. this.applyAttachmentTimeline(timeline, skeleton, applyTime, timelineBlend, attachments);
  16342. else {
  16343. // This fixes the WebKit 602 specific issue described at http://esotericsoftware.com/forum/iOS-10-disappearing-graphics-10109
  16344. Utils.webkit602BugfixHelper(alpha, blend);
  16345. if (drawOrder && timeline instanceof DrawOrderTimeline$2 && timelineBlend == MixBlend$2.setup)
  16346. direction = MixDirection$2.mixIn;
  16347. timeline.apply(skeleton, animationLast, applyTime, events, alpha, timelineBlend, direction);
  16348. }
  16349. }
  16350. }
  16351. if (to.mixDuration > 0) this.queueEvents(from, animationTime);
  16352. this.events.length = 0;
  16353. from.nextAnimationLast = animationTime;
  16354. from.nextTrackLast = from.trackTime;
  16355. return mix;
  16356. }
  16357. applyAttachmentTimeline (timeline, skeleton, time, blend, attachments) {
  16358. var slot = skeleton.slots[timeline.slotIndex];
  16359. if (!slot.bone.active) return;
  16360. var frames = timeline.frames;
  16361. if (time < frames[0]) { // Time is before first frame.
  16362. if (blend == MixBlend$2.setup || blend == MixBlend$2.first)
  16363. this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments);
  16364. }
  16365. else
  16366. this.setAttachment(skeleton, slot, timeline.attachmentNames[Animation$2.search(frames, time)], attachments);
  16367. // If an attachment wasn't set (ie before the first frame or attachments is false), set the setup attachment later.
  16368. if (slot.attachmentState <= this.unkeyedState) slot.attachmentState = this.unkeyedState + AnimationState$2.SETUP;
  16369. }
  16370. setAttachment (skeleton, slot, attachmentName, attachments) {
  16371. slot.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  16372. if (attachments) slot.attachmentState = this.unkeyedState + AnimationState$2.CURRENT;
  16373. }
  16374. applyRotateTimeline (timeline, skeleton, time, alpha, blend,
  16375. timelinesRotation, i, firstFrame) {
  16376. if (firstFrame) timelinesRotation[i] = 0;
  16377. if (alpha == 1) {
  16378. timeline.apply(skeleton, 0, time, null, 1, blend, MixDirection$2.mixIn);
  16379. return;
  16380. }
  16381. let rotateTimeline = timeline ;
  16382. let bone = skeleton.bones[rotateTimeline.boneIndex];
  16383. if (!bone.active) return;
  16384. let frames = rotateTimeline.frames;
  16385. let r1 = 0, r2 = 0;
  16386. if (time < frames[0]) {
  16387. switch (blend) {
  16388. case MixBlend$2.setup:
  16389. bone.rotation = bone.data.rotation;
  16390. default:
  16391. return;
  16392. case MixBlend$2.first:
  16393. r1 = bone.rotation;
  16394. r2 = bone.data.rotation;
  16395. }
  16396. } else {
  16397. r1 = blend == MixBlend$2.setup ? bone.data.rotation : bone.rotation;
  16398. r2 = bone.data.rotation + rotateTimeline.getCurveValue(time);
  16399. }
  16400. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
  16401. let total = 0, diff = r2 - r1;
  16402. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  16403. if (diff == 0) {
  16404. total = timelinesRotation[i];
  16405. } else {
  16406. let lastTotal = 0, lastDiff = 0;
  16407. if (firstFrame) {
  16408. lastTotal = 0;
  16409. lastDiff = diff;
  16410. } else {
  16411. lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops.
  16412. lastDiff = timelinesRotation[i + 1]; // Difference between bones.
  16413. }
  16414. let current = diff > 0, dir = lastTotal >= 0;
  16415. // Detect cross at 0 (not 180).
  16416. if (MathUtils.signum(lastDiff) != MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  16417. // A cross after a 360 rotation is a loop.
  16418. if (Math.abs(lastTotal) > 180) lastTotal += 360 * MathUtils.signum(lastTotal);
  16419. dir = current;
  16420. }
  16421. total = diff + lastTotal - lastTotal % 360; // Store loops as part of lastTotal.
  16422. if (dir != current) total += 360 * MathUtils.signum(lastTotal);
  16423. timelinesRotation[i] = total;
  16424. }
  16425. timelinesRotation[i + 1] = diff;
  16426. bone.rotation = r1 + total * alpha;
  16427. }
  16428. queueEvents (entry, animationTime) {
  16429. let animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  16430. let duration = animationEnd - animationStart;
  16431. let trackLastWrapped = entry.trackLast % duration;
  16432. // Queue events before complete.
  16433. let events = this.events;
  16434. let i = 0, n = events.length;
  16435. for (; i < n; i++) {
  16436. let event = events[i];
  16437. if (event.time < trackLastWrapped) break;
  16438. if (event.time > animationEnd) continue; // Discard events outside animation start/end.
  16439. this.queue.event(entry, event);
  16440. }
  16441. // Queue complete if completed a loop iteration or the animation.
  16442. let complete = false;
  16443. if (entry.loop)
  16444. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  16445. else
  16446. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  16447. if (complete) this.queue.complete(entry);
  16448. // Queue events after complete.
  16449. for (; i < n; i++) {
  16450. let event = events[i];
  16451. if (event.time < animationStart) continue; // Discard events outside animation start/end.
  16452. this.queue.event(entry, event);
  16453. }
  16454. }
  16455. /** Removes all animations from all tracks, leaving skeletons in their current pose.
  16456. *
  16457. * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose,
  16458. * rather than leaving them in their current pose. */
  16459. clearTracks () {
  16460. let oldDrainDisabled = this.queue.drainDisabled;
  16461. this.queue.drainDisabled = true;
  16462. for (let i = 0, n = this.tracks.length; i < n; i++)
  16463. this.clearTrack(i);
  16464. this.tracks.length = 0;
  16465. this.queue.drainDisabled = oldDrainDisabled;
  16466. this.queue.drain();
  16467. }
  16468. /** Removes all animations from the track, leaving skeletons in their current pose.
  16469. *
  16470. * It may be desired to use {@link AnimationState#setEmptyAnimation()} to mix the skeletons back to the setup pose,
  16471. * rather than leaving them in their current pose. */
  16472. clearTrack (trackIndex) {
  16473. if (trackIndex >= this.tracks.length) return;
  16474. let current = this.tracks[trackIndex];
  16475. if (current == null) return;
  16476. this.queue.end(current);
  16477. this.disposeNext(current);
  16478. let entry = current;
  16479. while (true) {
  16480. let from = entry.mixingFrom;
  16481. if (from == null) break;
  16482. this.queue.end(from);
  16483. entry.mixingFrom = null;
  16484. entry.mixingTo = null;
  16485. entry = from;
  16486. }
  16487. this.tracks[current.trackIndex] = null;
  16488. this.queue.drain();
  16489. }
  16490. /** Removes the {@link TrackEntry#getNext() next entry} and all entries after it for the specified entry. */
  16491. clearNext(entry) {
  16492. this.disposeNext(entry.next);
  16493. }
  16494. setCurrent (index, current, interrupt) {
  16495. let from = this.expandToIndex(index);
  16496. this.tracks[index] = current;
  16497. current.previous = null;
  16498. if (from != null) {
  16499. if (interrupt) this.queue.interrupt(from);
  16500. current.mixingFrom = from;
  16501. from.mixingTo = current;
  16502. current.mixTime = 0;
  16503. // Store the interrupted mix percentage.
  16504. if (from.mixingFrom != null && from.mixDuration > 0)
  16505. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  16506. from.timelinesRotation.length = 0; // Reset rotation for mixing out, in case entry was mixed in.
  16507. }
  16508. this.queue.start(current);
  16509. }
  16510. /** Sets an animation by name.
  16511. *
  16512. * {@link #setAnimationWith(}. */
  16513. setAnimation (trackIndex, animationName, loop) {
  16514. let animation = this.data.skeletonData.findAnimation(animationName);
  16515. if (animation == null) throw new Error("Animation not found: " + animationName);
  16516. return this.setAnimationWith(trackIndex, animation, loop);
  16517. }
  16518. /** Sets the current animation for a track, discarding any queued animations. If the formerly current track entry was never
  16519. * applied to a skeleton, it is replaced (not mixed from).
  16520. * @param loop If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
  16521. * duration. In either case {@link TrackEntry#trackEnd} determines when the track is cleared.
  16522. * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept
  16523. * after the {@link AnimationStateListener#dispose()} event occurs. */
  16524. setAnimationWith (trackIndex, animation, loop) {
  16525. if (animation == null) throw new Error("animation cannot be null.");
  16526. let interrupt = true;
  16527. let current = this.expandToIndex(trackIndex);
  16528. if (current != null) {
  16529. if (current.nextTrackLast == -1) {
  16530. // Don't mix from an entry that was never applied.
  16531. this.tracks[trackIndex] = current.mixingFrom;
  16532. this.queue.interrupt(current);
  16533. this.queue.end(current);
  16534. this.disposeNext(current);
  16535. current = current.mixingFrom;
  16536. interrupt = false;
  16537. } else
  16538. this.disposeNext(current);
  16539. }
  16540. let entry = this.trackEntry(trackIndex, animation, loop, current);
  16541. this.setCurrent(trackIndex, entry, interrupt);
  16542. this.queue.drain();
  16543. return entry;
  16544. }
  16545. /** Queues an animation by name.
  16546. *
  16547. * See {@link #addAnimationWith()}. */
  16548. addAnimation (trackIndex, animationName, loop, delay) {
  16549. let animation = this.data.skeletonData.findAnimation(animationName);
  16550. if (animation == null) throw new Error("Animation not found: " + animationName);
  16551. return this.addAnimationWith(trackIndex, animation, loop, delay);
  16552. }
  16553. /** Adds an animation to be played after the current or last queued animation for a track. If the track is empty, it is
  16554. * equivalent to calling {@link #setAnimationWith()}.
  16555. * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry
  16556. * minus any mix duration (from the {@link AnimationStateData}) plus the specified `delay` (ie the mix
  16557. * ends at (`delay` = 0) or before (`delay` < 0) the previous track entry duration). If the
  16558. * previous entry is looping, its next loop completion is used instead of its duration.
  16559. * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept
  16560. * after the {@link AnimationStateListener#dispose()} event occurs. */
  16561. addAnimationWith (trackIndex, animation, loop, delay) {
  16562. if (animation == null) throw new Error("animation cannot be null.");
  16563. let last = this.expandToIndex(trackIndex);
  16564. if (last != null) {
  16565. while (last.next != null)
  16566. last = last.next;
  16567. }
  16568. let entry = this.trackEntry(trackIndex, animation, loop, last);
  16569. if (last == null) {
  16570. this.setCurrent(trackIndex, entry, true);
  16571. this.queue.drain();
  16572. } else {
  16573. last.next = entry;
  16574. entry.previous = last;
  16575. if (delay <= 0) delay += last.getTrackComplete() - entry.mixDuration;
  16576. }
  16577. entry.delay = delay;
  16578. return entry;
  16579. }
  16580. /** Sets an empty animation for a track, discarding any queued animations, and sets the track entry's
  16581. * {@link TrackEntry#mixduration}. An empty animation has no timelines and serves as a placeholder for mixing in or out.
  16582. *
  16583. * Mixing out is done by setting an empty animation with a mix duration using either {@link #setEmptyAnimation()},
  16584. * {@link #setEmptyAnimations()}, or {@link #addEmptyAnimation()}. Mixing to an empty animation causes
  16585. * the previous animation to be applied less and less over the mix duration. Properties keyed in the previous animation
  16586. * transition to the value from lower tracks or to the setup pose value if no lower tracks key the property. A mix duration of
  16587. * 0 still mixes out over one frame.
  16588. *
  16589. * Mixing in is done by first setting an empty animation, then adding an animation using
  16590. * {@link #addAnimation()} and on the returned track entry, set the
  16591. * {@link TrackEntry#setMixDuration()}. Mixing from an empty animation causes the new animation to be applied more and
  16592. * more over the mix duration. Properties keyed in the new animation transition from the value from lower tracks or from the
  16593. * setup pose value if no lower tracks key the property to the value keyed in the new animation. */
  16594. setEmptyAnimation (trackIndex, mixDuration) {
  16595. let entry = this.setAnimationWith(trackIndex, AnimationState$2.emptyAnimation(), false);
  16596. entry.mixDuration = mixDuration;
  16597. entry.trackEnd = mixDuration;
  16598. return entry;
  16599. }
  16600. /** Adds an empty animation to be played after the current or last queued animation for a track, and sets the track entry's
  16601. * {@link TrackEntry#mixDuration}. If the track is empty, it is equivalent to calling
  16602. * {@link #setEmptyAnimation()}.
  16603. *
  16604. * See {@link #setEmptyAnimation()}.
  16605. * @param delay If > 0, sets {@link TrackEntry#delay}. If <= 0, the delay set is the duration of the previous track entry
  16606. * minus any mix duration plus the specified `delay` (ie the mix ends at (`delay` = 0) or
  16607. * before (`delay` < 0) the previous track entry duration). If the previous entry is looping, its next
  16608. * loop completion is used instead of its duration.
  16609. * @return A track entry to allow further customization of animation playback. References to the track entry must not be kept
  16610. * after the {@link AnimationStateListener#dispose()} event occurs. */
  16611. addEmptyAnimation (trackIndex, mixDuration, delay) {
  16612. let entry = this.addAnimationWith(trackIndex, AnimationState$2.emptyAnimation(), false, delay <= 0 ? 1 : delay);
  16613. entry.mixDuration = mixDuration;
  16614. entry.trackEnd = mixDuration;
  16615. if (delay <= 0 && entry.previous != null) entry.delay = entry.previous.getTrackComplete() - entry.mixDuration;
  16616. return entry;
  16617. }
  16618. /** Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix
  16619. * duration. */
  16620. setEmptyAnimations (mixDuration) {
  16621. let oldDrainDisabled = this.queue.drainDisabled;
  16622. this.queue.drainDisabled = true;
  16623. for (let i = 0, n = this.tracks.length; i < n; i++) {
  16624. let current = this.tracks[i];
  16625. if (current != null) this.setEmptyAnimation(current.trackIndex, mixDuration);
  16626. }
  16627. this.queue.drainDisabled = oldDrainDisabled;
  16628. this.queue.drain();
  16629. }
  16630. expandToIndex (index) {
  16631. if (index < this.tracks.length) return this.tracks[index];
  16632. Utils.ensureArrayCapacity(this.tracks, index + 1, null);
  16633. this.tracks.length = index + 1;
  16634. return null;
  16635. }
  16636. /** @param last May be null. */
  16637. trackEntry (trackIndex, animation, loop, last) {
  16638. let entry = this.trackEntryPool.obtain();
  16639. entry.trackIndex = trackIndex;
  16640. entry.animation = animation;
  16641. entry.loop = loop;
  16642. entry.holdPrevious = false;
  16643. entry.eventThreshold = 0;
  16644. entry.attachmentThreshold = 0;
  16645. entry.drawOrderThreshold = 0;
  16646. entry.animationStart = 0;
  16647. entry.animationEnd = animation.duration;
  16648. entry.animationLast = -1;
  16649. entry.nextAnimationLast = -1;
  16650. entry.delay = 0;
  16651. entry.trackTime = 0;
  16652. entry.trackLast = -1;
  16653. entry.nextTrackLast = -1;
  16654. entry.trackEnd = Number.MAX_VALUE;
  16655. entry.timeScale = 1;
  16656. entry.alpha = 1;
  16657. entry.interruptAlpha = 1;
  16658. entry.mixTime = 0;
  16659. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  16660. entry.mixBlend = MixBlend$2.replace;
  16661. return entry;
  16662. }
  16663. disposeNext (entry) {
  16664. let next = entry.next;
  16665. while (next != null) {
  16666. this.queue.dispose(next);
  16667. next = next.next;
  16668. }
  16669. entry.next = null;
  16670. }
  16671. _animationsChanged () {
  16672. this.animationsChanged = false;
  16673. this.propertyIDs.clear();
  16674. for (let i = 0, n = this.tracks.length; i < n; i++) {
  16675. let entry = this.tracks[i];
  16676. if (entry == null) continue;
  16677. while (entry.mixingFrom != null)
  16678. entry = entry.mixingFrom;
  16679. do {
  16680. if (entry.mixingFrom == null || entry.mixBlend != MixBlend$2.add) this.computeHold(entry);
  16681. entry = entry.mixingTo;
  16682. } while (entry != null)
  16683. }
  16684. }
  16685. computeHold (entry) {
  16686. let to = entry.mixingTo;
  16687. let timelines = entry.animation.timelines;
  16688. let timelinesCount = entry.animation.timelines.length;
  16689. let timelineMode = Utils.setArraySize(entry.timelineMode, timelinesCount);
  16690. entry.timelineHoldMix.length = 0;
  16691. let timelineDipMix = Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
  16692. let propertyIDs = this.propertyIDs;
  16693. if (to != null && to.holdPrevious) {
  16694. for (let i = 0; i < timelinesCount; i++) {
  16695. timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? AnimationState$2.HOLD_FIRST : AnimationState$2.HOLD_SUBSEQUENT;
  16696. }
  16697. return;
  16698. }
  16699. outer:
  16700. for (let i = 0; i < timelinesCount; i++) {
  16701. let timeline = timelines[i];
  16702. let ids = timeline.getPropertyIds();
  16703. if (!propertyIDs.addAll(ids))
  16704. timelineMode[i] = AnimationState$2.SUBSEQUENT;
  16705. else if (to == null || timeline instanceof AttachmentTimeline$2 || timeline instanceof DrawOrderTimeline$2
  16706. || timeline instanceof EventTimeline$2 || !to.animation.hasTimeline(ids)) {
  16707. timelineMode[i] = AnimationState$2.FIRST;
  16708. } else {
  16709. for (let next = to.mixingTo; next != null; next = next.mixingTo) {
  16710. if (next.animation.hasTimeline(ids)) continue;
  16711. if (entry.mixDuration > 0) {
  16712. timelineMode[i] = AnimationState$2.HOLD_MIX;
  16713. timelineDipMix[i] = next;
  16714. continue outer;
  16715. }
  16716. break;
  16717. }
  16718. timelineMode[i] = AnimationState$2.HOLD_FIRST;
  16719. }
  16720. }
  16721. }
  16722. /** Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing. */
  16723. getCurrent (trackIndex) {
  16724. if (trackIndex >= this.tracks.length) return null;
  16725. return this.tracks[trackIndex];
  16726. }
  16727. /** Adds a listener to receive events for all track entries. */
  16728. addListener (listener) {
  16729. if (listener == null) throw new Error("listener cannot be null.");
  16730. this.listeners.push(listener);
  16731. }
  16732. /** Removes the listener added with {@link #addListener()}. */
  16733. removeListener (listener) {
  16734. let index = this.listeners.indexOf(listener);
  16735. if (index >= 0) this.listeners.splice(index, 1);
  16736. }
  16737. /** Removes all listeners added with {@link #addListener()}. */
  16738. clearListeners () {
  16739. this.listeners.length = 0;
  16740. }
  16741. /** Discards all listener notifications that have not yet been delivered. This can be useful to call from an
  16742. * {@link AnimationStateListener} when it is known that further notifications that may have been already queued for delivery
  16743. * are not wanted because new animations are being set. */
  16744. clearListenerNotifications () {
  16745. this.queue.clear();
  16746. }
  16747. //deprecated stuff
  16748. static __initStatic9() {this.deprecatedWarning1 = false;}
  16749. setAnimationByName(trackIndex, animationName, loop) {
  16750. if (!AnimationState$2.deprecatedWarning1) {
  16751. AnimationState$2.deprecatedWarning1 = true;
  16752. console.warn("Spine Deprecation Warning: AnimationState.setAnimationByName is deprecated, please use setAnimation from now on.");
  16753. }
  16754. this.setAnimation(trackIndex, animationName, loop);
  16755. }
  16756. static __initStatic10() {this.deprecatedWarning2 = false;}
  16757. addAnimationByName(trackIndex, animationName, loop, delay) {
  16758. if (!AnimationState$2.deprecatedWarning2) {
  16759. AnimationState$2.deprecatedWarning2 = true;
  16760. console.warn("Spine Deprecation Warning: AnimationState.addAnimationByName is deprecated, please use addAnimation from now on.");
  16761. }
  16762. this.addAnimation(trackIndex, animationName, loop, delay);
  16763. }
  16764. static __initStatic11() {this.deprecatedWarning3 = false;}
  16765. hasAnimation(animationName) {
  16766. let animation = this.data.skeletonData.findAnimation(animationName);
  16767. return animation !== null;
  16768. }
  16769. hasAnimationByName(animationName) {
  16770. if (!AnimationState$2.deprecatedWarning3) {
  16771. AnimationState$2.deprecatedWarning3 = true;
  16772. console.warn("Spine Deprecation Warning: AnimationState.hasAnimationByName is deprecated, please use hasAnimation from now on.");
  16773. }
  16774. return this.hasAnimation(animationName);
  16775. }
  16776. } AnimationState$2.__initStatic(); AnimationState$2.__initStatic2(); AnimationState$2.__initStatic3(); AnimationState$2.__initStatic4(); AnimationState$2.__initStatic5(); AnimationState$2.__initStatic6(); AnimationState$2.__initStatic7(); AnimationState$2.__initStatic8(); AnimationState$2.__initStatic9(); AnimationState$2.__initStatic10(); AnimationState$2.__initStatic11();
  16777. /** Stores settings and other state for the playback of an animation on an {@link AnimationState} track.
  16778. *
  16779. * References to a track entry must not be kept after the {@link AnimationStateListener#dispose()} event occurs.
  16780. * @public
  16781. * */
  16782. class TrackEntry$2 {constructor() { TrackEntry$2.prototype.__init10.call(this);TrackEntry$2.prototype.__init11.call(this);TrackEntry$2.prototype.__init12.call(this);TrackEntry$2.prototype.__init13.call(this); }
  16783. /** The animation to apply for this track entry. */
  16784. /** The animation queued to start after this animation, or null. `next` makes up a linked list. */
  16785. /** The track entry for the previous animation when mixing from the previous animation to this animation, or null if no
  16786. * mixing is currently occuring. When mixing from multiple animations, `mixingFrom` makes up a linked list. */
  16787. /** The track entry for the next animation when mixing from this animation to the next animation, or null if no mixing is
  16788. * currently occuring. When mixing to multiple animations, `mixingTo` makes up a linked list. */
  16789. /** The listener for events generated by this track entry, or null.
  16790. *
  16791. * A track entry returned from {@link AnimationState#setAnimation()} is already the current animation
  16792. * for the track, so the track entry listener {@link AnimationStateListener#start()} will not be called. */
  16793. /** The index of the track where this track entry is either current or queued.
  16794. *
  16795. * See {@link AnimationState#getCurrent()}. */
  16796. /** If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its
  16797. * duration. */
  16798. /** If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead
  16799. * of being mixed out.
  16800. *
  16801. * When mixing between animations that key the same property, if a lower track also keys that property then the value will
  16802. * briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0%
  16803. * while the second animation mixes from 0% to 100%. Setting `holdPrevious` to true applies the first animation
  16804. * at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which
  16805. * keys the property, only when a higher track also keys the property.
  16806. *
  16807. * Snapping will occur if `holdPrevious` is true and this animation does not key all the same properties as the
  16808. * previous animation. */
  16809. /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the
  16810. * `eventThreshold`, event timelines are applied while this animation is being mixed out. Defaults to 0, so event
  16811. * timelines are not applied while this animation is being mixed out. */
  16812. /** When the mix percentage ({@link #mixtime} / {@link #mixDuration}) is less than the
  16813. * `attachmentThreshold`, attachment timelines are applied while this animation is being mixed out. Defaults to
  16814. * 0, so attachment timelines are not applied while this animation is being mixed out. */
  16815. /** When the mix percentage ({@link #mixTime} / {@link #mixDuration}) is less than the
  16816. * `drawOrderThreshold`, draw order timelines are applied while this animation is being mixed out. Defaults to 0,
  16817. * so draw order timelines are not applied while this animation is being mixed out. */
  16818. /** Seconds when this animation starts, both initially and after looping. Defaults to 0.
  16819. *
  16820. * When changing the `animationStart` time, it often makes sense to set {@link #animationLast} to the same
  16821. * value to prevent timeline keys before the start time from triggering. */
  16822. /** Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will
  16823. * loop back to {@link #animationStart} at this time. Defaults to the animation {@link Animation#duration}. */
  16824. /** The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this
  16825. * animation is applied, event timelines will fire all events between the `animationLast` time (exclusive) and
  16826. * `animationTime` (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation
  16827. * is applied. */
  16828. /** Seconds to postpone playing the animation. When this track entry is the current track entry, `delay`
  16829. * postpones incrementing the {@link #trackTime}. When this track entry is queued, `delay` is the time from
  16830. * the start of the previous animation to when this track entry will become the current track entry (ie when the previous
  16831. * track entry {@link TrackEntry#trackTime} >= this track entry's `delay`).
  16832. *
  16833. * {@link #timeScale} affects the delay. */
  16834. /** Current time in seconds this track entry has been the current track entry. The track time determines
  16835. * {@link #animationTime}. The track time can be set to start the animation at a time other than 0, without affecting
  16836. * looping. */
  16837. /** The track time in seconds when this animation will be removed from the track. Defaults to the highest possible float
  16838. * value, meaning the animation will be applied until a new animation is set or the track is cleared. If the track end time
  16839. * is reached, no other animations are queued for playback, and mixing from any previous animations is complete, then the
  16840. * properties keyed by the animation are set to the setup pose and the track is cleared.
  16841. *
  16842. * It may be desired to use {@link AnimationState#addEmptyAnimation()} rather than have the animation
  16843. * abruptly cease being applied. */
  16844. /** Multiplier for the delta time when this track entry is updated, causing time for this animation to pass slower or
  16845. * faster. Defaults to 1.
  16846. *
  16847. * {@link #mixTime} is not affected by track entry time scale, so {@link #mixDuration} may need to be adjusted to
  16848. * match the animation speed.
  16849. *
  16850. * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the
  16851. * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, assuming time scale to be 1. If
  16852. * the time scale is not 1, the delay may need to be adjusted.
  16853. *
  16854. * See AnimationState {@link AnimationState#timeScale} for affecting all animations. */
  16855. /** Values < 1 mix this animation with the skeleton's current pose (usually the pose resulting from lower tracks). Defaults
  16856. * to 1, which overwrites the skeleton's current pose with this animation.
  16857. *
  16858. * Typically track 0 is used to completely pose the skeleton, then alpha is used on higher tracks. It doesn't make sense to
  16859. * use alpha on track 0 if the skeleton pose is from the last frame render. */
  16860. /** Seconds from 0 to the {@link #getMixDuration()} when mixing from the previous animation to this animation. May be
  16861. * slightly more than `mixDuration` when the mix is complete. */
  16862. /** Seconds for mixing from the previous animation to this animation. Defaults to the value provided by AnimationStateData
  16863. * {@link AnimationStateData#getMix()} based on the animation before this animation (if any).
  16864. *
  16865. * A mix duration of 0 still mixes out over one frame to provide the track entry being mixed out a chance to revert the
  16866. * properties it was animating.
  16867. *
  16868. * The `mixDuration` can be set manually rather than use the value from
  16869. * {@link AnimationStateData#getMix()}. In that case, the `mixDuration` can be set for a new
  16870. * track entry only before {@link AnimationState#update(float)} is first called.
  16871. *
  16872. * When using {@link AnimationState#addAnimation()} with a `delay` <= 0, note the
  16873. * {@link #delay} is set using the mix duration from the {@link AnimationStateData}, not a mix duration set
  16874. * afterward. */
  16875. /** Controls how properties keyed in the animation are mixed with lower tracks. Defaults to {@link MixBlend#replace}, which
  16876. * replaces the values from the lower tracks with the animation values. {@link MixBlend#add} adds the animation values to
  16877. * the values from the lower tracks.
  16878. *
  16879. * The `mixBlend` can be set for a new track entry only before {@link AnimationState#apply()} is first
  16880. * called. */
  16881. __init10() {this.mixBlend = MixBlend$2.replace;}
  16882. __init11() {this.timelineMode = new Array();}
  16883. __init12() {this.timelineHoldMix = new Array();}
  16884. __init13() {this.timelinesRotation = new Array();}
  16885. reset () {
  16886. this.previous = null;
  16887. this.next = null;
  16888. this.mixingFrom = null;
  16889. this.mixingTo = null;
  16890. this.animation = null;
  16891. this.listener = null;
  16892. this.timelineMode.length = 0;
  16893. this.timelineHoldMix.length = 0;
  16894. this.timelinesRotation.length = 0;
  16895. }
  16896. /** Uses {@link #trackTime} to compute the `animationTime`, which is between {@link #animationStart}
  16897. * and {@link #animationEnd}. When the `trackTime` is 0, the `animationTime` is equal to the
  16898. * `animationStart` time. */
  16899. getAnimationTime () {
  16900. if (this.loop) {
  16901. let duration = this.animationEnd - this.animationStart;
  16902. if (duration == 0) return this.animationStart;
  16903. return (this.trackTime % duration) + this.animationStart;
  16904. }
  16905. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  16906. }
  16907. setAnimationLast(animationLast) {
  16908. this.animationLast = animationLast;
  16909. this.nextAnimationLast = animationLast;
  16910. }
  16911. /** Returns true if at least one loop has been completed.
  16912. *
  16913. * See {@link AnimationStateListener#complete()}. */
  16914. isComplete () {
  16915. return this.trackTime >= this.animationEnd - this.animationStart;
  16916. }
  16917. /** Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the
  16918. * long way around when using {@link #alpha} and starting animations on other tracks.
  16919. *
  16920. * Mixing with {@link MixBlend#replace} involves finding a rotation between two others, which has two possible solutions:
  16921. * the short way or the long way around. The two rotations likely change over time, so which direction is the short or long
  16922. * way also changes. If the short way was always chosen, bones would flip to the other side when that direction became the
  16923. * long way. TrackEntry chooses the short way the first time it is applied and remembers that direction. */
  16924. resetRotationDirections () {
  16925. this.timelinesRotation.length = 0;
  16926. }
  16927. getTrackComplete() {
  16928. let duration = this.animationEnd - this.animationStart;
  16929. if (duration != 0) {
  16930. if (this.loop) return duration * (1 + ((this.trackTime / duration) | 0)); // Completion of next loop.
  16931. if (this.trackTime < duration) return duration; // Before duration.
  16932. }
  16933. return this.trackTime; // Next update.
  16934. }
  16935. //deprecated stuff
  16936. static __initStatic12() {this.deprecatedWarning1 = false;}
  16937. static __initStatic13() {this.deprecatedWarning2 = false;}
  16938. get time() {
  16939. if (!TrackEntry$2.deprecatedWarning1) {
  16940. TrackEntry$2.deprecatedWarning1 = true;
  16941. console.warn("Spine Deprecation Warning: TrackEntry.time is deprecated, please use trackTime from now on.");
  16942. }
  16943. return this.trackTime;
  16944. }
  16945. set time(value) {
  16946. if (!TrackEntry$2.deprecatedWarning1) {
  16947. TrackEntry$2.deprecatedWarning1 = true;
  16948. console.warn("Spine Deprecation Warning: TrackEntry.time is deprecated, please use trackTime from now on.");
  16949. }
  16950. this.trackTime = value;
  16951. }
  16952. get endTime() {
  16953. if (!TrackEntry$2.deprecatedWarning2) {
  16954. TrackEntry$2.deprecatedWarning2 = true;
  16955. console.warn("Spine Deprecation Warning: TrackEntry.endTime is deprecated, please use trackEnd from now on.");
  16956. }
  16957. return this.trackTime;
  16958. }
  16959. set endTime(value) {
  16960. if (!TrackEntry$2.deprecatedWarning2) {
  16961. TrackEntry$2.deprecatedWarning2 = true;
  16962. console.warn("Spine Deprecation Warning: TrackEntry.endTime is deprecated, please use trackEnd from now on.");
  16963. }
  16964. this.trackTime = value;
  16965. }
  16966. loopsCount() {
  16967. return Math.floor(this.trackTime / this.trackEnd);
  16968. }
  16969. } TrackEntry$2.__initStatic12(); TrackEntry$2.__initStatic13();
  16970. /**
  16971. * @public
  16972. */
  16973. class EventQueue$2 {
  16974. __init14() {this.objects = [];}
  16975. __init15() {this.drainDisabled = false;}
  16976. constructor(animState) {EventQueue$2.prototype.__init14.call(this);EventQueue$2.prototype.__init15.call(this);
  16977. this.animState = animState;
  16978. }
  16979. start (entry) {
  16980. this.objects.push(EventType$2.start);
  16981. this.objects.push(entry);
  16982. this.animState.animationsChanged = true;
  16983. }
  16984. interrupt (entry) {
  16985. this.objects.push(EventType$2.interrupt);
  16986. this.objects.push(entry);
  16987. }
  16988. end (entry) {
  16989. this.objects.push(EventType$2.end);
  16990. this.objects.push(entry);
  16991. this.animState.animationsChanged = true;
  16992. }
  16993. dispose (entry) {
  16994. this.objects.push(EventType$2.dispose);
  16995. this.objects.push(entry);
  16996. }
  16997. complete (entry) {
  16998. this.objects.push(EventType$2.complete);
  16999. this.objects.push(entry);
  17000. }
  17001. event (entry, event) {
  17002. this.objects.push(EventType$2.event);
  17003. this.objects.push(entry);
  17004. this.objects.push(event);
  17005. }
  17006. drain () {
  17007. if (this.drainDisabled) return;
  17008. this.drainDisabled = true;
  17009. let objects = this.objects;
  17010. let listeners = this.animState.listeners;
  17011. for (let i = 0; i < objects.length; i += 2) {
  17012. let type = objects[i] ;
  17013. let entry = objects[i + 1] ;
  17014. switch (type) {
  17015. case EventType$2.start:
  17016. if (entry.listener != null && entry.listener.start) entry.listener.start(entry);
  17017. for (let ii = 0; ii < listeners.length; ii++)
  17018. if (listeners[ii].start) listeners[ii].start(entry);
  17019. break;
  17020. case EventType$2.interrupt:
  17021. if (entry.listener != null && entry.listener.interrupt) entry.listener.interrupt(entry);
  17022. for (let ii = 0; ii < listeners.length; ii++)
  17023. if (listeners[ii].interrupt) listeners[ii].interrupt(entry);
  17024. break;
  17025. case EventType$2.end:
  17026. if (entry.listener != null && entry.listener.end) entry.listener.end(entry);
  17027. for (let ii = 0; ii < listeners.length; ii++)
  17028. if (listeners[ii].end) listeners[ii].end(entry);
  17029. // Fall through.
  17030. case EventType$2.dispose:
  17031. if (entry.listener != null && entry.listener.dispose) entry.listener.dispose(entry);
  17032. for (let ii = 0; ii < listeners.length; ii++)
  17033. if (listeners[ii].dispose) listeners[ii].dispose(entry);
  17034. this.animState.trackEntryPool.free(entry);
  17035. break;
  17036. case EventType$2.complete:
  17037. if (entry.listener != null && entry.listener.complete) entry.listener.complete(entry);
  17038. for (let ii = 0; ii < listeners.length; ii++)
  17039. if (listeners[ii].complete) listeners[ii].complete(entry);
  17040. break;
  17041. case EventType$2.event:
  17042. let event = objects[i++ + 2] ;
  17043. if (entry.listener != null && entry.listener.event) entry.listener.event(entry, event);
  17044. for (let ii = 0; ii < listeners.length; ii++)
  17045. if (listeners[ii].event) listeners[ii].event(entry, event);
  17046. break;
  17047. }
  17048. }
  17049. this.clear();
  17050. this.drainDisabled = false;
  17051. }
  17052. clear () {
  17053. this.objects.length = 0;
  17054. }
  17055. }
  17056. /**
  17057. * @public
  17058. */
  17059. var EventType$2; (function (EventType) {
  17060. const start = 0; EventType[EventType["start"] = start] = "start"; const interrupt = start + 1; EventType[EventType["interrupt"] = interrupt] = "interrupt"; const end = interrupt + 1; EventType[EventType["end"] = end] = "end"; const dispose = end + 1; EventType[EventType["dispose"] = dispose] = "dispose"; const complete = dispose + 1; EventType[EventType["complete"] = complete] = "complete"; const event = complete + 1; EventType[EventType["event"] = event] = "event";
  17061. })(EventType$2 || (EventType$2 = {}));
  17062. /** The interface to implement for receiving TrackEntry events. It is always safe to call AnimationState methods when receiving
  17063. * events.
  17064. *
  17065. * See TrackEntry {@link TrackEntry#listener} and AnimationState
  17066. * {@link AnimationState#addListener()}.
  17067. * @public
  17068. * */
  17069. /**
  17070. * @public
  17071. */
  17072. class AnimationStateAdapter$1 {
  17073. start (entry) {
  17074. }
  17075. interrupt (entry) {
  17076. }
  17077. end (entry) {
  17078. }
  17079. dispose (entry) {
  17080. }
  17081. complete (entry) {
  17082. }
  17083. event (entry, event) {
  17084. }
  17085. }
  17086. /** Stores mix (crossfade) durations to be applied when {@link AnimationState} animations are changed.
  17087. * @public
  17088. * */
  17089. class AnimationStateData$2 {
  17090. /** The SkeletonData to look up animations when they are specified by name. */
  17091. __init() {this.animationToMixTime = { };}
  17092. /** The mix duration to use when no mix duration has been defined between two animations. */
  17093. __init2() {this.defaultMix = 0;}
  17094. constructor (skeletonData) {AnimationStateData$2.prototype.__init.call(this);AnimationStateData$2.prototype.__init2.call(this);
  17095. if (skeletonData == null) throw new Error("skeletonData cannot be null.");
  17096. this.skeletonData = skeletonData;
  17097. }
  17098. /** Sets a mix duration by animation name.
  17099. *
  17100. * See {@link #setMixWith()}. */
  17101. setMix (fromName, toName, duration) {
  17102. let from = this.skeletonData.findAnimation(fromName);
  17103. if (from == null) throw new Error("Animation not found: " + fromName);
  17104. let to = this.skeletonData.findAnimation(toName);
  17105. if (to == null) throw new Error("Animation not found: " + toName);
  17106. this.setMixWith(from, to, duration);
  17107. }
  17108. /** Sets the mix duration when changing from the specified animation to the other.
  17109. *
  17110. * See {@link TrackEntry#mixDuration}. */
  17111. setMixWith (from, to, duration) {
  17112. if (from == null) throw new Error("from cannot be null.");
  17113. if (to == null) throw new Error("to cannot be null.");
  17114. let key = from.name + "." + to.name;
  17115. this.animationToMixTime[key] = duration;
  17116. }
  17117. /** Returns the mix duration to use when changing from the specified animation to the other, or the {@link #defaultMix} if
  17118. * no mix duration has been set. */
  17119. getMix (from, to) {
  17120. let key = from.name + "." + to.name;
  17121. let value = this.animationToMixTime[key];
  17122. return value === undefined ? this.defaultMix : value;
  17123. }
  17124. }
  17125. /**
  17126. * @public
  17127. */
  17128. class AtlasAttachmentLoader$2 {
  17129. constructor(atlas) {
  17130. this.atlas = atlas;
  17131. }
  17132. /** @return May be null to not load an attachment. */
  17133. // @ts-ignore
  17134. newRegionAttachment(skin, name, path) {
  17135. let region = this.atlas.findRegion(path);
  17136. if (region == null) throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  17137. let attachment = new RegionAttachment$2(name);
  17138. attachment.region = region;
  17139. return attachment;
  17140. }
  17141. /** @return May be null to not load an attachment. */
  17142. // @ts-ignore
  17143. newMeshAttachment(skin, name, path) {
  17144. let region = this.atlas.findRegion(path);
  17145. if (region == null) throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  17146. let attachment = new MeshAttachment$2(name);
  17147. attachment.region = region;
  17148. return attachment;
  17149. }
  17150. /** @return May be null to not load an attachment. */
  17151. // @ts-ignore
  17152. newBoundingBoxAttachment(skin, name) {
  17153. return new BoundingBoxAttachment$2(name);
  17154. }
  17155. /** @return May be null to not load an attachment */
  17156. // @ts-ignore
  17157. newPathAttachment(skin, name) {
  17158. return new PathAttachment$2(name);
  17159. }
  17160. // @ts-ignore
  17161. newPointAttachment(skin, name) {
  17162. return new PointAttachment$2(name);
  17163. }
  17164. // @ts-ignore
  17165. newClippingAttachment(skin, name) {
  17166. return new ClippingAttachment$2(name);
  17167. }
  17168. }
  17169. /** Stores the setup pose for a {@link Bone}.
  17170. * @public
  17171. * */
  17172. class BoneData$2 {
  17173. /** The index of the bone in {@link Skeleton#getBones()}. */
  17174. /** The name of the bone, which is unique across all bones in the skeleton. */
  17175. /** @returns May be null. */
  17176. /** The bone's length. */
  17177. /** The local x translation. */
  17178. __init() {this.x = 0;}
  17179. /** The local y translation. */
  17180. __init2() {this.y = 0;}
  17181. /** The local rotation. */
  17182. __init3() {this.rotation = 0;}
  17183. /** The local scaleX. */
  17184. __init4() {this.scaleX = 1;}
  17185. /** The local scaleY. */
  17186. __init5() {this.scaleY = 1;}
  17187. /** The local shearX. */
  17188. __init6() {this.shearX = 0;}
  17189. /** The local shearX. */
  17190. __init7() {this.shearY = 0;}
  17191. /** The transform mode for how parent world transforms affect this bone. */
  17192. __init8() {this.transformMode = TransformMode$2.Normal;}
  17193. /** When true, {@link Skeleton#updateWorldTransform()} only updates this bone if the {@link Skeleton#skin} contains this
  17194. * bone.
  17195. * @see Skin#bones */
  17196. __init9() {this.skinRequired = false;}
  17197. /** The color of the bone as it was in Spine. Available only when nonessential data was exported. Bones are not usually
  17198. * rendered at runtime. */
  17199. __init10() {this.color = new Color();}
  17200. constructor (index, name, parent) {BoneData$2.prototype.__init.call(this);BoneData$2.prototype.__init2.call(this);BoneData$2.prototype.__init3.call(this);BoneData$2.prototype.__init4.call(this);BoneData$2.prototype.__init5.call(this);BoneData$2.prototype.__init6.call(this);BoneData$2.prototype.__init7.call(this);BoneData$2.prototype.__init8.call(this);BoneData$2.prototype.__init9.call(this);BoneData$2.prototype.__init10.call(this);
  17201. if (index < 0) throw new Error("index must be >= 0.");
  17202. if (name == null) throw new Error("name cannot be null.");
  17203. this.index = index;
  17204. this.name = name;
  17205. this.parent = parent;
  17206. }
  17207. }
  17208. /** Determines how a bone inherits world transforms from parent bones.
  17209. * @public
  17210. * */
  17211. var TransformMode$2; (function (TransformMode) {
  17212. const Normal = 0; TransformMode[TransformMode["Normal"] = Normal] = "Normal"; const OnlyTranslation = Normal + 1; TransformMode[TransformMode["OnlyTranslation"] = OnlyTranslation] = "OnlyTranslation"; const NoRotationOrReflection = OnlyTranslation + 1; TransformMode[TransformMode["NoRotationOrReflection"] = NoRotationOrReflection] = "NoRotationOrReflection"; const NoScale = NoRotationOrReflection + 1; TransformMode[TransformMode["NoScale"] = NoScale] = "NoScale"; const NoScaleOrReflection = NoScale + 1; TransformMode[TransformMode["NoScaleOrReflection"] = NoScaleOrReflection] = "NoScaleOrReflection";
  17213. })(TransformMode$2 || (TransformMode$2 = {}));
  17214. /** Stores a bone's current pose.
  17215. *
  17216. * A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a
  17217. * local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a
  17218. * constraint or application code modifies the world transform after it was computed from the local transform.
  17219. * @public
  17220. * */
  17221. class Bone$2 {
  17222. //be careful! Spine b,c is c,b in pixi matrix
  17223. __init() {this.matrix = new math.Matrix();}
  17224. get worldX() {
  17225. return this.matrix.tx;
  17226. }
  17227. get worldY() {
  17228. return this.matrix.ty;
  17229. }
  17230. /** The bone's setup pose data. */
  17231. /** The skeleton this bone belongs to. */
  17232. /** The parent bone, or null if this is the root bone. */
  17233. /** The immediate children of this bone. */
  17234. __init2() {this.children = new Array();}
  17235. /** The local x translation. */
  17236. __init3() {this.x = 0;}
  17237. /** The local y translation. */
  17238. __init4() {this.y = 0;}
  17239. /** The local rotation in degrees, counter clockwise. */
  17240. __init5() {this.rotation = 0;}
  17241. /** The local scaleX. */
  17242. __init6() {this.scaleX = 0;}
  17243. /** The local scaleY. */
  17244. __init7() {this.scaleY = 0;}
  17245. /** The local shearX. */
  17246. __init8() {this.shearX = 0;}
  17247. /** The local shearY. */
  17248. __init9() {this.shearY = 0;}
  17249. /** The applied local x translation. */
  17250. __init10() {this.ax = 0;}
  17251. /** The applied local y translation. */
  17252. __init11() {this.ay = 0;}
  17253. /** The applied local rotation in degrees, counter clockwise. */
  17254. __init12() {this.arotation = 0;}
  17255. /** The applied local scaleX. */
  17256. __init13() {this.ascaleX = 0;}
  17257. /** The applied local scaleY. */
  17258. __init14() {this.ascaleY = 0;}
  17259. /** The applied local shearX. */
  17260. __init15() {this.ashearX = 0;}
  17261. /** The applied local shearY. */
  17262. __init16() {this.ashearY = 0;}
  17263. /** If true, the applied transform matches the world transform. If false, the world transform has been modified since it was
  17264. * computed and {@link #updateAppliedTransform()} must be called before accessing the applied transform. */
  17265. __init17() {this.appliedValid = false;}
  17266. __init18() {this.sorted = false;}
  17267. __init19() {this.active = false;}
  17268. /** @param parent May be null. */
  17269. constructor (data, skeleton, parent) {Bone$2.prototype.__init.call(this);Bone$2.prototype.__init2.call(this);Bone$2.prototype.__init3.call(this);Bone$2.prototype.__init4.call(this);Bone$2.prototype.__init5.call(this);Bone$2.prototype.__init6.call(this);Bone$2.prototype.__init7.call(this);Bone$2.prototype.__init8.call(this);Bone$2.prototype.__init9.call(this);Bone$2.prototype.__init10.call(this);Bone$2.prototype.__init11.call(this);Bone$2.prototype.__init12.call(this);Bone$2.prototype.__init13.call(this);Bone$2.prototype.__init14.call(this);Bone$2.prototype.__init15.call(this);Bone$2.prototype.__init16.call(this);Bone$2.prototype.__init17.call(this);Bone$2.prototype.__init18.call(this);Bone$2.prototype.__init19.call(this);
  17270. if (data == null) throw new Error("data cannot be null.");
  17271. if (skeleton == null) throw new Error("skeleton cannot be null.");
  17272. this.data = data;
  17273. this.skeleton = skeleton;
  17274. this.parent = parent;
  17275. this.setToSetupPose();
  17276. }
  17277. /** Returns false when the bone has not been computed because {@link BoneData#skinRequired} is true and the
  17278. * {@link Skeleton#skin active skin} does not {@link Skin#bones contain} this bone. */
  17279. isActive () {
  17280. return this.active;
  17281. }
  17282. /** Same as {@link #updateWorldTransform()}. This method exists for Bone to implement {@link Updatable}. */
  17283. update () {
  17284. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  17285. }
  17286. /** Computes the world transform using the parent bone and this bone's local transform.
  17287. *
  17288. * See {@link #updateWorldTransformWith()}. */
  17289. updateWorldTransform () {
  17290. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  17291. }
  17292. /** Computes the world transform using the parent bone and the specified local transform. Child bones are not updated.
  17293. *
  17294. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  17295. * Runtimes Guide. */
  17296. updateWorldTransformWith (x, y, rotation, scaleX, scaleY, shearX, shearY) {
  17297. this.ax = x;
  17298. this.ay = y;
  17299. this.arotation = rotation;
  17300. this.ascaleX = scaleX;
  17301. this.ascaleY = scaleY;
  17302. this.ashearX = shearX;
  17303. this.ashearY = shearY;
  17304. this.appliedValid = true;
  17305. let parent = this.parent;
  17306. let m = this.matrix;
  17307. let sx = this.skeleton.scaleX;
  17308. let sy = settings.yDown? -this.skeleton.scaleY : this.skeleton.scaleY;
  17309. if (parent == null) { // Root bone.
  17310. let skeleton = this.skeleton;
  17311. let rotationY = rotation + 90 + shearY;
  17312. m.a = MathUtils.cosDeg(rotation + shearX) * scaleX * sx;
  17313. m.c = MathUtils.cosDeg(rotationY) * scaleY * sx;
  17314. m.b = MathUtils.sinDeg(rotation + shearX) * scaleX * sy;
  17315. m.d = MathUtils.sinDeg(rotationY) * scaleY * sy;
  17316. m.tx = x * sx + skeleton.x;
  17317. m.ty = y * sy + skeleton.y;
  17318. return;
  17319. }
  17320. let pa = parent.matrix.a, pb = parent.matrix.c, pc = parent.matrix.b, pd = parent.matrix.d;
  17321. m.tx = pa * x + pb * y + parent.matrix.tx;
  17322. m.ty = pc * x + pd * y + parent.matrix.ty;
  17323. switch (this.data.transformMode) {
  17324. case TransformMode$2.Normal: {
  17325. let rotationY = rotation + 90 + shearY;
  17326. let la = MathUtils.cosDeg(rotation + shearX) * scaleX;
  17327. let lb = MathUtils.cosDeg(rotationY) * scaleY;
  17328. let lc = MathUtils.sinDeg(rotation + shearX) * scaleX;
  17329. let ld = MathUtils.sinDeg(rotationY) * scaleY;
  17330. m.a = pa * la + pb * lc;
  17331. m.c = pa * lb + pb * ld;
  17332. m.b = pc * la + pd * lc;
  17333. m.d = pc * lb + pd * ld;
  17334. return;
  17335. }
  17336. case TransformMode$2.OnlyTranslation: {
  17337. let rotationY = rotation + 90 + shearY;
  17338. m.a = MathUtils.cosDeg(rotation + shearX) * scaleX;
  17339. m.c = MathUtils.cosDeg(rotationY) * scaleY;
  17340. m.b = MathUtils.sinDeg(rotation + shearX) * scaleX;
  17341. m.d = MathUtils.sinDeg(rotationY) * scaleY;
  17342. break;
  17343. }
  17344. case TransformMode$2.NoRotationOrReflection: {
  17345. let s = pa * pa + pc * pc;
  17346. let prx = 0;
  17347. if (s > 0.0001) {
  17348. s = Math.abs(pa * pd - pb * pc) / s;
  17349. pa /= this.skeleton.scaleX;
  17350. pc /= this.skeleton.scaleY;
  17351. pb = pc * s;
  17352. pd = pa * s;
  17353. prx = Math.atan2(pc, pa) * MathUtils.radDeg;
  17354. } else {
  17355. pa = 0;
  17356. pc = 0;
  17357. prx = 90 - Math.atan2(pd, pb) * MathUtils.radDeg;
  17358. }
  17359. let rx = rotation + shearX - prx;
  17360. let ry = rotation + shearY - prx + 90;
  17361. let la = MathUtils.cosDeg(rx) * scaleX;
  17362. let lb = MathUtils.cosDeg(ry) * scaleY;
  17363. let lc = MathUtils.sinDeg(rx) * scaleX;
  17364. let ld = MathUtils.sinDeg(ry) * scaleY;
  17365. m.a = pa * la - pb * lc;
  17366. m.c = pa * lb - pb * ld;
  17367. m.b = pc * la + pd * lc;
  17368. m.d = pc * lb + pd * ld;
  17369. break;
  17370. }
  17371. case TransformMode$2.NoScale:
  17372. case TransformMode$2.NoScaleOrReflection: {
  17373. let cos = MathUtils.cosDeg(rotation);
  17374. let sin = MathUtils.sinDeg(rotation);
  17375. let za = (pa * cos + pb * sin) / sx;
  17376. let zc = (pc * cos + pd * sin) / sy;
  17377. let s = Math.sqrt(za * za + zc * zc);
  17378. if (s > 0.00001) s = 1 / s;
  17379. za *= s;
  17380. zc *= s;
  17381. s = Math.sqrt(za * za + zc * zc);
  17382. if (
  17383. this.data.transformMode == TransformMode$2.NoScale
  17384. && (pa * pd - pb * pc < 0) != (settings.yDown?
  17385. (this.skeleton.scaleX < 0 != this.skeleton.scaleY > 0) :
  17386. (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0))
  17387. ) s = -s;
  17388. let r = Math.PI / 2 + Math.atan2(zc, za);
  17389. let zb = Math.cos(r) * s;
  17390. let zd = Math.sin(r) * s;
  17391. let la = MathUtils.cosDeg(shearX) * scaleX;
  17392. let lb = MathUtils.cosDeg(90 + shearY) * scaleY;
  17393. let lc = MathUtils.sinDeg(shearX) * scaleX;
  17394. let ld = MathUtils.sinDeg(90 + shearY) * scaleY;
  17395. m.a = za * la + zb * lc;
  17396. m.c = za * lb + zb * ld;
  17397. m.b = zc * la + zd * lc;
  17398. m.d = zc * lb + zd * ld;
  17399. break;
  17400. }
  17401. }
  17402. m.a *= sx;
  17403. m.c *= sx;
  17404. m.b *= sy;
  17405. m.d *= sy;
  17406. }
  17407. /** Sets this bone's local transform to the setup pose. */
  17408. setToSetupPose () {
  17409. let data = this.data;
  17410. this.x = data.x;
  17411. this.y = data.y;
  17412. this.rotation = data.rotation;
  17413. this.scaleX = data.scaleX;
  17414. this.scaleY = data.scaleY;
  17415. this.shearX = data.shearX;
  17416. this.shearY = data.shearY;
  17417. }
  17418. /** The world rotation for the X axis, calculated using {@link #a} and {@link #c}. */
  17419. getWorldRotationX () {
  17420. return Math.atan2(this.matrix.b, this.matrix.a) * MathUtils.radDeg;
  17421. }
  17422. /** The world rotation for the Y axis, calculated using {@link #b} and {@link #d}. */
  17423. getWorldRotationY () {
  17424. return Math.atan2(this.matrix.d, this.matrix.c) * MathUtils.radDeg;
  17425. }
  17426. /** The magnitude (always positive) of the world scale X, calculated using {@link #a} and {@link #c}. */
  17427. getWorldScaleX () {
  17428. let m = this.matrix;
  17429. return Math.sqrt(m.a * m.a + m.c * m.c);
  17430. }
  17431. /** The magnitude (always positive) of the world scale Y, calculated using {@link #b} and {@link #d}. */
  17432. getWorldScaleY () {
  17433. let m = this.matrix;
  17434. return Math.sqrt(m.b * m.b + m.d * m.d);
  17435. }
  17436. /** Computes the applied transform values from the world transform. This allows the applied transform to be accessed after the
  17437. * world transform has been modified (by a constraint, {@link #rotateWorld()}, etc).
  17438. *
  17439. * If {@link #updateWorldTransform()} has been called for a bone and {@link #appliedValid} is false, then
  17440. * {@link #updateAppliedTransform()} must be called before accessing the applied transform.
  17441. *
  17442. * Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after
  17443. * calling this method is equivalent to the local tranform used to compute the world transform, but may not be identical. */
  17444. updateAppliedTransform () {
  17445. this.appliedValid = true;
  17446. let parent = this.parent;
  17447. let m = this.matrix;
  17448. if (parent == null) {
  17449. this.ax = m.tx;
  17450. this.ay = m.ty;
  17451. this.arotation = Math.atan2(m.b, m.a) * MathUtils.radDeg;
  17452. this.ascaleX = Math.sqrt(m.a * m.a + m.b * m.b);
  17453. this.ascaleY = Math.sqrt(m.c * m.c + m.d * m.d);
  17454. this.ashearX = 0;
  17455. this.ashearY = Math.atan2(m.a * m.c + m.b * m.d, m.a * m.d - m.b * m.c) * MathUtils.radDeg;
  17456. return;
  17457. }
  17458. let pm = parent.matrix;
  17459. let pid = 1 / (pm.a * pm.d - pm.b * pm.c);
  17460. let dx = m.tx - pm.tx, dy = m.ty - pm.ty;
  17461. this.ax = (dx * pm.d * pid - dy * pm.c * pid);
  17462. this.ay = (dy * pm.a * pid - dx * pm.b * pid);
  17463. let ia = pid * pm.d;
  17464. let id = pid * pm.a;
  17465. let ib = pid * pm.c;
  17466. let ic = pid * pm.b;
  17467. let ra = ia * m.a - ib * m.b;
  17468. let rb = ia * m.c - ib * m.d;
  17469. let rc = id * m.b - ic * m.a;
  17470. let rd = id * m.d - ic * m.c;
  17471. this.ashearX = 0;
  17472. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  17473. if (this.ascaleX > 0.0001) {
  17474. let det = ra * rd - rb * rc;
  17475. this.ascaleY = det / this.ascaleX;
  17476. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * MathUtils.radDeg;
  17477. this.arotation = Math.atan2(rc, ra) * MathUtils.radDeg;
  17478. } else {
  17479. this.ascaleX = 0;
  17480. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  17481. this.ashearY = 0;
  17482. this.arotation = 90 - Math.atan2(rd, rb) * MathUtils.radDeg;
  17483. }
  17484. }
  17485. /** Transforms a point from world coordinates to the bone's local coordinates. */
  17486. worldToLocal(world) {
  17487. let m = this.matrix;
  17488. let a = m.a, b = m.c, c = m.b, d = m.d;
  17489. let invDet = 1 / (a * d - b * c);
  17490. let x = world.x - m.tx, y = world.y - m.ty;
  17491. world.x = (x * d * invDet - y * b * invDet);
  17492. world.y = (y * a * invDet - x * c * invDet);
  17493. return world;
  17494. }
  17495. /** Transforms a point from the bone's local coordinates to world coordinates. */
  17496. localToWorld(local) {
  17497. let m = this.matrix;
  17498. let x = local.x, y = local.y;
  17499. local.x = x * m.a + y * m.c + m.tx;
  17500. local.y = x * m.b + y * m.d + m.ty;
  17501. return local;
  17502. }
  17503. /** Transforms a world rotation to a local rotation. */
  17504. worldToLocalRotation (worldRotation) {
  17505. let sin = MathUtils.sinDeg(worldRotation), cos = MathUtils.cosDeg(worldRotation);
  17506. let mat = this.matrix;
  17507. return Math.atan2(mat.a * sin - mat.b * cos, mat.d * cos - mat.c * sin) * MathUtils.radDeg;
  17508. }
  17509. /** Transforms a local rotation to a world rotation. */
  17510. localToWorldRotation (localRotation) {
  17511. //TODO: check same place in 3.8
  17512. localRotation -= this.rotation - this.shearX;
  17513. let sin = MathUtils.sinDeg(localRotation), cos = MathUtils.cosDeg(localRotation);
  17514. let mat = this.matrix;
  17515. return Math.atan2(cos * mat.b + sin * mat.d, cos * mat.a + sin * mat.c) * MathUtils.radDeg;
  17516. }
  17517. /** Rotates the world transform the specified amount and sets {@link #appliedValid} to false.
  17518. * {@link #updateWorldTransform()} will need to be called on any child bones, recursively, and any constraints reapplied. */
  17519. rotateWorld (degrees) {
  17520. let mat = this.matrix;
  17521. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  17522. let cos = MathUtils.cosDeg(degrees), sin = MathUtils.sinDeg(degrees);
  17523. mat.a = cos * a - sin * c;
  17524. mat.c = cos * b - sin * d;
  17525. mat.b = sin * a + cos * c;
  17526. mat.d = sin * b + cos * d;
  17527. this.appliedValid = false;
  17528. }
  17529. }
  17530. /** The base class for all constraint datas.
  17531. * @public
  17532. * */
  17533. class ConstraintData$1 {
  17534. constructor( name, order, skinRequired) {this.name = name;this.order = order;this.skinRequired = skinRequired; }
  17535. }
  17536. /** Stores the current pose values for an {@link Event}.
  17537. *
  17538. * See Timeline {@link Timeline#apply()},
  17539. * AnimationStateListener {@link AnimationStateListener#event()}, and
  17540. * [Events](http://esotericsoftware.com/spine-events) in the Spine User Guide.
  17541. * @public
  17542. * */
  17543. class Event$2 {
  17544. constructor (time, data) {
  17545. if (data == null) throw new Error("data cannot be null.");
  17546. this.time = time;
  17547. this.data = data;
  17548. }
  17549. }
  17550. /** Stores the setup pose values for an {@link Event}.
  17551. *
  17552. * See [Events](http://esotericsoftware.com/spine-events) in the Spine User Guide.
  17553. * @public
  17554. * */
  17555. class EventData$2 {
  17556. constructor (name) {
  17557. this.name = name;
  17558. }
  17559. }
  17560. /** Stores the current pose for an IK constraint. An IK constraint adjusts the rotation of 1 or 2 constrained bones so the tip of
  17561. * the last bone is as close to the target bone as possible.
  17562. *
  17563. * See [IK constraints](http://esotericsoftware.com/spine-ik-constraints) in the Spine User Guide.
  17564. * @public
  17565. * */
  17566. class IkConstraint$2 {
  17567. /** The IK constraint's setup pose data. */
  17568. /** The bones that will be modified by this IK constraint. */
  17569. /** The bone that is the IK target. */
  17570. /** Controls the bend direction of the IK bones, either 1 or -1. */
  17571. __init() {this.bendDirection = 0;}
  17572. /** When true and only a single bone is being constrained, if the target is too close, the bone is scaled to reach it. */
  17573. __init2() {this.compress = false;}
  17574. /** 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
  17575. * and the parent bone has local nonuniform scale, stretch is not applied. */
  17576. __init3() {this.stretch = false;}
  17577. /** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
  17578. __init4() {this.mix = 1;}
  17579. /** For two bone IK, the distance from the maximum reach of the bones that rotation will slow. */
  17580. __init5() {this.softness = 0;}
  17581. __init6() {this.active = false;}
  17582. constructor (data, skeleton) {IkConstraint$2.prototype.__init.call(this);IkConstraint$2.prototype.__init2.call(this);IkConstraint$2.prototype.__init3.call(this);IkConstraint$2.prototype.__init4.call(this);IkConstraint$2.prototype.__init5.call(this);IkConstraint$2.prototype.__init6.call(this);
  17583. if (data == null) throw new Error("data cannot be null.");
  17584. if (skeleton == null) throw new Error("skeleton cannot be null.");
  17585. this.data = data;
  17586. this.mix = data.mix;
  17587. this.softness = data.softness;
  17588. this.bendDirection = data.bendDirection;
  17589. this.compress = data.compress;
  17590. this.stretch = data.stretch;
  17591. this.bones = new Array();
  17592. for (let i = 0; i < data.bones.length; i++)
  17593. this.bones.push(skeleton.findBone(data.bones[i].name));
  17594. this.target = skeleton.findBone(data.target.name);
  17595. }
  17596. isActive () {
  17597. return this.active;
  17598. }
  17599. update () {
  17600. if (this.mix == 0) return;
  17601. let target = this.target;
  17602. let bones = this.bones;
  17603. switch (bones.length) {
  17604. case 1:
  17605. this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix);
  17606. break;
  17607. case 2:
  17608. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.softness, this.mix);
  17609. break;
  17610. }
  17611. }
  17612. /** Applies 1 bone IK. The target is specified in the world coordinate system. */
  17613. apply1 (bone, targetX, targetY, compress, stretch, uniform, alpha) {
  17614. if (!bone.appliedValid) bone.updateAppliedTransform();
  17615. let p = bone.parent.matrix;
  17616. let pa = p.a, pb = p.c, pc = p.b, pd = p.d;
  17617. let rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
  17618. switch(bone.data.transformMode) {
  17619. case TransformMode$2.OnlyTranslation:
  17620. tx = targetX - bone.worldX;
  17621. ty = targetY - bone.worldY;
  17622. break;
  17623. case TransformMode$2.NoRotationOrReflection:
  17624. let s = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
  17625. let sa = pa / bone.skeleton.scaleX;
  17626. let sc = pc / bone.skeleton.scaleY;
  17627. pb = -sc * s * bone.skeleton.scaleX;
  17628. pd = sa * s * bone.skeleton.scaleY;
  17629. rotationIK += Math.atan2(sc, sa) * MathUtils.radDeg;
  17630. // Fall through
  17631. default:
  17632. let x = targetX - p.tx, y = targetY - p.ty;
  17633. let d = pa * pd - pb * pc;
  17634. tx = (x * pd - y * pb) / d - bone.ax;
  17635. ty = (y * pa - x * pc) / d - bone.ay;
  17636. }
  17637. rotationIK += Math.atan2(ty, tx) * MathUtils.radDeg;
  17638. if (bone.ascaleX < 0) rotationIK += 180;
  17639. if (rotationIK > 180)
  17640. rotationIK -= 360;
  17641. else if (rotationIK < -180) rotationIK += 360;
  17642. let sx = bone.ascaleX, sy = bone.ascaleY;
  17643. if (compress || stretch) {
  17644. switch (bone.data.transformMode) {
  17645. case TransformMode$2.NoScale:
  17646. case TransformMode$2.NoScaleOrReflection:
  17647. tx = targetX - bone.worldX;
  17648. ty = targetY - bone.worldY;
  17649. }
  17650. let b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
  17651. if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
  17652. let s = (dd / b - 1) * alpha + 1;
  17653. sx *= s;
  17654. if (uniform) sy *= s;
  17655. }
  17656. }
  17657. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX,
  17658. bone.ashearY);
  17659. }
  17660. /** Applies 2 bone IK. The target is specified in the world coordinate system.
  17661. * @param child A direct descendant of the parent bone. */
  17662. apply2 (parent, child, targetX, targetY, bendDir, stretch, softness, alpha) {
  17663. if (!parent.appliedValid) parent.updateAppliedTransform();
  17664. if (!child.appliedValid) child.updateAppliedTransform();
  17665. let px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
  17666. let pmat = parent.matrix;
  17667. let os1 = 0, os2 = 0, s2 = 0;
  17668. if (psx < 0) {
  17669. psx = -psx;
  17670. os1 = 180;
  17671. s2 = -1;
  17672. } else {
  17673. os1 = 0;
  17674. s2 = 1;
  17675. }
  17676. if (psy < 0) {
  17677. psy = -psy;
  17678. s2 = -s2;
  17679. }
  17680. if (csx < 0) {
  17681. csx = -csx;
  17682. os2 = 180;
  17683. } else
  17684. os2 = 0;
  17685. let cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = pmat.a, b = pmat.c, c = pmat.b, d = pmat.d;
  17686. let u = Math.abs(psx - psy) <= 0.0001;
  17687. if (!u) {
  17688. cy = 0;
  17689. cwx = a * cx + pmat.tx;
  17690. cwy = c * cx + pmat.ty;
  17691. } else {
  17692. cy = child.ay;
  17693. cwx = a * cx + b * cy + pmat.tx;
  17694. cwy = c * cx + d * cy + pmat.ty;
  17695. }
  17696. let pp = parent.parent.matrix;
  17697. a = pp.a;
  17698. b = pp.c;
  17699. c = pp.b;
  17700. d = pp.d;
  17701. let id = 1 / (a * d - b * c), x = cwx - pp.tx, y = cwy - pp.ty;
  17702. let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  17703. let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
  17704. if (l1 < 0.0001) {
  17705. this.apply1(parent, targetX, targetY, false, stretch, false, alpha);
  17706. child.updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  17707. return;
  17708. }
  17709. x = targetX - pp.tx;
  17710. y = targetY - pp.ty;
  17711. let tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  17712. let dd = tx * tx + ty * ty;
  17713. if (softness != 0) {
  17714. softness *= psx * (csx + 1) / 2;
  17715. let td = Math.sqrt(dd), sd = td - l1 - l2 * psx + softness;
  17716. if (sd > 0) {
  17717. let p = Math.min(1, sd / (softness * 2)) - 1;
  17718. p = (sd - softness * (1 - p * p)) / td;
  17719. tx -= p * tx;
  17720. ty -= p * ty;
  17721. dd = tx * tx + ty * ty;
  17722. }
  17723. }
  17724. outer:
  17725. if (u) {
  17726. l2 *= psx;
  17727. let cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  17728. if (cos < -1)
  17729. cos = -1;
  17730. else if (cos > 1) {
  17731. cos = 1;
  17732. if (stretch) sx *= (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
  17733. }
  17734. a2 = Math.acos(cos) * bendDir;
  17735. a = l1 + l2 * cos;
  17736. b = l2 * Math.sin(a2);
  17737. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  17738. } else {
  17739. a = psx * l2;
  17740. b = psy * l2;
  17741. let aa = a * a, bb = b * b, ta = Math.atan2(ty, tx);
  17742. c = bb * l1 * l1 + aa * dd - aa * bb;
  17743. let c1 = -2 * bb * l1, c2 = bb - aa;
  17744. d = c1 * c1 - 4 * c2 * c;
  17745. if (d >= 0) {
  17746. let q = Math.sqrt(d);
  17747. if (c1 < 0) q = -q;
  17748. q = -(c1 + q) / 2;
  17749. let r0 = q / c2, r1 = c / q;
  17750. let r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  17751. if (r * r <= dd) {
  17752. y = Math.sqrt(dd - r * r) * bendDir;
  17753. a1 = ta - Math.atan2(y, r);
  17754. a2 = Math.atan2(y / psy, (r - l1) / psx);
  17755. break outer;
  17756. }
  17757. }
  17758. let minAngle = MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  17759. let maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  17760. c = -a * l1 / (aa - bb);
  17761. if (c >= -1 && c <= 1) {
  17762. c = Math.acos(c);
  17763. x = a * Math.cos(c) + l1;
  17764. y = b * Math.sin(c);
  17765. d = x * x + y * y;
  17766. if (d < minDist) {
  17767. minAngle = c;
  17768. minDist = d;
  17769. minX = x;
  17770. minY = y;
  17771. }
  17772. if (d > maxDist) {
  17773. maxAngle = c;
  17774. maxDist = d;
  17775. maxX = x;
  17776. maxY = y;
  17777. }
  17778. }
  17779. if (dd <= (minDist + maxDist) / 2) {
  17780. a1 = ta - Math.atan2(minY * bendDir, minX);
  17781. a2 = minAngle * bendDir;
  17782. } else {
  17783. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  17784. a2 = maxAngle * bendDir;
  17785. }
  17786. }
  17787. let os = Math.atan2(cy, cx) * s2;
  17788. let rotation = parent.arotation;
  17789. a1 = (a1 - os) * MathUtils.radDeg + os1 - rotation;
  17790. if (a1 > 180)
  17791. a1 -= 360;
  17792. else if (a1 < -180) a1 += 360;
  17793. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, parent.ascaleY, 0, 0);
  17794. rotation = child.arotation;
  17795. a2 = ((a2 + os) * MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  17796. if (a2 > 180)
  17797. a2 -= 360;
  17798. else if (a2 < -180) a2 += 360;
  17799. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  17800. }
  17801. }
  17802. /** Stores the setup pose for an {@link IkConstraint}.
  17803. * <p>
  17804. * See [IK constraints](http://esotericsoftware.com/spine-ik-constraints) in the Spine User Guide.
  17805. * @public
  17806. * */
  17807. class IkConstraintData$2 extends ConstraintData$1 {
  17808. /** The bones that are constrained by this IK constraint. */
  17809. __init() {this.bones = new Array();}
  17810. /** The bone that is the IK target. */
  17811. /** Controls the bend direction of the IK bones, either 1 or -1. */
  17812. __init2() {this.bendDirection = 1;}
  17813. /** When true and only a single bone is being constrained, if the target is too close, the bone is scaled to reach it. */
  17814. __init3() {this.compress = false;}
  17815. /** 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
  17816. * and the parent bone has local nonuniform scale, stretch is not applied. */
  17817. __init4() {this.stretch = false;}
  17818. /** When true, only a single bone is being constrained, and {@link #getCompress()} or {@link #getStretch()} is used, the bone
  17819. * is scaled on both the X and Y axes. */
  17820. __init5() {this.uniform = false;}
  17821. /** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
  17822. __init6() {this.mix = 1;}
  17823. /** For two bone IK, the distance from the maximum reach of the bones that rotation will slow. */
  17824. __init7() {this.softness = 0;}
  17825. constructor (name) {
  17826. super(name, 0, false);IkConstraintData$2.prototype.__init.call(this);IkConstraintData$2.prototype.__init2.call(this);IkConstraintData$2.prototype.__init3.call(this);IkConstraintData$2.prototype.__init4.call(this);IkConstraintData$2.prototype.__init5.call(this);IkConstraintData$2.prototype.__init6.call(this);IkConstraintData$2.prototype.__init7.call(this); }
  17827. }
  17828. /** Stores the setup pose for a {@link PathConstraint}.
  17829. *
  17830. * See [Path constraints](http://esotericsoftware.com/spine-path-constraints) in the Spine User Guide.
  17831. * @public
  17832. * */
  17833. class PathConstraintData$2 extends ConstraintData$1 {
  17834. /** The bones that will be modified by this path constraint. */
  17835. __init() {this.bones = new Array();}
  17836. /** The slot whose path attachment will be used to constrained the bones. */
  17837. /** The mode for positioning the first bone on the path. */
  17838. /** The mode for positioning the bones after the first bone on the path. */
  17839. /** The mode for adjusting the rotation of the bones. */
  17840. /** An offset added to the constrained bone rotation. */
  17841. /** The position along the path. */
  17842. /** The spacing between bones. */
  17843. __init2() {this.mixRotate = 0;}
  17844. __init3() {this.mixX = 0;}
  17845. __init4() {this.mixY = 0;}
  17846. constructor (name) {
  17847. super(name, 0, false);PathConstraintData$2.prototype.__init.call(this);PathConstraintData$2.prototype.__init2.call(this);PathConstraintData$2.prototype.__init3.call(this);PathConstraintData$2.prototype.__init4.call(this); }
  17848. }
  17849. /** Controls how the first bone is positioned along the path.
  17850. *
  17851. * See [Position mode](http://esotericsoftware.com/spine-path-constraints#Position-mode) in the Spine User Guide.
  17852. * @public
  17853. * */
  17854. var PositionMode$2; (function (PositionMode) {
  17855. const Fixed = 0; PositionMode[PositionMode["Fixed"] = Fixed] = "Fixed"; const Percent = Fixed + 1; PositionMode[PositionMode["Percent"] = Percent] = "Percent";
  17856. })(PositionMode$2 || (PositionMode$2 = {}));
  17857. /** Controls how bones after the first bone are positioned along the path.
  17858. *
  17859. * [Spacing mode](http://esotericsoftware.com/spine-path-constraints#Spacing-mode) in the Spine User Guide.
  17860. * @public
  17861. * */
  17862. var SpacingMode$2; (function (SpacingMode) {
  17863. const Length = 0; SpacingMode[SpacingMode["Length"] = Length] = "Length"; const Fixed = Length + 1; SpacingMode[SpacingMode["Fixed"] = Fixed] = "Fixed"; const Percent = Fixed + 1; SpacingMode[SpacingMode["Percent"] = Percent] = "Percent"; const Proportional = Percent + 1; SpacingMode[SpacingMode["Proportional"] = Proportional] = "Proportional";
  17864. })(SpacingMode$2 || (SpacingMode$2 = {}));
  17865. /** Controls how bones are rotated, translated, and scaled to match the path.
  17866. *
  17867. * [Rotate mode](http://esotericsoftware.com/spine-path-constraints#Rotate-mod) in the Spine User Guide.
  17868. * @public
  17869. * */
  17870. var RotateMode$2; (function (RotateMode) {
  17871. const Tangent = 0; RotateMode[RotateMode["Tangent"] = Tangent] = "Tangent"; const Chain = Tangent + 1; RotateMode[RotateMode["Chain"] = Chain] = "Chain"; const ChainScale = Chain + 1; RotateMode[RotateMode["ChainScale"] = ChainScale] = "ChainScale";
  17872. })(RotateMode$2 || (RotateMode$2 = {}));
  17873. /** Stores the current pose for a path constraint. A path constraint adjusts the rotation, translation, and scale of the
  17874. * constrained bones so they follow a {@link PathAttachment}.
  17875. *
  17876. * See [Path constraints](http://esotericsoftware.com/spine-path-constraints) in the Spine User Guide.
  17877. * @public
  17878. * */
  17879. class PathConstraint$2 {
  17880. static __initStatic() {this.NONE = -1;} static __initStatic2() {this.BEFORE = -2;} static __initStatic3() {this.AFTER = -3;}
  17881. static __initStatic4() {this.epsilon = 0.00001;}
  17882. /** The path constraint's setup pose data. */
  17883. /** The bones that will be modified by this path constraint. */
  17884. /** The slot whose path attachment will be used to constrained the bones. */
  17885. /** The position along the path. */
  17886. __init() {this.position = 0;}
  17887. /** The spacing between bones. */
  17888. __init2() {this.spacing = 0;}
  17889. __init3() {this.mixRotate = 0;}
  17890. __init4() {this.mixX = 0;}
  17891. __init5() {this.mixY = 0;}
  17892. __init6() {this.spaces = new Array();} __init7() {this.positions = new Array();}
  17893. __init8() {this.world = new Array();} __init9() {this.curves = new Array();} __init10() {this.lengths = new Array();}
  17894. __init11() {this.segments = new Array();}
  17895. __init12() {this.active = false;}
  17896. constructor (data, skeleton) {PathConstraint$2.prototype.__init.call(this);PathConstraint$2.prototype.__init2.call(this);PathConstraint$2.prototype.__init3.call(this);PathConstraint$2.prototype.__init4.call(this);PathConstraint$2.prototype.__init5.call(this);PathConstraint$2.prototype.__init6.call(this);PathConstraint$2.prototype.__init7.call(this);PathConstraint$2.prototype.__init8.call(this);PathConstraint$2.prototype.__init9.call(this);PathConstraint$2.prototype.__init10.call(this);PathConstraint$2.prototype.__init11.call(this);PathConstraint$2.prototype.__init12.call(this);
  17897. if (data == null) throw new Error("data cannot be null.");
  17898. if (skeleton == null) throw new Error("skeleton cannot be null.");
  17899. this.data = data;
  17900. this.bones = new Array();
  17901. for (let i = 0, n = data.bones.length; i < n; i++)
  17902. this.bones.push(skeleton.findBone(data.bones[i].name));
  17903. this.target = skeleton.findSlot(data.target.name);
  17904. this.position = data.position;
  17905. this.spacing = data.spacing;
  17906. this.mixRotate = data.mixRotate;
  17907. this.mixX = data.mixX;
  17908. this.mixY = data.mixY;
  17909. }
  17910. isActive () {
  17911. return this.active;
  17912. }
  17913. update () {
  17914. let attachment = this.target.getAttachment();
  17915. if (!(attachment instanceof PathAttachment$2)) return;
  17916. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY;
  17917. if (mixRotate == 0 && mixX == 0 && mixY == 0) return;
  17918. let data = this.data;
  17919. let tangents = data.rotateMode == RotateMode$2.Tangent, scale = data.rotateMode == RotateMode$2.ChainScale;
  17920. let boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  17921. let bones = this.bones;
  17922. let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths = scale ? this.lengths = Utils.setArraySize(this.lengths, boneCount) : null;
  17923. let spacing = this.spacing;
  17924. switch (data.spacingMode) {
  17925. case SpacingMode$2.Percent:
  17926. if (scale) {
  17927. for (let i = 0, n = spacesCount - 1; i < n; i++) {
  17928. let bone = bones[i];
  17929. let setupLength = bone.data.length;
  17930. if (setupLength < PathConstraint$2.epsilon)
  17931. lengths[i] = 0;
  17932. else {
  17933. let x = setupLength * bone.matrix.a, y = setupLength * bone.matrix.b;
  17934. lengths[i] = Math.sqrt(x * x + y * y);
  17935. }
  17936. }
  17937. }
  17938. Utils.arrayFill(spaces, 1, spacesCount, spacing);
  17939. break;
  17940. case SpacingMode$2.Proportional:
  17941. let sum = 0;
  17942. for (let i = 0; i < boneCount;) {
  17943. let bone = bones[i];
  17944. let setupLength = bone.data.length;
  17945. if (setupLength < PathConstraint$2.epsilon) {
  17946. if (scale) lengths[i] = 0;
  17947. spaces[++i] = spacing;
  17948. } else {
  17949. let x = setupLength * bone.matrix.a, y = setupLength * bone.matrix.b;
  17950. let length = Math.sqrt(x * x + y * y);
  17951. if (scale) lengths[i] = length;
  17952. spaces[++i] = length;
  17953. sum += length;
  17954. }
  17955. }
  17956. if (sum > 0) {
  17957. sum = spacesCount / sum * spacing;
  17958. for (let i = 1; i < spacesCount; i++)
  17959. spaces[i] *= sum;
  17960. }
  17961. break;
  17962. default:
  17963. let lengthSpacing = data.spacingMode == SpacingMode$2.Length;
  17964. for (let i = 0, n = spacesCount - 1; i < n;) {
  17965. let bone = bones[i];
  17966. let setupLength = bone.data.length;
  17967. if (setupLength < PathConstraint$2.epsilon) {
  17968. if (scale) lengths[i] = 0;
  17969. spaces[++i] = spacing;
  17970. } else {
  17971. let x = setupLength * bone.matrix.a, y = setupLength * bone.matrix.b;
  17972. let length = Math.sqrt(x * x + y * y);
  17973. if (scale) lengths[i] = length;
  17974. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
  17975. }
  17976. }
  17977. }
  17978. let positions = this.computeWorldPositions(attachment, spacesCount, tangents);
  17979. let boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  17980. let tip = false;
  17981. if (offsetRotation == 0)
  17982. tip = data.rotateMode == RotateMode$2.Chain;
  17983. else {
  17984. tip = false;
  17985. let p = this.target.bone.matrix;
  17986. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.degRad : -MathUtils.degRad;
  17987. }
  17988. for (let i = 0, p = 3; i < boneCount; i++, p += 3) {
  17989. let bone = bones[i];
  17990. let mat = bone.matrix;
  17991. mat.tx += (boneX - mat.tx) * mixX;
  17992. mat.ty += (boneY - mat.ty) * mixY;
  17993. let x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  17994. if (scale) {
  17995. let length = lengths[i];
  17996. if (length != 0) {
  17997. let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1;
  17998. mat.a *= s;
  17999. mat.b *= s;
  18000. }
  18001. }
  18002. boneX = x;
  18003. boneY = y;
  18004. if (mixRotate) {
  18005. let a = mat.a, b = mat.c, c = mat.b, d = mat.d, r = 0, cos = 0, sin = 0;
  18006. if (tangents)
  18007. r = positions[p - 1];
  18008. else if (spaces[i + 1] == 0)
  18009. r = positions[p + 2];
  18010. else
  18011. r = Math.atan2(dy, dx);
  18012. r -= Math.atan2(c, a);
  18013. if (tip) {
  18014. cos = Math.cos(r);
  18015. sin = Math.sin(r);
  18016. let length = bone.data.length;
  18017. boneX += (length * (cos * a - sin * c) - dx) * mixRotate;
  18018. boneY += (length * (sin * a + cos * c) - dy) * mixRotate;
  18019. } else {
  18020. r += offsetRotation;
  18021. }
  18022. if (r > MathUtils.PI)
  18023. r -= MathUtils.PI2;
  18024. else if (r < -MathUtils.PI) //
  18025. r += MathUtils.PI2;
  18026. r *= mixRotate;
  18027. cos = Math.cos(r);
  18028. sin = Math.sin(r);
  18029. mat.a = cos * a - sin * c;
  18030. mat.c = cos * b - sin * d;
  18031. mat.b = sin * a + cos * c;
  18032. mat.d = sin * b + cos * d;
  18033. }
  18034. bone.appliedValid = false;
  18035. }
  18036. }
  18037. computeWorldPositions (path, spacesCount, tangents) {
  18038. let target = this.target;
  18039. let position = this.position;
  18040. let spaces = this.spaces, out = Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  18041. let closed = path.closed;
  18042. let verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint$2.NONE;
  18043. if (!path.constantSpeed) {
  18044. let lengths = path.lengths;
  18045. curveCount -= closed ? 1 : 2;
  18046. let pathLength = lengths[curveCount];
  18047. if (this.data.positionMode == PositionMode$2.Percent) position *= pathLength;
  18048. let multiplier;
  18049. switch (this.data.spacingMode) {
  18050. case SpacingMode$2.Percent:
  18051. multiplier = pathLength;
  18052. break;
  18053. case SpacingMode$2.Proportional:
  18054. multiplier = pathLength / spacesCount;
  18055. break;
  18056. default:
  18057. multiplier = 1;
  18058. }
  18059. world = Utils.setArraySize(this.world, 8);
  18060. for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  18061. let space = spaces[i] * multiplier;
  18062. position += space;
  18063. let p = position;
  18064. if (closed) {
  18065. p %= pathLength;
  18066. if (p < 0) p += pathLength;
  18067. curve = 0;
  18068. } else if (p < 0) {
  18069. if (prevCurve != PathConstraint$2.BEFORE) {
  18070. prevCurve = PathConstraint$2.BEFORE;
  18071. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  18072. }
  18073. this.addBeforePosition(p, world, 0, out, o);
  18074. continue;
  18075. } else if (p > pathLength) {
  18076. if (prevCurve != PathConstraint$2.AFTER) {
  18077. prevCurve = PathConstraint$2.AFTER;
  18078. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  18079. }
  18080. this.addAfterPosition(p - pathLength, world, 0, out, o);
  18081. continue;
  18082. }
  18083. // Determine curve containing position.
  18084. for (;; curve++) {
  18085. let length = lengths[curve];
  18086. if (p > length) continue;
  18087. if (curve == 0)
  18088. p /= length;
  18089. else {
  18090. let prev = lengths[curve - 1];
  18091. p = (p - prev) / (length - prev);
  18092. }
  18093. break;
  18094. }
  18095. if (curve != prevCurve) {
  18096. prevCurve = curve;
  18097. if (closed && curve == curveCount) {
  18098. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  18099. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  18100. } else
  18101. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  18102. }
  18103. this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o,
  18104. tangents || (i > 0 && space == 0));
  18105. }
  18106. return out;
  18107. }
  18108. // World vertices.
  18109. if (closed) {
  18110. verticesLength += 2;
  18111. world = Utils.setArraySize(this.world, verticesLength);
  18112. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  18113. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  18114. world[verticesLength - 2] = world[0];
  18115. world[verticesLength - 1] = world[1];
  18116. } else {
  18117. curveCount--;
  18118. verticesLength -= 4;
  18119. world = Utils.setArraySize(this.world, verticesLength);
  18120. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  18121. }
  18122. // Curve lengths.
  18123. let curves = Utils.setArraySize(this.curves, curveCount);
  18124. let pathLength = 0;
  18125. let x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  18126. let tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  18127. for (let i = 0, w = 2; i < curveCount; i++, w += 6) {
  18128. cx1 = world[w];
  18129. cy1 = world[w + 1];
  18130. cx2 = world[w + 2];
  18131. cy2 = world[w + 3];
  18132. x2 = world[w + 4];
  18133. y2 = world[w + 5];
  18134. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  18135. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  18136. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  18137. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  18138. ddfx = tmpx * 2 + dddfx;
  18139. ddfy = tmpy * 2 + dddfy;
  18140. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  18141. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  18142. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18143. dfx += ddfx;
  18144. dfy += ddfy;
  18145. ddfx += dddfx;
  18146. ddfy += dddfy;
  18147. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18148. dfx += ddfx;
  18149. dfy += ddfy;
  18150. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18151. dfx += ddfx + dddfx;
  18152. dfy += ddfy + dddfy;
  18153. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18154. curves[i] = pathLength;
  18155. x1 = x2;
  18156. y1 = y2;
  18157. }
  18158. if (this.data.positionMode == PositionMode$2.Percent) position *= pathLength;
  18159. let multiplier = 0;
  18160. switch (this.data.spacingMode) {
  18161. case SpacingMode$2.Percent:
  18162. multiplier = pathLength;
  18163. break;
  18164. case SpacingMode$2.Proportional:
  18165. multiplier = pathLength / spacesCount;
  18166. break;
  18167. default:
  18168. multiplier = 1;
  18169. }
  18170. let segments = this.segments;
  18171. let curveLength = 0;
  18172. for (let i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  18173. let space = spaces[i] * multiplier;
  18174. position += space;
  18175. let p = position;
  18176. if (closed) {
  18177. p %= pathLength;
  18178. if (p < 0) p += pathLength;
  18179. curve = 0;
  18180. } else if (p < 0) {
  18181. this.addBeforePosition(p, world, 0, out, o);
  18182. continue;
  18183. } else if (p > pathLength) {
  18184. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  18185. continue;
  18186. }
  18187. // Determine curve containing position.
  18188. for (;; curve++) {
  18189. let length = curves[curve];
  18190. if (p > length) continue;
  18191. if (curve == 0)
  18192. p /= length;
  18193. else {
  18194. let prev = curves[curve - 1];
  18195. p = (p - prev) / (length - prev);
  18196. }
  18197. break;
  18198. }
  18199. // Curve segment lengths.
  18200. if (curve != prevCurve) {
  18201. prevCurve = curve;
  18202. let ii = curve * 6;
  18203. x1 = world[ii];
  18204. y1 = world[ii + 1];
  18205. cx1 = world[ii + 2];
  18206. cy1 = world[ii + 3];
  18207. cx2 = world[ii + 4];
  18208. cy2 = world[ii + 5];
  18209. x2 = world[ii + 6];
  18210. y2 = world[ii + 7];
  18211. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  18212. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  18213. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  18214. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  18215. ddfx = tmpx * 2 + dddfx;
  18216. ddfy = tmpy * 2 + dddfy;
  18217. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  18218. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  18219. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  18220. segments[0] = curveLength;
  18221. for (ii = 1; ii < 8; ii++) {
  18222. dfx += ddfx;
  18223. dfy += ddfy;
  18224. ddfx += dddfx;
  18225. ddfy += dddfy;
  18226. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18227. segments[ii] = curveLength;
  18228. }
  18229. dfx += ddfx;
  18230. dfy += ddfy;
  18231. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18232. segments[8] = curveLength;
  18233. dfx += ddfx + dddfx;
  18234. dfy += ddfy + dddfy;
  18235. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  18236. segments[9] = curveLength;
  18237. segment = 0;
  18238. }
  18239. // Weight by segment length.
  18240. p *= curveLength;
  18241. for (;; segment++) {
  18242. let length = segments[segment];
  18243. if (p > length) continue;
  18244. if (segment == 0)
  18245. p /= length;
  18246. else {
  18247. let prev = segments[segment - 1];
  18248. p = segment + (p - prev) / (length - prev);
  18249. }
  18250. break;
  18251. }
  18252. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  18253. }
  18254. return out;
  18255. }
  18256. addBeforePosition (p, temp, i, out, o) {
  18257. let x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  18258. out[o] = x1 + p * Math.cos(r);
  18259. out[o + 1] = y1 + p * Math.sin(r);
  18260. out[o + 2] = r;
  18261. }
  18262. addAfterPosition (p, temp, i, out, o) {
  18263. let x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  18264. out[o] = x1 + p * Math.cos(r);
  18265. out[o + 1] = y1 + p * Math.sin(r);
  18266. out[o + 2] = r;
  18267. }
  18268. addCurvePosition (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2,
  18269. out, o, tangents) {
  18270. if (p == 0 || isNaN(p)) {
  18271. out[o] = x1;
  18272. out[o + 1] = y1;
  18273. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  18274. return;
  18275. }
  18276. let tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  18277. let ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  18278. let x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  18279. out[o] = x;
  18280. out[o + 1] = y;
  18281. if (tangents) {
  18282. if (p < 0.001)
  18283. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  18284. else
  18285. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  18286. }
  18287. }
  18288. } PathConstraint$2.__initStatic(); PathConstraint$2.__initStatic2(); PathConstraint$2.__initStatic3(); PathConstraint$2.__initStatic4();
  18289. /** Stores a slot's current pose. Slots organize attachments for {@link Skeleton#drawOrder} purposes and provide a place to store
  18290. * state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared
  18291. * across multiple skeletons.
  18292. * @public
  18293. * */
  18294. class Slot$2 {
  18295. //this is canon
  18296. /** The slot's setup pose data. */
  18297. /** The bone this slot belongs to. */
  18298. /** The color used to tint the slot's attachment. If {@link #getDarkColor()} is set, this is used as the light color for two
  18299. * color tinting. */
  18300. /** 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
  18301. * color's alpha is not used. */
  18302. /** Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a
  18303. * weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions.
  18304. *
  18305. * See {@link VertexAttachment#computeWorldVertices()} and {@link DeformTimeline}. */
  18306. __init() {this.deform = new Array();}
  18307. constructor (data, bone) {Slot$2.prototype.__init.call(this);
  18308. if (data == null) throw new Error("data cannot be null.");
  18309. if (bone == null) throw new Error("bone cannot be null.");
  18310. this.data = data;
  18311. this.bone = bone;
  18312. this.color = new Color();
  18313. this.darkColor = data.darkColor == null ? null : new Color();
  18314. this.setToSetupPose();
  18315. this.blendMode = this.data.blendMode;
  18316. }
  18317. /** The skeleton this slot belongs to. */
  18318. getSkeleton () {
  18319. return this.bone.skeleton;
  18320. }
  18321. /** The current attachment for the slot, or null if the slot has no attachment. */
  18322. getAttachment () {
  18323. return this.attachment;
  18324. }
  18325. /** Sets the slot's attachment and, if the attachment changed, resets {@link #attachmentTime} and clears {@link #deform}.
  18326. * @param attachment May be null. */
  18327. setAttachment (attachment) {
  18328. if (this.attachment == attachment) return;
  18329. this.attachment = attachment;
  18330. this.attachmentTime = this.bone.skeleton.time;
  18331. this.deform.length = 0;
  18332. }
  18333. setAttachmentTime (time) {
  18334. this.attachmentTime = this.bone.skeleton.time - time;
  18335. }
  18336. /** The time that has elapsed since the last time the attachment was set or cleared. Relies on Skeleton
  18337. * {@link Skeleton#time}. */
  18338. getAttachmentTime () {
  18339. return this.bone.skeleton.time - this.attachmentTime;
  18340. }
  18341. /** Sets this slot to the setup pose. */
  18342. setToSetupPose () {
  18343. this.color.setFromColor(this.data.color);
  18344. if (this.darkColor != null) this.darkColor.setFromColor(this.data.darkColor);
  18345. if (this.data.attachmentName == null)
  18346. this.attachment = null;
  18347. else {
  18348. this.attachment = null;
  18349. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  18350. }
  18351. }
  18352. }
  18353. /** Stores the current pose for a transform constraint. A transform constraint adjusts the world transform of the constrained
  18354. * bones to match that of the target bone.
  18355. *
  18356. * See [Transform constraints](http://esotericsoftware.com/spine-transform-constraints) in the Spine User Guide.
  18357. * @public
  18358. * */
  18359. class TransformConstraint$2 {
  18360. /** The transform constraint's setup pose data. */
  18361. /** The bones that will be modified by this transform constraint. */
  18362. /** The target bone whose world transform will be copied to the constrained bones. */
  18363. __init() {this.mixRotate = 0;} __init2() {this.mixX = 0;} __init3() {this.mixY = 0;} __init4() {this.mixScaleX = 0;} __init5() {this.mixScaleY = 0;} __init6() {this.mixShearY = 0;}
  18364. __init7() {this.temp = new Vector2();}
  18365. __init8() {this.active = false;}
  18366. constructor (data, skeleton) {TransformConstraint$2.prototype.__init.call(this);TransformConstraint$2.prototype.__init2.call(this);TransformConstraint$2.prototype.__init3.call(this);TransformConstraint$2.prototype.__init4.call(this);TransformConstraint$2.prototype.__init5.call(this);TransformConstraint$2.prototype.__init6.call(this);TransformConstraint$2.prototype.__init7.call(this);TransformConstraint$2.prototype.__init8.call(this);
  18367. if (data == null) throw new Error("data cannot be null.");
  18368. if (skeleton == null) throw new Error("skeleton cannot be null.");
  18369. this.data = data;
  18370. this.mixRotate = data.mixRotate;
  18371. this.mixX = data.mixX;
  18372. this.mixY = data.mixY;
  18373. this.mixScaleX = data.mixScaleX;
  18374. this.mixScaleY = data.mixScaleY;
  18375. this.mixShearY = data.mixShearY;
  18376. this.bones = new Array();
  18377. for (let i = 0; i < data.bones.length; i++)
  18378. this.bones.push(skeleton.findBone(data.bones[i].name));
  18379. this.target = skeleton.findBone(data.target.name);
  18380. }
  18381. isActive () {
  18382. return this.active;
  18383. }
  18384. update () {
  18385. if (this.mixRotate == 0 && this.mixX == 0 && this.mixY == 0 && this.mixScaleX == 0 && this.mixScaleX == 0 && this.mixShearY == 0) return;
  18386. if (this.data.local) {
  18387. if (this.data.relative)
  18388. this.applyRelativeLocal();
  18389. else
  18390. this.applyAbsoluteLocal();
  18391. } else {
  18392. if (this.data.relative)
  18393. this.applyRelativeWorld();
  18394. else
  18395. this.applyAbsoluteWorld();
  18396. }
  18397. }
  18398. applyAbsoluteWorld () {
  18399. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
  18400. mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  18401. let translate = mixX != 0 || mixY != 0;
  18402. let target = this.target;
  18403. const targetMat = target.matrix;
  18404. let ta = targetMat.a, tb = targetMat.c, tc = targetMat.b, td = targetMat.d;
  18405. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  18406. let offsetRotation = this.data.offsetRotation * degRadReflect;
  18407. let offsetShearY = this.data.offsetShearY * degRadReflect;
  18408. let bones = this.bones;
  18409. for (let i = 0, n = bones.length; i < n; i++) {
  18410. let bone = bones[i];
  18411. const mat = bone.matrix;
  18412. if (mixRotate != 0) {
  18413. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  18414. let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  18415. if (r > MathUtils.PI)
  18416. r -= MathUtils.PI2;
  18417. else if (r < -MathUtils.PI) //
  18418. r += MathUtils.PI2;
  18419. r *= mixRotate;
  18420. let cos = Math.cos(r), sin = Math.sin(r);
  18421. mat.a = cos * a - sin * c;
  18422. mat.c = cos * b - sin * d;
  18423. mat.b = sin * a + cos * c;
  18424. mat.d = sin * b + cos * d;
  18425. }
  18426. if (translate) {
  18427. let temp = this.temp;
  18428. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  18429. mat.tx += (temp.x - mat.tx) * mixX;
  18430. mat.ty += (temp.y - mat.tx) * mixY;
  18431. }
  18432. if (mixScaleX != 0) {
  18433. let s = Math.sqrt(mat.a * mat.a + mat.b * mat.b);
  18434. if (s != 0) s = (s + (Math.sqrt(ta * ta + tc * tc) - s + this.data.offsetScaleX) * mixScaleX) / s;
  18435. mat.a *= s;
  18436. mat.b *= s;
  18437. }
  18438. if (mixScaleY != 0) {
  18439. let s = Math.sqrt(mat.c * mat.c + mat.d * mat.d);
  18440. if (s != 0) s = (s + (Math.sqrt(tb * tb + td * td) - s + this.data.offsetScaleY) * mixScaleY) / s;
  18441. mat.c *= s;
  18442. mat.d *= s;
  18443. }
  18444. if (mixShearY > 0) {
  18445. let b = mat.c, d = mat.d;
  18446. let by = Math.atan2(d, b);
  18447. let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(mat.b, mat.a));
  18448. if (r > MathUtils.PI)
  18449. r -= MathUtils.PI2;
  18450. else if (r < -MathUtils.PI) //
  18451. r += MathUtils.PI2;
  18452. r = by + (r + offsetShearY) * mixShearY;
  18453. let s = Math.sqrt(b * b + d * d);
  18454. mat.c = Math.cos(r) * s;
  18455. mat.d = Math.sin(r) * s;
  18456. }
  18457. bone.appliedValid = false;
  18458. }
  18459. }
  18460. applyRelativeWorld () {
  18461. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
  18462. mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  18463. let translate = mixX != 0 || mixY != 0;
  18464. let target = this.target;
  18465. let targetMat = target.matrix;
  18466. let ta = targetMat.a, tb = targetMat.c, tc = targetMat.b, td = targetMat.d;
  18467. let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
  18468. let offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  18469. let bones = this.bones;
  18470. for (let i = 0, n = bones.length; i < n; i++) {
  18471. let bone = bones[i];
  18472. const mat = bone.matrix;
  18473. if (mixRotate != 0) {
  18474. let a = mat.a, b = mat.c, c = mat.b, d = mat.d;
  18475. let r = Math.atan2(tc, ta) + offsetRotation;
  18476. if (r > MathUtils.PI)
  18477. r -= MathUtils.PI2;
  18478. else if (r < -MathUtils.PI) //
  18479. r += MathUtils.PI2;
  18480. r *= mixRotate;
  18481. let cos = Math.cos(r), sin = Math.sin(r);
  18482. mat.a = cos * a - sin * c;
  18483. mat.c = cos * b - sin * d;
  18484. mat.b = sin * a + cos * c;
  18485. mat.d = sin * b + cos * d;
  18486. }
  18487. if (translate) {
  18488. let temp = this.temp;
  18489. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  18490. mat.tx += temp.x * mixX;
  18491. mat.ty += temp.y * mixY;
  18492. }
  18493. if (mixScaleX != 0) {
  18494. let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * mixScaleX + 1;
  18495. mat.a *= s;
  18496. mat.b *= s;
  18497. }
  18498. if (mixScaleY != 0) {
  18499. let s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * mixScaleY + 1;
  18500. mat.c *= s;
  18501. mat.d *= s;
  18502. }
  18503. if (mixShearY > 0) {
  18504. let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  18505. if (r > MathUtils.PI)
  18506. r -= MathUtils.PI2;
  18507. else if (r < -MathUtils.PI) //
  18508. r += MathUtils.PI2;
  18509. let b = mat.c, d = mat.d;
  18510. r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * mixShearY;
  18511. let s = Math.sqrt(b * b + d * d);
  18512. mat.c = Math.cos(r) * s;
  18513. mat.d = Math.sin(r) * s;
  18514. }
  18515. bone.appliedValid = false;
  18516. }
  18517. }
  18518. applyAbsoluteLocal () {
  18519. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
  18520. mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  18521. let target = this.target;
  18522. if (!target.appliedValid) target.updateAppliedTransform();
  18523. let bones = this.bones;
  18524. for (let i = 0, n = bones.length; i < n; i++) {
  18525. let bone = bones[i];
  18526. if (!bone.appliedValid) bone.updateAppliedTransform();
  18527. let rotation = bone.arotation;
  18528. if (mixRotate != 0) {
  18529. let r = target.arotation - rotation + this.data.offsetRotation;
  18530. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  18531. rotation += r * mixRotate;
  18532. }
  18533. let x = bone.ax, y = bone.ay;
  18534. x += (target.ax - x + this.data.offsetX) * mixX;
  18535. y += (target.ay - y + this.data.offsetY) * mixY;
  18536. let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  18537. if (mixScaleX != 0 && scaleX != 0)
  18538. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * mixScaleX) / scaleX;
  18539. if (mixScaleY != 0 && scaleY != 0)
  18540. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * mixScaleY) / scaleY;
  18541. let shearY = bone.ashearY;
  18542. if (mixShearY != 0) {
  18543. let r = target.ashearY - shearY + this.data.offsetShearY;
  18544. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  18545. // TODO: check this place in 3.8
  18546. shearY += r * mixShearY;
  18547. }
  18548. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  18549. }
  18550. }
  18551. applyRelativeLocal () {
  18552. let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
  18553. mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  18554. let target = this.target;
  18555. if (!target.appliedValid) target.updateAppliedTransform();
  18556. let bones = this.bones;
  18557. for (let i = 0, n = bones.length; i < n; i++) {
  18558. let bone = bones[i];
  18559. if (!bone.appliedValid) bone.updateAppliedTransform();
  18560. let rotation = bone.arotation + (target.arotation + this.data.offsetRotation) * mixRotate;
  18561. let x = bone.ax + (target.ax + this.data.offsetX) * mixX;
  18562. let y = bone.ay + (target.ay + this.data.offsetY) * mixY;
  18563. let scaleX = (bone.ascaleX * ((target.ascaleX - 1 + this.data.offsetScaleX) * mixScaleX) + 1);
  18564. let scaleY = (bone.ascaleY * ((target.ascaleY - 1 + this.data.offsetScaleY) * mixScaleY) + 1);
  18565. let shearY = bone.ashearY + (target.ashearY + this.data.offsetShearY) * mixShearY;
  18566. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  18567. }
  18568. }
  18569. }
  18570. /** Stores the current pose for a skeleton.
  18571. *
  18572. * See [Instance objects](http://esotericsoftware.com/spine-runtime-architecture#Instance-objects) in the Spine Runtimes Guide.
  18573. * @public
  18574. * */
  18575. class Skeleton$2 {
  18576. /** The skeleton's setup pose data. */
  18577. /** The skeleton's bones, sorted parent first. The root bone is always the first bone. */
  18578. /** The skeleton's slots. */
  18579. /** The skeleton's slots in the order they should be drawn. The returned array may be modified to change the draw order. */
  18580. /** The skeleton's IK constraints. */
  18581. /** The skeleton's transform constraints. */
  18582. /** The skeleton's path constraints. */
  18583. /** The list of bones and constraints, sorted in the order they should be updated, as computed by {@link #updateCache()}. */
  18584. __init() {this._updateCache = new Array();}
  18585. /** The skeleton's current skin. May be null. */
  18586. /** The color to tint all the skeleton's attachments. */
  18587. /** Returns the skeleton's time. This can be used for tracking, such as with Slot {@link Slot#attachmentTime}.
  18588. * <p>
  18589. * See {@link #update()}. */
  18590. __init2() {this.time = 0;}
  18591. /** Scales the entire skeleton on the X axis. This affects all bones, even if the bone's transform mode disallows scale
  18592. * inheritance. */
  18593. __init3() {this.scaleX = 1;}
  18594. /** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale
  18595. * inheritance. */
  18596. __init4() {this.scaleY = 1;}
  18597. /** Sets the skeleton X position, which is added to the root bone worldX position. */
  18598. __init5() {this.x = 0;}
  18599. /** Sets the skeleton Y position, which is added to the root bone worldY position. */
  18600. __init6() {this.y = 0;}
  18601. constructor (data) {Skeleton$2.prototype.__init.call(this);Skeleton$2.prototype.__init2.call(this);Skeleton$2.prototype.__init3.call(this);Skeleton$2.prototype.__init4.call(this);Skeleton$2.prototype.__init5.call(this);Skeleton$2.prototype.__init6.call(this);
  18602. if (data == null) throw new Error("data cannot be null.");
  18603. this.data = data;
  18604. this.bones = new Array();
  18605. for (let i = 0; i < data.bones.length; i++) {
  18606. let boneData = data.bones[i];
  18607. let bone;
  18608. if (boneData.parent == null)
  18609. bone = new Bone$2(boneData, this, null);
  18610. else {
  18611. let parent = this.bones[boneData.parent.index];
  18612. bone = new Bone$2(boneData, this, parent);
  18613. parent.children.push(bone);
  18614. }
  18615. this.bones.push(bone);
  18616. }
  18617. this.slots = new Array();
  18618. this.drawOrder = new Array();
  18619. for (let i = 0; i < data.slots.length; i++) {
  18620. let slotData = data.slots[i];
  18621. let bone = this.bones[slotData.boneData.index];
  18622. let slot = new Slot$2(slotData, bone);
  18623. this.slots.push(slot);
  18624. this.drawOrder.push(slot);
  18625. }
  18626. this.ikConstraints = new Array();
  18627. for (let i = 0; i < data.ikConstraints.length; i++) {
  18628. let ikConstraintData = data.ikConstraints[i];
  18629. this.ikConstraints.push(new IkConstraint$2(ikConstraintData, this));
  18630. }
  18631. this.transformConstraints = new Array();
  18632. for (let i = 0; i < data.transformConstraints.length; i++) {
  18633. let transformConstraintData = data.transformConstraints[i];
  18634. this.transformConstraints.push(new TransformConstraint$2(transformConstraintData, this));
  18635. }
  18636. this.pathConstraints = new Array();
  18637. for (let i = 0; i < data.pathConstraints.length; i++) {
  18638. let pathConstraintData = data.pathConstraints[i];
  18639. this.pathConstraints.push(new PathConstraint$2(pathConstraintData, this));
  18640. }
  18641. this.color = new Color(1, 1, 1, 1);
  18642. this.updateCache();
  18643. }
  18644. /** Caches information about bones and constraints. Must be called if the {@link #getSkin()} is modified or if bones,
  18645. * constraints, or weighted path attachments are added or removed. */
  18646. updateCache () {
  18647. let updateCache = this._updateCache;
  18648. updateCache.length = 0;
  18649. let bones = this.bones;
  18650. for (let i = 0, n = bones.length; i < n; i++) {
  18651. let bone = bones[i];
  18652. bone.sorted = bone.data.skinRequired;
  18653. bone.active = !bone.sorted;
  18654. }
  18655. if (this.skin != null) {
  18656. let skinBones = this.skin.bones;
  18657. for (let i = 0, n = this.skin.bones.length; i < n; i++) {
  18658. let bone = this.bones[skinBones[i].index];
  18659. do {
  18660. bone.sorted = false;
  18661. bone.active = true;
  18662. bone = bone.parent;
  18663. } while (bone != null);
  18664. }
  18665. }
  18666. // IK first, lowest hierarchy depth first.
  18667. let ikConstraints = this.ikConstraints;
  18668. let transformConstraints = this.transformConstraints;
  18669. let pathConstraints = this.pathConstraints;
  18670. let ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  18671. let constraintCount = ikCount + transformCount + pathCount;
  18672. outer:
  18673. for (let i = 0; i < constraintCount; i++) {
  18674. for (let ii = 0; ii < ikCount; ii++) {
  18675. let constraint = ikConstraints[ii];
  18676. if (constraint.data.order == i) {
  18677. this.sortIkConstraint(constraint);
  18678. continue outer;
  18679. }
  18680. }
  18681. for (let ii = 0; ii < transformCount; ii++) {
  18682. let constraint = transformConstraints[ii];
  18683. if (constraint.data.order == i) {
  18684. this.sortTransformConstraint(constraint);
  18685. continue outer;
  18686. }
  18687. }
  18688. for (let ii = 0; ii < pathCount; ii++) {
  18689. let constraint = pathConstraints[ii];
  18690. if (constraint.data.order == i) {
  18691. this.sortPathConstraint(constraint);
  18692. continue outer;
  18693. }
  18694. }
  18695. }
  18696. for (let i = 0, n = bones.length; i < n; i++)
  18697. this.sortBone(bones[i]);
  18698. }
  18699. sortIkConstraint (constraint) {
  18700. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)));
  18701. if (!constraint.active) return;
  18702. let target = constraint.target;
  18703. this.sortBone(target);
  18704. let constrained = constraint.bones;
  18705. let parent = constrained[0];
  18706. this.sortBone(parent);
  18707. if (constrained.length == 1) {
  18708. this._updateCache.push(constraint);
  18709. this.sortReset(parent.children);
  18710. } else {
  18711. let child = constrained[constrained.length - 1];
  18712. this.sortBone(child);
  18713. this._updateCache.push(constraint);
  18714. this.sortReset(parent.children);
  18715. child.sorted = true;
  18716. }
  18717. }
  18718. sortPathConstraint (constraint) {
  18719. constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || (this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)));
  18720. if (!constraint.active) return;
  18721. let slot = constraint.target;
  18722. let slotIndex = slot.data.index;
  18723. let slotBone = slot.bone;
  18724. if (this.skin != null) this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  18725. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  18726. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  18727. for (let i = 0, n = this.data.skins.length; i < n; i++)
  18728. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  18729. let attachment = slot.getAttachment();
  18730. if (attachment instanceof PathAttachment$2) this.sortPathConstraintAttachmentWith(attachment, slotBone);
  18731. let constrained = constraint.bones;
  18732. let boneCount = constrained.length;
  18733. for (let i = 0; i < boneCount; i++)
  18734. this.sortBone(constrained[i]);
  18735. this._updateCache.push(constraint);
  18736. for (let i = 0; i < boneCount; i++)
  18737. this.sortReset(constrained[i].children);
  18738. for (let i = 0; i < boneCount; i++)
  18739. constrained[i].sorted = true;
  18740. }
  18741. sortTransformConstraint (constraint) {
  18742. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin != null && Utils.contains(this.skin.constraints, constraint.data, true)));
  18743. if (!constraint.active) return;
  18744. this.sortBone(constraint.target);
  18745. let constrained = constraint.bones;
  18746. let boneCount = constrained.length;
  18747. if (constraint.data.local) {
  18748. for (let i = 0; i < boneCount; i++) {
  18749. let child = constrained[i];
  18750. this.sortBone(child.parent);
  18751. this.sortBone(child);
  18752. }
  18753. } else {
  18754. for (let i = 0; i < boneCount; i++) {
  18755. this.sortBone(constrained[i]);
  18756. }
  18757. }
  18758. this._updateCache.push(constraint);
  18759. for (let i = 0; i < boneCount; i++)
  18760. this.sortReset(constrained[i].children);
  18761. for (let i = 0; i < boneCount; i++)
  18762. constrained[i].sorted = true;
  18763. }
  18764. sortPathConstraintAttachment (skin, slotIndex, slotBone) {
  18765. let attachments = skin.attachments[slotIndex];
  18766. if (!attachments) return;
  18767. for (let key in attachments) {
  18768. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  18769. }
  18770. }
  18771. sortPathConstraintAttachmentWith (attachment, slotBone) {
  18772. if (!(attachment instanceof PathAttachment$2)) return;
  18773. let pathBones = (attachment).bones;
  18774. if (pathBones == null)
  18775. this.sortBone(slotBone);
  18776. else {
  18777. let bones = this.bones;
  18778. for (let i = 0, n = pathBones.length; i < n;) {
  18779. let nn = pathBones[i++];
  18780. nn += i;
  18781. while (i < nn)
  18782. this.sortBone(bones[pathBones[i++]]);
  18783. }
  18784. }
  18785. }
  18786. sortBone (bone) {
  18787. if (bone.sorted) return;
  18788. let parent = bone.parent;
  18789. if (parent != null) this.sortBone(parent);
  18790. bone.sorted = true;
  18791. this._updateCache.push(bone);
  18792. }
  18793. sortReset (bones) {
  18794. for (let i = 0, n = bones.length; i < n; i++) {
  18795. let bone = bones[i];
  18796. if (!bone.active) continue;
  18797. if (bone.sorted) this.sortReset(bone.children);
  18798. bone.sorted = false;
  18799. }
  18800. }
  18801. /** Updates the world transform for each bone and applies all constraints.
  18802. *
  18803. * See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
  18804. * Runtimes Guide. */
  18805. updateWorldTransform () {
  18806. let updateCache = this._updateCache;
  18807. for (let i = 0, n = updateCache.length; i < n; i++)
  18808. updateCache[i].update();
  18809. }
  18810. updateWorldTransformWith (parent) {
  18811. // Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection.
  18812. let rootBone = this.getRootBone();
  18813. let pa = parent.matrix.a, pb = parent.matrix.c, pc = parent.matrix.b, pd = parent.matrix.d;
  18814. rootBone.matrix.tx = pa * this.x + pb * this.y + parent.worldX;
  18815. rootBone.matrix.ty = pc * this.x + pd * this.y + parent.worldY;
  18816. let rotationY = rootBone.rotation + 90 + rootBone.shearY;
  18817. let la = MathUtils.cosDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
  18818. let lb = MathUtils.cosDeg(rotationY) * rootBone.scaleY;
  18819. let lc = MathUtils.sinDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
  18820. let ld = MathUtils.sinDeg(rotationY) * rootBone.scaleY;
  18821. const sx = this.scaleX;
  18822. const sy = settings.yDown? -this.scaleY : this.scaleY;
  18823. rootBone.matrix.a = (pa * la + pb * lc) * sx;
  18824. rootBone.matrix.b = (pa * lb + pb * ld) * sx;
  18825. rootBone.matrix.c = (pc * la + pd * lc) * sy;
  18826. rootBone.matrix.d = (pc * lb + pd * ld) * sy;
  18827. // Update everything except root bone.
  18828. let updateCache = this._updateCache;
  18829. for (let i = 0, n = updateCache.length; i < n; i++) {
  18830. let updatable = updateCache[i];
  18831. if (updatable != rootBone) updatable.update();
  18832. }
  18833. }
  18834. /** Sets the bones, constraints, and slots to their setup pose values. */
  18835. setToSetupPose () {
  18836. this.setBonesToSetupPose();
  18837. this.setSlotsToSetupPose();
  18838. }
  18839. /** Sets the bones and constraints to their setup pose values. */
  18840. setBonesToSetupPose () {
  18841. let bones = this.bones;
  18842. for (let i = 0, n = bones.length; i < n; i++)
  18843. bones[i].setToSetupPose();
  18844. let ikConstraints = this.ikConstraints;
  18845. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  18846. let constraint = ikConstraints[i];
  18847. constraint.mix = constraint.data.mix;
  18848. constraint.softness = constraint.data.softness;
  18849. constraint.bendDirection = constraint.data.bendDirection;
  18850. constraint.compress = constraint.data.compress;
  18851. constraint.stretch = constraint.data.stretch;
  18852. }
  18853. let transformConstraints = this.transformConstraints;
  18854. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  18855. let constraint = transformConstraints[i];
  18856. let data = constraint.data;
  18857. constraint.mixRotate = data.mixRotate;
  18858. constraint.mixX = data.mixX;
  18859. constraint.mixY = data.mixY;
  18860. constraint.mixScaleX = data.mixScaleX;
  18861. constraint.mixScaleY = data.mixScaleY;
  18862. constraint.mixShearY = data.mixShearY;
  18863. }
  18864. let pathConstraints = this.pathConstraints;
  18865. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  18866. let constraint = pathConstraints[i];
  18867. let data = constraint.data;
  18868. constraint.position = data.position;
  18869. constraint.spacing = data.spacing;
  18870. constraint.mixRotate = data.mixRotate;
  18871. constraint.mixX = data.mixX;
  18872. constraint.mixY = data.mixY;
  18873. }
  18874. }
  18875. /** Sets the slots and draw order to their setup pose values. */
  18876. setSlotsToSetupPose () {
  18877. let slots = this.slots;
  18878. Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  18879. for (let i = 0, n = slots.length; i < n; i++)
  18880. slots[i].setToSetupPose();
  18881. }
  18882. /** @returns May return null. */
  18883. getRootBone () {
  18884. if (this.bones.length == 0) return null;
  18885. return this.bones[0];
  18886. }
  18887. /** @returns May be null. */
  18888. findBone (boneName) {
  18889. if (boneName == null) throw new Error("boneName cannot be null.");
  18890. let bones = this.bones;
  18891. for (let i = 0, n = bones.length; i < n; i++) {
  18892. let bone = bones[i];
  18893. if (bone.data.name == boneName) return bone;
  18894. }
  18895. return null;
  18896. }
  18897. /** @returns -1 if the bone was not found. */
  18898. findBoneIndex (boneName) {
  18899. if (boneName == null) throw new Error("boneName cannot be null.");
  18900. let bones = this.bones;
  18901. for (let i = 0, n = bones.length; i < n; i++)
  18902. if (bones[i].data.name == boneName) return i;
  18903. return -1;
  18904. }
  18905. /** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
  18906. * repeatedly.
  18907. * @returns May be null. */
  18908. findSlot (slotName) {
  18909. if (slotName == null) throw new Error("slotName cannot be null.");
  18910. let slots = this.slots;
  18911. for (let i = 0, n = slots.length; i < n; i++) {
  18912. let slot = slots[i];
  18913. if (slot.data.name == slotName) return slot;
  18914. }
  18915. return null;
  18916. }
  18917. /** @returns -1 if the bone was not found. */
  18918. findSlotIndex (slotName) {
  18919. if (slotName == null) throw new Error("slotName cannot be null.");
  18920. let slots = this.slots;
  18921. for (let i = 0, n = slots.length; i < n; i++)
  18922. if (slots[i].data.name == slotName) return i;
  18923. return -1;
  18924. }
  18925. /** Sets a skin by name.
  18926. *
  18927. * See {@link #setSkin()}. */
  18928. setSkinByName (skinName) {
  18929. let skin = this.data.findSkin(skinName);
  18930. if (skin == null) throw new Error("Skin not found: " + skinName);
  18931. this.setSkin(skin);
  18932. }
  18933. /** Sets the skin used to look up attachments before looking in the {@link SkeletonData#defaultSkin default skin}. If the
  18934. * skin is changed, {@link #updateCache()} is called.
  18935. *
  18936. * Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. If there was no
  18937. * old skin, each slot's setup mode attachment is attached from the new skin.
  18938. *
  18939. * After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling
  18940. * {@link #setSlotsToSetupPose()}. Also, often {@link AnimationState#apply()} is called before the next time the
  18941. * skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin.
  18942. * @param newSkin May be null. */
  18943. setSkin (newSkin) {
  18944. if (newSkin == this.skin) return;
  18945. if (newSkin != null) {
  18946. if (this.skin != null)
  18947. newSkin.attachAll(this, this.skin);
  18948. else {
  18949. let slots = this.slots;
  18950. for (let i = 0, n = slots.length; i < n; i++) {
  18951. let slot = slots[i];
  18952. let name = slot.data.attachmentName;
  18953. if (name != null) {
  18954. let attachment = newSkin.getAttachment(i, name);
  18955. if (attachment != null) slot.setAttachment(attachment);
  18956. }
  18957. }
  18958. }
  18959. }
  18960. this.skin = newSkin;
  18961. this.updateCache();
  18962. }
  18963. /** Finds an attachment by looking in the {@link #skin} and {@link SkeletonData#defaultSkin} using the slot name and attachment
  18964. * name.
  18965. *
  18966. * See {@link #getAttachment()}.
  18967. * @returns May be null. */
  18968. getAttachmentByName (slotName, attachmentName) {
  18969. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  18970. }
  18971. /** Finds an attachment by looking in the {@link #skin} and {@link SkeletonData#defaultSkin} using the slot index and
  18972. * attachment name. First the skin is checked and if the attachment was not found, the default skin is checked.
  18973. *
  18974. * See [Runtime skins](http://esotericsoftware.com/spine-runtime-skins) in the Spine Runtimes Guide.
  18975. * @returns May be null. */
  18976. getAttachment (slotIndex, attachmentName) {
  18977. if (attachmentName == null) throw new Error("attachmentName cannot be null.");
  18978. if (this.skin != null) {
  18979. let attachment = this.skin.getAttachment(slotIndex, attachmentName);
  18980. if (attachment != null) return attachment;
  18981. }
  18982. if (this.data.defaultSkin != null) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  18983. return null;
  18984. }
  18985. /** A convenience method to set an attachment by finding the slot with {@link #findSlot()}, finding the attachment with
  18986. * {@link #getAttachment()}, then setting the slot's {@link Slot#attachment}.
  18987. * @param attachmentName May be null to clear the slot's attachment. */
  18988. setAttachment (slotName, attachmentName) {
  18989. if (slotName == null) throw new Error("slotName cannot be null.");
  18990. let slots = this.slots;
  18991. for (let i = 0, n = slots.length; i < n; i++) {
  18992. let slot = slots[i];
  18993. if (slot.data.name == slotName) {
  18994. let attachment = null;
  18995. if (attachmentName != null) {
  18996. attachment = this.getAttachment(i, attachmentName);
  18997. if (attachment == null)
  18998. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  18999. }
  19000. slot.setAttachment(attachment);
  19001. return;
  19002. }
  19003. }
  19004. throw new Error("Slot not found: " + slotName);
  19005. }
  19006. /** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method
  19007. * than to call it repeatedly.
  19008. * @return May be null. */
  19009. findIkConstraint (constraintName) {
  19010. if (constraintName == null) throw new Error("constraintName cannot be null.");
  19011. let ikConstraints = this.ikConstraints;
  19012. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  19013. let ikConstraint = ikConstraints[i];
  19014. if (ikConstraint.data.name == constraintName) return ikConstraint;
  19015. }
  19016. return null;
  19017. }
  19018. /** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of
  19019. * this method than to call it repeatedly.
  19020. * @return May be null. */
  19021. findTransformConstraint (constraintName) {
  19022. if (constraintName == null) throw new Error("constraintName cannot be null.");
  19023. let transformConstraints = this.transformConstraints;
  19024. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  19025. let constraint = transformConstraints[i];
  19026. if (constraint.data.name == constraintName) return constraint;
  19027. }
  19028. return null;
  19029. }
  19030. /** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method
  19031. * than to call it repeatedly.
  19032. * @return May be null. */
  19033. findPathConstraint (constraintName) {
  19034. if (constraintName == null) throw new Error("constraintName cannot be null.");
  19035. let pathConstraints = this.pathConstraints;
  19036. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  19037. let constraint = pathConstraints[i];
  19038. if (constraint.data.name == constraintName) return constraint;
  19039. }
  19040. return null;
  19041. }
  19042. /** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
  19043. * @param offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
  19044. * @param size An output value, the width and height of the AABB.
  19045. * @param temp Working memory to temporarily store attachments' computed world vertices. */
  19046. getBounds (offset, size, temp = new Array(2)) {
  19047. if (offset == null) throw new Error("offset cannot be null.");
  19048. if (size == null) throw new Error("size cannot be null.");
  19049. let drawOrder = this.drawOrder;
  19050. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  19051. for (let i = 0, n = drawOrder.length; i < n; i++) {
  19052. let slot = drawOrder[i];
  19053. if (!slot.bone.active) continue;
  19054. let verticesLength = 0;
  19055. let vertices = null;
  19056. let attachment = slot.getAttachment();
  19057. if (attachment instanceof RegionAttachment$2) {
  19058. verticesLength = 8;
  19059. vertices = Utils.setArraySize(temp, verticesLength, 0);
  19060. (attachment).computeWorldVertices(slot.bone, vertices, 0, 2);
  19061. } else if (attachment instanceof MeshAttachment$2) {
  19062. let mesh = (attachment);
  19063. verticesLength = mesh.worldVerticesLength;
  19064. vertices = Utils.setArraySize(temp, verticesLength, 0);
  19065. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  19066. }
  19067. if (vertices != null) {
  19068. for (let ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  19069. let x = vertices[ii], y = vertices[ii + 1];
  19070. minX = Math.min(minX, x);
  19071. minY = Math.min(minY, y);
  19072. maxX = Math.max(maxX, x);
  19073. maxY = Math.max(maxY, y);
  19074. }
  19075. }
  19076. }
  19077. offset.set(minX, minY);
  19078. size.set(maxX - minX, maxY - minY);
  19079. }
  19080. /** Increments the skeleton's {@link #time}. */
  19081. update (delta) {
  19082. this.time += delta;
  19083. }
  19084. get flipX() {
  19085. return this.scaleX == -1;
  19086. }
  19087. set flipX(value) {
  19088. if (!Skeleton$2.deprecatedWarning1) {
  19089. Skeleton$2.deprecatedWarning1 = true;
  19090. console.warn("Spine Deprecation Warning: `Skeleton.flipX/flipY` was deprecated, please use scaleX/scaleY");
  19091. }
  19092. this.scaleX = value ? 1.0 : -1.0;
  19093. }
  19094. get flipY() {
  19095. return this.scaleY == -1;
  19096. }
  19097. set flipY(value) {
  19098. if (!Skeleton$2.deprecatedWarning1) {
  19099. Skeleton$2.deprecatedWarning1 = true;
  19100. console.warn("Spine Deprecation Warning: `Skeleton.flipX/flipY` was deprecated, please use scaleX/scaleY");
  19101. }
  19102. this.scaleY = value ? 1.0 : -1.0;
  19103. }
  19104. static __initStatic() {this.deprecatedWarning1 = false;}
  19105. } Skeleton$2.__initStatic();
  19106. /** Stores the setup pose and all of the stateless data for a skeleton.
  19107. *
  19108. * See [Data objects](http://esotericsoftware.com/spine-runtime-architecture#Data-objects) in the Spine Runtimes
  19109. * Guide.
  19110. * @public
  19111. * */
  19112. class SkeletonData$2 {constructor() { SkeletonData$2.prototype.__init.call(this);SkeletonData$2.prototype.__init2.call(this);SkeletonData$2.prototype.__init3.call(this);SkeletonData$2.prototype.__init4.call(this);SkeletonData$2.prototype.__init5.call(this);SkeletonData$2.prototype.__init6.call(this);SkeletonData$2.prototype.__init7.call(this);SkeletonData$2.prototype.__init8.call(this);SkeletonData$2.prototype.__init9.call(this); }
  19113. /** The skeleton's name, which by default is the name of the skeleton data file, if possible. May be null. */
  19114. /** The skeleton's bones, sorted parent first. The root bone is always the first bone. */
  19115. __init() {this.bones = new Array();} // Ordered parents first.
  19116. /** The skeleton's slots. */
  19117. __init2() {this.slots = new Array();} // Setup pose draw order.
  19118. __init3() {this.skins = new Array();}
  19119. /** The skeleton's default skin. By default this skin contains all attachments that were not in a skin in Spine.
  19120. *
  19121. * See {@link Skeleton#getAttachmentByName()}.
  19122. * May be null. */
  19123. /** The skeleton's events. */
  19124. __init4() {this.events = new Array();}
  19125. /** The skeleton's animations. */
  19126. __init5() {this.animations = new Array();}
  19127. /** The skeleton's IK constraints. */
  19128. __init6() {this.ikConstraints = new Array();}
  19129. /** The skeleton's transform constraints. */
  19130. __init7() {this.transformConstraints = new Array();}
  19131. /** The skeleton's path constraints. */
  19132. __init8() {this.pathConstraints = new Array();}
  19133. /** The X coordinate of the skeleton's axis aligned bounding box in the setup pose. */
  19134. /** The Y coordinate of the skeleton's axis aligned bounding box in the setup pose. */
  19135. /** The width of the skeleton's axis aligned bounding box in the setup pose. */
  19136. /** The height of the skeleton's axis aligned bounding box in the setup pose. */
  19137. /** The Spine version used to export the skeleton data, or null. */
  19138. /** The skeleton data hash. This value will change if any of the skeleton data has changed. May be null. */
  19139. // Nonessential
  19140. /** The dopesheet FPS in Spine. Available only when nonessential data was exported. */
  19141. __init9() {this.fps = 0;}
  19142. /** The path to the images directory as defined in Spine. Available only when nonessential data was exported. May be null. */
  19143. /** The path to the audio directory as defined in Spine. Available only when nonessential data was exported. May be null. */
  19144. /** Finds a bone by comparing each bone's name. It is more efficient to cache the results of this method than to call it
  19145. * multiple times.
  19146. * @returns May be null. */
  19147. findBone (boneName) {
  19148. if (boneName == null) throw new Error("boneName cannot be null.");
  19149. let bones = this.bones;
  19150. for (let i = 0, n = bones.length; i < n; i++) {
  19151. let bone = bones[i];
  19152. if (bone.name == boneName) return bone;
  19153. }
  19154. return null;
  19155. }
  19156. findBoneIndex (boneName) {
  19157. if (boneName == null) throw new Error("boneName cannot be null.");
  19158. let bones = this.bones;
  19159. for (let i = 0, n = bones.length; i < n; i++)
  19160. if (bones[i].name == boneName) return i;
  19161. return -1;
  19162. }
  19163. /** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
  19164. * multiple times.
  19165. * @returns May be null. */
  19166. findSlot (slotName) {
  19167. if (slotName == null) throw new Error("slotName cannot be null.");
  19168. let slots = this.slots;
  19169. for (let i = 0, n = slots.length; i < n; i++) {
  19170. let slot = slots[i];
  19171. if (slot.name == slotName) return slot;
  19172. }
  19173. return null;
  19174. }
  19175. findSlotIndex (slotName) {
  19176. if (slotName == null) throw new Error("slotName cannot be null.");
  19177. let slots = this.slots;
  19178. for (let i = 0, n = slots.length; i < n; i++)
  19179. if (slots[i].name == slotName) return i;
  19180. return -1;
  19181. }
  19182. /** Finds a skin by comparing each skin's name. It is more efficient to cache the results of this method than to call it
  19183. * multiple times.
  19184. * @returns May be null. */
  19185. findSkin (skinName) {
  19186. if (skinName == null) throw new Error("skinName cannot be null.");
  19187. let skins = this.skins;
  19188. for (let i = 0, n = skins.length; i < n; i++) {
  19189. let skin = skins[i];
  19190. if (skin.name == skinName) return skin;
  19191. }
  19192. return null;
  19193. }
  19194. /** Finds an event by comparing each events's name. It is more efficient to cache the results of this method than to call it
  19195. * multiple times.
  19196. * @returns May be null. */
  19197. findEvent (eventDataName) {
  19198. if (eventDataName == null) throw new Error("eventDataName cannot be null.");
  19199. let events = this.events;
  19200. for (let i = 0, n = events.length; i < n; i++) {
  19201. let event = events[i];
  19202. if (event.name == eventDataName) return event;
  19203. }
  19204. return null;
  19205. }
  19206. /** Finds an animation by comparing each animation's name. It is more efficient to cache the results of this method than to
  19207. * call it multiple times.
  19208. * @returns May be null. */
  19209. findAnimation (animationName) {
  19210. if (animationName == null) throw new Error("animationName cannot be null.");
  19211. let animations = this.animations;
  19212. for (let i = 0, n = animations.length; i < n; i++) {
  19213. let animation = animations[i];
  19214. if (animation.name == animationName) return animation;
  19215. }
  19216. return null;
  19217. }
  19218. /** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method
  19219. * than to call it multiple times.
  19220. * @return May be null. */
  19221. findIkConstraint (constraintName) {
  19222. if (constraintName == null) throw new Error("constraintName cannot be null.");
  19223. let ikConstraints = this.ikConstraints;
  19224. for (let i = 0, n = ikConstraints.length; i < n; i++) {
  19225. let constraint = ikConstraints[i];
  19226. if (constraint.name == constraintName) return constraint;
  19227. }
  19228. return null;
  19229. }
  19230. /** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of
  19231. * this method than to call it multiple times.
  19232. * @return May be null. */
  19233. findTransformConstraint (constraintName) {
  19234. if (constraintName == null) throw new Error("constraintName cannot be null.");
  19235. let transformConstraints = this.transformConstraints;
  19236. for (let i = 0, n = transformConstraints.length; i < n; i++) {
  19237. let constraint = transformConstraints[i];
  19238. if (constraint.name == constraintName) return constraint;
  19239. }
  19240. return null;
  19241. }
  19242. /** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method
  19243. * than to call it multiple times.
  19244. * @return May be null. */
  19245. findPathConstraint (constraintName) {
  19246. if (constraintName == null) throw new Error("constraintName cannot be null.");
  19247. let pathConstraints = this.pathConstraints;
  19248. for (let i = 0, n = pathConstraints.length; i < n; i++) {
  19249. let constraint = pathConstraints[i];
  19250. if (constraint.name == constraintName) return constraint;
  19251. }
  19252. return null;
  19253. }
  19254. findPathConstraintIndex (pathConstraintName) {
  19255. if (pathConstraintName == null) throw new Error("pathConstraintName cannot be null.");
  19256. let pathConstraints = this.pathConstraints;
  19257. for (let i = 0, n = pathConstraints.length; i < n; i++)
  19258. if (pathConstraints[i].name == pathConstraintName) return i;
  19259. return -1;
  19260. }
  19261. }
  19262. /** Stores the setup pose for a {@link Slot}.
  19263. * @public
  19264. * */
  19265. class SlotData$2 {
  19266. /** The index of the slot in {@link Skeleton#getSlots()}. */
  19267. /** The name of the slot, which is unique across all slots in the skeleton. */
  19268. /** The bone this slot belongs to. */
  19269. /** The color used to tint the slot's attachment. If {@link #getDarkColor()} is set, this is used as the light color for two
  19270. * color tinting. */
  19271. __init() {this.color = new Color(1, 1, 1, 1);}
  19272. /** 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
  19273. * color's alpha is not used. */
  19274. /** The name of the attachment that is visible for this slot in the setup pose, or null if no attachment is visible. */
  19275. /** The blend mode for drawing the slot's attachment. */
  19276. constructor (index, name, boneData) {SlotData$2.prototype.__init.call(this);
  19277. if (index < 0) throw new Error("index must be >= 0.");
  19278. if (name == null) throw new Error("name cannot be null.");
  19279. if (boneData == null) throw new Error("boneData cannot be null.");
  19280. this.index = index;
  19281. this.name = name;
  19282. this.boneData = boneData;
  19283. }
  19284. }
  19285. /** Stores the setup pose for a {@link TransformConstraint}.
  19286. *
  19287. * See [Transform constraints](http://esotericsoftware.com/spine-transform-constraints) in the Spine User Guide.
  19288. * @public
  19289. * */
  19290. class TransformConstraintData$2 extends ConstraintData$1 {
  19291. /** The bones that will be modified by this transform constraint. */
  19292. __init() {this.bones = new Array();}
  19293. /** The target bone whose world transform will be copied to the constrained bones. */
  19294. __init2() {this.mixRotate = 0;}
  19295. __init3() {this.mixX = 0;}
  19296. __init4() {this.mixY = 0;}
  19297. __init5() {this.mixScaleX = 0;}
  19298. __init6() {this.mixScaleY = 0;}
  19299. __init7() {this.mixShearY = 0;}
  19300. /** An offset added to the constrained bone rotation. */
  19301. __init8() {this.offsetRotation = 0;}
  19302. /** An offset added to the constrained bone X translation. */
  19303. __init9() {this.offsetX = 0;}
  19304. /** An offset added to the constrained bone Y translation. */
  19305. __init10() {this.offsetY = 0;}
  19306. /** An offset added to the constrained bone scaleX. */
  19307. __init11() {this.offsetScaleX = 0;}
  19308. /** An offset added to the constrained bone scaleY. */
  19309. __init12() {this.offsetScaleY = 0;}
  19310. /** An offset added to the constrained bone shearY. */
  19311. __init13() {this.offsetShearY = 0;}
  19312. __init14() {this.relative = false;}
  19313. __init15() {this.local = false;}
  19314. constructor (name) {
  19315. super(name, 0, false);TransformConstraintData$2.prototype.__init.call(this);TransformConstraintData$2.prototype.__init2.call(this);TransformConstraintData$2.prototype.__init3.call(this);TransformConstraintData$2.prototype.__init4.call(this);TransformConstraintData$2.prototype.__init5.call(this);TransformConstraintData$2.prototype.__init6.call(this);TransformConstraintData$2.prototype.__init7.call(this);TransformConstraintData$2.prototype.__init8.call(this);TransformConstraintData$2.prototype.__init9.call(this);TransformConstraintData$2.prototype.__init10.call(this);TransformConstraintData$2.prototype.__init11.call(this);TransformConstraintData$2.prototype.__init12.call(this);TransformConstraintData$2.prototype.__init13.call(this);TransformConstraintData$2.prototype.__init14.call(this);TransformConstraintData$2.prototype.__init15.call(this); }
  19316. }
  19317. /** Stores an entry in the skin consisting of the slot index, name, and attachment
  19318. * @public
  19319. * **/
  19320. class SkinEntry$1 {
  19321. constructor( slotIndex, name, attachment) {this.slotIndex = slotIndex;this.name = name;this.attachment = attachment; }
  19322. }
  19323. /** Stores attachments by slot index and attachment name.
  19324. *
  19325. * See SkeletonData {@link SkeletonData#defaultSkin}, Skeleton {@link Skeleton#skin}, and
  19326. * [Runtime skins](http://esotericsoftware.com/spine-runtime-skins) in the Spine Runtimes Guide.
  19327. * @public
  19328. * */
  19329. class Skin$2 {
  19330. /** The skin's name, which is unique across all skins in the skeleton. */
  19331. __init() {this.attachments = new Array();}
  19332. __init2() {this.bones = Array();}
  19333. __init3() {this.constraints = new Array();}
  19334. constructor (name) {Skin$2.prototype.__init.call(this);Skin$2.prototype.__init2.call(this);Skin$2.prototype.__init3.call(this);
  19335. if (name == null) throw new Error("name cannot be null.");
  19336. this.name = name;
  19337. }
  19338. /** Adds an attachment to the skin for the specified slot index and name. */
  19339. setAttachment (slotIndex, name, attachment) {
  19340. if (attachment == null) throw new Error("attachment cannot be null.");
  19341. let attachments = this.attachments;
  19342. if (slotIndex >= attachments.length) attachments.length = slotIndex + 1;
  19343. if (!attachments[slotIndex]) attachments[slotIndex] = { };
  19344. attachments[slotIndex][name] = attachment;
  19345. }
  19346. /** Adds all attachments, bones, and constraints from the specified skin to this skin. */
  19347. addSkin (skin) {
  19348. for(let i = 0; i < skin.bones.length; i++) {
  19349. let bone = skin.bones[i];
  19350. let contained = false;
  19351. for (let j = 0; j < this.bones.length; j++) {
  19352. if (this.bones[j] == bone) {
  19353. contained = true;
  19354. break;
  19355. }
  19356. }
  19357. if (!contained) this.bones.push(bone);
  19358. }
  19359. for(let i = 0; i < skin.constraints.length; i++) {
  19360. let constraint = skin.constraints[i];
  19361. let contained = false;
  19362. for (let j = 0; j < this.constraints.length; j++) {
  19363. if (this.constraints[j] == constraint) {
  19364. contained = true;
  19365. break;
  19366. }
  19367. }
  19368. if (!contained) this.constraints.push(constraint);
  19369. }
  19370. let attachments = skin.getAttachments();
  19371. for (let i = 0; i < attachments.length; i++) {
  19372. var attachment = attachments[i];
  19373. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  19374. }
  19375. }
  19376. /** Adds all bones and constraints and copies of all attachments from the specified skin to this skin. Mesh attachments are not
  19377. * copied, instead a new linked mesh is created. The attachment copies can be modified without affecting the originals. */
  19378. copySkin (skin) {
  19379. for(let i = 0; i < skin.bones.length; i++) {
  19380. let bone = skin.bones[i];
  19381. let contained = false;
  19382. for (let j = 0; j < this.bones.length; j++) {
  19383. if (this.bones[j] == bone) {
  19384. contained = true;
  19385. break;
  19386. }
  19387. }
  19388. if (!contained) this.bones.push(bone);
  19389. }
  19390. for(let i = 0; i < skin.constraints.length; i++) {
  19391. let constraint = skin.constraints[i];
  19392. let contained = false;
  19393. for (let j = 0; j < this.constraints.length; j++) {
  19394. if (this.constraints[j] == constraint) {
  19395. contained = true;
  19396. break;
  19397. }
  19398. }
  19399. if (!contained) this.constraints.push(constraint);
  19400. }
  19401. let attachments = skin.getAttachments();
  19402. for (let i = 0; i < attachments.length; i++) {
  19403. var attachment = attachments[i];
  19404. if (attachment.attachment == null) continue;
  19405. if (attachment.attachment instanceof MeshAttachment$2) {
  19406. attachment.attachment = attachment.attachment.newLinkedMesh();
  19407. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  19408. } else {
  19409. attachment.attachment = attachment.attachment.copy();
  19410. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  19411. }
  19412. }
  19413. }
  19414. /** Returns the attachment for the specified slot index and name, or null. */
  19415. getAttachment (slotIndex, name) {
  19416. let dictionary = this.attachments[slotIndex];
  19417. return dictionary ? dictionary[name] : null;
  19418. }
  19419. /** Removes the attachment in the skin for the specified slot index and name, if any. */
  19420. removeAttachment (slotIndex, name) {
  19421. let dictionary = this.attachments[slotIndex];
  19422. if (dictionary) dictionary[name] = null;
  19423. }
  19424. /** Returns all attachments in this skin. */
  19425. getAttachments () {
  19426. let entries = new Array();
  19427. for (var i = 0; i < this.attachments.length; i++) {
  19428. let slotAttachments = this.attachments[i];
  19429. if (slotAttachments) {
  19430. for (let name in slotAttachments) {
  19431. let attachment = slotAttachments[name];
  19432. if (attachment) entries.push(new SkinEntry$1(i, name, attachment));
  19433. }
  19434. }
  19435. }
  19436. return entries;
  19437. }
  19438. /** Returns all attachments in this skin for the specified slot index. */
  19439. getAttachmentsForSlot (slotIndex, attachments) {
  19440. let slotAttachments = this.attachments[slotIndex];
  19441. if (slotAttachments) {
  19442. for (let name in slotAttachments) {
  19443. let attachment = slotAttachments[name];
  19444. if (attachment) attachments.push(new SkinEntry$1(slotIndex, name, attachment));
  19445. }
  19446. }
  19447. }
  19448. /** Clears all attachments, bones, and constraints. */
  19449. clear () {
  19450. this.attachments.length = 0;
  19451. this.bones.length = 0;
  19452. this.constraints.length = 0;
  19453. }
  19454. /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */
  19455. attachAll (skeleton, oldSkin) {
  19456. let slotIndex = 0;
  19457. for (let i = 0; i < skeleton.slots.length; i++) {
  19458. let slot = skeleton.slots[i];
  19459. let slotAttachment = slot.getAttachment();
  19460. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  19461. let dictionary = oldSkin.attachments[slotIndex];
  19462. for (let key in dictionary) {
  19463. let skinAttachment = dictionary[key];
  19464. if (slotAttachment == skinAttachment) {
  19465. let attachment = this.getAttachment(slotIndex, key);
  19466. if (attachment != null) slot.setAttachment(attachment);
  19467. break;
  19468. }
  19469. }
  19470. }
  19471. slotIndex++;
  19472. }
  19473. }
  19474. }
  19475. /** Loads skeleton data in the Spine binary format.
  19476. *
  19477. * See [Spine binary format](http://esotericsoftware.com/spine-binary-format) and
  19478. * [JSON and binary data](http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data) in the Spine
  19479. * Runtimes Guide.
  19480. * @public
  19481. * */
  19482. class SkeletonBinary$1 {
  19483. static __initStatic() {this.AttachmentTypeValues = [ 0 /*AttachmentType.Region*/, 1/*AttachmentType.BoundingBox*/, 2/*AttachmentType.Mesh*/, 3/*AttachmentType.LinkedMesh*/, 4/*AttachmentType.Path*/, 5/*AttachmentType.Point*/, 6/*AttachmentType.Clipping*/ ];}
  19484. static __initStatic2() {this.TransformModeValues = [TransformMode$2.Normal, TransformMode$2.OnlyTranslation, TransformMode$2.NoRotationOrReflection, TransformMode$2.NoScale, TransformMode$2.NoScaleOrReflection];}
  19485. static __initStatic3() {this.PositionModeValues = [ PositionMode$2.Fixed, PositionMode$2.Percent ];}
  19486. static __initStatic4() {this.SpacingModeValues = [ SpacingMode$2.Length, SpacingMode$2.Fixed, SpacingMode$2.Percent];}
  19487. static __initStatic5() {this.RotateModeValues = [ RotateMode$2.Tangent, RotateMode$2.Chain, RotateMode$2.ChainScale ];}
  19488. static __initStatic6() {this.BlendModeValues = [ constants.BLEND_MODES.NORMAL, constants.BLEND_MODES.ADD, constants.BLEND_MODES.MULTIPLY, constants.BLEND_MODES.SCREEN];}
  19489. static __initStatic7() {this.BONE_ROTATE = 0;}
  19490. static __initStatic8() {this.BONE_TRANSLATE = 1;}
  19491. static __initStatic9() {this.BONE_TRANSLATEX = 2;}
  19492. static __initStatic10() {this.BONE_TRANSLATEY = 3;}
  19493. static __initStatic11() {this.BONE_SCALE = 4;}
  19494. static __initStatic12() {this.BONE_SCALEX = 5;}
  19495. static __initStatic13() {this.BONE_SCALEY = 6;}
  19496. static __initStatic14() {this.BONE_SHEAR = 7;}
  19497. static __initStatic15() {this.BONE_SHEARX = 8;}
  19498. static __initStatic16() {this.BONE_SHEARY = 9;}
  19499. static __initStatic17() {this.SLOT_ATTACHMENT = 0;}
  19500. static __initStatic18() {this.SLOT_RGBA = 1;}
  19501. static __initStatic19() {this.SLOT_RGB = 2;}
  19502. static __initStatic20() {this.SLOT_RGBA2 = 3;}
  19503. static __initStatic21() {this.SLOT_RGB2 = 4;}
  19504. static __initStatic22() {this.SLOT_ALPHA = 5;}
  19505. static __initStatic23() {this.PATH_POSITION = 0;}
  19506. static __initStatic24() {this.PATH_SPACING = 1;}
  19507. static __initStatic25() {this.PATH_MIX = 2;}
  19508. static __initStatic26() {this.CURVE_LINEAR = 0;}
  19509. static __initStatic27() {this.CURVE_STEPPED = 1;}
  19510. static __initStatic28() {this.CURVE_BEZIER = 2;}
  19511. /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at
  19512. * runtime than were used in Spine.
  19513. *
  19514. * See [Scaling](http://esotericsoftware.com/spine-loading-skeleton-data#Scaling) in the Spine Runtimes Guide. */
  19515. __init() {this.scale = 1;}
  19516. __init2() {this.linkedMeshes = new Array();}
  19517. constructor (attachmentLoader) {SkeletonBinary$1.prototype.__init.call(this);SkeletonBinary$1.prototype.__init2.call(this);
  19518. this.attachmentLoader = attachmentLoader;
  19519. }
  19520. readSkeletonData (binary) {
  19521. let scale = this.scale;
  19522. let skeletonData = new SkeletonData$2();
  19523. skeletonData.name = ""; // BOZO
  19524. let input = new BinaryInput(binary);
  19525. let lowHash = input.readInt32();
  19526. let highHash = input.readInt32();
  19527. skeletonData.hash = highHash == 0 && lowHash == 0 ? null : highHash.toString(16) + lowHash.toString(16);
  19528. skeletonData.version = input.readString();
  19529. if (skeletonData.version.substr(0, 3) !== '4.0')
  19530. {
  19531. let error = `Spine 4.0 loader cant load version ${skeletonData.version}. Please configure your pixi-spine bundle`;
  19532. console.error(error);
  19533. }
  19534. skeletonData.x = input.readFloat();
  19535. skeletonData.y = input.readFloat();
  19536. skeletonData.width = input.readFloat();
  19537. skeletonData.height = input.readFloat();
  19538. let nonessential = input.readBoolean();
  19539. if (nonessential) {
  19540. skeletonData.fps = input.readFloat();
  19541. skeletonData.imagesPath = input.readString();
  19542. skeletonData.audioPath = input.readString();
  19543. }
  19544. let n = 0;
  19545. // Strings.
  19546. n = input.readInt(true);
  19547. for (let i = 0; i < n; i++)
  19548. input.strings.push(input.readString());
  19549. // Bones.
  19550. n = input.readInt(true);
  19551. for (let i = 0; i < n; i++) {
  19552. let name = input.readString();
  19553. let parent = i == 0 ? null : skeletonData.bones[input.readInt(true)];
  19554. let data = new BoneData$2(i, name, parent);
  19555. data.rotation = input.readFloat();
  19556. data.x = input.readFloat() * scale;
  19557. data.y = input.readFloat() * scale;
  19558. data.scaleX = input.readFloat();
  19559. data.scaleY = input.readFloat();
  19560. data.shearX = input.readFloat();
  19561. data.shearY = input.readFloat();
  19562. data.length = input.readFloat() * scale;
  19563. data.transformMode = SkeletonBinary$1.TransformModeValues[input.readInt(true)];
  19564. data.skinRequired = input.readBoolean();
  19565. if (nonessential) Color.rgba8888ToColor(data.color, input.readInt32());
  19566. skeletonData.bones.push(data);
  19567. }
  19568. // Slots.
  19569. n = input.readInt(true);
  19570. for (let i = 0; i < n; i++) {
  19571. let slotName = input.readString();
  19572. let boneData = skeletonData.bones[input.readInt(true)];
  19573. let data = new SlotData$2(i, slotName, boneData);
  19574. Color.rgba8888ToColor(data.color, input.readInt32());
  19575. let darkColor = input.readInt32();
  19576. if (darkColor != -1) Color.rgb888ToColor(data.darkColor = new Color(), darkColor);
  19577. data.attachmentName = input.readStringRef();
  19578. data.blendMode = SkeletonBinary$1.BlendModeValues[input.readInt(true)];
  19579. skeletonData.slots.push(data);
  19580. }
  19581. // IK constraints.
  19582. n = input.readInt(true);
  19583. for (let i = 0, nn; i < n; i++) {
  19584. let data = new IkConstraintData$2(input.readString());
  19585. data.order = input.readInt(true);
  19586. data.skinRequired = input.readBoolean();
  19587. nn = input.readInt(true);
  19588. for (let ii = 0; ii < nn; ii++)
  19589. data.bones.push(skeletonData.bones[input.readInt(true)]);
  19590. data.target = skeletonData.bones[input.readInt(true)];
  19591. data.mix = input.readFloat();
  19592. data.softness = input.readFloat() * scale;
  19593. data.bendDirection = input.readByte();
  19594. data.compress = input.readBoolean();
  19595. data.stretch = input.readBoolean();
  19596. data.uniform = input.readBoolean();
  19597. skeletonData.ikConstraints.push(data);
  19598. }
  19599. // Transform constraints.
  19600. n = input.readInt(true);
  19601. for (let i = 0, nn; i < n; i++) {
  19602. let data = new TransformConstraintData$2(input.readString());
  19603. data.order = input.readInt(true);
  19604. data.skinRequired = input.readBoolean();
  19605. nn = input.readInt(true);
  19606. for (let ii = 0; ii < nn; ii++)
  19607. data.bones.push(skeletonData.bones[input.readInt(true)]);
  19608. data.target = skeletonData.bones[input.readInt(true)];
  19609. data.local = input.readBoolean();
  19610. data.relative = input.readBoolean();
  19611. data.offsetRotation = input.readFloat();
  19612. data.offsetX = input.readFloat() * scale;
  19613. data.offsetY = input.readFloat() * scale;
  19614. data.offsetScaleX = input.readFloat();
  19615. data.offsetScaleY = input.readFloat();
  19616. data.offsetShearY = input.readFloat();
  19617. data.mixRotate = input.readFloat();
  19618. data.mixX = input.readFloat();
  19619. data.mixY = input.readFloat();
  19620. data.mixScaleX = input.readFloat();
  19621. data.mixScaleY = input.readFloat();
  19622. data.mixShearY = input.readFloat();
  19623. skeletonData.transformConstraints.push(data);
  19624. }
  19625. // Path constraints.
  19626. n = input.readInt(true);
  19627. for (let i = 0, nn; i < n; i++) {
  19628. let data = new PathConstraintData$2(input.readString());
  19629. data.order = input.readInt(true);
  19630. data.skinRequired = input.readBoolean();
  19631. nn = input.readInt(true);
  19632. for (let ii = 0; ii < nn; ii++)
  19633. data.bones.push(skeletonData.bones[input.readInt(true)]);
  19634. data.target = skeletonData.slots[input.readInt(true)];
  19635. data.positionMode = SkeletonBinary$1.PositionModeValues[input.readInt(true)];
  19636. data.spacingMode = SkeletonBinary$1.SpacingModeValues[input.readInt(true)];
  19637. data.rotateMode = SkeletonBinary$1.RotateModeValues[input.readInt(true)];
  19638. data.offsetRotation = input.readFloat();
  19639. data.position = input.readFloat();
  19640. if (data.positionMode == PositionMode$2.Fixed) data.position *= scale;
  19641. data.spacing = input.readFloat();
  19642. if (data.spacingMode == SpacingMode$2.Length || data.spacingMode == SpacingMode$2.Fixed) data.spacing *= scale;
  19643. data.mixRotate = input.readFloat();
  19644. data.mixX = input.readFloat();
  19645. data.mixY = input.readFloat();
  19646. skeletonData.pathConstraints.push(data);
  19647. }
  19648. // Default skin.
  19649. let defaultSkin = this.readSkin(input, skeletonData, true, nonessential);
  19650. if (defaultSkin != null) {
  19651. skeletonData.defaultSkin = defaultSkin;
  19652. skeletonData.skins.push(defaultSkin);
  19653. }
  19654. // Skins.
  19655. {
  19656. let i = skeletonData.skins.length;
  19657. Utils.setArraySize(skeletonData.skins, n = i + input.readInt(true));
  19658. for (; i < n; i++)
  19659. skeletonData.skins[i] = this.readSkin(input, skeletonData, false, nonessential);
  19660. }
  19661. // Linked meshes.
  19662. n = this.linkedMeshes.length;
  19663. for (let i = 0; i < n; i++) {
  19664. let linkedMesh = this.linkedMeshes[i];
  19665. let skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  19666. if (skin == null) throw new Error("Skin not found: " + linkedMesh.skin);
  19667. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  19668. if (parent == null) throw new Error("Parent mesh not found: " + linkedMesh.parent);
  19669. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent : linkedMesh.mesh;
  19670. linkedMesh.mesh.setParentMesh(parent );
  19671. // linkedMesh.mesh.updateUVs();
  19672. }
  19673. this.linkedMeshes.length = 0;
  19674. // Events.
  19675. n = input.readInt(true);
  19676. for (let i = 0; i < n; i++) {
  19677. let data = new EventData$2(input.readStringRef());
  19678. data.intValue = input.readInt(false);
  19679. data.floatValue = input.readFloat();
  19680. data.stringValue = input.readString();
  19681. data.audioPath = input.readString();
  19682. if (data.audioPath != null) {
  19683. data.volume = input.readFloat();
  19684. data.balance = input.readFloat();
  19685. }
  19686. skeletonData.events.push(data);
  19687. }
  19688. // Animations.
  19689. n = input.readInt(true);
  19690. for (let i = 0; i < n; i++)
  19691. skeletonData.animations.push(this.readAnimation(input, input.readString(), skeletonData));
  19692. return skeletonData;
  19693. }
  19694. readSkin (input, skeletonData, defaultSkin, nonessential) {
  19695. let skin = null;
  19696. let slotCount = 0;
  19697. if (defaultSkin) {
  19698. slotCount = input.readInt(true);
  19699. if (slotCount == 0) return null;
  19700. skin = new Skin$2("default");
  19701. } else {
  19702. skin = new Skin$2(input.readStringRef());
  19703. skin.bones.length = input.readInt(true);
  19704. for (let i = 0, n = skin.bones.length; i < n; i++)
  19705. skin.bones[i] = skeletonData.bones[input.readInt(true)];
  19706. for (let i = 0, n = input.readInt(true); i < n; i++)
  19707. skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]);
  19708. for (let i = 0, n = input.readInt(true); i < n; i++)
  19709. skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]);
  19710. for (let i = 0, n = input.readInt(true); i < n; i++)
  19711. skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]);
  19712. slotCount = input.readInt(true);
  19713. }
  19714. for (let i = 0; i < slotCount; i++) {
  19715. let slotIndex = input.readInt(true);
  19716. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  19717. let name = input.readStringRef();
  19718. let attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name, nonessential);
  19719. if (attachment != null) skin.setAttachment(slotIndex, name, attachment);
  19720. }
  19721. }
  19722. return skin;
  19723. }
  19724. readAttachment(input, skeletonData, skin, slotIndex, attachmentName, nonessential) {
  19725. let scale = this.scale;
  19726. let name = input.readStringRef();
  19727. if (name == null) name = attachmentName;
  19728. let typeIndex = input.readByte();
  19729. switch (SkeletonBinary$1.AttachmentTypeValues[typeIndex]) {
  19730. case exports.AttachmentType.Region: {
  19731. let path = input.readStringRef();
  19732. let rotation = input.readFloat();
  19733. let x = input.readFloat();
  19734. let y = input.readFloat();
  19735. let scaleX = input.readFloat();
  19736. let scaleY = input.readFloat();
  19737. let width = input.readFloat();
  19738. let height = input.readFloat();
  19739. let color = input.readInt32();
  19740. if (path == null) path = name;
  19741. let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  19742. if (region == null) return null;
  19743. region.path = path;
  19744. region.x = x * scale;
  19745. region.y = y * scale;
  19746. region.scaleX = scaleX;
  19747. region.scaleY = scaleY;
  19748. region.rotation = rotation;
  19749. region.width = width * scale;
  19750. region.height = height * scale;
  19751. Color.rgba8888ToColor(region.color, color);
  19752. // region.updateOffset();
  19753. return region;
  19754. }
  19755. case exports.AttachmentType.BoundingBox: {
  19756. let vertexCount = input.readInt(true);
  19757. let vertices = this.readVertices(input, vertexCount);
  19758. let color = nonessential ? input.readInt32() : 0;
  19759. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  19760. if (box == null) return null;
  19761. box.worldVerticesLength = vertexCount << 1;
  19762. box.vertices = vertices.vertices;
  19763. box.bones = vertices.bones;
  19764. if (nonessential) Color.rgba8888ToColor(box.color, color);
  19765. return box;
  19766. }
  19767. case exports.AttachmentType.Mesh: {
  19768. let path = input.readStringRef();
  19769. let color = input.readInt32();
  19770. let vertexCount = input.readInt(true);
  19771. let uvs = this.readFloatArray(input, vertexCount << 1, 1);
  19772. let triangles = this.readShortArray(input);
  19773. let vertices = this.readVertices(input, vertexCount);
  19774. let hullLength = input.readInt(true);
  19775. let edges = null;
  19776. let width = 0, height = 0;
  19777. if (nonessential) {
  19778. edges = this.readShortArray(input);
  19779. width = input.readFloat();
  19780. height = input.readFloat();
  19781. }
  19782. if (path == null) path = name;
  19783. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  19784. if (mesh == null) return null;
  19785. mesh.path = path;
  19786. Color.rgba8888ToColor(mesh.color, color);
  19787. mesh.bones = vertices.bones;
  19788. mesh.vertices = vertices.vertices;
  19789. mesh.worldVerticesLength = vertexCount << 1;
  19790. mesh.triangles = triangles;
  19791. mesh.regionUVs = new Float32Array(uvs);
  19792. // mesh.updateUVs();
  19793. mesh.hullLength = hullLength << 1;
  19794. if (nonessential) {
  19795. mesh.edges = edges;
  19796. mesh.width = width * scale;
  19797. mesh.height = height * scale;
  19798. }
  19799. return mesh;
  19800. }
  19801. case exports.AttachmentType.LinkedMesh: {
  19802. let path = input.readStringRef();
  19803. let color = input.readInt32();
  19804. let skinName = input.readStringRef();
  19805. let parent = input.readStringRef();
  19806. let inheritDeform = input.readBoolean();
  19807. let width = 0, height = 0;
  19808. if (nonessential) {
  19809. width = input.readFloat();
  19810. height = input.readFloat();
  19811. }
  19812. if (path == null) path = name;
  19813. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  19814. if (mesh == null) return null;
  19815. mesh.path = path;
  19816. Color.rgba8888ToColor(mesh.color, color);
  19817. if (nonessential) {
  19818. mesh.width = width * scale;
  19819. mesh.height = height * scale;
  19820. }
  19821. this.linkedMeshes.push(new LinkedMesh$3(mesh, skinName, slotIndex, parent, inheritDeform));
  19822. return mesh;
  19823. }
  19824. case exports.AttachmentType.Path: {
  19825. let closed = input.readBoolean();
  19826. let constantSpeed = input.readBoolean();
  19827. let vertexCount = input.readInt(true);
  19828. let vertices = this.readVertices(input, vertexCount);
  19829. let lengths = Utils.newArray(vertexCount / 3, 0);
  19830. for (let i = 0, n = lengths.length; i < n; i++)
  19831. lengths[i] = input.readFloat() * scale;
  19832. let color = nonessential ? input.readInt32() : 0;
  19833. let path = this.attachmentLoader.newPathAttachment(skin, name);
  19834. if (path == null) return null;
  19835. path.closed = closed;
  19836. path.constantSpeed = constantSpeed;
  19837. path.worldVerticesLength = vertexCount << 1;
  19838. path.vertices = vertices.vertices;
  19839. path.bones = vertices.bones;
  19840. path.lengths = lengths;
  19841. if (nonessential) Color.rgba8888ToColor(path.color, color);
  19842. return path;
  19843. }
  19844. case exports.AttachmentType.Point: {
  19845. let rotation = input.readFloat();
  19846. let x = input.readFloat();
  19847. let y = input.readFloat();
  19848. let color = nonessential ? input.readInt32() : 0;
  19849. let point = this.attachmentLoader.newPointAttachment(skin, name);
  19850. if (point == null) return null;
  19851. point.x = x * scale;
  19852. point.y = y * scale;
  19853. point.rotation = rotation;
  19854. if (nonessential) Color.rgba8888ToColor(point.color, color);
  19855. return point;
  19856. }
  19857. case exports.AttachmentType.Clipping: {
  19858. let endSlotIndex = input.readInt(true);
  19859. let vertexCount = input.readInt(true);
  19860. let vertices = this.readVertices(input, vertexCount);
  19861. let color = nonessential ? input.readInt32() : 0;
  19862. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  19863. if (clip == null) return null;
  19864. clip.endSlot = skeletonData.slots[endSlotIndex];
  19865. clip.worldVerticesLength = vertexCount << 1;
  19866. clip.vertices = vertices.vertices;
  19867. clip.bones = vertices.bones;
  19868. if (nonessential) Color.rgba8888ToColor(clip.color, color);
  19869. return clip;
  19870. }
  19871. }
  19872. return null;
  19873. }
  19874. readVertices (input, vertexCount) {
  19875. let scale = this.scale;
  19876. let verticesLength = vertexCount << 1;
  19877. let vertices = new Vertices$1();
  19878. if (!input.readBoolean()) {
  19879. vertices.vertices = this.readFloatArray(input, verticesLength, scale);
  19880. return vertices;
  19881. }
  19882. let weights = new Array();
  19883. let bonesArray = new Array();
  19884. for (let i = 0; i < vertexCount; i++) {
  19885. let boneCount = input.readInt(true);
  19886. bonesArray.push(boneCount);
  19887. for (let ii = 0; ii < boneCount; ii++) {
  19888. bonesArray.push(input.readInt(true));
  19889. weights.push(input.readFloat() * scale);
  19890. weights.push(input.readFloat() * scale);
  19891. weights.push(input.readFloat());
  19892. }
  19893. }
  19894. vertices.vertices = Utils.toFloatArray(weights);
  19895. vertices.bones = bonesArray;
  19896. return vertices;
  19897. }
  19898. readFloatArray (input, n, scale) {
  19899. let array = new Array(n);
  19900. if (scale == 1) {
  19901. for (let i = 0; i < n; i++)
  19902. array[i] = input.readFloat();
  19903. } else {
  19904. for (let i = 0; i < n; i++)
  19905. array[i] = input.readFloat() * scale;
  19906. }
  19907. return array;
  19908. }
  19909. readShortArray (input) {
  19910. let n = input.readInt(true);
  19911. let array = new Array(n);
  19912. for (let i = 0; i < n; i++)
  19913. array[i] = input.readShort();
  19914. return array;
  19915. }
  19916. readAnimation (input, name, skeletonData) {
  19917. // @ts-ignore
  19918. let numTimelines = input.readInt(true);
  19919. let timelines = new Array();
  19920. let scale = this.scale;
  19921. // Slot timelines.
  19922. for (let i = 0, n = input.readInt(true); i < n; i++) {
  19923. let slotIndex = input.readInt(true);
  19924. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  19925. let timelineType = input.readByte();
  19926. let frameCount = input.readInt(true);
  19927. let frameLast = frameCount - 1;
  19928. switch (timelineType) {
  19929. case SkeletonBinary$1.SLOT_ATTACHMENT: {
  19930. let timeline = new AttachmentTimeline$2(frameCount, slotIndex);
  19931. for (let frame = 0; frame < frameCount; frame++)
  19932. timeline.setFrame(frame, input.readFloat(), input.readStringRef());
  19933. timelines.push(timeline);
  19934. break;
  19935. }
  19936. case SkeletonBinary$1.SLOT_RGBA: {
  19937. let bezierCount = input.readInt(true);
  19938. let timeline = new RGBATimeline(frameCount, bezierCount, slotIndex);
  19939. let time = input.readFloat();
  19940. let r = input.readUnsignedByte() / 255.0;
  19941. let g = input.readUnsignedByte() / 255.0;
  19942. let b = input.readUnsignedByte() / 255.0;
  19943. let a = input.readUnsignedByte() / 255.0;
  19944. for (let frame = 0, bezier = 0;; frame++) {
  19945. timeline.setFrame(frame, time, r, g, b, a);
  19946. if (frame == frameLast) break;
  19947. let time2 = input.readFloat();
  19948. let r2 = input.readUnsignedByte() / 255.0;
  19949. let g2 = input.readUnsignedByte() / 255.0;
  19950. let b2 = input.readUnsignedByte() / 255.0;
  19951. let a2 = input.readUnsignedByte() / 255.0;
  19952. switch (input.readByte()) {
  19953. case SkeletonBinary$1.CURVE_STEPPED:
  19954. timeline.setStepped(frame);
  19955. break;
  19956. case SkeletonBinary$1.CURVE_BEZIER:
  19957. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
  19958. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
  19959. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
  19960. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1);
  19961. }
  19962. time = time2;
  19963. r = r2;
  19964. g = g2;
  19965. b = b2;
  19966. a = a2;
  19967. }
  19968. timelines.push(timeline);
  19969. break;
  19970. }
  19971. case SkeletonBinary$1.SLOT_RGB: {
  19972. let bezierCount = input.readInt(true);
  19973. let timeline = new RGBTimeline(frameCount, bezierCount, slotIndex);
  19974. let time = input.readFloat();
  19975. let r = input.readUnsignedByte() / 255.0;
  19976. let g = input.readUnsignedByte() / 255.0;
  19977. let b = input.readUnsignedByte() / 255.0;
  19978. for (let frame = 0, bezier = 0;; frame++) {
  19979. timeline.setFrame(frame, time, r, g, b);
  19980. if (frame == frameLast) break;
  19981. let time2 = input.readFloat();
  19982. let r2 = input.readUnsignedByte() / 255.0;
  19983. let g2 = input.readUnsignedByte() / 255.0;
  19984. let b2 = input.readUnsignedByte() / 255.0;
  19985. switch (input.readByte()) {
  19986. case SkeletonBinary$1.CURVE_STEPPED:
  19987. timeline.setStepped(frame);
  19988. break;
  19989. case SkeletonBinary$1.CURVE_BEZIER:
  19990. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
  19991. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
  19992. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
  19993. }
  19994. time = time2;
  19995. r = r2;
  19996. g = g2;
  19997. b = b2;
  19998. }
  19999. timelines.push(timeline);
  20000. break;
  20001. }
  20002. case SkeletonBinary$1.SLOT_RGBA2: {
  20003. let bezierCount = input.readInt(true);
  20004. let timeline = new RGBA2Timeline(frameCount, bezierCount, slotIndex);
  20005. let time = input.readFloat();
  20006. let r = input.readUnsignedByte() / 255.0;
  20007. let g = input.readUnsignedByte() / 255.0;
  20008. let b = input.readUnsignedByte() / 255.0;
  20009. let a = input.readUnsignedByte() / 255.0;
  20010. let r2 = input.readUnsignedByte() / 255.0;
  20011. let g2 = input.readUnsignedByte() / 255.0;
  20012. let b2 = input.readUnsignedByte() / 255.0;
  20013. for (let frame = 0, bezier = 0;; frame++) {
  20014. timeline.setFrame(frame, time, r, g, b, a, r2, g2, b2);
  20015. if (frame == frameLast) break;
  20016. let time2 = input.readFloat();
  20017. let nr = input.readUnsignedByte() / 255.0;
  20018. let ng = input.readUnsignedByte() / 255.0;
  20019. let nb = input.readUnsignedByte() / 255.0;
  20020. let na = input.readUnsignedByte() / 255.0;
  20021. let nr2 = input.readUnsignedByte() / 255.0;
  20022. let ng2 = input.readUnsignedByte() / 255.0;
  20023. let nb2 = input.readUnsignedByte() / 255.0;
  20024. switch (input.readByte()) {
  20025. case SkeletonBinary$1.CURVE_STEPPED:
  20026. timeline.setStepped(frame);
  20027. break;
  20028. case SkeletonBinary$1.CURVE_BEZIER:
  20029. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
  20030. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
  20031. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
  20032. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1);
  20033. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1);
  20034. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1);
  20035. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1);
  20036. }
  20037. time = time2;
  20038. r = nr;
  20039. g = ng;
  20040. b = nb;
  20041. a = na;
  20042. r2 = nr2;
  20043. g2 = ng2;
  20044. b2 = nb2;
  20045. }
  20046. timelines.push(timeline);
  20047. break;
  20048. }
  20049. case SkeletonBinary$1.SLOT_RGB2: {
  20050. let bezierCount = input.readInt(true);
  20051. let timeline = new RGB2Timeline(frameCount, bezierCount, slotIndex);
  20052. let time = input.readFloat();
  20053. let r = input.readUnsignedByte() / 255.0;
  20054. let g = input.readUnsignedByte() / 255.0;
  20055. let b = input.readUnsignedByte() / 255.0;
  20056. let r2 = input.readUnsignedByte() / 255.0;
  20057. let g2 = input.readUnsignedByte() / 255.0;
  20058. let b2 = input.readUnsignedByte() / 255.0;
  20059. for (let frame = 0, bezier = 0;; frame++) {
  20060. timeline.setFrame(frame, time, r, g, b, r2, g2, b2);
  20061. if (frame == frameLast) break;
  20062. let time2 = input.readFloat();
  20063. let nr = input.readUnsignedByte() / 255.0;
  20064. let ng = input.readUnsignedByte() / 255.0;
  20065. let nb = input.readUnsignedByte() / 255.0;
  20066. let nr2 = input.readUnsignedByte() / 255.0;
  20067. let ng2 = input.readUnsignedByte() / 255.0;
  20068. let nb2 = input.readUnsignedByte() / 255.0;
  20069. switch (input.readByte()) {
  20070. case SkeletonBinary$1.CURVE_STEPPED:
  20071. timeline.setStepped(frame);
  20072. break;
  20073. case SkeletonBinary$1.CURVE_BEZIER:
  20074. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
  20075. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
  20076. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
  20077. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1);
  20078. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1);
  20079. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1);
  20080. }
  20081. time = time2;
  20082. r = nr;
  20083. g = ng;
  20084. b = nb;
  20085. r2 = nr2;
  20086. g2 = ng2;
  20087. b2 = nb2;
  20088. }
  20089. timelines.push(timeline);
  20090. break;
  20091. }
  20092. case SkeletonBinary$1.SLOT_ALPHA: {
  20093. let timeline = new AlphaTimeline(frameCount, input.readInt(true), slotIndex);
  20094. let time = input.readFloat(), a = input.readUnsignedByte() / 255;
  20095. for (let frame = 0, bezier = 0;; frame++) {
  20096. timeline.setFrame(frame, time, a);
  20097. if (frame == frameLast) break;
  20098. let time2 = input.readFloat();
  20099. let a2 = input.readUnsignedByte() / 255;
  20100. switch (input.readByte()) {
  20101. case SkeletonBinary$1.CURVE_STEPPED:
  20102. timeline.setStepped(frame);
  20103. break;
  20104. case SkeletonBinary$1.CURVE_BEZIER:
  20105. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1);
  20106. }
  20107. time = time2;
  20108. a = a2;
  20109. }
  20110. timelines.push(timeline);
  20111. break;
  20112. }
  20113. }
  20114. }
  20115. }
  20116. // Bone timelines.
  20117. for (let i = 0, n = input.readInt(true); i < n; i++) {
  20118. let boneIndex = input.readInt(true);
  20119. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  20120. let type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true);
  20121. switch (type) {
  20122. case SkeletonBinary$1.BONE_ROTATE:
  20123. timelines.push(SkeletonBinary$1.readTimeline(input, new RotateTimeline$2(frameCount, bezierCount, boneIndex), 1));
  20124. break;
  20125. case SkeletonBinary$1.BONE_TRANSLATE:
  20126. timelines.push(SkeletonBinary$1.readTimeline2(input, new TranslateTimeline$2(frameCount, bezierCount, boneIndex), scale));
  20127. break;
  20128. case SkeletonBinary$1.BONE_TRANSLATEX:
  20129. timelines.push(SkeletonBinary$1.readTimeline(input, new TranslateXTimeline(frameCount, bezierCount, boneIndex), scale));
  20130. break;
  20131. case SkeletonBinary$1.BONE_TRANSLATEY:
  20132. timelines.push(SkeletonBinary$1.readTimeline(input, new TranslateYTimeline(frameCount, bezierCount, boneIndex), scale));
  20133. break;
  20134. case SkeletonBinary$1.BONE_SCALE:
  20135. timelines.push(SkeletonBinary$1.readTimeline2(input, new ScaleTimeline$2(frameCount, bezierCount, boneIndex), 1));
  20136. break;
  20137. case SkeletonBinary$1.BONE_SCALEX:
  20138. timelines.push(SkeletonBinary$1.readTimeline(input, new ScaleXTimeline(frameCount, bezierCount, boneIndex), 1));
  20139. break;
  20140. case SkeletonBinary$1.BONE_SCALEY:
  20141. timelines.push(SkeletonBinary$1.readTimeline(input, new ScaleYTimeline(frameCount, bezierCount, boneIndex), 1));
  20142. break;
  20143. case SkeletonBinary$1.BONE_SHEAR:
  20144. timelines.push(SkeletonBinary$1.readTimeline2(input, new ShearTimeline$2(frameCount, bezierCount, boneIndex), 1));
  20145. break;
  20146. case SkeletonBinary$1.BONE_SHEARX:
  20147. timelines.push(SkeletonBinary$1.readTimeline(input, new ShearXTimeline(frameCount, bezierCount, boneIndex), 1));
  20148. break;
  20149. case SkeletonBinary$1.BONE_SHEARY:
  20150. timelines.push(SkeletonBinary$1.readTimeline(input, new ShearYTimeline(frameCount, bezierCount, boneIndex), 1));
  20151. }
  20152. }
  20153. }
  20154. // IK constraint timelines.
  20155. for (let i = 0, n = input.readInt(true); i < n; i++) {
  20156. let index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1;
  20157. let timeline = new IkConstraintTimeline$2(frameCount, input.readInt(true), index);
  20158. let time = input.readFloat(), mix = input.readFloat(), softness = input.readFloat() * scale;
  20159. for (let frame = 0, bezier = 0;; frame++) {
  20160. timeline.setFrame(frame, time, mix, softness, input.readByte(), input.readBoolean(), input.readBoolean());
  20161. if (frame == frameLast) break;
  20162. let time2 = input.readFloat(), mix2 = input.readFloat(), softness2 = input.readFloat() * scale;
  20163. switch (input.readByte()) {
  20164. case SkeletonBinary$1.CURVE_STEPPED:
  20165. timeline.setStepped(frame);
  20166. break;
  20167. case SkeletonBinary$1.CURVE_BEZIER:
  20168. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1);
  20169. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale);
  20170. }
  20171. time = time2;
  20172. mix = mix2;
  20173. softness = softness2;
  20174. }
  20175. timelines.push(timeline);
  20176. }
  20177. // Transform constraint timelines.
  20178. for (let i = 0, n = input.readInt(true); i < n; i++) {
  20179. let index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1;
  20180. let timeline = new TransformConstraintTimeline$2(frameCount, input.readInt(true), index);
  20181. let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(),
  20182. mixScaleX = input.readFloat(), mixScaleY = input.readFloat(), mixShearY = input.readFloat();
  20183. for (let frame = 0, bezier = 0;; frame++) {
  20184. timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
  20185. if (frame == frameLast) break;
  20186. let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(),
  20187. mixScaleX2 = input.readFloat(), mixScaleY2 = input.readFloat(), mixShearY2 = input.readFloat();
  20188. switch (input.readByte()) {
  20189. case SkeletonBinary$1.CURVE_STEPPED:
  20190. timeline.setStepped(frame);
  20191. break;
  20192. case SkeletonBinary$1.CURVE_BEZIER:
  20193. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  20194. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
  20195. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
  20196. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
  20197. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
  20198. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1);
  20199. }
  20200. time = time2;
  20201. mixRotate = mixRotate2;
  20202. mixX = mixX2;
  20203. mixY = mixY2;
  20204. mixScaleX = mixScaleX2;
  20205. mixScaleY = mixScaleY2;
  20206. mixShearY = mixShearY2;
  20207. }
  20208. timelines.push(timeline);
  20209. }
  20210. // Path constraint timelines.
  20211. for (let i = 0, n = input.readInt(true); i < n; i++) {
  20212. let index = input.readInt(true);
  20213. let data = skeletonData.pathConstraints[index];
  20214. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  20215. switch (input.readByte()) {
  20216. case SkeletonBinary$1.PATH_POSITION:
  20217. timelines
  20218. .push(SkeletonBinary$1.readTimeline(input, new PathConstraintPositionTimeline$2(input.readInt(true), input.readInt(true), index),
  20219. data.positionMode == PositionMode$2.Fixed ? scale : 1));
  20220. break;
  20221. case SkeletonBinary$1.PATH_SPACING:
  20222. timelines
  20223. .push(SkeletonBinary$1.readTimeline(input, new PathConstraintSpacingTimeline$2(input.readInt(true), input.readInt(true), index),
  20224. data.spacingMode == SpacingMode$2.Length || data.spacingMode == SpacingMode$2.Fixed ? scale : 1));
  20225. break;
  20226. case SkeletonBinary$1.PATH_MIX:
  20227. let timeline = new PathConstraintMixTimeline$2(input.readInt(true), input.readInt(true),
  20228. index);
  20229. let time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat();
  20230. for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
  20231. timeline.setFrame(frame, time, mixRotate, mixX, mixY);
  20232. if (frame == frameLast) break;
  20233. let time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(),
  20234. mixY2 = input.readFloat();
  20235. switch (input.readByte()) {
  20236. case SkeletonBinary$1.CURVE_STEPPED:
  20237. timeline.setStepped(frame);
  20238. break;
  20239. case SkeletonBinary$1.CURVE_BEZIER:
  20240. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  20241. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
  20242. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
  20243. }
  20244. time = time2;
  20245. mixRotate = mixRotate2;
  20246. mixX = mixX2;
  20247. mixY = mixY2;
  20248. }
  20249. timelines.push(timeline);
  20250. }
  20251. }
  20252. }
  20253. // Deform timelines.
  20254. for (let i = 0, n = input.readInt(true); i < n; i++) {
  20255. let skin = skeletonData.skins[input.readInt(true)];
  20256. for (let ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  20257. let slotIndex = input.readInt(true);
  20258. for (let iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
  20259. let attachmentName = input.readStringRef();
  20260. let attachment = skin.getAttachment(slotIndex, attachmentName) ;
  20261. if (attachment == null) throw Error("Vertex attachment not found: " + attachmentName);
  20262. let weighted = attachment.bones != null;
  20263. let vertices = attachment.vertices;
  20264. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  20265. let frameCount = input.readInt(true);
  20266. let frameLast = frameCount - 1;
  20267. let bezierCount = input.readInt(true);
  20268. let timeline = new DeformTimeline$2(frameCount, bezierCount, slotIndex, attachment);
  20269. let time = input.readFloat();
  20270. for (let frame = 0, bezier = 0;; frame++) {
  20271. let deform;
  20272. let end = input.readInt(true);
  20273. if (end == 0)
  20274. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  20275. else {
  20276. deform = Utils.newFloatArray(deformLength);
  20277. let start = input.readInt(true);
  20278. end += start;
  20279. if (scale == 1) {
  20280. for (let v = start; v < end; v++)
  20281. deform[v] = input.readFloat();
  20282. } else {
  20283. for (let v = start; v < end; v++)
  20284. deform[v] = input.readFloat() * scale;
  20285. }
  20286. if (!weighted) {
  20287. for (let v = 0, vn = deform.length; v < vn; v++)
  20288. deform[v] += vertices[v];
  20289. }
  20290. }
  20291. timeline.setFrame(frame, time, deform);
  20292. if (frame == frameLast) break;
  20293. let time2 = input.readFloat();
  20294. switch(input.readByte()) {
  20295. case SkeletonBinary$1.CURVE_STEPPED:
  20296. timeline.setStepped(frame);
  20297. break;
  20298. case SkeletonBinary$1.CURVE_BEZIER:
  20299. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
  20300. }
  20301. time = time2;
  20302. }
  20303. timelines.push(timeline);
  20304. }
  20305. }
  20306. }
  20307. // Draw order timeline.
  20308. let drawOrderCount = input.readInt(true);
  20309. if (drawOrderCount > 0) {
  20310. let timeline = new DrawOrderTimeline$2(drawOrderCount);
  20311. let slotCount = skeletonData.slots.length;
  20312. for (let i = 0; i < drawOrderCount; i++) {
  20313. let time = input.readFloat();
  20314. let offsetCount = input.readInt(true);
  20315. let drawOrder = Utils.newArray(slotCount, 0);
  20316. for (let ii = slotCount - 1; ii >= 0; ii--)
  20317. drawOrder[ii] = -1;
  20318. let unchanged = Utils.newArray(slotCount - offsetCount, 0);
  20319. let originalIndex = 0, unchangedIndex = 0;
  20320. for (let ii = 0; ii < offsetCount; ii++) {
  20321. let slotIndex = input.readInt(true);
  20322. // Collect unchanged items.
  20323. while (originalIndex != slotIndex)
  20324. unchanged[unchangedIndex++] = originalIndex++;
  20325. // Set changed items.
  20326. drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
  20327. }
  20328. // Collect remaining unchanged items.
  20329. while (originalIndex < slotCount)
  20330. unchanged[unchangedIndex++] = originalIndex++;
  20331. // Fill in unchanged items.
  20332. for (let ii = slotCount - 1; ii >= 0; ii--)
  20333. if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex];
  20334. timeline.setFrame(i, time, drawOrder);
  20335. }
  20336. timelines.push(timeline);
  20337. }
  20338. // Event timeline.
  20339. let eventCount = input.readInt(true);
  20340. if (eventCount > 0) {
  20341. let timeline = new EventTimeline$2(eventCount);
  20342. for (let i = 0; i < eventCount; i++) {
  20343. let time = input.readFloat();
  20344. let eventData = skeletonData.events[input.readInt(true)];
  20345. let event = new Event$2(time, eventData);
  20346. event.intValue = input.readInt(false);
  20347. event.floatValue = input.readFloat();
  20348. event.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
  20349. if (event.data.audioPath != null) {
  20350. event.volume = input.readFloat();
  20351. event.balance = input.readFloat();
  20352. }
  20353. timeline.setFrame(i, event);
  20354. }
  20355. timelines.push(timeline);
  20356. }
  20357. let duration = 0;
  20358. for (let i = 0, n = timelines.length; i < n; i++)
  20359. duration = Math.max(duration, (timelines[i]).getDuration());
  20360. return new Animation$2(name, timelines, duration);
  20361. }
  20362. static readTimeline (input, timeline, scale) {
  20363. let time = input.readFloat(), value = input.readFloat() * scale;
  20364. for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
  20365. timeline.setFrame(frame, time, value);
  20366. if (frame == frameLast) break;
  20367. let time2 = input.readFloat(), value2 = input.readFloat() * scale;
  20368. switch (input.readByte()) {
  20369. case SkeletonBinary$1.CURVE_STEPPED:
  20370. timeline.setStepped(frame);
  20371. break;
  20372. case SkeletonBinary$1.CURVE_BEZIER:
  20373. SkeletonBinary$1.setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, 1);
  20374. }
  20375. time = time2;
  20376. value = value2;
  20377. }
  20378. return timeline;
  20379. }
  20380. static readTimeline2 (input, timeline, scale) {
  20381. let time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale;
  20382. for (let frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
  20383. timeline.setFrame(frame, time, value1, value2);
  20384. if (frame == frameLast) break;
  20385. let time2 = input.readFloat(), nvalue1 = input.readFloat() * scale, nvalue2 = input.readFloat() * scale;
  20386. switch (input.readByte()) {
  20387. case SkeletonBinary$1.CURVE_STEPPED:
  20388. timeline.setStepped(frame);
  20389. break;
  20390. case SkeletonBinary$1.CURVE_BEZIER:
  20391. this.setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
  20392. this.setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);
  20393. }
  20394. time = time2;
  20395. value1 = nvalue1;
  20396. value2 = nvalue2;
  20397. }
  20398. return timeline;
  20399. }
  20400. static setBezier (input, timeline, bezier, frame, value, time1, time2, value1, value2, scale) {
  20401. timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2);
  20402. }
  20403. } SkeletonBinary$1.__initStatic(); SkeletonBinary$1.__initStatic2(); SkeletonBinary$1.__initStatic3(); SkeletonBinary$1.__initStatic4(); SkeletonBinary$1.__initStatic5(); SkeletonBinary$1.__initStatic6(); SkeletonBinary$1.__initStatic7(); SkeletonBinary$1.__initStatic8(); SkeletonBinary$1.__initStatic9(); SkeletonBinary$1.__initStatic10(); SkeletonBinary$1.__initStatic11(); SkeletonBinary$1.__initStatic12(); SkeletonBinary$1.__initStatic13(); SkeletonBinary$1.__initStatic14(); SkeletonBinary$1.__initStatic15(); SkeletonBinary$1.__initStatic16(); SkeletonBinary$1.__initStatic17(); SkeletonBinary$1.__initStatic18(); SkeletonBinary$1.__initStatic19(); SkeletonBinary$1.__initStatic20(); SkeletonBinary$1.__initStatic21(); SkeletonBinary$1.__initStatic22(); SkeletonBinary$1.__initStatic23(); SkeletonBinary$1.__initStatic24(); SkeletonBinary$1.__initStatic25(); SkeletonBinary$1.__initStatic26(); SkeletonBinary$1.__initStatic27(); SkeletonBinary$1.__initStatic28();
  20404. class LinkedMesh$3 {
  20405. constructor (mesh, skin, slotIndex, parent, inheritDeform) {
  20406. this.mesh = mesh;
  20407. this.skin = skin;
  20408. this.slotIndex = slotIndex;
  20409. this.parent = parent;
  20410. this.inheritDeform = inheritDeform;
  20411. }
  20412. }
  20413. class Vertices$1 {
  20414. constructor( bones = null, vertices = null) {this.bones = bones;this.vertices = vertices; }
  20415. }
  20416. /** Collects each visible {@link BoundingBoxAttachment} and computes the world vertices for its polygon. The polygon vertices are
  20417. * provided along with convenience methods for doing hit detection.
  20418. * @public
  20419. * */
  20420. class SkeletonBounds$2 {constructor() { SkeletonBounds$2.prototype.__init.call(this);SkeletonBounds$2.prototype.__init2.call(this);SkeletonBounds$2.prototype.__init3.call(this);SkeletonBounds$2.prototype.__init4.call(this);SkeletonBounds$2.prototype.__init5.call(this);SkeletonBounds$2.prototype.__init6.call(this);SkeletonBounds$2.prototype.__init7.call(this); }
  20421. /** The left edge of the axis aligned bounding box. */
  20422. __init() {this.minX = 0;}
  20423. /** The bottom edge of the axis aligned bounding box. */
  20424. __init2() {this.minY = 0;}
  20425. /** The right edge of the axis aligned bounding box. */
  20426. __init3() {this.maxX = 0;}
  20427. /** The top edge of the axis aligned bounding box. */
  20428. __init4() {this.maxY = 0;}
  20429. /** The visible bounding boxes. */
  20430. __init5() {this.boundingBoxes = new Array();}
  20431. /** The world vertices for the bounding box polygons. */
  20432. __init6() {this.polygons = new Array();}
  20433. __init7() {this.polygonPool = new Pool(() => {
  20434. return Utils.newFloatArray(16);
  20435. });}
  20436. /** Clears any previous polygons, finds all visible bounding box attachments, and computes the world vertices for each bounding
  20437. * box's polygon.
  20438. * @param updateAabb If true, the axis aligned bounding box containing all the polygons is computed. If false, the
  20439. * SkeletonBounds AABB methods will always return true. */
  20440. update (skeleton, updateAabb) {
  20441. if (skeleton == null) throw new Error("skeleton cannot be null.");
  20442. let boundingBoxes = this.boundingBoxes;
  20443. let polygons = this.polygons;
  20444. let polygonPool = this.polygonPool;
  20445. let slots = skeleton.slots;
  20446. let slotCount = slots.length;
  20447. boundingBoxes.length = 0;
  20448. polygonPool.freeAll(polygons);
  20449. polygons.length = 0;
  20450. for (let i = 0; i < slotCount; i++) {
  20451. let slot = slots[i];
  20452. if (!slot.bone.active) continue;
  20453. let attachment = slot.getAttachment();
  20454. if (attachment instanceof BoundingBoxAttachment$2) {
  20455. let boundingBox = attachment ;
  20456. boundingBoxes.push(boundingBox);
  20457. let polygon = polygonPool.obtain();
  20458. if (polygon.length != boundingBox.worldVerticesLength) {
  20459. polygon = Utils.newFloatArray(boundingBox.worldVerticesLength);
  20460. }
  20461. polygons.push(polygon);
  20462. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  20463. }
  20464. }
  20465. if (updateAabb) {
  20466. this.aabbCompute();
  20467. } else {
  20468. this.minX = Number.POSITIVE_INFINITY;
  20469. this.minY = Number.POSITIVE_INFINITY;
  20470. this.maxX = Number.NEGATIVE_INFINITY;
  20471. this.maxY = Number.NEGATIVE_INFINITY;
  20472. }
  20473. }
  20474. aabbCompute () {
  20475. let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  20476. let polygons = this.polygons;
  20477. for (let i = 0, n = polygons.length; i < n; i++) {
  20478. let polygon = polygons[i];
  20479. let vertices = polygon;
  20480. for (let ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  20481. let x = vertices[ii];
  20482. let y = vertices[ii + 1];
  20483. minX = Math.min(minX, x);
  20484. minY = Math.min(minY, y);
  20485. maxX = Math.max(maxX, x);
  20486. maxY = Math.max(maxY, y);
  20487. }
  20488. }
  20489. this.minX = minX;
  20490. this.minY = minY;
  20491. this.maxX = maxX;
  20492. this.maxY = maxY;
  20493. }
  20494. /** Returns true if the axis aligned bounding box contains the point. */
  20495. aabbContainsPoint (x, y) {
  20496. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  20497. }
  20498. /** Returns true if the axis aligned bounding box intersects the line segment. */
  20499. aabbIntersectsSegment (x1, y1, x2, y2) {
  20500. let minX = this.minX;
  20501. let minY = this.minY;
  20502. let maxX = this.maxX;
  20503. let maxY = this.maxY;
  20504. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  20505. return false;
  20506. let m = (y2 - y1) / (x2 - x1);
  20507. let y = m * (minX - x1) + y1;
  20508. if (y > minY && y < maxY) return true;
  20509. y = m * (maxX - x1) + y1;
  20510. if (y > minY && y < maxY) return true;
  20511. let x = (minY - y1) / m + x1;
  20512. if (x > minX && x < maxX) return true;
  20513. x = (maxY - y1) / m + x1;
  20514. if (x > minX && x < maxX) return true;
  20515. return false;
  20516. }
  20517. /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */
  20518. aabbIntersectsSkeleton (bounds) {
  20519. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  20520. }
  20521. /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more
  20522. * efficient to only call this method if {@link #aabbContainsPoint(float, float)} returns true. */
  20523. containsPoint (x, y) {
  20524. let polygons = this.polygons;
  20525. for (let i = 0, n = polygons.length; i < n; i++)
  20526. if (this.containsPointPolygon(polygons[i], x, y)) return this.boundingBoxes[i];
  20527. return null;
  20528. }
  20529. /** Returns true if the polygon contains the point. */
  20530. containsPointPolygon (polygon, x, y) {
  20531. let vertices = polygon;
  20532. let nn = polygon.length;
  20533. let prevIndex = nn - 2;
  20534. let inside = false;
  20535. for (let ii = 0; ii < nn; ii += 2) {
  20536. let vertexY = vertices[ii + 1];
  20537. let prevY = vertices[prevIndex + 1];
  20538. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  20539. let vertexX = vertices[ii];
  20540. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) inside = !inside;
  20541. }
  20542. prevIndex = ii;
  20543. }
  20544. return inside;
  20545. }
  20546. /** Returns the first bounding box attachment that contains any part of the line segment, or null. When doing many checks, it
  20547. * is usually more efficient to only call this method if {@link #aabbIntersectsSegment()} returns
  20548. * true. */
  20549. intersectsSegment (x1, y1, x2, y2) {
  20550. let polygons = this.polygons;
  20551. for (let i = 0, n = polygons.length; i < n; i++)
  20552. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2)) return this.boundingBoxes[i];
  20553. return null;
  20554. }
  20555. /** Returns true if the polygon contains any part of the line segment. */
  20556. intersectsSegmentPolygon (polygon, x1, y1, x2, y2) {
  20557. let vertices = polygon;
  20558. let nn = polygon.length;
  20559. let width12 = x1 - x2, height12 = y1 - y2;
  20560. let det1 = x1 * y2 - y1 * x2;
  20561. let x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  20562. for (let ii = 0; ii < nn; ii += 2) {
  20563. let x4 = vertices[ii], y4 = vertices[ii + 1];
  20564. let det2 = x3 * y4 - y3 * x4;
  20565. let width34 = x3 - x4, height34 = y3 - y4;
  20566. let det3 = width12 * height34 - height12 * width34;
  20567. let x = (det1 * width34 - width12 * det2) / det3;
  20568. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  20569. let y = (det1 * height34 - height12 * det2) / det3;
  20570. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) return true;
  20571. }
  20572. x3 = x4;
  20573. y3 = y4;
  20574. }
  20575. return false;
  20576. }
  20577. /** Returns the polygon for the specified bounding box, or null. */
  20578. getPolygon (boundingBox) {
  20579. if (boundingBox == null) throw new Error("boundingBox cannot be null.");
  20580. let index = this.boundingBoxes.indexOf(boundingBox);
  20581. return index == -1 ? null : this.polygons[index];
  20582. }
  20583. /** The width of the axis aligned bounding box. */
  20584. getWidth () {
  20585. return this.maxX - this.minX;
  20586. }
  20587. /** The height of the axis aligned bounding box. */
  20588. getHeight () {
  20589. return this.maxY - this.minY;
  20590. }
  20591. }
  20592. /** Loads skeleton data in the Spine JSON format.
  20593. *
  20594. * See [Spine JSON format](http://esotericsoftware.com/spine-json-format) and
  20595. * [JSON and binary data](http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data) in the Spine
  20596. * Runtimes Guide.
  20597. * @public
  20598. * */
  20599. class SkeletonJson$2 {
  20600. /** Scales bone positions, image sizes, and translations as they are loaded. This allows different size images to be used at
  20601. * runtime than were used in Spine.
  20602. *
  20603. * See [Scaling](http://esotericsoftware.com/spine-loading-skeleton-data#Scaling) in the Spine Runtimes Guide. */
  20604. __init() {this.scale = 1;}
  20605. __init2() {this.linkedMeshes = new Array();}
  20606. constructor (attachmentLoader) {SkeletonJson$2.prototype.__init.call(this);SkeletonJson$2.prototype.__init2.call(this);
  20607. this.attachmentLoader = attachmentLoader;
  20608. }
  20609. readSkeletonData (json) {
  20610. let scale = this.scale;
  20611. let skeletonData = new SkeletonData$2();
  20612. let root = typeof(json) === "string" ? JSON.parse(json) : json;
  20613. // Skeleton
  20614. let skeletonMap = root.skeleton;
  20615. if (skeletonMap != null) {
  20616. skeletonData.hash = skeletonMap.hash;
  20617. skeletonData.version = skeletonMap.spine;
  20618. if (skeletonData.version.substr(0, 3) !== '4.0') {
  20619. let error = `Spine 4.0 loader cant load version ${skeletonMap.spine}. Please configure your pixi-spine bundle`;
  20620. console.error(error);
  20621. }
  20622. skeletonData.x = skeletonMap.x;
  20623. skeletonData.y = skeletonMap.y;
  20624. skeletonData.width = skeletonMap.width;
  20625. skeletonData.height = skeletonMap.height;
  20626. skeletonData.fps = skeletonMap.fps;
  20627. skeletonData.imagesPath = skeletonMap.images;
  20628. }
  20629. // Bones
  20630. if (root.bones) {
  20631. for (let i = 0; i < root.bones.length; i++) {
  20632. let boneMap = root.bones[i];
  20633. let parent = null;
  20634. let parentName = this.getValue(boneMap, "parent", null);
  20635. if (parentName != null) {
  20636. parent = skeletonData.findBone(parentName);
  20637. if (parent == null) throw new Error("Parent bone not found: " + parentName);
  20638. }
  20639. let data = new BoneData$2(skeletonData.bones.length, boneMap.name, parent);
  20640. data.length = this.getValue(boneMap, "length", 0) * scale;
  20641. data.x = this.getValue(boneMap, "x", 0) * scale;
  20642. data.y = this.getValue(boneMap, "y", 0) * scale;
  20643. data.rotation = this.getValue(boneMap, "rotation", 0);
  20644. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  20645. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  20646. data.shearX = this.getValue(boneMap, "shearX", 0);
  20647. data.shearY = this.getValue(boneMap, "shearY", 0);
  20648. data.transformMode = SkeletonJson$2.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  20649. data.skinRequired = this.getValue(boneMap, "skin", false);
  20650. let color = this.getValue(boneMap, "color", null);
  20651. if (color) data.color.setFromString(color);
  20652. skeletonData.bones.push(data);
  20653. }
  20654. }
  20655. // Slots.
  20656. if (root.slots) {
  20657. for (let i = 0; i < root.slots.length; i++) {
  20658. let slotMap = root.slots[i];
  20659. let slotName = slotMap.name;
  20660. let boneName = slotMap.bone;
  20661. let boneData = skeletonData.findBone(boneName);
  20662. if (boneData == null) throw new Error("Slot bone not found: " + boneName);
  20663. let data = new SlotData$2(skeletonData.slots.length, slotName, boneData);
  20664. let color = this.getValue(slotMap, "color", null);
  20665. if (color != null) data.color.setFromString(color);
  20666. let dark = this.getValue(slotMap, "dark", null);
  20667. if (dark != null) {
  20668. data.darkColor = new Color(1, 1, 1, 1);
  20669. data.darkColor.setFromString(dark);
  20670. }
  20671. data.attachmentName = this.getValue(slotMap, "attachment", null);
  20672. data.blendMode = SkeletonJson$2.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  20673. skeletonData.slots.push(data);
  20674. }
  20675. }
  20676. // IK constraints
  20677. if (root.ik) {
  20678. for (let i = 0; i < root.ik.length; i++) {
  20679. let constraintMap = root.ik[i];
  20680. let data = new IkConstraintData$2(constraintMap.name);
  20681. data.order = this.getValue(constraintMap, "order", 0);
  20682. data.skinRequired = this.getValue(constraintMap, "skin", false);
  20683. for (let j = 0; j < constraintMap.bones.length; j++) {
  20684. let boneName = constraintMap.bones[j];
  20685. let bone = skeletonData.findBone(boneName);
  20686. if (bone == null) throw new Error("IK bone not found: " + boneName);
  20687. data.bones.push(bone);
  20688. }
  20689. let targetName = constraintMap.target;
  20690. data.target = skeletonData.findBone(targetName);
  20691. if (data.target == null) throw new Error("IK target bone not found: " + targetName);
  20692. data.mix = this.getValue(constraintMap, "mix", 1);
  20693. data.softness = this.getValue(constraintMap, "softness", 0) * scale;
  20694. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  20695. data.compress = this.getValue(constraintMap, "compress", false);
  20696. data.stretch = this.getValue(constraintMap, "stretch", false);
  20697. data.uniform = this.getValue(constraintMap, "uniform", false);
  20698. skeletonData.ikConstraints.push(data);
  20699. }
  20700. }
  20701. // Transform constraints.
  20702. if (root.transform) {
  20703. for (let i = 0; i < root.transform.length; i++) {
  20704. let constraintMap = root.transform[i];
  20705. let data = new TransformConstraintData$2(constraintMap.name);
  20706. data.order = this.getValue(constraintMap, "order", 0);
  20707. data.skinRequired = this.getValue(constraintMap, "skin", false);
  20708. for (let j = 0; j < constraintMap.bones.length; j++) {
  20709. let boneName = constraintMap.bones[j];
  20710. let bone = skeletonData.findBone(boneName);
  20711. if (bone == null) throw new Error("Transform constraint bone not found: " + boneName);
  20712. data.bones.push(bone);
  20713. }
  20714. let targetName = constraintMap.target;
  20715. data.target = skeletonData.findBone(targetName);
  20716. if (data.target == null) throw new Error("Transform constraint target bone not found: " + targetName);
  20717. data.local = this.getValue(constraintMap, "local", false);
  20718. data.relative = this.getValue(constraintMap, "relative", false);
  20719. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  20720. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  20721. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  20722. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  20723. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  20724. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  20725. data.mixRotate = this.getValue(constraintMap, "mixRotate", 1);
  20726. data.mixX = this.getValue(constraintMap, "mixX", 1);
  20727. data.mixY = this.getValue(constraintMap, "mixY", data.mixX);
  20728. data.mixScaleX = this.getValue(constraintMap, "mixScaleX", 1);
  20729. data.mixScaleY = this.getValue(constraintMap, "mixScaleY", data.mixScaleX);
  20730. data.mixShearY = this.getValue(constraintMap, "mixShearY", 1);
  20731. skeletonData.transformConstraints.push(data);
  20732. }
  20733. }
  20734. // Path constraints.
  20735. if (root.path) {
  20736. for (let i = 0; i < root.path.length; i++) {
  20737. let constraintMap = root.path[i];
  20738. let data = new PathConstraintData$2(constraintMap.name);
  20739. data.order = this.getValue(constraintMap, "order", 0);
  20740. data.skinRequired = this.getValue(constraintMap, "skin", false);
  20741. for (let j = 0; j < constraintMap.bones.length; j++) {
  20742. let boneName = constraintMap.bones[j];
  20743. let bone = skeletonData.findBone(boneName);
  20744. if (bone == null) throw new Error("Transform constraint bone not found: " + boneName);
  20745. data.bones.push(bone);
  20746. }
  20747. let targetName = constraintMap.target;
  20748. data.target = skeletonData.findSlot(targetName);
  20749. if (data.target == null) throw new Error("Path target slot not found: " + targetName);
  20750. data.positionMode = SkeletonJson$2.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  20751. data.spacingMode = SkeletonJson$2.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  20752. data.rotateMode = SkeletonJson$2.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  20753. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  20754. data.position = this.getValue(constraintMap, "position", 0);
  20755. if (data.positionMode == PositionMode$2.Fixed) data.position *= scale;
  20756. data.spacing = this.getValue(constraintMap, "spacing", 0);
  20757. if (data.spacingMode == SpacingMode$2.Length || data.spacingMode == SpacingMode$2.Fixed) data.spacing *= scale;
  20758. data.mixRotate = this.getValue(constraintMap, "mixRotate", 1);
  20759. data.mixX = this.getValue(constraintMap, "mixX", 1);
  20760. data.mixY = this.getValue(constraintMap, "mixY", 1);
  20761. skeletonData.pathConstraints.push(data);
  20762. }
  20763. }
  20764. // Skins.
  20765. if (root.skins) {
  20766. for (let i = 0; i < root.skins.length; i++) {
  20767. let skinMap = root.skins[i];
  20768. let skin = new Skin$2(skinMap.name);
  20769. if (skinMap.bones) {
  20770. for (let ii = 0; ii < skinMap.bones.length; ii++) {
  20771. let bone = skeletonData.findBone(skinMap.bones[ii]);
  20772. if (bone == null) throw new Error("Skin bone not found: " + skinMap.bones[i]);
  20773. skin.bones.push(bone);
  20774. }
  20775. }
  20776. if (skinMap.ik) {
  20777. for (let ii = 0; ii < skinMap.ik.length; ii++) {
  20778. let constraint = skeletonData.findIkConstraint(skinMap.ik[ii]);
  20779. if (constraint == null) throw new Error("Skin IK constraint not found: " + skinMap.ik[i]);
  20780. skin.constraints.push(constraint);
  20781. }
  20782. }
  20783. if (skinMap.transform) {
  20784. for (let ii = 0; ii < skinMap.transform.length; ii++) {
  20785. let constraint = skeletonData.findTransformConstraint(skinMap.transform[ii]);
  20786. if (constraint == null) throw new Error("Skin transform constraint not found: " + skinMap.transform[i]);
  20787. skin.constraints.push(constraint);
  20788. }
  20789. }
  20790. if (skinMap.path) {
  20791. for (let ii = 0; ii < skinMap.path.length; ii++) {
  20792. let constraint = skeletonData.findPathConstraint(skinMap.path[ii]);
  20793. if (constraint == null) throw new Error("Skin path constraint not found: " + skinMap.path[i]);
  20794. skin.constraints.push(constraint);
  20795. }
  20796. }
  20797. for (let slotName in skinMap.attachments) {
  20798. let slot = skeletonData.findSlot(slotName);
  20799. if (slot == null) throw new Error("Slot not found: " + slotName);
  20800. let slotMap = skinMap.attachments[slotName];
  20801. for (let entryName in slotMap) {
  20802. let attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
  20803. if (attachment != null) skin.setAttachment(slot.index, entryName, attachment);
  20804. }
  20805. }
  20806. skeletonData.skins.push(skin);
  20807. if (skin.name == "default") skeletonData.defaultSkin = skin;
  20808. }
  20809. }
  20810. // Linked meshes.
  20811. for (let i = 0, n = this.linkedMeshes.length; i < n; i++) {
  20812. let linkedMesh = this.linkedMeshes[i];
  20813. let skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  20814. if (skin == null) throw new Error("Skin not found: " + linkedMesh.skin);
  20815. let parent = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  20816. if (parent == null) throw new Error("Parent mesh not found: " + linkedMesh.parent);
  20817. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent : linkedMesh.mesh;
  20818. linkedMesh.mesh.setParentMesh( parent);
  20819. // linkedMesh.mesh.updateUVs();
  20820. }
  20821. this.linkedMeshes.length = 0;
  20822. // Events.
  20823. if (root.events) {
  20824. for (let eventName in root.events) {
  20825. let eventMap = root.events[eventName];
  20826. let data = new EventData$2(eventName);
  20827. data.intValue = this.getValue(eventMap, "int", 0);
  20828. data.floatValue = this.getValue(eventMap, "float", 0);
  20829. data.stringValue = this.getValue(eventMap, "string", "");
  20830. data.audioPath = this.getValue(eventMap, "audio", null);
  20831. if (data.audioPath != null) {
  20832. data.volume = this.getValue(eventMap, "volume", 1);
  20833. data.balance = this.getValue(eventMap, "balance", 0);
  20834. }
  20835. skeletonData.events.push(data);
  20836. }
  20837. }
  20838. // Animations.
  20839. if (root.animations) {
  20840. for (let animationName in root.animations) {
  20841. let animationMap = root.animations[animationName];
  20842. this.readAnimation(animationMap, animationName, skeletonData);
  20843. }
  20844. }
  20845. return skeletonData;
  20846. }
  20847. readAttachment (map, skin, slotIndex, name, skeletonData) {
  20848. let scale = this.scale;
  20849. name = this.getValue(map, "name", name);
  20850. switch (this.getValue(map, "type", "region")) {
  20851. case "region": {
  20852. let path = this.getValue(map, "path", name);
  20853. let region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  20854. if (region == null) return null;
  20855. region.path = path;
  20856. region.x = this.getValue(map, "x", 0) * scale;
  20857. region.y = this.getValue(map, "y", 0) * scale;
  20858. region.scaleX = this.getValue(map, "scaleX", 1);
  20859. region.scaleY = this.getValue(map, "scaleY", 1);
  20860. region.rotation = this.getValue(map, "rotation", 0);
  20861. region.width = map.width * scale;
  20862. region.height = map.height * scale;
  20863. let color = this.getValue(map, "color", null);
  20864. if (color != null) region.color.setFromString(color);
  20865. // region.updateOffset();
  20866. return region;
  20867. }
  20868. case "boundingbox": {
  20869. let box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  20870. if (box == null) return null;
  20871. this.readVertices(map, box, map.vertexCount << 1);
  20872. let color = this.getValue(map, "color", null);
  20873. if (color != null) box.color.setFromString(color);
  20874. return box;
  20875. }
  20876. case "mesh":
  20877. case "linkedmesh": {
  20878. let path = this.getValue(map, "path", name);
  20879. let mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  20880. if (mesh == null) return null;
  20881. mesh.path = path;
  20882. let color = this.getValue(map, "color", null);
  20883. if (color != null) mesh.color.setFromString(color);
  20884. mesh.width = this.getValue(map, "width", 0) * scale;
  20885. mesh.height = this.getValue(map, "height", 0) * scale;
  20886. let parent = this.getValue(map, "parent", null);
  20887. if (parent != null) {
  20888. this.linkedMeshes.push(new LinkedMesh$1$1(mesh, this.getValue(map, "skin", null), slotIndex, parent, this.getValue(map, "deform", true)));
  20889. return mesh;
  20890. }
  20891. let uvs = map.uvs;
  20892. this.readVertices(map, mesh, uvs.length);
  20893. mesh.triangles = map.triangles;
  20894. mesh.regionUVs = new Float32Array(uvs);
  20895. // mesh.updateUVs();
  20896. mesh.edges = this.getValue(map, "edges", null);
  20897. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  20898. return mesh;
  20899. }
  20900. case "path": {
  20901. let path = this.attachmentLoader.newPathAttachment(skin, name);
  20902. if (path == null) return null;
  20903. path.closed = this.getValue(map, "closed", false);
  20904. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  20905. let vertexCount = map.vertexCount;
  20906. this.readVertices(map, path, vertexCount << 1);
  20907. let lengths = Utils.newArray(vertexCount / 3, 0);
  20908. for (let i = 0; i < map.lengths.length; i++)
  20909. lengths[i] = map.lengths[i] * scale;
  20910. path.lengths = lengths;
  20911. let color = this.getValue(map, "color", null);
  20912. if (color != null) path.color.setFromString(color);
  20913. return path;
  20914. }
  20915. case "point": {
  20916. let point = this.attachmentLoader.newPointAttachment(skin, name);
  20917. if (point == null) return null;
  20918. point.x = this.getValue(map, "x", 0) * scale;
  20919. point.y = this.getValue(map, "y", 0) * scale;
  20920. point.rotation = this.getValue(map, "rotation", 0);
  20921. let color = this.getValue(map, "color", null);
  20922. if (color != null) point.color.setFromString(color);
  20923. return point;
  20924. }
  20925. case "clipping": {
  20926. let clip = this.attachmentLoader.newClippingAttachment(skin, name);
  20927. if (clip == null) return null;
  20928. let end = this.getValue(map, "end", null);
  20929. if (end != null) {
  20930. let slot = skeletonData.findSlot(end);
  20931. if (slot == null) throw new Error("Clipping end slot not found: " + end);
  20932. clip.endSlot = slot;
  20933. }
  20934. let vertexCount = map.vertexCount;
  20935. this.readVertices(map, clip, vertexCount << 1);
  20936. let color = this.getValue(map, "color", null);
  20937. if (color != null) clip.color.setFromString(color);
  20938. return clip;
  20939. }
  20940. }
  20941. return null;
  20942. }
  20943. readVertices (map, attachment, verticesLength) {
  20944. let scale = this.scale;
  20945. attachment.worldVerticesLength = verticesLength;
  20946. let vertices = map.vertices;
  20947. if (verticesLength == vertices.length) {
  20948. let scaledVertices = Utils.toFloatArray(vertices);
  20949. if (scale != 1) {
  20950. for (let i = 0, n = vertices.length; i < n; i++)
  20951. scaledVertices[i] *= scale;
  20952. }
  20953. attachment.vertices = scaledVertices;
  20954. return;
  20955. }
  20956. let weights = new Array();
  20957. let bones = new Array();
  20958. for (let i = 0, n = vertices.length; i < n;) {
  20959. let boneCount = vertices[i++];
  20960. bones.push(boneCount);
  20961. for (let nn = i + boneCount * 4; i < nn; i += 4) {
  20962. bones.push(vertices[i]);
  20963. weights.push(vertices[i + 1] * scale);
  20964. weights.push(vertices[i + 2] * scale);
  20965. weights.push(vertices[i + 3]);
  20966. }
  20967. }
  20968. attachment.bones = bones;
  20969. attachment.vertices = Utils.toFloatArray(weights);
  20970. }
  20971. readAnimation (map, name, skeletonData) {
  20972. let scale = this.scale;
  20973. let timelines = new Array();
  20974. // Slot timelines.
  20975. if (map.slots) {
  20976. for (let slotName in map.slots) {
  20977. let slotMap = map.slots[slotName];
  20978. let slotIndex = skeletonData.findSlotIndex(slotName);
  20979. if (slotIndex == -1) throw new Error("Slot not found: " + slotName);
  20980. for (let timelineName in slotMap) {
  20981. let timelineMap = slotMap[timelineName];
  20982. if (!timelineMap) continue;
  20983. if (timelineName == "attachment") {
  20984. let timeline = new AttachmentTimeline$2(timelineMap.length, slotIndex);
  20985. for (let frame = 0; frame < timelineMap.length; frame++) {
  20986. let keyMap = timelineMap[frame];
  20987. timeline.setFrame(frame, this.getValue(keyMap, "time", 0), keyMap.name);
  20988. }
  20989. timelines.push(timeline);
  20990. } else if (timelineName == "rgba") {
  20991. let timeline = new RGBATimeline(timelineMap.length, timelineMap.length << 2, slotIndex);
  20992. let keyMap = timelineMap[0];
  20993. let time = this.getValue(keyMap, "time", 0);
  20994. let color = new Color().setFromString(keyMap.color);
  20995. for (let frame = 0, bezier = 0;; frame++) {
  20996. timeline.setFrame(frame, time, color.r, color.g, color.b, color.a);
  20997. if (timelineMap.length == frame + 1) {
  20998. break;
  20999. }
  21000. let nextMap = timelineMap[frame + 1];
  21001. let time2 = this.getValue(nextMap, "time", 0);
  21002. let newColor = new Color().setFromString(nextMap.color);
  21003. let curve = keyMap.curve;
  21004. if (curve) {
  21005. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  21006. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  21007. bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  21008. bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1);
  21009. }
  21010. time = time2;
  21011. color = newColor;
  21012. keyMap = nextMap;
  21013. }
  21014. timelines.push(timeline);
  21015. } else if (timelineName == "rgb") {
  21016. let timeline = new RGBTimeline(timelineMap.length, timelineMap.length * 3, slotIndex);
  21017. let keyMap = timelineMap[0];
  21018. let time = this.getValue(keyMap, "time", 0);
  21019. let color = new Color().setFromString(keyMap.color);
  21020. for (let frame = 0, bezier = 0;; frame++) {
  21021. timeline.setFrame(frame, time, color.r, color.g, color.b);
  21022. if (timelineMap.length == frame + 1) {
  21023. break;
  21024. }
  21025. let nextMap = timelineMap[frame + 1];
  21026. let time2 = this.getValue(nextMap, "time", 0);
  21027. let newColor = new Color().setFromString(nextMap.color);
  21028. let curve = keyMap.curve;
  21029. if (curve) {
  21030. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  21031. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  21032. bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  21033. }
  21034. time = time2;
  21035. color = newColor;
  21036. keyMap = nextMap;
  21037. }
  21038. timelines.push(timeline);
  21039. } else if (timelineName == "alpha") {
  21040. timelines.push(this.readTimeline(timelineMap, new AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1));
  21041. } else if (timelineName == "rgba2") {
  21042. let timeline = new RGBA2Timeline(timelineMap.length, timelineMap.length * 7, slotIndex);
  21043. let keyMap = timelineMap[0];
  21044. let time = this.getValue(keyMap, "time", 0);
  21045. let color = new Color().setFromString(keyMap.light);
  21046. let color2 = new Color().setFromString(keyMap.dark);
  21047. for (let frame = 0, bezier = 0;; frame++) {
  21048. timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b);
  21049. if (timelineMap.length == frame + 1) {
  21050. break;
  21051. }
  21052. let nextMap = timelineMap[frame + 1];
  21053. let time2 = this.getValue(nextMap, "time", 0);
  21054. let newColor = new Color().setFromString(nextMap.light);
  21055. let newColor2 = new Color().setFromString(nextMap.dark);
  21056. let curve = keyMap.curve;
  21057. if (curve) {
  21058. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  21059. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  21060. bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  21061. bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1);
  21062. bezier = this.readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1);
  21063. bezier = this.readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1);
  21064. bezier = this.readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1);
  21065. }
  21066. time = time2;
  21067. color = newColor;
  21068. color2 = newColor2;
  21069. keyMap = nextMap;
  21070. }
  21071. timelines.push(timeline);
  21072. } else if (timelineName == "rgb2") {
  21073. let timeline = new RGB2Timeline(timelineMap.length, timelineMap.length * 6, slotIndex);
  21074. let keyMap = timelineMap[0];
  21075. let time = this.getValue(keyMap, "time", 0);
  21076. let color = new Color().setFromString(keyMap.light);
  21077. let color2 = new Color().setFromString(keyMap.dark);
  21078. for (let frame = 0, bezier = 0;; frame++) {
  21079. timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b);
  21080. if (timelineMap.length == frame + 1) {
  21081. break;
  21082. }
  21083. let nextMap = timelineMap[frame + 1];
  21084. let time2 = this.getValue(nextMap, "time", 0);
  21085. let newColor = new Color().setFromString(nextMap.light);
  21086. let newColor2 = new Color().setFromString(nextMap.dark);
  21087. let curve = keyMap.curve;
  21088. if (curve) {
  21089. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  21090. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  21091. bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  21092. bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1);
  21093. bezier = this.readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1);
  21094. bezier = this.readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1);
  21095. }
  21096. time = time2;
  21097. color = newColor;
  21098. color2 = newColor2;
  21099. keyMap = nextMap;
  21100. }
  21101. timelines.push(timeline);
  21102. } else
  21103. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  21104. }
  21105. }
  21106. }
  21107. // Bone timelines.
  21108. if (map.bones) {
  21109. for (let boneName in map.bones) {
  21110. let boneMap = map.bones[boneName];
  21111. let boneIndex = skeletonData.findBoneIndex(boneName);
  21112. if (boneIndex == -1) throw new Error("Bone not found: " + boneName);
  21113. for (let timelineName in boneMap) {
  21114. let timelineMap = boneMap[timelineName];
  21115. if (timelineMap.length == 0) continue;
  21116. if (timelineName === "rotate") {
  21117. timelines.push(this.readTimeline(timelineMap, new RotateTimeline$2(timelineMap.length, timelineMap.length, boneIndex), 0, 1));
  21118. } else if (timelineName === "translate") {
  21119. let timeline = new TranslateTimeline$2(timelineMap.length, timelineMap.length << 1, boneIndex);
  21120. timelines.push(this.readTimeline2(timelineMap, timeline, "x", "y", 0, scale));
  21121. } else if (timelineName === "translatex") {
  21122. let timeline = new TranslateXTimeline(timelineMap.length, timelineMap.length, boneIndex);
  21123. timelines.push(this.readTimeline(timelineMap, timeline, 0, scale));
  21124. } else if (timelineName === "translatey") {
  21125. let timeline = new TranslateYTimeline(timelineMap.length, timelineMap.length, boneIndex);
  21126. timelines.push(this.readTimeline(timelineMap, timeline, 0, scale));
  21127. } else if (timelineName === "scale") {
  21128. let timeline = new ScaleTimeline$2(timelineMap.length, timelineMap.length << 1, boneIndex);
  21129. timelines.push(this.readTimeline2(timelineMap, timeline, "x", "y", 1, 1));
  21130. } else if (timelineName === "scalex") {
  21131. let timeline = new ScaleXTimeline(timelineMap.length, timelineMap.length, boneIndex);
  21132. timelines.push(this.readTimeline(timelineMap, timeline, 1, 1));
  21133. } else if (timelineName === "scaley") {
  21134. let timeline = new ScaleYTimeline(timelineMap.length, timelineMap.length, boneIndex);
  21135. timelines.push(this.readTimeline(timelineMap, timeline, 1, 1));
  21136. } else if (timelineName === "shear") {
  21137. let timeline = new ShearTimeline$2(timelineMap.length, timelineMap.length << 1, boneIndex);
  21138. timelines.push(this.readTimeline2(timelineMap, timeline, "x", "y", 0, 1));
  21139. } else if (timelineName === "shearx") {
  21140. let timeline = new ShearXTimeline(timelineMap.length, timelineMap.length, boneIndex);
  21141. timelines.push(this.readTimeline(timelineMap, timeline, 0, 1));
  21142. } else if (timelineName === "sheary") {
  21143. let timeline = new ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex);
  21144. timelines.push(this.readTimeline(timelineMap, timeline, 0, 1));
  21145. } else {
  21146. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  21147. }
  21148. }
  21149. }
  21150. }
  21151. // IK constraint timelines.
  21152. if (map.ik) {
  21153. for (let constraintName in map.ik) {
  21154. let constraintMap = map.ik[constraintName];
  21155. let keyMap = constraintMap[0];
  21156. if (!keyMap) continue;
  21157. let constraint = skeletonData.findIkConstraint(constraintName);
  21158. let constraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  21159. let timeline = new IkConstraintTimeline$2(constraintMap.length, constraintMap.length << 1, constraintIndex);
  21160. let time = this.getValue(keyMap, "time", 0);
  21161. let mix = this.getValue(keyMap, "mix", 1);
  21162. let softness = this.getValue(keyMap, "softness", 0) * scale;
  21163. for (let frame = 0, bezier = 0;; frame++) {
  21164. timeline.setFrame(frame, time, mix, softness, this.getValue(keyMap, "bendPositive", true) ? 1 : -1, this.getValue(keyMap, "compress", false), this.getValue(keyMap, "stretch", false));
  21165. let nextMap = constraintMap[frame + 1];
  21166. if (!nextMap) {
  21167. break;
  21168. }
  21169. let time2 = this.getValue(nextMap, "time", 0);
  21170. let mix2 = this.getValue(nextMap, "mix", 1);
  21171. let softness2 = this.getValue(nextMap, "softness", 0) * scale;
  21172. let curve = keyMap.curve;
  21173. if (curve) {
  21174. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1);
  21175. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, scale);
  21176. }
  21177. time = time2;
  21178. mix = mix2;
  21179. softness = softness2;
  21180. keyMap = nextMap;
  21181. }
  21182. timelines.push(timeline);
  21183. }
  21184. }
  21185. // Transform constraint timelines.
  21186. if (map.transform) {
  21187. for (let constraintName in map.transform) {
  21188. let timelineMap = map.transform[constraintName];
  21189. let keyMap = timelineMap[0];
  21190. if (!keyMap) continue;
  21191. let constraint = skeletonData.findTransformConstraint(constraintName);
  21192. let constraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  21193. let timeline = new TransformConstraintTimeline$2(timelineMap.length, timelineMap.length << 2, constraintIndex);
  21194. let time = this.getValue(keyMap, "time", 0);
  21195. let mixRotate = this.getValue(keyMap, "mixRotate", 1);
  21196. let mixShearY = this.getValue(keyMap, "mixShearY", 1);
  21197. let mixX = this.getValue(keyMap, "mixX", 1);
  21198. let mixY = this.getValue(keyMap, "mixY", mixX);
  21199. let mixScaleX = this.getValue(keyMap, "mixScaleX", 1);
  21200. let mixScaleY = this.getValue(keyMap, "mixScaleY", mixScaleX);
  21201. for (let frame = 0, bezier = 0;; frame++) {
  21202. timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
  21203. let nextMap = timelineMap[frame + 1];
  21204. if (!nextMap) {
  21205. break;
  21206. }
  21207. let time2 = this.getValue(nextMap, "time", 0);
  21208. let mixRotate2 = this.getValue(nextMap, "mixRotate", 1);
  21209. let mixShearY2 = this.getValue(nextMap, "mixShearY", 1);
  21210. let mixX2 = this.getValue(nextMap, "mixX", 1);
  21211. let mixY2 = this.getValue(nextMap, "mixY", mixX2);
  21212. let mixScaleX2 = this.getValue(nextMap, "mixScaleX", 1);
  21213. let mixScaleY2 = this.getValue(nextMap, "mixScaleY", mixScaleX2);
  21214. let curve = keyMap.curve;
  21215. if (curve) {
  21216. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  21217. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1);
  21218. bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1);
  21219. bezier = this.readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
  21220. bezier = this.readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
  21221. bezier = this.readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1);
  21222. }
  21223. time = time2;
  21224. mixRotate = mixRotate2;
  21225. mixX = mixX2;
  21226. mixY = mixY2;
  21227. mixScaleX = mixScaleX2;
  21228. mixScaleY = mixScaleY2;
  21229. mixScaleX = mixScaleX2;
  21230. keyMap = nextMap;
  21231. }
  21232. timelines.push(timeline);
  21233. }
  21234. }
  21235. // Path constraint timelines.
  21236. if (map.path) {
  21237. for (let constraintName in map.path) {
  21238. let constraintMap = map.path[constraintName];
  21239. let index = skeletonData.findPathConstraintIndex(constraintName);
  21240. if (index == -1) throw new Error("Path constraint not found: " + constraintName);
  21241. let data = skeletonData.pathConstraints[index];
  21242. for (let timelineName in constraintMap) {
  21243. let timelineMap = constraintMap[timelineName];
  21244. let keyMap = timelineMap[0];
  21245. if (!keyMap) continue;
  21246. if (timelineName === "position") {
  21247. let timeline = new PathConstraintPositionTimeline$2(timelineMap.length, timelineMap.length, index);
  21248. timelines.push(this.readTimeline(timelineMap, timeline, 0, data.positionMode == PositionMode$2.Fixed ? scale : 1));
  21249. } else if (timelineName === "spacing") {
  21250. let timeline = new PathConstraintSpacingTimeline$2(timelineMap.length, timelineMap.length, index);
  21251. timelines.push(this.readTimeline(timelineMap, timeline, 0, data.spacingMode == SpacingMode$2.Length || data.spacingMode == SpacingMode$2.Fixed ? scale : 1));
  21252. } else if (timelineName === "mix") {
  21253. let timeline = new PathConstraintMixTimeline$2(timelineMap.size, timelineMap.size * 3, index);
  21254. let time = this.getValue(keyMap, "time", 0);
  21255. let mixRotate = this.getValue(keyMap, "mixRotate", 1);
  21256. let mixX = this.getValue(keyMap, "mixX", 1);
  21257. let mixY = this.getValue(keyMap, "mixY", mixX);
  21258. for (let frame = 0, bezier = 0;; frame++) {
  21259. timeline.setFrame(frame, time, mixRotate, mixX, mixY);
  21260. let nextMap = timelineMap[frame + 1];
  21261. if (!nextMap) {
  21262. break;
  21263. }
  21264. let time2 = this.getValue(nextMap, "time", 0);
  21265. let mixRotate2 = this.getValue(nextMap, "mixRotate", 1);
  21266. let mixX2 = this.getValue(nextMap, "mixX", 1);
  21267. let mixY2 = this.getValue(nextMap, "mixY", mixX2);
  21268. let curve = keyMap.curve;
  21269. if (curve != null) {
  21270. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  21271. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1);
  21272. bezier = this.readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1);
  21273. }
  21274. time = time2;
  21275. mixRotate = mixRotate2;
  21276. mixX = mixX2;
  21277. mixY = mixY2;
  21278. keyMap = nextMap;
  21279. }
  21280. timelines.push(timeline);
  21281. }
  21282. }
  21283. }
  21284. }
  21285. // Deform timelines.
  21286. if (map.deform) {
  21287. for (let deformName in map.deform) {
  21288. let deformMap = map.deform[deformName];
  21289. let skin = skeletonData.findSkin(deformName);
  21290. if (skin == null) {
  21291. if (settings.FAIL_ON_NON_EXISTING_SKIN) {
  21292. throw new Error("Skin not found: " + deformName);
  21293. } else {
  21294. continue;
  21295. }
  21296. }
  21297. for (let slotName in deformMap) {
  21298. let slotMap = deformMap[slotName];
  21299. let slotIndex = skeletonData.findSlotIndex(slotName);
  21300. if (slotIndex == -1) throw new Error("Slot not found: " + slotMap.name);
  21301. for (let timelineName in slotMap) {
  21302. let timelineMap = slotMap[timelineName];
  21303. let keyMap = timelineMap[0];
  21304. if (!keyMap) continue;
  21305. let attachment = skin.getAttachment(slotIndex, timelineName);
  21306. if (attachment == null) throw new Error("Deform attachment not found: " + timelineMap.name);
  21307. let weighted = attachment.bones != null;
  21308. let vertices = attachment.vertices;
  21309. let deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  21310. let timeline = new DeformTimeline$2(timelineMap.length, timelineMap.length, slotIndex, attachment);
  21311. let time = this.getValue(keyMap, "time", 0);
  21312. for (let frame = 0, bezier = 0;; frame++) {
  21313. let deform;
  21314. let verticesValue = this.getValue(keyMap, "vertices", null);
  21315. if (verticesValue == null)
  21316. deform = weighted ? Utils.newFloatArray(deformLength) : vertices;
  21317. else {
  21318. deform = Utils.newFloatArray(deformLength);
  21319. let start = this.getValue(keyMap, "offset", 0);
  21320. Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  21321. if (scale != 1) {
  21322. for (let i = start, n = i + verticesValue.length; i < n; i++)
  21323. deform[i] *= scale;
  21324. }
  21325. if (!weighted) {
  21326. for (let i = 0; i < deformLength; i++)
  21327. deform[i] += vertices[i];
  21328. }
  21329. }
  21330. timeline.setFrame(frame, time, deform);
  21331. let nextMap = timelineMap[frame + 1];
  21332. if (!nextMap) {
  21333. break;
  21334. }
  21335. let time2 = this.getValue(nextMap, "time", 0);
  21336. let curve = keyMap.curve;
  21337. if (curve) {
  21338. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
  21339. }
  21340. time = time2;
  21341. keyMap = nextMap;
  21342. }
  21343. timelines.push(timeline);
  21344. }
  21345. }
  21346. }
  21347. }
  21348. // Draw order timeline.
  21349. let drawOrderNode = map.drawOrder;
  21350. if (drawOrderNode == null) drawOrderNode = map.draworder;
  21351. if (drawOrderNode != null) {
  21352. let timeline = new DrawOrderTimeline$2(drawOrderNode.length);
  21353. let slotCount = skeletonData.slots.length;
  21354. let frame = 0;
  21355. for (let j = 0; j < drawOrderNode.length; j++, frame++) {
  21356. let drawOrderMap = drawOrderNode[j];
  21357. let drawOrder = null;
  21358. let offsets = this.getValue(drawOrderMap, "offsets", null);
  21359. if (offsets != null) {
  21360. drawOrder = Utils.newArray(slotCount, -1);
  21361. let unchanged = Utils.newArray(slotCount - offsets.length, 0);
  21362. let originalIndex = 0, unchangedIndex = 0;
  21363. for (let i = 0; i < offsets.length; i++) {
  21364. let offsetMap = offsets[i];
  21365. let slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  21366. if (slotIndex == -1) throw new Error("Slot not found: " + offsetMap.slot);
  21367. // Collect unchanged items.
  21368. while (originalIndex != slotIndex)
  21369. unchanged[unchangedIndex++] = originalIndex++;
  21370. // Set changed items.
  21371. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  21372. }
  21373. // Collect remaining unchanged items.
  21374. while (originalIndex < slotCount)
  21375. unchanged[unchangedIndex++] = originalIndex++;
  21376. // Fill in unchanged items.
  21377. for (let i = slotCount - 1; i >= 0; i--)
  21378. if (drawOrder[i] == -1) drawOrder[i] = unchanged[--unchangedIndex];
  21379. }
  21380. timeline.setFrame(frame, this.getValue(drawOrderMap, "time", 0), drawOrder);
  21381. }
  21382. timelines.push(timeline);
  21383. }
  21384. // Event timeline.
  21385. if (map.events) {
  21386. let timeline = new EventTimeline$2(map.events.length);
  21387. let frame = 0;
  21388. for (let i = 0; i < map.events.length; i++, frame++) {
  21389. let eventMap = map.events[i];
  21390. let eventData = skeletonData.findEvent(eventMap.name);
  21391. if (eventData == null) throw new Error("Event not found: " + eventMap.name);
  21392. let event = new Event$2(Utils.toSinglePrecision(this.getValue(eventMap, "time", 0)), eventData);
  21393. event.intValue = this.getValue(eventMap, "int", eventData.intValue);
  21394. event.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  21395. event.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  21396. if (event.data.audioPath != null) {
  21397. event.volume = this.getValue(eventMap, "volume", 1);
  21398. event.balance = this.getValue(eventMap, "balance", 0);
  21399. }
  21400. timeline.setFrame(frame, event);
  21401. }
  21402. timelines.push(timeline);
  21403. }
  21404. let duration = 0;
  21405. for (let i = 0, n = timelines.length; i < n; i++)
  21406. duration = Math.max(duration, (timelines[i]).getDuration());
  21407. if (isNaN(duration)) {
  21408. throw new Error("Error while parsing animation, duration is NaN");
  21409. }
  21410. skeletonData.animations.push(new Animation$2(name, timelines, duration));
  21411. }
  21412. readTimeline (keys, timeline, defaultValue, scale) {
  21413. let keyMap = keys[0];
  21414. let time = this.getValue(keyMap, "time", 0);
  21415. let value = this.getValue(keyMap, "value", defaultValue) * scale;
  21416. let bezier = 0;
  21417. for (let frame = 0;; frame++) {
  21418. timeline.setFrame(frame, time, value);
  21419. let nextMap = keys[frame + 1];
  21420. if (!nextMap) break;
  21421. let time2 = this.getValue(nextMap, "time", 0);
  21422. let value2 = this.getValue(nextMap, "value", defaultValue) * scale;
  21423. let curve = keyMap.curve;
  21424. if (curve) bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, value, value2, scale);
  21425. time = time2;
  21426. value = value2;
  21427. keyMap = nextMap;
  21428. }
  21429. return timeline;
  21430. }
  21431. readTimeline2 (keys, timeline, name1, name2, defaultValue, scale) {
  21432. let keyMap = keys[0];
  21433. let time = this.getValue(keyMap, "time", 0);
  21434. let value1 = this.getValue(keyMap, name1, defaultValue) * scale;
  21435. let value2 = this.getValue(keyMap, name2, defaultValue) * scale;
  21436. let bezier = 0;
  21437. for (let frame = 0;; frame++) {
  21438. timeline.setFrame(frame, time, value1, value2);
  21439. let nextMap = keys[frame + 1];
  21440. if (!nextMap) break;
  21441. let time2 = this.getValue(nextMap, "time", 0);
  21442. let nvalue1 = this.getValue(nextMap, name1, defaultValue) * scale;
  21443. let nvalue2 = this.getValue(nextMap, name2, defaultValue) * scale;
  21444. let curve = keyMap.curve;
  21445. if (curve != null) {
  21446. bezier = this.readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale);
  21447. bezier = this.readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale);
  21448. }
  21449. time = time2;
  21450. value1 = nvalue1;
  21451. value2 = nvalue2;
  21452. keyMap = nextMap;
  21453. }
  21454. timeline.shrink(bezier);
  21455. return timeline;
  21456. }
  21457. readCurve (curve, timeline, bezier, frame, value, time1, time2,
  21458. value1, value2, scale) {
  21459. if (curve == "stepped") {
  21460. if (value != 0) timeline.setStepped(frame);
  21461. } else {
  21462. let i = value << 2;
  21463. let cx1 = curve[i++];
  21464. let cy1 = curve[i++] * scale;
  21465. let cx2 = curve[i++];
  21466. let cy2 = curve[i++] * scale;
  21467. this.setBezier(timeline, frame, value, bezier++, time1, value1, cx1, cy1, cx2, cy2, time2, value2);
  21468. }
  21469. return bezier;
  21470. }
  21471. setBezier (timeline, frame, value, bezier, time1, value1, cx1, cy1,
  21472. cx2, cy2, time2, value2) {
  21473. timeline.setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2);
  21474. }
  21475. getValue (map, prop, defaultValue) {
  21476. return map[prop] !== undefined ? map[prop] : defaultValue;
  21477. }
  21478. static blendModeFromString (str) {
  21479. str = str.toLowerCase();
  21480. if (str == "normal") return constants.BLEND_MODES.NORMAL;
  21481. if (str == "additive") return constants.BLEND_MODES.ADD;
  21482. if (str == "multiply") return constants.BLEND_MODES.MULTIPLY;
  21483. if (str == "screen") return constants.BLEND_MODES.SCREEN;
  21484. throw new Error(`Unknown blend mode: ${str}`);
  21485. }
  21486. static positionModeFromString (str) {
  21487. str = str.toLowerCase();
  21488. if (str == "fixed") return PositionMode$2.Fixed;
  21489. if (str == "percent") return PositionMode$2.Percent;
  21490. throw new Error(`Unknown position mode: ${str}`);
  21491. }
  21492. static spacingModeFromString (str) {
  21493. str = str.toLowerCase();
  21494. if (str == "length") return SpacingMode$2.Length;
  21495. if (str == "fixed") return SpacingMode$2.Fixed;
  21496. if (str == "percent") return SpacingMode$2.Percent;
  21497. if (str == "proportional") return SpacingMode$2.Proportional;
  21498. throw new Error(`Unknown spacing mode: ${str}`);
  21499. }
  21500. static rotateModeFromString (str) {
  21501. str = str.toLowerCase();
  21502. if (str == "tangent") return RotateMode$2.Tangent;
  21503. if (str == "chain") return RotateMode$2.Chain;
  21504. if (str == "chainscale") return RotateMode$2.ChainScale;
  21505. throw new Error(`Unknown rotate mode: ${str}`);
  21506. }
  21507. static transformModeFromString(str) {
  21508. str = str.toLowerCase();
  21509. if (str == "normal") return TransformMode$2.Normal;
  21510. if (str == "onlytranslation") return TransformMode$2.OnlyTranslation;
  21511. if (str == "norotationorreflection") return TransformMode$2.NoRotationOrReflection;
  21512. if (str == "noscale") return TransformMode$2.NoScale;
  21513. if (str == "noscaleorreflection") return TransformMode$2.NoScaleOrReflection;
  21514. throw new Error(`Unknown transform mode: ${str}`);
  21515. }
  21516. }
  21517. class LinkedMesh$1$1 {
  21518. constructor (mesh, skin, slotIndex, parent, inheritDeform) {
  21519. this.mesh = mesh;
  21520. this.skin = skin;
  21521. this.slotIndex = slotIndex;
  21522. this.parent = parent;
  21523. this.inheritDeform = inheritDeform;
  21524. }
  21525. }
  21526. /**
  21527. * @public
  21528. */
  21529. class Spine$2 extends SpineBase {
  21530. createSkeleton(spineData) {
  21531. this.skeleton = new Skeleton$2(spineData);
  21532. this.skeleton.updateWorldTransform();
  21533. this.stateData = new AnimationStateData$2(spineData);
  21534. this.state = new AnimationState$2(this.stateData);
  21535. }
  21536. }
  21537. var spine40 = /*#__PURE__*/Object.freeze({
  21538. __proto__: null,
  21539. AlphaTimeline: AlphaTimeline,
  21540. Animation: Animation$2,
  21541. AnimationState: AnimationState$2,
  21542. AnimationStateAdapter: AnimationStateAdapter$1,
  21543. AnimationStateData: AnimationStateData$2,
  21544. AtlasAttachmentLoader: AtlasAttachmentLoader$2,
  21545. Attachment: Attachment$2,
  21546. AttachmentTimeline: AttachmentTimeline$2,
  21547. Bone: Bone$2,
  21548. BoneData: BoneData$2,
  21549. BoundingBoxAttachment: BoundingBoxAttachment$2,
  21550. ClippingAttachment: ClippingAttachment$2,
  21551. ConstraintData: ConstraintData$1,
  21552. CurveTimeline: CurveTimeline$2,
  21553. CurveTimeline1: CurveTimeline1,
  21554. CurveTimeline2: CurveTimeline2,
  21555. DeformTimeline: DeformTimeline$2,
  21556. DrawOrderTimeline: DrawOrderTimeline$2,
  21557. Event: Event$2,
  21558. EventData: EventData$2,
  21559. EventQueue: EventQueue$2,
  21560. EventTimeline: EventTimeline$2,
  21561. get EventType () { return EventType$2; },
  21562. IkConstraint: IkConstraint$2,
  21563. IkConstraintData: IkConstraintData$2,
  21564. IkConstraintTimeline: IkConstraintTimeline$2,
  21565. JitterEffect: JitterEffect$2,
  21566. MeshAttachment: MeshAttachment$2,
  21567. get MixBlend () { return MixBlend$2; },
  21568. get MixDirection () { return MixDirection$2; },
  21569. PathAttachment: PathAttachment$2,
  21570. PathConstraint: PathConstraint$2,
  21571. PathConstraintData: PathConstraintData$2,
  21572. PathConstraintMixTimeline: PathConstraintMixTimeline$2,
  21573. PathConstraintPositionTimeline: PathConstraintPositionTimeline$2,
  21574. PathConstraintSpacingTimeline: PathConstraintSpacingTimeline$2,
  21575. PointAttachment: PointAttachment$2,
  21576. get PositionMode () { return PositionMode$2; },
  21577. get Property () { return Property; },
  21578. RGB2Timeline: RGB2Timeline,
  21579. RGBA2Timeline: RGBA2Timeline,
  21580. RGBATimeline: RGBATimeline,
  21581. RGBTimeline: RGBTimeline,
  21582. RegionAttachment: RegionAttachment$2,
  21583. get RotateMode () { return RotateMode$2; },
  21584. RotateTimeline: RotateTimeline$2,
  21585. ScaleTimeline: ScaleTimeline$2,
  21586. ScaleXTimeline: ScaleXTimeline,
  21587. ScaleYTimeline: ScaleYTimeline,
  21588. ShearTimeline: ShearTimeline$2,
  21589. ShearXTimeline: ShearXTimeline,
  21590. ShearYTimeline: ShearYTimeline,
  21591. Skeleton: Skeleton$2,
  21592. SkeletonBinary: SkeletonBinary$1,
  21593. SkeletonBounds: SkeletonBounds$2,
  21594. SkeletonData: SkeletonData$2,
  21595. SkeletonJson: SkeletonJson$2,
  21596. Skin: Skin$2,
  21597. SkinEntry: SkinEntry$1,
  21598. Slot: Slot$2,
  21599. SlotData: SlotData$2,
  21600. get SpacingMode () { return SpacingMode$2; },
  21601. Spine: Spine$2,
  21602. SwirlEffect: SwirlEffect$2,
  21603. Timeline: Timeline,
  21604. TrackEntry: TrackEntry$2,
  21605. TransformConstraint: TransformConstraint$2,
  21606. TransformConstraintData: TransformConstraintData$2,
  21607. TransformConstraintTimeline: TransformConstraintTimeline$2,
  21608. get TransformMode () { return TransformMode$2; },
  21609. TranslateTimeline: TranslateTimeline$2,
  21610. TranslateXTimeline: TranslateXTimeline,
  21611. TranslateYTimeline: TranslateYTimeline,
  21612. VertexAttachment: VertexAttachment$2
  21613. });
  21614. /* eslint-disable */
  21615. /**
  21616. * @public
  21617. */
  21618. var SPINE_VERSION; (function (SPINE_VERSION) {
  21619. const UNKNOWN = 0; SPINE_VERSION[SPINE_VERSION["UNKNOWN"] = UNKNOWN] = "UNKNOWN";
  21620. const VER37 = 37; SPINE_VERSION[SPINE_VERSION["VER37"] = VER37] = "VER37";
  21621. const VER38 = 38; SPINE_VERSION[SPINE_VERSION["VER38"] = VER38] = "VER38";
  21622. const VER40 = 40; SPINE_VERSION[SPINE_VERSION["VER40"] = VER40] = "VER40";
  21623. })(SPINE_VERSION || (SPINE_VERSION = {}));
  21624. /**
  21625. * @public
  21626. */
  21627. function detectSpineVersion(version) {
  21628. const ver3 = version.substr(0, 3);
  21629. const verNum = Math.floor(+ver3 * 10 + 1e-3);
  21630. if (ver3 === '3.7') {
  21631. return SPINE_VERSION.VER37;
  21632. }
  21633. if (ver3 === '3.8') {
  21634. return SPINE_VERSION.VER38;
  21635. }
  21636. if (ver3 === '4.0') {
  21637. return SPINE_VERSION.VER40;
  21638. }
  21639. // try parse old versions with 3.7
  21640. if (verNum < SPINE_VERSION.VER37) {
  21641. return SPINE_VERSION.VER37;
  21642. }
  21643. return SPINE_VERSION.UNKNOWN;
  21644. }
  21645. class UniBinaryParser {constructor() { UniBinaryParser.prototype.__init.call(this); }
  21646. __init() {this.scale = 1;}
  21647. readSkeletonData(atlas, dataToParse) {
  21648. let input = new BinaryInput(dataToParse);
  21649. input.readString();
  21650. let version = input.readString();
  21651. let ver = detectSpineVersion(version);
  21652. let parser = null;
  21653. if (ver === SPINE_VERSION.VER38) {
  21654. parser = new SkeletonBinary(new AtlasAttachmentLoader(atlas));
  21655. }
  21656. input = new BinaryInput(dataToParse);
  21657. input.readInt32();
  21658. input.readInt32();
  21659. version = input.readString();
  21660. ver = detectSpineVersion(version);
  21661. if (ver === SPINE_VERSION.VER40) {
  21662. parser = new SkeletonBinary$1(new AtlasAttachmentLoader$2(atlas));
  21663. }
  21664. if (!parser) {
  21665. let error = `Unsupported version of spine model ${version}, please update pixi-spine`;
  21666. console.error(error);
  21667. }
  21668. parser.scale = this.scale;
  21669. return parser.readSkeletonData(dataToParse);
  21670. }
  21671. }
  21672. class UniJsonParser {constructor() { UniJsonParser.prototype.__init2.call(this); }
  21673. __init2() {this.scale = 1;}
  21674. readSkeletonData(atlas, dataToParse) {
  21675. const version = dataToParse.skeleton.spine;
  21676. const ver = detectSpineVersion(version);
  21677. let parser = null;
  21678. if (ver === SPINE_VERSION.VER37) {
  21679. parser = new SkeletonJson$1(new AtlasAttachmentLoader$1(atlas));
  21680. }
  21681. if (ver === SPINE_VERSION.VER38) {
  21682. parser = new SkeletonJson(new AtlasAttachmentLoader(atlas));
  21683. }
  21684. if (ver === SPINE_VERSION.VER40) {
  21685. parser = new SkeletonJson$2(new AtlasAttachmentLoader$2(atlas));
  21686. }
  21687. if (!parser) {
  21688. let error = `Unsupported version of spine model ${version}, please update pixi-spine`;
  21689. console.error(error);
  21690. }
  21691. parser.scale = this.scale;
  21692. return parser.readSkeletonData(dataToParse);
  21693. }
  21694. }
  21695. /**
  21696. * @public
  21697. */
  21698. class SpineParser extends AbstractSpineParser {
  21699. createBinaryParser() {
  21700. return new UniBinaryParser();
  21701. }
  21702. createJsonParser() {
  21703. return new UniJsonParser();
  21704. }
  21705. parseData(resource, parser, atlas, dataToParse) {
  21706. const parserCast = parser ;
  21707. resource.spineData = parserCast.readSkeletonData(atlas, dataToParse);
  21708. resource.spineAtlas = atlas;
  21709. }
  21710. static __initStatic() {this.use = new SpineParser().genMiddleware().use;}
  21711. static registerLoaderPlugin() {
  21712. loaders.Loader.registerPlugin(SpineParser);
  21713. }
  21714. } SpineParser.__initStatic();
  21715. /**
  21716. * @public
  21717. */
  21718. class Spine$3 extends SpineBase
  21719. {
  21720. createSkeleton(spineData) {
  21721. const ver = detectSpineVersion(spineData.version);
  21722. let spine = null;
  21723. if (ver === SPINE_VERSION.VER37) {
  21724. spine = spine37;
  21725. }
  21726. if (ver === SPINE_VERSION.VER38) {
  21727. spine = spine38;
  21728. }
  21729. if (ver === SPINE_VERSION.VER40) {
  21730. spine = spine40;
  21731. }
  21732. if (!spine) {
  21733. let error = `Cant detect version of spine model ${spineData.version}`;
  21734. console.error(error);
  21735. }
  21736. this.skeleton = new spine.Skeleton(spineData);
  21737. this.skeleton.updateWorldTransform();
  21738. this.stateData = new spine.AnimationStateData(spineData);
  21739. this.state = new spine.AnimationState(this.stateData);
  21740. }
  21741. }
  21742. SpineParser.registerLoaderPlugin();
  21743. exports.BinaryInput = BinaryInput;
  21744. exports.Color = Color;
  21745. exports.DebugUtils = DebugUtils;
  21746. exports.IntSet = IntSet;
  21747. exports.Interpolation = Interpolation;
  21748. exports.MathUtils = MathUtils;
  21749. exports.Pool = Pool;
  21750. exports.Pow = Pow;
  21751. exports.PowOut = PowOut;
  21752. exports.Spine = Spine$3;
  21753. exports.SpineBase = SpineBase;
  21754. exports.SpineMesh = SpineMesh;
  21755. exports.SpineParser = SpineParser;
  21756. exports.SpineSprite = SpineSprite;
  21757. exports.StringSet = StringSet;
  21758. exports.TextureAtlas = TextureAtlas;
  21759. exports.TextureAtlasPage = TextureAtlasPage;
  21760. exports.TextureAtlasRegion = TextureAtlasRegion;
  21761. exports.TextureRegion = TextureRegion;
  21762. exports.TimeKeeper = TimeKeeper;
  21763. exports.Utils = Utils;
  21764. exports.Vector2 = Vector2;
  21765. exports.WindowedMean = WindowedMean;
  21766. exports.filterFromString = filterFromString;
  21767. exports.settings = settings;
  21768. exports.wrapFromString = wrapFromString;
  21769. Object.defineProperty(exports, '__esModule', { value: true });
  21770. })));
  21771. if (typeof pixi_spine !== 'undefined') { Object.assign(this.PIXI.spine, pixi_spine); }
  21772. //# sourceMappingURL=pixi-spine.umd.js.map