spine-threejs.js 256 KB

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