spine-all.js 351 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541
  1. var spine;
  2. (function (spine) {
  3. var AssetManager = (function () {
  4. function AssetManager(textureLoader, pathPrefix) {
  5. if (pathPrefix === void 0) { pathPrefix = ""; }
  6. this.assets = {};
  7. this.errors = {};
  8. this.toLoad = 0;
  9. this.loaded = 0;
  10. this.textureLoader = textureLoader;
  11. this.pathPrefix = pathPrefix;
  12. }
  13. AssetManager.prototype.loadText = function (path, success, error) {
  14. var _this = this;
  15. if (success === void 0) { success = null; }
  16. if (error === void 0) { error = null; }
  17. path = this.pathPrefix + path;
  18. this.toLoad++;
  19. var request = new XMLHttpRequest();
  20. request.onreadystatechange = function () {
  21. if (request.readyState == XMLHttpRequest.DONE) {
  22. if (request.status >= 200 && request.status < 300) {
  23. _this.assets[path] = request.responseText;
  24. if (success)
  25. success(path, request.responseText);
  26. }
  27. else {
  28. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  29. if (error)
  30. error(path, "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText);
  31. }
  32. _this.toLoad--;
  33. _this.loaded++;
  34. }
  35. };
  36. request.open("GET", path, true);
  37. request.send();
  38. };
  39. AssetManager.prototype.loadTexture = function (path, success, error) {
  40. var _this = this;
  41. if (success === void 0) { success = null; }
  42. if (error === void 0) { error = null; }
  43. path = this.pathPrefix + path;
  44. this.toLoad++;
  45. var img = new Image();
  46. img.crossOrigin = "anonymous";
  47. img.onload = function (ev) {
  48. var texture = _this.textureLoader(img);
  49. _this.assets[path] = texture;
  50. _this.toLoad--;
  51. _this.loaded++;
  52. if (success)
  53. success(path, img);
  54. };
  55. img.onerror = function (ev) {
  56. _this.errors[path] = "Couldn't load image " + path;
  57. _this.toLoad--;
  58. _this.loaded++;
  59. if (error)
  60. error(path, "Couldn't load image " + path);
  61. };
  62. img.src = path;
  63. };
  64. AssetManager.prototype.loadTextureData = function (path, data, success, error) {
  65. var _this = this;
  66. if (success === void 0) { success = null; }
  67. if (error === void 0) { error = null; }
  68. path = this.pathPrefix + path;
  69. this.toLoad++;
  70. var img = new Image();
  71. img.onload = function (ev) {
  72. var texture = _this.textureLoader(img);
  73. _this.assets[path] = texture;
  74. _this.toLoad--;
  75. _this.loaded++;
  76. if (success)
  77. success(path, img);
  78. };
  79. img.onerror = function (ev) {
  80. _this.errors[path] = "Couldn't load image " + path;
  81. _this.toLoad--;
  82. _this.loaded++;
  83. if (error)
  84. error(path, "Couldn't load image " + path);
  85. };
  86. img.src = data;
  87. };
  88. AssetManager.prototype.get = function (path) {
  89. path = this.pathPrefix + path;
  90. return this.assets[path];
  91. };
  92. AssetManager.prototype.remove = function (path) {
  93. path = this.pathPrefix + path;
  94. var asset = this.assets[path];
  95. if (asset.dispose)
  96. asset.dispose();
  97. this.assets[path] = null;
  98. };
  99. AssetManager.prototype.removeAll = function () {
  100. for (var key in this.assets) {
  101. var asset = this.assets[key];
  102. if (asset.dispose)
  103. asset.dispose();
  104. }
  105. this.assets = {};
  106. };
  107. AssetManager.prototype.isLoadingComplete = function () {
  108. return this.toLoad == 0;
  109. };
  110. AssetManager.prototype.getToLoad = function () {
  111. return this.toLoad;
  112. };
  113. AssetManager.prototype.getLoaded = function () {
  114. return this.loaded;
  115. };
  116. AssetManager.prototype.dispose = function () {
  117. this.removeAll();
  118. };
  119. AssetManager.prototype.hasErrors = function () {
  120. return Object.keys(this.errors).length > 0;
  121. };
  122. AssetManager.prototype.getErrors = function () {
  123. return this.errors;
  124. };
  125. return AssetManager;
  126. }());
  127. spine.AssetManager = AssetManager;
  128. })(spine || (spine = {}));
  129. var __extends = (this && this.__extends) || function (d, b) {
  130. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  131. function __() { this.constructor = d; }
  132. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  133. };
  134. var spine;
  135. (function (spine) {
  136. var canvas;
  137. (function (canvas) {
  138. var AssetManager = (function (_super) {
  139. __extends(AssetManager, _super);
  140. function AssetManager(pathPrefix) {
  141. if (pathPrefix === void 0) { pathPrefix = ""; }
  142. _super.call(this, function (image) { return new spine.canvas.CanvasTexture(image); }, pathPrefix);
  143. }
  144. return AssetManager;
  145. }(spine.AssetManager));
  146. canvas.AssetManager = AssetManager;
  147. })(canvas = spine.canvas || (spine.canvas = {}));
  148. })(spine || (spine = {}));
  149. var spine;
  150. (function (spine) {
  151. var Texture = (function () {
  152. function Texture(image) {
  153. this._image = image;
  154. }
  155. Texture.prototype.getImage = function () {
  156. return this._image;
  157. };
  158. Texture.filterFromString = function (text) {
  159. switch (text.toLowerCase()) {
  160. case "nearest": return TextureFilter.Nearest;
  161. case "linear": return TextureFilter.Linear;
  162. case "mipmap": return TextureFilter.MipMap;
  163. case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest;
  164. case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest;
  165. case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear;
  166. case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear;
  167. default: throw new Error("Unknown texture filter " + text);
  168. }
  169. };
  170. Texture.wrapFromString = function (text) {
  171. switch (text.toLowerCase()) {
  172. case "mirroredtepeat": return TextureWrap.MirroredRepeat;
  173. case "clamptoedge": return TextureWrap.ClampToEdge;
  174. case "repeat": return TextureWrap.Repeat;
  175. default: throw new Error("Unknown texture wrap " + text);
  176. }
  177. };
  178. return Texture;
  179. }());
  180. spine.Texture = Texture;
  181. (function (TextureFilter) {
  182. TextureFilter[TextureFilter["Nearest"] = 9728] = "Nearest";
  183. TextureFilter[TextureFilter["Linear"] = 9729] = "Linear";
  184. TextureFilter[TextureFilter["MipMap"] = 9987] = "MipMap";
  185. TextureFilter[TextureFilter["MipMapNearestNearest"] = 9984] = "MipMapNearestNearest";
  186. TextureFilter[TextureFilter["MipMapLinearNearest"] = 9985] = "MipMapLinearNearest";
  187. TextureFilter[TextureFilter["MipMapNearestLinear"] = 9986] = "MipMapNearestLinear";
  188. TextureFilter[TextureFilter["MipMapLinearLinear"] = 9987] = "MipMapLinearLinear";
  189. })(spine.TextureFilter || (spine.TextureFilter = {}));
  190. var TextureFilter = spine.TextureFilter;
  191. (function (TextureWrap) {
  192. TextureWrap[TextureWrap["MirroredRepeat"] = 33648] = "MirroredRepeat";
  193. TextureWrap[TextureWrap["ClampToEdge"] = 33071] = "ClampToEdge";
  194. TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat";
  195. })(spine.TextureWrap || (spine.TextureWrap = {}));
  196. var TextureWrap = spine.TextureWrap;
  197. var TextureRegion = (function () {
  198. function TextureRegion() {
  199. this.u = 0;
  200. this.v = 0;
  201. this.u2 = 0;
  202. this.v2 = 0;
  203. this.width = 0;
  204. this.height = 0;
  205. this.rotate = false;
  206. this.offsetX = 0;
  207. this.offsetY = 0;
  208. this.originalWidth = 0;
  209. this.originalHeight = 0;
  210. }
  211. return TextureRegion;
  212. }());
  213. spine.TextureRegion = TextureRegion;
  214. })(spine || (spine = {}));
  215. var spine;
  216. (function (spine) {
  217. var canvas;
  218. (function (canvas) {
  219. var CanvasTexture = (function (_super) {
  220. __extends(CanvasTexture, _super);
  221. function CanvasTexture(image) {
  222. _super.call(this, image);
  223. }
  224. CanvasTexture.prototype.setFilters = function (minFilter, magFilter) { };
  225. CanvasTexture.prototype.setWraps = function (uWrap, vWrap) { };
  226. CanvasTexture.prototype.dispose = function () { };
  227. return CanvasTexture;
  228. }(spine.Texture));
  229. canvas.CanvasTexture = CanvasTexture;
  230. })(canvas = spine.canvas || (spine.canvas = {}));
  231. })(spine || (spine = {}));
  232. var spine;
  233. (function (spine) {
  234. var canvas;
  235. (function (canvas) {
  236. var SkeletonRenderer = (function () {
  237. function SkeletonRenderer(context) {
  238. this.triangleRendering = false;
  239. this.debugRendering = false;
  240. this.vertices = spine.Utils.newFloatArray(8 * 1024);
  241. this.tempColor = new spine.Color();
  242. this.ctx = context;
  243. }
  244. SkeletonRenderer.prototype.draw = function (skeleton) {
  245. if (this.triangleRendering)
  246. this.drawTriangles(skeleton);
  247. else
  248. this.drawImages(skeleton);
  249. };
  250. SkeletonRenderer.prototype.drawImages = function (skeleton) {
  251. var ctx = this.ctx;
  252. var drawOrder = skeleton.drawOrder;
  253. if (this.debugRendering)
  254. ctx.strokeStyle = "green";
  255. ctx.save();
  256. for (var i = 0, n = drawOrder.length; i < n; i++) {
  257. var slot = drawOrder[i];
  258. var attachment = slot.getAttachment();
  259. var regionAttachment = null;
  260. var region = null;
  261. var image = null;
  262. if (attachment instanceof spine.RegionAttachment) {
  263. regionAttachment = attachment;
  264. region = regionAttachment.region;
  265. image = region.texture.getImage();
  266. }
  267. else
  268. continue;
  269. var skeleton_1 = slot.bone.skeleton;
  270. var skeletonColor = skeleton_1.color;
  271. var slotColor = slot.color;
  272. var regionColor = regionAttachment.color;
  273. var alpha = skeletonColor.a * slotColor.a * regionColor.a;
  274. var color = this.tempColor;
  275. color.set(skeletonColor.r * slotColor.r * regionColor.r, skeletonColor.g * slotColor.g * regionColor.g, skeletonColor.b * slotColor.b * regionColor.b, alpha);
  276. var att = attachment;
  277. var bone = slot.bone;
  278. var w = region.width;
  279. var h = region.height;
  280. ctx.save();
  281. ctx.transform(bone.a, bone.c, bone.b, bone.d, bone.worldX, bone.worldY);
  282. ctx.translate(attachment.offset[0], attachment.offset[1]);
  283. ctx.rotate(attachment.rotation * Math.PI / 180);
  284. ctx.scale(attachment.scaleX, attachment.scaleY);
  285. ctx.translate(w / 2, h / 2);
  286. if (attachment.region.rotate) {
  287. var t = w;
  288. w = h;
  289. h = t;
  290. ctx.rotate(-Math.PI / 2);
  291. }
  292. ctx.scale(1, -1);
  293. ctx.translate(-w / 2, -h / 2);
  294. if (color.r != 1 || color.g != 1 || color.b != 1 || color.a != 1) {
  295. ctx.globalAlpha = color.a;
  296. }
  297. ctx.drawImage(image, region.x, region.y, w, h, 0, 0, w, h);
  298. if (this.debugRendering)
  299. ctx.strokeRect(0, 0, w, h);
  300. ctx.restore();
  301. }
  302. ctx.restore();
  303. };
  304. SkeletonRenderer.prototype.drawTriangles = function (skeleton) {
  305. var blendMode = null;
  306. var vertices = this.vertices;
  307. var triangles = null;
  308. var drawOrder = skeleton.drawOrder;
  309. for (var i = 0, n = drawOrder.length; i < n; i++) {
  310. var slot = drawOrder[i];
  311. var attachment = slot.getAttachment();
  312. var texture = null;
  313. var region = null;
  314. if (attachment instanceof spine.RegionAttachment) {
  315. var regionAttachment = attachment;
  316. vertices = this.computeRegionVertices(slot, regionAttachment, false);
  317. triangles = SkeletonRenderer.QUAD_TRIANGLES;
  318. region = regionAttachment.region;
  319. texture = region.texture.getImage();
  320. }
  321. else if (attachment instanceof spine.MeshAttachment) {
  322. var mesh = attachment;
  323. vertices = this.computeMeshVertices(slot, mesh, false);
  324. triangles = mesh.triangles;
  325. texture = mesh.region.renderObject.texture.getImage();
  326. }
  327. else
  328. continue;
  329. if (texture != null) {
  330. var slotBlendMode = slot.data.blendMode;
  331. if (slotBlendMode != blendMode) {
  332. blendMode = slotBlendMode;
  333. }
  334. var ctx = this.ctx;
  335. for (var j = 0; j < triangles.length; j += 3) {
  336. var t1 = triangles[j] * 8, t2 = triangles[j + 1] * 8, t3 = triangles[j + 2] * 8;
  337. var x0 = vertices[t1], y0 = vertices[t1 + 1], u0 = vertices[t1 + 6], v0 = vertices[t1 + 7];
  338. var x1 = vertices[t2], y1 = vertices[t2 + 1], u1 = vertices[t2 + 6], v1 = vertices[t2 + 7];
  339. var x2 = vertices[t3], y2 = vertices[t3 + 1], u2 = vertices[t3 + 6], v2 = vertices[t3 + 7];
  340. this.drawTriangle(texture, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
  341. if (this.debugRendering) {
  342. ctx.strokeStyle = "green";
  343. ctx.beginPath();
  344. ctx.moveTo(x0, y0);
  345. ctx.lineTo(x1, y1);
  346. ctx.lineTo(x2, y2);
  347. ctx.lineTo(x0, y0);
  348. ctx.stroke();
  349. }
  350. }
  351. }
  352. }
  353. };
  354. SkeletonRenderer.prototype.drawTriangle = function (img, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2) {
  355. var ctx = this.ctx;
  356. u0 *= img.width;
  357. v0 *= img.height;
  358. u1 *= img.width;
  359. v1 *= img.height;
  360. u2 *= img.width;
  361. v2 *= img.height;
  362. ctx.beginPath();
  363. ctx.moveTo(x0, y0);
  364. ctx.lineTo(x1, y1);
  365. ctx.lineTo(x2, y2);
  366. ctx.closePath();
  367. x1 -= x0;
  368. y1 -= y0;
  369. x2 -= x0;
  370. y2 -= y0;
  371. u1 -= u0;
  372. v1 -= v0;
  373. u2 -= u0;
  374. v2 -= v0;
  375. var det = 1 / (u1 * v2 - u2 * v1), a = (v2 * x1 - v1 * x2) * det, b = (v2 * y1 - v1 * y2) * det, c = (u1 * x2 - u2 * x1) * det, d = (u1 * y2 - u2 * y1) * det, e = x0 - a * u0 - c * v0, f = y0 - b * u0 - d * v0;
  376. ctx.save();
  377. ctx.transform(a, b, c, d, e, f);
  378. ctx.clip();
  379. ctx.drawImage(img, 0, 0);
  380. ctx.restore();
  381. };
  382. SkeletonRenderer.prototype.computeRegionVertices = function (slot, region, pma) {
  383. var skeleton = slot.bone.skeleton;
  384. var skeletonColor = skeleton.color;
  385. var slotColor = slot.color;
  386. var regionColor = region.color;
  387. var alpha = skeletonColor.a * slotColor.a * regionColor.a;
  388. var multiplier = pma ? alpha : 1;
  389. var color = this.tempColor;
  390. color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha);
  391. region.computeWorldVertices(slot.bone, this.vertices, 0, SkeletonRenderer.VERTEX_SIZE);
  392. var vertices = this.vertices;
  393. var uvs = region.uvs;
  394. vertices[spine.RegionAttachment.C1R] = color.r;
  395. vertices[spine.RegionAttachment.C1G] = color.g;
  396. vertices[spine.RegionAttachment.C1B] = color.b;
  397. vertices[spine.RegionAttachment.C1A] = color.a;
  398. vertices[spine.RegionAttachment.U1] = uvs[0];
  399. vertices[spine.RegionAttachment.V1] = uvs[1];
  400. vertices[spine.RegionAttachment.C2R] = color.r;
  401. vertices[spine.RegionAttachment.C2G] = color.g;
  402. vertices[spine.RegionAttachment.C2B] = color.b;
  403. vertices[spine.RegionAttachment.C2A] = color.a;
  404. vertices[spine.RegionAttachment.U2] = uvs[2];
  405. vertices[spine.RegionAttachment.V2] = uvs[3];
  406. vertices[spine.RegionAttachment.C3R] = color.r;
  407. vertices[spine.RegionAttachment.C3G] = color.g;
  408. vertices[spine.RegionAttachment.C3B] = color.b;
  409. vertices[spine.RegionAttachment.C3A] = color.a;
  410. vertices[spine.RegionAttachment.U3] = uvs[4];
  411. vertices[spine.RegionAttachment.V3] = uvs[5];
  412. vertices[spine.RegionAttachment.C4R] = color.r;
  413. vertices[spine.RegionAttachment.C4G] = color.g;
  414. vertices[spine.RegionAttachment.C4B] = color.b;
  415. vertices[spine.RegionAttachment.C4A] = color.a;
  416. vertices[spine.RegionAttachment.U4] = uvs[6];
  417. vertices[spine.RegionAttachment.V4] = uvs[7];
  418. return vertices;
  419. };
  420. SkeletonRenderer.prototype.computeMeshVertices = function (slot, mesh, pma) {
  421. var skeleton = slot.bone.skeleton;
  422. var skeletonColor = skeleton.color;
  423. var slotColor = slot.color;
  424. var regionColor = mesh.color;
  425. var alpha = skeletonColor.a * slotColor.a * regionColor.a;
  426. var multiplier = pma ? alpha : 1;
  427. var color = this.tempColor;
  428. color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier, alpha);
  429. var numVertices = mesh.worldVerticesLength / 2;
  430. if (this.vertices.length < mesh.worldVerticesLength) {
  431. this.vertices = spine.Utils.newFloatArray(mesh.worldVerticesLength);
  432. }
  433. var vertices = this.vertices;
  434. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, SkeletonRenderer.VERTEX_SIZE);
  435. var uvs = mesh.uvs;
  436. for (var i = 0, n = numVertices, u = 0, v = 2; i < n; i++) {
  437. vertices[v++] = color.r;
  438. vertices[v++] = color.g;
  439. vertices[v++] = color.b;
  440. vertices[v++] = color.a;
  441. vertices[v++] = uvs[u++];
  442. vertices[v++] = uvs[u++];
  443. v += 2;
  444. }
  445. return vertices;
  446. };
  447. SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  448. SkeletonRenderer.VERTEX_SIZE = 2 + 2 + 4;
  449. return SkeletonRenderer;
  450. }());
  451. canvas.SkeletonRenderer = SkeletonRenderer;
  452. })(canvas = spine.canvas || (spine.canvas = {}));
  453. })(spine || (spine = {}));
  454. var spine;
  455. (function (spine) {
  456. var Animation = (function () {
  457. function Animation(name, timelines, duration) {
  458. if (name == null)
  459. throw new Error("name cannot be null.");
  460. if (timelines == null)
  461. throw new Error("timelines cannot be null.");
  462. this.name = name;
  463. this.timelines = timelines;
  464. this.duration = duration;
  465. }
  466. Animation.prototype.apply = function (skeleton, lastTime, time, loop, events, alpha, pose, direction) {
  467. if (skeleton == null)
  468. throw new Error("skeleton cannot be null.");
  469. if (loop && this.duration != 0) {
  470. time %= this.duration;
  471. if (lastTime > 0)
  472. lastTime %= this.duration;
  473. }
  474. var timelines = this.timelines;
  475. for (var i = 0, n = timelines.length; i < n; i++)
  476. timelines[i].apply(skeleton, lastTime, time, events, alpha, pose, direction);
  477. };
  478. Animation.binarySearch = function (values, target, step) {
  479. if (step === void 0) { step = 1; }
  480. var low = 0;
  481. var high = values.length / step - 2;
  482. if (high == 0)
  483. return step;
  484. var current = high >>> 1;
  485. while (true) {
  486. if (values[(current + 1) * step] <= target)
  487. low = current + 1;
  488. else
  489. high = current;
  490. if (low == high)
  491. return (low + 1) * step;
  492. current = (low + high) >>> 1;
  493. }
  494. };
  495. Animation.linearSearch = function (values, target, step) {
  496. for (var i = 0, last = values.length - step; i <= last; i += step)
  497. if (values[i] > target)
  498. return i;
  499. return -1;
  500. };
  501. return Animation;
  502. }());
  503. spine.Animation = Animation;
  504. (function (MixPose) {
  505. MixPose[MixPose["setup"] = 0] = "setup";
  506. MixPose[MixPose["current"] = 1] = "current";
  507. MixPose[MixPose["currentLayered"] = 2] = "currentLayered";
  508. })(spine.MixPose || (spine.MixPose = {}));
  509. var MixPose = spine.MixPose;
  510. (function (MixDirection) {
  511. MixDirection[MixDirection["in"] = 0] = "in";
  512. MixDirection[MixDirection["out"] = 1] = "out";
  513. })(spine.MixDirection || (spine.MixDirection = {}));
  514. var MixDirection = spine.MixDirection;
  515. (function (TimelineType) {
  516. TimelineType[TimelineType["rotate"] = 0] = "rotate";
  517. TimelineType[TimelineType["translate"] = 1] = "translate";
  518. TimelineType[TimelineType["scale"] = 2] = "scale";
  519. TimelineType[TimelineType["shear"] = 3] = "shear";
  520. TimelineType[TimelineType["attachment"] = 4] = "attachment";
  521. TimelineType[TimelineType["color"] = 5] = "color";
  522. TimelineType[TimelineType["deform"] = 6] = "deform";
  523. TimelineType[TimelineType["event"] = 7] = "event";
  524. TimelineType[TimelineType["drawOrder"] = 8] = "drawOrder";
  525. TimelineType[TimelineType["ikConstraint"] = 9] = "ikConstraint";
  526. TimelineType[TimelineType["transformConstraint"] = 10] = "transformConstraint";
  527. TimelineType[TimelineType["pathConstraintPosition"] = 11] = "pathConstraintPosition";
  528. TimelineType[TimelineType["pathConstraintSpacing"] = 12] = "pathConstraintSpacing";
  529. TimelineType[TimelineType["pathConstraintMix"] = 13] = "pathConstraintMix";
  530. TimelineType[TimelineType["twoColor"] = 14] = "twoColor";
  531. })(spine.TimelineType || (spine.TimelineType = {}));
  532. var TimelineType = spine.TimelineType;
  533. var CurveTimeline = (function () {
  534. function CurveTimeline(frameCount) {
  535. if (frameCount <= 0)
  536. throw new Error("frameCount must be > 0: " + frameCount);
  537. this.curves = spine.Utils.newFloatArray((frameCount - 1) * CurveTimeline.BEZIER_SIZE);
  538. }
  539. CurveTimeline.prototype.getFrameCount = function () {
  540. return this.curves.length / CurveTimeline.BEZIER_SIZE + 1;
  541. };
  542. CurveTimeline.prototype.setLinear = function (frameIndex) {
  543. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.LINEAR;
  544. };
  545. CurveTimeline.prototype.setStepped = function (frameIndex) {
  546. this.curves[frameIndex * CurveTimeline.BEZIER_SIZE] = CurveTimeline.STEPPED;
  547. };
  548. CurveTimeline.prototype.getCurveType = function (frameIndex) {
  549. var index = frameIndex * CurveTimeline.BEZIER_SIZE;
  550. if (index == this.curves.length)
  551. return CurveTimeline.LINEAR;
  552. var type = this.curves[index];
  553. if (type == CurveTimeline.LINEAR)
  554. return CurveTimeline.LINEAR;
  555. if (type == CurveTimeline.STEPPED)
  556. return CurveTimeline.STEPPED;
  557. return CurveTimeline.BEZIER;
  558. };
  559. CurveTimeline.prototype.setCurve = function (frameIndex, cx1, cy1, cx2, cy2) {
  560. var tmpx = (-cx1 * 2 + cx2) * 0.03, tmpy = (-cy1 * 2 + cy2) * 0.03;
  561. var dddfx = ((cx1 - cx2) * 3 + 1) * 0.006, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006;
  562. var ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
  563. var dfx = cx1 * 0.3 + tmpx + dddfx * 0.16666667, dfy = cy1 * 0.3 + tmpy + dddfy * 0.16666667;
  564. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  565. var curves = this.curves;
  566. curves[i++] = CurveTimeline.BEZIER;
  567. var x = dfx, y = dfy;
  568. for (var n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  569. curves[i] = x;
  570. curves[i + 1] = y;
  571. dfx += ddfx;
  572. dfy += ddfy;
  573. ddfx += dddfx;
  574. ddfy += dddfy;
  575. x += dfx;
  576. y += dfy;
  577. }
  578. };
  579. CurveTimeline.prototype.getCurvePercent = function (frameIndex, percent) {
  580. percent = spine.MathUtils.clamp(percent, 0, 1);
  581. var curves = this.curves;
  582. var i = frameIndex * CurveTimeline.BEZIER_SIZE;
  583. var type = curves[i];
  584. if (type == CurveTimeline.LINEAR)
  585. return percent;
  586. if (type == CurveTimeline.STEPPED)
  587. return 0;
  588. i++;
  589. var x = 0;
  590. for (var start = i, n = i + CurveTimeline.BEZIER_SIZE - 1; i < n; i += 2) {
  591. x = curves[i];
  592. if (x >= percent) {
  593. var prevX = void 0, prevY = void 0;
  594. if (i == start) {
  595. prevX = 0;
  596. prevY = 0;
  597. }
  598. else {
  599. prevX = curves[i - 2];
  600. prevY = curves[i - 1];
  601. }
  602. return prevY + (curves[i + 1] - prevY) * (percent - prevX) / (x - prevX);
  603. }
  604. }
  605. var y = curves[i - 1];
  606. return y + (1 - y) * (percent - x) / (1 - x);
  607. };
  608. CurveTimeline.LINEAR = 0;
  609. CurveTimeline.STEPPED = 1;
  610. CurveTimeline.BEZIER = 2;
  611. CurveTimeline.BEZIER_SIZE = 10 * 2 - 1;
  612. return CurveTimeline;
  613. }());
  614. spine.CurveTimeline = CurveTimeline;
  615. var RotateTimeline = (function (_super) {
  616. __extends(RotateTimeline, _super);
  617. function RotateTimeline(frameCount) {
  618. _super.call(this, frameCount);
  619. this.frames = spine.Utils.newFloatArray(frameCount << 1);
  620. }
  621. RotateTimeline.prototype.getPropertyId = function () {
  622. return (TimelineType.rotate << 24) + this.boneIndex;
  623. };
  624. RotateTimeline.prototype.setFrame = function (frameIndex, time, degrees) {
  625. frameIndex <<= 1;
  626. this.frames[frameIndex] = time;
  627. this.frames[frameIndex + RotateTimeline.ROTATION] = degrees;
  628. };
  629. RotateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  630. var frames = this.frames;
  631. var bone = skeleton.bones[this.boneIndex];
  632. if (time < frames[0]) {
  633. switch (pose) {
  634. case MixPose.setup:
  635. bone.rotation = bone.data.rotation;
  636. return;
  637. case MixPose.current:
  638. var r_1 = bone.data.rotation - bone.rotation;
  639. r_1 -= (16384 - ((16384.499999999996 - r_1 / 360) | 0)) * 360;
  640. bone.rotation += r_1 * alpha;
  641. }
  642. return;
  643. }
  644. if (time >= frames[frames.length - RotateTimeline.ENTRIES]) {
  645. if (pose == MixPose.setup)
  646. bone.rotation = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] * alpha;
  647. else {
  648. var r_2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION] - bone.rotation;
  649. r_2 -= (16384 - ((16384.499999999996 - r_2 / 360) | 0)) * 360;
  650. bone.rotation += r_2 * alpha;
  651. }
  652. return;
  653. }
  654. var frame = Animation.binarySearch(frames, time, RotateTimeline.ENTRIES);
  655. var prevRotation = frames[frame + RotateTimeline.PREV_ROTATION];
  656. var frameTime = frames[frame];
  657. var percent = this.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime));
  658. var r = frames[frame + RotateTimeline.ROTATION] - prevRotation;
  659. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  660. r = prevRotation + r * percent;
  661. if (pose == MixPose.setup) {
  662. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  663. bone.rotation = bone.data.rotation + r * alpha;
  664. }
  665. else {
  666. r = bone.data.rotation + r - bone.rotation;
  667. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  668. bone.rotation += r * alpha;
  669. }
  670. };
  671. RotateTimeline.ENTRIES = 2;
  672. RotateTimeline.PREV_TIME = -2;
  673. RotateTimeline.PREV_ROTATION = -1;
  674. RotateTimeline.ROTATION = 1;
  675. return RotateTimeline;
  676. }(CurveTimeline));
  677. spine.RotateTimeline = RotateTimeline;
  678. var TranslateTimeline = (function (_super) {
  679. __extends(TranslateTimeline, _super);
  680. function TranslateTimeline(frameCount) {
  681. _super.call(this, frameCount);
  682. this.frames = spine.Utils.newFloatArray(frameCount * TranslateTimeline.ENTRIES);
  683. }
  684. TranslateTimeline.prototype.getPropertyId = function () {
  685. return (TimelineType.translate << 24) + this.boneIndex;
  686. };
  687. TranslateTimeline.prototype.setFrame = function (frameIndex, time, x, y) {
  688. frameIndex *= TranslateTimeline.ENTRIES;
  689. this.frames[frameIndex] = time;
  690. this.frames[frameIndex + TranslateTimeline.X] = x;
  691. this.frames[frameIndex + TranslateTimeline.Y] = y;
  692. };
  693. TranslateTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  694. var frames = this.frames;
  695. var bone = skeleton.bones[this.boneIndex];
  696. if (time < frames[0]) {
  697. switch (pose) {
  698. case MixPose.setup:
  699. bone.x = bone.data.x;
  700. bone.y = bone.data.y;
  701. return;
  702. case MixPose.current:
  703. bone.x += (bone.data.x - bone.x) * alpha;
  704. bone.y += (bone.data.y - bone.y) * alpha;
  705. }
  706. return;
  707. }
  708. var x = 0, y = 0;
  709. if (time >= frames[frames.length - TranslateTimeline.ENTRIES]) {
  710. x = frames[frames.length + TranslateTimeline.PREV_X];
  711. y = frames[frames.length + TranslateTimeline.PREV_Y];
  712. }
  713. else {
  714. var frame = Animation.binarySearch(frames, time, TranslateTimeline.ENTRIES);
  715. x = frames[frame + TranslateTimeline.PREV_X];
  716. y = frames[frame + TranslateTimeline.PREV_Y];
  717. var frameTime = frames[frame];
  718. var percent = this.getCurvePercent(frame / TranslateTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TranslateTimeline.PREV_TIME] - frameTime));
  719. x += (frames[frame + TranslateTimeline.X] - x) * percent;
  720. y += (frames[frame + TranslateTimeline.Y] - y) * percent;
  721. }
  722. if (pose == MixPose.setup) {
  723. bone.x = bone.data.x + x * alpha;
  724. bone.y = bone.data.y + y * alpha;
  725. }
  726. else {
  727. bone.x += (bone.data.x + x - bone.x) * alpha;
  728. bone.y += (bone.data.y + y - bone.y) * alpha;
  729. }
  730. };
  731. TranslateTimeline.ENTRIES = 3;
  732. TranslateTimeline.PREV_TIME = -3;
  733. TranslateTimeline.PREV_X = -2;
  734. TranslateTimeline.PREV_Y = -1;
  735. TranslateTimeline.X = 1;
  736. TranslateTimeline.Y = 2;
  737. return TranslateTimeline;
  738. }(CurveTimeline));
  739. spine.TranslateTimeline = TranslateTimeline;
  740. var ScaleTimeline = (function (_super) {
  741. __extends(ScaleTimeline, _super);
  742. function ScaleTimeline(frameCount) {
  743. _super.call(this, frameCount);
  744. }
  745. ScaleTimeline.prototype.getPropertyId = function () {
  746. return (TimelineType.scale << 24) + this.boneIndex;
  747. };
  748. ScaleTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  749. var frames = this.frames;
  750. var bone = skeleton.bones[this.boneIndex];
  751. if (time < frames[0]) {
  752. switch (pose) {
  753. case MixPose.setup:
  754. bone.scaleX = bone.data.scaleX;
  755. bone.scaleY = bone.data.scaleY;
  756. return;
  757. case MixPose.current:
  758. bone.scaleX += (bone.data.scaleX - bone.scaleX) * alpha;
  759. bone.scaleY += (bone.data.scaleY - bone.scaleY) * alpha;
  760. }
  761. return;
  762. }
  763. var x = 0, y = 0;
  764. if (time >= frames[frames.length - ScaleTimeline.ENTRIES]) {
  765. x = frames[frames.length + ScaleTimeline.PREV_X] * bone.data.scaleX;
  766. y = frames[frames.length + ScaleTimeline.PREV_Y] * bone.data.scaleY;
  767. }
  768. else {
  769. var frame = Animation.binarySearch(frames, time, ScaleTimeline.ENTRIES);
  770. x = frames[frame + ScaleTimeline.PREV_X];
  771. y = frames[frame + ScaleTimeline.PREV_Y];
  772. var frameTime = frames[frame];
  773. var percent = this.getCurvePercent(frame / ScaleTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ScaleTimeline.PREV_TIME] - frameTime));
  774. x = (x + (frames[frame + ScaleTimeline.X] - x) * percent) * bone.data.scaleX;
  775. y = (y + (frames[frame + ScaleTimeline.Y] - y) * percent) * bone.data.scaleY;
  776. }
  777. if (alpha == 1) {
  778. bone.scaleX = x;
  779. bone.scaleY = y;
  780. }
  781. else {
  782. var bx = 0, by = 0;
  783. if (pose == MixPose.setup) {
  784. bx = bone.data.scaleX;
  785. by = bone.data.scaleY;
  786. }
  787. else {
  788. bx = bone.scaleX;
  789. by = bone.scaleY;
  790. }
  791. if (direction == MixDirection.out) {
  792. x = Math.abs(x) * spine.MathUtils.signum(bx);
  793. y = Math.abs(y) * spine.MathUtils.signum(by);
  794. }
  795. else {
  796. bx = Math.abs(bx) * spine.MathUtils.signum(x);
  797. by = Math.abs(by) * spine.MathUtils.signum(y);
  798. }
  799. bone.scaleX = bx + (x - bx) * alpha;
  800. bone.scaleY = by + (y - by) * alpha;
  801. }
  802. };
  803. return ScaleTimeline;
  804. }(TranslateTimeline));
  805. spine.ScaleTimeline = ScaleTimeline;
  806. var ShearTimeline = (function (_super) {
  807. __extends(ShearTimeline, _super);
  808. function ShearTimeline(frameCount) {
  809. _super.call(this, frameCount);
  810. }
  811. ShearTimeline.prototype.getPropertyId = function () {
  812. return (TimelineType.shear << 24) + this.boneIndex;
  813. };
  814. ShearTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  815. var frames = this.frames;
  816. var bone = skeleton.bones[this.boneIndex];
  817. if (time < frames[0]) {
  818. switch (pose) {
  819. case MixPose.setup:
  820. bone.shearX = bone.data.shearX;
  821. bone.shearY = bone.data.shearY;
  822. return;
  823. case MixPose.current:
  824. bone.shearX += (bone.data.shearX - bone.shearX) * alpha;
  825. bone.shearY += (bone.data.shearY - bone.shearY) * alpha;
  826. }
  827. return;
  828. }
  829. var x = 0, y = 0;
  830. if (time >= frames[frames.length - ShearTimeline.ENTRIES]) {
  831. x = frames[frames.length + ShearTimeline.PREV_X];
  832. y = frames[frames.length + ShearTimeline.PREV_Y];
  833. }
  834. else {
  835. var frame = Animation.binarySearch(frames, time, ShearTimeline.ENTRIES);
  836. x = frames[frame + ShearTimeline.PREV_X];
  837. y = frames[frame + ShearTimeline.PREV_Y];
  838. var frameTime = frames[frame];
  839. var percent = this.getCurvePercent(frame / ShearTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ShearTimeline.PREV_TIME] - frameTime));
  840. x = x + (frames[frame + ShearTimeline.X] - x) * percent;
  841. y = y + (frames[frame + ShearTimeline.Y] - y) * percent;
  842. }
  843. if (pose == MixPose.setup) {
  844. bone.shearX = bone.data.shearX + x * alpha;
  845. bone.shearY = bone.data.shearY + y * alpha;
  846. }
  847. else {
  848. bone.shearX += (bone.data.shearX + x - bone.shearX) * alpha;
  849. bone.shearY += (bone.data.shearY + y - bone.shearY) * alpha;
  850. }
  851. };
  852. return ShearTimeline;
  853. }(TranslateTimeline));
  854. spine.ShearTimeline = ShearTimeline;
  855. var ColorTimeline = (function (_super) {
  856. __extends(ColorTimeline, _super);
  857. function ColorTimeline(frameCount) {
  858. _super.call(this, frameCount);
  859. this.frames = spine.Utils.newFloatArray(frameCount * ColorTimeline.ENTRIES);
  860. }
  861. ColorTimeline.prototype.getPropertyId = function () {
  862. return (TimelineType.color << 24) + this.slotIndex;
  863. };
  864. ColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a) {
  865. frameIndex *= ColorTimeline.ENTRIES;
  866. this.frames[frameIndex] = time;
  867. this.frames[frameIndex + ColorTimeline.R] = r;
  868. this.frames[frameIndex + ColorTimeline.G] = g;
  869. this.frames[frameIndex + ColorTimeline.B] = b;
  870. this.frames[frameIndex + ColorTimeline.A] = a;
  871. };
  872. ColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  873. var slot = skeleton.slots[this.slotIndex];
  874. var frames = this.frames;
  875. if (time < frames[0]) {
  876. switch (pose) {
  877. case MixPose.setup:
  878. slot.color.setFromColor(slot.data.color);
  879. return;
  880. case MixPose.current:
  881. var color = slot.color, setup = slot.data.color;
  882. color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, (setup.a - color.a) * alpha);
  883. }
  884. return;
  885. }
  886. var r = 0, g = 0, b = 0, a = 0;
  887. if (time >= frames[frames.length - ColorTimeline.ENTRIES]) {
  888. var i = frames.length;
  889. r = frames[i + ColorTimeline.PREV_R];
  890. g = frames[i + ColorTimeline.PREV_G];
  891. b = frames[i + ColorTimeline.PREV_B];
  892. a = frames[i + ColorTimeline.PREV_A];
  893. }
  894. else {
  895. var frame = Animation.binarySearch(frames, time, ColorTimeline.ENTRIES);
  896. r = frames[frame + ColorTimeline.PREV_R];
  897. g = frames[frame + ColorTimeline.PREV_G];
  898. b = frames[frame + ColorTimeline.PREV_B];
  899. a = frames[frame + ColorTimeline.PREV_A];
  900. var frameTime = frames[frame];
  901. var percent = this.getCurvePercent(frame / ColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + ColorTimeline.PREV_TIME] - frameTime));
  902. r += (frames[frame + ColorTimeline.R] - r) * percent;
  903. g += (frames[frame + ColorTimeline.G] - g) * percent;
  904. b += (frames[frame + ColorTimeline.B] - b) * percent;
  905. a += (frames[frame + ColorTimeline.A] - a) * percent;
  906. }
  907. if (alpha == 1)
  908. slot.color.set(r, g, b, a);
  909. else {
  910. var color = slot.color;
  911. if (pose == MixPose.setup)
  912. color.setFromColor(slot.data.color);
  913. color.add((r - color.r) * alpha, (g - color.g) * alpha, (b - color.b) * alpha, (a - color.a) * alpha);
  914. }
  915. };
  916. ColorTimeline.ENTRIES = 5;
  917. ColorTimeline.PREV_TIME = -5;
  918. ColorTimeline.PREV_R = -4;
  919. ColorTimeline.PREV_G = -3;
  920. ColorTimeline.PREV_B = -2;
  921. ColorTimeline.PREV_A = -1;
  922. ColorTimeline.R = 1;
  923. ColorTimeline.G = 2;
  924. ColorTimeline.B = 3;
  925. ColorTimeline.A = 4;
  926. return ColorTimeline;
  927. }(CurveTimeline));
  928. spine.ColorTimeline = ColorTimeline;
  929. var TwoColorTimeline = (function (_super) {
  930. __extends(TwoColorTimeline, _super);
  931. function TwoColorTimeline(frameCount) {
  932. _super.call(this, frameCount);
  933. this.frames = spine.Utils.newFloatArray(frameCount * TwoColorTimeline.ENTRIES);
  934. }
  935. TwoColorTimeline.prototype.getPropertyId = function () {
  936. return (TimelineType.twoColor << 24) + this.slotIndex;
  937. };
  938. TwoColorTimeline.prototype.setFrame = function (frameIndex, time, r, g, b, a, r2, g2, b2) {
  939. frameIndex *= TwoColorTimeline.ENTRIES;
  940. this.frames[frameIndex] = time;
  941. this.frames[frameIndex + TwoColorTimeline.R] = r;
  942. this.frames[frameIndex + TwoColorTimeline.G] = g;
  943. this.frames[frameIndex + TwoColorTimeline.B] = b;
  944. this.frames[frameIndex + TwoColorTimeline.A] = a;
  945. this.frames[frameIndex + TwoColorTimeline.R2] = r2;
  946. this.frames[frameIndex + TwoColorTimeline.G2] = g2;
  947. this.frames[frameIndex + TwoColorTimeline.B2] = b2;
  948. };
  949. TwoColorTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  950. var slot = skeleton.slots[this.slotIndex];
  951. var frames = this.frames;
  952. if (time < frames[0]) {
  953. switch (pose) {
  954. case MixPose.setup:
  955. slot.color.setFromColor(slot.data.color);
  956. slot.darkColor.setFromColor(slot.data.darkColor);
  957. return;
  958. case MixPose.current:
  959. var light = slot.color, dark = slot.darkColor, setupLight = slot.data.color, setupDark = slot.data.darkColor;
  960. light.add((setupLight.r - light.r) * alpha, (setupLight.g - light.g) * alpha, (setupLight.b - light.b) * alpha, (setupLight.a - light.a) * alpha);
  961. dark.add((setupDark.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha, (setupDark.b - dark.b) * alpha, 0);
  962. }
  963. return;
  964. }
  965. var r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0;
  966. if (time >= frames[frames.length - TwoColorTimeline.ENTRIES]) {
  967. var i = frames.length;
  968. r = frames[i + TwoColorTimeline.PREV_R];
  969. g = frames[i + TwoColorTimeline.PREV_G];
  970. b = frames[i + TwoColorTimeline.PREV_B];
  971. a = frames[i + TwoColorTimeline.PREV_A];
  972. r2 = frames[i + TwoColorTimeline.PREV_R2];
  973. g2 = frames[i + TwoColorTimeline.PREV_G2];
  974. b2 = frames[i + TwoColorTimeline.PREV_B2];
  975. }
  976. else {
  977. var frame = Animation.binarySearch(frames, time, TwoColorTimeline.ENTRIES);
  978. r = frames[frame + TwoColorTimeline.PREV_R];
  979. g = frames[frame + TwoColorTimeline.PREV_G];
  980. b = frames[frame + TwoColorTimeline.PREV_B];
  981. a = frames[frame + TwoColorTimeline.PREV_A];
  982. r2 = frames[frame + TwoColorTimeline.PREV_R2];
  983. g2 = frames[frame + TwoColorTimeline.PREV_G2];
  984. b2 = frames[frame + TwoColorTimeline.PREV_B2];
  985. var frameTime = frames[frame];
  986. var percent = this.getCurvePercent(frame / TwoColorTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TwoColorTimeline.PREV_TIME] - frameTime));
  987. r += (frames[frame + TwoColorTimeline.R] - r) * percent;
  988. g += (frames[frame + TwoColorTimeline.G] - g) * percent;
  989. b += (frames[frame + TwoColorTimeline.B] - b) * percent;
  990. a += (frames[frame + TwoColorTimeline.A] - a) * percent;
  991. r2 += (frames[frame + TwoColorTimeline.R2] - r2) * percent;
  992. g2 += (frames[frame + TwoColorTimeline.G2] - g2) * percent;
  993. b2 += (frames[frame + TwoColorTimeline.B2] - b2) * percent;
  994. }
  995. if (alpha == 1) {
  996. slot.color.set(r, g, b, a);
  997. slot.darkColor.set(r2, g2, b2, 1);
  998. }
  999. else {
  1000. var light = slot.color, dark = slot.darkColor;
  1001. if (pose == MixPose.setup) {
  1002. light.setFromColor(slot.data.color);
  1003. dark.setFromColor(slot.data.darkColor);
  1004. }
  1005. light.add((r - light.r) * alpha, (g - light.g) * alpha, (b - light.b) * alpha, (a - light.a) * alpha);
  1006. dark.add((r2 - dark.r) * alpha, (g2 - dark.g) * alpha, (b2 - dark.b) * alpha, 0);
  1007. }
  1008. };
  1009. TwoColorTimeline.ENTRIES = 8;
  1010. TwoColorTimeline.PREV_TIME = -8;
  1011. TwoColorTimeline.PREV_R = -7;
  1012. TwoColorTimeline.PREV_G = -6;
  1013. TwoColorTimeline.PREV_B = -5;
  1014. TwoColorTimeline.PREV_A = -4;
  1015. TwoColorTimeline.PREV_R2 = -3;
  1016. TwoColorTimeline.PREV_G2 = -2;
  1017. TwoColorTimeline.PREV_B2 = -1;
  1018. TwoColorTimeline.R = 1;
  1019. TwoColorTimeline.G = 2;
  1020. TwoColorTimeline.B = 3;
  1021. TwoColorTimeline.A = 4;
  1022. TwoColorTimeline.R2 = 5;
  1023. TwoColorTimeline.G2 = 6;
  1024. TwoColorTimeline.B2 = 7;
  1025. return TwoColorTimeline;
  1026. }(CurveTimeline));
  1027. spine.TwoColorTimeline = TwoColorTimeline;
  1028. var AttachmentTimeline = (function () {
  1029. function AttachmentTimeline(frameCount) {
  1030. this.frames = spine.Utils.newFloatArray(frameCount);
  1031. this.attachmentNames = new Array(frameCount);
  1032. }
  1033. AttachmentTimeline.prototype.getPropertyId = function () {
  1034. return (TimelineType.attachment << 24) + this.slotIndex;
  1035. };
  1036. AttachmentTimeline.prototype.getFrameCount = function () {
  1037. return this.frames.length;
  1038. };
  1039. AttachmentTimeline.prototype.setFrame = function (frameIndex, time, attachmentName) {
  1040. this.frames[frameIndex] = time;
  1041. this.attachmentNames[frameIndex] = attachmentName;
  1042. };
  1043. AttachmentTimeline.prototype.apply = function (skeleton, lastTime, time, events, alpha, pose, direction) {
  1044. var slot = skeleton.slots[this.slotIndex];
  1045. if (direction == MixDirection.out && pose == MixPose.setup) {
  1046. var attachmentName_1 = slot.data.attachmentName;
  1047. slot.setAttachment(attachmentName_1 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_1));
  1048. return;
  1049. }
  1050. var frames = this.frames;
  1051. if (time < frames[0]) {
  1052. if (pose == MixPose.setup) {
  1053. var attachmentName_2 = slot.data.attachmentName;
  1054. slot.setAttachment(attachmentName_2 == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName_2));
  1055. }
  1056. return;
  1057. }
  1058. var frameIndex = 0;
  1059. if (time >= frames[frames.length - 1])
  1060. frameIndex = frames.length - 1;
  1061. else
  1062. frameIndex = Animation.binarySearch(frames, time, 1) - 1;
  1063. var attachmentName = this.attachmentNames[frameIndex];
  1064. skeleton.slots[this.slotIndex]
  1065. .setAttachment(attachmentName == null ? null : skeleton.getAttachment(this.slotIndex, attachmentName));
  1066. };
  1067. return AttachmentTimeline;
  1068. }());
  1069. spine.AttachmentTimeline = AttachmentTimeline;
  1070. var DeformTimeline = (function (_super) {
  1071. __extends(DeformTimeline, _super);
  1072. function DeformTimeline(frameCount) {
  1073. _super.call(this, frameCount);
  1074. this.frames = spine.Utils.newFloatArray(frameCount);
  1075. this.frameVertices = new Array(frameCount);
  1076. }
  1077. DeformTimeline.prototype.getPropertyId = function () {
  1078. return (TimelineType.deform << 27) + +this.attachment.id + this.slotIndex;
  1079. };
  1080. DeformTimeline.prototype.setFrame = function (frameIndex, time, vertices) {
  1081. this.frames[frameIndex] = time;
  1082. this.frameVertices[frameIndex] = vertices;
  1083. };
  1084. DeformTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1085. var slot = skeleton.slots[this.slotIndex];
  1086. var slotAttachment = slot.getAttachment();
  1087. if (!(slotAttachment instanceof spine.VertexAttachment) || !slotAttachment.applyDeform(this.attachment))
  1088. return;
  1089. var verticesArray = slot.attachmentVertices;
  1090. var frameVertices = this.frameVertices;
  1091. var vertexCount = frameVertices[0].length;
  1092. if (verticesArray.length != vertexCount && pose != MixPose.setup)
  1093. alpha = 1;
  1094. var vertices = spine.Utils.setArraySize(verticesArray, vertexCount);
  1095. var frames = this.frames;
  1096. if (time < frames[0]) {
  1097. switch (pose) {
  1098. case MixPose.setup:
  1099. verticesArray.length = 0;
  1100. return;
  1101. case MixPose.current:
  1102. alpha = 1 - alpha;
  1103. for (var i = 0; i < vertexCount; i++)
  1104. vertices[i] *= alpha;
  1105. }
  1106. return;
  1107. }
  1108. if (time >= frames[frames.length - 1]) {
  1109. var lastVertices = frameVertices[frames.length - 1];
  1110. if (alpha == 1) {
  1111. spine.Utils.arrayCopy(lastVertices, 0, vertices, 0, vertexCount);
  1112. }
  1113. else if (pose == MixPose.setup) {
  1114. var vertexAttachment = slotAttachment;
  1115. if (vertexAttachment.bones == null) {
  1116. var setupVertices = vertexAttachment.vertices;
  1117. for (var i = 0; i < vertexCount; i++) {
  1118. var setup = setupVertices[i];
  1119. vertices[i] = setup + (lastVertices[i] - setup) * alpha;
  1120. }
  1121. }
  1122. else {
  1123. for (var i = 0; i < vertexCount; i++)
  1124. vertices[i] = lastVertices[i] * alpha;
  1125. }
  1126. }
  1127. else {
  1128. for (var i = 0; i < vertexCount; i++)
  1129. vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
  1130. }
  1131. return;
  1132. }
  1133. var frame = Animation.binarySearch(frames, time);
  1134. var prevVertices = frameVertices[frame - 1];
  1135. var nextVertices = frameVertices[frame];
  1136. var frameTime = frames[frame];
  1137. var percent = this.getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime));
  1138. if (alpha == 1) {
  1139. for (var i = 0; i < vertexCount; i++) {
  1140. var prev = prevVertices[i];
  1141. vertices[i] = prev + (nextVertices[i] - prev) * percent;
  1142. }
  1143. }
  1144. else if (pose == MixPose.setup) {
  1145. var vertexAttachment = slotAttachment;
  1146. if (vertexAttachment.bones == null) {
  1147. var setupVertices = vertexAttachment.vertices;
  1148. for (var i = 0; i < vertexCount; i++) {
  1149. var prev = prevVertices[i], setup = setupVertices[i];
  1150. vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
  1151. }
  1152. }
  1153. else {
  1154. for (var i = 0; i < vertexCount; i++) {
  1155. var prev = prevVertices[i];
  1156. vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
  1157. }
  1158. }
  1159. }
  1160. else {
  1161. for (var i = 0; i < vertexCount; i++) {
  1162. var prev = prevVertices[i];
  1163. vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
  1164. }
  1165. }
  1166. };
  1167. return DeformTimeline;
  1168. }(CurveTimeline));
  1169. spine.DeformTimeline = DeformTimeline;
  1170. var EventTimeline = (function () {
  1171. function EventTimeline(frameCount) {
  1172. this.frames = spine.Utils.newFloatArray(frameCount);
  1173. this.events = new Array(frameCount);
  1174. }
  1175. EventTimeline.prototype.getPropertyId = function () {
  1176. return TimelineType.event << 24;
  1177. };
  1178. EventTimeline.prototype.getFrameCount = function () {
  1179. return this.frames.length;
  1180. };
  1181. EventTimeline.prototype.setFrame = function (frameIndex, event) {
  1182. this.frames[frameIndex] = event.time;
  1183. this.events[frameIndex] = event;
  1184. };
  1185. EventTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1186. if (firedEvents == null)
  1187. return;
  1188. var frames = this.frames;
  1189. var frameCount = this.frames.length;
  1190. if (lastTime > time) {
  1191. this.apply(skeleton, lastTime, Number.MAX_VALUE, firedEvents, alpha, pose, direction);
  1192. lastTime = -1;
  1193. }
  1194. else if (lastTime >= frames[frameCount - 1])
  1195. return;
  1196. if (time < frames[0])
  1197. return;
  1198. var frame = 0;
  1199. if (lastTime < frames[0])
  1200. frame = 0;
  1201. else {
  1202. frame = Animation.binarySearch(frames, lastTime);
  1203. var frameTime = frames[frame];
  1204. while (frame > 0) {
  1205. if (frames[frame - 1] != frameTime)
  1206. break;
  1207. frame--;
  1208. }
  1209. }
  1210. for (; frame < frameCount && time >= frames[frame]; frame++)
  1211. firedEvents.push(this.events[frame]);
  1212. };
  1213. return EventTimeline;
  1214. }());
  1215. spine.EventTimeline = EventTimeline;
  1216. var DrawOrderTimeline = (function () {
  1217. function DrawOrderTimeline(frameCount) {
  1218. this.frames = spine.Utils.newFloatArray(frameCount);
  1219. this.drawOrders = new Array(frameCount);
  1220. }
  1221. DrawOrderTimeline.prototype.getPropertyId = function () {
  1222. return TimelineType.drawOrder << 24;
  1223. };
  1224. DrawOrderTimeline.prototype.getFrameCount = function () {
  1225. return this.frames.length;
  1226. };
  1227. DrawOrderTimeline.prototype.setFrame = function (frameIndex, time, drawOrder) {
  1228. this.frames[frameIndex] = time;
  1229. this.drawOrders[frameIndex] = drawOrder;
  1230. };
  1231. DrawOrderTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1232. var drawOrder = skeleton.drawOrder;
  1233. var slots = skeleton.slots;
  1234. if (direction == MixDirection.out && pose == MixPose.setup) {
  1235. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  1236. return;
  1237. }
  1238. var frames = this.frames;
  1239. if (time < frames[0]) {
  1240. if (pose == MixPose.setup)
  1241. spine.Utils.arrayCopy(skeleton.slots, 0, skeleton.drawOrder, 0, skeleton.slots.length);
  1242. return;
  1243. }
  1244. var frame = 0;
  1245. if (time >= frames[frames.length - 1])
  1246. frame = frames.length - 1;
  1247. else
  1248. frame = Animation.binarySearch(frames, time) - 1;
  1249. var drawOrderToSetupIndex = this.drawOrders[frame];
  1250. if (drawOrderToSetupIndex == null)
  1251. spine.Utils.arrayCopy(slots, 0, drawOrder, 0, slots.length);
  1252. else {
  1253. for (var i = 0, n = drawOrderToSetupIndex.length; i < n; i++)
  1254. drawOrder[i] = slots[drawOrderToSetupIndex[i]];
  1255. }
  1256. };
  1257. return DrawOrderTimeline;
  1258. }());
  1259. spine.DrawOrderTimeline = DrawOrderTimeline;
  1260. var IkConstraintTimeline = (function (_super) {
  1261. __extends(IkConstraintTimeline, _super);
  1262. function IkConstraintTimeline(frameCount) {
  1263. _super.call(this, frameCount);
  1264. this.frames = spine.Utils.newFloatArray(frameCount * IkConstraintTimeline.ENTRIES);
  1265. }
  1266. IkConstraintTimeline.prototype.getPropertyId = function () {
  1267. return (TimelineType.ikConstraint << 24) + this.ikConstraintIndex;
  1268. };
  1269. IkConstraintTimeline.prototype.setFrame = function (frameIndex, time, mix, bendDirection) {
  1270. frameIndex *= IkConstraintTimeline.ENTRIES;
  1271. this.frames[frameIndex] = time;
  1272. this.frames[frameIndex + IkConstraintTimeline.MIX] = mix;
  1273. this.frames[frameIndex + IkConstraintTimeline.BEND_DIRECTION] = bendDirection;
  1274. };
  1275. IkConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1276. var frames = this.frames;
  1277. var constraint = skeleton.ikConstraints[this.ikConstraintIndex];
  1278. if (time < frames[0]) {
  1279. switch (pose) {
  1280. case MixPose.setup:
  1281. constraint.mix = constraint.data.mix;
  1282. constraint.bendDirection = constraint.data.bendDirection;
  1283. return;
  1284. case MixPose.current:
  1285. constraint.mix += (constraint.data.mix - constraint.mix) * alpha;
  1286. constraint.bendDirection = constraint.data.bendDirection;
  1287. }
  1288. return;
  1289. }
  1290. if (time >= frames[frames.length - IkConstraintTimeline.ENTRIES]) {
  1291. if (pose == MixPose.setup) {
  1292. constraint.mix = constraint.data.mix + (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.data.mix) * alpha;
  1293. constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection
  1294. : frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1295. }
  1296. else {
  1297. constraint.mix += (frames[frames.length + IkConstraintTimeline.PREV_MIX] - constraint.mix) * alpha;
  1298. if (direction == MixDirection.in)
  1299. constraint.bendDirection = frames[frames.length + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1300. }
  1301. return;
  1302. }
  1303. var frame = Animation.binarySearch(frames, time, IkConstraintTimeline.ENTRIES);
  1304. var mix = frames[frame + IkConstraintTimeline.PREV_MIX];
  1305. var frameTime = frames[frame];
  1306. var percent = this.getCurvePercent(frame / IkConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + IkConstraintTimeline.PREV_TIME] - frameTime));
  1307. if (pose == MixPose.setup) {
  1308. constraint.mix = constraint.data.mix + (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.data.mix) * alpha;
  1309. constraint.bendDirection = direction == MixDirection.out ? constraint.data.bendDirection : frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1310. }
  1311. else {
  1312. constraint.mix += (mix + (frames[frame + IkConstraintTimeline.MIX] - mix) * percent - constraint.mix) * alpha;
  1313. if (direction == MixDirection.in)
  1314. constraint.bendDirection = frames[frame + IkConstraintTimeline.PREV_BEND_DIRECTION];
  1315. }
  1316. };
  1317. IkConstraintTimeline.ENTRIES = 3;
  1318. IkConstraintTimeline.PREV_TIME = -3;
  1319. IkConstraintTimeline.PREV_MIX = -2;
  1320. IkConstraintTimeline.PREV_BEND_DIRECTION = -1;
  1321. IkConstraintTimeline.MIX = 1;
  1322. IkConstraintTimeline.BEND_DIRECTION = 2;
  1323. return IkConstraintTimeline;
  1324. }(CurveTimeline));
  1325. spine.IkConstraintTimeline = IkConstraintTimeline;
  1326. var TransformConstraintTimeline = (function (_super) {
  1327. __extends(TransformConstraintTimeline, _super);
  1328. function TransformConstraintTimeline(frameCount) {
  1329. _super.call(this, frameCount);
  1330. this.frames = spine.Utils.newFloatArray(frameCount * TransformConstraintTimeline.ENTRIES);
  1331. }
  1332. TransformConstraintTimeline.prototype.getPropertyId = function () {
  1333. return (TimelineType.transformConstraint << 24) + this.transformConstraintIndex;
  1334. };
  1335. TransformConstraintTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix, scaleMix, shearMix) {
  1336. frameIndex *= TransformConstraintTimeline.ENTRIES;
  1337. this.frames[frameIndex] = time;
  1338. this.frames[frameIndex + TransformConstraintTimeline.ROTATE] = rotateMix;
  1339. this.frames[frameIndex + TransformConstraintTimeline.TRANSLATE] = translateMix;
  1340. this.frames[frameIndex + TransformConstraintTimeline.SCALE] = scaleMix;
  1341. this.frames[frameIndex + TransformConstraintTimeline.SHEAR] = shearMix;
  1342. };
  1343. TransformConstraintTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1344. var frames = this.frames;
  1345. var constraint = skeleton.transformConstraints[this.transformConstraintIndex];
  1346. if (time < frames[0]) {
  1347. var data = constraint.data;
  1348. switch (pose) {
  1349. case MixPose.setup:
  1350. constraint.rotateMix = data.rotateMix;
  1351. constraint.translateMix = data.translateMix;
  1352. constraint.scaleMix = data.scaleMix;
  1353. constraint.shearMix = data.shearMix;
  1354. return;
  1355. case MixPose.current:
  1356. constraint.rotateMix += (data.rotateMix - constraint.rotateMix) * alpha;
  1357. constraint.translateMix += (data.translateMix - constraint.translateMix) * alpha;
  1358. constraint.scaleMix += (data.scaleMix - constraint.scaleMix) * alpha;
  1359. constraint.shearMix += (data.shearMix - constraint.shearMix) * alpha;
  1360. }
  1361. return;
  1362. }
  1363. var rotate = 0, translate = 0, scale = 0, shear = 0;
  1364. if (time >= frames[frames.length - TransformConstraintTimeline.ENTRIES]) {
  1365. var i = frames.length;
  1366. rotate = frames[i + TransformConstraintTimeline.PREV_ROTATE];
  1367. translate = frames[i + TransformConstraintTimeline.PREV_TRANSLATE];
  1368. scale = frames[i + TransformConstraintTimeline.PREV_SCALE];
  1369. shear = frames[i + TransformConstraintTimeline.PREV_SHEAR];
  1370. }
  1371. else {
  1372. var frame = Animation.binarySearch(frames, time, TransformConstraintTimeline.ENTRIES);
  1373. rotate = frames[frame + TransformConstraintTimeline.PREV_ROTATE];
  1374. translate = frames[frame + TransformConstraintTimeline.PREV_TRANSLATE];
  1375. scale = frames[frame + TransformConstraintTimeline.PREV_SCALE];
  1376. shear = frames[frame + TransformConstraintTimeline.PREV_SHEAR];
  1377. var frameTime = frames[frame];
  1378. var percent = this.getCurvePercent(frame / TransformConstraintTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + TransformConstraintTimeline.PREV_TIME] - frameTime));
  1379. rotate += (frames[frame + TransformConstraintTimeline.ROTATE] - rotate) * percent;
  1380. translate += (frames[frame + TransformConstraintTimeline.TRANSLATE] - translate) * percent;
  1381. scale += (frames[frame + TransformConstraintTimeline.SCALE] - scale) * percent;
  1382. shear += (frames[frame + TransformConstraintTimeline.SHEAR] - shear) * percent;
  1383. }
  1384. if (pose == MixPose.setup) {
  1385. var data = constraint.data;
  1386. constraint.rotateMix = data.rotateMix + (rotate - data.rotateMix) * alpha;
  1387. constraint.translateMix = data.translateMix + (translate - data.translateMix) * alpha;
  1388. constraint.scaleMix = data.scaleMix + (scale - data.scaleMix) * alpha;
  1389. constraint.shearMix = data.shearMix + (shear - data.shearMix) * alpha;
  1390. }
  1391. else {
  1392. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  1393. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  1394. constraint.scaleMix += (scale - constraint.scaleMix) * alpha;
  1395. constraint.shearMix += (shear - constraint.shearMix) * alpha;
  1396. }
  1397. };
  1398. TransformConstraintTimeline.ENTRIES = 5;
  1399. TransformConstraintTimeline.PREV_TIME = -5;
  1400. TransformConstraintTimeline.PREV_ROTATE = -4;
  1401. TransformConstraintTimeline.PREV_TRANSLATE = -3;
  1402. TransformConstraintTimeline.PREV_SCALE = -2;
  1403. TransformConstraintTimeline.PREV_SHEAR = -1;
  1404. TransformConstraintTimeline.ROTATE = 1;
  1405. TransformConstraintTimeline.TRANSLATE = 2;
  1406. TransformConstraintTimeline.SCALE = 3;
  1407. TransformConstraintTimeline.SHEAR = 4;
  1408. return TransformConstraintTimeline;
  1409. }(CurveTimeline));
  1410. spine.TransformConstraintTimeline = TransformConstraintTimeline;
  1411. var PathConstraintPositionTimeline = (function (_super) {
  1412. __extends(PathConstraintPositionTimeline, _super);
  1413. function PathConstraintPositionTimeline(frameCount) {
  1414. _super.call(this, frameCount);
  1415. this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintPositionTimeline.ENTRIES);
  1416. }
  1417. PathConstraintPositionTimeline.prototype.getPropertyId = function () {
  1418. return (TimelineType.pathConstraintPosition << 24) + this.pathConstraintIndex;
  1419. };
  1420. PathConstraintPositionTimeline.prototype.setFrame = function (frameIndex, time, value) {
  1421. frameIndex *= PathConstraintPositionTimeline.ENTRIES;
  1422. this.frames[frameIndex] = time;
  1423. this.frames[frameIndex + PathConstraintPositionTimeline.VALUE] = value;
  1424. };
  1425. PathConstraintPositionTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1426. var frames = this.frames;
  1427. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1428. if (time < frames[0]) {
  1429. switch (pose) {
  1430. case MixPose.setup:
  1431. constraint.position = constraint.data.position;
  1432. return;
  1433. case MixPose.current:
  1434. constraint.position += (constraint.data.position - constraint.position) * alpha;
  1435. }
  1436. return;
  1437. }
  1438. var position = 0;
  1439. if (time >= frames[frames.length - PathConstraintPositionTimeline.ENTRIES])
  1440. position = frames[frames.length + PathConstraintPositionTimeline.PREV_VALUE];
  1441. else {
  1442. var frame = Animation.binarySearch(frames, time, PathConstraintPositionTimeline.ENTRIES);
  1443. position = frames[frame + PathConstraintPositionTimeline.PREV_VALUE];
  1444. var frameTime = frames[frame];
  1445. var percent = this.getCurvePercent(frame / PathConstraintPositionTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintPositionTimeline.PREV_TIME] - frameTime));
  1446. position += (frames[frame + PathConstraintPositionTimeline.VALUE] - position) * percent;
  1447. }
  1448. if (pose == MixPose.setup)
  1449. constraint.position = constraint.data.position + (position - constraint.data.position) * alpha;
  1450. else
  1451. constraint.position += (position - constraint.position) * alpha;
  1452. };
  1453. PathConstraintPositionTimeline.ENTRIES = 2;
  1454. PathConstraintPositionTimeline.PREV_TIME = -2;
  1455. PathConstraintPositionTimeline.PREV_VALUE = -1;
  1456. PathConstraintPositionTimeline.VALUE = 1;
  1457. return PathConstraintPositionTimeline;
  1458. }(CurveTimeline));
  1459. spine.PathConstraintPositionTimeline = PathConstraintPositionTimeline;
  1460. var PathConstraintSpacingTimeline = (function (_super) {
  1461. __extends(PathConstraintSpacingTimeline, _super);
  1462. function PathConstraintSpacingTimeline(frameCount) {
  1463. _super.call(this, frameCount);
  1464. }
  1465. PathConstraintSpacingTimeline.prototype.getPropertyId = function () {
  1466. return (TimelineType.pathConstraintSpacing << 24) + this.pathConstraintIndex;
  1467. };
  1468. PathConstraintSpacingTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1469. var frames = this.frames;
  1470. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1471. if (time < frames[0]) {
  1472. switch (pose) {
  1473. case MixPose.setup:
  1474. constraint.spacing = constraint.data.spacing;
  1475. return;
  1476. case MixPose.current:
  1477. constraint.spacing += (constraint.data.spacing - constraint.spacing) * alpha;
  1478. }
  1479. return;
  1480. }
  1481. var spacing = 0;
  1482. if (time >= frames[frames.length - PathConstraintSpacingTimeline.ENTRIES])
  1483. spacing = frames[frames.length + PathConstraintSpacingTimeline.PREV_VALUE];
  1484. else {
  1485. var frame = Animation.binarySearch(frames, time, PathConstraintSpacingTimeline.ENTRIES);
  1486. spacing = frames[frame + PathConstraintSpacingTimeline.PREV_VALUE];
  1487. var frameTime = frames[frame];
  1488. var percent = this.getCurvePercent(frame / PathConstraintSpacingTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintSpacingTimeline.PREV_TIME] - frameTime));
  1489. spacing += (frames[frame + PathConstraintSpacingTimeline.VALUE] - spacing) * percent;
  1490. }
  1491. if (pose == MixPose.setup)
  1492. constraint.spacing = constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
  1493. else
  1494. constraint.spacing += (spacing - constraint.spacing) * alpha;
  1495. };
  1496. return PathConstraintSpacingTimeline;
  1497. }(PathConstraintPositionTimeline));
  1498. spine.PathConstraintSpacingTimeline = PathConstraintSpacingTimeline;
  1499. var PathConstraintMixTimeline = (function (_super) {
  1500. __extends(PathConstraintMixTimeline, _super);
  1501. function PathConstraintMixTimeline(frameCount) {
  1502. _super.call(this, frameCount);
  1503. this.frames = spine.Utils.newFloatArray(frameCount * PathConstraintMixTimeline.ENTRIES);
  1504. }
  1505. PathConstraintMixTimeline.prototype.getPropertyId = function () {
  1506. return (TimelineType.pathConstraintMix << 24) + this.pathConstraintIndex;
  1507. };
  1508. PathConstraintMixTimeline.prototype.setFrame = function (frameIndex, time, rotateMix, translateMix) {
  1509. frameIndex *= PathConstraintMixTimeline.ENTRIES;
  1510. this.frames[frameIndex] = time;
  1511. this.frames[frameIndex + PathConstraintMixTimeline.ROTATE] = rotateMix;
  1512. this.frames[frameIndex + PathConstraintMixTimeline.TRANSLATE] = translateMix;
  1513. };
  1514. PathConstraintMixTimeline.prototype.apply = function (skeleton, lastTime, time, firedEvents, alpha, pose, direction) {
  1515. var frames = this.frames;
  1516. var constraint = skeleton.pathConstraints[this.pathConstraintIndex];
  1517. if (time < frames[0]) {
  1518. switch (pose) {
  1519. case MixPose.setup:
  1520. constraint.rotateMix = constraint.data.rotateMix;
  1521. constraint.translateMix = constraint.data.translateMix;
  1522. return;
  1523. case MixPose.current:
  1524. constraint.rotateMix += (constraint.data.rotateMix - constraint.rotateMix) * alpha;
  1525. constraint.translateMix += (constraint.data.translateMix - constraint.translateMix) * alpha;
  1526. }
  1527. return;
  1528. }
  1529. var rotate = 0, translate = 0;
  1530. if (time >= frames[frames.length - PathConstraintMixTimeline.ENTRIES]) {
  1531. rotate = frames[frames.length + PathConstraintMixTimeline.PREV_ROTATE];
  1532. translate = frames[frames.length + PathConstraintMixTimeline.PREV_TRANSLATE];
  1533. }
  1534. else {
  1535. var frame = Animation.binarySearch(frames, time, PathConstraintMixTimeline.ENTRIES);
  1536. rotate = frames[frame + PathConstraintMixTimeline.PREV_ROTATE];
  1537. translate = frames[frame + PathConstraintMixTimeline.PREV_TRANSLATE];
  1538. var frameTime = frames[frame];
  1539. var percent = this.getCurvePercent(frame / PathConstraintMixTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PathConstraintMixTimeline.PREV_TIME] - frameTime));
  1540. rotate += (frames[frame + PathConstraintMixTimeline.ROTATE] - rotate) * percent;
  1541. translate += (frames[frame + PathConstraintMixTimeline.TRANSLATE] - translate) * percent;
  1542. }
  1543. if (pose == MixPose.setup) {
  1544. constraint.rotateMix = constraint.data.rotateMix + (rotate - constraint.data.rotateMix) * alpha;
  1545. constraint.translateMix = constraint.data.translateMix + (translate - constraint.data.translateMix) * alpha;
  1546. }
  1547. else {
  1548. constraint.rotateMix += (rotate - constraint.rotateMix) * alpha;
  1549. constraint.translateMix += (translate - constraint.translateMix) * alpha;
  1550. }
  1551. };
  1552. PathConstraintMixTimeline.ENTRIES = 3;
  1553. PathConstraintMixTimeline.PREV_TIME = -3;
  1554. PathConstraintMixTimeline.PREV_ROTATE = -2;
  1555. PathConstraintMixTimeline.PREV_TRANSLATE = -1;
  1556. PathConstraintMixTimeline.ROTATE = 1;
  1557. PathConstraintMixTimeline.TRANSLATE = 2;
  1558. return PathConstraintMixTimeline;
  1559. }(CurveTimeline));
  1560. spine.PathConstraintMixTimeline = PathConstraintMixTimeline;
  1561. })(spine || (spine = {}));
  1562. var spine;
  1563. (function (spine) {
  1564. var AnimationState = (function () {
  1565. function AnimationState(data) {
  1566. this.tracks = new Array();
  1567. this.events = new Array();
  1568. this.listeners = new Array();
  1569. this.queue = new EventQueue(this);
  1570. this.propertyIDs = new spine.IntSet();
  1571. this.mixingTo = new Array();
  1572. this.animationsChanged = false;
  1573. this.timeScale = 1;
  1574. this.trackEntryPool = new spine.Pool(function () { return new TrackEntry(); });
  1575. this.data = data;
  1576. }
  1577. AnimationState.prototype.update = function (delta) {
  1578. delta *= this.timeScale;
  1579. var tracks = this.tracks;
  1580. for (var i = 0, n = tracks.length; i < n; i++) {
  1581. var current = tracks[i];
  1582. if (current == null)
  1583. continue;
  1584. current.animationLast = current.nextAnimationLast;
  1585. current.trackLast = current.nextTrackLast;
  1586. var currentDelta = delta * current.timeScale;
  1587. if (current.delay > 0) {
  1588. current.delay -= currentDelta;
  1589. if (current.delay > 0)
  1590. continue;
  1591. currentDelta = -current.delay;
  1592. current.delay = 0;
  1593. }
  1594. var next = current.next;
  1595. if (next != null) {
  1596. var nextTime = current.trackLast - next.delay;
  1597. if (nextTime >= 0) {
  1598. next.delay = 0;
  1599. next.trackTime = nextTime + delta * next.timeScale;
  1600. current.trackTime += currentDelta;
  1601. this.setCurrent(i, next, true);
  1602. while (next.mixingFrom != null) {
  1603. next.mixTime += currentDelta;
  1604. next = next.mixingFrom;
  1605. }
  1606. continue;
  1607. }
  1608. }
  1609. else if (current.trackLast >= current.trackEnd && current.mixingFrom == null) {
  1610. tracks[i] = null;
  1611. this.queue.end(current);
  1612. this.disposeNext(current);
  1613. continue;
  1614. }
  1615. if (current.mixingFrom != null && this.updateMixingFrom(current, delta)) {
  1616. var from = current.mixingFrom;
  1617. current.mixingFrom = null;
  1618. while (from != null) {
  1619. this.queue.end(from);
  1620. from = from.mixingFrom;
  1621. }
  1622. }
  1623. current.trackTime += currentDelta;
  1624. }
  1625. this.queue.drain();
  1626. };
  1627. AnimationState.prototype.updateMixingFrom = function (to, delta) {
  1628. var from = to.mixingFrom;
  1629. if (from == null)
  1630. return true;
  1631. var finished = this.updateMixingFrom(from, delta);
  1632. if (to.mixTime > 0 && (to.mixTime >= to.mixDuration || to.timeScale == 0)) {
  1633. if (from.totalAlpha == 0) {
  1634. to.mixingFrom = from.mixingFrom;
  1635. to.interruptAlpha = from.interruptAlpha;
  1636. this.queue.end(from);
  1637. }
  1638. return finished;
  1639. }
  1640. from.animationLast = from.nextAnimationLast;
  1641. from.trackLast = from.nextTrackLast;
  1642. from.trackTime += delta * from.timeScale;
  1643. to.mixTime += delta * to.timeScale;
  1644. return false;
  1645. };
  1646. AnimationState.prototype.apply = function (skeleton) {
  1647. if (skeleton == null)
  1648. throw new Error("skeleton cannot be null.");
  1649. if (this.animationsChanged)
  1650. this._animationsChanged();
  1651. var events = this.events;
  1652. var tracks = this.tracks;
  1653. var applied = false;
  1654. for (var i = 0, n = tracks.length; i < n; i++) {
  1655. var current = tracks[i];
  1656. if (current == null || current.delay > 0)
  1657. continue;
  1658. applied = true;
  1659. var currentPose = i == 0 ? spine.MixPose.current : spine.MixPose.currentLayered;
  1660. var mix = current.alpha;
  1661. if (current.mixingFrom != null)
  1662. mix *= this.applyMixingFrom(current, skeleton, currentPose);
  1663. else if (current.trackTime >= current.trackEnd && current.next == null)
  1664. mix = 0;
  1665. var animationLast = current.animationLast, animationTime = current.getAnimationTime();
  1666. var timelineCount = current.animation.timelines.length;
  1667. var timelines = current.animation.timelines;
  1668. if (mix == 1) {
  1669. for (var ii = 0; ii < timelineCount; ii++)
  1670. timelines[ii].apply(skeleton, animationLast, animationTime, events, 1, spine.MixPose.setup, spine.MixDirection.in);
  1671. }
  1672. else {
  1673. var timelineData = current.timelineData;
  1674. var firstFrame = current.timelinesRotation.length == 0;
  1675. if (firstFrame)
  1676. spine.Utils.setArraySize(current.timelinesRotation, timelineCount << 1, null);
  1677. var timelinesRotation = current.timelinesRotation;
  1678. for (var ii = 0; ii < timelineCount; ii++) {
  1679. var timeline = timelines[ii];
  1680. var pose = timelineData[ii] >= AnimationState.FIRST ? spine.MixPose.setup : currentPose;
  1681. if (timeline instanceof spine.RotateTimeline) {
  1682. this.applyRotateTimeline(timeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
  1683. }
  1684. else
  1685. timeline.apply(skeleton, animationLast, animationTime, events, mix, pose, spine.MixDirection.in);
  1686. }
  1687. }
  1688. this.queueEvents(current, animationTime);
  1689. events.length = 0;
  1690. current.nextAnimationLast = animationTime;
  1691. current.nextTrackLast = current.trackTime;
  1692. }
  1693. this.queue.drain();
  1694. return applied;
  1695. };
  1696. AnimationState.prototype.applyMixingFrom = function (to, skeleton, currentPose) {
  1697. var from = to.mixingFrom;
  1698. if (from.mixingFrom != null)
  1699. this.applyMixingFrom(from, skeleton, currentPose);
  1700. var mix = 0;
  1701. if (to.mixDuration == 0)
  1702. mix = 1;
  1703. else {
  1704. mix = to.mixTime / to.mixDuration;
  1705. if (mix > 1)
  1706. mix = 1;
  1707. }
  1708. var events = mix < from.eventThreshold ? this.events : null;
  1709. var attachments = mix < from.attachmentThreshold, drawOrder = mix < from.drawOrderThreshold;
  1710. var animationLast = from.animationLast, animationTime = from.getAnimationTime();
  1711. var timelineCount = from.animation.timelines.length;
  1712. var timelines = from.animation.timelines;
  1713. var timelineData = from.timelineData;
  1714. var timelineDipMix = from.timelineDipMix;
  1715. var firstFrame = from.timelinesRotation.length == 0;
  1716. if (firstFrame)
  1717. spine.Utils.setArraySize(from.timelinesRotation, timelineCount << 1, null);
  1718. var timelinesRotation = from.timelinesRotation;
  1719. var pose;
  1720. var alphaDip = from.alpha * to.interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha = 0;
  1721. from.totalAlpha = 0;
  1722. for (var i = 0; i < timelineCount; i++) {
  1723. var timeline = timelines[i];
  1724. switch (timelineData[i]) {
  1725. case AnimationState.SUBSEQUENT:
  1726. if (!attachments && timeline instanceof spine.AttachmentTimeline)
  1727. continue;
  1728. if (!drawOrder && timeline instanceof spine.DrawOrderTimeline)
  1729. continue;
  1730. pose = currentPose;
  1731. alpha = alphaMix;
  1732. break;
  1733. case AnimationState.FIRST:
  1734. pose = spine.MixPose.setup;
  1735. alpha = alphaMix;
  1736. break;
  1737. case AnimationState.DIP:
  1738. pose = spine.MixPose.setup;
  1739. alpha = alphaDip;
  1740. break;
  1741. default:
  1742. pose = spine.MixPose.setup;
  1743. alpha = alphaDip;
  1744. var dipMix = timelineDipMix[i];
  1745. alpha *= Math.max(0, 1 - dipMix.mixTime / dipMix.mixDuration);
  1746. break;
  1747. }
  1748. from.totalAlpha += alpha;
  1749. if (timeline instanceof spine.RotateTimeline)
  1750. this.applyRotateTimeline(timeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
  1751. else {
  1752. timeline.apply(skeleton, animationLast, animationTime, events, alpha, pose, spine.MixDirection.out);
  1753. }
  1754. }
  1755. if (to.mixDuration > 0)
  1756. this.queueEvents(from, animationTime);
  1757. this.events.length = 0;
  1758. from.nextAnimationLast = animationTime;
  1759. from.nextTrackLast = from.trackTime;
  1760. return mix;
  1761. };
  1762. AnimationState.prototype.applyRotateTimeline = function (timeline, skeleton, time, alpha, pose, timelinesRotation, i, firstFrame) {
  1763. if (firstFrame)
  1764. timelinesRotation[i] = 0;
  1765. if (alpha == 1) {
  1766. timeline.apply(skeleton, 0, time, null, 1, pose, spine.MixDirection.in);
  1767. return;
  1768. }
  1769. var rotateTimeline = timeline;
  1770. var frames = rotateTimeline.frames;
  1771. var bone = skeleton.bones[rotateTimeline.boneIndex];
  1772. if (time < frames[0]) {
  1773. if (pose == spine.MixPose.setup)
  1774. bone.rotation = bone.data.rotation;
  1775. return;
  1776. }
  1777. var r2 = 0;
  1778. if (time >= frames[frames.length - spine.RotateTimeline.ENTRIES])
  1779. r2 = bone.data.rotation + frames[frames.length + spine.RotateTimeline.PREV_ROTATION];
  1780. else {
  1781. var frame = spine.Animation.binarySearch(frames, time, spine.RotateTimeline.ENTRIES);
  1782. var prevRotation = frames[frame + spine.RotateTimeline.PREV_ROTATION];
  1783. var frameTime = frames[frame];
  1784. var percent = rotateTimeline.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + spine.RotateTimeline.PREV_TIME] - frameTime));
  1785. r2 = frames[frame + spine.RotateTimeline.ROTATION] - prevRotation;
  1786. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1787. r2 = prevRotation + r2 * percent + bone.data.rotation;
  1788. r2 -= (16384 - ((16384.499999999996 - r2 / 360) | 0)) * 360;
  1789. }
  1790. var r1 = pose == spine.MixPose.setup ? bone.data.rotation : bone.rotation;
  1791. var total = 0, diff = r2 - r1;
  1792. if (diff == 0) {
  1793. total = timelinesRotation[i];
  1794. }
  1795. else {
  1796. diff -= (16384 - ((16384.499999999996 - diff / 360) | 0)) * 360;
  1797. var lastTotal = 0, lastDiff = 0;
  1798. if (firstFrame) {
  1799. lastTotal = 0;
  1800. lastDiff = diff;
  1801. }
  1802. else {
  1803. lastTotal = timelinesRotation[i];
  1804. lastDiff = timelinesRotation[i + 1];
  1805. }
  1806. var current = diff > 0, dir = lastTotal >= 0;
  1807. if (spine.MathUtils.signum(lastDiff) != spine.MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) {
  1808. if (Math.abs(lastTotal) > 180)
  1809. lastTotal += 360 * spine.MathUtils.signum(lastTotal);
  1810. dir = current;
  1811. }
  1812. total = diff + lastTotal - lastTotal % 360;
  1813. if (dir != current)
  1814. total += 360 * spine.MathUtils.signum(lastTotal);
  1815. timelinesRotation[i] = total;
  1816. }
  1817. timelinesRotation[i + 1] = diff;
  1818. r1 += total * alpha;
  1819. bone.rotation = r1 - (16384 - ((16384.499999999996 - r1 / 360) | 0)) * 360;
  1820. };
  1821. AnimationState.prototype.queueEvents = function (entry, animationTime) {
  1822. var animationStart = entry.animationStart, animationEnd = entry.animationEnd;
  1823. var duration = animationEnd - animationStart;
  1824. var trackLastWrapped = entry.trackLast % duration;
  1825. var events = this.events;
  1826. var i = 0, n = events.length;
  1827. for (; i < n; i++) {
  1828. var event_1 = events[i];
  1829. if (event_1.time < trackLastWrapped)
  1830. break;
  1831. if (event_1.time > animationEnd)
  1832. continue;
  1833. this.queue.event(entry, event_1);
  1834. }
  1835. if (entry.loop ? (trackLastWrapped > entry.trackTime % duration)
  1836. : (animationTime >= animationEnd && entry.animationLast < animationEnd)) {
  1837. this.queue.complete(entry);
  1838. }
  1839. for (; i < n; i++) {
  1840. var event_2 = events[i];
  1841. if (event_2.time < animationStart)
  1842. continue;
  1843. this.queue.event(entry, events[i]);
  1844. }
  1845. };
  1846. AnimationState.prototype.clearTracks = function () {
  1847. var oldDrainDisabled = this.queue.drainDisabled;
  1848. this.queue.drainDisabled = true;
  1849. for (var i = 0, n = this.tracks.length; i < n; i++)
  1850. this.clearTrack(i);
  1851. this.tracks.length = 0;
  1852. this.queue.drainDisabled = oldDrainDisabled;
  1853. this.queue.drain();
  1854. };
  1855. AnimationState.prototype.clearTrack = function (trackIndex) {
  1856. if (trackIndex >= this.tracks.length)
  1857. return;
  1858. var current = this.tracks[trackIndex];
  1859. if (current == null)
  1860. return;
  1861. this.queue.end(current);
  1862. this.disposeNext(current);
  1863. var entry = current;
  1864. while (true) {
  1865. var from = entry.mixingFrom;
  1866. if (from == null)
  1867. break;
  1868. this.queue.end(from);
  1869. entry.mixingFrom = null;
  1870. entry = from;
  1871. }
  1872. this.tracks[current.trackIndex] = null;
  1873. this.queue.drain();
  1874. };
  1875. AnimationState.prototype.setCurrent = function (index, current, interrupt) {
  1876. var from = this.expandToIndex(index);
  1877. this.tracks[index] = current;
  1878. if (from != null) {
  1879. if (interrupt)
  1880. this.queue.interrupt(from);
  1881. current.mixingFrom = from;
  1882. current.mixTime = 0;
  1883. if (from.mixingFrom != null && from.mixDuration > 0)
  1884. current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration);
  1885. from.timelinesRotation.length = 0;
  1886. }
  1887. this.queue.start(current);
  1888. };
  1889. AnimationState.prototype.setAnimation = function (trackIndex, animationName, loop) {
  1890. var animation = this.data.skeletonData.findAnimation(animationName);
  1891. if (animation == null)
  1892. throw new Error("Animation not found: " + animationName);
  1893. return this.setAnimationWith(trackIndex, animation, loop);
  1894. };
  1895. AnimationState.prototype.setAnimationWith = function (trackIndex, animation, loop) {
  1896. if (animation == null)
  1897. throw new Error("animation cannot be null.");
  1898. var interrupt = true;
  1899. var current = this.expandToIndex(trackIndex);
  1900. if (current != null) {
  1901. if (current.nextTrackLast == -1) {
  1902. this.tracks[trackIndex] = current.mixingFrom;
  1903. this.queue.interrupt(current);
  1904. this.queue.end(current);
  1905. this.disposeNext(current);
  1906. current = current.mixingFrom;
  1907. interrupt = false;
  1908. }
  1909. else
  1910. this.disposeNext(current);
  1911. }
  1912. var entry = this.trackEntry(trackIndex, animation, loop, current);
  1913. this.setCurrent(trackIndex, entry, interrupt);
  1914. this.queue.drain();
  1915. return entry;
  1916. };
  1917. AnimationState.prototype.addAnimation = function (trackIndex, animationName, loop, delay) {
  1918. var animation = this.data.skeletonData.findAnimation(animationName);
  1919. if (animation == null)
  1920. throw new Error("Animation not found: " + animationName);
  1921. return this.addAnimationWith(trackIndex, animation, loop, delay);
  1922. };
  1923. AnimationState.prototype.addAnimationWith = function (trackIndex, animation, loop, delay) {
  1924. if (animation == null)
  1925. throw new Error("animation cannot be null.");
  1926. var last = this.expandToIndex(trackIndex);
  1927. if (last != null) {
  1928. while (last.next != null)
  1929. last = last.next;
  1930. }
  1931. var entry = this.trackEntry(trackIndex, animation, loop, last);
  1932. if (last == null) {
  1933. this.setCurrent(trackIndex, entry, true);
  1934. this.queue.drain();
  1935. }
  1936. else {
  1937. last.next = entry;
  1938. if (delay <= 0) {
  1939. var duration = last.animationEnd - last.animationStart;
  1940. if (duration != 0)
  1941. delay += duration * (1 + ((last.trackTime / duration) | 0)) - this.data.getMix(last.animation, animation);
  1942. else
  1943. delay = 0;
  1944. }
  1945. }
  1946. entry.delay = delay;
  1947. return entry;
  1948. };
  1949. AnimationState.prototype.setEmptyAnimation = function (trackIndex, mixDuration) {
  1950. var entry = this.setAnimationWith(trackIndex, AnimationState.emptyAnimation, false);
  1951. entry.mixDuration = mixDuration;
  1952. entry.trackEnd = mixDuration;
  1953. return entry;
  1954. };
  1955. AnimationState.prototype.addEmptyAnimation = function (trackIndex, mixDuration, delay) {
  1956. if (delay <= 0)
  1957. delay -= mixDuration;
  1958. var entry = this.addAnimationWith(trackIndex, AnimationState.emptyAnimation, false, delay);
  1959. entry.mixDuration = mixDuration;
  1960. entry.trackEnd = mixDuration;
  1961. return entry;
  1962. };
  1963. AnimationState.prototype.setEmptyAnimations = function (mixDuration) {
  1964. var oldDrainDisabled = this.queue.drainDisabled;
  1965. this.queue.drainDisabled = true;
  1966. for (var i = 0, n = this.tracks.length; i < n; i++) {
  1967. var current = this.tracks[i];
  1968. if (current != null)
  1969. this.setEmptyAnimation(current.trackIndex, mixDuration);
  1970. }
  1971. this.queue.drainDisabled = oldDrainDisabled;
  1972. this.queue.drain();
  1973. };
  1974. AnimationState.prototype.expandToIndex = function (index) {
  1975. if (index < this.tracks.length)
  1976. return this.tracks[index];
  1977. spine.Utils.ensureArrayCapacity(this.tracks, index - this.tracks.length + 1, null);
  1978. this.tracks.length = index + 1;
  1979. return null;
  1980. };
  1981. AnimationState.prototype.trackEntry = function (trackIndex, animation, loop, last) {
  1982. var entry = this.trackEntryPool.obtain();
  1983. entry.trackIndex = trackIndex;
  1984. entry.animation = animation;
  1985. entry.loop = loop;
  1986. entry.eventThreshold = 0;
  1987. entry.attachmentThreshold = 0;
  1988. entry.drawOrderThreshold = 0;
  1989. entry.animationStart = 0;
  1990. entry.animationEnd = animation.duration;
  1991. entry.animationLast = -1;
  1992. entry.nextAnimationLast = -1;
  1993. entry.delay = 0;
  1994. entry.trackTime = 0;
  1995. entry.trackLast = -1;
  1996. entry.nextTrackLast = -1;
  1997. entry.trackEnd = Number.MAX_VALUE;
  1998. entry.timeScale = 1;
  1999. entry.alpha = 1;
  2000. entry.interruptAlpha = 1;
  2001. entry.mixTime = 0;
  2002. entry.mixDuration = last == null ? 0 : this.data.getMix(last.animation, animation);
  2003. return entry;
  2004. };
  2005. AnimationState.prototype.disposeNext = function (entry) {
  2006. var next = entry.next;
  2007. while (next != null) {
  2008. this.queue.dispose(next);
  2009. next = next.next;
  2010. }
  2011. entry.next = null;
  2012. };
  2013. AnimationState.prototype._animationsChanged = function () {
  2014. this.animationsChanged = false;
  2015. var propertyIDs = this.propertyIDs;
  2016. propertyIDs.clear();
  2017. var mixingTo = this.mixingTo;
  2018. var lastEntry = null;
  2019. for (var i = 0, n = this.tracks.length; i < n; i++) {
  2020. var entry = this.tracks[i];
  2021. if (entry != null) {
  2022. entry.setTimelineData(lastEntry, mixingTo, propertyIDs);
  2023. lastEntry = entry;
  2024. }
  2025. }
  2026. };
  2027. AnimationState.prototype.getCurrent = function (trackIndex) {
  2028. if (trackIndex >= this.tracks.length)
  2029. return null;
  2030. return this.tracks[trackIndex];
  2031. };
  2032. AnimationState.prototype.addListener = function (listener) {
  2033. if (listener == null)
  2034. throw new Error("listener cannot be null.");
  2035. this.listeners.push(listener);
  2036. };
  2037. AnimationState.prototype.removeListener = function (listener) {
  2038. var index = this.listeners.indexOf(listener);
  2039. if (index >= 0)
  2040. this.listeners.splice(index, 1);
  2041. };
  2042. AnimationState.prototype.clearListeners = function () {
  2043. this.listeners.length = 0;
  2044. };
  2045. AnimationState.prototype.clearListenerNotifications = function () {
  2046. this.queue.clear();
  2047. };
  2048. AnimationState.emptyAnimation = new spine.Animation("<empty>", [], 0);
  2049. AnimationState.SUBSEQUENT = 0;
  2050. AnimationState.FIRST = 1;
  2051. AnimationState.DIP = 2;
  2052. AnimationState.DIP_MIX = 3;
  2053. return AnimationState;
  2054. }());
  2055. spine.AnimationState = AnimationState;
  2056. var TrackEntry = (function () {
  2057. function TrackEntry() {
  2058. this.timelineData = new Array();
  2059. this.timelineDipMix = new Array();
  2060. this.timelinesRotation = new Array();
  2061. }
  2062. TrackEntry.prototype.reset = function () {
  2063. this.next = null;
  2064. this.mixingFrom = null;
  2065. this.animation = null;
  2066. this.listener = null;
  2067. this.timelineData.length = 0;
  2068. this.timelineDipMix.length = 0;
  2069. this.timelinesRotation.length = 0;
  2070. };
  2071. TrackEntry.prototype.setTimelineData = function (to, mixingToArray, propertyIDs) {
  2072. if (to != null)
  2073. mixingToArray.push(to);
  2074. var lastEntry = this.mixingFrom != null ? this.mixingFrom.setTimelineData(this, mixingToArray, propertyIDs) : this;
  2075. if (to != null)
  2076. mixingToArray.pop();
  2077. var mixingTo = mixingToArray;
  2078. var mixingToLast = mixingToArray.length - 1;
  2079. var timelines = this.animation.timelines;
  2080. var timelinesCount = this.animation.timelines.length;
  2081. var timelineData = spine.Utils.setArraySize(this.timelineData, timelinesCount);
  2082. this.timelineDipMix.length = 0;
  2083. var timelineDipMix = spine.Utils.setArraySize(this.timelineDipMix, timelinesCount);
  2084. outer: for (var i = 0; i < timelinesCount; i++) {
  2085. var id = timelines[i].getPropertyId();
  2086. if (!propertyIDs.add(id))
  2087. timelineData[i] = AnimationState.SUBSEQUENT;
  2088. else if (to == null || !to.hasTimeline(id))
  2089. timelineData[i] = AnimationState.FIRST;
  2090. else {
  2091. for (var ii = mixingToLast; ii >= 0; ii--) {
  2092. var entry = mixingTo[ii];
  2093. if (!entry.hasTimeline(id)) {
  2094. if (entry.mixDuration > 0) {
  2095. timelineData[i] = AnimationState.DIP_MIX;
  2096. timelineDipMix[i] = entry;
  2097. continue outer;
  2098. }
  2099. }
  2100. }
  2101. timelineData[i] = AnimationState.DIP;
  2102. }
  2103. }
  2104. return lastEntry;
  2105. };
  2106. TrackEntry.prototype.hasTimeline = function (id) {
  2107. var timelines = this.animation.timelines;
  2108. for (var i = 0, n = timelines.length; i < n; i++)
  2109. if (timelines[i].getPropertyId() == id)
  2110. return true;
  2111. return false;
  2112. };
  2113. TrackEntry.prototype.getAnimationTime = function () {
  2114. if (this.loop) {
  2115. var duration = this.animationEnd - this.animationStart;
  2116. if (duration == 0)
  2117. return this.animationStart;
  2118. return (this.trackTime % duration) + this.animationStart;
  2119. }
  2120. return Math.min(this.trackTime + this.animationStart, this.animationEnd);
  2121. };
  2122. TrackEntry.prototype.setAnimationLast = function (animationLast) {
  2123. this.animationLast = animationLast;
  2124. this.nextAnimationLast = animationLast;
  2125. };
  2126. TrackEntry.prototype.isComplete = function () {
  2127. return this.trackTime >= this.animationEnd - this.animationStart;
  2128. };
  2129. TrackEntry.prototype.resetRotationDirections = function () {
  2130. this.timelinesRotation.length = 0;
  2131. };
  2132. return TrackEntry;
  2133. }());
  2134. spine.TrackEntry = TrackEntry;
  2135. var EventQueue = (function () {
  2136. function EventQueue(animState) {
  2137. this.objects = [];
  2138. this.drainDisabled = false;
  2139. this.animState = animState;
  2140. }
  2141. EventQueue.prototype.start = function (entry) {
  2142. this.objects.push(EventType.start);
  2143. this.objects.push(entry);
  2144. this.animState.animationsChanged = true;
  2145. };
  2146. EventQueue.prototype.interrupt = function (entry) {
  2147. this.objects.push(EventType.interrupt);
  2148. this.objects.push(entry);
  2149. };
  2150. EventQueue.prototype.end = function (entry) {
  2151. this.objects.push(EventType.end);
  2152. this.objects.push(entry);
  2153. this.animState.animationsChanged = true;
  2154. };
  2155. EventQueue.prototype.dispose = function (entry) {
  2156. this.objects.push(EventType.dispose);
  2157. this.objects.push(entry);
  2158. };
  2159. EventQueue.prototype.complete = function (entry) {
  2160. this.objects.push(EventType.complete);
  2161. this.objects.push(entry);
  2162. };
  2163. EventQueue.prototype.event = function (entry, event) {
  2164. this.objects.push(EventType.event);
  2165. this.objects.push(entry);
  2166. this.objects.push(event);
  2167. };
  2168. EventQueue.prototype.drain = function () {
  2169. if (this.drainDisabled)
  2170. return;
  2171. this.drainDisabled = true;
  2172. var objects = this.objects;
  2173. var listeners = this.animState.listeners;
  2174. for (var i = 0; i < objects.length; i += 2) {
  2175. var type = objects[i];
  2176. var entry = objects[i + 1];
  2177. switch (type) {
  2178. case EventType.start:
  2179. if (entry.listener != null && entry.listener.start)
  2180. entry.listener.start(entry);
  2181. for (var ii = 0; ii < listeners.length; ii++)
  2182. if (listeners[ii].start)
  2183. listeners[ii].start(entry);
  2184. break;
  2185. case EventType.interrupt:
  2186. if (entry.listener != null && entry.listener.interrupt)
  2187. entry.listener.interrupt(entry);
  2188. for (var ii = 0; ii < listeners.length; ii++)
  2189. if (listeners[ii].interrupt)
  2190. listeners[ii].interrupt(entry);
  2191. break;
  2192. case EventType.end:
  2193. if (entry.listener != null && entry.listener.end)
  2194. entry.listener.end(entry);
  2195. for (var ii = 0; ii < listeners.length; ii++)
  2196. if (listeners[ii].end)
  2197. listeners[ii].end(entry);
  2198. case EventType.dispose:
  2199. if (entry.listener != null && entry.listener.dispose)
  2200. entry.listener.dispose(entry);
  2201. for (var ii = 0; ii < listeners.length; ii++)
  2202. if (listeners[ii].dispose)
  2203. listeners[ii].dispose(entry);
  2204. this.animState.trackEntryPool.free(entry);
  2205. break;
  2206. case EventType.complete:
  2207. if (entry.listener != null && entry.listener.complete)
  2208. entry.listener.complete(entry);
  2209. for (var ii = 0; ii < listeners.length; ii++)
  2210. if (listeners[ii].complete)
  2211. listeners[ii].complete(entry);
  2212. break;
  2213. case EventType.event:
  2214. var event_3 = objects[i++ + 2];
  2215. if (entry.listener != null && entry.listener.event)
  2216. entry.listener.event(entry, event_3);
  2217. for (var ii = 0; ii < listeners.length; ii++)
  2218. if (listeners[ii].event)
  2219. listeners[ii].event(entry, event_3);
  2220. break;
  2221. }
  2222. }
  2223. this.clear();
  2224. this.drainDisabled = false;
  2225. };
  2226. EventQueue.prototype.clear = function () {
  2227. this.objects.length = 0;
  2228. };
  2229. return EventQueue;
  2230. }());
  2231. spine.EventQueue = EventQueue;
  2232. (function (EventType) {
  2233. EventType[EventType["start"] = 0] = "start";
  2234. EventType[EventType["interrupt"] = 1] = "interrupt";
  2235. EventType[EventType["end"] = 2] = "end";
  2236. EventType[EventType["dispose"] = 3] = "dispose";
  2237. EventType[EventType["complete"] = 4] = "complete";
  2238. EventType[EventType["event"] = 5] = "event";
  2239. })(spine.EventType || (spine.EventType = {}));
  2240. var EventType = spine.EventType;
  2241. var AnimationStateAdapter2 = (function () {
  2242. function AnimationStateAdapter2() {
  2243. }
  2244. AnimationStateAdapter2.prototype.start = function (entry) {
  2245. };
  2246. AnimationStateAdapter2.prototype.interrupt = function (entry) {
  2247. };
  2248. AnimationStateAdapter2.prototype.end = function (entry) {
  2249. };
  2250. AnimationStateAdapter2.prototype.dispose = function (entry) {
  2251. };
  2252. AnimationStateAdapter2.prototype.complete = function (entry) {
  2253. };
  2254. AnimationStateAdapter2.prototype.event = function (entry, event) {
  2255. };
  2256. return AnimationStateAdapter2;
  2257. }());
  2258. spine.AnimationStateAdapter2 = AnimationStateAdapter2;
  2259. })(spine || (spine = {}));
  2260. var spine;
  2261. (function (spine) {
  2262. var AnimationStateData = (function () {
  2263. function AnimationStateData(skeletonData) {
  2264. this.animationToMixTime = {};
  2265. this.defaultMix = 0;
  2266. if (skeletonData == null)
  2267. throw new Error("skeletonData cannot be null.");
  2268. this.skeletonData = skeletonData;
  2269. }
  2270. AnimationStateData.prototype.setMix = function (fromName, toName, duration) {
  2271. var from = this.skeletonData.findAnimation(fromName);
  2272. if (from == null)
  2273. throw new Error("Animation not found: " + fromName);
  2274. var to = this.skeletonData.findAnimation(toName);
  2275. if (to == null)
  2276. throw new Error("Animation not found: " + toName);
  2277. this.setMixWith(from, to, duration);
  2278. };
  2279. AnimationStateData.prototype.setMixWith = function (from, to, duration) {
  2280. if (from == null)
  2281. throw new Error("from cannot be null.");
  2282. if (to == null)
  2283. throw new Error("to cannot be null.");
  2284. var key = from.name + to.name;
  2285. this.animationToMixTime[key] = duration;
  2286. };
  2287. AnimationStateData.prototype.getMix = function (from, to) {
  2288. var key = from.name + to.name;
  2289. var value = this.animationToMixTime[key];
  2290. return value === undefined ? this.defaultMix : value;
  2291. };
  2292. return AnimationStateData;
  2293. }());
  2294. spine.AnimationStateData = AnimationStateData;
  2295. })(spine || (spine = {}));
  2296. var spine;
  2297. (function (spine) {
  2298. var AtlasAttachmentLoader = (function () {
  2299. function AtlasAttachmentLoader(atlas) {
  2300. this.atlas = atlas;
  2301. }
  2302. AtlasAttachmentLoader.prototype.newRegionAttachment = function (skin, name, path) {
  2303. var region = this.atlas.findRegion(path);
  2304. if (region == null)
  2305. throw new Error("Region not found in atlas: " + path + " (region attachment: " + name + ")");
  2306. region.renderObject = region;
  2307. var attachment = new spine.RegionAttachment(name);
  2308. attachment.setRegion(region);
  2309. return attachment;
  2310. };
  2311. AtlasAttachmentLoader.prototype.newMeshAttachment = function (skin, name, path) {
  2312. var region = this.atlas.findRegion(path);
  2313. if (region == null)
  2314. throw new Error("Region not found in atlas: " + path + " (mesh attachment: " + name + ")");
  2315. region.renderObject = region;
  2316. var attachment = new spine.MeshAttachment(name);
  2317. attachment.region = region;
  2318. return attachment;
  2319. };
  2320. AtlasAttachmentLoader.prototype.newBoundingBoxAttachment = function (skin, name) {
  2321. return new spine.BoundingBoxAttachment(name);
  2322. };
  2323. AtlasAttachmentLoader.prototype.newPathAttachment = function (skin, name) {
  2324. return new spine.PathAttachment(name);
  2325. };
  2326. AtlasAttachmentLoader.prototype.newPointAttachment = function (skin, name) {
  2327. return new spine.PointAttachment(name);
  2328. };
  2329. AtlasAttachmentLoader.prototype.newClippingAttachment = function (skin, name) {
  2330. return new spine.ClippingAttachment(name);
  2331. };
  2332. return AtlasAttachmentLoader;
  2333. }());
  2334. spine.AtlasAttachmentLoader = AtlasAttachmentLoader;
  2335. })(spine || (spine = {}));
  2336. var spine;
  2337. (function (spine) {
  2338. var Attachment = (function () {
  2339. function Attachment(name) {
  2340. if (name == null)
  2341. throw new Error("name cannot be null.");
  2342. this.name = name;
  2343. }
  2344. return Attachment;
  2345. }());
  2346. spine.Attachment = Attachment;
  2347. var VertexAttachment = (function (_super) {
  2348. __extends(VertexAttachment, _super);
  2349. function VertexAttachment(name) {
  2350. _super.call(this, name);
  2351. this.id = (VertexAttachment.nextID++ & 65535) << 11;
  2352. this.worldVerticesLength = 0;
  2353. }
  2354. VertexAttachment.prototype.computeWorldVertices = function (slot, start, count, worldVertices, offset, stride) {
  2355. count = offset + (count >> 1) * stride;
  2356. var skeleton = slot.bone.skeleton;
  2357. var deformArray = slot.attachmentVertices;
  2358. var vertices = this.vertices;
  2359. var bones = this.bones;
  2360. if (bones == null) {
  2361. if (deformArray.length > 0)
  2362. vertices = deformArray;
  2363. var bone = slot.bone;
  2364. var x = bone.worldX;
  2365. var y = bone.worldY;
  2366. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  2367. for (var v_1 = start, w = offset; w < count; v_1 += 2, w += stride) {
  2368. var vx = vertices[v_1], vy = vertices[v_1 + 1];
  2369. worldVertices[w] = vx * a + vy * b + x;
  2370. worldVertices[w + 1] = vx * c + vy * d + y;
  2371. }
  2372. return;
  2373. }
  2374. var v = 0, skip = 0;
  2375. for (var i = 0; i < start; i += 2) {
  2376. var n = bones[v];
  2377. v += n + 1;
  2378. skip += n;
  2379. }
  2380. var skeletonBones = skeleton.bones;
  2381. if (deformArray.length == 0) {
  2382. for (var w = offset, b = skip * 3; w < count; w += stride) {
  2383. var wx = 0, wy = 0;
  2384. var n = bones[v++];
  2385. n += v;
  2386. for (; v < n; v++, b += 3) {
  2387. var bone = skeletonBones[bones[v]];
  2388. var vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2];
  2389. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  2390. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  2391. }
  2392. worldVertices[w] = wx;
  2393. worldVertices[w + 1] = wy;
  2394. }
  2395. }
  2396. else {
  2397. var deform = deformArray;
  2398. for (var w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
  2399. var wx = 0, wy = 0;
  2400. var n = bones[v++];
  2401. n += v;
  2402. for (; v < n; v++, b += 3, f += 2) {
  2403. var bone = skeletonBones[bones[v]];
  2404. var vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2];
  2405. wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight;
  2406. wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight;
  2407. }
  2408. worldVertices[w] = wx;
  2409. worldVertices[w + 1] = wy;
  2410. }
  2411. }
  2412. };
  2413. VertexAttachment.prototype.applyDeform = function (sourceAttachment) {
  2414. return this == sourceAttachment;
  2415. };
  2416. VertexAttachment.nextID = 0;
  2417. return VertexAttachment;
  2418. }(Attachment));
  2419. spine.VertexAttachment = VertexAttachment;
  2420. })(spine || (spine = {}));
  2421. var spine;
  2422. (function (spine) {
  2423. (function (AttachmentType) {
  2424. AttachmentType[AttachmentType["Region"] = 0] = "Region";
  2425. AttachmentType[AttachmentType["BoundingBox"] = 1] = "BoundingBox";
  2426. AttachmentType[AttachmentType["Mesh"] = 2] = "Mesh";
  2427. AttachmentType[AttachmentType["LinkedMesh"] = 3] = "LinkedMesh";
  2428. AttachmentType[AttachmentType["Path"] = 4] = "Path";
  2429. AttachmentType[AttachmentType["Point"] = 5] = "Point";
  2430. })(spine.AttachmentType || (spine.AttachmentType = {}));
  2431. var AttachmentType = spine.AttachmentType;
  2432. })(spine || (spine = {}));
  2433. var spine;
  2434. (function (spine) {
  2435. var BoundingBoxAttachment = (function (_super) {
  2436. __extends(BoundingBoxAttachment, _super);
  2437. function BoundingBoxAttachment(name) {
  2438. _super.call(this, name);
  2439. this.color = new spine.Color(1, 1, 1, 1);
  2440. }
  2441. return BoundingBoxAttachment;
  2442. }(spine.VertexAttachment));
  2443. spine.BoundingBoxAttachment = BoundingBoxAttachment;
  2444. })(spine || (spine = {}));
  2445. var spine;
  2446. (function (spine) {
  2447. var ClippingAttachment = (function (_super) {
  2448. __extends(ClippingAttachment, _super);
  2449. function ClippingAttachment(name) {
  2450. _super.call(this, name);
  2451. this.color = new spine.Color(0.2275, 0.2275, 0.8078, 1);
  2452. }
  2453. return ClippingAttachment;
  2454. }(spine.VertexAttachment));
  2455. spine.ClippingAttachment = ClippingAttachment;
  2456. })(spine || (spine = {}));
  2457. var spine;
  2458. (function (spine) {
  2459. var MeshAttachment = (function (_super) {
  2460. __extends(MeshAttachment, _super);
  2461. function MeshAttachment(name) {
  2462. _super.call(this, name);
  2463. this.color = new spine.Color(1, 1, 1, 1);
  2464. this.inheritDeform = false;
  2465. this.tempColor = new spine.Color(0, 0, 0, 0);
  2466. }
  2467. MeshAttachment.prototype.updateUVs = function () {
  2468. var u = 0, v = 0, width = 0, height = 0;
  2469. if (this.region == null) {
  2470. u = v = 0;
  2471. width = height = 1;
  2472. }
  2473. else {
  2474. u = this.region.u;
  2475. v = this.region.v;
  2476. width = this.region.u2 - u;
  2477. height = this.region.v2 - v;
  2478. }
  2479. var regionUVs = this.regionUVs;
  2480. if (this.uvs == null || this.uvs.length != regionUVs.length)
  2481. this.uvs = spine.Utils.newFloatArray(regionUVs.length);
  2482. var uvs = this.uvs;
  2483. if (this.region.rotate) {
  2484. for (var i = 0, n = uvs.length; i < n; i += 2) {
  2485. uvs[i] = u + regionUVs[i + 1] * width;
  2486. uvs[i + 1] = v + height - regionUVs[i] * height;
  2487. }
  2488. }
  2489. else {
  2490. for (var i = 0, n = uvs.length; i < n; i += 2) {
  2491. uvs[i] = u + regionUVs[i] * width;
  2492. uvs[i + 1] = v + regionUVs[i + 1] * height;
  2493. }
  2494. }
  2495. };
  2496. MeshAttachment.prototype.applyDeform = function (sourceAttachment) {
  2497. return this == sourceAttachment || (this.inheritDeform && this.parentMesh == sourceAttachment);
  2498. };
  2499. MeshAttachment.prototype.getParentMesh = function () {
  2500. return this.parentMesh;
  2501. };
  2502. MeshAttachment.prototype.setParentMesh = function (parentMesh) {
  2503. this.parentMesh = parentMesh;
  2504. if (parentMesh != null) {
  2505. this.bones = parentMesh.bones;
  2506. this.vertices = parentMesh.vertices;
  2507. this.worldVerticesLength = parentMesh.worldVerticesLength;
  2508. this.regionUVs = parentMesh.regionUVs;
  2509. this.triangles = parentMesh.triangles;
  2510. this.hullLength = parentMesh.hullLength;
  2511. this.worldVerticesLength = parentMesh.worldVerticesLength;
  2512. }
  2513. };
  2514. return MeshAttachment;
  2515. }(spine.VertexAttachment));
  2516. spine.MeshAttachment = MeshAttachment;
  2517. })(spine || (spine = {}));
  2518. var spine;
  2519. (function (spine) {
  2520. var PathAttachment = (function (_super) {
  2521. __extends(PathAttachment, _super);
  2522. function PathAttachment(name) {
  2523. _super.call(this, name);
  2524. this.closed = false;
  2525. this.constantSpeed = false;
  2526. this.color = new spine.Color(1, 1, 1, 1);
  2527. }
  2528. return PathAttachment;
  2529. }(spine.VertexAttachment));
  2530. spine.PathAttachment = PathAttachment;
  2531. })(spine || (spine = {}));
  2532. var spine;
  2533. (function (spine) {
  2534. var PointAttachment = (function (_super) {
  2535. __extends(PointAttachment, _super);
  2536. function PointAttachment(name) {
  2537. _super.call(this, name);
  2538. this.color = new spine.Color(0.38, 0.94, 0, 1);
  2539. }
  2540. PointAttachment.prototype.computeWorldPosition = function (bone, point) {
  2541. point.x = this.x * bone.a + this.y * bone.b + bone.worldX;
  2542. point.y = this.x * bone.c + this.y * bone.d + bone.worldY;
  2543. return point;
  2544. };
  2545. PointAttachment.prototype.computeWorldRotation = function (bone) {
  2546. var cos = spine.MathUtils.cosDeg(this.rotation), sin = spine.MathUtils.sinDeg(this.rotation);
  2547. var x = cos * bone.a + sin * bone.b;
  2548. var y = cos * bone.c + sin * bone.d;
  2549. return Math.atan2(y, x) * spine.MathUtils.radDeg;
  2550. };
  2551. return PointAttachment;
  2552. }(spine.VertexAttachment));
  2553. spine.PointAttachment = PointAttachment;
  2554. })(spine || (spine = {}));
  2555. var spine;
  2556. (function (spine) {
  2557. var RegionAttachment = (function (_super) {
  2558. __extends(RegionAttachment, _super);
  2559. function RegionAttachment(name) {
  2560. _super.call(this, name);
  2561. this.x = 0;
  2562. this.y = 0;
  2563. this.scaleX = 1;
  2564. this.scaleY = 1;
  2565. this.rotation = 0;
  2566. this.width = 0;
  2567. this.height = 0;
  2568. this.color = new spine.Color(1, 1, 1, 1);
  2569. this.offset = spine.Utils.newFloatArray(8);
  2570. this.uvs = spine.Utils.newFloatArray(8);
  2571. this.tempColor = new spine.Color(1, 1, 1, 1);
  2572. }
  2573. RegionAttachment.prototype.updateOffset = function () {
  2574. var regionScaleX = this.width / this.region.originalWidth * this.scaleX;
  2575. var regionScaleY = this.height / this.region.originalHeight * this.scaleY;
  2576. var localX = -this.width / 2 * this.scaleX + this.region.offsetX * regionScaleX;
  2577. var localY = -this.height / 2 * this.scaleY + this.region.offsetY * regionScaleY;
  2578. var localX2 = localX + this.region.width * regionScaleX;
  2579. var localY2 = localY + this.region.height * regionScaleY;
  2580. var radians = this.rotation * Math.PI / 180;
  2581. var cos = Math.cos(radians);
  2582. var sin = Math.sin(radians);
  2583. var localXCos = localX * cos + this.x;
  2584. var localXSin = localX * sin;
  2585. var localYCos = localY * cos + this.y;
  2586. var localYSin = localY * sin;
  2587. var localX2Cos = localX2 * cos + this.x;
  2588. var localX2Sin = localX2 * sin;
  2589. var localY2Cos = localY2 * cos + this.y;
  2590. var localY2Sin = localY2 * sin;
  2591. var offset = this.offset;
  2592. offset[RegionAttachment.OX1] = localXCos - localYSin;
  2593. offset[RegionAttachment.OY1] = localYCos + localXSin;
  2594. offset[RegionAttachment.OX2] = localXCos - localY2Sin;
  2595. offset[RegionAttachment.OY2] = localY2Cos + localXSin;
  2596. offset[RegionAttachment.OX3] = localX2Cos - localY2Sin;
  2597. offset[RegionAttachment.OY3] = localY2Cos + localX2Sin;
  2598. offset[RegionAttachment.OX4] = localX2Cos - localYSin;
  2599. offset[RegionAttachment.OY4] = localYCos + localX2Sin;
  2600. };
  2601. RegionAttachment.prototype.setRegion = function (region) {
  2602. this.region = region;
  2603. var uvs = this.uvs;
  2604. if (region.rotate) {
  2605. uvs[2] = region.u;
  2606. uvs[3] = region.v2;
  2607. uvs[4] = region.u;
  2608. uvs[5] = region.v;
  2609. uvs[6] = region.u2;
  2610. uvs[7] = region.v;
  2611. uvs[0] = region.u2;
  2612. uvs[1] = region.v2;
  2613. }
  2614. else {
  2615. uvs[0] = region.u;
  2616. uvs[1] = region.v2;
  2617. uvs[2] = region.u;
  2618. uvs[3] = region.v;
  2619. uvs[4] = region.u2;
  2620. uvs[5] = region.v;
  2621. uvs[6] = region.u2;
  2622. uvs[7] = region.v2;
  2623. }
  2624. };
  2625. RegionAttachment.prototype.computeWorldVertices = function (bone, worldVertices, offset, stride) {
  2626. var vertexOffset = this.offset;
  2627. var x = bone.worldX, y = bone.worldY;
  2628. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  2629. var offsetX = 0, offsetY = 0;
  2630. offsetX = vertexOffset[RegionAttachment.OX1];
  2631. offsetY = vertexOffset[RegionAttachment.OY1];
  2632. worldVertices[offset] = offsetX * a + offsetY * b + x;
  2633. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2634. offset += stride;
  2635. offsetX = vertexOffset[RegionAttachment.OX2];
  2636. offsetY = vertexOffset[RegionAttachment.OY2];
  2637. worldVertices[offset] = offsetX * a + offsetY * b + x;
  2638. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2639. offset += stride;
  2640. offsetX = vertexOffset[RegionAttachment.OX3];
  2641. offsetY = vertexOffset[RegionAttachment.OY3];
  2642. worldVertices[offset] = offsetX * a + offsetY * b + x;
  2643. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2644. offset += stride;
  2645. offsetX = vertexOffset[RegionAttachment.OX4];
  2646. offsetY = vertexOffset[RegionAttachment.OY4];
  2647. worldVertices[offset] = offsetX * a + offsetY * b + x;
  2648. worldVertices[offset + 1] = offsetX * c + offsetY * d + y;
  2649. };
  2650. RegionAttachment.OX1 = 0;
  2651. RegionAttachment.OY1 = 1;
  2652. RegionAttachment.OX2 = 2;
  2653. RegionAttachment.OY2 = 3;
  2654. RegionAttachment.OX3 = 4;
  2655. RegionAttachment.OY3 = 5;
  2656. RegionAttachment.OX4 = 6;
  2657. RegionAttachment.OY4 = 7;
  2658. RegionAttachment.X1 = 0;
  2659. RegionAttachment.Y1 = 1;
  2660. RegionAttachment.C1R = 2;
  2661. RegionAttachment.C1G = 3;
  2662. RegionAttachment.C1B = 4;
  2663. RegionAttachment.C1A = 5;
  2664. RegionAttachment.U1 = 6;
  2665. RegionAttachment.V1 = 7;
  2666. RegionAttachment.X2 = 8;
  2667. RegionAttachment.Y2 = 9;
  2668. RegionAttachment.C2R = 10;
  2669. RegionAttachment.C2G = 11;
  2670. RegionAttachment.C2B = 12;
  2671. RegionAttachment.C2A = 13;
  2672. RegionAttachment.U2 = 14;
  2673. RegionAttachment.V2 = 15;
  2674. RegionAttachment.X3 = 16;
  2675. RegionAttachment.Y3 = 17;
  2676. RegionAttachment.C3R = 18;
  2677. RegionAttachment.C3G = 19;
  2678. RegionAttachment.C3B = 20;
  2679. RegionAttachment.C3A = 21;
  2680. RegionAttachment.U3 = 22;
  2681. RegionAttachment.V3 = 23;
  2682. RegionAttachment.X4 = 24;
  2683. RegionAttachment.Y4 = 25;
  2684. RegionAttachment.C4R = 26;
  2685. RegionAttachment.C4G = 27;
  2686. RegionAttachment.C4B = 28;
  2687. RegionAttachment.C4A = 29;
  2688. RegionAttachment.U4 = 30;
  2689. RegionAttachment.V4 = 31;
  2690. return RegionAttachment;
  2691. }(spine.Attachment));
  2692. spine.RegionAttachment = RegionAttachment;
  2693. })(spine || (spine = {}));
  2694. var spine;
  2695. (function (spine) {
  2696. (function (BlendMode) {
  2697. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  2698. BlendMode[BlendMode["Additive"] = 1] = "Additive";
  2699. BlendMode[BlendMode["Multiply"] = 2] = "Multiply";
  2700. BlendMode[BlendMode["Screen"] = 3] = "Screen";
  2701. })(spine.BlendMode || (spine.BlendMode = {}));
  2702. var BlendMode = spine.BlendMode;
  2703. })(spine || (spine = {}));
  2704. var spine;
  2705. (function (spine) {
  2706. var Bone = (function () {
  2707. function Bone(data, skeleton, parent) {
  2708. this.children = new Array();
  2709. this.x = 0;
  2710. this.y = 0;
  2711. this.rotation = 0;
  2712. this.scaleX = 0;
  2713. this.scaleY = 0;
  2714. this.shearX = 0;
  2715. this.shearY = 0;
  2716. this.ax = 0;
  2717. this.ay = 0;
  2718. this.arotation = 0;
  2719. this.ascaleX = 0;
  2720. this.ascaleY = 0;
  2721. this.ashearX = 0;
  2722. this.ashearY = 0;
  2723. this.appliedValid = false;
  2724. this.a = 0;
  2725. this.b = 0;
  2726. this.worldX = 0;
  2727. this.c = 0;
  2728. this.d = 0;
  2729. this.worldY = 0;
  2730. this.sorted = false;
  2731. if (data == null)
  2732. throw new Error("data cannot be null.");
  2733. if (skeleton == null)
  2734. throw new Error("skeleton cannot be null.");
  2735. this.data = data;
  2736. this.skeleton = skeleton;
  2737. this.parent = parent;
  2738. this.setToSetupPose();
  2739. }
  2740. Bone.prototype.update = function () {
  2741. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2742. };
  2743. Bone.prototype.updateWorldTransform = function () {
  2744. this.updateWorldTransformWith(this.x, this.y, this.rotation, this.scaleX, this.scaleY, this.shearX, this.shearY);
  2745. };
  2746. Bone.prototype.updateWorldTransformWith = function (x, y, rotation, scaleX, scaleY, shearX, shearY) {
  2747. this.ax = x;
  2748. this.ay = y;
  2749. this.arotation = rotation;
  2750. this.ascaleX = scaleX;
  2751. this.ascaleY = scaleY;
  2752. this.ashearX = shearX;
  2753. this.ashearY = shearY;
  2754. this.appliedValid = true;
  2755. var parent = this.parent;
  2756. if (parent == null) {
  2757. var rotationY = rotation + 90 + shearY;
  2758. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2759. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2760. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2761. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2762. var skeleton = this.skeleton;
  2763. if (skeleton.flipX) {
  2764. x = -x;
  2765. la = -la;
  2766. lb = -lb;
  2767. }
  2768. if (skeleton.flipY) {
  2769. y = -y;
  2770. lc = -lc;
  2771. ld = -ld;
  2772. }
  2773. this.a = la;
  2774. this.b = lb;
  2775. this.c = lc;
  2776. this.d = ld;
  2777. this.worldX = x + skeleton.x;
  2778. this.worldY = y + skeleton.y;
  2779. return;
  2780. }
  2781. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2782. this.worldX = pa * x + pb * y + parent.worldX;
  2783. this.worldY = pc * x + pd * y + parent.worldY;
  2784. switch (this.data.transformMode) {
  2785. case spine.TransformMode.Normal: {
  2786. var rotationY = rotation + 90 + shearY;
  2787. var la = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2788. var lb = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2789. var lc = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2790. var ld = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2791. this.a = pa * la + pb * lc;
  2792. this.b = pa * lb + pb * ld;
  2793. this.c = pc * la + pd * lc;
  2794. this.d = pc * lb + pd * ld;
  2795. return;
  2796. }
  2797. case spine.TransformMode.OnlyTranslation: {
  2798. var rotationY = rotation + 90 + shearY;
  2799. this.a = spine.MathUtils.cosDeg(rotation + shearX) * scaleX;
  2800. this.b = spine.MathUtils.cosDeg(rotationY) * scaleY;
  2801. this.c = spine.MathUtils.sinDeg(rotation + shearX) * scaleX;
  2802. this.d = spine.MathUtils.sinDeg(rotationY) * scaleY;
  2803. break;
  2804. }
  2805. case spine.TransformMode.NoRotationOrReflection: {
  2806. var s = pa * pa + pc * pc;
  2807. var prx = 0;
  2808. if (s > 0.0001) {
  2809. s = Math.abs(pa * pd - pb * pc) / s;
  2810. pb = pc * s;
  2811. pd = pa * s;
  2812. prx = Math.atan2(pc, pa) * spine.MathUtils.radDeg;
  2813. }
  2814. else {
  2815. pa = 0;
  2816. pc = 0;
  2817. prx = 90 - Math.atan2(pd, pb) * spine.MathUtils.radDeg;
  2818. }
  2819. var rx = rotation + shearX - prx;
  2820. var ry = rotation + shearY - prx + 90;
  2821. var la = spine.MathUtils.cosDeg(rx) * scaleX;
  2822. var lb = spine.MathUtils.cosDeg(ry) * scaleY;
  2823. var lc = spine.MathUtils.sinDeg(rx) * scaleX;
  2824. var ld = spine.MathUtils.sinDeg(ry) * scaleY;
  2825. this.a = pa * la - pb * lc;
  2826. this.b = pa * lb - pb * ld;
  2827. this.c = pc * la + pd * lc;
  2828. this.d = pc * lb + pd * ld;
  2829. break;
  2830. }
  2831. case spine.TransformMode.NoScale:
  2832. case spine.TransformMode.NoScaleOrReflection: {
  2833. var cos = spine.MathUtils.cosDeg(rotation);
  2834. var sin = spine.MathUtils.sinDeg(rotation);
  2835. var za = pa * cos + pb * sin;
  2836. var zc = pc * cos + pd * sin;
  2837. var s = Math.sqrt(za * za + zc * zc);
  2838. if (s > 0.00001)
  2839. s = 1 / s;
  2840. za *= s;
  2841. zc *= s;
  2842. s = Math.sqrt(za * za + zc * zc);
  2843. var r = Math.PI / 2 + Math.atan2(zc, za);
  2844. var zb = Math.cos(r) * s;
  2845. var zd = Math.sin(r) * s;
  2846. var la = spine.MathUtils.cosDeg(shearX) * scaleX;
  2847. var lb = spine.MathUtils.cosDeg(90 + shearY) * scaleY;
  2848. var lc = spine.MathUtils.sinDeg(shearX) * scaleX;
  2849. var ld = spine.MathUtils.sinDeg(90 + shearY) * scaleY;
  2850. this.a = za * la + zb * lc;
  2851. this.b = za * lb + zb * ld;
  2852. this.c = zc * la + zd * lc;
  2853. this.d = zc * lb + zd * ld;
  2854. if (this.data.transformMode != spine.TransformMode.NoScaleOrReflection ? pa * pd - pb * pc < 0 : this.skeleton.flipX != this.skeleton.flipY) {
  2855. this.b = -this.b;
  2856. this.d = -this.d;
  2857. }
  2858. return;
  2859. }
  2860. }
  2861. if (this.skeleton.flipX) {
  2862. this.a = -this.a;
  2863. this.b = -this.b;
  2864. }
  2865. if (this.skeleton.flipY) {
  2866. this.c = -this.c;
  2867. this.d = -this.d;
  2868. }
  2869. };
  2870. Bone.prototype.setToSetupPose = function () {
  2871. var data = this.data;
  2872. this.x = data.x;
  2873. this.y = data.y;
  2874. this.rotation = data.rotation;
  2875. this.scaleX = data.scaleX;
  2876. this.scaleY = data.scaleY;
  2877. this.shearX = data.shearX;
  2878. this.shearY = data.shearY;
  2879. };
  2880. Bone.prototype.getWorldRotationX = function () {
  2881. return Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2882. };
  2883. Bone.prototype.getWorldRotationY = function () {
  2884. return Math.atan2(this.d, this.b) * spine.MathUtils.radDeg;
  2885. };
  2886. Bone.prototype.getWorldScaleX = function () {
  2887. return Math.sqrt(this.a * this.a + this.c * this.c);
  2888. };
  2889. Bone.prototype.getWorldScaleY = function () {
  2890. return Math.sqrt(this.b * this.b + this.d * this.d);
  2891. };
  2892. Bone.prototype.updateAppliedTransform = function () {
  2893. this.appliedValid = true;
  2894. var parent = this.parent;
  2895. if (parent == null) {
  2896. this.ax = this.worldX;
  2897. this.ay = this.worldY;
  2898. this.arotation = Math.atan2(this.c, this.a) * spine.MathUtils.radDeg;
  2899. this.ascaleX = Math.sqrt(this.a * this.a + this.c * this.c);
  2900. this.ascaleY = Math.sqrt(this.b * this.b + this.d * this.d);
  2901. this.ashearX = 0;
  2902. this.ashearY = Math.atan2(this.a * this.b + this.c * this.d, this.a * this.d - this.b * this.c) * spine.MathUtils.radDeg;
  2903. return;
  2904. }
  2905. var pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
  2906. var pid = 1 / (pa * pd - pb * pc);
  2907. var dx = this.worldX - parent.worldX, dy = this.worldY - parent.worldY;
  2908. this.ax = (dx * pd * pid - dy * pb * pid);
  2909. this.ay = (dy * pa * pid - dx * pc * pid);
  2910. var ia = pid * pd;
  2911. var id = pid * pa;
  2912. var ib = pid * pb;
  2913. var ic = pid * pc;
  2914. var ra = ia * this.a - ib * this.c;
  2915. var rb = ia * this.b - ib * this.d;
  2916. var rc = id * this.c - ic * this.a;
  2917. var rd = id * this.d - ic * this.b;
  2918. this.ashearX = 0;
  2919. this.ascaleX = Math.sqrt(ra * ra + rc * rc);
  2920. if (this.ascaleX > 0.0001) {
  2921. var det = ra * rd - rb * rc;
  2922. this.ascaleY = det / this.ascaleX;
  2923. this.ashearY = Math.atan2(ra * rb + rc * rd, det) * spine.MathUtils.radDeg;
  2924. this.arotation = Math.atan2(rc, ra) * spine.MathUtils.radDeg;
  2925. }
  2926. else {
  2927. this.ascaleX = 0;
  2928. this.ascaleY = Math.sqrt(rb * rb + rd * rd);
  2929. this.ashearY = 0;
  2930. this.arotation = 90 - Math.atan2(rd, rb) * spine.MathUtils.radDeg;
  2931. }
  2932. };
  2933. Bone.prototype.worldToLocal = function (world) {
  2934. var a = this.a, b = this.b, c = this.c, d = this.d;
  2935. var invDet = 1 / (a * d - b * c);
  2936. var x = world.x - this.worldX, y = world.y - this.worldY;
  2937. world.x = (x * d * invDet - y * b * invDet);
  2938. world.y = (y * a * invDet - x * c * invDet);
  2939. return world;
  2940. };
  2941. Bone.prototype.localToWorld = function (local) {
  2942. var x = local.x, y = local.y;
  2943. local.x = x * this.a + y * this.b + this.worldX;
  2944. local.y = x * this.c + y * this.d + this.worldY;
  2945. return local;
  2946. };
  2947. Bone.prototype.worldToLocalRotation = function (worldRotation) {
  2948. var sin = spine.MathUtils.sinDeg(worldRotation), cos = spine.MathUtils.cosDeg(worldRotation);
  2949. return Math.atan2(this.a * sin - this.c * cos, this.d * cos - this.b * sin) * spine.MathUtils.radDeg;
  2950. };
  2951. Bone.prototype.localToWorldRotation = function (localRotation) {
  2952. var sin = spine.MathUtils.sinDeg(localRotation), cos = spine.MathUtils.cosDeg(localRotation);
  2953. return Math.atan2(cos * this.c + sin * this.d, cos * this.a + sin * this.b) * spine.MathUtils.radDeg;
  2954. };
  2955. Bone.prototype.rotateWorld = function (degrees) {
  2956. var a = this.a, b = this.b, c = this.c, d = this.d;
  2957. var cos = spine.MathUtils.cosDeg(degrees), sin = spine.MathUtils.sinDeg(degrees);
  2958. this.a = cos * a - sin * c;
  2959. this.b = cos * b - sin * d;
  2960. this.c = sin * a + cos * c;
  2961. this.d = sin * b + cos * d;
  2962. this.appliedValid = false;
  2963. };
  2964. return Bone;
  2965. }());
  2966. spine.Bone = Bone;
  2967. })(spine || (spine = {}));
  2968. var spine;
  2969. (function (spine) {
  2970. var BoneData = (function () {
  2971. function BoneData(index, name, parent) {
  2972. this.x = 0;
  2973. this.y = 0;
  2974. this.rotation = 0;
  2975. this.scaleX = 1;
  2976. this.scaleY = 1;
  2977. this.shearX = 0;
  2978. this.shearY = 0;
  2979. this.transformMode = TransformMode.Normal;
  2980. if (index < 0)
  2981. throw new Error("index must be >= 0.");
  2982. if (name == null)
  2983. throw new Error("name cannot be null.");
  2984. this.index = index;
  2985. this.name = name;
  2986. this.parent = parent;
  2987. }
  2988. return BoneData;
  2989. }());
  2990. spine.BoneData = BoneData;
  2991. (function (TransformMode) {
  2992. TransformMode[TransformMode["Normal"] = 0] = "Normal";
  2993. TransformMode[TransformMode["OnlyTranslation"] = 1] = "OnlyTranslation";
  2994. TransformMode[TransformMode["NoRotationOrReflection"] = 2] = "NoRotationOrReflection";
  2995. TransformMode[TransformMode["NoScale"] = 3] = "NoScale";
  2996. TransformMode[TransformMode["NoScaleOrReflection"] = 4] = "NoScaleOrReflection";
  2997. })(spine.TransformMode || (spine.TransformMode = {}));
  2998. var TransformMode = spine.TransformMode;
  2999. })(spine || (spine = {}));
  3000. var spine;
  3001. (function (spine) {
  3002. var Event = (function () {
  3003. function Event(time, data) {
  3004. if (data == null)
  3005. throw new Error("data cannot be null.");
  3006. this.time = time;
  3007. this.data = data;
  3008. }
  3009. return Event;
  3010. }());
  3011. spine.Event = Event;
  3012. })(spine || (spine = {}));
  3013. var spine;
  3014. (function (spine) {
  3015. var EventData = (function () {
  3016. function EventData(name) {
  3017. this.name = name;
  3018. }
  3019. return EventData;
  3020. }());
  3021. spine.EventData = EventData;
  3022. })(spine || (spine = {}));
  3023. var spine;
  3024. (function (spine) {
  3025. var IkConstraint = (function () {
  3026. function IkConstraint(data, skeleton) {
  3027. this.mix = 1;
  3028. this.bendDirection = 0;
  3029. if (data == null)
  3030. throw new Error("data cannot be null.");
  3031. if (skeleton == null)
  3032. throw new Error("skeleton cannot be null.");
  3033. this.data = data;
  3034. this.mix = data.mix;
  3035. this.bendDirection = data.bendDirection;
  3036. this.bones = new Array();
  3037. for (var i = 0; i < data.bones.length; i++)
  3038. this.bones.push(skeleton.findBone(data.bones[i].name));
  3039. this.target = skeleton.findBone(data.target.name);
  3040. }
  3041. IkConstraint.prototype.getOrder = function () {
  3042. return this.data.order;
  3043. };
  3044. IkConstraint.prototype.apply = function () {
  3045. this.update();
  3046. };
  3047. IkConstraint.prototype.update = function () {
  3048. var target = this.target;
  3049. var bones = this.bones;
  3050. switch (bones.length) {
  3051. case 1:
  3052. this.apply1(bones[0], target.worldX, target.worldY, this.mix);
  3053. break;
  3054. case 2:
  3055. this.apply2(bones[0], bones[1], target.worldX, target.worldY, this.bendDirection, this.mix);
  3056. break;
  3057. }
  3058. };
  3059. IkConstraint.prototype.apply1 = function (bone, targetX, targetY, alpha) {
  3060. if (!bone.appliedValid)
  3061. bone.updateAppliedTransform();
  3062. var p = bone.parent;
  3063. var id = 1 / (p.a * p.d - p.b * p.c);
  3064. var x = targetX - p.worldX, y = targetY - p.worldY;
  3065. var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
  3066. var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
  3067. if (bone.ascaleX < 0)
  3068. rotationIK += 180;
  3069. if (rotationIK > 180)
  3070. rotationIK -= 360;
  3071. else if (rotationIK < -180)
  3072. rotationIK += 360;
  3073. bone.updateWorldTransformWith(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, bone.ascaleX, bone.ascaleY, bone.ashearX, bone.ashearY);
  3074. };
  3075. IkConstraint.prototype.apply2 = function (parent, child, targetX, targetY, bendDir, alpha) {
  3076. if (alpha == 0) {
  3077. child.updateWorldTransform();
  3078. return;
  3079. }
  3080. if (!parent.appliedValid)
  3081. parent.updateAppliedTransform();
  3082. if (!child.appliedValid)
  3083. child.updateAppliedTransform();
  3084. var px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, csx = child.ascaleX;
  3085. var os1 = 0, os2 = 0, s2 = 0;
  3086. if (psx < 0) {
  3087. psx = -psx;
  3088. os1 = 180;
  3089. s2 = -1;
  3090. }
  3091. else {
  3092. os1 = 0;
  3093. s2 = 1;
  3094. }
  3095. if (psy < 0) {
  3096. psy = -psy;
  3097. s2 = -s2;
  3098. }
  3099. if (csx < 0) {
  3100. csx = -csx;
  3101. os2 = 180;
  3102. }
  3103. else
  3104. os2 = 0;
  3105. var cx = child.ax, cy = 0, cwx = 0, cwy = 0, a = parent.a, b = parent.b, c = parent.c, d = parent.d;
  3106. var u = Math.abs(psx - psy) <= 0.0001;
  3107. if (!u) {
  3108. cy = 0;
  3109. cwx = a * cx + parent.worldX;
  3110. cwy = c * cx + parent.worldY;
  3111. }
  3112. else {
  3113. cy = child.ay;
  3114. cwx = a * cx + b * cy + parent.worldX;
  3115. cwy = c * cx + d * cy + parent.worldY;
  3116. }
  3117. var pp = parent.parent;
  3118. a = pp.a;
  3119. b = pp.b;
  3120. c = pp.c;
  3121. d = pp.d;
  3122. var id = 1 / (a * d - b * c), x = targetX - pp.worldX, y = targetY - pp.worldY;
  3123. var tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
  3124. x = cwx - pp.worldX;
  3125. y = cwy - pp.worldY;
  3126. var dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
  3127. var l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1 = 0, a2 = 0;
  3128. outer: if (u) {
  3129. l2 *= psx;
  3130. var cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  3131. if (cos < -1)
  3132. cos = -1;
  3133. else if (cos > 1)
  3134. cos = 1;
  3135. a2 = Math.acos(cos) * bendDir;
  3136. a = l1 + l2 * cos;
  3137. b = l2 * Math.sin(a2);
  3138. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  3139. }
  3140. else {
  3141. a = psx * l2;
  3142. b = psy * l2;
  3143. var aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = Math.atan2(ty, tx);
  3144. c = bb * l1 * l1 + aa * dd - aa * bb;
  3145. var c1 = -2 * bb * l1, c2 = bb - aa;
  3146. d = c1 * c1 - 4 * c2 * c;
  3147. if (d >= 0) {
  3148. var q = Math.sqrt(d);
  3149. if (c1 < 0)
  3150. q = -q;
  3151. q = -(c1 + q) / 2;
  3152. var r0 = q / c2, r1 = c / q;
  3153. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  3154. if (r * r <= dd) {
  3155. y = Math.sqrt(dd - r * r) * bendDir;
  3156. a1 = ta - Math.atan2(y, r);
  3157. a2 = Math.atan2(y / psy, (r - l1) / psx);
  3158. break outer;
  3159. }
  3160. }
  3161. var minAngle = spine.MathUtils.PI, minX = l1 - a, minDist = minX * minX, minY = 0;
  3162. var maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
  3163. c = -a * l1 / (aa - bb);
  3164. if (c >= -1 && c <= 1) {
  3165. c = Math.acos(c);
  3166. x = a * Math.cos(c) + l1;
  3167. y = b * Math.sin(c);
  3168. d = x * x + y * y;
  3169. if (d < minDist) {
  3170. minAngle = c;
  3171. minDist = d;
  3172. minX = x;
  3173. minY = y;
  3174. }
  3175. if (d > maxDist) {
  3176. maxAngle = c;
  3177. maxDist = d;
  3178. maxX = x;
  3179. maxY = y;
  3180. }
  3181. }
  3182. if (dd <= (minDist + maxDist) / 2) {
  3183. a1 = ta - Math.atan2(minY * bendDir, minX);
  3184. a2 = minAngle * bendDir;
  3185. }
  3186. else {
  3187. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  3188. a2 = maxAngle * bendDir;
  3189. }
  3190. }
  3191. var os = Math.atan2(cy, cx) * s2;
  3192. var rotation = parent.arotation;
  3193. a1 = (a1 - os) * spine.MathUtils.radDeg + os1 - rotation;
  3194. if (a1 > 180)
  3195. a1 -= 360;
  3196. else if (a1 < -180)
  3197. a1 += 360;
  3198. parent.updateWorldTransformWith(px, py, rotation + a1 * alpha, parent.ascaleX, parent.ascaleY, 0, 0);
  3199. rotation = child.arotation;
  3200. a2 = ((a2 + os) * spine.MathUtils.radDeg - child.ashearX) * s2 + os2 - rotation;
  3201. if (a2 > 180)
  3202. a2 -= 360;
  3203. else if (a2 < -180)
  3204. a2 += 360;
  3205. child.updateWorldTransformWith(cx, cy, rotation + a2 * alpha, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY);
  3206. };
  3207. return IkConstraint;
  3208. }());
  3209. spine.IkConstraint = IkConstraint;
  3210. })(spine || (spine = {}));
  3211. var spine;
  3212. (function (spine) {
  3213. var IkConstraintData = (function () {
  3214. function IkConstraintData(name) {
  3215. this.order = 0;
  3216. this.bones = new Array();
  3217. this.bendDirection = 1;
  3218. this.mix = 1;
  3219. this.name = name;
  3220. }
  3221. return IkConstraintData;
  3222. }());
  3223. spine.IkConstraintData = IkConstraintData;
  3224. })(spine || (spine = {}));
  3225. var spine;
  3226. (function (spine) {
  3227. var PathConstraint = (function () {
  3228. function PathConstraint(data, skeleton) {
  3229. this.position = 0;
  3230. this.spacing = 0;
  3231. this.rotateMix = 0;
  3232. this.translateMix = 0;
  3233. this.spaces = new Array();
  3234. this.positions = new Array();
  3235. this.world = new Array();
  3236. this.curves = new Array();
  3237. this.lengths = new Array();
  3238. this.segments = new Array();
  3239. if (data == null)
  3240. throw new Error("data cannot be null.");
  3241. if (skeleton == null)
  3242. throw new Error("skeleton cannot be null.");
  3243. this.data = data;
  3244. this.bones = new Array();
  3245. for (var i = 0, n = data.bones.length; i < n; i++)
  3246. this.bones.push(skeleton.findBone(data.bones[i].name));
  3247. this.target = skeleton.findSlot(data.target.name);
  3248. this.position = data.position;
  3249. this.spacing = data.spacing;
  3250. this.rotateMix = data.rotateMix;
  3251. this.translateMix = data.translateMix;
  3252. }
  3253. PathConstraint.prototype.apply = function () {
  3254. this.update();
  3255. };
  3256. PathConstraint.prototype.update = function () {
  3257. var attachment = this.target.getAttachment();
  3258. if (!(attachment instanceof spine.PathAttachment))
  3259. return;
  3260. var rotateMix = this.rotateMix, translateMix = this.translateMix;
  3261. var translate = translateMix > 0, rotate = rotateMix > 0;
  3262. if (!translate && !rotate)
  3263. return;
  3264. var data = this.data;
  3265. var spacingMode = data.spacingMode;
  3266. var lengthSpacing = spacingMode == spine.SpacingMode.Length;
  3267. var rotateMode = data.rotateMode;
  3268. var tangents = rotateMode == spine.RotateMode.Tangent, scale = rotateMode == spine.RotateMode.ChainScale;
  3269. var boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
  3270. var bones = this.bones;
  3271. var spaces = spine.Utils.setArraySize(this.spaces, spacesCount), lengths = null;
  3272. var spacing = this.spacing;
  3273. if (scale || lengthSpacing) {
  3274. if (scale)
  3275. lengths = spine.Utils.setArraySize(this.lengths, boneCount);
  3276. for (var i = 0, n = spacesCount - 1; i < n;) {
  3277. var bone = bones[i];
  3278. var setupLength = bone.data.length, x = setupLength * bone.a, y = setupLength * bone.c;
  3279. var length_1 = Math.sqrt(x * x + y * y);
  3280. if (scale)
  3281. lengths[i] = length_1;
  3282. spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length_1 / setupLength;
  3283. }
  3284. }
  3285. else {
  3286. for (var i = 1; i < spacesCount; i++)
  3287. spaces[i] = spacing;
  3288. }
  3289. var positions = this.computeWorldPositions(attachment, spacesCount, tangents, data.positionMode == spine.PositionMode.Percent, spacingMode == spine.SpacingMode.Percent);
  3290. var boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
  3291. var tip = false;
  3292. if (offsetRotation == 0)
  3293. tip = rotateMode == spine.RotateMode.Chain;
  3294. else {
  3295. tip = false;
  3296. var p = this.target.bone;
  3297. offsetRotation *= p.a * p.d - p.b * p.c > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  3298. }
  3299. for (var i = 0, p = 3; i < boneCount; i++, p += 3) {
  3300. var bone = bones[i];
  3301. bone.worldX += (boneX - bone.worldX) * translateMix;
  3302. bone.worldY += (boneY - bone.worldY) * translateMix;
  3303. var x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
  3304. if (scale) {
  3305. var length_2 = lengths[i];
  3306. if (length_2 != 0) {
  3307. var s = (Math.sqrt(dx * dx + dy * dy) / length_2 - 1) * rotateMix + 1;
  3308. bone.a *= s;
  3309. bone.c *= s;
  3310. }
  3311. }
  3312. boneX = x;
  3313. boneY = y;
  3314. if (rotate) {
  3315. var a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
  3316. if (tangents)
  3317. r = positions[p - 1];
  3318. else if (spaces[i + 1] == 0)
  3319. r = positions[p + 2];
  3320. else
  3321. r = Math.atan2(dy, dx);
  3322. r -= Math.atan2(c, a);
  3323. if (tip) {
  3324. cos = Math.cos(r);
  3325. sin = Math.sin(r);
  3326. var length_3 = bone.data.length;
  3327. boneX += (length_3 * (cos * a - sin * c) - dx) * rotateMix;
  3328. boneY += (length_3 * (sin * a + cos * c) - dy) * rotateMix;
  3329. }
  3330. else {
  3331. r += offsetRotation;
  3332. }
  3333. if (r > spine.MathUtils.PI)
  3334. r -= spine.MathUtils.PI2;
  3335. else if (r < -spine.MathUtils.PI)
  3336. r += spine.MathUtils.PI2;
  3337. r *= rotateMix;
  3338. cos = Math.cos(r);
  3339. sin = Math.sin(r);
  3340. bone.a = cos * a - sin * c;
  3341. bone.b = cos * b - sin * d;
  3342. bone.c = sin * a + cos * c;
  3343. bone.d = sin * b + cos * d;
  3344. }
  3345. bone.appliedValid = false;
  3346. }
  3347. };
  3348. PathConstraint.prototype.computeWorldPositions = function (path, spacesCount, tangents, percentPosition, percentSpacing) {
  3349. var target = this.target;
  3350. var position = this.position;
  3351. var spaces = this.spaces, out = spine.Utils.setArraySize(this.positions, spacesCount * 3 + 2), world = null;
  3352. var closed = path.closed;
  3353. var verticesLength = path.worldVerticesLength, curveCount = verticesLength / 6, prevCurve = PathConstraint.NONE;
  3354. if (!path.constantSpeed) {
  3355. var lengths = path.lengths;
  3356. curveCount -= closed ? 1 : 2;
  3357. var pathLength_1 = lengths[curveCount];
  3358. if (percentPosition)
  3359. position *= pathLength_1;
  3360. if (percentSpacing) {
  3361. for (var i = 0; i < spacesCount; i++)
  3362. spaces[i] *= pathLength_1;
  3363. }
  3364. world = spine.Utils.setArraySize(this.world, 8);
  3365. for (var i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
  3366. var space = spaces[i];
  3367. position += space;
  3368. var p = position;
  3369. if (closed) {
  3370. p %= pathLength_1;
  3371. if (p < 0)
  3372. p += pathLength_1;
  3373. curve = 0;
  3374. }
  3375. else if (p < 0) {
  3376. if (prevCurve != PathConstraint.BEFORE) {
  3377. prevCurve = PathConstraint.BEFORE;
  3378. path.computeWorldVertices(target, 2, 4, world, 0, 2);
  3379. }
  3380. this.addBeforePosition(p, world, 0, out, o);
  3381. continue;
  3382. }
  3383. else if (p > pathLength_1) {
  3384. if (prevCurve != PathConstraint.AFTER) {
  3385. prevCurve = PathConstraint.AFTER;
  3386. path.computeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
  3387. }
  3388. this.addAfterPosition(p - pathLength_1, world, 0, out, o);
  3389. continue;
  3390. }
  3391. for (;; curve++) {
  3392. var length_4 = lengths[curve];
  3393. if (p > length_4)
  3394. continue;
  3395. if (curve == 0)
  3396. p /= length_4;
  3397. else {
  3398. var prev = lengths[curve - 1];
  3399. p = (p - prev) / (length_4 - prev);
  3400. }
  3401. break;
  3402. }
  3403. if (curve != prevCurve) {
  3404. prevCurve = curve;
  3405. if (closed && curve == curveCount) {
  3406. path.computeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
  3407. path.computeWorldVertices(target, 0, 4, world, 4, 2);
  3408. }
  3409. else
  3410. path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
  3411. }
  3412. 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));
  3413. }
  3414. return out;
  3415. }
  3416. if (closed) {
  3417. verticesLength += 2;
  3418. world = spine.Utils.setArraySize(this.world, verticesLength);
  3419. path.computeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
  3420. path.computeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
  3421. world[verticesLength - 2] = world[0];
  3422. world[verticesLength - 1] = world[1];
  3423. }
  3424. else {
  3425. curveCount--;
  3426. verticesLength -= 4;
  3427. world = spine.Utils.setArraySize(this.world, verticesLength);
  3428. path.computeWorldVertices(target, 2, verticesLength, world, 0, 2);
  3429. }
  3430. var curves = spine.Utils.setArraySize(this.curves, curveCount);
  3431. var pathLength = 0;
  3432. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  3433. var tmpx = 0, tmpy = 0, dddfx = 0, dddfy = 0, ddfx = 0, ddfy = 0, dfx = 0, dfy = 0;
  3434. for (var i = 0, w = 2; i < curveCount; i++, w += 6) {
  3435. cx1 = world[w];
  3436. cy1 = world[w + 1];
  3437. cx2 = world[w + 2];
  3438. cy2 = world[w + 3];
  3439. x2 = world[w + 4];
  3440. y2 = world[w + 5];
  3441. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  3442. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  3443. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  3444. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  3445. ddfx = tmpx * 2 + dddfx;
  3446. ddfy = tmpy * 2 + dddfy;
  3447. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  3448. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  3449. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3450. dfx += ddfx;
  3451. dfy += ddfy;
  3452. ddfx += dddfx;
  3453. ddfy += dddfy;
  3454. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3455. dfx += ddfx;
  3456. dfy += ddfy;
  3457. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3458. dfx += ddfx + dddfx;
  3459. dfy += ddfy + dddfy;
  3460. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3461. curves[i] = pathLength;
  3462. x1 = x2;
  3463. y1 = y2;
  3464. }
  3465. if (percentPosition)
  3466. position *= pathLength;
  3467. if (percentSpacing) {
  3468. for (var i = 0; i < spacesCount; i++)
  3469. spaces[i] *= pathLength;
  3470. }
  3471. var segments = this.segments;
  3472. var curveLength = 0;
  3473. for (var i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  3474. var space = spaces[i];
  3475. position += space;
  3476. var p = position;
  3477. if (closed) {
  3478. p %= pathLength;
  3479. if (p < 0)
  3480. p += pathLength;
  3481. curve = 0;
  3482. }
  3483. else if (p < 0) {
  3484. this.addBeforePosition(p, world, 0, out, o);
  3485. continue;
  3486. }
  3487. else if (p > pathLength) {
  3488. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  3489. continue;
  3490. }
  3491. for (;; curve++) {
  3492. var length_5 = curves[curve];
  3493. if (p > length_5)
  3494. continue;
  3495. if (curve == 0)
  3496. p /= length_5;
  3497. else {
  3498. var prev = curves[curve - 1];
  3499. p = (p - prev) / (length_5 - prev);
  3500. }
  3501. break;
  3502. }
  3503. if (curve != prevCurve) {
  3504. prevCurve = curve;
  3505. var ii = curve * 6;
  3506. x1 = world[ii];
  3507. y1 = world[ii + 1];
  3508. cx1 = world[ii + 2];
  3509. cy1 = world[ii + 3];
  3510. cx2 = world[ii + 4];
  3511. cy2 = world[ii + 5];
  3512. x2 = world[ii + 6];
  3513. y2 = world[ii + 7];
  3514. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  3515. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  3516. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  3517. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  3518. ddfx = tmpx * 2 + dddfx;
  3519. ddfy = tmpy * 2 + dddfy;
  3520. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  3521. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  3522. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  3523. segments[0] = curveLength;
  3524. for (ii = 1; ii < 8; ii++) {
  3525. dfx += ddfx;
  3526. dfy += ddfy;
  3527. ddfx += dddfx;
  3528. ddfy += dddfy;
  3529. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3530. segments[ii] = curveLength;
  3531. }
  3532. dfx += ddfx;
  3533. dfy += ddfy;
  3534. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3535. segments[8] = curveLength;
  3536. dfx += ddfx + dddfx;
  3537. dfy += ddfy + dddfy;
  3538. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  3539. segments[9] = curveLength;
  3540. segment = 0;
  3541. }
  3542. p *= curveLength;
  3543. for (;; segment++) {
  3544. var length_6 = segments[segment];
  3545. if (p > length_6)
  3546. continue;
  3547. if (segment == 0)
  3548. p /= length_6;
  3549. else {
  3550. var prev = segments[segment - 1];
  3551. p = segment + (p - prev) / (length_6 - prev);
  3552. }
  3553. break;
  3554. }
  3555. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  3556. }
  3557. return out;
  3558. };
  3559. PathConstraint.prototype.addBeforePosition = function (p, temp, i, out, o) {
  3560. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  3561. out[o] = x1 + p * Math.cos(r);
  3562. out[o + 1] = y1 + p * Math.sin(r);
  3563. out[o + 2] = r;
  3564. };
  3565. PathConstraint.prototype.addAfterPosition = function (p, temp, i, out, o) {
  3566. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  3567. out[o] = x1 + p * Math.cos(r);
  3568. out[o + 1] = y1 + p * Math.sin(r);
  3569. out[o + 2] = r;
  3570. };
  3571. PathConstraint.prototype.addCurvePosition = function (p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  3572. if (p == 0 || isNaN(p))
  3573. p = 0.0001;
  3574. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  3575. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  3576. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  3577. out[o] = x;
  3578. out[o + 1] = y;
  3579. if (tangents)
  3580. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  3581. };
  3582. PathConstraint.prototype.getOrder = function () {
  3583. return this.data.order;
  3584. };
  3585. PathConstraint.NONE = -1;
  3586. PathConstraint.BEFORE = -2;
  3587. PathConstraint.AFTER = -3;
  3588. return PathConstraint;
  3589. }());
  3590. spine.PathConstraint = PathConstraint;
  3591. })(spine || (spine = {}));
  3592. var spine;
  3593. (function (spine) {
  3594. var PathConstraintData = (function () {
  3595. function PathConstraintData(name) {
  3596. this.order = 0;
  3597. this.bones = new Array();
  3598. this.name = name;
  3599. }
  3600. return PathConstraintData;
  3601. }());
  3602. spine.PathConstraintData = PathConstraintData;
  3603. (function (PositionMode) {
  3604. PositionMode[PositionMode["Fixed"] = 0] = "Fixed";
  3605. PositionMode[PositionMode["Percent"] = 1] = "Percent";
  3606. })(spine.PositionMode || (spine.PositionMode = {}));
  3607. var PositionMode = spine.PositionMode;
  3608. (function (SpacingMode) {
  3609. SpacingMode[SpacingMode["Length"] = 0] = "Length";
  3610. SpacingMode[SpacingMode["Fixed"] = 1] = "Fixed";
  3611. SpacingMode[SpacingMode["Percent"] = 2] = "Percent";
  3612. })(spine.SpacingMode || (spine.SpacingMode = {}));
  3613. var SpacingMode = spine.SpacingMode;
  3614. (function (RotateMode) {
  3615. RotateMode[RotateMode["Tangent"] = 0] = "Tangent";
  3616. RotateMode[RotateMode["Chain"] = 1] = "Chain";
  3617. RotateMode[RotateMode["ChainScale"] = 2] = "ChainScale";
  3618. })(spine.RotateMode || (spine.RotateMode = {}));
  3619. var RotateMode = spine.RotateMode;
  3620. })(spine || (spine = {}));
  3621. var spine;
  3622. (function (spine) {
  3623. var Assets = (function () {
  3624. function Assets(clientId) {
  3625. this.toLoad = new Array();
  3626. this.assets = {};
  3627. this.clientId = clientId;
  3628. }
  3629. Assets.prototype.loaded = function () {
  3630. var i = 0;
  3631. for (var v in this.assets)
  3632. i++;
  3633. return i;
  3634. };
  3635. return Assets;
  3636. }());
  3637. var SharedAssetManager = (function () {
  3638. function SharedAssetManager(pathPrefix) {
  3639. if (pathPrefix === void 0) { pathPrefix = ""; }
  3640. this.clientAssets = {};
  3641. this.queuedAssets = {};
  3642. this.rawAssets = {};
  3643. this.errors = {};
  3644. this.pathPrefix = pathPrefix;
  3645. }
  3646. SharedAssetManager.prototype.queueAsset = function (clientId, textureLoader, path) {
  3647. var clientAssets = this.clientAssets[clientId];
  3648. if (clientAssets === null || clientAssets === undefined) {
  3649. clientAssets = new Assets(clientId);
  3650. this.clientAssets[clientId] = clientAssets;
  3651. }
  3652. if (textureLoader !== null)
  3653. clientAssets.textureLoader = textureLoader;
  3654. clientAssets.toLoad.push(path);
  3655. if (this.queuedAssets[path] === path) {
  3656. return false;
  3657. }
  3658. else {
  3659. this.queuedAssets[path] = path;
  3660. return true;
  3661. }
  3662. };
  3663. SharedAssetManager.prototype.loadText = function (clientId, path) {
  3664. var _this = this;
  3665. path = this.pathPrefix + path;
  3666. if (!this.queueAsset(clientId, null, path))
  3667. return;
  3668. var request = new XMLHttpRequest();
  3669. request.onreadystatechange = function () {
  3670. if (request.readyState == XMLHttpRequest.DONE) {
  3671. if (request.status >= 200 && request.status < 300) {
  3672. _this.rawAssets[path] = request.responseText;
  3673. }
  3674. else {
  3675. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3676. }
  3677. }
  3678. };
  3679. request.open("GET", path, true);
  3680. request.send();
  3681. };
  3682. SharedAssetManager.prototype.loadJson = function (clientId, path) {
  3683. var _this = this;
  3684. path = this.pathPrefix + path;
  3685. if (!this.queueAsset(clientId, null, path))
  3686. return;
  3687. var request = new XMLHttpRequest();
  3688. request.onreadystatechange = function () {
  3689. if (request.readyState == XMLHttpRequest.DONE) {
  3690. if (request.status >= 200 && request.status < 300) {
  3691. _this.rawAssets[path] = JSON.parse(request.responseText);
  3692. }
  3693. else {
  3694. _this.errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
  3695. }
  3696. }
  3697. };
  3698. request.open("GET", path, true);
  3699. request.send();
  3700. };
  3701. SharedAssetManager.prototype.loadTexture = function (clientId, textureLoader, path) {
  3702. var _this = this;
  3703. path = this.pathPrefix + path;
  3704. if (!this.queueAsset(clientId, textureLoader, path))
  3705. return;
  3706. var img = new Image();
  3707. img.src = path;
  3708. img.crossOrigin = "anonymous";
  3709. img.onload = function (ev) {
  3710. _this.rawAssets[path] = img;
  3711. };
  3712. img.onerror = function (ev) {
  3713. _this.errors[path] = "Couldn't load image " + path;
  3714. };
  3715. };
  3716. SharedAssetManager.prototype.get = function (clientId, path) {
  3717. path = this.pathPrefix + path;
  3718. var clientAssets = this.clientAssets[clientId];
  3719. if (clientAssets === null || clientAssets === undefined)
  3720. return true;
  3721. return clientAssets.assets[path];
  3722. };
  3723. SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
  3724. for (var i = 0; i < clientAssets.toLoad.length; i++) {
  3725. var path = clientAssets.toLoad[i];
  3726. var asset = clientAssets.assets[path];
  3727. if (asset === null || asset === undefined) {
  3728. var rawAsset = this.rawAssets[path];
  3729. if (rawAsset === null || rawAsset === undefined)
  3730. continue;
  3731. if (rawAsset instanceof HTMLImageElement) {
  3732. clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
  3733. }
  3734. else {
  3735. clientAssets.assets[path] = rawAsset;
  3736. }
  3737. }
  3738. }
  3739. };
  3740. SharedAssetManager.prototype.isLoadingComplete = function (clientId) {
  3741. var clientAssets = this.clientAssets[clientId];
  3742. if (clientAssets === null || clientAssets === undefined)
  3743. return true;
  3744. this.updateClientAssets(clientAssets);
  3745. return clientAssets.toLoad.length == clientAssets.loaded();
  3746. };
  3747. SharedAssetManager.prototype.dispose = function () {
  3748. };
  3749. SharedAssetManager.prototype.hasErrors = function () {
  3750. return Object.keys(this.errors).length > 0;
  3751. };
  3752. SharedAssetManager.prototype.getErrors = function () {
  3753. return this.errors;
  3754. };
  3755. return SharedAssetManager;
  3756. }());
  3757. spine.SharedAssetManager = SharedAssetManager;
  3758. })(spine || (spine = {}));
  3759. var spine;
  3760. (function (spine) {
  3761. var Skeleton = (function () {
  3762. function Skeleton(data) {
  3763. this._updateCache = new Array();
  3764. this.updateCacheReset = new Array();
  3765. this.time = 0;
  3766. this.flipX = false;
  3767. this.flipY = false;
  3768. this.x = 0;
  3769. this.y = 0;
  3770. if (data == null)
  3771. throw new Error("data cannot be null.");
  3772. this.data = data;
  3773. this.bones = new Array();
  3774. for (var i = 0; i < data.bones.length; i++) {
  3775. var boneData = data.bones[i];
  3776. var bone = void 0;
  3777. if (boneData.parent == null)
  3778. bone = new spine.Bone(boneData, this, null);
  3779. else {
  3780. var parent_1 = this.bones[boneData.parent.index];
  3781. bone = new spine.Bone(boneData, this, parent_1);
  3782. parent_1.children.push(bone);
  3783. }
  3784. this.bones.push(bone);
  3785. }
  3786. this.slots = new Array();
  3787. this.drawOrder = new Array();
  3788. for (var i = 0; i < data.slots.length; i++) {
  3789. var slotData = data.slots[i];
  3790. var bone = this.bones[slotData.boneData.index];
  3791. var slot = new spine.Slot(slotData, bone);
  3792. this.slots.push(slot);
  3793. this.drawOrder.push(slot);
  3794. }
  3795. this.ikConstraints = new Array();
  3796. for (var i = 0; i < data.ikConstraints.length; i++) {
  3797. var ikConstraintData = data.ikConstraints[i];
  3798. this.ikConstraints.push(new spine.IkConstraint(ikConstraintData, this));
  3799. }
  3800. this.transformConstraints = new Array();
  3801. for (var i = 0; i < data.transformConstraints.length; i++) {
  3802. var transformConstraintData = data.transformConstraints[i];
  3803. this.transformConstraints.push(new spine.TransformConstraint(transformConstraintData, this));
  3804. }
  3805. this.pathConstraints = new Array();
  3806. for (var i = 0; i < data.pathConstraints.length; i++) {
  3807. var pathConstraintData = data.pathConstraints[i];
  3808. this.pathConstraints.push(new spine.PathConstraint(pathConstraintData, this));
  3809. }
  3810. this.color = new spine.Color(1, 1, 1, 1);
  3811. this.updateCache();
  3812. }
  3813. Skeleton.prototype.updateCache = function () {
  3814. var updateCache = this._updateCache;
  3815. updateCache.length = 0;
  3816. this.updateCacheReset.length = 0;
  3817. var bones = this.bones;
  3818. for (var i = 0, n = bones.length; i < n; i++)
  3819. bones[i].sorted = false;
  3820. var ikConstraints = this.ikConstraints;
  3821. var transformConstraints = this.transformConstraints;
  3822. var pathConstraints = this.pathConstraints;
  3823. var ikCount = ikConstraints.length, transformCount = transformConstraints.length, pathCount = pathConstraints.length;
  3824. var constraintCount = ikCount + transformCount + pathCount;
  3825. outer: for (var i = 0; i < constraintCount; i++) {
  3826. for (var ii = 0; ii < ikCount; ii++) {
  3827. var constraint = ikConstraints[ii];
  3828. if (constraint.data.order == i) {
  3829. this.sortIkConstraint(constraint);
  3830. continue outer;
  3831. }
  3832. }
  3833. for (var ii = 0; ii < transformCount; ii++) {
  3834. var constraint = transformConstraints[ii];
  3835. if (constraint.data.order == i) {
  3836. this.sortTransformConstraint(constraint);
  3837. continue outer;
  3838. }
  3839. }
  3840. for (var ii = 0; ii < pathCount; ii++) {
  3841. var constraint = pathConstraints[ii];
  3842. if (constraint.data.order == i) {
  3843. this.sortPathConstraint(constraint);
  3844. continue outer;
  3845. }
  3846. }
  3847. }
  3848. for (var i = 0, n = bones.length; i < n; i++)
  3849. this.sortBone(bones[i]);
  3850. };
  3851. Skeleton.prototype.sortIkConstraint = function (constraint) {
  3852. var target = constraint.target;
  3853. this.sortBone(target);
  3854. var constrained = constraint.bones;
  3855. var parent = constrained[0];
  3856. this.sortBone(parent);
  3857. if (constrained.length > 1) {
  3858. var child = constrained[constrained.length - 1];
  3859. if (!(this._updateCache.indexOf(child) > -1))
  3860. this.updateCacheReset.push(child);
  3861. }
  3862. this._updateCache.push(constraint);
  3863. this.sortReset(parent.children);
  3864. constrained[constrained.length - 1].sorted = true;
  3865. };
  3866. Skeleton.prototype.sortPathConstraint = function (constraint) {
  3867. var slot = constraint.target;
  3868. var slotIndex = slot.data.index;
  3869. var slotBone = slot.bone;
  3870. if (this.skin != null)
  3871. this.sortPathConstraintAttachment(this.skin, slotIndex, slotBone);
  3872. if (this.data.defaultSkin != null && this.data.defaultSkin != this.skin)
  3873. this.sortPathConstraintAttachment(this.data.defaultSkin, slotIndex, slotBone);
  3874. for (var i = 0, n = this.data.skins.length; i < n; i++)
  3875. this.sortPathConstraintAttachment(this.data.skins[i], slotIndex, slotBone);
  3876. var attachment = slot.getAttachment();
  3877. if (attachment instanceof spine.PathAttachment)
  3878. this.sortPathConstraintAttachmentWith(attachment, slotBone);
  3879. var constrained = constraint.bones;
  3880. var boneCount = constrained.length;
  3881. for (var i = 0; i < boneCount; i++)
  3882. this.sortBone(constrained[i]);
  3883. this._updateCache.push(constraint);
  3884. for (var i = 0; i < boneCount; i++)
  3885. this.sortReset(constrained[i].children);
  3886. for (var i = 0; i < boneCount; i++)
  3887. constrained[i].sorted = true;
  3888. };
  3889. Skeleton.prototype.sortTransformConstraint = function (constraint) {
  3890. this.sortBone(constraint.target);
  3891. var constrained = constraint.bones;
  3892. var boneCount = constrained.length;
  3893. if (constraint.data.local) {
  3894. for (var i = 0; i < boneCount; i++) {
  3895. var child = constrained[i];
  3896. this.sortBone(child.parent);
  3897. if (!(this._updateCache.indexOf(child) > -1))
  3898. this.updateCacheReset.push(child);
  3899. }
  3900. }
  3901. else {
  3902. for (var i = 0; i < boneCount; i++) {
  3903. this.sortBone(constrained[i]);
  3904. }
  3905. }
  3906. this._updateCache.push(constraint);
  3907. for (var ii = 0; ii < boneCount; ii++)
  3908. this.sortReset(constrained[ii].children);
  3909. for (var ii = 0; ii < boneCount; ii++)
  3910. constrained[ii].sorted = true;
  3911. };
  3912. Skeleton.prototype.sortPathConstraintAttachment = function (skin, slotIndex, slotBone) {
  3913. var attachments = skin.attachments[slotIndex];
  3914. if (!attachments)
  3915. return;
  3916. for (var key in attachments) {
  3917. this.sortPathConstraintAttachmentWith(attachments[key], slotBone);
  3918. }
  3919. };
  3920. Skeleton.prototype.sortPathConstraintAttachmentWith = function (attachment, slotBone) {
  3921. if (!(attachment instanceof spine.PathAttachment))
  3922. return;
  3923. var pathBones = attachment.bones;
  3924. if (pathBones == null)
  3925. this.sortBone(slotBone);
  3926. else {
  3927. var bones = this.bones;
  3928. var i = 0;
  3929. while (i < pathBones.length) {
  3930. var boneCount = pathBones[i++];
  3931. for (var n = i + boneCount; i < n; i++) {
  3932. var boneIndex = pathBones[i];
  3933. this.sortBone(bones[boneIndex]);
  3934. }
  3935. }
  3936. }
  3937. };
  3938. Skeleton.prototype.sortBone = function (bone) {
  3939. if (bone.sorted)
  3940. return;
  3941. var parent = bone.parent;
  3942. if (parent != null)
  3943. this.sortBone(parent);
  3944. bone.sorted = true;
  3945. this._updateCache.push(bone);
  3946. };
  3947. Skeleton.prototype.sortReset = function (bones) {
  3948. for (var i = 0, n = bones.length; i < n; i++) {
  3949. var bone = bones[i];
  3950. if (bone.sorted)
  3951. this.sortReset(bone.children);
  3952. bone.sorted = false;
  3953. }
  3954. };
  3955. Skeleton.prototype.updateWorldTransform = function () {
  3956. var updateCacheReset = this.updateCacheReset;
  3957. for (var i = 0, n = updateCacheReset.length; i < n; i++) {
  3958. var bone = updateCacheReset[i];
  3959. bone.ax = bone.x;
  3960. bone.ay = bone.y;
  3961. bone.arotation = bone.rotation;
  3962. bone.ascaleX = bone.scaleX;
  3963. bone.ascaleY = bone.scaleY;
  3964. bone.ashearX = bone.shearX;
  3965. bone.ashearY = bone.shearY;
  3966. bone.appliedValid = true;
  3967. }
  3968. var updateCache = this._updateCache;
  3969. for (var i = 0, n = updateCache.length; i < n; i++)
  3970. updateCache[i].update();
  3971. };
  3972. Skeleton.prototype.setToSetupPose = function () {
  3973. this.setBonesToSetupPose();
  3974. this.setSlotsToSetupPose();
  3975. };
  3976. Skeleton.prototype.setBonesToSetupPose = function () {
  3977. var bones = this.bones;
  3978. for (var i = 0, n = bones.length; i < n; i++)
  3979. bones[i].setToSetupPose();
  3980. var ikConstraints = this.ikConstraints;
  3981. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  3982. var constraint = ikConstraints[i];
  3983. constraint.bendDirection = constraint.data.bendDirection;
  3984. constraint.mix = constraint.data.mix;
  3985. }
  3986. var transformConstraints = this.transformConstraints;
  3987. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  3988. var constraint = transformConstraints[i];
  3989. var data = constraint.data;
  3990. constraint.rotateMix = data.rotateMix;
  3991. constraint.translateMix = data.translateMix;
  3992. constraint.scaleMix = data.scaleMix;
  3993. constraint.shearMix = data.shearMix;
  3994. }
  3995. var pathConstraints = this.pathConstraints;
  3996. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  3997. var constraint = pathConstraints[i];
  3998. var data = constraint.data;
  3999. constraint.position = data.position;
  4000. constraint.spacing = data.spacing;
  4001. constraint.rotateMix = data.rotateMix;
  4002. constraint.translateMix = data.translateMix;
  4003. }
  4004. };
  4005. Skeleton.prototype.setSlotsToSetupPose = function () {
  4006. var slots = this.slots;
  4007. spine.Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
  4008. for (var i = 0, n = slots.length; i < n; i++)
  4009. slots[i].setToSetupPose();
  4010. };
  4011. Skeleton.prototype.getRootBone = function () {
  4012. if (this.bones.length == 0)
  4013. return null;
  4014. return this.bones[0];
  4015. };
  4016. Skeleton.prototype.findBone = function (boneName) {
  4017. if (boneName == null)
  4018. throw new Error("boneName cannot be null.");
  4019. var bones = this.bones;
  4020. for (var i = 0, n = bones.length; i < n; i++) {
  4021. var bone = bones[i];
  4022. if (bone.data.name == boneName)
  4023. return bone;
  4024. }
  4025. return null;
  4026. };
  4027. Skeleton.prototype.findBoneIndex = function (boneName) {
  4028. if (boneName == null)
  4029. throw new Error("boneName cannot be null.");
  4030. var bones = this.bones;
  4031. for (var i = 0, n = bones.length; i < n; i++)
  4032. if (bones[i].data.name == boneName)
  4033. return i;
  4034. return -1;
  4035. };
  4036. Skeleton.prototype.findSlot = function (slotName) {
  4037. if (slotName == null)
  4038. throw new Error("slotName cannot be null.");
  4039. var slots = this.slots;
  4040. for (var i = 0, n = slots.length; i < n; i++) {
  4041. var slot = slots[i];
  4042. if (slot.data.name == slotName)
  4043. return slot;
  4044. }
  4045. return null;
  4046. };
  4047. Skeleton.prototype.findSlotIndex = function (slotName) {
  4048. if (slotName == null)
  4049. throw new Error("slotName cannot be null.");
  4050. var slots = this.slots;
  4051. for (var i = 0, n = slots.length; i < n; i++)
  4052. if (slots[i].data.name == slotName)
  4053. return i;
  4054. return -1;
  4055. };
  4056. Skeleton.prototype.setSkinByName = function (skinName) {
  4057. var skin = this.data.findSkin(skinName);
  4058. if (skin == null)
  4059. throw new Error("Skin not found: " + skinName);
  4060. this.setSkin(skin);
  4061. };
  4062. Skeleton.prototype.setSkin = function (newSkin) {
  4063. if (newSkin != null) {
  4064. if (this.skin != null)
  4065. newSkin.attachAll(this, this.skin);
  4066. else {
  4067. var slots = this.slots;
  4068. for (var i = 0, n = slots.length; i < n; i++) {
  4069. var slot = slots[i];
  4070. var name_1 = slot.data.attachmentName;
  4071. if (name_1 != null) {
  4072. var attachment = newSkin.getAttachment(i, name_1);
  4073. if (attachment != null)
  4074. slot.setAttachment(attachment);
  4075. }
  4076. }
  4077. }
  4078. }
  4079. this.skin = newSkin;
  4080. };
  4081. Skeleton.prototype.getAttachmentByName = function (slotName, attachmentName) {
  4082. return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
  4083. };
  4084. Skeleton.prototype.getAttachment = function (slotIndex, attachmentName) {
  4085. if (attachmentName == null)
  4086. throw new Error("attachmentName cannot be null.");
  4087. if (this.skin != null) {
  4088. var attachment = this.skin.getAttachment(slotIndex, attachmentName);
  4089. if (attachment != null)
  4090. return attachment;
  4091. }
  4092. if (this.data.defaultSkin != null)
  4093. return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
  4094. return null;
  4095. };
  4096. Skeleton.prototype.setAttachment = function (slotName, attachmentName) {
  4097. if (slotName == null)
  4098. throw new Error("slotName cannot be null.");
  4099. var slots = this.slots;
  4100. for (var i = 0, n = slots.length; i < n; i++) {
  4101. var slot = slots[i];
  4102. if (slot.data.name == slotName) {
  4103. var attachment = null;
  4104. if (attachmentName != null) {
  4105. attachment = this.getAttachment(i, attachmentName);
  4106. if (attachment == null)
  4107. throw new Error("Attachment not found: " + attachmentName + ", for slot: " + slotName);
  4108. }
  4109. slot.setAttachment(attachment);
  4110. return;
  4111. }
  4112. }
  4113. throw new Error("Slot not found: " + slotName);
  4114. };
  4115. Skeleton.prototype.findIkConstraint = function (constraintName) {
  4116. if (constraintName == null)
  4117. throw new Error("constraintName cannot be null.");
  4118. var ikConstraints = this.ikConstraints;
  4119. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  4120. var ikConstraint = ikConstraints[i];
  4121. if (ikConstraint.data.name == constraintName)
  4122. return ikConstraint;
  4123. }
  4124. return null;
  4125. };
  4126. Skeleton.prototype.findTransformConstraint = function (constraintName) {
  4127. if (constraintName == null)
  4128. throw new Error("constraintName cannot be null.");
  4129. var transformConstraints = this.transformConstraints;
  4130. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  4131. var constraint = transformConstraints[i];
  4132. if (constraint.data.name == constraintName)
  4133. return constraint;
  4134. }
  4135. return null;
  4136. };
  4137. Skeleton.prototype.findPathConstraint = function (constraintName) {
  4138. if (constraintName == null)
  4139. throw new Error("constraintName cannot be null.");
  4140. var pathConstraints = this.pathConstraints;
  4141. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  4142. var constraint = pathConstraints[i];
  4143. if (constraint.data.name == constraintName)
  4144. return constraint;
  4145. }
  4146. return null;
  4147. };
  4148. Skeleton.prototype.getBounds = function (offset, size, temp) {
  4149. if (offset == null)
  4150. throw new Error("offset cannot be null.");
  4151. if (size == null)
  4152. throw new Error("size cannot be null.");
  4153. var drawOrder = this.drawOrder;
  4154. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  4155. for (var i = 0, n = drawOrder.length; i < n; i++) {
  4156. var slot = drawOrder[i];
  4157. var verticesLength = 0;
  4158. var vertices = null;
  4159. var attachment = slot.getAttachment();
  4160. if (attachment instanceof spine.RegionAttachment) {
  4161. verticesLength = 8;
  4162. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  4163. attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  4164. }
  4165. else if (attachment instanceof spine.MeshAttachment) {
  4166. var mesh = attachment;
  4167. verticesLength = mesh.worldVerticesLength;
  4168. vertices = spine.Utils.setArraySize(temp, verticesLength, 0);
  4169. mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
  4170. }
  4171. if (vertices != null) {
  4172. for (var ii = 0, nn = vertices.length; ii < nn; ii += 2) {
  4173. var x = vertices[ii], y = vertices[ii + 1];
  4174. minX = Math.min(minX, x);
  4175. minY = Math.min(minY, y);
  4176. maxX = Math.max(maxX, x);
  4177. maxY = Math.max(maxY, y);
  4178. }
  4179. }
  4180. }
  4181. offset.set(minX, minY);
  4182. size.set(maxX - minX, maxY - minY);
  4183. };
  4184. Skeleton.prototype.update = function (delta) {
  4185. this.time += delta;
  4186. };
  4187. return Skeleton;
  4188. }());
  4189. spine.Skeleton = Skeleton;
  4190. })(spine || (spine = {}));
  4191. var spine;
  4192. (function (spine) {
  4193. var SkeletonBounds = (function () {
  4194. function SkeletonBounds() {
  4195. this.minX = 0;
  4196. this.minY = 0;
  4197. this.maxX = 0;
  4198. this.maxY = 0;
  4199. this.boundingBoxes = new Array();
  4200. this.polygons = new Array();
  4201. this.polygonPool = new spine.Pool(function () {
  4202. return spine.Utils.newFloatArray(16);
  4203. });
  4204. }
  4205. SkeletonBounds.prototype.update = function (skeleton, updateAabb) {
  4206. if (skeleton == null)
  4207. throw new Error("skeleton cannot be null.");
  4208. var boundingBoxes = this.boundingBoxes;
  4209. var polygons = this.polygons;
  4210. var polygonPool = this.polygonPool;
  4211. var slots = skeleton.slots;
  4212. var slotCount = slots.length;
  4213. boundingBoxes.length = 0;
  4214. polygonPool.freeAll(polygons);
  4215. polygons.length = 0;
  4216. for (var i = 0; i < slotCount; i++) {
  4217. var slot = slots[i];
  4218. var attachment = slot.getAttachment();
  4219. if (attachment instanceof spine.BoundingBoxAttachment) {
  4220. var boundingBox = attachment;
  4221. boundingBoxes.push(boundingBox);
  4222. var polygon = polygonPool.obtain();
  4223. if (polygon.length != boundingBox.worldVerticesLength) {
  4224. polygon = spine.Utils.newFloatArray(boundingBox.worldVerticesLength);
  4225. }
  4226. polygons.push(polygon);
  4227. boundingBox.computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2);
  4228. }
  4229. }
  4230. if (updateAabb) {
  4231. this.aabbCompute();
  4232. }
  4233. else {
  4234. this.minX = Number.POSITIVE_INFINITY;
  4235. this.minY = Number.POSITIVE_INFINITY;
  4236. this.maxX = Number.NEGATIVE_INFINITY;
  4237. this.maxY = Number.NEGATIVE_INFINITY;
  4238. }
  4239. };
  4240. SkeletonBounds.prototype.aabbCompute = function () {
  4241. var minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
  4242. var polygons = this.polygons;
  4243. for (var i = 0, n = polygons.length; i < n; i++) {
  4244. var polygon = polygons[i];
  4245. var vertices = polygon;
  4246. for (var ii = 0, nn = polygon.length; ii < nn; ii += 2) {
  4247. var x = vertices[ii];
  4248. var y = vertices[ii + 1];
  4249. minX = Math.min(minX, x);
  4250. minY = Math.min(minY, y);
  4251. maxX = Math.max(maxX, x);
  4252. maxY = Math.max(maxY, y);
  4253. }
  4254. }
  4255. this.minX = minX;
  4256. this.minY = minY;
  4257. this.maxX = maxX;
  4258. this.maxY = maxY;
  4259. };
  4260. SkeletonBounds.prototype.aabbContainsPoint = function (x, y) {
  4261. return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY;
  4262. };
  4263. SkeletonBounds.prototype.aabbIntersectsSegment = function (x1, y1, x2, y2) {
  4264. var minX = this.minX;
  4265. var minY = this.minY;
  4266. var maxX = this.maxX;
  4267. var maxY = this.maxY;
  4268. if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY))
  4269. return false;
  4270. var m = (y2 - y1) / (x2 - x1);
  4271. var y = m * (minX - x1) + y1;
  4272. if (y > minY && y < maxY)
  4273. return true;
  4274. y = m * (maxX - x1) + y1;
  4275. if (y > minY && y < maxY)
  4276. return true;
  4277. var x = (minY - y1) / m + x1;
  4278. if (x > minX && x < maxX)
  4279. return true;
  4280. x = (maxY - y1) / m + x1;
  4281. if (x > minX && x < maxX)
  4282. return true;
  4283. return false;
  4284. };
  4285. SkeletonBounds.prototype.aabbIntersectsSkeleton = function (bounds) {
  4286. return this.minX < bounds.maxX && this.maxX > bounds.minX && this.minY < bounds.maxY && this.maxY > bounds.minY;
  4287. };
  4288. SkeletonBounds.prototype.containsPoint = function (x, y) {
  4289. var polygons = this.polygons;
  4290. for (var i = 0, n = polygons.length; i < n; i++)
  4291. if (this.containsPointPolygon(polygons[i], x, y))
  4292. return this.boundingBoxes[i];
  4293. return null;
  4294. };
  4295. SkeletonBounds.prototype.containsPointPolygon = function (polygon, x, y) {
  4296. var vertices = polygon;
  4297. var nn = polygon.length;
  4298. var prevIndex = nn - 2;
  4299. var inside = false;
  4300. for (var ii = 0; ii < nn; ii += 2) {
  4301. var vertexY = vertices[ii + 1];
  4302. var prevY = vertices[prevIndex + 1];
  4303. if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
  4304. var vertexX = vertices[ii];
  4305. if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x)
  4306. inside = !inside;
  4307. }
  4308. prevIndex = ii;
  4309. }
  4310. return inside;
  4311. };
  4312. SkeletonBounds.prototype.intersectsSegment = function (x1, y1, x2, y2) {
  4313. var polygons = this.polygons;
  4314. for (var i = 0, n = polygons.length; i < n; i++)
  4315. if (this.intersectsSegmentPolygon(polygons[i], x1, y1, x2, y2))
  4316. return this.boundingBoxes[i];
  4317. return null;
  4318. };
  4319. SkeletonBounds.prototype.intersectsSegmentPolygon = function (polygon, x1, y1, x2, y2) {
  4320. var vertices = polygon;
  4321. var nn = polygon.length;
  4322. var width12 = x1 - x2, height12 = y1 - y2;
  4323. var det1 = x1 * y2 - y1 * x2;
  4324. var x3 = vertices[nn - 2], y3 = vertices[nn - 1];
  4325. for (var ii = 0; ii < nn; ii += 2) {
  4326. var x4 = vertices[ii], y4 = vertices[ii + 1];
  4327. var det2 = x3 * y4 - y3 * x4;
  4328. var width34 = x3 - x4, height34 = y3 - y4;
  4329. var det3 = width12 * height34 - height12 * width34;
  4330. var x = (det1 * width34 - width12 * det2) / det3;
  4331. if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
  4332. var y = (det1 * height34 - height12 * det2) / det3;
  4333. if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1)))
  4334. return true;
  4335. }
  4336. x3 = x4;
  4337. y3 = y4;
  4338. }
  4339. return false;
  4340. };
  4341. SkeletonBounds.prototype.getPolygon = function (boundingBox) {
  4342. if (boundingBox == null)
  4343. throw new Error("boundingBox cannot be null.");
  4344. var index = this.boundingBoxes.indexOf(boundingBox);
  4345. return index == -1 ? null : this.polygons[index];
  4346. };
  4347. SkeletonBounds.prototype.getWidth = function () {
  4348. return this.maxX - this.minX;
  4349. };
  4350. SkeletonBounds.prototype.getHeight = function () {
  4351. return this.maxY - this.minY;
  4352. };
  4353. return SkeletonBounds;
  4354. }());
  4355. spine.SkeletonBounds = SkeletonBounds;
  4356. })(spine || (spine = {}));
  4357. var spine;
  4358. (function (spine) {
  4359. var SkeletonClipping = (function () {
  4360. function SkeletonClipping() {
  4361. this.triangulator = new spine.Triangulator();
  4362. this.clippingPolygon = new Array();
  4363. this.clipOutput = new Array();
  4364. this.clippedVertices = new Array();
  4365. this.clippedTriangles = new Array();
  4366. this.scratch = new Array();
  4367. }
  4368. SkeletonClipping.prototype.clipStart = function (slot, clip) {
  4369. if (this.clipAttachment != null)
  4370. return 0;
  4371. this.clipAttachment = clip;
  4372. var n = clip.worldVerticesLength;
  4373. var vertices = spine.Utils.setArraySize(this.clippingPolygon, n);
  4374. clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
  4375. var clippingPolygon = this.clippingPolygon;
  4376. SkeletonClipping.makeClockwise(clippingPolygon);
  4377. var clippingPolygons = this.clippingPolygons = this.triangulator.decompose(clippingPolygon, this.triangulator.triangulate(clippingPolygon));
  4378. for (var i = 0, n_1 = clippingPolygons.length; i < n_1; i++) {
  4379. var polygon = clippingPolygons[i];
  4380. SkeletonClipping.makeClockwise(polygon);
  4381. polygon.push(polygon[0]);
  4382. polygon.push(polygon[1]);
  4383. }
  4384. return clippingPolygons.length;
  4385. };
  4386. SkeletonClipping.prototype.clipEndWithSlot = function (slot) {
  4387. if (this.clipAttachment != null && this.clipAttachment.endSlot == slot.data)
  4388. this.clipEnd();
  4389. };
  4390. SkeletonClipping.prototype.clipEnd = function () {
  4391. if (this.clipAttachment == null)
  4392. return;
  4393. this.clipAttachment = null;
  4394. this.clippingPolygons = null;
  4395. this.clippedVertices.length = 0;
  4396. this.clippedTriangles.length = 0;
  4397. this.clippingPolygon.length = 0;
  4398. };
  4399. SkeletonClipping.prototype.isClipping = function () {
  4400. return this.clipAttachment != null;
  4401. };
  4402. SkeletonClipping.prototype.clipTriangles = function (vertices, verticesLength, triangles, trianglesLength, uvs, light, dark, twoColor) {
  4403. var clipOutput = this.clipOutput, clippedVertices = this.clippedVertices;
  4404. var clippedTriangles = this.clippedTriangles;
  4405. var polygons = this.clippingPolygons;
  4406. var polygonsCount = this.clippingPolygons.length;
  4407. var vertexSize = twoColor ? 12 : 8;
  4408. var index = 0;
  4409. clippedVertices.length = 0;
  4410. clippedTriangles.length = 0;
  4411. outer: for (var i = 0; i < trianglesLength; i += 3) {
  4412. var vertexOffset = triangles[i] << 1;
  4413. var x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
  4414. var u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
  4415. vertexOffset = triangles[i + 1] << 1;
  4416. var x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
  4417. var u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
  4418. vertexOffset = triangles[i + 2] << 1;
  4419. var x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
  4420. var u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
  4421. for (var p = 0; p < polygonsCount; p++) {
  4422. var s = clippedVertices.length;
  4423. if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) {
  4424. var clipOutputLength = clipOutput.length;
  4425. if (clipOutputLength == 0)
  4426. continue;
  4427. var d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1;
  4428. var d = 1 / (d0 * d2 + d1 * (y1 - y3));
  4429. var clipOutputCount = clipOutputLength >> 1;
  4430. var clipOutputItems = this.clipOutput;
  4431. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + clipOutputCount * vertexSize);
  4432. for (var ii = 0; ii < clipOutputLength; ii += 2) {
  4433. var x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
  4434. clippedVerticesItems[s] = x;
  4435. clippedVerticesItems[s + 1] = y;
  4436. clippedVerticesItems[s + 2] = light.r;
  4437. clippedVerticesItems[s + 3] = light.g;
  4438. clippedVerticesItems[s + 4] = light.b;
  4439. clippedVerticesItems[s + 5] = light.a;
  4440. var c0 = x - x3, c1 = y - y3;
  4441. var a = (d0 * c0 + d1 * c1) * d;
  4442. var b = (d4 * c0 + d2 * c1) * d;
  4443. var c = 1 - a - b;
  4444. clippedVerticesItems[s + 6] = u1 * a + u2 * b + u3 * c;
  4445. clippedVerticesItems[s + 7] = v1 * a + v2 * b + v3 * c;
  4446. if (twoColor) {
  4447. clippedVerticesItems[s + 8] = dark.r;
  4448. clippedVerticesItems[s + 8] = dark.g;
  4449. clippedVerticesItems[s + 10] = dark.b;
  4450. clippedVerticesItems[s + 11] = dark.a;
  4451. }
  4452. s += vertexSize;
  4453. }
  4454. s = clippedTriangles.length;
  4455. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3 * (clipOutputCount - 2));
  4456. clipOutputCount--;
  4457. for (var ii = 1; ii < clipOutputCount; ii++) {
  4458. clippedTrianglesItems[s] = index;
  4459. clippedTrianglesItems[s + 1] = (index + ii);
  4460. clippedTrianglesItems[s + 2] = (index + ii + 1);
  4461. s += 3;
  4462. }
  4463. index += clipOutputCount + 1;
  4464. }
  4465. else {
  4466. var clippedVerticesItems = spine.Utils.setArraySize(clippedVertices, s + 3 * vertexSize);
  4467. clippedVerticesItems[s] = x1;
  4468. clippedVerticesItems[s + 1] = y1;
  4469. clippedVerticesItems[s + 2] = light.r;
  4470. clippedVerticesItems[s + 3] = light.g;
  4471. clippedVerticesItems[s + 4] = light.b;
  4472. clippedVerticesItems[s + 5] = light.a;
  4473. if (!twoColor) {
  4474. clippedVerticesItems[s + 6] = u1;
  4475. clippedVerticesItems[s + 7] = v1;
  4476. clippedVerticesItems[s + 8] = x2;
  4477. clippedVerticesItems[s + 9] = y2;
  4478. clippedVerticesItems[s + 10] = light.r;
  4479. clippedVerticesItems[s + 11] = light.g;
  4480. clippedVerticesItems[s + 12] = light.b;
  4481. clippedVerticesItems[s + 13] = light.a;
  4482. clippedVerticesItems[s + 14] = u2;
  4483. clippedVerticesItems[s + 15] = v2;
  4484. clippedVerticesItems[s + 16] = x3;
  4485. clippedVerticesItems[s + 17] = y3;
  4486. clippedVerticesItems[s + 18] = light.r;
  4487. clippedVerticesItems[s + 19] = light.g;
  4488. clippedVerticesItems[s + 20] = light.b;
  4489. clippedVerticesItems[s + 21] = light.a;
  4490. clippedVerticesItems[s + 22] = u3;
  4491. clippedVerticesItems[s + 23] = v3;
  4492. }
  4493. else {
  4494. clippedVerticesItems[s + 6] = u1;
  4495. clippedVerticesItems[s + 7] = v1;
  4496. clippedVerticesItems[s + 8] = dark.r;
  4497. clippedVerticesItems[s + 9] = dark.g;
  4498. clippedVerticesItems[s + 10] = dark.b;
  4499. clippedVerticesItems[s + 11] = dark.a;
  4500. clippedVerticesItems[s + 12] = x2;
  4501. clippedVerticesItems[s + 13] = y2;
  4502. clippedVerticesItems[s + 14] = light.r;
  4503. clippedVerticesItems[s + 15] = light.g;
  4504. clippedVerticesItems[s + 16] = light.b;
  4505. clippedVerticesItems[s + 17] = light.a;
  4506. clippedVerticesItems[s + 18] = u2;
  4507. clippedVerticesItems[s + 19] = v2;
  4508. clippedVerticesItems[s + 20] = dark.r;
  4509. clippedVerticesItems[s + 21] = dark.g;
  4510. clippedVerticesItems[s + 22] = dark.b;
  4511. clippedVerticesItems[s + 23] = dark.a;
  4512. clippedVerticesItems[s + 24] = x3;
  4513. clippedVerticesItems[s + 25] = y3;
  4514. clippedVerticesItems[s + 26] = light.r;
  4515. clippedVerticesItems[s + 27] = light.g;
  4516. clippedVerticesItems[s + 28] = light.b;
  4517. clippedVerticesItems[s + 29] = light.a;
  4518. clippedVerticesItems[s + 30] = u3;
  4519. clippedVerticesItems[s + 31] = v3;
  4520. clippedVerticesItems[s + 32] = dark.r;
  4521. clippedVerticesItems[s + 33] = dark.g;
  4522. clippedVerticesItems[s + 34] = dark.b;
  4523. clippedVerticesItems[s + 35] = dark.a;
  4524. }
  4525. s = clippedTriangles.length;
  4526. var clippedTrianglesItems = spine.Utils.setArraySize(clippedTriangles, s + 3);
  4527. clippedTrianglesItems[s] = index;
  4528. clippedTrianglesItems[s + 1] = (index + 1);
  4529. clippedTrianglesItems[s + 2] = (index + 2);
  4530. index += 3;
  4531. continue outer;
  4532. }
  4533. }
  4534. }
  4535. };
  4536. SkeletonClipping.prototype.clip = function (x1, y1, x2, y2, x3, y3, clippingArea, output) {
  4537. var originalOutput = output;
  4538. var clipped = false;
  4539. var input = null;
  4540. if (clippingArea.length % 4 >= 2) {
  4541. input = output;
  4542. output = this.scratch;
  4543. }
  4544. else
  4545. input = this.scratch;
  4546. input.length = 0;
  4547. input.push(x1);
  4548. input.push(y1);
  4549. input.push(x2);
  4550. input.push(y2);
  4551. input.push(x3);
  4552. input.push(y3);
  4553. input.push(x1);
  4554. input.push(y1);
  4555. output.length = 0;
  4556. var clippingVertices = clippingArea;
  4557. var clippingVerticesLast = clippingArea.length - 4;
  4558. for (var i = 0;; i += 2) {
  4559. var edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
  4560. var edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
  4561. var deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
  4562. var inputVertices = input;
  4563. var inputVerticesLength = input.length - 2, outputStart = output.length;
  4564. for (var ii = 0; ii < inputVerticesLength; ii += 2) {
  4565. var inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
  4566. var inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
  4567. var side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0;
  4568. if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
  4569. if (side2) {
  4570. output.push(inputX2);
  4571. output.push(inputY2);
  4572. continue;
  4573. }
  4574. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  4575. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
  4576. output.push(edgeX + (edgeX2 - edgeX) * ua);
  4577. output.push(edgeY + (edgeY2 - edgeY) * ua);
  4578. }
  4579. else if (side2) {
  4580. var c0 = inputY2 - inputY, c2 = inputX2 - inputX;
  4581. var ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
  4582. output.push(edgeX + (edgeX2 - edgeX) * ua);
  4583. output.push(edgeY + (edgeY2 - edgeY) * ua);
  4584. output.push(inputX2);
  4585. output.push(inputY2);
  4586. }
  4587. clipped = true;
  4588. }
  4589. if (outputStart == output.length) {
  4590. originalOutput.length = 0;
  4591. return true;
  4592. }
  4593. output.push(output[0]);
  4594. output.push(output[1]);
  4595. if (i == clippingVerticesLast)
  4596. break;
  4597. var temp = output;
  4598. output = input;
  4599. output.length = 0;
  4600. input = temp;
  4601. }
  4602. if (originalOutput != output) {
  4603. originalOutput.length = 0;
  4604. for (var i = 0, n = output.length - 2; i < n; i++)
  4605. originalOutput[i] = output[i];
  4606. }
  4607. else
  4608. originalOutput.length = originalOutput.length - 2;
  4609. return clipped;
  4610. };
  4611. SkeletonClipping.makeClockwise = function (polygon) {
  4612. var vertices = polygon;
  4613. var verticeslength = polygon.length;
  4614. var area = vertices[verticeslength - 2] * vertices[1] - vertices[0] * vertices[verticeslength - 1], p1x = 0, p1y = 0, p2x = 0, p2y = 0;
  4615. for (var i = 0, n = verticeslength - 3; i < n; i += 2) {
  4616. p1x = vertices[i];
  4617. p1y = vertices[i + 1];
  4618. p2x = vertices[i + 2];
  4619. p2y = vertices[i + 3];
  4620. area += p1x * p2y - p2x * p1y;
  4621. }
  4622. if (area < 0)
  4623. return;
  4624. for (var i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
  4625. var x = vertices[i], y = vertices[i + 1];
  4626. var other = lastX - i;
  4627. vertices[i] = vertices[other];
  4628. vertices[i + 1] = vertices[other + 1];
  4629. vertices[other] = x;
  4630. vertices[other + 1] = y;
  4631. }
  4632. };
  4633. return SkeletonClipping;
  4634. }());
  4635. spine.SkeletonClipping = SkeletonClipping;
  4636. })(spine || (spine = {}));
  4637. var spine;
  4638. (function (spine) {
  4639. var SkeletonData = (function () {
  4640. function SkeletonData() {
  4641. this.bones = new Array();
  4642. this.slots = new Array();
  4643. this.skins = new Array();
  4644. this.events = new Array();
  4645. this.animations = new Array();
  4646. this.ikConstraints = new Array();
  4647. this.transformConstraints = new Array();
  4648. this.pathConstraints = new Array();
  4649. this.fps = 0;
  4650. }
  4651. SkeletonData.prototype.findBone = function (boneName) {
  4652. if (boneName == null)
  4653. throw new Error("boneName cannot be null.");
  4654. var bones = this.bones;
  4655. for (var i = 0, n = bones.length; i < n; i++) {
  4656. var bone = bones[i];
  4657. if (bone.name == boneName)
  4658. return bone;
  4659. }
  4660. return null;
  4661. };
  4662. SkeletonData.prototype.findBoneIndex = function (boneName) {
  4663. if (boneName == null)
  4664. throw new Error("boneName cannot be null.");
  4665. var bones = this.bones;
  4666. for (var i = 0, n = bones.length; i < n; i++)
  4667. if (bones[i].name == boneName)
  4668. return i;
  4669. return -1;
  4670. };
  4671. SkeletonData.prototype.findSlot = function (slotName) {
  4672. if (slotName == null)
  4673. throw new Error("slotName cannot be null.");
  4674. var slots = this.slots;
  4675. for (var i = 0, n = slots.length; i < n; i++) {
  4676. var slot = slots[i];
  4677. if (slot.name == slotName)
  4678. return slot;
  4679. }
  4680. return null;
  4681. };
  4682. SkeletonData.prototype.findSlotIndex = function (slotName) {
  4683. if (slotName == null)
  4684. throw new Error("slotName cannot be null.");
  4685. var slots = this.slots;
  4686. for (var i = 0, n = slots.length; i < n; i++)
  4687. if (slots[i].name == slotName)
  4688. return i;
  4689. return -1;
  4690. };
  4691. SkeletonData.prototype.findSkin = function (skinName) {
  4692. if (skinName == null)
  4693. throw new Error("skinName cannot be null.");
  4694. var skins = this.skins;
  4695. for (var i = 0, n = skins.length; i < n; i++) {
  4696. var skin = skins[i];
  4697. if (skin.name == skinName)
  4698. return skin;
  4699. }
  4700. return null;
  4701. };
  4702. SkeletonData.prototype.findEvent = function (eventDataName) {
  4703. if (eventDataName == null)
  4704. throw new Error("eventDataName cannot be null.");
  4705. var events = this.events;
  4706. for (var i = 0, n = events.length; i < n; i++) {
  4707. var event_4 = events[i];
  4708. if (event_4.name == eventDataName)
  4709. return event_4;
  4710. }
  4711. return null;
  4712. };
  4713. SkeletonData.prototype.findAnimation = function (animationName) {
  4714. if (animationName == null)
  4715. throw new Error("animationName cannot be null.");
  4716. var animations = this.animations;
  4717. for (var i = 0, n = animations.length; i < n; i++) {
  4718. var animation = animations[i];
  4719. if (animation.name == animationName)
  4720. return animation;
  4721. }
  4722. return null;
  4723. };
  4724. SkeletonData.prototype.findIkConstraint = function (constraintName) {
  4725. if (constraintName == null)
  4726. throw new Error("constraintName cannot be null.");
  4727. var ikConstraints = this.ikConstraints;
  4728. for (var i = 0, n = ikConstraints.length; i < n; i++) {
  4729. var constraint = ikConstraints[i];
  4730. if (constraint.name == constraintName)
  4731. return constraint;
  4732. }
  4733. return null;
  4734. };
  4735. SkeletonData.prototype.findTransformConstraint = function (constraintName) {
  4736. if (constraintName == null)
  4737. throw new Error("constraintName cannot be null.");
  4738. var transformConstraints = this.transformConstraints;
  4739. for (var i = 0, n = transformConstraints.length; i < n; i++) {
  4740. var constraint = transformConstraints[i];
  4741. if (constraint.name == constraintName)
  4742. return constraint;
  4743. }
  4744. return null;
  4745. };
  4746. SkeletonData.prototype.findPathConstraint = function (constraintName) {
  4747. if (constraintName == null)
  4748. throw new Error("constraintName cannot be null.");
  4749. var pathConstraints = this.pathConstraints;
  4750. for (var i = 0, n = pathConstraints.length; i < n; i++) {
  4751. var constraint = pathConstraints[i];
  4752. if (constraint.name == constraintName)
  4753. return constraint;
  4754. }
  4755. return null;
  4756. };
  4757. SkeletonData.prototype.findPathConstraintIndex = function (pathConstraintName) {
  4758. if (pathConstraintName == null)
  4759. throw new Error("pathConstraintName cannot be null.");
  4760. var pathConstraints = this.pathConstraints;
  4761. for (var i = 0, n = pathConstraints.length; i < n; i++)
  4762. if (pathConstraints[i].name == pathConstraintName)
  4763. return i;
  4764. return -1;
  4765. };
  4766. return SkeletonData;
  4767. }());
  4768. spine.SkeletonData = SkeletonData;
  4769. })(spine || (spine = {}));
  4770. var spine;
  4771. (function (spine) {
  4772. var SkeletonJson = (function () {
  4773. function SkeletonJson(attachmentLoader) {
  4774. this.scale = 1;
  4775. this.linkedMeshes = new Array();
  4776. this.attachmentLoader = attachmentLoader;
  4777. }
  4778. SkeletonJson.prototype.readSkeletonData = function (json) {
  4779. var scale = this.scale;
  4780. var skeletonData = new spine.SkeletonData();
  4781. var root = typeof (json) === "string" ? JSON.parse(json) : json;
  4782. var skeletonMap = root.skeleton;
  4783. if (skeletonMap != null) {
  4784. skeletonData.hash = skeletonMap.hash;
  4785. skeletonData.version = skeletonMap.spine;
  4786. skeletonData.width = skeletonMap.width;
  4787. skeletonData.height = skeletonMap.height;
  4788. skeletonData.fps = skeletonMap.fps;
  4789. skeletonData.imagesPath = skeletonMap.images;
  4790. }
  4791. if (root.bones) {
  4792. for (var i = 0; i < root.bones.length; i++) {
  4793. var boneMap = root.bones[i];
  4794. var parent_2 = null;
  4795. var parentName = this.getValue(boneMap, "parent", null);
  4796. if (parentName != null) {
  4797. parent_2 = skeletonData.findBone(parentName);
  4798. if (parent_2 == null)
  4799. throw new Error("Parent bone not found: " + parentName);
  4800. }
  4801. var data = new spine.BoneData(skeletonData.bones.length, boneMap.name, parent_2);
  4802. data.length = this.getValue(boneMap, "length", 0) * scale;
  4803. data.x = this.getValue(boneMap, "x", 0) * scale;
  4804. data.y = this.getValue(boneMap, "y", 0) * scale;
  4805. data.rotation = this.getValue(boneMap, "rotation", 0);
  4806. data.scaleX = this.getValue(boneMap, "scaleX", 1);
  4807. data.scaleY = this.getValue(boneMap, "scaleY", 1);
  4808. data.shearX = this.getValue(boneMap, "shearX", 0);
  4809. data.shearY = this.getValue(boneMap, "shearY", 0);
  4810. data.transformMode = SkeletonJson.transformModeFromString(this.getValue(boneMap, "transform", "normal"));
  4811. skeletonData.bones.push(data);
  4812. }
  4813. }
  4814. if (root.slots) {
  4815. for (var i = 0; i < root.slots.length; i++) {
  4816. var slotMap = root.slots[i];
  4817. var slotName = slotMap.name;
  4818. var boneName = slotMap.bone;
  4819. var boneData = skeletonData.findBone(boneName);
  4820. if (boneData == null)
  4821. throw new Error("Slot bone not found: " + boneName);
  4822. var data = new spine.SlotData(skeletonData.slots.length, slotName, boneData);
  4823. var color = this.getValue(slotMap, "color", null);
  4824. if (color != null)
  4825. data.color.setFromString(color);
  4826. var dark = this.getValue(slotMap, "dark", null);
  4827. if (dark != null) {
  4828. data.darkColor = new spine.Color(1, 1, 1, 1);
  4829. data.darkColor.setFromString(dark);
  4830. }
  4831. data.attachmentName = this.getValue(slotMap, "attachment", null);
  4832. data.blendMode = SkeletonJson.blendModeFromString(this.getValue(slotMap, "blend", "normal"));
  4833. skeletonData.slots.push(data);
  4834. }
  4835. }
  4836. if (root.ik) {
  4837. for (var i = 0; i < root.ik.length; i++) {
  4838. var constraintMap = root.ik[i];
  4839. var data = new spine.IkConstraintData(constraintMap.name);
  4840. data.order = this.getValue(constraintMap, "order", 0);
  4841. for (var j = 0; j < constraintMap.bones.length; j++) {
  4842. var boneName = constraintMap.bones[j];
  4843. var bone = skeletonData.findBone(boneName);
  4844. if (bone == null)
  4845. throw new Error("IK bone not found: " + boneName);
  4846. data.bones.push(bone);
  4847. }
  4848. var targetName = constraintMap.target;
  4849. data.target = skeletonData.findBone(targetName);
  4850. if (data.target == null)
  4851. throw new Error("IK target bone not found: " + targetName);
  4852. data.bendDirection = this.getValue(constraintMap, "bendPositive", true) ? 1 : -1;
  4853. data.mix = this.getValue(constraintMap, "mix", 1);
  4854. skeletonData.ikConstraints.push(data);
  4855. }
  4856. }
  4857. if (root.transform) {
  4858. for (var i = 0; i < root.transform.length; i++) {
  4859. var constraintMap = root.transform[i];
  4860. var data = new spine.TransformConstraintData(constraintMap.name);
  4861. data.order = this.getValue(constraintMap, "order", 0);
  4862. for (var j = 0; j < constraintMap.bones.length; j++) {
  4863. var boneName = constraintMap.bones[j];
  4864. var bone = skeletonData.findBone(boneName);
  4865. if (bone == null)
  4866. throw new Error("Transform constraint bone not found: " + boneName);
  4867. data.bones.push(bone);
  4868. }
  4869. var targetName = constraintMap.target;
  4870. data.target = skeletonData.findBone(targetName);
  4871. if (data.target == null)
  4872. throw new Error("Transform constraint target bone not found: " + targetName);
  4873. data.local = this.getValue(constraintMap, "local", false);
  4874. data.relative = this.getValue(constraintMap, "relative", false);
  4875. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  4876. data.offsetX = this.getValue(constraintMap, "x", 0) * scale;
  4877. data.offsetY = this.getValue(constraintMap, "y", 0) * scale;
  4878. data.offsetScaleX = this.getValue(constraintMap, "scaleX", 0);
  4879. data.offsetScaleY = this.getValue(constraintMap, "scaleY", 0);
  4880. data.offsetShearY = this.getValue(constraintMap, "shearY", 0);
  4881. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  4882. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  4883. data.scaleMix = this.getValue(constraintMap, "scaleMix", 1);
  4884. data.shearMix = this.getValue(constraintMap, "shearMix", 1);
  4885. skeletonData.transformConstraints.push(data);
  4886. }
  4887. }
  4888. if (root.path) {
  4889. for (var i = 0; i < root.path.length; i++) {
  4890. var constraintMap = root.path[i];
  4891. var data = new spine.PathConstraintData(constraintMap.name);
  4892. data.order = this.getValue(constraintMap, "order", 0);
  4893. for (var j = 0; j < constraintMap.bones.length; j++) {
  4894. var boneName = constraintMap.bones[j];
  4895. var bone = skeletonData.findBone(boneName);
  4896. if (bone == null)
  4897. throw new Error("Transform constraint bone not found: " + boneName);
  4898. data.bones.push(bone);
  4899. }
  4900. var targetName = constraintMap.target;
  4901. data.target = skeletonData.findSlot(targetName);
  4902. if (data.target == null)
  4903. throw new Error("Path target slot not found: " + targetName);
  4904. data.positionMode = SkeletonJson.positionModeFromString(this.getValue(constraintMap, "positionMode", "percent"));
  4905. data.spacingMode = SkeletonJson.spacingModeFromString(this.getValue(constraintMap, "spacingMode", "length"));
  4906. data.rotateMode = SkeletonJson.rotateModeFromString(this.getValue(constraintMap, "rotateMode", "tangent"));
  4907. data.offsetRotation = this.getValue(constraintMap, "rotation", 0);
  4908. data.position = this.getValue(constraintMap, "position", 0);
  4909. if (data.positionMode == spine.PositionMode.Fixed)
  4910. data.position *= scale;
  4911. data.spacing = this.getValue(constraintMap, "spacing", 0);
  4912. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  4913. data.spacing *= scale;
  4914. data.rotateMix = this.getValue(constraintMap, "rotateMix", 1);
  4915. data.translateMix = this.getValue(constraintMap, "translateMix", 1);
  4916. skeletonData.pathConstraints.push(data);
  4917. }
  4918. }
  4919. if (root.skins) {
  4920. for (var skinName in root.skins) {
  4921. var skinMap = root.skins[skinName];
  4922. var skin = new spine.Skin(skinName);
  4923. for (var slotName in skinMap) {
  4924. var slotIndex = skeletonData.findSlotIndex(slotName);
  4925. if (slotIndex == -1)
  4926. throw new Error("Slot not found: " + slotName);
  4927. var slotMap = skinMap[slotName];
  4928. for (var entryName in slotMap) {
  4929. var attachment = this.readAttachment(slotMap[entryName], skin, slotIndex, entryName, skeletonData);
  4930. if (attachment != null)
  4931. skin.addAttachment(slotIndex, entryName, attachment);
  4932. }
  4933. }
  4934. skeletonData.skins.push(skin);
  4935. if (skin.name == "default")
  4936. skeletonData.defaultSkin = skin;
  4937. }
  4938. }
  4939. for (var i = 0, n = this.linkedMeshes.length; i < n; i++) {
  4940. var linkedMesh = this.linkedMeshes[i];
  4941. var skin = linkedMesh.skin == null ? skeletonData.defaultSkin : skeletonData.findSkin(linkedMesh.skin);
  4942. if (skin == null)
  4943. throw new Error("Skin not found: " + linkedMesh.skin);
  4944. var parent_3 = skin.getAttachment(linkedMesh.slotIndex, linkedMesh.parent);
  4945. if (parent_3 == null)
  4946. throw new Error("Parent mesh not found: " + linkedMesh.parent);
  4947. linkedMesh.mesh.setParentMesh(parent_3);
  4948. linkedMesh.mesh.updateUVs();
  4949. }
  4950. this.linkedMeshes.length = 0;
  4951. if (root.events) {
  4952. for (var eventName in root.events) {
  4953. var eventMap = root.events[eventName];
  4954. var data = new spine.EventData(eventName);
  4955. data.intValue = this.getValue(eventMap, "int", 0);
  4956. data.floatValue = this.getValue(eventMap, "float", 0);
  4957. data.stringValue = this.getValue(eventMap, "string", "");
  4958. skeletonData.events.push(data);
  4959. }
  4960. }
  4961. if (root.animations) {
  4962. for (var animationName in root.animations) {
  4963. var animationMap = root.animations[animationName];
  4964. this.readAnimation(animationMap, animationName, skeletonData);
  4965. }
  4966. }
  4967. return skeletonData;
  4968. };
  4969. SkeletonJson.prototype.readAttachment = function (map, skin, slotIndex, name, skeletonData) {
  4970. var scale = this.scale;
  4971. name = this.getValue(map, "name", name);
  4972. var type = this.getValue(map, "type", "region");
  4973. switch (type) {
  4974. case "region": {
  4975. var path = this.getValue(map, "path", name);
  4976. var region = this.attachmentLoader.newRegionAttachment(skin, name, path);
  4977. if (region == null)
  4978. return null;
  4979. region.path = path;
  4980. region.x = this.getValue(map, "x", 0) * scale;
  4981. region.y = this.getValue(map, "y", 0) * scale;
  4982. region.scaleX = this.getValue(map, "scaleX", 1);
  4983. region.scaleY = this.getValue(map, "scaleY", 1);
  4984. region.rotation = this.getValue(map, "rotation", 0);
  4985. region.width = map.width * scale;
  4986. region.height = map.height * scale;
  4987. var color = this.getValue(map, "color", null);
  4988. if (color != null)
  4989. region.color.setFromString(color);
  4990. region.updateOffset();
  4991. return region;
  4992. }
  4993. case "boundingbox": {
  4994. var box = this.attachmentLoader.newBoundingBoxAttachment(skin, name);
  4995. if (box == null)
  4996. return null;
  4997. this.readVertices(map, box, map.vertexCount << 1);
  4998. var color = this.getValue(map, "color", null);
  4999. if (color != null)
  5000. box.color.setFromString(color);
  5001. return box;
  5002. }
  5003. case "mesh":
  5004. case "linkedmesh": {
  5005. var path = this.getValue(map, "path", name);
  5006. var mesh = this.attachmentLoader.newMeshAttachment(skin, name, path);
  5007. if (mesh == null)
  5008. return null;
  5009. mesh.path = path;
  5010. var color = this.getValue(map, "color", null);
  5011. if (color != null)
  5012. mesh.color.setFromString(color);
  5013. var parent_4 = this.getValue(map, "parent", null);
  5014. if (parent_4 != null) {
  5015. mesh.inheritDeform = this.getValue(map, "deform", true);
  5016. this.linkedMeshes.push(new LinkedMesh(mesh, this.getValue(map, "skin", null), slotIndex, parent_4));
  5017. return mesh;
  5018. }
  5019. var uvs = map.uvs;
  5020. this.readVertices(map, mesh, uvs.length);
  5021. mesh.triangles = map.triangles;
  5022. mesh.regionUVs = uvs;
  5023. mesh.updateUVs();
  5024. mesh.hullLength = this.getValue(map, "hull", 0) * 2;
  5025. return mesh;
  5026. }
  5027. case "path": {
  5028. var path = this.attachmentLoader.newPathAttachment(skin, name);
  5029. if (path == null)
  5030. return null;
  5031. path.closed = this.getValue(map, "closed", false);
  5032. path.constantSpeed = this.getValue(map, "constantSpeed", true);
  5033. var vertexCount = map.vertexCount;
  5034. this.readVertices(map, path, vertexCount << 1);
  5035. var lengths = spine.Utils.newArray(vertexCount / 3, 0);
  5036. for (var i = 0; i < map.lengths.length; i++)
  5037. lengths[i] = map.lengths[i] * scale;
  5038. path.lengths = lengths;
  5039. var color = this.getValue(map, "color", null);
  5040. if (color != null)
  5041. path.color.setFromString(color);
  5042. return path;
  5043. }
  5044. case "point": {
  5045. var point = this.attachmentLoader.newPointAttachment(skin, name);
  5046. if (point == null)
  5047. return null;
  5048. point.x = this.getValue(map, "x", 0) * scale;
  5049. point.y = this.getValue(map, "y", 0) * scale;
  5050. point.rotation = this.getValue(map, "rotation", 0);
  5051. var color = this.getValue(map, "color", null);
  5052. if (color != null)
  5053. point.color.setFromString(color);
  5054. return point;
  5055. }
  5056. case "clipping": {
  5057. var clip = this.attachmentLoader.newClippingAttachment(skin, name);
  5058. if (clip == null)
  5059. return null;
  5060. var end = this.getValue(map, "end", null);
  5061. if (end != null) {
  5062. var slot = skeletonData.findSlot(end);
  5063. if (slot == null)
  5064. throw new Error("Clipping end slot not found: " + end);
  5065. clip.endSlot = slot;
  5066. }
  5067. var vertexCount = map.vertexCount;
  5068. this.readVertices(map, clip, vertexCount << 1);
  5069. var color = this.getValue(map, "color", null);
  5070. if (color != null)
  5071. clip.color.setFromString(color);
  5072. return clip;
  5073. }
  5074. }
  5075. return null;
  5076. };
  5077. SkeletonJson.prototype.readVertices = function (map, attachment, verticesLength) {
  5078. var scale = this.scale;
  5079. attachment.worldVerticesLength = verticesLength;
  5080. var vertices = map.vertices;
  5081. if (verticesLength == vertices.length) {
  5082. var scaledVertices = spine.Utils.toFloatArray(vertices);
  5083. if (scale != 1) {
  5084. for (var i = 0, n = vertices.length; i < n; i++)
  5085. scaledVertices[i] *= scale;
  5086. }
  5087. attachment.vertices = scaledVertices;
  5088. return;
  5089. }
  5090. var weights = new Array();
  5091. var bones = new Array();
  5092. for (var i = 0, n = vertices.length; i < n;) {
  5093. var boneCount = vertices[i++];
  5094. bones.push(boneCount);
  5095. for (var nn = i + boneCount * 4; i < nn; i += 4) {
  5096. bones.push(vertices[i]);
  5097. weights.push(vertices[i + 1] * scale);
  5098. weights.push(vertices[i + 2] * scale);
  5099. weights.push(vertices[i + 3]);
  5100. }
  5101. }
  5102. attachment.bones = bones;
  5103. attachment.vertices = spine.Utils.toFloatArray(weights);
  5104. };
  5105. SkeletonJson.prototype.readAnimation = function (map, name, skeletonData) {
  5106. var scale = this.scale;
  5107. var timelines = new Array();
  5108. var duration = 0;
  5109. if (map.slots) {
  5110. for (var slotName in map.slots) {
  5111. var slotMap = map.slots[slotName];
  5112. var slotIndex = skeletonData.findSlotIndex(slotName);
  5113. if (slotIndex == -1)
  5114. throw new Error("Slot not found: " + slotName);
  5115. for (var timelineName in slotMap) {
  5116. var timelineMap = slotMap[timelineName];
  5117. if (timelineName == "attachment") {
  5118. var timeline = new spine.AttachmentTimeline(timelineMap.length);
  5119. timeline.slotIndex = slotIndex;
  5120. var frameIndex = 0;
  5121. for (var i = 0; i < timelineMap.length; i++) {
  5122. var valueMap = timelineMap[i];
  5123. timeline.setFrame(frameIndex++, valueMap.time, valueMap.name);
  5124. }
  5125. timelines.push(timeline);
  5126. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5127. }
  5128. else if (timelineName == "color") {
  5129. var timeline = new spine.ColorTimeline(timelineMap.length);
  5130. timeline.slotIndex = slotIndex;
  5131. var frameIndex = 0;
  5132. for (var i = 0; i < timelineMap.length; i++) {
  5133. var valueMap = timelineMap[i];
  5134. var color = new spine.Color();
  5135. color.setFromString(valueMap.color);
  5136. timeline.setFrame(frameIndex, valueMap.time, color.r, color.g, color.b, color.a);
  5137. this.readCurve(valueMap, timeline, frameIndex);
  5138. frameIndex++;
  5139. }
  5140. timelines.push(timeline);
  5141. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.ColorTimeline.ENTRIES]);
  5142. }
  5143. else if (timelineName == "twoColor") {
  5144. var timeline = new spine.TwoColorTimeline(timelineMap.length);
  5145. timeline.slotIndex = slotIndex;
  5146. var frameIndex = 0;
  5147. for (var i = 0; i < timelineMap.length; i++) {
  5148. var valueMap = timelineMap[i];
  5149. var light = new spine.Color();
  5150. var dark = new spine.Color();
  5151. light.setFromString(valueMap.light);
  5152. dark.setFromString(valueMap.dark);
  5153. timeline.setFrame(frameIndex, valueMap.time, light.r, light.g, light.b, light.a, dark.r, dark.g, dark.b);
  5154. this.readCurve(valueMap, timeline, frameIndex);
  5155. frameIndex++;
  5156. }
  5157. timelines.push(timeline);
  5158. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TwoColorTimeline.ENTRIES]);
  5159. }
  5160. else
  5161. throw new Error("Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")");
  5162. }
  5163. }
  5164. }
  5165. if (map.bones) {
  5166. for (var boneName in map.bones) {
  5167. var boneMap = map.bones[boneName];
  5168. var boneIndex = skeletonData.findBoneIndex(boneName);
  5169. if (boneIndex == -1)
  5170. throw new Error("Bone not found: " + boneName);
  5171. for (var timelineName in boneMap) {
  5172. var timelineMap = boneMap[timelineName];
  5173. if (timelineName === "rotate") {
  5174. var timeline = new spine.RotateTimeline(timelineMap.length);
  5175. timeline.boneIndex = boneIndex;
  5176. var frameIndex = 0;
  5177. for (var i = 0; i < timelineMap.length; i++) {
  5178. var valueMap = timelineMap[i];
  5179. timeline.setFrame(frameIndex, valueMap.time, valueMap.angle);
  5180. this.readCurve(valueMap, timeline, frameIndex);
  5181. frameIndex++;
  5182. }
  5183. timelines.push(timeline);
  5184. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.RotateTimeline.ENTRIES]);
  5185. }
  5186. else if (timelineName === "translate" || timelineName === "scale" || timelineName === "shear") {
  5187. var timeline = null;
  5188. var timelineScale = 1;
  5189. if (timelineName === "scale")
  5190. timeline = new spine.ScaleTimeline(timelineMap.length);
  5191. else if (timelineName === "shear")
  5192. timeline = new spine.ShearTimeline(timelineMap.length);
  5193. else {
  5194. timeline = new spine.TranslateTimeline(timelineMap.length);
  5195. timelineScale = scale;
  5196. }
  5197. timeline.boneIndex = boneIndex;
  5198. var frameIndex = 0;
  5199. for (var i = 0; i < timelineMap.length; i++) {
  5200. var valueMap = timelineMap[i];
  5201. var x = this.getValue(valueMap, "x", 0), y = this.getValue(valueMap, "y", 0);
  5202. timeline.setFrame(frameIndex, valueMap.time, x * timelineScale, y * timelineScale);
  5203. this.readCurve(valueMap, timeline, frameIndex);
  5204. frameIndex++;
  5205. }
  5206. timelines.push(timeline);
  5207. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TranslateTimeline.ENTRIES]);
  5208. }
  5209. else
  5210. throw new Error("Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")");
  5211. }
  5212. }
  5213. }
  5214. if (map.ik) {
  5215. for (var constraintName in map.ik) {
  5216. var constraintMap = map.ik[constraintName];
  5217. var constraint = skeletonData.findIkConstraint(constraintName);
  5218. var timeline = new spine.IkConstraintTimeline(constraintMap.length);
  5219. timeline.ikConstraintIndex = skeletonData.ikConstraints.indexOf(constraint);
  5220. var frameIndex = 0;
  5221. for (var i = 0; i < constraintMap.length; i++) {
  5222. var valueMap = constraintMap[i];
  5223. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "mix", 1), this.getValue(valueMap, "bendPositive", true) ? 1 : -1);
  5224. this.readCurve(valueMap, timeline, frameIndex);
  5225. frameIndex++;
  5226. }
  5227. timelines.push(timeline);
  5228. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.IkConstraintTimeline.ENTRIES]);
  5229. }
  5230. }
  5231. if (map.transform) {
  5232. for (var constraintName in map.transform) {
  5233. var constraintMap = map.transform[constraintName];
  5234. var constraint = skeletonData.findTransformConstraint(constraintName);
  5235. var timeline = new spine.TransformConstraintTimeline(constraintMap.length);
  5236. timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(constraint);
  5237. var frameIndex = 0;
  5238. for (var i = 0; i < constraintMap.length; i++) {
  5239. var valueMap = constraintMap[i];
  5240. 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));
  5241. this.readCurve(valueMap, timeline, frameIndex);
  5242. frameIndex++;
  5243. }
  5244. timelines.push(timeline);
  5245. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.TransformConstraintTimeline.ENTRIES]);
  5246. }
  5247. }
  5248. if (map.paths) {
  5249. for (var constraintName in map.paths) {
  5250. var constraintMap = map.paths[constraintName];
  5251. var index = skeletonData.findPathConstraintIndex(constraintName);
  5252. if (index == -1)
  5253. throw new Error("Path constraint not found: " + constraintName);
  5254. var data = skeletonData.pathConstraints[index];
  5255. for (var timelineName in constraintMap) {
  5256. var timelineMap = constraintMap[timelineName];
  5257. if (timelineName === "position" || timelineName === "spacing") {
  5258. var timeline = null;
  5259. var timelineScale = 1;
  5260. if (timelineName === "spacing") {
  5261. timeline = new spine.PathConstraintSpacingTimeline(timelineMap.length);
  5262. if (data.spacingMode == spine.SpacingMode.Length || data.spacingMode == spine.SpacingMode.Fixed)
  5263. timelineScale = scale;
  5264. }
  5265. else {
  5266. timeline = new spine.PathConstraintPositionTimeline(timelineMap.length);
  5267. if (data.positionMode == spine.PositionMode.Fixed)
  5268. timelineScale = scale;
  5269. }
  5270. timeline.pathConstraintIndex = index;
  5271. var frameIndex = 0;
  5272. for (var i = 0; i < timelineMap.length; i++) {
  5273. var valueMap = timelineMap[i];
  5274. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, timelineName, 0) * timelineScale);
  5275. this.readCurve(valueMap, timeline, frameIndex);
  5276. frameIndex++;
  5277. }
  5278. timelines.push(timeline);
  5279. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintPositionTimeline.ENTRIES]);
  5280. }
  5281. else if (timelineName === "mix") {
  5282. var timeline = new spine.PathConstraintMixTimeline(timelineMap.length);
  5283. timeline.pathConstraintIndex = index;
  5284. var frameIndex = 0;
  5285. for (var i = 0; i < timelineMap.length; i++) {
  5286. var valueMap = timelineMap[i];
  5287. timeline.setFrame(frameIndex, valueMap.time, this.getValue(valueMap, "rotateMix", 1), this.getValue(valueMap, "translateMix", 1));
  5288. this.readCurve(valueMap, timeline, frameIndex);
  5289. frameIndex++;
  5290. }
  5291. timelines.push(timeline);
  5292. duration = Math.max(duration, timeline.frames[(timeline.getFrameCount() - 1) * spine.PathConstraintMixTimeline.ENTRIES]);
  5293. }
  5294. }
  5295. }
  5296. }
  5297. if (map.deform) {
  5298. for (var deformName in map.deform) {
  5299. var deformMap = map.deform[deformName];
  5300. var skin = skeletonData.findSkin(deformName);
  5301. if (skin == null)
  5302. throw new Error("Skin not found: " + deformName);
  5303. for (var slotName in deformMap) {
  5304. var slotMap = deformMap[slotName];
  5305. var slotIndex = skeletonData.findSlotIndex(slotName);
  5306. if (slotIndex == -1)
  5307. throw new Error("Slot not found: " + slotMap.name);
  5308. for (var timelineName in slotMap) {
  5309. var timelineMap = slotMap[timelineName];
  5310. var attachment = skin.getAttachment(slotIndex, timelineName);
  5311. if (attachment == null)
  5312. throw new Error("Deform attachment not found: " + timelineMap.name);
  5313. var weighted = attachment.bones != null;
  5314. var vertices = attachment.vertices;
  5315. var deformLength = weighted ? vertices.length / 3 * 2 : vertices.length;
  5316. var timeline = new spine.DeformTimeline(timelineMap.length);
  5317. timeline.slotIndex = slotIndex;
  5318. timeline.attachment = attachment;
  5319. var frameIndex = 0;
  5320. for (var j = 0; j < timelineMap.length; j++) {
  5321. var valueMap = timelineMap[j];
  5322. var deform = void 0;
  5323. var verticesValue = this.getValue(valueMap, "vertices", null);
  5324. if (verticesValue == null)
  5325. deform = weighted ? spine.Utils.newFloatArray(deformLength) : vertices;
  5326. else {
  5327. deform = spine.Utils.newFloatArray(deformLength);
  5328. var start = this.getValue(valueMap, "offset", 0);
  5329. spine.Utils.arrayCopy(verticesValue, 0, deform, start, verticesValue.length);
  5330. if (scale != 1) {
  5331. for (var i = start, n = i + verticesValue.length; i < n; i++)
  5332. deform[i] *= scale;
  5333. }
  5334. if (!weighted) {
  5335. for (var i = 0; i < deformLength; i++)
  5336. deform[i] += vertices[i];
  5337. }
  5338. }
  5339. timeline.setFrame(frameIndex, valueMap.time, deform);
  5340. this.readCurve(valueMap, timeline, frameIndex);
  5341. frameIndex++;
  5342. }
  5343. timelines.push(timeline);
  5344. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5345. }
  5346. }
  5347. }
  5348. }
  5349. var drawOrderNode = map.drawOrder;
  5350. if (drawOrderNode == null)
  5351. drawOrderNode = map.draworder;
  5352. if (drawOrderNode != null) {
  5353. var timeline = new spine.DrawOrderTimeline(drawOrderNode.length);
  5354. var slotCount = skeletonData.slots.length;
  5355. var frameIndex = 0;
  5356. for (var j = 0; j < drawOrderNode.length; j++) {
  5357. var drawOrderMap = drawOrderNode[j];
  5358. var drawOrder = null;
  5359. var offsets = this.getValue(drawOrderMap, "offsets", null);
  5360. if (offsets != null) {
  5361. drawOrder = spine.Utils.newArray(slotCount, -1);
  5362. var unchanged = spine.Utils.newArray(slotCount - offsets.length, 0);
  5363. var originalIndex = 0, unchangedIndex = 0;
  5364. for (var i = 0; i < offsets.length; i++) {
  5365. var offsetMap = offsets[i];
  5366. var slotIndex = skeletonData.findSlotIndex(offsetMap.slot);
  5367. if (slotIndex == -1)
  5368. throw new Error("Slot not found: " + offsetMap.slot);
  5369. while (originalIndex != slotIndex)
  5370. unchanged[unchangedIndex++] = originalIndex++;
  5371. drawOrder[originalIndex + offsetMap.offset] = originalIndex++;
  5372. }
  5373. while (originalIndex < slotCount)
  5374. unchanged[unchangedIndex++] = originalIndex++;
  5375. for (var i = slotCount - 1; i >= 0; i--)
  5376. if (drawOrder[i] == -1)
  5377. drawOrder[i] = unchanged[--unchangedIndex];
  5378. }
  5379. timeline.setFrame(frameIndex++, drawOrderMap.time, drawOrder);
  5380. }
  5381. timelines.push(timeline);
  5382. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5383. }
  5384. if (map.events) {
  5385. var timeline = new spine.EventTimeline(map.events.length);
  5386. var frameIndex = 0;
  5387. for (var i = 0; i < map.events.length; i++) {
  5388. var eventMap = map.events[i];
  5389. var eventData = skeletonData.findEvent(eventMap.name);
  5390. if (eventData == null)
  5391. throw new Error("Event not found: " + eventMap.name);
  5392. var event_5 = new spine.Event(eventMap.time, eventData);
  5393. event_5.intValue = this.getValue(eventMap, "int", eventData.intValue);
  5394. event_5.floatValue = this.getValue(eventMap, "float", eventData.floatValue);
  5395. event_5.stringValue = this.getValue(eventMap, "string", eventData.stringValue);
  5396. timeline.setFrame(frameIndex++, event_5);
  5397. }
  5398. timelines.push(timeline);
  5399. duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
  5400. }
  5401. if (isNaN(duration)) {
  5402. throw new Error("Error while parsing animation, duration is NaN");
  5403. }
  5404. skeletonData.animations.push(new spine.Animation(name, timelines, duration));
  5405. };
  5406. SkeletonJson.prototype.readCurve = function (map, timeline, frameIndex) {
  5407. if (!map.curve)
  5408. return;
  5409. if (map.curve === "stepped")
  5410. timeline.setStepped(frameIndex);
  5411. else if (Object.prototype.toString.call(map.curve) === '[object Array]') {
  5412. var curve = map.curve;
  5413. timeline.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]);
  5414. }
  5415. };
  5416. SkeletonJson.prototype.getValue = function (map, prop, defaultValue) {
  5417. return map[prop] !== undefined ? map[prop] : defaultValue;
  5418. };
  5419. SkeletonJson.blendModeFromString = function (str) {
  5420. str = str.toLowerCase();
  5421. if (str == "normal")
  5422. return spine.BlendMode.Normal;
  5423. if (str == "additive")
  5424. return spine.BlendMode.Additive;
  5425. if (str == "multiply")
  5426. return spine.BlendMode.Multiply;
  5427. if (str == "screen")
  5428. return spine.BlendMode.Screen;
  5429. throw new Error("Unknown blend mode: " + str);
  5430. };
  5431. SkeletonJson.positionModeFromString = function (str) {
  5432. str = str.toLowerCase();
  5433. if (str == "fixed")
  5434. return spine.PositionMode.Fixed;
  5435. if (str == "percent")
  5436. return spine.PositionMode.Percent;
  5437. throw new Error("Unknown position mode: " + str);
  5438. };
  5439. SkeletonJson.spacingModeFromString = function (str) {
  5440. str = str.toLowerCase();
  5441. if (str == "length")
  5442. return spine.SpacingMode.Length;
  5443. if (str == "fixed")
  5444. return spine.SpacingMode.Fixed;
  5445. if (str == "percent")
  5446. return spine.SpacingMode.Percent;
  5447. throw new Error("Unknown position mode: " + str);
  5448. };
  5449. SkeletonJson.rotateModeFromString = function (str) {
  5450. str = str.toLowerCase();
  5451. if (str == "tangent")
  5452. return spine.RotateMode.Tangent;
  5453. if (str == "chain")
  5454. return spine.RotateMode.Chain;
  5455. if (str == "chainscale")
  5456. return spine.RotateMode.ChainScale;
  5457. throw new Error("Unknown rotate mode: " + str);
  5458. };
  5459. SkeletonJson.transformModeFromString = function (str) {
  5460. str = str.toLowerCase();
  5461. if (str == "normal")
  5462. return spine.TransformMode.Normal;
  5463. if (str == "onlytranslation")
  5464. return spine.TransformMode.OnlyTranslation;
  5465. if (str == "norotationorreflection")
  5466. return spine.TransformMode.NoRotationOrReflection;
  5467. if (str == "noscale")
  5468. return spine.TransformMode.NoScale;
  5469. if (str == "noscaleorreflection")
  5470. return spine.TransformMode.NoScaleOrReflection;
  5471. throw new Error("Unknown transform mode: " + str);
  5472. };
  5473. return SkeletonJson;
  5474. }());
  5475. spine.SkeletonJson = SkeletonJson;
  5476. var LinkedMesh = (function () {
  5477. function LinkedMesh(mesh, skin, slotIndex, parent) {
  5478. this.mesh = mesh;
  5479. this.skin = skin;
  5480. this.slotIndex = slotIndex;
  5481. this.parent = parent;
  5482. }
  5483. return LinkedMesh;
  5484. }());
  5485. })(spine || (spine = {}));
  5486. var spine;
  5487. (function (spine) {
  5488. var Skin = (function () {
  5489. function Skin(name) {
  5490. this.attachments = new Array();
  5491. if (name == null)
  5492. throw new Error("name cannot be null.");
  5493. this.name = name;
  5494. }
  5495. Skin.prototype.addAttachment = function (slotIndex, name, attachment) {
  5496. if (attachment == null)
  5497. throw new Error("attachment cannot be null.");
  5498. var attachments = this.attachments;
  5499. if (slotIndex >= attachments.length)
  5500. attachments.length = slotIndex + 1;
  5501. if (!attachments[slotIndex])
  5502. attachments[slotIndex] = {};
  5503. attachments[slotIndex][name] = attachment;
  5504. };
  5505. Skin.prototype.getAttachment = function (slotIndex, name) {
  5506. var dictionary = this.attachments[slotIndex];
  5507. return dictionary ? dictionary[name] : null;
  5508. };
  5509. Skin.prototype.attachAll = function (skeleton, oldSkin) {
  5510. var slotIndex = 0;
  5511. for (var i = 0; i < skeleton.slots.length; i++) {
  5512. var slot = skeleton.slots[i];
  5513. var slotAttachment = slot.getAttachment();
  5514. if (slotAttachment && slotIndex < oldSkin.attachments.length) {
  5515. var dictionary = oldSkin.attachments[slotIndex];
  5516. for (var key in dictionary) {
  5517. var skinAttachment = dictionary[key];
  5518. if (slotAttachment == skinAttachment) {
  5519. var attachment = this.getAttachment(slotIndex, key);
  5520. if (attachment != null)
  5521. slot.setAttachment(attachment);
  5522. break;
  5523. }
  5524. }
  5525. }
  5526. slotIndex++;
  5527. }
  5528. };
  5529. return Skin;
  5530. }());
  5531. spine.Skin = Skin;
  5532. })(spine || (spine = {}));
  5533. var spine;
  5534. (function (spine) {
  5535. var Slot = (function () {
  5536. function Slot(data, bone) {
  5537. this.attachmentVertices = new Array();
  5538. if (data == null)
  5539. throw new Error("data cannot be null.");
  5540. if (bone == null)
  5541. throw new Error("bone cannot be null.");
  5542. this.data = data;
  5543. this.bone = bone;
  5544. this.color = new spine.Color();
  5545. this.darkColor = data.darkColor == null ? null : new spine.Color();
  5546. this.setToSetupPose();
  5547. }
  5548. Slot.prototype.getAttachment = function () {
  5549. return this.attachment;
  5550. };
  5551. Slot.prototype.setAttachment = function (attachment) {
  5552. if (this.attachment == attachment)
  5553. return;
  5554. this.attachment = attachment;
  5555. this.attachmentTime = this.bone.skeleton.time;
  5556. this.attachmentVertices.length = 0;
  5557. };
  5558. Slot.prototype.setAttachmentTime = function (time) {
  5559. this.attachmentTime = this.bone.skeleton.time - time;
  5560. };
  5561. Slot.prototype.getAttachmentTime = function () {
  5562. return this.bone.skeleton.time - this.attachmentTime;
  5563. };
  5564. Slot.prototype.setToSetupPose = function () {
  5565. this.color.setFromColor(this.data.color);
  5566. if (this.darkColor != null)
  5567. this.darkColor.setFromColor(this.data.darkColor);
  5568. if (this.data.attachmentName == null)
  5569. this.attachment = null;
  5570. else {
  5571. this.attachment = null;
  5572. this.setAttachment(this.bone.skeleton.getAttachment(this.data.index, this.data.attachmentName));
  5573. }
  5574. };
  5575. return Slot;
  5576. }());
  5577. spine.Slot = Slot;
  5578. })(spine || (spine = {}));
  5579. var spine;
  5580. (function (spine) {
  5581. var SlotData = (function () {
  5582. function SlotData(index, name, boneData) {
  5583. this.color = new spine.Color(1, 1, 1, 1);
  5584. if (index < 0)
  5585. throw new Error("index must be >= 0.");
  5586. if (name == null)
  5587. throw new Error("name cannot be null.");
  5588. if (boneData == null)
  5589. throw new Error("boneData cannot be null.");
  5590. this.index = index;
  5591. this.name = name;
  5592. this.boneData = boneData;
  5593. }
  5594. return SlotData;
  5595. }());
  5596. spine.SlotData = SlotData;
  5597. })(spine || (spine = {}));
  5598. var spine;
  5599. (function (spine) {
  5600. var TextureAtlas = (function () {
  5601. function TextureAtlas(atlasText, textureLoader) {
  5602. this.pages = new Array();
  5603. this.regions = new Array();
  5604. this.load(atlasText, textureLoader);
  5605. }
  5606. TextureAtlas.prototype.load = function (atlasText, textureLoader) {
  5607. if (textureLoader == null)
  5608. throw new Error("textureLoader cannot be null.");
  5609. var reader = new TextureAtlasReader(atlasText);
  5610. var tuple = new Array(4);
  5611. var page = null;
  5612. while (true) {
  5613. var line = reader.readLine();
  5614. if (line == null)
  5615. break;
  5616. line = line.trim();
  5617. if (line.length == 0)
  5618. page = null;
  5619. else if (!page) {
  5620. page = new TextureAtlasPage();
  5621. page.name = line;
  5622. if (reader.readTuple(tuple) == 2) {
  5623. page.width = parseInt(tuple[0]);
  5624. page.height = parseInt(tuple[1]);
  5625. reader.readTuple(tuple);
  5626. }
  5627. reader.readTuple(tuple);
  5628. page.minFilter = spine.Texture.filterFromString(tuple[0]);
  5629. page.magFilter = spine.Texture.filterFromString(tuple[1]);
  5630. var direction = reader.readValue();
  5631. page.uWrap = spine.TextureWrap.ClampToEdge;
  5632. page.vWrap = spine.TextureWrap.ClampToEdge;
  5633. if (direction == "x")
  5634. page.uWrap = spine.TextureWrap.Repeat;
  5635. else if (direction == "y")
  5636. page.vWrap = spine.TextureWrap.Repeat;
  5637. else if (direction == "xy")
  5638. page.uWrap = page.vWrap = spine.TextureWrap.Repeat;
  5639. page.texture = textureLoader(line);
  5640. page.texture.setFilters(page.minFilter, page.magFilter);
  5641. page.texture.setWraps(page.uWrap, page.vWrap);
  5642. page.width = page.texture.getImage().width;
  5643. page.height = page.texture.getImage().height;
  5644. this.pages.push(page);
  5645. }
  5646. else {
  5647. var region = new TextureAtlasRegion();
  5648. region.name = line;
  5649. region.page = page;
  5650. region.rotate = reader.readValue() == "true";
  5651. reader.readTuple(tuple);
  5652. var x = parseInt(tuple[0]);
  5653. var y = parseInt(tuple[1]);
  5654. reader.readTuple(tuple);
  5655. var width = parseInt(tuple[0]);
  5656. var height = parseInt(tuple[1]);
  5657. region.u = x / page.width;
  5658. region.v = y / page.height;
  5659. if (region.rotate) {
  5660. region.u2 = (x + height) / page.width;
  5661. region.v2 = (y + width) / page.height;
  5662. }
  5663. else {
  5664. region.u2 = (x + width) / page.width;
  5665. region.v2 = (y + height) / page.height;
  5666. }
  5667. region.x = x;
  5668. region.y = y;
  5669. region.width = Math.abs(width);
  5670. region.height = Math.abs(height);
  5671. if (reader.readTuple(tuple) == 4) {
  5672. if (reader.readTuple(tuple) == 4) {
  5673. reader.readTuple(tuple);
  5674. }
  5675. }
  5676. region.originalWidth = parseInt(tuple[0]);
  5677. region.originalHeight = parseInt(tuple[1]);
  5678. reader.readTuple(tuple);
  5679. region.offsetX = parseInt(tuple[0]);
  5680. region.offsetY = parseInt(tuple[1]);
  5681. region.index = parseInt(reader.readValue());
  5682. region.texture = page.texture;
  5683. this.regions.push(region);
  5684. }
  5685. }
  5686. };
  5687. TextureAtlas.prototype.findRegion = function (name) {
  5688. for (var i = 0; i < this.regions.length; i++) {
  5689. if (this.regions[i].name == name) {
  5690. return this.regions[i];
  5691. }
  5692. }
  5693. return null;
  5694. };
  5695. TextureAtlas.prototype.dispose = function () {
  5696. for (var i = 0; i < this.pages.length; i++) {
  5697. this.pages[i].texture.dispose();
  5698. }
  5699. };
  5700. return TextureAtlas;
  5701. }());
  5702. spine.TextureAtlas = TextureAtlas;
  5703. var TextureAtlasReader = (function () {
  5704. function TextureAtlasReader(text) {
  5705. this.index = 0;
  5706. this.lines = text.split(/\r\n|\r|\n/);
  5707. }
  5708. TextureAtlasReader.prototype.readLine = function () {
  5709. if (this.index >= this.lines.length)
  5710. return null;
  5711. return this.lines[this.index++];
  5712. };
  5713. TextureAtlasReader.prototype.readValue = function () {
  5714. var line = this.readLine();
  5715. var colon = line.indexOf(":");
  5716. if (colon == -1)
  5717. throw new Error("Invalid line: " + line);
  5718. return line.substring(colon + 1).trim();
  5719. };
  5720. TextureAtlasReader.prototype.readTuple = function (tuple) {
  5721. var line = this.readLine();
  5722. var colon = line.indexOf(":");
  5723. if (colon == -1)
  5724. throw new Error("Invalid line: " + line);
  5725. var i = 0, lastMatch = colon + 1;
  5726. for (; i < 3; i++) {
  5727. var comma = line.indexOf(",", lastMatch);
  5728. if (comma == -1)
  5729. break;
  5730. tuple[i] = line.substr(lastMatch, comma - lastMatch).trim();
  5731. lastMatch = comma + 1;
  5732. }
  5733. tuple[i] = line.substring(lastMatch).trim();
  5734. return i + 1;
  5735. };
  5736. return TextureAtlasReader;
  5737. }());
  5738. var TextureAtlasPage = (function () {
  5739. function TextureAtlasPage() {
  5740. }
  5741. return TextureAtlasPage;
  5742. }());
  5743. spine.TextureAtlasPage = TextureAtlasPage;
  5744. var TextureAtlasRegion = (function (_super) {
  5745. __extends(TextureAtlasRegion, _super);
  5746. function TextureAtlasRegion() {
  5747. _super.apply(this, arguments);
  5748. }
  5749. return TextureAtlasRegion;
  5750. }(spine.TextureRegion));
  5751. spine.TextureAtlasRegion = TextureAtlasRegion;
  5752. })(spine || (spine = {}));
  5753. var spine;
  5754. (function (spine) {
  5755. var TransformConstraint = (function () {
  5756. function TransformConstraint(data, skeleton) {
  5757. this.rotateMix = 0;
  5758. this.translateMix = 0;
  5759. this.scaleMix = 0;
  5760. this.shearMix = 0;
  5761. this.temp = new spine.Vector2();
  5762. if (data == null)
  5763. throw new Error("data cannot be null.");
  5764. if (skeleton == null)
  5765. throw new Error("skeleton cannot be null.");
  5766. this.data = data;
  5767. this.rotateMix = data.rotateMix;
  5768. this.translateMix = data.translateMix;
  5769. this.scaleMix = data.scaleMix;
  5770. this.shearMix = data.shearMix;
  5771. this.bones = new Array();
  5772. for (var i = 0; i < data.bones.length; i++)
  5773. this.bones.push(skeleton.findBone(data.bones[i].name));
  5774. this.target = skeleton.findBone(data.target.name);
  5775. }
  5776. TransformConstraint.prototype.apply = function () {
  5777. this.update();
  5778. };
  5779. TransformConstraint.prototype.update = function () {
  5780. if (this.data.local) {
  5781. if (this.data.relative)
  5782. this.applyRelativeLocal();
  5783. else
  5784. this.applyAbsoluteLocal();
  5785. }
  5786. else {
  5787. if (this.data.relative)
  5788. this.applyRelativeWorld();
  5789. else
  5790. this.applyAbsoluteWorld();
  5791. }
  5792. };
  5793. TransformConstraint.prototype.applyAbsoluteWorld = function () {
  5794. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5795. var target = this.target;
  5796. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  5797. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  5798. var offsetRotation = this.data.offsetRotation * degRadReflect;
  5799. var offsetShearY = this.data.offsetShearY * degRadReflect;
  5800. var bones = this.bones;
  5801. for (var i = 0, n = bones.length; i < n; i++) {
  5802. var bone = bones[i];
  5803. var modified = false;
  5804. if (rotateMix != 0) {
  5805. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  5806. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
  5807. if (r > spine.MathUtils.PI)
  5808. r -= spine.MathUtils.PI2;
  5809. else if (r < -spine.MathUtils.PI)
  5810. r += spine.MathUtils.PI2;
  5811. r *= rotateMix;
  5812. var cos = Math.cos(r), sin = Math.sin(r);
  5813. bone.a = cos * a - sin * c;
  5814. bone.b = cos * b - sin * d;
  5815. bone.c = sin * a + cos * c;
  5816. bone.d = sin * b + cos * d;
  5817. modified = true;
  5818. }
  5819. if (translateMix != 0) {
  5820. var temp = this.temp;
  5821. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  5822. bone.worldX += (temp.x - bone.worldX) * translateMix;
  5823. bone.worldY += (temp.y - bone.worldY) * translateMix;
  5824. modified = true;
  5825. }
  5826. if (scaleMix > 0) {
  5827. var s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
  5828. var ts = Math.sqrt(ta * ta + tc * tc);
  5829. if (s > 0.00001)
  5830. s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
  5831. bone.a *= s;
  5832. bone.c *= s;
  5833. s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
  5834. ts = Math.sqrt(tb * tb + td * td);
  5835. if (s > 0.00001)
  5836. s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
  5837. bone.b *= s;
  5838. bone.d *= s;
  5839. modified = true;
  5840. }
  5841. if (shearMix > 0) {
  5842. var b = bone.b, d = bone.d;
  5843. var by = Math.atan2(d, b);
  5844. var r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
  5845. if (r > spine.MathUtils.PI)
  5846. r -= spine.MathUtils.PI2;
  5847. else if (r < -spine.MathUtils.PI)
  5848. r += spine.MathUtils.PI2;
  5849. r = by + (r + offsetShearY) * shearMix;
  5850. var s = Math.sqrt(b * b + d * d);
  5851. bone.b = Math.cos(r) * s;
  5852. bone.d = Math.sin(r) * s;
  5853. modified = true;
  5854. }
  5855. if (modified)
  5856. bone.appliedValid = false;
  5857. }
  5858. };
  5859. TransformConstraint.prototype.applyRelativeWorld = function () {
  5860. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5861. var target = this.target;
  5862. var ta = target.a, tb = target.b, tc = target.c, td = target.d;
  5863. var degRadReflect = ta * td - tb * tc > 0 ? spine.MathUtils.degRad : -spine.MathUtils.degRad;
  5864. var offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
  5865. var bones = this.bones;
  5866. for (var i = 0, n = bones.length; i < n; i++) {
  5867. var bone = bones[i];
  5868. var modified = false;
  5869. if (rotateMix != 0) {
  5870. var a = bone.a, b = bone.b, c = bone.c, d = bone.d;
  5871. var r = Math.atan2(tc, ta) + offsetRotation;
  5872. if (r > spine.MathUtils.PI)
  5873. r -= spine.MathUtils.PI2;
  5874. else if (r < -spine.MathUtils.PI)
  5875. r += spine.MathUtils.PI2;
  5876. r *= rotateMix;
  5877. var cos = Math.cos(r), sin = Math.sin(r);
  5878. bone.a = cos * a - sin * c;
  5879. bone.b = cos * b - sin * d;
  5880. bone.c = sin * a + cos * c;
  5881. bone.d = sin * b + cos * d;
  5882. modified = true;
  5883. }
  5884. if (translateMix != 0) {
  5885. var temp = this.temp;
  5886. target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
  5887. bone.worldX += temp.x * translateMix;
  5888. bone.worldY += temp.y * translateMix;
  5889. modified = true;
  5890. }
  5891. if (scaleMix > 0) {
  5892. var s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
  5893. bone.a *= s;
  5894. bone.c *= s;
  5895. s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
  5896. bone.b *= s;
  5897. bone.d *= s;
  5898. modified = true;
  5899. }
  5900. if (shearMix > 0) {
  5901. var r = Math.atan2(td, tb) - Math.atan2(tc, ta);
  5902. if (r > spine.MathUtils.PI)
  5903. r -= spine.MathUtils.PI2;
  5904. else if (r < -spine.MathUtils.PI)
  5905. r += spine.MathUtils.PI2;
  5906. var b = bone.b, d = bone.d;
  5907. r = Math.atan2(d, b) + (r - spine.MathUtils.PI / 2 + offsetShearY) * shearMix;
  5908. var s = Math.sqrt(b * b + d * d);
  5909. bone.b = Math.cos(r) * s;
  5910. bone.d = Math.sin(r) * s;
  5911. modified = true;
  5912. }
  5913. if (modified)
  5914. bone.appliedValid = false;
  5915. }
  5916. };
  5917. TransformConstraint.prototype.applyAbsoluteLocal = function () {
  5918. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5919. var target = this.target;
  5920. if (!target.appliedValid)
  5921. target.updateAppliedTransform();
  5922. var bones = this.bones;
  5923. for (var i = 0, n = bones.length; i < n; i++) {
  5924. var bone = bones[i];
  5925. if (!bone.appliedValid)
  5926. bone.updateAppliedTransform();
  5927. var rotation = bone.arotation;
  5928. if (rotateMix != 0) {
  5929. var r = target.arotation - rotation + this.data.offsetRotation;
  5930. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  5931. rotation += r * rotateMix;
  5932. }
  5933. var x = bone.ax, y = bone.ay;
  5934. if (translateMix != 0) {
  5935. x += (target.ax - x + this.data.offsetX) * translateMix;
  5936. y += (target.ay - y + this.data.offsetY) * translateMix;
  5937. }
  5938. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  5939. if (scaleMix > 0) {
  5940. if (scaleX > 0.00001)
  5941. scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
  5942. if (scaleY > 0.00001)
  5943. scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
  5944. }
  5945. var shearY = bone.ashearY;
  5946. if (shearMix > 0) {
  5947. var r = target.ashearY - shearY + this.data.offsetShearY;
  5948. r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
  5949. bone.shearY += r * shearMix;
  5950. }
  5951. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  5952. }
  5953. };
  5954. TransformConstraint.prototype.applyRelativeLocal = function () {
  5955. var rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
  5956. var target = this.target;
  5957. if (!target.appliedValid)
  5958. target.updateAppliedTransform();
  5959. var bones = this.bones;
  5960. for (var i = 0, n = bones.length; i < n; i++) {
  5961. var bone = bones[i];
  5962. if (!bone.appliedValid)
  5963. bone.updateAppliedTransform();
  5964. var rotation = bone.arotation;
  5965. if (rotateMix != 0)
  5966. rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
  5967. var x = bone.ax, y = bone.ay;
  5968. if (translateMix != 0) {
  5969. x += (target.ax + this.data.offsetX) * translateMix;
  5970. y += (target.ay + this.data.offsetY) * translateMix;
  5971. }
  5972. var scaleX = bone.ascaleX, scaleY = bone.ascaleY;
  5973. if (scaleMix > 0) {
  5974. if (scaleX > 0.00001)
  5975. scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
  5976. if (scaleY > 0.00001)
  5977. scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
  5978. }
  5979. var shearY = bone.ashearY;
  5980. if (shearMix > 0)
  5981. shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
  5982. bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
  5983. }
  5984. };
  5985. TransformConstraint.prototype.getOrder = function () {
  5986. return this.data.order;
  5987. };
  5988. return TransformConstraint;
  5989. }());
  5990. spine.TransformConstraint = TransformConstraint;
  5991. })(spine || (spine = {}));
  5992. var spine;
  5993. (function (spine) {
  5994. var TransformConstraintData = (function () {
  5995. function TransformConstraintData(name) {
  5996. this.order = 0;
  5997. this.bones = new Array();
  5998. this.rotateMix = 0;
  5999. this.translateMix = 0;
  6000. this.scaleMix = 0;
  6001. this.shearMix = 0;
  6002. this.offsetRotation = 0;
  6003. this.offsetX = 0;
  6004. this.offsetY = 0;
  6005. this.offsetScaleX = 0;
  6006. this.offsetScaleY = 0;
  6007. this.offsetShearY = 0;
  6008. this.relative = false;
  6009. this.local = false;
  6010. if (name == null)
  6011. throw new Error("name cannot be null.");
  6012. this.name = name;
  6013. }
  6014. return TransformConstraintData;
  6015. }());
  6016. spine.TransformConstraintData = TransformConstraintData;
  6017. })(spine || (spine = {}));
  6018. var spine;
  6019. (function (spine) {
  6020. var Triangulator = (function () {
  6021. function Triangulator() {
  6022. this.convexPolygons = new Array();
  6023. this.convexPolygonsIndices = new Array();
  6024. this.indicesArray = new Array();
  6025. this.isConcaveArray = new Array();
  6026. this.triangles = new Array();
  6027. this.polygonPool = new spine.Pool(function () {
  6028. return new Array();
  6029. });
  6030. this.polygonIndicesPool = new spine.Pool(function () {
  6031. return new Array();
  6032. });
  6033. }
  6034. Triangulator.prototype.triangulate = function (verticesArray) {
  6035. var vertices = verticesArray;
  6036. var vertexCount = verticesArray.length >> 1;
  6037. var indices = this.indicesArray;
  6038. indices.length = 0;
  6039. for (var i = 0; i < vertexCount; i++)
  6040. indices[i] = i;
  6041. var isConcave = this.isConcaveArray;
  6042. isConcave.length = 0;
  6043. for (var i = 0, n = vertexCount; i < n; ++i)
  6044. isConcave[i] = Triangulator.isConcave(i, vertexCount, vertices, indices);
  6045. var triangles = this.triangles;
  6046. triangles.length = 0;
  6047. while (vertexCount > 3) {
  6048. var previous = vertexCount - 1, i = 0, next = 1;
  6049. while (true) {
  6050. outer: if (!isConcave[i]) {
  6051. var p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1;
  6052. var p1x = vertices[p1], p1y = vertices[p1 + 1];
  6053. var p2x = vertices[p2], p2y = vertices[p2 + 1];
  6054. var p3x = vertices[p3], p3y = vertices[p3 + 1];
  6055. for (var ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) {
  6056. if (!isConcave[ii])
  6057. continue;
  6058. var v = indices[ii] << 1;
  6059. var vx = vertices[v], vy = vertices[v + 1];
  6060. if (Triangulator.positiveArea(p3x, p3y, p1x, p1y, vx, vy)) {
  6061. if (Triangulator.positiveArea(p1x, p1y, p2x, p2y, vx, vy)) {
  6062. if (Triangulator.positiveArea(p2x, p2y, p3x, p3y, vx, vy))
  6063. break outer;
  6064. }
  6065. }
  6066. }
  6067. break;
  6068. }
  6069. if (next == 0) {
  6070. do {
  6071. if (!isConcave[i])
  6072. break;
  6073. i--;
  6074. } while (i > 0);
  6075. break;
  6076. }
  6077. previous = i;
  6078. i = next;
  6079. next = (next + 1) % vertexCount;
  6080. }
  6081. triangles.push(indices[(vertexCount + i - 1) % vertexCount]);
  6082. triangles.push(indices[i]);
  6083. triangles.push(indices[(i + 1) % vertexCount]);
  6084. indices.splice(i, 1);
  6085. isConcave.splice(i, 1);
  6086. vertexCount--;
  6087. var previousIndex = (vertexCount + i - 1) % vertexCount;
  6088. var nextIndex = i == vertexCount ? 0 : i;
  6089. isConcave[previousIndex] = Triangulator.isConcave(previousIndex, vertexCount, vertices, indices);
  6090. isConcave[nextIndex] = Triangulator.isConcave(nextIndex, vertexCount, vertices, indices);
  6091. }
  6092. if (vertexCount == 3) {
  6093. triangles.push(indices[2]);
  6094. triangles.push(indices[0]);
  6095. triangles.push(indices[1]);
  6096. }
  6097. return triangles;
  6098. };
  6099. Triangulator.prototype.decompose = function (verticesArray, triangles) {
  6100. var vertices = verticesArray;
  6101. var convexPolygons = this.convexPolygons;
  6102. this.polygonPool.freeAll(convexPolygons);
  6103. convexPolygons.length = 0;
  6104. var convexPolygonsIndices = this.convexPolygonsIndices;
  6105. this.polygonIndicesPool.freeAll(convexPolygonsIndices);
  6106. convexPolygonsIndices.length = 0;
  6107. var polygonIndices = this.polygonIndicesPool.obtain();
  6108. polygonIndices.length = 0;
  6109. var polygon = this.polygonPool.obtain();
  6110. polygon.length = 0;
  6111. var fanBaseIndex = -1, lastWinding = 0;
  6112. for (var i = 0, n = triangles.length; i < n; i += 3) {
  6113. var t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1;
  6114. var x1 = vertices[t1], y1 = vertices[t1 + 1];
  6115. var x2 = vertices[t2], y2 = vertices[t2 + 1];
  6116. var x3 = vertices[t3], y3 = vertices[t3 + 1];
  6117. var merged = false;
  6118. if (fanBaseIndex == t1) {
  6119. var o = polygon.length - 4;
  6120. var winding1 = Triangulator.winding(polygon[o], polygon[o + 1], polygon[o + 2], polygon[o + 3], x3, y3);
  6121. var winding2 = Triangulator.winding(x3, y3, polygon[0], polygon[1], polygon[2], polygon[3]);
  6122. if (winding1 == lastWinding && winding2 == lastWinding) {
  6123. polygon.push(x3);
  6124. polygon.push(y3);
  6125. polygonIndices.push(t3);
  6126. merged = true;
  6127. }
  6128. }
  6129. if (!merged) {
  6130. if (polygon.length > 0) {
  6131. convexPolygons.push(polygon);
  6132. convexPolygonsIndices.push(polygonIndices);
  6133. }
  6134. else {
  6135. this.polygonPool.free(polygon);
  6136. this.polygonIndicesPool.free(polygonIndices);
  6137. }
  6138. polygon = this.polygonPool.obtain();
  6139. polygon.length = 0;
  6140. polygon.push(x1);
  6141. polygon.push(y1);
  6142. polygon.push(x2);
  6143. polygon.push(y2);
  6144. polygon.push(x3);
  6145. polygon.push(y3);
  6146. polygonIndices = this.polygonIndicesPool.obtain();
  6147. polygonIndices.length = 0;
  6148. polygonIndices.push(t1);
  6149. polygonIndices.push(t2);
  6150. polygonIndices.push(t3);
  6151. lastWinding = Triangulator.winding(x1, y1, x2, y2, x3, y3);
  6152. fanBaseIndex = t1;
  6153. }
  6154. }
  6155. if (polygon.length > 0) {
  6156. convexPolygons.push(polygon);
  6157. convexPolygonsIndices.push(polygonIndices);
  6158. }
  6159. for (var i = 0, n = convexPolygons.length; i < n; i++) {
  6160. polygonIndices = convexPolygonsIndices[i];
  6161. if (polygonIndices.length == 0)
  6162. continue;
  6163. var firstIndex = polygonIndices[0];
  6164. var lastIndex = polygonIndices[polygonIndices.length - 1];
  6165. polygon = convexPolygons[i];
  6166. var o = polygon.length - 4;
  6167. var prevPrevX = polygon[o], prevPrevY = polygon[o + 1];
  6168. var prevX = polygon[o + 2], prevY = polygon[o + 3];
  6169. var firstX = polygon[0], firstY = polygon[1];
  6170. var secondX = polygon[2], secondY = polygon[3];
  6171. var winding = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY);
  6172. for (var ii = 0; ii < n; ii++) {
  6173. if (ii == i)
  6174. continue;
  6175. var otherIndices = convexPolygonsIndices[ii];
  6176. if (otherIndices.length != 3)
  6177. continue;
  6178. var otherFirstIndex = otherIndices[0];
  6179. var otherSecondIndex = otherIndices[1];
  6180. var otherLastIndex = otherIndices[2];
  6181. var otherPoly = convexPolygons[ii];
  6182. var x3 = otherPoly[otherPoly.length - 2], y3 = otherPoly[otherPoly.length - 1];
  6183. if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex)
  6184. continue;
  6185. var winding1 = Triangulator.winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3);
  6186. var winding2 = Triangulator.winding(x3, y3, firstX, firstY, secondX, secondY);
  6187. if (winding1 == winding && winding2 == winding) {
  6188. otherPoly.length = 0;
  6189. otherIndices.length = 0;
  6190. polygon.push(x3);
  6191. polygon.push(y3);
  6192. polygonIndices.push(otherLastIndex);
  6193. prevPrevX = prevX;
  6194. prevPrevY = prevY;
  6195. prevX = x3;
  6196. prevY = y3;
  6197. ii = 0;
  6198. }
  6199. }
  6200. }
  6201. for (var i = convexPolygons.length - 1; i >= 0; i--) {
  6202. polygon = convexPolygons[i];
  6203. if (polygon.length == 0) {
  6204. convexPolygons.splice(i, 1);
  6205. this.polygonPool.free(polygon);
  6206. polygonIndices = convexPolygonsIndices[i];
  6207. convexPolygonsIndices.splice(i, 1);
  6208. this.polygonIndicesPool.free(polygonIndices);
  6209. }
  6210. }
  6211. return convexPolygons;
  6212. };
  6213. Triangulator.isConcave = function (index, vertexCount, vertices, indices) {
  6214. var previous = indices[(vertexCount + index - 1) % vertexCount] << 1;
  6215. var current = indices[index] << 1;
  6216. var next = indices[(index + 1) % vertexCount] << 1;
  6217. return !this.positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]);
  6218. };
  6219. Triangulator.positiveArea = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  6220. return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0;
  6221. };
  6222. Triangulator.winding = function (p1x, p1y, p2x, p2y, p3x, p3y) {
  6223. var px = p2x - p1x, py = p2y - p1y;
  6224. return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
  6225. };
  6226. return Triangulator;
  6227. }());
  6228. spine.Triangulator = Triangulator;
  6229. })(spine || (spine = {}));
  6230. var spine;
  6231. (function (spine) {
  6232. var IntSet = (function () {
  6233. function IntSet() {
  6234. this.array = new Array();
  6235. }
  6236. IntSet.prototype.add = function (value) {
  6237. var contains = this.contains(value);
  6238. this.array[value | 0] = value | 0;
  6239. return !contains;
  6240. };
  6241. IntSet.prototype.contains = function (value) {
  6242. return this.array[value | 0] != undefined;
  6243. };
  6244. IntSet.prototype.remove = function (value) {
  6245. this.array[value | 0] = undefined;
  6246. };
  6247. IntSet.prototype.clear = function () {
  6248. this.array.length = 0;
  6249. };
  6250. return IntSet;
  6251. }());
  6252. spine.IntSet = IntSet;
  6253. var Color = (function () {
  6254. function Color(r, g, b, a) {
  6255. if (r === void 0) { r = 0; }
  6256. if (g === void 0) { g = 0; }
  6257. if (b === void 0) { b = 0; }
  6258. if (a === void 0) { a = 0; }
  6259. this.r = r;
  6260. this.g = g;
  6261. this.b = b;
  6262. this.a = a;
  6263. }
  6264. Color.prototype.set = function (r, g, b, a) {
  6265. this.r = r;
  6266. this.g = g;
  6267. this.b = b;
  6268. this.a = a;
  6269. this.clamp();
  6270. return this;
  6271. };
  6272. Color.prototype.setFromColor = function (c) {
  6273. this.r = c.r;
  6274. this.g = c.g;
  6275. this.b = c.b;
  6276. this.a = c.a;
  6277. return this;
  6278. };
  6279. Color.prototype.setFromString = function (hex) {
  6280. hex = hex.charAt(0) == '#' ? hex.substr(1) : hex;
  6281. this.r = parseInt(hex.substr(0, 2), 16) / 255.0;
  6282. this.g = parseInt(hex.substr(2, 2), 16) / 255.0;
  6283. this.b = parseInt(hex.substr(4, 2), 16) / 255.0;
  6284. this.a = (hex.length != 8 ? 255 : parseInt(hex.substr(6, 2), 16)) / 255.0;
  6285. return this;
  6286. };
  6287. Color.prototype.add = function (r, g, b, a) {
  6288. this.r += r;
  6289. this.g += g;
  6290. this.b += b;
  6291. this.a += a;
  6292. this.clamp();
  6293. return this;
  6294. };
  6295. Color.prototype.clamp = function () {
  6296. if (this.r < 0)
  6297. this.r = 0;
  6298. else if (this.r > 1)
  6299. this.r = 1;
  6300. if (this.g < 0)
  6301. this.g = 0;
  6302. else if (this.g > 1)
  6303. this.g = 1;
  6304. if (this.b < 0)
  6305. this.b = 0;
  6306. else if (this.b > 1)
  6307. this.b = 1;
  6308. if (this.a < 0)
  6309. this.a = 0;
  6310. else if (this.a > 1)
  6311. this.a = 1;
  6312. return this;
  6313. };
  6314. Color.WHITE = new Color(1, 1, 1, 1);
  6315. Color.RED = new Color(1, 0, 0, 1);
  6316. Color.GREEN = new Color(0, 1, 0, 1);
  6317. Color.BLUE = new Color(0, 0, 1, 1);
  6318. Color.MAGENTA = new Color(1, 0, 1, 1);
  6319. return Color;
  6320. }());
  6321. spine.Color = Color;
  6322. var MathUtils = (function () {
  6323. function MathUtils() {
  6324. }
  6325. MathUtils.clamp = function (value, min, max) {
  6326. if (value < min)
  6327. return min;
  6328. if (value > max)
  6329. return max;
  6330. return value;
  6331. };
  6332. MathUtils.cosDeg = function (degrees) {
  6333. return Math.cos(degrees * MathUtils.degRad);
  6334. };
  6335. MathUtils.sinDeg = function (degrees) {
  6336. return Math.sin(degrees * MathUtils.degRad);
  6337. };
  6338. MathUtils.signum = function (value) {
  6339. return value > 0 ? 1 : value < 0 ? -1 : 0;
  6340. };
  6341. MathUtils.toInt = function (x) {
  6342. return x > 0 ? Math.floor(x) : Math.ceil(x);
  6343. };
  6344. MathUtils.cbrt = function (x) {
  6345. var y = Math.pow(Math.abs(x), 1 / 3);
  6346. return x < 0 ? -y : y;
  6347. };
  6348. MathUtils.PI = 3.1415927;
  6349. MathUtils.PI2 = MathUtils.PI * 2;
  6350. MathUtils.radiansToDegrees = 180 / MathUtils.PI;
  6351. MathUtils.radDeg = MathUtils.radiansToDegrees;
  6352. MathUtils.degreesToRadians = MathUtils.PI / 180;
  6353. MathUtils.degRad = MathUtils.degreesToRadians;
  6354. return MathUtils;
  6355. }());
  6356. spine.MathUtils = MathUtils;
  6357. var Utils = (function () {
  6358. function Utils() {
  6359. }
  6360. Utils.arrayCopy = function (source, sourceStart, dest, destStart, numElements) {
  6361. for (var i = sourceStart, j = destStart; i < sourceStart + numElements; i++, j++) {
  6362. dest[j] = source[i];
  6363. }
  6364. };
  6365. Utils.setArraySize = function (array, size, value) {
  6366. if (value === void 0) { value = 0; }
  6367. var oldSize = array.length;
  6368. if (oldSize == size)
  6369. return array;
  6370. array.length = size;
  6371. if (oldSize < size) {
  6372. for (var i = oldSize; i < size; i++)
  6373. array[i] = value;
  6374. }
  6375. return array;
  6376. };
  6377. Utils.ensureArrayCapacity = function (array, size, value) {
  6378. if (value === void 0) { value = 0; }
  6379. if (array.length >= size)
  6380. return array;
  6381. return Utils.setArraySize(array, size, value);
  6382. };
  6383. Utils.newArray = function (size, defaultValue) {
  6384. var array = new Array(size);
  6385. for (var i = 0; i < size; i++)
  6386. array[i] = defaultValue;
  6387. return array;
  6388. };
  6389. Utils.newFloatArray = function (size) {
  6390. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  6391. return new Float32Array(size);
  6392. }
  6393. else {
  6394. var array = new Array(size);
  6395. for (var i = 0; i < array.length; i++)
  6396. array[i] = 0;
  6397. return array;
  6398. }
  6399. };
  6400. Utils.newShortArray = function (size) {
  6401. if (Utils.SUPPORTS_TYPED_ARRAYS) {
  6402. return new Int16Array(size);
  6403. }
  6404. else {
  6405. var array = new Array(size);
  6406. for (var i = 0; i < array.length; i++)
  6407. array[i] = 0;
  6408. return array;
  6409. }
  6410. };
  6411. Utils.toFloatArray = function (array) {
  6412. return Utils.SUPPORTS_TYPED_ARRAYS ? new Float32Array(array) : array;
  6413. };
  6414. Utils.SUPPORTS_TYPED_ARRAYS = typeof (Float32Array) !== "undefined";
  6415. return Utils;
  6416. }());
  6417. spine.Utils = Utils;
  6418. var DebugUtils = (function () {
  6419. function DebugUtils() {
  6420. }
  6421. DebugUtils.logBones = function (skeleton) {
  6422. for (var i = 0; i < skeleton.bones.length; i++) {
  6423. var bone = skeleton.bones[i];
  6424. console.log(bone.data.name + ", " + bone.a + ", " + bone.b + ", " + bone.c + ", " + bone.d + ", " + bone.worldX + ", " + bone.worldY);
  6425. }
  6426. };
  6427. return DebugUtils;
  6428. }());
  6429. spine.DebugUtils = DebugUtils;
  6430. var Pool = (function () {
  6431. function Pool(instantiator) {
  6432. this.items = new Array();
  6433. this.instantiator = instantiator;
  6434. }
  6435. Pool.prototype.obtain = function () {
  6436. return this.items.length > 0 ? this.items.pop() : this.instantiator();
  6437. };
  6438. Pool.prototype.free = function (item) {
  6439. if (item.reset)
  6440. item.reset();
  6441. this.items.push(item);
  6442. };
  6443. Pool.prototype.freeAll = function (items) {
  6444. for (var i = 0; i < items.length; i++) {
  6445. if (items[i].reset)
  6446. items[i].reset();
  6447. this.items[i] = items[i];
  6448. }
  6449. };
  6450. Pool.prototype.clear = function () {
  6451. this.items.length = 0;
  6452. };
  6453. return Pool;
  6454. }());
  6455. spine.Pool = Pool;
  6456. var Vector2 = (function () {
  6457. function Vector2(x, y) {
  6458. if (x === void 0) { x = 0; }
  6459. if (y === void 0) { y = 0; }
  6460. this.x = x;
  6461. this.y = y;
  6462. }
  6463. Vector2.prototype.set = function (x, y) {
  6464. this.x = x;
  6465. this.y = y;
  6466. return this;
  6467. };
  6468. Vector2.prototype.length = function () {
  6469. var x = this.x;
  6470. var y = this.y;
  6471. return Math.sqrt(x * x + y * y);
  6472. };
  6473. Vector2.prototype.normalize = function () {
  6474. var len = this.length();
  6475. if (len != 0) {
  6476. this.x /= len;
  6477. this.y /= len;
  6478. }
  6479. return this;
  6480. };
  6481. return Vector2;
  6482. }());
  6483. spine.Vector2 = Vector2;
  6484. var TimeKeeper = (function () {
  6485. function TimeKeeper() {
  6486. this.maxDelta = 0.064;
  6487. this.framesPerSecond = 0;
  6488. this.delta = 0;
  6489. this.totalTime = 0;
  6490. this.lastTime = Date.now() / 1000;
  6491. this.frameCount = 0;
  6492. this.frameTime = 0;
  6493. }
  6494. TimeKeeper.prototype.update = function () {
  6495. var now = Date.now() / 1000;
  6496. this.delta = now - this.lastTime;
  6497. this.frameTime += this.delta;
  6498. this.totalTime += this.delta;
  6499. if (this.delta > this.maxDelta)
  6500. this.delta = this.maxDelta;
  6501. this.lastTime = now;
  6502. this.frameCount++;
  6503. if (this.frameTime > 1) {
  6504. this.framesPerSecond = this.frameCount / this.frameTime;
  6505. this.frameTime = 0;
  6506. this.frameCount = 0;
  6507. }
  6508. };
  6509. return TimeKeeper;
  6510. }());
  6511. spine.TimeKeeper = TimeKeeper;
  6512. var WindowedMean = (function () {
  6513. function WindowedMean(windowSize) {
  6514. if (windowSize === void 0) { windowSize = 32; }
  6515. this.addedValues = 0;
  6516. this.lastValue = 0;
  6517. this.mean = 0;
  6518. this.dirty = true;
  6519. this.values = new Array(windowSize);
  6520. }
  6521. WindowedMean.prototype.hasEnoughData = function () {
  6522. return this.addedValues >= this.values.length;
  6523. };
  6524. WindowedMean.prototype.addValue = function (value) {
  6525. if (this.addedValues < this.values.length)
  6526. this.addedValues++;
  6527. this.values[this.lastValue++] = value;
  6528. if (this.lastValue > this.values.length - 1)
  6529. this.lastValue = 0;
  6530. this.dirty = true;
  6531. };
  6532. WindowedMean.prototype.getMean = function () {
  6533. if (this.hasEnoughData()) {
  6534. if (this.dirty) {
  6535. var mean = 0;
  6536. for (var i = 0; i < this.values.length; i++) {
  6537. mean += this.values[i];
  6538. }
  6539. this.mean = mean / this.values.length;
  6540. this.dirty = false;
  6541. }
  6542. return this.mean;
  6543. }
  6544. else {
  6545. return 0;
  6546. }
  6547. };
  6548. return WindowedMean;
  6549. }());
  6550. spine.WindowedMean = WindowedMean;
  6551. })(spine || (spine = {}));
  6552. var spine;
  6553. (function (spine) {
  6554. var threejs;
  6555. (function (threejs) {
  6556. var AssetManager = (function (_super) {
  6557. __extends(AssetManager, _super);
  6558. function AssetManager(pathPrefix) {
  6559. if (pathPrefix === void 0) { pathPrefix = ""; }
  6560. _super.call(this, function (image) {
  6561. return new threejs.ThreeJsTexture(image);
  6562. }, pathPrefix);
  6563. }
  6564. return AssetManager;
  6565. }(spine.AssetManager));
  6566. threejs.AssetManager = AssetManager;
  6567. })(threejs = spine.threejs || (spine.threejs = {}));
  6568. })(spine || (spine = {}));
  6569. var spine;
  6570. (function (spine) {
  6571. var threejs;
  6572. (function (threejs) {
  6573. var MeshBatcher = (function () {
  6574. function MeshBatcher(mesh, maxVertices) {
  6575. if (maxVertices === void 0) { maxVertices = 10920; }
  6576. this.verticesLength = 0;
  6577. this.indicesLength = 0;
  6578. if (maxVertices > 10920)
  6579. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  6580. var vertices = this.vertices = new Float32Array(maxVertices * MeshBatcher.VERTEX_SIZE);
  6581. var indices = this.indices = new Uint16Array(maxVertices * 3);
  6582. this.mesh = mesh;
  6583. var geo = new THREE.BufferGeometry();
  6584. var vertexBuffer = this.vertexBuffer = new THREE.InterleavedBuffer(vertices, MeshBatcher.VERTEX_SIZE);
  6585. vertexBuffer.dynamic = true;
  6586. geo.addAttribute("position", new THREE.InterleavedBufferAttribute(vertexBuffer, 3, 0, false));
  6587. geo.addAttribute("color", new THREE.InterleavedBufferAttribute(vertexBuffer, 4, 3, false));
  6588. geo.addAttribute("uv", new THREE.InterleavedBufferAttribute(vertexBuffer, 2, 7, false));
  6589. geo.setIndex(new THREE.BufferAttribute(indices, 1));
  6590. geo.getIndex().dynamic = true;
  6591. geo.drawRange.start = 0;
  6592. geo.drawRange.count = 0;
  6593. mesh.geometry = geo;
  6594. }
  6595. MeshBatcher.prototype.begin = function () {
  6596. this.verticesLength = 0;
  6597. this.indicesLength = 0;
  6598. };
  6599. MeshBatcher.prototype.batch = function (vertices, verticesLength, indices, indicesLength, z) {
  6600. if (z === void 0) { z = 0; }
  6601. var indexStart = this.verticesLength / MeshBatcher.VERTEX_SIZE;
  6602. var vertexBuffer = this.vertices;
  6603. var i = this.verticesLength;
  6604. var j = 0;
  6605. for (; j < verticesLength;) {
  6606. vertexBuffer[i++] = vertices[j++];
  6607. vertexBuffer[i++] = vertices[j++];
  6608. vertexBuffer[i++] = z;
  6609. vertexBuffer[i++] = vertices[j++];
  6610. vertexBuffer[i++] = vertices[j++];
  6611. vertexBuffer[i++] = vertices[j++];
  6612. vertexBuffer[i++] = vertices[j++];
  6613. vertexBuffer[i++] = vertices[j++];
  6614. vertexBuffer[i++] = vertices[j++];
  6615. }
  6616. this.verticesLength = i;
  6617. var indicesArray = this.indices;
  6618. for (i = this.indicesLength, j = 0; j < indicesLength; i++, j++)
  6619. indicesArray[i] = indices[j] + indexStart;
  6620. this.indicesLength += indicesLength;
  6621. };
  6622. MeshBatcher.prototype.end = function () {
  6623. this.vertexBuffer.needsUpdate = true;
  6624. this.vertexBuffer.updateRange.offset = 0;
  6625. this.vertexBuffer.updateRange.count = this.verticesLength;
  6626. var geo = this.mesh.geometry;
  6627. geo.getIndex().needsUpdate = true;
  6628. geo.getIndex().updateRange.offset = 0;
  6629. geo.getIndex().updateRange.count = this.indicesLength;
  6630. geo.drawRange.start = 0;
  6631. geo.drawRange.count = this.indicesLength;
  6632. };
  6633. MeshBatcher.VERTEX_SIZE = 9;
  6634. return MeshBatcher;
  6635. }());
  6636. threejs.MeshBatcher = MeshBatcher;
  6637. })(threejs = spine.threejs || (spine.threejs = {}));
  6638. })(spine || (spine = {}));
  6639. var spine;
  6640. (function (spine) {
  6641. var threejs;
  6642. (function (threejs) {
  6643. var SkeletonMesh = (function (_super) {
  6644. __extends(SkeletonMesh, _super);
  6645. function SkeletonMesh(skeletonData) {
  6646. _super.call(this);
  6647. this.zOffset = 0.1;
  6648. this.clipper = new spine.SkeletonClipping();
  6649. this.vertices = spine.Utils.newFloatArray(1024);
  6650. this.tempColor = new spine.Color();
  6651. this.skeleton = new spine.Skeleton(skeletonData);
  6652. var animData = new spine.AnimationStateData(skeletonData);
  6653. this.state = new spine.AnimationState(animData);
  6654. var material = this.material = new THREE.MeshBasicMaterial();
  6655. material.side = THREE.DoubleSide;
  6656. material.transparent = true;
  6657. material.alphaTest = 0.5;
  6658. this.batcher = new threejs.MeshBatcher(this);
  6659. }
  6660. SkeletonMesh.prototype.update = function (deltaTime) {
  6661. var state = this.state;
  6662. var skeleton = this.skeleton;
  6663. state.update(deltaTime);
  6664. state.apply(skeleton);
  6665. skeleton.updateWorldTransform();
  6666. this.updateGeometry();
  6667. };
  6668. SkeletonMesh.prototype.updateGeometry = function () {
  6669. var geometry = this.geometry;
  6670. var numVertices = 0;
  6671. var verticesLength = 0;
  6672. var indicesLength = 0;
  6673. var blendMode = null;
  6674. var clipper = this.clipper;
  6675. var vertices = this.vertices;
  6676. var triangles = null;
  6677. var uvs = null;
  6678. var drawOrder = this.skeleton.drawOrder;
  6679. var batcher = this.batcher;
  6680. batcher.begin();
  6681. var z = 0;
  6682. var zOffset = this.zOffset;
  6683. for (var i = 0, n = drawOrder.length; i < n; i++) {
  6684. var vertexSize = clipper.isClipping() ? 2 : SkeletonMesh.VERTEX_SIZE;
  6685. var slot = drawOrder[i];
  6686. var attachment = slot.getAttachment();
  6687. var attachmentColor = null;
  6688. var texture = null;
  6689. var numFloats = 0;
  6690. if (attachment instanceof spine.RegionAttachment) {
  6691. var region = attachment;
  6692. attachmentColor = region.color;
  6693. vertices = this.vertices;
  6694. numFloats = vertexSize * 4;
  6695. region.computeWorldVertices(slot.bone, vertices, 0, vertexSize);
  6696. triangles = SkeletonMesh.QUAD_TRIANGLES;
  6697. uvs = region.uvs;
  6698. texture = region.region.renderObject.texture;
  6699. }
  6700. else if (attachment instanceof spine.MeshAttachment) {
  6701. var mesh = attachment;
  6702. attachmentColor = mesh.color;
  6703. vertices = this.vertices;
  6704. numFloats = (mesh.worldVerticesLength >> 1) * vertexSize;
  6705. if (numFloats > vertices.length) {
  6706. vertices = this.vertices = spine.Utils.newFloatArray(numFloats);
  6707. }
  6708. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, vertexSize);
  6709. triangles = mesh.triangles;
  6710. uvs = mesh.uvs;
  6711. texture = mesh.region.renderObject.texture;
  6712. }
  6713. else if (attachment instanceof spine.ClippingAttachment) {
  6714. var clip = (attachment);
  6715. clipper.clipStart(slot, clip);
  6716. continue;
  6717. }
  6718. else
  6719. continue;
  6720. if (texture != null) {
  6721. if (!this.material.map) {
  6722. var mat = this.material;
  6723. mat.map = texture.texture;
  6724. mat.needsUpdate = true;
  6725. }
  6726. var skeleton = slot.bone.skeleton;
  6727. var skeletonColor = skeleton.color;
  6728. var slotColor = slot.color;
  6729. var alpha = skeletonColor.a * slotColor.a * attachmentColor.a;
  6730. var color = this.tempColor;
  6731. color.set(skeletonColor.r * slotColor.r * attachmentColor.r, skeletonColor.g * slotColor.g * attachmentColor.g, skeletonColor.b * slotColor.b * attachmentColor.b, alpha);
  6732. if (clipper.isClipping()) {
  6733. clipper.clipTriangles(vertices, numFloats, triangles, triangles.length, uvs, color, null, false);
  6734. var clippedVertices = clipper.clippedVertices;
  6735. var clippedTriangles = clipper.clippedTriangles;
  6736. batcher.batch(clippedVertices, clippedVertices.length, clippedTriangles, clippedTriangles.length, z);
  6737. }
  6738. else {
  6739. var verts = vertices;
  6740. for (var v = 2, u = 0, n_2 = numFloats; v < n_2; v += vertexSize, u += 2) {
  6741. verts[v] = color.r;
  6742. verts[v + 1] = color.g;
  6743. verts[v + 2] = color.b;
  6744. verts[v + 3] = color.a;
  6745. verts[v + 4] = uvs[u];
  6746. verts[v + 5] = uvs[u + 1];
  6747. }
  6748. batcher.batch(vertices, numFloats, triangles, triangles.length, z);
  6749. }
  6750. z += zOffset;
  6751. }
  6752. }
  6753. batcher.end();
  6754. };
  6755. SkeletonMesh.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  6756. SkeletonMesh.VERTEX_SIZE = 2 + 2 + 4;
  6757. return SkeletonMesh;
  6758. }(THREE.Mesh));
  6759. threejs.SkeletonMesh = SkeletonMesh;
  6760. })(threejs = spine.threejs || (spine.threejs = {}));
  6761. })(spine || (spine = {}));
  6762. var spine;
  6763. (function (spine) {
  6764. var threejs;
  6765. (function (threejs) {
  6766. var ThreeJsTexture = (function (_super) {
  6767. __extends(ThreeJsTexture, _super);
  6768. function ThreeJsTexture(image) {
  6769. _super.call(this, image);
  6770. this.texture = new THREE.Texture(image);
  6771. this.texture.flipY = false;
  6772. this.texture.needsUpdate = true;
  6773. }
  6774. ThreeJsTexture.prototype.setFilters = function (minFilter, magFilter) {
  6775. this.texture.minFilter = ThreeJsTexture.toThreeJsTextureFilter(minFilter);
  6776. this.texture.magFilter = ThreeJsTexture.toThreeJsTextureFilter(magFilter);
  6777. };
  6778. ThreeJsTexture.prototype.setWraps = function (uWrap, vWrap) {
  6779. this.texture.wrapS = ThreeJsTexture.toThreeJsTextureWrap(uWrap);
  6780. this.texture.wrapT = ThreeJsTexture.toThreeJsTextureWrap(vWrap);
  6781. };
  6782. ThreeJsTexture.prototype.dispose = function () {
  6783. this.texture.dispose();
  6784. };
  6785. ThreeJsTexture.toThreeJsTextureFilter = function (filter) {
  6786. if (filter === spine.TextureFilter.Linear)
  6787. return THREE.LinearFilter;
  6788. else if (filter === spine.TextureFilter.MipMap)
  6789. return THREE.LinearMipMapLinearFilter;
  6790. else if (filter === spine.TextureFilter.MipMapLinearNearest)
  6791. return THREE.LinearMipMapNearestFilter;
  6792. else if (filter === spine.TextureFilter.MipMapNearestLinear)
  6793. return THREE.NearestMipMapLinearFilter;
  6794. else if (filter === spine.TextureFilter.MipMapNearestNearest)
  6795. return THREE.NearestMipMapNearestFilter;
  6796. else if (filter === spine.TextureFilter.Nearest)
  6797. return THREE.NearestFilter;
  6798. else
  6799. throw new Error("Unknown texture filter: " + filter);
  6800. };
  6801. ThreeJsTexture.toThreeJsTextureWrap = function (wrap) {
  6802. if (wrap === spine.TextureWrap.ClampToEdge)
  6803. return THREE.ClampToEdgeWrapping;
  6804. else if (wrap === spine.TextureWrap.MirroredRepeat)
  6805. return THREE.MirroredRepeatWrapping;
  6806. else if (wrap === spine.TextureWrap.Repeat)
  6807. return THREE.RepeatWrapping;
  6808. else
  6809. throw new Error("Unknown texture wrap: " + wrap);
  6810. };
  6811. return ThreeJsTexture;
  6812. }(spine.Texture));
  6813. threejs.ThreeJsTexture = ThreeJsTexture;
  6814. })(threejs = spine.threejs || (spine.threejs = {}));
  6815. })(spine || (spine = {}));
  6816. var spine;
  6817. (function (spine) {
  6818. var webgl;
  6819. (function (webgl) {
  6820. var AssetManager = (function (_super) {
  6821. __extends(AssetManager, _super);
  6822. function AssetManager(context, pathPrefix) {
  6823. if (pathPrefix === void 0) { pathPrefix = ""; }
  6824. _super.call(this, function (image) {
  6825. return new spine.webgl.GLTexture(context, image);
  6826. }, pathPrefix);
  6827. }
  6828. return AssetManager;
  6829. }(spine.AssetManager));
  6830. webgl.AssetManager = AssetManager;
  6831. })(webgl = spine.webgl || (spine.webgl = {}));
  6832. })(spine || (spine = {}));
  6833. var spine;
  6834. (function (spine) {
  6835. var webgl;
  6836. (function (webgl) {
  6837. var OrthoCamera = (function () {
  6838. function OrthoCamera(viewportWidth, viewportHeight) {
  6839. this.position = new webgl.Vector3(0, 0, 0);
  6840. this.direction = new webgl.Vector3(0, 0, -1);
  6841. this.up = new webgl.Vector3(0, 1, 0);
  6842. this.near = 0;
  6843. this.far = 100;
  6844. this.zoom = 1;
  6845. this.viewportWidth = 0;
  6846. this.viewportHeight = 0;
  6847. this.projectionView = new webgl.Matrix4();
  6848. this.inverseProjectionView = new webgl.Matrix4();
  6849. this.projection = new webgl.Matrix4();
  6850. this.view = new webgl.Matrix4();
  6851. this.tmp = new webgl.Vector3();
  6852. this.viewportWidth = viewportWidth;
  6853. this.viewportHeight = viewportHeight;
  6854. this.update();
  6855. }
  6856. OrthoCamera.prototype.update = function () {
  6857. var projection = this.projection;
  6858. var view = this.view;
  6859. var projectionView = this.projectionView;
  6860. var inverseProjectionView = this.inverseProjectionView;
  6861. var zoom = this.zoom, viewportWidth = this.viewportWidth, viewportHeight = this.viewportHeight;
  6862. projection.ortho(zoom * (-viewportWidth / 2), zoom * (viewportWidth / 2), zoom * (-viewportHeight / 2), zoom * (viewportHeight / 2), this.near, this.far);
  6863. view.lookAt(this.position, this.direction, this.up);
  6864. projectionView.set(projection.values);
  6865. projectionView.multiply(view);
  6866. inverseProjectionView.set(projectionView.values).invert();
  6867. };
  6868. OrthoCamera.prototype.screenToWorld = function (screenCoords, screenWidth, screenHeight) {
  6869. var x = screenCoords.x, y = screenHeight - screenCoords.y - 1;
  6870. var tmp = this.tmp;
  6871. tmp.x = (2 * x) / screenWidth - 1;
  6872. tmp.y = (2 * y) / screenHeight - 1;
  6873. tmp.z = (2 * screenCoords.z) - 1;
  6874. tmp.project(this.inverseProjectionView);
  6875. screenCoords.set(tmp.x, tmp.y, tmp.z);
  6876. return screenCoords;
  6877. };
  6878. OrthoCamera.prototype.setViewport = function (viewportWidth, viewportHeight) {
  6879. this.viewportWidth = viewportWidth;
  6880. this.viewportHeight = viewportHeight;
  6881. };
  6882. return OrthoCamera;
  6883. }());
  6884. webgl.OrthoCamera = OrthoCamera;
  6885. })(webgl = spine.webgl || (spine.webgl = {}));
  6886. })(spine || (spine = {}));
  6887. var spine;
  6888. (function (spine) {
  6889. var webgl;
  6890. (function (webgl) {
  6891. var GLTexture = (function (_super) {
  6892. __extends(GLTexture, _super);
  6893. function GLTexture(context, image, useMipMaps) {
  6894. if (useMipMaps === void 0) { useMipMaps = false; }
  6895. _super.call(this, image);
  6896. this.texture = null;
  6897. this.boundUnit = 0;
  6898. this.useMipMaps = false;
  6899. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  6900. this.useMipMaps = useMipMaps;
  6901. this.restore();
  6902. this.context.addRestorable(this);
  6903. }
  6904. GLTexture.prototype.setFilters = function (minFilter, magFilter) {
  6905. var gl = this.context.gl;
  6906. this.bind();
  6907. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  6908. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
  6909. };
  6910. GLTexture.prototype.setWraps = function (uWrap, vWrap) {
  6911. var gl = this.context.gl;
  6912. this.bind();
  6913. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap);
  6914. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap);
  6915. };
  6916. GLTexture.prototype.update = function (useMipMaps) {
  6917. var gl = this.context.gl;
  6918. if (!this.texture) {
  6919. this.texture = this.context.gl.createTexture();
  6920. }
  6921. this.bind();
  6922. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image);
  6923. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  6924. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  6925. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6926. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6927. if (useMipMaps)
  6928. gl.generateMipmap(gl.TEXTURE_2D);
  6929. };
  6930. GLTexture.prototype.restore = function () {
  6931. this.texture = null;
  6932. this.update(this.useMipMaps);
  6933. };
  6934. GLTexture.prototype.bind = function (unit) {
  6935. if (unit === void 0) { unit = 0; }
  6936. var gl = this.context.gl;
  6937. this.boundUnit = unit;
  6938. gl.activeTexture(gl.TEXTURE0 + unit);
  6939. gl.bindTexture(gl.TEXTURE_2D, this.texture);
  6940. };
  6941. GLTexture.prototype.unbind = function () {
  6942. var gl = this.context.gl;
  6943. gl.activeTexture(gl.TEXTURE0 + this.boundUnit);
  6944. gl.bindTexture(gl.TEXTURE_2D, null);
  6945. };
  6946. GLTexture.prototype.dispose = function () {
  6947. this.context.removeRestorable(this);
  6948. var gl = this.context.gl;
  6949. gl.deleteTexture(this.texture);
  6950. };
  6951. return GLTexture;
  6952. }(spine.Texture));
  6953. webgl.GLTexture = GLTexture;
  6954. })(webgl = spine.webgl || (spine.webgl = {}));
  6955. })(spine || (spine = {}));
  6956. var spine;
  6957. (function (spine) {
  6958. var webgl;
  6959. (function (webgl) {
  6960. var Input = (function () {
  6961. function Input(element) {
  6962. this.lastX = 0;
  6963. this.lastY = 0;
  6964. this.buttonDown = false;
  6965. this.currTouch = null;
  6966. this.touchesPool = new spine.Pool(function () {
  6967. return new spine.webgl.Touch(0, 0, 0);
  6968. });
  6969. this.listeners = new Array();
  6970. this.element = element;
  6971. this.setupCallbacks(element);
  6972. }
  6973. Input.prototype.setupCallbacks = function (element) {
  6974. var _this = this;
  6975. element.addEventListener("mousedown", function (ev) {
  6976. if (ev instanceof MouseEvent) {
  6977. var rect = element.getBoundingClientRect();
  6978. var x = ev.clientX - rect.left;
  6979. var y = ev.clientY - rect.top;
  6980. var listeners = _this.listeners;
  6981. for (var i = 0; i < listeners.length; i++) {
  6982. listeners[i].down(x, y);
  6983. }
  6984. _this.lastX = x;
  6985. _this.lastY = y;
  6986. _this.buttonDown = true;
  6987. }
  6988. }, true);
  6989. element.addEventListener("mousemove", function (ev) {
  6990. if (ev instanceof MouseEvent) {
  6991. var rect = element.getBoundingClientRect();
  6992. var x = ev.clientX - rect.left;
  6993. var y = ev.clientY - rect.top;
  6994. var listeners = _this.listeners;
  6995. for (var i = 0; i < listeners.length; i++) {
  6996. if (_this.buttonDown) {
  6997. listeners[i].dragged(x, y);
  6998. }
  6999. else {
  7000. listeners[i].moved(x, y);
  7001. }
  7002. }
  7003. _this.lastX = x;
  7004. _this.lastY = y;
  7005. }
  7006. }, true);
  7007. element.addEventListener("mouseup", function (ev) {
  7008. if (ev instanceof MouseEvent) {
  7009. var rect = element.getBoundingClientRect();
  7010. var x = ev.clientX - rect.left;
  7011. var y = ev.clientY - rect.top;
  7012. var listeners = _this.listeners;
  7013. for (var i = 0; i < listeners.length; i++) {
  7014. listeners[i].up(x, y);
  7015. }
  7016. _this.lastX = x;
  7017. _this.lastY = y;
  7018. _this.buttonDown = false;
  7019. }
  7020. }, true);
  7021. element.addEventListener("touchstart", function (ev) {
  7022. if (_this.currTouch != null)
  7023. return;
  7024. var touches = ev.changedTouches;
  7025. for (var i = 0; i < touches.length; i++) {
  7026. var touch = touches[i];
  7027. var rect = element.getBoundingClientRect();
  7028. var x = touch.clientX - rect.left;
  7029. var y = touch.clientY - rect.top;
  7030. _this.currTouch = _this.touchesPool.obtain();
  7031. _this.currTouch.identifier = touch.identifier;
  7032. _this.currTouch.x = x;
  7033. _this.currTouch.y = y;
  7034. break;
  7035. }
  7036. var listeners = _this.listeners;
  7037. for (var i_1 = 0; i_1 < listeners.length; i_1++) {
  7038. listeners[i_1].down(_this.currTouch.x, _this.currTouch.y);
  7039. }
  7040. console.log("Start " + _this.currTouch.x + ", " + _this.currTouch.y);
  7041. _this.lastX = _this.currTouch.x;
  7042. _this.lastY = _this.currTouch.y;
  7043. _this.buttonDown = true;
  7044. ev.preventDefault();
  7045. }, false);
  7046. element.addEventListener("touchend", function (ev) {
  7047. var touches = ev.changedTouches;
  7048. for (var i = 0; i < touches.length; i++) {
  7049. var touch = touches[i];
  7050. if (_this.currTouch.identifier === touch.identifier) {
  7051. var rect = element.getBoundingClientRect();
  7052. var x = _this.currTouch.x = touch.clientX - rect.left;
  7053. var y = _this.currTouch.y = touch.clientY - rect.top;
  7054. _this.touchesPool.free(_this.currTouch);
  7055. var listeners = _this.listeners;
  7056. for (var i_2 = 0; i_2 < listeners.length; i_2++) {
  7057. listeners[i_2].up(x, y);
  7058. }
  7059. console.log("End " + x + ", " + y);
  7060. _this.lastX = x;
  7061. _this.lastY = y;
  7062. _this.buttonDown = false;
  7063. _this.currTouch = null;
  7064. break;
  7065. }
  7066. }
  7067. ev.preventDefault();
  7068. }, false);
  7069. element.addEventListener("touchcancel", function (ev) {
  7070. var touches = ev.changedTouches;
  7071. for (var i = 0; i < touches.length; i++) {
  7072. var touch = touches[i];
  7073. if (_this.currTouch.identifier === touch.identifier) {
  7074. var rect = element.getBoundingClientRect();
  7075. var x = _this.currTouch.x = touch.clientX - rect.left;
  7076. var y = _this.currTouch.y = touch.clientY - rect.top;
  7077. _this.touchesPool.free(_this.currTouch);
  7078. var listeners = _this.listeners;
  7079. for (var i_3 = 0; i_3 < listeners.length; i_3++) {
  7080. listeners[i_3].up(x, y);
  7081. }
  7082. console.log("End " + x + ", " + y);
  7083. _this.lastX = x;
  7084. _this.lastY = y;
  7085. _this.buttonDown = false;
  7086. _this.currTouch = null;
  7087. break;
  7088. }
  7089. }
  7090. ev.preventDefault();
  7091. }, false);
  7092. element.addEventListener("touchmove", function (ev) {
  7093. if (_this.currTouch == null)
  7094. return;
  7095. var touches = ev.changedTouches;
  7096. for (var i = 0; i < touches.length; i++) {
  7097. var touch = touches[i];
  7098. if (_this.currTouch.identifier === touch.identifier) {
  7099. var rect = element.getBoundingClientRect();
  7100. var x = touch.clientX - rect.left;
  7101. var y = touch.clientY - rect.top;
  7102. var listeners = _this.listeners;
  7103. for (var i_4 = 0; i_4 < listeners.length; i_4++) {
  7104. listeners[i_4].dragged(x, y);
  7105. }
  7106. console.log("Drag " + x + ", " + y);
  7107. _this.lastX = _this.currTouch.x = x;
  7108. _this.lastY = _this.currTouch.y = y;
  7109. break;
  7110. }
  7111. }
  7112. ev.preventDefault();
  7113. }, false);
  7114. };
  7115. Input.prototype.addListener = function (listener) {
  7116. this.listeners.push(listener);
  7117. };
  7118. Input.prototype.removeListener = function (listener) {
  7119. var idx = this.listeners.indexOf(listener);
  7120. if (idx > -1) {
  7121. this.listeners.splice(idx, 1);
  7122. }
  7123. };
  7124. return Input;
  7125. }());
  7126. webgl.Input = Input;
  7127. var Touch = (function () {
  7128. function Touch(identifier, x, y) {
  7129. this.identifier = identifier;
  7130. this.x = x;
  7131. this.y = y;
  7132. }
  7133. return Touch;
  7134. }());
  7135. webgl.Touch = Touch;
  7136. })(webgl = spine.webgl || (spine.webgl = {}));
  7137. })(spine || (spine = {}));
  7138. var spine;
  7139. (function (spine) {
  7140. var webgl;
  7141. (function (webgl) {
  7142. var LoadingScreen = (function () {
  7143. function LoadingScreen(renderer) {
  7144. this.logo = null;
  7145. this.spinner = null;
  7146. this.angle = 0;
  7147. this.fadeOut = 0;
  7148. this.timeKeeper = new spine.TimeKeeper();
  7149. this.backgroundColor = new spine.Color(0.135, 0.135, 0.135, 1);
  7150. this.tempColor = new spine.Color();
  7151. this.firstDraw = 0;
  7152. this.renderer = renderer;
  7153. this.timeKeeper.maxDelta = 9;
  7154. if (LoadingScreen.logoImg === null) {
  7155. var isSafari = navigator.userAgent.indexOf("Safari") > -1;
  7156. LoadingScreen.logoImg = new Image();
  7157. LoadingScreen.logoImg.src = LoadingScreen.SPINE_LOGO_DATA;
  7158. if (!isSafari)
  7159. LoadingScreen.logoImg.crossOrigin = "anonymous";
  7160. LoadingScreen.logoImg.onload = function (ev) {
  7161. LoadingScreen.loaded++;
  7162. };
  7163. LoadingScreen.spinnerImg = new Image();
  7164. LoadingScreen.spinnerImg.src = LoadingScreen.SPINNER_DATA;
  7165. if (!isSafari)
  7166. LoadingScreen.spinnerImg.crossOrigin = "anonymous";
  7167. LoadingScreen.spinnerImg.onload = function (ev) {
  7168. LoadingScreen.loaded++;
  7169. };
  7170. }
  7171. }
  7172. LoadingScreen.prototype.draw = function (complete) {
  7173. if (complete === void 0) { complete = false; }
  7174. if (complete && this.fadeOut > LoadingScreen.FADE_SECONDS)
  7175. return;
  7176. this.timeKeeper.update();
  7177. var a = Math.abs(Math.sin(this.timeKeeper.totalTime + 0.75));
  7178. this.angle -= this.timeKeeper.delta * 360 * (1 + 1.5 * Math.pow(a, 5));
  7179. var renderer = this.renderer;
  7180. var canvas = renderer.canvas;
  7181. var gl = renderer.context.gl;
  7182. var oldX = renderer.camera.position.x, oldY = renderer.camera.position.y;
  7183. renderer.camera.position.set(canvas.width / 2, canvas.height / 2, 0);
  7184. renderer.camera.viewportWidth = canvas.width;
  7185. renderer.camera.viewportHeight = canvas.height;
  7186. renderer.resize(webgl.ResizeMode.Stretch);
  7187. if (!complete) {
  7188. gl.clearColor(this.backgroundColor.r, this.backgroundColor.g, this.backgroundColor.b, this.backgroundColor.a);
  7189. gl.clear(gl.COLOR_BUFFER_BIT);
  7190. this.tempColor.a = 1;
  7191. }
  7192. else {
  7193. this.fadeOut += this.timeKeeper.delta * (this.timeKeeper.totalTime < 1 ? 2 : 1);
  7194. if (this.fadeOut > LoadingScreen.FADE_SECONDS) {
  7195. renderer.camera.position.set(oldX, oldY, 0);
  7196. return;
  7197. }
  7198. a = 1 - this.fadeOut / LoadingScreen.FADE_SECONDS;
  7199. this.tempColor.setFromColor(this.backgroundColor);
  7200. this.tempColor.a = 1 - (a - 1) * (a - 1);
  7201. renderer.begin();
  7202. renderer.quad(true, 0, 0, canvas.width, 0, canvas.width, canvas.height, 0, canvas.height, this.tempColor, this.tempColor, this.tempColor, this.tempColor);
  7203. renderer.end();
  7204. }
  7205. this.tempColor.set(1, 1, 1, this.tempColor.a);
  7206. if (LoadingScreen.loaded != 2)
  7207. return;
  7208. if (this.logo === null) {
  7209. this.logo = new webgl.GLTexture(renderer.context, LoadingScreen.logoImg);
  7210. this.spinner = new webgl.GLTexture(renderer.context, LoadingScreen.spinnerImg);
  7211. }
  7212. this.logo.update(false);
  7213. this.spinner.update(false);
  7214. var logoWidth = this.logo.getImage().width;
  7215. var logoHeight = this.logo.getImage().height;
  7216. var spinnerWidth = this.spinner.getImage().width;
  7217. var spinnerHeight = this.spinner.getImage().height;
  7218. renderer.batcher.setBlendMode(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
  7219. renderer.begin();
  7220. renderer.drawTexture(this.logo, (canvas.width - logoWidth) / 2, (canvas.height - logoHeight) / 2, logoWidth, logoHeight, this.tempColor);
  7221. renderer.drawTextureRotated(this.spinner, (canvas.width - spinnerWidth) / 2, (canvas.height - spinnerHeight) / 2, spinnerWidth, spinnerHeight, spinnerWidth / 2, spinnerHeight / 2, this.angle, this.tempColor);
  7222. renderer.end();
  7223. renderer.camera.position.set(oldX, oldY, 0);
  7224. };
  7225. LoadingScreen.FADE_SECONDS = 1;
  7226. LoadingScreen.loaded = 0;
  7227. LoadingScreen.spinnerImg = null;
  7228. LoadingScreen.logoImg = null;
  7229. 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==";
  7230. 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==";
  7231. return LoadingScreen;
  7232. }());
  7233. webgl.LoadingScreen = LoadingScreen;
  7234. })(webgl = spine.webgl || (spine.webgl = {}));
  7235. })(spine || (spine = {}));
  7236. var spine;
  7237. (function (spine) {
  7238. var webgl;
  7239. (function (webgl) {
  7240. webgl.M00 = 0;
  7241. webgl.M01 = 4;
  7242. webgl.M02 = 8;
  7243. webgl.M03 = 12;
  7244. webgl.M10 = 1;
  7245. webgl.M11 = 5;
  7246. webgl.M12 = 9;
  7247. webgl.M13 = 13;
  7248. webgl.M20 = 2;
  7249. webgl.M21 = 6;
  7250. webgl.M22 = 10;
  7251. webgl.M23 = 14;
  7252. webgl.M30 = 3;
  7253. webgl.M31 = 7;
  7254. webgl.M32 = 11;
  7255. webgl.M33 = 15;
  7256. var Matrix4 = (function () {
  7257. function Matrix4() {
  7258. this.temp = new Float32Array(16);
  7259. this.values = new Float32Array(16);
  7260. var v = this.values;
  7261. v[webgl.M00] = 1;
  7262. v[webgl.M11] = 1;
  7263. v[webgl.M22] = 1;
  7264. v[webgl.M33] = 1;
  7265. }
  7266. Matrix4.prototype.set = function (values) {
  7267. this.values.set(values);
  7268. return this;
  7269. };
  7270. Matrix4.prototype.transpose = function () {
  7271. var t = this.temp;
  7272. var v = this.values;
  7273. t[webgl.M00] = v[webgl.M00];
  7274. t[webgl.M01] = v[webgl.M10];
  7275. t[webgl.M02] = v[webgl.M20];
  7276. t[webgl.M03] = v[webgl.M30];
  7277. t[webgl.M10] = v[webgl.M01];
  7278. t[webgl.M11] = v[webgl.M11];
  7279. t[webgl.M12] = v[webgl.M21];
  7280. t[webgl.M13] = v[webgl.M31];
  7281. t[webgl.M20] = v[webgl.M02];
  7282. t[webgl.M21] = v[webgl.M12];
  7283. t[webgl.M22] = v[webgl.M22];
  7284. t[webgl.M23] = v[webgl.M32];
  7285. t[webgl.M30] = v[webgl.M03];
  7286. t[webgl.M31] = v[webgl.M13];
  7287. t[webgl.M32] = v[webgl.M23];
  7288. t[webgl.M33] = v[webgl.M33];
  7289. return this.set(t);
  7290. };
  7291. Matrix4.prototype.identity = function () {
  7292. var v = this.values;
  7293. v[webgl.M00] = 1;
  7294. v[webgl.M01] = 0;
  7295. v[webgl.M02] = 0;
  7296. v[webgl.M03] = 0;
  7297. v[webgl.M10] = 0;
  7298. v[webgl.M11] = 1;
  7299. v[webgl.M12] = 0;
  7300. v[webgl.M13] = 0;
  7301. v[webgl.M20] = 0;
  7302. v[webgl.M21] = 0;
  7303. v[webgl.M22] = 1;
  7304. v[webgl.M23] = 0;
  7305. v[webgl.M30] = 0;
  7306. v[webgl.M31] = 0;
  7307. v[webgl.M32] = 0;
  7308. v[webgl.M33] = 1;
  7309. return this;
  7310. };
  7311. Matrix4.prototype.invert = function () {
  7312. var v = this.values;
  7313. var t = this.temp;
  7314. 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]
  7315. + 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]
  7316. - 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]
  7317. - 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]
  7318. + 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]
  7319. + 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]
  7320. - 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]
  7321. - 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];
  7322. if (l_det == 0)
  7323. throw new Error("non-invertible matrix");
  7324. var inv_det = 1.0 / l_det;
  7325. 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]
  7326. - 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];
  7327. 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]
  7328. + 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];
  7329. 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]
  7330. - 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];
  7331. 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]
  7332. + 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];
  7333. 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]
  7334. + 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];
  7335. 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]
  7336. - 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];
  7337. 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]
  7338. + 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];
  7339. 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]
  7340. - 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];
  7341. 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]
  7342. - 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];
  7343. 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]
  7344. + 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];
  7345. 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]
  7346. - 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];
  7347. 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]
  7348. + 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];
  7349. 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]
  7350. + 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];
  7351. 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]
  7352. - 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];
  7353. 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]
  7354. + 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];
  7355. 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]
  7356. - 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];
  7357. v[webgl.M00] = t[webgl.M00] * inv_det;
  7358. v[webgl.M01] = t[webgl.M01] * inv_det;
  7359. v[webgl.M02] = t[webgl.M02] * inv_det;
  7360. v[webgl.M03] = t[webgl.M03] * inv_det;
  7361. v[webgl.M10] = t[webgl.M10] * inv_det;
  7362. v[webgl.M11] = t[webgl.M11] * inv_det;
  7363. v[webgl.M12] = t[webgl.M12] * inv_det;
  7364. v[webgl.M13] = t[webgl.M13] * inv_det;
  7365. v[webgl.M20] = t[webgl.M20] * inv_det;
  7366. v[webgl.M21] = t[webgl.M21] * inv_det;
  7367. v[webgl.M22] = t[webgl.M22] * inv_det;
  7368. v[webgl.M23] = t[webgl.M23] * inv_det;
  7369. v[webgl.M30] = t[webgl.M30] * inv_det;
  7370. v[webgl.M31] = t[webgl.M31] * inv_det;
  7371. v[webgl.M32] = t[webgl.M32] * inv_det;
  7372. v[webgl.M33] = t[webgl.M33] * inv_det;
  7373. return this;
  7374. };
  7375. Matrix4.prototype.determinant = function () {
  7376. var v = this.values;
  7377. 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]
  7378. + 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]
  7379. - 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]
  7380. - 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]
  7381. + 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]
  7382. + 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]
  7383. - 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]
  7384. - 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];
  7385. };
  7386. Matrix4.prototype.translate = function (x, y, z) {
  7387. var v = this.values;
  7388. v[webgl.M03] += x;
  7389. v[webgl.M13] += y;
  7390. v[webgl.M23] += z;
  7391. return this;
  7392. };
  7393. Matrix4.prototype.copy = function () {
  7394. return new Matrix4().set(this.values);
  7395. };
  7396. Matrix4.prototype.projection = function (near, far, fovy, aspectRatio) {
  7397. this.identity();
  7398. var l_fd = (1.0 / Math.tan((fovy * (Math.PI / 180)) / 2.0));
  7399. var l_a1 = (far + near) / (near - far);
  7400. var l_a2 = (2 * far * near) / (near - far);
  7401. var v = this.values;
  7402. v[webgl.M00] = l_fd / aspectRatio;
  7403. v[webgl.M10] = 0;
  7404. v[webgl.M20] = 0;
  7405. v[webgl.M30] = 0;
  7406. v[webgl.M01] = 0;
  7407. v[webgl.M11] = l_fd;
  7408. v[webgl.M21] = 0;
  7409. v[webgl.M31] = 0;
  7410. v[webgl.M02] = 0;
  7411. v[webgl.M12] = 0;
  7412. v[webgl.M22] = l_a1;
  7413. v[webgl.M32] = -1;
  7414. v[webgl.M03] = 0;
  7415. v[webgl.M13] = 0;
  7416. v[webgl.M23] = l_a2;
  7417. v[webgl.M33] = 0;
  7418. return this;
  7419. };
  7420. Matrix4.prototype.ortho2d = function (x, y, width, height) {
  7421. return this.ortho(x, x + width, y, y + height, 0, 1);
  7422. };
  7423. Matrix4.prototype.ortho = function (left, right, bottom, top, near, far) {
  7424. this.identity();
  7425. var x_orth = 2 / (right - left);
  7426. var y_orth = 2 / (top - bottom);
  7427. var z_orth = -2 / (far - near);
  7428. var tx = -(right + left) / (right - left);
  7429. var ty = -(top + bottom) / (top - bottom);
  7430. var tz = -(far + near) / (far - near);
  7431. var v = this.values;
  7432. v[webgl.M00] = x_orth;
  7433. v[webgl.M10] = 0;
  7434. v[webgl.M20] = 0;
  7435. v[webgl.M30] = 0;
  7436. v[webgl.M01] = 0;
  7437. v[webgl.M11] = y_orth;
  7438. v[webgl.M21] = 0;
  7439. v[webgl.M31] = 0;
  7440. v[webgl.M02] = 0;
  7441. v[webgl.M12] = 0;
  7442. v[webgl.M22] = z_orth;
  7443. v[webgl.M32] = 0;
  7444. v[webgl.M03] = tx;
  7445. v[webgl.M13] = ty;
  7446. v[webgl.M23] = tz;
  7447. v[webgl.M33] = 1;
  7448. return this;
  7449. };
  7450. Matrix4.prototype.multiply = function (matrix) {
  7451. var t = this.temp;
  7452. var v = this.values;
  7453. var m = matrix.values;
  7454. 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];
  7455. 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];
  7456. 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];
  7457. 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];
  7458. 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];
  7459. 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];
  7460. 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];
  7461. 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];
  7462. 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];
  7463. 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];
  7464. 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];
  7465. 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];
  7466. 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];
  7467. 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];
  7468. 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];
  7469. 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];
  7470. return this.set(this.temp);
  7471. };
  7472. Matrix4.prototype.multiplyLeft = function (matrix) {
  7473. var t = this.temp;
  7474. var v = this.values;
  7475. var m = matrix.values;
  7476. 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];
  7477. 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];
  7478. 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];
  7479. 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];
  7480. 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];
  7481. 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];
  7482. 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];
  7483. 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];
  7484. 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];
  7485. 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];
  7486. 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];
  7487. 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];
  7488. 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];
  7489. 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];
  7490. 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];
  7491. 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];
  7492. return this.set(this.temp);
  7493. };
  7494. Matrix4.prototype.lookAt = function (position, direction, up) {
  7495. Matrix4.initTemps();
  7496. var xAxis = Matrix4.xAxis, yAxis = Matrix4.yAxis, zAxis = Matrix4.zAxis;
  7497. zAxis.setFrom(direction).normalize();
  7498. xAxis.setFrom(direction).normalize();
  7499. xAxis.cross(up).normalize();
  7500. yAxis.setFrom(xAxis).cross(zAxis).normalize();
  7501. this.identity();
  7502. var val = this.values;
  7503. val[webgl.M00] = xAxis.x;
  7504. val[webgl.M01] = xAxis.y;
  7505. val[webgl.M02] = xAxis.z;
  7506. val[webgl.M10] = yAxis.x;
  7507. val[webgl.M11] = yAxis.y;
  7508. val[webgl.M12] = yAxis.z;
  7509. val[webgl.M20] = -zAxis.x;
  7510. val[webgl.M21] = -zAxis.y;
  7511. val[webgl.M22] = -zAxis.z;
  7512. Matrix4.tmpMatrix.identity();
  7513. Matrix4.tmpMatrix.values[webgl.M03] = -position.x;
  7514. Matrix4.tmpMatrix.values[webgl.M13] = -position.y;
  7515. Matrix4.tmpMatrix.values[webgl.M23] = -position.z;
  7516. this.multiply(Matrix4.tmpMatrix);
  7517. return this;
  7518. };
  7519. Matrix4.initTemps = function () {
  7520. if (Matrix4.xAxis === null)
  7521. Matrix4.xAxis = new webgl.Vector3();
  7522. if (Matrix4.yAxis === null)
  7523. Matrix4.yAxis = new webgl.Vector3();
  7524. if (Matrix4.zAxis === null)
  7525. Matrix4.zAxis = new webgl.Vector3();
  7526. };
  7527. Matrix4.xAxis = null;
  7528. Matrix4.yAxis = null;
  7529. Matrix4.zAxis = null;
  7530. Matrix4.tmpMatrix = new Matrix4();
  7531. return Matrix4;
  7532. }());
  7533. webgl.Matrix4 = Matrix4;
  7534. })(webgl = spine.webgl || (spine.webgl = {}));
  7535. })(spine || (spine = {}));
  7536. var spine;
  7537. (function (spine) {
  7538. var webgl;
  7539. (function (webgl) {
  7540. var Mesh = (function () {
  7541. function Mesh(context, attributes, maxVertices, maxIndices) {
  7542. this.attributes = attributes;
  7543. this.verticesLength = 0;
  7544. this.dirtyVertices = false;
  7545. this.indicesLength = 0;
  7546. this.dirtyIndices = false;
  7547. this.elementsPerVertex = 0;
  7548. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7549. this.elementsPerVertex = 0;
  7550. for (var i = 0; i < attributes.length; i++) {
  7551. this.elementsPerVertex += attributes[i].numElements;
  7552. }
  7553. this.vertices = new Float32Array(maxVertices * this.elementsPerVertex);
  7554. this.indices = new Uint16Array(maxIndices);
  7555. this.context.addRestorable(this);
  7556. }
  7557. Mesh.prototype.getAttributes = function () { return this.attributes; };
  7558. Mesh.prototype.maxVertices = function () { return this.vertices.length / this.elementsPerVertex; };
  7559. Mesh.prototype.numVertices = function () { return this.verticesLength / this.elementsPerVertex; };
  7560. Mesh.prototype.setVerticesLength = function (length) {
  7561. this.dirtyVertices = true;
  7562. this.verticesLength = length;
  7563. };
  7564. Mesh.prototype.getVertices = function () { return this.vertices; };
  7565. Mesh.prototype.maxIndices = function () { return this.indices.length; };
  7566. Mesh.prototype.numIndices = function () { return this.indicesLength; };
  7567. Mesh.prototype.setIndicesLength = function (length) {
  7568. this.dirtyIndices = true;
  7569. this.indicesLength = length;
  7570. };
  7571. Mesh.prototype.getIndices = function () { return this.indices; };
  7572. ;
  7573. Mesh.prototype.getVertexSizeInFloats = function () {
  7574. var size = 0;
  7575. for (var i = 0; i < this.attributes.length; i++) {
  7576. var attribute = this.attributes[i];
  7577. size += attribute.numElements;
  7578. }
  7579. return size;
  7580. };
  7581. Mesh.prototype.setVertices = function (vertices) {
  7582. this.dirtyVertices = true;
  7583. if (vertices.length > this.vertices.length)
  7584. throw Error("Mesh can't store more than " + this.maxVertices() + " vertices");
  7585. this.vertices.set(vertices, 0);
  7586. this.verticesLength = vertices.length;
  7587. };
  7588. Mesh.prototype.setIndices = function (indices) {
  7589. this.dirtyIndices = true;
  7590. if (indices.length > this.indices.length)
  7591. throw Error("Mesh can't store more than " + this.maxIndices() + " indices");
  7592. this.indices.set(indices, 0);
  7593. this.indicesLength = indices.length;
  7594. };
  7595. Mesh.prototype.draw = function (shader, primitiveType) {
  7596. this.drawWithOffset(shader, primitiveType, 0, this.indicesLength > 0 ? this.indicesLength : this.verticesLength / this.elementsPerVertex);
  7597. };
  7598. Mesh.prototype.drawWithOffset = function (shader, primitiveType, offset, count) {
  7599. var gl = this.context.gl;
  7600. if (this.dirtyVertices || this.dirtyIndices)
  7601. this.update();
  7602. this.bind(shader);
  7603. if (this.indicesLength > 0) {
  7604. gl.drawElements(primitiveType, count, gl.UNSIGNED_SHORT, offset * 2);
  7605. }
  7606. else {
  7607. gl.drawArrays(primitiveType, offset, count);
  7608. }
  7609. this.unbind(shader);
  7610. };
  7611. Mesh.prototype.bind = function (shader) {
  7612. var gl = this.context.gl;
  7613. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  7614. var offset = 0;
  7615. for (var i = 0; i < this.attributes.length; i++) {
  7616. var attrib = this.attributes[i];
  7617. var location_1 = shader.getAttributeLocation(attrib.name);
  7618. gl.enableVertexAttribArray(location_1);
  7619. gl.vertexAttribPointer(location_1, attrib.numElements, gl.FLOAT, false, this.elementsPerVertex * 4, offset * 4);
  7620. offset += attrib.numElements;
  7621. }
  7622. if (this.indicesLength > 0)
  7623. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  7624. };
  7625. Mesh.prototype.unbind = function (shader) {
  7626. var gl = this.context.gl;
  7627. for (var i = 0; i < this.attributes.length; i++) {
  7628. var attrib = this.attributes[i];
  7629. var location_2 = shader.getAttributeLocation(attrib.name);
  7630. gl.disableVertexAttribArray(location_2);
  7631. }
  7632. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  7633. if (this.indicesLength > 0)
  7634. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
  7635. };
  7636. Mesh.prototype.update = function () {
  7637. var gl = this.context.gl;
  7638. if (this.dirtyVertices) {
  7639. if (!this.verticesBuffer) {
  7640. this.verticesBuffer = gl.createBuffer();
  7641. }
  7642. gl.bindBuffer(gl.ARRAY_BUFFER, this.verticesBuffer);
  7643. gl.bufferData(gl.ARRAY_BUFFER, this.vertices.subarray(0, this.verticesLength), gl.DYNAMIC_DRAW);
  7644. this.dirtyVertices = false;
  7645. }
  7646. if (this.dirtyIndices) {
  7647. if (!this.indicesBuffer) {
  7648. this.indicesBuffer = gl.createBuffer();
  7649. }
  7650. gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer);
  7651. gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices.subarray(0, this.indicesLength), gl.DYNAMIC_DRAW);
  7652. this.dirtyIndices = false;
  7653. }
  7654. };
  7655. Mesh.prototype.restore = function () {
  7656. this.verticesBuffer = null;
  7657. this.indicesBuffer = null;
  7658. this.update();
  7659. };
  7660. Mesh.prototype.dispose = function () {
  7661. this.context.removeRestorable(this);
  7662. var gl = this.context.gl;
  7663. gl.deleteBuffer(this.verticesBuffer);
  7664. gl.deleteBuffer(this.indicesBuffer);
  7665. };
  7666. return Mesh;
  7667. }());
  7668. webgl.Mesh = Mesh;
  7669. var VertexAttribute = (function () {
  7670. function VertexAttribute(name, type, numElements) {
  7671. this.name = name;
  7672. this.type = type;
  7673. this.numElements = numElements;
  7674. }
  7675. return VertexAttribute;
  7676. }());
  7677. webgl.VertexAttribute = VertexAttribute;
  7678. var Position2Attribute = (function (_super) {
  7679. __extends(Position2Attribute, _super);
  7680. function Position2Attribute() {
  7681. _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 2);
  7682. }
  7683. return Position2Attribute;
  7684. }(VertexAttribute));
  7685. webgl.Position2Attribute = Position2Attribute;
  7686. var Position3Attribute = (function (_super) {
  7687. __extends(Position3Attribute, _super);
  7688. function Position3Attribute() {
  7689. _super.call(this, webgl.Shader.POSITION, VertexAttributeType.Float, 3);
  7690. }
  7691. return Position3Attribute;
  7692. }(VertexAttribute));
  7693. webgl.Position3Attribute = Position3Attribute;
  7694. var TexCoordAttribute = (function (_super) {
  7695. __extends(TexCoordAttribute, _super);
  7696. function TexCoordAttribute(unit) {
  7697. if (unit === void 0) { unit = 0; }
  7698. _super.call(this, webgl.Shader.TEXCOORDS + (unit == 0 ? "" : unit), VertexAttributeType.Float, 2);
  7699. }
  7700. return TexCoordAttribute;
  7701. }(VertexAttribute));
  7702. webgl.TexCoordAttribute = TexCoordAttribute;
  7703. var ColorAttribute = (function (_super) {
  7704. __extends(ColorAttribute, _super);
  7705. function ColorAttribute() {
  7706. _super.call(this, webgl.Shader.COLOR, VertexAttributeType.Float, 4);
  7707. }
  7708. return ColorAttribute;
  7709. }(VertexAttribute));
  7710. webgl.ColorAttribute = ColorAttribute;
  7711. var Color2Attribute = (function (_super) {
  7712. __extends(Color2Attribute, _super);
  7713. function Color2Attribute() {
  7714. _super.call(this, webgl.Shader.COLOR2, VertexAttributeType.Float, 4);
  7715. }
  7716. return Color2Attribute;
  7717. }(VertexAttribute));
  7718. webgl.Color2Attribute = Color2Attribute;
  7719. (function (VertexAttributeType) {
  7720. VertexAttributeType[VertexAttributeType["Float"] = 0] = "Float";
  7721. })(webgl.VertexAttributeType || (webgl.VertexAttributeType = {}));
  7722. var VertexAttributeType = webgl.VertexAttributeType;
  7723. })(webgl = spine.webgl || (spine.webgl = {}));
  7724. })(spine || (spine = {}));
  7725. var spine;
  7726. (function (spine) {
  7727. var webgl;
  7728. (function (webgl) {
  7729. var PolygonBatcher = (function () {
  7730. function PolygonBatcher(context, twoColorTint, maxVertices) {
  7731. if (twoColorTint === void 0) { twoColorTint = true; }
  7732. if (maxVertices === void 0) { maxVertices = 10920; }
  7733. this.isDrawing = false;
  7734. this.shader = null;
  7735. this.lastTexture = null;
  7736. this.verticesLength = 0;
  7737. this.indicesLength = 0;
  7738. if (maxVertices > 10920)
  7739. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  7740. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7741. var attributes = twoColorTint ?
  7742. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute(), new webgl.Color2Attribute()] :
  7743. [new webgl.Position2Attribute(), new webgl.ColorAttribute(), new webgl.TexCoordAttribute()];
  7744. this.mesh = new webgl.Mesh(context, attributes, maxVertices, maxVertices * 3);
  7745. this.srcBlend = this.context.gl.SRC_ALPHA;
  7746. this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
  7747. }
  7748. PolygonBatcher.prototype.begin = function (shader) {
  7749. var gl = this.context.gl;
  7750. if (this.isDrawing)
  7751. throw new Error("PolygonBatch is already drawing. Call PolygonBatch.end() before calling PolygonBatch.begin()");
  7752. this.drawCalls = 0;
  7753. this.shader = shader;
  7754. this.lastTexture = null;
  7755. this.isDrawing = true;
  7756. gl.enable(gl.BLEND);
  7757. gl.blendFunc(this.srcBlend, this.dstBlend);
  7758. };
  7759. PolygonBatcher.prototype.setBlendMode = function (srcBlend, dstBlend) {
  7760. var gl = this.context.gl;
  7761. this.srcBlend = srcBlend;
  7762. this.dstBlend = dstBlend;
  7763. if (this.isDrawing) {
  7764. this.flush();
  7765. gl.blendFunc(this.srcBlend, this.dstBlend);
  7766. }
  7767. };
  7768. PolygonBatcher.prototype.draw = function (texture, vertices, indices) {
  7769. if (texture != this.lastTexture) {
  7770. this.flush();
  7771. this.lastTexture = texture;
  7772. }
  7773. else if (this.verticesLength + vertices.length > this.mesh.getVertices().length ||
  7774. this.indicesLength + indices.length > this.mesh.getIndices().length) {
  7775. this.flush();
  7776. }
  7777. var indexStart = this.mesh.numVertices();
  7778. this.mesh.getVertices().set(vertices, this.verticesLength);
  7779. this.verticesLength += vertices.length;
  7780. this.mesh.setVerticesLength(this.verticesLength);
  7781. var indicesArray = this.mesh.getIndices();
  7782. for (var i = this.indicesLength, j = 0; j < indices.length; i++, j++)
  7783. indicesArray[i] = indices[j] + indexStart;
  7784. this.indicesLength += indices.length;
  7785. this.mesh.setIndicesLength(this.indicesLength);
  7786. };
  7787. PolygonBatcher.prototype.flush = function () {
  7788. var gl = this.context.gl;
  7789. if (this.verticesLength == 0)
  7790. return;
  7791. this.lastTexture.bind();
  7792. this.mesh.draw(this.shader, gl.TRIANGLES);
  7793. this.verticesLength = 0;
  7794. this.indicesLength = 0;
  7795. this.mesh.setVerticesLength(0);
  7796. this.mesh.setIndicesLength(0);
  7797. this.drawCalls++;
  7798. };
  7799. PolygonBatcher.prototype.end = function () {
  7800. var gl = this.context.gl;
  7801. if (!this.isDrawing)
  7802. throw new Error("PolygonBatch is not drawing. Call PolygonBatch.begin() before calling PolygonBatch.end()");
  7803. if (this.verticesLength > 0 || this.indicesLength > 0)
  7804. this.flush();
  7805. this.shader = null;
  7806. this.lastTexture = null;
  7807. this.isDrawing = false;
  7808. gl.disable(gl.BLEND);
  7809. };
  7810. PolygonBatcher.prototype.getDrawCalls = function () { return this.drawCalls; };
  7811. PolygonBatcher.prototype.dispose = function () {
  7812. this.mesh.dispose();
  7813. };
  7814. return PolygonBatcher;
  7815. }());
  7816. webgl.PolygonBatcher = PolygonBatcher;
  7817. })(webgl = spine.webgl || (spine.webgl = {}));
  7818. })(spine || (spine = {}));
  7819. var spine;
  7820. (function (spine) {
  7821. var webgl;
  7822. (function (webgl) {
  7823. var SceneRenderer = (function () {
  7824. function SceneRenderer(canvas, context, twoColorTint) {
  7825. if (twoColorTint === void 0) { twoColorTint = true; }
  7826. this.twoColorTint = false;
  7827. this.activeRenderer = null;
  7828. this.QUAD = [
  7829. 0, 0, 1, 1, 1, 1, 0, 0,
  7830. 0, 0, 1, 1, 1, 1, 0, 0,
  7831. 0, 0, 1, 1, 1, 1, 0, 0,
  7832. 0, 0, 1, 1, 1, 1, 0, 0,
  7833. ];
  7834. this.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  7835. this.WHITE = new spine.Color(1, 1, 1, 1);
  7836. this.canvas = canvas;
  7837. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  7838. this.twoColorTint = twoColorTint;
  7839. this.camera = new webgl.OrthoCamera(canvas.width, canvas.height);
  7840. this.batcherShader = twoColorTint ? webgl.Shader.newTwoColoredTextured(this.context) : webgl.Shader.newColoredTextured(this.context);
  7841. this.batcher = new webgl.PolygonBatcher(this.context, twoColorTint);
  7842. this.shapesShader = webgl.Shader.newColored(this.context);
  7843. this.shapes = new webgl.ShapeRenderer(this.context);
  7844. this.skeletonRenderer = new webgl.SkeletonRenderer(this.context, twoColorTint);
  7845. this.skeletonDebugRenderer = new webgl.SkeletonDebugRenderer(this.context);
  7846. }
  7847. SceneRenderer.prototype.begin = function () {
  7848. this.camera.update();
  7849. this.enableRenderer(this.batcher);
  7850. };
  7851. SceneRenderer.prototype.drawSkeleton = function (skeleton, premultipliedAlpha) {
  7852. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7853. this.enableRenderer(this.batcher);
  7854. this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
  7855. this.skeletonRenderer.draw(this.batcher, skeleton);
  7856. };
  7857. SceneRenderer.prototype.drawSkeletonDebug = function (skeleton, premultipliedAlpha, ignoredBones) {
  7858. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7859. if (ignoredBones === void 0) { ignoredBones = null; }
  7860. this.enableRenderer(this.shapes);
  7861. this.skeletonDebugRenderer.premultipliedAlpha = premultipliedAlpha;
  7862. this.skeletonDebugRenderer.draw(this.shapes, skeleton, ignoredBones);
  7863. };
  7864. SceneRenderer.prototype.drawTexture = function (texture, x, y, width, height, color) {
  7865. if (color === void 0) { color = null; }
  7866. this.enableRenderer(this.batcher);
  7867. if (color === null)
  7868. color = this.WHITE;
  7869. var quad = this.QUAD;
  7870. var i = 0;
  7871. quad[i++] = x;
  7872. quad[i++] = y;
  7873. quad[i++] = color.r;
  7874. quad[i++] = color.g;
  7875. quad[i++] = color.b;
  7876. quad[i++] = color.a;
  7877. quad[i++] = 0;
  7878. quad[i++] = 1;
  7879. if (this.twoColorTint) {
  7880. quad[i++] = 0;
  7881. quad[i++] = 0;
  7882. quad[i++] = 0;
  7883. quad[i++] = 0;
  7884. }
  7885. quad[i++] = x + width;
  7886. quad[i++] = y;
  7887. quad[i++] = color.r;
  7888. quad[i++] = color.g;
  7889. quad[i++] = color.b;
  7890. quad[i++] = color.a;
  7891. quad[i++] = 1;
  7892. quad[i++] = 1;
  7893. if (this.twoColorTint) {
  7894. quad[i++] = 0;
  7895. quad[i++] = 0;
  7896. quad[i++] = 0;
  7897. quad[i++] = 0;
  7898. }
  7899. quad[i++] = x + width;
  7900. quad[i++] = y + height;
  7901. quad[i++] = color.r;
  7902. quad[i++] = color.g;
  7903. quad[i++] = color.b;
  7904. quad[i++] = color.a;
  7905. quad[i++] = 1;
  7906. quad[i++] = 0;
  7907. if (this.twoColorTint) {
  7908. quad[i++] = 0;
  7909. quad[i++] = 0;
  7910. quad[i++] = 0;
  7911. quad[i++] = 0;
  7912. }
  7913. quad[i++] = x;
  7914. quad[i++] = y + height;
  7915. quad[i++] = color.r;
  7916. quad[i++] = color.g;
  7917. quad[i++] = color.b;
  7918. quad[i++] = color.a;
  7919. quad[i++] = 0;
  7920. quad[i++] = 0;
  7921. if (this.twoColorTint) {
  7922. quad[i++] = 0;
  7923. quad[i++] = 0;
  7924. quad[i++] = 0;
  7925. quad[i++] = 0;
  7926. }
  7927. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  7928. };
  7929. SceneRenderer.prototype.drawTextureRotated = function (texture, x, y, width, height, pivotX, pivotY, angle, color, premultipliedAlpha) {
  7930. if (color === void 0) { color = null; }
  7931. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  7932. this.enableRenderer(this.batcher);
  7933. if (color === null)
  7934. color = this.WHITE;
  7935. var quad = this.QUAD;
  7936. var worldOriginX = x + pivotX;
  7937. var worldOriginY = y + pivotY;
  7938. var fx = -pivotX;
  7939. var fy = -pivotY;
  7940. var fx2 = width - pivotX;
  7941. var fy2 = height - pivotY;
  7942. var p1x = fx;
  7943. var p1y = fy;
  7944. var p2x = fx;
  7945. var p2y = fy2;
  7946. var p3x = fx2;
  7947. var p3y = fy2;
  7948. var p4x = fx2;
  7949. var p4y = fy;
  7950. var x1 = 0;
  7951. var y1 = 0;
  7952. var x2 = 0;
  7953. var y2 = 0;
  7954. var x3 = 0;
  7955. var y3 = 0;
  7956. var x4 = 0;
  7957. var y4 = 0;
  7958. if (angle != 0) {
  7959. var cos = spine.MathUtils.cosDeg(angle);
  7960. var sin = spine.MathUtils.sinDeg(angle);
  7961. x1 = cos * p1x - sin * p1y;
  7962. y1 = sin * p1x + cos * p1y;
  7963. x4 = cos * p2x - sin * p2y;
  7964. y4 = sin * p2x + cos * p2y;
  7965. x3 = cos * p3x - sin * p3y;
  7966. y3 = sin * p3x + cos * p3y;
  7967. x2 = x3 + (x1 - x4);
  7968. y2 = y3 + (y1 - y4);
  7969. }
  7970. else {
  7971. x1 = p1x;
  7972. y1 = p1y;
  7973. x4 = p2x;
  7974. y4 = p2y;
  7975. x3 = p3x;
  7976. y3 = p3y;
  7977. x2 = p4x;
  7978. y2 = p4y;
  7979. }
  7980. x1 += worldOriginX;
  7981. y1 += worldOriginY;
  7982. x2 += worldOriginX;
  7983. y2 += worldOriginY;
  7984. x3 += worldOriginX;
  7985. y3 += worldOriginY;
  7986. x4 += worldOriginX;
  7987. y4 += worldOriginY;
  7988. var i = 0;
  7989. quad[i++] = x1;
  7990. quad[i++] = y1;
  7991. quad[i++] = color.r;
  7992. quad[i++] = color.g;
  7993. quad[i++] = color.b;
  7994. quad[i++] = color.a;
  7995. quad[i++] = 0;
  7996. quad[i++] = 1;
  7997. if (this.twoColorTint) {
  7998. quad[i++] = 0;
  7999. quad[i++] = 0;
  8000. quad[i++] = 0;
  8001. quad[i++] = 0;
  8002. }
  8003. quad[i++] = x2;
  8004. quad[i++] = y2;
  8005. quad[i++] = color.r;
  8006. quad[i++] = color.g;
  8007. quad[i++] = color.b;
  8008. quad[i++] = color.a;
  8009. quad[i++] = 1;
  8010. quad[i++] = 1;
  8011. if (this.twoColorTint) {
  8012. quad[i++] = 0;
  8013. quad[i++] = 0;
  8014. quad[i++] = 0;
  8015. quad[i++] = 0;
  8016. }
  8017. quad[i++] = x3;
  8018. quad[i++] = y3;
  8019. quad[i++] = color.r;
  8020. quad[i++] = color.g;
  8021. quad[i++] = color.b;
  8022. quad[i++] = color.a;
  8023. quad[i++] = 1;
  8024. quad[i++] = 0;
  8025. if (this.twoColorTint) {
  8026. quad[i++] = 0;
  8027. quad[i++] = 0;
  8028. quad[i++] = 0;
  8029. quad[i++] = 0;
  8030. }
  8031. quad[i++] = x4;
  8032. quad[i++] = y4;
  8033. quad[i++] = color.r;
  8034. quad[i++] = color.g;
  8035. quad[i++] = color.b;
  8036. quad[i++] = color.a;
  8037. quad[i++] = 0;
  8038. quad[i++] = 0;
  8039. if (this.twoColorTint) {
  8040. quad[i++] = 0;
  8041. quad[i++] = 0;
  8042. quad[i++] = 0;
  8043. quad[i++] = 0;
  8044. }
  8045. this.batcher.draw(texture, quad, this.QUAD_TRIANGLES);
  8046. };
  8047. SceneRenderer.prototype.drawRegion = function (region, x, y, width, height, color, premultipliedAlpha) {
  8048. if (color === void 0) { color = null; }
  8049. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  8050. this.enableRenderer(this.batcher);
  8051. if (color === null)
  8052. color = this.WHITE;
  8053. var quad = this.QUAD;
  8054. var i = 0;
  8055. quad[i++] = x;
  8056. quad[i++] = y;
  8057. quad[i++] = color.r;
  8058. quad[i++] = color.g;
  8059. quad[i++] = color.b;
  8060. quad[i++] = color.a;
  8061. quad[i++] = region.u;
  8062. quad[i++] = region.v2;
  8063. if (this.twoColorTint) {
  8064. quad[i++] = 0;
  8065. quad[i++] = 0;
  8066. quad[i++] = 0;
  8067. quad[i++] = 0;
  8068. }
  8069. quad[i++] = x + width;
  8070. quad[i++] = y;
  8071. quad[i++] = color.r;
  8072. quad[i++] = color.g;
  8073. quad[i++] = color.b;
  8074. quad[i++] = color.a;
  8075. quad[i++] = region.u2;
  8076. quad[i++] = region.v2;
  8077. if (this.twoColorTint) {
  8078. quad[i++] = 0;
  8079. quad[i++] = 0;
  8080. quad[i++] = 0;
  8081. quad[i++] = 0;
  8082. }
  8083. quad[i++] = x + width;
  8084. quad[i++] = y + height;
  8085. quad[i++] = color.r;
  8086. quad[i++] = color.g;
  8087. quad[i++] = color.b;
  8088. quad[i++] = color.a;
  8089. quad[i++] = region.u2;
  8090. quad[i++] = region.v;
  8091. if (this.twoColorTint) {
  8092. quad[i++] = 0;
  8093. quad[i++] = 0;
  8094. quad[i++] = 0;
  8095. quad[i++] = 0;
  8096. }
  8097. quad[i++] = x;
  8098. quad[i++] = y + height;
  8099. quad[i++] = color.r;
  8100. quad[i++] = color.g;
  8101. quad[i++] = color.b;
  8102. quad[i++] = color.a;
  8103. quad[i++] = region.u;
  8104. quad[i++] = region.v;
  8105. if (this.twoColorTint) {
  8106. quad[i++] = 0;
  8107. quad[i++] = 0;
  8108. quad[i++] = 0;
  8109. quad[i++] = 0;
  8110. }
  8111. this.batcher.draw(region.texture, quad, this.QUAD_TRIANGLES);
  8112. };
  8113. SceneRenderer.prototype.line = function (x, y, x2, y2, color, color2) {
  8114. if (color === void 0) { color = null; }
  8115. if (color2 === void 0) { color2 = null; }
  8116. this.enableRenderer(this.shapes);
  8117. this.shapes.line(x, y, x2, y2, color);
  8118. };
  8119. SceneRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  8120. if (color === void 0) { color = null; }
  8121. if (color2 === void 0) { color2 = null; }
  8122. if (color3 === void 0) { color3 = null; }
  8123. this.enableRenderer(this.shapes);
  8124. this.shapes.triangle(filled, x, y, x2, y2, x3, y3, color, color2, color3);
  8125. };
  8126. SceneRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  8127. if (color === void 0) { color = null; }
  8128. if (color2 === void 0) { color2 = null; }
  8129. if (color3 === void 0) { color3 = null; }
  8130. if (color4 === void 0) { color4 = null; }
  8131. this.enableRenderer(this.shapes);
  8132. this.shapes.quad(filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4);
  8133. };
  8134. SceneRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  8135. if (color === void 0) { color = null; }
  8136. this.enableRenderer(this.shapes);
  8137. this.shapes.rect(filled, x, y, width, height, color);
  8138. };
  8139. SceneRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  8140. if (color === void 0) { color = null; }
  8141. this.enableRenderer(this.shapes);
  8142. this.shapes.rectLine(filled, x1, y1, x2, y2, width, color);
  8143. };
  8144. SceneRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  8145. if (color === void 0) { color = null; }
  8146. this.enableRenderer(this.shapes);
  8147. this.shapes.polygon(polygonVertices, offset, count, color);
  8148. };
  8149. SceneRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  8150. if (color === void 0) { color = null; }
  8151. if (segments === void 0) { segments = 0; }
  8152. this.enableRenderer(this.shapes);
  8153. this.shapes.circle(filled, x, y, radius, color, segments);
  8154. };
  8155. SceneRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  8156. if (color === void 0) { color = null; }
  8157. this.enableRenderer(this.shapes);
  8158. this.shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color);
  8159. };
  8160. SceneRenderer.prototype.end = function () {
  8161. if (this.activeRenderer === this.batcher)
  8162. this.batcher.end();
  8163. else if (this.activeRenderer === this.shapes)
  8164. this.shapes.end();
  8165. this.activeRenderer = null;
  8166. };
  8167. SceneRenderer.prototype.resize = function (resizeMode) {
  8168. var canvas = this.canvas;
  8169. var w = canvas.clientWidth;
  8170. var h = canvas.clientHeight;
  8171. if (canvas.width != w || canvas.height != h) {
  8172. canvas.width = w;
  8173. canvas.height = h;
  8174. }
  8175. this.context.gl.viewport(0, 0, canvas.width, canvas.height);
  8176. if (resizeMode === ResizeMode.Stretch) {
  8177. }
  8178. else if (resizeMode === ResizeMode.Expand) {
  8179. this.camera.setViewport(w, h);
  8180. }
  8181. else if (resizeMode === ResizeMode.Fit) {
  8182. var sourceWidth = canvas.width, sourceHeight = canvas.height;
  8183. var targetWidth = this.camera.viewportWidth, targetHeight = this.camera.viewportHeight;
  8184. var targetRatio = targetHeight / targetWidth;
  8185. var sourceRatio = sourceHeight / sourceWidth;
  8186. var scale = targetRatio < sourceRatio ? targetWidth / sourceWidth : targetHeight / sourceHeight;
  8187. this.camera.viewportWidth = sourceWidth * scale;
  8188. this.camera.viewportHeight = sourceHeight * scale;
  8189. }
  8190. this.camera.update();
  8191. };
  8192. SceneRenderer.prototype.enableRenderer = function (renderer) {
  8193. if (this.activeRenderer === renderer)
  8194. return;
  8195. this.end();
  8196. if (renderer instanceof webgl.PolygonBatcher) {
  8197. this.batcherShader.bind();
  8198. this.batcherShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  8199. this.batcherShader.setUniformi("u_texture", 0);
  8200. this.batcher.begin(this.batcherShader);
  8201. this.activeRenderer = this.batcher;
  8202. }
  8203. else if (renderer instanceof webgl.ShapeRenderer) {
  8204. this.shapesShader.bind();
  8205. this.shapesShader.setUniform4x4f(webgl.Shader.MVP_MATRIX, this.camera.projectionView.values);
  8206. this.shapes.begin(this.shapesShader);
  8207. this.activeRenderer = this.shapes;
  8208. }
  8209. else {
  8210. this.activeRenderer = this.skeletonDebugRenderer;
  8211. }
  8212. };
  8213. SceneRenderer.prototype.dispose = function () {
  8214. this.batcher.dispose();
  8215. this.batcherShader.dispose();
  8216. this.shapes.dispose();
  8217. this.shapesShader.dispose();
  8218. this.skeletonDebugRenderer.dispose();
  8219. };
  8220. return SceneRenderer;
  8221. }());
  8222. webgl.SceneRenderer = SceneRenderer;
  8223. (function (ResizeMode) {
  8224. ResizeMode[ResizeMode["Stretch"] = 0] = "Stretch";
  8225. ResizeMode[ResizeMode["Expand"] = 1] = "Expand";
  8226. ResizeMode[ResizeMode["Fit"] = 2] = "Fit";
  8227. })(webgl.ResizeMode || (webgl.ResizeMode = {}));
  8228. var ResizeMode = webgl.ResizeMode;
  8229. })(webgl = spine.webgl || (spine.webgl = {}));
  8230. })(spine || (spine = {}));
  8231. var spine;
  8232. (function (spine) {
  8233. var webgl;
  8234. (function (webgl) {
  8235. var Shader = (function () {
  8236. function Shader(context, vertexShader, fragmentShader) {
  8237. this.vertexShader = vertexShader;
  8238. this.fragmentShader = fragmentShader;
  8239. this.vs = null;
  8240. this.fs = null;
  8241. this.program = null;
  8242. this.tmp2x2 = new Float32Array(2 * 2);
  8243. this.tmp3x3 = new Float32Array(3 * 3);
  8244. this.tmp4x4 = new Float32Array(4 * 4);
  8245. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8246. this.context.addRestorable(this);
  8247. this.compile();
  8248. }
  8249. Shader.prototype.getProgram = function () { return this.program; };
  8250. Shader.prototype.getVertexShader = function () { return this.vertexShader; };
  8251. Shader.prototype.getFragmentShader = function () { return this.fragmentShader; };
  8252. Shader.prototype.compile = function () {
  8253. var gl = this.context.gl;
  8254. try {
  8255. this.vs = this.compileShader(gl.VERTEX_SHADER, this.vertexShader);
  8256. this.fs = this.compileShader(gl.FRAGMENT_SHADER, this.fragmentShader);
  8257. this.program = this.compileProgram(this.vs, this.fs);
  8258. }
  8259. catch (e) {
  8260. this.dispose();
  8261. throw e;
  8262. }
  8263. };
  8264. Shader.prototype.compileShader = function (type, source) {
  8265. var gl = this.context.gl;
  8266. var shader = gl.createShader(type);
  8267. gl.shaderSource(shader, source);
  8268. gl.compileShader(shader);
  8269. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  8270. var error = "Couldn't compile shader: " + gl.getShaderInfoLog(shader);
  8271. gl.deleteShader(shader);
  8272. if (!gl.isContextLost())
  8273. throw new Error(error);
  8274. }
  8275. return shader;
  8276. };
  8277. Shader.prototype.compileProgram = function (vs, fs) {
  8278. var gl = this.context.gl;
  8279. var program = gl.createProgram();
  8280. gl.attachShader(program, vs);
  8281. gl.attachShader(program, fs);
  8282. gl.linkProgram(program);
  8283. if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  8284. var error = "Couldn't compile shader program: " + gl.getProgramInfoLog(program);
  8285. gl.deleteProgram(program);
  8286. if (!gl.isContextLost())
  8287. throw new Error(error);
  8288. }
  8289. return program;
  8290. };
  8291. Shader.prototype.restore = function () {
  8292. this.compile();
  8293. };
  8294. Shader.prototype.bind = function () {
  8295. this.context.gl.useProgram(this.program);
  8296. };
  8297. Shader.prototype.unbind = function () {
  8298. this.context.gl.useProgram(null);
  8299. };
  8300. Shader.prototype.setUniformi = function (uniform, value) {
  8301. this.context.gl.uniform1i(this.getUniformLocation(uniform), value);
  8302. };
  8303. Shader.prototype.setUniformf = function (uniform, value) {
  8304. this.context.gl.uniform1f(this.getUniformLocation(uniform), value);
  8305. };
  8306. Shader.prototype.setUniform2f = function (uniform, value, value2) {
  8307. this.context.gl.uniform2f(this.getUniformLocation(uniform), value, value2);
  8308. };
  8309. Shader.prototype.setUniform3f = function (uniform, value, value2, value3) {
  8310. this.context.gl.uniform3f(this.getUniformLocation(uniform), value, value2, value3);
  8311. };
  8312. Shader.prototype.setUniform4f = function (uniform, value, value2, value3, value4) {
  8313. this.context.gl.uniform4f(this.getUniformLocation(uniform), value, value2, value3, value4);
  8314. };
  8315. Shader.prototype.setUniform2x2f = function (uniform, value) {
  8316. var gl = this.context.gl;
  8317. this.tmp2x2.set(value);
  8318. gl.uniformMatrix2fv(this.getUniformLocation(uniform), false, this.tmp2x2);
  8319. };
  8320. Shader.prototype.setUniform3x3f = function (uniform, value) {
  8321. var gl = this.context.gl;
  8322. this.tmp3x3.set(value);
  8323. gl.uniformMatrix3fv(this.getUniformLocation(uniform), false, this.tmp3x3);
  8324. };
  8325. Shader.prototype.setUniform4x4f = function (uniform, value) {
  8326. var gl = this.context.gl;
  8327. this.tmp4x4.set(value);
  8328. gl.uniformMatrix4fv(this.getUniformLocation(uniform), false, this.tmp4x4);
  8329. };
  8330. Shader.prototype.getUniformLocation = function (uniform) {
  8331. var gl = this.context.gl;
  8332. var location = gl.getUniformLocation(this.program, uniform);
  8333. if (!location && !gl.isContextLost())
  8334. throw new Error("Couldn't find location for uniform " + uniform);
  8335. return location;
  8336. };
  8337. Shader.prototype.getAttributeLocation = function (attribute) {
  8338. var gl = this.context.gl;
  8339. var location = gl.getAttribLocation(this.program, attribute);
  8340. if (location == -1 && !gl.isContextLost())
  8341. throw new Error("Couldn't find location for attribute " + attribute);
  8342. return location;
  8343. };
  8344. Shader.prototype.dispose = function () {
  8345. this.context.removeRestorable(this);
  8346. var gl = this.context.gl;
  8347. if (this.vs) {
  8348. gl.deleteShader(this.vs);
  8349. this.vs = null;
  8350. }
  8351. if (this.fs) {
  8352. gl.deleteShader(this.fs);
  8353. this.fs = null;
  8354. }
  8355. if (this.program) {
  8356. gl.deleteProgram(this.program);
  8357. this.program = null;
  8358. }
  8359. };
  8360. Shader.newColoredTextured = function (context) {
  8361. 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";
  8362. 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";
  8363. return new Shader(context, vs, fs);
  8364. };
  8365. Shader.newTwoColoredTextured = function (context) {
  8366. 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";
  8367. 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";
  8368. return new Shader(context, vs, fs);
  8369. };
  8370. Shader.newColored = function (context) {
  8371. 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";
  8372. 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";
  8373. return new Shader(context, vs, fs);
  8374. };
  8375. Shader.MVP_MATRIX = "u_projTrans";
  8376. Shader.POSITION = "a_position";
  8377. Shader.COLOR = "a_color";
  8378. Shader.COLOR2 = "a_color2";
  8379. Shader.TEXCOORDS = "a_texCoords";
  8380. Shader.SAMPLER = "u_texture";
  8381. return Shader;
  8382. }());
  8383. webgl.Shader = Shader;
  8384. })(webgl = spine.webgl || (spine.webgl = {}));
  8385. })(spine || (spine = {}));
  8386. var spine;
  8387. (function (spine) {
  8388. var webgl;
  8389. (function (webgl) {
  8390. var ShapeRenderer = (function () {
  8391. function ShapeRenderer(context, maxVertices) {
  8392. if (maxVertices === void 0) { maxVertices = 10920; }
  8393. this.isDrawing = false;
  8394. this.shapeType = ShapeType.Filled;
  8395. this.color = new spine.Color(1, 1, 1, 1);
  8396. this.vertexIndex = 0;
  8397. this.tmp = new spine.Vector2();
  8398. if (maxVertices > 10920)
  8399. throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
  8400. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8401. this.mesh = new webgl.Mesh(context, [new webgl.Position2Attribute(), new webgl.ColorAttribute()], maxVertices, 0);
  8402. this.srcBlend = this.context.gl.SRC_ALPHA;
  8403. this.dstBlend = this.context.gl.ONE_MINUS_SRC_ALPHA;
  8404. }
  8405. ShapeRenderer.prototype.begin = function (shader) {
  8406. if (this.isDrawing)
  8407. throw new Error("ShapeRenderer.begin() has already been called");
  8408. this.shader = shader;
  8409. this.vertexIndex = 0;
  8410. this.isDrawing = true;
  8411. var gl = this.context.gl;
  8412. gl.enable(gl.BLEND);
  8413. gl.blendFunc(this.srcBlend, this.dstBlend);
  8414. };
  8415. ShapeRenderer.prototype.setBlendMode = function (srcBlend, dstBlend) {
  8416. var gl = this.context.gl;
  8417. this.srcBlend = srcBlend;
  8418. this.dstBlend = dstBlend;
  8419. if (this.isDrawing) {
  8420. this.flush();
  8421. gl.blendFunc(this.srcBlend, this.dstBlend);
  8422. }
  8423. };
  8424. ShapeRenderer.prototype.setColor = function (color) {
  8425. this.color.setFromColor(color);
  8426. };
  8427. ShapeRenderer.prototype.setColorWith = function (r, g, b, a) {
  8428. this.color.set(r, g, b, a);
  8429. };
  8430. ShapeRenderer.prototype.point = function (x, y, color) {
  8431. if (color === void 0) { color = null; }
  8432. this.check(ShapeType.Point, 1);
  8433. if (color === null)
  8434. color = this.color;
  8435. this.vertex(x, y, color);
  8436. };
  8437. ShapeRenderer.prototype.line = function (x, y, x2, y2, color) {
  8438. if (color === void 0) { color = null; }
  8439. this.check(ShapeType.Line, 2);
  8440. var vertices = this.mesh.getVertices();
  8441. var idx = this.vertexIndex;
  8442. if (color === null)
  8443. color = this.color;
  8444. this.vertex(x, y, color);
  8445. this.vertex(x2, y2, color);
  8446. };
  8447. ShapeRenderer.prototype.triangle = function (filled, x, y, x2, y2, x3, y3, color, color2, color3) {
  8448. if (color === void 0) { color = null; }
  8449. if (color2 === void 0) { color2 = null; }
  8450. if (color3 === void 0) { color3 = null; }
  8451. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  8452. var vertices = this.mesh.getVertices();
  8453. var idx = this.vertexIndex;
  8454. if (color === null)
  8455. color = this.color;
  8456. if (color2 === null)
  8457. color2 = this.color;
  8458. if (color3 === null)
  8459. color3 = this.color;
  8460. if (filled) {
  8461. this.vertex(x, y, color);
  8462. this.vertex(x2, y2, color2);
  8463. this.vertex(x3, y3, color3);
  8464. }
  8465. else {
  8466. this.vertex(x, y, color);
  8467. this.vertex(x2, y2, color2);
  8468. this.vertex(x2, y2, color);
  8469. this.vertex(x3, y3, color2);
  8470. this.vertex(x3, y3, color);
  8471. this.vertex(x, y, color2);
  8472. }
  8473. };
  8474. ShapeRenderer.prototype.quad = function (filled, x, y, x2, y2, x3, y3, x4, y4, color, color2, color3, color4) {
  8475. if (color === void 0) { color = null; }
  8476. if (color2 === void 0) { color2 = null; }
  8477. if (color3 === void 0) { color3 = null; }
  8478. if (color4 === void 0) { color4 = null; }
  8479. this.check(filled ? ShapeType.Filled : ShapeType.Line, 3);
  8480. var vertices = this.mesh.getVertices();
  8481. var idx = this.vertexIndex;
  8482. if (color === null)
  8483. color = this.color;
  8484. if (color2 === null)
  8485. color2 = this.color;
  8486. if (color3 === null)
  8487. color3 = this.color;
  8488. if (color4 === null)
  8489. color4 = this.color;
  8490. if (filled) {
  8491. this.vertex(x, y, color);
  8492. this.vertex(x2, y2, color2);
  8493. this.vertex(x3, y3, color3);
  8494. this.vertex(x3, y3, color3);
  8495. this.vertex(x4, y4, color4);
  8496. this.vertex(x, y, color);
  8497. }
  8498. else {
  8499. this.vertex(x, y, color);
  8500. this.vertex(x2, y2, color2);
  8501. this.vertex(x2, y2, color2);
  8502. this.vertex(x3, y3, color3);
  8503. this.vertex(x3, y3, color3);
  8504. this.vertex(x4, y4, color4);
  8505. this.vertex(x4, y4, color4);
  8506. this.vertex(x, y, color);
  8507. }
  8508. };
  8509. ShapeRenderer.prototype.rect = function (filled, x, y, width, height, color) {
  8510. if (color === void 0) { color = null; }
  8511. this.quad(filled, x, y, x + width, y, x + width, y + height, x, y + height, color, color, color, color);
  8512. };
  8513. ShapeRenderer.prototype.rectLine = function (filled, x1, y1, x2, y2, width, color) {
  8514. if (color === void 0) { color = null; }
  8515. this.check(filled ? ShapeType.Filled : ShapeType.Line, 8);
  8516. if (color === null)
  8517. color = this.color;
  8518. var t = this.tmp.set(y2 - y1, x1 - x2);
  8519. t.normalize();
  8520. width *= 0.5;
  8521. var tx = t.x * width;
  8522. var ty = t.y * width;
  8523. if (!filled) {
  8524. this.vertex(x1 + tx, y1 + ty, color);
  8525. this.vertex(x1 - tx, y1 - ty, color);
  8526. this.vertex(x2 + tx, y2 + ty, color);
  8527. this.vertex(x2 - tx, y2 - ty, color);
  8528. this.vertex(x2 + tx, y2 + ty, color);
  8529. this.vertex(x1 + tx, y1 + ty, color);
  8530. this.vertex(x2 - tx, y2 - ty, color);
  8531. this.vertex(x1 - tx, y1 - ty, color);
  8532. }
  8533. else {
  8534. this.vertex(x1 + tx, y1 + ty, color);
  8535. this.vertex(x1 - tx, y1 - ty, color);
  8536. this.vertex(x2 + tx, y2 + ty, color);
  8537. this.vertex(x2 - tx, y2 - ty, color);
  8538. this.vertex(x2 + tx, y2 + ty, color);
  8539. this.vertex(x1 - tx, y1 - ty, color);
  8540. }
  8541. };
  8542. ShapeRenderer.prototype.x = function (x, y, size) {
  8543. this.line(x - size, y - size, x + size, y + size);
  8544. this.line(x - size, y + size, x + size, y - size);
  8545. };
  8546. ShapeRenderer.prototype.polygon = function (polygonVertices, offset, count, color) {
  8547. if (color === void 0) { color = null; }
  8548. if (count < 3)
  8549. throw new Error("Polygon must contain at least 3 vertices");
  8550. this.check(ShapeType.Line, count * 2);
  8551. if (color === null)
  8552. color = this.color;
  8553. var vertices = this.mesh.getVertices();
  8554. var idx = this.vertexIndex;
  8555. offset <<= 1;
  8556. count <<= 1;
  8557. var firstX = polygonVertices[offset];
  8558. var firstY = polygonVertices[offset + 1];
  8559. var last = offset + count;
  8560. for (var i = offset, n = offset + count - 2; i < n; i += 2) {
  8561. var x1 = polygonVertices[i];
  8562. var y1 = polygonVertices[i + 1];
  8563. var x2 = 0;
  8564. var y2 = 0;
  8565. if (i + 2 >= last) {
  8566. x2 = firstX;
  8567. y2 = firstY;
  8568. }
  8569. else {
  8570. x2 = polygonVertices[i + 2];
  8571. y2 = polygonVertices[i + 3];
  8572. }
  8573. this.vertex(x1, y1, color);
  8574. this.vertex(x2, y2, color);
  8575. }
  8576. };
  8577. ShapeRenderer.prototype.circle = function (filled, x, y, radius, color, segments) {
  8578. if (color === void 0) { color = null; }
  8579. if (segments === void 0) { segments = 0; }
  8580. if (segments === 0)
  8581. segments = Math.max(1, (6 * spine.MathUtils.cbrt(radius)) | 0);
  8582. if (segments <= 0)
  8583. throw new Error("segments must be > 0.");
  8584. if (color === null)
  8585. color = this.color;
  8586. var angle = 2 * spine.MathUtils.PI / segments;
  8587. var cos = Math.cos(angle);
  8588. var sin = Math.sin(angle);
  8589. var cx = radius, cy = 0;
  8590. if (!filled) {
  8591. this.check(ShapeType.Line, segments * 2 + 2);
  8592. for (var i = 0; i < segments; i++) {
  8593. this.vertex(x + cx, y + cy, color);
  8594. var temp_1 = cx;
  8595. cx = cos * cx - sin * cy;
  8596. cy = sin * temp_1 + cos * cy;
  8597. this.vertex(x + cx, y + cy, color);
  8598. }
  8599. this.vertex(x + cx, y + cy, color);
  8600. }
  8601. else {
  8602. this.check(ShapeType.Filled, segments * 3 + 3);
  8603. segments--;
  8604. for (var i = 0; i < segments; i++) {
  8605. this.vertex(x, y, color);
  8606. this.vertex(x + cx, y + cy, color);
  8607. var temp_2 = cx;
  8608. cx = cos * cx - sin * cy;
  8609. cy = sin * temp_2 + cos * cy;
  8610. this.vertex(x + cx, y + cy, color);
  8611. }
  8612. this.vertex(x, y, color);
  8613. this.vertex(x + cx, y + cy, color);
  8614. }
  8615. var temp = cx;
  8616. cx = radius;
  8617. cy = 0;
  8618. this.vertex(x + cx, y + cy, color);
  8619. };
  8620. ShapeRenderer.prototype.curve = function (x1, y1, cx1, cy1, cx2, cy2, x2, y2, segments, color) {
  8621. if (color === void 0) { color = null; }
  8622. this.check(ShapeType.Line, segments * 2 + 2);
  8623. if (color === null)
  8624. color = this.color;
  8625. var subdiv_step = 1 / segments;
  8626. var subdiv_step2 = subdiv_step * subdiv_step;
  8627. var subdiv_step3 = subdiv_step * subdiv_step * subdiv_step;
  8628. var pre1 = 3 * subdiv_step;
  8629. var pre2 = 3 * subdiv_step2;
  8630. var pre4 = 6 * subdiv_step2;
  8631. var pre5 = 6 * subdiv_step3;
  8632. var tmp1x = x1 - cx1 * 2 + cx2;
  8633. var tmp1y = y1 - cy1 * 2 + cy2;
  8634. var tmp2x = (cx1 - cx2) * 3 - x1 + x2;
  8635. var tmp2y = (cy1 - cy2) * 3 - y1 + y2;
  8636. var fx = x1;
  8637. var fy = y1;
  8638. var dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3;
  8639. var dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3;
  8640. var ddfx = tmp1x * pre4 + tmp2x * pre5;
  8641. var ddfy = tmp1y * pre4 + tmp2y * pre5;
  8642. var dddfx = tmp2x * pre5;
  8643. var dddfy = tmp2y * pre5;
  8644. while (segments-- > 0) {
  8645. this.vertex(fx, fy, color);
  8646. fx += dfx;
  8647. fy += dfy;
  8648. dfx += ddfx;
  8649. dfy += ddfy;
  8650. ddfx += dddfx;
  8651. ddfy += dddfy;
  8652. this.vertex(fx, fy, color);
  8653. }
  8654. this.vertex(fx, fy, color);
  8655. this.vertex(x2, y2, color);
  8656. };
  8657. ShapeRenderer.prototype.vertex = function (x, y, color) {
  8658. var idx = this.vertexIndex;
  8659. var vertices = this.mesh.getVertices();
  8660. vertices[idx++] = x;
  8661. vertices[idx++] = y;
  8662. vertices[idx++] = color.r;
  8663. vertices[idx++] = color.g;
  8664. vertices[idx++] = color.b;
  8665. vertices[idx++] = color.a;
  8666. this.vertexIndex = idx;
  8667. };
  8668. ShapeRenderer.prototype.end = function () {
  8669. if (!this.isDrawing)
  8670. throw new Error("ShapeRenderer.begin() has not been called");
  8671. this.flush();
  8672. this.context.gl.disable(this.context.gl.BLEND);
  8673. this.isDrawing = false;
  8674. };
  8675. ShapeRenderer.prototype.flush = function () {
  8676. if (this.vertexIndex == 0)
  8677. return;
  8678. this.mesh.setVerticesLength(this.vertexIndex);
  8679. this.mesh.draw(this.shader, this.shapeType);
  8680. this.vertexIndex = 0;
  8681. };
  8682. ShapeRenderer.prototype.check = function (shapeType, numVertices) {
  8683. if (!this.isDrawing)
  8684. throw new Error("ShapeRenderer.begin() has not been called");
  8685. if (this.shapeType == shapeType) {
  8686. if (this.mesh.maxVertices() - this.mesh.numVertices() < numVertices)
  8687. this.flush();
  8688. else
  8689. return;
  8690. }
  8691. else {
  8692. this.flush();
  8693. this.shapeType = shapeType;
  8694. }
  8695. };
  8696. ShapeRenderer.prototype.dispose = function () {
  8697. this.mesh.dispose();
  8698. };
  8699. return ShapeRenderer;
  8700. }());
  8701. webgl.ShapeRenderer = ShapeRenderer;
  8702. (function (ShapeType) {
  8703. ShapeType[ShapeType["Point"] = 0] = "Point";
  8704. ShapeType[ShapeType["Line"] = 1] = "Line";
  8705. ShapeType[ShapeType["Filled"] = 4] = "Filled";
  8706. })(webgl.ShapeType || (webgl.ShapeType = {}));
  8707. var ShapeType = webgl.ShapeType;
  8708. })(webgl = spine.webgl || (spine.webgl = {}));
  8709. })(spine || (spine = {}));
  8710. var spine;
  8711. (function (spine) {
  8712. var webgl;
  8713. (function (webgl) {
  8714. var SkeletonDebugRenderer = (function () {
  8715. function SkeletonDebugRenderer(context) {
  8716. this.boneLineColor = new spine.Color(1, 0, 0, 1);
  8717. this.boneOriginColor = new spine.Color(0, 1, 0, 1);
  8718. this.attachmentLineColor = new spine.Color(0, 0, 1, 0.5);
  8719. this.triangleLineColor = new spine.Color(1, 0.64, 0, 0.5);
  8720. this.pathColor = new spine.Color().setFromString("FF7F00");
  8721. this.clipColor = new spine.Color(0.8, 0, 0, 2);
  8722. this.aabbColor = new spine.Color(0, 1, 0, 0.5);
  8723. this.drawBones = true;
  8724. this.drawRegionAttachments = true;
  8725. this.drawBoundingBoxes = true;
  8726. this.drawMeshHull = true;
  8727. this.drawMeshTriangles = true;
  8728. this.drawPaths = true;
  8729. this.drawSkeletonXY = false;
  8730. this.drawClipping = true;
  8731. this.premultipliedAlpha = false;
  8732. this.scale = 1;
  8733. this.boneWidth = 2;
  8734. this.bounds = new spine.SkeletonBounds();
  8735. this.temp = new Array();
  8736. this.vertices = spine.Utils.newFloatArray(2 * 1024);
  8737. this.context = context instanceof webgl.ManagedWebGLRenderingContext ? context : new webgl.ManagedWebGLRenderingContext(context);
  8738. }
  8739. SkeletonDebugRenderer.prototype.draw = function (shapes, skeleton, ignoredBones) {
  8740. if (ignoredBones === void 0) { ignoredBones = null; }
  8741. var skeletonX = skeleton.x;
  8742. var skeletonY = skeleton.y;
  8743. var gl = this.context.gl;
  8744. var srcFunc = this.premultipliedAlpha ? gl.ONE : gl.SRC_ALPHA;
  8745. shapes.setBlendMode(srcFunc, gl.ONE_MINUS_SRC_ALPHA);
  8746. var bones = skeleton.bones;
  8747. if (this.drawBones) {
  8748. shapes.setColor(this.boneLineColor);
  8749. for (var i = 0, n = bones.length; i < n; i++) {
  8750. var bone = bones[i];
  8751. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  8752. continue;
  8753. if (bone.parent == null)
  8754. continue;
  8755. var x = skeletonX + bone.data.length * bone.a + bone.worldX;
  8756. var y = skeletonY + bone.data.length * bone.c + bone.worldY;
  8757. shapes.rectLine(true, skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, this.boneWidth * this.scale);
  8758. }
  8759. if (this.drawSkeletonXY)
  8760. shapes.x(skeletonX, skeletonY, 4 * this.scale);
  8761. }
  8762. if (this.drawRegionAttachments) {
  8763. shapes.setColor(this.attachmentLineColor);
  8764. var slots = skeleton.slots;
  8765. for (var i = 0, n = slots.length; i < n; i++) {
  8766. var slot = slots[i];
  8767. var attachment = slot.getAttachment();
  8768. if (attachment instanceof spine.RegionAttachment) {
  8769. var regionAttachment = attachment;
  8770. var vertices = this.vertices;
  8771. regionAttachment.computeWorldVertices(slot.bone, vertices, 0, 2);
  8772. shapes.line(vertices[0], vertices[1], vertices[2], vertices[3]);
  8773. shapes.line(vertices[2], vertices[3], vertices[4], vertices[5]);
  8774. shapes.line(vertices[4], vertices[5], vertices[6], vertices[7]);
  8775. shapes.line(vertices[6], vertices[7], vertices[0], vertices[1]);
  8776. }
  8777. }
  8778. }
  8779. if (this.drawMeshHull || this.drawMeshTriangles) {
  8780. var slots = skeleton.slots;
  8781. for (var i = 0, n = slots.length; i < n; i++) {
  8782. var slot = slots[i];
  8783. var attachment = slot.getAttachment();
  8784. if (!(attachment instanceof spine.MeshAttachment))
  8785. continue;
  8786. var mesh = attachment;
  8787. var vertices = this.vertices;
  8788. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, vertices, 0, 2);
  8789. var triangles = mesh.triangles;
  8790. var hullLength = mesh.hullLength;
  8791. if (this.drawMeshTriangles) {
  8792. shapes.setColor(this.triangleLineColor);
  8793. for (var ii = 0, nn = triangles.length; ii < nn; ii += 3) {
  8794. var v1 = triangles[ii] * 2, v2 = triangles[ii + 1] * 2, v3 = triangles[ii + 2] * 2;
  8795. shapes.triangle(false, vertices[v1], vertices[v1 + 1], vertices[v2], vertices[v2 + 1], vertices[v3], vertices[v3 + 1]);
  8796. }
  8797. }
  8798. if (this.drawMeshHull && hullLength > 0) {
  8799. shapes.setColor(this.attachmentLineColor);
  8800. hullLength = (hullLength >> 1) * 2;
  8801. var lastX = vertices[hullLength - 2], lastY = vertices[hullLength - 1];
  8802. for (var ii = 0, nn = hullLength; ii < nn; ii += 2) {
  8803. var x = vertices[ii], y = vertices[ii + 1];
  8804. shapes.line(x, y, lastX, lastY);
  8805. lastX = x;
  8806. lastY = y;
  8807. }
  8808. }
  8809. }
  8810. }
  8811. if (this.drawBoundingBoxes) {
  8812. var bounds = this.bounds;
  8813. bounds.update(skeleton, true);
  8814. shapes.setColor(this.aabbColor);
  8815. shapes.rect(false, bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight());
  8816. var polygons = bounds.polygons;
  8817. var boxes = bounds.boundingBoxes;
  8818. for (var i = 0, n = polygons.length; i < n; i++) {
  8819. var polygon = polygons[i];
  8820. shapes.setColor(boxes[i].color);
  8821. shapes.polygon(polygon, 0, polygon.length);
  8822. }
  8823. }
  8824. if (this.drawPaths) {
  8825. var slots = skeleton.slots;
  8826. for (var i = 0, n = slots.length; i < n; i++) {
  8827. var slot = slots[i];
  8828. var attachment = slot.getAttachment();
  8829. if (!(attachment instanceof spine.PathAttachment))
  8830. continue;
  8831. var path = attachment;
  8832. var nn = path.worldVerticesLength;
  8833. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  8834. path.computeWorldVertices(slot, 0, nn, world, 0, 2);
  8835. var color = this.pathColor;
  8836. var x1 = world[2], y1 = world[3], x2 = 0, y2 = 0;
  8837. if (path.closed) {
  8838. shapes.setColor(color);
  8839. var cx1 = world[0], cy1 = world[1], cx2 = world[nn - 2], cy2 = world[nn - 1];
  8840. x2 = world[nn - 4];
  8841. y2 = world[nn - 3];
  8842. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  8843. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  8844. shapes.line(x1, y1, cx1, cy1);
  8845. shapes.line(x2, y2, cx2, cy2);
  8846. }
  8847. nn -= 4;
  8848. for (var ii = 4; ii < nn; ii += 6) {
  8849. var cx1 = world[ii], cy1 = world[ii + 1], cx2 = world[ii + 2], cy2 = world[ii + 3];
  8850. x2 = world[ii + 4];
  8851. y2 = world[ii + 5];
  8852. shapes.setColor(color);
  8853. shapes.curve(x1, y1, cx1, cy1, cx2, cy2, x2, y2, 32);
  8854. shapes.setColor(SkeletonDebugRenderer.LIGHT_GRAY);
  8855. shapes.line(x1, y1, cx1, cy1);
  8856. shapes.line(x2, y2, cx2, cy2);
  8857. x1 = x2;
  8858. y1 = y2;
  8859. }
  8860. }
  8861. }
  8862. if (this.drawBones) {
  8863. shapes.setColor(this.boneOriginColor);
  8864. for (var i = 0, n = bones.length; i < n; i++) {
  8865. var bone = bones[i];
  8866. if (ignoredBones && ignoredBones.indexOf(bone.data.name) > -1)
  8867. continue;
  8868. shapes.circle(true, skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * this.scale, SkeletonDebugRenderer.GREEN, 8);
  8869. }
  8870. }
  8871. if (this.drawClipping) {
  8872. var slots = skeleton.slots;
  8873. shapes.setColor(this.clipColor);
  8874. for (var i = 0, n = slots.length; i < n; i++) {
  8875. var slot = slots[i];
  8876. var attachment = slot.getAttachment();
  8877. if (!(attachment instanceof spine.ClippingAttachment))
  8878. continue;
  8879. var clip = attachment;
  8880. var nn = clip.worldVerticesLength;
  8881. var world = this.temp = spine.Utils.setArraySize(this.temp, nn, 0);
  8882. clip.computeWorldVertices(slot, 0, nn, world, 0, 2);
  8883. for (var i_5 = 0, n_3 = world.length; i_5 < n_3; i_5 += 2) {
  8884. var x = world[i_5];
  8885. var y = world[i_5 + 1];
  8886. var x2 = world[(i_5 + 2) % world.length];
  8887. var y2 = world[(i_5 + 3) % world.length];
  8888. shapes.line(x, y, x2, y2);
  8889. }
  8890. }
  8891. }
  8892. };
  8893. SkeletonDebugRenderer.prototype.dispose = function () {
  8894. };
  8895. SkeletonDebugRenderer.LIGHT_GRAY = new spine.Color(192 / 255, 192 / 255, 192 / 255, 1);
  8896. SkeletonDebugRenderer.GREEN = new spine.Color(0, 1, 0, 1);
  8897. return SkeletonDebugRenderer;
  8898. }());
  8899. webgl.SkeletonDebugRenderer = SkeletonDebugRenderer;
  8900. })(webgl = spine.webgl || (spine.webgl = {}));
  8901. })(spine || (spine = {}));
  8902. var spine;
  8903. (function (spine) {
  8904. var webgl;
  8905. (function (webgl) {
  8906. var Renderable = (function () {
  8907. function Renderable(vertices, numVertices, numFloats) {
  8908. this.vertices = vertices;
  8909. this.numVertices = numVertices;
  8910. this.numFloats = numFloats;
  8911. }
  8912. return Renderable;
  8913. }());
  8914. ;
  8915. var SkeletonRenderer = (function () {
  8916. function SkeletonRenderer(context, twoColorTint) {
  8917. if (twoColorTint === void 0) { twoColorTint = true; }
  8918. this.premultipliedAlpha = false;
  8919. this.tempColor = new spine.Color();
  8920. this.tempColor2 = new spine.Color();
  8921. this.vertexSize = 2 + 2 + 4;
  8922. this.twoColorTint = false;
  8923. this.renderable = new Renderable(null, 0, 0);
  8924. this.clipper = new spine.SkeletonClipping();
  8925. this.twoColorTint = twoColorTint;
  8926. if (twoColorTint)
  8927. this.vertexSize += 4;
  8928. this.vertices = spine.Utils.newFloatArray(this.vertexSize * 1024);
  8929. }
  8930. SkeletonRenderer.prototype.draw = function (batcher, skeleton) {
  8931. var clipper = this.clipper;
  8932. var premultipliedAlpha = this.premultipliedAlpha;
  8933. var twoColorTint = this.twoColorTint;
  8934. var blendMode = null;
  8935. var renderable = this.renderable;
  8936. var uvs = null;
  8937. var triangles = null;
  8938. var drawOrder = skeleton.drawOrder;
  8939. var attachmentColor = null;
  8940. var skeletonColor = skeleton.color;
  8941. var vertexSize = twoColorTint ? 12 : 8;
  8942. for (var i = 0, n = drawOrder.length; i < n; i++) {
  8943. var clippedVertexSize = clipper.isClipping() ? 2 : vertexSize;
  8944. var slot = drawOrder[i];
  8945. var attachment = slot.getAttachment();
  8946. var texture = null;
  8947. if (attachment instanceof spine.RegionAttachment) {
  8948. var region = attachment;
  8949. renderable.vertices = this.vertices;
  8950. renderable.numVertices = 4;
  8951. renderable.numFloats = clippedVertexSize << 2;
  8952. region.computeWorldVertices(slot.bone, renderable.vertices, 0, clippedVertexSize);
  8953. triangles = SkeletonRenderer.QUAD_TRIANGLES;
  8954. uvs = region.uvs;
  8955. texture = region.region.renderObject.texture;
  8956. attachmentColor = region.color;
  8957. }
  8958. else if (attachment instanceof spine.MeshAttachment) {
  8959. var mesh = attachment;
  8960. renderable.vertices = this.vertices;
  8961. renderable.numVertices = (mesh.worldVerticesLength >> 1);
  8962. renderable.numFloats = renderable.numVertices * clippedVertexSize;
  8963. if (renderable.numFloats > renderable.vertices.length) {
  8964. renderable.vertices = this.vertices = spine.Utils.newFloatArray(renderable.numFloats);
  8965. }
  8966. mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, renderable.vertices, 0, clippedVertexSize);
  8967. triangles = mesh.triangles;
  8968. texture = mesh.region.renderObject.texture;
  8969. uvs = mesh.uvs;
  8970. attachmentColor = mesh.color;
  8971. }
  8972. else if (attachment instanceof spine.ClippingAttachment) {
  8973. var clip = (attachment);
  8974. clipper.clipStart(slot, clip);
  8975. continue;
  8976. }
  8977. else
  8978. continue;
  8979. if (texture != null) {
  8980. var slotColor = slot.color;
  8981. var finalColor = this.tempColor;
  8982. finalColor.r = skeletonColor.r * slotColor.r * attachmentColor.r;
  8983. finalColor.g = skeletonColor.g * slotColor.g * attachmentColor.g;
  8984. finalColor.b = skeletonColor.b * slotColor.b * attachmentColor.b;
  8985. finalColor.a = skeletonColor.a * slotColor.a * attachmentColor.a;
  8986. if (premultipliedAlpha) {
  8987. finalColor.r *= finalColor.a;
  8988. finalColor.g *= finalColor.a;
  8989. finalColor.b *= finalColor.a;
  8990. }
  8991. var darkColor = this.tempColor2;
  8992. if (slot.darkColor == null)
  8993. darkColor.set(0, 0, 0, 1);
  8994. else
  8995. darkColor.setFromColor(slot.darkColor);
  8996. var slotBlendMode = slot.data.blendMode;
  8997. if (slotBlendMode != blendMode) {
  8998. blendMode = slotBlendMode;
  8999. batcher.setBlendMode(webgl.WebGLBlendModeConverter.getSourceGLBlendMode(blendMode, premultipliedAlpha), webgl.WebGLBlendModeConverter.getDestGLBlendMode(blendMode));
  9000. }
  9001. if (clipper.isClipping()) {
  9002. clipper.clipTriangles(renderable.vertices, renderable.numFloats, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint);
  9003. var clippedVertices = new Float32Array(clipper.clippedVertices);
  9004. var clippedTriangles = clipper.clippedTriangles;
  9005. batcher.draw(texture, clippedVertices, clippedTriangles);
  9006. }
  9007. else {
  9008. var verts = renderable.vertices;
  9009. if (!twoColorTint) {
  9010. for (var v = 2, u = 0, n_4 = renderable.numFloats; v < n_4; v += vertexSize, u += 2) {
  9011. verts[v] = finalColor.r;
  9012. verts[v + 1] = finalColor.g;
  9013. verts[v + 2] = finalColor.b;
  9014. verts[v + 3] = finalColor.a;
  9015. verts[v + 4] = uvs[u];
  9016. verts[v + 5] = uvs[u + 1];
  9017. }
  9018. }
  9019. else {
  9020. for (var v = 2, u = 0, n_5 = renderable.numFloats; v < n_5; v += vertexSize, u += 2) {
  9021. verts[v] = finalColor.r;
  9022. verts[v + 1] = finalColor.g;
  9023. verts[v + 2] = finalColor.b;
  9024. verts[v + 3] = finalColor.a;
  9025. verts[v + 4] = uvs[u];
  9026. verts[v + 5] = uvs[u + 1];
  9027. verts[v + 6] = darkColor.r;
  9028. verts[v + 7] = darkColor.g;
  9029. verts[v + 8] = darkColor.b;
  9030. verts[v + 9] = darkColor.a;
  9031. }
  9032. }
  9033. var view = renderable.vertices.subarray(0, renderable.numFloats);
  9034. batcher.draw(texture, view, triangles);
  9035. }
  9036. }
  9037. clipper.clipEndWithSlot(slot);
  9038. }
  9039. clipper.clipEnd();
  9040. };
  9041. SkeletonRenderer.QUAD_TRIANGLES = [0, 1, 2, 2, 3, 0];
  9042. return SkeletonRenderer;
  9043. }());
  9044. webgl.SkeletonRenderer = SkeletonRenderer;
  9045. })(webgl = spine.webgl || (spine.webgl = {}));
  9046. })(spine || (spine = {}));
  9047. var spine;
  9048. (function (spine) {
  9049. var webgl;
  9050. (function (webgl) {
  9051. var Vector3 = (function () {
  9052. function Vector3(x, y, z) {
  9053. if (x === void 0) { x = 0; }
  9054. if (y === void 0) { y = 0; }
  9055. if (z === void 0) { z = 0; }
  9056. this.x = 0;
  9057. this.y = 0;
  9058. this.z = 0;
  9059. this.x = x;
  9060. this.y = y;
  9061. this.z = z;
  9062. }
  9063. Vector3.prototype.setFrom = function (v) {
  9064. this.x = v.x;
  9065. this.y = v.y;
  9066. this.z = v.z;
  9067. return this;
  9068. };
  9069. Vector3.prototype.set = function (x, y, z) {
  9070. this.x = x;
  9071. this.y = y;
  9072. this.z = z;
  9073. return this;
  9074. };
  9075. Vector3.prototype.add = function (v) {
  9076. this.x += v.x;
  9077. this.y += v.y;
  9078. this.z += v.z;
  9079. return this;
  9080. };
  9081. Vector3.prototype.sub = function (v) {
  9082. this.x -= v.x;
  9083. this.y -= v.y;
  9084. this.z -= v.z;
  9085. return this;
  9086. };
  9087. Vector3.prototype.scale = function (s) {
  9088. this.x *= s;
  9089. this.y *= s;
  9090. this.z *= s;
  9091. return this;
  9092. };
  9093. Vector3.prototype.normalize = function () {
  9094. var len = this.length();
  9095. if (len == 0)
  9096. return this;
  9097. len = 1 / len;
  9098. this.x *= len;
  9099. this.y *= len;
  9100. this.z *= len;
  9101. return this;
  9102. };
  9103. Vector3.prototype.cross = function (v) {
  9104. 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);
  9105. };
  9106. Vector3.prototype.multiply = function (matrix) {
  9107. var l_mat = matrix.values;
  9108. 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]);
  9109. };
  9110. Vector3.prototype.project = function (matrix) {
  9111. var l_mat = matrix.values;
  9112. 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]);
  9113. 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);
  9114. };
  9115. Vector3.prototype.dot = function (v) {
  9116. return this.x * v.x + this.y * v.y + this.z * v.z;
  9117. };
  9118. Vector3.prototype.length = function () {
  9119. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  9120. };
  9121. Vector3.prototype.distance = function (v) {
  9122. var a = v.x - this.x;
  9123. var b = v.y - this.y;
  9124. var c = v.z - this.z;
  9125. return Math.sqrt(a * a + b * b + c * c);
  9126. };
  9127. return Vector3;
  9128. }());
  9129. webgl.Vector3 = Vector3;
  9130. })(webgl = spine.webgl || (spine.webgl = {}));
  9131. })(spine || (spine = {}));
  9132. var spine;
  9133. (function (spine) {
  9134. var webgl;
  9135. (function (webgl) {
  9136. var ManagedWebGLRenderingContext = (function () {
  9137. function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) {
  9138. var _this = this;
  9139. if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
  9140. this.restorables = new Array();
  9141. if (canvasOrContext instanceof HTMLCanvasElement) {
  9142. var canvas_1 = canvasOrContext;
  9143. this.gl = (canvas_1.getContext("webgl", contextConfig) || canvas_1.getContext("experimental-webgl", contextConfig));
  9144. this.canvas = canvas_1;
  9145. canvas_1.addEventListener("webglcontextlost", function (e) {
  9146. var event = e;
  9147. if (e) {
  9148. e.preventDefault();
  9149. }
  9150. });
  9151. canvas_1.addEventListener("webglcontextrestored", function (e) {
  9152. for (var i = 0, n = _this.restorables.length; i < n; i++) {
  9153. _this.restorables[i].restore();
  9154. }
  9155. });
  9156. }
  9157. else {
  9158. this.gl = canvasOrContext;
  9159. this.canvas = this.gl.canvas;
  9160. }
  9161. }
  9162. ManagedWebGLRenderingContext.prototype.addRestorable = function (restorable) {
  9163. this.restorables.push(restorable);
  9164. };
  9165. ManagedWebGLRenderingContext.prototype.removeRestorable = function (restorable) {
  9166. var index = this.restorables.indexOf(restorable);
  9167. if (index > -1)
  9168. this.restorables.splice(index, 1);
  9169. };
  9170. return ManagedWebGLRenderingContext;
  9171. }());
  9172. webgl.ManagedWebGLRenderingContext = ManagedWebGLRenderingContext;
  9173. var WebGLBlendModeConverter = (function () {
  9174. function WebGLBlendModeConverter() {
  9175. }
  9176. WebGLBlendModeConverter.getDestGLBlendMode = function (blendMode) {
  9177. switch (blendMode) {
  9178. case spine.BlendMode.Normal: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9179. case spine.BlendMode.Additive: return WebGLBlendModeConverter.ONE;
  9180. case spine.BlendMode.Multiply: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9181. case spine.BlendMode.Screen: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA;
  9182. default: throw new Error("Unknown blend mode: " + blendMode);
  9183. }
  9184. };
  9185. WebGLBlendModeConverter.getSourceGLBlendMode = function (blendMode, premultipliedAlpha) {
  9186. if (premultipliedAlpha === void 0) { premultipliedAlpha = false; }
  9187. switch (blendMode) {
  9188. case spine.BlendMode.Normal: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA;
  9189. case spine.BlendMode.Additive: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA;
  9190. case spine.BlendMode.Multiply: return WebGLBlendModeConverter.DST_COLOR;
  9191. case spine.BlendMode.Screen: return WebGLBlendModeConverter.ONE;
  9192. default: throw new Error("Unknown blend mode: " + blendMode);
  9193. }
  9194. };
  9195. WebGLBlendModeConverter.ZERO = 0;
  9196. WebGLBlendModeConverter.ONE = 1;
  9197. WebGLBlendModeConverter.SRC_COLOR = 0x0300;
  9198. WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR = 0x0301;
  9199. WebGLBlendModeConverter.SRC_ALPHA = 0x0302;
  9200. WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA = 0x0303;
  9201. WebGLBlendModeConverter.DST_ALPHA = 0x0304;
  9202. WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA = 0x0305;
  9203. WebGLBlendModeConverter.DST_COLOR = 0x0306;
  9204. return WebGLBlendModeConverter;
  9205. }());
  9206. webgl.WebGLBlendModeConverter = WebGLBlendModeConverter;
  9207. })(webgl = spine.webgl || (spine.webgl = {}));
  9208. })(spine || (spine = {}));
  9209. var spine;
  9210. (function (spine) {
  9211. var SpineWidget = (function () {
  9212. function SpineWidget(element, config) {
  9213. var _this = this;
  9214. this.mvp = new spine.webgl.Matrix4();
  9215. this.paused = false;
  9216. this.lastFrameTime = Date.now() / 1000.0;
  9217. this.backgroundColor = new spine.Color();
  9218. this.loaded = false;
  9219. this.bounds = { offset: new spine.Vector2(), size: new spine.Vector2() };
  9220. if (!element)
  9221. throw new Error("Please provide a DOM element, e.g. document.getElementById('myelement')");
  9222. if (!config)
  9223. throw new Error("Please provide a configuration, specifying at least the json file, atlas file and animation name");
  9224. var elementId = element;
  9225. if (typeof (element) === "string")
  9226. element = document.getElementById(element);
  9227. if (element == null)
  9228. throw new Error("Element " + elementId + " does not exist");
  9229. this.validateConfig(config);
  9230. var existingCanvas = element.children[0];
  9231. var canvas = this.canvas = existingCanvas || document.createElement("canvas");
  9232. canvas.style.width = "100%";
  9233. canvas.style.height = "100%";
  9234. if (!existingCanvas) {
  9235. element.appendChild(canvas);
  9236. }
  9237. canvas.width = element.clientWidth;
  9238. canvas.height = element.clientHeight;
  9239. var webglConfig = { alpha: config.alpha };
  9240. this.context = new spine.webgl.ManagedWebGLRenderingContext(canvas, webglConfig);
  9241. this.shader = spine.webgl.Shader.newTwoColoredTextured(this.context);
  9242. this.batcher = new spine.webgl.PolygonBatcher(this.context);
  9243. this.mvp.ortho2d(0, 0, canvas.width - 1, canvas.height - 1);
  9244. this.skeletonRenderer = new spine.webgl.SkeletonRenderer(this.context);
  9245. this.debugShader = spine.webgl.Shader.newColored(this.context);
  9246. this.debugRenderer = new spine.webgl.SkeletonDebugRenderer(this.context);
  9247. this.shapes = new spine.webgl.ShapeRenderer(this.context);
  9248. var assets = this.assetManager = new spine.webgl.AssetManager(this.context, config.imagesPath ? config.imagesPath : "");
  9249. if (!config.atlasContent) {
  9250. assets.loadText(config.atlas);
  9251. }
  9252. if (!config.jsonContent) {
  9253. assets.loadText(config.json);
  9254. }
  9255. if (config.atlasPages == null) {
  9256. if (config.atlas) {
  9257. var atlasPage = config.atlas.replace(".atlas", ".png");
  9258. if (atlasPage.lastIndexOf(config.imagesPath) == 0) {
  9259. atlasPage = atlasPage.substr(config.imagesPath.length);
  9260. }
  9261. assets.loadTexture(atlasPage);
  9262. }
  9263. else {
  9264. var firstLine = config.atlasContent.trim().split("\n")[0];
  9265. assets.loadTexture(firstLine);
  9266. }
  9267. }
  9268. else {
  9269. for (var i = 0; i < config.atlasPages.length; i++) {
  9270. if (config.atlasPagesContent && config.atlasPagesContent[i]) {
  9271. assets.loadTextureData(config.atlasPages[i], config.atlasPagesContent[0]);
  9272. }
  9273. else {
  9274. assets.loadTexture(config.atlasPages[i]);
  9275. }
  9276. }
  9277. }
  9278. requestAnimationFrame(function () { _this.load(); });
  9279. }
  9280. SpineWidget.prototype.validateConfig = function (config) {
  9281. if (!config.atlas && !config.atlasContent)
  9282. throw new Error("Please specify config.atlas or config.atlasContent");
  9283. if (!config.json && !config.jsonContent)
  9284. throw new Error("Please specify config.json or config.jsonContent");
  9285. if (!config.animation)
  9286. throw new Error("Please specify config.animationName");
  9287. if (!config.scale)
  9288. config.scale = 1.0;
  9289. if (!config.skin)
  9290. config.skin = "default";
  9291. if (config.loop === undefined)
  9292. config.loop = true;
  9293. if (!config.x)
  9294. config.x = 0;
  9295. if (!config.y)
  9296. config.y = 0;
  9297. if (config.fitToCanvas === undefined)
  9298. config.fitToCanvas = true;
  9299. if (!config.backgroundColor)
  9300. config.backgroundColor = "#555555";
  9301. if (!config.imagesPath) {
  9302. if (config.atlas) {
  9303. var index = config.atlas.lastIndexOf("/");
  9304. if (index != -1) {
  9305. config.imagesPath = config.atlas.substr(0, index) + "/";
  9306. }
  9307. else {
  9308. config.imagesPath = "";
  9309. }
  9310. }
  9311. else {
  9312. config.imagesPath = "";
  9313. }
  9314. }
  9315. if (config.json && config.json.lastIndexOf(config.imagesPath) == 0) {
  9316. config.json = config.json.substr(config.imagesPath.length);
  9317. }
  9318. if (config.atlas && config.atlas.lastIndexOf(config.imagesPath) == 0) {
  9319. config.atlas = config.atlas.substr(config.imagesPath.length);
  9320. }
  9321. if (!config.premultipliedAlpha === undefined)
  9322. config.premultipliedAlpha = false;
  9323. if (!config.debug === undefined)
  9324. config.debug = false;
  9325. if (!config.alpha === undefined)
  9326. config.alpha = true;
  9327. this.backgroundColor.setFromString(config.backgroundColor);
  9328. this.config = config;
  9329. };
  9330. SpineWidget.prototype.load = function () {
  9331. var _this = this;
  9332. var assetManager = this.assetManager;
  9333. var imagesPath = this.config.imagesPath;
  9334. var config = this.config;
  9335. if (assetManager.isLoadingComplete()) {
  9336. if (assetManager.hasErrors()) {
  9337. if (config.error)
  9338. config.error(this, "Failed to load assets: " + JSON.stringify(assetManager.getErrors()));
  9339. else
  9340. throw new Error("Failed to load assets: " + JSON.stringify(assetManager.getErrors()));
  9341. }
  9342. var atlasContent = config.atlasContent === undefined ? this.assetManager.get(this.config.atlas) : config.atlasContent;
  9343. var atlas = new spine.TextureAtlas(atlasContent, function (path) {
  9344. var texture = assetManager.get(path);
  9345. return texture;
  9346. });
  9347. var atlasLoader = new spine.AtlasAttachmentLoader(atlas);
  9348. var skeletonJson = new spine.SkeletonJson(atlasLoader);
  9349. skeletonJson.scale = config.scale;
  9350. var jsonContent = config.jsonContent === undefined ? assetManager.get(config.json) : config.jsonContent;
  9351. var skeletonData = skeletonJson.readSkeletonData(jsonContent);
  9352. var skeleton = this.skeleton = new spine.Skeleton(skeletonData);
  9353. var bounds = this.bounds;
  9354. skeleton.setSkinByName(config.skin);
  9355. skeleton.setToSetupPose();
  9356. skeleton.updateWorldTransform();
  9357. skeleton.getBounds(bounds.offset, bounds.size, []);
  9358. if (!config.fitToCanvas) {
  9359. skeleton.x = config.x;
  9360. skeleton.y = config.y;
  9361. }
  9362. var animationState = this.state = new spine.AnimationState(new spine.AnimationStateData(skeleton.data));
  9363. animationState.setAnimation(0, config.animation, config.loop);
  9364. this.loaded = true;
  9365. if (config.success)
  9366. config.success(this);
  9367. requestAnimationFrame(function () { _this.render(); });
  9368. }
  9369. else
  9370. requestAnimationFrame(function () { _this.load(); });
  9371. };
  9372. SpineWidget.prototype.render = function () {
  9373. var _this = this;
  9374. var now = Date.now() / 1000;
  9375. var delta = now - this.lastFrameTime;
  9376. if (delta > 0.1)
  9377. delta = 0;
  9378. this.lastFrameTime = now;
  9379. var gl = this.context.gl;
  9380. var color = this.backgroundColor;
  9381. this.resize();
  9382. gl.clearColor(color.r, color.g, color.b, color.a);
  9383. gl.clear(gl.COLOR_BUFFER_BIT);
  9384. var state = this.state;
  9385. var skeleton = this.skeleton;
  9386. var premultipliedAlpha = this.config.premultipliedAlpha;
  9387. state.update(delta);
  9388. state.apply(skeleton);
  9389. skeleton.updateWorldTransform();
  9390. var shader = this.shader;
  9391. var batcher = this.batcher;
  9392. var skeletonRenderer = this.skeletonRenderer;
  9393. shader.bind();
  9394. shader.setUniformi(spine.webgl.Shader.SAMPLER, 0);
  9395. shader.setUniform4x4f(spine.webgl.Shader.MVP_MATRIX, this.mvp.values);
  9396. batcher.begin(shader);
  9397. skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
  9398. skeletonRenderer.draw(batcher, skeleton);
  9399. batcher.end();
  9400. shader.unbind();
  9401. if (this.config.debug) {
  9402. var shader_1 = this.debugShader;
  9403. var shapes = this.shapes;
  9404. var renderer = this.debugRenderer;
  9405. shader_1.bind();
  9406. shader_1.setUniform4x4f(spine.webgl.Shader.MVP_MATRIX, this.mvp.values);
  9407. renderer.premultipliedAlpha = premultipliedAlpha;
  9408. shapes.begin(shader_1);
  9409. renderer.draw(shapes, skeleton);
  9410. shapes.end();
  9411. shader_1.unbind();
  9412. }
  9413. if (!this.paused)
  9414. requestAnimationFrame(function () { _this.render(); });
  9415. };
  9416. SpineWidget.prototype.resize = function () {
  9417. var canvas = this.canvas;
  9418. var w = canvas.clientWidth;
  9419. var h = canvas.clientHeight;
  9420. var bounds = this.bounds;
  9421. var devicePixelRatio = window.devicePixelRatio || 1;
  9422. if (canvas.width != Math.floor(w * devicePixelRatio) || canvas.height != Math.floor(h * devicePixelRatio)) {
  9423. canvas.width = Math.floor(w * devicePixelRatio);
  9424. canvas.height = Math.floor(h * devicePixelRatio);
  9425. }
  9426. if (this.config.fitToCanvas) {
  9427. var centerX = bounds.offset.x + bounds.size.x / 2;
  9428. var centerY = bounds.offset.y + bounds.size.y / 2;
  9429. var scaleX = bounds.size.x / w;
  9430. var scaleY = bounds.size.y / h;
  9431. var scale = Math.max(scaleX, scaleY) * 1.2;
  9432. if (scale < 1)
  9433. scale = 1;
  9434. var width = w * scale;
  9435. var height = h * scale;
  9436. this.skeleton.x = this.skeleton.y = 0;
  9437. this.mvp.ortho2d(centerX - width / 2, centerY - height / 2, width, height);
  9438. }
  9439. else {
  9440. this.mvp.ortho2d(0, 0, w - 1, h - 1);
  9441. }
  9442. this.context.gl.viewport(0, 0, canvas.width, canvas.height);
  9443. };
  9444. SpineWidget.prototype.pause = function () {
  9445. this.paused = true;
  9446. };
  9447. SpineWidget.prototype.play = function () {
  9448. var _this = this;
  9449. this.paused = false;
  9450. requestAnimationFrame(function () { _this.render(); });
  9451. };
  9452. SpineWidget.prototype.isPlaying = function () {
  9453. return !this.paused;
  9454. };
  9455. SpineWidget.prototype.setAnimation = function (animationName, animationStateListener) {
  9456. if (animationStateListener === void 0) { animationStateListener = null; }
  9457. if (!this.loaded)
  9458. throw new Error("Widget isn't loaded yet");
  9459. this.skeleton.setToSetupPose();
  9460. var entry = this.state.setAnimation(0, animationName, this.config.loop);
  9461. entry.listener = animationStateListener;
  9462. };
  9463. SpineWidget.loadWidgets = function () {
  9464. var widgets = document.getElementsByClassName("spine-widget");
  9465. for (var i = 0; i < widgets.length; i++) {
  9466. SpineWidget.loadWidget(widgets[i]);
  9467. }
  9468. };
  9469. SpineWidget.loadWidget = function (widget) {
  9470. var config = new SpineWidgetConfig();
  9471. config.atlas = widget.getAttribute("data-atlas");
  9472. config.json = widget.getAttribute("data-json");
  9473. config.animation = widget.getAttribute("data-animation");
  9474. if (widget.getAttribute("data-images-path"))
  9475. config.imagesPath = widget.getAttribute("data-images-path");
  9476. if (widget.getAttribute("data-atlas-pages"))
  9477. config.atlasPages = widget.getAttribute("data-atlas-pages").split(",");
  9478. if (widget.getAttribute("data-skin"))
  9479. config.skin = widget.getAttribute("data-skin");
  9480. if (widget.getAttribute("data-loop"))
  9481. config.loop = widget.getAttribute("data-loop") === "true";
  9482. if (widget.getAttribute("data-scale"))
  9483. config.scale = parseFloat(widget.getAttribute("data-scale"));
  9484. if (widget.getAttribute("data-x"))
  9485. config.x = parseFloat(widget.getAttribute("data-x"));
  9486. if (widget.getAttribute("data-y"))
  9487. config.y = parseFloat(widget.getAttribute("data-y"));
  9488. if (widget.getAttribute("data-fit-to-canvas"))
  9489. config.fitToCanvas = widget.getAttribute("data-fit-to-canvas") === "true";
  9490. if (widget.getAttribute("data-background-color"))
  9491. config.backgroundColor = widget.getAttribute("data-background-color");
  9492. if (widget.getAttribute("data-premultiplied-alpha"))
  9493. config.premultipliedAlpha = widget.getAttribute("data-premultiplied-alpha") === "true";
  9494. if (widget.getAttribute("data-debug"))
  9495. config.debug = widget.getAttribute("data-debug") === "true";
  9496. if (widget.getAttribute("data-alpha"))
  9497. config.alpha = widget.getAttribute("data-alpha") === "true";
  9498. new spine.SpineWidget(widget, config);
  9499. };
  9500. SpineWidget.ready = function () {
  9501. if (SpineWidget.pageLoaded)
  9502. return;
  9503. SpineWidget.pageLoaded = true;
  9504. SpineWidget.loadWidgets();
  9505. };
  9506. SpineWidget.setupDOMListener = function () {
  9507. if (document.addEventListener) {
  9508. document.addEventListener("DOMContentLoaded", SpineWidget.ready, false);
  9509. window.addEventListener("load", SpineWidget.ready, false);
  9510. }
  9511. else {
  9512. document.attachEvent("onreadystatechange", function readyStateChange() {
  9513. if (document.readyState === "complete")
  9514. SpineWidget.ready();
  9515. });
  9516. window.attachEvent("onload", SpineWidget.ready);
  9517. }
  9518. };
  9519. SpineWidget.pageLoaded = false;
  9520. return SpineWidget;
  9521. }());
  9522. spine.SpineWidget = SpineWidget;
  9523. var SpineWidgetConfig = (function () {
  9524. function SpineWidgetConfig() {
  9525. this.skin = "default";
  9526. this.loop = true;
  9527. this.scale = 1.0;
  9528. this.x = 0;
  9529. this.y = 0;
  9530. this.alpha = true;
  9531. this.fitToCanvas = true;
  9532. this.backgroundColor = "#555555";
  9533. this.premultipliedAlpha = false;
  9534. this.debug = false;
  9535. }
  9536. return SpineWidgetConfig;
  9537. }());
  9538. spine.SpineWidgetConfig = SpineWidgetConfig;
  9539. })(spine || (spine = {}));
  9540. spine.SpineWidget.setupDOMListener();
  9541. //# sourceMappingURL=spine-all.js.map