spine-webgl.js 319 KB

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