From e542be9ae89b399a0087dd43263e2ef16c234e76 Mon Sep 17 00:00:00 2001 From: nicloay Date: Thu, 22 May 2014 09:57:58 +0400 Subject: [PATCH 1/2] fix new size parameter in atlas metadata --- .../Model/Spine/Atlas/SpineMultialtas.cs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Assets/UnitySpineImporter/Scripts/Editor/Model/Spine/Atlas/SpineMultialtas.cs b/Assets/UnitySpineImporter/Scripts/Editor/Model/Spine/Atlas/SpineMultialtas.cs index 7321d68..ccce909 100644 --- a/Assets/UnitySpineImporter/Scripts/Editor/Model/Spine/Atlas/SpineMultialtas.cs +++ b/Assets/UnitySpineImporter/Scripts/Editor/Model/Spine/Atlas/SpineMultialtas.cs @@ -19,6 +19,7 @@ public static SpineMultiatlas deserializeFromFile(string multiatlasFilePath){ throw new SpineMultiatlasCreationException("provided file does not exists"); using(StreamReader streamReader = new StreamReader(multiatlasFilePath)){ string line; + string spriteNameAfterProps = ""; bool setMainProps = false; SpineAtlas spineAtlas = null; SpineSprite sprite = null; @@ -30,14 +31,30 @@ public static SpineMultiatlas deserializeFromFile(string multiatlasFilePath){ spineAtlas = new SpineAtlas(); multiAtlas.Add(spineAtlas); spineAtlas.imageName = line; - spineAtlas.format = streamReader.ReadLine(); - spineAtlas.filter = streamReader.ReadLine(); - spineAtlas.repeat = streamReader.ReadLine(); + Dictionary keyValue = new Dictionary(); + string[] kvp; + while( (kvp= streamReader.ReadLine().Split(':')).Length == 2) + keyValue.Add(kvp[0].Trim(), kvp[1].Trim()); + + spineAtlas.format = keyValue["format"]; + spineAtlas.filter = keyValue["filter"]; + spineAtlas.repeat = keyValue["repeat"]; + + spriteNameAfterProps = kvp[0]; spineAtlas.sprites = new List(); setMainProps = false; - } else { + + } + + if (!setMainProps){ sprite = new SpineSprite(); - sprite.name = line; + + if (string.IsNullOrEmpty( spriteNameAfterProps)){ + sprite.name = line; + } else { + sprite.name = spriteNameAfterProps; + spriteNameAfterProps = ""; + } try{ sprite.rotate = bool.Parse(streamReader.ReadLine().Split(':')[1]); sprite.xy = SpineUtil.lineToVector2(streamReader.ReadLine()); From 37e1a9ca2ca090d6e8736434a79aa89a1a9257f2 Mon Sep 17 00:00:00 2001 From: nicloay Date: Thu, 22 May 2014 11:14:55 +0400 Subject: [PATCH 2/2] rotate through quaternion. (previous Euler angles gave odd keyframes) --- .../Scripts/Editor/Util/SpineUtil.cs | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs b/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs index 32f57d1..83d51b5 100644 --- a/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs +++ b/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs @@ -740,9 +740,11 @@ public static void addBoneAnimationToClip(AnimationClip clip, Dictionary 0){ + AnimationCurve localRotationX = new AnimationCurve(); + AnimationCurve localRotationY = new AnimationCurve(); AnimationCurve localRotationZ = new AnimationCurve(); - AnimationCurve localRotationZero = new AnimationCurve(); - + AnimationCurve localRotationW = new AnimationCurve(); + JsonData[] curveData = new JsonData[boneAnimation.rotate.Count]; for (int i = 0; i < boneAnimation.rotate.Count; i++) { float origAngle = (float)boneAnimation.rotate[i].angle; @@ -750,26 +752,38 @@ public static void addBoneAnimationToClip(AnimationClip clip, Dictionary 180 ? origAngle - 360 : origAngle; else origAngle = origAngle < -180 ? origAngle + 360 : origAngle; - + float newZ = boneGO.transform.localRotation.eulerAngles.z + origAngle; - + Quaternion angle = Quaternion.Euler(0,0,newZ); float time = (float)boneAnimation.rotate[i].time; - + curveData[i] = boneAnimation.rotate[i].curve; - - localRotationZ.AddKey(new Keyframe(time, newZ)); - localRotationZero.AddKey(new Keyframe(time,0)); + + localRotationX.AddKey(new Keyframe(time, angle.x)); + localRotationY.AddKey(new Keyframe(time, angle.y)); + localRotationZ.AddKey(new Keyframe(time, angle.z)); + localRotationW.AddKey(new Keyframe(time, angle.w)); + } - + + fixAngles (localRotationX , curveData); + setTangents(localRotationX , curveData); + + fixAngles (localRotationY , curveData); + setTangents(localRotationY , curveData); + fixAngles (localRotationZ , curveData); setTangents(localRotationZ , curveData); - setTangents(localRotationZero, curveData); - - AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"localEulerAnglesBaked.x"), localRotationZero); - AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"localEulerAnglesBaked.y"), new AnimationCurve( localRotationZero.keys)); - AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"localEulerAnglesBaked.z"), localRotationZ); - //AnimationUtility.SetEditorCurve(clip,bonePath,typeof(Transform),"localEulerAngles.z",localRotationZ); + + fixAngles (localRotationW , curveData); + setTangents(localRotationW , curveData); + + AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"m_LocalRotation.x"), localRotationX); + AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"m_LocalRotation.y"), localRotationY); + AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"m_LocalRotation.z"), localRotationZ); + AnimationUtility.SetEditorCurve(clip,EditorCurveBinding.FloatCurve(bonePath,typeof(Transform),"m_LocalRotation.w"), localRotationW); + } if (boneAnimation.scale != null && boneAnimation.scale.Count > 0){