Fixed #187
Fixed #188
This commit is contained in:
Perfare 2018-05-05 01:32:55 +08:00
parent 75985c8bf0
commit 9385b4da76
3 changed files with 138 additions and 105 deletions

View File

@ -53,21 +53,24 @@ namespace AssetStudio
else else
reader.Position += 48; reader.Position += 48;
} }
//- OffsetPtr m_DefaultPose if (version[0] > 4 || (version[0] == 4 && version[1] >= 3))//4.3 and up
//-- SkeletonPose data
numXforms = reader.ReadInt32();
for (int i = 0; i < numXforms; i++)
{ {
if (version[0] > 5 || (version[0] == 5 && version[1] >= 4))//5.4 and up //- OffsetPtr m_DefaultPose
reader.Position += 40; //-- SkeletonPose data
else numXforms = reader.ReadInt32();
reader.Position += 48; for (int i = 0; i < numXforms; i++)
} {
//- vector m_SkeletonNameIDArray if (version[0] > 5 || (version[0] == 5 && version[1] >= 4))//5.4 and up
numIDs = reader.ReadInt32(); reader.Position += 40;
for (int i = 0; i < numIDs; i++) else
{ reader.Position += 48;
reader.Position += 4; }
//- vector m_SkeletonNameIDArray
numIDs = reader.ReadInt32();
for (int i = 0; i < numIDs; i++)
{
reader.Position += 4;
}
} }
//- OffsetPtr m_Human //- OffsetPtr m_Human
//-- Human data //-- Human data
@ -176,11 +179,14 @@ namespace AssetStudio
{ {
reader.Position += 4; reader.Position += 4;
} }
//- vector m_HumanSkeletonReverseIndexArray if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
int numReverseIndexes = reader.ReadInt32();
for (int i = 0; i < numReverseIndexes; i++)
{ {
reader.Position += 4; //- vector m_HumanSkeletonReverseIndexArray
int numReverseIndexes = reader.ReadInt32();
for (int i = 0; i < numReverseIndexes; i++)
{
reader.Position += 4;
}
} }
var m_RootMotionBoneIndex = reader.ReadInt32(); var m_RootMotionBoneIndex = reader.ReadInt32();
//- xform m_RootMotionBoneX //- xform m_RootMotionBoneX
@ -188,44 +194,47 @@ namespace AssetStudio
reader.Position += 40; reader.Position += 40;
else else
reader.Position += 48; reader.Position += 48;
//- OffsetPtr m_RootMotionSkeleton if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
//-- Skeleton data
//--- vector m_Node
numNodes = reader.ReadInt32();
for (int i = 0; i < numNodes; i++)
{ {
reader.Position += 8; //- OffsetPtr m_RootMotionSkeleton
} //-- Skeleton data
//--- vector m_ID //--- vector m_Node
numIDs = reader.ReadInt32(); numNodes = reader.ReadInt32();
for (int i = 0; i < numIDs; i++) for (int i = 0; i < numNodes; i++)
{ {
reader.Position += 4; reader.Position += 8;
} }
//--- vector m_AxesArray //--- vector m_ID
numAxes = reader.ReadInt32(); numIDs = reader.ReadInt32();
for (int i = 0; i < numAxes; i++) for (int i = 0; i < numIDs; i++)
{ {
if (version[0] > 5 || (version[0] == 5 && version[1] >= 4))//5.4 and up reader.Position += 4;
reader.Position += 76; }
else //--- vector m_AxesArray
reader.Position += 88; numAxes = reader.ReadInt32();
} for (int i = 0; i < numAxes; i++)
//- OffsetPtr m_RootMotionSkeletonPose {
//-- SkeletonPose data if (version[0] > 5 || (version[0] == 5 && version[1] >= 4))//5.4 and up
numXforms = reader.ReadInt32(); reader.Position += 76;
for (int i = 0; i < numXforms; i++) else
{ reader.Position += 88;
if (version[0] > 5 || (version[0] == 5 && version[1] >= 4))//5.4 and up }
reader.Position += 40; //- OffsetPtr m_RootMotionSkeletonPose
else //-- SkeletonPose data
reader.Position += 48; numXforms = reader.ReadInt32();
} for (int i = 0; i < numXforms; i++)
//- vector m_RootMotionSkeletonIndexArray {
int numMotionIndexes = reader.ReadInt32(); if (version[0] > 5 || (version[0] == 5 && version[1] >= 4))//5.4 and up
for (int i = 0; i < numMotionIndexes; i++) reader.Position += 40;
{ else
reader.Position += 4; reader.Position += 48;
}
//- vector m_RootMotionSkeletonIndexArray
int numMotionIndexes = reader.ReadInt32();
for (int i = 0; i < numMotionIndexes; i++)
{
reader.Position += 4;
}
} }
//map m_TOS //map m_TOS
int numTOS = reader.ReadInt32(); int numTOS = reader.ReadInt32();

