laya.ani.js 150 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490
  1. (function(window,document,Laya){
  2. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  3. var Bezier=laya.maths.Bezier,Browser=laya.utils.Browser,Byte=laya.utils.Byte,Const=laya.Const,Event=laya.events.Event;
  4. var EventDispatcher=laya.events.EventDispatcher,Graphics=laya.display.Graphics,Handler=laya.utils.Handler;
  5. var Loader=laya.net.Loader,MathUtil=laya.maths.MathUtil,Matrix=laya.maths.Matrix,Node=laya.display.Node,Rectangle=laya.maths.Rectangle;
  6. var Render=laya.renders.Render,Resource=laya.resource.Resource,Sprite=laya.display.Sprite,Stat=laya.utils.Stat;
  7. var Texture=laya.resource.Texture,Texture2D=laya.resource.Texture2D,Timer=laya.utils.Timer,URL=laya.net.URL;
  8. var Utils=laya.utils.Utils;
  9. /**
  10. *@private
  11. */
  12. //class laya.ani.bone.SlotData
  13. var SlotData=(function(){
  14. function SlotData(){
  15. this.name=null;
  16. this.displayArr=[];
  17. }
  18. __class(SlotData,'laya.ani.bone.SlotData');
  19. var __proto=SlotData.prototype;
  20. __proto.getDisplayByName=function(name){
  21. var tDisplay;
  22. for (var i=0,n=this.displayArr.length;i < n;i++){
  23. tDisplay=this.displayArr[i];
  24. if (tDisplay.attachmentName==name){
  25. return i;
  26. }
  27. }
  28. return-1;
  29. }
  30. return SlotData;
  31. })()
  32. /**
  33. *@private
  34. */
  35. //class laya.ani.bone.canvasmesh.MeshData
  36. var MeshData=(function(){
  37. function MeshData(){
  38. /**
  39. *纹理
  40. */
  41. this.texture=null;
  42. /**
  43. *uv变换矩阵
  44. */
  45. this.uvTransform=null;
  46. /**
  47. *是否有uv变化矩阵
  48. */
  49. this.useUvTransform=false;
  50. /**
  51. *扩展像素,用来去除黑边
  52. */
  53. this.canvasPadding=1;
  54. this.uvs=new Float32Array([0,0,1,0,1,1,0,1]);
  55. this.vertices=new Float32Array([0,0,100,0,100,100,0,100]);
  56. this.indexes=new Uint16Array([0,1,3,3,1,2]);
  57. }
  58. __class(MeshData,'laya.ani.bone.canvasmesh.MeshData');
  59. var __proto=MeshData.prototype;
  60. //TODO:coverage
  61. __proto.getBounds=function(){
  62. return Rectangle._getWrapRec(this.vertices);
  63. }
  64. return MeshData;
  65. })()
  66. /**
  67. *@private
  68. *@author ...
  69. */
  70. //class laya.ani.AnimationNodeContent
  71. var AnimationNodeContent=(function(){
  72. function AnimationNodeContent(){
  73. this.name=null;
  74. this.parentIndex=0;
  75. this.parent=null;
  76. this.keyframeWidth=0;
  77. this.lerpType=0;
  78. this.interpolationMethod=null;
  79. this.childs=null;
  80. this.keyFrame=null;
  81. //=new Vector.<KeyFramesContent>;
  82. this.playTime=NaN;
  83. this.extenData=null;
  84. this.dataOffset=0;
  85. }
  86. __class(AnimationNodeContent,'laya.ani.AnimationNodeContent');
  87. return AnimationNodeContent;
  88. })()
  89. /**
  90. *@private
  91. *@author ...
  92. */
  93. //class laya.ani.KeyFramesContent
  94. var KeyFramesContent=(function(){
  95. function KeyFramesContent(){
  96. //TODO 这个对内存影响较大,建议减少一下
  97. this.startTime=NaN;
  98. this.duration=NaN;
  99. this.interpolationData=null;
  100. //私有插值方式 [type0(插值类型),Data0(插值数据,可为空),type1(插值类型),Data1(插值数据,可为空)] 注意:254全线性插值,255全不插值
  101. this.data=null;
  102. //=new Float32Array();数据
  103. this.dData=null;
  104. //=new Float32Array();数据变化量
  105. this.nextData=null;
  106. }
  107. __class(KeyFramesContent,'laya.ani.KeyFramesContent');
  108. return KeyFramesContent;
  109. })()
  110. /**
  111. *@private
  112. */
  113. //class laya.ani.bone.TfConstraint
  114. var TfConstraint=(function(){
  115. function TfConstraint(data,bones){
  116. this._data=null;
  117. this._bones=null;
  118. this.target=null;
  119. this.rotateMix=NaN;
  120. this.translateMix=NaN;
  121. this.scaleMix=NaN;
  122. this.shearMix=NaN;
  123. this._temp=__newvec(2,0);
  124. this._data=data;
  125. if (this._bones==null){
  126. this._bones=[];
  127. }
  128. this.target=bones[data.targetIndex];
  129. var j=0,n=0;
  130. for (j=0,n=data.boneIndexs.length;j < n;j++){
  131. this._bones.push(bones[data.boneIndexs[j]]);
  132. }
  133. this.rotateMix=data.rotateMix;
  134. this.translateMix=data.translateMix;
  135. this.scaleMix=data.scaleMix;
  136. this.shearMix=data.shearMix;
  137. }
  138. __class(TfConstraint,'laya.ani.bone.TfConstraint');
  139. var __proto=TfConstraint.prototype;
  140. //TODO:coverage
  141. __proto.apply=function(){
  142. var tTfBone;
  143. var ta=this.target.resultMatrix.a,tb=this.target.resultMatrix.b,tc=this.target.resultMatrix.c,td=this.target.resultMatrix.d;
  144. for (var j=0,n=this._bones.length;j < n;j++){
  145. tTfBone=this._bones[j];
  146. if (this.rotateMix > 0){
  147. var a=tTfBone.resultMatrix.a,b=tTfBone.resultMatrix.b,c=tTfBone.resultMatrix.c,d=tTfBone.resultMatrix.d;
  148. var r=Math.atan2(tc,ta)-Math.atan2(c,a)+this._data.offsetRotation *Math.PI / 180;
  149. if (r > Math.PI)
  150. r-=Math.PI *2;
  151. else if (r <-Math.PI)r+=Math.PI *2;
  152. r *=this.rotateMix;
  153. var cos=Math.cos(r),sin=Math.sin(r);
  154. tTfBone.resultMatrix.a=cos *a-sin *c;
  155. tTfBone.resultMatrix.b=cos *b-sin *d;
  156. tTfBone.resultMatrix.c=sin *a+cos *c;
  157. tTfBone.resultMatrix.d=sin *b+cos *d;
  158. }
  159. if (this.translateMix){
  160. this._temp[0]=this._data.offsetX;
  161. this._temp[1]=this._data.offsetY;
  162. this.target.localToWorld(this._temp);
  163. tTfBone.resultMatrix.tx+=(this._temp[0]-tTfBone.resultMatrix.tx)*this.translateMix;
  164. tTfBone.resultMatrix.ty+=(this._temp[1]-tTfBone.resultMatrix.ty)*this.translateMix;
  165. tTfBone.updateChild();
  166. }
  167. if (this.scaleMix > 0){
  168. var bs=Math.sqrt(tTfBone.resultMatrix.a *tTfBone.resultMatrix.a+tTfBone.resultMatrix.c *tTfBone.resultMatrix.c);
  169. var ts=Math.sqrt(ta *ta+tc *tc);
  170. var s=bs > 0.00001 ? (bs+(ts-bs+this._data.offsetScaleX)*this.scaleMix)/ bs :0;
  171. tTfBone.resultMatrix.a *=s;
  172. tTfBone.resultMatrix.c *=s;
  173. bs=Math.sqrt(tTfBone.resultMatrix.b *tTfBone.resultMatrix.b+tTfBone.resultMatrix.d *tTfBone.resultMatrix.d);
  174. ts=Math.sqrt(tb *tb+td *td);
  175. s=bs > 0.00001 ? (bs+(ts-bs+this._data.offsetScaleY)*this.scaleMix)/ bs :0;
  176. tTfBone.resultMatrix.b *=s;
  177. tTfBone.resultMatrix.d *=s;
  178. }
  179. if (this.shearMix > 0){
  180. b=tTfBone.resultMatrix.b,d=tTfBone.resultMatrix.d;
  181. var by=Math.atan2(d,b);
  182. r=Math.atan2(td,tb)-Math.atan2(tc,ta)-(by-Math.atan2(tTfBone.resultMatrix.c,tTfBone.resultMatrix.a));
  183. if (r > Math.PI)
  184. r-=Math.PI *2;
  185. else if (r <-Math.PI)r+=Math.PI *2;
  186. r=by+(r+this._data.offsetShearY *Math.PI / 180)*this.shearMix;
  187. s=Math.sqrt(b *b+d *d);
  188. tTfBone.resultMatrix.b=Math.cos(r)*s;
  189. tTfBone.resultMatrix.d=Math.sin(r)*s;
  190. }
  191. }
  192. }
  193. return TfConstraint;
  194. })()
  195. /**
  196. *@private
  197. */
  198. //class laya.ani.bone.PathConstraintData
  199. var PathConstraintData=(function(){
  200. function PathConstraintData(){
  201. this.name=null;
  202. this.target=null;
  203. this.positionMode=null;
  204. this.spacingMode=null;
  205. this.rotateMode=null;
  206. this.offsetRotation=NaN;
  207. this.position=NaN;
  208. this.spacing=NaN;
  209. this.rotateMix=NaN;
  210. this.translateMix=NaN;
  211. this.bones=[];
  212. }
  213. __class(PathConstraintData,'laya.ani.bone.PathConstraintData');
  214. return PathConstraintData;
  215. })()
  216. /**
  217. *用于UV转换的工具类
  218. *@private
  219. */
  220. //class laya.ani.bone.UVTools
  221. var UVTools=(function(){
  222. function UVTools(){}
  223. __class(UVTools,'laya.ani.bone.UVTools');
  224. UVTools.getRelativeUV=function(bigUV,smallUV,rst){
  225. var startX=bigUV[0];
  226. var width=bigUV[2]-bigUV[0];
  227. var startY=bigUV[1];
  228. var height=bigUV[5]-bigUV[1];
  229. if(!rst)rst=[];
  230. rst.length=smallUV.length;
  231. var i=0,len=0;
  232. len=rst.length;
  233. var dWidth=1 / width;
  234. var dHeight=1 / height;
  235. for (i=0;i < len;i+=2){
  236. rst[i]=(smallUV[i]-startX)*dWidth;
  237. rst[i+1]=(smallUV[i+1]-startY)*dHeight;
  238. }
  239. return rst;
  240. }
  241. UVTools.getAbsoluteUV=function(bigUV,smallUV,rst){
  242. if (bigUV[0]==0 && bigUV[1]==0 && bigUV[4]==1 && bigUV[5]==1){
  243. if (rst){
  244. Utils.copyArray(rst,smallUV);
  245. return rst;
  246. }else{
  247. return smallUV;
  248. }
  249. };
  250. var startX=bigUV[0];
  251. var width=bigUV[2]-bigUV[0];
  252. var startY=bigUV[1];
  253. var height=bigUV[5]-bigUV[1];
  254. if(!rst)rst=[];
  255. rst.length=smallUV.length;
  256. var i=0,len=0;
  257. len=rst.length;
  258. for (i=0;i < len;i+=2){
  259. rst[i]=smallUV[i]*width+startX;
  260. rst[i+1]=smallUV[i+1]*height+startY;
  261. }
  262. return rst;
  263. }
  264. return UVTools;
  265. })()
  266. /**
  267. *@private
  268. */
  269. //class laya.ani.bone.DeformSlotData
  270. var DeformSlotData=(function(){
  271. function DeformSlotData(){
  272. this.deformSlotDisplayList=[];
  273. }
  274. __class(DeformSlotData,'laya.ani.bone.DeformSlotData');
  275. return DeformSlotData;
  276. })()
  277. /**
  278. *@private
  279. */
  280. //class laya.ani.AnimationParser02
  281. var AnimationParser02=(function(){
  282. function AnimationParser02(){}
  283. __class(AnimationParser02,'laya.ani.AnimationParser02');
  284. AnimationParser02.READ_DATA=function(){
  285. AnimationParser02._DATA.offset=AnimationParser02._reader.getUint32();
  286. AnimationParser02._DATA.size=AnimationParser02._reader.getUint32();
  287. }
  288. AnimationParser02.READ_BLOCK=function(){
  289. var count=AnimationParser02._BLOCK.count=AnimationParser02._reader.getUint16();
  290. var blockStarts=AnimationParser02._BLOCK.blockStarts=[];
  291. var blockLengths=AnimationParser02._BLOCK.blockLengths=[];
  292. for (var i=0;i < count;i++){
  293. blockStarts.push(AnimationParser02._reader.getUint32());
  294. blockLengths.push(AnimationParser02._reader.getUint32());
  295. }
  296. }
  297. AnimationParser02.READ_STRINGS=function(){
  298. var offset=AnimationParser02._reader.getUint32();
  299. var count=AnimationParser02._reader.getUint16();
  300. var prePos=AnimationParser02._reader.pos;
  301. AnimationParser02._reader.pos=offset+AnimationParser02._DATA.offset;
  302. for (var i=0;i < count;i++)
  303. AnimationParser02._strings[i]=AnimationParser02._reader.readUTFString();
  304. AnimationParser02._reader.pos=prePos;
  305. }
  306. AnimationParser02.parse=function(templet,reader){
  307. AnimationParser02._templet=templet;
  308. AnimationParser02._reader=reader;
  309. var arrayBuffer=reader.__getBuffer();
  310. AnimationParser02.READ_DATA();
  311. AnimationParser02.READ_BLOCK();
  312. AnimationParser02.READ_STRINGS();
  313. for (var i=0,n=AnimationParser02._BLOCK.count;i < n;i++){
  314. var index=reader.getUint16();
  315. var blockName=AnimationParser02._strings[index];
  316. var fn=AnimationParser02["READ_"+blockName];
  317. if (fn==null)
  318. throw new Error("model file err,no this function:"+index+" "+blockName);
  319. else
  320. fn.call(null);
  321. }
  322. }
  323. AnimationParser02.READ_ANIMATIONS=function(){
  324. var reader=AnimationParser02._reader;
  325. var arrayBuffer=reader.__getBuffer();
  326. var i=0,j=0,k=0,n=0,l=0;
  327. var keyframeWidth=reader.getUint16();
  328. var interpolationMethod=[];
  329. interpolationMethod.length=keyframeWidth;
  330. for (i=0;i < keyframeWidth;i++)
  331. interpolationMethod[i]=AnimationTemplet.interpolation[reader.getByte()];
  332. var aniCount=reader.getUint8();
  333. AnimationParser02._templet._anis.length=aniCount;
  334. for (i=0;i < aniCount;i++){
  335. var ani=AnimationParser02._templet._anis[i]=new AnimationContent();
  336. ani.nodes=new Array;
  337. var aniName=ani.name=AnimationParser02._strings[reader.getUint16()];
  338. AnimationParser02._templet._aniMap[aniName]=i;
  339. ani.bone3DMap={};
  340. ani.playTime=reader.getFloat32();
  341. var boneCount=ani.nodes.length=reader.getInt16();
  342. ani.totalKeyframeDatasLength=0;
  343. for (j=0;j < boneCount;j++){
  344. var node=ani.nodes[j]=new AnimationNodeContent();
  345. node.keyframeWidth=keyframeWidth;
  346. node.childs=[];
  347. var nameIndex=reader.getUint16();
  348. if (nameIndex >=0){
  349. node.name=AnimationParser02._strings[nameIndex];
  350. ani.bone3DMap[node.name]=j;
  351. }
  352. node.keyFrame=new Array;
  353. node.parentIndex=reader.getInt16();
  354. node.parentIndex==-1 ? node.parent=null :node.parent=ani.nodes[node.parentIndex]
  355. ani.totalKeyframeDatasLength+=keyframeWidth;
  356. node.interpolationMethod=interpolationMethod;
  357. if (node.parent !=null)
  358. node.parent.childs.push(node);
  359. var keyframeCount=reader.getUint16();
  360. node.keyFrame.length=keyframeCount;
  361. var keyFrame=null,lastKeyFrame=null;
  362. for (k=0,n=keyframeCount;k < n;k++){
  363. keyFrame=node.keyFrame[k]=new KeyFramesContent();
  364. keyFrame.startTime=reader.getFloat32();
  365. (lastKeyFrame)&& (lastKeyFrame.duration=keyFrame.startTime-lastKeyFrame.startTime);
  366. keyFrame.dData=new Float32Array(keyframeWidth);
  367. keyFrame.nextData=new Float32Array(keyframeWidth);
  368. var offset=AnimationParser02._DATA.offset;
  369. var keyframeDataOffset=reader.getUint32();
  370. var keyframeDataLength=keyframeWidth *4;
  371. var keyframeArrayBuffer=arrayBuffer.slice(offset+keyframeDataOffset,offset+keyframeDataOffset+keyframeDataLength);
  372. keyFrame.data=new Float32Array(keyframeArrayBuffer);
  373. lastKeyFrame=keyFrame;
  374. }
  375. keyFrame.duration=0;
  376. node.playTime=ani.playTime;
  377. AnimationParser02._templet._calculateKeyFrame(node,keyframeCount,keyframeWidth);
  378. }
  379. }
  380. }
  381. AnimationParser02._templet=null;
  382. AnimationParser02._reader=null;
  383. AnimationParser02._strings=[];
  384. __static(AnimationParser02,
  385. ['_BLOCK',function(){return this._BLOCK={count:0};},'_DATA',function(){return this._DATA={offset:0,size:0};}
  386. ]);
  387. return AnimationParser02;
  388. })()
  389. /**
  390. *@private
  391. */
  392. //class laya.ani.AnimationParser01
  393. var AnimationParser01=(function(){
  394. function AnimationParser01(){}
  395. __class(AnimationParser01,'laya.ani.AnimationParser01');
  396. AnimationParser01.parse=function(templet,reader){
  397. var data=reader.__getBuffer();
  398. var i=0,j=0,k=0,n=0,l=0,m=0,o=0;
  399. var aniClassName=reader.readUTFString();
  400. templet._aniClassName=aniClassName;
  401. var strList=reader.readUTFString().split("\n");
  402. var aniCount=reader.getUint8();
  403. var publicDataPos=reader.getUint32();
  404. var publicExtDataPos=reader.getUint32();
  405. var publicData;
  406. if (publicDataPos > 0)
  407. publicData=data.slice(publicDataPos,publicExtDataPos);
  408. var publicRead=new Byte(publicData);
  409. if (publicExtDataPos > 0)
  410. templet._publicExtData=data.slice(publicExtDataPos,data.byteLength);
  411. templet._useParent=!!reader.getUint8();
  412. templet._anis.length=aniCount;
  413. for (i=0;i < aniCount;i++){
  414. var ani=templet._anis[i]=new AnimationContent();
  415. {};
  416. ani.nodes=new Array;
  417. var name=ani.name=strList[reader.getUint16()];
  418. templet._aniMap[name]=i;
  419. ani.bone3DMap={};
  420. ani.playTime=reader.getFloat32();
  421. var boneCount=ani.nodes.length=reader.getUint8();
  422. ani.totalKeyframeDatasLength=0;
  423. for (j=0;j < boneCount;j++){
  424. var node=ani.nodes[j]=new AnimationNodeContent();
  425. {};
  426. node.childs=[];
  427. var nameIndex=reader.getInt16();
  428. if (nameIndex >=0){
  429. node.name=strList[nameIndex];
  430. ani.bone3DMap[node.name]=j;
  431. }
  432. node.keyFrame=new Array;
  433. node.parentIndex=reader.getInt16();
  434. node.parentIndex==-1 ? node.parent=null :node.parent=ani.nodes[node.parentIndex]
  435. node.lerpType=reader.getUint8();
  436. var keyframeParamsOffset=reader.getUint32();
  437. publicRead.pos=keyframeParamsOffset;
  438. var keyframeDataCount=node.keyframeWidth=publicRead.getUint16();
  439. ani.totalKeyframeDatasLength+=keyframeDataCount;
  440. if (node.lerpType===0 || node.lerpType===1){
  441. node.interpolationMethod=[];
  442. node.interpolationMethod.length=keyframeDataCount;
  443. for (k=0;k < keyframeDataCount;k++)
  444. node.interpolationMethod[k]=AnimationTemplet.interpolation[publicRead.getUint8()];
  445. }
  446. if (node.parent !=null)
  447. node.parent.childs.push(node);
  448. var privateDataLen=reader.getUint16();
  449. if (privateDataLen > 0){
  450. node.extenData=data.slice(reader.pos,reader.pos+privateDataLen);
  451. reader.pos+=privateDataLen;
  452. };
  453. var keyframeCount=reader.getUint16();
  454. node.keyFrame.length=keyframeCount;
  455. var startTime=0;
  456. var keyFrame;
  457. for (k=0,n=keyframeCount;k < n;k++){
  458. keyFrame=node.keyFrame[k]=new KeyFramesContent();
  459. {};
  460. keyFrame.duration=reader.getFloat32();
  461. keyFrame.startTime=startTime;
  462. if (node.lerpType===2){
  463. keyFrame.interpolationData=[];
  464. var interDataLength=reader.getUint8();
  465. var lerpType=0;
  466. lerpType=reader.getFloat32();
  467. switch (lerpType){
  468. case 254:
  469. keyFrame.interpolationData.length=keyframeDataCount;
  470. for (o=0;o < keyframeDataCount;o++)
  471. keyFrame.interpolationData[o]=0;
  472. break ;
  473. case 255:
  474. keyFrame.interpolationData.length=keyframeDataCount;
  475. for (o=0;o < keyframeDataCount;o++)
  476. keyFrame.interpolationData[o]=5;
  477. break ;
  478. default :
  479. keyFrame.interpolationData.push(lerpType);
  480. for (m=1;m < interDataLength;m++){
  481. keyFrame.interpolationData.push(reader.getFloat32());
  482. }
  483. }
  484. }
  485. keyFrame.data=new Float32Array(keyframeDataCount);
  486. keyFrame.dData=new Float32Array(keyframeDataCount);
  487. keyFrame.nextData=new Float32Array(keyframeDataCount);
  488. for (l=0;l < keyframeDataCount;l++){
  489. keyFrame.data[l]=reader.getFloat32();
  490. if (keyFrame.data[l] >-0.00000001 && keyFrame.data[l] < 0.00000001)keyFrame.data[l]=0;
  491. }
  492. startTime+=keyFrame.duration;
  493. }
  494. keyFrame.startTime=ani.playTime;
  495. node.playTime=ani.playTime;
  496. templet._calculateKeyFrame(node,keyframeCount,keyframeDataCount);
  497. }
  498. }
  499. }
  500. return AnimationParser01;
  501. })()
  502. /**
  503. *@private
  504. */
  505. //class laya.ani.bone.SkinData
  506. var SkinData=(function(){
  507. function SkinData(){
  508. this.name=null;
  509. this.slotArr=[];
  510. }
  511. __class(SkinData,'laya.ani.bone.SkinData');
  512. return SkinData;
  513. })()
  514. /**
  515. *@private
  516. */
  517. //class laya.ani.bone.IkConstraint
  518. var IkConstraint=(function(){
  519. function IkConstraint(data,bones){
  520. this._targetBone=null;
  521. this._bones=null;
  522. this._data=null;
  523. this.name=null;
  524. this.mix=NaN;
  525. this.bendDirection=NaN;
  526. this.isSpine=true;
  527. //debug相关代码
  528. this._sp=null;
  529. this.isDebug=false;
  530. this._data=data;
  531. this._targetBone=bones[data.targetBoneIndex];
  532. this.isSpine=data.isSpine;
  533. if (this._bones==null)this._bones=[];
  534. this._bones.length=0;
  535. for (var i=0,n=data.boneIndexs.length;i < n;i++){
  536. this._bones.push(bones[data.boneIndexs[i]]);
  537. }
  538. this.name=data.name;
  539. this.mix=data.mix;
  540. this.bendDirection=data.bendDirection;
  541. }
  542. __class(IkConstraint,'laya.ani.bone.IkConstraint');
  543. var __proto=IkConstraint.prototype;
  544. __proto.apply=function(){
  545. switch (this._bones.length){
  546. case 1:
  547. this._applyIk1(this._bones[0],this._targetBone.resultMatrix.tx,this._targetBone.resultMatrix.ty,this.mix);
  548. break ;
  549. case 2:
  550. if (this.isSpine){
  551. this._applyIk2(this._bones[0],this._bones[1],this._targetBone.resultMatrix.tx,this._targetBone.resultMatrix.ty,this.bendDirection,this.mix);
  552. }else{
  553. this._applyIk3(this._bones[0],this._bones[1],this._targetBone.resultMatrix.tx,this._targetBone.resultMatrix.ty,this.bendDirection,this.mix);
  554. }
  555. break ;
  556. }
  557. }
  558. //TODO:coverage
  559. __proto._applyIk1=function(bone,targetX,targetY,alpha){
  560. var pp=bone.parentBone;
  561. var id=1 / (pp.resultMatrix.a *pp.resultMatrix.d-pp.resultMatrix.b *pp.resultMatrix.c);
  562. var x=targetX-pp.resultMatrix.tx;
  563. var y=targetY-pp.resultMatrix.ty;
  564. var tx=(x *pp.resultMatrix.d-y *pp.resultMatrix.c)*id-bone.transform.x;
  565. var ty=(y *pp.resultMatrix.a-x *pp.resultMatrix.b)*id-bone.transform.y;
  566. var rotationIK=Math.atan2(ty,tx)*IkConstraint.radDeg-0-bone.transform.skX;
  567. if (bone.transform.scX < 0)rotationIK+=180;
  568. if (rotationIK > 180)
  569. rotationIK-=360;
  570. else if (rotationIK <-180)rotationIK+=360;
  571. bone.transform.skX=bone.transform.skY=bone.transform.skX+rotationIK *alpha;
  572. bone.update();
  573. }
  574. //TODO:coverage
  575. __proto.updatePos=function(x,y){
  576. if (this._sp){
  577. this._sp.pos(x,y);
  578. }
  579. }
  580. //TODO:coverage
  581. __proto._applyIk2=function(parent,child,targetX,targetY,bendDir,alpha){
  582. if (alpha==0){
  583. return;
  584. };
  585. var px=parent.resultTransform.x,py=parent.resultTransform.y;
  586. var psx=parent.transform.scX,psy=parent.transform.scY;
  587. var csx=child.transform.scX;
  588. var os1=0,os2=0,s2=0;
  589. if (psx < 0){
  590. psx=-psx;
  591. os1=180;
  592. s2=-1;
  593. }else {
  594. os1=0;
  595. s2=1;
  596. }
  597. if (psy < 0){
  598. psy=-psy;
  599. s2=-s2;
  600. }
  601. if (csx < 0){
  602. csx=-csx;
  603. os2=180;
  604. }else {
  605. os2=0
  606. };
  607. var cx=child.resultTransform.x,cy=NaN,cwx=NaN,cwy=NaN;
  608. var a=parent.resultMatrix.a,b=parent.resultMatrix.c;
  609. var c=parent.resultMatrix.b,d=parent.resultMatrix.d;
  610. var u=Math.abs(psx-psy)<=0.0001;
  611. if (!u){
  612. cy=0;
  613. cwx=a *cx+parent.resultMatrix.tx;
  614. cwy=c *cx+parent.resultMatrix.ty;
  615. }else {
  616. cy=child.resultTransform.y;
  617. cwx=a *cx+b *cy+parent.resultMatrix.tx;
  618. cwy=c *cx+d *cy+parent.resultMatrix.ty;
  619. }
  620. if (this.isDebug){
  621. if (!this._sp){
  622. this._sp=new Sprite();
  623. Laya.stage.addChild(this._sp);
  624. }
  625. this._sp.graphics.clear();
  626. this._sp.graphics.drawCircle(targetX,targetY,15,"#ffff00");
  627. this._sp.graphics.drawCircle(cwx,cwy,15,"#ff00ff");
  628. }
  629. parent.setRotation(Math.atan2(cwy-parent.resultMatrix.ty,cwx-parent.resultMatrix.tx));
  630. var pp=parent.parentBone;
  631. a=pp.resultMatrix.a;
  632. b=pp.resultMatrix.c;
  633. c=pp.resultMatrix.b;
  634. d=pp.resultMatrix.d;
  635. var id=1 / (a *d-b *c);
  636. var x=targetX-pp.resultMatrix.tx,y=targetY-pp.resultMatrix.ty;
  637. var tx=(x *d-y *b)*id-px;
  638. var ty=(y *a-x *c)*id-py;
  639. x=cwx-pp.resultMatrix.tx;
  640. y=cwy-pp.resultMatrix.ty;
  641. var dx=(x *d-y *b)*id-px;
  642. var dy=(y *a-x *c)*id-py;
  643. var l1=Math.sqrt(dx *dx+dy *dy);
  644. var l2=child.length *csx;
  645. var a1=NaN,a2=NaN;
  646. if (u){
  647. l2 *=psx;
  648. var cos=(tx *tx+ty *ty-l1 *l1-l2 *l2)/ (2 *l1 *l2);
  649. if (cos <-1)
  650. cos=-1;
  651. else if (cos > 1)cos=1;
  652. a2=Math.acos(cos)*bendDir;
  653. a=l1+l2 *cos;
  654. b=l2 *Math.sin(a2);
  655. a1=Math.atan2(ty *a-tx *b,tx *a+ty *b);
  656. }else {
  657. a=psx *l2;
  658. b=psy *l2;
  659. var aa=a *a,bb=b *b,dd=tx *tx+ty *ty,ta=Math.atan2(ty,tx);
  660. c=bb *l1 *l1+aa *dd-aa *bb;
  661. var c1=-2 *bb *l1,c2=bb-aa;
  662. d=c1 *c1-4 *c2 *c;
  663. if (d > 0){
  664. var q=Math.sqrt(d);
  665. if (c1 < 0)q=-q;
  666. q=-(c1+q)/ 2;
  667. var r0=q / c2,r1=c / q;
  668. var r=Math.abs(r0)< Math.abs(r1)? r0 :r1;
  669. if (r *r <=dd){
  670. y=Math.sqrt(dd-r *r)*bendDir;
  671. a1=ta-Math.atan2(y,r);
  672. a2=Math.atan2(y / psy,(r-l1)/ psx);
  673. }
  674. };
  675. var minAngle=0,minDist=Number.MAX_VALUE,minX=0,minY=0;
  676. var maxAngle=0,maxDist=0,maxX=0,maxY=0;
  677. x=l1+a;
  678. d=x *x;
  679. if (d > maxDist){
  680. maxAngle=0;
  681. maxDist=d;
  682. maxX=x;
  683. }
  684. x=l1-a;
  685. d=x *x;
  686. if (d < minDist){
  687. minAngle=Math.PI;
  688. minDist=d;
  689. minX=x;
  690. };
  691. var angle=Math.acos(-a *l1 / (aa-bb));
  692. x=a *Math.cos(angle)+l1;
  693. y=b *Math.sin(angle);
  694. d=x *x+y *y;
  695. if (d < minDist){
  696. minAngle=angle;
  697. minDist=d;
  698. minX=x;
  699. minY=y;
  700. }
  701. if (d > maxDist){
  702. maxAngle=angle;
  703. maxDist=d;
  704. maxX=x;
  705. maxY=y;
  706. }
  707. if (dd <=(minDist+maxDist)/ 2){
  708. a1=ta-Math.atan2(minY *bendDir,minX);
  709. a2=minAngle *bendDir;
  710. }else {
  711. a1=ta-Math.atan2(maxY *bendDir,maxX);
  712. a2=maxAngle *bendDir;
  713. }
  714. };
  715. var os=Math.atan2(cy,cx)*s2;
  716. var rotation=parent.resultTransform.skX;
  717. a1=(a1-os)*IkConstraint.radDeg+os1-rotation;
  718. if (a1 > 180)
  719. a1-=360;
  720. else if (a1 <-180)a1+=360;
  721. parent.resultTransform.x=px;
  722. parent.resultTransform.y=py;
  723. parent.resultTransform.skX=parent.resultTransform.skY=rotation+a1 *alpha;
  724. rotation=child.resultTransform.skX;
  725. rotation=rotation % 360;
  726. a2=((a2+os)*IkConstraint.radDeg-0)*s2+os2-rotation;
  727. if (a2 > 180)
  728. a2-=360;
  729. else if (a2 <-180)a2+=360;
  730. child.resultTransform.x=cx;
  731. child.resultTransform.y=cy;
  732. child.resultTransform.skX=child.resultTransform.skY=child.resultTransform.skY+a2 *alpha;
  733. parent.update();
  734. }
  735. //TODO:coverage
  736. __proto._applyIk3=function(parent,child,targetX,targetY,bendDir,alpha){
  737. if (alpha==0){
  738. return;
  739. };
  740. var cwx=NaN,cwy=NaN;
  741. var x=child.resultMatrix.a *child.length;
  742. var y=child.resultMatrix.b *child.length;
  743. var lLL=x *x+y *y;
  744. var lL=Math.sqrt(lLL);
  745. var parentX=parent.resultMatrix.tx;
  746. var parentY=parent.resultMatrix.ty;
  747. var childX=child.resultMatrix.tx;
  748. var childY=child.resultMatrix.ty;
  749. var dX=childX-parentX;
  750. var dY=childY-parentY;
  751. var lPP=dX *dX+dY *dY;
  752. var lP=Math.sqrt(lPP);
  753. dX=targetX-parent.resultMatrix.tx;
  754. dY=targetY-parent.resultMatrix.ty;
  755. var lTT=dX *dX+dY *dY;
  756. var lT=Math.sqrt(lTT);
  757. var ikRadianA=0;
  758. if (lL+lP <=lT || lT+lL <=lP || lT+lP <=lL){
  759. var rate=NaN;
  760. if (lL+lP <=lT){
  761. rate=1;
  762. }else{
  763. rate=-1;
  764. }
  765. childX=parentX+rate*(targetX-parentX)*lP / lT;
  766. childY=parentY+rate*(targetY-parentY)*lP / lT;
  767. }
  768. else{
  769. var h=(lPP-lLL+lTT)/ (2 *lTT);
  770. var r=Math.sqrt(lPP-h *h *lTT)/ lT;
  771. var hX=parentX+(dX *h);
  772. var hY=parentY+(dY *h);
  773. var rX=-dY *r;
  774. var rY=dX *r;
  775. if (bendDir>0){
  776. childX=hX-rX;
  777. childY=hY-rY;
  778. }
  779. else{
  780. childX=hX+rX;
  781. childY=hY+rY;
  782. }
  783. }
  784. cwx=childX;
  785. cwy=childY;
  786. if (this.isDebug){
  787. if (!this._sp){
  788. this._sp=new Sprite();
  789. Laya.stage.addChild(this._sp);
  790. }
  791. this._sp.graphics.clear();
  792. this._sp.graphics.drawCircle(parentX,parentY,15,"#ff00ff");
  793. this._sp.graphics.drawCircle(targetX,targetY,15,"#ffff00");
  794. this._sp.graphics.drawCircle(cwx,cwy,15,"#ff00ff");
  795. };
  796. var pRotation=NaN;
  797. pRotation=Math.atan2(cwy-parent.resultMatrix.ty,cwx-parent.resultMatrix.tx);
  798. parent.setRotation(pRotation);
  799. var pTarMatrix;
  800. pTarMatrix=IkConstraint._tempMatrix;
  801. pTarMatrix.identity();
  802. pTarMatrix.rotate(pRotation);
  803. pTarMatrix.scale(parent.resultMatrix.getScaleX(),parent.resultMatrix.getScaleY());
  804. pTarMatrix.translate(parent.resultMatrix.tx,parent.resultMatrix.ty);
  805. pTarMatrix.copyTo(parent.resultMatrix);
  806. parent.updateChild();
  807. var childRotation=NaN;
  808. childRotation=Math.atan2(targetY-cwy,targetX-cwx);
  809. child.setRotation(childRotation);
  810. var childTarMatrix;
  811. childTarMatrix=IkConstraint._tempMatrix;
  812. childTarMatrix.identity();
  813. childTarMatrix.rotate(childRotation);
  814. childTarMatrix.scale(child.resultMatrix.getScaleX(),child.resultMatrix.getScaleY());
  815. childTarMatrix.translate(cwx,cwy);
  816. pTarMatrix.copyTo(child.resultMatrix);
  817. child.updateChild();
  818. }
  819. __static(IkConstraint,
  820. ['radDeg',function(){return this.radDeg=180 / Math.PI;},'degRad',function(){return this.degRad=Math.PI / 180;},'_tempMatrix',function(){return this._tempMatrix=new Matrix();}
  821. ]);
  822. return IkConstraint;
  823. })()
  824. //TODO:coverage
  825. //class laya.ani.bone.TfConstraintData
  826. var TfConstraintData=(function(){
  827. function TfConstraintData(){
  828. this.name=null;
  829. this.targetIndex=0;
  830. this.rotateMix=NaN;
  831. this.translateMix=NaN;
  832. this.scaleMix=NaN;
  833. this.shearMix=NaN;
  834. this.offsetRotation=NaN;
  835. this.offsetX=NaN;
  836. this.offsetY=NaN;
  837. this.offsetScaleX=NaN;
  838. this.offsetScaleY=NaN;
  839. this.offsetShearY=NaN;
  840. this.boneIndexs=[];
  841. }
  842. __class(TfConstraintData,'laya.ani.bone.TfConstraintData');
  843. return TfConstraintData;
  844. })()
  845. /**
  846. *@private
  847. *@author ...
  848. */
  849. //class laya.ani.AnimationContent
  850. var AnimationContent=(function(){
  851. function AnimationContent(){
  852. this.nodes=null;
  853. this.name=null;
  854. this.playTime=NaN;
  855. this.bone3DMap=null;
  856. this.totalKeyframeDatasLength=0;
  857. }
  858. __class(AnimationContent,'laya.ani.AnimationContent');
  859. return AnimationContent;
  860. })()
  861. /**
  862. *@private
  863. */
  864. //class laya.ani.AnimationState
  865. var AnimationState=(function(){
  866. function AnimationState(){}
  867. __class(AnimationState,'laya.ani.AnimationState');
  868. AnimationState.stopped=0;
  869. AnimationState.paused=1;
  870. AnimationState.playing=2;
  871. return AnimationState;
  872. })()
  873. /**
  874. *@private
  875. */
  876. //class laya.ani.bone.DeformAniData
  877. var DeformAniData=(function(){
  878. function DeformAniData(){
  879. this.skinName=null;
  880. this.deformSlotDataList=[];
  881. }
  882. __class(DeformAniData,'laya.ani.bone.DeformAniData');
  883. return DeformAniData;
  884. })()
  885. /**
  886. *@private
  887. */
  888. //class laya.ani.bone.SkinSlotDisplayData
  889. var SkinSlotDisplayData=(function(){
  890. function SkinSlotDisplayData(){
  891. this.name=null;
  892. this.attachmentName=null;
  893. this.type=0;
  894. //0 硬 1 skin 2 另一种skin? 3 不支持
  895. this.transform=null;
  896. this.width=NaN;
  897. this.height=NaN;
  898. this.texture=null;
  899. this.bones=null;
  900. this.uvs=null;
  901. this.weights=null;
  902. this.triangles=null;
  903. this.vertices=null;
  904. this.lengths=null;
  905. this.verLen=0;
  906. }
  907. __class(SkinSlotDisplayData,'laya.ani.bone.SkinSlotDisplayData');
  908. var __proto=SkinSlotDisplayData.prototype;
  909. __proto.createTexture=function(currTexture){
  910. if (this.texture)return this.texture;
  911. this.texture=new Texture(currTexture.bitmap,this.uvs);
  912. if (this.uvs[0] > this.uvs[4]
  913. && this.uvs[1] > this.uvs[5]){
  914. this.texture.width=currTexture.height;
  915. this.texture.height=currTexture.width;
  916. this.texture.offsetX=-currTexture.offsetX;
  917. this.texture.offsetY=-currTexture.offsetY;
  918. this.texture.sourceWidth=currTexture.sourceHeight;
  919. this.texture.sourceHeight=currTexture.sourceWidth;
  920. }else {
  921. this.texture.width=currTexture.width;
  922. this.texture.height=currTexture.height;
  923. this.texture.offsetX=-currTexture.offsetX;
  924. this.texture.offsetY=-currTexture.offsetY;
  925. this.texture.sourceWidth=currTexture.sourceWidth;
  926. this.texture.sourceHeight=currTexture.sourceHeight;
  927. }
  928. return this.texture;
  929. }
  930. __proto.destory=function(){
  931. if (this.texture)this.texture.destroy();
  932. }
  933. return SkinSlotDisplayData;
  934. })()
  935. /**
  936. *@private
  937. */
  938. //class laya.ani.bone.DeformSlotDisplayData
  939. var DeformSlotDisplayData=(function(){
  940. function DeformSlotDisplayData(){
  941. this.boneSlot=null;
  942. this.slotIndex=-1;
  943. this.attachment=null;
  944. this.deformData=null;
  945. this.frameIndex=0;
  946. this.timeList=[];
  947. this.vectices=[];
  948. this.tweenKeyList=[];
  949. }
  950. __class(DeformSlotDisplayData,'laya.ani.bone.DeformSlotDisplayData');
  951. var __proto=DeformSlotDisplayData.prototype;
  952. __proto.binarySearch1=function(values,target){
  953. var low=0;
  954. var high=values.length-2;
  955. if (high==0)
  956. return 1;
  957. var current=high >>> 1;
  958. while (true){
  959. if (values[Math.floor(current+1)] <=target)
  960. low=current+1;
  961. else
  962. high=current;
  963. if (low==high)
  964. return low+1;
  965. current=(low+high)>>> 1;
  966. }
  967. return 0;
  968. }
  969. //TODO:coverage
  970. __proto.apply=function(time,boneSlot,alpha){
  971. (alpha===void 0)&& (alpha=1);
  972. time+=0.05;
  973. if (this.timeList.length <=0){
  974. return;
  975. };
  976. var i=0;
  977. var n=0;
  978. var tTime=this.timeList[0];
  979. if (time < tTime){
  980. return;
  981. };
  982. var tVertexCount=this.vectices[0].length;
  983. var tVertices=[];
  984. var tFrameIndex=this.binarySearch1(this.timeList,time);
  985. this.frameIndex=tFrameIndex;
  986. if (time >=this.timeList[this.timeList.length-1]){
  987. var lastVertices=this.vectices[this.vectices.length-1];
  988. if (alpha < 1){
  989. for (i=0;i < tVertexCount;i++){
  990. tVertices[i]+=(lastVertices[i]-tVertices[i])*alpha;
  991. }
  992. }else {
  993. for (i=0;i < tVertexCount;i++){
  994. tVertices[i]=lastVertices[i];
  995. }
  996. }
  997. this.deformData=tVertices;
  998. return;
  999. };
  1000. var tTweenKey=this.tweenKeyList[this.frameIndex];
  1001. var tPrevVertices=this.vectices[this.frameIndex-1];
  1002. var tNextVertices=this.vectices[this.frameIndex];
  1003. var tPreFrameTime=this.timeList[this.frameIndex-1];
  1004. var tFrameTime=this.timeList[this.frameIndex];
  1005. if (this.tweenKeyList[tFrameIndex-1]){
  1006. alpha=(time-tPreFrameTime)/ (tFrameTime-tPreFrameTime);
  1007. }else {
  1008. alpha=0;
  1009. };
  1010. var tPrev=NaN;
  1011. for (i=0;i < tVertexCount;i++){
  1012. tPrev=tPrevVertices[i];
  1013. tVertices[i]=tPrev+(tNextVertices[i]-tPrev)*alpha;
  1014. }
  1015. this.deformData=tVertices;
  1016. }
  1017. return DeformSlotDisplayData;
  1018. })()
  1019. /**
  1020. *@private
  1021. */
  1022. //class laya.ani.bone.BoneSlot
  1023. var BoneSlot=(function(){
  1024. function BoneSlot(){
  1025. /**插槽名称 */
  1026. this.name=null;
  1027. /**插槽绑定的骨骼名称 */
  1028. this.parent=null;
  1029. /**插糟显示数据数据的名称 */
  1030. this.attachmentName=null;
  1031. /**原始数据的索引 */
  1032. this.srcDisplayIndex=-1;
  1033. /**判断对象是否是原对象 */
  1034. this.type="src";
  1035. /**模板的指针 */
  1036. this.templet=null;
  1037. /**当前插槽对应的数据 */
  1038. this.currSlotData=null;
  1039. /**当前插槽显示的纹理 */
  1040. this.currTexture=null;
  1041. /**显示对象对应的数据 */
  1042. this.currDisplayData=null;
  1043. /**显示皮肤的索引 */
  1044. this.displayIndex=-1;
  1045. /**@private */
  1046. this.originalIndex=-1;
  1047. /**用户自定义的皮肤 */
  1048. this._diyTexture=null;
  1049. this._parentMatrix=null;
  1050. // 指向了骨骼的resultMatrix
  1051. this._resultMatrix=null;
  1052. /**索引替换表 */
  1053. this._replaceDic={};
  1054. /**当前diyTexture的动画纹理 */
  1055. this._curDiyUV=null;
  1056. this._curDiyVS=null;
  1057. /**实时模式下,复用使用 */
  1058. this._skinSprite=null;
  1059. /**@private 变形动画数据 */
  1060. this.deformData=null;
  1061. this._mVerticleArr=null;
  1062. this._preGraphicVerticle=null;
  1063. this._preGraphicMatrix=null;
  1064. }
  1065. __class(BoneSlot,'laya.ani.bone.BoneSlot');
  1066. var __proto=BoneSlot.prototype;
  1067. /**
  1068. *设置要显示的插槽数据
  1069. *@param slotData
  1070. *@param disIndex
  1071. *@param freshIndex 是否重置纹理
  1072. */
  1073. __proto.showSlotData=function(slotData,freshIndex){
  1074. (freshIndex===void 0)&& (freshIndex=true);
  1075. this.currSlotData=slotData;
  1076. if(freshIndex)
  1077. this.displayIndex=this.srcDisplayIndex;
  1078. this.currDisplayData=null;
  1079. this.currTexture=null;
  1080. }
  1081. /**
  1082. *通过名字显示指定对象
  1083. *@param name
  1084. */
  1085. __proto.showDisplayByName=function(name){
  1086. if (this.currSlotData){
  1087. this.showDisplayByIndex(this.currSlotData.getDisplayByName(name));
  1088. }
  1089. }
  1090. /**
  1091. *替换贴图名
  1092. *@param tarName 要替换的贴图名
  1093. *@param newName 替换后的贴图名
  1094. */
  1095. __proto.replaceDisplayByName=function(tarName,newName){
  1096. if (!this.currSlotData)return;
  1097. var preIndex=0;
  1098. preIndex=this.currSlotData.getDisplayByName(tarName);
  1099. var newIndex=0;
  1100. newIndex=this.currSlotData.getDisplayByName(newName);
  1101. this.replaceDisplayByIndex(preIndex,newIndex);
  1102. }
  1103. /**
  1104. *替换贴图索引
  1105. *@param tarIndex 要替换的索引
  1106. *@param newIndex 替换后的索引
  1107. */
  1108. __proto.replaceDisplayByIndex=function(tarIndex,newIndex){
  1109. if (!this.currSlotData)return;
  1110. this._replaceDic[tarIndex]=newIndex;
  1111. if (this.originalIndex==tarIndex){
  1112. this.showDisplayByIndex(tarIndex);
  1113. }
  1114. }
  1115. /**
  1116. *指定显示对象
  1117. *@param index
  1118. */
  1119. __proto.showDisplayByIndex=function(index){
  1120. this.originalIndex=index;
  1121. if (this._replaceDic[index]!=null)index=this._replaceDic[index];
  1122. if (this.currSlotData && index >-1 && index < this.currSlotData.displayArr.length){
  1123. this.displayIndex=index;
  1124. this.currDisplayData=this.currSlotData.displayArr[index];
  1125. if (this.currDisplayData){
  1126. var tName=this.currDisplayData.name;
  1127. this.currTexture=this.templet.getTexture(tName);
  1128. if (this.currTexture && this.currDisplayData.type==0 && this.currDisplayData.uvs){
  1129. this.currTexture=this.currDisplayData.createTexture(this.currTexture);
  1130. }
  1131. }
  1132. }else {
  1133. this.displayIndex=-1;
  1134. this.currDisplayData=null;
  1135. this.currTexture=null;
  1136. }
  1137. }
  1138. /**
  1139. *替换皮肤
  1140. *@param _texture
  1141. */
  1142. __proto.replaceSkin=function(_texture){
  1143. this._diyTexture=_texture;
  1144. if (this._curDiyUV)this._curDiyUV.length=0;
  1145. if (this.currDisplayData&&this._diyTexture==this.currDisplayData.texture){
  1146. this._diyTexture=null;
  1147. }
  1148. }
  1149. //TODO:coverage
  1150. __proto.setParentMatrix=function(parentMatrix){
  1151. this._parentMatrix=parentMatrix;
  1152. }
  1153. //TODO:coverage
  1154. __proto.getSaveVerticle=function(tArr){
  1155. if (BoneSlot.useSameMatrixAndVerticle&&this._preGraphicVerticle && BoneSlot.isSameArr(tArr,this._preGraphicVerticle)){
  1156. tArr=this._preGraphicVerticle;
  1157. }else{
  1158. tArr=Utils.copyArray([],tArr);
  1159. this._preGraphicVerticle=tArr;
  1160. }
  1161. return tArr;
  1162. }
  1163. //TODO:coverage
  1164. __proto.getSaveMatrix=function(tResultMatrix){
  1165. if (BoneSlot.useSameMatrixAndVerticle&&this._preGraphicMatrix && BoneSlot.isSameMatrix(tResultMatrix,this._preGraphicMatrix)){
  1166. tResultMatrix=this._preGraphicMatrix;
  1167. }else{
  1168. var newMatrix=tResultMatrix.clone();
  1169. tResultMatrix=newMatrix;
  1170. this._preGraphicMatrix=tResultMatrix;
  1171. }
  1172. return tResultMatrix;
  1173. }
  1174. /**
  1175. *把纹理画到Graphics上
  1176. *@param graphics
  1177. *@param noUseSave 不使用共享的矩阵对象 _tempResultMatrix,只有实时计算的时候才设置为true
  1178. */
  1179. __proto.draw=function(graphics,boneMatrixArray,noUseSave,alpha){
  1180. (noUseSave===void 0)&& (noUseSave=false);
  1181. (alpha===void 0)&& (alpha=1);
  1182. if ((this._diyTexture==null && this.currTexture==null)|| this.currDisplayData==null){
  1183. if (!(this.currDisplayData && this.currDisplayData.type==3)){
  1184. return;
  1185. }
  1186. };
  1187. var tTexture=this.currTexture;
  1188. if (this._diyTexture)tTexture=this._diyTexture;
  1189. var tSkinSprite;
  1190. switch (this.currDisplayData.type){
  1191. case 0:
  1192. if (graphics){
  1193. var tCurrentMatrix=this.getDisplayMatrix();
  1194. if (this._parentMatrix){
  1195. var tRotateKey=false;
  1196. if (tCurrentMatrix){
  1197. Matrix.mul(tCurrentMatrix,this._parentMatrix,Matrix.TEMP);
  1198. var tResultMatrix;
  1199. if (noUseSave){
  1200. if (this._resultMatrix==null)this._resultMatrix=new Matrix();
  1201. tResultMatrix=this._resultMatrix;
  1202. }else {
  1203. tResultMatrix=BoneSlot._tempResultMatrix;
  1204. }
  1205. if (this._diyTexture && this.currDisplayData.uvs){
  1206. var tTestMatrix=BoneSlot._tempMatrix;
  1207. tTestMatrix.identity();
  1208. if (this.currDisplayData.uvs[1] > this.currDisplayData.uvs[5]){
  1209. tTestMatrix.d=-1;
  1210. }
  1211. if (this.currDisplayData.uvs[0] > this.currDisplayData.uvs[4]
  1212. && this.currDisplayData.uvs[1] > this.currDisplayData.uvs[5]){
  1213. tRotateKey=true;
  1214. tTestMatrix.rotate(-Math.PI/2);
  1215. }
  1216. Matrix.mul(tTestMatrix,Matrix.TEMP,tResultMatrix);
  1217. }else {
  1218. Matrix.TEMP.copyTo(tResultMatrix);
  1219. }
  1220. if (!noUseSave){
  1221. tResultMatrix=this.getSaveMatrix(tResultMatrix);
  1222. }
  1223. tResultMatrix._checkTransform();
  1224. if (tRotateKey){
  1225. graphics.drawTexture(tTexture,-this.currDisplayData.height / 2,-this.currDisplayData.width / 2,this.currDisplayData.height,this.currDisplayData.width,tResultMatrix,alpha);
  1226. }else {
  1227. graphics.drawTexture(tTexture,-this.currDisplayData.width / 2,-this.currDisplayData.height / 2,this.currDisplayData.width,this.currDisplayData.height,tResultMatrix,alpha);
  1228. }
  1229. }
  1230. }
  1231. }
  1232. break ;
  1233. case 1:
  1234. if (noUseSave){
  1235. if (this._skinSprite==null){
  1236. this._skinSprite=BoneSlot.createSkinMesh();
  1237. }
  1238. tSkinSprite=this._skinSprite;
  1239. }else {
  1240. tSkinSprite=BoneSlot.createSkinMesh();
  1241. }
  1242. if (tSkinSprite==null){
  1243. return;
  1244. };
  1245. var tIBArray;
  1246. var tRed=1;
  1247. var tGreed=1;
  1248. var tBlue=1;
  1249. var tAlpha=1;
  1250. if (this.currDisplayData.bones==null){
  1251. var tVertices=this.currDisplayData.weights;
  1252. if (this.deformData){
  1253. tVertices=this.deformData;
  1254. };
  1255. var tUVs;
  1256. if (this._diyTexture){
  1257. if (!this._curDiyUV){
  1258. this._curDiyUV=[];
  1259. }
  1260. if (this._curDiyUV.length==0){
  1261. this._curDiyUV=UVTools.getRelativeUV(this.currTexture.uv,this.currDisplayData.uvs,this._curDiyUV);
  1262. this._curDiyUV=UVTools.getAbsoluteUV(this._diyTexture.uv,this._curDiyUV,this._curDiyUV);
  1263. }
  1264. tUVs=this._curDiyUV;
  1265. }else{
  1266. tUVs=this.currDisplayData.uvs;
  1267. }
  1268. this._mVerticleArr=tVertices;
  1269. var tTriangleNum=this.currDisplayData.triangles.length / 3;
  1270. tIBArray=this.currDisplayData.triangles;
  1271. if (this.deformData){
  1272. if (!noUseSave){
  1273. this._mVerticleArr=this.getSaveVerticle(this._mVerticleArr);
  1274. }
  1275. }
  1276. tSkinSprite.init2(tTexture,tIBArray,this._mVerticleArr,tUVs);
  1277. var tCurrentMatrix2=this.getDisplayMatrix();
  1278. if (this._parentMatrix){
  1279. if (tCurrentMatrix2){
  1280. Matrix.mul(tCurrentMatrix2,this._parentMatrix,Matrix.TEMP);
  1281. var tResultMatrix2;
  1282. if (noUseSave){
  1283. if (this._resultMatrix==null)this._resultMatrix=new Matrix();
  1284. tResultMatrix2=this._resultMatrix;
  1285. }else {
  1286. tResultMatrix2=BoneSlot._tempResultMatrix;
  1287. }
  1288. Matrix.TEMP.copyTo(tResultMatrix2);
  1289. if (!noUseSave){
  1290. tResultMatrix2=this.getSaveMatrix(tResultMatrix2);
  1291. }
  1292. tSkinSprite.transform=tResultMatrix2;
  1293. }
  1294. }
  1295. }else {
  1296. this.skinMesh(boneMatrixArray,tSkinSprite);
  1297. }
  1298. graphics.drawSkin(tSkinSprite,alpha);
  1299. break ;
  1300. case 2:
  1301. if (noUseSave){
  1302. if (this._skinSprite==null){
  1303. this._skinSprite=BoneSlot.createSkinMesh();
  1304. }
  1305. tSkinSprite=this._skinSprite;
  1306. }else {
  1307. tSkinSprite=BoneSlot.createSkinMesh();
  1308. }
  1309. if (tSkinSprite==null){
  1310. return;
  1311. }
  1312. this.skinMesh(boneMatrixArray,tSkinSprite);
  1313. graphics.drawSkin(tSkinSprite,alpha);
  1314. break ;
  1315. case 3:
  1316. break ;
  1317. }
  1318. }
  1319. /**
  1320. *显示蒙皮动画
  1321. *@param boneMatrixArray 当前帧的骨骼矩阵
  1322. */
  1323. __proto.skinMesh=function(boneMatrixArray,skinSprite){
  1324. var tTexture=this.currTexture;
  1325. var tBones=this.currDisplayData.bones;
  1326. var tUvs;
  1327. if (this._diyTexture){
  1328. tTexture=this._diyTexture;
  1329. if (!this._curDiyUV){
  1330. this._curDiyUV=[];
  1331. }
  1332. if (this._curDiyUV.length==0){
  1333. this._curDiyUV=UVTools.getRelativeUV(this.currTexture.uv,this.currDisplayData.uvs,this._curDiyUV);
  1334. this._curDiyUV=UVTools.getAbsoluteUV(this._diyTexture.uv,this._curDiyUV,this._curDiyUV);
  1335. }
  1336. tUvs=this._curDiyUV;
  1337. }else{
  1338. tUvs=this.currDisplayData.uvs;
  1339. };
  1340. var tWeights=this.currDisplayData.weights;
  1341. var tTriangles=this.currDisplayData.triangles;
  1342. var tIBArray;
  1343. var tRx=0;
  1344. var tRy=0;
  1345. var nn=0;
  1346. var tMatrix;
  1347. var tX=NaN;
  1348. var tY=NaN;
  1349. var tB=0;
  1350. var tWeight=0;
  1351. var tVertices;
  1352. var i=0,j=0,n=0;
  1353. var tRed=1;
  1354. var tGreed=1;
  1355. var tBlue=1;
  1356. BoneSlot._tempVerticleArr.length=0;
  1357. tVertices=BoneSlot._tempVerticleArr;
  1358. if (this.deformData && this.deformData.length > 0){
  1359. var f=0;
  1360. for (i=0,n=tBones.length;i < n;){
  1361. nn=tBones[i++]+i;
  1362. tRx=0,tRy=0;
  1363. for (;i < nn;i++){
  1364. tMatrix=boneMatrixArray[tBones[i]]
  1365. tX=tWeights[tB]+this.deformData[f++];
  1366. tY=tWeights[tB+1]+this.deformData[f++];
  1367. tWeight=tWeights[tB+2];
  1368. tRx+=(tX *tMatrix.a+tY *tMatrix.c+tMatrix.tx)*tWeight;
  1369. tRy+=(tX *tMatrix.b+tY *tMatrix.d+tMatrix.ty)*tWeight;
  1370. tB+=3;
  1371. }
  1372. tVertices.push(tRx,tRy);
  1373. }
  1374. }else {
  1375. for (i=0,n=tBones.length;i < n;){
  1376. nn=tBones[i++]+i;
  1377. tRx=0,tRy=0;
  1378. for (;i < nn;i++){
  1379. tMatrix=boneMatrixArray[tBones[i]]
  1380. tX=tWeights[tB];
  1381. tY=tWeights[tB+1];
  1382. tWeight=tWeights[tB+2];
  1383. tRx+=(tX *tMatrix.a+tY *tMatrix.c+tMatrix.tx)*tWeight;
  1384. tRy+=(tX *tMatrix.b+tY *tMatrix.d+tMatrix.ty)*tWeight;
  1385. tB+=3;
  1386. }
  1387. tVertices.push(tRx,tRy);
  1388. }
  1389. }
  1390. this._mVerticleArr=tVertices;
  1391. tIBArray=tTriangles;
  1392. this._mVerticleArr=this.getSaveVerticle(this._mVerticleArr);
  1393. skinSprite.init2(tTexture,tIBArray,this._mVerticleArr,tUvs);
  1394. }
  1395. /**
  1396. *画骨骼的起始点,方便调试
  1397. *@param graphics
  1398. */
  1399. __proto.drawBonePoint=function(graphics){
  1400. if (graphics && this._parentMatrix){
  1401. graphics.drawCircle(this._parentMatrix.tx,this._parentMatrix.ty,5,"#ff0000");
  1402. }
  1403. }
  1404. //TODO:coverage
  1405. __proto.getDisplayMatrix=function(){
  1406. if (this.currDisplayData){
  1407. return this.currDisplayData.transform.getMatrix();
  1408. }
  1409. return null;
  1410. }
  1411. /**
  1412. *得到插糟的矩阵
  1413. *@return
  1414. */
  1415. __proto.getMatrix=function(){
  1416. return this._resultMatrix;
  1417. }
  1418. /**
  1419. *用原始数据拷贝出一个
  1420. *@return
  1421. */
  1422. __proto.copy=function(){
  1423. var tBoneSlot=new BoneSlot();
  1424. tBoneSlot.type="copy";
  1425. tBoneSlot.name=this.name;
  1426. tBoneSlot.attachmentName=this.attachmentName;
  1427. tBoneSlot.srcDisplayIndex=this.srcDisplayIndex;
  1428. tBoneSlot.parent=this.parent;
  1429. tBoneSlot.displayIndex=this.displayIndex;
  1430. tBoneSlot.templet=this.templet;
  1431. tBoneSlot.currSlotData=this.currSlotData;
  1432. tBoneSlot.currTexture=this.currTexture;
  1433. tBoneSlot.currDisplayData=this.currDisplayData;
  1434. return tBoneSlot;
  1435. }
  1436. BoneSlot.createSkinMesh=function(){
  1437. return new SkinMeshForGraphic();
  1438. }
  1439. BoneSlot.isSameArr=function(arrA,arrB){
  1440. if (arrA.length !=arrB.length)return false;
  1441. var i=0,len=0;
  1442. len=arrA.length;
  1443. for (i=0;i < len;i++){
  1444. if (arrA[i] !=arrB[i])return false;
  1445. }
  1446. return true;
  1447. }
  1448. BoneSlot.isSameMatrix=function(mtA,mtB){
  1449. return mtA.a==mtB.a && mtA.b==mtB.b && mtA.c==mtB.c && mtA.d==mtB.d && Math.abs(mtA.tx-mtB.tx)<0.00001 && Math.abs(mtA.ty-mtB.ty)<0.00001;
  1450. }
  1451. BoneSlot.useSameMatrixAndVerticle=true;
  1452. BoneSlot._tempVerticleArr=[];
  1453. __static(BoneSlot,
  1454. ['_tempMatrix',function(){return this._tempMatrix=new Matrix();},'_tempResultMatrix',function(){return this._tempResultMatrix=new Matrix();}
  1455. ]);
  1456. return BoneSlot;
  1457. })()
  1458. /**
  1459. *@private
  1460. *路径作用器
  1461. *1,生成根据骨骼计算控制点
  1462. *2,根据控制点生成路径,并计算路径上的节点
  1463. *3,根据节点,重新调整骨骼位置
  1464. */
  1465. //class laya.ani.bone.PathConstraint
  1466. var PathConstraint=(function(){
  1467. function PathConstraint(data,bones){
  1468. this.target=null;
  1469. this.data=null;
  1470. this.bones=null;
  1471. this.position=NaN;
  1472. this.spacing=NaN;
  1473. this.rotateMix=NaN;
  1474. this.translateMix=NaN;
  1475. this._debugKey=false;
  1476. this._spaces=null;
  1477. this._segments=[];
  1478. this._curves=[];
  1479. this.data=data;
  1480. this.position=data.position;
  1481. this.spacing=data.spacing;
  1482. this.rotateMix=data.rotateMix;
  1483. this.translateMix=data.translateMix;
  1484. this.bones=[];
  1485. var tBoneIds=this.data.bones;
  1486. for (var i=0,n=tBoneIds.length;i < n;i++){
  1487. this.bones.push(bones[tBoneIds[i]]);
  1488. }
  1489. }
  1490. __class(PathConstraint,'laya.ani.bone.PathConstraint');
  1491. var __proto=PathConstraint.prototype;
  1492. //TODO:coverage
  1493. __proto.apply=function(boneList,graphics){
  1494. if (!this.target)
  1495. return;
  1496. var tTranslateMix=this.translateMix;
  1497. var tRotateMix=this.translateMix;
  1498. var tTranslate=tTranslateMix > 0;
  1499. var tRotate=tRotateMix > 0;
  1500. var tSpacingMode=this.data.spacingMode;
  1501. var tLengthSpacing=tSpacingMode=="length";
  1502. var tRotateMode=this.data.rotateMode;
  1503. var tTangents=tRotateMode=="tangent";
  1504. var tScale=tRotateMode=="chainScale";
  1505. var lengths=[];
  1506. var boneCount=this.bones.length;
  1507. var spacesCount=tTangents ? boneCount :boneCount+1;
  1508. var spaces=[];
  1509. this._spaces=spaces;
  1510. spaces[0]=this.position;
  1511. var spacing=this.spacing;
  1512. if (tScale || tLengthSpacing){
  1513. for (var i=0,n=spacesCount-1;i < n;){
  1514. var bone=this.bones[i];
  1515. var length=bone.length;
  1516. var x=length *bone.resultMatrix.a;
  1517. var y=length *bone.resultMatrix.b;
  1518. length=Math.sqrt(x *x+y *y);
  1519. if (tScale)
  1520. lengths[i]=length;
  1521. spaces[++i]=tLengthSpacing ? Math.max(0,length+spacing):spacing;
  1522. }
  1523. }
  1524. else {
  1525. for (i=1;i < spacesCount;i++){
  1526. spaces[i]=spacing;
  1527. }
  1528. };
  1529. var positions=this.computeWorldPositions(this.target,boneList,graphics,spacesCount,tTangents,this.data.positionMode=="percent",tSpacingMode=="percent");
  1530. if (this._debugKey){
  1531. for (i=0;i < positions.length;i++){
  1532. graphics.drawCircle(positions[i++],positions[i++],5,"#00ff00");
  1533. };
  1534. var tLinePos=[];
  1535. for (i=0;i < positions.length;i++){
  1536. tLinePos.push(positions[i++],positions[i++]);
  1537. }
  1538. graphics.drawLines(0,0,tLinePos,"#ff0000");
  1539. };
  1540. var skeletonX=NaN;
  1541. var skeletonY=NaN;
  1542. var boneX=positions[0];
  1543. var boneY=positions[1];
  1544. var offsetRotation=this.data.offsetRotation;
  1545. var tip=tRotateMode=="chain" && offsetRotation==0;
  1546. var p=NaN;
  1547. for (i=0,p=3;i < boneCount;i++,p+=3){
  1548. bone=this.bones[i];
  1549. bone.resultMatrix.tx+=(boneX-bone.resultMatrix.tx)*tTranslateMix;
  1550. bone.resultMatrix.ty+=(boneY-bone.resultMatrix.ty)*tTranslateMix;
  1551. x=positions[p];
  1552. y=positions[p+1];
  1553. var dx=x-boneX,dy=y-boneY;
  1554. if (tScale){
  1555. length=lengths[i];
  1556. if (length !=0){
  1557. var s=(Math.sqrt(dx *dx+dy *dy)/ length-1)*tRotateMix+1;
  1558. bone.resultMatrix.a *=s;
  1559. bone.resultMatrix.c *=s;
  1560. }
  1561. }
  1562. boneX=x;
  1563. boneY=y;
  1564. if (tRotate){
  1565. var a=bone.resultMatrix.a;
  1566. var b=bone.resultMatrix.c;
  1567. var c=bone.resultMatrix.b;
  1568. var d=bone.resultMatrix.d;
  1569. var r=NaN;
  1570. var cos=NaN;
  1571. var sin=NaN;
  1572. if (tTangents){
  1573. r=positions[p-1];
  1574. }
  1575. else if (spaces[i+1]==0){
  1576. r=positions[p+2];
  1577. }
  1578. else {
  1579. r=Math.atan2(dy,dx);
  1580. }
  1581. r-=Math.atan2(c,a)-offsetRotation / 180 *Math.PI;
  1582. if (tip){
  1583. cos=Math.cos(r);
  1584. sin=Math.sin(r);
  1585. length=bone.length;
  1586. boneX+=(length *(cos *a-sin *c)-dx)*tRotateMix;
  1587. boneY+=(length *(sin *a+cos *c)-dy)*tRotateMix;
  1588. }
  1589. if (r > Math.PI){
  1590. r-=(Math.PI *2);
  1591. }
  1592. else if (r <-Math.PI){
  1593. r+=(Math.PI *2);
  1594. }
  1595. r *=tRotateMix;
  1596. cos=Math.cos(r);
  1597. sin=Math.sin(r);
  1598. bone.resultMatrix.a=cos *a-sin *c;
  1599. bone.resultMatrix.c=cos *b-sin *d;
  1600. bone.resultMatrix.b=sin *a+cos *c;
  1601. bone.resultMatrix.d=sin *b+cos *d;
  1602. }
  1603. }
  1604. }
  1605. //TODO:coverage
  1606. __proto.computeWorldVertices2=function(boneSlot,boneList,start,count,worldVertices,offset){
  1607. var tBones=boneSlot.currDisplayData.bones;
  1608. var tWeights=boneSlot.currDisplayData.weights;
  1609. var tTriangles=boneSlot.currDisplayData.triangles;
  1610. var tMatrix;
  1611. var i=0;
  1612. var v=0;
  1613. var skip=0;
  1614. var n=0;
  1615. var w=0;
  1616. var b=0;
  1617. var wx=0;
  1618. var wy=0;
  1619. var vx=0;
  1620. var vy=0;
  1621. var bone;
  1622. var len=0;
  1623. if (tBones==null){
  1624. if (!tTriangles)tTriangles=tWeights;
  1625. if (boneSlot.deformData)
  1626. tTriangles=boneSlot.deformData;
  1627. var parentName;
  1628. parentName=boneSlot.parent;
  1629. if (boneList){
  1630. len=boneList.length;
  1631. for (i=0;i < len;i++){
  1632. if (boneList[i].name==parentName){
  1633. bone=boneList[i];
  1634. break ;
  1635. }
  1636. }
  1637. };
  1638. var tBoneMt;
  1639. if (bone){
  1640. tBoneMt=bone.resultMatrix;
  1641. }
  1642. if (!tBoneMt)tBoneMt=PathConstraint._tempMt;
  1643. var x=tBoneMt.tx;
  1644. var y=tBoneMt.ty;
  1645. var a=tBoneMt.a,bb=tBoneMt.b,c=tBoneMt.c,d=tBoneMt.d;
  1646. if(bone)d*=bone.d;
  1647. for (v=start,w=offset;w < count;v+=2,w+=2){
  1648. vx=tTriangles[v],vy=tTriangles[v+1];
  1649. worldVertices[w]=vx *a+vy *bb+x;
  1650. worldVertices[w+1]=-(vx *c+vy *d+y);
  1651. }
  1652. return;
  1653. }
  1654. for (i=0;i < start;i+=2){
  1655. n=tBones[v];
  1656. v+=n+1;
  1657. skip+=n;
  1658. };
  1659. var skeletonBones=boneList;
  1660. for (w=offset,b=skip *3;w < count;w+=2){
  1661. wx=0,wy=0;
  1662. n=tBones[v++];
  1663. n+=v;
  1664. for (;v < n;v++,b+=3){
  1665. tMatrix=skeletonBones[tBones[v]].resultMatrix;
  1666. vx=tWeights[b];
  1667. vy=tWeights[b+1];
  1668. var weight=tWeights[b+2];
  1669. wx+=(vx *tMatrix.a+vy *tMatrix.c+tMatrix.tx)*weight;
  1670. wy+=(vx *tMatrix.b+vy *tMatrix.d+tMatrix.ty)*weight;
  1671. }
  1672. worldVertices[w]=wx;
  1673. worldVertices[w+1]=wy;
  1674. }
  1675. }
  1676. //TODO:coverage
  1677. __proto.computeWorldPositions=function(boneSlot,boneList,graphics,spacesCount,tangents,percentPosition,percentSpacing){
  1678. var tBones=boneSlot.currDisplayData.bones;
  1679. var tWeights=boneSlot.currDisplayData.weights;
  1680. var tTriangles=boneSlot.currDisplayData.triangles;
  1681. var tRx=0;
  1682. var tRy=0;
  1683. var nn=0;
  1684. var tMatrix;
  1685. var tX=NaN;
  1686. var tY=NaN;
  1687. var tB=0;
  1688. var tWeight=0;
  1689. var tVertices=[];
  1690. var i=0,j=0,n=0;
  1691. var verticesLength=boneSlot.currDisplayData.verLen;
  1692. var target=boneSlot;
  1693. var position=this.position;
  1694. var spaces=this._spaces;
  1695. var world=[];
  1696. var out=[];
  1697. var closed=false;
  1698. var curveCount=verticesLength / 6;
  1699. var prevCurve=-1;
  1700. var pathLength=NaN;
  1701. var o=0,curve=0;
  1702. var p=NaN;
  1703. var space=NaN;
  1704. var prev=NaN;
  1705. var length=NaN;
  1706. if (!true){
  1707. var lengths=boneSlot.currDisplayData.lengths;
  1708. curveCount-=closed ? 1 :2;
  1709. pathLength=lengths[curveCount];
  1710. if (percentPosition)
  1711. position *=pathLength;
  1712. if (percentSpacing){
  1713. for (i=0;i < spacesCount;i++)
  1714. spaces[i] *=pathLength;
  1715. }
  1716. world.length=8;
  1717. for (i=0,o=0,curve=0;i < spacesCount;i++,o+=3){
  1718. space=spaces[i];
  1719. position+=space;
  1720. p=position;
  1721. if (closed){
  1722. p %=pathLength;
  1723. if (p < 0)
  1724. p+=pathLength;
  1725. curve=0;
  1726. }
  1727. else if (p < 0){
  1728. if (prevCurve !=PathConstraint.BEFORE){
  1729. prevCurve=PathConstraint.BEFORE;
  1730. this.computeWorldVertices2(target,boneList,2,4,world,0);
  1731. }
  1732. this.addBeforePosition(p,world,0,out,o);
  1733. continue ;
  1734. }
  1735. else if (p > pathLength){
  1736. if (prevCurve !=PathConstraint.AFTER){
  1737. prevCurve=PathConstraint.AFTER;
  1738. this.computeWorldVertices2(target,boneList,verticesLength-6,4,world,0);
  1739. }
  1740. this.addAfterPosition(p-pathLength,world,0,out,o);
  1741. continue ;
  1742. }
  1743. for (;;curve++){
  1744. length=lengths[curve];
  1745. if (p > length)
  1746. continue ;
  1747. if (curve==0)
  1748. p /=length;
  1749. else {
  1750. prev=lengths[curve-1];
  1751. p=(p-prev)/ (length-prev);
  1752. }
  1753. break ;
  1754. }
  1755. if (curve !=prevCurve){
  1756. prevCurve=curve;
  1757. if (closed && curve==curveCount){
  1758. this.computeWorldVertices2(target,boneList,verticesLength-4,4,world,0);
  1759. this.computeWorldVertices2(target,boneList,0,4,world,4);
  1760. }
  1761. else
  1762. this.computeWorldVertices2(target,boneList,curve *6+2,8,world,0);
  1763. }
  1764. 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));
  1765. }
  1766. return out;
  1767. }
  1768. if (closed){
  1769. verticesLength+=2;
  1770. world[verticesLength-2]=world[0];
  1771. world[verticesLength-1]=world[1];
  1772. }
  1773. else {
  1774. curveCount--;
  1775. verticesLength-=4;
  1776. this.computeWorldVertices2(boneSlot,boneList,2,verticesLength,tVertices,0);
  1777. if (this._debugKey){
  1778. for (i=0;i < tVertices.length;){
  1779. graphics.drawCircle(tVertices[i++],tVertices[i++],10,"#ff0000");
  1780. }
  1781. }
  1782. world=tVertices;
  1783. }
  1784. this._curves.length=curveCount;
  1785. var curves=this._curves;
  1786. pathLength=0;
  1787. var x1=world[0],y1=world[1],cx1=0,cy1=0,cx2=0,cy2=0,x2=0,y2=0;
  1788. var tmpx=NaN,tmpy=NaN,dddfx=NaN,dddfy=NaN,ddfx=NaN,ddfy=NaN,dfx=NaN,dfy=NaN;
  1789. var w=0;
  1790. for (i=0,w=2;i < curveCount;i++,w+=6){
  1791. cx1=world[w];
  1792. cy1=world[w+1];
  1793. cx2=world[w+2];
  1794. cy2=world[w+3];
  1795. x2=world[w+4];
  1796. y2=world[w+5];
  1797. tmpx=(x1-cx1 *2+cx2)*0.1875;
  1798. tmpy=(y1-cy1 *2+cy2)*0.1875;
  1799. dddfx=((cx1-cx2)*3-x1+x2)*0.09375;
  1800. dddfy=((cy1-cy2)*3-y1+y2)*0.09375;
  1801. ddfx=tmpx *2+dddfx;
  1802. ddfy=tmpy *2+dddfy;
  1803. dfx=(cx1-x1)*0.75+tmpx+dddfx *0.16666667;
  1804. dfy=(cy1-y1)*0.75+tmpy+dddfy *0.16666667;
  1805. pathLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1806. dfx+=ddfx;
  1807. dfy+=ddfy;
  1808. ddfx+=dddfx;
  1809. ddfy+=dddfy;
  1810. pathLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1811. dfx+=ddfx;
  1812. dfy+=ddfy;
  1813. pathLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1814. dfx+=ddfx+dddfx;
  1815. dfy+=ddfy+dddfy;
  1816. pathLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1817. curves[i]=pathLength;
  1818. x1=x2;
  1819. y1=y2;
  1820. }
  1821. if (percentPosition)
  1822. position *=pathLength;
  1823. if (percentSpacing){
  1824. for (i=0;i < spacesCount;i++)
  1825. spaces[i] *=pathLength;
  1826. };
  1827. var segments=this._segments;
  1828. var curveLength=0;
  1829. var segment=0;
  1830. for (i=0,o=0,curve=0,segment=0;i < spacesCount;i++,o+=3){
  1831. space=spaces[i];
  1832. position+=space;
  1833. p=position;
  1834. if (closed){
  1835. p %=pathLength;
  1836. if (p < 0)
  1837. p+=pathLength;
  1838. curve=0;
  1839. }
  1840. else if (p < 0){
  1841. this.addBeforePosition(p,world,0,out,o);
  1842. continue ;
  1843. }
  1844. else if (p > pathLength){
  1845. this.addAfterPosition(p-pathLength,world,verticesLength-4,out,o);
  1846. continue ;
  1847. }
  1848. for (;;curve++){
  1849. length=curves[curve];
  1850. if (p > length)
  1851. continue ;
  1852. if (curve==0)
  1853. p /=length;
  1854. else {
  1855. prev=curves[curve-1];
  1856. p=(p-prev)/ (length-prev);
  1857. }
  1858. break ;
  1859. }
  1860. if (curve !=prevCurve){
  1861. prevCurve=curve;
  1862. var ii=curve *6;
  1863. x1=world[ii];
  1864. y1=world[ii+1];
  1865. cx1=world[ii+2];
  1866. cy1=world[ii+3];
  1867. cx2=world[ii+4];
  1868. cy2=world[ii+5];
  1869. x2=world[ii+6];
  1870. y2=world[ii+7];
  1871. tmpx=(x1-cx1 *2+cx2)*0.03;
  1872. tmpy=(y1-cy1 *2+cy2)*0.03;
  1873. dddfx=((cx1-cx2)*3-x1+x2)*0.006;
  1874. dddfy=((cy1-cy2)*3-y1+y2)*0.006;
  1875. ddfx=tmpx *2+dddfx;
  1876. ddfy=tmpy *2+dddfy;
  1877. dfx=(cx1-x1)*0.3+tmpx+dddfx *0.16666667;
  1878. dfy=(cy1-y1)*0.3+tmpy+dddfy *0.16666667;
  1879. curveLength=Math.sqrt(dfx *dfx+dfy *dfy);
  1880. segments[0]=curveLength;
  1881. for (ii=1;ii < 8;ii++){
  1882. dfx+=ddfx;
  1883. dfy+=ddfy;
  1884. ddfx+=dddfx;
  1885. ddfy+=dddfy;
  1886. curveLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1887. segments[ii]=curveLength;
  1888. }
  1889. dfx+=ddfx;
  1890. dfy+=ddfy;
  1891. curveLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1892. segments[8]=curveLength;
  1893. dfx+=ddfx+dddfx;
  1894. dfy+=ddfy+dddfy;
  1895. curveLength+=Math.sqrt(dfx *dfx+dfy *dfy);
  1896. segments[9]=curveLength;
  1897. segment=0;
  1898. }
  1899. p *=curveLength;
  1900. for (;;segment++){
  1901. length=segments[segment];
  1902. if (p > length)
  1903. continue ;
  1904. if (segment==0)
  1905. p /=length;
  1906. else {
  1907. prev=segments[segment-1];
  1908. p=segment+(p-prev)/ (length-prev);
  1909. }
  1910. break ;
  1911. }
  1912. this.addCurvePosition(p *0.1,x1,y1,cx1,cy1,cx2,cy2,x2,y2,out,o,tangents || (i > 0 && space==0));
  1913. }
  1914. return out;
  1915. }
  1916. //TODO:coverage
  1917. __proto.addBeforePosition=function(p,temp,i,out,o){
  1918. var x1=temp[i],y1=temp[i+1],dx=temp[i+2]-x1,dy=temp[i+3]-y1,r=Math.atan2(dy,dx);
  1919. out[o]=x1+p *Math.cos(r);
  1920. out[o+1]=y1+p *Math.sin(r);
  1921. out[o+2]=r;
  1922. }
  1923. //TODO:coverage
  1924. __proto.addAfterPosition=function(p,temp,i,out,o){
  1925. var x1=temp[i+2],y1=temp[i+3],dx=x1-temp[i],dy=y1-temp[i+1],r=Math.atan2(dy,dx);
  1926. out[o]=x1+p *Math.cos(r);
  1927. out[o+1]=y1+p *Math.sin(r);
  1928. out[o+2]=r;
  1929. }
  1930. //TODO:coverage
  1931. __proto.addCurvePosition=function(p,x1,y1,cx1,cy1,cx2,cy2,x2,y2,out,o,tangents){
  1932. if (p==0)
  1933. p=0.0001;
  1934. var tt=p *p,ttt=tt *p,u=1-p,uu=u *u,uuu=uu *u;
  1935. var ut=u *p,ut3=ut *3,uut3=u *ut3,utt3=ut3 *p;
  1936. var x=x1 *uuu+cx1 *uut3+cx2 *utt3+x2 *ttt,y=y1 *uuu+cy1 *uut3+cy2 *utt3+y2 *ttt;
  1937. out[o]=x;
  1938. out[o+1]=y;
  1939. if (tangents){
  1940. out[o+2]=Math.atan2(y-(y1 *uu+cy1 *ut *2+cy2 *tt),x-(x1 *uu+cx1 *ut *2+cx2 *tt));
  1941. }
  1942. else {
  1943. out[o+2]=0;
  1944. }
  1945. }
  1946. PathConstraint.NONE=-1;
  1947. PathConstraint.BEFORE=-2;
  1948. PathConstraint.AFTER=-3;
  1949. __static(PathConstraint,
  1950. ['_tempMt',function(){return this._tempMt=new Matrix();}
  1951. ]);
  1952. return PathConstraint;
  1953. })()
  1954. /**
  1955. *@private
  1956. */
  1957. //class laya.ani.bone.Transform
  1958. var Transform=(function(){
  1959. function Transform(){
  1960. this.skX=0;
  1961. // 旋转?
  1962. this.skY=0;
  1963. // 不知道干什么的
  1964. this.scX=1;
  1965. // 缩放
  1966. this.scY=1;
  1967. this.x=0;
  1968. // 偏移
  1969. this.y=0;
  1970. this.skewX=0;
  1971. // skew
  1972. this.skewY=0;
  1973. this.mMatrix=null;
  1974. }
  1975. __class(Transform,'laya.ani.bone.Transform');
  1976. var __proto=Transform.prototype;
  1977. //TODO:coverage
  1978. __proto.initData=function(data){
  1979. if (data.x !=undefined){
  1980. this.x=data.x;
  1981. }
  1982. if (data.y !=undefined){
  1983. this.y=data.y;
  1984. }
  1985. if (data.skX !=undefined){
  1986. this.skX=data.skX;
  1987. }
  1988. if (data.skY !=undefined){
  1989. this.skY=data.skY;
  1990. }
  1991. if (data.scX !=undefined){
  1992. this.scX=data.scX;
  1993. }
  1994. if (data.scY !=undefined){
  1995. this.scY=data.scY;
  1996. }
  1997. }
  1998. //TODO:coverage
  1999. __proto.getMatrix=function(){
  2000. var tMatrix;
  2001. if (this.mMatrix){
  2002. tMatrix=this.mMatrix;
  2003. }else {
  2004. tMatrix=this.mMatrix=new Matrix();
  2005. }
  2006. tMatrix.identity();
  2007. tMatrix.scale(this.scX,this.scY);
  2008. if (this.skewX || this.skewY){
  2009. this.skew(tMatrix,this.skewX *Math.PI / 180,this.skewY *Math.PI / 180);
  2010. }
  2011. tMatrix.rotate(this.skX *Math.PI / 180);
  2012. tMatrix.translate(this.x,this.y);
  2013. return tMatrix;
  2014. }
  2015. //TODO:coverage
  2016. __proto.skew=function(m,x,y){
  2017. var sinX=Math.sin(y);
  2018. var cosX=Math.cos(y);
  2019. var sinY=Math.sin(x);
  2020. var cosY=Math.cos(x);
  2021. m.setTo(m.a *cosY-m.b *sinX,
  2022. m.a *sinY+m.b *cosX,
  2023. m.c *cosY-m.d *sinX,
  2024. m.c *sinY+m.d *cosX,
  2025. m.tx *cosY-m.ty *sinX,
  2026. m.tx *sinY+m.ty *cosX);
  2027. return m;
  2028. }
  2029. return Transform;
  2030. })()
  2031. /**
  2032. *@private
  2033. */
  2034. //class laya.ani.bone.DrawOrderData
  2035. var DrawOrderData=(function(){
  2036. function DrawOrderData(){
  2037. this.time=NaN;
  2038. this.drawOrder=[];
  2039. }
  2040. __class(DrawOrderData,'laya.ani.bone.DrawOrderData');
  2041. return DrawOrderData;
  2042. })()
  2043. /**
  2044. *@private
  2045. *...
  2046. *@author ww
  2047. */
  2048. //class laya.ani.math.BezierLerp
  2049. var BezierLerp=(function(){
  2050. function BezierLerp(){}
  2051. __class(BezierLerp,'laya.ani.math.BezierLerp');
  2052. BezierLerp.getBezierRate=function(t,px0,py0,px1,py1){
  2053. var key=BezierLerp._getBezierParamKey(px0,py0,px1,py1);
  2054. var vKey=key *100+t;
  2055. if (BezierLerp._bezierResultCache[vKey])return BezierLerp._bezierResultCache[vKey];
  2056. var points=BezierLerp._getBezierPoints(px0,py0,px1,py1,key);
  2057. var i=0,len=0;
  2058. len=points.length;
  2059. for (i=0;i < len;i+=2){
  2060. if (t <=points[i]){
  2061. BezierLerp._bezierResultCache[vKey]=points[i+1];
  2062. return points[i+1];
  2063. }
  2064. }
  2065. BezierLerp._bezierResultCache[vKey]=1;
  2066. return 1;
  2067. }
  2068. BezierLerp._getBezierParamKey=function(px0,py0,px1,py1){
  2069. return (((px0 *100+py0)*100+px1)*100+py1)*100;
  2070. }
  2071. BezierLerp._getBezierPoints=function(px0,py0,px1,py1,key){
  2072. if (BezierLerp._bezierPointsCache[key])return BezierLerp._bezierPointsCache[key];
  2073. var controlPoints;
  2074. controlPoints=[0,0,px0,py0,px1,py1,1,1];
  2075. var bz;
  2076. bz=new Bezier();
  2077. var points;
  2078. points=bz.getBezierPoints(controlPoints,100,3);
  2079. BezierLerp._bezierPointsCache[key]=points;
  2080. return points;
  2081. }
  2082. BezierLerp._bezierResultCache={};
  2083. BezierLerp._bezierPointsCache={};
  2084. return BezierLerp;
  2085. })()
  2086. /**
  2087. *@private
  2088. */
  2089. //class laya.ani.bone.Bone
  2090. var Bone=(function(){
  2091. function Bone(){
  2092. this.name=null;
  2093. this.root=null;
  2094. this.parentBone=null;
  2095. this.length=10;
  2096. this.transform=null;
  2097. this.inheritScale=true;
  2098. this.inheritRotation=true;
  2099. this.rotation=NaN;
  2100. this.resultRotation=NaN;
  2101. this.d=-1;
  2102. this._tempMatrix=null;
  2103. this._sprite=null;
  2104. this.resultTransform=new Transform();
  2105. this.resultMatrix=new Matrix();
  2106. this._children=[];
  2107. }
  2108. __class(Bone,'laya.ani.bone.Bone');
  2109. var __proto=Bone.prototype;
  2110. __proto.setTempMatrix=function(matrix){
  2111. this._tempMatrix=matrix;
  2112. var i=0,n=0;
  2113. var tBone;
  2114. for (i=0,n=this._children.length;i < n;i++){
  2115. tBone=this._children[i];
  2116. tBone.setTempMatrix(this._tempMatrix);
  2117. }
  2118. }
  2119. //TODO:coverage
  2120. __proto.update=function(pMatrix){
  2121. this.rotation=this.transform.skX;
  2122. var tResultMatrix;
  2123. if (pMatrix){
  2124. tResultMatrix=this.resultTransform.getMatrix();
  2125. Matrix.mul(tResultMatrix,pMatrix,this.resultMatrix);
  2126. this.resultRotation=this.rotation;
  2127. }
  2128. else {
  2129. this.resultRotation=this.rotation+this.parentBone.resultRotation;
  2130. if (this.parentBone){
  2131. if (this.inheritRotation && this.inheritScale){
  2132. tResultMatrix=this.resultTransform.getMatrix();
  2133. Matrix.mul(tResultMatrix,this.parentBone.resultMatrix,this.resultMatrix);
  2134. }
  2135. else {
  2136. var temp=0;
  2137. var parent=this.parentBone;
  2138. var tAngle=NaN;
  2139. var cos=NaN;
  2140. var sin=NaN;
  2141. var tParentMatrix=this.parentBone.resultMatrix;
  2142. tResultMatrix=this.resultTransform.getMatrix();
  2143. var worldX=tParentMatrix.a *tResultMatrix.tx+tParentMatrix.c *tResultMatrix.ty+tParentMatrix.tx;
  2144. var worldY=tParentMatrix.b *tResultMatrix.tx+tParentMatrix.d *tResultMatrix.ty+tParentMatrix.ty;
  2145. var tTestMatrix=new Matrix();
  2146. if (this.inheritRotation){
  2147. tAngle=Math.atan2(parent.resultMatrix.b,parent.resultMatrix.a);
  2148. cos=Math.cos(tAngle),sin=Math.sin(tAngle);
  2149. tTestMatrix.setTo(cos,sin,-sin,cos,0,0);
  2150. Matrix.mul(this._tempMatrix,tTestMatrix,Matrix.TEMP);
  2151. Matrix.TEMP.copyTo(tTestMatrix);
  2152. tResultMatrix=this.resultTransform.getMatrix();
  2153. Matrix.mul(tResultMatrix,tTestMatrix,this.resultMatrix);
  2154. if (this.resultTransform.scX *this.resultTransform.scY < 0){
  2155. this.resultMatrix.rotate(Math.PI*0.5);
  2156. }
  2157. this.resultMatrix.tx=worldX;
  2158. this.resultMatrix.ty=worldY;
  2159. }
  2160. else if (this.inheritScale){
  2161. tResultMatrix=this.resultTransform.getMatrix();
  2162. Matrix.TEMP.identity();
  2163. Matrix.TEMP.d=this.d;
  2164. Matrix.mul(tResultMatrix,Matrix.TEMP,this.resultMatrix);
  2165. this.resultMatrix.tx=worldX;
  2166. this.resultMatrix.ty=worldY;
  2167. }
  2168. else {
  2169. tResultMatrix=this.resultTransform.getMatrix();
  2170. Matrix.TEMP.identity();
  2171. Matrix.TEMP.d=this.d;
  2172. Matrix.mul(tResultMatrix,Matrix.TEMP,this.resultMatrix);
  2173. this.resultMatrix.tx=worldX;
  2174. this.resultMatrix.ty=worldY;
  2175. }
  2176. }
  2177. }
  2178. else {
  2179. tResultMatrix=this.resultTransform.getMatrix();
  2180. tResultMatrix.copyTo(this.resultMatrix);
  2181. }
  2182. };
  2183. var i=0,n=0;
  2184. var tBone;
  2185. for (i=0,n=this._children.length;i < n;i++){
  2186. tBone=this._children[i];
  2187. tBone.update();
  2188. }
  2189. }
  2190. //TODO:coverage
  2191. __proto.updateChild=function(){
  2192. var i=0,n=0;
  2193. var tBone;
  2194. for (i=0,n=this._children.length;i < n;i++){
  2195. tBone=this._children[i];
  2196. tBone.update();
  2197. }
  2198. }
  2199. //TODO:coverage
  2200. __proto.setRotation=function(rd){
  2201. if (this._sprite){
  2202. this._sprite.rotation=rd *180 / Math.PI;
  2203. }
  2204. }
  2205. //TODO:coverage
  2206. __proto.updateDraw=function(x,y){
  2207. if (!Bone.ShowBones || Bone.ShowBones[this.name]){
  2208. if (this._sprite){
  2209. this._sprite.x=x+this.resultMatrix.tx;
  2210. this._sprite.y=y+this.resultMatrix.ty;
  2211. }
  2212. else {
  2213. this._sprite=new Sprite();
  2214. this._sprite.graphics.drawCircle(0,0,5,"#ff0000");
  2215. this._sprite.graphics.drawLine(0,0,this.length,0,"#00ff00");
  2216. this._sprite.graphics.fillText(this.name,0,0,"20px Arial","#00ff00","center");
  2217. Laya.stage.addChild(this._sprite);
  2218. this._sprite.x=x+this.resultMatrix.tx;
  2219. this._sprite.y=y+this.resultMatrix.ty;
  2220. }
  2221. };
  2222. var i=0,n=0;
  2223. var tBone;
  2224. for (i=0,n=this._children.length;i < n;i++){
  2225. tBone=this._children[i];
  2226. tBone.updateDraw(x,y);
  2227. }
  2228. }
  2229. __proto.addChild=function(bone){
  2230. this._children.push(bone);
  2231. bone.parentBone=this;
  2232. }
  2233. //TODO:coverage
  2234. __proto.findBone=function(boneName){
  2235. if (this.name==boneName){
  2236. return this;
  2237. }
  2238. else {
  2239. var i=0,n=0;
  2240. var tBone;
  2241. var tResult;
  2242. for (i=0,n=this._children.length;i < n;i++){
  2243. tBone=this._children[i];
  2244. tResult=tBone.findBone(boneName);
  2245. if (tResult){
  2246. return tResult;
  2247. }
  2248. }
  2249. }
  2250. return null;
  2251. }
  2252. //TODO:coverage
  2253. __proto.localToWorld=function(local){
  2254. var localX=local[0];
  2255. var localY=local[1];
  2256. local[0]=localX *this.resultMatrix.a+localY *this.resultMatrix.c+this.resultMatrix.tx;
  2257. local[1]=localX *this.resultMatrix.b+localY *this.resultMatrix.d+this.resultMatrix.ty;
  2258. }
  2259. Bone.ShowBones={};
  2260. return Bone;
  2261. })()
  2262. /**
  2263. *@private
  2264. */
  2265. //class laya.ani.bone.EventData
  2266. var EventData=(function(){
  2267. function EventData(){
  2268. this.name=null;
  2269. this.intValue=0;
  2270. this.floatValue=NaN;
  2271. this.stringValue=null;
  2272. this.time=NaN;
  2273. }
  2274. __class(EventData,'laya.ani.bone.EventData');
  2275. return EventData;
  2276. })()
  2277. /**
  2278. *@private
  2279. */
  2280. //class laya.ani.bone.IkConstraintData
  2281. var IkConstraintData=(function(){
  2282. function IkConstraintData(){
  2283. this.name=null;
  2284. this.targetBoneName=null;
  2285. this.bendDirection=1;
  2286. this.mix=1;
  2287. this.isSpine=true;
  2288. this.targetBoneIndex=-1;
  2289. this.boneNames=[];
  2290. this.boneIndexs=[];
  2291. }
  2292. __class(IkConstraintData,'laya.ani.bone.IkConstraintData');
  2293. return IkConstraintData;
  2294. })()
  2295. /**
  2296. *<code>AnimationPlayer</code> 类用于动画播放器。
  2297. */
  2298. //class laya.ani.AnimationPlayer extends laya.events.EventDispatcher
  2299. var AnimationPlayer=(function(_super){
  2300. function AnimationPlayer(){
  2301. /**@private */
  2302. this._destroyed=false;
  2303. /**数据模板*/
  2304. this._templet=null;
  2305. /**当前精确时间,不包括重播时间*/
  2306. this._currentTime=NaN;
  2307. /**当前帧时间,不包括重播时间*/
  2308. this._currentFrameTime=NaN;
  2309. /**动画播放的起始时间位置*/
  2310. this._playStart=NaN;
  2311. /**动画播放的结束时间位置*/
  2312. this._playEnd=NaN;
  2313. /**动画播放一次的总时间*/
  2314. this._playDuration=NaN;
  2315. /**动画播放总时间*/
  2316. this._overallDuration=NaN;
  2317. /**是否在一次动画结束时停止。 设置这个标志后就不会再发送complete事件了*/
  2318. this._stopWhenCircleFinish=false;
  2319. /**已播放时间,包括重播时间*/
  2320. this._elapsedPlaybackTime=NaN;
  2321. /**播放时帧数*/
  2322. this._startUpdateLoopCount=NaN;
  2323. /**当前动画索引*/
  2324. this._currentAnimationClipIndex=0;
  2325. /**当前帧数*/
  2326. this._currentKeyframeIndex=0;
  2327. /**是否暂停*/
  2328. this._paused=false;
  2329. /**默认帧率,必须大于0*/
  2330. this._cacheFrameRate=0;
  2331. /**帧率间隔时间*/
  2332. this._cacheFrameRateInterval=NaN;
  2333. /**缓存播放速率*/
  2334. this._cachePlayRate=NaN;
  2335. /**是否缓存*/
  2336. this.isCache=true;
  2337. /**播放速率*/
  2338. this.playbackRate=1.0;
  2339. /**停止时是否归零*/
  2340. this.returnToZeroStopped=false;
  2341. AnimationPlayer.__super.call(this);
  2342. this._destroyed=false;
  2343. this._currentAnimationClipIndex=-1;
  2344. this._currentKeyframeIndex=-1;
  2345. this._currentTime=0.0;
  2346. this._overallDuration=Number.MAX_VALUE;
  2347. this._stopWhenCircleFinish=false;
  2348. this._elapsedPlaybackTime=0;
  2349. this._startUpdateLoopCount=-1;
  2350. this._cachePlayRate=1.0;
  2351. this.cacheFrameRate=60;
  2352. this.returnToZeroStopped=false;
  2353. }
  2354. __class(AnimationPlayer,'laya.ani.AnimationPlayer',_super);
  2355. var __proto=AnimationPlayer.prototype;
  2356. Laya.imps(__proto,{"laya.resource.IDestroy":true})
  2357. /**
  2358. *@private
  2359. */
  2360. __proto._onTempletLoadedComputeFullKeyframeIndices=function(cachePlayRate,cacheFrameRate,templet){
  2361. if (this._templet===templet && this._cachePlayRate===cachePlayRate && this._cacheFrameRate===cacheFrameRate)
  2362. this._computeFullKeyframeIndices();
  2363. }
  2364. /**
  2365. *@private
  2366. */
  2367. __proto._computeFullKeyframeIndices=function(){
  2368. return;
  2369. var templet=this._templet;
  2370. if (templet._fullFrames)
  2371. return;
  2372. var anifullFrames=this._templet._fullFrames=[];
  2373. var cacheFrameInterval=this._cacheFrameRateInterval *this._cachePlayRate;
  2374. for (var i=0,iNum=templet.getAnimationCount();i < iNum;i++){
  2375. var aniFullFrame=[];
  2376. if (!templet.getAnimation(i).nodes){
  2377. anifullFrames.push(aniFullFrame);
  2378. continue ;
  2379. }
  2380. for (var j=0,jNum=templet.getAnimation(i).nodes.length;j < jNum;j++){
  2381. var node=templet.getAnimation(i).nodes[j];
  2382. var frameCount=Math.round(node.playTime / cacheFrameInterval);
  2383. var nodeFullFrames=new Uint16Array(frameCount+1);
  2384. var stidx=-1;
  2385. var nodeframes=node.keyFrame;
  2386. for (var n=0,nNum=nodeframes.length;n < nNum;n++){
  2387. var keyFrame=nodeframes[n];
  2388. var pos=Math.round(keyFrame.startTime / cacheFrameInterval);
  2389. if (stidx < 0 && pos>0){
  2390. stidx=pos;
  2391. }
  2392. if (pos <=frameCount){
  2393. nodeFullFrames[pos]=n;
  2394. }
  2395. };
  2396. var cf=0;
  2397. for (n=stidx;n < frameCount;n++){
  2398. if (nodeFullFrames[n]==0){
  2399. nodeFullFrames[n]=cf;
  2400. }else {
  2401. cf=nodeFullFrames[n];
  2402. }
  2403. }
  2404. aniFullFrame.push(nodeFullFrames);
  2405. }
  2406. anifullFrames.push(aniFullFrame);
  2407. }
  2408. }
  2409. /**
  2410. *@private
  2411. */
  2412. __proto._onAnimationTempletLoaded=function(){
  2413. (this.destroyed)|| (this._calculatePlayDuration());
  2414. }
  2415. /**
  2416. *@private
  2417. */
  2418. __proto._calculatePlayDuration=function(){
  2419. if (this.state!==/*laya.ani.AnimationState.stopped*/0){
  2420. var oriDuration=this._templet.getAniDuration(this._currentAnimationClipIndex);
  2421. (this._playEnd===0)&& (this._playEnd=oriDuration);
  2422. if (this._playEnd > oriDuration)
  2423. this._playEnd=oriDuration;
  2424. this._playDuration=this._playEnd-this._playStart;
  2425. }
  2426. }
  2427. /**
  2428. *@private
  2429. */
  2430. __proto._setPlayParams=function(time,cacheFrameInterval){
  2431. this._currentTime=time;
  2432. this._currentKeyframeIndex=Math.floor((this.currentPlayTime)/ cacheFrameInterval+0.01);
  2433. this._currentFrameTime=this._currentKeyframeIndex *cacheFrameInterval;
  2434. }
  2435. /**
  2436. *动画停止了对应的参数。目前都是设置时间为最后
  2437. *@private
  2438. */
  2439. __proto._setPlayParamsWhenStop=function(currentAniClipPlayDuration,cacheFrameInterval){
  2440. this._currentTime=currentAniClipPlayDuration;
  2441. this._currentKeyframeIndex=Math.floor(currentAniClipPlayDuration / cacheFrameInterval+0.01);
  2442. this._currentFrameTime=this._currentKeyframeIndex *cacheFrameInterval;
  2443. this._currentAnimationClipIndex=-1;
  2444. }
  2445. /**
  2446. *@private
  2447. */
  2448. __proto._update=function(elapsedTime){
  2449. if (this._currentAnimationClipIndex===-1 || this._paused || !this._templet)
  2450. return;
  2451. var cacheFrameInterval=this._cacheFrameRateInterval *this._cachePlayRate;
  2452. var time=0;
  2453. (this._startUpdateLoopCount!==Stat.loopCount)&& (time=elapsedTime *this.playbackRate,this._elapsedPlaybackTime+=time);
  2454. var currentAniClipPlayDuration=this.playDuration;
  2455. if ((this._overallDuration!==0 && this._elapsedPlaybackTime >=this._overallDuration)|| (this._overallDuration===0 && this._elapsedPlaybackTime >=currentAniClipPlayDuration)){
  2456. this._setPlayParamsWhenStop(currentAniClipPlayDuration,cacheFrameInterval);
  2457. this.event(/*laya.events.Event.STOPPED*/"stopped");
  2458. return;
  2459. }
  2460. time+=this._currentTime;
  2461. if (currentAniClipPlayDuration > 0){
  2462. if (time >=currentAniClipPlayDuration){
  2463. if (this._stopWhenCircleFinish){
  2464. this._setPlayParamsWhenStop(currentAniClipPlayDuration,cacheFrameInterval);
  2465. this._stopWhenCircleFinish=false;
  2466. this.event(/*laya.events.Event.STOPPED*/"stopped");
  2467. return;
  2468. }else {
  2469. time=time % currentAniClipPlayDuration;
  2470. this._setPlayParams(time,cacheFrameInterval);
  2471. this.event(/*laya.events.Event.COMPLETE*/"complete");
  2472. return;
  2473. }
  2474. }else {
  2475. this._setPlayParams(time,cacheFrameInterval);
  2476. }
  2477. }else {
  2478. if (this._stopWhenCircleFinish){
  2479. this._setPlayParamsWhenStop(currentAniClipPlayDuration,cacheFrameInterval);
  2480. this._stopWhenCircleFinish=false;
  2481. this.event(/*laya.events.Event.STOPPED*/"stopped");
  2482. return;
  2483. }
  2484. this._currentTime=this._currentFrameTime=this._currentKeyframeIndex=0;
  2485. this.event(/*laya.events.Event.COMPLETE*/"complete");
  2486. }
  2487. }
  2488. /**
  2489. *@private
  2490. */
  2491. __proto._destroy=function(){
  2492. this.offAll();
  2493. this._templet=null;
  2494. this._destroyed=true;
  2495. }
  2496. /**
  2497. *播放动画。
  2498. *@param index 动画索引。
  2499. *@param playbackRate 播放速率。
  2500. *@param duration 播放时长(0为1次,Number.MAX_VALUE为循环播放)。
  2501. *@param playStart 播放的起始时间位置。
  2502. *@param playEnd 播放的结束时间位置。(0为动画一次循环的最长结束时间位置)。
  2503. */
  2504. __proto.play=function(index,playbackRate,overallDuration,playStart,playEnd){
  2505. (index===void 0)&& (index=0);
  2506. (playbackRate===void 0)&& (playbackRate=1.0);
  2507. (overallDuration===void 0)&& (overallDuration=2147483647);
  2508. (playStart===void 0)&& (playStart=0);
  2509. (playEnd===void 0)&& (playEnd=0);
  2510. if (!this._templet)
  2511. throw new Error("AnimationPlayer:templet must not be null,maybe you need to set url.");
  2512. if (overallDuration < 0 || playStart < 0 || playEnd < 0)
  2513. throw new Error("AnimationPlayer:overallDuration,playStart and playEnd must large than zero.");
  2514. if ((playEnd!==0)&& (playStart > playEnd))
  2515. throw new Error("AnimationPlayer:start must less than end.");
  2516. this._currentTime=0;
  2517. this._currentFrameTime=0;
  2518. this._elapsedPlaybackTime=0;
  2519. this.playbackRate=playbackRate;
  2520. this._overallDuration=overallDuration;
  2521. this._playStart=playStart;
  2522. this._playEnd=playEnd;
  2523. this._paused=false;
  2524. this._currentAnimationClipIndex=index;
  2525. this._currentKeyframeIndex=0;
  2526. this._startUpdateLoopCount=Stat.loopCount;
  2527. this.event(/*laya.events.Event.PLAYED*/"played");
  2528. this._calculatePlayDuration();
  2529. this._update(0);
  2530. }
  2531. /**
  2532. *播放动画。
  2533. *@param index 动画索引。
  2534. *@param playbackRate 播放速率。
  2535. *@param duration 播放时长(0为1次,Number.MAX_VALUE为循环播放)。
  2536. *@param playStartFrame 播放的原始起始帧率位置。
  2537. *@param playEndFrame 播放的原始结束帧率位置。(0为动画一次循环的最长结束时间位置)。
  2538. */
  2539. __proto.playByFrame=function(index,playbackRate,overallDuration,playStartFrame,playEndFrame,fpsIn3DBuilder){
  2540. (index===void 0)&& (index=0);
  2541. (playbackRate===void 0)&& (playbackRate=1.0);
  2542. (overallDuration===void 0)&& (overallDuration=2147483647);
  2543. (playStartFrame===void 0)&& (playStartFrame=0);
  2544. (playEndFrame===void 0)&& (playEndFrame=0);
  2545. (fpsIn3DBuilder===void 0)&& (fpsIn3DBuilder=30);
  2546. var interval=1000.0 / fpsIn3DBuilder;
  2547. this.play(index,playbackRate,overallDuration,playStartFrame *interval,playEndFrame *interval);
  2548. }
  2549. /**
  2550. *停止播放当前动画
  2551. *如果不是立即停止就等待动画播放完成后再停止
  2552. *@param immediate 是否立即停止
  2553. */
  2554. __proto.stop=function(immediate){
  2555. (immediate===void 0)&& (immediate=true);
  2556. if (immediate){
  2557. this._currentTime=this._currentFrameTime=this._currentKeyframeIndex=0;
  2558. this._currentAnimationClipIndex=-1;
  2559. this.event(/*laya.events.Event.STOPPED*/"stopped");
  2560. }else {
  2561. this._stopWhenCircleFinish=true;
  2562. }
  2563. }
  2564. /**
  2565. *@private
  2566. */
  2567. __proto.destroy=function(){}
  2568. /**
  2569. *动画播放的结束时间位置。
  2570. *@return 结束时间位置。
  2571. */
  2572. __getset(0,__proto,'playEnd',function(){
  2573. return this._playEnd;
  2574. });
  2575. /**
  2576. *设置动画数据模板,注意:修改此值会有计算开销。
  2577. *@param value 动画数据模板
  2578. */
  2579. /**
  2580. *获取动画数据模板
  2581. *@param value 动画数据模板
  2582. */
  2583. __getset(0,__proto,'templet',function(){
  2584. return this._templet;
  2585. },function(value){
  2586. if (!(this.state===/*laya.ani.AnimationState.stopped*/0))
  2587. this.stop(true);
  2588. if (this._templet!==value){
  2589. this._templet=value;
  2590. this._computeFullKeyframeIndices();
  2591. }
  2592. });
  2593. /**
  2594. *动画播放的起始时间位置。
  2595. *@return 起始时间位置。
  2596. */
  2597. __getset(0,__proto,'playStart',function(){
  2598. return this._playStart;
  2599. });
  2600. /**
  2601. *获取动画播放一次的总时间
  2602. *@return 动画播放一次的总时间
  2603. */
  2604. __getset(0,__proto,'playDuration',function(){
  2605. return this._playDuration;
  2606. });
  2607. /**
  2608. *获取当前播放状态
  2609. *@return 当前播放状态
  2610. */
  2611. __getset(0,__proto,'state',function(){
  2612. if (this._currentAnimationClipIndex===-1)
  2613. return /*laya.ani.AnimationState.stopped*/0;
  2614. if (this._paused)
  2615. return /*laya.ani.AnimationState.paused*/1;
  2616. return /*laya.ani.AnimationState.playing*/2;
  2617. });
  2618. /**
  2619. *获取当前帧数
  2620. *@return 当前帧数
  2621. */
  2622. __getset(0,__proto,'currentKeyframeIndex',function(){
  2623. return this._currentKeyframeIndex;
  2624. });
  2625. /**
  2626. *获取动画播放的总总时间
  2627. *@return 动画播放的总时间
  2628. */
  2629. __getset(0,__proto,'overallDuration',function(){
  2630. return this._overallDuration;
  2631. });
  2632. /**
  2633. *获取当前帧时间,不包括重播时间
  2634. *@return value 当前时间
  2635. */
  2636. __getset(0,__proto,'currentFrameTime',function(){
  2637. return this._currentFrameTime;
  2638. });
  2639. /**
  2640. *获取当前动画索引
  2641. *@return value 当前动画索引
  2642. */
  2643. __getset(0,__proto,'currentAnimationClipIndex',function(){
  2644. return this._currentAnimationClipIndex;
  2645. });
  2646. /**
  2647. *获取当前精确时间,不包括重播时间
  2648. *@return value 当前时间
  2649. */
  2650. __getset(0,__proto,'currentPlayTime',function(){
  2651. return this._currentTime+this._playStart;
  2652. });
  2653. /**
  2654. *设置缓存播放速率,默认值为1.0,注意:修改此值会有计算开销。*
  2655. *@return value 缓存播放速率。
  2656. */
  2657. /**
  2658. *获取缓存播放速率。*
  2659. *@return 缓存播放速率。
  2660. */
  2661. __getset(0,__proto,'cachePlayRate',function(){
  2662. return this._cachePlayRate;
  2663. },function(value){
  2664. if (this._cachePlayRate!==value){
  2665. this._cachePlayRate=value;
  2666. if (this._templet)
  2667. this._computeFullKeyframeIndices();
  2668. }
  2669. });
  2670. /**
  2671. *设置默认帧率,每秒60帧,注意:修改此值会有计算开销。*
  2672. *@return value 缓存帧率
  2673. */
  2674. /**
  2675. *获取默认帧率*
  2676. *@return value 默认帧率
  2677. */
  2678. __getset(0,__proto,'cacheFrameRate',function(){
  2679. return this._cacheFrameRate;
  2680. },function(value){
  2681. if (this._cacheFrameRate!==value){
  2682. this._cacheFrameRate=value;
  2683. this._cacheFrameRateInterval=1000.0 / this._cacheFrameRate;
  2684. if (this._templet)
  2685. this._computeFullKeyframeIndices();
  2686. }
  2687. });
  2688. /**
  2689. *设置当前播放位置
  2690. *@param value 当前时间
  2691. */
  2692. __getset(0,__proto,'currentTime',null,function(value){
  2693. if (this._currentAnimationClipIndex===-1 || !this._templet)
  2694. return;
  2695. if (value < this._playStart || value > this._playEnd)
  2696. throw new Error("AnimationPlayer:value must large than playStartTime,small than playEndTime.");
  2697. this._startUpdateLoopCount=Stat.loopCount;
  2698. var cacheFrameInterval=this._cacheFrameRateInterval *this._cachePlayRate;
  2699. this._currentTime=value;
  2700. this._currentKeyframeIndex=Math.floor(this.currentPlayTime / cacheFrameInterval);
  2701. this._currentFrameTime=this._currentKeyframeIndex *cacheFrameInterval;
  2702. });
  2703. /**
  2704. *设置是否暂停
  2705. *@param value 是否暂停
  2706. */
  2707. /**
  2708. *获取当前是否暂停
  2709. *@return 是否暂停
  2710. */
  2711. __getset(0,__proto,'paused',function(){
  2712. return this._paused;
  2713. },function(value){
  2714. this._paused=value;
  2715. value && this.event(/*laya.events.Event.PAUSED*/"paused");
  2716. });
  2717. /**
  2718. *获取缓存帧率间隔时间
  2719. *@return 缓存帧率间隔时间
  2720. */
  2721. __getset(0,__proto,'cacheFrameRateInterval',function(){
  2722. return this._cacheFrameRateInterval;
  2723. });
  2724. /**
  2725. *获取是否已销毁。
  2726. *@return 是否已销毁。
  2727. */
  2728. __getset(0,__proto,'destroyed',function(){
  2729. return this._destroyed;
  2730. });
  2731. return AnimationPlayer;
  2732. })(EventDispatcher)
  2733. /**
  2734. *@private
  2735. */
  2736. //class laya.ani.GraphicsAni extends laya.display.Graphics
  2737. var GraphicsAni=(function(_super){
  2738. function GraphicsAni(){
  2739. GraphicsAni.__super.call(this);;
  2740. }
  2741. __class(GraphicsAni,'laya.ani.GraphicsAni',_super);
  2742. var __proto=GraphicsAni.prototype;
  2743. //TODO:coverage
  2744. __proto.drawSkin=function(skinA,alpha){
  2745. this.drawTriangles(skinA.texture,0,0,skinA.vertices,skinA.uvs,skinA.indexes,skinA.transform||Matrix.EMPTY,alpha);
  2746. }
  2747. GraphicsAni.create=function(){
  2748. var rs=GraphicsAni._caches.pop();
  2749. return rs||new GraphicsAni();
  2750. }
  2751. GraphicsAni.recycle=function(graphics){
  2752. graphics.clear();
  2753. GraphicsAni._caches.push(graphics);
  2754. }
  2755. GraphicsAni._caches=[];
  2756. return GraphicsAni;
  2757. })(Graphics)
  2758. /**
  2759. *...
  2760. *@author ww
  2761. */
  2762. //class laya.ani.bone.canvasmesh.SkinMeshForGraphic extends laya.ani.bone.canvasmesh.MeshData
  2763. var SkinMeshForGraphic=(function(_super){
  2764. function SkinMeshForGraphic(){
  2765. /**
  2766. *矩阵
  2767. */
  2768. this.transform=null;
  2769. SkinMeshForGraphic.__super.call(this);
  2770. }
  2771. __class(SkinMeshForGraphic,'laya.ani.bone.canvasmesh.SkinMeshForGraphic',_super);
  2772. var __proto=SkinMeshForGraphic.prototype;
  2773. __proto.init2=function(texture,ps,verticles,uvs){
  2774. if (this.transform){
  2775. this.transform=null;
  2776. };
  2777. var _ps=ps || [0,1,3,3,1,2];
  2778. this.texture=texture;
  2779. this.indexes=new Uint16Array(_ps);
  2780. this.vertices=new Float32Array(verticles);
  2781. this.uvs=new Float32Array(uvs);
  2782. }
  2783. return SkinMeshForGraphic;
  2784. })(MeshData)
  2785. /**
  2786. *@private
  2787. *<code>AnimationTemplet</code> 类用于动画模板资源。
  2788. */
  2789. //class laya.ani.AnimationTemplet extends laya.resource.Resource
  2790. var AnimationTemplet=(function(_super){
  2791. function AnimationTemplet(){
  2792. /**@private */
  2793. //this._aniVersion=null;
  2794. /**@private */
  2795. this._aniMap={};
  2796. /**@private */
  2797. //this._publicExtData=null;
  2798. /**@private */
  2799. //this._useParent=false;
  2800. /**@private */
  2801. //this.unfixedCurrentFrameIndexes=null;
  2802. /**@private */
  2803. //this.unfixedCurrentTimes=null;
  2804. /**@private */
  2805. //this.unfixedKeyframes=null;
  2806. /**@private */
  2807. this.unfixedLastAniIndex=-1;
  2808. /**@private */
  2809. //this._aniClassName=null;
  2810. /**@private */
  2811. //this._animationDatasCache=null;
  2812. this._fullFrames=null;
  2813. /**@private */
  2814. this._boneCurKeyFrm=[];
  2815. AnimationTemplet.__super.call(this);
  2816. this._anis=new Array;
  2817. }
  2818. __class(AnimationTemplet,'laya.ani.AnimationTemplet',_super);
  2819. var __proto=AnimationTemplet.prototype;
  2820. /**
  2821. *@private
  2822. */
  2823. __proto.parse=function(data){
  2824. var reader=new Byte(data);
  2825. this._aniVersion=reader.readUTFString();
  2826. AnimationParser01.parse(this,reader);
  2827. }
  2828. /**
  2829. *@private
  2830. */
  2831. __proto._calculateKeyFrame=function(node,keyframeCount,keyframeDataCount){
  2832. var keyFrames=node.keyFrame;
  2833. keyFrames[keyframeCount]=keyFrames[0];
  2834. for (var i=0;i < keyframeCount;i++){
  2835. var keyFrame=keyFrames[i];
  2836. for (var j=0;j < keyframeDataCount;j++){
  2837. keyFrame.dData[j]=(keyFrame.duration===0)? 0 :(keyFrames[i+1].data[j]-keyFrame.data[j])/ keyFrame.duration;
  2838. keyFrame.nextData[j]=keyFrames[i+1].data[j];
  2839. }
  2840. }
  2841. keyFrames.length--;
  2842. }
  2843. //TODO:coverage
  2844. __proto._onAsynLoaded=function(data,propertyParams){
  2845. var reader=new Byte(data);
  2846. this._aniVersion=reader.readUTFString();
  2847. switch (this._aniVersion){
  2848. case "LAYAANIMATION:02":
  2849. AnimationParser02.parse(this,reader);
  2850. break ;
  2851. default :
  2852. AnimationParser01.parse(this,reader);
  2853. }
  2854. }
  2855. __proto.getAnimationCount=function(){
  2856. return this._anis.length;
  2857. }
  2858. __proto.getAnimation=function(aniIndex){
  2859. return this._anis[aniIndex];
  2860. }
  2861. __proto.getAniDuration=function(aniIndex){
  2862. return this._anis[aniIndex].playTime;
  2863. }
  2864. //TODO:coverage
  2865. __proto.getNodes=function(aniIndex){
  2866. return this._anis[aniIndex].nodes;
  2867. }
  2868. __proto.getNodeIndexWithName=function(aniIndex,name){
  2869. return this._anis[aniIndex].bone3DMap[name];
  2870. }
  2871. __proto.getNodeCount=function(aniIndex){
  2872. return this._anis[aniIndex].nodes.length;
  2873. }
  2874. __proto.getTotalkeyframesLength=function(aniIndex){
  2875. return this._anis[aniIndex].totalKeyframeDatasLength;
  2876. }
  2877. __proto.getPublicExtData=function(){
  2878. return this._publicExtData;
  2879. }
  2880. //TODO:coverage
  2881. __proto.getAnimationDataWithCache=function(key,cacheDatas,aniIndex,frameIndex){
  2882. var aniDatas=cacheDatas[aniIndex];
  2883. if (!aniDatas){
  2884. return null;
  2885. }else {
  2886. var keyDatas=aniDatas[key];
  2887. if (!keyDatas)
  2888. return null;
  2889. else {
  2890. return keyDatas[frameIndex];
  2891. }
  2892. }
  2893. }
  2894. //TODO:coverage
  2895. __proto.setAnimationDataWithCache=function(key,cacheDatas,aniIndex,frameIndex,data){
  2896. var aniDatas=(cacheDatas[aniIndex])|| (cacheDatas[aniIndex]={});
  2897. var aniDatasCache=(aniDatas[key])|| (aniDatas[key]=[]);
  2898. aniDatasCache[frameIndex]=data;
  2899. }
  2900. /**
  2901. *计算当前时间应该对应关键帧的哪一帧
  2902. *@param nodeframes 当前骨骼的关键帧数据
  2903. *@param nodeid 骨骼id,因为要使用和更新 _boneCurKeyFrm
  2904. *@param tm
  2905. *@return
  2906. *问题
  2907. *最后一帧有问题,例如倒数第二帧时间是0.033ms,则后两帧非常靠近,当实际给最后一帧的时候,根据帧数计算出的时间实际上落在倒数第二帧
  2908. *使用与AnimationPlayer一致的累积时间就行
  2909. */
  2910. __proto.getNodeKeyFrame=function(nodeframes,nodeid,tm){
  2911. var cid=this._boneCurKeyFrm[nodeid];
  2912. var frmNum=nodeframes.length;
  2913. if (cid==void 0 || cid>=frmNum){
  2914. cid=this._boneCurKeyFrm[nodeid]=0;
  2915. };
  2916. var kinfo=nodeframes[cid];
  2917. var curFrmTm=kinfo.startTime;
  2918. var dt=tm-curFrmTm;
  2919. if (dt==0 || (dt > 0 && kinfo.duration > dt)){
  2920. return cid;
  2921. };
  2922. var i=0;
  2923. if (dt > 0){
  2924. tm=tm+0.01;
  2925. for (i=cid+1;i < frmNum;i++){
  2926. kinfo=nodeframes[i];
  2927. if (kinfo.startTime <=tm && kinfo.startTime+kinfo.duration > tm){
  2928. this._boneCurKeyFrm[nodeid]=i;
  2929. return i;
  2930. }
  2931. }
  2932. return frmNum-1;
  2933. }else {
  2934. for (i=0;i < cid;i++){
  2935. kinfo=nodeframes[i];
  2936. if (kinfo.startTime <=tm && kinfo.startTime+kinfo.duration > tm){
  2937. this._boneCurKeyFrm[nodeid]=i;
  2938. return i;
  2939. }
  2940. }
  2941. return cid;
  2942. }
  2943. return 0;
  2944. }
  2945. /**
  2946. *
  2947. *@param aniIndex
  2948. *@param originalData
  2949. *@param nodesFrameIndices
  2950. *@param frameIndex
  2951. *@param playCurTime
  2952. */
  2953. __proto.getOriginalData=function(aniIndex,originalData,nodesFrameIndices,frameIndex,playCurTime){
  2954. var oneAni=this._anis[aniIndex];
  2955. var nodes=oneAni.nodes;
  2956. var curKFrm=this._boneCurKeyFrm;
  2957. if (curKFrm.length < nodes.length){
  2958. curKFrm.length=nodes.length;
  2959. };
  2960. var j=0;
  2961. for (var i=0,n=nodes.length,outOfs=0;i < n;i++){
  2962. var node=nodes[i];
  2963. var key;
  2964. var kfrm=node.keyFrame;
  2965. key=kfrm[ this.getNodeKeyFrame(kfrm,i,playCurTime)];
  2966. node.dataOffset=outOfs;
  2967. var dt=playCurTime-key.startTime;
  2968. var lerpType=node.lerpType;
  2969. if (lerpType){
  2970. switch (lerpType){
  2971. case 0:
  2972. case 1:
  2973. for (j=0;j < node.keyframeWidth;)
  2974. j+=node.interpolationMethod[j](node,j,originalData,outOfs+j,key.data,dt,key.dData,key.duration,key.nextData);
  2975. break ;
  2976. case 2:;
  2977. var interpolationData=key.interpolationData;
  2978. var interDataLen=interpolationData.length;
  2979. var dataIndex=0;
  2980. for (j=0;j < interDataLen;){
  2981. var type=interpolationData[j];
  2982. switch (type){
  2983. case 6:
  2984. j+=AnimationTemplet.interpolation[type](node,dataIndex,originalData,outOfs+dataIndex,key.data,dt,key.dData,key.duration,key.nextData,interpolationData,j+1);
  2985. break ;
  2986. case 7:
  2987. j+=AnimationTemplet.interpolation[type](node,dataIndex,originalData,outOfs+dataIndex,key.data,dt,key.dData,key.duration,key.nextData,interpolationData,j+1);
  2988. break ;
  2989. default :
  2990. j+=AnimationTemplet.interpolation[type](node,dataIndex,originalData,outOfs+dataIndex,key.data,dt,key.dData,key.duration,key.nextData);
  2991. }
  2992. dataIndex++;
  2993. }
  2994. break ;
  2995. }
  2996. }else {
  2997. for (j=0;j < node.keyframeWidth;)
  2998. j+=node.interpolationMethod[j](node,j,originalData,outOfs+j,key.data,dt,key.dData,key.duration,key.nextData);
  2999. }
  3000. outOfs+=node.keyframeWidth;
  3001. }
  3002. }
  3003. //TODO:coverage
  3004. __proto.getNodesCurrentFrameIndex=function(aniIndex,playCurTime){
  3005. var ani=this._anis[aniIndex];
  3006. var nodes=ani.nodes;
  3007. if (aniIndex!==this.unfixedLastAniIndex){
  3008. this.unfixedCurrentFrameIndexes=new Uint32Array(nodes.length);
  3009. this.unfixedCurrentTimes=new Float32Array(nodes.length);
  3010. this.unfixedLastAniIndex=aniIndex;
  3011. }
  3012. for (var i=0,n=nodes.length,outOfs=0;i < n;i++){
  3013. var node=nodes[i];
  3014. if (playCurTime < this.unfixedCurrentTimes[i])
  3015. this.unfixedCurrentFrameIndexes[i]=0;
  3016. this.unfixedCurrentTimes[i]=playCurTime;
  3017. while ((this.unfixedCurrentFrameIndexes[i] < node.keyFrame.length)){
  3018. if (node.keyFrame[this.unfixedCurrentFrameIndexes[i]].startTime > this.unfixedCurrentTimes[i])
  3019. break ;
  3020. this.unfixedCurrentFrameIndexes[i]++;
  3021. }
  3022. this.unfixedCurrentFrameIndexes[i]--;
  3023. }
  3024. return this.unfixedCurrentFrameIndexes;
  3025. }
  3026. //TODO:coverage
  3027. __proto.getOriginalDataUnfixedRate=function(aniIndex,originalData,playCurTime){
  3028. var oneAni=this._anis[aniIndex];
  3029. var nodes=oneAni.nodes;
  3030. if (aniIndex!==this.unfixedLastAniIndex){
  3031. this.unfixedCurrentFrameIndexes=new Uint32Array(nodes.length);
  3032. this.unfixedCurrentTimes=new Float32Array(nodes.length);
  3033. this.unfixedKeyframes=__newvec(nodes.length);
  3034. this.unfixedLastAniIndex=aniIndex;
  3035. };
  3036. var j=0;
  3037. for (var i=0,n=nodes.length,outOfs=0;i < n;i++){
  3038. var node=nodes[i];
  3039. if (playCurTime < this.unfixedCurrentTimes[i])
  3040. this.unfixedCurrentFrameIndexes[i]=0;
  3041. this.unfixedCurrentTimes[i]=playCurTime;
  3042. while (this.unfixedCurrentFrameIndexes[i] < node.keyFrame.length){
  3043. if (node.keyFrame[this.unfixedCurrentFrameIndexes[i]].startTime > this.unfixedCurrentTimes[i])
  3044. break ;
  3045. this.unfixedKeyframes[i]=node.keyFrame[this.unfixedCurrentFrameIndexes[i]];
  3046. this.unfixedCurrentFrameIndexes[i]++;
  3047. };
  3048. var key=this.unfixedKeyframes[i];
  3049. node.dataOffset=outOfs;
  3050. var dt=playCurTime-key.startTime;
  3051. var lerpType=node.lerpType;
  3052. if (lerpType){
  3053. switch (node.lerpType){
  3054. case 0:
  3055. case 1:
  3056. for (j=0;j < node.keyframeWidth;)
  3057. j+=node.interpolationMethod[j](node,j,originalData,outOfs+j,key.data,dt,key.dData,key.duration,key.nextData);
  3058. break ;
  3059. case 2:;
  3060. var interpolationData=key.interpolationData;
  3061. var interDataLen=interpolationData.length;
  3062. var dataIndex=0;
  3063. for (j=0;j < interDataLen;){
  3064. var type=interpolationData[j];
  3065. switch (type){
  3066. case 6:
  3067. j+=AnimationTemplet.interpolation[type](node,dataIndex,originalData,outOfs+dataIndex,key.data,dt,key.dData,key.duration,key.nextData,interpolationData,j+1);
  3068. break ;
  3069. case 7:
  3070. j+=AnimationTemplet.interpolation[type](node,dataIndex,originalData,outOfs+dataIndex,key.data,dt,key.dData,key.duration,key.nextData,interpolationData,j+1);
  3071. break ;
  3072. default :
  3073. j+=AnimationTemplet.interpolation[type](node,dataIndex,originalData,outOfs+dataIndex,key.data,dt,key.dData,key.duration,key.nextData);
  3074. }
  3075. dataIndex++;
  3076. }
  3077. break ;
  3078. }
  3079. }else {
  3080. for (j=0;j < node.keyframeWidth;)
  3081. j+=node.interpolationMethod[j](node,j,originalData,outOfs+j,key.data,dt,key.dData,key.duration,key.nextData);
  3082. }
  3083. outOfs+=node.keyframeWidth;
  3084. }
  3085. }
  3086. AnimationTemplet._LinearInterpolation_0=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData){
  3087. out[outOfs]=data[index]+dt *dData[index];
  3088. return 1;
  3089. }
  3090. AnimationTemplet._QuaternionInterpolation_1=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData){
  3091. var amount=duration===0 ? 0 :dt / duration;
  3092. MathUtil.slerpQuaternionArray(data,index,nextData,index,amount,out,outOfs);
  3093. return 4;
  3094. }
  3095. AnimationTemplet._AngleInterpolation_2=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData){
  3096. return 0;
  3097. }
  3098. AnimationTemplet._RadiansInterpolation_3=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData){
  3099. return 0;
  3100. }
  3101. AnimationTemplet._Matrix4x4Interpolation_4=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData){
  3102. for (var i=0;i < 16;i++,index++)
  3103. out[outOfs+i]=data[index]+dt *dData[index];
  3104. return 16;
  3105. }
  3106. AnimationTemplet._NoInterpolation_5=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData){
  3107. out[outOfs]=data[index];
  3108. return 1;
  3109. }
  3110. AnimationTemplet._BezierInterpolation_6=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData,offset){
  3111. (offset===void 0)&& (offset=0);
  3112. out[outOfs]=data[index]+(nextData[index]-data[index])*BezierLerp.getBezierRate(dt / duration,interData[offset],interData[offset+1],interData[offset+2],interData[offset+3]);
  3113. return 5;
  3114. }
  3115. AnimationTemplet._BezierInterpolation_7=function(bone,index,out,outOfs,data,dt,dData,duration,nextData,interData,offset){
  3116. (offset===void 0)&& (offset=0);
  3117. out[outOfs]=interData[offset+4]+interData[offset+5] *BezierLerp.getBezierRate((dt *0.001+interData[offset+6])/ interData[offset+7],interData[offset],interData[offset+1],interData[offset+2],interData[offset+3]);
  3118. return 9;
  3119. }
  3120. AnimationTemplet.interpolation=[AnimationTemplet._LinearInterpolation_0,AnimationTemplet._QuaternionInterpolation_1,AnimationTemplet._AngleInterpolation_2,AnimationTemplet._RadiansInterpolation_3,AnimationTemplet._Matrix4x4Interpolation_4,AnimationTemplet._NoInterpolation_5,AnimationTemplet._BezierInterpolation_6,AnimationTemplet._BezierInterpolation_7];
  3121. return AnimationTemplet;
  3122. })(Resource)
  3123. /**
  3124. *<p> <code>MovieClip</code> 用于播放经过工具处理后的 swf 动画。</p>
  3125. */
  3126. //class laya.ani.swf.MovieClip extends laya.display.Sprite
  3127. var MovieClip=(function(_super){
  3128. function MovieClip(parentMovieClip){
  3129. /**@private 数据起始位置。*/
  3130. this._start=0;
  3131. /**@private 当前位置。*/
  3132. this._Pos=0;
  3133. /**@private 数据。*/
  3134. this._data=null;
  3135. /**@private */
  3136. this._curIndex=0;
  3137. /**@private */
  3138. this._preIndex=0;
  3139. /**@private */
  3140. this._playIndex=0;
  3141. /**@private */
  3142. this._playing=false;
  3143. /**@private */
  3144. this._ended=true;
  3145. /**@private 总帧数。*/
  3146. this._count=0;
  3147. /**@private id_data起始位置表*/
  3148. this._ids=null;
  3149. /**@private */
  3150. this._loadedImage={};
  3151. /**@private id_实例表*/
  3152. this._idOfSprite=null;
  3153. /**@private 父mc*/
  3154. this._parentMovieClip=null;
  3155. /**@private 需要更新的movieClip表*/
  3156. this._movieClipList=null;
  3157. /**@private */
  3158. this._labels=null;
  3159. /**资源根目录。*/
  3160. this.basePath=null;
  3161. /**@private */
  3162. this._atlasPath=null;
  3163. /**@private */
  3164. this._url=null;
  3165. /**@private */
  3166. this._isRoot=false;
  3167. /**@private */
  3168. this._completeHandler=null;
  3169. /**@private */
  3170. this._endFrame=-1;
  3171. /**播放间隔(单位:毫秒)。*/
  3172. this.interval=30;
  3173. /**是否循环播放 */
  3174. this.loop=false;
  3175. MovieClip.__super.call(this);
  3176. this._ids={};
  3177. this._idOfSprite=[];
  3178. this._reset();
  3179. this._playing=false;
  3180. this._parentMovieClip=parentMovieClip;
  3181. if (!parentMovieClip){
  3182. this._movieClipList=[this];
  3183. this._isRoot=true;
  3184. this._setBitUp(/*laya.Const.DISPLAY*/0x10);
  3185. }else {
  3186. this._isRoot=false;
  3187. this._movieClipList=parentMovieClip._movieClipList;
  3188. this._movieClipList.push(this);
  3189. }
  3190. }
  3191. __class(MovieClip,'laya.ani.swf.MovieClip',_super);
  3192. var __proto=MovieClip.prototype;
  3193. /**
  3194. *<p>销毁此对象。以及销毁引用的Texture</p>
  3195. *@param destroyChild 是否同时销毁子节点,若值为true,则销毁子节点,否则不销毁子节点。
  3196. */
  3197. __proto.destroy=function(destroyChild){
  3198. (destroyChild===void 0)&& (destroyChild=true);
  3199. this._clear();
  3200. _super.prototype.destroy.call(this,destroyChild);
  3201. }
  3202. /**@private */
  3203. __proto._setDisplay=function(value){
  3204. _super.prototype._setDisplay.call(this,value);
  3205. if (this._isRoot){
  3206. this._$3__onDisplay(value);
  3207. }
  3208. }
  3209. /**@private */
  3210. __proto._$3__onDisplay=function(value){
  3211. if (value)this.timer.loop(this.interval,this,this.updates,null,true);
  3212. else this.timer.clear(this,this.updates);
  3213. }
  3214. //TODO:coverage
  3215. __proto.updates=function(){
  3216. if (this._parentMovieClip)return;
  3217. var i=0,len=0;
  3218. len=this._movieClipList.length;
  3219. for (i=0;i < len;i++){
  3220. this._movieClipList[i]&&this._movieClipList[i]._update();
  3221. }
  3222. }
  3223. /**
  3224. *增加一个标签到index帧上,播放到此index后会派发label事件
  3225. *@param label 标签名称
  3226. *@param index 索引位置
  3227. */
  3228. __proto.addLabel=function(label,index){
  3229. if (!this._labels)this._labels={};
  3230. this._labels[index]=label;
  3231. }
  3232. /**
  3233. *删除某个标签
  3234. *@param label 标签名字,如果label为空,则删除所有Label
  3235. */
  3236. __proto.removeLabel=function(label){
  3237. if (!label)this._labels=null;
  3238. else if (!this._labels){
  3239. for (var name in this._labels){
  3240. if (this._labels[name]===label){
  3241. delete this._labels[name];
  3242. break ;
  3243. }
  3244. }
  3245. }
  3246. }
  3247. //TODO:coverage
  3248. __proto._update=function(){
  3249. if (!this._data)return;
  3250. if (!this._playing)return;
  3251. this._playIndex++;
  3252. if (this._playIndex >=this._count){
  3253. if (!this.loop){
  3254. this._playIndex--;
  3255. this.stop();
  3256. return;
  3257. }
  3258. this._playIndex=0;
  3259. }
  3260. this._parseFrame(this._playIndex);
  3261. if (this._labels && this._labels[this._playIndex])this.event(/*laya.events.Event.LABEL*/"label",this._labels[this._playIndex]);
  3262. if (this._endFrame!=-1&&this._endFrame==this._playIndex){
  3263. this._endFrame=-1;
  3264. if (this._completeHandler !=null){
  3265. var handler=this._completeHandler;
  3266. this._completeHandler=null;
  3267. handler.run();
  3268. }
  3269. this.stop();
  3270. }
  3271. }
  3272. /**
  3273. *停止播放动画。
  3274. */
  3275. __proto.stop=function(){
  3276. this._playing=false;
  3277. }
  3278. /**
  3279. *跳到某帧并停止播放动画。
  3280. *@param frame 要跳到的帧
  3281. */
  3282. __proto.gotoAndStop=function(index){
  3283. this.index=index;
  3284. this.stop();
  3285. }
  3286. /**
  3287. *@private
  3288. *清理。
  3289. */
  3290. __proto._clear=function(){
  3291. this.stop();
  3292. this._idOfSprite.length=0;
  3293. if (!this._parentMovieClip){
  3294. this.timer.clear(this,this.updates);
  3295. var i=0,len=0;
  3296. len=this._movieClipList.length;
  3297. for (i=0;i < len;i++){
  3298. if (this._movieClipList[i] !=this)
  3299. this._movieClipList[i]._clear();
  3300. }
  3301. this._movieClipList.length=0;
  3302. }
  3303. if (this._atlasPath){
  3304. Loader.clearRes(this._atlasPath);
  3305. };
  3306. var key;
  3307. for (key in this._loadedImage){
  3308. if (this._loadedImage[key]){
  3309. Loader.clearRes(key);
  3310. this._loadedImage[key]=false;
  3311. }
  3312. }
  3313. this.removeChildren();
  3314. this.graphics=null;
  3315. this._parentMovieClip=null;
  3316. }
  3317. /**
  3318. *播放动画。
  3319. *@param index 帧索引。
  3320. */
  3321. __proto.play=function(index,loop){
  3322. (index===void 0)&& (index=0);
  3323. (loop===void 0)&& (loop=true);
  3324. this.loop=loop;
  3325. this._playing=true;
  3326. if (this._data)
  3327. this._displayFrame(index);
  3328. }
  3329. //TODO:coverage
  3330. __proto._displayFrame=function(frameIndex){
  3331. (frameIndex===void 0)&& (frameIndex=-1);
  3332. if (frameIndex !=-1){
  3333. if (this._curIndex > frameIndex)this._reset();
  3334. this._parseFrame(frameIndex);
  3335. }
  3336. }
  3337. /**@private */
  3338. __proto._reset=function(rm){
  3339. (rm===void 0)&& (rm=true);
  3340. if (rm && this._curIndex !=1)this.removeChildren();
  3341. this._preIndex=this._curIndex=-1;
  3342. this._Pos=this._start;
  3343. }
  3344. //TODO:coverage
  3345. __proto._parseFrame=function(frameIndex){
  3346. var curChild=this;
  3347. var mc,sp,key=0,type=0,tPos=0,ttype=0,ifAdd=false;
  3348. var _idOfSprite=this._idOfSprite,_data=this._data,eStr;
  3349. if (this._ended)this._reset();
  3350. _data.pos=this._Pos;
  3351. this._ended=false;
  3352. this._playIndex=frameIndex;
  3353. if (this._curIndex > frameIndex&&frameIndex<this._preIndex){
  3354. this._reset(true);
  3355. _data.pos=this._Pos;
  3356. }
  3357. while ((this._curIndex <=frameIndex)&& (!this._ended)){
  3358. type=_data.getUint16();
  3359. switch (type){
  3360. case 12:
  3361. key=_data.getUint16();
  3362. tPos=this._ids[_data.getUint16()];
  3363. this._Pos=_data.pos;
  3364. _data.pos=tPos;
  3365. if ((ttype=_data.getUint8())==0){
  3366. var pid=_data.getUint16();
  3367. sp=_idOfSprite[key]
  3368. if (!sp){
  3369. sp=_idOfSprite[key]=new Sprite();
  3370. var spp=new Sprite();
  3371. spp.loadImage(this.basePath+pid+".png");
  3372. this._loadedImage[this.basePath+pid+".png"]=true;
  3373. sp.addChild(spp);
  3374. spp.size(_data.getFloat32(),_data.getFloat32());
  3375. var mat=_data._getMatrix();
  3376. spp.transform=mat;
  3377. }
  3378. sp.alpha=1;
  3379. }else if (ttype==1){
  3380. mc=_idOfSprite[key]
  3381. if (!mc){
  3382. _idOfSprite[key]=mc=new MovieClip(this);
  3383. mc.interval=this.interval;
  3384. mc._ids=this._ids;
  3385. mc.basePath=this.basePath;
  3386. mc._setData(_data,tPos);
  3387. mc._initState();
  3388. mc.play(0);
  3389. }
  3390. mc.alpha=1;
  3391. }
  3392. _data.pos=this._Pos;
  3393. break ;
  3394. case 3:;
  3395. var node=_idOfSprite[ _data.getUint16()];
  3396. if (node){
  3397. this.addChild(node);
  3398. node.zOrder=_data.getUint16();
  3399. ifAdd=true;
  3400. }
  3401. break ;
  3402. case 4:
  3403. node=_idOfSprite[ _data.getUint16()];
  3404. node && node.removeSelf();
  3405. break ;
  3406. case 5:
  3407. _idOfSprite[_data.getUint16()][MovieClip._ValueList[_data.getUint16()]]=(_data.getFloat32());
  3408. break ;
  3409. case 6:
  3410. _idOfSprite[_data.getUint16()].visible=(_data.getUint8()> 0);
  3411. break ;
  3412. case 7:
  3413. sp=_idOfSprite[ _data.getUint16()];
  3414. var mt=sp.transform || Matrix.create();
  3415. mt.setTo(_data.getFloat32(),_data.getFloat32(),_data.getFloat32(),_data.getFloat32(),_data.getFloat32(),_data.getFloat32());
  3416. sp.transform=mt;
  3417. break ;
  3418. case 8:
  3419. _idOfSprite[_data.getUint16()].setPos(_data.getFloat32(),_data.getFloat32());
  3420. break ;
  3421. case 9:
  3422. _idOfSprite[_data.getUint16()].setSize(_data.getFloat32(),_data.getFloat32());
  3423. break ;
  3424. case 10:
  3425. _idOfSprite[ _data.getUint16()].alpha=_data.getFloat32();
  3426. break ;
  3427. case 11:
  3428. _idOfSprite[_data.getUint16()].setScale(_data.getFloat32(),_data.getFloat32());
  3429. break ;
  3430. case 98:
  3431. eStr=_data.getString();
  3432. this.event(eStr);
  3433. if (eStr=="stop")this.stop();
  3434. break ;
  3435. case 99:
  3436. this._curIndex=_data.getUint16();
  3437. ifAdd && this.updateZOrder();
  3438. break ;
  3439. case 100:
  3440. this._count=this._curIndex+1;
  3441. this._ended=true;
  3442. if (this._playing){
  3443. this.event(/*laya.events.Event.FRAME*/"enterframe");
  3444. this.event(/*laya.events.Event.END*/"end");
  3445. this.event(/*laya.events.Event.COMPLETE*/"complete");
  3446. }
  3447. this._reset(false);
  3448. break ;
  3449. }
  3450. }
  3451. if (this._playing&&!this._ended)this.event(/*laya.events.Event.FRAME*/"enterframe");
  3452. this._Pos=_data.pos;
  3453. }
  3454. //TODO:coverage
  3455. __proto._setData=function(data,start){
  3456. this._data=data;
  3457. this._start=start+3;
  3458. }
  3459. /**
  3460. *加载资源。
  3461. *@param url swf 资源地址。
  3462. *@param atlas 是否使用图集资源
  3463. *@param atlasPath 图集路径,默认使用与swf同名的图集
  3464. */
  3465. __proto.load=function(url,atlas,atlasPath){
  3466. (atlas===void 0)&& (atlas=false);
  3467. this._url=url;
  3468. if(atlas)this._atlasPath=atlasPath?atlasPath:url.split(".swf")[0]+".json";
  3469. this.stop();
  3470. this._clear();
  3471. this._movieClipList=[this];
  3472. var urls;
  3473. urls=[ {url:url,type:/*laya.net.Loader.BUFFER*/"arraybuffer" }];
  3474. if (this._atlasPath){
  3475. urls.push({url:this._atlasPath,type:/*laya.net.Loader.ATLAS*/"atlas" });
  3476. }
  3477. Laya.loader.load(urls,Handler.create(this,this._onLoaded));
  3478. }
  3479. /**@private */
  3480. __proto._onLoaded=function(){
  3481. var data;
  3482. data=Loader.getRes(this._url);
  3483. if (!data){
  3484. this.event(/*laya.events.Event.ERROR*/"error","file not find");
  3485. return;
  3486. }
  3487. if (this._atlasPath && !Loader.getAtlas(this._atlasPath)){
  3488. this.event(/*laya.events.Event.ERROR*/"error","Atlas not find");
  3489. return;
  3490. }
  3491. this.basePath=this._atlasPath?Loader.getAtlas(this._atlasPath).dir:this._url.split(".swf")[0]+"/image/";
  3492. this._initData(data);
  3493. }
  3494. //TODO:coverage
  3495. __proto._initState=function(){
  3496. this._reset();
  3497. this._ended=false;
  3498. var preState=this._playing;
  3499. this._playing=false;
  3500. this._curIndex=0;
  3501. while (!this._ended)this._parseFrame(++this._curIndex);
  3502. this._playing=preState;
  3503. }
  3504. //TODO:coverage
  3505. __proto._initData=function(data){
  3506. this._data=new Byte(data);
  3507. var i=0,len=this._data.getUint16();
  3508. for (i=0;i < len;i++)this._ids[this._data.getInt16()]=this._data.getInt32();
  3509. this.interval=1000 / this._data.getUint16();
  3510. this._setData(this._data,this._ids[32767]);
  3511. this._initState();
  3512. this.play(0);
  3513. this.event(/*laya.events.Event.LOADED*/"loaded");
  3514. if (!this._parentMovieClip)this.timer.loop(this.interval,this,this.updates,null,true);
  3515. }
  3516. /**
  3517. *从开始索引播放到结束索引,结束之后出发complete回调
  3518. *@param start 开始索引
  3519. *@param end 结束索引
  3520. *@param complete 结束回调
  3521. */
  3522. __proto.playTo=function(start,end,complete){
  3523. this._completeHandler=complete;
  3524. this._endFrame=end;
  3525. this.play(start,false);
  3526. }
  3527. /**当前播放索引。*/
  3528. __getset(0,__proto,'index',function(){
  3529. return this._playIndex;
  3530. },function(value){
  3531. this._playIndex=value;
  3532. if (this._data)
  3533. this._displayFrame(this._playIndex);
  3534. if (this._labels && this._labels[value])this.event(/*laya.events.Event.LABEL*/"label",this._labels[value]);
  3535. });
  3536. /**
  3537. *帧总数。
  3538. */
  3539. __getset(0,__proto,'count',function(){
  3540. return this._count;
  3541. });
  3542. /**
  3543. *是否在播放中
  3544. */
  3545. __getset(0,__proto,'playing',function(){
  3546. return this._playing;
  3547. });
  3548. /**
  3549. *资源地址。
  3550. */
  3551. __getset(0,__proto,'url',null,function(path){
  3552. this.load(path);
  3553. });
  3554. MovieClip._ValueList=["x","y","width","height","scaleX","scaleY","rotation","alpha"];
  3555. return MovieClip;
  3556. })(Sprite)
  3557. /**
  3558. *骨骼动画由<code>Templet</code>,<code>AnimationPlayer</code>,<code>Skeleton</code>三部分组成。
  3559. */
  3560. //class laya.ani.bone.Skeleton extends laya.display.Sprite
  3561. var Skeleton=(function(_super){
  3562. function Skeleton(templet,aniMode){
  3563. this._templet=null;
  3564. /**@private */
  3565. this._player=null;
  3566. /**@private */
  3567. this._curOriginalData=null;
  3568. //当前骨骼的偏移数据
  3569. this._boneMatrixArray=[];
  3570. //当前骨骼动画的最终结果数据
  3571. this._lastTime=0;
  3572. //上次的帧时间
  3573. this._currAniName=null;
  3574. this._currAniIndex=-1;
  3575. this._pause=true;
  3576. /**@private */
  3577. this._aniClipIndex=-1;
  3578. /**@private */
  3579. this._clipIndex=-1;
  3580. this._skinIndex=0;
  3581. this._skinName="default";
  3582. this._aniMode=0;
  3583. //当前动画自己的缓冲区
  3584. this._graphicsCache=null;
  3585. this._boneSlotDic=null;
  3586. this._bindBoneBoneSlotDic=null;
  3587. this._boneSlotArray=null;
  3588. this._index=-1;
  3589. this._total=-1;
  3590. this._indexControl=false;
  3591. //加载路径
  3592. this._aniPath=null;
  3593. this._texturePath=null;
  3594. this._complete=null;
  3595. this._loadAniMode=0;
  3596. this._yReverseMatrix=null;
  3597. this._ikArr=null;
  3598. this._tfArr=null;
  3599. this._pathDic=null;
  3600. this._rootBone=null;
  3601. /**@private */
  3602. this._boneList=null;
  3603. /**@private */
  3604. this._aniSectionDic=null;
  3605. // section 是每段数据(transform,slot,ik,path)的长度,这个是一个section的数据,表示每个clip的section数据
  3606. this._eventIndex=0;
  3607. this._drawOrderIndex=0;
  3608. this._drawOrder=null;
  3609. this._lastAniClipIndex=-1;
  3610. this._lastUpdateAniClipIndex=-1;
  3611. Skeleton.__super.call(this);
  3612. (aniMode===void 0)&& (aniMode=0);
  3613. if (templet)this.init(templet,aniMode);
  3614. }
  3615. __class(Skeleton,'laya.ani.bone.Skeleton',_super);
  3616. var __proto=Skeleton.prototype;
  3617. /**
  3618. *初始化动画
  3619. *@param templet 模板
  3620. *@param aniMode 动画模式
  3621. *<table>
  3622. *<tr><th>模式</th><th>描述</th></tr>
  3623. *<tr>
  3624. *<td>0</td> <td>使用模板缓冲的数据,模板缓冲的数据,不允许修改(内存开销小,计算开销小,不支持换装)</td>
  3625. *</tr>
  3626. *<tr>
  3627. *<td>1</td> <td>使用动画自己的缓冲区,每个动画都会有自己的缓冲区,相当耗费内存 (内存开销大,计算开销小,支持换装)</td>
  3628. *</tr>
  3629. *<tr>
  3630. *<td>2</td> <td>使用动态方式,去实时去画(内存开销小,计算开销大,支持换装,不建议使用)</td>
  3631. *</tr>
  3632. *</table>
  3633. */
  3634. __proto.init=function(templet,aniMode){
  3635. (aniMode===void 0)&& (aniMode=0);
  3636. var i=0,n=0;
  3637. if (aniMode==1){
  3638. this._graphicsCache=[];
  3639. for (i=0,n=templet.getAnimationCount();i < n;i++){
  3640. this._graphicsCache.push([]);
  3641. }
  3642. }
  3643. this._yReverseMatrix=templet.yReverseMatrix;
  3644. this._aniMode=aniMode;
  3645. this._templet=templet;
  3646. this._templet._addReference(1);
  3647. this._player=new AnimationPlayer();
  3648. this._player.cacheFrameRate=templet.rate;
  3649. this._player.templet=templet;
  3650. this._player.play();
  3651. this._parseSrcBoneMatrix();
  3652. this._boneList=templet.mBoneArr;
  3653. this._rootBone=templet.mRootBone;
  3654. this._aniSectionDic=templet.aniSectionDic;
  3655. if (templet.ikArr.length > 0){
  3656. this._ikArr=[];
  3657. for (i=0,n=templet.ikArr.length;i < n;i++){
  3658. this._ikArr.push(new IkConstraint(templet.ikArr[i],this._boneList));
  3659. }
  3660. }
  3661. if (templet.pathArr.length > 0){
  3662. var tPathData;
  3663. var tPathConstraint;
  3664. if (this._pathDic==null)this._pathDic={};
  3665. var tBoneSlot;
  3666. for (i=0,n=templet.pathArr.length;i < n;i++){
  3667. tPathData=templet.pathArr[i];
  3668. tPathConstraint=new PathConstraint(tPathData,this._boneList);
  3669. tBoneSlot=this._boneSlotDic[tPathData.name];
  3670. if (tBoneSlot){
  3671. tPathConstraint=new PathConstraint(tPathData,this._boneList);
  3672. tPathConstraint.target=tBoneSlot;
  3673. }
  3674. this._pathDic[tPathData.name]=tPathConstraint;
  3675. }
  3676. }
  3677. if (templet.tfArr.length > 0){
  3678. this._tfArr=[];
  3679. for (i=0,n=templet.tfArr.length;i < n;i++){
  3680. this._tfArr.push(new TfConstraint(templet.tfArr[i],this._boneList));
  3681. }
  3682. }
  3683. if (templet.skinDataArray.length > 0){
  3684. var tSkinData=this._templet.skinDataArray[this._skinIndex];
  3685. this._skinName=tSkinData.name;
  3686. }
  3687. this._player.on(/*laya.events.Event.PLAYED*/"played",this,this._onPlay);
  3688. this._player.on(/*laya.events.Event.STOPPED*/"stopped",this,this._onStop);
  3689. this._player.on(/*laya.events.Event.PAUSED*/"paused",this,this._onPause);
  3690. }
  3691. /**
  3692. *通过加载直接创建动画
  3693. *@param path 要加载的动画文件路径
  3694. *@param complete 加载完成的回调函数
  3695. *@param aniMode 与<code>Skeleton.init</code>的<code>aniMode</code>作用一致
  3696. */
  3697. __proto.load=function(path,complete,aniMode){
  3698. (aniMode===void 0)&& (aniMode=0);
  3699. this._aniPath=path;
  3700. this._complete=complete;
  3701. this._loadAniMode=aniMode;
  3702. Laya.loader.load([{url:path,type:/*laya.net.Loader.BUFFER*/"arraybuffer"}],Handler.create(this,this._onLoaded));
  3703. }
  3704. /**
  3705. *加载完成
  3706. */
  3707. __proto._onLoaded=function(){
  3708. var arraybuffer=Loader.getRes(this._aniPath);
  3709. if (arraybuffer==null)return;
  3710. if (Templet.TEMPLET_DICTIONARY==null){
  3711. Templet.TEMPLET_DICTIONARY={};
  3712. };
  3713. var tFactory;
  3714. tFactory=Templet.TEMPLET_DICTIONARY[this._aniPath];
  3715. if (tFactory){
  3716. if (tFactory.isParseFail){
  3717. this._parseFail();
  3718. }else {
  3719. if (tFactory.isParserComplete){
  3720. this._parseComplete();
  3721. }else {
  3722. tFactory.on(/*laya.events.Event.COMPLETE*/"complete",this,this._parseComplete);
  3723. tFactory.on(/*laya.events.Event.ERROR*/"error",this,this._parseFail);
  3724. }
  3725. }
  3726. }else {
  3727. tFactory=new Templet();
  3728. tFactory._setCreateURL(this._aniPath);
  3729. Templet.TEMPLET_DICTIONARY[this._aniPath]=tFactory;
  3730. tFactory.on(/*laya.events.Event.COMPLETE*/"complete",this,this._parseComplete);
  3731. tFactory.on(/*laya.events.Event.ERROR*/"error",this,this._parseFail);
  3732. tFactory.isParserComplete=false;
  3733. tFactory.parseData(null,arraybuffer);
  3734. }
  3735. }
  3736. /**
  3737. *解析完成
  3738. */
  3739. __proto._parseComplete=function(){
  3740. var tTemple=Templet.TEMPLET_DICTIONARY[this._aniPath];
  3741. if (tTemple){
  3742. this.init(tTemple,this._loadAniMode);
  3743. this.play(0,true);
  3744. }
  3745. this._complete && this._complete.runWith(this);
  3746. }
  3747. /**
  3748. *解析失败
  3749. */
  3750. __proto._parseFail=function(){
  3751. console.log("[Error]:"+this._aniPath+"解析失败");
  3752. }
  3753. /**
  3754. *传递PLAY事件
  3755. */
  3756. __proto._onPlay=function(){
  3757. this.event(/*laya.events.Event.PLAYED*/"played");
  3758. }
  3759. /**
  3760. *传递STOP事件
  3761. */
  3762. __proto._onStop=function(){
  3763. var tEventData;
  3764. var tEventAniArr=this._templet.eventAniArr;
  3765. var tEventArr=tEventAniArr[this._aniClipIndex];
  3766. if (tEventArr && this._eventIndex < tEventArr.length){
  3767. for (;this._eventIndex < tEventArr.length;this._eventIndex++){
  3768. tEventData=tEventArr[this._eventIndex];
  3769. if (tEventData.time >=this._player.playStart && tEventData.time <=this._player.playEnd){
  3770. this.event(/*laya.events.Event.LABEL*/"label",tEventData);
  3771. }
  3772. }
  3773. }
  3774. this._drawOrder=null;
  3775. this.event(/*laya.events.Event.STOPPED*/"stopped");
  3776. }
  3777. /**
  3778. *传递PAUSE事件
  3779. */
  3780. __proto._onPause=function(){
  3781. this.event(/*laya.events.Event.PAUSED*/"paused");
  3782. }
  3783. /**
  3784. *创建骨骼的矩阵,保存每次计算的最终结果
  3785. */
  3786. __proto._parseSrcBoneMatrix=function(){
  3787. var i=0,n=0;
  3788. n=this._templet.srcBoneMatrixArr.length;
  3789. for (i=0;i < n;i++){
  3790. this._boneMatrixArray.push(new Matrix());
  3791. }
  3792. if (this._aniMode==0){
  3793. this._boneSlotDic=this._templet.boneSlotDic;
  3794. this._bindBoneBoneSlotDic=this._templet.bindBoneBoneSlotDic;
  3795. this._boneSlotArray=this._templet.boneSlotArray;
  3796. }else {
  3797. if (this._boneSlotDic==null)this._boneSlotDic={};
  3798. if (this._bindBoneBoneSlotDic==null)this._bindBoneBoneSlotDic={};
  3799. if (this._boneSlotArray==null)this._boneSlotArray=[];
  3800. var tArr=this._templet.boneSlotArray;
  3801. var tBS;
  3802. var tBSArr;
  3803. for (i=0,n=tArr.length;i < n;i++){
  3804. tBS=tArr[i];
  3805. tBSArr=this._bindBoneBoneSlotDic[tBS.parent];
  3806. if (tBSArr==null){
  3807. this._bindBoneBoneSlotDic[tBS.parent]=tBSArr=[];
  3808. }
  3809. this._boneSlotDic[tBS.name]=tBS=tBS.copy();
  3810. tBSArr.push(tBS);
  3811. this._boneSlotArray.push(tBS);
  3812. }
  3813. }
  3814. }
  3815. __proto._emitMissedEvents=function(startTime,endTime,startIndex){
  3816. (startIndex===void 0)&& (startIndex=0);
  3817. var tEventAniArr=this._templet.eventAniArr;
  3818. var tEventArr=tEventAniArr[this._player.currentAnimationClipIndex];
  3819. if (tEventArr){
  3820. var i=0,len=0;
  3821. var tEventData;
  3822. len=tEventArr.length;
  3823. for (i=startIndex;i < len;i++){
  3824. tEventData=tEventArr[i];
  3825. if (tEventData.time >=this._player.playStart && tEventData.time <=this._player.playEnd){
  3826. this.event(/*laya.events.Event.LABEL*/"label",tEventData);
  3827. }
  3828. }
  3829. }
  3830. }
  3831. /**
  3832. *更新动画
  3833. *@param autoKey true为正常更新,false为index手动更新
  3834. */
  3835. __proto._update=function(autoKey){
  3836. (autoKey===void 0)&& (autoKey=true);
  3837. if (this._pause)return;
  3838. if (autoKey && this._indexControl){
  3839. return;
  3840. };
  3841. var tCurrTime=this.timer.currTimer;
  3842. var preIndex=this._player.currentKeyframeIndex;
  3843. var dTime=tCurrTime-this._lastTime;
  3844. if (autoKey){
  3845. this._player._update(dTime);
  3846. }else {
  3847. preIndex=-1;
  3848. }
  3849. this._lastTime=tCurrTime;
  3850. if (!this._player)return;
  3851. this._index=this._clipIndex=this._player.currentKeyframeIndex;
  3852. if (this._index < 0)return;
  3853. if (dTime > 0 && this._clipIndex==preIndex && this._lastUpdateAniClipIndex==this._aniClipIndex){
  3854. return;
  3855. }
  3856. this._lastUpdateAniClipIndex=this._aniClipIndex;
  3857. if (preIndex > this._clipIndex && this._eventIndex !=0){
  3858. this._emitMissedEvents(this._player.playStart,this._player.playEnd,this._eventIndex);
  3859. this._eventIndex=0;
  3860. };
  3861. var tEventArr=this._templet.eventAniArr[this._aniClipIndex];
  3862. if (tEventArr && this._eventIndex < tEventArr.length){
  3863. var tEventData=tEventArr[this._eventIndex];
  3864. if (tEventData.time >=this._player.playStart && tEventData.time <=this._player.playEnd){
  3865. if (this._player.currentPlayTime >=tEventData.time){
  3866. this.event(/*laya.events.Event.LABEL*/"label",tEventData);
  3867. this._eventIndex++;
  3868. }
  3869. }else {
  3870. this._eventIndex++;
  3871. }
  3872. };
  3873. var tGraphics;
  3874. if (this._aniMode==0){
  3875. tGraphics=this._templet.getGrahicsDataWithCache(this._aniClipIndex,this._clipIndex)||this._createGraphics();
  3876. if (tGraphics && this.graphics!=tGraphics){
  3877. this.graphics=tGraphics;
  3878. }
  3879. }else if (this._aniMode==1){
  3880. tGraphics=this._getGrahicsDataWithCache(this._aniClipIndex,this._clipIndex)|| this._createGraphics();
  3881. if (tGraphics && this.graphics!=tGraphics){
  3882. this.graphics=tGraphics;
  3883. }
  3884. }else{
  3885. this._createGraphics();
  3886. }
  3887. }
  3888. /**
  3889. *@private
  3890. *创建grahics图像. 并且保存到cache中
  3891. *@param _clipIndex 第几帧
  3892. */
  3893. __proto._createGraphics=function(_clipIndex){
  3894. (_clipIndex===void 0)&& (_clipIndex=-1);
  3895. if (_clipIndex==-1)_clipIndex=this._clipIndex;
  3896. var curTime=_clipIndex *this._player.cacheFrameRateInterval;
  3897. var tDrawOrderData;
  3898. var tDrawOrderAniArr=this._templet.drawOrderAniArr;
  3899. var tDrawOrderArr=tDrawOrderAniArr[this._aniClipIndex];
  3900. if (tDrawOrderArr && tDrawOrderArr.length > 0){
  3901. this._drawOrderIndex=0;
  3902. tDrawOrderData=tDrawOrderArr[this._drawOrderIndex];
  3903. while (curTime >=tDrawOrderData.time){
  3904. this._drawOrder=tDrawOrderData.drawOrder;
  3905. this._drawOrderIndex++;
  3906. if (this._drawOrderIndex >=tDrawOrderArr.length){
  3907. break ;
  3908. }
  3909. tDrawOrderData=tDrawOrderArr[this._drawOrderIndex];
  3910. }
  3911. }
  3912. if (this._aniMode==0 || this._aniMode==1){
  3913. this.graphics=GraphicsAni.create();
  3914. }else {
  3915. if ((this.graphics instanceof laya.ani.GraphicsAni )){
  3916. this.graphics.clear();
  3917. }else {
  3918. this.graphics=GraphicsAni.create();
  3919. }
  3920. };
  3921. var tGraphics=this.graphics;
  3922. var bones=this._templet.getNodes(this._aniClipIndex);
  3923. var stopped=this._player.state==0;
  3924. this._templet.getOriginalData(this._aniClipIndex,this._curOriginalData,null,_clipIndex,stopped?(curTime+this._player.cacheFrameRateInterval):curTime);
  3925. var tSectionArr=this._aniSectionDic[this._aniClipIndex];
  3926. var tParentMatrix;
  3927. var tStartIndex=0;
  3928. var i=0,j=0,k=0,n=0;
  3929. var tDBBoneSlot;
  3930. var tDBBoneSlotArr;
  3931. var tParentTransform;
  3932. var tSrcBone;
  3933. var boneCount=this._templet.srcBoneMatrixArr.length;
  3934. var origDt=this._curOriginalData;
  3935. for (i=0,n=tSectionArr[0];i < boneCount;i++){
  3936. tSrcBone=this._boneList[i];
  3937. var resultTrans=tSrcBone.resultTransform;
  3938. tParentTransform=this._templet.srcBoneMatrixArr[i];
  3939. resultTrans.scX=tParentTransform.scX *origDt[tStartIndex++];
  3940. resultTrans.skX=tParentTransform.skX+origDt[tStartIndex++];
  3941. resultTrans.skY=tParentTransform.skY+origDt[tStartIndex++];
  3942. resultTrans.scY=tParentTransform.scY *origDt[tStartIndex++];
  3943. resultTrans.x=tParentTransform.x+origDt[tStartIndex++];
  3944. resultTrans.y=tParentTransform.y+origDt[tStartIndex++];
  3945. if (this._templet.tMatrixDataLen===8){
  3946. resultTrans.skewX=tParentTransform.skewX+origDt[tStartIndex++];
  3947. resultTrans.skewY=tParentTransform.skewY+origDt[tStartIndex++];
  3948. }
  3949. };
  3950. var tSlotDic={};
  3951. var tSlotAlphaDic={};
  3952. var tBoneData;
  3953. for (n+=tSectionArr[1];i < n;i++){
  3954. tBoneData=bones[i];
  3955. tSlotDic[tBoneData.name]=origDt[tStartIndex++];
  3956. tSlotAlphaDic[tBoneData.name]=origDt[tStartIndex++];
  3957. tStartIndex+=4;
  3958. };
  3959. var tBendDirectionDic={};
  3960. var tMixDic={};
  3961. for (n+=tSectionArr[2];i < n;i++){
  3962. tBoneData=bones[i];
  3963. tBendDirectionDic[tBoneData.name]=origDt[tStartIndex++];
  3964. tMixDic[tBoneData.name]=origDt[tStartIndex++];
  3965. tStartIndex+=4;
  3966. }
  3967. if (this._pathDic){
  3968. var tPathConstraint;
  3969. for (n+=tSectionArr[3];i < n;i++){
  3970. tBoneData=bones[i];
  3971. tPathConstraint=this._pathDic[tBoneData.name];
  3972. if (tPathConstraint){
  3973. var tByte=new Byte(tBoneData.extenData);
  3974. switch (tByte.getByte()){
  3975. case 1:
  3976. tPathConstraint.position=origDt[tStartIndex++];
  3977. break ;
  3978. case 2:
  3979. tPathConstraint.spacing=origDt[tStartIndex++];
  3980. break ;
  3981. case 3:
  3982. tPathConstraint.rotateMix=origDt[tStartIndex++];
  3983. tPathConstraint.translateMix=origDt[tStartIndex++];
  3984. break ;
  3985. }
  3986. }
  3987. }
  3988. }
  3989. this._rootBone.update(this._yReverseMatrix || Matrix.TEMP.identity());
  3990. if (this._ikArr){
  3991. var tIkConstraint;
  3992. for (i=0,n=this._ikArr.length;i < n;i++){
  3993. tIkConstraint=this._ikArr[i];
  3994. if (tBendDirectionDic.hasOwnProperty(tIkConstraint.name)){
  3995. tIkConstraint.bendDirection=tBendDirectionDic[tIkConstraint.name];
  3996. }
  3997. if (tMixDic.hasOwnProperty(tIkConstraint.name)){
  3998. tIkConstraint.mix=tMixDic[tIkConstraint.name]
  3999. }
  4000. tIkConstraint.apply();
  4001. }
  4002. }
  4003. if (this._pathDic){
  4004. for (var tPathStr in this._pathDic){
  4005. tPathConstraint=this._pathDic[tPathStr];
  4006. tPathConstraint.apply(this._boneList,tGraphics);
  4007. }
  4008. }
  4009. if (this._tfArr){
  4010. var tTfConstraint;
  4011. for (i=0,k=this._tfArr.length;i < k;i++){
  4012. tTfConstraint=this._tfArr[i];
  4013. tTfConstraint.apply();
  4014. }
  4015. }
  4016. for (i=0,k=this._boneList.length;i < k;i++){
  4017. tSrcBone=this._boneList[i];
  4018. tDBBoneSlotArr=this._bindBoneBoneSlotDic[tSrcBone.name];
  4019. tSrcBone.resultMatrix.copyTo(this._boneMatrixArray[i]);
  4020. if (tDBBoneSlotArr){
  4021. for (j=0,n=tDBBoneSlotArr.length;j < n;j++){
  4022. tDBBoneSlot=tDBBoneSlotArr[j];
  4023. if (tDBBoneSlot){
  4024. tDBBoneSlot.setParentMatrix(tSrcBone.resultMatrix);
  4025. }
  4026. }
  4027. }
  4028. };
  4029. var tDeformDic={};
  4030. var tDeformAniArr=this._templet.deformAniArr;
  4031. var tDeformAniData;
  4032. var tDeformSlotData;
  4033. var tDeformSlotDisplayData;
  4034. if (tDeformAniArr && tDeformAniArr.length > 0){
  4035. if (this._lastAniClipIndex !=this._aniClipIndex){
  4036. this._lastAniClipIndex=this._aniClipIndex;
  4037. for (i=0,n=this._boneSlotArray.length;i < n;i++){
  4038. tDBBoneSlot=this._boneSlotArray[i];
  4039. tDBBoneSlot.deformData=null;
  4040. }
  4041. };
  4042. var tSkinDeformAni=tDeformAniArr[this._aniClipIndex];
  4043. tDeformAniData=(tSkinDeformAni["default"]);
  4044. this._setDeform(tDeformAniData,tDeformDic,this._boneSlotArray,curTime);
  4045. var tSkin;
  4046. for (tSkin in tSkinDeformAni){
  4047. if (tSkin !="default" && tSkin !=this._skinName){
  4048. tDeformAniData=tSkinDeformAni [tSkin];
  4049. this._setDeform(tDeformAniData,tDeformDic,this._boneSlotArray,curTime);
  4050. }
  4051. }
  4052. tDeformAniData=(tSkinDeformAni[this._skinName]);
  4053. this._setDeform(tDeformAniData,tDeformDic,this._boneSlotArray,curTime);
  4054. };
  4055. var tSlotData2;
  4056. var tSlotData3;
  4057. var tObject;
  4058. if (this._drawOrder){
  4059. for (i=0,n=this._drawOrder.length;i < n;i++){
  4060. tDBBoneSlot=this._boneSlotArray[this._drawOrder[i]];
  4061. tSlotData2=tSlotDic[tDBBoneSlot.name];
  4062. tSlotData3=tSlotAlphaDic[tDBBoneSlot.name];
  4063. if (!isNaN(tSlotData3)){}
  4064. if (!isNaN(tSlotData2)&& tSlotData2 !=-2){
  4065. if (this._templet.attachmentNames){
  4066. tDBBoneSlot.showDisplayByName(this._templet.attachmentNames[tSlotData2]);
  4067. }else {
  4068. tDBBoneSlot.showDisplayByIndex(tSlotData2);
  4069. }
  4070. }
  4071. if (tDeformDic[this._drawOrder[i]]){
  4072. tObject=tDeformDic[this._drawOrder[i]];
  4073. if (tDBBoneSlot.currDisplayData && tObject[tDBBoneSlot.currDisplayData.attachmentName]){
  4074. tDBBoneSlot.deformData=tObject[tDBBoneSlot.currDisplayData.attachmentName];
  4075. }else {
  4076. tDBBoneSlot.deformData=null;
  4077. }
  4078. }else {
  4079. tDBBoneSlot.deformData=null;
  4080. }
  4081. if (!isNaN(tSlotData3)){
  4082. tDBBoneSlot.draw(tGraphics,this._boneMatrixArray,this._aniMode==2,tSlotData3);
  4083. }else {
  4084. tDBBoneSlot.draw(tGraphics,this._boneMatrixArray,this._aniMode==2);
  4085. }
  4086. if (!isNaN(tSlotData3)){}
  4087. }
  4088. }else {
  4089. for (i=0,n=this._boneSlotArray.length;i < n;i++){
  4090. tDBBoneSlot=this._boneSlotArray[i];
  4091. tSlotData2=tSlotDic[tDBBoneSlot.name];
  4092. tSlotData3=tSlotAlphaDic[tDBBoneSlot.name];
  4093. if (!isNaN(tSlotData3)){}
  4094. if (!isNaN(tSlotData2)&& tSlotData2 !=-2){
  4095. if (this._templet.attachmentNames){
  4096. tDBBoneSlot.showDisplayByName(this._templet.attachmentNames[tSlotData2]);
  4097. }else {
  4098. tDBBoneSlot.showDisplayByIndex(tSlotData2);
  4099. }
  4100. }
  4101. if (tDeformDic[i]){
  4102. tObject=tDeformDic[i];
  4103. if (tDBBoneSlot.currDisplayData && tObject[tDBBoneSlot.currDisplayData.attachmentName]){
  4104. tDBBoneSlot.deformData=tObject[tDBBoneSlot.currDisplayData.attachmentName];
  4105. }else {
  4106. tDBBoneSlot.deformData=null;
  4107. }
  4108. }else {
  4109. tDBBoneSlot.deformData=null;
  4110. }
  4111. if (!isNaN(tSlotData3)){
  4112. tDBBoneSlot.draw(tGraphics,this._boneMatrixArray,this._aniMode==2,tSlotData3);
  4113. }else {
  4114. tDBBoneSlot.draw(tGraphics,this._boneMatrixArray,this._aniMode==2);
  4115. }
  4116. if (!isNaN(tSlotData3)){}
  4117. }
  4118. }
  4119. if (this._aniMode==0){
  4120. this._templet.setGrahicsDataWithCache(this._aniClipIndex,_clipIndex,tGraphics);
  4121. this._checkIsAllParsed(this._aniClipIndex);
  4122. }else if (this._aniMode==1){
  4123. this._setGrahicsDataWithCache(this._aniClipIndex,_clipIndex,tGraphics);
  4124. }
  4125. return tGraphics;
  4126. }
  4127. __proto._checkIsAllParsed=function(_aniClipIndex){
  4128. var i=0,len=0;
  4129. len=Math.floor(0.01+this._templet.getAniDuration(_aniClipIndex)/ 1000 *this._player.cacheFrameRate);
  4130. for (i=0;i < len;i++){
  4131. if (!this._templet.getGrahicsDataWithCache(_aniClipIndex,i))return;
  4132. }
  4133. if (!this._templet.getGrahicsDataWithCache(_aniClipIndex,len)){
  4134. this._createGraphics(len);
  4135. return;
  4136. }
  4137. this._templet.deleteAniData(_aniClipIndex);
  4138. }
  4139. /**
  4140. *设置deform数据
  4141. *@param tDeformAniData
  4142. *@param tDeformDic
  4143. *@param _boneSlotArray
  4144. *@param curTime
  4145. */
  4146. __proto._setDeform=function(tDeformAniData,tDeformDic,_boneSlotArray,curTime){
  4147. if (!tDeformAniData)return;
  4148. var tDeformSlotData;
  4149. var tDeformSlotDisplayData;
  4150. var tDBBoneSlot;
  4151. var i=0,n=0,j=0;
  4152. if (tDeformAniData){
  4153. for (i=0,n=tDeformAniData.deformSlotDataList.length;i < n;i++){
  4154. tDeformSlotData=tDeformAniData.deformSlotDataList[i];
  4155. for (j=0;j < tDeformSlotData.deformSlotDisplayList.length;j++){
  4156. tDeformSlotDisplayData=tDeformSlotData.deformSlotDisplayList[j];
  4157. tDBBoneSlot=_boneSlotArray[tDeformSlotDisplayData.slotIndex];
  4158. tDeformSlotDisplayData.apply(curTime,tDBBoneSlot);
  4159. if (!tDeformDic[tDeformSlotDisplayData.slotIndex]){
  4160. tDeformDic[tDeformSlotDisplayData.slotIndex]={};
  4161. }
  4162. tDeformDic[tDeformSlotDisplayData.slotIndex][tDeformSlotDisplayData.attachment]=tDeformSlotDisplayData.deformData;
  4163. }
  4164. }
  4165. }
  4166. }
  4167. /**
  4168. *得到当前动画的数量
  4169. *@return 当前动画的数量
  4170. */
  4171. __proto.getAnimNum=function(){
  4172. return this._templet.getAnimationCount();
  4173. }
  4174. /**
  4175. *得到指定动画的名字
  4176. *@param index 动画的索引
  4177. */
  4178. __proto.getAniNameByIndex=function(index){
  4179. return this._templet.getAniNameByIndex(index);
  4180. }
  4181. /**
  4182. *通过名字得到插槽的引用
  4183. *@param name 动画的名字
  4184. *@return 插槽的引用
  4185. */
  4186. __proto.getSlotByName=function(name){
  4187. return this._boneSlotDic[name];
  4188. }
  4189. /**
  4190. *通过名字显示一套皮肤
  4191. *@param name 皮肤的名字
  4192. *@param freshSlotIndex 是否将插槽纹理重置到初始化状态
  4193. */
  4194. __proto.showSkinByName=function(name,freshSlotIndex){
  4195. (freshSlotIndex===void 0)&& (freshSlotIndex=true);
  4196. this.showSkinByIndex(this._templet.getSkinIndexByName(name),freshSlotIndex);
  4197. }
  4198. /**
  4199. *通过索引显示一套皮肤
  4200. *@param skinIndex 皮肤索引
  4201. *@param freshSlotIndex 是否将插槽纹理重置到初始化状态
  4202. */
  4203. __proto.showSkinByIndex=function(skinIndex,freshSlotIndex){
  4204. (freshSlotIndex===void 0)&& (freshSlotIndex=true);
  4205. for (var i=0;i < this._boneSlotArray.length;i++){
  4206. (this._boneSlotArray [i]).showSlotData(null,freshSlotIndex);
  4207. }
  4208. if (this._templet.showSkinByIndex(this._boneSlotDic,skinIndex,freshSlotIndex)){
  4209. var tSkinData=this._templet.skinDataArray[skinIndex];
  4210. this._skinIndex=skinIndex;
  4211. this._skinName=tSkinData.name;
  4212. }
  4213. this._clearCache();
  4214. }
  4215. /**
  4216. *设置某插槽的皮肤
  4217. *@param slotName 插槽名称
  4218. *@param index 插糟皮肤的索引
  4219. */
  4220. __proto.showSlotSkinByIndex=function(slotName,index){
  4221. if (this._aniMode==0)return;
  4222. var tBoneSlot=this.getSlotByName(slotName);
  4223. if (tBoneSlot){
  4224. tBoneSlot.showDisplayByIndex(index);
  4225. }
  4226. this._clearCache();
  4227. }
  4228. /**
  4229. *设置某插槽的皮肤
  4230. *@param slotName 插槽名称
  4231. *@param name 皮肤名称
  4232. */
  4233. __proto.showSlotSkinByName=function(slotName,name){
  4234. if (this._aniMode==0)return;
  4235. var tBoneSlot=this.getSlotByName(slotName);
  4236. if (tBoneSlot){
  4237. tBoneSlot.showDisplayByName(name);
  4238. }
  4239. this._clearCache();
  4240. }
  4241. /**
  4242. *替换插槽贴图名
  4243. *@param slotName 插槽名称
  4244. *@param oldName 要替换的贴图名
  4245. *@param newName 替换后的贴图名
  4246. */
  4247. __proto.replaceSlotSkinName=function(slotName,oldName,newName){
  4248. if (this._aniMode==0)return;
  4249. var tBoneSlot=this.getSlotByName(slotName);
  4250. if (tBoneSlot){
  4251. tBoneSlot.replaceDisplayByName(oldName,newName);
  4252. }
  4253. this._clearCache();
  4254. }
  4255. /**
  4256. *替换插槽的贴图索引
  4257. *@param slotName 插槽名称
  4258. *@param oldIndex 要替换的索引
  4259. *@param newIndex 替换后的索引
  4260. */
  4261. __proto.replaceSlotSkinByIndex=function(slotName,oldIndex,newIndex){
  4262. if (this._aniMode==0)return;
  4263. var tBoneSlot=this.getSlotByName(slotName);
  4264. if (tBoneSlot){
  4265. tBoneSlot.replaceDisplayByIndex(oldIndex,newIndex);
  4266. }
  4267. this._clearCache();
  4268. }
  4269. /**
  4270. *设置自定义皮肤
  4271. *@param name 插糟的名字
  4272. *@param texture 自定义的纹理
  4273. */
  4274. __proto.setSlotSkin=function(slotName,texture){
  4275. if (this._aniMode==0)return;
  4276. var tBoneSlot=this.getSlotByName(slotName);
  4277. if (tBoneSlot){
  4278. tBoneSlot.replaceSkin(texture);
  4279. }
  4280. this._clearCache();
  4281. }
  4282. /**
  4283. *换装的时候,需要清一下缓冲区
  4284. */
  4285. __proto._clearCache=function(){
  4286. if (this._aniMode==1){
  4287. for (var i=0,n=this._graphicsCache.length;i < n;i++){
  4288. for (var j=0,len=this._graphicsCache[i].length;j < len;j++){
  4289. var gp=this._graphicsCache[i][j];
  4290. if (gp && gp !=this.graphics){
  4291. GraphicsAni.recycle(gp);
  4292. }
  4293. }
  4294. this._graphicsCache[i].length=0;
  4295. }
  4296. }
  4297. }
  4298. /**
  4299. *播放动画
  4300. *
  4301. *@param nameOrIndex 动画名字或者索引
  4302. *@param loop 是否循环播放
  4303. *@param force false,如果要播的动画跟上一个相同就不生效,true,强制生效
  4304. *@param start 起始时间
  4305. *@param end 结束时间
  4306. *@param freshSkin 是否刷新皮肤数据
  4307. */
  4308. __proto.play=function(nameOrIndex,loop,force,start,end,freshSkin){
  4309. (force===void 0)&& (force=true);
  4310. (start===void 0)&& (start=0);
  4311. (end===void 0)&& (end=0);
  4312. (freshSkin===void 0)&& (freshSkin=true);
  4313. this._indexControl=false;
  4314. var index=-1;
  4315. var duration=NaN;
  4316. if (loop){
  4317. duration=2147483647;
  4318. }else {
  4319. duration=0;
  4320. }
  4321. if ((typeof nameOrIndex=='string')){
  4322. for (var i=0,n=this._templet.getAnimationCount();i < n;i++){
  4323. var animation=this._templet.getAnimation(i);
  4324. if (animation && nameOrIndex==animation.name){
  4325. index=i;
  4326. break ;
  4327. }
  4328. }
  4329. }else {
  4330. index=nameOrIndex;
  4331. }
  4332. if (index >-1 && index < this.getAnimNum()){
  4333. this._aniClipIndex=index;
  4334. if (force || this._pause || this._currAniIndex !=index){
  4335. this._currAniIndex=index;
  4336. this._curOriginalData=new Float32Array(this._templet.getTotalkeyframesLength(index));
  4337. this._drawOrder=null;
  4338. this._eventIndex=0;
  4339. this._player.play(index,this._player.playbackRate,duration,start,end);
  4340. if (freshSkin)
  4341. this._templet.showSkinByIndex(this._boneSlotDic,this._skinIndex);
  4342. if (this._pause){
  4343. this._pause=false;
  4344. this._lastTime=Browser.now();
  4345. this.timer.frameLoop(1,this,this._update,null,true);
  4346. }
  4347. this._update();
  4348. }
  4349. }
  4350. }
  4351. /**
  4352. *停止动画
  4353. */
  4354. __proto.stop=function(){
  4355. if (!this._pause){
  4356. this._pause=true;
  4357. if (this._player){
  4358. this._player.stop(true);
  4359. }
  4360. this.timer.clear(this,this._update);
  4361. }
  4362. }
  4363. /**
  4364. *设置动画播放速率
  4365. *@param value 1为标准速率
  4366. */
  4367. __proto.playbackRate=function(value){
  4368. if (this._player){
  4369. this._player.playbackRate=value;
  4370. }
  4371. }
  4372. /**
  4373. *暂停动画的播放
  4374. */
  4375. __proto.paused=function(){
  4376. if (!this._pause){
  4377. this._pause=true;
  4378. if (this._player){
  4379. this._player.paused=true;
  4380. }
  4381. this.timer.clear(this,this._update);
  4382. }
  4383. }
  4384. /**
  4385. *恢复动画的播放
  4386. */
  4387. __proto.resume=function(){
  4388. this._indexControl=false;
  4389. if (this._pause){
  4390. this._pause=false;
  4391. if (this._player){
  4392. this._player.paused=false;
  4393. }
  4394. this._lastTime=Browser.now();
  4395. this.timer.frameLoop(1,this,this._update,null,true);
  4396. }
  4397. }
  4398. /**
  4399. *@private
  4400. *得到缓冲数据
  4401. *@param aniIndex
  4402. *@param frameIndex
  4403. *@return
  4404. */
  4405. __proto._getGrahicsDataWithCache=function(aniIndex,frameIndex){
  4406. return this._graphicsCache[aniIndex][frameIndex];
  4407. }
  4408. /**
  4409. *@private
  4410. *保存缓冲grahpics
  4411. *@param aniIndex
  4412. *@param frameIndex
  4413. *@param graphics
  4414. */
  4415. __proto._setGrahicsDataWithCache=function(aniIndex,frameIndex,graphics){
  4416. this._graphicsCache[aniIndex][frameIndex]=graphics;
  4417. }
  4418. /**
  4419. *销毁当前动画
  4420. */
  4421. __proto.destroy=function(destroyChild){
  4422. (destroyChild===void 0)&& (destroyChild=true);
  4423. _super.prototype.destroy.call(this,destroyChild);
  4424. this._templet._removeReference(1);
  4425. this._templet=null;
  4426. if (this._player)this._player.offAll();
  4427. this._player=null;
  4428. this._curOriginalData=null;
  4429. this._boneMatrixArray.length=0;
  4430. this._lastTime=0;
  4431. this.timer.clear(this,this._update);
  4432. }
  4433. /**
  4434. *设置动画路径
  4435. */
  4436. /**
  4437. *得到资源的URL
  4438. */
  4439. __getset(0,__proto,'url',function(){
  4440. return this._aniPath;
  4441. },function(path){
  4442. this.load(path);
  4443. });
  4444. /**
  4445. *@private
  4446. *设置帧索引
  4447. */
  4448. /**
  4449. *@private
  4450. *得到帧索引
  4451. */
  4452. __getset(0,__proto,'index',function(){
  4453. return this._index;
  4454. },function(value){
  4455. if (this.player){
  4456. this._index=value;
  4457. this._player.currentTime=this._index *1000 / this._player.cacheFrameRate;
  4458. this._indexControl=true;
  4459. this._update(false);
  4460. }
  4461. });
  4462. /**
  4463. *得到总帧数据
  4464. */
  4465. __getset(0,__proto,'total',function(){
  4466. if (this._templet && this._player){
  4467. this._total=Math.floor(this._templet.getAniDuration(this._player.currentAnimationClipIndex)/ 1000 *this._player.cacheFrameRate);
  4468. }else {
  4469. this._total=-1;
  4470. }
  4471. return this._total;
  4472. });
  4473. /**
  4474. *得到动画模板的引用
  4475. *@return templet.
  4476. */
  4477. __getset(0,__proto,'templet',function(){
  4478. return this._templet;
  4479. });
  4480. /**
  4481. *得到播放器的引用
  4482. */
  4483. __getset(0,__proto,'player',function(){
  4484. return this._player;
  4485. });
  4486. Skeleton.useSimpleMeshInCanvas=false;
  4487. return Skeleton;
  4488. })(Sprite)
  4489. /**
  4490. *动画模板类
  4491. */
  4492. //class laya.ani.bone.Templet extends laya.ani.AnimationTemplet
  4493. var Templet=(function(_super){
  4494. function Templet(){
  4495. this._mainTexture=null;
  4496. this._textureJson=null;
  4497. this._graphicsCache=[];
  4498. /**存放原始骨骼信息 */
  4499. this.srcBoneMatrixArr=[];
  4500. /**IK数据 */
  4501. this.ikArr=[];
  4502. /**transform数据 */
  4503. this.tfArr=[];
  4504. /**path数据 */
  4505. this.pathArr=[];
  4506. /**存放插槽数据的字典 */
  4507. this.boneSlotDic={};
  4508. /**绑定插槽数据的字典 */
  4509. this.bindBoneBoneSlotDic={};
  4510. /**存放插糟数据的数组 */
  4511. this.boneSlotArray=[];
  4512. /**皮肤数据 */
  4513. this.skinDataArray=[];
  4514. /**皮肤的字典数据 */
  4515. this.skinDic={};
  4516. /**存放纹理数据 */
  4517. this.subTextureDic={};
  4518. /**是否解析失败 */
  4519. this.isParseFail=false;
  4520. /**反转矩阵,有些骨骼动画要反转才能显示 */
  4521. this.yReverseMatrix=null;
  4522. /**渲染顺序动画数据 */
  4523. this.drawOrderAniArr=[];
  4524. /**事件动画数据 */
  4525. this.eventAniArr=[];
  4526. /**@private 索引对应的名称 */
  4527. this.attachmentNames=null;
  4528. /**顶点动画数据 */
  4529. this.deformAniArr=[];
  4530. this._isDestroyed=false;
  4531. this._rate=30;
  4532. this.isParserComplete=false;
  4533. this.aniSectionDic={};
  4534. this._skBufferUrl=null;
  4535. this._textureDic={};
  4536. this._loadList=null;
  4537. this._path=null;
  4538. this._relativeUrl=null;
  4539. /**@private */
  4540. this.tMatrixDataLen=0;
  4541. this.mRootBone=null;
  4542. Templet.__super.call(this);
  4543. this.skinSlotDisplayDataArr=[];
  4544. this.mBoneArr=[];
  4545. }
  4546. __class(Templet,'laya.ani.bone.Templet',_super);
  4547. var __proto=Templet.prototype;
  4548. __proto.loadAni=function(url){
  4549. this._skBufferUrl=url;
  4550. Laya.loader.load(url,Handler.create(this,this.onComplete),null,/*laya.net.Loader.BUFFER*/"arraybuffer");
  4551. }
  4552. __proto.onComplete=function(content){
  4553. if (this._isDestroyed){
  4554. this.destroy();
  4555. return;
  4556. };
  4557. var tSkBuffer=Loader.getRes(this._skBufferUrl);
  4558. if (!tSkBuffer){
  4559. this.event(/*laya.events.Event.ERROR*/"error","load failed:"+this._skBufferUrl);
  4560. return;
  4561. }
  4562. this._path=this._skBufferUrl.slice(0,this._skBufferUrl.lastIndexOf("/"))+"/";
  4563. this.parseData(null,tSkBuffer);
  4564. }
  4565. /**
  4566. *解析骨骼动画数据
  4567. *@param texture 骨骼动画用到的纹理
  4568. *@param skeletonData 骨骼动画信息及纹理分块信息
  4569. *@param playbackRate 缓冲的帧率数据(会根据帧率去分帧)
  4570. */
  4571. __proto.parseData=function(texture,skeletonData,playbackRate){
  4572. (playbackRate===void 0)&& (playbackRate=30);
  4573. if (!this._path){
  4574. var s1=(this._relativeUrl || this.url);
  4575. if (s1){
  4576. var p1=s1.lastIndexOf('/');
  4577. if (p1 > 0){
  4578. this._path=s1.slice(0,p1)+"/";
  4579. }else {
  4580. this._path='';
  4581. }
  4582. }
  4583. }
  4584. this._mainTexture=texture;
  4585. this._rate=playbackRate;
  4586. this.parse(skeletonData);
  4587. }
  4588. /**
  4589. *创建动画
  4590. *0,使用模板缓冲的数据,模板缓冲的数据,不允许修改 (内存开销小,计算开销小,不支持换装)
  4591. *1,使用动画自己的缓冲区,每个动画都会有自己的缓冲区,相当耗费内存 (内存开销大,计算开销小,支持换装)
  4592. *2,使用动态方式,去实时去画 (内存开销小,计算开销大,支持换装,不建议使用)
  4593. *@param aniMode 0 动画模式,0:不支持换装,1,2支持换装
  4594. *@return
  4595. */
  4596. __proto.buildArmature=function(aniMode){
  4597. (aniMode===void 0)&& (aniMode=0);
  4598. return new Skeleton(this,aniMode);
  4599. }
  4600. /**
  4601. *@private
  4602. *解析动画
  4603. *@param data 解析的二进制数据
  4604. *@param playbackRate 帧率
  4605. */
  4606. __proto.parse=function(data){
  4607. _super.prototype.parse.call(this,data);
  4608. this.event(/*laya.events.Event.LOADED*/"loaded",this);
  4609. if (this._aniVersion !=Templet.LAYA_ANIMATION_VISION){
  4610. console.log("[Error] 版本不一致,请使用IDE版本配套的重新导出"+this._aniVersion+"->"+Templet.LAYA_ANIMATION_VISION);
  4611. }
  4612. if (this._mainTexture){
  4613. this._parsePublicExtData();
  4614. }else {
  4615. this._parseTexturePath();
  4616. }
  4617. }
  4618. //}
  4619. __proto._parseTexturePath=function(){
  4620. if (this._isDestroyed){
  4621. this.destroy();
  4622. return;
  4623. };
  4624. var i=0;
  4625. this._loadList=[];
  4626. var tByte=new Byte(this.getPublicExtData());
  4627. var tX=0,tY=0,tWidth=0,tHeight=0;
  4628. var tFrameX=0,tFrameY=0,tFrameWidth=0,tFrameHeight=0;
  4629. var tTempleData=0;
  4630. var tTextureLen=tByte.getInt32();
  4631. var tTextureName=tByte.readUTFString();
  4632. var tTextureNameArr=tTextureName.split("\n");
  4633. var tTexture;
  4634. var tSrcTexturePath;
  4635. for (i=0;i < tTextureLen;i++){
  4636. tSrcTexturePath=this._path+tTextureNameArr[i *2];
  4637. tTextureName=tTextureNameArr[i *2+1];
  4638. tX=tByte.getFloat32();
  4639. tY=tByte.getFloat32();
  4640. tWidth=tByte.getFloat32();
  4641. tHeight=tByte.getFloat32();
  4642. tTempleData=tByte.getFloat32();
  4643. tFrameX=isNaN(tTempleData)? 0 :tTempleData;
  4644. tTempleData=tByte.getFloat32();
  4645. tFrameY=isNaN(tTempleData)? 0 :tTempleData;
  4646. tTempleData=tByte.getFloat32();
  4647. tFrameWidth=isNaN(tTempleData)? tWidth :tTempleData;
  4648. tTempleData=tByte.getFloat32();
  4649. tFrameHeight=isNaN(tTempleData)? tHeight :tTempleData;
  4650. if (this._loadList.indexOf(tSrcTexturePath)==-1){
  4651. this._loadList.push(tSrcTexturePath);
  4652. }
  4653. }
  4654. Laya.loader.load(this._loadList,Handler.create(this,this._textureComplete));
  4655. }
  4656. /**
  4657. *纹理加载完成
  4658. */
  4659. __proto._textureComplete=function(){
  4660. var tTexture;
  4661. var tTextureName;
  4662. for (var i=0,n=this._loadList.length;i < n;i++){
  4663. tTextureName=this._loadList[i];
  4664. tTexture=this._textureDic[tTextureName]=Loader.getRes(tTextureName);
  4665. }
  4666. this._parsePublicExtData();
  4667. }
  4668. /**
  4669. *解析自定义数据
  4670. */
  4671. __proto._parsePublicExtData=function(){
  4672. var i=0,j=0,k=0,l=0,n=0;
  4673. for (i=0,n=this.getAnimationCount();i < n;i++){
  4674. this._graphicsCache.push([]);
  4675. };
  4676. var isSpine=false;
  4677. isSpine=this._aniClassName !="Dragon";
  4678. var tByte=new Byte(this.getPublicExtData());
  4679. var tX=0,tY=0,tWidth=0,tHeight=0;
  4680. var tFrameX=0,tFrameY=0,tFrameWidth=0,tFrameHeight=0;
  4681. var tTempleData=0;
  4682. var tTextureLen=tByte.getInt32();
  4683. var tTextureName=tByte.readUTFString();
  4684. var tTextureNameArr=tTextureName.split("\n");
  4685. var tTexture;
  4686. var tSrcTexturePath;
  4687. for (i=0;i < tTextureLen;i++){
  4688. tTexture=this._mainTexture;
  4689. tSrcTexturePath=this._path+tTextureNameArr[i *2];
  4690. tTextureName=tTextureNameArr[i *2+1];
  4691. if (this._mainTexture==null){
  4692. tTexture=this._textureDic[tSrcTexturePath];
  4693. }
  4694. if (!tTexture){
  4695. this.event(/*laya.events.Event.ERROR*/"error",this);
  4696. this.isParseFail=true;
  4697. return;
  4698. }
  4699. tX=tByte.getFloat32();
  4700. tY=tByte.getFloat32();
  4701. tWidth=tByte.getFloat32();
  4702. tHeight=tByte.getFloat32();
  4703. tTempleData=tByte.getFloat32();
  4704. tFrameX=isNaN(tTempleData)? 0 :tTempleData;
  4705. tTempleData=tByte.getFloat32();
  4706. tFrameY=isNaN(tTempleData)? 0 :tTempleData;
  4707. tTempleData=tByte.getFloat32();
  4708. tFrameWidth=isNaN(tTempleData)? tWidth :tTempleData;
  4709. tTempleData=tByte.getFloat32();
  4710. tFrameHeight=isNaN(tTempleData)? tHeight :tTempleData;
  4711. this.subTextureDic[tTextureName]=Texture.create(tTexture,tX,tY,tWidth,tHeight,-tFrameX,-tFrameY,tFrameWidth,tFrameHeight);
  4712. }
  4713. this._mainTexture=tTexture;
  4714. var tAniCount=tByte.getUint16();
  4715. var tSectionArr;
  4716. for (i=0;i < tAniCount;i++){
  4717. tSectionArr=[];
  4718. tSectionArr.push(tByte.getUint16());
  4719. tSectionArr.push(tByte.getUint16());
  4720. tSectionArr.push(tByte.getUint16());
  4721. tSectionArr.push(tByte.getUint16());
  4722. this.aniSectionDic[i]=tSectionArr;
  4723. };
  4724. var tBone;
  4725. var tParentBone;
  4726. var tName;
  4727. var tParentName;
  4728. var tBoneLen=tByte.getInt16();
  4729. var tBoneDic={};
  4730. var tRootBone;
  4731. for (i=0;i < tBoneLen;i++){
  4732. tBone=new Bone();
  4733. if (i==0){
  4734. tRootBone=tBone;
  4735. }else {
  4736. tBone.root=tRootBone;
  4737. }
  4738. tBone.d=isSpine?-1:1;
  4739. tName=tByte.readUTFString();
  4740. tParentName=tByte.readUTFString();
  4741. tBone.length=tByte.getFloat32();
  4742. if (tByte.getByte()==1){
  4743. tBone.inheritRotation=false;
  4744. }
  4745. if (tByte.getByte()==1){
  4746. tBone.inheritScale=false;
  4747. }
  4748. tBone.name=tName;
  4749. if (tParentName){
  4750. tParentBone=tBoneDic[tParentName];
  4751. if (tParentBone){
  4752. tParentBone.addChild(tBone);
  4753. }else {
  4754. this.mRootBone=tBone;
  4755. }
  4756. }
  4757. tBoneDic[tName]=tBone;
  4758. this.mBoneArr.push(tBone);
  4759. }
  4760. this.tMatrixDataLen=tByte.getUint16();
  4761. var tLen=tByte.getUint16();
  4762. var parentIndex=0;
  4763. var boneLength=Math.floor(tLen / this.tMatrixDataLen);
  4764. var tResultTransform;
  4765. var tMatrixArray=this.srcBoneMatrixArr;
  4766. for (i=0;i < boneLength;i++){
  4767. tResultTransform=new Transform();
  4768. tResultTransform.scX=tByte.getFloat32();
  4769. tResultTransform.skX=tByte.getFloat32();
  4770. tResultTransform.skY=tByte.getFloat32();
  4771. tResultTransform.scY=tByte.getFloat32();
  4772. tResultTransform.x=tByte.getFloat32();
  4773. tResultTransform.y=tByte.getFloat32();
  4774. if (this.tMatrixDataLen===8){
  4775. tResultTransform.skewX=tByte.getFloat32();
  4776. tResultTransform.skewY=tByte.getFloat32();
  4777. }
  4778. tMatrixArray.push(tResultTransform);
  4779. tBone=this.mBoneArr[i];
  4780. tBone.transform=tResultTransform;
  4781. };
  4782. var tIkConstraintData;
  4783. var tIkLen=tByte.getUint16();
  4784. var tIkBoneLen=0;
  4785. for (i=0;i < tIkLen;i++){
  4786. tIkConstraintData=new IkConstraintData();
  4787. tIkBoneLen=tByte.getUint16();
  4788. for (j=0;j < tIkBoneLen;j++){
  4789. tIkConstraintData.boneNames.push(tByte.readUTFString());
  4790. tIkConstraintData.boneIndexs.push(tByte.getInt16());
  4791. }
  4792. tIkConstraintData.name=tByte.readUTFString();
  4793. tIkConstraintData.targetBoneName=tByte.readUTFString();
  4794. tIkConstraintData.targetBoneIndex=tByte.getInt16();
  4795. tIkConstraintData.bendDirection=tByte.getFloat32();
  4796. tIkConstraintData.mix=tByte.getFloat32();
  4797. tIkConstraintData.isSpine=isSpine;
  4798. this.ikArr.push(tIkConstraintData);
  4799. };
  4800. var tTfConstraintData;
  4801. var tTfLen=tByte.getUint16();
  4802. var tTfBoneLen=0;
  4803. for (i=0;i < tTfLen;i++){
  4804. tTfConstraintData=new TfConstraintData();
  4805. tTfBoneLen=tByte.getUint16();
  4806. for (j=0;j < tTfBoneLen;j++){
  4807. tTfConstraintData.boneIndexs.push(tByte.getInt16());
  4808. }
  4809. tTfConstraintData.name=tByte.getUTFString();
  4810. tTfConstraintData.targetIndex=tByte.getInt16();
  4811. tTfConstraintData.rotateMix=tByte.getFloat32();
  4812. tTfConstraintData.translateMix=tByte.getFloat32();
  4813. tTfConstraintData.scaleMix=tByte.getFloat32();
  4814. tTfConstraintData.shearMix=tByte.getFloat32();
  4815. tTfConstraintData.offsetRotation=tByte.getFloat32();
  4816. tTfConstraintData.offsetX=tByte.getFloat32();
  4817. tTfConstraintData.offsetY=tByte.getFloat32();
  4818. tTfConstraintData.offsetScaleX=tByte.getFloat32();
  4819. tTfConstraintData.offsetScaleY=tByte.getFloat32();
  4820. tTfConstraintData.offsetShearY=tByte.getFloat32();
  4821. this.tfArr.push(tTfConstraintData);
  4822. };
  4823. var tPathConstraintData;
  4824. var tPathLen=tByte.getUint16();
  4825. var tPathBoneLen=0;
  4826. for (i=0;i < tPathLen;i++){
  4827. tPathConstraintData=new PathConstraintData();
  4828. tPathConstraintData.name=tByte.readUTFString();
  4829. tPathBoneLen=tByte.getUint16();
  4830. for (j=0;j < tPathBoneLen;j++){
  4831. tPathConstraintData.bones.push(tByte.getInt16());
  4832. }
  4833. tPathConstraintData.target=tByte.readUTFString();
  4834. tPathConstraintData.positionMode=tByte.readUTFString();
  4835. tPathConstraintData.spacingMode=tByte.readUTFString();
  4836. tPathConstraintData.rotateMode=tByte.readUTFString();
  4837. tPathConstraintData.offsetRotation=tByte.getFloat32();
  4838. tPathConstraintData.position=tByte.getFloat32();
  4839. tPathConstraintData.spacing=tByte.getFloat32();
  4840. tPathConstraintData.rotateMix=tByte.getFloat32();
  4841. tPathConstraintData.translateMix=tByte.getFloat32();
  4842. this.pathArr.push(tPathConstraintData);
  4843. };
  4844. var tDeformSlotLen=0;
  4845. var tDeformSlotDisplayLen=0;
  4846. var tDSlotIndex=0;
  4847. var tDAttachment;
  4848. var tDeformTimeLen=0;
  4849. var tDTime=NaN;
  4850. var tDeformVecticesLen=0;
  4851. var tDeformAniData;
  4852. var tDeformSlotData;
  4853. var tDeformSlotDisplayData;
  4854. var tDeformVectices;
  4855. var tDeformAniLen=tByte.getInt16();
  4856. for (i=0;i < tDeformAniLen;i++){
  4857. var tDeformSkinLen=tByte.getUint8();
  4858. var tSkinDic={};
  4859. this.deformAniArr.push(tSkinDic);
  4860. for (var f=0;f < tDeformSkinLen;f++){
  4861. tDeformAniData=new DeformAniData();
  4862. tDeformAniData.skinName=tByte.getUTFString();
  4863. tSkinDic[tDeformAniData.skinName]=tDeformAniData;
  4864. tDeformSlotLen=tByte.getInt16();
  4865. for (j=0;j < tDeformSlotLen;j++){
  4866. tDeformSlotData=new DeformSlotData();
  4867. tDeformAniData.deformSlotDataList.push(tDeformSlotData);
  4868. tDeformSlotDisplayLen=tByte.getInt16();
  4869. for (k=0;k < tDeformSlotDisplayLen;k++){
  4870. tDeformSlotDisplayData=new DeformSlotDisplayData();
  4871. tDeformSlotData.deformSlotDisplayList.push(tDeformSlotDisplayData);
  4872. tDeformSlotDisplayData.slotIndex=tDSlotIndex=tByte.getInt16();
  4873. tDeformSlotDisplayData.attachment=tDAttachment=tByte.getUTFString();
  4874. tDeformTimeLen=tByte.getInt16();
  4875. for (l=0;l < tDeformTimeLen;l++){
  4876. if (tByte.getByte()==1){
  4877. tDeformSlotDisplayData.tweenKeyList.push(true);
  4878. }else {
  4879. tDeformSlotDisplayData.tweenKeyList.push(false);
  4880. }
  4881. tDTime=tByte.getFloat32();
  4882. tDeformSlotDisplayData.timeList.push(tDTime);
  4883. tDeformVectices=[];
  4884. tDeformSlotDisplayData.vectices.push(tDeformVectices);
  4885. tDeformVecticesLen=tByte.getInt16();
  4886. for (n=0;n < tDeformVecticesLen;n++){
  4887. tDeformVectices.push(tByte.getFloat32());
  4888. }
  4889. }
  4890. }
  4891. }
  4892. }
  4893. };
  4894. var tDrawOrderArr;
  4895. var tDrawOrderAniLen=tByte.getInt16();
  4896. var tDrawOrderLen=0;
  4897. var tDrawOrderData;
  4898. var tDoLen=0;
  4899. for (i=0;i < tDrawOrderAniLen;i++){
  4900. tDrawOrderLen=tByte.getInt16();
  4901. tDrawOrderArr=[];
  4902. for (j=0;j < tDrawOrderLen;j++){
  4903. tDrawOrderData=new DrawOrderData();
  4904. tDrawOrderData.time=tByte.getFloat32();
  4905. tDoLen=tByte.getInt16();
  4906. for (k=0;k < tDoLen;k++){
  4907. tDrawOrderData.drawOrder.push(tByte.getInt16());
  4908. }
  4909. tDrawOrderArr.push(tDrawOrderData);
  4910. }
  4911. this.drawOrderAniArr.push(tDrawOrderArr);
  4912. };
  4913. var tEventArr;
  4914. var tEventAniLen=tByte.getInt16();
  4915. var tEventLen=0;
  4916. var tEventData;
  4917. for (i=0;i < tEventAniLen;i++){
  4918. tEventLen=tByte.getInt16();
  4919. tEventArr=[];
  4920. for (j=0;j < tEventLen;j++){
  4921. tEventData=new EventData();
  4922. tEventData.name=tByte.getUTFString();
  4923. tEventData.intValue=tByte.getInt32();
  4924. tEventData.floatValue=tByte.getFloat32();
  4925. tEventData.stringValue=tByte.getUTFString();
  4926. tEventData.time=tByte.getFloat32();
  4927. tEventArr.push(tEventData);
  4928. }
  4929. this.eventAniArr.push(tEventArr);
  4930. };
  4931. var tAttachmentLen=tByte.getInt16();
  4932. if (tAttachmentLen > 0){
  4933. this.attachmentNames=[];
  4934. for (i=0;i < tAttachmentLen;i++){
  4935. this.attachmentNames.push(tByte.getUTFString());
  4936. }
  4937. };
  4938. var tBoneSlotLen=tByte.getInt16();
  4939. var tDBBoneSlot;
  4940. var tDBBoneSlotArr;
  4941. for (i=0;i < tBoneSlotLen;i++){
  4942. tDBBoneSlot=new BoneSlot();
  4943. tDBBoneSlot.name=tByte.readUTFString();
  4944. tDBBoneSlot.parent=tByte.readUTFString();
  4945. tDBBoneSlot.attachmentName=tByte.readUTFString();
  4946. tDBBoneSlot.srcDisplayIndex=tDBBoneSlot.displayIndex=tByte.getInt16();
  4947. tDBBoneSlot.templet=this;
  4948. this.boneSlotDic[tDBBoneSlot.name]=tDBBoneSlot;
  4949. tDBBoneSlotArr=this.bindBoneBoneSlotDic[tDBBoneSlot.parent];
  4950. if (tDBBoneSlotArr==null){
  4951. this.bindBoneBoneSlotDic[tDBBoneSlot.parent]=tDBBoneSlotArr=[];
  4952. }
  4953. tDBBoneSlotArr.push(tDBBoneSlot);
  4954. this.boneSlotArray.push(tDBBoneSlot);
  4955. };
  4956. var tNameString=tByte.readUTFString();
  4957. var tNameArray=tNameString.split("\n");
  4958. var tNameStartIndex=0;
  4959. var tSkinDataLen=tByte.getUint8();
  4960. var tSkinData,tSlotData,tDisplayData;
  4961. var tSlotDataLen=0,tDisplayDataLen=0;
  4962. var tUvLen=0,tWeightLen=0,tTriangleLen=0,tVerticeLen=0,tLengthLen=0;
  4963. for (i=0;i < tSkinDataLen;i++){
  4964. tSkinData=new SkinData();
  4965. tSkinData.name=tNameArray[tNameStartIndex++];
  4966. tSlotDataLen=tByte.getUint8();
  4967. for (j=0;j < tSlotDataLen;j++){
  4968. tSlotData=new SlotData();
  4969. tSlotData.name=tNameArray[tNameStartIndex++];
  4970. tDBBoneSlot=this.boneSlotDic[tSlotData.name];
  4971. tDisplayDataLen=tByte.getUint8();
  4972. for (k=0;k < tDisplayDataLen;k++){
  4973. tDisplayData=new SkinSlotDisplayData();
  4974. this.skinSlotDisplayDataArr.push(tDisplayData);
  4975. tDisplayData.name=tNameArray[tNameStartIndex++];
  4976. tDisplayData.attachmentName=tNameArray[tNameStartIndex++];
  4977. tDisplayData.transform=new Transform();
  4978. tDisplayData.transform.scX=tByte.getFloat32();
  4979. tDisplayData.transform.skX=tByte.getFloat32();
  4980. tDisplayData.transform.skY=tByte.getFloat32();
  4981. tDisplayData.transform.scY=tByte.getFloat32();
  4982. tDisplayData.transform.x=tByte.getFloat32();
  4983. tDisplayData.transform.y=tByte.getFloat32();
  4984. tSlotData.displayArr.push(tDisplayData);
  4985. tDisplayData.width=tByte.getFloat32();
  4986. tDisplayData.height=tByte.getFloat32();
  4987. tDisplayData.type=tByte.getUint8();
  4988. tDisplayData.verLen=tByte.getUint16();
  4989. tBoneLen=tByte.getUint16();
  4990. if (tBoneLen > 0){
  4991. tDisplayData.bones=[];
  4992. for (l=0;l < tBoneLen;l++){
  4993. var tBoneId=tByte.getUint16();
  4994. tDisplayData.bones.push(tBoneId);
  4995. }
  4996. }
  4997. tUvLen=tByte.getUint16();
  4998. if (tUvLen > 0){
  4999. tDisplayData.uvs=[];
  5000. for (l=0;l < tUvLen;l++){
  5001. tDisplayData.uvs.push(tByte.getFloat32());
  5002. }
  5003. }
  5004. tWeightLen=tByte.getUint16();
  5005. if (tWeightLen > 0){
  5006. tDisplayData.weights=[];
  5007. for (l=0;l < tWeightLen;l++){
  5008. tDisplayData.weights.push(tByte.getFloat32());
  5009. }
  5010. }
  5011. tTriangleLen=tByte.getUint16();
  5012. if (tTriangleLen > 0){
  5013. tDisplayData.triangles=[];
  5014. for (l=0;l < tTriangleLen;l++){
  5015. tDisplayData.triangles.push(tByte.getUint16());
  5016. }
  5017. }
  5018. tVerticeLen=tByte.getUint16();
  5019. if (tVerticeLen > 0){
  5020. tDisplayData.vertices=[];
  5021. for (l=0;l < tVerticeLen;l++){
  5022. tDisplayData.vertices.push(tByte.getFloat32());
  5023. }
  5024. }
  5025. tLengthLen=tByte.getUint16();
  5026. if (tLengthLen > 0){
  5027. tDisplayData.lengths=[];
  5028. for (l=0;l < tLengthLen;l++){
  5029. tDisplayData.lengths.push(tByte.getFloat32());
  5030. }
  5031. }
  5032. }
  5033. tSkinData.slotArr.push(tSlotData);
  5034. }
  5035. this.skinDic[tSkinData.name]=tSkinData;
  5036. this.skinDataArray.push(tSkinData);
  5037. };
  5038. var tReverse=tByte.getUint8();
  5039. if (tReverse==1){
  5040. this.yReverseMatrix=new Matrix(1,0,0,-1,0,0);
  5041. if (tRootBone){
  5042. tRootBone.setTempMatrix(this.yReverseMatrix);
  5043. }
  5044. }else {
  5045. if (tRootBone){
  5046. tRootBone.setTempMatrix(new Matrix());
  5047. }
  5048. }
  5049. this.showSkinByIndex(this.boneSlotDic,0);
  5050. this.isParserComplete=true;
  5051. this.event(/*laya.events.Event.COMPLETE*/"complete",this);
  5052. }
  5053. /**
  5054. *得到指定的纹理
  5055. *@param name 纹理的名字
  5056. *@return
  5057. */
  5058. __proto.getTexture=function(name){
  5059. var tTexture=this.subTextureDic[name];
  5060. if (!tTexture){
  5061. tTexture=this.subTextureDic[name.substr(0,name.length-1)];
  5062. }
  5063. if (tTexture==null){
  5064. return this._mainTexture;
  5065. }
  5066. return tTexture;
  5067. }
  5068. /**
  5069. *@private
  5070. *显示指定的皮肤
  5071. *@param boneSlotDic 插糟字典的引用
  5072. *@param skinIndex 皮肤的索引
  5073. *@param freshDisplayIndex 是否重置插槽纹理
  5074. */
  5075. __proto.showSkinByIndex=function(boneSlotDic,skinIndex,freshDisplayIndex){
  5076. (freshDisplayIndex===void 0)&& (freshDisplayIndex=true);
  5077. if (skinIndex < 0 && skinIndex >=this.skinDataArray.length)return false;
  5078. var i=0,n=0;
  5079. var tBoneSlot;
  5080. var tSlotData;
  5081. var tSkinData=this.skinDataArray[skinIndex];
  5082. if (tSkinData){
  5083. for (i=0,n=tSkinData.slotArr.length;i < n;i++){
  5084. tSlotData=tSkinData.slotArr[i];
  5085. if (tSlotData){
  5086. tBoneSlot=boneSlotDic[tSlotData.name];
  5087. if (tBoneSlot){
  5088. tBoneSlot.showSlotData(tSlotData,freshDisplayIndex);
  5089. if (freshDisplayIndex&&tBoneSlot.attachmentName !="undefined" && tBoneSlot.attachmentName !="null"){
  5090. tBoneSlot.showDisplayByName(tBoneSlot.attachmentName);
  5091. }else {
  5092. tBoneSlot.showDisplayByIndex(tBoneSlot.displayIndex);
  5093. }
  5094. }
  5095. }
  5096. }
  5097. return true;
  5098. }
  5099. return false;
  5100. }
  5101. /**
  5102. *通过皮肤名字得到皮肤索引
  5103. *@param skinName 皮肤名称
  5104. *@return
  5105. */
  5106. __proto.getSkinIndexByName=function(skinName){
  5107. var tSkinData;
  5108. for (var i=0,n=this.skinDataArray.length;i < n;i++){
  5109. tSkinData=this.skinDataArray[i];
  5110. if (tSkinData.name==skinName){
  5111. return i;
  5112. }
  5113. }
  5114. return-1;
  5115. }
  5116. /**
  5117. *@private
  5118. *得到缓冲数据
  5119. *@param aniIndex 动画索引
  5120. *@param frameIndex 帧索引
  5121. *@return
  5122. */
  5123. __proto.getGrahicsDataWithCache=function(aniIndex,frameIndex){
  5124. if (this._graphicsCache[aniIndex] && this._graphicsCache[aniIndex][frameIndex]){
  5125. return this._graphicsCache[aniIndex][frameIndex];
  5126. }
  5127. return null;
  5128. }
  5129. __proto._setCreateURL=function(url){
  5130. this._relativeUrl=url;
  5131. laya.resource.Resource.prototype._setCreateURL.call(this,url);
  5132. }
  5133. /**
  5134. *@private
  5135. *保存缓冲grahpics
  5136. *@param aniIndex 动画索引
  5137. *@param frameIndex 帧索引
  5138. *@param graphics 要保存的数据
  5139. */
  5140. __proto.setGrahicsDataWithCache=function(aniIndex,frameIndex,graphics){
  5141. this._graphicsCache[aniIndex][frameIndex]=graphics;
  5142. }
  5143. __proto.deleteAniData=function(aniIndex){
  5144. if (this._anis[aniIndex]){
  5145. var tAniDataO=this._anis[aniIndex];
  5146. tAniDataO.bone3DMap=null;
  5147. tAniDataO.nodes=null;
  5148. }
  5149. }
  5150. /**
  5151. *释放纹理
  5152. */
  5153. __proto.destroy=function(){
  5154. this._isDestroyed=true;
  5155. var tTexture;
  5156. var $each_tTexture;
  5157. /*for each*/for($each_tTexture in this.subTextureDic){
  5158. tTexture=this.subTextureDic[$each_tTexture];
  5159. if(tTexture)
  5160. tTexture.destroy();
  5161. }
  5162. var $each_tTexture;
  5163. /*for each*/for($each_tTexture in this._textureDic){
  5164. tTexture=this._textureDic[$each_tTexture];
  5165. if(tTexture)
  5166. tTexture.destroy();
  5167. };
  5168. var tSkinSlotDisplayData;
  5169. for (var i=0,n=this.skinSlotDisplayDataArr.length;i < n;i++){
  5170. tSkinSlotDisplayData=this.skinSlotDisplayDataArr[i];
  5171. tSkinSlotDisplayData.destory();
  5172. }
  5173. this.skinSlotDisplayDataArr.length=0;
  5174. if (this.url){
  5175. delete Templet.TEMPLET_DICTIONARY[this.url];
  5176. }
  5177. laya.resource.Resource.prototype.destroy.call(this);
  5178. }
  5179. /**
  5180. *通过索引得动画名称
  5181. *@param index
  5182. *@return
  5183. */
  5184. __proto.getAniNameByIndex=function(index){
  5185. var tAni=this.getAnimation(index);
  5186. if (tAni)return tAni.name;
  5187. return null;
  5188. }
  5189. __getset(0,__proto,'rate',function(){
  5190. return this._rate;
  5191. },function(v){
  5192. this._rate=v;
  5193. });
  5194. Templet.LAYA_ANIMATION_VISION="LAYAANIMATION:1.6.0";
  5195. Templet.TEMPLET_DICTIONARY=null;
  5196. return Templet;
  5197. })(AnimationTemplet)
  5198. })(window,document,Laya);