laya.ani.js 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209
  1. (function (exports, Laya) {
  2. 'use strict';
  3. class IAniLib {
  4. }
  5. IAniLib.Skeleton = null;
  6. IAniLib.AnimationTemplet = null;
  7. IAniLib.Templet = null;
  8. class AnimationContent {
  9. }
  10. class AnimationNodeContent {
  11. }
  12. class KeyFramesContent {
  13. }
  14. class AnimationParser01 {
  15. static parse(templet, reader) {
  16. var data = reader.__getBuffer();
  17. var i, j, k, n, l, m, o;
  18. var aniClassName = reader.readUTFString();
  19. templet._aniClassName = aniClassName;
  20. var strList = reader.readUTFString().split("\n");
  21. var aniCount = reader.getUint8();
  22. var publicDataPos = reader.getUint32();
  23. var publicExtDataPos = reader.getUint32();
  24. var publicData;
  25. if (publicDataPos > 0)
  26. publicData = data.slice(publicDataPos, publicExtDataPos);
  27. var publicRead = new Laya.Byte(publicData);
  28. if (publicExtDataPos > 0)
  29. templet._publicExtData = data.slice(publicExtDataPos, data.byteLength);
  30. templet._useParent = !!reader.getUint8();
  31. templet._anis.length = aniCount;
  32. for (i = 0; i < aniCount; i++) {
  33. var ani = templet._anis[i] = new AnimationContent();
  34. ani.nodes = [];
  35. var name = ani.name = strList[reader.getUint16()];
  36. templet._aniMap[name] = i;
  37. ani.bone3DMap = {};
  38. ani.playTime = reader.getFloat32();
  39. var boneCount = ani.nodes.length = reader.getUint8();
  40. ani.totalKeyframeDatasLength = 0;
  41. for (j = 0; j < boneCount; j++) {
  42. var node = ani.nodes[j] = new AnimationNodeContent();
  43. node.childs = [];
  44. var nameIndex = reader.getInt16();
  45. if (nameIndex >= 0) {
  46. node.name = strList[nameIndex];
  47. ani.bone3DMap[node.name] = j;
  48. }
  49. node.keyFrame = [];
  50. node.parentIndex = reader.getInt16();
  51. node.parentIndex == -1 ? node.parent = null : node.parent = ani.nodes[node.parentIndex];
  52. node.lerpType = reader.getUint8();
  53. var keyframeParamsOffset = reader.getUint32();
  54. publicRead.pos = keyframeParamsOffset;
  55. var keyframeDataCount = node.keyframeWidth = publicRead.getUint16();
  56. ani.totalKeyframeDatasLength += keyframeDataCount;
  57. if (node.lerpType === 0 || node.lerpType === 1) {
  58. node.interpolationMethod = [];
  59. node.interpolationMethod.length = keyframeDataCount;
  60. for (k = 0; k < keyframeDataCount; k++)
  61. node.interpolationMethod[k] = IAniLib.AnimationTemplet.interpolation[publicRead.getUint8()];
  62. }
  63. if (node.parent != null)
  64. node.parent.childs.push(node);
  65. var privateDataLen = reader.getUint16();
  66. if (privateDataLen > 0) {
  67. node.extenData = data.slice(reader.pos, reader.pos + privateDataLen);
  68. reader.pos += privateDataLen;
  69. }
  70. var keyframeCount = reader.getUint16();
  71. node.keyFrame.length = keyframeCount;
  72. var startTime = 0;
  73. var keyFrame;
  74. for (k = 0, n = keyframeCount; k < n; k++) {
  75. keyFrame = node.keyFrame[k] = new KeyFramesContent();
  76. keyFrame.duration = reader.getFloat32();
  77. keyFrame.startTime = startTime;
  78. if (node.lerpType === 2) {
  79. keyFrame.interpolationData = [];
  80. var interDataLength = reader.getUint8();
  81. var lerpType;
  82. lerpType = reader.getFloat32();
  83. switch (lerpType) {
  84. case 254:
  85. keyFrame.interpolationData.length = keyframeDataCount;
  86. for (o = 0; o < keyframeDataCount; o++)
  87. keyFrame.interpolationData[o] = 0;
  88. break;
  89. case 255:
  90. keyFrame.interpolationData.length = keyframeDataCount;
  91. for (o = 0; o < keyframeDataCount; o++)
  92. keyFrame.interpolationData[o] = 5;
  93. break;
  94. default:
  95. keyFrame.interpolationData.push(lerpType);
  96. for (m = 1; m < interDataLength; m++) {
  97. keyFrame.interpolationData.push(reader.getFloat32());
  98. }
  99. }
  100. }
  101. keyFrame.data = new Float32Array(keyframeDataCount);
  102. keyFrame.dData = new Float32Array(keyframeDataCount);
  103. keyFrame.nextData = new Float32Array(keyframeDataCount);
  104. for (l = 0; l < keyframeDataCount; l++) {
  105. keyFrame.data[l] = reader.getFloat32();
  106. if (keyFrame.data[l] > -0.00000001 && keyFrame.data[l] < 0.00000001)
  107. keyFrame.data[l] = 0;
  108. }
  109. startTime += keyFrame.duration;
  110. }
  111. keyFrame.startTime = ani.playTime;
  112. node.playTime = ani.playTime;
  113. templet._calculateKeyFrame(node, keyframeCount, keyframeDataCount);
  114. }
  115. }
  116. }
  117. }
  118. class AnimationParser02 {
  119. static READ_DATA() {
  120. AnimationParser02._DATA.offset = AnimationParser02._reader.getUint32();
  121. AnimationParser02._DATA.size = AnimationParser02._reader.getUint32();
  122. }
  123. static READ_BLOCK() {
  124. var count = AnimationParser02._BLOCK.count = AnimationParser02._reader.getUint16();
  125. var blockStarts = AnimationParser02._BLOCK.blockStarts = [];
  126. var blockLengths = AnimationParser02._BLOCK.blockLengths = [];
  127. for (var i = 0; i < count; i++) {
  128. blockStarts.push(AnimationParser02._reader.getUint32());
  129. blockLengths.push(AnimationParser02._reader.getUint32());
  130. }
  131. }
  132. static READ_STRINGS() {
  133. var offset = AnimationParser02._reader.getUint32();
  134. var count = AnimationParser02._reader.getUint16();
  135. var prePos = AnimationParser02._reader.pos;
  136. AnimationParser02._reader.pos = offset + AnimationParser02._DATA.offset;
  137. for (var i = 0; i < count; i++)
  138. AnimationParser02._strings[i] = AnimationParser02._reader.readUTFString();
  139. AnimationParser02._reader.pos = prePos;
  140. }
  141. static parse(templet, reader) {
  142. AnimationParser02._templet = templet;
  143. AnimationParser02._reader = reader;
  144. var arrayBuffer = reader.__getBuffer();
  145. AnimationParser02.READ_DATA();
  146. AnimationParser02.READ_BLOCK();
  147. AnimationParser02.READ_STRINGS();
  148. for (var i = 0, n = AnimationParser02._BLOCK.count; i < n; i++) {
  149. var index = reader.getUint16();
  150. var blockName = AnimationParser02._strings[index];
  151. var fn = AnimationParser02["READ_" + blockName];
  152. if (fn == null)
  153. throw new Error("model file err,no this function:" + index + " " + blockName);
  154. else
  155. fn.call(null);
  156. }
  157. }
  158. static READ_ANIMATIONS() {
  159. var reader = AnimationParser02._reader;
  160. var arrayBuffer = reader.__getBuffer();
  161. var i, j, k, n;
  162. var keyframeWidth = reader.getUint16();
  163. var interpolationMethod = [];
  164. interpolationMethod.length = keyframeWidth;
  165. for (i = 0; i < keyframeWidth; i++)
  166. interpolationMethod[i] = IAniLib.AnimationTemplet.interpolation[reader.getByte()];
  167. var aniCount = reader.getUint8();
  168. AnimationParser02._templet._anis.length = aniCount;
  169. for (i = 0; i < aniCount; i++) {
  170. var ani = AnimationParser02._templet._anis[i] = new AnimationContent();
  171. ani.nodes = [];
  172. var aniName = ani.name = AnimationParser02._strings[reader.getUint16()];
  173. AnimationParser02._templet._aniMap[aniName] = i;
  174. ani.bone3DMap = {};
  175. ani.playTime = reader.getFloat32();
  176. var boneCount = ani.nodes.length = reader.getInt16();
  177. ani.totalKeyframeDatasLength = 0;
  178. for (j = 0; j < boneCount; j++) {
  179. var node = ani.nodes[j] = new AnimationNodeContent();
  180. node.keyframeWidth = keyframeWidth;
  181. node.childs = [];
  182. var nameIndex = reader.getUint16();
  183. if (nameIndex >= 0) {
  184. node.name = AnimationParser02._strings[nameIndex];
  185. ani.bone3DMap[node.name] = j;
  186. }
  187. node.keyFrame = [];
  188. node.parentIndex = reader.getInt16();
  189. node.parentIndex == -1 ? node.parent = null : node.parent = ani.nodes[node.parentIndex];
  190. ani.totalKeyframeDatasLength += keyframeWidth;
  191. node.interpolationMethod = interpolationMethod;
  192. if (node.parent != null)
  193. node.parent.childs.push(node);
  194. var keyframeCount = reader.getUint16();
  195. node.keyFrame.length = keyframeCount;
  196. var keyFrame = null, lastKeyFrame = null;
  197. for (k = 0, n = keyframeCount; k < n; k++) {
  198. keyFrame = node.keyFrame[k] = new KeyFramesContent();
  199. keyFrame.startTime = reader.getFloat32();
  200. (lastKeyFrame) && (lastKeyFrame.duration = keyFrame.startTime - lastKeyFrame.startTime);
  201. keyFrame.dData = new Float32Array(keyframeWidth);
  202. keyFrame.nextData = new Float32Array(keyframeWidth);
  203. var offset = AnimationParser02._DATA.offset;
  204. var keyframeDataOffset = reader.getUint32();
  205. var keyframeDataLength = keyframeWidth * 4;
  206. var keyframeArrayBuffer = arrayBuffer.slice(offset + keyframeDataOffset, offset + keyframeDataOffset + keyframeDataLength);
  207. keyFrame.data = new Float32Array(keyframeArrayBuffer);
  208. lastKeyFrame = keyFrame;
  209. }
  210. keyFrame.duration = 0;
  211. node.playTime = ani.playTime;
  212. AnimationParser02._templet._calculateKeyFrame(node, keyframeCount, keyframeWidth);
  213. }
  214. }
  215. }
  216. }
  217. AnimationParser02._strings = [];
  218. AnimationParser02._BLOCK = { count: 0 };
  219. AnimationParser02._DATA = { offset: 0, size: 0 };
  220. class AnimationState {
  221. constructor() {
  222. }
  223. }
  224. AnimationState.stopped = 0;
  225. AnimationState.paused = 1;
  226. AnimationState.playing = 2;
  227. class AnimationPlayer extends Laya.EventDispatcher {
  228. constructor() {
  229. super();
  230. this.isCache = true;
  231. this.playbackRate = 1.0;
  232. this._destroyed = false;
  233. this._currentAnimationClipIndex = -1;
  234. this._currentKeyframeIndex = -1;
  235. this._currentTime = 0.0;
  236. this._overallDuration = Number.MAX_VALUE;
  237. this._stopWhenCircleFinish = false;
  238. this._elapsedPlaybackTime = 0;
  239. this._startUpdateLoopCount = -1;
  240. this._cachePlayRate = 1.0;
  241. this.cacheFrameRate = 60;
  242. this.returnToZeroStopped = false;
  243. }
  244. get templet() {
  245. return this._templet;
  246. }
  247. set templet(value) {
  248. if (!(this.state === AnimationState.stopped))
  249. this.stop(true);
  250. if (this._templet !== value) {
  251. this._templet = value;
  252. this._computeFullKeyframeIndices();
  253. }
  254. }
  255. get playStart() {
  256. return this._playStart;
  257. }
  258. get playEnd() {
  259. return this._playEnd;
  260. }
  261. get playDuration() {
  262. return this._playDuration;
  263. }
  264. get overallDuration() {
  265. return this._overallDuration;
  266. }
  267. get currentAnimationClipIndex() {
  268. return this._currentAnimationClipIndex;
  269. }
  270. get currentKeyframeIndex() {
  271. return this._currentKeyframeIndex;
  272. }
  273. get currentPlayTime() {
  274. return this._currentTime + this._playStart;
  275. }
  276. get currentFrameTime() {
  277. return this._currentFrameTime;
  278. }
  279. get cachePlayRate() {
  280. return this._cachePlayRate;
  281. }
  282. set cachePlayRate(value) {
  283. if (this._cachePlayRate !== value) {
  284. this._cachePlayRate = value;
  285. if (this._templet)
  286. this._computeFullKeyframeIndices();
  287. }
  288. }
  289. get cacheFrameRate() {
  290. return this._cacheFrameRate;
  291. }
  292. set cacheFrameRate(value) {
  293. if (this._cacheFrameRate !== value) {
  294. this._cacheFrameRate = value;
  295. this._cacheFrameRateInterval = 1000.0 / this._cacheFrameRate;
  296. if (this._templet)
  297. this._computeFullKeyframeIndices();
  298. }
  299. }
  300. set currentTime(value) {
  301. if (this._currentAnimationClipIndex === -1 || !this._templet)
  302. return;
  303. if (value < this._playStart || value > this._playEnd)
  304. throw new Error("AnimationPlayer:value must large than playStartTime,small than playEndTime.");
  305. this._startUpdateLoopCount = Laya.Stat.loopCount;
  306. var cacheFrameInterval = this._cacheFrameRateInterval * this._cachePlayRate;
  307. this._currentTime = value;
  308. this._currentKeyframeIndex = Math.floor(this.currentPlayTime / cacheFrameInterval);
  309. this._currentFrameTime = this._currentKeyframeIndex * cacheFrameInterval;
  310. }
  311. get paused() {
  312. return this._paused;
  313. }
  314. set paused(value) {
  315. this._paused = value;
  316. value && this.event(Laya.Event.PAUSED);
  317. }
  318. get cacheFrameRateInterval() {
  319. return this._cacheFrameRateInterval;
  320. }
  321. get state() {
  322. if (this._currentAnimationClipIndex === -1)
  323. return AnimationState.stopped;
  324. if (this._paused)
  325. return AnimationState.paused;
  326. return AnimationState.playing;
  327. }
  328. get destroyed() {
  329. return this._destroyed;
  330. }
  331. _onTempletLoadedComputeFullKeyframeIndices(cachePlayRate, cacheFrameRate, templet) {
  332. if (this._templet === templet && this._cachePlayRate === cachePlayRate && this._cacheFrameRate === cacheFrameRate)
  333. this._computeFullKeyframeIndices();
  334. }
  335. _computeFullKeyframeIndices() {
  336. return;
  337. var templet = this._templet;
  338. if (templet._fullFrames)
  339. return;
  340. var anifullFrames = this._templet._fullFrames = [];
  341. var cacheFrameInterval = this._cacheFrameRateInterval * this._cachePlayRate;
  342. for (var i = 0, iNum = templet.getAnimationCount(); i < iNum; i++) {
  343. var aniFullFrame = [];
  344. if (!templet.getAnimation(i).nodes) {
  345. anifullFrames.push(aniFullFrame);
  346. continue;
  347. }
  348. for (var j = 0, jNum = templet.getAnimation(i).nodes.length; j < jNum; j++) {
  349. var node = templet.getAnimation(i).nodes[j];
  350. var frameCount = Math.round(node.playTime / cacheFrameInterval);
  351. var nodeFullFrames = new Uint16Array(frameCount + 1);
  352. var stidx = -1;
  353. var nodeframes = node.keyFrame;
  354. for (var n = 0, nNum = nodeframes.length; n < nNum; n++) {
  355. var keyFrame = nodeframes[n];
  356. var pos = Math.round(keyFrame.startTime / cacheFrameInterval);
  357. if (stidx < 0 && pos > 0) {
  358. stidx = pos;
  359. }
  360. if (pos <= frameCount) {
  361. nodeFullFrames[pos] = n;
  362. }
  363. }
  364. var cf = 0;
  365. for (n = stidx; n < frameCount; n++) {
  366. if (nodeFullFrames[n] == 0) {
  367. nodeFullFrames[n] = cf;
  368. }
  369. else {
  370. cf = nodeFullFrames[n];
  371. }
  372. }
  373. aniFullFrame.push(nodeFullFrames);
  374. }
  375. anifullFrames.push(aniFullFrame);
  376. }
  377. }
  378. _onAnimationTempletLoaded() {
  379. (this.destroyed) || (this._calculatePlayDuration());
  380. }
  381. _calculatePlayDuration() {
  382. if (this.state !== AnimationState.stopped) {
  383. var oriDuration = this._templet.getAniDuration(this._currentAnimationClipIndex);
  384. (this._playEnd === 0) && (this._playEnd = oriDuration);
  385. if (this._playEnd > oriDuration)
  386. this._playEnd = oriDuration;
  387. this._playDuration = this._playEnd - this._playStart;
  388. }
  389. }
  390. _setPlayParams(time, cacheFrameInterval) {
  391. this._currentTime = time;
  392. this._currentKeyframeIndex = Math.floor((this.currentPlayTime) / cacheFrameInterval + 0.01);
  393. this._currentFrameTime = this._currentKeyframeIndex * cacheFrameInterval;
  394. }
  395. _setPlayParamsWhenStop(currentAniClipPlayDuration, cacheFrameInterval, playEnd = -1) {
  396. this._currentTime = currentAniClipPlayDuration;
  397. var endTime = playEnd > 0 ? playEnd : currentAniClipPlayDuration;
  398. this._currentKeyframeIndex = Math.floor(endTime / cacheFrameInterval + 0.01);
  399. this._currentKeyframeIndex = Math.floor(currentAniClipPlayDuration / cacheFrameInterval + 0.01);
  400. this._currentFrameTime = this._currentKeyframeIndex * cacheFrameInterval;
  401. this._currentAnimationClipIndex = -1;
  402. }
  403. _update(elapsedTime) {
  404. if (this._currentAnimationClipIndex === -1 || this._paused || !this._templet)
  405. return;
  406. var cacheFrameInterval = this._cacheFrameRateInterval * this._cachePlayRate;
  407. var time = 0;
  408. (this._startUpdateLoopCount !== Laya.Stat.loopCount) && (time = elapsedTime * this.playbackRate, this._elapsedPlaybackTime += time);
  409. var currentAniClipPlayDuration = this.playDuration;
  410. time += this._currentTime;
  411. if ((this._overallDuration !== 0 && this._elapsedPlaybackTime >= this._overallDuration) || (this._overallDuration === 0 && this._elapsedPlaybackTime >= currentAniClipPlayDuration
  412. || (this._overallDuration === 0 && time >= this.playEnd))) {
  413. this._setPlayParamsWhenStop(currentAniClipPlayDuration, cacheFrameInterval, this.playEnd);
  414. this.event(Laya.Event.STOPPED);
  415. return;
  416. }
  417. if (currentAniClipPlayDuration > 0) {
  418. if (time >= currentAniClipPlayDuration) {
  419. if (this._stopWhenCircleFinish) {
  420. this._setPlayParamsWhenStop(currentAniClipPlayDuration, cacheFrameInterval);
  421. this._stopWhenCircleFinish = false;
  422. this.event(Laya.Event.STOPPED);
  423. return;
  424. }
  425. else {
  426. time = time % currentAniClipPlayDuration;
  427. this._setPlayParams(time, cacheFrameInterval);
  428. this.event(Laya.Event.COMPLETE);
  429. return;
  430. }
  431. }
  432. else {
  433. this._setPlayParams(time, cacheFrameInterval);
  434. }
  435. }
  436. else {
  437. if (this._stopWhenCircleFinish) {
  438. this._setPlayParamsWhenStop(currentAniClipPlayDuration, cacheFrameInterval);
  439. this._stopWhenCircleFinish = false;
  440. this.event(Laya.Event.STOPPED);
  441. return;
  442. }
  443. this._currentTime = this._currentFrameTime = this._currentKeyframeIndex = 0;
  444. this.event(Laya.Event.COMPLETE);
  445. }
  446. }
  447. _destroy() {
  448. this.offAll();
  449. this._templet = null;
  450. this._destroyed = true;
  451. }
  452. play(index = 0, playbackRate = 1.0, overallDuration = 2147483647, playStart = 0, playEnd = 0) {
  453. if (!this._templet)
  454. throw new Error("AnimationPlayer:templet must not be null,maybe you need to set url.");
  455. if (overallDuration < 0 || playStart < 0 || playEnd < 0)
  456. throw new Error("AnimationPlayer:overallDuration,playStart and playEnd must large than zero.");
  457. if ((playEnd !== 0) && (playStart > playEnd))
  458. throw new Error("AnimationPlayer:start must less than end.");
  459. this._currentTime = 0;
  460. this._currentFrameTime = 0;
  461. this._elapsedPlaybackTime = 0;
  462. this.playbackRate = playbackRate;
  463. this._overallDuration = overallDuration;
  464. this._playStart = playStart;
  465. this._playEnd = playEnd;
  466. this._paused = false;
  467. this._currentAnimationClipIndex = index;
  468. this._currentKeyframeIndex = 0;
  469. this._startUpdateLoopCount = Laya.Stat.loopCount;
  470. this.event(Laya.Event.PLAYED);
  471. this._calculatePlayDuration();
  472. this._update(0);
  473. }
  474. playByFrame(index = 0, playbackRate = 1.0, overallDuration = 2147483647, playStartFrame = 0, playEndFrame = 0, fpsIn3DBuilder = 30) {
  475. var interval = 1000.0 / fpsIn3DBuilder;
  476. this.play(index, playbackRate, overallDuration, playStartFrame * interval, playEndFrame * interval);
  477. }
  478. stop(immediate = true) {
  479. if (immediate) {
  480. this._currentTime = this._currentFrameTime = this._currentKeyframeIndex = 0;
  481. this._currentAnimationClipIndex = -1;
  482. this.event(Laya.Event.STOPPED);
  483. }
  484. else {
  485. this._stopWhenCircleFinish = true;
  486. }
  487. }
  488. destroy() {
  489. }
  490. }
  491. class BezierLerp {
  492. constructor() {
  493. }
  494. static getBezierRate(t, px0, py0, px1, py1) {
  495. var key = BezierLerp._getBezierParamKey(px0, py0, px1, py1);
  496. var vKey = key * 100 + t;
  497. if (BezierLerp._bezierResultCache[vKey])
  498. return BezierLerp._bezierResultCache[vKey];
  499. var points = BezierLerp._getBezierPoints(px0, py0, px1, py1, key);
  500. var i, len;
  501. len = points.length;
  502. for (i = 0; i < len; i += 2) {
  503. if (t <= points[i]) {
  504. BezierLerp._bezierResultCache[vKey] = points[i + 1];
  505. return points[i + 1];
  506. }
  507. }
  508. BezierLerp._bezierResultCache[vKey] = 1;
  509. return 1;
  510. }
  511. static _getBezierParamKey(px0, py0, px1, py1) {
  512. return (((px0 * 100 + py0) * 100 + px1) * 100 + py1) * 100;
  513. }
  514. static _getBezierPoints(px0, py0, px1, py1, key) {
  515. if (BezierLerp._bezierPointsCache[key])
  516. return BezierLerp._bezierPointsCache[key];
  517. var controlPoints;
  518. controlPoints = [0, 0, px0, py0, px1, py1, 1, 1];
  519. var bz;
  520. bz = new Laya.Bezier();
  521. var points;
  522. points = bz.getBezierPoints(controlPoints, 100, 3);
  523. BezierLerp._bezierPointsCache[key] = points;
  524. return points;
  525. }
  526. }
  527. BezierLerp._bezierResultCache = {};
  528. BezierLerp._bezierPointsCache = {};
  529. class AnimationTemplet extends Laya.Resource {
  530. constructor() {
  531. super();
  532. this._anis = [];
  533. this._aniMap = {};
  534. this.unfixedLastAniIndex = -1;
  535. this._fullFrames = null;
  536. this._boneCurKeyFrm = [];
  537. }
  538. static _LinearInterpolation_0(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null) {
  539. out[outOfs] = data[index] + dt * dData[index];
  540. return 1;
  541. }
  542. static _QuaternionInterpolation_1(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null) {
  543. var amount = duration === 0 ? 0 : dt / duration;
  544. Laya.MathUtil.slerpQuaternionArray(data, index, nextData, index, amount, out, outOfs);
  545. return 4;
  546. }
  547. static _AngleInterpolation_2(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null) {
  548. return 0;
  549. }
  550. static _RadiansInterpolation_3(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null) {
  551. return 0;
  552. }
  553. static _Matrix4x4Interpolation_4(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null) {
  554. for (var i = 0; i < 16; i++, index++)
  555. out[outOfs + i] = data[index] + dt * dData[index];
  556. return 16;
  557. }
  558. static _NoInterpolation_5(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null) {
  559. out[outOfs] = data[index];
  560. return 1;
  561. }
  562. static _BezierInterpolation_6(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null, offset = 0) {
  563. out[outOfs] = data[index] + (nextData[index] - data[index]) * BezierLerp.getBezierRate(dt / duration, interData[offset], interData[offset + 1], interData[offset + 2], interData[offset + 3]);
  564. return 5;
  565. }
  566. static _BezierInterpolation_7(bone, index, out, outOfs, data, dt, dData, duration, nextData, interData = null, offset = 0) {
  567. 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]);
  568. return 9;
  569. }
  570. parse(data) {
  571. var reader = new Laya.Byte(data);
  572. this._aniVersion = reader.readUTFString();
  573. AnimationParser01.parse(this, reader);
  574. }
  575. _calculateKeyFrame(node, keyframeCount, keyframeDataCount) {
  576. var keyFrames = node.keyFrame;
  577. keyFrames[keyframeCount] = keyFrames[0];
  578. for (var i = 0; i < keyframeCount; i++) {
  579. var keyFrame = keyFrames[i];
  580. for (var j = 0; j < keyframeDataCount; j++) {
  581. keyFrame.dData[j] = (keyFrame.duration === 0) ? 0 : (keyFrames[i + 1].data[j] - keyFrame.data[j]) / keyFrame.duration;
  582. keyFrame.nextData[j] = keyFrames[i + 1].data[j];
  583. }
  584. }
  585. keyFrames.length--;
  586. }
  587. _onAsynLoaded(data, propertyParams = null) {
  588. var reader = new Laya.Byte(data);
  589. this._aniVersion = reader.readUTFString();
  590. switch (this._aniVersion) {
  591. case "LAYAANIMATION:02":
  592. AnimationParser02.parse(this, reader);
  593. break;
  594. default:
  595. AnimationParser01.parse(this, reader);
  596. }
  597. }
  598. getAnimationCount() {
  599. return this._anis.length;
  600. }
  601. getAnimation(aniIndex) {
  602. return this._anis[aniIndex];
  603. }
  604. getAniDuration(aniIndex) {
  605. return this._anis[aniIndex].playTime;
  606. }
  607. getNodes(aniIndex) {
  608. return this._anis[aniIndex].nodes;
  609. }
  610. getNodeIndexWithName(aniIndex, name) {
  611. return this._anis[aniIndex].bone3DMap[name];
  612. }
  613. getNodeCount(aniIndex) {
  614. return this._anis[aniIndex].nodes.length;
  615. }
  616. getTotalkeyframesLength(aniIndex) {
  617. return this._anis[aniIndex].totalKeyframeDatasLength;
  618. }
  619. getPublicExtData() {
  620. return this._publicExtData;
  621. }
  622. getAnimationDataWithCache(key, cacheDatas, aniIndex, frameIndex) {
  623. var aniDatas = cacheDatas[aniIndex];
  624. if (!aniDatas) {
  625. return null;
  626. }
  627. else {
  628. var keyDatas = aniDatas[key];
  629. if (!keyDatas)
  630. return null;
  631. else {
  632. return keyDatas[frameIndex];
  633. }
  634. }
  635. }
  636. setAnimationDataWithCache(key, cacheDatas, aniIndex, frameIndex, data) {
  637. var aniDatas = (cacheDatas[aniIndex]) || (cacheDatas[aniIndex] = {});
  638. var aniDatasCache = (aniDatas[key]) || (aniDatas[key] = []);
  639. aniDatasCache[frameIndex] = data;
  640. }
  641. getNodeKeyFrame(nodeframes, nodeid, tm) {
  642. var cid = this._boneCurKeyFrm[nodeid];
  643. var frmNum = nodeframes.length;
  644. if (cid == void 0 || cid >= frmNum) {
  645. cid = this._boneCurKeyFrm[nodeid] = 0;
  646. }
  647. var kinfo = nodeframes[cid];
  648. var curFrmTm = kinfo.startTime;
  649. var dt = tm - curFrmTm;
  650. if (dt == 0 || (dt > 0 && kinfo.duration > dt)) {
  651. return cid;
  652. }
  653. var i = 0;
  654. if (dt > 0) {
  655. tm = tm + 0.01;
  656. for (i = cid + 1; i < frmNum; i++) {
  657. kinfo = nodeframes[i];
  658. if (kinfo.startTime <= tm && kinfo.startTime + kinfo.duration > tm) {
  659. this._boneCurKeyFrm[nodeid] = i;
  660. return i;
  661. }
  662. }
  663. return frmNum - 1;
  664. }
  665. else {
  666. for (i = 0; i < cid; i++) {
  667. kinfo = nodeframes[i];
  668. if (kinfo.startTime <= tm && kinfo.startTime + kinfo.duration > tm) {
  669. this._boneCurKeyFrm[nodeid] = i;
  670. return i;
  671. }
  672. }
  673. return cid;
  674. }
  675. return 0;
  676. }
  677. getOriginalData(aniIndex, originalData, nodesFrameIndices, frameIndex, playCurTime) {
  678. var oneAni = this._anis[aniIndex];
  679. var nodes = oneAni.nodes;
  680. var curKFrm = this._boneCurKeyFrm;
  681. if (curKFrm.length < nodes.length) {
  682. curKFrm.length = nodes.length;
  683. }
  684. var j = 0;
  685. for (var i = 0, n = nodes.length, outOfs = 0; i < n; i++) {
  686. var node = nodes[i];
  687. var key;
  688. var kfrm = node.keyFrame;
  689. key = kfrm[this.getNodeKeyFrame(kfrm, i, playCurTime)];
  690. node.dataOffset = outOfs;
  691. var dt = playCurTime - key.startTime;
  692. var lerpType = node.lerpType;
  693. if (lerpType) {
  694. switch (lerpType) {
  695. case 0:
  696. case 1:
  697. for (j = 0; j < node.keyframeWidth;)
  698. j += node.interpolationMethod[j](node, j, originalData, outOfs + j, key.data, dt, key.dData, key.duration, key.nextData);
  699. break;
  700. case 2:
  701. var interpolationData = key.interpolationData;
  702. var interDataLen = interpolationData.length;
  703. var dataIndex = 0;
  704. for (j = 0; j < interDataLen;) {
  705. var type = interpolationData[j];
  706. switch (type) {
  707. case 6:
  708. j += AnimationTemplet.interpolation[type](node, dataIndex, originalData, outOfs + dataIndex, key.data, dt, key.dData, key.duration, key.nextData, interpolationData, j + 1);
  709. break;
  710. case 7:
  711. j += AnimationTemplet.interpolation[type](node, dataIndex, originalData, outOfs + dataIndex, key.data, dt, key.dData, key.duration, key.nextData, interpolationData, j + 1);
  712. break;
  713. default:
  714. j += AnimationTemplet.interpolation[type](node, dataIndex, originalData, outOfs + dataIndex, key.data, dt, key.dData, key.duration, key.nextData);
  715. }
  716. dataIndex++;
  717. }
  718. break;
  719. }
  720. }
  721. else {
  722. for (j = 0; j < node.keyframeWidth;)
  723. j += node.interpolationMethod[j](node, j, originalData, outOfs + j, key.data, dt, key.dData, key.duration, key.nextData);
  724. }
  725. outOfs += node.keyframeWidth;
  726. }
  727. }
  728. getNodesCurrentFrameIndex(aniIndex, playCurTime) {
  729. var ani = this._anis[aniIndex];
  730. var nodes = ani.nodes;
  731. if (aniIndex !== this.unfixedLastAniIndex) {
  732. this.unfixedCurrentFrameIndexes = new Uint32Array(nodes.length);
  733. this.unfixedCurrentTimes = new Float32Array(nodes.length);
  734. this.unfixedLastAniIndex = aniIndex;
  735. }
  736. for (var i = 0, n = nodes.length; i < n; i++) {
  737. var node = nodes[i];
  738. if (playCurTime < this.unfixedCurrentTimes[i])
  739. this.unfixedCurrentFrameIndexes[i] = 0;
  740. this.unfixedCurrentTimes[i] = playCurTime;
  741. while ((this.unfixedCurrentFrameIndexes[i] < node.keyFrame.length)) {
  742. if (node.keyFrame[this.unfixedCurrentFrameIndexes[i]].startTime > this.unfixedCurrentTimes[i])
  743. break;
  744. this.unfixedCurrentFrameIndexes[i]++;
  745. }
  746. this.unfixedCurrentFrameIndexes[i]--;
  747. }
  748. return this.unfixedCurrentFrameIndexes;
  749. }
  750. getOriginalDataUnfixedRate(aniIndex, originalData, playCurTime) {
  751. var oneAni = this._anis[aniIndex];
  752. var nodes = oneAni.nodes;
  753. if (aniIndex !== this.unfixedLastAniIndex) {
  754. this.unfixedCurrentFrameIndexes = new Uint32Array(nodes.length);
  755. this.unfixedCurrentTimes = new Float32Array(nodes.length);
  756. this.unfixedKeyframes = [];
  757. this.unfixedLastAniIndex = aniIndex;
  758. }
  759. var j = 0;
  760. for (var i = 0, n = nodes.length, outOfs = 0; i < n; i++) {
  761. var node = nodes[i];
  762. if (playCurTime < this.unfixedCurrentTimes[i])
  763. this.unfixedCurrentFrameIndexes[i] = 0;
  764. this.unfixedCurrentTimes[i] = playCurTime;
  765. while (this.unfixedCurrentFrameIndexes[i] < node.keyFrame.length) {
  766. if (node.keyFrame[this.unfixedCurrentFrameIndexes[i]].startTime > this.unfixedCurrentTimes[i])
  767. break;
  768. this.unfixedKeyframes[i] = node.keyFrame[this.unfixedCurrentFrameIndexes[i]];
  769. this.unfixedCurrentFrameIndexes[i]++;
  770. }
  771. var key = this.unfixedKeyframes[i];
  772. node.dataOffset = outOfs;
  773. var dt = playCurTime - key.startTime;
  774. var lerpType = node.lerpType;
  775. if (lerpType) {
  776. switch (node.lerpType) {
  777. case 0:
  778. case 1:
  779. for (j = 0; j < node.keyframeWidth;)
  780. j += node.interpolationMethod[j](node, j, originalData, outOfs + j, key.data, dt, key.dData, key.duration, key.nextData);
  781. break;
  782. case 2:
  783. var interpolationData = key.interpolationData;
  784. var interDataLen = interpolationData.length;
  785. var dataIndex = 0;
  786. for (j = 0; j < interDataLen;) {
  787. var type = interpolationData[j];
  788. switch (type) {
  789. case 6:
  790. j += AnimationTemplet.interpolation[type](node, dataIndex, originalData, outOfs + dataIndex, key.data, dt, key.dData, key.duration, key.nextData, interpolationData, j + 1);
  791. break;
  792. case 7:
  793. j += AnimationTemplet.interpolation[type](node, dataIndex, originalData, outOfs + dataIndex, key.data, dt, key.dData, key.duration, key.nextData, interpolationData, j + 1);
  794. break;
  795. default:
  796. j += AnimationTemplet.interpolation[type](node, dataIndex, originalData, outOfs + dataIndex, key.data, dt, key.dData, key.duration, key.nextData);
  797. }
  798. dataIndex++;
  799. }
  800. break;
  801. }
  802. }
  803. else {
  804. for (j = 0; j < node.keyframeWidth;)
  805. j += node.interpolationMethod[j](node, j, originalData, outOfs + j, key.data, dt, key.dData, key.duration, key.nextData);
  806. }
  807. outOfs += node.keyframeWidth;
  808. }
  809. }
  810. }
  811. 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];
  812. IAniLib.AnimationTemplet = AnimationTemplet;
  813. class GraphicsAni extends Laya.Graphics {
  814. drawSkin(skinA, alpha) {
  815. this.drawTriangles(skinA.texture, 0, 0, skinA.vertices, skinA.uvs, skinA.indexes, skinA.transform || Laya.Matrix.EMPTY, alpha);
  816. }
  817. static create() {
  818. var rs = GraphicsAni._caches.pop();
  819. return rs || new GraphicsAni();
  820. }
  821. static recycle(graphics) {
  822. graphics.clear();
  823. GraphicsAni._caches.push(graphics);
  824. }
  825. }
  826. GraphicsAni._caches = [];
  827. class Transform {
  828. constructor() {
  829. this.skX = 0;
  830. this.skY = 0;
  831. this.scX = 1;
  832. this.scY = 1;
  833. this.x = 0;
  834. this.y = 0;
  835. this.skewX = 0;
  836. this.skewY = 0;
  837. }
  838. initData(data) {
  839. if (data.x != undefined) {
  840. this.x = data.x;
  841. }
  842. if (data.y != undefined) {
  843. this.y = data.y;
  844. }
  845. if (data.skX != undefined) {
  846. this.skX = data.skX;
  847. }
  848. if (data.skY != undefined) {
  849. this.skY = data.skY;
  850. }
  851. if (data.scX != undefined) {
  852. this.scX = data.scX;
  853. }
  854. if (data.scY != undefined) {
  855. this.scY = data.scY;
  856. }
  857. }
  858. getMatrix() {
  859. var tMatrix;
  860. if (this.mMatrix) {
  861. tMatrix = this.mMatrix;
  862. }
  863. else {
  864. tMatrix = this.mMatrix = new Laya.Matrix();
  865. }
  866. tMatrix.identity();
  867. tMatrix.scale(this.scX, this.scY);
  868. if (this.skewX || this.skewY) {
  869. this.skew(tMatrix, this.skewX * Math.PI / 180, this.skewY * Math.PI / 180);
  870. }
  871. tMatrix.rotate(this.skX * Math.PI / 180);
  872. tMatrix.translate(this.x, this.y);
  873. return tMatrix;
  874. }
  875. skew(m, x, y) {
  876. var sinX = Math.sin(y);
  877. var cosX = Math.cos(y);
  878. var sinY = Math.sin(x);
  879. var cosY = Math.cos(x);
  880. m.setTo(m.a * cosY - m.b * sinX, m.a * sinY + m.b * cosX, m.c * cosY - m.d * sinX, m.c * sinY + m.d * cosX, m.tx * cosY - m.ty * sinX, m.tx * sinY + m.ty * cosX);
  881. return m;
  882. }
  883. }
  884. class Bone {
  885. constructor() {
  886. this.length = 10;
  887. this.resultTransform = new Transform();
  888. this.resultMatrix = new Laya.Matrix();
  889. this.inheritScale = true;
  890. this.inheritRotation = true;
  891. this.d = -1;
  892. this._children = [];
  893. }
  894. setTempMatrix(matrix) {
  895. this._tempMatrix = matrix;
  896. var i = 0, n = 0;
  897. var tBone;
  898. for (i = 0, n = this._children.length; i < n; i++) {
  899. tBone = this._children[i];
  900. tBone.setTempMatrix(this._tempMatrix);
  901. }
  902. }
  903. update(pMatrix = null) {
  904. this.rotation = this.transform.skX;
  905. var tResultMatrix;
  906. if (pMatrix) {
  907. tResultMatrix = this.resultTransform.getMatrix();
  908. Laya.Matrix.mul(tResultMatrix, pMatrix, this.resultMatrix);
  909. this.resultRotation = this.rotation;
  910. }
  911. else {
  912. this.resultRotation = this.rotation + this.parentBone.resultRotation;
  913. if (this.parentBone) {
  914. if (this.inheritRotation && this.inheritScale) {
  915. tResultMatrix = this.resultTransform.getMatrix();
  916. Laya.Matrix.mul(tResultMatrix, this.parentBone.resultMatrix, this.resultMatrix);
  917. }
  918. else {
  919. var parent = this.parentBone;
  920. var tAngle;
  921. var cos;
  922. var sin;
  923. var tParentMatrix = this.parentBone.resultMatrix;
  924. tResultMatrix = this.resultTransform.getMatrix();
  925. var worldX = tParentMatrix.a * tResultMatrix.tx + tParentMatrix.c * tResultMatrix.ty + tParentMatrix.tx;
  926. var worldY = tParentMatrix.b * tResultMatrix.tx + tParentMatrix.d * tResultMatrix.ty + tParentMatrix.ty;
  927. var tTestMatrix = new Laya.Matrix();
  928. if (this.inheritRotation) {
  929. tAngle = Math.atan2(parent.resultMatrix.b, parent.resultMatrix.a);
  930. cos = Math.cos(tAngle), sin = Math.sin(tAngle);
  931. tTestMatrix.setTo(cos, sin, -sin, cos, 0, 0);
  932. Laya.Matrix.mul(this._tempMatrix, tTestMatrix, Laya.Matrix.TEMP);
  933. Laya.Matrix.TEMP.copyTo(tTestMatrix);
  934. tResultMatrix = this.resultTransform.getMatrix();
  935. Laya.Matrix.mul(tResultMatrix, tTestMatrix, this.resultMatrix);
  936. if (this.resultTransform.scX * this.resultTransform.scY < 0) {
  937. this.resultMatrix.rotate(Math.PI * 0.5);
  938. }
  939. this.resultMatrix.tx = worldX;
  940. this.resultMatrix.ty = worldY;
  941. }
  942. else if (this.inheritScale) {
  943. tResultMatrix = this.resultTransform.getMatrix();
  944. Laya.Matrix.TEMP.identity();
  945. Laya.Matrix.TEMP.d = this.d;
  946. Laya.Matrix.mul(tResultMatrix, Laya.Matrix.TEMP, this.resultMatrix);
  947. this.resultMatrix.tx = worldX;
  948. this.resultMatrix.ty = worldY;
  949. }
  950. else {
  951. tResultMatrix = this.resultTransform.getMatrix();
  952. Laya.Matrix.TEMP.identity();
  953. Laya.Matrix.TEMP.d = this.d;
  954. Laya.Matrix.mul(tResultMatrix, Laya.Matrix.TEMP, this.resultMatrix);
  955. this.resultMatrix.tx = worldX;
  956. this.resultMatrix.ty = worldY;
  957. }
  958. }
  959. }
  960. else {
  961. tResultMatrix = this.resultTransform.getMatrix();
  962. tResultMatrix.copyTo(this.resultMatrix);
  963. }
  964. }
  965. var i = 0, n = 0;
  966. var tBone;
  967. for (i = 0, n = this._children.length; i < n; i++) {
  968. tBone = this._children[i];
  969. tBone.update();
  970. }
  971. }
  972. updateChild() {
  973. var i = 0, n = 0;
  974. var tBone;
  975. for (i = 0, n = this._children.length; i < n; i++) {
  976. tBone = this._children[i];
  977. tBone.update();
  978. }
  979. }
  980. setRotation(rd) {
  981. if (this._sprite) {
  982. this._sprite.rotation = rd * 180 / Math.PI;
  983. }
  984. }
  985. updateDraw(x, y) {
  986. if (!Bone.ShowBones || Bone.ShowBones[this.name]) {
  987. if (this._sprite) {
  988. this._sprite.x = x + this.resultMatrix.tx;
  989. this._sprite.y = y + this.resultMatrix.ty;
  990. }
  991. else {
  992. this._sprite = new Laya.Sprite();
  993. this._sprite.graphics.drawCircle(0, 0, 5, "#ff0000");
  994. this._sprite.graphics.drawLine(0, 0, this.length, 0, "#00ff00");
  995. this._sprite.graphics.fillText(this.name, 0, 0, "20px Arial", "#00ff00", "center");
  996. Laya.ILaya.stage.addChild(this._sprite);
  997. this._sprite.x = x + this.resultMatrix.tx;
  998. this._sprite.y = y + this.resultMatrix.ty;
  999. }
  1000. }
  1001. var i = 0, n = 0;
  1002. var tBone;
  1003. for (i = 0, n = this._children.length; i < n; i++) {
  1004. tBone = this._children[i];
  1005. tBone.updateDraw(x, y);
  1006. }
  1007. }
  1008. addChild(bone) {
  1009. this._children.push(bone);
  1010. bone.parentBone = this;
  1011. }
  1012. findBone(boneName) {
  1013. if (this.name == boneName) {
  1014. return this;
  1015. }
  1016. else {
  1017. var i, n;
  1018. var tBone;
  1019. var tResult;
  1020. for (i = 0, n = this._children.length; i < n; i++) {
  1021. tBone = this._children[i];
  1022. tResult = tBone.findBone(boneName);
  1023. if (tResult) {
  1024. return tResult;
  1025. }
  1026. }
  1027. }
  1028. return null;
  1029. }
  1030. localToWorld(local) {
  1031. var localX = local[0];
  1032. var localY = local[1];
  1033. local[0] = localX * this.resultMatrix.a + localY * this.resultMatrix.c + this.resultMatrix.tx;
  1034. local[1] = localX * this.resultMatrix.b + localY * this.resultMatrix.d + this.resultMatrix.ty;
  1035. }
  1036. }
  1037. Bone.ShowBones = {};
  1038. class UVTools {
  1039. constructor() {
  1040. }
  1041. static getRelativeUV(bigUV, smallUV, rst = null) {
  1042. var startX = bigUV[0];
  1043. var width = bigUV[2] - bigUV[0];
  1044. var startY = bigUV[1];
  1045. var height = bigUV[5] - bigUV[1];
  1046. if (!rst)
  1047. rst = [];
  1048. rst.length = smallUV.length;
  1049. var i, len;
  1050. len = rst.length;
  1051. var dWidth = 1 / width;
  1052. var dHeight = 1 / height;
  1053. for (i = 0; i < len; i += 2) {
  1054. rst[i] = (smallUV[i] - startX) * dWidth;
  1055. rst[i + 1] = (smallUV[i + 1] - startY) * dHeight;
  1056. }
  1057. return rst;
  1058. }
  1059. static getAbsoluteUV(bigUV, smallUV, rst = null) {
  1060. if (bigUV[0] == 0 && bigUV[1] == 0 && bigUV[4] == 1 && bigUV[5] == 1) {
  1061. if (rst) {
  1062. Laya.Utils.copyArray(rst, smallUV);
  1063. return rst;
  1064. }
  1065. else {
  1066. return smallUV;
  1067. }
  1068. }
  1069. var startX = bigUV[0];
  1070. var width = bigUV[2] - bigUV[0];
  1071. var startY = bigUV[1];
  1072. var height = bigUV[5] - bigUV[1];
  1073. if (!rst)
  1074. rst = [];
  1075. rst.length = smallUV.length;
  1076. var i, len;
  1077. len = rst.length;
  1078. for (i = 0; i < len; i += 2) {
  1079. rst[i] = smallUV[i] * width + startX;
  1080. rst[i + 1] = smallUV[i + 1] * height + startY;
  1081. }
  1082. return rst;
  1083. }
  1084. }
  1085. class MeshData {
  1086. constructor() {
  1087. this.uvs = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]);
  1088. this.vertices = new Float32Array([0, 0, 100, 0, 100, 100, 0, 100]);
  1089. this.indexes = new Uint16Array([0, 1, 3, 3, 1, 2]);
  1090. this.useUvTransform = false;
  1091. this.canvasPadding = 1;
  1092. }
  1093. getBounds() {
  1094. return Laya.Rectangle._getWrapRec(this.vertices);
  1095. }
  1096. }
  1097. class SkinMeshForGraphic extends MeshData {
  1098. constructor() {
  1099. super();
  1100. }
  1101. init2(texture, ps, verticles, uvs) {
  1102. if (this.transform) {
  1103. this.transform = null;
  1104. }
  1105. var _ps = ps || [0, 1, 3, 3, 1, 2];
  1106. this.texture = texture;
  1107. this.indexes = new Uint16Array(_ps);
  1108. this.vertices = new Float32Array(verticles);
  1109. this.uvs = new Float32Array(uvs);
  1110. }
  1111. }
  1112. class BoneSlot {
  1113. constructor() {
  1114. this.srcDisplayIndex = -1;
  1115. this.type = "src";
  1116. this.displayIndex = -1;
  1117. this.originalIndex = -1;
  1118. this._replaceDic = {};
  1119. }
  1120. showSlotData(slotData, freshIndex = true) {
  1121. this.currSlotData = slotData;
  1122. if (freshIndex)
  1123. this.displayIndex = this.srcDisplayIndex;
  1124. this.currDisplayData = null;
  1125. this.currTexture = null;
  1126. }
  1127. showDisplayByName(name) {
  1128. if (this.currSlotData) {
  1129. this.showDisplayByIndex(this.currSlotData.getDisplayByName(name));
  1130. }
  1131. }
  1132. replaceDisplayByName(tarName, newName) {
  1133. if (!this.currSlotData)
  1134. return;
  1135. var preIndex;
  1136. preIndex = this.currSlotData.getDisplayByName(tarName);
  1137. var newIndex;
  1138. newIndex = this.currSlotData.getDisplayByName(newName);
  1139. this.replaceDisplayByIndex(preIndex, newIndex);
  1140. }
  1141. replaceDisplayByIndex(tarIndex, newIndex) {
  1142. if (!this.currSlotData)
  1143. return;
  1144. this._replaceDic[tarIndex] = newIndex;
  1145. if (this.originalIndex == tarIndex) {
  1146. this.showDisplayByIndex(tarIndex);
  1147. }
  1148. }
  1149. showDisplayByIndex(index) {
  1150. this.originalIndex = index;
  1151. if (this._replaceDic[index] != null)
  1152. index = this._replaceDic[index];
  1153. if (this.currSlotData && index > -1 && index < this.currSlotData.displayArr.length) {
  1154. this.displayIndex = index;
  1155. this.currDisplayData = this.currSlotData.displayArr[index];
  1156. if (this.currDisplayData) {
  1157. var tName = this.currDisplayData.name;
  1158. this.currTexture = this.templet.getTexture(tName);
  1159. if (this.currTexture && this.currDisplayData.type == 0 && this.currDisplayData.uvs) {
  1160. this.currTexture = this.currDisplayData.createTexture(this.currTexture);
  1161. }
  1162. }
  1163. }
  1164. else {
  1165. this.displayIndex = -1;
  1166. this.currDisplayData = null;
  1167. this.currTexture = null;
  1168. }
  1169. }
  1170. replaceSkin(_texture) {
  1171. this._diyTexture = _texture;
  1172. if (this._curDiyUV)
  1173. this._curDiyUV.length = 0;
  1174. if (this.currDisplayData && this._diyTexture == this.currDisplayData.texture) {
  1175. this._diyTexture = null;
  1176. }
  1177. }
  1178. setParentMatrix(parentMatrix) {
  1179. this._parentMatrix = parentMatrix;
  1180. }
  1181. static createSkinMesh() {
  1182. return new SkinMeshForGraphic();
  1183. }
  1184. static isSameArr(arrA, arrB) {
  1185. if (arrA.length != arrB.length)
  1186. return false;
  1187. var i, len;
  1188. len = arrA.length;
  1189. for (i = 0; i < len; i++) {
  1190. if (arrA[i] != arrB[i])
  1191. return false;
  1192. }
  1193. return true;
  1194. }
  1195. getSaveVerticle(tArr) {
  1196. if (BoneSlot.useSameMatrixAndVerticle && this._preGraphicVerticle && BoneSlot.isSameArr(tArr, this._preGraphicVerticle)) {
  1197. tArr = this._preGraphicVerticle;
  1198. }
  1199. else {
  1200. tArr = Laya.ILaya.Utils.copyArray([], tArr);
  1201. this._preGraphicVerticle = tArr;
  1202. }
  1203. return tArr;
  1204. }
  1205. static isSameMatrix(mtA, mtB) {
  1206. 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;
  1207. }
  1208. getSaveMatrix(tResultMatrix) {
  1209. if (BoneSlot.useSameMatrixAndVerticle && this._preGraphicMatrix && BoneSlot.isSameMatrix(tResultMatrix, this._preGraphicMatrix)) {
  1210. tResultMatrix = this._preGraphicMatrix;
  1211. }
  1212. else {
  1213. var newMatrix = tResultMatrix.clone();
  1214. tResultMatrix = newMatrix;
  1215. this._preGraphicMatrix = tResultMatrix;
  1216. }
  1217. return tResultMatrix;
  1218. }
  1219. draw(graphics, boneMatrixArray, noUseSave = false, alpha = 1) {
  1220. if ((this._diyTexture == null && this.currTexture == null) || this.currDisplayData == null) {
  1221. if (!(this.currDisplayData && this.currDisplayData.type == 3)) {
  1222. return;
  1223. }
  1224. }
  1225. var tTexture = this.currTexture;
  1226. if (this._diyTexture)
  1227. tTexture = this._diyTexture;
  1228. var tSkinSprite;
  1229. switch (this.currDisplayData.type) {
  1230. case 0:
  1231. if (graphics) {
  1232. var tCurrentMatrix = this.getDisplayMatrix();
  1233. if (this._parentMatrix) {
  1234. var tRotateKey = false;
  1235. if (tCurrentMatrix) {
  1236. Laya.Matrix.mul(tCurrentMatrix, this._parentMatrix, Laya.Matrix.TEMP);
  1237. var tResultMatrix;
  1238. if (noUseSave) {
  1239. if (this._resultMatrix == null)
  1240. this._resultMatrix = new Laya.Matrix();
  1241. tResultMatrix = this._resultMatrix;
  1242. }
  1243. else {
  1244. tResultMatrix = BoneSlot._tempResultMatrix;
  1245. }
  1246. if (this._diyTexture && this.currDisplayData.uvs) {
  1247. var tTestMatrix = BoneSlot._tempMatrix;
  1248. tTestMatrix.identity();
  1249. if (this.currDisplayData.uvs[1] > this.currDisplayData.uvs[5]) {
  1250. tTestMatrix.d = -1;
  1251. }
  1252. if (this.currDisplayData.uvs[0] > this.currDisplayData.uvs[4]
  1253. && this.currDisplayData.uvs[1] > this.currDisplayData.uvs[5]) {
  1254. tRotateKey = true;
  1255. tTestMatrix.rotate(-Math.PI / 2);
  1256. }
  1257. Laya.Matrix.mul(tTestMatrix, Laya.Matrix.TEMP, tResultMatrix);
  1258. }
  1259. else {
  1260. Laya.Matrix.TEMP.copyTo(tResultMatrix);
  1261. }
  1262. if (!noUseSave) {
  1263. tResultMatrix = this.getSaveMatrix(tResultMatrix);
  1264. }
  1265. tResultMatrix._checkTransform();
  1266. if (tRotateKey) {
  1267. graphics.drawTexture(tTexture, -this.currDisplayData.height / 2, -this.currDisplayData.width / 2, this.currDisplayData.height, this.currDisplayData.width, tResultMatrix, alpha);
  1268. }
  1269. else {
  1270. graphics.drawTexture(tTexture, -this.currDisplayData.width / 2, -this.currDisplayData.height / 2, this.currDisplayData.width, this.currDisplayData.height, tResultMatrix, alpha);
  1271. }
  1272. }
  1273. }
  1274. }
  1275. break;
  1276. case 1:
  1277. if (noUseSave) {
  1278. if (this._skinSprite == null) {
  1279. this._skinSprite = BoneSlot.createSkinMesh();
  1280. }
  1281. tSkinSprite = this._skinSprite;
  1282. }
  1283. else {
  1284. tSkinSprite = BoneSlot.createSkinMesh();
  1285. }
  1286. if (tSkinSprite == null) {
  1287. return;
  1288. }
  1289. var tIBArray;
  1290. if (this.currDisplayData.bones == null) {
  1291. var tVertices = this.currDisplayData.weights;
  1292. if (this.deformData) {
  1293. tVertices = this.deformData;
  1294. }
  1295. var tUVs;
  1296. if (this._diyTexture) {
  1297. if (!this._curDiyUV) {
  1298. this._curDiyUV = [];
  1299. }
  1300. if (this._curDiyUV.length == 0) {
  1301. this._curDiyUV = UVTools.getRelativeUV(this.currTexture.uv, this.currDisplayData.uvs, this._curDiyUV);
  1302. this._curDiyUV = UVTools.getAbsoluteUV(this._diyTexture.uv, this._curDiyUV, this._curDiyUV);
  1303. }
  1304. tUVs = this._curDiyUV;
  1305. }
  1306. else {
  1307. tUVs = this.currDisplayData.uvs;
  1308. }
  1309. this._mVerticleArr = tVertices;
  1310. var tTriangleNum = this.currDisplayData.triangles.length / 3;
  1311. tIBArray = this.currDisplayData.triangles;
  1312. if (this.deformData) {
  1313. if (!noUseSave) {
  1314. this._mVerticleArr = this.getSaveVerticle(this._mVerticleArr);
  1315. }
  1316. }
  1317. tSkinSprite.init2(tTexture, tIBArray, this._mVerticleArr, tUVs);
  1318. var tCurrentMatrix2 = this.getDisplayMatrix();
  1319. if (this._parentMatrix) {
  1320. if (tCurrentMatrix2) {
  1321. Laya.Matrix.mul(tCurrentMatrix2, this._parentMatrix, Laya.Matrix.TEMP);
  1322. var tResultMatrix2;
  1323. if (noUseSave) {
  1324. if (this._resultMatrix == null)
  1325. this._resultMatrix = new Laya.Matrix();
  1326. tResultMatrix2 = this._resultMatrix;
  1327. }
  1328. else {
  1329. tResultMatrix2 = BoneSlot._tempResultMatrix;
  1330. }
  1331. Laya.Matrix.TEMP.copyTo(tResultMatrix2);
  1332. if (!noUseSave) {
  1333. tResultMatrix2 = this.getSaveMatrix(tResultMatrix2);
  1334. }
  1335. tSkinSprite.transform = tResultMatrix2;
  1336. }
  1337. }
  1338. }
  1339. else {
  1340. this.skinMesh(boneMatrixArray, tSkinSprite);
  1341. }
  1342. graphics.drawSkin(tSkinSprite, alpha);
  1343. break;
  1344. case 2:
  1345. if (noUseSave) {
  1346. if (this._skinSprite == null) {
  1347. this._skinSprite = BoneSlot.createSkinMesh();
  1348. }
  1349. tSkinSprite = this._skinSprite;
  1350. }
  1351. else {
  1352. tSkinSprite = BoneSlot.createSkinMesh();
  1353. }
  1354. if (tSkinSprite == null) {
  1355. return;
  1356. }
  1357. this.skinMesh(boneMatrixArray, tSkinSprite);
  1358. graphics.drawSkin(tSkinSprite, alpha);
  1359. break;
  1360. case 3:
  1361. break;
  1362. }
  1363. }
  1364. skinMesh(boneMatrixArray, skinSprite) {
  1365. var tTexture = this.currTexture;
  1366. var tBones = this.currDisplayData.bones;
  1367. var tUvs;
  1368. if (this._diyTexture) {
  1369. tTexture = this._diyTexture;
  1370. if (!this._curDiyUV) {
  1371. this._curDiyUV = [];
  1372. }
  1373. if (this._curDiyUV.length == 0) {
  1374. this._curDiyUV = UVTools.getRelativeUV(this.currTexture.uv, this.currDisplayData.uvs, this._curDiyUV);
  1375. this._curDiyUV = UVTools.getAbsoluteUV(this._diyTexture.uv, this._curDiyUV, this._curDiyUV);
  1376. }
  1377. tUvs = this._curDiyUV;
  1378. }
  1379. else {
  1380. tUvs = this.currDisplayData.uvs;
  1381. }
  1382. var tWeights = this.currDisplayData.weights;
  1383. var tTriangles = this.currDisplayData.triangles;
  1384. var tIBArray;
  1385. var tRx = 0;
  1386. var tRy = 0;
  1387. var nn = 0;
  1388. var tMatrix;
  1389. var tX;
  1390. var tY;
  1391. var tB = 0;
  1392. var tWeight = 0;
  1393. var tVertices;
  1394. var i = 0, n = 0;
  1395. BoneSlot._tempVerticleArr.length = 0;
  1396. tVertices = BoneSlot._tempVerticleArr;
  1397. if (this.deformData && this.deformData.length > 0) {
  1398. var f = 0;
  1399. for (i = 0, n = tBones.length; i < n;) {
  1400. nn = tBones[i++] + i;
  1401. tRx = 0, tRy = 0;
  1402. for (; i < nn; i++) {
  1403. tMatrix = boneMatrixArray[tBones[i]];
  1404. tX = tWeights[tB] + this.deformData[f++];
  1405. tY = tWeights[tB + 1] + this.deformData[f++];
  1406. tWeight = tWeights[tB + 2];
  1407. tRx += (tX * tMatrix.a + tY * tMatrix.c + tMatrix.tx) * tWeight;
  1408. tRy += (tX * tMatrix.b + tY * tMatrix.d + tMatrix.ty) * tWeight;
  1409. tB += 3;
  1410. }
  1411. tVertices.push(tRx, tRy);
  1412. }
  1413. }
  1414. else {
  1415. for (i = 0, n = tBones.length; i < n;) {
  1416. nn = tBones[i++] + i;
  1417. tRx = 0, tRy = 0;
  1418. for (; i < nn; i++) {
  1419. tMatrix = boneMatrixArray[tBones[i]];
  1420. tX = tWeights[tB];
  1421. tY = tWeights[tB + 1];
  1422. tWeight = tWeights[tB + 2];
  1423. tRx += (tX * tMatrix.a + tY * tMatrix.c + tMatrix.tx) * tWeight;
  1424. tRy += (tX * tMatrix.b + tY * tMatrix.d + tMatrix.ty) * tWeight;
  1425. tB += 3;
  1426. }
  1427. tVertices.push(tRx, tRy);
  1428. }
  1429. }
  1430. this._mVerticleArr = tVertices;
  1431. tIBArray = tTriangles;
  1432. this._mVerticleArr = this.getSaveVerticle(this._mVerticleArr);
  1433. skinSprite.init2(tTexture, tIBArray, this._mVerticleArr, tUvs);
  1434. }
  1435. drawBonePoint(graphics) {
  1436. if (graphics && this._parentMatrix) {
  1437. graphics.drawCircle(this._parentMatrix.tx, this._parentMatrix.ty, 5, "#ff0000");
  1438. }
  1439. }
  1440. getDisplayMatrix() {
  1441. if (this.currDisplayData) {
  1442. return this.currDisplayData.transform.getMatrix();
  1443. }
  1444. return null;
  1445. }
  1446. getMatrix() {
  1447. return this._resultMatrix;
  1448. }
  1449. copy() {
  1450. var tBoneSlot = new BoneSlot();
  1451. tBoneSlot.type = "copy";
  1452. tBoneSlot.name = this.name;
  1453. tBoneSlot.attachmentName = this.attachmentName;
  1454. tBoneSlot.srcDisplayIndex = this.srcDisplayIndex;
  1455. tBoneSlot.parent = this.parent;
  1456. tBoneSlot.displayIndex = this.displayIndex;
  1457. tBoneSlot.templet = this.templet;
  1458. tBoneSlot.currSlotData = this.currSlotData;
  1459. tBoneSlot.currTexture = this.currTexture;
  1460. tBoneSlot.currDisplayData = this.currDisplayData;
  1461. return tBoneSlot;
  1462. }
  1463. }
  1464. BoneSlot._tempMatrix = new Laya.Matrix();
  1465. BoneSlot._tempResultMatrix = new Laya.Matrix();
  1466. BoneSlot.useSameMatrixAndVerticle = true;
  1467. BoneSlot._tempVerticleArr = [];
  1468. class DeformAniData {
  1469. constructor() {
  1470. this.deformSlotDataList = [];
  1471. }
  1472. }
  1473. class DeformSlotData {
  1474. constructor() {
  1475. this.deformSlotDisplayList = [];
  1476. }
  1477. }
  1478. class DeformSlotDisplayData {
  1479. constructor() {
  1480. this.slotIndex = -1;
  1481. this.timeList = [];
  1482. this.vectices = [];
  1483. this.tweenKeyList = [];
  1484. this.frameIndex = 0;
  1485. }
  1486. binarySearch1(values, target) {
  1487. var low = 0;
  1488. var high = values.length - 2;
  1489. if (high == 0)
  1490. return 1;
  1491. var current = high >>> 1;
  1492. while (true) {
  1493. if (values[Math.floor(current + 1)] <= target)
  1494. low = current + 1;
  1495. else
  1496. high = current;
  1497. if (low == high)
  1498. return low + 1;
  1499. current = (low + high) >>> 1;
  1500. }
  1501. return 0;
  1502. }
  1503. apply(time, boneSlot, alpha = 1) {
  1504. time += 0.05;
  1505. if (this.timeList.length <= 0) {
  1506. return;
  1507. }
  1508. var i = 0;
  1509. var tTime = this.timeList[0];
  1510. if (time < tTime) {
  1511. return;
  1512. }
  1513. var tVertexCount = this.vectices[0].length;
  1514. var tVertices = [];
  1515. var tFrameIndex = this.binarySearch1(this.timeList, time);
  1516. this.frameIndex = tFrameIndex;
  1517. if (time >= this.timeList[this.timeList.length - 1]) {
  1518. var lastVertices = this.vectices[this.vectices.length - 1];
  1519. if (alpha < 1) {
  1520. for (i = 0; i < tVertexCount; i++) {
  1521. tVertices[i] += (lastVertices[i] - tVertices[i]) * alpha;
  1522. }
  1523. }
  1524. else {
  1525. for (i = 0; i < tVertexCount; i++) {
  1526. tVertices[i] = lastVertices[i];
  1527. }
  1528. }
  1529. this.deformData = tVertices;
  1530. return;
  1531. }
  1532. var tPrevVertices = this.vectices[this.frameIndex - 1];
  1533. var tNextVertices = this.vectices[this.frameIndex];
  1534. var tPreFrameTime = this.timeList[this.frameIndex - 1];
  1535. var tFrameTime = this.timeList[this.frameIndex];
  1536. if (this.tweenKeyList[tFrameIndex - 1]) {
  1537. alpha = (time - tPreFrameTime) / (tFrameTime - tPreFrameTime);
  1538. }
  1539. else {
  1540. alpha = 0;
  1541. }
  1542. var tPrev;
  1543. for (i = 0; i < tVertexCount; i++) {
  1544. tPrev = tPrevVertices[i];
  1545. tVertices[i] = tPrev + (tNextVertices[i] - tPrev) * alpha;
  1546. }
  1547. this.deformData = tVertices;
  1548. }
  1549. }
  1550. class DrawOrderData {
  1551. constructor() {
  1552. this.drawOrder = [];
  1553. }
  1554. }
  1555. class EventData {
  1556. constructor() {
  1557. }
  1558. }
  1559. class IkConstraint {
  1560. constructor(data, bones) {
  1561. this.isSpine = true;
  1562. this.isDebug = false;
  1563. this._targetBone = bones[data.targetBoneIndex];
  1564. this.isSpine = data.isSpine;
  1565. if (this._bones == null)
  1566. this._bones = [];
  1567. this._bones.length = 0;
  1568. for (var i = 0, n = data.boneIndexs.length; i < n; i++) {
  1569. this._bones.push(bones[data.boneIndexs[i]]);
  1570. }
  1571. this.name = data.name;
  1572. this.mix = data.mix;
  1573. this.bendDirection = data.bendDirection;
  1574. }
  1575. apply() {
  1576. switch (this._bones.length) {
  1577. case 1:
  1578. this._applyIk1(this._bones[0], this._targetBone.resultMatrix.tx, this._targetBone.resultMatrix.ty, this.mix);
  1579. break;
  1580. case 2:
  1581. if (this.isSpine) {
  1582. this._applyIk2(this._bones[0], this._bones[1], this._targetBone.resultMatrix.tx, this._targetBone.resultMatrix.ty, this.bendDirection, this.mix);
  1583. }
  1584. else {
  1585. this._applyIk3(this._bones[0], this._bones[1], this._targetBone.resultMatrix.tx, this._targetBone.resultMatrix.ty, this.bendDirection, this.mix);
  1586. }
  1587. break;
  1588. }
  1589. }
  1590. _applyIk1(bone, targetX, targetY, alpha) {
  1591. var pp = bone.parentBone;
  1592. var id = 1 / (pp.resultMatrix.a * pp.resultMatrix.d - pp.resultMatrix.b * pp.resultMatrix.c);
  1593. var x = targetX - pp.resultMatrix.tx;
  1594. var y = targetY - pp.resultMatrix.ty;
  1595. var tx = (x * pp.resultMatrix.d - y * pp.resultMatrix.c) * id - bone.transform.x;
  1596. var ty = (y * pp.resultMatrix.a - x * pp.resultMatrix.b) * id - bone.transform.y;
  1597. var rotationIK = Math.atan2(ty, tx) * IkConstraint.radDeg - 0 - bone.transform.skX;
  1598. if (bone.transform.scX < 0)
  1599. rotationIK += 180;
  1600. if (rotationIK > 180)
  1601. rotationIK -= 360;
  1602. else if (rotationIK < -180)
  1603. rotationIK += 360;
  1604. bone.transform.skX = bone.transform.skY = bone.transform.skX + rotationIK * alpha;
  1605. bone.update();
  1606. }
  1607. updatePos(x, y) {
  1608. if (this._sp) {
  1609. this._sp.pos(x, y);
  1610. }
  1611. }
  1612. _applyIk2(parent, child, targetX, targetY, bendDir, alpha) {
  1613. if (alpha == 0) {
  1614. return;
  1615. }
  1616. var px = parent.resultTransform.x, py = parent.resultTransform.y;
  1617. var psx = parent.transform.scX, psy = parent.transform.scY;
  1618. var csx = child.transform.scX;
  1619. var os1, os2, s2;
  1620. if (psx < 0) {
  1621. psx = -psx;
  1622. os1 = 180;
  1623. s2 = -1;
  1624. }
  1625. else {
  1626. os1 = 0;
  1627. s2 = 1;
  1628. }
  1629. if (psy < 0) {
  1630. psy = -psy;
  1631. s2 = -s2;
  1632. }
  1633. if (csx < 0) {
  1634. csx = -csx;
  1635. os2 = 180;
  1636. }
  1637. else {
  1638. os2 = 0;
  1639. }
  1640. var cx = child.resultTransform.x, cy, cwx, cwy;
  1641. var a = parent.resultMatrix.a, b = parent.resultMatrix.c;
  1642. var c = parent.resultMatrix.b, d = parent.resultMatrix.d;
  1643. var u = Math.abs(psx - psy) <= 0.0001;
  1644. if (!u) {
  1645. cy = 0;
  1646. cwx = a * cx + parent.resultMatrix.tx;
  1647. cwy = c * cx + parent.resultMatrix.ty;
  1648. }
  1649. else {
  1650. cy = child.resultTransform.y;
  1651. cwx = a * cx + b * cy + parent.resultMatrix.tx;
  1652. cwy = c * cx + d * cy + parent.resultMatrix.ty;
  1653. }
  1654. if (this.isDebug) {
  1655. if (!this._sp) {
  1656. this._sp = new Laya.Sprite();
  1657. Laya.ILaya.stage.addChild(this._sp);
  1658. }
  1659. this._sp.graphics.clear();
  1660. this._sp.graphics.drawCircle(targetX, targetY, 15, "#ffff00");
  1661. this._sp.graphics.drawCircle(cwx, cwy, 15, "#ff00ff");
  1662. }
  1663. parent.setRotation(Math.atan2(cwy - parent.resultMatrix.ty, cwx - parent.resultMatrix.tx));
  1664. var pp = parent.parentBone;
  1665. a = pp.resultMatrix.a;
  1666. b = pp.resultMatrix.c;
  1667. c = pp.resultMatrix.b;
  1668. d = pp.resultMatrix.d;
  1669. var id = 1 / (a * d - b * c);
  1670. var x = targetX - pp.resultMatrix.tx, y = targetY - pp.resultMatrix.ty;
  1671. var tx = (x * d - y * b) * id - px;
  1672. var ty = (y * a - x * c) * id - py;
  1673. x = cwx - pp.resultMatrix.tx;
  1674. y = cwy - pp.resultMatrix.ty;
  1675. var dx = (x * d - y * b) * id - px;
  1676. var dy = (y * a - x * c) * id - py;
  1677. var l1 = Math.sqrt(dx * dx + dy * dy);
  1678. var l2 = child.length * csx;
  1679. var a1, a2;
  1680. if (u) {
  1681. l2 *= psx;
  1682. var cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  1683. if (cos < -1)
  1684. cos = -1;
  1685. else if (cos > 1)
  1686. cos = 1;
  1687. a2 = Math.acos(cos) * bendDir;
  1688. a = l1 + l2 * cos;
  1689. b = l2 * Math.sin(a2);
  1690. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  1691. }
  1692. else {
  1693. a = psx * l2;
  1694. b = psy * l2;
  1695. var aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = Math.atan2(ty, tx);
  1696. c = bb * l1 * l1 + aa * dd - aa * bb;
  1697. var c1 = -2 * bb * l1, c2 = bb - aa;
  1698. d = c1 * c1 - 4 * c2 * c;
  1699. if (d > 0) {
  1700. var q = Math.sqrt(d);
  1701. if (c1 < 0)
  1702. q = -q;
  1703. q = -(c1 + q) / 2;
  1704. var r0 = q / c2, r1 = c / q;
  1705. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  1706. if (r * r <= dd) {
  1707. y = Math.sqrt(dd - r * r) * bendDir;
  1708. a1 = ta - Math.atan2(y, r);
  1709. a2 = Math.atan2(y / psy, (r - l1) / psx);
  1710. }
  1711. }
  1712. var minAngle = 0, minDist = Number.MAX_VALUE, minX = 0, minY = 0;
  1713. var maxAngle = 0, maxDist = 0, maxX = 0, maxY = 0;
  1714. x = l1 + a;
  1715. d = x * x;
  1716. if (d > maxDist) {
  1717. maxAngle = 0;
  1718. maxDist = d;
  1719. maxX = x;
  1720. }
  1721. x = l1 - a;
  1722. d = x * x;
  1723. if (d < minDist) {
  1724. minAngle = Math.PI;
  1725. minDist = d;
  1726. minX = x;
  1727. }
  1728. var angle = Math.acos(-a * l1 / (aa - bb));
  1729. x = a * Math.cos(angle) + l1;
  1730. y = b * Math.sin(angle);
  1731. d = x * x + y * y;
  1732. if (d < minDist) {
  1733. minAngle = angle;
  1734. minDist = d;
  1735. minX = x;
  1736. minY = y;
  1737. }
  1738. if (d > maxDist) {
  1739. maxAngle = angle;
  1740. maxDist = d;
  1741. maxX = x;
  1742. maxY = y;
  1743. }
  1744. if (dd <= (minDist + maxDist) / 2) {
  1745. a1 = ta - Math.atan2(minY * bendDir, minX);
  1746. a2 = minAngle * bendDir;
  1747. }
  1748. else {
  1749. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  1750. a2 = maxAngle * bendDir;
  1751. }
  1752. }
  1753. var os = Math.atan2(cy, cx) * s2;
  1754. var rotation = parent.resultTransform.skX;
  1755. a1 = (a1 - os) * IkConstraint.radDeg + os1 - rotation;
  1756. if (a1 > 180)
  1757. a1 -= 360;
  1758. else if (a1 < -180)
  1759. a1 += 360;
  1760. parent.resultTransform.x = px;
  1761. parent.resultTransform.y = py;
  1762. parent.resultTransform.skX = parent.resultTransform.skY = rotation + a1 * alpha;
  1763. rotation = child.resultTransform.skX;
  1764. rotation = rotation % 360;
  1765. a2 = ((a2 + os) * IkConstraint.radDeg - 0) * s2 + os2 - rotation;
  1766. if (a2 > 180)
  1767. a2 -= 360;
  1768. else if (a2 < -180)
  1769. a2 += 360;
  1770. child.resultTransform.x = cx;
  1771. child.resultTransform.y = cy;
  1772. child.resultTransform.skX = child.resultTransform.skY = child.resultTransform.skY + a2 * alpha;
  1773. parent.update();
  1774. }
  1775. _applyIk3(parent, child, targetX, targetY, bendDir, alpha) {
  1776. if (alpha == 0) {
  1777. return;
  1778. }
  1779. var cwx, cwy;
  1780. const x = child.resultMatrix.a * child.length;
  1781. const y = child.resultMatrix.b * child.length;
  1782. const lLL = x * x + y * y;
  1783. const lL = Math.sqrt(lLL);
  1784. var parentX = parent.resultMatrix.tx;
  1785. var parentY = parent.resultMatrix.ty;
  1786. var childX = child.resultMatrix.tx;
  1787. var childY = child.resultMatrix.ty;
  1788. var dX = childX - parentX;
  1789. var dY = childY - parentY;
  1790. const lPP = dX * dX + dY * dY;
  1791. const lP = Math.sqrt(lPP);
  1792. dX = targetX - parent.resultMatrix.tx;
  1793. dY = targetY - parent.resultMatrix.ty;
  1794. const lTT = dX * dX + dY * dY;
  1795. const lT = Math.sqrt(lTT);
  1796. if (lL + lP <= lT || lT + lL <= lP || lT + lP <= lL) {
  1797. var rate;
  1798. if (lL + lP <= lT) {
  1799. rate = 1;
  1800. }
  1801. else {
  1802. rate = -1;
  1803. }
  1804. childX = parentX + rate * (targetX - parentX) * lP / lT;
  1805. childY = parentY + rate * (targetY - parentY) * lP / lT;
  1806. }
  1807. else {
  1808. const h = (lPP - lLL + lTT) / (2 * lTT);
  1809. const r = Math.sqrt(lPP - h * h * lTT) / lT;
  1810. const hX = parentX + (dX * h);
  1811. const hY = parentY + (dY * h);
  1812. const rX = -dY * r;
  1813. const rY = dX * r;
  1814. if (bendDir > 0) {
  1815. childX = hX - rX;
  1816. childY = hY - rY;
  1817. }
  1818. else {
  1819. childX = hX + rX;
  1820. childY = hY + rY;
  1821. }
  1822. }
  1823. cwx = childX;
  1824. cwy = childY;
  1825. if (this.isDebug) {
  1826. if (!this._sp) {
  1827. this._sp = new Laya.Sprite();
  1828. Laya.ILaya.stage.addChild(this._sp);
  1829. }
  1830. this._sp.graphics.clear();
  1831. this._sp.graphics.drawCircle(parentX, parentY, 15, "#ff00ff");
  1832. this._sp.graphics.drawCircle(targetX, targetY, 15, "#ffff00");
  1833. this._sp.graphics.drawCircle(cwx, cwy, 15, "#ff00ff");
  1834. }
  1835. var pRotation;
  1836. pRotation = Math.atan2(cwy - parent.resultMatrix.ty, cwx - parent.resultMatrix.tx);
  1837. parent.setRotation(pRotation);
  1838. var pTarMatrix;
  1839. pTarMatrix = IkConstraint._tempMatrix;
  1840. pTarMatrix.identity();
  1841. pTarMatrix.rotate(pRotation);
  1842. pTarMatrix.scale(parent.resultMatrix.getScaleX(), parent.resultMatrix.getScaleY());
  1843. pTarMatrix.translate(parent.resultMatrix.tx, parent.resultMatrix.ty);
  1844. pTarMatrix.copyTo(parent.resultMatrix);
  1845. parent.updateChild();
  1846. var childRotation;
  1847. childRotation = Math.atan2(targetY - cwy, targetX - cwx);
  1848. child.setRotation(childRotation);
  1849. var childTarMatrix;
  1850. childTarMatrix = IkConstraint._tempMatrix;
  1851. childTarMatrix.identity();
  1852. childTarMatrix.rotate(childRotation);
  1853. childTarMatrix.scale(child.resultMatrix.getScaleX(), child.resultMatrix.getScaleY());
  1854. childTarMatrix.translate(cwx, cwy);
  1855. pTarMatrix.copyTo(child.resultMatrix);
  1856. child.updateChild();
  1857. }
  1858. }
  1859. IkConstraint.radDeg = 180 / Math.PI;
  1860. IkConstraint.degRad = Math.PI / 180;
  1861. IkConstraint._tempMatrix = new Laya.Matrix();
  1862. class IkConstraintData {
  1863. constructor() {
  1864. this.boneNames = [];
  1865. this.bendDirection = 1;
  1866. this.mix = 1;
  1867. this.isSpine = true;
  1868. this.targetBoneIndex = -1;
  1869. this.boneIndexs = [];
  1870. }
  1871. }
  1872. class PathConstraint {
  1873. constructor(data, bones) {
  1874. this._debugKey = false;
  1875. this._segments = [];
  1876. this._curves = [];
  1877. this.data = data;
  1878. this.position = data.position;
  1879. this.spacing = data.spacing;
  1880. this.rotateMix = data.rotateMix;
  1881. this.translateMix = data.translateMix;
  1882. this.bones = [];
  1883. var tBoneIds = this.data.bones;
  1884. for (var i = 0, n = tBoneIds.length; i < n; i++) {
  1885. this.bones.push(bones[tBoneIds[i]]);
  1886. }
  1887. }
  1888. apply(boneList, graphics) {
  1889. if (!this.target)
  1890. return;
  1891. var tTranslateMix = this.translateMix;
  1892. var tRotateMix = this.translateMix;
  1893. var tRotate = tRotateMix > 0;
  1894. var tSpacingMode = this.data.spacingMode;
  1895. var tLengthSpacing = tSpacingMode == "length";
  1896. var tRotateMode = this.data.rotateMode;
  1897. var tTangents = tRotateMode == "tangent";
  1898. var tScale = tRotateMode == "chainScale";
  1899. var lengths = [];
  1900. var boneCount = this.bones.length;
  1901. var spacesCount = tTangents ? boneCount : boneCount + 1;
  1902. var spaces = [];
  1903. this._spaces = spaces;
  1904. spaces[0] = this.position;
  1905. var spacing = this.spacing;
  1906. if (tScale || tLengthSpacing) {
  1907. for (var i = 0, n = spacesCount - 1; i < n;) {
  1908. var bone = this.bones[i];
  1909. var length = bone.length;
  1910. var x = length * bone.resultMatrix.a;
  1911. var y = length * bone.resultMatrix.b;
  1912. length = Math.sqrt(x * x + y * y);
  1913. if (tScale)
  1914. lengths[i] = length;
  1915. spaces[++i] = tLengthSpacing ? Math.max(0, length + spacing) : spacing;
  1916. }
  1917. }
  1918. else {
  1919. for (i = 1; i < spacesCount; i++) {
  1920. spaces[i] = spacing;
  1921. }
  1922. }
  1923. var positions = this.computeWorldPositions(this.target, boneList, graphics, spacesCount, tTangents, this.data.positionMode == "percent", tSpacingMode == "percent");
  1924. if (this._debugKey) {
  1925. for (i = 0; i < positions.length; i++) {
  1926. graphics.drawCircle(positions[i++], positions[i++], 5, "#00ff00");
  1927. }
  1928. var tLinePos = [];
  1929. for (i = 0; i < positions.length; i++) {
  1930. tLinePos.push(positions[i++], positions[i++]);
  1931. }
  1932. graphics.drawLines(0, 0, tLinePos, "#ff0000");
  1933. }
  1934. var boneX = positions[0];
  1935. var boneY = positions[1];
  1936. var offsetRotation = this.data.offsetRotation;
  1937. var tip = tRotateMode == "chain" && offsetRotation == 0;
  1938. var p;
  1939. for (i = 0, p = 3; i < boneCount; i++, p += 3) {
  1940. bone = this.bones[i];
  1941. bone.resultMatrix.tx += (boneX - bone.resultMatrix.tx) * tTranslateMix;
  1942. bone.resultMatrix.ty += (boneY - bone.resultMatrix.ty) * tTranslateMix;
  1943. x = positions[p];
  1944. y = positions[p + 1];
  1945. var dx = x - boneX, dy = y - boneY;
  1946. if (tScale) {
  1947. length = lengths[i];
  1948. if (length != 0) {
  1949. var s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * tRotateMix + 1;
  1950. bone.resultMatrix.a *= s;
  1951. bone.resultMatrix.c *= s;
  1952. }
  1953. }
  1954. boneX = x;
  1955. boneY = y;
  1956. if (tRotate) {
  1957. var a = bone.resultMatrix.a;
  1958. var b = bone.resultMatrix.c;
  1959. var c = bone.resultMatrix.b;
  1960. var d = bone.resultMatrix.d;
  1961. var r;
  1962. var cos;
  1963. var sin;
  1964. if (tTangents) {
  1965. r = positions[p - 1];
  1966. }
  1967. else if (spaces[i + 1] == 0) {
  1968. r = positions[p + 2];
  1969. }
  1970. else {
  1971. r = Math.atan2(dy, dx);
  1972. }
  1973. r -= Math.atan2(c, a) - offsetRotation / 180 * Math.PI;
  1974. if (tip) {
  1975. cos = Math.cos(r);
  1976. sin = Math.sin(r);
  1977. length = bone.length;
  1978. boneX += (length * (cos * a - sin * c) - dx) * tRotateMix;
  1979. boneY += (length * (sin * a + cos * c) - dy) * tRotateMix;
  1980. }
  1981. if (r > Math.PI) {
  1982. r -= (Math.PI * 2);
  1983. }
  1984. else if (r < -Math.PI) {
  1985. r += (Math.PI * 2);
  1986. }
  1987. r *= tRotateMix;
  1988. cos = Math.cos(r);
  1989. sin = Math.sin(r);
  1990. bone.resultMatrix.a = cos * a - sin * c;
  1991. bone.resultMatrix.c = cos * b - sin * d;
  1992. bone.resultMatrix.b = sin * a + cos * c;
  1993. bone.resultMatrix.d = sin * b + cos * d;
  1994. }
  1995. }
  1996. }
  1997. computeWorldVertices2(boneSlot, boneList, start, count, worldVertices, offset) {
  1998. var tBones = boneSlot.currDisplayData.bones;
  1999. var tWeights = boneSlot.currDisplayData.weights;
  2000. var tTriangles = boneSlot.currDisplayData.triangles;
  2001. var tMatrix;
  2002. var i = 0;
  2003. var v = 0;
  2004. var skip = 0;
  2005. var n = 0;
  2006. var w = 0;
  2007. var b = 0;
  2008. var wx = 0;
  2009. var wy = 0;
  2010. var vx = 0;
  2011. var vy = 0;
  2012. var bone;
  2013. var len;
  2014. if (tBones == null) {
  2015. if (!tTriangles)
  2016. tTriangles = tWeights;
  2017. if (boneSlot.deformData)
  2018. tTriangles = boneSlot.deformData;
  2019. var parentName;
  2020. parentName = boneSlot.parent;
  2021. if (boneList) {
  2022. len = boneList.length;
  2023. for (i = 0; i < len; i++) {
  2024. if (boneList[i].name == parentName) {
  2025. bone = boneList[i];
  2026. break;
  2027. }
  2028. }
  2029. }
  2030. var tBoneMt;
  2031. if (bone) {
  2032. tBoneMt = bone.resultMatrix;
  2033. }
  2034. if (!tBoneMt)
  2035. tBoneMt = PathConstraint._tempMt;
  2036. var x = tBoneMt.tx;
  2037. var y = tBoneMt.ty;
  2038. var a = tBoneMt.a, bb = tBoneMt.b, c = tBoneMt.c, d = tBoneMt.d;
  2039. if (bone)
  2040. d *= bone.d;
  2041. for (v = start, w = offset; w < count; v += 2, w += 2) {
  2042. vx = tTriangles[v], vy = tTriangles[v + 1];
  2043. worldVertices[w] = vx * a + vy * bb + x;
  2044. worldVertices[w + 1] = -(vx * c + vy * d + y);
  2045. }
  2046. return;
  2047. }
  2048. for (i = 0; i < start; i += 2) {
  2049. n = tBones[v];
  2050. v += n + 1;
  2051. skip += n;
  2052. }
  2053. var skeletonBones = boneList;
  2054. for (w = offset, b = skip * 3; w < count; w += 2) {
  2055. wx = 0, wy = 0;
  2056. n = tBones[v++];
  2057. n += v;
  2058. for (; v < n; v++, b += 3) {
  2059. tMatrix = skeletonBones[tBones[v]].resultMatrix;
  2060. vx = tWeights[b];
  2061. vy = tWeights[b + 1];
  2062. var weight = tWeights[b + 2];
  2063. wx += (vx * tMatrix.a + vy * tMatrix.c + tMatrix.tx) * weight;
  2064. wy += (vx * tMatrix.b + vy * tMatrix.d + tMatrix.ty) * weight;
  2065. }
  2066. worldVertices[w] = wx;
  2067. worldVertices[w + 1] = wy;
  2068. }
  2069. }
  2070. computeWorldPositions(boneSlot, boneList, graphics, spacesCount, tangents, percentPosition, percentSpacing) {
  2071. var tBones = boneSlot.currDisplayData.bones;
  2072. var tWeights = boneSlot.currDisplayData.weights;
  2073. var tTriangles = boneSlot.currDisplayData.triangles;
  2074. var tVertices = [];
  2075. var i = 0;
  2076. var verticesLength = boneSlot.currDisplayData.verLen;
  2077. var position = this.position;
  2078. var spaces = this._spaces;
  2079. var world = [];
  2080. var out = [];
  2081. var curveCount = verticesLength / 6;
  2082. var prevCurve = -1;
  2083. var pathLength;
  2084. var o, curve;
  2085. var p;
  2086. var space;
  2087. var prev;
  2088. var length;
  2089. {
  2090. curveCount--;
  2091. verticesLength -= 4;
  2092. this.computeWorldVertices2(boneSlot, boneList, 2, verticesLength, tVertices, 0);
  2093. if (this._debugKey) {
  2094. for (i = 0; i < tVertices.length;) {
  2095. graphics.drawCircle(tVertices[i++], tVertices[i++], 10, "#ff0000");
  2096. }
  2097. }
  2098. world = tVertices;
  2099. }
  2100. this._curves.length = curveCount;
  2101. var curves = this._curves;
  2102. pathLength = 0;
  2103. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  2104. var tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;
  2105. var w;
  2106. for (i = 0, w = 2; i < curveCount; i++, w += 6) {
  2107. cx1 = world[w];
  2108. cy1 = world[w + 1];
  2109. cx2 = world[w + 2];
  2110. cy2 = world[w + 3];
  2111. x2 = world[w + 4];
  2112. y2 = world[w + 5];
  2113. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  2114. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  2115. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  2116. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  2117. ddfx = tmpx * 2 + dddfx;
  2118. ddfy = tmpy * 2 + dddfy;
  2119. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  2120. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  2121. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2122. dfx += ddfx;
  2123. dfy += ddfy;
  2124. ddfx += dddfx;
  2125. ddfy += dddfy;
  2126. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2127. dfx += ddfx;
  2128. dfy += ddfy;
  2129. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2130. dfx += ddfx + dddfx;
  2131. dfy += ddfy + dddfy;
  2132. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2133. curves[i] = pathLength;
  2134. x1 = x2;
  2135. y1 = y2;
  2136. }
  2137. if (percentPosition)
  2138. position *= pathLength;
  2139. if (percentSpacing) {
  2140. for (i = 0; i < spacesCount; i++)
  2141. spaces[i] *= pathLength;
  2142. }
  2143. var segments = this._segments;
  2144. var curveLength = 0;
  2145. var segment;
  2146. for (i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  2147. space = spaces[i];
  2148. position += space;
  2149. p = position;
  2150. if (p < 0) {
  2151. this.addBeforePosition(p, world, 0, out, o);
  2152. continue;
  2153. }
  2154. else if (p > pathLength) {
  2155. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  2156. continue;
  2157. }
  2158. for (;; curve++) {
  2159. length = curves[curve];
  2160. if (p > length)
  2161. continue;
  2162. if (curve == 0)
  2163. p /= length;
  2164. else {
  2165. prev = curves[curve - 1];
  2166. p = (p - prev) / (length - prev);
  2167. }
  2168. break;
  2169. }
  2170. if (curve != prevCurve) {
  2171. prevCurve = curve;
  2172. var ii = curve * 6;
  2173. x1 = world[ii];
  2174. y1 = world[ii + 1];
  2175. cx1 = world[ii + 2];
  2176. cy1 = world[ii + 3];
  2177. cx2 = world[ii + 4];
  2178. cy2 = world[ii + 5];
  2179. x2 = world[ii + 6];
  2180. y2 = world[ii + 7];
  2181. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  2182. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  2183. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  2184. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  2185. ddfx = tmpx * 2 + dddfx;
  2186. ddfy = tmpy * 2 + dddfy;
  2187. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  2188. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  2189. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  2190. segments[0] = curveLength;
  2191. for (ii = 1; ii < 8; ii++) {
  2192. dfx += ddfx;
  2193. dfy += ddfy;
  2194. ddfx += dddfx;
  2195. ddfy += dddfy;
  2196. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2197. segments[ii] = curveLength;
  2198. }
  2199. dfx += ddfx;
  2200. dfy += ddfy;
  2201. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2202. segments[8] = curveLength;
  2203. dfx += ddfx + dddfx;
  2204. dfy += ddfy + dddfy;
  2205. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2206. segments[9] = curveLength;
  2207. segment = 0;
  2208. }
  2209. p *= curveLength;
  2210. for (;; segment++) {
  2211. length = segments[segment];
  2212. if (p > length)
  2213. continue;
  2214. if (segment == 0)
  2215. p /= length;
  2216. else {
  2217. prev = segments[segment - 1];
  2218. p = segment + (p - prev) / (length - prev);
  2219. }
  2220. break;
  2221. }
  2222. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  2223. }
  2224. return out;
  2225. }
  2226. addBeforePosition(p, temp, i, out, o) {
  2227. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  2228. out[o] = x1 + p * Math.cos(r);
  2229. out[o + 1] = y1 + p * Math.sin(r);
  2230. out[o + 2] = r;
  2231. }
  2232. addAfterPosition(p, temp, i, out, o) {
  2233. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  2234. out[o] = x1 + p * Math.cos(r);
  2235. out[o + 1] = y1 + p * Math.sin(r);
  2236. out[o + 2] = r;
  2237. }
  2238. addCurvePosition(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  2239. if (p == 0)
  2240. p = 0.0001;
  2241. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  2242. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  2243. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  2244. out[o] = x;
  2245. out[o + 1] = y;
  2246. if (tangents) {
  2247. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  2248. }
  2249. else {
  2250. out[o + 2] = 0;
  2251. }
  2252. }
  2253. }
  2254. PathConstraint.BEFORE = -2;
  2255. PathConstraint.AFTER = -3;
  2256. PathConstraint._tempMt = new Laya.Matrix();
  2257. class PathConstraintData {
  2258. constructor() {
  2259. this.bones = [];
  2260. }
  2261. }
  2262. class TfConstraint {
  2263. constructor(data, bones) {
  2264. this._temp = [];
  2265. this._data = data;
  2266. if (this._bones == null) {
  2267. this._bones = [];
  2268. }
  2269. this.target = bones[data.targetIndex];
  2270. var j, n;
  2271. for (j = 0, n = data.boneIndexs.length; j < n; j++) {
  2272. this._bones.push(bones[data.boneIndexs[j]]);
  2273. }
  2274. this.rotateMix = data.rotateMix;
  2275. this.translateMix = data.translateMix;
  2276. this.scaleMix = data.scaleMix;
  2277. this.shearMix = data.shearMix;
  2278. }
  2279. apply() {
  2280. var tTfBone;
  2281. var ta = this.target.resultMatrix.a, tb = this.target.resultMatrix.b, tc = this.target.resultMatrix.c, td = this.target.resultMatrix.d;
  2282. for (var j = 0, n = this._bones.length; j < n; j++) {
  2283. tTfBone = this._bones[j];
  2284. if (this.rotateMix > 0) {
  2285. var a = tTfBone.resultMatrix.a, b = tTfBone.resultMatrix.b, c = tTfBone.resultMatrix.c, d = tTfBone.resultMatrix.d;
  2286. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + this._data.offsetRotation * Math.PI / 180;
  2287. if (r > Math.PI)
  2288. r -= Math.PI * 2;
  2289. else if (r < -Math.PI)
  2290. r += Math.PI * 2;
  2291. r *= this.rotateMix;
  2292. var cos = Math.cos(r), sin = Math.sin(r);
  2293. tTfBone.resultMatrix.a = cos * a - sin * c;
  2294. tTfBone.resultMatrix.b = cos * b - sin * d;
  2295. tTfBone.resultMatrix.c = sin * a + cos * c;
  2296. tTfBone.resultMatrix.d = sin * b + cos * d;
  2297. }
  2298. if (this.translateMix) {
  2299. this._temp[0] = this._data.offsetX;
  2300. this._temp[1] = this._data.offsetY;
  2301. this.target.localToWorld(this._temp);
  2302. tTfBone.resultMatrix.tx += (this._temp[0] - tTfBone.resultMatrix.tx) * this.translateMix;
  2303. tTfBone.resultMatrix.ty += (this._temp[1] - tTfBone.resultMatrix.ty) * this.translateMix;
  2304. tTfBone.updateChild();
  2305. }
  2306. if (this.scaleMix > 0) {
  2307. var bs = Math.sqrt(tTfBone.resultMatrix.a * tTfBone.resultMatrix.a + tTfBone.resultMatrix.c * tTfBone.resultMatrix.c);
  2308. var ts = Math.sqrt(ta * ta + tc * tc);
  2309. var s = bs > 0.00001 ? (bs + (ts - bs + this._data.offsetScaleX) * this.scaleMix) / bs : 0;
  2310. tTfBone.resultMatrix.a *= s;
  2311. tTfBone.resultMatrix.c *= s;
  2312. bs = Math.sqrt(tTfBone.resultMatrix.b * tTfBone.resultMatrix.b + tTfBone.resultMatrix.d * tTfBone.resultMatrix.d);
  2313. ts = Math.sqrt(tb * tb + td * td);
  2314. s = bs > 0.00001 ? (bs + (ts - bs + this._data.offsetScaleY) * this.scaleMix) / bs : 0;
  2315. tTfBone.resultMatrix.b *= s;
  2316. tTfBone.resultMatrix.d *= s;
  2317. }
  2318. if (this.shearMix > 0) {
  2319. b = tTfBone.resultMatrix.b, d = tTfBone.resultMatrix.d;
  2320. var by = Math.atan2(d, b);
  2321. r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(tTfBone.resultMatrix.c, tTfBone.resultMatrix.a));
  2322. if (r > Math.PI)
  2323. r -= Math.PI * 2;
  2324. else if (r < -Math.PI)
  2325. r += Math.PI * 2;
  2326. r = by + (r + this._data.offsetShearY * Math.PI / 180) * this.shearMix;
  2327. s = Math.sqrt(b * b + d * d);
  2328. tTfBone.resultMatrix.b = Math.cos(r) * s;
  2329. tTfBone.resultMatrix.d = Math.sin(r) * s;
  2330. }
  2331. }
  2332. }
  2333. }
  2334. class Skeleton extends Laya.Sprite {
  2335. constructor(templet = null, aniMode = 0) {
  2336. super();
  2337. this._boneMatrixArray = [];
  2338. this._lastTime = 0;
  2339. this._currAniIndex = -1;
  2340. this._pause = true;
  2341. this._aniClipIndex = -1;
  2342. this._clipIndex = -1;
  2343. this._skinIndex = 0;
  2344. this._skinName = "default";
  2345. this._aniMode = 0;
  2346. this._index = -1;
  2347. this._total = -1;
  2348. this._indexControl = false;
  2349. this._eventIndex = 0;
  2350. this._drawOrderIndex = 0;
  2351. this._drawOrder = null;
  2352. this._lastAniClipIndex = -1;
  2353. this._lastUpdateAniClipIndex = -1;
  2354. this._playAudio = true;
  2355. this._soundChannelArr = [];
  2356. if (templet)
  2357. this.init(templet, aniMode);
  2358. }
  2359. init(templet, aniMode = 0) {
  2360. var i = 0, n;
  2361. if (aniMode == 1) {
  2362. this._graphicsCache = [];
  2363. for (i = 0, n = templet.getAnimationCount(); i < n; i++) {
  2364. this._graphicsCache.push([]);
  2365. }
  2366. }
  2367. this._yReverseMatrix = templet.yReverseMatrix;
  2368. this._aniMode = aniMode;
  2369. this._templet = templet;
  2370. this._templet._addReference(1);
  2371. this._player = new AnimationPlayer();
  2372. this._player.cacheFrameRate = templet.rate;
  2373. this._player.templet = templet;
  2374. this._player.play();
  2375. this._parseSrcBoneMatrix();
  2376. this._boneList = templet.mBoneArr;
  2377. this._rootBone = templet.mRootBone;
  2378. this._aniSectionDic = templet.aniSectionDic;
  2379. if (templet.ikArr.length > 0) {
  2380. this._ikArr = [];
  2381. for (i = 0, n = templet.ikArr.length; i < n; i++) {
  2382. this._ikArr.push(new IkConstraint(templet.ikArr[i], this._boneList));
  2383. }
  2384. }
  2385. if (templet.pathArr.length > 0) {
  2386. var tPathData;
  2387. var tPathConstraint;
  2388. if (this._pathDic == null)
  2389. this._pathDic = {};
  2390. var tBoneSlot;
  2391. for (i = 0, n = templet.pathArr.length; i < n; i++) {
  2392. tPathData = templet.pathArr[i];
  2393. tPathConstraint = new PathConstraint(tPathData, this._boneList);
  2394. tBoneSlot = this._boneSlotDic[tPathData.name];
  2395. if (tBoneSlot) {
  2396. tPathConstraint = new PathConstraint(tPathData, this._boneList);
  2397. tPathConstraint.target = tBoneSlot;
  2398. }
  2399. this._pathDic[tPathData.name] = tPathConstraint;
  2400. }
  2401. }
  2402. if (templet.tfArr.length > 0) {
  2403. this._tfArr = [];
  2404. for (i = 0, n = templet.tfArr.length; i < n; i++) {
  2405. this._tfArr.push(new TfConstraint(templet.tfArr[i], this._boneList));
  2406. }
  2407. }
  2408. if (templet.skinDataArray.length > 0) {
  2409. var tSkinData = this._templet.skinDataArray[this._skinIndex];
  2410. this._skinName = tSkinData.name;
  2411. }
  2412. this._player.on(Laya.Event.PLAYED, this, this._onPlay);
  2413. this._player.on(Laya.Event.STOPPED, this, this._onStop);
  2414. this._player.on(Laya.Event.PAUSED, this, this._onPause);
  2415. }
  2416. get url() {
  2417. return this._aniPath;
  2418. }
  2419. set url(path) {
  2420. this.load(path);
  2421. }
  2422. load(path, complete = null, aniMode = 0) {
  2423. this._aniPath = path;
  2424. this._complete = complete;
  2425. this._loadAniMode = aniMode;
  2426. Laya.ILaya.loader.load([{ url: path, type: Laya.ILaya.Loader.BUFFER }], Laya.Handler.create(this, this._onLoaded));
  2427. }
  2428. _onLoaded() {
  2429. var arraybuffer = Laya.ILaya.Loader.getRes(this._aniPath);
  2430. if (arraybuffer == null)
  2431. return;
  2432. if (IAniLib.Templet.TEMPLET_DICTIONARY == null) {
  2433. IAniLib.Templet.TEMPLET_DICTIONARY = {};
  2434. }
  2435. var tFactory;
  2436. tFactory = IAniLib.Templet.TEMPLET_DICTIONARY[this._aniPath];
  2437. if (tFactory) {
  2438. if (tFactory.isParseFail) {
  2439. this._parseFail();
  2440. }
  2441. else {
  2442. if (tFactory.isParserComplete) {
  2443. this._parseComplete();
  2444. }
  2445. else {
  2446. tFactory.on(Laya.Event.COMPLETE, this, this._parseComplete);
  2447. tFactory.on(Laya.Event.ERROR, this, this._parseFail);
  2448. }
  2449. }
  2450. }
  2451. else {
  2452. tFactory = new IAniLib.Templet();
  2453. tFactory._setCreateURL(this._aniPath);
  2454. IAniLib.Templet.TEMPLET_DICTIONARY[this._aniPath] = tFactory;
  2455. tFactory.on(Laya.Event.COMPLETE, this, this._parseComplete);
  2456. tFactory.on(Laya.Event.ERROR, this, this._parseFail);
  2457. tFactory.isParserComplete = false;
  2458. tFactory.parseData(null, arraybuffer);
  2459. }
  2460. }
  2461. _parseComplete() {
  2462. var tTemple = IAniLib.Templet.TEMPLET_DICTIONARY[this._aniPath];
  2463. if (tTemple) {
  2464. this.init(tTemple, this._loadAniMode);
  2465. this.play(0, true);
  2466. }
  2467. this._complete && this._complete.runWith(this);
  2468. }
  2469. _parseFail() {
  2470. console.log("[Error]:" + this._aniPath + "解析失败");
  2471. }
  2472. _onPlay() {
  2473. this.event(Laya.Event.PLAYED);
  2474. }
  2475. _onStop() {
  2476. var tEventData;
  2477. var tEventAniArr = this._templet.eventAniArr;
  2478. var tEventArr = tEventAniArr[this._aniClipIndex];
  2479. if (tEventArr && this._eventIndex < tEventArr.length) {
  2480. for (; this._eventIndex < tEventArr.length; this._eventIndex++) {
  2481. tEventData = tEventArr[this._eventIndex];
  2482. if (tEventData.time >= this._player.playStart && tEventData.time <= this._player.playEnd) {
  2483. this.event(Laya.Event.LABEL, tEventData);
  2484. }
  2485. }
  2486. }
  2487. this._drawOrder = null;
  2488. this.event(Laya.Event.STOPPED);
  2489. }
  2490. _onPause() {
  2491. this.event(Laya.Event.PAUSED);
  2492. }
  2493. _parseSrcBoneMatrix() {
  2494. var i = 0, n = 0;
  2495. n = this._templet.srcBoneMatrixArr.length;
  2496. for (i = 0; i < n; i++) {
  2497. this._boneMatrixArray.push(new Laya.Matrix());
  2498. }
  2499. if (this._aniMode == 0) {
  2500. this._boneSlotDic = this._templet.boneSlotDic;
  2501. this._bindBoneBoneSlotDic = this._templet.bindBoneBoneSlotDic;
  2502. this._boneSlotArray = this._templet.boneSlotArray;
  2503. }
  2504. else {
  2505. if (this._boneSlotDic == null)
  2506. this._boneSlotDic = {};
  2507. if (this._bindBoneBoneSlotDic == null)
  2508. this._bindBoneBoneSlotDic = {};
  2509. if (this._boneSlotArray == null)
  2510. this._boneSlotArray = [];
  2511. var tArr = this._templet.boneSlotArray;
  2512. var tBS;
  2513. var tBSArr;
  2514. for (i = 0, n = tArr.length; i < n; i++) {
  2515. tBS = tArr[i];
  2516. tBSArr = this._bindBoneBoneSlotDic[tBS.parent];
  2517. if (tBSArr == null) {
  2518. this._bindBoneBoneSlotDic[tBS.parent] = tBSArr = [];
  2519. }
  2520. this._boneSlotDic[tBS.name] = tBS = tBS.copy();
  2521. tBSArr.push(tBS);
  2522. this._boneSlotArray.push(tBS);
  2523. }
  2524. }
  2525. }
  2526. _emitMissedEvents(startTime, endTime, startIndex = 0) {
  2527. var tEventAniArr = this._templet.eventAniArr;
  2528. var tEventArr = tEventAniArr[this._player.currentAnimationClipIndex];
  2529. if (tEventArr) {
  2530. var i = 0, len;
  2531. var tEventData;
  2532. len = tEventArr.length;
  2533. for (i = startIndex; i < len; i++) {
  2534. tEventData = tEventArr[i];
  2535. if (tEventData.time >= this._player.playStart && tEventData.time <= this._player.playEnd) {
  2536. this.event(Laya.Event.LABEL, tEventData);
  2537. }
  2538. }
  2539. }
  2540. }
  2541. _update(autoKey = true) {
  2542. if (this._pause)
  2543. return;
  2544. if (autoKey && this._indexControl) {
  2545. return;
  2546. }
  2547. var tCurrTime = this.timer.currTimer;
  2548. var preIndex = this._player.currentKeyframeIndex;
  2549. var dTime = tCurrTime - this._lastTime;
  2550. if (autoKey) {
  2551. this._player._update(dTime);
  2552. }
  2553. else {
  2554. preIndex = -1;
  2555. }
  2556. this._lastTime = tCurrTime;
  2557. if (!this._player)
  2558. return;
  2559. this._index = this._clipIndex = this._player.currentKeyframeIndex;
  2560. if (this._index < 0)
  2561. return;
  2562. if (dTime > 0 && this._clipIndex == preIndex && this._lastUpdateAniClipIndex == this._aniClipIndex) {
  2563. return;
  2564. }
  2565. this._lastUpdateAniClipIndex = this._aniClipIndex;
  2566. if (preIndex > this._clipIndex && this._eventIndex != 0) {
  2567. this._emitMissedEvents(this._player.playStart, this._player.playEnd, this._eventIndex);
  2568. this._eventIndex = 0;
  2569. }
  2570. var tEventArr = this._templet.eventAniArr[this._aniClipIndex];
  2571. var _soundChannel;
  2572. if (tEventArr && this._eventIndex < tEventArr.length) {
  2573. var tEventData = tEventArr[this._eventIndex];
  2574. if (tEventData.time >= this._player.playStart && tEventData.time <= this._player.playEnd) {
  2575. if (this._player.currentPlayTime >= tEventData.time) {
  2576. this.event(Laya.Event.LABEL, tEventData);
  2577. this._eventIndex++;
  2578. if (this._playAudio && tEventData.audioValue && tEventData.audioValue !== "null" && tEventData.audioValue !== "undefined") {
  2579. _soundChannel = Laya.SoundManager.playSound(this._player.templet._path + tEventData.audioValue, 1, Laya.Handler.create(this, this._onAniSoundStoped));
  2580. Laya.SoundManager.playbackRate = this._player.playbackRate;
  2581. _soundChannel && this._soundChannelArr.push(_soundChannel);
  2582. }
  2583. }
  2584. }
  2585. else if (tEventData.time < this._player.playStart && this._playAudio && tEventData.audioValue && tEventData.audioValue !== "null" && tEventData.audioValue !== "undefined") {
  2586. this._eventIndex++;
  2587. _soundChannel = Laya.SoundManager.playSound(this._player.templet._path + tEventData.audioValue, 1, Laya.Handler.create(this, this._onAniSoundStoped), null, (this._player.currentPlayTime - tEventData.time) / 1000);
  2588. Laya.SoundManager.playbackRate = this._player.playbackRate;
  2589. _soundChannel && this._soundChannelArr.push(_soundChannel);
  2590. }
  2591. else {
  2592. this._eventIndex++;
  2593. }
  2594. }
  2595. var tGraphics;
  2596. if (this._aniMode == 0) {
  2597. tGraphics = this._templet.getGrahicsDataWithCache(this._aniClipIndex, this._clipIndex) || this._createGraphics();
  2598. if (tGraphics && this.graphics != tGraphics) {
  2599. this.graphics = tGraphics;
  2600. }
  2601. }
  2602. else if (this._aniMode == 1) {
  2603. tGraphics = this._getGrahicsDataWithCache(this._aniClipIndex, this._clipIndex) || this._createGraphics();
  2604. if (tGraphics && this.graphics != tGraphics) {
  2605. this.graphics = tGraphics;
  2606. }
  2607. }
  2608. else {
  2609. this._createGraphics();
  2610. }
  2611. }
  2612. _onAniSoundStoped(force) {
  2613. var _channel;
  2614. for (var len = this._soundChannelArr.length, i = 0; i < len; i++) {
  2615. _channel = this._soundChannelArr[i];
  2616. if (_channel.isStopped || force) {
  2617. !_channel.isStopped && _channel.stop();
  2618. this._soundChannelArr.splice(i, 1);
  2619. len--;
  2620. i--;
  2621. }
  2622. }
  2623. }
  2624. _createGraphics(_clipIndex = -1) {
  2625. if (_clipIndex == -1)
  2626. _clipIndex = this._clipIndex;
  2627. var curTime = _clipIndex * this._player.cacheFrameRateInterval;
  2628. var tDrawOrderData;
  2629. var tDrawOrderAniArr = this._templet.drawOrderAniArr;
  2630. var tDrawOrderArr = tDrawOrderAniArr[this._aniClipIndex];
  2631. if (tDrawOrderArr && tDrawOrderArr.length > 0) {
  2632. this._drawOrderIndex = 0;
  2633. tDrawOrderData = tDrawOrderArr[this._drawOrderIndex];
  2634. while (curTime >= tDrawOrderData.time) {
  2635. this._drawOrder = tDrawOrderData.drawOrder;
  2636. this._drawOrderIndex++;
  2637. if (this._drawOrderIndex >= tDrawOrderArr.length) {
  2638. break;
  2639. }
  2640. tDrawOrderData = tDrawOrderArr[this._drawOrderIndex];
  2641. }
  2642. }
  2643. if (this._aniMode == 0 || this._aniMode == 1) {
  2644. this.graphics = GraphicsAni.create();
  2645. }
  2646. else {
  2647. if (this.graphics instanceof GraphicsAni) {
  2648. this.graphics.clear();
  2649. }
  2650. else {
  2651. this.graphics = GraphicsAni.create();
  2652. }
  2653. }
  2654. var tGraphics = this.graphics;
  2655. var bones = this._templet.getNodes(this._aniClipIndex);
  2656. var stopped = this._player.state == 0;
  2657. this._templet.getOriginalData(this._aniClipIndex, this._curOriginalData, null, _clipIndex, stopped ? (curTime + this._player.cacheFrameRateInterval) : curTime);
  2658. var tSectionArr = this._aniSectionDic[this._aniClipIndex];
  2659. var tStartIndex = 0;
  2660. var i = 0, j = 0, k = 0, n = 0;
  2661. var tDBBoneSlot;
  2662. var tDBBoneSlotArr;
  2663. var tParentTransform;
  2664. var tSrcBone;
  2665. var boneCount = this._templet.srcBoneMatrixArr.length;
  2666. var origDt = this._curOriginalData;
  2667. for (i = 0, n = tSectionArr[0]; i < boneCount; i++) {
  2668. tSrcBone = this._boneList[i];
  2669. var resultTrans = tSrcBone.resultTransform;
  2670. tParentTransform = this._templet.srcBoneMatrixArr[i];
  2671. resultTrans.scX = tParentTransform.scX * origDt[tStartIndex++];
  2672. resultTrans.skX = tParentTransform.skX + origDt[tStartIndex++];
  2673. resultTrans.skY = tParentTransform.skY + origDt[tStartIndex++];
  2674. resultTrans.scY = tParentTransform.scY * origDt[tStartIndex++];
  2675. resultTrans.x = tParentTransform.x + origDt[tStartIndex++];
  2676. resultTrans.y = tParentTransform.y + origDt[tStartIndex++];
  2677. if (this._templet.tMatrixDataLen === 8) {
  2678. resultTrans.skewX = tParentTransform.skewX + origDt[tStartIndex++];
  2679. resultTrans.skewY = tParentTransform.skewY + origDt[tStartIndex++];
  2680. }
  2681. }
  2682. var tSlotDic = {};
  2683. var tSlotAlphaDic = {};
  2684. var tBoneData;
  2685. for (n += tSectionArr[1]; i < n; i++) {
  2686. tBoneData = bones[i];
  2687. tSlotDic[tBoneData.name] = origDt[tStartIndex++];
  2688. tSlotAlphaDic[tBoneData.name] = origDt[tStartIndex++];
  2689. tStartIndex += 4;
  2690. }
  2691. var tBendDirectionDic = {};
  2692. var tMixDic = {};
  2693. for (n += tSectionArr[2]; i < n; i++) {
  2694. tBoneData = bones[i];
  2695. tBendDirectionDic[tBoneData.name] = origDt[tStartIndex++];
  2696. tMixDic[tBoneData.name] = origDt[tStartIndex++];
  2697. tStartIndex += 4;
  2698. }
  2699. if (this._pathDic) {
  2700. var tPathConstraint;
  2701. for (n += tSectionArr[3]; i < n; i++) {
  2702. tBoneData = bones[i];
  2703. tPathConstraint = this._pathDic[tBoneData.name];
  2704. if (tPathConstraint) {
  2705. var tByte = new Laya.Byte(tBoneData.extenData);
  2706. switch (tByte.getByte()) {
  2707. case 1:
  2708. tPathConstraint.position = origDt[tStartIndex++];
  2709. break;
  2710. case 2:
  2711. tPathConstraint.spacing = origDt[tStartIndex++];
  2712. break;
  2713. case 3:
  2714. tPathConstraint.rotateMix = origDt[tStartIndex++];
  2715. tPathConstraint.translateMix = origDt[tStartIndex++];
  2716. break;
  2717. }
  2718. }
  2719. }
  2720. }
  2721. this._rootBone.update(this._yReverseMatrix || Laya.Matrix.TEMP.identity());
  2722. if (this._ikArr) {
  2723. var tIkConstraint;
  2724. for (i = 0, n = this._ikArr.length; i < n; i++) {
  2725. tIkConstraint = this._ikArr[i];
  2726. if (tIkConstraint.name in tBendDirectionDic) {
  2727. tIkConstraint.bendDirection = tBendDirectionDic[tIkConstraint.name];
  2728. }
  2729. if (tIkConstraint.name in tMixDic) {
  2730. tIkConstraint.mix = tMixDic[tIkConstraint.name];
  2731. }
  2732. tIkConstraint.apply();
  2733. }
  2734. }
  2735. if (this._pathDic) {
  2736. for (var tPathStr in this._pathDic) {
  2737. tPathConstraint = this._pathDic[tPathStr];
  2738. tPathConstraint.apply(this._boneList, tGraphics);
  2739. }
  2740. }
  2741. if (this._tfArr) {
  2742. var tTfConstraint;
  2743. for (i = 0, k = this._tfArr.length; i < k; i++) {
  2744. tTfConstraint = this._tfArr[i];
  2745. tTfConstraint.apply();
  2746. }
  2747. }
  2748. for (i = 0, k = this._boneList.length; i < k; i++) {
  2749. tSrcBone = this._boneList[i];
  2750. tDBBoneSlotArr = this._bindBoneBoneSlotDic[tSrcBone.name];
  2751. tSrcBone.resultMatrix.copyTo(this._boneMatrixArray[i]);
  2752. if (tDBBoneSlotArr) {
  2753. for (j = 0, n = tDBBoneSlotArr.length; j < n; j++) {
  2754. tDBBoneSlot = tDBBoneSlotArr[j];
  2755. if (tDBBoneSlot) {
  2756. tDBBoneSlot.setParentMatrix(tSrcBone.resultMatrix);
  2757. }
  2758. }
  2759. }
  2760. }
  2761. var tDeformDic = {};
  2762. var tDeformAniArr = this._templet.deformAniArr;
  2763. var tDeformAniData;
  2764. if (tDeformAniArr && tDeformAniArr.length > 0) {
  2765. if (this._lastAniClipIndex != this._aniClipIndex) {
  2766. this._lastAniClipIndex = this._aniClipIndex;
  2767. for (i = 0, n = this._boneSlotArray.length; i < n; i++) {
  2768. tDBBoneSlot = this._boneSlotArray[i];
  2769. tDBBoneSlot.deformData = null;
  2770. }
  2771. }
  2772. var tSkinDeformAni = tDeformAniArr[this._aniClipIndex];
  2773. tDeformAniData = (tSkinDeformAni["default"]);
  2774. this._setDeform(tDeformAniData, tDeformDic, this._boneSlotArray, curTime);
  2775. var tSkin;
  2776. for (tSkin in tSkinDeformAni) {
  2777. if (tSkin != "default" && tSkin != this._skinName) {
  2778. tDeformAniData = tSkinDeformAni[tSkin];
  2779. this._setDeform(tDeformAniData, tDeformDic, this._boneSlotArray, curTime);
  2780. }
  2781. }
  2782. tDeformAniData = (tSkinDeformAni[this._skinName]);
  2783. this._setDeform(tDeformAniData, tDeformDic, this._boneSlotArray, curTime);
  2784. }
  2785. var tSlotData2;
  2786. var tSlotData3;
  2787. var tObject;
  2788. if (this._drawOrder) {
  2789. for (i = 0, n = this._drawOrder.length; i < n; i++) {
  2790. tDBBoneSlot = this._boneSlotArray[this._drawOrder[i]];
  2791. tSlotData2 = tSlotDic[tDBBoneSlot.name];
  2792. tSlotData3 = tSlotAlphaDic[tDBBoneSlot.name];
  2793. if (!isNaN(tSlotData2) && tSlotData2 != -2) {
  2794. if (this._templet.attachmentNames) {
  2795. tDBBoneSlot.showDisplayByName(this._templet.attachmentNames[tSlotData2]);
  2796. }
  2797. else {
  2798. tDBBoneSlot.showDisplayByIndex(tSlotData2);
  2799. }
  2800. }
  2801. if (tDeformDic[this._drawOrder[i]]) {
  2802. tObject = tDeformDic[this._drawOrder[i]];
  2803. if (tDBBoneSlot.currDisplayData && tObject[tDBBoneSlot.currDisplayData.attachmentName]) {
  2804. tDBBoneSlot.deformData = tObject[tDBBoneSlot.currDisplayData.attachmentName];
  2805. }
  2806. else {
  2807. tDBBoneSlot.deformData = null;
  2808. }
  2809. }
  2810. else {
  2811. tDBBoneSlot.deformData = null;
  2812. }
  2813. if (!isNaN(tSlotData3)) {
  2814. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2, tSlotData3);
  2815. }
  2816. else {
  2817. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2);
  2818. }
  2819. }
  2820. }
  2821. else {
  2822. for (i = 0, n = this._boneSlotArray.length; i < n; i++) {
  2823. tDBBoneSlot = this._boneSlotArray[i];
  2824. tSlotData2 = tSlotDic[tDBBoneSlot.name];
  2825. tSlotData3 = tSlotAlphaDic[tDBBoneSlot.name];
  2826. if (!isNaN(tSlotData2) && tSlotData2 != -2) {
  2827. if (this._templet.attachmentNames) {
  2828. tDBBoneSlot.showDisplayByName(this._templet.attachmentNames[tSlotData2]);
  2829. }
  2830. else {
  2831. tDBBoneSlot.showDisplayByIndex(tSlotData2);
  2832. }
  2833. }
  2834. if (tDeformDic[i]) {
  2835. tObject = tDeformDic[i];
  2836. if (tDBBoneSlot.currDisplayData && tObject[tDBBoneSlot.currDisplayData.attachmentName]) {
  2837. tDBBoneSlot.deformData = tObject[tDBBoneSlot.currDisplayData.attachmentName];
  2838. }
  2839. else {
  2840. tDBBoneSlot.deformData = null;
  2841. }
  2842. }
  2843. else {
  2844. tDBBoneSlot.deformData = null;
  2845. }
  2846. if (!isNaN(tSlotData3)) {
  2847. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2, tSlotData3);
  2848. }
  2849. else {
  2850. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2);
  2851. }
  2852. }
  2853. }
  2854. if (this._aniMode == 0) {
  2855. this._templet.setGrahicsDataWithCache(this._aniClipIndex, _clipIndex, tGraphics);
  2856. this._checkIsAllParsed(this._aniClipIndex);
  2857. }
  2858. else if (this._aniMode == 1) {
  2859. this._setGrahicsDataWithCache(this._aniClipIndex, _clipIndex, tGraphics);
  2860. }
  2861. return tGraphics;
  2862. }
  2863. _checkIsAllParsed(_aniClipIndex) {
  2864. var i, len;
  2865. len = Math.floor(0.01 + this._templet.getAniDuration(_aniClipIndex) / 1000 * this._player.cacheFrameRate);
  2866. for (i = 0; i < len; i++) {
  2867. if (!this._templet.getGrahicsDataWithCache(_aniClipIndex, i))
  2868. return;
  2869. }
  2870. if (!this._templet.getGrahicsDataWithCache(_aniClipIndex, len)) {
  2871. this._createGraphics(len);
  2872. return;
  2873. }
  2874. this._templet.deleteAniData(_aniClipIndex);
  2875. }
  2876. _setDeform(tDeformAniData, tDeformDic, _boneSlotArray, curTime) {
  2877. if (!tDeformAniData)
  2878. return;
  2879. var tDeformSlotData;
  2880. var tDeformSlotDisplayData;
  2881. var tDBBoneSlot;
  2882. var i, n, j;
  2883. if (tDeformAniData) {
  2884. for (i = 0, n = tDeformAniData.deformSlotDataList.length; i < n; i++) {
  2885. tDeformSlotData = tDeformAniData.deformSlotDataList[i];
  2886. for (j = 0; j < tDeformSlotData.deformSlotDisplayList.length; j++) {
  2887. tDeformSlotDisplayData = tDeformSlotData.deformSlotDisplayList[j];
  2888. tDBBoneSlot = _boneSlotArray[tDeformSlotDisplayData.slotIndex];
  2889. tDeformSlotDisplayData.apply(curTime, tDBBoneSlot);
  2890. if (!tDeformDic[tDeformSlotDisplayData.slotIndex]) {
  2891. tDeformDic[tDeformSlotDisplayData.slotIndex] = {};
  2892. }
  2893. tDeformDic[tDeformSlotDisplayData.slotIndex][tDeformSlotDisplayData.attachment] = tDeformSlotDisplayData.deformData;
  2894. }
  2895. }
  2896. }
  2897. }
  2898. getAnimNum() {
  2899. return this._templet.getAnimationCount();
  2900. }
  2901. getAniNameByIndex(index) {
  2902. return this._templet.getAniNameByIndex(index);
  2903. }
  2904. getSlotByName(name) {
  2905. return this._boneSlotDic[name];
  2906. }
  2907. showSkinByName(name, freshSlotIndex = true) {
  2908. this.showSkinByIndex(this._templet.getSkinIndexByName(name), freshSlotIndex);
  2909. }
  2910. showSkinByIndex(skinIndex, freshSlotIndex = true) {
  2911. for (var i = 0; i < this._boneSlotArray.length; i++) {
  2912. this._boneSlotArray[i].showSlotData(null, freshSlotIndex);
  2913. }
  2914. if (this._templet.showSkinByIndex(this._boneSlotDic, skinIndex, freshSlotIndex)) {
  2915. var tSkinData = this._templet.skinDataArray[skinIndex];
  2916. this._skinIndex = skinIndex;
  2917. this._skinName = tSkinData.name;
  2918. }
  2919. this._clearCache();
  2920. }
  2921. showSlotSkinByIndex(slotName, index) {
  2922. if (this._aniMode == 0)
  2923. return;
  2924. var tBoneSlot = this.getSlotByName(slotName);
  2925. if (tBoneSlot) {
  2926. tBoneSlot.showDisplayByIndex(index);
  2927. }
  2928. this._clearCache();
  2929. }
  2930. showSlotSkinByName(slotName, name) {
  2931. if (this._aniMode == 0)
  2932. return;
  2933. var tBoneSlot = this.getSlotByName(slotName);
  2934. if (tBoneSlot) {
  2935. tBoneSlot.showDisplayByName(name);
  2936. }
  2937. this._clearCache();
  2938. }
  2939. replaceSlotSkinName(slotName, oldName, newName) {
  2940. if (this._aniMode == 0)
  2941. return;
  2942. var tBoneSlot = this.getSlotByName(slotName);
  2943. if (tBoneSlot) {
  2944. tBoneSlot.replaceDisplayByName(oldName, newName);
  2945. }
  2946. this._clearCache();
  2947. }
  2948. replaceSlotSkinByIndex(slotName, oldIndex, newIndex) {
  2949. if (this._aniMode == 0)
  2950. return;
  2951. var tBoneSlot = this.getSlotByName(slotName);
  2952. if (tBoneSlot) {
  2953. tBoneSlot.replaceDisplayByIndex(oldIndex, newIndex);
  2954. }
  2955. this._clearCache();
  2956. }
  2957. setSlotSkin(slotName, texture) {
  2958. if (this._aniMode == 0)
  2959. return;
  2960. var tBoneSlot = this.getSlotByName(slotName);
  2961. if (tBoneSlot) {
  2962. tBoneSlot.replaceSkin(texture);
  2963. }
  2964. this._clearCache();
  2965. }
  2966. _clearCache() {
  2967. if (this._aniMode == 1) {
  2968. for (var i = 0, n = this._graphicsCache.length; i < n; i++) {
  2969. for (var j = 0, len = this._graphicsCache[i].length; j < len; j++) {
  2970. var gp = this._graphicsCache[i][j];
  2971. if (gp && gp != this.graphics) {
  2972. GraphicsAni.recycle(gp);
  2973. }
  2974. }
  2975. this._graphicsCache[i].length = 0;
  2976. }
  2977. }
  2978. }
  2979. play(nameOrIndex, loop, force = true, start = 0, end = 0, freshSkin = true, playAudio = true) {
  2980. this._playAudio = playAudio;
  2981. this._indexControl = false;
  2982. var index = -1;
  2983. var duration;
  2984. if (loop) {
  2985. duration = 2147483647;
  2986. }
  2987. else {
  2988. duration = 0;
  2989. }
  2990. if (typeof (nameOrIndex) == 'string') {
  2991. for (var i = 0, n = this._templet.getAnimationCount(); i < n; i++) {
  2992. var animation = this._templet.getAnimation(i);
  2993. if (animation && nameOrIndex == animation.name) {
  2994. index = i;
  2995. break;
  2996. }
  2997. }
  2998. }
  2999. else {
  3000. index = nameOrIndex;
  3001. }
  3002. if (index > -1 && index < this.getAnimNum()) {
  3003. this._aniClipIndex = index;
  3004. if (force || this._pause || this._currAniIndex != index) {
  3005. this._currAniIndex = index;
  3006. this._curOriginalData = new Float32Array(this._templet.getTotalkeyframesLength(index));
  3007. this._drawOrder = null;
  3008. this._eventIndex = 0;
  3009. this._player.play(index, this._player.playbackRate, duration, start, end);
  3010. if (freshSkin)
  3011. this._templet.showSkinByIndex(this._boneSlotDic, this._skinIndex);
  3012. if (this._pause) {
  3013. this._pause = false;
  3014. this._lastTime = Laya.ILaya.Browser.now();
  3015. this.timer.frameLoop(1, this, this._update, null, true);
  3016. }
  3017. this._update();
  3018. }
  3019. }
  3020. }
  3021. stop() {
  3022. if (!this._pause) {
  3023. this._pause = true;
  3024. if (this._player) {
  3025. this._player.stop(true);
  3026. }
  3027. if (this._soundChannelArr.length > 0) {
  3028. this._onAniSoundStoped(true);
  3029. }
  3030. this.timer.clear(this, this._update);
  3031. }
  3032. }
  3033. playbackRate(value) {
  3034. if (this._player) {
  3035. this._player.playbackRate = value;
  3036. }
  3037. }
  3038. paused() {
  3039. if (!this._pause) {
  3040. this._pause = true;
  3041. if (this._player) {
  3042. this._player.paused = true;
  3043. }
  3044. if (this._soundChannelArr.length > 0) {
  3045. var _soundChannel;
  3046. for (var len = this._soundChannelArr.length, i = 0; i < len; i++) {
  3047. _soundChannel = this._soundChannelArr[i];
  3048. if (!_soundChannel.isStopped) {
  3049. _soundChannel.pause();
  3050. }
  3051. }
  3052. }
  3053. this.timer.clear(this, this._update);
  3054. }
  3055. }
  3056. resume() {
  3057. this._indexControl = false;
  3058. if (this._pause) {
  3059. this._pause = false;
  3060. if (this._player) {
  3061. this._player.paused = false;
  3062. }
  3063. if (this._soundChannelArr.length > 0) {
  3064. var _soundChannel;
  3065. for (var len = this._soundChannelArr.length, i = 0; i < len; i++) {
  3066. _soundChannel = this._soundChannelArr[i];
  3067. if (_soundChannel.audioBuffer) {
  3068. _soundChannel.resume();
  3069. }
  3070. }
  3071. }
  3072. this._lastTime = Laya.ILaya.Browser.now();
  3073. this.timer.frameLoop(1, this, this._update, null, true);
  3074. }
  3075. }
  3076. _getGrahicsDataWithCache(aniIndex, frameIndex) {
  3077. return this._graphicsCache[aniIndex][frameIndex];
  3078. }
  3079. _setGrahicsDataWithCache(aniIndex, frameIndex, graphics) {
  3080. this._graphicsCache[aniIndex][frameIndex] = graphics;
  3081. }
  3082. destroy(destroyChild = true) {
  3083. super.destroy(destroyChild);
  3084. this._templet._removeReference(1);
  3085. this._templet = null;
  3086. if (this._player)
  3087. this._player.offAll();
  3088. this._player = null;
  3089. this._curOriginalData = null;
  3090. this._boneMatrixArray.length = 0;
  3091. this._lastTime = 0;
  3092. this.timer.clear(this, this._update);
  3093. if (this._soundChannelArr.length > 0) {
  3094. this._onAniSoundStoped(true);
  3095. }
  3096. }
  3097. get index() {
  3098. return this._index;
  3099. }
  3100. set index(value) {
  3101. if (this.player) {
  3102. this._index = value;
  3103. this._player.currentTime = this._index * 1000 / this._player.cacheFrameRate;
  3104. this._indexControl = true;
  3105. this._update(false);
  3106. }
  3107. }
  3108. get total() {
  3109. if (this._templet && this._player) {
  3110. this._total = Math.floor(this._templet.getAniDuration(this._player.currentAnimationClipIndex) / 1000 * this._player.cacheFrameRate);
  3111. }
  3112. else {
  3113. this._total = -1;
  3114. }
  3115. return this._total;
  3116. }
  3117. get player() {
  3118. return this._player;
  3119. }
  3120. get templet() {
  3121. return this._templet;
  3122. }
  3123. }
  3124. Skeleton.useSimpleMeshInCanvas = false;
  3125. IAniLib.Skeleton = Skeleton;
  3126. Laya.ILaya.regClass(Skeleton);
  3127. Laya.ClassUtils.regClass("laya.ani.bone.Skeleton", Skeleton);
  3128. Laya.ClassUtils.regClass("Laya.Skeleton", Skeleton);
  3129. class SkinData {
  3130. constructor() {
  3131. this.slotArr = [];
  3132. }
  3133. }
  3134. class SkinSlotDisplayData {
  3135. createTexture(currTexture) {
  3136. if (this.texture)
  3137. return this.texture;
  3138. this.texture = new Laya.Texture(currTexture.bitmap, this.uvs);
  3139. if (this.uvs[0] > this.uvs[4]
  3140. && this.uvs[1] > this.uvs[5]) {
  3141. this.texture.width = currTexture.height;
  3142. this.texture.height = currTexture.width;
  3143. this.texture.offsetX = -currTexture.offsetX;
  3144. this.texture.offsetY = -currTexture.offsetY;
  3145. this.texture.sourceWidth = currTexture.sourceHeight;
  3146. this.texture.sourceHeight = currTexture.sourceWidth;
  3147. }
  3148. else {
  3149. this.texture.width = currTexture.width;
  3150. this.texture.height = currTexture.height;
  3151. this.texture.offsetX = -currTexture.offsetX;
  3152. this.texture.offsetY = -currTexture.offsetY;
  3153. this.texture.sourceWidth = currTexture.sourceWidth;
  3154. this.texture.sourceHeight = currTexture.sourceHeight;
  3155. }
  3156. return this.texture;
  3157. }
  3158. destory() {
  3159. if (this.texture)
  3160. this.texture.destroy();
  3161. }
  3162. }
  3163. class SlotData {
  3164. constructor() {
  3165. this.displayArr = [];
  3166. }
  3167. getDisplayByName(name) {
  3168. var tDisplay;
  3169. for (var i = 0, n = this.displayArr.length; i < n; i++) {
  3170. tDisplay = this.displayArr[i];
  3171. if (tDisplay.attachmentName == name) {
  3172. return i;
  3173. }
  3174. }
  3175. return -1;
  3176. }
  3177. }
  3178. class TfConstraintData {
  3179. constructor() {
  3180. this.boneIndexs = [];
  3181. }
  3182. }
  3183. class Templet extends AnimationTemplet {
  3184. constructor() {
  3185. super(...arguments);
  3186. this._graphicsCache = [];
  3187. this.srcBoneMatrixArr = [];
  3188. this.ikArr = [];
  3189. this.tfArr = [];
  3190. this.pathArr = [];
  3191. this.boneSlotDic = {};
  3192. this.bindBoneBoneSlotDic = {};
  3193. this.boneSlotArray = [];
  3194. this.skinDataArray = [];
  3195. this.skinDic = {};
  3196. this.subTextureDic = {};
  3197. this.isParseFail = false;
  3198. this.drawOrderAniArr = [];
  3199. this.eventAniArr = [];
  3200. this.attachmentNames = null;
  3201. this.deformAniArr = [];
  3202. this.skinSlotDisplayDataArr = [];
  3203. this._isParseAudio = false;
  3204. this._isDestroyed = false;
  3205. this._rate = 30;
  3206. this.isParserComplete = false;
  3207. this.aniSectionDic = {};
  3208. this._textureDic = {};
  3209. this.mBoneArr = [];
  3210. }
  3211. loadAni(url) {
  3212. this._skBufferUrl = url;
  3213. Laya.ILaya.loader.load(url, Laya.Handler.create(this, this.onComplete), null, Laya.ILaya.Loader.BUFFER);
  3214. }
  3215. onComplete(content = null) {
  3216. if (this._isDestroyed) {
  3217. this.destroy();
  3218. return;
  3219. }
  3220. var tSkBuffer = Laya.ILaya.Loader.getRes(this._skBufferUrl);
  3221. if (!tSkBuffer) {
  3222. this.event(Laya.Event.ERROR, "load failed:" + this._skBufferUrl);
  3223. return;
  3224. }
  3225. this._path = this._skBufferUrl.slice(0, this._skBufferUrl.lastIndexOf("/")) + "/";
  3226. this.parseData(null, tSkBuffer);
  3227. }
  3228. parseData(texture, skeletonData, playbackRate = 30) {
  3229. if (!this._path) {
  3230. var s1 = (this._relativeUrl || this.url);
  3231. if (s1) {
  3232. var p1 = s1.lastIndexOf('/');
  3233. if (p1 > 0) {
  3234. this._path = s1.slice(0, p1) + "/";
  3235. }
  3236. else {
  3237. this._path = '';
  3238. }
  3239. }
  3240. }
  3241. this._mainTexture = texture;
  3242. this._rate = playbackRate;
  3243. this.parse(skeletonData);
  3244. }
  3245. buildArmature(aniMode = 0) {
  3246. return new Skeleton(this, aniMode);
  3247. }
  3248. parse(data) {
  3249. super.parse(data);
  3250. this.event(Laya.Event.LOADED, this);
  3251. if (this._aniVersion === Templet.LAYA_ANIMATION_VISION) {
  3252. this._isParseAudio = true;
  3253. }
  3254. else if (this._aniVersion != Templet.LAYA_ANIMATION_160_VISION) {
  3255. console.log("[Error] 版本不一致,请使用IDE版本配套的重新导出" + this._aniVersion + "->" + Templet.LAYA_ANIMATION_VISION);
  3256. }
  3257. if (this._mainTexture) {
  3258. this._parsePublicExtData();
  3259. }
  3260. else {
  3261. this._parseTexturePath();
  3262. }
  3263. }
  3264. _parseTexturePath() {
  3265. if (this._isDestroyed) {
  3266. this.destroy();
  3267. return;
  3268. }
  3269. var i = 0;
  3270. this._loadList = [];
  3271. var tByte = new Laya.Byte(this.getPublicExtData());
  3272. var tX = 0, tY = 0, tWidth = 0, tHeight = 0;
  3273. var tTempleData = 0;
  3274. var tTextureLen = tByte.getInt32();
  3275. var tTextureName = tByte.readUTFString();
  3276. var tTextureNameArr = tTextureName.split("\n");
  3277. var tSrcTexturePath;
  3278. for (i = 0; i < tTextureLen; i++) {
  3279. tSrcTexturePath = this._path + tTextureNameArr[i * 2];
  3280. tTextureName = tTextureNameArr[i * 2 + 1];
  3281. tX = tByte.getFloat32();
  3282. tY = tByte.getFloat32();
  3283. tWidth = tByte.getFloat32();
  3284. tHeight = tByte.getFloat32();
  3285. tTempleData = tByte.getFloat32();
  3286. tTempleData = tByte.getFloat32();
  3287. tTempleData = tByte.getFloat32();
  3288. tTempleData = tByte.getFloat32();
  3289. if (this._loadList.indexOf(tSrcTexturePath) == -1) {
  3290. this._loadList.push(tSrcTexturePath);
  3291. }
  3292. }
  3293. Laya.ILaya.loader.load(this._loadList, Laya.Handler.create(this, this._textureComplete));
  3294. }
  3295. _textureComplete() {
  3296. var tTexture;
  3297. var tTextureName;
  3298. for (var i = 0, n = this._loadList.length; i < n; i++) {
  3299. tTextureName = this._loadList[i];
  3300. tTexture = this._textureDic[tTextureName] = Laya.ILaya.Loader.getRes(tTextureName);
  3301. }
  3302. this._parsePublicExtData();
  3303. }
  3304. _parsePublicExtData() {
  3305. var i = 0, j = 0, k = 0, l = 0, n = 0;
  3306. for (i = 0, n = this.getAnimationCount(); i < n; i++) {
  3307. this._graphicsCache.push([]);
  3308. }
  3309. var isSpine;
  3310. isSpine = this._aniClassName != "Dragon";
  3311. var tByte = new Laya.Byte(this.getPublicExtData());
  3312. var tX = 0, tY = 0, tWidth = 0, tHeight = 0;
  3313. var tFrameX = 0, tFrameY = 0, tFrameWidth = 0, tFrameHeight = 0;
  3314. var tTempleData = 0;
  3315. var tTextureLen = tByte.getInt32();
  3316. var tTextureName = tByte.readUTFString();
  3317. var tTextureNameArr = tTextureName.split("\n");
  3318. var tTexture;
  3319. var tSrcTexturePath;
  3320. for (i = 0; i < tTextureLen; i++) {
  3321. tTexture = this._mainTexture;
  3322. tSrcTexturePath = this._path + tTextureNameArr[i * 2];
  3323. tTextureName = tTextureNameArr[i * 2 + 1];
  3324. if (this._mainTexture == null) {
  3325. tTexture = this._textureDic[tSrcTexturePath];
  3326. }
  3327. if (!tTexture) {
  3328. this.event(Laya.Event.ERROR, this);
  3329. this.isParseFail = true;
  3330. return;
  3331. }
  3332. tX = tByte.getFloat32();
  3333. tY = tByte.getFloat32();
  3334. tWidth = tByte.getFloat32();
  3335. tHeight = tByte.getFloat32();
  3336. tTempleData = tByte.getFloat32();
  3337. tFrameX = isNaN(tTempleData) ? 0 : tTempleData;
  3338. tTempleData = tByte.getFloat32();
  3339. tFrameY = isNaN(tTempleData) ? 0 : tTempleData;
  3340. tTempleData = tByte.getFloat32();
  3341. tFrameWidth = isNaN(tTempleData) ? tWidth : tTempleData;
  3342. tTempleData = tByte.getFloat32();
  3343. tFrameHeight = isNaN(tTempleData) ? tHeight : tTempleData;
  3344. this.subTextureDic[tTextureName] = Laya.Texture.create(tTexture, tX, tY, tWidth, tHeight, -tFrameX, -tFrameY, tFrameWidth, tFrameHeight);
  3345. }
  3346. this._mainTexture = tTexture;
  3347. var tAniCount = tByte.getUint16();
  3348. var tSectionArr;
  3349. for (i = 0; i < tAniCount; i++) {
  3350. tSectionArr = [];
  3351. tSectionArr.push(tByte.getUint16());
  3352. tSectionArr.push(tByte.getUint16());
  3353. tSectionArr.push(tByte.getUint16());
  3354. tSectionArr.push(tByte.getUint16());
  3355. this.aniSectionDic[i] = tSectionArr;
  3356. }
  3357. var tBone;
  3358. var tParentBone;
  3359. var tName;
  3360. var tParentName;
  3361. var tBoneLen = tByte.getInt16();
  3362. var tBoneDic = {};
  3363. var tRootBone;
  3364. for (i = 0; i < tBoneLen; i++) {
  3365. tBone = new Bone();
  3366. if (i == 0) {
  3367. tRootBone = tBone;
  3368. }
  3369. else {
  3370. tBone.root = tRootBone;
  3371. }
  3372. tBone.d = isSpine ? -1 : 1;
  3373. tName = tByte.readUTFString();
  3374. tParentName = tByte.readUTFString();
  3375. tBone.length = tByte.getFloat32();
  3376. if (tByte.getByte() == 1) {
  3377. tBone.inheritRotation = false;
  3378. }
  3379. if (tByte.getByte() == 1) {
  3380. tBone.inheritScale = false;
  3381. }
  3382. tBone.name = tName;
  3383. if (tParentName) {
  3384. tParentBone = tBoneDic[tParentName];
  3385. if (tParentBone) {
  3386. tParentBone.addChild(tBone);
  3387. }
  3388. else {
  3389. this.mRootBone = tBone;
  3390. }
  3391. }
  3392. tBoneDic[tName] = tBone;
  3393. this.mBoneArr.push(tBone);
  3394. }
  3395. this.tMatrixDataLen = tByte.getUint16();
  3396. var tLen = tByte.getUint16();
  3397. var boneLength = Math.floor(tLen / this.tMatrixDataLen);
  3398. var tResultTransform;
  3399. var tMatrixArray = this.srcBoneMatrixArr;
  3400. for (i = 0; i < boneLength; i++) {
  3401. tResultTransform = new Transform();
  3402. tResultTransform.scX = tByte.getFloat32();
  3403. tResultTransform.skX = tByte.getFloat32();
  3404. tResultTransform.skY = tByte.getFloat32();
  3405. tResultTransform.scY = tByte.getFloat32();
  3406. tResultTransform.x = tByte.getFloat32();
  3407. tResultTransform.y = tByte.getFloat32();
  3408. if (this.tMatrixDataLen === 8) {
  3409. tResultTransform.skewX = tByte.getFloat32();
  3410. tResultTransform.skewY = tByte.getFloat32();
  3411. }
  3412. tMatrixArray.push(tResultTransform);
  3413. tBone = this.mBoneArr[i];
  3414. tBone.transform = tResultTransform;
  3415. }
  3416. var tIkConstraintData;
  3417. var tIkLen = tByte.getUint16();
  3418. var tIkBoneLen;
  3419. for (i = 0; i < tIkLen; i++) {
  3420. tIkConstraintData = new IkConstraintData();
  3421. tIkBoneLen = tByte.getUint16();
  3422. for (j = 0; j < tIkBoneLen; j++) {
  3423. tIkConstraintData.boneNames.push(tByte.readUTFString());
  3424. tIkConstraintData.boneIndexs.push(tByte.getInt16());
  3425. }
  3426. tIkConstraintData.name = tByte.readUTFString();
  3427. tIkConstraintData.targetBoneName = tByte.readUTFString();
  3428. tIkConstraintData.targetBoneIndex = tByte.getInt16();
  3429. tIkConstraintData.bendDirection = tByte.getFloat32();
  3430. tIkConstraintData.mix = tByte.getFloat32();
  3431. tIkConstraintData.isSpine = isSpine;
  3432. this.ikArr.push(tIkConstraintData);
  3433. }
  3434. var tTfConstraintData;
  3435. var tTfLen = tByte.getUint16();
  3436. var tTfBoneLen;
  3437. for (i = 0; i < tTfLen; i++) {
  3438. tTfConstraintData = new TfConstraintData();
  3439. tTfBoneLen = tByte.getUint16();
  3440. for (j = 0; j < tTfBoneLen; j++) {
  3441. tTfConstraintData.boneIndexs.push(tByte.getInt16());
  3442. }
  3443. tTfConstraintData.name = tByte.getUTFString();
  3444. tTfConstraintData.targetIndex = tByte.getInt16();
  3445. tTfConstraintData.rotateMix = tByte.getFloat32();
  3446. tTfConstraintData.translateMix = tByte.getFloat32();
  3447. tTfConstraintData.scaleMix = tByte.getFloat32();
  3448. tTfConstraintData.shearMix = tByte.getFloat32();
  3449. tTfConstraintData.offsetRotation = tByte.getFloat32();
  3450. tTfConstraintData.offsetX = tByte.getFloat32();
  3451. tTfConstraintData.offsetY = tByte.getFloat32();
  3452. tTfConstraintData.offsetScaleX = tByte.getFloat32();
  3453. tTfConstraintData.offsetScaleY = tByte.getFloat32();
  3454. tTfConstraintData.offsetShearY = tByte.getFloat32();
  3455. this.tfArr.push(tTfConstraintData);
  3456. }
  3457. var tPathConstraintData;
  3458. var tPathLen = tByte.getUint16();
  3459. var tPathBoneLen;
  3460. for (i = 0; i < tPathLen; i++) {
  3461. tPathConstraintData = new PathConstraintData();
  3462. tPathConstraintData.name = tByte.readUTFString();
  3463. tPathBoneLen = tByte.getUint16();
  3464. for (j = 0; j < tPathBoneLen; j++) {
  3465. tPathConstraintData.bones.push(tByte.getInt16());
  3466. }
  3467. tPathConstraintData.target = tByte.readUTFString();
  3468. tPathConstraintData.positionMode = tByte.readUTFString();
  3469. tPathConstraintData.spacingMode = tByte.readUTFString();
  3470. tPathConstraintData.rotateMode = tByte.readUTFString();
  3471. tPathConstraintData.offsetRotation = tByte.getFloat32();
  3472. tPathConstraintData.position = tByte.getFloat32();
  3473. tPathConstraintData.spacing = tByte.getFloat32();
  3474. tPathConstraintData.rotateMix = tByte.getFloat32();
  3475. tPathConstraintData.translateMix = tByte.getFloat32();
  3476. this.pathArr.push(tPathConstraintData);
  3477. }
  3478. var tDeformSlotLen;
  3479. var tDeformSlotDisplayLen;
  3480. var tDSlotIndex;
  3481. var tDAttachment;
  3482. var tDeformTimeLen;
  3483. var tDTime;
  3484. var tDeformVecticesLen;
  3485. var tDeformAniData;
  3486. var tDeformSlotData;
  3487. var tDeformSlotDisplayData;
  3488. var tDeformVectices;
  3489. var tDeformAniLen = tByte.getInt16();
  3490. for (i = 0; i < tDeformAniLen; i++) {
  3491. var tDeformSkinLen = tByte.getUint8();
  3492. var tSkinDic = {};
  3493. this.deformAniArr.push(tSkinDic);
  3494. for (var f = 0; f < tDeformSkinLen; f++) {
  3495. tDeformAniData = new DeformAniData();
  3496. tDeformAniData.skinName = tByte.getUTFString();
  3497. tSkinDic[tDeformAniData.skinName] = tDeformAniData;
  3498. tDeformSlotLen = tByte.getInt16();
  3499. for (j = 0; j < tDeformSlotLen; j++) {
  3500. tDeformSlotData = new DeformSlotData();
  3501. tDeformAniData.deformSlotDataList.push(tDeformSlotData);
  3502. tDeformSlotDisplayLen = tByte.getInt16();
  3503. for (k = 0; k < tDeformSlotDisplayLen; k++) {
  3504. tDeformSlotDisplayData = new DeformSlotDisplayData();
  3505. tDeformSlotData.deformSlotDisplayList.push(tDeformSlotDisplayData);
  3506. tDeformSlotDisplayData.slotIndex = tDSlotIndex = tByte.getInt16();
  3507. tDeformSlotDisplayData.attachment = tDAttachment = tByte.getUTFString();
  3508. tDeformTimeLen = tByte.getInt16();
  3509. for (l = 0; l < tDeformTimeLen; l++) {
  3510. if (tByte.getByte() == 1) {
  3511. tDeformSlotDisplayData.tweenKeyList.push(true);
  3512. }
  3513. else {
  3514. tDeformSlotDisplayData.tweenKeyList.push(false);
  3515. }
  3516. tDTime = tByte.getFloat32();
  3517. tDeformSlotDisplayData.timeList.push(tDTime);
  3518. tDeformVectices = [];
  3519. tDeformSlotDisplayData.vectices.push(tDeformVectices);
  3520. tDeformVecticesLen = tByte.getInt16();
  3521. for (n = 0; n < tDeformVecticesLen; n++) {
  3522. tDeformVectices.push(tByte.getFloat32());
  3523. }
  3524. }
  3525. }
  3526. }
  3527. }
  3528. }
  3529. var tDrawOrderArr;
  3530. var tDrawOrderAniLen = tByte.getInt16();
  3531. var tDrawOrderLen;
  3532. var tDrawOrderData;
  3533. var tDoLen;
  3534. for (i = 0; i < tDrawOrderAniLen; i++) {
  3535. tDrawOrderLen = tByte.getInt16();
  3536. tDrawOrderArr = [];
  3537. for (j = 0; j < tDrawOrderLen; j++) {
  3538. tDrawOrderData = new DrawOrderData();
  3539. tDrawOrderData.time = tByte.getFloat32();
  3540. tDoLen = tByte.getInt16();
  3541. for (k = 0; k < tDoLen; k++) {
  3542. tDrawOrderData.drawOrder.push(tByte.getInt16());
  3543. }
  3544. tDrawOrderArr.push(tDrawOrderData);
  3545. }
  3546. this.drawOrderAniArr.push(tDrawOrderArr);
  3547. }
  3548. var tEventArr;
  3549. var tEventAniLen = tByte.getInt16();
  3550. var tEventLen;
  3551. var tEventData;
  3552. for (i = 0; i < tEventAniLen; i++) {
  3553. tEventLen = tByte.getInt16();
  3554. tEventArr = [];
  3555. for (j = 0; j < tEventLen; j++) {
  3556. tEventData = new EventData();
  3557. tEventData.name = tByte.getUTFString();
  3558. if (this._isParseAudio)
  3559. tEventData.audioValue = tByte.getUTFString();
  3560. tEventData.intValue = tByte.getInt32();
  3561. tEventData.floatValue = tByte.getFloat32();
  3562. tEventData.stringValue = tByte.getUTFString();
  3563. tEventData.time = tByte.getFloat32();
  3564. tEventArr.push(tEventData);
  3565. }
  3566. this.eventAniArr.push(tEventArr);
  3567. }
  3568. var tAttachmentLen = tByte.getInt16();
  3569. if (tAttachmentLen > 0) {
  3570. this.attachmentNames = [];
  3571. for (i = 0; i < tAttachmentLen; i++) {
  3572. this.attachmentNames.push(tByte.getUTFString());
  3573. }
  3574. }
  3575. var tBoneSlotLen = tByte.getInt16();
  3576. var tDBBoneSlot;
  3577. var tDBBoneSlotArr;
  3578. for (i = 0; i < tBoneSlotLen; i++) {
  3579. tDBBoneSlot = new BoneSlot();
  3580. tDBBoneSlot.name = tByte.readUTFString();
  3581. tDBBoneSlot.parent = tByte.readUTFString();
  3582. tDBBoneSlot.attachmentName = tByte.readUTFString();
  3583. tDBBoneSlot.srcDisplayIndex = tDBBoneSlot.displayIndex = tByte.getInt16();
  3584. tDBBoneSlot.templet = this;
  3585. this.boneSlotDic[tDBBoneSlot.name] = tDBBoneSlot;
  3586. tDBBoneSlotArr = this.bindBoneBoneSlotDic[tDBBoneSlot.parent];
  3587. if (tDBBoneSlotArr == null) {
  3588. this.bindBoneBoneSlotDic[tDBBoneSlot.parent] = tDBBoneSlotArr = [];
  3589. }
  3590. tDBBoneSlotArr.push(tDBBoneSlot);
  3591. this.boneSlotArray.push(tDBBoneSlot);
  3592. }
  3593. var tNameString = tByte.readUTFString();
  3594. var tNameArray = tNameString.split("\n");
  3595. var tNameStartIndex = 0;
  3596. var tSkinDataLen = tByte.getUint8();
  3597. var tSkinData, tSlotData, tDisplayData;
  3598. var tSlotDataLen, tDisplayDataLen;
  3599. var tUvLen, tWeightLen, tTriangleLen, tVerticeLen, tLengthLen;
  3600. for (i = 0; i < tSkinDataLen; i++) {
  3601. tSkinData = new SkinData();
  3602. tSkinData.name = tNameArray[tNameStartIndex++];
  3603. tSlotDataLen = tByte.getUint8();
  3604. for (j = 0; j < tSlotDataLen; j++) {
  3605. tSlotData = new SlotData();
  3606. tSlotData.name = tNameArray[tNameStartIndex++];
  3607. tDBBoneSlot = this.boneSlotDic[tSlotData.name];
  3608. tDisplayDataLen = tByte.getUint8();
  3609. for (k = 0; k < tDisplayDataLen; k++) {
  3610. tDisplayData = new SkinSlotDisplayData();
  3611. this.skinSlotDisplayDataArr.push(tDisplayData);
  3612. tDisplayData.name = tNameArray[tNameStartIndex++];
  3613. tDisplayData.attachmentName = tNameArray[tNameStartIndex++];
  3614. tDisplayData.transform = new Transform();
  3615. tDisplayData.transform.scX = tByte.getFloat32();
  3616. tDisplayData.transform.skX = tByte.getFloat32();
  3617. tDisplayData.transform.skY = tByte.getFloat32();
  3618. tDisplayData.transform.scY = tByte.getFloat32();
  3619. tDisplayData.transform.x = tByte.getFloat32();
  3620. tDisplayData.transform.y = tByte.getFloat32();
  3621. tSlotData.displayArr.push(tDisplayData);
  3622. tDisplayData.width = tByte.getFloat32();
  3623. tDisplayData.height = tByte.getFloat32();
  3624. tDisplayData.type = tByte.getUint8();
  3625. tDisplayData.verLen = tByte.getUint16();
  3626. tBoneLen = tByte.getUint16();
  3627. if (tBoneLen > 0) {
  3628. tDisplayData.bones = [];
  3629. for (l = 0; l < tBoneLen; l++) {
  3630. var tBoneId = tByte.getUint16();
  3631. tDisplayData.bones.push(tBoneId);
  3632. }
  3633. }
  3634. tUvLen = tByte.getUint16();
  3635. if (tUvLen > 0) {
  3636. tDisplayData.uvs = [];
  3637. for (l = 0; l < tUvLen; l++) {
  3638. tDisplayData.uvs.push(tByte.getFloat32());
  3639. }
  3640. }
  3641. tWeightLen = tByte.getUint16();
  3642. if (tWeightLen > 0) {
  3643. tDisplayData.weights = [];
  3644. for (l = 0; l < tWeightLen; l++) {
  3645. tDisplayData.weights.push(tByte.getFloat32());
  3646. }
  3647. }
  3648. tTriangleLen = tByte.getUint16();
  3649. if (tTriangleLen > 0) {
  3650. tDisplayData.triangles = [];
  3651. for (l = 0; l < tTriangleLen; l++) {
  3652. tDisplayData.triangles.push(tByte.getUint16());
  3653. }
  3654. }
  3655. tVerticeLen = tByte.getUint16();
  3656. if (tVerticeLen > 0) {
  3657. tDisplayData.vertices = [];
  3658. for (l = 0; l < tVerticeLen; l++) {
  3659. tDisplayData.vertices.push(tByte.getFloat32());
  3660. }
  3661. }
  3662. tLengthLen = tByte.getUint16();
  3663. if (tLengthLen > 0) {
  3664. tDisplayData.lengths = [];
  3665. for (l = 0; l < tLengthLen; l++) {
  3666. tDisplayData.lengths.push(tByte.getFloat32());
  3667. }
  3668. }
  3669. }
  3670. tSkinData.slotArr.push(tSlotData);
  3671. }
  3672. this.skinDic[tSkinData.name] = tSkinData;
  3673. this.skinDataArray.push(tSkinData);
  3674. }
  3675. var tReverse = tByte.getUint8();
  3676. if (tReverse == 1) {
  3677. this.yReverseMatrix = new Laya.Matrix(1, 0, 0, -1, 0, 0);
  3678. if (tRootBone) {
  3679. tRootBone.setTempMatrix(this.yReverseMatrix);
  3680. }
  3681. }
  3682. else {
  3683. if (tRootBone) {
  3684. tRootBone.setTempMatrix(new Laya.Matrix());
  3685. }
  3686. }
  3687. this.showSkinByIndex(this.boneSlotDic, 0);
  3688. this.isParserComplete = true;
  3689. this.event(Laya.Event.COMPLETE, this);
  3690. }
  3691. getTexture(name) {
  3692. var tTexture = this.subTextureDic[name];
  3693. if (!tTexture) {
  3694. tTexture = this.subTextureDic[name.substr(0, name.length - 1)];
  3695. }
  3696. if (tTexture == null) {
  3697. return this._mainTexture;
  3698. }
  3699. return tTexture;
  3700. }
  3701. showSkinByIndex(boneSlotDic, skinIndex, freshDisplayIndex = true) {
  3702. if (skinIndex < 0 && skinIndex >= this.skinDataArray.length)
  3703. return false;
  3704. var i, n;
  3705. var tBoneSlot;
  3706. var tSlotData;
  3707. var tSkinData = this.skinDataArray[skinIndex];
  3708. if (tSkinData) {
  3709. for (i = 0, n = tSkinData.slotArr.length; i < n; i++) {
  3710. tSlotData = tSkinData.slotArr[i];
  3711. if (tSlotData) {
  3712. tBoneSlot = boneSlotDic[tSlotData.name];
  3713. if (tBoneSlot) {
  3714. tBoneSlot.showSlotData(tSlotData, freshDisplayIndex);
  3715. if (freshDisplayIndex && tBoneSlot.attachmentName != "undefined" && tBoneSlot.attachmentName != "null") {
  3716. tBoneSlot.showDisplayByName(tBoneSlot.attachmentName);
  3717. }
  3718. else {
  3719. tBoneSlot.showDisplayByIndex(tBoneSlot.displayIndex);
  3720. }
  3721. }
  3722. }
  3723. }
  3724. return true;
  3725. }
  3726. return false;
  3727. }
  3728. getSkinIndexByName(skinName) {
  3729. var tSkinData;
  3730. for (var i = 0, n = this.skinDataArray.length; i < n; i++) {
  3731. tSkinData = this.skinDataArray[i];
  3732. if (tSkinData.name == skinName) {
  3733. return i;
  3734. }
  3735. }
  3736. return -1;
  3737. }
  3738. getGrahicsDataWithCache(aniIndex, frameIndex) {
  3739. if (this._graphicsCache[aniIndex] && this._graphicsCache[aniIndex][frameIndex]) {
  3740. return this._graphicsCache[aniIndex][frameIndex];
  3741. }
  3742. return null;
  3743. }
  3744. _setCreateURL(url) {
  3745. this._skBufferUrl = this._relativeUrl = url;
  3746. super._setCreateURL(url);
  3747. }
  3748. setGrahicsDataWithCache(aniIndex, frameIndex, graphics) {
  3749. this._graphicsCache[aniIndex][frameIndex] = graphics;
  3750. }
  3751. deleteAniData(aniIndex) {
  3752. if (this._anis[aniIndex]) {
  3753. var tAniDataO = this._anis[aniIndex];
  3754. tAniDataO.bone3DMap = null;
  3755. tAniDataO.nodes = null;
  3756. }
  3757. }
  3758. destroy() {
  3759. this._isDestroyed = true;
  3760. var tTexture;
  3761. for (tTexture in this.subTextureDic) {
  3762. if (tTexture) {
  3763. this.subTextureDic[tTexture].destroy();
  3764. }
  3765. }
  3766. for (tTexture in this._textureDic) {
  3767. if (tTexture) {
  3768. this._textureDic[tTexture].destroy();
  3769. }
  3770. }
  3771. var tSkinSlotDisplayData;
  3772. for (var i = 0, n = this.skinSlotDisplayDataArr.length; i < n; i++) {
  3773. tSkinSlotDisplayData = this.skinSlotDisplayDataArr[i];
  3774. tSkinSlotDisplayData.destory();
  3775. }
  3776. this.skinSlotDisplayDataArr.length = 0;
  3777. if (this._relativeUrl) {
  3778. delete Templet.TEMPLET_DICTIONARY[this._relativeUrl];
  3779. }
  3780. super.destroy();
  3781. Laya.ILaya.loader.clearRes(this._skBufferUrl);
  3782. }
  3783. getAniNameByIndex(index) {
  3784. var tAni = this.getAnimation(index);
  3785. if (tAni)
  3786. return tAni.name;
  3787. return null;
  3788. }
  3789. get rate() {
  3790. return this._rate;
  3791. }
  3792. set rate(v) {
  3793. this._rate = v;
  3794. }
  3795. }
  3796. Templet.LAYA_ANIMATION_160_VISION = "LAYAANIMATION:1.6.0";
  3797. Templet.LAYA_ANIMATION_VISION = "LAYAANIMATION:1.7.0";
  3798. IAniLib.Templet = Templet;
  3799. class MovieClip extends Laya.Sprite {
  3800. constructor(parentMovieClip = null) {
  3801. super();
  3802. this._start = 0;
  3803. this._Pos = 0;
  3804. this._ended = true;
  3805. this._loadedImage = {};
  3806. this._endFrame = -1;
  3807. this.interval = 30;
  3808. this._ids = {};
  3809. this._idOfSprite = [];
  3810. this._reset();
  3811. this._playing = false;
  3812. this._parentMovieClip = parentMovieClip;
  3813. if (!parentMovieClip) {
  3814. this._movieClipList = [this];
  3815. this._isRoot = true;
  3816. this._setBitUp(Laya.Const.DISPLAY);
  3817. }
  3818. else {
  3819. this._isRoot = false;
  3820. this._movieClipList = parentMovieClip._movieClipList;
  3821. this._movieClipList.push(this);
  3822. }
  3823. }
  3824. destroy(destroyChild = true) {
  3825. this._clear();
  3826. super.destroy(destroyChild);
  3827. }
  3828. _setDisplay(value) {
  3829. super._setDisplay(value);
  3830. if (this._isRoot) {
  3831. this._onDisplay(value);
  3832. }
  3833. }
  3834. _onDisplay(value) {
  3835. if (value)
  3836. this.timer.loop(this.interval, this, this.updates, null, true);
  3837. else
  3838. this.timer.clear(this, this.updates);
  3839. }
  3840. updates() {
  3841. if (this._parentMovieClip)
  3842. return;
  3843. var i, len;
  3844. len = this._movieClipList.length;
  3845. for (i = 0; i < len; i++) {
  3846. this._movieClipList[i] && this._movieClipList[i]._update();
  3847. }
  3848. }
  3849. get index() {
  3850. return this._playIndex;
  3851. }
  3852. set index(value) {
  3853. this._playIndex = value;
  3854. if (this._data)
  3855. this._displayFrame(this._playIndex);
  3856. if (this._labels && this._labels[value])
  3857. this.event(Laya.Event.LABEL, this._labels[value]);
  3858. }
  3859. addLabel(label, index) {
  3860. if (!this._labels)
  3861. this._labels = {};
  3862. this._labels[index] = label;
  3863. }
  3864. removeLabel(label) {
  3865. if (!label)
  3866. this._labels = null;
  3867. else if (!this._labels) {
  3868. for (var name in this._labels) {
  3869. if (this._labels[name] === label) {
  3870. delete this._labels[name];
  3871. break;
  3872. }
  3873. }
  3874. }
  3875. }
  3876. get count() {
  3877. return this._count;
  3878. }
  3879. get playing() {
  3880. return this._playing;
  3881. }
  3882. _update() {
  3883. if (!this._data)
  3884. return;
  3885. if (!this._playing)
  3886. return;
  3887. this._playIndex++;
  3888. if (this._playIndex >= this._count) {
  3889. if (!this.loop) {
  3890. this._playIndex--;
  3891. this.stop();
  3892. return;
  3893. }
  3894. this._playIndex = 0;
  3895. }
  3896. this._parseFrame(this._playIndex);
  3897. if (this._labels && this._labels[this._playIndex])
  3898. this.event(Laya.Event.LABEL, this._labels[this._playIndex]);
  3899. if (this._endFrame != -1 && this._endFrame == this._playIndex) {
  3900. this._endFrame = -1;
  3901. if (this._completeHandler != null) {
  3902. var handler = this._completeHandler;
  3903. this._completeHandler = null;
  3904. handler.run();
  3905. }
  3906. this.stop();
  3907. }
  3908. }
  3909. stop() {
  3910. this._playing = false;
  3911. }
  3912. gotoAndStop(index) {
  3913. this.index = index;
  3914. this.stop();
  3915. }
  3916. _clear() {
  3917. this.stop();
  3918. this._idOfSprite.length = 0;
  3919. if (!this._parentMovieClip) {
  3920. this.timer.clear(this, this.updates);
  3921. var i, len;
  3922. len = this._movieClipList.length;
  3923. for (i = 0; i < len; i++) {
  3924. if (this._movieClipList[i] != this)
  3925. this._movieClipList[i]._clear();
  3926. }
  3927. this._movieClipList.length = 0;
  3928. }
  3929. if (this._atlasPath) {
  3930. Laya.ILaya.Loader.clearRes(this._atlasPath);
  3931. }
  3932. var key;
  3933. for (key in this._loadedImage) {
  3934. if (this._loadedImage[key]) {
  3935. Laya.ILaya.Loader.clearRes(key);
  3936. this._loadedImage[key] = false;
  3937. }
  3938. }
  3939. this.removeChildren();
  3940. this.graphics = null;
  3941. this._parentMovieClip = null;
  3942. }
  3943. play(index = 0, loop = true) {
  3944. this.loop = loop;
  3945. this._playing = true;
  3946. if (this._data)
  3947. this._displayFrame(index);
  3948. }
  3949. _displayFrame(frameIndex = -1) {
  3950. if (frameIndex != -1) {
  3951. if (this._curIndex > frameIndex)
  3952. this._reset();
  3953. this._parseFrame(frameIndex);
  3954. }
  3955. }
  3956. _reset(rm = true) {
  3957. if (rm && this._curIndex != 1)
  3958. this.removeChildren();
  3959. this._preIndex = this._curIndex = -1;
  3960. this._Pos = this._start;
  3961. }
  3962. _parseFrame(frameIndex) {
  3963. var mc, sp, key, type, tPos, ttype, ifAdd = false;
  3964. var _idOfSprite = this._idOfSprite, _data = this._data, eStr;
  3965. if (this._ended)
  3966. this._reset();
  3967. _data.pos = this._Pos;
  3968. this._ended = false;
  3969. this._playIndex = frameIndex;
  3970. if (this._curIndex > frameIndex && frameIndex < this._preIndex) {
  3971. this._reset(true);
  3972. _data.pos = this._Pos;
  3973. }
  3974. while ((this._curIndex <= frameIndex) && (!this._ended)) {
  3975. type = _data.getUint16();
  3976. switch (type) {
  3977. case 12:
  3978. key = _data.getUint16();
  3979. tPos = this._ids[_data.getUint16()];
  3980. this._Pos = _data.pos;
  3981. _data.pos = tPos;
  3982. if ((ttype = _data.getUint8()) == 0) {
  3983. var pid = _data.getUint16();
  3984. sp = _idOfSprite[key];
  3985. if (!sp) {
  3986. sp = _idOfSprite[key] = new Laya.Sprite();
  3987. var spp = new Laya.Sprite();
  3988. spp.loadImage(this.basePath + pid + ".png");
  3989. this._loadedImage[this.basePath + pid + ".png"] = true;
  3990. sp.addChild(spp);
  3991. spp.size(_data.getFloat32(), _data.getFloat32());
  3992. var mat = _data._getMatrix();
  3993. spp.transform = mat;
  3994. }
  3995. sp.alpha = 1;
  3996. }
  3997. else if (ttype == 1) {
  3998. mc = _idOfSprite[key];
  3999. if (!mc) {
  4000. _idOfSprite[key] = mc = new MovieClip(this);
  4001. mc.interval = this.interval;
  4002. mc._ids = this._ids;
  4003. mc.basePath = this.basePath;
  4004. mc._setData(_data, tPos);
  4005. mc._initState();
  4006. mc.play(0);
  4007. }
  4008. mc.alpha = 1;
  4009. }
  4010. _data.pos = this._Pos;
  4011. break;
  4012. case 3:
  4013. var node = _idOfSprite[_data.getUint16()];
  4014. if (node) {
  4015. this.addChild(node);
  4016. node.zOrder = _data.getUint16();
  4017. ifAdd = true;
  4018. }
  4019. break;
  4020. case 4:
  4021. node = _idOfSprite[_data.getUint16()];
  4022. node && node.removeSelf();
  4023. break;
  4024. case 5:
  4025. _idOfSprite[_data.getUint16()][MovieClip._ValueList[_data.getUint16()]] = (_data.getFloat32());
  4026. break;
  4027. case 6:
  4028. _idOfSprite[_data.getUint16()].visible = (_data.getUint8() > 0);
  4029. break;
  4030. case 7:
  4031. sp = _idOfSprite[_data.getUint16()];
  4032. var mt = sp.transform || Laya.Matrix.create();
  4033. mt.setTo(_data.getFloat32(), _data.getFloat32(), _data.getFloat32(), _data.getFloat32(), _data.getFloat32(), _data.getFloat32());
  4034. sp.transform = mt;
  4035. break;
  4036. case 8:
  4037. _idOfSprite[_data.getUint16()].setPos(_data.getFloat32(), _data.getFloat32());
  4038. break;
  4039. case 9:
  4040. _idOfSprite[_data.getUint16()].setSize(_data.getFloat32(), _data.getFloat32());
  4041. break;
  4042. case 10:
  4043. _idOfSprite[_data.getUint16()].alpha = _data.getFloat32();
  4044. break;
  4045. case 11:
  4046. _idOfSprite[_data.getUint16()].setScale(_data.getFloat32(), _data.getFloat32());
  4047. break;
  4048. case 98:
  4049. eStr = _data.getString();
  4050. this.event(eStr);
  4051. if (eStr == "stop")
  4052. this.stop();
  4053. break;
  4054. case 99:
  4055. this._curIndex = _data.getUint16();
  4056. ifAdd && this.updateZOrder();
  4057. break;
  4058. case 100:
  4059. this._count = this._curIndex + 1;
  4060. this._ended = true;
  4061. if (this._playing) {
  4062. this.event(Laya.Event.FRAME);
  4063. this.event(Laya.Event.END);
  4064. this.event(Laya.Event.COMPLETE);
  4065. }
  4066. this._reset(false);
  4067. break;
  4068. }
  4069. }
  4070. if (this._playing && !this._ended)
  4071. this.event(Laya.Event.FRAME);
  4072. this._Pos = _data.pos;
  4073. }
  4074. _setData(data, start) {
  4075. this._data = data;
  4076. this._start = start + 3;
  4077. }
  4078. set url(path) {
  4079. this.load(path);
  4080. }
  4081. load(url, atlas = false, atlasPath = null) {
  4082. this._url = url;
  4083. if (atlas)
  4084. this._atlasPath = atlasPath ? atlasPath : url.split(".swf")[0] + ".json";
  4085. this.stop();
  4086. this._clear();
  4087. this._movieClipList = [this];
  4088. var urls;
  4089. urls = [{ url: url, type: Laya.ILaya.Loader.BUFFER }];
  4090. if (this._atlasPath) {
  4091. urls.push({ url: this._atlasPath, type: Laya.ILaya.Loader.ATLAS });
  4092. }
  4093. Laya.ILaya.loader.load(urls, Laya.Handler.create(this, this._onLoaded));
  4094. }
  4095. _onLoaded() {
  4096. var data;
  4097. data = Laya.ILaya.Loader.getRes(this._url);
  4098. if (!data) {
  4099. this.event(Laya.Event.ERROR, "file not find");
  4100. return;
  4101. }
  4102. if (this._atlasPath && !Laya.ILaya.Loader.getAtlas(this._atlasPath)) {
  4103. this.event(Laya.Event.ERROR, "Atlas not find");
  4104. return;
  4105. }
  4106. this.basePath = this._atlasPath ? Laya.ILaya.Loader.getAtlas(this._atlasPath).dir : this._url.split(".swf")[0] + "/image/";
  4107. this._initData(data);
  4108. }
  4109. _initState() {
  4110. this._reset();
  4111. this._ended = false;
  4112. var preState = this._playing;
  4113. this._playing = false;
  4114. this._curIndex = 0;
  4115. while (!this._ended)
  4116. this._parseFrame(++this._curIndex);
  4117. this._playing = preState;
  4118. }
  4119. _initData(data) {
  4120. this._data = new Laya.Byte(data);
  4121. var i, len = this._data.getUint16();
  4122. for (i = 0; i < len; i++)
  4123. this._ids[this._data.getInt16()] = this._data.getInt32();
  4124. this.interval = 1000 / this._data.getUint16();
  4125. this._setData(this._data, this._ids[32767]);
  4126. this._initState();
  4127. this.play(0);
  4128. this.event(Laya.Event.LOADED);
  4129. if (!this._parentMovieClip)
  4130. this.timer.loop(this.interval, this, this.updates, null, true);
  4131. }
  4132. playTo(start, end, complete = null) {
  4133. this._completeHandler = complete;
  4134. this._endFrame = end;
  4135. this.play(start, false);
  4136. }
  4137. }
  4138. MovieClip._ValueList = ["x", "y", "width", "height", "scaleX", "scaleY", "rotation", "alpha"];
  4139. exports.AnimationContent = AnimationContent;
  4140. exports.AnimationNodeContent = AnimationNodeContent;
  4141. exports.AnimationParser01 = AnimationParser01;
  4142. exports.AnimationParser02 = AnimationParser02;
  4143. exports.AnimationPlayer = AnimationPlayer;
  4144. exports.AnimationState = AnimationState;
  4145. exports.AnimationTemplet = AnimationTemplet;
  4146. exports.BezierLerp = BezierLerp;
  4147. exports.Bone = Bone;
  4148. exports.BoneSlot = BoneSlot;
  4149. exports.DeformAniData = DeformAniData;
  4150. exports.DeformSlotData = DeformSlotData;
  4151. exports.DeformSlotDisplayData = DeformSlotDisplayData;
  4152. exports.DrawOrderData = DrawOrderData;
  4153. exports.EventData = EventData;
  4154. exports.GraphicsAni = GraphicsAni;
  4155. exports.IAniLib = IAniLib;
  4156. exports.IkConstraint = IkConstraint;
  4157. exports.IkConstraintData = IkConstraintData;
  4158. exports.KeyFramesContent = KeyFramesContent;
  4159. exports.MeshData = MeshData;
  4160. exports.MovieClip = MovieClip;
  4161. exports.PathConstraint = PathConstraint;
  4162. exports.PathConstraintData = PathConstraintData;
  4163. exports.Skeleton = Skeleton;
  4164. exports.SkinData = SkinData;
  4165. exports.SkinMeshForGraphic = SkinMeshForGraphic;
  4166. exports.SkinSlotDisplayData = SkinSlotDisplayData;
  4167. exports.SlotData = SlotData;
  4168. exports.Templet = Templet;
  4169. exports.TfConstraint = TfConstraint;
  4170. exports.TfConstraintData = TfConstraintData;
  4171. exports.Transform = Transform;
  4172. exports.UVTools = UVTools;
  4173. }(window.Laya = window.Laya || {}, Laya));