From 9e4be3e08208b814f526c4d65780747fdd65044e Mon Sep 17 00:00:00 2001 From: Perfare Date: Mon, 9 Apr 2018 02:43:58 +0800 Subject: [PATCH] Some improvements --- AssetStudio/StudioClasses/ModelConverter.cs | 56 +++++------ AssetStudioFBX/AssemblyInfo.cpp | 4 +- AssetStudioFBX/AssetStudioFBX.rc | Bin 2458 -> 0 bytes AssetStudioFBX/ImportedFBXExporter.cpp | 102 +++++++++----------- AssetStudioUtility/Imported.cs | 19 ++-- 5 files changed, 77 insertions(+), 104 deletions(-) delete mode 100644 AssetStudioFBX/AssetStudioFBX.rc diff --git a/AssetStudio/StudioClasses/ModelConverter.cs b/AssetStudio/StudioClasses/ModelConverter.cs index 1da635e..0972254 100644 --- a/AssetStudio/StudioClasses/ModelConverter.cs +++ b/AssetStudio/StudioClasses/ModelConverter.cs @@ -46,6 +46,7 @@ namespace AssetStudio private void InitWithAnimator(Animator m_Animator) { + //In fact, doesn't need this. if (assetsfileList.TryGetPD(m_Animator.m_Avatar, out var m_Avatar)) avatar = new Avatar(m_Avatar); @@ -306,31 +307,35 @@ namespace AssetStudio { //Bone iMesh.BoneList = new List(sMesh.m_Bones.Length); - /*if (meshR.m_Bones.Length >= 256) + /*if (sMesh.m_Bones.Length >= 256) { throw new Exception("Too many bones (" + mesh.m_BindPose.Length + ")"); }*/ for (int i = 0; i < sMesh.m_Bones.Length; i++) { var bone = new ImportedBone(); - var boneHash = mesh.m_BoneNameHashes[i]; - bone.Name = GetNameFromBonePathHashes(boneHash); - if (string.IsNullOrEmpty(bone.Name)) + if (assetsfileList.TryGetTransform(sMesh.m_Bones[i], out var m_Transform)) { - bone.Name = avatar?.FindBoneName(boneHash); - } - if (string.IsNullOrEmpty(bone.Name)) - { - if (assetsfileList.TryGetTransform(sMesh.m_Bones[i], out var m_Transform)) + if (assetsfileList.TryGetGameObject(m_Transform.m_GameObject, out var m_GameObject)) { - assetsfileList.TryGetGameObject(m_Transform.m_GameObject, out var m_GameObject); bone.Name = m_GameObject.m_Name; } - else + } + //No first use m_BoneNameHashes, because it may be wrong + if (string.IsNullOrEmpty(bone.Name)) + { + var boneHash = mesh.m_BoneNameHashes[i]; + bone.Name = GetNameFromBonePathHashes(boneHash); + if (string.IsNullOrEmpty(bone.Name)) { - throw new NotSupportedException(); + bone.Name = avatar?.FindBoneName(boneHash); + } + if (string.IsNullOrEmpty(bone.Name)) + { + throw new Exception("A Bone could neither be found by hash in Avatar nor by index in SkinnedMeshRenderer."); } } + var om = new Matrix(); for (int x = 0; x < 4; x++) { @@ -577,16 +582,11 @@ namespace AssetStudio } foreach (var m_Curve in m_RotationCurve.curve.m_Curve) { - if (!track.Keyframes.TryGetValue(m_Curve.time, out var keyFrames)) - { - keyFrames = new ImportedAnimationKeyframe(); - track.Keyframes.Add(m_Curve.time, keyFrames); - } - keyFrames.Rotation = new ImportedKeyframe( + track.Rotations.Add(new ImportedKeyframe( m_Curve.time, new Quaternion(m_Curve.value.X, -m_Curve.value.Y, -m_Curve.value.Z, m_Curve.value.W), new Quaternion(m_Curve.inSlope.X, -m_Curve.inSlope.Y, -m_Curve.inSlope.Z, m_Curve.inSlope.W), - new Quaternion(m_Curve.outSlope.X, -m_Curve.outSlope.Y, -m_Curve.outSlope.Z, m_Curve.outSlope.W)); + new Quaternion(m_Curve.outSlope.X, -m_Curve.outSlope.Y, -m_Curve.outSlope.Z, m_Curve.outSlope.W))); } } foreach (var m_PositionCurve in clip.m_PositionCurves) @@ -602,16 +602,11 @@ namespace AssetStudio } foreach (var m_Curve in m_PositionCurve.curve.m_Curve) { - if (!track.Keyframes.TryGetValue(m_Curve.time, out var keyFrames)) - { - keyFrames = new ImportedAnimationKeyframe(); - track.Keyframes.Add(m_Curve.time, keyFrames); - } - keyFrames.Translation = new ImportedKeyframe( + track.Translations.Add(new ImportedKeyframe( m_Curve.time, new Vector3(-m_Curve.value.X, m_Curve.value.Y, m_Curve.value.Z), new Vector3(-m_Curve.inSlope.X, m_Curve.inSlope.Y, m_Curve.inSlope.Z), - new Vector3(-m_Curve.outSlope.X, m_Curve.outSlope.Y, m_Curve.outSlope.Z)); + new Vector3(-m_Curve.outSlope.X, m_Curve.outSlope.Y, m_Curve.outSlope.Z))); } } foreach (var m_ScaleCurve in clip.m_ScaleCurves) @@ -627,16 +622,11 @@ namespace AssetStudio } foreach (var m_Curve in m_ScaleCurve.curve.m_Curve) { - if (!track.Keyframes.TryGetValue(m_Curve.time, out var keyFrames)) - { - keyFrames = new ImportedAnimationKeyframe(); - track.Keyframes.Add(m_Curve.time, keyFrames); - } - keyFrames.Scaling = new ImportedKeyframe( + track.Scalings.Add(new ImportedKeyframe( m_Curve.time, new Vector3(m_Curve.value.X, m_Curve.value.Y, m_Curve.value.Z), new Vector3(m_Curve.inSlope.X, m_Curve.inSlope.Y, m_Curve.inSlope.Z), - new Vector3(m_Curve.outSlope.X, m_Curve.outSlope.Y, m_Curve.outSlope.Z)); + new Vector3(m_Curve.outSlope.X, m_Curve.outSlope.Y, m_Curve.outSlope.Z))); } } } diff --git a/AssetStudioFBX/AssemblyInfo.cpp b/AssetStudioFBX/AssemblyInfo.cpp index 75590de..cd57534 100644 --- a/AssetStudioFBX/AssemblyInfo.cpp +++ b/AssetStudioFBX/AssemblyInfo.cpp @@ -1,4 +1,4 @@ -using namespace System; +using namespace System; using namespace System::Reflection; using namespace System::Runtime::CompilerServices; using namespace System::Runtime::InteropServices; @@ -9,7 +9,7 @@ using namespace System::Security::Permissions; [assembly:AssemblyConfigurationAttribute(L"")]; [assembly:AssemblyCompanyAttribute(L"")]; [assembly:AssemblyProductAttribute(L"AssetStudioFBX")]; -[assembly:AssemblyCopyrightAttribute(L"°æÈ¨ËùÓÐ(c) 2018")]; +[assembly:AssemblyCopyrightAttribute(L"Copyright © 2018")]; [assembly:AssemblyTrademarkAttribute(L"")]; [assembly:AssemblyCultureAttribute(L"")]; diff --git a/AssetStudioFBX/AssetStudioFBX.rc b/AssetStudioFBX/AssetStudioFBX.rc deleted file mode 100644 index 1d2130dd4e2c2450b33c90905714eead7ae8e148..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2458 zcmdT_T}uK{5Iyu52|f4HrY}a?n)L_rBazlMT$KVr%GMIZAlrJVhk~G|pkLNMDm$~+ zi-x;aK5blf?{%D+J9FmD?C8^k2?G`M(7`pXFyzz44P{NrhVXETK7Zx0#bsdKTRnTe zExf)B)}B%qOPLs!>A{5T30e&3r%$VMxYUl*r|bLlcJTUm%+*S8b>eH_6- z9SsyvMip(;P^7fLvkeO;lsJ4>kfX%nS>G=)L~rTn^lsqYHke-#$9$KWQ=VB!wnb*2 z zxWb~Lu;`Kf1~$fcNdLGzC&~E(azydpA=ex1ggjZ&CRZ#j@$|rDgj&|=qlOYKisV^? z7ILFSsZD8vd&y_r9#Zs@_5Yp36kZ=;ZIcll(z@{P`Y*WmByZu6?DFgok#Nl%GcWnw zE4s#b1<$$`GUItCRZw_|mGpY>4dPEU!fpwgvT@8#gE(58xh*nE&D%+wVKMD49MfNK zN|5C;0~GsJWP*RtJecL1pcC$4Ue85qPE1E5IZZ!OCount; i++) { - bool keyframed = dynamic_cast(importedAnimationList[i]) != nullptr; + auto importedAnimation = importedAnimationList[i]; + FbxString kTakeName; + if (importedAnimation->Name) + { + WITH_MARSHALLED_STRING + ( + pClipName, + importedAnimation->Name, + kTakeName = FbxString(pClipName); + ); + } + else + { + kTakeName = FbxString("Take") + FbxString(i); + } + bool keyframed = dynamic_cast(importedAnimation) != nullptr; if (keyframed) { - ImportedKeyframedAnimation^ parser = (ImportedKeyframedAnimation^)importedAnimationList[i]; - FbxString kTakeName; - if (parser->Name) - { - WITH_MARSHALLED_STRING - ( - pClipName, - parser->Name, - kTakeName = FbxString(pClipName); - ); - } - else - { - kTakeName = FbxString("Take") + FbxString(i); - } + ImportedKeyframedAnimation^ parser = (ImportedKeyframedAnimation^)importedAnimation; ExportKeyframedAnimation(parser, kTakeName, lFilter, filterPrecision, scale, rotate, translate, pNotFound); } else { - ImportedSampledAnimation^ parser = (ImportedSampledAnimation^)importedAnimationList[i]; - FbxString kTakeName; - if (parser->Name) - { - WITH_MARSHALLED_STRING - ( - pClipName, - parser->Name, - kTakeName = FbxString(pClipName); - ); - } - else - { - kTakeName = FbxString("Take") + FbxString(i); - } + ImportedSampledAnimation^ parser = (ImportedSampledAnimation^)importedAnimation; ExportSampledAnimation(parser, kTakeName, lFilter, filterPrecision, flatInbetween, scale, rotate, translate, pNotFound); } } - if (pNotFound->Count > 0) + /*if (pNotFound->Count > 0) { String^ pNotFoundString = gcnew String("Warning: Animations weren't exported for the following missing frames or morphs: "); for (int i = 0; i < pNotFound->Count; i++) { pNotFoundString += pNotFound[i] + ", "; } - //Report::ReportLog(pNotFoundString->Substring(0, pNotFoundString->Length - 2)); - } + Report::ReportLog(pNotFoundString->Substring(0, pNotFoundString->Length - 2)); + }*/ } void Fbx::Exporter::ExportKeyframedAnimation(ImportedKeyframedAnimation^ parser, FbxString& kTakeName, FbxAnimCurveFilterUnroll* EulerFilter, float filterPrecision, @@ -797,31 +784,32 @@ namespace AssetStudio lCurveTY->KeyModifyBegin(); lCurveTZ->KeyModifyBegin(); - for each (auto keyframes in keyframeList->Keyframes) + for each (auto Scaling in keyframeList->Scalings) { - lTime.SetSecondDouble(keyframes.Key); + lTime.SetSecondDouble(Scaling->time); - if (keyframes.Value->Scaling != nullptr) - { - lCurveSX->KeySet(lCurveSX->KeyAdd(lTime), lTime, keyframes.Value->Scaling->value.X); - lCurveSY->KeySet(lCurveSY->KeyAdd(lTime), lTime, keyframes.Value->Scaling->value.Y); - lCurveSZ->KeySet(lCurveSZ->KeyAdd(lTime), lTime, keyframes.Value->Scaling->value.Z); - } - if (keyframes.Value->Rotation != nullptr) - { - Vector3 rotation = Fbx::QuaternionToEuler(keyframes.Value->Rotation->value); - Vector3 inSlope = Fbx::QuaternionToEuler(keyframes.Value->Rotation->inSlope); - Vector3 outSlope = Fbx::QuaternionToEuler(keyframes.Value->Rotation->outSlope); - lCurveRX->KeySet(lCurveRX->KeyAdd(lTime), lTime, rotation.X); - lCurveRY->KeySet(lCurveRY->KeyAdd(lTime), lTime, rotation.Y); - lCurveRZ->KeySet(lCurveRZ->KeyAdd(lTime), lTime, rotation.Z); - } - if (keyframes.Value->Translation != nullptr) - { - lCurveTX->KeySet(lCurveTX->KeyAdd(lTime), lTime, keyframes.Value->Translation->value.X); - lCurveTY->KeySet(lCurveTY->KeyAdd(lTime), lTime, keyframes.Value->Translation->value.Y); - lCurveTZ->KeySet(lCurveTZ->KeyAdd(lTime), lTime, keyframes.Value->Translation->value.Z); - } + lCurveSX->KeySet(lCurveSX->KeyAdd(lTime), lTime, Scaling->value.X); + lCurveSY->KeySet(lCurveSY->KeyAdd(lTime), lTime, Scaling->value.Y); + lCurveSZ->KeySet(lCurveSZ->KeyAdd(lTime), lTime, Scaling->value.Z); + } + for each (auto Rotation in keyframeList->Rotations) + { + lTime.SetSecondDouble(Rotation->time); + + Vector3 rotation = Fbx::QuaternionToEuler(Rotation->value); + Vector3 inSlope = Fbx::QuaternionToEuler(Rotation->inSlope); + Vector3 outSlope = Fbx::QuaternionToEuler(Rotation->outSlope); + lCurveRX->KeySet(lCurveRX->KeyAdd(lTime), lTime, rotation.X); + lCurveRY->KeySet(lCurveRY->KeyAdd(lTime), lTime, rotation.Y); + lCurveRZ->KeySet(lCurveRZ->KeyAdd(lTime), lTime, rotation.Z); + } + for each (auto Translation in keyframeList->Translations) + { + lTime.SetSecondDouble(Translation->time); + + lCurveTX->KeySet(lCurveTX->KeyAdd(lTime), lTime, Translation->value.X); + lCurveTY->KeySet(lCurveTY->KeyAdd(lTime), lTime, Translation->value.Y); + lCurveTZ->KeySet(lCurveTZ->KeyAdd(lTime), lTime, Translation->value.Z); } lCurveSX->KeyModifyEnd(); diff --git a/AssetStudioUtility/Imported.cs b/AssetStudioUtility/Imported.cs index 7b479ca..b7669c9 100644 --- a/AssetStudioUtility/Imported.cs +++ b/AssetStudioUtility/Imported.cs @@ -91,8 +91,9 @@ namespace AssetStudio } } - public interface ImportedAnimation + public abstract class ImportedAnimation { + public string Name { get; set; } } public abstract class ImportedAnimationTrackContainer : ImportedAnimation where TrackType : ImportedAnimationTrack @@ -107,12 +108,11 @@ namespace AssetStudio public class ImportedKeyframedAnimation : ImportedAnimationTrackContainer { - public string Name { get; set; } + } public class ImportedSampledAnimation : ImportedAnimationTrackContainer { - public string Name { get; set; } public float SampleRate { get; set; } } @@ -121,11 +121,6 @@ namespace AssetStudio public string Name { get; set; } } - public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack - { - public Dictionary Keyframes { get; set; } = new Dictionary(); - } - public class ImportedKeyframe { public float time { get; set; } @@ -142,11 +137,11 @@ namespace AssetStudio } } - public class ImportedAnimationKeyframe + public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack { - public ImportedKeyframe Scaling { get; set; } - public ImportedKeyframe Rotation { get; set; } - public ImportedKeyframe Translation { get; set; } + public List> Scalings = new List>(); + public List> Rotations = new List>(); + public List> Translations = new List>(); } public class ImportedAnimationSampledTrack : ImportedAnimationTrack