This commit is contained in:
Perfare 2018-10-16 00:42:56 +08:00
parent ec8b41155a
commit f15ee038b4
2 changed files with 81 additions and 30 deletions

View File

@ -9,11 +9,55 @@ namespace AssetStudio
{
public PPtr m_Avatar;
public PPtr m_Controller;
public bool m_HasTransformHierarchy;
public Animator(AssetPreloadData preloadData) : base(preloadData)
{
m_Avatar = sourceFile.ReadPPtr();
m_Controller = sourceFile.ReadPPtr();
var m_CullingMode = reader.ReadInt32();
if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
{
var m_UpdateMode = reader.ReadInt32();
}
var m_ApplyRootMotion = reader.ReadBoolean();
if (version[0] == 4 && version[1] >= 5) //4.5 and up - 5.0 down
{
reader.AlignStream(4);
}
if (version[0] >= 5) //5.0 and up
{
var m_LinearVelocityBlending = reader.ReadBoolean();
reader.AlignStream(4);
}
if (version[0] < 4 || (version[0] == 4 && version[1] < 5)) //4.5 down
{
var m_AnimatePhysics = reader.ReadBoolean();
}
if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
{
m_HasTransformHierarchy = reader.ReadBoolean();
}
if (version[0] > 4 || (version[0] == 4 && version[1] >= 5)) //4.5 and up
{
var m_AllowConstantClipSamplingOptimization = reader.ReadBoolean();
}
if (version[0] >= 5 && version[0] < 2018) //5.0 and up - 2018 down
{
reader.AlignStream(4);
}
if (version[0] >= 2018) //2018 and up
{
var m_KeepAnimatorControllerStateOnDisable = reader.ReadBoolean();
reader.AlignStream(4);
}
}
}
}

View File

@ -22,7 +22,6 @@ namespace AssetStudio
private Dictionary<uint, string> morphChannelInfo = new Dictionary<uint, string>();
private HashSet<AssetPreloadData> animationClipHashSet = new HashSet<AssetPreloadData>();
private Dictionary<uint, string> bonePathHash = new Dictionary<uint, string>();
private bool deoptimize;
public ModelConverter(GameObject m_GameObject)
{
@ -76,36 +75,46 @@ namespace AssetStudio
avatar = new Avatar(m_Avatar);
assetsfileList.TryGetGameObject(m_Animator.m_GameObject, out var m_GameObject);
InitWithGameObject(m_GameObject);
InitWithGameObject(m_GameObject, m_Animator.m_HasTransformHierarchy);
}
private void InitWithGameObject(GameObject m_GameObject)
private void InitWithGameObject(GameObject m_GameObject, bool hasTransformHierarchy = true)
{
assetsfileList.TryGetTransform(m_GameObject.m_Transform, out var m_Transform);
var rootTransform = m_Transform;
var frameList = new List<ImportedFrame>();
while (assetsfileList.TryGetTransform(rootTransform.m_Father, out var m_Father))
if (!hasTransformHierarchy)
{
frameList.Add(ConvertFrame(m_Father));
rootTransform = m_Father;
}
if (frameList.Count > 0)
{
FrameList.Add(frameList[frameList.Count - 1]);
for (var i = frameList.Count - 2; i >= 0; i--)
{
var frame = frameList[i];
var parent = frameList[i + 1];
parent.AddChild(frame);
}
ConvertFrames(m_Transform, frameList[0]);
var rootFrame = ConvertFrame(rootTransform);
FrameList.Add(rootFrame);
DeoptimizeTransformHierarchy();
}
else
{
ConvertFrames(m_Transform, null);
var frameList = new List<ImportedFrame>();
while (assetsfileList.TryGetTransform(rootTransform.m_Father, out var m_Father))
{
frameList.Add(ConvertFrame(m_Father));
rootTransform = m_Father;
}
if (frameList.Count > 0)
{
FrameList.Add(frameList[frameList.Count - 1]);
for (var i = frameList.Count - 2; i >= 0; i--)
{
var frame = frameList[i];
var parent = frameList[i + 1];
parent.AddChild(frame);
}
ConvertFrames(m_Transform, frameList[0]);
}
else
{
ConvertFrames(m_Transform, null);
}
CreateBonePathHash(rootTransform);
}
CreateBonePathHash(rootTransform);
ConvertMeshRenderer(m_Transform);
}
@ -423,14 +432,9 @@ namespace AssetStudio
iMesh.BoneList.Add(bone);
}
//hierarchy has been optimized
if (sMesh.m_Bones.Length == 0 && mesh.m_BindPose?.Length > 0 && mesh.m_BoneNameHashes?.Length > 0)
{
//TODO move to Init method use Animator.m_HasTransformHierarchy to judge
if (!deoptimize)
{
DeoptimizeTransformHierarchy();
deoptimize = true;
}
//TODO Repeat code with above
for (int i = 0; i < mesh.m_BindPose.Length; i++)
{
@ -596,12 +600,15 @@ namespace AssetStudio
private string GetTransformPath(Transform meshTransform)
{
assetsfileList.TryGetGameObject(meshTransform.m_GameObject, out var m_GameObject);
if (assetsfileList.TryGetTransform(meshTransform.m_Father, out var Father))
var curFrame = ImportedHelpers.FindFrame(m_GameObject.m_Name, FrameList[0]);
var path = curFrame.Name;
while (curFrame.Parent != null)
{
return GetTransformPath(Father) + "/" + m_GameObject.m_Name;
curFrame = curFrame.Parent;
path = curFrame.Name + "/" + path;
}
return m_GameObject.m_Name;
return path;
}
private ImportedMaterial ConvertMaterial(Material mat)
@ -987,7 +994,7 @@ namespace AssetStudio
private void DeoptimizeTransformHierarchy()
{
if (avatar == null)
return;
throw new Exception("Transform hierarchy has been optimized, but can't find Avatar to deoptimize.");
// 1. Figure out the skeletonPaths from the unstripped avatar
var skeletonPaths = new List<string>();
foreach (var id in avatar.m_Avatar.m_AvatarSkeleton.m_ID)