spine-threejs.js 232 KB

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