From 1e9b8037abd6bf373ac1ba1c201fe577ebca775e Mon Sep 17 00:00:00 2001 From: Perfare Date: Mon, 22 Oct 2018 13:23:49 +0800 Subject: [PATCH] Fixed bug --- AssetStudio/Classes/AnimationClip.cs | 50 +++++++++++++++-- AssetStudio/StudioClasses/AssetPreloadData.cs | 2 +- AssetStudio/StudioClasses/ModelConverter.cs | 56 +++++++++---------- AssetStudioUtility/Imported.cs | 25 +-------- 4 files changed, 76 insertions(+), 57 deletions(-) diff --git a/AssetStudio/Classes/AnimationClip.cs b/AssetStudio/Classes/AnimationClip.cs index c48af38..f6eb5c1 100644 --- a/AssetStudio/Classes/AnimationClip.cs +++ b/AssetStudio/Classes/AnimationClip.cs @@ -477,13 +477,35 @@ namespace AssetStudio public class StreamedCurveKey { public int index { get; set; } - public Vector3 tcb { get; set; } - public float value { get; set; } + public float[] coeff { get; set; } + + public float value; + public float outSlope; + public float inSlope; + public StreamedCurveKey(BinaryReader reader) { index = reader.ReadInt32(); - tcb = reader.ReadVector3(); - value = reader.ReadSingle(); + coeff = reader.ReadSingleArray(4); + + outSlope = coeff[2]; + value = coeff[3]; + } + + public float CalculateNextInSlope(float dx, StreamedCurveKey rhs) + { + //Stepped + if (coeff[0] == 0f && coeff[1] == 0f && coeff[2] == 0f) + { + return float.PositiveInfinity; + } + + dx = Math.Max(dx, 0.0001f); + var dy = rhs.value - value; + var length = 1.0f / (dx * dx); + var d1 = outSlope * dx; + var d2 = dy + dy + dy - d1 - d1 - coeff[1] / length; + return d2 / dx; } } @@ -507,7 +529,7 @@ namespace AssetStudio public List ReadData() { - List frameList = new List(); + var frameList = new List(); using (Stream stream = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(stream); @@ -518,6 +540,24 @@ namespace AssetStudio frameList.Add(new StreamedFrame(new BinaryReader(stream))); } } + + for (int frameIndex = 2; frameIndex < frameList.Count - 1; frameIndex++) + { + var frame = frameList[frameIndex]; + foreach (var curveKey in frame.keyList) + { + for (int i = frameIndex - 1; i >= 0; i--) + { + var preFrame = frameList[i]; + var preCurveKey = preFrame.keyList.Find(x => x.index == curveKey.index); + if (preCurveKey != null) + { + curveKey.inSlope = preCurveKey.CalculateNextInSlope(frame.time - preFrame.time, preCurveKey); + break; + } + } + } + } return frameList; } } diff --git a/AssetStudio/StudioClasses/AssetPreloadData.cs b/AssetStudio/StudioClasses/AssetPreloadData.cs index 012db33..e59e794 100644 --- a/AssetStudio/StudioClasses/AssetPreloadData.cs +++ b/AssetStudio/StudioClasses/AssetPreloadData.cs @@ -61,7 +61,7 @@ namespace AssetStudio public bool HasStructMember(string name) { - return serializedType.m_Nodes != null && serializedType.m_Nodes.Any(x => x.m_Name == name); + return serializedType?.m_Nodes != null && serializedType.m_Nodes.Any(x => x.m_Name == name); } } } diff --git a/AssetStudio/StudioClasses/ModelConverter.cs b/AssetStudio/StudioClasses/ModelConverter.cs index 41e6dff..1ed1ccc 100644 --- a/AssetStudio/StudioClasses/ModelConverter.cs +++ b/AssetStudio/StudioClasses/ModelConverter.cs @@ -91,10 +91,11 @@ namespace AssetStudio else { var frameList = new List(); - while (rootTransform.m_Father.TryGetTransform(out var m_Father)) + var tempTransform = rootTransform; + while (tempTransform.m_Father.TryGetTransform(out var m_Father)) { frameList.Add(ConvertFrame(m_Father)); - rootTransform = m_Father; + tempTransform = m_Father; } if (frameList.Count > 0) { @@ -537,28 +538,24 @@ namespace AssetStudio if (combine) { meshR.m_GameObject.TryGetGameObject(out var m_GameObject); - foreach (var root in FrameList) + var frame = ImportedHelpers.FindFrame(m_GameObject.m_Name, FrameList[0]); + if (frame?.Parent != null) { - var frame = ImportedHelpers.FindFrame(m_GameObject.m_Name, root); - if (frame?.Parent != null) + var parent = frame; + while (true) { - var parent = frame; - while (true) + if (parent.Parent != null) { - if (parent.Parent != null) - { - parent = parent.Parent; - } - else - { - frame.LocalRotation = parent.LocalRotation; - frame.LocalScale = parent.LocalScale; - frame.LocalPosition = parent.LocalPosition; - break; - } + parent = parent.Parent; + } + else + { + frame.LocalRotation = parent.LocalRotation; + frame.LocalScale = parent.LocalScale; + frame.LocalPosition = parent.LocalPosition; + break; } } - break; } } @@ -826,7 +823,7 @@ namespace AssetStudio var streamCount = m_Clip.m_StreamedClip.curveCount; for (int frameIndex = 0; frameIndex < m_DenseClip.m_FrameCount; frameIndex++) { - var time = frameIndex / m_DenseClip.m_SampleRate; + var time = m_DenseClip.m_BeginTime + frameIndex / m_DenseClip.m_SampleRate; var frameOffset = frameIndex * m_DenseClip.m_CurveCount; for (int curveIndex = 0; curveIndex < m_DenseClip.m_CurveCount;) { @@ -834,17 +831,20 @@ namespace AssetStudio ReadCurveData(iAnim, m_ClipBindingConstant, (int)index, time, m_DenseClip.m_SampleArray, (int)frameOffset, ref curveIndex); } } - var m_ConstantClip = m_Clip.m_ConstantClip; - var denseCount = m_Clip.m_DenseClip.m_CurveCount; - var time2 = 0.0f; - for (int i = 0; i < 2; i++) + if (m_Clip.m_ConstantClip != null) { - for (int curveIndex = 0; curveIndex < m_ConstantClip.data.Length;) + var m_ConstantClip = m_Clip.m_ConstantClip; + var denseCount = m_Clip.m_DenseClip.m_CurveCount; + var time2 = 0.0f; + for (int i = 0; i < 2; i++) { - var index = streamCount + denseCount + curveIndex; - ReadCurveData(iAnim, m_ClipBindingConstant, (int)index, time2, m_ConstantClip.data, 0, ref curveIndex); + for (int curveIndex = 0; curveIndex < m_ConstantClip.data.Length;) + { + var index = streamCount + denseCount + curveIndex; + ReadCurveData(iAnim, m_ClipBindingConstant, (int)index, time2, m_ConstantClip.data, 0, ref curveIndex); + } + time2 = animationClip.m_MuscleClip.m_StopTime; } - time2 = animationClip.m_MuscleClip.m_StopTime; } } } diff --git a/AssetStudioUtility/Imported.cs b/AssetStudioUtility/Imported.cs index a27bd34..495f592 100644 --- a/AssetStudioUtility/Imported.cs +++ b/AssetStudioUtility/Imported.cs @@ -41,29 +41,6 @@ namespace AssetStudio obj.Parent = this; } - public void InsertChild(int i, ImportedFrame obj) - { - children.Insert(i, obj); - obj.Parent = this; - } - - public void RemoveChild(ImportedFrame obj) - { - obj.Parent = null; - children.Remove(obj); - } - - public void RemoveChild(int i) - { - children[i].Parent = null; - children.RemoveAt(i); - } - - public int IndexOf(ImportedFrame obj) - { - return children.IndexOf(obj); - } - public void ClearChild() { children.Clear(); @@ -177,6 +154,8 @@ namespace AssetStudio { public float time { get; set; } public T value { get; set; } + public T inSlope { get; set; } + public T outSlope { get; set; } public ImportedKeyframe(float time, T value) {