spine-webgl.js 420 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = function (d, b) {
  3. extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  6. return extendStatics(d, b);
  7. };
  8. return function (d, b) {
  9. if (typeof b !== "function" && b !== null)
  10. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  11. extendStatics(d, b);
  12. function __() { this.constructor = d; }
  13. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14. };
  15. })();
  16. var spine;
  17. (function (spine) {
  18. var Animation = (function () {
  19. function Animation(name, timelines, duration) {
  20. if (!name)
  21. throw new Error("name cannot be null.");
  22. this.name = name;
  23. this.setTimelines(timelines);
  24. this.duration = duration;
  25. }
  26. Animation.prototype.setTimelines = function (timelines) {
  27. if (!timelines)
  28. throw new Error("timelines cannot be null.");
  29. this.timelines = timelines;
  30. this.timelineIds = new spine.StringSet();
  31. for (var i = 0; i < timelines.length; i++)
  32. this.timelineIds.addAll(timelines[i].getPropertyIds());
  33. };
  34. Animation.prototype.hasTimeline = function (ids) {
  35. for (var i = 0; i < ids.length; i++)
  36. if (this.timelineIds.contains(ids[i]))
  37. return true;
  38. return false;
  39. };
  40. Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, blend, direction) {
  41. if (!skeleton)
  42. throw new Error("skeleton cannot be null.");
  43. if (loop && this.duration != 0) {
  44. time %= this.duration;
  45. if (lastTime > 0)
  46. lastTime %= this.duration;
  47. }
  48. var timelines = this.timelines;
  49. for (var i = 0, n = timelines.length; i < n; i++)
  50. timelines[i].apply(skeleton, lastTime, time, events, alpha, blend, direction);
  51. };
  52. return Animation;
  53. }());
  54. spine.Animation = Animation;
  55. var MixBlend;
  56. (function (MixBlend) {
  57. MixBlend[MixBlend["setup"] = 0] = "setup";
  58. MixBlend[MixBlend["first"] = 1] = "first";
  59. MixBlend[MixBlend["replace"] = 2] = "replace";
  60. MixBlend[MixBlend["add"] = 3] = "add";
  61. })(MixBlend = spine.MixBlend || (spine.MixBlend = {}));
  62. var MixDirection;
  63. (function (MixDirection) {
  64. MixDirection[MixDirection["mixIn"] = 0] = "mixIn";
  65. MixDirection[MixDirection["mixOut"] = 1] = "mixOut";
  66. })(MixDirection = spine.MixDirection || (spine.MixDirection = {}));
  67. var Property = {
  68. rotate: 0,
  69. x: 1,
  70. y: 2,
  71. scaleX: 3,
  72. scaleY: 4,
  73. shearX: 5,
  74. shearY: 6,
  75. rgb: 7,
  76. alpha: 8,
  77. rgb2: 9,
  78. attachment: 10,
  79. deform: 11,
  80. event: 12,
  81. drawOrder: 13,
  82. ikConstraint: 14,
  83. transformConstraint: 15,
  84. pathConstraintPosition: 16,
  85. pathConstraintSpacing: 17,
  86. pathConstraintMix: 18
  87. };
  88. var Timeline = (function () {
  89. function Timeline(frameCount, propertyIds) {
  90. this.propertyIds = propertyIds;
  91. this.frames = spine.Utils.newFloatArray(frameCount * this.getFrameEntries());
  92. }
  93. Timeline.prototype.getPropertyIds = function () {
  94. return this.propertyIds;
  95. };
  96. Timeline.prototype.getFrameEntries = function () {
  97. return 1;
  98. };
  99. Timeline.prototype.getFrameCount = function () {
  100. return this.frames.length / this.getFrameEntries();
  101. };
  102. Timeline.prototype.getDuration = function () {
  103. return this.frames[this.frames.length - this.getFrameEntries()];
  104. };
  105. Timeline.search1 = function (frames, time) {
  106. var n = frames.length;
  107. for (var i = 1; i < n; i++)
  108. if (frames[i] > time)
  109. return i - 1;
  110. return n - 1;
  111. };
  112. Timeline.search = function (frames, time, step) {
  113. var n = frames.length;
  114. for (var i = step; i < n; i += step)
  115. if (frames[i] > time)
  116. return i - step;
  117. return n - step;
  118. };
  119. return Timeline;
  120. }());
  121. spine.Timeline = Timeline;
  122. var CurveTimeline = (function (_super) {
  123. __extends(CurveTimeline, _super);
  124. function CurveTimeline(frameCount, bezierCount, propertyIds) {
  125. var _this = _super.call(this, frameCount, propertyIds) || this;
  126. _this.curves = spine.Utils.newFloatArray(frameCount + bezierCount * 18);
  127. _this.curves[frameCount - 1] = 1;
  128. return _this;
  129. }
  130. CurveTimeline.prototype.setLinear = function (frame) {
  131. this.curves[frame] = 0;
  132. };
  133. CurveTimeline.prototype.setStepped = function (frame) {
  134. this.curves[frame] = 1;
  135. };
  136. CurveTimeline.prototype.shrink = function (bezierCount) {
  137. var size = this.getFrameCount() + bezierCount * 18;
  138. if (this.curves.length > size) {
  139. var newCurves = spine.Utils.newFloatArray(size);
  140. spine.Utils.arrayCopy(this.curves, 0, newCurves, 0, size);
  141. this.curves = newCurves;
  142. }
  143. };
  144. CurveTimeline.prototype.setBezier = function (bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) {
  145. var curves = this.curves;
  146. var i = this.getFrameCount() + bezier * 18;
  147. if (value == 0)
  148. curves[frame] = 2 + i;
  149. var tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = (value1 - cy1 * 2 + cy2) * 0.03;
  150. var dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = ((cy1 - cy2) * 3 - value1 + value2) * 0.006;
  151. var ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
  152. var dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = (cy1 - value1) * 0.3 + tmpy + dddy * 0.16666667;
  153. var x = time1 + dx, y = value1 + dy;
  154. for (var n = i + 18; i < n; i += 2) {
  155. curves[i] = x;
  156. curves[i + 1] = y;
  157. dx += ddx;
  158. dy += ddy;
  159. ddx += dddx;
  160. ddy += dddy;
  161. x += dx;
  162. y += dy;
  163. }
  164. };
  165. CurveTimeline.prototype.getBezierValue = function (time, frameIndex, valueOffset, i) {
  166. var curves = this.curves;
  167. if (curves[i] > time) {
  168. var x_1 = this.frames[frameIndex], y_1 = this.frames[frameIndex + valueOffset];
  169. return y_1 + (time - x_1) / (curves[i] - x_1) * (curves[i + 1] - y_1);
  170. }
  171. var n = i + 18;
  172. for (i += 2; i < n; i += 2) {
  173. if (curves[i] >= time) {
  174. var x_2 = curves[i - 2], y_2 = curves[i - 1];
  175. return y_2 + (time - x_2) / (curves[i] - x_2) * (curves[i + 1] - y_2);
  176. }
  177. }
  178. frameIndex += this.getFrameEntries();
  179. var x = curves[n - 2], y = curves[n - 1];
  180. return y + (time - x) / (this.frames[frameIndex] - x) * (this.frames[frameIndex + valueOffset] - y);
  181. };
  182. return CurveTimeline;
  183. }(Timeline));
  184. spine.CurveTimeline = CurveTimeline;
  185. var CurveTimeline1 = (function (_super) {
  186. __extends(CurveTimeline1, _super);
  187. function CurveTimeline1(frameCount, bezierCount, propertyId) {
  188. return _super.call(this, frameCount, bezierCount, [propertyId]) || this;
  189. }
  190. CurveTimeline1.prototype.getFrameEntries = function () {
  191. return 2;
  192. };
  193. CurveTimeline1.prototype.setFrame = function (frame, time, value) {
  194. frame <<= 1;
  195. this.frames[frame] = time;
  196. this.frames[frame + 1] = value;
  197. };
  198. CurveTimeline1.prototype.getCurveValue = function (time) {
  199. var frames = this.frames;
  200. var i = frames.length - 2;
  201. for (var ii = 2; ii <= i; ii += 2) {
  202. if (frames[ii] > time) {
  203. i = ii - 2;
  204. break;
  205. }
  206. }
  207. var curveType = this.curves[i >> 1];
  208. switch (curveType) {
  209. case 0:
  210. var before = frames[i], value = frames[i + 1];
  211. return value + (time - before) / (frames[i + 2] - before) * (frames[i + 2 + 1] - value);
  212. case 1:
  213. return frames[i + 1];
  214. }
  215. return this.getBezierValue(time, i, 1, curveType - 2);
  216. };
  217. return CurveTimeline1;
  218. }(CurveTimeline));
  219. spine.CurveTimeline1 = CurveTimeline1;
  220. var CurveTimeline2 = (function (_super) {
  221. __extends(CurveTimeline2, _super);
  222. function CurveTimeline2(frameCount, bezierCount, propertyId1, propertyId2) {
  223. return _super.call(this, frameCount, bezierCount, [propertyId1, propertyId2]) || this;
  224. }
  225. CurveTimeline2.prototype.getFrameEntries = function () {
  226. return 3;
  227. };
  228. CurveTimeline2.prototype.setFrame = function (frame, time, value1, value2) {
  229. frame *= 3;
  230. this.frames[frame] = time;
  231. this.frames[frame + 1] = value1;
  232. this.frames[frame + 2] = value2;
  233. };
  234. return CurveTimeline2;
  235. }(CurveTimeline));
  236. spine.CurveTimeline2 = CurveTimeline2;
  237. var RotateTimeline = (function (_super) {
  238. __extends(RotateTimeline, _super);
  239. function RotateTimeline(frameCount, bezierCount, boneIndex) {
  240. var _this = _super.call(this, frameCount, bezierCount, Property.rotate + "|" + boneIndex) || this;
  241. _this.boneIndex = 0;
  242. _this.boneIndex = boneIndex;
  243. return _this;
  244. }
  245. RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  246. var bone = skeleton.bones[this.boneIndex];
  247. if (!bone.active)
  248. return;
  249. var frames = this.frames;
  250. if (time < frames[0]) {
  251. switch (blend) {
  252. case MixBlend.setup:
  253. bone.rotation = bone.data.rotation;
  254. return;
  255. case MixBlend.first:
  256. bone.rotation += (bone.data.rotation - bone.rotation) * alpha;
  257. }
  258. return;
  259. }
  260. var r = this.getCurveValue(time);
  261. switch (blend) {
  262. case MixBlend.setup:
  263. bone.rotation = bone.data.rotation + r * alpha;
  264. break;
  265. case MixBlend.first:
  266. case MixBlend.replace:
  267. r += bone.data.rotation - bone.rotation;
  268. case MixBlend.add:
  269. bone.rotation += r * alpha;
  270. }
  271. };
  272. return RotateTimeline;
  273. }(CurveTimeline1));
  274. spine.RotateTimeline = RotateTimeline;
  275. var TranslateTimeline = (function (_super) {
  276. __extends(TranslateTimeline, _super);
  277. function TranslateTimeline(frameCount, bezierCount, boneIndex) {
  278. var _this = _super.call(this, frameCount, bezierCount, Property.x + "|" + boneIndex, Property.y + "|" + boneIndex) || this;
  279. _this.boneIndex = 0;
  280. _this.boneIndex = boneIndex;
  281. return _this;
  282. }
  283. TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  284. var bone = skeleton.bones[this.boneIndex];
  285. if (!bone.active)
  286. return;
  287. var frames = this.frames;
  288. if (time < frames[0]) {
  289. switch (blend) {
  290. case MixBlend.setup:
  291. bone.x = bone.data.x;
  292. bone.y = bone.data.y;
  293. return;
  294. case MixBlend.first:
  295. bone.x += (bone.data.x - bone.x) * alpha;
  296. bone.y += (bone.data.y - bone.y) * alpha;
  297. }
  298. return;
  299. }
  300. var x = 0, y = 0;
  301. var i = Timeline.search(frames, time, 3);
  302. var curveType = this.curves[i / 3];
  303. switch (curveType) {
  304. case 0:
  305. var before = frames[i];
  306. x = frames[i + 1];
  307. y = frames[i + 2];
  308. var t = (time - before) / (frames[i + 3] - before);
  309. x += (frames[i + 3 + 1] - x) * t;
  310. y += (frames[i + 3 + 2] - y) * t;
  311. break;
  312. case 1:
  313. x = frames[i + 1];
  314. y = frames[i + 2];
  315. break;
  316. default:
  317. x = this.getBezierValue(time, i, 1, curveType - 2);
  318. y = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  319. }
  320. switch (blend) {
  321. case MixBlend.setup:
  322. bone.x = bone.data.x + x * alpha;
  323. bone.y = bone.data.y + y * alpha;
  324. break;
  325. case MixBlend.first:
  326. case MixBlend.replace:
  327. bone.x += (bone.data.x + x - bone.x) * alpha;
  328. bone.y += (bone.data.y + y - bone.y) * alpha;
  329. break;
  330. case MixBlend.add:
  331. bone.x += x * alpha;
  332. bone.y += y * alpha;
  333. }
  334. };
  335. return TranslateTimeline;
  336. }(CurveTimeline2));
  337. spine.TranslateTimeline = TranslateTimeline;
  338. var TranslateXTimeline = (function (_super) {
  339. __extends(TranslateXTimeline, _super);
  340. function TranslateXTimeline(frameCount, bezierCount, boneIndex) {
  341. var _this = _super.call(this, frameCount, bezierCount, Property.x + "|" + boneIndex) || this;
  342. _this.boneIndex = 0;
  343. _this.boneIndex = boneIndex;
  344. return _this;
  345. }
  346. TranslateXTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  347. var bone = skeleton.bones[this.boneIndex];
  348. if (!bone.active)
  349. return;
  350. var frames = this.frames;
  351. if (time < frames[0]) {
  352. switch (blend) {
  353. case MixBlend.setup:
  354. bone.x = bone.data.x;
  355. return;
  356. case MixBlend.first:
  357. bone.x += (bone.data.x - bone.x) * alpha;
  358. }
  359. return;
  360. }
  361. var x = this.getCurveValue(time);
  362. switch (blend) {
  363. case MixBlend.setup:
  364. bone.x = bone.data.x + x * alpha;
  365. break;
  366. case MixBlend.first:
  367. case MixBlend.replace:
  368. bone.x += (bone.data.x + x - bone.x) * alpha;
  369. break;
  370. case MixBlend.add:
  371. bone.x += x * alpha;
  372. }
  373. };
  374. return TranslateXTimeline;
  375. }(CurveTimeline1));
  376. spine.TranslateXTimeline = TranslateXTimeline;
  377. var TranslateYTimeline = (function (_super) {
  378. __extends(TranslateYTimeline, _super);
  379. function TranslateYTimeline(frameCount, bezierCount, boneIndex) {
  380. var _this = _super.call(this, frameCount, bezierCount, Property.y + "|" + boneIndex) || this;
  381. _this.boneIndex = 0;
  382. _this.boneIndex = boneIndex;
  383. return _this;
  384. }
  385. TranslateYTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  386. var bone = skeleton.bones[this.boneIndex];
  387. if (!bone.active)
  388. return;
  389. var frames = this.frames;
  390. if (time < frames[0]) {
  391. switch (blend) {
  392. case MixBlend.setup:
  393. bone.y = bone.data.y;
  394. return;
  395. case MixBlend.first:
  396. bone.y += (bone.data.y - bone.y) * alpha;
  397. }
  398. return;
  399. }
  400. var y = this.getCurveValue(time);
  401. switch (blend) {
  402. case MixBlend.setup:
  403. bone.y = bone.data.y + y * alpha;
  404. break;
  405. case MixBlend.first:
  406. case MixBlend.replace:
  407. bone.y += (bone.data.y + y - bone.y) * alpha;
  408. break;
  409. case MixBlend.add:
  410. bone.y += y * alpha;
  411. }
  412. };
  413. return TranslateYTimeline;
  414. }(CurveTimeline1));
  415. spine.TranslateYTimeline = TranslateYTimeline;
  416. var ScaleTimeline = (function (_super) {
  417. __extends(ScaleTimeline, _super);
  418. function ScaleTimeline(frameCount, bezierCount, boneIndex) {
  419. var _this = _super.call(this, frameCount, bezierCount, Property.scaleX + "|" + boneIndex, Property.scaleY + "|" + boneIndex) || this;
  420. _this.boneIndex = 0;
  421. _this.boneIndex = boneIndex;
  422. return _this;
  423. }
  424. ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  425. var bone = skeleton.bones[this.boneIndex];
  426. if (!bone.active)
  427. return;
  428. var frames = this.frames;
  429. if (time < frames[0]) {
  430. switch (blend) {
  431. case MixBlend.setup:
  432. bone.scaleX = bone.data.scaleX;
  433. bone.scaleY = bone.data.scaleY;
  434. return;
  435. case MixBlend.first:
  436. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  437. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  438. }
  439. return;
  440. }
  441. var x, y;
  442. var i = Timeline.search(frames, time, 3);
  443. var curveType = this.curves[i / 3];
  444. switch (curveType) {
  445. case 0:
  446. var before = frames[i];
  447. x = frames[i + 1];
  448. y = frames[i + 2];
  449. var t = (time - before) / (frames[i + 3] - before);
  450. x += (frames[i + 3 + 1] - x) * t;
  451. y += (frames[i + 3 + 2] - y) * t;
  452. break;
  453. case 1:
  454. x = frames[i + 1];
  455. y = frames[i + 2];
  456. break;
  457. default:
  458. x = this.getBezierValue(time, i, 1, curveType - 2);
  459. y = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  460. }
  461. x *= bone.data.scaleX;
  462. y *= bone.data.scaleY;
  463. if (alpha == 1) {
  464. if (blend == MixBlend.add) {
  465. bone.scaleX += x - bone.data.scaleX;
  466. bone.scaleY += y - bone.data.scaleY;
  467. }
  468. else {
  469. bone.scaleX = x;
  470. bone.scaleY = y;
  471. }
  472. }
  473. else {
  474. var bx = 0, by = 0;
  475. if (direction == MixDirection.mixOut) {
  476. switch (blend) {
  477. case MixBlend.setup:
  478. bx = bone.data.scaleX;
  479. by = bone.data.scaleY;
  480. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bx) * alpha;
  481. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - by) * alpha;
  482. break;
  483. case MixBlend.first:
  484. case MixBlend.replace:
  485. bx = bone.scaleX;
  486. by = bone.scaleY;
  487. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bx) * alpha;
  488. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - by) * alpha;
  489. break;
  490. case MixBlend.add:
  491. bx = bone.scaleX;
  492. by = bone.scaleY;
  493. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  494. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - bone.data.scaleY) * alpha;
  495. }
  496. }
  497. else {
  498. switch (blend) {
  499. case MixBlend.setup:
  500. bx = Math.abs(bone.data.scaleX) * spine.MathUtils.signum(x);
  501. by = Math.abs(bone.data.scaleY) * spine.MathUtils.signum(y);
  502. bone.scaleX = bx + (x - bx) * alpha;
  503. bone.scaleY = by + (y - by) * alpha;
  504. break;
  505. case MixBlend.first:
  506. case MixBlend.replace:
  507. bx = Math.abs(bone.scaleX) * spine.MathUtils.signum(x);
  508. by = Math.abs(bone.scaleY) * spine.MathUtils.signum(y);
  509. bone.scaleX = bx + (x - bx) * alpha;
  510. bone.scaleY = by + (y - by) * alpha;
  511. break;
  512. case MixBlend.add:
  513. bx = spine.MathUtils.signum(x);
  514. by = spine.MathUtils.signum(y);
  515. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  516. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  517. }
  518. }
  519. }
  520. };
  521. return ScaleTimeline;
  522. }(CurveTimeline2));
  523. spine.ScaleTimeline = ScaleTimeline;
  524. var ScaleXTimeline = (function (_super) {
  525. __extends(ScaleXTimeline, _super);
  526. function ScaleXTimeline(frameCount, bezierCount, boneIndex) {
  527. var _this = _super.call(this, frameCount, bezierCount, Property.scaleX + "|" + boneIndex) || this;
  528. _this.boneIndex = 0;
  529. _this.boneIndex = boneIndex;
  530. return _this;
  531. }
  532. ScaleXTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  533. var bone = skeleton.bones[this.boneIndex];
  534. if (!bone.active)
  535. return;
  536. var frames = this.frames;
  537. if (time < frames[0]) {
  538. switch (blend) {
  539. case MixBlend.setup:
  540. bone.scaleX = bone.data.scaleX;
  541. return;
  542. case MixBlend.first:
  543. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  544. }
  545. return;
  546. }
  547. var x = this.getCurveValue(time) * bone.data.scaleX;
  548. if (alpha == 1) {
  549. if (blend == MixBlend.add)
  550. bone.scaleX += x - bone.data.scaleX;
  551. else
  552. bone.scaleX = x;
  553. }
  554. else {
  555. var bx = 0;
  556. if (direction == MixDirection.mixOut) {
  557. switch (blend) {
  558. case MixBlend.setup:
  559. bx = bone.data.scaleX;
  560. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bx) * alpha;
  561. break;
  562. case MixBlend.first:
  563. case MixBlend.replace:
  564. bx = bone.scaleX;
  565. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bx) * alpha;
  566. break;
  567. case MixBlend.add:
  568. bx = bone.scaleX;
  569. bone.scaleX = bx + (Math.abs(x) * spine.MathUtils.signum(bx) - bone.data.scaleX) * alpha;
  570. }
  571. }
  572. else {
  573. switch (blend) {
  574. case MixBlend.setup:
  575. bx = Math.abs(bone.data.scaleX) * spine.MathUtils.signum(x);
  576. bone.scaleX = bx + (x - bx) * alpha;
  577. break;
  578. case MixBlend.first:
  579. case MixBlend.replace:
  580. bx = Math.abs(bone.scaleX) * spine.MathUtils.signum(x);
  581. bone.scaleX = bx + (x - bx) * alpha;
  582. break;
  583. case MixBlend.add:
  584. bx = spine.MathUtils.signum(x);
  585. bone.scaleX = Math.abs(bone.scaleX) * bx + (x - Math.abs(bone.data.scaleX) * bx) * alpha;
  586. }
  587. }
  588. }
  589. };
  590. return ScaleXTimeline;
  591. }(CurveTimeline1));
  592. spine.ScaleXTimeline = ScaleXTimeline;
  593. var ScaleYTimeline = (function (_super) {
  594. __extends(ScaleYTimeline, _super);
  595. function ScaleYTimeline(frameCount, bezierCount, boneIndex) {
  596. var _this = _super.call(this, frameCount, bezierCount, Property.scaleY + "|" + boneIndex) || this;
  597. _this.boneIndex = 0;
  598. _this.boneIndex = boneIndex;
  599. return _this;
  600. }
  601. ScaleYTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  602. var bone = skeleton.bones[this.boneIndex];
  603. if (!bone.active)
  604. return;
  605. var frames = this.frames;
  606. if (time < frames[0]) {
  607. switch (blend) {
  608. case MixBlend.setup:
  609. bone.scaleY = bone.data.scaleY;
  610. return;
  611. case MixBlend.first:
  612. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  613. }
  614. return;
  615. }
  616. var y = this.getCurveValue(time) * bone.data.scaleY;
  617. if (alpha == 1) {
  618. if (blend == MixBlend.add)
  619. bone.scaleY += y - bone.data.scaleY;
  620. else
  621. bone.scaleY = y;
  622. }
  623. else {
  624. var by = 0;
  625. if (direction == MixDirection.mixOut) {
  626. switch (blend) {
  627. case MixBlend.setup:
  628. by = bone.data.scaleY;
  629. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - by) * alpha;
  630. break;
  631. case MixBlend.first:
  632. case MixBlend.replace:
  633. by = bone.scaleY;
  634. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - by) * alpha;
  635. break;
  636. case MixBlend.add:
  637. by = bone.scaleY;
  638. bone.scaleY = by + (Math.abs(y) * spine.MathUtils.signum(by) - bone.data.scaleY) * alpha;
  639. }
  640. }
  641. else {
  642. switch (blend) {
  643. case MixBlend.setup:
  644. by = Math.abs(bone.data.scaleY) * spine.MathUtils.signum(y);
  645. bone.scaleY = by + (y - by) * alpha;
  646. break;
  647. case MixBlend.first:
  648. case MixBlend.replace:
  649. by = Math.abs(bone.scaleY) * spine.MathUtils.signum(y);
  650. bone.scaleY = by + (y - by) * alpha;
  651. break;
  652. case MixBlend.add:
  653. by = spine.MathUtils.signum(y);
  654. bone.scaleY = Math.abs(bone.scaleY) * by + (y - Math.abs(bone.data.scaleY) * by) * alpha;
  655. }
  656. }
  657. }
  658. };
  659. return ScaleYTimeline;
  660. }(CurveTimeline1));
  661. spine.ScaleYTimeline = ScaleYTimeline;
  662. var ShearTimeline = (function (_super) {
  663. __extends(ShearTimeline, _super);
  664. function ShearTimeline(frameCount, bezierCount, boneIndex) {
  665. var _this = _super.call(this, frameCount, bezierCount, Property.shearX + "|" + boneIndex, Property.shearY + "|" + boneIndex) || this;
  666. _this.boneIndex = 0;
  667. _this.boneIndex = boneIndex;
  668. return _this;
  669. }
  670. ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  671. var bone = skeleton.bones[this.boneIndex];
  672. if (!bone.active)
  673. return;
  674. var frames = this.frames;
  675. if (time < frames[0]) {
  676. switch (blend) {
  677. case MixBlend.setup:
  678. bone.shearX = bone.data.shearX;
  679. bone.shearY = bone.data.shearY;
  680. return;
  681. case MixBlend.first:
  682. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  683. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  684. }
  685. return;
  686. }
  687. var x = 0, y = 0;
  688. var i = Timeline.search(frames, time, 3);
  689. var curveType = this.curves[i / 3];
  690. switch (curveType) {
  691. case 0:
  692. var before = frames[i];
  693. x = frames[i + 1];
  694. y = frames[i + 2];
  695. var t = (time - before) / (frames[i + 3] - before);
  696. x += (frames[i + 3 + 1] - x) * t;
  697. y += (frames[i + 3 + 2] - y) * t;
  698. break;
  699. case 1:
  700. x = frames[i + 1];
  701. y = frames[i + 2];
  702. break;
  703. default:
  704. x = this.getBezierValue(time, i, 1, curveType - 2);
  705. y = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  706. }
  707. switch (blend) {
  708. case MixBlend.setup:
  709. bone.shearX = bone.data.shearX + x * alpha;
  710. bone.shearY = bone.data.shearY + y * alpha;
  711. break;
  712. case MixBlend.first:
  713. case MixBlend.replace:
  714. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  715. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  716. break;
  717. case MixBlend.add:
  718. bone.shearX += x * alpha;
  719. bone.shearY += y * alpha;
  720. }
  721. };
  722. return ShearTimeline;
  723. }(CurveTimeline2));
  724. spine.ShearTimeline = ShearTimeline;
  725. var ShearXTimeline = (function (_super) {
  726. __extends(ShearXTimeline, _super);
  727. function ShearXTimeline(frameCount, bezierCount, boneIndex) {
  728. var _this = _super.call(this, frameCount, bezierCount, Property.shearX + "|" + boneIndex) || this;
  729. _this.boneIndex = 0;
  730. _this.boneIndex = boneIndex;
  731. return _this;
  732. }
  733. ShearXTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  734. var bone = skeleton.bones[this.boneIndex];
  735. if (!bone.active)
  736. return;
  737. var frames = this.frames;
  738. if (time < frames[0]) {
  739. switch (blend) {
  740. case MixBlend.setup:
  741. bone.shearX = bone.data.shearX;
  742. return;
  743. case MixBlend.first:
  744. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  745. }
  746. return;
  747. }
  748. var x = this.getCurveValue(time);
  749. switch (blend) {
  750. case MixBlend.setup:
  751. bone.shearX = bone.data.shearX + x * alpha;
  752. break;
  753. case MixBlend.first:
  754. case MixBlend.replace:
  755. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  756. break;
  757. case MixBlend.add:
  758. bone.shearX += x * alpha;
  759. }
  760. };
  761. return ShearXTimeline;
  762. }(CurveTimeline1));
  763. spine.ShearXTimeline = ShearXTimeline;
  764. var ShearYTimeline = (function (_super) {
  765. __extends(ShearYTimeline, _super);
  766. function ShearYTimeline(frameCount, bezierCount, boneIndex) {
  767. var _this = _super.call(this, frameCount, bezierCount, Property.shearY + "|" + boneIndex) || this;
  768. _this.boneIndex = 0;
  769. _this.boneIndex = boneIndex;
  770. return _this;
  771. }
  772. ShearYTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  773. var bone = skeleton.bones[this.boneIndex];
  774. if (!bone.active)
  775. return;
  776. var frames = this.frames;
  777. if (time < frames[0]) {
  778. switch (blend) {
  779. case MixBlend.setup:
  780. bone.shearY = bone.data.shearY;
  781. return;
  782. case MixBlend.first:
  783. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  784. }
  785. return;
  786. }
  787. var y = this.getCurveValue(time);
  788. switch (blend) {
  789. case MixBlend.setup:
  790. bone.shearY = bone.data.shearY + y * alpha;
  791. break;
  792. case MixBlend.first:
  793. case MixBlend.replace:
  794. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  795. break;
  796. case MixBlend.add:
  797. bone.shearY += y * alpha;
  798. }
  799. };
  800. return ShearYTimeline;
  801. }(CurveTimeline1));
  802. spine.ShearYTimeline = ShearYTimeline;
  803. var RGBATimeline = (function (_super) {
  804. __extends(RGBATimeline, _super);
  805. function RGBATimeline(frameCount, bezierCount, slotIndex) {
  806. var _this = _super.call(this, frameCount, bezierCount, [
  807. Property.rgb + "|" + slotIndex,
  808. Property.alpha + "|" + slotIndex
  809. ]) || this;
  810. _this.slotIndex = 0;
  811. _this.slotIndex = slotIndex;
  812. return _this;
  813. }
  814. RGBATimeline.prototype.getFrameEntries = function () {
  815. return 5;
  816. };
  817. RGBATimeline.prototype.setFrame = function (frame, time, r, g, b, a) {
  818. frame *= 5;
  819. this.frames[frame] = time;
  820. this.frames[frame + 1] = r;
  821. this.frames[frame + 2] = g;
  822. this.frames[frame + 3] = b;
  823. this.frames[frame + 4] = a;
  824. };
  825. RGBATimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  826. var slot = skeleton.slots[this.slotIndex];
  827. if (!slot.bone.active)
  828. return;
  829. var frames = this.frames;
  830. var color = slot.color;
  831. if (time < frames[0]) {
  832. var setup = slot.data.color;
  833. switch (blend) {
  834. case MixBlend.setup:
  835. color.setFromColor(setup);
  836. return;
  837. case MixBlend.first:
  838. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
  839. }
  840. return;
  841. }
  842. var r = 0, g = 0, b = 0, a = 0;
  843. var i = Timeline.search(frames, time, 5);
  844. var curveType = this.curves[i / 5];
  845. switch (curveType) {
  846. case 0:
  847. var before = frames[i];
  848. r = frames[i + 1];
  849. g = frames[i + 2];
  850. b = frames[i + 3];
  851. a = frames[i + 4];
  852. var t = (time - before) / (frames[i + 5] - before);
  853. r += (frames[i + 5 + 1] - r) * t;
  854. g += (frames[i + 5 + 2] - g) * t;
  855. b += (frames[i + 5 + 3] - b) * t;
  856. a += (frames[i + 5 + 4] - a) * t;
  857. break;
  858. case 1:
  859. r = frames[i + 1];
  860. g = frames[i + 2];
  861. b = frames[i + 3];
  862. a = frames[i + 4];
  863. break;
  864. default:
  865. r = this.getBezierValue(time, i, 1, curveType - 2);
  866. g = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  867. b = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
  868. a = this.getBezierValue(time, i, 4, curveType + 18 * 3 - 2);
  869. }
  870. if (alpha == 1)
  871. color.set(r, g, b, a);
  872. else {
  873. if (blend == MixBlend.setup)
  874. color.setFromColor(slot.data.color);
  875. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  876. }
  877. };
  878. return RGBATimeline;
  879. }(CurveTimeline));
  880. spine.RGBATimeline = RGBATimeline;
  881. var RGBTimeline = (function (_super) {
  882. __extends(RGBTimeline, _super);
  883. function RGBTimeline(frameCount, bezierCount, slotIndex) {
  884. var _this = _super.call(this, frameCount, bezierCount, [
  885. Property.rgb + "|" + slotIndex
  886. ]) || this;
  887. _this.slotIndex = 0;
  888. _this.slotIndex = slotIndex;
  889. return _this;
  890. }
  891. RGBTimeline.prototype.getFrameEntries = function () {
  892. return 4;
  893. };
  894. RGBTimeline.prototype.setFrame = function (frame, time, r, g, b) {
  895. frame <<= 2;
  896. this.frames[frame] = time;
  897. this.frames[frame + 1] = r;
  898. this.frames[frame + 2] = g;
  899. this.frames[frame + 3] = b;
  900. };
  901. RGBTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  902. var slot = skeleton.slots[this.slotIndex];
  903. if (!slot.bone.active)
  904. return;
  905. var frames = this.frames;
  906. var color = slot.color;
  907. if (time < frames[0]) {
  908. var setup = slot.data.color;
  909. switch (blend) {
  910. case MixBlend.setup:
  911. color.r = setup.r;
  912. color.g = setup.g;
  913. color.b = setup.b;
  914. return;
  915. case MixBlend.first:
  916. color.r += (setup.r - color.r) * alpha;
  917. color.g += (setup.g - color.g) * alpha;
  918. color.b += (setup.b - color.b) * alpha;
  919. }
  920. return;
  921. }
  922. var r = 0, g = 0, b = 0;
  923. var i = Timeline.search(frames, time, 4);
  924. var curveType = this.curves[i >> 2];
  925. switch (curveType) {
  926. case 0:
  927. var before = frames[i];
  928. r = frames[i + 1];
  929. g = frames[i + 2];
  930. b = frames[i + 3];
  931. var t = (time - before) / (frames[i + 4] - before);
  932. r += (frames[i + 4 + 1] - r) * t;
  933. g += (frames[i + 4 + 2] - g) * t;
  934. b += (frames[i + 4 + 3] - b) * t;
  935. break;
  936. case 1:
  937. r = frames[i + 1];
  938. g = frames[i + 2];
  939. b = frames[i + 3];
  940. break;
  941. default:
  942. r = this.getBezierValue(time, i, 1, curveType - 2);
  943. g = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  944. b = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
  945. }
  946. if (alpha == 1) {
  947. color.r = r;
  948. color.g = g;
  949. color.b = b;
  950. }
  951. else {
  952. if (blend == MixBlend.setup) {
  953. var setup = slot.data.color;
  954. color.r = setup.r;
  955. color.g = setup.g;
  956. color.b = setup.b;
  957. }
  958. color.r += (r - color.r) * alpha;
  959. color.g += (g - color.g) * alpha;
  960. color.b += (b - color.b) * alpha;
  961. }
  962. };
  963. return RGBTimeline;
  964. }(CurveTimeline));
  965. spine.RGBTimeline = RGBTimeline;
  966. var AlphaTimeline = (function (_super) {
  967. __extends(AlphaTimeline, _super);
  968. function AlphaTimeline(frameCount, bezierCount, slotIndex) {
  969. var _this = _super.call(this, frameCount, bezierCount, Property.alpha + "|" + slotIndex) || this;
  970. _this.slotIndex = 0;
  971. _this.slotIndex = slotIndex;
  972. return _this;
  973. }
  974. AlphaTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  975. var slot = skeleton.slots[this.slotIndex];
  976. if (!slot.bone.active)
  977. return;
  978. var color = slot.color;
  979. if (time < this.frames[0]) {
  980. var setup = slot.data.color;
  981. switch (blend) {
  982. case MixBlend.setup:
  983. color.a = setup.a;
  984. return;
  985. case MixBlend.first:
  986. color.a += (setup.a - color.a) * alpha;
  987. }
  988. return;
  989. }
  990. var a = this.getCurveValue(time);
  991. if (alpha == 1)
  992. color.a = a;
  993. else {
  994. if (blend == MixBlend.setup)
  995. color.a = slot.data.color.a;
  996. color.a += (a - color.a) * alpha;
  997. }
  998. };
  999. return AlphaTimeline;
  1000. }(CurveTimeline1));
  1001. spine.AlphaTimeline = AlphaTimeline;
  1002. var RGBA2Timeline = (function (_super) {
  1003. __extends(RGBA2Timeline, _super);
  1004. function RGBA2Timeline(frameCount, bezierCount, slotIndex) {
  1005. var _this = _super.call(this, frameCount, bezierCount, [
  1006. Property.rgb + "|" + slotIndex,
  1007. Property.alpha + "|" + slotIndex,
  1008. Property.rgb2 + "|" + slotIndex
  1009. ]) || this;
  1010. _this.slotIndex = 0;
  1011. _this.slotIndex = slotIndex;
  1012. return _this;
  1013. }
  1014. RGBA2Timeline.prototype.getFrameEntries = function () {
  1015. return 8;
  1016. };
  1017. RGBA2Timeline.prototype.setFrame = function (frame, time, r, g, b, a, r2, g2, b2) {
  1018. frame <<= 3;
  1019. this.frames[frame] = time;
  1020. this.frames[frame + 1] = r;
  1021. this.frames[frame + 2] = g;
  1022. this.frames[frame + 3] = b;
  1023. this.frames[frame + 4] = a;
  1024. this.frames[frame + 5] = r2;
  1025. this.frames[frame + 6] = g2;
  1026. this.frames[frame + 7] = b2;
  1027. };
  1028. RGBA2Timeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  1029. var slot = skeleton.slots[this.slotIndex];
  1030. if (!slot.bone.active)
  1031. return;
  1032. var frames = this.frames;
  1033. var light = slot.color, dark = slot.darkColor;
  1034. if (time < frames[0]) {
  1035. var setupLight = slot.data.color, setupDark = slot.data.darkColor;
  1036. switch (blend) {
  1037. case MixBlend.setup:
  1038. light.setFromColor(setupLight);
  1039. dark.r = setupDark.r;
  1040. dark.g = setupDark.g;
  1041. dark.b = setupDark.b;
  1042. return;
  1043. case MixBlend.first:
  1044. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
  1045. dark.r += (setupDark.r - dark.r) * alpha;
  1046. dark.g += (setupDark.g - dark.g) * alpha;
  1047. dark.b += (setupDark.b - dark.b) * alpha;
  1048. }
  1049. return;
  1050. }
  1051. var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  1052. var i = Timeline.search(frames, time, 8);
  1053. var curveType = this.curves[i >> 3];
  1054. switch (curveType) {
  1055. case 0:
  1056. var before = frames[i];
  1057. r = frames[i + 1];
  1058. g = frames[i + 2];
  1059. b = frames[i + 3];
  1060. a = frames[i + 4];
  1061. r2 = frames[i + 5];
  1062. g2 = frames[i + 6];
  1063. b2 = frames[i + 7];
  1064. var t = (time - before) / (frames[i + 8] - before);
  1065. r += (frames[i + 8 + 1] - r) * t;
  1066. g += (frames[i + 8 + 2] - g) * t;
  1067. b += (frames[i + 8 + 3] - b) * t;
  1068. a += (frames[i + 8 + 4] - a) * t;
  1069. r2 += (frames[i + 8 + 5] - r2) * t;
  1070. g2 += (frames[i + 8 + 6] - g2) * t;
  1071. b2 += (frames[i + 8 + 7] - b2) * t;
  1072. break;
  1073. case 1:
  1074. r = frames[i + 1];
  1075. g = frames[i + 2];
  1076. b = frames[i + 3];
  1077. a = frames[i + 4];
  1078. r2 = frames[i + 5];
  1079. g2 = frames[i + 6];
  1080. b2 = frames[i + 7];
  1081. break;
  1082. default:
  1083. r = this.getBezierValue(time, i, 1, curveType - 2);
  1084. g = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  1085. b = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
  1086. a = this.getBezierValue(time, i, 4, curveType + 18 * 3 - 2);
  1087. r2 = this.getBezierValue(time, i, 5, curveType + 18 * 4 - 2);
  1088. g2 = this.getBezierValue(time, i, 6, curveType + 18 * 5 - 2);
  1089. b2 = this.getBezierValue(time, i, 7, curveType + 18 * 6 - 2);
  1090. }
  1091. if (alpha == 1) {
  1092. light.set(r, g, b, a);
  1093. dark.r = r2;
  1094. dark.g = g2;
  1095. dark.b = b2;
  1096. }
  1097. else {
  1098. if (blend == MixBlend.setup) {
  1099. light.setFromColor(slot.data.color);
  1100. var setupDark = slot.data.darkColor;
  1101. dark.r = setupDark.r;
  1102. dark.g = setupDark.g;
  1103. dark.b = setupDark.b;
  1104. }
  1105. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  1106. dark.r += (r2 - dark.r) * alpha;
  1107. dark.g += (g2 - dark.g) * alpha;
  1108. dark.b += (b2 - dark.b) * alpha;
  1109. }
  1110. };
  1111. return RGBA2Timeline;
  1112. }(CurveTimeline));
  1113. spine.RGBA2Timeline = RGBA2Timeline;
  1114. var RGB2Timeline = (function (_super) {
  1115. __extends(RGB2Timeline, _super);
  1116. function RGB2Timeline(frameCount, bezierCount, slotIndex) {
  1117. var _this = _super.call(this, frameCount, bezierCount, [
  1118. Property.rgb + "|" + slotIndex,
  1119. Property.rgb2 + "|" + slotIndex
  1120. ]) || this;
  1121. _this.slotIndex = 0;
  1122. _this.slotIndex = slotIndex;
  1123. return _this;
  1124. }
  1125. RGB2Timeline.prototype.getFrameEntries = function () {
  1126. return 7;
  1127. };
  1128. RGB2Timeline.prototype.setFrame = function (frame, time, r, g, b, r2, g2, b2) {
  1129. frame *= 7;
  1130. this.frames[frame] = time;
  1131. this.frames[frame + 1] = r;
  1132. this.frames[frame + 2] = g;
  1133. this.frames[frame + 3] = b;
  1134. this.frames[frame + 4] = r2;
  1135. this.frames[frame + 5] = g2;
  1136. this.frames[frame + 6] = b2;
  1137. };
  1138. RGB2Timeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  1139. var slot = skeleton.slots[this.slotIndex];
  1140. if (!slot.bone.active)
  1141. return;
  1142. var frames = this.frames;
  1143. var light = slot.color, dark = slot.darkColor;
  1144. if (time < frames[0]) {
  1145. var setupLight = slot.data.color, setupDark = slot.data.darkColor;
  1146. switch (blend) {
  1147. case MixBlend.setup:
  1148. light.r = setupLight.r;
  1149. light.g = setupLight.g;
  1150. light.b = setupLight.b;
  1151. dark.r = setupDark.r;
  1152. dark.g = setupDark.g;
  1153. dark.b = setupDark.b;
  1154. return;
  1155. case MixBlend.first:
  1156. light.r += (setupLight.r - light.r) * alpha;
  1157. light.g += (setupLight.g - light.g) * alpha;
  1158. light.b += (setupLight.b - light.b) * alpha;
  1159. dark.r += (setupDark.r - dark.r) * alpha;
  1160. dark.g += (setupDark.g - dark.g) * alpha;
  1161. dark.b += (setupDark.b - dark.b) * alpha;
  1162. }
  1163. return;
  1164. }
  1165. var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  1166. var i = Timeline.search(frames, time, 7);
  1167. var curveType = this.curves[i / 7];
  1168. switch (curveType) {
  1169. case 0:
  1170. var before = frames[i];
  1171. r = frames[i + 1];
  1172. g = frames[i + 2];
  1173. b = frames[i + 3];
  1174. r2 = frames[i + 4];
  1175. g2 = frames[i + 5];
  1176. b2 = frames[i + 6];
  1177. var t = (time - before) / (frames[i + 7] - before);
  1178. r += (frames[i + 7 + 1] - r) * t;
  1179. g += (frames[i + 7 + 2] - g) * t;
  1180. b += (frames[i + 7 + 3] - b) * t;
  1181. r2 += (frames[i + 7 + 4] - r2) * t;
  1182. g2 += (frames[i + 7 + 5] - g2) * t;
  1183. b2 += (frames[i + 7 + 6] - b2) * t;
  1184. break;
  1185. case 1:
  1186. r = frames[i + 1];
  1187. g = frames[i + 2];
  1188. b = frames[i + 3];
  1189. r2 = frames[i + 4];
  1190. g2 = frames[i + 5];
  1191. b2 = frames[i + 6];
  1192. break;
  1193. default:
  1194. r = this.getBezierValue(time, i, 1, curveType - 2);
  1195. g = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  1196. b = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
  1197. r2 = this.getBezierValue(time, i, 4, curveType + 18 * 3 - 2);
  1198. g2 = this.getBezierValue(time, i, 5, curveType + 18 * 4 - 2);
  1199. b2 = this.getBezierValue(time, i, 6, curveType + 18 * 5 - 2);
  1200. }
  1201. if (alpha == 1) {
  1202. light.r = r;
  1203. light.g = g;
  1204. light.b = b;
  1205. dark.r = r2;
  1206. dark.g = g2;
  1207. dark.b = b2;
  1208. }
  1209. else {
  1210. if (blend == MixBlend.setup) {
  1211. var setupLight = slot.data.color, setupDark = slot.data.darkColor;
  1212. light.r = setupLight.r;
  1213. light.g = setupLight.g;
  1214. light.b = setupLight.b;
  1215. dark.r = setupDark.r;
  1216. dark.g = setupDark.g;
  1217. dark.b = setupDark.b;
  1218. }
  1219. light.r += (r - light.r) * alpha;
  1220. light.g += (g - light.g) * alpha;
  1221. light.b += (b - light.b) * alpha;
  1222. dark.r += (r2 - dark.r) * alpha;
  1223. dark.g += (g2 - dark.g) * alpha;
  1224. dark.b += (b2 - dark.b) * alpha;
  1225. }
  1226. };
  1227. return RGB2Timeline;
  1228. }(CurveTimeline));
  1229. spine.RGB2Timeline = RGB2Timeline;
  1230. var AttachmentTimeline = (function (_super) {
  1231. __extends(AttachmentTimeline, _super);
  1232. function AttachmentTimeline(frameCount, slotIndex) {
  1233. var _this = _super.call(this, frameCount, [
  1234. Property.attachment + "|" + slotIndex
  1235. ]) || this;
  1236. _this.slotIndex = 0;
  1237. _this.slotIndex = slotIndex;
  1238. _this.attachmentNames = new Array(frameCount);
  1239. return _this;
  1240. }
  1241. AttachmentTimeline.prototype.getFrameCount = function () {
  1242. return this.frames.length;
  1243. };
  1244. AttachmentTimeline.prototype.setFrame = function (frame, time, attachmentName) {
  1245. this.frames[frame] = time;
  1246. this.attachmentNames[frame] = attachmentName;
  1247. };
  1248. AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, blend, direction) {
  1249. var slot = skeleton.slots[this.slotIndex];
  1250. if (!slot.bone.active)
  1251. return;
  1252. if (direction == MixDirection.mixOut) {
  1253. if (blend == MixBlend.setup)
  1254. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  1255. return;
  1256. }
  1257. if (time < this.frames[0]) {
  1258. if (blend == MixBlend.setup || blend == MixBlend.first)
  1259. this.setAttachment(skeleton, slot, slot.data.attachmentName);
  1260. return;
  1261. }
  1262. this.setAttachment(skeleton, slot, this.attachmentNames[Timeline.search1(this.frames, time)]);
  1263. };
  1264. AttachmentTimeline.prototype.setAttachment = function (skeleton, slot, attachmentName) {
  1265. slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  1266. };
  1267. return AttachmentTimeline;
  1268. }(Timeline));
  1269. spine.AttachmentTimeline = AttachmentTimeline;
  1270. var DeformTimeline = (function (_super) {
  1271. __extends(DeformTimeline, _super);
  1272. function DeformTimeline(frameCount, bezierCount, slotIndex, attachment) {
  1273. var _this = _super.call(this, frameCount, bezierCount, [
  1274. Property.deform + "|" + slotIndex + "|" + attachment.id
  1275. ]) || this;
  1276. _this.slotIndex = 0;
  1277. _this.slotIndex = slotIndex;
  1278. _this.attachment = attachment;
  1279. _this.vertices = new Array(frameCount);
  1280. return _this;
  1281. }
  1282. DeformTimeline.prototype.getFrameCount = function () {
  1283. return this.frames.length;
  1284. };
  1285. DeformTimeline.prototype.setFrame = function (frame, time, vertices) {
  1286. this.frames[frame] = time;
  1287. this.vertices[frame] = vertices;
  1288. };
  1289. DeformTimeline.prototype.setBezier = function (bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2) {
  1290. var curves = this.curves;
  1291. var i = this.getFrameCount() + bezier * 18;
  1292. if (value == 0)
  1293. curves[frame] = 2 + i;
  1294. var tmpx = (time1 - cx1 * 2 + cx2) * 0.03, tmpy = cy2 * 0.03 - cy1 * 0.06;
  1295. var dddx = ((cx1 - cx2) * 3 - time1 + time2) * 0.006, dddy = (cy1 - cy2 + 0.33333333) * 0.018;
  1296. var ddx = tmpx * 2 + dddx, ddy = tmpy * 2 + dddy;
  1297. var dx = (cx1 - time1) * 0.3 + tmpx + dddx * 0.16666667, dy = cy1 * 0.3 + tmpy + dddy * 0.16666667;
  1298. var x = time1 + dx, y = dy;
  1299. for (var n = i + 18; i < n; i += 2) {
  1300. curves[i] = x;
  1301. curves[i + 1] = y;
  1302. dx += ddx;
  1303. dy += ddy;
  1304. ddx += dddx;
  1305. ddy += dddy;
  1306. x += dx;
  1307. y += dy;
  1308. }
  1309. };
  1310. DeformTimeline.prototype.getCurvePercent = function (time, frame) {
  1311. var curves = this.curves;
  1312. var i = curves[frame];
  1313. switch (i) {
  1314. case 0:
  1315. var x_3 = this.frames[frame];
  1316. return (time - x_3) / (this.frames[frame + this.getFrameEntries()] - x_3);
  1317. case 1:
  1318. return 0;
  1319. }
  1320. i -= 2;
  1321. if (curves[i] > time) {
  1322. var x_4 = this.frames[frame];
  1323. return curves[i + 1] * (time - x_4) / (curves[i] - x_4);
  1324. }
  1325. var n = i + 18;
  1326. for (i += 2; i < n; i += 2) {
  1327. if (curves[i] >= time) {
  1328. var x_5 = curves[i - 2], y_3 = curves[i - 1];
  1329. return y_3 + (time - x_5) / (curves[i] - x_5) * (curves[i + 1] - y_3);
  1330. }
  1331. }
  1332. var x = curves[n - 2], y = curves[n - 1];
  1333. return y + (1 - y) * (time - x) / (this.frames[frame + this.getFrameEntries()] - x);
  1334. };
  1335. DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1336. var slot = skeleton.slots[this.slotIndex];
  1337. if (!slot.bone.active)
  1338. return;
  1339. var slotAttachment = slot.getAttachment();
  1340. if (!(slotAttachment instanceof spine.VertexAttachment) || slotAttachment.deformAttachment != this.attachment)
  1341. return;
  1342. var deform = slot.deform;
  1343. if (deform.length == 0)
  1344. blend = MixBlend.setup;
  1345. var vertices = this.vertices;
  1346. var vertexCount = vertices[0].length;
  1347. var frames = this.frames;
  1348. if (time < frames[0]) {
  1349. var vertexAttachment = slotAttachment;
  1350. switch (blend) {
  1351. case MixBlend.setup:
  1352. deform.length = 0;
  1353. return;
  1354. case MixBlend.first:
  1355. if (alpha == 1) {
  1356. deform.length = 0;
  1357. return;
  1358. }
  1359. deform.length = vertexCount;
  1360. if (!vertexAttachment.bones) {
  1361. var setupVertices = vertexAttachment.vertices;
  1362. for (var i = 0; i < vertexCount; i++)
  1363. deform[i] += (setupVertices[i] - deform[i]) * alpha;
  1364. }
  1365. else {
  1366. alpha = 1 - alpha;
  1367. for (var i = 0; i < vertexCount; i++)
  1368. deform[i] *= alpha;
  1369. }
  1370. }
  1371. return;
  1372. }
  1373. deform.length = vertexCount;
  1374. if (time >= frames[frames.length - 1]) {
  1375. var lastVertices = vertices[frames.length - 1];
  1376. if (alpha == 1) {
  1377. if (blend == MixBlend.add) {
  1378. var vertexAttachment = slotAttachment;
  1379. if (!vertexAttachment.bones) {
  1380. var setupVertices = vertexAttachment.vertices;
  1381. for (var i_1 = 0; i_1 < vertexCount; i_1++)
  1382. deform[i_1] += lastVertices[i_1] - setupVertices[i_1];
  1383. }
  1384. else {
  1385. for (var i_2 = 0; i_2 < vertexCount; i_2++)
  1386. deform[i_2] += lastVertices[i_2];
  1387. }
  1388. }
  1389. else
  1390. spine.Utils.arrayCopy(lastVertices, 0, deform, 0, vertexCount);
  1391. }
  1392. else {
  1393. switch (blend) {
  1394. case MixBlend.setup: {
  1395. var vertexAttachment_1 = slotAttachment;
  1396. if (!vertexAttachment_1.bones) {
  1397. var setupVertices = vertexAttachment_1.vertices;
  1398. for (var i_3 = 0; i_3 < vertexCount; i_3++) {
  1399. var setup = setupVertices[i_3];
  1400. deform[i_3] = setup + (lastVertices[i_3] - setup) * alpha;
  1401. }
  1402. }
  1403. else {
  1404. for (var i_4 = 0; i_4 < vertexCount; i_4++)
  1405. deform[i_4] = lastVertices[i_4] * alpha;
  1406. }
  1407. break;
  1408. }
  1409. case MixBlend.first:
  1410. case MixBlend.replace:
  1411. for (var i_5 = 0; i_5 < vertexCount; i_5++)
  1412. deform[i_5] += (lastVertices[i_5] - deform[i_5]) * alpha;
  1413. break;
  1414. case MixBlend.add:
  1415. var vertexAttachment = slotAttachment;
  1416. if (!vertexAttachment.bones) {
  1417. var setupVertices = vertexAttachment.vertices;
  1418. for (var i_6 = 0; i_6 < vertexCount; i_6++)
  1419. deform[i_6] += (lastVertices[i_6] - setupVertices[i_6]) * alpha;
  1420. }
  1421. else {
  1422. for (var i_7 = 0; i_7 < vertexCount; i_7++)
  1423. deform[i_7] += lastVertices[i_7] * alpha;
  1424. }
  1425. }
  1426. }
  1427. return;
  1428. }
  1429. var frame = Timeline.search1(frames, time);
  1430. var percent = this.getCurvePercent(time, frame);
  1431. var prevVertices = vertices[frame];
  1432. var nextVertices = vertices[frame + 1];
  1433. if (alpha == 1) {
  1434. if (blend == MixBlend.add) {
  1435. var vertexAttachment = slotAttachment;
  1436. if (!vertexAttachment.bones) {
  1437. var setupVertices = vertexAttachment.vertices;
  1438. for (var i_8 = 0; i_8 < vertexCount; i_8++) {
  1439. var prev = prevVertices[i_8];
  1440. deform[i_8] += prev + (nextVertices[i_8] - prev) * percent - setupVertices[i_8];
  1441. }
  1442. }
  1443. else {
  1444. for (var i_9 = 0; i_9 < vertexCount; i_9++) {
  1445. var prev = prevVertices[i_9];
  1446. deform[i_9] += prev + (nextVertices[i_9] - prev) * percent;
  1447. }
  1448. }
  1449. }
  1450. else {
  1451. for (var i_10 = 0; i_10 < vertexCount; i_10++) {
  1452. var prev = prevVertices[i_10];
  1453. deform[i_10] = prev + (nextVertices[i_10] - prev) * percent;
  1454. }
  1455. }
  1456. }
  1457. else {
  1458. switch (blend) {
  1459. case MixBlend.setup: {
  1460. var vertexAttachment_2 = slotAttachment;
  1461. if (!vertexAttachment_2.bones) {
  1462. var setupVertices = vertexAttachment_2.vertices;
  1463. for (var i_11 = 0; i_11 < vertexCount; i_11++) {
  1464. var prev = prevVertices[i_11], setup = setupVertices[i_11];
  1465. deform[i_11] = setup + (prev + (nextVertices[i_11] - prev) * percent - setup) * alpha;
  1466. }
  1467. }
  1468. else {
  1469. for (var i_12 = 0; i_12 < vertexCount; i_12++) {
  1470. var prev = prevVertices[i_12];
  1471. deform[i_12] = (prev + (nextVertices[i_12] - prev) * percent) * alpha;
  1472. }
  1473. }
  1474. break;
  1475. }
  1476. case MixBlend.first:
  1477. case MixBlend.replace:
  1478. for (var i_13 = 0; i_13 < vertexCount; i_13++) {
  1479. var prev = prevVertices[i_13];
  1480. deform[i_13] += (prev + (nextVertices[i_13] - prev) * percent - deform[i_13]) * alpha;
  1481. }
  1482. break;
  1483. case MixBlend.add:
  1484. var vertexAttachment = slotAttachment;
  1485. if (!vertexAttachment.bones) {
  1486. var setupVertices = vertexAttachment.vertices;
  1487. for (var i_14 = 0; i_14 < vertexCount; i_14++) {
  1488. var prev = prevVertices[i_14];
  1489. deform[i_14] += (prev + (nextVertices[i_14] - prev) * percent - setupVertices[i_14]) * alpha;
  1490. }
  1491. }
  1492. else {
  1493. for (var i_15 = 0; i_15 < vertexCount; i_15++) {
  1494. var prev = prevVertices[i_15];
  1495. deform[i_15] += (prev + (nextVertices[i_15] - prev) * percent) * alpha;
  1496. }
  1497. }
  1498. }
  1499. }
  1500. };
  1501. return DeformTimeline;
  1502. }(CurveTimeline));
  1503. spine.DeformTimeline = DeformTimeline;
  1504. var EventTimeline = (function (_super) {
  1505. __extends(EventTimeline, _super);
  1506. function EventTimeline(frameCount) {
  1507. var _this = _super.call(this, frameCount, EventTimeline.propertyIds) || this;
  1508. _this.events = new Array(frameCount);
  1509. return _this;
  1510. }
  1511. EventTimeline.prototype.getFrameCount = function () {
  1512. return this.frames.length;
  1513. };
  1514. EventTimeline.prototype.setFrame = function (frame, event) {
  1515. this.frames[frame] = event.time;
  1516. this.events[frame] = event;
  1517. };
  1518. EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1519. if (!firedEvents)
  1520. return;
  1521. var frames = this.frames;
  1522. var frameCount = this.frames.length;
  1523. if (lastTime > time) {
  1524. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, blend, direction);
  1525. lastTime = -1;
  1526. }
  1527. else if (lastTime >= frames[frameCount - 1])
  1528. return;
  1529. if (time < frames[0])
  1530. return;
  1531. var i = 0;
  1532. if (lastTime < frames[0])
  1533. i = 0;
  1534. else {
  1535. i = Timeline.search1(frames, lastTime) + 1;
  1536. var frameTime = frames[i];
  1537. while (i > 0) {
  1538. if (frames[i - 1] != frameTime)
  1539. break;
  1540. i--;
  1541. }
  1542. }
  1543. for (; i < frameCount && time >= frames[i]; i++)
  1544. firedEvents.push(this.events[i]);
  1545. };
  1546. EventTimeline.propertyIds = ["" + Property.event];
  1547. return EventTimeline;
  1548. }(Timeline));
  1549. spine.EventTimeline = EventTimeline;
  1550. var DrawOrderTimeline = (function (_super) {
  1551. __extends(DrawOrderTimeline, _super);
  1552. function DrawOrderTimeline(frameCount) {
  1553. var _this = _super.call(this, frameCount, DrawOrderTimeline.propertyIds) || this;
  1554. _this.drawOrders = new Array(frameCount);
  1555. return _this;
  1556. }
  1557. DrawOrderTimeline.prototype.getFrameCount = function () {
  1558. return this.frames.length;
  1559. };
  1560. DrawOrderTimeline.prototype.setFrame = function (frame, time, drawOrder) {
  1561. this.frames[frame] = time;
  1562. this.drawOrders[frame] = drawOrder;
  1563. };
  1564. DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1565. if (direction == MixDirection.mixOut) {
  1566. if (blend == MixBlend.setup)
  1567. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  1568. return;
  1569. }
  1570. if (time < this.frames[0]) {
  1571. if (blend == MixBlend.setup || blend == MixBlend.first)
  1572. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  1573. return;
  1574. }
  1575. var drawOrderToSetupIndex = this.drawOrders[Timeline.search1(this.frames, time)];
  1576. if (!drawOrderToSetupIndex)
  1577. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  1578. else {
  1579. var drawOrder = skeleton.drawOrder;
  1580. var slots = skeleton.slots;
  1581. for (var i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  1582. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  1583. }
  1584. };
  1585. DrawOrderTimeline.propertyIds = ["" + Property.drawOrder];
  1586. return DrawOrderTimeline;
  1587. }(Timeline));
  1588. spine.DrawOrderTimeline = DrawOrderTimeline;
  1589. var IkConstraintTimeline = (function (_super) {
  1590. __extends(IkConstraintTimeline, _super);
  1591. function IkConstraintTimeline(frameCount, bezierCount, ikConstraintIndex) {
  1592. var _this = _super.call(this, frameCount, bezierCount, [
  1593. Property.ikConstraint + "|" + ikConstraintIndex
  1594. ]) || this;
  1595. _this.ikConstraintIndex = ikConstraintIndex;
  1596. return _this;
  1597. }
  1598. IkConstraintTimeline.prototype.getFrameEntries = function () {
  1599. return 6;
  1600. };
  1601. IkConstraintTimeline.prototype.setFrame = function (frame, time, mix, softness, bendDirection, compress, stretch) {
  1602. frame *= 6;
  1603. this.frames[frame] = time;
  1604. this.frames[frame + 1] = mix;
  1605. this.frames[frame + 2] = softness;
  1606. this.frames[frame + 3] = bendDirection;
  1607. this.frames[frame + 4] = compress ? 1 : 0;
  1608. this.frames[frame + 5] = stretch ? 1 : 0;
  1609. };
  1610. IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1611. var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  1612. if (!constraint.active)
  1613. return;
  1614. var frames = this.frames;
  1615. if (time < frames[0]) {
  1616. switch (blend) {
  1617. case MixBlend.setup:
  1618. constraint.mix = constraint.data.mix;
  1619. constraint.softness = constraint.data.softness;
  1620. constraint.bendDirection = constraint.data.bendDirection;
  1621. constraint.compress = constraint.data.compress;
  1622. constraint.stretch = constraint.data.stretch;
  1623. return;
  1624. case MixBlend.first:
  1625. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  1626. constraint.softness += (constraint.data.softness - constraint.softness) * alpha;
  1627. constraint.bendDirection = constraint.data.bendDirection;
  1628. constraint.compress = constraint.data.compress;
  1629. constraint.stretch = constraint.data.stretch;
  1630. }
  1631. return;
  1632. }
  1633. var mix = 0, softness = 0;
  1634. var i = Timeline.search(frames, time, 6);
  1635. var curveType = this.curves[i / 6];
  1636. switch (curveType) {
  1637. case 0:
  1638. var before = frames[i];
  1639. mix = frames[i + 1];
  1640. softness = frames[i + 2];
  1641. var t = (time - before) / (frames[i + 6] - before);
  1642. mix += (frames[i + 6 + 1] - mix) * t;
  1643. softness += (frames[i + 6 + 2] - softness) * t;
  1644. break;
  1645. case 1:
  1646. mix = frames[i + 1];
  1647. softness = frames[i + 2];
  1648. break;
  1649. default:
  1650. mix = this.getBezierValue(time, i, 1, curveType - 2);
  1651. softness = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  1652. }
  1653. if (blend == MixBlend.setup) {
  1654. constraint.mix = constraint.data.mix + (mix - constraint.data.mix) * alpha;
  1655. constraint.softness = constraint.data.softness + (softness - constraint.data.softness) * alpha;
  1656. if (direction == MixDirection.mixOut) {
  1657. constraint.bendDirection = constraint.data.bendDirection;
  1658. constraint.compress = constraint.data.compress;
  1659. constraint.stretch = constraint.data.stretch;
  1660. }
  1661. else {
  1662. constraint.bendDirection = frames[i + 3];
  1663. constraint.compress = frames[i + 4] != 0;
  1664. constraint.stretch = frames[i + 5] != 0;
  1665. }
  1666. }
  1667. else {
  1668. constraint.mix += (mix - constraint.mix) * alpha;
  1669. constraint.softness += (softness - constraint.softness) * alpha;
  1670. if (direction == MixDirection.mixIn) {
  1671. constraint.bendDirection = frames[i + 3];
  1672. constraint.compress = frames[i + 4] != 0;
  1673. constraint.stretch = frames[i + 5] != 0;
  1674. }
  1675. }
  1676. };
  1677. return IkConstraintTimeline;
  1678. }(CurveTimeline));
  1679. spine.IkConstraintTimeline = IkConstraintTimeline;
  1680. var TransformConstraintTimeline = (function (_super) {
  1681. __extends(TransformConstraintTimeline, _super);
  1682. function TransformConstraintTimeline(frameCount, bezierCount, transformConstraintIndex) {
  1683. var _this = _super.call(this, frameCount, bezierCount, [
  1684. Property.transformConstraint + "|" + transformConstraintIndex
  1685. ]) || this;
  1686. _this.transformConstraintIndex = transformConstraintIndex;
  1687. return _this;
  1688. }
  1689. TransformConstraintTimeline.prototype.getFrameEntries = function () {
  1690. return 7;
  1691. };
  1692. TransformConstraintTimeline.prototype.setFrame = function (frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY) {
  1693. var frames = this.frames;
  1694. frame *= 7;
  1695. frames[frame] = time;
  1696. frames[frame + 1] = mixRotate;
  1697. frames[frame + 2] = mixX;
  1698. frames[frame + 3] = mixY;
  1699. frames[frame + 4] = mixScaleX;
  1700. frames[frame + 5] = mixScaleY;
  1701. frames[frame + 6] = mixShearY;
  1702. };
  1703. TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1704. var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  1705. if (!constraint.active)
  1706. return;
  1707. var frames = this.frames;
  1708. if (time < frames[0]) {
  1709. var data = constraint.data;
  1710. switch (blend) {
  1711. case MixBlend.setup:
  1712. constraint.mixRotate = data.mixRotate;
  1713. constraint.mixX = data.mixX;
  1714. constraint.mixY = data.mixY;
  1715. constraint.mixScaleX = data.mixScaleX;
  1716. constraint.mixScaleY = data.mixScaleY;
  1717. constraint.mixShearY = data.mixShearY;
  1718. return;
  1719. case MixBlend.first:
  1720. constraint.mixRotate += (data.mixRotate - constraint.mixRotate) * alpha;
  1721. constraint.mixX += (data.mixX - constraint.mixX) * alpha;
  1722. constraint.mixY += (data.mixY - constraint.mixY) * alpha;
  1723. constraint.mixScaleX += (data.mixScaleX - constraint.mixScaleX) * alpha;
  1724. constraint.mixScaleY += (data.mixScaleY - constraint.mixScaleY) * alpha;
  1725. constraint.mixShearY += (data.mixShearY - constraint.mixShearY) * alpha;
  1726. }
  1727. return;
  1728. }
  1729. var rotate, x, y, scaleX, scaleY, shearY;
  1730. var i = Timeline.search(frames, time, 7);
  1731. var curveType = this.curves[i / 7];
  1732. switch (curveType) {
  1733. case 0:
  1734. var before = frames[i];
  1735. rotate = frames[i + 1];
  1736. x = frames[i + 2];
  1737. y = frames[i + 3];
  1738. scaleX = frames[i + 4];
  1739. scaleY = frames[i + 5];
  1740. shearY = frames[i + 6];
  1741. var t = (time - before) / (frames[i + 7] - before);
  1742. rotate += (frames[i + 7 + 1] - rotate) * t;
  1743. x += (frames[i + 7 + 2] - x) * t;
  1744. y += (frames[i + 7 + 3] - y) * t;
  1745. scaleX += (frames[i + 7 + 4] - scaleX) * t;
  1746. scaleY += (frames[i + 7 + 5] - scaleY) * t;
  1747. shearY += (frames[i + 7 + 6] - shearY) * t;
  1748. break;
  1749. case 1:
  1750. rotate = frames[i + 1];
  1751. x = frames[i + 2];
  1752. y = frames[i + 3];
  1753. scaleX = frames[i + 4];
  1754. scaleY = frames[i + 5];
  1755. shearY = frames[i + 6];
  1756. break;
  1757. default:
  1758. rotate = this.getBezierValue(time, i, 1, curveType - 2);
  1759. x = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  1760. y = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
  1761. scaleX = this.getBezierValue(time, i, 4, curveType + 18 * 3 - 2);
  1762. scaleY = this.getBezierValue(time, i, 5, curveType + 18 * 4 - 2);
  1763. shearY = this.getBezierValue(time, i, 6, curveType + 18 * 5 - 2);
  1764. }
  1765. if (blend == MixBlend.setup) {
  1766. var data = constraint.data;
  1767. constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha;
  1768. constraint.mixX = data.mixX + (x - data.mixX) * alpha;
  1769. constraint.mixY = data.mixY + (y - data.mixY) * alpha;
  1770. constraint.mixScaleX = data.mixScaleX + (scaleX - data.mixScaleX) * alpha;
  1771. constraint.mixScaleY = data.mixScaleY + (scaleY - data.mixScaleY) * alpha;
  1772. constraint.mixShearY = data.mixShearY + (shearY - data.mixShearY) * alpha;
  1773. }
  1774. else {
  1775. constraint.mixRotate += (rotate - constraint.mixRotate) * alpha;
  1776. constraint.mixX += (x - constraint.mixX) * alpha;
  1777. constraint.mixY += (y - constraint.mixY) * alpha;
  1778. constraint.mixScaleX += (scaleX - constraint.mixScaleX) * alpha;
  1779. constraint.mixScaleY += (scaleY - constraint.mixScaleY) * alpha;
  1780. constraint.mixShearY += (shearY - constraint.mixShearY) * alpha;
  1781. }
  1782. };
  1783. return TransformConstraintTimeline;
  1784. }(CurveTimeline));
  1785. spine.TransformConstraintTimeline = TransformConstraintTimeline;
  1786. var PathConstraintPositionTimeline = (function (_super) {
  1787. __extends(PathConstraintPositionTimeline, _super);
  1788. function PathConstraintPositionTimeline(frameCount, bezierCount, pathConstraintIndex) {
  1789. var _this = _super.call(this, frameCount, bezierCount, Property.pathConstraintPosition + "|" + pathConstraintIndex) || this;
  1790. _this.pathConstraintIndex = pathConstraintIndex;
  1791. return _this;
  1792. }
  1793. PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1794. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1795. if (!constraint.active)
  1796. return;
  1797. var frames = this.frames;
  1798. if (time < frames[0]) {
  1799. switch (blend) {
  1800. case MixBlend.setup:
  1801. constraint.position = constraint.data.position;
  1802. return;
  1803. case MixBlend.first:
  1804. constraint.position += (constraint.data.position - constraint.position) * alpha;
  1805. }
  1806. return;
  1807. }
  1808. var position = this.getCurveValue(time);
  1809. if (blend == MixBlend.setup)
  1810. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  1811. else
  1812. constraint.position += (position - constraint.position) * alpha;
  1813. };
  1814. return PathConstraintPositionTimeline;
  1815. }(CurveTimeline1));
  1816. spine.PathConstraintPositionTimeline = PathConstraintPositionTimeline;
  1817. var PathConstraintSpacingTimeline = (function (_super) {
  1818. __extends(PathConstraintSpacingTimeline, _super);
  1819. function PathConstraintSpacingTimeline(frameCount, bezierCount, pathConstraintIndex) {
  1820. var _this = _super.call(this, frameCount, bezierCount, Property.pathConstraintSpacing + "|" + pathConstraintIndex) || this;
  1821. _this.pathConstraintIndex = 0;
  1822. _this.pathConstraintIndex = pathConstraintIndex;
  1823. return _this;
  1824. }
  1825. PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1826. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1827. if (!constraint.active)
  1828. return;
  1829. var frames = this.frames;
  1830. if (time < frames[0]) {
  1831. switch (blend) {
  1832. case MixBlend.setup:
  1833. constraint.spacing = constraint.data.spacing;
  1834. return;
  1835. case MixBlend.first:
  1836. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  1837. }
  1838. return;
  1839. }
  1840. var spacing = this.getCurveValue(time);
  1841. if (blend == MixBlend.setup)
  1842. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  1843. else
  1844. constraint.spacing += (spacing - constraint.spacing) * alpha;
  1845. };
  1846. return PathConstraintSpacingTimeline;
  1847. }(CurveTimeline1));
  1848. spine.PathConstraintSpacingTimeline = PathConstraintSpacingTimeline;
  1849. var PathConstraintMixTimeline = (function (_super) {
  1850. __extends(PathConstraintMixTimeline, _super);
  1851. function PathConstraintMixTimeline(frameCount, bezierCount, pathConstraintIndex) {
  1852. var _this = _super.call(this, frameCount, bezierCount, [
  1853. Property.pathConstraintMix + "|" + pathConstraintIndex
  1854. ]) || this;
  1855. _this.pathConstraintIndex = 0;
  1856. _this.pathConstraintIndex = pathConstraintIndex;
  1857. return _this;
  1858. }
  1859. PathConstraintMixTimeline.prototype.getFrameEntries = function () {
  1860. return 4;
  1861. };
  1862. PathConstraintMixTimeline.prototype.setFrame = function (frame, time, mixRotate, mixX, mixY) {
  1863. var frames = this.frames;
  1864. frame <<= 2;
  1865. frames[frame] = time;
  1866. frames[frame + 1] = mixRotate;
  1867. frames[frame + 2] = mixX;
  1868. frames[frame + 3] = mixY;
  1869. };
  1870. PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, blend, direction) {
  1871. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1872. if (!constraint.active)
  1873. return;
  1874. var frames = this.frames;
  1875. if (time < frames[0]) {
  1876. switch (blend) {
  1877. case MixBlend.setup:
  1878. constraint.mixRotate = constraint.data.mixRotate;
  1879. constraint.mixX = constraint.data.mixX;
  1880. constraint.mixY = constraint.data.mixY;
  1881. return;
  1882. case MixBlend.first:
  1883. constraint.mixRotate += (constraint.data.mixRotate - constraint.mixRotate) * alpha;
  1884. constraint.mixX += (constraint.data.mixX - constraint.mixX) * alpha;
  1885. constraint.mixY += (constraint.data.mixY - constraint.mixY) * alpha;
  1886. }
  1887. return;
  1888. }
  1889. var rotate, x, y;
  1890. var i = Timeline.search(frames, time, 4);
  1891. var curveType = this.curves[i >> 2];
  1892. switch (curveType) {
  1893. case 0:
  1894. var before = frames[i];
  1895. rotate = frames[i + 1];
  1896. x = frames[i + 2];
  1897. y = frames[i + 3];
  1898. var t = (time - before) / (frames[i + 4] - before);
  1899. rotate += (frames[i + 4 + 1] - rotate) * t;
  1900. x += (frames[i + 4 + 2] - x) * t;
  1901. y += (frames[i + 4 + 3] - y) * t;
  1902. break;
  1903. case 1:
  1904. rotate = frames[i + 1];
  1905. x = frames[i + 2];
  1906. y = frames[i + 3];
  1907. break;
  1908. default:
  1909. rotate = this.getBezierValue(time, i, 1, curveType - 2);
  1910. x = this.getBezierValue(time, i, 2, curveType + 18 - 2);
  1911. y = this.getBezierValue(time, i, 3, curveType + 18 * 2 - 2);
  1912. }
  1913. if (blend == MixBlend.setup) {
  1914. var data = constraint.data;
  1915. constraint.mixRotate = data.mixRotate + (rotate - data.mixRotate) * alpha;
  1916. constraint.mixX = data.mixX + (x - data.mixX) * alpha;
  1917. constraint.mixY = data.mixY + (y - data.mixY) * alpha;
  1918. }
  1919. else {
  1920. constraint.mixRotate += (rotate - constraint.mixRotate) * alpha;
  1921. constraint.mixX += (x - constraint.mixX) * alpha;
  1922. constraint.mixY += (y - constraint.mixY) * alpha;
  1923. }
  1924. };
  1925. return PathConstraintMixTimeline;
  1926. }(CurveTimeline));
  1927. spine.PathConstraintMixTimeline = PathConstraintMixTimeline;
  1928. })(spine || (spine = {}));
  1929. var spine;
  1930. (function (spine) {
  1931. var AnimationState = (function () {
  1932. function AnimationState(data) {
  1933. this.tracks = new Array();
  1934. this.timeScale = 1;
  1935. this.unkeyedState = 0;
  1936. this.events = new Array();
  1937. this.listeners = new Array();
  1938. this.queue = new EventQueue(this);
  1939. this.propertyIDs = new spine.StringSet();
  1940. this.animationsChanged = false;
  1941. this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
  1942. this.data = data;
  1943. }
  1944. AnimationState.emptyAnimation = function () {
  1945. if (!_emptyAnimation)
  1946. _emptyAnimation = new spine.Animation("<empty>", [], 0);
  1947. return _emptyAnimation;
  1948. };
  1949. AnimationState.prototype.update = function (delta) {
  1950. delta *= this.timeScale;
  1951. var tracks = this.tracks;
  1952. for (var i = 0, n = tracks.length; i < n; i++) {
  1953. var current = tracks[i];
  1954. if (!current)
  1955. continue;
  1956. current.animationLast = current.nextAnimationLast;
  1957. current.trackLast = current.nextTrackLast;
  1958. var currentDelta = delta * current.timeScale;
  1959. if (current.delay > 0) {
  1960. current.delay -= currentDelta;
  1961. if (current.delay > 0)
  1962. continue;
  1963. currentDelta = -current.delay;
  1964. current.delay = 0;
  1965. }
  1966. var next = current.next;
  1967. if (next) {
  1968. var nextTime = current.trackLast - next.delay;
  1969. if (nextTime >= 0) {
  1970. next.delay = 0;
  1971. next.trackTime += current.timeScale == 0 ? 0 : (nextTime / current.timeScale + delta) * next.timeScale;
  1972. current.trackTime += currentDelta;
  1973. this.setCurrent(i, next, true);
  1974. while (next.mixingFrom) {
  1975. next.mixTime += delta;
  1976. next = next.mixingFrom;
  1977. }
  1978. continue;
  1979. }
  1980. }
  1981. else if (current.trackLast >= current.trackEnd && !current.mixingFrom) {
  1982. tracks[i] = null;
  1983. this.queue.end(current);
  1984. this.clearNext(current);
  1985. continue;
  1986. }
  1987. if (current.mixingFrom && this.updateMixingFrom(current, delta)) {
  1988. var from = current.mixingFrom;
  1989. current.mixingFrom = null;
  1990. if (from)
  1991. from.mixingTo = null;
  1992. while (from) {
  1993. this.queue.end(from);
  1994. from = from.mixingFrom;
  1995. }
  1996. }
  1997. current.trackTime += currentDelta;
  1998. }
  1999. this.queue.drain();
  2000. };
  2001. AnimationState.prototype.updateMixingFrom = function (to, delta) {
  2002. var from = to.mixingFrom;
  2003. if (!from)
  2004. return true;
  2005. var finished = this.updateMixingFrom(from, delta);
  2006. from.animationLast = from.nextAnimationLast;
  2007. from.trackLast = from.nextTrackLast;
  2008. if (to.mixTime > 0 && to.mixTime >= to.mixDuration) {
  2009. if (from.totalAlpha == 0 || to.mixDuration == 0) {
  2010. to.mixingFrom = from.mixingFrom;
  2011. if (from.mixingFrom)
  2012. from.mixingFrom.mixingTo = to;
  2013. to.interruptAlpha = from.interruptAlpha;
  2014. this.queue.end(from);
  2015. }
  2016. return finished;
  2017. }
  2018. from.trackTime += delta * from.timeScale;
  2019. to.mixTime += delta;
  2020. return false;
  2021. };
  2022. AnimationState.prototype.apply = function (skeleton) {
  2023. if (!skeleton)
  2024. throw new Error("skeleton cannot be null.");
  2025. if (this.animationsChanged)
  2026. this._animationsChanged();
  2027. var events = this.events;
  2028. var tracks = this.tracks;
  2029. var applied = false;
  2030. for (var i_16 = 0, n_1 = tracks.length; i_16 < n_1; i_16++) {
  2031. var current = tracks[i_16];
  2032. if (!current || current.delay > 0)
  2033. continue;
  2034. applied = true;
  2035. var blend = i_16 == 0 ? spine.MixBlend.first : current.mixBlend;
  2036. var mix = current.alpha;
  2037. if (current.mixingFrom)
  2038. mix *= this.applyMixingFrom(current, skeleton, blend);
  2039. else if (current.trackTime >= current.trackEnd && !current.next)
  2040. mix = 0;
  2041. var animationLast = current.animationLast, animationTime = current.getAnimationTime(), applyTime = animationTime;
  2042. var applyEvents = events;
  2043. if (current.reverse) {
  2044. applyTime = current.animation.duration - applyTime;
  2045. applyEvents = null;
  2046. }
  2047. var timelines = current.animation.timelines;
  2048. var timelineCount = timelines.length;
  2049. if ((i_16 == 0 && mix == 1) || blend == spine.MixBlend.add) {
  2050. for (var ii = 0; ii < timelineCount; ii++) {
  2051. spine.Utils.webkit602BugfixHelper(mix, blend);
  2052. var timeline = timelines[ii];
  2053. if (timeline instanceof spine.AttachmentTimeline)
  2054. this.applyAttachmentTimeline(timeline, skeleton, applyTime, blend, true);
  2055. else
  2056. timeline.apply(skeleton, animationLast, applyTime, applyEvents, mix, blend, spine.MixDirection.mixIn);
  2057. }
  2058. }
  2059. else {
  2060. var timelineMode = current.timelineMode;
  2061. var firstFrame = current.timelinesRotation.length != timelineCount << 1;
  2062. if (firstFrame)
  2063. current.timelinesRotation.length = timelineCount << 1;
  2064. for (var ii = 0; ii < timelineCount; ii++) {
  2065. var timeline_1 = timelines[ii];
  2066. var timelineBlend = timelineMode[ii] == SUBSEQUENT ? blend : spine.MixBlend.setup;
  2067. if (timeline_1 instanceof spine.RotateTimeline) {
  2068. this.applyRotateTimeline(timeline_1, skeleton, applyTime, mix, timelineBlend, current.timelinesRotation, ii << 1, firstFrame);
  2069. }
  2070. else if (timeline_1 instanceof spine.AttachmentTimeline) {
  2071. this.applyAttachmentTimeline(timeline_1, skeleton, applyTime, blend, true);
  2072. }
  2073. else {
  2074. spine.Utils.webkit602BugfixHelper(mix, blend);
  2075. timeline_1.apply(skeleton, animationLast, applyTime, applyEvents, mix, timelineBlend, spine.MixDirection.mixIn);
  2076. }
  2077. }
  2078. }
  2079. this.queueEvents(current, animationTime);
  2080. events.length = 0;
  2081. current.nextAnimationLast = animationTime;
  2082. current.nextTrackLast = current.trackTime;
  2083. }
  2084. var setupState = this.unkeyedState + SETUP;
  2085. var slots = skeleton.slots;
  2086. for (var i = 0, n = skeleton.slots.length; i < n; i++) {
  2087. var slot = slots[i];
  2088. if (slot.attachmentState == setupState) {
  2089. var attachmentName = slot.data.attachmentName;
  2090. slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  2091. }
  2092. }
  2093. this.unkeyedState += 2;
  2094. this.queue.drain();
  2095. return applied;
  2096. };
  2097. AnimationState.prototype.applyMixingFrom = function (to, skeleton, blend) {
  2098. var from = to.mixingFrom;
  2099. if (from.mixingFrom)
  2100. this.applyMixingFrom(from, skeleton, blend);
  2101. var mix = 0;
  2102. if (to.mixDuration == 0) {
  2103. mix = 1;
  2104. if (blend == spine.MixBlend.first)
  2105. blend = spine.MixBlend.setup;
  2106. }
  2107. else {
  2108. mix = to.mixTime / to.mixDuration;
  2109. if (mix > 1)
  2110. mix = 1;
  2111. if (blend != spine.MixBlend.first)
  2112. blend = from.mixBlend;
  2113. }
  2114. var attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  2115. var timelines = from.animation.timelines;
  2116. var timelineCount = timelines.length;
  2117. var alphaHold = from.alpha * to.interruptAlpha, alphaMix = alphaHold * (1 - mix);
  2118. var animationLast = from.animationLast, animationTime = from.getAnimationTime(), applyTime = animationTime;
  2119. var events = null;
  2120. if (from.reverse)
  2121. applyTime = from.animation.duration - applyTime;
  2122. else if (mix < from.eventThreshold)
  2123. events = this.events;
  2124. if (blend == spine.MixBlend.add) {
  2125. for (var i = 0; i < timelineCount; i++)
  2126. timelines[i].apply(skeleton, animationLast, applyTime, events, alphaMix, blend, spine.MixDirection.mixOut);
  2127. }
  2128. else {
  2129. var timelineMode = from.timelineMode;
  2130. var timelineHoldMix = from.timelineHoldMix;
  2131. var firstFrame = from.timelinesRotation.length != timelineCount << 1;
  2132. if (firstFrame)
  2133. from.timelinesRotation.length = timelineCount << 1;
  2134. from.totalAlpha = 0;
  2135. for (var i = 0; i < timelineCount; i++) {
  2136. var timeline = timelines[i];
  2137. var direction = spine.MixDirection.mixOut;
  2138. var timelineBlend = void 0;
  2139. var alpha = 0;
  2140. switch (timelineMode[i]) {
  2141. case SUBSEQUENT:
  2142. if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
  2143. continue;
  2144. timelineBlend = blend;
  2145. alpha = alphaMix;
  2146. break;
  2147. case FIRST:
  2148. timelineBlend = spine.MixBlend.setup;
  2149. alpha = alphaMix;
  2150. break;
  2151. case HOLD_SUBSEQUENT:
  2152. timelineBlend = blend;
  2153. alpha = alphaHold;
  2154. break;
  2155. case HOLD_FIRST:
  2156. timelineBlend = spine.MixBlend.setup;
  2157. alpha = alphaHold;
  2158. break;
  2159. default:
  2160. timelineBlend = spine.MixBlend.setup;
  2161. var holdMix = timelineHoldMix[i];
  2162. alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration);
  2163. break;
  2164. }
  2165. from.totalAlpha += alpha;
  2166. if (timeline instanceof spine.RotateTimeline)
  2167. this.applyRotateTimeline(timeline, skeleton, applyTime, alpha, timelineBlend, from.timelinesRotation, i << 1, firstFrame);
  2168. else if (timeline instanceof spine.AttachmentTimeline)
  2169. this.applyAttachmentTimeline(timeline, skeleton, applyTime, timelineBlend, attachments);
  2170. else {
  2171. spine.Utils.webkit602BugfixHelper(alpha, blend);
  2172. if (drawOrder && timeline instanceof spine.DrawOrderTimeline && timelineBlend == spine.MixBlend.setup)
  2173. direction = spine.MixDirection.mixIn;
  2174. timeline.apply(skeleton, animationLast, applyTime, events, alpha, timelineBlend, direction);
  2175. }
  2176. }
  2177. }
  2178. if (to.mixDuration > 0)
  2179. this.queueEvents(from, animationTime);
  2180. this.events.length = 0;
  2181. from.nextAnimationLast = animationTime;
  2182. from.nextTrackLast = from.trackTime;
  2183. return mix;
  2184. };
  2185. AnimationState.prototype.applyAttachmentTimeline = function (timeline, skeleton, time, blend, attachments) {
  2186. var slot = skeleton.slots[timeline.slotIndex];
  2187. if (!slot.bone.active)
  2188. return;
  2189. if (time < timeline.frames[0]) {
  2190. if (blend == spine.MixBlend.setup || blend == spine.MixBlend.first)
  2191. this.setAttachment(skeleton, slot, slot.data.attachmentName, attachments);
  2192. }
  2193. else
  2194. this.setAttachment(skeleton, slot, timeline.attachmentNames[spine.Timeline.search1(timeline.frames, time)], attachments);
  2195. if (slot.attachmentState <= this.unkeyedState)
  2196. slot.attachmentState = this.unkeyedState + SETUP;
  2197. };
  2198. AnimationState.prototype.setAttachment = function (skeleton, slot, attachmentName, attachments) {
  2199. slot.setAttachment(!attachmentName ? null : skeleton.getAttachment(slot.data.index, attachmentName));
  2200. if (attachments)
  2201. slot.attachmentState = this.unkeyedState + CURRENT;
  2202. };
  2203. AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, blend, timelinesRotation, i, firstFrame) {
  2204. if (firstFrame)
  2205. timelinesRotation[i] = 0;
  2206. if (alpha == 1) {
  2207. timeline.apply(skeleton, 0, time, null, 1, blend, spine.MixDirection.mixIn);
  2208. return;
  2209. }
  2210. var bone = skeleton.bones[timeline.boneIndex];
  2211. if (!bone.active)
  2212. return;
  2213. var frames = timeline.frames;
  2214. var r1 = 0, r2 = 0;
  2215. if (time < frames[0]) {
  2216. switch (blend) {
  2217. case spine.MixBlend.setup:
  2218. bone.rotation = bone.data.rotation;
  2219. default:
  2220. return;
  2221. case spine.MixBlend.first:
  2222. r1 = bone.rotation;
  2223. r2 = bone.data.rotation;
  2224. }
  2225. }
  2226. else {
  2227. r1 = blend == spine.MixBlend.setup ? bone.data.rotation : bone.rotation;
  2228. r2 = bone.data.rotation + timeline.getCurveValue(time);
  2229. }
  2230. var total = 0, diff = r2 - r1;
  2231. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  2232. if (diff == 0) {
  2233. total = timelinesRotation[i];
  2234. }
  2235. else {
  2236. var lastTotal = 0, lastDiff = 0;
  2237. if (firstFrame) {
  2238. lastTotal = 0;
  2239. lastDiff = diff;
  2240. }
  2241. else {
  2242. lastTotal = timelinesRotation[i];
  2243. lastDiff = timelinesRotation[i + 1];
  2244. }
  2245. var current = diff > 0, dir = lastTotal >= 0;
  2246. if (spine.MathUtils.signum(lastDiff) != spine.MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  2247. if (Math.abs(lastTotal) > 180)
  2248. lastTotal += 360 * spine.MathUtils.signum(lastTotal);
  2249. dir = current;
  2250. }
  2251. total = diff + lastTotal - lastTotal % 360;
  2252. if (dir != current)
  2253. total += 360 * spine.MathUtils.signum(lastTotal);
  2254. timelinesRotation[i] = total;
  2255. }
  2256. timelinesRotation[i + 1] = diff;
  2257. bone.rotation = r1 + total * alpha;
  2258. };
  2259. AnimationState.prototype.queueEvents = function (entry, animationTime) {
  2260. var animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  2261. var duration = animationEnd - animationStart;
  2262. var trackLastWrapped = entry.trackLast % duration;
  2263. var events = this.events;
  2264. var i = 0, n = events.length;
  2265. for (; i < n; i++) {
  2266. var event_1 = events[i];
  2267. if (event_1.time < trackLastWrapped)
  2268. break;
  2269. if (event_1.time > animationEnd)
  2270. continue;
  2271. this.queue.event(entry, event_1);
  2272. }
  2273. var complete = false;
  2274. if (entry.loop)
  2275. complete = duration == 0 || trackLastWrapped > entry.trackTime % duration;
  2276. else
  2277. complete = animationTime >= animationEnd && entry.animationLast < animationEnd;
  2278. if (complete)
  2279. this.queue.complete(entry);
  2280. for (; i < n; i++) {
  2281. var event_2 = events[i];
  2282. if (event_2.time < animationStart)
  2283. continue;
  2284. this.queue.event(entry, event_2);
  2285. }
  2286. };
  2287. AnimationState.prototype.clearTracks = function () {
  2288. var oldDrainDisabled = this.queue.drainDisabled;
  2289. this.queue.drainDisabled = true;
  2290. for (var i = 0, n = this.tracks.length; i < n; i++)
  2291. this.clearTrack(i);
  2292. this.tracks.length = 0;
  2293. this.queue.drainDisabled = oldDrainDisabled;
  2294. this.queue.drain();
  2295. };
  2296. AnimationState.prototype.clearTrack = function (trackIndex) {
  2297. if (trackIndex >= this.tracks.length)
  2298. return;
  2299. var current = this.tracks[trackIndex];
  2300. if (!current)
  2301. return;
  2302. this.queue.end(current);
  2303. this.clearNext(current);
  2304. var entry = current;
  2305. while (true) {
  2306. var from = entry.mixingFrom;
  2307. if (!from)
  2308. break;
  2309. this.queue.end(from);
  2310. entry.mixingFrom = null;
  2311. entry.mixingTo = null;
  2312. entry = from;
  2313. }
  2314. this.tracks[current.trackIndex] = null;
  2315. this.queue.drain();
  2316. };
  2317. AnimationState.prototype.setCurrent = function (index, current, interrupt) {
  2318. var from = this.expandToIndex(index);
  2319. this.tracks[index] = current;
  2320. current.previous = null;
  2321. if (from) {
  2322. if (interrupt)
  2323. this.queue.interrupt(from);
  2324. current.mixingFrom = from;
  2325. from.mixingTo = current;
  2326. current.mixTime = 0;
  2327. if (from.mixingFrom && from.mixDuration > 0)
  2328. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  2329. from.timelinesRotation.length = 0;
  2330. }
  2331. this.queue.start(current);
  2332. };
  2333. AnimationState.prototype.setAnimation = function (trackIndex, animationName, loop) {
  2334. if (loop === void 0) { loop = false; }
  2335. var animation = this.data.skeletonData.findAnimation(animationName);
  2336. if (!animation)
  2337. throw new Error("Animation not found: " + animationName);
  2338. return this.setAnimationWith(trackIndex, animation, loop);
  2339. };
  2340. AnimationState.prototype.setAnimationWith = function (trackIndex, animation, loop) {
  2341. if (loop === void 0) { loop = false; }
  2342. if (!animation)
  2343. throw new Error("animation cannot be null.");
  2344. var interrupt = true;
  2345. var current = this.expandToIndex(trackIndex);
  2346. if (current) {
  2347. if (current.nextTrackLast == -1) {
  2348. this.tracks[trackIndex] = current.mixingFrom;
  2349. this.queue.interrupt(current);
  2350. this.queue.end(current);
  2351. this.clearNext(current);
  2352. current = current.mixingFrom;
  2353. interrupt = false;
  2354. }
  2355. else
  2356. this.clearNext(current);
  2357. }
  2358. var entry = this.trackEntry(trackIndex, animation, loop, current);
  2359. this.setCurrent(trackIndex, entry, interrupt);
  2360. this.queue.drain();
  2361. return entry;
  2362. };
  2363. AnimationState.prototype.addAnimation = function (trackIndex, animationName, loop, delay) {
  2364. if (loop === void 0) { loop = false; }
  2365. if (delay === void 0) { delay = 0; }
  2366. var animation = this.data.skeletonData.findAnimation(animationName);
  2367. if (!animation)
  2368. throw new Error("Animation not found: " + animationName);
  2369. return this.addAnimationWith(trackIndex, animation, loop, delay);
  2370. };
  2371. AnimationState.prototype.addAnimationWith = function (trackIndex, animation, loop, delay) {
  2372. if (loop === void 0) { loop = false; }
  2373. if (delay === void 0) { delay = 0; }
  2374. if (!animation)
  2375. throw new Error("animation cannot be null.");
  2376. var last = this.expandToIndex(trackIndex);
  2377. if (last) {
  2378. while (last.next)
  2379. last = last.next;
  2380. }
  2381. var entry = this.trackEntry(trackIndex, animation, loop, last);
  2382. if (!last) {
  2383. this.setCurrent(trackIndex, entry, true);
  2384. this.queue.drain();
  2385. }
  2386. else {
  2387. last.next = entry;
  2388. entry.previous = last;
  2389. if (delay <= 0)
  2390. delay += last.getTrackComplete() - entry.mixDuration;
  2391. }
  2392. entry.delay = delay;
  2393. return entry;
  2394. };
  2395. AnimationState.prototype.setEmptyAnimation = function (trackIndex, mixDuration) {
  2396. if (mixDuration === void 0) { mixDuration = 0; }
  2397. var entry = this.setAnimationWith(trackIndex, AnimationState.emptyAnimation(), false);
  2398. entry.mixDuration = mixDuration;
  2399. entry.trackEnd = mixDuration;
  2400. return entry;
  2401. };
  2402. AnimationState.prototype.addEmptyAnimation = function (trackIndex, mixDuration, delay) {
  2403. if (mixDuration === void 0) { mixDuration = 0; }
  2404. if (delay === void 0) { delay = 0; }
  2405. var entry = this.addAnimationWith(trackIndex, AnimationState.emptyAnimation(), false, delay <= 0 ? 1 : delay);
  2406. entry.mixDuration = mixDuration;
  2407. entry.trackEnd = mixDuration;
  2408. if (delay <= 0 && entry.previous)
  2409. entry.delay = entry.previous.getTrackComplete() - entry.mixDuration + delay;
  2410. return entry;
  2411. };
  2412. AnimationState.prototype.setEmptyAnimations = function (mixDuration) {
  2413. if (mixDuration === void 0) { mixDuration = 0; }
  2414. var oldDrainDisabled = this.queue.drainDisabled;
  2415. this.queue.drainDisabled = true;
  2416. for (var i = 0, n = this.tracks.length; i < n; i++) {
  2417. var current = this.tracks[i];
  2418. if (current)
  2419. this.setEmptyAnimation(current.trackIndex, mixDuration);
  2420. }
  2421. this.queue.drainDisabled = oldDrainDisabled;
  2422. this.queue.drain();
  2423. };
  2424. AnimationState.prototype.expandToIndex = function (index) {
  2425. if (index < this.tracks.length)
  2426. return this.tracks[index];
  2427. spine.Utils.ensureArrayCapacity(this.tracks, index + 1, null);
  2428. this.tracks.length = index + 1;
  2429. return null;
  2430. };
  2431. AnimationState.prototype.trackEntry = function (trackIndex, animation, loop, last) {
  2432. var entry = this.trackEntryPool.obtain();
  2433. entry.trackIndex = trackIndex;
  2434. entry.animation = animation;
  2435. entry.loop = loop;
  2436. entry.holdPrevious = false;
  2437. entry.eventThreshold = 0;
  2438. entry.attachmentThreshold = 0;
  2439. entry.drawOrderThreshold = 0;
  2440. entry.animationStart = 0;
  2441. entry.animationEnd = animation.duration;
  2442. entry.animationLast = -1;
  2443. entry.nextAnimationLast = -1;
  2444. entry.delay = 0;
  2445. entry.trackTime = 0;
  2446. entry.trackLast = -1;
  2447. entry.nextTrackLast = -1;
  2448. entry.trackEnd = Number.MAX_VALUE;
  2449. entry.timeScale = 1;
  2450. entry.alpha = 1;
  2451. entry.interruptAlpha = 1;
  2452. entry.mixTime = 0;
  2453. entry.mixDuration = !last ? 0 : this.data.getMix(last.animation, animation);
  2454. entry.mixBlend = spine.MixBlend.replace;
  2455. return entry;
  2456. };
  2457. AnimationState.prototype.clearNext = function (entry) {
  2458. var next = entry.next;
  2459. while (next) {
  2460. this.queue.dispose(next);
  2461. next = next.next;
  2462. }
  2463. entry.next = null;
  2464. };
  2465. AnimationState.prototype._animationsChanged = function () {
  2466. this.animationsChanged = false;
  2467. this.propertyIDs.clear();
  2468. var tracks = this.tracks;
  2469. for (var i = 0, n = tracks.length; i < n; i++) {
  2470. var entry = tracks[i];
  2471. if (!entry)
  2472. continue;
  2473. while (entry.mixingFrom)
  2474. entry = entry.mixingFrom;
  2475. do {
  2476. if (!entry.mixingTo || entry.mixBlend != spine.MixBlend.add)
  2477. this.computeHold(entry);
  2478. entry = entry.mixingTo;
  2479. } while (entry);
  2480. }
  2481. };
  2482. AnimationState.prototype.computeHold = function (entry) {
  2483. var to = entry.mixingTo;
  2484. var timelines = entry.animation.timelines;
  2485. var timelinesCount = entry.animation.timelines.length;
  2486. var timelineMode = entry.timelineMode;
  2487. timelineMode.length = timelinesCount;
  2488. var timelineHoldMix = entry.timelineHoldMix;
  2489. timelineHoldMix.length = 0;
  2490. var propertyIDs = this.propertyIDs;
  2491. if (to && to.holdPrevious) {
  2492. for (var i = 0; i < timelinesCount; i++)
  2493. timelineMode[i] = propertyIDs.addAll(timelines[i].getPropertyIds()) ? HOLD_FIRST : HOLD_SUBSEQUENT;
  2494. return;
  2495. }
  2496. outer: for (var i = 0; i < timelinesCount; i++) {
  2497. var timeline = timelines[i];
  2498. var ids = timeline.getPropertyIds();
  2499. if (!propertyIDs.addAll(ids))
  2500. timelineMode[i] = SUBSEQUENT;
  2501. else if (!to || timeline instanceof spine.AttachmentTimeline || timeline instanceof spine.DrawOrderTimeline
  2502. || timeline instanceof spine.EventTimeline || !to.animation.hasTimeline(ids)) {
  2503. timelineMode[i] = FIRST;
  2504. }
  2505. else {
  2506. for (var next = to.mixingTo; next; next = next.mixingTo) {
  2507. if (next.animation.hasTimeline(ids))
  2508. continue;
  2509. if (entry.mixDuration > 0) {
  2510. timelineMode[i] = HOLD_MIX;
  2511. timelineHoldMix[i] = next;
  2512. continue outer;
  2513. }
  2514. break;
  2515. }
  2516. timelineMode[i] = HOLD_FIRST;
  2517. }
  2518. }
  2519. };
  2520. AnimationState.prototype.getCurrent = function (trackIndex) {
  2521. if (trackIndex >= this.tracks.length)
  2522. return null;
  2523. return this.tracks[trackIndex];
  2524. };
  2525. AnimationState.prototype.addListener = function (listener) {
  2526. if (!listener)
  2527. throw new Error("listener cannot be null.");
  2528. this.listeners.push(listener);
  2529. };
  2530. AnimationState.prototype.removeListener = function (listener) {
  2531. var index = this.listeners.indexOf(listener);
  2532. if (index >= 0)
  2533. this.listeners.splice(index, 1);
  2534. };
  2535. AnimationState.prototype.clearListeners = function () {
  2536. this.listeners.length = 0;
  2537. };
  2538. AnimationState.prototype.clearListenerNotifications = function () {
  2539. this.queue.clear();
  2540. };
  2541. return AnimationState;
  2542. }());
  2543. spine.AnimationState = AnimationState;
  2544. var TrackEntry = (function () {
  2545. function TrackEntry() {
  2546. this.mixBlend = spine.MixBlend.replace;
  2547. this.timelineMode = new Array();
  2548. this.timelineHoldMix = new Array();
  2549. this.timelinesRotation = new Array();
  2550. }
  2551. TrackEntry.prototype.reset = function () {
  2552. this.next = null;
  2553. this.previous = null;
  2554. this.mixingFrom = null;
  2555. this.mixingTo = null;
  2556. this.animation = null;
  2557. this.listener = null;
  2558. this.timelineMode.length = 0;
  2559. this.timelineHoldMix.length = 0;
  2560. this.timelinesRotation.length = 0;
  2561. };
  2562. TrackEntry.prototype.getAnimationTime = function () {
  2563. if (this.loop) {
  2564. var duration = this.animationEnd - this.animationStart;
  2565. if (duration == 0)
  2566. return this.animationStart;
  2567. return (this.trackTime % duration) + this.animationStart;
  2568. }
  2569. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  2570. };
  2571. TrackEntry.prototype.setAnimationLast = function (animationLast) {
  2572. this.animationLast = animationLast;
  2573. this.nextAnimationLast = animationLast;
  2574. };
  2575. TrackEntry.prototype.isComplete = function () {
  2576. return this.trackTime >= this.animationEnd - this.animationStart;
  2577. };
  2578. TrackEntry.prototype.resetRotationDirections = function () {
  2579. this.timelinesRotation.length = 0;
  2580. };
  2581. TrackEntry.prototype.getTrackComplete = function () {
  2582. var duration = this.animationEnd - this.animationStart;
  2583. if (duration != 0) {
  2584. if (this.loop)
  2585. return duration * (1 + ((this.trackTime / duration) | 0));
  2586. if (this.trackTime < duration)
  2587. return duration;
  2588. }
  2589. return this.trackTime;
  2590. };
  2591. return TrackEntry;
  2592. }());
  2593. spine.TrackEntry = TrackEntry;
  2594. var EventQueue = (function () {
  2595. function EventQueue(animState) {
  2596. this.objects = [];
  2597. this.drainDisabled = false;
  2598. this.animState = animState;
  2599. }
  2600. EventQueue.prototype.start = function (entry) {
  2601. this.objects.push(EventType.start);
  2602. this.objects.push(entry);
  2603. this.animState.animationsChanged = true;
  2604. };
  2605. EventQueue.prototype.interrupt = function (entry) {
  2606. this.objects.push(EventType.interrupt);
  2607. this.objects.push(entry);
  2608. };
  2609. EventQueue.prototype.end = function (entry) {
  2610. this.objects.push(EventType.end);
  2611. this.objects.push(entry);
  2612. this.animState.animationsChanged = true;
  2613. };
  2614. EventQueue.prototype.dispose = function (entry) {
  2615. this.objects.push(EventType.dispose);
  2616. this.objects.push(entry);
  2617. };
  2618. EventQueue.prototype.complete = function (entry) {
  2619. this.objects.push(EventType.complete);
  2620. this.objects.push(entry);
  2621. };
  2622. EventQueue.prototype.event = function (entry, event) {
  2623. this.objects.push(EventType.event);
  2624. this.objects.push(entry);
  2625. this.objects.push(event);
  2626. };
  2627. EventQueue.prototype.drain = function () {
  2628. if (this.drainDisabled)
  2629. return;
  2630. this.drainDisabled = true;
  2631. var objects = this.objects;
  2632. var listeners = this.animState.listeners;
  2633. for (var i = 0; i < objects.length; i += 2) {
  2634. var type = objects[i];
  2635. var entry = objects[i + 1];
  2636. switch (type) {
  2637. case EventType.start:
  2638. if (entry.listener && entry.listener.start)
  2639. entry.listener.start(entry);
  2640. for (var ii = 0; ii < listeners.length; ii++)
  2641. if (listeners[ii].start)
  2642. listeners[ii].start(entry);
  2643. break;
  2644. case EventType.interrupt:
  2645. if (entry.listener && entry.listener.interrupt)
  2646. entry.listener.interrupt(entry);
  2647. for (var ii = 0; ii < listeners.length; ii++)
  2648. if (listeners[ii].interrupt)
  2649. listeners[ii].interrupt(entry);
  2650. break;
  2651. case EventType.end:
  2652. if (entry.listener && entry.listener.end)
  2653. entry.listener.end(entry);
  2654. for (var ii = 0; ii < listeners.length; ii++)
  2655. if (listeners[ii].end)
  2656. listeners[ii].end(entry);
  2657. case EventType.dispose:
  2658. if (entry.listener && entry.listener.dispose)
  2659. entry.listener.dispose(entry);
  2660. for (var ii = 0; ii < listeners.length; ii++)
  2661. if (listeners[ii].dispose)
  2662. listeners[ii].dispose(entry);
  2663. this.animState.trackEntryPool.free(entry);
  2664. break;
  2665. case EventType.complete:
  2666. if (entry.listener && entry.listener.complete)
  2667. entry.listener.complete(entry);
  2668. for (var ii = 0; ii < listeners.length; ii++)
  2669. if (listeners[ii].complete)
  2670. listeners[ii].complete(entry);
  2671. break;
  2672. case EventType.event:
  2673. var event_3 = objects[i++ + 2];
  2674. if (entry.listener && entry.listener.event)
  2675. entry.listener.event(entry, event_3);
  2676. for (var ii = 0; ii < listeners.length; ii++)
  2677. if (listeners[ii].event)
  2678. listeners[ii].event(entry, event_3);
  2679. break;
  2680. }
  2681. }
  2682. this.clear();
  2683. this.drainDisabled = false;
  2684. };
  2685. EventQueue.prototype.clear = function () {
  2686. this.objects.length = 0;
  2687. };
  2688. return EventQueue;
  2689. }());
  2690. spine.EventQueue = EventQueue;
  2691. var EventType;
  2692. (function (EventType) {
  2693. EventType[EventType["start"] = 0] = "start";
  2694. EventType[EventType["interrupt"] = 1] = "interrupt";
  2695. EventType[EventType["end"] = 2] = "end";
  2696. EventType[EventType["dispose"] = 3] = "dispose";
  2697. EventType[EventType["complete"] = 4] = "complete";
  2698. EventType[EventType["event"] = 5] = "event";
  2699. })(EventType = spine.EventType || (spine.EventType = {}));
  2700. var AnimationStateAdapter = (function () {
  2701. function AnimationStateAdapter() {
  2702. }
  2703. AnimationStateAdapter.prototype.start = function (entry) {
  2704. };
  2705. AnimationStateAdapter.prototype.interrupt = function (entry) {
  2706. };
  2707. AnimationStateAdapter.prototype.end = function (entry) {
  2708. };
  2709. AnimationStateAdapter.prototype.dispose = function (entry) {
  2710. };
  2711. AnimationStateAdapter.prototype.complete = function (entry) {
  2712. };
  2713. AnimationStateAdapter.prototype.event = function (entry, event) {
  2714. };
  2715. return AnimationStateAdapter;
  2716. }());
  2717. spine.AnimationStateAdapter = AnimationStateAdapter;
  2718. var SUBSEQUENT = 0;
  2719. var FIRST = 1;
  2720. var HOLD_SUBSEQUENT = 2;
  2721. var HOLD_FIRST = 3;
  2722. var HOLD_MIX = 4;
  2723. var SETUP = 1;
  2724. var CURRENT = 2;
  2725. var _emptyAnimation = null;
  2726. })(spine || (spine = {}));
  2727. var spine;
  2728. (function (spine) {
  2729. var AnimationStateData = (function () {
  2730. function AnimationStateData(skeletonData) {
  2731. this.animationToMixTime = {};
  2732. this.defaultMix = 0;
  2733. if (!skeletonData)
  2734. throw new Error("skeletonData cannot be null.");
  2735. this.skeletonData = skeletonData;
  2736. }
  2737. AnimationStateData.prototype.setMix = function (fromName, toName, duration) {
  2738. var from = this.skeletonData.findAnimation(fromName);
  2739. if (!from)
  2740. throw new Error("Animation not found: " + fromName);
  2741. var to = this.skeletonData.findAnimation(toName);
  2742. if (!to)
  2743. throw new Error("Animation not found: " + toName);
  2744. this.setMixWith(from, to, duration);
  2745. };
  2746. AnimationStateData.prototype.setMixWith = function (from, to, duration) {
  2747. if (!from)
  2748. throw new Error("from cannot be null.");
  2749. if (!to)
  2750. throw new Error("to cannot be null.");
  2751. var key = from.name + "." + to.name;
  2752. this.animationToMixTime[key] = duration;
  2753. };
  2754. AnimationStateData.prototype.getMix = function (from, to) {
  2755. var key = from.name + "." + to.name;
  2756. var value = this.animationToMixTime[key];
  2757. return value === undefined ? this.defaultMix : value;
  2758. };
  2759. return AnimationStateData;
  2760. }());
  2761. spine.AnimationStateData = AnimationStateData;
  2762. })(spine || (spine = {}));
  2763. var spine;
  2764. (function (spine) {
  2765. var AssetManager = (function () {
  2766. function AssetManager(textureLoader, pathPrefix, downloader) {
  2767. if (pathPrefix === void 0) { pathPrefix = ""; }
  2768. if (downloader === void 0) { downloader = null; }
  2769. this.assets = {};
  2770. this.errors = {};
  2771. this.toLoad = 0;
  2772. this.loaded = 0;
  2773. this.textureLoader = textureLoader;
  2774. this.pathPrefix = pathPrefix;
  2775. this.downloader = downloader || new Downloader();
  2776. }
  2777. AssetManager.prototype.start = function (path) {
  2778. this.toLoad++;
  2779. return this.pathPrefix + path;
  2780. };
  2781. AssetManager.prototype.success = function (callback, path, asset) {
  2782. this.toLoad--;
  2783. this.loaded++;
  2784. this.assets[path] = asset;
  2785. if (callback)
  2786. callback(path, asset);
  2787. };
  2788. AssetManager.prototype.error = function (callback, path, message) {
  2789. this.toLoad--;
  2790. this.loaded++;
  2791. this.errors[path] = message;
  2792. if (callback)
  2793. callback(path, message);
  2794. };
  2795. AssetManager.prototype.setRawDataURI = function (path, data) {
  2796. this.downloader.rawDataUris[this.pathPrefix + path] = data;
  2797. };
  2798. AssetManager.prototype.loadBinary = function (path, success, error) {
  2799. var _this = this;
  2800. if (success === void 0) { success = null; }
  2801. if (error === void 0) { error = null; }
  2802. path = this.start(path);
  2803. this.downloader.downloadBinary(path, function (data) {
  2804. _this.success(success, path, data);
  2805. }, function (status, responseText) {
  2806. _this.error(error, path, "Couldn't load binary " + path + ": status " + status + ", " + responseText);
  2807. });
  2808. };
  2809. AssetManager.prototype.loadText = function (path, success, error) {
  2810. var _this = this;
  2811. if (success === void 0) { success = null; }
  2812. if (error === void 0) { error = null; }
  2813. path = this.start(path);
  2814. this.downloader.downloadText(path, function (data) {
  2815. _this.success(success, path, data);
  2816. }, function (status, responseText) {
  2817. _this.error(error, path, "Couldn't load text " + path + ": status " + status + ", " + responseText);
  2818. });
  2819. };
  2820. AssetManager.prototype.loadJson = function (path, success, error) {
  2821. var _this = this;
  2822. if (success === void 0) { success = null; }
  2823. if (error === void 0) { error = null; }
  2824. path = this.start(path);
  2825. this.downloader.downloadJson(path, function (data) {
  2826. _this.success(success, path, data);
  2827. }, function (status, responseText) {
  2828. _this.error(error, path, "Couldn't load JSON " + path + ": status " + status + ", " + responseText);
  2829. });
  2830. };
  2831. AssetManager.prototype.loadTexture = function (path, success, error) {
  2832. var _this = this;
  2833. if (success === void 0) { success = null; }
  2834. if (error === void 0) { error = null; }
  2835. path = this.start(path);
  2836. var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
  2837. var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
  2838. if (isWebWorker) {
  2839. fetch(path, { mode: "cors" }).then(function (response) {
  2840. if (response.ok)
  2841. return response.blob();
  2842. _this.error(error, path, "Couldn't load image: " + path);
  2843. return null;
  2844. }).then(function (blob) {
  2845. return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
  2846. }).then(function (bitmap) {
  2847. if (bitmap)
  2848. _this.success(success, path, _this.textureLoader(bitmap));
  2849. });
  2850. }
  2851. else {
  2852. var image_1 = new Image();
  2853. image_1.crossOrigin = "anonymous";
  2854. image_1.onload = function () {
  2855. _this.success(success, path, _this.textureLoader(image_1));
  2856. };
  2857. image_1.onerror = function () {
  2858. _this.error(error, path, "Couldn't load image: " + path);
  2859. };
  2860. if (this.downloader.rawDataUris[path])
  2861. path = this.downloader.rawDataUris[path];
  2862. image_1.src = path;
  2863. }
  2864. };
  2865. AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
  2866. var _this = this;
  2867. if (success === void 0) { success = null; }
  2868. if (error === void 0) { error = null; }
  2869. var index = path.lastIndexOf("/");
  2870. var parent = index >= 0 ? path.substring(0, index + 1) : "";
  2871. path = this.start(path);
  2872. this.downloader.downloadText(path, function (atlasText) {
  2873. try {
  2874. var atlas_1 = new spine.TextureAtlas(atlasText);
  2875. var toLoad_1 = atlas_1.pages.length, abort_1 = false;
  2876. var _loop_1 = function (page) {
  2877. _this.loadTexture(parent + page.name, function (imagePath, texture) {
  2878. if (!abort_1) {
  2879. page.setTexture(texture);
  2880. if (--toLoad_1 == 0)
  2881. _this.success(success, path, atlas_1);
  2882. }
  2883. }, function (imagePath, message) {
  2884. if (!abort_1)
  2885. _this.error(error, path, "Couldn't load texture atlas " + path + " page image: " + imagePath);
  2886. abort_1 = true;
  2887. });
  2888. };
  2889. for (var _i = 0, _a = atlas_1.pages; _i < _a.length; _i++) {
  2890. var page = _a[_i];
  2891. _loop_1(page);
  2892. }
  2893. }
  2894. catch (e) {
  2895. _this.error(error, path, "Couldn't parse texture atlas " + path + ": " + e.message);
  2896. }
  2897. }, function (status, responseText) {
  2898. _this.error(error, path, "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText);
  2899. });
  2900. };
  2901. AssetManager.prototype.get = function (path) {
  2902. return this.assets[this.pathPrefix + path];
  2903. };
  2904. AssetManager.prototype.require = function (path) {
  2905. path = this.pathPrefix + path;
  2906. var asset = this.assets[path];
  2907. if (asset)
  2908. return asset;
  2909. var error = this.errors[path];
  2910. throw Error("Asset not found: " + path + (error ? "\n" + error : ""));
  2911. };
  2912. AssetManager.prototype.remove = function (path) {
  2913. path = this.pathPrefix + path;
  2914. var asset = this.assets[path];
  2915. if (asset.dispose)
  2916. asset.dispose();
  2917. delete this.assets[path];
  2918. return asset;
  2919. };
  2920. AssetManager.prototype.removeAll = function () {
  2921. for (var key in this.assets) {
  2922. var asset = this.assets[key];
  2923. if (asset.dispose)
  2924. asset.dispose();
  2925. }
  2926. this.assets = {};
  2927. };
  2928. AssetManager.prototype.isLoadingComplete = function () {
  2929. return this.toLoad == 0;
  2930. };
  2931. AssetManager.prototype.getToLoad = function () {
  2932. return this.toLoad;
  2933. };
  2934. AssetManager.prototype.getLoaded = function () {
  2935. return this.loaded;
  2936. };
  2937. AssetManager.prototype.dispose = function () {
  2938. this.removeAll();
  2939. };
  2940. AssetManager.prototype.hasErrors = function () {
  2941. return Object.keys(this.errors).length > 0;
  2942. };
  2943. AssetManager.prototype.getErrors = function () {
  2944. return this.errors;
  2945. };
  2946. return AssetManager;
  2947. }());
  2948. spine.AssetManager = AssetManager;
  2949. var Downloader = (function () {
  2950. function Downloader() {
  2951. this.callbacks = {};
  2952. this.rawDataUris = {};
  2953. }
  2954. Downloader.prototype.downloadText = function (url, success, error) {
  2955. var _this = this;
  2956. if (this.rawDataUris[url])
  2957. url = this.rawDataUris[url];
  2958. if (this.start(url, success, error))
  2959. return;
  2960. var request = new XMLHttpRequest();
  2961. request.overrideMimeType("text/html");
  2962. request.open("GET", url, true);
  2963. var done = function () {
  2964. _this.finish(url, request.status, request.responseText);
  2965. };
  2966. request.onload = done;
  2967. request.onerror = done;
  2968. request.send();
  2969. };
  2970. Downloader.prototype.downloadJson = function (url, success, error) {
  2971. this.downloadText(url, function (data) {
  2972. success(JSON.parse(data));
  2973. }, error);
  2974. };
  2975. Downloader.prototype.downloadBinary = function (url, success, error) {
  2976. var _this = this;
  2977. if (this.rawDataUris[url])
  2978. url = this.rawDataUris[url];
  2979. if (this.start(url, success, error))
  2980. return;
  2981. var request = new XMLHttpRequest();
  2982. request.open("GET", url, true);
  2983. request.responseType = "arraybuffer";
  2984. var onerror = function () {
  2985. _this.finish(url, request.status, request.responseText);
  2986. };
  2987. request.onload = function () {
  2988. if (request.status == 200)
  2989. _this.finish(url, 200, new Uint8Array(request.response));
  2990. else
  2991. onerror();
  2992. };
  2993. request.onerror = onerror;
  2994. request.send();
  2995. };
  2996. Downloader.prototype.start = function (url, success, error) {
  2997. var callbacks = this.callbacks[url];
  2998. try {
  2999. if (callbacks)
  3000. return true;
  3001. this.callbacks[url] = callbacks = [];
  3002. }
  3003. finally {
  3004. callbacks.push(success, error);
  3005. }
  3006. };
  3007. Downloader.prototype.finish = function (url, status, data) {
  3008. var callbacks = this.callbacks[url];
  3009. delete this.callbacks[url];
  3010. var args = status == 200 ? [data] : [status, data];
  3011. for (var i = args.length - 1, n = callbacks.length; i < n; i += 2)
  3012. callbacks[i].apply(null, args);
  3013. };
  3014. return Downloader;
  3015. }());
  3016. spine.Downloader = Downloader;
  3017. })(spine || (spine = {}));
  3018. var spine;
  3019. (function (spine) {
  3020. var AtlasAttachmentLoader = (function () {
  3021. function AtlasAttachmentLoader(atlas) {
  3022. this.atlas = atlas;
  3023. }
  3024. AtlasAttachmentLoader.prototype.newRegionAttachment = function (skin, name, path) {
  3025. var region = this.atlas.findRegion(path);
  3026. if (!region)
  3027. // throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  3028. return null;
  3029. region.renderObject = region;
  3030. var attachment = new spine.RegionAttachment(name);
  3031. attachment.setRegion(region);
  3032. return attachment;
  3033. };
  3034. AtlasAttachmentLoader.prototype.newMeshAttachment = function (skin, name, path) {
  3035. var region = this.atlas.findRegion(path);
  3036. if (!region)
  3037. // throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  3038. return null;
  3039. region.renderObject = region;
  3040. var attachment = new spine.MeshAttachment(name);
  3041. attachment.region = region;
  3042. return attachment;
  3043. };
  3044. AtlasAttachmentLoader.prototype.newBoundingBoxAttachment = function (skin, name) {
  3045. return new spine.BoundingBoxAttachment(name);
  3046. };
  3047. AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) {
  3048. return new spine.PathAttachment(name);
  3049. };
  3050. AtlasAttachmentLoader.prototype.newPointAttachment = function (skin, name) {
  3051. return new spine.PointAttachment(name);
  3052. };
  3053. AtlasAttachmentLoader.prototype.newClippingAttachment = function (skin, name) {
  3054. return new spine.ClippingAttachment(name);
  3055. };
  3056. return AtlasAttachmentLoader;
  3057. }());
  3058. spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
  3059. })(spine || (spine = {}));
  3060. var spine;
  3061. (function (spine) {
  3062. var Bone = (function () {
  3063. function Bone(data, skeleton, parent) {
  3064. this.children = new Array();
  3065. this.x = 0;
  3066. this.y = 0;
  3067. this.rotation = 0;
  3068. this.scaleX = 0;
  3069. this.scaleY = 0;
  3070. this.shearX = 0;
  3071. this.shearY = 0;
  3072. this.ax = 0;
  3073. this.ay = 0;
  3074. this.arotation = 0;
  3075. this.ascaleX = 0;
  3076. this.ascaleY = 0;
  3077. this.ashearX = 0;
  3078. this.ashearY = 0;
  3079. this.a = 0;
  3080. this.b = 0;
  3081. this.c = 0;
  3082. this.d = 0;
  3083. this.worldY = 0;
  3084. this.worldX = 0;
  3085. this.sorted = false;
  3086. this.active = false;
  3087. if (!data)
  3088. throw new Error("data cannot be null.");
  3089. if (!skeleton)
  3090. throw new Error("skeleton cannot be null.");
  3091. this.data = data;
  3092. this.skeleton = skeleton;
  3093. this.parent = parent;
  3094. this.setToSetupPose();
  3095. }
  3096. Bone.prototype.isActive = function () {
  3097. return this.active;
  3098. };
  3099. Bone.prototype.update = function () {
  3100. this.updateWorldTransformWith(this.ax, this.ay, this.arotation, this.ascaleX, this.ascaleY, this.ashearX, this.ashearY);
  3101. };
  3102. Bone.prototype.updateWorldTransform = function () {
  3103. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  3104. };
  3105. Bone.prototype.updateWorldTransformWith = function (x, y, rotation, scaleX, scaleY, shearX, shearY) {
  3106. this.ax = x;
  3107. this.ay = y;
  3108. this.arotation = rotation;
  3109. this.ascaleX = scaleX;
  3110. this.ascaleY = scaleY;
  3111. this.ashearX = shearX;
  3112. this.ashearY = shearY;
  3113. var parent = this.parent;
  3114. if (!parent) {
  3115. var skeleton = this.skeleton;
  3116. var rotationY = rotation + 90 + shearY;
  3117. var sx = skeleton.scaleX;
  3118. var sy = skeleton.scaleY;
  3119. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX * sx;
  3120. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY * sx;
  3121. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX * sy;
  3122. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY * sy;
  3123. this.worldX = x * sx + skeleton.x;
  3124. this.worldY = y * sy + skeleton.y;
  3125. return;
  3126. }
  3127. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  3128. this.worldX = pa * x + pb * y + parent.worldX;
  3129. this.worldY = pc * x + pd * y + parent.worldY;
  3130. switch (this.data.transformMode) {
  3131. case spine.TransformMode.Normal: {
  3132. var rotationY = rotation + 90 + shearY;
  3133. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  3134. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  3135. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  3136. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  3137. this.a = pa * la + pb * lc;
  3138. this.b = pa * lb + pb * ld;
  3139. this.c = pc * la + pd * lc;
  3140. this.d = pc * lb + pd * ld;
  3141. return;
  3142. }
  3143. case spine.TransformMode.OnlyTranslation: {
  3144. var rotationY = rotation + 90 + shearY;
  3145. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  3146. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY;
  3147. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  3148. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY;
  3149. break;
  3150. }
  3151. case spine.TransformMode.NoRotationOrReflection: {
  3152. var s = pa * pa + pc * pc;
  3153. var prx = 0;
  3154. if (s > 0.0001) {
  3155. s = Math.abs(pa * pd - pb * pc) / s;
  3156. pa /= this.skeleton.scaleX;
  3157. pc /= this.skeleton.scaleY;
  3158. pb = pc * s;
  3159. pd = pa * s;
  3160. prx = Math.atan2(pc, pa) * spine.MathUtils.radDeg;
  3161. }
  3162. else {
  3163. pa = 0;
  3164. pc = 0;
  3165. prx = 90 - Math.atan2(pd, pb) * spine.MathUtils.radDeg;
  3166. }
  3167. var rx = rotation + shearX - prx;
  3168. var ry = rotation + shearY - prx + 90;
  3169. var la = spine.MathUtils.cosDeg(rx) * scaleX;
  3170. var lb = spine.MathUtils.cosDeg(ry) * scaleY;
  3171. var lc = spine.MathUtils.sinDeg(rx) * scaleX;
  3172. var ld = spine.MathUtils.sinDeg(ry) * scaleY;
  3173. this.a = pa * la - pb * lc;
  3174. this.b = pa * lb - pb * ld;
  3175. this.c = pc * la + pd * lc;
  3176. this.d = pc * lb + pd * ld;
  3177. break;
  3178. }
  3179. case spine.TransformMode.NoScale:
  3180. case spine.TransformMode.NoScaleOrReflection: {
  3181. var cos = spine.MathUtils.cosDeg(rotation);
  3182. var sin = spine.MathUtils.sinDeg(rotation);
  3183. var za = (pa * cos + pb * sin) / this.skeleton.scaleX;
  3184. var zc = (pc * cos + pd * sin) / this.skeleton.scaleY;
  3185. var s = Math.sqrt(za * za + zc * zc);
  3186. if (s > 0.00001)
  3187. s = 1 / s;
  3188. za *= s;
  3189. zc *= s;
  3190. s = Math.sqrt(za * za + zc * zc);
  3191. if (this.data.transformMode == spine.TransformMode.NoScale
  3192. && (pa * pd - pb * pc < 0) != (this.skeleton.scaleX < 0 != this.skeleton.scaleY < 0))
  3193. s = -s;
  3194. var r = Math.PI / 2 + Math.atan2(zc, za);
  3195. var zb = Math.cos(r) * s;
  3196. var zd = Math.sin(r) * s;
  3197. var la = spine.MathUtils.cosDeg(shearX) * scaleX;
  3198. var lb = spine.MathUtils.cosDeg(90 + shearY) * scaleY;
  3199. var lc = spine.MathUtils.sinDeg(shearX) * scaleX;
  3200. var ld = spine.MathUtils.sinDeg(90 + shearY) * scaleY;
  3201. this.a = za * la + zb * lc;
  3202. this.b = za * lb + zb * ld;
  3203. this.c = zc * la + zd * lc;
  3204. this.d = zc * lb + zd * ld;
  3205. break;
  3206. }
  3207. }
  3208. this.a *= this.skeleton.scaleX;
  3209. this.b *= this.skeleton.scaleX;
  3210. this.c *= this.skeleton.scaleY;
  3211. this.d *= this.skeleton.scaleY;
  3212. };
  3213. Bone.prototype.setToSetupPose = function () {
  3214. var data = this.data;
  3215. this.x = data.x;
  3216. this.y = data.y;
  3217. this.rotation = data.rotation;
  3218. this.scaleX = data.scaleX;
  3219. this.scaleY = data.scaleY;
  3220. this.shearX = data.shearX;
  3221. this.shearY = data.shearY;
  3222. };
  3223. Bone.prototype.getWorldRotationX = function () {
  3224. return Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  3225. };
  3226. Bone.prototype.getWorldRotationY = function () {
  3227. return Math.atan2(this.d, this.b) * spine.MathUtils.radDeg;
  3228. };
  3229. Bone.prototype.getWorldScaleX = function () {
  3230. return Math.sqrt(this.a * this.a + this.c * this.c);
  3231. };
  3232. Bone.prototype.getWorldScaleY = function () {
  3233. return Math.sqrt(this.b * this.b + this.d * this.d);
  3234. };
  3235. Bone.prototype.updateAppliedTransform = function () {
  3236. var parent = this.parent;
  3237. if (!parent) {
  3238. this.ax = this.worldX;
  3239. this.ay = this.worldY;
  3240. this.arotation = Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  3241. this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c);
  3242. this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d);
  3243. this.ashearX = 0;
  3244. this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * spine.MathUtils.radDeg;
  3245. return;
  3246. }
  3247. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  3248. var pid = 1 / (pa * pd - pb * pc);
  3249. var dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY;
  3250. this.ax = (dx * pd * pid - dy * pb * pid);
  3251. this.ay = (dy * pa * pid - dx * pc * pid);
  3252. var ia = pid * pd;
  3253. var id = pid * pa;
  3254. var ib = pid * pb;
  3255. var ic = pid * pc;
  3256. var ra = ia * this.a - ib * this.c;
  3257. var rb = ia * this.b - ib * this.d;
  3258. var rc = id * this.c - ic * this.a;
  3259. var rd = id * this.d - ic * this.b;
  3260. this.ashearX = 0;
  3261. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  3262. if (this.ascaleX > 0.0001) {
  3263. var det = ra * rd - rb * rc;
  3264. this.ascaleY = det / this.ascaleX;
  3265. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * spine.MathUtils.radDeg;
  3266. this.arotation = Math.atan2(rc, ra) * spine.MathUtils.radDeg;
  3267. }
  3268. else {
  3269. this.ascaleX = 0;
  3270. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  3271. this.ashearY = 0;
  3272. this.arotation = 90 - Math.atan2(rd, rb) * spine.MathUtils.radDeg;
  3273. }
  3274. };
  3275. Bone.prototype.worldToLocal = function (world) {
  3276. var invDet = 1 / (this.a * this.d - this.b * this.c);
  3277. var x = world.x - this.worldX, y = world.y - this.worldY;
  3278. world.x = x * this.d * invDet - y * this.b * invDet;
  3279. world.y = y * this.a * invDet - x * this.c * invDet;
  3280. return world;
  3281. };
  3282. Bone.prototype.localToWorld = function (local) {
  3283. var x = local.x, y = local.y;
  3284. local.x = x * this.a + y * this.b + this.worldX;
  3285. local.y = x * this.c + y * this.d + this.worldY;
  3286. return local;
  3287. };
  3288. Bone.prototype.worldToLocalRotation = function (worldRotation) {
  3289. var sin = spine.MathUtils.sinDeg(worldRotation), cos = spine.MathUtils.cosDeg(worldRotation);
  3290. return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * spine.MathUtils.radDeg + this.rotation - this.shearX;
  3291. };
  3292. Bone.prototype.localToWorldRotation = function (localRotation) {
  3293. localRotation -= this.rotation - this.shearX;
  3294. var sin = spine.MathUtils.sinDeg(localRotation), cos = spine.MathUtils.cosDeg(localRotation);
  3295. return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * spine.MathUtils.radDeg;
  3296. };
  3297. Bone.prototype.rotateWorld = function (degrees) {
  3298. var a = this.a, b = this.b, c = this.c, d = this.d;
  3299. var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
  3300. this.a = cos * a - sin * c;
  3301. this.b = cos * b - sin * d;
  3302. this.c = sin * a + cos * c;
  3303. this.d = sin * b + cos * d;
  3304. };
  3305. return Bone;
  3306. }());
  3307. spine.Bone = Bone;
  3308. })(spine || (spine = {}));
  3309. var spine;
  3310. (function (spine) {
  3311. var BoneData = (function () {
  3312. function BoneData(index, name, parent) {
  3313. this.x = 0;
  3314. this.y = 0;
  3315. this.rotation = 0;
  3316. this.scaleX = 1;
  3317. this.scaleY = 1;
  3318. this.shearX = 0;
  3319. this.shearY = 0;
  3320. this.transformMode = TransformMode.Normal;
  3321. this.skinRequired = false;
  3322. this.color = new spine.Color();
  3323. if (index < 0)
  3324. throw new Error("index must be >= 0.");
  3325. if (!name)
  3326. throw new Error("name cannot be null.");
  3327. this.index = index;
  3328. this.name = name;
  3329. this.parent = parent;
  3330. }
  3331. return BoneData;
  3332. }());
  3333. spine.BoneData = BoneData;
  3334. var TransformMode;
  3335. (function (TransformMode) {
  3336. TransformMode[TransformMode["Normal"] = 0] = "Normal";
  3337. TransformMode[TransformMode["OnlyTranslation"] = 1] = "OnlyTranslation";
  3338. TransformMode[TransformMode["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
  3339. TransformMode[TransformMode["NoScale"] = 3] = "NoScale";
  3340. TransformMode[TransformMode["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
  3341. })(TransformMode = spine.TransformMode || (spine.TransformMode = {}));
  3342. })(spine || (spine = {}));
  3343. var spine;
  3344. (function (spine) {
  3345. var ConstraintData = (function () {
  3346. function ConstraintData(name, order, skinRequired) {
  3347. this.name = name;
  3348. this.order = order;
  3349. this.skinRequired = skinRequired;
  3350. }
  3351. return ConstraintData;
  3352. }());
  3353. spine.ConstraintData = ConstraintData;
  3354. })(spine || (spine = {}));
  3355. var spine;
  3356. (function (spine) {
  3357. var Event = (function () {
  3358. function Event(time, data) {
  3359. if (!data)
  3360. throw new Error("data cannot be null.");
  3361. this.time = time;
  3362. this.data = data;
  3363. }
  3364. return Event;
  3365. }());
  3366. spine.Event = Event;
  3367. })(spine || (spine = {}));
  3368. var spine;
  3369. (function (spine) {
  3370. var EventData = (function () {
  3371. function EventData(name) {
  3372. this.name = name;
  3373. }
  3374. return EventData;
  3375. }());
  3376. spine.EventData = EventData;
  3377. })(spine || (spine = {}));
  3378. var spine;
  3379. (function (spine) {
  3380. var IkConstraint = (function () {
  3381. function IkConstraint(data, skeleton) {
  3382. this.bendDirection = 0;
  3383. this.compress = false;
  3384. this.stretch = false;
  3385. this.mix = 1;
  3386. this.softness = 0;
  3387. this.active = false;
  3388. if (!data)
  3389. throw new Error("data cannot be null.");
  3390. if (!skeleton)
  3391. throw new Error("skeleton cannot be null.");
  3392. this.data = data;
  3393. this.mix = data.mix;
  3394. this.softness = data.softness;
  3395. this.bendDirection = data.bendDirection;
  3396. this.compress = data.compress;
  3397. this.stretch = data.stretch;
  3398. this.bones = new Array();
  3399. for (var i = 0; i < data.bones.length; i++)
  3400. this.bones.push(skeleton.findBone(data.bones[i].name));
  3401. this.target = skeleton.findBone(data.target.name);
  3402. }
  3403. IkConstraint.prototype.isActive = function () {
  3404. return this.active;
  3405. };
  3406. IkConstraint.prototype.update = function () {
  3407. if (this.mix == 0)
  3408. return;
  3409. var target = this.target;
  3410. var bones = this.bones;
  3411. switch (bones.length) {
  3412. case 1:
  3413. this.apply1(bones[0], target.worldX, target.worldY, this.compress, this.stretch, this.data.uniform, this.mix);
  3414. break;
  3415. case 2:
  3416. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.stretch, this.data.uniform, this.softness, this.mix);
  3417. break;
  3418. }
  3419. };
  3420. IkConstraint.prototype.apply1 = function (bone, targetX, targetY, compress, stretch, uniform, alpha) {
  3421. var p = bone.parent;
  3422. var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
  3423. var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
  3424. switch (bone.data.transformMode) {
  3425. case spine.TransformMode.OnlyTranslation:
  3426. tx = targetX - bone.worldX;
  3427. ty = targetY - bone.worldY;
  3428. break;
  3429. case spine.TransformMode.NoRotationOrReflection:
  3430. var s = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
  3431. var sa = pa / bone.skeleton.scaleX;
  3432. var sc = pc / bone.skeleton.scaleY;
  3433. pb = -sc * s * bone.skeleton.scaleX;
  3434. pd = sa * s * bone.skeleton.scaleY;
  3435. rotationIK += Math.atan2(sc, sa) * spine.MathUtils.radDeg;
  3436. default:
  3437. var x = targetX - p.worldX, y = targetY - p.worldY;
  3438. var d = pa * pd - pb * pc;
  3439. tx = (x * pd - y * pb) / d - bone.ax;
  3440. ty = (y * pa - x * pc) / d - bone.ay;
  3441. }
  3442. rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
  3443. if (bone.ascaleX < 0)
  3444. rotationIK += 180;
  3445. if (rotationIK > 180)
  3446. rotationIK -= 360;
  3447. else if (rotationIK < -180)
  3448. rotationIK += 360;
  3449. var sx = bone.ascaleX, sy = bone.ascaleY;
  3450. if (compress || stretch) {
  3451. switch (bone.data.transformMode) {
  3452. case spine.TransformMode.NoScale:
  3453. case spine.TransformMode.NoScaleOrReflection:
  3454. tx = targetX - bone.worldX;
  3455. ty = targetY - bone.worldY;
  3456. }
  3457. var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
  3458. if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
  3459. var s = (dd / b - 1) * alpha + 1;
  3460. sx *= s;
  3461. if (uniform)
  3462. sy *= s;
  3463. }
  3464. }
  3465. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX, bone.ashearY);
  3466. };
  3467. IkConstraint.prototype.apply2 = function (parent, child, targetX, targetY, bendDir, stretch, uniform, softness, alpha) {
  3468. var px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, sx = psx, sy = psy, csx = child.ascaleX;
  3469. var os1 = 0, os2 = 0, s2 = 0;
  3470. if (psx < 0) {
  3471. psx = -psx;
  3472. os1 = 180;
  3473. s2 = -1;
  3474. }
  3475. else {
  3476. os1 = 0;
  3477. s2 = 1;
  3478. }
  3479. if (psy < 0) {
  3480. psy = -psy;
  3481. s2 = -s2;
  3482. }
  3483. if (csx < 0) {
  3484. csx = -csx;
  3485. os2 = 180;
  3486. }
  3487. else
  3488. os2 = 0;
  3489. var cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
  3490. var u = Math.abs(psx - psy) <= 0.0001;
  3491. if (!u || stretch) {
  3492. cy = 0;
  3493. cwx = a * cx + parent.worldX;
  3494. cwy = c * cx + parent.worldY;
  3495. }
  3496. else {
  3497. cy = child.ay;
  3498. cwx = a * cx + b * cy + parent.worldX;
  3499. cwy = c * cx + d * cy + parent.worldY;
  3500. }
  3501. var pp = parent.parent;
  3502. a = pp.a;
  3503. b = pp.b;
  3504. c = pp.c;
  3505. d = pp.d;
  3506. var id = 1 / (a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY;
  3507. var dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  3508. var l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
  3509. if (l1 < 0.0001) {
  3510. this.apply1(parent, targetX, targetY, false, stretch, false, alpha);
  3511. child.updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  3512. return;
  3513. }
  3514. x = targetX - pp.worldX;
  3515. y = targetY - pp.worldY;
  3516. var tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  3517. var dd = tx * tx + ty * ty;
  3518. if (softness != 0) {
  3519. softness *= psx * (csx + 1) * 0.5;
  3520. var td = Math.sqrt(dd), sd = td - l1 - l2 * psx + softness;
  3521. if (sd > 0) {
  3522. var p = Math.min(1, sd / (softness * 2)) - 1;
  3523. p = (sd - softness * (1 - p * p)) / td;
  3524. tx -= p * tx;
  3525. ty -= p * ty;
  3526. dd = tx * tx + ty * ty;
  3527. }
  3528. }
  3529. outer: if (u) {
  3530. l2 *= psx;
  3531. var cos = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  3532. if (cos < -1) {
  3533. cos = -1;
  3534. a2 = Math.PI * bendDir;
  3535. }
  3536. else if (cos > 1) {
  3537. cos = 1;
  3538. a2 = 0;
  3539. if (stretch) {
  3540. a = (Math.sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
  3541. sx *= a;
  3542. if (uniform)
  3543. sy *= a;
  3544. }
  3545. }
  3546. else
  3547. a2 = Math.acos(cos) * bendDir;
  3548. a = l1 + l2 * cos;
  3549. b = l2 * Math.sin(a2);
  3550. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  3551. }
  3552. else {
  3553. a = psx * l2;
  3554. b = psy * l2;
  3555. var aa = a * a, bb = b * b, ta = Math.atan2(ty, tx);
  3556. c = bb * l1 * l1 + aa * dd - aa * bb;
  3557. var c1 = -2 * bb * l1, c2 = bb - aa;
  3558. d = c1 * c1 - 4 * c2 * c;
  3559. if (d >= 0) {
  3560. var q = Math.sqrt(d);
  3561. if (c1 < 0)
  3562. q = -q;
  3563. q = -(c1 + q) * 0.5;
  3564. var r0 = q / c2, r1 = c / q;
  3565. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  3566. if (r * r <= dd) {
  3567. y = Math.sqrt(dd - r * r) * bendDir;
  3568. a1 = ta - Math.atan2(y, r);
  3569. a2 = Math.atan2(y / psy, (r - l1) / psx);
  3570. break outer;
  3571. }
  3572. }
  3573. var minAngle = spine.MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  3574. var maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  3575. c = -a * l1 / (aa - bb);
  3576. if (c >= -1 && c <= 1) {
  3577. c = Math.acos(c);
  3578. x = a * Math.cos(c) + l1;
  3579. y = b * Math.sin(c);
  3580. d = x * x + y * y;
  3581. if (d < minDist) {
  3582. minAngle = c;
  3583. minDist = d;
  3584. minX = x;
  3585. minY = y;
  3586. }
  3587. if (d > maxDist) {
  3588. maxAngle = c;
  3589. maxDist = d;
  3590. maxX = x;
  3591. maxY = y;
  3592. }
  3593. }
  3594. if (dd <= (minDist + maxDist) * 0.5) {
  3595. a1 = ta - Math.atan2(minY * bendDir, minX);
  3596. a2 = minAngle * bendDir;
  3597. }
  3598. else {
  3599. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  3600. a2 = maxAngle * bendDir;
  3601. }
  3602. }
  3603. var os = Math.atan2(cy, cx) * s2;
  3604. var rotation = parent.arotation;
  3605. a1 = (a1 - os) * spine.MathUtils.radDeg + os1 - rotation;
  3606. if (a1 > 180)
  3607. a1 -= 360;
  3608. else if (a1 < -180)
  3609. a1 += 360;
  3610. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, sx, sy, 0, 0);
  3611. rotation = child.arotation;
  3612. a2 = ((a2 + os) * spine.MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  3613. if (a2 > 180)
  3614. a2 -= 360;
  3615. else if (a2 < -180)
  3616. a2 += 360;
  3617. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  3618. };
  3619. return IkConstraint;
  3620. }());
  3621. spine.IkConstraint = IkConstraint;
  3622. })(spine || (spine = {}));
  3623. var spine;
  3624. (function (spine) {
  3625. var IkConstraintData = (function (_super) {
  3626. __extends(IkConstraintData, _super);
  3627. function IkConstraintData(name) {
  3628. var _this = _super.call(this, name, 0, false) || this;
  3629. _this.bones = new Array();
  3630. _this.bendDirection = 1;
  3631. _this.compress = false;
  3632. _this.stretch = false;
  3633. _this.uniform = false;
  3634. _this.mix = 1;
  3635. _this.softness = 0;
  3636. return _this;
  3637. }
  3638. return IkConstraintData;
  3639. }(spine.ConstraintData));
  3640. spine.IkConstraintData = IkConstraintData;
  3641. })(spine || (spine = {}));
  3642. var spine;
  3643. (function (spine) {
  3644. var PathConstraint = (function () {
  3645. function PathConstraint(data, skeleton) {
  3646. this.position = 0;
  3647. this.spacing = 0;
  3648. this.mixRotate = 0;
  3649. this.mixX = 0;
  3650. this.mixY = 0;
  3651. this.spaces = new Array();
  3652. this.positions = new Array();
  3653. this.world = new Array();
  3654. this.curves = new Array();
  3655. this.lengths = new Array();
  3656. this.segments = new Array();
  3657. this.active = false;
  3658. if (!data)
  3659. throw new Error("data cannot be null.");
  3660. if (!skeleton)
  3661. throw new Error("skeleton cannot be null.");
  3662. this.data = data;
  3663. this.bones = new Array();
  3664. for (var i = 0, n = data.bones.length; i < n; i++)
  3665. this.bones.push(skeleton.findBone(data.bones[i].name));
  3666. this.target = skeleton.findSlot(data.target.name);
  3667. this.position = data.position;
  3668. this.spacing = data.spacing;
  3669. this.mixRotate = data.mixRotate;
  3670. this.mixX = data.mixX;
  3671. this.mixY = data.mixY;
  3672. }
  3673. PathConstraint.prototype.isActive = function () {
  3674. return this.active;
  3675. };
  3676. PathConstraint.prototype.update = function () {
  3677. var attachment = this.target.getAttachment();
  3678. if (!(attachment instanceof spine.PathAttachment))
  3679. return;
  3680. var mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY;
  3681. if (mixRotate == 0 && mixX == 0 && mixY == 0)
  3682. return;
  3683. var data = this.data;
  3684. var tangents = data.rotateMode == spine.RotateMode.Tangent, scale = data.rotateMode == spine.RotateMode.ChainScale;
  3685. var bones = this.bones;
  3686. var boneCount = bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  3687. var spaces = spine.Utils.setArraySize(this.spaces, spacesCount), lengths = scale ? this.lengths = spine.Utils.setArraySize(this.lengths, boneCount) : null;
  3688. var spacing = this.spacing;
  3689. switch (data.spacingMode) {
  3690. case spine.SpacingMode.Percent:
  3691. if (scale) {
  3692. for (var i = 0, n = spacesCount - 1; i < n; i++) {
  3693. var bone = bones[i];
  3694. var setupLength = bone.data.length;
  3695. if (setupLength < PathConstraint.epsilon)
  3696. lengths[i] = 0;
  3697. else {
  3698. var x = setupLength * bone.a, y = setupLength * bone.c;
  3699. lengths[i] = Math.sqrt(x * x + y * y);
  3700. }
  3701. }
  3702. }
  3703. spine.Utils.arrayFill(spaces, 1, spacesCount, spacing);
  3704. break;
  3705. case spine.SpacingMode.Proportional:
  3706. var sum = 0;
  3707. for (var i = 0; i < boneCount;) {
  3708. var bone = bones[i];
  3709. var setupLength = bone.data.length;
  3710. if (setupLength < PathConstraint.epsilon) {
  3711. if (scale)
  3712. lengths[i] = 0;
  3713. spaces[++i] = spacing;
  3714. }
  3715. else {
  3716. var x = setupLength * bone.a, y = setupLength * bone.c;
  3717. var length_1 = Math.sqrt(x * x + y * y);
  3718. if (scale)
  3719. lengths[i] = length_1;
  3720. spaces[++i] = length_1;
  3721. sum += length_1;
  3722. }
  3723. }
  3724. if (sum > 0) {
  3725. sum = spacesCount / sum * spacing;
  3726. for (var i = 1; i < spacesCount; i++)
  3727. spaces[i] *= sum;
  3728. }
  3729. break;
  3730. default:
  3731. var lengthSpacing = data.spacingMode == spine.SpacingMode.Length;
  3732. for (var i = 0, n = spacesCount - 1; i < n;) {
  3733. var bone = bones[i];
  3734. var setupLength = bone.data.length;
  3735. if (setupLength < PathConstraint.epsilon) {
  3736. if (scale)
  3737. lengths[i] = 0;
  3738. spaces[++i] = spacing;
  3739. }
  3740. else {
  3741. var x = setupLength * bone.a, y = setupLength * bone.c;
  3742. var length_2 = Math.sqrt(x * x + y * y);
  3743. if (scale)
  3744. lengths[i] = length_2;
  3745. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length_2 / setupLength;
  3746. }
  3747. }
  3748. }
  3749. var positions = this.computeWorldPositions(attachment, spacesCount, tangents);
  3750. var boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  3751. var tip = false;
  3752. if (offsetRotation == 0)
  3753. tip = data.rotateMode == spine.RotateMode.Chain;
  3754. else {
  3755. tip = false;
  3756. var p = this.target.bone;
  3757. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  3758. }
  3759. for (var i = 0, p = 3; i < boneCount; i++, p += 3) {
  3760. var bone = bones[i];
  3761. bone.worldX += (boneX - bone.worldX) * mixX;
  3762. bone.worldY += (boneY - bone.worldY) * mixY;
  3763. var x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  3764. if (scale) {
  3765. var length_3 = lengths[i];
  3766. if (length_3 != 0) {
  3767. var s = (Math.sqrt(dx * dx + dy * dy) / length_3 - 1) * mixRotate + 1;
  3768. bone.a *= s;
  3769. bone.c *= s;
  3770. }
  3771. }
  3772. boneX = x;
  3773. boneY = y;
  3774. if (mixRotate > 0) {
  3775. var a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
  3776. if (tangents)
  3777. r = positions[p - 1];
  3778. else if (spaces[i + 1] == 0)
  3779. r = positions[p + 2];
  3780. else
  3781. r = Math.atan2(dy, dx);
  3782. r -= Math.atan2(c, a);
  3783. if (tip) {
  3784. cos = Math.cos(r);
  3785. sin = Math.sin(r);
  3786. var length_4 = bone.data.length;
  3787. boneX += (length_4 * (cos * a - sin * c) - dx) * mixRotate;
  3788. boneY += (length_4 * (sin * a + cos * c) - dy) * mixRotate;
  3789. }
  3790. else {
  3791. r += offsetRotation;
  3792. }
  3793. if (r > spine.MathUtils.PI)
  3794. r -= spine.MathUtils.PI2;
  3795. else if (r < -spine.MathUtils.PI)
  3796. r += spine.MathUtils.PI2;
  3797. r *= mixRotate;
  3798. cos = Math.cos(r);
  3799. sin = Math.sin(r);
  3800. bone.a = cos * a - sin * c;
  3801. bone.b = cos * b - sin * d;
  3802. bone.c = sin * a + cos * c;
  3803. bone.d = sin * b + cos * d;
  3804. }
  3805. bone.updateAppliedTransform();
  3806. }
  3807. };
  3808. PathConstraint.prototype.computeWorldPositions = function (path, spacesCount, tangents) {
  3809. var target = this.target;
  3810. var position = this.position;
  3811. var spaces = this.spaces, out = spine.Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  3812. var closed = path.closed;
  3813. var verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint.NONE;
  3814. if (!path.constantSpeed) {
  3815. var lengths = path.lengths;
  3816. curveCount -= closed ? 1 : 2;
  3817. var pathLength_1 = lengths[curveCount];
  3818. if (this.data.positionMode == spine.PositionMode.Percent)
  3819. position *= pathLength_1;
  3820. var multiplier_1;
  3821. switch (this.data.spacingMode) {
  3822. case spine.SpacingMode.Percent:
  3823. multiplier_1 = pathLength_1;
  3824. break;
  3825. case spine.SpacingMode.Proportional:
  3826. multiplier_1 = pathLength_1 / spacesCount;
  3827. break;
  3828. default:
  3829. multiplier_1 = 1;
  3830. }
  3831. world = spine.Utils.setArraySize(this.world, 8);
  3832. for (var i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  3833. var space = spaces[i] * multiplier_1;
  3834. position += space;
  3835. var p = position;
  3836. if (closed) {
  3837. p %= pathLength_1;
  3838. if (p < 0)
  3839. p += pathLength_1;
  3840. curve = 0;
  3841. }
  3842. else if (p < 0) {
  3843. if (prevCurve != PathConstraint.BEFORE) {
  3844. prevCurve = PathConstraint.BEFORE;
  3845. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  3846. }
  3847. this.addBeforePosition(p, world, 0, out, o);
  3848. continue;
  3849. }
  3850. else if (p > pathLength_1) {
  3851. if (prevCurve != PathConstraint.AFTER) {
  3852. prevCurve = PathConstraint.AFTER;
  3853. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  3854. }
  3855. this.addAfterPosition(p - pathLength_1, world, 0, out, o);
  3856. continue;
  3857. }
  3858. for (;; curve++) {
  3859. var length_5 = lengths[curve];
  3860. if (p > length_5)
  3861. continue;
  3862. if (curve == 0)
  3863. p /= length_5;
  3864. else {
  3865. var prev = lengths[curve - 1];
  3866. p = (p - prev) / (length_5 - prev);
  3867. }
  3868. break;
  3869. }
  3870. if (curve != prevCurve) {
  3871. prevCurve = curve;
  3872. if (closed && curve == curveCount) {
  3873. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  3874. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  3875. }
  3876. else
  3877. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  3878. }
  3879. 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));
  3880. }
  3881. return out;
  3882. }
  3883. if (closed) {
  3884. verticesLength += 2;
  3885. world = spine.Utils.setArraySize(this.world, verticesLength);
  3886. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  3887. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  3888. world[verticesLength - 2] = world[0];
  3889. world[verticesLength - 1] = world[1];
  3890. }
  3891. else {
  3892. curveCount--;
  3893. verticesLength -= 4;
  3894. world = spine.Utils.setArraySize(this.world, verticesLength);
  3895. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  3896. }
  3897. var curves = spine.Utils.setArraySize(this.curves, curveCount);
  3898. var pathLength = 0;
  3899. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  3900. var tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  3901. for (var i = 0, w = 2; i < curveCount; i++, w += 6) {
  3902. cx1 = world[w];
  3903. cy1 = world[w + 1];
  3904. cx2 = world[w + 2];
  3905. cy2 = world[w + 3];
  3906. x2 = world[w + 4];
  3907. y2 = world[w + 5];
  3908. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  3909. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  3910. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  3911. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  3912. ddfx = tmpx * 2 + dddfx;
  3913. ddfy = tmpy * 2 + dddfy;
  3914. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  3915. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  3916. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3917. dfx += ddfx;
  3918. dfy += ddfy;
  3919. ddfx += dddfx;
  3920. ddfy += dddfy;
  3921. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3922. dfx += ddfx;
  3923. dfy += ddfy;
  3924. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3925. dfx += ddfx + dddfx;
  3926. dfy += ddfy + dddfy;
  3927. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3928. curves[i] = pathLength;
  3929. x1 = x2;
  3930. y1 = y2;
  3931. }
  3932. if (this.data.positionMode == spine.PositionMode.Percent)
  3933. position *= pathLength;
  3934. var multiplier;
  3935. switch (this.data.spacingMode) {
  3936. case spine.SpacingMode.Percent:
  3937. multiplier = pathLength;
  3938. break;
  3939. case spine.SpacingMode.Proportional:
  3940. multiplier = pathLength / spacesCount;
  3941. break;
  3942. default:
  3943. multiplier = 1;
  3944. }
  3945. var segments = this.segments;
  3946. var curveLength = 0;
  3947. for (var i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  3948. var space = spaces[i] * multiplier;
  3949. position += space;
  3950. var p = position;
  3951. if (closed) {
  3952. p %= pathLength;
  3953. if (p < 0)
  3954. p += pathLength;
  3955. curve = 0;
  3956. }
  3957. else if (p < 0) {
  3958. this.addBeforePosition(p, world, 0, out, o);
  3959. continue;
  3960. }
  3961. else if (p > pathLength) {
  3962. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  3963. continue;
  3964. }
  3965. for (;; curve++) {
  3966. var length_6 = curves[curve];
  3967. if (p > length_6)
  3968. continue;
  3969. if (curve == 0)
  3970. p /= length_6;
  3971. else {
  3972. var prev = curves[curve - 1];
  3973. p = (p - prev) / (length_6 - prev);
  3974. }
  3975. break;
  3976. }
  3977. if (curve != prevCurve) {
  3978. prevCurve = curve;
  3979. var ii = curve * 6;
  3980. x1 = world[ii];
  3981. y1 = world[ii + 1];
  3982. cx1 = world[ii + 2];
  3983. cy1 = world[ii + 3];
  3984. cx2 = world[ii + 4];
  3985. cy2 = world[ii + 5];
  3986. x2 = world[ii + 6];
  3987. y2 = world[ii + 7];
  3988. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  3989. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  3990. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  3991. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  3992. ddfx = tmpx * 2 + dddfx;
  3993. ddfy = tmpy * 2 + dddfy;
  3994. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  3995. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  3996. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  3997. segments[0] = curveLength;
  3998. for (ii = 1; ii < 8; ii++) {
  3999. dfx += ddfx;
  4000. dfy += ddfy;
  4001. ddfx += dddfx;
  4002. ddfy += dddfy;
  4003. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  4004. segments[ii] = curveLength;
  4005. }
  4006. dfx += ddfx;
  4007. dfy += ddfy;
  4008. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  4009. segments[8] = curveLength;
  4010. dfx += ddfx + dddfx;
  4011. dfy += ddfy + dddfy;
  4012. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  4013. segments[9] = curveLength;
  4014. segment = 0;
  4015. }
  4016. p *= curveLength;
  4017. for (;; segment++) {
  4018. var length_7 = segments[segment];
  4019. if (p > length_7)
  4020. continue;
  4021. if (segment == 0)
  4022. p /= length_7;
  4023. else {
  4024. var prev = segments[segment - 1];
  4025. p = segment + (p - prev) / (length_7 - prev);
  4026. }
  4027. break;
  4028. }
  4029. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  4030. }
  4031. return out;
  4032. };
  4033. PathConstraint.prototype.addBeforePosition = function (p, temp, i, out, o) {
  4034. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  4035. out[o] = x1 + p * Math.cos(r);
  4036. out[o + 1] = y1 + p * Math.sin(r);
  4037. out[o + 2] = r;
  4038. };
  4039. PathConstraint.prototype.addAfterPosition = function (p, temp, i, out, o) {
  4040. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  4041. out[o] = x1 + p * Math.cos(r);
  4042. out[o + 1] = y1 + p * Math.sin(r);
  4043. out[o + 2] = r;
  4044. };
  4045. PathConstraint.prototype.addCurvePosition = function (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  4046. if (p == 0 || isNaN(p)) {
  4047. out[o] = x1;
  4048. out[o + 1] = y1;
  4049. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  4050. return;
  4051. }
  4052. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  4053. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  4054. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  4055. out[o] = x;
  4056. out[o + 1] = y;
  4057. if (tangents) {
  4058. if (p < 0.001)
  4059. out[o + 2] = Math.atan2(cy1 - y1, cx1 - x1);
  4060. else
  4061. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  4062. }
  4063. };
  4064. PathConstraint.NONE = -1;
  4065. PathConstraint.BEFORE = -2;
  4066. PathConstraint.AFTER = -3;
  4067. PathConstraint.epsilon = 0.00001;
  4068. return PathConstraint;
  4069. }());
  4070. spine.PathConstraint = PathConstraint;
  4071. })(spine || (spine = {}));
  4072. var spine;
  4073. (function (spine) {
  4074. var PathConstraintData = (function (_super) {
  4075. __extends(PathConstraintData, _super);
  4076. function PathConstraintData(name) {
  4077. var _this = _super.call(this, name, 0, false) || this;
  4078. _this.bones = new Array();
  4079. _this.mixRotate = 0;
  4080. _this.mixX = 0;
  4081. _this.mixY = 0;
  4082. return _this;
  4083. }
  4084. return PathConstraintData;
  4085. }(spine.ConstraintData));
  4086. spine.PathConstraintData = PathConstraintData;
  4087. var PositionMode;
  4088. (function (PositionMode) {
  4089. PositionMode[PositionMode["Fixed"] = 0] = "Fixed";
  4090. PositionMode[PositionMode["Percent"] = 1] = "Percent";
  4091. })(PositionMode = spine.PositionMode || (spine.PositionMode = {}));
  4092. var SpacingMode;
  4093. (function (SpacingMode) {
  4094. SpacingMode[SpacingMode["Length"] = 0] = "Length";
  4095. SpacingMode[SpacingMode["Fixed"] = 1] = "Fixed";
  4096. SpacingMode[SpacingMode["Percent"] = 2] = "Percent";
  4097. SpacingMode[SpacingMode["Proportional"] = 3] = "Proportional";
  4098. })(SpacingMode = spine.SpacingMode || (spine.SpacingMode = {}));
  4099. var RotateMode;
  4100. (function (RotateMode) {
  4101. RotateMode[RotateMode["Tangent"] = 0] = "Tangent";
  4102. RotateMode[RotateMode["Chain"] = 1] = "Chain";
  4103. RotateMode[RotateMode["ChainScale"] = 2] = "ChainScale";
  4104. })(RotateMode = spine.RotateMode || (spine.RotateMode = {}));
  4105. })(spine || (spine = {}));
  4106. var spine;
  4107. (function (spine) {
  4108. var Skeleton = (function () {
  4109. function Skeleton(data) {
  4110. this._updateCache = new Array();
  4111. this.time = 0;
  4112. this.scaleX = 1;
  4113. this.scaleY = 1;
  4114. this.x = 0;
  4115. this.y = 0;
  4116. if (!data)
  4117. throw new Error("data cannot be null.");
  4118. this.data = data;
  4119. this.bones = new Array();
  4120. for (var i = 0; i < data.bones.length; i++) {
  4121. var boneData = data.bones[i];
  4122. var bone = void 0;
  4123. if (!boneData.parent)
  4124. bone = new spine.Bone(boneData, this, null);
  4125. else {
  4126. var parent_1 = this.bones[boneData.parent.index];
  4127. bone = new spine.Bone(boneData, this, parent_1);
  4128. parent_1.children.push(bone);
  4129. }
  4130. this.bones.push(bone);
  4131. }
  4132. this.slots = new Array();
  4133. this.drawOrder = new Array();
  4134. for (var i = 0; i < data.slots.length; i++) {
  4135. var slotData = data.slots[i];
  4136. var bone = this.bones[slotData.boneData.index];
  4137. var slot = new spine.Slot(slotData, bone);
  4138. this.slots.push(slot);
  4139. this.drawOrder.push(slot);
  4140. }
  4141. this.ikConstraints = new Array();
  4142. for (var i = 0; i < data.ikConstraints.length; i++) {
  4143. var ikConstraintData = data.ikConstraints[i];
  4144. this.ikConstraints.push(new spine.IkConstraint(ikConstraintData, this));
  4145. }
  4146. this.transformConstraints = new Array();
  4147. for (var i = 0; i < data.transformConstraints.length; i++) {
  4148. var transformConstraintData = data.transformConstraints[i];
  4149. this.transformConstraints.push(new spine.TransformConstraint(transformConstraintData, this));
  4150. }
  4151. this.pathConstraints = new Array();
  4152. for (var i = 0; i < data.pathConstraints.length; i++) {
  4153. var pathConstraintData = data.pathConstraints[i];
  4154. this.pathConstraints.push(new spine.PathConstraint(pathConstraintData, this));
  4155. }
  4156. this.color = new spine.Color(1, 1, 1, 1);
  4157. this.updateCache();
  4158. }
  4159. Skeleton.prototype.updateCache = function () {
  4160. var updateCache = this._updateCache;
  4161. updateCache.length = 0;
  4162. var bones = this.bones;
  4163. for (var i = 0, n = bones.length; i < n; i++) {
  4164. var bone = bones[i];
  4165. bone.sorted = bone.data.skinRequired;
  4166. bone.active = !bone.sorted;
  4167. }
  4168. if (this.skin) {
  4169. var skinBones = this.skin.bones;
  4170. for (var i = 0, n = this.skin.bones.length; i < n; i++) {
  4171. var bone = this.bones[skinBones[i].index];
  4172. do {
  4173. bone.sorted = false;
  4174. bone.active = true;
  4175. bone = bone.parent;
  4176. } while (bone);
  4177. }
  4178. }
  4179. var ikConstraints = this.ikConstraints;
  4180. var transformConstraints = this.transformConstraints;
  4181. var pathConstraints = this.pathConstraints;
  4182. var ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  4183. var constraintCount = ikCount + transformCount + pathCount;
  4184. outer: for (var i = 0; i < constraintCount; i++) {
  4185. for (var ii = 0; ii < ikCount; ii++) {
  4186. var constraint = ikConstraints[ii];
  4187. if (constraint.data.order == i) {
  4188. this.sortIkConstraint(constraint);
  4189. continue outer;
  4190. }
  4191. }
  4192. for (var ii = 0; ii < transformCount; ii++) {
  4193. var constraint = transformConstraints[ii];
  4194. if (constraint.data.order == i) {
  4195. this.sortTransformConstraint(constraint);
  4196. continue outer;
  4197. }
  4198. }
  4199. for (var ii = 0; ii < pathCount; ii++) {
  4200. var constraint = pathConstraints[ii];
  4201. if (constraint.data.order == i) {
  4202. this.sortPathConstraint(constraint);
  4203. continue outer;
  4204. }
  4205. }
  4206. }
  4207. for (var i = 0, n = bones.length; i < n; i++)
  4208. this.sortBone(bones[i]);
  4209. };
  4210. Skeleton.prototype.sortIkConstraint = function (constraint) {
  4211. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin && spine.Utils.contains(this.skin.constraints, constraint.data, true)));
  4212. if (!constraint.active)
  4213. return;
  4214. var target = constraint.target;
  4215. this.sortBone(target);
  4216. var constrained = constraint.bones;
  4217. var parent = constrained[0];
  4218. this.sortBone(parent);
  4219. if (constrained.length == 1) {
  4220. this._updateCache.push(constraint);
  4221. this.sortReset(parent.children);
  4222. }
  4223. else {
  4224. var child = constrained[constrained.length - 1];
  4225. this.sortBone(child);
  4226. this._updateCache.push(constraint);
  4227. this.sortReset(parent.children);
  4228. child.sorted = true;
  4229. }
  4230. };
  4231. Skeleton.prototype.sortPathConstraint = function (constraint) {
  4232. constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || (this.skin && spine.Utils.contains(this.skin.constraints, constraint.data, true)));
  4233. if (!constraint.active)
  4234. return;
  4235. var slot = constraint.target;
  4236. var slotIndex = slot.data.index;
  4237. var slotBone = slot.bone;
  4238. if (this.skin)
  4239. this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  4240. if (this.data.defaultSkin && this.data.defaultSkin != this.skin)
  4241. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  4242. for (var i = 0, n = this.data.skins.length; i < n; i++)
  4243. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  4244. var attachment = slot.getAttachment();
  4245. if (attachment instanceof spine.PathAttachment)
  4246. this.sortPathConstraintAttachmentWith(attachment, slotBone);
  4247. var constrained = constraint.bones;
  4248. var boneCount = constrained.length;
  4249. for (var i = 0; i < boneCount; i++)
  4250. this.sortBone(constrained[i]);
  4251. this._updateCache.push(constraint);
  4252. for (var i = 0; i < boneCount; i++)
  4253. this.sortReset(constrained[i].children);
  4254. for (var i = 0; i < boneCount; i++)
  4255. constrained[i].sorted = true;
  4256. };
  4257. Skeleton.prototype.sortTransformConstraint = function (constraint) {
  4258. constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin && spine.Utils.contains(this.skin.constraints, constraint.data, true)));
  4259. if (!constraint.active)
  4260. return;
  4261. this.sortBone(constraint.target);
  4262. var constrained = constraint.bones;
  4263. var boneCount = constrained.length;
  4264. if (constraint.data.local) {
  4265. for (var i = 0; i < boneCount; i++) {
  4266. var child = constrained[i];
  4267. this.sortBone(child.parent);
  4268. this.sortBone(child);
  4269. }
  4270. }
  4271. else {
  4272. for (var i = 0; i < boneCount; i++) {
  4273. this.sortBone(constrained[i]);
  4274. }
  4275. }
  4276. this._updateCache.push(constraint);
  4277. for (var i = 0; i < boneCount; i++)
  4278. this.sortReset(constrained[i].children);
  4279. for (var i = 0; i < boneCount; i++)
  4280. constrained[i].sorted = true;
  4281. };
  4282. Skeleton.prototype.sortPathConstraintAttachment = function (skin, slotIndex, slotBone) {
  4283. var attachments = skin.attachments[slotIndex];
  4284. if (!attachments)
  4285. return;
  4286. for (var key in attachments) {
  4287. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  4288. }
  4289. };
  4290. Skeleton.prototype.sortPathConstraintAttachmentWith = function (attachment, slotBone) {
  4291. if (!(attachment instanceof spine.PathAttachment))
  4292. return;
  4293. var pathBones = attachment.bones;
  4294. if (!pathBones)
  4295. this.sortBone(slotBone);
  4296. else {
  4297. var bones = this.bones;
  4298. for (var i = 0, n = pathBones.length; i < n;) {
  4299. var nn = pathBones[i++];
  4300. nn += i;
  4301. while (i < nn)
  4302. this.sortBone(bones[pathBones[i++]]);
  4303. }
  4304. }
  4305. };
  4306. Skeleton.prototype.sortBone = function (bone) {
  4307. if (bone.sorted)
  4308. return;
  4309. var parent = bone.parent;
  4310. if (parent)
  4311. this.sortBone(parent);
  4312. bone.sorted = true;
  4313. this._updateCache.push(bone);
  4314. };
  4315. Skeleton.prototype.sortReset = function (bones) {
  4316. for (var i = 0, n = bones.length; i < n; i++) {
  4317. var bone = bones[i];
  4318. if (!bone.active)
  4319. continue;
  4320. if (bone.sorted)
  4321. this.sortReset(bone.children);
  4322. bone.sorted = false;
  4323. }
  4324. };
  4325. Skeleton.prototype.updateWorldTransform = function () {
  4326. var bones = this.bones;
  4327. for (var i = 0, n = bones.length; i < n; i++) {
  4328. var bone = bones[i];
  4329. bone.ax = bone.x;
  4330. bone.ay = bone.y;
  4331. bone.arotation = bone.rotation;
  4332. bone.ascaleX = bone.scaleX;
  4333. bone.ascaleY = bone.scaleY;
  4334. bone.ashearX = bone.shearX;
  4335. bone.ashearY = bone.shearY;
  4336. }
  4337. var updateCache = this._updateCache;
  4338. for (var i = 0, n = updateCache.length; i < n; i++)
  4339. updateCache[i].update();
  4340. };
  4341. Skeleton.prototype.updateWorldTransformWith = function (parent) {
  4342. var rootBone = this.getRootBone();
  4343. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  4344. rootBone.worldX = pa * this.x + pb * this.y + parent.worldX;
  4345. rootBone.worldY = pc * this.x + pd * this.y + parent.worldY;
  4346. var rotationY = rootBone.rotation + 90 + rootBone.shearY;
  4347. var la = spine.MathUtils.cosDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
  4348. var lb = spine.MathUtils.cosDeg(rotationY) * rootBone.scaleY;
  4349. var lc = spine.MathUtils.sinDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
  4350. var ld = spine.MathUtils.sinDeg(rotationY) * rootBone.scaleY;
  4351. rootBone.a = (pa * la + pb * lc) * this.scaleX;
  4352. rootBone.b = (pa * lb + pb * ld) * this.scaleX;
  4353. rootBone.c = (pc * la + pd * lc) * this.scaleY;
  4354. rootBone.d = (pc * lb + pd * ld) * this.scaleY;
  4355. var updateCache = this._updateCache;
  4356. for (var i = 0, n = updateCache.length; i < n; i++) {
  4357. var updatable = updateCache[i];
  4358. if (updatable != rootBone)
  4359. updatable.update();
  4360. }
  4361. };
  4362. Skeleton.prototype.setToSetupPose = function () {
  4363. this.setBonesToSetupPose();
  4364. this.setSlotsToSetupPose();
  4365. };
  4366. Skeleton.prototype.setBonesToSetupPose = function () {
  4367. var bones = this.bones;
  4368. for (var i = 0, n = bones.length; i < n; i++)
  4369. bones[i].setToSetupPose();
  4370. var ikConstraints = this.ikConstraints;
  4371. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  4372. var constraint = ikConstraints[i];
  4373. constraint.mix = constraint.data.mix;
  4374. constraint.softness = constraint.data.softness;
  4375. constraint.bendDirection = constraint.data.bendDirection;
  4376. constraint.compress = constraint.data.compress;
  4377. constraint.stretch = constraint.data.stretch;
  4378. }
  4379. var transformConstraints = this.transformConstraints;
  4380. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  4381. var constraint = transformConstraints[i];
  4382. var data = constraint.data;
  4383. constraint.mixRotate = data.mixRotate;
  4384. constraint.mixX = data.mixX;
  4385. constraint.mixY = data.mixY;
  4386. constraint.mixScaleX = data.mixScaleX;
  4387. constraint.mixScaleY = data.mixScaleY;
  4388. constraint.mixShearY = data.mixShearY;
  4389. }
  4390. var pathConstraints = this.pathConstraints;
  4391. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  4392. var constraint = pathConstraints[i];
  4393. var data = constraint.data;
  4394. constraint.position = data.position;
  4395. constraint.spacing = data.spacing;
  4396. constraint.mixRotate = data.mixRotate;
  4397. constraint.mixX = data.mixX;
  4398. constraint.mixY = data.mixY;
  4399. }
  4400. };
  4401. Skeleton.prototype.setSlotsToSetupPose = function () {
  4402. var slots = this.slots;
  4403. spine.Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  4404. for (var i = 0, n = slots.length; i < n; i++)
  4405. slots[i].setToSetupPose();
  4406. };
  4407. Skeleton.prototype.getRootBone = function () {
  4408. if (this.bones.length == 0)
  4409. return null;
  4410. return this.bones[0];
  4411. };
  4412. Skeleton.prototype.findBone = function (boneName) {
  4413. if (!boneName)
  4414. throw new Error("boneName cannot be null.");
  4415. var bones = this.bones;
  4416. for (var i = 0, n = bones.length; i < n; i++) {
  4417. var bone = bones[i];
  4418. if (bone.data.name == boneName)
  4419. return bone;
  4420. }
  4421. return null;
  4422. };
  4423. Skeleton.prototype.findBoneIndex = function (boneName) {
  4424. if (!boneName)
  4425. throw new Error("boneName cannot be null.");
  4426. var bones = this.bones;
  4427. for (var i = 0, n = bones.length; i < n; i++)
  4428. if (bones[i].data.name == boneName)
  4429. return i;
  4430. return -1;
  4431. };
  4432. Skeleton.prototype.findSlot = function (slotName) {
  4433. if (!slotName)
  4434. throw new Error("slotName cannot be null.");
  4435. var slots = this.slots;
  4436. for (var i = 0, n = slots.length; i < n; i++) {
  4437. var slot = slots[i];
  4438. if (slot.data.name == slotName)
  4439. return slot;
  4440. }
  4441. return null;
  4442. };
  4443. Skeleton.prototype.findSlotIndex = function (slotName) {
  4444. if (!slotName)
  4445. throw new Error("slotName cannot be null.");
  4446. var slots = this.slots;
  4447. for (var i = 0, n = slots.length; i < n; i++)
  4448. if (slots[i].data.name == slotName)
  4449. return i;
  4450. return -1;
  4451. };
  4452. Skeleton.prototype.setSkinByName = function (skinName) {
  4453. var skin = this.data.findSkin(skinName);
  4454. if (!skin)
  4455. throw new Error("Skin not found: " + skinName);
  4456. this.setSkin(skin);
  4457. };
  4458. Skeleton.prototype.setSkin = function (newSkin) {
  4459. if (newSkin == this.skin)
  4460. return;
  4461. if (newSkin) {
  4462. if (this.skin)
  4463. newSkin.attachAll(this, this.skin);
  4464. else {
  4465. var slots = this.slots;
  4466. for (var i = 0, n = slots.length; i < n; i++) {
  4467. var slot = slots[i];
  4468. var name_1 = slot.data.attachmentName;
  4469. if (name_1) {
  4470. var attachment = newSkin.getAttachment(i, name_1);
  4471. if (attachment)
  4472. slot.setAttachment(attachment);
  4473. }
  4474. }
  4475. }
  4476. }
  4477. this.skin = newSkin;
  4478. this.updateCache();
  4479. };
  4480. Skeleton.prototype.getAttachmentByName = function (slotName, attachmentName) {
  4481. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  4482. };
  4483. Skeleton.prototype.getAttachment = function (slotIndex, attachmentName) {
  4484. if (!attachmentName)
  4485. throw new Error("attachmentName cannot be null.");
  4486. if (this.skin) {
  4487. var attachment = this.skin.getAttachment(slotIndex, attachmentName);
  4488. if (attachment)
  4489. return attachment;
  4490. }
  4491. if (this.data.defaultSkin)
  4492. return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  4493. return null;
  4494. };
  4495. Skeleton.prototype.setAttachment = function (slotName, attachmentName) {
  4496. if (!slotName)
  4497. throw new Error("slotName cannot be null.");
  4498. var slots = this.slots;
  4499. for (var i = 0, n = slots.length; i < n; i++) {
  4500. var slot = slots[i];
  4501. if (slot.data.name == slotName) {
  4502. var attachment = null;
  4503. if (attachmentName) {
  4504. attachment = this.getAttachment(i, attachmentName);
  4505. if (!attachment)
  4506. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  4507. }
  4508. slot.setAttachment(attachment);
  4509. return;
  4510. }
  4511. }
  4512. throw new Error("Slot not found: " + slotName);
  4513. };
  4514. Skeleton.prototype.findIkConstraint = function (constraintName) {
  4515. if (!constraintName)
  4516. throw new Error("constraintName cannot be null.");
  4517. var ikConstraints = this.ikConstraints;
  4518. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  4519. var ikConstraint = ikConstraints[i];
  4520. if (ikConstraint.data.name == constraintName)
  4521. return ikConstraint;
  4522. }
  4523. return null;
  4524. };
  4525. Skeleton.prototype.findTransformConstraint = function (constraintName) {
  4526. if (!constraintName)
  4527. throw new Error("constraintName cannot be null.");
  4528. var transformConstraints = this.transformConstraints;
  4529. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  4530. var constraint = transformConstraints[i];
  4531. if (constraint.data.name == constraintName)
  4532. return constraint;
  4533. }
  4534. return null;
  4535. };
  4536. Skeleton.prototype.findPathConstraint = function (constraintName) {
  4537. if (!constraintName)
  4538. throw new Error("constraintName cannot be null.");
  4539. var pathConstraints = this.pathConstraints;
  4540. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  4541. var constraint = pathConstraints[i];
  4542. if (constraint.data.name == constraintName)
  4543. return constraint;
  4544. }
  4545. return null;
  4546. };
  4547. Skeleton.prototype.getBounds = function (offset, size, temp) {
  4548. if (temp === void 0) { temp = new Array(2); }
  4549. if (!offset)
  4550. throw new Error("offset cannot be null.");
  4551. if (!size)
  4552. throw new Error("size cannot be null.");
  4553. var drawOrder = this.drawOrder;
  4554. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  4555. for (var i = 0, n = drawOrder.length; i < n; i++) {
  4556. var slot = drawOrder[i];
  4557. if (!slot.bone.active)
  4558. continue;
  4559. var verticesLength = 0;
  4560. var vertices = null;
  4561. var attachment = slot.getAttachment();
  4562. if (attachment instanceof spine.RegionAttachment) {
  4563. verticesLength = 8;
  4564. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  4565. attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  4566. }
  4567. else if (attachment instanceof spine.MeshAttachment) {
  4568. var mesh = attachment;
  4569. verticesLength = mesh.worldVerticesLength;
  4570. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  4571. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  4572. }
  4573. if (vertices) {
  4574. for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  4575. var x = vertices[ii], y = vertices[ii + 1];
  4576. minX = Math.min(minX, x);
  4577. minY = Math.min(minY, y);
  4578. maxX = Math.max(maxX, x);
  4579. maxY = Math.max(maxY, y);
  4580. }
  4581. }
  4582. }
  4583. offset.set(minX, minY);
  4584. size.set(maxX - minX, maxY - minY);
  4585. };
  4586. Skeleton.prototype.update = function (delta) {
  4587. this.time += delta;
  4588. };
  4589. return Skeleton;
  4590. }());
  4591. spine.Skeleton = Skeleton;
  4592. })(spine || (spine = {}));
  4593. var spine;
  4594. (function (spine) {
  4595. var SkeletonBinary = (function () {
  4596. function SkeletonBinary(attachmentLoader) {
  4597. this.scale = 1;
  4598. this.linkedMeshes = new Array();
  4599. this.attachmentLoader = attachmentLoader;
  4600. }
  4601. SkeletonBinary.prototype.readSkeletonData = function (binary) {
  4602. var scale = this.scale;
  4603. var skeletonData = new spine.SkeletonData();
  4604. skeletonData.name = "";
  4605. var input = new BinaryInput(binary);
  4606. var lowHash = input.readInt32();
  4607. var highHash = input.readInt32();
  4608. skeletonData.hash = highHash == 0 && lowHash == 0 ? null : highHash.toString(16) + lowHash.toString(16);
  4609. skeletonData.version = input.readString();
  4610. skeletonData.x = input.readFloat();
  4611. skeletonData.y = input.readFloat();
  4612. skeletonData.width = input.readFloat();
  4613. skeletonData.height = input.readFloat();
  4614. var nonessential = input.readBoolean();
  4615. if (nonessential) {
  4616. skeletonData.fps = input.readFloat();
  4617. skeletonData.imagesPath = input.readString();
  4618. skeletonData.audioPath = input.readString();
  4619. }
  4620. var n = 0;
  4621. n = input.readInt(true);
  4622. for (var i = 0; i < n; i++)
  4623. input.strings.push(input.readString());
  4624. n = input.readInt(true);
  4625. for (var i = 0; i < n; i++) {
  4626. var name_2 = input.readString();
  4627. var parent_2 = i == 0 ? null : skeletonData.bones[input.readInt(true)];
  4628. var data = new spine.BoneData(i, name_2, parent_2);
  4629. data.rotation = input.readFloat();
  4630. data.x = input.readFloat() * scale;
  4631. data.y = input.readFloat() * scale;
  4632. data.scaleX = input.readFloat();
  4633. data.scaleY = input.readFloat();
  4634. data.shearX = input.readFloat();
  4635. data.shearY = input.readFloat();
  4636. data.length = input.readFloat() * scale;
  4637. data.transformMode = input.readInt(true);
  4638. data.skinRequired = input.readBoolean();
  4639. if (nonessential)
  4640. spine.Color.rgba8888ToColor(data.color, input.readInt32());
  4641. skeletonData.bones.push(data);
  4642. }
  4643. n = input.readInt(true);
  4644. for (var i = 0; i < n; i++) {
  4645. var slotName = input.readString();
  4646. var boneData = skeletonData.bones[input.readInt(true)];
  4647. var data = new spine.SlotData(i, slotName, boneData);
  4648. spine.Color.rgba8888ToColor(data.color, input.readInt32());
  4649. var darkColor = input.readInt32();
  4650. if (darkColor != -1)
  4651. spine.Color.rgb888ToColor(data.darkColor = new spine.Color(), darkColor);
  4652. data.attachmentName = input.readStringRef();
  4653. data.blendMode = input.readInt(true);
  4654. skeletonData.slots.push(data);
  4655. }
  4656. n = input.readInt(true);
  4657. for (var i = 0, nn = void 0; i < n; i++) {
  4658. var data = new spine.IkConstraintData(input.readString());
  4659. data.order = input.readInt(true);
  4660. data.skinRequired = input.readBoolean();
  4661. nn = input.readInt(true);
  4662. for (var ii = 0; ii < nn; ii++)
  4663. data.bones.push(skeletonData.bones[input.readInt(true)]);
  4664. data.target = skeletonData.bones[input.readInt(true)];
  4665. data.mix = input.readFloat();
  4666. data.softness = input.readFloat() * scale;
  4667. data.bendDirection = input.readByte();
  4668. data.compress = input.readBoolean();
  4669. data.stretch = input.readBoolean();
  4670. data.uniform = input.readBoolean();
  4671. skeletonData.ikConstraints.push(data);
  4672. }
  4673. n = input.readInt(true);
  4674. for (var i = 0, nn = void 0; i < n; i++) {
  4675. var data = new spine.TransformConstraintData(input.readString());
  4676. data.order = input.readInt(true);
  4677. data.skinRequired = input.readBoolean();
  4678. nn = input.readInt(true);
  4679. for (var ii = 0; ii < nn; ii++)
  4680. data.bones.push(skeletonData.bones[input.readInt(true)]);
  4681. data.target = skeletonData.bones[input.readInt(true)];
  4682. data.local = input.readBoolean();
  4683. data.relative = input.readBoolean();
  4684. data.offsetRotation = input.readFloat();
  4685. data.offsetX = input.readFloat() * scale;
  4686. data.offsetY = input.readFloat() * scale;
  4687. data.offsetScaleX = input.readFloat();
  4688. data.offsetScaleY = input.readFloat();
  4689. data.offsetShearY = input.readFloat();
  4690. data.mixRotate = input.readFloat();
  4691. data.mixX = input.readFloat();
  4692. data.mixY = input.readFloat();
  4693. data.mixScaleX = input.readFloat();
  4694. data.mixScaleY = input.readFloat();
  4695. data.mixShearY = input.readFloat();
  4696. skeletonData.transformConstraints.push(data);
  4697. }
  4698. n = input.readInt(true);
  4699. for (var i = 0, nn = void 0; i < n; i++) {
  4700. var data = new spine.PathConstraintData(input.readString());
  4701. data.order = input.readInt(true);
  4702. data.skinRequired = input.readBoolean();
  4703. nn = input.readInt(true);
  4704. for (var ii = 0; ii < nn; ii++)
  4705. data.bones.push(skeletonData.bones[input.readInt(true)]);
  4706. data.target = skeletonData.slots[input.readInt(true)];
  4707. data.positionMode = input.readInt(true);
  4708. data.spacingMode = input.readInt(true);
  4709. data.rotateMode = input.readInt(true);
  4710. data.offsetRotation = input.readFloat();
  4711. data.position = input.readFloat();
  4712. if (data.positionMode == spine.PositionMode.Fixed)
  4713. data.position *= scale;
  4714. data.spacing = input.readFloat();
  4715. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4716. data.spacing *= scale;
  4717. data.mixRotate = input.readFloat();
  4718. data.mixX = input.readFloat();
  4719. data.mixY = input.readFloat();
  4720. skeletonData.pathConstraints.push(data);
  4721. }
  4722. var defaultSkin = this.readSkin(input, skeletonData, true, nonessential);
  4723. if (defaultSkin) {
  4724. skeletonData.defaultSkin = defaultSkin;
  4725. skeletonData.skins.push(defaultSkin);
  4726. }
  4727. {
  4728. var i = skeletonData.skins.length;
  4729. spine.Utils.setArraySize(skeletonData.skins, n = i + input.readInt(true));
  4730. for (; i < n; i++)
  4731. skeletonData.skins[i] = this.readSkin(input, skeletonData, false, nonessential);
  4732. }
  4733. n = this.linkedMeshes.length;
  4734. for (var i = 0; i < n; i++) {
  4735. var linkedMesh = this.linkedMeshes[i];
  4736. var skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  4737. var parent_3 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  4738. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent_3 : linkedMesh.mesh;
  4739. linkedMesh.mesh.setParentMesh(parent_3);
  4740. linkedMesh.mesh.updateUVs();
  4741. }
  4742. this.linkedMeshes.length = 0;
  4743. n = input.readInt(true);
  4744. for (var i = 0; i < n; i++) {
  4745. var data = new spine.EventData(input.readStringRef());
  4746. data.intValue = input.readInt(false);
  4747. data.floatValue = input.readFloat();
  4748. data.stringValue = input.readString();
  4749. data.audioPath = input.readString();
  4750. if (data.audioPath) {
  4751. data.volume = input.readFloat();
  4752. data.balance = input.readFloat();
  4753. }
  4754. skeletonData.events.push(data);
  4755. }
  4756. n = input.readInt(true);
  4757. for (var i = 0; i < n; i++)
  4758. skeletonData.animations.push(this.readAnimation(input, input.readString(), skeletonData));
  4759. return skeletonData;
  4760. };
  4761. SkeletonBinary.prototype.readSkin = function (input, skeletonData, defaultSkin, nonessential) {
  4762. var skin = null;
  4763. var slotCount = 0;
  4764. if (defaultSkin) {
  4765. slotCount = input.readInt(true);
  4766. if (slotCount == 0)
  4767. return null;
  4768. skin = new spine.Skin("default");
  4769. }
  4770. else {
  4771. skin = new spine.Skin(input.readStringRef());
  4772. skin.bones.length = input.readInt(true);
  4773. for (var i = 0, n = skin.bones.length; i < n; i++)
  4774. skin.bones[i] = skeletonData.bones[input.readInt(true)];
  4775. for (var i = 0, n = input.readInt(true); i < n; i++)
  4776. skin.constraints.push(skeletonData.ikConstraints[input.readInt(true)]);
  4777. for (var i = 0, n = input.readInt(true); i < n; i++)
  4778. skin.constraints.push(skeletonData.transformConstraints[input.readInt(true)]);
  4779. for (var i = 0, n = input.readInt(true); i < n; i++)
  4780. skin.constraints.push(skeletonData.pathConstraints[input.readInt(true)]);
  4781. slotCount = input.readInt(true);
  4782. }
  4783. for (var i = 0; i < slotCount; i++) {
  4784. var slotIndex = input.readInt(true);
  4785. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  4786. var name_3 = input.readStringRef();
  4787. var attachment = this.readAttachment(input, skeletonData, skin, slotIndex, name_3, nonessential);
  4788. if (attachment)
  4789. skin.setAttachment(slotIndex, name_3, attachment);
  4790. }
  4791. }
  4792. return skin;
  4793. };
  4794. SkeletonBinary.prototype.readAttachment = function (input, skeletonData, skin, slotIndex, attachmentName, nonessential) {
  4795. var scale = this.scale;
  4796. var name = input.readStringRef();
  4797. if (!name)
  4798. name = attachmentName;
  4799. switch (input.readByte()) {
  4800. case AttachmentType.Region: {
  4801. var path = input.readStringRef();
  4802. var rotation = input.readFloat();
  4803. var x = input.readFloat();
  4804. var y = input.readFloat();
  4805. var scaleX = input.readFloat();
  4806. var scaleY = input.readFloat();
  4807. var width = input.readFloat();
  4808. var height = input.readFloat();
  4809. var color = input.readInt32();
  4810. if (!path)
  4811. path = name;
  4812. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  4813. if (!region)
  4814. return null;
  4815. region.path = path;
  4816. region.x = x * scale;
  4817. region.y = y * scale;
  4818. region.scaleX = scaleX;
  4819. region.scaleY = scaleY;
  4820. region.rotation = rotation;
  4821. region.width = width * scale;
  4822. region.height = height * scale;
  4823. spine.Color.rgba8888ToColor(region.color, color);
  4824. region.updateOffset();
  4825. return region;
  4826. }
  4827. case AttachmentType.BoundingBox: {
  4828. var vertexCount = input.readInt(true);
  4829. var vertices = this.readVertices(input, vertexCount);
  4830. var color = nonessential ? input.readInt32() : 0;
  4831. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  4832. if (!box)
  4833. return null;
  4834. box.worldVerticesLength = vertexCount << 1;
  4835. box.vertices = vertices.vertices;
  4836. box.bones = vertices.bones;
  4837. if (nonessential)
  4838. spine.Color.rgba8888ToColor(box.color, color);
  4839. return box;
  4840. }
  4841. case AttachmentType.Mesh: {
  4842. var path = input.readStringRef();
  4843. var color = input.readInt32();
  4844. var vertexCount = input.readInt(true);
  4845. var uvs = this.readFloatArray(input, vertexCount << 1, 1);
  4846. var triangles = this.readShortArray(input);
  4847. var vertices = this.readVertices(input, vertexCount);
  4848. var hullLength = input.readInt(true);
  4849. var edges = null;
  4850. var width = 0, height = 0;
  4851. if (nonessential) {
  4852. edges = this.readShortArray(input);
  4853. width = input.readFloat();
  4854. height = input.readFloat();
  4855. }
  4856. if (!path)
  4857. path = name;
  4858. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4859. if (!mesh)
  4860. return null;
  4861. mesh.path = path;
  4862. spine.Color.rgba8888ToColor(mesh.color, color);
  4863. mesh.bones = vertices.bones;
  4864. mesh.vertices = vertices.vertices;
  4865. mesh.worldVerticesLength = vertexCount << 1;
  4866. mesh.triangles = triangles;
  4867. mesh.regionUVs = uvs;
  4868. mesh.updateUVs();
  4869. mesh.hullLength = hullLength << 1;
  4870. if (nonessential) {
  4871. mesh.edges = edges;
  4872. mesh.width = width * scale;
  4873. mesh.height = height * scale;
  4874. }
  4875. return mesh;
  4876. }
  4877. case AttachmentType.LinkedMesh: {
  4878. var path = input.readStringRef();
  4879. var color = input.readInt32();
  4880. var skinName = input.readStringRef();
  4881. var parent_4 = input.readStringRef();
  4882. var inheritDeform = input.readBoolean();
  4883. var width = 0, height = 0;
  4884. if (nonessential) {
  4885. width = input.readFloat();
  4886. height = input.readFloat();
  4887. }
  4888. if (!path)
  4889. path = name;
  4890. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  4891. if (!mesh)
  4892. return null;
  4893. mesh.path = path;
  4894. spine.Color.rgba8888ToColor(mesh.color, color);
  4895. if (nonessential) {
  4896. mesh.width = width * scale;
  4897. mesh.height = height * scale;
  4898. }
  4899. this.linkedMeshes.push(new LinkedMesh(mesh, skinName, slotIndex, parent_4, inheritDeform));
  4900. return mesh;
  4901. }
  4902. case AttachmentType.Path: {
  4903. var closed_1 = input.readBoolean();
  4904. var constantSpeed = input.readBoolean();
  4905. var vertexCount = input.readInt(true);
  4906. var vertices = this.readVertices(input, vertexCount);
  4907. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  4908. for (var i = 0, n = lengths.length; i < n; i++)
  4909. lengths[i] = input.readFloat() * scale;
  4910. var color = nonessential ? input.readInt32() : 0;
  4911. var path = this.attachmentLoader.newPathAttachment(skin, name);
  4912. if (!path)
  4913. return null;
  4914. path.closed = closed_1;
  4915. path.constantSpeed = constantSpeed;
  4916. path.worldVerticesLength = vertexCount << 1;
  4917. path.vertices = vertices.vertices;
  4918. path.bones = vertices.bones;
  4919. path.lengths = lengths;
  4920. if (nonessential)
  4921. spine.Color.rgba8888ToColor(path.color, color);
  4922. return path;
  4923. }
  4924. case AttachmentType.Point: {
  4925. var rotation = input.readFloat();
  4926. var x = input.readFloat();
  4927. var y = input.readFloat();
  4928. var color = nonessential ? input.readInt32() : 0;
  4929. var point = this.attachmentLoader.newPointAttachment(skin, name);
  4930. if (!point)
  4931. return null;
  4932. point.x = x * scale;
  4933. point.y = y * scale;
  4934. point.rotation = rotation;
  4935. if (nonessential)
  4936. spine.Color.rgba8888ToColor(point.color, color);
  4937. return point;
  4938. }
  4939. case AttachmentType.Clipping: {
  4940. var endSlotIndex = input.readInt(true);
  4941. var vertexCount = input.readInt(true);
  4942. var vertices = this.readVertices(input, vertexCount);
  4943. var color = nonessential ? input.readInt32() : 0;
  4944. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  4945. if (!clip)
  4946. return null;
  4947. clip.endSlot = skeletonData.slots[endSlotIndex];
  4948. clip.worldVerticesLength = vertexCount << 1;
  4949. clip.vertices = vertices.vertices;
  4950. clip.bones = vertices.bones;
  4951. if (nonessential)
  4952. spine.Color.rgba8888ToColor(clip.color, color);
  4953. return clip;
  4954. }
  4955. }
  4956. return null;
  4957. };
  4958. SkeletonBinary.prototype.readVertices = function (input, vertexCount) {
  4959. var scale = this.scale;
  4960. var verticesLength = vertexCount << 1;
  4961. var vertices = new Vertices();
  4962. if (!input.readBoolean()) {
  4963. vertices.vertices = this.readFloatArray(input, verticesLength, scale);
  4964. return vertices;
  4965. }
  4966. var weights = new Array();
  4967. var bonesArray = new Array();
  4968. for (var i = 0; i < vertexCount; i++) {
  4969. var boneCount = input.readInt(true);
  4970. bonesArray.push(boneCount);
  4971. for (var ii = 0; ii < boneCount; ii++) {
  4972. bonesArray.push(input.readInt(true));
  4973. weights.push(input.readFloat() * scale);
  4974. weights.push(input.readFloat() * scale);
  4975. weights.push(input.readFloat());
  4976. }
  4977. }
  4978. vertices.vertices = spine.Utils.toFloatArray(weights);
  4979. vertices.bones = bonesArray;
  4980. return vertices;
  4981. };
  4982. SkeletonBinary.prototype.readFloatArray = function (input, n, scale) {
  4983. var array = new Array(n);
  4984. if (scale == 1) {
  4985. for (var i = 0; i < n; i++)
  4986. array[i] = input.readFloat();
  4987. }
  4988. else {
  4989. for (var i = 0; i < n; i++)
  4990. array[i] = input.readFloat() * scale;
  4991. }
  4992. return array;
  4993. };
  4994. SkeletonBinary.prototype.readShortArray = function (input) {
  4995. var n = input.readInt(true);
  4996. var array = new Array(n);
  4997. for (var i = 0; i < n; i++)
  4998. array[i] = input.readShort();
  4999. return array;
  5000. };
  5001. SkeletonBinary.prototype.readAnimation = function (input, name, skeletonData) {
  5002. input.readInt(true);
  5003. var timelines = new Array();
  5004. var scale = this.scale;
  5005. var tempColor1 = new spine.Color();
  5006. var tempColor2 = new spine.Color();
  5007. for (var i = 0, n = input.readInt(true); i < n; i++) {
  5008. var slotIndex = input.readInt(true);
  5009. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  5010. var timelineType = input.readByte();
  5011. var frameCount = input.readInt(true);
  5012. var frameLast = frameCount - 1;
  5013. switch (timelineType) {
  5014. case SLOT_ATTACHMENT: {
  5015. var timeline = new spine.AttachmentTimeline(frameCount, slotIndex);
  5016. for (var frame = 0; frame < frameCount; frame++)
  5017. timeline.setFrame(frame, input.readFloat(), input.readStringRef());
  5018. timelines.push(timeline);
  5019. break;
  5020. }
  5021. case SLOT_RGBA: {
  5022. var bezierCount = input.readInt(true);
  5023. var timeline = new spine.RGBATimeline(frameCount, bezierCount, slotIndex);
  5024. var time = input.readFloat();
  5025. var r = input.readUnsignedByte() / 255.0;
  5026. var g = input.readUnsignedByte() / 255.0;
  5027. var b = input.readUnsignedByte() / 255.0;
  5028. var a = input.readUnsignedByte() / 255.0;
  5029. for (var frame = 0, bezier = 0;; frame++) {
  5030. timeline.setFrame(frame, time, r, g, b, a);
  5031. if (frame == frameLast)
  5032. break;
  5033. var time2 = input.readFloat();
  5034. var r2 = input.readUnsignedByte() / 255.0;
  5035. var g2 = input.readUnsignedByte() / 255.0;
  5036. var b2 = input.readUnsignedByte() / 255.0;
  5037. var a2 = input.readUnsignedByte() / 255.0;
  5038. switch (input.readByte()) {
  5039. case CURVE_STEPPED:
  5040. timeline.setStepped(frame);
  5041. break;
  5042. case CURVE_BEZIER:
  5043. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
  5044. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
  5045. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
  5046. setBezier(input, timeline, bezier++, frame, 3, time, time2, a, a2, 1);
  5047. }
  5048. time = time2;
  5049. r = r2;
  5050. g = g2;
  5051. b = b2;
  5052. a = a2;
  5053. }
  5054. timelines.push(timeline);
  5055. break;
  5056. }
  5057. case SLOT_RGB: {
  5058. var bezierCount = input.readInt(true);
  5059. var timeline = new spine.RGBTimeline(frameCount, bezierCount, slotIndex);
  5060. var time = input.readFloat();
  5061. var r = input.readUnsignedByte() / 255.0;
  5062. var g = input.readUnsignedByte() / 255.0;
  5063. var b = input.readUnsignedByte() / 255.0;
  5064. for (var frame = 0, bezier = 0;; frame++) {
  5065. timeline.setFrame(frame, time, r, g, b);
  5066. if (frame == frameLast)
  5067. break;
  5068. var time2 = input.readFloat();
  5069. var r2 = input.readUnsignedByte() / 255.0;
  5070. var g2 = input.readUnsignedByte() / 255.0;
  5071. var b2 = input.readUnsignedByte() / 255.0;
  5072. switch (input.readByte()) {
  5073. case CURVE_STEPPED:
  5074. timeline.setStepped(frame);
  5075. break;
  5076. case CURVE_BEZIER:
  5077. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, r2, 1);
  5078. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, g2, 1);
  5079. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, b2, 1);
  5080. }
  5081. time = time2;
  5082. r = r2;
  5083. g = g2;
  5084. b = b2;
  5085. }
  5086. timelines.push(timeline);
  5087. break;
  5088. }
  5089. case SLOT_RGBA2: {
  5090. var bezierCount = input.readInt(true);
  5091. var timeline = new spine.RGBA2Timeline(frameCount, bezierCount, slotIndex);
  5092. var time = input.readFloat();
  5093. var r = input.readUnsignedByte() / 255.0;
  5094. var g = input.readUnsignedByte() / 255.0;
  5095. var b = input.readUnsignedByte() / 255.0;
  5096. var a = input.readUnsignedByte() / 255.0;
  5097. var r2 = input.readUnsignedByte() / 255.0;
  5098. var g2 = input.readUnsignedByte() / 255.0;
  5099. var b2 = input.readUnsignedByte() / 255.0;
  5100. for (var frame = 0, bezier = 0;; frame++) {
  5101. timeline.setFrame(frame, time, r, g, b, a, r2, g2, b2);
  5102. if (frame == frameLast)
  5103. break;
  5104. var time2 = input.readFloat();
  5105. var nr = input.readUnsignedByte() / 255.0;
  5106. var ng = input.readUnsignedByte() / 255.0;
  5107. var nb = input.readUnsignedByte() / 255.0;
  5108. var na = input.readUnsignedByte() / 255.0;
  5109. var nr2 = input.readUnsignedByte() / 255.0;
  5110. var ng2 = input.readUnsignedByte() / 255.0;
  5111. var nb2 = input.readUnsignedByte() / 255.0;
  5112. switch (input.readByte()) {
  5113. case CURVE_STEPPED:
  5114. timeline.setStepped(frame);
  5115. break;
  5116. case CURVE_BEZIER:
  5117. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
  5118. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
  5119. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
  5120. setBezier(input, timeline, bezier++, frame, 3, time, time2, a, na, 1);
  5121. setBezier(input, timeline, bezier++, frame, 4, time, time2, r2, nr2, 1);
  5122. setBezier(input, timeline, bezier++, frame, 5, time, time2, g2, ng2, 1);
  5123. setBezier(input, timeline, bezier++, frame, 6, time, time2, b2, nb2, 1);
  5124. }
  5125. time = time2;
  5126. r = nr;
  5127. g = ng;
  5128. b = nb;
  5129. a = na;
  5130. r2 = nr2;
  5131. g2 = ng2;
  5132. b2 = nb2;
  5133. }
  5134. timelines.push(timeline);
  5135. break;
  5136. }
  5137. case SLOT_RGB2: {
  5138. var bezierCount = input.readInt(true);
  5139. var timeline = new spine.RGB2Timeline(frameCount, bezierCount, slotIndex);
  5140. var time = input.readFloat();
  5141. var r = input.readUnsignedByte() / 255.0;
  5142. var g = input.readUnsignedByte() / 255.0;
  5143. var b = input.readUnsignedByte() / 255.0;
  5144. var r2 = input.readUnsignedByte() / 255.0;
  5145. var g2 = input.readUnsignedByte() / 255.0;
  5146. var b2 = input.readUnsignedByte() / 255.0;
  5147. for (var frame = 0, bezier = 0;; frame++) {
  5148. timeline.setFrame(frame, time, r, g, b, r2, g2, b2);
  5149. if (frame == frameLast)
  5150. break;
  5151. var time2 = input.readFloat();
  5152. var nr = input.readUnsignedByte() / 255.0;
  5153. var ng = input.readUnsignedByte() / 255.0;
  5154. var nb = input.readUnsignedByte() / 255.0;
  5155. var nr2 = input.readUnsignedByte() / 255.0;
  5156. var ng2 = input.readUnsignedByte() / 255.0;
  5157. var nb2 = input.readUnsignedByte() / 255.0;
  5158. switch (input.readByte()) {
  5159. case CURVE_STEPPED:
  5160. timeline.setStepped(frame);
  5161. break;
  5162. case CURVE_BEZIER:
  5163. setBezier(input, timeline, bezier++, frame, 0, time, time2, r, nr, 1);
  5164. setBezier(input, timeline, bezier++, frame, 1, time, time2, g, ng, 1);
  5165. setBezier(input, timeline, bezier++, frame, 2, time, time2, b, nb, 1);
  5166. setBezier(input, timeline, bezier++, frame, 3, time, time2, r2, nr2, 1);
  5167. setBezier(input, timeline, bezier++, frame, 4, time, time2, g2, ng2, 1);
  5168. setBezier(input, timeline, bezier++, frame, 5, time, time2, b2, nb2, 1);
  5169. }
  5170. time = time2;
  5171. r = nr;
  5172. g = ng;
  5173. b = nb;
  5174. r2 = nr2;
  5175. g2 = ng2;
  5176. b2 = nb2;
  5177. }
  5178. timelines.push(timeline);
  5179. break;
  5180. }
  5181. case SLOT_ALPHA: {
  5182. var timeline = new spine.AlphaTimeline(frameCount, input.readInt(true), slotIndex);
  5183. var time = input.readFloat(), a = input.readUnsignedByte() / 255;
  5184. for (var frame = 0, bezier = 0;; frame++) {
  5185. timeline.setFrame(frame, time, a);
  5186. if (frame == frameLast)
  5187. break;
  5188. var time2 = input.readFloat();
  5189. var a2 = input.readUnsignedByte() / 255;
  5190. switch (input.readByte()) {
  5191. case CURVE_STEPPED:
  5192. timeline.setStepped(frame);
  5193. break;
  5194. case CURVE_BEZIER:
  5195. setBezier(input, timeline, bezier++, frame, 0, time, time2, a, a2, 1);
  5196. }
  5197. time = time2;
  5198. a = a2;
  5199. }
  5200. timelines.push(timeline);
  5201. break;
  5202. }
  5203. }
  5204. }
  5205. }
  5206. for (var i = 0, n = input.readInt(true); i < n; i++) {
  5207. var boneIndex = input.readInt(true);
  5208. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  5209. var type = input.readByte(), frameCount = input.readInt(true), bezierCount = input.readInt(true);
  5210. switch (type) {
  5211. case BONE_ROTATE:
  5212. timelines.push(readTimeline1(input, new spine.RotateTimeline(frameCount, bezierCount, boneIndex), 1));
  5213. break;
  5214. case BONE_TRANSLATE:
  5215. timelines.push(readTimeline2(input, new spine.TranslateTimeline(frameCount, bezierCount, boneIndex), scale));
  5216. break;
  5217. case BONE_TRANSLATEX:
  5218. timelines.push(readTimeline1(input, new spine.TranslateXTimeline(frameCount, bezierCount, boneIndex), scale));
  5219. break;
  5220. case BONE_TRANSLATEY:
  5221. timelines.push(readTimeline1(input, new spine.TranslateYTimeline(frameCount, bezierCount, boneIndex), scale));
  5222. break;
  5223. case BONE_SCALE:
  5224. timelines.push(readTimeline2(input, new spine.ScaleTimeline(frameCount, bezierCount, boneIndex), 1));
  5225. break;
  5226. case BONE_SCALEX:
  5227. timelines.push(readTimeline1(input, new spine.ScaleXTimeline(frameCount, bezierCount, boneIndex), 1));
  5228. break;
  5229. case BONE_SCALEY:
  5230. timelines.push(readTimeline1(input, new spine.ScaleYTimeline(frameCount, bezierCount, boneIndex), 1));
  5231. break;
  5232. case BONE_SHEAR:
  5233. timelines.push(readTimeline2(input, new spine.ShearTimeline(frameCount, bezierCount, boneIndex), 1));
  5234. break;
  5235. case BONE_SHEARX:
  5236. timelines.push(readTimeline1(input, new spine.ShearXTimeline(frameCount, bezierCount, boneIndex), 1));
  5237. break;
  5238. case BONE_SHEARY:
  5239. timelines.push(readTimeline1(input, new spine.ShearYTimeline(frameCount, bezierCount, boneIndex), 1));
  5240. }
  5241. }
  5242. }
  5243. for (var i = 0, n = input.readInt(true); i < n; i++) {
  5244. var index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1;
  5245. var timeline = new spine.IkConstraintTimeline(frameCount, input.readInt(true), index);
  5246. var time = input.readFloat(), mix = input.readFloat(), softness = input.readFloat() * scale;
  5247. for (var frame = 0, bezier = 0;; frame++) {
  5248. timeline.setFrame(frame, time, mix, softness, input.readByte(), input.readBoolean(), input.readBoolean());
  5249. if (frame == frameLast)
  5250. break;
  5251. var time2 = input.readFloat(), mix2 = input.readFloat(), softness2 = input.readFloat() * scale;
  5252. switch (input.readByte()) {
  5253. case CURVE_STEPPED:
  5254. timeline.setStepped(frame);
  5255. break;
  5256. case CURVE_BEZIER:
  5257. setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1);
  5258. setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale);
  5259. }
  5260. time = time2;
  5261. mix = mix2;
  5262. softness = softness2;
  5263. }
  5264. timelines.push(timeline);
  5265. }
  5266. for (var i = 0, n = input.readInt(true); i < n; i++) {
  5267. var index = input.readInt(true), frameCount = input.readInt(true), frameLast = frameCount - 1;
  5268. var timeline = new spine.TransformConstraintTimeline(frameCount, input.readInt(true), index);
  5269. var time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat(), mixScaleX = input.readFloat(), mixScaleY = input.readFloat(), mixShearY = input.readFloat();
  5270. for (var frame = 0, bezier = 0;; frame++) {
  5271. timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
  5272. if (frame == frameLast)
  5273. break;
  5274. var time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat(), mixScaleX2 = input.readFloat(), mixScaleY2 = input.readFloat(), mixShearY2 = input.readFloat();
  5275. switch (input.readByte()) {
  5276. case CURVE_STEPPED:
  5277. timeline.setStepped(frame);
  5278. break;
  5279. case CURVE_BEZIER:
  5280. setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  5281. setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
  5282. setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
  5283. setBezier(input, timeline, bezier++, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
  5284. setBezier(input, timeline, bezier++, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
  5285. setBezier(input, timeline, bezier++, frame, 5, time, time2, mixShearY, mixShearY2, 1);
  5286. }
  5287. time = time2;
  5288. mixRotate = mixRotate2;
  5289. mixX = mixX2;
  5290. mixY = mixY2;
  5291. mixScaleX = mixScaleX2;
  5292. mixScaleY = mixScaleY2;
  5293. mixShearY = mixShearY2;
  5294. }
  5295. timelines.push(timeline);
  5296. }
  5297. for (var i = 0, n = input.readInt(true); i < n; i++) {
  5298. var index = input.readInt(true);
  5299. var data = skeletonData.pathConstraints[index];
  5300. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  5301. switch (input.readByte()) {
  5302. case PATH_POSITION:
  5303. timelines
  5304. .push(readTimeline1(input, new spine.PathConstraintPositionTimeline(input.readInt(true), input.readInt(true), index), data.positionMode == spine.PositionMode.Fixed ? scale : 1));
  5305. break;
  5306. case PATH_SPACING:
  5307. timelines
  5308. .push(readTimeline1(input, new spine.PathConstraintSpacingTimeline(input.readInt(true), input.readInt(true), index), data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed ? scale : 1));
  5309. break;
  5310. case PATH_MIX:
  5311. var timeline = new spine.PathConstraintMixTimeline(input.readInt(true), input.readInt(true), index);
  5312. var time = input.readFloat(), mixRotate = input.readFloat(), mixX = input.readFloat(), mixY = input.readFloat();
  5313. for (var frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
  5314. timeline.setFrame(frame, time, mixRotate, mixX, mixY);
  5315. if (frame == frameLast)
  5316. break;
  5317. var time2 = input.readFloat(), mixRotate2 = input.readFloat(), mixX2 = input.readFloat(), mixY2 = input.readFloat();
  5318. switch (input.readByte()) {
  5319. case CURVE_STEPPED:
  5320. timeline.setStepped(frame);
  5321. break;
  5322. case CURVE_BEZIER:
  5323. setBezier(input, timeline, bezier++, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  5324. setBezier(input, timeline, bezier++, frame, 1, time, time2, mixX, mixX2, 1);
  5325. setBezier(input, timeline, bezier++, frame, 2, time, time2, mixY, mixY2, 1);
  5326. }
  5327. time = time2;
  5328. mixRotate = mixRotate2;
  5329. mixX = mixX2;
  5330. mixY = mixY2;
  5331. }
  5332. timelines.push(timeline);
  5333. }
  5334. }
  5335. }
  5336. for (var i = 0, n = input.readInt(true); i < n; i++) {
  5337. var skin = skeletonData.skins[input.readInt(true)];
  5338. for (var ii = 0, nn = input.readInt(true); ii < nn; ii++) {
  5339. var slotIndex = input.readInt(true);
  5340. for (var iii = 0, nnn = input.readInt(true); iii < nnn; iii++) {
  5341. var attachmentName = input.readStringRef();
  5342. var attachment = skin.getAttachment(slotIndex, attachmentName);
  5343. var weighted = attachment.bones;
  5344. var vertices = attachment.vertices;
  5345. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  5346. var frameCount = input.readInt(true);
  5347. var frameLast = frameCount - 1;
  5348. var bezierCount = input.readInt(true);
  5349. var timeline = new spine.DeformTimeline(frameCount, bezierCount, slotIndex, attachment);
  5350. var time = input.readFloat();
  5351. for (var frame = 0, bezier = 0;; frame++) {
  5352. var deform = void 0;
  5353. var end = input.readInt(true);
  5354. if (end == 0)
  5355. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  5356. else {
  5357. deform = spine.Utils.newFloatArray(deformLength);
  5358. var start = input.readInt(true);
  5359. end += start;
  5360. if (scale == 1) {
  5361. for (var v = start; v < end; v++)
  5362. deform[v] = input.readFloat();
  5363. }
  5364. else {
  5365. for (var v = start; v < end; v++)
  5366. deform[v] = input.readFloat() * scale;
  5367. }
  5368. if (!weighted) {
  5369. for (var v = 0, vn = deform.length; v < vn; v++)
  5370. deform[v] += vertices[v];
  5371. }
  5372. }
  5373. timeline.setFrame(frame, time, deform);
  5374. if (frame == frameLast)
  5375. break;
  5376. var time2 = input.readFloat();
  5377. switch (input.readByte()) {
  5378. case CURVE_STEPPED:
  5379. timeline.setStepped(frame);
  5380. break;
  5381. case CURVE_BEZIER:
  5382. setBezier(input, timeline, bezier++, frame, 0, time, time2, 0, 1, 1);
  5383. }
  5384. time = time2;
  5385. }
  5386. timelines.push(timeline);
  5387. }
  5388. }
  5389. }
  5390. var drawOrderCount = input.readInt(true);
  5391. if (drawOrderCount > 0) {
  5392. var timeline = new spine.DrawOrderTimeline(drawOrderCount);
  5393. var slotCount = skeletonData.slots.length;
  5394. for (var i = 0; i < drawOrderCount; i++) {
  5395. var time = input.readFloat();
  5396. var offsetCount = input.readInt(true);
  5397. var drawOrder = spine.Utils.newArray(slotCount, 0);
  5398. for (var ii = slotCount - 1; ii >= 0; ii--)
  5399. drawOrder[ii] = -1;
  5400. var unchanged = spine.Utils.newArray(slotCount - offsetCount, 0);
  5401. var originalIndex = 0, unchangedIndex = 0;
  5402. for (var ii = 0; ii < offsetCount; ii++) {
  5403. var slotIndex = input.readInt(true);
  5404. while (originalIndex != slotIndex)
  5405. unchanged[unchangedIndex++] = originalIndex++;
  5406. drawOrder[originalIndex + input.readInt(true)] = originalIndex++;
  5407. }
  5408. while (originalIndex < slotCount)
  5409. unchanged[unchangedIndex++] = originalIndex++;
  5410. for (var ii = slotCount - 1; ii >= 0; ii--)
  5411. if (drawOrder[ii] == -1)
  5412. drawOrder[ii] = unchanged[--unchangedIndex];
  5413. timeline.setFrame(i, time, drawOrder);
  5414. }
  5415. timelines.push(timeline);
  5416. }
  5417. var eventCount = input.readInt(true);
  5418. if (eventCount > 0) {
  5419. var timeline = new spine.EventTimeline(eventCount);
  5420. for (var i = 0; i < eventCount; i++) {
  5421. var time = input.readFloat();
  5422. var eventData = skeletonData.events[input.readInt(true)];
  5423. var event_4 = new spine.Event(time, eventData);
  5424. event_4.intValue = input.readInt(false);
  5425. event_4.floatValue = input.readFloat();
  5426. event_4.stringValue = input.readBoolean() ? input.readString() : eventData.stringValue;
  5427. if (event_4.data.audioPath) {
  5428. event_4.volume = input.readFloat();
  5429. event_4.balance = input.readFloat();
  5430. }
  5431. timeline.setFrame(i, event_4);
  5432. }
  5433. timelines.push(timeline);
  5434. }
  5435. var duration = 0;
  5436. for (var i = 0, n = timelines.length; i < n; i++)
  5437. duration = Math.max(duration, timelines[i].getDuration());
  5438. return new spine.Animation(name, timelines, duration);
  5439. };
  5440. return SkeletonBinary;
  5441. }());
  5442. spine.SkeletonBinary = SkeletonBinary;
  5443. var BinaryInput = (function () {
  5444. function BinaryInput(data, strings, index, buffer) {
  5445. if (strings === void 0) { strings = new Array(); }
  5446. if (index === void 0) { index = 0; }
  5447. if (buffer === void 0) { buffer = new DataView(data.buffer); }
  5448. this.strings = strings;
  5449. this.index = index;
  5450. this.buffer = buffer;
  5451. }
  5452. BinaryInput.prototype.readByte = function () {
  5453. return this.buffer.getInt8(this.index++);
  5454. };
  5455. BinaryInput.prototype.readUnsignedByte = function () {
  5456. return this.buffer.getUint8(this.index++);
  5457. };
  5458. BinaryInput.prototype.readShort = function () {
  5459. var value = this.buffer.getInt16(this.index);
  5460. this.index += 2;
  5461. return value;
  5462. };
  5463. BinaryInput.prototype.readInt32 = function () {
  5464. var value = this.buffer.getInt32(this.index);
  5465. this.index += 4;
  5466. return value;
  5467. };
  5468. BinaryInput.prototype.readInt = function (optimizePositive) {
  5469. var b = this.readByte();
  5470. var result = b & 0x7F;
  5471. if ((b & 0x80) != 0) {
  5472. b = this.readByte();
  5473. result |= (b & 0x7F) << 7;
  5474. if ((b & 0x80) != 0) {
  5475. b = this.readByte();
  5476. result |= (b & 0x7F) << 14;
  5477. if ((b & 0x80) != 0) {
  5478. b = this.readByte();
  5479. result |= (b & 0x7F) << 21;
  5480. if ((b & 0x80) != 0) {
  5481. b = this.readByte();
  5482. result |= (b & 0x7F) << 28;
  5483. }
  5484. }
  5485. }
  5486. }
  5487. return optimizePositive ? result : ((result >>> 1) ^ -(result & 1));
  5488. };
  5489. BinaryInput.prototype.readStringRef = function () {
  5490. var index = this.readInt(true);
  5491. return index == 0 ? null : this.strings[index - 1];
  5492. };
  5493. BinaryInput.prototype.readString = function () {
  5494. var byteCount = this.readInt(true);
  5495. switch (byteCount) {
  5496. case 0:
  5497. return null;
  5498. case 1:
  5499. return "";
  5500. }
  5501. byteCount--;
  5502. var chars = "";
  5503. var charCount = 0;
  5504. for (var i = 0; i < byteCount;) {
  5505. var b = this.readByte();
  5506. switch (b >> 4) {
  5507. case 12:
  5508. case 13:
  5509. chars += String.fromCharCode(((b & 0x1F) << 6 | this.readByte() & 0x3F));
  5510. i += 2;
  5511. break;
  5512. case 14:
  5513. chars += String.fromCharCode(((b & 0x0F) << 12 | (this.readByte() & 0x3F) << 6 | this.readByte() & 0x3F));
  5514. i += 3;
  5515. break;
  5516. default:
  5517. chars += String.fromCharCode(b);
  5518. i++;
  5519. }
  5520. }
  5521. return chars;
  5522. };
  5523. BinaryInput.prototype.readFloat = function () {
  5524. var value = this.buffer.getFloat32(this.index);
  5525. this.index += 4;
  5526. return value;
  5527. };
  5528. BinaryInput.prototype.readBoolean = function () {
  5529. return this.readByte() != 0;
  5530. };
  5531. return BinaryInput;
  5532. }());
  5533. var LinkedMesh = (function () {
  5534. function LinkedMesh(mesh, skin, slotIndex, parent, inheritDeform) {
  5535. this.mesh = mesh;
  5536. this.skin = skin;
  5537. this.slotIndex = slotIndex;
  5538. this.parent = parent;
  5539. this.inheritDeform = inheritDeform;
  5540. }
  5541. return LinkedMesh;
  5542. }());
  5543. var Vertices = (function () {
  5544. function Vertices(bones, vertices) {
  5545. if (bones === void 0) { bones = null; }
  5546. if (vertices === void 0) { vertices = null; }
  5547. this.bones = bones;
  5548. this.vertices = vertices;
  5549. }
  5550. return Vertices;
  5551. }());
  5552. var AttachmentType;
  5553. (function (AttachmentType) {
  5554. AttachmentType[AttachmentType["Region"] = 0] = "Region";
  5555. AttachmentType[AttachmentType["BoundingBox"] = 1] = "BoundingBox";
  5556. AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
  5557. AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
  5558. AttachmentType[AttachmentType["Path"] = 4] = "Path";
  5559. AttachmentType[AttachmentType["Point"] = 5] = "Point";
  5560. AttachmentType[AttachmentType["Clipping"] = 6] = "Clipping";
  5561. })(AttachmentType || (AttachmentType = {}));
  5562. function readTimeline1(input, timeline, scale) {
  5563. var time = input.readFloat(), value = input.readFloat() * scale;
  5564. for (var frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
  5565. timeline.setFrame(frame, time, value);
  5566. if (frame == frameLast)
  5567. break;
  5568. var time2 = input.readFloat(), value2 = input.readFloat() * scale;
  5569. switch (input.readByte()) {
  5570. case CURVE_STEPPED:
  5571. timeline.setStepped(frame);
  5572. break;
  5573. case CURVE_BEZIER:
  5574. setBezier(input, timeline, bezier++, frame, 0, time, time2, value, value2, 1);
  5575. }
  5576. time = time2;
  5577. value = value2;
  5578. }
  5579. return timeline;
  5580. }
  5581. function readTimeline2(input, timeline, scale) {
  5582. var time = input.readFloat(), value1 = input.readFloat() * scale, value2 = input.readFloat() * scale;
  5583. for (var frame = 0, bezier = 0, frameLast = timeline.getFrameCount() - 1;; frame++) {
  5584. timeline.setFrame(frame, time, value1, value2);
  5585. if (frame == frameLast)
  5586. break;
  5587. var time2 = input.readFloat(), nvalue1 = input.readFloat() * scale, nvalue2 = input.readFloat() * scale;
  5588. switch (input.readByte()) {
  5589. case CURVE_STEPPED:
  5590. timeline.setStepped(frame);
  5591. break;
  5592. case CURVE_BEZIER:
  5593. setBezier(input, timeline, bezier++, frame, 0, time, time2, value1, nvalue1, scale);
  5594. setBezier(input, timeline, bezier++, frame, 1, time, time2, value2, nvalue2, scale);
  5595. }
  5596. time = time2;
  5597. value1 = nvalue1;
  5598. value2 = nvalue2;
  5599. }
  5600. return timeline;
  5601. }
  5602. function setBezier(input, timeline, bezier, frame, value, time1, time2, value1, value2, scale) {
  5603. timeline.setBezier(bezier, frame, value, time1, value1, input.readFloat(), input.readFloat() * scale, input.readFloat(), input.readFloat() * scale, time2, value2);
  5604. }
  5605. var BONE_ROTATE = 0;
  5606. var BONE_TRANSLATE = 1;
  5607. var BONE_TRANSLATEX = 2;
  5608. var BONE_TRANSLATEY = 3;
  5609. var BONE_SCALE = 4;
  5610. var BONE_SCALEX = 5;
  5611. var BONE_SCALEY = 6;
  5612. var BONE_SHEAR = 7;
  5613. var BONE_SHEARX = 8;
  5614. var BONE_SHEARY = 9;
  5615. var SLOT_ATTACHMENT = 0;
  5616. var SLOT_RGBA = 1;
  5617. var SLOT_RGB = 2;
  5618. var SLOT_RGBA2 = 3;
  5619. var SLOT_RGB2 = 4;
  5620. var SLOT_ALPHA = 5;
  5621. var PATH_POSITION = 0;
  5622. var PATH_SPACING = 1;
  5623. var PATH_MIX = 2;
  5624. var CURVE_LINEAR = 0;
  5625. var CURVE_STEPPED = 1;
  5626. var CURVE_BEZIER = 2;
  5627. })(spine || (spine = {}));
  5628. var spine;
  5629. (function (spine) {
  5630. var SkeletonBounds = (function () {
  5631. function SkeletonBounds() {
  5632. this.minX = 0;
  5633. this.minY = 0;
  5634. this.maxX = 0;
  5635. this.maxY = 0;
  5636. this.boundingBoxes = new Array();
  5637. this.polygons = new Array();
  5638. this.polygonPool = new spine.Pool(function () {
  5639. return spine.Utils.newFloatArray(16);
  5640. });
  5641. }
  5642. SkeletonBounds.prototype.update = function (skeleton, updateAabb) {
  5643. if (!skeleton)
  5644. throw new Error("skeleton cannot be null.");
  5645. var boundingBoxes = this.boundingBoxes;
  5646. var polygons = this.polygons;
  5647. var polygonPool = this.polygonPool;
  5648. var slots = skeleton.slots;
  5649. var slotCount = slots.length;
  5650. boundingBoxes.length = 0;
  5651. polygonPool.freeAll(polygons);
  5652. polygons.length = 0;
  5653. for (var i = 0; i < slotCount; i++) {
  5654. var slot = slots[i];
  5655. if (!slot.bone.active)
  5656. continue;
  5657. var attachment = slot.getAttachment();
  5658. if (attachment instanceof spine.BoundingBoxAttachment) {
  5659. var boundingBox = attachment;
  5660. boundingBoxes.push(boundingBox);
  5661. var polygon = polygonPool.obtain();
  5662. if (polygon.length != boundingBox.worldVerticesLength) {
  5663. polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength);
  5664. }
  5665. polygons.push(polygon);
  5666. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  5667. }
  5668. }
  5669. if (updateAabb) {
  5670. this.aabbCompute();
  5671. }
  5672. else {
  5673. this.minX = Number.POSITIVE_INFINITY;
  5674. this.minY = Number.POSITIVE_INFINITY;
  5675. this.maxX = Number.NEGATIVE_INFINITY;
  5676. this.maxY = Number.NEGATIVE_INFINITY;
  5677. }
  5678. };
  5679. SkeletonBounds.prototype.aabbCompute = function () {
  5680. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  5681. var polygons = this.polygons;
  5682. for (var i = 0, n = polygons.length; i < n; i++) {
  5683. var polygon = polygons[i];
  5684. var vertices = polygon;
  5685. for (var ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  5686. var x = vertices[ii];
  5687. var y = vertices[ii + 1];
  5688. minX = Math.min(minX, x);
  5689. minY = Math.min(minY, y);
  5690. maxX = Math.max(maxX, x);
  5691. maxY = Math.max(maxY, y);
  5692. }
  5693. }
  5694. this.minX = minX;
  5695. this.minY = minY;
  5696. this.maxX = maxX;
  5697. this.maxY = maxY;
  5698. };
  5699. SkeletonBounds.prototype.aabbContainsPoint = function (x, y) {
  5700. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  5701. };
  5702. SkeletonBounds.prototype.aabbIntersectsSegment = function (x1, y1, x2, y2) {
  5703. var minX = this.minX;
  5704. var minY = this.minY;
  5705. var maxX = this.maxX;
  5706. var maxY = this.maxY;
  5707. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  5708. return false;
  5709. var m = (y2 - y1) / (x2 - x1);
  5710. var y = m * (minX - x1) + y1;
  5711. if (y > minY && y < maxY)
  5712. return true;
  5713. y = m * (maxX - x1) + y1;
  5714. if (y > minY && y < maxY)
  5715. return true;
  5716. var x = (minY - y1) / m + x1;
  5717. if (x > minX && x < maxX)
  5718. return true;
  5719. x = (maxY - y1) / m + x1;
  5720. if (x > minX && x < maxX)
  5721. return true;
  5722. return false;
  5723. };
  5724. SkeletonBounds.prototype.aabbIntersectsSkeleton = function (bounds) {
  5725. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  5726. };
  5727. SkeletonBounds.prototype.containsPoint = function (x, y) {
  5728. var polygons = this.polygons;
  5729. for (var i = 0, n = polygons.length; i < n; i++)
  5730. if (this.containsPointPolygon(polygons[i], x, y))
  5731. return this.boundingBoxes[i];
  5732. return null;
  5733. };
  5734. SkeletonBounds.prototype.containsPointPolygon = function (polygon, x, y) {
  5735. var vertices = polygon;
  5736. var nn = polygon.length;
  5737. var prevIndex = nn - 2;
  5738. var inside = false;
  5739. for (var ii = 0; ii < nn; ii += 2) {
  5740. var vertexY = vertices[ii + 1];
  5741. var prevY = vertices[prevIndex + 1];
  5742. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  5743. var vertexX = vertices[ii];
  5744. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x)
  5745. inside = !inside;
  5746. }
  5747. prevIndex = ii;
  5748. }
  5749. return inside;
  5750. };
  5751. SkeletonBounds.prototype.intersectsSegment = function (x1, y1, x2, y2) {
  5752. var polygons = this.polygons;
  5753. for (var i = 0, n = polygons.length; i < n; i++)
  5754. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2))
  5755. return this.boundingBoxes[i];
  5756. return null;
  5757. };
  5758. SkeletonBounds.prototype.intersectsSegmentPolygon = function (polygon, x1, y1, x2, y2) {
  5759. var vertices = polygon;
  5760. var nn = polygon.length;
  5761. var width12 = x1 - x2, height12 = y1 - y2;
  5762. var det1 = x1 * y2 - y1 * x2;
  5763. var x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  5764. for (var ii = 0; ii < nn; ii += 2) {
  5765. var x4 = vertices[ii], y4 = vertices[ii + 1];
  5766. var det2 = x3 * y4 - y3 * x4;
  5767. var width34 = x3 - x4, height34 = y3 - y4;
  5768. var det3 = width12 * height34 - height12 * width34;
  5769. var x = (det1 * width34 - width12 * det2) / det3;
  5770. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  5771. var y = (det1 * height34 - height12 * det2) / det3;
  5772. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1)))
  5773. return true;
  5774. }
  5775. x3 = x4;
  5776. y3 = y4;
  5777. }
  5778. return false;
  5779. };
  5780. SkeletonBounds.prototype.getPolygon = function (boundingBox) {
  5781. if (!boundingBox)
  5782. throw new Error("boundingBox cannot be null.");
  5783. var index = this.boundingBoxes.indexOf(boundingBox);
  5784. return index == -1 ? null : this.polygons[index];
  5785. };
  5786. SkeletonBounds.prototype.getWidth = function () {
  5787. return this.maxX - this.minX;
  5788. };
  5789. SkeletonBounds.prototype.getHeight = function () {
  5790. return this.maxY - this.minY;
  5791. };
  5792. return SkeletonBounds;
  5793. }());
  5794. spine.SkeletonBounds = SkeletonBounds;
  5795. })(spine || (spine = {}));
  5796. var spine;
  5797. (function (spine) {
  5798. var SkeletonClipping = (function () {
  5799. function SkeletonClipping() {
  5800. this.triangulator = new spine.Triangulator();
  5801. this.clippingPolygon = new Array();
  5802. this.clipOutput = new Array();
  5803. this.clippedVertices = new Array();
  5804. this.clippedTriangles = new Array();
  5805. this.scratch = new Array();
  5806. }
  5807. SkeletonClipping.prototype.clipStart = function (slot, clip) {
  5808. if (this.clipAttachment)
  5809. return 0;
  5810. this.clipAttachment = clip;
  5811. var n = clip.worldVerticesLength;
  5812. var vertices = spine.Utils.setArraySize(this.clippingPolygon, n);
  5813. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  5814. var clippingPolygon = this.clippingPolygon;
  5815. SkeletonClipping.makeClockwise(clippingPolygon);
  5816. var clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon));
  5817. for (var i = 0, n_2 = clippingPolygons.length; i < n_2; i++) {
  5818. var polygon = clippingPolygons[i];
  5819. SkeletonClipping.makeClockwise(polygon);
  5820. polygon.push(polygon[0]);
  5821. polygon.push(polygon[1]);
  5822. }
  5823. return clippingPolygons.length;
  5824. };
  5825. SkeletonClipping.prototype.clipEndWithSlot = function (slot) {
  5826. if (this.clipAttachment && this.clipAttachment.endSlot == slot.data)
  5827. this.clipEnd();
  5828. };
  5829. SkeletonClipping.prototype.clipEnd = function () {
  5830. if (!this.clipAttachment)
  5831. return;
  5832. this.clipAttachment = null;
  5833. this.clippingPolygons = null;
  5834. this.clippedVertices.length = 0;
  5835. this.clippedTriangles.length = 0;
  5836. this.clippingPolygon.length = 0;
  5837. };
  5838. SkeletonClipping.prototype.isClipping = function () {
  5839. return this.clipAttachment != null;
  5840. };
  5841. SkeletonClipping.prototype.clipTriangles = function (vertices, verticesLength, triangles, trianglesLength, uvs, light, dark, twoColor) {
  5842. var clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
  5843. var clippedTriangles = this.clippedTriangles;
  5844. var polygons = this.clippingPolygons;
  5845. var polygonsCount = this.clippingPolygons.length;
  5846. var vertexSize = twoColor ? 12 : 8;
  5847. var index = 0;
  5848. clippedVertices.length = 0;
  5849. clippedTriangles.length = 0;
  5850. outer: for (var i = 0; i < trianglesLength; i += 3) {
  5851. var vertexOffset = triangles[i] << 1;
  5852. var x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
  5853. var u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
  5854. vertexOffset = triangles[i + 1] << 1;
  5855. var x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
  5856. var u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
  5857. vertexOffset = triangles[i + 2] << 1;
  5858. var x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
  5859. var u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
  5860. for (var p = 0; p < polygonsCount; p++) {
  5861. var s = clippedVertices.length;
  5862. if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
  5863. var clipOutputLength = clipOutput.length;
  5864. if (clipOutputLength == 0)
  5865. continue;
  5866. var d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
  5867. var d = 1 / (d0 * d2 + d1 * (y1 - y3));
  5868. var clipOutputCount = clipOutputLength >> 1;
  5869. var clipOutputItems = this.clipOutput;
  5870. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize);
  5871. for (var ii = 0; ii < clipOutputLength; ii += 2) {
  5872. var x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
  5873. clippedVerticesItems[s] = x;
  5874. clippedVerticesItems[s + 1] = y;
  5875. clippedVerticesItems[s + 2] = light.r;
  5876. clippedVerticesItems[s + 3] = light.g;
  5877. clippedVerticesItems[s + 4] = light.b;
  5878. clippedVerticesItems[s + 5] = light.a;
  5879. var c0 = x - x3, c1 = y - y3;
  5880. var a = (d0 * c0 + d1 * c1) * d;
  5881. var b = (d4 * c0 + d2 * c1) * d;
  5882. var c = 1 - a - b;
  5883. clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
  5884. clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c;
  5885. if (twoColor) {
  5886. clippedVerticesItems[s + 8] = dark.r;
  5887. clippedVerticesItems[s + 9] = dark.g;
  5888. clippedVerticesItems[s + 10] = dark.b;
  5889. clippedVerticesItems[s + 11] = dark.a;
  5890. }
  5891. s += vertexSize;
  5892. }
  5893. s = clippedTriangles.length;
  5894. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2));
  5895. clipOutputCount--;
  5896. for (var ii = 1; ii < clipOutputCount; ii++) {
  5897. clippedTrianglesItems[s] = index;
  5898. clippedTrianglesItems[s + 1] = (index + ii);
  5899. clippedTrianglesItems[s + 2] = (index + ii + 1);
  5900. s += 3;
  5901. }
  5902. index += clipOutputCount + 1;
  5903. }
  5904. else {
  5905. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + 3 * vertexSize);
  5906. clippedVerticesItems[s] = x1;
  5907. clippedVerticesItems[s + 1] = y1;
  5908. clippedVerticesItems[s + 2] = light.r;
  5909. clippedVerticesItems[s + 3] = light.g;
  5910. clippedVerticesItems[s + 4] = light.b;
  5911. clippedVerticesItems[s + 5] = light.a;
  5912. if (!twoColor) {
  5913. clippedVerticesItems[s + 6] = u1;
  5914. clippedVerticesItems[s + 7] = v1;
  5915. clippedVerticesItems[s + 8] = x2;
  5916. clippedVerticesItems[s + 9] = y2;
  5917. clippedVerticesItems[s + 10] = light.r;
  5918. clippedVerticesItems[s + 11] = light.g;
  5919. clippedVerticesItems[s + 12] = light.b;
  5920. clippedVerticesItems[s + 13] = light.a;
  5921. clippedVerticesItems[s + 14] = u2;
  5922. clippedVerticesItems[s + 15] = v2;
  5923. clippedVerticesItems[s + 16] = x3;
  5924. clippedVerticesItems[s + 17] = y3;
  5925. clippedVerticesItems[s + 18] = light.r;
  5926. clippedVerticesItems[s + 19] = light.g;
  5927. clippedVerticesItems[s + 20] = light.b;
  5928. clippedVerticesItems[s + 21] = light.a;
  5929. clippedVerticesItems[s + 22] = u3;
  5930. clippedVerticesItems[s + 23] = v3;
  5931. }
  5932. else {
  5933. clippedVerticesItems[s + 6] = u1;
  5934. clippedVerticesItems[s + 7] = v1;
  5935. clippedVerticesItems[s + 8] = dark.r;
  5936. clippedVerticesItems[s + 9] = dark.g;
  5937. clippedVerticesItems[s + 10] = dark.b;
  5938. clippedVerticesItems[s + 11] = dark.a;
  5939. clippedVerticesItems[s + 12] = x2;
  5940. clippedVerticesItems[s + 13] = y2;
  5941. clippedVerticesItems[s + 14] = light.r;
  5942. clippedVerticesItems[s + 15] = light.g;
  5943. clippedVerticesItems[s + 16] = light.b;
  5944. clippedVerticesItems[s + 17] = light.a;
  5945. clippedVerticesItems[s + 18] = u2;
  5946. clippedVerticesItems[s + 19] = v2;
  5947. clippedVerticesItems[s + 20] = dark.r;
  5948. clippedVerticesItems[s + 21] = dark.g;
  5949. clippedVerticesItems[s + 22] = dark.b;
  5950. clippedVerticesItems[s + 23] = dark.a;
  5951. clippedVerticesItems[s + 24] = x3;
  5952. clippedVerticesItems[s + 25] = y3;
  5953. clippedVerticesItems[s + 26] = light.r;
  5954. clippedVerticesItems[s + 27] = light.g;
  5955. clippedVerticesItems[s + 28] = light.b;
  5956. clippedVerticesItems[s + 29] = light.a;
  5957. clippedVerticesItems[s + 30] = u3;
  5958. clippedVerticesItems[s + 31] = v3;
  5959. clippedVerticesItems[s + 32] = dark.r;
  5960. clippedVerticesItems[s + 33] = dark.g;
  5961. clippedVerticesItems[s + 34] = dark.b;
  5962. clippedVerticesItems[s + 35] = dark.a;
  5963. }
  5964. s = clippedTriangles.length;
  5965. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3);
  5966. clippedTrianglesItems[s] = index;
  5967. clippedTrianglesItems[s + 1] = (index + 1);
  5968. clippedTrianglesItems[s + 2] = (index + 2);
  5969. index += 3;
  5970. continue outer;
  5971. }
  5972. }
  5973. }
  5974. };
  5975. SkeletonClipping.prototype.clip = function (x1, y1, x2, y2, x3, y3, clippingArea, output) {
  5976. var originalOutput = output;
  5977. var clipped = false;
  5978. var input = null;
  5979. if (clippingArea.length % 4 >= 2) {
  5980. input = output;
  5981. output = this.scratch;
  5982. }
  5983. else
  5984. input = this.scratch;
  5985. input.length = 0;
  5986. input.push(x1);
  5987. input.push(y1);
  5988. input.push(x2);
  5989. input.push(y2);
  5990. input.push(x3);
  5991. input.push(y3);
  5992. input.push(x1);
  5993. input.push(y1);
  5994. output.length = 0;
  5995. var clippingVertices = clippingArea;
  5996. var clippingVerticesLast = clippingArea.length - 4;
  5997. for (var i = 0;; i += 2) {
  5998. var edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
  5999. var edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
  6000. var deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
  6001. var inputVertices = input;
  6002. var inputVerticesLength = input.length - 2, outputStart = output.length;
  6003. for (var ii = 0; ii < inputVerticesLength; ii += 2) {
  6004. var inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
  6005. var inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
  6006. var side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
  6007. if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
  6008. if (side2) {
  6009. output.push(inputX2);
  6010. output.push(inputY2);
  6011. continue;
  6012. }
  6013. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  6014. var s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY);
  6015. if (Math.abs(s) > 0.000001) {
  6016. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s;
  6017. output.push(edgeX + (edgeX2 - edgeX) * ua);
  6018. output.push(edgeY + (edgeY2 - edgeY) * ua);
  6019. }
  6020. else {
  6021. output.push(edgeX);
  6022. output.push(edgeY);
  6023. }
  6024. }
  6025. else if (side2) {
  6026. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  6027. var s = c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY);
  6028. if (Math.abs(s) > 0.000001) {
  6029. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / s;
  6030. output.push(edgeX + (edgeX2 - edgeX) * ua);
  6031. output.push(edgeY + (edgeY2 - edgeY) * ua);
  6032. }
  6033. else {
  6034. output.push(edgeX);
  6035. output.push(edgeY);
  6036. }
  6037. output.push(inputX2);
  6038. output.push(inputY2);
  6039. }
  6040. clipped = true;
  6041. }
  6042. if (outputStart == output.length) {
  6043. originalOutput.length = 0;
  6044. return true;
  6045. }
  6046. output.push(output[0]);
  6047. output.push(output[1]);
  6048. if (i == clippingVerticesLast)
  6049. break;
  6050. var temp = output;
  6051. output = input;
  6052. output.length = 0;
  6053. input = temp;
  6054. }
  6055. if (originalOutput != output) {
  6056. originalOutput.length = 0;
  6057. for (var i = 0, n = output.length - 2; i < n; i++)
  6058. originalOutput[i] = output[i];
  6059. }
  6060. else
  6061. originalOutput.length = originalOutput.length - 2;
  6062. return clipped;
  6063. };
  6064. SkeletonClipping.makeClockwise = function (polygon) {
  6065. var vertices = polygon;
  6066. var verticeslength = polygon.length;
  6067. var area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0;
  6068. for (var i = 0, n = verticeslength - 3; i < n; i += 2) {
  6069. p1x = vertices[i];
  6070. p1y = vertices[i + 1];
  6071. p2x = vertices[i + 2];
  6072. p2y = vertices[i + 3];
  6073. area += p1x * p2y - p2x * p1y;
  6074. }
  6075. if (area < 0)
  6076. return;
  6077. for (var i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
  6078. var x = vertices[i], y = vertices[i + 1];
  6079. var other = lastX - i;
  6080. vertices[i] = vertices[other];
  6081. vertices[i + 1] = vertices[other + 1];
  6082. vertices[other] = x;
  6083. vertices[other + 1] = y;
  6084. }
  6085. };
  6086. return SkeletonClipping;
  6087. }());
  6088. spine.SkeletonClipping = SkeletonClipping;
  6089. })(spine || (spine = {}));
  6090. var spine;
  6091. (function (spine) {
  6092. var SkeletonData = (function () {
  6093. function SkeletonData() {
  6094. this.bones = new Array();
  6095. this.slots = new Array();
  6096. this.skins = new Array();
  6097. this.events = new Array();
  6098. this.animations = new Array();
  6099. this.ikConstraints = new Array();
  6100. this.transformConstraints = new Array();
  6101. this.pathConstraints = new Array();
  6102. this.fps = 0;
  6103. }
  6104. SkeletonData.prototype.findBone = function (boneName) {
  6105. if (!boneName)
  6106. throw new Error("boneName cannot be null.");
  6107. var bones = this.bones;
  6108. for (var i = 0, n = bones.length; i < n; i++) {
  6109. var bone = bones[i];
  6110. if (bone.name == boneName)
  6111. return bone;
  6112. }
  6113. return null;
  6114. };
  6115. SkeletonData.prototype.findBoneIndex = function (boneName) {
  6116. if (!boneName)
  6117. throw new Error("boneName cannot be null.");
  6118. var bones = this.bones;
  6119. for (var i = 0, n = bones.length; i < n; i++)
  6120. if (bones[i].name == boneName)
  6121. return i;
  6122. return -1;
  6123. };
  6124. SkeletonData.prototype.findSlot = function (slotName) {
  6125. if (!slotName)
  6126. throw new Error("slotName cannot be null.");
  6127. var slots = this.slots;
  6128. for (var i = 0, n = slots.length; i < n; i++) {
  6129. var slot = slots[i];
  6130. if (slot.name == slotName)
  6131. return slot;
  6132. }
  6133. return null;
  6134. };
  6135. SkeletonData.prototype.findSlotIndex = function (slotName) {
  6136. if (!slotName)
  6137. throw new Error("slotName cannot be null.");
  6138. var slots = this.slots;
  6139. for (var i = 0, n = slots.length; i < n; i++)
  6140. if (slots[i].name == slotName)
  6141. return i;
  6142. return -1;
  6143. };
  6144. SkeletonData.prototype.findSkin = function (skinName) {
  6145. if (!skinName)
  6146. throw new Error("skinName cannot be null.");
  6147. var skins = this.skins;
  6148. for (var i = 0, n = skins.length; i < n; i++) {
  6149. var skin = skins[i];
  6150. if (skin.name == skinName)
  6151. return skin;
  6152. }
  6153. return null;
  6154. };
  6155. SkeletonData.prototype.findEvent = function (eventDataName) {
  6156. if (!eventDataName)
  6157. throw new Error("eventDataName cannot be null.");
  6158. var events = this.events;
  6159. for (var i = 0, n = events.length; i < n; i++) {
  6160. var event_5 = events[i];
  6161. if (event_5.name == eventDataName)
  6162. return event_5;
  6163. }
  6164. return null;
  6165. };
  6166. SkeletonData.prototype.findAnimation = function (animationName) {
  6167. if (!animationName)
  6168. throw new Error("animationName cannot be null.");
  6169. var animations = this.animations;
  6170. for (var i = 0, n = animations.length; i < n; i++) {
  6171. var animation = animations[i];
  6172. if (animation.name == animationName)
  6173. return animation;
  6174. }
  6175. return null;
  6176. };
  6177. SkeletonData.prototype.findIkConstraint = function (constraintName) {
  6178. if (!constraintName)
  6179. throw new Error("constraintName cannot be null.");
  6180. var ikConstraints = this.ikConstraints;
  6181. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  6182. var constraint = ikConstraints[i];
  6183. if (constraint.name == constraintName)
  6184. return constraint;
  6185. }
  6186. return null;
  6187. };
  6188. SkeletonData.prototype.findTransformConstraint = function (constraintName) {
  6189. if (!constraintName)
  6190. throw new Error("constraintName cannot be null.");
  6191. var transformConstraints = this.transformConstraints;
  6192. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  6193. var constraint = transformConstraints[i];
  6194. if (constraint.name == constraintName)
  6195. return constraint;
  6196. }
  6197. return null;
  6198. };
  6199. SkeletonData.prototype.findPathConstraint = function (constraintName) {
  6200. if (!constraintName)
  6201. throw new Error("constraintName cannot be null.");
  6202. var pathConstraints = this.pathConstraints;
  6203. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  6204. var constraint = pathConstraints[i];
  6205. if (constraint.name == constraintName)
  6206. return constraint;
  6207. }
  6208. return null;
  6209. };
  6210. return SkeletonData;
  6211. }());
  6212. spine.SkeletonData = SkeletonData;
  6213. })(spine || (spine = {}));
  6214. var spine;
  6215. (function (spine) {
  6216. var SkeletonJson = (function () {
  6217. function SkeletonJson(attachmentLoader) {
  6218. this.scale = 1;
  6219. this.linkedMeshes = new Array();
  6220. this.attachmentLoader = attachmentLoader;
  6221. }
  6222. SkeletonJson.prototype.readSkeletonData = function (json) {
  6223. var scale = this.scale;
  6224. var skeletonData = new spine.SkeletonData();
  6225. var root = typeof (json) === "string" ? JSON.parse(json) : json;
  6226. var skeletonMap = root.skeleton;
  6227. if (skeletonMap) {
  6228. skeletonData.hash = skeletonMap.hash;
  6229. skeletonData.version = skeletonMap.spine;
  6230. skeletonData.x = skeletonMap.x;
  6231. skeletonData.y = skeletonMap.y;
  6232. skeletonData.width = skeletonMap.width;
  6233. skeletonData.height = skeletonMap.height;
  6234. skeletonData.fps = skeletonMap.fps;
  6235. skeletonData.imagesPath = skeletonMap.images;
  6236. }
  6237. if (root.bones) {
  6238. for (var i = 0; i < root.bones.length; i++) {
  6239. var boneMap = root.bones[i];
  6240. var parent_5 = null;
  6241. var parentName = getValue(boneMap, "parent", null);
  6242. if (parentName)
  6243. parent_5 = skeletonData.findBone(parentName);
  6244. var data = new spine.BoneData(skeletonData.bones.length, boneMap.name, parent_5);
  6245. data.length = getValue(boneMap, "length", 0) * scale;
  6246. data.x = getValue(boneMap, "x", 0) * scale;
  6247. data.y = getValue(boneMap, "y", 0) * scale;
  6248. data.rotation = getValue(boneMap, "rotation", 0);
  6249. data.scaleX = getValue(boneMap, "scaleX", 1);
  6250. data.scaleY = getValue(boneMap, "scaleY", 1);
  6251. data.shearX = getValue(boneMap, "shearX", 0);
  6252. data.shearY = getValue(boneMap, "shearY", 0);
  6253. data.transformMode = spine.Utils.enumValue(spine.TransformMode, getValue(boneMap, "transform", "Normal"));
  6254. data.skinRequired = getValue(boneMap, "skin", false);
  6255. var color = getValue(boneMap, "color", null);
  6256. if (color)
  6257. data.color.setFromString(color);
  6258. skeletonData.bones.push(data);
  6259. }
  6260. }
  6261. if (root.slots) {
  6262. for (var i = 0; i < root.slots.length; i++) {
  6263. var slotMap = root.slots[i];
  6264. var boneData = skeletonData.findBone(slotMap.bone);
  6265. var data = new spine.SlotData(skeletonData.slots.length, slotMap.name, boneData);
  6266. var color = getValue(slotMap, "color", null);
  6267. if (color)
  6268. data.color.setFromString(color);
  6269. var dark = getValue(slotMap, "dark", null);
  6270. if (dark)
  6271. data.darkColor = spine.Color.fromString(dark);
  6272. data.attachmentName = getValue(slotMap, "attachment", null);
  6273. data.blendMode = spine.Utils.enumValue(spine.BlendMode, getValue(slotMap, "blend", "normal"));
  6274. skeletonData.slots.push(data);
  6275. }
  6276. }
  6277. if (root.ik) {
  6278. for (var i = 0; i < root.ik.length; i++) {
  6279. var constraintMap = root.ik[i];
  6280. var data = new spine.IkConstraintData(constraintMap.name);
  6281. data.order = getValue(constraintMap, "order", 0);
  6282. data.skinRequired = getValue(constraintMap, "skin", false);
  6283. for (var ii = 0; ii < constraintMap.bones.length; ii++)
  6284. data.bones.push(skeletonData.findBone(constraintMap.bones[ii]));
  6285. data.target = skeletonData.findBone(constraintMap.target);
  6286. data.mix = getValue(constraintMap, "mix", 1);
  6287. data.softness = getValue(constraintMap, "softness", 0) * scale;
  6288. data.bendDirection = getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  6289. data.compress = getValue(constraintMap, "compress", false);
  6290. data.stretch = getValue(constraintMap, "stretch", false);
  6291. data.uniform = getValue(constraintMap, "uniform", false);
  6292. skeletonData.ikConstraints.push(data);
  6293. }
  6294. }
  6295. if (root.transform) {
  6296. for (var i = 0; i < root.transform.length; i++) {
  6297. var constraintMap = root.transform[i];
  6298. var data = new spine.TransformConstraintData(constraintMap.name);
  6299. data.order = getValue(constraintMap, "order", 0);
  6300. data.skinRequired = getValue(constraintMap, "skin", false);
  6301. for (var ii = 0; ii < constraintMap.bones.length; ii++)
  6302. data.bones.push(skeletonData.findBone(constraintMap.bones[ii]));
  6303. var targetName = constraintMap.target;
  6304. data.target = skeletonData.findBone(targetName);
  6305. data.local = getValue(constraintMap, "local", false);
  6306. data.relative = getValue(constraintMap, "relative", false);
  6307. data.offsetRotation = getValue(constraintMap, "rotation", 0);
  6308. data.offsetX = getValue(constraintMap, "x", 0) * scale;
  6309. data.offsetY = getValue(constraintMap, "y", 0) * scale;
  6310. data.offsetScaleX = getValue(constraintMap, "scaleX", 0);
  6311. data.offsetScaleY = getValue(constraintMap, "scaleY", 0);
  6312. data.offsetShearY = getValue(constraintMap, "shearY", 0);
  6313. data.mixRotate = getValue(constraintMap, "mixRotate", 1);
  6314. data.mixX = getValue(constraintMap, "mixX", 1);
  6315. data.mixY = getValue(constraintMap, "mixY", data.mixX);
  6316. data.mixScaleX = getValue(constraintMap, "mixScaleX", 1);
  6317. data.mixScaleY = getValue(constraintMap, "mixScaleY", data.mixScaleX);
  6318. data.mixShearY = getValue(constraintMap, "mixShearY", 1);
  6319. skeletonData.transformConstraints.push(data);
  6320. }
  6321. }
  6322. if (root.path) {
  6323. for (var i = 0; i < root.path.length; i++) {
  6324. var constraintMap = root.path[i];
  6325. var data = new spine.PathConstraintData(constraintMap.name);
  6326. data.order = getValue(constraintMap, "order", 0);
  6327. data.skinRequired = getValue(constraintMap, "skin", false);
  6328. for (var ii = 0; ii < constraintMap.bones.length; ii++)
  6329. data.bones.push(skeletonData.findBone(constraintMap.bones[ii]));
  6330. var targetName = constraintMap.target;
  6331. data.target = skeletonData.findSlot(targetName);
  6332. data.positionMode = spine.Utils.enumValue(spine.PositionMode, getValue(constraintMap, "positionMode", "Percent"));
  6333. data.spacingMode = spine.Utils.enumValue(spine.SpacingMode, getValue(constraintMap, "spacingMode", "Length"));
  6334. data.rotateMode = spine.Utils.enumValue(spine.RotateMode, getValue(constraintMap, "rotateMode", "Tangent"));
  6335. data.offsetRotation = getValue(constraintMap, "rotation", 0);
  6336. data.position = getValue(constraintMap, "position", 0);
  6337. if (data.positionMode == spine.PositionMode.Fixed)
  6338. data.position *= scale;
  6339. data.spacing = getValue(constraintMap, "spacing", 0);
  6340. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  6341. data.spacing *= scale;
  6342. data.mixRotate = getValue(constraintMap, "mixRotate", 1);
  6343. data.mixX = getValue(constraintMap, "mixX", 1);
  6344. data.mixY = getValue(constraintMap, "mixY", data.mixX);
  6345. skeletonData.pathConstraints.push(data);
  6346. }
  6347. }
  6348. if (root.skins) {
  6349. var skins = root.skins;
  6350. var isArray = skins instanceof Array;
  6351. if (!isArray) {
  6352. var skinArray = [];
  6353. for (var skinName in skins) {
  6354. skinArray.push({ name: skinName, attachments: skins[skinName] });
  6355. }
  6356. skins = skinArray;
  6357. }
  6358. for (var i = 0; i < skins.length; i++) {
  6359. var skinMap = skins[i];
  6360. var skin = new spine.Skin(skinMap.name);
  6361. if (skinMap.bones) {
  6362. for (var ii = 0; ii < skinMap.bones.length; ii++)
  6363. skin.bones.push(skeletonData.findBone(skinMap.bones[ii]));
  6364. }
  6365. if (skinMap.ik) {
  6366. for (var ii = 0; ii < skinMap.ik.length; ii++)
  6367. skin.constraints.push(skeletonData.findIkConstraint(skinMap.ik[ii]));
  6368. }
  6369. if (skinMap.transform) {
  6370. for (var ii = 0; ii < skinMap.transform.length; ii++)
  6371. skin.constraints.push(skeletonData.findTransformConstraint(skinMap.transform[ii]));
  6372. }
  6373. if (skinMap.path) {
  6374. for (var ii = 0; ii < skinMap.path.length; ii++)
  6375. skin.constraints.push(skeletonData.findPathConstraint(skinMap.path[ii]));
  6376. }
  6377. for (var slotName in skinMap.attachments) {
  6378. var slot = skeletonData.findSlot(slotName);
  6379. var slotMap = skinMap.attachments[slotName];
  6380. for (var entryName in slotMap) {
  6381. var attachment = this.readAttachment(slotMap[entryName], skin, slot.index, entryName, skeletonData);
  6382. if (attachment)
  6383. skin.setAttachment(slot.index, entryName, attachment);
  6384. }
  6385. }
  6386. skeletonData.skins.push(skin);
  6387. if (skin.name == "default")
  6388. skeletonData.defaultSkin = skin;
  6389. }
  6390. }
  6391. for (var i = 0, n = this.linkedMeshes.length; i < n; i++) {
  6392. var linkedMesh = this.linkedMeshes[i];
  6393. var skin = !linkedMesh.skin ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  6394. var parent_6 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  6395. linkedMesh.mesh.deformAttachment = linkedMesh.inheritDeform ? parent_6 : linkedMesh.mesh;
  6396. linkedMesh.mesh.setParentMesh(parent_6);
  6397. linkedMesh.mesh.updateUVs();
  6398. }
  6399. this.linkedMeshes.length = 0;
  6400. if (root.events) {
  6401. for (var eventName in root.events) {
  6402. var eventMap = root.events[eventName];
  6403. var data = new spine.EventData(eventName);
  6404. data.intValue = getValue(eventMap, "int", 0);
  6405. data.floatValue = getValue(eventMap, "float", 0);
  6406. data.stringValue = getValue(eventMap, "string", "");
  6407. data.audioPath = getValue(eventMap, "audio", null);
  6408. if (data.audioPath) {
  6409. data.volume = getValue(eventMap, "volume", 1);
  6410. data.balance = getValue(eventMap, "balance", 0);
  6411. }
  6412. skeletonData.events.push(data);
  6413. }
  6414. }
  6415. if (root.animations) {
  6416. for (var animationName in root.animations) {
  6417. var animationMap = root.animations[animationName];
  6418. this.readAnimation(animationMap, animationName, skeletonData);
  6419. }
  6420. }
  6421. return skeletonData;
  6422. };
  6423. SkeletonJson.prototype.readAttachment = function (map, skin, slotIndex, name, skeletonData) {
  6424. var scale = this.scale;
  6425. name = getValue(map, "name", name);
  6426. switch (getValue(map, "type", "region")) {
  6427. case "region": {
  6428. var path = getValue(map, "path", name);
  6429. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  6430. if (!region)
  6431. return null;
  6432. region.path = path;
  6433. region.x = getValue(map, "x", 0) * scale;
  6434. region.y = getValue(map, "y", 0) * scale;
  6435. region.scaleX = getValue(map, "scaleX", 1);
  6436. region.scaleY = getValue(map, "scaleY", 1);
  6437. region.rotation = getValue(map, "rotation", 0);
  6438. region.width = map.width * scale;
  6439. region.height = map.height * scale;
  6440. var color = getValue(map, "color", null);
  6441. if (color)
  6442. region.color.setFromString(color);
  6443. region.updateOffset();
  6444. return region;
  6445. }
  6446. case "boundingbox": {
  6447. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  6448. if (!box)
  6449. return null;
  6450. this.readVertices(map, box, map.vertexCount << 1);
  6451. var color = getValue(map, "color", null);
  6452. if (color)
  6453. box.color.setFromString(color);
  6454. return box;
  6455. }
  6456. case "mesh":
  6457. case "linkedmesh": {
  6458. var path = getValue(map, "path", name);
  6459. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  6460. if (!mesh)
  6461. return null;
  6462. mesh.path = path;
  6463. var color = getValue(map, "color", null);
  6464. if (color)
  6465. mesh.color.setFromString(color);
  6466. mesh.width = getValue(map, "width", 0) * scale;
  6467. mesh.height = getValue(map, "height", 0) * scale;
  6468. var parent_7 = getValue(map, "parent", null);
  6469. if (parent_7) {
  6470. this.linkedMeshes.push(new LinkedMesh(mesh, getValue(map, "skin", null), slotIndex, parent_7, getValue(map, "deform", true)));
  6471. return mesh;
  6472. }
  6473. var uvs = map.uvs;
  6474. this.readVertices(map, mesh, uvs.length);
  6475. mesh.triangles = map.triangles;
  6476. mesh.regionUVs = uvs;
  6477. mesh.updateUVs();
  6478. mesh.edges = getValue(map, "edges", null);
  6479. mesh.hullLength = getValue(map, "hull", 0) * 2;
  6480. return mesh;
  6481. }
  6482. case "path": {
  6483. var path = this.attachmentLoader.newPathAttachment(skin, name);
  6484. if (!path)
  6485. return null;
  6486. path.closed = getValue(map, "closed", false);
  6487. path.constantSpeed = getValue(map, "constantSpeed", true);
  6488. var vertexCount = map.vertexCount;
  6489. this.readVertices(map, path, vertexCount << 1);
  6490. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  6491. for (var i = 0; i < map.lengths.length; i++)
  6492. lengths[i] = map.lengths[i] * scale;
  6493. path.lengths = lengths;
  6494. var color = getValue(map, "color", null);
  6495. if (color)
  6496. path.color.setFromString(color);
  6497. return path;
  6498. }
  6499. case "point": {
  6500. var point = this.attachmentLoader.newPointAttachment(skin, name);
  6501. if (!point)
  6502. return null;
  6503. point.x = getValue(map, "x", 0) * scale;
  6504. point.y = getValue(map, "y", 0) * scale;
  6505. point.rotation = getValue(map, "rotation", 0);
  6506. var color = getValue(map, "color", null);
  6507. if (color)
  6508. point.color.setFromString(color);
  6509. return point;
  6510. }
  6511. case "clipping": {
  6512. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  6513. if (!clip)
  6514. return null;
  6515. var end = getValue(map, "end", null);
  6516. if (end)
  6517. clip.endSlot = skeletonData.findSlot(end);
  6518. var vertexCount = map.vertexCount;
  6519. this.readVertices(map, clip, vertexCount << 1);
  6520. var color = getValue(map, "color", null);
  6521. if (color)
  6522. clip.color.setFromString(color);
  6523. return clip;
  6524. }
  6525. }
  6526. return null;
  6527. };
  6528. SkeletonJson.prototype.readVertices = function (map, attachment, verticesLength) {
  6529. var scale = this.scale;
  6530. attachment.worldVerticesLength = verticesLength;
  6531. var vertices = map.vertices;
  6532. if (verticesLength == vertices.length) {
  6533. var scaledVertices = spine.Utils.toFloatArray(vertices);
  6534. if (scale != 1) {
  6535. for (var i = 0, n = vertices.length; i < n; i++)
  6536. scaledVertices[i] *= scale;
  6537. }
  6538. attachment.vertices = scaledVertices;
  6539. return;
  6540. }
  6541. var weights = new Array();
  6542. var bones = new Array();
  6543. for (var i = 0, n = vertices.length; i < n;) {
  6544. var boneCount = vertices[i++];
  6545. bones.push(boneCount);
  6546. for (var nn = i + boneCount * 4; i < nn; i += 4) {
  6547. bones.push(vertices[i]);
  6548. weights.push(vertices[i + 1] * scale);
  6549. weights.push(vertices[i + 2] * scale);
  6550. weights.push(vertices[i + 3]);
  6551. }
  6552. }
  6553. attachment.bones = bones;
  6554. attachment.vertices = spine.Utils.toFloatArray(weights);
  6555. };
  6556. SkeletonJson.prototype.readAnimation = function (map, name, skeletonData) {
  6557. var scale = this.scale;
  6558. var timelines = new Array();
  6559. if (map.slots) {
  6560. for (var slotName in map.slots) {
  6561. var slotMap = map.slots[slotName];
  6562. var slotIndex = skeletonData.findSlotIndex(slotName);
  6563. for (var timelineName in slotMap) {
  6564. var timelineMap = slotMap[timelineName];
  6565. if (!timelineMap)
  6566. continue;
  6567. if (timelineName == "attachment") {
  6568. var timeline = new spine.AttachmentTimeline(timelineMap.length, slotIndex);
  6569. for (var frame = 0; frame < timelineMap.length; frame++) {
  6570. var keyMap = timelineMap[frame];
  6571. timeline.setFrame(frame, getValue(keyMap, "time", 0), keyMap.name);
  6572. }
  6573. timelines.push(timeline);
  6574. }
  6575. else if (timelineName == "rgba") {
  6576. var timeline = new spine.RGBATimeline(timelineMap.length, timelineMap.length << 2, slotIndex);
  6577. var keyMap = timelineMap[0];
  6578. var time = getValue(keyMap, "time", 0);
  6579. var color = spine.Color.fromString(keyMap.color);
  6580. for (var frame = 0, bezier = 0;; frame++) {
  6581. timeline.setFrame(frame, time, color.r, color.g, color.b, color.a);
  6582. var nextMap = timelineMap[frame + 1];
  6583. if (!nextMap) {
  6584. timeline.shrink(bezier);
  6585. break;
  6586. }
  6587. var time2 = getValue(nextMap, "time", 0);
  6588. var newColor = spine.Color.fromString(nextMap.color);
  6589. var curve = keyMap.curve;
  6590. if (curve) {
  6591. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  6592. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  6593. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  6594. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1);
  6595. }
  6596. time = time2;
  6597. color = newColor;
  6598. keyMap = nextMap;
  6599. }
  6600. timelines.push(timeline);
  6601. }
  6602. else if (timelineName == "rgb") {
  6603. var timeline = new spine.RGBTimeline(timelineMap.length, timelineMap.length * 3, slotIndex);
  6604. var keyMap = timelineMap[0];
  6605. var time = getValue(keyMap, "time", 0);
  6606. var color = spine.Color.fromString(keyMap.color);
  6607. for (var frame = 0, bezier = 0;; frame++) {
  6608. timeline.setFrame(frame, time, color.r, color.g, color.b);
  6609. var nextMap = timelineMap[frame + 1];
  6610. if (!nextMap) {
  6611. timeline.shrink(bezier);
  6612. break;
  6613. }
  6614. var time2 = getValue(nextMap, "time", 0);
  6615. var newColor = spine.Color.fromString(nextMap.color);
  6616. var curve = keyMap.curve;
  6617. if (curve) {
  6618. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  6619. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  6620. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  6621. }
  6622. time = time2;
  6623. color = newColor;
  6624. keyMap = nextMap;
  6625. }
  6626. timelines.push(timeline);
  6627. }
  6628. else if (timelineName == "alpha") {
  6629. timelines.push(readTimeline1(timelineMap, new spine.AlphaTimeline(timelineMap.length, timelineMap.length, slotIndex), 0, 1));
  6630. }
  6631. else if (timelineName == "rgba2") {
  6632. var timeline = new spine.RGBA2Timeline(timelineMap.length, timelineMap.length * 7, slotIndex);
  6633. var keyMap = timelineMap[0];
  6634. var time = getValue(keyMap, "time", 0);
  6635. var color = spine.Color.fromString(keyMap.light);
  6636. var color2 = spine.Color.fromString(keyMap.dark);
  6637. for (var frame = 0, bezier = 0;; frame++) {
  6638. timeline.setFrame(frame, time, color.r, color.g, color.b, color.a, color2.r, color2.g, color2.b);
  6639. var nextMap = timelineMap[frame + 1];
  6640. if (!nextMap) {
  6641. timeline.shrink(bezier);
  6642. break;
  6643. }
  6644. var time2 = getValue(nextMap, "time", 0);
  6645. var newColor = spine.Color.fromString(nextMap.light);
  6646. var newColor2 = spine.Color.fromString(nextMap.dark);
  6647. var curve = keyMap.curve;
  6648. if (curve) {
  6649. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  6650. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  6651. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  6652. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color.a, newColor.a, 1);
  6653. bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.r, newColor2.r, 1);
  6654. bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.g, newColor2.g, 1);
  6655. bezier = readCurve(curve, timeline, bezier, frame, 6, time, time2, color2.b, newColor2.b, 1);
  6656. }
  6657. time = time2;
  6658. color = newColor;
  6659. color2 = newColor2;
  6660. keyMap = nextMap;
  6661. }
  6662. timelines.push(timeline);
  6663. }
  6664. else if (timelineName == "rgb2") {
  6665. var timeline = new spine.RGB2Timeline(timelineMap.length, timelineMap.length * 6, slotIndex);
  6666. var keyMap = timelineMap[0];
  6667. var time = getValue(keyMap, "time", 0);
  6668. var color = spine.Color.fromString(keyMap.light);
  6669. var color2 = spine.Color.fromString(keyMap.dark);
  6670. for (var frame = 0, bezier = 0;; frame++) {
  6671. timeline.setFrame(frame, time, color.r, color.g, color.b, color2.r, color2.g, color2.b);
  6672. var nextMap = timelineMap[frame + 1];
  6673. if (!nextMap) {
  6674. timeline.shrink(bezier);
  6675. break;
  6676. }
  6677. var time2 = getValue(nextMap, "time", 0);
  6678. var newColor = spine.Color.fromString(nextMap.light);
  6679. var newColor2 = spine.Color.fromString(nextMap.dark);
  6680. var curve = keyMap.curve;
  6681. if (curve) {
  6682. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, color.r, newColor.r, 1);
  6683. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, color.g, newColor.g, 1);
  6684. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, color.b, newColor.b, 1);
  6685. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, color2.r, newColor2.r, 1);
  6686. bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, color2.g, newColor2.g, 1);
  6687. bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, color2.b, newColor2.b, 1);
  6688. }
  6689. time = time2;
  6690. color = newColor;
  6691. color2 = newColor2;
  6692. keyMap = nextMap;
  6693. }
  6694. timelines.push(timeline);
  6695. }
  6696. }
  6697. }
  6698. }
  6699. if (map.bones) {
  6700. for (var boneName in map.bones) {
  6701. var boneMap = map.bones[boneName];
  6702. var boneIndex = skeletonData.findBoneIndex(boneName);
  6703. for (var timelineName in boneMap) {
  6704. var timelineMap = boneMap[timelineName];
  6705. if (timelineMap.length == 0)
  6706. continue;
  6707. if (timelineName === "rotate") {
  6708. timelines.push(readTimeline1(timelineMap, new spine.RotateTimeline(timelineMap.length, timelineMap.length, boneIndex), 0, 1));
  6709. }
  6710. else if (timelineName === "translate") {
  6711. var timeline = new spine.TranslateTimeline(timelineMap.length, timelineMap.length << 1, boneIndex);
  6712. timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, scale));
  6713. }
  6714. else if (timelineName === "translatex") {
  6715. var timeline = new spine.TranslateXTimeline(timelineMap.length, timelineMap.length, boneIndex);
  6716. timelines.push(readTimeline1(timelineMap, timeline, 0, scale));
  6717. }
  6718. else if (timelineName === "translatey") {
  6719. var timeline = new spine.TranslateYTimeline(timelineMap.length, timelineMap.length, boneIndex);
  6720. timelines.push(readTimeline1(timelineMap, timeline, 0, scale));
  6721. }
  6722. else if (timelineName === "scale") {
  6723. var timeline = new spine.ScaleTimeline(timelineMap.length, timelineMap.length << 1, boneIndex);
  6724. timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 1, 1));
  6725. }
  6726. else if (timelineName === "scalex") {
  6727. var timeline = new spine.ScaleXTimeline(timelineMap.length, timelineMap.length, boneIndex);
  6728. timelines.push(readTimeline1(timelineMap, timeline, 1, 1));
  6729. }
  6730. else if (timelineName === "scaley") {
  6731. var timeline = new spine.ScaleYTimeline(timelineMap.length, timelineMap.length, boneIndex);
  6732. timelines.push(readTimeline1(timelineMap, timeline, 1, 1));
  6733. }
  6734. else if (timelineName === "shear") {
  6735. var timeline = new spine.ShearTimeline(timelineMap.length, timelineMap.length << 1, boneIndex);
  6736. timelines.push(readTimeline2(timelineMap, timeline, "x", "y", 0, 1));
  6737. }
  6738. else if (timelineName === "shearx") {
  6739. var timeline = new spine.ShearXTimeline(timelineMap.length, timelineMap.length, boneIndex);
  6740. timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
  6741. }
  6742. else if (timelineName === "sheary") {
  6743. var timeline = new spine.ShearYTimeline(timelineMap.length, timelineMap.length, boneIndex);
  6744. timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
  6745. }
  6746. }
  6747. }
  6748. }
  6749. if (map.ik) {
  6750. for (var constraintName in map.ik) {
  6751. var constraintMap = map.ik[constraintName];
  6752. var keyMap = constraintMap[0];
  6753. if (!keyMap)
  6754. continue;
  6755. var constraint = skeletonData.findIkConstraint(constraintName);
  6756. var constraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  6757. var timeline = new spine.IkConstraintTimeline(constraintMap.length, constraintMap.length << 1, constraintIndex);
  6758. var time = getValue(keyMap, "time", 0);
  6759. var mix = getValue(keyMap, "mix", 1);
  6760. var softness = getValue(keyMap, "softness", 0) * scale;
  6761. for (var frame = 0, bezier = 0;; frame++) {
  6762. timeline.setFrame(frame, time, mix, softness, getValue(keyMap, "bendPositive", true) ? 1 : -1, getValue(keyMap, "compress", false), getValue(keyMap, "stretch", false));
  6763. var nextMap = constraintMap[frame + 1];
  6764. if (!nextMap) {
  6765. timeline.shrink(bezier);
  6766. break;
  6767. }
  6768. var time2 = getValue(nextMap, "time", 0);
  6769. var mix2 = getValue(nextMap, "mix", 1);
  6770. var softness2 = getValue(nextMap, "softness", 0) * scale;
  6771. var curve = keyMap.curve;
  6772. if (curve) {
  6773. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mix, mix2, 1);
  6774. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, softness, softness2, scale);
  6775. }
  6776. time = time2;
  6777. mix = mix2;
  6778. softness = softness2;
  6779. keyMap = nextMap;
  6780. }
  6781. timelines.push(timeline);
  6782. }
  6783. }
  6784. if (map.transform) {
  6785. for (var constraintName in map.transform) {
  6786. var timelineMap = map.transform[constraintName];
  6787. var keyMap = timelineMap[0];
  6788. if (!keyMap)
  6789. continue;
  6790. var constraint = skeletonData.findTransformConstraint(constraintName);
  6791. var constraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  6792. var timeline = new spine.TransformConstraintTimeline(timelineMap.length, timelineMap.length << 2, constraintIndex);
  6793. var time = getValue(keyMap, "time", 0);
  6794. var mixRotate = getValue(keyMap, "mixRotate", 1);
  6795. var mixX = getValue(keyMap, "mixX", 1);
  6796. var mixY = getValue(keyMap, "mixY", mixX);
  6797. var mixScaleX = getValue(keyMap, "mixScaleX", 1);
  6798. var mixScaleY = getValue(keyMap, "mixScaleY", mixScaleX);
  6799. var mixShearY = getValue(keyMap, "mixShearY", 1);
  6800. for (var frame = 0, bezier = 0;; frame++) {
  6801. timeline.setFrame(frame, time, mixRotate, mixX, mixY, mixScaleX, mixScaleY, mixShearY);
  6802. var nextMap = timelineMap[frame + 1];
  6803. if (!nextMap) {
  6804. timeline.shrink(bezier);
  6805. break;
  6806. }
  6807. var time2 = getValue(nextMap, "time", 0);
  6808. var mixRotate2 = getValue(nextMap, "mixRotate", 1);
  6809. var mixX2 = getValue(nextMap, "mixX", 1);
  6810. var mixY2 = getValue(nextMap, "mixY", mixX2);
  6811. var mixScaleX2 = getValue(nextMap, "mixScaleX", 1);
  6812. var mixScaleY2 = getValue(nextMap, "mixScaleY", mixScaleX2);
  6813. var mixShearY2 = getValue(nextMap, "mixShearY", 1);
  6814. var curve = keyMap.curve;
  6815. if (curve) {
  6816. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  6817. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1);
  6818. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1);
  6819. bezier = readCurve(curve, timeline, bezier, frame, 3, time, time2, mixScaleX, mixScaleX2, 1);
  6820. bezier = readCurve(curve, timeline, bezier, frame, 4, time, time2, mixScaleY, mixScaleY2, 1);
  6821. bezier = readCurve(curve, timeline, bezier, frame, 5, time, time2, mixShearY, mixShearY2, 1);
  6822. }
  6823. time = time2;
  6824. mixRotate = mixRotate2;
  6825. mixX = mixX2;
  6826. mixY = mixY2;
  6827. mixScaleX = mixScaleX2;
  6828. mixScaleY = mixScaleY2;
  6829. mixScaleX = mixScaleX2;
  6830. keyMap = nextMap;
  6831. }
  6832. timelines.push(timeline);
  6833. }
  6834. }
  6835. if (map.path) {
  6836. for (var constraintName in map.path) {
  6837. var constraintMap = map.path[constraintName];
  6838. var constraint = skeletonData.findPathConstraint(constraintName);
  6839. var constraintIndex = skeletonData.pathConstraints.indexOf(constraint);
  6840. for (var timelineName in constraintMap) {
  6841. var timelineMap = constraintMap[timelineName];
  6842. var keyMap = timelineMap[0];
  6843. if (!keyMap)
  6844. continue;
  6845. if (timelineName === "position") {
  6846. var timeline = new spine.PathConstraintPositionTimeline(timelineMap.length, timelineMap.length, constraintIndex);
  6847. timelines.push(readTimeline1(timelineMap, timeline, 0, constraint.positionMode == spine.PositionMode.Fixed ? scale : 1));
  6848. }
  6849. else if (timelineName === "spacing") {
  6850. var timeline = new spine.PathConstraintSpacingTimeline(timelineMap.length, timelineMap.length, constraintIndex);
  6851. timelines.push(readTimeline1(timelineMap, timeline, 0, constraint.spacingMode == spine.SpacingMode.Length || constraint.spacingMode == spine.SpacingMode.Fixed ? scale : 1));
  6852. }
  6853. else if (timelineName === "mix") {
  6854. var timeline = new spine.PathConstraintMixTimeline(timelineMap.size, timelineMap.size * 3, constraintIndex);
  6855. var time = getValue(keyMap, "time", 0);
  6856. var mixRotate = getValue(keyMap, "mixRotate", 1);
  6857. var mixX = getValue(keyMap, "mixX", 1);
  6858. var mixY = getValue(keyMap, "mixY", mixX);
  6859. for (var frame = 0, bezier = 0;; frame++) {
  6860. timeline.setFrame(frame, time, mixRotate, mixX, mixY);
  6861. var nextMap = timelineMap[frame + 1];
  6862. if (!nextMap) {
  6863. timeline.shrink(bezier);
  6864. break;
  6865. }
  6866. var time2 = getValue(nextMap, "time", 0);
  6867. var mixRotate2 = getValue(nextMap, "mixRotate", 1);
  6868. var mixX2 = getValue(nextMap, "mixX", 1);
  6869. var mixY2 = getValue(nextMap, "mixY", mixX2);
  6870. var curve = keyMap.curve;
  6871. if (curve) {
  6872. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, mixRotate, mixRotate2, 1);
  6873. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, mixX, mixX2, 1);
  6874. bezier = readCurve(curve, timeline, bezier, frame, 2, time, time2, mixY, mixY2, 1);
  6875. }
  6876. time = time2;
  6877. mixRotate = mixRotate2;
  6878. mixX = mixX2;
  6879. mixY = mixY2;
  6880. keyMap = nextMap;
  6881. }
  6882. timelines.push(timeline);
  6883. }
  6884. }
  6885. }
  6886. }
  6887. if (map.deform) {
  6888. for (var deformName in map.deform) {
  6889. var deformMap = map.deform[deformName];
  6890. var skin = skeletonData.findSkin(deformName);
  6891. for (var slotName in deformMap) {
  6892. var slotMap = deformMap[slotName];
  6893. var slotIndex = skeletonData.findSlotIndex(slotName);
  6894. for (var timelineName in slotMap) {
  6895. var timelineMap = slotMap[timelineName];
  6896. var keyMap = timelineMap[0];
  6897. if (!keyMap)
  6898. continue;
  6899. var attachment = skin.getAttachment(slotIndex, timelineName);
  6900. var weighted = attachment.bones;
  6901. var vertices = attachment.vertices;
  6902. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  6903. var timeline = new spine.DeformTimeline(timelineMap.length, timelineMap.length, slotIndex, attachment);
  6904. var time = getValue(keyMap, "time", 0);
  6905. for (var frame = 0, bezier = 0;; frame++) {
  6906. var deform = void 0;
  6907. var verticesValue = getValue(keyMap, "vertices", null);
  6908. if (!verticesValue)
  6909. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  6910. else {
  6911. deform = spine.Utils.newFloatArray(deformLength);
  6912. var start = getValue(keyMap, "offset", 0);
  6913. spine.Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  6914. if (scale != 1) {
  6915. for (var i = start, n = i + verticesValue.length; i < n; i++)
  6916. deform[i] *= scale;
  6917. }
  6918. if (!weighted) {
  6919. for (var i = 0; i < deformLength; i++)
  6920. deform[i] += vertices[i];
  6921. }
  6922. }
  6923. timeline.setFrame(frame, time, deform);
  6924. var nextMap = timelineMap[frame + 1];
  6925. if (!nextMap) {
  6926. timeline.shrink(bezier);
  6927. break;
  6928. }
  6929. var time2 = getValue(nextMap, "time", 0);
  6930. var curve = keyMap.curve;
  6931. if (curve)
  6932. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, 0, 1, 1);
  6933. time = time2;
  6934. keyMap = nextMap;
  6935. }
  6936. timelines.push(timeline);
  6937. }
  6938. }
  6939. }
  6940. }
  6941. if (map.drawOrder) {
  6942. var timeline = new spine.DrawOrderTimeline(map.drawOrder.length);
  6943. var slotCount = skeletonData.slots.length;
  6944. var frame = 0;
  6945. for (var i = 0; i < map.drawOrder.length; i++, frame++) {
  6946. var drawOrderMap = map.drawOrder[i];
  6947. var drawOrder = null;
  6948. var offsets = getValue(drawOrderMap, "offsets", null);
  6949. if (offsets) {
  6950. drawOrder = spine.Utils.newArray(slotCount, -1);
  6951. var unchanged = spine.Utils.newArray(slotCount - offsets.length, 0);
  6952. var originalIndex = 0, unchangedIndex = 0;
  6953. for (var ii = 0; ii < offsets.length; ii++) {
  6954. var offsetMap = offsets[ii];
  6955. var slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  6956. while (originalIndex != slotIndex)
  6957. unchanged[unchangedIndex++] = originalIndex++;
  6958. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  6959. }
  6960. while (originalIndex < slotCount)
  6961. unchanged[unchangedIndex++] = originalIndex++;
  6962. for (var ii = slotCount - 1; ii >= 0; ii--)
  6963. if (drawOrder[ii] == -1)
  6964. drawOrder[ii] = unchanged[--unchangedIndex];
  6965. }
  6966. timeline.setFrame(frame, getValue(drawOrderMap, "time", 0), drawOrder);
  6967. }
  6968. timelines.push(timeline);
  6969. }
  6970. if (map.events) {
  6971. var timeline = new spine.EventTimeline(map.events.length);
  6972. var frame = 0;
  6973. for (var i = 0; i < map.events.length; i++, frame++) {
  6974. var eventMap = map.events[i];
  6975. var eventData = skeletonData.findEvent(eventMap.name);
  6976. var event_6 = new spine.Event(spine.Utils.toSinglePrecision(getValue(eventMap, "time", 0)), eventData);
  6977. event_6.intValue = getValue(eventMap, "int", eventData.intValue);
  6978. event_6.floatValue = getValue(eventMap, "float", eventData.floatValue);
  6979. event_6.stringValue = getValue(eventMap, "string", eventData.stringValue);
  6980. if (event_6.data.audioPath) {
  6981. event_6.volume = getValue(eventMap, "volume", 1);
  6982. event_6.balance = getValue(eventMap, "balance", 0);
  6983. }
  6984. timeline.setFrame(frame, event_6);
  6985. }
  6986. timelines.push(timeline);
  6987. }
  6988. var duration = 0;
  6989. for (var i = 0, n = timelines.length; i < n; i++)
  6990. duration = Math.max(duration, timelines[i].getDuration());
  6991. skeletonData.animations.push(new spine.Animation(name, timelines, duration));
  6992. };
  6993. return SkeletonJson;
  6994. }());
  6995. spine.SkeletonJson = SkeletonJson;
  6996. var LinkedMesh = (function () {
  6997. function LinkedMesh(mesh, skin, slotIndex, parent, inheritDeform) {
  6998. this.mesh = mesh;
  6999. this.skin = skin;
  7000. this.slotIndex = slotIndex;
  7001. this.parent = parent;
  7002. this.inheritDeform = inheritDeform;
  7003. }
  7004. return LinkedMesh;
  7005. }());
  7006. function readTimeline1(keys, timeline, defaultValue, scale) {
  7007. var keyMap = keys[0];
  7008. var time = getValue(keyMap, "time", 0);
  7009. var value = getValue(keyMap, "value", defaultValue) * scale;
  7010. var bezier = 0;
  7011. for (var frame = 0;; frame++) {
  7012. timeline.setFrame(frame, time, value);
  7013. var nextMap = keys[frame + 1];
  7014. if (!nextMap) {
  7015. timeline.shrink(bezier);
  7016. return timeline;
  7017. }
  7018. var time2 = getValue(nextMap, "time", 0);
  7019. var value2 = getValue(nextMap, "value", defaultValue) * scale;
  7020. if (keyMap.curve)
  7021. bezier = readCurve(keyMap.curve, timeline, bezier, frame, 0, time, time2, value, value2, scale);
  7022. time = time2;
  7023. value = value2;
  7024. keyMap = nextMap;
  7025. }
  7026. }
  7027. function readTimeline2(keys, timeline, name1, name2, defaultValue, scale) {
  7028. var keyMap = keys[0];
  7029. var time = getValue(keyMap, "time", 0);
  7030. var value1 = getValue(keyMap, name1, defaultValue) * scale;
  7031. var value2 = getValue(keyMap, name2, defaultValue) * scale;
  7032. var bezier = 0;
  7033. for (var frame = 0;; frame++) {
  7034. timeline.setFrame(frame, time, value1, value2);
  7035. var nextMap = keys[frame + 1];
  7036. if (!nextMap) {
  7037. timeline.shrink(bezier);
  7038. return timeline;
  7039. }
  7040. var time2 = getValue(nextMap, "time", 0);
  7041. var nvalue1 = getValue(nextMap, name1, defaultValue) * scale;
  7042. var nvalue2 = getValue(nextMap, name2, defaultValue) * scale;
  7043. var curve = keyMap.curve;
  7044. if (curve) {
  7045. bezier = readCurve(curve, timeline, bezier, frame, 0, time, time2, value1, nvalue1, scale);
  7046. bezier = readCurve(curve, timeline, bezier, frame, 1, time, time2, value2, nvalue2, scale);
  7047. }
  7048. time = time2;
  7049. value1 = nvalue1;
  7050. value2 = nvalue2;
  7051. keyMap = nextMap;
  7052. }
  7053. }
  7054. function readCurve(curve, timeline, bezier, frame, value, time1, time2, value1, value2, scale) {
  7055. if (curve == "stepped") {
  7056. timeline.setStepped(frame);
  7057. return bezier;
  7058. }
  7059. var i = value << 2;
  7060. var cx1 = curve[i];
  7061. var cy1 = curve[i + 1] * scale;
  7062. var cx2 = curve[i + 2];
  7063. var cy2 = curve[i + 3] * scale;
  7064. timeline.setBezier(bezier, frame, value, time1, value1, cx1, cy1, cx2, cy2, time2, value2);
  7065. return bezier + 1;
  7066. }
  7067. function getValue(map, property, defaultValue) {
  7068. return map[property] !== undefined ? map[property] : defaultValue;
  7069. }
  7070. })(spine || (spine = {}));
  7071. var spine;
  7072. (function (spine) {
  7073. var SkinEntry = (function () {
  7074. function SkinEntry(slotIndex, name, attachment) {
  7075. this.slotIndex = slotIndex;
  7076. this.name = name;
  7077. this.attachment = attachment;
  7078. }
  7079. return SkinEntry;
  7080. }());
  7081. spine.SkinEntry = SkinEntry;
  7082. var Skin = (function () {
  7083. function Skin(name) {
  7084. this.attachments = new Array();
  7085. this.bones = Array();
  7086. this.constraints = new Array();
  7087. if (!name)
  7088. throw new Error("name cannot be null.");
  7089. this.name = name;
  7090. }
  7091. Skin.prototype.setAttachment = function (slotIndex, name, attachment) {
  7092. if (!attachment)
  7093. throw new Error("attachment cannot be null.");
  7094. var attachments = this.attachments;
  7095. if (slotIndex >= attachments.length)
  7096. attachments.length = slotIndex + 1;
  7097. if (!attachments[slotIndex])
  7098. attachments[slotIndex] = {};
  7099. attachments[slotIndex][name] = attachment;
  7100. };
  7101. Skin.prototype.addSkin = function (skin) {
  7102. for (var i = 0; i < skin.bones.length; i++) {
  7103. var bone = skin.bones[i];
  7104. var contained = false;
  7105. for (var ii = 0; ii < this.bones.length; ii++) {
  7106. if (this.bones[ii] == bone) {
  7107. contained = true;
  7108. break;
  7109. }
  7110. }
  7111. if (!contained)
  7112. this.bones.push(bone);
  7113. }
  7114. for (var i = 0; i < skin.constraints.length; i++) {
  7115. var constraint = skin.constraints[i];
  7116. var contained = false;
  7117. for (var ii = 0; ii < this.constraints.length; ii++) {
  7118. if (this.constraints[ii] == constraint) {
  7119. contained = true;
  7120. break;
  7121. }
  7122. }
  7123. if (!contained)
  7124. this.constraints.push(constraint);
  7125. }
  7126. var attachments = skin.getAttachments();
  7127. for (var i = 0; i < attachments.length; i++) {
  7128. var attachment = attachments[i];
  7129. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  7130. }
  7131. };
  7132. Skin.prototype.copySkin = function (skin) {
  7133. for (var i = 0; i < skin.bones.length; i++) {
  7134. var bone = skin.bones[i];
  7135. var contained = false;
  7136. for (var ii = 0; ii < this.bones.length; ii++) {
  7137. if (this.bones[ii] == bone) {
  7138. contained = true;
  7139. break;
  7140. }
  7141. }
  7142. if (!contained)
  7143. this.bones.push(bone);
  7144. }
  7145. for (var i = 0; i < skin.constraints.length; i++) {
  7146. var constraint = skin.constraints[i];
  7147. var contained = false;
  7148. for (var ii = 0; ii < this.constraints.length; ii++) {
  7149. if (this.constraints[ii] == constraint) {
  7150. contained = true;
  7151. break;
  7152. }
  7153. }
  7154. if (!contained)
  7155. this.constraints.push(constraint);
  7156. }
  7157. var attachments = skin.getAttachments();
  7158. for (var i = 0; i < attachments.length; i++) {
  7159. var attachment = attachments[i];
  7160. if (!attachment.attachment)
  7161. continue;
  7162. if (attachment.attachment instanceof spine.MeshAttachment) {
  7163. attachment.attachment = attachment.attachment.newLinkedMesh();
  7164. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  7165. }
  7166. else {
  7167. attachment.attachment = attachment.attachment.copy();
  7168. this.setAttachment(attachment.slotIndex, attachment.name, attachment.attachment);
  7169. }
  7170. }
  7171. };
  7172. Skin.prototype.getAttachment = function (slotIndex, name) {
  7173. var dictionary = this.attachments[slotIndex];
  7174. return dictionary ? dictionary[name] : null;
  7175. };
  7176. Skin.prototype.removeAttachment = function (slotIndex, name) {
  7177. var dictionary = this.attachments[slotIndex];
  7178. if (dictionary)
  7179. dictionary[name] = null;
  7180. };
  7181. Skin.prototype.getAttachments = function () {
  7182. var entries = new Array();
  7183. for (var i = 0; i < this.attachments.length; i++) {
  7184. var slotAttachments = this.attachments[i];
  7185. if (slotAttachments) {
  7186. for (var name_4 in slotAttachments) {
  7187. var attachment = slotAttachments[name_4];
  7188. if (attachment)
  7189. entries.push(new SkinEntry(i, name_4, attachment));
  7190. }
  7191. }
  7192. }
  7193. return entries;
  7194. };
  7195. Skin.prototype.getAttachmentsForSlot = function (slotIndex, attachments) {
  7196. var slotAttachments = this.attachments[slotIndex];
  7197. if (slotAttachments) {
  7198. for (var name_5 in slotAttachments) {
  7199. var attachment = slotAttachments[name_5];
  7200. if (attachment)
  7201. attachments.push(new SkinEntry(slotIndex, name_5, attachment));
  7202. }
  7203. }
  7204. };
  7205. Skin.prototype.clear = function () {
  7206. this.attachments.length = 0;
  7207. this.bones.length = 0;
  7208. this.constraints.length = 0;
  7209. };
  7210. Skin.prototype.attachAll = function (skeleton, oldSkin) {
  7211. var slotIndex = 0;
  7212. for (var i = 0; i < skeleton.slots.length; i++) {
  7213. var slot = skeleton.slots[i];
  7214. var slotAttachment = slot.getAttachment();
  7215. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  7216. var dictionary = oldSkin.attachments[slotIndex];
  7217. for (var key in dictionary) {
  7218. var skinAttachment = dictionary[key];
  7219. if (slotAttachment == skinAttachment) {
  7220. var attachment = this.getAttachment(slotIndex, key);
  7221. if (attachment)
  7222. slot.setAttachment(attachment);
  7223. break;
  7224. }
  7225. }
  7226. }
  7227. slotIndex++;
  7228. }
  7229. };
  7230. return Skin;
  7231. }());
  7232. spine.Skin = Skin;
  7233. })(spine || (spine = {}));
  7234. var spine;
  7235. (function (spine) {
  7236. var Slot = (function () {
  7237. function Slot(data, bone) {
  7238. this.deform = new Array();
  7239. if (!data)
  7240. throw new Error("data cannot be null.");
  7241. if (!bone)
  7242. throw new Error("bone cannot be null.");
  7243. this.data = data;
  7244. this.bone = bone;
  7245. this.color = new spine.Color();
  7246. this.darkColor = !data.darkColor ? null : new spine.Color();
  7247. this.setToSetupPose();
  7248. }
  7249. Slot.prototype.getSkeleton = function () {
  7250. return this.bone.skeleton;
  7251. };
  7252. Slot.prototype.getAttachment = function () {
  7253. return this.attachment;
  7254. };
  7255. Slot.prototype.setAttachment = function (attachment) {
  7256. if (this.attachment == attachment)
  7257. return;
  7258. if (!(attachment instanceof spine.VertexAttachment) || !(this.attachment instanceof spine.VertexAttachment)
  7259. || attachment.deformAttachment != this.attachment.deformAttachment) {
  7260. this.deform.length = 0;
  7261. }
  7262. this.attachment = attachment;
  7263. this.attachmentTime = this.bone.skeleton.time;
  7264. };
  7265. Slot.prototype.setAttachmentTime = function (time) {
  7266. this.attachmentTime = this.bone.skeleton.time - time;
  7267. };
  7268. Slot.prototype.getAttachmentTime = function () {
  7269. return this.bone.skeleton.time - this.attachmentTime;
  7270. };
  7271. Slot.prototype.setToSetupPose = function () {
  7272. this.color.setFromColor(this.data.color);
  7273. if (this.darkColor)
  7274. this.darkColor.setFromColor(this.data.darkColor);
  7275. if (!this.data.attachmentName)
  7276. this.attachment = null;
  7277. else {
  7278. this.attachment = null;
  7279. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  7280. }
  7281. };
  7282. return Slot;
  7283. }());
  7284. spine.Slot = Slot;
  7285. })(spine || (spine = {}));
  7286. var spine;
  7287. (function (spine) {
  7288. var SlotData = (function () {
  7289. function SlotData(index, name, boneData) {
  7290. this.color = new spine.Color(1, 1, 1, 1);
  7291. if (index < 0)
  7292. throw new Error("index must be >= 0.");
  7293. if (!name)
  7294. throw new Error("name cannot be null.");
  7295. if (!boneData)
  7296. throw new Error("boneData cannot be null.");
  7297. this.index = index;
  7298. this.name = name;
  7299. this.boneData = boneData;
  7300. }
  7301. return SlotData;
  7302. }());
  7303. spine.SlotData = SlotData;
  7304. var BlendMode;
  7305. (function (BlendMode) {
  7306. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  7307. BlendMode[BlendMode["Additive"] = 1] = "Additive";
  7308. BlendMode[BlendMode["Multiply"] = 2] = "Multiply";
  7309. BlendMode[BlendMode["Screen"] = 3] = "Screen";
  7310. })(BlendMode = spine.BlendMode || (spine.BlendMode = {}));
  7311. })(spine || (spine = {}));
  7312. var spine;
  7313. (function (spine) {
  7314. var Texture = (function () {
  7315. function Texture(image) {
  7316. this._image = image;
  7317. }
  7318. Texture.prototype.getImage = function () {
  7319. return this._image;
  7320. };
  7321. return Texture;
  7322. }());
  7323. spine.Texture = Texture;
  7324. var TextureFilter;
  7325. (function (TextureFilter) {
  7326. TextureFilter[TextureFilter["Nearest"] = 9728] = "Nearest";
  7327. TextureFilter[TextureFilter["Linear"] = 9729] = "Linear";
  7328. TextureFilter[TextureFilter["MipMap"] = 9987] = "MipMap";
  7329. TextureFilter[TextureFilter["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
  7330. TextureFilter[TextureFilter["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
  7331. TextureFilter[TextureFilter["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
  7332. TextureFilter[TextureFilter["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
  7333. })(TextureFilter = spine.TextureFilter || (spine.TextureFilter = {}));
  7334. var TextureWrap;
  7335. (function (TextureWrap) {
  7336. TextureWrap[TextureWrap["MirroredRepeat"] = 33648] = "MirroredRepeat";
  7337. TextureWrap[TextureWrap["ClampToEdge"] = 33071] = "ClampToEdge";
  7338. TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat";
  7339. })(TextureWrap = spine.TextureWrap || (spine.TextureWrap = {}));
  7340. var TextureRegion = (function () {
  7341. function TextureRegion() {
  7342. this.u = 0;
  7343. this.v = 0;
  7344. this.u2 = 0;
  7345. this.v2 = 0;
  7346. this.width = 0;
  7347. this.height = 0;
  7348. this.degrees = 0;
  7349. this.offsetX = 0;
  7350. this.offsetY = 0;
  7351. this.originalWidth = 0;
  7352. this.originalHeight = 0;
  7353. }
  7354. return TextureRegion;
  7355. }());
  7356. spine.TextureRegion = TextureRegion;
  7357. var FakeTexture = (function (_super) {
  7358. __extends(FakeTexture, _super);
  7359. function FakeTexture() {
  7360. return _super !== null && _super.apply(this, arguments) || this;
  7361. }
  7362. FakeTexture.prototype.setFilters = function (minFilter, magFilter) { };
  7363. FakeTexture.prototype.setWraps = function (uWrap, vWrap) { };
  7364. FakeTexture.prototype.dispose = function () { };
  7365. return FakeTexture;
  7366. }(Texture));
  7367. spine.FakeTexture = FakeTexture;
  7368. })(spine || (spine = {}));
  7369. var spine;
  7370. (function (spine) {
  7371. var TextureAtlas = (function () {
  7372. function TextureAtlas(atlasText) {
  7373. this.pages = new Array();
  7374. this.regions = new Array();
  7375. var reader = new TextureAtlasReader(atlasText);
  7376. var entry = new Array(4);
  7377. var page = null;
  7378. var region = null;
  7379. var pageFields = {};
  7380. pageFields["size"] = function () {
  7381. page.width = parseInt(entry[1]);
  7382. page.height = parseInt(entry[2]);
  7383. };
  7384. pageFields["format"] = function () {
  7385. };
  7386. pageFields["filter"] = function () {
  7387. page.minFilter = spine.Utils.enumValue(spine.TextureFilter, entry[1]);
  7388. page.magFilter = spine.Utils.enumValue(spine.TextureFilter, entry[2]);
  7389. };
  7390. pageFields["repeat"] = function () {
  7391. if (entry[1].indexOf('x') != -1)
  7392. page.uWrap = spine.TextureWrap.Repeat;
  7393. if (entry[1].indexOf('y') != -1)
  7394. page.vWrap = spine.TextureWrap.Repeat;
  7395. };
  7396. pageFields["pma"] = function () {
  7397. page.pma = entry[1] == "true";
  7398. };
  7399. var regionFields = {};
  7400. regionFields["xy"] = function () {
  7401. region.x = parseInt(entry[1]);
  7402. region.y = parseInt(entry[2]);
  7403. };
  7404. regionFields["size"] = function () {
  7405. region.width = parseInt(entry[1]);
  7406. region.height = parseInt(entry[2]);
  7407. };
  7408. regionFields["bounds"] = function () {
  7409. region.x = parseInt(entry[1]);
  7410. region.y = parseInt(entry[2]);
  7411. region.width = parseInt(entry[3]);
  7412. region.height = parseInt(entry[4]);
  7413. };
  7414. regionFields["offset"] = function () {
  7415. region.offsetX = parseInt(entry[1]);
  7416. region.offsetY = parseInt(entry[2]);
  7417. };
  7418. regionFields["orig"] = function () {
  7419. region.originalWidth = parseInt(entry[1]);
  7420. region.originalHeight = parseInt(entry[2]);
  7421. };
  7422. regionFields["offsets"] = function () {
  7423. region.offsetX = parseInt(entry[1]);
  7424. region.offsetY = parseInt(entry[2]);
  7425. region.originalWidth = parseInt(entry[3]);
  7426. region.originalHeight = parseInt(entry[4]);
  7427. };
  7428. regionFields["rotate"] = function () {
  7429. var value = entry[1];
  7430. if (value == "true")
  7431. region.degrees = 90;
  7432. else if (value != "false")
  7433. region.degrees = parseInt(value);
  7434. };
  7435. regionFields["index"] = function () {
  7436. region.index = parseInt(entry[1]);
  7437. };
  7438. var line = reader.readLine();
  7439. while (line && line.trim().length == 0)
  7440. line = reader.readLine();
  7441. while (true) {
  7442. if (!line || line.trim().length == 0)
  7443. break;
  7444. if (reader.readEntry(entry, line) == 0)
  7445. break;
  7446. line = reader.readLine();
  7447. }
  7448. var names = null;
  7449. var values = null;
  7450. while (true) {
  7451. if (line === null)
  7452. break;
  7453. if (line.trim().length == 0) {
  7454. page = null;
  7455. line = reader.readLine();
  7456. }
  7457. else if (!page) {
  7458. page = new TextureAtlasPage();
  7459. page.name = line.trim();
  7460. while (true) {
  7461. if (reader.readEntry(entry, line = reader.readLine()) == 0)
  7462. break;
  7463. var field = pageFields[entry[0]];
  7464. if (field)
  7465. field();
  7466. }
  7467. this.pages.push(page);
  7468. }
  7469. else {
  7470. region = new TextureAtlasRegion();
  7471. region.page = page;
  7472. region.name = line;
  7473. while (true) {
  7474. var count = reader.readEntry(entry, line = reader.readLine());
  7475. if (count == 0)
  7476. break;
  7477. var field = regionFields[entry[0]];
  7478. if (field)
  7479. field();
  7480. else {
  7481. if (!names) {
  7482. names = [];
  7483. values = [];
  7484. }
  7485. names.push(entry[0]);
  7486. var entryValues = [];
  7487. for (var i = 0; i < count; i++)
  7488. entryValues.push(parseInt(entry[i + 1]));
  7489. values.push(entryValues);
  7490. }
  7491. }
  7492. if (region.originalWidth == 0 && region.originalHeight == 0) {
  7493. region.originalWidth = region.width;
  7494. region.originalHeight = region.height;
  7495. }
  7496. if (names && names.length > 0) {
  7497. region.names = names;
  7498. region.values = values;
  7499. names = null;
  7500. values = null;
  7501. }
  7502. region.u = region.x / page.width;
  7503. region.v = region.y / page.height;
  7504. if (region.degrees == 90) {
  7505. region.u2 = (region.x + region.height) / page.width;
  7506. region.v2 = (region.y + region.width) / page.height;
  7507. }
  7508. else {
  7509. region.u2 = (region.x + region.width) / page.width;
  7510. region.v2 = (region.y + region.height) / page.height;
  7511. }
  7512. this.regions.push(region);
  7513. }
  7514. }
  7515. }
  7516. TextureAtlas.prototype.findRegion = function (name) {
  7517. for (var i = 0; i < this.regions.length; i++) {
  7518. if (this.regions[i].name == name) {
  7519. return this.regions[i];
  7520. }
  7521. }
  7522. return null;
  7523. };
  7524. TextureAtlas.prototype.setTextures = function (assetManager, pathPrefix) {
  7525. if (pathPrefix === void 0) { pathPrefix = ""; }
  7526. for (var _i = 0, _a = this.pages; _i < _a.length; _i++) {
  7527. var page = _a[_i];
  7528. page.setTexture(assetManager.get(pathPrefix + page.name));
  7529. }
  7530. };
  7531. TextureAtlas.prototype.dispose = function () {
  7532. for (var i = 0; i < this.pages.length; i++) {
  7533. this.pages[i].texture.dispose();
  7534. }
  7535. };
  7536. return TextureAtlas;
  7537. }());
  7538. spine.TextureAtlas = TextureAtlas;
  7539. var TextureAtlasReader = (function () {
  7540. function TextureAtlasReader(text) {
  7541. this.index = 0;
  7542. this.lines = text.split(/\r\n|\r|\n/);
  7543. }
  7544. TextureAtlasReader.prototype.readLine = function () {
  7545. if (this.index >= this.lines.length)
  7546. return null;
  7547. return this.lines[this.index++];
  7548. };
  7549. TextureAtlasReader.prototype.readEntry = function (entry, line) {
  7550. if (!line)
  7551. return 0;
  7552. line = line.trim();
  7553. if (line.length == 0)
  7554. return 0;
  7555. var colon = line.indexOf(':');
  7556. if (colon == -1)
  7557. return 0;
  7558. entry[0] = line.substr(0, colon).trim();
  7559. for (var i = 1, lastMatch = colon + 1;; i++) {
  7560. var comma = line.indexOf(',', lastMatch);
  7561. if (comma == -1) {
  7562. entry[i] = line.substr(lastMatch).trim();
  7563. return i;
  7564. }
  7565. entry[i] = line.substr(lastMatch, comma - lastMatch).trim();
  7566. lastMatch = comma + 1;
  7567. if (i == 4)
  7568. return 4;
  7569. }
  7570. };
  7571. return TextureAtlasReader;
  7572. }());
  7573. var TextureAtlasPage = (function () {
  7574. function TextureAtlasPage() {
  7575. this.minFilter = spine.TextureFilter.Nearest;
  7576. this.magFilter = spine.TextureFilter.Nearest;
  7577. this.uWrap = spine.TextureWrap.ClampToEdge;
  7578. this.vWrap = spine.TextureWrap.ClampToEdge;
  7579. }
  7580. TextureAtlasPage.prototype.setTexture = function (texture) {
  7581. this.texture = texture;
  7582. texture.setFilters(this.minFilter, this.magFilter);
  7583. texture.setWraps(this.uWrap, this.vWrap);
  7584. };
  7585. return TextureAtlasPage;
  7586. }());
  7587. spine.TextureAtlasPage = TextureAtlasPage;
  7588. var TextureAtlasRegion = (function (_super) {
  7589. __extends(TextureAtlasRegion, _super);
  7590. function TextureAtlasRegion() {
  7591. return _super !== null && _super.apply(this, arguments) || this;
  7592. }
  7593. return TextureAtlasRegion;
  7594. }(spine.TextureRegion));
  7595. spine.TextureAtlasRegion = TextureAtlasRegion;
  7596. })(spine || (spine = {}));
  7597. var spine;
  7598. (function (spine) {
  7599. var TransformConstraint = (function () {
  7600. function TransformConstraint(data, skeleton) {
  7601. this.mixRotate = 0;
  7602. this.mixX = 0;
  7603. this.mixY = 0;
  7604. this.mixScaleX = 0;
  7605. this.mixScaleY = 0;
  7606. this.mixShearY = 0;
  7607. this.temp = new spine.Vector2();
  7608. this.active = false;
  7609. if (!data)
  7610. throw new Error("data cannot be null.");
  7611. if (!skeleton)
  7612. throw new Error("skeleton cannot be null.");
  7613. this.data = data;
  7614. this.mixRotate = data.mixRotate;
  7615. this.mixX = data.mixX;
  7616. this.mixY = data.mixY;
  7617. this.mixScaleX = data.mixScaleX;
  7618. this.mixScaleY = data.mixScaleY;
  7619. this.mixShearY = data.mixShearY;
  7620. this.bones = new Array();
  7621. for (var i = 0; i < data.bones.length; i++)
  7622. this.bones.push(skeleton.findBone(data.bones[i].name));
  7623. this.target = skeleton.findBone(data.target.name);
  7624. }
  7625. TransformConstraint.prototype.isActive = function () {
  7626. return this.active;
  7627. };
  7628. TransformConstraint.prototype.update = function () {
  7629. if (this.mixRotate == 0 && this.mixX == 0 && this.mixY == 0 && this.mixScaleX == 0 && this.mixScaleX == 0 && this.mixShearY == 0)
  7630. return;
  7631. if (this.data.local) {
  7632. if (this.data.relative)
  7633. this.applyRelativeLocal();
  7634. else
  7635. this.applyAbsoluteLocal();
  7636. }
  7637. else {
  7638. if (this.data.relative)
  7639. this.applyRelativeWorld();
  7640. else
  7641. this.applyAbsoluteWorld();
  7642. }
  7643. };
  7644. TransformConstraint.prototype.applyAbsoluteWorld = function () {
  7645. var mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  7646. var translate = mixX != 0 || mixY != 0;
  7647. var target = this.target;
  7648. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  7649. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  7650. var offsetRotation = this.data.offsetRotation * degRadReflect;
  7651. var offsetShearY = this.data.offsetShearY * degRadReflect;
  7652. var bones = this.bones;
  7653. for (var i = 0, n = bones.length; i < n; i++) {
  7654. var bone = bones[i];
  7655. if (mixRotate != 0) {
  7656. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  7657. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  7658. if (r > spine.MathUtils.PI)
  7659. r -= spine.MathUtils.PI2;
  7660. else if (r < -spine.MathUtils.PI)
  7661. r += spine.MathUtils.PI2;
  7662. r *= mixRotate;
  7663. var cos = Math.cos(r), sin = Math.sin(r);
  7664. bone.a = cos * a - sin * c;
  7665. bone.b = cos * b - sin * d;
  7666. bone.c = sin * a + cos * c;
  7667. bone.d = sin * b + cos * d;
  7668. }
  7669. if (translate) {
  7670. var temp = this.temp;
  7671. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  7672. bone.worldX += (temp.x - bone.worldX) * mixX;
  7673. bone.worldY += (temp.y - bone.worldY) * mixY;
  7674. }
  7675. if (mixScaleX != 0) {
  7676. var s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
  7677. if (s != 0)
  7678. s = (s + (Math.sqrt(ta * ta + tc * tc) - s + this.data.offsetScaleX) * mixScaleX) / s;
  7679. bone.a *= s;
  7680. bone.c *= s;
  7681. }
  7682. if (mixScaleY != 0) {
  7683. var s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
  7684. if (s != 0)
  7685. s = (s + (Math.sqrt(tb * tb + td * td) - s + this.data.offsetScaleY) * mixScaleY) / s;
  7686. bone.b *= s;
  7687. bone.d *= s;
  7688. }
  7689. if (mixShearY > 0) {
  7690. var b = bone.b, d = bone.d;
  7691. var by = Math.atan2(d, b);
  7692. var r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
  7693. if (r > spine.MathUtils.PI)
  7694. r -= spine.MathUtils.PI2;
  7695. else if (r < -spine.MathUtils.PI)
  7696. r += spine.MathUtils.PI2;
  7697. r = by + (r + offsetShearY) * mixShearY;
  7698. var s = Math.sqrt(b * b + d * d);
  7699. bone.b = Math.cos(r) * s;
  7700. bone.d = Math.sin(r) * s;
  7701. }
  7702. bone.updateAppliedTransform();
  7703. }
  7704. };
  7705. TransformConstraint.prototype.applyRelativeWorld = function () {
  7706. var mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  7707. var translate = mixX != 0 || mixY != 0;
  7708. var target = this.target;
  7709. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  7710. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  7711. var offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  7712. var bones = this.bones;
  7713. for (var i = 0, n = bones.length; i < n; i++) {
  7714. var bone = bones[i];
  7715. if (mixRotate != 0) {
  7716. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  7717. var r = Math.atan2(tc, ta) + offsetRotation;
  7718. if (r > spine.MathUtils.PI)
  7719. r -= spine.MathUtils.PI2;
  7720. else if (r < -spine.MathUtils.PI)
  7721. r += spine.MathUtils.PI2;
  7722. r *= mixRotate;
  7723. var cos = Math.cos(r), sin = Math.sin(r);
  7724. bone.a = cos * a - sin * c;
  7725. bone.b = cos * b - sin * d;
  7726. bone.c = sin * a + cos * c;
  7727. bone.d = sin * b + cos * d;
  7728. }
  7729. if (translate) {
  7730. var temp = this.temp;
  7731. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  7732. bone.worldX += temp.x * mixX;
  7733. bone.worldY += temp.y * mixY;
  7734. }
  7735. if (mixScaleX != 0) {
  7736. var s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * mixScaleX + 1;
  7737. bone.a *= s;
  7738. bone.c *= s;
  7739. }
  7740. if (mixScaleY != 0) {
  7741. var s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * mixScaleY + 1;
  7742. bone.b *= s;
  7743. bone.d *= s;
  7744. }
  7745. if (mixShearY > 0) {
  7746. var r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  7747. if (r > spine.MathUtils.PI)
  7748. r -= spine.MathUtils.PI2;
  7749. else if (r < -spine.MathUtils.PI)
  7750. r += spine.MathUtils.PI2;
  7751. var b = bone.b, d = bone.d;
  7752. r = Math.atan2(d, b) + (r - spine.MathUtils.PI / 2 + offsetShearY) * mixShearY;
  7753. var s = Math.sqrt(b * b + d * d);
  7754. bone.b = Math.cos(r) * s;
  7755. bone.d = Math.sin(r) * s;
  7756. }
  7757. bone.updateAppliedTransform();
  7758. }
  7759. };
  7760. TransformConstraint.prototype.applyAbsoluteLocal = function () {
  7761. var mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  7762. var target = this.target;
  7763. var bones = this.bones;
  7764. for (var i = 0, n = bones.length; i < n; i++) {
  7765. var bone = bones[i];
  7766. var rotation = bone.arotation;
  7767. if (mixRotate != 0) {
  7768. var r = target.arotation - rotation + this.data.offsetRotation;
  7769. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  7770. rotation += r * mixRotate;
  7771. }
  7772. var x = bone.ax, y = bone.ay;
  7773. x += (target.ax - x + this.data.offsetX) * mixX;
  7774. y += (target.ay - y + this.data.offsetY) * mixY;
  7775. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  7776. if (mixScaleX != 0 && scaleX != 0)
  7777. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * mixScaleX) / scaleX;
  7778. if (mixScaleY != 0 && scaleY != 0)
  7779. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * mixScaleY) / scaleY;
  7780. var shearY = bone.ashearY;
  7781. if (mixShearY != 0) {
  7782. var r = target.ashearY - shearY + this.data.offsetShearY;
  7783. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  7784. shearY += r * mixShearY;
  7785. }
  7786. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  7787. }
  7788. };
  7789. TransformConstraint.prototype.applyRelativeLocal = function () {
  7790. var mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX, mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
  7791. var target = this.target;
  7792. var bones = this.bones;
  7793. for (var i = 0, n = bones.length; i < n; i++) {
  7794. var bone = bones[i];
  7795. var rotation = bone.arotation + (target.arotation + this.data.offsetRotation) * mixRotate;
  7796. var x = bone.ax + (target.ax + this.data.offsetX) * mixX;
  7797. var y = bone.ay + (target.ay + this.data.offsetY) * mixY;
  7798. var scaleX = (bone.ascaleX * ((target.ascaleX - 1 + this.data.offsetScaleX) * mixScaleX) + 1);
  7799. var scaleY = (bone.ascaleY * ((target.ascaleY - 1 + this.data.offsetScaleY) * mixScaleY) + 1);
  7800. var shearY = bone.ashearY + (target.ashearY + this.data.offsetShearY) * mixShearY;
  7801. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  7802. }
  7803. };
  7804. return TransformConstraint;
  7805. }());
  7806. spine.TransformConstraint = TransformConstraint;
  7807. })(spine || (spine = {}));
  7808. var spine;
  7809. (function (spine) {
  7810. var TransformConstraintData = (function (_super) {
  7811. __extends(TransformConstraintData, _super);
  7812. function TransformConstraintData(name) {
  7813. var _this = _super.call(this, name, 0, false) || this;
  7814. _this.bones = new Array();
  7815. _this.mixRotate = 0;
  7816. _this.mixX = 0;
  7817. _this.mixY = 0;
  7818. _this.mixScaleX = 0;
  7819. _this.mixScaleY = 0;
  7820. _this.mixShearY = 0;
  7821. _this.offsetRotation = 0;
  7822. _this.offsetX = 0;
  7823. _this.offsetY = 0;
  7824. _this.offsetScaleX = 0;
  7825. _this.offsetScaleY = 0;
  7826. _this.offsetShearY = 0;
  7827. _this.relative = false;
  7828. _this.local = false;
  7829. return _this;
  7830. }
  7831. return TransformConstraintData;
  7832. }(spine.ConstraintData));
  7833. spine.TransformConstraintData = TransformConstraintData;
  7834. })(spine || (spine = {}));
  7835. var spine;
  7836. (function (spine) {
  7837. var Triangulator = (function () {
  7838. function Triangulator() {
  7839. this.convexPolygons = new Array();
  7840. this.convexPolygonsIndices = new Array();
  7841. this.indicesArray = new Array();
  7842. this.isConcaveArray = new Array();
  7843. this.triangles = new Array();
  7844. this.polygonPool = new spine.Pool(function () {
  7845. return new Array();
  7846. });
  7847. this.polygonIndicesPool = new spine.Pool(function () {
  7848. return new Array();
  7849. });
  7850. }
  7851. Triangulator.prototype.triangulate = function (verticesArray) {
  7852. var vertices = verticesArray;
  7853. var vertexCount = verticesArray.length >> 1;
  7854. var indices = this.indicesArray;
  7855. indices.length = 0;
  7856. for (var i = 0; i < vertexCount; i++)
  7857. indices[i] = i;
  7858. var isConcave = this.isConcaveArray;
  7859. isConcave.length = 0;
  7860. for (var i = 0, n = vertexCount; i < n; ++i)
  7861. isConcave[i] = Triangulator.isConcave(i, vertexCount, vertices, indices);
  7862. var triangles = this.triangles;
  7863. triangles.length = 0;
  7864. while (vertexCount > 3) {
  7865. var previous = vertexCount - 1, i = 0, next = 1;
  7866. while (true) {
  7867. outer: if (!isConcave[i]) {
  7868. var p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1;
  7869. var p1x = vertices[p1], p1y = vertices[p1 + 1];
  7870. var p2x = vertices[p2], p2y = vertices[p2 + 1];
  7871. var p3x = vertices[p3], p3y = vertices[p3 + 1];
  7872. for (var ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
  7873. if (!isConcave[ii])
  7874. continue;
  7875. var v = indices[ii] << 1;
  7876. var vx = vertices[v], vy = vertices[v + 1];
  7877. if (Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
  7878. if (Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
  7879. if (Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy))
  7880. break outer;
  7881. }
  7882. }
  7883. }
  7884. break;
  7885. }
  7886. if (next == 0) {
  7887. do {
  7888. if (!isConcave[i])
  7889. break;
  7890. i--;
  7891. } while (i > 0);
  7892. break;
  7893. }
  7894. previous = i;
  7895. i = next;
  7896. next = (next + 1) % vertexCount;
  7897. }
  7898. triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
  7899. triangles.push(indices[i]);
  7900. triangles.push(indices[(i + 1) % vertexCount]);
  7901. indices.splice(i, 1);
  7902. isConcave.splice(i, 1);
  7903. vertexCount--;
  7904. var previousIndex = (vertexCount + i - 1) % vertexCount;
  7905. var nextIndex = i == vertexCount ? 0 : i;
  7906. isConcave[previousIndex] = Triangulator.isConcave(previousIndex, vertexCount, vertices, indices);
  7907. isConcave[nextIndex] = Triangulator.isConcave(nextIndex, vertexCount, vertices, indices);
  7908. }
  7909. if (vertexCount == 3) {
  7910. triangles.push(indices[2]);
  7911. triangles.push(indices[0]);
  7912. triangles.push(indices[1]);
  7913. }
  7914. return triangles;
  7915. };
  7916. Triangulator.prototype.decompose = function (verticesArray, triangles) {
  7917. var vertices = verticesArray;
  7918. var convexPolygons = this.convexPolygons;
  7919. this.polygonPool.freeAll(convexPolygons);
  7920. convexPolygons.length = 0;
  7921. var convexPolygonsIndices = this.convexPolygonsIndices;
  7922. this.polygonIndicesPool.freeAll(convexPolygonsIndices);
  7923. convexPolygonsIndices.length = 0;
  7924. var polygonIndices = this.polygonIndicesPool.obtain();
  7925. polygonIndices.length = 0;
  7926. var polygon = this.polygonPool.obtain();
  7927. polygon.length = 0;
  7928. var fanBaseIndex = -1, lastWinding = 0;
  7929. for (var i = 0, n = triangles.length; i < n; i += 3) {
  7930. var t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1;
  7931. var x1 = vertices[t1], y1 = vertices[t1 + 1];
  7932. var x2 = vertices[t2], y2 = vertices[t2 + 1];
  7933. var x3 = vertices[t3], y3 = vertices[t3 + 1];
  7934. var merged = false;
  7935. if (fanBaseIndex == t1) {
  7936. var o = polygon.length - 4;
  7937. var winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
  7938. var winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
  7939. if (winding1 == lastWinding && winding2 == lastWinding) {
  7940. polygon.push(x3);
  7941. polygon.push(y3);
  7942. polygonIndices.push(t3);
  7943. merged = true;
  7944. }
  7945. }
  7946. if (!merged) {
  7947. if (polygon.length > 0) {
  7948. convexPolygons.push(polygon);
  7949. convexPolygonsIndices.push(polygonIndices);
  7950. }
  7951. else {
  7952. this.polygonPool.free(polygon);
  7953. this.polygonIndicesPool.free(polygonIndices);
  7954. }
  7955. polygon = this.polygonPool.obtain();
  7956. polygon.length = 0;
  7957. polygon.push(x1);
  7958. polygon.push(y1);
  7959. polygon.push(x2);
  7960. polygon.push(y2);
  7961. polygon.push(x3);
  7962. polygon.push(y3);
  7963. polygonIndices = this.polygonIndicesPool.obtain();
  7964. polygonIndices.length = 0;
  7965. polygonIndices.push(t1);
  7966. polygonIndices.push(t2);
  7967. polygonIndices.push(t3);
  7968. lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
  7969. fanBaseIndex = t1;
  7970. }
  7971. }
  7972. if (polygon.length > 0) {
  7973. convexPolygons.push(polygon);
  7974. convexPolygonsIndices.push(polygonIndices);
  7975. }
  7976. for (var i = 0, n = convexPolygons.length; i < n; i++) {
  7977. polygonIndices = convexPolygonsIndices[i];
  7978. if (polygonIndices.length == 0)
  7979. continue;
  7980. var firstIndex = polygonIndices[0];
  7981. var lastIndex = polygonIndices[polygonIndices.length - 1];
  7982. polygon = convexPolygons[i];
  7983. var o = polygon.length - 4;
  7984. var prevPrevX = polygon[o], prevPrevY = polygon[o + 1];
  7985. var prevX = polygon[o + 2], prevY = polygon[o + 3];
  7986. var firstX = polygon[0], firstY = polygon[1];
  7987. var secondX = polygon[2], secondY = polygon[3];
  7988. var winding = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
  7989. for (var ii = 0; ii < n; ii++) {
  7990. if (ii == i)
  7991. continue;
  7992. var otherIndices = convexPolygonsIndices[ii];
  7993. if (otherIndices.length != 3)
  7994. continue;
  7995. var otherFirstIndex = otherIndices[0];
  7996. var otherSecondIndex = otherIndices[1];
  7997. var otherLastIndex = otherIndices[2];
  7998. var otherPoly = convexPolygons[ii];
  7999. var x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1];
  8000. if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex)
  8001. continue;
  8002. var winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
  8003. var winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
  8004. if (winding1 == winding && winding2 == winding) {
  8005. otherPoly.length = 0;
  8006. otherIndices.length = 0;
  8007. polygon.push(x3);
  8008. polygon.push(y3);
  8009. polygonIndices.push(otherLastIndex);
  8010. prevPrevX = prevX;
  8011. prevPrevY = prevY;
  8012. prevX = x3;
  8013. prevY = y3;
  8014. ii = 0;
  8015. }
  8016. }
  8017. }
  8018. for (var i = convexPolygons.length - 1; i >= 0; i--) {
  8019. polygon = convexPolygons[i];
  8020. if (polygon.length == 0) {
  8021. convexPolygons.splice(i, 1);
  8022. this.polygonPool.free(polygon);
  8023. polygonIndices = convexPolygonsIndices[i];
  8024. convexPolygonsIndices.splice(i, 1);
  8025. this.polygonIndicesPool.free(polygonIndices);
  8026. }
  8027. }
  8028. return convexPolygons;
  8029. };
  8030. Triangulator.isConcave = function (index, vertexCount, vertices, indices) {
  8031. var previous = indices[(vertexCount + index - 1) % vertexCount] << 1;
  8032. var current = indices[index] << 1;
  8033. var next = indices[(index + 1) % vertexCount] << 1;
  8034. return !this.positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]);
  8035. };
  8036. Triangulator.positiveArea = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  8037. return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
  8038. };
  8039. Triangulator.winding = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  8040. var px = p2x - p1x, py = p2y - p1y;
  8041. return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
  8042. };
  8043. return Triangulator;
  8044. }());
  8045. spine.Triangulator = Triangulator;
  8046. })(spine || (spine = {}));
  8047. var spine;
  8048. (function (spine) {
  8049. var IntSet = (function () {
  8050. function IntSet() {
  8051. this.array = new Array();
  8052. }
  8053. IntSet.prototype.add = function (value) {
  8054. var contains = this.contains(value);
  8055. this.array[value | 0] = value | 0;
  8056. return !contains;
  8057. };
  8058. IntSet.prototype.contains = function (value) {
  8059. return this.array[value | 0] != undefined;
  8060. };
  8061. IntSet.prototype.remove = function (value) {
  8062. this.array[value | 0] = undefined;
  8063. };
  8064. IntSet.prototype.clear = function () {
  8065. this.array.length = 0;
  8066. };
  8067. return IntSet;
  8068. }());
  8069. spine.IntSet = IntSet;
  8070. var StringSet = (function () {
  8071. function StringSet() {
  8072. this.entries = {};
  8073. this.size = 0;
  8074. }
  8075. StringSet.prototype.add = function (value) {
  8076. var contains = this.entries[value];
  8077. this.entries[value] = true;
  8078. if (!contains) {
  8079. this.size++;
  8080. return true;
  8081. }
  8082. return false;
  8083. };
  8084. StringSet.prototype.addAll = function (values) {
  8085. var oldSize = this.size;
  8086. for (var i = 0, n = values.length; i < n; i++)
  8087. this.add(values[i]);
  8088. return oldSize != this.size;
  8089. };
  8090. StringSet.prototype.contains = function (value) {
  8091. return this.entries[value];
  8092. };
  8093. StringSet.prototype.clear = function () {
  8094. this.entries = {};
  8095. this.size = 0;
  8096. };
  8097. return StringSet;
  8098. }());
  8099. spine.StringSet = StringSet;
  8100. var Color = (function () {
  8101. function Color(r, g, b, a) {
  8102. if (r === void 0) { r = 0; }
  8103. if (g === void 0) { g = 0; }
  8104. if (b === void 0) { b = 0; }
  8105. if (a === void 0) { a = 0; }
  8106. this.r = r;
  8107. this.g = g;
  8108. this.b = b;
  8109. this.a = a;
  8110. }
  8111. Color.prototype.set = function (r, g, b, a) {
  8112. this.r = r;
  8113. this.g = g;
  8114. this.b = b;
  8115. this.a = a;
  8116. return this.clamp();
  8117. };
  8118. Color.prototype.setFromColor = function (c) {
  8119. this.r = c.r;
  8120. this.g = c.g;
  8121. this.b = c.b;
  8122. this.a = c.a;
  8123. return this;
  8124. };
  8125. Color.prototype.setFromString = function (hex) {
  8126. hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
  8127. this.r = parseInt(hex.substr(0, 2), 16) / 255;
  8128. this.g = parseInt(hex.substr(2, 2), 16) / 255;
  8129. this.b = parseInt(hex.substr(4, 2), 16) / 255;
  8130. this.a = hex.length != 8 ? 1 : parseInt(hex.substr(6, 2), 16) / 255;
  8131. return this;
  8132. };
  8133. Color.prototype.add = function (r, g, b, a) {
  8134. this.r += r;
  8135. this.g += g;
  8136. this.b += b;
  8137. this.a += a;
  8138. return this.clamp();
  8139. };
  8140. Color.prototype.clamp = function () {
  8141. if (this.r < 0)
  8142. this.r = 0;
  8143. else if (this.r > 1)
  8144. this.r = 1;
  8145. if (this.g < 0)
  8146. this.g = 0;
  8147. else if (this.g > 1)
  8148. this.g = 1;
  8149. if (this.b < 0)
  8150. this.b = 0;
  8151. else if (this.b > 1)
  8152. this.b = 1;
  8153. if (this.a < 0)
  8154. this.a = 0;
  8155. else if (this.a > 1)
  8156. this.a = 1;
  8157. return this;
  8158. };
  8159. Color.rgba8888ToColor = function (color, value) {
  8160. color.r = ((value & 0xff000000) >>> 24) / 255;
  8161. color.g = ((value & 0x00ff0000) >>> 16) / 255;
  8162. color.b = ((value & 0x0000ff00) >>> 8) / 255;
  8163. color.a = ((value & 0x000000ff)) / 255;
  8164. };
  8165. Color.rgb888ToColor = function (color, value) {
  8166. color.r = ((value & 0x00ff0000) >>> 16) / 255;
  8167. color.g = ((value & 0x0000ff00) >>> 8) / 255;
  8168. color.b = ((value & 0x000000ff)) / 255;
  8169. };
  8170. Color.fromString = function (hex) {
  8171. return new Color().setFromString(hex);
  8172. };
  8173. Color.WHITE = new Color(1, 1, 1, 1);
  8174. Color.RED = new Color(1, 0, 0, 1);
  8175. Color.GREEN = new Color(0, 1, 0, 1);
  8176. Color.BLUE = new Color(0, 0, 1, 1);
  8177. Color.MAGENTA = new Color(1, 0, 1, 1);
  8178. return Color;
  8179. }());
  8180. spine.Color = Color;
  8181. var MathUtils = (function () {
  8182. function MathUtils() {
  8183. }
  8184. MathUtils.clamp = function (value, min, max) {
  8185. if (value < min)
  8186. return min;
  8187. if (value > max)
  8188. return max;
  8189. return value;
  8190. };
  8191. MathUtils.cosDeg = function (degrees) {
  8192. return Math.cos(degrees * MathUtils.degRad);
  8193. };
  8194. MathUtils.sinDeg = function (degrees) {
  8195. return Math.sin(degrees * MathUtils.degRad);
  8196. };
  8197. MathUtils.signum = function (value) {
  8198. return value > 0 ? 1 : value < 0 ? -1 : 0;
  8199. };
  8200. MathUtils.toInt = function (x) {
  8201. return x > 0 ? Math.floor(x) : Math.ceil(x);
  8202. };
  8203. MathUtils.cbrt = function (x) {
  8204. var y = Math.pow(Math.abs(x), 1 / 3);
  8205. return x < 0 ? -y : y;
  8206. };
  8207. MathUtils.randomTriangular = function (min, max) {
  8208. return MathUtils.randomTriangularWith(min, max, (min + max) * 0.5);
  8209. };
  8210. MathUtils.randomTriangularWith = function (min, max, mode) {
  8211. var u = Math.random();
  8212. var d = max - min;
  8213. if (u <= (mode - min) / d)
  8214. return min + Math.sqrt(u * d * (mode - min));
  8215. return max - Math.sqrt((1 - u) * d * (max - mode));
  8216. };
  8217. MathUtils.PI = 3.1415927;
  8218. MathUtils.PI2 = MathUtils.PI * 2;
  8219. MathUtils.radiansToDegrees = 180 / MathUtils.PI;
  8220. MathUtils.radDeg = MathUtils.radiansToDegrees;
  8221. MathUtils.degreesToRadians = MathUtils.PI / 180;
  8222. MathUtils.degRad = MathUtils.degreesToRadians;
  8223. return MathUtils;
  8224. }());
  8225. spine.MathUtils = MathUtils;
  8226. var Interpolation = (function () {
  8227. function Interpolation() {
  8228. }
  8229. Interpolation.prototype.apply = function (start, end, a) {
  8230. return start + (end - start) * this.applyInternal(a);
  8231. };
  8232. return Interpolation;
  8233. }());
  8234. spine.Interpolation = Interpolation;
  8235. var Pow = (function (_super) {
  8236. __extends(Pow, _super);
  8237. function Pow(power) {
  8238. var _this = _super.call(this) || this;
  8239. _this.power = 2;
  8240. _this.power = power;
  8241. return _this;
  8242. }
  8243. Pow.prototype.applyInternal = function (a) {
  8244. if (a <= 0.5)
  8245. return Math.pow(a * 2, this.power) / 2;
  8246. return Math.pow((a - 1) * 2, this.power) / (this.power % 2 == 0 ? -2 : 2) + 1;
  8247. };
  8248. return Pow;
  8249. }(Interpolation));
  8250. spine.Pow = Pow;
  8251. var PowOut = (function (_super) {
  8252. __extends(PowOut, _super);
  8253. function PowOut(power) {
  8254. return _super.call(this, power) || this;
  8255. }
  8256. PowOut.prototype.applyInternal = function (a) {
  8257. return Math.pow(a - 1, this.power) * (this.power % 2 == 0 ? -1 : 1) + 1;
  8258. };
  8259. return PowOut;
  8260. }(Pow));
  8261. spine.PowOut = PowOut;
  8262. var Utils = (function () {
  8263. function Utils() {
  8264. }
  8265. Utils.arrayCopy = function (source, sourceStart, dest, destStart, numElements) {
  8266. for (var i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  8267. dest[j] = source[i];
  8268. }
  8269. };
  8270. Utils.arrayFill = function (array, fromIndex, toIndex, value) {
  8271. for (var i = fromIndex; i < toIndex; i++)
  8272. array[i] = value;
  8273. };
  8274. Utils.setArraySize = function (array, size, value) {
  8275. if (value === void 0) { value = 0; }
  8276. var oldSize = array.length;
  8277. if (oldSize == size)
  8278. return array;
  8279. array.length = size;
  8280. if (oldSize < size) {
  8281. for (var i = oldSize; i < size; i++)
  8282. array[i] = value;
  8283. }
  8284. return array;
  8285. };
  8286. Utils.ensureArrayCapacity = function (array, size, value) {
  8287. if (value === void 0) { value = 0; }
  8288. if (array.length >= size)
  8289. return array;
  8290. return Utils.setArraySize(array, size, value);
  8291. };
  8292. Utils.newArray = function (size, defaultValue) {
  8293. var array = new Array(size);
  8294. for (var i = 0; i < size; i++)
  8295. array[i] = defaultValue;
  8296. return array;
  8297. };
  8298. Utils.newFloatArray = function (size) {
  8299. if (Utils.SUPPORTS_TYPED_ARRAYS)
  8300. return new Float32Array(size);
  8301. else {
  8302. var array = new Array(size);
  8303. for (var i = 0; i < array.length; i++)
  8304. array[i] = 0;
  8305. return array;
  8306. }
  8307. };
  8308. Utils.newShortArray = function (size) {
  8309. if (Utils.SUPPORTS_TYPED_ARRAYS)
  8310. return new Int16Array(size);
  8311. else {
  8312. var array = new Array(size);
  8313. for (var i = 0; i < array.length; i++)
  8314. array[i] = 0;
  8315. return array;
  8316. }
  8317. };
  8318. Utils.toFloatArray = function (array) {
  8319. return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  8320. };
  8321. Utils.toSinglePrecision = function (value) {
  8322. return Utils.SUPPORTS_TYPED_ARRAYS ? Math.fround(value) : value;
  8323. };
  8324. Utils.webkit602BugfixHelper = function (alpha, blend) {
  8325. };
  8326. Utils.contains = function (array, element, identity) {
  8327. if (identity === void 0) { identity = true; }
  8328. for (var i = 0; i < array.length; i++)
  8329. if (array[i] == element)
  8330. return true;
  8331. return false;
  8332. };
  8333. Utils.enumValue = function (type, name) {
  8334. return type[name[0].toUpperCase() + name.slice(1)];
  8335. };
  8336. Utils.SUPPORTS_TYPED_ARRAYS = typeof (Float32Array) !== "undefined";
  8337. return Utils;
  8338. }());
  8339. spine.Utils = Utils;
  8340. var DebugUtils = (function () {
  8341. function DebugUtils() {
  8342. }
  8343. DebugUtils.logBones = function (skeleton) {
  8344. for (var i = 0; i < skeleton.bones.length; i++) {
  8345. var bone = skeleton.bones[i];
  8346. console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
  8347. }
  8348. };
  8349. return DebugUtils;
  8350. }());
  8351. spine.DebugUtils = DebugUtils;
  8352. var Pool = (function () {
  8353. function Pool(instantiator) {
  8354. this.items = new Array();
  8355. this.instantiator = instantiator;
  8356. }
  8357. Pool.prototype.obtain = function () {
  8358. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  8359. };
  8360. Pool.prototype.free = function (item) {
  8361. if (item.reset)
  8362. item.reset();
  8363. this.items.push(item);
  8364. };
  8365. Pool.prototype.freeAll = function (items) {
  8366. for (var i = 0; i < items.length; i++)
  8367. this.free(items[i]);
  8368. };
  8369. Pool.prototype.clear = function () {
  8370. this.items.length = 0;
  8371. };
  8372. return Pool;
  8373. }());
  8374. spine.Pool = Pool;
  8375. var Vector2 = (function () {
  8376. function Vector2(x, y) {
  8377. if (x === void 0) { x = 0; }
  8378. if (y === void 0) { y = 0; }
  8379. this.x = x;
  8380. this.y = y;
  8381. }
  8382. Vector2.prototype.set = function (x, y) {
  8383. this.x = x;
  8384. this.y = y;
  8385. return this;
  8386. };
  8387. Vector2.prototype.length = function () {
  8388. var x = this.x;
  8389. var y = this.y;
  8390. return Math.sqrt(x * x + y * y);
  8391. };
  8392. Vector2.prototype.normalize = function () {
  8393. var len = this.length();
  8394. if (len != 0) {
  8395. this.x /= len;
  8396. this.y /= len;
  8397. }
  8398. return this;
  8399. };
  8400. return Vector2;
  8401. }());
  8402. spine.Vector2 = Vector2;
  8403. var TimeKeeper = (function () {
  8404. function TimeKeeper() {
  8405. this.maxDelta = 0.064;
  8406. this.framesPerSecond = 0;
  8407. this.delta = 0;
  8408. this.totalTime = 0;
  8409. this.lastTime = Date.now() / 1000;
  8410. this.frameCount = 0;
  8411. this.frameTime = 0;
  8412. }
  8413. TimeKeeper.prototype.update = function () {
  8414. var now = Date.now() / 1000;
  8415. this.delta = now - this.lastTime;
  8416. this.frameTime += this.delta;
  8417. this.totalTime += this.delta;
  8418. if (this.delta > this.maxDelta)
  8419. this.delta = this.maxDelta;
  8420. this.lastTime = now;
  8421. this.frameCount++;
  8422. if (this.frameTime > 1) {
  8423. this.framesPerSecond = this.frameCount / this.frameTime;
  8424. this.frameTime = 0;
  8425. this.frameCount = 0;
  8426. }
  8427. };
  8428. return TimeKeeper;
  8429. }());
  8430. spine.TimeKeeper = TimeKeeper;
  8431. var WindowedMean = (function () {
  8432. function WindowedMean(windowSize) {
  8433. if (windowSize === void 0) { windowSize = 32; }
  8434. this.addedValues = 0;
  8435. this.lastValue = 0;
  8436. this.mean = 0;
  8437. this.dirty = true;
  8438. this.values = new Array(windowSize);
  8439. }
  8440. WindowedMean.prototype.hasEnoughData = function () {
  8441. return this.addedValues >= this.values.length;
  8442. };
  8443. WindowedMean.prototype.addValue = function (value) {
  8444. if (this.addedValues < this.values.length)
  8445. this.addedValues++;
  8446. this.values[this.lastValue++] = value;
  8447. if (this.lastValue > this.values.length - 1)
  8448. this.lastValue = 0;
  8449. this.dirty = true;
  8450. };
  8451. WindowedMean.prototype.getMean = function () {
  8452. if (this.hasEnoughData()) {
  8453. if (this.dirty) {
  8454. var mean = 0;
  8455. for (var i = 0; i < this.values.length; i++)
  8456. mean += this.values[i];
  8457. this.mean = mean / this.values.length;
  8458. this.dirty = false;
  8459. }
  8460. return this.mean;
  8461. }
  8462. return 0;
  8463. };
  8464. return WindowedMean;
  8465. }());
  8466. spine.WindowedMean = WindowedMean;
  8467. })(spine || (spine = {}));
  8468. (function () {
  8469. if (!Math.fround) {
  8470. Math.fround = (function (array) {
  8471. return function (x) {
  8472. return array[0] = x, array[0];
  8473. };
  8474. })(new Float32Array(1));
  8475. }
  8476. })();
  8477. var spine;
  8478. (function (spine) {
  8479. var Attachment = (function () {
  8480. function Attachment(name) {
  8481. if (!name)
  8482. throw new Error("name cannot be null.");
  8483. this.name = name;
  8484. }
  8485. return Attachment;
  8486. }());
  8487. spine.Attachment = Attachment;
  8488. var VertexAttachment = (function (_super) {
  8489. __extends(VertexAttachment, _super);
  8490. function VertexAttachment(name) {
  8491. var _this = _super.call(this, name) || this;
  8492. _this.id = VertexAttachment.nextID++;
  8493. _this.worldVerticesLength = 0;
  8494. _this.deformAttachment = _this;
  8495. return _this;
  8496. }
  8497. VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
  8498. count = offset + (count >> 1) * stride;
  8499. var skeleton = slot.bone.skeleton;
  8500. var deformArray = slot.deform;
  8501. var vertices = this.vertices;
  8502. var bones = this.bones;
  8503. if (!bones) {
  8504. if (deformArray.length > 0)
  8505. vertices = deformArray;
  8506. var bone = slot.bone;
  8507. var x = bone.worldX;
  8508. var y = bone.worldY;
  8509. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  8510. for (var v_1 = start, w = offset; w < count; v_1 += 2, w += stride) {
  8511. var vx = vertices[v_1], vy = vertices[v_1 + 1];
  8512. worldVertices[w] = vx * a + vy * b + x;
  8513. worldVertices[w + 1] = vx * c + vy * d + y;
  8514. }
  8515. return;
  8516. }
  8517. var v = 0, skip = 0;
  8518. for (var i = 0; i < start; i += 2) {
  8519. var n = bones[v];
  8520. v += n + 1;
  8521. skip += n;
  8522. }
  8523. var skeletonBones = skeleton.bones;
  8524. if (deformArray.length == 0) {
  8525. for (var w = offset, b = skip * 3; w < count; w += stride) {
  8526. var wx = 0, wy = 0;
  8527. var n = bones[v++];
  8528. n += v;
  8529. for (; v < n; v++, b += 3) {
  8530. var bone = skeletonBones[bones[v]];
  8531. var vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  8532. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  8533. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  8534. }
  8535. worldVertices[w] = wx;
  8536. worldVertices[w + 1] = wy;
  8537. }
  8538. }
  8539. else {
  8540. var deform = deformArray;
  8541. for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  8542. var wx = 0, wy = 0;
  8543. var n = bones[v++];
  8544. n += v;
  8545. for (; v < n; v++, b += 3, f += 2) {
  8546. var bone = skeletonBones[bones[v]];
  8547. var vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  8548. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  8549. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  8550. }
  8551. worldVertices[w] = wx;
  8552. worldVertices[w + 1] = wy;
  8553. }
  8554. }
  8555. };
  8556. VertexAttachment.prototype.copyTo = function (attachment) {
  8557. if (this.bones) {
  8558. attachment.bones = new Array(this.bones.length);
  8559. spine.Utils.arrayCopy(this.bones, 0, attachment.bones, 0, this.bones.length);
  8560. }
  8561. else
  8562. attachment.bones = null;
  8563. if (this.vertices) {
  8564. attachment.vertices = spine.Utils.newFloatArray(this.vertices.length);
  8565. spine.Utils.arrayCopy(this.vertices, 0, attachment.vertices, 0, this.vertices.length);
  8566. }
  8567. else
  8568. attachment.vertices = null;
  8569. attachment.worldVerticesLength = this.worldVerticesLength;
  8570. attachment.deformAttachment = this.deformAttachment;
  8571. };
  8572. VertexAttachment.nextID = 0;
  8573. return VertexAttachment;
  8574. }(Attachment));
  8575. spine.VertexAttachment = VertexAttachment;
  8576. })(spine || (spine = {}));
  8577. var spine;
  8578. (function (spine) {
  8579. var BoundingBoxAttachment = (function (_super) {
  8580. __extends(BoundingBoxAttachment, _super);
  8581. function BoundingBoxAttachment(name) {
  8582. var _this = _super.call(this, name) || this;
  8583. _this.color = new spine.Color(1, 1, 1, 1);
  8584. return _this;
  8585. }
  8586. BoundingBoxAttachment.prototype.copy = function () {
  8587. var copy = new BoundingBoxAttachment(this.name);
  8588. this.copyTo(copy);
  8589. copy.color.setFromColor(this.color);
  8590. return copy;
  8591. };
  8592. return BoundingBoxAttachment;
  8593. }(spine.VertexAttachment));
  8594. spine.BoundingBoxAttachment = BoundingBoxAttachment;
  8595. })(spine || (spine = {}));
  8596. var spine;
  8597. (function (spine) {
  8598. var ClippingAttachment = (function (_super) {
  8599. __extends(ClippingAttachment, _super);
  8600. function ClippingAttachment(name) {
  8601. var _this = _super.call(this, name) || this;
  8602. _this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1);
  8603. return _this;
  8604. }
  8605. ClippingAttachment.prototype.copy = function () {
  8606. var copy = new ClippingAttachment(this.name);
  8607. this.copyTo(copy);
  8608. copy.endSlot = this.endSlot;
  8609. copy.color.setFromColor(this.color);
  8610. return copy;
  8611. };
  8612. return ClippingAttachment;
  8613. }(spine.VertexAttachment));
  8614. spine.ClippingAttachment = ClippingAttachment;
  8615. })(spine || (spine = {}));
  8616. var spine;
  8617. (function (spine) {
  8618. var MeshAttachment = (function (_super) {
  8619. __extends(MeshAttachment, _super);
  8620. function MeshAttachment(name) {
  8621. var _this = _super.call(this, name) || this;
  8622. _this.color = new spine.Color(1, 1, 1, 1);
  8623. _this.tempColor = new spine.Color(0, 0, 0, 0);
  8624. return _this;
  8625. }
  8626. MeshAttachment.prototype.updateUVs = function () {
  8627. var regionUVs = this.regionUVs;
  8628. if (!this.uvs || this.uvs.length != regionUVs.length)
  8629. this.uvs = spine.Utils.newFloatArray(regionUVs.length);
  8630. var uvs = this.uvs;
  8631. var n = this.uvs.length;
  8632. var u = this.region.u, v = this.region.v, width = 0, height = 0;
  8633. if (this.region instanceof spine.TextureAtlasRegion) {
  8634. var region = this.region, image = region.page.texture.getImage();
  8635. var textureWidth = image.width, textureHeight = image.height;
  8636. switch (region.degrees) {
  8637. case 90:
  8638. u -= (region.originalHeight - region.offsetY - region.height) / textureWidth;
  8639. v -= (region.originalWidth - region.offsetX - region.width) / textureHeight;
  8640. width = region.originalHeight / textureWidth;
  8641. height = region.originalWidth / textureHeight;
  8642. for (var i = 0; i < n; i += 2) {
  8643. uvs[i] = u + regionUVs[i + 1] * width;
  8644. uvs[i + 1] = v + (1 - regionUVs[i]) * height;
  8645. }
  8646. return;
  8647. case 180:
  8648. u -= (region.originalWidth - region.offsetX - region.width) / textureWidth;
  8649. v -= region.offsetY / textureHeight;
  8650. width = region.originalWidth / textureWidth;
  8651. height = region.originalHeight / textureHeight;
  8652. for (var i = 0; i < n; i += 2) {
  8653. uvs[i] = u + (1 - regionUVs[i]) * width;
  8654. uvs[i + 1] = v + (1 - regionUVs[i + 1]) * height;
  8655. }
  8656. return;
  8657. case 270:
  8658. u -= region.offsetY / textureWidth;
  8659. v -= region.offsetX / textureHeight;
  8660. width = region.originalHeight / textureWidth;
  8661. height = region.originalWidth / textureHeight;
  8662. for (var i = 0; i < n; i += 2) {
  8663. uvs[i] = u + (1 - regionUVs[i + 1]) * width;
  8664. uvs[i + 1] = v + regionUVs[i] * height;
  8665. }
  8666. return;
  8667. }
  8668. u -= region.offsetX / textureWidth;
  8669. v -= (region.originalHeight - region.offsetY - region.height) / textureHeight;
  8670. width = region.originalWidth / textureWidth;
  8671. height = region.originalHeight / textureHeight;
  8672. }
  8673. else if (!this.region) {
  8674. u = v = 0;
  8675. width = height = 1;
  8676. }
  8677. else {
  8678. width = this.region.u2 - u;
  8679. height = this.region.v2 - v;
  8680. }
  8681. for (var i = 0; i < n; i += 2) {
  8682. uvs[i] = u + regionUVs[i] * width;
  8683. uvs[i + 1] = v + regionUVs[i + 1] * height;
  8684. }
  8685. };
  8686. MeshAttachment.prototype.getParentMesh = function () {
  8687. return this.parentMesh;
  8688. };
  8689. MeshAttachment.prototype.setParentMesh = function (parentMesh) {
  8690. this.parentMesh = parentMesh;
  8691. if (parentMesh) {
  8692. this.bones = parentMesh.bones;
  8693. this.vertices = parentMesh.vertices;
  8694. this.worldVerticesLength = parentMesh.worldVerticesLength;
  8695. this.regionUVs = parentMesh.regionUVs;
  8696. this.triangles = parentMesh.triangles;
  8697. this.hullLength = parentMesh.hullLength;
  8698. this.worldVerticesLength = parentMesh.worldVerticesLength;
  8699. }
  8700. };
  8701. MeshAttachment.prototype.copy = function () {
  8702. if (this.parentMesh)
  8703. return this.newLinkedMesh();
  8704. var copy = new MeshAttachment(this.name);
  8705. copy.region = this.region;
  8706. copy.path = this.path;
  8707. copy.color.setFromColor(this.color);
  8708. this.copyTo(copy);
  8709. copy.regionUVs = new Array(this.regionUVs.length);
  8710. spine.Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
  8711. copy.uvs = new Array(this.uvs.length);
  8712. spine.Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
  8713. copy.triangles = new Array(this.triangles.length);
  8714. spine.Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
  8715. copy.hullLength = this.hullLength;
  8716. if (this.edges) {
  8717. copy.edges = new Array(this.edges.length);
  8718. spine.Utils.arrayCopy(this.edges, 0, copy.edges, 0, this.edges.length);
  8719. }
  8720. copy.width = this.width;
  8721. copy.height = this.height;
  8722. return copy;
  8723. };
  8724. MeshAttachment.prototype.newLinkedMesh = function () {
  8725. var copy = new MeshAttachment(this.name);
  8726. copy.region = this.region;
  8727. copy.path = this.path;
  8728. copy.color.setFromColor(this.color);
  8729. copy.deformAttachment = this.deformAttachment;
  8730. copy.setParentMesh(this.parentMesh ? this.parentMesh : this);
  8731. copy.updateUVs();
  8732. return copy;
  8733. };
  8734. return MeshAttachment;
  8735. }(spine.VertexAttachment));
  8736. spine.MeshAttachment = MeshAttachment;
  8737. })(spine || (spine = {}));
  8738. var spine;
  8739. (function (spine) {
  8740. var PathAttachment = (function (_super) {
  8741. __extends(PathAttachment, _super);
  8742. function PathAttachment(name) {
  8743. var _this = _super.call(this, name) || this;
  8744. _this.closed = false;
  8745. _this.constantSpeed = false;
  8746. _this.color = new spine.Color(1, 1, 1, 1);
  8747. return _this;
  8748. }
  8749. PathAttachment.prototype.copy = function () {
  8750. var copy = new PathAttachment(this.name);
  8751. this.copyTo(copy);
  8752. copy.lengths = new Array(this.lengths.length);
  8753. spine.Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
  8754. copy.closed = closed;
  8755. copy.constantSpeed = this.constantSpeed;
  8756. copy.color.setFromColor(this.color);
  8757. return copy;
  8758. };
  8759. return PathAttachment;
  8760. }(spine.VertexAttachment));
  8761. spine.PathAttachment = PathAttachment;
  8762. })(spine || (spine = {}));
  8763. var spine;
  8764. (function (spine) {
  8765. var PointAttachment = (function (_super) {
  8766. __extends(PointAttachment, _super);
  8767. function PointAttachment(name) {
  8768. var _this = _super.call(this, name) || this;
  8769. _this.color = new spine.Color(0.38, 0.94, 0, 1);
  8770. return _this;
  8771. }
  8772. PointAttachment.prototype.computeWorldPosition = function (bone, point) {
  8773. point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
  8774. point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
  8775. return point;
  8776. };
  8777. PointAttachment.prototype.computeWorldRotation = function (bone) {
  8778. var cos = spine.MathUtils.cosDeg(this.rotation), sin = spine.MathUtils.sinDeg(this.rotation);
  8779. var x = cos * bone.a + sin * bone.b;
  8780. var y = cos * bone.c + sin * bone.d;
  8781. return Math.atan2(y, x) * spine.MathUtils.radDeg;
  8782. };
  8783. PointAttachment.prototype.copy = function () {
  8784. var copy = new PointAttachment(this.name);
  8785. copy.x = this.x;
  8786. copy.y = this.y;
  8787. copy.rotation = this.rotation;
  8788. copy.color.setFromColor(this.color);
  8789. return copy;
  8790. };
  8791. return PointAttachment;
  8792. }(spine.VertexAttachment));
  8793. spine.PointAttachment = PointAttachment;
  8794. })(spine || (spine = {}));
  8795. var spine;
  8796. (function (spine) {
  8797. var RegionAttachment = (function (_super) {
  8798. __extends(RegionAttachment, _super);
  8799. function RegionAttachment(name) {
  8800. var _this = _super.call(this, name) || this;
  8801. _this.x = 0;
  8802. _this.y = 0;
  8803. _this.scaleX = 1;
  8804. _this.scaleY = 1;
  8805. _this.rotation = 0;
  8806. _this.width = 0;
  8807. _this.height = 0;
  8808. _this.color = new spine.Color(1, 1, 1, 1);
  8809. _this.offset = spine.Utils.newFloatArray(8);
  8810. _this.uvs = spine.Utils.newFloatArray(8);
  8811. _this.tempColor = new spine.Color(1, 1, 1, 1);
  8812. return _this;
  8813. }
  8814. RegionAttachment.prototype.updateOffset = function () {
  8815. var region = this.region;
  8816. var regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  8817. var regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  8818. var localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  8819. var localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  8820. var localX2 = localX + this.region.width * regionScaleX;
  8821. var localY2 = localY + this.region.height * regionScaleY;
  8822. var radians = this.rotation * Math.PI / 180;
  8823. var cos = Math.cos(radians);
  8824. var sin = Math.sin(radians);
  8825. var x = this.x, y = this.y;
  8826. var localXCos = localX * cos + x;
  8827. var localXSin = localX * sin;
  8828. var localYCos = localY * cos + y;
  8829. var localYSin = localY * sin;
  8830. var localX2Cos = localX2 * cos + x;
  8831. var localX2Sin = localX2 * sin;
  8832. var localY2Cos = localY2 * cos + y;
  8833. var localY2Sin = localY2 * sin;
  8834. var offset = this.offset;
  8835. offset[0] = localXCos - localYSin;
  8836. offset[1] = localYCos + localXSin;
  8837. offset[2] = localXCos - localY2Sin;
  8838. offset[3] = localY2Cos + localXSin;
  8839. offset[4] = localX2Cos - localY2Sin;
  8840. offset[5] = localY2Cos + localX2Sin;
  8841. offset[6] = localX2Cos - localYSin;
  8842. offset[7] = localYCos + localX2Sin;
  8843. };
  8844. RegionAttachment.prototype.setRegion = function (region) {
  8845. this.region = region;
  8846. var uvs = this.uvs;
  8847. if (region.degrees == 90) {
  8848. uvs[2] = region.u;
  8849. uvs[3] = region.v2;
  8850. uvs[4] = region.u;
  8851. uvs[5] = region.v;
  8852. uvs[6] = region.u2;
  8853. uvs[7] = region.v;
  8854. uvs[0] = region.u2;
  8855. uvs[1] = region.v2;
  8856. }
  8857. else {
  8858. uvs[0] = region.u;
  8859. uvs[1] = region.v2;
  8860. uvs[2] = region.u;
  8861. uvs[3] = region.v;
  8862. uvs[4] = region.u2;
  8863. uvs[5] = region.v;
  8864. uvs[6] = region.u2;
  8865. uvs[7] = region.v2;
  8866. }
  8867. };
  8868. RegionAttachment.prototype.computeWorldVertices = function (bone, worldVertices, offset, stride) {
  8869. var vertexOffset = this.offset;
  8870. var x = bone.worldX, y = bone.worldY;
  8871. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  8872. var offsetX = 0, offsetY = 0;
  8873. offsetX = vertexOffset[0];
  8874. offsetY = vertexOffset[1];
  8875. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8876. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8877. offset += stride;
  8878. offsetX = vertexOffset[2];
  8879. offsetY = vertexOffset[3];
  8880. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8881. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8882. offset += stride;
  8883. offsetX = vertexOffset[4];
  8884. offsetY = vertexOffset[5];
  8885. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8886. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8887. offset += stride;
  8888. offsetX = vertexOffset[6];
  8889. offsetY = vertexOffset[7];
  8890. worldVertices[offset] = offsetX * a + offsetY * b + x;
  8891. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  8892. };
  8893. RegionAttachment.prototype.copy = function () {
  8894. var copy = new RegionAttachment(this.name);
  8895. copy.region = this.region;
  8896. copy.rendererObject = this.rendererObject;
  8897. copy.path = this.path;
  8898. copy.x = this.x;
  8899. copy.y = this.y;
  8900. copy.scaleX = this.scaleX;
  8901. copy.scaleY = this.scaleY;
  8902. copy.rotation = this.rotation;
  8903. copy.width = this.width;
  8904. copy.height = this.height;
  8905. spine.Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, 8);
  8906. spine.Utils.arrayCopy(this.offset, 0, copy.offset, 0, 8);
  8907. copy.color.setFromColor(this.color);
  8908. return copy;
  8909. };
  8910. RegionAttachment.X1 = 0;
  8911. RegionAttachment.Y1 = 1;
  8912. RegionAttachment.C1R = 2;
  8913. RegionAttachment.C1G = 3;
  8914. RegionAttachment.C1B = 4;
  8915. RegionAttachment.C1A = 5;
  8916. RegionAttachment.U1 = 6;
  8917. RegionAttachment.V1 = 7;
  8918. RegionAttachment.X2 = 8;
  8919. RegionAttachment.Y2 = 9;
  8920. RegionAttachment.C2R = 10;
  8921. RegionAttachment.C2G = 11;
  8922. RegionAttachment.C2B = 12;
  8923. RegionAttachment.C2A = 13;
  8924. RegionAttachment.U2 = 14;
  8925. RegionAttachment.V2 = 15;
  8926. RegionAttachment.X3 = 16;
  8927. RegionAttachment.Y3 = 17;
  8928. RegionAttachment.C3R = 18;
  8929. RegionAttachment.C3G = 19;
  8930. RegionAttachment.C3B = 20;
  8931. RegionAttachment.C3A = 21;
  8932. RegionAttachment.U3 = 22;
  8933. RegionAttachment.V3 = 23;
  8934. RegionAttachment.X4 = 24;
  8935. RegionAttachment.Y4 = 25;
  8936. RegionAttachment.C4R = 26;
  8937. RegionAttachment.C4G = 27;
  8938. RegionAttachment.C4B = 28;
  8939. RegionAttachment.C4A = 29;
  8940. RegionAttachment.U4 = 30;
  8941. RegionAttachment.V4 = 31;
  8942. return RegionAttachment;
  8943. }(spine.Attachment));
  8944. spine.RegionAttachment = RegionAttachment;
  8945. })(spine || (spine = {}));
  8946. var spine;
  8947. (function (spine) {
  8948. var JitterEffect = (function () {
  8949. function JitterEffect(jitterX, jitterY) {
  8950. this.jitterX = 0;
  8951. this.jitterY = 0;
  8952. this.jitterX = jitterX;
  8953. this.jitterY = jitterY;
  8954. }
  8955. JitterEffect.prototype.begin = function (skeleton) {
  8956. };
  8957. JitterEffect.prototype.transform = function (position, uv, light, dark) {
  8958. position.x += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  8959. position.y += spine.MathUtils.randomTriangular(-this.jitterX, this.jitterY);
  8960. };
  8961. JitterEffect.prototype.end = function () {
  8962. };
  8963. return JitterEffect;
  8964. }());
  8965. spine.JitterEffect = JitterEffect;
  8966. })(spine || (spine = {}));
  8967. var spine;
  8968. (function (spine) {
  8969. var SwirlEffect = (function () {
  8970. function SwirlEffect(radius) {
  8971. this.centerX = 0;
  8972. this.centerY = 0;
  8973. this.radius = 0;
  8974. this.angle = 0;
  8975. this.worldX = 0;
  8976. this.worldY = 0;
  8977. this.radius = radius;
  8978. }
  8979. SwirlEffect.prototype.begin = function (skeleton) {
  8980. this.worldX = skeleton.x + this.centerX;
  8981. this.worldY = skeleton.y + this.centerY;
  8982. };
  8983. SwirlEffect.prototype.transform = function (position, uv, light, dark) {
  8984. var radAngle = this.angle * spine.MathUtils.degreesToRadians;
  8985. var x = position.x - this.worldX;
  8986. var y = position.y - this.worldY;
  8987. var dist = Math.sqrt(x * x + y * y);
  8988. if (dist < this.radius) {
  8989. var theta = SwirlEffect.interpolation.apply(0, radAngle, (this.radius - dist) / this.radius);
  8990. var cos = Math.cos(theta);
  8991. var sin = Math.sin(theta);
  8992. position.x = cos * x - sin * y + this.worldX;
  8993. position.y = sin * x + cos * y + this.worldY;
  8994. }
  8995. };
  8996. SwirlEffect.prototype.end = function () {
  8997. };
  8998. SwirlEffect.interpolation = new spine.PowOut(2);
  8999. return SwirlEffect;
  9000. }());
  9001. spine.SwirlEffect = SwirlEffect;
  9002. })(spine || (spine = {}));
  9003. var spine;
  9004. (function (spine) {
  9005. var webgl;
  9006. (function (webgl) {
  9007. var AssetManager = (function (_super) {
  9008. __extends(AssetManager, _super);
  9009. function AssetManager(context, pathPrefix, downloader) {
  9010. if (pathPrefix === void 0) { pathPrefix = ""; }
  9011. if (downloader === void 0) { downloader = null; }
  9012. return _super.call(this, function (image) {
  9013. return new spine.webgl.GLTexture(context, image);
  9014. }, pathPrefix, downloader) || this;
  9015. }
  9016. return AssetManager;
  9017. }(spine.AssetManager));
  9018. webgl.AssetManager = AssetManager;
  9019. })(webgl = spine.webgl || (spine.webgl = {}));
  9020. })(spine || (spine = {}));
  9021. var spine;
  9022. (function (spine) {
  9023. var webgl;
  9024. (function (webgl) {
  9025. var OrthoCamera = (function () {
  9026. function OrthoCamera(viewportWidth, viewportHeight) {
  9027. this.position = new webgl.Vector3(0, 0, 0);
  9028. this.direction = new webgl.Vector3(0, 0, -1);
  9029. this.up = new webgl.Vector3(0, 1, 0);
  9030. this.near = 0;
  9031. this.far = 100;
  9032. this.zoom = 1;
  9033. this.viewportWidth = 0;
  9034. this.viewportHeight = 0;
  9035. this.projectionView = new webgl.Matrix4();
  9036. this.inverseProjectionView = new webgl.Matrix4();
  9037. this.projection = new webgl.Matrix4();
  9038. this.view = new webgl.Matrix4();
  9039. this.viewportWidth = viewportWidth;
  9040. this.viewportHeight = viewportHeight;
  9041. this.update();
  9042. }
  9043. OrthoCamera.prototype.update = function () {
  9044. var projection = this.projection;
  9045. var view = this.view;
  9046. var projectionView = this.projectionView;
  9047. var inverseProjectionView = this.inverseProjectionView;
  9048. var zoom = this.zoom, viewportWidth = this.viewportWidth, viewportHeight = this.viewportHeight;
  9049. projection.ortho(zoom * (-viewportWidth / 2), zoom * (viewportWidth / 2), zoom * (-viewportHeight / 2), zoom * (viewportHeight / 2), this.near, this.far);
  9050. view.lookAt(this.position, this.direction, this.up);
  9051. projectionView.set(projection.values);
  9052. projectionView.multiply(view);
  9053. inverseProjectionView.set(projectionView.values).invert();
  9054. };
  9055. OrthoCamera.prototype.screenToWorld = function (screenCoords, screenWidth, screenHeight) {
  9056. var x = screenCoords.x, y = screenHeight - screenCoords.y - 1;
  9057. screenCoords.x = (2 * x) / screenWidth - 1;
  9058. screenCoords.y = (2 * y) / screenHeight - 1;
  9059. screenCoords.z = (2 * screenCoords.z) - 1;
  9060. screenCoords.project(this.inverseProjectionView);
  9061. return screenCoords;
  9062. };
  9063. OrthoCamera.prototype.worldToScreen = function (worldCoords, screenWidth, screenHeight) {
  9064. worldCoords.project(this.projectionView);
  9065. worldCoords.x = screenWidth * (worldCoords.x + 1) / 2;
  9066. worldCoords.y = screenHeight * (worldCoords.y + 1) / 2;
  9067. worldCoords.z = (worldCoords.z + 1) / 2;
  9068. return worldCoords;
  9069. };
  9070. OrthoCamera.prototype.setViewport = function (viewportWidth, viewportHeight) {
  9071. this.viewportWidth = viewportWidth;
  9072. this.viewportHeight = viewportHeight;
  9073. };
  9074. return OrthoCamera;
  9075. }());
  9076. webgl.OrthoCamera = OrthoCamera;
  9077. })(webgl = spine.webgl || (spine.webgl = {}));
  9078. })(spine || (spine = {}));
  9079. var spine;
  9080. (function (spine) {
  9081. var webgl;
  9082. (function (webgl) {
  9083. var GLTexture = (function (_super) {
  9084. __extends(GLTexture, _super);
  9085. function GLTexture(context, image, useMipMaps) {
  9086. if (useMipMaps === void 0) { useMipMaps = false; }
  9087. var _this = _super.call(this, image) || this;
  9088. _this.texture = null;
  9089. _this.boundUnit = 0;
  9090. _this.useMipMaps = false;
  9091. _this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  9092. _this.useMipMaps = useMipMaps;
  9093. _this.restore();
  9094. _this.context.addRestorable(_this);
  9095. return _this;
  9096. }
  9097. GLTexture.prototype.setFilters = function (minFilter, magFilter) {
  9098. var gl = this.context.gl;
  9099. this.bind();
  9100. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  9101. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, GLTexture.validateMagFilter(magFilter));
  9102. };
  9103. GLTexture.validateMagFilter = function (magFilter) {
  9104. switch (magFilter) {
  9105. case spine.TextureFilter.MipMap:
  9106. case spine.TextureFilter.MipMapLinearLinear:
  9107. case spine.TextureFilter.MipMapLinearNearest:
  9108. case spine.TextureFilter.MipMapNearestLinear:
  9109. case spine.TextureFilter.MipMapNearestNearest:
  9110. return spine.TextureFilter.Linear;
  9111. default:
  9112. return magFilter;
  9113. }
  9114. };
  9115. GLTexture.prototype.setWraps = function (uWrap, vWrap) {
  9116. var gl = this.context.gl;
  9117. this.bind();
  9118. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap);
  9119. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap);
  9120. };
  9121. GLTexture.prototype.update = function (useMipMaps) {
  9122. var gl = this.context.gl;
  9123. if (!this.texture)
  9124. this.texture = this.context.gl.createTexture();
  9125. this.bind();
  9126. if (GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL)
  9127. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
  9128. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image);
  9129. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  9130. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  9131. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  9132. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  9133. if (useMipMaps)
  9134. gl.generateMipmap(gl.TEXTURE_2D);
  9135. };
  9136. GLTexture.prototype.restore = function () {
  9137. this.texture = null;
  9138. this.update(this.useMipMaps);
  9139. };
  9140. GLTexture.prototype.bind = function (unit) {
  9141. if (unit === void 0) { unit = 0; }
  9142. var gl = this.context.gl;
  9143. this.boundUnit = unit;
  9144. gl.activeTexture(gl.TEXTURE0 + unit);
  9145. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  9146. };
  9147. GLTexture.prototype.unbind = function () {
  9148. var gl = this.context.gl;
  9149. gl.activeTexture(gl.TEXTURE0 + this.boundUnit);
  9150. gl.bindTexture(gl.TEXTURE_2D, null);
  9151. };
  9152. GLTexture.prototype.dispose = function () {
  9153. this.context.removeRestorable(this);
  9154. var gl = this.context.gl;
  9155. gl.deleteTexture(this.texture);
  9156. };
  9157. GLTexture.DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL = false;
  9158. return GLTexture;
  9159. }(spine.Texture));
  9160. webgl.GLTexture = GLTexture;
  9161. })(webgl = spine.webgl || (spine.webgl = {}));
  9162. })(spine || (spine = {}));
  9163. var spine;
  9164. (function (spine) {
  9165. var webgl;
  9166. (function (webgl) {
  9167. var Input = (function () {
  9168. function Input(element) {
  9169. this.lastX = 0;
  9170. this.lastY = 0;
  9171. this.buttonDown = false;
  9172. this.currTouch = null;
  9173. this.listeners = new Array();
  9174. this.touchesPool = new spine.Pool(function () {
  9175. return new spine.webgl.Touch(0, 0, 0);
  9176. });
  9177. this.element = element;
  9178. this.setupCallbacks(element);
  9179. }
  9180. Input.prototype.setupCallbacks = function (element) {
  9181. var _this = this;
  9182. var mouseDown = function (ev) {
  9183. if (ev instanceof MouseEvent) {
  9184. var rect = element.getBoundingClientRect();
  9185. var x = ev.clientX - rect.left;
  9186. var y = ev.clientY - rect.top;
  9187. var listeners = _this.listeners;
  9188. for (var i = 0; i < listeners.length; i++)
  9189. if (listeners[i].down)
  9190. listeners[i].down(x, y);
  9191. _this.lastX = x;
  9192. _this.lastY = y;
  9193. _this.buttonDown = true;
  9194. document.addEventListener("mousemove", mouseMove);
  9195. document.addEventListener("mouseup", mouseUp);
  9196. }
  9197. };
  9198. var mouseMove = function (ev) {
  9199. if (ev instanceof MouseEvent) {
  9200. var rect = element.getBoundingClientRect();
  9201. var x = ev.clientX - rect.left;
  9202. var y = ev.clientY - rect.top;
  9203. var listeners = _this.listeners;
  9204. for (var i = 0; i < listeners.length; i++) {
  9205. if (_this.buttonDown) {
  9206. if (listeners[i].dragged)
  9207. listeners[i].dragged(x, y);
  9208. }
  9209. else {
  9210. if (listeners[i].moved)
  9211. listeners[i].moved(x, y);
  9212. }
  9213. }
  9214. _this.lastX = x;
  9215. _this.lastY = y;
  9216. }
  9217. };
  9218. var mouseUp = function (ev) {
  9219. if (ev instanceof MouseEvent) {
  9220. var rect = element.getBoundingClientRect();
  9221. var x = ev.clientX - rect.left;
  9222. var y = ev.clientY - rect.top;
  9223. var listeners = _this.listeners;
  9224. for (var i = 0; i < listeners.length; i++)
  9225. if (listeners[i].up)
  9226. listeners[i].up(x, y);
  9227. _this.lastX = x;
  9228. _this.lastY = y;
  9229. _this.buttonDown = false;
  9230. document.removeEventListener("mousemove", mouseMove);
  9231. document.removeEventListener("mouseup", mouseUp);
  9232. }
  9233. };
  9234. element.addEventListener("mousedown", mouseDown, true);
  9235. element.addEventListener("mousemove", mouseMove, true);
  9236. element.addEventListener("mouseup", mouseUp, true);
  9237. element.addEventListener("touchstart", function (ev) {
  9238. if (!_this.currTouch) {
  9239. var touches = ev.changedTouches;
  9240. for (var i = 0; i < touches.length; i++) {
  9241. var touch = touches[i];
  9242. var rect = element.getBoundingClientRect();
  9243. var x = touch.clientX - rect.left;
  9244. var y = touch.clientY - rect.top;
  9245. _this.currTouch = _this.touchesPool.obtain();
  9246. _this.currTouch.identifier = touch.identifier;
  9247. _this.currTouch.x = x;
  9248. _this.currTouch.y = y;
  9249. break;
  9250. }
  9251. var listeners = _this.listeners;
  9252. for (var i_17 = 0; i_17 < listeners.length; i_17++) {
  9253. if (listeners[i_17].down)
  9254. listeners[i_17].down(_this.currTouch.x, _this.currTouch.y);
  9255. }
  9256. _this.lastX = _this.currTouch.x;
  9257. _this.lastY = _this.currTouch.y;
  9258. _this.buttonDown = true;
  9259. }
  9260. ev.preventDefault();
  9261. }, false);
  9262. element.addEventListener("touchend", function (ev) {
  9263. if (_this.currTouch) {
  9264. var touches = ev.changedTouches;
  9265. for (var i = 0; i < touches.length; i++) {
  9266. var touch = touches[i];
  9267. if (_this.currTouch.identifier === touch.identifier) {
  9268. var rect = element.getBoundingClientRect();
  9269. var x = _this.currTouch.x = touch.clientX - rect.left;
  9270. var y = _this.currTouch.y = touch.clientY - rect.top;
  9271. _this.touchesPool.free(_this.currTouch);
  9272. var listeners = _this.listeners;
  9273. for (var i_18 = 0; i_18 < listeners.length; i_18++) {
  9274. if (listeners[i_18].up)
  9275. listeners[i_18].up(x, y);
  9276. }
  9277. _this.lastX = x;
  9278. _this.lastY = y;
  9279. _this.buttonDown = false;
  9280. _this.currTouch = null;
  9281. break;
  9282. }
  9283. }
  9284. }
  9285. ev.preventDefault();
  9286. }, false);
  9287. element.addEventListener("touchcancel", function (ev) {
  9288. if (_this.currTouch) {
  9289. var touches = ev.changedTouches;
  9290. for (var i = 0; i < touches.length; i++) {
  9291. var touch = touches[i];
  9292. if (_this.currTouch.identifier === touch.identifier) {
  9293. var rect = element.getBoundingClientRect();
  9294. var x = _this.currTouch.x = touch.clientX - rect.left;
  9295. var y = _this.currTouch.y = touch.clientY - rect.top;
  9296. _this.touchesPool.free(_this.currTouch);
  9297. var listeners = _this.listeners;
  9298. for (var i_19 = 0; i_19 < listeners.length; i_19++) {
  9299. if (listeners[i_19].up)
  9300. listeners[i_19].up(x, y);
  9301. }
  9302. _this.lastX = x;
  9303. _this.lastY = y;
  9304. _this.buttonDown = false;
  9305. _this.currTouch = null;
  9306. break;
  9307. }
  9308. }
  9309. }
  9310. ev.preventDefault();
  9311. }, false);
  9312. element.addEventListener("touchmove", function (ev) {
  9313. if (_this.currTouch) {
  9314. var touches = ev.changedTouches;
  9315. for (var i = 0; i < touches.length; i++) {
  9316. var touch = touches[i];
  9317. if (_this.currTouch.identifier === touch.identifier) {
  9318. var rect = element.getBoundingClientRect();
  9319. var x = touch.clientX - rect.left;
  9320. var y = touch.clientY - rect.top;
  9321. var listeners = _this.listeners;
  9322. for (var i_20 = 0; i_20 < listeners.length; i_20++) {
  9323. if (listeners[i_20].dragged)
  9324. listeners[i_20].dragged(x, y);
  9325. }
  9326. _this.lastX = _this.currTouch.x = x;
  9327. _this.lastY = _this.currTouch.y = y;
  9328. break;
  9329. }
  9330. }
  9331. }
  9332. ev.preventDefault();
  9333. }, false);
  9334. };
  9335. Input.prototype.addListener = function (listener) {
  9336. this.listeners.push(listener);
  9337. };
  9338. Input.prototype.removeListener = function (listener) {
  9339. var idx = this.listeners.indexOf(listener);
  9340. if (idx > -1) {
  9341. this.listeners.splice(idx, 1);
  9342. }
  9343. };
  9344. return Input;
  9345. }());
  9346. webgl.Input = Input;
  9347. var Touch = (function () {
  9348. function Touch(identifier, x, y) {
  9349. this.identifier = identifier;
  9350. this.x = x;
  9351. this.y = y;
  9352. }
  9353. return Touch;
  9354. }());
  9355. webgl.Touch = Touch;
  9356. })(webgl = spine.webgl || (spine.webgl = {}));
  9357. })(spine || (spine = {}));
  9358. var spine;
  9359. (function (spine) {
  9360. var webgl;
  9361. (function (webgl) {
  9362. var spinnerImage;
  9363. var logoImage;
  9364. var loaded = 0;
  9365. var FADE_IN = 1, FADE_OUT = 1;
  9366. var logoWidth = 165, logoHeight = 108, spinnerSize = 163;
  9367. var LoadingScreen = (function () {
  9368. function LoadingScreen(renderer) {
  9369. this.logo = null;
  9370. this.spinner = null;
  9371. this.angle = 0;
  9372. this.fadeOut = 0;
  9373. this.fadeIn = 0;
  9374. this.timeKeeper = new spine.TimeKeeper();
  9375. this.backgroundColor = new spine.Color(0.135, 0.135, 0.135, 1);
  9376. this.tempColor = new spine.Color();
  9377. this.renderer = renderer;
  9378. this.timeKeeper.maxDelta = 9;
  9379. if (!logoImage) {
  9380. var isSafari = navigator.userAgent.indexOf("Safari") > -1;
  9381. var onload_1 = function () { return loaded++; };
  9382. logoImage = new Image();
  9383. logoImage.src = SPINE_LOGO_DATA;
  9384. if (!isSafari)
  9385. logoImage.crossOrigin = "anonymous";
  9386. logoImage.onload = onload_1;
  9387. spinnerImage = new Image();
  9388. spinnerImage.src = SPINNER_DATA;
  9389. if (!isSafari)
  9390. spinnerImage.crossOrigin = "anonymous";
  9391. spinnerImage.onload = onload_1;
  9392. }
  9393. }
  9394. LoadingScreen.prototype.draw = function (complete) {
  9395. if (complete === void 0) { complete = false; }
  9396. if (loaded < 2 || (complete && this.fadeOut > FADE_OUT))
  9397. return;
  9398. this.timeKeeper.update();
  9399. var a = Math.abs(Math.sin(this.timeKeeper.totalTime + 0.25));
  9400. this.angle -= this.timeKeeper.delta * 200 * (1 + 1.5 * Math.pow(a, 5));
  9401. var tempColor = this.tempColor;
  9402. var renderer = this.renderer;
  9403. var canvas = renderer.canvas;
  9404. var gl = renderer.context.gl;
  9405. renderer.resize(webgl.ResizeMode.Expand);
  9406. renderer.camera.position.set(canvas.width / 2, canvas.height / 2, 0);
  9407. renderer.batcher.setBlendMode(gl.ONE, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  9408. if (complete) {
  9409. this.fadeOut += this.timeKeeper.delta * (this.timeKeeper.totalTime < 1 ? 2 : 1);
  9410. if (this.fadeOut > FADE_OUT)
  9411. return;
  9412. tempColor.setFromColor(this.backgroundColor);
  9413. a = 1 - this.fadeOut / FADE_OUT;
  9414. a = 1 - (a - 1) * (a - 1);
  9415. tempColor.a *= a;
  9416. if (tempColor.a > 0) {
  9417. renderer.camera.zoom = 1;
  9418. renderer.begin();
  9419. renderer.quad(true, 0, 0, canvas.width, 0, canvas.width, canvas.height, 0, canvas.height, tempColor, tempColor, tempColor, tempColor);
  9420. renderer.end();
  9421. }
  9422. }
  9423. else {
  9424. this.fadeIn += this.timeKeeper.delta;
  9425. if (this.backgroundColor.a > 0) {
  9426. gl.clearColor(this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a);
  9427. gl.clear(gl.COLOR_BUFFER_BIT);
  9428. }
  9429. a = 1;
  9430. }
  9431. a *= Math.min(this.fadeIn / FADE_IN, 1);
  9432. tempColor.set(a, a, a, a);
  9433. if (!this.logo) {
  9434. this.logo = new webgl.GLTexture(renderer.context, logoImage);
  9435. this.spinner = new webgl.GLTexture(renderer.context, spinnerImage);
  9436. }
  9437. renderer.camera.zoom = Math.max(1, spinnerSize / canvas.height);
  9438. renderer.begin();
  9439. renderer.drawTexture(this.logo, (canvas.width - logoWidth) / 2, (canvas.height - logoHeight) / 2, logoWidth, logoHeight, tempColor);
  9440. renderer.drawTextureRotated(this.spinner, (canvas.width - spinnerSize) / 2, (canvas.height - spinnerSize) / 2, spinnerSize, spinnerSize, spinnerSize / 2, spinnerSize / 2, this.angle, tempColor);
  9441. renderer.end();
  9442. };
  9443. return LoadingScreen;
  9444. }());
  9445. webgl.LoadingScreen = LoadingScreen;
  9446. var SPINNER_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKMAAACjCAYAAADmbK6AAAALKElEQVR42u2de2iW5R/GPzuqcwfnnKfNmafl5tTNHWzqNi3DEMQykcAoJSsySkspjSIk0iD/07Kf4R+FnVBDUTshZGpWUEJaaiWFgZlUFmXmIe3HNXthyebeZ77P9H13ffBG8Y8H7ut7vff93N/7fu4vGGPiFZiez/Qtw9lytJajfzfw9z/j+efPOv7cV8W+lUNY2a8T/ayTCRsWFLJA5rtUO1LLkV5p9LJeJizQiHeqnlOtmVFtdTGrrZkJCxYXsTgaI6r9MY4/UpNItW4mFDaXsTlaM6qVZlBq3UwofFrJp0HMWJ9DvXUzobCznJ1BzFjWlTLrZkJh/TDWBzFjTgo51s2EgnKI0Rrx+FiOWzNzVaym91Syx5qZsGBWb2ZFa0ZN6dbMhAWTcpkUrRmXD2K5NTNhgVbH0Zpxbl/mWjMTFvRIo0e0ZpzcncnWzISKtvmiMWNRJ4qslwmVXRXsas2Ix8ZwzFqZsGFREYtaM+Oaa1ljrUzYkJ9G/ok6TlzKjJWZVFor0y7c1Zu7WjLiqiGsskamXdHopyT4vALmzS9k/t19uHtKHlOSIMn6xAtARjIZ1sFcUSZ0Y4La+G6M18hS2IlCn4a+WoC0JNL0d/dUupdnUj40g6EJ2VEdMnhrOG/p5f/jUXz8SgmvaGU6KpNRNsLVQV0OdXf24s63h/P2gWoOrBjMCr2GJFQnnxnIM3q5P1PPmaYv+4ev4/C6UtbpV2gzXCkgL5W8Bwt48OIc6ul6Tp+s4+SyASxLiI4+PYCn1bHzDZxvaQW6vZzto7MYnQIpNkf7kp5EuozYUroqEjcNKHHd0Tl9mBPN1pk+hFeieGBnBtog7UXjsj9pWg+m6duecw2cay1OC/uxMC47KmP9OIYfoz1YoC20J/rzRG4quTZK2EAyJGs20qwUbYw0aNRmUxtvfUW/uEtNzc1NB1/X8LVyd15hh82F43AvD+VlXcsSJEZa1CQ3ejleAO7oxR3RDP0XN91X4+NXYb8nkv7UNTwV7e0YTdu7I3g33t7tuaEbNwSZpps2fSyvs4M2Tjhot+jb0Xzbltj8r5j/xVt/6Z1Ob93U1ZYO691EhhzchcHeXosVjcNZysyezLw4xRZt05R+fTeuj8vOj+zKyG0j2aZcVVs6v+QalnjrMFZASQYl2nBoSyz06e3j/Xk8rgWYmMvEICu2pm1HOTuc7okV8FgRj0XukwzanhvCc/F+72TjoQjdObN1OFuDLmh0xP+WHtxiI10ukJlCprb4guiv1fP+avZrS1C7NAkliHZjDtZwMMgqbukAltpMlwuMy2FcEBPqvfLLar5Uqi0hBdEwryy+Mv5n6zkbjTBa+dlMlwvUZFETZKGiFM7tvbhdJ3gSVRO0wzIjnxmvl/J6a6JsGMYGrahtpssFeqbR841S3mhN80OjOaSDEdqd6SjaMKgzgzRK7q1ib3PT9sYyNo7JZoyNFNvRcVMZmy7WOvIuryv/Zvdmdt90+nY0bRp3AvROohFwdwW7dTG7RFlbwlqdrbOBYg005NAQmZU0HWt1rXMBH1Xw0dQ8pmqzoaPmdhun7bHZjNVe9qP9eFQfO1VkUmHjhAVUZ1GtnKFSbjrkrPfy4i4UW5t/6ZxM54J0CqxFe81KpGsQyE4h23oYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjLna+bdOy+IiFquIpGq16Pb79cNYv3IIK/X/ugx+Ui6TVKvYVU9Nc8gX8od8Ir/IN/KPfCQ/yVfyl/6/pfJvLChkQdD6wyqntquCXYuKWJSfRr6D0dEAxV3xlw/khyD+kd/ku/88cHo+09tS3LBpO1HHCVUqcIA6CqB4K+6X6x35L/JM2loXurlWmUmlA5XogOIcK8/If5HncrSWo7F6cKIWPjT/RXGOlWfkv8hzaWsN4uaaysE6WIkOKM6x8oz8F3kusXqo2vxC5jtYiQ4ozrH0TeS5qIZcrB7qkrwdA8U5Vp6R/yLPZV8V+2L14Cl5THGwEh1QnGPlGfkv8lyUlIzFQ1cNYVVHrcjZ0VCcFe9Y+Eb+izy3ceclUl43aFN52DXXssYpnY6a4qFS8ZcP2uIf+e7inRh6pdFrdTGrm8uiHx/L8T2V7NGWzvJBLJ/bl7mTuzO5qBNFDoiJID/IF/KHfCK/yDfyT3O7d/KbfNfS80hNIrU0g9L6HOq1x5iTQo6FNpeLfCQ/yVfyl3xmXYwxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHGGGOMMcYYY4wxxhhjjDHNk9z4JwJ0SqKTdQkbyEwhU393T6V7zzR6pieR3tE1ITeVXImhe6BXDGZFdRbVeank2TBhcaEMr0rwbixj49IBLL2/L/ffmMuNHfqO9tFZjJYBd1ewO3Lx+IcVfKhqna5nHZYR6XFPH+5R3eeI5t9fx/fvjeC9Jdew5OKZKqFR/RDVKL6vL/f9PJafmyvHsL+a/ff24V6NmjZQbGchVbY6UM2BluqHv1rCqzVZ1KQlkZboepCdQvacPsz5bjTfXao+yMEaDt7Wk9tSIMVGig3TejCtJSM2bSpkPjWPqd1S6Zao+lORSYWmgkOjORRNwZqd5ezMSiHLRooNr5XwWjS6/1XHX9vL2T67N7M1iyXa9JCrYjVrS1gbpJyw6hBfsmiNCYT0P9/A+Wj1/6qGr5YNYFlJBiWJogEzezLz/ZG8/9s4fgtSyuvNYbyp1IONFBtu7sHNv4/j9yAxUHWrdaWsG9+N8XHd+YxkMpSy+aySz841cC5oXbmHCnnI74yxAgZ3YbDeB4PEQCOpBpFNZWwa2ZWRcdnxLsl00crtRB0n2lLg8JNRfDKoM4NsolgBSmw/UMADba1+qpmqfyf6x1u/0a/og3I+aEunP6/i86osqmygcGarF4p54dex/Bo0LqfqOfVwIQ/HW5/RSkwV1oN2WLlHTc82TljAwM4M1O5LWwYKZTjibYXNS0N5KcjKTe10PadfLObFuJwK4ozp+UzXDBTUjL+M5ZcBnRkQV53dMIwNQTu6bSTbVEzbi5awuVByd2E/FgaN0Tc1fKOzBHHV2aAdVSdv6s5NNkp7cSH/++xAng2yyHx+CM/H21YhfdPp+0U1X0TbSZnXx8faG9Aop0MS0cToh1p+iLcpOkLj9t/JOk5eqoPHxnDsyf486an5yqCDK7XZ1O4oZ4dWyy3FSXHUAYq47uyYbMZoGmhpG3DlEFb6uNiVBhpyaHhnBO8oJmfqOROJjzIiP43hJ8UxITqqX56S2Hur2KsOnq3nrE6PPNKPRwrSKbAZrjTQNZmuE7oxYXMZmxWbw9dxWFu4W4ezVedOE6qzI7oyYkY+M7TPeWsPbk2UX1qioSN+E3OZqOR2cReKE+qQRFN0Pi7y73g/UawU1KzezJpXwLz5hczX1ueUPKYkNb6GJQZ+j7/aAfRZREsv+quGsMoamXZBW2Gt5eU0alorEzYsKmJRa/m4NdeyxlqZsCGa84DKnVorEzboC7podis69DfIJmwufHMc7famvvmxZiYsKOtKWbRm1OcW1syEBboSJFozLh/EcmtmwgIluaM14/phrLdmJixYXMTiaM24p5I91syEBTphFOR7Y2tmwgJNvUFOr+tov3UzoaAv44KYUatv62ZCoemdhtG0+hzqrZsJBR08DWLG0gxKrZu50qvpxos3U5NItW4mFPp1ot+lPlpq2lYXs9qamVBZUMiC1ox4pJYjvlfStAu6GmTLcLboMtPIV4/6im5fFfuUi9QIap2MiWP+D96R1vPmsD/fAAAAAElFTkSuQmCC";
  9447. var SPINE_LOGO_DATA = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKUAAABsCAYAAAALzHKmAAAQ7klEQVR42u3da4xdVRUA4D0zd2Y6nZY59DVtZ1puS9+lzC0YAi2UQ8AAQczFpPgA9VIeIQbirRqJ0cBUBVGjDr/QCKSNRSMmpuODxAdxqhgwxkhFjf6Sxh/+UUNVNGJCzR7uTvas7LXX2q9zzp3em6y0gTN3Zu75utZe5+yztxC9V+/Ve5X9En1Vjd7J6SFbLNF7naPw+l2jh7YHMBWssqMHtlsRdim4qsLtIawaPiHEQOLoNrA9iIkQDnRrVA1qD2LZ8ISoxYqKo13sQAtBWBayQWZUAXGRQM9JjCngDVY0UqJNDbQrMcaGmArdUKpIjbYiQLsCZCyIMQBy8QwnilR4Q5AuCpxFYvRFmBLbEiwKwpsSaWycVQGZBKMrwBjA9BhxDe57u2L2hOoKNCbOrgAZitEVYUxoKSMErQvSxYIzCkguRg5EF4AUhqUlhy/YUKSxcRaKsioYOQhD4I0yYxkR3PcJBcuFysmgsXAWBTMJyBCMIQh9kGGxXIXvexCQXbHGAMrBWTbM2CCpMSMLIxehC77lSJwXGth7M0FzoVJIXXDWQnGmhOkL0ic7YhhtWdGGkAuPAjUWGoF4faCmwBkbZmyUqUCyMqMLRA4+E6IsdTjidUHKBYrh9CnpRcH0ypKxsyOGEYNIIeTCOz91OIJ1QYoB5eAMyZo+MFNnyVTZ0YiRC9EGEMOyAgshxErHsL2XK1gOUgwohtM1a5YNM7Rsu4K0ZkcbRm4mpPBRwFZ5hg9eCqkrUB+csWGGogzNkqEgrdnRhpGLkINudaLgwvVB6oqzCjCTZElb2Y4B0gUjBtEG0ARnDRLjjoG9DwcshtQGlIPTljVjwUySLWNkyRCQVHa0ZUUTRAwgF91a33BEy0VKAcVwwqwZC2bqbOlUurllOxQkJzNyINoAYqjWhYYjWg5SCiiG05Q1U8FMjTIoS8YE6YORi1BHtJ4KIcQEEtTXUWAxpK44YVlPBdO1jCdFWTZIE8bVGEYMIRPcZGBw4HKQcoBiOE1ZMzbMgVQwU6JMAdKEEcuIJogUvg1YCCE2gsCO42DlIIVAKZwpYJaSLVNnSU6XjYHUmxhTmXaFaMO3EYkLqMC+FsLlIoVAKZzMrEnBhJeLfLNlKMrYWRIDCbOkFSSVHbHM6AKRC6/ODUewNqQ+OLlZkxpjUmV8MBbMUJSxyzY3Q1IgTRgxiBRCHdem0KDAUkBh9sRwwjEnAXMMgTnKhFlUtiwkS5rGka4g9SaGgxFmRC7AzTCEEBcyA36dDSsXqAtOLkysjGMwY5XxVChjZ0kuSCo7YlkRQsQQYtDEFsegsLoCxUp7Kpgps2UslFGzJGccSYHUmxhOZqwzEZqAbfUMCisHKIZzgsCpl3MTzMwTpi1bYp2477gyFKUxS7qWbdjY2EBS2dGE0QQRA7gNCyHEdhjE8RhUDlBT9tzgmjWZMFNlSy+Urk1OzCyJlW0XkK4YOQh1cDtcgwBrQmoDWkdgboBZE8mYsJSHlnFbJ+5bwmOPJ7lZkirbC8aRsMvmgtTHjBhGE0QbwJ2egUE1ITVlUC5OmDVdYNrKuN70xM6WoShjlW4464dbtiFIWK6x7GjESEHUUe0iYncnbMdQSE0Z1ITTNOb0hRmjjLtmS9dmJ2rp1jtuKktyyrb6YLEMCUHq2dGG0QQRQ7f72kzc+cJecerne8Wvv7JNPHPvenEkz8Sh3UtFc92QyGt9Yko/HgOLAIUZlItTz5ouMF3KuE+2jFLCQ1D6lm6fLMkBacuOJowYRBUXyfjuHjF3NhdnsfjvAfH6E9vFt9XxKgikEKgJZyyYalzOLeMu2bLbULI6bh+QGwmQ+rgRlumdGEQAao+K56bEL2woVUwOiev0r8OAUjiJrMmFCbvykGxZRAmPitK1dHM7bohyMsuyi/I8f0+e57fJYIKEZXpXo9E4mOf5XTKyLLvCBLETF8uY2SKepkC+dpX4T02Ivepr4HvZcOZ5fmee54fyPL+DmTUhzAs6n4n8bN5dr9f3YdkSg8nsxG0lPBVKVpNjG0/aGhzfLDmRZdnumZmZp8+c+cdZPV555fSr7Xb7s0jJ3i5Pcue4MxKkPPkvvXTqz/B92u32l0wYOzG1fkhcd/py8Rcbyq/vFM/KY1WA95h/3zzP71bfU6JsNpsfgj+P/FlbrdaDGExYyuXvLz8H+DudODH700ajcSM3W6Yu4alQ1spCOTd38jcKocTZbh9+9NixY99XJ8AEUkcpo9W64yH197m5k7+bnZ19QT+J09NHntQhwji/Jg58qi6++ofLxJ8gSFneVw2Ka4QQDfh1Ok4dZavVmtZ/nrm5k7/Vf55O1tRhboUw5+ZOvqyOl5+R/FyOHj32PYVU/tloNG5IXcKrhJIzngwp3fNjomazea/64BuNxts646f50lWv169utw9/DmtqdJQyZFaSJVuV6nq9fqMEof5/vV6/CYBqgJDlee+yAbF/+4i4ZWqZeNfaIfHWzn+Hx0KcEuU9+s8jv3ej0bhVlXOZydX/k0iRMeb8P0D5e6tj8zy/Xb9UJIc56h/yqVOnXul8lmuZ2bJslKmbHG7XrbpCmCXFRLvdfqQD6jTS3Jiy5I4OykM6ADV+1Eu1DmV6evopBORexzDi1L+X/HnGxsb2w3Hm9PSRJ9QxWPOTZdmlKht2hi+w6dkox5bqffI8fye3hDteGqKaHVsHXihKl0tB+h0cY+lute54AGRKDCW89LNTRynHb7ChUWVVjetOnJh9EYBUyPZeNCoOtsbFQwdXi4/esELcd+tq8cCHJ8UXp+viy9efLz7AgamjlKXc1AA1m83DoIRDlFubzeb96hhZLVTlgJ24gttutx+ONa50bHZKRenaeTs1OfpAfnr6yOOdE7EZdNwmlKocntXLNkA5JTGq47Ds+Lf94lWsyfnXleLfnIwJUN4DOnNYwuUxh2A3Ln9XULrfK8t3J27Tu3BVwiOjXJqoAy8UZej1yclGo3GTLN+gu3w+z/P3YaWbQqk3Ne12e4ZC+c8rxWsYytcPiP9RpZxCqWDKnxOiBNlyAUpOnGsoh4tA2Rm8X9xqtT6md5wyZmYe+0YRKL+1S/wYQ3n8zctBl5SBUv5djivfjMOPduIzcizeiYfr9foVvUwZG+XCuzibZKnSceZ5/v4QlKp8y7ElhnJlTeTP7BI/kllRYfzrfvHqFy4UX1vaL/aVlSmROzwbwdS29T2UcEwZF+V8ozM2lu1VY812u/15akypGh3TmFJesJbHHD167IdUxz3YJy5bNySuX1mbvy55CbMLtzU6tjGlsdFptVqfUMc0Go23F4wy1l2dSnbfvpMwVPe9WWVLDsrOJaF9MFu2Wq1PqmNkGce67xiXhTjdNwdlvV6/BgxfbPfBfVCetxi6b9/rlCup65QzM48dl2OjLMv26CibzeZ96sTIzEFdpwQXz9U1yrtVlpR/Zll2Fec65Y6l4pbbx8XHH9kknvzJlPjlHy8Tp29eKT5ou0aJoIT3w3dBlLDzVpfAJEZ1XOdaJZxnOSlvPMjPzxFljIvng914RwebsjYO7uhMyHu46sOfnf3Oz2TXDW6vvYxdFoIXz3Wc8J5zs9n8iOn2IrxTc2BM3Glqdp7dI553uaOjxrhwcob+MyuUpjs6WZZdon8OcigjPx8V+u+GTWFTSWEx3WYcdJ225jNDSE4q0GHCzlueHOyujn6bUWYgeb9ZZUaQPe+GzQ+Gc8+oOGhC+c1d4gfI16n3XDAhQ7+9qE9l01E2Go132GYKyXE1NiFDTcpoNpv3LOYJGWXNErJNW9sEp63p2RKiVPMn1bS1DgxsyhoGdGpmizj+xtXiDYnx7/vFmce3iWdW1cTVGEY4hQ2ZW0nNq8Qm/M6XbXm3S100lwGedFybuvNOibLI+ZS2ceU4eAxiEuvCkfmU8ycToDxETe6FgCBQHeqyAbFvfEhcO7BwDuXFCEbTZF840XeHK0jYcbs2OIGle0mVJ/mmnClEPQqxyTY5I8/zFhif7fSZee4bnrPOU4AssnRXHaVTCTd14dRDY3UbTIiSeFhsN/aMjgnqthFx880rxX3yATL5p3y4LPXzOaBkUyBjZMlYpbtQlIOBD475ZEusjMNSvkXe6VEoJVDkeZ2dzIfIFsRzU+JF2OyM9M9fTC/6SUYOyFQPjQ2nWiUjxnPfw5EeHqMWIqAeIFsAU847lJM2JM6xsewt1OIDLs99P7ZFHNdB/upS8XtPiD7PfLuCXJNolYyyFiNI/Zit65ItrOVafFbHcFohY7hPTN21Tjz4uc3iqfsnxKdX1MTl1OoYRFaMsToGB6Trw2JFP/OdZC2hJZ7ZkrMoAbbSGmelDJ91hFKuJeS7jlBMkJnrAqqJlgMUZS/dArPlGHNdSg5M3xXXtvquuEatvIYtDRhpxbUJuIgqsU5lGWtUploK0KuEU9mSW8YpmFQ556xNuYW7NiW13B+FkMiKHIy+C6eGgBxJvMR0oSv5hi6+z4HJyZoU0M2RVvDlrOQbcxVfX5AhZbuqy0v7ZstYMLHlAVlLTF9ALLbvu9Y5Zylpn/XOsd0ibIvxr2KCLHpp6SCUIdnSZSF+WzfOhem6GD+1KwR3Z4jNjrtDpNoZwmWd8yrupZN6Hx3fbMmFSe0Swdq2ZIPjxk1112Duo8OBGLrBkw/IoncdK2XHsdC9dHz204m50xh3tzFq1zFqtzHXrfCw7OgDsqyNnZLszVijsmXgrmNcmGtS78lIoMX2aJz03fKO2sDJddPQSCDPiQ1DfWBycY6XtXstc2PQKuxgG2McmXTPb9/9vmuJYXKyJrWjbeg+3xPM4O73nWqvbyw7xgZZSJbEUBa157cNJjdr2vb+5iA1YV3HxYscj30PDCEHIgcjtfm8K8hSsmRotkwFk5s1TTghUAopB6xrjHMBBkI0YYTZ0dZlxwLpkiWDULpmy5gwqayZgZNkA7oKQQCxctByYg0XIIEQQuRitGVHblMTA2ShKGPDpC6wu+DEgJqg2rDGDBtAF4Q6RAojp1xXGmSMbImVcR+YWNY04eQCtUG1ofUJ2/uvcETIgUhhdAE5GAlkKShjwHTNmhhODKgJqQ2sC14uOgyfD0IbRF+MlQaZAiZWyn2yJsTJATqGnHQO2Jhh+xlsACFCG0QbRtdyzQFZCZSxYPpmTS7Q5cjJHYNBYIkZpu99HoUQ/o4QIYSIZUZfjJ4ZMjZI32wZBDMU5yhy8pZTULl4XYP5fagMyEVoy4oupTpGduwnkloSlKEwY+AcQU4MhRTD6ovXBRwFzwWgCSEF0QVjJUGmgEllTS5OLlCIlIN1mS9mx/cZ5eLDALpCTI2RAhkTZQqYoTgpoCPECbaBHQ2ETL3PUl98ECAXYijG0OyYAmQoTG7W5ODkAF1CnVgm2JQx4okPA+gCMTbGskBGgRmaOblAh5GTORIrfKFx4VH4EIAxIXIxlg2SBbMvECY3e7oApbDaIgQu5/2HmeEKEINYiwSRi7EQkLFgumZOCuggctKGI4ULZN/vMeSLj0AYMytWEqMLzFg4fYDaoKaC6wvOFR4FkIPQFaILxrJAOsHsc/zlfYDWXE8qF22s8Pz5KHxcgEVALBtjJXBSSEOwFhk1Zgy4hitCT4hVw+gFs8/zwxqIBbUgyK7fcyA0PD9XX4iVxhiC0xdof6STWCsoBmKF7+cVCWFXQYyBMxRpf+STX1b0x45AhN0OMSrOGEirhrY/dfQAdjvS7oy+WCF6r1RIFxXWvlTRg1YVqFWBmxZbD99ig9pt0YPQw9rD1nstVri9V+/Ve3XrS/wfim4P5fIFxLoAAAAASUVORK5CYII=";
  9448. })(webgl = spine.webgl || (spine.webgl = {}));
  9449. })(spine || (spine = {}));
  9450. var spine;
  9451. (function (spine) {
  9452. var webgl;
  9453. (function (webgl) {
  9454. webgl.M00 = 0;
  9455. webgl.M01 = 4;
  9456. webgl.M02 = 8;
  9457. webgl.M03 = 12;
  9458. webgl.M10 = 1;
  9459. webgl.M11 = 5;
  9460. webgl.M12 = 9;
  9461. webgl.M13 = 13;
  9462. webgl.M20 = 2;
  9463. webgl.M21 = 6;
  9464. webgl.M22 = 10;
  9465. webgl.M23 = 14;
  9466. webgl.M30 = 3;
  9467. webgl.M31 = 7;
  9468. webgl.M32 = 11;
  9469. webgl.M33 = 15;
  9470. var Matrix4 = (function () {
  9471. function Matrix4() {
  9472. this.temp = new Float32Array(16);
  9473. this.values = new Float32Array(16);
  9474. var v = this.values;
  9475. v[webgl.M00] = 1;
  9476. v[webgl.M11] = 1;
  9477. v[webgl.M22] = 1;
  9478. v[webgl.M33] = 1;
  9479. }
  9480. Matrix4.prototype.set = function (values) {
  9481. this.values.set(values);
  9482. return this;
  9483. };
  9484. Matrix4.prototype.transpose = function () {
  9485. var t = this.temp;
  9486. var v = this.values;
  9487. t[webgl.M00] = v[webgl.M00];
  9488. t[webgl.M01] = v[webgl.M10];
  9489. t[webgl.M02] = v[webgl.M20];
  9490. t[webgl.M03] = v[webgl.M30];
  9491. t[webgl.M10] = v[webgl.M01];
  9492. t[webgl.M11] = v[webgl.M11];
  9493. t[webgl.M12] = v[webgl.M21];
  9494. t[webgl.M13] = v[webgl.M31];
  9495. t[webgl.M20] = v[webgl.M02];
  9496. t[webgl.M21] = v[webgl.M12];
  9497. t[webgl.M22] = v[webgl.M22];
  9498. t[webgl.M23] = v[webgl.M32];
  9499. t[webgl.M30] = v[webgl.M03];
  9500. t[webgl.M31] = v[webgl.M13];
  9501. t[webgl.M32] = v[webgl.M23];
  9502. t[webgl.M33] = v[webgl.M33];
  9503. return this.set(t);
  9504. };
  9505. Matrix4.prototype.identity = function () {
  9506. var v = this.values;
  9507. v[webgl.M00] = 1;
  9508. v[webgl.M01] = 0;
  9509. v[webgl.M02] = 0;
  9510. v[webgl.M03] = 0;
  9511. v[webgl.M10] = 0;
  9512. v[webgl.M11] = 1;
  9513. v[webgl.M12] = 0;
  9514. v[webgl.M13] = 0;
  9515. v[webgl.M20] = 0;
  9516. v[webgl.M21] = 0;
  9517. v[webgl.M22] = 1;
  9518. v[webgl.M23] = 0;
  9519. v[webgl.M30] = 0;
  9520. v[webgl.M31] = 0;
  9521. v[webgl.M32] = 0;
  9522. v[webgl.M33] = 1;
  9523. return this;
  9524. };
  9525. Matrix4.prototype.invert = function () {
  9526. var v = this.values;
  9527. var t = this.temp;
  9528. 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]
  9529. + 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]
  9530. - 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]
  9531. - 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]
  9532. + 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]
  9533. + 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]
  9534. - 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]
  9535. - 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];
  9536. if (l_det == 0)
  9537. throw new Error("non-invertible matrix");
  9538. var inv_det = 1.0 / l_det;
  9539. 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]
  9540. - 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];
  9541. 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]
  9542. + 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];
  9543. 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]
  9544. - 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];
  9545. 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]
  9546. + 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];
  9547. 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]
  9548. + 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];
  9549. 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]
  9550. - 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];
  9551. 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]
  9552. + 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];
  9553. 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]
  9554. - 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];
  9555. 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]
  9556. - 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];
  9557. 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]
  9558. + 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];
  9559. 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]
  9560. - 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];
  9561. 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]
  9562. + 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];
  9563. 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]
  9564. + 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];
  9565. 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]
  9566. - 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];
  9567. 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]
  9568. + 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];
  9569. 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]
  9570. - 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];
  9571. v[webgl.M00] = t[webgl.M00] * inv_det;
  9572. v[webgl.M01] = t[webgl.M01] * inv_det;
  9573. v[webgl.M02] = t[webgl.M02] * inv_det;
  9574. v[webgl.M03] = t[webgl.M03] * inv_det;
  9575. v[webgl.M10] = t[webgl.M10] * inv_det;
  9576. v[webgl.M11] = t[webgl.M11] * inv_det;
  9577. v[webgl.M12] = t[webgl.M12] * inv_det;
  9578. v[webgl.M13] = t[webgl.M13] * inv_det;
  9579. v[webgl.M20] = t[webgl.M20] * inv_det;
  9580. v[webgl.M21] = t[webgl.M21] * inv_det;
  9581. v[webgl.M22] = t[webgl.M22] * inv_det;
  9582. v[webgl.M23] = t[webgl.M23] * inv_det;
  9583. v[webgl.M30] = t[webgl.M30] * inv_det;
  9584. v[webgl.M31] = t[webgl.M31] * inv_det;
  9585. v[webgl.M32] = t[webgl.M32] * inv_det;
  9586. v[webgl.M33] = t[webgl.M33] * inv_det;
  9587. return this;
  9588. };
  9589. Matrix4.prototype.determinant = function () {
  9590. var v = this.values;
  9591. 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]
  9592. + 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]
  9593. - 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]
  9594. - 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]
  9595. + 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]
  9596. + 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]
  9597. - 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]
  9598. - 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];
  9599. };
  9600. Matrix4.prototype.translate = function (x, y, z) {
  9601. var v = this.values;
  9602. v[webgl.M03] += x;
  9603. v[webgl.M13] += y;
  9604. v[webgl.M23] += z;
  9605. return this;
  9606. };
  9607. Matrix4.prototype.copy = function () {
  9608. return new Matrix4().set(this.values);
  9609. };
  9610. Matrix4.prototype.projection = function (near, far, fovy, aspectRatio) {
  9611. this.identity();
  9612. var l_fd = (1.0 / Math.tan((fovy * (Math.PI / 180)) / 2.0));
  9613. var l_a1 = (far + near) / (near - far);
  9614. var l_a2 = (2 * far * near) / (near - far);
  9615. var v = this.values;
  9616. v[webgl.M00] = l_fd / aspectRatio;
  9617. v[webgl.M10] = 0;
  9618. v[webgl.M20] = 0;
  9619. v[webgl.M30] = 0;
  9620. v[webgl.M01] = 0;
  9621. v[webgl.M11] = l_fd;
  9622. v[webgl.M21] = 0;
  9623. v[webgl.M31] = 0;
  9624. v[webgl.M02] = 0;
  9625. v[webgl.M12] = 0;
  9626. v[webgl.M22] = l_a1;
  9627. v[webgl.M32] = -1;
  9628. v[webgl.M03] = 0;
  9629. v[webgl.M13] = 0;
  9630. v[webgl.M23] = l_a2;
  9631. v[webgl.M33] = 0;
  9632. return this;
  9633. };
  9634. Matrix4.prototype.ortho2d = function (x, y, width, height) {
  9635. return this.ortho(x, x + width, y, y + height, 0, 1);
  9636. };
  9637. Matrix4.prototype.ortho = function (left, right, bottom, top, near, far) {
  9638. this.identity();
  9639. var x_orth = 2 / (right - left);
  9640. var y_orth = 2 / (top - bottom);
  9641. var z_orth = -2 / (far - near);
  9642. var tx = -(right + left) / (right - left);
  9643. var ty = -(top + bottom) / (top - bottom);
  9644. var tz = -(far + near) / (far - near);
  9645. var v = this.values;
  9646. v[webgl.M00] = x_orth;
  9647. v[webgl.M10] = 0;
  9648. v[webgl.M20] = 0;
  9649. v[webgl.M30] = 0;
  9650. v[webgl.M01] = 0;
  9651. v[webgl.M11] = y_orth;
  9652. v[webgl.M21] = 0;
  9653. v[webgl.M31] = 0;
  9654. v[webgl.M02] = 0;
  9655. v[webgl.M12] = 0;
  9656. v[webgl.M22] = z_orth;
  9657. v[webgl.M32] = 0;
  9658. v[webgl.M03] = tx;
  9659. v[webgl.M13] = ty;
  9660. v[webgl.M23] = tz;
  9661. v[webgl.M33] = 1;
  9662. return this;
  9663. };
  9664. Matrix4.prototype.multiply = function (matrix) {
  9665. var t = this.temp;
  9666. var v = this.values;
  9667. var m = matrix.values;
  9668. 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];
  9669. 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];
  9670. 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];
  9671. 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];
  9672. 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];
  9673. 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];
  9674. 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];
  9675. 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];
  9676. 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];
  9677. 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];
  9678. 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];
  9679. 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];
  9680. 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];
  9681. 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];
  9682. 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];
  9683. 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];
  9684. return this.set(this.temp);
  9685. };
  9686. Matrix4.prototype.multiplyLeft = function (matrix) {
  9687. var t = this.temp;
  9688. var v = this.values;
  9689. var m = matrix.values;
  9690. 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];
  9691. 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];
  9692. 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];
  9693. 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];
  9694. 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];
  9695. 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];
  9696. 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];
  9697. 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];
  9698. 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];
  9699. 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];
  9700. 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];
  9701. 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];
  9702. 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];
  9703. 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];
  9704. 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];
  9705. 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];
  9706. return this.set(this.temp);
  9707. };
  9708. Matrix4.prototype.lookAt = function (position, direction, up) {
  9709. Matrix4.initTemps();
  9710. var xAxis = Matrix4.xAxis, yAxis = Matrix4.yAxis, zAxis = Matrix4.zAxis;
  9711. zAxis.setFrom(direction).normalize();
  9712. xAxis.setFrom(direction).normalize();
  9713. xAxis.cross(up).normalize();
  9714. yAxis.setFrom(xAxis).cross(zAxis).normalize();
  9715. this.identity();
  9716. var val = this.values;
  9717. val[webgl.M00] = xAxis.x;
  9718. val[webgl.M01] = xAxis.y;
  9719. val[webgl.M02] = xAxis.z;
  9720. val[webgl.M10] = yAxis.x;
  9721. val[webgl.M11] = yAxis.y;
  9722. val[webgl.M12] = yAxis.z;
  9723. val[webgl.M20] = -zAxis.x;
  9724. val[webgl.M21] = -zAxis.y;
  9725. val[webgl.M22] = -zAxis.z;
  9726. Matrix4.tmpMatrix.identity();
  9727. Matrix4.tmpMatrix.values[webgl.M03] = -position.x;
  9728. Matrix4.tmpMatrix.values[webgl.M13] = -position.y;
  9729. Matrix4.tmpMatrix.values[webgl.M23] = -position.z;
  9730. this.multiply(Matrix4.tmpMatrix);
  9731. return this;
  9732. };
  9733. Matrix4.initTemps = function () {
  9734. if (Matrix4.xAxis === null)
  9735. Matrix4.xAxis = new webgl.Vector3();
  9736. if (Matrix4.yAxis === null)
  9737. Matrix4.yAxis = new webgl.Vector3();
  9738. if (Matrix4.zAxis === null)
  9739. Matrix4.zAxis = new webgl.Vector3();
  9740. };
  9741. Matrix4.xAxis = null;
  9742. Matrix4.yAxis = null;
  9743. Matrix4.zAxis = null;
  9744. Matrix4.tmpMatrix = new Matrix4();
  9745. return Matrix4;
  9746. }());
  9747. webgl.Matrix4 = Matrix4;
  9748. })(webgl = spine.webgl || (spine.webgl = {}));
  9749. })(spine || (spine = {}));
  9750. var spine;
  9751. (function (spine) {
  9752. var webgl;
  9753. (function (webgl) {
  9754. var Mesh = (function () {
  9755. function Mesh(context, attributes, maxVertices, maxIndices) {
  9756. this.attributes = attributes;
  9757. this.verticesLength = 0;
  9758. this.dirtyVertices = false;
  9759. this.indicesLength = 0;
  9760. this.dirtyIndices = false;
  9761. this.elementsPerVertex = 0;
  9762. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  9763. this.elementsPerVertex = 0;
  9764. for (var i = 0; i < attributes.length; i++) {
  9765. this.elementsPerVertex += attributes[i].numElements;
  9766. }
  9767. this.vertices = new Float32Array(maxVertices * this.elementsPerVertex);
  9768. this.indices = new Uint16Array(maxIndices);
  9769. this.context.addRestorable(this);
  9770. }
  9771. Mesh.prototype.getAttributes = function () { return this.attributes; };
  9772. Mesh.prototype.maxVertices = function () { return this.vertices.length / this.elementsPerVertex; };
  9773. Mesh.prototype.numVertices = function () { return this.verticesLength / this.elementsPerVertex; };
  9774. Mesh.prototype.setVerticesLength = function (length) {
  9775. this.dirtyVertices = true;
  9776. this.verticesLength = length;
  9777. };
  9778. Mesh.prototype.getVertices = function () { return this.vertices; };
  9779. Mesh.prototype.maxIndices = function () { return this.indices.length; };
  9780. Mesh.prototype.numIndices = function () { return this.indicesLength; };
  9781. Mesh.prototype.setIndicesLength = function (length) {
  9782. this.dirtyIndices = true;
  9783. this.indicesLength = length;
  9784. };
  9785. Mesh.prototype.getIndices = function () { return this.indices; };
  9786. ;
  9787. Mesh.prototype.getVertexSizeInFloats = function () {
  9788. var size = 0;
  9789. for (var i = 0; i < this.attributes.length; i++) {
  9790. var attribute = this.attributes[i];
  9791. size += attribute.numElements;
  9792. }
  9793. return size;
  9794. };
  9795. Mesh.prototype.setVertices = function (vertices) {
  9796. this.dirtyVertices = true;
  9797. if (vertices.length > this.vertices.length)
  9798. throw Error("Mesh can't store more than " + this.maxVertices() + " vertices");
  9799. this.vertices.set(vertices, 0);
  9800. this.verticesLength = vertices.length;
  9801. };
  9802. Mesh.prototype.setIndices = function (indices) {
  9803. this.dirtyIndices = true;
  9804. if (indices.length > this.indices.length)
  9805. throw Error("Mesh can't store more than " + this.maxIndices() + " indices");
  9806. this.indices.set(indices, 0);
  9807. this.indicesLength = indices.length;
  9808. };
  9809. Mesh.prototype.draw = function (shader, primitiveType) {
  9810. this.drawWithOffset(shader, primitiveType, 0, this.indicesLength > 0 ? this.indicesLength : this.verticesLength / this.elementsPerVertex);
  9811. };
  9812. Mesh.prototype.drawWithOffset = function (shader, primitiveType, offset, count) {
  9813. var gl = this.context.gl;
  9814. if (this.dirtyVertices || this.dirtyIndices)
  9815. this.update();
  9816. this.bind(shader);
  9817. if (this.indicesLength > 0) {
  9818. gl.drawElements(primitiveType, count, gl.UNSIGNED_SHORT, offset * 2);
  9819. }
  9820. else {
  9821. gl.drawArrays(primitiveType, offset, count);
  9822. }
  9823. this.unbind(shader);
  9824. };
  9825. Mesh.prototype.bind = function (shader) {
  9826. var gl = this.context.gl;
  9827. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  9828. var offset = 0;
  9829. for (var i = 0; i < this.attributes.length; i++) {
  9830. var attrib = this.attributes[i];
  9831. var location_1 = shader.getAttributeLocation(attrib.name);
  9832. gl.enableVertexAttribArray(location_1);
  9833. gl.vertexAttribPointer(location_1, attrib.numElements, gl.FLOAT, false, this.elementsPerVertex * 4, offset * 4);
  9834. offset += attrib.numElements;
  9835. }
  9836. if (this.indicesLength > 0)
  9837. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  9838. };
  9839. Mesh.prototype.unbind = function (shader) {
  9840. var gl = this.context.gl;
  9841. for (var i = 0; i < this.attributes.length; i++) {
  9842. var attrib = this.attributes[i];
  9843. var location_2 = shader.getAttributeLocation(attrib.name);
  9844. gl.disableVertexAttribArray(location_2);
  9845. }
  9846. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  9847. if (this.indicesLength > 0)
  9848. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  9849. };
  9850. Mesh.prototype.update = function () {
  9851. var gl = this.context.gl;
  9852. if (this.dirtyVertices) {
  9853. if (!this.verticesBuffer) {
  9854. this.verticesBuffer = gl.createBuffer();
  9855. }
  9856. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  9857. gl.bufferData(gl.ARRAY_BUFFER, this.vertices.subarray(0, this.verticesLength), gl.DYNAMIC_DRAW);
  9858. this.dirtyVertices = false;
  9859. }
  9860. if (this.dirtyIndices) {
  9861. if (!this.indicesBuffer) {
  9862. this.indicesBuffer = gl.createBuffer();
  9863. }
  9864. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  9865. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices.subarray(0, this.indicesLength), gl.DYNAMIC_DRAW);
  9866. this.dirtyIndices = false;
  9867. }
  9868. };
  9869. Mesh.prototype.restore = function () {
  9870. this.verticesBuffer = null;
  9871. this.indicesBuffer = null;
  9872. this.update();
  9873. };
  9874. Mesh.prototype.dispose = function () {
  9875. this.context.removeRestorable(this);
  9876. var gl = this.context.gl;
  9877. gl.deleteBuffer(this.verticesBuffer);
  9878. gl.deleteBuffer(this.indicesBuffer);
  9879. };
  9880. return Mesh;
  9881. }());
  9882. webgl.Mesh = Mesh;
  9883. var VertexAttribute = (function () {
  9884. function VertexAttribute(name, type, numElements) {
  9885. this.name = name;
  9886. this.type = type;
  9887. this.numElements = numElements;
  9888. }
  9889. return VertexAttribute;
  9890. }());
  9891. webgl.VertexAttribute = VertexAttribute;
  9892. var Position2Attribute = (function (_super) {
  9893. __extends(Position2Attribute, _super);
  9894. function Position2Attribute() {
  9895. return _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 2) || this;
  9896. }
  9897. return Position2Attribute;
  9898. }(VertexAttribute));
  9899. webgl.Position2Attribute = Position2Attribute;
  9900. var Position3Attribute = (function (_super) {
  9901. __extends(Position3Attribute, _super);
  9902. function Position3Attribute() {
  9903. return _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 3) || this;
  9904. }
  9905. return Position3Attribute;
  9906. }(VertexAttribute));
  9907. webgl.Position3Attribute = Position3Attribute;
  9908. var TexCoordAttribute = (function (_super) {
  9909. __extends(TexCoordAttribute, _super);
  9910. function TexCoordAttribute(unit) {
  9911. if (unit === void 0) { unit = 0; }
  9912. return _super.call(this, webgl.Shader.TEXCOORDS + (unit == 0 ? "" : unit), VertexAttributeType.Float, 2) || this;
  9913. }
  9914. return TexCoordAttribute;
  9915. }(VertexAttribute));
  9916. webgl.TexCoordAttribute = TexCoordAttribute;
  9917. var ColorAttribute = (function (_super) {
  9918. __extends(ColorAttribute, _super);
  9919. function ColorAttribute() {
  9920. return _super.call(this, webgl.Shader.COLOR, VertexAttributeType.Float, 4) || this;
  9921. }
  9922. return ColorAttribute;
  9923. }(VertexAttribute));
  9924. webgl.ColorAttribute = ColorAttribute;
  9925. var Color2Attribute = (function (_super) {
  9926. __extends(Color2Attribute, _super);
  9927. function Color2Attribute() {
  9928. return _super.call(this, webgl.Shader.COLOR2, VertexAttributeType.Float, 4) || this;
  9929. }
  9930. return Color2Attribute;
  9931. }(VertexAttribute));
  9932. webgl.Color2Attribute = Color2Attribute;
  9933. var VertexAttributeType;
  9934. (function (VertexAttributeType) {
  9935. VertexAttributeType[VertexAttributeType["Float"] = 0] = "Float";
  9936. })(VertexAttributeType = webgl.VertexAttributeType || (webgl.VertexAttributeType = {}));
  9937. })(webgl = spine.webgl || (spine.webgl = {}));
  9938. })(spine || (spine = {}));
  9939. var spine;
  9940. (function (spine) {
  9941. var webgl;
  9942. (function (webgl) {
  9943. var PolygonBatcher = (function () {
  9944. function PolygonBatcher(context, twoColorTint, maxVertices) {
  9945. if (twoColorTint === void 0) { twoColorTint = true; }
  9946. if (maxVertices === void 0) { maxVertices = 10920; }
  9947. this.isDrawing = false;
  9948. this.shader = null;
  9949. this.lastTexture = null;
  9950. this.verticesLength = 0;
  9951. this.indicesLength = 0;
  9952. if (maxVertices > 10920)
  9953. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  9954. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  9955. var attributes = twoColorTint ?
  9956. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute(), new webgl.Color2Attribute()] :
  9957. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute()];
  9958. this.mesh = new webgl.Mesh(context, attributes, maxVertices, maxVertices * 3);
  9959. var gl = this.context.gl;
  9960. this.srcColorBlend = gl.SRC_ALPHA;
  9961. this.srcAlphaBlend = gl.ONE;
  9962. this.dstBlend = gl.ONE_MINUS_SRC_ALPHA;
  9963. }
  9964. PolygonBatcher.prototype.begin = function (shader) {
  9965. if (this.isDrawing)
  9966. throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()");
  9967. this.drawCalls = 0;
  9968. this.shader = shader;
  9969. this.lastTexture = null;
  9970. this.isDrawing = true;
  9971. var gl = this.context.gl;
  9972. gl.enable(gl.BLEND);
  9973. gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
  9974. };
  9975. PolygonBatcher.prototype.setBlendMode = function (srcColorBlend, srcAlphaBlend, dstBlend) {
  9976. this.srcColorBlend = srcColorBlend;
  9977. this.srcAlphaBlend = srcAlphaBlend;
  9978. this.dstBlend = dstBlend;
  9979. if (this.isDrawing) {
  9980. this.flush();
  9981. var gl = this.context.gl;
  9982. gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
  9983. }
  9984. };
  9985. PolygonBatcher.prototype.draw = function (texture, vertices, indices) {
  9986. if (texture != this.lastTexture) {
  9987. this.flush();
  9988. this.lastTexture = texture;
  9989. }
  9990. else if (this.verticesLength + vertices.length > this.mesh.getVertices().length ||
  9991. this.indicesLength + indices.length > this.mesh.getIndices().length) {
  9992. this.flush();
  9993. }
  9994. var indexStart = this.mesh.numVertices();
  9995. this.mesh.getVertices().set(vertices, this.verticesLength);
  9996. this.verticesLength += vertices.length;
  9997. this.mesh.setVerticesLength(this.verticesLength);
  9998. var indicesArray = this.mesh.getIndices();
  9999. for (var i = this.indicesLength, j = 0; j < indices.length; i++, j++)
  10000. indicesArray[i] = indices[j] + indexStart;
  10001. this.indicesLength += indices.length;
  10002. this.mesh.setIndicesLength(this.indicesLength);
  10003. };
  10004. PolygonBatcher.prototype.flush = function () {
  10005. if (this.verticesLength == 0)
  10006. return;
  10007. this.lastTexture.bind();
  10008. this.mesh.draw(this.shader, this.context.gl.TRIANGLES);
  10009. this.verticesLength = 0;
  10010. this.indicesLength = 0;
  10011. this.mesh.setVerticesLength(0);
  10012. this.mesh.setIndicesLength(0);
  10013. this.drawCalls++;
  10014. };
  10015. PolygonBatcher.prototype.end = function () {
  10016. if (!this.isDrawing)
  10017. throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()");
  10018. if (this.verticesLength > 0 || this.indicesLength > 0)
  10019. this.flush();
  10020. this.shader = null;
  10021. this.lastTexture = null;
  10022. this.isDrawing = false;
  10023. var gl = this.context.gl;
  10024. gl.disable(gl.BLEND);
  10025. };
  10026. PolygonBatcher.prototype.getDrawCalls = function () {
  10027. return this.drawCalls;
  10028. };
  10029. PolygonBatcher.prototype.dispose = function () {
  10030. this.mesh.dispose();
  10031. };
  10032. return PolygonBatcher;
  10033. }());
  10034. webgl.PolygonBatcher = PolygonBatcher;
  10035. })(webgl = spine.webgl || (spine.webgl = {}));
  10036. })(spine || (spine = {}));
  10037. var spine;
  10038. (function (spine) {
  10039. var webgl;
  10040. (function (webgl) {
  10041. var quad = [
  10042. 0, 0, 1, 1, 1, 1, 0, 0,
  10043. 0, 0, 1, 1, 1, 1, 0, 0,
  10044. 0, 0, 1, 1, 1, 1, 0, 0,
  10045. 0, 0, 1, 1, 1, 1, 0, 0,
  10046. ];
  10047. var QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  10048. var WHITE = new spine.Color(1, 1, 1, 1);
  10049. var SceneRenderer = (function () {
  10050. function SceneRenderer(canvas, context, twoColorTint) {
  10051. if (twoColorTint === void 0) { twoColorTint = true; }
  10052. this.twoColorTint = false;
  10053. this.canvas = canvas;
  10054. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  10055. this.twoColorTint = twoColorTint;
  10056. this.camera = new webgl.OrthoCamera(canvas.width, canvas.height);
  10057. this.batcherShader = twoColorTint ? webgl.Shader.newTwoColoredTextured(this.context) : webgl.Shader.newColoredTextured(this.context);
  10058. this.batcher = new webgl.PolygonBatcher(this.context, twoColorTint);
  10059. this.shapesShader = webgl.Shader.newColored(this.context);
  10060. this.shapes = new webgl.ShapeRenderer(this.context);
  10061. this.skeletonRenderer = new webgl.SkeletonRenderer(this.context, twoColorTint);
  10062. this.skeletonDebugRenderer = new webgl.SkeletonDebugRenderer(this.context);
  10063. }
  10064. SceneRenderer.prototype.begin = function () {
  10065. this.camera.update();
  10066. this.enableRenderer(this.batcher);
  10067. };
  10068. SceneRenderer.prototype.drawSkeleton = function (skeleton, premultipliedAlpha, slotRangeStart, slotRangeEnd) {
  10069. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  10070. if (slotRangeStart === void 0) { slotRangeStart = -1; }
  10071. if (slotRangeEnd === void 0) { slotRangeEnd = -1; }
  10072. this.enableRenderer(this.batcher);
  10073. this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
  10074. this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd);
  10075. };
  10076. SceneRenderer.prototype.drawSkeletonDebug = function (skeleton, premultipliedAlpha, ignoredBones) {
  10077. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  10078. if (ignoredBones === void 0) { ignoredBones = null; }
  10079. this.enableRenderer(this.shapes);
  10080. this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha;
  10081. this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones);
  10082. };
  10083. SceneRenderer.prototype.drawTexture = function (texture, x, y, width, height, color) {
  10084. if (color === void 0) { color = null; }
  10085. this.enableRenderer(this.batcher);
  10086. if (color === null)
  10087. color = WHITE;
  10088. var i = 0;
  10089. quad[i++] = x;
  10090. quad[i++] = y;
  10091. quad[i++] = color.r;
  10092. quad[i++] = color.g;
  10093. quad[i++] = color.b;
  10094. quad[i++] = color.a;
  10095. quad[i++] = 0;
  10096. quad[i++] = 1;
  10097. if (this.twoColorTint) {
  10098. quad[i++] = 0;
  10099. quad[i++] = 0;
  10100. quad[i++] = 0;
  10101. quad[i++] = 0;
  10102. }
  10103. quad[i++] = x + width;
  10104. quad[i++] = y;
  10105. quad[i++] = color.r;
  10106. quad[i++] = color.g;
  10107. quad[i++] = color.b;
  10108. quad[i++] = color.a;
  10109. quad[i++] = 1;
  10110. quad[i++] = 1;
  10111. if (this.twoColorTint) {
  10112. quad[i++] = 0;
  10113. quad[i++] = 0;
  10114. quad[i++] = 0;
  10115. quad[i++] = 0;
  10116. }
  10117. quad[i++] = x + width;
  10118. quad[i++] = y + height;
  10119. quad[i++] = color.r;
  10120. quad[i++] = color.g;
  10121. quad[i++] = color.b;
  10122. quad[i++] = color.a;
  10123. quad[i++] = 1;
  10124. quad[i++] = 0;
  10125. if (this.twoColorTint) {
  10126. quad[i++] = 0;
  10127. quad[i++] = 0;
  10128. quad[i++] = 0;
  10129. quad[i++] = 0;
  10130. }
  10131. quad[i++] = x;
  10132. quad[i++] = y + height;
  10133. quad[i++] = color.r;
  10134. quad[i++] = color.g;
  10135. quad[i++] = color.b;
  10136. quad[i++] = color.a;
  10137. quad[i++] = 0;
  10138. quad[i++] = 0;
  10139. if (this.twoColorTint) {
  10140. quad[i++] = 0;
  10141. quad[i++] = 0;
  10142. quad[i++] = 0;
  10143. quad[i] = 0;
  10144. }
  10145. this.batcher.draw(texture, quad, QUAD_TRIANGLES);
  10146. };
  10147. SceneRenderer.prototype.drawTextureUV = function (texture, x, y, width, height, u, v, u2, v2, color) {
  10148. if (color === void 0) { color = null; }
  10149. this.enableRenderer(this.batcher);
  10150. if (color === null)
  10151. color = WHITE;
  10152. var i = 0;
  10153. quad[i++] = x;
  10154. quad[i++] = y;
  10155. quad[i++] = color.r;
  10156. quad[i++] = color.g;
  10157. quad[i++] = color.b;
  10158. quad[i++] = color.a;
  10159. quad[i++] = u;
  10160. quad[i++] = v;
  10161. if (this.twoColorTint) {
  10162. quad[i++] = 0;
  10163. quad[i++] = 0;
  10164. quad[i++] = 0;
  10165. quad[i++] = 0;
  10166. }
  10167. quad[i++] = x + width;
  10168. quad[i++] = y;
  10169. quad[i++] = color.r;
  10170. quad[i++] = color.g;
  10171. quad[i++] = color.b;
  10172. quad[i++] = color.a;
  10173. quad[i++] = u2;
  10174. quad[i++] = v;
  10175. if (this.twoColorTint) {
  10176. quad[i++] = 0;
  10177. quad[i++] = 0;
  10178. quad[i++] = 0;
  10179. quad[i++] = 0;
  10180. }
  10181. quad[i++] = x + width;
  10182. quad[i++] = y + height;
  10183. quad[i++] = color.r;
  10184. quad[i++] = color.g;
  10185. quad[i++] = color.b;
  10186. quad[i++] = color.a;
  10187. quad[i++] = u2;
  10188. quad[i++] = v2;
  10189. if (this.twoColorTint) {
  10190. quad[i++] = 0;
  10191. quad[i++] = 0;
  10192. quad[i++] = 0;
  10193. quad[i++] = 0;
  10194. }
  10195. quad[i++] = x;
  10196. quad[i++] = y + height;
  10197. quad[i++] = color.r;
  10198. quad[i++] = color.g;
  10199. quad[i++] = color.b;
  10200. quad[i++] = color.a;
  10201. quad[i++] = u;
  10202. quad[i++] = v2;
  10203. if (this.twoColorTint) {
  10204. quad[i++] = 0;
  10205. quad[i++] = 0;
  10206. quad[i++] = 0;
  10207. quad[i] = 0;
  10208. }
  10209. this.batcher.draw(texture, quad, QUAD_TRIANGLES);
  10210. };
  10211. SceneRenderer.prototype.drawTextureRotated = function (texture, x, y, width, height, pivotX, pivotY, angle, color) {
  10212. if (color === void 0) { color = null; }
  10213. this.enableRenderer(this.batcher);
  10214. if (color === null)
  10215. color = WHITE;
  10216. var worldOriginX = x + pivotX;
  10217. var worldOriginY = y + pivotY;
  10218. var fx = -pivotX;
  10219. var fy = -pivotY;
  10220. var fx2 = width - pivotX;
  10221. var fy2 = height - pivotY;
  10222. var p1x = fx;
  10223. var p1y = fy;
  10224. var p2x = fx;
  10225. var p2y = fy2;
  10226. var p3x = fx2;
  10227. var p3y = fy2;
  10228. var p4x = fx2;
  10229. var p4y = fy;
  10230. var x1 = 0;
  10231. var y1 = 0;
  10232. var x2 = 0;
  10233. var y2 = 0;
  10234. var x3 = 0;
  10235. var y3 = 0;
  10236. var x4 = 0;
  10237. var y4 = 0;
  10238. if (angle != 0) {
  10239. var cos = spine.MathUtils.cosDeg(angle);
  10240. var sin = spine.MathUtils.sinDeg(angle);
  10241. x1 = cos * p1x - sin * p1y;
  10242. y1 = sin * p1x + cos * p1y;
  10243. x4 = cos * p2x - sin * p2y;
  10244. y4 = sin * p2x + cos * p2y;
  10245. x3 = cos * p3x - sin * p3y;
  10246. y3 = sin * p3x + cos * p3y;
  10247. x2 = x3 + (x1 - x4);
  10248. y2 = y3 + (y1 - y4);
  10249. }
  10250. else {
  10251. x1 = p1x;
  10252. y1 = p1y;
  10253. x4 = p2x;
  10254. y4 = p2y;
  10255. x3 = p3x;
  10256. y3 = p3y;
  10257. x2 = p4x;
  10258. y2 = p4y;
  10259. }
  10260. x1 += worldOriginX;
  10261. y1 += worldOriginY;
  10262. x2 += worldOriginX;
  10263. y2 += worldOriginY;
  10264. x3 += worldOriginX;
  10265. y3 += worldOriginY;
  10266. x4 += worldOriginX;
  10267. y4 += worldOriginY;
  10268. var i = 0;
  10269. quad[i++] = x1;
  10270. quad[i++] = y1;
  10271. quad[i++] = color.r;
  10272. quad[i++] = color.g;
  10273. quad[i++] = color.b;
  10274. quad[i++] = color.a;
  10275. quad[i++] = 0;
  10276. quad[i++] = 1;
  10277. if (this.twoColorTint) {
  10278. quad[i++] = 0;
  10279. quad[i++] = 0;
  10280. quad[i++] = 0;
  10281. quad[i++] = 0;
  10282. }
  10283. quad[i++] = x2;
  10284. quad[i++] = y2;
  10285. quad[i++] = color.r;
  10286. quad[i++] = color.g;
  10287. quad[i++] = color.b;
  10288. quad[i++] = color.a;
  10289. quad[i++] = 1;
  10290. quad[i++] = 1;
  10291. if (this.twoColorTint) {
  10292. quad[i++] = 0;
  10293. quad[i++] = 0;
  10294. quad[i++] = 0;
  10295. quad[i++] = 0;
  10296. }
  10297. quad[i++] = x3;
  10298. quad[i++] = y3;
  10299. quad[i++] = color.r;
  10300. quad[i++] = color.g;
  10301. quad[i++] = color.b;
  10302. quad[i++] = color.a;
  10303. quad[i++] = 1;
  10304. quad[i++] = 0;
  10305. if (this.twoColorTint) {
  10306. quad[i++] = 0;
  10307. quad[i++] = 0;
  10308. quad[i++] = 0;
  10309. quad[i++] = 0;
  10310. }
  10311. quad[i++] = x4;
  10312. quad[i++] = y4;
  10313. quad[i++] = color.r;
  10314. quad[i++] = color.g;
  10315. quad[i++] = color.b;
  10316. quad[i++] = color.a;
  10317. quad[i++] = 0;
  10318. quad[i++] = 0;
  10319. if (this.twoColorTint) {
  10320. quad[i++] = 0;
  10321. quad[i++] = 0;
  10322. quad[i++] = 0;
  10323. quad[i] = 0;
  10324. }
  10325. this.batcher.draw(texture, quad, QUAD_TRIANGLES);
  10326. };
  10327. SceneRenderer.prototype.drawRegion = function (region, x, y, width, height, color) {
  10328. if (color === void 0) { color = null; }
  10329. this.enableRenderer(this.batcher);
  10330. if (color === null)
  10331. color = WHITE;
  10332. var i = 0;
  10333. quad[i++] = x;
  10334. quad[i++] = y;
  10335. quad[i++] = color.r;
  10336. quad[i++] = color.g;
  10337. quad[i++] = color.b;
  10338. quad[i++] = color.a;
  10339. quad[i++] = region.u;
  10340. quad[i++] = region.v2;
  10341. if (this.twoColorTint) {
  10342. quad[i++] = 0;
  10343. quad[i++] = 0;
  10344. quad[i++] = 0;
  10345. quad[i++] = 0;
  10346. }
  10347. quad[i++] = x + width;
  10348. quad[i++] = y;
  10349. quad[i++] = color.r;
  10350. quad[i++] = color.g;
  10351. quad[i++] = color.b;
  10352. quad[i++] = color.a;
  10353. quad[i++] = region.u2;
  10354. quad[i++] = region.v2;
  10355. if (this.twoColorTint) {
  10356. quad[i++] = 0;
  10357. quad[i++] = 0;
  10358. quad[i++] = 0;
  10359. quad[i++] = 0;
  10360. }
  10361. quad[i++] = x + width;
  10362. quad[i++] = y + height;
  10363. quad[i++] = color.r;
  10364. quad[i++] = color.g;
  10365. quad[i++] = color.b;
  10366. quad[i++] = color.a;
  10367. quad[i++] = region.u2;
  10368. quad[i++] = region.v;
  10369. if (this.twoColorTint) {
  10370. quad[i++] = 0;
  10371. quad[i++] = 0;
  10372. quad[i++] = 0;
  10373. quad[i++] = 0;
  10374. }
  10375. quad[i++] = x;
  10376. quad[i++] = y + height;
  10377. quad[i++] = color.r;
  10378. quad[i++] = color.g;
  10379. quad[i++] = color.b;
  10380. quad[i++] = color.a;
  10381. quad[i++] = region.u;
  10382. quad[i++] = region.v;
  10383. if (this.twoColorTint) {
  10384. quad[i++] = 0;
  10385. quad[i++] = 0;
  10386. quad[i++] = 0;
  10387. quad[i] = 0;
  10388. }
  10389. this.batcher.draw(region.page.texture, quad, QUAD_TRIANGLES);
  10390. };
  10391. SceneRenderer.prototype.line = function (x, y, x2, y2, color, color2) {
  10392. if (color === void 0) { color = null; }
  10393. if (color2 === void 0) { color2 = null; }
  10394. this.enableRenderer(this.shapes);
  10395. this.shapes.line(x, y, x2, y2, color);
  10396. };
  10397. SceneRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  10398. if (color === void 0) { color = null; }
  10399. if (color2 === void 0) { color2 = null; }
  10400. if (color3 === void 0) { color3 = null; }
  10401. this.enableRenderer(this.shapes);
  10402. this.shapes.triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3);
  10403. };
  10404. SceneRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  10405. if (color === void 0) { color = null; }
  10406. if (color2 === void 0) { color2 = null; }
  10407. if (color3 === void 0) { color3 = null; }
  10408. if (color4 === void 0) { color4 = null; }
  10409. this.enableRenderer(this.shapes);
  10410. this.shapes.quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4);
  10411. };
  10412. SceneRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  10413. if (color === void 0) { color = null; }
  10414. this.enableRenderer(this.shapes);
  10415. this.shapes.rect(filled, x, y, width, height, color);
  10416. };
  10417. SceneRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  10418. if (color === void 0) { color = null; }
  10419. this.enableRenderer(this.shapes);
  10420. this.shapes.rectLine(filled, x1, y1, x2, y2, width, color);
  10421. };
  10422. SceneRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  10423. if (color === void 0) { color = null; }
  10424. this.enableRenderer(this.shapes);
  10425. this.shapes.polygon(polygonVertices, offset, count, color);
  10426. };
  10427. SceneRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  10428. if (color === void 0) { color = null; }
  10429. if (segments === void 0) { segments = 0; }
  10430. this.enableRenderer(this.shapes);
  10431. this.shapes.circle(filled, x, y, radius, color, segments);
  10432. };
  10433. SceneRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  10434. if (color === void 0) { color = null; }
  10435. this.enableRenderer(this.shapes);
  10436. this.shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color);
  10437. };
  10438. SceneRenderer.prototype.end = function () {
  10439. if (this.activeRenderer === this.batcher)
  10440. this.batcher.end();
  10441. else if (this.activeRenderer === this.shapes)
  10442. this.shapes.end();
  10443. this.activeRenderer = null;
  10444. };
  10445. SceneRenderer.prototype.resize = function (resizeMode) {
  10446. var canvas = this.canvas;
  10447. var dpr = window.devicePixelRatio || 1;
  10448. var w = Math.round(canvas.clientWidth * dpr);
  10449. var h = Math.round(canvas.clientHeight * dpr);
  10450. if (canvas.width != w || canvas.height != h) {
  10451. canvas.width = w;
  10452. canvas.height = h;
  10453. }
  10454. this.context.gl.viewport(0, 0, canvas.width, canvas.height);
  10455. if (resizeMode === ResizeMode.Expand)
  10456. this.camera.setViewport(w, h);
  10457. else if (resizeMode === ResizeMode.Fit) {
  10458. var sourceWidth = canvas.width, sourceHeight = canvas.height;
  10459. var targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHeight;
  10460. var targetRatio = targetHeight / targetWidth;
  10461. var sourceRatio = sourceHeight / sourceWidth;
  10462. var scale = targetRatio < sourceRatio ? targetWidth / sourceWidth : targetHeight / sourceHeight;
  10463. this.camera.setViewport(sourceWidth * scale, sourceHeight * scale);
  10464. }
  10465. this.camera.update();
  10466. };
  10467. SceneRenderer.prototype.enableRenderer = function (renderer) {
  10468. if (this.activeRenderer === renderer)
  10469. return;
  10470. this.end();
  10471. if (renderer instanceof webgl.PolygonBatcher) {
  10472. this.batcherShader.bind();
  10473. this.batcherShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  10474. this.batcherShader.setUniformi("u_texture", 0);
  10475. this.batcher.begin(this.batcherShader);
  10476. this.activeRenderer = this.batcher;
  10477. }
  10478. else if (renderer instanceof webgl.ShapeRenderer) {
  10479. this.shapesShader.bind();
  10480. this.shapesShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  10481. this.shapes.begin(this.shapesShader);
  10482. this.activeRenderer = this.shapes;
  10483. }
  10484. else
  10485. this.activeRenderer = this.skeletonDebugRenderer;
  10486. };
  10487. SceneRenderer.prototype.dispose = function () {
  10488. this.batcher.dispose();
  10489. this.batcherShader.dispose();
  10490. this.shapes.dispose();
  10491. this.shapesShader.dispose();
  10492. this.skeletonDebugRenderer.dispose();
  10493. };
  10494. return SceneRenderer;
  10495. }());
  10496. webgl.SceneRenderer = SceneRenderer;
  10497. var ResizeMode;
  10498. (function (ResizeMode) {
  10499. ResizeMode[ResizeMode["Stretch"] = 0] = "Stretch";
  10500. ResizeMode[ResizeMode["Expand"] = 1] = "Expand";
  10501. ResizeMode[ResizeMode["Fit"] = 2] = "Fit";
  10502. })(ResizeMode = webgl.ResizeMode || (webgl.ResizeMode = {}));
  10503. })(webgl = spine.webgl || (spine.webgl = {}));
  10504. })(spine || (spine = {}));
  10505. var spine;
  10506. (function (spine) {
  10507. var webgl;
  10508. (function (webgl) {
  10509. var Shader = (function () {
  10510. function Shader(context, vertexShader, fragmentShader) {
  10511. this.vertexShader = vertexShader;
  10512. this.fragmentShader = fragmentShader;
  10513. this.vs = null;
  10514. this.fs = null;
  10515. this.program = null;
  10516. this.tmp2x2 = new Float32Array(2 * 2);
  10517. this.tmp3x3 = new Float32Array(3 * 3);
  10518. this.tmp4x4 = new Float32Array(4 * 4);
  10519. this.vsSource = vertexShader;
  10520. this.fsSource = fragmentShader;
  10521. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  10522. this.context.addRestorable(this);
  10523. this.compile();
  10524. }
  10525. Shader.prototype.getProgram = function () { return this.program; };
  10526. Shader.prototype.getVertexShader = function () { return this.vertexShader; };
  10527. Shader.prototype.getFragmentShader = function () { return this.fragmentShader; };
  10528. Shader.prototype.getVertexShaderSource = function () { return this.vsSource; };
  10529. Shader.prototype.getFragmentSource = function () { return this.fsSource; };
  10530. Shader.prototype.compile = function () {
  10531. var gl = this.context.gl;
  10532. try {
  10533. this.vs = this.compileShader(gl.VERTEX_SHADER, this.vertexShader);
  10534. this.fs = this.compileShader(gl.FRAGMENT_SHADER, this.fragmentShader);
  10535. this.program = this.compileProgram(this.vs, this.fs);
  10536. }
  10537. catch (e) {
  10538. this.dispose();
  10539. throw e;
  10540. }
  10541. };
  10542. Shader.prototype.compileShader = function (type, source) {
  10543. var gl = this.context.gl;
  10544. var shader = gl.createShader(type);
  10545. gl.shaderSource(shader, source);
  10546. gl.compileShader(shader);
  10547. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  10548. var error = "Couldn't compile shader: " + gl.getShaderInfoLog(shader);
  10549. gl.deleteShader(shader);
  10550. if (!gl.isContextLost())
  10551. throw new Error(error);
  10552. }
  10553. return shader;
  10554. };
  10555. Shader.prototype.compileProgram = function (vs, fs) {
  10556. var gl = this.context.gl;
  10557. var program = gl.createProgram();
  10558. gl.attachShader(program, vs);
  10559. gl.attachShader(program, fs);
  10560. gl.linkProgram(program);
  10561. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  10562. var error = "Couldn't compile shader program: " + gl.getProgramInfoLog(program);
  10563. gl.deleteProgram(program);
  10564. if (!gl.isContextLost())
  10565. throw new Error(error);
  10566. }
  10567. return program;
  10568. };
  10569. Shader.prototype.restore = function () {
  10570. this.compile();
  10571. };
  10572. Shader.prototype.bind = function () {
  10573. this.context.gl.useProgram(this.program);
  10574. };
  10575. Shader.prototype.unbind = function () {
  10576. this.context.gl.useProgram(null);
  10577. };
  10578. Shader.prototype.setUniformi = function (uniform, value) {
  10579. this.context.gl.uniform1i(this.getUniformLocation(uniform), value);
  10580. };
  10581. Shader.prototype.setUniformf = function (uniform, value) {
  10582. this.context.gl.uniform1f(this.getUniformLocation(uniform), value);
  10583. };
  10584. Shader.prototype.setUniform2f = function (uniform, value, value2) {
  10585. this.context.gl.uniform2f(this.getUniformLocation(uniform), value, value2);
  10586. };
  10587. Shader.prototype.setUniform3f = function (uniform, value, value2, value3) {
  10588. this.context.gl.uniform3f(this.getUniformLocation(uniform), value, value2, value3);
  10589. };
  10590. Shader.prototype.setUniform4f = function (uniform, value, value2, value3, value4) {
  10591. this.context.gl.uniform4f(this.getUniformLocation(uniform), value, value2, value3, value4);
  10592. };
  10593. Shader.prototype.setUniform2x2f = function (uniform, value) {
  10594. var gl = this.context.gl;
  10595. this.tmp2x2.set(value);
  10596. gl.uniformMatrix2fv(this.getUniformLocation(uniform), false, this.tmp2x2);
  10597. };
  10598. Shader.prototype.setUniform3x3f = function (uniform, value) {
  10599. var gl = this.context.gl;
  10600. this.tmp3x3.set(value);
  10601. gl.uniformMatrix3fv(this.getUniformLocation(uniform), false, this.tmp3x3);
  10602. };
  10603. Shader.prototype.setUniform4x4f = function (uniform, value) {
  10604. var gl = this.context.gl;
  10605. this.tmp4x4.set(value);
  10606. gl.uniformMatrix4fv(this.getUniformLocation(uniform), false, this.tmp4x4);
  10607. };
  10608. Shader.prototype.getUniformLocation = function (uniform) {
  10609. var gl = this.context.gl;
  10610. var location = gl.getUniformLocation(this.program, uniform);
  10611. if (!location && !gl.isContextLost())
  10612. throw new Error("Couldn't find location for uniform " + uniform);
  10613. return location;
  10614. };
  10615. Shader.prototype.getAttributeLocation = function (attribute) {
  10616. var gl = this.context.gl;
  10617. var location = gl.getAttribLocation(this.program, attribute);
  10618. if (location == -1 && !gl.isContextLost())
  10619. throw new Error("Couldn't find location for attribute " + attribute);
  10620. return location;
  10621. };
  10622. Shader.prototype.dispose = function () {
  10623. this.context.removeRestorable(this);
  10624. var gl = this.context.gl;
  10625. if (this.vs) {
  10626. gl.deleteShader(this.vs);
  10627. this.vs = null;
  10628. }
  10629. if (this.fs) {
  10630. gl.deleteShader(this.fs);
  10631. this.fs = null;
  10632. }
  10633. if (this.program) {
  10634. gl.deleteProgram(this.program);
  10635. this.program = null;
  10636. }
  10637. };
  10638. Shader.newColoredTextured = function (context) {
  10639. 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";
  10640. 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";
  10641. return new Shader(context, vs, fs);
  10642. };
  10643. Shader.newTwoColoredTextured = function (context) {
  10644. 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";
  10645. 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";
  10646. return new Shader(context, vs, fs);
  10647. };
  10648. Shader.newColored = function (context) {
  10649. 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";
  10650. 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";
  10651. return new Shader(context, vs, fs);
  10652. };
  10653. Shader.MVP_MATRIX = "u_projTrans";
  10654. Shader.POSITION = "a_position";
  10655. Shader.COLOR = "a_color";
  10656. Shader.COLOR2 = "a_color2";
  10657. Shader.TEXCOORDS = "a_texCoords";
  10658. Shader.SAMPLER = "u_texture";
  10659. return Shader;
  10660. }());
  10661. webgl.Shader = Shader;
  10662. })(webgl = spine.webgl || (spine.webgl = {}));
  10663. })(spine || (spine = {}));
  10664. var spine;
  10665. (function (spine) {
  10666. var webgl;
  10667. (function (webgl) {
  10668. var ShapeRenderer = (function () {
  10669. function ShapeRenderer(context, maxVertices) {
  10670. if (maxVertices === void 0) { maxVertices = 10920; }
  10671. this.isDrawing = false;
  10672. this.shapeType = ShapeType.Filled;
  10673. this.color = new spine.Color(1, 1, 1, 1);
  10674. this.vertexIndex = 0;
  10675. this.tmp = new spine.Vector2();
  10676. if (maxVertices > 10920)
  10677. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  10678. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  10679. this.mesh = new webgl.Mesh(context, [new webgl.Position2Attribute(), new webgl.ColorAttribute()], maxVertices, 0);
  10680. var gl = this.context.gl;
  10681. this.srcColorBlend = gl.SRC_ALPHA;
  10682. this.srcAlphaBlend = gl.ONE;
  10683. this.dstBlend = gl.ONE_MINUS_SRC_ALPHA;
  10684. }
  10685. ShapeRenderer.prototype.begin = function (shader) {
  10686. if (this.isDrawing)
  10687. throw new Error("ShapeRenderer.begin() has already been called");
  10688. this.shader = shader;
  10689. this.vertexIndex = 0;
  10690. this.isDrawing = true;
  10691. var gl = this.context.gl;
  10692. gl.enable(gl.BLEND);
  10693. gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
  10694. };
  10695. ShapeRenderer.prototype.setBlendMode = function (srcColorBlend, srcAlphaBlend, dstBlend) {
  10696. this.srcColorBlend = srcColorBlend;
  10697. this.srcAlphaBlend = srcAlphaBlend;
  10698. this.dstBlend = dstBlend;
  10699. if (this.isDrawing) {
  10700. this.flush();
  10701. var gl = this.context.gl;
  10702. gl.blendFuncSeparate(srcColorBlend, dstBlend, srcAlphaBlend, dstBlend);
  10703. }
  10704. };
  10705. ShapeRenderer.prototype.setColor = function (color) {
  10706. this.color.setFromColor(color);
  10707. };
  10708. ShapeRenderer.prototype.setColorWith = function (r, g, b, a) {
  10709. this.color.set(r, g, b, a);
  10710. };
  10711. ShapeRenderer.prototype.point = function (x, y, color) {
  10712. if (color === void 0) { color = null; }
  10713. this.check(ShapeType.Point, 1);
  10714. if (color === null)
  10715. color = this.color;
  10716. this.vertex(x, y, color);
  10717. };
  10718. ShapeRenderer.prototype.line = function (x, y, x2, y2, color) {
  10719. if (color === void 0) { color = null; }
  10720. this.check(ShapeType.Line, 2);
  10721. var vertices = this.mesh.getVertices();
  10722. var idx = this.vertexIndex;
  10723. if (color === null)
  10724. color = this.color;
  10725. this.vertex(x, y, color);
  10726. this.vertex(x2, y2, color);
  10727. };
  10728. ShapeRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  10729. if (color === void 0) { color = null; }
  10730. if (color2 === void 0) { color2 = null; }
  10731. if (color3 === void 0) { color3 = null; }
  10732. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  10733. var vertices = this.mesh.getVertices();
  10734. var idx = this.vertexIndex;
  10735. if (color === null)
  10736. color = this.color;
  10737. if (color2 === null)
  10738. color2 = this.color;
  10739. if (color3 === null)
  10740. color3 = this.color;
  10741. if (filled) {
  10742. this.vertex(x, y, color);
  10743. this.vertex(x2, y2, color2);
  10744. this.vertex(x3, y3, color3);
  10745. }
  10746. else {
  10747. this.vertex(x, y, color);
  10748. this.vertex(x2, y2, color2);
  10749. this.vertex(x2, y2, color);
  10750. this.vertex(x3, y3, color2);
  10751. this.vertex(x3, y3, color);
  10752. this.vertex(x, y, color2);
  10753. }
  10754. };
  10755. ShapeRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  10756. if (color === void 0) { color = null; }
  10757. if (color2 === void 0) { color2 = null; }
  10758. if (color3 === void 0) { color3 = null; }
  10759. if (color4 === void 0) { color4 = null; }
  10760. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  10761. var vertices = this.mesh.getVertices();
  10762. var idx = this.vertexIndex;
  10763. if (color === null)
  10764. color = this.color;
  10765. if (color2 === null)
  10766. color2 = this.color;
  10767. if (color3 === null)
  10768. color3 = this.color;
  10769. if (color4 === null)
  10770. color4 = this.color;
  10771. if (filled) {
  10772. this.vertex(x, y, color);
  10773. this.vertex(x2, y2, color2);
  10774. this.vertex(x3, y3, color3);
  10775. this.vertex(x3, y3, color3);
  10776. this.vertex(x4, y4, color4);
  10777. this.vertex(x, y, color);
  10778. }
  10779. else {
  10780. this.vertex(x, y, color);
  10781. this.vertex(x2, y2, color2);
  10782. this.vertex(x2, y2, color2);
  10783. this.vertex(x3, y3, color3);
  10784. this.vertex(x3, y3, color3);
  10785. this.vertex(x4, y4, color4);
  10786. this.vertex(x4, y4, color4);
  10787. this.vertex(x, y, color);
  10788. }
  10789. };
  10790. ShapeRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  10791. if (color === void 0) { color = null; }
  10792. this.quad(filled, x, y, x + width, y, x + width, y + height, x, y + height, color, color, color, color);
  10793. };
  10794. ShapeRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  10795. if (color === void 0) { color = null; }
  10796. this.check(filled ? ShapeType.Filled : ShapeType.Line, 8);
  10797. if (color === null)
  10798. color = this.color;
  10799. var t = this.tmp.set(y2 - y1, x1 - x2);
  10800. t.normalize();
  10801. width *= 0.5;
  10802. var tx = t.x * width;
  10803. var ty = t.y * width;
  10804. if (!filled) {
  10805. this.vertex(x1 + tx, y1 + ty, color);
  10806. this.vertex(x1 - tx, y1 - ty, color);
  10807. this.vertex(x2 + tx, y2 + ty, color);
  10808. this.vertex(x2 - tx, y2 - ty, color);
  10809. this.vertex(x2 + tx, y2 + ty, color);
  10810. this.vertex(x1 + tx, y1 + ty, color);
  10811. this.vertex(x2 - tx, y2 - ty, color);
  10812. this.vertex(x1 - tx, y1 - ty, color);
  10813. }
  10814. else {
  10815. this.vertex(x1 + tx, y1 + ty, color);
  10816. this.vertex(x1 - tx, y1 - ty, color);
  10817. this.vertex(x2 + tx, y2 + ty, color);
  10818. this.vertex(x2 - tx, y2 - ty, color);
  10819. this.vertex(x2 + tx, y2 + ty, color);
  10820. this.vertex(x1 - tx, y1 - ty, color);
  10821. }
  10822. };
  10823. ShapeRenderer.prototype.x = function (x, y, size) {
  10824. this.line(x - size, y - size, x + size, y + size);
  10825. this.line(x - size, y + size, x + size, y - size);
  10826. };
  10827. ShapeRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  10828. if (color === void 0) { color = null; }
  10829. if (count < 3)
  10830. throw new Error("Polygon must contain at least 3 vertices");
  10831. this.check(ShapeType.Line, count * 2);
  10832. if (color === null)
  10833. color = this.color;
  10834. var vertices = this.mesh.getVertices();
  10835. var idx = this.vertexIndex;
  10836. offset <<= 1;
  10837. count <<= 1;
  10838. var firstX = polygonVertices[offset];
  10839. var firstY = polygonVertices[offset + 1];
  10840. var last = offset + count;
  10841. for (var i = offset, n = offset + count - 2; i < n; i += 2) {
  10842. var x1 = polygonVertices[i];
  10843. var y1 = polygonVertices[i + 1];
  10844. var x2 = 0;
  10845. var y2 = 0;
  10846. if (i + 2 >= last) {
  10847. x2 = firstX;
  10848. y2 = firstY;
  10849. }
  10850. else {
  10851. x2 = polygonVertices[i + 2];
  10852. y2 = polygonVertices[i + 3];
  10853. }
  10854. this.vertex(x1, y1, color);
  10855. this.vertex(x2, y2, color);
  10856. }
  10857. };
  10858. ShapeRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  10859. if (color === void 0) { color = null; }
  10860. if (segments === void 0) { segments = 0; }
  10861. if (segments === 0)
  10862. segments = Math.max(1, (6 * spine.MathUtils.cbrt(radius)) | 0);
  10863. if (segments <= 0)
  10864. throw new Error("segments must be > 0.");
  10865. if (color === null)
  10866. color = this.color;
  10867. var angle = 2 * spine.MathUtils.PI / segments;
  10868. var cos = Math.cos(angle);
  10869. var sin = Math.sin(angle);
  10870. var cx = radius, cy = 0;
  10871. if (!filled) {
  10872. this.check(ShapeType.Line, segments * 2 + 2);
  10873. for (var i = 0; i < segments; i++) {
  10874. this.vertex(x + cx, y + cy, color);
  10875. var temp_1 = cx;
  10876. cx = cos * cx - sin * cy;
  10877. cy = sin * temp_1 + cos * cy;
  10878. this.vertex(x + cx, y + cy, color);
  10879. }
  10880. this.vertex(x + cx, y + cy, color);
  10881. }
  10882. else {
  10883. this.check(ShapeType.Filled, segments * 3 + 3);
  10884. segments--;
  10885. for (var i = 0; i < segments; i++) {
  10886. this.vertex(x, y, color);
  10887. this.vertex(x + cx, y + cy, color);
  10888. var temp_2 = cx;
  10889. cx = cos * cx - sin * cy;
  10890. cy = sin * temp_2 + cos * cy;
  10891. this.vertex(x + cx, y + cy, color);
  10892. }
  10893. this.vertex(x, y, color);
  10894. this.vertex(x + cx, y + cy, color);
  10895. }
  10896. var temp = cx;
  10897. cx = radius;
  10898. cy = 0;
  10899. this.vertex(x + cx, y + cy, color);
  10900. };
  10901. ShapeRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  10902. if (color === void 0) { color = null; }
  10903. this.check(ShapeType.Line, segments * 2 + 2);
  10904. if (color === null)
  10905. color = this.color;
  10906. var subdiv_step = 1 / segments;
  10907. var subdiv_step2 = subdiv_step * subdiv_step;
  10908. var subdiv_step3 = subdiv_step * subdiv_step * subdiv_step;
  10909. var pre1 = 3 * subdiv_step;
  10910. var pre2 = 3 * subdiv_step2;
  10911. var pre4 = 6 * subdiv_step2;
  10912. var pre5 = 6 * subdiv_step3;
  10913. var tmp1x = x1 - cx1 * 2 + cx2;
  10914. var tmp1y = y1 - cy1 * 2 + cy2;
  10915. var tmp2x = (cx1 - cx2) * 3 - x1 + x2;
  10916. var tmp2y = (cy1 - cy2) * 3 - y1 + y2;
  10917. var fx = x1;
  10918. var fy = y1;
  10919. var dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
  10920. var dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
  10921. var ddfx = tmp1x * pre4 + tmp2x * pre5;
  10922. var ddfy = tmp1y * pre4 + tmp2y * pre5;
  10923. var dddfx = tmp2x * pre5;
  10924. var dddfy = tmp2y * pre5;
  10925. while (segments-- > 0) {
  10926. this.vertex(fx, fy, color);
  10927. fx += dfx;
  10928. fy += dfy;
  10929. dfx += ddfx;
  10930. dfy += ddfy;
  10931. ddfx += dddfx;
  10932. ddfy += dddfy;
  10933. this.vertex(fx, fy, color);
  10934. }
  10935. this.vertex(fx, fy, color);
  10936. this.vertex(x2, y2, color);
  10937. };
  10938. ShapeRenderer.prototype.vertex = function (x, y, color) {
  10939. var idx = this.vertexIndex;
  10940. var vertices = this.mesh.getVertices();
  10941. vertices[idx++] = x;
  10942. vertices[idx++] = y;
  10943. vertices[idx++] = color.r;
  10944. vertices[idx++] = color.g;
  10945. vertices[idx++] = color.b;
  10946. vertices[idx++] = color.a;
  10947. this.vertexIndex = idx;
  10948. };
  10949. ShapeRenderer.prototype.end = function () {
  10950. if (!this.isDrawing)
  10951. throw new Error("ShapeRenderer.begin() has not been called");
  10952. this.flush();
  10953. var gl = this.context.gl;
  10954. gl.disable(gl.BLEND);
  10955. this.isDrawing = false;
  10956. };
  10957. ShapeRenderer.prototype.flush = function () {
  10958. if (this.vertexIndex == 0)
  10959. return;
  10960. this.mesh.setVerticesLength(this.vertexIndex);
  10961. this.mesh.draw(this.shader, this.shapeType);
  10962. this.vertexIndex = 0;
  10963. };
  10964. ShapeRenderer.prototype.check = function (shapeType, numVertices) {
  10965. if (!this.isDrawing)
  10966. throw new Error("ShapeRenderer.begin() has not been called");
  10967. if (this.shapeType == shapeType) {
  10968. if (this.mesh.maxVertices() - this.mesh.numVertices() < numVertices)
  10969. this.flush();
  10970. else
  10971. return;
  10972. }
  10973. else {
  10974. this.flush();
  10975. this.shapeType = shapeType;
  10976. }
  10977. };
  10978. ShapeRenderer.prototype.dispose = function () {
  10979. this.mesh.dispose();
  10980. };
  10981. return ShapeRenderer;
  10982. }());
  10983. webgl.ShapeRenderer = ShapeRenderer;
  10984. var ShapeType;
  10985. (function (ShapeType) {
  10986. ShapeType[ShapeType["Point"] = 0] = "Point";
  10987. ShapeType[ShapeType["Line"] = 1] = "Line";
  10988. ShapeType[ShapeType["Filled"] = 4] = "Filled";
  10989. })(ShapeType = webgl.ShapeType || (webgl.ShapeType = {}));
  10990. })(webgl = spine.webgl || (spine.webgl = {}));
  10991. })(spine || (spine = {}));
  10992. var spine;
  10993. (function (spine) {
  10994. var webgl;
  10995. (function (webgl) {
  10996. var SkeletonDebugRenderer = (function () {
  10997. function SkeletonDebugRenderer(context) {
  10998. this.boneLineColor = new spine.Color(1, 0, 0, 1);
  10999. this.boneOriginColor = new spine.Color(0, 1, 0, 1);
  11000. this.attachmentLineColor = new spine.Color(0, 0, 1, 0.5);
  11001. this.triangleLineColor = new spine.Color(1, 0.64, 0, 0.5);
  11002. this.pathColor = new spine.Color().setFromString("FF7F00");
  11003. this.clipColor = new spine.Color(0.8, 0, 0, 2);
  11004. this.aabbColor = new spine.Color(0, 1, 0, 0.5);
  11005. this.drawBones = true;
  11006. this.drawRegionAttachments = true;
  11007. this.drawBoundingBoxes = true;
  11008. this.drawMeshHull = true;
  11009. this.drawMeshTriangles = true;
  11010. this.drawPaths = true;
  11011. this.drawSkeletonXY = false;
  11012. this.drawClipping = true;
  11013. this.premultipliedAlpha = false;
  11014. this.scale = 1;
  11015. this.boneWidth = 2;
  11016. this.bounds = new spine.SkeletonBounds();
  11017. this.temp = new Array();
  11018. this.vertices = spine.Utils.newFloatArray(2 * 1024);
  11019. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  11020. }
  11021. SkeletonDebugRenderer.prototype.draw = function (shapes, skeleton, ignoredBones) {
  11022. if (ignoredBones === void 0) { ignoredBones = null; }
  11023. var skeletonX = skeleton.x;
  11024. var skeletonY = skeleton.y;
  11025. var gl = this.context.gl;
  11026. var srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA;
  11027. shapes.setBlendMode(srcFunc, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  11028. var bones = skeleton.bones;
  11029. if (this.drawBones) {
  11030. shapes.setColor(this.boneLineColor);
  11031. for (var i = 0, n = bones.length; i < n; i++) {
  11032. var bone = bones[i];
  11033. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  11034. continue;
  11035. if (!bone.parent)
  11036. continue;
  11037. var x = skeletonX + bone.data.length * bone.a + bone.worldX;
  11038. var y = skeletonY + bone.data.length * bone.c + bone.worldY;
  11039. shapes.rectLine(true, skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, this.boneWidth * this.scale);
  11040. }
  11041. if (this.drawSkeletonXY)
  11042. shapes.x(skeletonX, skeletonY, 4 * this.scale);
  11043. }
  11044. if (this.drawRegionAttachments) {
  11045. shapes.setColor(this.attachmentLineColor);
  11046. var slots = skeleton.slots;
  11047. for (var i = 0, n = slots.length; i < n; i++) {
  11048. var slot = slots[i];
  11049. var attachment = slot.getAttachment();
  11050. if (attachment instanceof spine.RegionAttachment) {
  11051. var regionAttachment = attachment;
  11052. var vertices = this.vertices;
  11053. regionAttachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  11054. shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]);
  11055. shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]);
  11056. shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]);
  11057. shapes.line(vertices[6], vertices[7], vertices[0], vertices[1]);
  11058. }
  11059. }
  11060. }
  11061. if (this.drawMeshHull || this.drawMeshTriangles) {
  11062. var slots = skeleton.slots;
  11063. for (var i = 0, n = slots.length; i < n; i++) {
  11064. var slot = slots[i];
  11065. if (!slot.bone.active)
  11066. continue;
  11067. var attachment = slot.getAttachment();
  11068. if (!(attachment instanceof spine.MeshAttachment))
  11069. continue;
  11070. var mesh = attachment;
  11071. var vertices = this.vertices;
  11072. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 2);
  11073. var triangles = mesh.triangles;
  11074. var hullLength = mesh.hullLength;
  11075. if (this.drawMeshTriangles) {
  11076. shapes.setColor(this.triangleLineColor);
  11077. for (var ii = 0, nn = triangles.length; ii < nn; ii += 3) {
  11078. var v1 = triangles[ii] * 2, v2 = triangles[ii + 1] * 2, v3 = triangles[ii + 2] * 2;
  11079. shapes.triangle(false, vertices[v1], vertices[v1 + 1], vertices[v2], vertices[v2 + 1], vertices[v3], vertices[v3 + 1]);
  11080. }
  11081. }
  11082. if (this.drawMeshHull && hullLength > 0) {
  11083. shapes.setColor(this.attachmentLineColor);
  11084. hullLength = (hullLength >> 1) * 2;
  11085. var lastX = vertices[hullLength - 2], lastY = vertices[hullLength - 1];
  11086. for (var ii = 0, nn = hullLength; ii < nn; ii += 2) {
  11087. var x = vertices[ii], y = vertices[ii + 1];
  11088. shapes.line(x, y, lastX, lastY);
  11089. lastX = x;
  11090. lastY = y;
  11091. }
  11092. }
  11093. }
  11094. }
  11095. if (this.drawBoundingBoxes) {
  11096. var bounds = this.bounds;
  11097. bounds.update(skeleton, true);
  11098. shapes.setColor(this.aabbColor);
  11099. shapes.rect(false, bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight());
  11100. var polygons = bounds.polygons;
  11101. var boxes = bounds.boundingBoxes;
  11102. for (var i = 0, n = polygons.length; i < n; i++) {
  11103. var polygon = polygons[i];
  11104. shapes.setColor(boxes[i].color);
  11105. shapes.polygon(polygon, 0, polygon.length);
  11106. }
  11107. }
  11108. if (this.drawPaths) {
  11109. var slots = skeleton.slots;
  11110. for (var i = 0, n = slots.length; i < n; i++) {
  11111. var slot = slots[i];
  11112. if (!slot.bone.active)
  11113. continue;
  11114. var attachment = slot.getAttachment();
  11115. if (!(attachment instanceof spine.PathAttachment))
  11116. continue;
  11117. var path = attachment;
  11118. var nn = path.worldVerticesLength;
  11119. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  11120. path.computeWorldVertices(slot, 0, nn, world, 0, 2);
  11121. var color = this.pathColor;
  11122. var x1 = world[2], y1 = world[3], x2 = 0, y2 = 0;
  11123. if (path.closed) {
  11124. shapes.setColor(color);
  11125. var cx1 = world[0], cy1 = world[1], cx2 = world[nn - 2], cy2 = world[nn - 1];
  11126. x2 = world[nn - 4];
  11127. y2 = world[nn - 3];
  11128. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  11129. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  11130. shapes.line(x1, y1, cx1, cy1);
  11131. shapes.line(x2, y2, cx2, cy2);
  11132. }
  11133. nn -= 4;
  11134. for (var ii = 4; ii < nn; ii += 6) {
  11135. var cx1 = world[ii], cy1 = world[ii + 1], cx2 = world[ii + 2], cy2 = world[ii + 3];
  11136. x2 = world[ii + 4];
  11137. y2 = world[ii + 5];
  11138. shapes.setColor(color);
  11139. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  11140. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  11141. shapes.line(x1, y1, cx1, cy1);
  11142. shapes.line(x2, y2, cx2, cy2);
  11143. x1 = x2;
  11144. y1 = y2;
  11145. }
  11146. }
  11147. }
  11148. if (this.drawBones) {
  11149. shapes.setColor(this.boneOriginColor);
  11150. for (var i = 0, n = bones.length; i < n; i++) {
  11151. var bone = bones[i];
  11152. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  11153. continue;
  11154. shapes.circle(true, skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * this.scale, SkeletonDebugRenderer.GREEN, 8);
  11155. }
  11156. }
  11157. if (this.drawClipping) {
  11158. var slots = skeleton.slots;
  11159. shapes.setColor(this.clipColor);
  11160. for (var i = 0, n = slots.length; i < n; i++) {
  11161. var slot = slots[i];
  11162. if (!slot.bone.active)
  11163. continue;
  11164. var attachment = slot.getAttachment();
  11165. if (!(attachment instanceof spine.ClippingAttachment))
  11166. continue;
  11167. var clip = attachment;
  11168. var nn = clip.worldVerticesLength;
  11169. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  11170. clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
  11171. for (var i_21 = 0, n_3 = world.length; i_21 < n_3; i_21 += 2) {
  11172. var x = world[i_21];
  11173. var y = world[i_21 + 1];
  11174. var x2 = world[(i_21 + 2) % world.length];
  11175. var y2 = world[(i_21 + 3) % world.length];
  11176. shapes.line(x, y, x2, y2);
  11177. }
  11178. }
  11179. }
  11180. };
  11181. SkeletonDebugRenderer.prototype.dispose = function () {
  11182. };
  11183. SkeletonDebugRenderer.LIGHT_GRAY = new spine.Color(192 / 255, 192 / 255, 192 / 255, 1);
  11184. SkeletonDebugRenderer.GREEN = new spine.Color(0, 1, 0, 1);
  11185. return SkeletonDebugRenderer;
  11186. }());
  11187. webgl.SkeletonDebugRenderer = SkeletonDebugRenderer;
  11188. })(webgl = spine.webgl || (spine.webgl = {}));
  11189. })(spine || (spine = {}));
  11190. var spine;
  11191. (function (spine) {
  11192. var webgl;
  11193. (function (webgl) {
  11194. var Renderable = (function () {
  11195. function Renderable(vertices, numVertices, numFloats) {
  11196. this.vertices = vertices;
  11197. this.numVertices = numVertices;
  11198. this.numFloats = numFloats;
  11199. }
  11200. return Renderable;
  11201. }());
  11202. ;
  11203. var SkeletonRenderer = (function () {
  11204. function SkeletonRenderer(context, twoColorTint) {
  11205. if (twoColorTint === void 0) { twoColorTint = true; }
  11206. this.premultipliedAlpha = false;
  11207. this.vertexEffect = null;
  11208. this.tempColor = new spine.Color();
  11209. this.tempColor2 = new spine.Color();
  11210. this.vertexSize = 2 + 2 + 4;
  11211. this.twoColorTint = false;
  11212. this.renderable = new Renderable(null, 0, 0);
  11213. this.clipper = new spine.SkeletonClipping();
  11214. this.temp = new spine.Vector2();
  11215. this.temp2 = new spine.Vector2();
  11216. this.temp3 = new spine.Color();
  11217. this.temp4 = new spine.Color();
  11218. this.twoColorTint = twoColorTint;
  11219. if (twoColorTint)
  11220. this.vertexSize += 4;
  11221. this.vertices = spine.Utils.newFloatArray(this.vertexSize * 1024);
  11222. }
  11223. SkeletonRenderer.prototype.draw = function (batcher, skeleton, slotRangeStart, slotRangeEnd) {
  11224. if (slotRangeStart === void 0) { slotRangeStart = -1; }
  11225. if (slotRangeEnd === void 0) { slotRangeEnd = -1; }
  11226. var clipper = this.clipper;
  11227. var premultipliedAlpha = this.premultipliedAlpha;
  11228. var twoColorTint = this.twoColorTint;
  11229. var blendMode = null;
  11230. var tempPos = this.temp;
  11231. var tempUv = this.temp2;
  11232. var tempLight = this.temp3;
  11233. var tempDark = this.temp4;
  11234. var renderable = this.renderable;
  11235. var uvs = null;
  11236. var triangles = null;
  11237. var drawOrder = skeleton.drawOrder;
  11238. var attachmentColor = null;
  11239. var skeletonColor = skeleton.color;
  11240. var vertexSize = twoColorTint ? 12 : 8;
  11241. var inRange = false;
  11242. if (slotRangeStart == -1)
  11243. inRange = true;
  11244. for (var i = 0, n = drawOrder.length; i < n; i++) {
  11245. var clippedVertexSize = clipper.isClipping() ? 2 : vertexSize;
  11246. var slot = drawOrder[i];
  11247. if (!slot.bone.active) {
  11248. clipper.clipEndWithSlot(slot);
  11249. continue;
  11250. }
  11251. if (slotRangeStart >= 0 && slotRangeStart == slot.data.index) {
  11252. inRange = true;
  11253. }
  11254. if (!inRange) {
  11255. clipper.clipEndWithSlot(slot);
  11256. continue;
  11257. }
  11258. if (slotRangeEnd >= 0 && slotRangeEnd == slot.data.index) {
  11259. inRange = false;
  11260. }
  11261. var attachment = slot.getAttachment();
  11262. var texture = null;
  11263. if (attachment instanceof spine.RegionAttachment) {
  11264. var region = attachment;
  11265. renderable.vertices = this.vertices;
  11266. renderable.numVertices = 4;
  11267. renderable.numFloats = clippedVertexSize << 2;
  11268. region.computeWorldVertices(slot.bone, renderable.vertices, 0, clippedVertexSize);
  11269. triangles = SkeletonRenderer.QUAD_TRIANGLES;
  11270. uvs = region.uvs;
  11271. texture = region.region.renderObject.page.texture;
  11272. attachmentColor = region.color;
  11273. }
  11274. else if (attachment instanceof spine.MeshAttachment) {
  11275. var mesh = attachment;
  11276. renderable.vertices = this.vertices;
  11277. renderable.numVertices = (mesh.worldVerticesLength >> 1);
  11278. renderable.numFloats = renderable.numVertices * clippedVertexSize;
  11279. if (renderable.numFloats > renderable.vertices.length) {
  11280. renderable.vertices = this.vertices = spine.Utils.newFloatArray(renderable.numFloats);
  11281. }
  11282. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, renderable.vertices, 0, clippedVertexSize);
  11283. triangles = mesh.triangles;
  11284. texture = mesh.region.renderObject.page.texture;
  11285. uvs = mesh.uvs;
  11286. attachmentColor = mesh.color;
  11287. }
  11288. else if (attachment instanceof spine.ClippingAttachment) {
  11289. var clip = (attachment);
  11290. clipper.clipStart(slot, clip);
  11291. continue;
  11292. }
  11293. else {
  11294. clipper.clipEndWithSlot(slot);
  11295. continue;
  11296. }
  11297. if (texture) {
  11298. var slotColor = slot.color;
  11299. var finalColor = this.tempColor;
  11300. finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
  11301. finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
  11302. finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
  11303. finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
  11304. if (premultipliedAlpha) {
  11305. finalColor.r *= finalColor.a;
  11306. finalColor.g *= finalColor.a;
  11307. finalColor.b *= finalColor.a;
  11308. }
  11309. var darkColor = this.tempColor2;
  11310. if (!slot.darkColor)
  11311. darkColor.set(0, 0, 0, 1.0);
  11312. else {
  11313. if (premultipliedAlpha) {
  11314. darkColor.r = slot.darkColor.r * finalColor.a;
  11315. darkColor.g = slot.darkColor.g * finalColor.a;
  11316. darkColor.b = slot.darkColor.b * finalColor.a;
  11317. }
  11318. else {
  11319. darkColor.setFromColor(slot.darkColor);
  11320. }
  11321. darkColor.a = premultipliedAlpha ? 1.0 : 0.0;
  11322. }
  11323. var slotBlendMode = slot.data.blendMode;
  11324. if (slotBlendMode != blendMode) {
  11325. blendMode = slotBlendMode;
  11326. batcher.setBlendMode(webgl.WebGLBlendModeConverter.getSourceColorGLBlendMode(blendMode, premultipliedAlpha), webgl.WebGLBlendModeConverter.getSourceAlphaGLBlendMode(blendMode), webgl.WebGLBlendModeConverter.getDestGLBlendMode(blendMode));
  11327. }
  11328. if (clipper.isClipping()) {
  11329. clipper.clipTriangles(renderable.vertices, renderable.numFloats, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint);
  11330. var clippedVertices = new Float32Array(clipper.clippedVertices);
  11331. var clippedTriangles = clipper.clippedTriangles;
  11332. if (this.vertexEffect) {
  11333. var vertexEffect = this.vertexEffect;
  11334. var verts = clippedVertices;
  11335. if (!twoColorTint) {
  11336. for (var v = 0, n_4 = clippedVertices.length; v < n_4; v += vertexSize) {
  11337. tempPos.x = verts[v];
  11338. tempPos.y = verts[v + 1];
  11339. tempLight.set(verts[v + 2], verts[v + 3], verts[v + 4], verts[v + 5]);
  11340. tempUv.x = verts[v + 6];
  11341. tempUv.y = verts[v + 7];
  11342. tempDark.set(0, 0, 0, 0);
  11343. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  11344. verts[v] = tempPos.x;
  11345. verts[v + 1] = tempPos.y;
  11346. verts[v + 2] = tempLight.r;
  11347. verts[v + 3] = tempLight.g;
  11348. verts[v + 4] = tempLight.b;
  11349. verts[v + 5] = tempLight.a;
  11350. verts[v + 6] = tempUv.x;
  11351. verts[v + 7] = tempUv.y;
  11352. }
  11353. }
  11354. else {
  11355. for (var v = 0, n_5 = clippedVertices.length; v < n_5; v += vertexSize) {
  11356. tempPos.x = verts[v];
  11357. tempPos.y = verts[v + 1];
  11358. tempLight.set(verts[v + 2], verts[v + 3], verts[v + 4], verts[v + 5]);
  11359. tempUv.x = verts[v + 6];
  11360. tempUv.y = verts[v + 7];
  11361. tempDark.set(verts[v + 8], verts[v + 9], verts[v + 10], verts[v + 11]);
  11362. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  11363. verts[v] = tempPos.x;
  11364. verts[v + 1] = tempPos.y;
  11365. verts[v + 2] = tempLight.r;
  11366. verts[v + 3] = tempLight.g;
  11367. verts[v + 4] = tempLight.b;
  11368. verts[v + 5] = tempLight.a;
  11369. verts[v + 6] = tempUv.x;
  11370. verts[v + 7] = tempUv.y;
  11371. verts[v + 8] = tempDark.r;
  11372. verts[v + 9] = tempDark.g;
  11373. verts[v + 10] = tempDark.b;
  11374. verts[v + 11] = tempDark.a;
  11375. }
  11376. }
  11377. }
  11378. batcher.draw(texture, clippedVertices, clippedTriangles);
  11379. }
  11380. else {
  11381. var verts = renderable.vertices;
  11382. if (this.vertexEffect) {
  11383. var vertexEffect = this.vertexEffect;
  11384. if (!twoColorTint) {
  11385. for (var v = 0, u = 0, n_6 = renderable.numFloats; v < n_6; v += vertexSize, u += 2) {
  11386. tempPos.x = verts[v];
  11387. tempPos.y = verts[v + 1];
  11388. tempUv.x = uvs[u];
  11389. tempUv.y = uvs[u + 1];
  11390. tempLight.setFromColor(finalColor);
  11391. tempDark.set(0, 0, 0, 0);
  11392. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  11393. verts[v] = tempPos.x;
  11394. verts[v + 1] = tempPos.y;
  11395. verts[v + 2] = tempLight.r;
  11396. verts[v + 3] = tempLight.g;
  11397. verts[v + 4] = tempLight.b;
  11398. verts[v + 5] = tempLight.a;
  11399. verts[v + 6] = tempUv.x;
  11400. verts[v + 7] = tempUv.y;
  11401. }
  11402. }
  11403. else {
  11404. for (var v = 0, u = 0, n_7 = renderable.numFloats; v < n_7; v += vertexSize, u += 2) {
  11405. tempPos.x = verts[v];
  11406. tempPos.y = verts[v + 1];
  11407. tempUv.x = uvs[u];
  11408. tempUv.y = uvs[u + 1];
  11409. tempLight.setFromColor(finalColor);
  11410. tempDark.setFromColor(darkColor);
  11411. vertexEffect.transform(tempPos, tempUv, tempLight, tempDark);
  11412. verts[v] = tempPos.x;
  11413. verts[v + 1] = tempPos.y;
  11414. verts[v + 2] = tempLight.r;
  11415. verts[v + 3] = tempLight.g;
  11416. verts[v + 4] = tempLight.b;
  11417. verts[v + 5] = tempLight.a;
  11418. verts[v + 6] = tempUv.x;
  11419. verts[v + 7] = tempUv.y;
  11420. verts[v + 8] = tempDark.r;
  11421. verts[v + 9] = tempDark.g;
  11422. verts[v + 10] = tempDark.b;
  11423. verts[v + 11] = tempDark.a;
  11424. }
  11425. }
  11426. }
  11427. else {
  11428. if (!twoColorTint) {
  11429. for (var v = 2, u = 0, n_8 = renderable.numFloats; v < n_8; v += vertexSize, u += 2) {
  11430. verts[v] = finalColor.r;
  11431. verts[v + 1] = finalColor.g;
  11432. verts[v + 2] = finalColor.b;
  11433. verts[v + 3] = finalColor.a;
  11434. verts[v + 4] = uvs[u];
  11435. verts[v + 5] = uvs[u + 1];
  11436. }
  11437. }
  11438. else {
  11439. for (var v = 2, u = 0, n_9 = renderable.numFloats; v < n_9; v += vertexSize, u += 2) {
  11440. verts[v] = finalColor.r;
  11441. verts[v + 1] = finalColor.g;
  11442. verts[v + 2] = finalColor.b;
  11443. verts[v + 3] = finalColor.a;
  11444. verts[v + 4] = uvs[u];
  11445. verts[v + 5] = uvs[u + 1];
  11446. verts[v + 6] = darkColor.r;
  11447. verts[v + 7] = darkColor.g;
  11448. verts[v + 8] = darkColor.b;
  11449. verts[v + 9] = darkColor.a;
  11450. }
  11451. }
  11452. }
  11453. var view = renderable.vertices.subarray(0, renderable.numFloats);
  11454. batcher.draw(texture, view, triangles);
  11455. }
  11456. }
  11457. clipper.clipEndWithSlot(slot);
  11458. }
  11459. clipper.clipEnd();
  11460. };
  11461. SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  11462. return SkeletonRenderer;
  11463. }());
  11464. webgl.SkeletonRenderer = SkeletonRenderer;
  11465. })(webgl = spine.webgl || (spine.webgl = {}));
  11466. })(spine || (spine = {}));
  11467. var spine;
  11468. (function (spine) {
  11469. var webgl;
  11470. (function (webgl) {
  11471. var Vector3 = (function () {
  11472. function Vector3(x, y, z) {
  11473. if (x === void 0) { x = 0; }
  11474. if (y === void 0) { y = 0; }
  11475. if (z === void 0) { z = 0; }
  11476. this.x = 0;
  11477. this.y = 0;
  11478. this.z = 0;
  11479. this.x = x;
  11480. this.y = y;
  11481. this.z = z;
  11482. }
  11483. Vector3.prototype.setFrom = function (v) {
  11484. this.x = v.x;
  11485. this.y = v.y;
  11486. this.z = v.z;
  11487. return this;
  11488. };
  11489. Vector3.prototype.set = function (x, y, z) {
  11490. this.x = x;
  11491. this.y = y;
  11492. this.z = z;
  11493. return this;
  11494. };
  11495. Vector3.prototype.add = function (v) {
  11496. this.x += v.x;
  11497. this.y += v.y;
  11498. this.z += v.z;
  11499. return this;
  11500. };
  11501. Vector3.prototype.sub = function (v) {
  11502. this.x -= v.x;
  11503. this.y -= v.y;
  11504. this.z -= v.z;
  11505. return this;
  11506. };
  11507. Vector3.prototype.scale = function (s) {
  11508. this.x *= s;
  11509. this.y *= s;
  11510. this.z *= s;
  11511. return this;
  11512. };
  11513. Vector3.prototype.normalize = function () {
  11514. var len = this.length();
  11515. if (len == 0)
  11516. return this;
  11517. len = 1 / len;
  11518. this.x *= len;
  11519. this.y *= len;
  11520. this.z *= len;
  11521. return this;
  11522. };
  11523. Vector3.prototype.cross = function (v) {
  11524. 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);
  11525. };
  11526. Vector3.prototype.multiply = function (matrix) {
  11527. var l_mat = matrix.values;
  11528. 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]);
  11529. };
  11530. Vector3.prototype.project = function (matrix) {
  11531. var l_mat = matrix.values;
  11532. 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]);
  11533. 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);
  11534. };
  11535. Vector3.prototype.dot = function (v) {
  11536. return this.x * v.x + this.y * v.y + this.z * v.z;
  11537. };
  11538. Vector3.prototype.length = function () {
  11539. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  11540. };
  11541. Vector3.prototype.distance = function (v) {
  11542. var a = v.x - this.x;
  11543. var b = v.y - this.y;
  11544. var c = v.z - this.z;
  11545. return Math.sqrt(a * a + b * b + c * c);
  11546. };
  11547. return Vector3;
  11548. }());
  11549. webgl.Vector3 = Vector3;
  11550. })(webgl = spine.webgl || (spine.webgl = {}));
  11551. })(spine || (spine = {}));
  11552. var spine;
  11553. (function (spine) {
  11554. var webgl;
  11555. (function (webgl) {
  11556. var ManagedWebGLRenderingContext = (function () {
  11557. function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) {
  11558. if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
  11559. this.restorables = new Array();
  11560. if (!((canvasOrContext instanceof WebGLRenderingContext) || (canvasOrContext instanceof WebGL2RenderingContext)))
  11561. this.setupCanvas(canvasOrContext, contextConfig);
  11562. else {
  11563. this.gl = canvasOrContext;
  11564. this.canvas = this.gl.canvas;
  11565. }
  11566. }
  11567. ManagedWebGLRenderingContext.prototype.setupCanvas = function (canvas, contextConfig) {
  11568. var _this = this;
  11569. this.gl = (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
  11570. this.canvas = canvas;
  11571. canvas.addEventListener("webglcontextlost", function (e) {
  11572. var event = e;
  11573. if (e)
  11574. e.preventDefault();
  11575. });
  11576. canvas.addEventListener("webglcontextrestored", function (e) {
  11577. for (var i = 0, n = _this.restorables.length; i < n; i++)
  11578. _this.restorables[i].restore();
  11579. });
  11580. };
  11581. ManagedWebGLRenderingContext.prototype.addRestorable = function (restorable) {
  11582. this.restorables.push(restorable);
  11583. };
  11584. ManagedWebGLRenderingContext.prototype.removeRestorable = function (restorable) {
  11585. var index = this.restorables.indexOf(restorable);
  11586. if (index > -1)
  11587. this.restorables.splice(index, 1);
  11588. };
  11589. return ManagedWebGLRenderingContext;
  11590. }());
  11591. webgl.ManagedWebGLRenderingContext = ManagedWebGLRenderingContext;
  11592. var ONE = 1;
  11593. var ONE_MINUS_SRC_COLOR = 0x0301;
  11594. var SRC_ALPHA = 0x0302;
  11595. var ONE_MINUS_SRC_ALPHA = 0x0303;
  11596. var ONE_MINUS_DST_ALPHA = 0x0305;
  11597. var DST_COLOR = 0x0306;
  11598. var WebGLBlendModeConverter = (function () {
  11599. function WebGLBlendModeConverter() {
  11600. }
  11601. WebGLBlendModeConverter.getDestGLBlendMode = function (blendMode) {
  11602. switch (blendMode) {
  11603. case spine.BlendMode.Normal: return ONE_MINUS_SRC_ALPHA;
  11604. case spine.BlendMode.Additive: return ONE;
  11605. case spine.BlendMode.Multiply: return ONE_MINUS_SRC_ALPHA;
  11606. case spine.BlendMode.Screen: return ONE_MINUS_SRC_ALPHA;
  11607. default: throw new Error("Unknown blend mode: " + blendMode);
  11608. }
  11609. };
  11610. WebGLBlendModeConverter.getSourceColorGLBlendMode = function (blendMode, premultipliedAlpha) {
  11611. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  11612. switch (blendMode) {
  11613. case spine.BlendMode.Normal: return premultipliedAlpha ? ONE : SRC_ALPHA;
  11614. case spine.BlendMode.Additive: return premultipliedAlpha ? ONE : SRC_ALPHA;
  11615. case spine.BlendMode.Multiply: return DST_COLOR;
  11616. case spine.BlendMode.Screen: return ONE;
  11617. default: throw new Error("Unknown blend mode: " + blendMode);
  11618. }
  11619. };
  11620. WebGLBlendModeConverter.getSourceAlphaGLBlendMode = function (blendMode) {
  11621. switch (blendMode) {
  11622. case spine.BlendMode.Normal: return ONE;
  11623. case spine.BlendMode.Additive: return ONE;
  11624. case spine.BlendMode.Multiply: return ONE_MINUS_SRC_ALPHA;
  11625. case spine.BlendMode.Screen: return ONE_MINUS_SRC_COLOR;
  11626. default: throw new Error("Unknown blend mode: " + blendMode);
  11627. }
  11628. };
  11629. return WebGLBlendModeConverter;
  11630. }());
  11631. webgl.WebGLBlendModeConverter = WebGLBlendModeConverter;
  11632. })(webgl = spine.webgl || (spine.webgl = {}));
  11633. })(spine || (spine = {}));
  11634. module.exports = spine;