View File

@ -511,7 +511,7 @@ namespace AssetStudio
#region BlendShapeData and BindPose for 4.3.0 and later #region BlendShapeData and BindPose for 4.3.0 and later
else if (version[0] >= 5 || (version[0] == 4 && version[1] >= 3)) else if (version[0] >= 5 || (version[0] == 4 && version[1] >= 3))
{ {
m_Shapes = new BlendShapeData(reader);//TODO 4.3 down m_Shapes = new BlendShapeData(reader);
m_BindPose = new float[reader.ReadInt32()][,]; m_BindPose = new float[reader.ReadInt32()][,];
for (int i = 0; i < m_BindPose.Length; i++) for (int i = 0; i < m_BindPose.Length; i++)

View File

@ -77,13 +77,29 @@ namespace AssetStudio
{ {
assetsfileList.TryGetTransform(m_GameObject.m_Transform, out var m_Transform); assetsfileList.TryGetTransform(m_GameObject.m_Transform, out var m_Transform);
var rootTransform = m_Transform; var rootTransform = m_Transform;
while (assetsfileList.TryGetTransform(rootTransform.m_Father, out var m_Father))//Get Root Transform var frameList = new List<ImportedFrame>();
while (assetsfileList.TryGetTransform(rootTransform.m_Father, out var m_Father))
{ {
frameList.Add(ConvertFrames(m_Father));
rootTransform = 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);
ConvertFrames(rootTransform, null);
ConvertMeshRenderer(m_Transform); ConvertMeshRenderer(m_Transform);
} }
@ -170,7 +186,7 @@ namespace AssetStudio
} }
} }
private void ConvertFrames(Transform trans, ImportedFrame parent) private ImportedFrame ConvertFrames(Transform trans)
{ {
var frame = new ImportedFrame(); var frame = new ImportedFrame();
assetsfileList.TryGetGameObject(trans.m_GameObject, out var m_GameObject); assetsfileList.TryGetGameObject(trans.m_GameObject, out var m_GameObject);
@ -182,9 +198,14 @@ namespace AssetStudio
var m_LocalScale = new Vector3(trans.m_LocalScale[0], trans.m_LocalScale[1], trans.m_LocalScale[2]); var m_LocalScale = new Vector3(trans.m_LocalScale[0], trans.m_LocalScale[1], trans.m_LocalScale[2]);
var m_LocalPosition = new Vector3(trans.m_LocalPosition[0], trans.m_LocalPosition[1], trans.m_LocalPosition[2]); var m_LocalPosition = new Vector3(trans.m_LocalPosition[0], trans.m_LocalPosition[1], trans.m_LocalPosition[2]);
frame.Matrix = Matrix.Scaling(m_LocalScale) * Matrix.RotationQuaternion(mirroredRotation) * Matrix.Translation(-m_LocalPosition.X, m_LocalPosition.Y, m_LocalPosition.Z); frame.Matrix = Matrix.Scaling(m_LocalScale) * Matrix.RotationQuaternion(mirroredRotation) * Matrix.Translation(-m_LocalPosition.X, m_LocalPosition.Y, m_LocalPosition.Z);
return frame;
}
private void ConvertFrames(Transform trans, ImportedFrame parent)
{
var frame = ConvertFrames(trans);
if (parent == null) if (parent == null)
{ {
FrameList = new List<ImportedFrame>();
FrameList.Add(frame); FrameList.Add(frame);
} }
else else
@ -356,57 +377,60 @@ namespace AssetStudio
} }
//Morphs //Morphs
foreach (var channel in mesh.m_Shapes.channels) if (mesh.m_Shapes != null)
{ {
morphChannelInfo.Add(channel.nameHash, channel.name); foreach (var channel in mesh.m_Shapes.channels)
}
if (mesh.m_Shapes.shapes.Count > 0)
{
ImportedMorph morph = null;
string lastGroup = "";
for (int i = 0; i < mesh.m_Shapes.channels.Count; i++)
{ {
string group = BlendShapeNameGroup(mesh, i); morphChannelInfo.Add(channel.nameHash, channel.name);
if (group != lastGroup) }
if (mesh.m_Shapes.shapes.Count > 0)
{
ImportedMorph morph = null;
string lastGroup = "";
for (int i = 0; i < mesh.m_Shapes.channels.Count; i++)
{ {
morph = new ImportedMorph(); string group = BlendShapeNameGroup(mesh, i);
MorphList.Add(morph); if (group != lastGroup)
morph.Name = iMesh.Name;
morph.ClipName = group;
morph.Channels = new List<Tuple<float, int, int>>(mesh.m_Shapes.channels.Count);
morph.KeyframeList = new List<ImportedMorphKeyframe>(mesh.m_Shapes.shapes.Count);
lastGroup = group;
}
morph.Channels.Add(new Tuple<float, int, int>(i < sMesh.m_BlendShapeWeights.Count ? sMesh.m_BlendShapeWeights[i] : 0f, morph.KeyframeList.Count, mesh.m_Shapes.channels[i].frameCount));
for (int frameIdx = 0; frameIdx < mesh.m_Shapes.channels[i].frameCount; frameIdx++)
{
ImportedMorphKeyframe keyframe = new ImportedMorphKeyframe();
keyframe.Name = BlendShapeNameExtension(mesh, i) + "_" + frameIdx;
int shapeIdx = mesh.m_Shapes.channels[i].frameIndex + frameIdx;
keyframe.VertexList = new List<ImportedVertex>((int)mesh.m_Shapes.shapes[shapeIdx].vertexCount);
keyframe.MorphedVertexIndices = new List<ushort>((int)mesh.m_Shapes.shapes[shapeIdx].vertexCount);
keyframe.Weight = shapeIdx < mesh.m_Shapes.fullWeights.Count ? mesh.m_Shapes.fullWeights[shapeIdx] : 100f;
int lastVertIndex = (int)(mesh.m_Shapes.shapes[shapeIdx].firstVertex + mesh.m_Shapes.shapes[shapeIdx].vertexCount);
for (int j = (int)mesh.m_Shapes.shapes[shapeIdx].firstVertex; j < lastVertIndex; j++)
{ {
var morphVert = mesh.m_Shapes.vertices[j]; morph = new ImportedMorph();
ImportedVertex vert = GetSourceVertex(iMesh.SubmeshList, (int)morphVert.index); MorphList.Add(morph);
ImportedVertex destVert = new ImportedVertex(); morph.Name = iMesh.Name;
Vector3 morphPos = morphVert.vertex; morph.ClipName = group;
morphPos.X *= -1; morph.Channels = new List<Tuple<float, int, int>>(mesh.m_Shapes.channels.Count);
destVert.Position = vert.Position + morphPos; morph.KeyframeList = new List<ImportedMorphKeyframe>(mesh.m_Shapes.shapes.Count);
Vector3 morphNormal = morphVert.normal; lastGroup = group;
morphNormal.X *= -1;
destVert.Normal = morphNormal;
Vector4 morphTangent = new Vector4(morphVert.tangent, 0);
morphTangent.X *= -1;
destVert.Tangent = morphTangent;
keyframe.VertexList.Add(destVert);
keyframe.MorphedVertexIndices.Add((ushort)morphVert.index);
} }
morph.KeyframeList.Add(keyframe); morph.Channels.Add(new Tuple<float, int, int>(i < sMesh.m_BlendShapeWeights.Count ? sMesh.m_BlendShapeWeights[i] : 0f, morph.KeyframeList.Count, mesh.m_Shapes.channels[i].frameCount));
for (int frameIdx = 0; frameIdx < mesh.m_Shapes.channels[i].frameCount; frameIdx++)
{
ImportedMorphKeyframe keyframe = new ImportedMorphKeyframe();
keyframe.Name = BlendShapeNameExtension(mesh, i) + "_" + frameIdx;
int shapeIdx = mesh.m_Shapes.channels[i].frameIndex + frameIdx;
keyframe.VertexList = new List<ImportedVertex>((int)mesh.m_Shapes.shapes[shapeIdx].vertexCount);
keyframe.MorphedVertexIndices = new List<ushort>((int)mesh.m_Shapes.shapes[shapeIdx].vertexCount);
keyframe.Weight = shapeIdx < mesh.m_Shapes.fullWeights.Count ? mesh.m_Shapes.fullWeights[shapeIdx] : 100f;
int lastVertIndex = (int)(mesh.m_Shapes.shapes[shapeIdx].firstVertex + mesh.m_Shapes.shapes[shapeIdx].vertexCount);
for (int j = (int)mesh.m_Shapes.shapes[shapeIdx].firstVertex; j < lastVertIndex; j++)
{
var morphVert = mesh.m_Shapes.vertices[j];
ImportedVertex vert = GetSourceVertex(iMesh.SubmeshList, (int)morphVert.index);
ImportedVertex destVert = new ImportedVertex();
Vector3 morphPos = morphVert.vertex;
morphPos.X *= -1;
destVert.Position = vert.Position + morphPos;
Vector3 morphNormal = morphVert.normal;
morphNormal.X *= -1;
destVert.Normal = morphNormal;
Vector4 morphTangent = new Vector4(morphVert.tangent, 0);
morphTangent.X *= -1;
destVert.Tangent = morphTangent;
keyframe.VertexList.Add(destVert);
keyframe.MorphedVertexIndices.Add((ushort)morphVert.index);
}
morph.KeyframeList.Add(keyframe);
}
} }
} }
} }