laya.ani.js 179 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213
  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 tTweenKey = this.tweenKeyList[this.frameIndex];
  1533. var tPrevVertices = this.vectices[this.frameIndex - 1];
  1534. var tNextVertices = this.vectices[this.frameIndex];
  1535. var tPreFrameTime = this.timeList[this.frameIndex - 1];
  1536. var tFrameTime = this.timeList[this.frameIndex];
  1537. if (this.tweenKeyList[tFrameIndex - 1]) {
  1538. alpha = (time - tPreFrameTime) / (tFrameTime - tPreFrameTime);
  1539. }
  1540. else {
  1541. alpha = 0;
  1542. }
  1543. var tPrev;
  1544. for (i = 0; i < tVertexCount; i++) {
  1545. tPrev = tPrevVertices[i];
  1546. tVertices[i] = tPrev + (tNextVertices[i] - tPrev) * alpha;
  1547. }
  1548. this.deformData = tVertices;
  1549. }
  1550. }
  1551. class DrawOrderData {
  1552. constructor() {
  1553. this.drawOrder = [];
  1554. }
  1555. }
  1556. class EventData {
  1557. constructor() {
  1558. }
  1559. }
  1560. class IkConstraint {
  1561. constructor(data, bones) {
  1562. this.isSpine = true;
  1563. this.isDebug = false;
  1564. this._data = data;
  1565. this._targetBone = bones[data.targetBoneIndex];
  1566. this.isSpine = data.isSpine;
  1567. if (this._bones == null)
  1568. this._bones = [];
  1569. this._bones.length = 0;
  1570. for (var i = 0, n = data.boneIndexs.length; i < n; i++) {
  1571. this._bones.push(bones[data.boneIndexs[i]]);
  1572. }
  1573. this.name = data.name;
  1574. this.mix = data.mix;
  1575. this.bendDirection = data.bendDirection;
  1576. }
  1577. apply() {
  1578. switch (this._bones.length) {
  1579. case 1:
  1580. this._applyIk1(this._bones[0], this._targetBone.resultMatrix.tx, this._targetBone.resultMatrix.ty, this.mix);
  1581. break;
  1582. case 2:
  1583. if (this.isSpine) {
  1584. this._applyIk2(this._bones[0], this._bones[1], this._targetBone.resultMatrix.tx, this._targetBone.resultMatrix.ty, this.bendDirection, this.mix);
  1585. }
  1586. else {
  1587. this._applyIk3(this._bones[0], this._bones[1], this._targetBone.resultMatrix.tx, this._targetBone.resultMatrix.ty, this.bendDirection, this.mix);
  1588. }
  1589. break;
  1590. }
  1591. }
  1592. _applyIk1(bone, targetX, targetY, alpha) {
  1593. var pp = bone.parentBone;
  1594. var id = 1 / (pp.resultMatrix.a * pp.resultMatrix.d - pp.resultMatrix.b * pp.resultMatrix.c);
  1595. var x = targetX - pp.resultMatrix.tx;
  1596. var y = targetY - pp.resultMatrix.ty;
  1597. var tx = (x * pp.resultMatrix.d - y * pp.resultMatrix.c) * id - bone.transform.x;
  1598. var ty = (y * pp.resultMatrix.a - x * pp.resultMatrix.b) * id - bone.transform.y;
  1599. var rotationIK = Math.atan2(ty, tx) * IkConstraint.radDeg - 0 - bone.transform.skX;
  1600. if (bone.transform.scX < 0)
  1601. rotationIK += 180;
  1602. if (rotationIK > 180)
  1603. rotationIK -= 360;
  1604. else if (rotationIK < -180)
  1605. rotationIK += 360;
  1606. bone.transform.skX = bone.transform.skY = bone.transform.skX + rotationIK * alpha;
  1607. bone.update();
  1608. }
  1609. updatePos(x, y) {
  1610. if (this._sp) {
  1611. this._sp.pos(x, y);
  1612. }
  1613. }
  1614. _applyIk2(parent, child, targetX, targetY, bendDir, alpha) {
  1615. if (alpha == 0) {
  1616. return;
  1617. }
  1618. var px = parent.resultTransform.x, py = parent.resultTransform.y;
  1619. var psx = parent.transform.scX, psy = parent.transform.scY;
  1620. var csx = child.transform.scX;
  1621. var os1, os2, s2;
  1622. if (psx < 0) {
  1623. psx = -psx;
  1624. os1 = 180;
  1625. s2 = -1;
  1626. }
  1627. else {
  1628. os1 = 0;
  1629. s2 = 1;
  1630. }
  1631. if (psy < 0) {
  1632. psy = -psy;
  1633. s2 = -s2;
  1634. }
  1635. if (csx < 0) {
  1636. csx = -csx;
  1637. os2 = 180;
  1638. }
  1639. else {
  1640. os2 = 0;
  1641. }
  1642. var cx = child.resultTransform.x, cy, cwx, cwy;
  1643. var a = parent.resultMatrix.a, b = parent.resultMatrix.c;
  1644. var c = parent.resultMatrix.b, d = parent.resultMatrix.d;
  1645. var u = Math.abs(psx - psy) <= 0.0001;
  1646. if (!u) {
  1647. cy = 0;
  1648. cwx = a * cx + parent.resultMatrix.tx;
  1649. cwy = c * cx + parent.resultMatrix.ty;
  1650. }
  1651. else {
  1652. cy = child.resultTransform.y;
  1653. cwx = a * cx + b * cy + parent.resultMatrix.tx;
  1654. cwy = c * cx + d * cy + parent.resultMatrix.ty;
  1655. }
  1656. if (this.isDebug) {
  1657. if (!this._sp) {
  1658. this._sp = new Laya.Sprite();
  1659. Laya.ILaya.stage.addChild(this._sp);
  1660. }
  1661. this._sp.graphics.clear();
  1662. this._sp.graphics.drawCircle(targetX, targetY, 15, "#ffff00");
  1663. this._sp.graphics.drawCircle(cwx, cwy, 15, "#ff00ff");
  1664. }
  1665. parent.setRotation(Math.atan2(cwy - parent.resultMatrix.ty, cwx - parent.resultMatrix.tx));
  1666. var pp = parent.parentBone;
  1667. a = pp.resultMatrix.a;
  1668. b = pp.resultMatrix.c;
  1669. c = pp.resultMatrix.b;
  1670. d = pp.resultMatrix.d;
  1671. var id = 1 / (a * d - b * c);
  1672. var x = targetX - pp.resultMatrix.tx, y = targetY - pp.resultMatrix.ty;
  1673. var tx = (x * d - y * b) * id - px;
  1674. var ty = (y * a - x * c) * id - py;
  1675. x = cwx - pp.resultMatrix.tx;
  1676. y = cwy - pp.resultMatrix.ty;
  1677. var dx = (x * d - y * b) * id - px;
  1678. var dy = (y * a - x * c) * id - py;
  1679. var l1 = Math.sqrt(dx * dx + dy * dy);
  1680. var l2 = child.length * csx;
  1681. var a1, a2;
  1682. if (u) {
  1683. l2 *= psx;
  1684. var cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
  1685. if (cos < -1)
  1686. cos = -1;
  1687. else if (cos > 1)
  1688. cos = 1;
  1689. a2 = Math.acos(cos) * bendDir;
  1690. a = l1 + l2 * cos;
  1691. b = l2 * Math.sin(a2);
  1692. a1 = Math.atan2(ty * a - tx * b, tx * a + ty * b);
  1693. }
  1694. else {
  1695. a = psx * l2;
  1696. b = psy * l2;
  1697. var aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = Math.atan2(ty, tx);
  1698. c = bb * l1 * l1 + aa * dd - aa * bb;
  1699. var c1 = -2 * bb * l1, c2 = bb - aa;
  1700. d = c1 * c1 - 4 * c2 * c;
  1701. if (d > 0) {
  1702. var q = Math.sqrt(d);
  1703. if (c1 < 0)
  1704. q = -q;
  1705. q = -(c1 + q) / 2;
  1706. var r0 = q / c2, r1 = c / q;
  1707. var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1;
  1708. if (r * r <= dd) {
  1709. y = Math.sqrt(dd - r * r) * bendDir;
  1710. a1 = ta - Math.atan2(y, r);
  1711. a2 = Math.atan2(y / psy, (r - l1) / psx);
  1712. }
  1713. }
  1714. var minAngle = 0, minDist = Number.MAX_VALUE, minX = 0, minY = 0;
  1715. var maxAngle = 0, maxDist = 0, maxX = 0, maxY = 0;
  1716. x = l1 + a;
  1717. d = x * x;
  1718. if (d > maxDist) {
  1719. maxAngle = 0;
  1720. maxDist = d;
  1721. maxX = x;
  1722. }
  1723. x = l1 - a;
  1724. d = x * x;
  1725. if (d < minDist) {
  1726. minAngle = Math.PI;
  1727. minDist = d;
  1728. minX = x;
  1729. }
  1730. var angle = Math.acos(-a * l1 / (aa - bb));
  1731. x = a * Math.cos(angle) + l1;
  1732. y = b * Math.sin(angle);
  1733. d = x * x + y * y;
  1734. if (d < minDist) {
  1735. minAngle = angle;
  1736. minDist = d;
  1737. minX = x;
  1738. minY = y;
  1739. }
  1740. if (d > maxDist) {
  1741. maxAngle = angle;
  1742. maxDist = d;
  1743. maxX = x;
  1744. maxY = y;
  1745. }
  1746. if (dd <= (minDist + maxDist) / 2) {
  1747. a1 = ta - Math.atan2(minY * bendDir, minX);
  1748. a2 = minAngle * bendDir;
  1749. }
  1750. else {
  1751. a1 = ta - Math.atan2(maxY * bendDir, maxX);
  1752. a2 = maxAngle * bendDir;
  1753. }
  1754. }
  1755. var os = Math.atan2(cy, cx) * s2;
  1756. var rotation = parent.resultTransform.skX;
  1757. a1 = (a1 - os) * IkConstraint.radDeg + os1 - rotation;
  1758. if (a1 > 180)
  1759. a1 -= 360;
  1760. else if (a1 < -180)
  1761. a1 += 360;
  1762. parent.resultTransform.x = px;
  1763. parent.resultTransform.y = py;
  1764. parent.resultTransform.skX = parent.resultTransform.skY = rotation + a1 * alpha;
  1765. rotation = child.resultTransform.skX;
  1766. rotation = rotation % 360;
  1767. a2 = ((a2 + os) * IkConstraint.radDeg - 0) * s2 + os2 - rotation;
  1768. if (a2 > 180)
  1769. a2 -= 360;
  1770. else if (a2 < -180)
  1771. a2 += 360;
  1772. child.resultTransform.x = cx;
  1773. child.resultTransform.y = cy;
  1774. child.resultTransform.skX = child.resultTransform.skY = child.resultTransform.skY + a2 * alpha;
  1775. parent.update();
  1776. }
  1777. _applyIk3(parent, child, targetX, targetY, bendDir, alpha) {
  1778. if (alpha == 0) {
  1779. return;
  1780. }
  1781. var cwx, cwy;
  1782. const x = child.resultMatrix.a * child.length;
  1783. const y = child.resultMatrix.b * child.length;
  1784. const lLL = x * x + y * y;
  1785. const lL = Math.sqrt(lLL);
  1786. var parentX = parent.resultMatrix.tx;
  1787. var parentY = parent.resultMatrix.ty;
  1788. var childX = child.resultMatrix.tx;
  1789. var childY = child.resultMatrix.ty;
  1790. var dX = childX - parentX;
  1791. var dY = childY - parentY;
  1792. const lPP = dX * dX + dY * dY;
  1793. const lP = Math.sqrt(lPP);
  1794. dX = targetX - parent.resultMatrix.tx;
  1795. dY = targetY - parent.resultMatrix.ty;
  1796. const lTT = dX * dX + dY * dY;
  1797. const lT = Math.sqrt(lTT);
  1798. if (lL + lP <= lT || lT + lL <= lP || lT + lP <= lL) {
  1799. var rate;
  1800. if (lL + lP <= lT) {
  1801. rate = 1;
  1802. }
  1803. else {
  1804. rate = -1;
  1805. }
  1806. childX = parentX + rate * (targetX - parentX) * lP / lT;
  1807. childY = parentY + rate * (targetY - parentY) * lP / lT;
  1808. }
  1809. else {
  1810. const h = (lPP - lLL + lTT) / (2 * lTT);
  1811. const r = Math.sqrt(lPP - h * h * lTT) / lT;
  1812. const hX = parentX + (dX * h);
  1813. const hY = parentY + (dY * h);
  1814. const rX = -dY * r;
  1815. const rY = dX * r;
  1816. if (bendDir > 0) {
  1817. childX = hX - rX;
  1818. childY = hY - rY;
  1819. }
  1820. else {
  1821. childX = hX + rX;
  1822. childY = hY + rY;
  1823. }
  1824. }
  1825. cwx = childX;
  1826. cwy = childY;
  1827. if (this.isDebug) {
  1828. if (!this._sp) {
  1829. this._sp = new Laya.Sprite();
  1830. Laya.ILaya.stage.addChild(this._sp);
  1831. }
  1832. this._sp.graphics.clear();
  1833. this._sp.graphics.drawCircle(parentX, parentY, 15, "#ff00ff");
  1834. this._sp.graphics.drawCircle(targetX, targetY, 15, "#ffff00");
  1835. this._sp.graphics.drawCircle(cwx, cwy, 15, "#ff00ff");
  1836. }
  1837. var pRotation;
  1838. pRotation = Math.atan2(cwy - parent.resultMatrix.ty, cwx - parent.resultMatrix.tx);
  1839. parent.setRotation(pRotation);
  1840. var pTarMatrix;
  1841. pTarMatrix = IkConstraint._tempMatrix;
  1842. pTarMatrix.identity();
  1843. pTarMatrix.rotate(pRotation);
  1844. pTarMatrix.scale(parent.resultMatrix.getScaleX(), parent.resultMatrix.getScaleY());
  1845. pTarMatrix.translate(parent.resultMatrix.tx, parent.resultMatrix.ty);
  1846. pTarMatrix.copyTo(parent.resultMatrix);
  1847. parent.updateChild();
  1848. var childRotation;
  1849. childRotation = Math.atan2(targetY - cwy, targetX - cwx);
  1850. child.setRotation(childRotation);
  1851. var childTarMatrix;
  1852. childTarMatrix = IkConstraint._tempMatrix;
  1853. childTarMatrix.identity();
  1854. childTarMatrix.rotate(childRotation);
  1855. childTarMatrix.scale(child.resultMatrix.getScaleX(), child.resultMatrix.getScaleY());
  1856. childTarMatrix.translate(cwx, cwy);
  1857. pTarMatrix.copyTo(child.resultMatrix);
  1858. child.updateChild();
  1859. }
  1860. }
  1861. IkConstraint.radDeg = 180 / Math.PI;
  1862. IkConstraint.degRad = Math.PI / 180;
  1863. IkConstraint._tempMatrix = new Laya.Matrix();
  1864. class IkConstraintData {
  1865. constructor() {
  1866. this.boneNames = [];
  1867. this.bendDirection = 1;
  1868. this.mix = 1;
  1869. this.isSpine = true;
  1870. this.targetBoneIndex = -1;
  1871. this.boneIndexs = [];
  1872. }
  1873. }
  1874. class PathConstraint {
  1875. constructor(data, bones) {
  1876. this._debugKey = false;
  1877. this._segments = [];
  1878. this._curves = [];
  1879. this.data = data;
  1880. this.position = data.position;
  1881. this.spacing = data.spacing;
  1882. this.rotateMix = data.rotateMix;
  1883. this.translateMix = data.translateMix;
  1884. this.bones = [];
  1885. var tBoneIds = this.data.bones;
  1886. for (var i = 0, n = tBoneIds.length; i < n; i++) {
  1887. this.bones.push(bones[tBoneIds[i]]);
  1888. }
  1889. }
  1890. apply(boneList, graphics) {
  1891. if (!this.target)
  1892. return;
  1893. var tTranslateMix = this.translateMix;
  1894. var tRotateMix = this.translateMix;
  1895. var tRotate = tRotateMix > 0;
  1896. var tSpacingMode = this.data.spacingMode;
  1897. var tLengthSpacing = tSpacingMode == "length";
  1898. var tRotateMode = this.data.rotateMode;
  1899. var tTangents = tRotateMode == "tangent";
  1900. var tScale = tRotateMode == "chainScale";
  1901. var lengths = [];
  1902. var boneCount = this.bones.length;
  1903. var spacesCount = tTangents ? boneCount : boneCount + 1;
  1904. var spaces = [];
  1905. this._spaces = spaces;
  1906. spaces[0] = this.position;
  1907. var spacing = this.spacing;
  1908. if (tScale || tLengthSpacing) {
  1909. for (var i = 0, n = spacesCount - 1; i < n;) {
  1910. var bone = this.bones[i];
  1911. var length = bone.length;
  1912. var x = length * bone.resultMatrix.a;
  1913. var y = length * bone.resultMatrix.b;
  1914. length = Math.sqrt(x * x + y * y);
  1915. if (tScale)
  1916. lengths[i] = length;
  1917. spaces[++i] = tLengthSpacing ? Math.max(0, length + spacing) : spacing;
  1918. }
  1919. }
  1920. else {
  1921. for (i = 1; i < spacesCount; i++) {
  1922. spaces[i] = spacing;
  1923. }
  1924. }
  1925. var positions = this.computeWorldPositions(this.target, boneList, graphics, spacesCount, tTangents, this.data.positionMode == "percent", tSpacingMode == "percent");
  1926. if (this._debugKey) {
  1927. for (i = 0; i < positions.length; i++) {
  1928. graphics.drawCircle(positions[i++], positions[i++], 5, "#00ff00");
  1929. }
  1930. var tLinePos = [];
  1931. for (i = 0; i < positions.length; i++) {
  1932. tLinePos.push(positions[i++], positions[i++]);
  1933. }
  1934. graphics.drawLines(0, 0, tLinePos, "#ff0000");
  1935. }
  1936. var boneX = positions[0];
  1937. var boneY = positions[1];
  1938. var offsetRotation = this.data.offsetRotation;
  1939. var tip = tRotateMode == "chain" && offsetRotation == 0;
  1940. var p;
  1941. for (i = 0, p = 3; i < boneCount; i++, p += 3) {
  1942. bone = this.bones[i];
  1943. bone.resultMatrix.tx += (boneX - bone.resultMatrix.tx) * tTranslateMix;
  1944. bone.resultMatrix.ty += (boneY - bone.resultMatrix.ty) * tTranslateMix;
  1945. x = positions[p];
  1946. y = positions[p + 1];
  1947. var dx = x - boneX, dy = y - boneY;
  1948. if (tScale) {
  1949. length = lengths[i];
  1950. if (length != 0) {
  1951. var s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * tRotateMix + 1;
  1952. bone.resultMatrix.a *= s;
  1953. bone.resultMatrix.c *= s;
  1954. }
  1955. }
  1956. boneX = x;
  1957. boneY = y;
  1958. if (tRotate) {
  1959. var a = bone.resultMatrix.a;
  1960. var b = bone.resultMatrix.c;
  1961. var c = bone.resultMatrix.b;
  1962. var d = bone.resultMatrix.d;
  1963. var r;
  1964. var cos;
  1965. var sin;
  1966. if (tTangents) {
  1967. r = positions[p - 1];
  1968. }
  1969. else if (spaces[i + 1] == 0) {
  1970. r = positions[p + 2];
  1971. }
  1972. else {
  1973. r = Math.atan2(dy, dx);
  1974. }
  1975. r -= Math.atan2(c, a) - offsetRotation / 180 * Math.PI;
  1976. if (tip) {
  1977. cos = Math.cos(r);
  1978. sin = Math.sin(r);
  1979. length = bone.length;
  1980. boneX += (length * (cos * a - sin * c) - dx) * tRotateMix;
  1981. boneY += (length * (sin * a + cos * c) - dy) * tRotateMix;
  1982. }
  1983. if (r > Math.PI) {
  1984. r -= (Math.PI * 2);
  1985. }
  1986. else if (r < -Math.PI) {
  1987. r += (Math.PI * 2);
  1988. }
  1989. r *= tRotateMix;
  1990. cos = Math.cos(r);
  1991. sin = Math.sin(r);
  1992. bone.resultMatrix.a = cos * a - sin * c;
  1993. bone.resultMatrix.c = cos * b - sin * d;
  1994. bone.resultMatrix.b = sin * a + cos * c;
  1995. bone.resultMatrix.d = sin * b + cos * d;
  1996. }
  1997. }
  1998. }
  1999. computeWorldVertices2(boneSlot, boneList, start, count, worldVertices, offset) {
  2000. var tBones = boneSlot.currDisplayData.bones;
  2001. var tWeights = boneSlot.currDisplayData.weights;
  2002. var tTriangles = boneSlot.currDisplayData.triangles;
  2003. var tMatrix;
  2004. var i = 0;
  2005. var v = 0;
  2006. var skip = 0;
  2007. var n = 0;
  2008. var w = 0;
  2009. var b = 0;
  2010. var wx = 0;
  2011. var wy = 0;
  2012. var vx = 0;
  2013. var vy = 0;
  2014. var bone;
  2015. var len;
  2016. if (tBones == null) {
  2017. if (!tTriangles)
  2018. tTriangles = tWeights;
  2019. if (boneSlot.deformData)
  2020. tTriangles = boneSlot.deformData;
  2021. var parentName;
  2022. parentName = boneSlot.parent;
  2023. if (boneList) {
  2024. len = boneList.length;
  2025. for (i = 0; i < len; i++) {
  2026. if (boneList[i].name == parentName) {
  2027. bone = boneList[i];
  2028. break;
  2029. }
  2030. }
  2031. }
  2032. var tBoneMt;
  2033. if (bone) {
  2034. tBoneMt = bone.resultMatrix;
  2035. }
  2036. if (!tBoneMt)
  2037. tBoneMt = PathConstraint._tempMt;
  2038. var x = tBoneMt.tx;
  2039. var y = tBoneMt.ty;
  2040. var a = tBoneMt.a, bb = tBoneMt.b, c = tBoneMt.c, d = tBoneMt.d;
  2041. if (bone)
  2042. d *= bone.d;
  2043. for (v = start, w = offset; w < count; v += 2, w += 2) {
  2044. vx = tTriangles[v], vy = tTriangles[v + 1];
  2045. worldVertices[w] = vx * a + vy * bb + x;
  2046. worldVertices[w + 1] = -(vx * c + vy * d + y);
  2047. }
  2048. return;
  2049. }
  2050. for (i = 0; i < start; i += 2) {
  2051. n = tBones[v];
  2052. v += n + 1;
  2053. skip += n;
  2054. }
  2055. var skeletonBones = boneList;
  2056. for (w = offset, b = skip * 3; w < count; w += 2) {
  2057. wx = 0, wy = 0;
  2058. n = tBones[v++];
  2059. n += v;
  2060. for (; v < n; v++, b += 3) {
  2061. tMatrix = skeletonBones[tBones[v]].resultMatrix;
  2062. vx = tWeights[b];
  2063. vy = tWeights[b + 1];
  2064. var weight = tWeights[b + 2];
  2065. wx += (vx * tMatrix.a + vy * tMatrix.c + tMatrix.tx) * weight;
  2066. wy += (vx * tMatrix.b + vy * tMatrix.d + tMatrix.ty) * weight;
  2067. }
  2068. worldVertices[w] = wx;
  2069. worldVertices[w + 1] = wy;
  2070. }
  2071. }
  2072. computeWorldPositions(boneSlot, boneList, graphics, spacesCount, tangents, percentPosition, percentSpacing) {
  2073. var tBones = boneSlot.currDisplayData.bones;
  2074. var tWeights = boneSlot.currDisplayData.weights;
  2075. var tTriangles = boneSlot.currDisplayData.triangles;
  2076. var tVertices = [];
  2077. var i = 0;
  2078. var verticesLength = boneSlot.currDisplayData.verLen;
  2079. var position = this.position;
  2080. var spaces = this._spaces;
  2081. var world = [];
  2082. var out = [];
  2083. var curveCount = verticesLength / 6;
  2084. var prevCurve = -1;
  2085. var pathLength;
  2086. var o, curve;
  2087. var p;
  2088. var space;
  2089. var prev;
  2090. var length;
  2091. {
  2092. curveCount--;
  2093. verticesLength -= 4;
  2094. this.computeWorldVertices2(boneSlot, boneList, 2, verticesLength, tVertices, 0);
  2095. if (this._debugKey) {
  2096. for (i = 0; i < tVertices.length;) {
  2097. graphics.drawCircle(tVertices[i++], tVertices[i++], 10, "#ff0000");
  2098. }
  2099. }
  2100. world = tVertices;
  2101. }
  2102. this._curves.length = curveCount;
  2103. var curves = this._curves;
  2104. pathLength = 0;
  2105. var x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
  2106. var tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;
  2107. var w;
  2108. for (i = 0, w = 2; i < curveCount; i++, w += 6) {
  2109. cx1 = world[w];
  2110. cy1 = world[w + 1];
  2111. cx2 = world[w + 2];
  2112. cy2 = world[w + 3];
  2113. x2 = world[w + 4];
  2114. y2 = world[w + 5];
  2115. tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
  2116. tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
  2117. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
  2118. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
  2119. ddfx = tmpx * 2 + dddfx;
  2120. ddfy = tmpy * 2 + dddfy;
  2121. dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
  2122. dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
  2123. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2124. dfx += ddfx;
  2125. dfy += ddfy;
  2126. ddfx += dddfx;
  2127. ddfy += dddfy;
  2128. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2129. dfx += ddfx;
  2130. dfy += ddfy;
  2131. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2132. dfx += ddfx + dddfx;
  2133. dfy += ddfy + dddfy;
  2134. pathLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2135. curves[i] = pathLength;
  2136. x1 = x2;
  2137. y1 = y2;
  2138. }
  2139. if (percentPosition)
  2140. position *= pathLength;
  2141. if (percentSpacing) {
  2142. for (i = 0; i < spacesCount; i++)
  2143. spaces[i] *= pathLength;
  2144. }
  2145. var segments = this._segments;
  2146. var curveLength = 0;
  2147. var segment;
  2148. for (i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
  2149. space = spaces[i];
  2150. position += space;
  2151. p = position;
  2152. if (p < 0) {
  2153. this.addBeforePosition(p, world, 0, out, o);
  2154. continue;
  2155. }
  2156. else if (p > pathLength) {
  2157. this.addAfterPosition(p - pathLength, world, verticesLength - 4, out, o);
  2158. continue;
  2159. }
  2160. for (;; curve++) {
  2161. length = curves[curve];
  2162. if (p > length)
  2163. continue;
  2164. if (curve == 0)
  2165. p /= length;
  2166. else {
  2167. prev = curves[curve - 1];
  2168. p = (p - prev) / (length - prev);
  2169. }
  2170. break;
  2171. }
  2172. if (curve != prevCurve) {
  2173. prevCurve = curve;
  2174. var ii = curve * 6;
  2175. x1 = world[ii];
  2176. y1 = world[ii + 1];
  2177. cx1 = world[ii + 2];
  2178. cy1 = world[ii + 3];
  2179. cx2 = world[ii + 4];
  2180. cy2 = world[ii + 5];
  2181. x2 = world[ii + 6];
  2182. y2 = world[ii + 7];
  2183. tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
  2184. tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
  2185. dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
  2186. dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
  2187. ddfx = tmpx * 2 + dddfx;
  2188. ddfy = tmpy * 2 + dddfy;
  2189. dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
  2190. dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
  2191. curveLength = Math.sqrt(dfx * dfx + dfy * dfy);
  2192. segments[0] = curveLength;
  2193. for (ii = 1; ii < 8; ii++) {
  2194. dfx += ddfx;
  2195. dfy += ddfy;
  2196. ddfx += dddfx;
  2197. ddfy += dddfy;
  2198. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2199. segments[ii] = curveLength;
  2200. }
  2201. dfx += ddfx;
  2202. dfy += ddfy;
  2203. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2204. segments[8] = curveLength;
  2205. dfx += ddfx + dddfx;
  2206. dfy += ddfy + dddfy;
  2207. curveLength += Math.sqrt(dfx * dfx + dfy * dfy);
  2208. segments[9] = curveLength;
  2209. segment = 0;
  2210. }
  2211. p *= curveLength;
  2212. for (;; segment++) {
  2213. length = segments[segment];
  2214. if (p > length)
  2215. continue;
  2216. if (segment == 0)
  2217. p /= length;
  2218. else {
  2219. prev = segments[segment - 1];
  2220. p = segment + (p - prev) / (length - prev);
  2221. }
  2222. break;
  2223. }
  2224. this.addCurvePosition(p * 0.1, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents || (i > 0 && space == 0));
  2225. }
  2226. return out;
  2227. }
  2228. addBeforePosition(p, temp, i, out, o) {
  2229. var x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = Math.atan2(dy, dx);
  2230. out[o] = x1 + p * Math.cos(r);
  2231. out[o + 1] = y1 + p * Math.sin(r);
  2232. out[o + 2] = r;
  2233. }
  2234. addAfterPosition(p, temp, i, out, o) {
  2235. var x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = Math.atan2(dy, dx);
  2236. out[o] = x1 + p * Math.cos(r);
  2237. out[o + 1] = y1 + p * Math.sin(r);
  2238. out[o + 2] = r;
  2239. }
  2240. addCurvePosition(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) {
  2241. if (p == 0)
  2242. p = 0.0001;
  2243. var tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
  2244. var ut = u * p, ut3 = ut * 3, uut3 = u * ut3, utt3 = ut3 * p;
  2245. var x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
  2246. out[o] = x;
  2247. out[o + 1] = y;
  2248. if (tangents) {
  2249. out[o + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
  2250. }
  2251. else {
  2252. out[o + 2] = 0;
  2253. }
  2254. }
  2255. }
  2256. PathConstraint.NONE = -1;
  2257. PathConstraint.BEFORE = -2;
  2258. PathConstraint.AFTER = -3;
  2259. PathConstraint._tempMt = new Laya.Matrix();
  2260. class PathConstraintData {
  2261. constructor() {
  2262. this.bones = [];
  2263. }
  2264. }
  2265. class TfConstraint {
  2266. constructor(data, bones) {
  2267. this._temp = [];
  2268. this._data = data;
  2269. if (this._bones == null) {
  2270. this._bones = [];
  2271. }
  2272. this.target = bones[data.targetIndex];
  2273. var j, n;
  2274. for (j = 0, n = data.boneIndexs.length; j < n; j++) {
  2275. this._bones.push(bones[data.boneIndexs[j]]);
  2276. }
  2277. this.rotateMix = data.rotateMix;
  2278. this.translateMix = data.translateMix;
  2279. this.scaleMix = data.scaleMix;
  2280. this.shearMix = data.shearMix;
  2281. }
  2282. apply() {
  2283. var tTfBone;
  2284. var ta = this.target.resultMatrix.a, tb = this.target.resultMatrix.b, tc = this.target.resultMatrix.c, td = this.target.resultMatrix.d;
  2285. for (var j = 0, n = this._bones.length; j < n; j++) {
  2286. tTfBone = this._bones[j];
  2287. if (this.rotateMix > 0) {
  2288. var a = tTfBone.resultMatrix.a, b = tTfBone.resultMatrix.b, c = tTfBone.resultMatrix.c, d = tTfBone.resultMatrix.d;
  2289. var r = Math.atan2(tc, ta) - Math.atan2(c, a) + this._data.offsetRotation * Math.PI / 180;
  2290. if (r > Math.PI)
  2291. r -= Math.PI * 2;
  2292. else if (r < -Math.PI)
  2293. r += Math.PI * 2;
  2294. r *= this.rotateMix;
  2295. var cos = Math.cos(r), sin = Math.sin(r);
  2296. tTfBone.resultMatrix.a = cos * a - sin * c;
  2297. tTfBone.resultMatrix.b = cos * b - sin * d;
  2298. tTfBone.resultMatrix.c = sin * a + cos * c;
  2299. tTfBone.resultMatrix.d = sin * b + cos * d;
  2300. }
  2301. if (this.translateMix) {
  2302. this._temp[0] = this._data.offsetX;
  2303. this._temp[1] = this._data.offsetY;
  2304. this.target.localToWorld(this._temp);
  2305. tTfBone.resultMatrix.tx += (this._temp[0] - tTfBone.resultMatrix.tx) * this.translateMix;
  2306. tTfBone.resultMatrix.ty += (this._temp[1] - tTfBone.resultMatrix.ty) * this.translateMix;
  2307. tTfBone.updateChild();
  2308. }
  2309. if (this.scaleMix > 0) {
  2310. var bs = Math.sqrt(tTfBone.resultMatrix.a * tTfBone.resultMatrix.a + tTfBone.resultMatrix.c * tTfBone.resultMatrix.c);
  2311. var ts = Math.sqrt(ta * ta + tc * tc);
  2312. var s = bs > 0.00001 ? (bs + (ts - bs + this._data.offsetScaleX) * this.scaleMix) / bs : 0;
  2313. tTfBone.resultMatrix.a *= s;
  2314. tTfBone.resultMatrix.c *= s;
  2315. bs = Math.sqrt(tTfBone.resultMatrix.b * tTfBone.resultMatrix.b + tTfBone.resultMatrix.d * tTfBone.resultMatrix.d);
  2316. ts = Math.sqrt(tb * tb + td * td);
  2317. s = bs > 0.00001 ? (bs + (ts - bs + this._data.offsetScaleY) * this.scaleMix) / bs : 0;
  2318. tTfBone.resultMatrix.b *= s;
  2319. tTfBone.resultMatrix.d *= s;
  2320. }
  2321. if (this.shearMix > 0) {
  2322. b = tTfBone.resultMatrix.b, d = tTfBone.resultMatrix.d;
  2323. var by = Math.atan2(d, b);
  2324. r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(tTfBone.resultMatrix.c, tTfBone.resultMatrix.a));
  2325. if (r > Math.PI)
  2326. r -= Math.PI * 2;
  2327. else if (r < -Math.PI)
  2328. r += Math.PI * 2;
  2329. r = by + (r + this._data.offsetShearY * Math.PI / 180) * this.shearMix;
  2330. s = Math.sqrt(b * b + d * d);
  2331. tTfBone.resultMatrix.b = Math.cos(r) * s;
  2332. tTfBone.resultMatrix.d = Math.sin(r) * s;
  2333. }
  2334. }
  2335. }
  2336. }
  2337. class Skeleton extends Laya.Sprite {
  2338. constructor(templet = null, aniMode = 0) {
  2339. super();
  2340. this._boneMatrixArray = [];
  2341. this._lastTime = 0;
  2342. this._currAniIndex = -1;
  2343. this._pause = true;
  2344. this._aniClipIndex = -1;
  2345. this._clipIndex = -1;
  2346. this._skinIndex = 0;
  2347. this._skinName = "default";
  2348. this._aniMode = 0;
  2349. this._index = -1;
  2350. this._total = -1;
  2351. this._indexControl = false;
  2352. this._eventIndex = 0;
  2353. this._drawOrderIndex = 0;
  2354. this._drawOrder = null;
  2355. this._lastAniClipIndex = -1;
  2356. this._lastUpdateAniClipIndex = -1;
  2357. this._playAudio = true;
  2358. this._soundChannelArr = [];
  2359. if (templet)
  2360. this.init(templet, aniMode);
  2361. }
  2362. init(templet, aniMode = 0) {
  2363. var i = 0, n;
  2364. if (aniMode == 1) {
  2365. this._graphicsCache = [];
  2366. for (i = 0, n = templet.getAnimationCount(); i < n; i++) {
  2367. this._graphicsCache.push([]);
  2368. }
  2369. }
  2370. this._yReverseMatrix = templet.yReverseMatrix;
  2371. this._aniMode = aniMode;
  2372. this._templet = templet;
  2373. this._templet._addReference(1);
  2374. this._player = new AnimationPlayer();
  2375. this._player.cacheFrameRate = templet.rate;
  2376. this._player.templet = templet;
  2377. this._player.play();
  2378. this._parseSrcBoneMatrix();
  2379. this._boneList = templet.mBoneArr;
  2380. this._rootBone = templet.mRootBone;
  2381. this._aniSectionDic = templet.aniSectionDic;
  2382. if (templet.ikArr.length > 0) {
  2383. this._ikArr = [];
  2384. for (i = 0, n = templet.ikArr.length; i < n; i++) {
  2385. this._ikArr.push(new IkConstraint(templet.ikArr[i], this._boneList));
  2386. }
  2387. }
  2388. if (templet.pathArr.length > 0) {
  2389. var tPathData;
  2390. var tPathConstraint;
  2391. if (this._pathDic == null)
  2392. this._pathDic = {};
  2393. var tBoneSlot;
  2394. for (i = 0, n = templet.pathArr.length; i < n; i++) {
  2395. tPathData = templet.pathArr[i];
  2396. tPathConstraint = new PathConstraint(tPathData, this._boneList);
  2397. tBoneSlot = this._boneSlotDic[tPathData.name];
  2398. if (tBoneSlot) {
  2399. tPathConstraint = new PathConstraint(tPathData, this._boneList);
  2400. tPathConstraint.target = tBoneSlot;
  2401. }
  2402. this._pathDic[tPathData.name] = tPathConstraint;
  2403. }
  2404. }
  2405. if (templet.tfArr.length > 0) {
  2406. this._tfArr = [];
  2407. for (i = 0, n = templet.tfArr.length; i < n; i++) {
  2408. this._tfArr.push(new TfConstraint(templet.tfArr[i], this._boneList));
  2409. }
  2410. }
  2411. if (templet.skinDataArray.length > 0) {
  2412. var tSkinData = this._templet.skinDataArray[this._skinIndex];
  2413. this._skinName = tSkinData.name;
  2414. }
  2415. this._player.on(Laya.Event.PLAYED, this, this._onPlay);
  2416. this._player.on(Laya.Event.STOPPED, this, this._onStop);
  2417. this._player.on(Laya.Event.PAUSED, this, this._onPause);
  2418. }
  2419. get url() {
  2420. return this._aniPath;
  2421. }
  2422. set url(path) {
  2423. this.load(path);
  2424. }
  2425. load(path, complete = null, aniMode = 0) {
  2426. this._aniPath = path;
  2427. this._complete = complete;
  2428. this._loadAniMode = aniMode;
  2429. Laya.ILaya.loader.load([{ url: path, type: Laya.ILaya.Loader.BUFFER }], Laya.Handler.create(this, this._onLoaded));
  2430. }
  2431. _onLoaded() {
  2432. var arraybuffer = Laya.ILaya.Loader.getRes(this._aniPath);
  2433. if (arraybuffer == null)
  2434. return;
  2435. if (IAniLib.Templet.TEMPLET_DICTIONARY == null) {
  2436. IAniLib.Templet.TEMPLET_DICTIONARY = {};
  2437. }
  2438. var tFactory;
  2439. tFactory = IAniLib.Templet.TEMPLET_DICTIONARY[this._aniPath];
  2440. if (tFactory) {
  2441. if (tFactory.isParseFail) {
  2442. this._parseFail();
  2443. }
  2444. else {
  2445. if (tFactory.isParserComplete) {
  2446. this._parseComplete();
  2447. }
  2448. else {
  2449. tFactory.on(Laya.Event.COMPLETE, this, this._parseComplete);
  2450. tFactory.on(Laya.Event.ERROR, this, this._parseFail);
  2451. }
  2452. }
  2453. }
  2454. else {
  2455. tFactory = new IAniLib.Templet();
  2456. tFactory._setCreateURL(this._aniPath);
  2457. IAniLib.Templet.TEMPLET_DICTIONARY[this._aniPath] = tFactory;
  2458. tFactory.on(Laya.Event.COMPLETE, this, this._parseComplete);
  2459. tFactory.on(Laya.Event.ERROR, this, this._parseFail);
  2460. tFactory.isParserComplete = false;
  2461. tFactory.parseData(null, arraybuffer);
  2462. }
  2463. }
  2464. _parseComplete() {
  2465. var tTemple = IAniLib.Templet.TEMPLET_DICTIONARY[this._aniPath];
  2466. if (tTemple) {
  2467. this.init(tTemple, this._loadAniMode);
  2468. this.play(0, true);
  2469. }
  2470. this._complete && this._complete.runWith(this);
  2471. }
  2472. _parseFail() {
  2473. console.log("[Error]:" + this._aniPath + "解析失败");
  2474. }
  2475. _onPlay() {
  2476. this.event(Laya.Event.PLAYED);
  2477. }
  2478. _onStop() {
  2479. var tEventData;
  2480. var tEventAniArr = this._templet.eventAniArr;
  2481. var tEventArr = tEventAniArr[this._aniClipIndex];
  2482. if (tEventArr && this._eventIndex < tEventArr.length) {
  2483. for (; this._eventIndex < tEventArr.length; this._eventIndex++) {
  2484. tEventData = tEventArr[this._eventIndex];
  2485. if (tEventData.time >= this._player.playStart && tEventData.time <= this._player.playEnd) {
  2486. this.event(Laya.Event.LABEL, tEventData);
  2487. }
  2488. }
  2489. }
  2490. this._drawOrder = null;
  2491. this.event(Laya.Event.STOPPED);
  2492. }
  2493. _onPause() {
  2494. this.event(Laya.Event.PAUSED);
  2495. }
  2496. _parseSrcBoneMatrix() {
  2497. var i = 0, n = 0;
  2498. n = this._templet.srcBoneMatrixArr.length;
  2499. for (i = 0; i < n; i++) {
  2500. this._boneMatrixArray.push(new Laya.Matrix());
  2501. }
  2502. if (this._aniMode == 0) {
  2503. this._boneSlotDic = this._templet.boneSlotDic;
  2504. this._bindBoneBoneSlotDic = this._templet.bindBoneBoneSlotDic;
  2505. this._boneSlotArray = this._templet.boneSlotArray;
  2506. }
  2507. else {
  2508. if (this._boneSlotDic == null)
  2509. this._boneSlotDic = {};
  2510. if (this._bindBoneBoneSlotDic == null)
  2511. this._bindBoneBoneSlotDic = {};
  2512. if (this._boneSlotArray == null)
  2513. this._boneSlotArray = [];
  2514. var tArr = this._templet.boneSlotArray;
  2515. var tBS;
  2516. var tBSArr;
  2517. for (i = 0, n = tArr.length; i < n; i++) {
  2518. tBS = tArr[i];
  2519. tBSArr = this._bindBoneBoneSlotDic[tBS.parent];
  2520. if (tBSArr == null) {
  2521. this._bindBoneBoneSlotDic[tBS.parent] = tBSArr = [];
  2522. }
  2523. this._boneSlotDic[tBS.name] = tBS = tBS.copy();
  2524. tBSArr.push(tBS);
  2525. this._boneSlotArray.push(tBS);
  2526. }
  2527. }
  2528. }
  2529. _emitMissedEvents(startTime, endTime, startIndex = 0) {
  2530. var tEventAniArr = this._templet.eventAniArr;
  2531. var tEventArr = tEventAniArr[this._player.currentAnimationClipIndex];
  2532. if (tEventArr) {
  2533. var i = 0, len;
  2534. var tEventData;
  2535. len = tEventArr.length;
  2536. for (i = startIndex; i < len; i++) {
  2537. tEventData = tEventArr[i];
  2538. if (tEventData.time >= this._player.playStart && tEventData.time <= this._player.playEnd) {
  2539. this.event(Laya.Event.LABEL, tEventData);
  2540. }
  2541. }
  2542. }
  2543. }
  2544. _update(autoKey = true) {
  2545. if (this._pause)
  2546. return;
  2547. if (autoKey && this._indexControl) {
  2548. return;
  2549. }
  2550. var tCurrTime = this.timer.currTimer;
  2551. var preIndex = this._player.currentKeyframeIndex;
  2552. var dTime = tCurrTime - this._lastTime;
  2553. if (autoKey) {
  2554. this._player._update(dTime);
  2555. }
  2556. else {
  2557. preIndex = -1;
  2558. }
  2559. this._lastTime = tCurrTime;
  2560. if (!this._player)
  2561. return;
  2562. this._index = this._clipIndex = this._player.currentKeyframeIndex;
  2563. if (this._index < 0)
  2564. return;
  2565. if (dTime > 0 && this._clipIndex == preIndex && this._lastUpdateAniClipIndex == this._aniClipIndex) {
  2566. return;
  2567. }
  2568. this._lastUpdateAniClipIndex = this._aniClipIndex;
  2569. if (preIndex > this._clipIndex && this._eventIndex != 0) {
  2570. this._emitMissedEvents(this._player.playStart, this._player.playEnd, this._eventIndex);
  2571. this._eventIndex = 0;
  2572. }
  2573. var tEventArr = this._templet.eventAniArr[this._aniClipIndex];
  2574. var _soundChannel;
  2575. if (tEventArr && this._eventIndex < tEventArr.length) {
  2576. var tEventData = tEventArr[this._eventIndex];
  2577. if (tEventData.time >= this._player.playStart && tEventData.time <= this._player.playEnd) {
  2578. if (this._player.currentPlayTime >= tEventData.time) {
  2579. this.event(Laya.Event.LABEL, tEventData);
  2580. this._eventIndex++;
  2581. if (this._playAudio && tEventData.audioValue && tEventData.audioValue !== "null") {
  2582. _soundChannel = Laya.SoundManager.playSound(this._player.templet._path + tEventData.audioValue, 1, Laya.Handler.create(this, this._onAniSoundStoped));
  2583. Laya.SoundManager.playbackRate = this._player.playbackRate;
  2584. _soundChannel && this._soundChannelArr.push(_soundChannel);
  2585. }
  2586. }
  2587. }
  2588. else if (tEventData.time < this._player.playStart && this._playAudio && tEventData.audioValue && tEventData.audioValue !== "null") {
  2589. this._eventIndex++;
  2590. _soundChannel = Laya.SoundManager.playSound(this._player.templet._path + tEventData.audioValue, 1, Laya.Handler.create(this, this._onAniSoundStoped), null, (this._player.currentPlayTime - tEventData.time) / 1000);
  2591. Laya.SoundManager.playbackRate = this._player.playbackRate;
  2592. _soundChannel && this._soundChannelArr.push(_soundChannel);
  2593. }
  2594. else {
  2595. this._eventIndex++;
  2596. }
  2597. }
  2598. var tGraphics;
  2599. if (this._aniMode == 0) {
  2600. tGraphics = this._templet.getGrahicsDataWithCache(this._aniClipIndex, this._clipIndex) || this._createGraphics();
  2601. if (tGraphics && this.graphics != tGraphics) {
  2602. this.graphics = tGraphics;
  2603. }
  2604. }
  2605. else if (this._aniMode == 1) {
  2606. tGraphics = this._getGrahicsDataWithCache(this._aniClipIndex, this._clipIndex) || this._createGraphics();
  2607. if (tGraphics && this.graphics != tGraphics) {
  2608. this.graphics = tGraphics;
  2609. }
  2610. }
  2611. else {
  2612. this._createGraphics();
  2613. }
  2614. }
  2615. _onAniSoundStoped(force) {
  2616. var _channel;
  2617. for (var len = this._soundChannelArr.length, i = 0; i < len; i++) {
  2618. _channel = this._soundChannelArr[i];
  2619. if (_channel.isStopped || force) {
  2620. !_channel.isStopped && _channel.stop();
  2621. this._soundChannelArr.splice(i, 1);
  2622. len--;
  2623. i--;
  2624. }
  2625. }
  2626. }
  2627. _createGraphics(_clipIndex = -1) {
  2628. if (_clipIndex == -1)
  2629. _clipIndex = this._clipIndex;
  2630. var curTime = _clipIndex * this._player.cacheFrameRateInterval;
  2631. var tDrawOrderData;
  2632. var tDrawOrderAniArr = this._templet.drawOrderAniArr;
  2633. var tDrawOrderArr = tDrawOrderAniArr[this._aniClipIndex];
  2634. if (tDrawOrderArr && tDrawOrderArr.length > 0) {
  2635. this._drawOrderIndex = 0;
  2636. tDrawOrderData = tDrawOrderArr[this._drawOrderIndex];
  2637. while (curTime >= tDrawOrderData.time) {
  2638. this._drawOrder = tDrawOrderData.drawOrder;
  2639. this._drawOrderIndex++;
  2640. if (this._drawOrderIndex >= tDrawOrderArr.length) {
  2641. break;
  2642. }
  2643. tDrawOrderData = tDrawOrderArr[this._drawOrderIndex];
  2644. }
  2645. }
  2646. if (this._aniMode == 0 || this._aniMode == 1) {
  2647. this.graphics = GraphicsAni.create();
  2648. }
  2649. else {
  2650. if (this.graphics instanceof GraphicsAni) {
  2651. this.graphics.clear();
  2652. }
  2653. else {
  2654. this.graphics = GraphicsAni.create();
  2655. }
  2656. }
  2657. var tGraphics = this.graphics;
  2658. var bones = this._templet.getNodes(this._aniClipIndex);
  2659. var stopped = this._player.state == 0;
  2660. this._templet.getOriginalData(this._aniClipIndex, this._curOriginalData, null, _clipIndex, stopped ? (curTime + this._player.cacheFrameRateInterval) : curTime);
  2661. var tSectionArr = this._aniSectionDic[this._aniClipIndex];
  2662. var tStartIndex = 0;
  2663. var i = 0, j = 0, k = 0, n = 0;
  2664. var tDBBoneSlot;
  2665. var tDBBoneSlotArr;
  2666. var tParentTransform;
  2667. var tSrcBone;
  2668. var boneCount = this._templet.srcBoneMatrixArr.length;
  2669. var origDt = this._curOriginalData;
  2670. for (i = 0, n = tSectionArr[0]; i < boneCount; i++) {
  2671. tSrcBone = this._boneList[i];
  2672. var resultTrans = tSrcBone.resultTransform;
  2673. tParentTransform = this._templet.srcBoneMatrixArr[i];
  2674. resultTrans.scX = tParentTransform.scX * origDt[tStartIndex++];
  2675. resultTrans.skX = tParentTransform.skX + origDt[tStartIndex++];
  2676. resultTrans.skY = tParentTransform.skY + origDt[tStartIndex++];
  2677. resultTrans.scY = tParentTransform.scY * origDt[tStartIndex++];
  2678. resultTrans.x = tParentTransform.x + origDt[tStartIndex++];
  2679. resultTrans.y = tParentTransform.y + origDt[tStartIndex++];
  2680. if (this._templet.tMatrixDataLen === 8) {
  2681. resultTrans.skewX = tParentTransform.skewX + origDt[tStartIndex++];
  2682. resultTrans.skewY = tParentTransform.skewY + origDt[tStartIndex++];
  2683. }
  2684. }
  2685. var tSlotDic = {};
  2686. var tSlotAlphaDic = {};
  2687. var tBoneData;
  2688. for (n += tSectionArr[1]; i < n; i++) {
  2689. tBoneData = bones[i];
  2690. tSlotDic[tBoneData.name] = origDt[tStartIndex++];
  2691. tSlotAlphaDic[tBoneData.name] = origDt[tStartIndex++];
  2692. tStartIndex += 4;
  2693. }
  2694. var tBendDirectionDic = {};
  2695. var tMixDic = {};
  2696. for (n += tSectionArr[2]; i < n; i++) {
  2697. tBoneData = bones[i];
  2698. tBendDirectionDic[tBoneData.name] = origDt[tStartIndex++];
  2699. tMixDic[tBoneData.name] = origDt[tStartIndex++];
  2700. tStartIndex += 4;
  2701. }
  2702. if (this._pathDic) {
  2703. var tPathConstraint;
  2704. for (n += tSectionArr[3]; i < n; i++) {
  2705. tBoneData = bones[i];
  2706. tPathConstraint = this._pathDic[tBoneData.name];
  2707. if (tPathConstraint) {
  2708. var tByte = new Laya.Byte(tBoneData.extenData);
  2709. switch (tByte.getByte()) {
  2710. case 1:
  2711. tPathConstraint.position = origDt[tStartIndex++];
  2712. break;
  2713. case 2:
  2714. tPathConstraint.spacing = origDt[tStartIndex++];
  2715. break;
  2716. case 3:
  2717. tPathConstraint.rotateMix = origDt[tStartIndex++];
  2718. tPathConstraint.translateMix = origDt[tStartIndex++];
  2719. break;
  2720. }
  2721. }
  2722. }
  2723. }
  2724. this._rootBone.update(this._yReverseMatrix || Laya.Matrix.TEMP.identity());
  2725. if (this._ikArr) {
  2726. var tIkConstraint;
  2727. for (i = 0, n = this._ikArr.length; i < n; i++) {
  2728. tIkConstraint = this._ikArr[i];
  2729. if (tIkConstraint.name in tBendDirectionDic) {
  2730. tIkConstraint.bendDirection = tBendDirectionDic[tIkConstraint.name];
  2731. }
  2732. if (tIkConstraint.name in tMixDic) {
  2733. tIkConstraint.mix = tMixDic[tIkConstraint.name];
  2734. }
  2735. tIkConstraint.apply();
  2736. }
  2737. }
  2738. if (this._pathDic) {
  2739. for (var tPathStr in this._pathDic) {
  2740. tPathConstraint = this._pathDic[tPathStr];
  2741. tPathConstraint.apply(this._boneList, tGraphics);
  2742. }
  2743. }
  2744. if (this._tfArr) {
  2745. var tTfConstraint;
  2746. for (i = 0, k = this._tfArr.length; i < k; i++) {
  2747. tTfConstraint = this._tfArr[i];
  2748. tTfConstraint.apply();
  2749. }
  2750. }
  2751. for (i = 0, k = this._boneList.length; i < k; i++) {
  2752. tSrcBone = this._boneList[i];
  2753. tDBBoneSlotArr = this._bindBoneBoneSlotDic[tSrcBone.name];
  2754. tSrcBone.resultMatrix.copyTo(this._boneMatrixArray[i]);
  2755. if (tDBBoneSlotArr) {
  2756. for (j = 0, n = tDBBoneSlotArr.length; j < n; j++) {
  2757. tDBBoneSlot = tDBBoneSlotArr[j];
  2758. if (tDBBoneSlot) {
  2759. tDBBoneSlot.setParentMatrix(tSrcBone.resultMatrix);
  2760. }
  2761. }
  2762. }
  2763. }
  2764. var tDeformDic = {};
  2765. var tDeformAniArr = this._templet.deformAniArr;
  2766. var tDeformAniData;
  2767. if (tDeformAniArr && tDeformAniArr.length > 0) {
  2768. if (this._lastAniClipIndex != this._aniClipIndex) {
  2769. this._lastAniClipIndex = this._aniClipIndex;
  2770. for (i = 0, n = this._boneSlotArray.length; i < n; i++) {
  2771. tDBBoneSlot = this._boneSlotArray[i];
  2772. tDBBoneSlot.deformData = null;
  2773. }
  2774. }
  2775. var tSkinDeformAni = tDeformAniArr[this._aniClipIndex];
  2776. tDeformAniData = (tSkinDeformAni["default"]);
  2777. this._setDeform(tDeformAniData, tDeformDic, this._boneSlotArray, curTime);
  2778. var tSkin;
  2779. for (tSkin in tSkinDeformAni) {
  2780. if (tSkin != "default" && tSkin != this._skinName) {
  2781. tDeformAniData = tSkinDeformAni[tSkin];
  2782. this._setDeform(tDeformAniData, tDeformDic, this._boneSlotArray, curTime);
  2783. }
  2784. }
  2785. tDeformAniData = (tSkinDeformAni[this._skinName]);
  2786. this._setDeform(tDeformAniData, tDeformDic, this._boneSlotArray, curTime);
  2787. }
  2788. var tSlotData2;
  2789. var tSlotData3;
  2790. var tObject;
  2791. if (this._drawOrder) {
  2792. for (i = 0, n = this._drawOrder.length; i < n; i++) {
  2793. tDBBoneSlot = this._boneSlotArray[this._drawOrder[i]];
  2794. tSlotData2 = tSlotDic[tDBBoneSlot.name];
  2795. tSlotData3 = tSlotAlphaDic[tDBBoneSlot.name];
  2796. if (!isNaN(tSlotData2) && tSlotData2 != -2) {
  2797. if (this._templet.attachmentNames) {
  2798. tDBBoneSlot.showDisplayByName(this._templet.attachmentNames[tSlotData2]);
  2799. }
  2800. else {
  2801. tDBBoneSlot.showDisplayByIndex(tSlotData2);
  2802. }
  2803. }
  2804. if (tDeformDic[this._drawOrder[i]]) {
  2805. tObject = tDeformDic[this._drawOrder[i]];
  2806. if (tDBBoneSlot.currDisplayData && tObject[tDBBoneSlot.currDisplayData.attachmentName]) {
  2807. tDBBoneSlot.deformData = tObject[tDBBoneSlot.currDisplayData.attachmentName];
  2808. }
  2809. else {
  2810. tDBBoneSlot.deformData = null;
  2811. }
  2812. }
  2813. else {
  2814. tDBBoneSlot.deformData = null;
  2815. }
  2816. if (!isNaN(tSlotData3)) {
  2817. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2, tSlotData3);
  2818. }
  2819. else {
  2820. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2);
  2821. }
  2822. }
  2823. }
  2824. else {
  2825. for (i = 0, n = this._boneSlotArray.length; i < n; i++) {
  2826. tDBBoneSlot = this._boneSlotArray[i];
  2827. tSlotData2 = tSlotDic[tDBBoneSlot.name];
  2828. tSlotData3 = tSlotAlphaDic[tDBBoneSlot.name];
  2829. if (!isNaN(tSlotData2) && tSlotData2 != -2) {
  2830. if (this._templet.attachmentNames) {
  2831. tDBBoneSlot.showDisplayByName(this._templet.attachmentNames[tSlotData2]);
  2832. }
  2833. else {
  2834. tDBBoneSlot.showDisplayByIndex(tSlotData2);
  2835. }
  2836. }
  2837. if (tDeformDic[i]) {
  2838. tObject = tDeformDic[i];
  2839. if (tDBBoneSlot.currDisplayData && tObject[tDBBoneSlot.currDisplayData.attachmentName]) {
  2840. tDBBoneSlot.deformData = tObject[tDBBoneSlot.currDisplayData.attachmentName];
  2841. }
  2842. else {
  2843. tDBBoneSlot.deformData = null;
  2844. }
  2845. }
  2846. else {
  2847. tDBBoneSlot.deformData = null;
  2848. }
  2849. if (!isNaN(tSlotData3)) {
  2850. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2, tSlotData3);
  2851. }
  2852. else {
  2853. tDBBoneSlot.draw(tGraphics, this._boneMatrixArray, this._aniMode == 2);
  2854. }
  2855. }
  2856. }
  2857. if (this._aniMode == 0) {
  2858. this._templet.setGrahicsDataWithCache(this._aniClipIndex, _clipIndex, tGraphics);
  2859. this._checkIsAllParsed(this._aniClipIndex);
  2860. }
  2861. else if (this._aniMode == 1) {
  2862. this._setGrahicsDataWithCache(this._aniClipIndex, _clipIndex, tGraphics);
  2863. }
  2864. return tGraphics;
  2865. }
  2866. _checkIsAllParsed(_aniClipIndex) {
  2867. var i, len;
  2868. len = Math.floor(0.01 + this._templet.getAniDuration(_aniClipIndex) / 1000 * this._player.cacheFrameRate);
  2869. for (i = 0; i < len; i++) {
  2870. if (!this._templet.getGrahicsDataWithCache(_aniClipIndex, i))
  2871. return;
  2872. }
  2873. if (!this._templet.getGrahicsDataWithCache(_aniClipIndex, len)) {
  2874. this._createGraphics(len);
  2875. return;
  2876. }
  2877. this._templet.deleteAniData(_aniClipIndex);
  2878. }
  2879. _setDeform(tDeformAniData, tDeformDic, _boneSlotArray, curTime) {
  2880. if (!tDeformAniData)
  2881. return;
  2882. var tDeformSlotData;
  2883. var tDeformSlotDisplayData;
  2884. var tDBBoneSlot;
  2885. var i, n, j;
  2886. if (tDeformAniData) {
  2887. for (i = 0, n = tDeformAniData.deformSlotDataList.length; i < n; i++) {
  2888. tDeformSlotData = tDeformAniData.deformSlotDataList[i];
  2889. for (j = 0; j < tDeformSlotData.deformSlotDisplayList.length; j++) {
  2890. tDeformSlotDisplayData = tDeformSlotData.deformSlotDisplayList[j];
  2891. tDBBoneSlot = _boneSlotArray[tDeformSlotDisplayData.slotIndex];
  2892. tDeformSlotDisplayData.apply(curTime, tDBBoneSlot);
  2893. if (!tDeformDic[tDeformSlotDisplayData.slotIndex]) {
  2894. tDeformDic[tDeformSlotDisplayData.slotIndex] = {};
  2895. }
  2896. tDeformDic[tDeformSlotDisplayData.slotIndex][tDeformSlotDisplayData.attachment] = tDeformSlotDisplayData.deformData;
  2897. }
  2898. }
  2899. }
  2900. }
  2901. getAnimNum() {
  2902. return this._templet.getAnimationCount();
  2903. }
  2904. getAniNameByIndex(index) {
  2905. return this._templet.getAniNameByIndex(index);
  2906. }
  2907. getSlotByName(name) {
  2908. return this._boneSlotDic[name];
  2909. }
  2910. showSkinByName(name, freshSlotIndex = true) {
  2911. this.showSkinByIndex(this._templet.getSkinIndexByName(name), freshSlotIndex);
  2912. }
  2913. showSkinByIndex(skinIndex, freshSlotIndex = true) {
  2914. for (var i = 0; i < this._boneSlotArray.length; i++) {
  2915. this._boneSlotArray[i].showSlotData(null, freshSlotIndex);
  2916. }
  2917. if (this._templet.showSkinByIndex(this._boneSlotDic, skinIndex, freshSlotIndex)) {
  2918. var tSkinData = this._templet.skinDataArray[skinIndex];
  2919. this._skinIndex = skinIndex;
  2920. this._skinName = tSkinData.name;
  2921. }
  2922. this._clearCache();
  2923. }
  2924. showSlotSkinByIndex(slotName, index) {
  2925. if (this._aniMode == 0)
  2926. return;
  2927. var tBoneSlot = this.getSlotByName(slotName);
  2928. if (tBoneSlot) {
  2929. tBoneSlot.showDisplayByIndex(index);
  2930. }
  2931. this._clearCache();
  2932. }
  2933. showSlotSkinByName(slotName, name) {
  2934. if (this._aniMode == 0)
  2935. return;
  2936. var tBoneSlot = this.getSlotByName(slotName);
  2937. if (tBoneSlot) {
  2938. tBoneSlot.showDisplayByName(name);
  2939. }
  2940. this._clearCache();
  2941. }
  2942. replaceSlotSkinName(slotName, oldName, newName) {
  2943. if (this._aniMode == 0)
  2944. return;
  2945. var tBoneSlot = this.getSlotByName(slotName);
  2946. if (tBoneSlot) {
  2947. tBoneSlot.replaceDisplayByName(oldName, newName);
  2948. }
  2949. this._clearCache();
  2950. }
  2951. replaceSlotSkinByIndex(slotName, oldIndex, newIndex) {
  2952. if (this._aniMode == 0)
  2953. return;
  2954. var tBoneSlot = this.getSlotByName(slotName);
  2955. if (tBoneSlot) {
  2956. tBoneSlot.replaceDisplayByIndex(oldIndex, newIndex);
  2957. }
  2958. this._clearCache();
  2959. }
  2960. setSlotSkin(slotName, texture) {
  2961. if (this._aniMode == 0)
  2962. return;
  2963. var tBoneSlot = this.getSlotByName(slotName);
  2964. if (tBoneSlot) {
  2965. tBoneSlot.replaceSkin(texture);
  2966. }
  2967. this._clearCache();
  2968. }
  2969. _clearCache() {
  2970. if (this._aniMode == 1) {
  2971. for (var i = 0, n = this._graphicsCache.length; i < n; i++) {
  2972. for (var j = 0, len = this._graphicsCache[i].length; j < len; j++) {
  2973. var gp = this._graphicsCache[i][j];
  2974. if (gp && gp != this.graphics) {
  2975. GraphicsAni.recycle(gp);
  2976. }
  2977. }
  2978. this._graphicsCache[i].length = 0;
  2979. }
  2980. }
  2981. }
  2982. play(nameOrIndex, loop, force = true, start = 0, end = 0, freshSkin = true, playAudio = true) {
  2983. this._playAudio = playAudio;
  2984. this._indexControl = false;
  2985. var index = -1;
  2986. var duration;
  2987. if (loop) {
  2988. duration = 2147483647;
  2989. }
  2990. else {
  2991. duration = 0;
  2992. }
  2993. if (typeof (nameOrIndex) == 'string') {
  2994. for (var i = 0, n = this._templet.getAnimationCount(); i < n; i++) {
  2995. var animation = this._templet.getAnimation(i);
  2996. if (animation && nameOrIndex == animation.name) {
  2997. index = i;
  2998. break;
  2999. }
  3000. }
  3001. }
  3002. else {
  3003. index = nameOrIndex;
  3004. }
  3005. if (index > -1 && index < this.getAnimNum()) {
  3006. this._aniClipIndex = index;
  3007. if (force || this._pause || this._currAniIndex != index) {
  3008. this._currAniIndex = index;
  3009. this._curOriginalData = new Float32Array(this._templet.getTotalkeyframesLength(index));
  3010. this._drawOrder = null;
  3011. this._eventIndex = 0;
  3012. this._player.play(index, this._player.playbackRate, duration, start, end);
  3013. if (freshSkin)
  3014. this._templet.showSkinByIndex(this._boneSlotDic, this._skinIndex);
  3015. if (this._pause) {
  3016. this._pause = false;
  3017. this._lastTime = Laya.ILaya.Browser.now();
  3018. this.timer.frameLoop(1, this, this._update, null, true);
  3019. }
  3020. this._update();
  3021. }
  3022. }
  3023. }
  3024. stop() {
  3025. if (!this._pause) {
  3026. this._pause = true;
  3027. if (this._player) {
  3028. this._player.stop(true);
  3029. }
  3030. if (this._soundChannelArr.length > 0) {
  3031. this._onAniSoundStoped(true);
  3032. }
  3033. this.timer.clear(this, this._update);
  3034. }
  3035. }
  3036. playbackRate(value) {
  3037. if (this._player) {
  3038. this._player.playbackRate = value;
  3039. }
  3040. }
  3041. paused() {
  3042. if (!this._pause) {
  3043. this._pause = true;
  3044. if (this._player) {
  3045. this._player.paused = true;
  3046. }
  3047. if (this._soundChannelArr.length > 0) {
  3048. var _soundChannel;
  3049. for (var len = this._soundChannelArr.length, i = 0; i < len; i++) {
  3050. _soundChannel = this._soundChannelArr[i];
  3051. if (!_soundChannel.isStopped) {
  3052. _soundChannel.pause();
  3053. }
  3054. }
  3055. }
  3056. this.timer.clear(this, this._update);
  3057. }
  3058. }
  3059. resume() {
  3060. this._indexControl = false;
  3061. if (this._pause) {
  3062. this._pause = false;
  3063. if (this._player) {
  3064. this._player.paused = false;
  3065. }
  3066. if (this._soundChannelArr.length > 0) {
  3067. var _soundChannel;
  3068. for (var len = this._soundChannelArr.length, i = 0; i < len; i++) {
  3069. _soundChannel = this._soundChannelArr[i];
  3070. if (_soundChannel.audioBuffer) {
  3071. _soundChannel.resume();
  3072. }
  3073. }
  3074. }
  3075. this._lastTime = Laya.ILaya.Browser.now();
  3076. this.timer.frameLoop(1, this, this._update, null, true);
  3077. }
  3078. }
  3079. _getGrahicsDataWithCache(aniIndex, frameIndex) {
  3080. return this._graphicsCache[aniIndex][frameIndex];
  3081. }
  3082. _setGrahicsDataWithCache(aniIndex, frameIndex, graphics) {
  3083. this._graphicsCache[aniIndex][frameIndex] = graphics;
  3084. }
  3085. destroy(destroyChild = true) {
  3086. super.destroy(destroyChild);
  3087. this._templet._removeReference(1);
  3088. this._templet = null;
  3089. if (this._player)
  3090. this._player.offAll();
  3091. this._player = null;
  3092. this._curOriginalData = null;
  3093. this._boneMatrixArray.length = 0;
  3094. this._lastTime = 0;
  3095. this.timer.clear(this, this._update);
  3096. if (this._soundChannelArr.length > 0) {
  3097. this._onAniSoundStoped(true);
  3098. }
  3099. }
  3100. get index() {
  3101. return this._index;
  3102. }
  3103. set index(value) {
  3104. if (this.player) {
  3105. this._index = value;
  3106. this._player.currentTime = this._index * 1000 / this._player.cacheFrameRate;
  3107. this._indexControl = true;
  3108. this._update(false);
  3109. }
  3110. }
  3111. get total() {
  3112. if (this._templet && this._player) {
  3113. this._total = Math.floor(this._templet.getAniDuration(this._player.currentAnimationClipIndex) / 1000 * this._player.cacheFrameRate);
  3114. }
  3115. else {
  3116. this._total = -1;
  3117. }
  3118. return this._total;
  3119. }
  3120. get player() {
  3121. return this._player;
  3122. }
  3123. get templet() {
  3124. return this._templet;
  3125. }
  3126. }
  3127. Skeleton.useSimpleMeshInCanvas = false;
  3128. IAniLib.Skeleton = Skeleton;
  3129. Laya.ILaya.regClass(Skeleton);
  3130. Laya.ClassUtils.regClass("laya.ani.bone.Skeleton", Skeleton);
  3131. Laya.ClassUtils.regClass("Laya.Skeleton", Skeleton);
  3132. class SkinData {
  3133. constructor() {
  3134. this.slotArr = [];
  3135. }
  3136. }
  3137. class SkinSlotDisplayData {
  3138. createTexture(currTexture) {
  3139. if (this.texture)
  3140. return this.texture;
  3141. this.texture = new Laya.Texture(currTexture.bitmap, this.uvs);
  3142. if (this.uvs[0] > this.uvs[4]
  3143. && this.uvs[1] > this.uvs[5]) {
  3144. this.texture.width = currTexture.height;
  3145. this.texture.height = currTexture.width;
  3146. this.texture.offsetX = -currTexture.offsetX;
  3147. this.texture.offsetY = -currTexture.offsetY;
  3148. this.texture.sourceWidth = currTexture.sourceHeight;
  3149. this.texture.sourceHeight = currTexture.sourceWidth;
  3150. }
  3151. else {
  3152. this.texture.width = currTexture.width;
  3153. this.texture.height = currTexture.height;
  3154. this.texture.offsetX = -currTexture.offsetX;
  3155. this.texture.offsetY = -currTexture.offsetY;
  3156. this.texture.sourceWidth = currTexture.sourceWidth;
  3157. this.texture.sourceHeight = currTexture.sourceHeight;
  3158. }
  3159. return this.texture;
  3160. }
  3161. destory() {
  3162. if (this.texture)
  3163. this.texture.destroy();
  3164. }
  3165. }
  3166. class SlotData {
  3167. constructor() {
  3168. this.displayArr = [];
  3169. }
  3170. getDisplayByName(name) {
  3171. var tDisplay;
  3172. for (var i = 0, n = this.displayArr.length; i < n; i++) {
  3173. tDisplay = this.displayArr[i];
  3174. if (tDisplay.attachmentName == name) {
  3175. return i;
  3176. }
  3177. }
  3178. return -1;
  3179. }
  3180. }
  3181. class TfConstraintData {
  3182. constructor() {
  3183. this.boneIndexs = [];
  3184. }
  3185. }
  3186. class Templet extends AnimationTemplet {
  3187. constructor() {
  3188. super(...arguments);
  3189. this._graphicsCache = [];
  3190. this.srcBoneMatrixArr = [];
  3191. this.ikArr = [];
  3192. this.tfArr = [];
  3193. this.pathArr = [];
  3194. this.boneSlotDic = {};
  3195. this.bindBoneBoneSlotDic = {};
  3196. this.boneSlotArray = [];
  3197. this.skinDataArray = [];
  3198. this.skinDic = {};
  3199. this.subTextureDic = {};
  3200. this.isParseFail = false;
  3201. this.drawOrderAniArr = [];
  3202. this.eventAniArr = [];
  3203. this.attachmentNames = null;
  3204. this.deformAniArr = [];
  3205. this.skinSlotDisplayDataArr = [];
  3206. this._isParseAudio = false;
  3207. this._isDestroyed = false;
  3208. this._rate = 30;
  3209. this.isParserComplete = false;
  3210. this.aniSectionDic = {};
  3211. this._textureDic = {};
  3212. this.mBoneArr = [];
  3213. }
  3214. loadAni(url) {
  3215. this._skBufferUrl = url;
  3216. Laya.ILaya.loader.load(url, Laya.Handler.create(this, this.onComplete), null, Laya.ILaya.Loader.BUFFER);
  3217. }
  3218. onComplete(content = null) {
  3219. if (this._isDestroyed) {
  3220. this.destroy();
  3221. return;
  3222. }
  3223. var tSkBuffer = Laya.ILaya.Loader.getRes(this._skBufferUrl);
  3224. if (!tSkBuffer) {
  3225. this.event(Laya.Event.ERROR, "load failed:" + this._skBufferUrl);
  3226. return;
  3227. }
  3228. this._path = this._skBufferUrl.slice(0, this._skBufferUrl.lastIndexOf("/")) + "/";
  3229. this.parseData(null, tSkBuffer);
  3230. }
  3231. parseData(texture, skeletonData, playbackRate = 30) {
  3232. if (!this._path) {
  3233. var s1 = (this._relativeUrl || this.url);
  3234. if (s1) {
  3235. var p1 = s1.lastIndexOf('/');
  3236. if (p1 > 0) {
  3237. this._path = s1.slice(0, p1) + "/";
  3238. }
  3239. else {
  3240. this._path = '';
  3241. }
  3242. }
  3243. }
  3244. this._mainTexture = texture;
  3245. this._rate = playbackRate;
  3246. this.parse(skeletonData);
  3247. }
  3248. buildArmature(aniMode = 0) {
  3249. return new Skeleton(this, aniMode);
  3250. }
  3251. parse(data) {
  3252. super.parse(data);
  3253. this.event(Laya.Event.LOADED, this);
  3254. if (this._aniVersion === Templet.LAYA_ANIMATION_VISION) {
  3255. this._isParseAudio = true;
  3256. }
  3257. else if (this._aniVersion != Templet.LAYA_ANIMATION_160_VISION) {
  3258. console.log("[Error] 版本不一致,请使用IDE版本配套的重新导出" + this._aniVersion + "->" + Templet.LAYA_ANIMATION_VISION);
  3259. }
  3260. if (this._mainTexture) {
  3261. this._parsePublicExtData();
  3262. }
  3263. else {
  3264. this._parseTexturePath();
  3265. }
  3266. }
  3267. _parseTexturePath() {
  3268. if (this._isDestroyed) {
  3269. this.destroy();
  3270. return;
  3271. }
  3272. var i = 0;
  3273. this._loadList = [];
  3274. var tByte = new Laya.Byte(this.getPublicExtData());
  3275. var tX = 0, tY = 0, tWidth = 0, tHeight = 0;
  3276. var tTempleData = 0;
  3277. var tTextureLen = tByte.getInt32();
  3278. var tTextureName = tByte.readUTFString();
  3279. var tTextureNameArr = tTextureName.split("\n");
  3280. var tSrcTexturePath;
  3281. for (i = 0; i < tTextureLen; i++) {
  3282. tSrcTexturePath = this._path + tTextureNameArr[i * 2];
  3283. tTextureName = tTextureNameArr[i * 2 + 1];
  3284. tX = tByte.getFloat32();
  3285. tY = tByte.getFloat32();
  3286. tWidth = tByte.getFloat32();
  3287. tHeight = tByte.getFloat32();
  3288. tTempleData = tByte.getFloat32();
  3289. tTempleData = tByte.getFloat32();
  3290. tTempleData = tByte.getFloat32();
  3291. tTempleData = tByte.getFloat32();
  3292. if (this._loadList.indexOf(tSrcTexturePath) == -1) {
  3293. this._loadList.push(tSrcTexturePath);
  3294. }
  3295. }
  3296. Laya.ILaya.loader.load(this._loadList, Laya.Handler.create(this, this._textureComplete));
  3297. }
  3298. _textureComplete() {
  3299. var tTexture;
  3300. var tTextureName;
  3301. for (var i = 0, n = this._loadList.length; i < n; i++) {
  3302. tTextureName = this._loadList[i];
  3303. tTexture = this._textureDic[tTextureName] = Laya.ILaya.Loader.getRes(tTextureName);
  3304. }
  3305. this._parsePublicExtData();
  3306. }
  3307. _parsePublicExtData() {
  3308. var i = 0, j = 0, k = 0, l = 0, n = 0;
  3309. for (i = 0, n = this.getAnimationCount(); i < n; i++) {
  3310. this._graphicsCache.push([]);
  3311. }
  3312. var isSpine;
  3313. isSpine = this._aniClassName != "Dragon";
  3314. var tByte = new Laya.Byte(this.getPublicExtData());
  3315. var tX = 0, tY = 0, tWidth = 0, tHeight = 0;
  3316. var tFrameX = 0, tFrameY = 0, tFrameWidth = 0, tFrameHeight = 0;
  3317. var tTempleData = 0;
  3318. var tTextureLen = tByte.getInt32();
  3319. var tTextureName = tByte.readUTFString();
  3320. var tTextureNameArr = tTextureName.split("\n");
  3321. var tTexture;
  3322. var tSrcTexturePath;
  3323. for (i = 0; i < tTextureLen; i++) {
  3324. tTexture = this._mainTexture;
  3325. tSrcTexturePath = this._path + tTextureNameArr[i * 2];
  3326. tTextureName = tTextureNameArr[i * 2 + 1];
  3327. if (this._mainTexture == null) {
  3328. tTexture = this._textureDic[tSrcTexturePath];
  3329. }
  3330. if (!tTexture) {
  3331. this.event(Laya.Event.ERROR, this);
  3332. this.isParseFail = true;
  3333. return;
  3334. }
  3335. tX = tByte.getFloat32();
  3336. tY = tByte.getFloat32();
  3337. tWidth = tByte.getFloat32();
  3338. tHeight = tByte.getFloat32();
  3339. tTempleData = tByte.getFloat32();
  3340. tFrameX = isNaN(tTempleData) ? 0 : tTempleData;
  3341. tTempleData = tByte.getFloat32();
  3342. tFrameY = isNaN(tTempleData) ? 0 : tTempleData;
  3343. tTempleData = tByte.getFloat32();
  3344. tFrameWidth = isNaN(tTempleData) ? tWidth : tTempleData;
  3345. tTempleData = tByte.getFloat32();
  3346. tFrameHeight = isNaN(tTempleData) ? tHeight : tTempleData;
  3347. this.subTextureDic[tTextureName] = Laya.Texture.create(tTexture, tX, tY, tWidth, tHeight, -tFrameX, -tFrameY, tFrameWidth, tFrameHeight);
  3348. }
  3349. this._mainTexture = tTexture;
  3350. var tAniCount = tByte.getUint16();
  3351. var tSectionArr;
  3352. for (i = 0; i < tAniCount; i++) {
  3353. tSectionArr = [];
  3354. tSectionArr.push(tByte.getUint16());
  3355. tSectionArr.push(tByte.getUint16());
  3356. tSectionArr.push(tByte.getUint16());
  3357. tSectionArr.push(tByte.getUint16());
  3358. this.aniSectionDic[i] = tSectionArr;
  3359. }
  3360. var tBone;
  3361. var tParentBone;
  3362. var tName;
  3363. var tParentName;
  3364. var tBoneLen = tByte.getInt16();
  3365. var tBoneDic = {};
  3366. var tRootBone;
  3367. for (i = 0; i < tBoneLen; i++) {
  3368. tBone = new Bone();
  3369. if (i == 0) {
  3370. tRootBone = tBone;
  3371. }
  3372. else {
  3373. tBone.root = tRootBone;
  3374. }
  3375. tBone.d = isSpine ? -1 : 1;
  3376. tName = tByte.readUTFString();
  3377. tParentName = tByte.readUTFString();
  3378. tBone.length = tByte.getFloat32();
  3379. if (tByte.getByte() == 1) {
  3380. tBone.inheritRotation = false;
  3381. }
  3382. if (tByte.getByte() == 1) {
  3383. tBone.inheritScale = false;
  3384. }
  3385. tBone.name = tName;
  3386. if (tParentName) {
  3387. tParentBone = tBoneDic[tParentName];
  3388. if (tParentBone) {
  3389. tParentBone.addChild(tBone);
  3390. }
  3391. else {
  3392. this.mRootBone = tBone;
  3393. }
  3394. }
  3395. tBoneDic[tName] = tBone;
  3396. this.mBoneArr.push(tBone);
  3397. }
  3398. this.tMatrixDataLen = tByte.getUint16();
  3399. var tLen = tByte.getUint16();
  3400. var boneLength = Math.floor(tLen / this.tMatrixDataLen);
  3401. var tResultTransform;
  3402. var tMatrixArray = this.srcBoneMatrixArr;
  3403. for (i = 0; i < boneLength; i++) {
  3404. tResultTransform = new Transform();
  3405. tResultTransform.scX = tByte.getFloat32();
  3406. tResultTransform.skX = tByte.getFloat32();
  3407. tResultTransform.skY = tByte.getFloat32();
  3408. tResultTransform.scY = tByte.getFloat32();
  3409. tResultTransform.x = tByte.getFloat32();
  3410. tResultTransform.y = tByte.getFloat32();
  3411. if (this.tMatrixDataLen === 8) {
  3412. tResultTransform.skewX = tByte.getFloat32();
  3413. tResultTransform.skewY = tByte.getFloat32();
  3414. }
  3415. tMatrixArray.push(tResultTransform);
  3416. tBone = this.mBoneArr[i];
  3417. tBone.transform = tResultTransform;
  3418. }
  3419. var tIkConstraintData;
  3420. var tIkLen = tByte.getUint16();
  3421. var tIkBoneLen;
  3422. for (i = 0; i < tIkLen; i++) {
  3423. tIkConstraintData = new IkConstraintData();
  3424. tIkBoneLen = tByte.getUint16();
  3425. for (j = 0; j < tIkBoneLen; j++) {
  3426. tIkConstraintData.boneNames.push(tByte.readUTFString());
  3427. tIkConstraintData.boneIndexs.push(tByte.getInt16());
  3428. }
  3429. tIkConstraintData.name = tByte.readUTFString();
  3430. tIkConstraintData.targetBoneName = tByte.readUTFString();
  3431. tIkConstraintData.targetBoneIndex = tByte.getInt16();
  3432. tIkConstraintData.bendDirection = tByte.getFloat32();
  3433. tIkConstraintData.mix = tByte.getFloat32();
  3434. tIkConstraintData.isSpine = isSpine;
  3435. this.ikArr.push(tIkConstraintData);
  3436. }
  3437. var tTfConstraintData;
  3438. var tTfLen = tByte.getUint16();
  3439. var tTfBoneLen;
  3440. for (i = 0; i < tTfLen; i++) {
  3441. tTfConstraintData = new TfConstraintData();
  3442. tTfBoneLen = tByte.getUint16();
  3443. for (j = 0; j < tTfBoneLen; j++) {
  3444. tTfConstraintData.boneIndexs.push(tByte.getInt16());
  3445. }
  3446. tTfConstraintData.name = tByte.getUTFString();
  3447. tTfConstraintData.targetIndex = tByte.getInt16();
  3448. tTfConstraintData.rotateMix = tByte.getFloat32();
  3449. tTfConstraintData.translateMix = tByte.getFloat32();
  3450. tTfConstraintData.scaleMix = tByte.getFloat32();
  3451. tTfConstraintData.shearMix = tByte.getFloat32();
  3452. tTfConstraintData.offsetRotation = tByte.getFloat32();
  3453. tTfConstraintData.offsetX = tByte.getFloat32();
  3454. tTfConstraintData.offsetY = tByte.getFloat32();
  3455. tTfConstraintData.offsetScaleX = tByte.getFloat32();
  3456. tTfConstraintData.offsetScaleY = tByte.getFloat32();
  3457. tTfConstraintData.offsetShearY = tByte.getFloat32();
  3458. this.tfArr.push(tTfConstraintData);
  3459. }
  3460. var tPathConstraintData;
  3461. var tPathLen = tByte.getUint16();
  3462. var tPathBoneLen;
  3463. for (i = 0; i < tPathLen; i++) {
  3464. tPathConstraintData = new PathConstraintData();
  3465. tPathConstraintData.name = tByte.readUTFString();
  3466. tPathBoneLen = tByte.getUint16();
  3467. for (j = 0; j < tPathBoneLen; j++) {
  3468. tPathConstraintData.bones.push(tByte.getInt16());
  3469. }
  3470. tPathConstraintData.target = tByte.readUTFString();
  3471. tPathConstraintData.positionMode = tByte.readUTFString();
  3472. tPathConstraintData.spacingMode = tByte.readUTFString();
  3473. tPathConstraintData.rotateMode = tByte.readUTFString();
  3474. tPathConstraintData.offsetRotation = tByte.getFloat32();
  3475. tPathConstraintData.position = tByte.getFloat32();
  3476. tPathConstraintData.spacing = tByte.getFloat32();
  3477. tPathConstraintData.rotateMix = tByte.getFloat32();
  3478. tPathConstraintData.translateMix = tByte.getFloat32();
  3479. this.pathArr.push(tPathConstraintData);
  3480. }
  3481. var tDeformSlotLen;
  3482. var tDeformSlotDisplayLen;
  3483. var tDSlotIndex;
  3484. var tDAttachment;
  3485. var tDeformTimeLen;
  3486. var tDTime;
  3487. var tDeformVecticesLen;
  3488. var tDeformAniData;
  3489. var tDeformSlotData;
  3490. var tDeformSlotDisplayData;
  3491. var tDeformVectices;
  3492. var tDeformAniLen = tByte.getInt16();
  3493. for (i = 0; i < tDeformAniLen; i++) {
  3494. var tDeformSkinLen = tByte.getUint8();
  3495. var tSkinDic = {};
  3496. this.deformAniArr.push(tSkinDic);
  3497. for (var f = 0; f < tDeformSkinLen; f++) {
  3498. tDeformAniData = new DeformAniData();
  3499. tDeformAniData.skinName = tByte.getUTFString();
  3500. tSkinDic[tDeformAniData.skinName] = tDeformAniData;
  3501. tDeformSlotLen = tByte.getInt16();
  3502. for (j = 0; j < tDeformSlotLen; j++) {
  3503. tDeformSlotData = new DeformSlotData();
  3504. tDeformAniData.deformSlotDataList.push(tDeformSlotData);
  3505. tDeformSlotDisplayLen = tByte.getInt16();
  3506. for (k = 0; k < tDeformSlotDisplayLen; k++) {
  3507. tDeformSlotDisplayData = new DeformSlotDisplayData();
  3508. tDeformSlotData.deformSlotDisplayList.push(tDeformSlotDisplayData);
  3509. tDeformSlotDisplayData.slotIndex = tDSlotIndex = tByte.getInt16();
  3510. tDeformSlotDisplayData.attachment = tDAttachment = tByte.getUTFString();
  3511. tDeformTimeLen = tByte.getInt16();
  3512. for (l = 0; l < tDeformTimeLen; l++) {
  3513. if (tByte.getByte() == 1) {
  3514. tDeformSlotDisplayData.tweenKeyList.push(true);
  3515. }
  3516. else {
  3517. tDeformSlotDisplayData.tweenKeyList.push(false);
  3518. }
  3519. tDTime = tByte.getFloat32();
  3520. tDeformSlotDisplayData.timeList.push(tDTime);
  3521. tDeformVectices = [];
  3522. tDeformSlotDisplayData.vectices.push(tDeformVectices);
  3523. tDeformVecticesLen = tByte.getInt16();
  3524. for (n = 0; n < tDeformVecticesLen; n++) {
  3525. tDeformVectices.push(tByte.getFloat32());
  3526. }
  3527. }
  3528. }
  3529. }
  3530. }
  3531. }
  3532. var tDrawOrderArr;
  3533. var tDrawOrderAniLen = tByte.getInt16();
  3534. var tDrawOrderLen;
  3535. var tDrawOrderData;
  3536. var tDoLen;
  3537. for (i = 0; i < tDrawOrderAniLen; i++) {
  3538. tDrawOrderLen = tByte.getInt16();
  3539. tDrawOrderArr = [];
  3540. for (j = 0; j < tDrawOrderLen; j++) {
  3541. tDrawOrderData = new DrawOrderData();
  3542. tDrawOrderData.time = tByte.getFloat32();
  3543. tDoLen = tByte.getInt16();
  3544. for (k = 0; k < tDoLen; k++) {
  3545. tDrawOrderData.drawOrder.push(tByte.getInt16());
  3546. }
  3547. tDrawOrderArr.push(tDrawOrderData);
  3548. }
  3549. this.drawOrderAniArr.push(tDrawOrderArr);
  3550. }
  3551. var tEventArr;
  3552. var tEventAniLen = tByte.getInt16();
  3553. var tEventLen;
  3554. var tEventData;
  3555. for (i = 0; i < tEventAniLen; i++) {
  3556. tEventLen = tByte.getInt16();
  3557. tEventArr = [];
  3558. for (j = 0; j < tEventLen; j++) {
  3559. tEventData = new EventData();
  3560. tEventData.name = tByte.getUTFString();
  3561. if (this._isParseAudio)
  3562. tEventData.audioValue = tByte.getUTFString();
  3563. tEventData.intValue = tByte.getInt32();
  3564. tEventData.floatValue = tByte.getFloat32();
  3565. tEventData.stringValue = tByte.getUTFString();
  3566. tEventData.time = tByte.getFloat32();
  3567. tEventArr.push(tEventData);
  3568. }
  3569. this.eventAniArr.push(tEventArr);
  3570. }
  3571. var tAttachmentLen = tByte.getInt16();
  3572. if (tAttachmentLen > 0) {
  3573. this.attachmentNames = [];
  3574. for (i = 0; i < tAttachmentLen; i++) {
  3575. this.attachmentNames.push(tByte.getUTFString());
  3576. }
  3577. }
  3578. var tBoneSlotLen = tByte.getInt16();
  3579. var tDBBoneSlot;
  3580. var tDBBoneSlotArr;
  3581. for (i = 0; i < tBoneSlotLen; i++) {
  3582. tDBBoneSlot = new BoneSlot();
  3583. tDBBoneSlot.name = tByte.readUTFString();
  3584. tDBBoneSlot.parent = tByte.readUTFString();
  3585. tDBBoneSlot.attachmentName = tByte.readUTFString();
  3586. tDBBoneSlot.srcDisplayIndex = tDBBoneSlot.displayIndex = tByte.getInt16();
  3587. tDBBoneSlot.templet = this;
  3588. this.boneSlotDic[tDBBoneSlot.name] = tDBBoneSlot;
  3589. tDBBoneSlotArr = this.bindBoneBoneSlotDic[tDBBoneSlot.parent];
  3590. if (tDBBoneSlotArr == null) {
  3591. this.bindBoneBoneSlotDic[tDBBoneSlot.parent] = tDBBoneSlotArr = [];
  3592. }
  3593. tDBBoneSlotArr.push(tDBBoneSlot);
  3594. this.boneSlotArray.push(tDBBoneSlot);
  3595. }
  3596. var tNameString = tByte.readUTFString();
  3597. var tNameArray = tNameString.split("\n");
  3598. var tNameStartIndex = 0;
  3599. var tSkinDataLen = tByte.getUint8();
  3600. var tSkinData, tSlotData, tDisplayData;
  3601. var tSlotDataLen, tDisplayDataLen;
  3602. var tUvLen, tWeightLen, tTriangleLen, tVerticeLen, tLengthLen;
  3603. for (i = 0; i < tSkinDataLen; i++) {
  3604. tSkinData = new SkinData();
  3605. tSkinData.name = tNameArray[tNameStartIndex++];
  3606. tSlotDataLen = tByte.getUint8();
  3607. for (j = 0; j < tSlotDataLen; j++) {
  3608. tSlotData = new SlotData();
  3609. tSlotData.name = tNameArray[tNameStartIndex++];
  3610. tDBBoneSlot = this.boneSlotDic[tSlotData.name];
  3611. tDisplayDataLen = tByte.getUint8();
  3612. for (k = 0; k < tDisplayDataLen; k++) {
  3613. tDisplayData = new SkinSlotDisplayData();
  3614. this.skinSlotDisplayDataArr.push(tDisplayData);
  3615. tDisplayData.name = tNameArray[tNameStartIndex++];
  3616. tDisplayData.attachmentName = tNameArray[tNameStartIndex++];
  3617. tDisplayData.transform = new Transform();
  3618. tDisplayData.transform.scX = tByte.getFloat32();
  3619. tDisplayData.transform.skX = tByte.getFloat32();
  3620. tDisplayData.transform.skY = tByte.getFloat32();
  3621. tDisplayData.transform.scY = tByte.getFloat32();
  3622. tDisplayData.transform.x = tByte.getFloat32();
  3623. tDisplayData.transform.y = tByte.getFloat32();
  3624. tSlotData.displayArr.push(tDisplayData);
  3625. tDisplayData.width = tByte.getFloat32();
  3626. tDisplayData.height = tByte.getFloat32();
  3627. tDisplayData.type = tByte.getUint8();
  3628. tDisplayData.verLen = tByte.getUint16();
  3629. tBoneLen = tByte.getUint16();
  3630. if (tBoneLen > 0) {
  3631. tDisplayData.bones = [];
  3632. for (l = 0; l < tBoneLen; l++) {
  3633. var tBoneId = tByte.getUint16();
  3634. tDisplayData.bones.push(tBoneId);
  3635. }
  3636. }
  3637. tUvLen = tByte.getUint16();
  3638. if (tUvLen > 0) {
  3639. tDisplayData.uvs = [];
  3640. for (l = 0; l < tUvLen; l++) {
  3641. tDisplayData.uvs.push(tByte.getFloat32());
  3642. }
  3643. }
  3644. tWeightLen = tByte.getUint16();
  3645. if (tWeightLen > 0) {
  3646. tDisplayData.weights = [];
  3647. for (l = 0; l < tWeightLen; l++) {
  3648. tDisplayData.weights.push(tByte.getFloat32());
  3649. }
  3650. }
  3651. tTriangleLen = tByte.getUint16();
  3652. if (tTriangleLen > 0) {
  3653. tDisplayData.triangles = [];
  3654. for (l = 0; l < tTriangleLen; l++) {
  3655. tDisplayData.triangles.push(tByte.getUint16());
  3656. }
  3657. }
  3658. tVerticeLen = tByte.getUint16();
  3659. if (tVerticeLen > 0) {
  3660. tDisplayData.vertices = [];
  3661. for (l = 0; l < tVerticeLen; l++) {
  3662. tDisplayData.vertices.push(tByte.getFloat32());
  3663. }
  3664. }
  3665. tLengthLen = tByte.getUint16();
  3666. if (tLengthLen > 0) {
  3667. tDisplayData.lengths = [];
  3668. for (l = 0; l < tLengthLen; l++) {
  3669. tDisplayData.lengths.push(tByte.getFloat32());
  3670. }
  3671. }
  3672. }
  3673. tSkinData.slotArr.push(tSlotData);
  3674. }
  3675. this.skinDic[tSkinData.name] = tSkinData;
  3676. this.skinDataArray.push(tSkinData);
  3677. }
  3678. var tReverse = tByte.getUint8();
  3679. if (tReverse == 1) {
  3680. this.yReverseMatrix = new Laya.Matrix(1, 0, 0, -1, 0, 0);
  3681. if (tRootBone) {
  3682. tRootBone.setTempMatrix(this.yReverseMatrix);
  3683. }
  3684. }
  3685. else {
  3686. if (tRootBone) {
  3687. tRootBone.setTempMatrix(new Laya.Matrix());
  3688. }
  3689. }
  3690. this.showSkinByIndex(this.boneSlotDic, 0);
  3691. this.isParserComplete = true;
  3692. this.event(Laya.Event.COMPLETE, this);
  3693. }
  3694. getTexture(name) {
  3695. var tTexture = this.subTextureDic[name];
  3696. if (!tTexture) {
  3697. tTexture = this.subTextureDic[name.substr(0, name.length - 1)];
  3698. }
  3699. if (tTexture == null) {
  3700. return this._mainTexture;
  3701. }
  3702. return tTexture;
  3703. }
  3704. showSkinByIndex(boneSlotDic, skinIndex, freshDisplayIndex = true) {
  3705. if (skinIndex < 0 && skinIndex >= this.skinDataArray.length)
  3706. return false;
  3707. var i, n;
  3708. var tBoneSlot;
  3709. var tSlotData;
  3710. var tSkinData = this.skinDataArray[skinIndex];
  3711. if (tSkinData) {
  3712. for (i = 0, n = tSkinData.slotArr.length; i < n; i++) {
  3713. tSlotData = tSkinData.slotArr[i];
  3714. if (tSlotData) {
  3715. tBoneSlot = boneSlotDic[tSlotData.name];
  3716. if (tBoneSlot) {
  3717. tBoneSlot.showSlotData(tSlotData, freshDisplayIndex);
  3718. if (freshDisplayIndex && tBoneSlot.attachmentName != "undefined" && tBoneSlot.attachmentName != "null") {
  3719. tBoneSlot.showDisplayByName(tBoneSlot.attachmentName);
  3720. }
  3721. else {
  3722. tBoneSlot.showDisplayByIndex(tBoneSlot.displayIndex);
  3723. }
  3724. }
  3725. }
  3726. }
  3727. return true;
  3728. }
  3729. return false;
  3730. }
  3731. getSkinIndexByName(skinName) {
  3732. var tSkinData;
  3733. for (var i = 0, n = this.skinDataArray.length; i < n; i++) {
  3734. tSkinData = this.skinDataArray[i];
  3735. if (tSkinData.name == skinName) {
  3736. return i;
  3737. }
  3738. }
  3739. return -1;
  3740. }
  3741. getGrahicsDataWithCache(aniIndex, frameIndex) {
  3742. if (this._graphicsCache[aniIndex] && this._graphicsCache[aniIndex][frameIndex]) {
  3743. return this._graphicsCache[aniIndex][frameIndex];
  3744. }
  3745. return null;
  3746. }
  3747. _setCreateURL(url) {
  3748. this._skBufferUrl = this._relativeUrl = url;
  3749. super._setCreateURL(url);
  3750. }
  3751. setGrahicsDataWithCache(aniIndex, frameIndex, graphics) {
  3752. this._graphicsCache[aniIndex][frameIndex] = graphics;
  3753. }
  3754. deleteAniData(aniIndex) {
  3755. if (this._anis[aniIndex]) {
  3756. var tAniDataO = this._anis[aniIndex];
  3757. tAniDataO.bone3DMap = null;
  3758. tAniDataO.nodes = null;
  3759. }
  3760. }
  3761. destroy() {
  3762. this._isDestroyed = true;
  3763. var tTexture;
  3764. for (tTexture in this.subTextureDic) {
  3765. if (tTexture) {
  3766. this.subTextureDic[tTexture].destroy();
  3767. }
  3768. }
  3769. for (tTexture in this._textureDic) {
  3770. if (tTexture) {
  3771. this._textureDic[tTexture].destroy();
  3772. }
  3773. }
  3774. var tSkinSlotDisplayData;
  3775. for (var i = 0, n = this.skinSlotDisplayDataArr.length; i < n; i++) {
  3776. tSkinSlotDisplayData = this.skinSlotDisplayDataArr[i];
  3777. tSkinSlotDisplayData.destory();
  3778. }
  3779. this.skinSlotDisplayDataArr.length = 0;
  3780. if (this.url) {
  3781. delete Templet.TEMPLET_DICTIONARY[this.url];
  3782. }
  3783. super.destroy();
  3784. Laya.ILaya.loader.clearRes(this._skBufferUrl);
  3785. }
  3786. getAniNameByIndex(index) {
  3787. var tAni = this.getAnimation(index);
  3788. if (tAni)
  3789. return tAni.name;
  3790. return null;
  3791. }
  3792. get rate() {
  3793. return this._rate;
  3794. }
  3795. set rate(v) {
  3796. this._rate = v;
  3797. }
  3798. }
  3799. Templet.LAYA_ANIMATION_160_VISION = "LAYAANIMATION:1.6.0";
  3800. Templet.LAYA_ANIMATION_VISION = "LAYAANIMATION:1.7.0";
  3801. IAniLib.Templet = Templet;
  3802. class MovieClip extends Laya.Sprite {
  3803. constructor(parentMovieClip = null) {
  3804. super();
  3805. this._start = 0;
  3806. this._Pos = 0;
  3807. this._ended = true;
  3808. this._loadedImage = {};
  3809. this._endFrame = -1;
  3810. this.interval = 30;
  3811. this._ids = {};
  3812. this._idOfSprite = [];
  3813. this._reset();
  3814. this._playing = false;
  3815. this._parentMovieClip = parentMovieClip;
  3816. if (!parentMovieClip) {
  3817. this._movieClipList = [this];
  3818. this._isRoot = true;
  3819. this._setBitUp(Laya.Const.DISPLAY);
  3820. }
  3821. else {
  3822. this._isRoot = false;
  3823. this._movieClipList = parentMovieClip._movieClipList;
  3824. this._movieClipList.push(this);
  3825. }
  3826. }
  3827. destroy(destroyChild = true) {
  3828. this._clear();
  3829. super.destroy(destroyChild);
  3830. }
  3831. _setDisplay(value) {
  3832. super._setDisplay(value);
  3833. if (this._isRoot) {
  3834. this._onDisplay(value);
  3835. }
  3836. }
  3837. _onDisplay(value) {
  3838. if (value)
  3839. this.timer.loop(this.interval, this, this.updates, null, true);
  3840. else
  3841. this.timer.clear(this, this.updates);
  3842. }
  3843. updates() {
  3844. if (this._parentMovieClip)
  3845. return;
  3846. var i, len;
  3847. len = this._movieClipList.length;
  3848. for (i = 0; i < len; i++) {
  3849. this._movieClipList[i] && this._movieClipList[i]._update();
  3850. }
  3851. }
  3852. get index() {
  3853. return this._playIndex;
  3854. }
  3855. set index(value) {
  3856. this._playIndex = value;
  3857. if (this._data)
  3858. this._displayFrame(this._playIndex);
  3859. if (this._labels && this._labels[value])
  3860. this.event(Laya.Event.LABEL, this._labels[value]);
  3861. }
  3862. addLabel(label, index) {
  3863. if (!this._labels)
  3864. this._labels = {};
  3865. this._labels[index] = label;
  3866. }
  3867. removeLabel(label) {
  3868. if (!label)
  3869. this._labels = null;
  3870. else if (!this._labels) {
  3871. for (var name in this._labels) {
  3872. if (this._labels[name] === label) {
  3873. delete this._labels[name];
  3874. break;
  3875. }
  3876. }
  3877. }
  3878. }
  3879. get count() {
  3880. return this._count;
  3881. }
  3882. get playing() {
  3883. return this._playing;
  3884. }
  3885. _update() {
  3886. if (!this._data)
  3887. return;
  3888. if (!this._playing)
  3889. return;
  3890. this._playIndex++;
  3891. if (this._playIndex >= this._count) {
  3892. if (!this.loop) {
  3893. this._playIndex--;
  3894. this.stop();
  3895. return;
  3896. }
  3897. this._playIndex = 0;
  3898. }
  3899. this._parseFrame(this._playIndex);
  3900. if (this._labels && this._labels[this._playIndex])
  3901. this.event(Laya.Event.LABEL, this._labels[this._playIndex]);
  3902. if (this._endFrame != -1 && this._endFrame == this._playIndex) {
  3903. this._endFrame = -1;
  3904. if (this._completeHandler != null) {
  3905. var handler = this._completeHandler;
  3906. this._completeHandler = null;
  3907. handler.run();
  3908. }
  3909. this.stop();
  3910. }
  3911. }
  3912. stop() {
  3913. this._playing = false;
  3914. }
  3915. gotoAndStop(index) {
  3916. this.index = index;
  3917. this.stop();
  3918. }
  3919. _clear() {
  3920. this.stop();
  3921. this._idOfSprite.length = 0;
  3922. if (!this._parentMovieClip) {
  3923. this.timer.clear(this, this.updates);
  3924. var i, len;
  3925. len = this._movieClipList.length;
  3926. for (i = 0; i < len; i++) {
  3927. if (this._movieClipList[i] != this)
  3928. this._movieClipList[i]._clear();
  3929. }
  3930. this._movieClipList.length = 0;
  3931. }
  3932. if (this._atlasPath) {
  3933. Laya.ILaya.Loader.clearRes(this._atlasPath);
  3934. }
  3935. var key;
  3936. for (key in this._loadedImage) {
  3937. if (this._loadedImage[key]) {
  3938. Laya.ILaya.Loader.clearRes(key);
  3939. this._loadedImage[key] = false;
  3940. }
  3941. }
  3942. this.removeChildren();
  3943. this.graphics = null;
  3944. this._parentMovieClip = null;
  3945. }
  3946. play(index = 0, loop = true) {
  3947. this.loop = loop;
  3948. this._playing = true;
  3949. if (this._data)
  3950. this._displayFrame(index);
  3951. }
  3952. _displayFrame(frameIndex = -1) {
  3953. if (frameIndex != -1) {
  3954. if (this._curIndex > frameIndex)
  3955. this._reset();
  3956. this._parseFrame(frameIndex);
  3957. }
  3958. }
  3959. _reset(rm = true) {
  3960. if (rm && this._curIndex != 1)
  3961. this.removeChildren();
  3962. this._preIndex = this._curIndex = -1;
  3963. this._Pos = this._start;
  3964. }
  3965. _parseFrame(frameIndex) {
  3966. var mc, sp, key, type, tPos, ttype, ifAdd = false;
  3967. var _idOfSprite = this._idOfSprite, _data = this._data, eStr;
  3968. if (this._ended)
  3969. this._reset();
  3970. _data.pos = this._Pos;
  3971. this._ended = false;
  3972. this._playIndex = frameIndex;
  3973. if (this._curIndex > frameIndex && frameIndex < this._preIndex) {
  3974. this._reset(true);
  3975. _data.pos = this._Pos;
  3976. }
  3977. while ((this._curIndex <= frameIndex) && (!this._ended)) {
  3978. type = _data.getUint16();
  3979. switch (type) {
  3980. case 12:
  3981. key = _data.getUint16();
  3982. tPos = this._ids[_data.getUint16()];
  3983. this._Pos = _data.pos;
  3984. _data.pos = tPos;
  3985. if ((ttype = _data.getUint8()) == 0) {
  3986. var pid = _data.getUint16();
  3987. sp = _idOfSprite[key];
  3988. if (!sp) {
  3989. sp = _idOfSprite[key] = new Laya.Sprite();
  3990. var spp = new Laya.Sprite();
  3991. spp.loadImage(this.basePath + pid + ".png");
  3992. this._loadedImage[this.basePath + pid + ".png"] = true;
  3993. sp.addChild(spp);
  3994. spp.size(_data.getFloat32(), _data.getFloat32());
  3995. var mat = _data._getMatrix();
  3996. spp.transform = mat;
  3997. }
  3998. sp.alpha = 1;
  3999. }
  4000. else if (ttype == 1) {
  4001. mc = _idOfSprite[key];
  4002. if (!mc) {
  4003. _idOfSprite[key] = mc = new MovieClip(this);
  4004. mc.interval = this.interval;
  4005. mc._ids = this._ids;
  4006. mc.basePath = this.basePath;
  4007. mc._setData(_data, tPos);
  4008. mc._initState();
  4009. mc.play(0);
  4010. }
  4011. mc.alpha = 1;
  4012. }
  4013. _data.pos = this._Pos;
  4014. break;
  4015. case 3:
  4016. var node = _idOfSprite[_data.getUint16()];
  4017. if (node) {
  4018. this.addChild(node);
  4019. node.zOrder = _data.getUint16();
  4020. ifAdd = true;
  4021. }
  4022. break;
  4023. case 4:
  4024. node = _idOfSprite[_data.getUint16()];
  4025. node && node.removeSelf();
  4026. break;
  4027. case 5:
  4028. _idOfSprite[_data.getUint16()][MovieClip._ValueList[_data.getUint16()]] = (_data.getFloat32());
  4029. break;
  4030. case 6:
  4031. _idOfSprite[_data.getUint16()].visible = (_data.getUint8() > 0);
  4032. break;
  4033. case 7:
  4034. sp = _idOfSprite[_data.getUint16()];
  4035. var mt = sp.transform || Laya.Matrix.create();
  4036. mt.setTo(_data.getFloat32(), _data.getFloat32(), _data.getFloat32(), _data.getFloat32(), _data.getFloat32(), _data.getFloat32());
  4037. sp.transform = mt;
  4038. break;
  4039. case 8:
  4040. _idOfSprite[_data.getUint16()].setPos(_data.getFloat32(), _data.getFloat32());
  4041. break;
  4042. case 9:
  4043. _idOfSprite[_data.getUint16()].setSize(_data.getFloat32(), _data.getFloat32());
  4044. break;
  4045. case 10:
  4046. _idOfSprite[_data.getUint16()].alpha = _data.getFloat32();
  4047. break;
  4048. case 11:
  4049. _idOfSprite[_data.getUint16()].setScale(_data.getFloat32(), _data.getFloat32());
  4050. break;
  4051. case 98:
  4052. eStr = _data.getString();
  4053. this.event(eStr);
  4054. if (eStr == "stop")
  4055. this.stop();
  4056. break;
  4057. case 99:
  4058. this._curIndex = _data.getUint16();
  4059. ifAdd && this.updateZOrder();
  4060. break;
  4061. case 100:
  4062. this._count = this._curIndex + 1;
  4063. this._ended = true;
  4064. if (this._playing) {
  4065. this.event(Laya.Event.FRAME);
  4066. this.event(Laya.Event.END);
  4067. this.event(Laya.Event.COMPLETE);
  4068. }
  4069. this._reset(false);
  4070. break;
  4071. }
  4072. }
  4073. if (this._playing && !this._ended)
  4074. this.event(Laya.Event.FRAME);
  4075. this._Pos = _data.pos;
  4076. }
  4077. _setData(data, start) {
  4078. this._data = data;
  4079. this._start = start + 3;
  4080. }
  4081. set url(path) {
  4082. this.load(path);
  4083. }
  4084. load(url, atlas = false, atlasPath = null) {
  4085. this._url = url;
  4086. if (atlas)
  4087. this._atlasPath = atlasPath ? atlasPath : url.split(".swf")[0] + ".json";
  4088. this.stop();
  4089. this._clear();
  4090. this._movieClipList = [this];
  4091. var urls;
  4092. urls = [{ url: url, type: Laya.ILaya.Loader.BUFFER }];
  4093. if (this._atlasPath) {
  4094. urls.push({ url: this._atlasPath, type: Laya.ILaya.Loader.ATLAS });
  4095. }
  4096. Laya.ILaya.loader.load(urls, Laya.Handler.create(this, this._onLoaded));
  4097. }
  4098. _onLoaded() {
  4099. var data;
  4100. data = Laya.ILaya.Loader.getRes(this._url);
  4101. if (!data) {
  4102. this.event(Laya.Event.ERROR, "file not find");
  4103. return;
  4104. }
  4105. if (this._atlasPath && !Laya.ILaya.Loader.getAtlas(this._atlasPath)) {
  4106. this.event(Laya.Event.ERROR, "Atlas not find");
  4107. return;
  4108. }
  4109. this.basePath = this._atlasPath ? Laya.ILaya.Loader.getAtlas(this._atlasPath).dir : this._url.split(".swf")[0] + "/image/";
  4110. this._initData(data);
  4111. }
  4112. _initState() {
  4113. this._reset();
  4114. this._ended = false;
  4115. var preState = this._playing;
  4116. this._playing = false;
  4117. this._curIndex = 0;
  4118. while (!this._ended)
  4119. this._parseFrame(++this._curIndex);
  4120. this._playing = preState;
  4121. }
  4122. _initData(data) {
  4123. this._data = new Laya.Byte(data);
  4124. var i, len = this._data.getUint16();
  4125. for (i = 0; i < len; i++)
  4126. this._ids[this._data.getInt16()] = this._data.getInt32();
  4127. this.interval = 1000 / this._data.getUint16();
  4128. this._setData(this._data, this._ids[32767]);
  4129. this._initState();
  4130. this.play(0);
  4131. this.event(Laya.Event.LOADED);
  4132. if (!this._parentMovieClip)
  4133. this.timer.loop(this.interval, this, this.updates, null, true);
  4134. }
  4135. playTo(start, end, complete = null) {
  4136. this._completeHandler = complete;
  4137. this._endFrame = end;
  4138. this.play(start, false);
  4139. }
  4140. }
  4141. MovieClip._ValueList = ["x", "y", "width", "height", "scaleX", "scaleY", "rotation", "alpha"];
  4142. exports.AnimationContent = AnimationContent;
  4143. exports.AnimationNodeContent = AnimationNodeContent;
  4144. exports.AnimationParser01 = AnimationParser01;
  4145. exports.AnimationParser02 = AnimationParser02;
  4146. exports.AnimationPlayer = AnimationPlayer;
  4147. exports.AnimationState = AnimationState;
  4148. exports.AnimationTemplet = AnimationTemplet;
  4149. exports.BezierLerp = BezierLerp;
  4150. exports.Bone = Bone;
  4151. exports.BoneSlot = BoneSlot;
  4152. exports.DeformAniData = DeformAniData;
  4153. exports.DeformSlotData = DeformSlotData;
  4154. exports.DeformSlotDisplayData = DeformSlotDisplayData;
  4155. exports.DrawOrderData = DrawOrderData;
  4156. exports.EventData = EventData;
  4157. exports.GraphicsAni = GraphicsAni;
  4158. exports.IAniLib = IAniLib;
  4159. exports.IkConstraint = IkConstraint;
  4160. exports.IkConstraintData = IkConstraintData;
  4161. exports.KeyFramesContent = KeyFramesContent;
  4162. exports.MeshData = MeshData;
  4163. exports.MovieClip = MovieClip;
  4164. exports.PathConstraint = PathConstraint;
  4165. exports.PathConstraintData = PathConstraintData;
  4166. exports.Skeleton = Skeleton;
  4167. exports.SkinData = SkinData;
  4168. exports.SkinMeshForGraphic = SkinMeshForGraphic;
  4169. exports.SkinSlotDisplayData = SkinSlotDisplayData;
  4170. exports.SlotData = SlotData;
  4171. exports.Templet = Templet;
  4172. exports.TfConstraint = TfConstraint;
  4173. exports.TfConstraintData = TfConstraintData;
  4174. exports.Transform = Transform;
  4175. exports.UVTools = UVTools;
  4176. }(window.Laya = window.Laya|| {}, Laya));