pixi-spine.js 355 KB

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