diff --git a/AssetStudio/IImported.cs b/AssetStudio/IImported.cs index 620618f..f0d765e 100644 --- a/AssetStudio/IImported.cs +++ b/AssetStudio/IImported.cs @@ -8,7 +8,7 @@ namespace AssetStudio { public interface IImported { - List FrameList { get; } + ImportedFrame RootFrame { get; } List MeshList { get; } List MaterialList { get; } List TextureList { get; } diff --git a/AssetStudioFBX/AssetStudioFBXExporter.cpp b/AssetStudioFBX/AssetStudioFBXExporter.cpp index c272748..cbef509 100644 --- a/AssetStudioFBX/AssetStudioFBXExporter.cpp +++ b/AssetStudioFBX/AssetStudioFBXExporter.cpp @@ -111,7 +111,7 @@ namespace AssetStudio } pMeshNodes = imported->MeshList != nullptr ? new FbxArray(imported->MeshList->Count) : NULL; - ExportFrame(pScene->GetRootNode(), imported->FrameList[0]); + ExportFrame(pScene->GetRootNode(), imported->RootFrame); if (imported->MeshList != nullptr) { @@ -207,7 +207,7 @@ namespace AssetStudio return nullptr; } HashSet^ exportFrames = gcnew HashSet(); - SearchHierarchy(imported->FrameList[0], exportFrames); + SearchHierarchy(imported->RootFrame, exportFrames); return exportFrames; } @@ -230,7 +230,7 @@ namespace AssetStudio { if (!exportFrames->Contains(boneList[i]->Name)) { - ImportedFrame^ boneParent = ImportedHelpers::FindChildOrRoot(boneList[i]->Name, imported->FrameList[0]); + ImportedFrame^ boneParent = ImportedHelpers::FindChildOrRoot(boneList[i]->Name, imported->RootFrame); while (boneParent != nullptr) { exportFrames->Add(boneParent->Name); @@ -751,7 +751,7 @@ namespace AssetStudio ImportedAnimationKeyframedTrack^ keyframeList = pAnimationList[j]; String^ name = keyframeList->Name; int dotPos = name->IndexOf('.'); - if (dotPos >= 0 && !ImportedHelpers::FindChildOrRoot(name, imported->FrameList[0])) + if (dotPos >= 0 && !ImportedHelpers::FindChildOrRoot(name, imported->RootFrame)) { name = name->Substring(0, dotPos); } diff --git a/AssetStudioUtility/ModelConverter.cs b/AssetStudioUtility/ModelConverter.cs index 819729f..094412e 100644 --- a/AssetStudioUtility/ModelConverter.cs +++ b/AssetStudioUtility/ModelConverter.cs @@ -10,7 +10,7 @@ namespace AssetStudio { public class ModelConverter : IImported { - public List FrameList { get; protected set; } = new List(); + public ImportedFrame RootFrame { get; protected set; } public List MeshList { get; protected set; } = new List(); public List MaterialList { get; protected set; } = new List(); public List TextureList { get; protected set; } = new List(); @@ -95,7 +95,7 @@ namespace AssetStudio } if (frameList.Count > 0) { - FrameList.Add(frameList[frameList.Count - 1]); + RootFrame = frameList[frameList.Count - 1]; for (var i = frameList.Count - 2; i >= 0; i--) { var frame = frameList[i]; @@ -218,7 +218,7 @@ namespace AssetStudio var frame = ConvertFrame(trans); if (parent == null) { - FrameList.Add(frame); + RootFrame = frame; } else { @@ -521,24 +521,14 @@ namespace AssetStudio if (combine) { meshR.m_GameObject.TryGet(out var m_GameObject); - var frame = ImportedHelpers.FindChildOrRoot(m_GameObject.m_Name, FrameList[0]); - if (frame?.Parent != null) + var frame = ImportedHelpers.FindChildOrRoot(m_GameObject.m_Name, RootFrame); + frame.LocalPosition = RootFrame.LocalPosition; + frame.LocalRotation = RootFrame.LocalRotation; + while (frame.Parent != null) { - var parent = frame; - while (true) - { - if (parent.Parent != null) - { - parent = parent.Parent; - } - else - { - frame.LocalRotation = parent.LocalRotation; - frame.LocalScale = parent.LocalScale; - frame.LocalPosition = parent.LocalPosition; - break; - } - } + frame = frame.Parent; + frame.LocalPosition = RootFrame.LocalPosition; + frame.LocalRotation = RootFrame.LocalRotation; } } @@ -572,7 +562,7 @@ namespace AssetStudio private string GetMeshPath(Transform meshTransform) { meshTransform.m_GameObject.TryGet(out var m_GameObject); - var curFrame = ImportedHelpers.FindChildOrRoot(m_GameObject.m_Name, FrameList[0]); + var curFrame = ImportedHelpers.FindChildOrRoot(m_GameObject.m_Name, RootFrame); var path = curFrame.Name; while (curFrame.Parent != null) { @@ -1019,7 +1009,6 @@ namespace AssetStudio } // 2. Restore the original transform hierarchy // Prerequisite: skeletonPaths follow pre-order traversal - var rootFrame = FrameList[0]; for (var i = 1; i < skeletonPaths.Count; i++) // start from 1, skip the root transform because it will always be there. { var path = skeletonPaths[i]; @@ -1029,19 +1018,19 @@ namespace AssetStudio if (strs.Length == 1) { transformName = path; - parentFrame = rootFrame; + parentFrame = RootFrame; } else { transformName = strs.Last(); var parentFrameName = strs[strs.Length - 2]; - parentFrame = ImportedHelpers.FindChildOrRoot(parentFrameName, rootFrame); + parentFrame = ImportedHelpers.FindChildOrRoot(parentFrameName, RootFrame); } var skeletonPose = avatar.m_Avatar.m_DefaultPose; var xform = skeletonPose.m_X[i]; - var frame = ImportedHelpers.FindChildOrRoot(transformName, rootFrame); + var frame = ImportedHelpers.FindChildOrRoot(transformName, RootFrame); if (frame != null) { SetFrame(frame, xform.t, xform.q, xform.s);