spine-threejs.js 307 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = function (d, b) {
  3. extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return extendStatics(d, b);
  7. };
  8. return function (d, b) {
  9. extendStatics(d, b);
  10. function __() { this.constructor = d; }
  11. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  12. };
  13. })();
  14. var spine;
  15. (function (spine) {
  16. var Animation = (function () {
  17. function Animation(name, timelines, duration) {
  18. if (name == null)
  19. throw new Error("name cannot be null.");
  20. if (timelines == null)
  21. throw new Error("timelines cannot be null.");
  22. this.name = name;
  23. this.timelines = timelines;
  24. this.timelineIds = [];
  25. for (var i = 0; i < timelines.length; i++)
  26. this.timelineIds[timelines[i].getPropertyId()] = true;
  27. this.duration = duration;
  28. }
  29. Animation.prototype.hasTimeline = function (id) {
  30. return this.timelineIds[id] == true;
  31. };
  32. Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
  33. if (skeleton == null)
  34. throw new Error("skeleton cannot be null.");
  35. if (loop && this.duration != 0) {
  36. time %= this.duration;
  37. if (lastTime > 0)
  38. lastTime %= this.duration;
  39. }
  40. var timelines = this.timelines;
  41. for (var i = 0, n = timelines.length; i < n; i++)
  42. timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
  43. };
  44. Animation.binarySearch = function (values, target, step) {
  45. if (step === void 0) { step = 1; }
  46. var low = 0;
  47. var high = values.length / step - 2;
  48. if (high == 0)
  49. return step;
  50. var current = high >>> 1;
  51. while (true) {
  52. if (values[(current + 1) * step] <= target)
  53. low = current + 1;
  54. else
  55. high = current;
  56. if (low == high)
  57. return (low + 1) * step;
  58. current = (low + high) >>> 1;
  59. }
  60. };
  61. Animation.linearSearch = function (values, target, step) {
  62. for (var i = 0, last = values.length - step; i <= last; i += step)
  63. if (values[i] > target)
  64. return i;
  65. return -1;
  66. };
  67. return Animation;
  68. }());
  69. spine.Animation = Animation;
  70. var MixBlend;
  71. (function (MixBlend) {
  72. MixBlend[MixBlend["setup"] = 0] = "setup";
  73. MixBlend[MixBlend["first"] = 1] = "first";
  74. MixBlend[MixBlend["replace"] = 2] = "replace";
  75. MixBlend[MixBlend["add"] = 3] = "add";
  76. })(MixBlend = spine.MixBlend || (spine.MixBlend = {}));
  77. var MixDirection;
  78. (function (MixDirection) {
  79. MixDirection[MixDirection["mixIn"] = 0] = "mixIn";
  80. MixDirection[MixDirection["mixOut"] = 1] = "mixOut";
  81. })(MixDirection = spine.MixDirection || (spine.MixDirection = {}));
  82. var TimelineType;
  83. (function (TimelineType) {
  84. TimelineType[TimelineType["rotate"] = 0] = "rotate";
  85. TimelineType[TimelineType["translate"] = 1] = "translate";
  86. TimelineType[TimelineType["scale"] = 2] = "scale";
  87. TimelineType[TimelineType["shear"] = 3] = "shear";
  88. TimelineType[TimelineType["attachment"] = 4] = "attachment";
  89. TimelineType[TimelineType["color"] = 5] = "color";
  90. TimelineType[TimelineType["deform"] = 6] = "deform";
  91. TimelineType[TimelineType["event"] = 7] = "event";
  92. TimelineType[TimelineType["drawOrder"] = 8] = "drawOrder";
  93. TimelineType[TimelineType["ikConstraint"] = 9] = "ikConstraint";
  94. TimelineType[TimelineType["transformConstraint"] = 10] = "transformConstraint";
  95. TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition";
  96. TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing";
  97. TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix";
  98. TimelineType[TimelineType["twoColor"] = 14] = "twoColor";
  99. })(TimelineType = spine.TimelineType || (spine.TimelineType = {}));
  100. var CurveTimeline = (function () {
  101. function CurveTimeline(frameCount) {
  102. if (frameCount <= 0)
  103. throw new Error("frameCount must be > 0: " + frameCount);
  104. this.curves = spine.Utils.newFloatArray((frameCount - 1) * CurveTimeline.BEZIER_SIZE);
  105. }
  106. CurveTimeline.prototype.getFrameCount = function () {
  107. return this.curves.length / CurveTimeline.BEZIER_SIZE + 1;
  108. };
  109. CurveTimeline.prototype.setLinear = function (frameIndex) {
  110. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.LINEAR;
  111. };
  112. CurveTimeline.prototype.setStepped = function (frameIndex) {
  113. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.STEPPED;
  114. };
  115. CurveTimeline.prototype.getCurveType = function (frameIndex) {
  116. var index = frameIndex * CurveTimeline.BEZIER_SIZE;
  117. if (index == this.curves.length)
  118. return CurveTimeline.LINEAR;
  119. var type = this.curves[index];
  120. if (type == CurveTimeline.LINEAR)
  121. return CurveTimeline.LINEAR;
  122. if (type == CurveTimeline.STEPPED)
  123. return CurveTimeline.STEPPED;
  124. return CurveTimeline.BEZIER;
  125. };
  126. CurveTimeline.prototype.setCurve = function (frameIndex, cx1, cy1, cx2, cy2) {
  127. var tmpx = (-cx1 * 2 + cx2) * 0.03, tmpy = (-cy1 * 2 + cy2) * 0.03;
  128. var dddfx = ((cx1 - cx2) * 3 + 1) * 0.006, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006;
  129. var ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
  130. var dfx = cx1 * 0.3 + tmpx + dddfx * 0.16666667, dfy = cy1 * 0.3 + tmpy + dddfy * 0.16666667;
  131. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  132. var curves = this.curves;
  133. curves[i++] = CurveTimeline.BEZIER;
  134. var x = dfx, y = dfy;
  135. for (var n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  136. curves[i] = x;
  137. curves[i + 1] = y;
  138. dfx += ddfx;
  139. dfy += ddfy;
  140. ddfx += dddfx;
  141. ddfy += dddfy;
  142. x += dfx;
  143. y += dfy;
  144. }
  145. };
  146. CurveTimeline.prototype.getCurvePercent = function (frameIndex, percent) {
  147. percent = spine.MathUtils.clamp(percent, 0, 1);
  148. var curves = this.curves;
  149. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  150. var type = curves[i];
  151. if (type == CurveTimeline.LINEAR)
  152. return percent;
  153. if (type == CurveTimeline.STEPPED)
  154. return 0;
  155. i++;
  156. var x = 0;
  157. for (var start = i, n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  158. x = curves[i];
  159. if (x >= percent) {
  160. var prevX = void 0, prevY = void 0;
  161. if (i == start) {
  162. prevX = 0;
  163. prevY = 0;
  164. }
  165. else {
  166. prevX = curves[i - 2];
  167. prevY = curves[i - 1];
  168. }
  169. return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
  170. }
  171. }
  172. var y = curves[i - 1];
  173. return y + (1 - y) * (percent - x) / (1 - x);
  174. };
  175. CurveTimeline.LINEAR = 0;
  176. CurveTimeline.STEPPED = 1;
  177. CurveTimeline.BEZIER = 2;
  178. CurveTimeline.BEZIER_SIZE = 10 * 2 - 1;
  179. return CurveTimeline;
  180. }());
  181. spine.CurveTimeline = CurveTimeline;
  182. var RotateTimeline = (function (_super) {
  183. __extends(RotateTimeline, _super);
  184. function RotateTimeline(frameCount) {
  185. var _this = _super.call(this, frameCount) || this;
  186. _this.frames = spine.Utils.newFloatArray(frameCount << 1);
  187. return _this;
  188. }
  189. RotateTimeline.prototype.getPropertyId = function () {
  190. return (TimelineType.rotate << 24) + this.boneIndex;
  191. };
  192. RotateTimeline.prototype.setFrame = function (frameIndex, time, degrees) {
  193. frameIndex <<= 1;
  194. this.frames[frameIndex] = time;
  195. this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
  196. };
  197. RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  198. var frames = this.frames;
  199. var bone = skeleton.bones[this.boneIndex];
  200. if (!bone.active)
  201. return;
  202. if (time < frames[0]) {
  203. switch (blend) {
  204. case MixBlend.setup:
  205. bone.rotation = bone.data.rotation;
  206. return;
  207. case MixBlend.first:
  208. var r_1 = bone.data.rotation - bone.rotation;
  209. bone.rotation += (r_1 - (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360) * alpha;
  210. }
  211. return;
  212. }
  213. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
  214. var r_2 = frames[frames.length + RotateTimeline.PREV_ROTATION];
  215. switch (blend) {
  216. case MixBlend.setup:
  217. bone.rotation = bone.data.rotation + r_2 * alpha;
  218. break;
  219. case MixBlend.first:
  220. case MixBlend.replace:
  221. r_2 += bone.data.rotation - bone.rotation;
  222. r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
  223. case MixBlend.add:
  224. bone.rotation += r_2 * alpha;
  225. }
  226. return;
  227. }
  228. var frame = Animation.binarySearch(frames, time, RotateTimeline.ENTRIES);
  229. var prevRotation = frames[frame + RotateTimeline.PREV_ROTATION];
  230. var frameTime = frames[frame];
  231. var percent = this.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
  232. var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
  233. r = prevRotation + (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * percent;
  234. switch (blend) {
  235. case MixBlend.setup:
  236. bone.rotation = bone.data.rotation + (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  237. break;
  238. case MixBlend.first:
  239. case MixBlend.replace:
  240. r += bone.data.rotation - bone.rotation;
  241. case MixBlend.add:
  242. bone.rotation += (r - (16384 - ((16384.499999999996 - r / 360) | 0)) * 360) * alpha;
  243. }
  244. };
  245. RotateTimeline.ENTRIES = 2;
  246. RotateTimeline.PREV_TIME = -2;
  247. RotateTimeline.PREV_ROTATION = -1;
  248. RotateTimeline.ROTATION = 1;
  249. return RotateTimeline;
  250. }(CurveTimeline));
  251. spine.RotateTimeline = RotateTimeline;
  252. var TranslateTimeline = (function (_super) {
  253. __extends(TranslateTimeline, _super);
  254. function TranslateTimeline(frameCount) {
  255. var _this = _super.call(this, frameCount) || this;
  256. _this.frames = spine.Utils.newFloatArray(frameCount * TranslateTimeline.ENTRIES);
  257. return _this;
  258. }
  259. TranslateTimeline.prototype.getPropertyId = function () {
  260. return (TimelineType.translate << 24) + this.boneIndex;
  261. };
  262. TranslateTimeline.prototype.setFrame = function (frameIndex, time, x, y) {
  263. frameIndex *= TranslateTimeline.ENTRIES;
  264. this.frames[frameIndex] = time;
  265. this.frames[frameIndex + TranslateTimeline.X] = x;
  266. this.frames[frameIndex + TranslateTimeline.Y] = y;
  267. };
  268. TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  269. var frames = this.frames;
  270. var bone = skeleton.bones[this.boneIndex];
  271. if (!bone.active)
  272. return;
  273. if (time < frames[0]) {
  274. switch (blend) {
  275. case MixBlend.setup:
  276. bone.x = bone.data.x;
  277. bone.y = bone.data.y;
  278. return;
  279. case MixBlend.first:
  280. bone.x += (bone.data.x - bone.x) * alpha;
  281. bone.y += (bone.data.y - bone.y) * alpha;
  282. }
  283. return;
  284. }
  285. var x = 0, y = 0;
  286. if (time >= frames[frames.length - TranslateTimeline.ENTRIES]) {
  287. x = frames[frames.length + TranslateTimeline.PREV_X];
  288. y = frames[frames.length + TranslateTimeline.PREV_Y];
  289. }
  290. else {
  291. var frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
  292. x = frames[frame + TranslateTimeline.PREV_X];
  293. y = frames[frame + TranslateTimeline.PREV_Y];
  294. var frameTime = frames[frame];
  295. var percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
  296. x += (frames[frame + TranslateTimeline.X] - x) * percent;
  297. y += (frames[frame + TranslateTimeline.Y] - y) * percent;
  298. }
  299. switch (blend) {
  300. case MixBlend.setup:
  301. bone.x = bone.data.x + x * alpha;
  302. bone.y = bone.data.y + y * alpha;
  303. break;
  304. case MixBlend.first:
  305. case MixBlend.replace:
  306. bone.x += (bone.data.x + x - bone.x) * alpha;
  307. bone.y += (bone.data.y + y - bone.y) * alpha;
  308. break;
  309. case MixBlend.add:
  310. bone.x += x * alpha;
  311. bone.y += y * alpha;
  312. }
  313. };
  314. TranslateTimeline.ENTRIES = 3;
  315. TranslateTimeline.PREV_TIME = -3;
  316. TranslateTimeline.PREV_X = -2;
  317. TranslateTimeline.PREV_Y = -1;
  318. TranslateTimeline.X = 1;
  319. TranslateTimeline.Y = 2;
  320. return TranslateTimeline;
  321. }(CurveTimeline));
  322. spine.TranslateTimeline = TranslateTimeline;
  323. var ScaleTimeline = (function (_super) {
  324. __extends(ScaleTimeline, _super);
  325. function ScaleTimeline(frameCount) {
  326. return _super.call(this, frameCount) || this;
  327. }
  328. ScaleTimeline.prototype.getPropertyId = function () {
  329. return (TimelineType.scale << 24) + this.boneIndex;
  330. };
  331. ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  332. var frames = this.frames;
  333. var bone = skeleton.bones[this.boneIndex];
  334. if (!bone.active)
  335. return;
  336. if (time < frames[0]) {
  337. switch (blend) {
  338. case MixBlend.setup:
  339. bone.scaleX = bone.data.scaleX;
  340. bone.scaleY = bone.data.scaleY;
  341. return;
  342. case MixBlend.first:
  343. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  344. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  345. }
  346. return;
  347. }
  348. var x = 0, y = 0;
  349. if (time >= frames[frames.length - ScaleTimeline.ENTRIES]) {
  350. x = frames[frames.length + ScaleTimeline.PREV_X] * bone.data.scaleX;
  351. y = frames[frames.length + ScaleTimeline.PREV_Y] * bone.data.scaleY;
  352. }
  353. else {
  354. var frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
  355. x = frames[frame + ScaleTimeline.PREV_X];
  356. y = frames[frame + ScaleTimeline.PREV_Y];
  357. var frameTime = frames[frame];
  358. var percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
  359. x = (x + (frames[frame + ScaleTimeline.X] - x) * percent) * bone.data.scaleX;
  360. y = (y + (frames[frame + ScaleTimeline.Y] - y) * percent) * bone.data.scaleY;
  361. }
  362. if (alpha == 1) {
  363. if (blend == MixBlend.add) {
  364. bone.scaleX += x - bone.data.scaleX;
  365. bone.scaleY += y - bone.data.scaleY;
  366. }
  367. else {
  368. bone.scaleX = x;
  369. bone.scaleY = y;
  370. }
  371. }
  372. else {
  373. var bx = 0, by = 0;
  374. if (direction == MixDirection.mixOut) {
  375. switch (blend) {
  376. case MixBlend.setup:
  377. bx = bone.data.scaleX;
  378. by = bone.data.scaleY;
  379. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bx) * alpha;
  380. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - by) * alpha;
  381. break;
  382. case MixBlend.first:
  383. case MixBlend.replace:
  384. bx = bone.scaleX;
  385. by = bone.scaleY;
  386. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bx) * alpha;
  387. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - by) * alpha;
  388. break;
  389. case MixBlend.add:
  390. bx = bone.scaleX;
  391. by = bone.scaleY;
  392. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  393. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - bone.data.scaleY) * alpha;
  394. }
  395. }
  396. else {
  397. switch (blend) {
  398. case MixBlend.setup:
  399. bx = Math.abs(bone.data.scaleX) * spine.MathUtils.signum(x);
  400. by = Math.abs(bone.data.scaleY) * spine.MathUtils.signum(y);
  401. bone.scaleX = bx + (x - bx) * alpha;
  402. bone.scaleY = by + (y - by) * alpha;
  403. break;
  404. case MixBlend.first:
  405. case MixBlend.replace:
  406. bx = Math.abs(bone.scaleX) * spine.MathUtils.signum(x);
  407. by = Math.abs(bone.scaleY) * spine.MathUtils.signum(y);
  408. bone.scaleX = bx + (x - bx) * alpha;
  409. bone.scaleY = by + (y - by) * alpha;
  410. break;
  411. case MixBlend.add:
  412. bx = spine.MathUtils.signum(x);
  413. by = spine.MathUtils.signum(y);
  414. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  415. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  416. }
  417. }
  418. }
  419. };
  420. return ScaleTimeline;
  421. }(TranslateTimeline));
  422. spine.ScaleTimeline = ScaleTimeline;
  423. var ShearTimeline = (function (_super) {
  424. __extends(ShearTimeline, _super);
  425. function ShearTimeline(frameCount) {
  426. return _super.call(this, frameCount) || this;
  427. }
  428. ShearTimeline.prototype.getPropertyId = function () {
  429. return (TimelineType.shear << 24) + this.boneIndex;
  430. };
  431. ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  432. var frames = this.frames;
  433. var bone = skeleton.bones[this.boneIndex];
  434. if (!bone.active)
  435. return;
  436. if (time < frames[0]) {
  437. switch (blend) {
  438. case MixBlend.setup:
  439. bone.shearX = bone.data.shearX;
  440. bone.shearY = bone.data.shearY;
  441. return;
  442. case MixBlend.first:
  443. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  444. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  445. }
  446. return;
  447. }
  448. var x = 0, y = 0;
  449. if (time >= frames[frames.length - ShearTimeline.ENTRIES]) {
  450. x = frames[frames.length + ShearTimeline.PREV_X];
  451. y = frames[frames.length + ShearTimeline.PREV_Y];
  452. }
  453. else {
  454. var frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
  455. x = frames[frame + ShearTimeline.PREV_X];
  456. y = frames[frame + ShearTimeline.PREV_Y];
  457. var frameTime = frames[frame];
  458. var percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
  459. x = x + (frames[frame + ShearTimeline.X] - x) * percent;
  460. y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
  461. }
  462. switch (blend) {
  463. case MixBlend.setup:
  464. bone.shearX = bone.data.shearX + x * alpha;
  465. bone.shearY = bone.data.shearY + y * alpha;
  466. break;
  467. case MixBlend.first:
  468. case MixBlend.replace:
  469. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  470. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  471. break;
  472. case MixBlend.add:
  473. bone.shearX += x * alpha;
  474. bone.shearY += y * alpha;
  475. }
  476. };
  477. return ShearTimeline;
  478. }(TranslateTimeline));
  479. spine.ShearTimeline = ShearTimeline;
  480. var ColorTimeline = (function (_super) {
  481. __extends(ColorTimeline, _super);
  482. function ColorTimeline(frameCount) {
  483. var _this = _super.call(this, frameCount) || this;
  484. _this.frames = spine.Utils.newFloatArray(frameCount * ColorTimeline.ENTRIES);
  485. return _this;
  486. }
  487. ColorTimeline.prototype.getPropertyId = function () {
  488. return (TimelineType.color << 24) + this.slotIndex;
  489. };
  490. ColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a) {
  491. frameIndex *= ColorTimeline.ENTRIES;
  492. this.frames[frameIndex] = time;
  493. this.frames[frameIndex + ColorTimeline.R] = r;
  494. this.frames[frameIndex + ColorTimeline.G] = g;
  495. this.frames[frameIndex + ColorTimeline.B] = b;
  496. this.frames[frameIndex + ColorTimeline.A] = a;
  497. };
  498. ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  499. var slot = skeleton.slots[this.slotIndex];
  500. if (!slot.bone.active)
  501. return;
  502. var frames = this.frames;
  503. if (time < frames[0]) {
  504. switch (blend) {
  505. case MixBlend.setup:
  506. slot.color.setFromColor(slot.data.color);
  507. return;
  508. case MixBlend.first:
  509. var color = slot.color, setup = slot.data.color;
  510. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
  511. }
  512. return;
  513. }
  514. var r = 0, g = 0, b = 0, a = 0;
  515. if (time >= frames[frames.length - ColorTimeline.ENTRIES]) {
  516. var i = frames.length;
  517. r = frames[i + ColorTimeline.PREV_R];
  518. g = frames[i + ColorTimeline.PREV_G];
  519. b = frames[i + ColorTimeline.PREV_B];
  520. a = frames[i + ColorTimeline.PREV_A];
  521. }
  522. else {
  523. var frame = Animation.binarySearch(frames, time, ColorTimeline.ENTRIES);
  524. r = frames[frame + ColorTimeline.PREV_R];
  525. g = frames[frame + ColorTimeline.PREV_G];
  526. b = frames[frame + ColorTimeline.PREV_B];
  527. a = frames[frame + ColorTimeline.PREV_A];
  528. var frameTime = frames[frame];
  529. var percent = this.getCurvePercent(frame / ColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ColorTimeline.PREV_TIME] - frameTime));
  530. r += (frames[frame + ColorTimeline.R] - r) * percent;
  531. g += (frames[frame + ColorTimeline.G] - g) * percent;
  532. b += (frames[frame + ColorTimeline.B] - b) * percent;
  533. a += (frames[frame + ColorTimeline.A] - a) * percent;
  534. }
  535. if (alpha == 1)
  536. slot.color.set(r, g, b, a);
  537. else {
  538. var color = slot.color;
  539. if (blend == MixBlend.setup)
  540. color.setFromColor(slot.data.color);
  541. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  542. }
  543. };
  544. ColorTimeline.ENTRIES = 5;
  545. ColorTimeline.PREV_TIME = -5;
  546. ColorTimeline.PREV_R = -4;
  547. ColorTimeline.PREV_G = -3;
  548. ColorTimeline.PREV_B = -2;
  549. ColorTimeline.PREV_A = -1;
  550. ColorTimeline.R = 1;
  551. ColorTimeline.G = 2;
  552. ColorTimeline.B = 3;
  553. ColorTimeline.A = 4;
  554. return ColorTimeline;
  555. }(CurveTimeline));
  556. spine.ColorTimeline = ColorTimeline;
  557. var TwoColorTimeline = (function (_super) {
  558. __extends(TwoColorTimeline, _super);
  559. function TwoColorTimeline(frameCount) {
  560. var _this = _super.call(this, frameCount) || this;
  561. _this.frames = spine.Utils.newFloatArray(frameCount * TwoColorTimeline.ENTRIES);
  562. return _this;
  563. }
  564. TwoColorTimeline.prototype.getPropertyId = function () {
  565. return (TimelineType.twoColor << 24) + this.slotIndex;
  566. };
  567. TwoColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a, r2, g2, b2) {
  568. frameIndex *= TwoColorTimeline.ENTRIES;
  569. this.frames[frameIndex] = time;
  570. this.frames[frameIndex + TwoColorTimeline.R] = r;
  571. this.frames[frameIndex + TwoColorTimeline.G] = g;
  572. this.frames[frameIndex + TwoColorTimeline.B] = b;
  573. this.frames[frameIndex + TwoColorTimeline.A] = a;
  574. this.frames[frameIndex + TwoColorTimeline.R2] = r2;
  575. this.frames[frameIndex + TwoColorTimeline.G2] = g2;
  576. this.frames[frameIndex + TwoColorTimeline.B2] = b2;
  577. };
  578. TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  579. var slot = skeleton.slots[this.slotIndex];
  580. if (!slot.bone.active)
  581. return;
  582. var frames = this.frames;
  583. if (time < frames[0]) {
  584. switch (blend) {
  585. case MixBlend.setup:
  586. slot.color.setFromColor(slot.data.color);
  587. slot.darkColor.setFromColor(slot.data.darkColor);
  588. return;
  589. case MixBlend.first:
  590. var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  591. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
  592. dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
  593. }
  594. return;
  595. }
  596. var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  597. if (time >= frames[frames.length - TwoColorTimeline.ENTRIES]) {
  598. var i = frames.length;
  599. r = frames[i + TwoColorTimeline.PREV_R];
  600. g = frames[i + TwoColorTimeline.PREV_G];
  601. b = frames[i + TwoColorTimeline.PREV_B];
  602. a = frames[i + TwoColorTimeline.PREV_A];
  603. r2 = frames[i + TwoColorTimeline.PREV_R2];
  604. g2 = frames[i + TwoColorTimeline.PREV_G2];
  605. b2 = frames[i + TwoColorTimeline.PREV_B2];
  606. }
  607. else {
  608. var frame = Animation.binarySearch(frames, time, TwoColorTimeline.ENTRIES);
  609. r = frames[frame + TwoColorTimeline.PREV_R];
  610. g = frames[frame + TwoColorTimeline.PREV_G];
  611. b = frames[frame + TwoColorTimeline.PREV_B];
  612. a = frames[frame + TwoColorTimeline.PREV_A];
  613. r2 = frames[frame + TwoColorTimeline.PREV_R2];
  614. g2 = frames[frame + TwoColorTimeline.PREV_G2];
  615. b2 = frames[frame + TwoColorTimeline.PREV_B2];
  616. var frameTime = frames[frame];
  617. var percent = this.getCurvePercent(frame / TwoColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TwoColorTimeline.PREV_TIME] - frameTime));
  618. r += (frames[frame + TwoColorTimeline.R] - r) * percent;
  619. g += (frames[frame + TwoColorTimeline.G] - g) * percent;
  620. b += (frames[frame + TwoColorTimeline.B] - b) * percent;
  621. a += (frames[frame + TwoColorTimeline.A] - a) * percent;
  622. r2 += (frames[frame + TwoColorTimeline.R2] - r2) * percent;
  623. g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
  624. b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
  625. }
  626. if (alpha == 1) {
  627. slot.color.set(r, g, b, a);
  628. slot.darkColor.set(r2, g2, b2, 1);
  629. }
  630. else {
  631. var light = slot.color, dark = slot.darkColor;
  632. if (blend == MixBlend.setup) {
  633. light.setFromColor(slot.data.color);
  634. dark.setFromColor(slot.data.darkColor);
  635. }
  636. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  637. dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
  638. }
  639. };
  640. TwoColorTimeline.ENTRIES = 8;
  641. TwoColorTimeline.PREV_TIME = -8;
  642. TwoColorTimeline.PREV_R = -7;
  643. TwoColorTimeline.PREV_G = -6;
  644. TwoColorTimeline.PREV_B = -5;
  645. TwoColorTimeline.PREV_A = -4;
  646. TwoColorTimeline.PREV_R2 = -3;
  647. TwoColorTimeline.PREV_G2 = -2;
  648. TwoColorTimeline.PREV_B2 = -1;
  649. TwoColorTimeline.R = 1;
  650. TwoColorTimeline.G = 2;
  651. TwoColorTimeline.B = 3;
  652. TwoColorTimeline.A = 4;
  653. TwoColorTimeline.R2 = 5;
  654. TwoColorTimeline.G2 = 6;
  655. TwoColorTimeline.B2 = 7;
  656. return TwoColorTimeline;
  657. }(CurveTimeline));
  658. spine.TwoColorTimeline = TwoColorTimeline;
  659. var AttachmentTimeline = (function () {
  660. function AttachmentTimeline(frameCount) {
  661. this.frames = spine.Utils.newFloatArray(frameCount);
  662. this.attachmentNames = new Array(frameCount);
  663. }
  664. AttachmentTimeline.prototype.getPropertyId = function () {
  665. return (TimelineType.attachment << 24) + this.slotIndex;
  666. };
  667. AttachmentTimeline.prototype.getFrameCount = function () {
  668. return this.frames.length;
  669. };
  670. AttachmentTimeline.prototype.setFrame = function (frameIndex, time, attachmentName) {
  671. this.frames[frameIndex] = time;
  672. this.attachmentNames[frameIndex] = attachmentName;
  673. };
  674. AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  675. var slot = skeleton.slots[this.slotIndex];
  676. if (!slot.bone.active)
  677. return;
  678. if (direction == MixDirection.mixOut) {
  679. if (blend == MixBlend.setup)
  680. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  681. return;
  682. }
  683. var frames = this.frames;
  684. if (time < frames[0]) {
  685. if (blend == MixBlend.setup || blend == MixBlend.first)
  686. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  687. return;
  688. }
  689. var frameIndex = 0;
  690. if (time >= frames[frames.length - 1])
  691. frameIndex = frames.length - 1;
  692. else
  693. frameIndex = Animation.binarySearch(frames, time, 1) - 1;
  694. var attachmentName = this.attachmentNames[frameIndex];
  695. skeleton.slots[this.slotIndex]
  696. .setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  697. };
  698. AttachmentTimeline.prototype.setAttachment = function (skeleton, slot, attachmentName) {
  699. slot.attachment = attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName);
  700. };
  701. return AttachmentTimeline;
  702. }());
  703. spine.AttachmentTimeline = AttachmentTimeline;
  704. var zeros = null;
  705. var DeformTimeline = (function (_super) {
  706. __extends(DeformTimeline, _super);
  707. function DeformTimeline(frameCount) {
  708. var _this = _super.call(this, frameCount) || this;
  709. _this.frames = spine.Utils.newFloatArray(frameCount);
  710. _this.frameVertices = new Array(frameCount);
  711. if (zeros == null)
  712. zeros = spine.Utils.newFloatArray(64);
  713. return _this;
  714. }
  715. DeformTimeline.prototype.getPropertyId = function () {
  716. return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
  717. };
  718. DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
  719. this.frames[frameIndex] = time;
  720. this.frameVertices[frameIndex] = vertices;
  721. };
  722. DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  723. var slot = skeleton.slots[this.slotIndex];
  724. if (!slot.bone.active)
  725. return;
  726. var slotAttachment = slot.getAttachment();
  727. if (!(slotAttachment instanceof spine.VertexAttachment) || !(slotAttachment.deformAttachment == this.attachment))
  728. return;
  729. var deformArray = slot.deform;
  730. if (deformArray.length == 0)
  731. blend = MixBlend.setup;
  732. var frameVertices = this.frameVertices;
  733. var vertexCount = frameVertices[0].length;
  734. var frames = this.frames;
  735. if (time < frames[0]) {
  736. var vertexAttachment = slotAttachment;
  737. switch (blend) {
  738. case MixBlend.setup:
  739. deformArray.length = 0;
  740. return;
  741. case MixBlend.first:
  742. if (alpha == 1) {
  743. deformArray.length = 0;
  744. break;
  745. }
  746. var deform_1 = spine.Utils.setArraySize(deformArray, vertexCount);
  747. if (vertexAttachment.bones == null) {
  748. var setupVertices = vertexAttachment.vertices;
  749. for (var i = 0; i < vertexCount; i++)
  750. deform_1[i] += (setupVertices[i] - deform_1[i]) * alpha;
  751. }
  752. else {
  753. alpha = 1 - alpha;
  754. for (var i = 0; i < vertexCount; i++)
  755. deform_1[i] *= alpha;
  756. }
  757. }
  758. return;
  759. }
  760. var deform = spine.Utils.setArraySize(deformArray, vertexCount);
  761. if (time >= frames[frames.length - 1]) {
  762. var lastVertices = frameVertices[frames.length - 1];
  763. if (alpha == 1) {
  764. if (blend == MixBlend.add) {
  765. var vertexAttachment = slotAttachment;
  766. if (vertexAttachment.bones == null) {
  767. var setupVertices = vertexAttachment.vertices;
  768. for (var i_1 = 0; i_1 < vertexCount; i_1++) {
  769. deform[i_1] += lastVertices[i_1] - setupVertices[i_1];
  770. }
  771. }
  772. else {
  773. for (var i_2 = 0; i_2 < vertexCount; i_2++)
  774. deform[i_2] += lastVertices[i_2];
  775. }
  776. }
  777. else {
  778. spine.Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount);
  779. }
  780. }
  781. else {
  782. switch (blend) {
  783. case MixBlend.setup: {
  784. var vertexAttachment_1 = slotAttachment;
  785. if (vertexAttachment_1.bones == null) {
  786. var setupVertices = vertexAttachment_1.vertices;
  787. for (var i_3 = 0; i_3 < vertexCount; i_3++) {
  788. var setup = setupVertices[i_3];
  789. deform[i_3] = setup + (lastVertices[i_3] - setup) * alpha;
  790. }
  791. }
  792. else {
  793. for (var i_4 = 0; i_4 < vertexCount; i_4++)
  794. deform[i_4] = lastVertices[i_4] * alpha;
  795. }
  796. break;
  797. }
  798. case MixBlend.first:
  799. case MixBlend.replace:
  800. for (var i_5 = 0; i_5 < vertexCount; i_5++)
  801. deform[i_5] += (lastVertices[i_5] - deform[i_5]) * alpha;
  802. break;
  803. case MixBlend.add:
  804. var vertexAttachment = slotAttachment;
  805. if (vertexAttachment.bones == null) {
  806. var setupVertices = vertexAttachment.vertices;
  807. for (var i_6 = 0; i_6 < vertexCount; i_6++) {
  808. deform[i_6] += (lastVertices[i_6] - setupVertices[i_6]) * alpha;
  809. }
  810. }
  811. else {
  812. for (var i_7 = 0; i_7 < vertexCount; i_7++)
  813. deform[i_7] += lastVertices[i_7] * alpha;
  814. }
  815. }
  816. }
  817. return;
  818. }
  819. var frame = Animation.binarySearch(frames, time);
  820. var prevVertices = frameVertices[frame - 1];
  821. var nextVertices = frameVertices[frame];
  822. var frameTime = frames[frame];
  823. var percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
  824. if (alpha == 1) {
  825. if (blend == MixBlend.add) {
  826. var vertexAttachment = slotAttachment;
  827. if (vertexAttachment.bones == null) {
  828. var setupVertices = vertexAttachment.vertices;
  829. for (var i_8 = 0; i_8 < vertexCount; i_8++) {
  830. var prev = prevVertices[i_8];
  831. deform[i_8] += prev + (nextVertices[i_8] - prev) * percent - setupVertices[i_8];
  832. }
  833. }
  834. else {
  835. for (var i_9 = 0; i_9 < vertexCount; i_9++) {
  836. var prev = prevVertices[i_9];
  837. deform[i_9] += prev + (nextVertices[i_9] - prev) * percent;
  838. }
  839. }
  840. }
  841. else {
  842. for (var i_10 = 0; i_10 < vertexCount; i_10++) {
  843. var prev = prevVertices[i_10];
  844. deform[i_10] = prev + (nextVertices[i_10] - prev) * percent;
  845. }
  846. }
  847. }
  848. else {
  849. switch (blend) {
  850. case MixBlend.setup: {
  851. var vertexAttachment_2 = slotAttachment;
  852. if (vertexAttachment_2.bones == null) {
  853. var setupVertices = vertexAttachment_2.vertices;
  854. for (var i_11 = 0; i_11 < vertexCount; i_11++) {
  855. var prev = prevVertices[i_11], setup = setupVertices[i_11];
  856. deform[i_11] = setup + (prev + (nextVertices[i_11] - prev) * percent - setup) * alpha;
  857. }
  858. }
  859. else {
  860. for (var i_12 = 0; i_12 < vertexCount; i_12++) {
  861. var prev = prevVertices[i_12];
  862. deform[i_12] = (prev + (nextVertices[i_12] - prev) * percent) * alpha;
  863. }
  864. }
  865. break;
  866. }
  867. case MixBlend.first:
  868. case MixBlend.replace:
  869. for (var i_13 = 0; i_13 < vertexCount; i_13++) {
  870. var prev = prevVertices[i_13];
  871. deform[i_13] += (prev + (nextVertices[i_13] - prev) * percent - deform[i_13]) * alpha;
  872. }
  873. break;
  874. case MixBlend.add:
  875. var vertexAttachment = slotAttachment;
  876. if (vertexAttachment.bones == null) {
  877. var setupVertices = vertexAttachment.vertices;
  878. for (var i_14 = 0; i_14 < vertexCount; i_14++) {
  879. var prev = prevVertices[i_14];
  880. deform[i_14] += (prev + (nextVertices[i_14] - prev) * percent - setupVertices[i_14]) * alpha;
  881. }
  882. }
  883. else {
  884. for (var i_15 = 0; i_15 < vertexCount; i_15++) {
  885. var prev = prevVertices[i_15];
  886. deform[i_15] += (prev + (nextVertices[i_15] - prev) * percent) * alpha;
  887. }
  888. }
  889. }
  890. }
  891. };
  892. return DeformTimeline;
  893. }(CurveTimeline));
  894. spine.DeformTimeline = DeformTimeline;
  895. var EventTimeline = (function () {
  896. function EventTimeline(frameCount) {
  897. this.frames = spine.Utils.newFloatArray(frameCount);
  898. this.events = new Array(frameCount);
  899. }
  900. EventTimeline.prototype.getPropertyId = function () {
  901. return TimelineType.event << 24;
  902. };
  903. EventTimeline.prototype.getFrameCount = function () {
  904. return this.frames.length;
  905. };
  906. EventTimeline.prototype.setFrame = function (frameIndex, event) {
  907. this.frames[frameIndex] = event.time;
  908. this.events[frameIndex] = event;
  909. };
  910. EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  911. if (firedEvents == null)
  912. return;
  913. var frames = this.frames;
  914. var frameCount = this.frames.length;
  915. if (lastTime > time) {
  916. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction);
  917. lastTime = -1;
  918. }
  919. else if (lastTime >= frames[frameCount - 1])
  920. return;
  921. if (time < frames[0])
  922. return;
  923. var frame = 0;
  924. if (lastTime < frames[0])
  925. frame = 0;
  926. else {
  927. frame = Animation.binarySearch(frames, lastTime);
  928. var frameTime = frames[frame];
  929. while (frame > 0) {
  930. if (frames[frame - 1] != frameTime)
  931. break;
  932. frame--;
  933. }
  934. }
  935. for (; frame < frameCount && time >= frames[frame]; frame++)
  936. firedEvents.push(this.events[frame]);
  937. };
  938. return EventTimeline;
  939. }());
  940. spine.EventTimeline = EventTimeline;
  941. var DrawOrderTimeline = (function () {
  942. function DrawOrderTimeline(frameCount) {
  943. this.frames = spine.Utils.newFloatArray(frameCount);
  944. this.drawOrders = new Array(frameCount);
  945. }
  946. DrawOrderTimeline.prototype.getPropertyId = function () {
  947. return TimelineType.drawOrder << 24;
  948. };
  949. DrawOrderTimeline.prototype.getFrameCount = function () {
  950. return this.frames.length;
  951. };
  952. DrawOrderTimeline.prototype.setFrame = function (frameIndex, time, drawOrder) {
  953. this.frames[frameIndex] = time;
  954. this.drawOrders[frameIndex] = drawOrder;
  955. };
  956. DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  957. var drawOrder = skeleton.drawOrder;
  958. var slots = skeleton.slots;
  959. if (direction == MixDirection.mixOut) {
  960. if (blend == MixBlend.setup)
  961. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  962. return;
  963. }
  964. var frames = this.frames;
  965. if (time < frames[0]) {
  966. if (blend == MixBlend.setup || blend == MixBlend.first)
  967. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  968. return;
  969. }
  970. var frame = 0;
  971. if (time >= frames[frames.length - 1])
  972. frame = frames.length - 1;
  973. else
  974. frame = Animation.binarySearch(frames, time) - 1;
  975. var drawOrderToSetupIndex = this.drawOrders[frame];
  976. if (drawOrderToSetupIndex == null)
  977. spine.Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  978. else {
  979. for (var i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  980. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  981. }
  982. };
  983. return DrawOrderTimeline;
  984. }());
  985. spine.DrawOrderTimeline = DrawOrderTimeline;
  986. var IkConstraintTimeline = (function (_super) {
  987. __extends(IkConstraintTimeline, _super);
  988. function IkConstraintTimeline(frameCount) {
  989. var _this = _super.call(this, frameCount) || this;
  990. _this.frames = spine.Utils.newFloatArray(frameCount * IkConstraintTimeline.ENTRIES);
  991. return _this;
  992. }
  993. IkConstraintTimeline.prototype.getPropertyId = function () {
  994. return (TimelineType.ikConstraint << 24) + this.ikConstraintIndex;
  995. };
  996. IkConstraintTimeline.prototype.setFrame = function (frameIndex, time, mix, softness, bendDirection, compress, stretch) {
  997. frameIndex *= IkConstraintTimeline.ENTRIES;
  998. this.frames[frameIndex] = time;
  999. this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
  1000. this.frames[frameIndex + IkConstraintTimeline.SOFTNESS] = softness;
  1001. this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
  1002. this.frames[frameIndex + IkConstraintTimeline.COMPRESS] = compress ? 1 : 0;
  1003. this.frames[frameIndex + IkConstraintTimeline.STRETCH] = stretch ? 1 : 0;
  1004. };
  1005. IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1006. var frames = this.frames;
  1007. var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  1008. if (!constraint.active)
  1009. return;
  1010. if (time < frames[0]) {
  1011. switch (blend) {
  1012. case MixBlend.setup:
  1013. constraint.mix = constraint.data.mix;
  1014. constraint.softness = constraint.data.softness;
  1015. constraint.bendDirection = constraint.data.bendDirection;
  1016. constraint.compress = constraint.data.compress;
  1017. constraint.stretch = constraint.data.stretch;
  1018. return;
  1019. case MixBlend.first:
  1020. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  1021. constraint.softness += (constraint.data.softness - constraint.softness) * alpha;
  1022. constraint.bendDirection = constraint.data.bendDirection;
  1023. constraint.compress = constraint.data.compress;
  1024. constraint.stretch = constraint.data.stretch;
  1025. }
  1026. return;
  1027. }
  1028. if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
  1029. if (blend == MixBlend.setup) {
  1030. constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
  1031. constraint.softness = constraint.data.softness
  1032. + (frames[frames.length + IkConstraintTimeline.PREV_SOFTNESS] - constraint.data.softness) * alpha;
  1033. if (direction == MixDirection.mixOut) {
  1034. constraint.bendDirection = constraint.data.bendDirection;
  1035. constraint.compress = constraint.data.compress;
  1036. constraint.stretch = constraint.data.stretch;
  1037. }
  1038. else {
  1039. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1040. constraint.compress = frames[frames.length + IkConstraintTimeline.PREV_COMPRESS] != 0;
  1041. constraint.stretch = frames[frames.length + IkConstraintTimeline.PREV_STRETCH] != 0;
  1042. }
  1043. }
  1044. else {
  1045. constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
  1046. constraint.softness += (frames[frames.length + IkConstraintTimeline.PREV_SOFTNESS] - constraint.softness) * alpha;
  1047. if (direction == MixDirection.mixIn) {
  1048. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1049. constraint.compress = frames[frames.length + IkConstraintTimeline.PREV_COMPRESS] != 0;
  1050. constraint.stretch = frames[frames.length + IkConstraintTimeline.PREV_STRETCH] != 0;
  1051. }
  1052. }
  1053. return;
  1054. }
  1055. var frame = Animation.binarySearch(frames, time, IkConstraintTimeline.ENTRIES);
  1056. var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
  1057. var softness = frames[frame + IkConstraintTimeline.PREV_SOFTNESS];
  1058. var frameTime = frames[frame];
  1059. var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
  1060. if (blend == MixBlend.setup) {
  1061. constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha;
  1062. constraint.softness = constraint.data.softness
  1063. + (softness + (frames[frame + IkConstraintTimeline.SOFTNESS] - softness) * percent - constraint.data.softness) * alpha;
  1064. if (direction == MixDirection.mixOut) {
  1065. constraint.bendDirection = constraint.data.bendDirection;
  1066. constraint.compress = constraint.data.compress;
  1067. constraint.stretch = constraint.data.stretch;
  1068. }
  1069. else {
  1070. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1071. constraint.compress = frames[frame + IkConstraintTimeline.PREV_COMPRESS] != 0;
  1072. constraint.stretch = frames[frame + IkConstraintTimeline.PREV_STRETCH] != 0;
  1073. }
  1074. }
  1075. else {
  1076. constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
  1077. constraint.softness += (softness + (frames[frame + IkConstraintTimeline.SOFTNESS] - softness) * percent - constraint.softness) * alpha;
  1078. if (direction == MixDirection.mixIn) {
  1079. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1080. constraint.compress = frames[frame + IkConstraintTimeline.PREV_COMPRESS] != 0;
  1081. constraint.stretch = frames[frame + IkConstraintTimeline.PREV_STRETCH] != 0;
  1082. }
  1083. }
  1084. };
  1085. IkConstraintTimeline.ENTRIES = 6;
  1086. IkConstraintTimeline.PREV_TIME = -6;
  1087. IkConstraintTimeline.PREV_MIX = -5;
  1088. IkConstraintTimeline.PREV_SOFTNESS = -4;
  1089. IkConstraintTimeline.PREV_BEND_DIRECTION = -3;
  1090. IkConstraintTimeline.PREV_COMPRESS = -2;
  1091. IkConstraintTimeline.PREV_STRETCH = -1;
  1092. IkConstraintTimeline.MIX = 1;
  1093. IkConstraintTimeline.SOFTNESS = 2;
  1094. IkConstraintTimeline.BEND_DIRECTION = 3;
  1095. IkConstraintTimeline.COMPRESS = 4;
  1096. IkConstraintTimeline.STRETCH = 5;
  1097. return IkConstraintTimeline;
  1098. }(CurveTimeline));
  1099. spine.IkConstraintTimeline = IkConstraintTimeline;
  1100. var TransformConstraintTimeline = (function (_super) {
  1101. __extends(TransformConstraintTimeline, _super);
  1102. function TransformConstraintTimeline(frameCount) {
  1103. var _this = _super.call(this, frameCount) || this;
  1104. _this.frames = spine.Utils.newFloatArray(frameCount * TransformConstraintTimeline.ENTRIES);
  1105. return _this;
  1106. }
  1107. TransformConstraintTimeline.prototype.getPropertyId = function () {
  1108. return (TimelineType.transformConstraint << 24) + this.transformConstraintIndex;
  1109. };
  1110. TransformConstraintTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix, scaleMix, shearMix) {
  1111. frameIndex *= TransformConstraintTimeline.ENTRIES;
  1112. this.frames[frameIndex] = time;
  1113. this.frames[frameIndex + TransformConstraintTimeline.ROTATE] = rotateMix;
  1114. this.frames[frameIndex + TransformConstraintTimeline.TRANSLATE] = translateMix;
  1115. this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
  1116. this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
  1117. };
  1118. TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1119. var frames = this.frames;
  1120. var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  1121. if (!constraint.active)
  1122. return;
  1123. if (time < frames[0]) {
  1124. var data = constraint.data;
  1125. switch (blend) {
  1126. case MixBlend.setup:
  1127. constraint.rotateMix = data.rotateMix;
  1128. constraint.translateMix = data.translateMix;
  1129. constraint.scaleMix = data.scaleMix;
  1130. constraint.shearMix = data.shearMix;
  1131. return;
  1132. case MixBlend.first:
  1133. constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
  1134. constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
  1135. constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
  1136. constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
  1137. }
  1138. return;
  1139. }
  1140. var rotate = 0, translate = 0, scale = 0, shear = 0;
  1141. if (time >= frames[frames.length - TransformConstraintTimeline.ENTRIES]) {
  1142. var i = frames.length;
  1143. rotate = frames[i + TransformConstraintTimeline.PREV_ROTATE];
  1144. translate = frames[i + TransformConstraintTimeline.PREV_TRANSLATE];
  1145. scale = frames[i + TransformConstraintTimeline.PREV_SCALE];
  1146. shear = frames[i + TransformConstraintTimeline.PREV_SHEAR];
  1147. }
  1148. else {
  1149. var frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
  1150. rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
  1151. translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
  1152. scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
  1153. shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
  1154. var frameTime = frames[frame];
  1155. var percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
  1156. rotate += (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent;
  1157. translate += (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent;
  1158. scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
  1159. shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
  1160. }
  1161. if (blend == MixBlend.setup) {
  1162. var data = constraint.data;
  1163. constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
  1164. constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
  1165. constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
  1166. constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
  1167. }
  1168. else {
  1169. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  1170. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  1171. constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
  1172. constraint.shearMix += (shear - constraint.shearMix) * alpha;
  1173. }
  1174. };
  1175. TransformConstraintTimeline.ENTRIES = 5;
  1176. TransformConstraintTimeline.PREV_TIME = -5;
  1177. TransformConstraintTimeline.PREV_ROTATE = -4;
  1178. TransformConstraintTimeline.PREV_TRANSLATE = -3;
  1179. TransformConstraintTimeline.PREV_SCALE = -2;
  1180. TransformConstraintTimeline.PREV_SHEAR = -1;
  1181. TransformConstraintTimeline.ROTATE = 1;
  1182. TransformConstraintTimeline.TRANSLATE = 2;
  1183. TransformConstraintTimeline.SCALE = 3;
  1184. TransformConstraintTimeline.SHEAR = 4;
  1185. return TransformConstraintTimeline;
  1186. }(CurveTimeline));
  1187. spine.TransformConstraintTimeline = TransformConstraintTimeline;
  1188. var PathConstraintPositionTimeline = (function (_super) {
  1189. __extends(PathConstraintPositionTimeline, _super);
  1190. function PathConstraintPositionTimeline(frameCount) {
  1191. var _this = _super.call(this, frameCount) || this;
  1192. _this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintPositionTimeline.ENTRIES);
  1193. return _this;
  1194. }
  1195. PathConstraintPositionTimeline.prototype.getPropertyId = function () {
  1196. return (TimelineType.pathConstraintPosition << 24) + this.pathConstraintIndex;
  1197. };
  1198. PathConstraintPositionTimeline.prototype.setFrame = function (frameIndex, time, value) {
  1199. frameIndex *= PathConstraintPositionTimeline.ENTRIES;
  1200. this.frames[frameIndex] = time;
  1201. this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
  1202. };
  1203. PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1204. var frames = this.frames;
  1205. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1206. if (!constraint.active)
  1207. return;
  1208. if (time < frames[0]) {
  1209. switch (blend) {
  1210. case MixBlend.setup:
  1211. constraint.position = constraint.data.position;
  1212. return;
  1213. case MixBlend.first:
  1214. constraint.position += (constraint.data.position - constraint.position) * alpha;
  1215. }
  1216. return;
  1217. }
  1218. var position = 0;
  1219. if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES])
  1220. position = frames[frames.length + PathConstraintPositionTimeline.PREV_VALUE];
  1221. else {
  1222. var frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
  1223. position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
  1224. var frameTime = frames[frame];
  1225. var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
  1226. position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
  1227. }
  1228. if (blend == MixBlend.setup)
  1229. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  1230. else
  1231. constraint.position += (position - constraint.position) * alpha;
  1232. };
  1233. PathConstraintPositionTimeline.ENTRIES = 2;
  1234. PathConstraintPositionTimeline.PREV_TIME = -2;
  1235. PathConstraintPositionTimeline.PREV_VALUE = -1;
  1236. PathConstraintPositionTimeline.VALUE = 1;
  1237. return PathConstraintPositionTimeline;
  1238. }(CurveTimeline));
  1239. spine.PathConstraintPositionTimeline = PathConstraintPositionTimeline;
  1240. var PathConstraintSpacingTimeline = (function (_super) {
  1241. __extends(PathConstraintSpacingTimeline, _super);
  1242. function PathConstraintSpacingTimeline(frameCount) {
  1243. return _super.call(this, frameCount) || this;
  1244. }
  1245. PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
  1246. return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
  1247. };
  1248. PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1249. var frames = this.frames;
  1250. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1251. if (!constraint.active)
  1252. return;
  1253. if (time < frames[0]) {
  1254. switch (blend) {
  1255. case MixBlend.setup:
  1256. constraint.spacing = constraint.data.spacing;
  1257. return;
  1258. case MixBlend.first:
  1259. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  1260. }
  1261. return;
  1262. }
  1263. var spacing = 0;
  1264. if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES])
  1265. spacing = frames[frames.length + PathConstraintSpacingTimeline.PREV_VALUE];
  1266. else {
  1267. var frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
  1268. spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
  1269. var frameTime = frames[frame];
  1270. var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
  1271. spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
  1272. }
  1273. if (blend == MixBlend.setup)
  1274. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  1275. else
  1276. constraint.spacing += (spacing - constraint.spacing) * alpha;
  1277. };
  1278. return PathConstraintSpacingTimeline;
  1279. }(PathConstraintPositionTimeline));
  1280. spine.PathConstraintSpacingTimeline = PathConstraintSpacingTimeline;
  1281. var PathConstraintMixTimeline = (function (_super) {
  1282. __extends(PathConstraintMixTimeline, _super);
  1283. function PathConstraintMixTimeline(frameCount) {
  1284. var _this = _super.call(this, frameCount) || this;
  1285. _this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintMixTimeline.ENTRIES);
  1286. return _this;
  1287. }
  1288. PathConstraintMixTimeline.prototype.getPropertyId = function () {
  1289. return (TimelineType.pathConstraintMix << 24) + this.pathConstraintIndex;
  1290. };
  1291. PathConstraintMixTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix) {
  1292. frameIndex *= PathConstraintMixTimeline.ENTRIES;
  1293. this.frames[frameIndex] = time;
  1294. this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
  1295. this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
  1296. };
  1297. PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1298. var frames = this.frames;
  1299. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1300. if (!constraint.active)
  1301. return;
  1302. if (time < frames[0]) {
  1303. switch (blend) {
  1304. case MixBlend.setup:
  1305. constraint.rotateMix = constraint.data.rotateMix;
  1306. constraint.translateMix = constraint.data.translateMix;
  1307. return;
  1308. case MixBlend.first:
  1309. constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
  1310. constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
  1311. }
  1312. return;
  1313. }
  1314. var rotate = 0, translate = 0;
  1315. if (time >= frames[frames.length - PathConstraintMixTimeline.ENTRIES]) {
  1316. rotate = frames[frames.length + PathConstraintMixTimeline.PREV_ROTATE];
  1317. translate = frames[frames.length + PathConstraintMixTimeline.PREV_TRANSLATE];
  1318. }
  1319. else {
  1320. var frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
  1321. rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
  1322. translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
  1323. var frameTime = frames[frame];
  1324. var percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
  1325. rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
  1326. translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
  1327. }
  1328. if (blend == MixBlend.setup) {
  1329. constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
  1330. constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
  1331. }
  1332. else {
  1333. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  1334. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  1335. }
  1336. };
  1337. PathConstraintMixTimeline.ENTRIES = 3;
  1338. PathConstraintMixTimeline.PREV_TIME = -3;
  1339. PathConstraintMixTimeline.PREV_ROTATE = -2;
  1340. PathConstraintMixTimeline.PREV_TRANSLATE = -1;
  1341. PathConstraintMixTimeline.ROTATE = 1;
  1342. PathConstraintMixTimeline.TRANSLATE = 2;
  1343. return PathConstraintMixTimeline;
  1344. }(CurveTimeline));
  1345. spine.PathConstraintMixTimeline = PathConstraintMixTimeline;
  1346. })(spine || (spine = {}));
  1347. var spine;
  1348. (function (spine) {
  1349. var AnimationState = (function () {
  1350. function AnimationState(data) {
  1351. this.tracks = new Array();
  1352. this.timeScale = 1;
  1353. this.unkeyedState = 0;
  1354. this.events = new Array();
  1355. this.listeners = new Array();
  1356. this.queue = new EventQueue(this);
  1357. this.propertyIDs = new spine.IntSet();
  1358. this.animationsChanged = false;
  1359. this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
  1360. this.data = data;
  1361. }
  1362. AnimationState.prototype.update = function (delta) {
  1363. delta *= this.timeScale;
  1364. var tracks = this.tracks;
  1365. for (var i = 0, n = tracks.length; i < n; i++) {
  1366. var current = tracks[i];
  1367. if (current == null)
  1368. continue;
  1369. current.animationLast = current.nextAnimationLast;
  1370. current.trackLast = current.nextTrackLast;
  1371. var currentDelta = delta * current.timeScale;
  1372. if (current.delay > 0) {
  1373. current.delay -= currentDelta;
  1374. if (current.delay > 0)
  1375. continue;
  1376. currentDelta = -current.delay;
  1377. current.delay = 0;
  1378. }
  1379. var next = current.next;
  1380. if (next != null) {
  1381. var nextTime = current.trackLast - next.delay;
  1382. if (nextTime >= 0) {
  1383. next.delay = 0;
  1384. next.trackTime += current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale;
  1385. current.trackTime += currentDelta;
  1386. this.setCurrent(i, next, true);
  1387. while (next.mixingFrom != null) {
  1388. next.mixTime += delta;
  1389. next = next.mixingFrom;
  1390. }
  1391. continue;
  1392. }
  1393. }
  1394. else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  1395. tracks[i] = null;
  1396. this.queue.end(current);
  1397. this.disposeNext(current);
  1398. continue;
  1399. }
  1400. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  1401. var from = current.mixingFrom;
  1402. current.mixingFrom = null;
  1403. if (from != null)
  1404. from.mixingTo = null;
  1405. while (from != null) {
  1406. this.queue.end(from);
  1407. from = from.mixingFrom;
  1408. }
  1409. }
  1410. current.trackTime += currentDelta;
  1411. }
  1412. this.queue.drain();
  1413. };
  1414. AnimationState.prototype.updateMixingFrom = function (to, delta) {
  1415. var from = to.mixingFrom;
  1416. if (from == null)
  1417. return true;
  1418. var finished = this.updateMixingFrom(from, delta);
  1419. from.animationLast = from.nextAnimationLast;
  1420. from.trackLast = from.nextTrackLast;
  1421. if (to.mixTime > 0 && to.mixTime >= to.mixDuration) {
  1422. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  1423. to.mixingFrom = from.mixingFrom;
  1424. if (from.mixingFrom != null)
  1425. from.mixingFrom.mixingTo = to;
  1426. to.interruptAlpha = from.interruptAlpha;
  1427. this.queue.end(from);
  1428. }
  1429. return finished;
  1430. }
  1431. from.trackTime += delta * from.timeScale;
  1432. to.mixTime += delta;
  1433. return false;
  1434. };
  1435. AnimationState.prototype.apply = function (skeleton) {
  1436. if (skeleton == null)
  1437. throw new Error("skeleton cannot be null.");
  1438. if (this.animationsChanged)
  1439. this._animationsChanged();
  1440. var events = this.events;
  1441. var tracks = this.tracks;
  1442. var applied = false;
  1443. for (var i_16 = 0, n_1 = tracks.length; i_16 < n_1; i_16++) {
  1444. var current = tracks[i_16];
  1445. if (current == null || current.delay > 0)
  1446. continue;
  1447. applied = true;
  1448. var blend = i_16 == 0 ? spine.MixBlend.first : current.mixBlend;
  1449. var mix = current.alpha;
  1450. if (current.mixingFrom != null)
  1451. mix *= this.applyMixingFrom(current, skeleton, blend);
  1452. else if (current.trackTime >= current.trackEnd && current.next == null)
  1453. mix = 0;
  1454. var animationLast = current.animationLast, animationTime = current.getAnimationTime();
  1455. var timelineCount = current.animation.timelines.length;
  1456. var timelines = current.animation.timelines;
  1457. if ((i_16 == 0 && mix == 1) || blend == spine.MixBlend.add) {
  1458. for (var ii = 0; ii < timelineCount; ii++) {
  1459. spine.Utils.webkit602BugfixHelper(mix, blend);
  1460. var timeline = timelines[ii];
  1461. if (timeline instanceof spine.AttachmentTimeline)
  1462. this.applyAttachmentTimeline(timeline, skeleton, animationTime, blend, true);
  1463. else
  1464. timeline.apply(skeleton, animationLast, animationTime, events, mix, blend, spine.MixDirection.mixIn);
  1465. }
  1466. }
  1467. else {
  1468. var timelineMode = current.timelineMode;
  1469. var firstFrame = current.timelinesRotation.length == 0;
  1470. if (firstFrame)
  1471. spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  1472. var timelinesRotation = current.timelinesRotation;
  1473. for (var ii = 0; ii < timelineCount; ii++) {
  1474. var timeline_1 = timelines[ii];
  1475. var timelineBlend = timelineMode[ii] == AnimationState.SUBSEQUENT ? blend : spine.MixBlend.setup;
  1476. if (timeline_1 instanceof spine.RotateTimeline) {
  1477. this.applyRotateTimeline(timeline_1, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame);
  1478. }
  1479. else if (timeline_1 instanceof spine.AttachmentTimeline) {
  1480. this.applyAttachmentTimeline(timeline_1, skeleton, animationTime, blend, true);
  1481. }
  1482. else {
  1483. spine.Utils.webkit602BugfixHelper(mix, blend);
  1484. timeline_1.apply(skeleton, animationLast, animationTime, events, mix, timelineBlend, spine.MixDirection.mixIn);
  1485. }
  1486. }
  1487. }
  1488. this.queueEvents(current, animationTime);
  1489. events.length = 0;
  1490. current.nextAnimationLast = animationTime;
  1491. current.nextTrackLast = current.trackTime;
  1492. }
  1493. var setupState = this.unkeyedState + AnimationState.SETUP;
  1494. var slots = skeleton.slots;
  1495. for (var i = 0, n = skeleton.slots.length; i < n; i++) {
  1496. var slot = slots[i];
  1497. if (slot.attachmentState == setupState) {
  1498. var attachmentName = slot.data.attachmentName;
  1499. slot.attachment = (attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  1500. }
  1501. }
  1502. this.unkeyedState += 2;
  1503. this.queue.drain();
  1504. return applied;
  1505. };
  1506. AnimationState.prototype.applyMixingFrom = function (to, skeleton, blend) {
  1507. var from = to.mixingFrom;
  1508. if (from.mixingFrom != null)
  1509. this.applyMixingFrom(from, skeleton, blend);
  1510. var mix = 0;
  1511. if (to.mixDuration == 0) {
  1512. mix = 1;
  1513. if (blend == spine.MixBlend.first)
  1514. blend = spine.MixBlend.setup;
  1515. }
  1516. else {
  1517. mix = to.mixTime / to.mixDuration;
  1518. if (mix > 1)
  1519. mix = 1;
  1520. if (blend != spine.MixBlend.first)
  1521. blend = from.mixBlend;
  1522. }
  1523. var events = mix < from.eventThreshold ? this.events : null;
  1524. var attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  1525. var animationLast = from.animationLast, animationTime = from.getAnimationTime();
  1526. var timelineCount = from.animation.timelines.length;
  1527. var timelines = from.animation.timelines;
  1528. var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
  1529. if (blend == spine.MixBlend.add) {
  1530. for (var i = 0; i < timelineCount; i++)
  1531. timelines[i].apply(skeleton, animationLast, animationTime, events, alphaMix, blend, spine.MixDirection.mixOut);
  1532. }
  1533. else {
  1534. var timelineMode = from.timelineMode;
  1535. var timelineHoldMix = from.timelineHoldMix;
  1536. var firstFrame = from.timelinesRotation.length == 0;
  1537. if (firstFrame)
  1538. spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  1539. var timelinesRotation = from.timelinesRotation;
  1540. from.totalAlpha = 0;
  1541. for (var i = 0; i < timelineCount; i++) {
  1542. var timeline = timelines[i];
  1543. var direction = spine.MixDirection.mixOut;
  1544. var timelineBlend = void 0;
  1545. var alpha = 0;
  1546. switch (timelineMode[i]) {
  1547. case AnimationState.SUBSEQUENT:
  1548. if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
  1549. continue;
  1550. timelineBlend = blend;
  1551. alpha = alphaMix;
  1552. break;
  1553. case AnimationState.FIRST:
  1554. timelineBlend = spine.MixBlend.setup;
  1555. alpha = alphaMix;
  1556. break;
  1557. case AnimationState.HOLD:
  1558. timelineBlend = spine.MixBlend.setup;
  1559. alpha = alphaHold;
  1560. break;
  1561. default:
  1562. timelineBlend = spine.MixBlend.setup;
  1563. var holdMix = timelineHoldMix[i];
  1564. alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
  1565. break;
  1566. }
  1567. from.totalAlpha += alpha;
  1568. if (timeline instanceof spine.RotateTimeline)
  1569. this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame);
  1570. else if (timeline instanceof spine.AttachmentTimeline)
  1571. this.applyAttachmentTimeline(timeline, skeleton, animationTime, timelineBlend, attachments);
  1572. else {
  1573. spine.Utils.webkit602BugfixHelper(alpha, blend);
  1574. if (drawOrder && timeline instanceof spine.DrawOrderTimeline && timelineBlend == spine.MixBlend.setup)
  1575. direction = spine.MixDirection.mixIn;
  1576. timeline.apply(skeleton, animationLast, animationTime, events, alpha, timelineBlend, direction);
  1577. }
  1578. }
  1579. }
  1580. if (to.mixDuration > 0)
  1581. this.queueEvents(from, animationTime);
  1582. this.events.length = 0;
  1583. from.nextAnimationLast = animationTime;
  1584. from.nextTrackLast = from.trackTime;
  1585. return mix;
  1586. };
  1587. AnimationState.prototype.applyAttachmentTimeline = function (timeline, skeleton, time, blend, attachments) {
  1588. var slot = skeleton.slots[timeline.slotIndex];
  1589. if (!slot.bone.active)
  1590. return;
  1591. var frames = timeline.frames;
  1592. if (time < frames[0]) {
  1593. if (blend == spine.MixBlend.setup || blend == spine.MixBlend.first)
  1594. this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments);
  1595. }
  1596. else {
  1597. var frameIndex;
  1598. if (time >= frames[frames.length - 1])
  1599. frameIndex = frames.length - 1;
  1600. else
  1601. frameIndex = spine.Animation.binarySearch(frames, time) - 1;
  1602. this.setAttachment(skeleton, slot, timeline.attachmentNames[frameIndex], attachments);
  1603. }
  1604. if (slot.attachmentState <= this.unkeyedState)
  1605. slot.attachmentState = this.unkeyedState + AnimationState.SETUP;
  1606. };
  1607. AnimationState.prototype.setAttachment = function (skeleton, slot, attachmentName, attachments) {
  1608. slot.attachment = attachmentName == null ? null : skeleton.getAttachment(slot.data.index, attachmentName);
  1609. if (attachments)
  1610. slot.attachmentState = this.unkeyedState + AnimationState.CURRENT;
  1611. };
  1612. AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame) {
  1613. if (firstFrame)
  1614. timelinesRotation[i] = 0;
  1615. if (alpha == 1) {
  1616. timeline.apply(skeleton, 0, time, null, 1, blend, spine.MixDirection.mixIn);
  1617. return;
  1618. }
  1619. var rotateTimeline = timeline;
  1620. var frames = rotateTimeline.frames;
  1621. var bone = skeleton.bones[rotateTimeline.boneIndex];
  1622. if (!bone.active)
  1623. return;
  1624. var r1 = 0, r2 = 0;
  1625. if (time < frames[0]) {
  1626. switch (blend) {
  1627. case spine.MixBlend.setup:
  1628. bone.rotation = bone.data.rotation;
  1629. default:
  1630. return;
  1631. case spine.MixBlend.first:
  1632. r1 = bone.rotation;
  1633. r2 = bone.data.rotation;
  1634. }
  1635. }
  1636. else {
  1637. r1 = blend == spine.MixBlend.setup ? bone.data.rotation : bone.rotation;
  1638. if (time >= frames[frames.length - spine.RotateTimeline.ENTRIES])
  1639. r2 = bone.data.rotation + frames[frames.length + spine.RotateTimeline.PREV_ROTATION];
  1640. else {
  1641. var frame = spine.Animation.binarySearch(frames, time, spine.RotateTimeline.ENTRIES);
  1642. var prevRotation = frames[frame + spine.RotateTimeline.PREV_ROTATION];
  1643. var frameTime = frames[frame];
  1644. var percent = rotateTimeline.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + spine.RotateTimeline.PREV_TIME] - frameTime));
  1645. r2 = frames[frame + spine.RotateTimeline.ROTATION] - prevRotation;
  1646. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1647. r2 = prevRotation + r2 * percent + bone.data.rotation;
  1648. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1649. }
  1650. }
  1651. var total = 0, diff = r2 - r1;
  1652. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  1653. if (diff == 0) {
  1654. total = timelinesRotation[i];
  1655. }
  1656. else {
  1657. var lastTotal = 0, lastDiff = 0;
  1658. if (firstFrame) {
  1659. lastTotal = 0;
  1660. lastDiff = diff;
  1661. }
  1662. else {
  1663. lastTotal = timelinesRotation[i];
  1664. lastDiff = timelinesRotation[i + 1];
  1665. }
  1666. var current = diff > 0, dir = lastTotal >= 0;
  1667. if (spine.MathUtils.signum(lastDiff) != spine.MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  1668. if (Math.abs(lastTotal) > 180)
  1669. lastTotal += 360 * spine.MathUtils.signum(lastTotal);
  1670. dir = current;
  1671. }
  1672. total = diff + lastTotal - lastTotal % 360;
  1673. if (dir != current)
  1674. total += 360 * spine.MathUtils.signum(lastTotal);
  1675. timelinesRotation[i] = total;
  1676. }
  1677. timelinesRotation[i + 1] = diff;
  1678. r1 += total * alpha;
  1679. bone.rotation = r1 - (16384 - ((16384.499999999996 - r1 / 360) | 0)) * 360;
  1680. };
  1681. AnimationState.prototype.queueEvents = function (entry, animationTime) {
  1682. var animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  1683. var duration = animationEnd - animationStart;
  1684. var trackLastWrapped = entry.trackLast % duration;
  1685. var events = this.events;
  1686. var i = 0, n = events.length;
  1687. for (; i < n; i++) {
  1688. var event_1 = events[i];
  1689. if (event_1.time < trackLastWrapped)
  1690. break;
  1691. if (event_1.time > animationEnd)
  1692. continue;
  1693. this.queue.event(entry, event_1);
  1694. }
  1695. var complete = false;
  1696. if (entry.loop)
  1697. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  1698. else
  1699. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  1700. if (complete)
  1701. this.queue.complete(entry);
  1702. for (; i < n; i++) {
  1703. var event_2 = events[i];
  1704. if (event_2.time < animationStart)
  1705. continue;
  1706. this.queue.event(entry, events[i]);
  1707. }
  1708. };
  1709. AnimationState.prototype.clearTracks = function () {
  1710. var oldDrainDisabled = this.queue.drainDisabled;
  1711. this.queue.drainDisabled = true;
  1712. for (var i = 0, n = this.tracks.length; i < n; i++)
  1713. this.clearTrack(i);
  1714. this.tracks.length = 0;
  1715. this.queue.drainDisabled = oldDrainDisabled;
  1716. this.queue.drain();
  1717. };
  1718. AnimationState.prototype.clearTrack = function (trackIndex) {
  1719. if (trackIndex >= this.tracks.length)
  1720. return;
  1721. var current = this.tracks[trackIndex];
  1722. if (current == null)
  1723. return;
  1724. this.queue.end(current);
  1725. this.disposeNext(current);
  1726. var entry = current;
  1727. while (true) {
  1728. var from = entry.mixingFrom;
  1729. if (from == null)
  1730. break;
  1731. this.queue.end(from);
  1732. entry.mixingFrom = null;
  1733. entry.mixingTo = null;
  1734. entry = from;
  1735. }
  1736. this.tracks[current.trackIndex] = null;
  1737. this.queue.drain();
  1738. };
  1739. AnimationState.prototype.setCurrent = function (index, current, interrupt) {
  1740. var from = this.expandToIndex(index);
  1741. this.tracks[index] = current;
  1742. if (from != null) {
  1743. if (interrupt)
  1744. this.queue.interrupt(from);
  1745. current.mixingFrom = from;
  1746. from.mixingTo = current;
  1747. current.mixTime = 0;
  1748. if (from.mixingFrom != null && from.mixDuration > 0)
  1749. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  1750. from.timelinesRotation.length = 0;
  1751. }
  1752. this.queue.start(current);
  1753. };
  1754. AnimationState.prototype.setAnimation = function (trackIndex, animationName, loop) {
  1755. var animation = this.data.skeletonData.findAnimation(animationName);
  1756. if (animation == null)
  1757. throw new Error("Animation not found: " + animationName);
  1758. return this.setAnimationWith(trackIndex, animation, loop);
  1759. };
  1760. AnimationState.prototype.setAnimationWith = function (trackIndex, animation, loop) {
  1761. if (animation == null)
  1762. throw new Error("animation cannot be null.");
  1763. var interrupt = true;
  1764. var current = this.expandToIndex(trackIndex);
  1765. if (current != null) {
  1766. if (current.nextTrackLast == -1) {
  1767. this.tracks[trackIndex] = current.mixingFrom;
  1768. this.queue.interrupt(current);
  1769. this.queue.end(current);
  1770. this.disposeNext(current);
  1771. current = current.mixingFrom;
  1772. interrupt = false;
  1773. }
  1774. else
  1775. this.disposeNext(current);
  1776. }
  1777. var entry = this.trackEntry(trackIndex, animation, loop, current);
  1778. this.setCurrent(trackIndex, entry, interrupt);
  1779. this.queue.drain();
  1780. return entry;
  1781. };
  1782. AnimationState.prototype.addAnimation = function (trackIndex, animationName, loop, delay) {
  1783. var animation = this.data.skeletonData.findAnimation(animationName);
  1784. if (animation == null)
  1785. throw new Error("Animation not found: " + animationName);
  1786. return this.addAnimationWith(trackIndex, animation, loop, delay);
  1787. };
  1788. AnimationState.prototype.addAnimationWith = function (trackIndex, animation, loop, delay) {
  1789. if (animation == null)
  1790. throw new Error("animation cannot be null.");
  1791. var last = this.expandToIndex(trackIndex);
  1792. if (last != null) {
  1793. while (last.next != null)
  1794. last = last.next;
  1795. }
  1796. var entry = this.trackEntry(trackIndex, animation, loop, last);
  1797. if (last == null) {
  1798. this.setCurrent(trackIndex, entry, true);
  1799. this.queue.drain();
  1800. }
  1801. else {
  1802. last.next = entry;
  1803. if (delay <= 0) {
  1804. var duration = last.animationEnd - last.animationStart;
  1805. if (duration != 0) {
  1806. if (last.loop)
  1807. delay += duration * (1 + ((last.trackTime / duration) | 0));
  1808. else
  1809. delay += Math.max(duration, last.trackTime);
  1810. delay -= this.data.getMix(last.animation, animation);
  1811. }
  1812. else
  1813. delay = last.trackTime;
  1814. }
  1815. }
  1816. entry.delay = delay;
  1817. return entry;
  1818. };
  1819. AnimationState.prototype.setEmptyAnimation = function (trackIndex, mixDuration) {
  1820. var entry = this.setAnimationWith(trackIndex, AnimationState.emptyAnimation, false);
  1821. entry.mixDuration = mixDuration;
  1822. entry.trackEnd = mixDuration;
  1823. return entry;
  1824. };
  1825. AnimationState.prototype.addEmptyAnimation = function (trackIndex, mixDuration, delay) {
  1826. if (delay <= 0)
  1827. delay -= mixDuration;
  1828. var entry = this.addAnimationWith(trackIndex, AnimationState.emptyAnimation, false, delay);
  1829. entry.mixDuration = mixDuration;
  1830. entry.trackEnd = mixDuration;
  1831. return entry;
  1832. };
  1833. AnimationState.prototype.setEmptyAnimations = function (mixDuration) {
  1834. var oldDrainDisabled = this.queue.drainDisabled;
  1835. this.queue.drainDisabled = true;
  1836. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1837. var current = this.tracks[i];
  1838. if (current != null)
  1839. this.setEmptyAnimation(current.trackIndex, mixDuration);
  1840. }
  1841. this.queue.drainDisabled = oldDrainDisabled;
  1842. this.queue.drain();
  1843. };
  1844. AnimationState.prototype.expandToIndex = function (index) {
  1845. if (index < this.tracks.length)
  1846. return this.tracks[index];
  1847. spine.Utils.ensureArrayCapacity(this.tracks, index + 1, null);
  1848. this.tracks.length = index + 1;
  1849. return null;
  1850. };
  1851. AnimationState.prototype.trackEntry = function (trackIndex, animation, loop, last) {
  1852. var entry = this.trackEntryPool.obtain();
  1853. entry.trackIndex = trackIndex;
  1854. entry.animation = animation;
  1855. entry.loop = loop;
  1856. entry.holdPrevious = false;
  1857. entry.eventThreshold = 0;
  1858. entry.attachmentThreshold = 0;
  1859. entry.drawOrderThreshold = 0;
  1860. entry.animationStart = 0;
  1861. entry.animationEnd = animation.duration;
  1862. entry.animationLast = -1;
  1863. entry.nextAnimationLast = -1;
  1864. entry.delay = 0;
  1865. entry.trackTime = 0;
  1866. entry.trackLast = -1;
  1867. entry.nextTrackLast = -1;
  1868. entry.trackEnd = Number.MAX_VALUE;
  1869. entry.timeScale = 1;
  1870. entry.alpha = 1;
  1871. entry.interruptAlpha = 1;
  1872. entry.mixTime = 0;
  1873. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  1874. entry.mixBlend = spine.MixBlend.replace;
  1875. return entry;
  1876. };
  1877. AnimationState.prototype.disposeNext = function (entry) {
  1878. var next = entry.next;
  1879. while (next != null) {
  1880. this.queue.dispose(next);
  1881. next = next.next;
  1882. }
  1883. entry.next = null;
  1884. };
  1885. AnimationState.prototype._animationsChanged = function () {
  1886. this.animationsChanged = false;
  1887. this.propertyIDs.clear();
  1888. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1889. var entry = this.tracks[i];
  1890. if (entry == null)
  1891. continue;
  1892. while (entry.mixingFrom != null)
  1893. entry = entry.mixingFrom;
  1894. do {
  1895. if (entry.mixingFrom == null || entry.mixBlend != spine.MixBlend.add)
  1896. this.computeHold(entry);
  1897. entry = entry.mixingTo;
  1898. } while (entry != null);
  1899. }
  1900. };
  1901. AnimationState.prototype.computeHold = function (entry) {
  1902. var to = entry.mixingTo;
  1903. var timelines = entry.animation.timelines;
  1904. var timelinesCount = entry.animation.timelines.length;
  1905. var timelineMode = spine.Utils.setArraySize(entry.timelineMode, timelinesCount);
  1906. entry.timelineHoldMix.length = 0;
  1907. var timelineDipMix = spine.Utils.setArraySize(entry.timelineHoldMix, timelinesCount);
  1908. var propertyIDs = this.propertyIDs;
  1909. if (to != null && to.holdPrevious) {
  1910. for (var i = 0; i < timelinesCount; i++) {
  1911. propertyIDs.add(timelines[i].getPropertyId());
  1912. timelineMode[i] = AnimationState.HOLD;
  1913. }
  1914. return;
  1915. }
  1916. outer: for (var i = 0; i < timelinesCount; i++) {
  1917. var timeline = timelines[i];
  1918. var id = timeline.getPropertyId();
  1919. if (!propertyIDs.add(id))
  1920. timelineMode[i] = AnimationState.SUBSEQUENT;
  1921. else if (to == null || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
  1922. || timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(id)) {
  1923. timelineMode[i] = AnimationState.FIRST;
  1924. }
  1925. else {
  1926. for (var next = to.mixingTo; next != null; next = next.mixingTo) {
  1927. if (next.animation.hasTimeline(id))
  1928. continue;
  1929. if (entry.mixDuration > 0) {
  1930. timelineMode[i] = AnimationState.HOLD_MIX;
  1931. timelineDipMix[i] = next;
  1932. continue outer;
  1933. }
  1934. break;
  1935. }
  1936. timelineMode[i] = AnimationState.HOLD;
  1937. }
  1938. }
  1939. };
  1940. AnimationState.prototype.getCurrent = function (trackIndex) {
  1941. if (trackIndex >= this.tracks.length)
  1942. return null;
  1943. return this.tracks[trackIndex];
  1944. };
  1945. AnimationState.prototype.addListener = function (listener) {
  1946. if (listener == null)
  1947. throw new Error("listener cannot be null.");
  1948. this.listeners.push(listener);
  1949. };
  1950. AnimationState.prototype.removeListener = function (listener) {
  1951. var index = this.listeners.indexOf(listener);
  1952. if (index >= 0)
  1953. this.listeners.splice(index, 1);
  1954. };
  1955. AnimationState.prototype.clearListeners = function () {
  1956. this.listeners.length = 0;
  1957. };
  1958. AnimationState.prototype.clearListenerNotifications = function () {
  1959. this.queue.clear();
  1960. };
  1961. AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
  1962. AnimationState.SUBSEQUENT = 0;
  1963. AnimationState.FIRST = 1;
  1964. AnimationState.HOLD = 2;
  1965. AnimationState.HOLD_MIX = 3;
  1966. AnimationState.SETUP = 1;
  1967. AnimationState.CURRENT = 2;
  1968. return AnimationState;
  1969. }());
  1970. spine.AnimationState = AnimationState;
  1971. var TrackEntry = (function () {
  1972. function TrackEntry() {
  1973. this.mixBlend = spine.MixBlend.replace;
  1974. this.timelineMode = new Array();
  1975. this.timelineHoldMix = new Array();
  1976. this.timelinesRotation = new Array();
  1977. }
  1978. TrackEntry.prototype.reset = function () {
  1979. this.next = null;
  1980. this.mixingFrom = null;
  1981. this.mixingTo = null;
  1982. this.animation = null;
  1983. this.listener = null;
  1984. this.timelineMode.length = 0;
  1985. this.timelineHoldMix.length = 0;
  1986. this.timelinesRotation.length = 0;
  1987. };
  1988. TrackEntry.prototype.getAnimationTime = function () {
  1989. if (this.loop) {
  1990. var duration = this.animationEnd - this.animationStart;
  1991. if (duration == 0)
  1992. return this.animationStart;
  1993. return (this.trackTime % duration) + this.animationStart;
  1994. }
  1995. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  1996. };
  1997. TrackEntry.prototype.setAnimationLast = function (animationLast) {
  1998. this.animationLast = animationLast;
  1999. this.nextAnimationLast = animationLast;
  2000. };
  2001. TrackEntry.prototype.isComplete = function () {
  2002. return this.trackTime >= this.animationEnd - this.animationStart;
  2003. };
  2004. TrackEntry.prototype.resetRotationDirections = function () {
  2005. this.timelinesRotation.length = 0;
  2006. };
  2007. return TrackEntry;
  2008. }());
  2009. spine.TrackEntry = TrackEntry;
  2010. var EventQueue = (function () {
  2011. function EventQueue(animState) {
  2012. this.objects = [];
  2013. this.drainDisabled = false;
  2014. this.animState = animState;
  2015. }
  2016. EventQueue.prototype.start = function (entry) {
  2017. this.objects.push(EventType.start);
  2018. this.objects.push(entry);
  2019. this.animState.animationsChanged = true;
  2020. };
  2021. EventQueue.prototype.interrupt = function (entry) {
  2022. this.objects.push(EventType.interrupt);
  2023. this.objects.push(entry);
  2024. };
  2025. EventQueue.prototype.end = function (entry) {
  2026. this.objects.push(EventType.end);
  2027. this.objects.push(entry);
  2028. this.animState.animationsChanged = true;
  2029. };
  2030. EventQueue.prototype.dispose = function (entry) {
  2031. this.objects.push(EventType.dispose);
  2032. this.objects.push(entry);
  2033. };
  2034. EventQueue.prototype.complete = function (entry) {
  2035. this.objects.push(EventType.complete);
  2036. this.objects.push(entry);
  2037. };
  2038. EventQueue.prototype.event = function (entry, event) {
  2039. this.objects.push(EventType.event);
  2040. this.objects.push(entry);
  2041. this.objects.push(event);
  2042. };
  2043. EventQueue.prototype.drain = function () {
  2044. if (this.drainDisabled)
  2045. return;
  2046. this.drainDisabled = true;
  2047. var objects = this.objects;
  2048. var listeners = this.animState.listeners;
  2049. for (var i = 0; i < objects.length; i += 2) {
  2050. var type = objects[i];
  2051. var entry = objects[i + 1];
  2052. switch (type) {
  2053. case EventType.start:
  2054. if (entry.listener != null && entry.listener.start)
  2055. entry.listener.start(entry);
  2056. for (var ii = 0; ii < listeners.length; ii++)
  2057. if (listeners[ii].start)
  2058. listeners[ii].start(entry);
  2059. break;
  2060. case EventType.interrupt:
  2061. if (entry.listener != null && entry.listener.interrupt)
  2062. entry.listener.interrupt(entry);
  2063. for (var ii = 0; ii < listeners.length; ii++)
  2064. if (listeners[ii].interrupt)
  2065. listeners[ii].interrupt(entry);
  2066. break;
  2067. case EventType.end:
  2068. if (entry.listener != null && entry.listener.end)
  2069. entry.listener.end(entry);
  2070. for (var ii = 0; ii < listeners.length; ii++)
  2071. if (listeners[ii].end)
  2072. listeners[ii].end(entry);
  2073. case EventType.dispose:
  2074. if (entry.listener != null && entry.listener.dispose)
  2075. entry.listener.dispose(entry);
  2076. for (var ii = 0; ii < listeners.length; ii++)
  2077. if (listeners[ii].dispose)
  2078. listeners[ii].dispose(entry);
  2079. this.animState.trackEntryPool.free(entry);
  2080. break;
  2081. case EventType.complete:
  2082. if (entry.listener != null && entry.listener.complete)
  2083. entry.listener.complete(entry);
  2084. for (var ii = 0; ii < listeners.length; ii++)
  2085. if (listeners[ii].complete)
  2086. listeners[ii].complete(entry);
  2087. break;
  2088. case EventType.event:
  2089. var event_3 = objects[i++ + 2];
  2090. if (entry.listener != null && entry.listener.event)
  2091. entry.listener.event(entry, event_3);
  2092. for (var ii = 0; ii < listeners.length; ii++)
  2093. if (listeners[ii].event)
  2094. listeners[ii].event(entry, event_3);
  2095. break;
  2096. }
  2097. }
  2098. this.clear();
  2099. this.drainDisabled = false;
  2100. };
  2101. EventQueue.prototype.clear = function () {
  2102. this.objects.length = 0;
  2103. };
  2104. return EventQueue;
  2105. }());
  2106. spine.EventQueue = EventQueue;
  2107. var EventType;
  2108. (function (EventType) {
  2109. EventType[EventType["start"] = 0] = "start";
  2110. EventType[EventType["interrupt"] = 1] = "interrupt";
  2111. EventType[EventType["end"] = 2] = "end";
  2112. EventType[EventType["dispose"] = 3] = "dispose";
  2113. EventType[EventType["complete"] = 4] = "complete";
  2114. EventType[EventType["event"] = 5] = "event";
  2115. })(EventType = spine.EventType || (spine.EventType = {}));
  2116. var AnimationStateAdapter = (function () {
  2117. function AnimationStateAdapter() {
  2118. }
  2119. AnimationStateAdapter.prototype.start = function (entry) {
  2120. };
  2121. AnimationStateAdapter.prototype.interrupt = function (entry) {
  2122. };
  2123. AnimationStateAdapter.prototype.end = function (entry) {
  2124. };
  2125. AnimationStateAdapter.prototype.dispose = function (entry) {
  2126. };
  2127. AnimationStateAdapter.prototype.complete = function (entry) {
  2128. };
  2129. AnimationStateAdapter.prototype.event = function (entry, event) {
  2130. };
  2131. return AnimationStateAdapter;
  2132. }());
  2133. spine.AnimationStateAdapter = AnimationStateAdapter;
  2134. })(spine || (spine = {}));
  2135. var spine;
  2136. (function (spine) {
  2137. var AnimationStateData = (function () {
  2138. function AnimationStateData(skeletonData) {
  2139. this.animationToMixTime = {};
  2140. this.defaultMix = 0;
  2141. if (skeletonData == null)
  2142. throw new Error("skeletonData cannot be null.");
  2143. this.skeletonData = skeletonData;
  2144. }
  2145. AnimationStateData.prototype.setMix = function (fromName, toName, duration) {
  2146. var from = this.skeletonData.findAnimation(fromName);
  2147. if (from == null)
  2148. throw new Error("Animation not found: " + fromName);
  2149. var to = this.skeletonData.findAnimation(toName);
  2150. if (to == null)
  2151. throw new Error("Animation not found: " + toName);
  2152. this.setMixWith(from, to, duration);
  2153. };
  2154. AnimationStateData.prototype.setMixWith = function (from, to, duration) {
  2155. if (from == null)
  2156. throw new Error("from cannot be null.");
  2157. if (to == null)
  2158. throw new Error("to cannot be null.");
  2159. var key = from.name + "." + to.name;
  2160. this.animationToMixTime[key] = duration;
  2161. };
  2162. AnimationStateData.prototype.getMix = function (from, to) {
  2163. var key = from.name + "." + to.name;
  2164. var value = this.animationToMixTime[key];
  2165. return value === undefined ? this.defaultMix : value;
  2166. };
  2167. return AnimationStateData;
  2168. }());
  2169. spine.AnimationStateData = AnimationStateData;
  2170. })(spine || (spine = {}));
  2171. var spine;
  2172. (function (spine) {
  2173. var AssetManager = (function () {
  2174. function AssetManager(textureLoader, pathPrefix) {
  2175. if (pathPrefix === void 0) { pathPrefix = ""; }
  2176. this.assets = {};
  2177. this.errors = {};
  2178. this.toLoad = 0;
  2179. this.loaded = 0;
  2180. this.rawDataUris = {};
  2181. this.textureLoader = textureLoader;
  2182. this.pathPrefix = pathPrefix;
  2183. }
  2184. AssetManager.prototype.downloadText = function (url, success, error) {
  2185. var request = new XMLHttpRequest();
  2186. request.overrideMimeType("text/html");
  2187. if (this.rawDataUris[url])
  2188. url = this.rawDataUris[url];
  2189. request.open("GET", url, true);
  2190. request.onload = function () {
  2191. if (request.status == 200) {
  2192. success(request.responseText);
  2193. }
  2194. else {
  2195. error(request.status, request.responseText);
  2196. }
  2197. };
  2198. request.onerror = function () {
  2199. error(request.status, request.responseText);
  2200. };
  2201. request.send();
  2202. };
  2203. AssetManager.prototype.downloadBinary = function (url, success, error) {
  2204. var request = new XMLHttpRequest();
  2205. if (this.rawDataUris[url])
  2206. url = this.rawDataUris[url];
  2207. request.open("GET", url, true);
  2208. request.responseType = "arraybuffer";
  2209. request.onload = function () {
  2210. if (request.status == 200) {
  2211. success(new Uint8Array(request.response));
  2212. }
  2213. else {
  2214. error(request.status, request.responseText);
  2215. }
  2216. };
  2217. request.onerror = function () {
  2218. error(request.status, request.responseText);
  2219. };
  2220. request.send();
  2221. };
  2222. AssetManager.prototype.setRawDataURI = function (path, data) {
  2223. this.rawDataUris[this.pathPrefix + path] = data;
  2224. };
  2225. AssetManager.prototype.loadBinary = function (path, success, error) {
  2226. var _this = this;
  2227. if (success === void 0) { success = null; }
  2228. if (error === void 0) { error = null; }
  2229. path = this.pathPrefix + path;
  2230. this.toLoad++;
  2231. this.downloadBinary(path, function (data) {
  2232. _this.assets[path] = data;
  2233. if (success)
  2234. success(path, data);
  2235. _this.toLoad--;
  2236. _this.loaded++;
  2237. }, function (state, responseText) {
  2238. _this.errors[path] = "Couldn't load binary " + path + ": status " + status + ", " + responseText;
  2239. if (error)
  2240. error(path, "Couldn't load binary " + path + ": status " + status + ", " + responseText);
  2241. _this.toLoad--;
  2242. _this.loaded++;
  2243. });
  2244. };
  2245. AssetManager.prototype.loadText = function (path, success, error) {
  2246. var _this = this;
  2247. if (success === void 0) { success = null; }
  2248. if (error === void 0) { error = null; }
  2249. path = this.pathPrefix + path;
  2250. this.toLoad++;
  2251. this.downloadText(path, function (data) {
  2252. _this.assets[path] = data;
  2253. if (success)
  2254. success(path, data);
  2255. _this.toLoad--;
  2256. _this.loaded++;
  2257. }, function (state, responseText) {
  2258. _this.errors[path] = "Couldn't load text " + path + ": status " + status + ", " + responseText;
  2259. if (error)
  2260. error(path, "Couldn't load text " + path + ": status " + status + ", " + responseText);
  2261. _this.toLoad--;
  2262. _this.loaded++;
  2263. });
  2264. };
  2265. AssetManager.prototype.loadTexture = function (path, success, error) {
  2266. var _this = this;
  2267. if (success === void 0) { success = null; }
  2268. if (error === void 0) { error = null; }
  2269. path = this.pathPrefix + path;
  2270. var storagePath = path;
  2271. this.toLoad++;
  2272. var img = new Image();
  2273. img.crossOrigin = "anonymous";
  2274. img.onload = function (ev) {
  2275. var texture = _this.textureLoader(img);
  2276. _this.assets[storagePath] = texture;
  2277. _this.toLoad--;
  2278. _this.loaded++;
  2279. if (success)
  2280. success(path, img);
  2281. };
  2282. img.onerror = function (ev) {
  2283. _this.errors[path] = "Couldn't load image " + path;
  2284. _this.toLoad--;
  2285. _this.loaded++;
  2286. if (error)
  2287. error(path, "Couldn't load image " + path);
  2288. };
  2289. if (this.rawDataUris[path])
  2290. path = this.rawDataUris[path];
  2291. img.src = path;
  2292. };
  2293. AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
  2294. var _this = this;
  2295. if (success === void 0) { success = null; }
  2296. if (error === void 0) { error = null; }
  2297. var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
  2298. path = this.pathPrefix + path;
  2299. this.toLoad++;
  2300. this.downloadText(path, function (atlasData) {
  2301. var pagesLoaded = { count: 0 };
  2302. var atlasPages = new Array();
  2303. try {
  2304. var atlas = new spine.TextureAtlas(atlasData, function (path) {
  2305. atlasPages.push(parent == "" ? path : parent + "/" + path);
  2306. var image = document.createElement("img");
  2307. image.width = 16;
  2308. image.height = 16;
  2309. return new spine.FakeTexture(image);
  2310. });
  2311. }
  2312. catch (e) {
  2313. var ex = e;
  2314. _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message;
  2315. if (error)
  2316. error(path, "Couldn't load texture atlas " + path + ": " + ex.message);
  2317. _this.toLoad--;
  2318. _this.loaded++;
  2319. return;
  2320. }
  2321. var _loop_1 = function (atlasPage) {
  2322. var pageLoadError = false;
  2323. _this.loadTexture(atlasPage, function (imagePath, image) {
  2324. pagesLoaded.count++;
  2325. if (pagesLoaded.count == atlasPages.length) {
  2326. if (!pageLoadError) {
  2327. try {
  2328. var atlas = new spine.TextureAtlas(atlasData, function (path) {
  2329. return _this.get(parent == "" ? path : parent + "/" + path);
  2330. });
  2331. _this.assets[path] = atlas;
  2332. if (success)
  2333. success(path, atlas);
  2334. _this.toLoad--;
  2335. _this.loaded++;
  2336. }
  2337. catch (e) {
  2338. var ex = e;
  2339. _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message;
  2340. if (error)
  2341. error(path, "Couldn't load texture atlas " + path + ": " + ex.message);
  2342. _this.toLoad--;
  2343. _this.loaded++;
  2344. }
  2345. }
  2346. else {
  2347. _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path;
  2348. if (error)
  2349. error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path);
  2350. _this.toLoad--;
  2351. _this.loaded++;
  2352. }
  2353. }
  2354. }, function (imagePath, errorMessage) {
  2355. pageLoadError = true;
  2356. pagesLoaded.count++;
  2357. if (pagesLoaded.count == atlasPages.length) {
  2358. _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path;
  2359. if (error)
  2360. error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path);
  2361. _this.toLoad--;
  2362. _this.loaded++;
  2363. }
  2364. });
  2365. };
  2366. for (var _i = 0, atlasPages_1 = atlasPages; _i < atlasPages_1.length; _i++) {
  2367. var atlasPage = atlasPages_1[_i];
  2368. _loop_1(atlasPage);
  2369. }
  2370. }, function (state, responseText) {
  2371. _this.errors[path] = "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText;
  2372. if (error)
  2373. error(path, "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText);
  2374. _this.toLoad--;
  2375. _this.loaded++;
  2376. });
  2377. };
  2378. AssetManager.prototype.get = function (path) {
  2379. path = this.pathPrefix + path;
  2380. return this.assets[path];
  2381. };
  2382. AssetManager.prototype.remove = function (path) {
  2383. path = this.pathPrefix + path;
  2384. var asset = this.assets[path];
  2385. if (asset.dispose)
  2386. asset.dispose();
  2387. this.assets[path] = null;
  2388. };
  2389. AssetManager.prototype.removeAll = function () {
  2390. for (var key in this.assets) {
  2391. var asset = this.assets[key];
  2392. if (asset.dispose)
  2393. asset.dispose();
  2394. }
  2395. this.assets = {};
  2396. };
  2397. AssetManager.prototype.isLoadingComplete = function () {
  2398. return this.toLoad == 0;
  2399. };
  2400. AssetManager.prototype.getToLoad = function () {
  2401. return this.toLoad;
  2402. };
  2403. AssetManager.prototype.getLoaded = function () {
  2404. return this.loaded;
  2405. };
  2406. AssetManager.prototype.dispose = function () {
  2407. this.removeAll();
  2408. };
  2409. AssetManager.prototype.hasErrors = function () {
  2410. return Object.keys(this.errors).length > 0;
  2411. };
  2412. AssetManager.prototype.getErrors = function () {
  2413. return this.errors;
  2414. };
  2415. return AssetManager;
  2416. }());
  2417. spine.AssetManager = AssetManager;
  2418. })(spine || (spine = {}));
  2419. var spine;
  2420. (function (spine) {
  2421. var AtlasAttachmentLoader = (function () {
  2422. function AtlasAttachmentLoader(atlas) {
  2423. this.atlas = atlas;
  2424. }
  2425. AtlasAttachmentLoader.prototype.newRegionAttachment = function (skin, name, path) {
  2426. var region = this.atlas.findRegion(path);
  2427. if (region == null)
  2428. throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  2429. region.renderObject = region;
  2430. var attachment = new spine.RegionAttachment(name);
  2431. attachment.setRegion(region);
  2432. return attachment;
  2433. };
  2434. AtlasAttachmentLoader.prototype.newMeshAttachment = function (skin, name, path) {
  2435. var region = this.atlas.findRegion(path);
  2436. if (region == null)
  2437. throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  2438. region.renderObject = region;
  2439. var attachment = new spine.MeshAttachment(name);
  2440. attachment.region = region;
  2441. return attachment;
  2442. };
  2443. AtlasAttachmentLoader.prototype.newBoundingBoxAttachment = function (skin, name) {
  2444. return new spine.BoundingBoxAttachment(name);
  2445. };
  2446. AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) {
  2447. return new spine.PathAttachment(name);
  2448. };
  2449. AtlasAttachmentLoader.prototype.newPointAttachment = function (skin, name) {
  2450. return new spine.PointAttachment(name);
  2451. };
  2452. AtlasAttachmentLoader.prototype.newClippingAttachment = function (skin, name) {
  2453. return new spine.ClippingAttachment(name);
  2454. };
  2455. return AtlasAttachmentLoader;
  2456. }());
  2457. spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
  2458. })(spine || (spine = {}));
  2459. var spine;
  2460. (function (spine) {
  2461. var BlendMode;
  2462. (function (BlendMode) {
  2463. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  2464. BlendMode[BlendMode["Additive"] = 1] = "Additive";
  2465. BlendMode[BlendMode["Multiply"] = 2] = "Multiply";
  2466. BlendMode[BlendMode["Screen"] = 3] = "Screen";
  2467. })(BlendMode = spine.BlendMode || (spine.BlendMode = {}));
  2468. })(spine || (spine = {}));
  2469. var spine;
  2470. (function (spine) {
  2471. var Bone = (function () {
  2472. function Bone(data, skeleton, parent) {
  2473. this.children = new Array();
  2474. this.x = 0;
  2475. this.y = 0;
  2476. this.rotation = 0;
  2477. this.scaleX = 0;
  2478. this.scaleY = 0;
  2479. this.shearX = 0;
  2480. this.shearY = 0;
  2481. this.ax = 0;
  2482. this.ay = 0;
  2483. this.arotation = 0;
  2484. this.ascaleX = 0;
  2485. this.ascaleY = 0;
  2486. this.ashearX = 0;
  2487. this.ashearY = 0;
  2488. this.appliedValid = false;
  2489. this.a = 0;
  2490. this.b = 0;
  2491. this.c = 0;
  2492. this.d = 0;
  2493. this.worldY = 0;
  2494. this.worldX = 0;
  2495. this.sorted = false;
  2496. this.active = false;
  2497. if (data == null)
  2498. throw new Error("data cannot be null.");
  2499. if (skeleton == null)
  2500. throw new Error("skeleton cannot be null.");
  2501. this.data = data;
  2502. this.skeleton = skeleton;
  2503. this.parent = parent;
  2504. this.setToSetupPose();
  2505. }
  2506. Bone.prototype.isActive = function () {
  2507. return this.active;
  2508. };
  2509. Bone.prototype.update = function () {
  2510. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2511. };
  2512. Bone.prototype.updateWorldTransform = function () {
  2513. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2514. };
  2515. Bone.prototype.updateWorldTransformWith = function (x, y, rotation, scaleX, scaleY, shearX, shearY) {
  2516. this.ax = x;
  2517. this.ay = y;
  2518. this.arotation = rotation;
  2519. this.ascaleX = scaleX;
  2520. this.ascaleY = scaleY;
  2521. this.ashearX = shearX;
  2522. this.ashearY = shearY;
  2523. this.appliedValid = true;
  2524. var parent = this.parent;
  2525. if (parent == null) {
  2526. var skeleton = this.skeleton;
  2527. var rotationY = rotation + 90 + shearY;
  2528. var sx = skeleton.scaleX;
  2529. var sy = skeleton.scaleY;
  2530. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX * sx;
  2531. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY * sx;
  2532. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX * sy;
  2533. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY * sy;
  2534. this.worldX = x * sx + skeleton.x;
  2535. this.worldY = y * sy + skeleton.y;
  2536. return;
  2537. }
  2538. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2539. this.worldX = pa * x + pb * y + parent.worldX;
  2540. this.worldY = pc * x + pd * y + parent.worldY;
  2541. switch (this.data.transformMode) {
  2542. case spine.TransformMode.Normal: {
  2543. var rotationY = rotation + 90 + shearY;
  2544. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2545. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2546. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2547. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2548. this.a = pa * la + pb * lc;
  2549. this.b = pa * lb + pb * ld;
  2550. this.c = pc * la + pd * lc;
  2551. this.d = pc * lb + pd * ld;
  2552. return;
  2553. }
  2554. case spine.TransformMode.OnlyTranslation: {
  2555. var rotationY = rotation + 90 + shearY;
  2556. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2557. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2558. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2559. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2560. break;
  2561. }
  2562. case spine.TransformMode.NoRotationOrReflection: {
  2563. var s = pa * pa + pc * pc;
  2564. var prx = 0;
  2565. if (s > 0.0001) {
  2566. s = Math.abs(pa * pd - pb * pc) / s;
  2567. pb = pc * s;
  2568. pd = pa * s;
  2569. prx = Math.atan2(pc, pa) * spine.MathUtils.radDeg;
  2570. }
  2571. else {
  2572. pa = 0;
  2573. pc = 0;
  2574. prx = 90 - Math.atan2(pd, pb) * spine.MathUtils.radDeg;
  2575. }
  2576. var rx = rotation + shearX - prx;
  2577. var ry = rotation + shearY - prx + 90;
  2578. var la = spine.MathUtils.cosDeg(rx) * scaleX;
  2579. var lb = spine.MathUtils.cosDeg(ry) * scaleY;
  2580. var lc = spine.MathUtils.sinDeg(rx) * scaleX;
  2581. var ld = spine.MathUtils.sinDeg(ry) * scaleY;
  2582. this.a = pa * la - pb * lc;
  2583. this.b = pa * lb - pb * ld;
  2584. this.c = pc * la + pd * lc;
  2585. this.d = pc * lb + pd * ld;
  2586. return;
  2587. }
  2588. case spine.TransformMode.NoScale:
  2589. case spine.TransformMode.NoScaleOrReflection: {
  2590. var cos = spine.MathUtils.cosDeg(rotation);
  2591. var sin = spine.MathUtils.sinDeg(rotation);
  2592. var za = (pa * cos + pb * sin) / this.skeleton.scaleX;
  2593. var zc = (pc * cos + pd * sin) / this.skeleton.scaleY;
  2594. var s = Math.sqrt(za * za + zc * zc);
  2595. if (s > 0.00001)
  2596. s = 1 / s;
  2597. za *= s;
  2598. zc *= s;
  2599. s = Math.sqrt(za * za + zc * zc);
  2600. if (this.data.transformMode == spine.TransformMode.NoScale
  2601. && (pa * pd - pb * pc < 0) != (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0))
  2602. s = -s;
  2603. var r = Math.PI / 2 + Math.atan2(zc, za);
  2604. var zb = Math.cos(r) * s;
  2605. var zd = Math.sin(r) * s;
  2606. var la = spine.MathUtils.cosDeg(shearX) * scaleX;
  2607. var lb = spine.MathUtils.cosDeg(90 + shearY) * scaleY;
  2608. var lc = spine.MathUtils.sinDeg(shearX) * scaleX;
  2609. var ld = spine.MathUtils.sinDeg(90 + shearY) * scaleY;
  2610. this.a = za * la + zb * lc;
  2611. this.b = za * lb + zb * ld;
  2612. this.c = zc * la + zd * lc;
  2613. this.d = zc * lb + zd * ld;
  2614. break;
  2615. }
  2616. }
  2617. this.a *= this.skeleton.scaleX;
  2618. this.b *= this.skeleton.scaleX;
  2619. this.c *= this.skeleton.scaleY;
  2620. this.d *= this.skeleton.scaleY;
  2621. };
  2622. Bone.prototype.setToSetupPose = function () {
  2623. var data = this.data;
  2624. this.x = data.x;
  2625. this.y = data.y;
  2626. this.rotation = data.rotation;
  2627. this.scaleX = data.scaleX;
  2628. this.scaleY = data.scaleY;
  2629. this.shearX = data.shearX;
  2630. this.shearY = data.shearY;
  2631. };
  2632. Bone.prototype.getWorldRotationX = function () {
  2633. return Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2634. };
  2635. Bone.prototype.getWorldRotationY = function () {
  2636. return Math.atan2(this.d, this.b) * spine.MathUtils.radDeg;
  2637. };
  2638. Bone.prototype.getWorldScaleX = function () {
  2639. return Math.sqrt(this.a * this.a + this.c * this.c);
  2640. };
  2641. Bone.prototype.getWorldScaleY = function () {
  2642. return Math.sqrt(this.b * this.b + this.d * this.d);
  2643. };
  2644. Bone.prototype.updateAppliedTransform = function () {
  2645. this.appliedValid = true;
  2646. var parent = this.parent;
  2647. if (parent == null) {
  2648. this.ax = this.worldX;
  2649. this.ay = this.worldY;
  2650. this.arotation = Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2651. this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c);
  2652. this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d);
  2653. this.ashearX = 0;
  2654. this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * spine.MathUtils.radDeg;
  2655. return;
  2656. }
  2657. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2658. var pid = 1 / (pa * pd - pb * pc);
  2659. var dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY;
  2660. this.ax = (dx * pd * pid - dy * pb * pid);
  2661. this.ay = (dy * pa * pid - dx * pc * pid);
  2662. var ia = pid * pd;
  2663. var id = pid * pa;
  2664. var ib = pid * pb;
  2665. var ic = pid * pc;
  2666. var ra = ia * this.a - ib * this.c;
  2667. var rb = ia * this.b - ib * this.d;
  2668. var rc = id * this.c - ic * this.a;
  2669. var rd = id * this.d - ic * this.b;
  2670. this.ashearX = 0;
  2671. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  2672. if (this.ascaleX > 0.0001) {
  2673. var det = ra * rd - rb * rc;
  2674. this.ascaleY = det / this.ascaleX;
  2675. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * spine.MathUtils.radDeg;
  2676. this.arotation = Math.atan2(rc, ra) * spine.MathUtils.radDeg;
  2677. }
  2678. else {
  2679. this.ascaleX = 0;
  2680. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  2681. this.ashearY = 0;
  2682. this.arotation = 90 - Math.atan2(rd, rb) * spine.MathUtils.radDeg;
  2683. }
  2684. };
  2685. Bone.prototype.worldToLocal = function (world) {
  2686. var a = this.a, b = this.b, c = this.c, d = this.d;
  2687. var invDet = 1 / (a * d - b * c);
  2688. var x = world.x - this.worldX, y = world.y - this.worldY;
  2689. world.x = (x * d * invDet - y * b * invDet);
  2690. world.y = (y * a * invDet - x * c * invDet);
  2691. return world;
  2692. };
  2693. Bone.prototype.localToWorld = function (local) {
  2694. var x = local.x, y = local.y;
  2695. local.x = x * this.a + y * this.b + this.worldX;
  2696. local.y = x * this.c + y * this.d + this.worldY;
  2697. return local;
  2698. };
  2699. Bone.prototype.worldToLocalRotation = function (worldRotation) {
  2700. var sin = spine.MathUtils.sinDeg(worldRotation), cos = spine.MathUtils.cosDeg(worldRotation);
  2701. return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * spine.MathUtils.radDeg + this.rotation - this.shearX;
  2702. };
  2703. Bone.prototype.localToWorldRotation = function (localRotation) {
  2704. localRotation -= this.rotation - this.shearX;
  2705. var sin = spine.MathUtils.sinDeg(localRotation), cos = spine.MathUtils.cosDeg(localRotation);
  2706. return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * spine.MathUtils.radDeg;
  2707. };
  2708. Bone.prototype.rotateWorld = function (degrees) {
  2709. var a = this.a, b = this.b, c = this.c, d = this.d;
  2710. var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
  2711. this.a = cos * a - sin * c;
  2712. this.b = cos * b - sin * d;
  2713. this.c = sin * a + cos * c;
  2714. this.d = sin * b + cos * d;
  2715. this.appliedValid = false;
  2716. };
  2717. return Bone;
  2718. }());
  2719. spine.Bone = Bone;
  2720. })(spine || (spine = {}));
  2721. var spine;
  2722. (function (spine) {
  2723. var BoneData = (function () {
  2724. function BoneData(index, name, parent) {
  2725. this.x = 0;
  2726. this.y = 0;
  2727. this.rotation = 0;
  2728. this.scaleX = 1;
  2729. this.scaleY = 1;
  2730. this.shearX = 0;
  2731. this.shearY = 0;
  2732. this.transformMode = TransformMode.Normal;
  2733. this.skinRequired = false;
  2734. this.color = new spine.Color();
  2735. if (index < 0)
  2736. throw new Error("index must be >= 0.");
  2737. if (name == null)
  2738. throw new Error("name cannot be null.");
  2739. this.index = index;
  2740. this.name = name;
  2741. this.parent = parent;
  2742. }
  2743. return BoneData;
  2744. }());
  2745. spine.BoneData = BoneData;
  2746. var TransformMode;
  2747. (function (TransformMode) {
  2748. TransformMode[TransformMode["Normal"] = 0] = "Normal";
  2749. TransformMode[TransformMode["OnlyTranslation"] = 1] = "OnlyTranslation";
  2750. TransformMode[TransformMode["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
  2751. TransformMode[TransformMode["NoScale"] = 3] = "NoScale";
  2752. TransformMode[TransformMode["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
  2753. })(TransformMode = spine.TransformMode || (spine.TransformMode = {}));
  2754. })(spine || (spine = {}));
  2755. var spine;
  2756. (function (spine) {
  2757. var ConstraintData = (function () {
  2758. function ConstraintData(name, order, skinRequired) {
  2759. this.name = name;
  2760. this.order = order;
  2761. this.skinRequired = skinRequired;
  2762. }
  2763. return ConstraintData;
  2764. }());
  2765. spine.ConstraintData = ConstraintData;
  2766. })(spine || (spine = {}));
  2767. var spine;
  2768. (function (spine) {
  2769. var Event = (function () {
  2770. function Event(time, data) {
  2771. if (data == null)
  2772. throw new Error("data cannot be null.");
  2773. this.time = time;
  2774. this.data = data;
  2775. }
  2776. return Event;
  2777. }());
  2778. spine.Event = Event;
  2779. })(spine || (spine = {}));
  2780. var spine;
  2781. (function (spine) {
  2782. var EventData = (function () {
  2783. function EventData(name) {
  2784. this.name = name;
  2785. }
  2786. return EventData;
  2787. }());
  2788. spine.EventData = EventData;
  2789. })(spine || (spine = {}));
  2790. var spine;
  2791. (function (spine) {
  2792. var IkConstraint = (function () {
  2793. function IkConstraint(data, skeleton) {
  2794. this.bendDirection = 0;
  2795. this.compress = false;
  2796. this.stretch = false;
  2797. this.mix = 1;
  2798. this.softness = 0;
  2799. this.active = false;
  2800. if (data == null)
  2801. throw new Error("data cannot be null.");
  2802. if (skeleton == null)
  2803. throw new Error("skeleton cannot be null.");
  2804. this.data = data;
  2805. this.mix = data.mix;
  2806. this.softness = data.softness;
  2807. this.bendDirection = data.bendDirection;
  2808. this.compress = data.compress;
  2809. this.stretch = data.stretch;
  2810. this.bones = new Array();
  2811. for (var i = 0; i < data.bones.length; i++)
  2812. this.bones.push(skeleton.findBone(data.bones[i].name));
  2813. this.target = skeleton.findBone(data.target.name);
  2814. }
  2815. IkConstraint.prototype.isActive = function () {
  2816. return this.active;
  2817. };
  2818. IkConstraint.prototype.apply = function () {
  2819. this.update();
  2820. };
  2821. IkConstraint.prototype.update = function () {
  2822. var target = this.target;
  2823. var bones = this.bones;
  2824. switch (bones.length) {
  2825. case 1:
  2826. this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix);
  2827. break;
  2828. case 2:
  2829. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.softness, this.mix);
  2830. break;
  2831. }
  2832. };
  2833. IkConstraint.prototype.apply1 = function (bone, targetX, targetY, compress, stretch, uniform, alpha) {
  2834. if (!bone.appliedValid)
  2835. bone.updateAppliedTransform();
  2836. var p = bone.parent;
  2837. var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
  2838. var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
  2839. switch (bone.data.transformMode) {
  2840. case spine.TransformMode.OnlyTranslation:
  2841. tx = targetX - bone.worldX;
  2842. ty = targetY - bone.worldY;
  2843. break;
  2844. case spine.TransformMode.NoRotationOrReflection:
  2845. rotationIK += Math.atan2(pc, pa) * spine.MathUtils.radDeg;
  2846. var ps = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
  2847. pb = -pc * ps;
  2848. pd = pa * ps;
  2849. default:
  2850. var x = targetX - p.worldX, y = targetY - p.worldY;
  2851. var d = pa * pd - pb * pc;
  2852. tx = (x * pd - y * pb) / d - bone.ax;
  2853. ty = (y * pa - x * pc) / d - bone.ay;
  2854. }
  2855. rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
  2856. if (bone.ascaleX < 0)
  2857. rotationIK += 180;
  2858. if (rotationIK > 180)
  2859. rotationIK -= 360;
  2860. else if (rotationIK < -180)
  2861. rotationIK += 360;
  2862. var sx = bone.ascaleX, sy = bone.ascaleY;
  2863. if (compress || stretch) {
  2864. switch (bone.data.transformMode) {
  2865. case spine.TransformMode.NoScale:
  2866. case spine.TransformMode.NoScaleOrReflection:
  2867. tx = targetX - bone.worldX;
  2868. ty = targetY - bone.worldY;
  2869. }
  2870. var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
  2871. if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
  2872. var s = (dd / b - 1) * alpha + 1;
  2873. sx *= s;
  2874. if (uniform)
  2875. sy *= s;
  2876. }
  2877. }
  2878. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX, bone.ashearY);
  2879. };
  2880. IkConstraint.prototype.apply2 = function (parent, child, targetX, targetY, bendDir, stretch, softness, alpha) {
  2881. if (alpha == 0) {
  2882. child.updateWorldTransform();
  2883. return;
  2884. }
  2885. if (!parent.appliedValid)
  2886. parent.updateAppliedTransform();
  2887. if (!child.appliedValid)
  2888. child.updateAppliedTransform();
  2889. var px = parent.ax, py = parent.ay, psx = parent.ascaleX, sx = psx, psy = parent.ascaleY, csx = child.ascaleX;
  2890. var os1 = 0, os2 = 0, s2 = 0;
  2891. if (psx < 0) {
  2892. psx = -psx;
  2893. os1 = 180;
  2894. s2 = -1;
  2895. }
  2896. else {
  2897. os1 = 0;
  2898. s2 = 1;
  2899. }
  2900. if (psy < 0) {
  2901. psy = -psy;
  2902. s2 = -s2;
  2903. }
  2904. if (csx < 0) {
  2905. csx = -csx;
  2906. os2 = 180;
  2907. }
  2908. else
  2909. os2 = 0;
  2910. var cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
  2911. var u = Math.abs(psx - psy) <= 0.0001;
  2912. if (!u) {
  2913. cy = 0;
  2914. cwx = a * cx + parent.worldX;
  2915. cwy = c * cx + parent.worldY;
  2916. }
  2917. else {
  2918. cy = child.ay;
  2919. cwx = a * cx + b * cy + parent.worldX;
  2920. cwy = c * cx + d * cy + parent.worldY;
  2921. }
  2922. var pp = parent.parent;
  2923. a = pp.a;
  2924. b = pp.b;
  2925. c = pp.c;
  2926. d = pp.d;
  2927. var id = 1 / (a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY;
  2928. var dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  2929. var l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
  2930. if (l1 < 0.0001) {
  2931. this.apply1(parent, targetX, targetY, false, stretch, false, alpha);
  2932. child.updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  2933. return;
  2934. }
  2935. x = targetX - pp.worldX;
  2936. y = targetY - pp.worldY;
  2937. var tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  2938. var dd = tx * tx + ty * ty;
  2939. if (softness != 0) {
  2940. softness *= psx * (csx + 1) / 2;
  2941. var td = Math.sqrt(dd), sd = td - l1 - l2 * psx + softness;
  2942. if (sd > 0) {
  2943. var p = Math.min(1, sd / (softness * 2)) - 1;
  2944. p = (sd - softness * (1 - p * p)) / td;
  2945. tx -= p * tx;
  2946. ty -= p * ty;
  2947. dd = tx * tx + ty * ty;
  2948. }
  2949. }
  2950. outer: if (u) {
  2951. l2 *= psx;
  2952. var cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  2953. if (cos < -1)
  2954. cos = -1;
  2955. else if (cos > 1) {
  2956. cos = 1;
  2957. if (stretch)
  2958. sx *= (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
  2959. }
  2960. a2 = Math.acos(cos) * bendDir;
  2961. a = l1 + l2 * cos;
  2962. b = l2 * Math.sin(a2);
  2963. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  2964. }
  2965. else {
  2966. a = psx * l2;
  2967. b = psy * l2;
  2968. var aa = a * a, bb = b * b, ta = Math.atan2(ty, tx);
  2969. c = bb * l1 * l1 + aa * dd - aa * bb;
  2970. var c1 = -2 * bb * l1, c2 = bb - aa;
  2971. d = c1 * c1 - 4 * c2 * c;
  2972. if (d >= 0) {
  2973. var q = Math.sqrt(d);
  2974. if (c1 < 0)
  2975. q = -q;
  2976. q = -(c1 + q) / 2;
  2977. var r0 = q / c2, r1 = c / q;
  2978. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  2979. if (r * r <= dd) {
  2980. y = Math.sqrt(dd - r * r) * bendDir;
  2981. a1 = ta - Math.atan2(y, r);
  2982. a2 = Math.atan2(y / psy, (r - l1) / psx);
  2983. break outer;
  2984. }
  2985. }
  2986. var minAngle = spine.MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  2987. var maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  2988. c = -a * l1 / (aa - bb);
  2989. if (c >= -1 && c <= 1) {
  2990. c = Math.acos(c);
  2991. x = a * Math.cos(c) + l1;
  2992. y = b * Math.sin(c);
  2993. d = x * x + y * y;
  2994. if (d < minDist) {
  2995. minAngle = c;
  2996. minDist = d;
  2997. minX = x;
  2998. minY = y;
  2999. }
  3000. if (d > maxDist) {
  3001. maxAngle = c;
  3002. maxDist = d;
  3003. maxX = x;
  3004. maxY = y;
  3005. }
  3006. }
  3007. if (dd <= (minDist + maxDist) / 2) {
  3008. a1 = ta - Math.atan2(minY * bendDir, minX);
  3009. a2 = minAngle * bendDir;
  3010. }
  3011. else {
  3012. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  3013. a2 = maxAngle * bendDir;
  3014. }
  3015. }
  3016. var os = Math.atan2(cy, cx) * s2;
  3017. var rotation = parent.arotation;
  3018. a1 = (a1 - os) * spine.MathUtils.radDeg + os1 - rotation;
  3019. if (a1 > 180)
  3020. a1 -= 360;
  3021. else if (a1 < -180)
  3022. a1 += 360;
  3023. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, parent.ascaleY, 0, 0);
  3024. rotation = child.arotation;
  3025. a2 = ((a2 + os) * spine.MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  3026. if (a2 > 180)
  3027. a2 -= 360;
  3028. else if (a2 < -180)
  3029. a2 += 360;
  3030. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  3031. };
  3032. return IkConstraint;
  3033. }());
  3034. spine.IkConstraint = IkConstraint;
  3035. })(spine || (spine = {}));
  3036. var spine;
  3037. (function (spine) {
  3038. var IkConstraintData = (function (_super) {
  3039. __extends(IkConstraintData, _super);
  3040. function IkConstraintData(name) {
  3041. var _this = _super.call(this, name, 0, false) || this;
  3042. _this.bones = new Array();
  3043. _this.bendDirection = 1;
  3044. _this.compress = false;
  3045. _this.stretch = false;
  3046. _this.uniform = false;
  3047. _this.mix = 1;
  3048. _this.softness = 0;
  3049. return _this;
  3050. }
  3051. return IkConstraintData;
  3052. }(spine.ConstraintData));
  3053. spine.IkConstraintData = IkConstraintData;
  3054. })(spine || (spine = {}));
  3055. var spine;
  3056. (function (spine) {
  3057. var PathConstraint = (function () {
  3058. function PathConstraint(data, skeleton) {
  3059. this.position = 0;
  3060. this.spacing = 0;
  3061. this.rotateMix = 0;
  3062. this.translateMix = 0;
  3063. this.spaces = new Array();
  3064. this.positions = new Array();
  3065. this.world = new Array();
  3066. this.curves = new Array();
  3067. this.lengths = new Array();
  3068. this.segments = new Array();
  3069. this.active = false;
  3070. if (data == null)
  3071. throw new Error("data cannot be null.");
  3072. if (skeleton == null)
  3073. throw new Error("skeleton cannot be null.");
  3074. this.data = data;
  3075. this.bones = new Array();
  3076. for (var i = 0, n = data.bones.length; i < n; i++)
  3077. this.bones.push(skeleton.findBone(data.bones[i].name));
  3078. this.target = skeleton.findSlot(data.target.name);
  3079. this.position = data.position;
  3080. this.spacing = data.spacing;
  3081. this.rotateMix = data.rotateMix;
  3082. this.translateMix = data.translateMix;
  3083. }
  3084. PathConstraint.prototype.isActive = function () {
  3085. return this.active;
  3086. };
  3087. PathConstraint.prototype.apply = function () {
  3088. this.update();
  3089. };
  3090. PathConstraint.prototype.update = function () {
  3091. var attachment = this.target.getAttachment();
  3092. if (!(attachment instanceof spine.PathAttachment))
  3093. return;
  3094. var rotateMix = this.rotateMix, translateMix = this.translateMix;
  3095. var translate = translateMix > 0, rotate = rotateMix > 0;
  3096. if (!translate && !rotate)
  3097. return;
  3098. var data = this.data;
  3099. var percentSpacing = data.spacingMode == spine.SpacingMode.Percent;
  3100. var rotateMode = data.rotateMode;
  3101. var tangents = rotateMode == spine.RotateMode.Tangent, scale = rotateMode == spine.RotateMode.ChainScale;
  3102. var boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  3103. var bones = this.bones;
  3104. var spaces = spine.Utils.setArraySize(this.spaces, spacesCount), lengths = null;
  3105. var spacing = this.spacing;
  3106. if (scale || !percentSpacing) {
  3107. if (scale)
  3108. lengths = spine.Utils.setArraySize(this.lengths, boneCount);
  3109. var lengthSpacing = data.spacingMode == spine.SpacingMode.Length;
  3110. for (var i = 0, n = spacesCount - 1; i < n;) {
  3111. var bone = bones[i];
  3112. var setupLength = bone.data.length;
  3113. if (setupLength < PathConstraint.epsilon) {
  3114. if (scale)
  3115. lengths[i] = 0;
  3116. spaces[++i] = 0;
  3117. }
  3118. else if (percentSpacing) {
  3119. if (scale) {
  3120. var x = setupLength * bone.a, y = setupLength * bone.c;
  3121. var length_1 = Math.sqrt(x * x + y * y);
  3122. lengths[i] = length_1;
  3123. }
  3124. spaces[++i] = spacing;
  3125. }
  3126. else {
  3127. var x = setupLength * bone.a, y = setupLength * bone.c;
  3128. var length_2 = Math.sqrt(x * x + y * y);
  3129. if (scale)
  3130. lengths[i] = length_2;
  3131. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length_2 / setupLength;
  3132. }
  3133. }
  3134. }
  3135. else {
  3136. for (var i = 1; i < spacesCount; i++)
  3137. spaces[i] = spacing;
  3138. }
  3139. var positions = this.computeWorldPositions(attachment, spacesCount, tangents, data.positionMode == spine.PositionMode.Percent, percentSpacing);
  3140. var boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  3141. var tip = false;
  3142. if (offsetRotation == 0)
  3143. tip = rotateMode == spine.RotateMode.Chain;
  3144. else {
  3145. tip = false;
  3146. var p = this.target.bone;
  3147. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  3148. }
  3149. for (var i = 0, p = 3; i < boneCount; i++, p += 3) {
  3150. var bone = bones[i];
  3151. bone.worldX += (boneX - bone.worldX) * translateMix;
  3152. bone.worldY += (boneY - bone.worldY) * translateMix;
  3153. var x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  3154. if (scale) {
  3155. var length_3 = lengths[i];
  3156. if (length_3 != 0) {
  3157. var s = (Math.sqrt(dx * dx + dy * dy) / length_3 - 1) * rotateMix + 1;
  3158. bone.a *= s;
  3159. bone.c *= s;
  3160. }
  3161. }
  3162. boneX = x;
  3163. boneY = y;
  3164. if (rotate) {
  3165. var a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
  3166. if (tangents)
  3167. r = positions[p - 1];
  3168. else if (spaces[i + 1] == 0)
  3169. r = positions[p + 2];
  3170. else
  3171. r = Math.atan2(dy, dx);
  3172. r -= Math.atan2(c, a);
  3173. if (tip) {
  3174. cos = Math.cos(r);
  3175. sin = Math.sin(r);
  3176. var length_4 = bone.data.length;
  3177. boneX += (length_4 * (cos * a - sin * c) - dx) * rotateMix;
  3178. boneY += (length_4 * (sin * a + cos * c) - dy) * rotateMix;
  3179. }
  3180. else {
  3181. r += offsetRotation;
  3182. }
  3183. if (r > spine.MathUtils.PI)
  3184. r -= spine.MathUtils.PI2;
  3185. else if (r < -spine.MathUtils.PI)
  3186. r += spine.MathUtils.PI2;
  3187. r *= rotateMix;
  3188. cos = Math.cos(r);
  3189. sin = Math.sin(r);
  3190. bone.a = cos * a - sin * c;
  3191. bone.b = cos * b - sin * d;
  3192. bone.c = sin * a + cos * c;
  3193. bone.d = sin * b + cos * d;
  3194. }
  3195. bone.appliedValid = false;
  3196. }
  3197. };
  3198. PathConstraint.prototype.computeWorldPositions = function (path, spacesCount, tangents, percentPosition, percentSpacing) {
  3199. var target = this.target;
  3200. var position = this.position;
  3201. var spaces = this.spaces, out = spine.Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  3202. var closed = path.closed;
  3203. var verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint.NONE;
  3204. if (!path.constantSpeed) {
  3205. var lengths = path.lengths;
  3206. curveCount -= closed ? 1 : 2;
  3207. var pathLength_1 = lengths[curveCount];
  3208. if (percentPosition)
  3209. position *= pathLength_1;
  3210. if (percentSpacing) {
  3211. for (var i = 1; i < spacesCount; i++)
  3212. spaces[i] *= pathLength_1;
  3213. }
  3214. world = spine.Utils.setArraySize(this.world, 8);
  3215. for (var i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  3216. var space = spaces[i];
  3217. position += space;
  3218. var p = position;
  3219. if (closed) {
  3220. p %= pathLength_1;
  3221. if (p < 0)
  3222. p += pathLength_1;
  3223. curve = 0;
  3224. }
  3225. else if (p < 0) {
  3226. if (prevCurve != PathConstraint.BEFORE) {
  3227. prevCurve = PathConstraint.BEFORE;
  3228. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  3229. }
  3230. this.addBeforePosition(p, world, 0, out, o);
  3231. continue;
  3232. }
  3233. else if (p > pathLength_1) {
  3234. if (prevCurve != PathConstraint.AFTER) {
  3235. prevCurve = PathConstraint.AFTER;
  3236. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  3237. }
  3238. this.addAfterPosition(p - pathLength_1, world, 0, out, o);
  3239. continue;
  3240. }
  3241. for (;; curve++) {
  3242. var length_5 = lengths[curve];
  3243. if (p > length_5)
  3244. continue;
  3245. if (curve == 0)
  3246. p /= length_5;
  3247. else {
  3248. var prev = lengths[curve - 1];
  3249. p = (p - prev) / (length_5 - prev);
  3250. }
  3251. break;
  3252. }
  3253. if (curve != prevCurve) {
  3254. prevCurve = curve;
  3255. if (closed && curve == curveCount) {
  3256. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  3257. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  3258. }
  3259. else
  3260. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  3261. }
  3262. this.addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o, tangents || (i > 0 && space == 0));
  3263. }
  3264. return out;
  3265. }
  3266. if (closed) {
  3267. verticesLength += 2;
  3268. world = spine.Utils.setArraySize(this.world, verticesLength);
  3269. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  3270. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  3271. world[verticesLength - 2] = world[0];
  3272. world[verticesLength - 1] = world[1];
  3273. }
  3274. else {
  3275. curveCount--;
  3276. verticesLength -= 4;
  3277. world = spine.Utils.setArraySize(this.world, verticesLength);
  3278. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  3279. }
  3280. var curves = spine.Utils.setArraySize(this.curves, curveCount);
  3281. var pathLength = 0;
  3282. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  3283. var tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  3284. for (var i = 0, w = 2; i < curveCount; i++, w += 6) {
  3285. cx1 = world[w];
  3286. cy1 = world[w + 1];
  3287. cx2 = world[w + 2];
  3288. cy2 = world[w + 3];
  3289. x2 = world[w + 4];
  3290. y2 = world[w + 5];
  3291. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  3292. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  3293. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  3294. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  3295. ddfx = tmpx * 2 + dddfx;
  3296. ddfy = tmpy * 2 + dddfy;
  3297. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  3298. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  3299. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3300. dfx += ddfx;
  3301. dfy += ddfy;
  3302. ddfx += dddfx;
  3303. ddfy += dddfy;
  3304. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3305. dfx += ddfx;
  3306. dfy += ddfy;
  3307. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3308. dfx += ddfx + dddfx;
  3309. dfy += ddfy + dddfy;
  3310. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3311. curves[i] = pathLength;
  3312. x1 = x2;
  3313. y1 = y2;
  3314. }
  3315. if (percentPosition)
  3316. position *= pathLength;
  3317. else
  3318. position *= pathLength / path.lengths[curveCount - 1];
  3319. if (percentSpacing) {
  3320. for (var i = 1; i < spacesCount; i++)
  3321. spaces[i] *= pathLength;
  3322. }
  3323. var segments = this.segments;
  3324. var curveLength = 0;
  3325. for (var i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  3326. var space = spaces[i];
  3327. position += space;
  3328. var p = position;
  3329. if (closed) {
  3330. p %= pathLength;
  3331. if (p < 0)
  3332. p += pathLength;
  3333. curve = 0;
  3334. }
  3335. else if (p < 0) {
  3336. this.addBeforePosition(p, world, 0, out, o);
  3337. continue;
  3338. }
  3339. else if (p > pathLength) {
  3340. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  3341. continue;
  3342. }
  3343. for (;; curve++) {
  3344. var length_6 = curves[curve];
  3345. if (p > length_6)
  3346. continue;
  3347. if (curve == 0)
  3348. p /= length_6;
  3349. else {
  3350. var prev = curves[curve - 1];
  3351. p = (p - prev) / (length_6 - prev);
  3352. }
  3353. break;
  3354. }
  3355. if (curve != prevCurve) {
  3356. prevCurve = curve;
  3357. var ii = curve * 6;
  3358. x1 = world[ii];
  3359. y1 = world[ii + 1];
  3360. cx1 = world[ii + 2];
  3361. cy1 = world[ii + 3];
  3362. cx2 = world[ii + 4];
  3363. cy2 = world[ii + 5];
  3364. x2 = world[ii + 6];
  3365. y2 = world[ii + 7];
  3366. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  3367. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  3368. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  3369. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  3370. ddfx = tmpx * 2 + dddfx;
  3371. ddfy = tmpy * 2 + dddfy;
  3372. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  3373. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  3374. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  3375. segments[0] = curveLength;
  3376. for (ii = 1; ii < 8; ii++) {
  3377. dfx += ddfx;
  3378. dfy += ddfy;
  3379. ddfx += dddfx;
  3380. ddfy += dddfy;
  3381. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3382. segments[ii] = curveLength;
  3383. }
  3384. dfx += ddfx;
  3385. dfy += ddfy;
  3386. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3387. segments[8] = curveLength;
  3388. dfx += ddfx + dddfx;
  3389. dfy += ddfy + dddfy;
  3390. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3391. segments[9] = curveLength;
  3392. segment = 0;
  3393. }
  3394. p *= curveLength;
  3395. for (;; segment++) {
  3396. var length_7 = segments[segment];
  3397. if (p > length_7)
  3398. continue;
  3399. if (segment == 0)
  3400. p /= length_7;
  3401. else {
  3402. var prev = segments[segment - 1];
  3403. p = segment + (p - prev) / (length_7 - prev);
  3404. }
  3405. break;
  3406. }
  3407. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  3408. }
  3409. return out;
  3410. };
  3411. PathConstraint.prototype.addBeforePosition = function (p, temp, i, out, o) {
  3412. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  3413. out[o] = x1 + p * Math.cos(r);
  3414. out[o + 1] = y1 + p * Math.sin(r);
  3415. out[o + 2] = r;
  3416. };
  3417. PathConstraint.prototype.addAfterPosition = function (p, temp, i, out, o) {
  3418. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  3419. out[o] = x1 + p * Math.cos(r);
  3420. out[o + 1] = y1 + p * Math.sin(r);
  3421. out[o + 2] = r;
  3422. };
  3423. PathConstraint.prototype.addCurvePosition = function (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  3424. if (p == 0 || isNaN(p)) {
  3425. out[o] = x1;
  3426. out[o + 1] = y1;
  3427. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  3428. return;
  3429. }
  3430. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  3431. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  3432. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  3433. out[o] = x;
  3434. out[o + 1] = y;
  3435. if (tangents) {
  3436. if (p < 0.001)
  3437. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  3438. else
  3439. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  3440. }
  3441. };
  3442. PathConstraint.NONE = -1;
  3443. PathConstraint.BEFORE = -2;
  3444. PathConstraint.AFTER = -3;
  3445. PathConstraint.epsilon = 0.00001;
  3446. return PathConstraint;
  3447. }());
  3448. spine.PathConstraint = PathConstraint;
  3449. })(spine || (spine = {}));
  3450. var spine;
  3451. (function (spine) {
  3452. var PathConstraintData = (function (_super) {
  3453. __extends(PathConstraintData, _super);
  3454. function PathConstraintData(name) {
  3455. var _this = _super.call(this, name, 0, false) || this;
  3456. _this.bones = new Array();
  3457. return _this;
  3458. }
  3459. return PathConstraintData;
  3460. }(spine.ConstraintData));
  3461. spine.PathConstraintData = PathConstraintData;
  3462. var PositionMode;
  3463. (function (PositionMode) {
  3464. PositionMode[PositionMode["Fixed"] = 0] = "Fixed";
  3465. PositionMode[PositionMode["Percent"] = 1] = "Percent";
  3466. })(PositionMode = spine.PositionMode || (spine.PositionMode = {}));
  3467. var SpacingMode;
  3468. (function (SpacingMode) {
  3469. SpacingMode[SpacingMode["Length"] = 0] = "Length";
  3470. SpacingMode[SpacingMode["Fixed"] = 1] = "Fixed";
  3471. SpacingMode[SpacingMode["Percent"] = 2] = "Percent";
  3472. })(SpacingMode = spine.SpacingMode || (spine.SpacingMode = {}));
  3473. var RotateMode;
  3474. (function (RotateMode) {
  3475. RotateMode[RotateMode["Tangent"] = 0] = "Tangent";
  3476. RotateMode[RotateMode["Chain"] = 1] = "Chain";
  3477. RotateMode[RotateMode["ChainScale"] = 2] = "ChainScale";
  3478. })(RotateMode = spine.RotateMode || (spine.RotateMode = {}));
  3479. })(spine || (spine = {}));
  3480. var spine;
  3481. (function (spine) {
  3482. var Assets = (function () {
  3483. function Assets(clientId) {
  3484. this.toLoad = new Array();
  3485. this.assets = {};
  3486. this.clientId = clientId;
  3487. }
  3488. Assets.prototype.loaded = function () {
  3489. var i = 0;
  3490. for (var v in this.assets)
  3491. i++;
  3492. return i;
  3493. };
  3494. return Assets;
  3495. }());
  3496. var SharedAssetManager = (function () {
  3497. function SharedAssetManager(pathPrefix) {
  3498. if (pathPrefix === void 0) { pathPrefix = ""; }
  3499. this.clientAssets = {};
  3500. this.queuedAssets = {};
  3501. this.rawAssets = {};
  3502. this.errors = {};
  3503. this.pathPrefix = pathPrefix;
  3504. }
  3505. SharedAssetManager.prototype.queueAsset = function (clientId, textureLoader, path) {
  3506. var clientAssets = this.clientAssets[clientId];
  3507. if (clientAssets === null || clientAssets === undefined) {
  3508. clientAssets = new Assets(clientId);
  3509. this.clientAssets[clientId] = clientAssets;
  3510. }
  3511. if (textureLoader !== null)
  3512. clientAssets.textureLoader = textureLoader;
  3513. clientAssets.toLoad.push(path);
  3514. if (this.queuedAssets[path] === path) {
  3515. return false;
  3516. }
  3517. else {
  3518. this.queuedAssets[path] = path;
  3519. return true;
  3520. }
  3521. };
  3522. SharedAssetManager.prototype.loadText = function (clientId, path) {
  3523. var _this = this;
  3524. path = this.pathPrefix + path;
  3525. if (!this.queueAsset(clientId, null, path))
  3526. return;
  3527. var request = new XMLHttpRequest();
  3528. request.overrideMimeType("text/html");
  3529. request.onreadystatechange = function () {
  3530. if (request.readyState == XMLHttpRequest.DONE) {
  3531. if (request.status >= 200 && request.status < 300) {
  3532. _this.rawAssets[path] = request.responseText;
  3533. }
  3534. else {
  3535. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3536. }
  3537. }
  3538. };
  3539. request.open("GET", path, true);
  3540. request.send();
  3541. };
  3542. SharedAssetManager.prototype.loadJson = function (clientId, path) {
  3543. var _this = this;
  3544. path = this.pathPrefix + path;
  3545. if (!this.queueAsset(clientId, null, path))
  3546. return;
  3547. var request = new XMLHttpRequest();
  3548. request.overrideMimeType("text/html");
  3549. request.onreadystatechange = function () {
  3550. if (request.readyState == XMLHttpRequest.DONE) {
  3551. if (request.status >= 200 && request.status < 300) {
  3552. _this.rawAssets[path] = JSON.parse(request.responseText);
  3553. }
  3554. else {
  3555. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3556. }
  3557. }
  3558. };
  3559. request.open("GET", path, true);
  3560. request.send();
  3561. };
  3562. SharedAssetManager.prototype.loadTexture = function (clientId, textureLoader, path) {
  3563. var _this = this;
  3564. path = this.pathPrefix + path;
  3565. if (!this.queueAsset(clientId, textureLoader, path))
  3566. return;
  3567. var img = new Image();
  3568. img.crossOrigin = "anonymous";
  3569. img.onload = function (ev) {
  3570. _this.rawAssets[path] = img;
  3571. };
  3572. img.onerror = function (ev) {
  3573. _this.errors[path] = "Couldn't load image " + path;
  3574. };
  3575. img.src = path;
  3576. };
  3577. SharedAssetManager.prototype.get = function (clientId, path) {
  3578. path = this.pathPrefix + path;
  3579. var clientAssets = this.clientAssets[clientId];
  3580. if (clientAssets === null || clientAssets === undefined)
  3581. return true;
  3582. return clientAssets.assets[path];
  3583. };
  3584. SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
  3585. for (var i = 0; i < clientAssets.toLoad.length; i++) {
  3586. var path = clientAssets.toLoad[i];
  3587. var asset = clientAssets.assets[path];
  3588. if (asset === null || asset === undefined) {
  3589. var rawAsset = this.rawAssets[path];
  3590. if (rawAsset === null || rawAsset === undefined)
  3591. continue;
  3592. if (rawAsset instanceof HTMLImageElement) {
  3593. clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
  3594. }
  3595. else {
  3596. clientAssets.assets[path] = rawAsset;
  3597. }
  3598. }
  3599. }
  3600. };
  3601. SharedAssetManager.prototype.isLoadingComplete = function (clientId) {
  3602. var clientAssets = this.clientAssets[clientId];
  3603. if (clientAssets === null || clientAssets === undefined)
  3604. return true;
  3605. this.updateClientAssets(clientAssets);
  3606. return clientAssets.toLoad.length == clientAssets.loaded();
  3607. };
  3608. SharedAssetManager.prototype.dispose = function () {
  3609. };
  3610. SharedAssetManager.prototype.hasErrors = function () {
  3611. return Object.keys(this.errors).length > 0;
  3612. };
  3613. SharedAssetManager.prototype.getErrors = function () {
  3614. return this.errors;
  3615. };
  3616. return SharedAssetManager;
  3617. }());
  3618. spine.SharedAssetManager = SharedAssetManager;
  3619. })(spine || (spine = {}));
  3620. var spine;
  3621. (function (spine) {
  3622. var Skeleton = (function () {
  3623. function Skeleton(data) {
  3624. this._updateCache = new Array();
  3625. this.updateCacheReset = new Array();
  3626. this.time = 0;
  3627. this.scaleX = 1;
  3628. this.scaleY = 1;
  3629. this.x = 0;
  3630. this.y = 0;
  3631. if (data == null)
  3632. throw new Error("data cannot be null.");
  3633. this.data = data;
  3634. this.bones = new Array();
  3635. for (var i = 0; i < data.bones.length; i++) {
  3636. var boneData = data.bones[i];
  3637. var bone = void 0;
  3638. if (boneData.parent == null)
  3639. bone = new spine.Bone(boneData, this, null);
  3640. else {
  3641. var parent_1 = this.bones[boneData.parent.index];
  3642. bone = new spine.Bone(boneData, this, parent_1);
  3643. parent_1.children.push(bone);
  3644. }
  3645. this.bones.push(bone);
  3646. }
  3647. this.slots = new Array();
  3648. this.drawOrder = new Array();
  3649. for (var i = 0; i < data.slots.length; i++) {
  3650. var slotData = data.slots[i];
  3651. var bone = this.bones[slotData.boneData.index];
  3652. var slot = new spine.Slot(slotData, bone);
  3653. this.slots.push(slot);
  3654. this.drawOrder.push(slot);
  3655. }
  3656. this.ikConstraints = new Array();
  3657. for (var i = 0; i < data.ikConstraints.length; i++) {
  3658. var ikConstraintData = data.ikConstraints[i];
  3659. this.ikConstraints.push(new spine.IkConstraint(ikConstraintData, this));
  3660. }
  3661. this.transformConstraints = new Array();
  3662. for (var i = 0; i < data.transformConstraints.length; i++) {
  3663. var transformConstraintData = data.transformConstraints[i];
  3664. this.transformConstraints.push(new spine.TransformConstraint(transformConstraintData, this));
  3665. }
  3666. this.pathConstraints = new Array();
  3667. for (var i = 0; i < data.pathConstraints.length; i++) {
  3668. var pathConstraintData = data.pathConstraints[i];
  3669. this.pathConstraints.push(new spine.PathConstraint(pathConstraintData, this));
  3670. }
  3671. this.color = new spine.Color(1, 1, 1, 1);
  3672. this.updateCache();
  3673. }
  3674. Skeleton.prototype.updateCache = function () {
  3675. var updateCache = this._updateCache;
  3676. updateCache.length = 0;
  3677. this.updateCacheReset.length = 0;
  3678. var bones = this.bones;
  3679. for (var i = 0, n = bones.length; i < n; i++) {
  3680. var bone = bones[i];
  3681. bone.sorted = bone.data.skinRequired;
  3682. bone.active = !bone.sorted;
  3683. }
  3684. if (this.skin != null) {
  3685. var skinBones = this.skin.bones;
  3686. for (var i = 0, n = this.skin.bones.length; i < n; i++) {
  3687. var bone = this.bones[skinBones[i].index];
  3688. do {
  3689. bone.sorted = false;
  3690. bone.active = true;
  3691. bone = bone.parent;
  3692. } while (bone != null);
  3693. }
  3694. }
  3695. var ikConstraints = this.ikConstraints;
  3696. var transformConstraints = this.transformConstraints;
  3697. var pathConstraints = this.pathConstraints;
  3698. var ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  3699. var constraintCount = ikCount + transformCount + pathCount;
  3700. outer: for (var i = 0; i < constraintCount; i++) {
  3701. for (var ii = 0; ii < ikCount; ii++) {
  3702. var constraint = ikConstraints[ii];
  3703. if (constraint.data.order == i) {
  3704. this.sortIkConstraint(constraint);
  3705. continue outer;
  3706. }
  3707. }
  3708. for (var ii = 0; ii < transformCount; ii++) {
  3709. var constraint = transformConstraints[ii];
  3710. if (constraint.data.order == i) {
  3711. this.sortTransformConstraint(constraint);
  3712. continue outer;
  3713. }
  3714. }
  3715. for (var ii = 0; ii < pathCount; ii++) {
  3716. var constraint = pathConstraints[ii];
  3717. if (constraint.data.order == i) {
  3718. this.sortPathConstraint(constraint);
  3719. continue outer;
  3720. }
  3721. }
  3722. }
  3723. for (var i = 0, n = bones.length; i < n; i++)
  3724. this.sortBone(bones[i]);
  3725. };
  3726. Skeleton.prototype.sortIkConstraint = function (constraint) {
  3727. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin != null && spine.Utils.contains(this.skin.constraints, constraint.data, true)));
  3728. if (!constraint.active)
  3729. return;
  3730. var target = constraint.target;
  3731. this.sortBone(target);
  3732. var constrained = constraint.bones;
  3733. var parent = constrained[0];
  3734. this.sortBone(parent);
  3735. if (constrained.length > 1) {
  3736. var child = constrained[constrained.length - 1];
  3737. if (!(this._updateCache.indexOf(child) > -1))
  3738. this.updateCacheReset.push(child);
  3739. }
  3740. this._updateCache.push(constraint);
  3741. this.sortReset(parent.children);
  3742. constrained[constrained.length - 1].sorted = true;
  3743. };
  3744. Skeleton.prototype.sortPathConstraint = function (constraint) {
  3745. constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || (this.skin != null && spine.Utils.contains(this.skin.constraints, constraint.data, true)));
  3746. if (!constraint.active)
  3747. return;
  3748. var slot = constraint.target;
  3749. var slotIndex = slot.data.index;
  3750. var slotBone = slot.bone;
  3751. if (this.skin != null)
  3752. this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  3753. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  3754. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  3755. for (var i = 0, n = this.data.skins.length; i < n; i++)
  3756. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  3757. var attachment = slot.getAttachment();
  3758. if (attachment instanceof spine.PathAttachment)
  3759. this.sortPathConstraintAttachmentWith(attachment, slotBone);
  3760. var constrained = constraint.bones;
  3761. var boneCount = constrained.length;
  3762. for (var i = 0; i < boneCount; i++)
  3763. this.sortBone(constrained[i]);
  3764. this._updateCache.push(constraint);
  3765. for (var i = 0; i < boneCount; i++)
  3766. this.sortReset(constrained[i].children);
  3767. for (var i = 0; i < boneCount; i++)
  3768. constrained[i].sorted = true;
  3769. };
  3770. Skeleton.prototype.sortTransformConstraint = function (constraint) {
  3771. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin != null && spine.Utils.contains(this.skin.constraints, constraint.data, true)));
  3772. if (!constraint.active)
  3773. return;
  3774. this.sortBone(constraint.target);
  3775. var constrained = constraint.bones;
  3776. var boneCount = constrained.length;
  3777. if (constraint.data.local) {
  3778. for (var i = 0; i < boneCount; i++) {
  3779. var child = constrained[i];
  3780. this.sortBone(child.parent);
  3781. if (!(this._updateCache.indexOf(child) > -1))
  3782. this.updateCacheReset.push(child);
  3783. }
  3784. }
  3785. else {
  3786. for (var i = 0; i < boneCount; i++) {
  3787. this.sortBone(constrained[i]);
  3788. }
  3789. }
  3790. this._updateCache.push(constraint);
  3791. for (var ii = 0; ii < boneCount; ii++)
  3792. this.sortReset(constrained[ii].children);
  3793. for (var ii = 0; ii < boneCount; ii++)
  3794. constrained[ii].sorted = true;
  3795. };
  3796. Skeleton.prototype.sortPathConstraintAttachment = function (skin, slotIndex, slotBone) {
  3797. var attachments = skin.attachments[slotIndex];
  3798. if (!attachments)
  3799. return;
  3800. for (var key in attachments) {
  3801. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  3802. }
  3803. };
  3804. Skeleton.prototype.sortPathConstraintAttachmentWith = function (attachment, slotBone) {
  3805. if (!(attachment instanceof spine.PathAttachment))
  3806. return;
  3807. var pathBones = attachment.bones;
  3808. if (pathBones == null)
  3809. this.sortBone(slotBone);
  3810. else {
  3811. var bones = this.bones;
  3812. var i = 0;
  3813. while (i < pathBones.length) {
  3814. var boneCount = pathBones[i++];
  3815. for (var n = i + boneCount; i < n; i++) {
  3816. var boneIndex = pathBones[i];
  3817. this.sortBone(bones[boneIndex]);
  3818. }
  3819. }
  3820. }
  3821. };
  3822. Skeleton.prototype.sortBone = function (bone) {
  3823. if (bone.sorted)
  3824. return;
  3825. var parent = bone.parent;
  3826. if (parent != null)
  3827. this.sortBone(parent);
  3828. bone.sorted = true;
  3829. this._updateCache.push(bone);
  3830. };
  3831. Skeleton.prototype.sortReset = function (bones) {
  3832. for (var i = 0, n = bones.length; i < n; i++) {
  3833. var bone = bones[i];
  3834. if (!bone.active)
  3835. continue;
  3836. if (bone.sorted)
  3837. this.sortReset(bone.children);
  3838. bone.sorted = false;
  3839. }
  3840. };
  3841. Skeleton.prototype.updateWorldTransform = function () {
  3842. var updateCacheReset = this.updateCacheReset;
  3843. for (var i = 0, n = updateCacheReset.length; i < n; i++) {
  3844. var bone = updateCacheReset[i];
  3845. bone.ax = bone.x;
  3846. bone.ay = bone.y;
  3847. bone.arotation = bone.rotation;
  3848. bone.ascaleX = bone.scaleX;
  3849. bone.ascaleY = bone.scaleY;
  3850. bone.ashearX = bone.shearX;
  3851. bone.ashearY = bone.shearY;
  3852. bone.appliedValid = true;
  3853. }
  3854. var updateCache = this._updateCache;
  3855. for (var i = 0, n = updateCache.length; i < n; i++)
  3856. updateCache[i].update();
  3857. };
  3858. Skeleton.prototype.setToSetupPose = function () {
  3859. this.setBonesToSetupPose();
  3860. this.setSlotsToSetupPose();
  3861. };
  3862. Skeleton.prototype.setBonesToSetupPose = function () {
  3863. var bones = this.bones;
  3864. for (var i = 0, n = bones.length; i < n; i++)
  3865. bones[i].setToSetupPose();
  3866. var ikConstraints = this.ikConstraints;
  3867. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  3868. var constraint = ikConstraints[i];
  3869. constraint.mix = constraint.data.mix;
  3870. constraint.softness = constraint.data.softness;
  3871. constraint.bendDirection = constraint.data.bendDirection;
  3872. constraint.compress = constraint.data.compress;
  3873. constraint.stretch = constraint.data.stretch;
  3874. }
  3875. var transformConstraints = this.transformConstraints;
  3876. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  3877. var constraint = transformConstraints[i];
  3878. var data = constraint.data;
  3879. constraint.rotateMix = data.rotateMix;
  3880. constraint.translateMix = data.translateMix;
  3881. constraint.scaleMix = data.scaleMix;
  3882. constraint.shearMix = data.shearMix;
  3883. }
  3884. var pathConstraints = this.pathConstraints;
  3885. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  3886. var constraint = pathConstraints[i];
  3887. var data = constraint.data;
  3888. constraint.position = data.position;
  3889. constraint.spacing = data.spacing;
  3890. constraint.rotateMix = data.rotateMix;
  3891. constraint.translateMix = data.translateMix;
  3892. }
  3893. };
  3894. Skeleton.prototype.setSlotsToSetupPose = function () {
  3895. var slots = this.slots;
  3896. spine.Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  3897. for (var i = 0, n = slots.length; i < n; i++)
  3898. slots[i].setToSetupPose();
  3899. };
  3900. Skeleton.prototype.getRootBone = function () {
  3901. if (this.bones.length == 0)
  3902. return null;
  3903. return this.bones[0];
  3904. };
  3905. Skeleton.prototype.findBone = function (boneName) {
  3906. if (boneName == null)
  3907. throw new Error("boneName cannot be null.");
  3908. var bones = this.bones;
  3909. for (var i = 0, n = bones.length; i < n; i++) {
  3910. var bone = bones[i];
  3911. if (bone.data.name == boneName)
  3912. return bone;
  3913. }
  3914. return null;
  3915. };
  3916. Skeleton.prototype.findBoneIndex = function (boneName) {
  3917. if (boneName == null)
  3918. throw new Error("boneName cannot be null.");
  3919. var bones = this.bones;
  3920. for (var i = 0, n = bones.length; i < n; i++)
  3921. if (bones[i].data.name == boneName)
  3922. return i;
  3923. return -1;
  3924. };
  3925. Skeleton.prototype.findSlot = function (slotName) {
  3926. if (slotName == null)
  3927. throw new Error("slotName cannot be null.");
  3928. var slots = this.slots;
  3929. for (var i = 0, n = slots.length; i < n; i++) {
  3930. var slot = slots[i];
  3931. if (slot.data.name == slotName)
  3932. return slot;
  3933. }
  3934. return null;
  3935. };
  3936. Skeleton.prototype.findSlotIndex = function (slotName) {
  3937. if (slotName == null)
  3938. throw new Error("slotName cannot be null.");
  3939. var slots = this.slots;
  3940. for (var i = 0, n = slots.length; i < n; i++)
  3941. if (slots[i].data.name == slotName)
  3942. return i;
  3943. return -1;
  3944. };
  3945. Skeleton.prototype.setSkinByName = function (skinName) {
  3946. var skin = this.data.findSkin(skinName);
  3947. if (skin == null)
  3948. throw new Error("Skin not found: " + skinName);
  3949. this.setSkin(skin);
  3950. };
  3951. Skeleton.prototype.setSkin = function (newSkin) {
  3952. if (newSkin == this.skin)
  3953. return;
  3954. if (newSkin != null) {
  3955. if (this.skin != null)
  3956. newSkin.attachAll(this, this.skin);
  3957. else {
  3958. var slots = this.slots;
  3959. for (var i = 0, n = slots.length; i < n; i++) {
  3960. var slot = slots[i];
  3961. var name_1 = slot.data.attachmentName;
  3962. if (name_1 != null) {
  3963. var attachment = newSkin.getAttachment(i, name_1);
  3964. if (attachment != null)
  3965. slot.setAttachment(attachment);
  3966. }
  3967. }
  3968. }
  3969. }
  3970. this.skin = newSkin;
  3971. this.updateCache();
  3972. };
  3973. Skeleton.prototype.getAttachmentByName = function (slotName, attachmentName) {
  3974. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  3975. };
  3976. Skeleton.prototype.getAttachment = function (slotIndex, attachmentName) {
  3977. if (attachmentName == null)
  3978. throw new Error("attachmentName cannot be null.");
  3979. if (this.skin != null) {
  3980. var attachment = this.skin.getAttachment(slotIndex, attachmentName);
  3981. if (attachment != null)
  3982. return attachment;
  3983. }
  3984. if (this.data.defaultSkin != null)
  3985. return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  3986. return null;
  3987. };
  3988. Skeleton.prototype.setAttachment = function (slotName, attachmentName) {
  3989. if (slotName == null)
  3990. throw new Error("slotName cannot be null.");
  3991. var slots = this.slots;
  3992. for (var i = 0, n = slots.length; i < n; i++) {
  3993. var slot = slots[i];
  3994. if (slot.data.name == slotName) {
  3995. var attachment = null;
  3996. if (attachmentName != null) {
  3997. attachment = this.getAttachment(i, attachmentName);
  3998. if (attachment == null)
  3999. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  4000. }
  4001. slot.setAttachment(attachment);
  4002. return;
  4003. }
  4004. }
  4005. throw new Error("Slot not found: " + slotName);
  4006. };
  4007. Skeleton.prototype.findIkConstraint = function (constraintName) {
  4008. if (constraintName == null)
  4009. throw new Error("constraintName cannot be null.");
  4010. var ikConstraints = this.ikConstraints;
  4011. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  4012. var ikConstraint = ikConstraints[i];
  4013. if (ikConstraint.data.name == constraintName)
  4014. return ikConstraint;
  4015. }
  4016. return null;
  4017. };
  4018. Skeleton.prototype.findTransformConstraint = function (constraintName) {
  4019. if (constraintName == null)
  4020. throw new Error("constraintName cannot be null.");
  4021. var transformConstraints = this.transformConstraints;
  4022. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  4023. var constraint = transformConstraints[i];
  4024. if (constraint.data.name == constraintName)
  4025. return constraint;
  4026. }
  4027. return null;
  4028. };
  4029. Skeleton.prototype.findPathConstraint = function (constraintName) {
  4030. if (constraintName == null)
  4031. throw new Error("constraintName cannot be null.");
  4032. var pathConstraints = this.pathConstraints;
  4033. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  4034. var constraint = pathConstraints[i];
  4035. if (constraint.data.name == constraintName)
  4036. return constraint;
  4037. }
  4038. return null;
  4039. };
  4040. Skeleton.prototype.getBounds = function (offset, size, temp) {
  4041. if (temp === void 0) { temp = new Array(2); }
  4042. if (offset == null)
  4043. throw new Error("offset cannot be null.");
  4044. if (size == null)
  4045. throw new Error("size cannot be null.");
  4046. var drawOrder = this.drawOrder;
  4047. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  4048. for (var i = 0, n = drawOrder.length; i < n; i++) {
  4049. var slot = drawOrder[i];
  4050. if (!slot.bone.active)
  4051. continue;
  4052. var verticesLength = 0;
  4053. var vertices = null;
  4054. var attachment = slot.getAttachment();
  4055. if (attachment instanceof spine.RegionAttachment) {
  4056. verticesLength = 8;
  4057. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  4058. attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  4059. }
  4060. else if (attachment instanceof spine.MeshAttachment) {
  4061. var mesh = attachment;
  4062. verticesLength = mesh.worldVerticesLength;
  4063. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  4064. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  4065. }
  4066. if (vertices != null) {
  4067. for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  4068. var x = vertices[ii], y = vertices[ii + 1];
  4069. minX = Math.min(minX, x);
  4070. minY = Math.min(minY, y);
  4071. maxX = Math.max(maxX, x);
  4072. maxY = Math.max(maxY, y);
  4073. }
  4074. }
  4075. }
  4076. offset.set(minX, minY);
  4077. size.set(maxX - minX, maxY - minY);
  4078. };
  4079. Skeleton.prototype.update = function (delta) {
  4080. this.time += delta;
  4081. };
  4082. return Skeleton;
  4083. }());
  4084. spine.Skeleton = Skeleton;
  4085. })(spine || (spine = {}));
  4086. var spine;
  4087. (function (spine) {
  4088. var SkeletonBinary = (function () {
  4089. function SkeletonBinary(attachmentLoader) {
  4090. this.scale = 1;
  4091. this.linkedMeshes = new Array();
  4092. this.attachmentLoader = attachmentLoader;
  4093. }
  4094. SkeletonBinary.prototype.readSkeletonData = function (binary) {
  4095. var scale = this.scale;
  4096. var skeletonData = new spine.SkeletonData();
  4097. skeletonData.name = "";
  4098. var input = new BinaryInput(binary);
  4099. skeletonData.hash = input.readString();
  4100. skeletonData.version = input.readString();
  4101. if ("3.8.75" == skeletonData.version)
  4102. throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
  4103. skeletonData.x = input.readFloat();
  4104. skeletonData.y = input.readFloat();
  4105. skeletonData.width = input.readFloat();
  4106. skeletonData.height = input.readFloat();
  4107. var nonessential = input.readBoolean();
  4108. if (nonessential) {
  4109. skeletonData.fps = input.readFloat();
  4110. skeletonData.imagesPath = input.readString();
  4111. skeletonData.audioPath = input.readString();
  4112. }
  4113. var n = 0;
  4114. n = input.readInt(true);
  4115. for (var i = 0; i < n; i++)
  4116. input.strings.push(input.readString());
  4117. n = input.readInt(true);
  4118. for (var i = 0; i < n; i++) {
  4119. var name_2 = input.readString();
  4120. var parent_2 = i == 0 ? null : skeletonData.bones[input.readInt(true)];
  4121. var data = new spine.BoneData(i, name_2, parent_2);
  4122. data.rotation = input.readFloat();
  4123. data.x = input.readFloat() * scale;
  4124. data.y = input.readFloat() * scale;
  4125. data.scaleX = input.readFloat();
  4126. data.scaleY = input.readFloat();
  4127. data.shearX = input.readFloat();
  4128. data.shearY = input.readFloat();
  4129. data.length = input.readFloat() * scale;
  4130. data.transformMode = SkeletonBinary.TransformModeValues[input.readInt(true)];
  4131. data.skinRequired = input.readBoolean();
  4132. if (nonessential)
  4133. spine.Color.rgba8888ToColor(data.color, input.readInt32());
  4134. skeletonData.bones.push(data);
  4135. }
  4136. n = input.readInt(true);
  4137. for (var i = 0; i < n; i++) {
  4138. var slotName = input.readString();
  4139. var boneData = skeletonData.bones[input.readInt(true)];
  4140. var data = new spine.SlotData(i, slotName, boneData);
  4141. spine.Color.rgba8888ToColor(data.color, input.readInt32());
  4142. var darkColor = input.readInt32();
  4143. if (darkColor != -1)
  4144. spine.Color.rgb888ToColor(data.darkColor = new spine.Color(), darkColor);
  4145. data.attachmentName = input.readStringRef();
  4146. data.blendMode = SkeletonBinary.BlendModeValues[input.readInt(true)];
  4147. skeletonData.slots.push(data);
  4148. }
  4149. n = input.readInt(true);
  4150. for (var i = 0, nn = void 0; i < n; i++) {
  4151. var data = new spine.IkConstraintData(input.readString());
  4152. data.order = input.readInt(true);
  4153. data.skinRequired = input.readBoolean();
  4154. nn = input.readInt(true);
  4155. for (var ii = 0; ii < nn; ii++)
  4156. data.bones.push(skeletonData.bones[input.readInt(true)]);
  4157. data.target = skeletonData.bones[input.readInt(true)];
  4158. data.mix = input.readFloat();
  4159. data.softness = input.readFloat() * scale;
  4160. data.bendDirection = input.readByte();
  4161. data.compress = input.readBoolean();
  4162. data.stretch = input.readBoolean();
  4163. data.uniform = input.readBoolean();
  4164. skeletonData.ikConstraints.push(data);
  4165. }
  4166. n = input.readInt(true);
  4167. for (var i = 0, nn = void 0; i < n; i++) {
  4168. var data = new spine.TransformConstraintData(input.readString());
  4169. data.order = input.readInt(true);
  4170. data.skinRequired = input.readBoolean();
  4171. nn = input.readInt(true);
  4172. for (var ii = 0; ii < nn; ii++)
  4173. data.bones.push(skeletonData.bones[input.readInt(true)]);
  4174. data.target = skeletonData.bones[input.readInt(true)];
  4175. data.local = input.readBoolean();
  4176. data.relative = input.readBoolean();
  4177. data.offsetRotation = input.readFloat();
  4178. data.offsetX = input.readFloat() * scale;
  4179. data.offsetY = input.readFloat() * scale;
  4180. data.offsetScaleX = input.readFloat();
  4181. data.offsetScaleY = input.readFloat();
  4182. data.offsetShearY = input.readFloat();
  4183. data.rotateMix = input.readFloat();
  4184. data.translateMix = input.readFloat();
  4185. data.scaleMix = input.readFloat();
  4186. data.shearMix = input.readFloat();
  4187. skeletonData.transformConstraints.push(data);
  4188. }
  4189. n = input.readInt(true);
  4190. for (var i = 0, nn = void 0; i < n; i++) {
  4191. var data = new spine.PathConstraintData(input.readString());
  4192. data.order = input.readInt(true);
  4193. data.skinRequired = input.readBoolean();
  4194. nn = input.readInt(true);
  4195. for (var ii = 0; ii < nn; ii++)
  4196. data.bones.push(skeletonData.bones[input.readInt(true)]);
  4197. data.target = skeletonData.slots[input.readInt(true)];
  4198. data.positionMode = SkeletonBinary.PositionModeValues[input.readInt(true)];
  4199. data.spacingMode = SkeletonBinary.SpacingModeValues[input.readInt(true)];
  4200. data.rotateMode = SkeletonBinary.RotateModeValues[input.readInt(true)];
  4201. data.offsetRotation = input.readFloat();
  4202. data.position = input.readFloat();
  4203. if (data.positionMode == spine.PositionMode.Fixed)
  4204. data.position *= scale;
  4205. data.spacing = input.readFloat();
  4206. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4207. data.spacing *= scale;
  4208. data.rotateMix = input.readFloat();
  4209. data.translateMix = input.readFloat();
  4210. skeletonData.pathConstraints.push(data);
  4211. }
  4212. var defaultSkin = this.readSkin(input, skeletonData, true, nonessential);
  4213. if (defaultSkin != null) {
  4214. skeletonData.defaultSkin = defaultSkin;
  4215. skeletonData.skins.push(defaultSkin);
  4216. }
  4217. {
  4218. var i = skeletonData.skins.length;
  4219. spine.Utils.setArraySize(skeletonData.skins, n = i + input.readInt(true));
  4220. for (; i < n; i++)
  4221. skeletonData.skins[i] = this.readSkin(input, skeletonData, false, nonessential);
  4222. }
  4223. n = this.linkedMeshes.length;
  4224. for (var i = 0; i < n; i++) {
  4225. var linkedMesh = this.linkedMeshes[i];
  4226. var skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  4227. if (skin == null)
  4228. throw new Error("Skin not found: " + linkedMesh.skin);
  4229. var parent_3 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  4230. if (parent_3 == null)
  4231. throw new Error("Parent mesh not found: " + linkedMesh.parent);
  4232. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent_3 : linkedMesh.mesh;
  4233. linkedMesh.mesh.setParentMesh(parent_3);
  4234. linkedMesh.mesh.updateUVs();
  4235. }
  4236. this.linkedMeshes.length = 0;
  4237. n = input.readInt(true);
  4238. for (var i = 0; i < n; i++) {
  4239. var data = new spine.EventData(input.readStringRef());
  4240. data.intValue = input.readInt(false);
  4241. data.floatValue = input.readFloat();
  4242. data.stringValue = input.readString();
  4243. data.audioPath = input.readString();
  4244. if (data.audioPath != null) {
  4245. data.volume = input.readFloat();
  4246. data.balance = input.readFloat();
  4247. }
  4248. skeletonData.events.push(data);
  4249. }
  4250. n = input.readInt(true);
  4251. for (var i = 0; i < n; i++)
  4252. skeletonData.animations.push(this.readAnimation(input, input.readString(), skeletonData));
  4253. return skeletonData;
  4254. };
  4255. SkeletonBinary.prototype.readSkin = function (input, skeletonData, defaultSkin, nonessential) {
  4256. var skin = null;
  4257. var slotCount = 0;
  4258. if (defaultSkin) {
  4259. slotCount = input.readInt(true);
  4260. if (slotCount == 0)
  4261. return null;
  4262. skin = new spine.Skin("default");
  4263. }
  4264. else {
  4265. skin = new spine.Skin(input.readStringRef());
  4266. skin.bones.length = input.readInt(true);
  4267. for (var i = 0, n = skin.bones.length; i < n; i++)
  4268. skin.bones[i] = skeletonData.bones[input.readInt(true)];
  4269. for (var i = 0, n = input.readInt(true); i < n; i++)
  4270. skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]);
  4271. for (var i = 0, n = input.readInt(true); i < n; i++)
  4272. skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]);
  4273. for (var i = 0, n = input.readInt(true); i < n; i++)
  4274. skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]);
  4275. slotCount = input.readInt(true);
  4276. }
  4277. for (var i = 0; i < slotCount; i++) {
  4278. var slotIndex = input.readInt(true);
  4279. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  4280. var name_3 = input.readStringRef();
  4281. var attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name_3, nonessential);
  4282. if (attachment != null)
  4283. skin.setAttachment(slotIndex, name_3, attachment);
  4284. }
  4285. }
  4286. return skin;
  4287. };
  4288. SkeletonBinary.prototype.readAttachment = function (input, skeletonData, skin, slotIndex, attachmentName, nonessential) {
  4289. var scale = this.scale;
  4290. var name = input.readStringRef();
  4291. if (name == null)
  4292. name = attachmentName;
  4293. var typeIndex = input.readByte();
  4294. var type = SkeletonBinary.AttachmentTypeValues[typeIndex];
  4295. switch (type) {
  4296. case spine.AttachmentType.Region: {
  4297. var path = input.readStringRef();
  4298. var rotation = input.readFloat();
  4299. var x = input.readFloat();
  4300. var y = input.readFloat();
  4301. var scaleX = input.readFloat();
  4302. var scaleY = input.readFloat();
  4303. var width = input.readFloat();
  4304. var height = input.readFloat();
  4305. var color = input.readInt32();
  4306. if (path == null)
  4307. path = name;
  4308. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  4309. if (region == null)
  4310. return null;
  4311. region.path = path;
  4312. region.x = x * scale;
  4313. region.y = y * scale;
  4314. region.scaleX = scaleX;
  4315. region.scaleY = scaleY;
  4316. region.rotation = rotation;
  4317. region.width = width * scale;
  4318. region.height = height * scale;
  4319. spine.Color.rgba8888ToColor(region.color, color);
  4320. region.updateOffset();
  4321. return region;
  4322. }
  4323. case spine.AttachmentType.BoundingBox: {
  4324. var vertexCount = input.readInt(true);
  4325. var vertices = this.readVertices(input, vertexCount);
  4326. var color = nonessential ? input.readInt32() : 0;
  4327. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  4328. if (box == null)
  4329. return null;
  4330. box.worldVerticesLength = vertexCount << 1;
  4331. box.vertices = vertices.vertices;
  4332. box.bones = vertices.bones;
  4333. if (nonessential)
  4334. spine.Color.rgba8888ToColor(box.color, color);
  4335. return box;
  4336. }
  4337. case spine.AttachmentType.Mesh: {
  4338. var path = input.readStringRef();
  4339. var color = input.readInt32();
  4340. var vertexCount = input.readInt(true);
  4341. var uvs = this.readFloatArray(input, vertexCount << 1, 1);
  4342. var triangles = this.readShortArray(input);
  4343. var vertices = this.readVertices(input, vertexCount);
  4344. var hullLength = input.readInt(true);
  4345. var edges = null;
  4346. var width = 0, height = 0;
  4347. if (nonessential) {
  4348. edges = this.readShortArray(input);
  4349. width = input.readFloat();
  4350. height = input.readFloat();
  4351. }
  4352. if (path == null)
  4353. path = name;
  4354. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4355. if (mesh == null)
  4356. return null;
  4357. mesh.path = path;
  4358. spine.Color.rgba8888ToColor(mesh.color, color);
  4359. mesh.bones = vertices.bones;
  4360. mesh.vertices = vertices.vertices;
  4361. mesh.worldVerticesLength = vertexCount << 1;
  4362. mesh.triangles = triangles;
  4363. mesh.regionUVs = uvs;
  4364. mesh.updateUVs();
  4365. mesh.hullLength = hullLength << 1;
  4366. if (nonessential) {
  4367. mesh.edges = edges;
  4368. mesh.width = width * scale;
  4369. mesh.height = height * scale;
  4370. }
  4371. return mesh;
  4372. }
  4373. case spine.AttachmentType.LinkedMesh: {
  4374. var path = input.readStringRef();
  4375. var color = input.readInt32();
  4376. var skinName = input.readStringRef();
  4377. var parent_4 = input.readStringRef();
  4378. var inheritDeform = input.readBoolean();
  4379. var width = 0, height = 0;
  4380. if (nonessential) {
  4381. width = input.readFloat();
  4382. height = input.readFloat();
  4383. }
  4384. if (path == null)
  4385. path = name;
  4386. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4387. if (mesh == null)
  4388. return null;
  4389. mesh.path = path;
  4390. spine.Color.rgba8888ToColor(mesh.color, color);
  4391. if (nonessential) {
  4392. mesh.width = width * scale;
  4393. mesh.height = height * scale;
  4394. }
  4395. this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent_4, inheritDeform));
  4396. return mesh;
  4397. }
  4398. case spine.AttachmentType.Path: {
  4399. var closed_1 = input.readBoolean();
  4400. var constantSpeed = input.readBoolean();
  4401. var vertexCount = input.readInt(true);
  4402. var vertices = this.readVertices(input, vertexCount);
  4403. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  4404. for (var i = 0, n = lengths.length; i < n; i++)
  4405. lengths[i] = input.readFloat() * scale;
  4406. var color = nonessential ? input.readInt32() : 0;
  4407. var path = this.attachmentLoader.newPathAttachment(skin, name);
  4408. if (path == null)
  4409. return null;
  4410. path.closed = closed_1;
  4411. path.constantSpeed = constantSpeed;
  4412. path.worldVerticesLength = vertexCount << 1;
  4413. path.vertices = vertices.vertices;
  4414. path.bones = vertices.bones;
  4415. path.lengths = lengths;
  4416. if (nonessential)
  4417. spine.Color.rgba8888ToColor(path.color, color);
  4418. return path;
  4419. }
  4420. case spine.AttachmentType.Point: {
  4421. var rotation = input.readFloat();
  4422. var x = input.readFloat();
  4423. var y = input.readFloat();
  4424. var color = nonessential ? input.readInt32() : 0;
  4425. var point = this.attachmentLoader.newPointAttachment(skin, name);
  4426. if (point == null)
  4427. return null;
  4428. point.x = x * scale;
  4429. point.y = y * scale;
  4430. point.rotation = rotation;
  4431. if (nonessential)
  4432. spine.Color.rgba8888ToColor(point.color, color);
  4433. return point;
  4434. }
  4435. case spine.AttachmentType.Clipping: {
  4436. var endSlotIndex = input.readInt(true);
  4437. var vertexCount = input.readInt(true);
  4438. var vertices = this.readVertices(input, vertexCount);
  4439. var color = nonessential ? input.readInt32() : 0;
  4440. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  4441. if (clip == null)
  4442. return null;
  4443. clip.endSlot = skeletonData.slots[endSlotIndex];
  4444. clip.worldVerticesLength = vertexCount << 1;
  4445. clip.vertices = vertices.vertices;
  4446. clip.bones = vertices.bones;
  4447. if (nonessential)
  4448. spine.Color.rgba8888ToColor(clip.color, color);
  4449. return clip;
  4450. }
  4451. }
  4452. return null;
  4453. };
  4454. SkeletonBinary.prototype.readVertices = function (input, vertexCount) {
  4455. var verticesLength = vertexCount << 1;
  4456. var vertices = new Vertices();
  4457. var scale = this.scale;
  4458. if (!input.readBoolean()) {
  4459. vertices.vertices = this.readFloatArray(input, verticesLength, scale);
  4460. return vertices;
  4461. }
  4462. var weights = new Array();
  4463. var bonesArray = new Array();
  4464. for (var i = 0; i < vertexCount; i++) {
  4465. var boneCount = input.readInt(true);
  4466. bonesArray.push(boneCount);
  4467. for (var ii = 0; ii < boneCount; ii++) {
  4468. bonesArray.push(input.readInt(true));
  4469. weights.push(input.readFloat() * scale);
  4470. weights.push(input.readFloat() * scale);
  4471. weights.push(input.readFloat());
  4472. }
  4473. }
  4474. vertices.vertices = spine.Utils.toFloatArray(weights);
  4475. vertices.bones = bonesArray;
  4476. return vertices;
  4477. };
  4478. SkeletonBinary.prototype.readFloatArray = function (input, n, scale) {
  4479. var array = new Array(n);
  4480. if (scale == 1) {
  4481. for (var i = 0; i < n; i++)
  4482. array[i] = input.readFloat();
  4483. }
  4484. else {
  4485. for (var i = 0; i < n; i++)
  4486. array[i] = input.readFloat() * scale;
  4487. }
  4488. return array;
  4489. };
  4490. SkeletonBinary.prototype.readShortArray = function (input) {
  4491. var n = input.readInt(true);
  4492. var array = new Array(n);
  4493. for (var i = 0; i < n; i++)
  4494. array[i] = input.readShort();
  4495. return array;
  4496. };
  4497. SkeletonBinary.prototype.readAnimation = function (input, name, skeletonData) {
  4498. var timelines = new Array();
  4499. var scale = this.scale;
  4500. var duration = 0;
  4501. var tempColor1 = new spine.Color();
  4502. var tempColor2 = new spine.Color();
  4503. for (var i = 0, n = input.readInt(true); i < n; i++) {
  4504. var slotIndex = input.readInt(true);
  4505. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  4506. var timelineType = input.readByte();
  4507. var frameCount = input.readInt(true);
  4508. switch (timelineType) {
  4509. case SkeletonBinary.SLOT_ATTACHMENT: {
  4510. var timeline = new spine.AttachmentTimeline(frameCount);
  4511. timeline.slotIndex = slotIndex;
  4512. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++)
  4513. timeline.setFrame(frameIndex, input.readFloat(), input.readStringRef());
  4514. timelines.push(timeline);
  4515. duration = Math.max(duration, timeline.frames[frameCount - 1]);
  4516. break;
  4517. }
  4518. case SkeletonBinary.SLOT_COLOR: {
  4519. var timeline = new spine.ColorTimeline(frameCount);
  4520. timeline.slotIndex = slotIndex;
  4521. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4522. var time = input.readFloat();
  4523. spine.Color.rgba8888ToColor(tempColor1, input.readInt32());
  4524. timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a);
  4525. if (frameIndex < frameCount - 1)
  4526. this.readCurve(input, frameIndex, timeline);
  4527. }
  4528. timelines.push(timeline);
  4529. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.ColorTimeline.ENTRIES]);
  4530. break;
  4531. }
  4532. case SkeletonBinary.SLOT_TWO_COLOR: {
  4533. var timeline = new spine.TwoColorTimeline(frameCount);
  4534. timeline.slotIndex = slotIndex;
  4535. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4536. var time = input.readFloat();
  4537. spine.Color.rgba8888ToColor(tempColor1, input.readInt32());
  4538. spine.Color.rgb888ToColor(tempColor2, input.readInt32());
  4539. timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a, tempColor2.r, tempColor2.g, tempColor2.b);
  4540. if (frameIndex < frameCount - 1)
  4541. this.readCurve(input, frameIndex, timeline);
  4542. }
  4543. timelines.push(timeline);
  4544. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.TwoColorTimeline.ENTRIES]);
  4545. break;
  4546. }
  4547. }
  4548. }
  4549. }
  4550. for (var i = 0, n = input.readInt(true); i < n; i++) {
  4551. var boneIndex = input.readInt(true);
  4552. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  4553. var timelineType = input.readByte();
  4554. var frameCount = input.readInt(true);
  4555. switch (timelineType) {
  4556. case SkeletonBinary.BONE_ROTATE: {
  4557. var timeline = new spine.RotateTimeline(frameCount);
  4558. timeline.boneIndex = boneIndex;
  4559. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4560. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat());
  4561. if (frameIndex < frameCount - 1)
  4562. this.readCurve(input, frameIndex, timeline);
  4563. }
  4564. timelines.push(timeline);
  4565. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.RotateTimeline.ENTRIES]);
  4566. break;
  4567. }
  4568. case SkeletonBinary.BONE_TRANSLATE:
  4569. case SkeletonBinary.BONE_SCALE:
  4570. case SkeletonBinary.BONE_SHEAR: {
  4571. var timeline = void 0;
  4572. var timelineScale = 1;
  4573. if (timelineType == SkeletonBinary.BONE_SCALE)
  4574. timeline = new spine.ScaleTimeline(frameCount);
  4575. else if (timelineType == SkeletonBinary.BONE_SHEAR)
  4576. timeline = new spine.ShearTimeline(frameCount);
  4577. else {
  4578. timeline = new spine.TranslateTimeline(frameCount);
  4579. timelineScale = scale;
  4580. }
  4581. timeline.boneIndex = boneIndex;
  4582. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4583. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat() * timelineScale);
  4584. if (frameIndex < frameCount - 1)
  4585. this.readCurve(input, frameIndex, timeline);
  4586. }
  4587. timelines.push(timeline);
  4588. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.TranslateTimeline.ENTRIES]);
  4589. break;
  4590. }
  4591. }
  4592. }
  4593. }
  4594. for (var i = 0, n = input.readInt(true); i < n; i++) {
  4595. var index = input.readInt(true);
  4596. var frameCount = input.readInt(true);
  4597. var timeline = new spine.IkConstraintTimeline(frameCount);
  4598. timeline.ikConstraintIndex = index;
  4599. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4600. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat() * scale, input.readByte(), input.readBoolean(), input.readBoolean());
  4601. if (frameIndex < frameCount - 1)
  4602. this.readCurve(input, frameIndex, timeline);
  4603. }
  4604. timelines.push(timeline);
  4605. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.IkConstraintTimeline.ENTRIES]);
  4606. }
  4607. for (var i = 0, n = input.readInt(true); i < n; i++) {
  4608. var index = input.readInt(true);
  4609. var frameCount = input.readInt(true);
  4610. var timeline = new spine.TransformConstraintTimeline(frameCount);
  4611. timeline.transformConstraintIndex = index;
  4612. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4613. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat());
  4614. if (frameIndex < frameCount - 1)
  4615. this.readCurve(input, frameIndex, timeline);
  4616. }
  4617. timelines.push(timeline);
  4618. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.TransformConstraintTimeline.ENTRIES]);
  4619. }
  4620. for (var i = 0, n = input.readInt(true); i < n; i++) {
  4621. var index = input.readInt(true);
  4622. var data = skeletonData.pathConstraints[index];
  4623. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  4624. var timelineType = input.readByte();
  4625. var frameCount = input.readInt(true);
  4626. switch (timelineType) {
  4627. case SkeletonBinary.PATH_POSITION:
  4628. case SkeletonBinary.PATH_SPACING: {
  4629. var timeline = void 0;
  4630. var timelineScale = 1;
  4631. if (timelineType == SkeletonBinary.PATH_SPACING) {
  4632. timeline = new spine.PathConstraintSpacingTimeline(frameCount);
  4633. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4634. timelineScale = scale;
  4635. }
  4636. else {
  4637. timeline = new spine.PathConstraintPositionTimeline(frameCount);
  4638. if (data.positionMode == spine.PositionMode.Fixed)
  4639. timelineScale = scale;
  4640. }
  4641. timeline.pathConstraintIndex = index;
  4642. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4643. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat() * timelineScale);
  4644. if (frameIndex < frameCount - 1)
  4645. this.readCurve(input, frameIndex, timeline);
  4646. }
  4647. timelines.push(timeline);
  4648. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.PathConstraintPositionTimeline.ENTRIES]);
  4649. break;
  4650. }
  4651. case SkeletonBinary.PATH_MIX: {
  4652. var timeline = new spine.PathConstraintMixTimeline(frameCount);
  4653. timeline.pathConstraintIndex = index;
  4654. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4655. timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readFloat());
  4656. if (frameIndex < frameCount - 1)
  4657. this.readCurve(input, frameIndex, timeline);
  4658. }
  4659. timelines.push(timeline);
  4660. duration = Math.max(duration, timeline.frames[(frameCount - 1) * spine.PathConstraintMixTimeline.ENTRIES]);
  4661. break;
  4662. }
  4663. }
  4664. }
  4665. }
  4666. for (var i = 0, n = input.readInt(true); i < n; i++) {
  4667. var skin = skeletonData.skins[input.readInt(true)];
  4668. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  4669. var slotIndex = input.readInt(true);
  4670. for (var iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
  4671. var attachment = skin.getAttachment(slotIndex, input.readStringRef());
  4672. var weighted = attachment.bones != null;
  4673. var vertices = attachment.vertices;
  4674. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  4675. var frameCount = input.readInt(true);
  4676. var timeline = new spine.DeformTimeline(frameCount);
  4677. timeline.slotIndex = slotIndex;
  4678. timeline.attachment = attachment;
  4679. for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) {
  4680. var time = input.readFloat();
  4681. var deform = void 0;
  4682. var end = input.readInt(true);
  4683. if (end == 0)
  4684. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  4685. else {
  4686. deform = spine.Utils.newFloatArray(deformLength);
  4687. var start = input.readInt(true);
  4688. end += start;
  4689. if (scale == 1) {
  4690. for (var v = start; v < end; v++)
  4691. deform[v] = input.readFloat();
  4692. }
  4693. else {
  4694. for (var v = start; v < end; v++)
  4695. deform[v] = input.readFloat() * scale;
  4696. }
  4697. if (!weighted) {
  4698. for (var v = 0, vn = deform.length; v < vn; v++)
  4699. deform[v] += vertices[v];
  4700. }
  4701. }
  4702. timeline.setFrame(frameIndex, time, deform);
  4703. if (frameIndex < frameCount - 1)
  4704. this.readCurve(input, frameIndex, timeline);
  4705. }
  4706. timelines.push(timeline);
  4707. duration = Math.max(duration, timeline.frames[frameCount - 1]);
  4708. }
  4709. }
  4710. }
  4711. var drawOrderCount = input.readInt(true);
  4712. if (drawOrderCount > 0) {
  4713. var timeline = new spine.DrawOrderTimeline(drawOrderCount);
  4714. var slotCount = skeletonData.slots.length;
  4715. for (var i = 0; i < drawOrderCount; i++) {
  4716. var time = input.readFloat();
  4717. var offsetCount = input.readInt(true);
  4718. var drawOrder = spine.Utils.newArray(slotCount, 0);
  4719. for (var ii = slotCount - 1; ii >= 0; ii--)
  4720. drawOrder[ii] = -1;
  4721. var unchanged = spine.Utils.newArray(slotCount - offsetCount, 0);
  4722. var originalIndex = 0, unchangedIndex = 0;
  4723. for (var ii = 0; ii < offsetCount; ii++) {
  4724. var slotIndex = input.readInt(true);
  4725. while (originalIndex != slotIndex)
  4726. unchanged[unchangedIndex++] = originalIndex++;
  4727. drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
  4728. }
  4729. while (originalIndex < slotCount)
  4730. unchanged[unchangedIndex++] = originalIndex++;
  4731. for (var ii = slotCount - 1; ii >= 0; ii--)
  4732. if (drawOrder[ii] == -1)
  4733. drawOrder[ii] = unchanged[--unchangedIndex];
  4734. timeline.setFrame(i, time, drawOrder);
  4735. }
  4736. timelines.push(timeline);
  4737. duration = Math.max(duration, timeline.frames[drawOrderCount - 1]);
  4738. }
  4739. var eventCount = input.readInt(true);
  4740. if (eventCount > 0) {
  4741. var timeline = new spine.EventTimeline(eventCount);
  4742. for (var i = 0; i < eventCount; i++) {
  4743. var time = input.readFloat();
  4744. var eventData = skeletonData.events[input.readInt(true)];
  4745. var event_4 = new spine.Event(time, eventData);
  4746. event_4.intValue = input.readInt(false);
  4747. event_4.floatValue = input.readFloat();
  4748. event_4.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
  4749. if (event_4.data.audioPath != null) {
  4750. event_4.volume = input.readFloat();
  4751. event_4.balance = input.readFloat();
  4752. }
  4753. timeline.setFrame(i, event_4);
  4754. }
  4755. timelines.push(timeline);
  4756. duration = Math.max(duration, timeline.frames[eventCount - 1]);
  4757. }
  4758. return new spine.Animation(name, timelines, duration);
  4759. };
  4760. SkeletonBinary.prototype.readCurve = function (input, frameIndex, timeline) {
  4761. switch (input.readByte()) {
  4762. case SkeletonBinary.CURVE_STEPPED:
  4763. timeline.setStepped(frameIndex);
  4764. break;
  4765. case SkeletonBinary.CURVE_BEZIER:
  4766. this.setCurve(timeline, frameIndex, input.readFloat(), input.readFloat(), input.readFloat(), input.readFloat());
  4767. break;
  4768. }
  4769. };
  4770. SkeletonBinary.prototype.setCurve = function (timeline, frameIndex, cx1, cy1, cx2, cy2) {
  4771. timeline.setCurve(frameIndex, cx1, cy1, cx2, cy2);
  4772. };
  4773. SkeletonBinary.AttachmentTypeValues = [0, 1, 2, 3, 4, 5, 6];
  4774. SkeletonBinary.TransformModeValues = [spine.TransformMode.Normal, spine.TransformMode.OnlyTranslation, spine.TransformMode.NoRotationOrReflection, spine.TransformMode.NoScale, spine.TransformMode.NoScaleOrReflection];
  4775. SkeletonBinary.PositionModeValues = [spine.PositionMode.Fixed, spine.PositionMode.Percent];
  4776. SkeletonBinary.SpacingModeValues = [spine.SpacingMode.Length, spine.SpacingMode.Fixed, spine.SpacingMode.Percent];
  4777. SkeletonBinary.RotateModeValues = [spine.RotateMode.Tangent, spine.RotateMode.Chain, spine.RotateMode.ChainScale];
  4778. SkeletonBinary.BlendModeValues = [spine.BlendMode.Normal, spine.BlendMode.Additive, spine.BlendMode.Multiply, spine.BlendMode.Screen];
  4779. SkeletonBinary.BONE_ROTATE = 0;
  4780. SkeletonBinary.BONE_TRANSLATE = 1;
  4781. SkeletonBinary.BONE_SCALE = 2;
  4782. SkeletonBinary.BONE_SHEAR = 3;
  4783. SkeletonBinary.SLOT_ATTACHMENT = 0;
  4784. SkeletonBinary.SLOT_COLOR = 1;
  4785. SkeletonBinary.SLOT_TWO_COLOR = 2;
  4786. SkeletonBinary.PATH_POSITION = 0;
  4787. SkeletonBinary.PATH_SPACING = 1;
  4788. SkeletonBinary.PATH_MIX = 2;
  4789. SkeletonBinary.CURVE_LINEAR = 0;
  4790. SkeletonBinary.CURVE_STEPPED = 1;
  4791. SkeletonBinary.CURVE_BEZIER = 2;
  4792. return SkeletonBinary;
  4793. }());
  4794. spine.SkeletonBinary = SkeletonBinary;
  4795. var BinaryInput = (function () {
  4796. function BinaryInput(data, strings, index, buffer) {
  4797. if (strings === void 0) { strings = new Array(); }
  4798. if (index === void 0) { index = 0; }
  4799. if (buffer === void 0) { buffer = new DataView(data.buffer); }
  4800. this.strings = strings;
  4801. this.index = index;
  4802. this.buffer = buffer;
  4803. }
  4804. BinaryInput.prototype.readByte = function () {
  4805. return this.buffer.getInt8(this.index++);
  4806. };
  4807. BinaryInput.prototype.readShort = function () {
  4808. var value = this.buffer.getInt16(this.index);
  4809. this.index += 2;
  4810. return value;
  4811. };
  4812. BinaryInput.prototype.readInt32 = function () {
  4813. var value = this.buffer.getInt32(this.index);
  4814. this.index += 4;
  4815. return value;
  4816. };
  4817. BinaryInput.prototype.readInt = function (optimizePositive) {
  4818. var b = this.readByte();
  4819. var result = b & 0x7F;
  4820. if ((b & 0x80) != 0) {
  4821. b = this.readByte();
  4822. result |= (b & 0x7F) << 7;
  4823. if ((b & 0x80) != 0) {
  4824. b = this.readByte();
  4825. result |= (b & 0x7F) << 14;
  4826. if ((b & 0x80) != 0) {
  4827. b = this.readByte();
  4828. result |= (b & 0x7F) << 21;
  4829. if ((b & 0x80) != 0) {
  4830. b = this.readByte();
  4831. result |= (b & 0x7F) << 28;
  4832. }
  4833. }
  4834. }
  4835. }
  4836. return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
  4837. };
  4838. BinaryInput.prototype.readStringRef = function () {
  4839. var index = this.readInt(true);
  4840. return index == 0 ? null : this.strings[index - 1];
  4841. };
  4842. BinaryInput.prototype.readString = function () {
  4843. var byteCount = this.readInt(true);
  4844. switch (byteCount) {
  4845. case 0:
  4846. return null;
  4847. case 1:
  4848. return "";
  4849. }
  4850. byteCount--;
  4851. var chars = "";
  4852. var charCount = 0;
  4853. for (var i = 0; i < byteCount;) {
  4854. var b = this.readByte();
  4855. switch (b >> 4) {
  4856. case 12:
  4857. case 13:
  4858. chars += String.fromCharCode(((b & 0x1F) << 6 | this.readByte() & 0x3F));
  4859. i += 2;
  4860. break;
  4861. case 14:
  4862. chars += String.fromCharCode(((b & 0x0F) << 12 | (this.readByte() & 0x3F) << 6 | this.readByte() & 0x3F));
  4863. i += 3;
  4864. break;
  4865. default:
  4866. chars += String.fromCharCode(b);
  4867. i++;
  4868. }
  4869. }
  4870. return chars;
  4871. };
  4872. BinaryInput.prototype.readFloat = function () {
  4873. var value = this.buffer.getFloat32(this.index);
  4874. this.index += 4;
  4875. return value;
  4876. };
  4877. BinaryInput.prototype.readBoolean = function () {
  4878. return this.readByte() != 0;
  4879. };
  4880. return BinaryInput;
  4881. }());
  4882. var LinkedMesh = (function () {
  4883. function LinkedMesh(mesh, skin, slotIndex, parent, inheritDeform) {
  4884. this.mesh = mesh;
  4885. this.skin = skin;
  4886. this.slotIndex = slotIndex;
  4887. this.parent = parent;
  4888. this.inheritDeform = inheritDeform;
  4889. }
  4890. return LinkedMesh;
  4891. }());
  4892. var Vertices = (function () {
  4893. function Vertices(bones, vertices) {
  4894. if (bones === void 0) { bones = null; }
  4895. if (vertices === void 0) { vertices = null; }
  4896. this.bones = bones;
  4897. this.vertices = vertices;
  4898. }
  4899. return Vertices;
  4900. }());
  4901. })(spine || (spine = {}));
  4902. var spine;
  4903. (function (spine) {
  4904. var SkeletonBounds = (function () {
  4905. function SkeletonBounds() {
  4906. this.minX = 0;
  4907. this.minY = 0;
  4908. this.maxX = 0;
  4909. this.maxY = 0;
  4910. this.boundingBoxes = new Array();
  4911. this.polygons = new Array();
  4912. this.polygonPool = new spine.Pool(function () {
  4913. return spine.Utils.newFloatArray(16);
  4914. });
  4915. }
  4916. SkeletonBounds.prototype.update = function (skeleton, updateAabb) {
  4917. if (skeleton == null)
  4918. throw new Error("skeleton cannot be null.");
  4919. var boundingBoxes = this.boundingBoxes;
  4920. var polygons = this.polygons;
  4921. var polygonPool = this.polygonPool;
  4922. var slots = skeleton.slots;
  4923. var slotCount = slots.length;
  4924. boundingBoxes.length = 0;
  4925. polygonPool.freeAll(polygons);
  4926. polygons.length = 0;
  4927. for (var i = 0; i < slotCount; i++) {
  4928. var slot = slots[i];
  4929. if (!slot.bone.active)
  4930. continue;
  4931. var attachment = slot.getAttachment();
  4932. if (attachment instanceof spine.BoundingBoxAttachment) {
  4933. var boundingBox = attachment;
  4934. boundingBoxes.push(boundingBox);
  4935. var polygon = polygonPool.obtain();
  4936. if (polygon.length != boundingBox.worldVerticesLength) {
  4937. polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength);
  4938. }
  4939. polygons.push(polygon);
  4940. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  4941. }
  4942. }
  4943. if (updateAabb) {
  4944. this.aabbCompute();
  4945. }
  4946. else {
  4947. this.minX = Number.POSITIVE_INFINITY;
  4948. this.minY = Number.POSITIVE_INFINITY;
  4949. this.maxX = Number.NEGATIVE_INFINITY;
  4950. this.maxY = Number.NEGATIVE_INFINITY;
  4951. }
  4952. };
  4953. SkeletonBounds.prototype.aabbCompute = function () {
  4954. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  4955. var polygons = this.polygons;
  4956. for (var i = 0, n = polygons.length; i < n; i++) {
  4957. var polygon = polygons[i];
  4958. var vertices = polygon;
  4959. for (var ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  4960. var x = vertices[ii];
  4961. var y = vertices[ii + 1];
  4962. minX = Math.min(minX, x);
  4963. minY = Math.min(minY, y);
  4964. maxX = Math.max(maxX, x);
  4965. maxY = Math.max(maxY, y);
  4966. }
  4967. }
  4968. this.minX = minX;
  4969. this.minY = minY;
  4970. this.maxX = maxX;
  4971. this.maxY = maxY;
  4972. };
  4973. SkeletonBounds.prototype.aabbContainsPoint = function (x, y) {
  4974. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  4975. };
  4976. SkeletonBounds.prototype.aabbIntersectsSegment = function (x1, y1, x2, y2) {
  4977. var minX = this.minX;
  4978. var minY = this.minY;
  4979. var maxX = this.maxX;
  4980. var maxY = this.maxY;
  4981. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  4982. return false;
  4983. var m = (y2 - y1) / (x2 - x1);
  4984. var y = m * (minX - x1) + y1;
  4985. if (y > minY && y < maxY)
  4986. return true;
  4987. y = m * (maxX - x1) + y1;
  4988. if (y > minY && y < maxY)
  4989. return true;
  4990. var x = (minY - y1) / m + x1;
  4991. if (x > minX && x < maxX)
  4992. return true;
  4993. x = (maxY - y1) / m + x1;
  4994. if (x > minX && x < maxX)
  4995. return true;
  4996. return false;
  4997. };
  4998. SkeletonBounds.prototype.aabbIntersectsSkeleton = function (bounds) {
  4999. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  5000. };
  5001. SkeletonBounds.prototype.containsPoint = function (x, y) {
  5002. var polygons = this.polygons;
  5003. for (var i = 0, n = polygons.length; i < n; i++)
  5004. if (this.containsPointPolygon(polygons[i], x, y))
  5005. return this.boundingBoxes[i];
  5006. return null;
  5007. };
  5008. SkeletonBounds.prototype.containsPointPolygon = function (polygon, x, y) {
  5009. var vertices = polygon;
  5010. var nn = polygon.length;
  5011. var prevIndex = nn - 2;
  5012. var inside = false;
  5013. for (var ii = 0; ii < nn; ii += 2) {
  5014. var vertexY = vertices[ii + 1];
  5015. var prevY = vertices[prevIndex + 1];
  5016. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  5017. var vertexX = vertices[ii];
  5018. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x)
  5019. inside = !inside;
  5020. }
  5021. prevIndex = ii;
  5022. }
  5023. return inside;
  5024. };
  5025. SkeletonBounds.prototype.intersectsSegment = function (x1, y1, x2, y2) {
  5026. var polygons = this.polygons;
  5027. for (var i = 0, n = polygons.length; i < n; i++)
  5028. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2))
  5029. return this.boundingBoxes[i];
  5030. return null;
  5031. };
  5032. SkeletonBounds.prototype.intersectsSegmentPolygon = function (polygon, x1, y1, x2, y2) {
  5033. var vertices = polygon;
  5034. var nn = polygon.length;
  5035. var width12 = x1 - x2, height12 = y1 - y2;
  5036. var det1 = x1 * y2 - y1 * x2;
  5037. var x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  5038. for (var ii = 0; ii < nn; ii += 2) {
  5039. var x4 = vertices[ii], y4 = vertices[ii + 1];
  5040. var det2 = x3 * y4 - y3 * x4;
  5041. var width34 = x3 - x4, height34 = y3 - y4;
  5042. var det3 = width12 * height34 - height12 * width34;
  5043. var x = (det1 * width34 - width12 * det2) / det3;
  5044. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  5045. var y = (det1 * height34 - height12 * det2) / det3;
  5046. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1)))
  5047. return true;
  5048. }
  5049. x3 = x4;
  5050. y3 = y4;
  5051. }
  5052. return false;
  5053. };
  5054. SkeletonBounds.prototype.getPolygon = function (boundingBox) {
  5055. if (boundingBox == null)
  5056. throw new Error("boundingBox cannot be null.");
  5057. var index = this.boundingBoxes.indexOf(boundingBox);
  5058. return index == -1 ? null : this.polygons[index];
  5059. };
  5060. SkeletonBounds.prototype.getWidth = function () {
  5061. return this.maxX - this.minX;
  5062. };
  5063. SkeletonBounds.prototype.getHeight = function () {
  5064. return this.maxY - this.minY;
  5065. };
  5066. return SkeletonBounds;
  5067. }());
  5068. spine.SkeletonBounds = SkeletonBounds;
  5069. })(spine || (spine = {}));
  5070. var spine;
  5071. (function (spine) {
  5072. var SkeletonClipping = (function () {
  5073. function SkeletonClipping() {
  5074. this.triangulator = new spine.Triangulator();
  5075. this.clippingPolygon = new Array();
  5076. this.clipOutput = new Array();
  5077. this.clippedVertices = new Array();
  5078. this.clippedTriangles = new Array();
  5079. this.scratch = new Array();
  5080. }
  5081. SkeletonClipping.prototype.clipStart = function (slot, clip) {
  5082. if (this.clipAttachment != null)
  5083. return 0;
  5084. this.clipAttachment = clip;
  5085. var n = clip.worldVerticesLength;
  5086. var vertices = spine.Utils.setArraySize(this.clippingPolygon, n);
  5087. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  5088. var clippingPolygon = this.clippingPolygon;
  5089. SkeletonClipping.makeClockwise(clippingPolygon);
  5090. var clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon));
  5091. for (var i = 0, n_2 = clippingPolygons.length; i < n_2; i++) {
  5092. var polygon = clippingPolygons[i];
  5093. SkeletonClipping.makeClockwise(polygon);
  5094. polygon.push(polygon[0]);
  5095. polygon.push(polygon[1]);
  5096. }
  5097. return clippingPolygons.length;
  5098. };
  5099. SkeletonClipping.prototype.clipEndWithSlot = function (slot) {
  5100. if (this.clipAttachment != null && this.clipAttachment.endSlot == slot.data)
  5101. this.clipEnd();
  5102. };
  5103. SkeletonClipping.prototype.clipEnd = function () {
  5104. if (this.clipAttachment == null)
  5105. return;
  5106. this.clipAttachment = null;
  5107. this.clippingPolygons = null;
  5108. this.clippedVertices.length = 0;
  5109. this.clippedTriangles.length = 0;
  5110. this.clippingPolygon.length = 0;
  5111. };
  5112. SkeletonClipping.prototype.isClipping = function () {
  5113. return this.clipAttachment != null;
  5114. };
  5115. SkeletonClipping.prototype.clipTriangles = function (vertices, verticesLength, triangles, trianglesLength, uvs, light, dark, twoColor) {
  5116. var clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
  5117. var clippedTriangles = this.clippedTriangles;
  5118. var polygons = this.clippingPolygons;
  5119. var polygonsCount = this.clippingPolygons.length;
  5120. var vertexSize = twoColor ? 12 : 8;
  5121. var index = 0;
  5122. clippedVertices.length = 0;
  5123. clippedTriangles.length = 0;
  5124. outer: for (var i = 0; i < trianglesLength; i += 3) {
  5125. var vertexOffset = triangles[i] << 1;
  5126. var x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
  5127. var u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
  5128. vertexOffset = triangles[i + 1] << 1;
  5129. var x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
  5130. var u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
  5131. vertexOffset = triangles[i + 2] << 1;
  5132. var x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
  5133. var u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
  5134. for (var p = 0; p < polygonsCount; p++) {
  5135. var s = clippedVertices.length;
  5136. if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
  5137. var clipOutputLength = clipOutput.length;
  5138. if (clipOutputLength == 0)
  5139. continue;
  5140. var d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
  5141. var d = 1 / (d0 * d2 + d1 * (y1 - y3));
  5142. var clipOutputCount = clipOutputLength >> 1;
  5143. var clipOutputItems = this.clipOutput;
  5144. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize);
  5145. for (var ii = 0; ii < clipOutputLength; ii += 2) {
  5146. var x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
  5147. clippedVerticesItems[s] = x;
  5148. clippedVerticesItems[s + 1] = y;
  5149. clippedVerticesItems[s + 2] = light.r;
  5150. clippedVerticesItems[s + 3] = light.g;
  5151. clippedVerticesItems[s + 4] = light.b;
  5152. clippedVerticesItems[s + 5] = light.a;
  5153. var c0 = x - x3, c1 = y - y3;
  5154. var a = (d0 * c0 + d1 * c1) * d;
  5155. var b = (d4 * c0 + d2 * c1) * d;
  5156. var c = 1 - a - b;
  5157. clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
  5158. clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c;
  5159. if (twoColor) {
  5160. clippedVerticesItems[s + 8] = dark.r;
  5161. clippedVerticesItems[s + 9] = dark.g;
  5162. clippedVerticesItems[s + 10] = dark.b;
  5163. clippedVerticesItems[s + 11] = dark.a;
  5164. }
  5165. s += vertexSize;
  5166. }
  5167. s = clippedTriangles.length;
  5168. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2));
  5169. clipOutputCount--;
  5170. for (var ii = 1; ii < clipOutputCount; ii++) {
  5171. clippedTrianglesItems[s] = index;
  5172. clippedTrianglesItems[s + 1] = (index + ii);
  5173. clippedTrianglesItems[s + 2] = (index + ii + 1);
  5174. s += 3;
  5175. }
  5176. index += clipOutputCount + 1;
  5177. }
  5178. else {
  5179. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + 3 * vertexSize);
  5180. clippedVerticesItems[s] = x1;
  5181. clippedVerticesItems[s + 1] = y1;
  5182. clippedVerticesItems[s + 2] = light.r;
  5183. clippedVerticesItems[s + 3] = light.g;
  5184. clippedVerticesItems[s + 4] = light.b;
  5185. clippedVerticesItems[s + 5] = light.a;
  5186. if (!twoColor) {
  5187. clippedVerticesItems[s + 6] = u1;
  5188. clippedVerticesItems[s + 7] = v1;
  5189. clippedVerticesItems[s + 8] = x2;
  5190. clippedVerticesItems[s + 9] = y2;
  5191. clippedVerticesItems[s + 10] = light.r;
  5192. clippedVerticesItems[s + 11] = light.g;
  5193. clippedVerticesItems[s + 12] = light.b;
  5194. clippedVerticesItems[s + 13] = light.a;
  5195. clippedVerticesItems[s + 14] = u2;
  5196. clippedVerticesItems[s + 15] = v2;
  5197. clippedVerticesItems[s + 16] = x3;
  5198. clippedVerticesItems[s + 17] = y3;
  5199. clippedVerticesItems[s + 18] = light.r;
  5200. clippedVerticesItems[s + 19] = light.g;
  5201. clippedVerticesItems[s + 20] = light.b;
  5202. clippedVerticesItems[s + 21] = light.a;
  5203. clippedVerticesItems[s + 22] = u3;
  5204. clippedVerticesItems[s + 23] = v3;
  5205. }
  5206. else {
  5207. clippedVerticesItems[s + 6] = u1;
  5208. clippedVerticesItems[s + 7] = v1;
  5209. clippedVerticesItems[s + 8] = dark.r;
  5210. clippedVerticesItems[s + 9] = dark.g;
  5211. clippedVerticesItems[s + 10] = dark.b;
  5212. clippedVerticesItems[s + 11] = dark.a;
  5213. clippedVerticesItems[s + 12] = x2;
  5214. clippedVerticesItems[s + 13] = y2;
  5215. clippedVerticesItems[s + 14] = light.r;
  5216. clippedVerticesItems[s + 15] = light.g;
  5217. clippedVerticesItems[s + 16] = light.b;
  5218. clippedVerticesItems[s + 17] = light.a;
  5219. clippedVerticesItems[s + 18] = u2;
  5220. clippedVerticesItems[s + 19] = v2;
  5221. clippedVerticesItems[s + 20] = dark.r;
  5222. clippedVerticesItems[s + 21] = dark.g;
  5223. clippedVerticesItems[s + 22] = dark.b;
  5224. clippedVerticesItems[s + 23] = dark.a;
  5225. clippedVerticesItems[s + 24] = x3;
  5226. clippedVerticesItems[s + 25] = y3;
  5227. clippedVerticesItems[s + 26] = light.r;
  5228. clippedVerticesItems[s + 27] = light.g;
  5229. clippedVerticesItems[s + 28] = light.b;
  5230. clippedVerticesItems[s + 29] = light.a;
  5231. clippedVerticesItems[s + 30] = u3;
  5232. clippedVerticesItems[s + 31] = v3;
  5233. clippedVerticesItems[s + 32] = dark.r;
  5234. clippedVerticesItems[s + 33] = dark.g;
  5235. clippedVerticesItems[s + 34] = dark.b;
  5236. clippedVerticesItems[s + 35] = dark.a;
  5237. }
  5238. s = clippedTriangles.length;
  5239. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3);
  5240. clippedTrianglesItems[s] = index;
  5241. clippedTrianglesItems[s + 1] = (index + 1);
  5242. clippedTrianglesItems[s + 2] = (index + 2);
  5243. index += 3;
  5244. continue outer;
  5245. }
  5246. }
  5247. }
  5248. };
  5249. SkeletonClipping.prototype.clip = function (x1, y1, x2, y2, x3, y3, clippingArea, output) {
  5250. var originalOutput = output;
  5251. var clipped = false;
  5252. var input = null;
  5253. if (clippingArea.length % 4 >= 2) {
  5254. input = output;
  5255. output = this.scratch;
  5256. }
  5257. else
  5258. input = this.scratch;
  5259. input.length = 0;
  5260. input.push(x1);
  5261. input.push(y1);
  5262. input.push(x2);
  5263. input.push(y2);
  5264. input.push(x3);
  5265. input.push(y3);
  5266. input.push(x1);
  5267. input.push(y1);
  5268. output.length = 0;
  5269. var clippingVertices = clippingArea;
  5270. var clippingVerticesLast = clippingArea.length - 4;
  5271. for (var i = 0;; i += 2) {
  5272. var edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
  5273. var edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
  5274. var deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
  5275. var inputVertices = input;
  5276. var inputVerticesLength = input.length - 2, outputStart = output.length;
  5277. for (var ii = 0; ii < inputVerticesLength; ii += 2) {
  5278. var inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
  5279. var inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
  5280. var side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
  5281. if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
  5282. if (side2) {
  5283. output.push(inputX2);
  5284. output.push(inputY2);
  5285. continue;
  5286. }
  5287. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  5288. var s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY);
  5289. if (Math.abs(s) > 0.000001) {
  5290. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s;
  5291. output.push(edgeX + (edgeX2 - edgeX) * ua);
  5292. output.push(edgeY + (edgeY2 - edgeY) * ua);
  5293. }
  5294. else {
  5295. output.push(edgeX);
  5296. output.push(edgeY);
  5297. }
  5298. }
  5299. else if (side2) {
  5300. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  5301. var s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY);
  5302. if (Math.abs(s) > 0.000001) {
  5303. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s;
  5304. output.push(edgeX + (edgeX2 - edgeX) * ua);
  5305. output.push(edgeY + (edgeY2 - edgeY) * ua);
  5306. }
  5307. else {
  5308. output.push(edgeX);
  5309. output.push(edgeY);
  5310. }
  5311. output.push(inputX2);
  5312. output.push(inputY2);
  5313. }
  5314. clipped = true;
  5315. }
  5316. if (outputStart == output.length) {
  5317. originalOutput.length = 0;
  5318. return true;
  5319. }
  5320. output.push(output[0]);
  5321. output.push(output[1]);
  5322. if (i == clippingVerticesLast)
  5323. break;
  5324. var temp = output;
  5325. output = input;
  5326. output.length = 0;
  5327. input = temp;
  5328. }
  5329. if (originalOutput != output) {
  5330. originalOutput.length = 0;
  5331. for (var i = 0, n = output.length - 2; i < n; i++)
  5332. originalOutput[i] = output[i];
  5333. }
  5334. else
  5335. originalOutput.length = originalOutput.length - 2;
  5336. return clipped;
  5337. };
  5338. SkeletonClipping.makeClockwise = function (polygon) {
  5339. var vertices = polygon;
  5340. var verticeslength = polygon.length;
  5341. var area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0;
  5342. for (var i = 0, n = verticeslength - 3; i < n; i += 2) {
  5343. p1x = vertices[i];
  5344. p1y = vertices[i + 1];
  5345. p2x = vertices[i + 2];
  5346. p2y = vertices[i + 3];
  5347. area += p1x * p2y - p2x * p1y;
  5348. }
  5349. if (area < 0)
  5350. return;
  5351. for (var i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
  5352. var x = vertices[i], y = vertices[i + 1];
  5353. var other = lastX - i;
  5354. vertices[i] = vertices[other];
  5355. vertices[i + 1] = vertices[other + 1];
  5356. vertices[other] = x;
  5357. vertices[other + 1] = y;
  5358. }
  5359. };
  5360. return SkeletonClipping;
  5361. }());
  5362. spine.SkeletonClipping = SkeletonClipping;
  5363. })(spine || (spine = {}));
  5364. var spine;
  5365. (function (spine) {
  5366. var SkeletonData = (function () {
  5367. function SkeletonData() {
  5368. this.bones = new Array();
  5369. this.slots = new Array();
  5370. this.skins = new Array();
  5371. this.events = new Array();
  5372. this.animations = new Array();
  5373. this.ikConstraints = new Array();
  5374. this.transformConstraints = new Array();
  5375. this.pathConstraints = new Array();
  5376. this.fps = 0;
  5377. }
  5378. SkeletonData.prototype.findBone = function (boneName) {
  5379. if (boneName == null)
  5380. throw new Error("boneName cannot be null.");
  5381. var bones = this.bones;
  5382. for (var i = 0, n = bones.length; i < n; i++) {
  5383. var bone = bones[i];
  5384. if (bone.name == boneName)
  5385. return bone;
  5386. }
  5387. return null;
  5388. };
  5389. SkeletonData.prototype.findBoneIndex = function (boneName) {
  5390. if (boneName == null)
  5391. throw new Error("boneName cannot be null.");
  5392. var bones = this.bones;
  5393. for (var i = 0, n = bones.length; i < n; i++)
  5394. if (bones[i].name == boneName)
  5395. return i;
  5396. return -1;
  5397. };
  5398. SkeletonData.prototype.findSlot = function (slotName) {
  5399. if (slotName == null)
  5400. throw new Error("slotName cannot be null.");
  5401. var slots = this.slots;
  5402. for (var i = 0, n = slots.length; i < n; i++) {
  5403. var slot = slots[i];
  5404. if (slot.name == slotName)
  5405. return slot;
  5406. }
  5407. return null;
  5408. };
  5409. SkeletonData.prototype.findSlotIndex = function (slotName) {
  5410. if (slotName == null)
  5411. throw new Error("slotName cannot be null.");
  5412. var slots = this.slots;
  5413. for (var i = 0, n = slots.length; i < n; i++)
  5414. if (slots[i].name == slotName)
  5415. return i;
  5416. return -1;
  5417. };
  5418. SkeletonData.prototype.findSkin = function (skinName) {
  5419. if (skinName == null)
  5420. throw new Error("skinName cannot be null.");
  5421. var skins = this.skins;
  5422. for (var i = 0, n = skins.length; i < n; i++) {
  5423. var skin = skins[i];
  5424. if (skin.name == skinName)
  5425. return skin;
  5426. }
  5427. return null;
  5428. };
  5429. SkeletonData.prototype.findEvent = function (eventDataName) {
  5430. if (eventDataName == null)
  5431. throw new Error("eventDataName cannot be null.");
  5432. var events = this.events;
  5433. for (var i = 0, n = events.length; i < n; i++) {
  5434. var event_5 = events[i];
  5435. if (event_5.name == eventDataName)
  5436. return event_5;
  5437. }
  5438. return null;
  5439. };
  5440. SkeletonData.prototype.findAnimation = function (animationName) {
  5441. if (animationName == null)
  5442. throw new Error("animationName cannot be null.");
  5443. var animations = this.animations;
  5444. for (var i = 0, n = animations.length; i < n; i++) {
  5445. var animation = animations[i];
  5446. if (animation.name == animationName)
  5447. return animation;
  5448. }
  5449. return null;
  5450. };
  5451. SkeletonData.prototype.findIkConstraint = function (constraintName) {
  5452. if (constraintName == null)
  5453. throw new Error("constraintName cannot be null.");
  5454. var ikConstraints = this.ikConstraints;
  5455. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  5456. var constraint = ikConstraints[i];
  5457. if (constraint.name == constraintName)
  5458. return constraint;
  5459. }
  5460. return null;
  5461. };
  5462. SkeletonData.prototype.findTransformConstraint = function (constraintName) {
  5463. if (constraintName == null)
  5464. throw new Error("constraintName cannot be null.");
  5465. var transformConstraints = this.transformConstraints;
  5466. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  5467. var constraint = transformConstraints[i];
  5468. if (constraint.name == constraintName)
  5469. return constraint;
  5470. }
  5471. return null;
  5472. };
  5473. SkeletonData.prototype.findPathConstraint = function (constraintName) {
  5474. if (constraintName == null)
  5475. throw new Error("constraintName cannot be null.");
  5476. var pathConstraints = this.pathConstraints;
  5477. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  5478. var constraint = pathConstraints[i];
  5479. if (constraint.name == constraintName)
  5480. return constraint;
  5481. }
  5482. return null;
  5483. };
  5484. SkeletonData.prototype.findPathConstraintIndex = function (pathConstraintName) {
  5485. if (pathConstraintName == null)
  5486. throw new Error("pathConstraintName cannot be null.");
  5487. var pathConstraints = this.pathConstraints;
  5488. for (var i = 0, n = pathConstraints.length; i < n; i++)
  5489. if (pathConstraints[i].name == pathConstraintName)
  5490. return i;
  5491. return -1;
  5492. };
  5493. return SkeletonData;
  5494. }());
  5495. spine.SkeletonData = SkeletonData;
  5496. })(spine || (spine = {}));
  5497. var spine;
  5498. (function (spine) {
  5499. var SkeletonJson = (function () {
  5500. function SkeletonJson(attachmentLoader) {
  5501. this.scale = 1;
  5502. this.linkedMeshes = new Array();
  5503. this.attachmentLoader = attachmentLoader;
  5504. }
  5505. SkeletonJson.prototype.readSkeletonData = function (json) {
  5506. var scale = this.scale;
  5507. var skeletonData = new spine.SkeletonData();
  5508. var root = typeof (json) === "string" ? JSON.parse(json) : json;
  5509. var skeletonMap = root.skeleton;
  5510. if (skeletonMap != null) {
  5511. skeletonData.hash = skeletonMap.hash;
  5512. skeletonData.version = skeletonMap.spine;
  5513. if ("3.8.75" == skeletonData.version)
  5514. throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
  5515. skeletonData.x = skeletonMap.x;
  5516. skeletonData.y = skeletonMap.y;
  5517. skeletonData.width = skeletonMap.width;
  5518. skeletonData.height = skeletonMap.height;
  5519. skeletonData.fps = skeletonMap.fps;
  5520. skeletonData.imagesPath = skeletonMap.images;
  5521. }
  5522. if (root.bones) {
  5523. for (var i = 0; i < root.bones.length; i++) {
  5524. var boneMap = root.bones[i];
  5525. var parent_5 = null;
  5526. var parentName = this.getValue(boneMap, "parent", null);
  5527. if (parentName != null) {
  5528. parent_5 = skeletonData.findBone(parentName);
  5529. if (parent_5 == null)
  5530. throw new Error("Parent bone not found: " + parentName);
  5531. }
  5532. var data = new spine.BoneData(skeletonData.bones.length, boneMap.name, parent_5);
  5533. data.length = this.getValue(boneMap, "length", 0) * scale;
  5534. data.x = this.getValue(boneMap, "x", 0) * scale;
  5535. data.y = this.getValue(boneMap, "y", 0) * scale;
  5536. data.rotation = this.getValue(boneMap, "rotation", 0);
  5537. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  5538. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  5539. data.shearX = this.getValue(boneMap, "shearX", 0);
  5540. data.shearY = this.getValue(boneMap, "shearY", 0);
  5541. data.transformMode = SkeletonJson.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  5542. data.skinRequired = this.getValue(boneMap, "skin", false);
  5543. skeletonData.bones.push(data);
  5544. }
  5545. }
  5546. if (root.slots) {
  5547. for (var i = 0; i < root.slots.length; i++) {
  5548. var slotMap = root.slots[i];
  5549. var slotName = slotMap.name;
  5550. var boneName = slotMap.bone;
  5551. var boneData = skeletonData.findBone(boneName);
  5552. if (boneData == null)
  5553. throw new Error("Slot bone not found: " + boneName);
  5554. var data = new spine.SlotData(skeletonData.slots.length, slotName, boneData);
  5555. var color = this.getValue(slotMap, "color", null);
  5556. if (color != null)
  5557. data.color.setFromString(color);
  5558. var dark = this.getValue(slotMap, "dark", null);
  5559. if (dark != null) {
  5560. data.darkColor = new spine.Color(1, 1, 1, 1);
  5561. data.darkColor.setFromString(dark);
  5562. }
  5563. data.attachmentName = this.getValue(slotMap, "attachment", null);
  5564. data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  5565. skeletonData.slots.push(data);
  5566. }
  5567. }
  5568. if (root.ik) {
  5569. for (var i = 0; i < root.ik.length; i++) {
  5570. var constraintMap = root.ik[i];
  5571. var data = new spine.IkConstraintData(constraintMap.name);
  5572. data.order = this.getValue(constraintMap, "order", 0);
  5573. data.skinRequired = this.getValue(constraintMap, "skin", false);
  5574. for (var j = 0; j < constraintMap.bones.length; j++) {
  5575. var boneName = constraintMap.bones[j];
  5576. var bone = skeletonData.findBone(boneName);
  5577. if (bone == null)
  5578. throw new Error("IK bone not found: " + boneName);
  5579. data.bones.push(bone);
  5580. }
  5581. var targetName = constraintMap.target;
  5582. data.target = skeletonData.findBone(targetName);
  5583. if (data.target == null)
  5584. throw new Error("IK target bone not found: " + targetName);
  5585. data.mix = this.getValue(constraintMap, "mix", 1);
  5586. data.softness = this.getValue(constraintMap, "softness", 0) * scale;
  5587. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  5588. data.compress = this.getValue(constraintMap, "compress", false);
  5589. data.stretch = this.getValue(constraintMap, "stretch", false);
  5590. data.uniform = this.getValue(constraintMap, "uniform", false);
  5591. skeletonData.ikConstraints.push(data);
  5592. }
  5593. }
  5594. if (root.transform) {
  5595. for (var i = 0; i < root.transform.length; i++) {
  5596. var constraintMap = root.transform[i];
  5597. var data = new spine.TransformConstraintData(constraintMap.name);
  5598. data.order = this.getValue(constraintMap, "order", 0);
  5599. data.skinRequired = this.getValue(constraintMap, "skin", false);
  5600. for (var j = 0; j < constraintMap.bones.length; j++) {
  5601. var boneName = constraintMap.bones[j];
  5602. var bone = skeletonData.findBone(boneName);
  5603. if (bone == null)
  5604. throw new Error("Transform constraint bone not found: " + boneName);
  5605. data.bones.push(bone);
  5606. }
  5607. var targetName = constraintMap.target;
  5608. data.target = skeletonData.findBone(targetName);
  5609. if (data.target == null)
  5610. throw new Error("Transform constraint target bone not found: " + targetName);
  5611. data.local = this.getValue(constraintMap, "local", false);
  5612. data.relative = this.getValue(constraintMap, "relative", false);
  5613. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  5614. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  5615. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  5616. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  5617. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  5618. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  5619. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  5620. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  5621. data.scaleMix = this.getValue(constraintMap, "scaleMix", 1);
  5622. data.shearMix = this.getValue(constraintMap, "shearMix", 1);
  5623. skeletonData.transformConstraints.push(data);
  5624. }
  5625. }
  5626. if (root.path) {
  5627. for (var i = 0; i < root.path.length; i++) {
  5628. var constraintMap = root.path[i];
  5629. var data = new spine.PathConstraintData(constraintMap.name);
  5630. data.order = this.getValue(constraintMap, "order", 0);
  5631. data.skinRequired = this.getValue(constraintMap, "skin", false);
  5632. for (var j = 0; j < constraintMap.bones.length; j++) {
  5633. var boneName = constraintMap.bones[j];
  5634. var bone = skeletonData.findBone(boneName);
  5635. if (bone == null)
  5636. throw new Error("Transform constraint bone not found: " + boneName);
  5637. data.bones.push(bone);
  5638. }
  5639. var targetName = constraintMap.target;
  5640. data.target = skeletonData.findSlot(targetName);
  5641. if (data.target == null)
  5642. throw new Error("Path target slot not found: " + targetName);
  5643. data.positionMode = SkeletonJson.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  5644. data.spacingMode = SkeletonJson.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  5645. data.rotateMode = SkeletonJson.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  5646. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  5647. data.position = this.getValue(constraintMap, "position", 0);
  5648. if (data.positionMode == spine.PositionMode.Fixed)
  5649. data.position *= scale;
  5650. data.spacing = this.getValue(constraintMap, "spacing", 0);
  5651. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  5652. data.spacing *= scale;
  5653. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  5654. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  5655. skeletonData.pathConstraints.push(data);
  5656. }
  5657. }
  5658. if (root.skins) {
  5659. for (var i = 0; i < root.skins.length; i++) {
  5660. var skinMap = root.skins[i];
  5661. var skin = new spine.Skin(skinMap.name);
  5662. if (skinMap.bones) {
  5663. for (var ii = 0; ii < skinMap.bones.length; ii++) {
  5664. var bone = skeletonData.findBone(skinMap.bones[ii]);
  5665. if (bone == null)
  5666. throw new Error("Skin bone not found: " + skinMap.bones[i]);
  5667. skin.bones.push(bone);
  5668. }
  5669. }
  5670. if (skinMap.ik) {
  5671. for (var ii = 0; ii < skinMap.ik.length; ii++) {
  5672. var constraint = skeletonData.findIkConstraint(skinMap.ik[ii]);
  5673. if (constraint == null)
  5674. throw new Error("Skin IK constraint not found: " + skinMap.ik[i]);
  5675. skin.constraints.push(constraint);
  5676. }
  5677. }
  5678. if (skinMap.transform) {
  5679. for (var ii = 0; ii < skinMap.transform.length; ii++) {
  5680. var constraint = skeletonData.findTransformConstraint(skinMap.transform[ii]);
  5681. if (constraint == null)
  5682. throw new Error("Skin transform constraint not found: " + skinMap.transform[i]);
  5683. skin.constraints.push(constraint);
  5684. }
  5685. }
  5686. if (skinMap.path) {
  5687. for (var ii = 0; ii < skinMap.path.length; ii++) {
  5688. var constraint = skeletonData.findPathConstraint(skinMap.path[ii]);
  5689. if (constraint == null)
  5690. throw new Error("Skin path constraint not found: " + skinMap.path[i]);
  5691. skin.constraints.push(constraint);
  5692. }
  5693. }
  5694. for (var slotName in skinMap.attachments) {
  5695. var slot = skeletonData.findSlot(slotName);
  5696. if (slot == null)
  5697. throw new Error("Slot not found: " + slotName);
  5698. var slotMap = skinMap.attachments[slotName];
  5699. for (var entryName in slotMap) {
  5700. var attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
  5701. if (attachment != null)
  5702. skin.setAttachment(slot.index, entryName, attachment);
  5703. }
  5704. }
  5705. skeletonData.skins.push(skin);
  5706. if (skin.name == "default")
  5707. skeletonData.defaultSkin = skin;
  5708. }
  5709. }
  5710. for (var i = 0, n = this.linkedMeshes.length; i < n; i++) {
  5711. var linkedMesh = this.linkedMeshes[i];
  5712. var skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  5713. if (skin == null)
  5714. throw new Error("Skin not found: " + linkedMesh.skin);
  5715. var parent_6 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  5716. if (parent_6 == null)
  5717. throw new Error("Parent mesh not found: " + linkedMesh.parent);
  5718. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent_6 : linkedMesh.mesh;
  5719. linkedMesh.mesh.setParentMesh(parent_6);
  5720. linkedMesh.mesh.updateUVs();
  5721. }
  5722. this.linkedMeshes.length = 0;
  5723. if (root.events) {
  5724. for (var eventName in root.events) {
  5725. var eventMap = root.events[eventName];
  5726. var data = new spine.EventData(eventName);
  5727. data.intValue = this.getValue(eventMap, "int", 0);
  5728. data.floatValue = this.getValue(eventMap, "float", 0);
  5729. data.stringValue = this.getValue(eventMap, "string", "");
  5730. data.audioPath = this.getValue(eventMap, "audio", null);
  5731. if (data.audioPath != null) {
  5732. data.volume = this.getValue(eventMap, "volume", 1);
  5733. data.balance = this.getValue(eventMap, "balance", 0);
  5734. }
  5735. skeletonData.events.push(data);
  5736. }
  5737. }
  5738. if (root.animations) {
  5739. for (var animationName in root.animations) {
  5740. var animationMap = root.animations[animationName];
  5741. this.readAnimation(animationMap, animationName, skeletonData);
  5742. }
  5743. }
  5744. return skeletonData;
  5745. };
  5746. SkeletonJson.prototype.readAttachment = function (map, skin, slotIndex, name, skeletonData) {
  5747. var scale = this.scale;
  5748. name = this.getValue(map, "name", name);
  5749. var type = this.getValue(map, "type", "region");
  5750. switch (type) {
  5751. case "region": {
  5752. var path = this.getValue(map, "path", name);
  5753. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  5754. if (region == null)
  5755. return null;
  5756. region.path = path;
  5757. region.x = this.getValue(map, "x", 0) * scale;
  5758. region.y = this.getValue(map, "y", 0) * scale;
  5759. region.scaleX = this.getValue(map, "scaleX", 1);
  5760. region.scaleY = this.getValue(map, "scaleY", 1);
  5761. region.rotation = this.getValue(map, "rotation", 0);
  5762. region.width = map.width * scale;
  5763. region.height = map.height * scale;
  5764. var color = this.getValue(map, "color", null);
  5765. if (color != null)
  5766. region.color.setFromString(color);
  5767. region.updateOffset();
  5768. return region;
  5769. }
  5770. case "boundingbox": {
  5771. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  5772. if (box == null)
  5773. return null;
  5774. this.readVertices(map, box, map.vertexCount << 1);
  5775. var color = this.getValue(map, "color", null);
  5776. if (color != null)
  5777. box.color.setFromString(color);
  5778. return box;
  5779. }
  5780. case "mesh":
  5781. case "linkedmesh": {
  5782. var path = this.getValue(map, "path", name);
  5783. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  5784. if (mesh == null)
  5785. return null;
  5786. mesh.path = path;
  5787. var color = this.getValue(map, "color", null);
  5788. if (color != null)
  5789. mesh.color.setFromString(color);
  5790. mesh.width = this.getValue(map, "width", 0) * scale;
  5791. mesh.height = this.getValue(map, "height", 0) * scale;
  5792. var parent_7 = this.getValue(map, "parent", null);
  5793. if (parent_7 != null) {
  5794. this.linkedMeshes.push(new LinkedMesh(mesh, this.getValue(map, "skin", null), slotIndex, parent_7, this.getValue(map, "deform", true)));
  5795. return mesh;
  5796. }
  5797. var uvs = map.uvs;
  5798. this.readVertices(map, mesh, uvs.length);
  5799. mesh.triangles = map.triangles;
  5800. mesh.regionUVs = uvs;
  5801. mesh.updateUVs();
  5802. mesh.edges = this.getValue(map, "edges", null);
  5803. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  5804. return mesh;
  5805. }
  5806. case "path": {
  5807. var path = this.attachmentLoader.newPathAttachment(skin, name);
  5808. if (path == null)
  5809. return null;
  5810. path.closed = this.getValue(map, "closed", false);
  5811. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  5812. var vertexCount = map.vertexCount;
  5813. this.readVertices(map, path, vertexCount << 1);
  5814. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  5815. for (var i = 0; i < map.lengths.length; i++)
  5816. lengths[i] = map.lengths[i] * scale;
  5817. path.lengths = lengths;
  5818. var color = this.getValue(map, "color", null);
  5819. if (color != null)
  5820. path.color.setFromString(color);
  5821. return path;
  5822. }
  5823. case "point": {
  5824. var point = this.attachmentLoader.newPointAttachment(skin, name);
  5825. if (point == null)
  5826. return null;
  5827. point.x = this.getValue(map, "x", 0) * scale;
  5828. point.y = this.getValue(map, "y", 0) * scale;
  5829. point.rotation = this.getValue(map, "rotation", 0);
  5830. var color = this.getValue(map, "color", null);
  5831. if (color != null)
  5832. point.color.setFromString(color);
  5833. return point;
  5834. }
  5835. case "clipping": {
  5836. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  5837. if (clip == null)
  5838. return null;
  5839. var end = this.getValue(map, "end", null);
  5840. if (end != null) {
  5841. var slot = skeletonData.findSlot(end);
  5842. if (slot == null)
  5843. throw new Error("Clipping end slot not found: " + end);
  5844. clip.endSlot = slot;
  5845. }
  5846. var vertexCount = map.vertexCount;
  5847. this.readVertices(map, clip, vertexCount << 1);
  5848. var color = this.getValue(map, "color", null);
  5849. if (color != null)
  5850. clip.color.setFromString(color);
  5851. return clip;
  5852. }
  5853. }
  5854. return null;
  5855. };
  5856. SkeletonJson.prototype.readVertices = function (map, attachment, verticesLength) {
  5857. var scale = this.scale;
  5858. attachment.worldVerticesLength = verticesLength;
  5859. var vertices = map.vertices;
  5860. if (verticesLength == vertices.length) {
  5861. var scaledVertices = spine.Utils.toFloatArray(vertices);
  5862. if (scale != 1) {
  5863. for (var i = 0, n = vertices.length; i < n; i++)
  5864. scaledVertices[i] *= scale;
  5865. }
  5866. attachment.vertices = scaledVertices;
  5867. return;
  5868. }
  5869. var weights = new Array();
  5870. var bones = new Array();
  5871. for (var i = 0, n = vertices.length; i < n;) {
  5872. var boneCount = vertices[i++];
  5873. bones.push(boneCount);
  5874. for (var nn = i + boneCount * 4; i < nn; i += 4) {
  5875. bones.push(vertices[i]);
  5876. weights.push(vertices[i + 1] * scale);
  5877. weights.push(vertices[i + 2] * scale);
  5878. weights.push(vertices[i + 3]);
  5879. }
  5880. }
  5881. attachment.bones = bones;
  5882. attachment.vertices = spine.Utils.toFloatArray(weights);
  5883. };
  5884. SkeletonJson.prototype.readAnimation = function (map, name, skeletonData) {
  5885. var scale = this.scale;
  5886. var timelines = new Array();
  5887. var duration = 0;
  5888. if (map.slots) {
  5889. for (var slotName in map.slots) {
  5890. var slotMap = map.slots[slotName];
  5891. var slotIndex = skeletonData.findSlotIndex(slotName);
  5892. if (slotIndex == -1)
  5893. throw new Error("Slot not found: " + slotName);
  5894. for (var timelineName in slotMap) {
  5895. var timelineMap = slotMap[timelineName];
  5896. if (timelineName == "attachment") {
  5897. var timeline = new spine.AttachmentTimeline(timelineMap.length);
  5898. timeline.slotIndex = slotIndex;
  5899. var frameIndex = 0;
  5900. for (var i = 0; i < timelineMap.length; i++) {
  5901. var valueMap = timelineMap[i];
  5902. timeline.setFrame(frameIndex++, this.getValue(valueMap, "time", 0), valueMap.name);
  5903. }
  5904. timelines.push(timeline);
  5905. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5906. }
  5907. else if (timelineName == "color") {
  5908. var timeline = new spine.ColorTimeline(timelineMap.length);
  5909. timeline.slotIndex = slotIndex;
  5910. var frameIndex = 0;
  5911. for (var i = 0; i < timelineMap.length; i++) {
  5912. var valueMap = timelineMap[i];
  5913. var color = new spine.Color();
  5914. color.setFromString(valueMap.color);
  5915. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), color.r, color.g, color.b, color.a);
  5916. this.readCurve(valueMap, timeline, frameIndex);
  5917. frameIndex++;
  5918. }
  5919. timelines.push(timeline);
  5920. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]);
  5921. }
  5922. else if (timelineName == "twoColor") {
  5923. var timeline = new spine.TwoColorTimeline(timelineMap.length);
  5924. timeline.slotIndex = slotIndex;
  5925. var frameIndex = 0;
  5926. for (var i = 0; i < timelineMap.length; i++) {
  5927. var valueMap = timelineMap[i];
  5928. var light = new spine.Color();
  5929. var dark = new spine.Color();
  5930. light.setFromString(valueMap.light);
  5931. dark.setFromString(valueMap.dark);
  5932. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
  5933. this.readCurve(valueMap, timeline, frameIndex);
  5934. frameIndex++;
  5935. }
  5936. timelines.push(timeline);
  5937. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TwoColorTimeline.ENTRIES]);
  5938. }
  5939. else
  5940. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  5941. }
  5942. }
  5943. }
  5944. if (map.bones) {
  5945. for (var boneName in map.bones) {
  5946. var boneMap = map.bones[boneName];
  5947. var boneIndex = skeletonData.findBoneIndex(boneName);
  5948. if (boneIndex == -1)
  5949. throw new Error("Bone not found: " + boneName);
  5950. for (var timelineName in boneMap) {
  5951. var timelineMap = boneMap[timelineName];
  5952. if (timelineName === "rotate") {
  5953. var timeline = new spine.RotateTimeline(timelineMap.length);
  5954. timeline.boneIndex = boneIndex;
  5955. var frameIndex = 0;
  5956. for (var i = 0; i < timelineMap.length; i++) {
  5957. var valueMap = timelineMap[i];
  5958. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "angle", 0));
  5959. this.readCurve(valueMap, timeline, frameIndex);
  5960. frameIndex++;
  5961. }
  5962. timelines.push(timeline);
  5963. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.RotateTimeline.ENTRIES]);
  5964. }
  5965. else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
  5966. var timeline = null;
  5967. var timelineScale = 1, defaultValue = 0;
  5968. if (timelineName === "scale") {
  5969. timeline = new spine.ScaleTimeline(timelineMap.length);
  5970. defaultValue = 1;
  5971. }
  5972. else if (timelineName === "shear")
  5973. timeline = new spine.ShearTimeline(timelineMap.length);
  5974. else {
  5975. timeline = new spine.TranslateTimeline(timelineMap.length);
  5976. timelineScale = scale;
  5977. }
  5978. timeline.boneIndex = boneIndex;
  5979. var frameIndex = 0;
  5980. for (var i = 0; i < timelineMap.length; i++) {
  5981. var valueMap = timelineMap[i];
  5982. var x = this.getValue(valueMap, "x", defaultValue), y = this.getValue(valueMap, "y", defaultValue);
  5983. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), x * timelineScale, y * timelineScale);
  5984. this.readCurve(valueMap, timeline, frameIndex);
  5985. frameIndex++;
  5986. }
  5987. timelines.push(timeline);
  5988. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TranslateTimeline.ENTRIES]);
  5989. }
  5990. else
  5991. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  5992. }
  5993. }
  5994. }
  5995. if (map.ik) {
  5996. for (var constraintName in map.ik) {
  5997. var constraintMap = map.ik[constraintName];
  5998. var constraint = skeletonData.findIkConstraint(constraintName);
  5999. var timeline = new spine.IkConstraintTimeline(constraintMap.length);
  6000. timeline.ikConstraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  6001. var frameIndex = 0;
  6002. for (var i = 0; i < constraintMap.length; i++) {
  6003. var valueMap = constraintMap[i];
  6004. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "mix", 1), this.getValue(valueMap, "softness", 0) * scale, this.getValue(valueMap, "bendPositive", true) ? 1 : -1, this.getValue(valueMap, "compress", false), this.getValue(valueMap, "stretch", false));
  6005. this.readCurve(valueMap, timeline, frameIndex);
  6006. frameIndex++;
  6007. }
  6008. timelines.push(timeline);
  6009. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.IkConstraintTimeline.ENTRIES]);
  6010. }
  6011. }
  6012. if (map.transform) {
  6013. for (var constraintName in map.transform) {
  6014. var constraintMap = map.transform[constraintName];
  6015. var constraint = skeletonData.findTransformConstraint(constraintName);
  6016. var timeline = new spine.TransformConstraintTimeline(constraintMap.length);
  6017. timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  6018. var frameIndex = 0;
  6019. for (var i = 0; i < constraintMap.length; i++) {
  6020. var valueMap = constraintMap[i];
  6021. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1), this.getValue(valueMap, "scaleMix", 1), this.getValue(valueMap, "shearMix", 1));
  6022. this.readCurve(valueMap, timeline, frameIndex);
  6023. frameIndex++;
  6024. }
  6025. timelines.push(timeline);
  6026. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TransformConstraintTimeline.ENTRIES]);
  6027. }
  6028. }
  6029. if (map.path) {
  6030. for (var constraintName in map.path) {
  6031. var constraintMap = map.path[constraintName];
  6032. var index = skeletonData.findPathConstraintIndex(constraintName);
  6033. if (index == -1)
  6034. throw new Error("Path constraint not found: " + constraintName);
  6035. var data = skeletonData.pathConstraints[index];
  6036. for (var timelineName in constraintMap) {
  6037. var timelineMap = constraintMap[timelineName];
  6038. if (timelineName === "position" || timelineName === "spacing") {
  6039. var timeline = null;
  6040. var timelineScale = 1;
  6041. if (timelineName === "spacing") {
  6042. timeline = new spine.PathConstraintSpacingTimeline(timelineMap.length);
  6043. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  6044. timelineScale = scale;
  6045. }
  6046. else {
  6047. timeline = new spine.PathConstraintPositionTimeline(timelineMap.length);
  6048. if (data.positionMode == spine.PositionMode.Fixed)
  6049. timelineScale = scale;
  6050. }
  6051. timeline.pathConstraintIndex = index;
  6052. var frameIndex = 0;
  6053. for (var i = 0; i < timelineMap.length; i++) {
  6054. var valueMap = timelineMap[i];
  6055. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, timelineName, 0) * timelineScale);
  6056. this.readCurve(valueMap, timeline, frameIndex);
  6057. frameIndex++;
  6058. }
  6059. timelines.push(timeline);
  6060. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintPositionTimeline.ENTRIES]);
  6061. }
  6062. else if (timelineName === "mix") {
  6063. var timeline = new spine.PathConstraintMixTimeline(timelineMap.length);
  6064. timeline.pathConstraintIndex = index;
  6065. var frameIndex = 0;
  6066. for (var i = 0; i < timelineMap.length; i++) {
  6067. var valueMap = timelineMap[i];
  6068. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1));
  6069. this.readCurve(valueMap, timeline, frameIndex);
  6070. frameIndex++;
  6071. }
  6072. timelines.push(timeline);
  6073. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintMixTimeline.ENTRIES]);
  6074. }
  6075. }
  6076. }
  6077. }
  6078. if (map.deform) {
  6079. for (var deformName in map.deform) {
  6080. var deformMap = map.deform[deformName];
  6081. var skin = skeletonData.findSkin(deformName);
  6082. if (skin == null)
  6083. throw new Error("Skin not found: " + deformName);
  6084. for (var slotName in deformMap) {
  6085. var slotMap = deformMap[slotName];
  6086. var slotIndex = skeletonData.findSlotIndex(slotName);
  6087. if (slotIndex == -1)
  6088. throw new Error("Slot not found: " + slotMap.name);
  6089. for (var timelineName in slotMap) {
  6090. var timelineMap = slotMap[timelineName];
  6091. var attachment = skin.getAttachment(slotIndex, timelineName);
  6092. if (attachment == null)
  6093. throw new Error("Deform attachment not found: " + timelineMap.name);
  6094. var weighted = attachment.bones != null;
  6095. var vertices = attachment.vertices;
  6096. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  6097. var timeline = new spine.DeformTimeline(timelineMap.length);
  6098. timeline.slotIndex = slotIndex;
  6099. timeline.attachment = attachment;
  6100. var frameIndex = 0;
  6101. for (var j = 0; j < timelineMap.length; j++) {
  6102. var valueMap = timelineMap[j];
  6103. var deform = void 0;
  6104. var verticesValue = this.getValue(valueMap, "vertices", null);
  6105. if (verticesValue == null)
  6106. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  6107. else {
  6108. deform = spine.Utils.newFloatArray(deformLength);
  6109. var start = this.getValue(valueMap, "offset", 0);
  6110. spine.Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  6111. if (scale != 1) {
  6112. for (var i = start, n = i + verticesValue.length; i < n; i++)
  6113. deform[i] *= scale;
  6114. }
  6115. if (!weighted) {
  6116. for (var i = 0; i < deformLength; i++)
  6117. deform[i] += vertices[i];
  6118. }
  6119. }
  6120. timeline.setFrame(frameIndex, this.getValue(valueMap, "time", 0), deform);
  6121. this.readCurve(valueMap, timeline, frameIndex);
  6122. frameIndex++;
  6123. }
  6124. timelines.push(timeline);
  6125. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  6126. }
  6127. }
  6128. }
  6129. }
  6130. var drawOrderNode = map.drawOrder;
  6131. if (drawOrderNode == null)
  6132. drawOrderNode = map.draworder;
  6133. if (drawOrderNode != null) {
  6134. var timeline = new spine.DrawOrderTimeline(drawOrderNode.length);
  6135. var slotCount = skeletonData.slots.length;
  6136. var frameIndex = 0;
  6137. for (var j = 0; j < drawOrderNode.length; j++) {
  6138. var drawOrderMap = drawOrderNode[j];
  6139. var drawOrder = null;
  6140. var offsets = this.getValue(drawOrderMap, "offsets", null);
  6141. if (offsets != null) {
  6142. drawOrder = spine.Utils.newArray(slotCount, -1);
  6143. var unchanged = spine.Utils.newArray(slotCount - offsets.length, 0);
  6144. var originalIndex = 0, unchangedIndex = 0;
  6145. for (var i = 0; i < offsets.length; i++) {
  6146. var offsetMap = offsets[i];
  6147. var slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  6148. if (slotIndex == -1)
  6149. throw new Error("Slot not found: " + offsetMap.slot);
  6150. while (originalIndex != slotIndex)
  6151. unchanged[unchangedIndex++] = originalIndex++;
  6152. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  6153. }
  6154. while (originalIndex < slotCount)
  6155. unchanged[unchangedIndex++] = originalIndex++;
  6156. for (var i = slotCount - 1; i >= 0; i--)
  6157. if (drawOrder[i] == -1)
  6158. drawOrder[i] = unchanged[--unchangedIndex];
  6159. }
  6160. timeline.setFrame(frameIndex++, this.getValue(drawOrderMap, "time", 0), drawOrder);
  6161. }
  6162. timelines.push(timeline);
  6163. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  6164. }
  6165. if (map.events) {
  6166. var timeline = new spine.EventTimeline(map.events.length);
  6167. var frameIndex = 0;
  6168. for (var i = 0; i < map.events.length; i++) {
  6169. var eventMap = map.events[i];
  6170. var eventData = skeletonData.findEvent(eventMap.name);
  6171. if (eventData == null)
  6172. throw new Error("Event not found: " + eventMap.name);
  6173. var event_6 = new spine.Event(spine.Utils.toSinglePrecision(this.getValue(eventMap, "time", 0)), eventData);
  6174. event_6.intValue = this.getValue(eventMap, "int", eventData.intValue);
  6175. event_6.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  6176. event_6.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  6177. if (event_6.data.audioPath != null) {
  6178. event_6.volume = this.getValue(eventMap, "volume", 1);
  6179. event_6.balance = this.getValue(eventMap, "balance", 0);
  6180. }
  6181. timeline.setFrame(frameIndex++, event_6);
  6182. }
  6183. timelines.push(timeline);
  6184. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  6185. }
  6186. if (isNaN(duration)) {
  6187. throw new Error("Error while parsing animation, duration is NaN");
  6188. }
  6189. skeletonData.animations.push(new spine.Animation(name, timelines, duration));
  6190. };
  6191. SkeletonJson.prototype.readCurve = function (map, timeline, frameIndex) {
  6192. if (!map.hasOwnProperty("curve"))
  6193. return;
  6194. if (map.curve == "stepped")
  6195. timeline.setStepped(frameIndex);
  6196. else {
  6197. var curve = map.curve;
  6198. timeline.setCurve(frameIndex, curve, this.getValue(map, "c2", 0), this.getValue(map, "c3", 1), this.getValue(map, "c4", 1));
  6199. }
  6200. };
  6201. SkeletonJson.prototype.getValue = function (map, prop, defaultValue) {
  6202. return map[prop] !== undefined ? map[prop] : defaultValue;
  6203. };
  6204. SkeletonJson.blendModeFromString = function (str) {
  6205. str = str.toLowerCase();
  6206. if (str == "normal")
  6207. return spine.BlendMode.Normal;
  6208. if (str == "additive")
  6209. return spine.BlendMode.Additive;
  6210. if (str == "multiply")
  6211. return spine.BlendMode.Multiply;
  6212. if (str == "screen")
  6213. return spine.BlendMode.Screen;
  6214. throw new Error("Unknown blend mode: " + str);
  6215. };
  6216. SkeletonJson.positionModeFromString = function (str) {
  6217. str = str.toLowerCase();
  6218. if (str == "fixed")
  6219. return spine.PositionMode.Fixed;
  6220. if (str == "percent")
  6221. return spine.PositionMode.Percent;
  6222. throw new Error("Unknown position mode: " + str);
  6223. };
  6224. SkeletonJson.spacingModeFromString = function (str) {
  6225. str = str.toLowerCase();
  6226. if (str == "length")
  6227. return spine.SpacingMode.Length;
  6228. if (str == "fixed")
  6229. return spine.SpacingMode.Fixed;
  6230. if (str == "percent")
  6231. return spine.SpacingMode.Percent;
  6232. throw new Error("Unknown position mode: " + str);
  6233. };
  6234. SkeletonJson.rotateModeFromString = function (str) {
  6235. str = str.toLowerCase();
  6236. if (str == "tangent")
  6237. return spine.RotateMode.Tangent;
  6238. if (str == "chain")
  6239. return spine.RotateMode.Chain;
  6240. if (str == "chainscale")
  6241. return spine.RotateMode.ChainScale;
  6242. throw new Error("Unknown rotate mode: " + str);
  6243. };
  6244. SkeletonJson.transformModeFromString = function (str) {
  6245. str = str.toLowerCase();
  6246. if (str == "normal")
  6247. return spine.TransformMode.Normal;
  6248. if (str == "onlytranslation")
  6249. return spine.TransformMode.OnlyTranslation;
  6250. if (str == "norotationorreflection")
  6251. return spine.TransformMode.NoRotationOrReflection;
  6252. if (str == "noscale")
  6253. return spine.TransformMode.NoScale;
  6254. if (str == "noscaleorreflection")
  6255. return spine.TransformMode.NoScaleOrReflection;
  6256. throw new Error("Unknown transform mode: " + str);
  6257. };
  6258. return SkeletonJson;
  6259. }());
  6260. spine.SkeletonJson = SkeletonJson;
  6261. var LinkedMesh = (function () {
  6262. function LinkedMesh(mesh, skin, slotIndex, parent, inheritDeform) {
  6263. this.mesh = mesh;
  6264. this.skin = skin;
  6265. this.slotIndex = slotIndex;
  6266. this.parent = parent;
  6267. this.inheritDeform = inheritDeform;
  6268. }
  6269. return LinkedMesh;
  6270. }());
  6271. })(spine || (spine = {}));
  6272. var spine;
  6273. (function (spine) {
  6274. var SkinEntry = (function () {
  6275. function SkinEntry(slotIndex, name, attachment) {
  6276. this.slotIndex = slotIndex;
  6277. this.name = name;
  6278. this.attachment = attachment;
  6279. }
  6280. return SkinEntry;
  6281. }());
  6282. spine.SkinEntry = SkinEntry;
  6283. var Skin = (function () {
  6284. function Skin(name) {
  6285. this.attachments = new Array();
  6286. this.bones = Array();
  6287. this.constraints = new Array();
  6288. if (name == null)
  6289. throw new Error("name cannot be null.");
  6290. this.name = name;
  6291. }
  6292. Skin.prototype.setAttachment = function (slotIndex, name, attachment) {
  6293. if (attachment == null)
  6294. throw new Error("attachment cannot be null.");
  6295. var attachments = this.attachments;
  6296. if (slotIndex >= attachments.length)
  6297. attachments.length = slotIndex + 1;
  6298. if (!attachments[slotIndex])
  6299. attachments[slotIndex] = {};
  6300. attachments[slotIndex][name] = attachment;
  6301. };
  6302. Skin.prototype.addSkin = function (skin) {
  6303. for (var i = 0; i < skin.bones.length; i++) {
  6304. var bone = skin.bones[i];
  6305. var contained = false;
  6306. for (var j = 0; j < this.bones.length; j++) {
  6307. if (this.bones[j] == bone) {
  6308. contained = true;
  6309. break;
  6310. }
  6311. }
  6312. if (!contained)
  6313. this.bones.push(bone);
  6314. }
  6315. for (var i = 0; i < skin.constraints.length; i++) {
  6316. var constraint = skin.constraints[i];
  6317. var contained = false;
  6318. for (var j = 0; j < this.constraints.length; j++) {
  6319. if (this.constraints[j] == constraint) {
  6320. contained = true;
  6321. break;
  6322. }
  6323. }
  6324. if (!contained)
  6325. this.constraints.push(constraint);
  6326. }
  6327. var attachments = skin.getAttachments();
  6328. for (var i = 0; i < attachments.length; i++) {
  6329. var attachment = attachments[i];
  6330. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  6331. }
  6332. };
  6333. Skin.prototype.copySkin = function (skin) {
  6334. for (var i = 0; i < skin.bones.length; i++) {
  6335. var bone = skin.bones[i];
  6336. var contained = false;
  6337. for (var j = 0; j < this.bones.length; j++) {
  6338. if (this.bones[j] == bone) {
  6339. contained = true;
  6340. break;
  6341. }
  6342. }
  6343. if (!contained)
  6344. this.bones.push(bone);
  6345. }
  6346. for (var i = 0; i < skin.constraints.length; i++) {
  6347. var constraint = skin.constraints[i];
  6348. var contained = false;
  6349. for (var j = 0; j < this.constraints.length; j++) {
  6350. if (this.constraints[j] == constraint) {
  6351. contained = true;
  6352. break;
  6353. }
  6354. }
  6355. if (!contained)
  6356. this.constraints.push(constraint);
  6357. }
  6358. var attachments = skin.getAttachments();
  6359. for (var i = 0; i < attachments.length; i++) {
  6360. var attachment = attachments[i];
  6361. if (attachment.attachment == null)
  6362. continue;
  6363. if (attachment.attachment instanceof spine.MeshAttachment) {
  6364. attachment.attachment = attachment.attachment.newLinkedMesh();
  6365. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  6366. }
  6367. else {
  6368. attachment.attachment = attachment.attachment.copy();
  6369. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  6370. }
  6371. }
  6372. };
  6373. Skin.prototype.getAttachment = function (slotIndex, name) {
  6374. var dictionary = this.attachments[slotIndex];
  6375. return dictionary ? dictionary[name] : null;
  6376. };
  6377. Skin.prototype.removeAttachment = function (slotIndex, name) {
  6378. var dictionary = this.attachments[slotIndex];
  6379. if (dictionary)
  6380. dictionary[name] = null;
  6381. };
  6382. Skin.prototype.getAttachments = function () {
  6383. var entries = new Array();
  6384. for (var i = 0; i < this.attachments.length; i++) {
  6385. var slotAttachments = this.attachments[i];
  6386. if (slotAttachments) {
  6387. for (var name_4 in slotAttachments) {
  6388. var attachment = slotAttachments[name_4];
  6389. if (attachment)
  6390. entries.push(new SkinEntry(i, name_4, attachment));
  6391. }
  6392. }
  6393. }
  6394. return entries;
  6395. };
  6396. Skin.prototype.getAttachmentsForSlot = function (slotIndex, attachments) {
  6397. var slotAttachments = this.attachments[slotIndex];
  6398. if (slotAttachments) {
  6399. for (var name_5 in slotAttachments) {
  6400. var attachment = slotAttachments[name_5];
  6401. if (attachment)
  6402. attachments.push(new SkinEntry(slotIndex, name_5, attachment));
  6403. }
  6404. }
  6405. };
  6406. Skin.prototype.clear = function () {
  6407. this.attachments.length = 0;
  6408. this.bones.length = 0;
  6409. this.constraints.length = 0;
  6410. };
  6411. Skin.prototype.attachAll = function (skeleton, oldSkin) {
  6412. var slotIndex = 0;
  6413. for (var i = 0; i < skeleton.slots.length; i++) {
  6414. var slot = skeleton.slots[i];
  6415. var slotAttachment = slot.getAttachment();
  6416. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  6417. var dictionary = oldSkin.attachments[slotIndex];
  6418. for (var key in dictionary) {
  6419. var skinAttachment = dictionary[key];
  6420. if (slotAttachment == skinAttachment) {
  6421. var attachment = this.getAttachment(slotIndex, key);
  6422. if (attachment != null)
  6423. slot.setAttachment(attachment);
  6424. break;
  6425. }
  6426. }
  6427. }
  6428. slotIndex++;
  6429. }
  6430. };
  6431. return Skin;
  6432. }());
  6433. spine.Skin = Skin;
  6434. })(spine || (spine = {}));
  6435. var spine;
  6436. (function (spine) {
  6437. var Slot = (function () {
  6438. function Slot(data, bone) {
  6439. this.deform = new Array();
  6440. if (data == null)
  6441. throw new Error("data cannot be null.");
  6442. if (bone == null)
  6443. throw new Error("bone cannot be null.");
  6444. this.data = data;
  6445. this.bone = bone;
  6446. this.color = new spine.Color();
  6447. this.darkColor = data.darkColor == null ? null : new spine.Color();
  6448. this.setToSetupPose();
  6449. }
  6450. Slot.prototype.getSkeleton = function () {
  6451. return this.bone.skeleton;
  6452. };
  6453. Slot.prototype.getAttachment = function () {
  6454. return this.attachment;
  6455. };
  6456. Slot.prototype.setAttachment = function (attachment) {
  6457. if (this.attachment == attachment)
  6458. return;
  6459. this.attachment = attachment;
  6460. this.attachmentTime = this.bone.skeleton.time;
  6461. this.deform.length = 0;
  6462. };
  6463. Slot.prototype.setAttachmentTime = function (time) {
  6464. this.attachmentTime = this.bone.skeleton.time - time;
  6465. };
  6466. Slot.prototype.getAttachmentTime = function () {
  6467. return this.bone.skeleton.time - this.attachmentTime;
  6468. };
  6469. Slot.prototype.setToSetupPose = function () {
  6470. this.color.setFromColor(this.data.color);
  6471. if (this.darkColor != null)
  6472. this.darkColor.setFromColor(this.data.darkColor);
  6473. if (this.data.attachmentName == null)
  6474. this.attachment = null;
  6475. else {
  6476. this.attachment = null;
  6477. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  6478. }
  6479. };
  6480. return Slot;
  6481. }());
  6482. spine.Slot = Slot;
  6483. })(spine || (spine = {}));
  6484. var spine;
  6485. (function (spine) {
  6486. var SlotData = (function () {
  6487. function SlotData(index, name, boneData) {
  6488. this.color = new spine.Color(1, 1, 1, 1);
  6489. if (index < 0)
  6490. throw new Error("index must be >= 0.");
  6491. if (name == null)
  6492. throw new Error("name cannot be null.");
  6493. if (boneData == null)
  6494. throw new Error("boneData cannot be null.");
  6495. this.index = index;
  6496. this.name = name;
  6497. this.boneData = boneData;
  6498. }
  6499. return SlotData;
  6500. }());
  6501. spine.SlotData = SlotData;
  6502. })(spine || (spine = {}));
  6503. var spine;
  6504. (function (spine) {
  6505. var Texture = (function () {
  6506. function Texture(image) {
  6507. this._image = image;
  6508. }
  6509. Texture.prototype.getImage = function () {
  6510. return this._image;
  6511. };
  6512. Texture.filterFromString = function (text) {
  6513. switch (text.toLowerCase()) {
  6514. case "nearest": return TextureFilter.Nearest;
  6515. case "linear": return TextureFilter.Linear;
  6516. case "mipmap": return TextureFilter.MipMap;
  6517. case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest;
  6518. case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest;
  6519. case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear;
  6520. case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear;
  6521. default: throw new Error("Unknown texture filter " + text);
  6522. }
  6523. };
  6524. Texture.wrapFromString = function (text) {
  6525. switch (text.toLowerCase()) {
  6526. case "mirroredtepeat": return TextureWrap.MirroredRepeat;
  6527. case "clamptoedge": return TextureWrap.ClampToEdge;
  6528. case "repeat": return TextureWrap.Repeat;
  6529. default: throw new Error("Unknown texture wrap " + text);
  6530. }
  6531. };
  6532. return Texture;
  6533. }());
  6534. spine.Texture = Texture;
  6535. var TextureFilter;
  6536. (function (TextureFilter) {
  6537. TextureFilter[TextureFilter["Nearest"] = 9728] = "Nearest";
  6538. TextureFilter[TextureFilter["Linear"] = 9729] = "Linear";
  6539. TextureFilter[TextureFilter["MipMap"] = 9987] = "MipMap";
  6540. TextureFilter[TextureFilter["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
  6541. TextureFilter[TextureFilter["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
  6542. TextureFilter[TextureFilter["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
  6543. TextureFilter[TextureFilter["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
  6544. })(TextureFilter = spine.TextureFilter || (spine.TextureFilter = {}));
  6545. var TextureWrap;
  6546. (function (TextureWrap) {
  6547. TextureWrap[TextureWrap["MirroredRepeat"] = 33648] = "MirroredRepeat";
  6548. TextureWrap[TextureWrap["ClampToEdge"] = 33071] = "ClampToEdge";
  6549. TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat";
  6550. })(TextureWrap = spine.TextureWrap || (spine.TextureWrap = {}));
  6551. var TextureRegion = (function () {
  6552. function TextureRegion() {
  6553. this.u = 0;
  6554. this.v = 0;
  6555. this.u2 = 0;
  6556. this.v2 = 0;
  6557. this.width = 0;
  6558. this.height = 0;
  6559. this.rotate = false;
  6560. this.offsetX = 0;
  6561. this.offsetY = 0;
  6562. this.originalWidth = 0;
  6563. this.originalHeight = 0;
  6564. }
  6565. return TextureRegion;
  6566. }());
  6567. spine.TextureRegion = TextureRegion;
  6568. var FakeTexture = (function (_super) {
  6569. __extends(FakeTexture, _super);
  6570. function FakeTexture() {
  6571. return _super !== null && _super.apply(this, arguments) || this;
  6572. }
  6573. FakeTexture.prototype.setFilters = function (minFilter, magFilter) { };
  6574. FakeTexture.prototype.setWraps = function (uWrap, vWrap) { };
  6575. FakeTexture.prototype.dispose = function () { };
  6576. return FakeTexture;
  6577. }(Texture));
  6578. spine.FakeTexture = FakeTexture;
  6579. })(spine || (spine = {}));
  6580. var spine;
  6581. (function (spine) {
  6582. var TextureAtlas = (function () {
  6583. function TextureAtlas(atlasText, textureLoader) {
  6584. this.pages = new Array();
  6585. this.regions = new Array();
  6586. this.load(atlasText, textureLoader);
  6587. }
  6588. TextureAtlas.prototype.load = function (atlasText, textureLoader) {
  6589. if (textureLoader == null)
  6590. throw new Error("textureLoader cannot be null.");
  6591. var reader = new TextureAtlasReader(atlasText);
  6592. var tuple = new Array(4);
  6593. var page = null;
  6594. while (true) {
  6595. var line = reader.readLine();
  6596. if (line == null)
  6597. break;
  6598. line = line.trim();
  6599. if (line.length == 0)
  6600. page = null;
  6601. else if (!page) {
  6602. page = new TextureAtlasPage();
  6603. page.name = line;
  6604. if (reader.readTuple(tuple) == 2) {
  6605. page.width = parseInt(tuple[0]);
  6606. page.height = parseInt(tuple[1]);
  6607. reader.readTuple(tuple);
  6608. }
  6609. reader.readTuple(tuple);
  6610. page.minFilter = spine.Texture.filterFromString(tuple[0]);
  6611. page.magFilter = spine.Texture.filterFromString(tuple[1]);
  6612. var direction = reader.readValue();
  6613. page.uWrap = spine.TextureWrap.ClampToEdge;
  6614. page.vWrap = spine.TextureWrap.ClampToEdge;
  6615. if (direction == "x")
  6616. page.uWrap = spine.TextureWrap.Repeat;
  6617. else if (direction == "y")
  6618. page.vWrap = spine.TextureWrap.Repeat;
  6619. else if (direction == "xy")
  6620. page.uWrap = page.vWrap = spine.TextureWrap.Repeat;
  6621. page.texture = textureLoader(line);
  6622. page.texture.setFilters(page.minFilter, page.magFilter);
  6623. page.texture.setWraps(page.uWrap, page.vWrap);
  6624. page.width = page.texture.getImage().width;
  6625. page.height = page.texture.getImage().height;
  6626. this.pages.push(page);
  6627. }
  6628. else {
  6629. var region = new TextureAtlasRegion();
  6630. region.name = line;
  6631. region.page = page;
  6632. var rotateValue = reader.readValue();
  6633. if (rotateValue.toLocaleLowerCase() == "true") {
  6634. region.degrees = 90;
  6635. }
  6636. else if (rotateValue.toLocaleLowerCase() == "false") {
  6637. region.degrees = 0;
  6638. }
  6639. else {
  6640. region.degrees = parseFloat(rotateValue);
  6641. }
  6642. region.rotate = region.degrees == 90;
  6643. reader.readTuple(tuple);
  6644. var x = parseInt(tuple[0]);
  6645. var y = parseInt(tuple[1]);
  6646. reader.readTuple(tuple);
  6647. var width = parseInt(tuple[0]);
  6648. var height = parseInt(tuple[1]);
  6649. region.u = x / page.width;
  6650. region.v = y / page.height;
  6651. if (region.rotate) {
  6652. region.u2 = (x + height) / page.width;
  6653. region.v2 = (y + width) / page.height;
  6654. }
  6655. else {
  6656. region.u2 = (x + width) / page.width;
  6657. region.v2 = (y + height) / page.height;
  6658. }
  6659. region.x = x;
  6660. region.y = y;
  6661. region.width = Math.abs(width);
  6662. region.height = Math.abs(height);
  6663. if (reader.readTuple(tuple) == 4) {
  6664. if (reader.readTuple(tuple) == 4) {
  6665. reader.readTuple(tuple);
  6666. }
  6667. }
  6668. region.originalWidth = parseInt(tuple[0]);
  6669. region.originalHeight = parseInt(tuple[1]);
  6670. reader.readTuple(tuple);
  6671. region.offsetX = parseInt(tuple[0]);
  6672. region.offsetY = parseInt(tuple[1]);
  6673. region.index = parseInt(reader.readValue());
  6674. region.texture = page.texture;
  6675. this.regions.push(region);
  6676. }
  6677. }
  6678. };
  6679. TextureAtlas.prototype.findRegion = function (name) {
  6680. for (var i = 0; i < this.regions.length; i++) {
  6681. if (this.regions[i].name == name) {
  6682. return this.regions[i];
  6683. }
  6684. }
  6685. return null;
  6686. };
  6687. TextureAtlas.prototype.dispose = function () {
  6688. for (var i = 0; i < this.pages.length; i++) {
  6689. this.pages[i].texture.dispose();
  6690. }
  6691. };
  6692. return TextureAtlas;
  6693. }());
  6694. spine.TextureAtlas = TextureAtlas;
  6695. var TextureAtlasReader = (function () {
  6696. function TextureAtlasReader(text) {
  6697. this.index = 0;
  6698. this.lines = text.split(/\r\n|\r|\n/);
  6699. }
  6700. TextureAtlasReader.prototype.readLine = function () {
  6701. if (this.index >= this.lines.length)
  6702. return null;
  6703. return this.lines[this.index++];
  6704. };
  6705. TextureAtlasReader.prototype.readValue = function () {
  6706. var line = this.readLine();
  6707. var colon = line.indexOf(":");
  6708. if (colon == -1)
  6709. throw new Error("Invalid line: " + line);
  6710. return line.substring(colon + 1).trim();
  6711. };
  6712. TextureAtlasReader.prototype.readTuple = function (tuple) {
  6713. var line = this.readLine();
  6714. var colon = line.indexOf(":");
  6715. if (colon == -1)
  6716. throw new Error("Invalid line: " + line);
  6717. var i = 0, lastMatch = colon + 1;
  6718. for (; i < 3; i++) {
  6719. var comma = line.indexOf(",", lastMatch);
  6720. if (comma == -1)
  6721. break;
  6722. tuple[i] = line.substr(lastMatch, comma - lastMatch).trim();
  6723. lastMatch = comma + 1;
  6724. }
  6725. tuple[i] = line.substring(lastMatch).trim();
  6726. return i + 1;
  6727. };
  6728. return TextureAtlasReader;
  6729. }());
  6730. var TextureAtlasPage = (function () {
  6731. function TextureAtlasPage() {
  6732. }
  6733. return TextureAtlasPage;
  6734. }());
  6735. spine.TextureAtlasPage = TextureAtlasPage;
  6736. var TextureAtlasRegion = (function (_super) {
  6737. __extends(TextureAtlasRegion, _super);
  6738. function TextureAtlasRegion() {
  6739. return _super !== null && _super.apply(this, arguments) || this;
  6740. }
  6741. return TextureAtlasRegion;
  6742. }(spine.TextureRegion));
  6743. spine.TextureAtlasRegion = TextureAtlasRegion;
  6744. })(spine || (spine = {}));
  6745. var spine;
  6746. (function (spine) {
  6747. var TransformConstraint = (function () {
  6748. function TransformConstraint(data, skeleton) {
  6749. this.rotateMix = 0;
  6750. this.translateMix = 0;
  6751. this.scaleMix = 0;
  6752. this.shearMix = 0;
  6753. this.temp = new spine.Vector2();
  6754. this.active = false;
  6755. if (data == null)
  6756. throw new Error("data cannot be null.");
  6757. if (skeleton == null)
  6758. throw new Error("skeleton cannot be null.");
  6759. this.data = data;
  6760. this.rotateMix = data.rotateMix;
  6761. this.translateMix = data.translateMix;
  6762. this.scaleMix = data.scaleMix;
  6763. this.shearMix = data.shearMix;
  6764. this.bones = new Array();
  6765. for (var i = 0; i < data.bones.length; i++)
  6766. this.bones.push(skeleton.findBone(data.bones[i].name));
  6767. this.target = skeleton.findBone(data.target.name);
  6768. }
  6769. TransformConstraint.prototype.isActive = function () {
  6770. return this.active;
  6771. };
  6772. TransformConstraint.prototype.apply = function () {
  6773. this.update();
  6774. };
  6775. TransformConstraint.prototype.update = function () {
  6776. if (this.data.local) {
  6777. if (this.data.relative)
  6778. this.applyRelativeLocal();
  6779. else
  6780. this.applyAbsoluteLocal();
  6781. }
  6782. else {
  6783. if (this.data.relative)
  6784. this.applyRelativeWorld();
  6785. else
  6786. this.applyAbsoluteWorld();
  6787. }
  6788. };
  6789. TransformConstraint.prototype.applyAbsoluteWorld = function () {
  6790. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6791. var target = this.target;
  6792. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  6793. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  6794. var offsetRotation = this.data.offsetRotation * degRadReflect;
  6795. var offsetShearY = this.data.offsetShearY * degRadReflect;
  6796. var bones = this.bones;
  6797. for (var i = 0, n = bones.length; i < n; i++) {
  6798. var bone = bones[i];
  6799. var modified = false;
  6800. if (rotateMix != 0) {
  6801. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6802. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  6803. if (r > spine.MathUtils.PI)
  6804. r -= spine.MathUtils.PI2;
  6805. else if (r < -spine.MathUtils.PI)
  6806. r += spine.MathUtils.PI2;
  6807. r *= rotateMix;
  6808. var cos = Math.cos(r), sin = Math.sin(r);
  6809. bone.a = cos * a - sin * c;
  6810. bone.b = cos * b - sin * d;
  6811. bone.c = sin * a + cos * c;
  6812. bone.d = sin * b + cos * d;
  6813. modified = true;
  6814. }
  6815. if (translateMix != 0) {
  6816. var temp = this.temp;
  6817. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  6818. bone.worldX += (temp.x - bone.worldX) * translateMix;
  6819. bone.worldY += (temp.y - bone.worldY) * translateMix;
  6820. modified = true;
  6821. }
  6822. if (scaleMix > 0) {
  6823. var s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
  6824. var ts = Math.sqrt(ta * ta + tc * tc);
  6825. if (s > 0.00001)
  6826. s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
  6827. bone.a *= s;
  6828. bone.c *= s;
  6829. s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
  6830. ts = Math.sqrt(tb * tb + td * td);
  6831. if (s > 0.00001)
  6832. s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
  6833. bone.b *= s;
  6834. bone.d *= s;
  6835. modified = true;
  6836. }
  6837. if (shearMix > 0) {
  6838. var b = bone.b, d = bone.d;
  6839. var by = Math.atan2(d, b);
  6840. var r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
  6841. if (r > spine.MathUtils.PI)
  6842. r -= spine.MathUtils.PI2;
  6843. else if (r < -spine.MathUtils.PI)
  6844. r += spine.MathUtils.PI2;
  6845. r = by + (r + offsetShearY) * shearMix;
  6846. var s = Math.sqrt(b * b + d * d);
  6847. bone.b = Math.cos(r) * s;
  6848. bone.d = Math.sin(r) * s;
  6849. modified = true;
  6850. }
  6851. if (modified)
  6852. bone.appliedValid = false;
  6853. }
  6854. };
  6855. TransformConstraint.prototype.applyRelativeWorld = function () {
  6856. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6857. var target = this.target;
  6858. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  6859. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  6860. var offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  6861. var bones = this.bones;
  6862. for (var i = 0, n = bones.length; i < n; i++) {
  6863. var bone = bones[i];
  6864. var modified = false;
  6865. if (rotateMix != 0) {
  6866. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6867. var r = Math.atan2(tc, ta) + offsetRotation;
  6868. if (r > spine.MathUtils.PI)
  6869. r -= spine.MathUtils.PI2;
  6870. else if (r < -spine.MathUtils.PI)
  6871. r += spine.MathUtils.PI2;
  6872. r *= rotateMix;
  6873. var cos = Math.cos(r), sin = Math.sin(r);
  6874. bone.a = cos * a - sin * c;
  6875. bone.b = cos * b - sin * d;
  6876. bone.c = sin * a + cos * c;
  6877. bone.d = sin * b + cos * d;
  6878. modified = true;
  6879. }
  6880. if (translateMix != 0) {
  6881. var temp = this.temp;
  6882. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  6883. bone.worldX += temp.x * translateMix;
  6884. bone.worldY += temp.y * translateMix;
  6885. modified = true;
  6886. }
  6887. if (scaleMix > 0) {
  6888. var s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
  6889. bone.a *= s;
  6890. bone.c *= s;
  6891. s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
  6892. bone.b *= s;
  6893. bone.d *= s;
  6894. modified = true;
  6895. }
  6896. if (shearMix > 0) {
  6897. var r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  6898. if (r > spine.MathUtils.PI)
  6899. r -= spine.MathUtils.PI2;
  6900. else if (r < -spine.MathUtils.PI)
  6901. r += spine.MathUtils.PI2;
  6902. var b = bone.b, d = bone.d;
  6903. r = Math.atan2(d, b) + (r - spine.MathUtils.PI / 2 + offsetShearY) * shearMix;
  6904. var s = Math.sqrt(b * b + d * d);
  6905. bone.b = Math.cos(r) * s;
  6906. bone.d = Math.sin(r) * s;
  6907. modified = true;
  6908. }
  6909. if (modified)
  6910. bone.appliedValid = false;
  6911. }
  6912. };
  6913. TransformConstraint.prototype.applyAbsoluteLocal = function () {
  6914. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6915. var target = this.target;
  6916. if (!target.appliedValid)
  6917. target.updateAppliedTransform();
  6918. var bones = this.bones;
  6919. for (var i = 0, n = bones.length; i < n; i++) {
  6920. var bone = bones[i];
  6921. if (!bone.appliedValid)
  6922. bone.updateAppliedTransform();
  6923. var rotation = bone.arotation;
  6924. if (rotateMix != 0) {
  6925. var r = target.arotation - rotation + this.data.offsetRotation;
  6926. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  6927. rotation += r * rotateMix;
  6928. }
  6929. var x = bone.ax, y = bone.ay;
  6930. if (translateMix != 0) {
  6931. x += (target.ax - x + this.data.offsetX) * translateMix;
  6932. y += (target.ay - y + this.data.offsetY) * translateMix;
  6933. }
  6934. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  6935. if (scaleMix != 0) {
  6936. if (scaleX > 0.00001)
  6937. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
  6938. if (scaleY > 0.00001)
  6939. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
  6940. }
  6941. var shearY = bone.ashearY;
  6942. if (shearMix != 0) {
  6943. var r = target.ashearY - shearY + this.data.offsetShearY;
  6944. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  6945. bone.shearY += r * shearMix;
  6946. }
  6947. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  6948. }
  6949. };
  6950. TransformConstraint.prototype.applyRelativeLocal = function () {
  6951. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  6952. var target = this.target;
  6953. if (!target.appliedValid)
  6954. target.updateAppliedTransform();
  6955. var bones = this.bones;
  6956. for (var i = 0, n = bones.length; i < n; i++) {
  6957. var bone = bones[i];
  6958. if (!bone.appliedValid)
  6959. bone.updateAppliedTransform();
  6960. var rotation = bone.arotation;
  6961. if (rotateMix != 0)
  6962. rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
  6963. var x = bone.ax, y = bone.ay;
  6964. if (translateMix != 0) {
  6965. x += (target.ax + this.data.offsetX) * translateMix;
  6966. y += (target.ay + this.data.offsetY) * translateMix;
  6967. }
  6968. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  6969. if (scaleMix != 0) {
  6970. if (scaleX > 0.00001)
  6971. scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
  6972. if (scaleY > 0.00001)
  6973. scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
  6974. }
  6975. var shearY = bone.ashearY;
  6976. if (shearMix != 0)
  6977. shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
  6978. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  6979. }
  6980. };
  6981. return TransformConstraint;
  6982. }());
  6983. spine.TransformConstraint = TransformConstraint;
  6984. })(spine || (spine = {}));
  6985. var spine;
  6986. (function (spine) {
  6987. var TransformConstraintData = (function (_super) {
  6988. __extends(TransformConstraintData, _super);
  6989. function TransformConstraintData(name) {
  6990. var _this = _super.call(this, name, 0, false) || this;
  6991. _this.bones = new Array();
  6992. _this.rotateMix = 0;
  6993. _this.translateMix = 0;
  6994. _this.scaleMix = 0;
  6995. _this.shearMix = 0;
  6996. _this.offsetRotation = 0;
  6997. _this.offsetX = 0;
  6998. _this.offsetY = 0;
  6999. _this.offsetScaleX = 0;
  7000. _this.offsetScaleY = 0;
  7001. _this.offsetShearY = 0;
  7002. _this.relative = false;
  7003. _this.local = false;
  7004. return _this;
  7005. }
  7006. return TransformConstraintData;
  7007. }(spine.ConstraintData));
  7008. spine.TransformConstraintData = TransformConstraintData;
  7009. })(spine || (spine = {}));
  7010. var spine;
  7011. (function (spine) {
  7012. var Triangulator = (function () {
  7013. function Triangulator() {
  7014. this.convexPolygons = new Array();
  7015. this.convexPolygonsIndices = new Array();
  7016. this.indicesArray = new Array();
  7017. this.isConcaveArray = new Array();
  7018. this.triangles = new Array();
  7019. this.polygonPool = new spine.Pool(function () {
  7020. return new Array();
  7021. });
  7022. this.polygonIndicesPool = new spine.Pool(function () {
  7023. return new Array();
  7024. });
  7025. }
  7026. Triangulator.prototype.triangulate = function (verticesArray) {
  7027. var vertices = verticesArray;
  7028. var vertexCount = verticesArray.length >> 1;
  7029. var indices = this.indicesArray;
  7030. indices.length = 0;
  7031. for (var i = 0; i < vertexCount; i++)
  7032. indices[i] = i;
  7033. var isConcave = this.isConcaveArray;
  7034. isConcave.length = 0;
  7035. for (var i = 0, n = vertexCount; i < n; ++i)
  7036. isConcave[i] = Triangulator.isConcave(i, vertexCount, vertices, indices);
  7037. var triangles = this.triangles;
  7038. triangles.length = 0;
  7039. while (vertexCount > 3) {
  7040. var previous = vertexCount - 1, i = 0, next = 1;
  7041. while (true) {
  7042. outer: if (!isConcave[i]) {
  7043. var p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1;
  7044. var p1x = vertices[p1], p1y = vertices[p1 + 1];
  7045. var p2x = vertices[p2], p2y = vertices[p2 + 1];
  7046. var p3x = vertices[p3], p3y = vertices[p3 + 1];
  7047. for (var ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
  7048. if (!isConcave[ii])
  7049. continue;
  7050. var v = indices[ii] << 1;
  7051. var vx = vertices[v], vy = vertices[v + 1];
  7052. if (Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
  7053. if (Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
  7054. if (Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy))
  7055. break outer;
  7056. }
  7057. }
  7058. }
  7059. break;
  7060. }
  7061. if (next == 0) {
  7062. do {
  7063. if (!isConcave[i])
  7064. break;
  7065. i--;
  7066. } while (i > 0);
  7067. break;
  7068. }
  7069. previous = i;
  7070. i = next;
  7071. next = (next + 1) % vertexCount;
  7072. }
  7073. triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
  7074. triangles.push(indices[i]);
  7075. triangles.push(indices[(i + 1) % vertexCount]);
  7076. indices.splice(i, 1);
  7077. isConcave.splice(i, 1);
  7078. vertexCount--;
  7079. var previousIndex = (vertexCount + i - 1) % vertexCount;
  7080. var nextIndex = i == vertexCount ? 0 : i;
  7081. isConcave[previousIndex] = Triangulator.isConcave(previousIndex, vertexCount, vertices, indices);
  7082. isConcave[nextIndex] = Triangulator.isConcave(nextIndex, vertexCount, vertices, indices);
  7083. }
  7084. if (vertexCount == 3) {
  7085. triangles.push(indices[2]);
  7086. triangles.push(indices[0]);
  7087. triangles.push(indices[1]);
  7088. }
  7089. return triangles;
  7090. };
  7091. Triangulator.prototype.decompose = function (verticesArray, triangles) {
  7092. var vertices = verticesArray;
  7093. var convexPolygons = this.convexPolygons;
  7094. this.polygonPool.freeAll(convexPolygons);
  7095. convexPolygons.length = 0;
  7096. var convexPolygonsIndices = this.convexPolygonsIndices;
  7097. this.polygonIndicesPool.freeAll(convexPolygonsIndices);
  7098. convexPolygonsIndices.length = 0;
  7099. var polygonIndices = this.polygonIndicesPool.obtain();
  7100. polygonIndices.length = 0;
  7101. var polygon = this.polygonPool.obtain();
  7102. polygon.length = 0;
  7103. var fanBaseIndex = -1, lastWinding = 0;
  7104. for (var i = 0, n = triangles.length; i < n; i += 3) {
  7105. var t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1;
  7106. var x1 = vertices[t1], y1 = vertices[t1 + 1];
  7107. var x2 = vertices[t2], y2 = vertices[t2 + 1];
  7108. var x3 = vertices[t3], y3 = vertices[t3 + 1];
  7109. var merged = false;
  7110. if (fanBaseIndex == t1) {
  7111. var o = polygon.length - 4;
  7112. var winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
  7113. var winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
  7114. if (winding1 == lastWinding && winding2 == lastWinding) {
  7115. polygon.push(x3);
  7116. polygon.push(y3);
  7117. polygonIndices.push(t3);
  7118. merged = true;
  7119. }
  7120. }
  7121. if (!merged) {
  7122. if (polygon.length > 0) {
  7123. convexPolygons.push(polygon);
  7124. convexPolygonsIndices.push(polygonIndices);
  7125. }
  7126. else {
  7127. this.polygonPool.free(polygon);
  7128. this.polygonIndicesPool.free(polygonIndices);
  7129. }
  7130. polygon = this.polygonPool.obtain();
  7131. polygon.length = 0;
  7132. polygon.push(x1);
  7133. polygon.push(y1);
  7134. polygon.push(x2);
  7135. polygon.push(y2);
  7136. polygon.push(x3);
  7137. polygon.push(y3);
  7138. polygonIndices = this.polygonIndicesPool.obtain();
  7139. polygonIndices.length = 0;
  7140. polygonIndices.push(t1);
  7141. polygonIndices.push(t2);
  7142. polygonIndices.push(t3);
  7143. lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
  7144. fanBaseIndex = t1;
  7145. }
  7146. }
  7147. if (polygon.length > 0) {
  7148. convexPolygons.push(polygon);
  7149. convexPolygonsIndices.push(polygonIndices);
  7150. }
  7151. for (var i = 0, n = convexPolygons.length; i < n; i++) {
  7152. polygonIndices = convexPolygonsIndices[i];
  7153. if (polygonIndices.length == 0)
  7154. continue;
  7155. var firstIndex = polygonIndices[0];
  7156. var lastIndex = polygonIndices[polygonIndices.length - 1];
  7157. polygon = convexPolygons[i];
  7158. var o = polygon.length - 4;
  7159. var prevPrevX = polygon[o], prevPrevY = polygon[o + 1];
  7160. var prevX = polygon[o + 2], prevY = polygon[o + 3];
  7161. var firstX = polygon[0], firstY = polygon[1];
  7162. var secondX = polygon[2], secondY = polygon[3];
  7163. var winding = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
  7164. for (var ii = 0; ii < n; ii++) {
  7165. if (ii == i)
  7166. continue;
  7167. var otherIndices = convexPolygonsIndices[ii];
  7168. if (otherIndices.length != 3)
  7169. continue;
  7170. var otherFirstIndex = otherIndices[0];
  7171. var otherSecondIndex = otherIndices[1];
  7172. var otherLastIndex = otherIndices[2];
  7173. var otherPoly = convexPolygons[ii];
  7174. var x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1];
  7175. if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex)
  7176. continue;
  7177. var winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
  7178. var winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
  7179. if (winding1 == winding && winding2 == winding) {
  7180. otherPoly.length = 0;
  7181. otherIndices.length = 0;
  7182. polygon.push(x3);
  7183. polygon.push(y3);
  7184. polygonIndices.push(otherLastIndex);
  7185. prevPrevX = prevX;
  7186. prevPrevY = prevY;
  7187. prevX = x3;
  7188. prevY = y3;
  7189. ii = 0;
  7190. }
  7191. }
  7192. }
  7193. for (var i = convexPolygons.length - 1; i >= 0; i--) {
  7194. polygon = convexPolygons[i];
  7195. if (polygon.length == 0) {
  7196. convexPolygons.splice(i, 1);
  7197. this.polygonPool.free(polygon);
  7198. polygonIndices = convexPolygonsIndices[i];
  7199. convexPolygonsIndices.splice(i, 1);
  7200. this.polygonIndicesPool.free(polygonIndices);
  7201. }
  7202. }
  7203. return convexPolygons;
  7204. };
  7205. Triangulator.isConcave = function (index, vertexCount, vertices, indices) {
  7206. var previous = indices[(vertexCount + index - 1) % vertexCount] << 1;
  7207. var current = indices[index] << 1;
  7208. var next = indices[(index + 1) % vertexCount] << 1;
  7209. return !this.positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]);
  7210. };
  7211. Triangulator.positiveArea = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  7212. return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
  7213. };
  7214. Triangulator.winding = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  7215. var px = p2x - p1x, py = p2y - p1y;
  7216. return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
  7217. };
  7218. return Triangulator;
  7219. }());
  7220. spine.Triangulator = Triangulator;
  7221. })(spine || (spine = {}));
  7222. var spine;
  7223. (function (spine) {
  7224. var IntSet = (function () {
  7225. function IntSet() {
  7226. this.array = new Array();
  7227. }
  7228. IntSet.prototype.add = function (value) {
  7229. var contains = this.contains(value);
  7230. this.array[value | 0] = value | 0;
  7231. return !contains;
  7232. };
  7233. IntSet.prototype.contains = function (value) {
  7234. return this.array[value | 0] != undefined;
  7235. };
  7236. IntSet.prototype.remove = function (value) {
  7237. this.array[value | 0] = undefined;
  7238. };
  7239. IntSet.prototype.clear = function () {
  7240. this.array.length = 0;
  7241. };
  7242. return IntSet;
  7243. }());
  7244. spine.IntSet = IntSet;
  7245. var Color = (function () {
  7246. function Color(r, g, b, a) {
  7247. if (r === void 0) { r = 0; }
  7248. if (g === void 0) { g = 0; }
  7249. if (b === void 0) { b = 0; }
  7250. if (a === void 0) { a = 0; }
  7251. this.r = r;
  7252. this.g = g;
  7253. this.b = b;
  7254. this.a = a;
  7255. }
  7256. Color.prototype.set = function (r, g, b, a) {
  7257. this.r = r;
  7258. this.g = g;
  7259. this.b = b;
  7260. this.a = a;
  7261. this.clamp();
  7262. return this;
  7263. };
  7264. Color.prototype.setFromColor = function (c) {
  7265. this.r = c.r;
  7266. this.g = c.g;
  7267. this.b = c.b;
  7268. this.a = c.a;
  7269. return this;
  7270. };
  7271. Color.prototype.setFromString = function (hex) {
  7272. hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
  7273. this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
  7274. this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
  7275. this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
  7276. this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
  7277. return this;
  7278. };
  7279. Color.prototype.add = function (r, g, b, a) {
  7280. this.r += r;
  7281. this.g += g;
  7282. this.b += b;
  7283. this.a += a;
  7284. this.clamp();
  7285. return this;
  7286. };
  7287. Color.prototype.clamp = function () {
  7288. if (this.r < 0)
  7289. this.r = 0;
  7290. else if (this.r > 1)
  7291. this.r = 1;
  7292. if (this.g < 0)
  7293. this.g = 0;
  7294. else if (this.g > 1)
  7295. this.g = 1;
  7296. if (this.b < 0)
  7297. this.b = 0;
  7298. else if (this.b > 1)
  7299. this.b = 1;
  7300. if (this.a < 0)
  7301. this.a = 0;
  7302. else if (this.a > 1)
  7303. this.a = 1;
  7304. return this;
  7305. };
  7306. Color.rgba8888ToColor = function (color, value) {
  7307. color.r = ((value & 0xff000000) >>> 24) / 255;
  7308. color.g = ((value & 0x00ff0000) >>> 16) / 255;
  7309. color.b = ((value & 0x0000ff00) >>> 8) / 255;
  7310. color.a = ((value & 0x000000ff)) / 255;
  7311. };
  7312. Color.rgb888ToColor = function (color, value) {
  7313. color.r = ((value & 0x00ff0000) >>> 16) / 255;
  7314. color.g = ((value & 0x0000ff00) >>> 8) / 255;
  7315. color.b = ((value & 0x000000ff)) / 255;
  7316. };
  7317. Color.WHITE = new Color(1, 1, 1, 1);
  7318. Color.RED = new Color(1, 0, 0, 1);
  7319. Color.GREEN = new Color(0, 1, 0, 1);
  7320. Color.BLUE = new Color(0, 0, 1, 1);
  7321. Color.MAGENTA = new Color(1, 0, 1, 1);
  7322. return Color;
  7323. }());
  7324. spine.Color = Color;
  7325. var MathUtils = (function () {
  7326. function MathUtils() {
  7327. }
  7328. MathUtils.clamp = function (value, min, max) {
  7329. if (value < min)
  7330. return min;
  7331. if (value > max)
  7332. return max;
  7333. return value;
  7334. };
  7335. MathUtils.cosDeg = function (degrees) {
  7336. return Math.cos(degrees * MathUtils.degRad);
  7337. };
  7338. MathUtils.sinDeg = function (degrees) {
  7339. return Math.sin(degrees * MathUtils.degRad);
  7340. };
  7341. MathUtils.signum = function (value) {
  7342. return value > 0 ? 1 : value < 0 ? -1 : 0;
  7343. };
  7344. MathUtils.toInt = function (x) {
  7345. return x > 0 ? Math.floor(x) : Math.ceil(x);
  7346. };
  7347. MathUtils.cbrt = function (x) {
  7348. var y = Math.pow(Math.abs(x), 1 / 3);
  7349. return x < 0 ? -y : y;
  7350. };
  7351. MathUtils.randomTriangular = function (min, max) {
  7352. return MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
  7353. };
  7354. MathUtils.randomTriangularWith = function (min, max, mode) {
  7355. var u = Math.random();
  7356. var d = max - min;
  7357. if (u <= (mode - min) / d)
  7358. return min + Math.sqrt(u * d * (mode - min));
  7359. return max - Math.sqrt((1 - u) * d * (max - mode));
  7360. };
  7361. MathUtils.PI = 3.1415927;
  7362. MathUtils.PI2 = MathUtils.PI * 2;
  7363. MathUtils.radiansToDegrees = 180 / MathUtils.PI;
  7364. MathUtils.radDeg = MathUtils.radiansToDegrees;
  7365. MathUtils.degreesToRadians = MathUtils.PI / 180;
  7366. MathUtils.degRad = MathUtils.degreesToRadians;
  7367. return MathUtils;
  7368. }());
  7369. spine.MathUtils = MathUtils;
  7370. var Interpolation = (function () {
  7371. function Interpolation() {
  7372. }
  7373. Interpolation.prototype.apply = function (start, end, a) {
  7374. return start + (end - start) * this.applyInternal(a);
  7375. };
  7376. return Interpolation;
  7377. }());
  7378. spine.Interpolation = Interpolation;
  7379. var Pow = (function (_super) {
  7380. __extends(Pow, _super);
  7381. function Pow(power) {
  7382. var _this = _super.call(this) || this;
  7383. _this.power = 2;
  7384. _this.power = power;
  7385. return _this;
  7386. }
  7387. Pow.prototype.applyInternal = function (a) {
  7388. if (a <= 0.5)
  7389. return Math.pow(a * 2, this.power) / 2;
  7390. return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
  7391. };
  7392. return Pow;
  7393. }(Interpolation));
  7394. spine.Pow = Pow;
  7395. var PowOut = (function (_super) {
  7396. __extends(PowOut, _super);
  7397. function PowOut(power) {
  7398. return _super.call(this, power) || this;
  7399. }
  7400. PowOut.prototype.applyInternal = function (a) {
  7401. return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
  7402. };
  7403. return PowOut;
  7404. }(Pow));
  7405. spine.PowOut = PowOut;
  7406. var Utils = (function () {
  7407. function Utils() {
  7408. }
  7409. Utils.arrayCopy = function (source, sourceStart, dest, destStart, numElements) {
  7410. for (var i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  7411. dest[j] = source[i];
  7412. }
  7413. };
  7414. Utils.setArraySize = function (array, size, value) {
  7415. if (value === void 0) { value = 0; }
  7416. var oldSize = array.length;
  7417. if (oldSize == size)
  7418. return array;
  7419. array.length = size;
  7420. if (oldSize < size) {
  7421. for (var i = oldSize; i < size; i++)
  7422. array[i] = value;
  7423. }
  7424. return array;
  7425. };
  7426. Utils.ensureArrayCapacity = function (array, size, value) {
  7427. if (value === void 0) { value = 0; }
  7428. if (array.length >= size)
  7429. return array;
  7430. return Utils.setArraySize(array, size, value);
  7431. };
  7432. Utils.newArray = function (size, defaultValue) {
  7433. var array = new Array(size);
  7434. for (var i = 0; i < size; i++)
  7435. array[i] = defaultValue;
  7436. return array;
  7437. };
  7438. Utils.newFloatArray = function (size) {
  7439. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  7440. return new Float32Array(size);
  7441. }
  7442. else {
  7443. var array = new Array(size);
  7444. for (var i = 0; i < array.length; i++)
  7445. array[i] = 0;
  7446. return array;
  7447. }
  7448. };
  7449. Utils.newShortArray = function (size) {
  7450. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  7451. return new Int16Array(size);
  7452. }
  7453. else {
  7454. var array = new Array(size);
  7455. for (var i = 0; i < array.length; i++)
  7456. array[i] = 0;
  7457. return array;
  7458. }
  7459. };
  7460. Utils.toFloatArray = function (array) {
  7461. return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  7462. };
  7463. Utils.toSinglePrecision = function (value) {
  7464. return Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
  7465. };
  7466. Utils.webkit602BugfixHelper = function (alpha, blend) {
  7467. };
  7468. Utils.contains = function (array, element, identity) {
  7469. if (identity === void 0) { identity = true; }
  7470. for (var i = 0; i < array.length; i++) {
  7471. if (array[i] == element)
  7472. return true;
  7473. }
  7474. return false;
  7475. };
  7476. Utils.SUPPORTS_TYPED_ARRAYS = typeof (Float32Array) !== "undefined";
  7477. return Utils;
  7478. }());
  7479. spine.Utils = Utils;
  7480. var DebugUtils = (function () {
  7481. function DebugUtils() {
  7482. }
  7483. DebugUtils.logBones = function (skeleton) {
  7484. for (var i = 0; i < skeleton.bones.length; i++) {
  7485. var bone = skeleton.bones[i];
  7486. console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
  7487. }
  7488. };
  7489. return DebugUtils;
  7490. }());
  7491. spine.DebugUtils = DebugUtils;
  7492. var Pool = (function () {
  7493. function Pool(instantiator) {
  7494. this.items = new Array();
  7495. this.instantiator = instantiator;
  7496. }
  7497. Pool.prototype.obtain = function () {
  7498. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  7499. };
  7500. Pool.prototype.free = function (item) {
  7501. if (item.reset)
  7502. item.reset();
  7503. this.items.push(item);
  7504. };
  7505. Pool.prototype.freeAll = function (items) {
  7506. for (var i = 0; i < items.length; i++) {
  7507. if (items[i].reset)
  7508. items[i].reset();
  7509. this.items[i] = items[i];
  7510. }
  7511. };
  7512. Pool.prototype.clear = function () {
  7513. this.items.length = 0;
  7514. };
  7515. return Pool;
  7516. }());
  7517. spine.Pool = Pool;
  7518. var Vector2 = (function () {
  7519. function Vector2(x, y) {
  7520. if (x === void 0) { x = 0; }
  7521. if (y === void 0) { y = 0; }
  7522. this.x = x;
  7523. this.y = y;
  7524. }
  7525. Vector2.prototype.set = function (x, y) {
  7526. this.x = x;
  7527. this.y = y;
  7528. return this;
  7529. };
  7530. Vector2.prototype.length = function () {
  7531. var x = this.x;
  7532. var y = this.y;
  7533. return Math.sqrt(x * x + y * y);
  7534. };
  7535. Vector2.prototype.normalize = function () {
  7536. var len = this.length();
  7537. if (len != 0) {
  7538. this.x /= len;
  7539. this.y /= len;
  7540. }
  7541. return this;
  7542. };
  7543. return Vector2;
  7544. }());
  7545. spine.Vector2 = Vector2;
  7546. var TimeKeeper = (function () {
  7547. function TimeKeeper() {
  7548. this.maxDelta = 0.064;
  7549. this.framesPerSecond = 0;
  7550. this.delta = 0;
  7551. this.totalTime = 0;
  7552. this.lastTime = Date.now() / 1000;
  7553. this.frameCount = 0;
  7554. this.frameTime = 0;
  7555. }
  7556. TimeKeeper.prototype.update = function () {
  7557. var now = Date.now() / 1000;
  7558. this.delta = now - this.lastTime;
  7559. this.frameTime += this.delta;
  7560. this.totalTime += this.delta;
  7561. if (this.delta > this.maxDelta)
  7562. this.delta = this.maxDelta;
  7563. this.lastTime = now;
  7564. this.frameCount++;
  7565. if (this.frameTime > 1) {
  7566. this.framesPerSecond = this.frameCount / this.frameTime;
  7567. this.frameTime = 0;
  7568. this.frameCount = 0;
  7569. }
  7570. };
  7571. return TimeKeeper;
  7572. }());
  7573. spine.TimeKeeper = TimeKeeper;
  7574. var WindowedMean = (function () {
  7575. function WindowedMean(windowSize) {
  7576. if (windowSize === void 0) { windowSize = 32; }
  7577. this.addedValues = 0;
  7578. this.lastValue = 0;
  7579. this.mean = 0;
  7580. this.dirty = true;
  7581. this.values = new Array(windowSize);
  7582. }
  7583. WindowedMean.prototype.hasEnoughData = function () {
  7584. return this.addedValues >= this.values.length;
  7585. };
  7586. WindowedMean.prototype.addValue = function (value) {
  7587. if (this.addedValues < this.values.length)
  7588. this.addedValues++;
  7589. this.values[this.lastValue++] = value;
  7590. if (this.lastValue > this.values.length - 1)
  7591. this.lastValue = 0;
  7592. this.dirty = true;
  7593. };
  7594. WindowedMean.prototype.getMean = function () {
  7595. if (this.hasEnoughData()) {
  7596. if (this.dirty) {
  7597. var mean = 0;
  7598. for (var i = 0; i < this.values.length; i++) {
  7599. mean += this.values[i];
  7600. }
  7601. this.mean = mean / this.values.length;
  7602. this.dirty = false;
  7603. }
  7604. return this.mean;
  7605. }
  7606. else {
  7607. return 0;
  7608. }
  7609. };
  7610. return WindowedMean;
  7611. }());
  7612. spine.WindowedMean = WindowedMean;
  7613. })(spine || (spine = {}));
  7614. (function () {
  7615. if (!Math.fround) {
  7616. Math.fround = (function (array) {
  7617. return function (x) {
  7618. return array[0] = x, array[0];
  7619. };
  7620. })(new Float32Array(1));
  7621. }
  7622. })();
  7623. var spine;
  7624. (function (spine) {
  7625. var Attachment = (function () {
  7626. function Attachment(name) {
  7627. if (name == null)
  7628. throw new Error("name cannot be null.");
  7629. this.name = name;
  7630. }
  7631. return Attachment;
  7632. }());
  7633. spine.Attachment = Attachment;
  7634. var VertexAttachment = (function (_super) {
  7635. __extends(VertexAttachment, _super);
  7636. function VertexAttachment(name) {
  7637. var _this = _super.call(this, name) || this;
  7638. _this.id = (VertexAttachment.nextID++ & 65535) << 11;
  7639. _this.worldVerticesLength = 0;
  7640. _this.deformAttachment = _this;
  7641. return _this;
  7642. }
  7643. VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
  7644. count = offset + (count >> 1) * stride;
  7645. var skeleton = slot.bone.skeleton;
  7646. var deformArray = slot.deform;
  7647. var vertices = this.vertices;
  7648. var bones = this.bones;
  7649. if (bones == null) {
  7650. if (deformArray.length > 0)
  7651. vertices = deformArray;
  7652. var bone = slot.bone;
  7653. var x = bone.worldX;
  7654. var y = bone.worldY;
  7655. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  7656. for (var v_1 = start, w = offset; w < count; v_1 += 2, w += stride) {
  7657. var vx = vertices[v_1], vy = vertices[v_1 + 1];
  7658. worldVertices[w] = vx * a + vy * b + x;
  7659. worldVertices[w + 1] = vx * c + vy * d + y;
  7660. }
  7661. return;
  7662. }
  7663. var v = 0, skip = 0;
  7664. for (var i = 0; i < start; i += 2) {
  7665. var n = bones[v];
  7666. v += n + 1;
  7667. skip += n;
  7668. }
  7669. var skeletonBones = skeleton.bones;
  7670. if (deformArray.length == 0) {
  7671. for (var w = offset, b = skip * 3; w < count; w += stride) {
  7672. var wx = 0, wy = 0;
  7673. var n = bones[v++];
  7674. n += v;
  7675. for (; v < n; v++, b += 3) {
  7676. var bone = skeletonBones[bones[v]];
  7677. var vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  7678. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  7679. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  7680. }
  7681. worldVertices[w] = wx;
  7682. worldVertices[w + 1] = wy;
  7683. }
  7684. }
  7685. else {
  7686. var deform = deformArray;
  7687. for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  7688. var wx = 0, wy = 0;
  7689. var n = bones[v++];
  7690. n += v;
  7691. for (; v < n; v++, b += 3, f += 2) {
  7692. var bone = skeletonBones[bones[v]];
  7693. var vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  7694. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  7695. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  7696. }
  7697. worldVertices[w] = wx;
  7698. worldVertices[w + 1] = wy;
  7699. }
  7700. }
  7701. };
  7702. VertexAttachment.prototype.copyTo = function (attachment) {
  7703. if (this.bones != null) {
  7704. attachment.bones = new Array(this.bones.length);
  7705. spine.Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
  7706. }
  7707. else
  7708. attachment.bones = null;
  7709. if (this.vertices != null) {
  7710. attachment.vertices = spine.Utils.newFloatArray(this.vertices.length);
  7711. spine.Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
  7712. }
  7713. else
  7714. attachment.vertices = null;
  7715. attachment.worldVerticesLength = this.worldVerticesLength;
  7716. attachment.deformAttachment = this.deformAttachment;
  7717. };
  7718. VertexAttachment.nextID = 0;
  7719. return VertexAttachment;
  7720. }(Attachment));
  7721. spine.VertexAttachment = VertexAttachment;
  7722. })(spine || (spine = {}));
  7723. var spine;
  7724. (function (spine) {
  7725. var AttachmentType;
  7726. (function (AttachmentType) {
  7727. AttachmentType[AttachmentType["Region"] = 0] = "Region";
  7728. AttachmentType[AttachmentType["BoundingBox"] = 1] = "BoundingBox";
  7729. AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
  7730. AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
  7731. AttachmentType[AttachmentType["Path"] = 4] = "Path";
  7732. AttachmentType[AttachmentType["Point"] = 5] = "Point";
  7733. AttachmentType[AttachmentType["Clipping"] = 6] = "Clipping";
  7734. })(AttachmentType = spine.AttachmentType || (spine.AttachmentType = {}));
  7735. })(spine || (spine = {}));
  7736. var spine;
  7737. (function (spine) {
  7738. var BoundingBoxAttachment = (function (_super) {
  7739. __extends(BoundingBoxAttachment, _super);
  7740. function BoundingBoxAttachment(name) {
  7741. var _this = _super.call(this, name) || this;
  7742. _this.color = new spine.Color(1, 1, 1, 1);
  7743. return _this;
  7744. }
  7745. BoundingBoxAttachment.prototype.copy = function () {
  7746. var copy = new BoundingBoxAttachment(name);
  7747. this.copyTo(copy);
  7748. copy.color.setFromColor(this.color);
  7749. return copy;
  7750. };
  7751. return BoundingBoxAttachment;
  7752. }(spine.VertexAttachment));
  7753. spine.BoundingBoxAttachment = BoundingBoxAttachment;
  7754. })(spine || (spine = {}));
  7755. var spine;
  7756. (function (spine) {
  7757. var ClippingAttachment = (function (_super) {
  7758. __extends(ClippingAttachment, _super);
  7759. function ClippingAttachment(name) {
  7760. var _this = _super.call(this, name) || this;
  7761. _this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1);
  7762. return _this;
  7763. }
  7764. ClippingAttachment.prototype.copy = function () {
  7765. var copy = new ClippingAttachment(name);
  7766. this.copyTo(copy);
  7767. copy.endSlot = this.endSlot;
  7768. copy.color.setFromColor(this.color);
  7769. return copy;
  7770. };
  7771. return ClippingAttachment;
  7772. }(spine.VertexAttachment));
  7773. spine.ClippingAttachment = ClippingAttachment;
  7774. })(spine || (spine = {}));
  7775. var spine;
  7776. (function (spine) {
  7777. var MeshAttachment = (function (_super) {
  7778. __extends(MeshAttachment, _super);
  7779. function MeshAttachment(name) {
  7780. var _this = _super.call(this, name) || this;
  7781. _this.color = new spine.Color(1, 1, 1, 1);
  7782. _this.tempColor = new spine.Color(0, 0, 0, 0);
  7783. return _this;
  7784. }
  7785. MeshAttachment.prototype.updateUVs = function () {
  7786. var regionUVs = this.regionUVs;
  7787. if (this.uvs == null || this.uvs.length != regionUVs.length)
  7788. this.uvs = spine.Utils.newFloatArray(regionUVs.length);
  7789. var uvs = this.uvs;
  7790. var n = this.uvs.length;
  7791. var u = this.region.u, v = this.region.v, width = 0, height = 0;
  7792. if (this.region instanceof spine.TextureAtlasRegion) {
  7793. var region = this.region;
  7794. var textureWidth = region.texture.getImage().width, textureHeight = region.texture.getImage().height;
  7795. switch (region.degrees) {
  7796. case 90:
  7797. u -= (region.originalHeight - region.offsetY - region.height) / textureWidth;
  7798. v -= (region.originalWidth - region.offsetX - region.width) / textureHeight;
  7799. width = region.originalHeight / textureWidth;
  7800. height = region.originalWidth / textureHeight;
  7801. for (var i = 0; i < n; i += 2) {
  7802. uvs[i] = u + regionUVs[i + 1] * width;
  7803. uvs[i + 1] = v + (1 - regionUVs[i]) * height;
  7804. }
  7805. return;
  7806. case 180:
  7807. u -= (region.originalWidth - region.offsetX - region.width) / textureWidth;
  7808. v -= region.offsetY / textureHeight;
  7809. width = region.originalWidth / textureWidth;
  7810. height = region.originalHeight / textureHeight;
  7811. for (var i = 0; i < n; i += 2) {
  7812. uvs[i] = u + (1 - regionUVs[i]) * width;
  7813. uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
  7814. }
  7815. return;
  7816. case 270:
  7817. u -= region.offsetY / textureWidth;
  7818. v -= region.offsetX / textureHeight;
  7819. width = region.originalHeight / textureWidth;
  7820. height = region.originalWidth / textureHeight;
  7821. for (var i = 0; i < n; i += 2) {
  7822. uvs[i] = u + (1 - regionUVs[i + 1]) * width;
  7823. uvs[i + 1] = v + regionUVs[i] * height;
  7824. }
  7825. return;
  7826. }
  7827. u -= region.offsetX / textureWidth;
  7828. v -= (region.originalHeight - region.offsetY - region.height) / textureHeight;
  7829. width = region.originalWidth / textureWidth;
  7830. height = region.originalHeight / textureHeight;
  7831. }
  7832. else if (this.region == null) {
  7833. u = v = 0;
  7834. width = height = 1;
  7835. }
  7836. else {
  7837. width = this.region.u2 - u;
  7838. height = this.region.v2 - v;
  7839. }
  7840. for (var i = 0; i < n; i += 2) {
  7841. uvs[i] = u + regionUVs[i] * width;
  7842. uvs[i + 1] = v + regionUVs[i + 1] * height;
  7843. }
  7844. };
  7845. MeshAttachment.prototype.getParentMesh = function () {
  7846. return this.parentMesh;
  7847. };
  7848. MeshAttachment.prototype.setParentMesh = function (parentMesh) {
  7849. this.parentMesh = parentMesh;
  7850. if (parentMesh != null) {
  7851. this.bones = parentMesh.bones;
  7852. this.vertices = parentMesh.vertices;
  7853. this.worldVerticesLength = parentMesh.worldVerticesLength;
  7854. this.regionUVs = parentMesh.regionUVs;
  7855. this.triangles = parentMesh.triangles;
  7856. this.hullLength = parentMesh.hullLength;
  7857. this.worldVerticesLength = parentMesh.worldVerticesLength;
  7858. }
  7859. };
  7860. MeshAttachment.prototype.copy = function () {
  7861. if (this.parentMesh != null)
  7862. return this.newLinkedMesh();
  7863. var copy = new MeshAttachment(this.name);
  7864. copy.region = this.region;
  7865. copy.path = this.path;
  7866. copy.color.setFromColor(this.color);
  7867. this.copyTo(copy);
  7868. copy.regionUVs = new Array(this.regionUVs.length);
  7869. spine.Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
  7870. copy.uvs = new Array(this.uvs.length);
  7871. spine.Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
  7872. copy.triangles = new Array(this.triangles.length);
  7873. spine.Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
  7874. copy.hullLength = this.hullLength;
  7875. if (this.edges != null) {
  7876. copy.edges = new Array(this.edges.length);
  7877. spine.Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
  7878. }
  7879. copy.width = this.width;
  7880. copy.height = this.height;
  7881. return copy;
  7882. };
  7883. MeshAttachment.prototype.newLinkedMesh = function () {
  7884. var copy = new MeshAttachment(this.name);
  7885. copy.region = this.region;
  7886. copy.path = this.path;
  7887. copy.color.setFromColor(this.color);
  7888. copy.deformAttachment = this.deformAttachment;
  7889. copy.setParentMesh(this.parentMesh != null ? this.parentMesh : this);
  7890. copy.updateUVs();
  7891. return copy;
  7892. };
  7893. return MeshAttachment;
  7894. }(spine.VertexAttachment));
  7895. spine.MeshAttachment = MeshAttachment;
  7896. })(spine || (spine = {}));
  7897. var spine;
  7898. (function (spine) {
  7899. var PathAttachment = (function (_super) {
  7900. __extends(PathAttachment, _super);
  7901. function PathAttachment(name) {
  7902. var _this = _super.call(this, name) || this;
  7903. _this.closed = false;
  7904. _this.constantSpeed = false;
  7905. _this.color = new spine.Color(1, 1, 1, 1);
  7906. return _this;
  7907. }
  7908. PathAttachment.prototype.copy = function () {
  7909. var copy = new PathAttachment(name);
  7910. this.copyTo(copy);
  7911. copy.lengths = new Array(this.lengths.length);
  7912. spine.Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
  7913. copy.closed = closed;
  7914. copy.constantSpeed = this.constantSpeed;
  7915. copy.color.setFromColor(this.color);
  7916. return copy;
  7917. };
  7918. return PathAttachment;
  7919. }(spine.VertexAttachment));
  7920. spine.PathAttachment = PathAttachment;
  7921. })(spine || (spine = {}));
  7922. var spine;
  7923. (function (spine) {
  7924. var PointAttachment = (function (_super) {
  7925. __extends(PointAttachment, _super);
  7926. function PointAttachment(name) {
  7927. var _this = _super.call(this, name) || this;
  7928. _this.color = new spine.Color(0.38, 0.94, 0, 1);
  7929. return _this;
  7930. }
  7931. PointAttachment.prototype.computeWorldPosition = function (bone, point) {
  7932. point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
  7933. point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
  7934. return point;
  7935. };
  7936. PointAttachment.prototype.computeWorldRotation = function (bone) {
  7937. var cos = spine.MathUtils.cosDeg(this.rotation), sin = spine.MathUtils.sinDeg(this.rotation);
  7938. var x = cos * bone.a + sin * bone.b;
  7939. var y = cos * bone.c + sin * bone.d;
  7940. return Math.atan2(y, x) * spine.MathUtils.radDeg;
  7941. };
  7942. PointAttachment.prototype.copy = function () {
  7943. var copy = new PointAttachment(name);
  7944. copy.x = this.x;
  7945. copy.y = this.y;
  7946. copy.rotation = this.rotation;
  7947. copy.color.setFromColor(this.color);
  7948. return copy;
  7949. };
  7950. return PointAttachment;
  7951. }(spine.VertexAttachment));
  7952. spine.PointAttachment = PointAttachment;
  7953. })(spine || (spine = {}));
  7954. var spine;
  7955. (function (spine) {
  7956. var RegionAttachment = (function (_super) {
  7957. __extends(RegionAttachment, _super);
  7958. function RegionAttachment(name) {
  7959. var _this = _super.call(this, name) || this;
  7960. _this.x = 0;
  7961. _this.y = 0;
  7962. _this.scaleX = 1;
  7963. _this.scaleY = 1;
  7964. _this.rotation = 0;
  7965. _this.width = 0;
  7966. _this.height = 0;
  7967. _this.color = new spine.Color(1, 1, 1, 1);
  7968. _this.offset = spine.Utils.newFloatArray(8);
  7969. _this.uvs = spine.Utils.newFloatArray(8);
  7970. _this.tempColor = new spine.Color(1, 1, 1, 1);
  7971. return _this;
  7972. }
  7973. RegionAttachment.prototype.updateOffset = function () {
  7974. var regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  7975. var regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  7976. var localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  7977. var localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  7978. var localX2 = localX + this.region.width * regionScaleX;
  7979. var localY2 = localY + this.region.height * regionScaleY;
  7980. var radians = this.rotation * Math.PI / 180;
  7981. var cos = Math.cos(radians);
  7982. var sin = Math.sin(radians);
  7983. var localXCos = localX * cos + this.x;
  7984. var localXSin = localX * sin;
  7985. var localYCos = localY * cos + this.y;
  7986. var localYSin = localY * sin;
  7987. var localX2Cos = localX2 * cos + this.x;
  7988. var localX2Sin = localX2 * sin;
  7989. var localY2Cos = localY2 * cos + this.y;
  7990. var localY2Sin = localY2 * sin;
  7991. var offset = this.offset;
  7992. offset[RegionAttachment.OX1] = localXCos - localYSin;
  7993. offset[RegionAttachment.OY1] = localYCos + localXSin;
  7994. offset[RegionAttachment.OX2] = localXCos - localY2Sin;
  7995. offset[RegionAttachment.OY2] = localY2Cos + localXSin;
  7996. offset[RegionAttachment.OX3] = localX2Cos - localY2Sin;
  7997. offset[RegionAttachment.OY3] = localY2Cos + localX2Sin;
  7998. offset[RegionAttachment.OX4] = localX2Cos - localYSin;
  7999. offset[RegionAttachment.OY4] = localYCos + localX2Sin;
  8000. };
  8001. RegionAttachment.prototype.setRegion = function (region) {
  8002. this.region = region;
  8003. var uvs = this.uvs;
  8004. if (region.rotate) {
  8005. uvs[2] = region.u;
  8006. uvs[3] = region.v2;
  8007. uvs[4] = region.u;
  8008. uvs[5] = region.v;
  8009. uvs[6] = region.u2;
  8010. uvs[7] = region.v;
  8011. uvs[0] = region.u2;
  8012. uvs[1] = region.v2;
  8013. }
  8014. else {
  8015. uvs[0] = region.u;
  8016. uvs[1] = region.v2;
  8017. uvs[2] = region.u;
  8018. uvs[3] = region.v;
  8019. uvs[4] = region.u2;
  8020. uvs[5] = region.v;
  8021. uvs[6] = region.u2;
  8022. uvs[7] = region.v2;
  8023. }
  8024. };
  8025. RegionAttachment.prototype.computeWorldVertices = function (bone, worldVertices, offset, stride) {
  8026. var vertexOffset = this.offset;
  8027. var x = bone.worldX, y = bone.worldY;
  8028. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  8029. var offsetX = 0, offsetY = 0;
  8030. offsetX = vertexOffset[RegionAttachment.OX1];
  8031. offsetY = vertexOffset[RegionAttachment.OY1];
  8032. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8033. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8034. offset += stride;
  8035. offsetX = vertexOffset[RegionAttachment.OX2];
  8036. offsetY = vertexOffset[RegionAttachment.OY2];
  8037. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8038. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8039. offset += stride;
  8040. offsetX = vertexOffset[RegionAttachment.OX3];
  8041. offsetY = vertexOffset[RegionAttachment.OY3];
  8042. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8043. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8044. offset += stride;
  8045. offsetX = vertexOffset[RegionAttachment.OX4];
  8046. offsetY = vertexOffset[RegionAttachment.OY4];
  8047. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8048. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8049. };
  8050. RegionAttachment.prototype.copy = function () {
  8051. var copy = new RegionAttachment(name);
  8052. copy.region = this.region;
  8053. copy.rendererObject = this.rendererObject;
  8054. copy.path = this.path;
  8055. copy.x = this.x;
  8056. copy.y = this.y;
  8057. copy.scaleX = this.scaleX;
  8058. copy.scaleY = this.scaleY;
  8059. copy.rotation = this.rotation;
  8060. copy.width = this.width;
  8061. copy.height = this.height;
  8062. spine.Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
  8063. spine.Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
  8064. copy.color.setFromColor(this.color);
  8065. return copy;
  8066. };
  8067. RegionAttachment.OX1 = 0;
  8068. RegionAttachment.OY1 = 1;
  8069. RegionAttachment.OX2 = 2;
  8070. RegionAttachment.OY2 = 3;
  8071. RegionAttachment.OX3 = 4;
  8072. RegionAttachment.OY3 = 5;
  8073. RegionAttachment.OX4 = 6;
  8074. RegionAttachment.OY4 = 7;
  8075. RegionAttachment.X1 = 0;
  8076. RegionAttachment.Y1 = 1;
  8077. RegionAttachment.C1R = 2;
  8078. RegionAttachment.C1G = 3;
  8079. RegionAttachment.C1B = 4;
  8080. RegionAttachment.C1A = 5;
  8081. RegionAttachment.U1 = 6;
  8082. RegionAttachment.V1 = 7;
  8083. RegionAttachment.X2 = 8;
  8084. RegionAttachment.Y2 = 9;
  8085. RegionAttachment.C2R = 10;
  8086. RegionAttachment.C2G = 11;
  8087. RegionAttachment.C2B = 12;
  8088. RegionAttachment.C2A = 13;
  8089. RegionAttachment.U2 = 14;
  8090. RegionAttachment.V2 = 15;
  8091. RegionAttachment.X3 = 16;
  8092. RegionAttachment.Y3 = 17;
  8093. RegionAttachment.C3R = 18;
  8094. RegionAttachment.C3G = 19;
  8095. RegionAttachment.C3B = 20;
  8096. RegionAttachment.C3A = 21;
  8097. RegionAttachment.U3 = 22;
  8098. RegionAttachment.V3 = 23;
  8099. RegionAttachment.X4 = 24;
  8100. RegionAttachment.Y4 = 25;
  8101. RegionAttachment.C4R = 26;
  8102. RegionAttachment.C4G = 27;
  8103. RegionAttachment.C4B = 28;
  8104. RegionAttachment.C4A = 29;
  8105. RegionAttachment.U4 = 30;
  8106. RegionAttachment.V4 = 31;
  8107. return RegionAttachment;
  8108. }(spine.Attachment));
  8109. spine.RegionAttachment = RegionAttachment;
  8110. })(spine || (spine = {}));
  8111. var spine;
  8112. (function (spine) {
  8113. var JitterEffect = (function () {
  8114. function JitterEffect(jitterX, jitterY) {
  8115. this.jitterX = 0;
  8116. this.jitterY = 0;
  8117. this.jitterX = jitterX;
  8118. this.jitterY = jitterY;
  8119. }
  8120. JitterEffect.prototype.begin = function (skeleton) {
  8121. };
  8122. JitterEffect.prototype.transform = function (position, uv, light, dark) {
  8123. position.x += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  8124. position.y += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  8125. };
  8126. JitterEffect.prototype.end = function () {
  8127. };
  8128. return JitterEffect;
  8129. }());
  8130. spine.JitterEffect = JitterEffect;
  8131. })(spine || (spine = {}));
  8132. var spine;
  8133. (function (spine) {
  8134. var SwirlEffect = (function () {
  8135. function SwirlEffect(radius) {
  8136. this.centerX = 0;
  8137. this.centerY = 0;
  8138. this.radius = 0;
  8139. this.angle = 0;
  8140. this.worldX = 0;
  8141. this.worldY = 0;
  8142. this.radius = radius;
  8143. }
  8144. SwirlEffect.prototype.begin = function (skeleton) {
  8145. this.worldX = skeleton.x + this.centerX;
  8146. this.worldY = skeleton.y + this.centerY;
  8147. };
  8148. SwirlEffect.prototype.transform = function (position, uv, light, dark) {
  8149. var radAngle = this.angle * spine.MathUtils.degreesToRadians;
  8150. var x = position.x - this.worldX;
  8151. var y = position.y - this.worldY;
  8152. var dist = Math.sqrt(x * x + y * y);
  8153. if (dist < this.radius) {
  8154. var theta = SwirlEffect.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  8155. var cos = Math.cos(theta);
  8156. var sin = Math.sin(theta);
  8157. position.x = cos * x - sin * y + this.worldX;
  8158. position.y = sin * x + cos * y + this.worldY;
  8159. }
  8160. };
  8161. SwirlEffect.prototype.end = function () {
  8162. };
  8163. SwirlEffect.interpolation = new spine.PowOut(2);
  8164. return SwirlEffect;
  8165. }());
  8166. spine.SwirlEffect = SwirlEffect;
  8167. })(spine || (spine = {}));
  8168. var spine;
  8169. (function (spine) {
  8170. var threejs;
  8171. (function (threejs) {
  8172. var AssetManager = (function (_super) {
  8173. __extends(AssetManager, _super);
  8174. function AssetManager(pathPrefix) {
  8175. if (pathPrefix === void 0) { pathPrefix = ""; }
  8176. return _super.call(this, function (image) {
  8177. return new threejs.ThreeJsTexture(image);
  8178. }, pathPrefix) || this;
  8179. }
  8180. return AssetManager;
  8181. }(spine.AssetManager));
  8182. threejs.AssetManager = AssetManager;
  8183. })(threejs = spine.threejs || (spine.threejs = {}));
  8184. })(spine || (spine = {}));
  8185. var spine;
  8186. (function (spine) {
  8187. var threejs;
  8188. (function (threejs) {
  8189. var MeshBatcher = (function (_super) {
  8190. __extends(MeshBatcher, _super);
  8191. function MeshBatcher(maxVertices, materialCustomizer) {
  8192. if (maxVertices === void 0) { maxVertices = 10920; }
  8193. if (materialCustomizer === void 0) { materialCustomizer = function (parameters) { }; }
  8194. var _this = _super.call(this) || this;
  8195. _this.verticesLength = 0;
  8196. _this.indicesLength = 0;
  8197. if (maxVertices > 10920)
  8198. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  8199. var vertices = _this.vertices = new Float32Array(maxVertices * MeshBatcher.VERTEX_SIZE);
  8200. var indices = _this.indices = new Uint16Array(maxVertices * 3);
  8201. var geo = new THREE.BufferGeometry();
  8202. var vertexBuffer = _this.vertexBuffer = new THREE.InterleavedBuffer(vertices, MeshBatcher.VERTEX_SIZE);
  8203. vertexBuffer.usage = WebGLRenderingContext.DYNAMIC_DRAW;
  8204. geo.setAttribute("position", new THREE.InterleavedBufferAttribute(vertexBuffer, 3, 0, false));
  8205. geo.setAttribute("color", new THREE.InterleavedBufferAttribute(vertexBuffer, 4, 3, false));
  8206. geo.setAttribute("uv", new THREE.InterleavedBufferAttribute(vertexBuffer, 2, 7, false));
  8207. geo.setIndex(new THREE.BufferAttribute(indices, 1));
  8208. geo.getIndex().usage = WebGLRenderingContext.DYNAMIC_DRAW;
  8209. ;
  8210. geo.drawRange.start = 0;
  8211. geo.drawRange.count = 0;
  8212. _this.geometry = geo;
  8213. _this.material = new threejs.SkeletonMeshMaterial(materialCustomizer);
  8214. return _this;
  8215. }
  8216. MeshBatcher.prototype.dispose = function () {
  8217. this.geometry.dispose();
  8218. if (this.material instanceof THREE.Material)
  8219. this.material.dispose();
  8220. else if (this.material) {
  8221. for (var i = 0; i < this.material.length; i++) {
  8222. var material = this.material[i];
  8223. if (material instanceof THREE.Material)
  8224. material.dispose();
  8225. }
  8226. }
  8227. };
  8228. MeshBatcher.prototype.clear = function () {
  8229. var geo = this.geometry;
  8230. geo.drawRange.start = 0;
  8231. geo.drawRange.count = 0;
  8232. this.material.uniforms.map.value = null;
  8233. };
  8234. MeshBatcher.prototype.begin = function () {
  8235. this.verticesLength = 0;
  8236. this.indicesLength = 0;
  8237. };
  8238. MeshBatcher.prototype.canBatch = function (verticesLength, indicesLength) {
  8239. if (this.indicesLength + indicesLength >= this.indices.byteLength / 2)
  8240. return false;
  8241. if (this.verticesLength + verticesLength >= this.vertices.byteLength / 2)
  8242. return false;
  8243. return true;
  8244. };
  8245. MeshBatcher.prototype.batch = function (vertices, verticesLength, indices, indicesLength, z) {
  8246. if (z === void 0) { z = 0; }
  8247. var indexStart = this.verticesLength / MeshBatcher.VERTEX_SIZE;
  8248. var vertexBuffer = this.vertices;
  8249. var i = this.verticesLength;
  8250. var j = 0;
  8251. for (; j < verticesLength;) {
  8252. vertexBuffer[i++] = vertices[j++];
  8253. vertexBuffer[i++] = vertices[j++];
  8254. vertexBuffer[i++] = z;
  8255. vertexBuffer[i++] = vertices[j++];
  8256. vertexBuffer[i++] = vertices[j++];
  8257. vertexBuffer[i++] = vertices[j++];
  8258. vertexBuffer[i++] = vertices[j++];
  8259. vertexBuffer[i++] = vertices[j++];
  8260. vertexBuffer[i++] = vertices[j++];
  8261. }
  8262. this.verticesLength = i;
  8263. var indicesArray = this.indices;
  8264. for (i = this.indicesLength, j = 0; j < indicesLength; i++, j++)
  8265. indicesArray[i] = indices[j] + indexStart;
  8266. this.indicesLength += indicesLength;
  8267. };
  8268. MeshBatcher.prototype.end = function () {
  8269. this.vertexBuffer.needsUpdate = this.verticesLength > 0;
  8270. this.vertexBuffer.updateRange.offset = 0;
  8271. this.vertexBuffer.updateRange.count = this.verticesLength;
  8272. var geo = this.geometry;
  8273. geo.getIndex().needsUpdate = this.indicesLength > 0;
  8274. geo.getIndex().updateRange.offset = 0;
  8275. geo.getIndex().updateRange.count = this.indicesLength;
  8276. geo.drawRange.start = 0;
  8277. geo.drawRange.count = this.indicesLength;
  8278. };
  8279. MeshBatcher.VERTEX_SIZE = 9;
  8280. return MeshBatcher;
  8281. }(THREE.Mesh));
  8282. threejs.MeshBatcher = MeshBatcher;
  8283. })(threejs = spine.threejs || (spine.threejs = {}));
  8284. })(spine || (spine = {}));
  8285. var spine;
  8286. (function (spine) {
  8287. var threejs;
  8288. (function (threejs) {
  8289. var SkeletonMeshMaterial = (function (_super) {
  8290. __extends(SkeletonMeshMaterial, _super);
  8291. function SkeletonMeshMaterial(customizer) {
  8292. var _this = this;
  8293. var vertexShader = "\n\t\t\t\tattribute vec4 color;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvUv = uv;\n\t\t\t\t\tvColor = color;\n\t\t\t\t\tgl_Position = projectionMatrix*modelViewMatrix*vec4(position,1.0);\n\t\t\t\t}\n\t\t\t";
  8294. var fragmentShader = "\n\t\t\t\tuniform sampler2D map;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main(void) {\n\t\t\t\t\tgl_FragColor = texture2D(map, vUv)*vColor;\n\t\t\t\t}\n\t\t\t";
  8295. var parameters = {
  8296. uniforms: {
  8297. map: { type: "t", value: null }
  8298. },
  8299. vertexShader: vertexShader,
  8300. fragmentShader: fragmentShader,
  8301. side: THREE.DoubleSide,
  8302. transparent: true,
  8303. alphaTest: 0.5
  8304. };
  8305. customizer(parameters);
  8306. _this = _super.call(this, parameters) || this;
  8307. return _this;
  8308. }
  8309. ;
  8310. return SkeletonMeshMaterial;
  8311. }(THREE.ShaderMaterial));
  8312. threejs.SkeletonMeshMaterial = SkeletonMeshMaterial;
  8313. var SkeletonMesh = (function (_super) {
  8314. __extends(SkeletonMesh, _super);
  8315. function SkeletonMesh(skeletonData, materialCustomizer) {
  8316. if (materialCustomizer === void 0) { materialCustomizer = function (parameters) { }; }
  8317. var _this = _super.call(this) || this;
  8318. _this.tempPos = new spine.Vector2();
  8319. _this.tempUv = new spine.Vector2();
  8320. _this.tempLight = new spine.Color();
  8321. _this.tempDark = new spine.Color();
  8322. _this.zOffset = 0.1;
  8323. _this.batches = new Array();
  8324. _this.nextBatchIndex = 0;
  8325. _this.clipper = new spine.SkeletonClipping();
  8326. _this.vertices = spine.Utils.newFloatArray(1024);
  8327. _this.tempColor = new spine.Color();
  8328. _this.materialCustomizer = materialCustomizer;
  8329. _this.skeleton = new spine.Skeleton(skeletonData);
  8330. var animData = new spine.AnimationStateData(skeletonData);
  8331. _this.state = new spine.AnimationState(animData);
  8332. return _this;
  8333. }
  8334. SkeletonMesh.prototype.update = function (deltaTime) {
  8335. var state = this.state;
  8336. var skeleton = this.skeleton;
  8337. state.update(deltaTime);
  8338. state.apply(skeleton);
  8339. skeleton.updateWorldTransform();
  8340. this.updateGeometry();
  8341. };
  8342. SkeletonMesh.prototype.dispose = function () {
  8343. for (var i = 0; i < this.batches.length; i++) {
  8344. this.batches[i].dispose();
  8345. }
  8346. };
  8347. SkeletonMesh.prototype.clearBatches = function () {
  8348. for (var i = 0; i < this.batches.length; i++) {
  8349. this.batches[i].clear();
  8350. this.batches[i].visible = false;
  8351. }
  8352. this.nextBatchIndex = 0;
  8353. };
  8354. SkeletonMesh.prototype.nextBatch = function () {
  8355. if (this.batches.length == this.nextBatchIndex) {
  8356. var batch_1 = new threejs.MeshBatcher(10920, this.materialCustomizer);
  8357. this.add(batch_1);
  8358. this.batches.push(batch_1);
  8359. }
  8360. var batch = this.batches[this.nextBatchIndex++];
  8361. batch.visible = true;
  8362. return batch;
  8363. };
  8364. SkeletonMesh.prototype.updateGeometry = function () {
  8365. this.clearBatches();
  8366. var tempPos = this.tempPos;
  8367. var tempUv = this.tempUv;
  8368. var tempLight = this.tempLight;
  8369. var tempDark = this.tempDark;
  8370. var numVertices = 0;
  8371. var verticesLength = 0;
  8372. var indicesLength = 0;
  8373. var blendMode = null;
  8374. var clipper = this.clipper;
  8375. var vertices = this.vertices;
  8376. var triangles = null;
  8377. var uvs = null;
  8378. var drawOrder = this.skeleton.drawOrder;
  8379. var batch = this.nextBatch();
  8380. batch.begin();
  8381. var z = 0;
  8382. var zOffset = this.zOffset;
  8383. for (var i = 0, n = drawOrder.length; i < n; i++) {
  8384. var vertexSize = clipper.isClipping() ? 2 : SkeletonMesh.VERTEX_SIZE;
  8385. var slot = drawOrder[i];
  8386. if (!slot.bone.active)
  8387. continue;
  8388. var attachment = slot.getAttachment();
  8389. var attachmentColor = null;
  8390. var texture = null;
  8391. var numFloats = 0;
  8392. if (attachment instanceof spine.RegionAttachment) {
  8393. var region = attachment;
  8394. attachmentColor = region.color;
  8395. vertices = this.vertices;
  8396. numFloats = vertexSize * 4;
  8397. region.computeWorldVertices(slot.bone, vertices, 0, vertexSize);
  8398. triangles = SkeletonMesh.QUAD_TRIANGLES;
  8399. uvs = region.uvs;
  8400. texture = region.region.renderObject.texture;
  8401. }
  8402. else if (attachment instanceof spine.MeshAttachment) {
  8403. var mesh = attachment;
  8404. attachmentColor = mesh.color;
  8405. vertices = this.vertices;
  8406. numFloats = (mesh.worldVerticesLength >> 1) * vertexSize;
  8407. if (numFloats > vertices.length) {
  8408. vertices = this.vertices = spine.Utils.newFloatArray(numFloats);
  8409. }
  8410. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, vertexSize);
  8411. triangles = mesh.triangles;
  8412. uvs = mesh.uvs;
  8413. texture = mesh.region.renderObject.texture;
  8414. }
  8415. else if (attachment instanceof spine.ClippingAttachment) {
  8416. var clip = (attachment);
  8417. clipper.clipStart(slot, clip);
  8418. continue;
  8419. }
  8420. else
  8421. continue;
  8422. if (texture != null) {
  8423. var skeleton = slot.bone.skeleton;
  8424. var skeletonColor = skeleton.color;
  8425. var slotColor = slot.color;
  8426. var alpha = skeletonColor.a * slotColor.a * attachmentColor.a;
  8427. var color = this.tempColor;
  8428. color.set(skeletonColor.r * slotColor.r * attachmentColor.r, skeletonColor.g * slotColor.g * attachmentColor.g, skeletonColor.b * slotColor.b * attachmentColor.b, alpha);
  8429. var finalVertices = void 0;
  8430. var finalVerticesLength = void 0;
  8431. var finalIndices = void 0;
  8432. var finalIndicesLength = void 0;
  8433. if (clipper.isClipping()) {
  8434. clipper.clipTriangles(vertices, numFloats, triangles, triangles.length, uvs, color, null, false);
  8435. var clippedVertices = clipper.clippedVertices;
  8436. var clippedTriangles = clipper.clippedTriangles;
  8437. if (this.vertexEffect != null) {
  8438. var vertexEffect = this.vertexEffect;
  8439. var verts = clippedVertices;
  8440. for (var v = 0, n_3 = clippedVertices.length; v < n_3; v += vertexSize) {
  8441. tempPos.x = verts[v];
  8442. tempPos.y = verts[v + 1];
  8443. tempLight.setFromColor(color);
  8444. tempDark.set(0, 0, 0, 0);
  8445. tempUv.x = verts[v + 6];
  8446. tempUv.y = verts[v + 7];
  8447. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  8448. verts[v] = tempPos.x;
  8449. verts[v + 1] = tempPos.y;
  8450. verts[v + 2] = tempLight.r;
  8451. verts[v + 3] = tempLight.g;
  8452. verts[v + 4] = tempLight.b;
  8453. verts[v + 5] = tempLight.a;
  8454. verts[v + 6] = tempUv.x;
  8455. verts[v + 7] = tempUv.y;
  8456. }
  8457. }
  8458. finalVertices = clippedVertices;
  8459. finalVerticesLength = clippedVertices.length;
  8460. finalIndices = clippedTriangles;
  8461. finalIndicesLength = clippedTriangles.length;
  8462. }
  8463. else {
  8464. var verts = vertices;
  8465. if (this.vertexEffect != null) {
  8466. var vertexEffect = this.vertexEffect;
  8467. for (var v = 0, u = 0, n_4 = numFloats; v < n_4; v += vertexSize, u += 2) {
  8468. tempPos.x = verts[v];
  8469. tempPos.y = verts[v + 1];
  8470. tempLight.setFromColor(color);
  8471. tempDark.set(0, 0, 0, 0);
  8472. tempUv.x = uvs[u];
  8473. tempUv.y = uvs[u + 1];
  8474. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  8475. verts[v] = tempPos.x;
  8476. verts[v + 1] = tempPos.y;
  8477. verts[v + 2] = tempLight.r;
  8478. verts[v + 3] = tempLight.g;
  8479. verts[v + 4] = tempLight.b;
  8480. verts[v + 5] = tempLight.a;
  8481. verts[v + 6] = tempUv.x;
  8482. verts[v + 7] = tempUv.y;
  8483. }
  8484. }
  8485. else {
  8486. for (var v = 2, u = 0, n_5 = numFloats; v < n_5; v += vertexSize, u += 2) {
  8487. verts[v] = color.r;
  8488. verts[v + 1] = color.g;
  8489. verts[v + 2] = color.b;
  8490. verts[v + 3] = color.a;
  8491. verts[v + 4] = uvs[u];
  8492. verts[v + 5] = uvs[u + 1];
  8493. }
  8494. }
  8495. finalVertices = vertices;
  8496. finalVerticesLength = numFloats;
  8497. finalIndices = triangles;
  8498. finalIndicesLength = triangles.length;
  8499. }
  8500. if (finalVerticesLength == 0 || finalIndicesLength == 0)
  8501. continue;
  8502. if (!batch.canBatch(finalVerticesLength, finalIndicesLength)) {
  8503. batch.end();
  8504. batch = this.nextBatch();
  8505. batch.begin();
  8506. }
  8507. var batchMaterial = batch.material;
  8508. if (batchMaterial.uniforms.map.value == null) {
  8509. batchMaterial.uniforms.map.value = texture.texture;
  8510. }
  8511. if (batchMaterial.uniforms.map.value != texture.texture) {
  8512. batch.end();
  8513. batch = this.nextBatch();
  8514. batch.begin();
  8515. batchMaterial = batch.material;
  8516. batchMaterial.uniforms.map.value = texture.texture;
  8517. }
  8518. batchMaterial.needsUpdate = true;
  8519. batch.batch(finalVertices, finalVerticesLength, finalIndices, finalIndicesLength, z);
  8520. z += zOffset;
  8521. }
  8522. clipper.clipEndWithSlot(slot);
  8523. }
  8524. clipper.clipEnd();
  8525. batch.end();
  8526. };
  8527. SkeletonMesh.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  8528. SkeletonMesh.VERTEX_SIZE = 2 + 2 + 4;
  8529. return SkeletonMesh;
  8530. }(THREE.Object3D));
  8531. threejs.SkeletonMesh = SkeletonMesh;
  8532. })(threejs = spine.threejs || (spine.threejs = {}));
  8533. })(spine || (spine = {}));
  8534. var spine;
  8535. (function (spine) {
  8536. var threejs;
  8537. (function (threejs) {
  8538. var ThreeJsTexture = (function (_super) {
  8539. __extends(ThreeJsTexture, _super);
  8540. function ThreeJsTexture(image) {
  8541. var _this = _super.call(this, image) || this;
  8542. _this.texture = new THREE.Texture(image);
  8543. _this.texture.flipY = false;
  8544. _this.texture.needsUpdate = true;
  8545. return _this;
  8546. }
  8547. ThreeJsTexture.prototype.setFilters = function (minFilter, magFilter) {
  8548. this.texture.minFilter = ThreeJsTexture.toThreeJsTextureFilter(minFilter);
  8549. this.texture.magFilter = ThreeJsTexture.toThreeJsTextureFilter(magFilter);
  8550. };
  8551. ThreeJsTexture.prototype.setWraps = function (uWrap, vWrap) {
  8552. this.texture.wrapS = ThreeJsTexture.toThreeJsTextureWrap(uWrap);
  8553. this.texture.wrapT = ThreeJsTexture.toThreeJsTextureWrap(vWrap);
  8554. };
  8555. ThreeJsTexture.prototype.dispose = function () {
  8556. this.texture.dispose();
  8557. };
  8558. ThreeJsTexture.toThreeJsTextureFilter = function (filter) {
  8559. if (filter === spine.TextureFilter.Linear)
  8560. return THREE.LinearFilter;
  8561. else if (filter === spine.TextureFilter.MipMap)
  8562. return THREE.LinearMipMapLinearFilter;
  8563. else if (filter === spine.TextureFilter.MipMapLinearNearest)
  8564. return THREE.LinearMipMapNearestFilter;
  8565. else if (filter === spine.TextureFilter.MipMapNearestLinear)
  8566. return THREE.NearestMipMapLinearFilter;
  8567. else if (filter === spine.TextureFilter.MipMapNearestNearest)
  8568. return THREE.NearestMipMapNearestFilter;
  8569. else if (filter === spine.TextureFilter.Nearest)
  8570. return THREE.NearestFilter;
  8571. else
  8572. throw new Error("Unknown texture filter: " + filter);
  8573. };
  8574. ThreeJsTexture.toThreeJsTextureWrap = function (wrap) {
  8575. if (wrap === spine.TextureWrap.ClampToEdge)
  8576. return THREE.ClampToEdgeWrapping;
  8577. else if (wrap === spine.TextureWrap.MirroredRepeat)
  8578. return THREE.MirroredRepeatWrapping;
  8579. else if (wrap === spine.TextureWrap.Repeat)
  8580. return THREE.RepeatWrapping;
  8581. else
  8582. throw new Error("Unknown texture wrap: " + wrap);
  8583. };
  8584. return ThreeJsTexture;
  8585. }(spine.Texture));
  8586. threejs.ThreeJsTexture = ThreeJsTexture;
  8587. })(threejs = spine.threejs || (spine.threejs = {}));
  8588. })(spine || (spine = {}));
  8589. //# sourceMappingURL=spine-threejs.js.map