spine-webgl.js 335 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. var spine;
  12. (function (spine) {
  13. var Animation = (function () {
  14. function Animation(name, timelines, duration) {
  15. if (name == null)
  16. throw new Error("name cannot be null.");
  17. if (timelines == null)
  18. throw new Error("timelines cannot be null.");
  19. this.name = name;
  20. this.timelines = timelines;
  21. this.duration = duration;
  22. }
  23. Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
  24. if (skeleton == null)
  25. throw new Error("skeleton cannot be null.");
  26. if (loop && this.duration != 0) {
  27. time %= this.duration;
  28. if (lastTime > 0)
  29. lastTime %= this.duration;
  30. }
  31. var timelines = this.timelines;
  32. for (var i = 0, n = timelines.length; i < n; i++)
  33. timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
  34. };
  35. Animation.binarySearch = function (values, target, step) {
  36. if (step === void 0) { step = 1; }
  37. var low = 0;
  38. var high = values.length / step - 2;
  39. if (high == 0)
  40. return step;
  41. var current = high >>> 1;
  42. while (true) {
  43. if (values[(current + 1) * step] <= target)
  44. low = current + 1;
  45. else
  46. high = current;
  47. if (low == high)
  48. return (low + 1) * step;
  49. current = (low + high) >>> 1;
  50. }
  51. };
  52. Animation.linearSearch = function (values, target, step) {
  53. for (var i = 0, last = values.length - step; i <= last; i += step)
  54. if (values[i] > target)
  55. return i;
  56. return -1;
  57. };
  58. return Animation;
  59. }());
  60. spine.Animation = Animation;
  61. var MixPose;
  62. (function (MixPose) {
  63. MixPose[MixPose["setup"] = 0] = "setup";
  64. MixPose[MixPose["current"] = 1] = "current";
  65. MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
  66. })(MixPose = spine.MixPose || (spine.MixPose = {}));
  67. var MixDirection;
  68. (function (MixDirection) {
  69. MixDirection[MixDirection["in"] = 0] = "in";
  70. MixDirection[MixDirection["out"] = 1] = "out";
  71. })(MixDirection = spine.MixDirection || (spine.MixDirection = {}));
  72. var TimelineType;
  73. (function (TimelineType) {
  74. TimelineType[TimelineType["rotate"] = 0] = "rotate";
  75. TimelineType[TimelineType["translate"] = 1] = "translate";
  76. TimelineType[TimelineType["scale"] = 2] = "scale";
  77. TimelineType[TimelineType["shear"] = 3] = "shear";
  78. TimelineType[TimelineType["attachment"] = 4] = "attachment";
  79. TimelineType[TimelineType["color"] = 5] = "color";
  80. TimelineType[TimelineType["deform"] = 6] = "deform";
  81. TimelineType[TimelineType["event"] = 7] = "event";
  82. TimelineType[TimelineType["drawOrder"] = 8] = "drawOrder";
  83. TimelineType[TimelineType["ikConstraint"] = 9] = "ikConstraint";
  84. TimelineType[TimelineType["transformConstraint"] = 10] = "transformConstraint";
  85. TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition";
  86. TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing";
  87. TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix";
  88. TimelineType[TimelineType["twoColor"] = 14] = "twoColor";
  89. })(TimelineType = spine.TimelineType || (spine.TimelineType = {}));
  90. var CurveTimeline = (function () {
  91. function CurveTimeline(frameCount) {
  92. if (frameCount <= 0)
  93. throw new Error("frameCount must be > 0: " + frameCount);
  94. this.curves = spine.Utils.newFloatArray((frameCount - 1) * CurveTimeline.BEZIER_SIZE);
  95. }
  96. CurveTimeline.prototype.getFrameCount = function () {
  97. return this.curves.length / CurveTimeline.BEZIER_SIZE + 1;
  98. };
  99. CurveTimeline.prototype.setLinear = function (frameIndex) {
  100. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.LINEAR;
  101. };
  102. CurveTimeline.prototype.setStepped = function (frameIndex) {
  103. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.STEPPED;
  104. };
  105. CurveTimeline.prototype.getCurveType = function (frameIndex) {
  106. var index = frameIndex * CurveTimeline.BEZIER_SIZE;
  107. if (index == this.curves.length)
  108. return CurveTimeline.LINEAR;
  109. var type = this.curves[index];
  110. if (type == CurveTimeline.LINEAR)
  111. return CurveTimeline.LINEAR;
  112. if (type == CurveTimeline.STEPPED)
  113. return CurveTimeline.STEPPED;
  114. return CurveTimeline.BEZIER;
  115. };
  116. CurveTimeline.prototype.setCurve = function (frameIndex, cx1, cy1, cx2, cy2) {
  117. var tmpx = (-cx1 * 2 + cx2) * 0.03, tmpy = (-cy1 * 2 + cy2) * 0.03;
  118. var dddfx = ((cx1 - cx2) * 3 + 1) * 0.006, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006;
  119. var ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
  120. var dfx = cx1 * 0.3 + tmpx + dddfx * 0.16666667, dfy = cy1 * 0.3 + tmpy + dddfy * 0.16666667;
  121. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  122. var curves = this.curves;
  123. curves[i++] = CurveTimeline.BEZIER;
  124. var x = dfx, y = dfy;
  125. for (var n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  126. curves[i] = x;
  127. curves[i + 1] = y;
  128. dfx += ddfx;
  129. dfy += ddfy;
  130. ddfx += dddfx;
  131. ddfy += dddfy;
  132. x += dfx;
  133. y += dfy;
  134. }
  135. };
  136. CurveTimeline.prototype.getCurvePercent = function (frameIndex, percent) {
  137. percent = spine.MathUtils.clamp(percent, 0, 1);
  138. var curves = this.curves;
  139. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  140. var type = curves[i];
  141. if (type == CurveTimeline.LINEAR)
  142. return percent;
  143. if (type == CurveTimeline.STEPPED)
  144. return 0;
  145. i++;
  146. var x = 0;
  147. for (var start = i, n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  148. x = curves[i];
  149. if (x >= percent) {
  150. var prevX = void 0, prevY = void 0;
  151. if (i == start) {
  152. prevX = 0;
  153. prevY = 0;
  154. }
  155. else {
  156. prevX = curves[i - 2];
  157. prevY = curves[i - 1];
  158. }
  159. return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
  160. }
  161. }
  162. var y = curves[i - 1];
  163. return y + (1 - y) * (percent - x) / (1 - x);
  164. };
  165. CurveTimeline.LINEAR = 0;
  166. CurveTimeline.STEPPED = 1;
  167. CurveTimeline.BEZIER = 2;
  168. CurveTimeline.BEZIER_SIZE = 10 * 2 - 1;
  169. return CurveTimeline;
  170. }());
  171. spine.CurveTimeline = CurveTimeline;
  172. var RotateTimeline = (function (_super) {
  173. __extends(RotateTimeline, _super);
  174. function RotateTimeline(frameCount) {
  175. var _this = _super.call(this, frameCount) || this;
  176. _this.frames = spine.Utils.newFloatArray(frameCount << 1);
  177. return _this;
  178. }
  179. RotateTimeline.prototype.getPropertyId = function () {
  180. return (TimelineType.rotate << 24) + this.boneIndex;
  181. };
  182. RotateTimeline.prototype.setFrame = function (frameIndex, time, degrees) {
  183. frameIndex <<= 1;
  184. this.frames[frameIndex] = time;
  185. this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
  186. };
  187. RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  188. var frames = this.frames;
  189. var bone = skeleton.bones[this.boneIndex];
  190. if (time < frames[0]) {
  191. switch (pose) {
  192. case MixPose.setup:
  193. bone.rotation = bone.data.rotation;
  194. return;
  195. case MixPose.current:
  196. var r_1 = bone.data.rotation - bone.rotation;
  197. r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
  198. bone.rotation += r_1 * alpha;
  199. }
  200. return;
  201. }
  202. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
  203. if (pose == MixPose.setup)
  204. bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
  205. else {
  206. var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
  207. r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
  208. bone.rotation += r_2 * alpha;
  209. }
  210. return;
  211. }
  212. var frame = Animation.binarySearch(frames, time, RotateTimeline.ENTRIES);
  213. var prevRotation = frames[frame + RotateTimeline.PREV_ROTATION];
  214. var frameTime = frames[frame];
  215. var percent = this.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
  216. var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
  217. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  218. r = prevRotation + r * percent;
  219. if (pose == MixPose.setup) {
  220. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  221. bone.rotation = bone.data.rotation + r * alpha;
  222. }
  223. else {
  224. r = bone.data.rotation + r - bone.rotation;
  225. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  226. bone.rotation += r * alpha;
  227. }
  228. };
  229. RotateTimeline.ENTRIES = 2;
  230. RotateTimeline.PREV_TIME = -2;
  231. RotateTimeline.PREV_ROTATION = -1;
  232. RotateTimeline.ROTATION = 1;
  233. return RotateTimeline;
  234. }(CurveTimeline));
  235. spine.RotateTimeline = RotateTimeline;
  236. var TranslateTimeline = (function (_super) {
  237. __extends(TranslateTimeline, _super);
  238. function TranslateTimeline(frameCount) {
  239. var _this = _super.call(this, frameCount) || this;
  240. _this.frames = spine.Utils.newFloatArray(frameCount * TranslateTimeline.ENTRIES);
  241. return _this;
  242. }
  243. TranslateTimeline.prototype.getPropertyId = function () {
  244. return (TimelineType.translate << 24) + this.boneIndex;
  245. };
  246. TranslateTimeline.prototype.setFrame = function (frameIndex, time, x, y) {
  247. frameIndex *= TranslateTimeline.ENTRIES;
  248. this.frames[frameIndex] = time;
  249. this.frames[frameIndex + TranslateTimeline.X] = x;
  250. this.frames[frameIndex + TranslateTimeline.Y] = y;
  251. };
  252. TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  253. var frames = this.frames;
  254. var bone = skeleton.bones[this.boneIndex];
  255. if (time < frames[0]) {
  256. switch (pose) {
  257. case MixPose.setup:
  258. bone.x = bone.data.x;
  259. bone.y = bone.data.y;
  260. return;
  261. case MixPose.current:
  262. bone.x += (bone.data.x - bone.x) * alpha;
  263. bone.y += (bone.data.y - bone.y) * alpha;
  264. }
  265. return;
  266. }
  267. var x = 0, y = 0;
  268. if (time >= frames[frames.length - TranslateTimeline.ENTRIES]) {
  269. x = frames[frames.length + TranslateTimeline.PREV_X];
  270. y = frames[frames.length + TranslateTimeline.PREV_Y];
  271. }
  272. else {
  273. var frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
  274. x = frames[frame + TranslateTimeline.PREV_X];
  275. y = frames[frame + TranslateTimeline.PREV_Y];
  276. var frameTime = frames[frame];
  277. var percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
  278. x += (frames[frame + TranslateTimeline.X] - x) * percent;
  279. y += (frames[frame + TranslateTimeline.Y] - y) * percent;
  280. }
  281. if (pose == MixPose.setup) {
  282. bone.x = bone.data.x + x * alpha;
  283. bone.y = bone.data.y + y * alpha;
  284. }
  285. else {
  286. bone.x += (bone.data.x + x - bone.x) * alpha;
  287. bone.y += (bone.data.y + y - bone.y) * alpha;
  288. }
  289. };
  290. TranslateTimeline.ENTRIES = 3;
  291. TranslateTimeline.PREV_TIME = -3;
  292. TranslateTimeline.PREV_X = -2;
  293. TranslateTimeline.PREV_Y = -1;
  294. TranslateTimeline.X = 1;
  295. TranslateTimeline.Y = 2;
  296. return TranslateTimeline;
  297. }(CurveTimeline));
  298. spine.TranslateTimeline = TranslateTimeline;
  299. var ScaleTimeline = (function (_super) {
  300. __extends(ScaleTimeline, _super);
  301. function ScaleTimeline(frameCount) {
  302. return _super.call(this, frameCount) || this;
  303. }
  304. ScaleTimeline.prototype.getPropertyId = function () {
  305. return (TimelineType.scale << 24) + this.boneIndex;
  306. };
  307. ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  308. var frames = this.frames;
  309. var bone = skeleton.bones[this.boneIndex];
  310. if (time < frames[0]) {
  311. switch (pose) {
  312. case MixPose.setup:
  313. bone.scaleX = bone.data.scaleX;
  314. bone.scaleY = bone.data.scaleY;
  315. return;
  316. case MixPose.current:
  317. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  318. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  319. }
  320. return;
  321. }
  322. var x = 0, y = 0;
  323. if (time >= frames[frames.length - ScaleTimeline.ENTRIES]) {
  324. x = frames[frames.length + ScaleTimeline.PREV_X] * bone.data.scaleX;
  325. y = frames[frames.length + ScaleTimeline.PREV_Y] * bone.data.scaleY;
  326. }
  327. else {
  328. var frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
  329. x = frames[frame + ScaleTimeline.PREV_X];
  330. y = frames[frame + ScaleTimeline.PREV_Y];
  331. var frameTime = frames[frame];
  332. var percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
  333. x = (x + (frames[frame + ScaleTimeline.X] - x) * percent) * bone.data.scaleX;
  334. y = (y + (frames[frame + ScaleTimeline.Y] - y) * percent) * bone.data.scaleY;
  335. }
  336. if (alpha == 1) {
  337. bone.scaleX = x;
  338. bone.scaleY = y;
  339. }
  340. else {
  341. var bx = 0, by = 0;
  342. if (pose == MixPose.setup) {
  343. bx = bone.data.scaleX;
  344. by = bone.data.scaleY;
  345. }
  346. else {
  347. bx = bone.scaleX;
  348. by = bone.scaleY;
  349. }
  350. if (direction == MixDirection.out) {
  351. x = Math.abs(x) * spine.MathUtils.signum(bx);
  352. y = Math.abs(y) * spine.MathUtils.signum(by);
  353. }
  354. else {
  355. bx = Math.abs(bx) * spine.MathUtils.signum(x);
  356. by = Math.abs(by) * spine.MathUtils.signum(y);
  357. }
  358. bone.scaleX = bx + (x - bx) * alpha;
  359. bone.scaleY = by + (y - by) * alpha;
  360. }
  361. };
  362. return ScaleTimeline;
  363. }(TranslateTimeline));
  364. spine.ScaleTimeline = ScaleTimeline;
  365. var ShearTimeline = (function (_super) {
  366. __extends(ShearTimeline, _super);
  367. function ShearTimeline(frameCount) {
  368. return _super.call(this, frameCount) || this;
  369. }
  370. ShearTimeline.prototype.getPropertyId = function () {
  371. return (TimelineType.shear << 24) + this.boneIndex;
  372. };
  373. ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  374. var frames = this.frames;
  375. var bone = skeleton.bones[this.boneIndex];
  376. if (time < frames[0]) {
  377. switch (pose) {
  378. case MixPose.setup:
  379. bone.shearX = bone.data.shearX;
  380. bone.shearY = bone.data.shearY;
  381. return;
  382. case MixPose.current:
  383. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  384. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  385. }
  386. return;
  387. }
  388. var x = 0, y = 0;
  389. if (time >= frames[frames.length - ShearTimeline.ENTRIES]) {
  390. x = frames[frames.length + ShearTimeline.PREV_X];
  391. y = frames[frames.length + ShearTimeline.PREV_Y];
  392. }
  393. else {
  394. var frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
  395. x = frames[frame + ShearTimeline.PREV_X];
  396. y = frames[frame + ShearTimeline.PREV_Y];
  397. var frameTime = frames[frame];
  398. var percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
  399. x = x + (frames[frame + ShearTimeline.X] - x) * percent;
  400. y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
  401. }
  402. if (pose == MixPose.setup) {
  403. bone.shearX = bone.data.shearX + x * alpha;
  404. bone.shearY = bone.data.shearY + y * alpha;
  405. }
  406. else {
  407. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  408. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  409. }
  410. };
  411. return ShearTimeline;
  412. }(TranslateTimeline));
  413. spine.ShearTimeline = ShearTimeline;
  414. var ColorTimeline = (function (_super) {
  415. __extends(ColorTimeline, _super);
  416. function ColorTimeline(frameCount) {
  417. var _this = _super.call(this, frameCount) || this;
  418. _this.frames = spine.Utils.newFloatArray(frameCount * ColorTimeline.ENTRIES);
  419. return _this;
  420. }
  421. ColorTimeline.prototype.getPropertyId = function () {
  422. return (TimelineType.color << 24) + this.slotIndex;
  423. };
  424. ColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a) {
  425. frameIndex *= ColorTimeline.ENTRIES;
  426. this.frames[frameIndex] = time;
  427. this.frames[frameIndex + ColorTimeline.R] = r;
  428. this.frames[frameIndex + ColorTimeline.G] = g;
  429. this.frames[frameIndex + ColorTimeline.B] = b;
  430. this.frames[frameIndex + ColorTimeline.A] = a;
  431. };
  432. ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  433. var slot = skeleton.slots[this.slotIndex];
  434. var frames = this.frames;
  435. if (time < frames[0]) {
  436. switch (pose) {
  437. case MixPose.setup:
  438. slot.color.setFromColor(slot.data.color);
  439. return;
  440. case MixPose.current:
  441. var color = slot.color, setup = slot.data.color;
  442. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
  443. }
  444. return;
  445. }
  446. var r = 0, g = 0, b = 0, a = 0;
  447. if (time >= frames[frames.length - ColorTimeline.ENTRIES]) {
  448. var i = frames.length;
  449. r = frames[i + ColorTimeline.PREV_R];
  450. g = frames[i + ColorTimeline.PREV_G];
  451. b = frames[i + ColorTimeline.PREV_B];
  452. a = frames[i + ColorTimeline.PREV_A];
  453. }
  454. else {
  455. var frame = Animation.binarySearch(frames, time, ColorTimeline.ENTRIES);
  456. r = frames[frame + ColorTimeline.PREV_R];
  457. g = frames[frame + ColorTimeline.PREV_G];
  458. b = frames[frame + ColorTimeline.PREV_B];
  459. a = frames[frame + ColorTimeline.PREV_A];
  460. var frameTime = frames[frame];
  461. var percent = this.getCurvePercent(frame / ColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ColorTimeline.PREV_TIME] - frameTime));
  462. r += (frames[frame + ColorTimeline.R] - r) * percent;
  463. g += (frames[frame + ColorTimeline.G] - g) * percent;
  464. b += (frames[frame + ColorTimeline.B] - b) * percent;
  465. a += (frames[frame + ColorTimeline.A] - a) * percent;
  466. }
  467. if (alpha == 1)
  468. slot.color.set(r, g, b, a);
  469. else {
  470. var color = slot.color;
  471. if (pose == MixPose.setup)
  472. color.setFromColor(slot.data.color);
  473. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  474. }
  475. };
  476. ColorTimeline.ENTRIES = 5;
  477. ColorTimeline.PREV_TIME = -5;
  478. ColorTimeline.PREV_R = -4;
  479. ColorTimeline.PREV_G = -3;
  480. ColorTimeline.PREV_B = -2;
  481. ColorTimeline.PREV_A = -1;
  482. ColorTimeline.R = 1;
  483. ColorTimeline.G = 2;
  484. ColorTimeline.B = 3;
  485. ColorTimeline.A = 4;
  486. return ColorTimeline;
  487. }(CurveTimeline));
  488. spine.ColorTimeline = ColorTimeline;
  489. var TwoColorTimeline = (function (_super) {
  490. __extends(TwoColorTimeline, _super);
  491. function TwoColorTimeline(frameCount) {
  492. var _this = _super.call(this, frameCount) || this;
  493. _this.frames = spine.Utils.newFloatArray(frameCount * TwoColorTimeline.ENTRIES);
  494. return _this;
  495. }
  496. TwoColorTimeline.prototype.getPropertyId = function () {
  497. return (TimelineType.twoColor << 24) + this.slotIndex;
  498. };
  499. TwoColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a, r2, g2, b2) {
  500. frameIndex *= TwoColorTimeline.ENTRIES;
  501. this.frames[frameIndex] = time;
  502. this.frames[frameIndex + TwoColorTimeline.R] = r;
  503. this.frames[frameIndex + TwoColorTimeline.G] = g;
  504. this.frames[frameIndex + TwoColorTimeline.B] = b;
  505. this.frames[frameIndex + TwoColorTimeline.A] = a;
  506. this.frames[frameIndex + TwoColorTimeline.R2] = r2;
  507. this.frames[frameIndex + TwoColorTimeline.G2] = g2;
  508. this.frames[frameIndex + TwoColorTimeline.B2] = b2;
  509. };
  510. TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  511. var slot = skeleton.slots[this.slotIndex];
  512. var frames = this.frames;
  513. if (time < frames[0]) {
  514. switch (pose) {
  515. case MixPose.setup:
  516. slot.color.setFromColor(slot.data.color);
  517. slot.darkColor.setFromColor(slot.data.darkColor);
  518. return;
  519. case MixPose.current:
  520. var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  521. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
  522. dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
  523. }
  524. return;
  525. }
  526. var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  527. if (time >= frames[frames.length - TwoColorTimeline.ENTRIES]) {
  528. var i = frames.length;
  529. r = frames[i + TwoColorTimeline.PREV_R];
  530. g = frames[i + TwoColorTimeline.PREV_G];
  531. b = frames[i + TwoColorTimeline.PREV_B];
  532. a = frames[i + TwoColorTimeline.PREV_A];
  533. r2 = frames[i + TwoColorTimeline.PREV_R2];
  534. g2 = frames[i + TwoColorTimeline.PREV_G2];
  535. b2 = frames[i + TwoColorTimeline.PREV_B2];
  536. }
  537. else {
  538. var frame = Animation.binarySearch(frames, time, TwoColorTimeline.ENTRIES);
  539. r = frames[frame + TwoColorTimeline.PREV_R];
  540. g = frames[frame + TwoColorTimeline.PREV_G];
  541. b = frames[frame + TwoColorTimeline.PREV_B];
  542. a = frames[frame + TwoColorTimeline.PREV_A];
  543. r2 = frames[frame + TwoColorTimeline.PREV_R2];
  544. g2 = frames[frame + TwoColorTimeline.PREV_G2];
  545. b2 = frames[frame + TwoColorTimeline.PREV_B2];
  546. var frameTime = frames[frame];
  547. var percent = this.getCurvePercent(frame / TwoColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TwoColorTimeline.PREV_TIME] - frameTime));
  548. r += (frames[frame + TwoColorTimeline.R] - r) * percent;
  549. g += (frames[frame + TwoColorTimeline.G] - g) * percent;
  550. b += (frames[frame + TwoColorTimeline.B] - b) * percent;
  551. a += (frames[frame + TwoColorTimeline.A] - a) * percent;
  552. r2 += (frames[frame + TwoColorTimeline.R2] - r2) * percent;
  553. g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
  554. b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
  555. }
  556. if (alpha == 1) {
  557. slot.color.set(r, g, b, a);
  558. slot.darkColor.set(r2, g2, b2, 1);
  559. }
  560. else {
  561. var light = slot.color, dark = slot.darkColor;
  562. if (pose == MixPose.setup) {
  563. light.setFromColor(slot.data.color);
  564. dark.setFromColor(slot.data.darkColor);
  565. }
  566. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  567. dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
  568. }
  569. };
  570. TwoColorTimeline.ENTRIES = 8;
  571. TwoColorTimeline.PREV_TIME = -8;
  572. TwoColorTimeline.PREV_R = -7;
  573. TwoColorTimeline.PREV_G = -6;
  574. TwoColorTimeline.PREV_B = -5;
  575. TwoColorTimeline.PREV_A = -4;
  576. TwoColorTimeline.PREV_R2 = -3;
  577. TwoColorTimeline.PREV_G2 = -2;
  578. TwoColorTimeline.PREV_B2 = -1;
  579. TwoColorTimeline.R = 1;
  580. TwoColorTimeline.G = 2;
  581. TwoColorTimeline.B = 3;
  582. TwoColorTimeline.A = 4;
  583. TwoColorTimeline.R2 = 5;
  584. TwoColorTimeline.G2 = 6;
  585. TwoColorTimeline.B2 = 7;
  586. return TwoColorTimeline;
  587. }(CurveTimeline));
  588. spine.TwoColorTimeline = TwoColorTimeline;
  589. var AttachmentTimeline = (function () {
  590. function AttachmentTimeline(frameCount) {
  591. this.frames = spine.Utils.newFloatArray(frameCount);
  592. this.attachmentNames = new Array(frameCount);
  593. }
  594. AttachmentTimeline.prototype.getPropertyId = function () {
  595. return (TimelineType.attachment << 24) + this.slotIndex;
  596. };
  597. AttachmentTimeline.prototype.getFrameCount = function () {
  598. return this.frames.length;
  599. };
  600. AttachmentTimeline.prototype.setFrame = function (frameIndex, time, attachmentName) {
  601. this.frames[frameIndex] = time;
  602. this.attachmentNames[frameIndex] = attachmentName;
  603. };
  604. AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  605. var slot = skeleton.slots[this.slotIndex];
  606. if (direction == MixDirection.out && pose == MixPose.setup) {
  607. var attachmentName_1 = slot.data.attachmentName;
  608. slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
  609. return;
  610. }
  611. var frames = this.frames;
  612. if (time < frames[0]) {
  613. if (pose == MixPose.setup) {
  614. var attachmentName_2 = slot.data.attachmentName;
  615. slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
  616. }
  617. return;
  618. }
  619. var frameIndex = 0;
  620. if (time >= frames[frames.length - 1])
  621. frameIndex = frames.length - 1;
  622. else
  623. frameIndex = Animation.binarySearch(frames, time, 1) - 1;
  624. var attachmentName = this.attachmentNames[frameIndex];
  625. skeleton.slots[this.slotIndex]
  626. .setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  627. };
  628. return AttachmentTimeline;
  629. }());
  630. spine.AttachmentTimeline = AttachmentTimeline;
  631. var zeros = null;
  632. var DeformTimeline = (function (_super) {
  633. __extends(DeformTimeline, _super);
  634. function DeformTimeline(frameCount) {
  635. var _this = _super.call(this, frameCount) || this;
  636. _this.frames = spine.Utils.newFloatArray(frameCount);
  637. _this.frameVertices = new Array(frameCount);
  638. if (zeros == null)
  639. zeros = spine.Utils.newFloatArray(64);
  640. return _this;
  641. }
  642. DeformTimeline.prototype.getPropertyId = function () {
  643. return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
  644. };
  645. DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
  646. this.frames[frameIndex] = time;
  647. this.frameVertices[frameIndex] = vertices;
  648. };
  649. DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  650. var slot = skeleton.slots[this.slotIndex];
  651. var slotAttachment = slot.getAttachment();
  652. if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
  653. return;
  654. var verticesArray = slot.attachmentVertices;
  655. if (verticesArray.length == 0)
  656. alpha = 1;
  657. var frameVertices = this.frameVertices;
  658. var vertexCount = frameVertices[0].length;
  659. var frames = this.frames;
  660. if (time < frames[0]) {
  661. var vertexAttachment = slotAttachment;
  662. switch (pose) {
  663. case MixPose.setup:
  664. verticesArray.length = 0;
  665. return;
  666. case MixPose.current:
  667. if (alpha == 1) {
  668. verticesArray.length = 0;
  669. break;
  670. }
  671. var vertices_1 = spine.Utils.setArraySize(verticesArray, vertexCount);
  672. if (vertexAttachment.bones == null) {
  673. var setupVertices = vertexAttachment.vertices;
  674. for (var i = 0; i < vertexCount; i++)
  675. vertices_1[i] += (setupVertices[i] - vertices_1[i]) * alpha;
  676. }
  677. else {
  678. alpha = 1 - alpha;
  679. for (var i = 0; i < vertexCount; i++)
  680. vertices_1[i] *= alpha;
  681. }
  682. }
  683. return;
  684. }
  685. var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
  686. if (time >= frames[frames.length - 1]) {
  687. var lastVertices = frameVertices[frames.length - 1];
  688. if (alpha == 1) {
  689. spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
  690. }
  691. else if (pose == MixPose.setup) {
  692. var vertexAttachment = slotAttachment;
  693. if (vertexAttachment.bones == null) {
  694. var setupVertices_1 = vertexAttachment.vertices;
  695. for (var i_1 = 0; i_1 < vertexCount; i_1++) {
  696. var setup = setupVertices_1[i_1];
  697. vertices[i_1] = setup + (lastVertices[i_1] - setup) * alpha;
  698. }
  699. }
  700. else {
  701. for (var i_2 = 0; i_2 < vertexCount; i_2++)
  702. vertices[i_2] = lastVertices[i_2] * alpha;
  703. }
  704. }
  705. else {
  706. for (var i_3 = 0; i_3 < vertexCount; i_3++)
  707. vertices[i_3] += (lastVertices[i_3] - vertices[i_3]) * alpha;
  708. }
  709. return;
  710. }
  711. var frame = Animation.binarySearch(frames, time);
  712. var prevVertices = frameVertices[frame - 1];
  713. var nextVertices = frameVertices[frame];
  714. var frameTime = frames[frame];
  715. var percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
  716. if (alpha == 1) {
  717. for (var i_4 = 0; i_4 < vertexCount; i_4++) {
  718. var prev = prevVertices[i_4];
  719. vertices[i_4] = prev + (nextVertices[i_4] - prev) * percent;
  720. }
  721. }
  722. else if (pose == MixPose.setup) {
  723. var vertexAttachment = slotAttachment;
  724. if (vertexAttachment.bones == null) {
  725. var setupVertices_2 = vertexAttachment.vertices;
  726. for (var i_5 = 0; i_5 < vertexCount; i_5++) {
  727. var prev = prevVertices[i_5], setup = setupVertices_2[i_5];
  728. vertices[i_5] = setup + (prev + (nextVertices[i_5] - prev) * percent - setup) * alpha;
  729. }
  730. }
  731. else {
  732. for (var i_6 = 0; i_6 < vertexCount; i_6++) {
  733. var prev = prevVertices[i_6];
  734. vertices[i_6] = (prev + (nextVertices[i_6] - prev) * percent) * alpha;
  735. }
  736. }
  737. }
  738. else {
  739. for (var i_7 = 0; i_7 < vertexCount; i_7++) {
  740. var prev = prevVertices[i_7];
  741. vertices[i_7] += (prev + (nextVertices[i_7] - prev) * percent - vertices[i_7]) * alpha;
  742. }
  743. }
  744. };
  745. return DeformTimeline;
  746. }(CurveTimeline));
  747. spine.DeformTimeline = DeformTimeline;
  748. var EventTimeline = (function () {
  749. function EventTimeline(frameCount) {
  750. this.frames = spine.Utils.newFloatArray(frameCount);
  751. this.events = new Array(frameCount);
  752. }
  753. EventTimeline.prototype.getPropertyId = function () {
  754. return TimelineType.event << 24;
  755. };
  756. EventTimeline.prototype.getFrameCount = function () {
  757. return this.frames.length;
  758. };
  759. EventTimeline.prototype.setFrame = function (frameIndex, event) {
  760. this.frames[frameIndex] = event.time;
  761. this.events[frameIndex] = event;
  762. };
  763. EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  764. if (firedEvents == null)
  765. return;
  766. var frames = this.frames;
  767. var frameCount = this.frames.length;
  768. if (lastTime > time) {
  769. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
  770. lastTime = -1;
  771. }
  772. else if (lastTime >= frames[frameCount - 1])
  773. return;
  774. if (time < frames[0])
  775. return;
  776. var frame = 0;
  777. if (lastTime < frames[0])
  778. frame = 0;
  779. else {
  780. frame = Animation.binarySearch(frames, lastTime);
  781. var frameTime = frames[frame];
  782. while (frame > 0) {
  783. if (frames[frame - 1] != frameTime)
  784. break;
  785. frame--;
  786. }
  787. }
  788. for (; frame < frameCount && time >= frames[frame]; frame++)
  789. firedEvents.push(this.events[frame]);
  790. };
  791. return EventTimeline;
  792. }());
  793. spine.EventTimeline = EventTimeline;
  794. var DrawOrderTimeline = (function () {
  795. function DrawOrderTimeline(frameCount) {
  796. this.frames = spine.Utils.newFloatArray(frameCount);
  797. this.drawOrders = new Array(frameCount);
  798. }
  799. DrawOrderTimeline.prototype.getPropertyId = function () {
  800. return TimelineType.drawOrder << 24;
  801. };
  802. DrawOrderTimeline.prototype.getFrameCount = function () {
  803. return this.frames.length;
  804. };
  805. DrawOrderTimeline.prototype.setFrame = function (frameIndex, time, drawOrder) {
  806. this.frames[frameIndex] = time;
  807. this.drawOrders[frameIndex] = drawOrder;
  808. };
  809. DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  810. var drawOrder = skeleton.drawOrder;
  811. var slots = skeleton.slots;
  812. if (direction == MixDirection.out && pose == MixPose.setup) {
  813. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  814. return;
  815. }
  816. var frames = this.frames;
  817. if (time < frames[0]) {
  818. if (pose == MixPose.setup)
  819. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  820. return;
  821. }
  822. var frame = 0;
  823. if (time >= frames[frames.length - 1])
  824. frame = frames.length - 1;
  825. else
  826. frame = Animation.binarySearch(frames, time) - 1;
  827. var drawOrderToSetupIndex = this.drawOrders[frame];
  828. if (drawOrderToSetupIndex == null)
  829. spine.Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  830. else {
  831. for (var i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  832. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  833. }
  834. };
  835. return DrawOrderTimeline;
  836. }());
  837. spine.DrawOrderTimeline = DrawOrderTimeline;
  838. var IkConstraintTimeline = (function (_super) {
  839. __extends(IkConstraintTimeline, _super);
  840. function IkConstraintTimeline(frameCount) {
  841. var _this = _super.call(this, frameCount) || this;
  842. _this.frames = spine.Utils.newFloatArray(frameCount * IkConstraintTimeline.ENTRIES);
  843. return _this;
  844. }
  845. IkConstraintTimeline.prototype.getPropertyId = function () {
  846. return (TimelineType.ikConstraint << 24) + this.ikConstraintIndex;
  847. };
  848. IkConstraintTimeline.prototype.setFrame = function (frameIndex, time, mix, bendDirection) {
  849. frameIndex *= IkConstraintTimeline.ENTRIES;
  850. this.frames[frameIndex] = time;
  851. this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
  852. this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
  853. };
  854. IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  855. var frames = this.frames;
  856. var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  857. if (time < frames[0]) {
  858. switch (pose) {
  859. case MixPose.setup:
  860. constraint.mix = constraint.data.mix;
  861. constraint.bendDirection = constraint.data.bendDirection;
  862. return;
  863. case MixPose.current:
  864. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  865. constraint.bendDirection = constraint.data.bendDirection;
  866. }
  867. return;
  868. }
  869. if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
  870. if (pose == MixPose.setup) {
  871. constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
  872. constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
  873. : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  874. }
  875. else {
  876. constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
  877. if (direction == MixDirection["in"])
  878. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  879. }
  880. return;
  881. }
  882. var frame = Animation.binarySearch(frames, time, IkConstraintTimeline.ENTRIES);
  883. var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
  884. var frameTime = frames[frame];
  885. var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
  886. if (pose == MixPose.setup) {
  887. constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha;
  888. constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  889. }
  890. else {
  891. constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
  892. if (direction == MixDirection["in"])
  893. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  894. }
  895. };
  896. IkConstraintTimeline.ENTRIES = 3;
  897. IkConstraintTimeline.PREV_TIME = -3;
  898. IkConstraintTimeline.PREV_MIX = -2;
  899. IkConstraintTimeline.PREV_BEND_DIRECTION = -1;
  900. IkConstraintTimeline.MIX = 1;
  901. IkConstraintTimeline.BEND_DIRECTION = 2;
  902. return IkConstraintTimeline;
  903. }(CurveTimeline));
  904. spine.IkConstraintTimeline = IkConstraintTimeline;
  905. var TransformConstraintTimeline = (function (_super) {
  906. __extends(TransformConstraintTimeline, _super);
  907. function TransformConstraintTimeline(frameCount) {
  908. var _this = _super.call(this, frameCount) || this;
  909. _this.frames = spine.Utils.newFloatArray(frameCount * TransformConstraintTimeline.ENTRIES);
  910. return _this;
  911. }
  912. TransformConstraintTimeline.prototype.getPropertyId = function () {
  913. return (TimelineType.transformConstraint << 24) + this.transformConstraintIndex;
  914. };
  915. TransformConstraintTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix, scaleMix, shearMix) {
  916. frameIndex *= TransformConstraintTimeline.ENTRIES;
  917. this.frames[frameIndex] = time;
  918. this.frames[frameIndex + TransformConstraintTimeline.ROTATE] = rotateMix;
  919. this.frames[frameIndex + TransformConstraintTimeline.TRANSLATE] = translateMix;
  920. this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
  921. this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
  922. };
  923. TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  924. var frames = this.frames;
  925. var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  926. if (time < frames[0]) {
  927. var data = constraint.data;
  928. switch (pose) {
  929. case MixPose.setup:
  930. constraint.rotateMix = data.rotateMix;
  931. constraint.translateMix = data.translateMix;
  932. constraint.scaleMix = data.scaleMix;
  933. constraint.shearMix = data.shearMix;
  934. return;
  935. case MixPose.current:
  936. constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
  937. constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
  938. constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
  939. constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
  940. }
  941. return;
  942. }
  943. var rotate = 0, translate = 0, scale = 0, shear = 0;
  944. if (time >= frames[frames.length - TransformConstraintTimeline.ENTRIES]) {
  945. var i = frames.length;
  946. rotate = frames[i + TransformConstraintTimeline.PREV_ROTATE];
  947. translate = frames[i + TransformConstraintTimeline.PREV_TRANSLATE];
  948. scale = frames[i + TransformConstraintTimeline.PREV_SCALE];
  949. shear = frames[i + TransformConstraintTimeline.PREV_SHEAR];
  950. }
  951. else {
  952. var frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
  953. rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
  954. translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
  955. scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
  956. shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
  957. var frameTime = frames[frame];
  958. var percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
  959. rotate += (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent;
  960. translate += (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent;
  961. scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
  962. shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
  963. }
  964. if (pose == MixPose.setup) {
  965. var data = constraint.data;
  966. constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
  967. constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
  968. constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
  969. constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
  970. }
  971. else {
  972. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  973. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  974. constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
  975. constraint.shearMix += (shear - constraint.shearMix) * alpha;
  976. }
  977. };
  978. TransformConstraintTimeline.ENTRIES = 5;
  979. TransformConstraintTimeline.PREV_TIME = -5;
  980. TransformConstraintTimeline.PREV_ROTATE = -4;
  981. TransformConstraintTimeline.PREV_TRANSLATE = -3;
  982. TransformConstraintTimeline.PREV_SCALE = -2;
  983. TransformConstraintTimeline.PREV_SHEAR = -1;
  984. TransformConstraintTimeline.ROTATE = 1;
  985. TransformConstraintTimeline.TRANSLATE = 2;
  986. TransformConstraintTimeline.SCALE = 3;
  987. TransformConstraintTimeline.SHEAR = 4;
  988. return TransformConstraintTimeline;
  989. }(CurveTimeline));
  990. spine.TransformConstraintTimeline = TransformConstraintTimeline;
  991. var PathConstraintPositionTimeline = (function (_super) {
  992. __extends(PathConstraintPositionTimeline, _super);
  993. function PathConstraintPositionTimeline(frameCount) {
  994. var _this = _super.call(this, frameCount) || this;
  995. _this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintPositionTimeline.ENTRIES);
  996. return _this;
  997. }
  998. PathConstraintPositionTimeline.prototype.getPropertyId = function () {
  999. return (TimelineType.pathConstraintPosition << 24) + this.pathConstraintIndex;
  1000. };
  1001. PathConstraintPositionTimeline.prototype.setFrame = function (frameIndex, time, value) {
  1002. frameIndex *= PathConstraintPositionTimeline.ENTRIES;
  1003. this.frames[frameIndex] = time;
  1004. this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
  1005. };
  1006. PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1007. var frames = this.frames;
  1008. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1009. if (time < frames[0]) {
  1010. switch (pose) {
  1011. case MixPose.setup:
  1012. constraint.position = constraint.data.position;
  1013. return;
  1014. case MixPose.current:
  1015. constraint.position += (constraint.data.position - constraint.position) * alpha;
  1016. }
  1017. return;
  1018. }
  1019. var position = 0;
  1020. if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES])
  1021. position = frames[frames.length + PathConstraintPositionTimeline.PREV_VALUE];
  1022. else {
  1023. var frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
  1024. position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
  1025. var frameTime = frames[frame];
  1026. var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
  1027. position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
  1028. }
  1029. if (pose == MixPose.setup)
  1030. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  1031. else
  1032. constraint.position += (position - constraint.position) * alpha;
  1033. };
  1034. PathConstraintPositionTimeline.ENTRIES = 2;
  1035. PathConstraintPositionTimeline.PREV_TIME = -2;
  1036. PathConstraintPositionTimeline.PREV_VALUE = -1;
  1037. PathConstraintPositionTimeline.VALUE = 1;
  1038. return PathConstraintPositionTimeline;
  1039. }(CurveTimeline));
  1040. spine.PathConstraintPositionTimeline = PathConstraintPositionTimeline;
  1041. var PathConstraintSpacingTimeline = (function (_super) {
  1042. __extends(PathConstraintSpacingTimeline, _super);
  1043. function PathConstraintSpacingTimeline(frameCount) {
  1044. return _super.call(this, frameCount) || this;
  1045. }
  1046. PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
  1047. return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
  1048. };
  1049. PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1050. var frames = this.frames;
  1051. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1052. if (time < frames[0]) {
  1053. switch (pose) {
  1054. case MixPose.setup:
  1055. constraint.spacing = constraint.data.spacing;
  1056. return;
  1057. case MixPose.current:
  1058. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  1059. }
  1060. return;
  1061. }
  1062. var spacing = 0;
  1063. if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES])
  1064. spacing = frames[frames.length + PathConstraintSpacingTimeline.PREV_VALUE];
  1065. else {
  1066. var frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
  1067. spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
  1068. var frameTime = frames[frame];
  1069. var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
  1070. spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
  1071. }
  1072. if (pose == MixPose.setup)
  1073. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  1074. else
  1075. constraint.spacing += (spacing - constraint.spacing) * alpha;
  1076. };
  1077. return PathConstraintSpacingTimeline;
  1078. }(PathConstraintPositionTimeline));
  1079. spine.PathConstraintSpacingTimeline = PathConstraintSpacingTimeline;
  1080. var PathConstraintMixTimeline = (function (_super) {
  1081. __extends(PathConstraintMixTimeline, _super);
  1082. function PathConstraintMixTimeline(frameCount) {
  1083. var _this = _super.call(this, frameCount) || this;
  1084. _this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintMixTimeline.ENTRIES);
  1085. return _this;
  1086. }
  1087. PathConstraintMixTimeline.prototype.getPropertyId = function () {
  1088. return (TimelineType.pathConstraintMix << 24) + this.pathConstraintIndex;
  1089. };
  1090. PathConstraintMixTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix) {
  1091. frameIndex *= PathConstraintMixTimeline.ENTRIES;
  1092. this.frames[frameIndex] = time;
  1093. this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
  1094. this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
  1095. };
  1096. PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1097. var frames = this.frames;
  1098. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1099. if (time < frames[0]) {
  1100. switch (pose) {
  1101. case MixPose.setup:
  1102. constraint.rotateMix = constraint.data.rotateMix;
  1103. constraint.translateMix = constraint.data.translateMix;
  1104. return;
  1105. case MixPose.current:
  1106. constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
  1107. constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
  1108. }
  1109. return;
  1110. }
  1111. var rotate = 0, translate = 0;
  1112. if (time >= frames[frames.length - PathConstraintMixTimeline.ENTRIES]) {
  1113. rotate = frames[frames.length + PathConstraintMixTimeline.PREV_ROTATE];
  1114. translate = frames[frames.length + PathConstraintMixTimeline.PREV_TRANSLATE];
  1115. }
  1116. else {
  1117. var frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
  1118. rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
  1119. translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
  1120. var frameTime = frames[frame];
  1121. var percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
  1122. rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
  1123. translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
  1124. }
  1125. if (pose == MixPose.setup) {
  1126. constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
  1127. constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
  1128. }
  1129. else {
  1130. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  1131. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  1132. }
  1133. };
  1134. PathConstraintMixTimeline.ENTRIES = 3;
  1135. PathConstraintMixTimeline.PREV_TIME = -3;
  1136. PathConstraintMixTimeline.PREV_ROTATE = -2;
  1137. PathConstraintMixTimeline.PREV_TRANSLATE = -1;
  1138. PathConstraintMixTimeline.ROTATE = 1;
  1139. PathConstraintMixTimeline.TRANSLATE = 2;
  1140. return PathConstraintMixTimeline;
  1141. }(CurveTimeline));
  1142. spine.PathConstraintMixTimeline = PathConstraintMixTimeline;
  1143. })(spine || (spine = {}));
  1144. var spine;
  1145. (function (spine) {
  1146. var AnimationState = (function () {
  1147. function AnimationState(data) {
  1148. this.tracks = new Array();
  1149. this.events = new Array();
  1150. this.listeners = new Array();
  1151. this.queue = new EventQueue(this);
  1152. this.propertyIDs = new spine.IntSet();
  1153. this.mixingTo = new Array();
  1154. this.animationsChanged = false;
  1155. this.timeScale = 1;
  1156. this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
  1157. this.data = data;
  1158. }
  1159. AnimationState.prototype.update = function (delta) {
  1160. delta *= this.timeScale;
  1161. var tracks = this.tracks;
  1162. for (var i = 0, n = tracks.length; i < n; i++) {
  1163. var current = tracks[i];
  1164. if (current == null)
  1165. continue;
  1166. current.animationLast = current.nextAnimationLast;
  1167. current.trackLast = current.nextTrackLast;
  1168. var currentDelta = delta * current.timeScale;
  1169. if (current.delay > 0) {
  1170. current.delay -= currentDelta;
  1171. if (current.delay > 0)
  1172. continue;
  1173. currentDelta = -current.delay;
  1174. current.delay = 0;
  1175. }
  1176. var next = current.next;
  1177. if (next != null) {
  1178. var nextTime = current.trackLast - next.delay;
  1179. if (nextTime >= 0) {
  1180. next.delay = 0;
  1181. next.trackTime = nextTime + delta * next.timeScale;
  1182. current.trackTime += currentDelta;
  1183. this.setCurrent(i, next, true);
  1184. while (next.mixingFrom != null) {
  1185. next.mixTime += currentDelta;
  1186. next = next.mixingFrom;
  1187. }
  1188. continue;
  1189. }
  1190. }
  1191. else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  1192. tracks[i] = null;
  1193. this.queue.end(current);
  1194. this.disposeNext(current);
  1195. continue;
  1196. }
  1197. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  1198. var from = current.mixingFrom;
  1199. current.mixingFrom = null;
  1200. while (from != null) {
  1201. this.queue.end(from);
  1202. from = from.mixingFrom;
  1203. }
  1204. }
  1205. current.trackTime += currentDelta;
  1206. }
  1207. this.queue.drain();
  1208. };
  1209. AnimationState.prototype.updateMixingFrom = function (to, delta) {
  1210. var from = to.mixingFrom;
  1211. if (from == null)
  1212. return true;
  1213. var finished = this.updateMixingFrom(from, delta);
  1214. from.animationLast = from.nextAnimationLast;
  1215. from.trackLast = from.nextTrackLast;
  1216. if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
  1217. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  1218. to.mixingFrom = from.mixingFrom;
  1219. to.interruptAlpha = from.interruptAlpha;
  1220. this.queue.end(from);
  1221. }
  1222. return finished;
  1223. }
  1224. from.trackTime += delta * from.timeScale;
  1225. to.mixTime += delta * to.timeScale;
  1226. return false;
  1227. };
  1228. AnimationState.prototype.apply = function (skeleton) {
  1229. if (skeleton == null)
  1230. throw new Error("skeleton cannot be null.");
  1231. if (this.animationsChanged)
  1232. this._animationsChanged();
  1233. var events = this.events;
  1234. var tracks = this.tracks;
  1235. var applied = false;
  1236. for (var i = 0, n = tracks.length; i < n; i++) {
  1237. var current = tracks[i];
  1238. if (current == null || current.delay > 0)
  1239. continue;
  1240. applied = true;
  1241. var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
  1242. var mix = current.alpha;
  1243. if (current.mixingFrom != null)
  1244. mix *= this.applyMixingFrom(current, skeleton, currentPose);
  1245. else if (current.trackTime >= current.trackEnd && current.next == null)
  1246. mix = 0;
  1247. var animationLast = current.animationLast, animationTime = current.getAnimationTime();
  1248. var timelineCount = current.animation.timelines.length;
  1249. var timelines = current.animation.timelines;
  1250. if (mix == 1) {
  1251. for (var ii = 0; ii < timelineCount; ii++)
  1252. timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection["in"]);
  1253. }
  1254. else {
  1255. var timelineData = current.timelineData;
  1256. var firstFrame = current.timelinesRotation.length == 0;
  1257. if (firstFrame)
  1258. spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  1259. var timelinesRotation = current.timelinesRotation;
  1260. for (var ii = 0; ii < timelineCount; ii++) {
  1261. var timeline = timelines[ii];
  1262. var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
  1263. if (timeline instanceof spine.RotateTimeline) {
  1264. this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
  1265. }
  1266. else {
  1267. spine.Utils.webkit602BugfixHelper(mix, pose);
  1268. timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection["in"]);
  1269. }
  1270. }
  1271. }
  1272. this.queueEvents(current, animationTime);
  1273. events.length = 0;
  1274. current.nextAnimationLast = animationTime;
  1275. current.nextTrackLast = current.trackTime;
  1276. }
  1277. this.queue.drain();
  1278. return applied;
  1279. };
  1280. AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
  1281. var from = to.mixingFrom;
  1282. if (from.mixingFrom != null)
  1283. this.applyMixingFrom(from, skeleton, currentPose);
  1284. var mix = 0;
  1285. if (to.mixDuration == 0) {
  1286. mix = 1;
  1287. currentPose = spine.MixPose.setup;
  1288. }
  1289. else {
  1290. mix = to.mixTime / to.mixDuration;
  1291. if (mix > 1)
  1292. mix = 1;
  1293. }
  1294. var events = mix < from.eventThreshold ? this.events : null;
  1295. var attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  1296. var animationLast = from.animationLast, animationTime = from.getAnimationTime();
  1297. var timelineCount = from.animation.timelines.length;
  1298. var timelines = from.animation.timelines;
  1299. var timelineData = from.timelineData;
  1300. var timelineDipMix = from.timelineDipMix;
  1301. var firstFrame = from.timelinesRotation.length == 0;
  1302. if (firstFrame)
  1303. spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  1304. var timelinesRotation = from.timelinesRotation;
  1305. var pose;
  1306. var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
  1307. from.totalAlpha = 0;
  1308. for (var i = 0; i < timelineCount; i++) {
  1309. var timeline = timelines[i];
  1310. switch (timelineData[i]) {
  1311. case AnimationState.SUBSEQUENT:
  1312. if (!attachments && timeline instanceof spine.AttachmentTimeline)
  1313. continue;
  1314. if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
  1315. continue;
  1316. pose = currentPose;
  1317. alpha = alphaMix;
  1318. break;
  1319. case AnimationState.FIRST:
  1320. pose = spine.MixPose.setup;
  1321. alpha = alphaMix;
  1322. break;
  1323. case AnimationState.DIP:
  1324. pose = spine.MixPose.setup;
  1325. alpha = alphaDip;
  1326. break;
  1327. default:
  1328. pose = spine.MixPose.setup;
  1329. alpha = alphaDip;
  1330. var dipMix = timelineDipMix[i];
  1331. alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
  1332. break;
  1333. }
  1334. from.totalAlpha += alpha;
  1335. if (timeline instanceof spine.RotateTimeline)
  1336. this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
  1337. else {
  1338. spine.Utils.webkit602BugfixHelper(alpha, pose);
  1339. timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
  1340. }
  1341. }
  1342. if (to.mixDuration > 0)
  1343. this.queueEvents(from, animationTime);
  1344. this.events.length = 0;
  1345. from.nextAnimationLast = animationTime;
  1346. from.nextTrackLast = from.trackTime;
  1347. return mix;
  1348. };
  1349. AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
  1350. if (firstFrame)
  1351. timelinesRotation[i] = 0;
  1352. if (alpha == 1) {
  1353. timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection["in"]);
  1354. return;
  1355. }
  1356. var rotateTimeline = timeline;
  1357. var frames = rotateTimeline.frames;
  1358. var bone = skeleton.bones[rotateTimeline.boneIndex];
  1359. if (time < frames[0]) {
  1360. if (pose == spine.MixPose.setup)
  1361. bone.rotation = bone.data.rotation;
  1362. return;
  1363. }
  1364. var r2 = 0;
  1365. if (time >= frames[frames.length - spine.RotateTimeline.ENTRIES])
  1366. r2 = bone.data.rotation + frames[frames.length + spine.RotateTimeline.PREV_ROTATION];
  1367. else {
  1368. var frame = spine.Animation.binarySearch(frames, time, spine.RotateTimeline.ENTRIES);
  1369. var prevRotation = frames[frame + spine.RotateTimeline.PREV_ROTATION];
  1370. var frameTime = frames[frame];
  1371. var percent = rotateTimeline.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + spine.RotateTimeline.PREV_TIME] - frameTime));
  1372. r2 = frames[frame + spine.RotateTimeline.ROTATION] - prevRotation;
  1373. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1374. r2 = prevRotation + r2 * percent + bone.data.rotation;
  1375. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1376. }
  1377. var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
  1378. var total = 0, diff = r2 - r1;
  1379. if (diff == 0) {
  1380. total = timelinesRotation[i];
  1381. }
  1382. else {
  1383. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  1384. var lastTotal = 0, lastDiff = 0;
  1385. if (firstFrame) {
  1386. lastTotal = 0;
  1387. lastDiff = diff;
  1388. }
  1389. else {
  1390. lastTotal = timelinesRotation[i];
  1391. lastDiff = timelinesRotation[i + 1];
  1392. }
  1393. var current = diff > 0, dir = lastTotal >= 0;
  1394. if (spine.MathUtils.signum(lastDiff) != spine.MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  1395. if (Math.abs(lastTotal) > 180)
  1396. lastTotal += 360 * spine.MathUtils.signum(lastTotal);
  1397. dir = current;
  1398. }
  1399. total = diff + lastTotal - lastTotal % 360;
  1400. if (dir != current)
  1401. total += 360 * spine.MathUtils.signum(lastTotal);
  1402. timelinesRotation[i] = total;
  1403. }
  1404. timelinesRotation[i + 1] = diff;
  1405. r1 += total * alpha;
  1406. bone.rotation = r1 - (16384 - ((16384.499999999996 - r1 / 360) | 0)) * 360;
  1407. };
  1408. AnimationState.prototype.queueEvents = function (entry, animationTime) {
  1409. var animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  1410. var duration = animationEnd - animationStart;
  1411. var trackLastWrapped = entry.trackLast % duration;
  1412. var events = this.events;
  1413. var i = 0, n = events.length;
  1414. for (; i < n; i++) {
  1415. var event_1 = events[i];
  1416. if (event_1.time < trackLastWrapped)
  1417. break;
  1418. if (event_1.time > animationEnd)
  1419. continue;
  1420. this.queue.event(entry, event_1);
  1421. }
  1422. var complete = false;
  1423. if (entry.loop)
  1424. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  1425. else
  1426. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  1427. if (complete)
  1428. this.queue.complete(entry);
  1429. for (; i < n; i++) {
  1430. var event_2 = events[i];
  1431. if (event_2.time < animationStart)
  1432. continue;
  1433. this.queue.event(entry, events[i]);
  1434. }
  1435. };
  1436. AnimationState.prototype.clearTracks = function () {
  1437. var oldDrainDisabled = this.queue.drainDisabled;
  1438. this.queue.drainDisabled = true;
  1439. for (var i = 0, n = this.tracks.length; i < n; i++)
  1440. this.clearTrack(i);
  1441. this.tracks.length = 0;
  1442. this.queue.drainDisabled = oldDrainDisabled;
  1443. this.queue.drain();
  1444. };
  1445. AnimationState.prototype.clearTrack = function (trackIndex) {
  1446. if (trackIndex >= this.tracks.length)
  1447. return;
  1448. var current = this.tracks[trackIndex];
  1449. if (current == null)
  1450. return;
  1451. this.queue.end(current);
  1452. this.disposeNext(current);
  1453. var entry = current;
  1454. while (true) {
  1455. var from = entry.mixingFrom;
  1456. if (from == null)
  1457. break;
  1458. this.queue.end(from);
  1459. entry.mixingFrom = null;
  1460. entry = from;
  1461. }
  1462. this.tracks[current.trackIndex] = null;
  1463. this.queue.drain();
  1464. };
  1465. AnimationState.prototype.setCurrent = function (index, current, interrupt) {
  1466. var from = this.expandToIndex(index);
  1467. this.tracks[index] = current;
  1468. if (from != null) {
  1469. if (interrupt)
  1470. this.queue.interrupt(from);
  1471. current.mixingFrom = from;
  1472. current.mixTime = 0;
  1473. if (from.mixingFrom != null && from.mixDuration > 0)
  1474. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  1475. from.timelinesRotation.length = 0;
  1476. }
  1477. this.queue.start(current);
  1478. };
  1479. AnimationState.prototype.setAnimation = function (trackIndex, animationName, loop) {
  1480. var animation = this.data.skeletonData.findAnimation(animationName);
  1481. if (animation == null)
  1482. throw new Error("Animation not found: " + animationName);
  1483. return this.setAnimationWith(trackIndex, animation, loop);
  1484. };
  1485. AnimationState.prototype.setAnimationWith = function (trackIndex, animation, loop) {
  1486. if (animation == null)
  1487. throw new Error("animation cannot be null.");
  1488. var interrupt = true;
  1489. var current = this.expandToIndex(trackIndex);
  1490. if (current != null) {
  1491. if (current.nextTrackLast == -1) {
  1492. this.tracks[trackIndex] = current.mixingFrom;
  1493. this.queue.interrupt(current);
  1494. this.queue.end(current);
  1495. this.disposeNext(current);
  1496. current = current.mixingFrom;
  1497. interrupt = false;
  1498. }
  1499. else
  1500. this.disposeNext(current);
  1501. }
  1502. var entry = this.trackEntry(trackIndex, animation, loop, current);
  1503. this.setCurrent(trackIndex, entry, interrupt);
  1504. this.queue.drain();
  1505. return entry;
  1506. };
  1507. AnimationState.prototype.addAnimation = function (trackIndex, animationName, loop, delay) {
  1508. var animation = this.data.skeletonData.findAnimation(animationName);
  1509. if (animation == null)
  1510. throw new Error("Animation not found: " + animationName);
  1511. return this.addAnimationWith(trackIndex, animation, loop, delay);
  1512. };
  1513. AnimationState.prototype.addAnimationWith = function (trackIndex, animation, loop, delay) {
  1514. if (animation == null)
  1515. throw new Error("animation cannot be null.");
  1516. var last = this.expandToIndex(trackIndex);
  1517. if (last != null) {
  1518. while (last.next != null)
  1519. last = last.next;
  1520. }
  1521. var entry = this.trackEntry(trackIndex, animation, loop, last);
  1522. if (last == null) {
  1523. this.setCurrent(trackIndex, entry, true);
  1524. this.queue.drain();
  1525. }
  1526. else {
  1527. last.next = entry;
  1528. if (delay <= 0) {
  1529. var duration = last.animationEnd - last.animationStart;
  1530. if (duration != 0) {
  1531. if (last.loop)
  1532. delay += duration * (1 + ((last.trackTime / duration) | 0));
  1533. else
  1534. delay += duration;
  1535. delay -= this.data.getMix(last.animation, animation);
  1536. }
  1537. else
  1538. delay = 0;
  1539. }
  1540. }
  1541. entry.delay = delay;
  1542. return entry;
  1543. };
  1544. AnimationState.prototype.setEmptyAnimation = function (trackIndex, mixDuration) {
  1545. var entry = this.setAnimationWith(trackIndex, AnimationState.emptyAnimation, false);
  1546. entry.mixDuration = mixDuration;
  1547. entry.trackEnd = mixDuration;
  1548. return entry;
  1549. };
  1550. AnimationState.prototype.addEmptyAnimation = function (trackIndex, mixDuration, delay) {
  1551. if (delay <= 0)
  1552. delay -= mixDuration;
  1553. var entry = this.addAnimationWith(trackIndex, AnimationState.emptyAnimation, false, delay);
  1554. entry.mixDuration = mixDuration;
  1555. entry.trackEnd = mixDuration;
  1556. return entry;
  1557. };
  1558. AnimationState.prototype.setEmptyAnimations = function (mixDuration) {
  1559. var oldDrainDisabled = this.queue.drainDisabled;
  1560. this.queue.drainDisabled = true;
  1561. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1562. var current = this.tracks[i];
  1563. if (current != null)
  1564. this.setEmptyAnimation(current.trackIndex, mixDuration);
  1565. }
  1566. this.queue.drainDisabled = oldDrainDisabled;
  1567. this.queue.drain();
  1568. };
  1569. AnimationState.prototype.expandToIndex = function (index) {
  1570. if (index < this.tracks.length)
  1571. return this.tracks[index];
  1572. spine.Utils.ensureArrayCapacity(this.tracks, index - this.tracks.length + 1, null);
  1573. this.tracks.length = index + 1;
  1574. return null;
  1575. };
  1576. AnimationState.prototype.trackEntry = function (trackIndex, animation, loop, last) {
  1577. var entry = this.trackEntryPool.obtain();
  1578. entry.trackIndex = trackIndex;
  1579. entry.animation = animation;
  1580. entry.loop = loop;
  1581. entry.eventThreshold = 0;
  1582. entry.attachmentThreshold = 0;
  1583. entry.drawOrderThreshold = 0;
  1584. entry.animationStart = 0;
  1585. entry.animationEnd = animation.duration;
  1586. entry.animationLast = -1;
  1587. entry.nextAnimationLast = -1;
  1588. entry.delay = 0;
  1589. entry.trackTime = 0;
  1590. entry.trackLast = -1;
  1591. entry.nextTrackLast = -1;
  1592. entry.trackEnd = Number.MAX_VALUE;
  1593. entry.timeScale = 1;
  1594. entry.alpha = 1;
  1595. entry.interruptAlpha = 1;
  1596. entry.mixTime = 0;
  1597. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  1598. return entry;
  1599. };
  1600. AnimationState.prototype.disposeNext = function (entry) {
  1601. var next = entry.next;
  1602. while (next != null) {
  1603. this.queue.dispose(next);
  1604. next = next.next;
  1605. }
  1606. entry.next = null;
  1607. };
  1608. AnimationState.prototype._animationsChanged = function () {
  1609. this.animationsChanged = false;
  1610. var propertyIDs = this.propertyIDs;
  1611. propertyIDs.clear();
  1612. var mixingTo = this.mixingTo;
  1613. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1614. var entry = this.tracks[i];
  1615. if (entry != null)
  1616. entry.setTimelineData(null, mixingTo, propertyIDs);
  1617. }
  1618. };
  1619. AnimationState.prototype.getCurrent = function (trackIndex) {
  1620. if (trackIndex >= this.tracks.length)
  1621. return null;
  1622. return this.tracks[trackIndex];
  1623. };
  1624. AnimationState.prototype.addListener = function (listener) {
  1625. if (listener == null)
  1626. throw new Error("listener cannot be null.");
  1627. this.listeners.push(listener);
  1628. };
  1629. AnimationState.prototype.removeListener = function (listener) {
  1630. var index = this.listeners.indexOf(listener);
  1631. if (index >= 0)
  1632. this.listeners.splice(index, 1);
  1633. };
  1634. AnimationState.prototype.clearListeners = function () {
  1635. this.listeners.length = 0;
  1636. };
  1637. AnimationState.prototype.clearListenerNotifications = function () {
  1638. this.queue.clear();
  1639. };
  1640. AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
  1641. AnimationState.SUBSEQUENT = 0;
  1642. AnimationState.FIRST = 1;
  1643. AnimationState.DIP = 2;
  1644. AnimationState.DIP_MIX = 3;
  1645. return AnimationState;
  1646. }());
  1647. spine.AnimationState = AnimationState;
  1648. var TrackEntry = (function () {
  1649. function TrackEntry() {
  1650. this.timelineData = new Array();
  1651. this.timelineDipMix = new Array();
  1652. this.timelinesRotation = new Array();
  1653. }
  1654. TrackEntry.prototype.reset = function () {
  1655. this.next = null;
  1656. this.mixingFrom = null;
  1657. this.animation = null;
  1658. this.listener = null;
  1659. this.timelineData.length = 0;
  1660. this.timelineDipMix.length = 0;
  1661. this.timelinesRotation.length = 0;
  1662. };
  1663. TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
  1664. if (to != null)
  1665. mixingToArray.push(to);
  1666. var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
  1667. if (to != null)
  1668. mixingToArray.pop();
  1669. var mixingTo = mixingToArray;
  1670. var mixingToLast = mixingToArray.length - 1;
  1671. var timelines = this.animation.timelines;
  1672. var timelinesCount = this.animation.timelines.length;
  1673. var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
  1674. this.timelineDipMix.length = 0;
  1675. var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
  1676. outer: for (var i = 0; i < timelinesCount; i++) {
  1677. var id = timelines[i].getPropertyId();
  1678. if (!propertyIDs.add(id))
  1679. timelineData[i] = AnimationState.SUBSEQUENT;
  1680. else if (to == null || !to.hasTimeline(id))
  1681. timelineData[i] = AnimationState.FIRST;
  1682. else {
  1683. for (var ii = mixingToLast; ii >= 0; ii--) {
  1684. var entry = mixingTo[ii];
  1685. if (!entry.hasTimeline(id)) {
  1686. if (entry.mixDuration > 0) {
  1687. timelineData[i] = AnimationState.DIP_MIX;
  1688. timelineDipMix[i] = entry;
  1689. continue outer;
  1690. }
  1691. }
  1692. }
  1693. timelineData[i] = AnimationState.DIP;
  1694. }
  1695. }
  1696. return lastEntry;
  1697. };
  1698. TrackEntry.prototype.hasTimeline = function (id) {
  1699. var timelines = this.animation.timelines;
  1700. for (var i = 0, n = timelines.length; i < n; i++)
  1701. if (timelines[i].getPropertyId() == id)
  1702. return true;
  1703. return false;
  1704. };
  1705. TrackEntry.prototype.getAnimationTime = function () {
  1706. if (this.loop) {
  1707. var duration = this.animationEnd - this.animationStart;
  1708. if (duration == 0)
  1709. return this.animationStart;
  1710. return (this.trackTime % duration) + this.animationStart;
  1711. }
  1712. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  1713. };
  1714. TrackEntry.prototype.setAnimationLast = function (animationLast) {
  1715. this.animationLast = animationLast;
  1716. this.nextAnimationLast = animationLast;
  1717. };
  1718. TrackEntry.prototype.isComplete = function () {
  1719. return this.trackTime >= this.animationEnd - this.animationStart;
  1720. };
  1721. TrackEntry.prototype.resetRotationDirections = function () {
  1722. this.timelinesRotation.length = 0;
  1723. };
  1724. return TrackEntry;
  1725. }());
  1726. spine.TrackEntry = TrackEntry;
  1727. var EventQueue = (function () {
  1728. function EventQueue(animState) {
  1729. this.objects = [];
  1730. this.drainDisabled = false;
  1731. this.animState = animState;
  1732. }
  1733. EventQueue.prototype.start = function (entry) {
  1734. this.objects.push(EventType.start);
  1735. this.objects.push(entry);
  1736. this.animState.animationsChanged = true;
  1737. };
  1738. EventQueue.prototype.interrupt = function (entry) {
  1739. this.objects.push(EventType.interrupt);
  1740. this.objects.push(entry);
  1741. };
  1742. EventQueue.prototype.end = function (entry) {
  1743. this.objects.push(EventType.end);
  1744. this.objects.push(entry);
  1745. this.animState.animationsChanged = true;
  1746. };
  1747. EventQueue.prototype.dispose = function (entry) {
  1748. this.objects.push(EventType.dispose);
  1749. this.objects.push(entry);
  1750. };
  1751. EventQueue.prototype.complete = function (entry) {
  1752. this.objects.push(EventType.complete);
  1753. this.objects.push(entry);
  1754. };
  1755. EventQueue.prototype.event = function (entry, event) {
  1756. this.objects.push(EventType.event);
  1757. this.objects.push(entry);
  1758. this.objects.push(event);
  1759. };
  1760. EventQueue.prototype.drain = function () {
  1761. if (this.drainDisabled)
  1762. return;
  1763. this.drainDisabled = true;
  1764. var objects = this.objects;
  1765. var listeners = this.animState.listeners;
  1766. for (var i = 0; i < objects.length; i += 2) {
  1767. var type = objects[i];
  1768. var entry = objects[i + 1];
  1769. switch (type) {
  1770. case EventType.start:
  1771. if (entry.listener != null && entry.listener.start)
  1772. entry.listener.start(entry);
  1773. for (var ii = 0; ii < listeners.length; ii++)
  1774. if (listeners[ii].start)
  1775. listeners[ii].start(entry);
  1776. break;
  1777. case EventType.interrupt:
  1778. if (entry.listener != null && entry.listener.interrupt)
  1779. entry.listener.interrupt(entry);
  1780. for (var ii = 0; ii < listeners.length; ii++)
  1781. if (listeners[ii].interrupt)
  1782. listeners[ii].interrupt(entry);
  1783. break;
  1784. case EventType.end:
  1785. if (entry.listener != null && entry.listener.end)
  1786. entry.listener.end(entry);
  1787. for (var ii = 0; ii < listeners.length; ii++)
  1788. if (listeners[ii].end)
  1789. listeners[ii].end(entry);
  1790. case EventType.dispose:
  1791. if (entry.listener != null && entry.listener.dispose)
  1792. entry.listener.dispose(entry);
  1793. for (var ii = 0; ii < listeners.length; ii++)
  1794. if (listeners[ii].dispose)
  1795. listeners[ii].dispose(entry);
  1796. this.animState.trackEntryPool.free(entry);
  1797. break;
  1798. case EventType.complete:
  1799. if (entry.listener != null && entry.listener.complete)
  1800. entry.listener.complete(entry);
  1801. for (var ii = 0; ii < listeners.length; ii++)
  1802. if (listeners[ii].complete)
  1803. listeners[ii].complete(entry);
  1804. break;
  1805. case EventType.event:
  1806. var event_3 = objects[i++ + 2];
  1807. if (entry.listener != null && entry.listener.event)
  1808. entry.listener.event(entry, event_3);
  1809. for (var ii = 0; ii < listeners.length; ii++)
  1810. if (listeners[ii].event)
  1811. listeners[ii].event(entry, event_3);
  1812. break;
  1813. }
  1814. }
  1815. this.clear();
  1816. this.drainDisabled = false;
  1817. };
  1818. EventQueue.prototype.clear = function () {
  1819. this.objects.length = 0;
  1820. };
  1821. return EventQueue;
  1822. }());
  1823. spine.EventQueue = EventQueue;
  1824. var EventType;
  1825. (function (EventType) {
  1826. EventType[EventType["start"] = 0] = "start";
  1827. EventType[EventType["interrupt"] = 1] = "interrupt";
  1828. EventType[EventType["end"] = 2] = "end";
  1829. EventType[EventType["dispose"] = 3] = "dispose";
  1830. EventType[EventType["complete"] = 4] = "complete";
  1831. EventType[EventType["event"] = 5] = "event";
  1832. })(EventType = spine.EventType || (spine.EventType = {}));
  1833. var AnimationStateAdapter2 = (function () {
  1834. function AnimationStateAdapter2() {
  1835. }
  1836. AnimationStateAdapter2.prototype.start = function (entry) {
  1837. };
  1838. AnimationStateAdapter2.prototype.interrupt = function (entry) {
  1839. };
  1840. AnimationStateAdapter2.prototype.end = function (entry) {
  1841. };
  1842. AnimationStateAdapter2.prototype.dispose = function (entry) {
  1843. };
  1844. AnimationStateAdapter2.prototype.complete = function (entry) {
  1845. };
  1846. AnimationStateAdapter2.prototype.event = function (entry, event) {
  1847. };
  1848. return AnimationStateAdapter2;
  1849. }());
  1850. spine.AnimationStateAdapter2 = AnimationStateAdapter2;
  1851. })(spine || (spine = {}));
  1852. var spine;
  1853. (function (spine) {
  1854. var AnimationStateData = (function () {
  1855. function AnimationStateData(skeletonData) {
  1856. this.animationToMixTime = {};
  1857. this.defaultMix = 0;
  1858. if (skeletonData == null)
  1859. throw new Error("skeletonData cannot be null.");
  1860. this.skeletonData = skeletonData;
  1861. }
  1862. AnimationStateData.prototype.setMix = function (fromName, toName, duration) {
  1863. var from = this.skeletonData.findAnimation(fromName);
  1864. if (from == null)
  1865. throw new Error("Animation not found: " + fromName);
  1866. var to = this.skeletonData.findAnimation(toName);
  1867. if (to == null)
  1868. throw new Error("Animation not found: " + toName);
  1869. this.setMixWith(from, to, duration);
  1870. };
  1871. AnimationStateData.prototype.setMixWith = function (from, to, duration) {
  1872. if (from == null)
  1873. throw new Error("from cannot be null.");
  1874. if (to == null)
  1875. throw new Error("to cannot be null.");
  1876. var key = from.name + "." + to.name;
  1877. this.animationToMixTime[key] = duration;
  1878. };
  1879. AnimationStateData.prototype.getMix = function (from, to) {
  1880. var key = from.name + "." + to.name;
  1881. var value = this.animationToMixTime[key];
  1882. return value === undefined ? this.defaultMix : value;
  1883. };
  1884. return AnimationStateData;
  1885. }());
  1886. spine.AnimationStateData = AnimationStateData;
  1887. })(spine || (spine = {}));
  1888. var spine;
  1889. (function (spine) {
  1890. var AssetManager = (function () {
  1891. function AssetManager(textureLoader, pathPrefix) {
  1892. if (pathPrefix === void 0) { pathPrefix = ""; }
  1893. this.assets = {};
  1894. this.errors = {};
  1895. this.toLoad = 0;
  1896. this.loaded = 0;
  1897. this.textureLoader = textureLoader;
  1898. this.pathPrefix = pathPrefix;
  1899. }
  1900. AssetManager.downloadText = function (url, success, error) {
  1901. var request = new XMLHttpRequest();
  1902. request.open("GET", url, true);
  1903. request.onload = function () {
  1904. if (request.status == 200) {
  1905. success(request.responseText);
  1906. }
  1907. else {
  1908. error(request.status, request.responseText);
  1909. }
  1910. };
  1911. request.onerror = function () {
  1912. error(request.status, request.responseText);
  1913. };
  1914. request.send();
  1915. };
  1916. AssetManager.downloadBinary = function (url, success, error) {
  1917. var request = new XMLHttpRequest();
  1918. request.open("GET", url, true);
  1919. request.responseType = "arraybuffer";
  1920. request.onload = function () {
  1921. if (request.status == 200) {
  1922. success(new Uint8Array(request.response));
  1923. }
  1924. else {
  1925. error(request.status, request.responseText);
  1926. }
  1927. };
  1928. request.onerror = function () {
  1929. error(request.status, request.responseText);
  1930. };
  1931. request.send();
  1932. };
  1933. AssetManager.prototype.loadText = function (path, success, error) {
  1934. var _this = this;
  1935. if (success === void 0) { success = null; }
  1936. if (error === void 0) { error = null; }
  1937. path = this.pathPrefix + path;
  1938. this.toLoad++;
  1939. AssetManager.downloadText(path, function (data) {
  1940. _this.assets[path] = data;
  1941. if (success)
  1942. success(path, data);
  1943. _this.toLoad--;
  1944. _this.loaded++;
  1945. }, function (state, responseText) {
  1946. _this.errors[path] = "Couldn't load text " + path + ": status " + status + ", " + responseText;
  1947. if (error)
  1948. error(path, "Couldn't load text " + path + ": status " + status + ", " + responseText);
  1949. _this.toLoad--;
  1950. _this.loaded++;
  1951. });
  1952. };
  1953. AssetManager.prototype.loadTexture = function (path, success, error) {
  1954. var _this = this;
  1955. if (success === void 0) { success = null; }
  1956. if (error === void 0) { error = null; }
  1957. path = this.pathPrefix + path;
  1958. this.toLoad++;
  1959. var img = new Image();
  1960. img.crossOrigin = "anonymous";
  1961. img.onload = function (ev) {
  1962. var texture = _this.textureLoader(img);
  1963. _this.assets[path] = texture;
  1964. _this.toLoad--;
  1965. _this.loaded++;
  1966. if (success)
  1967. success(path, img);
  1968. };
  1969. img.onerror = function (ev) {
  1970. _this.errors[path] = "Couldn't load image " + path;
  1971. _this.toLoad--;
  1972. _this.loaded++;
  1973. if (error)
  1974. error(path, "Couldn't load image " + path);
  1975. };
  1976. img.src = path;
  1977. };
  1978. AssetManager.prototype.loadTextureData = function (path, data, success, error) {
  1979. var _this = this;
  1980. if (success === void 0) { success = null; }
  1981. if (error === void 0) { error = null; }
  1982. path = this.pathPrefix + path;
  1983. this.toLoad++;
  1984. var img = new Image();
  1985. img.onload = function (ev) {
  1986. var texture = _this.textureLoader(img);
  1987. _this.assets[path] = texture;
  1988. _this.toLoad--;
  1989. _this.loaded++;
  1990. if (success)
  1991. success(path, img);
  1992. };
  1993. img.onerror = function (ev) {
  1994. _this.errors[path] = "Couldn't load image " + path;
  1995. _this.toLoad--;
  1996. _this.loaded++;
  1997. if (error)
  1998. error(path, "Couldn't load image " + path);
  1999. };
  2000. img.src = data;
  2001. };
  2002. AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
  2003. var _this = this;
  2004. if (success === void 0) { success = null; }
  2005. if (error === void 0) { error = null; }
  2006. var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
  2007. path = this.pathPrefix + path;
  2008. this.toLoad++;
  2009. AssetManager.downloadText(path, function (atlasData) {
  2010. var pagesLoaded = { count: 0 };
  2011. var atlasPages = new Array();
  2012. try {
  2013. var atlas = new spine.TextureAtlas(atlasData, function (path) {
  2014. atlasPages.push(parent + "/" + path);
  2015. var image = document.createElement("img");
  2016. image.width = 16;
  2017. image.height = 16;
  2018. return new spine.FakeTexture(image);
  2019. });
  2020. }
  2021. catch (e) {
  2022. var ex = e;
  2023. _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message;
  2024. if (error)
  2025. error(path, "Couldn't load texture atlas " + path + ": " + ex.message);
  2026. _this.toLoad--;
  2027. _this.loaded++;
  2028. return;
  2029. }
  2030. var _loop_1 = function (atlasPage) {
  2031. var pageLoadError = false;
  2032. _this.loadTexture(atlasPage, function (imagePath, image) {
  2033. pagesLoaded.count++;
  2034. if (pagesLoaded.count == atlasPages.length) {
  2035. if (!pageLoadError) {
  2036. try {
  2037. var atlas = new spine.TextureAtlas(atlasData, function (path) {
  2038. return _this.get(parent + "/" + path);
  2039. });
  2040. _this.assets[path] = atlas;
  2041. if (success)
  2042. success(path, atlas);
  2043. _this.toLoad--;
  2044. _this.loaded++;
  2045. }
  2046. catch (e) {
  2047. var ex = e;
  2048. _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message;
  2049. if (error)
  2050. error(path, "Couldn't load texture atlas " + path + ": " + ex.message);
  2051. _this.toLoad--;
  2052. _this.loaded++;
  2053. }
  2054. }
  2055. else {
  2056. _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path;
  2057. if (error)
  2058. error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path);
  2059. _this.toLoad--;
  2060. _this.loaded++;
  2061. }
  2062. }
  2063. }, function (imagePath, errorMessage) {
  2064. pageLoadError = true;
  2065. pagesLoaded.count++;
  2066. if (pagesLoaded.count == atlasPages.length) {
  2067. _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path;
  2068. if (error)
  2069. error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path);
  2070. _this.toLoad--;
  2071. _this.loaded++;
  2072. }
  2073. });
  2074. };
  2075. for (var _i = 0, atlasPages_1 = atlasPages; _i < atlasPages_1.length; _i++) {
  2076. var atlasPage = atlasPages_1[_i];
  2077. _loop_1(atlasPage);
  2078. }
  2079. }, function (state, responseText) {
  2080. _this.errors[path] = "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText;
  2081. if (error)
  2082. error(path, "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText);
  2083. _this.toLoad--;
  2084. _this.loaded++;
  2085. });
  2086. };
  2087. AssetManager.prototype.get = function (path) {
  2088. path = this.pathPrefix + path;
  2089. return this.assets[path];
  2090. };
  2091. AssetManager.prototype.remove = function (path) {
  2092. path = this.pathPrefix + path;
  2093. var asset = this.assets[path];
  2094. if (asset.dispose)
  2095. asset.dispose();
  2096. this.assets[path] = null;
  2097. };
  2098. AssetManager.prototype.removeAll = function () {
  2099. for (var key in this.assets) {
  2100. var asset = this.assets[key];
  2101. if (asset.dispose)
  2102. asset.dispose();
  2103. }
  2104. this.assets = {};
  2105. };
  2106. AssetManager.prototype.isLoadingComplete = function () {
  2107. return this.toLoad == 0;
  2108. };
  2109. AssetManager.prototype.getToLoad = function () {
  2110. return this.toLoad;
  2111. };
  2112. AssetManager.prototype.getLoaded = function () {
  2113. return this.loaded;
  2114. };
  2115. AssetManager.prototype.dispose = function () {
  2116. this.removeAll();
  2117. };
  2118. AssetManager.prototype.hasErrors = function () {
  2119. return Object.keys(this.errors).length > 0;
  2120. };
  2121. AssetManager.prototype.getErrors = function () {
  2122. return this.errors;
  2123. };
  2124. return AssetManager;
  2125. }());
  2126. spine.AssetManager = AssetManager;
  2127. })(spine || (spine = {}));
  2128. var spine;
  2129. (function (spine) {
  2130. var AtlasAttachmentLoader = (function () {
  2131. function AtlasAttachmentLoader(atlas) {
  2132. this.atlas = atlas;
  2133. }
  2134. AtlasAttachmentLoader.prototype.newRegionAttachment = function (skin, name, path) {
  2135. var region = this.atlas.findRegion(path);
  2136. if (region == null)
  2137. // throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  2138. return null;
  2139. region.renderObject = region;
  2140. var attachment = new spine.RegionAttachment(name);
  2141. attachment.setRegion(region);
  2142. return attachment;
  2143. };
  2144. AtlasAttachmentLoader.prototype.newMeshAttachment = function (skin, name, path) {
  2145. var region = this.atlas.findRegion(path);
  2146. if (region == null)
  2147. // throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  2148. return null;
  2149. region.renderObject = region;
  2150. var attachment = new spine.MeshAttachment(name);
  2151. attachment.region = region;
  2152. return attachment;
  2153. };
  2154. AtlasAttachmentLoader.prototype.newBoundingBoxAttachment = function (skin, name) {
  2155. return new spine.BoundingBoxAttachment(name);
  2156. };
  2157. AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) {
  2158. return new spine.PathAttachment(name);
  2159. };
  2160. AtlasAttachmentLoader.prototype.newPointAttachment = function (skin, name) {
  2161. return new spine.PointAttachment(name);
  2162. };
  2163. AtlasAttachmentLoader.prototype.newClippingAttachment = function (skin, name) {
  2164. return new spine.ClippingAttachment(name);
  2165. };
  2166. return AtlasAttachmentLoader;
  2167. }());
  2168. spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
  2169. })(spine || (spine = {}));
  2170. var spine;
  2171. (function (spine) {
  2172. var BlendMode;
  2173. (function (BlendMode) {
  2174. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  2175. BlendMode[BlendMode["Additive"] = 1] = "Additive";
  2176. BlendMode[BlendMode["Multiply"] = 2] = "Multiply";
  2177. BlendMode[BlendMode["Screen"] = 3] = "Screen";
  2178. })(BlendMode = spine.BlendMode || (spine.BlendMode = {}));
  2179. })(spine || (spine = {}));
  2180. var spine;
  2181. (function (spine) {
  2182. var Bone = (function () {
  2183. function Bone(data, skeleton, parent) {
  2184. this.children = new Array();
  2185. this.x = 0;
  2186. this.y = 0;
  2187. this.rotation = 0;
  2188. this.scaleX = 0;
  2189. this.scaleY = 0;
  2190. this.shearX = 0;
  2191. this.shearY = 0;
  2192. this.ax = 0;
  2193. this.ay = 0;
  2194. this.arotation = 0;
  2195. this.ascaleX = 0;
  2196. this.ascaleY = 0;
  2197. this.ashearX = 0;
  2198. this.ashearY = 0;
  2199. this.appliedValid = false;
  2200. this.a = 0;
  2201. this.b = 0;
  2202. this.worldX = 0;
  2203. this.c = 0;
  2204. this.d = 0;
  2205. this.worldY = 0;
  2206. this.sorted = false;
  2207. if (data == null)
  2208. throw new Error("data cannot be null.");
  2209. if (skeleton == null)
  2210. throw new Error("skeleton cannot be null.");
  2211. this.data = data;
  2212. this.skeleton = skeleton;
  2213. this.parent = parent;
  2214. this.setToSetupPose();
  2215. }
  2216. Bone.prototype.update = function () {
  2217. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2218. };
  2219. Bone.prototype.updateWorldTransform = function () {
  2220. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2221. };
  2222. Bone.prototype.updateWorldTransformWith = function (x, y, rotation, scaleX, scaleY, shearX, shearY) {
  2223. this.ax = x;
  2224. this.ay = y;
  2225. this.arotation = rotation;
  2226. this.ascaleX = scaleX;
  2227. this.ascaleY = scaleY;
  2228. this.ashearX = shearX;
  2229. this.ashearY = shearY;
  2230. this.appliedValid = true;
  2231. var parent = this.parent;
  2232. if (parent == null) {
  2233. var rotationY = rotation + 90 + shearY;
  2234. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2235. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2236. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2237. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2238. var skeleton = this.skeleton;
  2239. if (skeleton.flipX) {
  2240. x = -x;
  2241. la = -la;
  2242. lb = -lb;
  2243. }
  2244. if (skeleton.flipY) {
  2245. y = -y;
  2246. lc = -lc;
  2247. ld = -ld;
  2248. }
  2249. this.a = la;
  2250. this.b = lb;
  2251. this.c = lc;
  2252. this.d = ld;
  2253. this.worldX = x + skeleton.x;
  2254. this.worldY = y + skeleton.y;
  2255. return;
  2256. }
  2257. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2258. this.worldX = pa * x + pb * y + parent.worldX;
  2259. this.worldY = pc * x + pd * y + parent.worldY;
  2260. switch (this.data.transformMode) {
  2261. case spine.TransformMode.Normal: {
  2262. var rotationY = rotation + 90 + shearY;
  2263. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2264. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2265. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2266. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2267. this.a = pa * la + pb * lc;
  2268. this.b = pa * lb + pb * ld;
  2269. this.c = pc * la + pd * lc;
  2270. this.d = pc * lb + pd * ld;
  2271. return;
  2272. }
  2273. case spine.TransformMode.OnlyTranslation: {
  2274. var rotationY = rotation + 90 + shearY;
  2275. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2276. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2277. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2278. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2279. break;
  2280. }
  2281. case spine.TransformMode.NoRotationOrReflection: {
  2282. var s = pa * pa + pc * pc;
  2283. var prx = 0;
  2284. if (s > 0.0001) {
  2285. s = Math.abs(pa * pd - pb * pc) / s;
  2286. pb = pc * s;
  2287. pd = pa * s;
  2288. prx = Math.atan2(pc, pa) * spine.MathUtils.radDeg;
  2289. }
  2290. else {
  2291. pa = 0;
  2292. pc = 0;
  2293. prx = 90 - Math.atan2(pd, pb) * spine.MathUtils.radDeg;
  2294. }
  2295. var rx = rotation + shearX - prx;
  2296. var ry = rotation + shearY - prx + 90;
  2297. var la = spine.MathUtils.cosDeg(rx) * scaleX;
  2298. var lb = spine.MathUtils.cosDeg(ry) * scaleY;
  2299. var lc = spine.MathUtils.sinDeg(rx) * scaleX;
  2300. var ld = spine.MathUtils.sinDeg(ry) * scaleY;
  2301. this.a = pa * la - pb * lc;
  2302. this.b = pa * lb - pb * ld;
  2303. this.c = pc * la + pd * lc;
  2304. this.d = pc * lb + pd * ld;
  2305. break;
  2306. }
  2307. case spine.TransformMode.NoScale:
  2308. case spine.TransformMode.NoScaleOrReflection: {
  2309. var cos = spine.MathUtils.cosDeg(rotation);
  2310. var sin = spine.MathUtils.sinDeg(rotation);
  2311. var za = pa * cos + pb * sin;
  2312. var zc = pc * cos + pd * sin;
  2313. var s = Math.sqrt(za * za + zc * zc);
  2314. if (s > 0.00001)
  2315. s = 1 / s;
  2316. za *= s;
  2317. zc *= s;
  2318. s = Math.sqrt(za * za + zc * zc);
  2319. var r = Math.PI / 2 + Math.atan2(zc, za);
  2320. var zb = Math.cos(r) * s;
  2321. var zd = Math.sin(r) * s;
  2322. var la = spine.MathUtils.cosDeg(shearX) * scaleX;
  2323. var lb = spine.MathUtils.cosDeg(90 + shearY) * scaleY;
  2324. var lc = spine.MathUtils.sinDeg(shearX) * scaleX;
  2325. var ld = spine.MathUtils.sinDeg(90 + shearY) * scaleY;
  2326. if (this.data.transformMode != spine.TransformMode.NoScaleOrReflection ? pa * pd - pb * pc < 0 : this.skeleton.flipX != this.skeleton.flipY) {
  2327. zb = -zb;
  2328. zd = -zd;
  2329. }
  2330. this.a = za * la + zb * lc;
  2331. this.b = za * lb + zb * ld;
  2332. this.c = zc * la + zd * lc;
  2333. this.d = zc * lb + zd * ld;
  2334. return;
  2335. }
  2336. }
  2337. if (this.skeleton.flipX) {
  2338. this.a = -this.a;
  2339. this.b = -this.b;
  2340. }
  2341. if (this.skeleton.flipY) {
  2342. this.c = -this.c;
  2343. this.d = -this.d;
  2344. }
  2345. };
  2346. Bone.prototype.setToSetupPose = function () {
  2347. var data = this.data;
  2348. this.x = data.x;
  2349. this.y = data.y;
  2350. this.rotation = data.rotation;
  2351. this.scaleX = data.scaleX;
  2352. this.scaleY = data.scaleY;
  2353. this.shearX = data.shearX;
  2354. this.shearY = data.shearY;
  2355. };
  2356. Bone.prototype.getWorldRotationX = function () {
  2357. return Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2358. };
  2359. Bone.prototype.getWorldRotationY = function () {
  2360. return Math.atan2(this.d, this.b) * spine.MathUtils.radDeg;
  2361. };
  2362. Bone.prototype.getWorldScaleX = function () {
  2363. return Math.sqrt(this.a * this.a + this.c * this.c);
  2364. };
  2365. Bone.prototype.getWorldScaleY = function () {
  2366. return Math.sqrt(this.b * this.b + this.d * this.d);
  2367. };
  2368. Bone.prototype.updateAppliedTransform = function () {
  2369. this.appliedValid = true;
  2370. var parent = this.parent;
  2371. if (parent == null) {
  2372. this.ax = this.worldX;
  2373. this.ay = this.worldY;
  2374. this.arotation = Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2375. this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c);
  2376. this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d);
  2377. this.ashearX = 0;
  2378. this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * spine.MathUtils.radDeg;
  2379. return;
  2380. }
  2381. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2382. var pid = 1 / (pa * pd - pb * pc);
  2383. var dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY;
  2384. this.ax = (dx * pd * pid - dy * pb * pid);
  2385. this.ay = (dy * pa * pid - dx * pc * pid);
  2386. var ia = pid * pd;
  2387. var id = pid * pa;
  2388. var ib = pid * pb;
  2389. var ic = pid * pc;
  2390. var ra = ia * this.a - ib * this.c;
  2391. var rb = ia * this.b - ib * this.d;
  2392. var rc = id * this.c - ic * this.a;
  2393. var rd = id * this.d - ic * this.b;
  2394. this.ashearX = 0;
  2395. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  2396. if (this.ascaleX > 0.0001) {
  2397. var det = ra * rd - rb * rc;
  2398. this.ascaleY = det / this.ascaleX;
  2399. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * spine.MathUtils.radDeg;
  2400. this.arotation = Math.atan2(rc, ra) * spine.MathUtils.radDeg;
  2401. }
  2402. else {
  2403. this.ascaleX = 0;
  2404. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  2405. this.ashearY = 0;
  2406. this.arotation = 90 - Math.atan2(rd, rb) * spine.MathUtils.radDeg;
  2407. }
  2408. };
  2409. Bone.prototype.worldToLocal = function (world) {
  2410. var a = this.a, b = this.b, c = this.c, d = this.d;
  2411. var invDet = 1 / (a * d - b * c);
  2412. var x = world.x - this.worldX, y = world.y - this.worldY;
  2413. world.x = (x * d * invDet - y * b * invDet);
  2414. world.y = (y * a * invDet - x * c * invDet);
  2415. return world;
  2416. };
  2417. Bone.prototype.localToWorld = function (local) {
  2418. var x = local.x, y = local.y;
  2419. local.x = x * this.a + y * this.b + this.worldX;
  2420. local.y = x * this.c + y * this.d + this.worldY;
  2421. return local;
  2422. };
  2423. Bone.prototype.worldToLocalRotation = function (worldRotation) {
  2424. var sin = spine.MathUtils.sinDeg(worldRotation), cos = spine.MathUtils.cosDeg(worldRotation);
  2425. return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * spine.MathUtils.radDeg;
  2426. };
  2427. Bone.prototype.localToWorldRotation = function (localRotation) {
  2428. var sin = spine.MathUtils.sinDeg(localRotation), cos = spine.MathUtils.cosDeg(localRotation);
  2429. return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * spine.MathUtils.radDeg;
  2430. };
  2431. Bone.prototype.rotateWorld = function (degrees) {
  2432. var a = this.a, b = this.b, c = this.c, d = this.d;
  2433. var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
  2434. this.a = cos * a - sin * c;
  2435. this.b = cos * b - sin * d;
  2436. this.c = sin * a + cos * c;
  2437. this.d = sin * b + cos * d;
  2438. this.appliedValid = false;
  2439. };
  2440. return Bone;
  2441. }());
  2442. spine.Bone = Bone;
  2443. })(spine || (spine = {}));
  2444. var spine;
  2445. (function (spine) {
  2446. var BoneData = (function () {
  2447. function BoneData(index, name, parent) {
  2448. this.x = 0;
  2449. this.y = 0;
  2450. this.rotation = 0;
  2451. this.scaleX = 1;
  2452. this.scaleY = 1;
  2453. this.shearX = 0;
  2454. this.shearY = 0;
  2455. this.transformMode = TransformMode.Normal;
  2456. if (index < 0)
  2457. throw new Error("index must be >= 0.");
  2458. if (name == null)
  2459. throw new Error("name cannot be null.");
  2460. this.index = index;
  2461. this.name = name;
  2462. this.parent = parent;
  2463. }
  2464. return BoneData;
  2465. }());
  2466. spine.BoneData = BoneData;
  2467. var TransformMode;
  2468. (function (TransformMode) {
  2469. TransformMode[TransformMode["Normal"] = 0] = "Normal";
  2470. TransformMode[TransformMode["OnlyTranslation"] = 1] = "OnlyTranslation";
  2471. TransformMode[TransformMode["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
  2472. TransformMode[TransformMode["NoScale"] = 3] = "NoScale";
  2473. TransformMode[TransformMode["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
  2474. })(TransformMode = spine.TransformMode || (spine.TransformMode = {}));
  2475. })(spine || (spine = {}));
  2476. var spine;
  2477. (function (spine) {
  2478. var Event = (function () {
  2479. function Event(time, data) {
  2480. if (data == null)
  2481. throw new Error("data cannot be null.");
  2482. this.time = time;
  2483. this.data = data;
  2484. }
  2485. return Event;
  2486. }());
  2487. spine.Event = Event;
  2488. })(spine || (spine = {}));
  2489. var spine;
  2490. (function (spine) {
  2491. var EventData = (function () {
  2492. function EventData(name) {
  2493. this.name = name;
  2494. }
  2495. return EventData;
  2496. }());
  2497. spine.EventData = EventData;
  2498. })(spine || (spine = {}));
  2499. var spine;
  2500. (function (spine) {
  2501. var IkConstraint = (function () {
  2502. function IkConstraint(data, skeleton) {
  2503. this.mix = 1;
  2504. this.bendDirection = 0;
  2505. if (data == null)
  2506. throw new Error("data cannot be null.");
  2507. if (skeleton == null)
  2508. throw new Error("skeleton cannot be null.");
  2509. this.data = data;
  2510. this.mix = data.mix;
  2511. this.bendDirection = data.bendDirection;
  2512. this.bones = new Array();
  2513. for (var i = 0; i < data.bones.length; i++)
  2514. this.bones.push(skeleton.findBone(data.bones[i].name));
  2515. this.target = skeleton.findBone(data.target.name);
  2516. }
  2517. IkConstraint.prototype.getOrder = function () {
  2518. return this.data.order;
  2519. };
  2520. IkConstraint.prototype.apply = function () {
  2521. this.update();
  2522. };
  2523. IkConstraint.prototype.update = function () {
  2524. var target = this.target;
  2525. var bones = this.bones;
  2526. switch (bones.length) {
  2527. case 1:
  2528. this.apply1(bones[0], target.worldX, target.worldY, this.mix);
  2529. break;
  2530. case 2:
  2531. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.mix);
  2532. break;
  2533. }
  2534. };
  2535. IkConstraint.prototype.apply1 = function (bone, targetX, targetY, alpha) {
  2536. if (!bone.appliedValid)
  2537. bone.updateAppliedTransform();
  2538. var p = bone.parent;
  2539. var id = 1 / (p.a * p.d - p.b * p.c);
  2540. var x = targetX - p.worldX, y = targetY - p.worldY;
  2541. var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
  2542. var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
  2543. if (bone.ascaleX < 0)
  2544. rotationIK += 180;
  2545. if (rotationIK > 180)
  2546. rotationIK -= 360;
  2547. else if (rotationIK < -180)
  2548. rotationIK += 360;
  2549. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, bone.ascaleX, bone.ascaleY, bone.ashearX, bone.ashearY);
  2550. };
  2551. IkConstraint.prototype.apply2 = function (parent, child, targetX, targetY, bendDir, alpha) {
  2552. if (alpha == 0) {
  2553. child.updateWorldTransform();
  2554. return;
  2555. }
  2556. if (!parent.appliedValid)
  2557. parent.updateAppliedTransform();
  2558. if (!child.appliedValid)
  2559. child.updateAppliedTransform();
  2560. var px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, csx = child.ascaleX;
  2561. var os1 = 0, os2 = 0, s2 = 0;
  2562. if (psx < 0) {
  2563. psx = -psx;
  2564. os1 = 180;
  2565. s2 = -1;
  2566. }
  2567. else {
  2568. os1 = 0;
  2569. s2 = 1;
  2570. }
  2571. if (psy < 0) {
  2572. psy = -psy;
  2573. s2 = -s2;
  2574. }
  2575. if (csx < 0) {
  2576. csx = -csx;
  2577. os2 = 180;
  2578. }
  2579. else
  2580. os2 = 0;
  2581. var cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
  2582. var u = Math.abs(psx - psy) <= 0.0001;
  2583. if (!u) {
  2584. cy = 0;
  2585. cwx = a * cx + parent.worldX;
  2586. cwy = c * cx + parent.worldY;
  2587. }
  2588. else {
  2589. cy = child.ay;
  2590. cwx = a * cx + b * cy + parent.worldX;
  2591. cwy = c * cx + d * cy + parent.worldY;
  2592. }
  2593. var pp = parent.parent;
  2594. a = pp.a;
  2595. b = pp.b;
  2596. c = pp.c;
  2597. d = pp.d;
  2598. var id = 1 / (a * d - b * c), x = targetX - pp.worldX, y = targetY - pp.worldY;
  2599. var tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  2600. x = cwx - pp.worldX;
  2601. y = cwy - pp.worldY;
  2602. var dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  2603. var l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1 = 0, a2 = 0;
  2604. outer: if (u) {
  2605. l2 *= psx;
  2606. var cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  2607. if (cos < -1)
  2608. cos = -1;
  2609. else if (cos > 1)
  2610. cos = 1;
  2611. a2 = Math.acos(cos) * bendDir;
  2612. a = l1 + l2 * cos;
  2613. b = l2 * Math.sin(a2);
  2614. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  2615. }
  2616. else {
  2617. a = psx * l2;
  2618. b = psy * l2;
  2619. var aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = Math.atan2(ty, tx);
  2620. c = bb * l1 * l1 + aa * dd - aa * bb;
  2621. var c1 = -2 * bb * l1, c2 = bb - aa;
  2622. d = c1 * c1 - 4 * c2 * c;
  2623. if (d >= 0) {
  2624. var q = Math.sqrt(d);
  2625. if (c1 < 0)
  2626. q = -q;
  2627. q = -(c1 + q) / 2;
  2628. var r0 = q / c2, r1 = c / q;
  2629. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  2630. if (r * r <= dd) {
  2631. y = Math.sqrt(dd - r * r) * bendDir;
  2632. a1 = ta - Math.atan2(y, r);
  2633. a2 = Math.atan2(y / psy, (r - l1) / psx);
  2634. break outer;
  2635. }
  2636. }
  2637. var minAngle = spine.MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  2638. var maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  2639. c = -a * l1 / (aa - bb);
  2640. if (c >= -1 && c <= 1) {
  2641. c = Math.acos(c);
  2642. x = a * Math.cos(c) + l1;
  2643. y = b * Math.sin(c);
  2644. d = x * x + y * y;
  2645. if (d < minDist) {
  2646. minAngle = c;
  2647. minDist = d;
  2648. minX = x;
  2649. minY = y;
  2650. }
  2651. if (d > maxDist) {
  2652. maxAngle = c;
  2653. maxDist = d;
  2654. maxX = x;
  2655. maxY = y;
  2656. }
  2657. }
  2658. if (dd <= (minDist + maxDist) / 2) {
  2659. a1 = ta - Math.atan2(minY * bendDir, minX);
  2660. a2 = minAngle * bendDir;
  2661. }
  2662. else {
  2663. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  2664. a2 = maxAngle * bendDir;
  2665. }
  2666. }
  2667. var os = Math.atan2(cy, cx) * s2;
  2668. var rotation = parent.arotation;
  2669. a1 = (a1 - os) * spine.MathUtils.radDeg + os1 - rotation;
  2670. if (a1 > 180)
  2671. a1 -= 360;
  2672. else if (a1 < -180)
  2673. a1 += 360;
  2674. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, parent.ascaleX, parent.ascaleY, 0, 0);
  2675. rotation = child.arotation;
  2676. a2 = ((a2 + os) * spine.MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  2677. if (a2 > 180)
  2678. a2 -= 360;
  2679. else if (a2 < -180)
  2680. a2 += 360;
  2681. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  2682. };
  2683. return IkConstraint;
  2684. }());
  2685. spine.IkConstraint = IkConstraint;
  2686. })(spine || (spine = {}));
  2687. var spine;
  2688. (function (spine) {
  2689. var IkConstraintData = (function () {
  2690. function IkConstraintData(name) {
  2691. this.order = 0;
  2692. this.bones = new Array();
  2693. this.bendDirection = 1;
  2694. this.mix = 1;
  2695. this.name = name;
  2696. }
  2697. return IkConstraintData;
  2698. }());
  2699. spine.IkConstraintData = IkConstraintData;
  2700. })(spine || (spine = {}));
  2701. var spine;
  2702. (function (spine) {
  2703. var PathConstraint = (function () {
  2704. function PathConstraint(data, skeleton) {
  2705. this.position = 0;
  2706. this.spacing = 0;
  2707. this.rotateMix = 0;
  2708. this.translateMix = 0;
  2709. this.spaces = new Array();
  2710. this.positions = new Array();
  2711. this.world = new Array();
  2712. this.curves = new Array();
  2713. this.lengths = new Array();
  2714. this.segments = new Array();
  2715. if (data == null)
  2716. throw new Error("data cannot be null.");
  2717. if (skeleton == null)
  2718. throw new Error("skeleton cannot be null.");
  2719. this.data = data;
  2720. this.bones = new Array();
  2721. for (var i = 0, n = data.bones.length; i < n; i++)
  2722. this.bones.push(skeleton.findBone(data.bones[i].name));
  2723. this.target = skeleton.findSlot(data.target.name);
  2724. this.position = data.position;
  2725. this.spacing = data.spacing;
  2726. this.rotateMix = data.rotateMix;
  2727. this.translateMix = data.translateMix;
  2728. }
  2729. PathConstraint.prototype.apply = function () {
  2730. this.update();
  2731. };
  2732. PathConstraint.prototype.update = function () {
  2733. var attachment = this.target.getAttachment();
  2734. if (!(attachment instanceof spine.PathAttachment))
  2735. return;
  2736. var rotateMix = this.rotateMix, translateMix = this.translateMix;
  2737. var translate = translateMix > 0, rotate = rotateMix > 0;
  2738. if (!translate && !rotate)
  2739. return;
  2740. var data = this.data;
  2741. var spacingMode = data.spacingMode;
  2742. var lengthSpacing = spacingMode == spine.SpacingMode.Length;
  2743. var rotateMode = data.rotateMode;
  2744. var tangents = rotateMode == spine.RotateMode.Tangent, scale = rotateMode == spine.RotateMode.ChainScale;
  2745. var boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  2746. var bones = this.bones;
  2747. var spaces = spine.Utils.setArraySize(this.spaces, spacesCount), lengths = null;
  2748. var spacing = this.spacing;
  2749. if (scale || lengthSpacing) {
  2750. if (scale)
  2751. lengths = spine.Utils.setArraySize(this.lengths, boneCount);
  2752. for (var i = 0, n = spacesCount - 1; i < n;) {
  2753. var bone = bones[i];
  2754. var setupLength = bone.data.length;
  2755. if (setupLength < PathConstraint.epsilon) {
  2756. if (scale)
  2757. lengths[i] = 0;
  2758. spaces[++i] = 0;
  2759. }
  2760. else {
  2761. var x = setupLength * bone.a, y = setupLength * bone.c;
  2762. var length_1 = Math.sqrt(x * x + y * y);
  2763. if (scale)
  2764. lengths[i] = length_1;
  2765. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length_1 / setupLength;
  2766. }
  2767. }
  2768. }
  2769. else {
  2770. for (var i = 1; i < spacesCount; i++)
  2771. spaces[i] = spacing;
  2772. }
  2773. var positions = this.computeWorldPositions(attachment, spacesCount, tangents, data.positionMode == spine.PositionMode.Percent, spacingMode == spine.SpacingMode.Percent);
  2774. var boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  2775. var tip = false;
  2776. if (offsetRotation == 0)
  2777. tip = rotateMode == spine.RotateMode.Chain;
  2778. else {
  2779. tip = false;
  2780. var p = this.target.bone;
  2781. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  2782. }
  2783. for (var i = 0, p = 3; i < boneCount; i++, p += 3) {
  2784. var bone = bones[i];
  2785. bone.worldX += (boneX - bone.worldX) * translateMix;
  2786. bone.worldY += (boneY - bone.worldY) * translateMix;
  2787. var x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  2788. if (scale) {
  2789. var length_2 = lengths[i];
  2790. if (length_2 != 0) {
  2791. var s = (Math.sqrt(dx * dx + dy * dy) / length_2 - 1) * rotateMix + 1;
  2792. bone.a *= s;
  2793. bone.c *= s;
  2794. }
  2795. }
  2796. boneX = x;
  2797. boneY = y;
  2798. if (rotate) {
  2799. var a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
  2800. if (tangents)
  2801. r = positions[p - 1];
  2802. else if (spaces[i + 1] == 0)
  2803. r = positions[p + 2];
  2804. else
  2805. r = Math.atan2(dy, dx);
  2806. r -= Math.atan2(c, a);
  2807. if (tip) {
  2808. cos = Math.cos(r);
  2809. sin = Math.sin(r);
  2810. var length_3 = bone.data.length;
  2811. boneX += (length_3 * (cos * a - sin * c) - dx) * rotateMix;
  2812. boneY += (length_3 * (sin * a + cos * c) - dy) * rotateMix;
  2813. }
  2814. else {
  2815. r += offsetRotation;
  2816. }
  2817. if (r > spine.MathUtils.PI)
  2818. r -= spine.MathUtils.PI2;
  2819. else if (r < -spine.MathUtils.PI)
  2820. r += spine.MathUtils.PI2;
  2821. r *= rotateMix;
  2822. cos = Math.cos(r);
  2823. sin = Math.sin(r);
  2824. bone.a = cos * a - sin * c;
  2825. bone.b = cos * b - sin * d;
  2826. bone.c = sin * a + cos * c;
  2827. bone.d = sin * b + cos * d;
  2828. }
  2829. bone.appliedValid = false;
  2830. }
  2831. };
  2832. PathConstraint.prototype.computeWorldPositions = function (path, spacesCount, tangents, percentPosition, percentSpacing) {
  2833. var target = this.target;
  2834. var position = this.position;
  2835. var spaces = this.spaces, out = spine.Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  2836. var closed = path.closed;
  2837. var verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint.NONE;
  2838. if (!path.constantSpeed) {
  2839. var lengths = path.lengths;
  2840. curveCount -= closed ? 1 : 2;
  2841. var pathLength_1 = lengths[curveCount];
  2842. if (percentPosition)
  2843. position *= pathLength_1;
  2844. if (percentSpacing) {
  2845. for (var i = 0; i < spacesCount; i++)
  2846. spaces[i] *= pathLength_1;
  2847. }
  2848. world = spine.Utils.setArraySize(this.world, 8);
  2849. for (var i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  2850. var space = spaces[i];
  2851. position += space;
  2852. var p = position;
  2853. if (closed) {
  2854. p %= pathLength_1;
  2855. if (p < 0)
  2856. p += pathLength_1;
  2857. curve = 0;
  2858. }
  2859. else if (p < 0) {
  2860. if (prevCurve != PathConstraint.BEFORE) {
  2861. prevCurve = PathConstraint.BEFORE;
  2862. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  2863. }
  2864. this.addBeforePosition(p, world, 0, out, o);
  2865. continue;
  2866. }
  2867. else if (p > pathLength_1) {
  2868. if (prevCurve != PathConstraint.AFTER) {
  2869. prevCurve = PathConstraint.AFTER;
  2870. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  2871. }
  2872. this.addAfterPosition(p - pathLength_1, world, 0, out, o);
  2873. continue;
  2874. }
  2875. for (;; curve++) {
  2876. var length_4 = lengths[curve];
  2877. if (p > length_4)
  2878. continue;
  2879. if (curve == 0)
  2880. p /= length_4;
  2881. else {
  2882. var prev = lengths[curve - 1];
  2883. p = (p - prev) / (length_4 - prev);
  2884. }
  2885. break;
  2886. }
  2887. if (curve != prevCurve) {
  2888. prevCurve = curve;
  2889. if (closed && curve == curveCount) {
  2890. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  2891. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  2892. }
  2893. else
  2894. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  2895. }
  2896. 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));
  2897. }
  2898. return out;
  2899. }
  2900. if (closed) {
  2901. verticesLength += 2;
  2902. world = spine.Utils.setArraySize(this.world, verticesLength);
  2903. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  2904. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  2905. world[verticesLength - 2] = world[0];
  2906. world[verticesLength - 1] = world[1];
  2907. }
  2908. else {
  2909. curveCount--;
  2910. verticesLength -= 4;
  2911. world = spine.Utils.setArraySize(this.world, verticesLength);
  2912. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  2913. }
  2914. var curves = spine.Utils.setArraySize(this.curves, curveCount);
  2915. var pathLength = 0;
  2916. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  2917. var tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  2918. for (var i = 0, w = 2; i < curveCount; i++, w += 6) {
  2919. cx1 = world[w];
  2920. cy1 = world[w + 1];
  2921. cx2 = world[w + 2];
  2922. cy2 = world[w + 3];
  2923. x2 = world[w + 4];
  2924. y2 = world[w + 5];
  2925. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  2926. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  2927. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  2928. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  2929. ddfx = tmpx * 2 + dddfx;
  2930. ddfy = tmpy * 2 + dddfy;
  2931. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  2932. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  2933. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2934. dfx += ddfx;
  2935. dfy += ddfy;
  2936. ddfx += dddfx;
  2937. ddfy += dddfy;
  2938. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2939. dfx += ddfx;
  2940. dfy += ddfy;
  2941. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2942. dfx += ddfx + dddfx;
  2943. dfy += ddfy + dddfy;
  2944. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2945. curves[i] = pathLength;
  2946. x1 = x2;
  2947. y1 = y2;
  2948. }
  2949. if (percentPosition)
  2950. position *= pathLength;
  2951. if (percentSpacing) {
  2952. for (var i = 0; i < spacesCount; i++)
  2953. spaces[i] *= pathLength;
  2954. }
  2955. var segments = this.segments;
  2956. var curveLength = 0;
  2957. for (var i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  2958. var space = spaces[i];
  2959. position += space;
  2960. var p = position;
  2961. if (closed) {
  2962. p %= pathLength;
  2963. if (p < 0)
  2964. p += pathLength;
  2965. curve = 0;
  2966. }
  2967. else if (p < 0) {
  2968. this.addBeforePosition(p, world, 0, out, o);
  2969. continue;
  2970. }
  2971. else if (p > pathLength) {
  2972. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  2973. continue;
  2974. }
  2975. for (;; curve++) {
  2976. var length_5 = curves[curve];
  2977. if (p > length_5)
  2978. continue;
  2979. if (curve == 0)
  2980. p /= length_5;
  2981. else {
  2982. var prev = curves[curve - 1];
  2983. p = (p - prev) / (length_5 - prev);
  2984. }
  2985. break;
  2986. }
  2987. if (curve != prevCurve) {
  2988. prevCurve = curve;
  2989. var ii = curve * 6;
  2990. x1 = world[ii];
  2991. y1 = world[ii + 1];
  2992. cx1 = world[ii + 2];
  2993. cy1 = world[ii + 3];
  2994. cx2 = world[ii + 4];
  2995. cy2 = world[ii + 5];
  2996. x2 = world[ii + 6];
  2997. y2 = world[ii + 7];
  2998. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  2999. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  3000. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  3001. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  3002. ddfx = tmpx * 2 + dddfx;
  3003. ddfy = tmpy * 2 + dddfy;
  3004. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  3005. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  3006. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  3007. segments[0] = curveLength;
  3008. for (ii = 1; ii < 8; ii++) {
  3009. dfx += ddfx;
  3010. dfy += ddfy;
  3011. ddfx += dddfx;
  3012. ddfy += dddfy;
  3013. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3014. segments[ii] = curveLength;
  3015. }
  3016. dfx += ddfx;
  3017. dfy += ddfy;
  3018. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3019. segments[8] = curveLength;
  3020. dfx += ddfx + dddfx;
  3021. dfy += ddfy + dddfy;
  3022. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3023. segments[9] = curveLength;
  3024. segment = 0;
  3025. }
  3026. p *= curveLength;
  3027. for (;; segment++) {
  3028. var length_6 = segments[segment];
  3029. if (p > length_6)
  3030. continue;
  3031. if (segment == 0)
  3032. p /= length_6;
  3033. else {
  3034. var prev = segments[segment - 1];
  3035. p = segment + (p - prev) / (length_6 - prev);
  3036. }
  3037. break;
  3038. }
  3039. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  3040. }
  3041. return out;
  3042. };
  3043. PathConstraint.prototype.addBeforePosition = function (p, temp, i, out, o) {
  3044. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  3045. out[o] = x1 + p * Math.cos(r);
  3046. out[o + 1] = y1 + p * Math.sin(r);
  3047. out[o + 2] = r;
  3048. };
  3049. PathConstraint.prototype.addAfterPosition = function (p, temp, i, out, o) {
  3050. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  3051. out[o] = x1 + p * Math.cos(r);
  3052. out[o + 1] = y1 + p * Math.sin(r);
  3053. out[o + 2] = r;
  3054. };
  3055. PathConstraint.prototype.addCurvePosition = function (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  3056. if (p == 0 || isNaN(p))
  3057. p = 0.0001;
  3058. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  3059. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  3060. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  3061. out[o] = x;
  3062. out[o + 1] = y;
  3063. if (tangents)
  3064. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  3065. };
  3066. PathConstraint.prototype.getOrder = function () {
  3067. return this.data.order;
  3068. };
  3069. PathConstraint.NONE = -1;
  3070. PathConstraint.BEFORE = -2;
  3071. PathConstraint.AFTER = -3;
  3072. PathConstraint.epsilon = 0.00001;
  3073. return PathConstraint;
  3074. }());
  3075. spine.PathConstraint = PathConstraint;
  3076. })(spine || (spine = {}));
  3077. var spine;
  3078. (function (spine) {
  3079. var PathConstraintData = (function () {
  3080. function PathConstraintData(name) {
  3081. this.order = 0;
  3082. this.bones = new Array();
  3083. this.name = name;
  3084. }
  3085. return PathConstraintData;
  3086. }());
  3087. spine.PathConstraintData = PathConstraintData;
  3088. var PositionMode;
  3089. (function (PositionMode) {
  3090. PositionMode[PositionMode["Fixed"] = 0] = "Fixed";
  3091. PositionMode[PositionMode["Percent"] = 1] = "Percent";
  3092. })(PositionMode = spine.PositionMode || (spine.PositionMode = {}));
  3093. var SpacingMode;
  3094. (function (SpacingMode) {
  3095. SpacingMode[SpacingMode["Length"] = 0] = "Length";
  3096. SpacingMode[SpacingMode["Fixed"] = 1] = "Fixed";
  3097. SpacingMode[SpacingMode["Percent"] = 2] = "Percent";
  3098. })(SpacingMode = spine.SpacingMode || (spine.SpacingMode = {}));
  3099. var RotateMode;
  3100. (function (RotateMode) {
  3101. RotateMode[RotateMode["Tangent"] = 0] = "Tangent";
  3102. RotateMode[RotateMode["Chain"] = 1] = "Chain";
  3103. RotateMode[RotateMode["ChainScale"] = 2] = "ChainScale";
  3104. })(RotateMode = spine.RotateMode || (spine.RotateMode = {}));
  3105. })(spine || (spine = {}));
  3106. var spine;
  3107. (function (spine) {
  3108. var Assets = (function () {
  3109. function Assets(clientId) {
  3110. this.toLoad = new Array();
  3111. this.assets = {};
  3112. this.clientId = clientId;
  3113. }
  3114. Assets.prototype.loaded = function () {
  3115. var i = 0;
  3116. for (var v in this.assets)
  3117. i++;
  3118. return i;
  3119. };
  3120. return Assets;
  3121. }());
  3122. var SharedAssetManager = (function () {
  3123. function SharedAssetManager(pathPrefix) {
  3124. if (pathPrefix === void 0) { pathPrefix = ""; }
  3125. this.clientAssets = {};
  3126. this.queuedAssets = {};
  3127. this.rawAssets = {};
  3128. this.errors = {};
  3129. this.pathPrefix = pathPrefix;
  3130. }
  3131. SharedAssetManager.prototype.queueAsset = function (clientId, textureLoader, path) {
  3132. var clientAssets = this.clientAssets[clientId];
  3133. if (clientAssets === null || clientAssets === undefined) {
  3134. clientAssets = new Assets(clientId);
  3135. this.clientAssets[clientId] = clientAssets;
  3136. }
  3137. if (textureLoader !== null)
  3138. clientAssets.textureLoader = textureLoader;
  3139. clientAssets.toLoad.push(path);
  3140. if (this.queuedAssets[path] === path) {
  3141. return false;
  3142. }
  3143. else {
  3144. this.queuedAssets[path] = path;
  3145. return true;
  3146. }
  3147. };
  3148. SharedAssetManager.prototype.loadText = function (clientId, path) {
  3149. var _this = this;
  3150. path = this.pathPrefix + path;
  3151. if (!this.queueAsset(clientId, null, path))
  3152. return;
  3153. var request = new XMLHttpRequest();
  3154. request.onreadystatechange = function () {
  3155. if (request.readyState == XMLHttpRequest.DONE) {
  3156. if (request.status >= 200 && request.status < 300) {
  3157. _this.rawAssets[path] = request.responseText;
  3158. }
  3159. else {
  3160. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3161. }
  3162. }
  3163. };
  3164. request.open("GET", path, true);
  3165. request.send();
  3166. };
  3167. SharedAssetManager.prototype.loadJson = function (clientId, path) {
  3168. var _this = this;
  3169. path = this.pathPrefix + path;
  3170. if (!this.queueAsset(clientId, null, path))
  3171. return;
  3172. var request = new XMLHttpRequest();
  3173. request.onreadystatechange = function () {
  3174. if (request.readyState == XMLHttpRequest.DONE) {
  3175. if (request.status >= 200 && request.status < 300) {
  3176. _this.rawAssets[path] = JSON.parse(request.responseText);
  3177. }
  3178. else {
  3179. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3180. }
  3181. }
  3182. };
  3183. request.open("GET", path, true);
  3184. request.send();
  3185. };
  3186. SharedAssetManager.prototype.loadTexture = function (clientId, textureLoader, path) {
  3187. var _this = this;
  3188. path = this.pathPrefix + path;
  3189. if (!this.queueAsset(clientId, textureLoader, path))
  3190. return;
  3191. var img = new Image();
  3192. img.src = path;
  3193. img.crossOrigin = "anonymous";
  3194. img.onload = function (ev) {
  3195. _this.rawAssets[path] = img;
  3196. };
  3197. img.onerror = function (ev) {
  3198. _this.errors[path] = "Couldn't load image " + path;
  3199. };
  3200. };
  3201. SharedAssetManager.prototype.get = function (clientId, path) {
  3202. path = this.pathPrefix + path;
  3203. var clientAssets = this.clientAssets[clientId];
  3204. if (clientAssets === null || clientAssets === undefined)
  3205. return true;
  3206. return clientAssets.assets[path];
  3207. };
  3208. SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
  3209. for (var i = 0; i < clientAssets.toLoad.length; i++) {
  3210. var path = clientAssets.toLoad[i];
  3211. var asset = clientAssets.assets[path];
  3212. if (asset === null || asset === undefined) {
  3213. var rawAsset = this.rawAssets[path];
  3214. if (rawAsset === null || rawAsset === undefined)
  3215. continue;
  3216. if (rawAsset instanceof HTMLImageElement) {
  3217. clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
  3218. }
  3219. else {
  3220. clientAssets.assets[path] = rawAsset;
  3221. }
  3222. }
  3223. }
  3224. };
  3225. SharedAssetManager.prototype.isLoadingComplete = function (clientId) {
  3226. var clientAssets = this.clientAssets[clientId];
  3227. if (clientAssets === null || clientAssets === undefined)
  3228. return true;
  3229. this.updateClientAssets(clientAssets);
  3230. return clientAssets.toLoad.length == clientAssets.loaded();
  3231. };
  3232. SharedAssetManager.prototype.dispose = function () {
  3233. };
  3234. SharedAssetManager.prototype.hasErrors = function () {
  3235. return Object.keys(this.errors).length > 0;
  3236. };
  3237. SharedAssetManager.prototype.getErrors = function () {
  3238. return this.errors;
  3239. };
  3240. return SharedAssetManager;
  3241. }());
  3242. spine.SharedAssetManager = SharedAssetManager;
  3243. })(spine || (spine = {}));
  3244. var spine;
  3245. (function (spine) {
  3246. var Skeleton = (function () {
  3247. function Skeleton(data) {
  3248. this._updateCache = new Array();
  3249. this.updateCacheReset = new Array();
  3250. this.time = 0;
  3251. this.flipX = false;
  3252. this.flipY = false;
  3253. this.x = 0;
  3254. this.y = 0;
  3255. if (data == null)
  3256. throw new Error("data cannot be null.");
  3257. this.data = data;
  3258. this.bones = new Array();
  3259. for (var i = 0; i < data.bones.length; i++) {
  3260. var boneData = data.bones[i];
  3261. var bone = void 0;
  3262. if (boneData.parent == null)
  3263. bone = new spine.Bone(boneData, this, null);
  3264. else {
  3265. var parent_1 = this.bones[boneData.parent.index];
  3266. bone = new spine.Bone(boneData, this, parent_1);
  3267. parent_1.children.push(bone);
  3268. }
  3269. this.bones.push(bone);
  3270. }
  3271. this.slots = new Array();
  3272. this.drawOrder = new Array();
  3273. for (var i = 0; i < data.slots.length; i++) {
  3274. var slotData = data.slots[i];
  3275. var bone = this.bones[slotData.boneData.index];
  3276. var slot = new spine.Slot(slotData, bone);
  3277. this.slots.push(slot);
  3278. this.drawOrder.push(slot);
  3279. }
  3280. this.ikConstraints = new Array();
  3281. for (var i = 0; i < data.ikConstraints.length; i++) {
  3282. var ikConstraintData = data.ikConstraints[i];
  3283. this.ikConstraints.push(new spine.IkConstraint(ikConstraintData, this));
  3284. }
  3285. this.transformConstraints = new Array();
  3286. for (var i = 0; i < data.transformConstraints.length; i++) {
  3287. var transformConstraintData = data.transformConstraints[i];
  3288. this.transformConstraints.push(new spine.TransformConstraint(transformConstraintData, this));
  3289. }
  3290. this.pathConstraints = new Array();
  3291. for (var i = 0; i < data.pathConstraints.length; i++) {
  3292. var pathConstraintData = data.pathConstraints[i];
  3293. this.pathConstraints.push(new spine.PathConstraint(pathConstraintData, this));
  3294. }
  3295. this.color = new spine.Color(1, 1, 1, 1);
  3296. this.updateCache();
  3297. }
  3298. Skeleton.prototype.updateCache = function () {
  3299. var updateCache = this._updateCache;
  3300. updateCache.length = 0;
  3301. this.updateCacheReset.length = 0;
  3302. var bones = this.bones;
  3303. for (var i = 0, n = bones.length; i < n; i++)
  3304. bones[i].sorted = false;
  3305. var ikConstraints = this.ikConstraints;
  3306. var transformConstraints = this.transformConstraints;
  3307. var pathConstraints = this.pathConstraints;
  3308. var ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  3309. var constraintCount = ikCount + transformCount + pathCount;
  3310. outer: for (var i = 0; i < constraintCount; i++) {
  3311. for (var ii = 0; ii < ikCount; ii++) {
  3312. var constraint = ikConstraints[ii];
  3313. if (constraint.data.order == i) {
  3314. this.sortIkConstraint(constraint);
  3315. continue outer;
  3316. }
  3317. }
  3318. for (var ii = 0; ii < transformCount; ii++) {
  3319. var constraint = transformConstraints[ii];
  3320. if (constraint.data.order == i) {
  3321. this.sortTransformConstraint(constraint);
  3322. continue outer;
  3323. }
  3324. }
  3325. for (var ii = 0; ii < pathCount; ii++) {
  3326. var constraint = pathConstraints[ii];
  3327. if (constraint.data.order == i) {
  3328. this.sortPathConstraint(constraint);
  3329. continue outer;
  3330. }
  3331. }
  3332. }
  3333. for (var i = 0, n = bones.length; i < n; i++)
  3334. this.sortBone(bones[i]);
  3335. };
  3336. Skeleton.prototype.sortIkConstraint = function (constraint) {
  3337. var target = constraint.target;
  3338. this.sortBone(target);
  3339. var constrained = constraint.bones;
  3340. var parent = constrained[0];
  3341. this.sortBone(parent);
  3342. if (constrained.length > 1) {
  3343. var child = constrained[constrained.length - 1];
  3344. if (!(this._updateCache.indexOf(child) > -1))
  3345. this.updateCacheReset.push(child);
  3346. }
  3347. this._updateCache.push(constraint);
  3348. this.sortReset(parent.children);
  3349. constrained[constrained.length - 1].sorted = true;
  3350. };
  3351. Skeleton.prototype.sortPathConstraint = function (constraint) {
  3352. var slot = constraint.target;
  3353. var slotIndex = slot.data.index;
  3354. var slotBone = slot.bone;
  3355. if (this.skin != null)
  3356. this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  3357. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  3358. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  3359. for (var i = 0, n = this.data.skins.length; i < n; i++)
  3360. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  3361. var attachment = slot.getAttachment();
  3362. if (attachment instanceof spine.PathAttachment)
  3363. this.sortPathConstraintAttachmentWith(attachment, slotBone);
  3364. var constrained = constraint.bones;
  3365. var boneCount = constrained.length;
  3366. for (var i = 0; i < boneCount; i++)
  3367. this.sortBone(constrained[i]);
  3368. this._updateCache.push(constraint);
  3369. for (var i = 0; i < boneCount; i++)
  3370. this.sortReset(constrained[i].children);
  3371. for (var i = 0; i < boneCount; i++)
  3372. constrained[i].sorted = true;
  3373. };
  3374. Skeleton.prototype.sortTransformConstraint = function (constraint) {
  3375. this.sortBone(constraint.target);
  3376. var constrained = constraint.bones;
  3377. var boneCount = constrained.length;
  3378. if (constraint.data.local) {
  3379. for (var i = 0; i < boneCount; i++) {
  3380. var child = constrained[i];
  3381. this.sortBone(child.parent);
  3382. if (!(this._updateCache.indexOf(child) > -1))
  3383. this.updateCacheReset.push(child);
  3384. }
  3385. }
  3386. else {
  3387. for (var i = 0; i < boneCount; i++) {
  3388. this.sortBone(constrained[i]);
  3389. }
  3390. }
  3391. this._updateCache.push(constraint);
  3392. for (var ii = 0; ii < boneCount; ii++)
  3393. this.sortReset(constrained[ii].children);
  3394. for (var ii = 0; ii < boneCount; ii++)
  3395. constrained[ii].sorted = true;
  3396. };
  3397. Skeleton.prototype.sortPathConstraintAttachment = function (skin, slotIndex, slotBone) {
  3398. var attachments = skin.attachments[slotIndex];
  3399. if (!attachments)
  3400. return;
  3401. for (var key in attachments) {
  3402. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  3403. }
  3404. };
  3405. Skeleton.prototype.sortPathConstraintAttachmentWith = function (attachment, slotBone) {
  3406. if (!(attachment instanceof spine.PathAttachment))
  3407. return;
  3408. var pathBones = attachment.bones;
  3409. if (pathBones == null)
  3410. this.sortBone(slotBone);
  3411. else {
  3412. var bones = this.bones;
  3413. var i = 0;
  3414. while (i < pathBones.length) {
  3415. var boneCount = pathBones[i++];
  3416. for (var n = i + boneCount; i < n; i++) {
  3417. var boneIndex = pathBones[i];
  3418. this.sortBone(bones[boneIndex]);
  3419. }
  3420. }
  3421. }
  3422. };
  3423. Skeleton.prototype.sortBone = function (bone) {
  3424. if (bone.sorted)
  3425. return;
  3426. var parent = bone.parent;
  3427. if (parent != null)
  3428. this.sortBone(parent);
  3429. bone.sorted = true;
  3430. this._updateCache.push(bone);
  3431. };
  3432. Skeleton.prototype.sortReset = function (bones) {
  3433. for (var i = 0, n = bones.length; i < n; i++) {
  3434. var bone = bones[i];
  3435. if (bone.sorted)
  3436. this.sortReset(bone.children);
  3437. bone.sorted = false;
  3438. }
  3439. };
  3440. Skeleton.prototype.updateWorldTransform = function () {
  3441. var updateCacheReset = this.updateCacheReset;
  3442. for (var i = 0, n = updateCacheReset.length; i < n; i++) {
  3443. var bone = updateCacheReset[i];
  3444. bone.ax = bone.x;
  3445. bone.ay = bone.y;
  3446. bone.arotation = bone.rotation;
  3447. bone.ascaleX = bone.scaleX;
  3448. bone.ascaleY = bone.scaleY;
  3449. bone.ashearX = bone.shearX;
  3450. bone.ashearY = bone.shearY;
  3451. bone.appliedValid = true;
  3452. }
  3453. var updateCache = this._updateCache;
  3454. for (var i = 0, n = updateCache.length; i < n; i++)
  3455. updateCache[i].update();
  3456. };
  3457. Skeleton.prototype.setToSetupPose = function () {
  3458. this.setBonesToSetupPose();
  3459. this.setSlotsToSetupPose();
  3460. };
  3461. Skeleton.prototype.setBonesToSetupPose = function () {
  3462. var bones = this.bones;
  3463. for (var i = 0, n = bones.length; i < n; i++)
  3464. bones[i].setToSetupPose();
  3465. var ikConstraints = this.ikConstraints;
  3466. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  3467. var constraint = ikConstraints[i];
  3468. constraint.bendDirection = constraint.data.bendDirection;
  3469. constraint.mix = constraint.data.mix;
  3470. }
  3471. var transformConstraints = this.transformConstraints;
  3472. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  3473. var constraint = transformConstraints[i];
  3474. var data = constraint.data;
  3475. constraint.rotateMix = data.rotateMix;
  3476. constraint.translateMix = data.translateMix;
  3477. constraint.scaleMix = data.scaleMix;
  3478. constraint.shearMix = data.shearMix;
  3479. }
  3480. var pathConstraints = this.pathConstraints;
  3481. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  3482. var constraint = pathConstraints[i];
  3483. var data = constraint.data;
  3484. constraint.position = data.position;
  3485. constraint.spacing = data.spacing;
  3486. constraint.rotateMix = data.rotateMix;
  3487. constraint.translateMix = data.translateMix;
  3488. }
  3489. };
  3490. Skeleton.prototype.setSlotsToSetupPose = function () {
  3491. var slots = this.slots;
  3492. spine.Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  3493. for (var i = 0, n = slots.length; i < n; i++)
  3494. slots[i].setToSetupPose();
  3495. };
  3496. Skeleton.prototype.getRootBone = function () {
  3497. if (this.bones.length == 0)
  3498. return null;
  3499. return this.bones[0];
  3500. };
  3501. Skeleton.prototype.findBone = function (boneName) {
  3502. if (boneName == null)
  3503. throw new Error("boneName cannot be null.");
  3504. var bones = this.bones;
  3505. for (var i = 0, n = bones.length; i < n; i++) {
  3506. var bone = bones[i];
  3507. if (bone.data.name == boneName)
  3508. return bone;
  3509. }
  3510. return null;
  3511. };
  3512. Skeleton.prototype.findBoneIndex = function (boneName) {
  3513. if (boneName == null)
  3514. throw new Error("boneName cannot be null.");
  3515. var bones = this.bones;
  3516. for (var i = 0, n = bones.length; i < n; i++)
  3517. if (bones[i].data.name == boneName)
  3518. return i;
  3519. return -1;
  3520. };
  3521. Skeleton.prototype.findSlot = function (slotName) {
  3522. if (slotName == null)
  3523. throw new Error("slotName cannot be null.");
  3524. var slots = this.slots;
  3525. for (var i = 0, n = slots.length; i < n; i++) {
  3526. var slot = slots[i];
  3527. if (slot.data.name == slotName)
  3528. return slot;
  3529. }
  3530. return null;
  3531. };
  3532. Skeleton.prototype.findSlotIndex = function (slotName) {
  3533. if (slotName == null)
  3534. throw new Error("slotName cannot be null.");
  3535. var slots = this.slots;
  3536. for (var i = 0, n = slots.length; i < n; i++)
  3537. if (slots[i].data.name == slotName)
  3538. return i;
  3539. return -1;
  3540. };
  3541. Skeleton.prototype.setSkinByName = function (skinName) {
  3542. var skin = this.data.findSkin(skinName);
  3543. if (skin == null)
  3544. throw new Error("Skin not found: " + skinName);
  3545. this.setSkin(skin);
  3546. };
  3547. Skeleton.prototype.setSkin = function (newSkin) {
  3548. if (newSkin != null) {
  3549. if (this.skin != null)
  3550. newSkin.attachAll(this, this.skin);
  3551. else {
  3552. var slots = this.slots;
  3553. for (var i = 0, n = slots.length; i < n; i++) {
  3554. var slot = slots[i];
  3555. var name_1 = slot.data.attachmentName;
  3556. if (name_1 != null) {
  3557. var attachment = newSkin.getAttachment(i, name_1);
  3558. if (attachment != null)
  3559. slot.setAttachment(attachment);
  3560. }
  3561. }
  3562. }
  3563. }
  3564. this.skin = newSkin;
  3565. };
  3566. Skeleton.prototype.getAttachmentByName = function (slotName, attachmentName) {
  3567. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  3568. };
  3569. Skeleton.prototype.getAttachment = function (slotIndex, attachmentName) {
  3570. if (attachmentName == null)
  3571. throw new Error("attachmentName cannot be null.");
  3572. if (this.skin != null) {
  3573. var attachment = this.skin.getAttachment(slotIndex, attachmentName);
  3574. if (attachment != null)
  3575. return attachment;
  3576. }
  3577. if (this.data.defaultSkin != null)
  3578. return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  3579. return null;
  3580. };
  3581. Skeleton.prototype.setAttachment = function (slotName, attachmentName) {
  3582. if (slotName == null)
  3583. throw new Error("slotName cannot be null.");
  3584. var slots = this.slots;
  3585. for (var i = 0, n = slots.length; i < n; i++) {
  3586. var slot = slots[i];
  3587. if (slot.data.name == slotName) {
  3588. var attachment = null;
  3589. if (attachmentName != null) {
  3590. attachment = this.getAttachment(i, attachmentName);
  3591. if (attachment == null)
  3592. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  3593. }
  3594. slot.setAttachment(attachment);
  3595. return;
  3596. }
  3597. }
  3598. throw new Error("Slot not found: " + slotName);
  3599. };
  3600. Skeleton.prototype.findIkConstraint = function (constraintName) {
  3601. if (constraintName == null)
  3602. throw new Error("constraintName cannot be null.");
  3603. var ikConstraints = this.ikConstraints;
  3604. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  3605. var ikConstraint = ikConstraints[i];
  3606. if (ikConstraint.data.name == constraintName)
  3607. return ikConstraint;
  3608. }
  3609. return null;
  3610. };
  3611. Skeleton.prototype.findTransformConstraint = function (constraintName) {
  3612. if (constraintName == null)
  3613. throw new Error("constraintName cannot be null.");
  3614. var transformConstraints = this.transformConstraints;
  3615. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  3616. var constraint = transformConstraints[i];
  3617. if (constraint.data.name == constraintName)
  3618. return constraint;
  3619. }
  3620. return null;
  3621. };
  3622. Skeleton.prototype.findPathConstraint = function (constraintName) {
  3623. if (constraintName == null)
  3624. throw new Error("constraintName cannot be null.");
  3625. var pathConstraints = this.pathConstraints;
  3626. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  3627. var constraint = pathConstraints[i];
  3628. if (constraint.data.name == constraintName)
  3629. return constraint;
  3630. }
  3631. return null;
  3632. };
  3633. Skeleton.prototype.getBounds = function (offset, size, temp) {
  3634. if (offset == null)
  3635. throw new Error("offset cannot be null.");
  3636. if (size == null)
  3637. throw new Error("size cannot be null.");
  3638. var drawOrder = this.drawOrder;
  3639. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  3640. for (var i = 0, n = drawOrder.length; i < n; i++) {
  3641. var slot = drawOrder[i];
  3642. var verticesLength = 0;
  3643. var vertices = null;
  3644. var attachment = slot.getAttachment();
  3645. if (attachment instanceof spine.RegionAttachment) {
  3646. verticesLength = 8;
  3647. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  3648. attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  3649. }
  3650. else if (attachment instanceof spine.MeshAttachment) {
  3651. var mesh = attachment;
  3652. verticesLength = mesh.worldVerticesLength;
  3653. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  3654. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  3655. }
  3656. if (vertices != null) {
  3657. for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  3658. var x = vertices[ii], y = vertices[ii + 1];
  3659. minX = Math.min(minX, x);
  3660. minY = Math.min(minY, y);
  3661. maxX = Math.max(maxX, x);
  3662. maxY = Math.max(maxY, y);
  3663. }
  3664. }
  3665. }
  3666. offset.set(minX, minY);
  3667. size.set(maxX - minX, maxY - minY);
  3668. };
  3669. Skeleton.prototype.update = function (delta) {
  3670. this.time += delta;
  3671. };
  3672. return Skeleton;
  3673. }());
  3674. spine.Skeleton = Skeleton;
  3675. })(spine || (spine = {}));
  3676. var spine;
  3677. (function (spine) {
  3678. var SkeletonBounds = (function () {
  3679. function SkeletonBounds() {
  3680. this.minX = 0;
  3681. this.minY = 0;
  3682. this.maxX = 0;
  3683. this.maxY = 0;
  3684. this.boundingBoxes = new Array();
  3685. this.polygons = new Array();
  3686. this.polygonPool = new spine.Pool(function () {
  3687. return spine.Utils.newFloatArray(16);
  3688. });
  3689. }
  3690. SkeletonBounds.prototype.update = function (skeleton, updateAabb) {
  3691. if (skeleton == null)
  3692. throw new Error("skeleton cannot be null.");
  3693. var boundingBoxes = this.boundingBoxes;
  3694. var polygons = this.polygons;
  3695. var polygonPool = this.polygonPool;
  3696. var slots = skeleton.slots;
  3697. var slotCount = slots.length;
  3698. boundingBoxes.length = 0;
  3699. polygonPool.freeAll(polygons);
  3700. polygons.length = 0;
  3701. for (var i = 0; i < slotCount; i++) {
  3702. var slot = slots[i];
  3703. var attachment = slot.getAttachment();
  3704. if (attachment instanceof spine.BoundingBoxAttachment) {
  3705. var boundingBox = attachment;
  3706. boundingBoxes.push(boundingBox);
  3707. var polygon = polygonPool.obtain();
  3708. if (polygon.length != boundingBox.worldVerticesLength) {
  3709. polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength);
  3710. }
  3711. polygons.push(polygon);
  3712. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  3713. }
  3714. }
  3715. if (updateAabb) {
  3716. this.aabbCompute();
  3717. }
  3718. else {
  3719. this.minX = Number.POSITIVE_INFINITY;
  3720. this.minY = Number.POSITIVE_INFINITY;
  3721. this.maxX = Number.NEGATIVE_INFINITY;
  3722. this.maxY = Number.NEGATIVE_INFINITY;
  3723. }
  3724. };
  3725. SkeletonBounds.prototype.aabbCompute = function () {
  3726. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  3727. var polygons = this.polygons;
  3728. for (var i = 0, n = polygons.length; i < n; i++) {
  3729. var polygon = polygons[i];
  3730. var vertices = polygon;
  3731. for (var ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  3732. var x = vertices[ii];
  3733. var y = vertices[ii + 1];
  3734. minX = Math.min(minX, x);
  3735. minY = Math.min(minY, y);
  3736. maxX = Math.max(maxX, x);
  3737. maxY = Math.max(maxY, y);
  3738. }
  3739. }
  3740. this.minX = minX;
  3741. this.minY = minY;
  3742. this.maxX = maxX;
  3743. this.maxY = maxY;
  3744. };
  3745. SkeletonBounds.prototype.aabbContainsPoint = function (x, y) {
  3746. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  3747. };
  3748. SkeletonBounds.prototype.aabbIntersectsSegment = function (x1, y1, x2, y2) {
  3749. var minX = this.minX;
  3750. var minY = this.minY;
  3751. var maxX = this.maxX;
  3752. var maxY = this.maxY;
  3753. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  3754. return false;
  3755. var m = (y2 - y1) / (x2 - x1);
  3756. var y = m * (minX - x1) + y1;
  3757. if (y > minY && y < maxY)
  3758. return true;
  3759. y = m * (maxX - x1) + y1;
  3760. if (y > minY && y < maxY)
  3761. return true;
  3762. var x = (minY - y1) / m + x1;
  3763. if (x > minX && x < maxX)
  3764. return true;
  3765. x = (maxY - y1) / m + x1;
  3766. if (x > minX && x < maxX)
  3767. return true;
  3768. return false;
  3769. };
  3770. SkeletonBounds.prototype.aabbIntersectsSkeleton = function (bounds) {
  3771. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  3772. };
  3773. SkeletonBounds.prototype.containsPoint = function (x, y) {
  3774. var polygons = this.polygons;
  3775. for (var i = 0, n = polygons.length; i < n; i++)
  3776. if (this.containsPointPolygon(polygons[i], x, y))
  3777. return this.boundingBoxes[i];
  3778. return null;
  3779. };
  3780. SkeletonBounds.prototype.containsPointPolygon = function (polygon, x, y) {
  3781. var vertices = polygon;
  3782. var nn = polygon.length;
  3783. var prevIndex = nn - 2;
  3784. var inside = false;
  3785. for (var ii = 0; ii < nn; ii += 2) {
  3786. var vertexY = vertices[ii + 1];
  3787. var prevY = vertices[prevIndex + 1];
  3788. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  3789. var vertexX = vertices[ii];
  3790. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x)
  3791. inside = !inside;
  3792. }
  3793. prevIndex = ii;
  3794. }
  3795. return inside;
  3796. };
  3797. SkeletonBounds.prototype.intersectsSegment = function (x1, y1, x2, y2) {
  3798. var polygons = this.polygons;
  3799. for (var i = 0, n = polygons.length; i < n; i++)
  3800. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2))
  3801. return this.boundingBoxes[i];
  3802. return null;
  3803. };
  3804. SkeletonBounds.prototype.intersectsSegmentPolygon = function (polygon, x1, y1, x2, y2) {
  3805. var vertices = polygon;
  3806. var nn = polygon.length;
  3807. var width12 = x1 - x2, height12 = y1 - y2;
  3808. var det1 = x1 * y2 - y1 * x2;
  3809. var x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  3810. for (var ii = 0; ii < nn; ii += 2) {
  3811. var x4 = vertices[ii], y4 = vertices[ii + 1];
  3812. var det2 = x3 * y4 - y3 * x4;
  3813. var width34 = x3 - x4, height34 = y3 - y4;
  3814. var det3 = width12 * height34 - height12 * width34;
  3815. var x = (det1 * width34 - width12 * det2) / det3;
  3816. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  3817. var y = (det1 * height34 - height12 * det2) / det3;
  3818. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1)))
  3819. return true;
  3820. }
  3821. x3 = x4;
  3822. y3 = y4;
  3823. }
  3824. return false;
  3825. };
  3826. SkeletonBounds.prototype.getPolygon = function (boundingBox) {
  3827. if (boundingBox == null)
  3828. throw new Error("boundingBox cannot be null.");
  3829. var index = this.boundingBoxes.indexOf(boundingBox);
  3830. return index == -1 ? null : this.polygons[index];
  3831. };
  3832. SkeletonBounds.prototype.getWidth = function () {
  3833. return this.maxX - this.minX;
  3834. };
  3835. SkeletonBounds.prototype.getHeight = function () {
  3836. return this.maxY - this.minY;
  3837. };
  3838. return SkeletonBounds;
  3839. }());
  3840. spine.SkeletonBounds = SkeletonBounds;
  3841. })(spine || (spine = {}));
  3842. var spine;
  3843. (function (spine) {
  3844. var SkeletonClipping = (function () {
  3845. function SkeletonClipping() {
  3846. this.triangulator = new spine.Triangulator();
  3847. this.clippingPolygon = new Array();
  3848. this.clipOutput = new Array();
  3849. this.clippedVertices = new Array();
  3850. this.clippedTriangles = new Array();
  3851. this.scratch = new Array();
  3852. }
  3853. SkeletonClipping.prototype.clipStart = function (slot, clip) {
  3854. if (this.clipAttachment != null)
  3855. return 0;
  3856. this.clipAttachment = clip;
  3857. var n = clip.worldVerticesLength;
  3858. var vertices = spine.Utils.setArraySize(this.clippingPolygon, n);
  3859. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  3860. var clippingPolygon = this.clippingPolygon;
  3861. SkeletonClipping.makeClockwise(clippingPolygon);
  3862. var clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon));
  3863. for (var i = 0, n_1 = clippingPolygons.length; i < n_1; i++) {
  3864. var polygon = clippingPolygons[i];
  3865. SkeletonClipping.makeClockwise(polygon);
  3866. polygon.push(polygon[0]);
  3867. polygon.push(polygon[1]);
  3868. }
  3869. return clippingPolygons.length;
  3870. };
  3871. SkeletonClipping.prototype.clipEndWithSlot = function (slot) {
  3872. if (this.clipAttachment != null && this.clipAttachment.endSlot == slot.data)
  3873. this.clipEnd();
  3874. };
  3875. SkeletonClipping.prototype.clipEnd = function () {
  3876. if (this.clipAttachment == null)
  3877. return;
  3878. this.clipAttachment = null;
  3879. this.clippingPolygons = null;
  3880. this.clippedVertices.length = 0;
  3881. this.clippedTriangles.length = 0;
  3882. this.clippingPolygon.length = 0;
  3883. };
  3884. SkeletonClipping.prototype.isClipping = function () {
  3885. return this.clipAttachment != null;
  3886. };
  3887. SkeletonClipping.prototype.clipTriangles = function (vertices, verticesLength, triangles, trianglesLength, uvs, light, dark, twoColor) {
  3888. var clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
  3889. var clippedTriangles = this.clippedTriangles;
  3890. var polygons = this.clippingPolygons;
  3891. var polygonsCount = this.clippingPolygons.length;
  3892. var vertexSize = twoColor ? 12 : 8;
  3893. var index = 0;
  3894. clippedVertices.length = 0;
  3895. clippedTriangles.length = 0;
  3896. outer: for (var i = 0; i < trianglesLength; i += 3) {
  3897. var vertexOffset = triangles[i] << 1;
  3898. var x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
  3899. var u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
  3900. vertexOffset = triangles[i + 1] << 1;
  3901. var x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
  3902. var u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
  3903. vertexOffset = triangles[i + 2] << 1;
  3904. var x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
  3905. var u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
  3906. for (var p = 0; p < polygonsCount; p++) {
  3907. var s = clippedVertices.length;
  3908. if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
  3909. var clipOutputLength = clipOutput.length;
  3910. if (clipOutputLength == 0)
  3911. continue;
  3912. var d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
  3913. var d = 1 / (d0 * d2 + d1 * (y1 - y3));
  3914. var clipOutputCount = clipOutputLength >> 1;
  3915. var clipOutputItems = this.clipOutput;
  3916. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize);
  3917. for (var ii = 0; ii < clipOutputLength; ii += 2) {
  3918. var x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
  3919. clippedVerticesItems[s] = x;
  3920. clippedVerticesItems[s + 1] = y;
  3921. clippedVerticesItems[s + 2] = light.r;
  3922. clippedVerticesItems[s + 3] = light.g;
  3923. clippedVerticesItems[s + 4] = light.b;
  3924. clippedVerticesItems[s + 5] = light.a;
  3925. var c0 = x - x3, c1 = y - y3;
  3926. var a = (d0 * c0 + d1 * c1) * d;
  3927. var b = (d4 * c0 + d2 * c1) * d;
  3928. var c = 1 - a - b;
  3929. clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
  3930. clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c;
  3931. if (twoColor) {
  3932. clippedVerticesItems[s + 8] = dark.r;
  3933. clippedVerticesItems[s + 9] = dark.g;
  3934. clippedVerticesItems[s + 10] = dark.b;
  3935. clippedVerticesItems[s + 11] = dark.a;
  3936. }
  3937. s += vertexSize;
  3938. }
  3939. s = clippedTriangles.length;
  3940. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2));
  3941. clipOutputCount--;
  3942. for (var ii = 1; ii < clipOutputCount; ii++) {
  3943. clippedTrianglesItems[s] = index;
  3944. clippedTrianglesItems[s + 1] = (index + ii);
  3945. clippedTrianglesItems[s + 2] = (index + ii + 1);
  3946. s += 3;
  3947. }
  3948. index += clipOutputCount + 1;
  3949. }
  3950. else {
  3951. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + 3 * vertexSize);
  3952. clippedVerticesItems[s] = x1;
  3953. clippedVerticesItems[s + 1] = y1;
  3954. clippedVerticesItems[s + 2] = light.r;
  3955. clippedVerticesItems[s + 3] = light.g;
  3956. clippedVerticesItems[s + 4] = light.b;
  3957. clippedVerticesItems[s + 5] = light.a;
  3958. if (!twoColor) {
  3959. clippedVerticesItems[s + 6] = u1;
  3960. clippedVerticesItems[s + 7] = v1;
  3961. clippedVerticesItems[s + 8] = x2;
  3962. clippedVerticesItems[s + 9] = y2;
  3963. clippedVerticesItems[s + 10] = light.r;
  3964. clippedVerticesItems[s + 11] = light.g;
  3965. clippedVerticesItems[s + 12] = light.b;
  3966. clippedVerticesItems[s + 13] = light.a;
  3967. clippedVerticesItems[s + 14] = u2;
  3968. clippedVerticesItems[s + 15] = v2;
  3969. clippedVerticesItems[s + 16] = x3;
  3970. clippedVerticesItems[s + 17] = y3;
  3971. clippedVerticesItems[s + 18] = light.r;
  3972. clippedVerticesItems[s + 19] = light.g;
  3973. clippedVerticesItems[s + 20] = light.b;
  3974. clippedVerticesItems[s + 21] = light.a;
  3975. clippedVerticesItems[s + 22] = u3;
  3976. clippedVerticesItems[s + 23] = v3;
  3977. }
  3978. else {
  3979. clippedVerticesItems[s + 6] = u1;
  3980. clippedVerticesItems[s + 7] = v1;
  3981. clippedVerticesItems[s + 8] = dark.r;
  3982. clippedVerticesItems[s + 9] = dark.g;
  3983. clippedVerticesItems[s + 10] = dark.b;
  3984. clippedVerticesItems[s + 11] = dark.a;
  3985. clippedVerticesItems[s + 12] = x2;
  3986. clippedVerticesItems[s + 13] = y2;
  3987. clippedVerticesItems[s + 14] = light.r;
  3988. clippedVerticesItems[s + 15] = light.g;
  3989. clippedVerticesItems[s + 16] = light.b;
  3990. clippedVerticesItems[s + 17] = light.a;
  3991. clippedVerticesItems[s + 18] = u2;
  3992. clippedVerticesItems[s + 19] = v2;
  3993. clippedVerticesItems[s + 20] = dark.r;
  3994. clippedVerticesItems[s + 21] = dark.g;
  3995. clippedVerticesItems[s + 22] = dark.b;
  3996. clippedVerticesItems[s + 23] = dark.a;
  3997. clippedVerticesItems[s + 24] = x3;
  3998. clippedVerticesItems[s + 25] = y3;
  3999. clippedVerticesItems[s + 26] = light.r;
  4000. clippedVerticesItems[s + 27] = light.g;
  4001. clippedVerticesItems[s + 28] = light.b;
  4002. clippedVerticesItems[s + 29] = light.a;
  4003. clippedVerticesItems[s + 30] = u3;
  4004. clippedVerticesItems[s + 31] = v3;
  4005. clippedVerticesItems[s + 32] = dark.r;
  4006. clippedVerticesItems[s + 33] = dark.g;
  4007. clippedVerticesItems[s + 34] = dark.b;
  4008. clippedVerticesItems[s + 35] = dark.a;
  4009. }
  4010. s = clippedTriangles.length;
  4011. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3);
  4012. clippedTrianglesItems[s] = index;
  4013. clippedTrianglesItems[s + 1] = (index + 1);
  4014. clippedTrianglesItems[s + 2] = (index + 2);
  4015. index += 3;
  4016. continue outer;
  4017. }
  4018. }
  4019. }
  4020. };
  4021. SkeletonClipping.prototype.clip = function (x1, y1, x2, y2, x3, y3, clippingArea, output) {
  4022. var originalOutput = output;
  4023. var clipped = false;
  4024. var input = null;
  4025. if (clippingArea.length % 4 >= 2) {
  4026. input = output;
  4027. output = this.scratch;
  4028. }
  4029. else
  4030. input = this.scratch;
  4031. input.length = 0;
  4032. input.push(x1);
  4033. input.push(y1);
  4034. input.push(x2);
  4035. input.push(y2);
  4036. input.push(x3);
  4037. input.push(y3);
  4038. input.push(x1);
  4039. input.push(y1);
  4040. output.length = 0;
  4041. var clippingVertices = clippingArea;
  4042. var clippingVerticesLast = clippingArea.length - 4;
  4043. for (var i = 0;; i += 2) {
  4044. var edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
  4045. var edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
  4046. var deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
  4047. var inputVertices = input;
  4048. var inputVerticesLength = input.length - 2, outputStart = output.length;
  4049. for (var ii = 0; ii < inputVerticesLength; ii += 2) {
  4050. var inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
  4051. var inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
  4052. var side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
  4053. if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
  4054. if (side2) {
  4055. output.push(inputX2);
  4056. output.push(inputY2);
  4057. continue;
  4058. }
  4059. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  4060. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
  4061. output.push(edgeX + (edgeX2 - edgeX) * ua);
  4062. output.push(edgeY + (edgeY2 - edgeY) * ua);
  4063. }
  4064. else if (side2) {
  4065. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  4066. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
  4067. output.push(edgeX + (edgeX2 - edgeX) * ua);
  4068. output.push(edgeY + (edgeY2 - edgeY) * ua);
  4069. output.push(inputX2);
  4070. output.push(inputY2);
  4071. }
  4072. clipped = true;
  4073. }
  4074. if (outputStart == output.length) {
  4075. originalOutput.length = 0;
  4076. return true;
  4077. }
  4078. output.push(output[0]);
  4079. output.push(output[1]);
  4080. if (i == clippingVerticesLast)
  4081. break;
  4082. var temp = output;
  4083. output = input;
  4084. output.length = 0;
  4085. input = temp;
  4086. }
  4087. if (originalOutput != output) {
  4088. originalOutput.length = 0;
  4089. for (var i = 0, n = output.length - 2; i < n; i++)
  4090. originalOutput[i] = output[i];
  4091. }
  4092. else
  4093. originalOutput.length = originalOutput.length - 2;
  4094. return clipped;
  4095. };
  4096. SkeletonClipping.makeClockwise = function (polygon) {
  4097. var vertices = polygon;
  4098. var verticeslength = polygon.length;
  4099. var area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0;
  4100. for (var i = 0, n = verticeslength - 3; i < n; i += 2) {
  4101. p1x = vertices[i];
  4102. p1y = vertices[i + 1];
  4103. p2x = vertices[i + 2];
  4104. p2y = vertices[i + 3];
  4105. area += p1x * p2y - p2x * p1y;
  4106. }
  4107. if (area < 0)
  4108. return;
  4109. for (var i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
  4110. var x = vertices[i], y = vertices[i + 1];
  4111. var other = lastX - i;
  4112. vertices[i] = vertices[other];
  4113. vertices[i + 1] = vertices[other + 1];
  4114. vertices[other] = x;
  4115. vertices[other + 1] = y;
  4116. }
  4117. };
  4118. return SkeletonClipping;
  4119. }());
  4120. spine.SkeletonClipping = SkeletonClipping;
  4121. })(spine || (spine = {}));
  4122. var spine;
  4123. (function (spine) {
  4124. var SkeletonData = (function () {
  4125. function SkeletonData() {
  4126. this.bones = new Array();
  4127. this.slots = new Array();
  4128. this.skins = new Array();
  4129. this.events = new Array();
  4130. this.animations = new Array();
  4131. this.ikConstraints = new Array();
  4132. this.transformConstraints = new Array();
  4133. this.pathConstraints = new Array();
  4134. this.fps = 0;
  4135. }
  4136. SkeletonData.prototype.findBone = function (boneName) {
  4137. if (boneName == null)
  4138. throw new Error("boneName cannot be null.");
  4139. var bones = this.bones;
  4140. for (var i = 0, n = bones.length; i < n; i++) {
  4141. var bone = bones[i];
  4142. if (bone.name == boneName)
  4143. return bone;
  4144. }
  4145. return null;
  4146. };
  4147. SkeletonData.prototype.findBoneIndex = function (boneName) {
  4148. if (boneName == null)
  4149. throw new Error("boneName cannot be null.");
  4150. var bones = this.bones;
  4151. for (var i = 0, n = bones.length; i < n; i++)
  4152. if (bones[i].name == boneName)
  4153. return i;
  4154. return -1;
  4155. };
  4156. SkeletonData.prototype.findSlot = function (slotName) {
  4157. if (slotName == null)
  4158. throw new Error("slotName cannot be null.");
  4159. var slots = this.slots;
  4160. for (var i = 0, n = slots.length; i < n; i++) {
  4161. var slot = slots[i];
  4162. if (slot.name == slotName)
  4163. return slot;
  4164. }
  4165. return null;
  4166. };
  4167. SkeletonData.prototype.findSlotIndex = function (slotName) {
  4168. if (slotName == null)
  4169. throw new Error("slotName cannot be null.");
  4170. var slots = this.slots;
  4171. for (var i = 0, n = slots.length; i < n; i++)
  4172. if (slots[i].name == slotName)
  4173. return i;
  4174. return -1;
  4175. };
  4176. SkeletonData.prototype.findSkin = function (skinName) {
  4177. if (skinName == null)
  4178. throw new Error("skinName cannot be null.");
  4179. var skins = this.skins;
  4180. for (var i = 0, n = skins.length; i < n; i++) {
  4181. var skin = skins[i];
  4182. if (skin.name == skinName)
  4183. return skin;
  4184. }
  4185. return null;
  4186. };
  4187. SkeletonData.prototype.findEvent = function (eventDataName) {
  4188. if (eventDataName == null)
  4189. throw new Error("eventDataName cannot be null.");
  4190. var events = this.events;
  4191. for (var i = 0, n = events.length; i < n; i++) {
  4192. var event_4 = events[i];
  4193. if (event_4.name == eventDataName)
  4194. return event_4;
  4195. }
  4196. return null;
  4197. };
  4198. SkeletonData.prototype.findAnimation = function (animationName) {
  4199. if (animationName == null)
  4200. throw new Error("animationName cannot be null.");
  4201. var animations = this.animations;
  4202. for (var i = 0, n = animations.length; i < n; i++) {
  4203. var animation = animations[i];
  4204. if (animation.name == animationName)
  4205. return animation;
  4206. }
  4207. return null;
  4208. };
  4209. SkeletonData.prototype.findIkConstraint = function (constraintName) {
  4210. if (constraintName == null)
  4211. throw new Error("constraintName cannot be null.");
  4212. var ikConstraints = this.ikConstraints;
  4213. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  4214. var constraint = ikConstraints[i];
  4215. if (constraint.name == constraintName)
  4216. return constraint;
  4217. }
  4218. return null;
  4219. };
  4220. SkeletonData.prototype.findTransformConstraint = function (constraintName) {
  4221. if (constraintName == null)
  4222. throw new Error("constraintName cannot be null.");
  4223. var transformConstraints = this.transformConstraints;
  4224. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  4225. var constraint = transformConstraints[i];
  4226. if (constraint.name == constraintName)
  4227. return constraint;
  4228. }
  4229. return null;
  4230. };
  4231. SkeletonData.prototype.findPathConstraint = function (constraintName) {
  4232. if (constraintName == null)
  4233. throw new Error("constraintName cannot be null.");
  4234. var pathConstraints = this.pathConstraints;
  4235. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  4236. var constraint = pathConstraints[i];
  4237. if (constraint.name == constraintName)
  4238. return constraint;
  4239. }
  4240. return null;
  4241. };
  4242. SkeletonData.prototype.findPathConstraintIndex = function (pathConstraintName) {
  4243. if (pathConstraintName == null)
  4244. throw new Error("pathConstraintName cannot be null.");
  4245. var pathConstraints = this.pathConstraints;
  4246. for (var i = 0, n = pathConstraints.length; i < n; i++)
  4247. if (pathConstraints[i].name == pathConstraintName)
  4248. return i;
  4249. return -1;
  4250. };
  4251. return SkeletonData;
  4252. }());
  4253. spine.SkeletonData = SkeletonData;
  4254. })(spine || (spine = {}));
  4255. var spine;
  4256. (function (spine) {
  4257. var SkeletonJson = (function () {
  4258. function SkeletonJson(attachmentLoader) {
  4259. this.scale = 1;
  4260. this.linkedMeshes = new Array();
  4261. this.attachmentLoader = attachmentLoader;
  4262. }
  4263. SkeletonJson.prototype.readSkeletonData = function (json) {
  4264. var scale = this.scale;
  4265. var skeletonData = new spine.SkeletonData();
  4266. var root = typeof (json) === "string" ? JSON.parse(json) : json;
  4267. var skeletonMap = root.skeleton;
  4268. if (skeletonMap != null) {
  4269. skeletonData.hash = skeletonMap.hash;
  4270. skeletonData.version = skeletonMap.spine;
  4271. skeletonData.width = skeletonMap.width;
  4272. skeletonData.height = skeletonMap.height;
  4273. skeletonData.fps = skeletonMap.fps;
  4274. skeletonData.imagesPath = skeletonMap.images;
  4275. }
  4276. if (root.bones) {
  4277. for (var i = 0; i < root.bones.length; i++) {
  4278. var boneMap = root.bones[i];
  4279. var parent_2 = null;
  4280. var parentName = this.getValue(boneMap, "parent", null);
  4281. if (parentName != null) {
  4282. parent_2 = skeletonData.findBone(parentName);
  4283. if (parent_2 == null)
  4284. throw new Error("Parent bone not found: " + parentName);
  4285. }
  4286. var data = new spine.BoneData(skeletonData.bones.length, boneMap.name, parent_2);
  4287. data.length = this.getValue(boneMap, "length", 0) * scale;
  4288. data.x = this.getValue(boneMap, "x", 0) * scale;
  4289. data.y = this.getValue(boneMap, "y", 0) * scale;
  4290. data.rotation = this.getValue(boneMap, "rotation", 0);
  4291. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  4292. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  4293. data.shearX = this.getValue(boneMap, "shearX", 0);
  4294. data.shearY = this.getValue(boneMap, "shearY", 0);
  4295. data.transformMode = SkeletonJson.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  4296. skeletonData.bones.push(data);
  4297. }
  4298. }
  4299. if (root.slots) {
  4300. for (var i = 0; i < root.slots.length; i++) {
  4301. var slotMap = root.slots[i];
  4302. var slotName = slotMap.name;
  4303. var boneName = slotMap.bone;
  4304. var boneData = skeletonData.findBone(boneName);
  4305. if (boneData == null)
  4306. throw new Error("Slot bone not found: " + boneName);
  4307. var data = new spine.SlotData(skeletonData.slots.length, slotName, boneData);
  4308. var color = this.getValue(slotMap, "color", null);
  4309. if (color != null)
  4310. data.color.setFromString(color);
  4311. var dark = this.getValue(slotMap, "dark", null);
  4312. if (dark != null) {
  4313. data.darkColor = new spine.Color(1, 1, 1, 1);
  4314. data.darkColor.setFromString(dark);
  4315. }
  4316. data.attachmentName = this.getValue(slotMap, "attachment", null);
  4317. data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  4318. skeletonData.slots.push(data);
  4319. }
  4320. }
  4321. if (root.ik) {
  4322. for (var i = 0; i < root.ik.length; i++) {
  4323. var constraintMap = root.ik[i];
  4324. var data = new spine.IkConstraintData(constraintMap.name);
  4325. data.order = this.getValue(constraintMap, "order", 0);
  4326. for (var j = 0; j < constraintMap.bones.length; j++) {
  4327. var boneName = constraintMap.bones[j];
  4328. var bone = skeletonData.findBone(boneName);
  4329. if (bone == null)
  4330. throw new Error("IK bone not found: " + boneName);
  4331. data.bones.push(bone);
  4332. }
  4333. var targetName = constraintMap.target;
  4334. data.target = skeletonData.findBone(targetName);
  4335. if (data.target == null)
  4336. throw new Error("IK target bone not found: " + targetName);
  4337. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  4338. data.mix = this.getValue(constraintMap, "mix", 1);
  4339. skeletonData.ikConstraints.push(data);
  4340. }
  4341. }
  4342. if (root.transform) {
  4343. for (var i = 0; i < root.transform.length; i++) {
  4344. var constraintMap = root.transform[i];
  4345. var data = new spine.TransformConstraintData(constraintMap.name);
  4346. data.order = this.getValue(constraintMap, "order", 0);
  4347. for (var j = 0; j < constraintMap.bones.length; j++) {
  4348. var boneName = constraintMap.bones[j];
  4349. var bone = skeletonData.findBone(boneName);
  4350. if (bone == null)
  4351. throw new Error("Transform constraint bone not found: " + boneName);
  4352. data.bones.push(bone);
  4353. }
  4354. var targetName = constraintMap.target;
  4355. data.target = skeletonData.findBone(targetName);
  4356. if (data.target == null)
  4357. throw new Error("Transform constraint target bone not found: " + targetName);
  4358. data.local = this.getValue(constraintMap, "local", false);
  4359. data.relative = this.getValue(constraintMap, "relative", false);
  4360. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  4361. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  4362. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  4363. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  4364. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  4365. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  4366. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  4367. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  4368. data.scaleMix = this.getValue(constraintMap, "scaleMix", 1);
  4369. data.shearMix = this.getValue(constraintMap, "shearMix", 1);
  4370. skeletonData.transformConstraints.push(data);
  4371. }
  4372. }
  4373. if (root.path) {
  4374. for (var i = 0; i < root.path.length; i++) {
  4375. var constraintMap = root.path[i];
  4376. var data = new spine.PathConstraintData(constraintMap.name);
  4377. data.order = this.getValue(constraintMap, "order", 0);
  4378. for (var j = 0; j < constraintMap.bones.length; j++) {
  4379. var boneName = constraintMap.bones[j];
  4380. var bone = skeletonData.findBone(boneName);
  4381. if (bone == null)
  4382. throw new Error("Transform constraint bone not found: " + boneName);
  4383. data.bones.push(bone);
  4384. }
  4385. var targetName = constraintMap.target;
  4386. data.target = skeletonData.findSlot(targetName);
  4387. if (data.target == null)
  4388. throw new Error("Path target slot not found: " + targetName);
  4389. data.positionMode = SkeletonJson.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  4390. data.spacingMode = SkeletonJson.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  4391. data.rotateMode = SkeletonJson.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  4392. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  4393. data.position = this.getValue(constraintMap, "position", 0);
  4394. if (data.positionMode == spine.PositionMode.Fixed)
  4395. data.position *= scale;
  4396. data.spacing = this.getValue(constraintMap, "spacing", 0);
  4397. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4398. data.spacing *= scale;
  4399. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  4400. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  4401. skeletonData.pathConstraints.push(data);
  4402. }
  4403. }
  4404. if (root.skins) {
  4405. for (var skinName in root.skins) {
  4406. var skinMap = root.skins[skinName];
  4407. var skin = new spine.Skin(skinName);
  4408. for (var slotName in skinMap) {
  4409. var slotIndex = skeletonData.findSlotIndex(slotName);
  4410. if (slotIndex == -1)
  4411. throw new Error("Slot not found: " + slotName);
  4412. var slotMap = skinMap[slotName];
  4413. for (var entryName in slotMap) {
  4414. var attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
  4415. if (attachment != null)
  4416. skin.addAttachment(slotIndex, entryName, attachment);
  4417. }
  4418. }
  4419. skeletonData.skins.push(skin);
  4420. if (skin.name == "default")
  4421. skeletonData.defaultSkin = skin;
  4422. }
  4423. }
  4424. for (var i = 0, n = this.linkedMeshes.length; i < n; i++) {
  4425. var linkedMesh = this.linkedMeshes[i];
  4426. var skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  4427. if (skin == null)
  4428. throw new Error("Skin not found: " + linkedMesh.skin);
  4429. var parent_3 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  4430. if (parent_3 == null)
  4431. throw new Error("Parent mesh not found: " + linkedMesh.parent);
  4432. linkedMesh.mesh.setParentMesh(parent_3);
  4433. linkedMesh.mesh.updateUVs();
  4434. }
  4435. this.linkedMeshes.length = 0;
  4436. if (root.events) {
  4437. for (var eventName in root.events) {
  4438. var eventMap = root.events[eventName];
  4439. var data = new spine.EventData(eventName);
  4440. data.intValue = this.getValue(eventMap, "int", 0);
  4441. data.floatValue = this.getValue(eventMap, "float", 0);
  4442. data.stringValue = this.getValue(eventMap, "string", "");
  4443. skeletonData.events.push(data);
  4444. }
  4445. }
  4446. if (root.animations) {
  4447. for (var animationName in root.animations) {
  4448. var animationMap = root.animations[animationName];
  4449. this.readAnimation(animationMap, animationName, skeletonData);
  4450. }
  4451. }
  4452. return skeletonData;
  4453. };
  4454. SkeletonJson.prototype.readAttachment = function (map, skin, slotIndex, name, skeletonData) {
  4455. var scale = this.scale;
  4456. name = this.getValue(map, "name", name);
  4457. var type = this.getValue(map, "type", "region");
  4458. switch (type) {
  4459. case "region": {
  4460. var path = this.getValue(map, "path", name);
  4461. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  4462. if (region == null)
  4463. return null;
  4464. region.path = path;
  4465. region.x = this.getValue(map, "x", 0) * scale;
  4466. region.y = this.getValue(map, "y", 0) * scale;
  4467. region.scaleX = this.getValue(map, "scaleX", 1);
  4468. region.scaleY = this.getValue(map, "scaleY", 1);
  4469. region.rotation = this.getValue(map, "rotation", 0);
  4470. region.width = map.width * scale;
  4471. region.height = map.height * scale;
  4472. var color = this.getValue(map, "color", null);
  4473. if (color != null)
  4474. region.color.setFromString(color);
  4475. region.updateOffset();
  4476. return region;
  4477. }
  4478. case "boundingbox": {
  4479. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  4480. if (box == null)
  4481. return null;
  4482. this.readVertices(map, box, map.vertexCount << 1);
  4483. var color = this.getValue(map, "color", null);
  4484. if (color != null)
  4485. box.color.setFromString(color);
  4486. return box;
  4487. }
  4488. case "mesh":
  4489. case "linkedmesh": {
  4490. var path = this.getValue(map, "path", name);
  4491. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4492. if (mesh == null)
  4493. return null;
  4494. mesh.path = path;
  4495. var color = this.getValue(map, "color", null);
  4496. if (color != null)
  4497. mesh.color.setFromString(color);
  4498. var parent_4 = this.getValue(map, "parent", null);
  4499. if (parent_4 != null) {
  4500. mesh.inheritDeform = this.getValue(map, "deform", true);
  4501. this.linkedMeshes.push(new LinkedMesh(mesh, this.getValue(map, "skin", null), slotIndex, parent_4));
  4502. return mesh;
  4503. }
  4504. var uvs = map.uvs;
  4505. this.readVertices(map, mesh, uvs.length);
  4506. mesh.triangles = map.triangles;
  4507. mesh.regionUVs = uvs;
  4508. mesh.updateUVs();
  4509. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  4510. return mesh;
  4511. }
  4512. case "path": {
  4513. var path = this.attachmentLoader.newPathAttachment(skin, name);
  4514. if (path == null)
  4515. return null;
  4516. path.closed = this.getValue(map, "closed", false);
  4517. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  4518. var vertexCount = map.vertexCount;
  4519. this.readVertices(map, path, vertexCount << 1);
  4520. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  4521. for (var i = 0; i < map.lengths.length; i++)
  4522. lengths[i] = map.lengths[i] * scale;
  4523. path.lengths = lengths;
  4524. var color = this.getValue(map, "color", null);
  4525. if (color != null)
  4526. path.color.setFromString(color);
  4527. return path;
  4528. }
  4529. case "point": {
  4530. var point = this.attachmentLoader.newPointAttachment(skin, name);
  4531. if (point == null)
  4532. return null;
  4533. point.x = this.getValue(map, "x", 0) * scale;
  4534. point.y = this.getValue(map, "y", 0) * scale;
  4535. point.rotation = this.getValue(map, "rotation", 0);
  4536. var color = this.getValue(map, "color", null);
  4537. if (color != null)
  4538. point.color.setFromString(color);
  4539. return point;
  4540. }
  4541. case "clipping": {
  4542. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  4543. if (clip == null)
  4544. return null;
  4545. var end = this.getValue(map, "end", null);
  4546. if (end != null) {
  4547. var slot = skeletonData.findSlot(end);
  4548. if (slot == null)
  4549. throw new Error("Clipping end slot not found: " + end);
  4550. clip.endSlot = slot;
  4551. }
  4552. var vertexCount = map.vertexCount;
  4553. this.readVertices(map, clip, vertexCount << 1);
  4554. var color = this.getValue(map, "color", null);
  4555. if (color != null)
  4556. clip.color.setFromString(color);
  4557. return clip;
  4558. }
  4559. }
  4560. return null;
  4561. };
  4562. SkeletonJson.prototype.readVertices = function (map, attachment, verticesLength) {
  4563. var scale = this.scale;
  4564. attachment.worldVerticesLength = verticesLength;
  4565. var vertices = map.vertices;
  4566. if (verticesLength == vertices.length) {
  4567. var scaledVertices = spine.Utils.toFloatArray(vertices);
  4568. if (scale != 1) {
  4569. for (var i = 0, n = vertices.length; i < n; i++)
  4570. scaledVertices[i] *= scale;
  4571. }
  4572. attachment.vertices = scaledVertices;
  4573. return;
  4574. }
  4575. var weights = new Array();
  4576. var bones = new Array();
  4577. for (var i = 0, n = vertices.length; i < n;) {
  4578. var boneCount = vertices[i++];
  4579. bones.push(boneCount);
  4580. for (var nn = i + boneCount * 4; i < nn; i += 4) {
  4581. bones.push(vertices[i]);
  4582. weights.push(vertices[i + 1] * scale);
  4583. weights.push(vertices[i + 2] * scale);
  4584. weights.push(vertices[i + 3]);
  4585. }
  4586. }
  4587. attachment.bones = bones;
  4588. attachment.vertices = spine.Utils.toFloatArray(weights);
  4589. };
  4590. SkeletonJson.prototype.readAnimation = function (map, name, skeletonData) {
  4591. var scale = this.scale;
  4592. var timelines = new Array();
  4593. var duration = 0;
  4594. if (map.slots) {
  4595. for (var slotName in map.slots) {
  4596. var slotMap = map.slots[slotName];
  4597. var slotIndex = skeletonData.findSlotIndex(slotName);
  4598. if (slotIndex == -1)
  4599. throw new Error("Slot not found: " + slotName);
  4600. for (var timelineName in slotMap) {
  4601. var timelineMap = slotMap[timelineName];
  4602. if (timelineName == "attachment") {
  4603. var timeline = new spine.AttachmentTimeline(timelineMap.length);
  4604. timeline.slotIndex = slotIndex;
  4605. var frameIndex = 0;
  4606. for (var i = 0; i < timelineMap.length; i++) {
  4607. var valueMap = timelineMap[i];
  4608. timeline.setFrame(frameIndex++, valueMap.time, valueMap.name);
  4609. }
  4610. timelines.push(timeline);
  4611. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4612. }
  4613. else if (timelineName == "color") {
  4614. var timeline = new spine.ColorTimeline(timelineMap.length);
  4615. timeline.slotIndex = slotIndex;
  4616. var frameIndex = 0;
  4617. for (var i = 0; i < timelineMap.length; i++) {
  4618. var valueMap = timelineMap[i];
  4619. var color = new spine.Color();
  4620. color.setFromString(valueMap.color);
  4621. timeline.setFrame(frameIndex, valueMap.time, color.r, color.g, color.b, color.a);
  4622. this.readCurve(valueMap, timeline, frameIndex);
  4623. frameIndex++;
  4624. }
  4625. timelines.push(timeline);
  4626. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]);
  4627. }
  4628. else if (timelineName == "twoColor") {
  4629. var timeline = new spine.TwoColorTimeline(timelineMap.length);
  4630. timeline.slotIndex = slotIndex;
  4631. var frameIndex = 0;
  4632. for (var i = 0; i < timelineMap.length; i++) {
  4633. var valueMap = timelineMap[i];
  4634. var light = new spine.Color();
  4635. var dark = new spine.Color();
  4636. light.setFromString(valueMap.light);
  4637. dark.setFromString(valueMap.dark);
  4638. timeline.setFrame(frameIndex, valueMap.time, light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
  4639. this.readCurve(valueMap, timeline, frameIndex);
  4640. frameIndex++;
  4641. }
  4642. timelines.push(timeline);
  4643. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TwoColorTimeline.ENTRIES]);
  4644. }
  4645. else
  4646. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  4647. }
  4648. }
  4649. }
  4650. if (map.bones) {
  4651. for (var boneName in map.bones) {
  4652. var boneMap = map.bones[boneName];
  4653. var boneIndex = skeletonData.findBoneIndex(boneName);
  4654. if (boneIndex == -1)
  4655. throw new Error("Bone not found: " + boneName);
  4656. for (var timelineName in boneMap) {
  4657. var timelineMap = boneMap[timelineName];
  4658. if (timelineName === "rotate") {
  4659. var timeline = new spine.RotateTimeline(timelineMap.length);
  4660. timeline.boneIndex = boneIndex;
  4661. var frameIndex = 0;
  4662. for (var i = 0; i < timelineMap.length; i++) {
  4663. var valueMap = timelineMap[i];
  4664. timeline.setFrame(frameIndex, valueMap.time, valueMap.angle);
  4665. this.readCurve(valueMap, timeline, frameIndex);
  4666. frameIndex++;
  4667. }
  4668. timelines.push(timeline);
  4669. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.RotateTimeline.ENTRIES]);
  4670. }
  4671. else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
  4672. var timeline = null;
  4673. var timelineScale = 1;
  4674. if (timelineName === "scale")
  4675. timeline = new spine.ScaleTimeline(timelineMap.length);
  4676. else if (timelineName === "shear")
  4677. timeline = new spine.ShearTimeline(timelineMap.length);
  4678. else {
  4679. timeline = new spine.TranslateTimeline(timelineMap.length);
  4680. timelineScale = scale;
  4681. }
  4682. timeline.boneIndex = boneIndex;
  4683. var frameIndex = 0;
  4684. for (var i = 0; i < timelineMap.length; i++) {
  4685. var valueMap = timelineMap[i];
  4686. var x = this.getValue(valueMap, "x", 0), y = this.getValue(valueMap, "y", 0);
  4687. timeline.setFrame(frameIndex, valueMap.time, x * timelineScale, y * timelineScale);
  4688. this.readCurve(valueMap, timeline, frameIndex);
  4689. frameIndex++;
  4690. }
  4691. timelines.push(timeline);
  4692. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TranslateTimeline.ENTRIES]);
  4693. }
  4694. else
  4695. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  4696. }
  4697. }
  4698. }
  4699. if (map.ik) {
  4700. for (var constraintName in map.ik) {
  4701. var constraintMap = map.ik[constraintName];
  4702. var constraint = skeletonData.findIkConstraint(constraintName);
  4703. var timeline = new spine.IkConstraintTimeline(constraintMap.length);
  4704. timeline.ikConstraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  4705. var frameIndex = 0;
  4706. for (var i = 0; i < constraintMap.length; i++) {
  4707. var valueMap = constraintMap[i];
  4708. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "mix", 1), this.getValue(valueMap, "bendPositive", true) ? 1 : -1);
  4709. this.readCurve(valueMap, timeline, frameIndex);
  4710. frameIndex++;
  4711. }
  4712. timelines.push(timeline);
  4713. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.IkConstraintTimeline.ENTRIES]);
  4714. }
  4715. }
  4716. if (map.transform) {
  4717. for (var constraintName in map.transform) {
  4718. var constraintMap = map.transform[constraintName];
  4719. var constraint = skeletonData.findTransformConstraint(constraintName);
  4720. var timeline = new spine.TransformConstraintTimeline(constraintMap.length);
  4721. timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  4722. var frameIndex = 0;
  4723. for (var i = 0; i < constraintMap.length; i++) {
  4724. var valueMap = constraintMap[i];
  4725. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1), this.getValue(valueMap, "scaleMix", 1), this.getValue(valueMap, "shearMix", 1));
  4726. this.readCurve(valueMap, timeline, frameIndex);
  4727. frameIndex++;
  4728. }
  4729. timelines.push(timeline);
  4730. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TransformConstraintTimeline.ENTRIES]);
  4731. }
  4732. }
  4733. if (map.paths) {
  4734. for (var constraintName in map.paths) {
  4735. var constraintMap = map.paths[constraintName];
  4736. var index = skeletonData.findPathConstraintIndex(constraintName);
  4737. if (index == -1)
  4738. throw new Error("Path constraint not found: " + constraintName);
  4739. var data = skeletonData.pathConstraints[index];
  4740. for (var timelineName in constraintMap) {
  4741. var timelineMap = constraintMap[timelineName];
  4742. if (timelineName === "position" || timelineName === "spacing") {
  4743. var timeline = null;
  4744. var timelineScale = 1;
  4745. if (timelineName === "spacing") {
  4746. timeline = new spine.PathConstraintSpacingTimeline(timelineMap.length);
  4747. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4748. timelineScale = scale;
  4749. }
  4750. else {
  4751. timeline = new spine.PathConstraintPositionTimeline(timelineMap.length);
  4752. if (data.positionMode == spine.PositionMode.Fixed)
  4753. timelineScale = scale;
  4754. }
  4755. timeline.pathConstraintIndex = index;
  4756. var frameIndex = 0;
  4757. for (var i = 0; i < timelineMap.length; i++) {
  4758. var valueMap = timelineMap[i];
  4759. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, timelineName, 0) * timelineScale);
  4760. this.readCurve(valueMap, timeline, frameIndex);
  4761. frameIndex++;
  4762. }
  4763. timelines.push(timeline);
  4764. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintPositionTimeline.ENTRIES]);
  4765. }
  4766. else if (timelineName === "mix") {
  4767. var timeline = new spine.PathConstraintMixTimeline(timelineMap.length);
  4768. timeline.pathConstraintIndex = index;
  4769. var frameIndex = 0;
  4770. for (var i = 0; i < timelineMap.length; i++) {
  4771. var valueMap = timelineMap[i];
  4772. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1));
  4773. this.readCurve(valueMap, timeline, frameIndex);
  4774. frameIndex++;
  4775. }
  4776. timelines.push(timeline);
  4777. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintMixTimeline.ENTRIES]);
  4778. }
  4779. }
  4780. }
  4781. }
  4782. if (map.deform) {
  4783. for (var deformName in map.deform) {
  4784. var deformMap = map.deform[deformName];
  4785. var skin = skeletonData.findSkin(deformName);
  4786. if (skin == null)
  4787. throw new Error("Skin not found: " + deformName);
  4788. for (var slotName in deformMap) {
  4789. var slotMap = deformMap[slotName];
  4790. var slotIndex = skeletonData.findSlotIndex(slotName);
  4791. if (slotIndex == -1)
  4792. throw new Error("Slot not found: " + slotMap.name);
  4793. for (var timelineName in slotMap) {
  4794. var timelineMap = slotMap[timelineName];
  4795. var attachment = skin.getAttachment(slotIndex, timelineName);
  4796. if (attachment == null)
  4797. // throw new Error("Deform attachment not found: " + timelineMap.name);
  4798. continue;
  4799. var weighted = attachment.bones != null;
  4800. var vertices = attachment.vertices;
  4801. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  4802. var timeline = new spine.DeformTimeline(timelineMap.length);
  4803. timeline.slotIndex = slotIndex;
  4804. timeline.attachment = attachment;
  4805. var frameIndex = 0;
  4806. for (var j = 0; j < timelineMap.length; j++) {
  4807. var valueMap = timelineMap[j];
  4808. var deform = void 0;
  4809. var verticesValue = this.getValue(valueMap, "vertices", null);
  4810. if (verticesValue == null)
  4811. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  4812. else {
  4813. deform = spine.Utils.newFloatArray(deformLength);
  4814. var start = this.getValue(valueMap, "offset", 0);
  4815. spine.Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  4816. if (scale != 1) {
  4817. for (var i = start, n = i + verticesValue.length; i < n; i++)
  4818. deform[i] *= scale;
  4819. }
  4820. if (!weighted) {
  4821. for (var i = 0; i < deformLength; i++)
  4822. deform[i] += vertices[i];
  4823. }
  4824. }
  4825. timeline.setFrame(frameIndex, valueMap.time, deform);
  4826. this.readCurve(valueMap, timeline, frameIndex);
  4827. frameIndex++;
  4828. }
  4829. timelines.push(timeline);
  4830. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4831. }
  4832. }
  4833. }
  4834. }
  4835. var drawOrderNode = map.drawOrder;
  4836. if (drawOrderNode == null)
  4837. drawOrderNode = map.draworder;
  4838. if (drawOrderNode != null) {
  4839. var timeline = new spine.DrawOrderTimeline(drawOrderNode.length);
  4840. var slotCount = skeletonData.slots.length;
  4841. var frameIndex = 0;
  4842. for (var j = 0; j < drawOrderNode.length; j++) {
  4843. var drawOrderMap = drawOrderNode[j];
  4844. var drawOrder = null;
  4845. var offsets = this.getValue(drawOrderMap, "offsets", null);
  4846. if (offsets != null) {
  4847. drawOrder = spine.Utils.newArray(slotCount, -1);
  4848. var unchanged = spine.Utils.newArray(slotCount - offsets.length, 0);
  4849. var originalIndex = 0, unchangedIndex = 0;
  4850. for (var i = 0; i < offsets.length; i++) {
  4851. var offsetMap = offsets[i];
  4852. var slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  4853. if (slotIndex == -1)
  4854. throw new Error("Slot not found: " + offsetMap.slot);
  4855. while (originalIndex != slotIndex)
  4856. unchanged[unchangedIndex++] = originalIndex++;
  4857. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  4858. }
  4859. while (originalIndex < slotCount)
  4860. unchanged[unchangedIndex++] = originalIndex++;
  4861. for (var i = slotCount - 1; i >= 0; i--)
  4862. if (drawOrder[i] == -1)
  4863. drawOrder[i] = unchanged[--unchangedIndex];
  4864. }
  4865. timeline.setFrame(frameIndex++, drawOrderMap.time, drawOrder);
  4866. }
  4867. timelines.push(timeline);
  4868. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4869. }
  4870. if (map.events) {
  4871. var timeline = new spine.EventTimeline(map.events.length);
  4872. var frameIndex = 0;
  4873. for (var i = 0; i < map.events.length; i++) {
  4874. var eventMap = map.events[i];
  4875. var eventData = skeletonData.findEvent(eventMap.name);
  4876. if (eventData == null)
  4877. throw new Error("Event not found: " + eventMap.name);
  4878. var event_5 = new spine.Event(spine.Utils.toSinglePrecision(eventMap.time), eventData);
  4879. event_5.intValue = this.getValue(eventMap, "int", eventData.intValue);
  4880. event_5.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  4881. event_5.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  4882. timeline.setFrame(frameIndex++, event_5);
  4883. }
  4884. timelines.push(timeline);
  4885. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  4886. }
  4887. if (isNaN(duration)) {
  4888. throw new Error("Error while parsing animation, duration is NaN");
  4889. }
  4890. skeletonData.animations.push(new spine.Animation(name, timelines, duration));
  4891. };
  4892. SkeletonJson.prototype.readCurve = function (map, timeline, frameIndex) {
  4893. if (!map.curve)
  4894. return;
  4895. if (map.curve === "stepped")
  4896. timeline.setStepped(frameIndex);
  4897. else if (Object.prototype.toString.call(map.curve) === '[object Array]') {
  4898. var curve = map.curve;
  4899. timeline.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]);
  4900. }
  4901. };
  4902. SkeletonJson.prototype.getValue = function (map, prop, defaultValue) {
  4903. return map[prop] !== undefined ? map[prop] : defaultValue;
  4904. };
  4905. SkeletonJson.blendModeFromString = function (str) {
  4906. str = str.toLowerCase();
  4907. if (str == "normal")
  4908. return spine.BlendMode.Normal;
  4909. if (str == "additive")
  4910. return spine.BlendMode.Additive;
  4911. if (str == "multiply")
  4912. return spine.BlendMode.Multiply;
  4913. if (str == "screen")
  4914. return spine.BlendMode.Screen;
  4915. throw new Error("Unknown blend mode: " + str);
  4916. };
  4917. SkeletonJson.positionModeFromString = function (str) {
  4918. str = str.toLowerCase();
  4919. if (str == "fixed")
  4920. return spine.PositionMode.Fixed;
  4921. if (str == "percent")
  4922. return spine.PositionMode.Percent;
  4923. throw new Error("Unknown position mode: " + str);
  4924. };
  4925. SkeletonJson.spacingModeFromString = function (str) {
  4926. str = str.toLowerCase();
  4927. if (str == "length")
  4928. return spine.SpacingMode.Length;
  4929. if (str == "fixed")
  4930. return spine.SpacingMode.Fixed;
  4931. if (str == "percent")
  4932. return spine.SpacingMode.Percent;
  4933. throw new Error("Unknown position mode: " + str);
  4934. };
  4935. SkeletonJson.rotateModeFromString = function (str) {
  4936. str = str.toLowerCase();
  4937. if (str == "tangent")
  4938. return spine.RotateMode.Tangent;
  4939. if (str == "chain")
  4940. return spine.RotateMode.Chain;
  4941. if (str == "chainscale")
  4942. return spine.RotateMode.ChainScale;
  4943. throw new Error("Unknown rotate mode: " + str);
  4944. };
  4945. SkeletonJson.transformModeFromString = function (str) {
  4946. str = str.toLowerCase();
  4947. if (str == "normal")
  4948. return spine.TransformMode.Normal;
  4949. if (str == "onlytranslation")
  4950. return spine.TransformMode.OnlyTranslation;
  4951. if (str == "norotationorreflection")
  4952. return spine.TransformMode.NoRotationOrReflection;
  4953. if (str == "noscale")
  4954. return spine.TransformMode.NoScale;
  4955. if (str == "noscaleorreflection")
  4956. return spine.TransformMode.NoScaleOrReflection;
  4957. throw new Error("Unknown transform mode: " + str);
  4958. };
  4959. return SkeletonJson;
  4960. }());
  4961. spine.SkeletonJson = SkeletonJson;
  4962. var LinkedMesh = (function () {
  4963. function LinkedMesh(mesh, skin, slotIndex, parent) {
  4964. this.mesh = mesh;
  4965. this.skin = skin;
  4966. this.slotIndex = slotIndex;
  4967. this.parent = parent;
  4968. }
  4969. return LinkedMesh;
  4970. }());
  4971. })(spine || (spine = {}));
  4972. var spine;
  4973. (function (spine) {
  4974. var Skin = (function () {
  4975. function Skin(name) {
  4976. this.attachments = new Array();
  4977. if (name == null)
  4978. throw new Error("name cannot be null.");
  4979. this.name = name;
  4980. }
  4981. Skin.prototype.addAttachment = function (slotIndex, name, attachment) {
  4982. if (attachment == null)
  4983. throw new Error("attachment cannot be null.");
  4984. var attachments = this.attachments;
  4985. if (slotIndex >= attachments.length)
  4986. attachments.length = slotIndex + 1;
  4987. if (!attachments[slotIndex])
  4988. attachments[slotIndex] = {};
  4989. attachments[slotIndex][name] = attachment;
  4990. };
  4991. Skin.prototype.getAttachment = function (slotIndex, name) {
  4992. var dictionary = this.attachments[slotIndex];
  4993. return dictionary ? dictionary[name] : null;
  4994. };
  4995. Skin.prototype.attachAll = function (skeleton, oldSkin) {
  4996. var slotIndex = 0;
  4997. for (var i = 0; i < skeleton.slots.length; i++) {
  4998. var slot = skeleton.slots[i];
  4999. var slotAttachment = slot.getAttachment();
  5000. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  5001. var dictionary = oldSkin.attachments[slotIndex];
  5002. for (var key in dictionary) {
  5003. var skinAttachment = dictionary[key];
  5004. if (slotAttachment == skinAttachment) {
  5005. var attachment = this.getAttachment(slotIndex, key);
  5006. if (attachment != null)
  5007. slot.setAttachment(attachment);
  5008. break;
  5009. }
  5010. }
  5011. }
  5012. slotIndex++;
  5013. }
  5014. };
  5015. return Skin;
  5016. }());
  5017. spine.Skin = Skin;
  5018. })(spine || (spine = {}));
  5019. var spine;
  5020. (function (spine) {
  5021. var Slot = (function () {
  5022. function Slot(data, bone) {
  5023. this.attachmentVertices = new Array();
  5024. if (data == null)
  5025. throw new Error("data cannot be null.");
  5026. if (bone == null)
  5027. throw new Error("bone cannot be null.");
  5028. this.data = data;
  5029. this.bone = bone;
  5030. this.color = new spine.Color();
  5031. this.darkColor = data.darkColor == null ? null : new spine.Color();
  5032. this.setToSetupPose();
  5033. }
  5034. Slot.prototype.getAttachment = function () {
  5035. return this.attachment;
  5036. };
  5037. Slot.prototype.setAttachment = function (attachment) {
  5038. if (this.attachment == attachment)
  5039. return;
  5040. this.attachment = attachment;
  5041. this.attachmentTime = this.bone.skeleton.time;
  5042. this.attachmentVertices.length = 0;
  5043. };
  5044. Slot.prototype.setAttachmentTime = function (time) {
  5045. this.attachmentTime = this.bone.skeleton.time - time;
  5046. };
  5047. Slot.prototype.getAttachmentTime = function () {
  5048. return this.bone.skeleton.time - this.attachmentTime;
  5049. };
  5050. Slot.prototype.setToSetupPose = function () {
  5051. this.color.setFromColor(this.data.color);
  5052. if (this.darkColor != null)
  5053. this.darkColor.setFromColor(this.data.darkColor);
  5054. if (this.data.attachmentName == null)
  5055. this.attachment = null;
  5056. else {
  5057. this.attachment = null;
  5058. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  5059. }
  5060. };
  5061. return Slot;
  5062. }());
  5063. spine.Slot = Slot;
  5064. })(spine || (spine = {}));
  5065. var spine;
  5066. (function (spine) {
  5067. var SlotData = (function () {
  5068. function SlotData(index, name, boneData) {
  5069. this.color = new spine.Color(1, 1, 1, 1);
  5070. if (index < 0)
  5071. throw new Error("index must be >= 0.");
  5072. if (name == null)
  5073. throw new Error("name cannot be null.");
  5074. if (boneData == null)
  5075. throw new Error("boneData cannot be null.");
  5076. this.index = index;
  5077. this.name = name;
  5078. this.boneData = boneData;
  5079. }
  5080. return SlotData;
  5081. }());
  5082. spine.SlotData = SlotData;
  5083. })(spine || (spine = {}));
  5084. var spine;
  5085. (function (spine) {
  5086. var Texture = (function () {
  5087. function Texture(image) {
  5088. this._image = image;
  5089. }
  5090. Texture.prototype.getImage = function () {
  5091. return this._image;
  5092. };
  5093. Texture.filterFromString = function (text) {
  5094. switch (text.toLowerCase()) {
  5095. case "nearest": return TextureFilter.Nearest;
  5096. case "linear": return TextureFilter.Linear;
  5097. case "mipmap": return TextureFilter.MipMap;
  5098. case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest;
  5099. case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest;
  5100. case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear;
  5101. case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear;
  5102. default: throw new Error("Unknown texture filter " + text);
  5103. }
  5104. };
  5105. Texture.wrapFromString = function (text) {
  5106. switch (text.toLowerCase()) {
  5107. case "mirroredtepeat": return TextureWrap.MirroredRepeat;
  5108. case "clamptoedge": return TextureWrap.ClampToEdge;
  5109. case "repeat": return TextureWrap.Repeat;
  5110. default: throw new Error("Unknown texture wrap " + text);
  5111. }
  5112. };
  5113. return Texture;
  5114. }());
  5115. spine.Texture = Texture;
  5116. var TextureFilter;
  5117. (function (TextureFilter) {
  5118. TextureFilter[TextureFilter["Nearest"] = 9728] = "Nearest";
  5119. TextureFilter[TextureFilter["Linear"] = 9729] = "Linear";
  5120. TextureFilter[TextureFilter["MipMap"] = 9987] = "MipMap";
  5121. TextureFilter[TextureFilter["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
  5122. TextureFilter[TextureFilter["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
  5123. TextureFilter[TextureFilter["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
  5124. TextureFilter[TextureFilter["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
  5125. })(TextureFilter = spine.TextureFilter || (spine.TextureFilter = {}));
  5126. var TextureWrap;
  5127. (function (TextureWrap) {
  5128. TextureWrap[TextureWrap["MirroredRepeat"] = 33648] = "MirroredRepeat";
  5129. TextureWrap[TextureWrap["ClampToEdge"] = 33071] = "ClampToEdge";
  5130. TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat";
  5131. })(TextureWrap = spine.TextureWrap || (spine.TextureWrap = {}));
  5132. var TextureRegion = (function () {
  5133. function TextureRegion() {
  5134. this.u = 0;
  5135. this.v = 0;
  5136. this.u2 = 0;
  5137. this.v2 = 0;
  5138. this.width = 0;
  5139. this.height = 0;
  5140. this.rotate = false;
  5141. this.offsetX = 0;
  5142. this.offsetY = 0;
  5143. this.originalWidth = 0;
  5144. this.originalHeight = 0;
  5145. }
  5146. return TextureRegion;
  5147. }());
  5148. spine.TextureRegion = TextureRegion;
  5149. var FakeTexture = (function (_super) {
  5150. __extends(FakeTexture, _super);
  5151. function FakeTexture() {
  5152. return _super !== null && _super.apply(this, arguments) || this;
  5153. }
  5154. FakeTexture.prototype.setFilters = function (minFilter, magFilter) { };
  5155. FakeTexture.prototype.setWraps = function (uWrap, vWrap) { };
  5156. FakeTexture.prototype.dispose = function () { };
  5157. return FakeTexture;
  5158. }(spine.Texture));
  5159. spine.FakeTexture = FakeTexture;
  5160. })(spine || (spine = {}));
  5161. var spine;
  5162. (function (spine) {
  5163. var TextureAtlas = (function () {
  5164. function TextureAtlas(atlasText, textureLoader) {
  5165. this.pages = new Array();
  5166. this.regions = new Array();
  5167. this.load(atlasText, textureLoader);
  5168. }
  5169. TextureAtlas.prototype.load = function (atlasText, textureLoader) {
  5170. if (textureLoader == null)
  5171. throw new Error("textureLoader cannot be null.");
  5172. var reader = new TextureAtlasReader(atlasText);
  5173. var tuple = new Array(4);
  5174. var page = null;
  5175. while (true) {
  5176. var line = reader.readLine();
  5177. if (line == null)
  5178. break;
  5179. line = line.trim();
  5180. if (line.length == 0)
  5181. page = null;
  5182. else if (!page) {
  5183. page = new TextureAtlasPage();
  5184. page.name = line;
  5185. if (reader.readTuple(tuple) == 2) {
  5186. page.width = parseInt(tuple[0]);
  5187. page.height = parseInt(tuple[1]);
  5188. reader.readTuple(tuple);
  5189. }
  5190. reader.readTuple(tuple);
  5191. page.minFilter = spine.Texture.filterFromString(tuple[0]);
  5192. page.magFilter = spine.Texture.filterFromString(tuple[1]);
  5193. var direction = reader.readValue();
  5194. page.uWrap = spine.TextureWrap.ClampToEdge;
  5195. page.vWrap = spine.TextureWrap.ClampToEdge;
  5196. if (direction == "x")
  5197. page.uWrap = spine.TextureWrap.Repeat;
  5198. else if (direction == "y")
  5199. page.vWrap = spine.TextureWrap.Repeat;
  5200. else if (direction == "xy")
  5201. page.uWrap = page.vWrap = spine.TextureWrap.Repeat;
  5202. page.texture = textureLoader(line);
  5203. page.texture.setFilters(page.minFilter, page.magFilter);
  5204. page.texture.setWraps(page.uWrap, page.vWrap);
  5205. page.width = page.texture.getImage().width;
  5206. page.height = page.texture.getImage().height;
  5207. this.pages.push(page);
  5208. }
  5209. else {
  5210. var region = new TextureAtlasRegion();
  5211. region.name = line;
  5212. region.page = page;
  5213. region.rotate = reader.readValue() == "true";
  5214. reader.readTuple(tuple);
  5215. var x = parseInt(tuple[0]);
  5216. var y = parseInt(tuple[1]);
  5217. reader.readTuple(tuple);
  5218. var width = parseInt(tuple[0]);
  5219. var height = parseInt(tuple[1]);
  5220. region.u = x / page.width;
  5221. region.v = y / page.height;
  5222. if (region.rotate) {
  5223. region.u2 = (x + height) / page.width;
  5224. region.v2 = (y + width) / page.height;
  5225. }
  5226. else {
  5227. region.u2 = (x + width) / page.width;
  5228. region.v2 = (y + height) / page.height;
  5229. }
  5230. region.x = x;
  5231. region.y = y;
  5232. region.width = Math.abs(width);
  5233. region.height = Math.abs(height);
  5234. if (reader.readTuple(tuple) == 4) {
  5235. if (reader.readTuple(tuple) == 4) {
  5236. reader.readTuple(tuple);
  5237. }
  5238. }
  5239. region.originalWidth = parseInt(tuple[0]);
  5240. region.originalHeight = parseInt(tuple[1]);
  5241. reader.readTuple(tuple);
  5242. region.offsetX = parseInt(tuple[0]);
  5243. region.offsetY = parseInt(tuple[1]);
  5244. region.index = parseInt(reader.readValue());
  5245. region.texture = page.texture;
  5246. this.regions.push(region);
  5247. }
  5248. }
  5249. };
  5250. TextureAtlas.prototype.findRegion = function (name) {
  5251. for (var i = 0; i < this.regions.length; i++) {
  5252. if (this.regions[i].name == name) {
  5253. return this.regions[i];
  5254. }
  5255. }
  5256. return null;
  5257. };
  5258. TextureAtlas.prototype.dispose = function () {
  5259. for (var i = 0; i < this.pages.length; i++) {
  5260. this.pages[i].texture.dispose();
  5261. }
  5262. };
  5263. return TextureAtlas;
  5264. }());
  5265. spine.TextureAtlas = TextureAtlas;
  5266. var TextureAtlasReader = (function () {
  5267. function TextureAtlasReader(text) {
  5268. this.index = 0;
  5269. this.lines = text.split(/\r\n|\r|\n/);
  5270. }
  5271. TextureAtlasReader.prototype.readLine = function () {
  5272. if (this.index >= this.lines.length)
  5273. return null;
  5274. return this.lines[this.index++];
  5275. };
  5276. TextureAtlasReader.prototype.readValue = function () {
  5277. var line = this.readLine();
  5278. var colon = line.indexOf(":");
  5279. if (colon == -1)
  5280. throw new Error("Invalid line: " + line);
  5281. return line.substring(colon + 1).trim();
  5282. };
  5283. TextureAtlasReader.prototype.readTuple = function (tuple) {
  5284. var line = this.readLine();
  5285. var colon = line.indexOf(":");
  5286. if (colon == -1)
  5287. throw new Error("Invalid line: " + line);
  5288. var i = 0, lastMatch = colon + 1;
  5289. for (; i < 3; i++) {
  5290. var comma = line.indexOf(",", lastMatch);
  5291. if (comma == -1)
  5292. break;
  5293. tuple[i] = line.substr(lastMatch, comma - lastMatch).trim();
  5294. lastMatch = comma + 1;
  5295. }
  5296. tuple[i] = line.substring(lastMatch).trim();
  5297. return i + 1;
  5298. };
  5299. return TextureAtlasReader;
  5300. }());
  5301. var TextureAtlasPage = (function () {
  5302. function TextureAtlasPage() {
  5303. }
  5304. return TextureAtlasPage;
  5305. }());
  5306. spine.TextureAtlasPage = TextureAtlasPage;
  5307. var TextureAtlasRegion = (function (_super) {
  5308. __extends(TextureAtlasRegion, _super);
  5309. function TextureAtlasRegion() {
  5310. return _super !== null && _super.apply(this, arguments) || this;
  5311. }
  5312. return TextureAtlasRegion;
  5313. }(spine.TextureRegion));
  5314. spine.TextureAtlasRegion = TextureAtlasRegion;
  5315. })(spine || (spine = {}));
  5316. var spine;
  5317. (function (spine) {
  5318. var TransformConstraint = (function () {
  5319. function TransformConstraint(data, skeleton) {
  5320. this.rotateMix = 0;
  5321. this.translateMix = 0;
  5322. this.scaleMix = 0;
  5323. this.shearMix = 0;
  5324. this.temp = new spine.Vector2();
  5325. if (data == null)
  5326. throw new Error("data cannot be null.");
  5327. if (skeleton == null)
  5328. throw new Error("skeleton cannot be null.");
  5329. this.data = data;
  5330. this.rotateMix = data.rotateMix;
  5331. this.translateMix = data.translateMix;
  5332. this.scaleMix = data.scaleMix;
  5333. this.shearMix = data.shearMix;
  5334. this.bones = new Array();
  5335. for (var i = 0; i < data.bones.length; i++)
  5336. this.bones.push(skeleton.findBone(data.bones[i].name));
  5337. this.target = skeleton.findBone(data.target.name);
  5338. }
  5339. TransformConstraint.prototype.apply = function () {
  5340. this.update();
  5341. };
  5342. TransformConstraint.prototype.update = function () {
  5343. if (this.data.local) {
  5344. if (this.data.relative)
  5345. this.applyRelativeLocal();
  5346. else
  5347. this.applyAbsoluteLocal();
  5348. }
  5349. else {
  5350. if (this.data.relative)
  5351. this.applyRelativeWorld();
  5352. else
  5353. this.applyAbsoluteWorld();
  5354. }
  5355. };
  5356. TransformConstraint.prototype.applyAbsoluteWorld = function () {
  5357. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5358. var target = this.target;
  5359. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  5360. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  5361. var offsetRotation = this.data.offsetRotation * degRadReflect;
  5362. var offsetShearY = this.data.offsetShearY * degRadReflect;
  5363. var bones = this.bones;
  5364. for (var i = 0, n = bones.length; i < n; i++) {
  5365. var bone = bones[i];
  5366. var modified = false;
  5367. if (rotateMix != 0) {
  5368. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  5369. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  5370. if (r > spine.MathUtils.PI)
  5371. r -= spine.MathUtils.PI2;
  5372. else if (r < -spine.MathUtils.PI)
  5373. r += spine.MathUtils.PI2;
  5374. r *= rotateMix;
  5375. var cos = Math.cos(r), sin = Math.sin(r);
  5376. bone.a = cos * a - sin * c;
  5377. bone.b = cos * b - sin * d;
  5378. bone.c = sin * a + cos * c;
  5379. bone.d = sin * b + cos * d;
  5380. modified = true;
  5381. }
  5382. if (translateMix != 0) {
  5383. var temp = this.temp;
  5384. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  5385. bone.worldX += (temp.x - bone.worldX) * translateMix;
  5386. bone.worldY += (temp.y - bone.worldY) * translateMix;
  5387. modified = true;
  5388. }
  5389. if (scaleMix > 0) {
  5390. var s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
  5391. var ts = Math.sqrt(ta * ta + tc * tc);
  5392. if (s > 0.00001)
  5393. s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
  5394. bone.a *= s;
  5395. bone.c *= s;
  5396. s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
  5397. ts = Math.sqrt(tb * tb + td * td);
  5398. if (s > 0.00001)
  5399. s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
  5400. bone.b *= s;
  5401. bone.d *= s;
  5402. modified = true;
  5403. }
  5404. if (shearMix > 0) {
  5405. var b = bone.b, d = bone.d;
  5406. var by = Math.atan2(d, b);
  5407. var r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
  5408. if (r > spine.MathUtils.PI)
  5409. r -= spine.MathUtils.PI2;
  5410. else if (r < -spine.MathUtils.PI)
  5411. r += spine.MathUtils.PI2;
  5412. r = by + (r + offsetShearY) * shearMix;
  5413. var s = Math.sqrt(b * b + d * d);
  5414. bone.b = Math.cos(r) * s;
  5415. bone.d = Math.sin(r) * s;
  5416. modified = true;
  5417. }
  5418. if (modified)
  5419. bone.appliedValid = false;
  5420. }
  5421. };
  5422. TransformConstraint.prototype.applyRelativeWorld = function () {
  5423. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5424. var target = this.target;
  5425. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  5426. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  5427. var offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  5428. var bones = this.bones;
  5429. for (var i = 0, n = bones.length; i < n; i++) {
  5430. var bone = bones[i];
  5431. var modified = false;
  5432. if (rotateMix != 0) {
  5433. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  5434. var r = Math.atan2(tc, ta) + offsetRotation;
  5435. if (r > spine.MathUtils.PI)
  5436. r -= spine.MathUtils.PI2;
  5437. else if (r < -spine.MathUtils.PI)
  5438. r += spine.MathUtils.PI2;
  5439. r *= rotateMix;
  5440. var cos = Math.cos(r), sin = Math.sin(r);
  5441. bone.a = cos * a - sin * c;
  5442. bone.b = cos * b - sin * d;
  5443. bone.c = sin * a + cos * c;
  5444. bone.d = sin * b + cos * d;
  5445. modified = true;
  5446. }
  5447. if (translateMix != 0) {
  5448. var temp = this.temp;
  5449. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  5450. bone.worldX += temp.x * translateMix;
  5451. bone.worldY += temp.y * translateMix;
  5452. modified = true;
  5453. }
  5454. if (scaleMix > 0) {
  5455. var s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
  5456. bone.a *= s;
  5457. bone.c *= s;
  5458. s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
  5459. bone.b *= s;
  5460. bone.d *= s;
  5461. modified = true;
  5462. }
  5463. if (shearMix > 0) {
  5464. var r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  5465. if (r > spine.MathUtils.PI)
  5466. r -= spine.MathUtils.PI2;
  5467. else if (r < -spine.MathUtils.PI)
  5468. r += spine.MathUtils.PI2;
  5469. var b = bone.b, d = bone.d;
  5470. r = Math.atan2(d, b) + (r - spine.MathUtils.PI / 2 + offsetShearY) * shearMix;
  5471. var s = Math.sqrt(b * b + d * d);
  5472. bone.b = Math.cos(r) * s;
  5473. bone.d = Math.sin(r) * s;
  5474. modified = true;
  5475. }
  5476. if (modified)
  5477. bone.appliedValid = false;
  5478. }
  5479. };
  5480. TransformConstraint.prototype.applyAbsoluteLocal = function () {
  5481. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5482. var target = this.target;
  5483. if (!target.appliedValid)
  5484. target.updateAppliedTransform();
  5485. var bones = this.bones;
  5486. for (var i = 0, n = bones.length; i < n; i++) {
  5487. var bone = bones[i];
  5488. if (!bone.appliedValid)
  5489. bone.updateAppliedTransform();
  5490. var rotation = bone.arotation;
  5491. if (rotateMix != 0) {
  5492. var r = target.arotation - rotation + this.data.offsetRotation;
  5493. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  5494. rotation += r * rotateMix;
  5495. }
  5496. var x = bone.ax, y = bone.ay;
  5497. if (translateMix != 0) {
  5498. x += (target.ax - x + this.data.offsetX) * translateMix;
  5499. y += (target.ay - y + this.data.offsetY) * translateMix;
  5500. }
  5501. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  5502. if (scaleMix > 0) {
  5503. if (scaleX > 0.00001)
  5504. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
  5505. if (scaleY > 0.00001)
  5506. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
  5507. }
  5508. var shearY = bone.ashearY;
  5509. if (shearMix > 0) {
  5510. var r = target.ashearY - shearY + this.data.offsetShearY;
  5511. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  5512. bone.shearY += r * shearMix;
  5513. }
  5514. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  5515. }
  5516. };
  5517. TransformConstraint.prototype.applyRelativeLocal = function () {
  5518. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5519. var target = this.target;
  5520. if (!target.appliedValid)
  5521. target.updateAppliedTransform();
  5522. var bones = this.bones;
  5523. for (var i = 0, n = bones.length; i < n; i++) {
  5524. var bone = bones[i];
  5525. if (!bone.appliedValid)
  5526. bone.updateAppliedTransform();
  5527. var rotation = bone.arotation;
  5528. if (rotateMix != 0)
  5529. rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
  5530. var x = bone.ax, y = bone.ay;
  5531. if (translateMix != 0) {
  5532. x += (target.ax + this.data.offsetX) * translateMix;
  5533. y += (target.ay + this.data.offsetY) * translateMix;
  5534. }
  5535. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  5536. if (scaleMix > 0) {
  5537. if (scaleX > 0.00001)
  5538. scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
  5539. if (scaleY > 0.00001)
  5540. scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
  5541. }
  5542. var shearY = bone.ashearY;
  5543. if (shearMix > 0)
  5544. shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
  5545. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  5546. }
  5547. };
  5548. TransformConstraint.prototype.getOrder = function () {
  5549. return this.data.order;
  5550. };
  5551. return TransformConstraint;
  5552. }());
  5553. spine.TransformConstraint = TransformConstraint;
  5554. })(spine || (spine = {}));
  5555. var spine;
  5556. (function (spine) {
  5557. var TransformConstraintData = (function () {
  5558. function TransformConstraintData(name) {
  5559. this.order = 0;
  5560. this.bones = new Array();
  5561. this.rotateMix = 0;
  5562. this.translateMix = 0;
  5563. this.scaleMix = 0;
  5564. this.shearMix = 0;
  5565. this.offsetRotation = 0;
  5566. this.offsetX = 0;
  5567. this.offsetY = 0;
  5568. this.offsetScaleX = 0;
  5569. this.offsetScaleY = 0;
  5570. this.offsetShearY = 0;
  5571. this.relative = false;
  5572. this.local = false;
  5573. if (name == null)
  5574. throw new Error("name cannot be null.");
  5575. this.name = name;
  5576. }
  5577. return TransformConstraintData;
  5578. }());
  5579. spine.TransformConstraintData = TransformConstraintData;
  5580. })(spine || (spine = {}));
  5581. var spine;
  5582. (function (spine) {
  5583. var Triangulator = (function () {
  5584. function Triangulator() {
  5585. this.convexPolygons = new Array();
  5586. this.convexPolygonsIndices = new Array();
  5587. this.indicesArray = new Array();
  5588. this.isConcaveArray = new Array();
  5589. this.triangles = new Array();
  5590. this.polygonPool = new spine.Pool(function () {
  5591. return new Array();
  5592. });
  5593. this.polygonIndicesPool = new spine.Pool(function () {
  5594. return new Array();
  5595. });
  5596. }
  5597. Triangulator.prototype.triangulate = function (verticesArray) {
  5598. var vertices = verticesArray;
  5599. var vertexCount = verticesArray.length >> 1;
  5600. var indices = this.indicesArray;
  5601. indices.length = 0;
  5602. for (var i = 0; i < vertexCount; i++)
  5603. indices[i] = i;
  5604. var isConcave = this.isConcaveArray;
  5605. isConcave.length = 0;
  5606. for (var i = 0, n = vertexCount; i < n; ++i)
  5607. isConcave[i] = Triangulator.isConcave(i, vertexCount, vertices, indices);
  5608. var triangles = this.triangles;
  5609. triangles.length = 0;
  5610. while (vertexCount > 3) {
  5611. var previous = vertexCount - 1, i = 0, next = 1;
  5612. while (true) {
  5613. outer: if (!isConcave[i]) {
  5614. var p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1;
  5615. var p1x = vertices[p1], p1y = vertices[p1 + 1];
  5616. var p2x = vertices[p2], p2y = vertices[p2 + 1];
  5617. var p3x = vertices[p3], p3y = vertices[p3 + 1];
  5618. for (var ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
  5619. if (!isConcave[ii])
  5620. continue;
  5621. var v = indices[ii] << 1;
  5622. var vx = vertices[v], vy = vertices[v + 1];
  5623. if (Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
  5624. if (Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
  5625. if (Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy))
  5626. break outer;
  5627. }
  5628. }
  5629. }
  5630. break;
  5631. }
  5632. if (next == 0) {
  5633. do {
  5634. if (!isConcave[i])
  5635. break;
  5636. i--;
  5637. } while (i > 0);
  5638. break;
  5639. }
  5640. previous = i;
  5641. i = next;
  5642. next = (next + 1) % vertexCount;
  5643. }
  5644. triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
  5645. triangles.push(indices[i]);
  5646. triangles.push(indices[(i + 1) % vertexCount]);
  5647. indices.splice(i, 1);
  5648. isConcave.splice(i, 1);
  5649. vertexCount--;
  5650. var previousIndex = (vertexCount + i - 1) % vertexCount;
  5651. var nextIndex = i == vertexCount ? 0 : i;
  5652. isConcave[previousIndex] = Triangulator.isConcave(previousIndex, vertexCount, vertices, indices);
  5653. isConcave[nextIndex] = Triangulator.isConcave(nextIndex, vertexCount, vertices, indices);
  5654. }
  5655. if (vertexCount == 3) {
  5656. triangles.push(indices[2]);
  5657. triangles.push(indices[0]);
  5658. triangles.push(indices[1]);
  5659. }
  5660. return triangles;
  5661. };
  5662. Triangulator.prototype.decompose = function (verticesArray, triangles) {
  5663. var vertices = verticesArray;
  5664. var convexPolygons = this.convexPolygons;
  5665. this.polygonPool.freeAll(convexPolygons);
  5666. convexPolygons.length = 0;
  5667. var convexPolygonsIndices = this.convexPolygonsIndices;
  5668. this.polygonIndicesPool.freeAll(convexPolygonsIndices);
  5669. convexPolygonsIndices.length = 0;
  5670. var polygonIndices = this.polygonIndicesPool.obtain();
  5671. polygonIndices.length = 0;
  5672. var polygon = this.polygonPool.obtain();
  5673. polygon.length = 0;
  5674. var fanBaseIndex = -1, lastWinding = 0;
  5675. for (var i = 0, n = triangles.length; i < n; i += 3) {
  5676. var t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1;
  5677. var x1 = vertices[t1], y1 = vertices[t1 + 1];
  5678. var x2 = vertices[t2], y2 = vertices[t2 + 1];
  5679. var x3 = vertices[t3], y3 = vertices[t3 + 1];
  5680. var merged = false;
  5681. if (fanBaseIndex == t1) {
  5682. var o = polygon.length - 4;
  5683. var winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
  5684. var winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
  5685. if (winding1 == lastWinding && winding2 == lastWinding) {
  5686. polygon.push(x3);
  5687. polygon.push(y3);
  5688. polygonIndices.push(t3);
  5689. merged = true;
  5690. }
  5691. }
  5692. if (!merged) {
  5693. if (polygon.length > 0) {
  5694. convexPolygons.push(polygon);
  5695. convexPolygonsIndices.push(polygonIndices);
  5696. }
  5697. else {
  5698. this.polygonPool.free(polygon);
  5699. this.polygonIndicesPool.free(polygonIndices);
  5700. }
  5701. polygon = this.polygonPool.obtain();
  5702. polygon.length = 0;
  5703. polygon.push(x1);
  5704. polygon.push(y1);
  5705. polygon.push(x2);
  5706. polygon.push(y2);
  5707. polygon.push(x3);
  5708. polygon.push(y3);
  5709. polygonIndices = this.polygonIndicesPool.obtain();
  5710. polygonIndices.length = 0;
  5711. polygonIndices.push(t1);
  5712. polygonIndices.push(t2);
  5713. polygonIndices.push(t3);
  5714. lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
  5715. fanBaseIndex = t1;
  5716. }
  5717. }
  5718. if (polygon.length > 0) {
  5719. convexPolygons.push(polygon);
  5720. convexPolygonsIndices.push(polygonIndices);
  5721. }
  5722. for (var i = 0, n = convexPolygons.length; i < n; i++) {
  5723. polygonIndices = convexPolygonsIndices[i];
  5724. if (polygonIndices.length == 0)
  5725. continue;
  5726. var firstIndex = polygonIndices[0];
  5727. var lastIndex = polygonIndices[polygonIndices.length - 1];
  5728. polygon = convexPolygons[i];
  5729. var o = polygon.length - 4;
  5730. var prevPrevX = polygon[o], prevPrevY = polygon[o + 1];
  5731. var prevX = polygon[o + 2], prevY = polygon[o + 3];
  5732. var firstX = polygon[0], firstY = polygon[1];
  5733. var secondX = polygon[2], secondY = polygon[3];
  5734. var winding = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
  5735. for (var ii = 0; ii < n; ii++) {
  5736. if (ii == i)
  5737. continue;
  5738. var otherIndices = convexPolygonsIndices[ii];
  5739. if (otherIndices.length != 3)
  5740. continue;
  5741. var otherFirstIndex = otherIndices[0];
  5742. var otherSecondIndex = otherIndices[1];
  5743. var otherLastIndex = otherIndices[2];
  5744. var otherPoly = convexPolygons[ii];
  5745. var x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1];
  5746. if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex)
  5747. continue;
  5748. var winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
  5749. var winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
  5750. if (winding1 == winding && winding2 == winding) {
  5751. otherPoly.length = 0;
  5752. otherIndices.length = 0;
  5753. polygon.push(x3);
  5754. polygon.push(y3);
  5755. polygonIndices.push(otherLastIndex);
  5756. prevPrevX = prevX;
  5757. prevPrevY = prevY;
  5758. prevX = x3;
  5759. prevY = y3;
  5760. ii = 0;
  5761. }
  5762. }
  5763. }
  5764. for (var i = convexPolygons.length - 1; i >= 0; i--) {
  5765. polygon = convexPolygons[i];
  5766. if (polygon.length == 0) {
  5767. convexPolygons.splice(i, 1);
  5768. this.polygonPool.free(polygon);
  5769. polygonIndices = convexPolygonsIndices[i];
  5770. convexPolygonsIndices.splice(i, 1);
  5771. this.polygonIndicesPool.free(polygonIndices);
  5772. }
  5773. }
  5774. return convexPolygons;
  5775. };
  5776. Triangulator.isConcave = function (index, vertexCount, vertices, indices) {
  5777. var previous = indices[(vertexCount + index - 1) % vertexCount] << 1;
  5778. var current = indices[index] << 1;
  5779. var next = indices[(index + 1) % vertexCount] << 1;
  5780. return !this.positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]);
  5781. };
  5782. Triangulator.positiveArea = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  5783. return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
  5784. };
  5785. Triangulator.winding = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  5786. var px = p2x - p1x, py = p2y - p1y;
  5787. return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
  5788. };
  5789. return Triangulator;
  5790. }());
  5791. spine.Triangulator = Triangulator;
  5792. })(spine || (spine = {}));
  5793. var spine;
  5794. (function (spine) {
  5795. var IntSet = (function () {
  5796. function IntSet() {
  5797. this.array = new Array();
  5798. }
  5799. IntSet.prototype.add = function (value) {
  5800. var contains = this.contains(value);
  5801. this.array[value | 0] = value | 0;
  5802. return !contains;
  5803. };
  5804. IntSet.prototype.contains = function (value) {
  5805. return this.array[value | 0] != undefined;
  5806. };
  5807. IntSet.prototype.remove = function (value) {
  5808. this.array[value | 0] = undefined;
  5809. };
  5810. IntSet.prototype.clear = function () {
  5811. this.array.length = 0;
  5812. };
  5813. return IntSet;
  5814. }());
  5815. spine.IntSet = IntSet;
  5816. var Color = (function () {
  5817. function Color(r, g, b, a) {
  5818. if (r === void 0) { r = 0; }
  5819. if (g === void 0) { g = 0; }
  5820. if (b === void 0) { b = 0; }
  5821. if (a === void 0) { a = 0; }
  5822. this.r = r;
  5823. this.g = g;
  5824. this.b = b;
  5825. this.a = a;
  5826. }
  5827. Color.prototype.set = function (r, g, b, a) {
  5828. this.r = r;
  5829. this.g = g;
  5830. this.b = b;
  5831. this.a = a;
  5832. this.clamp();
  5833. return this;
  5834. };
  5835. Color.prototype.setFromColor = function (c) {
  5836. this.r = c.r;
  5837. this.g = c.g;
  5838. this.b = c.b;
  5839. this.a = c.a;
  5840. return this;
  5841. };
  5842. Color.prototype.setFromString = function (hex) {
  5843. hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
  5844. this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
  5845. this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
  5846. this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
  5847. this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
  5848. return this;
  5849. };
  5850. Color.prototype.add = function (r, g, b, a) {
  5851. this.r += r;
  5852. this.g += g;
  5853. this.b += b;
  5854. this.a += a;
  5855. this.clamp();
  5856. return this;
  5857. };
  5858. Color.prototype.clamp = function () {
  5859. if (this.r < 0)
  5860. this.r = 0;
  5861. else if (this.r > 1)
  5862. this.r = 1;
  5863. if (this.g < 0)
  5864. this.g = 0;
  5865. else if (this.g > 1)
  5866. this.g = 1;
  5867. if (this.b < 0)
  5868. this.b = 0;
  5869. else if (this.b > 1)
  5870. this.b = 1;
  5871. if (this.a < 0)
  5872. this.a = 0;
  5873. else if (this.a > 1)
  5874. this.a = 1;
  5875. return this;
  5876. };
  5877. Color.WHITE = new Color(1, 1, 1, 1);
  5878. Color.RED = new Color(1, 0, 0, 1);
  5879. Color.GREEN = new Color(0, 1, 0, 1);
  5880. Color.BLUE = new Color(0, 0, 1, 1);
  5881. Color.MAGENTA = new Color(1, 0, 1, 1);
  5882. return Color;
  5883. }());
  5884. spine.Color = Color;
  5885. var MathUtils = (function () {
  5886. function MathUtils() {
  5887. }
  5888. MathUtils.clamp = function (value, min, max) {
  5889. if (value < min)
  5890. return min;
  5891. if (value > max)
  5892. return max;
  5893. return value;
  5894. };
  5895. MathUtils.cosDeg = function (degrees) {
  5896. return Math.cos(degrees * MathUtils.degRad);
  5897. };
  5898. MathUtils.sinDeg = function (degrees) {
  5899. return Math.sin(degrees * MathUtils.degRad);
  5900. };
  5901. MathUtils.signum = function (value) {
  5902. return value > 0 ? 1 : value < 0 ? -1 : 0;
  5903. };
  5904. MathUtils.toInt = function (x) {
  5905. return x > 0 ? Math.floor(x) : Math.ceil(x);
  5906. };
  5907. MathUtils.cbrt = function (x) {
  5908. var y = Math.pow(Math.abs(x), 1 / 3);
  5909. return x < 0 ? -y : y;
  5910. };
  5911. MathUtils.randomTriangular = function (min, max) {
  5912. return MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
  5913. };
  5914. MathUtils.randomTriangularWith = function (min, max, mode) {
  5915. var u = Math.random();
  5916. var d = max - min;
  5917. if (u <= (mode - min) / d)
  5918. return min + Math.sqrt(u * d * (mode - min));
  5919. return max - Math.sqrt((1 - u) * d * (max - mode));
  5920. };
  5921. MathUtils.PI = 3.1415927;
  5922. MathUtils.PI2 = MathUtils.PI * 2;
  5923. MathUtils.radiansToDegrees = 180 / MathUtils.PI;
  5924. MathUtils.radDeg = MathUtils.radiansToDegrees;
  5925. MathUtils.degreesToRadians = MathUtils.PI / 180;
  5926. MathUtils.degRad = MathUtils.degreesToRadians;
  5927. return MathUtils;
  5928. }());
  5929. spine.MathUtils = MathUtils;
  5930. var Interpolation = (function () {
  5931. function Interpolation() {
  5932. }
  5933. Interpolation.prototype.apply = function (start, end, a) {
  5934. return start + (end - start) * this.applyInternal(a);
  5935. };
  5936. return Interpolation;
  5937. }());
  5938. spine.Interpolation = Interpolation;
  5939. var Pow = (function (_super) {
  5940. __extends(Pow, _super);
  5941. function Pow(power) {
  5942. var _this = _super.call(this) || this;
  5943. _this.power = 2;
  5944. _this.power = power;
  5945. return _this;
  5946. }
  5947. Pow.prototype.applyInternal = function (a) {
  5948. if (a <= 0.5)
  5949. return Math.pow(a * 2, this.power) / 2;
  5950. return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
  5951. };
  5952. return Pow;
  5953. }(Interpolation));
  5954. spine.Pow = Pow;
  5955. var PowOut = (function (_super) {
  5956. __extends(PowOut, _super);
  5957. function PowOut(power) {
  5958. return _super.call(this, power) || this;
  5959. }
  5960. PowOut.prototype.applyInternal = function (a) {
  5961. return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
  5962. };
  5963. return PowOut;
  5964. }(Pow));
  5965. spine.PowOut = PowOut;
  5966. var Utils = (function () {
  5967. function Utils() {
  5968. }
  5969. Utils.arrayCopy = function (source, sourceStart, dest, destStart, numElements) {
  5970. for (var i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  5971. dest[j] = source[i];
  5972. }
  5973. };
  5974. Utils.setArraySize = function (array, size, value) {
  5975. if (value === void 0) { value = 0; }
  5976. var oldSize = array.length;
  5977. if (oldSize == size)
  5978. return array;
  5979. array.length = size;
  5980. if (oldSize < size) {
  5981. for (var i = oldSize; i < size; i++)
  5982. array[i] = value;
  5983. }
  5984. return array;
  5985. };
  5986. Utils.ensureArrayCapacity = function (array, size, value) {
  5987. if (value === void 0) { value = 0; }
  5988. if (array.length >= size)
  5989. return array;
  5990. return Utils.setArraySize(array, size, value);
  5991. };
  5992. Utils.newArray = function (size, defaultValue) {
  5993. var array = new Array(size);
  5994. for (var i = 0; i < size; i++)
  5995. array[i] = defaultValue;
  5996. return array;
  5997. };
  5998. Utils.newFloatArray = function (size) {
  5999. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  6000. return new Float32Array(size);
  6001. }
  6002. else {
  6003. var array = new Array(size);
  6004. for (var i = 0; i < array.length; i++)
  6005. array[i] = 0;
  6006. return array;
  6007. }
  6008. };
  6009. Utils.newShortArray = function (size) {
  6010. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  6011. return new Int16Array(size);
  6012. }
  6013. else {
  6014. var array = new Array(size);
  6015. for (var i = 0; i < array.length; i++)
  6016. array[i] = 0;
  6017. return array;
  6018. }
  6019. };
  6020. Utils.toFloatArray = function (array) {
  6021. return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  6022. };
  6023. Utils.toSinglePrecision = function (value) {
  6024. return Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
  6025. };
  6026. Utils.webkit602BugfixHelper = function (alpha, pose) {
  6027. };
  6028. Utils.SUPPORTS_TYPED_ARRAYS = typeof (Float32Array) !== "undefined";
  6029. return Utils;
  6030. }());
  6031. spine.Utils = Utils;
  6032. var DebugUtils = (function () {
  6033. function DebugUtils() {
  6034. }
  6035. DebugUtils.logBones = function (skeleton) {
  6036. for (var i = 0; i < skeleton.bones.length; i++) {
  6037. var bone = skeleton.bones[i];
  6038. console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
  6039. }
  6040. };
  6041. return DebugUtils;
  6042. }());
  6043. spine.DebugUtils = DebugUtils;
  6044. var Pool = (function () {
  6045. function Pool(instantiator) {
  6046. this.items = new Array();
  6047. this.instantiator = instantiator;
  6048. }
  6049. Pool.prototype.obtain = function () {
  6050. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  6051. };
  6052. Pool.prototype.free = function (item) {
  6053. if (item.reset)
  6054. item.reset();
  6055. this.items.push(item);
  6056. };
  6057. Pool.prototype.freeAll = function (items) {
  6058. for (var i = 0; i < items.length; i++) {
  6059. if (items[i].reset)
  6060. items[i].reset();
  6061. this.items[i] = items[i];
  6062. }
  6063. };
  6064. Pool.prototype.clear = function () {
  6065. this.items.length = 0;
  6066. };
  6067. return Pool;
  6068. }());
  6069. spine.Pool = Pool;
  6070. var Vector2 = (function () {
  6071. function Vector2(x, y) {
  6072. if (x === void 0) { x = 0; }
  6073. if (y === void 0) { y = 0; }
  6074. this.x = x;
  6075. this.y = y;
  6076. }
  6077. Vector2.prototype.set = function (x, y) {
  6078. this.x = x;
  6079. this.y = y;
  6080. return this;
  6081. };
  6082. Vector2.prototype.length = function () {
  6083. var x = this.x;
  6084. var y = this.y;
  6085. return Math.sqrt(x * x + y * y);
  6086. };
  6087. Vector2.prototype.normalize = function () {
  6088. var len = this.length();
  6089. if (len != 0) {
  6090. this.x /= len;
  6091. this.y /= len;
  6092. }
  6093. return this;
  6094. };
  6095. return Vector2;
  6096. }());
  6097. spine.Vector2 = Vector2;
  6098. var TimeKeeper = (function () {
  6099. function TimeKeeper() {
  6100. this.maxDelta = 0.064;
  6101. this.framesPerSecond = 0;
  6102. this.delta = 0;
  6103. this.totalTime = 0;
  6104. this.lastTime = Date.now() / 1000;
  6105. this.frameCount = 0;
  6106. this.frameTime = 0;
  6107. }
  6108. TimeKeeper.prototype.update = function () {
  6109. var now = Date.now() / 1000;
  6110. this.delta = now - this.lastTime;
  6111. this.frameTime += this.delta;
  6112. this.totalTime += this.delta;
  6113. if (this.delta > this.maxDelta)
  6114. this.delta = this.maxDelta;
  6115. this.lastTime = now;
  6116. this.frameCount++;
  6117. if (this.frameTime > 1) {
  6118. this.framesPerSecond = this.frameCount / this.frameTime;
  6119. this.frameTime = 0;
  6120. this.frameCount = 0;
  6121. }
  6122. };
  6123. return TimeKeeper;
  6124. }());
  6125. spine.TimeKeeper = TimeKeeper;
  6126. var WindowedMean = (function () {
  6127. function WindowedMean(windowSize) {
  6128. if (windowSize === void 0) { windowSize = 32; }
  6129. this.addedValues = 0;
  6130. this.lastValue = 0;
  6131. this.mean = 0;
  6132. this.dirty = true;
  6133. this.values = new Array(windowSize);
  6134. }
  6135. WindowedMean.prototype.hasEnoughData = function () {
  6136. return this.addedValues >= this.values.length;
  6137. };
  6138. WindowedMean.prototype.addValue = function (value) {
  6139. if (this.addedValues < this.values.length)
  6140. this.addedValues++;
  6141. this.values[this.lastValue++] = value;
  6142. if (this.lastValue > this.values.length - 1)
  6143. this.lastValue = 0;
  6144. this.dirty = true;
  6145. };
  6146. WindowedMean.prototype.getMean = function () {
  6147. if (this.hasEnoughData()) {
  6148. if (this.dirty) {
  6149. var mean = 0;
  6150. for (var i = 0; i < this.values.length; i++) {
  6151. mean += this.values[i];
  6152. }
  6153. this.mean = mean / this.values.length;
  6154. this.dirty = false;
  6155. }
  6156. return this.mean;
  6157. }
  6158. else {
  6159. return 0;
  6160. }
  6161. };
  6162. return WindowedMean;
  6163. }());
  6164. spine.WindowedMean = WindowedMean;
  6165. })(spine || (spine = {}));
  6166. (function () {
  6167. if (!Math.fround) {
  6168. Math.fround = (function (array) {
  6169. return function (x) {
  6170. return array[0] = x, array[0];
  6171. };
  6172. })(new Float32Array(1));
  6173. }
  6174. })();
  6175. var spine;
  6176. (function (spine) {
  6177. var Attachment = (function () {
  6178. function Attachment(name) {
  6179. if (name == null)
  6180. throw new Error("name cannot be null.");
  6181. this.name = name;
  6182. }
  6183. return Attachment;
  6184. }());
  6185. spine.Attachment = Attachment;
  6186. var VertexAttachment = (function (_super) {
  6187. __extends(VertexAttachment, _super);
  6188. function VertexAttachment(name) {
  6189. var _this = _super.call(this, name) || this;
  6190. _this.id = (VertexAttachment.nextID++ & 65535) << 11;
  6191. _this.worldVerticesLength = 0;
  6192. return _this;
  6193. }
  6194. VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
  6195. count = offset + (count >> 1) * stride;
  6196. var skeleton = slot.bone.skeleton;
  6197. var deformArray = slot.attachmentVertices;
  6198. var vertices = this.vertices;
  6199. var bones = this.bones;
  6200. if (bones == null) {
  6201. if (deformArray.length > 0)
  6202. vertices = deformArray;
  6203. var bone = slot.bone;
  6204. var x = bone.worldX;
  6205. var y = bone.worldY;
  6206. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6207. for (var v_1 = start, w = offset; w < count; v_1 += 2, w += stride) {
  6208. var vx = vertices[v_1], vy = vertices[v_1 + 1];
  6209. worldVertices[w] = vx * a + vy * b + x;
  6210. worldVertices[w + 1] = vx * c + vy * d + y;
  6211. }
  6212. return;
  6213. }
  6214. var v = 0, skip = 0;
  6215. for (var i = 0; i < start; i += 2) {
  6216. var n = bones[v];
  6217. v += n + 1;
  6218. skip += n;
  6219. }
  6220. var skeletonBones = skeleton.bones;
  6221. if (deformArray.length == 0) {
  6222. for (var w = offset, b = skip * 3; w < count; w += stride) {
  6223. var wx = 0, wy = 0;
  6224. var n = bones[v++];
  6225. n += v;
  6226. for (; v < n; v++, b += 3) {
  6227. var bone = skeletonBones[bones[v]];
  6228. var vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  6229. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  6230. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  6231. }
  6232. worldVertices[w] = wx;
  6233. worldVertices[w + 1] = wy;
  6234. }
  6235. }
  6236. else {
  6237. var deform = deformArray;
  6238. for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  6239. var wx = 0, wy = 0;
  6240. var n = bones[v++];
  6241. n += v;
  6242. for (; v < n; v++, b += 3, f += 2) {
  6243. var bone = skeletonBones[bones[v]];
  6244. var vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  6245. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  6246. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  6247. }
  6248. worldVertices[w] = wx;
  6249. worldVertices[w + 1] = wy;
  6250. }
  6251. }
  6252. };
  6253. VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
  6254. return this == sourceAttachment;
  6255. };
  6256. VertexAttachment.nextID = 0;
  6257. return VertexAttachment;
  6258. }(Attachment));
  6259. spine.VertexAttachment = VertexAttachment;
  6260. })(spine || (spine = {}));
  6261. var spine;
  6262. (function (spine) {
  6263. var AttachmentType;
  6264. (function (AttachmentType) {
  6265. AttachmentType[AttachmentType["Region"] = 0] = "Region";
  6266. AttachmentType[AttachmentType["BoundingBox"] = 1] = "BoundingBox";
  6267. AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
  6268. AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
  6269. AttachmentType[AttachmentType["Path"] = 4] = "Path";
  6270. AttachmentType[AttachmentType["Point"] = 5] = "Point";
  6271. })(AttachmentType = spine.AttachmentType || (spine.AttachmentType = {}));
  6272. })(spine || (spine = {}));
  6273. var spine;
  6274. (function (spine) {
  6275. var BoundingBoxAttachment = (function (_super) {
  6276. __extends(BoundingBoxAttachment, _super);
  6277. function BoundingBoxAttachment(name) {
  6278. var _this = _super.call(this, name) || this;
  6279. _this.color = new spine.Color(1, 1, 1, 1);
  6280. return _this;
  6281. }
  6282. return BoundingBoxAttachment;
  6283. }(spine.VertexAttachment));
  6284. spine.BoundingBoxAttachment = BoundingBoxAttachment;
  6285. })(spine || (spine = {}));
  6286. var spine;
  6287. (function (spine) {
  6288. var ClippingAttachment = (function (_super) {
  6289. __extends(ClippingAttachment, _super);
  6290. function ClippingAttachment(name) {
  6291. var _this = _super.call(this, name) || this;
  6292. _this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1);
  6293. return _this;
  6294. }
  6295. return ClippingAttachment;
  6296. }(spine.VertexAttachment));
  6297. spine.ClippingAttachment = ClippingAttachment;
  6298. })(spine || (spine = {}));
  6299. var spine;
  6300. (function (spine) {
  6301. var MeshAttachment = (function (_super) {
  6302. __extends(MeshAttachment, _super);
  6303. function MeshAttachment(name) {
  6304. var _this = _super.call(this, name) || this;
  6305. _this.color = new spine.Color(1, 1, 1, 1);
  6306. _this.inheritDeform = false;
  6307. _this.tempColor = new spine.Color(0, 0, 0, 0);
  6308. return _this;
  6309. }
  6310. MeshAttachment.prototype.updateUVs = function () {
  6311. var u = 0, v = 0, width = 0, height = 0;
  6312. if (this.region == null) {
  6313. u = v = 0;
  6314. width = height = 1;
  6315. }
  6316. else {
  6317. u = this.region.u;
  6318. v = this.region.v;
  6319. width = this.region.u2 - u;
  6320. height = this.region.v2 - v;
  6321. }
  6322. var regionUVs = this.regionUVs;
  6323. if (this.uvs == null || this.uvs.length != regionUVs.length)
  6324. this.uvs = spine.Utils.newFloatArray(regionUVs.length);
  6325. var uvs = this.uvs;
  6326. if (this.region.rotate) {
  6327. for (var i = 0, n = uvs.length; i < n; i += 2) {
  6328. uvs[i] = u + regionUVs[i + 1] * width;
  6329. uvs[i + 1] = v + height - regionUVs[i] * height;
  6330. }
  6331. }
  6332. else {
  6333. for (var i = 0, n = uvs.length; i < n; i += 2) {
  6334. uvs[i] = u + regionUVs[i] * width;
  6335. uvs[i + 1] = v + regionUVs[i + 1] * height;
  6336. }
  6337. }
  6338. };
  6339. MeshAttachment.prototype.applyDeform = function (sourceAttachment) {
  6340. return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
  6341. };
  6342. MeshAttachment.prototype.getParentMesh = function () {
  6343. return this.parentMesh;
  6344. };
  6345. MeshAttachment.prototype.setParentMesh = function (parentMesh) {
  6346. this.parentMesh = parentMesh;
  6347. if (parentMesh != null) {
  6348. this.bones = parentMesh.bones;
  6349. this.vertices = parentMesh.vertices;
  6350. this.worldVerticesLength = parentMesh.worldVerticesLength;
  6351. this.regionUVs = parentMesh.regionUVs;
  6352. this.triangles = parentMesh.triangles;
  6353. this.hullLength = parentMesh.hullLength;
  6354. this.worldVerticesLength = parentMesh.worldVerticesLength;
  6355. }
  6356. };
  6357. return MeshAttachment;
  6358. }(spine.VertexAttachment));
  6359. spine.MeshAttachment = MeshAttachment;
  6360. })(spine || (spine = {}));
  6361. var spine;
  6362. (function (spine) {
  6363. var PathAttachment = (function (_super) {
  6364. __extends(PathAttachment, _super);
  6365. function PathAttachment(name) {
  6366. var _this = _super.call(this, name) || this;
  6367. _this.closed = false;
  6368. _this.constantSpeed = false;
  6369. _this.color = new spine.Color(1, 1, 1, 1);
  6370. return _this;
  6371. }
  6372. return PathAttachment;
  6373. }(spine.VertexAttachment));
  6374. spine.PathAttachment = PathAttachment;
  6375. })(spine || (spine = {}));
  6376. var spine;
  6377. (function (spine) {
  6378. var PointAttachment = (function (_super) {
  6379. __extends(PointAttachment, _super);
  6380. function PointAttachment(name) {
  6381. var _this = _super.call(this, name) || this;
  6382. _this.color = new spine.Color(0.38, 0.94, 0, 1);
  6383. return _this;
  6384. }
  6385. PointAttachment.prototype.computeWorldPosition = function (bone, point) {
  6386. point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
  6387. point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
  6388. return point;
  6389. };
  6390. PointAttachment.prototype.computeWorldRotation = function (bone) {
  6391. var cos = spine.MathUtils.cosDeg(this.rotation), sin = spine.MathUtils.sinDeg(this.rotation);
  6392. var x = cos * bone.a + sin * bone.b;
  6393. var y = cos * bone.c + sin * bone.d;
  6394. return Math.atan2(y, x) * spine.MathUtils.radDeg;
  6395. };
  6396. return PointAttachment;
  6397. }(spine.VertexAttachment));
  6398. spine.PointAttachment = PointAttachment;
  6399. })(spine || (spine = {}));
  6400. var spine;
  6401. (function (spine) {
  6402. var RegionAttachment = (function (_super) {
  6403. __extends(RegionAttachment, _super);
  6404. function RegionAttachment(name) {
  6405. var _this = _super.call(this, name) || this;
  6406. _this.x = 0;
  6407. _this.y = 0;
  6408. _this.scaleX = 1;
  6409. _this.scaleY = 1;
  6410. _this.rotation = 0;
  6411. _this.width = 0;
  6412. _this.height = 0;
  6413. _this.color = new spine.Color(1, 1, 1, 1);
  6414. _this.offset = spine.Utils.newFloatArray(8);
  6415. _this.uvs = spine.Utils.newFloatArray(8);
  6416. _this.tempColor = new spine.Color(1, 1, 1, 1);
  6417. return _this;
  6418. }
  6419. RegionAttachment.prototype.updateOffset = function () {
  6420. var regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  6421. var regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  6422. var localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  6423. var localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  6424. var localX2 = localX + this.region.width * regionScaleX;
  6425. var localY2 = localY + this.region.height * regionScaleY;
  6426. var radians = this.rotation * Math.PI / 180;
  6427. var cos = Math.cos(radians);
  6428. var sin = Math.sin(radians);
  6429. var localXCos = localX * cos + this.x;
  6430. var localXSin = localX * sin;
  6431. var localYCos = localY * cos + this.y;
  6432. var localYSin = localY * sin;
  6433. var localX2Cos = localX2 * cos + this.x;
  6434. var localX2Sin = localX2 * sin;
  6435. var localY2Cos = localY2 * cos + this.y;
  6436. var localY2Sin = localY2 * sin;
  6437. var offset = this.offset;
  6438. offset[RegionAttachment.OX1] = localXCos - localYSin;
  6439. offset[RegionAttachment.OY1] = localYCos + localXSin;
  6440. offset[RegionAttachment.OX2] = localXCos - localY2Sin;
  6441. offset[RegionAttachment.OY2] = localY2Cos + localXSin;
  6442. offset[RegionAttachment.OX3] = localX2Cos - localY2Sin;
  6443. offset[RegionAttachment.OY3] = localY2Cos + localX2Sin;
  6444. offset[RegionAttachment.OX4] = localX2Cos - localYSin;
  6445. offset[RegionAttachment.OY4] = localYCos + localX2Sin;
  6446. };
  6447. RegionAttachment.prototype.setRegion = function (region) {
  6448. this.region = region;
  6449. var uvs = this.uvs;
  6450. if (region.rotate) {
  6451. uvs[2] = region.u;
  6452. uvs[3] = region.v2;
  6453. uvs[4] = region.u;
  6454. uvs[5] = region.v;
  6455. uvs[6] = region.u2;
  6456. uvs[7] = region.v;
  6457. uvs[0] = region.u2;
  6458. uvs[1] = region.v2;
  6459. }
  6460. else {
  6461. uvs[0] = region.u;
  6462. uvs[1] = region.v2;
  6463. uvs[2] = region.u;
  6464. uvs[3] = region.v;
  6465. uvs[4] = region.u2;
  6466. uvs[5] = region.v;
  6467. uvs[6] = region.u2;
  6468. uvs[7] = region.v2;
  6469. }
  6470. };
  6471. RegionAttachment.prototype.computeWorldVertices = function (bone, worldVertices, offset, stride) {
  6472. var vertexOffset = this.offset;
  6473. var x = bone.worldX, y = bone.worldY;
  6474. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  6475. var offsetX = 0, offsetY = 0;
  6476. offsetX = vertexOffset[RegionAttachment.OX1];
  6477. offsetY = vertexOffset[RegionAttachment.OY1];
  6478. worldVertices[offset] = offsetX * a + offsetY * b + x;
  6479. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  6480. offset += stride;
  6481. offsetX = vertexOffset[RegionAttachment.OX2];
  6482. offsetY = vertexOffset[RegionAttachment.OY2];
  6483. worldVertices[offset] = offsetX * a + offsetY * b + x;
  6484. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  6485. offset += stride;
  6486. offsetX = vertexOffset[RegionAttachment.OX3];
  6487. offsetY = vertexOffset[RegionAttachment.OY3];
  6488. worldVertices[offset] = offsetX * a + offsetY * b + x;
  6489. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  6490. offset += stride;
  6491. offsetX = vertexOffset[RegionAttachment.OX4];
  6492. offsetY = vertexOffset[RegionAttachment.OY4];
  6493. worldVertices[offset] = offsetX * a + offsetY * b + x;
  6494. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  6495. };
  6496. RegionAttachment.OX1 = 0;
  6497. RegionAttachment.OY1 = 1;
  6498. RegionAttachment.OX2 = 2;
  6499. RegionAttachment.OY2 = 3;
  6500. RegionAttachment.OX3 = 4;
  6501. RegionAttachment.OY3 = 5;
  6502. RegionAttachment.OX4 = 6;
  6503. RegionAttachment.OY4 = 7;
  6504. RegionAttachment.X1 = 0;
  6505. RegionAttachment.Y1 = 1;
  6506. RegionAttachment.C1R = 2;
  6507. RegionAttachment.C1G = 3;
  6508. RegionAttachment.C1B = 4;
  6509. RegionAttachment.C1A = 5;
  6510. RegionAttachment.U1 = 6;
  6511. RegionAttachment.V1 = 7;
  6512. RegionAttachment.X2 = 8;
  6513. RegionAttachment.Y2 = 9;
  6514. RegionAttachment.C2R = 10;
  6515. RegionAttachment.C2G = 11;
  6516. RegionAttachment.C2B = 12;
  6517. RegionAttachment.C2A = 13;
  6518. RegionAttachment.U2 = 14;
  6519. RegionAttachment.V2 = 15;
  6520. RegionAttachment.X3 = 16;
  6521. RegionAttachment.Y3 = 17;
  6522. RegionAttachment.C3R = 18;
  6523. RegionAttachment.C3G = 19;
  6524. RegionAttachment.C3B = 20;
  6525. RegionAttachment.C3A = 21;
  6526. RegionAttachment.U3 = 22;
  6527. RegionAttachment.V3 = 23;
  6528. RegionAttachment.X4 = 24;
  6529. RegionAttachment.Y4 = 25;
  6530. RegionAttachment.C4R = 26;
  6531. RegionAttachment.C4G = 27;
  6532. RegionAttachment.C4B = 28;
  6533. RegionAttachment.C4A = 29;
  6534. RegionAttachment.U4 = 30;
  6535. RegionAttachment.V4 = 31;
  6536. return RegionAttachment;
  6537. }(spine.Attachment));
  6538. spine.RegionAttachment = RegionAttachment;
  6539. })(spine || (spine = {}));
  6540. var spine;
  6541. (function (spine) {
  6542. var JitterEffect = (function () {
  6543. function JitterEffect(jitterX, jitterY) {
  6544. this.jitterX = 0;
  6545. this.jitterY = 0;
  6546. this.jitterX = jitterX;
  6547. this.jitterY = jitterY;
  6548. }
  6549. JitterEffect.prototype.begin = function (skeleton) {
  6550. };
  6551. JitterEffect.prototype.transform = function (position, uv, light, dark) {
  6552. position.x += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  6553. position.y += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  6554. };
  6555. JitterEffect.prototype.end = function () {
  6556. };
  6557. return JitterEffect;
  6558. }());
  6559. spine.JitterEffect = JitterEffect;
  6560. })(spine || (spine = {}));
  6561. var spine;
  6562. (function (spine) {
  6563. var SwirlEffect = (function () {
  6564. function SwirlEffect(radius) {
  6565. this.centerX = 0;
  6566. this.centerY = 0;
  6567. this.radius = 0;
  6568. this.angle = 0;
  6569. this.worldX = 0;
  6570. this.worldY = 0;
  6571. this.radius = radius;
  6572. }
  6573. SwirlEffect.prototype.begin = function (skeleton) {
  6574. this.worldX = skeleton.x + this.centerX;
  6575. this.worldY = skeleton.y + this.centerY;
  6576. };
  6577. SwirlEffect.prototype.transform = function (position, uv, light, dark) {
  6578. var radAngle = this.angle * spine.MathUtils.degreesToRadians;
  6579. var x = position.x - this.worldX;
  6580. var y = position.y - this.worldY;
  6581. var dist = Math.sqrt(x * x + y * y);
  6582. if (dist < this.radius) {
  6583. var theta = SwirlEffect.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  6584. var cos = Math.cos(theta);
  6585. var sin = Math.sin(theta);
  6586. position.x = cos * x - sin * y + this.worldX;
  6587. position.y = sin * x + cos * y + this.worldY;
  6588. }
  6589. };
  6590. SwirlEffect.prototype.end = function () {
  6591. };
  6592. SwirlEffect.interpolation = new spine.PowOut(2);
  6593. return SwirlEffect;
  6594. }());
  6595. spine.SwirlEffect = SwirlEffect;
  6596. })(spine || (spine = {}));
  6597. var spine;
  6598. (function (spine) {
  6599. var webgl;
  6600. (function (webgl) {
  6601. var AssetManager = (function (_super) {
  6602. __extends(AssetManager, _super);
  6603. function AssetManager(context, pathPrefix) {
  6604. if (pathPrefix === void 0) { pathPrefix = ""; }
  6605. return _super.call(this, function (image) {
  6606. return new spine.webgl.GLTexture(context, image);
  6607. }, pathPrefix) || this;
  6608. }
  6609. return AssetManager;
  6610. }(spine.AssetManager));
  6611. webgl.AssetManager = AssetManager;
  6612. })(webgl = spine.webgl || (spine.webgl = {}));
  6613. })(spine || (spine = {}));
  6614. var spine;
  6615. (function (spine) {
  6616. var webgl;
  6617. (function (webgl) {
  6618. var OrthoCamera = (function () {
  6619. function OrthoCamera(viewportWidth, viewportHeight) {
  6620. this.position = new webgl.Vector3(0, 0, 0);
  6621. this.direction = new webgl.Vector3(0, 0, -1);
  6622. this.up = new webgl.Vector3(0, 1, 0);
  6623. this.near = 0;
  6624. this.far = 100;
  6625. this.zoom = 1;
  6626. this.viewportWidth = 0;
  6627. this.viewportHeight = 0;
  6628. this.projectionView = new webgl.Matrix4();
  6629. this.inverseProjectionView = new webgl.Matrix4();
  6630. this.projection = new webgl.Matrix4();
  6631. this.view = new webgl.Matrix4();
  6632. this.tmp = new webgl.Vector3();
  6633. this.viewportWidth = viewportWidth;
  6634. this.viewportHeight = viewportHeight;
  6635. this.update();
  6636. }
  6637. OrthoCamera.prototype.update = function () {
  6638. var projection = this.projection;
  6639. var view = this.view;
  6640. var projectionView = this.projectionView;
  6641. var inverseProjectionView = this.inverseProjectionView;
  6642. var zoom = this.zoom, viewportWidth = this.viewportWidth, viewportHeight = this.viewportHeight;
  6643. projection.ortho(zoom * (-viewportWidth / 2), zoom * (viewportWidth / 2), zoom * (-viewportHeight / 2), zoom * (viewportHeight / 2), this.near, this.far);
  6644. view.lookAt(this.position, this.direction, this.up);
  6645. projectionView.set(projection.values);
  6646. projectionView.multiply(view);
  6647. inverseProjectionView.set(projectionView.values).invert();
  6648. };
  6649. OrthoCamera.prototype.screenToWorld = function (screenCoords, screenWidth, screenHeight) {
  6650. var x = screenCoords.x, y = screenHeight - screenCoords.y - 1;
  6651. var tmp = this.tmp;
  6652. tmp.x = (2 * x) / screenWidth - 1;
  6653. tmp.y = (2 * y) / screenHeight - 1;
  6654. tmp.z = (2 * screenCoords.z) - 1;
  6655. tmp.project(this.inverseProjectionView);
  6656. screenCoords.set(tmp.x, tmp.y, tmp.z);
  6657. return screenCoords;
  6658. };
  6659. OrthoCamera.prototype.setViewport = function (viewportWidth, viewportHeight) {
  6660. this.viewportWidth = viewportWidth;
  6661. this.viewportHeight = viewportHeight;
  6662. };
  6663. return OrthoCamera;
  6664. }());
  6665. webgl.OrthoCamera = OrthoCamera;
  6666. })(webgl = spine.webgl || (spine.webgl = {}));
  6667. })(spine || (spine = {}));
  6668. var spine;
  6669. (function (spine) {
  6670. var webgl;
  6671. (function (webgl) {
  6672. var GLTexture = (function (_super) {
  6673. __extends(GLTexture, _super);
  6674. function GLTexture(context, image, useMipMaps) {
  6675. if (useMipMaps === void 0) { useMipMaps = false; }
  6676. var _this = _super.call(this, image) || this;
  6677. _this.texture = null;
  6678. _this.boundUnit = 0;
  6679. _this.useMipMaps = false;
  6680. _this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  6681. _this.useMipMaps = useMipMaps;
  6682. _this.restore();
  6683. _this.context.addRestorable(_this);
  6684. return _this;
  6685. }
  6686. GLTexture.prototype.setFilters = function (minFilter, magFilter) {
  6687. var gl = this.context.gl;
  6688. this.bind();
  6689. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  6690. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
  6691. };
  6692. GLTexture.prototype.setWraps = function (uWrap, vWrap) {
  6693. var gl = this.context.gl;
  6694. this.bind();
  6695. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap);
  6696. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap);
  6697. };
  6698. GLTexture.prototype.update = function (useMipMaps) {
  6699. var gl = this.context.gl;
  6700. if (!this.texture) {
  6701. this.texture = this.context.gl.createTexture();
  6702. }
  6703. this.bind();
  6704. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image);
  6705. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  6706. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  6707. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6708. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6709. if (useMipMaps)
  6710. gl.generateMipmap(gl.TEXTURE_2D);
  6711. };
  6712. GLTexture.prototype.restore = function () {
  6713. this.texture = null;
  6714. this.update(this.useMipMaps);
  6715. };
  6716. GLTexture.prototype.bind = function (unit) {
  6717. if (unit === void 0) { unit = 0; }
  6718. var gl = this.context.gl;
  6719. this.boundUnit = unit;
  6720. gl.activeTexture(gl.TEXTURE0 + unit);
  6721. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  6722. };
  6723. GLTexture.prototype.unbind = function () {
  6724. var gl = this.context.gl;
  6725. gl.activeTexture(gl.TEXTURE0 + this.boundUnit);
  6726. gl.bindTexture(gl.TEXTURE_2D, null);
  6727. };
  6728. GLTexture.prototype.dispose = function () {
  6729. this.context.removeRestorable(this);
  6730. var gl = this.context.gl;
  6731. gl.deleteTexture(this.texture);
  6732. };
  6733. return GLTexture;
  6734. }(spine.Texture));
  6735. webgl.GLTexture = GLTexture;
  6736. })(webgl = spine.webgl || (spine.webgl = {}));
  6737. })(spine || (spine = {}));
  6738. var spine;
  6739. (function (spine) {
  6740. var webgl;
  6741. (function (webgl) {
  6742. var Input = (function () {
  6743. function Input(element) {
  6744. this.lastX = 0;
  6745. this.lastY = 0;
  6746. this.buttonDown = false;
  6747. this.currTouch = null;
  6748. this.touchesPool = new spine.Pool(function () {
  6749. return new spine.webgl.Touch(0, 0, 0);
  6750. });
  6751. this.listeners = new Array();
  6752. this.element = element;
  6753. this.setupCallbacks(element);
  6754. }
  6755. Input.prototype.setupCallbacks = function (element) {
  6756. var _this = this;
  6757. element.addEventListener("mousedown", function (ev) {
  6758. if (ev instanceof MouseEvent) {
  6759. var rect = element.getBoundingClientRect();
  6760. var x = ev.clientX - rect.left;
  6761. var y = ev.clientY - rect.top;
  6762. var listeners = _this.listeners;
  6763. for (var i = 0; i < listeners.length; i++) {
  6764. listeners[i].down(x, y);
  6765. }
  6766. _this.lastX = x;
  6767. _this.lastY = y;
  6768. _this.buttonDown = true;
  6769. }
  6770. }, true);
  6771. element.addEventListener("mousemove", function (ev) {
  6772. if (ev instanceof MouseEvent) {
  6773. var rect = element.getBoundingClientRect();
  6774. var x = ev.clientX - rect.left;
  6775. var y = ev.clientY - rect.top;
  6776. var listeners = _this.listeners;
  6777. for (var i = 0; i < listeners.length; i++) {
  6778. if (_this.buttonDown) {
  6779. listeners[i].dragged(x, y);
  6780. }
  6781. else {
  6782. listeners[i].moved(x, y);
  6783. }
  6784. }
  6785. _this.lastX = x;
  6786. _this.lastY = y;
  6787. }
  6788. }, true);
  6789. element.addEventListener("mouseup", function (ev) {
  6790. if (ev instanceof MouseEvent) {
  6791. var rect = element.getBoundingClientRect();
  6792. var x = ev.clientX - rect.left;
  6793. var y = ev.clientY - rect.top;
  6794. var listeners = _this.listeners;
  6795. for (var i = 0; i < listeners.length; i++) {
  6796. listeners[i].up(x, y);
  6797. }
  6798. _this.lastX = x;
  6799. _this.lastY = y;
  6800. _this.buttonDown = false;
  6801. }
  6802. }, true);
  6803. element.addEventListener("touchstart", function (ev) {
  6804. if (_this.currTouch != null)
  6805. return;
  6806. var touches = ev.changedTouches;
  6807. for (var i = 0; i < touches.length; i++) {
  6808. var touch = touches[i];
  6809. var rect = element.getBoundingClientRect();
  6810. var x = touch.clientX - rect.left;
  6811. var y = touch.clientY - rect.top;
  6812. _this.currTouch = _this.touchesPool.obtain();
  6813. _this.currTouch.identifier = touch.identifier;
  6814. _this.currTouch.x = x;
  6815. _this.currTouch.y = y;
  6816. break;
  6817. }
  6818. var listeners = _this.listeners;
  6819. for (var i_8 = 0; i_8 < listeners.length; i_8++) {
  6820. listeners[i_8].down(_this.currTouch.x, _this.currTouch.y);
  6821. }
  6822. console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y);
  6823. _this.lastX = _this.currTouch.x;
  6824. _this.lastY = _this.currTouch.y;
  6825. _this.buttonDown = true;
  6826. ev.preventDefault();
  6827. }, false);
  6828. element.addEventListener("touchend", function (ev) {
  6829. var touches = ev.changedTouches;
  6830. for (var i = 0; i < touches.length; i++) {
  6831. var touch = touches[i];
  6832. if (_this.currTouch.identifier === touch.identifier) {
  6833. var rect = element.getBoundingClientRect();
  6834. var x = _this.currTouch.x = touch.clientX - rect.left;
  6835. var y = _this.currTouch.y = touch.clientY - rect.top;
  6836. _this.touchesPool.free(_this.currTouch);
  6837. var listeners = _this.listeners;
  6838. for (var i_9 = 0; i_9 < listeners.length; i_9++) {
  6839. listeners[i_9].up(x, y);
  6840. }
  6841. console.log("End " + x + ", " + y);
  6842. _this.lastX = x;
  6843. _this.lastY = y;
  6844. _this.buttonDown = false;
  6845. _this.currTouch = null;
  6846. break;
  6847. }
  6848. }
  6849. ev.preventDefault();
  6850. }, false);
  6851. element.addEventListener("touchcancel", function (ev) {
  6852. var touches = ev.changedTouches;
  6853. for (var i = 0; i < touches.length; i++) {
  6854. var touch = touches[i];
  6855. if (_this.currTouch.identifier === touch.identifier) {
  6856. var rect = element.getBoundingClientRect();
  6857. var x = _this.currTouch.x = touch.clientX - rect.left;
  6858. var y = _this.currTouch.y = touch.clientY - rect.top;
  6859. _this.touchesPool.free(_this.currTouch);
  6860. var listeners = _this.listeners;
  6861. for (var i_10 = 0; i_10 < listeners.length; i_10++) {
  6862. listeners[i_10].up(x, y);
  6863. }
  6864. console.log("End " + x + ", " + y);
  6865. _this.lastX = x;
  6866. _this.lastY = y;
  6867. _this.buttonDown = false;
  6868. _this.currTouch = null;
  6869. break;
  6870. }
  6871. }
  6872. ev.preventDefault();
  6873. }, false);
  6874. element.addEventListener("touchmove", function (ev) {
  6875. if (_this.currTouch == null)
  6876. return;
  6877. var touches = ev.changedTouches;
  6878. for (var i = 0; i < touches.length; i++) {
  6879. var touch = touches[i];
  6880. if (_this.currTouch.identifier === touch.identifier) {
  6881. var rect = element.getBoundingClientRect();
  6882. var x = touch.clientX - rect.left;
  6883. var y = touch.clientY - rect.top;
  6884. var listeners = _this.listeners;
  6885. for (var i_11 = 0; i_11 < listeners.length; i_11++) {
  6886. listeners[i_11].dragged(x, y);
  6887. }
  6888. console.log("Drag " + x + ", " + y);
  6889. _this.lastX = _this.currTouch.x = x;
  6890. _this.lastY = _this.currTouch.y = y;
  6891. break;
  6892. }
  6893. }
  6894. ev.preventDefault();
  6895. }, false);
  6896. };
  6897. Input.prototype.addListener = function (listener) {
  6898. this.listeners.push(listener);
  6899. };
  6900. Input.prototype.removeListener = function (listener) {
  6901. var idx = this.listeners.indexOf(listener);
  6902. if (idx > -1) {
  6903. this.listeners.splice(idx, 1);
  6904. }
  6905. };
  6906. return Input;
  6907. }());
  6908. webgl.Input = Input;
  6909. var Touch = (function () {
  6910. function Touch(identifier, x, y) {
  6911. this.identifier = identifier;
  6912. this.x = x;
  6913. this.y = y;
  6914. }
  6915. return Touch;
  6916. }());
  6917. webgl.Touch = Touch;
  6918. })(webgl = spine.webgl || (spine.webgl = {}));
  6919. })(spine || (spine = {}));
  6920. var spine;
  6921. (function (spine) {
  6922. var webgl;
  6923. (function (webgl) {
  6924. var LoadingScreen = (function () {
  6925. function LoadingScreen(renderer) {
  6926. this.logo = null;
  6927. this.spinner = null;
  6928. this.angle = 0;
  6929. this.fadeOut = 0;
  6930. this.timeKeeper = new spine.TimeKeeper();
  6931. this.backgroundColor = new spine.Color(0.135, 0.135, 0.135, 1);
  6932. this.tempColor = new spine.Color();
  6933. this.firstDraw = 0;
  6934. this.renderer = renderer;
  6935. this.timeKeeper.maxDelta = 9;
  6936. if (LoadingScreen.logoImg === null) {
  6937. var isSafari = navigator.userAgent.indexOf("Safari") > -1;
  6938. LoadingScreen.logoImg = new Image();
  6939. LoadingScreen.logoImg.src = LoadingScreen.SPINE_LOGO_DATA;
  6940. if (!isSafari)
  6941. LoadingScreen.logoImg.crossOrigin = "anonymous";
  6942. LoadingScreen.logoImg.onload = function (ev) {
  6943. LoadingScreen.loaded++;
  6944. };
  6945. LoadingScreen.spinnerImg = new Image();
  6946. LoadingScreen.spinnerImg.src = LoadingScreen.SPINNER_DATA;
  6947. if (!isSafari)
  6948. LoadingScreen.spinnerImg.crossOrigin = "anonymous";
  6949. LoadingScreen.spinnerImg.onload = function (ev) {
  6950. LoadingScreen.loaded++;
  6951. };
  6952. }
  6953. }
  6954. LoadingScreen.prototype.draw = function (complete) {
  6955. if (complete === void 0) { complete = false; }
  6956. if (complete && this.fadeOut > LoadingScreen.FADE_SECONDS)
  6957. return;
  6958. this.timeKeeper.update();
  6959. var a = Math.abs(Math.sin(this.timeKeeper.totalTime + 0.75));
  6960. this.angle -= this.timeKeeper.delta * 360 * (1 + 1.5 * Math.pow(a, 5));
  6961. var renderer = this.renderer;
  6962. var canvas = renderer.canvas;
  6963. var gl = renderer.context.gl;
  6964. var oldX = renderer.camera.position.x, oldY = renderer.camera.position.y;
  6965. renderer.camera.position.set(canvas.width / 2, canvas.height / 2, 0);
  6966. renderer.camera.viewportWidth = canvas.width;
  6967. renderer.camera.viewportHeight = canvas.height;
  6968. renderer.resize(webgl.ResizeMode.Stretch);
  6969. if (!complete) {
  6970. gl.clearColor(this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a);
  6971. gl.clear(gl.COLOR_BUFFER_BIT);
  6972. this.tempColor.a = 1;
  6973. }
  6974. else {
  6975. this.fadeOut += this.timeKeeper.delta * (this.timeKeeper.totalTime < 1 ? 2 : 1);
  6976. if (this.fadeOut > LoadingScreen.FADE_SECONDS) {
  6977. renderer.camera.position.set(oldX, oldY, 0);
  6978. return;
  6979. }
  6980. a = 1 - this.fadeOut / LoadingScreen.FADE_SECONDS;
  6981. this.tempColor.setFromColor(this.backgroundColor);
  6982. this.tempColor.a = 1 - (a - 1) * (a - 1);
  6983. renderer.begin();
  6984. renderer.quad(true, 0, 0, canvas.width, 0, canvas.width, canvas.height, 0, canvas.height, this.tempColor, this.tempColor, this.tempColor, this.tempColor);
  6985. renderer.end();
  6986. }
  6987. this.tempColor.set(1, 1, 1, this.tempColor.a);
  6988. if (LoadingScreen.loaded != 2)
  6989. return;
  6990. if (this.logo === null) {
  6991. this.logo = new webgl.GLTexture(renderer.context, LoadingScreen.logoImg);
  6992. this.spinner = new webgl.GLTexture(renderer.context, LoadingScreen.spinnerImg);
  6993. }
  6994. this.logo.update(false);
  6995. this.spinner.update(false);
  6996. var logoWidth = this.logo.getImage().width;
  6997. var logoHeight = this.logo.getImage().height;
  6998. var spinnerWidth = this.spinner.getImage().width;
  6999. var spinnerHeight = this.spinner.getImage().height;
  7000. renderer.batcher.setBlendMode(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  7001. renderer.begin();
  7002. renderer.drawTexture(this.logo, (canvas.width - logoWidth) / 2, (canvas.height - logoHeight) / 2, logoWidth, logoHeight, this.tempColor);
  7003. renderer.drawTextureRotated(this.spinner, (canvas.width - spinnerWidth) / 2, (canvas.height - spinnerHeight) / 2, spinnerWidth, spinnerHeight, spinnerWidth / 2, spinnerHeight / 2, this.angle, this.tempColor);
  7004. renderer.end();
  7005. renderer.camera.position.set(oldX, oldY, 0);
  7006. };
  7007. LoadingScreen.FADE_SECONDS = 1;
  7008. LoadingScreen.loaded = 0;
  7009. LoadingScreen.spinnerImg = null;
  7010. LoadingScreen.logoImg = null;
  7011. LoadingScreen.SPINNER_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAChCAMAAAB3TUS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAYNQTFRFAAAA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AA/0AAkTDRyAAAAIB0Uk5TAAABAgMEBQYHCAkKCwwODxAREhMUFRYXGBkaHB0eICEiIyQlJicoKSorLC0uLzAxMjM0Nzg5Ojs8PT4/QEFDRUlKS0xNTk9QUlRWWFlbXF1eYWJjZmhscHF0d3h5e3x+f4CIiYuMj5GSlJWXm56io6arr7rAxcjO0dXe6Onr8fmb5sOOAAADuElEQVQYGe3B+3vTVBwH4M/3nCRt13br2Lozhug2q25gYQubcxqVKYoMCYoKjEsUdSpeiBc0Kl7yp9t2za39pely7PF5zvuiQKc+/e2f8K+f9g2oyQ77Ag4VGX+HketQ0XYYe0JQ0CdhogwF+WFiBgr6JkxUoKCDMMGgoP0w9gdUtB3GfoCKVsPYAVQ0H8YuQUWVMHYGKuJhrAklPQkjJpT0bdj3O9S0FfZ9ADXxP8MjVSiqFfa8B2VVV8+df14QtB4iwn+BpuZEgyM38WMQHDYhnbkgukrIh5ygZ48glyn6KshlL+jbhVRcxCzk0ApiC5CI5kVsgTAy9jiI/WxBGmqIFBMjqwYphwRZaiLNwsjqQdoVSFISGRwjM4OMFUjBRcYCYWT0XZD2SwUS0LzIKCGH2SDja0LxKiJjCrm0gowVFI6aIs1CTouPg5QvUTgSKXMMuVUeBSmEopFITBPGwO8HCYbCTYtImTAWejuI3CMUjmZFT5NjbM/9GvQcMkhADdFRIxxD7aug4wGDFGSVTcLx0MzutQ2CpmmapmmapmmapmmapmmaphWBmGFV6rNNcaLC0GUuv3LROftUo8wJk0a10207sVED6IIf+9673LIwQeW2PaCEJX/A+xYmhTbtQUu46g96SJgQZg9Zwxf+EAMTwuwhm3jkD7EwIdweBn+YhQlh9pA2HvpDTEwIs4es4GN/CMekNOxBJ9D2B10nTAyfW7fT1hjYgZ/xYIUwUcycaiwuv2h3tOcZADr7ud/12c0ru2cWSwQ1UAcixIgImqZpmqZpmqZpmqZpmqZp2v8HMSIcF186t8oghbnlOJt1wnHwl7yOGxwSlHacrjWG8dVuej03OApn7jhHtiyMiZa9yD6haLYTebWOsbDXvQRHwchJWSTkV/rQS+EoWttJaTHkJe56KXcJRZt20jY48nnBy9hE4WjLSbvAkIfwMm5zFG/KyWgRRke3vYwGZDjpZHCMruJltCAFrTtpVYxu1ktzCHKwbSdlGqOreynXGGQpOylljI5uebFbBuSZc2IbhBxmvcj9GiSiZ52+HQO5nPb6TkIqajs9L5eQk7jnddxZgGT0jNOxYSI36+Kdj9oG5OPV6QpB6yJuGAYnqIrecLveYlDUKffIOtREl90+BiWV3cgMlNR0I09DSS030oaSttzILpT0phu5BBWRmyAoiLkJgoIMN8GgoJKb4FBQzU0YUFDdTRhQUNVNcCjIdBMEBdE7buQ8lFRz+97lUFN5fe+qu//aMkeB/gU2ae9y2HgbngAAAABJRU5ErkJggg==";
  7012. LoadingScreen.SPINE_LOGO_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFIAAAAZCAYAAACis3k0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAtNJREFUaN7tmT2I1EAUxwN+oWgRT0HFKo0WCkJ6ObmAWFwZbCxsXGysLNJaiCyIoDaSwk4ETzvhmnBaCRbBWoQ01ho4PwotjP8cE337mMy8TLK757mBH3fLTWbe/PbN53neNniqZW8FvAVvQAqugwvgDDgO9niLRyTyJagM/ACPF6bsIl9ZRDac/Cc6tLn5xQdRQ496QlKPLxD5QCDxO9jtGM8QfYoIgUlgCipGCRJL5VvlyOdCU09iEXkCfLSIfCrs7Fab6nOsiafu06iDwES9w/uU1QnDC+ekkVS9vEaDsgVeB0d+z1VDtOGxRaYPboP3Gokb4GgXkZp4chZPJKgvZ3U0XkriK/TIt9YUDllFgTAjGwoaoHqfBhMI58yD4BQ4V6/aHYdfxToftvw9F2SiVroawU2/Cv5C4Thv0KB9S5nxlOd4STxjwUjzSdYlgrYijw2BsEfgsaFcM09lhiys94xXQQwugcvgJrgFLjrEE7WUiTuWCQzt/ZXN7FfqGwuGClyVy2xZAFmfDQvNtwFFSspMDGsD+UTWqu1KoVmVooFEJgKRXw0if85RpISEzwsjzeqWzkjkC4PIJ3MUmQgITAHlQwTFhnZhELkEntfZRwR+AvfAgXmJHOqU02XligWT8ppg67NXbdCXeq7afUQ6L8C2DalEZNt2YyQ94Qy8/ekjMpBMbfyl5iTjG7YAI8cNecROAb4kJmTjaXAF3AGvwQewOiuRxEtlSaT4j2h2lMsUueQEoMlIKpTvAmKhxPMtC876jEX6rE8l8TNx/KVbn6xlWU9NWcSDUsO4NGWpQOTZFpHPOooMXcswmW2XFk3ixb2v0Nq+XVKP00QNaffBLyWwBI/AkTlfMYZDXMf12kc6yjwEjoFdO/5me5oi/6tnyhlZX6OtgmX1c2Uh0k3khmbB2b9TRfpd/jfTUeRDJvHdYg5wE7kPXAN3wQ1weDvH+xufEgpi5qIl3QAAAABJRU5ErkJggg==";
  7013. return LoadingScreen;
  7014. }());
  7015. webgl.LoadingScreen = LoadingScreen;
  7016. })(webgl = spine.webgl || (spine.webgl = {}));
  7017. })(spine || (spine = {}));
  7018. var spine;
  7019. (function (spine) {
  7020. var webgl;
  7021. (function (webgl) {
  7022. webgl.M00 = 0;
  7023. webgl.M01 = 4;
  7024. webgl.M02 = 8;
  7025. webgl.M03 = 12;
  7026. webgl.M10 = 1;
  7027. webgl.M11 = 5;
  7028. webgl.M12 = 9;
  7029. webgl.M13 = 13;
  7030. webgl.M20 = 2;
  7031. webgl.M21 = 6;
  7032. webgl.M22 = 10;
  7033. webgl.M23 = 14;
  7034. webgl.M30 = 3;
  7035. webgl.M31 = 7;
  7036. webgl.M32 = 11;
  7037. webgl.M33 = 15;
  7038. var Matrix4 = (function () {
  7039. function Matrix4() {
  7040. this.temp = new Float32Array(16);
  7041. this.values = new Float32Array(16);
  7042. var v = this.values;
  7043. v[webgl.M00] = 1;
  7044. v[webgl.M11] = 1;
  7045. v[webgl.M22] = 1;
  7046. v[webgl.M33] = 1;
  7047. }
  7048. Matrix4.prototype.set = function (values) {
  7049. this.values.set(values);
  7050. return this;
  7051. };
  7052. Matrix4.prototype.transpose = function () {
  7053. var t = this.temp;
  7054. var v = this.values;
  7055. t[webgl.M00] = v[webgl.M00];
  7056. t[webgl.M01] = v[webgl.M10];
  7057. t[webgl.M02] = v[webgl.M20];
  7058. t[webgl.M03] = v[webgl.M30];
  7059. t[webgl.M10] = v[webgl.M01];
  7060. t[webgl.M11] = v[webgl.M11];
  7061. t[webgl.M12] = v[webgl.M21];
  7062. t[webgl.M13] = v[webgl.M31];
  7063. t[webgl.M20] = v[webgl.M02];
  7064. t[webgl.M21] = v[webgl.M12];
  7065. t[webgl.M22] = v[webgl.M22];
  7066. t[webgl.M23] = v[webgl.M32];
  7067. t[webgl.M30] = v[webgl.M03];
  7068. t[webgl.M31] = v[webgl.M13];
  7069. t[webgl.M32] = v[webgl.M23];
  7070. t[webgl.M33] = v[webgl.M33];
  7071. return this.set(t);
  7072. };
  7073. Matrix4.prototype.identity = function () {
  7074. var v = this.values;
  7075. v[webgl.M00] = 1;
  7076. v[webgl.M01] = 0;
  7077. v[webgl.M02] = 0;
  7078. v[webgl.M03] = 0;
  7079. v[webgl.M10] = 0;
  7080. v[webgl.M11] = 1;
  7081. v[webgl.M12] = 0;
  7082. v[webgl.M13] = 0;
  7083. v[webgl.M20] = 0;
  7084. v[webgl.M21] = 0;
  7085. v[webgl.M22] = 1;
  7086. v[webgl.M23] = 0;
  7087. v[webgl.M30] = 0;
  7088. v[webgl.M31] = 0;
  7089. v[webgl.M32] = 0;
  7090. v[webgl.M33] = 1;
  7091. return this;
  7092. };
  7093. Matrix4.prototype.invert = function () {
  7094. var v = this.values;
  7095. var t = this.temp;
  7096. var l_det = v[webgl.M30] * v[webgl.M21] * v[webgl.M12] * v[webgl.M03] - v[webgl.M20] * v[webgl.M31] * v[webgl.M12] * v[webgl.M03] - v[webgl.M30] * v[webgl.M11] * v[webgl.M22] * v[webgl.M03]
  7097. + v[webgl.M10] * v[webgl.M31] * v[webgl.M22] * v[webgl.M03] + v[webgl.M20] * v[webgl.M11] * v[webgl.M32] * v[webgl.M03] - v[webgl.M10] * v[webgl.M21] * v[webgl.M32] * v[webgl.M03]
  7098. - v[webgl.M30] * v[webgl.M21] * v[webgl.M02] * v[webgl.M13] + v[webgl.M20] * v[webgl.M31] * v[webgl.M02] * v[webgl.M13] + v[webgl.M30] * v[webgl.M01] * v[webgl.M22] * v[webgl.M13]
  7099. - v[webgl.M00] * v[webgl.M31] * v[webgl.M22] * v[webgl.M13] - v[webgl.M20] * v[webgl.M01] * v[webgl.M32] * v[webgl.M13] + v[webgl.M00] * v[webgl.M21] * v[webgl.M32] * v[webgl.M13]
  7100. + v[webgl.M30] * v[webgl.M11] * v[webgl.M02] * v[webgl.M23] - v[webgl.M10] * v[webgl.M31] * v[webgl.M02] * v[webgl.M23] - v[webgl.M30] * v[webgl.M01] * v[webgl.M12] * v[webgl.M23]
  7101. + v[webgl.M00] * v[webgl.M31] * v[webgl.M12] * v[webgl.M23] + v[webgl.M10] * v[webgl.M01] * v[webgl.M32] * v[webgl.M23] - v[webgl.M00] * v[webgl.M11] * v[webgl.M32] * v[webgl.M23]
  7102. - v[webgl.M20] * v[webgl.M11] * v[webgl.M02] * v[webgl.M33] + v[webgl.M10] * v[webgl.M21] * v[webgl.M02] * v[webgl.M33] + v[webgl.M20] * v[webgl.M01] * v[webgl.M12] * v[webgl.M33]
  7103. - v[webgl.M00] * v[webgl.M21] * v[webgl.M12] * v[webgl.M33] - v[webgl.M10] * v[webgl.M01] * v[webgl.M22] * v[webgl.M33] + v[webgl.M00] * v[webgl.M11] * v[webgl.M22] * v[webgl.M33];
  7104. if (l_det == 0)
  7105. throw new Error("non-invertible matrix");
  7106. var inv_det = 1.0 / l_det;
  7107. t[webgl.M00] = v[webgl.M12] * v[webgl.M23] * v[webgl.M31] - v[webgl.M13] * v[webgl.M22] * v[webgl.M31] + v[webgl.M13] * v[webgl.M21] * v[webgl.M32]
  7108. - v[webgl.M11] * v[webgl.M23] * v[webgl.M32] - v[webgl.M12] * v[webgl.M21] * v[webgl.M33] + v[webgl.M11] * v[webgl.M22] * v[webgl.M33];
  7109. t[webgl.M01] = v[webgl.M03] * v[webgl.M22] * v[webgl.M31] - v[webgl.M02] * v[webgl.M23] * v[webgl.M31] - v[webgl.M03] * v[webgl.M21] * v[webgl.M32]
  7110. + v[webgl.M01] * v[webgl.M23] * v[webgl.M32] + v[webgl.M02] * v[webgl.M21] * v[webgl.M33] - v[webgl.M01] * v[webgl.M22] * v[webgl.M33];
  7111. t[webgl.M02] = v[webgl.M02] * v[webgl.M13] * v[webgl.M31] - v[webgl.M03] * v[webgl.M12] * v[webgl.M31] + v[webgl.M03] * v[webgl.M11] * v[webgl.M32]
  7112. - v[webgl.M01] * v[webgl.M13] * v[webgl.M32] - v[webgl.M02] * v[webgl.M11] * v[webgl.M33] + v[webgl.M01] * v[webgl.M12] * v[webgl.M33];
  7113. t[webgl.M03] = v[webgl.M03] * v[webgl.M12] * v[webgl.M21] - v[webgl.M02] * v[webgl.M13] * v[webgl.M21] - v[webgl.M03] * v[webgl.M11] * v[webgl.M22]
  7114. + v[webgl.M01] * v[webgl.M13] * v[webgl.M22] + v[webgl.M02] * v[webgl.M11] * v[webgl.M23] - v[webgl.M01] * v[webgl.M12] * v[webgl.M23];
  7115. t[webgl.M10] = v[webgl.M13] * v[webgl.M22] * v[webgl.M30] - v[webgl.M12] * v[webgl.M23] * v[webgl.M30] - v[webgl.M13] * v[webgl.M20] * v[webgl.M32]
  7116. + v[webgl.M10] * v[webgl.M23] * v[webgl.M32] + v[webgl.M12] * v[webgl.M20] * v[webgl.M33] - v[webgl.M10] * v[webgl.M22] * v[webgl.M33];
  7117. t[webgl.M11] = v[webgl.M02] * v[webgl.M23] * v[webgl.M30] - v[webgl.M03] * v[webgl.M22] * v[webgl.M30] + v[webgl.M03] * v[webgl.M20] * v[webgl.M32]
  7118. - v[webgl.M00] * v[webgl.M23] * v[webgl.M32] - v[webgl.M02] * v[webgl.M20] * v[webgl.M33] + v[webgl.M00] * v[webgl.M22] * v[webgl.M33];
  7119. t[webgl.M12] = v[webgl.M03] * v[webgl.M12] * v[webgl.M30] - v[webgl.M02] * v[webgl.M13] * v[webgl.M30] - v[webgl.M03] * v[webgl.M10] * v[webgl.M32]
  7120. + v[webgl.M00] * v[webgl.M13] * v[webgl.M32] + v[webgl.M02] * v[webgl.M10] * v[webgl.M33] - v[webgl.M00] * v[webgl.M12] * v[webgl.M33];
  7121. t[webgl.M13] = v[webgl.M02] * v[webgl.M13] * v[webgl.M20] - v[webgl.M03] * v[webgl.M12] * v[webgl.M20] + v[webgl.M03] * v[webgl.M10] * v[webgl.M22]
  7122. - v[webgl.M00] * v[webgl.M13] * v[webgl.M22] - v[webgl.M02] * v[webgl.M10] * v[webgl.M23] + v[webgl.M00] * v[webgl.M12] * v[webgl.M23];
  7123. t[webgl.M20] = v[webgl.M11] * v[webgl.M23] * v[webgl.M30] - v[webgl.M13] * v[webgl.M21] * v[webgl.M30] + v[webgl.M13] * v[webgl.M20] * v[webgl.M31]
  7124. - v[webgl.M10] * v[webgl.M23] * v[webgl.M31] - v[webgl.M11] * v[webgl.M20] * v[webgl.M33] + v[webgl.M10] * v[webgl.M21] * v[webgl.M33];
  7125. t[webgl.M21] = v[webgl.M03] * v[webgl.M21] * v[webgl.M30] - v[webgl.M01] * v[webgl.M23] * v[webgl.M30] - v[webgl.M03] * v[webgl.M20] * v[webgl.M31]
  7126. + v[webgl.M00] * v[webgl.M23] * v[webgl.M31] + v[webgl.M01] * v[webgl.M20] * v[webgl.M33] - v[webgl.M00] * v[webgl.M21] * v[webgl.M33];
  7127. t[webgl.M22] = v[webgl.M01] * v[webgl.M13] * v[webgl.M30] - v[webgl.M03] * v[webgl.M11] * v[webgl.M30] + v[webgl.M03] * v[webgl.M10] * v[webgl.M31]
  7128. - v[webgl.M00] * v[webgl.M13] * v[webgl.M31] - v[webgl.M01] * v[webgl.M10] * v[webgl.M33] + v[webgl.M00] * v[webgl.M11] * v[webgl.M33];
  7129. t[webgl.M23] = v[webgl.M03] * v[webgl.M11] * v[webgl.M20] - v[webgl.M01] * v[webgl.M13] * v[webgl.M20] - v[webgl.M03] * v[webgl.M10] * v[webgl.M21]
  7130. + v[webgl.M00] * v[webgl.M13] * v[webgl.M21] + v[webgl.M01] * v[webgl.M10] * v[webgl.M23] - v[webgl.M00] * v[webgl.M11] * v[webgl.M23];
  7131. t[webgl.M30] = v[webgl.M12] * v[webgl.M21] * v[webgl.M30] - v[webgl.M11] * v[webgl.M22] * v[webgl.M30] - v[webgl.M12] * v[webgl.M20] * v[webgl.M31]
  7132. + v[webgl.M10] * v[webgl.M22] * v[webgl.M31] + v[webgl.M11] * v[webgl.M20] * v[webgl.M32] - v[webgl.M10] * v[webgl.M21] * v[webgl.M32];
  7133. t[webgl.M31] = v[webgl.M01] * v[webgl.M22] * v[webgl.M30] - v[webgl.M02] * v[webgl.M21] * v[webgl.M30] + v[webgl.M02] * v[webgl.M20] * v[webgl.M31]
  7134. - v[webgl.M00] * v[webgl.M22] * v[webgl.M31] - v[webgl.M01] * v[webgl.M20] * v[webgl.M32] + v[webgl.M00] * v[webgl.M21] * v[webgl.M32];
  7135. t[webgl.M32] = v[webgl.M02] * v[webgl.M11] * v[webgl.M30] - v[webgl.M01] * v[webgl.M12] * v[webgl.M30] - v[webgl.M02] * v[webgl.M10] * v[webgl.M31]
  7136. + v[webgl.M00] * v[webgl.M12] * v[webgl.M31] + v[webgl.M01] * v[webgl.M10] * v[webgl.M32] - v[webgl.M00] * v[webgl.M11] * v[webgl.M32];
  7137. t[webgl.M33] = v[webgl.M01] * v[webgl.M12] * v[webgl.M20] - v[webgl.M02] * v[webgl.M11] * v[webgl.M20] + v[webgl.M02] * v[webgl.M10] * v[webgl.M21]
  7138. - v[webgl.M00] * v[webgl.M12] * v[webgl.M21] - v[webgl.M01] * v[webgl.M10] * v[webgl.M22] + v[webgl.M00] * v[webgl.M11] * v[webgl.M22];
  7139. v[webgl.M00] = t[webgl.M00] * inv_det;
  7140. v[webgl.M01] = t[webgl.M01] * inv_det;
  7141. v[webgl.M02] = t[webgl.M02] * inv_det;
  7142. v[webgl.M03] = t[webgl.M03] * inv_det;
  7143. v[webgl.M10] = t[webgl.M10] * inv_det;
  7144. v[webgl.M11] = t[webgl.M11] * inv_det;
  7145. v[webgl.M12] = t[webgl.M12] * inv_det;
  7146. v[webgl.M13] = t[webgl.M13] * inv_det;
  7147. v[webgl.M20] = t[webgl.M20] * inv_det;
  7148. v[webgl.M21] = t[webgl.M21] * inv_det;
  7149. v[webgl.M22] = t[webgl.M22] * inv_det;
  7150. v[webgl.M23] = t[webgl.M23] * inv_det;
  7151. v[webgl.M30] = t[webgl.M30] * inv_det;
  7152. v[webgl.M31] = t[webgl.M31] * inv_det;
  7153. v[webgl.M32] = t[webgl.M32] * inv_det;
  7154. v[webgl.M33] = t[webgl.M33] * inv_det;
  7155. return this;
  7156. };
  7157. Matrix4.prototype.determinant = function () {
  7158. var v = this.values;
  7159. return v[webgl.M30] * v[webgl.M21] * v[webgl.M12] * v[webgl.M03] - v[webgl.M20] * v[webgl.M31] * v[webgl.M12] * v[webgl.M03] - v[webgl.M30] * v[webgl.M11] * v[webgl.M22] * v[webgl.M03]
  7160. + v[webgl.M10] * v[webgl.M31] * v[webgl.M22] * v[webgl.M03] + v[webgl.M20] * v[webgl.M11] * v[webgl.M32] * v[webgl.M03] - v[webgl.M10] * v[webgl.M21] * v[webgl.M32] * v[webgl.M03]
  7161. - v[webgl.M30] * v[webgl.M21] * v[webgl.M02] * v[webgl.M13] + v[webgl.M20] * v[webgl.M31] * v[webgl.M02] * v[webgl.M13] + v[webgl.M30] * v[webgl.M01] * v[webgl.M22] * v[webgl.M13]
  7162. - v[webgl.M00] * v[webgl.M31] * v[webgl.M22] * v[webgl.M13] - v[webgl.M20] * v[webgl.M01] * v[webgl.M32] * v[webgl.M13] + v[webgl.M00] * v[webgl.M21] * v[webgl.M32] * v[webgl.M13]
  7163. + v[webgl.M30] * v[webgl.M11] * v[webgl.M02] * v[webgl.M23] - v[webgl.M10] * v[webgl.M31] * v[webgl.M02] * v[webgl.M23] - v[webgl.M30] * v[webgl.M01] * v[webgl.M12] * v[webgl.M23]
  7164. + v[webgl.M00] * v[webgl.M31] * v[webgl.M12] * v[webgl.M23] + v[webgl.M10] * v[webgl.M01] * v[webgl.M32] * v[webgl.M23] - v[webgl.M00] * v[webgl.M11] * v[webgl.M32] * v[webgl.M23]
  7165. - v[webgl.M20] * v[webgl.M11] * v[webgl.M02] * v[webgl.M33] + v[webgl.M10] * v[webgl.M21] * v[webgl.M02] * v[webgl.M33] + v[webgl.M20] * v[webgl.M01] * v[webgl.M12] * v[webgl.M33]
  7166. - v[webgl.M00] * v[webgl.M21] * v[webgl.M12] * v[webgl.M33] - v[webgl.M10] * v[webgl.M01] * v[webgl.M22] * v[webgl.M33] + v[webgl.M00] * v[webgl.M11] * v[webgl.M22] * v[webgl.M33];
  7167. };
  7168. Matrix4.prototype.translate = function (x, y, z) {
  7169. var v = this.values;
  7170. v[webgl.M03] += x;
  7171. v[webgl.M13] += y;
  7172. v[webgl.M23] += z;
  7173. return this;
  7174. };
  7175. Matrix4.prototype.copy = function () {
  7176. return new Matrix4().set(this.values);
  7177. };
  7178. Matrix4.prototype.projection = function (near, far, fovy, aspectRatio) {
  7179. this.identity();
  7180. var l_fd = (1.0 / Math.tan((fovy * (Math.PI / 180)) / 2.0));
  7181. var l_a1 = (far + near) / (near - far);
  7182. var l_a2 = (2 * far * near) / (near - far);
  7183. var v = this.values;
  7184. v[webgl.M00] = l_fd / aspectRatio;
  7185. v[webgl.M10] = 0;
  7186. v[webgl.M20] = 0;
  7187. v[webgl.M30] = 0;
  7188. v[webgl.M01] = 0;
  7189. v[webgl.M11] = l_fd;
  7190. v[webgl.M21] = 0;
  7191. v[webgl.M31] = 0;
  7192. v[webgl.M02] = 0;
  7193. v[webgl.M12] = 0;
  7194. v[webgl.M22] = l_a1;
  7195. v[webgl.M32] = -1;
  7196. v[webgl.M03] = 0;
  7197. v[webgl.M13] = 0;
  7198. v[webgl.M23] = l_a2;
  7199. v[webgl.M33] = 0;
  7200. return this;
  7201. };
  7202. Matrix4.prototype.ortho2d = function (x, y, width, height) {
  7203. return this.ortho(x, x + width, y, y + height, 0, 1);
  7204. };
  7205. Matrix4.prototype.ortho = function (left, right, bottom, top, near, far) {
  7206. this.identity();
  7207. var x_orth = 2 / (right - left);
  7208. var y_orth = 2 / (top - bottom);
  7209. var z_orth = -2 / (far - near);
  7210. var tx = -(right + left) / (right - left);
  7211. var ty = -(top + bottom) / (top - bottom);
  7212. var tz = -(far + near) / (far - near);
  7213. var v = this.values;
  7214. v[webgl.M00] = x_orth;
  7215. v[webgl.M10] = 0;
  7216. v[webgl.M20] = 0;
  7217. v[webgl.M30] = 0;
  7218. v[webgl.M01] = 0;
  7219. v[webgl.M11] = y_orth;
  7220. v[webgl.M21] = 0;
  7221. v[webgl.M31] = 0;
  7222. v[webgl.M02] = 0;
  7223. v[webgl.M12] = 0;
  7224. v[webgl.M22] = z_orth;
  7225. v[webgl.M32] = 0;
  7226. v[webgl.M03] = tx;
  7227. v[webgl.M13] = ty;
  7228. v[webgl.M23] = tz;
  7229. v[webgl.M33] = 1;
  7230. return this;
  7231. };
  7232. Matrix4.prototype.multiply = function (matrix) {
  7233. var t = this.temp;
  7234. var v = this.values;
  7235. var m = matrix.values;
  7236. t[webgl.M00] = v[webgl.M00] * m[webgl.M00] + v[webgl.M01] * m[webgl.M10] + v[webgl.M02] * m[webgl.M20] + v[webgl.M03] * m[webgl.M30];
  7237. t[webgl.M01] = v[webgl.M00] * m[webgl.M01] + v[webgl.M01] * m[webgl.M11] + v[webgl.M02] * m[webgl.M21] + v[webgl.M03] * m[webgl.M31];
  7238. t[webgl.M02] = v[webgl.M00] * m[webgl.M02] + v[webgl.M01] * m[webgl.M12] + v[webgl.M02] * m[webgl.M22] + v[webgl.M03] * m[webgl.M32];
  7239. t[webgl.M03] = v[webgl.M00] * m[webgl.M03] + v[webgl.M01] * m[webgl.M13] + v[webgl.M02] * m[webgl.M23] + v[webgl.M03] * m[webgl.M33];
  7240. t[webgl.M10] = v[webgl.M10] * m[webgl.M00] + v[webgl.M11] * m[webgl.M10] + v[webgl.M12] * m[webgl.M20] + v[webgl.M13] * m[webgl.M30];
  7241. t[webgl.M11] = v[webgl.M10] * m[webgl.M01] + v[webgl.M11] * m[webgl.M11] + v[webgl.M12] * m[webgl.M21] + v[webgl.M13] * m[webgl.M31];
  7242. t[webgl.M12] = v[webgl.M10] * m[webgl.M02] + v[webgl.M11] * m[webgl.M12] + v[webgl.M12] * m[webgl.M22] + v[webgl.M13] * m[webgl.M32];
  7243. t[webgl.M13] = v[webgl.M10] * m[webgl.M03] + v[webgl.M11] * m[webgl.M13] + v[webgl.M12] * m[webgl.M23] + v[webgl.M13] * m[webgl.M33];
  7244. t[webgl.M20] = v[webgl.M20] * m[webgl.M00] + v[webgl.M21] * m[webgl.M10] + v[webgl.M22] * m[webgl.M20] + v[webgl.M23] * m[webgl.M30];
  7245. t[webgl.M21] = v[webgl.M20] * m[webgl.M01] + v[webgl.M21] * m[webgl.M11] + v[webgl.M22] * m[webgl.M21] + v[webgl.M23] * m[webgl.M31];
  7246. t[webgl.M22] = v[webgl.M20] * m[webgl.M02] + v[webgl.M21] * m[webgl.M12] + v[webgl.M22] * m[webgl.M22] + v[webgl.M23] * m[webgl.M32];
  7247. t[webgl.M23] = v[webgl.M20] * m[webgl.M03] + v[webgl.M21] * m[webgl.M13] + v[webgl.M22] * m[webgl.M23] + v[webgl.M23] * m[webgl.M33];
  7248. t[webgl.M30] = v[webgl.M30] * m[webgl.M00] + v[webgl.M31] * m[webgl.M10] + v[webgl.M32] * m[webgl.M20] + v[webgl.M33] * m[webgl.M30];
  7249. t[webgl.M31] = v[webgl.M30] * m[webgl.M01] + v[webgl.M31] * m[webgl.M11] + v[webgl.M32] * m[webgl.M21] + v[webgl.M33] * m[webgl.M31];
  7250. t[webgl.M32] = v[webgl.M30] * m[webgl.M02] + v[webgl.M31] * m[webgl.M12] + v[webgl.M32] * m[webgl.M22] + v[webgl.M33] * m[webgl.M32];
  7251. t[webgl.M33] = v[webgl.M30] * m[webgl.M03] + v[webgl.M31] * m[webgl.M13] + v[webgl.M32] * m[webgl.M23] + v[webgl.M33] * m[webgl.M33];
  7252. return this.set(this.temp);
  7253. };
  7254. Matrix4.prototype.multiplyLeft = function (matrix) {
  7255. var t = this.temp;
  7256. var v = this.values;
  7257. var m = matrix.values;
  7258. t[webgl.M00] = m[webgl.M00] * v[webgl.M00] + m[webgl.M01] * v[webgl.M10] + m[webgl.M02] * v[webgl.M20] + m[webgl.M03] * v[webgl.M30];
  7259. t[webgl.M01] = m[webgl.M00] * v[webgl.M01] + m[webgl.M01] * v[webgl.M11] + m[webgl.M02] * v[webgl.M21] + m[webgl.M03] * v[webgl.M31];
  7260. t[webgl.M02] = m[webgl.M00] * v[webgl.M02] + m[webgl.M01] * v[webgl.M12] + m[webgl.M02] * v[webgl.M22] + m[webgl.M03] * v[webgl.M32];
  7261. t[webgl.M03] = m[webgl.M00] * v[webgl.M03] + m[webgl.M01] * v[webgl.M13] + m[webgl.M02] * v[webgl.M23] + m[webgl.M03] * v[webgl.M33];
  7262. t[webgl.M10] = m[webgl.M10] * v[webgl.M00] + m[webgl.M11] * v[webgl.M10] + m[webgl.M12] * v[webgl.M20] + m[webgl.M13] * v[webgl.M30];
  7263. t[webgl.M11] = m[webgl.M10] * v[webgl.M01] + m[webgl.M11] * v[webgl.M11] + m[webgl.M12] * v[webgl.M21] + m[webgl.M13] * v[webgl.M31];
  7264. t[webgl.M12] = m[webgl.M10] * v[webgl.M02] + m[webgl.M11] * v[webgl.M12] + m[webgl.M12] * v[webgl.M22] + m[webgl.M13] * v[webgl.M32];
  7265. t[webgl.M13] = m[webgl.M10] * v[webgl.M03] + m[webgl.M11] * v[webgl.M13] + m[webgl.M12] * v[webgl.M23] + m[webgl.M13] * v[webgl.M33];
  7266. t[webgl.M20] = m[webgl.M20] * v[webgl.M00] + m[webgl.M21] * v[webgl.M10] + m[webgl.M22] * v[webgl.M20] + m[webgl.M23] * v[webgl.M30];
  7267. t[webgl.M21] = m[webgl.M20] * v[webgl.M01] + m[webgl.M21] * v[webgl.M11] + m[webgl.M22] * v[webgl.M21] + m[webgl.M23] * v[webgl.M31];
  7268. t[webgl.M22] = m[webgl.M20] * v[webgl.M02] + m[webgl.M21] * v[webgl.M12] + m[webgl.M22] * v[webgl.M22] + m[webgl.M23] * v[webgl.M32];
  7269. t[webgl.M23] = m[webgl.M20] * v[webgl.M03] + m[webgl.M21] * v[webgl.M13] + m[webgl.M22] * v[webgl.M23] + m[webgl.M23] * v[webgl.M33];
  7270. t[webgl.M30] = m[webgl.M30] * v[webgl.M00] + m[webgl.M31] * v[webgl.M10] + m[webgl.M32] * v[webgl.M20] + m[webgl.M33] * v[webgl.M30];
  7271. t[webgl.M31] = m[webgl.M30] * v[webgl.M01] + m[webgl.M31] * v[webgl.M11] + m[webgl.M32] * v[webgl.M21] + m[webgl.M33] * v[webgl.M31];
  7272. t[webgl.M32] = m[webgl.M30] * v[webgl.M02] + m[webgl.M31] * v[webgl.M12] + m[webgl.M32] * v[webgl.M22] + m[webgl.M33] * v[webgl.M32];
  7273. t[webgl.M33] = m[webgl.M30] * v[webgl.M03] + m[webgl.M31] * v[webgl.M13] + m[webgl.M32] * v[webgl.M23] + m[webgl.M33] * v[webgl.M33];
  7274. return this.set(this.temp);
  7275. };
  7276. Matrix4.prototype.lookAt = function (position, direction, up) {
  7277. Matrix4.initTemps();
  7278. var xAxis = Matrix4.xAxis, yAxis = Matrix4.yAxis, zAxis = Matrix4.zAxis;
  7279. zAxis.setFrom(direction).normalize();
  7280. xAxis.setFrom(direction).normalize();
  7281. xAxis.cross(up).normalize();
  7282. yAxis.setFrom(xAxis).cross(zAxis).normalize();
  7283. this.identity();
  7284. var val = this.values;
  7285. val[webgl.M00] = xAxis.x;
  7286. val[webgl.M01] = xAxis.y;
  7287. val[webgl.M02] = xAxis.z;
  7288. val[webgl.M10] = yAxis.x;
  7289. val[webgl.M11] = yAxis.y;
  7290. val[webgl.M12] = yAxis.z;
  7291. val[webgl.M20] = -zAxis.x;
  7292. val[webgl.M21] = -zAxis.y;
  7293. val[webgl.M22] = -zAxis.z;
  7294. Matrix4.tmpMatrix.identity();
  7295. Matrix4.tmpMatrix.values[webgl.M03] = -position.x;
  7296. Matrix4.tmpMatrix.values[webgl.M13] = -position.y;
  7297. Matrix4.tmpMatrix.values[webgl.M23] = -position.z;
  7298. this.multiply(Matrix4.tmpMatrix);
  7299. return this;
  7300. };
  7301. Matrix4.initTemps = function () {
  7302. if (Matrix4.xAxis === null)
  7303. Matrix4.xAxis = new webgl.Vector3();
  7304. if (Matrix4.yAxis === null)
  7305. Matrix4.yAxis = new webgl.Vector3();
  7306. if (Matrix4.zAxis === null)
  7307. Matrix4.zAxis = new webgl.Vector3();
  7308. };
  7309. Matrix4.xAxis = null;
  7310. Matrix4.yAxis = null;
  7311. Matrix4.zAxis = null;
  7312. Matrix4.tmpMatrix = new Matrix4();
  7313. return Matrix4;
  7314. }());
  7315. webgl.Matrix4 = Matrix4;
  7316. })(webgl = spine.webgl || (spine.webgl = {}));
  7317. })(spine || (spine = {}));
  7318. var spine;
  7319. (function (spine) {
  7320. var webgl;
  7321. (function (webgl) {
  7322. var Mesh = (function () {
  7323. function Mesh(context, attributes, maxVertices, maxIndices) {
  7324. this.attributes = attributes;
  7325. this.verticesLength = 0;
  7326. this.dirtyVertices = false;
  7327. this.indicesLength = 0;
  7328. this.dirtyIndices = false;
  7329. this.elementsPerVertex = 0;
  7330. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7331. this.elementsPerVertex = 0;
  7332. for (var i = 0; i < attributes.length; i++) {
  7333. this.elementsPerVertex += attributes[i].numElements;
  7334. }
  7335. this.vertices = new Float32Array(maxVertices * this.elementsPerVertex);
  7336. this.indices = new Uint16Array(maxIndices);
  7337. this.context.addRestorable(this);
  7338. }
  7339. Mesh.prototype.getAttributes = function () { return this.attributes; };
  7340. Mesh.prototype.maxVertices = function () { return this.vertices.length / this.elementsPerVertex; };
  7341. Mesh.prototype.numVertices = function () { return this.verticesLength / this.elementsPerVertex; };
  7342. Mesh.prototype.setVerticesLength = function (length) {
  7343. this.dirtyVertices = true;
  7344. this.verticesLength = length;
  7345. };
  7346. Mesh.prototype.getVertices = function () { return this.vertices; };
  7347. Mesh.prototype.maxIndices = function () { return this.indices.length; };
  7348. Mesh.prototype.numIndices = function () { return this.indicesLength; };
  7349. Mesh.prototype.setIndicesLength = function (length) {
  7350. this.dirtyIndices = true;
  7351. this.indicesLength = length;
  7352. };
  7353. Mesh.prototype.getIndices = function () { return this.indices; };
  7354. ;
  7355. Mesh.prototype.getVertexSizeInFloats = function () {
  7356. var size = 0;
  7357. for (var i = 0; i < this.attributes.length; i++) {
  7358. var attribute = this.attributes[i];
  7359. size += attribute.numElements;
  7360. }
  7361. return size;
  7362. };
  7363. Mesh.prototype.setVertices = function (vertices) {
  7364. this.dirtyVertices = true;
  7365. if (vertices.length > this.vertices.length)
  7366. throw Error("Mesh can't store more than " + this.maxVertices() + " vertices");
  7367. this.vertices.set(vertices, 0);
  7368. this.verticesLength = vertices.length;
  7369. };
  7370. Mesh.prototype.setIndices = function (indices) {
  7371. this.dirtyIndices = true;
  7372. if (indices.length > this.indices.length)
  7373. throw Error("Mesh can't store more than " + this.maxIndices() + " indices");
  7374. this.indices.set(indices, 0);
  7375. this.indicesLength = indices.length;
  7376. };
  7377. Mesh.prototype.draw = function (shader, primitiveType) {
  7378. this.drawWithOffset(shader, primitiveType, 0, this.indicesLength > 0 ? this.indicesLength : this.verticesLength / this.elementsPerVertex);
  7379. };
  7380. Mesh.prototype.drawWithOffset = function (shader, primitiveType, offset, count) {
  7381. var gl = this.context.gl;
  7382. if (this.dirtyVertices || this.dirtyIndices)
  7383. this.update();
  7384. this.bind(shader);
  7385. if (this.indicesLength > 0) {
  7386. gl.drawElements(primitiveType, count, gl.UNSIGNED_SHORT, offset * 2);
  7387. }
  7388. else {
  7389. gl.drawArrays(primitiveType, offset, count);
  7390. }
  7391. this.unbind(shader);
  7392. };
  7393. Mesh.prototype.bind = function (shader) {
  7394. var gl = this.context.gl;
  7395. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  7396. var offset = 0;
  7397. for (var i = 0; i < this.attributes.length; i++) {
  7398. var attrib = this.attributes[i];
  7399. var location_1 = shader.getAttributeLocation(attrib.name);
  7400. gl.enableVertexAttribArray(location_1);
  7401. gl.vertexAttribPointer(location_1, attrib.numElements, gl.FLOAT, false, this.elementsPerVertex * 4, offset * 4);
  7402. offset += attrib.numElements;
  7403. }
  7404. if (this.indicesLength > 0)
  7405. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  7406. };
  7407. Mesh.prototype.unbind = function (shader) {
  7408. var gl = this.context.gl;
  7409. for (var i = 0; i < this.attributes.length; i++) {
  7410. var attrib = this.attributes[i];
  7411. var location_2 = shader.getAttributeLocation(attrib.name);
  7412. gl.disableVertexAttribArray(location_2);
  7413. }
  7414. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  7415. if (this.indicesLength > 0)
  7416. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  7417. };
  7418. Mesh.prototype.update = function () {
  7419. var gl = this.context.gl;
  7420. if (this.dirtyVertices) {
  7421. if (!this.verticesBuffer) {
  7422. this.verticesBuffer = gl.createBuffer();
  7423. }
  7424. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  7425. gl.bufferData(gl.ARRAY_BUFFER, this.vertices.subarray(0, this.verticesLength), gl.DYNAMIC_DRAW);
  7426. this.dirtyVertices = false;
  7427. }
  7428. if (this.dirtyIndices) {
  7429. if (!this.indicesBuffer) {
  7430. this.indicesBuffer = gl.createBuffer();
  7431. }
  7432. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  7433. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices.subarray(0, this.indicesLength), gl.DYNAMIC_DRAW);
  7434. this.dirtyIndices = false;
  7435. }
  7436. };
  7437. Mesh.prototype.restore = function () {
  7438. this.verticesBuffer = null;
  7439. this.indicesBuffer = null;
  7440. this.update();
  7441. };
  7442. Mesh.prototype.dispose = function () {
  7443. this.context.removeRestorable(this);
  7444. var gl = this.context.gl;
  7445. gl.deleteBuffer(this.verticesBuffer);
  7446. gl.deleteBuffer(this.indicesBuffer);
  7447. };
  7448. return Mesh;
  7449. }());
  7450. webgl.Mesh = Mesh;
  7451. var VertexAttribute = (function () {
  7452. function VertexAttribute(name, type, numElements) {
  7453. this.name = name;
  7454. this.type = type;
  7455. this.numElements = numElements;
  7456. }
  7457. return VertexAttribute;
  7458. }());
  7459. webgl.VertexAttribute = VertexAttribute;
  7460. var Position2Attribute = (function (_super) {
  7461. __extends(Position2Attribute, _super);
  7462. function Position2Attribute() {
  7463. return _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 2) || this;
  7464. }
  7465. return Position2Attribute;
  7466. }(VertexAttribute));
  7467. webgl.Position2Attribute = Position2Attribute;
  7468. var Position3Attribute = (function (_super) {
  7469. __extends(Position3Attribute, _super);
  7470. function Position3Attribute() {
  7471. return _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 3) || this;
  7472. }
  7473. return Position3Attribute;
  7474. }(VertexAttribute));
  7475. webgl.Position3Attribute = Position3Attribute;
  7476. var TexCoordAttribute = (function (_super) {
  7477. __extends(TexCoordAttribute, _super);
  7478. function TexCoordAttribute(unit) {
  7479. if (unit === void 0) { unit = 0; }
  7480. return _super.call(this, webgl.Shader.TEXCOORDS + (unit == 0 ? "" : unit), VertexAttributeType.Float, 2) || this;
  7481. }
  7482. return TexCoordAttribute;
  7483. }(VertexAttribute));
  7484. webgl.TexCoordAttribute = TexCoordAttribute;
  7485. var ColorAttribute = (function (_super) {
  7486. __extends(ColorAttribute, _super);
  7487. function ColorAttribute() {
  7488. return _super.call(this, webgl.Shader.COLOR, VertexAttributeType.Float, 4) || this;
  7489. }
  7490. return ColorAttribute;
  7491. }(VertexAttribute));
  7492. webgl.ColorAttribute = ColorAttribute;
  7493. var Color2Attribute = (function (_super) {
  7494. __extends(Color2Attribute, _super);
  7495. function Color2Attribute() {
  7496. return _super.call(this, webgl.Shader.COLOR2, VertexAttributeType.Float, 4) || this;
  7497. }
  7498. return Color2Attribute;
  7499. }(VertexAttribute));
  7500. webgl.Color2Attribute = Color2Attribute;
  7501. var VertexAttributeType;
  7502. (function (VertexAttributeType) {
  7503. VertexAttributeType[VertexAttributeType["Float"] = 0] = "Float";
  7504. })(VertexAttributeType = webgl.VertexAttributeType || (webgl.VertexAttributeType = {}));
  7505. })(webgl = spine.webgl || (spine.webgl = {}));
  7506. })(spine || (spine = {}));
  7507. var spine;
  7508. (function (spine) {
  7509. var webgl;
  7510. (function (webgl) {
  7511. var PolygonBatcher = (function () {
  7512. function PolygonBatcher(context, twoColorTint, maxVertices) {
  7513. if (twoColorTint === void 0) { twoColorTint = true; }
  7514. if (maxVertices === void 0) { maxVertices = 10920; }
  7515. this.isDrawing = false;
  7516. this.shader = null;
  7517. this.lastTexture = null;
  7518. this.verticesLength = 0;
  7519. this.indicesLength = 0;
  7520. if (maxVertices > 10920)
  7521. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  7522. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7523. var attributes = twoColorTint ?
  7524. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute(), new webgl.Color2Attribute()] :
  7525. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute()];
  7526. this.mesh = new webgl.Mesh(context, attributes, maxVertices, maxVertices * 3);
  7527. this.srcBlend = this.context.gl.SRC_ALPHA;
  7528. this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
  7529. }
  7530. PolygonBatcher.prototype.begin = function (shader) {
  7531. var gl = this.context.gl;
  7532. if (this.isDrawing)
  7533. throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()");
  7534. this.drawCalls = 0;
  7535. this.shader = shader;
  7536. this.lastTexture = null;
  7537. this.isDrawing = true;
  7538. gl.enable(gl.BLEND);
  7539. gl.blendFunc(this.srcBlend, this.dstBlend);
  7540. };
  7541. PolygonBatcher.prototype.setBlendMode = function (srcBlend, dstBlend) {
  7542. var gl = this.context.gl;
  7543. this.srcBlend = srcBlend;
  7544. this.dstBlend = dstBlend;
  7545. if (this.isDrawing) {
  7546. this.flush();
  7547. gl.blendFunc(this.srcBlend, this.dstBlend);
  7548. }
  7549. };
  7550. PolygonBatcher.prototype.draw = function (texture, vertices, indices) {
  7551. if (texture != this.lastTexture) {
  7552. this.flush();
  7553. this.lastTexture = texture;
  7554. }
  7555. else if (this.verticesLength + vertices.length > this.mesh.getVertices().length ||
  7556. this.indicesLength + indices.length > this.mesh.getIndices().length) {
  7557. this.flush();
  7558. }
  7559. var indexStart = this.mesh.numVertices();
  7560. this.mesh.getVertices().set(vertices, this.verticesLength);
  7561. this.verticesLength += vertices.length;
  7562. this.mesh.setVerticesLength(this.verticesLength);
  7563. var indicesArray = this.mesh.getIndices();
  7564. for (var i = this.indicesLength, j = 0; j < indices.length; i++, j++)
  7565. indicesArray[i] = indices[j] + indexStart;
  7566. this.indicesLength += indices.length;
  7567. this.mesh.setIndicesLength(this.indicesLength);
  7568. };
  7569. PolygonBatcher.prototype.flush = function () {
  7570. var gl = this.context.gl;
  7571. if (this.verticesLength == 0)
  7572. return;
  7573. this.lastTexture.bind();
  7574. this.mesh.draw(this.shader, gl.TRIANGLES);
  7575. this.verticesLength = 0;
  7576. this.indicesLength = 0;
  7577. this.mesh.setVerticesLength(0);
  7578. this.mesh.setIndicesLength(0);
  7579. this.drawCalls++;
  7580. };
  7581. PolygonBatcher.prototype.end = function () {
  7582. var gl = this.context.gl;
  7583. if (!this.isDrawing)
  7584. throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()");
  7585. if (this.verticesLength > 0 || this.indicesLength > 0)
  7586. this.flush();
  7587. this.shader = null;
  7588. this.lastTexture = null;
  7589. this.isDrawing = false;
  7590. gl.disable(gl.BLEND);
  7591. };
  7592. PolygonBatcher.prototype.getDrawCalls = function () { return this.drawCalls; };
  7593. PolygonBatcher.prototype.dispose = function () {
  7594. this.mesh.dispose();
  7595. };
  7596. return PolygonBatcher;
  7597. }());
  7598. webgl.PolygonBatcher = PolygonBatcher;
  7599. })(webgl = spine.webgl || (spine.webgl = {}));
  7600. })(spine || (spine = {}));
  7601. var spine;
  7602. (function (spine) {
  7603. var webgl;
  7604. (function (webgl) {
  7605. var SceneRenderer = (function () {
  7606. function SceneRenderer(canvas, context, twoColorTint) {
  7607. if (twoColorTint === void 0) { twoColorTint = true; }
  7608. this.twoColorTint = false;
  7609. this.activeRenderer = null;
  7610. this.QUAD = [
  7611. 0, 0, 1, 1, 1, 1, 0, 0,
  7612. 0, 0, 1, 1, 1, 1, 0, 0,
  7613. 0, 0, 1, 1, 1, 1, 0, 0,
  7614. 0, 0, 1, 1, 1, 1, 0, 0,
  7615. ];
  7616. this.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  7617. this.WHITE = new spine.Color(1, 1, 1, 1);
  7618. this.canvas = canvas;
  7619. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7620. this.twoColorTint = twoColorTint;
  7621. this.camera = new webgl.OrthoCamera(canvas.width, canvas.height);
  7622. this.batcherShader = twoColorTint ? webgl.Shader.newTwoColoredTextured(this.context) : webgl.Shader.newColoredTextured(this.context);
  7623. this.batcher = new webgl.PolygonBatcher(this.context, twoColorTint);
  7624. this.shapesShader = webgl.Shader.newColored(this.context);
  7625. this.shapes = new webgl.ShapeRenderer(this.context);
  7626. this.skeletonRenderer = new webgl.SkeletonRenderer(this.context, twoColorTint);
  7627. this.skeletonDebugRenderer = new webgl.SkeletonDebugRenderer(this.context);
  7628. }
  7629. SceneRenderer.prototype.begin = function () {
  7630. this.camera.update();
  7631. this.enableRenderer(this.batcher);
  7632. };
  7633. SceneRenderer.prototype.drawSkeleton = function (skeleton, premultipliedAlpha, slotRangeStart, slotRangeEnd) {
  7634. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7635. if (slotRangeStart === void 0) { slotRangeStart = -1; }
  7636. if (slotRangeEnd === void 0) { slotRangeEnd = -1; }
  7637. this.enableRenderer(this.batcher);
  7638. this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
  7639. this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd);
  7640. };
  7641. SceneRenderer.prototype.drawSkeletonDebug = function (skeleton, premultipliedAlpha, ignoredBones) {
  7642. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7643. if (ignoredBones === void 0) { ignoredBones = null; }
  7644. this.enableRenderer(this.shapes);
  7645. this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha;
  7646. this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones);
  7647. };
  7648. SceneRenderer.prototype.drawTexture = function (texture, x, y, width, height, color) {
  7649. if (color === void 0) { color = null; }
  7650. this.enableRenderer(this.batcher);
  7651. if (color === null)
  7652. color = this.WHITE;
  7653. var quad = this.QUAD;
  7654. var i = 0;
  7655. quad[i++] = x;
  7656. quad[i++] = y;
  7657. quad[i++] = color.r;
  7658. quad[i++] = color.g;
  7659. quad[i++] = color.b;
  7660. quad[i++] = color.a;
  7661. quad[i++] = 0;
  7662. quad[i++] = 1;
  7663. if (this.twoColorTint) {
  7664. quad[i++] = 0;
  7665. quad[i++] = 0;
  7666. quad[i++] = 0;
  7667. quad[i++] = 0;
  7668. }
  7669. quad[i++] = x + width;
  7670. quad[i++] = y;
  7671. quad[i++] = color.r;
  7672. quad[i++] = color.g;
  7673. quad[i++] = color.b;
  7674. quad[i++] = color.a;
  7675. quad[i++] = 1;
  7676. quad[i++] = 1;
  7677. if (this.twoColorTint) {
  7678. quad[i++] = 0;
  7679. quad[i++] = 0;
  7680. quad[i++] = 0;
  7681. quad[i++] = 0;
  7682. }
  7683. quad[i++] = x + width;
  7684. quad[i++] = y + height;
  7685. quad[i++] = color.r;
  7686. quad[i++] = color.g;
  7687. quad[i++] = color.b;
  7688. quad[i++] = color.a;
  7689. quad[i++] = 1;
  7690. quad[i++] = 0;
  7691. if (this.twoColorTint) {
  7692. quad[i++] = 0;
  7693. quad[i++] = 0;
  7694. quad[i++] = 0;
  7695. quad[i++] = 0;
  7696. }
  7697. quad[i++] = x;
  7698. quad[i++] = y + height;
  7699. quad[i++] = color.r;
  7700. quad[i++] = color.g;
  7701. quad[i++] = color.b;
  7702. quad[i++] = color.a;
  7703. quad[i++] = 0;
  7704. quad[i++] = 0;
  7705. if (this.twoColorTint) {
  7706. quad[i++] = 0;
  7707. quad[i++] = 0;
  7708. quad[i++] = 0;
  7709. quad[i++] = 0;
  7710. }
  7711. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  7712. };
  7713. SceneRenderer.prototype.drawTextureUV = function (texture, x, y, width, height, u, v, u2, v2, color) {
  7714. if (color === void 0) { color = null; }
  7715. this.enableRenderer(this.batcher);
  7716. if (color === null)
  7717. color = this.WHITE;
  7718. var quad = this.QUAD;
  7719. var i = 0;
  7720. quad[i++] = x;
  7721. quad[i++] = y;
  7722. quad[i++] = color.r;
  7723. quad[i++] = color.g;
  7724. quad[i++] = color.b;
  7725. quad[i++] = color.a;
  7726. quad[i++] = u;
  7727. quad[i++] = v;
  7728. if (this.twoColorTint) {
  7729. quad[i++] = 0;
  7730. quad[i++] = 0;
  7731. quad[i++] = 0;
  7732. quad[i++] = 0;
  7733. }
  7734. quad[i++] = x + width;
  7735. quad[i++] = y;
  7736. quad[i++] = color.r;
  7737. quad[i++] = color.g;
  7738. quad[i++] = color.b;
  7739. quad[i++] = color.a;
  7740. quad[i++] = u2;
  7741. quad[i++] = v;
  7742. if (this.twoColorTint) {
  7743. quad[i++] = 0;
  7744. quad[i++] = 0;
  7745. quad[i++] = 0;
  7746. quad[i++] = 0;
  7747. }
  7748. quad[i++] = x + width;
  7749. quad[i++] = y + height;
  7750. quad[i++] = color.r;
  7751. quad[i++] = color.g;
  7752. quad[i++] = color.b;
  7753. quad[i++] = color.a;
  7754. quad[i++] = u2;
  7755. quad[i++] = v2;
  7756. if (this.twoColorTint) {
  7757. quad[i++] = 0;
  7758. quad[i++] = 0;
  7759. quad[i++] = 0;
  7760. quad[i++] = 0;
  7761. }
  7762. quad[i++] = x;
  7763. quad[i++] = y + height;
  7764. quad[i++] = color.r;
  7765. quad[i++] = color.g;
  7766. quad[i++] = color.b;
  7767. quad[i++] = color.a;
  7768. quad[i++] = u;
  7769. quad[i++] = v2;
  7770. if (this.twoColorTint) {
  7771. quad[i++] = 0;
  7772. quad[i++] = 0;
  7773. quad[i++] = 0;
  7774. quad[i++] = 0;
  7775. }
  7776. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  7777. };
  7778. SceneRenderer.prototype.drawTextureRotated = function (texture, x, y, width, height, pivotX, pivotY, angle, color, premultipliedAlpha) {
  7779. if (color === void 0) { color = null; }
  7780. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7781. this.enableRenderer(this.batcher);
  7782. if (color === null)
  7783. color = this.WHITE;
  7784. var quad = this.QUAD;
  7785. var worldOriginX = x + pivotX;
  7786. var worldOriginY = y + pivotY;
  7787. var fx = -pivotX;
  7788. var fy = -pivotY;
  7789. var fx2 = width - pivotX;
  7790. var fy2 = height - pivotY;
  7791. var p1x = fx;
  7792. var p1y = fy;
  7793. var p2x = fx;
  7794. var p2y = fy2;
  7795. var p3x = fx2;
  7796. var p3y = fy2;
  7797. var p4x = fx2;
  7798. var p4y = fy;
  7799. var x1 = 0;
  7800. var y1 = 0;
  7801. var x2 = 0;
  7802. var y2 = 0;
  7803. var x3 = 0;
  7804. var y3 = 0;
  7805. var x4 = 0;
  7806. var y4 = 0;
  7807. if (angle != 0) {
  7808. var cos = spine.MathUtils.cosDeg(angle);
  7809. var sin = spine.MathUtils.sinDeg(angle);
  7810. x1 = cos * p1x - sin * p1y;
  7811. y1 = sin * p1x + cos * p1y;
  7812. x4 = cos * p2x - sin * p2y;
  7813. y4 = sin * p2x + cos * p2y;
  7814. x3 = cos * p3x - sin * p3y;
  7815. y3 = sin * p3x + cos * p3y;
  7816. x2 = x3 + (x1 - x4);
  7817. y2 = y3 + (y1 - y4);
  7818. }
  7819. else {
  7820. x1 = p1x;
  7821. y1 = p1y;
  7822. x4 = p2x;
  7823. y4 = p2y;
  7824. x3 = p3x;
  7825. y3 = p3y;
  7826. x2 = p4x;
  7827. y2 = p4y;
  7828. }
  7829. x1 += worldOriginX;
  7830. y1 += worldOriginY;
  7831. x2 += worldOriginX;
  7832. y2 += worldOriginY;
  7833. x3 += worldOriginX;
  7834. y3 += worldOriginY;
  7835. x4 += worldOriginX;
  7836. y4 += worldOriginY;
  7837. var i = 0;
  7838. quad[i++] = x1;
  7839. quad[i++] = y1;
  7840. quad[i++] = color.r;
  7841. quad[i++] = color.g;
  7842. quad[i++] = color.b;
  7843. quad[i++] = color.a;
  7844. quad[i++] = 0;
  7845. quad[i++] = 1;
  7846. if (this.twoColorTint) {
  7847. quad[i++] = 0;
  7848. quad[i++] = 0;
  7849. quad[i++] = 0;
  7850. quad[i++] = 0;
  7851. }
  7852. quad[i++] = x2;
  7853. quad[i++] = y2;
  7854. quad[i++] = color.r;
  7855. quad[i++] = color.g;
  7856. quad[i++] = color.b;
  7857. quad[i++] = color.a;
  7858. quad[i++] = 1;
  7859. quad[i++] = 1;
  7860. if (this.twoColorTint) {
  7861. quad[i++] = 0;
  7862. quad[i++] = 0;
  7863. quad[i++] = 0;
  7864. quad[i++] = 0;
  7865. }
  7866. quad[i++] = x3;
  7867. quad[i++] = y3;
  7868. quad[i++] = color.r;
  7869. quad[i++] = color.g;
  7870. quad[i++] = color.b;
  7871. quad[i++] = color.a;
  7872. quad[i++] = 1;
  7873. quad[i++] = 0;
  7874. if (this.twoColorTint) {
  7875. quad[i++] = 0;
  7876. quad[i++] = 0;
  7877. quad[i++] = 0;
  7878. quad[i++] = 0;
  7879. }
  7880. quad[i++] = x4;
  7881. quad[i++] = y4;
  7882. quad[i++] = color.r;
  7883. quad[i++] = color.g;
  7884. quad[i++] = color.b;
  7885. quad[i++] = color.a;
  7886. quad[i++] = 0;
  7887. quad[i++] = 0;
  7888. if (this.twoColorTint) {
  7889. quad[i++] = 0;
  7890. quad[i++] = 0;
  7891. quad[i++] = 0;
  7892. quad[i++] = 0;
  7893. }
  7894. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  7895. };
  7896. SceneRenderer.prototype.drawRegion = function (region, x, y, width, height, color, premultipliedAlpha) {
  7897. if (color === void 0) { color = null; }
  7898. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7899. this.enableRenderer(this.batcher);
  7900. if (color === null)
  7901. color = this.WHITE;
  7902. var quad = this.QUAD;
  7903. var i = 0;
  7904. quad[i++] = x;
  7905. quad[i++] = y;
  7906. quad[i++] = color.r;
  7907. quad[i++] = color.g;
  7908. quad[i++] = color.b;
  7909. quad[i++] = color.a;
  7910. quad[i++] = region.u;
  7911. quad[i++] = region.v2;
  7912. if (this.twoColorTint) {
  7913. quad[i++] = 0;
  7914. quad[i++] = 0;
  7915. quad[i++] = 0;
  7916. quad[i++] = 0;
  7917. }
  7918. quad[i++] = x + width;
  7919. quad[i++] = y;
  7920. quad[i++] = color.r;
  7921. quad[i++] = color.g;
  7922. quad[i++] = color.b;
  7923. quad[i++] = color.a;
  7924. quad[i++] = region.u2;
  7925. quad[i++] = region.v2;
  7926. if (this.twoColorTint) {
  7927. quad[i++] = 0;
  7928. quad[i++] = 0;
  7929. quad[i++] = 0;
  7930. quad[i++] = 0;
  7931. }
  7932. quad[i++] = x + width;
  7933. quad[i++] = y + height;
  7934. quad[i++] = color.r;
  7935. quad[i++] = color.g;
  7936. quad[i++] = color.b;
  7937. quad[i++] = color.a;
  7938. quad[i++] = region.u2;
  7939. quad[i++] = region.v;
  7940. if (this.twoColorTint) {
  7941. quad[i++] = 0;
  7942. quad[i++] = 0;
  7943. quad[i++] = 0;
  7944. quad[i++] = 0;
  7945. }
  7946. quad[i++] = x;
  7947. quad[i++] = y + height;
  7948. quad[i++] = color.r;
  7949. quad[i++] = color.g;
  7950. quad[i++] = color.b;
  7951. quad[i++] = color.a;
  7952. quad[i++] = region.u;
  7953. quad[i++] = region.v;
  7954. if (this.twoColorTint) {
  7955. quad[i++] = 0;
  7956. quad[i++] = 0;
  7957. quad[i++] = 0;
  7958. quad[i++] = 0;
  7959. }
  7960. this.batcher.draw(region.texture, quad, this.QUAD_TRIANGLES);
  7961. };
  7962. SceneRenderer.prototype.line = function (x, y, x2, y2, color, color2) {
  7963. if (color === void 0) { color = null; }
  7964. if (color2 === void 0) { color2 = null; }
  7965. this.enableRenderer(this.shapes);
  7966. this.shapes.line(x, y, x2, y2, color);
  7967. };
  7968. SceneRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  7969. if (color === void 0) { color = null; }
  7970. if (color2 === void 0) { color2 = null; }
  7971. if (color3 === void 0) { color3 = null; }
  7972. this.enableRenderer(this.shapes);
  7973. this.shapes.triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3);
  7974. };
  7975. SceneRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  7976. if (color === void 0) { color = null; }
  7977. if (color2 === void 0) { color2 = null; }
  7978. if (color3 === void 0) { color3 = null; }
  7979. if (color4 === void 0) { color4 = null; }
  7980. this.enableRenderer(this.shapes);
  7981. this.shapes.quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4);
  7982. };
  7983. SceneRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  7984. if (color === void 0) { color = null; }
  7985. this.enableRenderer(this.shapes);
  7986. this.shapes.rect(filled, x, y, width, height, color);
  7987. };
  7988. SceneRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  7989. if (color === void 0) { color = null; }
  7990. this.enableRenderer(this.shapes);
  7991. this.shapes.rectLine(filled, x1, y1, x2, y2, width, color);
  7992. };
  7993. SceneRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  7994. if (color === void 0) { color = null; }
  7995. this.enableRenderer(this.shapes);
  7996. this.shapes.polygon(polygonVertices, offset, count, color);
  7997. };
  7998. SceneRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  7999. if (color === void 0) { color = null; }
  8000. if (segments === void 0) { segments = 0; }
  8001. this.enableRenderer(this.shapes);
  8002. this.shapes.circle(filled, x, y, radius, color, segments);
  8003. };
  8004. SceneRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  8005. if (color === void 0) { color = null; }
  8006. this.enableRenderer(this.shapes);
  8007. this.shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color);
  8008. };
  8009. SceneRenderer.prototype.end = function () {
  8010. if (this.activeRenderer === this.batcher)
  8011. this.batcher.end();
  8012. else if (this.activeRenderer === this.shapes)
  8013. this.shapes.end();
  8014. this.activeRenderer = null;
  8015. };
  8016. SceneRenderer.prototype.resize = function (resizeMode) {
  8017. var canvas = this.canvas;
  8018. var w = canvas.clientWidth;
  8019. var h = canvas.clientHeight;
  8020. if (canvas.width != w || canvas.height != h) {
  8021. canvas.width = w;
  8022. canvas.height = h;
  8023. }
  8024. this.context.gl.viewport(0, 0, canvas.width, canvas.height);
  8025. if (resizeMode === ResizeMode.Stretch) {
  8026. }
  8027. else if (resizeMode === ResizeMode.Expand) {
  8028. this.camera.setViewport(w, h);
  8029. }
  8030. else if (resizeMode === ResizeMode.Fit) {
  8031. var sourceWidth = canvas.width, sourceHeight = canvas.height;
  8032. var targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHeight;
  8033. var targetRatio = targetHeight / targetWidth;
  8034. var sourceRatio = sourceHeight / sourceWidth;
  8035. var scale = targetRatio < sourceRatio ? targetWidth / sourceWidth : targetHeight / sourceHeight;
  8036. this.camera.viewportWidth = sourceWidth * scale;
  8037. this.camera.viewportHeight = sourceHeight * scale;
  8038. }
  8039. this.camera.update();
  8040. };
  8041. SceneRenderer.prototype.enableRenderer = function (renderer) {
  8042. if (this.activeRenderer === renderer)
  8043. return;
  8044. this.end();
  8045. if (renderer instanceof webgl.PolygonBatcher) {
  8046. this.batcherShader.bind();
  8047. this.batcherShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  8048. this.batcherShader.setUniformi("u_texture", 0);
  8049. this.batcher.begin(this.batcherShader);
  8050. this.activeRenderer = this.batcher;
  8051. }
  8052. else if (renderer instanceof webgl.ShapeRenderer) {
  8053. this.shapesShader.bind();
  8054. this.shapesShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  8055. this.shapes.begin(this.shapesShader);
  8056. this.activeRenderer = this.shapes;
  8057. }
  8058. else {
  8059. this.activeRenderer = this.skeletonDebugRenderer;
  8060. }
  8061. };
  8062. SceneRenderer.prototype.dispose = function () {
  8063. this.batcher.dispose();
  8064. this.batcherShader.dispose();
  8065. this.shapes.dispose();
  8066. this.shapesShader.dispose();
  8067. this.skeletonDebugRenderer.dispose();
  8068. };
  8069. return SceneRenderer;
  8070. }());
  8071. webgl.SceneRenderer = SceneRenderer;
  8072. var ResizeMode;
  8073. (function (ResizeMode) {
  8074. ResizeMode[ResizeMode["Stretch"] = 0] = "Stretch";
  8075. ResizeMode[ResizeMode["Expand"] = 1] = "Expand";
  8076. ResizeMode[ResizeMode["Fit"] = 2] = "Fit";
  8077. })(ResizeMode = webgl.ResizeMode || (webgl.ResizeMode = {}));
  8078. })(webgl = spine.webgl || (spine.webgl = {}));
  8079. })(spine || (spine = {}));
  8080. var spine;
  8081. (function (spine) {
  8082. var webgl;
  8083. (function (webgl) {
  8084. var Shader = (function () {
  8085. function Shader(context, vertexShader, fragmentShader) {
  8086. this.vertexShader = vertexShader;
  8087. this.fragmentShader = fragmentShader;
  8088. this.vs = null;
  8089. this.fs = null;
  8090. this.program = null;
  8091. this.tmp2x2 = new Float32Array(2 * 2);
  8092. this.tmp3x3 = new Float32Array(3 * 3);
  8093. this.tmp4x4 = new Float32Array(4 * 4);
  8094. this.vsSource = vertexShader;
  8095. this.fsSource = fragmentShader;
  8096. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8097. this.context.addRestorable(this);
  8098. this.compile();
  8099. }
  8100. Shader.prototype.getProgram = function () { return this.program; };
  8101. Shader.prototype.getVertexShader = function () { return this.vertexShader; };
  8102. Shader.prototype.getFragmentShader = function () { return this.fragmentShader; };
  8103. Shader.prototype.getVertexShaderSource = function () { return this.vsSource; };
  8104. Shader.prototype.getFragmentSource = function () { return this.fsSource; };
  8105. Shader.prototype.compile = function () {
  8106. var gl = this.context.gl;
  8107. try {
  8108. this.vs = this.compileShader(gl.VERTEX_SHADER, this.vertexShader);
  8109. this.fs = this.compileShader(gl.FRAGMENT_SHADER, this.fragmentShader);
  8110. this.program = this.compileProgram(this.vs, this.fs);
  8111. }
  8112. catch (e) {
  8113. this.dispose();
  8114. throw e;
  8115. }
  8116. };
  8117. Shader.prototype.compileShader = function (type, source) {
  8118. var gl = this.context.gl;
  8119. var shader = gl.createShader(type);
  8120. gl.shaderSource(shader, source);
  8121. gl.compileShader(shader);
  8122. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  8123. var error = "Couldn't compile shader: " + gl.getShaderInfoLog(shader);
  8124. gl.deleteShader(shader);
  8125. if (!gl.isContextLost())
  8126. throw new Error(error);
  8127. }
  8128. return shader;
  8129. };
  8130. Shader.prototype.compileProgram = function (vs, fs) {
  8131. var gl = this.context.gl;
  8132. var program = gl.createProgram();
  8133. gl.attachShader(program, vs);
  8134. gl.attachShader(program, fs);
  8135. gl.linkProgram(program);
  8136. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  8137. var error = "Couldn't compile shader program: " + gl.getProgramInfoLog(program);
  8138. gl.deleteProgram(program);
  8139. if (!gl.isContextLost())
  8140. throw new Error(error);
  8141. }
  8142. return program;
  8143. };
  8144. Shader.prototype.restore = function () {
  8145. this.compile();
  8146. };
  8147. Shader.prototype.bind = function () {
  8148. this.context.gl.useProgram(this.program);
  8149. };
  8150. Shader.prototype.unbind = function () {
  8151. this.context.gl.useProgram(null);
  8152. };
  8153. Shader.prototype.setUniformi = function (uniform, value) {
  8154. this.context.gl.uniform1i(this.getUniformLocation(uniform), value);
  8155. };
  8156. Shader.prototype.setUniformf = function (uniform, value) {
  8157. this.context.gl.uniform1f(this.getUniformLocation(uniform), value);
  8158. };
  8159. Shader.prototype.setUniform2f = function (uniform, value, value2) {
  8160. this.context.gl.uniform2f(this.getUniformLocation(uniform), value, value2);
  8161. };
  8162. Shader.prototype.setUniform3f = function (uniform, value, value2, value3) {
  8163. this.context.gl.uniform3f(this.getUniformLocation(uniform), value, value2, value3);
  8164. };
  8165. Shader.prototype.setUniform4f = function (uniform, value, value2, value3, value4) {
  8166. this.context.gl.uniform4f(this.getUniformLocation(uniform), value, value2, value3, value4);
  8167. };
  8168. Shader.prototype.setUniform2x2f = function (uniform, value) {
  8169. var gl = this.context.gl;
  8170. this.tmp2x2.set(value);
  8171. gl.uniformMatrix2fv(this.getUniformLocation(uniform), false, this.tmp2x2);
  8172. };
  8173. Shader.prototype.setUniform3x3f = function (uniform, value) {
  8174. var gl = this.context.gl;
  8175. this.tmp3x3.set(value);
  8176. gl.uniformMatrix3fv(this.getUniformLocation(uniform), false, this.tmp3x3);
  8177. };
  8178. Shader.prototype.setUniform4x4f = function (uniform, value) {
  8179. var gl = this.context.gl;
  8180. this.tmp4x4.set(value);
  8181. gl.uniformMatrix4fv(this.getUniformLocation(uniform), false, this.tmp4x4);
  8182. };
  8183. Shader.prototype.getUniformLocation = function (uniform) {
  8184. var gl = this.context.gl;
  8185. var location = gl.getUniformLocation(this.program, uniform);
  8186. if (!location && !gl.isContextLost())
  8187. throw new Error("Couldn't find location for uniform " + uniform);
  8188. return location;
  8189. };
  8190. Shader.prototype.getAttributeLocation = function (attribute) {
  8191. var gl = this.context.gl;
  8192. var location = gl.getAttribLocation(this.program, attribute);
  8193. if (location == -1 && !gl.isContextLost())
  8194. throw new Error("Couldn't find location for attribute " + attribute);
  8195. return location;
  8196. };
  8197. Shader.prototype.dispose = function () {
  8198. this.context.removeRestorable(this);
  8199. var gl = this.context.gl;
  8200. if (this.vs) {
  8201. gl.deleteShader(this.vs);
  8202. this.vs = null;
  8203. }
  8204. if (this.fs) {
  8205. gl.deleteShader(this.fs);
  8206. this.fs = null;
  8207. }
  8208. if (this.program) {
  8209. gl.deleteProgram(this.program);
  8210. this.program = null;
  8211. }
  8212. };
  8213. Shader.newColoredTextured = function (context) {
  8214. var vs = "\n\t\t\t\tattribute vec4 " + Shader.POSITION + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR + ";\n\t\t\t\tattribute vec2 " + Shader.TEXCOORDS + ";\n\t\t\t\tuniform mat4 " + Shader.MVP_MATRIX + ";\n\t\t\t\tvarying vec4 v_color;\n\t\t\t\tvarying vec2 v_texCoords;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tv_color = " + Shader.COLOR + ";\n\t\t\t\t\tv_texCoords = " + Shader.TEXCOORDS + ";\n\t\t\t\t\tgl_Position = " + Shader.MVP_MATRIX + " * " + Shader.POSITION + ";\n\t\t\t\t}\n\t\t\t";
  8215. var fs = "\n\t\t\t\t#ifdef GL_ES\n\t\t\t\t\t#define LOWP lowp\n\t\t\t\t\tprecision mediump float;\n\t\t\t\t#else\n\t\t\t\t\t#define LOWP\n\t\t\t\t#endif\n\t\t\t\tvarying LOWP vec4 v_color;\n\t\t\t\tvarying vec2 v_texCoords;\n\t\t\t\tuniform sampler2D u_texture;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tgl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n\t\t\t\t}\n\t\t\t";
  8216. return new Shader(context, vs, fs);
  8217. };
  8218. Shader.newTwoColoredTextured = function (context) {
  8219. var vs = "\n\t\t\t\tattribute vec4 " + Shader.POSITION + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR2 + ";\n\t\t\t\tattribute vec2 " + Shader.TEXCOORDS + ";\n\t\t\t\tuniform mat4 " + Shader.MVP_MATRIX + ";\n\t\t\t\tvarying vec4 v_light;\n\t\t\t\tvarying vec4 v_dark;\n\t\t\t\tvarying vec2 v_texCoords;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tv_light = " + Shader.COLOR + ";\n\t\t\t\t\tv_dark = " + Shader.COLOR2 + ";\n\t\t\t\t\tv_texCoords = " + Shader.TEXCOORDS + ";\n\t\t\t\t\tgl_Position = " + Shader.MVP_MATRIX + " * " + Shader.POSITION + ";\n\t\t\t\t}\n\t\t\t";
  8220. var fs = "\n\t\t\t\t#ifdef GL_ES\n\t\t\t\t\t#define LOWP lowp\n\t\t\t\t\tprecision mediump float;\n\t\t\t\t#else\n\t\t\t\t\t#define LOWP\n\t\t\t\t#endif\n\t\t\t\tvarying LOWP vec4 v_light;\n\t\t\t\tvarying LOWP vec4 v_dark;\n\t\t\t\tvarying vec2 v_texCoords;\n\t\t\t\tuniform sampler2D u_texture;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tvec4 texColor = texture2D(u_texture, v_texCoords);\n\t\t\t\t\tgl_FragColor.a = texColor.a * v_light.a;\n\t\t\t\t\tgl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb;\n\t\t\t\t}\n\t\t\t";
  8221. return new Shader(context, vs, fs);
  8222. };
  8223. Shader.newColored = function (context) {
  8224. var vs = "\n\t\t\t\tattribute vec4 " + Shader.POSITION + ";\n\t\t\t\tattribute vec4 " + Shader.COLOR + ";\n\t\t\t\tuniform mat4 " + Shader.MVP_MATRIX + ";\n\t\t\t\tvarying vec4 v_color;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tv_color = " + Shader.COLOR + ";\n\t\t\t\t\tgl_Position = " + Shader.MVP_MATRIX + " * " + Shader.POSITION + ";\n\t\t\t\t}\n\t\t\t";
  8225. var fs = "\n\t\t\t\t#ifdef GL_ES\n\t\t\t\t\t#define LOWP lowp\n\t\t\t\t\tprecision mediump float;\n\t\t\t\t#else\n\t\t\t\t\t#define LOWP\n\t\t\t\t#endif\n\t\t\t\tvarying LOWP vec4 v_color;\n\n\t\t\t\tvoid main () {\n\t\t\t\t\tgl_FragColor = v_color;\n\t\t\t\t}\n\t\t\t";
  8226. return new Shader(context, vs, fs);
  8227. };
  8228. Shader.MVP_MATRIX = "u_projTrans";
  8229. Shader.POSITION = "a_position";
  8230. Shader.COLOR = "a_color";
  8231. Shader.COLOR2 = "a_color2";
  8232. Shader.TEXCOORDS = "a_texCoords";
  8233. Shader.SAMPLER = "u_texture";
  8234. return Shader;
  8235. }());
  8236. webgl.Shader = Shader;
  8237. })(webgl = spine.webgl || (spine.webgl = {}));
  8238. })(spine || (spine = {}));
  8239. var spine;
  8240. (function (spine) {
  8241. var webgl;
  8242. (function (webgl) {
  8243. var ShapeRenderer = (function () {
  8244. function ShapeRenderer(context, maxVertices) {
  8245. if (maxVertices === void 0) { maxVertices = 10920; }
  8246. this.isDrawing = false;
  8247. this.shapeType = ShapeType.Filled;
  8248. this.color = new spine.Color(1, 1, 1, 1);
  8249. this.vertexIndex = 0;
  8250. this.tmp = new spine.Vector2();
  8251. if (maxVertices > 10920)
  8252. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  8253. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8254. this.mesh = new webgl.Mesh(context, [new webgl.Position2Attribute(), new webgl.ColorAttribute()], maxVertices, 0);
  8255. this.srcBlend = this.context.gl.SRC_ALPHA;
  8256. this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
  8257. }
  8258. ShapeRenderer.prototype.begin = function (shader) {
  8259. if (this.isDrawing)
  8260. throw new Error("ShapeRenderer.begin() has already been called");
  8261. this.shader = shader;
  8262. this.vertexIndex = 0;
  8263. this.isDrawing = true;
  8264. var gl = this.context.gl;
  8265. gl.enable(gl.BLEND);
  8266. gl.blendFunc(this.srcBlend, this.dstBlend);
  8267. };
  8268. ShapeRenderer.prototype.setBlendMode = function (srcBlend, dstBlend) {
  8269. var gl = this.context.gl;
  8270. this.srcBlend = srcBlend;
  8271. this.dstBlend = dstBlend;
  8272. if (this.isDrawing) {
  8273. this.flush();
  8274. gl.blendFunc(this.srcBlend, this.dstBlend);
  8275. }
  8276. };
  8277. ShapeRenderer.prototype.setColor = function (color) {
  8278. this.color.setFromColor(color);
  8279. };
  8280. ShapeRenderer.prototype.setColorWith = function (r, g, b, a) {
  8281. this.color.set(r, g, b, a);
  8282. };
  8283. ShapeRenderer.prototype.point = function (x, y, color) {
  8284. if (color === void 0) { color = null; }
  8285. this.check(ShapeType.Point, 1);
  8286. if (color === null)
  8287. color = this.color;
  8288. this.vertex(x, y, color);
  8289. };
  8290. ShapeRenderer.prototype.line = function (x, y, x2, y2, color) {
  8291. if (color === void 0) { color = null; }
  8292. this.check(ShapeType.Line, 2);
  8293. var vertices = this.mesh.getVertices();
  8294. var idx = this.vertexIndex;
  8295. if (color === null)
  8296. color = this.color;
  8297. this.vertex(x, y, color);
  8298. this.vertex(x2, y2, color);
  8299. };
  8300. ShapeRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  8301. if (color === void 0) { color = null; }
  8302. if (color2 === void 0) { color2 = null; }
  8303. if (color3 === void 0) { color3 = null; }
  8304. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  8305. var vertices = this.mesh.getVertices();
  8306. var idx = this.vertexIndex;
  8307. if (color === null)
  8308. color = this.color;
  8309. if (color2 === null)
  8310. color2 = this.color;
  8311. if (color3 === null)
  8312. color3 = this.color;
  8313. if (filled) {
  8314. this.vertex(x, y, color);
  8315. this.vertex(x2, y2, color2);
  8316. this.vertex(x3, y3, color3);
  8317. }
  8318. else {
  8319. this.vertex(x, y, color);
  8320. this.vertex(x2, y2, color2);
  8321. this.vertex(x2, y2, color);
  8322. this.vertex(x3, y3, color2);
  8323. this.vertex(x3, y3, color);
  8324. this.vertex(x, y, color2);
  8325. }
  8326. };
  8327. ShapeRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  8328. if (color === void 0) { color = null; }
  8329. if (color2 === void 0) { color2 = null; }
  8330. if (color3 === void 0) { color3 = null; }
  8331. if (color4 === void 0) { color4 = null; }
  8332. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  8333. var vertices = this.mesh.getVertices();
  8334. var idx = this.vertexIndex;
  8335. if (color === null)
  8336. color = this.color;
  8337. if (color2 === null)
  8338. color2 = this.color;
  8339. if (color3 === null)
  8340. color3 = this.color;
  8341. if (color4 === null)
  8342. color4 = this.color;
  8343. if (filled) {
  8344. this.vertex(x, y, color);
  8345. this.vertex(x2, y2, color2);
  8346. this.vertex(x3, y3, color3);
  8347. this.vertex(x3, y3, color3);
  8348. this.vertex(x4, y4, color4);
  8349. this.vertex(x, y, color);
  8350. }
  8351. else {
  8352. this.vertex(x, y, color);
  8353. this.vertex(x2, y2, color2);
  8354. this.vertex(x2, y2, color2);
  8355. this.vertex(x3, y3, color3);
  8356. this.vertex(x3, y3, color3);
  8357. this.vertex(x4, y4, color4);
  8358. this.vertex(x4, y4, color4);
  8359. this.vertex(x, y, color);
  8360. }
  8361. };
  8362. ShapeRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  8363. if (color === void 0) { color = null; }
  8364. this.quad(filled, x, y, x + width, y, x + width, y + height, x, y + height, color, color, color, color);
  8365. };
  8366. ShapeRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  8367. if (color === void 0) { color = null; }
  8368. this.check(filled ? ShapeType.Filled : ShapeType.Line, 8);
  8369. if (color === null)
  8370. color = this.color;
  8371. var t = this.tmp.set(y2 - y1, x1 - x2);
  8372. t.normalize();
  8373. width *= 0.5;
  8374. var tx = t.x * width;
  8375. var ty = t.y * width;
  8376. if (!filled) {
  8377. this.vertex(x1 + tx, y1 + ty, color);
  8378. this.vertex(x1 - tx, y1 - ty, color);
  8379. this.vertex(x2 + tx, y2 + ty, color);
  8380. this.vertex(x2 - tx, y2 - ty, color);
  8381. this.vertex(x2 + tx, y2 + ty, color);
  8382. this.vertex(x1 + tx, y1 + ty, color);
  8383. this.vertex(x2 - tx, y2 - ty, color);
  8384. this.vertex(x1 - tx, y1 - ty, color);
  8385. }
  8386. else {
  8387. this.vertex(x1 + tx, y1 + ty, color);
  8388. this.vertex(x1 - tx, y1 - ty, color);
  8389. this.vertex(x2 + tx, y2 + ty, color);
  8390. this.vertex(x2 - tx, y2 - ty, color);
  8391. this.vertex(x2 + tx, y2 + ty, color);
  8392. this.vertex(x1 - tx, y1 - ty, color);
  8393. }
  8394. };
  8395. ShapeRenderer.prototype.x = function (x, y, size) {
  8396. this.line(x - size, y - size, x + size, y + size);
  8397. this.line(x - size, y + size, x + size, y - size);
  8398. };
  8399. ShapeRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  8400. if (color === void 0) { color = null; }
  8401. if (count < 3)
  8402. throw new Error("Polygon must contain at least 3 vertices");
  8403. this.check(ShapeType.Line, count * 2);
  8404. if (color === null)
  8405. color = this.color;
  8406. var vertices = this.mesh.getVertices();
  8407. var idx = this.vertexIndex;
  8408. offset <<= 1;
  8409. count <<= 1;
  8410. var firstX = polygonVertices[offset];
  8411. var firstY = polygonVertices[offset + 1];
  8412. var last = offset + count;
  8413. for (var i = offset, n = offset + count - 2; i < n; i += 2) {
  8414. var x1 = polygonVertices[i];
  8415. var y1 = polygonVertices[i + 1];
  8416. var x2 = 0;
  8417. var y2 = 0;
  8418. if (i + 2 >= last) {
  8419. x2 = firstX;
  8420. y2 = firstY;
  8421. }
  8422. else {
  8423. x2 = polygonVertices[i + 2];
  8424. y2 = polygonVertices[i + 3];
  8425. }
  8426. this.vertex(x1, y1, color);
  8427. this.vertex(x2, y2, color);
  8428. }
  8429. };
  8430. ShapeRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  8431. if (color === void 0) { color = null; }
  8432. if (segments === void 0) { segments = 0; }
  8433. if (segments === 0)
  8434. segments = Math.max(1, (6 * spine.MathUtils.cbrt(radius)) | 0);
  8435. if (segments <= 0)
  8436. throw new Error("segments must be > 0.");
  8437. if (color === null)
  8438. color = this.color;
  8439. var angle = 2 * spine.MathUtils.PI / segments;
  8440. var cos = Math.cos(angle);
  8441. var sin = Math.sin(angle);
  8442. var cx = radius, cy = 0;
  8443. if (!filled) {
  8444. this.check(ShapeType.Line, segments * 2 + 2);
  8445. for (var i = 0; i < segments; i++) {
  8446. this.vertex(x + cx, y + cy, color);
  8447. var temp_1 = cx;
  8448. cx = cos * cx - sin * cy;
  8449. cy = sin * temp_1 + cos * cy;
  8450. this.vertex(x + cx, y + cy, color);
  8451. }
  8452. this.vertex(x + cx, y + cy, color);
  8453. }
  8454. else {
  8455. this.check(ShapeType.Filled, segments * 3 + 3);
  8456. segments--;
  8457. for (var i = 0; i < segments; i++) {
  8458. this.vertex(x, y, color);
  8459. this.vertex(x + cx, y + cy, color);
  8460. var temp_2 = cx;
  8461. cx = cos * cx - sin * cy;
  8462. cy = sin * temp_2 + cos * cy;
  8463. this.vertex(x + cx, y + cy, color);
  8464. }
  8465. this.vertex(x, y, color);
  8466. this.vertex(x + cx, y + cy, color);
  8467. }
  8468. var temp = cx;
  8469. cx = radius;
  8470. cy = 0;
  8471. this.vertex(x + cx, y + cy, color);
  8472. };
  8473. ShapeRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  8474. if (color === void 0) { color = null; }
  8475. this.check(ShapeType.Line, segments * 2 + 2);
  8476. if (color === null)
  8477. color = this.color;
  8478. var subdiv_step = 1 / segments;
  8479. var subdiv_step2 = subdiv_step * subdiv_step;
  8480. var subdiv_step3 = subdiv_step * subdiv_step * subdiv_step;
  8481. var pre1 = 3 * subdiv_step;
  8482. var pre2 = 3 * subdiv_step2;
  8483. var pre4 = 6 * subdiv_step2;
  8484. var pre5 = 6 * subdiv_step3;
  8485. var tmp1x = x1 - cx1 * 2 + cx2;
  8486. var tmp1y = y1 - cy1 * 2 + cy2;
  8487. var tmp2x = (cx1 - cx2) * 3 - x1 + x2;
  8488. var tmp2y = (cy1 - cy2) * 3 - y1 + y2;
  8489. var fx = x1;
  8490. var fy = y1;
  8491. var dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
  8492. var dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
  8493. var ddfx = tmp1x * pre4 + tmp2x * pre5;
  8494. var ddfy = tmp1y * pre4 + tmp2y * pre5;
  8495. var dddfx = tmp2x * pre5;
  8496. var dddfy = tmp2y * pre5;
  8497. while (segments-- > 0) {
  8498. this.vertex(fx, fy, color);
  8499. fx += dfx;
  8500. fy += dfy;
  8501. dfx += ddfx;
  8502. dfy += ddfy;
  8503. ddfx += dddfx;
  8504. ddfy += dddfy;
  8505. this.vertex(fx, fy, color);
  8506. }
  8507. this.vertex(fx, fy, color);
  8508. this.vertex(x2, y2, color);
  8509. };
  8510. ShapeRenderer.prototype.vertex = function (x, y, color) {
  8511. var idx = this.vertexIndex;
  8512. var vertices = this.mesh.getVertices();
  8513. vertices[idx++] = x;
  8514. vertices[idx++] = y;
  8515. vertices[idx++] = color.r;
  8516. vertices[idx++] = color.g;
  8517. vertices[idx++] = color.b;
  8518. vertices[idx++] = color.a;
  8519. this.vertexIndex = idx;
  8520. };
  8521. ShapeRenderer.prototype.end = function () {
  8522. if (!this.isDrawing)
  8523. throw new Error("ShapeRenderer.begin() has not been called");
  8524. this.flush();
  8525. this.context.gl.disable(this.context.gl.BLEND);
  8526. this.isDrawing = false;
  8527. };
  8528. ShapeRenderer.prototype.flush = function () {
  8529. if (this.vertexIndex == 0)
  8530. return;
  8531. this.mesh.setVerticesLength(this.vertexIndex);
  8532. this.mesh.draw(this.shader, this.shapeType);
  8533. this.vertexIndex = 0;
  8534. };
  8535. ShapeRenderer.prototype.check = function (shapeType, numVertices) {
  8536. if (!this.isDrawing)
  8537. throw new Error("ShapeRenderer.begin() has not been called");
  8538. if (this.shapeType == shapeType) {
  8539. if (this.mesh.maxVertices() - this.mesh.numVertices() < numVertices)
  8540. this.flush();
  8541. else
  8542. return;
  8543. }
  8544. else {
  8545. this.flush();
  8546. this.shapeType = shapeType;
  8547. }
  8548. };
  8549. ShapeRenderer.prototype.dispose = function () {
  8550. this.mesh.dispose();
  8551. };
  8552. return ShapeRenderer;
  8553. }());
  8554. webgl.ShapeRenderer = ShapeRenderer;
  8555. var ShapeType;
  8556. (function (ShapeType) {
  8557. ShapeType[ShapeType["Point"] = 0] = "Point";
  8558. ShapeType[ShapeType["Line"] = 1] = "Line";
  8559. ShapeType[ShapeType["Filled"] = 4] = "Filled";
  8560. })(ShapeType = webgl.ShapeType || (webgl.ShapeType = {}));
  8561. })(webgl = spine.webgl || (spine.webgl = {}));
  8562. })(spine || (spine = {}));
  8563. var spine;
  8564. (function (spine) {
  8565. var webgl;
  8566. (function (webgl) {
  8567. var SkeletonDebugRenderer = (function () {
  8568. function SkeletonDebugRenderer(context) {
  8569. this.boneLineColor = new spine.Color(1, 0, 0, 1);
  8570. this.boneOriginColor = new spine.Color(0, 1, 0, 1);
  8571. this.attachmentLineColor = new spine.Color(0, 0, 1, 0.5);
  8572. this.triangleLineColor = new spine.Color(1, 0.64, 0, 0.5);
  8573. this.pathColor = new spine.Color().setFromString("FF7F00");
  8574. this.clipColor = new spine.Color(0.8, 0, 0, 2);
  8575. this.aabbColor = new spine.Color(0, 1, 0, 0.5);
  8576. this.drawBones = true;
  8577. this.drawRegionAttachments = true;
  8578. this.drawBoundingBoxes = true;
  8579. this.drawMeshHull = true;
  8580. this.drawMeshTriangles = true;
  8581. this.drawPaths = true;
  8582. this.drawSkeletonXY = false;
  8583. this.drawClipping = true;
  8584. this.premultipliedAlpha = false;
  8585. this.scale = 1;
  8586. this.boneWidth = 2;
  8587. this.bounds = new spine.SkeletonBounds();
  8588. this.temp = new Array();
  8589. this.vertices = spine.Utils.newFloatArray(2 * 1024);
  8590. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8591. }
  8592. SkeletonDebugRenderer.prototype.draw = function (shapes, skeleton, ignoredBones) {
  8593. if (ignoredBones === void 0) { ignoredBones = null; }
  8594. var skeletonX = skeleton.x;
  8595. var skeletonY = skeleton.y;
  8596. var gl = this.context.gl;
  8597. var srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA;
  8598. shapes.setBlendMode(srcFunc, gl.ONE_MINUS_SRC_ALPHA);
  8599. var bones = skeleton.bones;
  8600. if (this.drawBones) {
  8601. shapes.setColor(this.boneLineColor);
  8602. for (var i = 0, n = bones.length; i < n; i++) {
  8603. var bone = bones[i];
  8604. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  8605. continue;
  8606. if (bone.parent == null)
  8607. continue;
  8608. var x = skeletonX + bone.data.length * bone.a + bone.worldX;
  8609. var y = skeletonY + bone.data.length * bone.c + bone.worldY;
  8610. shapes.rectLine(true, skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, this.boneWidth * this.scale);
  8611. }
  8612. if (this.drawSkeletonXY)
  8613. shapes.x(skeletonX, skeletonY, 4 * this.scale);
  8614. }
  8615. if (this.drawRegionAttachments) {
  8616. shapes.setColor(this.attachmentLineColor);
  8617. var slots = skeleton.slots;
  8618. for (var i = 0, n = slots.length; i < n; i++) {
  8619. var slot = slots[i];
  8620. var attachment = slot.getAttachment();
  8621. if (attachment instanceof spine.RegionAttachment) {
  8622. var regionAttachment = attachment;
  8623. var vertices = this.vertices;
  8624. regionAttachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  8625. shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]);
  8626. shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]);
  8627. shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]);
  8628. shapes.line(vertices[6], vertices[7], vertices[0], vertices[1]);
  8629. }
  8630. }
  8631. }
  8632. if (this.drawMeshHull || this.drawMeshTriangles) {
  8633. var slots = skeleton.slots;
  8634. for (var i = 0, n = slots.length; i < n; i++) {
  8635. var slot = slots[i];
  8636. var attachment = slot.getAttachment();
  8637. if (!(attachment instanceof spine.MeshAttachment))
  8638. continue;
  8639. var mesh = attachment;
  8640. var vertices = this.vertices;
  8641. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 2);
  8642. var triangles = mesh.triangles;
  8643. var hullLength = mesh.hullLength;
  8644. if (this.drawMeshTriangles) {
  8645. shapes.setColor(this.triangleLineColor);
  8646. for (var ii = 0, nn = triangles.length; ii < nn; ii += 3) {
  8647. var v1 = triangles[ii] * 2, v2 = triangles[ii + 1] * 2, v3 = triangles[ii + 2] * 2;
  8648. shapes.triangle(false, vertices[v1], vertices[v1 + 1], vertices[v2], vertices[v2 + 1], vertices[v3], vertices[v3 + 1]);
  8649. }
  8650. }
  8651. if (this.drawMeshHull && hullLength > 0) {
  8652. shapes.setColor(this.attachmentLineColor);
  8653. hullLength = (hullLength >> 1) * 2;
  8654. var lastX = vertices[hullLength - 2], lastY = vertices[hullLength - 1];
  8655. for (var ii = 0, nn = hullLength; ii < nn; ii += 2) {
  8656. var x = vertices[ii], y = vertices[ii + 1];
  8657. shapes.line(x, y, lastX, lastY);
  8658. lastX = x;
  8659. lastY = y;
  8660. }
  8661. }
  8662. }
  8663. }
  8664. if (this.drawBoundingBoxes) {
  8665. var bounds = this.bounds;
  8666. bounds.update(skeleton, true);
  8667. shapes.setColor(this.aabbColor);
  8668. shapes.rect(false, bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight());
  8669. var polygons = bounds.polygons;
  8670. var boxes = bounds.boundingBoxes;
  8671. for (var i = 0, n = polygons.length; i < n; i++) {
  8672. var polygon = polygons[i];
  8673. shapes.setColor(boxes[i].color);
  8674. shapes.polygon(polygon, 0, polygon.length);
  8675. }
  8676. }
  8677. if (this.drawPaths) {
  8678. var slots = skeleton.slots;
  8679. for (var i = 0, n = slots.length; i < n; i++) {
  8680. var slot = slots[i];
  8681. var attachment = slot.getAttachment();
  8682. if (!(attachment instanceof spine.PathAttachment))
  8683. continue;
  8684. var path = attachment;
  8685. var nn = path.worldVerticesLength;
  8686. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  8687. path.computeWorldVertices(slot, 0, nn, world, 0, 2);
  8688. var color = this.pathColor;
  8689. var x1 = world[2], y1 = world[3], x2 = 0, y2 = 0;
  8690. if (path.closed) {
  8691. shapes.setColor(color);
  8692. var cx1 = world[0], cy1 = world[1], cx2 = world[nn - 2], cy2 = world[nn - 1];
  8693. x2 = world[nn - 4];
  8694. y2 = world[nn - 3];
  8695. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  8696. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  8697. shapes.line(x1, y1, cx1, cy1);
  8698. shapes.line(x2, y2, cx2, cy2);
  8699. }
  8700. nn -= 4;
  8701. for (var ii = 4; ii < nn; ii += 6) {
  8702. var cx1 = world[ii], cy1 = world[ii + 1], cx2 = world[ii + 2], cy2 = world[ii + 3];
  8703. x2 = world[ii + 4];
  8704. y2 = world[ii + 5];
  8705. shapes.setColor(color);
  8706. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  8707. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  8708. shapes.line(x1, y1, cx1, cy1);
  8709. shapes.line(x2, y2, cx2, cy2);
  8710. x1 = x2;
  8711. y1 = y2;
  8712. }
  8713. }
  8714. }
  8715. if (this.drawBones) {
  8716. shapes.setColor(this.boneOriginColor);
  8717. for (var i = 0, n = bones.length; i < n; i++) {
  8718. var bone = bones[i];
  8719. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  8720. continue;
  8721. shapes.circle(true, skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * this.scale, SkeletonDebugRenderer.GREEN, 8);
  8722. }
  8723. }
  8724. if (this.drawClipping) {
  8725. var slots = skeleton.slots;
  8726. shapes.setColor(this.clipColor);
  8727. for (var i = 0, n = slots.length; i < n; i++) {
  8728. var slot = slots[i];
  8729. var attachment = slot.getAttachment();
  8730. if (!(attachment instanceof spine.ClippingAttachment))
  8731. continue;
  8732. var clip = attachment;
  8733. var nn = clip.worldVerticesLength;
  8734. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  8735. clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
  8736. for (var i_12 = 0, n_2 = world.length; i_12 < n_2; i_12 += 2) {
  8737. var x = world[i_12];
  8738. var y = world[i_12 + 1];
  8739. var x2 = world[(i_12 + 2) % world.length];
  8740. var y2 = world[(i_12 + 3) % world.length];
  8741. shapes.line(x, y, x2, y2);
  8742. }
  8743. }
  8744. }
  8745. };
  8746. SkeletonDebugRenderer.prototype.dispose = function () {
  8747. };
  8748. SkeletonDebugRenderer.LIGHT_GRAY = new spine.Color(192 / 255, 192 / 255, 192 / 255, 1);
  8749. SkeletonDebugRenderer.GREEN = new spine.Color(0, 1, 0, 1);
  8750. return SkeletonDebugRenderer;
  8751. }());
  8752. webgl.SkeletonDebugRenderer = SkeletonDebugRenderer;
  8753. })(webgl = spine.webgl || (spine.webgl = {}));
  8754. })(spine || (spine = {}));
  8755. var spine;
  8756. (function (spine) {
  8757. var webgl;
  8758. (function (webgl) {
  8759. var Renderable = (function () {
  8760. function Renderable(vertices, numVertices, numFloats) {
  8761. this.vertices = vertices;
  8762. this.numVertices = numVertices;
  8763. this.numFloats = numFloats;
  8764. }
  8765. return Renderable;
  8766. }());
  8767. ;
  8768. var SkeletonRenderer = (function () {
  8769. function SkeletonRenderer(context, twoColorTint) {
  8770. if (twoColorTint === void 0) { twoColorTint = true; }
  8771. this.premultipliedAlpha = false;
  8772. this.vertexEffect = null;
  8773. this.tempColor = new spine.Color();
  8774. this.tempColor2 = new spine.Color();
  8775. this.vertexSize = 2 + 2 + 4;
  8776. this.twoColorTint = false;
  8777. this.renderable = new Renderable(null, 0, 0);
  8778. this.clipper = new spine.SkeletonClipping();
  8779. this.temp = new spine.Vector2();
  8780. this.temp2 = new spine.Vector2();
  8781. this.temp3 = new spine.Color();
  8782. this.temp4 = new spine.Color();
  8783. this.twoColorTint = twoColorTint;
  8784. if (twoColorTint)
  8785. this.vertexSize += 4;
  8786. this.vertices = spine.Utils.newFloatArray(this.vertexSize * 1024);
  8787. }
  8788. SkeletonRenderer.prototype.draw = function (batcher, skeleton, slotRangeStart, slotRangeEnd) {
  8789. if (slotRangeStart === void 0) { slotRangeStart = -1; }
  8790. if (slotRangeEnd === void 0) { slotRangeEnd = -1; }
  8791. var clipper = this.clipper;
  8792. var premultipliedAlpha = this.premultipliedAlpha;
  8793. var twoColorTint = this.twoColorTint;
  8794. var blendMode = null;
  8795. var tempPos = this.temp;
  8796. var tempUv = this.temp2;
  8797. var tempLight = this.temp3;
  8798. var tempDark = this.temp4;
  8799. var renderable = this.renderable;
  8800. var uvs = null;
  8801. var triangles = null;
  8802. var drawOrder = skeleton.drawOrder;
  8803. var attachmentColor = null;
  8804. var skeletonColor = skeleton.color;
  8805. var vertexSize = twoColorTint ? 12 : 8;
  8806. var inRange = false;
  8807. if (slotRangeStart == -1)
  8808. inRange = true;
  8809. for (var i = 0, n = drawOrder.length; i < n; i++) {
  8810. var clippedVertexSize = clipper.isClipping() ? 2 : vertexSize;
  8811. var slot = drawOrder[i];
  8812. if (slotRangeStart >= 0 && slotRangeStart == slot.data.index) {
  8813. inRange = true;
  8814. }
  8815. if (!inRange) {
  8816. clipper.clipEndWithSlot(slot);
  8817. continue;
  8818. }
  8819. if (slotRangeEnd >= 0 && slotRangeEnd == slot.data.index) {
  8820. inRange = false;
  8821. }
  8822. var attachment = slot.getAttachment();
  8823. var texture = null;
  8824. if (attachment instanceof spine.RegionAttachment) {
  8825. var region = attachment;
  8826. renderable.vertices = this.vertices;
  8827. renderable.numVertices = 4;
  8828. renderable.numFloats = clippedVertexSize << 2;
  8829. region.computeWorldVertices(slot.bone, renderable.vertices, 0, clippedVertexSize);
  8830. triangles = SkeletonRenderer.QUAD_TRIANGLES;
  8831. uvs = region.uvs;
  8832. texture = region.region.renderObject.texture;
  8833. attachmentColor = region.color;
  8834. }
  8835. else if (attachment instanceof spine.MeshAttachment) {
  8836. var mesh = attachment;
  8837. renderable.vertices = this.vertices;
  8838. renderable.numVertices = (mesh.worldVerticesLength >> 1);
  8839. renderable.numFloats = renderable.numVertices * clippedVertexSize;
  8840. if (renderable.numFloats > renderable.vertices.length) {
  8841. renderable.vertices = this.vertices = spine.Utils.newFloatArray(renderable.numFloats);
  8842. }
  8843. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, renderable.vertices, 0, clippedVertexSize);
  8844. triangles = mesh.triangles;
  8845. texture = mesh.region.renderObject.texture;
  8846. uvs = mesh.uvs;
  8847. attachmentColor = mesh.color;
  8848. }
  8849. else if (attachment instanceof spine.ClippingAttachment) {
  8850. var clip = (attachment);
  8851. clipper.clipStart(slot, clip);
  8852. continue;
  8853. }
  8854. else
  8855. continue;
  8856. if (texture != null) {
  8857. var slotColor = slot.color;
  8858. var finalColor = this.tempColor;
  8859. finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
  8860. finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
  8861. finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
  8862. finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
  8863. if (premultipliedAlpha) {
  8864. finalColor.r *= finalColor.a;
  8865. finalColor.g *= finalColor.a;
  8866. finalColor.b *= finalColor.a;
  8867. }
  8868. var darkColor = this.tempColor2;
  8869. if (slot.darkColor == null)
  8870. darkColor.set(0, 0, 0, 1.0);
  8871. else {
  8872. if (premultipliedAlpha) {
  8873. darkColor.r = slot.darkColor.r * finalColor.a;
  8874. darkColor.g = slot.darkColor.g * finalColor.a;
  8875. darkColor.b = slot.darkColor.b * finalColor.a;
  8876. }
  8877. else {
  8878. darkColor.setFromColor(slot.darkColor);
  8879. }
  8880. darkColor.a = premultipliedAlpha ? 1.0 : 0.0;
  8881. }
  8882. var slotBlendMode = slot.data.blendMode;
  8883. if (slotBlendMode != blendMode) {
  8884. blendMode = slotBlendMode;
  8885. batcher.setBlendMode(webgl.WebGLBlendModeConverter.getSourceGLBlendMode(blendMode, premultipliedAlpha), webgl.WebGLBlendModeConverter.getDestGLBlendMode(blendMode));
  8886. }
  8887. if (clipper.isClipping()) {
  8888. clipper.clipTriangles(renderable.vertices, renderable.numFloats, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint);
  8889. var clippedVertices = new Float32Array(clipper.clippedVertices);
  8890. var clippedTriangles = clipper.clippedTriangles;
  8891. if (this.vertexEffect != null) {
  8892. var vertexEffect = this.vertexEffect;
  8893. var verts = clippedVertices;
  8894. if (!twoColorTint) {
  8895. for (var v = 0, n_3 = clippedVertices.length; v < n_3; v += vertexSize) {
  8896. tempPos.x = verts[v];
  8897. tempPos.y = verts[v + 1];
  8898. tempLight.set(verts[v + 2], verts[v + 3], verts[v + 4], verts[v + 5]);
  8899. tempUv.x = verts[v + 6];
  8900. tempUv.y = verts[v + 7];
  8901. tempDark.set(0, 0, 0, 0);
  8902. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  8903. verts[v] = tempPos.x;
  8904. verts[v + 1] = tempPos.y;
  8905. verts[v + 2] = tempLight.r;
  8906. verts[v + 3] = tempLight.g;
  8907. verts[v + 4] = tempLight.b;
  8908. verts[v + 5] = tempLight.a;
  8909. verts[v + 6] = tempUv.x;
  8910. verts[v + 7] = tempUv.y;
  8911. }
  8912. }
  8913. else {
  8914. for (var v = 0, n_4 = clippedVertices.length; v < n_4; v += vertexSize) {
  8915. tempPos.x = verts[v];
  8916. tempPos.y = verts[v + 1];
  8917. tempLight.set(verts[v + 2], verts[v + 3], verts[v + 4], verts[v + 5]);
  8918. tempUv.x = verts[v + 6];
  8919. tempUv.y = verts[v + 7];
  8920. tempDark.set(verts[v + 8], verts[v + 9], verts[v + 10], verts[v + 11]);
  8921. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  8922. verts[v] = tempPos.x;
  8923. verts[v + 1] = tempPos.y;
  8924. verts[v + 2] = tempLight.r;
  8925. verts[v + 3] = tempLight.g;
  8926. verts[v + 4] = tempLight.b;
  8927. verts[v + 5] = tempLight.a;
  8928. verts[v + 6] = tempUv.x;
  8929. verts[v + 7] = tempUv.y;
  8930. verts[v + 8] = tempDark.r;
  8931. verts[v + 9] = tempDark.g;
  8932. verts[v + 10] = tempDark.b;
  8933. verts[v + 11] = tempDark.a;
  8934. }
  8935. }
  8936. }
  8937. batcher.draw(texture, clippedVertices, clippedTriangles);
  8938. }
  8939. else {
  8940. var verts = renderable.vertices;
  8941. if (this.vertexEffect != null) {
  8942. var vertexEffect = this.vertexEffect;
  8943. if (!twoColorTint) {
  8944. for (var v = 0, u = 0, n_5 = renderable.numFloats; v < n_5; v += vertexSize, u += 2) {
  8945. tempPos.x = verts[v];
  8946. tempPos.y = verts[v + 1];
  8947. tempUv.x = uvs[u];
  8948. tempUv.y = uvs[u + 1];
  8949. tempLight.setFromColor(finalColor);
  8950. tempDark.set(0, 0, 0, 0);
  8951. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  8952. verts[v] = tempPos.x;
  8953. verts[v + 1] = tempPos.y;
  8954. verts[v + 2] = tempLight.r;
  8955. verts[v + 3] = tempLight.g;
  8956. verts[v + 4] = tempLight.b;
  8957. verts[v + 5] = tempLight.a;
  8958. verts[v + 6] = tempUv.x;
  8959. verts[v + 7] = tempUv.y;
  8960. }
  8961. }
  8962. else {
  8963. for (var v = 0, u = 0, n_6 = renderable.numFloats; v < n_6; v += vertexSize, u += 2) {
  8964. tempPos.x = verts[v];
  8965. tempPos.y = verts[v + 1];
  8966. tempUv.x = uvs[u];
  8967. tempUv.y = uvs[u + 1];
  8968. tempLight.setFromColor(finalColor);
  8969. tempDark.setFromColor(darkColor);
  8970. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  8971. verts[v] = tempPos.x;
  8972. verts[v + 1] = tempPos.y;
  8973. verts[v + 2] = tempLight.r;
  8974. verts[v + 3] = tempLight.g;
  8975. verts[v + 4] = tempLight.b;
  8976. verts[v + 5] = tempLight.a;
  8977. verts[v + 6] = tempUv.x;
  8978. verts[v + 7] = tempUv.y;
  8979. verts[v + 8] = tempDark.r;
  8980. verts[v + 9] = tempDark.g;
  8981. verts[v + 10] = tempDark.b;
  8982. verts[v + 11] = tempDark.a;
  8983. }
  8984. }
  8985. }
  8986. else {
  8987. if (!twoColorTint) {
  8988. for (var v = 2, u = 0, n_7 = renderable.numFloats; v < n_7; v += vertexSize, u += 2) {
  8989. verts[v] = finalColor.r;
  8990. verts[v + 1] = finalColor.g;
  8991. verts[v + 2] = finalColor.b;
  8992. verts[v + 3] = finalColor.a;
  8993. verts[v + 4] = uvs[u];
  8994. verts[v + 5] = uvs[u + 1];
  8995. }
  8996. }
  8997. else {
  8998. for (var v = 2, u = 0, n_8 = renderable.numFloats; v < n_8; v += vertexSize, u += 2) {
  8999. verts[v] = finalColor.r;
  9000. verts[v + 1] = finalColor.g;
  9001. verts[v + 2] = finalColor.b;
  9002. verts[v + 3] = finalColor.a;
  9003. verts[v + 4] = uvs[u];
  9004. verts[v + 5] = uvs[u + 1];
  9005. verts[v + 6] = darkColor.r;
  9006. verts[v + 7] = darkColor.g;
  9007. verts[v + 8] = darkColor.b;
  9008. verts[v + 9] = darkColor.a;
  9009. }
  9010. }
  9011. }
  9012. var view = renderable.vertices.subarray(0, renderable.numFloats);
  9013. batcher.draw(texture, view, triangles);
  9014. }
  9015. }
  9016. clipper.clipEndWithSlot(slot);
  9017. }
  9018. clipper.clipEnd();
  9019. };
  9020. SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  9021. return SkeletonRenderer;
  9022. }());
  9023. webgl.SkeletonRenderer = SkeletonRenderer;
  9024. })(webgl = spine.webgl || (spine.webgl = {}));
  9025. })(spine || (spine = {}));
  9026. var spine;
  9027. (function (spine) {
  9028. var webgl;
  9029. (function (webgl) {
  9030. var Vector3 = (function () {
  9031. function Vector3(x, y, z) {
  9032. if (x === void 0) { x = 0; }
  9033. if (y === void 0) { y = 0; }
  9034. if (z === void 0) { z = 0; }
  9035. this.x = 0;
  9036. this.y = 0;
  9037. this.z = 0;
  9038. this.x = x;
  9039. this.y = y;
  9040. this.z = z;
  9041. }
  9042. Vector3.prototype.setFrom = function (v) {
  9043. this.x = v.x;
  9044. this.y = v.y;
  9045. this.z = v.z;
  9046. return this;
  9047. };
  9048. Vector3.prototype.set = function (x, y, z) {
  9049. this.x = x;
  9050. this.y = y;
  9051. this.z = z;
  9052. return this;
  9053. };
  9054. Vector3.prototype.add = function (v) {
  9055. this.x += v.x;
  9056. this.y += v.y;
  9057. this.z += v.z;
  9058. return this;
  9059. };
  9060. Vector3.prototype.sub = function (v) {
  9061. this.x -= v.x;
  9062. this.y -= v.y;
  9063. this.z -= v.z;
  9064. return this;
  9065. };
  9066. Vector3.prototype.scale = function (s) {
  9067. this.x *= s;
  9068. this.y *= s;
  9069. this.z *= s;
  9070. return this;
  9071. };
  9072. Vector3.prototype.normalize = function () {
  9073. var len = this.length();
  9074. if (len == 0)
  9075. return this;
  9076. len = 1 / len;
  9077. this.x *= len;
  9078. this.y *= len;
  9079. this.z *= len;
  9080. return this;
  9081. };
  9082. Vector3.prototype.cross = function (v) {
  9083. return this.set(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
  9084. };
  9085. Vector3.prototype.multiply = function (matrix) {
  9086. var l_mat = matrix.values;
  9087. return this.set(this.x * l_mat[webgl.M00] + this.y * l_mat[webgl.M01] + this.z * l_mat[webgl.M02] + l_mat[webgl.M03], this.x * l_mat[webgl.M10] + this.y * l_mat[webgl.M11] + this.z * l_mat[webgl.M12] + l_mat[webgl.M13], this.x * l_mat[webgl.M20] + this.y * l_mat[webgl.M21] + this.z * l_mat[webgl.M22] + l_mat[webgl.M23]);
  9088. };
  9089. Vector3.prototype.project = function (matrix) {
  9090. var l_mat = matrix.values;
  9091. var l_w = 1 / (this.x * l_mat[webgl.M30] + this.y * l_mat[webgl.M31] + this.z * l_mat[webgl.M32] + l_mat[webgl.M33]);
  9092. return this.set((this.x * l_mat[webgl.M00] + this.y * l_mat[webgl.M01] + this.z * l_mat[webgl.M02] + l_mat[webgl.M03]) * l_w, (this.x * l_mat[webgl.M10] + this.y * l_mat[webgl.M11] + this.z * l_mat[webgl.M12] + l_mat[webgl.M13]) * l_w, (this.x * l_mat[webgl.M20] + this.y * l_mat[webgl.M21] + this.z * l_mat[webgl.M22] + l_mat[webgl.M23]) * l_w);
  9093. };
  9094. Vector3.prototype.dot = function (v) {
  9095. return this.x * v.x + this.y * v.y + this.z * v.z;
  9096. };
  9097. Vector3.prototype.length = function () {
  9098. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  9099. };
  9100. Vector3.prototype.distance = function (v) {
  9101. var a = v.x - this.x;
  9102. var b = v.y - this.y;
  9103. var c = v.z - this.z;
  9104. return Math.sqrt(a * a + b * b + c * c);
  9105. };
  9106. return Vector3;
  9107. }());
  9108. webgl.Vector3 = Vector3;
  9109. })(webgl = spine.webgl || (spine.webgl = {}));
  9110. })(spine || (spine = {}));
  9111. var spine;
  9112. (function (spine) {
  9113. var webgl;
  9114. (function (webgl) {
  9115. var ManagedWebGLRenderingContext = (function () {
  9116. function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) {
  9117. if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
  9118. var _this = this;
  9119. this.restorables = new Array();
  9120. if (canvasOrContext instanceof HTMLCanvasElement) {
  9121. var canvas = canvasOrContext;
  9122. this.gl = (canvas.getContext("webgl", contextConfig) || canvas.getContext("experimental-webgl", contextConfig));
  9123. this.canvas = canvas;
  9124. canvas.addEventListener("webglcontextlost", function (e) {
  9125. var event = e;
  9126. if (e) {
  9127. e.preventDefault();
  9128. }
  9129. });
  9130. canvas.addEventListener("webglcontextrestored", function (e) {
  9131. for (var i = 0, n = _this.restorables.length; i < n; i++) {
  9132. _this.restorables[i].restore();
  9133. }
  9134. });
  9135. }
  9136. else {
  9137. this.gl = canvasOrContext;
  9138. this.canvas = this.gl.canvas;
  9139. }
  9140. }
  9141. ManagedWebGLRenderingContext.prototype.addRestorable = function (restorable) {
  9142. this.restorables.push(restorable);
  9143. };
  9144. ManagedWebGLRenderingContext.prototype.removeRestorable = function (restorable) {
  9145. var index = this.restorables.indexOf(restorable);
  9146. if (index > -1)
  9147. this.restorables.splice(index, 1);
  9148. };
  9149. return ManagedWebGLRenderingContext;
  9150. }());
  9151. webgl.ManagedWebGLRenderingContext = ManagedWebGLRenderingContext;
  9152. var WebGLBlendModeConverter = (function () {
  9153. function WebGLBlendModeConverter() {
  9154. }
  9155. WebGLBlendModeConverter.getDestGLBlendMode = function (blendMode) {
  9156. switch (blendMode) {
  9157. case spine.BlendMode.Normal: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9158. case spine.BlendMode.Additive: return WebGLBlendModeConverter.ONE;
  9159. case spine.BlendMode.Multiply: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9160. case spine.BlendMode.Screen: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9161. default: throw new Error("Unknown blend mode: " + blendMode);
  9162. }
  9163. };
  9164. WebGLBlendModeConverter.getSourceGLBlendMode = function (blendMode, premultipliedAlpha) {
  9165. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  9166. switch (blendMode) {
  9167. case spine.BlendMode.Normal: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA;
  9168. case spine.BlendMode.Additive: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA;
  9169. case spine.BlendMode.Multiply: return WebGLBlendModeConverter.DST_COLOR;
  9170. case spine.BlendMode.Screen: return WebGLBlendModeConverter.ONE;
  9171. default: throw new Error("Unknown blend mode: " + blendMode);
  9172. }
  9173. };
  9174. WebGLBlendModeConverter.ZERO = 0;
  9175. WebGLBlendModeConverter.ONE = 1;
  9176. WebGLBlendModeConverter.SRC_COLOR = 0x0300;
  9177. WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR = 0x0301;
  9178. WebGLBlendModeConverter.SRC_ALPHA = 0x0302;
  9179. WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA = 0x0303;
  9180. WebGLBlendModeConverter.DST_ALPHA = 0x0304;
  9181. WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA = 0x0305;
  9182. WebGLBlendModeConverter.DST_COLOR = 0x0306;
  9183. return WebGLBlendModeConverter;
  9184. }());
  9185. webgl.WebGLBlendModeConverter = WebGLBlendModeConverter;
  9186. })(webgl = spine.webgl || (spine.webgl = {}));
  9187. })(spine || (spine = {}));
  9188. module.exports = spine;